Jump to content

WHMCS licensing addon issues (again)


anglian

Recommended Posts

OK, I am getting really frustrated with the licensing addon and the total lack of any support from WHMCS helpdesk.

 

I am hoping someone will do me a huge favour and provide a working licensing addon script (including .sql file) with license key and local keys saved to a database, for the following code

 

<?php
echo "Hello World!"; 
?>

 

I am sure I can manage to get the integration done eventually if I can only get a working version first.

Surely this is something that WHMCS should provide when the addon is purchased!

 

I know I would be very grateful for such code and it would help me a lot, and I am sure would be of great value to other members of the community.

Link to comment
Share on other sites

Hi,

Thanks for the reply, I have read them about 20 times, and even using the basic code & integration script there cannot get it to work

 

My code looks like

 

<?php
include 'licensefunction.php';

$licensekey = "vox12-613698c3a7";
$localkey = '';

$results = check_license($licensekey,$localkey);

if ($results["status"]=="Active") {

if (isset($_POST['add1'])) {
$result = $_POST['add1'] + $_POST['add2'];
echo $result;
}
?>
<form method="POST" action="#">
<input type="text" name="add1"> plus 
<input type="text" name="add2">
<input type="submit" value="Solve">
</form>

<?php

}
else {
echo 'License could not be verified';
}

?>

 

and

 

licensefunction.php is like

<?php
/*
*************************************************************************
*                                                                       *
* WHMCompleteSolution - Client Management, Billing & Support System     *
* Copyright (c) 2007-2012 WHMCS. All Rights Reserved,                   *
* Licensing Addon Integration Code                                      *
* Last Modified: 1st October 2010                                       *
*                                                                       *
*************************************************************************
*/

// Begin Check Function

function check_license($licensekey,$localkey="") {
   $whmcsurl = "http://mydomain.com/";
   $licensing_secret_key = "mysecretkey"; # Unique value, should match what is set in the product configuration for MD5 Hash Verification
   $check_token = time().md5(mt_rand(1000000000,9999999999).$licensekey);
   $checkdate = date("Ymd"); # Current date
   $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
   $localkeydays = 15; # How long the local key is valid for in between remote checks
   $allowcheckfaildays = 5; # How many days to allow after local key expiry before blocking access if connection cannot be made
   $localkeyvalid = false;
   if ($localkey) {
       $localkey = str_replace("\n",'',$localkey); # Remove the line breaks
	$localdata = substr($localkey,0,strlen($localkey)-32); # Extract License Data
	$md5hash = substr($localkey,strlen($localkey)-32); # Extract MD5 Hash
       if ($md5hash==md5($localdata.$licensing_secret_key)) {
           $localdata = strrev($localdata); # Reverse the string
   		$md5hash = substr($localdata,0,32); # Extract MD5 Hash
   		$localdata = substr($localdata,32); # Extract License Data
   		$localdata = base64_decode($localdata);
   		$localkeyresults = unserialize($localdata);
           $originalcheckdate = $localkeyresults["checkdate"];
           if ($md5hash==md5($originalcheckdate.$licensing_secret_key)) {
               $localexpiry = date("Ymd",mktime(0,0,0,date("m"),date("d")-$localkeydays,date("Y")));
               if ($originalcheckdate>$localexpiry) {
                   $localkeyvalid = true;
                   $results = $localkeyresults;
                   $validdomains = explode(",",$results["validdomain"]);
                   if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) {
                       $localkeyvalid = false;
                       $localkeyresults["status"] = "Invalid";
                       $results = array();
                   }
                   $validips = explode(",",$results["validip"]);
                   if (!in_array($usersip, $validips)) {
                       $localkeyvalid = false;
                       $localkeyresults["status"] = "Invalid";
                       $results = array();
                   }
                   if ($results["validdirectory"]!=dirname(__FILE__)) {
                       $localkeyvalid = false;
                       $localkeyresults["status"] = "Invalid";
                       $results = array();
                   }
               }
           }
       }
   }
   if (!$localkeyvalid) {
       $postfields["licensekey"] = $licensekey;
       $postfields["domain"] = $_SERVER['SERVER_NAME'];
       $postfields["ip"] = $usersip;
       $postfields["dir"] = dirname(__FILE__);
       if ($check_token) $postfields["check_token"] = $check_token;
       if (function_exists("curl_exec")) {
           $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, $whmcsurl."modules/servers/licensing/verify.php");
           curl_setopt($ch, CURLOPT_POST, 1);
           curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
           curl_setopt($ch, CURLOPT_TIMEOUT, 30);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           $data = curl_exec($ch);
           curl_close($ch);
       } else {
           $fp = fsockopen($whmcsurl, 80, $errno, $errstr, 5);
        if ($fp) {
       		$querystring = "";
               foreach ($postfields AS $k=>$v) {
                   $querystring .= "$k=".urlencode($v)."&";
               }
               $header="POST ".$whmcsurl."modules/servers/licensing/verify.php HTTP/1.0\r\n";
       		$header.="Host: ".$whmcsurl."\r\n";
       		$header.="Content-type: application/x-www-form-urlencoded\r\n";
       		$header.="Content-length: ".@strlen($querystring)."\r\n";
       		$header.="Connection: close\r\n\r\n";
       		$header.=$querystring;
       		$data="";
       		@stream_set_timeout($fp, 20);
       		@fputs($fp, $header);
       		$status = @socket_get_status($fp);
       		while (!@feof($fp)&&$status) {
       		    $data .= @fgets($fp, 1024);
       			$status = @socket_get_status($fp);
       		}
       		@fclose ($fp);
           }
       }
       if (!$data) {
           $localexpiry = date("Ymd",mktime(0,0,0,date("m"),date("d")-($localkeydays+$allowcheckfaildays),date("Y")));
           if ($originalcheckdate>$localexpiry) {
               $results = $localkeyresults;
           } else {
               $results["status"] = "Invalid";
               $results["description"] = "Remote Check Failed";
               return $results;
           }
       } else {
           preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches);
           $results = array();
           foreach ($matches[1] AS $k=>$v) {
               $results[$v] = $matches[2][$k];
           }
       }
       if ($results["md5hash"]) {
           if ($results["md5hash"]!=md5($licensing_secret_key.$check_token)) {
               $results["status"] = "Invalid";
               $results["description"] = "MD5 Checksum Verification Failed";
               return $results;
           }
       }
       if ($results["status"]=="Active") {
           $results["checkdate"] = $checkdate;
           $data_encoded = serialize($results);
           $data_encoded = base64_encode($data_encoded);
           $data_encoded = md5($checkdate.$licensing_secret_key).$data_encoded;
           $data_encoded = strrev($data_encoded);
           $data_encoded = $data_encoded.md5($data_encoded.$licensing_secret_key);
           $data_encoded = wordwrap($data_encoded,80,"\n",true);
           $results["localkey"] = $data_encoded;
       }
       $results["remotecheck"] = true;
   }
   unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash);
   return $results;
}

// End Check Function
?>

 

Can anyone see any reason why this does not work? The domain & secret key have been removed here but are correct in my actual test script

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated