<?php

/*******************************************************************************
 * eredeti url: http://www.archlinexp.com/index.php?menu=tips2012&lang=hun&version=1&session=OTA0NkEzMTlBMDcwQTE3NkE4NzRBMzc1QTc3NkEwNzJBNTc0Q0Y3NUE3NzdBMjdGQTc3RUE4NzJBNDcwQTgxOUNGNzVDRjc3QTA3NkEyNzdBMzZCQTM3MEJENzVBNTA3QkQ3MkEwN0ZBMDAzQTYxOUEyNjhBOTY4QTA3NEJFNzZCRTc3RTIyMUY1MjNCRTI4QTE3N0E4NzE=
 * eredeti url: http://old.archlinexp.com/tips/tips2009/hun/1/OTA0NkEzMTlBMDcwQTE3NkE4NzRBMzc1QTc3NkEwNzJBNTc0Q0Y3NUE3NzdBMjdGQTc3RUE4NzJBNDcwQTgxOUNGNzVDRjc3QTA3NkEyNzdBMzZCQTM3MEJENzVBNTA3QkQ3MkEwN0ZBMDAzQTYxOUEyNjhBOTY4QTA3NEJFNzZCRTc3RTIyMUY1MjNCRTI4QTE3N0E4NzE=/46.139.109.235
 * új url:      http://www.archlinexp.com/maintenance/tips.php?lang=hun&version=2&session=OTA0NkEzMTlBMDcwQTE3NkE4NzRBMzc1QTc3NkEwNzJBNTc0Q0Y3NUE3NzdBMjdGQTc3RUE4NzJBNDcwQTgxOUNGNzVDRjc3QTA3NkEyNzdBMzZCQTM3MEJENzVBNTA3QkQ3MkEwN0ZBMDAzQTYxOUEyNjhBOTY4QTA3NEJFNzZCRTc3RTIyMUY1MjNCRTI4QTE3N0E4NzE=
 * logfilter=0 - csak a legfontosabb logok;
 * logfilter=10 - minden logot küld;
 ******************************************************************************/
error_reporting(E_ERROR | E_PARSE);

if (!class_exists('crm_hardlock')) require_once("common_cadline_libraries/crm_hardlock.class.php");
if (!class_exists('crm_users')) require_once("common_cadline_libraries/crm_users.class.php");

// error_log(print_r($_GET, TRUE), 3, "../tmp/error_tips.log");

$user_lang_db = $user_lang = $origlang = (isset($_GET['lang']) && !empty($_GET['lang'])) ? trim($_GET['lang']) : 'eng';
//-$user_version = (isset($_GET['version']) && empty($_GET['version']) == false ? trim($_GET['version']) : NULL); nem ahsznalt valtozo volt, kivettem 2019-ben
$user_ssID  = (isset($_GET['session']) && !empty($_GET['session']) ? trim($_GET['session']) : NULL);
$user_IP    = $_SERVER['REMOTE_ADDR'];
$time       = time();

if (isset($_GET["launched"]) && $_GET["launched"] == 'test') $user_IP = 'Cadline Internal Test';

//get country name from ip
$locale = @file_get_contents("http://freegeoip.net/xml/" . $user_IP, FALSE, stream_context_create(array('http' => array('timeout' => 2))));

if (strstr($locale, "CountryName")) { // A freegeoip.net oldal mar nem elerheto
    $tomb       = json_decode(json_encode(simplexml_load_string($locale)), TRUE);
    $ctrname    = $tomb["CountryName"];
}

$temp = explode(".", gethostbyaddr($user_IP));

if (!isset($ctrname) || $ctrname == '') $ctrname = 'unknown';

if (!isset($user_ssID) || $user_ssID == '') {
    $rec = array(
        'hiba'  => "Tips.php: unknown tips data\n",
        'datum' => date('Y-m-d H:i:s', time())
    );
    Database::getInstance()->insert(JMLADATBAZIS . '.a_hibak', $rec, 'ss');
    return; //- ha nincs meg a kodolt stream, akkor semmilyen infor
}

