From b2c8e8cadd86fcdd5bd73d972fa1c79009079742 Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Sun, 4 Jan 2015 20:35:27 +0100 Subject: [PATCH] finishing Account (to be tested) starting Domain --- lib/Alternc/Api/Object/Account.php | 11 +++-- lib/Alternc/Api/Object/Domain.php | 77 ++++++++++++++++++++++++++++++ lib/Alternc/Api/Service.php | 1 + 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 lib/Alternc/Api/Object/Domain.php diff --git a/lib/Alternc/Api/Object/Account.php b/lib/Alternc/Api/Object/Account.php index 476202f0..4bb1d534 100644 --- a/lib/Alternc/Api/Object/Account.php +++ b/lib/Alternc/Api/Object/Account.php @@ -9,14 +9,19 @@ class Alternc_Api_Object_Account { const ERR_ALTERNC_FUNCTION = 1115102; const ERR_NOT_FOUND = 1115103; + var $admin; // m_admin instance + var $cuid; // current user id + var $isAdmin; // is it an Admin account? + function __construct($service) { global $admin,$cuid; if (!($service instanceof Alternc_Api_Service)) { throw new \Exception("Bad argument: service is not an Alternc_Api_Service", self::ERR_INVALID_ARGUMENT); } // We store the global $cuid to AlternC legacy classes - $cuid=$service->token->uid; - // We use the global $ssl from AlternC legacy classes + $this->cuid=$cuid=$service->token->uid; + $this->isAdmin=$service->token->isAdmin; + // We use the global $admin from AlternC legacy classes $this->admin=$admin; } @@ -165,4 +170,4 @@ class Alternc_Api_Object_Account { } -} // class Alternc_Api_Object_Ssl \ No newline at end of file +} // class Alternc_Api_Object_Account \ No newline at end of file diff --git a/lib/Alternc/Api/Object/Domain.php b/lib/Alternc/Api/Object/Domain.php new file mode 100644 index 00000000..82607e0a --- /dev/null +++ b/lib/Alternc/Api/Object/Domain.php @@ -0,0 +1,77 @@ +cuid=$cuid=$service->token->uid; + $this->isAdmin=$service->token->isAdmin; + // We use the global $admin & $dom from AlternC legacy classes + $this->admin=$admin; + $this->dom=$dom; + } + + + /** API Method from legacy class method dom->get_domain_list() + * @param $options a 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. + * @return Alternc_Api_Response whose content is the list of hosted domains on this server + */ + function find($options) { + global $cuid; + $sql=""; + if ($this->isAdmin) { + if (isset($options["uid"])) { + $uid=intval($options["uid"]); + } else { + $uid=-1; + } + } else { + $uid=$cuid; + } + $result=$this->dom->get_domain_list($uid); + if (!$result) { + return $this->alterncLegacyErrorManager(); + } else { + $offset=-1; $count=-1; + if (isset($options["count"])) $count=intval($options["count"]); + if (isset($options["offset"])) $offset=intval($options["offset"]); + if ($offset!=-1 || $count!=-1) { + if ($offset<0 || $offset>count($result)) $offset=0; + if ($count<0 || $count>1000) $count=1000; + $result= array_slice($result, $offset, $count); + } + return new Alternc_Api_Response( array("content" =>$result) ); + } + } + + + + /** return a proper Alternc_Api_Response from an error class and error string + * from AlternC legacy class + */ + private function alterncLegacyErrorManager() { + global $err; + return new Alternc_Api_Response( array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[".$err->clsid."] ".$err->error) ); + } + + +} // class Alternc_Api_Object_Ssl \ No newline at end of file diff --git a/lib/Alternc/Api/Service.php b/lib/Alternc/Api/Service.php index 9bd06240..40d9e345 100644 --- a/lib/Alternc/Api/Service.php +++ b/lib/Alternc/Api/Service.php @@ -12,6 +12,7 @@ class Alternc_Api_Service { private $db; // PDO object private $loggerList; // List of loggers private $allowedAuth; // list of allowed authenticators + public $token; // Token (useful for called classes) const ERR_INVALID_ARGUMENT = 111801; const ERR_METHOD_DENIED = 111802;