| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- class ApiClient {
- private string $apiUrl;
- private string $apiKey;
- /**
- * @param $apiUrl
- * @param $apiKey
- */
- public function __construct($apiUrl, $apiKey) {
- $this->apiUrl = rtrim($apiUrl, '/');
- $this->apiKey = $apiKey;
- }
- /**
- * Initially deploy the development site for the customer
- *
- * @param $userName : The username under which the domain is deployed
- * @param $domain : The Domain to migrate
- * @param $adminName : The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param $adminPassword : A self randomly generated password
- *
- * @return array a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
- * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
- *
- * Attention: The given parameters username, adminName and adminPassword must be
- * stored locally for the Single Sign on from whcms plugin
- */
- public function deployDev($userName, $domain, $adminName, $adminPassword): array {
- $url = "$this->apiUrl/deploydev/$userName/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
- /**
- * Migrate dev site to prod site
- *
- * @param $userName: The username under which the domain is deployed
- * @param $domain: The Domain to migrate
- * @param $adminName: The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param $adminPassword: A self randomly generated password
- *
- * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
- * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
- *
- * Attention: The given parameters adminName and adminPassword must be stored locally for the
- * Single Sign on from whcms plugin
- */
- public function migrateprod($userName, $domain, $adminName, $adminPassword): array {
- $url = "$this->apiUrl/migrateprod/$userName/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
- /**
- * Disables the prod webpage
- *
- * @param username: The username under which the domain is deployed
- * @param domain: The Domain to migrate
- *
- * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
- * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
- */
- public function disableprod($domain, $userName): array {
- $url = "$this->apiUrl/disableprod/$userName/$domain";
- return $this->sendRequest('GET', $url);
- }
- /**
- * Enables the prod webpage
- *
- * @param username: The username under which the domain is deployed
- * @param domain: The Domain to migrate
- *
- * @return a json with ['status' => $httpCode,'response' => ['isenabled' => 'YES']];
- * or a json with ['status' => $httpCode,'response' => ['isenabled' => 'NO']];
- */
- public function enableprod($domain, $userName): array {
- $url = "$this->apiUrl/enableprod/$userName/$domain";
- return $this->sendRequest('GET', $url);
- }
- /**
- * Disables the prod webpage
- *
- * @param username: The username under which the domain is deployed
- * @param domain: The Domain to migrate
- *
- * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
- * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
- */
- public function isprodenabled($domain, $userName): array {
- $url = "$this->apiUrl/isprodenabled/$userName/$domain";
- return $this->sendRequest('GET', $url);
- }
- /**
- * Disables the prod webpage
- *
- * @param username: The username under which the domain is deployed
- * @param domain: The Domain to migrate
- *
- * @return a json with ['status' => $httpCode,'response' => ['ssl_expiry' => 'Datum des Ablaufs des Zertifikats', 'ssl_remaining' => 'Anzahl der Tage bis zum Ablauf des Zertifikats']];
- */
- public function getSSLDays($domain, $userName): array {
- $url = "$this->apiUrl/getssldays/$userName/$domain";
- return $this->sendRequest('GET', $url);
- }
- /**
- * Lists the Prod Backups for the prod webpage
- *
- * @param username: The username under which the domain is deployed
- * @param domain: The Domain to migrate
- *
- * @return a json with ['status' => $httpCode,'response' => [
- * 'backups' =>
- * [
- * ['backup_date' => 'ISO Backup Datum',
- * 'swiss_date' => 'Datum im Schweizer Format',
- * 'size_mb' => 'Grösse in Megabyte',
- * 'filename' => 'Dateiname des tar.gz's'
- * ]
- * ];
- *
- */
- public function listbackups($domain, $userName): array {
- $url = "$this->apiUrl/listbackups/$userName/$domain";
- return $this->sendRequest('GET', $url);
- }
- /**
- * Restores a Backup with the given ISO Date
- *
- * @param username: The username under which the domain is deployed
- * @param domain: The Domain to migrate
- * @param backupDate: The ISO-Date of the backup (backup_date from listBackups) to restore
- *
- * @return a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
- * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
- */
- public function restorebackup($domain, $userName, $backupDate): array {
- $url = "$this->apiUrl/restorebackup/$userName/$domain";
- $data = [
- 'backup_date' => $backupDate
- ];
- return $this->sendRequest('POST', $url, $data);
- }
- /**
- * Terminates a Website permanently
- *
- * @param $domain : The domain to terminate (terminates dev and prod website)
- * @param $userName : The username under which the domain is deployed
- * @return array : a json with ['status' => $httpCode,'response' => ['success' => 'Text']];
- * or a json with ['status' => $httpCode,'response' => ['error' => 'Error-Description']];
- */
- public function terminate($domain, $userName): array {
- $url = "$this->apiUrl/terminate/$userName/$domain";
- return $this->sendRequest('GET', $url);
- }
- private function sendRequest($method, $url, $data = []): array {
- $ch = curl_init();
- error_log("SEND REQUEST: " . print_r($data, true));
- $options = [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPHEADER => [
- "X-Api-Key: $this->apiKey",
- "Content-Type: application/json"
- ],
- CURLOPT_CONNECTTIMEOUT => 0,
- CURLOPT_TIMEOUT => 400,
- //CURLOPT_CUSTOMREQUEST => $method,
- CURLOPT_SSL_VERIFYPEER => false, // Deaktiviert die Überprüfung des SSL-Zertifikats
- CURLOPT_SSL_VERIFYHOST => false // Akzeptiert alle Hostnamen
- ];
- if ($method === 'POST' && !empty($data)) {
- $options[CURLOPT_POST] = true;
- // $options[CURLOPT_POSTFIELDS] = $data;
- $options[CURLOPT_POSTFIELDS] = json_encode($data,true);
- }
- curl_setopt_array($ch, $options);
- $response = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- return [
- 'status' => $httpCode,
- 'response' => json_decode($response, true)
- ];
- }
- }
- // Beispielnutzung mit HTTPS
- $apiClient = new ApiClient('https://vm-dc-builderhost-01.thurdata.local', 'your-secure-password');
- //$response = $apiClient->getSSLDays('exampleuser', 'example.com');
- $response = $apiClient->deployDev('roka101', 'tech-design.ch', 'info@tech-design.ch', 'Technics2312');
- print_r($response);
|