adding Subdomain class in API + few functions as of now
This commit is contained in:
parent
d6980d7664
commit
cab86d7fa5
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
class Alternc_Api_Object_Account extends Alternc_Api_Legacyobject {
|
class Alternc_Api_Object_Account extends Alternc_Api_Legacyobject {
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method admin->add_mem()
|
/** API Method from legacy class method admin->add_mem()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: login, pass, nom, prenom, mail,
|
* mandatory parameters: login, pass, nom, prenom, mail,
|
||||||
|
|
|
@ -44,13 +44,45 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
while ($me = $stmt->fetch(PDO::FETCH_OBJ)) {
|
while ($me = $stmt->fetch(PDO::FETCH_OBJ)) {
|
||||||
$result[$me->domaine] = $me;
|
$result[$me->domaine] = $me;
|
||||||
}
|
}
|
||||||
list($offset,$count)=$this->offsetAndCount($options, count($result));
|
list($offset, $count) = $this->offsetAndCount($options, count($result));
|
||||||
if ($offset != -1 || $count != -1) {
|
if ($offset != -1 || $count != -1) {
|
||||||
$result = array_slice($result, $offset, $count);
|
$result = array_slice($result, $offset, $count);
|
||||||
}
|
}
|
||||||
return new Alternc_Api_Response(array("content" => $result));
|
return new Alternc_Api_Response(array("content" => $result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** API Method from legacy class method dom->get_domain_all($dom)
|
||||||
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
|
* musr be the domain name $dom
|
||||||
|
* @return Alternc_Api_Response whose content is the list of domain info and subdomains
|
||||||
|
*/
|
||||||
|
function get($options) {
|
||||||
|
global $cuid;
|
||||||
|
if ($this->isAdmin) {
|
||||||
|
if (isset($options["uid"])) {
|
||||||
|
$cuid = intval($options["uid"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$mandatory = array("dom");
|
||||||
|
$missing = "";
|
||||||
|
foreach ($mandatory as $key) {
|
||||||
|
if (!isset($options[$key])) {
|
||||||
|
$missing.=$key . " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($missing) {
|
||||||
|
return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
|
||||||
|
}
|
||||||
|
$this->dom->lock();
|
||||||
|
$did = $this->dom->get_domain_all($options["dom"]);
|
||||||
|
$this->dom->unlock();
|
||||||
|
if (!$did) {
|
||||||
|
return $this->alterncLegacyErrorManager();
|
||||||
|
} else {
|
||||||
|
return new Alternc_Api_Response(array("content" => $did));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** API Method from legacy class method dom->add_domain()
|
/** API Method from legacy class method dom->add_domain()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: domain(str), dns(bool)
|
* mandatory parameters: domain(str), dns(bool)
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subdomain Api of AlternC, used by alternc-api package
|
||||||
|
*/
|
||||||
|
class Alternc_Api_Object_Subdomain extends Alternc_Api_Legacyobject {
|
||||||
|
|
||||||
|
protected $dom; // m_dom instance
|
||||||
|
|
||||||
|
function __construct($service) {
|
||||||
|
global $dom;
|
||||||
|
parent::__construct($service);
|
||||||
|
$this->dom = $dom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** API Method from legacy class method dom->get_sub_domain_all($dom)
|
||||||
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
|
* musr be the subdomain id ID
|
||||||
|
* @return Alternc_Api_Response whose content is the list of subdomains on this server
|
||||||
|
*/
|
||||||
|
function get($options) {
|
||||||
|
global $cuid;
|
||||||
|
if ($this->isAdmin) {
|
||||||
|
if (isset($options["uid"])) {
|
||||||
|
$cuid = intval($options["uid"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$mandatory = array("id");
|
||||||
|
$missing = "";
|
||||||
|
foreach ($mandatory as $key) {
|
||||||
|
if (!isset($options[$key])) {
|
||||||
|
$missing.=$key . " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($missing) {
|
||||||
|
return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
|
||||||
|
}
|
||||||
|
$this->dom->lock();
|
||||||
|
$did = $this->dom->get_sub_domain_all($options["id"]);
|
||||||
|
$this->dom->unlock();
|
||||||
|
if (!$did) {
|
||||||
|
return $this->alterncLegacyErrorManager();
|
||||||
|
} else {
|
||||||
|
return new Alternc_Api_Response(array("content" => $did));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** API Method from legacy class method dom->set_sub_domain($dom)
|
||||||
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
|
* must be $dom, $sub, $type, $dest and could be $sub_domain_id
|
||||||
|
* @return Alternc_Api_Response whose content is true or false
|
||||||
|
* if the change has been made
|
||||||
|
*/
|
||||||
|
function set($options) {
|
||||||
|
global $cuid;
|
||||||
|
if ($this->isAdmin) {
|
||||||
|
if (isset($options["uid"])) {
|
||||||
|
$cuid = intval($options["uid"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$mandatory = array("dom", "sub", "type", "dest");
|
||||||
|
$defaults = array("sub_domain_id" => null);
|
||||||
|
$missing = "";
|
||||||
|
foreach ($mandatory as $key) {
|
||||||
|
if (!isset($options[$key])) {
|
||||||
|
$missing.=$key . " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($defaults as $key => $value) {
|
||||||
|
if (!isset($options[$key])) {
|
||||||
|
$options[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($missing) {
|
||||||
|
return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
|
||||||
|
}
|
||||||
|
$this->dom->lock();
|
||||||
|
$did = $this->dom->set_sub_domain($options["dom"], $options["sub"], $options["type"], $options["dest"], $options["sub_domain_id"]);
|
||||||
|
$this->dom->unlock();
|
||||||
|
if (!$did) {
|
||||||
|
return $this->alterncLegacyErrorManager();
|
||||||
|
} else {
|
||||||
|
return new Alternc_Api_Response(array("content" => $did));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// class Alternc_Api_Object_Subdomain
|
Loading…
Reference in New Issue