Your IP : 216.73.217.78


Current Path : /home/seto/tdsbs.com/
Upload File :
Current File : /home/seto/tdsbs.com/cron.php

<?php
define("INDEX", "yes");
@set_time_limit(0);
@ini_set('memory_limit', '-1');
require_once __DIR__.'/config.php';
if(!file_exists(__DIR__.'/temp')){
	mkdir(__DIR__.'/temp', 0755);
}
$mode = '';
$header = '';
$request = '';
$time = date("H:i");
if($time == '00:00'){
	$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($cron_time_1)){
	$url = 'https://ztds.info/user/?q=update&m=1';
	$data = curl();
	if(!empty($data) && $http_code == 200){
		sort_ip($data);
	}
	if(!empty($update_bl)){
		$url = $update_bl;
		$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($cron_time_4)){
	$url = 'https://ztds.info/user/?q=update&m=2';
	$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_2) && 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){
				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 = 'vt';
						$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']));
						$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';
								}
							}
						}
					}
					if($status == 1){
						if($g_data[$s]['av_option'] == 0 && !empty($g_data[$s]['av_out'])){
							$sep = separator($g_data[$s]['av_out']);
							$av_out = explode($sep, $g_data[$s]['av_out']);
							if(!empty($av_out[0])){
								$out_new = trim($av_out[0]);
								$g_data[$s]['s_out'] = $out_new;
								unset($av_out[0]);
								$av_out = array_values($av_out);
								$av_out = implode($sep, $av_out);
								$g_data[$s]['av_out'] = $av_out;
								$wr = 1;
							}
						}
						if($g_data[$s]['av_option'] == 1 && !empty($g_data[$s]['av_out'])){
							$url = trim($g_data[$s]['av_out']);
							$mode = '';
							$out_new = htmlentities(trim(curl()));
							if(!empty($out_new)){
								$g_data[$s]['s_out'] = $out_new;
							}
							$wr = 1;
						}
						if($g_data[$s]['av_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 = 'tlg';
							curl();
						}
						if($g_data[$s]['av_option'] == 3){
							$g_data[$s]['s_status'] = 0;
							$wr = 1;
						}
						if($g_data[$s]['av_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."\n", LOCK_EX);
						}
					}
					sleep($delay);
				}
			}
			$s++;
		}
	}
}
if(check_time($cron_time_3) && !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 = 'tlg';
		curl();
	}
}
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 == 'vt'){
		curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	}
	if($mode == 'tlg'){
		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;
			}
		}
	}
}
?>