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

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

+ Inheritance diagram for Alternc_Api_Object_Domain:

Public Member Functions

 __construct ($service)
 
 find ($options)
 API Method from legacy class method dom->get_domain_list() More...
 
 get ($options)
 API Method from legacy class method dom->get_domain_all($dom) More...
 
 add ($options)
 API Method from legacy class method dom->add_domain() More...
 
 update ($options)
 API Method from legacy class method dom->edit_domain() More...
 
 del ($options)
 API Method from legacy class method dom->del_domain() More...
 

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

 $dom
 
 $admin
 
 $cuid
 
 $isAdmin
 
 $db
 

Detailed Description

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

Definition at line 6 of file Domain.php.

Constructor & Destructor Documentation

◆ __construct()

Alternc_Api_Object_Domain::__construct (   $service)

Reimplemented from Alternc_Api_Legacyobject.

Definition at line 10 of file Domain.php.

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

References $dom.

Member Function Documentation

◆ add()

Alternc_Api_Object_Domain::add (   $options)

API Method from legacy class method dom->add_domain()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: domain(str), dns(bool) non-mandatory: noerase(bool, only admins), force(bool, only admins), isslave(bool), slavedom(str)
Returns
Alternc_Api_Response whose content is the newly created DOMAIN id

Definition at line 92 of file Domain.php.

92  {
93  $mandatory = array("domain", "dns");
94  $defaults = array("noerase" => false, "force" => false, "isslave" => false, "slavedom" => "");
95  $missing = "";
96  foreach ($mandatory as $key) {
97  if (!isset($options[$key])) {
98  $missing.=$key . " ";
99  }
100  }
101  if ($missing) {
102  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
103  }
104  foreach ($defaults as $key => $value) {
105  if (!isset($options[$key])) {
106  $options[$key] = $value;
107  }
108  }
109  if (!$this->isAdmin) { // only admin can change the options below:
110  $options["noerase"] = false;
111  $options["force"] = false;
112  }
113  $did = $this->dom->add_domain($options["domain"], $options["dns"], $options["noerase"], $options["force"], $options["isslave"], $options["slavedom"]);
114  if (!$did) {
115  return $this->alterncLegacyErrorManager();
116  } else {
117  return new Alternc_Api_Response(array("content" => $did));
118  }
119  }
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
$value
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14

References $key, $value, 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 Alternc_Api_Object_Mail\account(), Alternc_Api_Object_Account\add(), 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(), Alternc_Api_Object_Mail\create(), Alternc_Api_Object_Account\del(), del(), Alternc_Api_Object_Ftp\del(), Alternc_Api_Object_Mysql\del(), Alternc_Api_Object_Mail\delete(), Alternc_Api_Object_Mail\disable(), Alternc_Api_Object_Mail\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(), get(), Alternc_Api_Object_Mail\get(), Alternc_Api_Object_Subdomain\get(), Alternc_Api_Object_Mail\getAll(), Alternc_Api_Object_Ssl\getCertificate(), Alternc_Api_Object_Ssl\importCert(), Alternc_Api_Object_Mail\isAvailable(), Alternc_Api_Object_Ftp\isFtp(), Alternc_Api_Object_Mail\listDomains(), Alternc_Api_Object_Account\lock(), Alternc_Api_Object_Mysql\lock(), Alternc_Api_Object_Ssl\newCsr(), Alternc_Api_Object_Mail\passwd(), Alternc_Api_Object_Subdomain\set(), Alternc_Api_Object_Account\setAdmin(), Alternc_Api_Object_Mysql\setAdmin(), Alternc_Api_Object_Ssl\share(), Alternc_Api_Object_Mail\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(), update(), Alternc_Api_Object_Ftp\update(), Alternc_Api_Object_Mail\update(), Alternc_Api_Object_Mysql\update(), and Alternc_Api_Object_Policy\update().

◆ del()

Alternc_Api_Object_Domain::del (   $options)

API Method from legacy class method dom->del_domain()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: domain
Returns
Alternc_Api_Response TRUE if the domain has been marked for deletion.

Definition at line 160 of file Domain.php.

160  {
161  if (!isset($options["domain"])) {
162  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: DOMAIN"));
163  }
164  $result = $this->dom->del_domain($options["domain"]);
165  if (!$result) {
166  return $this->alterncLegacyErrorManager();
167  } else {
168  return new Alternc_Api_Response(array("content" => true));
169  }
170  }

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

