,
* Pascal Bellard
* Christophe Lincoln
*
*
* GNU License Agreement
* ---------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* http://www.gnu.org/licenses/gpl.txt
*/
// Get the path (cut out the query string from the request_uri)
list($path) = explode('?', $_SERVER['REQUEST_URI']);
// Get the path that we're supposed to show.
$path = ltrim(rawurldecode($path), '/');
if(strlen($path) == 0) {
$path = "./";
}
// Can't call the script directly since REQUEST_URI won't be a directory
if($_SERVER['PHP_SELF'] == '/'.$path) {
redirect();
// die("Unable to call " . $path . " directly.");
}
$vpath = ($path != "./")?$path:"";
// Make sure it is valid.
if(!is_dir($path)) {
// die("" . $path . " is not a valid path.");
$path = dirname($_SERVER["SCRIPT_FILENAME"]);
list($vpath) = explode('?', $_SERVER['REQUEST_URI']);
$vpath = ltrim(rawurldecode($vpath), '/');
}
//
// This function returns the file size of a specified $file.
//
function format_bytes($size, $precision=1) {
$sizes = array('Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'K', '');
$total = count($sizes);
while($total-- && $size > 1024) $size /= 1024;
if ($sizes[$total] == '') {
$size /= 1024;
$total--;
}
return sprintf('%.'.$precision.'f', $size).$sizes[$total];
}
//
// Get some variables from /etc/lighttpd/lighttpd.conf
//
$conf_lightty = file_get_contents("/etc/lighttpd/lighttpd.conf");
function get_conf($var,$start,$stop,$default='') {
global $conf_lightty;
if (!preg_match('/'.$var.'/',$conf_lightty)) return $default;
$filter = '/(.*\n)*'.$var.'\s*=\s*'.$start.'(([^'.$stop.']*\n*)*)'.$stop.'(.*\n)*/';
return preg_replace($filter,'$2',$conf_lightty);
}
$encoding = get_conf('dir-listing.encoding','"','"','ascii');
$external_css = get_conf('dir-listing.external-css','"','"');
$show_hidden_files = false;
if (get_conf('dir-listing.hide-dotfile','"','"','disable') == "disable") {
$show_hidden_files = true;
}
// get_conf('dir-listing.exclude','\(','\)');
// get_conf('dir-listing.set-footer','"','"');
$mime_types = array();
foreach (explode(',',get_conf('mimetype.assign','\(','\)')) as $item) {
$filter = '/\s*"(.*)"\s*=>\s*"(.*)".*/';
$val = explode(',',preg_replace($filter,'$1,$2',$item));
if (isset($val[1])) $mime_types[$val[0]] = $val[1];
}
//
// This function returns the mime type of $file.
//
function get_file_type($file) {
global $mime_types;
$file = basename($file);
$default_type = "application/octet-stream";
if (isset($mime_types[$file])) {
return $mime_types[$file];
}
$pos = strrpos($file, ".");
if ($pos === false) {
return $default_type;
}
//FIXME .tar.gz
$ext = '.'.rtrim(substr($file, $pos+1), "~");
if (isset($mime_types[$ext])) {
return $mime_types[$ext];
}
return $default_type;
}
//$slitaz_style = (dirname($_SERVER["PHP_SELF"]) == '/');
//$slitaz_style = ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org");
$slitaz_style = preg_match("/mirror\.slitaz\./",$_SERVER["SERVER_NAME"]);
if ($slitaz_style) {
$fvalue = "";
if (isset($_GET['f'])) $fvalue = 'value="'.$_GET['f'].'"';
print <<Index of /$vpath
EOT;
if (preg_match("/mirror\.slitaz\./",$_SERVER["SERVER_NAME"])) print <<This is the SliTaz GNU/Linux main mirror. The server runs naturally
SliTaz (stable) in an lguest virtual machine provided by
ADS and is located in France.
Mirror info...
EOT;
print <<