1, 'include' => 1, 'include/smarty' => 1, 'include/smarty/templates' => 1, 'include/smarty/templates/apache' => 1, 'include/smarty/templates/viewsource' => 1, 'include/smarty/templates/codemonkey' => 1, 'openid' => 1, 'tvguide/html' => 1, '.' => 1, '/' => 1, ); if ($url != '/') { $path = '/'.$url; } else { $path = $url; } if (!file_exists($file)) { // Spoof Apache's 404 Page $apache = new apache(); $apache->path = $path; $apache->e404(); die; } if (!array_key_exists(dirname($url),$legal_dirs)) { // Spoof Apache's 403 Page $apache = new apache(); $apache->path = $path; $apache->e403(); die(); } if (!is_dir($file)) { $smarty = smarty_setup(); $smarty->caching = true; $smarty->cache_lifetime = 3600; $smarty->cache_modified_check = true; if ((time() - filemtime($file)) < 3600) { $smarty->clear_cache('viewsource/viewsource.tpl',$_SERVER['REQUEST_URI']); } //echo time() - filemtime($file); if (!$smarty->is_cached('viewsource/viewsource.tpl',$_SERVER['REQUEST_URI'])) { $source = file_get_contents($file); $source = highlight_string($source,true); $smarty->assign('path',$path); $smarty->assign('source',$source); $smarty->assign('serversig',$_SERVER['SERVER_SIGNATURE']); } $smarty->display('viewsource/viewsource.tpl',$_SERVER['REQUEST_URI']); } else { // Redirect to true location for directories if ($url != '/' && substr($file,(strlen($file) - 1),strlen($file)) != '/') { header("Location: ".$_SERVER['REQUEST_URI'].'/'); die(); } $apache = new apache(); $apache->func = 'directorylist'; $apache->cache = 0; $apache->cachetime = 3600; //if (!$apache->is_cached()) { // Spoof Apache's Directory List $scandir = scandir($file); $i = 0; foreach ($scandir as $f) { if ($f != '.' && $f != '..') { if (is_dir($file.$f)) { $list[$i] = array('icon'=>'folder','path'=>$f,'date'=>filemtime($file.$f)); if ($file.$f == $_SERVER['DOCUMENT_ROOT'].'index.php') { $list[$i]['name'] = 'index.php'; $list[$i]['path'] = 'index.php?file=/index.php'; } } else { $list[$i] = array('icon'=>'f','path'=>$f,'size'=>filesize($file.$f),'date'=>filemtime($file.$f)); } $i++; } } $apache->list = $list; //} $apache->path = $path; $apache->directorylist(); } // // Contents of apache.php: // directorylist(); * Used to spoof the default directory listing page from Apache, with your * own list from an array. * * Example: * $apache = new apache(); * $apache->list = array(); * $apache->path = $_SERVER['REQUEST_URI']; * $apache->directorylist(); * * $apache->list Syntax: * Array ( * [0] => Array ( * [path] => 'filename.html' * [date] => seconds since epoch, if null the present time is assumed * [name] => optional name spoof, will use name for readable text and path for the link * [icon] => which apache icon should we use? .gif extention is assumed. if icon is unset, f is assumed * ) * [1] => Array ( * [path] => 'index.php' * [date] => * [icon] => 'script' * ) * ) * * Caching: * Caching is provided with this class, presently with the directorylist * function only. There really seems no need to cache the 403 and 404 pages * considering they are rather simplistic. * It is assumed your PHP code uses mod_rewrite in some form, to redirect * all requests to your PHP script. Because of this, cache objects are * identified internally by $_SERVER['REQUEST_URI'] * * Caching Example: * $apache = new apache(); * $apache->cachetime = expiry time in seconds * $apache->cache = 1; * $apache->func = 'directorylist'; * if (!$apache->is_cached()) { * do complex stuff to generate a list * $apache->list = array(); * } * $apache->directorylist(); */ class apache { public $path = NULL; public $list = NULL; public $cache = 0; public $cachetime = 86400; public $func = NULL; // Global setup function function setvars() { if ($this->path == NULL) { $this->path = $_SERVER['REQUEST_URI']; } } // Generate a 404 Page function e404() { $this->setvars(); $smarty = smarty_setup(); $smarty->assign('path',$this->path); $smarty->assign('serversig',$_SERVER['SERVER_SIGNATURE']); header("HTTP/1.0 404 Not Found"); $smarty->display('apache/404.tpl'); } // Generate a 403 Page function e403() { $this->setvars(); $smarty = smarty_setup(); $smarty->assign('path',$this->path); $smarty->assign('serversig',$_SERVER['SERVER_SIGNATURE']); header("HTTP/1.0 403 Forbidden"); $smarty->display('apache/403.tpl'); } // Generate a Directory List function directorylist() { $this->setvars(); $smarty = smarty_setup(); // Caching enabled? if ($this->cache == 1) { $smarty->cache_lifetime = $this->cachetime; $smarty->caching = true; } else { $smarty->caching = false; } /* Page cached? * * Utilizing caching here avoids some looping and is a performance benefit */ //if (!$smarty->is_cached('apache/directorylist.tpl',$_SERVER['REQUEST_URI'])) { if (is_array($this->list)) { // Convert sizes into readable values // This is a bit of performance bog, perhaps the OPTION // to do this outside the class and disable this function? // This really does need to exist tho, as 'off the shelf' // PHP has no human readable format and most use of this class // will use filesize() foreach ($this->list as $key => $row) { if (array_key_exists('size',$row)) { $this->list[$key]['size'] = size_readable($row['size']); } } $smarty->assign('list',$this->list); } $smarty->assign('path',$this->path); // TODO: fix parent link $data = split("/",$this->path); $parent = print_r($data,true); $smarty->assign('parent',$parent); $smarty->assign('serversig',$_SERVER['SERVER_SIGNATURE']); //} // Fetch page $smarty->display('apache/directorylist.tpl',$_SERVER['REQUEST_URI']); } function is_cached() { if ($this->func == NULL) { echo "Error: class apache->is_cached called, but apache->func is null

"; return 0; die(); } $smarty = smarty_setup(); $smarty->cache_lifetime = $this->cachetime; if ($smarty->is_cached('apache/'.$this->func.'.tpl',$_SERVER['REQUEST_URI'])) { return 1; } else { return 0; } } } // // Contents of smarty.php // template_dir = SMARTY_TEMPLATEDIR; $smarty->compile_dir = SMARTY_COMPILEDIR; $smarty->cache_dir = SMARTY_CACHEDIR; $smarty->config_dir = SMARTY_CONFIGDIR; return $smarty; } ?> // // Contents of filesystem.php //