Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.1.0.0
- * @ Author : DeZender
- * @ Release on : 15.05.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class RobotRestClient
- {
- private $curl;
- private $curlOptions = [];
- protected $httpHeader = [];
- protected $baseUrl;
- public function __construct($url, $user, $password, $verbose = false)
- {
- $this->baseUrl = rtrim($url, '/');
- $this->curl = curl_init();
- $this->setCurlOption(CURLOPT_RETURNTRANSFER, true);
- $this->setCurlOption(CURLOPT_USERPWD, $user . ':' . $password);
- $this->setCurlOption(CURLOPT_VERBOSE, $verbose);
- }
- public function __destruct()
- {
- curl_close($this->curl);
- }
- protected function setCurlOption($option, $value)
- {
- $this->curlOptions[$option] = $value;
- }
- protected function getCurlOption($option)
- {
- return isset($this->curlOptions[$option]) ? $this->curlOptions[$option] : NULL;
- }
- public function setHttpHeader($name, $value)
- {
- $this->httpHeader[$name] = $name . ': ' . $value;
- }
- protected function get($url)
- {
- $this->setCurlOption(CURLOPT_URL, $url);
- $this->setCurlOption(CURLOPT_HTTPGET, true);
- $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'GET');
- return $this->executeRequest();
- }
- protected function post($url, array $data = [])
- {
- $this->setCurlOption(CURLOPT_URL, $url);
- $this->setCurlOption(CURLOPT_POST, true);
- $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'POST');
- if ($data) {
- $this->setCurlOption(CURLOPT_POSTFIELDS, http_build_query($data));
- }
- return $this->executeRequest();
- }
- protected function put($url, array $data = [])
- {
- $this->setCurlOption(CURLOPT_URL, $url);
- $this->setCurlOption(CURLOPT_HTTPGET, true);
- $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT');
- if ($data) {
- $this->setCurlOption(CURLOPT_POSTFIELDS, http_build_query($data));
- }
- return $this->executeRequest();
- }
- protected function delete($url, array $data = [])
- {
- $this->setCurlOption(CURLOPT_URL, $url);
- $this->setCurlOption(CURLOPT_HTTPGET, true);
- $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'DELETE');
- if ($data) {
- $this->setCurlOption(CURLOPT_POSTFIELDS, http_build_query($data));
- }
- return $this->executeRequest();
- }
- protected function executeRequest()
- {
- $this->setCurlOption(CURLOPT_HTTPHEADER, array_values($this->httpHeader));
- curl_setopt_array($this->curl, $this->curlOptions);
- $response = curl_exec($this->curl);
- return ['response_code' => curl_getinfo($this->curl, CURLINFO_HTTP_CODE), 'response' => $response];
- }
- }
- class RobotClient extends RobotRestClient
- {
- const VERSION = '2018.06';
- protected $httpHeader = [];
- protected $baseUrl;
- public function __construct($projectID, $verbose = false)
- {
- if ($projectID == 0) {
- }
- else {
- $HetznerAccounts = WHMCS\Database\Capsule::table('mod_hetzner_account')->where(['id' => $projectID])->first();
- $url = 'https://robot-ws.your-server.de';
- $userDecrypt = $this->Hetzner_ED('decrypt', $HetznerAccounts->webuser);
- $PassDecrypt = $this->Hetzner_ED('decrypt', $HetznerAccounts->webpass);
- parent::__construct($url, $userDecrypt, $PassDecrypt, $verbose);
- $this->setHttpHeader('Accept', 'application/json');
- $this->setHttpHeader('User-Agent', 'HetznerRobotClient/2018.06');
- }
- }
- protected function executeRequest()
- {
- $result = parent::executeRequest();
- if ($result['response'] === false) {
- throw new RobotClientException('robot not reachable, upgrade curl in your server', 'NOT_REACHABLE');
- }
- if (empty($result['response'])) {
- $response = new StdClass();
- }
- else {
- $response = json_decode($result['response']);
- }
- if ($response === NULL) {
- throw new RobotClientException('response can not be decoded', 'RESPONSE_DECODE_ERROR');
- }
- if ((400 <= $result['response_code']) && ($result['response_code'] <= 503)) {
- throw new RobotClientException($response->error->message, $response->error->code);
- }
- return $response;
- }
- public function failoverGet($ip = NULL, ?array $query = NULL)
- {
- $url = $this->baseUrl . '/failover';
- if ($ip) {
- $url .= '/' . $ip;
- }
- if ($query) {
- $url .= '?' . http_build_query($query);
- }
- return $this->get($url);
- }
- public function failoverGetByServerIp($serverIp)
- {
- return $this->failoverGet(NULL, ['server_ip' => $serverIp]);
- ........................................................................
- ..........................................
- ..............
Add Comment
Please, Sign In to add comment