sitebuilder.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 adminName: The Super-Admin User of the CRM System (usually the e-mail of the customer
  13. * @param 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. * Initially deploy the development site for the customer
  31. *
  32. * @param username: The username under which the domain is deployed
  33. * @param domain: The Domain to migrate
  34. * @param adminName: The Super-Admin User of the CRM System (usually the e-mail of the customer
  35. * @param adminPassword: A self randomly generated password
  36. *
  37. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  38. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  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 deployDev($username, $domain, $adminName, $adminPassword) {
  45. $url = "$this->apiUrl/deploydev/$username/$domain";
  46. $data = [
  47. 'admin_name' => $adminName,
  48. 'admin_password' => $adminPassword
  49. ];
  50. return $this->sendRequest('POST', $url, $data);
  51. }
  52. /**
  53. * Migrate dev site to prod site
  54. *
  55. * @param username: The username under which the domain is deployed
  56. * @param domain: The Domain to migrate
  57. * @param adminName: The Super-Admin User of the CRM System (usually the e-mail of the customer
  58. * @param adminPassword: A self randomly generated password
  59. *
  60. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  61. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  62. *
  63. * Attention: The given parameters adminName and adminPassword must be stored locally for the
  64. * Single Sign on from whcms plugin
  65. */
  66. public function migrateprod($username, $domain, $adminName, $adminPassword) {
  67. $url = "$this->apiUrl/migrateprod/$username/$domain";
  68. $data = [
  69. 'admin_name' => $adminName,
  70. 'admin_password' => $adminPassword
  71. ];
  72. return $this->sendRequest('POST', $url, $data);
  73. }
  74. /**
  75. * Disables the prod webpage
  76. *
  77. * @param username: The username under which the domain is deployed
  78. * @param domain: The Domain to migrate
  79. *
  80. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  81. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  82. */
  83. public function disableprod($domain,$username) {
  84. $url = "$this->apiUrl/disableprod/$username/$domain";
  85. return $this->sendRequest('GET', $url);
  86. }
  87. /**
  88. * Deletes the prod & dev webpages
  89. *
  90. * @param username: The username under which the domain is deployed
  91. * @param domain: The Domain to migrate
  92. *
  93. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  94. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  95. */
  96. public function terminate($domain,$username) {
  97. $url = "$this->apiUrl/terminate/$username/$domain";
  98. return $this->sendRequest('GET', $url);
  99. }
  100. /**
  101. * Enables the prod webpage
  102. *
  103. * @param username: The username under which the domain is deployed
  104. * @param domain: The Domain to migrate
  105. *
  106. * @return a json with ['status' => $httpCode,'response' => ['isenabled' => 'YES']];
  107. * or a json with ['status' => $httpCode,'response' => ['isenabled' => 'NO']];
  108. */
  109. public function enableprod($domain,$username) {
  110. $url = "$this->apiUrl/enableprod/$username/$domain";
  111. return $this->sendRequest('GET', $url);
  112. }
  113. /**
  114. * Disables the prod webpage
  115. *
  116. * @param username: The username under which the domain is deployed
  117. * @param domain: The Domain to migrate
  118. *
  119. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  120. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  121. */
  122. public function isprodenabled($domain,$username) {
  123. $url = "$this->apiUrl/isprodenabled/$username/$domain";
  124. return $this->sendRequest('GET', $url);
  125. }
  126. /**
  127. * Disables the prod webpage
  128. *
  129. * @param username: The username under which the domain is deployed
  130. * @param domain: The Domain to migrate
  131. *
  132. * @return a json with ['status' => $httpCode,'response' => ['ssl_expiry' => 'Datum des Ablaufs des Zertifikats', 'ssl_remaining' => 'Anzahl der Tage bis zum Ablauf des Zertifikats']];
  133. */
  134. public function getSSLDays($domain,$username) {
  135. $url = "$this->apiUrl/getssldays/$username/$domain";
  136. return $this->sendRequest('GET', $url);
  137. }
  138. /**
  139. * Lists the Prod Backups for the prod webpage
  140. *
  141. * @param username: The username under which the domain is deployed
  142. * @param domain: The Domain to migrate
  143. *
  144. * @return a json with ['status' => $httpCode,'response' => [
  145. * 'backups' =>
  146. * [
  147. * ['backup_date' => 'ISO Backup Datum',
  148. * 'swiss_date' => 'Datum im Schweizer Format',
  149. * 'size_mb' => 'Grösse in Megabyte',
  150. * 'filename' => 'Dateiname des tar.gz's'
  151. * ]
  152. * ];
  153. *
  154. */
  155. public function listbackups($domain,$username) {
  156. $url = "$this->apiUrl/listbackups/$username/$domain";
  157. return $this->sendRequest('GET', $url);
  158. }
  159. /**
  160. * Restores a Backup with the given ISO Date
  161. *
  162. * @param username: The username under which the domain is deployed
  163. * @param domain: The Domain to migrate
  164. * @param backupDate: The ISO-Date of the backup (backup_date from listBackups) to restore
  165. *
  166. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  167. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  168. */
  169. public function restorebackup($domain,$username,$backupDate) {
  170. $url = "$this->apiUrl/restorebackup/$username/$domain";
  171. $data = [
  172. 'backup_date' => $backupDate
  173. ];
  174. return $this->sendRequest('POST', $url, $data);
  175. }
  176. private function sendRequest($method, $url, $data = []) {
  177. $ch = curl_init();
  178. $options = [
  179. CURLOPT_URL => $url,
  180. CURLOPT_RETURNTRANSFER => true,
  181. CURLOPT_HTTPHEADER => [
  182. "X-Api-Key: $this->apiKey",
  183. "Content-Type: application/json"
  184. ],
  185. CURLOPT_CUSTOMREQUEST => $method,
  186. CURLOPT_SSL_VERIFYPEER => false, // Deaktiviert die Überprüfung des SSL-Zertifikats
  187. CURLOPT_SSL_VERIFYHOST => false // Akzeptiert alle Hostnamen
  188. ];
  189. if ($method === 'POST' && !empty($data)) {
  190. $options[CURLOPT_POSTFIELDS] = json_encode($data);
  191. }
  192. curl_setopt_array($ch, $options);
  193. $response = curl_exec($ch);
  194. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  195. curl_close($ch);
  196. return [
  197. 'status' => $httpCode,
  198. 'response' => json_decode($response, true)
  199. ];
  200. }
  201. }