$str_decoded = base64_decode($user_ssID); //decode the session string

sscanf(substr($str_decoded, 0, 4), '%04x', $keyDec);
$encoded = str_split(substr($str_decoded, 4), 4);
$decoded = '';

foreach ($encoded as $e) {
    sscanf($e, '%04x', $temp);
    if (strlen(substr(sprintf('%x', $temp ^ $keyDec), 2)) > 0) {
        $decoded .= chr(hexdec(substr(sprintf('%04x', $temp ^ $keyDec), 2)));
        $decoded .= chr(hexdec(substr(sprintf('%04x', $temp ^ $keyDec), 0, 2)));
    } else {
        $decoded .= chr(hexdec(substr(sprintf('%04x', $temp ^ $keyDec), 2)));
    }
}

$pos = strpos($decoded, '#');    //ba 2018.07.04. atterunk a # separatorra. Ezidaig nem fordulhatott elo benne ilyen jel
if ($pos === false) $separator = '_';
else $separator = '#';

$numdata = substr_count($decoded, $separator);    //ba most már kapunk adatot az oprendszerrol is

$osdata = '';
$reactivationCounter = 0;

if ($numdata >= 11)
    list($empty, $pwd, $compID, $build, $ctrID, $telepitesikod, $osdata, $usGCMan, $usGCType, $usGCDriverVer, $npID, $partnerID, $name, $email, $company, $phone, $newsletter, $reactivationCounter, $isTwTw) = explode($separator, $decoded);
elseif ($numdata >= 6)
    list($empty, $pwd, $compID, $build, $ctrID, $telepitesikod, $osdata, $usGCMan, $usGCType, $usGCDriverVer, $npID, $partnerID) = explode($separator, $decoded);
else
    list($empty, $pwd, $compID, $build, $ctrID, $telepitesikod) = explode($separator, $decoded);

crm_hardlock::InsertLog($pwd);

// Biztositsuk, hogy ez mindenkepp bool tipusu legyen
$isTwTw = $isTwTw == 'true';
$personalMessageLink = '';

$crackedProgram = strpos($osdata, ".gray.") !== false ? true : false;
if ($crackedProgram) {    //- 2018-as proragramoktol(nehany 2018-as build nem fut ide be)
    /*$crackedProgramDeactivated = false;
    if(crm_hardlock::IsCalledFromMyIP()){
        header('Content-Type: text/xml; charset=utf-8');
        header('Content-Disposition: inline; filename=response.xml');
        print '<'.'?'.'xml version="1.0" encoding="UTF-8" standalone="yes"'.'?'.'>
            <Tips>
                <Tip lang="en" version="2">
                    <path>/public/support/tips/en/</path>
                </Tip>
                <actcode>'.$validTelepitesikod.'</actcode>
                <Virtualization>true</Virtualization>
                <logfilter>0</logfilter>
                <loginEnabled>false</loginEnabled>
                <PersonalMessage></PersonalMessage>
                <graylink></graylink>
            </Tips>';
        $crackedProgramDeactivated = true;
    }*/

    // A crackelt programok ne menjenek bele a debug_table-be
    /*$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    $message = "Crack: ".$decoded." || url: ".$actual_link;
    crm_hardlock::AddToDebugTable($message);*/

    return; // A crackelt programokat nem taroljuk
}

$validPassword = Codegen::IsValidPassword($pwd);
if ($validPassword) {
    $ver8and9 = crm_hardlock::GetVer8And9FromPassword($pwd);
    $softwareKey = Codegen::IsSoftwareKey($pwd); // Software kulcs 2019

    if (crm_hardlock::IsProgramExpiredByFixDate($pwd)) {
        // A lejart programok ne menjenek be a debug_table-be
        /*$message = "Tip error: expired program by IsProgramExpiredByFixDate || password: ".$pwd;
        crm_hardlock::AddToDebugTable($message);*/

        return;
    }
} else {
    $ver8and9       = 0;
    $softwareKey    = false;

    $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    $message = "Tip error: invalid password || password: {$pwd} || url: {$actual_link}";
    crm_hardlock::AddToDebugTable($message);

    return;
}
$validTelepitesikod = Codegen::IsValidTimeCode($telepitesikod);
if ($validTelepitesikod || ($validPassword && !$softwareKey))  //- hardware kulcseseten az isid a passwordbol generalhato
    $isid = ($softwareKey ? crm_hardlock::GetIsidFromTimeCode($telepitesikod) : substr($pwd, 0, 2) . $ver8and9);
