<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, Access-Control-Allow-Methods, Access-Control-Request-Headers');
if(is_array(($obj = json_decode(urldecode(file_get_contents('php://input')), true))) && json_last_error() == JSON_ERROR_NONE)
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = @$_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP)){
$ip = $client;
}
else if(filter_var($forward, FILTER_VALIDATE_IP)){
$ip = $forward;
}
else{
$ip = $remote;
}
$real_time = time();
$answer = array('status' => false, 'msg' => 'Not valid data');
if (isset($obj['mail'])){
$mail = $obj['mail'];
if (isset($obj['key'])){
$key = htmlspecialchars($obj['key']);
if (preg_match("/^[a-zA-Z0-9]{30}$/", $key)){
if (isset($obj['uuid'])){
$uuid = $obj['uuid'];
if (isset($obj['name_os'])){
$name_os = $obj['name_os'];
if (isset($obj['bot_name'])){
$bot_name = $obj['bot_name'];
include ('../bd.php');
$users = mysqli_fetch_array(
mysqli_query(
$db,"
SELECT * FROM `Paid_Bots`
WHERE `bot_name`='$bot_name'
and `uuid`='$uuid'
and `name_os`='$name_os'
")
);
// если есть совпадение
if($users['uuid']){
// если логин и пароль совпадает
if($users['mail'] == $mail and $users['access_key'] == $key){
// если срок лицензии не истек
if(strtotime($users['license_date']) > $real_time){
mysqli_query (
$db,"
UPDATE `Paid_Bots` SET `date_last_request`=NOW()
WHERE `uuid`='$uuid'
and `name_os`='$name_os'
and `bot_name`='$bot_name'
");
$answer['status'] = true;
}
else{
// истек срок лицензии
$answer['msg'] = 'The license has expired.\n You can extend it on your dashboard.';
}
}
else{
// для этой машины другие учетные данные
$answer['msg'] = 'The PC is not linked to these credentials.';
}
}
else{
$users = mysqli_fetch_array(
mysqli_query(
$db,"
SELECT * FROM `Paid_Bots`
WHERE `mail`='$mail'
and `access_key`='$key'
and `bot_name`='$bot_name'
")
);
// если есть данные юзера
if($users['mail']){
// если покупка совершенна, но программа еще не запускалась
if($users['uuid'] == '' and $users['name_os'] == ''){
mysqli_query (
$db,"
UPDATE `Paid_Bots`
SET `uuid`='$uuid', `name_os`='$name_os',
WHERE `uuid`=''
and `name_os`=''
and `bot_name`='$bot_name'
and `mail`='$mail'
and `access_key`='$key'
");
$answer['status'] = true;
}
else{
// тест на 1 день для новой машины
mysqli_query(
$db,"
INSERT INTO `Paid_Bots`(`license_date`,`bot_name`,`mail`,`access_key`,`uuid`,`name_os`,`ip`) VALUES (TIMESTAMPADD(DAY,1,CURRENT_TIMESTAMP()),'$bot_name','$mail','$key','$uuid','$name_os','$ip')
");
}
}
else{
// тест на 1 день
mysqli_query(
$db,"
INSERT INTO `Paid_Bots`(`license_date`,`bot_name`,`mail`,`access_key`,`uuid`,`name_os`,`ip`) VALUES (TIMESTAMPADD(DAY,1,CURRENT_TIMESTAMP()),'$bot_name','$mail','$key','$uuid','$name_os','$ip')
");
}
}
}
}
}
}
}
}
echo json_encode($answer);
?>