File: /var/www/www-root/data/www/beartz.com/t/index.php
<?php
header('Access-Control-Allow-Origin: *');
define("INDEX", "yes");
@ini_set('max_execution_time', $max_ex_time);
require_once 'config.php';
require_once 'files/remote.php';
if($disable_tds == 1){
exit();
}
$bot = $page = $cf_country = $country = $city = $region = $asn = $org = $os_title = $os_name = $os_version = $browser_title = $browser_name = $browser_version = $device = $brand = $utc_offset = $empty;
$s_ch_ua = $s_name = $postback = $key = $out = $api = '';
$s_api_mac_exe = 0;
if(!empty($folder_tds)){
$path = $_SERVER['HTTP_HOST'].'/'.$folder_tds;
}
else{
$path = $_SERVER['HTTP_HOST'];
}
if(!empty($_GET['pb']) && $_GET['pb'] == $key_postback){
if(empty($_GET['cid']) || empty($_GET['profit'])){
stop();
}
$get_cid = $_GET['cid'];
$profit = SQLite3::escapeString(floatval($_GET['profit']));
$get_cid = base64_decode($get_cid);
if(!strstr($get_cid, ';') || empty($profit) || !is_numeric($profit)){
stop();
}
$ex_cid = explode(';', $get_cid);
if(empty($ex_cid[0]) || empty($ex_cid[1])){
stop();
}
$id = $ex_cid[0];
$cid = $ex_cid[1];
if(!file_exists($folder_log.'/'.$id.'.db')){
stop();
}
$d1 = $d2 = $d3 = $empty;
if(!empty($_GET['1'])){
$d1 = trim($_GET['1']);
}
if(!empty($_GET['2'])){
$d2 = trim($_GET['2']);
}
if(!empty($_GET['3'])){
$d3 = trim($_GET['3']);
}
$db_pb = new SQLite3($folder_log.'/postback.db');
$db_pb->busyTimeout($timeout_1);
$db_pb->exec("PRAGMA journal_mode = WAL;");
$db_pb->querySingle("BEGIN IMMEDIATE;");
if(!$db_pb->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'postback';")){
$db_pb->querySingle("PRAGMA encoding = 'UTF-8'; PRAGMA journal_mode = WAL; CREATE TABLE 'postback' (id INTEGER PRIMARY KEY, date TEXT, time TEXT, domain TEXT, page TEXT, device TEXT, operator TEXT, country TEXT, city TEXT, asn TEXT, se TEXT, key TEXT, d1 TEXT, d2 TEXT, d3 TEXT, profit INTEGER, ngroup TEXT, nstream TEXT, cid TEXT, strtotime INTEGER);");
$db_pb->exec("CREATE INDEX 'pb_idx1' ON 'postback' (domain, ngroup, nstream, strtotime);");
$db_pb->exec("CREATE INDEX 'pb_idx2' ON 'postback' (cid);");
}
$db = new SQLite3($folder_log.'/'.$id.'.db');
$db->busyTimeout($timeout_1);
$db->exec("PRAGMA journal_mode = WAL;");
$db->querySingle("BEGIN IMMEDIATE;");
$res = $db->query("SELECT * FROM sqlite_master WHERE type = 'table' ORDER BY name DESC;");
$end = 0;
while(true){
if($array = $res->fetchArray(SQLITE3_ASSOC)){
$table = $array['name'];
$test_1 = $db->querySingle("SELECT id FROM '$table' WHERE cid = '$cid';");
if(!empty($test_1)){
$db->querySingle("UPDATE '$table' SET postback = '$profit' WHERE cid = '$cid';");
$test_2 = $db_pb->querySingle("SELECT id FROM 'postback' WHERE cid = '$cid';");
if(empty($test_2)){
$postback_data = $db->query("SELECT * FROM '$table' WHERE cid = '$cid';");
$date = date('Y-m-d', $table);
if($array = $postback_data->fetchArray(SQLITE3_ASSOC)){
$db_pb->querySingle("INSERT INTO 'postback' (date, time, domain, page, device, operator, country, city, asn, se, key, d1, d2, d3, profit, ngroup, nstream, cid, strtotime) VALUES ('".$date."', '".$array['time']."', '".SQLite3::escapeString($array['domain'])."', '".SQLite3::escapeString($array['page'])."', '".$array['device']."', '".$array['operator']."', '".SQLite3::escapeString($array['country'])."', '".SQLite3::escapeString($array['city'])."', '".SQLite3::escapeString($array['asn'])."', '".$array['se']."', '".SQLite3::escapeString($array['keyword'])."', '".SQLite3::escapeString($d1)."', '".SQLite3::escapeString($d2)."', '".SQLite3::escapeString($d3)."', '$profit', '".SQLite3::escapeString($array['ngroup'])."', '".SQLite3::escapeString($array['nstream'])."', '".$array['cid']."', '".$array['strtotime']."')");
if($tlg_postback == 1){
$group = $array['ngroup'];
$stream = $array['nstream'];
$country = $array['country'];
$city = $array['city'];
$domain = $array['domain'];
$device = $array['device'];
$se = $array['se'];
$key = $array['keyword'];
$msg = file_get_contents('database/postback.dat');
$msg = str_replace('[PROFIT]', $profit, $msg);
$msg = str_replace('[GROUP]', $group, $msg);
$msg = str_replace('[STREAM]', $stream, $msg);
$msg = str_replace('[COUNTRY]', $country, $msg);
$msg = str_replace('[CITY]', $city, $msg);
$msg = str_replace('[DOMAIN]', $domain, $msg);
$msg = str_replace('[DEVICE]', $device, $msg);
$msg = str_replace('[SE]', $se, $msg);
$msg = str_replace('[KEY]', $key, $msg);
$msg = str_replace('[D1]', $d1, $msg);
$msg = str_replace('[D2]', $d2, $msg);
$msg = str_replace('[D3]', $d3, $msg);
if(preg_match_all("~\[STRTOUPPER\](.+?)\[/STRTOUPPER\]~", $msg, $matches)){
foreach($matches[1] as $v){
$msg = preg_replace("~\[STRTOUPPER\]$v\[/STRTOUPPER\]~", mb_strtoupper($v), $msg, 1);
}
}
if(preg_match_all("~\[UCFIRST\](.+?)\[/UCFIRST\]~", $msg, $matches)){
foreach($matches[1] as $v){
$v2 = ucfirst($v);
$v1 = preg_quote($v);
$msg = preg_replace("~\[UCFIRST\]$v1\[/UCFIRST\]~", $v2, $msg, 1);
}
}
$msg = explode("\n", $msg);
$arr = array();
foreach($msg as $v){
$v = trim($v);
if($v != $empty && $v != 'unknown'){
$arr[] = $v;
}
}
$msg = implode("\n", $arr);
$request = array(
'chat_id' => $tlg_chat_id,
'text' => $msg,
'parse_mode' => 'html'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot$tlg_bot_token/sendMessage");
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);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch);
curl_close($ch);
}
if($data_collection == 1 && $array['asn'] != $empty){
file_put_contents('temp/geo.dat', $array['asn'].';'.$array['org'].';'.strtotime("now")."\n", FILE_APPEND | LOCK_EX);
}
}
}
else{
$db_pb->querySingle("UPDATE 'postback' SET profit = '$profit', d1 = '$d1', d2 = '$d2', d3 = '$d3' WHERE cid = '$cid';");
}
break;
}
}
else{
break;
}
}
$db->querySingle("COMMIT;");
$db_pb->querySingle("COMMIT;");
$db->close();
unset($db);
$db_pb->close();
unset($db_pb);
exit();
}
if(!empty($_POST['api']) || !empty($_GET['api'])){
if(!empty($_POST['api'])){
$api_data = @unserialize($_POST['api']);
}
if(!empty($_GET['api'])){
$api_data = @unserialize(base64_decode($_GET['api']));
}
if(!isset($api_data[0])){
exit();
}
$key_api_host = $api_data[0];
$ex = explode(',', $key_api);
if(in_array($key_api_host, $ex)){
$api = 1;
}
else{
exit();
}
$id = $api_data[1];
$ipuser = $api_data[2];
$referer = $api_data[3];
$useragent = $api_data[4];
$se = $api_data[5];
$lang = $api_data[6];
$uniq = $api_data[7];
$key = $api_data[8];
$domain = $api_data[9];
$page = $api_data[10];
$cf_country = $api_data[11];
$options = $api_data[12];
$counter = $empty;
if($uniq == 'yes' || $uniq == 1){
$uniq = 'yes';
}
else{
$uniq = 'no';
}
}
else{
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
if(strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ".") > 0 && strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0){
$ip = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
$ipuser = trim($ip[0]);
}
elseif(strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ".") > 0 && strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") === false){
$ipuser = trim($_SERVER['HTTP_X_FORWARDED_FOR']);
}
}
if(empty($ipuser)){
$ipuser = trim($_SERVER['REMOTE_ADDR']);
}
if(!filter_var($ipuser, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && !filter_var($ipuser, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
$ipuser = $empty;
}
if(!empty($_SERVER['HTTP_USER_AGENT'])){
$useragent = $_SERVER['HTTP_USER_AGENT'];
}
else{
$useragent = $empty;
}
if(!empty($_SERVER['HTTP_REFERER'])){
$referer = $_SERVER['HTTP_REFERER'];
}
else{
$referer = $empty;
}
if(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
else{
$lang = $empty;
}
$se = $empty;
}
$ip_stop_file = file('database/blacklist_ip.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if(search_in_database($ip_stop_file, $ipuser)){
exit();
}
$ua_stop_file = file('database/blacklist_ua.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($ua_stop_file as $v){
if($useragent == trim($v)){
exit();
}
}
if(empty($api)){
$in_url = $_SERVER['HTTP_HOST'].trim($_SERVER['REQUEST_URI']);
if(preg_match("~^$path\/([^/]*)(/)?$~", $in_url, $matches)){
$id = $matches[1];
}
if(preg_match("~^$path\/(.+?)\/(.+?)$~", $in_url, $matches)){
$id = $matches[1];
$key = $matches[2];
}
if(preg_match("~^$path\/(.+?)\?.+?=(.+?)?$~", $in_url, $matches)){
$id = $matches[1];
$options = $options_pack = $options_get = array();
foreach($_GET as $name => $value){
if($name == $name_get_ex){
$options_pack = base64_decode($value);
break;
}
else{
if($name == $name_get_key){
$key = trim(@urldecode($value));
}
else{
$options_get[] = array("name"=>$name, "value"=>trim(@urldecode($value)));
}
}
}
if(empty($options_pack) && !empty($options_get)){
$options = $options_get;
}
if(!empty($options_pack)){
$options_pack = @unserialize($options_pack);
foreach($options_pack as $name => $value){
if($name == 'key'){
if(!empty($value)){
$key = $value;
}
}
elseif($name == 'referer'){
if(!empty($value)){
$referer = $value;
}
else{
$referer = $empty;
}
}
else{
$options[] = array("name"=>$name, "value"=>trim(@urldecode($value)));
}
}
}
}
if(preg_match("~^http(s)?://(www\.)?(.+?)(/.*)?$~", $referer, $matches)){
$domain = $matches[3];
}
else{
$domain = 'unknown';
}
}
if(!empty($key)){
$key = urldecode($key);
if(substr($key, 0, 1) == '%'){
$key = urldecode($key);
}
if(utf8_bad_find($key) !== false){
$key = iconv('windows-1251', 'utf-8//IGNORE', $key);
}
}
if(!empty($id)){
if(file_exists("$folder_ini/$id.ini")){
$data_ini = @unserialize(file_get_contents("$folder_ini/$id.ini"));
}
else{
$x = 0;
$files = scandir("$folder_ini");
foreach($files as $v){
if($v != "." && $v != ".." && $v != ".htaccess" && preg_match("~^.+?\.ini$~", $v)){
$data_ini = @unserialize(file_get_contents("$folder_ini/$v"));
$aliases = explode(',', $data_ini[0]['g_aliases']);
if(in_array($id, $aliases)){
$id = $data_ini[0]['g_id'];
$x = 1;
break;
}
}
}
if($x == 0){
stop();
}
}
}
else{
/*
$trash_url = '';
header("Location: $trash_url");
exit();
*/
stop();
}
$g_name = $data_ini[0]['g_name'];
$g_mode = $data_ini[0]['g_mode'];
$g_status = $data_ini[0]['g_status'];
$g_uniq_method = $data_ini[0]['g_uniq_method'];
$g_uniq_time = $data_ini[0]['g_uniq_time'];
$g_firewall = $data_ini[0]['g_firewall'];
$g_f_queries = $data_ini[0]['g_f_queries'];
$g_f_time = $data_ini[0]['g_f_time'];
$g_save_keys = $data_ini[0]['g_save_keys'];
$g_save_keys_se = $data_ini[0]['g_save_keys_se'];
$g_geo = $data_ini[0]['g_geo'];
if($g_status == 0 || !isset($data_ini[1])){
stop();
}
if($g_mode == 'api' && empty($api)){
stop();
}
if($g_geo == 'cf' && !empty($api)){
$country = $cf_country;
}
use GeoIp2\Database\Reader;
if($ipuser != $empty && ($g_geo == 'geolite2' || ($g_geo == 'cf' && (empty($api) || $cf_country == $empty)))){
require_once "files/lib/geolite2/geoip2.phar";
try{
$reader = new Reader('files/lib/geolite2/GeoLite2-City.mmdb');
$record = '';
}
catch(\MaxMind\Db\Reader\InvalidDatabaseException $e){
$record = $empty;
}
if($record != $empty){
$reader = new Reader('files/lib/geolite2/GeoLite2-City.mmdb');
try{
$record = $reader->city($ipuser);
}
catch(\GeoIp2\Exception\AddressNotFoundException $e){
$record = $empty;
}
if(!empty($record->country->isoCode)){
$country = mb_strtolower($record->country->isoCode);
}
if(!empty($record->city->name)){
$city = mb_strtolower($record->city->name);
}
if(!empty($record->subdivisions[0]->isoCode)){
$region = mb_strtolower($country.'-'.$record->subdivisions[0]->isoCode);
}
if(!empty($record->location->timeZone)){
$tz_arr = timezone_identifiers_list();
$tz = $record->location->timeZone;
if($tz == 'Europe/Kyiv' && in_array('Europe/Kiev', $tz_arr)){
$tz = 'Europe/Kiev';
}
$date_current = new DateTime(null, new DateTimeZone($tz));
$seconds = $date_current->getOffset();
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$minutes = $minutes - ($hours * 60);
if($hours > 0){
$hours = '+'.$hours;
}
if($minutes != 0){
$minutes = ':'.$minutes;
}
else{
$minutes = '';
}
$utc_offset = $hours.$minutes;
}
}
try{
$reader = new Reader('files/lib/geolite2/GeoLite2-ASN.mmdb');
$record = '';
}
catch(\MaxMind\Db\Reader\InvalidDatabaseException $e){
$record = $empty;
}
if($record != $empty){
try{
$record = $reader->asn($ipuser);
}
catch(\GeoIp2\Exception\AddressNotFoundException $e){
$record = $empty;
}
if($record != $empty){
if(!empty($record->autonomousSystemNumber)){
$asn = mb_strtolower($record->autonomousSystemNumber);
$asn_stop_file = file('database/blacklist_asn.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($asn_stop_file as $v){
if($asn == trim($v)){
exit();
}
}
}
if(!empty($record->autonomousSystemOrganization)){
$org = mb_strtolower($record->autonomousSystemOrganization);
}
}
}
}
if($ipuser != $empty && $g_geo == 'sypex'){
require_once 'files/lib/sypex/SxGeo.php';
$SxGeo = new SxGeo('files/lib/sypex/SxGeo.dat');
$country = $SxGeo->getCountry($ipuser);
if(empty($country)){
$country = $empty;
}
else{
$country = mb_strtolower($country);
}
$SxGeo = new SxGeo('files/lib/sypex/SxGeoCity.dat');
$geodata = $SxGeo->getCityFull($ipuser);
if(empty($geodata["city"]["name_en"])){
$city = $empty;
}
else{
$city = mb_strtolower($geodata["city"]["name_en"]);
}
if(empty($geodata["region"]["iso"])){
$region = $empty;
}
else{
$region = mb_strtolower($geodata["region"]["iso"]);
}
}
require_once 'files/lib/MDetect.php';
if($useragent != $empty){
require_once('files/lib/BrowserDetection.php');
$detect = new foroco\BrowserDetection();
$detect = $detect->getAll($useragent);
if(!empty($detect['os_title']) && $detect['os_title'] != 'unknown'){
$os_title = mb_strtolower($detect['os_title']);
}
if(!empty($detect['os_name']) && $detect['os_name'] != 'unknown'){
$os_name = mb_strtolower($detect['os_name']);
}
if(!empty($detect['os_version']) && $detect['os_version'] != 'unknown'){
$os_version = mb_strtolower($detect['os_version']);
}
if(!empty($detect['browser_title']) && $detect['browser_title'] != 'unknown'){
$browser_title = mb_strtolower($detect['browser_title']);
}
if(!empty($detect['browser_name']) && $detect['browser_name'] != 'unknown'){
$browser_name = mb_strtolower($detect['browser_name']);
}
if(!empty($detect['browser_version']) && $detect['browser_version'] != 'unknown'){
$browser_version = mb_strtolower($detect['browser_version']);
}
}
$wap_file = unserialize(file_get_contents('database/wap.dat'));
$wap_data = array();
foreach($wap as $v){
$wap_data[] = '#'.$v;
if(!empty($wap_file[$v])){
foreach($wap_file[$v] as $x){
$wap_data[] = $x;
}
}
}
if(search_in_database($wap_data, $ipuser)){
$operator = $label;
}
if(empty($operator)){
$operator = $empty;
}
if(empty($api)){
$name_cookies = md5($_SERVER['HTTP_HOST'].'_'.$id);
$cookies_options = array('expires'=>time() + $g_uniq_time, 'path'=>'/', 'domain'=>'', 'secure'=>true, 'httponly'=>true, 'samesite'=>'None');
if(!isset($_COOKIE[$name_cookies])){
SetCookie($name_cookies, 0, $cookies_options);
$c_counter = 0;
if($g_uniq_method == 0){
$uniq = 'yes';
}
}
else{
$c_counter = $_COOKIE[$name_cookies] + 1;
SetCookie($name_cookies, $c_counter, $cookies_options);
$uniq = 'no';
}
}
$db = new SQLite3($folder_log.'/'.$id.'.db');
$db->busyTimeout($timeout_1);
$db->exec("PRAGMA journal_mode = WAL;");
$db->querySingle("BEGIN IMMEDIATE;");
if($g_uniq_method == 1){
$uniq = 'no';
$y = strtotime("- $g_uniq_time seconds");
$res = $db->query("SELECT * FROM sqlite_master WHERE type = 'table' ORDER BY name DESC;");
while(true){
if($array = $res->fetchArray(SQLITE3_ASSOC)){
$table = $array['name'];
$count = $db->querySingle("SELECT COUNT(id) FROM '$table';");
$z = $db->querySingle("SELECT strtotime FROM '$table' WHERE id = '$count';");
if($z < $y){
$uniq = 'yes';
break;
}
if($db->querySingle("SELECT strtotime FROM '$table' WHERE uniq = 'yes' AND ipuser = '$ipuser' AND strtotime > $y;")){
break;
}
}
else{
$uniq = 'yes';
break;
}
}
}
if($g_uniq_method == 2){
$uniq = 'no';
if(!empty($key)){
$y = strtotime("- $g_uniq_time seconds");
$res = $db->query("SELECT * FROM sqlite_master WHERE type = 'table' ORDER BY name DESC;");
while(true){
if($array = $res->fetchArray(SQLITE3_ASSOC)){
$table = $array['name'];
$count = $db->querySingle("SELECT COUNT(id) FROM '$table';");
$z = $db->querySingle("SELECT strtotime FROM '$table' WHERE id = '$count';");
if($z < $y){
$uniq = 'yes';
break;
}
if($db->querySingle("SELECT strtotime FROM '$table' WHERE uniq = 'yes' AND keyword = '$key' AND strtotime > $y;")){
break;
}
}
else{
$uniq = 'yes';
break;
}
}
}
}
if($g_firewall == 1){
$c = 0;
$y = strtotime("- $g_f_time seconds");
$res = $db->query("SELECT * FROM sqlite_master WHERE type = 'table' ORDER BY name DESC;");
$end = 0;
while(true){
if($array = $res->fetchArray(SQLITE3_ASSOC)){
$table = $array['name'];
$count = $db->querySingle("SELECT COUNT (*) FROM '$table';");
$z = $db->querySingle("SELECT strtotime FROM '$table' WHERE id = '$count';");
if($z > $y){
$c = $db->querySingle("SELECT COUNT (*) FROM '$table' WHERE ipuser = '$ipuser' AND strtotime > $y;");
}
if($c >= $g_f_queries){
exit();
}
}
else{
break;
}
}
}
$z = 0;
$x = 1;
while(true){
if(!empty($data_ini[$x])){
$z = 1;
if($data_ini[$x]['s_status'] != 1){
$z = 0;
}
if($z != 0){
if(date("w") == 0 && !empty($data_ini[$x]['sch_0'])){
schedule($data_ini[$x]['sch_0']);
}
if(date("w") == 1 && !empty($data_ini[$x]['sch_1'])){
schedule($data_ini[$x]['sch_1']);
}
if(date("w") == 2 && !empty($data_ini[$x]['sch_2'])){
schedule($data_ini[$x]['sch_2']);
}
if(date("w") == 3 && !empty($data_ini[$x]['sch_3'])){
schedule($data_ini[$x]['sch_3']);
}
if(date("w") == 4 && !empty($data_ini[$x]['sch_4'])){
schedule($data_ini[$x]['sch_4']);
}
if(date("w") == 5 && !empty($data_ini[$x]['sch_5'])){
schedule($data_ini[$x]['sch_5']);
}
if(date("w") == 6 && !empty($data_ini[$x]['sch_6'])){
schedule($data_ini[$x]['sch_6']);
}
}
if($z != 0){
$day_week = date('w');
$stream = $data_ini[$x]['s_name'];
if($data_ini[$x]['limit'] == 1){
if($data_ini[$x]['limit_type'] == 1){
$table = strtotime(date('Y-m-d'));
if($db->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '$table';")){
$c = $db->querySingle("SELECT COUNT (*) FROM '$table' WHERE nstream = '$stream';");
if($c >= $data_ini[$x]['limit_с']){
$z = 0;
}
}
}
if($data_ini[$x]['limit_type'] == 2){
$c = 0;
$limit_h = $data_ini[$x]['limit_h'];
$y = strtotime("- $limit_h seconds");
$res = $db->query("SELECT * FROM sqlite_master WHERE type = 'table' ORDER BY name DESC;");
while(true){
if($array = $res->fetchArray(SQLITE3_ASSOC)){
$table = $array['name'];
$count = $db->querySingle("SELECT COUNT (*) FROM '$table';");
$r = $db->querySingle("SELECT strtotime FROM '$table' WHERE id = '$count';");
if($r > $y){
$c = $db->querySingle("SELECT COUNT (*) FROM '$table' WHERE strtotime > $y AND nstream = '$stream';");
}
if($c >= $data_ini[$x]['limit_с']){
$z = 0;
break;
}
}
else{
break;
}
}
}
if($z == 0 && $data_ini[$x]['limit_disable'] == 1){
$data_ini[$x]['s_status'] = 0;
file_put_contents($folder_ini.'/'.$id.'.ini', serialize($data_ini), LOCK_EX);
}
}
}
if($z != 0 && $data_ini[$x]['brand_flag'] != 2 && !empty($data_ini[$x]['brand_text'])){
f1($data_ini[$x]['brand_text'], $brand, $data_ini[$x]['brand_flag']);
}
if($z != 0 && $data_ini[$x]['lang_flag'] != 2 && !empty($data_ini[$x]['lang_text'])){
f1($data_ini[$x]['lang_text'], $lang, $data_ini[$x]['lang_flag']);
}
if($z != 0 && $data_ini[$x]['country_flag'] != 2 && !empty($data_ini[$x]['country_text'])){
f1($data_ini[$x]['country_text'], $country, $data_ini[$x]['country_flag']);
}
if($z != 0 && $data_ini[$x]['city_flag'] != 2 && !empty($data_ini[$x]['city_text'])){
f1($data_ini[$x]['city_text'], $city, $data_ini[$x]['city_flag']);
}
if($z != 0 && $data_ini[$x]['region_flag'] != 2 && !empty($data_ini[$x]['region_text'])){
f1($data_ini[$x]['region_text'], $region, $data_ini[$x]['region_flag']);
}
if($z != 0 && $data_ini[$x]['asn_flag'] != 2 && !empty($data_ini[$x]['asn_text'])){
f1($data_ini[$x]['asn_text'], $asn, $data_ini[$x]['asn_flag']);
}
if($z != 0 && $data_ini[$x]['utc_flag'] != 2 && !empty($data_ini[$x]['utc_text'])){
f1($data_ini[$x]['utc_text'], $utc_offset, $data_ini[$x]['utc_flag']);
}
if($z != 0 && $data_ini[$x]['org_flag'] != 2 && !empty($data_ini[$x]['org_text'])){
f2($org, $data_ini[$x]['org_text'], $data_ini[$x]['org_flag']);
}
if($z != 0 && $data_ini[$x]['ua_flag'] != 2 && !empty($data_ini[$x]['ua_text'])){
f2($useragent, $data_ini[$x]['ua_text'], $data_ini[$x]['ua_flag']);
}
if($z != 0 && $data_ini[$x]['referer_flag'] != 2 && !empty($data_ini[$x]['referer_text'])){
f2($referer, $data_ini[$x]['referer_text'], $data_ini[$x]['referer_flag']);
}
if($z != 0 && $data_ini[$x]['domain_flag'] != 2 && !empty($data_ini[$x]['domain_text'])){
f2($domain, $data_ini[$x]['domain_text'], $data_ini[$x]['domain_flag']);
}
if($z != 0 && $data_ini[$x]['key_flag'] != 2 && !empty($data_ini[$x]['key_text'])){
upper_replace();
f2($key, $data_ini[$x]['key_text'], $data_ini[$x]['key_flag']);
}
if($z != 0 && $data_ini[$x]['os_flag'] != 2 && !empty($data_ini[$x]['os_text'])){
f3($data_ini[$x]['os_text'], $os_name, $os_version, $data_ini[$x]['os_flag']);
}
if($z != 0 && $data_ini[$x]['browser_flag'] != 2 && !empty($data_ini[$x]['browser_text'])){
f3($data_ini[$x]['browser_text'], $browser_name, $browser_version, $data_ini[$x]['browser_flag']);
}
if($z != 0 && $data_ini[$x]['computer'] != 2){
if($data_ini[$x]['computer'] == 0 && $device == 'computer'){
$z = 0;
}
}
if($z != 0 && $data_ini[$x]['phone'] != 2){
if($data_ini[$x]['phone'] == 0 && $device == 'phone'){
$z = 0;
}
}
if($z != 0 && $data_ini[$x]['tablet'] != 2){
if($data_ini[$x]['tablet'] == 0 && $device == 'tablet'){
$z = 0;
}
}
if($z != 0 && $data_ini[$x]['other_devices'] != 2){
if($data_ini[$x]['other_devices'] == 0 && $device == 'other'){
$z = 0;
}
}
if($z != 0){
foreach($wap as $v){
if(isset($data_ini[$x][$v]) && $data_ini[$x][$v] != 2){
if($data_ini[$x][$v] == 0 && $operator == $v){
$z = 0;
break;
}
}
}
foreach($wap as $v){
if(isset($data_ini[$x][$v]) && $data_ini[$x][$v] == 1 && $operator == $empty){
$z = 0;
break;
}
}
}
if($z != 0 && $data_ini[$x]['unique_user'] != 2){
if($data_ini[$x]['unique_user'] == 0 && $uniq != 'yes'){
$z = 0;
}
if($data_ini[$x]['unique_user'] == 1 && $uniq == 'yes'){
$z = 0;
}
}
if($z != 0 && $data_ini[$x]['ch_list_ip_flag'] != 2){
if(!empty($data_ini[$x]['list_ip_file'])){
$list_ip = file('database/'.$data_ini[$x]['list_ip_file']);
if($data_ini[$x]['ch_list_ip_flag'] == 0){
if(search_in_database($list_ip, $ipuser)){
$z = 0;
}
}
if($data_ini[$x]['ch_list_ip_flag'] == 1){
if(!search_in_database($list_ip, $ipuser)){
$z = 0;
}
}
}
}
if($z == 1){
$s_name = $data_ini[$x]['s_name'];
$s_redirect = $data_ini[$x]['redirect'];
$s_distribution_type = $data_ini[$x]['distribution_type'];
$s_out = $data_ini[$x]['s_out'];
$s_remote = $data_ini[$x]['remote'];
$s_remote_cache = $data_ini[$x]['remote_cache'];
$s_remote_regexp = $data_ini[$x]['remote_regexp'];
$s_remote_reserved_out = $data_ini[$x]['remote_reserved_out'];
$s_remote_url = $data_ini[$x]['remote_url'];
$s_separation = $data_ini[$x]['separation'];
$s_separation_file = $data_ini[$x]['separation_file'];
$s_curl = $data_ini[$x]['s_curl'];
$s_bot_curl = $data_ini[$x]['b_curl'];
$s_bot_redirect = $data_ini[$x]['bot_redirect'];
$s_out_bot = $data_ini[$x]['out_bot'];
$s_remote_ip_ch = $data_ini[$x]['remote_ip_ch'];
$s_remote_ip_ch_data = $data_ini[$x]['remote_ip_ch_data'];
$s_ch_ipv6 = $data_ini[$x]['ch_ipv6'];
$s_ch_bot_ip_baidu = $data_ini[$x]['ch_bot_ip_baidu'];
$s_ch_bot_ip_bing = $data_ini[$x]['ch_bot_ip_bing'];
$s_ch_bot_ip_google = $data_ini[$x]['ch_bot_ip_google'];
$s_ch_bot_ip_mail = $data_ini[$x]['ch_bot_ip_mail'];
$s_ch_bot_ip_yahoo = $data_ini[$x]['ch_bot_ip_yahoo'];
$s_ch_bot_ip_yandex = $data_ini[$x]['ch_bot_ip_yandex'];
$s_ch_bot_ip_others = $data_ini[$x]['ch_bot_ip_others'];
$s_ch_bot_ip_facebook = $data_ini[$x]['ch_bot_ip_facebook'];
$s_save_ip = $data_ini[$x]['save_ip'];
$s_ch_ua = $data_ini[$x]['ch_ua'];
$s_ch_ua_asn = $data_ini[$x]['ch_ua_asn'];
$s_ch_ua_ip = $data_ini[$x]['ch_ua_ip'];
$s_ch_empty_ua = $data_ini[$x]['ch_empty_ua'];
$s_ch_empty_ref = $data_ini[$x]['ch_empty_ref'];
$s_ch_empty_lang = $data_ini[$x]['ch_empty_lang'];
$s_ch_empty_key = $data_ini[$x]['ch_empty_key'];
$s_ch_asn_se = $data_ini[$x]['ch_asn_se'];
$s_ch_asn_sn = $data_ini[$x]['ch_asn_sn'];
$s_ch_asn_dc = $data_ini[$x]['ch_asn_dc'];
$s_ch_asn_others = $data_ini[$x]['ch_asn_others'];
$s_ch_ptr = $data_ini[$x]['ch_ptr'];
$s_chance = $data_ini[$x]['chance'];
$s_api_mac_exe = $data_ini[$x]['api_mac_exe'];
$s_api_mac = $data_ini[$x]['api_mac'];
$s_api_mac_prob = $data_ini[$x]['api_mac_prob'];
break;
}
$x++;
}
else{
$db->querySingle("COMMIT;");
$db->close();
unset($db);
stop();
}
}
if($g_geo == 'geolite2'){
if($s_ch_asn_se == 1){
$asn_file = file('database/asn_se.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$label = '';
foreach($asn_file as $v){
if(trim($v[0]) == '#'){
$label = trim(substr($v, 1)).'_';
}
if($v == $asn){
$bot = $label.'asn';
break;
}
}
}
if($bot == $empty && $s_ch_asn_sn == 1){
$asn_file = file('database/asn_sn.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$label = '';
foreach($asn_file as $v){
if(trim($v[0]) == '#'){
$label = trim(substr($v, 1)).'_';
}
if($v == $asn){
$bot = $label.'asn';
break;
}
}
}
if($bot == $empty && $s_ch_asn_dc == 1){
$asn_file = file('database/asn_dc.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$label = '';
foreach($asn_file as $v){
if(trim($v[0]) == '#'){
$label = trim(substr($v, 1)).'_';
}
if($v == $asn){
$bot = $label.'asn';
break;
}
}
}
if($bot == $empty && $s_ch_asn_others == 1){
$asn_file = file('database/asn_others.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$label = '';
foreach($asn_file as $v){
if(trim($v[0]) == '#'){
$label = trim(substr($v, 1)).'_';
}
if($v == $asn){
$bot = $label.'asn';
break;
}
}
}
}
if($bot == $empty && $s_ch_bot_ip_baidu == 1){
$bots_ip = file('database/baidu.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'baidu_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_bing == 1){
$bots_ip = file('database/bing.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'bing_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_google == 1){
$bots_ip = file('database/google.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'google_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_mail == 1){
$bots_ip = file('database/mail.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'mail_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_yahoo == 1){
$bots_ip = file('database/yahoo.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'yahoo_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_yandex == 1){
$bots_ip = file('database/yandex.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'yandex_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_others == 1){
$bots_ip = file('database/others.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'others_ip';
}
}
if($bot == $empty && $s_ch_bot_ip_facebook == 1){
$bots_ip = file('database/facebook.dat');
if(search_in_database($bots_ip, $ipuser)){
$bot = 'facebook_ip';
}
}
if($bot == $empty && $s_ch_ua == 1){
if(stristr($useragent, 'baidu.com') && ($g_geo != 'geolite2' || ($g_geo == 'geolite2' && $s_ch_ua_asn == 0)) && $s_ch_ua_ip == 0){$bot = 'baidu_ua';}
if(stristr($useragent, 'bing.com') || stristr($useragent, 'msnbot') && ($g_geo != 'geolite2' || ($g_geo == 'geolite2' && $s_ch_ua_asn == 0)) && $s_ch_ua_ip == 0){$bot = 'bing_ua';}
if(stristr($useragent, 'google.') && ($g_geo != 'geolite2' || ($g_geo == 'geolite2' && $s_ch_ua_asn == 0)) && $s_ch_ua_ip == 0){$bot = 'google_ua';}
if(stristr($useragent, 'mail.ru') && ($g_geo != 'geolite2' || ($g_geo == 'geolite2' && $s_ch_ua_asn == 0)) && $s_ch_ua_ip == 0){$bot = 'mail_ua';}
if(stristr($useragent, 'yahoo.com') && ($g_geo != 'geolite2' || ($g_geo == 'geolite2' && $s_ch_ua_asn == 0)) && $s_ch_ua_ip == 0){$bot = 'yahoo_ua';}
if(stristr($useragent, 'yandex.com/bots') && ($g_geo != 'geolite2' || ($g_geo == 'geolite2' && $s_ch_ua_asn == 0)) && $s_ch_ua_ip == 0){$bot = 'yandex_ua';}
if(stristr($useragent, 'facebook')){$bot = 'facebook';}
if($bot == $empty && $useragent != $empty){
$signature_ua = file('database/signature_ua.dat');
for($i = 0; $i<count($signature_ua); $i++){
$signature_ua_x = trim($signature_ua[$i]);
if(stristr($useragent, $signature_ua_x)){
$bot = 'sign_ua';
break;
}
}
}
if($bot == $empty && $referer != $empty){
$signature_ref = file('database/signature_ref.dat');
for($i = 0; $i<count($signature_ref); $i++){
$signature_ref_x = trim($signature_ref[$i]);
if(strstr($referer, $signature_ref_x)){
$bot = 'sign_ref';
break;
}
}
}
}
if($bot == $empty && $s_ch_ipv6 == 1 && filter_var($ipuser, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
$bot = 'ipv6';
}
if($bot == $empty && $s_ch_empty_ua == 1){
if($useragent == $empty || $useragent == ' '){
$bot = 'empty_ua';
}
}
if($bot == $empty && $s_ch_empty_ref == 1){
if($referer == $empty){
$bot = 'empty_ref';
}
}
if($bot == $empty && $s_ch_empty_lang == 1){
if($lang == $empty){
$bot = 'empty_lang';
}
}
if($bot == $empty && $s_ch_empty_key == 1){
if(empty($key)){
$bot = 'empty_key';
}
}
if($bot == $empty && $s_ch_ptr == 1 && $ipuser != $empty){
$ptr = gethostbyaddr($ipuser);
if(stristr($ptr, 'baidu')){$bot = 'baidu_ptr';}
if(stristr($ptr, 'bing') || stristr($ptr, 'msnbot')){$bot = 'bing_ptr';}
if(stristr($ptr, 'google') && !stristr($z_ptr_rec, 'googlefiber')){$bot = 'google_ptr';}
if(stristr($ptr, 'mail.ru')){$bot = 'mail_ptr';}
if(stristr($ptr, 'yahoo')){$bot = 'yahoo_ptr';}
if(stristr($ptr, 'yandex')){$bot = 'yandex_ptr';}
}
if($bot != $empty && $s_save_ip == 1){
$bot_name = '';
if(strstr($bot, 'baidu')){$bot_name = 'baidu';}
if(strstr($bot, 'bing')){$bot_name = 'bing';}
if(strstr($bot, 'google')){$bot_name = 'google';}
if(strstr($bot, 'mail')){$bot_name = 'mail';}
if(strstr($bot, 'yahoo')){$bot_name = 'yahoo';}
if(strstr($bot, 'yandex')){$bot_name = 'yandex';}
if(!empty($bot_name)){
$bots_ip_file = file('database/'.$bot_name.'.dat');
if(!search_in_database($bots_ip_file, $ipuser)){
file_put_contents('database/'.$bot_name.'.dat', $ipuser."\n", FILE_APPEND | LOCK_EX);
}
}
}
if($bot == $empty && $s_remote_ip_ch == 1){
remote_ip_ch(html_entity_decode($s_remote_ip_ch_data));
}
if($bot != $empty){
if($s_out_bot == 'ignore'){
$s_bot_redirect = 'ignore';
}
if($s_bot_redirect == 'api'){
$out = $s_out_bot;
$redirect = 'api';
out();
}
if($s_bot_redirect == 'javascript'){
$out = $s_out_bot;
$redirect = 'javascript';
out();
}
if($s_bot_redirect == 'iframe'){
$out = $s_out_bot;
$redirect = 'iframe';
out();
}
if($s_bot_redirect == 'http_redirect'){
$out = $s_out_bot;
$redirect = 'http_redirect';
out();
}
if($s_bot_redirect == 'show_text'){
$out = $s_out_bot;
$redirect = 'show_text';
out();
}
if($s_bot_redirect == 'curl'){
$out = $s_out_bot;
$redirect = 'curl';
$curl = $s_bot_curl;
out();
}
if($s_bot_redirect == '403_forbidden'){
$redirect = '403_forbidden';
$out = '';
out();
}
if($s_bot_redirect == '404_not_found'){
$redirect = '404_not_found';
$out = '';
out();
}
if($s_bot_redirect == '500_server_error'){
$redirect = '500_server_error';
$out = '';
out();
}
}
if($s_separation == 1 && !empty($key) && !empty($s_separation_file)){
if($bot == $empty || $s_bot_redirect == 'ignore'){
s_separation();
}
}
if($s_remote == 1 && !empty($s_out) && strstr($s_out, '[REMOTE]')){
$s_remote_url = html_entity_decode($s_remote_url, ENT_QUOTES, 'UTF-8');
if($s_remote_cache != 0){
$st_now = strtotime("now");
$st = strtotime("- $s_remote_cache seconds");
temp();
if(!file_exists('temp/remote_'.$g_name.'_'.$s_name)){
remote_pars();
}
else{
$file = file('temp/remote_'.$g_name.'_'.$s_name);
$dat = explode(';', $file[0]);
if($dat[0] > $st){
$s_out = str_replace('[REMOTE]', $dat[1], $s_out);
}
else{
remote_pars();
}
}
}
else{
if(strstr($s_remote_url, '[IP]')){
$s_remote_url = str_replace('[IP]', $ipuser, $s_remote_url);
}
if(strstr($s_remote_url, '[COUNTRY]')){
$s_remote_url = str_replace('[COUNTRY]', $country, $s_remote_url);
}
if(strstr($s_remote_url, '[CITY]')){
$s_remote_url = str_replace('[CITY]', $city, $s_remote_url);
}
if(strstr($s_remote_url, '[LANG]')){
$s_remote_url = str_replace('[LANG]', $lang, $s_remote_url);
}
if(strstr($s_remote_url, '[KEY]')){
$s_remote_url = str_replace('[KEY]', $key, $s_remote_url);
}
remote_pars();
}
}
if(!empty($s_out) && strstr($s_out, '|||')){
$out_ex = explode("|||", $s_out);
if($s_distribution_type == 'rotator'){
if(empty($api)){
if(isset($out_ex[$c_counter])){
$out = trim($out_ex[$c_counter]);
$counter = $c_counter;
}
else{
$out = trim($out_ex[0]);
$counter = 0;
SetCookie($name_cookies, 0, $cookies_options);
}
}
else{
$out = $s_out;
}
}
if($s_distribution_type == 'evenly'){
$table = strtotime(date('Y-m-d'));
if($db->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '$table';")){
$c = $db->querySingle("SELECT counter FROM '$table' WHERE nstream = '$s_name' ORDER BY id DESC;");
if(is_numeric($c)){
$c++;
}
else{
$c = 0;
}
$counter = $c;
if(empty($out_ex[$c])){
$out = trim($out_ex[0]);
$counter = 0;
}
else{
$out = trim($out_ex[$c]);
}
}
else{
$out = trim($out_ex[0]);
$counter = 0;
}
}
if($s_distribution_type == 'random'){
$rand = mt_rand(0, count($out_ex)-1);
$counter = $rand;
$out = trim($out_ex[$rand]);
}
}
else{
if(!empty($s_out)){
$out = $s_out;
}
}
$redirect = $s_redirect;
$curl = $s_curl;
out();
exit();
function out(){
global $redirect, $out, $key, $lang, $country, $city, $region, $asn, $org, $device, $brand, $operator, $os_name, $os_version, $browser_name, $browser_version, $bot, $uniq, $se, $path, $s_chance, $g_save_keys_se, $options, $key_se, $ipuser, $key_api, $key_api_host, $domain, $useragent, $id, $cid, $curl_cache, $s_name, $g_name, $s_api_mac_exe, $s_api_mac, $s_api_mac_prob, $s_redirect, $empty;
$mac_output = '';
if($s_redirect == 'api' && $s_api_mac_exe == 1 && !empty($s_api_mac) && $s_api_mac_prob > mt_rand(1, 100)){
$mac_input = $s_api_mac;
}
else{
$mac_input = '';
}
$out = trim(html_entity_decode($out, ENT_QUOTES, 'UTF-8'));
if(strstr($out, '[PATH]')){
$out = str_replace('[PATH]', $path, $out);
}
if(strstr($out, '[HOST]')){
$out = str_replace('[HOST]', $_SERVER['HTTP_HOST'], $out);
}
if($redirect == 'javascript'){
if(empty($s_chance)){$s_chance = 100;}
$rand = mt_rand(1, 100);
if($s_chance < $rand){
$out = '';
}
}
if(strstr($out, '[KEY]')){
logs();
save_keys();
$key = urlencode($key);
$out = str_replace('[KEY]', $key, $out);
}
else{
logs();
save_keys();
}
if($g_save_keys_se == 1){
keys_se();
save_keys_se();
}
if(!empty($options)){
foreach($options as $v){
$name = $v['name'];
$value = $v['value'];
if(stristr($out, '['.$name.']')){
$out = str_ireplace('['.$name.']', $value, $out);
}
}
}
if(strstr($out, '[IP]')){
$out = str_replace('[IP]', $ipuser, $out);
}
if(strstr($out, '[COUNTRY]')){
$out = str_replace('[COUNTRY]', $country, $out);
}
if(strstr($out, '[CITY]')){
$out = str_replace('[CITY]', $city, $out);
}
if(strstr($out, '[LANG]')){
$out = str_replace('[LANG]', $lang, $out);
}
if(strstr($out, '[KEY_SE]')){
keys_se();
$key_se = urlencode($key_se);
$out = str_replace('[KEY_SE]', $key_se, $out);
}
if(strstr($out, '[DOMAIN]')){
$out = str_replace('[DOMAIN]', $domain, $out);
}
if(strstr($out, '[USERAGENT]')){
$out = str_replace('[USERAGENT]', $useragent, $out);
}
if(strstr($out, '[REGION]')){
$out = str_replace('[REGION]', $region, $out);
}
if(strstr($out, '[DEVICE]')){
$out = str_replace('[DEVICE]', $device, $out);
}
if(strstr($out, '[BRAND]')){
$out = str_replace('[BRAND]', $brand, $out);
}
if(strstr($out, '[SE]')){
$out = str_replace('[SE]', $se, $out);
}
if(strstr($out, '[ASN]')){
$out = str_replace('[ASN]', $asn, $out);
}
if(strstr($out, '[CID]')){
$out = str_replace('[CID]', base64_encode($id.';'.$cid), $out);
}
if(strstr($out, 'CITY') && preg_match("~\[\((.+?)?\)CITY\((.+?)?\)\]~", $out, $matches)){
$prefix = $matches[1];
$suffix = $matches[2];
$l = 0;
$file_city = file('database/city.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($file_city as $v){
$v = mb_strtolower(trim($v));
if(strstr($v, ';')){
$ex = explode(";", $v);
$f = trim($ex[0]);
$r = trim($ex[1]);
if($f == $city && !empty($r)){
$r = str_replace(' ', '-', $r);
$out = preg_replace("~\[\((.+?)?\)CITY\((.+?)?\)\]~", $prefix.$r.$suffix, $out, 1);
$l = 1;
break;
}
}
elseif($city == $v){
$r = str_replace(' ', '-', $v);
$out = preg_replace("~\[\((.+?)?\)CITY\((.+?)?\)\]~", $prefix.$r.$suffix, $out, 1);
$l = 1;
break;
}
}
if($l == 0){
$out = preg_replace("~\[\((.+?)?\)CITY\((.+?)?\)\]~", '', $out, 1);
}
}
if(strstr($out, 'COUNTRY') && preg_match("~\[\((.+?)?\)COUNTRY\((.+?)?\)\]~", $out, $matches)){
$prefix = $matches[1];
$suffix = $matches[2];
$l = 0;
$file_country = file('database/country.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($file_country as $v){
$v = mb_strtolower(trim($v));
if(strstr($v, ';')){
$ex = explode(";", $v);
$f = trim($ex[0]);
$r = trim($ex[1]);
if($f == $country && !empty($r)){
$out = preg_replace("~\[\((.+?)?\)COUNTRY\((.+?)?\)\]~", $prefix.$r.$suffix, $out, 1);
$l = 1;
break;
}
}
elseif($country == $v){
$out = preg_replace("~\[\((.+?)?\)COUNTRY\((.+?)?\)\]~", $prefix.$v.$suffix, $out, 1);
$l = 1;
break;
}
}
if($l == 0){
$out = preg_replace("~\[\((.+?)?\)COUNTRY\((.+?)?\)\]~", '', $out, 1);
}
}
if(strstr($out, 'RANDNUM')){
$out = randnum($out);
}
if(strstr($out, 'RANDSTR')){
$out = randstr($out);
}
if(strstr($out, 'RANDLINE')){
$out = randline($out);
}
if(strstr($out, 'RANDDFL')){
$out = randdfl($out);
}
if(!empty($mac_input)){
if(strstr($mac_input, 'RANDNUM')){
$mac_input = randnum($mac_input);
}
if(strstr($mac_input, 'RANDSTR')){
$mac_input = randstr($mac_input);
}
if(strstr($mac_input, 'RANDLINE')){
$mac_input = randline($mac_input);
}
if(strstr($mac_input, 'RANDDFL')){
$mac_input = randdfl($mac_input);
}
$mac_output = $mac_input;
}
if($redirect == 'api'){
header("Content-Type: application/json; charset=UTF-8");
$array = array();
$array[0] = $out;
$array[1] = $country;
$array[2] = $region;
$array[3] = $city;
$array[4] = $asn;
$array[5] = $org;
$array[6] = $device;
$array[7] = $operator;
$array[8] = $bot;
$array[9] = $uniq;
$array[10] = $lang;
$array[11] = $mac_output;
$array[12] = $os_name;
$array[13] = $os_version;
$array[14] = $browser_name;
$array[15] = $browser_version;
$array[16] = $brand;
$api_data = serialize($array);
echo $api_data;
exit();
}
if($redirect == 'show_text'){
header("Content-Type: text/html; charset=UTF-8");
echo $out;
exit();
}
if($redirect == 'curl'){
header("Content-Type: text/html; charset=UTF-8");
temp();
$file_name = 'curl_'.$g_name.'_'.$s_name;
if($curl_cache != 0){
$st_now = strtotime("now");
$st = strtotime("- $curl_cache minutes");
if(!file_exists("temp/$file_name")){
curl($out, $key, $file_name);
}
else{
$data = file("temp/$file_name");
if($data[0] > $st){
unset($data[0]);
$data = implode('', $data);
echo $data;
exit();
}
else{
curl($out, $key, $file_name);
}
}
}
else{
curl($out, $key, $file_name);
}
}
if($redirect == 'http_redirect'){
header("Location: $out");
exit();
}
if($redirect == 'iframe'){
header("Content-Type: application/javascript; charset=UTF-8");
if(empty($out)){
echo '';
}
else{
echo 'var splashpage = {
splashenabled: 1,
splashpageurl: "'.$out.'",
enablefrequency: 0,
displayfrequency: "2 days",
cookiename: ["splashpagecookie", "path=/"],
autohidetimer: 0,
launch: false,
browserdetectstr:(window.opera && window.getSelection) || (!window.opera && window.XMLHttpRequest),
output: function(){
document.write(\'<style>body {overflow: hidden;}</style>\');
document.write(\'<div id="slashpage" style="position: absolute; z-index: 10000; color: white; background-color:white">\');
document.write(\'<iframe name="splashpage-iframe" src="about:blank" style="margin:0; border:0; padding:0; width:100%; height: 100%"></iframe>\');
document.write(\'<br /> </div>\');
this.splashpageref = document.getElementById("slashpage");
this.splashiframeref = window.frames["splashpage-iframe"];
this.splashiframeref.location.replace(this.splashpageurl);
this.standardbody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body;
if(!/safari/i.test(navigator.userAgent)) this.standardbody.style.overflow = "hidden";
this.splashpageref.style.left = 0;
this.splashpageref.style.top = 0;
this.splashpageref.style.width = "100%";
this.splashpageref.style.height = "100%";
this.moveuptimer = setInterval("window.scrollTo(0,0)", 50);
},
closeit: function(){
clearInterval(this.moveuptimer);
this.splashpageref.style.display = "none";
this.splashiframeref.location.replace("about:blank");
this.standardbody.style.overflow = "auto";
},
init: function(){
if(this.enablefrequency == 1){
if(/sessiononly/i.test(this.displayfrequency)){
if(this.getCookie(this.cookiename[0] + "_s") == null){
this.setCookie(this.cookiename[0] + "_s", "loaded");
this.launch = true;
}
}
else if(/day/i.test(this.displayfrequency)){
if(this.getCookie(this.cookiename[0]) == null || parseInt(this.getCookie(this.cookiename[0])) != parseInt(this.displayfrequency)){
this.setCookie(this.cookiename[0], parseInt(this.displayfrequency), parseInt(this.displayfrequency));
this.launch = true;
}
}
} else this.launch = true; if(this.launch){
this.output();
if(parseInt(this.autohidetimer) > 0) setTimeout("splashpage.closeit()", parseInt(this.autohidetimer) * 1000);
}
},
getCookie: function(Name){
var re = new RegExp(Name + "=[^;]+", "i");
if(document.cookie.match(re)) return document.cookie.match(re)[0].split("=")[1];
return null;
},
setCookie: function(name, value, days){
var expireDate = new Date();
if(typeof days != "undefined"){
var expstring = expireDate.setDate(expireDate.getDate() + parseInt(days));
document.cookie = name + "=" + value + "; expires=" + expireDate.toGMTString() + "; " + splashpage.cookiename[1];
} else document.cookie = name + "=" + value + "; " + splashpage.cookiename[1];
}
};
if(splashpage.browserdetectstr && splashpage.splashenabled == 1) splashpage.init();';
}
exit();
}
if($redirect == 'javascript'){
header("Content-Type: application/javascript; charset=UTF-8");
echo $out;
exit();
}
if($redirect == '403_forbidden'){
header('HTTP/1.0 403 Forbidden', true, 403);
exit();
}
if($redirect == '404_not_found'){
header('HTTP/1.0 404 Not Found', true, 404);
exit();
}
if($redirect == '500_server_error'){
header('HTTP/1.0 500 Internal Server Error', true, 500);
exit();
}
}
function search_in_database($net, $ip){
global $label;
$label = '';
$ip = trim($ip);
for($i = 0; $i<count($net); $i++){
if(trim($net[$i][0]) == '#'){
$label = trim(substr($net[$i], 1));
}
if(trim($net[$i]) != false && trim($net[$i][0]) != '#'){
$net[$i] = trim($net[$i]);
if($ip == $net[$i]){
return true;
}
}
if(trim($net[$i]) != false && trim($net[$i][0]) != '#' && strstr($net[$i], '/')){
$net_ex = explode('/', $net[$i]);
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && filter_var($net_ex[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){
$range_start = ip2long($net_ex[0]);
$range_end = $range_start + pow(2, 32-intval($net_ex[1])) - 1;
$ip_long = ip2long($ip);
if($ip_long >=$range_start && $ip_long <= $range_end){
return true;
}
}
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && filter_var($net_ex[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
$ip_bin = inet_pton($ip);
list($first_addr_str, $prefix_len) = $net_ex;
$first_addr_bin = inet_pton($first_addr_str);
$first_addr_hex = unpack('H*', $first_addr_bin);
$first_addr_hex = reset($first_addr_hex);
$flex_bits = 128 - $prefix_len;
$last_addr_hex = $first_addr_hex;
$n_pos = 31;
while($flex_bits > 0){
$orig = substr($last_addr_hex, $n_pos, 1);
$orig_val = hexdec($orig);
$new_val = $orig_val | (pow(2, min(4, $flex_bits)) - 1);
$new = dechex($new_val);
$last_addr_hex = substr_replace($last_addr_hex, $new, $n_pos, 1);
$flex_bits -= 4;
$n_pos -= 1;
}
$last_addr_bin = pack('H*', $last_addr_hex);
if($ip_bin >= $first_addr_bin && $ip_bin <= $last_addr_bin){
return true;
}
}
}
if(trim($net[$i]) != false && trim($net[$i][0]) != '#' && strstr($net[$i], '-')){
$net_ex = explode('-', $net[$i]);
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && filter_var(trim($net_ex[0]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){
if(ip2long($ip) >= ip2long(trim($net_ex[0])) && ip2long($ip) <= ip2long(trim($net_ex[1]))){
return true;
}
}
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && filter_var(trim($net_ex[0]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
$ip_bin = inet_pton($ip);
$first_addr_bin = inet_pton(trim($net_ex[0]));
$last_addr_bin = inet_pton(trim($net_ex[1]));
if($ip_bin >= $first_addr_bin && $ip_bin <= $last_addr_bin){
return true;
}
}
}
}
$label = '';
}
function logs(){
global $id, $g_name, $s_name, $folder_log, $out, $key, $redirect, $device, $brand, $operator, $country, $city, $region, $asn, $org, $utc_offset, $os_title, $browser_title, $lang, $uniq, $bot, $ipuser, $referer, $useragent, $domain, $page, $se, $period_log, $db, $empty, $log_bots, $log_out, $save_log, $counter, $timeout_1, $postback, $cid, $index_mode;
if($save_log['bots'] != 1 && $bot != $empty){
return;
}
$time = date("H:i:s");
$strtotime = strtotime("now");
$table = strtotime(date('Y-m-d'));
if(!$db->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '$table';")){
$db->querySingle("PRAGMA encoding = 'UTF-8'; PRAGMA journal_mode = WAL; CREATE TABLE '$table' (id INTEGER PRIMARY KEY, time TEXT, ngroup TEXT, nstream TEXT, out TEXT, keyword TEXT, redirect TEXT, device TEXT, brand TEXT, operator TEXT, country TEXT, city TEXT, region TEXT, asn INTEGER, org TEXT, utc TEXT, os TEXT, browser TEXT, lang TEXT, uniq TEXT, bot TEXT, ipuser TEXT, referer TEXT, useragent TEXT, domain TEXT, page TEXT, se TEXT, strtotime INTEGER, counter TEXT, cid TEXT, postback INTEGER);");
if($index_mode == 1 || $index_mode == 2){
$db->exec("CREATE INDEX '$table"."_uniq' ON '$table' (ipuser,uniq,strtotime);");
$db->exec("CREATE INDEX '$table"."_limit' ON '$table' (nstream,strtotime);");
}
if($index_mode == 2){
$db->exec("CREATE INDEX '$table"."_country' ON '$table' (country,nstream,bot,domain,se,uniq);");
$db->exec("CREATE INDEX '$table"."_sources' ON '$table' (domain,nstream,bot,device,operator,se,uniq,strtotime);");
$db->exec("CREATE INDEX '$table"."_group' ON '$table' (uniq,bot,se,nstream,device,operator,strtotime);");
}
}
$g_name_wr = SQLite3::escapeString($g_name);
$s_name_wr = SQLite3::escapeString($s_name);
$out_wr = SQLite3::escapeString(htmlentities($out, ENT_QUOTES, 'UTF-8'));
$key_wr = SQLite3::escapeString($key);
$city_wr = SQLite3::escapeString($city);
$region_wr = SQLite3::escapeString($region);
$asn_wr = SQLite3::escapeString($asn);
$org_wr = SQLite3::escapeString($org);
$utc_offset_wr = SQLite3::escapeString($utc_offset);
$os_wr = SQLite3::escapeString($os_title);
$browser_wr = SQLite3::escapeString($browser_title);
$lang_wr = SQLite3::escapeString($lang);
$ipuser_wr = SQLite3::escapeString($ipuser);
$referer_wr = SQLite3::escapeString($referer);
$useragent_wr = SQLite3::escapeString($useragent);
$domain_wr = SQLite3::escapeString($domain);
$page_wr = SQLite3::escapeString($page);
$operator_wr = $operator;
$postback_wr = $postback;
$cid = substr(md5(microtime(1)), 0, 10);
if(empty($s_name_wr)){$s_name_wr = $empty;}
if(empty($key_wr)){$key_wr = $empty;}
if(empty($out_wr)){$out_wr = $empty;}
if(empty($postback_wr)){$postback_wr = $empty;}
if(!empty($save_log['out'])){
if(!in_array($redirect, explode(',', $save_log['out']))){
$out_wr = $empty;
}
}
else{
$out_wr = $empty;
}
if($save_log['referer'] != 1){
$referer_wr = $empty;
}
if($save_log['useragent'] != 1){
$useragent_wr = $empty;
}
if($save_log['page'] != 1){
$page_wr = $empty;
}
if($save_log['key'] != 1){
$key_wr = $empty;
}
if($save_log['brand'] != 1){
$brand_wr = $empty;
}
if($save_log['os'] != 1){
$os_wr = $empty;
}
if($save_log['browser'] != 1){
$browser_wr = $empty;
}
if($save_log['region'] != 1){
$region_wr = $empty;
}
if($save_log['org'] != 1){
$org_wr = $empty;
}
if($save_log['utc'] != 1){
$utc_wr = $empty;
}
$db->querySingle("INSERT INTO '$table' (time, ngroup, nstream, out, keyword, redirect, device, brand, operator, country, city, region, asn, org, utc, os, browser, lang, uniq, bot, ipuser, referer, useragent, domain, page, se, strtotime, counter, cid, postback) VALUES ('$time', '$g_name_wr', '$s_name_wr', '$out_wr', '$key_wr', '$redirect', '$device', '$brand', '$operator', '$country', '$city_wr', '$region_wr', '$asn_wr', '$org_wr', '$utc_offset', '$os_wr', '$browser_wr', '$lang_wr', '$uniq', '$bot', '$ipuser_wr', '$referer_wr', '$useragent_wr', '$domain_wr', '$page_wr', '$se', '$strtotime', '$counter', '$cid', '$postback_wr')");
$db->querySingle("COMMIT;");
$db->close();
unset($db);
}
function utf8_bad_find($str){
$utf8_bad =
'([\x00-\x7F]'.
'|[\xC2-\xDF][\x80-\xBF]'.
'|\xE0[\xA0-\xBF][\x80-\xBF]'.
'|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'.
'|\xED[\x80-\x9F][\x80-\xBF]'.
'|\xF0[\x90-\xBF][\x80-\xBF]{2}'.
'|[\xF1-\xF3][\x80-\xBF]{3}'.
'|\xF4[\x80-\x8F][\x80-\xBF]{2}'.
'|(.{1}))';
$pos = 0;
while(preg_match('/'.$utf8_bad.'/S', $str, $matches)){
$bytes = strlen($matches[0]);
if(isset($matches[2]))
return $pos;
$pos += $bytes;
$str = substr($str, $bytes);
}
return false;
}
function stop(){
header("Content-Type: text/html; charset=UTF-8");
exit();
}
function sep_str(){
global $sep_str, $sep_data;
$sep_str = trim(array_shift($sep_data));
if(!empty($sep_str)){
implode("\n", $sep_data);
}
else{
$sep_str = 'end';
}
}
function s_separation(){
global $s_out, $s_separation_file, $key, $sep_data, $sep_str;
upper_replace();
$sep_data = file_get_contents('database/'.$s_separation_file);
$sep_data = explode("\n", $sep_data);
while($sep_str != 'end'){
sep_str();
if($sep_str != 'end'){
$x = explode(";", $sep_str);
$sep_name = $x[0];
if(stristr($key, $sep_name)){
$s_out = $x[1];
break;
}
}
}
}
function save_keys(){
global $g_save_keys, $bot, $key, $folder_keys, $g_name, $empty;
if($g_save_keys == 1 && $bot == $empty && !empty($key)){
$date = date("Y-m-d");
if(!file_exists($folder_keys)){
mkdir($folder_keys, 0755);
}
if(!file_exists($folder_keys.'/'.$g_name)){
mkdir($folder_keys.'/'.$g_name, 0755);
file_put_contents($folder_keys.'/'.$g_name.'/'.'.htaccess', "<Files *.dat>\nDeny from all\n</Files>", LOCK_EX);
}
file_put_contents($folder_keys.'/'.$g_name.'/'.$date.'.dat', $key."\n", FILE_APPEND | LOCK_EX);
}
}
function keys_se(){
global $bot, $referer, $empty, $key_se;
if($bot == $empty && !empty($referer)){
$key_se = '';
if(strstr($referer, 'google') || strstr($referer, 'yandex') || strstr($referer, 'mail.ru') || strstr($referer, 'rambler.ru') || strstr($referer, 'tut.by') || strstr($referer, 'nigma.ru')){
$query = '';
if(strstr($referer, 'google') && !strstr($referer, '&q=&') && !strstr($referer, '?q=&')){$query = 'q';}
if(strstr($referer, 'mail.ru') && !strstr($referer, '&q=&') && !strstr($referer, '?q=&')){$query = 'q';}
if(strstr($referer, 'rambler.ru') && !strstr($referer, '&query=&') && !strstr($referer, '?query=&')){$query = 'query';}
if(strstr($referer, 'tut.by') && !strstr($referer, '&query=&') && !strstr($referer, '?query=&')){$query = 'query';}
if(strstr($referer, 'yandex') && !strstr($referer, '&text=&') && !strstr($referer, '?text=&')){$query = 'text';}
if(strstr($referer, 'nigma.ru') && !strstr($referer, '&s=&') && !strstr($referer, '?s=&')){$query = 's';}
if(preg_match("~^.*[?&]$query=(.+?)&.*$~", $referer, $matches)){
$key_se = trim(urldecode($matches[1]));
}
else{
if(preg_match("~^.*[?&]$query=(.*)$~", $referer, $matches)){
$key_se = trim(urldecode($matches[1]));
}
}
if(!empty($key_se)){
if(utf8_bad_find($key_se) !== false){
$key_se = iconv('windows-1251', 'utf-8//IGNORE', $key_se);
}
}
}
}
}
function save_keys_se(){
global $bot, $folder_keys, $g_name, $empty, $key_se;
if($bot == $empty && !empty($key_se)){
$date = date("Y-m-d");
if(!file_exists($folder_keys)){
mkdir($folder_keys, 0755);
}
if(!file_exists($folder_keys.'/'.$g_name)){
mkdir($folder_keys.'/'.$g_name, 0755);
file_put_contents($folder_keys.'/'.$g_name.'/'.'.htaccess', "<Files *.dat>\nDeny from all\n</Files>", LOCK_EX);
}
file_put_contents($folder_keys.'/'.$g_name.'/'.$date.'-se.dat', $key_se."\n", FILE_APPEND | LOCK_EX);
}
}
function upper_replace(){
global $key;
$key_array = array($key);
$search = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я');
$replace = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я');
$res = str_ireplace($search, $replace, $key_array);
$key = $res[0];
}
function remote_pars(){
global $s_out, $s_remote_url, $s_remote_regexp, $s_remote_reserved_out, $s_remote_cache, $st_now, $g_name, $s_name;
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL, $s_remote_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$pars = trim(curl_exec($ch));
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200){
if(!empty($s_remote_regexp) && substr($s_remote_regexp, 0, 1) == '/'){
$s_remote_regexp = trim(html_entity_decode($s_remote_regexp, ENT_QUOTES, 'UTF-8'));
if(preg_match($s_remote_regexp, $pars, $matches)){
if(!empty($matches[1])){
$pars_res = $matches[1];
}
}
else{
$pars_res = '';
}
}
else{
$pars_res = $pars;
}
if(empty($pars_res)){
$pars_res = $s_remote_reserved_out;
}
if($s_remote_cache != 0){
$dat = $st_now.';'.$pars_res;
file_put_contents('temp/remote_'.$g_name.'_'.$s_name, $dat, LOCK_EX);
}
$s_out = str_replace('[REMOTE]', $pars_res, $s_out);
}
else{
$s_out = $s_remote_reserved_out;
if($s_remote_cache != 0){
$dat = $st_now.';'.$s_out;
file_put_contents('temp/remote_'.$g_name.'_'.$s_name, $dat, LOCK_EX);
}
}
curl_close($ch);
}
function curl($out, $key, $file_name){
global $curl_ua, $curl, $curl_cache;
$ch = curl_init($out);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $curl_ua);
$data = curl_exec($ch);
curl_close($ch);
if(utf8_bad_find($data) !== false){
$data = iconv('windows-1251', 'utf-8//IGNORE', $data);
}
$curl_ex = explode("\n", $curl);
foreach($curl_ex as $v){
if(strstr($v, '|||')){
$str = explode("|||", $v);
$find = trim(html_entity_decode($str[0], ENT_QUOTES, 'UTF-8'));
$replace = trim(html_entity_decode($str[1], ENT_QUOTES, 'UTF-8'));
if(strstr($replace, '[KEY]')){
$replace = str_replace('[KEY]', $key, $replace);
}
$data = str_ireplace($find, $replace, $data);
}
}
if($curl_cache != 0){
$st_now = strtotime("now");
$dat = $st_now."\n".$data;
file_put_contents("temp/$file_name", $dat, LOCK_EX);
}
echo $data;
exit();
}
function temp(){
if(!file_exists('temp')){
mkdir('temp', 0755);
}
}
function randline($dat){
if(preg_match_all("~\[RANDLINE-\((.+?)\)-([0-9]*)(/u)?\]~", $dat, $matches)){
foreach($matches[1] as $f){
if(!file_exists('database/'.$f) || !is_file('database/'.$f)){
$k = array_search($f, $matches[1]);
unset($matches[0][$k]);
unset($matches[1][$k]);
unset($matches[2][$k]);
unset($matches[3][$k]);
$matches[0] = array_values($matches[0]);
$matches[1] = array_values($matches[1]);
$matches[2] = array_values($matches[2]);
$matches[3] = array_values($matches[3]);
$dat = preg_replace('~\[RANDLINE-\('.$f.'\)-[0-9]*(/u)?\]~', '', $dat, 1);
}
}
$x = 0;
while(!empty($matches[1][$x])){
$rf = file('database/'.$matches[1][$x]);
if(count($rf) < $matches[2][$x]){
$matches[3][$x] = '';
}
if(!empty($rf)){
$rand_str = array();
$y = 0;
while($matches[2][$x] != $y){
if($matches[3][$x] == '/u'){
while(true){
$str = trim($rf[array_rand($rf)]);
if(!in_array($str, $rand_str)){
$rand_str[] = $str;
break;
}
}
}
else{
$rand_str[] = trim($rf[array_rand($rf)]);
}
$y++;
}
$rand_str = implode(';', $rand_str);
}
$dat = preg_replace('~\[RANDLINE-\('.$matches[1][$x].'\)-[0-9]*(/u)?\]~', $rand_str, $dat, 1);
$x++;
}
}
return $dat;
}
function randdfl($dat){
if(preg_match_all("~\[RANDDFL-\((.+?)\)-([0-9]*)(/u)?\]~", $dat, $matches)){
foreach($matches[1] as $f){
if(!file_exists('database/'.$f) || !is_dir('database/'.$f)){
$k = array_search($f, $matches[1]);
unset($matches[0][$k]);
unset($matches[1][$k]);
unset($matches[2][$k]);
unset($matches[3][$k]);
$matches[0] = array_values($matches[0]);
$matches[1] = array_values($matches[1]);
$matches[2] = array_values($matches[2]);
$matches[3] = array_values($matches[3]);
$dat = preg_replace('~\[RANDDFL-\('.$f.'\)-[0-9]*(/u)?\]~', '', $dat, 1);
}
else{
if(!file_exists('database/'.$f.'/randdfl.dat')){
$dir = opendir('database/'.$f);
$list_arr = array();
while(false !== ($file = readdir($dir))){
if ($file != '.' && $file != '..' && $file != '.htaccess' && $file != 'randdfl.dat') {
$list_arr[] = $file;
}
}
if(!empty($list_arr)){
$list = implode("\n", $list_arr);
file_put_contents('database/'.$f.'/randdfl.dat', $list, LOCK_EX);
}
}
}
}
$x = 0;
while(!empty($matches[1][$x])){
$rand_str = '';
if(file_exists('database/'.$matches[1][$x].'/randdfl.dat')){
$list_arr = file('database/'.$matches[1][$x].'/randdfl.dat');
if(!empty($list_arr)){
$rf = trim($list_arr[array_rand($list_arr)]);
if(!empty($rf)){
$rf_arr = file('database/'.$matches[1][$x].'/'.$rf);
if(!empty($rf_arr)){
$rand_str = array();
$y = 0;
while($matches[2][$x] != $y){
if($matches[3][$x] == '/u'){
while(true){
$str = trim($rf_arr[array_rand($rf_arr)]);
if(!in_array($str, $rand_str)){
$rand_str[] = $str;
break;
}
}
}
else{
$rand_str[] = trim($rf[array_rand($rf)]);
}
$y++;
}
$rand_str = implode(';', $rand_str);
}
}
}
}
$dat = preg_replace('~\[RANDDFL-\('.$f.'\)-[0-9]*(/u)?\]~', $rand_str, $dat, 1);
$x++;
}
}
return $dat;
}
function randstr($dat){
if(preg_match_all("~\[RANDSTR-\((.+?)\)-([0-9]*)\]~", $dat, $matches)){
$x = 0;
while(!empty($matches[0][$x])){
$set = $matches[1][$x];
$count = $matches[2][$x];
$str_len = strlen($set) - 1;
$rand_str = '';
while(!empty($count)){
$sym = $set[mt_rand(0, $str_len)];
$rand_str = $rand_str.$sym;
$count--;
}
$dat = preg_replace('~\[RANDSTR-\('.$matches[1][$x].'\)-('.$matches[2][$x].')\]~', $rand_str, $dat, 1);
$x++;
}
}
return $dat;
}
function randnum($dat){
if(preg_match_all("~\[RANDNUM-([0-9]*)-([0-9]*)\]~", $dat, $matches)){
$x = 0;
while(!empty($matches[0][$x])){
$rand_num = mt_rand($matches[1][$x], $matches[2][$x]);
$dat = preg_replace('~\[RANDNUM-'.$matches[1][$x].'-'.$matches[2][$x].'\]~', $rand_num, $dat, 1);
$x++;
}
}
return $dat;
}
function f1($block, $find, $flag){
global $z;
$l = 0;
$block = explode(',', mb_strtolower($block));
if(in_array($find, $block)){
$l = 1;
}
if($flag == 0 && $l == 1){
$z = 0;
}
if($flag == 1 && $l == 0){
$z = 0;
}
}
function f2($str, $find, $flag){
global $z;
$l = 0;
if(substr($find, 0, 1) == '/'){
if(preg_match($find, $str)){
$l = 1;
}
}
else{
$str = mb_strtolower($str);
$find = explode(',', mb_strtolower($find));
foreach($find as $v){
if(stristr($str, $v)){
$l = 1;
break;
}
}
}
if($flag == 0 && $l == 1){
$z = 0;
}
if($flag == 1 && $l == 0){
$z = 0;
}
}
function f3($block, $name, $version, $flag){
global $z;
$l = 0;
$block = explode(',', mb_strtolower($block));
foreach($block as $v1){
if(strstr($v1, ':')){
$ex1 = explode(':', $v1);
if(trim($ex1[0]) == $name){
$ex2 = explode(';', $ex1[1]);
foreach($ex2 as $v2){
if(trim($v2) == $version){
$l = 1;
break;
}
}
if($l == 1){
break;
}
}
}
else{
if(trim($v1) == $name){
$l = 1;
break;
}
}
}
if($flag == 0 && $l == 1){
$z = 0;
}
if($flag == 1 && $l == 0){
$z = 0;
}
}
function schedule($sch){
global $z;
$l = 0;
$time_now = strtotime(date("H:i"));
$sch = explode(',', $sch);
foreach($sch as $v){
if(preg_match("~^([0-9]{2}:[0-9]{2})\-([0-9]{2}:[0-9]{2})$~", $v, $matches)){
$time_start = strtotime(date($matches[1]));
$time_end = strtotime(date($matches[2]));
if($time_now >= $time_start && $time_now <= $time_end){
$l = 1;
break;
}
}
}
if($l != 1){
$z = 0;
}
}
?>