else {
    $telepitesikod  = "";
    $isid           = "";
}

if (!$validPassword && substr($decoded, 0, 2) == "##") {    //- 2018-as proragramoktol(nehany 2018-as build nem fut ide be)
    $actual_link    = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    $message        = "Tip error: missing password || url: {$actual_link}";
    crm_hardlock::AddToDebugTable($message);
}
if ($validPassword && !$validTelepitesikod && $ver8and9 > 35) { //- csak a 2019-es programokat es ujabbakat vizsgalunk, a regbbiekben elofordulhatnak hibas idokodok
    $actual_link    = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    $message        = "Tip error: invalid timecode {$decoded} || url: {$actual_link}";
    crm_hardlock::AddToDebugTable($message);
}

if (isset($npID)) $compid = crm_hardlock::AddOrUpdateComputer($npID, '');

$isNamirialAutoCreate   = isset($npID) && $npID > '' && isset($partnerID) && $partnerID == '2nt' /*-&& isset($telepitesikod) && $telepitesikod>''-*/ && $validPassword;
$isBimLadderAutoCreate  = isset($npID) && $npID > '' && isset($partnerID) && $partnerID == 'kbl' /*-&& isset($telepitesikod) && $telepitesikod>''-*/ && $validPassword;

/*******************************************************************************
 *NAMIRIAL vagy BIMLADDER automata kulcskiadás és program létrehozás
 ******************************************************************************/
if ($isNamirialAutoCreate || $isBimLadderAutoCreate) {
    $queryStr = "SELECT hlID FROM `" . CRMADATBAZIS . "`.`nonprofit` WHERE computer_id = ? AND partnerID = ? AND verID = ?";
    Database::getInstance()->query($queryStr, array('isi', $compid, $partnerID, $ver8and9));
    $res = Database::getInstance()->fetchNext();

    $rangeMin   = $isNamirialAutoCreate ? 940001 : 920001;
    $rangeMax   = $isNamirialAutoCreate ? 949999 : 929999;
    $interval   = $isNamirialAutoCreate ? 90 : 30;
    $country_id = $isNamirialAutoCreate ? 39 : 82;
    $topic_id   = $isNamirialAutoCreate ? 366 : 368;
    $info       = $isNamirialAutoCreate ? 'Namirial nonprofit kulcs aktiválás' : 'BIMLadder nonprofit kulcs aktiválás';
    $contact    = $isNamirialAutoCreate ? 8 : 9;
    $fizetve    = $time + $interval * 86400;

    if ($isTwTw) { // Az engedelyezett napok szamat konvertalni kell TWTW eseten
        $interval = Codegen::GetDayInterval(crm_hardlock::getTwTwRootTimeString(), date('Y-m-d', $fizetve));
    }

    $type   = crm_hardlock::GetTypeFromPassword($pwd);
    $ver    = crm_hardlock::GetVersion(array('verPassword8and9' => $ver8and9));

    //ba nincs ehhez a gephez meg non-profit program regisztralva
    if (empty($res)) {
        $hlNum  = crm_hardlock::GetTheFirstNotUsedHlNumFromInterval($rangeMin, $rangeMax);
        $pass   = Codegen::GeneratePassword($hlNum, 0, $type, $ver['verCode']);
        $aktKod = Codegen::GenerateTimeCode($pass, $isid, $interval);

        // Ha nincs benne a user a CRM-be, akkor hozza adjuk
        $userID = crm_users::AddUser(
            array(
                'strName'       => $name,
                'strEMail'      => $email,
                'strTel'        => $phone,
                'nCtrID'        => $country_id,
                'old_db'        => 'clusers_eng',
                'dateInsert'    => $time,
                'strCompany'    => $company,
                'nUserType'     => 2
            ),
            $newsletter,
            'sssisssi'
        );

        //ba regisztraljuk hozza a non-profit programot
        crm_hardlock::AddNonprofit(
            array(
                'isid'                  => $isid,
                'verid'                 => $ver8and9,
                'hlID'                  => $hlNum,
                'nUserID'               => $userID,
                'add_datetime'          => date('Y-m-d H:i:s', $time),
                'expire_datetime'       => date('Y-m-d H:i:s', strtotime('+90 day', $time)),
                'activation_datetime'   => date('Y-m-d H:i:s', $time),
                'old_db'                => 'clusers_eng',
                'partnerID'             => $partnerID,
                'enabled'               => 'Y',
                'computer_id'           => $compid
            ),
            'sisissssssi'
        );

        //Namirial vagy BIMLADDER non-profit kod aktivalas beszurasa crm -> u_history tablaba
        crm_users::AddUserHistory(array(
            'nUserID'       => $userID,
            'nTopicID'      => $topic_id,
            'dateEvent'     => date('Y-m-d H:i:s', $time),
            'strPlace'      => '',
            'strInfo'       => $info,
            'nManagerID'    => 36,
            'insertDate'    => date('Y-m-d H:i:s', $time)
        ));

        crm_hardlock::AddHardlock(
            array(
                'hlNum'         => $hlNum,
                'hlCtrID'       => $country_id,
                'hlLan'         => 0,
                'hlStat'        => 1,
                'hlDateIssue'   => date('Y-m-d', $time),
                'hlManID'       => 36,
                'hlTime'        => date('Y-m-d H:i:s', $time),
                'hlUser'        => $userID,
                'hlDealer'      => 62103,
                'bUjithato'     => 1,
                'old_db'        => 'clusers_eng'
            ),
            'siiisissiis'
        );

        crm_hardlock::AddProgram(
            array(
                'prTypeID'      => $type,
                'prVerID'       => $ver['verID'],
                'prLan'         => 0,
                'prPass'        => trim($pass),
                'prSellDate'    => date('Y-m-d', $time),
                'prActDate'     => date('Y-m-d', $fizetve), // 90 vagy 30 nap
                'prFizetve'     => date('Y-m-d', $fizetve),
                'prActCode'     => trim($aktKod),
                'prTime'        => date('Y-m-d H:i:s', $time),
                'prLastMod'     => date('Y-m-d H:i:s', $time),
                'prContact'     => $contact, // Non-profit
                'prHlNum'       => $hlNum, // 99xxxx
                'prManID'       => 36, // web
                'prStat'        => 0,
                'prHiType'      => 1, // 1 Rendelés | 2 Tipus Valtas | 3 Frissites | 4 Auto Friss.
                'twtw'          => $isTwTw ? 1 : 0
            ),
            'iiisssssssisiiii'
        );

        $pwd = $pass; //ba 2018.07.02. mostantol az uj jelszava a usernek a most generalt, 94-es lesz, nem pedig a 93-as!
    } else {
        //ba ehhez a gephez mar volt non-profit regisztracio, keressuk ki a sorozatszamot neki
        $hlNum = $res['hlID'];
        $query = "SELECT prPass FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?";
        Database::getInstance()->query($query, array('s', $hlNum));
        $programQuery = Database::getInstance()->fetchNext();
        $pwd = $programQuery['prPass'];
    }
} //- if ($isNamirialAutoCreate || $isBimLadderAutoCreate) vege

$hlNum = crm_hardlock::GetHlnumFromPassword($pwd);

//insert stats to the userstats table
$stats = array(
    'usLang'            => $user_lang_db,
    'usDate'            => time(),
    'usPwd'             => $pwd,
    'usVer'             => $ver8and9,
    'usCompID'          => $compID,
    'usCtrID'           => $ctrID,
    'usBuild'           => $build,
    'usCtrName'         => $ctrname,
    'usIP'              => $user_IP,
    'usOSData'          => $osdata,
    'usISID'            => $isid,
    'usInditasokSzama'  => 1
);

