Advertisement
Guest User

Untitled

a guest
Aug 5th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. <?php
  2.  
  3. namespace WGS\HOSTXTEMPLATE;
  4.  
  5. if (!defined("WHMCS")) {
  6. exit("This file cannot be accessed directly");
  7. }
  8. class HOSTX
  9. {
  10. public function __construct()
  11. {
  12. }
  13. public function wgs_hostx_get_license($license)
  14. {
  15. function wgs_hostx_checkLicense($licensekey, $localkey = "")
  16. {
  17. $whmcsurl = "https://whmcs.atoznull.com/";
  18. $licensing_secret_key = "HOSTX-WHMCS-SOM-Rakesh";
  19. $check_token = time() . md5(mt_rand(1000000000, 10000000000.0) . $licensekey);
  20. $checkdate = date("Ymd");
  21. $usersip = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : $_SERVER["LOCAL_ADDR"];
  22. $localkeydays = 10;
  23. $allowcheckfaildays = 5;
  24. $localkeyvalid = false;
  25. $lkey = \WHMCS\Database\Capsule::table("tblconfiguration")->where("setting", "wgs_hostx_localkey")->get();
  26. if ($lkey) {
  27. $localkey = $lkey[0]->value;
  28. }
  29. if ($localkey) {
  30. $localkey = str_replace("\n", "", $localkey);
  31. $localdata = substr($localkey, 0, strlen($localkey) - 32);
  32. $md5hash = substr($localkey, strlen($localkey) - 32);
  33. if ($md5hash == md5($localdata . $licensing_secret_key)) {
  34. $localdata = strrev($localdata);
  35. $md5hash = substr($localdata, 0, 32);
  36. $localdata = substr($localdata, 32);
  37. $localdata = base64_decode($localdata);
  38. $localkeyresults = unserialize($localdata);
  39. $originalcheckdate = $localkeyresults["checkdate"];
  40. if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) {
  41. $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y")));
  42. if ($localexpiry < $originalcheckdate) {
  43. $localkeyvalid = true;
  44. $results = $localkeyresults;
  45. $validdomains = explode(",", $results["validdomain"]);
  46. if (!in_array($_SERVER["SERVER_NAME"], $validdomains)) {
  47. $localkeyvalid = false;
  48. $localkeyresults["status"] = "Invalid";
  49. $results = array();
  50. }
  51. $validips = explode(",", $results["validip"]);
  52. if (!in_array($usersip, $validips)) {
  53. $localkeyvalid = false;
  54. $localkeyresults["status"] = "Invalid";
  55. $results = array();
  56. }
  57. if ($results["validdirectory"] != dirname(__FILE__)) {
  58. $localkeyvalid = false;
  59. $localkeyresults["status"] = "Invalid";
  60. $results = array();
  61. }
  62. }
  63. }
  64. }
  65. }
  66. if (!$localkeyvalid) {
  67. $postfields["licensekey"] = $licensekey;
  68. $postfields["domain"] = $_SERVER["SERVER_NAME"];
  69. $postfields["ip"] = $usersip;
  70. $postfields["dir"] = dirname(__FILE__);
  71. if ($check_token) {
  72. $postfields["check_token"] = $check_token;
  73. }
  74. if (function_exists("curl_exec")) {
  75. $ch = curl_init();
  76. curl_setopt($ch, CURLOPT_URL, $whmcsurl . "modules/servers/licensing/verify.php");
  77. curl_setopt($ch, CURLOPT_POST, 1);
  78. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  79. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  80. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  81. $data = curl_exec($ch);
  82. curl_close($ch);
  83. } else {
  84. $fp = fsockopen($whmcsurl, 80, $errno, $errstr, 5);
  85. if ($fp) {
  86. $querystring = "";
  87. foreach ($postfields as $k => $v) {
  88. $querystring .= (string) $k . "=" . urlencode($v) . "&";
  89. }
  90. $header = "POST " . $whmcsurl . "modules/servers/licensing/verify.php HTTP/1.0\r\n";
  91. $header .= "Host: " . $whmcsurl . "\r\n";
  92. $header .= "Content-type: application/x-www-form-urlencoded\r\n";
  93. $header .= "Content-length: " . @strlen($querystring) . "\r\n";
  94. $header .= "Connection: close\r\n\r\n";
  95. $header .= $querystring;
  96. $data = "";
  97. @stream_set_timeout($fp, 20);
  98. @fputs($fp, $header);
  99. $status = @socket_get_status($fp);
  100. while (!feof($fp) && $status) {
  101. $data .= @fgets($fp, 1024);
  102. $status = @socket_get_status($fp);
  103. }
  104. @fclose($fp);
  105. }
  106. }
  107. if (!$data) {
  108. $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y")));
  109. if ($localexpiry < $originalcheckdate) {
  110. $results = $localkeyresults;
  111. } else {
  112. $results["status"] = "Invalid";
  113. $results["description"] = "Remote Check Failed";
  114. return $results;
  115. }
  116. }
  117. preg_match_all("/<(.*?)>([^<]+)<\\/\\1>/i", $data, $matches);
  118. $results = array();
  119. foreach ($matches[1] as $k => $v) {
  120. $results[$v] = $matches[2][$k];
  121. }
  122. if ($results["md5hash"] && $results["md5hash"] != md5($licensing_secret_key . $check_token)) {
  123. $results["status"] = "Invalid";
  124. $results["description"] = "MD5 Checksum Verification Failed";
  125. return $results;
  126. .............................................................................
  127. .......................................
  128. .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement