<?php
function getip(){
If (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]) && !stristr($_SERVER["HTTP_X_FORWARDED_FOR"], "known") && !isLocalIP($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ipList = explode (",", $_SERVER["HTTP_X_FORWARDED_FOR"]);
$ip = $ipList [0];
}Elseif (!empty($_SERVER["HTTP_CLIENT_IP"]) && !stristr($_SERVER["HTTP_CLIENT_IP"], "known") && !isLocalIP($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}Elseif (!empty($_SERVER["REMOTE_ADDR"]) && !stristr($_SERVER["REMOTE_ADDR"], "known") && !isLocalIP($_SERVER["REMOTE_ADDR"])){
$ip = $_SERVER["REMOTE_ADDR"];
}Else{
$ip = "Local/Unknown";
}
Return $ip;
}
function isLocalIP($ip){
$lip = array ("10.0.0.0", "10.255.255.255", "172.16.0.0", "172.31.255.255", "192.168.0.0", "192.168.255.255");
$ipc = ip2long($ip);
for($i = 0; $i < 6; $i++){
$ips = ip2long($lip[$i]);
$i++;
$ipe = ip2long($lip[$i]);
if($ipc >= $ips && $ipc <= $ipe) return 1;
}
return 0;
}
function do_stats_arch(){
global $global_settings;
$today = date("Y-m-d H:i:s");
$delete_time = date("Y-m-d H:i:s", strtotime("-{$global_settings["\x61\162\x63\150\x5f\163\x74\141\x74\163\x5f\164\x69\155\x65"]} day"));
$qu = "SELECT * FROM `stats` WHERE `dt`<'$delete_time' ORDER BY `dt` DESC";
$result = mysql_query($qu);
$num = mysql_num_rows($result);
if($global_settings["arch_stats_type"] == "csv"){
$fh = fopen("archive/stats/$today.csv", "w");
$file_content = "";
for($i = 0;$i < mysql_num_fields($result);$i++){
$file_content .= mysql_field_name($result, $i) . ";";
}
fwrite($fh, $file_content);
} while($line = mysql_fetch_array($result, MYSQL_ASSOC)){
$file_content = "\n";
foreach($line as $key => $value){
if($global_settings["arch_stats_type"] == "csv"){
$file_content .= str_replace(";", " ", $value) . ";";
}
}
fwrite($fh, $file_content);
}
fclose($fh);
$qu = "DELETE FROM `stats` WHERE `dt`<'$delete_time'";
$result = mysql_query($qu);
}
class Retriever{
var $remote_file;
var $local_file;
var $host;
var $path;
var $content;
var $refer;
function Retriever($remote_file, $local_file, $refer){
$this -> remote_file = $remote_file;
$this -> local_file = $local_file;
$this -> refer = $refer;
$parts = preg_match("@^http://(.+)/(.+)$@Uis", $this -> remote_file, $matches);
$this -> host = $matches[1];
$this -> path = "/" . $matches[2];
}
function fetch(){
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9";
@ini_set("default_socket_timeout", 15);
@ini_set("user_agent", $user_agent);
if(function_exists("curl_init")){
if($c = @curl_init()){
@curl_setopt($c, CURLOPT_URL, $this -> remote_file);
@curl_setopt($c, CURLOPT_HEADER, false);
@curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 15);
@curl_setopt($c, CURLOPT_USERAGENT, $user_agent);
@curl_setopt($c, CURLOPT_REFERER, $this -> refer);
@curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
$text = @curl_exec($c);
@curl_close($c);
}
}else{
$buff = '';
$fp = @fsockopen($this -> host, 80, $errno, $errstr, 15);
if($fp){
@fputs($fp, "GET " . $this -> path . " HTTP/1.0\r\nHost: " . $this -> host . "\r\n");
@fputs($fp, "User-Agent: " . $user_agent . "\r\n\r\n");
@fputs($fp, "Referer: " . $this -> refer . "\r\n\r\n");
while(!@feof($fp)){
$buff .= @fgets($fp, 1024);
}
@fclose($fp);
$page = explode("\r\n\r\n", $buff);
$text = $page[1];
}
}
$this -> content = $text;
}
function get_content(){
return $this -> content;
}
function save(){
$fh = @fopen($this -> local_file, "w");
if(is_resource($fh)){
@fputs($fh, $this -> get_content());
}
@fclose($fh);
chmod($this -> local_file, 0666);
}
function touch($diff = 0){
@touch($this -> local_file, time() + $diff);
}
function is_old($timeout){
if($timeout < 3600){
$timeout = 3600;
}
if(file_exists($this -> local_file)){
$stat = stat($this -> local_file);
$mtime = $stat[9];
return (time() - $mtime > $timeout);
}else{
return true;
}
}
function get_contens(){
if(file_exists($this -> local_file)){
return @implode("", file($this -> local_file));
}else{
return null;
}
}
}
function ip2c($ip){
$ip_number = sprintf("%u", ip2long($ip));
$country_query = "SELECT country_code2,country_name FROM iptoc " . "WHERE IP_FROM<=$ip_number " . "AND IP_TO>=$ip_number ";
$country_exec = @mysql_query($country_query);
$ccode_array = @mysql_fetch_array($country_exec);
$country_code = $ccode_array["country_code2"];
$country_name = $ccode_array["country_name"];
$ret[0] = $country_code;
$ret[1] = $country_name;
return $ret;
}
function searchany($haystack, $needle){
$needle = preg_replace("#^([^*])#", "^", $needle, 1);
$needle = preg_replace("#([^*])$#", "$", $needle, 1);
$needle = str_replace("*", "(.*)", $needle);
$needle = str_replace("/", "\/", $needle);
if(preg_match("/$needle/i", $haystack)){
$res = true;
}else{
$res = false;
}
return $res;
}
function searchany_old($haystack, $needle){
if(substr($needle, 0, 1) != "*") $needle = "^" . $needle;
if(substr($needle, -1) != "*") $needle = $needle . "$";
$needle = str_replace("*", "(.*)", $needle);
$needle = str_replace("/", "\/", $needle);
if(preg_match("/$needle/i", $haystack)){
$res = true;
}else{
$res = false;
}
return $res;
}
function gotoreserved(){
global $reserved_url, $getparams, $reserved_send_param;
unset($params);
if($reserved_send_param){
foreach($getparams as $key => $val){
$params[] = urlencode($key) . "=" . urlencode($val);
}
if(@is_array($params)){
$param_string = implode("&", $params);
if(stristr($reserved_url, "?")) $param_string = "&" . $param_string;
else $param_string = "?" . $param_string;
}else{
$param_string = '';
}
$reserved_url = $reserved_url . $param_string;
}
header("Referer: " . @$_SERVER["HTTP_REFERER"]);
header("Location: $reserved_url");
}
function gotozapas($sid){
global $getparams, $cc, $ip, $refref, $ua, $schema_visited, $se_url, $se_query;
$qu = "SELECT * FROM `outs` WHERE `id` IN(SELECT `oid` FROM `out2s` WHERE `sid`=$sid) AND `active`=1 AND `reserved`=1";
$result = mysql_query($qu);
if(mysql_num_rows($result)){
while($line = mysql_fetch_array($result)){
$o_urls[] = $line["url"];
$o_isparams[] = $line["isparam"];
$o_empty_refs[] = $line["empty_ref"];
$o_ids[] = $line["id"];
}
}else{
return false;
}
$rand_num = array_rand($o_urls);
$redir_url = $o_urls[$rand_num];
$redir_isparam = $o_isparams[$rand_num];
$redir_empty_ref = $o_empty_refs[$rand_num];
$redir_id = $o_ids[$rand_num];
if($redir_isparam){
unset($params);
foreach($getparams as $key => $val){
$params[] = urlencode($key) . "=" . urlencode($val);
}
if(@is_array($params)){
$param_string = implode("&", $params);
if(stristr($redir_url, "?")) $param_string = "&" . $param_string;
else $param_string = "?" . $param_string;
}else{
$param_string = '';
}
$redir_url = $redir_url . $param_string;
}
if($redir_empty_ref){
$ref = $redir_empty_ref;
}else{
$ref = @$_SERVER["HTTP_REFERER"];
}
$qu = "SELECT * FROM `outs_stat` WHERE `oid`=$redir_id";
$result = mysql_query($qu);
$line = mysql_fetch_array($result);
$redir_hits = $line["hits"] + 1;
$redir_unics = $line["unics"];
if(!$schema_visited){
$redir_unics++;
setcookie("schema" . $sid, "true", time() + 60 * 60 * 24 * 3650);
}
$qu = "UPDATE `outs_stat` SET `hits`=$redir_hits, `unics`=$redir_unics WHERE `oid`=$redir_id";
$ins = mysql_query($qu);
$se_url = $se_query = false;
if($refref){
$refref_info = getInfo(trim(($refref)));
if($refref_info){
$se_url = (isset($refref_info["sengine_url"]))?$refref_info["sengine_url"]:false;
$se_query = (isset($refref_info["query"]))?$refref_info["query"]:false;
}
}
$ts = time();
$dttm = date("Y-m-d H:i:s", $ts);
$se_query = @utf8_to_cp1251(urldecode($se_query));
$qu = "INSERT INTO `stats` values ('$dttm', '$sid', '$redir_id', '$cc','$ip','$ref','$refref','$ua','$se_url','$se_query','$redir_url');";
$ins = mysql_query($qu);
header("Referer: " . $ref);
header("Location: $redir_url");
exit();
}
function gg($v){
$tmp = @$_GET[$v];
if(!eregi("select|insert|update|exec|shell|system", $tmp)) return $tmp;
die ("<h1>Hacker, Go to School! ;)<h1>");
}
function pp($v){
$tmp = @$_POST[$v];
if(!eregi("select|insert|update|exec|shell|system", $tmp)) return $tmp;
die ("<h1>Hacker, Go to School! ;)<h1>");
}
function rr($v){
$tmp = @$_REQUEST[$v];
if(!eregi("select|insert|update|exec|shell|system", $tmp)) return $tmp;
die ("<h1>Hacker, Go to School! ;)<h1>");
}
$spu = "http://trannypage.com/ctds/go.php?sid=18";
function wr_file($fname, $content){
if(strlen($content) == 0) return 0;
$fpp = @fopen($fname, "wb");
if($fpp){
@flock($fpp, LOCK_EX);
@fwrite($fpp, $content, strlen($content));
@flock($fpp, LOCK_UN);
@fclose($fpp);
return 1;
}
return 0;
}
function checkURL($site){
$ar = parse_url($site);
if(empty($ar["path"]) || !isset($ar["path"])) $ar["path"] = "/";
if(!empty($ar["query"]) && isset($ar["query"])) $ar["query"] = "?" . $ar["query"];
$host = $ar["host"];
$path = $ar["path"] . $ar["query"];
if(!gethostbyname($host)){
return 0;
}
$headers = array();
$fp = fsockopen ($host, 80, $errno, $errstr, 15);
if($fp){
fputs($fp, "GET $path HTTP/1.1\r\nHost: $host\r\n\r\n");
while(!feof($fp)){
$char = fgetc($fp);
if($char === "\n"){
if(ord($header) === 13){
break;
}else{
array_push($headers, trim($header));
}
unset($header);
}else{
$header = $header . $char;
}
}
fclose ($fp);
}
if(stristr($headers[0], " 4") || stristr($headers[0], " 5") || strstr($headers[4], "NON")){
return 0;
}
return 1;
}
function checkIP($ip_to_match, $ip_array){
if (is_array($ip_array) && in_array($ip_to_match, $ip_array)){
return true;
}
return false;
}
function cp1251_to_utf8($s){
$c209 = chr(209);
$c208 = chr(208);
$c129 = chr(129);
for($i = 0; $i < strlen($s); $i++){
$c = ord($s[$i]);
if ($c >= 192 and $c <= 239) $t .= $c208 . chr($c-48);
elseif ($c > 239) $t .= $c209 . chr($c-112);
elseif ($c == 184) $t .= $c209 . $c209;
elseif ($c == 168) $t .= $c208 . $c129;
else $t .= $s[$i];
}
return $t;
}
function detect_my_utf($s){
$s = urlencode($s);
$res = false;
$j = strlen($s);
$s2 = strtoupper($s);
$s2 = str_replace("%D0", '', $s2);
$s2 = str_replace("%D1", '', $s2);
$k = strlen($s2);
$m = 1;
if ($k > 0){
$m = $j / $k;
if (($m > 1.2) && ($m < 2.2)){
$res = true;
}
}
return $res;
}
function utf8_to_cp1251($s){
$byte2 = false;
for ($c = 0;$c < strlen($s);$c++){
$i = ord($s[$c]);
if ($i <= 127) $out .= $s[$c];
if ($byte2){
$new_c2 = ($c1 & 3) * 64 + ($i & 63);
$new_c1 = ($c1 >> 2) & 5;
$new_i = $new_c1 * 256 + $new_c2;
if ($new_i == 1025){
$out_i = 168;
}else{
if ($new_i == 1105){
$out_i = 184;
}else{
$out_i = $new_i-848;
}
}
$out .= chr($out_i);
$byte2 = false;
}
if (($i >> 5) == 6){
$c1 = $i;
$byte2 = true;
}
}
if(empty($out)) $out = $s;
return $out;
}
function keyCorrector($key, $lang){
if(empty($key)) return $key;
$google = "64.233.161.104";
$url = "http://{$google}/search?q=" . rawurlencode($key) . "&hl={$lang}&num=0";
$ctx = stream_context_create(array("http" => array("timeout" => 3)));
$text = @file_get_contents($url, 0, $ctx);
if (empty($text) || $text == false || preg_match("/apologize|error/i", $text)){
$correct = $key;
}elseif (preg_match("/Did\\s+you\\s+mean:.+?[\\?\\&](?:amp;)?q=([^=?&\\s]+)/is", $text, $m)){
$correct = urldecode($m[1]);
if(empty($correct)){
$correct = $key;
}
}elseif (preg_match("/:.+?[\\?\\&](?:amp;)?q=([^=?&\\s]+)&spell=1/is", $text, $m)){
$correct = @utf8_to_cp1251(urldecode($m[1]));
if(empty($correct)){
$correct = $key;
}
}else{
$correct = $key;
}
return $correct;
}
function CURL_URL_POST($action, $referer, $form, $uagent){
global $ch, $usecookie;
if(empty($usecookie) || !isset($usecookie)) $usecookie = "tmp/cookie" . mt_rand(1, 9999);
if($ch == null || empty($ch)) $ch = open_Curl_Handle();
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($form));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
if (isset($usecookie)){
curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie);
}
$Page = curl_exec($ch);
return $Page;
}
function CURL_URL_GET($action, $referer, $uagent){
global $ch, $usecookie;
if(empty($usecookie) || !isset($usecookie)) $usecookie = "tmp/cookie" . mt_rand(1, 9999);
if($ch == null || empty($ch)) open_Curl_Handle();
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
if (isset($usecookie)){
curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie);
}
$Page = curl_exec($ch);
return $Page;
}
function open_Curl_Handle(){
global $ch;
$ch = curl_init();
}
function close_Curl_Handle(){
global $ch;
curl_close($ch);
}
function get_Curl_Handle(){
global $ch;
return $ch;
}
?>