$query = "SELECT hlLan, hlCtrID, hlStat, hlUser FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlNum = ?";
Database::getInstance()->query($query, array('s', $hlNum));
$hardlock = Database::getInstance()->fetchNext();

$isLanProgram = !empty($hardlock) && $hardlock['hlLan'] > 0;

// A szarmazasi orszag beallitasa
if ($softwareKey) {
    if (!empty($hardlock)) { // Azok a programok, amik regisztrálódnak a CRM-ben 2019
        if (isset($hardlock['hlCtrID'])) $stats['usHlCtrID'] = $hardlock['hlCtrID'];
    }
} else {
    $stats['usHlCtrID'] = substr($pwd, 0, 2);
}

$trialProgram               = crm_hardlock::IsTrialKey($pwd);
$trialSpecialEditionProgram = $trialProgram ? crm_hardlock::IsSpecialEditionTrial($pwd) : false;

// Kereskedelmi valtozatok lekezelese (a statisztika miatt bekerulnek a Namirial es a BIMLadder programok is)
if ($ver8and9 > 29 && (!$trialProgram || $trialSpecialEditionProgram)) {
    if (!$trialSpecialEditionProgram) {
        $binding    = array('s', $pwd);
        $query      = "SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?";
        if ($softwareKey && $isLanProgram) { //- szoftveres lan kulcsnal mindig telepitesenkent egyedi az aktivalo kod
            $query  .= " AND prActCode LIKE ?";
            $binding = array('ss', $pwd, "%-{$isid}-%");
        }
        Database::getInstance()->query($query, $binding);
        $prgrm = Database::getInstance()->fetchNext();

        if (empty($prgrm) && $softwareKey && $isLanProgram) {    //- a lan-os valtozatnal na nem volt telepitve lehet, hogy nem volt talalat
            $query = "SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ? AND (prActCode = '' OR prActCode IS NULL)";
            Database::getInstance()->query($query, array('s', $pwd));
            $prgrm = Database::getInstance()->fetchNext();
        }
    }

    if ($softwareKey) {   //- a telepitesi datum frissitese
        if ($validTelepitesikod) //- telepitesi datum tarolasanak elokeszitese
            $installDate = crm_hardlock::GetInstallationDateFromInstallationCode($telepitesikod, $isTwTw);
        else
            $installDate = time();
    } else {
        if (empty($prgrm)) $installDate = time(); //- todo ez gigantikus hiba, jelezni kell, ha ilyen elofordul
        else $installDate = $prgrm['prSellDate'];
    }

    $stats['usTelepitesiDatum'] = $installDate;

    if (!empty($prgrm)) $jelenlegi_aktivalokod = $prgrm['prActCode'];
    else $jelenlegi_aktivalokod = '';

    //- idokod generalasa
    if ($isTwTw) $aktivalokod = crm_hardlock::GetOrGenerateTimeCodeTWTW($pwd, $isid, $telepitesikod, $npID);
    else $aktivalokod = crm_hardlock::GetOrGenerateTimeCode($pwd, $isid, $telepitesikod, $npID);

    // A userstats2013 tablaba megkeresi az utolso bejegyzest és amennyiben valtozatlan, updateli az inditasok szamat, különben uj bejegyzést hoz letre
    if (!$trialSpecialEditionProgram) {
        $usstatid = crm_hardlock::UpdateInstallationDate($pwd, $compID, $build, $aktivalokod, $user_IP, $installDate, $stats);
    } else {
        // Nem irjuk vissza a generalt kodot
        $usstatid = crm_hardlock::UpdateInstallationDate($pwd, $compID, $build, $jelenlegi_aktivalokod, $user_IP, $installDate, $stats);
    }

    $virtualization = ($hardlock['hlStat'] == '2' ? "false" : "true"); // letiltott kulcs visszajelzése a programnak

    $valasz = ($aktivalokod != "") ? $aktivalokod : "(( nem kapott valaszt ))";

    if (($valasz == "(( nem kapott valaszt ))" && substr($pwd, 0, 2) != 39) || strpos($valasz, 'error') !== false) {
        $query = "SELECT id FROM `" . CRMADATBAZIS . "`.`hibajelento` WHERE pwd = ? ORDER BY datum DESC";
        Database::getInstance()->query($query, array('s', $pwd));
        $res = Database::getInstance()->fetchNext();

        if (!empty($res)) {
            Database::getInstance()->update(
                CRMADATBAZIS . ".hibajelento",
                array(
                    'error'     => $valasz,
                    'datum'     => date('Y-m-d H:i:s', time())
                ),
                array('id'  => $res['id']),
                'ssi'
            );
        } else {
            $query = Database::getInstance()->insert(
                CRMADATBAZIS . ".hibajelento",
                array(
                    "error" => $valasz,
                    "datum" => date('Y-m-d H:i:s', time()),
                    "pwd"   => $pwd
                ),
                'sss'
            );
        }
    }
}

