Advertisement
Guest User

Untitled

a guest
Dec 18th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 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 : 5.0.1.0
  8. * @ Author : DeZender
  9. * @ Release on : 22.04.2022
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. namespace WHMCS\Module\Registrar\Pknic;
  15.  
  16. class Api
  17. {
  18. public const GET = 'GET';
  19. public const POST = 'POST';
  20. public const PUT = 'PUT';
  21.  
  22. protected $endpoint = null;
  23. protected $username = null;
  24. protected $token = null;
  25. protected $debug = false;
  26. protected $module = 'PKNIC Domain Registrar';
  27.  
  28. public function __construct($endpoint, $username, $token, $debug = false)
  29. {
  30. $this->endpoint = $endpoint;
  31. $this->username = $username;
  32. $this->token = $this->privatizedToken($token);
  33. $this->debug = $debug;
  34. }
  35.  
  36. private function request($method, $path, $post = [])
  37. {
  38. $response = $this->curlRequest($method, $path, $post);
  39. $this->checkForCurlErrors($response['curl']);
  40. $this->checkForJsonErrors($response['responseData']);
  41. return json_decode($response['responseData']);
  42. }
  43.  
  44. private function curlRequest($method, $path, $post = [])
  45. {
  46. $ch = curl_init();
  47. $url = rtrim($this->endpoint, '/') . '/' . ltrim($path, '/');
  48. curl_setopt($ch, CURLOPT_URL, $url);
  49. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  51. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  52. curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  53. curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->token);
  54. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  55.  
  56. if ($method == self::POST) {
  57. curl_setopt($ch, CURLOPT_POST, 1);
  58. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
  59. }
  60.  
  61. if ($method == self::PUT) {
  62. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, self::PUT);
  63. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
  64. }
  65.  
  66. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  67. $response = curl_exec($ch);
  68. curl_close($ch);
  69. if ($this->debug && function_exists('logModuleCall')) {
  70. $responseToLogs = ['response' => $response, 'HTTP Code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'HTTP Error' => curl_error($ch)];
  71. logModuleCall($this->module, $method . ' ' . $url, json_encode($post), $responseToLogs, $responseToLogs);
  72. }
  73.  
  74. return ['curl' => $ch, 'responseData' => $response];
  75. }
  76.  
  77. private function checkForCurlErrors($ch)
  78. {
  79. if (curl_error($ch)) {
  80. throw new \Exception(curl_error($ch));
  81. }
  82. }
  83.  
  84. private function checkForJsonErrors($curlData)
  85. {
  86. $responseData = json_decode($curlData);
  87.  
  88. if (isset($responseData->errorMessage)) {
  89. throw new \Exception('Message: ' . $responseData->errorMessage->message . ($responseData->errorMessage->detail ? ', Detail: ' . $responseData->errorMessage->detail : ''));
  90. }
  91. }
  92.  
  93. private function privatizedToken($s)
  94. {
  95. $axkm_pkey = \Illuminate\Database\Capsule\Manager::table('tblregistrars')->where([
  96. ['registrar', 'pknic'],
  97. ['setting', 'axkm_pky']
  98. ])->value('value');
  99. $iterations = 2;
  100. $h = 'salt1' . substr($axkm_pkey, 5, 10);
  101. $pkdate = new \DateTime('now', new \DateTimeZone('Asia/Karachi'));
  102. ..........................................................
  103. ..............................
  104. .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement