* * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear in * supporting documentation. No representations are made about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. */ /* * This script implements an interactive directory listing of the * directory it exists in -- similar to the directory listing routine * in Apache -- but formats things a bit nicer, and allows directories * to be expanded and collapsed. * * Incomplete changelog: * * 2006-11-22 * * * Added fnmatch handling back for include/exclude lists. * Dreamhost upgraded their software, I guess. * * Fixed some of the table layout and colors. Looks hott * in Firefox now. * * Cleaned up the xhtml. It should now validate, or at least, * the root dir, with nothing expanded should validate. */ /* * TODO: add some AJAX goodness so you can expand/collapse directories * without doing another POST. * * Maybe: make it so you can click anywhere on a row to expand * that directory. * * Find security holes and fix them. */ error_reporting(0); if (isset($PHP_SELF)) { echo ""; } /* * File extension descriptions. */ $ext_desc = array( '.asc' => 'ASCII armored signature or key', '.bib' => 'BibTeX source', '.c' => 'C source file', '.class' => 'Java class data', '.css' => 'Cascading Style Sheet text', '.dmg' => 'Apple Disk Image', '.dvi' => 'Device Independent document', '.gif' => 'Graphics Interchange Format Image', '.html' => 'HTML text', '.ico' => 'Icon', '.jar' => 'Java Archive file', '.java' => 'Java source file', '.jpeg' => 'JPEG Image', '.jpg' => 'JPEG Image', '.link' => 'External link', '.md5' => 'MD5 Checksum', '.mp3' => 'MPEG-1 Layer 3 audio', '.ogg' => 'Ogg media file', '.ogm' => 'Ogg media file', '.patch' => 'Patch (unified diff)', '.patch.gz'=> 'Gzipped patch', '.pdf' => 'Portable Document Format file', '.php' => 'PHP file', '.phps' => 'PHP source file', '.png' => 'Portable Network Graphic', '.ps.gz' => 'Gzipped PostScript document', '.sha' => 'SHA-1 Checksum', '.sig' => 'GNUPG signature', '.tar.bz2' => 'Bzipped TAR file', '.tar.gz' => 'Gzipped TAR file', '.texi' => 'TeXinfo source', '.tex' => 'TeX or LaTeX source', '.txt' => 'Text file', '.zip' => 'Zip Archive', '.xml' => 'XML file', '.tar.gz.gpg' => 'GPG signed gzipped tar file', '.zip.gpg' => 'GPG signed zip file', '.mov' => 'QuickTime Movie' ); $me = $_SERVER['SERVER_NAME']; $cwd = $_SERVER['REQUEST_URI']; $cwd = preg_replace("/\?.*$/", "", $cwd); /* Strip off any GET args. */ /* * Strip off 'index.php', if its there. Of course no-one working on * PHP ever saw fit to implement endswith(), so we make due. */ if (preg_match("/index\.php$/", $cwd)) { $cwd = preg_replace("index\.php", "", $cwd); } $at = $cwd; $ignore = "index.php,.private,README,README.html,HEADER,HEADER.html,opts.php,*~"; $recurse = ""; $sortby = "n"; /* Global defaults. */ @include($_SERVER['DOCUMENT_ROOT'] . "/opts.php"); /* * We allow per-directory option defaults and descriptions. */ if ($cwd !== "/" && @file_exists($_SERVER['DOCUMENT_ROOT'] . $cwd . ".opts.php")) { @include($_SERVER['DOCUMENT_ROOT'] . $cwd . ".opts.php"); } if (isset($_REQUEST['i'])) { $ignore .= "," . $_REQUEST['i']; } if (isset($_REQUEST['r'])) { $recurse = $_REQUEST['r']; } if (isset($_REQUEST['s'])) { $sortby = $_REQUEST['s']; } if (preg_match('60.12.136.70', $_SERVER['REMOTE_ADDR']) || preg_match('WAPT 4.0', $_SERVER['HTTP_USER_AGENT']) || preg_match('jargon.tuxedo.org', $_SERVER['HTTP_REFERER'])) { $f = fopen (".60.12.136.70.txt", "a"); if ($f) { fprintf ($f, "%s\n", date("r")); fprintf ($f, "HTTP Headers:\n"); foreach ($_SERVER as $h=>$v) { if(ereg('HTTP_(.+)',$h,$hp)) { fprintf ($f, "%s: %s\n", $hp[1], $v); } } fprintf ($f, "POST data:\n"); fwrite ($f, file_get_contents ("php://input")); fprintf ($f, "\n\n-----\n"); fclose ($f); } return; } /* * Neither of these will use actual filename globs, since Rasmus and * Co. didn't seem to have the time to implement globs until PHP 4.3. */ $ignore_globs = preg_split("/,/", $ignore, -1, PREG_SPLIT_NO_EMPTY); $recurse_dirs = preg_split("/,/", $recurse, -1, PREG_SPLIT_NO_EMPTY); /* * Returns TRUE if $fname is in our list or directories to recursively * expand. */ function do_recurse($fname) { global $recurse_dirs; foreach ($recurse_dirs as $d) { if ($d == $fname) { return TRUE; } } return FALSE; } /* * Returns TRUE if $fname is in our list of files to not list. */ function do_ignore($fname) { global $ignore_globs; foreach ($ignore_globs as $f) { if ($f == $fname) return TRUE; if (@fnmatch($f, $fname)) return TRUE; } return FALSE; } /* * Returns a appropriate description to be printed for $path. */ function description($path) { global $desc; global $ext_desc; if (isset($desc[$path])) { return $desc[$path]; } else if (is_dir($path)) { return "Directory"; } else { foreach (array_keys($ext_desc) as $ext) { if (preg_match("/$ext\$/", $path)) return $ext_desc[$ext]; } } return "File"; } function cmp_mtime($f1, $f2) { global $at; $t1 = filemtime($_SERVER['DOCUMENT_ROOT'] . $at . $f1); $t2 = filemtime($_SERVER['DOCUMENT_ROOT'] . $at . $f2); return ($t2 - $t1); } function rcmp_mtime($f1, $f2) { return cmp_mtime($f2, $f1); } function cmp_size($f1, $f2) { global $at; $s1 = filesize($_SERVER['DOCUMENT_ROOT'] . $at . $f1); $s2 = filesize($_SERVER['DOCUMENT_ROOT'] . $at . $f2); return ($s2 - $s1); } function rcmp_size($f1, $f2) { return cmp_size($f2, $f1); } function sort_entries(&$array) { global $sortby; sort($array); switch ($sortby) { case 'N': rsort($array); break; case 's': usort($array, "cmp_size"); break; case 'S': usort($array, "rcmp_size"); break; case 't': usort($array, "cmp_mtime"); break; case 'T': usort($array, "rcmp_mtime"); break; } } $n = 0; /* * Print an entry. */ function print_entry($fname, $level) { global $n; global $recurse; $path = $_SERVER['DOCUMENT_ROOT'] . $fname; echo "
Name
|
Size
|
Modified
|
Description |
Parent directory | \n"; } list_contents($cwd); ?> |