if ($trialProgram && substr($pwd, 0, 2) == '96' && substr($pwd, 2, 4) != '0001' && substr($pwd, 2, 4) != '0002')
    crm_hardlock::AddToDebugTable('Unknown trial code (' . $ver8and9 . ')', $pwd);

if ($trialProgram && $ver8and9 == 37 && $build == 371) $virtualization = 'false'; // a 2020-as program 371-es buildjenek a trial programjai nem jartak le, ezert le lettek tiltva
/*if ($trialProgram && $ver8and9 == 37 && $build < 397 && $build > 100)
    crm_hardlock::AddToDebugTable('Old trial 2020 build ('.$build.')', $pwd);*/

$query = "SELECT prID, prLogFilter FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?";
Database::getInstance()->query($query, array('s', $pwd));
$programs = Database::getInstance()->fetchNext();

if ($ver8and9 == 37 && $build == 257) { // A listaban megadott vagy ismeretlen sorozatszamok letiltasa a 20-as verzio, 257-es buildnel
    $disabledPrograms = array(
        '3900818370905571',
        '3900918370787595',
        '3900928370377805',
        '3927288372916698',
        '3927618370940811',
        '3927818370587932',
        '3935548370737107',
        '3935548370737107',
        '4317638370978599',
        //- Febr. 17-en leallitott programok 12:07
        '3944107370431359',
        '3902268370018090',
        '3900598370731017',
        '3958088370568762',
        '3972278370582604',
        '3971618370953291',
        '3969098372372780',
        '3967778370942522',
        '3965826370794868',
        '3980518370165197',
        '3979978372152989',
        '3979156370468368',
        '3975678370016038',
        '3986628370454716',
        '3985648370487415',
        '3984778370420511',
        '3983916370785889',
        '3981746370800383',
        '3988768370350372',
        '3988328379279434',
        '3988146370680554',
        '3987726370647018',
        '3987298370563850',
        //- Febr. 24-en leallitott programok 9:27
        '9968618370957233',
        '9939518370957951',
        '9988778370193564',
        '9936978370437452',
        '9914298370034321',
    );

    if (in_array($pwd, $disabledPrograms) || empty($programs))
        $virtualization = 'false';

    if (!empty($programs)) { // Akik felhasznalok, azokat iranyitsuk at az oldalra
        if ($user_lang_db == 'hun')
            $personalMessageLink = 'https://www.archline.hu/build-257?lang=';
        elseif ($user_lang_db == 'ita')
            $personalMessageLink = 'https://www.archlinexp.com/build-257-italy?lang=';

        if ($personalMessageLink != '') {
            crm_hardlock::AddToDebugTable('A felhasznalo uzenetet kapott 257-es frissitesrol', $pwd);
        }
    }
}

// Tavoli logolasi parameterek beallitasa
$logfilter = 0;
if ($validPassword && !$crackedProgram && !$trialProgram) $logfilter = $programs['prLogFilter'];

