Jump to content

Help Me Please With Migrating From Whmcs Licensing To Blesta Licensing


timnboys

Recommended Posts

Help Me Please with migrating from whmcs licensing to blesta licensing

I currently use a flat file for storing settings

http://stackoverflow.com/questions/14752470/creating-a-config-file-in-php

that is where I found out my current implementation of how to store the settings ^

I just need help trying to get the blesta license manager to call back home

I think whmcs made it too easy to integrate their licensing addon which of course is making me scratch my head on how to get the blesta licensing manager integrated into my script

could someone give me a code example of how they integrated it into their script? you know at least something to give me a idea of how to use it in my script? 

Link to comment
Share on other sites

Documentation on the License Manager can be found here.

 

If you're using flat files, simply file_put_contents for the license key, license data, and public key. So, you'd have 3 files. Then you would just file_get_contents and assign them to the their respective variables.

okay so how would I implement that as I tried using your included example.php file code but it returns this on whmcs on calling the licensing function:

NULL NULL array(1) { ["status"]=> string(7) "unknown" } Array ( [status] => unknown )

This is my current writing style for putting the variables back in the config.php file I made(flat file)

$config = include("fraudrecord_config.php");
$config['public_key'] = $public_key;
file_put_contents('fraudrecord_config.php', '<?php return ' . var_export($config, true) . ';');
could you please tell me if I am doing it right or not?
As this is my empty config file format & template:
<?php

return array(
        'license_key' => '',
	'public_key' => '',
	'license_data' => '',
);

and this is how I am getting the contents:

$configs = include("fraudrecord_config.php");
$license_key = $configs['license_key'];
$public_key1 = $configs['public_key'];
$license_data = $configs['license_data'];

here is where I got the original idea for my flat file setting system:

http://stackoverflow.com/questions/2015715/fastest-way-to-store-easily-editable-config-data-in-php

Link to comment
Share on other sites

Hello @Cody is there anyway I can test the plugin's response as I know with whmcs licensing addon I could just post to validate.php with the ip, domain, dir and it would give me back a response but with blesta's I cannot get it to do that even with the sample php code provided.

At this point I just want to make sure it works and I am not losing it.

Link to comment
Share on other sites

Hello @Cody is there anyway I can test the plugin's response as I know with whmcs licensing addon I could just post to validate.php with the ip, domain, dir and it would give me back a response but with blesta's I cannot get it to do that even with the sample php code provided.

At this point I just want to make sure it works and I am not losing it.

 

You can post via theirs? that sounds risky as you could get modify the outcome and get a validation if it's correct to skip licensing?

Link to comment
Share on other sites

You can post via theirs? that sounds risky as you could get modify the outcome and get a validation if it's correct to skip licensing?

yea that is what I said but there licensing system is built different.

hey michael dance may I ask a favor could you send me a copy of your blestacms non ioncubed just for me to be able to study how your developer used the blesta licensing system and got it to work? as I have tried everything to get it to work and tried to study everything that was open for me but I still cannot figure it out.

as I only want to study the licensing part of how your developer made it work I don't want to do anything else with the code but just figure out how your developer got it working and how to get mine working.

Link to comment
Share on other sites

could you please tell me if I am doing it right or not?
As this is my empty config file format & template:
<?php

return array(
        'license_key' => '',
	'public_key' => '',
	'license_data' => '',
);

and this is how I am getting the contents:

$configs = include("fraudrecord_config.php");
$license_key = $configs['license_key'];
$public_key1 = $configs['public_key'];
$license_data = $configs['license_data'];

 

You can't store data like that because you're not going to be able to write to it that way. Try this:

<?php
require_once "path/to/license.php";

////////////////////////////////////////////////////
// BEGIN: ONE-TIME SETUP
////////////////////////////////////////////////////

// Get license key from user and write to file
file_put_contents("path/to/license_key.txt", $_POST['license_key']);

// Initialize to fetch public key
$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib"; // The path to the phpseclib library
$license = new License($path_to_phpseclib);
$license_manager->setLicenseServerUrl($server_url);

// Get public key from license server and write to file
file_put_contents("path/to/public_key.txt", $license_manager->requestKey());
////////////////////////////////////////////////////
// END: ONE-TIME SETUP
////////////////////////////////////////////////////

<?php
////////////////////////////////////////////////////
// BEGIN: FETCH LICENSE DATA
////////////////////////////////////////////////////
$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$license_key = file_get_contents("path/to/license_key.txt"); // The client's license key
$public_key = file_get_contents("path/to/public_key.txt"); // The client's public key (if they have one)
$shared_secret = "your-secret"; // A random shared secret value that exists for this Licese Module product
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib"; // The path to the phpseclib library

$license = new License($path_to_phpseclib);
$license_manager = $license->getManager();
$license_manager->setLicenseServerUrl($server_url);
$license_manager->setKeys($license_key, $public_key, $shared_secret);

file_put_contents("path/to/license_data.txt", $license_manager->requestData());

////////////////////////////////////////////////////
// END: FETCH LICENSE DATA
////////////////////////////////////////////////////


////////////////////////////////////////////////////
// BEGIN: VERIFY LICENSE DATA
////////////////////////////////////////////////////

$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$license_key = file_get_contents("path/to/license_key.txt"); // The client's license key
$public_key = file_get_contents("path/to/public_key.txt"); // The client's public key (if they have one)
$shared_secret = "your-secret"; // A random shared secret value that exists for this Licese Module product
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib"; // The path to the phpseclib library

$license = new License($path_to_phpseclib);
$license_manager = $license->getManager();
$license_manager->setLicenseServerUrl($server_url);
$license_manager->setKeys($license_key, $public_key, $shared_secret);

$ttl = 1209600; // Amount of time local license data should be valid for (60*60*24*14 = 1209600 = 14 days)
$data = $license_manager->validate(file_get_contents("path/to/license_data.txt"), $ttl);

print_r($data);

////////////////////////////////////////////////////
// END: VERIFY LICENSE DATA
////////////////////////////////////////////////////
Link to comment
Share on other sites

 

You can't store data like that because you're not going to be able to write to it that way. Try this:

<?php
require_once "path/to/license.php";

////////////////////////////////////////////////////
// BEGIN: ONE-TIME SETUP
////////////////////////////////////////////////////

// Get license key from user and write to file
file_put_contents("path/to/license_key.txt", $_POST['license_key']);

// Initialize to fetch public key
$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib"; // The path to the phpseclib library
$license = new License($path_to_phpseclib);
$license_manager->setLicenseServerUrl($server_url);

// Get public key from license server and write to file
file_put_contents("path/to/public_key.txt", $license_manager->requestKey());
////////////////////////////////////////////////////
// END: ONE-TIME SETUP
////////////////////////////////////////////////////

<?php
////////////////////////////////////////////////////
// BEGIN: FETCH LICENSE DATA
////////////////////////////////////////////////////
$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$license_key = file_get_contents("path/to/license_key.txt"); // The client's license key
$public_key = file_get_contents("path/to/public_key.txt"); // The client's public key (if they have one)
$shared_secret = "your-secret"; // A random shared secret value that exists for this Licese Module product
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib"; // The path to the phpseclib library

$license = new License($path_to_phpseclib);
$license_manager = $license->getManager();
$license_manager->setLicenseServerUrl($server_url);
$license_manager->setKeys($license_key, $public_key, $shared_secret);

file_put_contents("path/to/license_data.txt", $license_manager->requestData());

////////////////////////////////////////////////////
// END: FETCH LICENSE DATA
////////////////////////////////////////////////////


////////////////////////////////////////////////////
// BEGIN: VERIFY LICENSE DATA
////////////////////////////////////////////////////

$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$license_key = file_get_contents("path/to/license_key.txt"); // The client's license key
$public_key = file_get_contents("path/to/public_key.txt"); // The client's public key (if they have one)
$shared_secret = "your-secret"; // A random shared secret value that exists for this Licese Module product
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib"; // The path to the phpseclib library

$license = new License($path_to_phpseclib);
$license_manager = $license->getManager();
$license_manager->setLicenseServerUrl($server_url);
$license_manager->setKeys($license_key, $public_key, $shared_secret);

$ttl = 1209600; // Amount of time local license data should be valid for (60*60*24*14 = 1209600 = 14 days)
$data = $license_manager->validate(file_get_contents("path/to/license_data.txt"), $ttl);

print_r($data);

////////////////////////////////////////////////////
// END: VERIFY LICENSE DATA
////////////////////////////////////////////////////

@Cody I have narrowed down the culprit or the issue:

okay I have narrowed it down to a specific function that isn't working it is request_data in license_manager.php I don't know what I am doing wrong but I cannot even get my plugin to return anything no response empty even when I try to manually try to launch a curl request with the parameters it is using I don't get back a response either so something must be going wrong with the plugin or "license server" then. as I have verified it isn't code related.

 

that is what I submitted on the ticket ^

let me just give concrete evidence of what I have tested & found to provide more info on my issue

Array ( [status] => unknown )

^ That is all I get when checking for license

and also when running on either linux or windows I don't get a response back from request_data as the txt file it is supposed to have doesn't have anything in it(blank, empty)

I have tried alot of things to see if I could figure it out including modifying the license_manager.php file to see if it would echo out what it is seeing and it didn't see nothing back as a response which is my problem it hashes and signs the $params variable like it should including the key variable is included

this is what I have gotten on the $params data item in the array when I modified the file to return back the $params object

TUANYPfG11HfldNzbSEeEj1p1ULhekOLMItcNGmSLlvU0xqjZf83ND8OFdpvrzOUgwskuXKd2yxLla/CX4dWRfUi/w67RtPK3AZ1clhJytMVwlH7I9fkMtxGKdRdC0TdPoG3vEg9sVuOOeh2jPWTbMlkjtS6oA7Le3XYbthjT1Dl9jfQw703392du5lmE/PnaVbp9N3pUNHc5KRzEqGkWg==$sjiPxI/dr92K0H2RujhjwRMnVcL2TlWMUH6jyj7J+k4tGkQHuu47hVp3Dz4oOqUeOfi5e7zZ0DbPO0kH00k5SpjZgkip9O4mQD7gUqk7Y353gIT5E8/w9P5YLdeVKVbd1OD/2XUYP3SiA54HbsvBOvFT9/6lh5DrIj6JPUvFRgY=

 

all would seem right? right? well not really as best as I can tell that is supposed to be right but blesta doesn't return any licensing data according to that back. so honestly I am at a lost here it is taken more time and more figuring out how to even get blesta's licensing manager working then it did with whmcs's licensing addon. no offense to the blesta dev's or anyone really but I just don't understand why it is so hard for me to figure out how to get blesta's licensing manager working and why it wasn't that hard at all for the whmcs licensing addon?

To be honest this might be a compliment for blesta that is it is so hard to figure out how to get it to work that it must be very hard to break or circumvent.

Link to comment
Share on other sites

@Cody I have narrowed down the culprit or the issue:

that is what I submitted on the ticket ^

let me just give concrete evidence of what I have tested & found to provide more info on my issue

Array ( [status] => unknown )

^ That is all I get when checking for license

and also when running on either linux or windows I don't get a response back from request_data as the txt file it is supposed to have doesn't have anything in it(blank, empty)

I have tried alot of things to see if I could figure it out including modifying the license_manager.php file to see if it would echo out what it is seeing and it didn't see nothing back as a response which is my problem it hashes and signs the $params variable like it should including the key variable is included

this is what I have gotten on the $params data item in the array when I modified the file to return back the $params object

all would seem right? right? well not really as best as I can tell that is supposed to be right but blesta doesn't return any licensing data according to that back. so honestly I am at a lost here it is taken more time and more figuring out how to even get blesta's licensing manager working then it did with whmcs's licensing addon. no offense to the blesta dev's or anyone really but I just don't understand why it is so hard for me to figure out how to get blesta's licensing manager working and why it wasn't that hard at all for the whmcs licensing addon?

To be honest this might be a compliment for blesta that is it is so hard to figure out how to get it to work that it must be very hard to break or circumvent.

 

When you do it the better and securer way it seems hard at first. In our BlestaCMS I made a mistake so I'll also tell you on the ticket with me.

Link to comment
Share on other sites

When you do it the better and securer way it seems hard at first. In our BlestaCMS I made a mistake so I'll also tell you on the ticket with me.

okay I finally got the whole issue narrowed down it appears when it calls home it isn't passing the verify signature function in validate.php as whatever is being send to the licensing server isn't valid it appears and isn't passing verifyrsa function.

so that means I am this close closer to figuring out why it doesn't work and how to fix it.

and after commenting out the part in validate.php where it verifies the rsa signature it finally calls home successfully and I can see the valid ip, domain, dir in the blesta properties of the license.

so that probably means what I just need to cancel that license and create a new one then?

as it is obvious that it was checking or encrypted with the wrong private key or public key. 

Link to comment
Share on other sites

okay I finally got the whole issue narrowed down it appears when it calls home it isn't passing the verify signature function in validate.php as whatever is being send to the licensing server isn't valid it appears and isn't passing verifyrsa function.

so that means I am this close closer to figuring out why it doesn't work and how to fix it.

and after commenting out the part in validate.php where it verifies the rsa signature it finally calls home successfully and I can see the valid ip, domain, dir in the blesta properties of the license.

