Updater License Check - Advanced Installer Community
jlh211
Posts: 18
Joined: Tue Nov 12, 2013 1:02 am

Updater License Check

Hello, I have been using Advanced Installer for over a year now and love it! I would like to implement this feature and am having issues.

I would like to have the updater check against my database to see if a user is eligible for updates. To do this I've created a script on my server that checks the user's "install_date" and adds a year to it. If that value is less than the current date, then the user is not eligible for updates any longer. I've added the URL to the "License Check URL" when building the updater and have uploaded the update file to my server, but it's not working.

Here is my code, can someone tell me what I'm doing wrong?

Code: Select all

<?php

// connect to db
$dbhost = 'localhost';
$dbname = ****';
$dbuser = '****';
$dbpass = '****';

$dbconn = null;
connect_to_db();

// get all required parameters
$license_id = get_parameter('licenseid');
if ($license_id === null || !is_numeric($license_id)) {
    response(200, "603\nExpired");
}




// get data from db for provided serial number
$filter = "`camera_sn` = '$license_id' AND `install_date` > DATE_SUB(CURDATE(), INTERVAL 1 YEAR)";
$row = get_row_from_db('customer_no, install_date', 'customers', $filter);


if (is_null($row)) {
    response(200, "603\nExpired");
} else {
    mysqli_query($dbconn, "update `customers` set `install_date` = CURDATE() WHERE `customer_no`='{$row['customer_no']}'");
    response(200, "601\nOK");
}

die;

////////////////////////////////////////////////////////////////////////////////
// implementation

function response($code, $msg = null)
{
    header("HTTP/1.1 $code", true);
    if ($msg !== null)
        echo $msg;
    die;
}

function get_parameter($name)
{
    global $dbconn;
    if (!isset($_POST[$name]))
        return null;
    $value = mysqli_real_escape_string($dbconn, trim($_POST[$name]));
    if ($value === '')
        return null;
    return $value;
}

function connect_to_db()
{
    global $dbconn;
    if ($dbconn !== null)
        return;
    global $dbhost, $dbname, $dbuser, $dbpass;
    $dbconn = mysqli_connect($dbhost, $dbuser, $dbpass) or response(500);
    mysqli_query($dbconn, "set names utf8;");
    mysqli_query($dbconn, "set character set utf8;");
    mysqli_query($dbconn, "set collation_connection = 'utf8_general_ci';");
    mysqli_query($dbconn, "use `$dbname`;");
}

function get_row_from_db($columns, $table, $filter)
{
    global $dbconn;
    if ($dbconn === null)
        response(500);
    $query = "select $columns from $table where $filter";
    $res = mysqli_query($dbconn, $query);
    if ($res === false)
        response(500);
    $row = mysqli_fetch_assoc($res);
    mysqli_free_result($res);
    return $row;
}
Thanks!
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Updater License Check

Hello,

Can you please give us more details about the behavior you are encountering? What exactly isn't working? Also, please tell us what command line are you using when launching the Updater.

Basically, in order to use our "Updater License Check" functionality you should make sure your license check script returns "601\nMessage" when the license is valid and "603\nMessage" when the license is invalid. For testing purposes, you can create your own HTML form which will do an HTTP Post request towards your server script sending test values for "licenseid" and "languageid" post parameters, and check the server script response.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jlh211
Posts: 18
Joined: Tue Nov 12, 2013 1:02 am

Re: Updater License Check

Hey Daniel,

I was able to get this to work, however now I'm having the issue of users being able to bypass the check. When the "Check for Updates" button is launched from my program it send the correct Command Line to do the License check, however if a user just goes to the Program's folder under Program Files and runs the "updater.exe" program the License check does not occur since they are accessing updater.exe directly.

How can I fix this so that even if they run updater.exe form the program folder it will still do the license check?

Thanks!
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Updater License Check

Hello,

If you still want to force the license check even when the users manually launch the Updater, then you can proceed like this:
1. store the license id into a registry value of type REG_SZ (e.g. HKLM\Software\MyEditor\LicenseValue)
2. go to "Table Editor" page and select the "IniFile" table
3. edit the "Value" field, of the "DefaultCommandLine", so it use a command line which does the license validation check, like this:

Code: Select all

/checknow HKLM\Software\MyEditor\LicenseValue
4. rebuild, install and test again the scenario

Please note this approach requires the "Table Editor" feature which is available starting with an Enterprise or higher edition. Also, it can be used only for future product versions which will be installed on users' machines. For already released and installed versions, unfortunately there is nothing you can do.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jlh211
Posts: 18
Joined: Tue Nov 12, 2013 1:02 am

Re: Updater License Check

Hey Daniel,

I've done everything as described and it's still allowing me to update when i run updater.exe manually even though when I launch it from my program I'm getting a license expired message.

Please advise.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Updater License Check

Hello,

I'm not sure why this happens. I've tested the scenario, but I cannot replicate the behavior. Can you please send us the .AIPs (project files of your old version, upgraded version and of your updates configuration project) to support at advancedinstaller dot com so we can investigate thier settings?

As a side note, please note that if you have set the "DefaultCommandLine" of the Updater to search for the "HKLM\Software\MyEditor\LicenseValue" registry, then at run time on a 64-bit machine the Updater will search in the "Wow3264Node" redirected location (i.e. "\HKLM\Software\Wow6432Node\MyEditor\LicenseValue"). So, please make sure the above registry exists at run time and also that your license validation script returns a 603 answer code.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”