Alternc  latest
Alternc logiel libre pour l'hébergement
Alternc_Api_Object_Mail Class Reference

Domain Api of AlternC, used by alternc-api package. More...

+ Inheritance diagram for Alternc_Api_Object_Mail:

Public Member Functions

 __construct ($service)
 
 listDomains ($options)
 API Method from legacy class method mail->enum_domains() More...
 
 isAvailable ($options)
 API Method from legacy class method mail->available() More...
 
 getAll ($options)
 API Method from legacy class method $mail->enum_domain_mails ($dom_id = null, $search="", $offset=0, $count=30, $show_systemmails=false) More...
 
 create ($options)
 API Method from legacy class method $mail->create ($dom_id, $mail,$type="",$dontcheck=false){. More...
 
 get ($options)
 API Method from legacy class method $mail->get_details($mail_id) More...
 
 account ($options)
 API Method from legacy class method $mail->get_account_by_mail_id($mail_id) More...
 
 delete ($options)
 API Method from legacy class method $mail->delete($mail_id) More...
 
 undelete ($options)
 API Method from legacy class method $mail->undelete($mail_id) More...
 
 passwd ($options)
 API Method from legacy class method $mail->delete($mail_id) More...
 
 enable ($options)
 API Method from legacy class method $mail->enable($mail_id) More...
 
 disable ($options)
 API Method from legacy class method $mail->disable($mail_id) More...
 
 update ($options)
 API Method from legacy class method $mail-> set_details ($mail_id, $islocal, $quotamb, $recipients,$delivery="dovecot",$dontcheck=false) More...
 
 login ($options)
 API Method for email authentication. More...
 
 check_password ($password, $hash)
 

Public Attributes

const ERR_INVALID_ARGUMENT = 111201
 
const ERR_ALTERNC_FUNCTION = 111202
 
const ERR_NOT_FOUND = 111203
 

Protected Member Functions

 alterncLegacyErrorManager ()
 return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class More...
 
 offsetAndCount ($options, $max)
 ensure that offset & count are set properly from $options. More...
 

Protected Attributes

 $mail
 
 $admin
 
 $cuid
 
 $isAdmin
 
 $db
 

Detailed Description

Domain Api of AlternC, used by alternc-api package.

Definition at line 6 of file Mail.php.

Constructor & Destructor Documentation

◆ __construct()

Alternc_Api_Object_Mail::__construct (   $service)

Reimplemented from Alternc_Api_Legacyobject.

Definition at line 10 of file Mail.php.

10  {
11  global $mail;
12  parent::__construct($service);
13  $this->mail = $mail;
14  }

References $mail.

Member Function Documentation

◆ account()

Alternc_Api_Object_Mail::account (   $options)

API Method from legacy class method $mail->get_account_by_mail_id($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id
Returns
Alternc_Api_Response whose content is

Definition at line 138 of file Mail.php.

138  {
139  $mandatory = array("mail_id");
140  $missing = "";
141  foreach ($mandatory as $key) {
142  if (!isset($options[$key])) {
143  $missing.=$key . " ";
144  }
145  }
146  if ($missing) {
147  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
148  }
149  $did = $this->mail->get_account_by_mail_id($options["mail_id"]);
150  if (!$did) {
151  return $this->alterncLegacyErrorManager();
152  } else {
153  return new Alternc_Api_Response(array("content" => $did));
154  }
155  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class
Standard Response object for the AlternC API.
Definition: Response.php:7
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ alterncLegacyErrorManager()

Alternc_Api_Legacyobject::alterncLegacyErrorManager ( )
protectedinherited

return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class

Definition at line 38 of file Legacyobject.php.

38  {
39  global $err;
40  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[" . $err->clsid . "] " . $err->error));
41  }
$err
Definition: bootstrap.php:72

References $err.

Referenced by account(), Alternc_Api_Object_Account\add(), Alternc_Api_Object_Domain\add(), Alternc_Api_Object_Ftp\add(), Alternc_Api_Object_Mysql\add(), Alternc_Api_Object_Ssl\aliasAdd(), Alternc_Api_Object_Ssl\aliasDel(), Alternc_Api_Object_Policy\check(), create(), Alternc_Api_Object_Account\del(), Alternc_Api_Object_Domain\del(), Alternc_Api_Object_Ftp\del(), Alternc_Api_Object_Mysql\del(), delete(), disable(), enable(), Alternc_Api_Object_Ssl\finalize(), Alternc_Api_Object_Account\find(), Alternc_Api_Object_Ftp\find(), Alternc_Api_Object_Mysql\find(), Alternc_Api_Object_Policy\find(), Alternc_Api_Object_Domain\get(), get(), Alternc_Api_Object_Subdomain\get(), getAll(), Alternc_Api_Object_Ssl\getCertificate(), Alternc_Api_Object_Ssl\importCert(), isAvailable(), Alternc_Api_Object_Ftp\isFtp(), listDomains(), Alternc_Api_Object_Account\lock(), Alternc_Api_Object_Mysql\lock(), Alternc_Api_Object_Ssl\newCsr(), passwd(), Alternc_Api_Object_Subdomain\set(), Alternc_Api_Object_Account\setAdmin(), Alternc_Api_Object_Mysql\setAdmin(), Alternc_Api_Object_Ssl\share(), undelete(), Alternc_Api_Object_Account\unlock(), Alternc_Api_Object_Mysql\unlock(), Alternc_Api_Object_Account\unsetAdmin(), Alternc_Api_Object_Mysql\unsetAdmin(), Alternc_Api_Object_Account\update(), Alternc_Api_Object_Domain\update(), Alternc_Api_Object_Ftp\update(), update(), Alternc_Api_Object_Mysql\update(), and Alternc_Api_Object_Policy\update().

◆ check_password()

Alternc_Api_Object_Mail::check_password (   $password,
  $hash 
)

Definition at line 337 of file Mail.php.

337  {
338  if ($hash == '') { // no password
339  return FALSE;
340  }
341 
342  if ($hash{0} != '{') { // plaintext or crypt() password ?
343  if ($hash{0} == '$' ) {
344  if (crypt($password,$hash)==$hash)
345  return TRUE;
346  } else { // plaintext ? (NOT RECOMMENDED !!!)
347  if ($password == $hash)
348  return TRUE;
349  }
350  return FALSE;
351  }
352 
353  if (substr($hash,0,7) == '{crypt}') {
354  if (crypt($password, substr($hash,7)) == substr($hash,7))
355  return TRUE;
356  return FALSE;
357  }
358  elseif (substr($hash,0,5) == '{MD5}') {
359  $encrypted_password = '{MD5}' . base64_encode(md5( $password,TRUE));
360  }
361  elseif (substr($hash,0,6) == '{SHA1}') {
362  $encrypted_password = '{SHA}' . base64_encode(sha1( $password, TRUE ));
363  }
364  elseif (substr($hash,0,6) == '{SSHA}') {
365  $salt = substr(base64_decode(substr($hash,6)),20);
366  $encrypted_password = '{SSHA}' . base64_encode(sha1( $password.$salt, TRUE ). $salt);
367  } else {
368  echo "Unsupported password hash format";
369  return FALSE;
370  }
371 
372  if ($hash == $encrypted_password)
373  return TRUE;
374 
375  return FALSE;
376  }
$password
Definition: bootstrap.php:85
if(empty($site_name)) elseif($piwik->site_add( $site_name, $site_urls))

References $password, and elseif.

Referenced by login().

◆ create()

Alternc_Api_Object_Mail::create (   $options)

API Method from legacy class method $mail->create ($dom_id, $mail,$type="",$dontcheck=false){.

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: non-mandatory:
Returns
Alternc_Api_Response whose content is

Definition at line 84 of file Mail.php.

84  {
85  $defaults = array("type" => "");
86  $mandatory = array("dom_id", "mail");
87  $missing = "";
88  foreach ($mandatory as $key) {
89  if (!isset($options[$key])) {
90  $missing.=$key . " ";
91  }
92  }
93  if ($missing) {
94  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
95  }
96  foreach ($defaults as $key => $value) {
97  if (!isset($options[$key])) {
98  $options[$key] = $value;
99  }
100  }
101  $did = $this->mail->create($options["dom_id"], $options["mail"], $options["type"]);
102  if (!$did) {
103  return $this->alterncLegacyErrorManager();
104  } else {
105  return new Alternc_Api_Response(array("content" => $did));
106  }
107  }
$value

References $key, $value, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ delete()

Alternc_Api_Object_Mail::delete (   $options)

API Method from legacy class method $mail->delete($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id
Returns
Alternc_Api_Response whose content is

Definition at line 162 of file Mail.php.

162  {
163  $mandatory = array("mail_id");
164  $missing = "";
165  foreach ($mandatory as $key) {
166  if (!isset($options[$key])) {
167  $missing.=$key . " ";
168  }
169  }
170  if ($missing) {
171  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
172  }
173  $did = $this->mail->delete($options["mail_id"]);
174  if (!$did) {
175  return $this->alterncLegacyErrorManager();
176  } else {
177  return new Alternc_Api_Response(array("content" => $did));
178  }
179  }

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ disable()

Alternc_Api_Object_Mail::disable (   $options)

API Method from legacy class method $mail->disable($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id
Returns
Alternc_Api_Response whose content is

Definition at line 258 of file Mail.php.

258  {
259  $mandatory = array("mail_id");
260  $missing = "";
261  foreach ($mandatory as $key) {
262  if (!isset($options[$key])) {
263  $missing.=$key . " ";
264  }
265  }
266  if ($missing) {
267  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
268  }
269  $did = $this->mail->disable($options["mail_id"]);
270  if (!$did) {
271  return $this->alterncLegacyErrorManager();
272  } else {
273  return new Alternc_Api_Response(array("content" => $did));
274  }
275  }

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ enable()

Alternc_Api_Object_Mail::enable (   $options)

API Method from legacy class method $mail->enable($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id
Returns
Alternc_Api_Response whose content is

Definition at line 234 of file Mail.php.

234  {
235  $mandatory = array("mail_id");
236  $missing = "";
237  foreach ($mandatory as $key) {
238  if (!isset($options[$key])) {
239  $missing.=$key . " ";
240  }
241  }
242  if ($missing) {
243  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
244  }
245  $did = $this->mail->enable($options["mail_id"]);
246  if (!$did) {
247  return $this->alterncLegacyErrorManager();
248  } else {
249  return new Alternc_Api_Response(array("content" => $did));
250  }
251  }

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ get()

Alternc_Api_Object_Mail::get (   $options)

API Method from legacy class method $mail->get_details($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id
Returns
Alternc_Api_Response whose content is

Definition at line 114 of file Mail.php.

114  {
115  $mandatory = array("mail_id");
116  $missing = "";
117  foreach ($mandatory as $key) {
118  if (!isset($options[$key])) {
119  $missing.=$key . " ";
120  }
121  }
122  if ($missing) {
123  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
124  }
125  $did = $this->mail->get_details($options["mail_id"]);
126  if (!$did) {
127  return $this->alterncLegacyErrorManager();
128  } else {
129  return new Alternc_Api_Response(array("content" => $did));
130  }
131  }

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ getAll()

Alternc_Api_Object_Mail::getAll (   $options)

API Method from legacy class method $mail->enum_domain_mails ($dom_id = null, $search="", $offset=0, $count=30, $show_systemmails=false)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: non-mandatory:
Returns
Alternc_Api_Response whose content is

Definition at line 62 of file Mail.php.

62  {
63  $defaults = array("dom_id" => null, "search" => "", "offset" => 0, "count" => 30, "show_systemmails" => false);
64  foreach ($defaults as $key => $value) {
65  if (!isset($options[$key])) {
66  $options[$key] = $value;
67  }
68  }
69  $did = $this->mail->enum_domain_mails($options["dom_id"], $options["search"], $options["offset"], $options["count"], $options["show_systemmails"]);
70  if (!$did) {
71  return $this->alterncLegacyErrorManager();
72  } else {
73  return new Alternc_Api_Response(array("content" => $did));
74  }
75  }

References $key, $value, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ isAvailable()

Alternc_Api_Object_Mail::isAvailable (   $options)

API Method from legacy class method mail->available()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail(str)
Returns
Alternc_Api_Response telling TRUE or FALSE

Definition at line 43 of file Mail.php.

43  {
44  if (!isset($options["mail"])) {
45  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . "mail"));
46  }
47  $did = $this->mail->available($options["mail"]);
48  if (!$did) {
49  return $this->alterncLegacyErrorManager();
50  } else {
51  return new Alternc_Api_Response(array("content" => $did));
52  }
53  }

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ listDomains()

Alternc_Api_Object_Mail::listDomains (   $options)

API Method from legacy class method mail->enum_domains()

Parameters
$optionsa hash with parameters transmitted to legacy call
Returns
Alternc_Api_Response whose content is the list of hosted domains for mails on this server (no more details as of now)

Definition at line 22 of file Mail.php.

22  {
23  global $cuid;
24  $sql = "";
25  $uid = $cuid;
26  if ($this->isAdmin && isset($options["uid"])) {
27  $uid = intval($options["uid"]);
28  }
29 
30  $did = $this->mail->enum_domains($uid);
31  if (!$did) {
32  return $this->alterncLegacyErrorManager();
33  } else {
34  return new Alternc_Api_Response(array("content" => $did));
35  }
36  }
$uid

References Alternc_Api_Legacyobject\$cuid, $uid, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ login()

Alternc_Api_Object_Mail::login (   $options)

API Method for email authentication.

Parameters
$optionsa hash with email and password parameters.
Returns
Alternc_Api_Response whose content is true / false if the auth to this email was successfull.

Definition at line 315 of file Mail.php.

315  {
316  global $cuid;
317  $uid = $cuid;
318  if ($this->isAdmin && isset($options["uid"])) {
319  $uid = intval($options["uid"]);
320  }
321  if (!isset($options["email"]) || !isset($options["password"])) {
322  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing email or password argument"));
323  }
324  list($address,$domain)=explode("@",$options["email"],2);
325  $stmt = $this->db->prepare("SELECT enabled,password FROM domaines d,address a WHERE a.domain_id=d.id AND address=? AND domaine=?;");
326  $stmt->execute(array($address,$domain));
327  $me = $stmt->fetch(PDO::FETCH_OBJ);
328  if ($me && $me->enabled) {
329  // Check password :
330  return new Alternc_Api_Response(array("content" => $this->check_password($options["password"],$me->password) ));
331  } else {
332  return new Alternc_Api_Response(array("content" => false));
333  }
334  }
check_password($password, $hash)
Definition: Mail.php:337
$domain
Definition: dom_import.php:36

References Alternc_Api_Legacyobject\$cuid, $domain, $uid, and check_password().

◆ offsetAndCount()

Alternc_Api_Legacyobject::offsetAndCount (   $options,
  $max 
)
protectedinherited

ensure that offset & count are set properly from $options.

Definition at line 45 of file Legacyobject.php.

45  {
46  $offset = -1;
47  $count = -1;
48  if (isset($options["count"]))
49  $count = intval($options["count"]);
50  if (isset($options["offset"]))
51  $offset = intval($options["offset"]);
52  if ($offset != -1 || $count != -1) {
53  if ($offset < 0 || $offset > $max)
54  $offset = 0;
55  if ($count < 0 || $count > 1000)
56  $count = 1000;
57  }
58  return array($offset, $count);
59  }

Referenced by Alternc_Api_Object_Account\find(), Alternc_Api_Object_Domain\find(), Alternc_Api_Object_Ftp\find(), and Alternc_Api_Object_Mysql\find().

◆ passwd()

Alternc_Api_Object_Mail::passwd (   $options)

API Method from legacy class method $mail->delete($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id, password
Returns
Alternc_Api_Response whose content is

Definition at line 210 of file Mail.php.

210  {
211  $mandatory = array("mail_id", "password");
212  $missing = "";
213  foreach ($mandatory as $key) {
214  if (!isset($options[$key])) {
215  $missing.=$key . " ";
216  }
217  }
218  if ($missing) {
219  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
220  }
221  $did = $this->mail->set_passwd($options["mail_id"], $options["password"]);
222  if (!$did) {
223  return $this->alterncLegacyErrorManager();
224  } else {
225  return new Alternc_Api_Response(array("content" => $did));
226  }
227  }

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ undelete()

Alternc_Api_Object_Mail::undelete (   $options)

API Method from legacy class method $mail->undelete($mail_id)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: mail_id
Returns
Alternc_Api_Response whose content is

Definition at line 186 of file Mail.php.

186  {
187  $mandatory = array("mail_id");
188  $missing = "";
189  foreach ($mandatory as $key) {
190  if (!isset($options[$key])) {
191  $missing.=$key . " ";
192  }
193  }
194  if ($missing) {
195  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
196  }
197  $did = $this->mail->undelete($options["mail_id"]);
198  if (!$did) {
199  return $this->alterncLegacyErrorManager();
200  } else {
201  return new Alternc_Api_Response(array("content" => $did));
202  }
203  }

References $key, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ update()

Alternc_Api_Object_Mail::update (   $options)

API Method from legacy class method $mail-> set_details ($mail_id, $islocal, $quotamb, $recipients,$delivery="dovecot",$dontcheck=false)

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: non-mandatory:
Returns
Alternc_Api_Response whose content is

Definition at line 284 of file Mail.php.

284  {
285  $defaults = array("delivery" => "dovecot");
286  $mandatory = array("mail_id", "islocal", "quotamb", "recipients");
287  $missing = "";
288  foreach ($mandatory as $key) {
289  if (!isset($options[$key])) {
290  $missing.=$key . " ";
291  }
292  }
293  if ($missing) {
294  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
295  }
296  foreach ($defaults as $key => $value) {
297  if (!isset($options[$key])) {
298  $options[$key] = $value;
299  }
300  }
301  $did = $this->mail->set_details($options["mail_id"], $options["islocal"], $options["quotamb"], $options["recipients"], $options["delivery"]);
302  if (!$did) {
303  return $this->alterncLegacyErrorManager();
304  } else {
305  return new Alternc_Api_Response(array("content" => $did));
306  }
307  }

References $key, $value, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

Member Data Documentation

◆ $admin

Alternc_Api_Legacyobject::$admin
protectedinherited

Definition at line 11 of file Legacyobject.php.

Referenced by Alternc_Api_Legacyobject\__construct().

◆ $cuid

◆ $db

Alternc_Api_Legacyobject::$db
protectedinherited

Definition at line 14 of file Legacyobject.php.

◆ $isAdmin

Alternc_Api_Legacyobject::$isAdmin
protectedinherited

Definition at line 13 of file Legacyobject.php.

Referenced by Alternc_Api_Legacyobject\__construct().

◆ $mail

Alternc_Api_Object_Mail::$mail
protected

Definition at line 8 of file Mail.php.

Referenced by __construct().

◆ ERR_ALTERNC_FUNCTION

const Alternc_Api_Legacyobject::ERR_ALTERNC_FUNCTION = 111202
inherited

Definition at line 17 of file Legacyobject.php.

◆ ERR_INVALID_ARGUMENT

const Alternc_Api_Legacyobject::ERR_INVALID_ARGUMENT = 111201
inherited

Definition at line 16 of file Legacyobject.php.

◆ ERR_NOT_FOUND

const Alternc_Api_Legacyobject::ERR_NOT_FOUND = 111203
inherited

Definition at line 18 of file Legacyobject.php.


The documentation for this class was generated from the following file: