<?php
$pagestartime=microtime();
ob_start("ob_gzhandler");                                   /*使用缓冲，可以提高速度2~3倍，不支持请去掉这行*/
 session_start();

 $basepath="/home/chaostic/public_html";                    /*这里设置你的根目录,先看说明文件*/
if($password=="123456"){session_register("login");          /*你的密码123456*/
                                        $HTTP_SESSION_VARS["login"]="yes";}    

function wlcdel($path){
                   if(is_dir($path)){
                                    $dir=@opendir($path);
                                    while($file=@readdir($dir))
                                                               { if($file=="."||$file=="..")continue;
                                                               wlcdel("$path/$file");
                                                                 }
                                    closedir($dir);
                                    if(@rmdir($path))return 1;
                                    }
                   else {@chmod($path,0777);if(@unlink("$path"))return 1;}
                   }
function wlccopy($path1,$path2){
                   if(is_dir($path1)){
                                    @mkdir($path2,0777);
                                    $dir=@opendir($path1);
                                    while($file=@readdir($dir))
                                                               { if($file=="."||$file=="..")continue;
                                                               wlccopy("$path1/$file","$path2/$file");
                                                                 }
                                    closedir($dir);
                                    }
                   else {@copy($path1,$path2);}
                   }
function zip($path){
                   global $fp1,$b,$c,$dir;
                   if(is_dir("$dir$path")){$b="$b|w|".$path;
                                    $wlcdir=opendir("$dir$path");
                                    while($f=readdir($wlcdir))
                                                               { if($f=="."||$f=="..")continue; 
                                                               zip("$path/$f");
                                                                  }
                                    closedir($wlcdir);
                                    }
                   else {     $c="$c|w|"."$path";
                                   $fp=fopen("$dir$path","r");
                              $msg=fread($fp,filesize("$dir$path")); 
                             fclose($fp);
                              fwrite($fp1,"$msg|wlc|");
                         }                   }
function unzip($undir,$data){ 
                  $fp=fopen($data,"r");
                  $msg=explode("|wlc|",fread($fp,filesize($data)));
                  fclose($fp);
                  $num=count($msg)-3;
                  @mkdir($undir,0777);
                  $wlcdir=explode("|w|",$msg[$num+1]);
                  for($i=0;$i<=count($wlcdir)-1;$i++)
                      {
                      @mkdir("$undir/$wlcdir[$i]",0777);
                      }
                  $file=explode("|w|",$msg[$num+2]);
                  for($i=1;$i<=count($file)-1;$i++)
                      {
                      $fp=fopen("$undir/$file[$i]","w");
                      fwrite($fp,$msg[$i-1]);
                      fclose($fp);
                      }
                  }
