Skip to content

Commit

Permalink
add options in conf section FIND
Browse files Browse the repository at this point in the history
optimize request keys from server
add tmp clear function
optimize mirror checks
  • Loading branch information
Kingston-kms committed Feb 20, 2021
1 parent 58c8e3e commit 30bb35f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 14 deletions.
9 changes: 7 additions & 2 deletions inc/classes/Mirror.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ static public function test_key()

$test_mirrors = [];
foreach (static::$ESET['mirror'] as $mirror) {

Tools::download_file(
[
CURLOPT_USERPWD => static::$key[0] . ":" . static::$key[1],
Expand All @@ -118,7 +119,8 @@ static public function test_key()
if ($version) {
$maxVersion = $version > $maxVersion ? $version : $maxVersion;
$sameMirrors[] = ['host' => $mirror, 'db_version' => $version];
}
} else
return false;
}

static::$mirrors = array_filter($sameMirrors, function ($v, $k) use ($maxVersion) {
Expand Down Expand Up @@ -416,6 +418,7 @@ static protected function single_download($download_files, $onlyCheck = false, $
static::$total_downloads += $header['size_download'];
break;
} else {
if ($onlyCheck) @unlink(static::$tmp_update_file);
@unlink($out);
}
}
Expand All @@ -431,7 +434,7 @@ static protected function download($download_files, $onlyCheck = false, $checked
{
Log::write_log(Language::t("Running %s", __METHOD__), 5, static::$version);

switch (function_exists('curl_multi_init') && Config::get('CONNECTION')['use_multidownload']) {
switch (function_exists('curl_multi_init') && (bool)(Config::get('CONNECTION')['use_multidownload']) && !$onlyCheck) {
case true:
static::multiple_download($download_files, $onlyCheck, $checkedMirror);
break;
Expand Down Expand Up @@ -533,6 +536,7 @@ static public function set_key($key)
static public function destruct()
{
Log::write_log(Language::t("Running %s", __METHOD__), 5, static::$version);

static::$total_downloads = 0;
static::$version = null;
static::$source_update_file = null;
Expand All @@ -543,6 +547,7 @@ static public function destruct()
static::$unAuthorized = false;
}


/**
* @param $folder
* @return int
Expand Down
60 changes: 55 additions & 5 deletions inc/classes/Nod32ms.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ private function validate_key($key)
{
Log::write_log(Language::t("Running %s", __METHOD__), 5, Mirror::$version);
$result = explode(":", $key);
Log::write_log(Language::t("Validating key [%s:%s]", $result[0], $result[1]), 4, Mirror::$version);

if ($this->key_exists_in_file($result[0], $result[1], static::$key_invalid_file)) return false;
Log::write_log(Language::t("Validating key [%s:%s] for version %s", $result[0], $result[1], Mirror::$version), 4, Mirror::$version);

Mirror::set_key(array($result[0], $result[1]));
$ret = Mirror::test_key();
Expand Down Expand Up @@ -401,9 +402,26 @@ private function get_key_from_server()

if ($FIND['use_server']) {
try {
$key = file_get_contents($FIND['server_url']);
$ch = curl_init();
$opt = [

CURLOPT_URL => $FIND['server_url'],
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => 1
];
if (strlen($FIND['user']) > 0 ) {
$opt[CURLOPT_POST] = true;
$opt[CURLOPT_POSTFIELDS] = "user=" . $FIND['user'];
}
curl_setopt_array($ch, $opt);
$key = curl_exec($ch);
if ($key == false) {
Log::write_log(Language::t("Error %s", curl_error($ch)), 5, Mirror::$version);
return false;
}

$key = json_decode($key, true);
if ($this->validate_key($key['username'] . ':' . $key['password'])) {
if ($key && $this->validate_key($key['username'] . ':' . $key['password'])) {
static::$foundValidKey = true;
return true;
}
Expand All @@ -423,7 +441,11 @@ private function find_keys()
Log::write_log(Language::t("Running %s", __METHOD__), 5, Mirror::$version);
$FIND = Config::get('FIND');

if ($this->get_key_from_server()) return true;
$attempts = 0;
while ($attempts < $FIND['number_attempts']) {
if ($this->get_key_from_server()) return true;
$attempts++;
}

if ($FIND['auto'] != 1)
return null;
Expand Down Expand Up @@ -595,15 +617,17 @@ private function run_script()
$total_size = array();
$total_downloads = array();
$average_speed = array();
//$web_dir = Config::get('SCRIPT')['web_dir'];


foreach ($DIRECTORIES as $version => $dir) {
if (Config::upd_version_is_set($version) == '1') {

Log::write_log(Language::t("Init Mirror for version %s in %s", $version, $dir['name']), 5, $version);
Mirror::init($version, $dir);

static::$foundValidKey = false;
$this->read_keys();

if (static::$foundValidKey == false) {
$this->find_keys();

Expand Down Expand Up @@ -652,6 +676,11 @@ private function run_script()
}
}

foreach (glob(Tools::ds(TMP_PATH, '*')) as $folder) {
static::clear_tmp($folder);
@rmdir($folder);
}

Log::write_log(Language::t("Total size for all databases: %s", Tools::bytesToSize1024(array_sum($total_size))), 3);

if (array_sum($total_downloads) > 0)
Expand All @@ -663,6 +692,27 @@ private function run_script()
if (Config::get('SCRIPT')['generate_html'] == '1') $this->generate_html();
}

private function clear_tmp($path)
{
try {
$iterator = new DirectoryIterator($path);
foreach ( $iterator as $fileinfo) {
if($fileinfo->isDot())continue;
if($fileinfo->isDir()){
if(static::clear_tmp($fileinfo->getPathname()))
@rmdir($fileinfo->getPathname());
}
if($fileinfo->isFile()){
@unlink($fileinfo->getPathname());
}
}
} catch ( Exception $e ){
// write log
return false;
}
return true;
}

/**
* @param $old_version
* @param $new_version
Expand Down
2 changes: 1 addition & 1 deletion inc/classes/Tools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static public function ping(array $options, $hostname, $port = 80, $file = NULL)
static public function bytesToSize1024($bytes, $precision = 2)
{
$unit = ['Bytes', 'KBytes', 'MBytes', 'GBytes', 'TBytes', 'PBytes', 'EBytes'];
return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision) . ' ' . $unit[intval($i)];
return $bytes > 0 ? @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision) . ' ' . $unit[intval($i)] : '0 ' . $unit[intval(0)];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions langpacks/en.lng
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Average speed for all databases: %s/s
n/a
Generating html...
Testing key [%s:%s]
Validating key [%s:%s]
Validating key [%s:%s] for version %s
The script has been stopped!
Checking mirror %s with key [%s:%s]
Extracting file %s to %s
Expand All @@ -90,4 +90,4 @@ Running %s
Your version of database is relevant %s
Mirror %s active
Mirror %s inactive
Try next mirror %s
Try next mirror %s
2 changes: 1 addition & 1 deletion langpacks/ru.lng
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ESET NOD32 сервер обновления
н/д
Генерация html...
Проверка ключа [%s:%s]
Валидация ключа [%s:%s]
Валидация ключа [%s:%s] для версии %s
Скрипт будет остановлен!
Проверка зеркала %s с ключом [%s:%s]
Распаковка файла %s в %s
Expand Down
4 changes: 2 additions & 2 deletions langpacks/ukr.lng
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ESET NOD32 сервер оновлення
н/д
Створення html...
Перевірка ключа [%s:%s]
Валідація ключа [%s:%s]
Валідація ключа [%s:%s] для версії %s
Скрипт буде зупинен!
Перевірка дзеркала %s з ключом [%s:%s]
Розпаковка файлу %s в %s
Expand All @@ -90,4 +90,4 @@ Unrar не є виконуваним за шляхом %s
Версія вашої бази %s актуальна
Дзеркало %s доступне
Дзеркало %s недоступне
Спроба завантаження з наступного дзеркала %s
Спроба завантаження з наступного дзеркала %s
8 changes: 7 additions & 1 deletion nod32ms.conf.eng
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ auto = 1
; Telegram channel: https://t.me/nod32trialKeys

; This parameter is responsible for the ability to take keys from the key server
;  Trial keys, official, it is possible to take a unique key with the ability to automatically update the key
; Trial keys, official, it is possible to take a unique key with the ability to automatically update the key
; If the option is enabled, then the key search does not occur.
use_server = 1

Expand All @@ -169,6 +169,12 @@ use_server = 1
;
server_url = "https://api.nod32-trial-keys.site/api/single-license"

; User email which registered on site nod32-trial-keys.site to request licenses
user = ''

; Number of attempts to request new key if previous invalid
number_attempts = 5

; ###########################
; end

Expand Down
6 changes: 6 additions & 0 deletions nod32ms.conf.rus
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ use_server = 1
;
server_url = "https://api.nod32-trial-keys.site/api/single-license"

; Email юзера, отправившего запрос лицензий на сайте nod32-trial-keys.site
user = ''

; Количество попыток запросить новый ключ, если предыдущий невалидный
number_attempts = 5

; ###########################
; конец блока

Expand Down

0 comments on commit 30bb35f

Please sign in to comment.