rev |
line source |
pankso@166
|
1 <?php
|
pankso@166
|
2 function redirect()
|
pankso@166
|
3 {
|
pankso@166
|
4 ?>
|
pankso@166
|
5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
pankso@166
|
6 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
pankso@166
|
7 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
pankso@166
|
8 <head>
|
pankso@166
|
9 <title>SliTaz mirror redirection</title>
|
pankso@166
|
10 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
|
pankso@166
|
11 <meta name="description" content="slitaz mirror redirection" />
|
pankso@166
|
12 <meta name="robots" content="index, nofollow" />
|
pankso@166
|
13 <meta name="author" content="SliTaz Contributors" />
|
pascal@577
|
14 <meta http-equiv="Refresh" content="0;url=http://mirror1.slitaz.org/">
|
pankso@166
|
15 </head>
|
pankso@166
|
16 <?php
|
pankso@166
|
17 }
|
pankso@166
|
18
|
pascal@587
|
19 $VERSION = "0.3-slitaz";
|
pankso@166
|
20
|
pankso@166
|
21 /* Lighttpd Enhanced Directory Listing Script
|
pankso@166
|
22 * ------------------------------------------
|
pankso@166
|
23 * Authors: Evan Fosmark <me@evanfosmark.com>,
|
pankso@166
|
24 * Pascal Bellard <pascal.bellard@slitaz.org>
|
pankso@166
|
25 * Christophe Lincoln <pankso@slitaz.org>
|
pankso@166
|
26 *
|
pankso@166
|
27 *
|
pankso@166
|
28 * GNU License Agreement
|
pankso@166
|
29 * ---------------------
|
pankso@166
|
30 * This program is free software; you can redistribute it and/or modify
|
pankso@166
|
31 * it under the terms of the GNU General Public License as published by
|
pankso@166
|
32 * the Free Software Foundation; either version 2 of the License, or
|
pankso@166
|
33 * (at your option) any later version.
|
pankso@166
|
34 *
|
pankso@166
|
35 * This program is distributed in the hope that it will be useful,
|
pankso@166
|
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
pankso@166
|
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
pankso@166
|
38 * GNU General Public License for more details.
|
pankso@166
|
39 *
|
pankso@166
|
40 * You should have received a copy of the GNU General Public License
|
pankso@166
|
41 * along with this program; if not, write to the Free Software
|
pankso@166
|
42 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
pankso@166
|
43 *
|
pankso@166
|
44 * http://www.gnu.org/licenses/gpl.txt
|
pankso@166
|
45 */
|
pankso@166
|
46
|
pankso@166
|
47 // Get the path (cut out the query string from the request_uri)
|
pankso@166
|
48 list($path) = explode('?', $_SERVER['REQUEST_URI']);
|
pankso@166
|
49
|
pankso@166
|
50
|
pankso@166
|
51 // Get the path that we're supposed to show.
|
pankso@166
|
52 $path = ltrim(rawurldecode($path), '/');
|
pankso@166
|
53
|
pankso@166
|
54
|
pankso@166
|
55 if(strlen($path) == 0) {
|
pankso@166
|
56 $path = "./";
|
pankso@166
|
57 }
|
pankso@166
|
58
|
pankso@166
|
59
|
pankso@166
|
60 // Can't call the script directly since REQUEST_URI won't be a directory
|
pankso@166
|
61 if($_SERVER['PHP_SELF'] == '/'.$path) {
|
pankso@166
|
62 redirect();
|
pankso@166
|
63 // die("Unable to call " . $path . " directly.");
|
pankso@166
|
64 }
|
pankso@166
|
65
|
pankso@166
|
66
|
pankso@166
|
67 $vpath = ($path != "./")?$path:"";
|
pankso@166
|
68 // Make sure it is valid.
|
pankso@166
|
69 if(!is_dir($path)) {
|
pankso@166
|
70 // die("<b>" . $path . "</b> is not a valid path.");
|
pankso@166
|
71 $path = dirname($_SERVER["SCRIPT_FILENAME"]);
|
pankso@166
|
72 list($vpath) = explode('?', $_SERVER['REQUEST_URI']);
|
pankso@166
|
73 $vpath = ltrim(rawurldecode($vpath), '/');
|
pankso@166
|
74 }
|
pankso@166
|
75
|
pankso@166
|
76
|
pankso@166
|
77 //
|
pankso@166
|
78 // This function returns the file size of a specified $file.
|
pankso@166
|
79 //
|
pankso@166
|
80 function format_bytes($size, $precision=1) {
|
pankso@166
|
81 $sizes = array('Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'K', '');
|
pankso@166
|
82 $total = count($sizes);
|
pankso@166
|
83
|
pankso@166
|
84 while($total-- && $size > 1024) $size /= 1024;
|
pankso@166
|
85 if ($sizes[$total] == '') {
|
pankso@166
|
86 $size /= 1024;
|
pankso@166
|
87 $total--;
|
pankso@166
|
88 }
|
pankso@166
|
89 return sprintf('%.'.$precision.'f', $size).$sizes[$total];
|
pankso@166
|
90 }
|
pankso@166
|
91
|
pankso@166
|
92 //
|
pankso@166
|
93 // Get some variables from /etc/lighttpd/lighttpd.conf
|
pankso@166
|
94 //
|
pankso@166
|
95 $conf_lightty = file_get_contents("/etc/lighttpd/lighttpd.conf");
|
pankso@166
|
96
|
pankso@166
|
97 function get_conf($var,$start,$stop,$default='') {
|
pankso@166
|
98 global $conf_lightty;
|
pankso@166
|
99
|
pankso@166
|
100 if (!preg_match('/'.$var.'/',$conf_lightty)) return $default;
|
pankso@166
|
101 $filter = '/(.*\n)*'.$var.'\s*=\s*'.$start.'(([^'.$stop.']*\n*)*)'.$stop.'(.*\n)*/';
|
pankso@166
|
102 return preg_replace($filter,'$2',$conf_lightty);
|
pankso@166
|
103 }
|
pankso@166
|
104
|
pankso@166
|
105 $encoding = get_conf('dir-listing.encoding','"','"','ascii');
|
pankso@166
|
106 $external_css = get_conf('dir-listing.external-css','"','"');
|
pankso@166
|
107
|
pankso@166
|
108 $show_hidden_files = false;
|
pankso@166
|
109 if (get_conf('dir-listing.hide-dotfile','"','"','disable') == "disable") {
|
pankso@166
|
110 $show_hidden_files = true;
|
pankso@166
|
111 }
|
pankso@166
|
112 // get_conf('dir-listing.exclude','\(','\)');
|
pankso@166
|
113 // get_conf('dir-listing.set-footer','"','"');
|
pankso@166
|
114
|
pankso@166
|
115 $mime_types = array();
|
pankso@166
|
116 foreach (explode(',',get_conf('mimetype.assign','\(','\)')) as $item) {
|
pankso@166
|
117 $filter = '/\s*"(.*)"\s*=>\s*"(.*)".*/';
|
pankso@166
|
118 $val = explode(',',preg_replace($filter,'$1,$2',$item));
|
pankso@166
|
119 if (isset($val[1])) $mime_types[$val[0]] = $val[1];
|
pankso@166
|
120 }
|
pankso@166
|
121
|
pankso@166
|
122 //
|
pankso@166
|
123 // This function returns the mime type of $file.
|
pankso@166
|
124 //
|
pankso@166
|
125 function get_file_type($file) {
|
pankso@166
|
126 global $mime_types;
|
pankso@166
|
127
|
pankso@166
|
128 $file = basename($file);
|
pankso@166
|
129 $default_type = "application/octet-stream";
|
pankso@166
|
130 if (isset($mime_types[$file])) {
|
pankso@166
|
131 return $mime_types[$file];
|
pankso@166
|
132 }
|
pankso@166
|
133 $pos = strrpos($file, ".");
|
pankso@166
|
134 if ($pos === false) {
|
pankso@166
|
135 return $default_type;
|
pankso@166
|
136 }
|
pankso@166
|
137 //FIXME .tar.gz
|
pankso@166
|
138 $ext = '.'.rtrim(substr($file, $pos+1), "~");
|
pankso@166
|
139 if (isset($mime_types[$ext])) {
|
pankso@166
|
140 return $mime_types[$ext];
|
pankso@166
|
141 }
|
pankso@166
|
142 return $default_type;
|
pankso@166
|
143 }
|
pankso@166
|
144
|
pankso@166
|
145 //$slitaz_style = (dirname($_SERVER["PHP_SELF"]) == '/');
|
pascal@577
|
146 //$slitaz_style = ($_SERVER["SERVER_NAME"] == "mirror1.slitaz.org");
|
pascal@577
|
147 $slitaz_style = preg_match("/mirror1\.slitaz\./",$_SERVER["SERVER_NAME"]);
|
pankso@166
|
148 if ($slitaz_style) {
|
pascal@379
|
149 $modified = gmdate("D, d M Y H:i:s e", strtotime("-1 hour"));
|
pascal@379
|
150 $expires = gmdate("D, d M Y H:i:s e", strtotime("+1 hour"));
|
pankso@166
|
151 $fvalue = "";
|
pankso@166
|
152 if (isset($_GET['f'])) $fvalue = 'value="'.$_GET['f'].'"';
|
pascal@379
|
153 header("Expires: ".$expires);
|
pascal@379
|
154 header("Last-Modified: " . $modified);
|
pascal@379
|
155 header("Pragma: cache");
|
pascal@379
|
156 // header("Cache-Control: public");
|
pascal@379
|
157 // <meta http-equiv="cache-control" content="public" />
|
pascal@379
|
158 // <meta http-equiv="last-modified" content="$modified" />
|
pascal@379
|
159 // <meta http-equiv="expires" content="$expires" />
|
pankso@166
|
160 print <<<EOT
|
pankso@166
|
161 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
pankso@166
|
162 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
pankso@166
|
163 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
pankso@166
|
164 <head>
|
pankso@166
|
165 <title>Index of /$vpath</title>
|
pankso@166
|
166 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
|
pankso@166
|
167 <meta name="description" content=">Index of /$vpath" />
|
pankso@166
|
168 <meta name="robots" content="index, nofollow" />
|
pankso@166
|
169 <meta name="author" content="SliTaz Contributors" />
|
pankso@173
|
170 <link rel="shortcut icon" href="/static/favicon.ico" />
|
pankso@173
|
171 <link rel="stylesheet" type="text/css" href="/static/slitaz.css" />
|
pankso@168
|
172 <style type="text/css">
|
pankso@178
|
173 #block { min-height: 160px; }
|
pankso@175
|
174 div.list { background-color: white; padding-bottom: 14px; }
|
pankso@175
|
175 th, td { font: 90% monospace; text-align: left; }
|
pankso@175
|
176 th { font-weight: bold; padding-right: 14px; padding-bottom: 3px; }
|
pankso@175
|
177 td { padding-right: 14px; }
|
pankso@175
|
178 td.s, th.s { text-align: right; }
|
pankso@168
|
179 </style>
|
pankso@166
|
180 </head>
|
pankso@166
|
181 <body>
|
pankso@166
|
182
|
pankso@166
|
183 <!-- Header -->
|
pankso@166
|
184 <div id="header">
|
pankso@166
|
185 <div id="logo"></div>
|
pankso@166
|
186 <div id="network">
|
pankso@166
|
187 <a href="http://www.slitaz.org/">
|
pankso@175
|
188 <img src="/static/home.png" alt="[ Home ]" /></a>
|
pankso@166
|
189 <a href="http://scn.slitaz.org/">Community</a>
|
pankso@166
|
190 <a href="http://doc.slitaz.org/">Doc</a>
|
pankso@166
|
191 <a href="http://forum.slitaz.org/">Forum</a>
|
pankso@166
|
192 <a href="http://pro.slitaz.org/">Pro</a>
|
pankso@166
|
193 <a href="https://slitaz.spreadshirt.net/">Shop</a>
|
pankso@166
|
194 <a href="http://bugs.slitaz.org">Bugs</a>
|
pascal@343
|
195 <a href="http://hg.slitaz.org/?sort=lastchange">Hg</a>
|
pankso@173
|
196 <a href="http://cook.slitaz.org/">Cook</a>
|
pankso@166
|
197 </div>
|
pascal@577
|
198 <h1><a href="http://mirror1.slitaz.org/">SliTaz Mirror</a></h1>
|
pankso@166
|
199 </div>
|
pankso@166
|
200
|
pankso@166
|
201 <!-- Block -->
|
pankso@166
|
202 <div id="block">
|
pankso@166
|
203 <!-- Navigation -->
|
pankso@166
|
204 <div id="block_nav">
|
pankso@166
|
205 <h4>Online Tools</h4>
|
pankso@166
|
206 <ul>
|
pascal@378
|
207 <li><a href="http://pizza.slitaz.me/">Live ISO Builder</a></li>
|
pascal@378
|
208 <li><a href="http://pizza.slitaz.org/">Live flavor Builder</a></li>
|
pascal@378
|
209 <li><a href="http://tiny.slitaz.org/">Tiny SliTaz Builder</a></li>
|
pankso@166
|
210 <li><a href="http://boot.slitaz.org/">Web Boot</a></li>
|
pankso@166
|
211 </ul>
|
pankso@166
|
212 </div>
|
pankso@166
|
213 <!-- Information/image -->
|
pankso@166
|
214 <div id="block_info">
|
pankso@166
|
215 <h4>Welcome to Open Source!</h4>
|
pankso@166
|
216 EOT;
|
pascal@577
|
217 if (preg_match("/mirror1\.slitaz\./",$_SERVER["SERVER_NAME"])) print <<<EOT
|
pankso@166
|
218 <p>This is the SliTaz GNU/Linux main mirror. The server runs naturally
|
pascal@577
|
219 SliTaz (stable) in an uml virtual machine provided by
|
pankso@173
|
220 <a href="http://www.ads-lu.com/">ADS</a> and is located in France.
|
pankso@166
|
221 <a href="/info/">Mirror info...</a></p>
|
pankso@166
|
222 EOT;
|
pankso@166
|
223 print <<<EOT
|
pankso@166
|
224 <form action="${_SERVER["REQUEST_URI"]}" method="get" style="width: 300px;">
|
pankso@166
|
225 <p><input type="text" name="f" $fvalue
|
pankso@182
|
226 style="width: 260px;" /></p>
|
pankso@166
|
227 </form>
|
pankso@166
|
228 </div>
|
pankso@166
|
229 </div>
|
pankso@166
|
230
|
pascal@587
|
231 <!-- script type="text/javascript" src="/static/qrcode.js"></script -->
|
pascal@379
|
232 <script type="text/javascript">
|
pascal@379
|
233 function QRCodePNG(str, obj) {
|
pascal@379
|
234 try {
|
pascal@587
|
235 obj.height = obj.width += 200;
|
pascal@379
|
236 return QRCode.generatePNG(str, {ecclevel: 'H'});
|
pascal@379
|
237 }
|
pascal@379
|
238 catch (any) {
|
pascal@379
|
239 var element = document.createElement("script");
|
pascal@379
|
240 element.src = "/static/qrcode.js";
|
pascal@379
|
241 element.type ="text/javascript";
|
pascal@379
|
242 element.onload = function() {
|
pascal@379
|
243 obj.src = QRCode.generatePNG(str, {ecclevel: 'H'});
|
pascal@379
|
244 };
|
pascal@379
|
245 document.body.appendChild(element);
|
pascal@379
|
246 }
|
pascal@379
|
247 }
|
pascal@379
|
248 </script>
|
pankso@166
|
249 <div id="lang">
|
pankso@167
|
250 Path: /${vpath}
|
pankso@167
|
251 </div>
|
pankso@167
|
252
|
pankso@169
|
253 <!-- Content -->
|
pankso@169
|
254 <div id="content">
|
pankso@169
|
255
|
pankso@167
|
256 <div id="mirrors">
|
pankso@180
|
257 <img src="/static/network.png" alt="[ Mirrors ]" style="margin-right: 5px;" />
|
pankso@166
|
258 EOT;
|
pankso@166
|
259
|
pankso@166
|
260 // Mirror list
|
pankso@166
|
261 $mirrors = array();
|
pankso@166
|
262 $fp = @fopen(dirname($_SERVER["SCRIPT_FILENAME"])."/mirrors","r");
|
pankso@166
|
263 if ($fp) {
|
pankso@166
|
264 while (($line = fgets($fp)) !== false) {
|
pankso@166
|
265 $line = chop($line);
|
pankso@166
|
266 $url = parse_url($line);
|
pankso@166
|
267 if ($_SERVER["SERVER_NAME"] == $url['host']) continue;
|
pankso@166
|
268 $host = explode('.',$url['host']);
|
pankso@166
|
269 $mirrors[$host[count($host)-2].".".
|
pankso@166
|
270 $host[count($host)-1]] = $line;
|
pankso@166
|
271 }
|
pankso@166
|
272 }
|
pankso@166
|
273 fclose($fp);
|
pankso@166
|
274 foreach($mirrors as $name => $url) {
|
pankso@166
|
275 echo "<a href=\"$url$vpath\" title=\"$name mirror\">$name</a>\n";
|
pankso@166
|
276 }
|
pankso@169
|
277 echo "</div>";
|
pankso@166
|
278 }
|
pankso@166
|
279 else {
|
pankso@166
|
280
|
pankso@166
|
281 // Print the heading stuff
|
pankso@166
|
282 print "<?xml version='1.0' encoding='$encoding'?>
|
pankso@166
|
283 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
|
pankso@166
|
284 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
|
pankso@166
|
285 <head>
|
pankso@166
|
286 <title>Index of /" .$vpath. "</title>
|
pankso@166
|
287 ";
|
pankso@166
|
288 if ($external_css != '') {
|
pankso@166
|
289 print " <link rel='stylesheet' type='text/css' href='".$external_css."' />
|
pankso@166
|
290 ";
|
pankso@166
|
291 }
|
pankso@166
|
292 else {
|
pankso@166
|
293 print " <style type='text/css'>
|
pankso@166
|
294 a, a:active {text-decoration: none; color: blue;}
|
pankso@166
|
295 a:visited {color: #48468F;}
|
pankso@166
|
296 a:hover, a:focus {text-decoration: underline; color: red;}
|
pankso@166
|
297 body {background-color: #F5F5F5;}
|
pankso@166
|
298 h2 {margin-bottom: 12px;}
|
pankso@166
|
299 table {margin-left: 12px;}
|
pankso@166
|
300 th, td { font: 90% monospace; text-align: left;}
|
pankso@166
|
301 th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
|
pankso@166
|
302 td {padding-right: 14px;}
|
pankso@166
|
303 td.s, th.s {text-align: right;}
|
pankso@166
|
304 div.list { background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;}
|
pankso@166
|
305 div.foot { font: 90% monospace; color: #787878; padding-top: 4px;}
|
pankso@166
|
306 </style>
|
pankso@166
|
307 ";
|
pankso@166
|
308 }
|
pankso@166
|
309 print " </head>
|
pankso@166
|
310 <body>
|
pankso@166
|
311 <h2>Index of /" . $vpath ."</h2>
|
pankso@166
|
312 ";
|
pankso@166
|
313 }
|
pankso@166
|
314
|
pankso@166
|
315 print " <div class='list'>
|
pankso@166
|
316 <table summary='Directory Listing' cellpadding='0' cellspacing='0'>
|
pankso@166
|
317 ";
|
pankso@166
|
318
|
pankso@166
|
319 function my_is_file($path) // 2G+ file support
|
pankso@166
|
320 {
|
pankso@166
|
321 exec("[ -f '".$path."' ]", $tmp, $ret);
|
pankso@166
|
322 return $ret == 0;
|
pascal@280
|
323 //return is_file($path);
|
pankso@166
|
324 }
|
pankso@166
|
325
|
pankso@166
|
326 function my_filesize($path) // 2G+ file support
|
pankso@166
|
327 {
|
pankso@166
|
328 return rtrim(shell_exec("stat -Lc %s '".$path."'"));
|
pascal@280
|
329 //return filesize($path);
|
pankso@166
|
330 }
|
pankso@166
|
331
|
pankso@166
|
332 function my_filemtime($path) // 2G+ file support
|
pankso@166
|
333 {
|
pankso@166
|
334 return rtrim(shell_exec("stat -Lc %Y '".$path."'"));
|
pascal@280
|
335 //return filemtime($path);
|
pankso@166
|
336 }
|
pankso@166
|
337
|
pankso@166
|
338 function my_filemtimeasc($path) // 2G+ file support
|
pankso@166
|
339 {
|
pascal@280
|
340 return rtrim(shell_exec("LC_ALL=C date -r '".$path."' '+%Y-%b-%d %H:%M:%S'"));
|
pascal@280
|
341 //return date('Y-M-d H:m:s', filemtime($path));
|
pankso@166
|
342 }
|
pankso@166
|
343
|
pascal@587
|
344 if (filesize($path."/.folderlist") > 0 && filesize($path."/.filelist") > 0 &&
|
pascal@539
|
345 filemtime($path."/.filelist") > filemtime($path)) {
|
pascal@587
|
346 $folderlist = unserialize(file_get_contents($path."/.folderlist"));
|
pascal@587
|
347 $filelist = unserialize(file_get_contents($path."/.filelist"));
|
pascal@280
|
348 }
|
pascal@280
|
349 else {
|
pascal@280
|
350
|
pascal@378
|
351 proc_nice(10);
|
pankso@166
|
352 // Get all of the folders and files.
|
pankso@166
|
353 $folderlist = array();
|
pankso@166
|
354 $filelist = array();
|
pankso@166
|
355 if($handle = @opendir($path)) {
|
pankso@166
|
356 while(($item = readdir($handle)) !== false) {
|
pankso@166
|
357 if ($item == "index.php") continue;
|
pascal@280
|
358 if ($item == ".folderlist") continue;
|
pascal@280
|
359 if ($item == ".filelist") continue;
|
pankso@166
|
360 if ($item == "dir-generator.php") continue;
|
pascal@456
|
361 if ($item == "robots.txt") continue;
|
pascal@456
|
362 if ($item == "humans.txt") continue;
|
pankso@166
|
363 if(is_dir($path.'/'.$item) and $item != '.' and $item != '..') {
|
pankso@166
|
364 $folderlist[] = array(
|
pankso@166
|
365 'name' => $item,
|
pankso@166
|
366 'size' => 0,
|
pankso@166
|
367 'modtime'=> filemtime($path.'/'.$item),
|
pankso@166
|
368 'modtimeasc'=> my_filemtimeasc($path.'/'.$item),
|
pankso@166
|
369 'file_type' => "Directory"
|
pankso@166
|
370 );
|
pankso@166
|
371 }
|
pankso@166
|
372 elseif(my_is_file($path.'/'.$item)) {
|
pankso@166
|
373 if(!$show_hidden_files) {
|
pankso@166
|
374 if(substr($item, 0, 1) == "." or substr($item, -1) == "~") {
|
pankso@166
|
375 continue;
|
pankso@166
|
376 }
|
pankso@166
|
377 }
|
pankso@166
|
378 $filelist[] = array(
|
pankso@166
|
379 'name'=> $item,
|
pankso@166
|
380 'size'=> my_filesize($path.'/'.$item),
|
pankso@166
|
381 'modtime'=> my_filemtime($path.'/'.$item),
|
pankso@166
|
382 'modtimeasc'=> my_filemtimeasc($path.'/'.$item),
|
pankso@166
|
383 'file_type' => get_file_type($path.'/'.$item)
|
pankso@166
|
384 );
|
pankso@166
|
385 }
|
pankso@166
|
386 }
|
pankso@166
|
387 closedir($handle);
|
pascal@587
|
388 file_put_contents($path."/.folderlist",serialize($folderlist),LOCK_EX);
|
pascal@587
|
389 file_put_contents($path."/.filelist",serialize($filelist),LOCK_EX);
|
pascal@280
|
390 }
|
pankso@166
|
391 }
|
pankso@166
|
392
|
pascal@282
|
393 if (isset($_GET['f'])) {
|
pascal@282
|
394 $filter = $_GET['f'];
|
pascal@282
|
395 if (substr($filter,0,1) != '/')
|
pascal@282
|
396 $filter = '/'.$filter.'/i';
|
pascal@282
|
397 foreach ($filelist as $key => $value)
|
pascal@282
|
398 if (!preg_match($filter,$value['name']))
|
pascal@282
|
399 unset($filelist[$key]);
|
pascal@282
|
400 foreach ($folderlist as $key => $value)
|
pascal@282
|
401 if (!preg_match($filter,$value['name']))
|
pascal@282
|
402 unset($folderlist[$key]);
|
pascal@282
|
403 }
|
pankso@166
|
404
|
pankso@166
|
405 if(!isset($_GET['s'])) {
|
pankso@166
|
406 $_GET['s'] = 'name';
|
pankso@166
|
407 }
|
pankso@166
|
408
|
pankso@166
|
409 // Figure out what to sort files by
|
pankso@166
|
410 $file_order_by = array();
|
pankso@166
|
411 foreach ($filelist as $key=>$row) {
|
pankso@166
|
412 $file_order_by[$key] = $row[$_GET['s']];
|
pankso@166
|
413 }
|
pankso@166
|
414
|
pankso@166
|
415 // Figure out what to sort folders by
|
pankso@166
|
416 $folder_order_by = array();
|
pankso@166
|
417 foreach ($folderlist as $key=>$row) {
|
pankso@166
|
418 $folder_order_by[$key] = $row[$_GET['s']];
|
pankso@166
|
419 }
|
pankso@166
|
420
|
pankso@166
|
421 // Order the files and folders
|
pankso@166
|
422 $sort_type = SORT_ASC;
|
pankso@166
|
423 $order = "&o=d";
|
pankso@166
|
424 if(isset($_GET['o'])) {
|
pankso@166
|
425 $sort_type = SORT_DESC;
|
pankso@166
|
426 $order = "";
|
pankso@166
|
427 }
|
pankso@166
|
428 array_multisort($folder_order_by, $sort_type, $folderlist);
|
pankso@166
|
429 array_multisort($file_order_by, $sort_type, $filelist);
|
pankso@166
|
430
|
pankso@166
|
431
|
pankso@166
|
432 // Show sort methods
|
pankso@166
|
433 print "<thead><tr>";
|
pankso@166
|
434
|
pankso@166
|
435 $sort_methods = array();
|
pankso@166
|
436 $sort_methods['name'] = "Name";
|
pankso@166
|
437 $sort_methods['modtime'] = "Last Modified";
|
pankso@166
|
438 $sort_methods['size'] = "Size";
|
pankso@166
|
439 $sort_methods['file_type'] = "Type";
|
pankso@166
|
440
|
pankso@166
|
441 foreach($sort_methods as $key=>$item) {
|
pankso@166
|
442 if ($_GET['s'] == $key) $key = "$key$order";
|
pankso@166
|
443 print "<th class='n'><a href='?s=$key'>$item</a></th>";
|
pankso@166
|
444 }
|
pankso@166
|
445 print "</tr></thead>\n<tbody>\n";
|
pankso@166
|
446
|
pankso@166
|
447
|
pankso@166
|
448
|
pankso@166
|
449 // Parent directory link
|
pankso@166
|
450 if($path != "./") {
|
pankso@166
|
451 print "<tr><td class='n'><a href='..'>Parent Directory</a>/</td>";
|
pankso@166
|
452 print "<td class='m'> </td>";
|
pankso@166
|
453 print "<td class='s'>- </td>";
|
pankso@166
|
454 print "<td class='t'>Directory</td></tr>\n";
|
pankso@166
|
455 }
|
pankso@166
|
456
|
pankso@166
|
457
|
pankso@166
|
458
|
pankso@166
|
459 // Print folder information
|
pankso@166
|
460 foreach($folderlist as $folder) {
|
pankso@166
|
461 print "<tr><td class='n'><a href='" . addslashes($folder['name']). "'>" .htmlentities($folder['name']). "</a>/</td>";
|
pankso@166
|
462 print "<td class='m'>" . $folder['modtimeasc'] . "</td>";
|
pankso@166
|
463 print "<td class='s'>- </td>";
|
pankso@166
|
464 print "<td class='t'>" . $folder['file_type'] . "</td></tr>\n";
|
pankso@166
|
465 }
|
pankso@166
|
466
|
pankso@166
|
467
|
pankso@166
|
468 // Print file information
|
pankso@166
|
469 foreach($filelist as $file) {
|
pascal@378
|
470 $url = addslashes($file['name']);
|
pascal@378
|
471 print "<tr><td class='n'><a href='$url'>" .htmlentities($file['name']). "</a></td>";
|
pascal@378
|
472 print "<td class='m'>" . $file['modtimeasc'] .
|
pascal@378
|
473 " <img src=\"/static/qr.png\" alt=\"@\" onmouseover=" .
|
pascal@353
|
474 "\"this.title = location.href+'$url'\" onclick=" .
|
pascal@379
|
475 "\"this.src = QRCodePNG(location.href+'$url', this) \"/></td>";
|
pascal@378
|
476 print "<td class='s'>" . format_bytes($file['size']) . "</td>";
|
pascal@378
|
477 print "<td class='t'>" . $file['file_type'] . "</td></tr>\n";
|
pankso@166
|
478 }
|
pankso@166
|
479
|
pankso@166
|
480 // Print ending stuff
|
pankso@166
|
481 $soft = explode('/',$_SERVER["SERVER_SOFTWARE"]);
|
pankso@166
|
482 $tag = get_conf('server.tag','"','"',$soft[0].' <'.$soft[1].'>');
|
pankso@166
|
483 print "</tbody>
|
pankso@166
|
484 </table>
|
pascal@378
|
485 ".count($folderlist)." folders and ".count($filelist)." files.</div>";
|
pascal@587
|
486 if (filesize($path."/README")) {
|
pascal@587
|
487 echo "<pre>\n";
|
pascal@587
|
488 echo file_get_contents($path."/README");
|
pascal@587
|
489 echo "</pre>\n";
|
pascal@587
|
490 }
|
pascal@587
|
491
|
pankso@166
|
492 if ($slitaz_style) { ?>
|
pankso@166
|
493
|
pankso@166
|
494 <!-- End of content -->
|
pankso@166
|
495 </div>
|
pankso@166
|
496
|
pankso@166
|
497 <!-- Footer -->
|
pankso@166
|
498 <div id="footer">
|
pankso@166
|
499 Copyright © <span class="year"></span>
|
pankso@166
|
500 <a href="http://www.slitaz.org/">SliTaz</a> - Network:
|
pankso@166
|
501 <a href="http://scn.slitaz.org/">Community</a>
|
pankso@166
|
502 <a href="http://doc.slitaz.org/">Doc</a>
|
pankso@166
|
503 <a href="http://forum.slitaz.org/">Forum</a>
|
pankso@166
|
504 <a href="http://pkgs.slitaz.org/">Packages</a>
|
pankso@166
|
505 <a href="http://bugs.slitaz.org">Bugs</a>
|
pascal@378
|
506 <a href="http://hg.slitaz.org/?sort=lastchange">Hg</a>
|
pankso@166
|
507 <p>
|
pascal@378
|
508 <img src="/static/qr.png" alt="#" onmouseover="this.title = location.href"
|
pascal@379
|
509 onclick="this.src = QRCodePNG(location.href, this)" />
|
pascal@378
|
510 SliTaz @
|
pankso@166
|
511 <a href="http://twitter.com/slitaz">Twitter</a>
|
pankso@166
|
512 <a href="http://www.facebook.com/slitaz">Facebook</a>
|
pankso@166
|
513 <a href="http://distrowatch.com/slitaz">Distrowatch</a>
|
pankso@166
|
514 <a href="http://en.wikipedia.org/wiki/SliTaz">Wikipedia</a>
|
pankso@166
|
515 <a href="http://flattr.com/profile/slitaz">Flattr</a>
|
pankso@166
|
516 </p>
|
pankso@166
|
517 <p>
|
pankso@166
|
518 <a href="http://validator.w3.org/check?uri=referer">
|
pascal@222
|
519 <img src="/static/xhtml10.png"
|
pankso@166
|
520 alt="Valid XHTML 1.0" title="Code validé XHTML 1.0"
|
pankso@166
|
521 style="width: 80px; height: 15px;" /></a>
|
pankso@166
|
522 </p>
|
pankso@166
|
523 </div>
|
pankso@166
|
524
|
pankso@166
|
525 <?php }
|
pankso@166
|
526 else print "
|
pankso@166
|
527 <form action='".$_SERVER["REQUEST_URI"]."' method='get'>
|
pankso@166
|
528 <div class='foot'>".$tag."
|
pankso@166
|
529 <input type='text' name='f'/>
|
pankso@166
|
530 <!-- <input type='submit' value='Filter' /> -->
|
pankso@166
|
531 </div>
|
pankso@166
|
532 </form>
|
pankso@166
|
533 ";
|
pankso@166
|
534 print "</body>
|
pankso@166
|
535 </html>";
|
pankso@166
|
536 ?>
|