function no($action,$dir,$file,$msg,$button,$value,$hidden){
return"  <tr>          <form method=\"POST\" action=\"index.php?action=$action&dir=$dir&file=$file&l=yes\">
          <td width=\"100%\" height=\"23\" colspan=\"2\">
             <p class=\"font\">系统：$hidden <input type=\"text\" name=\"$button\" size=\"20\" value=\"$value\">
              <input type=\"submit\" value=\"确认\" name=\"B3\"> $msg          </td>
         </form>        </tr>";                     }
function yes($msg){
return "        <tr>          <td width=\"100%\" height=\"23\" colspan=\"2\">系统：$msg </td>        </tr>";
                 }
function show($dir,$f,$url){
                    $f=str_replace($f,"",realpath("$dir"));
                     $f=str_replace("\\","/",$f);
                    $wlcdir=@opendir($dir);
                    while($file=@readdir($wlcdir))
                         {if($file==".")continue;
                          if(@is_dir("$dir$file"))$a[]=$file;
                           else $b[]=$file;
                         }
                     @closedir($wlcdir);
                     echo"<div>
                                              <center>
                                                 <table border=\"1\" width=\"100%\" height=\"22\">  
                                     <form method=\"POST\" action=\"index.php\">
                                 <tr>  
                                    <td width=\"32%\" height=\"16\" colspan=\"5\">
             <input type=button value=\"全选\" onClick=\"this.value=check(this.form)\"><font color=blue>全选时注意不要选上级目录../,会带来意想不到的后果</font>
                                   属性：   <input type=\"checkbox\" name=\"action\" value=\"chmod\">&nbsp;&nbsp;&nbsp;&nbsp;
                                   拷贝：   <input type=\"checkbox\" name=\"action\" value=\"copy\">&nbsp;&nbsp;&nbsp;&nbsp;
                                   删除：   <input type=\"checkbox\" name=\"action\" value=\"del\">&nbsp;&nbsp;&nbsp;&nbsp;              <input type=\"submit\" value=\"提交\" name=\"B3\">   
               <input type=\"reset\" value=\"重写\" name=\"B3\"> </td>  

                                </tr>
                                 <tr>  
                                    <td width=\"32%\" height=\"16\">名称</td>  
                                    <td width=\"7%\" height=\"16\">属性</td>  
                                    <td width=\"16%\" height=\"16\">修改时间</td> 
                                    <td width=\"15%\" height=\"16\">大小</td> 
                                    <td width=\"45%\" height=\"16\">操作</td> 
                                </tr>";
                    for($i=0;$i<=count($a)-1;$i++)
                      {  $fileperm=@substr(@base_convert(@fileperms("$dir$a[$i]"),10,8),-4);
                      echo"     <tr>  
                                    <td width=\"32%\" height=\"16\"><input type=\"checkbox\" name=\"w[]\" value=\"$a[$i]\"><a href=http://$url/$f/$a[$i] target=_blank>□$a[$i]/</a></td>  
                                    <td width=\"7%\" height=\"16\">$fileperm</td>  
                                    <td width=\"16%\" height=\"16\"> &nbsp;</td> 
                                    <td width=\"15%\" height=\"16\">无</td> 
                                    <td width=\"45%\" height=\"16\"><a href=index.php?dir=$dir$a[$i]/>进入</a> <a href=index.php?action=del&dir=$dir&file=$a[$i]>删除</a> <a href=index.php?action=chmod&dir=$dir&file=$a[$i]>属性</a> <a href=index.php?action=rename&dir=$dir&file=$a[$i]>改名</a> <a href=index.php?action=zip&dir=$dir&file=$a[$i]>压缩</a> <a href=index.php?action=copy&dir=$dir&file=$a[$i]>拷贝</a> </td>
                                </tr>";


                      }
                    for($i=0;$i<=count($b)-1;$i++)
                      {$size=@filesize("$dir$b[$i]");
	                $size=$size/1024 ;
                       $lastsave=@date("Y-n-d H:i",filectime("$dir$b[$i]"));
                       $size=@number_format($size, 3);
                       $fileperm=@substr(@base_convert(@fileperms("$dir$b[$i]"),10,8),-4);
                    
                      echo"     <tr>  
                                    <td width=\"32%\" height=\"16\"><input type=\"checkbox\" name=\"w[]\" value=\"$b[$i]\"><a href=http://$url/$f/$b[$i] target=_blank>◆$b[$i]</a></td>  
                                    <td width=\"7%\" height=\"16\">$fileperm</td>  
                                    <td width=\"16%\" height=\"16\">$lastsave</td> 
                                    <td width=\"15%\" height=\"16\">$size kb</td> 
                                    <td width=\"45%\" height=\"16\"><a href=index.php?action=edit&dir=$dir&file=$b[$i]>编辑</a> <a href=index.php?action=del&dir=$dir&file=$b[$i]>删除</a> <a href=index.php?action=chmod&dir=$dir&file=$b[$i]>属性</a> <a href=index.php?action=rename&dir=$dir&file=$b[$i]>改名</a> <a href=index.php?action=unzip&dir=$dir&file=$b[$i]>解压</a> <a href=index.php?action=copy&dir=$dir&file=$b[$i]>拷贝</a> <a href=index.php?action=down&dir=$dir&file=$b[$i]>下载</a></td>
                            </tr>";

                       }
                    echo"     </form> </table>";
                    }
if($dir=="")$dir="./";
$system=yes("你没有进行任何操作");
if($HTTP_SESSION_VARS["login"]=="yes")
if($HTTP_POST_VARS["action"]!="")
{
$j=0;
for($i=0;$i<=count($w);$i++)
{if($w[$i]!="")
{
$hidden.="<input type=hidden name=w[$j] value=$w[$i]>";
$j++;
}
}

}
switch($action){
case"del": if($l!="yes")$system=no($action,$dir,$file,"你真的要删除$file 吗","","确认删除",$hidden);
           else {
                if($file!=""){if($file!="..")wlcdel("$dir$file"); $system=yes("文件已经删除");}
                else for($i=0;$i<=count($w)-1;$i++)
                        {if($w[$i]!="..")wlcdel("$dir$w[$i]");  }
                         $system=yes("文件已经删除");
                } break;
case"copy":if($l!="yes")$system=no($action,$dir,$file,"请添入你要拷贝到的地方,如./bbs","copydir",$dir.$file."bak",$hidden);
              else { if($file!=""){wlccopy("$dir$file",$copydir);$system=yes("文件拷贝成功");} 
                      else  {$count=0;
                             for($i=0;$i<=count($w)-1;$i++)
                             {if(is_dir("$dir/$w[$i]"))mkdir("$copydir/$w[$i]",0777);
                              wlccopy("$dir$w[$i]","$copydir/$w[$i]");
                              $system=yes("文件拷贝成功");}
                            }
                   }break;
case"unzip":if($l!="yes")$system=no($action,$dir,$file,"请添入你要解压到的地方,如./bbs","undir",$dir,$hidden);
           else {unzip("$undir","$dir$file");$system=yes("文件解压成功");}   break;
case"zip":if($l!="yes")$system=no($action,$dir,$file,"请添入你要压缩到那个文件,如./data.wlc","zipdir",$dir."data.wlc",$hidden); 
          else {$fp1=@fopen("$zipdir","w");
                 zip("$file");
                 fwrite($fp1,"$b|wlc|$c");
                 fclose($fp1);$system=yes("文件压缩成功");}   break;
case"post":   
                for($i=0;$i<=18;$i++){        
                                      if(@copy($HTTP_POST_FILES['a']['tmp_name'][$i],$dir."/".$HTTP_POST_FILES['a']['name'][$i]))$j++;
                                     }$system=yes("上传成功 $j 个文件");break;
case"down":
             $filename = @basename("$dir$file");
		$filename_info = @explode('.', $filename);	
	       $fileext = $filename_info[count($filename_info)-1];
		header('Content-type: application/x-'.$fileext);
		header('Content-Disposition: attachment; filename='.$filename);
		header('Content-Description: PHP3 Generated Data');
		readfile("$dir$file");
		exit;break;
case"mkdir":if(@mkdir($newdir,0777))$system=yes("文件夹建立成功"); 
            else $system=yes("文件夹建立失败");break;
case"logout":$HTTP_SESSION_VARS["login"]="no";exit;break;
case"phpinfo":phpinfo();exit;break;
case"mkfile":if(file_exists($newfile)) $system=yes("文件建立失败,原因是文件已经存在");
            else{if($fp=@fopen($newfile,"w")){$system=yes("文件建立成功");fclose($fp);}
                else $system=yes("文件建立失败");}break;
case"chmod":if($l!="yes")$system=no($action,$dir,$file,"输入你要修改的文件 $file 的文件属性","chmod","0777",$hidden);
             else {    $a=@OctDec($chmod);
                       if($file!="")
                            {if(@chmod("$dir$file",$a))$system=yes("$file 文件属性更改为 $chmod成功");
                             else $system=yes("$file 文件属性更改为 $chmod 失败");}
                       else {$count=0;
                             for($i=0;$i<=count($w)-1;$i++)
                             if(@chmod("$dir$w[$i]",$a))$count++;
                              $system=yes("$count 个文件属性更改为 $chmod 成功");}
                                }break;
case"edit":if($l=="yes"){$content=stripslashes("$content");
                        $content= str_replace("//textarea>","/textarea>",$content);
                        $fp=@fopen("$dir$savename","w");
                        @fwrite($fp,$content);@fclose($fp);
                        @$system=yes("文件保存成功");}break;
case"rename":if($l!="yes")$system=no($action,$dir,$file,"请添入更改后的文件名","newname",$file,$hidden);
           else {if(@rename("$dir$file","$dir$newname"))$system=yes("文件更名成功成功");
                else  $system=yes("文件更名失败");          }   break;
}
?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件管理1.7a</title>
<style>
<!--A:link {	COLOR: #9900cc; FONT-FAMILY: 宋体; TEXT-DECORATION: none}
A:visited {	COLOR: #9900cc; FONT-FAMILY: 宋体; TEXT-DECORATION: none}
A:active {	COLOR: #000000; FONT-FAMILY: 宋体; TEXT-DECORATION: none}
A:hover {	COLOR: #9900cc; TEXT-DECORATION: none}
body         { background-color: #f3f3f3; background-repeat: repeat; background-attachment: 
               scroll; margin: 10px; background-position: 0% }
td           { font-family: 宋体; font-size: 9pt; color: #cc00cc; background-color: 
               #E7E7E7; border: 1px solid #666666 }
select, option, textarea, input { font-family: 宋体; font-size: 8pt; color: #cc00cc; background-color: #ffffff; 
               border: 1px solid #bb00bb }
-->
</style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "不选"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "全选"; }
}
//  End -->
</script>
</head>
<body>
<?
if($HTTP_SESSION_VARS["login"]!="yes"){
               echo" <p>   <P>   
                                     <P>  <P>
                 <div>
                    <center>
                 <table>
                <form action=\"index.php\" method=\"post\">
                  <tr>    
            <td width=\"30%\" height=\"20\">用 户：</td>    
            <td width=\"70%\" height=\"17\"><input type=\"text\" name=\"username\" value=\"adminstrator\" size=\"15\"></td>    
          </tr>    
            <tr>    
            <td width=\"30%\" height=\"20\">密 码：</td>    
            <td width=\"70%\" height=\"20\"><input type=\"password\" name=\"password\" size=\"15\"></td>    
          </tr>    
          <tr>    
            <td width=\"30%\" height=\"20\">  
            </td>   
            <td width=\"70%\" height=\"20\"><input type=\"submit\" value=\"提交\" name=\"B3\">   
               <input type=\"reset\" value=\"重写\" name=\"B3\"></td>   
          </tr>   
           </form>   
        </table>
                    </center></div>  ";exit();}
?>
<div align="center">
  <center>
  <table border="0" width="100%" height="101" cellspacing="0" cellpadding="0">
    <tr>
      <td width="70%" height="101" valign="top">
        <table border="1" width="100%" height="132">
          <tr>
            <td width="100%" colspan="2" align="center" height="20"><span class="forn"><font color="blue">ID&WLC</font>
              <font color="blue">文件管理1.7b</font></span></td>        
          </tr>        
          <tr>        
            <td width="100%" colspan="2" height="20"><font size="2" color="red"><a href=index.php?action=logout>用户注销</a>
              <a href=index.php?action=phpinfo>配置信息</a></font></td>      
          </tr>      
          <tr>      
                    <form method="POST" action="./index.php?">     
          <td width="50%" height="15"  >     
            目录：<input type="text" name="dir" value="" size="20"> <input type="submit" value="更改" name="B3">       
             </td></form>       
            <td width="50%" height="13">不填写时为脚本所在的目录</td>        
          </tr>        
          <tr>        
           <form method="POST" action="./index.php?action=mkdir&dir=<? echo$dir;?>">       
          <td width="50%" height="20"  >       
            目录：<input type="text" name="newdir" value="<?php echo"$dir"?>" size="20"> <input type="submit" value="创建" name="B3">       
             </td></form>       
             <form method="POST" action="./index.php?action=mkfile&dir=<? echo$dir;?>">       
          <td width="50%" height="20"  >       
            文件：<input type="text" name="newfile" value="<?php echo"$dir";?>" size="20"> <input type="submit" value="创建" name="B3">       
             </td></form>       
          </tr>        
          <tr>        
            <td width="100%" height="23" colspan="2">路径:<? echo realpath(".");?></td>      
          </tr>      
<?php echo$system;?>   
        </table>      
      </td>      
      <td width="30%" height="101" valign="top">      
        <table border="1" width="100%">      
          <form method="POST" action="./index.php?action=post" ENCTYPE="multipart/form-data">    
          <tr>     
            <td width="100%" height="20" colspan="2" align="center"><font size="2">文件上传</font></td>    
          </tr>    
          <tr>    
            <td width="50%" height="20"><input type="file" name="a[]" size="6"></td>    
            <td width="50%" height="17"><input type="file" name="a[]" size="6"></td>    
          </tr>    
           <tr>    
            <td width="50%" height="20"><input type="file" name="a[]" size="6"></td>    
            <td width="50%" height="20"><input type="file" name="a[]" size="6"></td>    
          </tr>    
          <tr>    
            <td width="50%" height="20"><input type="file" name="a[]" size="6"></td>    
            <td width="50%" height="17"><input type="file" name="a[]" size="6"></td>    
          </tr>    
            <tr>    
            <td width="50%" height="20"><input type="file" name="a[]" size="6"></td>    
            <td width="50%" height="20"><input type="file" name="a[]" size="6"></td>    
          </tr>    
          <tr>    
            <td width="50%" height="20">    
            <input type="text" name="dir" value="<?echo"$dir";?>" size="10">传到   
            </td>   
            <td width="50%" height="20"><input type="submit" value="提交" name="B3">   
               <input type="reset" value="重写" name="B3"></td>   
          </tr>   
           </form>   
        </table>    
      </td>    
    </tr>    
  </table>    
  </center>    
</div>    
<?php
 if($action=="edit"&&$l!="yes"){ 
 $fd = @fopen( "$dir$file", "r" );
  $a = @fread($fd, filesize("$dir$file"));
  @fclose( $fd );
  $a= str_replace("/textarea>","//textarea>",$a);
 echo"      <form method=\"POST\" action=\"index.php?action=edit&l=yes&dir=$dir\">
<p>
<textarea rows=\"17\" name=\"content\" cols=\"120\">$a</textarea>
<br>文件名:<input type=\"text\" name=\"savename\" size=\"15\" value=\"$file\"> 
<input type=\"submit\" value=\"提交\" name=\"i\"> 
<input type=\"reset\" value=\"全部重写\" name=\"B2\"></p> 
          </form>
      <p>";}else show($dir,"$basepath",$HTTP_HOST);?>
    </td>
    </tr>
  </table>
  </center>
</div>
<div>
   <center>
 <table border="1" width="100%" height="22">  
                                 <tr>  
                                    <td width="100%" height="16">
       <?php
$pageendtime=microtime();
$starttime=explode(" ",$pagestartime);
$endtime=explode(" ",$pageendtime);
$totaltime=$endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost=sprintf("%s",$totaltime);
echo "<font color=red>页面运行时间：$timecost 秒 </font>";?>
</td>  
</tr>
  </table>
  </center>
</div>
</body>
</html>                                         