Jump to content
  • 0

LicenseManager and CLI version


Blesta Addons

Question

yesterday we have found a issue with one of our licensed plugin, and after a deep look, we found the issue come from LicenseManager.php .

when the cron is running fro web, all thing is good, but when the cron are running from CLI, the issue is that the class can't determine the domain and the ip when it running from CLI . $_SERVER['SERVER_Name'] , $_SERVER['SERVER_ADDR']  and $_SERVER['LOCAL_ADDR']  global variables is only accessible when running through a browser . we have made a simple patch fro the license manager to get domain from blesta.company vars ,

       else if (isset(Configure::get('Blesta.company')->hostname)) {
            $data['domain'] = Configure::get('Blesta.company')->hostname;
        }

the same for ip we have added a patch to resolve the blesta compay, but after this fixe, the LicenseManager still return error for invalid location;

the cause is licensemanager send a wrong info when it run in CLI,

Array
(
    [status] => invalid_location
    [label] => XXXXXX Plugin
    [time] => 1498148289
    [allow_reissue] => 1
    [addons] =>
    [version] => 4.0.1
    [custom] => Array
        (
            [license_type] => onetime
            [cancellation_date] =>
            [license_for] => XXXXXX
            [addon_version] => 1.0.0
        )

    [domain] => Array
        (
            [0] => XXXXX.com
        )

    [ip] => Array
        (
            [0] => XXX.165.XXXX.249
        )

    [path] => Array
        (
            [0] => /home/XXXXXX/public_html/blesta/
        )

    [updates] =>

 

when we run it from web

 

Array
(
    [status] => valid
    [label] => XXXXXX
    [time] => 1498148277
    [allow_reissue] => 1
    [addons] => 
    [version] => 4.0.1
    [custom] => Array
        (
            [license_type] => onetime
            [cancellation_date] => 
            [license_for] => XXXXXX
            [addon_version] => 1.2.0
        )

    [domain] => Array
        (
            [0] => XXXXX.com
        )

    [ip] => Array
        (
            [0] => XXX.165.XXX.249
        )

    [path] => Array
        (
            [0] => /home/XXXXXX/public_html/blesta/
        )

    [updates] => 
)

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

more debug:

the fucntion @gethostbyaddr($data['ip']) is not reliable, as it return wroong domain instead of the domain if the ip has other reverse name. a sample case is blesta.com :)

i think the license manager should has another approuch if the file called from CLI, finnaly we have arrived to make ad this to make it workig .

        // Set the IP
        if (isset($_SERVER['SERVER_ADDR'])) {
            $data['ip'] = $_SERVER['SERVER_ADDR'];
        } elseif (isset($_SERVER['LOCAL_ADDR'])) {
            // Windows IIS 7 support
            $data['ip'] = $_SERVER['LOCAL_ADDR'];
        } elseif (isset($_SERVER['SERVER_NAME'])) {
            // If no IP found, perform lookup based on server name
            $data['ip'] = @gethostbyname($_SERVER['SERVER_NAME']);
        } elseif (isset(Configure::get('Blesta.company')->hostname)) {
            $data['ip'] = @gethostbyname(Configure::get('Blesta.company')->hostname);
        }

        // Set the domain if SERVER_NAME is available, otherwise perform lookup based on IP
        if (isset($_SERVER['SERVER_NAME'])) {
            $data['domain'] = $_SERVER['SERVER_NAME'];
        } else if (isset(Configure::get('Blesta.company')->hostname)) {
            $data['domain'] = Configure::get('Blesta.company')->hostname;
        } else {
            $data['domain'] = @gethostbyaddr($data['ip']);
        }

 

Link to comment
Share on other sites

  • 0

i think a update to the model is needed, either :

1 - correct the way of collecting the info .

2 - allow plugin to accept setting our own info to send (not the custom_data) , but the base info (ip, domain, path), something like setLicenseServerUrl() , why not setLicenseDomain(), setLicenseIP(), setLicensePath()  :blesta:

Link to comment
Share on other sites

  • 0
On 6/30/2017 at 8:51 PM, Blesta Addons said:

you can use my patch to get it working in CLI, or just clone the patched LicenceManger.php and include it in your scripts

Thanks for your suggestion. We have had a talk in our team and we finally implemented it in a different way which is suitable for our envs. Thanks again for your help :)

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
Answer this question...

×   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...