Lui2004 Posted November 27, 2015 Share Posted November 27, 2015 hi everybody i am setting up the licensing module for a friend because he want sell hie own licences and secure his php. so my problem is that the module dont call back i dont get any infos about valid ip - valid domain ecc thats my check_sample_code.php renamed in check_code.php <?php /** * WHMCS Licensing Addon - Integration Code Sample * http://www.whmcs.com/addons/licensing-addon/ * * The following code is a fully working code sample demonstrating how to * perform license checks using the WHMCS Licensing Addon. It is PHP 4 and * 5 compatible. Requires the WHMCS Licensing Addon to be used. * * @package WHMCS * @author WHMCS Limited <development@whmcs.com> * @copyright Copyright (c) WHMCS Limited 2005-2014 * @license http://www.whmcs.com/license/ WHMCS Eula * @version $Id$ * @link http://www.whmcs.com/ */ /** * This is just example code, and is not intended to be invoked directly. * * To ensure this code isn't unintentionally invoked on the command line or * via the web interface, any attempt to actually execute this code will * be exited: */ /** * If you are using this file as a template for your own module, once * you've modified the code for your use, remove the exit above. */ // Replace "yourprefix" with your own unique prefix to avoid conflicts with // other instances of the licensing addon included within the same scope function check_license($licensekey,$localkey='') { // ----------------------------------- // -- Configuration Values -- // ----------------------------------- // Enter the url to your WHMCS installation here $whmcsurl = 'http://myhostip/'; // Must match what is specified in the MD5 Hash Verification field // of the licensing product that will be used with this check. $licensing_secret_key = 'i have insert the correct one from licensing module'; // The number of days to wait between performing remote license checks $localkeydays = 15; // The number of days to allow failover for after local key expiry $allowcheckfaildays = 5; // ----------------------------------- // -- Do not edit below this line -- // ----------------------------------- $check_token = time() . md5(mt_rand(1000000000, 9999999999) . $licensekey); $checkdate = date("Ymd"); $domain = $_SERVER['SERVER_NAME']; $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; $dirpath = dirname(__FILE__); $verifyfilepath = 'modules/servers/licensing/verify.php'; $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(); } $validdirs = explode(',', $results['validdirectory']); if (!in_array($dirpath, $validdirs)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } } } } } if (!$localkeyvalid) { $responseCode = 0; $postfields = array( 'licensekey' => $licensekey, 'domain' => $domain, 'ip' => $usersip, 'dir' => $dirpath, ); if ($check_token) $postfields['check_token'] = $check_token; $query_string = ''; foreach ($postfields AS $k=>$v) { $query_string .= $k.'='.urlencode($v).'&'; } if (function_exists('curl_exec')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsurl . $verifyfilepath); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { $responseCodePattern = '/^HTTP\/\d+\.\d+\s+(\d+)/'; $fp = @fsockopen($whmcsurl, 80, $errno, $errstr, 5); if ($fp) { $newlinefeed = "\r\n"; $header = "POST ".$whmcsurl . $verifyfilepath . " HTTP/1.0" . $newlinefeed; $header .= "Host: ".$whmcsurl . $newlinefeed; $header .= "Content-type: application/x-www-form-urlencoded" . $newlinefeed; $header .= "Content-length: ".@strlen($query_string) . $newlinefeed; $header .= "Connection: close" . $newlinefeed . $newlinefeed; $header .= $query_string; $data = $line = ''; @stream_set_timeout($fp, 20); @fputs($fp, $header); $status = @socket_get_status($fp); while (!@feof($fp)&&$status) { $line = @fgets($fp, 1024); $patternMatches = array(); if (!$responseCode && preg_match($responseCodePattern, trim($line), $patternMatches) ) { $responseCode = (empty($patternMatches[1])) ? 0 : $patternMatches[1]; } $data .= $line; $status = @socket_get_status($fp); } @fclose ($fp); } } if ($responseCode != 200) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y"))); if ($originalcheckdate > $localexpiry) { $results = $localkeyresults; } else { $results = array(); $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 (!is_array($results)) { die("Invalid License Server Response"); } 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; } $licensekey = mysql_result(mysql_query("SELECT license_key FROM mod_licensing LIMIT 1"), 0); //Gets the license key from the database $localkey = mysql_result(mysql_query("SELECT local_key FROM mod_licensing LIMIT 1"), 0); //Gets the local key from the database // Validate the license key information $results = check_license($licensekey, $localkey); // Raw output of results for debugging purpose echo '<textarea cols="100" rows="20">' . print_r($results, true) . '</textarea>'; // Interpret response if ($results["status"]=="Active") { # Allow Script to Run if ($results["localkey"]) { # Save Updated Local Key to DB or File $localkeydata = $results["localkey"]; mysql_query("UPDATE keys SET local_key = '$localkeydata'"); } } elseif ($results["status"]=="Invalid") { # Show Invalid Message } elseif ($results["status"]=="Expired") { # Show Expired Message } elseif ($results["status"]=="Suspended") { # Show Suspended Message } i dont now what i make wrong,till 2 days to configure the module and no fortune an example for this where nice i hope you can help me regards 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 27, 2015 Author Share Posted November 27, 2015 (edited) i post some pictures where is my problem licensing addon dont give valid domain,valid ip and so on when i create a licence my script say invalid licence this is a picture in client area blank without licence - valid ip - valid domain ...... - Removed - strange picture 2 times reissue ( seems tpl is broken? or anybody cn post me his tpl ) - Removed - here you can see no valid domain, no valid ip and the licence when put in the php give as invalid - Removed - thanks for help regards Edited November 29, 2015 by Infopro Please Attach Images to Your Posts. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 28, 2015 Author Share Posted November 28, 2015 Hi Nobody can help me with my Problem? Give me some explain how to configure the lincensing addon. Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 29, 2015 Share Posted November 29, 2015 read this tutorial: http://forum.whmcs.com/showthread.php?99354-How-to-guide-Configure-and-Setup-the-WHMCS-Licensing-Addon 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 29, 2015 Author Share Posted November 29, 2015 Hi I Have Read this but still the same Problem my Problem ist the licence key is invalid . Do you have an Example for me? Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 29, 2015 Share Posted November 29, 2015 the check code example included with the addon files should be easy for any developer to embed in their code, if you have issue with the addon module itself you may check the Activity Logs in WHMCS Admin Area for any error records! 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 29, 2015 Author Share Posted November 29, 2015 What i muss Set here ? $licensekey= "" $localkey = "" And where the will found my generated license? Sorry for all this questions 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 29, 2015 Share Posted November 29, 2015 first you need to pass both variables to the following function everytime: yourprefix123_check_license($licensekey, $localkey='') function $licensekey= "" this is the License Key, your client will need to purchase it from your WHMCS client area, once they pay WHMCS will generate unique key for this purchase. $localkey = "" this is the Local Key, How to get it? * It will be automatically generated and returned as a result of running the function above. Where to save it? * you can save it in the software installed Database or .TXT file for example. Why do I need it? * this text contain all the information related to this use of license, like the installation path of this software, IP addresses, domain name, and new check date or expiry date for that license etc, all this information is encrypted. * so each time the function above run, it will validate the information from this (Local Key) if all is OK it will return array of result including (License Status = Active, LocalKey = New Key to be saved for the next run, etc ), otherwise it will try to connect to your server to validate the license. And where the will found my generated license? Activate the Addon Module from Admin Area -> Setup -> Addon Modules -> License Manager Sorry for all this questions not a problem 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 29, 2015 Author Share Posted November 29, 2015 (edited) Ok perfect I have create a Table in database called keys and create into this table license_keys and local_key how to store now my localkey and licence key into this tables? Yourprefix123_check_license($licensekey, $localkey=")function Which Name i have to give Yourprefix123_check_license? I Have call it: check_license($licensekey, $localkey=")function I run check_license.php and I Got follow on my browser: Array ( [status] => invalid [Massage] => domain invalid [Remotecheck] => 1 ) License key is invalid Thanks for helping me Ps: i can write here only with Handy and not with my PC, why? Edited November 29, 2015 by Lui2004 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 29, 2015 Share Posted November 29, 2015 that's great, now you need to create/purchase a license key in your WHMCS installation to test it with this function 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 29, 2015 Author Share Posted November 29, 2015 I Have purchase a licens but i get in Browser follow: Array ( [status] => Invalid [Remotecheck => 1 ) In my database is no localkey or licensekey saved I have this in my check_license.php $licensekey = mysql_result(mysql_query("SELECT license_key FROM keys LIMIT 1"),0); $localkey = mysql_result(mysql_query("SELECT local_key FROM key LIMIT 1"),0); Do you have a how to or you can give a help to create the table key with the license_key and local_key field because i think i dont have Made it correctly Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 29, 2015 Share Posted November 29, 2015 in the following lines, do you have your WHMCS installation URL added? function yourprefix123_check_license($licensekey, $localkey='') { // ----------------------------------- // -- Configuration Values -- // ----------------------------------- // Enter the url to your WHMCS installation here $whmcsurl = 'http://www.yourdomain.com/whmcs/'; check this tutorial I mentioned before, it cover all what you ask for: http://markustenghamn.com/how-to-configure-and-setup-whmcs-licensing-addon-review-how-to 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 29, 2015 Author Share Posted November 29, 2015 Can anybody Post the how to connect with database ?because their is not available Thanks 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted November 30, 2015 Share Posted November 30, 2015 (edited) Try hardcoding the license key in your program and leaving the local key null. This will be a test without much work before you add it to a database. As for how to retrieve from a database just google "php retrieve data from a mysql database". I had an issue with the license check not working of our cyphers followed newer PCI recomended standards but doing away with being so strict on those solved our problem. For the WHMCS domain in your check code are you making sure it is your WHMCS frontend area path? For example if WHMCS is installed in /public_html/whmcs your domain would be http://example.com/whmcs Edited November 30, 2015 by Sliffer21 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 30, 2015 Author Share Posted November 30, 2015 So now I have Insert the licens and I Got Valid Domains, valid ips valid directory But my Programm saß not valid licens I am disperated What i make wrong? Thanks 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted November 30, 2015 Share Posted November 30, 2015 Ok so you have inserted the license key into the code (hardcoded it)? Your WHMCS updates the license IP and directory fields? But your still getting an invalid license correct? 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 30, 2015 Author Share Posted November 30, 2015 Yes Thats correct 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted November 30, 2015 Share Posted November 30, 2015 OK what is your licensing addon log saying? 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted November 30, 2015 Author Share Posted November 30, 2015 (edited) Licensing Manager: 1 active licenses 1 total licenses in database Status message: Invalid key - Without licens Thats strange Thanks Edited November 30, 2015 by Lui2004 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted November 30, 2015 Share Posted November 30, 2015 Without seeing a handful of things I am not sure what the problem could be since obviously the licensing is working because it is updating the directory and IP. I would venture to open up a support ticket with technical support in your situation. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 1, 2015 Author Share Posted December 1, 2015 Hi I Have in Internet a verify.php and I have try it and it Works only if i put the licens manually into this verify.php I dont now if its ok if i Post this verify.php because the original is coded and this one From Internet is open but with this is verify.php my licens work. But this code dont send me valid ip ,valid domain and valid directory Why i can write into this thread only with M mobile Phone on my PC to reply thread is grey Regards 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 1, 2015 Share Posted December 1, 2015 Chances are that verify.php file you found that is unencoded is being used for something bad such as pirated licensing or something of that nature. I am not aware of WHMCS ever releasing and unencoded one because that file is basically the core of the licensing addon. I wouldn't trust it but definitely report the link to where you found it to WHMCS's piracy department. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 1, 2015 Author Share Posted December 1, 2015 Oh **************** i will delete this file I dont want to be a pirate 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 Hi I Got some News about my Problem with licensing addon: I execute the check_code.php and I Got follow on my browser : Array ( [status] => active [Registeredname] => test test => my Email adress [serviceid] => 6 [Productid] => 1 [Productname] => my Productname [regdate] => 2015-12-02 [nextduedate] => 0000-00-00 [billingcycle] => Free Account [validdomain] => my ip ,www [Validip] => my ip [Validdiractory] => /var/www/html/modules/servers/licensing [Md5Hash] => generated hash [checkdate] => 20151202 ) Why the code check the wrong directory? What i doing wrong ? Thanks 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 2, 2015 Share Posted December 2, 2015 In your check license function code there is a line at the top of the function: $whmcsurl = 'http://www.yourdomain.com/whmcs/'; Make sure that goes to your WHMCS installation such as https://example.com/whmcs/ (with the ending "/"), let me know if that helps. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.