slitaz-dev-tools diff mirror-tools/slitaz/mirror/dir-generator.php @ rev 10
Add mirror-tools/slitaz folder.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Thu Feb 24 02:26:10 2011 +0000 (2011-02-24) |
parents | |
children | c9f517d25721 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mirror-tools/slitaz/mirror/dir-generator.php Thu Feb 24 02:26:10 2011 +0000 1.3 @@ -0,0 +1,442 @@ 1.4 +<?php 1.5 +function redirect() 1.6 +{ 1.7 +?> 1.8 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 1.9 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1.10 +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"> 1.11 +<head> 1.12 + <title>SliTaz mirror redirection</title> 1.13 + <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 1.14 + <meta name="description" content="slitaz mirror redirection" /> 1.15 + <meta name="robots" content="index, nofollow" /> 1.16 + <meta name="author" content="SliTaz Contributors" /> 1.17 + <meta http-equiv="Refresh" content="0;url=http://mirror.slitaz.org/"> 1.18 +</head> 1.19 +<?php 1.20 +} 1.21 + 1.22 +$VERSION = "0.2-slitaz"; 1.23 + 1.24 +/* Lighttpd Enhanced Directory Listing Script 1.25 + * ------------------------------------------ 1.26 + * Authors: Evan Fosmark <me@evanfosmark.com>, 1.27 + * Pascal Bellard <pascal.bellard@slitaz.org> 1.28 + * Christophe Lincoln <pankso@slitaz.org> 1.29 + * 1.30 + * 1.31 + * GNU License Agreement 1.32 + * --------------------- 1.33 + * This program is free software; you can redistribute it and/or modify 1.34 + * it under the terms of the GNU General Public License as published by 1.35 + * the Free Software Foundation; either version 2 of the License, or 1.36 + * (at your option) any later version. 1.37 + * 1.38 + * This program is distributed in the hope that it will be useful, 1.39 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.40 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.41 + * GNU General Public License for more details. 1.42 + * 1.43 + * You should have received a copy of the GNU General Public License 1.44 + * along with this program; if not, write to the Free Software 1.45 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1.46 + * 1.47 + * http://www.gnu.org/licenses/gpl.txt 1.48 + */ 1.49 + 1.50 +// Get the path (cut out the query string from the request_uri) 1.51 +list($path) = explode('?', $_SERVER['REQUEST_URI']); 1.52 + 1.53 + 1.54 +// Get the path that we're supposed to show. 1.55 +$path = ltrim(rawurldecode($path), '/'); 1.56 + 1.57 + 1.58 +if(strlen($path) == 0) { 1.59 + $path = "./"; 1.60 +} 1.61 + 1.62 + 1.63 +// Can't call the script directly since REQUEST_URI won't be a directory 1.64 +if($_SERVER['PHP_SELF'] == '/'.$path) { 1.65 + redirect(); 1.66 +// die("Unable to call " . $path . " directly."); 1.67 +} 1.68 + 1.69 + 1.70 +$vpath = ($path != "./")?$path:""; 1.71 +// Make sure it is valid. 1.72 +if(!is_dir($path)) { 1.73 +// die("<b>" . $path . "</b> is not a valid path."); 1.74 + $path = dirname($_SERVER["SCRIPT_FILENAME"]); 1.75 + list($vpath) = explode('?', $_SERVER['REQUEST_URI']); 1.76 + $vpath = ltrim(rawurldecode($vpath), '/'); 1.77 +} 1.78 + 1.79 + 1.80 +// 1.81 +// This function returns the file size of a specified $file. 1.82 +// 1.83 +function format_bytes($size, $precision=1) { 1.84 + $sizes = array('Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'K', ''); 1.85 + $total = count($sizes); 1.86 + 1.87 + while($total-- && $size > 1024) $size /= 1024; 1.88 + if ($sizes[$total] == '') { 1.89 + $size /= 1024; 1.90 + $total--; 1.91 + } 1.92 + return sprintf('%.'.$precision.'f', $size).$sizes[$total]; 1.93 +} 1.94 + 1.95 + 1.96 +// 1.97 +// Get some variables from /etc/lighttpd/lighttpd.conf 1.98 +// 1.99 +$conf_lightty = file_get_contents("/etc/lighttpd/lighttpd.conf"); 1.100 + 1.101 +function get_conf($var,$start,$stop,$default='') { 1.102 + global $conf_lightty; 1.103 + 1.104 + if (!preg_match('/'.$var.'/',$conf_lightty)) return $default; 1.105 + $filter = '/(.*\n)*'.$var.'\s*=\s*'.$start.'(([^'.$stop.']*\n*)*)'.$stop.'(.*\n)*/'; 1.106 + return preg_replace($filter,'$2',$conf_lightty); 1.107 +} 1.108 + 1.109 +$encoding = get_conf('dir-listing.encoding','"','"','ascii'); 1.110 +$external_css = get_conf('dir-listing.external-css','"','"'); 1.111 + 1.112 +$show_hidden_files = false; 1.113 +if (get_conf('dir-listing.hide-dotfile','"','"','disable') == "disable") { 1.114 + $show_hidden_files = true; 1.115 +} 1.116 +// get_conf('dir-listing.exclude','\(','\)'); 1.117 +// get_conf('dir-listing.set-footer','"','"'); 1.118 + 1.119 +$mime_types = array(); 1.120 +foreach (explode(',',get_conf('mimetype.assign','\(','\)')) as $item) { 1.121 + $filter = '/\s*"(.*)"\s*=>\s*"(.*)".*/'; 1.122 + $val = explode(',',preg_replace($filter,'$1,$2',$item)); 1.123 + if (isset($val[1])) $mime_types[$val[0]] = $val[1]; 1.124 +} 1.125 + 1.126 +// 1.127 +// This function returns the mime type of $file. 1.128 +// 1.129 +function get_file_type($file) { 1.130 + global $mime_types; 1.131 + 1.132 + $file = basename($file); 1.133 + $default_type = "application/octet-stream"; 1.134 + if (isset($mime_types[$file])) { 1.135 + return $mime_types[$file]; 1.136 + } 1.137 + $pos = strrpos($file, "."); 1.138 + if ($pos === false) { 1.139 + return $default_type; 1.140 + } 1.141 +//FIXME .tar.gz 1.142 + $ext = '.'.rtrim(substr($file, $pos+1), "~"); 1.143 + if (isset($mime_types[$ext])) { 1.144 + return $mime_types[$ext]; 1.145 + } 1.146 + return $default_type; 1.147 +} 1.148 + 1.149 +//$slitaz_style = (dirname($_SERVER["PHP_SELF"]) == '/'); 1.150 +$slitaz_style = ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org"); 1.151 +if ($slitaz_style) { 1.152 + $fvalue = ""; 1.153 + if (isset($_GET[f])) $fvalue = 'value="'.$_GET[f].'"'; 1.154 + print <<<EOT 1.155 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 1.156 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1.157 +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"> 1.158 +<head> 1.159 + <title>Index of /$vpath</title> 1.160 + <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 1.161 + <meta name="description" content=">Index of /$vpath" /> 1.162 + <meta name="robots" content="index, nofollow" /> 1.163 + <meta name="author" content="SliTaz Contributors" /> 1.164 + <link rel="shortcut icon" href="/css/favicon.ico" /> 1.165 + <link rel="stylesheet" type="text/css" href="/css/slitaz.css" /> 1.166 + <style type='text/css'> 1.167 + div.list { background-color: white; padding-bottom: 14px;} 1.168 + table {width: 100% ;} 1.169 + th, td { font: 90% monospace; text-align: left;} 1.170 + th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;} 1.171 + td {padding-right: 14px;} 1.172 + td.s, th.s {text-align: right;} 1.173 + </style> 1.174 +</head> 1.175 +<body> 1.176 + 1.177 +<!-- Header --> 1.178 +<div id="header"> 1.179 + <a href="http://mirror.slitaz.org/"><img id="logo" 1.180 + src="/css/pics/website/logo.png" 1.181 + title="mirror.slitaz.org" alt="mirror.slitaz.org" /></a> 1.182 + <p id="titre">#!/Mirror/${vpath}</p> 1.183 +</div> 1.184 + 1.185 +<!-- Content --> 1.186 +<div id="content-full"> 1.187 + 1.188 +<!-- Block begin --> 1.189 +<div class="block"> 1.190 + <!-- Nav block begin --> 1.191 + <div id="block_nav"> 1.192 + <h3><img src="/css/pics/website/users.png" alt="users.png" />Community</h3> 1.193 + <ul> 1.194 + <li><a href="http://pizza.slitaz.org/">Live Builder</a></li> 1.195 + <li><a href="http://boot.slitaz.org/">Web Boot</a></li> 1.196 + </ul> 1.197 + <h3>Search</h3> 1.198 + <form class="search" action="${_SERVER["REQUEST_URI"]}" method="get" > 1.199 + <p><input type="text" name="f" $fvalue /></p> 1.200 + </form> 1.201 + <!-- Nav block end --> 1.202 + </div> 1.203 + <!-- Top block begin --> 1.204 + <div id="block_top"> 1.205 + <h1>About Mirror</h1> 1.206 + <p>Welcome to Open Source! 1.207 +EOT; 1.208 + if ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org") print <<<EOT 1.209 + This is the SliTaz GNU/Linux main mirror. The server runs naturally SliTaz 1.210 + (stable) in an lguest virtual machine provided by 1.211 + <a href="http://www.ads-lu.com/">ADS</a>. 1.212 +EOT; 1.213 + print <<<EOT 1.214 + </p> 1.215 + <p><img src="/css/pics/website/network.png" 1.216 + alt=".png" style="vertical-align:middle;"/>Mirrors: 1.217 +EOT; 1.218 + $mirrors = array(); 1.219 + $fp = @fopen(dirname($_SERVER["SCRIPT_FILENAME"])."/mirrors","r"); 1.220 + if ($fp) { 1.221 + while (($line = fgets($fp)) !== false) { 1.222 + $line = chop($line); 1.223 + $url = parse_url($line); 1.224 + if ($_SERVER["SERVER_NAME"] == $url['host']) continue; 1.225 + $host = explode('.',$url['host']); 1.226 + $mirrors[$host[count($host)-2].".". 1.227 + $host[count($host)-1]] = $line; 1.228 + } 1.229 + } 1.230 + fclose($fp); 1.231 + foreach($mirrors as $name => $url) { 1.232 + echo "<a href=\"$url$vpath\" title=\"$name mirror\">$name</a>\n"; 1.233 + } 1.234 + print <<<EOT 1.235 + </p> 1.236 + <!-- Top block end --> 1.237 + </div> 1.238 +<!-- Block end --> 1.239 +</div> 1.240 + 1.241 +EOT; 1.242 +} 1.243 +else { 1.244 + 1.245 +// Print the heading stuff 1.246 +print "<?xml version='1.0' encoding='$encoding'?> 1.247 +<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'> 1.248 +<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> 1.249 + <head> 1.250 + <title>Index of /" .$vpath. "</title> 1.251 +"; 1.252 +if ($external_css != '') { 1.253 +print " <link rel='stylesheet' type='text/css' href='".$external_css."' /> 1.254 +"; 1.255 +} 1.256 +else { 1.257 +print " <style type='text/css'> 1.258 + a, a:active {text-decoration: none; color: blue;} 1.259 + a:visited {color: #48468F;} 1.260 + a:hover, a:focus {text-decoration: underline; color: red;} 1.261 + body {background-color: #F5F5F5;} 1.262 + h2 {margin-bottom: 12px;} 1.263 + table {margin-left: 12px;} 1.264 + th, td { font: 90% monospace; text-align: left;} 1.265 + th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;} 1.266 + td {padding-right: 14px;} 1.267 + td.s, th.s {text-align: right;} 1.268 + div.list { background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;} 1.269 + div.foot { font: 90% monospace; color: #787878; padding-top: 4px;} 1.270 + </style> 1.271 +"; 1.272 +} 1.273 +print " </head> 1.274 + <boby> 1.275 + <h2>Index of /" . $vpath ."</h2> 1.276 +"; 1.277 +} 1.278 + 1.279 +print " <div class='list'> 1.280 + <table summary='Directory Listing' cellpadding='0' cellspacing='0'> 1.281 +"; 1.282 + 1.283 + 1.284 + 1.285 +// Get all of the folders and files. 1.286 +$folderlist = array(); 1.287 +$filelist = array(); 1.288 +if($handle = @opendir($path)) { 1.289 + while(($item = readdir($handle)) !== false) { 1.290 + if ($item == "index.php") continue; 1.291 + if ($item == "dir-generator.php") continue; 1.292 + if (isset($_GET['f'])) { 1.293 + $filter = $_GET['f']; 1.294 + if (substr($filter,0,1) != '/') 1.295 + $filter = '/'.$filter.'/i'; 1.296 + if (!preg_match($filter,$item)) continue; 1.297 + } 1.298 + if(is_dir($path.'/'.$item) and $item != '.' and $item != '..') { 1.299 + $folderlist[] = array( 1.300 + 'name' => $item, 1.301 + 'size' => 0, 1.302 + 'modtime'=> filemtime($path.'/'.$item), 1.303 + 'file_type' => "Directory" 1.304 + ); 1.305 + } 1.306 + elseif(is_file($path.'/'.$item)) { 1.307 + if(!$show_hidden_files) { 1.308 + if(substr($item, 0, 1) == "." or substr($item, -1) == "~") { 1.309 + continue; 1.310 + } 1.311 + } 1.312 + $filelist[] = array( 1.313 + 'name'=> $item, 1.314 + 'size'=> filesize($path.'/'.$item), 1.315 + 'modtime'=> filemtime($path.'/'.$item), 1.316 + 'file_type' => get_file_type($path.'/'.$item) 1.317 + ); 1.318 + } 1.319 + } 1.320 + closedir($handle); 1.321 +} 1.322 + 1.323 + 1.324 +if(!isset($_GET['s'])) { 1.325 + $_GET['s'] = 'name'; 1.326 +} 1.327 + 1.328 +// Figure out what to sort files by 1.329 +$file_order_by = array(); 1.330 +foreach ($filelist as $key=>$row) { 1.331 + $file_order_by[$key] = $row[$_GET['s']]; 1.332 +} 1.333 + 1.334 +// Figure out what to sort folders by 1.335 +$folder_order_by = array(); 1.336 +foreach ($folderlist as $key=>$row) { 1.337 + $folder_order_by[$key] = $row[$_GET['s']]; 1.338 +} 1.339 + 1.340 +// Order the files and folders 1.341 +$sort_type = SORT_ASC; 1.342 +$order = "&o=d"; 1.343 +if(isset($_GET['o'])) { 1.344 + $sort_type = SORT_DESC; 1.345 + $order = ""; 1.346 +} 1.347 +array_multisort($folder_order_by, $sort_type, $folderlist); 1.348 +array_multisort($file_order_by, $sort_type, $filelist); 1.349 + 1.350 + 1.351 +// Show sort methods 1.352 +print "<thead><tr>"; 1.353 + 1.354 +$sort_methods = array(); 1.355 +$sort_methods['name'] = "Name"; 1.356 +$sort_methods['modtime'] = "Last Modified"; 1.357 +$sort_methods['size'] = "Size"; 1.358 +$sort_methods['file_type'] = "Type"; 1.359 + 1.360 +foreach($sort_methods as $key=>$item) { 1.361 + if ($_GET['s'] == $key) $key = "$key$order"; 1.362 + print "<th class='n'><a href='?s=$key'>$item</a></th>"; 1.363 +} 1.364 +print "</tr></thead>\n<tbody>\n"; 1.365 + 1.366 + 1.367 + 1.368 +// Parent directory link 1.369 +if($path != "./") { 1.370 + print "<tr><td class='n'><a href='..'>Parent Directory</a>/</td>"; 1.371 + print "<td class='m'> </td>"; 1.372 + print "<td class='s'>- </td>"; 1.373 + print "<td class='t'>Directory</td></tr>\n"; 1.374 +} 1.375 + 1.376 + 1.377 + 1.378 +// Print folder information 1.379 +foreach($folderlist as $folder) { 1.380 + print "<tr><td class='n'><a href='" . addslashes($folder['name']). "'>" .htmlentities($folder['name']). "</a>/</td>"; 1.381 + print "<td class='m'>" . date('Y-M-d H:m:s', $folder['modtime']) . "</td>"; 1.382 + print "<td class='s'>- </td>"; 1.383 + print "<td class='t'>" . $folder['file_type'] . "</td></tr>\n"; 1.384 +} 1.385 + 1.386 + 1.387 +// Print file information 1.388 +foreach($filelist as $file) { 1.389 + print "<tr><td class='n'><a href='" . addslashes($file['name']). "'>" .htmlentities($file['name']). "</a></td>"; 1.390 + print "<td class='m'>" . date('Y-M-d H:m:s', $file['modtime']) . "</td>"; 1.391 + print "<td class='s'>" . format_bytes($file['size']) . "</td>"; 1.392 + print "<td class='t'>" . $file['file_type'] . "</td></tr>\n"; 1.393 +} 1.394 + 1.395 +// Print ending stuff 1.396 +$soft = explode('/',$_SERVER["SERVER_SOFTWARE"]); 1.397 +$tag = get_conf('server.tag','"','"',$soft[0].' <'.$soft[1].'>'); 1.398 +print "</tbody> 1.399 + </table> 1.400 + </div>"; 1.401 +if ($slitaz_style) { ?> 1.402 + 1.403 +<!-- End of content --> 1.404 +</div> 1.405 + 1.406 +<!-- Footer --> 1.407 +<div id="footer"> 1.408 + <div class="right_box"> 1.409 + <h4>SliTaz Network</h4> 1.410 + <ul> 1.411 + <li><a href="http://www.slitaz.org/">Main Website</a></li> 1.412 + <li><a href="http://doc.slitaz.org/">Documentation</a></li> 1.413 + <li><a href="http://forum.slitaz.org/">Support Forum</a></li> 1.414 + <li><a href="http://scn.slitaz.org/">Community Network</a></li> 1.415 + <li><a href="http://pkgs.slitaz.org/">Packages</a></li> 1.416 + <li><a href="http://labs.slitaz.org/">Laboratories</a></li> 1.417 + </ul> 1.418 + </div> 1.419 + <h4>SliTaz Website</h4> 1.420 + <ul> 1.421 + <li><a href="#header">Top of the page</a></li> 1.422 + <li>Copyright © <span class="year"></span> 1.423 + <a href="http://www.slitaz.org/">SliTaz</a></li> 1.424 + <li><a href="about/">About the project</a></li> 1.425 + <li><a href="netmap.php">Network Map</a></li> 1.426 + <li>Page modified the <?php echo date('r'); ?></li> 1.427 + <li><a href="http://validator.w3.org/check?uri=referer"><img 1.428 + src="pics/website/xhtml10.png" alt="Valid XHTML 1.0" 1.429 + title="Code validé XHTML 1.0" 1.430 + style="width: 80px; height: 15px; vertical-align: middle;" /></a></li> 1.431 + </ul> 1.432 +</div> 1.433 + 1.434 +<?php } 1.435 +else print " 1.436 + <form action='".$_SERVER["REQUEST_URI"]."' method='get'> 1.437 + <div class='foot'>".$tag." 1.438 + <input type='text' name='f'/> 1.439 + <!-- <input type='submit' value='Filter' /> --> 1.440 + </div> 1.441 + </form> 1.442 +"; 1.443 +print "</body> 1.444 + </html>"; 1.445 +?>