wok-6.x view mirror-tools/stuff/var/www/slitaz/mirror/dir-generator.php @ rev 8625

Up: scummvm 1.2.1
author Antoine Bodin <gokhlayeh@slitaz.org>
date Tue Feb 15 03:13:24 2011 +0100 (2011-02-15)
parents 874e4034d260
children
line source
1 <?php
2 function redirect()
3 {
4 ?>
5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
6 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
8 <head>
9 <title>SliTaz mirror redirection</title>
10 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
11 <meta name="description" content="slitaz mirror redirection" />
12 <meta name="robots" content="index, nofollow" />
13 <meta name="author" content="SliTaz Contributors" />
14 <meta http-equiv="Refresh" content="0;url=http://mirror.slitaz.org/">
15 </head>
16 <?php
17 }
19 $VERSION = "0.2-slitaz";
21 /* Lighttpd Enhanced Directory Listing Script
22 * ------------------------------------------
23 * Authors: Evan Fosmark <me@evanfosmark.com>,
24 * Pascal Bellard <pascal.bellard@slitaz.org>
25 * Christophe Lincoln <pankso@slitaz.org>
26 *
27 *
28 * GNU License Agreement
29 * ---------------------
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
34 *
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
39 *
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
43 *
44 * http://www.gnu.org/licenses/gpl.txt
45 */
47 // Get the path (cut out the query string from the request_uri)
48 list($path) = explode('?', $_SERVER['REQUEST_URI']);
51 // Get the path that we're supposed to show.
52 $path = ltrim(rawurldecode($path), '/');
55 if(strlen($path) == 0) {
56 $path = "./";
57 }
60 // Can't call the script directly since REQUEST_URI won't be a directory
61 if($_SERVER['PHP_SELF'] == '/'.$path) {
62 redirect();
63 // die("Unable to call " . $path . " directly.");
64 }
67 $vpath = ($path != "./")?$path:"";
68 // Make sure it is valid.
69 if(!is_dir($path)) {
70 // die("<b>" . $path . "</b> is not a valid path.");
71 $path = dirname($_SERVER["SCRIPT_FILENAME"]);
72 list($vpath) = explode('?', $_SERVER['REQUEST_URI']);
73 $vpath = ltrim(rawurldecode($vpath), '/');
74 }
77 //
78 // This function returns the file size of a specified $file.
79 //
80 function format_bytes($size, $precision=1) {
81 $sizes = array('Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'K', '');
82 $total = count($sizes);
84 while($total-- && $size > 1024) $size /= 1024;
85 if ($sizes[$total] == '') {
86 $size /= 1024;
87 $total--;
88 }
89 return sprintf('%.'.$precision.'f', $size).$sizes[$total];
90 }
93 //
94 // Get some variables from /etc/lighttpd/lighttpd.conf
95 //
96 $conf_lightty = file_get_contents("/etc/lighttpd/lighttpd.conf");
98 function get_conf($var,$start,$stop,$default='') {
99 global $conf_lightty;
101 if (!preg_match('/'.$var.'/',$conf_lightty)) return $default;
102 $filter = '/(.*\n)*'.$var.'\s*=\s*'.$start.'(([^'.$stop.']*\n*)*)'.$stop.'(.*\n)*/';
103 return preg_replace($filter,'$2',$conf_lightty);
104 }
106 $encoding = get_conf('dir-listing.encoding','"','"','ascii');
107 $external_css = get_conf('dir-listing.external-css','"','"');
109 $show_hidden_files = false;
110 if (get_conf('dir-listing.hide-dotfile','"','"','disable') == "disable") {
111 $show_hidden_files = true;
112 }
113 // get_conf('dir-listing.exclude','\(','\)');
114 // get_conf('dir-listing.set-footer','"','"');
116 $mime_types = array();
117 foreach (explode(',',get_conf('mimetype.assign','\(','\)')) as $item) {
118 $filter = '/\s*"(.*)"\s*=>\s*"(.*)".*/';
119 $val = explode(',',preg_replace($filter,'$1,$2',$item));
120 if (isset($val[1])) $mime_types[$val[0]] = $val[1];
121 }
123 //
124 // This function returns the mime type of $file.
125 //
126 function get_file_type($file) {
127 global $mime_types;
129 $file = basename($file);
130 $default_type = "application/octet-stream";
131 if (isset($mime_types[$file])) {
132 return $mime_types[$file];
133 }
134 $pos = strrpos($file, ".");
135 if ($pos === false) {
136 return $default_type;
137 }
138 //FIXME .tar.gz
139 $ext = '.'.rtrim(substr($file, $pos+1), "~");
140 if (isset($mime_types[$ext])) {
141 return $mime_types[$ext];
142 }
143 return $default_type;
144 }
146 //$slitaz_style = (dirname($_SERVER["PHP_SELF"]) == '/');
147 $slitaz_style = ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org");
148 if ($slitaz_style) {
149 $fvalue = "";
150 if (isset($_GET[f])) $fvalue = 'value="'.$_GET[f].'"';
151 print <<<EOT
152 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
153 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
154 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
155 <head>
156 <title>Index of /$vpath</title>
157 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
158 <meta name="description" content=">Index of /$vpath" />
159 <meta name="robots" content="index, nofollow" />
160 <meta name="author" content="SliTaz Contributors" />
161 <link rel="shortcut icon" href="/css/favicon.ico" />
162 <link rel="stylesheet" type="text/css" href="/css/slitaz.css" />
163 <style type='text/css'>
164 div.list { background-color: white; padding-bottom: 14px;}
165 table {width: 100% ;}
166 th, td { font: 90% monospace; text-align: left;}
167 th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
168 td {padding-right: 14px;}
169 td.s, th.s {text-align: right;}
170 </style>
171 </head>
172 <body>
174 <!-- Header -->
175 <div id="header">
176 <a href="http://mirror.slitaz.org/"><img id="logo"
177 src="/css/pics/website/logo.png"
178 title="mirror.slitaz.org" alt="mirror.slitaz.org" /></a>
179 <p id="titre">#!/Mirror/${vpath}</p>
180 </div>
182 <!-- Content -->
183 <div id="content-full">
185 <!-- Block begin -->
186 <div class="block">
187 <!-- Nav block begin -->
188 <div id="block_nav">
189 <h3><img src="/css/pics/website/users.png" alt="users.png" />Community</h3>
190 <ul>
191 <li><a href="http://pizza.slitaz.org/">Live Builder</a></li>
192 <li><a href="http://boot.slitaz.org/">Web Boot</a></li>
193 </ul>
194 <h3>Search</h3>
195 <form class="search" action="${_SERVER["REQUEST_URI"]}" method="get" >
196 <p><input type="text" name="f" $fvalue /></p>
197 </form>
198 <!-- Nav block end -->
199 </div>
200 <!-- Top block begin -->
201 <div id="block_top">
202 <h1>About Mirror</h1>
203 <p>Welcome to Open Source!
204 EOT;
205 if ($_SERVER["SERVER_NAME"] == "mirror.slitaz.org") print <<<EOT
206 This is the SliTaz GNU/Linux main mirror. The server runs naturally SliTaz
207 (stable) in an lguest virtual machine provided by
208 <a href="http://www.ads-lu.com/">ADS</a>.
209 EOT;
210 print <<<EOT
211 </p>
212 <p><img src="/css/pics/website/network.png"
213 alt=".png" style="vertical-align:middle;"/>Mirrors:
214 EOT;
215 $mirrors = array();
216 $fp = @fopen(dirname($_SERVER["SCRIPT_FILENAME"])."/mirrors","r");
217 if ($fp) {
218 while (($line = fgets($fp)) !== false) {
219 $line = chop($line);
220 $url = parse_url($line);
221 if ($_SERVER["SERVER_NAME"] == $url['host']) continue;
222 $host = explode('.',$url['host']);
223 $mirrors[$host[count($host)-2].".".
224 $host[count($host)-1]] = $line;
225 }
226 }
227 fclose($fp);
228 foreach($mirrors as $name => $url) {
229 echo "<a href=\"$url$vpath\" title=\"$name mirror\">$name</a>\n";
230 }
231 print <<<EOT
232 </p>
233 <!-- Top block end -->
234 </div>
235 <!-- Block end -->
236 </div>
238 EOT;
239 }
240 else {
242 // Print the heading stuff
243 print "<?xml version='1.0' encoding='$encoding'?>
244 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
245 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
246 <head>
247 <title>Index of /" .$vpath. "</title>
248 ";
249 if ($external_css != '') {
250 print " <link rel='stylesheet' type='text/css' href='".$external_css."' />
251 ";
252 }
253 else {
254 print " <style type='text/css'>
255 a, a:active {text-decoration: none; color: blue;}
256 a:visited {color: #48468F;}
257 a:hover, a:focus {text-decoration: underline; color: red;}
258 body {background-color: #F5F5F5;}
259 h2 {margin-bottom: 12px;}
260 table {margin-left: 12px;}
261 th, td { font: 90% monospace; text-align: left;}
262 th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
263 td {padding-right: 14px;}
264 td.s, th.s {text-align: right;}
265 div.list { background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;}
266 div.foot { font: 90% monospace; color: #787878; padding-top: 4px;}
267 </style>
268 ";
269 }
270 print " </head>
271 <boby>
272 <h2>Index of /" . $vpath ."</h2>
273 ";
274 }
276 print " <div class='list'>
277 <table summary='Directory Listing' cellpadding='0' cellspacing='0'>
278 ";
282 // Get all of the folders and files.
283 $folderlist = array();
284 $filelist = array();
285 if($handle = @opendir($path)) {
286 while(($item = readdir($handle)) !== false) {
287 if ($item == "index.php") continue;
288 if ($item == "dir-generator.php") continue;
289 if (isset($_GET['f'])) {
290 $filter = $_GET['f'];
291 if (substr($filter,0,1) != '/')
292 $filter = '/'.$filter.'/i';
293 if (!preg_match($filter,$item)) continue;
294 }
295 if(is_dir($path.'/'.$item) and $item != '.' and $item != '..') {
296 $folderlist[] = array(
297 'name' => $item,
298 'size' => 0,
299 'modtime'=> filemtime($path.'/'.$item),
300 'file_type' => "Directory"
301 );
302 }
303 elseif(is_file($path.'/'.$item)) {
304 if(!$show_hidden_files) {
305 if(substr($item, 0, 1) == "." or substr($item, -1) == "~") {
306 continue;
307 }
308 }
309 $filelist[] = array(
310 'name'=> $item,
311 'size'=> filesize($path.'/'.$item),
312 'modtime'=> filemtime($path.'/'.$item),
313 'file_type' => get_file_type($path.'/'.$item)
314 );
315 }
316 }
317 closedir($handle);
318 }
321 if(!isset($_GET['s'])) {
322 $_GET['s'] = 'name';
323 }
325 // Figure out what to sort files by
326 $file_order_by = array();
327 foreach ($filelist as $key=>$row) {
328 $file_order_by[$key] = $row[$_GET['s']];
329 }
331 // Figure out what to sort folders by
332 $folder_order_by = array();
333 foreach ($folderlist as $key=>$row) {
334 $folder_order_by[$key] = $row[$_GET['s']];
335 }
337 // Order the files and folders
338 $sort_type = SORT_ASC;
339 $order = "&amp;o=d";
340 if(isset($_GET['o'])) {
341 $sort_type = SORT_DESC;
342 $order = "";
343 }
344 array_multisort($folder_order_by, $sort_type, $folderlist);
345 array_multisort($file_order_by, $sort_type, $filelist);
348 // Show sort methods
349 print "<thead><tr>";
351 $sort_methods = array();
352 $sort_methods['name'] = "Name";
353 $sort_methods['modtime'] = "Last Modified";
354 $sort_methods['size'] = "Size";
355 $sort_methods['file_type'] = "Type";
357 foreach($sort_methods as $key=>$item) {
358 if ($_GET['s'] == $key) $key = "$key$order";
359 print "<th class='n'><a href='?s=$key'>$item</a></th>";
360 }
361 print "</tr></thead>\n<tbody>\n";
365 // Parent directory link
366 if($path != "./") {
367 print "<tr><td class='n'><a href='..'>Parent Directory</a>/</td>";
368 print "<td class='m'>&nbsp;</td>";
369 print "<td class='s'>- &nbsp;</td>";
370 print "<td class='t'>Directory</td></tr>\n";
371 }
375 // Print folder information
376 foreach($folderlist as $folder) {
377 print "<tr><td class='n'><a href='" . addslashes($folder['name']). "'>" .htmlentities($folder['name']). "</a>/</td>";
378 print "<td class='m'>" . date('Y-M-d H:m:s', $folder['modtime']) . "</td>";
379 print "<td class='s'>- &nbsp;</td>";
380 print "<td class='t'>" . $folder['file_type'] . "</td></tr>\n";
381 }
384 // Print file information
385 foreach($filelist as $file) {
386 print "<tr><td class='n'><a href='" . addslashes($file['name']). "'>" .htmlentities($file['name']). "</a></td>";
387 print "<td class='m'>" . date('Y-M-d H:m:s', $file['modtime']) . "</td>";
388 print "<td class='s'>" . format_bytes($file['size']) . "</td>";
389 print "<td class='t'>" . $file['file_type'] . "</td></tr>\n";
390 }
392 // Print ending stuff
393 $soft = explode('/',$_SERVER["SERVER_SOFTWARE"]);
394 $tag = get_conf('server.tag','"','"',$soft[0].' &lt;'.$soft[1].'&gt;');
395 print "</tbody>
396 </table>
397 </div>";
398 if ($slitaz_style) { ?>
400 <!-- End of content -->
401 </div>
403 <!-- Footer -->
404 <div id="footer">
405 <div class="right_box">
406 <h4>SliTaz Network</h4>
407 <ul>
408 <li><a href="http://www.slitaz.org/">Main Website</a></li>
409 <li><a href="http://doc.slitaz.org/">Documentation</a></li>
410 <li><a href="http://forum.slitaz.org/">Support Forum</a></li>
411 <li><a href="http://scn.slitaz.org/">Community Network</a></li>
412 <li><a href="http://pkgs.slitaz.org/">Packages</a></li>
413 <li><a href="http://labs.slitaz.org/">Laboratories</a></li>
414 </ul>
415 </div>
416 <h4>SliTaz Website</h4>
417 <ul>
418 <li><a href="#header">Top of the page</a></li>
419 <li>Copyright &copy; <span class="year"></span>
420 <a href="http://www.slitaz.org/">SliTaz</a></li>
421 <li><a href="about/">About the project</a></li>
422 <li><a href="netmap.php">Network Map</a></li>
423 <li>Page modified the <?php echo date('r'); ?></li>
424 <li><a href="http://validator.w3.org/check?uri=referer"><img
425 src="pics/website/xhtml10.png" alt="Valid XHTML 1.0"
426 title="Code validé XHTML 1.0"
427 style="width: 80px; height: 15px; vertical-align: middle;" /></a></li>
428 </ul>
429 </div>
431 <?php }
432 else print "
433 <form action='".$_SERVER["REQUEST_URI"]."' method='get'>
434 <div class='foot'>".$tag."
435 <input type='text' name='f'/>
436 <!-- <input type='submit' value='Filter' /> -->
437 </div>
438 </form>
439 ";
440 print "</body>
441 </html>";
442 ?>