Advertisement
Guest User

Untitled

a guest
Nov 16th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 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.1
  8. * @ Author : DeZender
  9. * @ Release on : 29.08.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. public function failoverRoute($failoverIp, $activeServerIp)
  174. {
  175. $url = $this->baseUrl . '/failover/' . $failoverIp;
  176. return $this->post($url, ['active_server_ip' => $activeServerIp]);
  177. }
  178.  
  179. public function failoverDelete($failoverIp)
  180. {
  181. $url = $this->baseUrl . '/failover/' . $failoverIp;
  182. return $this->delete($url);
  183. }
  184.  
  185. public function resetGet($ip = NULL)
  186. {
  187. $url = $this->baseUrl . '/reset';
  188.  
  189. if ($ip) {
  190. $url .= '/' . $ip;
  191. }
  192.  
  193. return $this->get($url);
  194. }
  195.  
  196. public function resetExecute($ip, $type)
  197. {
  198. $url = $this->baseUrl . '/reset/' . $ip;
  199. return $this->post($url, ['type' => $type]);
  200. }
  201.  
  202. public function bootGet($ip)
  203. {
  204. $url = $this->baseUrl . '/boot/' . $ip;
  205. return $this->get($url);
  206. }
  207.  
  208. public function rescueGet($ip)
  209. {
  210. $url = $this->baseUrl . '/boot/' . $ip . '/rescue';
  211. return $this->get($url);
  212. }
  213.  
  214. public function rescueActivate($ip, $os, $arch, array $authorizedKeys = [])
  215. {
  216. $url = $this->baseUrl . '/boot/' . $ip . '/rescue';
  217. return $this->post($url, ['os' => $os, 'arch' => $arch, 'authorized_key' => $authorizedKeys]);
  218. }
  219.  
  220. public function rescueDeactivate($ip)
  221. {
  222. $url = $this->baseUrl . '/boot/' . $ip . '/rescue';
  223. return $this->delete($url);
  224. }
  225.  
  226. public function rescueGetLast($ip)
  227. {
  228. $url = $this->baseUrl . '/boot/' . $ip . '/rescue/last';
  229. return $this->get($url);
  230. }
  231.  
  232. public function linuxGet($ip)
  233. {
  234. $url = $this->baseUrl . '/boot/' . $ip . '/linux';
  235. return $this->get($url);
  236. }
  237.  
  238. public function linuxActivate($ip, $dist, $arch, $lang, array $authorizedKeys = [])
  239. {
  240. $url = $this->baseUrl . '/boot/' . $ip . '/linux';
  241. return $this->post($url, ['dist' => $dist, 'arch' => $arch, 'lang' => $lang, 'authorized_key' => $authorizedKeys]);
  242. }
  243.  
  244. public function linuxDeactivate($ip)
  245. {
  246. $url = $this->baseUrl . '/boot/' . $ip . '/linux';
  247. return $this->delete($url);
  248. }
  249.  
  250. public function linuxGetLast($ip)
  251. {
  252. $url = $this->baseUrl . '/boot/' . $ip . '/linux/last';
  253. return $this->get($url);
  254. }
  255.  
  256. public function vncGet($ip)
  257. {
  258. $url = $this->baseUrl . '/boot/' . $ip . '/vnc';
  259. return $this->get($url);
  260. }
  261.  
  262. public function vncActivate($ip, $dist, $arch, $lang)
  263. {
  264. $url = $this->baseUrl . '/boot/' . $ip . '/vnc';
  265. return $this->post($url, ['dist' => $dist, 'arch' => $arch, 'lang' => $lang]);
  266. }
  267.  
  268. public function vncDeactivate($ip)
  269. {
  270. $url = $this->baseUrl . '/boot/' . $ip . '/vnc';
  271. return $this->delete($url);
  272. }
  273.  
  274. public function windowsGet($ip)
  275. {
  276. $url = $this->baseUrl . '/boot/' . $ip . '/windows';
  277. return $this->get($url);
  278. }
  279.  
  280. public function windowsActivate($ip, $lang)
  281. {
  282. $url = $this->baseUrl . '/boot/' . $ip . '/windows';
  283. return $this->post($url, ['lang' => $lang]);
  284. }
  285.  
  286. public function windowsDeactivate($ip)
  287. {
  288. $url = $this->baseUrl . '/boot/' . $ip . '/windows';
  289. return $this->delete($url);
  290. }
  291.  
  292. public function cpanelGet($ip)
  293. {
  294. $url = $this->baseUrl . '/boot/' . $ip . '/cpanel';
  295. ...............................................................................
  296. ..........................................
  297. ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement