sitebuilder.php 9.9 KB

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