◆ find()

Alternc_Api_Object_Domain::find (   $options)

API Method from legacy class method dom->get_domain_list()

Parameters
$optionsa hash with parameters transmitted to legacy call may be "uid" to only return domains for a specific user-id (if you are not admin, this WILL only list YOUR domains anyway) may be "offset" and/or "count" to do paging.
Returns
Alternc_Api_Response whose content is the list of hosted domains on this server (no more details as of now)

Definition at line 24 of file Domain.php.

24  {
25  global $cuid;
26  $sql = "";
27  if ($this->isAdmin) {
28  if (isset($options["uid"])) {
29  $uid = intval($options["uid"]);
30  } else {
31  $uid = -1;
32  }
33  } else {
34  $uid = $cuid;
35  }
36  if ($uid != -1) {
37  $sql = " WHERE compte=$uid ";
38  } else {
39  $sql = "";
40  }
41  $stmt = $this->db->prepare("SELECT * FROM domaines $sql ORDER BY domaine");
42  $stmt->execute();
43  $result = array();
44  while ($me = $stmt->fetch(PDO::FETCH_OBJ)) {
45  $result[$me->domaine] = $me;
46  }
47  list($offset, $count) = $this->offsetAndCount($options, count($result));
48  if ($offset != -1 || $count != -1) {
49  $result = array_slice($result, $offset, $count);
50  }
51  return new Alternc_Api_Response(array("content" => $result));
52  }
offsetAndCount($options, $max)
ensure that offset & count are set properly from $options.
$uid

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

◆ get()

Alternc_Api_Object_Domain::get (   $options)

API Method from legacy class method dom->get_domain_all($dom)

Parameters
$optionsa hash with parameters transmitted to legacy call musr be the domain name $dom
Returns
Alternc_Api_Response whose content is the list of domain info and subdomains

Definition at line 59 of file Domain.php.

59  {
60  global $cuid;
61  if ($this->isAdmin) {
62  if (isset($options["uid"])) {
63  $cuid = intval($options["uid"]);
64  }
65  }
66  $mandatory = array("dom");
67  $missing = "";
68  foreach ($mandatory as $key) {
69  if (!isset($options[$key])) {
70  $missing.=$key . " ";
71  }
72  }
73  if ($missing) {
74  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
75  }
76  $this->dom->lock();
77  $did = $this->dom->get_domain_all($options["dom"]);
78  $this->dom->unlock();
79  if (!$did) {
80  return $this->alterncLegacyErrorManager();
81  } else {
82  return new Alternc_Api_Response(array("content" => $did));
83  }
84  }

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

◆ 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(), find(), Alternc_Api_Object_Ftp\find(), and Alternc_Api_Object_Mysql\find().

◆ update()

Alternc_Api_Object_Domain::update (   $options)

API Method from legacy class method dom->edit_domain()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: domain(str), dns(bool) non-mandatory: noerase(bool, only admins), force(bool, only admins), isslave(bool), slavedom(str)
Returns
Alternc_Api_Response whose content is the newly created DOMAIN id

Definition at line 127 of file Domain.php.

127  {
128  $mandatory = array("domain", "dns", "gesmx");
129  $defaults = array("force" => false, "ttl" => 86400);
130  $missing = "";
131  foreach ($mandatory as $key) {
132  if (!isset($options[$key])) {
133  $missing.=$key . " ";
134  }
135  }
136  if ($missing) {
137  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
138  }
139  foreach ($defaults as $key => $value) {
140  if (!isset($options[$key])) {
141  $options[$key] = $value;
142  }
143  }
144  if (!$this->isAdmin) { // only admin can change the options below:
145  $options["force"] = false;
146  }
147  $did = $this->dom->edit_domain($options["domain"], $options["dns"], $options["gesmx"], $options["force"], $options["ttl"]);
148  if (!$did) {
149  return $this->alterncLegacyErrorManager();
150  } else {
151  return new Alternc_Api_Response(array("content" => $did));
152  }
153  }

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.

◆ $dom

Alternc_Api_Object_Domain::$dom
protected

Definition at line 8 of file Domain.php.

Referenced by __construct().

◆ $isAdmin

Alternc_Api_Legacyobject::$isAdmin
protectedinherited

Definition at line 13 of file Legacyobject.php.

Referenced by Alternc_Api_Legacyobject\__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: