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