940001, 'max' => 949999); public static $arrBIMLadderRange = array('min' => 920001, 'max' => 929999); private static $noAnswer = "(( nem kapott valaszt ))"; private static $arrCodeReplyEnabled = array(30, 34, 36, 38, 40, 41, 42, 43, 44, 47, 48, 49, 82, 88, 91, 92, 93, 94, 95, 97, 98, 99); function ActCode() { if (!class_exists('MySqlHelper')) require_once("MySqlHelper.class.php"); if (!class_exists('crm_hardlock')) require_once($_SERVER['DOCUMENT_ROOT'] . "/common_cadline_libraries/crm_hardlock.class.php"); } public static function getActCode($lang, $version, $session) { if (!is_numeric($version)) { die('Invalid version id sent: ' . $version); } $ctrName = IpToCountryHelper::getInstance()->getCountryName(); $arrSess = self::decodeSessionString($session); if ($lang && is_array($arrSess) && count($arrSess)) { if (isset($arrSess['npID']) && $arrSess['npID'] > '' && isset($arrSess['partnerID']) && $arrSess['partnerID'] == '2nt' && isset($arrSess['idokod']) && $arrSess['idokod'] > '' && isset($arrSess['pwd']) && $arrSess['pwd'] > '') { self::namirialProcess($arrSess['npID'], $arrSess['partnerID'], $arrSess['idokod'], $arrSess['pwd']); } else if (isset($arrSess['npID']) && $arrSess['npID'] > '' && isset($arrSess['partnerID']) && $arrSess['partnerID'] == 'kbl' && isset($arrSess['idokod']) && $arrSess['idokod'] > '' && isset($arrSess['pwd']) && $arrSess['pwd'] > '') { self::bimLadderProcess($arrSess['npID'], $arrSess['partnerID'], $arrSess['idokod'], $arrSess['pwd']); } // $pass=&$arrSess['pwd']; $pass = '9908258340388286'; $kulcs = HardlockHelper::getHardlock(substr($pass, 0, 6)); $prog = ProgramHelper::getProgram($pass); $isid = ProgramHelper::getIsidFromPass($pass, $prog['prActCode']); $aktivalokod = CodeGenHelper::generateTimeCode($pass, $isid, 600); // ??? $tomb = array_merge($arrSess, array('lang' => $lang, 'ctrname' => $ctrName, 'aktivalokod' => $aktivalokod, 'valasz' => (trim($aktivalokod) > "" ? trim($aktivalokod) : self::$noAnswer))); $newUsID = self::insertUserStats($tomb); // ??? self::insertAktivalasInfok(array_merge($tomb, array('usID' => $newUsID, 'isid' => $isid))); self::xmlOutput($kulcs['hlStat'], $prog['prLogFilter'], $aktivalokod, $newUsID); // ??? if (substr($pass, 7, 2) > 29 && substr($pass, 0, 2) != '96') // ??? { /* $version->ujaktivalasikod2($pass,$isid,$arrSess['idokod']); */ } } else { self::insertError("Valami hianyzik:\nlang: " . $lang . "\nverzio: " . $version . "\nssID: " . $session . "\ndecoded session: " . print_r($arrSess, TRUE), __FUNCTION__); } } public static function getAnswer($pass, $isid, $idokod) { if (self::isCodeReplyEnabled($pass) === TRUE) { $prog = ProgramHelper::getPrograms($pass); // a LAN-osok miatt több rekordot is visszaadhat if (!$prog) { return "error: nincs ilyen password"; } $kulcs = HardlockHelper::getHardlock((int)substr($pass, 0, 6)); if (!$kulcs) { return "error: nincs ilyen hardlock"; } if ($kulcs['hlStat'] != 1) { return "error: nem aktiv a program"; } $szoftveres = CodeGenHelper::isSoftwareKey($pass); if ($szoftveres === FALSE) { return $prog[0]['prActCode']; } // hardveres kulcs esetén egyből visszaadja az aktuális aktiválási kód /* ???????????????????????????????????????????????????????????????????????????????? */ $voltures = false; foreach ($prog as $program) { if ($program['prActCode'] != "") // neki megfelelő aktiválási kód { $this->win10creator_old_isid = substr($program['prActCode'], 5, 4); $isidOK = (substr($program['prActCode'], 5, 4) == $isid); if ($isidOK) { $valasz = $program['prActCode']; break; } // aktuális aktiválási kód ???? if (!$isidOK && substr($program['prActCode'], 7, 2) == substr($isid, 2, 2)) { $elteltnapok = 0; sscanf(substr($idokod, 11, 2), '%02x', $elteltnapok); $elteltnapok += $this->convert(substr($idokod, 10, 1)) * 256; $engedelyezettnapok = 0; sscanf(substr($program['prActCode'], 11, 2), '%02x', $engedelyezettnapok); $engedelyezettnapok += $this->convert(substr($program['prActCode'], 10, 1)) * 256; if ($engedelyezettnapok > $elteltnapok) { $valasz = "error: win10 creator"; break; } } if ($isidOK) { $valasz = $program['prActCode']; // aktuális aktiválási kód ??? break; } else { $valasz = 'error: masik gep van regisztralva'; } } else { $valasz = "error: hianyzo kod"; // nincs beirva a kod $voltures = TRUE; } } if ($voltures === TRUE && $valasz == "error: masik gep van regisztralva") // LAN-os szoftver kulcsos liszensznél ha ezt a liszenszt nem találtuk de volt üres liszensz, akkor csinálja ezt { $valasz = "error: hianyzo kod"; } /* ???????????????????????????????????????????????????????????????????????????????? */ return $valasz; } } public static function bimLadderProcess($npID = '', $partnerID = '', $idokod = '', $pwd = '') { if ($npID == '' || $partnerID != 'kbl' || $idokod == '' || $pwd == '') { die('Missing parameters: |' . $npID . '|' . $partnerID . '|' . $idokod . '|' . $pwd . '|'); } MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE `computer_id`='" . $npID . "' LIMIT 1;"); $res4 = MySqlHelper::getInstance()->fetchAssoc(); if (empty($res4)) { $comp = array( 'computer_id' => $npID, 'last_mod' => date('Y-m-d', time()) ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`computers`", $comp); } MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE `computer_id`='" . $npID . "' LIMIT 1;"); $compid = MySqlHelper::getInstance()->fetchAssoc(); MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`nonprofit` WHERE computer_id='" . $compid[0]['id'] . "' AND partnerID = 'kbl' LIMIT 1;"); $res = MySqlHelper::getInstance()->fetchAssoc(); if (empty($res)) { $time = time(); $hlNum = crm_hardlock::GetTheFirstNotUsedHlNumFromInterval(self::$arrBIMLadderRange['min'], self::$arrBIMLadderRange['max']); $arrIdokod = explode("-", $idokod); $isid = $arrIdokod[1]; $type = substr($pwd, 6, 1); $verid = substr($pwd, 7, 2); MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`p_versions` WHERE `verPassword8and9`='" . $verid . "' LIMIT 1;"); $ver = $msh->fetchAssoc(); $ver = $ret[0]; $interval = date_diff(date_create(date('Y-m-d', $time)), date_create((string)((int)date('Y', $time) + 1) . '-12-31')); $pass = CodeGenHelper::generatePassword($hlNum, 0, $type, $ver['verCode']); // hlNum,lan,type=8,75=2018 $aktKod = CodeGenHelper::generateTimeCode($pass, $isid, $interval->days); // pass,isid,numOfDays $msh->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE computer_id='" . $npID . "' LIMIT 1;"); $res = $msh->fetchAssoc(); if (empty($res)) { $comp = array( 'computer_id' => $npID, 'last_mod' => date('Y-m-d', time()) ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`computers`", $comp); } MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE `computer_id`='" . $npID . "' LIMIT 1;"); $compid = MySqlHelper::getInstance()->fetchAssoc(); $nonprofit = array( 'isid' => $isid, 'verid' => $verid, 'hlID' => $hlNum, 'nUserID' => 62103, //ba ez invalid! namirialnal is! nem egy Namirial usernek az idje kene hogy itt legyen? Ami most 63051.. 'add_datetime' => date('Y-m-d H:i:s', $time), 'expire_datetime' => (string)((int)date('Y', $time) + 1) . '-12-31 23:59:59', 'activation_datetime' => date('Y-m-d H:i:s', $time), 'old_db' => 'clusers_eng', 'partnerID' => $partnerID, 'enabled' => 'Y', 'computer_id' => $compid[0]['id'] ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`nonprofit`", $nonprofit); $hardlock = array( 'hlNum' => $hlNum, 'hlCtrID' => 82, 'hlLan' => 0, 'hlStat' => 1, 'hlDateIssue' => date('Y-m-d', $time), 'hlManID' => 36, 'hlTime' => date('Y-m-d H:i:s', $time), 'hlUser' => 62103, //ba ez invalid! namirialnal is! nem egy Namirial usernek az idje kene hogy itt legyen? Ami most 63051.. 'hlDealer' => 62103, //ba ez invalid! namirialnal is! nem egy Namirial usernek az idje kene hogy itt legyen? Ami most 63051.. 'bUjithato' => 1, 'old_db' => 'clusers_eng' ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`hardlock`", $hardlock); $program = array( 'prTypeID' => $type, 'prVerID' => $ver['verID'], 'prLan' => 0, 'prPass' => trim($pass), 'prSellDate' => date('Y-m-d', $time), 'prActDate' => (string)((int)date('Y', $time) + 1) . '-12-31', 'prFizetve' => (string)((int)date('Y', $time) + 1) . '-12-31', 'prActCode' => trim($aktKod), 'prTime' => date('Y-m-d H:i:s', $time), 'prLastMod' => date('Y-m-d H:i:s', $time), 'prContact' => 9, 'prHlNum' => $hlNum, // 99xxxx 'prManID' => 36, // web 'prStat' => 0, 'prHiType' => 1, // 1 Rendelés | 2 Típus Váltás | 3 Frissítés | 4 Auto Friss. ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`h_programs`", $program); } } public static function namirialProcess($npID = '', $partnerID = '', $idokod = '', $pwd = '') { if ($npID == '' || $partnerID != '2nt' || $idokod == '' || $pwd == '') { die('Missing parameters: |' . $npID . '|' . $partnerID . '|' . $idokod . '|' . $pwd . '|'); } MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE `computer_id`='" . $npID . "' LIMIT 1;"); $res4 = MySqlHelper::getInstance()->fetchAssoc(); if (empty($res4)) { $comp = array( 'computer_id' => $npID, 'last_mod' => date('Y-m-d', time()) ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`computers`", $comp); } MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE `computer_id`='" . $npID . "' LIMIT 1;"); $compid = MySqlHelper::getInstance()->fetchAssoc(); MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`nonprofit` WHERE computer_id='" . $compid[0]['id'] . "' AND partnerID = '2nt' LIMIT 1;"); $res = MySqlHelper::getInstance()->fetchAssoc(); if (empty($res)) { $time = time(); $hlNum = crm_hardlock::GetTheFirstNotUsedHlNumFromInterval(self::$arrNamirialRange['min'], self::$arrNamirialRange['max']); $arrIdokod = explode("-", $idokod); $isid = $arrIdokod[1]; $type = substr($pwd, 6, 1); $verid = substr($pwd, 7, 2); MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`p_versions` WHERE `verPassword8and9`='" . $verid . "' LIMIT 1;"); $ver = $msh->fetchAssoc(); $ver = $ret[0]; $interval = date_diff(date_create(date('Y-m-d', $time)), date_create((string)((int)date('Y', $time) + 1) . '-12-31')); $pass = CodeGenHelper::generatePassword($hlNum, 0, $type, $ver['verCode']); // hlNum,lan,type=8,75=2018 $aktKod = CodeGenHelper::generateTimeCode($pass, $isid, $interval->days); // pass,isid,numOfDays MySqlHelper::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`computers` WHERE `computer_id`='" . $npID . "' LIMIT 1;"); $compid = MySqlHelper::getInstance()->fetchAssoc(); $nonprofit = array( 'isid' => $isid, 'verid' => $verid, 'hlID' => $hlNum, 'nUserID' => 62103, //ba ez invalid! namirialnal is! nem egy Namirial usernek az idje kene hogy itt legyen? Ami most 63051.. 'add_datetime' => date('Y-m-d H:i:s', $time), 'expire_datetime' => (string)((int)date('Y', $time) + 1) . '-12-31 23:59:59', 'activation_datetime' => date('Y-m-d H:i:s', $time), 'old_db' => 'clusers_eng', 'partnerID' => $partnerID, 'enabled' => 'Y', 'computer_id' => $compid[0]['id'] ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`nonprofit`", $nonprofit); $hardlock = array( 'hlNum' => $hlNum, 'hlCtrID' => 39, 'hlLan' => 0, 'hlStat' => 1, 'hlDateIssue' => date('Y-m-d', $time), 'hlManID' => 36, 'hlTime' => date('Y-m-d H:i:s', $time), 'hlUser' => 62103, //ba ez invalid! namirialnal is! nem egy Namirial usernek az idje kene hogy itt legyen? Ami most 63051.. 'hlDealer' => 62103, //ba ez invalid! namirialnal is! nem egy Namirial usernek az idje kene hogy itt legyen? Ami most 63051.. 'bUjithato' => 1, 'old_db' => 'clusers_eng' ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`hardlock`", $hardlock); $program = array( 'prTypeID' => $type, 'prVerID' => $ver['verID'], 'prLan' => 0, 'prPass' => trim($pass), 'prSellDate' => date('Y-m-d', $time), 'prActDate' => (string)((int)date('Y', $time) + 1) . '-12-31', 'prFizetve' => (string)((int)date('Y', $time) + 1) . '-12-31', 'prActCode' => trim($aktKod), 'prTime' => date('Y-m-d H:i:s', $time), 'prLastMod' => date('Y-m-d H:i:s', $time), 'prContact' => 8, // Non-profit 'prHlNum' => $hlNum, // 99xxxx 'prManID' => 36, // web 'prStat' => 0, 'prHiType' => 1, // 1 Rendelés | 2 Típus Váltás | 3 Frissítés | 4 Auto Friss. ); MySqlHelper::getInstance()->insert("`" . CRMADATBAZIS . "`.`h_programs`", $program); } } public static function decodeSessionString($str = "") { if ($str == "") { die("Missing session string!"); } $str_decoded = base64_decode($str); //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))); } } $parts = explode('_', $decoded); $arrSess['empty'] = $parts[0]; $arrSess['pwd'] = $parts[1]; $arrSess['compID'] = $parts[2]; $arrSess['build'] = $parts[3]; $arrSess['ctrID'] = $parts[4]; $arrSess['idokod'] = $parts[5]; if (count($parts) > 6) { if (isset($parts[6]) && trim($parts[6]) > '') $arrSess['osdata'] = $parts[6]; if (isset($parts[7]) && trim($parts[7]) > '') $arrSess['usGCMan'] = $parts[7]; if (isset($parts[8]) && trim($parts[8]) > '') $arrSess['usGCType'] = $parts[8]; if (isset($parts[9]) && trim($parts[9]) > '') $arrSess['usGCDriverVer'] = $parts[9]; if (isset($parts[10]) && trim($parts[10]) > '') $arrSess['npID'] = $parts[10]; if (isset($parts[11]) && trim($parts[11]) > '') $arrSess['partnerID'] = $parts[11]; } return ($arrSess); } public static function isCodeReplyEnabled($pass = '') { if ($pass == '') return (FALSE); $ret = (in_array((int)substr($pass, 0, 2), self::$arrCodeReplyEnabled) ? TRUE : FALSE); return ($ret); } public static function insertUserStats($tomb = array()) { if (empty($tomb)) return (FALSE); $stats = array( 'usLang' => $tomb['lang'], 'usDate' => time(), 'usPwd' => $tomb['pwd'], 'usVer' => substr($tomb['pwd'], 7, 2), 'usCompID' => $tomb['compID'], 'usCtrID' => $tomb['ctrID'], 'usBuild' => $tomb['build'], 'usCtrName' => $tomb['ctrname'], 'usIP' => $_SERVER['REMOTE_ADDR'], 'usOSData' => $tomb['osdata'], ); if (isset($tomb['usGCMan']) && trim($tomb['usGCMan']) > '' && isset($tomb['usGCType']) && trim($tomb['usGCType']) > '' && isset($tomb['usGCDriverVer']) && trim($tomb['usGCDriverVer']) > '') { $stats['usGCMan'] = $tomb['usGCMan']; $stats['usGCType'] = $tomb['usGCType']; $stats['usGCDriverVer'] = $tomb['usGCDriverVer']; } if (substr($tomb['pwd'], 0, 1) == '9') { if (in_array(substr($pwd, 0, 2), array('99', '98', '95'))) { $hlRec = HardlockHelper::getHardlock(substr($pwd, 0, 6)); if (isset($hlRec['hlCtrID'])) $stats['usHlCtrID'] = $hlRec['hlCtrID']; } } else { $stats['usHlCtrID'] = substr($tomb['pwd'], 0, 2); } if (CodeGenHelper::isSoftwareKey($tomb['pwd']) === TRUE) $stats['usISID'] = substr($tomb['idokod'], 5, 4); MySqlHelper::getInstance()->insert("`cl_hlusers`.`userstats2013`", $stats); $newID = MySqlHelper::getInstance()->getInsertedId(); return ($newID); } public static function insertAktivalasInfok($tomb = array()) { if (empty($tomb)) return (FALSE); $info = array( "kulcs" => substr($tomb['pwd'], 0, 6), "datum" => date('Y-m-d H:i:s', time()), "ip" => $_SERVER['REMOTE_ADDR'], "kuldo" => "tips", "leiras" => "programinditas - pw: " . $tomb['pwd'] . ", build: " . $tomb['build'] . ", isid: " . $tomb['isid'] . ", időkód: " . $tomb['idokod'] . ", valasz: " . $tomb['valasz'], "statusz" => "uj", "usGCMan" => (isset($tomb['usGCMan']) && trim($tomb['usGCMan']) ? trim($tomb['usGCMan']) : NULL), "usGCType" => (isset($tomb['usGCType']) && trim($tomb['usGCType']) ? trim($tomb['usGCType']) : NULL), "usGCDriverVer" => (isset($tomb['usGCDriverVer']) && trim($tomb['usGCDriverVer']) ? trim($tomb['usGCDriverVer']) : NULL), "usID" => (isset($tomb['usID']) && trim($tomb['usID']) ? trim($tomb['usID']) : NULL), ); MySqlHelper::getInstance()->insert('`' . CRMADATBAZIS . '`.`h_aktivalas_infok`', $info); } public static function insertError($str = '', $fv = '') { if (trim($str) > '') { MySqlHelper::getInstance()->insert("`" . JMLADATBAZIS . "`.`a_hibak`", array( 'osztaly' => __CLASS__, 'fv' => trim($fv), 'hiba' => trim($str), 'datum' => date('Y-m-d H:i:s', time()), )); } } public static function getEnabledLang($lang = "") { return (in_array(strtolower($lang), self::$arrEnabledLangs) ? strtolower($lang) : 'eng'); } public static function xmlOutput($hlStat, $prLogFilter, $aktivalokod, $newUsID) { 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"' . '?' . '>' . '' . ((isset($aktivalokod) && $aktivalokod > '') ? $aktivalokod : self::$noAnswer) . '' . // aktivalo kod '' . ((isset($hlStat) && (int)$hlStat == 2) ? 'false' : 'true') . '' . // letiltott kulcs visszajelzése a programnak ((isset($newUsID) && (int)$newUsID > 0) ? '' . (int)$newUsID . '' : '') . // userstats tabla rekord azonosito, amit a telemetria tabla is megkap, hogy ossze lehessen kapcsolni '' . ((isset($prLogFilter) && (int)$prLogFilter > 0) ? $prLogFilter : 0) . '' . // user programjan tavolrol be lehet kapcsolni a logolast '' . ($_SERVER['REMOTE_ADDR'] = '46.139.14.111' ? 'true' : 'false') . '' . ''; } } // end of class