sitebuilder.php 7.7 KB

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