Guest User

Untitled

a guest
Jul 21st, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.1.0.0
  8. * @ Author : DeZender
  9. * @ Release on : 15.05.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class RobotRestClient
  15. {
  16. private $curl;
  17. private $curlOptions = [];
  18. protected $httpHeader = [];
  19. protected $baseUrl;
  20.  
  21. public function __construct($url, $user, $password, $verbose = false)
  22. {
  23. $this->baseUrl = rtrim($url, '/');
  24. $this->curl = curl_init();
  25. $this->setCurlOption(CURLOPT_RETURNTRANSFER, true);
  26. $this->setCurlOption(CURLOPT_USERPWD, $user . ':' . $password);
  27. $this->setCurlOption(CURLOPT_VERBOSE, $verbose);
  28. }
  29.  
  30. public function __destruct()
  31. {
  32. curl_close($this->curl);
  33. }
  34.  
  35. protected function setCurlOption($option, $value)
  36. {
  37. $this->curlOptions[$option] = $value;
  38. }
  39.  
  40. protected function getCurlOption($option)
  41. {
  42. return isset($this->curlOptions[$option]) ? $this->curlOptions[$option] : NULL;
  43. }
  44.  
  45. public function setHttpHeader($name, $value)
  46. {
  47. $this->httpHeader[$name] = $name . ': ' . $value;
  48. }
  49.  
  50. protected function get($url)
  51. {
  52. $this->setCurlOption(CURLOPT_URL, $url);
  53. $this->setCurlOption(CURLOPT_HTTPGET, true);
  54. $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'GET');
  55. return $this->executeRequest();
  56. }
  57.  
  58. protected function post($url, array $data = [])
  59. {
  60. $this->setCurlOption(CURLOPT_URL, $url);
  61. $this->setCurlOption(CURLOPT_POST, true);
  62. $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'POST');
  63.  
  64. if ($data) {
  65. $this->setCurlOption(CURLOPT_POSTFIELDS, http_build_query($data));
  66. }
  67.  
  68. return $this->executeRequest();
  69. }
  70.  
  71. protected function put($url, array $data = [])
  72. {
  73. $this->setCurlOption(CURLOPT_URL, $url);
  74. $this->setCurlOption(CURLOPT_HTTPGET, true);
  75. $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT');
  76.  
  77. if ($data) {
  78. $this->setCurlOption(CURLOPT_POSTFIELDS, http_build_query($data));
  79. }
  80.  
  81. return $this->executeRequest();
  82. }
  83.  
  84. protected function delete($url, array $data = [])
  85. {
  86. $this->setCurlOption(CURLOPT_URL, $url);
  87. $this->setCurlOption(CURLOPT_HTTPGET, true);
  88. $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'DELETE');
  89.  
  90. if ($data) {
  91. $this->setCurlOption(CURLOPT_POSTFIELDS, http_build_query($data));
  92. }
  93.  
  94. return $this->executeRequest();
  95. }
  96.  
  97. protected function executeRequest()
  98. {
  99. $this->setCurlOption(CURLOPT_HTTPHEADER, array_values($this->httpHeader));
  100. curl_setopt_array($this->curl, $this->curlOptions);
  101. $response = curl_exec($this->curl);
  102. return ['response_code' => curl_getinfo($this->curl, CURLINFO_HTTP_CODE), 'response' => $response];
  103. }
  104. }
  105.  
  106. class RobotClient extends RobotRestClient
  107. {
  108. const VERSION = '2018.06';
  109.  
  110. protected $httpHeader = [];
  111. protected $baseUrl;
  112.  
  113. public function __construct($projectID, $verbose = false)
  114. {
  115. if ($projectID == 0) {
  116. }
  117. else {
  118. $HetznerAccounts = WHMCS\Database\Capsule::table('mod_hetzner_account')->where(['id' => $projectID])->first();
  119. $url = 'https://robot-ws.your-server.de';
  120. $userDecrypt = $this->Hetzner_ED('decrypt', $HetznerAccounts->webuser);
  121. $PassDecrypt = $this->Hetzner_ED('decrypt', $HetznerAccounts->webpass);
  122. parent::__construct($url, $userDecrypt, $PassDecrypt, $verbose);
  123. $this->setHttpHeader('Accept', 'application/json');
  124. $this->setHttpHeader('User-Agent', 'HetznerRobotClient/2018.06');
  125. }
  126. }
  127.  
  128. protected function executeRequest()
  129. {
  130. $result = parent::executeRequest();
  131.  
  132. if ($result['response'] === false) {
  133. throw new RobotClientException('robot not reachable, upgrade curl in your server', 'NOT_REACHABLE');
  134. }
  135.  
  136. if (empty($result['response'])) {
  137. $response = new StdClass();
  138. }
  139. else {
  140. $response = json_decode($result['response']);
  141. }
  142.  
  143. if ($response === NULL) {
  144. throw new RobotClientException('response can not be decoded', 'RESPONSE_DECODE_ERROR');
  145. }
  146. if ((400 <= $result['response_code']) && ($result['response_code'] <= 503)) {
  147. throw new RobotClientException($response->error->message, $response->error->code);
  148. }
  149.  
  150. return $response;
  151. }
  152.  
  153. public function failoverGet($ip = NULL, ?array $query = NULL)
  154. {
  155. $url = $this->baseUrl . '/failover';
  156.  
  157. if ($ip) {
  158. $url .= '/' . $ip;
  159. }
  160.  
  161. if ($query) {
  162. $url .= '?' . http_build_query($query);
  163. }
  164.  
  165. return $this->get($url);
  166. }
  167.  
  168. public function failoverGetByServerIp($serverIp)
  169. {
  170. return $this->failoverGet(NULL, ['server_ip' => $serverIp]);
  171. ........................................................................
  172. ..........................................
  173. ..............
Add Comment
Please, Sign In to add comment