File: /var/www/www-root/data/www/wowik.click/tds/cron.php
<?php
define("INDEX", "yes");
require_once __DIR__.'/config.php';
@set_time_limit(180);
@ini_set('memory_limit', '-1');
if(!file_exists(__DIR__.'/temp')){
mkdir(__DIR__.'/temp', 0755);
}
$header = '';
$request = '';
$time = date("H:i");
$minutes = minutes($rnd);
if($time == '00:00' && file_exists(__DIR__."/$folder_log")){
$expiry = strtotime(date("Y-m-d", strtotime('-'.$period_log.' day')));
$db_array = array();
$files = scandir(__DIR__."/$folder_log");
foreach($files as $v){
if($v != "." && $v != ".." && $v != ".htaccess" && $v != "postback.db" && is_file(__DIR__."/$folder_log/$v") && preg_match("~^.+?\.db$~", $v)){
$db_array[] = $v;
}
}
foreach($db_array as $db_name){
$db = new SQLite3(__DIR__."/$folder_log/$db_name");
$db->busyTimeout($timeout_1);
$db->exec("PRAGMA journal_mode = WAL;");
$db->querySingle("BEGIN IMMEDIATE;");
$table_del = array();
$res = $db->query("SELECT * FROM sqlite_master WHERE type = 'table';");
while($array = $res->fetchArray(SQLITE3_ASSOC)){
$table = $array['name'];
if($table <= $expiry){
$table_del[] = $table;
}
}
if(!empty($table_del)){
foreach($table_del as $table){
$db->querySingle("DROP TABLE '$table';");
}
}
$db->querySingle("COMMIT;");
$db->querySingle("VACUUM;");
$db->close();
}
if(file_exists(__DIR__."/$folder_log/postback.db")){
$expiry = strtotime(date("Y-m-d", strtotime('-'.($period_pb - 1).' day')));
$db = new SQLite3(__DIR__."/$folder_log/postback.db");
$db->busyTimeout($timeout_1);
$db->exec("PRAGMA journal_mode = WAL;");
$db->querySingle("BEGIN IMMEDIATE;");
$pb_del = array();
$res = $db->query("SELECT * FROM 'postback' WHERE strtotime <= '$expiry';");
while($array = $res->fetchArray(SQLITE3_ASSOC)){
$pb_del[] = $array['cid'];
}
if(!empty($pb_del)){
foreach($pb_del as $cid){
$db->querySingle("DELETE FROM 'postback' WHERE cid = '$cid';");
}
}
$db->querySingle("COMMIT;");
$db->querySingle("VACUUM;");
$db->close();
}
}
if(check_time("05:$minutes")){
$url = 'https://ztds.info/user/?q=update&m=1';
$mode = '';
$data = curl();
if(!empty($data) && $http_code == 200){
sort_ip($data);
}
if(!empty($update_bl)){
$url = $update_bl;
$mode = '';
$data = curl();
if(!empty($data) && $http_code == 200){
$data = explode("\n", $data);
if($update_ip_mode == 1){
$file = trim(file_get_contents(__DIR__."/database/blacklist_ip.dat"));
$file = explode("\n", $file);
$data = array_merge($file, $data);
unset($file);
}
$data = array_unique($data);
$data = implode("\n", $data);
file_put_contents(__DIR__."/database/blacklist_ip.dat", $data."\n", LOCK_EX);
}
}
}
if(date("w") == 4 && check_time("04:$minutes")){
$url = 'https://ztds.info/user/?q=update&m=2';
$mode = '';
$data = curl();
if(!empty($data) && $http_code == 200){
file_put_contents(__DIR__.'/update.zip', $data, LOCK_EX);
$zip = new ZipArchive;
if($zip->open(__DIR__.'/update.zip') === true){
if(!$zip->extractTo(__DIR__)){
unlink(__DIR__.'/update.zip');
}
$zip->close();
}
else{
unlink(__DIR__.'/update.zip');
}
unlink(__DIR__.'/update.zip');
}
}
if(check_time($cron_time_1) && file_exists(__DIR__."/$folder_ini")){
$arr_ini = array();
$files = scandir(__DIR__."/$folder_ini");
foreach($files as $v){
$v = trim($v);
if(preg_match("~^(.+?\.ini)$~", $v)){
$arr_ini[] = $v;
}
}
foreach($arr_ini as $ini){
$g_data = unserialize(file_get_contents(__DIR__."/$folder_ini/$ini"));
$s = 1;
while(!empty($g_data[$s])){
$wr = 0;
if($g_data[$s]['av'] != 0 || $g_data[$s]['rkn'] == 1){
if(!empty($g_data[$s]['s_out']) && preg_match("~^http(s)?:\/\/(.+?)(\/.*)?$~", $g_data[$s]['s_out'], $matches)){
$domain_test = '';
if(preg_match("~^http(s)?:\/\/(.+?)(\/.*)?$~", $g_data[$s]['s_out'], $matches)){
$domain_test = $matches[2];
}
$av_msg_arr = array();
$delay = 0;
$status = 0;
if($g_data[$s]['av'] == 1 && !empty($key_vt)){
$url = "https://www.virustotal.com/api/v3/domains/$domain_test";
$header = array();
$header[] = "x-apikey: $key_vt";
$mode = 'header';
$response = curl();
if($http_code == 200 && !empty($g_data[$s]['av_list'])){
$response = json_decode($response, true);
$arr_res = array_change_key_case($response['data']['attributes']['last_analysis_results']);
$delay = 15;
$sep = separator($g_data[$s]['av_list']);
$arr_anti = explode($sep, $g_data[$s]['av_list']);
foreach($arr_anti as $anti){
$anti = mb_strtolower(trim($anti));
if($arr_res[$anti]['result'] != 'clean' && $arr_res[$anti]['result'] != 'unrated'){
$av_msg_arr[] = $arr_res[$anti]['engine_name'].': <b>'.$arr_res[$anti]['result'].'</b>';
$status = 1;
$service = 'VirusTotal';
}
}
}
}
if($g_data[$s]['av'] == 2){
$url = 'https://ztds.info/user/?q=av&d='.base64_encode(serialize($g_data[$s]['s_out']));
$mode = '';
$response = curl();
if($http_code == 200 && !empty($response)){
$arr_res = array_change_key_case(json_decode($response, true));
$sep = separator($g_data[$s]['av_list']);
$arr_anti = explode($sep, $g_data[$s]['av_list']);
foreach($arr_anti as $anti){
$anti = mb_strtolower(trim($anti));
if(!empty($arr_res[$anti])){
$av_msg_arr[] = $anti.': <b>'.$arr_res[$anti].'</b>';
$status = 1;
$service = 'zTDS_av';
}
}
}
}
if($g_data[$s]['rkn'] == 1 && !empty($domain_test)){
$url = 'https://ztds.info/user/?q=rkn&d='.base64_encode($domain_test);
$mode = '';
$response = curl();
if($http_code == 200 && $response == 1){
$status = 1;
$service = 'zTDS_rkn';
}
}
if($status == 1){
if($g_data[$s]['ch_option'] == 0 && !empty($g_data[$s]['ch_out'])){
$sep = separator($g_data[$s]['ch_out']);
$ch_out = explode($sep, $g_data[$s]['ch_out']);
if(!empty($ch_out[0])){
$out_new = trim($ch_out[0]);
$g_data[$s]['s_out'] = $out_new;
unset($ch_out[0]);
$ch_out = array_values($ch_out);
$ch_out = implode($sep, $ch_out);
$g_data[$s]['ch_out'] = $ch_out;
$wr = 1;
}
}
if($g_data[$s]['ch_option'] == 1 && !empty($g_data[$s]['ch_out'])){
$url = trim($g_data[$s]['ch_out']);
$mode = '';
$out_new = htmlentities(trim(curl()));
if(!empty($out_new)){
$g_data[$s]['s_out'] = $out_new;
}
$wr = 1;
}
if($g_data[$s]['ch_option'] == 2 && !empty($tlg_bot_token) && !empty($tlg_chat_id)){
$av_msg = implode("\n", $av_msg_arr);
$msg = '<b>'.$service."</b>\nGroup: ".$g_data[0]['g_name']."\nStream: ".$g_data[$s]['s_name']."\nDomain: ".$domain_test."\n".$av_msg;
$url = "https://api.telegram.org/bot$tlg_bot_token/sendMessage";
$request = array(
'chat_id' => $tlg_chat_id,
'text' => $msg,
'parse_mode' => 'html'
);
$mode = 'post';
curl();
}
if($g_data[$s]['ch_option'] == 3){
$g_data[$s]['s_status'] = 0;
$wr = 1;
}
if($g_data[$s]['ch_option'] == 4){
$g_data[0]['g_status'] = 0;
$wr = 1;
}
if($wr == 1){
$g_id = $g_data[0]['g_id'];
$g_data_wr = serialize($g_data);
file_put_contents(__DIR__."/$folder_ini/$g_id.ini", $g_data_wr, LOCK_EX);
}
}
sleep($delay);
}
}
$s++;
}
}
}
if(check_time($cron_time_2) && !empty($tlg_bot_token) && !empty($tlg_chat_id)){
$free_space = round(disk_free_space(__DIR__) / 1024 / 1024);
if($free_space < $min_free_space){
$msg = "<b>Warning!</b>\nDrives are at risk of running out of free space.\nDisk space available: $free_space Mb";
$url = "https://api.telegram.org/bot$tlg_bot_token/sendMessage";
$request = array(
'chat_id' => $tlg_chat_id,
'text' => $msg,
'parse_mode' => 'html'
);
$mode = 'post';
curl();
}
}
if(check_time("01:$minutes") && $data_collection == 1){
if(file_exists(__DIR__.'/temp/geo.dat')){
$data = file(__DIR__.'/temp/geo.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if(!empty($data)){
$request = array();
$request['data'] = serialize($data);
$url = 'https://ztds.info/user/?q=report&m=geo';
$mode = 'post';
$response = curl();
if($http_code == 200 && $response == 'success'){
unlink(__DIR__.'/temp/geo.dat');
}
}
}
if(file_exists(__DIR__.'/temp/ua.dat')){
$data = file(__DIR__.'/temp/ua.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if(!empty($data)){
$request = array();
$request['data'] = serialize($data);
$url = 'https://ztds.info/user/?q=report&m=ua';
$mode = 'post';
$response = curl();
if($http_code == 200 && $response == 'success'){
unlink(__DIR__.'/temp/ua.dat');
}
}
}
}
function sort_ip($data){
$data = json_decode($data, true);
if(!empty($data['baidu'])){
$name = 'baidu';
save($name, $data['baidu']);
}
if(!empty($data['bing'])){
$name = 'bing';
save($name, $data['bing']);
}
if(!empty($data['facebook'])){
$name = 'facebook';
save($name, $data['facebook']);
}
if(!empty($data['google'])){
$name = 'google';
save($name, $data['google']);
}
if(!empty($data['mail'])){
$name = 'mail';
save($name, $data['mail']);
}
if(!empty($data['yahoo'])){
$name = 'yahoo';
save($name, $data['yahoo']);
}
if(!empty($data['yandex'])){
$name = 'yandex';
save($name, $data['yandex']);
}
if(!empty($data['others'])){
$name = 'others';
save($name, $data['others']);
}
}
function save($name, $data){
global $update_ip_mode;
if($update_ip_mode == 1){
$file = trim(file_get_contents(__DIR__."/database/$name.dat"));
$file = explode("\n", $file);
$data = array_merge($file, $data);
unset($file);
}
$data = array_unique($data);
$data = implode("\n", $data);
file_put_contents(__DIR__."/database/$name.dat", $data."\n", LOCK_EX);
unset($data);
}
function separator($str){
if(stristr($str, ',')){
$sep = ',';
}
else{
$sep = "\n";
}
return $sep;
}
function curl(){
global $url, $mode, $header, $request, $curl_ua, $http_code;
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $curl_ua);
if($mode == 'header'){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
if($mode == 'post'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
}
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $response;
}
function check_time($cron_time){
global $time;
if(!empty($cron_time)){
$cron_time = explode(',', $cron_time);
foreach($cron_time as $v){
if($time == trim($v)){
return true;
}
}
}
}
function minutes($md5){
$x = 0;
while(isset($md5[$x])){
if(is_numeric($md5[$x])){
$arr[] = $md5[$x];
}
$x++;
}
foreach($arr as $v){
if(!isset($n1) && $v < 6){
$n1 = $v;
}
elseif(isset($n1) && !isset($n2)){
$n2 = $v;
$minutes = "$n1$n2";
break;
}
}
if(empty($minutes) || strlen($minutes) < 2){
$minutes = '11';
}
return $minutes;
}
?>