apiUrl = rtrim($apiUrl, '/'); $this->apiKey = $apiKey; } /** * Initially deploy the webserver environment 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 init($userName, $domain, $adminName, $adminPassword): array { $url = "$this->apiUrl/init/$userName/$domain"; $data = [ 'admin_name' => $adminName, 'admin_password' => $adminPassword ]; return $this->sendRequest('POST', $url, $data); } /** * Disables the 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 disable($domain, $userName): array { $url = "$this->apiUrl/disable/$userName/$domain"; return $this->sendRequest('GET', $url); } /** * Enables the 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 enable($domain, $userName): array { $url = "$this->apiUrl/enableprod/$userName/$domain"; return $this->sendRequest('GET', $url); } /** * Returns certifikate informations * * @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); } /** * 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); } // helpers 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);