| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
-
- class ApiClient {
- private $apiUrl;
- private $apiKey;
-
- public function __construct($apiUrl, $apiKey) {
- $this->apiUrl = rtrim($apiUrl, '/');
- $this->apiKey = $apiKey;
- }
-
- /**
- * Check accessibility to the Server
- *
- * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param string $adminPassword A self randomly generated password
- *
- * @return string 'pong' on success
- *
- * Attention: The given parameters username, adminName and adminPassword must be
- * stored locally for the Single Sign on from whcms plugin
- *
- */
- public function ping($adminName, $adminPassword) {
- $url = "$this->apiUrl/ping/test/test";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Deploy the website to customers webspace
- *
- * @param string $username The username
- * @param string $domain The site to deploy
- * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param string $adminPassword A self randomly generated password
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- *
- * Attention: The given parameters username, adminName and adminPassword must be
- * stored locally for the Single Sign on from whcms plugin
- *
- */
- public function deploy($username, $domain, $adminName, $adminPassword) {
- $url = "$this->apiUrl/deploy/$username/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Initially deploy the placeholder site and config for the new website
- *
- * @param string $username The username
- * @param string $domain The site to init
- * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param string $adminPassword A self randomly generated password
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- *
- * 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) {
- $url = "$this->apiUrl/init/$username/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Re-init the site for the customer
- *
- * @param string $username The username
- * @param string $domain The site to revert
- * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param string $adminPassword A self randomly generated password
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- *
- * Attention: The given parameters username, adminName and adminPassword must be
- * stored locally for the Single Sign on from whcms plugin
- *
- */
- public function revert($username, $domain, $adminName, $adminPassword) {
- $url = "$this->apiUrl/revert/$username/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Removes the site for the customer
- *
- * @param string $username The username
- * @param string $domain The site to remove
- * @param string $adminName The Super-Admin User of the CRM System (usually the e-mail of the customer
- * @param string $adminPassword A self randomly generated password
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- *
- * Attention: The given parameters username, adminName and adminPassword must be
- * stored locally for the Single Sign on from whcms plugin
- *
- */
- public function undeploy($username, $domain, $adminName, $adminPassword) {
- $url = "$this->apiUrl/undeploy/$username/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Disables the webpage
- *
- * @param string $username The username
- * @param string $domain The site to disable
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- */
- public function disable($username, $domain) {
- $url = "$this->apiUrl/disable/$username/$domain";
- return $this->sendRequest('GET', $url);
- }
-
- /**
- * Creates a user and base configuration
- *
- * @param string $username The username
- * @param string $domain The site to create
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- */
- public function create($username, $domain, $adminName, $adminPassword) {
- $url = "$this->apiUrl/create/$username/$domain";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Removes a user and user configuration
- *
- * @param string $username The username
- * @param string $domain The base domain of the service
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- */
- public function terminate($username, $domain) {
- $url = "$this->apiUrl/terminate/$username/$domain";
- return $this->sendRequest('GET', $url);
- }
-
- /**
- * Enables the webpage
- *
- * @param string $username The username
- * @param string $domain The site to enable
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- */
- public function enable($username, $domain) {
- $url = "$this->apiUrl/enable/$username/$domain";
- return $this->sendRequest('GET', $url);
- }
-
-
- /**
- * Check a webpage for enabled state
- *
- * @param string $username The username
- * @param string $domain The site to check about
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- *
- */
- public function isenabled($username, $domain) {
- $url = "$this->apiUrl/isenabled/$username/$domain";
- return $this->sendRequest('GET', $url);
- }
-
- /**
- * Return users quota
- *
- * @param string $username The username
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- */
- public function getQuota($username) {
- $url = "$this->apiUrl/getquota/$username";
- return $this->sendRequest('GET', $url);
- }
-
- /**
- * Set users quota
- *
- * @param string $username The username
- * @param string $quota Quota in MegaBytes (MB)
- * @param string $adminName Admin user
- * @param string $adminPassword Admin password
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- */
- public function setQuota($username, $quota, $adminName, $adminPassword) {
- $url = "$this->apiUrl/setquota/$username";
- $data = [
- 'admin_name' => $adminName,
- 'admin_password' => $adminPassword,
- 'quota' => $quota,
- ];
- return $this->sendRequest('POST', $url, $data);
- }
-
- /**
- * Return users quota
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- */
- public function getStats() {
- $url = "$this->apiUrl/getstats";
- return $this->sendRequest('GET', $url);
- }
-
- /**
- * Return SSL informations
- *
- * @param string $username The username
- * @param string $domain The site to gater informations about
- *
- * @return array with ['status' => $httpCode,'response' => $response'];
- */
- public function getSSLDays($username, $domain) {
- $url = "$this->apiUrl/getssldays/$username/$domain";
- return $this->sendRequest('GET', $url);
- }
-
- // send request
- private function sendRequest($method, $url, $data = []) {
- $ch = curl_init();
-
- $options = [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPHEADER => [
- "X-Api-Key: $this->apiKey",
- "Content-Type: application/json"
- ],
- 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_POSTFIELDS] = json_encode($data);
- }
-
- 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)
- ];
- }
- }
|