# HG changeset patch # User Pascal Bellard # Date 1295604559 -3600 # Node ID 874e4034d260ba99a82f5926e4faec561d1c62bf # Parent 1414fab16d56aa8d940f38246818599e316e614a mirror-tools: add dir-generator.php diff -r 1414fab16d56 -r 874e4034d260 busybox/stuff/init --- a/busybox/stuff/init Fri Jan 21 01:21:30 2011 +0100 +++ b/busybox/stuff/init Fri Jan 21 11:09:19 2011 +0100 @@ -52,14 +52,12 @@ lvmsetup() { -if grep -q lvmroot= /proc/cmdline; then + grep -q lvmroot= /proc/cmdline || return 1 modprobe dm-mod vgscan --ignorelockingfailure vgchange -ay --ignorelockingfailure root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)" return 0 -fi -return 1 } load_raid() diff -r 1414fab16d56 -r 874e4034d260 mirror-tools/stuff/var/www/slitaz/mirror/dir-generator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mirror-tools/stuff/var/www/slitaz/mirror/dir-generator.php Fri Jan 21 11:09:19 2011 +0100 @@ -0,0 +1,425 @@ +, + * 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) { + 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"); +if ($slitaz_style) { + $fvalue = ""; + if (isset($_GET[f])) $fvalue = 'value="'.$_GET[f].'"'; + print << + + + Index of /$vpath + + + + + + + + + + + + + + +
+ + +
+ +
+

users.pngCommunity

+ +

Search

+ + +
+ +
+

About Mirror

+

Welcome to Open Source! +EOT; + if ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org") print <<ADS. +EOT; + print << +

.pngMirrors: +EOT; + $mirrors = array( + "switch.ch" => "http://mirror.switch.ch/ftp/mirror/slitaz/", + "gatech.edu" => "http://www.gtlib.gatech.edu/pub/slitaz/", + "tuxfamily.org" => "http://download.tuxfamily.org/slitaz/", + "lupaworld.com" => "http://mirror.lupaworld.com/slitaz/", + "ufpr.br" => "http://slitaz.c3sl.ufpr.br/", + "pina.si" => "ftp://ftp.pina.si/slitaz/", + "ibiblio.org" => "http://distro.ibiblio.org/pub/linux/distributions/slitaz/", + "vim.org" => "http://ftp.vim.org/ftp/os/Linux/distr/slitaz/", + "nedit.org" => "http://ftp.nedit.org/ftp/ftp/pub/os/Linux/distr/slitaz/", + "xemacs.org" => "http://ftp.ch.xemacs.org/ftp/pool/2/mirror/slitaz/", + "garr.it" => "http://slitaz.mirror.garr.it/mirrors/slitaz/", + ); + foreach($mirrors as $name => $url) { + echo "$name\n"; + } + print << + +

+ +
+ +EOT; +} +else { + +// Print the heading stuff +print " + + + + Index of /" .$vpath. " +"; +if ($external_css != '') { +print " +"; +} +else { +print " +"; +} +print " + +

Index of /" . $vpath ."

+"; +} + +print "
+ +"; + + + +// Get all of the folders and files. +$folderlist = array(); +$filelist = array(); +if($handle = @opendir($path)) { + while(($item = readdir($handle)) !== false) { + if ($item == "index.php") continue; + if ($item == "dir-generator.php") continue; + if (isset($_GET['f'])) { + $filter = $_GET['f']; + if (substr($filter,0,1) != '/') + $filter = '/'.$filter.'/i'; + if (!preg_match($filter,$item)) continue; + } + if(is_dir($path.'/'.$item) and $item != '.' and $item != '..') { + $folderlist[] = array( + 'name' => $item, + 'size' => 0, + 'modtime'=> filemtime($path.'/'.$item), + 'file_type' => "Directory" + ); + } + elseif(is_file($path.'/'.$item)) { + if(!$show_hidden_files) { + if(substr($item, 0, 1) == "." or substr($item, -1) == "~") { + continue; + } + } + $filelist[] = array( + 'name'=> $item, + 'size'=> filesize($path.'/'.$item), + 'modtime'=> filemtime($path.'/'.$item), + 'file_type' => get_file_type($path.'/'.$item) + ); + } + } + closedir($handle); +} + + +if(!isset($_GET['s'])) { + $_GET['s'] = 'name'; +} + +// Figure out what to sort files by +$file_order_by = array(); +foreach ($filelist as $key=>$row) { + $file_order_by[$key] = $row[$_GET['s']]; +} + +// Figure out what to sort folders by +$folder_order_by = array(); +foreach ($folderlist as $key=>$row) { + $folder_order_by[$key] = $row[$_GET['s']]; +} + +// Order the files and folders +$sort_type = SORT_ASC; +$order = "&o=d"; +if(isset($_GET['o'])) { + $sort_type = SORT_DESC; + $order = ""; +} +array_multisort($folder_order_by, $sort_type, $folderlist); +array_multisort($file_order_by, $sort_type, $filelist); + + +// Show sort methods +print ""; + +$sort_methods = array(); +$sort_methods['name'] = "Name"; +$sort_methods['modtime'] = "Last Modified"; +$sort_methods['size'] = "Size"; +$sort_methods['file_type'] = "Type"; + +foreach($sort_methods as $key=>$item) { + if ($_GET['s'] == $key) $key = "$key$order"; + print ""; +} +print "\n\n"; + + + +// Parent directory link +if($path != "./") { + print ""; + print ""; + print ""; + print "\n"; +} + + + +// Print folder information +foreach($folderlist as $folder) { + print ""; + print ""; + print ""; + print "\n"; +} + + +// Print file information +foreach($filelist as $file) { + print ""; + print ""; + print ""; + print "\n"; +} + +// Print ending stuff +$soft = explode('/',$_SERVER["SERVER_SOFTWARE"]); +$tag = get_conf('server.tag','"','"',$soft[0].' <'.$soft[1].'>'); +print " +
$item
Parent Directory/ -  Directory
" .htmlentities($folder['name']). "/" . date('Y-M-d H:m:s', $folder['modtime']) . "-  " . $folder['file_type'] . "
" .htmlentities($file['name']). "" . date('Y-M-d H:m:s', $file['modtime']) . "" . format_bytes($file['size']) . "" . $file['file_type'] . "
+
"; +if ($slitaz_style) { ?> + + +
+ + + + + +
".$tag." + + +
+ +"; +print " + "; +?>