sitebuilder.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. * Enables the prod webpage
  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' => ['isenabled' => 'YES']];
  94. * or a json with ['status' => $httpCode,'response' => ['isenabled' => 'NO']];
  95. */
  96. public function enableprod($domain,$userName) {
  97. $url = "$this->apiUrl/enableprod/$username/$domain";
  98. return $this->sendRequest('GET', $url);
  99. }
  100. /**
  101. * Disables 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' => ['success' => 'Text']];
  107. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  108. */
  109. public function isprodenabled($domain,$userName) {
  110. $url = "$this->apiUrl/isprodenabled/$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' => ['ssl_expiry' => 'Datum des Ablaufs des Zertifikats', 'ssl_remaining' => 'Anzahl der Tage bis zum Ablauf des Zertifikats']];
  120. */
  121. public function getSSLDays($domain,$userName) {
  122. $url = "$this->apiUrl/getssldays/$username/$domain";
  123. return $this->sendRequest('GET', $url);
  124. }
  125. /**
  126. * Lists the Prod Backups for the prod webpage
  127. *
  128. * @param username: The username under which the domain is deployed
  129. * @param domain: The Domain to migrate
  130. *
  131. * @return a json with ['status' => $httpCode,'response' => [
  132. * 'backups' =>
  133. [
  134. * ['backup_date' => 'ISO Backup Datum',
  135. * 'swiss_date' => 'Datum im Schweizer Format',
  136. * 'size_mb' => 'Grösse in Megabyte',
  137. * 'filename' => 'Dateiname des tar.gz's'
  138. * ]
  139. * ];
  140. *
  141. */
  142. public function listbackups($domain,$userName) {
  143. $url = "$this->apiUrl/listbackups/$username/$domain";
  144. return $this->sendRequest('GET', $url);
  145. }
  146. /**
  147. * Restores a Backup with the given ISO Date
  148. *
  149. * @param username: The username under which the domain is deployed
  150. * @param domain: The Domain to migrate
  151. * @param backupDate: The ISO-Date of the backup (backup_date from listBackups) to restore
  152. *
  153. * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
  154. * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
  155. */
  156. public function restorebackup($domain,$userName,$backupDate) {
  157. $url = "$this->apiUrl/restorebackup/$username/$domain";
  158. $data = [
  159. 'backup_date' => $backupDate
  160. ];
  161. return $this->sendRequest('POST', $url, $data);
  162. }
  163. private function sendRequest($method, $url, $data = []) {
  164. $ch = curl_init();
  165. $options = [
  166. CURLOPT_URL => $url,
  167. CURLOPT_RETURNTRANSFER => true,
  168. CURLOPT_HTTPHEADER => [
  169. "X-Api-Key: $this->apiKey",
  170. "Content-Type: application/json"
  171. ],
  172. CURLOPT_CUSTOMREQUEST => $method,
  173. CURLOPT_SSL_VERIFYPEER => false, // Deaktiviert die Überprüfung des SSL-Zertifikats
  174. CURLOPT_SSL_VERIFYHOST => false // Akzeptiert alle Hostnamen
  175. ];
  176. if ($method === 'POST' && !empty($data)) {
  177. $options[CURLOPT_POSTFIELDS] = json_encode($data);
  178. }
  179. curl_setopt_array($ch, $options);
  180. $response = curl_exec($ch);
  181. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  182. curl_close($ch);
  183. return [
  184. 'status' => $httpCode,
  185. 'response' => json_decode($response, true)
  186. ];
  187. }
  188. }