****************************************************************************/ /***************************************************************************/ /** REAL CODE STARTS HERE, NO NEED TO CHANGE ANYTHING **/ /***************************************************************************/ // INITIALISATION require 'config.inc'; require 'functions.inc'; require 'Smarty/Smarty.class.php'; $s = new Smarty; $s->template_dir = $templatePath; $s->compile_dir = $compilePath; $s->register_function('thumb', 'smarty_function_thumb'); // make sure all the notices don't come up in some configurations error_reporting (E_ALL ^ E_NOTICE); $displayError = ""; // safify all GET variables foreach($_GET AS $key => $value) { $_GET[$key] = strip_tags($value); } $uri = ""; $server = $_SERVER['SERVER_NAME']; $baseurl = ""; $docroot = ""; ## determine URI / handle urlencoded URI / handle mozilla URI / ignore ?something=set list($uri) = explode("?", $_SERVER["REQUEST_URI"]); # '?hash=uauaus&bla=xx' weg $uri = rawurldecode($uri); # falls uri encoded ist -> DEcoden ;) preg_replace("/http\:\/\/$server\//", "", $uri); # sort of mozilla-hack .. ## determine SERVER / BASEURL / DOCROOT $baseurl = "http://" . $server; $docroot = preg_replace("/\/$/","", $_SERVER["DOCUMENT_ROOT"]); # get rid of trailing '/' $path = $docroot . $uri; // default sorting is by name if ($_GET["sort"]=="") { $_GET["sort"] = "name"; } // default order is ascending if ($_GET["order"]=="") { $_GET["order"] = "asc"; } else { $_GET["order"] = strtolower($_GET["order"]); } // add files used by snif to hidden file list $hiddenFilesWildcards[] = $useDescriptionsFrom; $hiddenFilesWildcards[] = "."; $hiddenFilesWildcards[] = basename($_SERVER["PHP_SELF"]); // build hidden files regular expression for ($i=0;$i "\\.", "*" => ".*", "?" => ".?", "+" => "\\+", "[" => "\\[", "]" => "\\]", "(" => "\\(", ")" => "\\)", "{" => "\\{", "}" => "\\}", "^" => "\\^", "\$" => "\\\$", "\\" => "\\\\", ); $hiddenFilesRegex[] = "^".strtr($hiddenFilesWildcards[$i],$translate)."$"; } // hide .* $hiddenFilesRegex[] = "^\\.[^.].*$"; $hiddenFilesWholeRegex = "/".join("|",$hiddenFilesRegex)."/i"; // handle image requests if ($_GET["getimage"]!="") { require 'doGetImage.inc'; } // handle thumbnail creation if ($_GET["thumbnail"]!="") { require 'doThumbnail.inc'; } // handle download requests if ($_GET["download"]!="") { require 'doDownload.inc'; } if (isset($_GET['redir'])) { require 'doRedir.inc'; } // load .config if (file_exists($path.'/.snif/.config')) { @include($path.'/.snif/.config'); if ($coralize) { $coralbase = 'http://' . $server . '.nyud.net:8090' . $uri; } } // change directory // must be done before description file is parsed if ($path!="") { if (!@chdir($path)) { $displayError = "$path is not a subdirectory of the current directory."; $path = ""; } } $dir = dir("."); // parsing description file $descriptions = Array(); if ($useDescriptionsFrom!="") { $descriptionsFile = @file($useDescriptionsFrom); if ($descriptionsFile!==false) { for ($i=0;$iread()) { // if the filename matches one of the hidden files wildcards, skip the file if (fileIsHidden($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["isDownloadable"] = (substr(strtolower($entry), -4)!=".php") || $allowPHPDownloads; $f["isDirectory"] = is_dir($entry); $fDate = @filemtime($entry); $f["date"] = $fDate; $f["fullDate"] = date("r", $fDate); $f["shortDate"] = date($snifDateFormat, $fDate); $f["description"] = getDescription($entry); if (is_dir($entry)) { $f["type"] = "<DIR>"; $f["size"] = ""; $f["nicesize"] = ""; // building the link if ($entry=="..") { $f["link"] = '..'; } else { $f["link"] = $entry; } } else { $fSize = @filesize($entry); $f["size"] = $fSize; $f["fullSize"] = number_format($fSize,0,".",","); $f["niceSize"] = nicesize($fSize); $pi = pathinfo($entry); $f["type"] = $pi["extension"]; if ($coralize) { $f["link"] = '?redir=' . urlencode($coralbase . $entry); $f['download'] = '?redir=' . urlencode($coralbase . '?download=' . $entry); } else { $f["link"] = myEncode($entry); $f['download'] = '?download=' . $entry; } } $f["filetype"] = getFileType($f["type"], is_dir($entry)); $f["icon"] = getIcon($f["filetype"]); $files[] = $f; } usort($files, "myCompare"); $pagingInEffect = $usePaging>0 && count($files)>$usePaging; if ($usePaging>0) { $pageStart = $_GET["start"]; if ($pageStart=="" || $pageStart<0 || $pageStart>count($files)) $pageStart = 0; $pagingActualPage = floor($pageStart / $usePaging); $pagingNumberOfPages = ceil(count($files) / $usePaging); } else { $pageStart = 0; $usePaging = count($files); } $pageEnd = min(count($files),$pageStart+$usePaging); $columns = 4; if ($useDescriptionsFrom!="") { $columns++; } //----------------------------------------------------------------------------- // Push data to smarty $s->assign('page_title', $baseurl.$uri); $s->assign('error', $displayError); $s->assign('columns', $columns); $s->assign('baseUrl', $baseurl); $s->assign('uri', $uri); $s->assign('path', $path); $s->assign('paging', $pagingInEffect); if ($pagingInEffect) { $s->assign('paging_header', getPagingHeader()); } if ($useDescriptionsFrom != "") { $s->assign('description', true); } if (file_exists($path.'index.txt')) { $s->assign('longDescription', join('',file($path.'index.txt'))); } $s->assign('order', $_GET['order']); $s->assign('sort', $_GET['sort']); $s->assign('sortName', getNewSortURL('name')); $s->assign('sortType', getNewSortURL('type')); $s->assign('sortSize', getNewSortURL('size')); $s->assign('sortDate', getNewSortURL('date')); $s->assign('files', $files); $s->assign('pageStart', $pageStart); $s->assign('pageEnd', $pageEnd); if ($_GET['order'] == 'asc') { $s->assign('orderImage', getIcon('asc')); } else { $s->assign('orderImage', getIcon('desc')); } $s->assign('downloadImage', getIcon('download')); $s->assign('thumbnails', $useAutoThumbnails); // Finally, display the template $s->display("snif.tpl"); ?>