Advertisement
johnburn

[lib.php] Decoded for: [email protected]

Jul 19th, 2011
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.71 KB | None | 0 0
  1. <?php
  2. function check_license($licensekey, $localkey) {
  3.     $chy = curl_init();
  4.     curl_setopt($chy, CURLOPT_URL, "http://portal.syslint.com/modules/servers/licensing/wimip.php");
  5.     curl_setopt($chy, CURLOPT_RETURNTRANSFER, 1);
  6.     $ip = curl_exec($chy);
  7.     $HIP = $ip;
  8.     curl_close($chy);
  9.     $whmcsurl = "http://portal.syslint.com/";
  10.     $licensing_secret_key = "cs+PWxyjyprot4pc4xebwzkbf";
  11.     $checkdate = date("Ymd");
  12.     $usersip = $ip;
  13.     $localkeydays = 7;
  14.     $allowcheckfaildays = 2;
  15.     $localkeyvalid = false;
  16.     if ($localkey) {
  17.         $localkey = str_replace("\n", "", $localkey);
  18.         $localdata = substr();
  19.         $md5hash = substr($localkey, strlen($localkey) - 32);
  20.         if ($md5hash == md5($localdata . $licensing_secret_key)) {
  21.             $localdata = strrev($localdata);
  22.             $md5hash = substr($localdata, 0, 32);
  23.             $localdata = substr($localdata, 32);
  24.             $localdata = base64_decode($localdata);
  25.             $localkeyresults = unserialize($localdata);
  26.             $originalcheckdate = $localkeyresults['checkdate'];
  27.             if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) {
  28.                 $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y")));
  29.                 if ($localexpiry < $originalcheckdate) {
  30.                     $localkeyvalid = true;
  31.                     $results = $localkeyresults;
  32.                     $validdomains = explode(",", $results['validdomain']);
  33.                     if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) {
  34.                         $localkeyvalid = false;
  35.                         $localkeyresults['status'] = "Invalid";
  36.                         $results = array();
  37.                     }
  38.                     $validips = explode(",", $results['validip']);
  39.                     if (!in_array($usersip, $validips)) {
  40.                         $localkeyvalid = false;
  41.                         $localkeyresults['status'] = "Invalid";
  42.                         $results = array();
  43.                     }
  44.                     if ($results['validdirectory'] != dirname(__FILE__)) {
  45.                         $localkeyvalid = false;
  46.                         $localkeyresults['status'] = "Invalid";
  47.                         $results = array();
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.     }
  53.     if (!$localkeyvalid) {
  54.         if (isset($_SERVER['HOSTNAME'])) {
  55.             $hostname = trim($_SERVER['HOSTNAME']);
  56.         } else {
  57.             $hostname = "localhost";
  58.         }
  59.         $postfields['licensekey'] = $licensekey;
  60.         $postfields['domain'] = $hostname;
  61.         $postfields['ip'] = $HIP;
  62.         $postfields['dir'] = "/usr/local/directadmin/plugins/danginx";
  63.         if (function_exists("curl_exec")) {
  64.             $ch = curl_init();
  65.             curl_setopt($ch, CURLOPT_URL, $whmcsurl . "modules/servers/licensing/verify.php");
  66.             curl_setopt($ch, CURLOPT_POST, 1);
  67.             curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  68.             curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  69.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  70.             $data = curl_exec($ch);
  71.             curl_close($ch);
  72.         } else {
  73.             $fp = fsockopen($whmcsurl, 80, $errno, $errstr, 5);
  74.             if ($fp) {
  75.                 $querystring = "";
  76.                 foreach($postfields as $k => $v) {
  77.                     $querystring.= "{$k}=" . urlencode($v) . "&";
  78.                 }
  79.                 $header = "POST " . $whmcsurl . "modules/servers/licensing/verify.php HTTP/1.0\r\n";
  80.                 $header.= "Host: " . $whmcsurl . "\r\n";
  81.                 $header.= "Content-type: application/x-www-form-urlencoded\r\n";
  82.                 $header.= "Content-length: " . @strlen(@$querystring) . "\r\n";
  83.                 $header.= "Connection: close\r\n\r\n";
  84.                 $header.= $querystring;
  85.                 $data = "";
  86.                 @stream_set_timeout(@$fp, 20);
  87.                 @fputs(@$fp, @$header);
  88.                 $status = @socket_get_status(@$fp);
  89.                 while (!feof(@$fp) && $status) {
  90.                     $data.= @fgets(@$fp, 1024);
  91.                     $status = @socket_get_status(@$fp);
  92.                 }
  93.                 @fclose(@$fp);
  94.             }
  95.         }
  96.         if (!$data) {
  97.             $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y")));
  98.             if ($localexpiry < $originalcheckdate) {
  99.                 $results = $localkeyresults;
  100.             } else {
  101.                 $results['status'] = "Remote Check Failed";
  102.                 return $results;
  103.             }
  104.         }
  105.         preg_match_all("/<(.*?)>([^<]+)<\\/\\1>/i", $data, $matches);
  106.         $results = array();
  107.         foreach($matches[1] as $k => $v) {
  108.             $results[$v] = $matches[2][$k];
  109.         }
  110.         if ($results['status'] == "Active") {
  111.             $results['checkdate'] = $checkdate;
  112.             $data_encoded = serialize($results);
  113.             $data_encoded = base64_encode($data_encoded);
  114.             $data_encoded = md5($checkdate . $licensing_secret_key) . $data_encoded;
  115.             $data_encoded = strrev($data_encoded);
  116.             $data_encoded = $data_encoded . md5($data_encoded . $licensing_secret_key);
  117.             $data_encoded = wordwrap($data_encoded, 80, "\n", true);
  118.             $results['localkey'] = $data_encoded;
  119.         }
  120.         $results['remotecheck'] = true;
  121.     }
  122.     unset($postfields);
  123.     unset($data);
  124.     unset($matches);
  125.     unset($whmcsurl);
  126.     unset($licensing_secret_key);
  127.     unset($checkdate);
  128.     unset($usersip);
  129.     unset($localkeydays);
  130.     unset($allowcheckfaildays);
  131.     unset($md5hash);
  132.     return $results;
  133. }
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement