**************************************************************************** Changelog: v1.0 10-19-03 initial release ***************************************************************************/ /***************************************************************************/ /** SET YOUR CONFIGURATION HERE **/ /***************************************************************************/ // specify which files should be hidden in the file listing // using unix/DOS wildcards (? and *) // this is case insensitive // this script, the current directory and the description file will automatically be hidden $hiddenFilesWildcards = Array("*.php",".*"); // description file, leave blank for no descriptions $useDescriptionsFrom = ""; // show sub directories and let the user enter them $allowSubDirs = true; /***************************************************************************/ /** REAL CODE STARTS HERE **/ /***************************************************************************/ // default sorting is by name if ($_GET["sort"]=="") $_GET["sort"] = "name"; // default order is ascending if ($_GET["order"]=="") $_GET["order"] = "asc"; // add files used by snif to hidden file list $hiddenFilesWildcards[] = $useDescriptionsFrom; $hiddenFilesWildcards[] = "."; $hiddenFilesWildcards[] = basename($_SERVER["PHP_SELF"]); // handle image requests if ($_GET["getimage"]!="") { Header("Content-Type: image/gif"); Header("Expires: ".date("r",time()+3600)); switch ($_GET["getimage"]) { case "asc": echo base64_decode("R0lGODlhBQADAIABAN3d3f///yH5BAEAAAEALAAAAAAFAAMAAAIFTGAHuF0AOw=="); break; case "binary": echo base64_decode("R0lGODlhEAAQAJECAAAAAP///////wAAACH5BAEAAAIALAAAAAAQABAAAAI0lICZxgYBY0DNyfhAfROrxoVQBo5mpzFih5bsFLoX5iLYWK6xyur5ubPAbhPZrKhSKCmCAgA7"); break; case "desc": echo base64_decode("R0lGODlhBQADAIABAN3d3f///yH5BAEAAAEALAAAAAAFAAMAAAIFhB0XC1sAOw=="); break; case "folder": echo base64_decode("R0lGODlhEAAQAJECAAAAAP///////wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+JwKAJggzuiThl2wbnT3UgWHmjJp5Tqa5py7bhJc/mWW46Z/V+UgAAOw=="); break; case "html": echo base64_decode("R0lGODlhEAAQAKIHABsb/2ho/4CA/0BA/zY2/wAAAP///////yH5BAEAAAcALAAAAAAQABAAAANEeFfcrVAVQ6thUdo6S57b9UBgSHmkyUWlMAzCmlKxAZ9s5Q5AjWqGwIAS8OVsNYJxJgDwXrHfQoVLEa7Y6+Wokjq+owQAOw=="); break; case "image": echo base64_decode("R0lGODlhEAAQAKIEAK6urmRkZAAAAP///////wAAAAAAAAAAACH5BAEAAAQALAAAAAAQABAAAANCSCTcrVCJQetgUdo6RZ7b9UBgSHnkAKwscEZTy74pG9zuBavA7dOanu+H0gyGxN0RGdClKEjgwvKTlkzFhWOLISQAADs="); break; case "text": echo base64_decode("R0lGODlhEAAQAJECAAAAAP///////wAAACH5BAEAAAIALAAAAAAQABAAAAI0lICZxgYBY0DNyfhAfXcuxnWQBnoKMjXZ6qUlFroWLJHzGNtHnat87cOhRkGRbGc8npakAgA7"); break; case "unknown": echo base64_decode("R0lGODlhEAAQAJECAAAAAP///////wAAACH5BAEAAAIALAAAAAAQABAAAAI1lICZxgYBY0DNyfhAfXcuxnkI1nCjB2lgappld6qWdE4vFtprR+4sffv1ZjwdkSc7KJYUQQEAOw=="); break; } die(); } /** * Formats a file's size nicely (750 B, 3,4 KB etc.) */ function niceSize($size) { $units = Array(" B","KB","MB","GB","TB"); $sizeStep = 1024.0; if ($size=="") return ""; $unitIndex = 0; while ($size>$sizeStep) { $size = $size / $sizeStep; $unitIndex++; } if ($unitIndex==0) { return number_format($size, 0)." ".$units[$unitIndex]; } else { return number_format($size, 1, ".", ",")." ".$units[$unitIndex]; } } /** * Compare two strings or numbers. Return values as strcmp(). */ function myCompare($arrA, $arrB, $caseSensitive=false) { $a = $arrA[$_GET["sort"]]; $b = $arrB[$_GET["sort"]]; // sort directories above everything else if ($arrA["isDirectory"]!=$arrB["isDirectory"]) { $result = $arrB["isDirectory"]-$arrA["isDirectory"]; } else { if (is_string($a) OR is_string($b)) { if (!$caseSensitive) { $a = strtoupper($a); $b = strtoupper($b); } $result = strcoll($a,$b); } else { $result = $a-$b; } } if (strtolower($_GET["order"])=="desc") { return -$result; } else { return $result; } } /** * Build a URL using new sorting settings. */ function getNewSortURL($newSort) { GLOBAL $path; $base = $_SERVER["PHP_SELF"]; $url = $base."?sort=$newSort"; if ($newSort==$_GET["sort"]) { if ($_GET["order"]=="asc" OR $_GET["order"]=="") { $url.= "&order=desc"; } } if ($path!="") { $url.= "&path=$path"; } return $url; } /** * Determine a file's file type based on its extension. */ function getFileType($extension, $isDir) { if ($isDir) return "folder"; if (in_array($extension, Array("ace","avi","bin","class","doc","exe","gz","jar","mov","mpg","mpeg","mp3","ogg","pdf","rar","rm","swf","tar","tgz","zip"))) return "binary"; if (in_array($extension, Array("html","htm"))) return "html"; if (in_array($extension, Array("gif","jpg","jpeg","png"))) return "image"; if (in_array($extension, Array("asp","c","cpp","css","h","ini","java","php","phps","txt","xml"))) return "text"; return "unknown"; } // if sub directories are forbidden, ignore any path setting if (!$allowSubDirs) { $path = ""; } else { $path = $_GET["path"]; // ignore any potentially malicious paths if (strpos($path,"..")!==false OR substr($path,0,1)=="/") $path = ""; } // read directory //chdir($path); $dir = dir("."); // transform the hidden files wildcards to one big regex $hiddenFilesRegex = Array(); for ($i=0;$iread()) { // if the filename matches one of the hidden files wildcards, skip the file if (preg_match($hiddenFilesWholeRegex,$entry)) continue; // if the file is a directory and if directories are forbidden, skip it if (!$allowSubDirs AND is_dir($entry)) continue; $f = Array(); $f["name"] = $entry; $f["isDirectory"] = is_dir($entry); $f["date"] = filemtime($entry); if (is_dir($entry)) { $f["type"] = "<DIR>"; // building the link if ($entry=="..") { // strip the last directory from the path $pathArr = explode("/",$path); $link = implode("/",array_slice($pathArr,0,count($pathArr)-2)); // if there is no path set, don't add it to the link if ($link=="") { // we're already in $baseDir, so skip the file if ($path=="") continue; $f["link"] = $_SERVER["PHP_SELF"]; } else { $link.= "/"; $f["link"] = $_SERVER["PHP_SELF"]."?path=".$link; } } else { $f["link"] = $_SERVER["PHP_SELF"]."?path=".$path.$entry."/"; } } else { $f["size"] = filesize($entry); $f["type"] = substr($entry,strrpos($entry,".")+1); $f["link"] = $path.$entry; } $f["icon"] = getFileType($f["type"], is_dir($entry)); $f["description"] = $descriptions[$entry]; $files[] = $f; } usort($files, "myCompare"); $columns = 4; if ($useDescriptionsFrom!="") $columns++; ?> Index of <?echo dirname($_SERVER["PHP_SELF"]);?> ">
http://
">name  "; ?> ">type  "; ?> "; ?> ">size ">date  "; ?> description
">" width="16" height="16" border="0" style="vertical-align:middle;">   Bytes"> ">

snif 1.0 © 2003 Kai Blankenhorn