wok rev 8066

mirror-tools: add dir-generator.php
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 21 11:09:19 2011 +0100 (2011-01-21)
parents 1414fab16d56
children 6810b116924d
files busybox/stuff/init mirror-tools/stuff/var/www/slitaz/mirror/dir-generator.php
line diff
     1.1 --- a/busybox/stuff/init	Fri Jan 21 01:21:30 2011 +0100
     1.2 +++ b/busybox/stuff/init	Fri Jan 21 11:09:19 2011 +0100
     1.3 @@ -52,14 +52,12 @@
     1.4  
     1.5  lvmsetup()
     1.6  {
     1.7 -if grep -q lvmroot= /proc/cmdline; then
     1.8 +	grep -q lvmroot= /proc/cmdline || return 1
     1.9  	modprobe dm-mod
    1.10  	vgscan --ignorelockingfailure
    1.11  	vgchange -ay --ignorelockingfailure
    1.12  	root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
    1.13  	return 0
    1.14 -fi
    1.15 -return 1
    1.16  }
    1.17  
    1.18  load_raid()
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/mirror-tools/stuff/var/www/slitaz/mirror/dir-generator.php	Fri Jan 21 11:09:19 2011 +0100
     2.3 @@ -0,0 +1,425 @@
     2.4 +<?php
     2.5 +
     2.6 +$VERSION = "0.2-slitaz";
     2.7 +
     2.8 +/*  Lighttpd Enhanced Directory Listing Script
     2.9 + *  ------------------------------------------
    2.10 + *  Authors: Evan Fosmark   <me@evanfosmark.com>,
    2.11 + *           Pascal Bellard <pascal.bellard@slitaz.org>
    2.12 + *           Christophe Lincoln <pankso@slitaz.org>
    2.13 + *
    2.14 + *
    2.15 + *  GNU License Agreement
    2.16 + *  ---------------------
    2.17 + *  This program is free software; you can redistribute it and/or modify
    2.18 + *  it under the terms of the GNU General Public License as published by
    2.19 + *  the Free Software Foundation; either version 2 of the License, or
    2.20 + *  (at your option) any later version.
    2.21 + *
    2.22 + *  This program is distributed in the hope that it will be useful,
    2.23 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.24 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.25 + *  GNU General Public License for more details.
    2.26 + *
    2.27 + *  You should have received a copy of the GNU General Public License
    2.28 + *  along with this program; if not, write to the Free Software
    2.29 + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.30 + *
    2.31 + *  http://www.gnu.org/licenses/gpl.txt
    2.32 + */
    2.33 + 
    2.34 +// Get the path (cut out the query string from the request_uri)
    2.35 +list($path) = explode('?', $_SERVER['REQUEST_URI']);
    2.36 +
    2.37 +
    2.38 +// Get the path that we're supposed to show.
    2.39 +$path = ltrim(rawurldecode($path), '/');
    2.40 +
    2.41 +
    2.42 +if(strlen($path) == 0) {
    2.43 +	$path = "./";
    2.44 +}
    2.45 +
    2.46 +
    2.47 +// Can't call the script directly since REQUEST_URI won't be a directory
    2.48 +if($_SERVER['PHP_SELF'] == '/'.$path) {
    2.49 +	die("Unable to call " . $path . " directly.");
    2.50 +}
    2.51 +
    2.52 +
    2.53 +$vpath = ($path != "./")?$path:"";
    2.54 +// Make sure it is valid.
    2.55 +if(!is_dir($path)) {
    2.56 +//	die("<b>" . $path . "</b> is not a valid path.");
    2.57 +	$path = dirname($_SERVER["SCRIPT_FILENAME"]);
    2.58 +	list($vpath) = explode('?', $_SERVER['REQUEST_URI']);
    2.59 +	$vpath = ltrim(rawurldecode($vpath), '/');
    2.60 +}
    2.61 +
    2.62 +
    2.63 +//
    2.64 +// This function returns the file size of a specified $file.
    2.65 +//
    2.66 +function format_bytes($size, $precision=1) {
    2.67 +    $sizes = array('Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'K', '');
    2.68 +    $total = count($sizes);
    2.69 +
    2.70 +    while($total-- && $size > 1024) $size /= 1024;
    2.71 +    if ($sizes[$total] == '') {
    2.72 +    	$size /= 1024;
    2.73 +    	$total--;
    2.74 +    }
    2.75 +    return sprintf('%.'.$precision.'f', $size).$sizes[$total];
    2.76 +}
    2.77 +
    2.78 +
    2.79 +//
    2.80 +// Get some variables from /etc/lighttpd/lighttpd.conf
    2.81 +//
    2.82 +$conf_lightty = file_get_contents("/etc/lighttpd/lighttpd.conf");
    2.83 +
    2.84 +function get_conf($var,$start,$stop,$default='') {
    2.85 +    global $conf_lightty;
    2.86 +
    2.87 +    if (!preg_match('/'.$var.'/',$conf_lightty)) return $default;
    2.88 +    $filter = '/(.*\n)*'.$var.'\s*=\s*'.$start.'(([^'.$stop.']*\n*)*)'.$stop.'(.*\n)*/';
    2.89 +    return preg_replace($filter,'$2',$conf_lightty);
    2.90 +}
    2.91 +
    2.92 +$encoding = get_conf('dir-listing.encoding','"','"','ascii');
    2.93 +$external_css = get_conf('dir-listing.external-css','"','"');
    2.94 +
    2.95 +$show_hidden_files = false;
    2.96 +if (get_conf('dir-listing.hide-dotfile','"','"','disable') == "disable") {
    2.97 +	$show_hidden_files = true;
    2.98 +}
    2.99 +// get_conf('dir-listing.exclude','\(','\)');
   2.100 +// get_conf('dir-listing.set-footer','"','"');
   2.101 +
   2.102 +$mime_types = array();
   2.103 +foreach (explode(',',get_conf('mimetype.assign','\(','\)')) as $item) {
   2.104 +	$filter = '/\s*"(.*)"\s*=>\s*"(.*)".*/';
   2.105 +	$val = explode(',',preg_replace($filter,'$1,$2',$item));
   2.106 +	if (isset($val[1])) $mime_types[$val[0]] = $val[1];
   2.107 +}
   2.108 +
   2.109 +//
   2.110 +// This function returns the mime type of $file.
   2.111 +//
   2.112 +function get_file_type($file) {
   2.113 +	global $mime_types;
   2.114 +	
   2.115 +	$file = basename($file);
   2.116 +	$default_type = "application/octet-stream";
   2.117 +	if (isset($mime_types[$file])) {
   2.118 +		return $mime_types[$file];
   2.119 +	}
   2.120 +	$pos = strrpos($file, ".");
   2.121 +	if ($pos === false) {
   2.122 +		return $default_type;
   2.123 +	}
   2.124 +//FIXME .tar.gz
   2.125 +	$ext = '.'.rtrim(substr($file, $pos+1), "~");
   2.126 +	if (isset($mime_types[$ext])) {
   2.127 +		return $mime_types[$ext];
   2.128 +	}
   2.129 +	return $default_type;
   2.130 +}
   2.131 +
   2.132 +//$slitaz_style = (dirname($_SERVER["PHP_SELF"]) == '/');
   2.133 +$slitaz_style = ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org");
   2.134 +if ($slitaz_style) {
   2.135 +	$fvalue = "";
   2.136 +	if (isset($_GET[f])) $fvalue = 'value="'.$_GET[f].'"';
   2.137 +	print <<<EOT
   2.138 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   2.139 +	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   2.140 +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
   2.141 +<head>
   2.142 +	<title>Index of /$vpath</title>
   2.143 +	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
   2.144 +	<meta name="description" content=">Index of /$vpath" />
   2.145 +	<meta name="robots" content="index, nofollow" />
   2.146 +	<meta name="author" content="SliTaz Contributors" />
   2.147 +	<link rel="shortcut icon" href="/css/favicon.ico" />
   2.148 +	<link rel="stylesheet" type="text/css" href="/css/slitaz.css" />
   2.149 +	<style type='text/css'>
   2.150 +		div.list { background-color: white; padding-bottom: 14px;}
   2.151 +		table {width: 100% ;}
   2.152 +		th, td { font: 90% monospace; text-align: left;}
   2.153 +		th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
   2.154 +		td {padding-right: 14px;}
   2.155 +		td.s, th.s {text-align: right;}
   2.156 +	</style>
   2.157 +</head>
   2.158 +<body>
   2.159 +
   2.160 +<!-- Header -->
   2.161 +<div id="header">
   2.162 +	<a href="http://mirror.slitaz.org/"><img id="logo" 
   2.163 +		src="/css/pics/website/logo.png" 
   2.164 +		title="mirror.slitaz.org" alt="mirror.slitaz.org" /></a>
   2.165 +	<p id="titre">#!/Mirror/${vpath}</p>
   2.166 +</div>
   2.167 +
   2.168 +<!-- Content -->
   2.169 +<div id="content-full">
   2.170 +
   2.171 +<!-- Block begin -->
   2.172 +<div class="block">
   2.173 +	<!-- Nav block begin -->
   2.174 +	<div id="block_nav">
   2.175 +		<h3><img src="/css/pics/website/users.png" alt="users.png" />Community</h3>
   2.176 +		<ul>
   2.177 +			<li><a href="http://pizza.slitaz.org/">Live Builder</a></li>
   2.178 +			<li><a href="http://boot.slitaz.org/">Web Boot</a></li>
   2.179 +		</ul>
   2.180 +		<h3>Search</h3>
   2.181 +		<form class="search" action="${_SERVER["REQUEST_URI"]}" method="get" >
   2.182 +			<p><input type="text" name="f" $fvalue /></p>
   2.183 +		</form>
   2.184 +	<!-- Nav block end -->
   2.185 +	</div>
   2.186 +	<!-- Top block begin -->
   2.187 +	<div id="block_top">
   2.188 +		<h1>About Mirror</h1>
   2.189 +		<p>Welcome to Open Source!
   2.190 +EOT;
   2.191 +	if ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org") print <<<EOT
   2.192 +		This is the SliTaz GNU/Linux main mirror. The server runs naturally SliTaz 
   2.193 +		(stable) in an lguest virtual machine provided by 
   2.194 +		<a href="http://www.ads-lu.com/">ADS</a>.	
   2.195 +EOT;
   2.196 +	print <<<EOT
   2.197 +		</p>
   2.198 +		<p><img src="/css/pics/website/network.png" 
   2.199 +			alt=".png" style="vertical-align:middle;"/>Mirrors: 
   2.200 +EOT;
   2.201 +	$mirrors = array(
   2.202 +	"switch.ch"     => "http://mirror.switch.ch/ftp/mirror/slitaz/",
   2.203 +	"gatech.edu"    => "http://www.gtlib.gatech.edu/pub/slitaz/",
   2.204 +	"tuxfamily.org" => "http://download.tuxfamily.org/slitaz/",
   2.205 +	"lupaworld.com" => "http://mirror.lupaworld.com/slitaz/",
   2.206 +	"ufpr.br"       => "http://slitaz.c3sl.ufpr.br/",
   2.207 +	"pina.si"       => "ftp://ftp.pina.si/slitaz/",
   2.208 +	"ibiblio.org"   => "http://distro.ibiblio.org/pub/linux/distributions/slitaz/",
   2.209 +	"vim.org"       => "http://ftp.vim.org/ftp/os/Linux/distr/slitaz/",
   2.210 +	"nedit.org"     => "http://ftp.nedit.org/ftp/ftp/pub/os/Linux/distr/slitaz/",
   2.211 +	"xemacs.org"    => "http://ftp.ch.xemacs.org/ftp/pool/2/mirror/slitaz/",
   2.212 +	"garr.it"       => "http://slitaz.mirror.garr.it/mirrors/slitaz/",
   2.213 +	);
   2.214 +	foreach($mirrors as $name => $url) {
   2.215 +		echo "<a href=\"$url$vpath\" title=\"$name mirror\">$name</a>\n";
   2.216 +	}
   2.217 +	print <<<EOT
   2.218 +		</p>
   2.219 +	<!-- Top block end -->
   2.220 +	</div>
   2.221 +<!-- Block end -->
   2.222 +</div>
   2.223 +
   2.224 +EOT;
   2.225 +}
   2.226 +else {
   2.227 +
   2.228 +// Print the heading stuff
   2.229 +print "<?xml version='1.0' encoding='$encoding'?>
   2.230 +<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
   2.231 +<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
   2.232 +	<head>
   2.233 +		<title>Index of /" .$vpath. "</title>
   2.234 +";
   2.235 +if ($external_css != '') {
   2.236 +print "	<link rel='stylesheet' type='text/css' href='".$external_css."' />
   2.237 +";
   2.238 +}
   2.239 +else {
   2.240 +print " <style type='text/css'>
   2.241 +		a, a:active {text-decoration: none; color: blue;}
   2.242 +		a:visited {color: #48468F;}
   2.243 +		a:hover, a:focus {text-decoration: underline; color: red;}
   2.244 +		body {background-color: #F5F5F5;}
   2.245 +		h2 {margin-bottom: 12px;}
   2.246 +		table {margin-left: 12px;}
   2.247 +		th, td { font: 90% monospace; text-align: left;}
   2.248 +		th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
   2.249 +		td {padding-right: 14px;}
   2.250 +		td.s, th.s {text-align: right;}
   2.251 +		div.list { background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;}
   2.252 +		div.foot { font: 90% monospace; color: #787878; padding-top: 4px;}
   2.253 +		</style>
   2.254 +";
   2.255 +}
   2.256 +print "	</head>
   2.257 +	<boby>
   2.258 +	<h2>Index of /" . $vpath ."</h2>
   2.259 +";
   2.260 +}
   2.261 +
   2.262 +print "	<div class='list'>
   2.263 +	<table summary='Directory Listing' cellpadding='0' cellspacing='0'>
   2.264 +";
   2.265 +
   2.266 +
   2.267 +
   2.268 +// Get all of the folders and files. 
   2.269 +$folderlist = array();
   2.270 +$filelist = array();
   2.271 +if($handle = @opendir($path)) {
   2.272 +	while(($item = readdir($handle)) !== false) {
   2.273 +		if ($item == "index.php") continue;
   2.274 +		if ($item == "dir-generator.php") continue;
   2.275 +		if (isset($_GET['f'])) {
   2.276 +			$filter = $_GET['f'];
   2.277 +			if (substr($filter,0,1) != '/')
   2.278 +				$filter = '/'.$filter.'/i';
   2.279 +			if (!preg_match($filter,$item)) continue;
   2.280 +		}
   2.281 +		if(is_dir($path.'/'.$item) and $item != '.' and $item != '..') {
   2.282 +			$folderlist[] = array(
   2.283 +				'name' => $item, 
   2.284 +				'size' => 0, 
   2.285 +				'modtime'=> filemtime($path.'/'.$item),
   2.286 +				'file_type' => "Directory"
   2.287 +			);
   2.288 +		}
   2.289 +		elseif(is_file($path.'/'.$item)) {
   2.290 +			if(!$show_hidden_files) {
   2.291 +				if(substr($item, 0, 1) == "." or substr($item, -1) == "~") {
   2.292 +					continue;
   2.293 +				}
   2.294 +			}
   2.295 +			$filelist[] = array(
   2.296 +				'name'=> $item, 
   2.297 +				'size'=> filesize($path.'/'.$item), 
   2.298 +				'modtime'=> filemtime($path.'/'.$item),
   2.299 +				'file_type' => get_file_type($path.'/'.$item)
   2.300 +			);
   2.301 +		}
   2.302 +	}
   2.303 +	closedir($handle);
   2.304 +}
   2.305 +
   2.306 +
   2.307 +if(!isset($_GET['s'])) {
   2.308 +	$_GET['s'] = 'name';
   2.309 +}
   2.310 +
   2.311 +// Figure out what to sort files by
   2.312 +$file_order_by = array();
   2.313 +foreach ($filelist as $key=>$row) {
   2.314 +    $file_order_by[$key]  = $row[$_GET['s']];
   2.315 +}
   2.316 +
   2.317 +// Figure out what to sort folders by
   2.318 +$folder_order_by = array();
   2.319 +foreach ($folderlist as $key=>$row) {
   2.320 +    $folder_order_by[$key]  = $row[$_GET['s']];
   2.321 +}
   2.322 +
   2.323 +// Order the files and folders
   2.324 +$sort_type = SORT_ASC;
   2.325 +$order = "&amp;o=d";
   2.326 +if(isset($_GET['o'])) {
   2.327 +	$sort_type = SORT_DESC;
   2.328 +	$order = "";
   2.329 +}
   2.330 +array_multisort($folder_order_by, $sort_type, $folderlist);
   2.331 +array_multisort($file_order_by, $sort_type, $filelist);
   2.332 +
   2.333 +
   2.334 +// Show sort methods
   2.335 +print "<thead><tr>";
   2.336 +
   2.337 +$sort_methods = array();
   2.338 +$sort_methods['name'] = "Name";
   2.339 +$sort_methods['modtime'] = "Last Modified";
   2.340 +$sort_methods['size'] = "Size";
   2.341 +$sort_methods['file_type'] = "Type";
   2.342 +
   2.343 +foreach($sort_methods as $key=>$item) {
   2.344 +	if ($_GET['s'] == $key) $key = "$key$order";
   2.345 +	print "<th class='n'><a href='?s=$key'>$item</a></th>";
   2.346 +}
   2.347 +print "</tr></thead>\n<tbody>\n";
   2.348 +
   2.349 +
   2.350 +
   2.351 +// Parent directory link
   2.352 +if($path != "./") {
   2.353 +	print "<tr><td class='n'><a href='..'>Parent Directory</a>/</td>";
   2.354 +	print "<td class='m'>&nbsp;</td>";
   2.355 +	print "<td class='s'>- &nbsp;</td>";
   2.356 +	print "<td class='t'>Directory</td></tr>\n";
   2.357 +}
   2.358 +
   2.359 +
   2.360 +
   2.361 +// Print folder information
   2.362 +foreach($folderlist as $folder) {
   2.363 +	print "<tr><td class='n'><a href='" . addslashes($folder['name']). "'>" .htmlentities($folder['name']). "</a>/</td>";
   2.364 +	print "<td class='m'>" . date('Y-M-d H:m:s', $folder['modtime']) . "</td>";
   2.365 +	print "<td class='s'>- &nbsp;</td>";
   2.366 +	print "<td class='t'>" . $folder['file_type']                    . "</td></tr>\n";
   2.367 +}
   2.368 +
   2.369 +
   2.370 +// Print file information
   2.371 +foreach($filelist as $file) {
   2.372 +	print "<tr><td class='n'><a href='" . addslashes($file['name']). "'>" .htmlentities($file['name']). "</a></td>";
   2.373 +	print "<td class='m'>" . date('Y-M-d H:m:s', $file['modtime'])   . "</td>";
   2.374 +	print "<td class='s'>" . format_bytes($file['size'])           . "</td>";
   2.375 +	print "<td class='t'>" . $file['file_type']                      . "</td></tr>\n";
   2.376 +}
   2.377 +
   2.378 +// Print ending stuff
   2.379 +$soft = explode('/',$_SERVER["SERVER_SOFTWARE"]);
   2.380 +$tag = get_conf('server.tag','"','"',$soft[0].' &lt;'.$soft[1].'&gt;');
   2.381 +print "</tbody>
   2.382 +	</table>
   2.383 +	</div>";
   2.384 +if ($slitaz_style) { ?>
   2.385 +
   2.386 +<!-- End of content -->
   2.387 +</div>
   2.388 +
   2.389 +<!-- Footer -->
   2.390 +<div id="footer">
   2.391 +	<div class="right_box">
   2.392 +	<h4>SliTaz Network</h4>
   2.393 +		<ul>
   2.394 +			<li><a href="http://www.slitaz.org/">Main Website</a></li>
   2.395 +			<li><a href="http://doc.slitaz.org/">Documentation</a></li>
   2.396 +			<li><a href="http://forum.slitaz.org/">Support Forum</a></li>
   2.397 +			<li><a href="http://scn.slitaz.org/">Community Network</a></li>
   2.398 +			<li><a href="http://pkgs.slitaz.org/">Packages</a></li>
   2.399 +			<li><a href="http://labs.slitaz.org/">Laboratories</a></li>
   2.400 +		</ul>
   2.401 +	</div>
   2.402 +	<h4>SliTaz Website</h4>
   2.403 +	<ul>
   2.404 +		<li><a href="#header">Top of the page</a></li>
   2.405 +		<li>Copyright &copy; <span class="year"></span>
   2.406 +			<a href="http://www.slitaz.org/">SliTaz</a></li>
   2.407 +		<li><a href="about/">About the project</a></li>
   2.408 +		<li><a href="netmap.php">Network Map</a></li>
   2.409 +		<li>Page modified the <?php echo date('r'); ?></li>
   2.410 +		<li><a href="http://validator.w3.org/check?uri=referer"><img
   2.411 +		src="pics/website/xhtml10.png" alt="Valid XHTML 1.0"
   2.412 +		title="Code validé XHTML 1.0"
   2.413 +		style="width: 80px; height: 15px; vertical-align: middle;" /></a></li>
   2.414 +	</ul>
   2.415 +</div>
   2.416 +
   2.417 +<?php }
   2.418 +else print "
   2.419 +	<form action='".$_SERVER["REQUEST_URI"]."' method='get'>
   2.420 +	<div class='foot'>".$tag."
   2.421 +		<input type='text' name='f'/>
   2.422 +		<!-- <input type='submit' value='Filter' /> -->
   2.423 +	</div>
   2.424 +	</form>
   2.425 +";
   2.426 +print "</body>
   2.427 +	</html>";
   2.428 +?>