Alternc  latest
Alternc logiel libre pour l'hébergement
Ssl.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * SSL Api of AlternC, used by alternc-api package
5  */
7 
8  protected $ssl;
9 
10  function __construct($service) {
11  global $ssl;
12  parent::__construct($service);
13  // We use the global $ssl from AlternC legacy classes
14  $this->ssl=$ssl;
15  }
16 
17  /** API Method from legacy class get_list()
18  * @param $options a hash with parameters transmitted to legacy call
19  * filter = the kind of ssl certificates to show or not show
20  * @return Alternc_Api_Response whose content is an array of hashes containing all corresponding certificates informations
21  */
22  function getList($options) {
23  if (isset($options["filter"]) && intval($options["filter"])) {
24  $filter=intval($options["filter"]);
25  } else {
26  $filter=null;
27  }
28  $ssllist=$this->ssl->get_list($filter);
29  return new Alternc_Api_Response( array("content" => $ssllist) );
30  }
31 
32 
33  /** API Method from legacy class new_csr()
34  * @param $options a hash with parameters transmitted to legacy call
35  * fqdn = the DNS name to create a CSR to
36  * @return Alternc_Api_Response whose content is the CSR ID in the certificate database
37  */
38  function newCsr($options) {
39  if (!isset($options["fqdn"]) || !is_string($options["fqdn"])) {
40  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: FQDN") );
41  }
42  $certid=$this->ssl->new_csr($options["fqdn"]);
43  if ($certid===false) {
44  return $this->alterncLegacyErrorManager();
45  }
46  return new Alternc_Api_Response( array("content" => $certid) );
47  }
48 
49 
50  /** API Method from legacy class get_certificate()
51  * @param $options a hash with parameters transmitted to legacy call
52  * id = the ID of the certificate in the certifiate table to get
53  * @return Alternc_Api_Response whose content is a hash with all informations for that certificate
54  */
55  function getCertificate($options) {
56  if (!isset($options["id"]) || !intval($options["id"])) {
57  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: ID") );
58  }
59  $certinfo=$this->ssl->get_certificate(intval($options["id"]));
60  if ($certinfo===false) {
61  return $this->alterncLegacyErrorManager();
62  }
63  return new Alternc_Api_Response( array("content" => $certinfo) );
64  }
65 
66 
67  /** API Method from legacy class share()
68  * @param $options a hash with parameters transmitted to legacy call
69  * id = the ID of the certificate to share or unshare
70  * action = boolean telling to share(true) or unshare(false) this certificate
71  * @return Alternc_Api_Response true.
72  */
73  function share($options) {
74  if (!isset($options["id"]) || !intval($options["id"])) {
75  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: ID") );
76  }
77  if (!isset($options["action"]) ) {
78  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: ACTION") );
79  }
80  $isok=$this->ssl->share(intval($options["id"]), (intval($options["action"]))? true : false );
81  if ($isok===false) {
82  return $this->alterncLegacyErrorManager();
83  }
84  return new Alternc_Api_Response( array("content" => $isok) );
85  }
86 
87 
88  /** API Method from legacy class import_cert()
89  * @param $options a hash with parameters transmitted to legacy call
90  * key, crt, chain = key and crt (both mandatory) and chain (not mandatory) to import
91  * @return Alternc_Api_Response the ID of the newly created certificate in the table.
92  */
93  function importCert($options) {
94  if (!isset($options["key"]) || !is_string($options["key"])) {
95  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: KEY") );
96  }
97  if (!isset($options["crt"]) || !is_string($options["crt"])) {
98  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: CRT") );
99  }
100  if (isset($options["chain"])) {
101  if (!is_string($options["chain"])) {
102  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Invalid argument: CHAIN") );
103  }
104  } else {
105  $options["chain"]="";
106  }
107 
108  $certid=$this->ssl->import_cert($options["key"],$options["crt"],$options["chain"]);
109  if ($certid===false) {
110  return $this->alterncLegacyErrorManager();
111  }
112  return new Alternc_Api_Response( array("content" => $certid) );
113  }
114 
115 
116  /** API Method from legacy class finalize()
117  * @param $options a hash with parameters transmitted to legacy call
118  * second part of the new_csr() call, finalize a certificate creation
119  * id = ID of the certificate to finalize in the table.
120  * crt = Certificate data
121  * chain = Chained Certificate date (not mandatory)
122  * @return Alternc_Api_Response the ID of the updated certificate in the table.
123  */
124  function finalize($options) {
125  if (!isset($options["id"]) || !intval($options["id"])) {
126  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: ID") );
127  }
128  if (!isset($options["crt"]) || !is_string($options["crt"])) {
129  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: CRT") );
130  }
131  if (isset($options["chain"])) {
132  if (!is_string($options["chain"])) {
133  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Invalid argument: CHAIN") );
134  }
135  } else {
136  $options["chain"]="";
137  }
138 
139  $certid=$this->ssl->finalize(intval($options["id"]),$options["crt"],$options["chain"]);
140  if ($certid===false) {
141  return $this->alterncLegacyErrorManager();
142  }
143  return new Alternc_Api_Response( array("content" => $certid) );
144  }
145 
146 
147  /** API Method from legacy class alias_add()
148  * @param $options a hash with parameters transmitted to legacy call
149  * add the alias 'name' with the content value 'value' in the global apache configuration
150  * @return Alternc_Api_Response true
151  */
152  function aliasAdd($options) {
153  if (!isset($options["name"]) || !is_string($options["name"])) {
154  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: NAME") );
155  }
156  if (!isset($options["content"]) || !is_string($options["content"])) {
157  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: CONTENT") );
158  }
159 
160  $isok=$this->ssl->alias_add($options["name"],$options["content"]);
161  if ($isok===false) {
162  return $this->alterncLegacyErrorManager();
163  }
164  return new Alternc_Api_Response( array("content" => $isok) );
165  }
166 
167 
168  /** API Method from legacy class alias_del()
169  * @param $options a hash with parameters transmitted to legacy call
170  * del the alias 'name' in the global apache configuration
171  * @return Alternc_Api_Response true
172  */
173  function aliasDel($options) {
174  if (!isset($options["name"]) || !is_string($options["name"])) {
175  return new Alternc_Api_Response( array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: NAME") );
176  }
177 
178  $isok=$this->ssl->alias_del($options["name"]);
179  if ($isok===false) {
180  return $this->alterncLegacyErrorManager();
181  }
182  return new Alternc_Api_Response( array("content" => $isok) );
183  }
184 
185 
186 
187 } // class Alternc_Api_Object_Ssl
Any Legacy AlternC Api should use this class as a parent to be able to handle properly the access rig...
Definition: Legacyobject.php:9
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class
SSL Api of AlternC, used by alternc-api package.
Definition: Ssl.php:6
share($options)
API Method from legacy class share()
Definition: Ssl.php:73
aliasAdd($options)
API Method from legacy class alias_add()
Definition: Ssl.php:152
__construct($service)
Definition: Ssl.php:10
getCertificate($options)
API Method from legacy class get_certificate()
Definition: Ssl.php:55
importCert($options)
API Method from legacy class import_cert()
Definition: Ssl.php:93
newCsr($options)
API Method from legacy class new_csr()
Definition: Ssl.php:38
getList($options)
API Method from legacy class get_list()
Definition: Ssl.php:22
aliasDel($options)
API Method from legacy class alias_del()
Definition: Ssl.php:173
finalize($options)
API Method from legacy class finalize()
Definition: Ssl.php:124
Standard Response object for the AlternC API.
Definition: Response.php:7