so that probably means what I just need to cancel that license and create a new one then?

as it is obvious that it was checking or encrypted with the wrong private key or public key. 

I finally got it to work finally after all of this time I finally got a response.

 

 

Array ( [status] => valid [label] =>  [time] => 1450816116 [allow_reissue] => true [addons] => [version] => [custom] => Array ( [license_type] => month [cancellation_date] => ) [domain] => Array ( [0] => ) [ip] => Array ( [0] => ) [path] => Array ( [0] =>  ) [updates] => 2016-01-22T19:46:56+00:00 )

by the way licensecart I hope you don't mind if I borrowed your copy of the phpseclib folder from your blesta_cms as it appears your folder and its files finally made it work!

Link to comment
Share on other sites

  • 1 month later...

Okay could any of you tell me how to handle this error message?

 PHP Fatal error:  Cannot redeclare class Crypt_AES in /vendors/phpseclib/Crypt/AES.php on line 608, referer: /admin/plugin/order/admin_forms/settings/

as this happens when I try to instantiate the blesta licensing manager which uses phpseclib also so don't know how to handle this could cody or tyson or one of the blesta dev's or someone please give me a hand on this and tell me how to fix it?

as it appears for some reason Crypt_AES is already declared when I try to start up the licensing manager which somehow declares again Crypt_AES which doesn't work hence the issue.

Link to comment
Share on other sites

  • 1 year later...

Hello,

I have tried the code in the below reply. 

There is no public_key get from the server.  So I try to manage to get the key from the server logs for testing.  And in the second script (for fetching and verifying license data ), I get the following message after adjusting the variable path_to_phpseclib By add a slash (/) at the end, which is   "phpseclib/

Quote

Array
(
    [status] => unknown
)

Can anyone suggest a solution for the same. 

Link to comment
Share on other sites

1 hour ago, Suhesh said:

Hello,

I have tried the code in the below reply. 

There is no public_key get from the server.  So I try to manage to get the key from the server logs for testing.  And in the second script (for fetching and verifying license data ), I get the following message after adjusting the variable path_to_phpseclib By add a slash (/) at the end, which is   "phpseclib/

Can anyone suggest a solution for the same. 

nope rewrite the entire license manager plugin like I did to make it work.

Link to comment
Share on other sites

2 hours ago, Suhesh said:

There is no public_key get from the server.  So I try to manage to get the key from the server logs for testing.  And in the second script (for fetching and verifying license data ), I get the following message after adjusting the variable path_to_phpseclib By add a slash (/) at the end, which is   "phpseclib/

Per https://docs.blesta.com/display/user/License+Manager a status of "unknown" means the license data does not exist or is corrupt. Regarding RSA keys, those should be generated for each license that is created within Blesta. I'm assuming you've installed both the License Manager plugin and License Module and have create a Package using the license module, and added a service with the Package? In which case, there should be a public key that can be fetched.

Link to comment
Share on other sites

Hello,

I have installed the module and plugin and created product and created a package using the license module ( and use the product ).  Also added the package to one customer and use the license key for testing and no public_key is getting from the server.  The following function not resulting any data. It gives only NULL

license_manager->requestKey

Link to comment
Share on other sites

3 hours ago, Suhesh said:

Hello,

I have installed the module and plugin and created product and created a package using the license module ( and use the product ).  Also added the package to one customer and use the license key for testing and no public_key is getting from the server.  The following function not resulting any data. It gives only NULL

license_manager->requestKey

do you have any third party plugin installed , specially "the debugger" ? it was my issue in the past .

 

 

Link to comment
Share on other sites

Hello,

It is resolved by using the following code provided by @Tyson

require_once "path/to/license.php";

$server_url = "https://domain.com/path_to_blesta/plugin/license_manager/validate/";
$license_key = "YOUR LICENSE KEY"; // The license key
$public_key = null; // The client's public key (if they have one)
$shared_secret = "YOUR SHARED SECRET"; // A random shared secret value that exists for this Licese Module product
$path_to_phpseclib = dirname(__FILE__) . DIRECTORY_SEPARATOR . "phpseclib". DIRECTORY_SEPARATOR; // The path to the phpseclib library

$license = new License($path_to_phpseclib);
$license_manager = $license->getManager();
$license_manager->setLicenseServerUrl($server_url);
$license_manager->setKeys($license_key, $public_key, $shared_secret);

// Get the public key
$public_key = $license_manager->requestKey();
var_dump($public_key);
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.

Loading...
×
×
  • Create New...