sitebuilder.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. class ApiClient {
  3. private $apiUrl;
  4. private $apiKey;
  5. public function __construct($apiUrl, $apiKey) {
  6. $this->apiUrl = rtrim($apiUrl, '/');
  7. $this->apiKey = $apiKey;
  8. }
  9. /**
  10. * Check accessibility to the Server
  11. *
  12. * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
  13. * @param string $adminPassword A self randomly generated password
  14. *
  15. * @return string 'pong' on success
  16. *
  17. * Attention: The given parameters username, adminName and adminPassword must be
  18. * stored locally for the Single Sign on from whcms plugin
  19. *
  20. */
  21. public function ping($adminName, $adminPassword) {
  22. $url = "$this->apiUrl/ping/test/test";
  23. $data = [
  24. 'admin_name' => $adminName,
  25. 'admin_password' => $adminPassword
  26. ];
  27. return $this->sendRequest('POST', $url, $data);
  28. }
  29. /**
  30. * Deploy the website to customers webspace
  31. *
  32. * @param string $username The username
  33. * @param string $domain The site to deploy
  34. * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
  35. * @param string $adminPassword A self randomly generated password
  36. *
  37. * @return array with ['status' => $httpCode,'response' => $response'];
  38. *
  39. *
  40. * Attention: The given parameters username, adminName and adminPassword must be
  41. * stored locally for the Single Sign on from whcms plugin
  42. *
  43. */
  44. public function deploy($username, $domain, $adminName, $adminPassword) {
  45. $url = "$this->apiUrl/deploy/$username/$domain";
  46. $data = [
  47. 'admin_name' => $adminName,
  48. 'admin_password' => $adminPassword
  49. ];
  50. return $this->sendRequest('POST', $url, $data);
  51. }
  52. /**
  53. * Initially deploy the placeholder site and config for the new website
  54. *
  55. * @param string $username The username
  56. * @param string $domain The site to init
  57. * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
  58. * @param string $adminPassword A self randomly generated password
  59. *
  60. * @return array with ['status' => $httpCode,'response' => $response'];
  61. *
  62. *
  63. * Attention: The given parameters username, adminName and adminPassword must be
  64. * stored locally for the Single Sign on from whcms plugin
  65. *
  66. */
  67. public function init($username, $domain, $adminName, $adminPassword) {
  68. $url = "$this->apiUrl/init/$username/$domain";
  69. $data = [
  70. 'admin_name' => $adminName,
  71. 'admin_password' => $adminPassword
  72. ];
  73. return $this->sendRequest('POST', $url, $data);
  74. }
  75. /**
  76. * Re-init the site for the customer
  77. *
  78. * @param string $username The username
  79. * @param string $domain The site to revert
  80. * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
  81. * @param string $adminPassword A self randomly generated password
  82. *
  83. * @return array with ['status' => $httpCode,'response' => $response'];
  84. *
  85. *
  86. * Attention: The given parameters username, adminName and adminPassword must be
  87. * stored locally for the Single Sign on from whcms plugin
  88. *
  89. */
  90. public function revert($username, $domain, $adminName, $adminPassword) {
  91. $url = "$this->apiUrl/revert/$username/$domain";
  92. $data = [
  93. 'admin_name' => $adminName,
  94. 'admin_password' => $adminPassword
  95. ];
  96. return $this->sendRequest('POST', $url, $data);
  97. }
  98. /**
  99. * Removes the site for the customer
  100. *
  101. * @param string $username The username
  102. * @param string $domain The site to remove
  103. * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
  104. * @param string $adminPassword A self randomly generated password
  105. *
  106. * @return array with ['status' => $httpCode,'response' => $response'];
  107. *
  108. *
  109. * Attention: The given parameters username, adminName and adminPassword must be
  110. * stored locally for the Single Sign on from whcms plugin
  111. *
  112. */
  113. public function undeploy($username, $domain, $adminName, $adminPassword) {
  114. $url = "$this->apiUrl/undeploy/$username/$domain";
  115. $data = [
  116. 'admin_name' => $adminName,
  117. 'admin_password' => $adminPassword
  118. ];
  119. return $this->sendRequest('POST', $url, $data);
  120. }
  121. /**
  122. * Disables the webpage
  123. *
  124. * @param string $username The username
  125. * @param string $domain The site to disable
  126. *
  127. * @return array with ['status' => $httpCode,'response' => $response'];
  128. *
  129. */
  130. public function disable($username, $domain) {
  131. $url = "$this->apiUrl/disable/$username/$domain";
  132. return $this->sendRequest('GET', $url);
  133. }
  134. /**
  135. * Creates a user and base configuration
  136. *
  137. * @param string $username The username
  138. * @param string $domain The site to create
  139. *
  140. * @return array with ['status' => $httpCode,'response' => $response'];
  141. *
  142. */
  143. public function create($username, $domain, $adminName, $adminPassword) {
  144. $url = "$this->apiUrl/create/$username/$domain";
  145. $data = [
  146. 'admin_name' => $adminName,
  147. 'admin_password' => $adminPassword
  148. ];
  149. return $this->sendRequest('POST', $url, $data);
  150. }
  151. /**
  152. * Removes a user and user configuration
  153. *
  154. * @param string $username The username
  155. * @param string $domain The base domain of the service
  156. *
  157. * @return array with ['status' => $httpCode,'response' => $response'];
  158. *
  159. */
  160. public function terminate($username, $domain) {
  161. $url = "$this->apiUrl/terminate/$username/$domain";
  162. return $this->sendRequest('GET', $url);
  163. }
  164. /**
  165. * Enables the webpage
  166. *
  167. * @param string $username The username
  168. * @param string $domain The site to enable
  169. *
  170. * @return array with ['status' => $httpCode,'response' => $response'];
  171. *
  172. */
  173. public function enable($username, $domain) {
  174. $url = "$this->apiUrl/enable/$username/$domain";
  175. return $this->sendRequest('GET', $url);
  176. }
  177. /**
  178. * Check a webpage for enabled state
  179. *
  180. * @param string $username The username
  181. * @param string $domain The site to check about
  182. *
  183. * @return array with ['status' => $httpCode,'response' => $response'];
  184. *
  185. */
  186. public function isenabled($username, $domain) {
  187. $url = "$this->apiUrl/isenabled/$username/$domain";
  188. return $this->sendRequest('GET', $url);
  189. }
  190. /**
  191. * Return users quota
  192. *
  193. * @param string $username The username
  194. *
  195. * @return array with ['status' => $httpCode,'response' => $response'];
  196. */
  197. public function getQuota($username) {
  198. $url = "$this->apiUrl/getquota/$username";
  199. return $this->sendRequest('GET', $url);
  200. }
  201. /**
  202. * Set users quota
  203. *
  204. * @param string $username The username
  205. * @param string $quota Quota in MegaBytes (MB)
  206. * @param string $adminName Admin user
  207. * @param string $adminPassword Admin password
  208. *
  209. * @return array with ['status' => $httpCode,'response' => $response'];
  210. */
  211. public function setQuota($username, $quota, $adminName, $adminPassword) {
  212. $url = "$this->apiUrl/setquota/$username";
  213. $data = [
  214. 'admin_name' => $adminName,
  215. 'admin_password' => $adminPassword,
  216. 'quota' => $quota,
  217. ];
  218. return $this->sendRequest('POST', $url, $data);
  219. }
  220. /**
  221. * Return users quota
  222. *
  223. * @return array with ['status' => $httpCode,'response' => $response'];
  224. */
  225. public function getStats() {
  226. $url = "$this->apiUrl/getstats";
  227. return $this->sendRequest('GET', $url);
  228. }
  229. /**
  230. * Return SSL informations
  231. *
  232. * @param string $username The username
  233. * @param string $domain The site to gater informations about
  234. *
  235. * @return array with ['status' => $httpCode,'response' => $response'];
  236. */
  237. public function getSSLDays($username, $domain) {
  238. $url = "$this->apiUrl/getssldays/$username/$domain";
  239. return $this->sendRequest('GET', $url);
  240. }
  241. // send request
  242. private function sendRequest($method, $url, $data = []) {
  243. $ch = curl_init();
  244. $options = [
  245. CURLOPT_URL => $url,
  246. CURLOPT_RETURNTRANSFER => true,
  247. CURLOPT_HTTPHEADER => [
  248. "X-Api-Key: $this->apiKey",
  249. "Content-Type: application/json"
  250. ],
  251. CURLOPT_CUSTOMREQUEST => $method,
  252. CURLOPT_SSL_VERIFYPEER => false, // Deaktiviert die Überprüfung des SSL-Zertifikats
  253. CURLOPT_SSL_VERIFYHOST => false // Akzeptiert alle Hostnamen
  254. ];
  255. if ($method === 'POST' && !empty($data)) {
  256. $options[CURLOPT_POSTFIELDS] = json_encode($data);
  257. }
  258. curl_setopt_array($ch, $options);
  259. $response = curl_exec($ch);
  260. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  261. curl_close($ch);
  262. return [
  263. 'status' => $httpCode,
  264. 'response' => json_decode($response, true)
  265. ];
  266. }
  267. }