sitebuilder.php 8.6 KB

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