// Ha a verid >= 36, akkor beinsertalja a hardlockot és a computer id-t a hardlock_computers tablaba, ha meg nincs benne
if ($softwareKey && !$crackedProgram && !$trialProgram) crm_hardlock::AddHardlockComputer($hlNum, $compid, $ver8and9);

// Kulcsok tesztelese
if ($softwareKey && !$crackedProgram && !$trialProgram) {
    $valasz = crm_hardlock::sCheckPassword($pwd);

    if (!empty($valasz)) {
        $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
        $message = "Checked Password || Serial: {$pwd} || Valasz: {$valasz} || url: {$actual_link}";
        crm_hardlock::AddToDebugTable($message, $pwd);
    }
}

// Modul es reaktivalo kodok kiiratasa
if (!$crackedProgram && !$trialProgram) {
    // Modul kodok osszegyujtese
    $moduleList = "";
    if (!empty($programs)) {
        $query = "SELECT mdCode FROM `" . CRMADATBAZIS . "`.`p_modules` WHERE mdPrID = ?";
        Database::getInstance()->query($query, array('i', $programs['prID']));
        $modules = Database::getInstance()->fetchAssoc();

        foreach ($modules as $module) {
            if (!empty($moduleList)) $moduleList .= ";";

            $moduleList .= $module['mdCode'];
        }
    }

    // Reaktivalokodok kuldese
    if ($virtualization == "true" && $reactivationCounter > 0) {
        $reactivationCounter--;
        $modulIsid = substr($pwd, 0, 2) . $ver8and9;

        if ($reactivationCounter > 4) $reactivationCounter = 4; // 5-nel tobb nem lehet

        for ($i = 0; $i <= $reactivationCounter; $i++) {
            $modulID = 35 + $i;
            $reactivationCode = Codegen::GenerateTimeCode($pwd, $modulIsid, $modulID);

            if (!empty($moduleList)) $moduleList .= ";";

            $moduleList .= $reactivationCode;
        }
    }
}

if ($softwareKey) {
    $utst = time();
    (int)$convertedDay = crm_hardlock::ConvertDay(date('w'));
    $tid = (int)($utst / $convertedDay);

    $query = "SELECT * FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = ? AND isid = ? AND aktiv = ?";
    Database::getInstance()->query($query, array('ssi', $pwd, $isid, 1));
    $p_serial_isid = Database::getInstance()->fetchAssoc();

    if (empty($p_serial_isid)) $regenr = crm_hardlock::No($utst, 39);
    else $regenr = crm_hardlock::Yes($utst, 39);
}

header('Content-Type: text/xml; charset=utf-8');
header('Content-Disposition: inline; filename=response.xml');
print '<' . '?' . 'xml version="1.0" encoding="UTF-8" standalone="yes"' . '?' . '>
    <Tips>
        <Tip lang="en" version="2">
            <path>/public/support/tips/en/</path>
        </Tip>
        ' . ((isset($aktivalokod) && $aktivalokod) ? '<actcode>' . $aktivalokod . '</actcode>' : '') . '
        ' . ((isset($virtualization) && $virtualization) ? '<Virtualization>' . $virtualization . '</Virtualization>' : '') . '
        ' . ((isset($usstatid) && (int)$usstatid > 0) ? '<actid>' . (int)$usstatid . '</actid>' : '') . '
        <logfilter>' . $logfilter . '</logfilter>
        ' . ((empty($moduleList) == false) ? '<Modules>' . $moduleList . '</Modules>' : '') . '
        <loginEnabled>' . ($hlNum == '360006' ? 'true' : 'false') . '</loginEnabled>
        ' . ((isset($regenr) && (int)$regenr > 0) ? '<regnr>' . (int)$regenr . '</regnr>' : '') . '
        ' . ((isset($tid) && (int)$tid > 0) ? '<tid>' . (int)$tid . '</tid>' : '') . '
        ' . ((isset($personalMessageLink) && $personalMessageLink) ? '<PersonalMessageLink>' . $personalMessageLink . '</PersonalMessageLink>' : '') . '
    </Tips>';
