slitaz-dev-tools view mirror-tools/var/www/slitaz/mirror/floppies/builder/index.php @ rev 5

Add /var/www/mirror-info/mirror from mirror-tools stuff.
author Christopher Rogers <slaxemulator@gmail.com>
date Thu Feb 24 01:29:50 2011 +0000 (2011-02-24)
parents
children
line source
1 <?php
2 if (false) { // no php support on this mirror !
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
7 <head>
8 <title>SliTaz Boot Floppies redirection</title>
9 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
10 <meta name="description" content="slitaz boot floppies builder redirection" />
11 <meta name="robots" content="index, nofollow" />
12 <meta name="author" content="SliTaz Contributors" />
13 <meta http-equiv="Refresh" content="0;url=http://mirror.slitaz.org/floppies/builder/index.php">
14 </head>
15 <?php
16 }
17 ini_set('upload_max_filesize','16M');
18 ini_set('post_max_size','16M');
19 if (isset($_GET['id']) && is_file("/tmp/".$_GET['id']."/fd")) {
21 // Download a floppy image
23 $size = $_GET['s'];
24 if ($size == 0)
25 $size = filesize("/tmp/".$_GET['id']."/fd");
26 header("Content-Type: application/octet-stream");
27 header("Content-Length: ".$size);
28 header("Content-Disposition: attachment; filename=".
29 sprintf("fd%03d.img",$_GET['n']));
30 $cmd = "cat /tmp/".$_GET['id']."/fd";
31 if ($_GET['s'] != 0) {
32 $cmd .= " /dev/zero | dd count=1 bs=".$_GET['s'];
33 if ($_GET['n'] > 1)
34 $cmd .= " skip=".($_GET['n']-1);
35 }
36 echo `$cmd 2> /dev/null`;
37 exit;
38 }
39 ?>
40 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
41 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
42 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
43 <head>
44 <title>SliTaz Boot Floppies</title>
45 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
46 <meta name="description" content="slitaz boot floppies builder" />
47 <meta name="robots" content="index, nofollow" />
48 <meta name="author" content="SliTaz Contributors" />
49 <link rel="shortcut icon" href="../../css/favicon.ico" />
50 <link rel="stylesheet" type="text/css" href="../../css/slitaz.css" />
51 <style>
52 input[type=text] {
53 width: inherit;
54 }
55 </style>
56 </head>
57 <body bgcolor="#ffffff">
58 <!-- Header -->
59 <div id="header">
60 <a name="top"></a>
61 <!-- Access -->
62 <div id="access">
63 <a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a> |
64 <a href="../../boot/floppy-grub4dos" title="Boot tools">Generic boot floppy</a>
65 </div>
66 <a href="http://www.slitaz.org/"><img id="logo" src="../../css/pics/website/logo.png" title="www.slitaz.org" alt="www.slitaz.org" style="border: 0px solid ; width: 200px; height: 74px;" /></a>
67 <p id="titre">#!/boot/floppies/builder</p>
68 </div>
70 <!-- Navigation menu -->
71 <div id="nav">
73 <?php
75 // Cleanup old sessions
77 $dir = opendir("/tmp");
78 while (($name = readdir($dir)) !== false) {
79 if (preg_match('/^fdbuild/',$name) == 0) continue;
80 if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
81 system("rm -rf /tmp/$name");
82 }
83 closedir($dir);
85 function get_long($file, $offset)
86 {
87 $value = 0;
88 if ($fp = fopen($file,"r")) {
89 fseek($fp,$offset,SEEK_SET);
90 for ($i = 0; $i < 32; $i += 8) {
91 $value += ord(fgetc($fp)) << $i;
92 }
93 fclose($fp);
94 }
95 return $value;
96 }
98 function error($string, $title="Error")
99 {
100 echo <<<EOT
101 <div class="nav_box">
102 <h4>$title</h4>
103 <p>
104 $string
105 </p>
106 </div>
107 EOT;
108 }
110 $size = 0;
111 $initrd_size = 0;
113 // Upload kernel
115 foreach($_FILES as $data) {
116 $msg="The file ".$_FILES["kernel"]['name']." ";
117 switch ($data["error"]) {
118 case UPLOAD_ERR_INI_SIZE :
119 error($msg."exceeds upload_max_filesize.");
120 break;
121 case UPLOAD_ERR_FORM_SIZE :
122 error($msg."exceeds max_post_size.");
123 break;
124 case UPLOAD_ERR_PARTIAL :
125 error($msg."was only partially uploaded.");
126 break;
127 case UPLOAD_ERR_NO_TMP_DIR :
128 error("Missing a temporary folder.");
129 break;
130 case UPLOAD_ERR_CANT_WRITE :
131 error("Failed to write file to disk.");
132 break;
133 }
134 }
135 if (isset($_FILES["kernel"]['tmp_name']) &&
136 is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
137 $tmp_dir = tempnam('','fdbuild');
138 if (file_exists($tmp_dir)) unlink($tmp_dir);
139 mkdir($tmp_dir);
140 $tmp_dir .= '/';
141 move_uploaded_file($_FILES["kernel"]['tmp_name'],
142 $tmp_dir."kernel");
143 $kernel = $tmp_dir."kernel";
144 $boot_version = get_long($kernel,0x206) & 255;
145 $size = get_long($kernel,0x1F4); // syssize paragraphs
146 if ($boot_version < 4) $size &= 0xFFFF; // 16 bits before 2.4
147 $size = ($size + 0xFFF) & 0xFFFF000; // round up to 64K
148 $size <<= 4; // paragraphs -> bytes
149 if (get_long($kernel,0x202) != 0x53726448 || // 'HdrS' magic
150 (get_long($kernel,0x211) & 1 != 1)) { // bzImage flag
151 error("The file ".$_FILES["kernel"]['name'].
152 " is not a bzImage Linux kernel.");
153 $size = 0;
154 }
155 else if ($boot_version < 2 && $_POST['cmdline']) { // before 2.2
156 unset($_POST['cmdline']);
157 error("This boot loader does not support Linux kernel ".
158 "prior 2.4.0-test3-pre3 command line.",
159 "Warning");
160 }
161 $msg = "The size of the file ".$_FILES["kernel"]['name'];
162 }
164 // Upload initrd
166 if ($size && isset($_FILES["initrd"]['tmp_name']) &&
167 is_uploaded_file($_FILES["initrd"]['tmp_name'])) {
168 move_uploaded_file($_FILES["initrd"]['tmp_name'],
169 $tmp_dir."initrd");
170 $initrd_size = $_FILES["initrd"]['size'];
171 $size += $initrd_size;
172 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
173 " and ".$_FILES["initrd"]['name'];
174 }
175 if ($initrd_size && isset($_FILES["initrd2"]['tmp_name']) &&
176 is_uploaded_file($_FILES["initrd2"]['tmp_name'])) {
177 move_uploaded_file($_FILES["initrd2"]['tmp_name'],
178 $tmp_dir."initrd2");
179 $initrd2_size = $_FILES["initrd2"]['size'];
180 $size += $initrd2_size;
181 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
182 ", ".$_FILES["initrd"]['name'].
183 " and ".$_FILES["initrd2"]['name'];
184 }
185 if ($size >= 15 * 1024 * 1024) {
186 error($msg." exceeds 15 MB.");
187 $size = 0;
188 }
189 if ($size == 0) {
190 if (isset($tmp_dir))
191 system("rm -f $tmp_dir");
192 }
193 else {
194 $cmd = "./bootloader ".$tmp_dir."kernel --prefix "
195 . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
196 . " --video ".$_POST['video'];
197 if ($_POST['cmdline'])
198 $cmd .= " --cmdline '".$_POST['cmdline']."'";
199 if (file_exists($_POST['rdev']))
200 $cmd .= " --rdev ".$_POST['rdev'];
201 if ($initrd_size)
202 $cmd .= " --initrd ".$tmp_dir."initrd";
203 if ($initrd2_size)
204 $cmd .= " --initrd ".$tmp_dir."initrd2";
205 switch ($_POST['size']) {
206 case 1763328 :
207 case 2015232 :
208 case 3526656 :
209 case 4030464 :
210 $cmd .= " --tracks 82"; break;
211 case 1784832 :
212 $cmd .= " --tracks 83"; break;
213 }
214 shell_exec($cmd);
215 $count = 1;
216 if ($_POST['size'] != 0) {
217 $count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
218 $padding = $_POST['size'] -
219 (filesize($tmp_dir."fd") % $_POST['size']);
220 }
221 }
222 $sizes = array(
223 "368640" => "360 KB", "737280" => "720 KB",
224 "1228800" => "1.20 MB",
225 "1474560" => "1.44 MB", "1638400" => "1.60 MB",
226 "1720320" => "1.68 MB", "1763328" => "1.72 MB",
227 "1784832" => "1.74 MB", "1802240" => "1.76 MB",
228 "1884160" => "1.84 MB", "1966080" => "1.92 MB",
229 "2015232" => "1.96 MB", "2949120" => "2.88 MB",
230 "3440640" => "3.36 MB", "3526656" => "3.44 MB",
231 "3932160" => "3.84 MB", "4030464" => "3.92 MB",
232 "0" => "no limit"
233 );
235 function show_size($size)
236 {
237 global $sizes;
238 if ($size != 0) return " ".$sizes[$size];
239 }
240 if (!isset($count)) {
241 ?>
242 <div class="nav_box">
243 <h4>How does it work ?</h4>
244 <p>
245 This tool updates the boot sector of your kernel with
246 <a href="http://hg.slitaz.org/wok/raw-file/b84ff32e3457/linux/stuff/linux-header-2.6.34.u">this patch</a>.
247 You may add a default cmdline and an initramfs. The cmdline can be edited at boot
248 time but the keyboard is not mandatory.
249 A <a href="bootloader"> standalone version</a> is available.
250 </p>
251 <p>
252 Each part (boot, setup, cmdline, kernel, initramfs) is aligned to 512 bytes.
253 The result is split to fit the floppy size.
254 The last floppy image is padded with zeros.
255 </p>
256 </div>
257 <?php
258 }
259 else {
260 ?>
261 <div class="nav_box">
262 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
263 <ul>
264 <?php
265 for ($i = 1; $i <= $count; $i++) {
266 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
267 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
268 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
269 show_size($_POST["size"])."</a></li>\n";
270 }
271 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
272 ?>
273 </div>
274 <?php
275 }
276 ?>
278 <!-- End navigation menu -->
279 </div>
281 <!-- Content top. -->
282 <div id="content_top">
283 <div class="top_left"></div>
284 <div class="top_right"></div>
285 </div>
287 <!-- Content -->
288 <div id="content">
290 <h1><font color="#3e1220">Boot</font></h1>
291 <h2><font color="#df8f06">Floppy image set builder</font></h2>
293 <?php
294 if (!isset($count)) {
295 $max = rtrim(ini_get('upload_max_filesize'),"M");
296 $max_post = rtrim(ini_get('post_max_size'),"M");
297 if ($max_post < $max) $max = $max_post;
298 $msg = "the tiny boot loader can't load more than 15 MB";
299 if ($max < 16)
300 $msg = "the web server can't upload more than $max MB";
301 ?>
302 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
303 <table>
304 <tr>
305 <td>Linux kernel:</td>
306 <td><input type="file" name="kernel" size="25" /> <i>required</i></td>
307 </tr>
308 <tr>
309 <td>Initramfs / Initrd:</td>
310 <td><input type="file" name="initrd" size="25" /> <i>optional</i></td>
311 </tr>
312 <tr>
313 <td>Extra initramfs:</td>
314 <td><input type="file" name="initrd2" size="25" /> <i>optional</i></td>
315 </tr>
316 <tr>
317 <td>Default cmdline:</td>
318 <td><input type="text" name="cmdline" size="36" <?php
319 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
320 ?>/> <i>optional</i></td>
321 </tr>
322 <tr>
323 <td>Root device:</td>
324 <td><input type="text" name="rdev" size="8" value="<?php
325 if (isset($_GET['rdev'])) echo $_GET['rdev'];
326 else echo "/dev/fd0";
327 ?>" />
328 &nbsp;&nbsp;Root flags: <select name="flags">
329 <option value="1">R/O</option>
330 <option value="0" <?php
331 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
332 echo ' selected="selected"'
333 ?>>R/W</option>
334 </select>
335 &nbsp;&nbsp;VGA mode: <select name="video">
336 <?php
337 $selected=-1;
338 if (isset($_GET['video'])) $selected = $_GET['video'];
339 $options = array();
340 $options[-3] = "Ask";
341 $options[-2] = "Ext";
342 $options[-1] = "Std";
343 for ($i = 0; $i < 64; $i++) $options[$i] = $i;
344 foreach ($options as $key => $value) {
345 echo '<option value="'.$key.'"';
346 if ($key == $selected || $value == $selected)
347 echo ' selected="selected"';
348 echo '>'.$value."</option>\n";
349 }
350 ?>
351 </select>
352 </td>
353 </tr>
354 <tr>
355 <td>Floppy size:</td>
356 <td><select name="size">
357 <?php
358 foreach ($sizes as $key => $value) {
359 echo " <option value=\"$key\"";
360 if ($key == "1474560") echo " selected='selected'";
361 echo ">$value</option>\n";
362 }
363 ?>
364 </select>
365 <input name="build" value="Build floppy set" type="submit" />
366 </td>
367 </tr>
368 </table>
369 </form>
370 <?php
371 echo <<<EOT
372 <p>
373 Note 1: $msg of files (kernel and initramfs) in memory.
374 </p>
375 <p>
376 Note 2: the extra initramfs may be useful to add your own configuration files.
377 </p>
378 EOT;
379 }
380 else {
381 ?>
383 <p>
384 You can write floppies with SliTaz <i>bootfloppybox</i>,
385 <a href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply dd:
386 </p>
387 <pre># dd if=fd001.img of=/dev/fd0
388 </pre>
390 <p>
391 Start your computer with <i>fd001.img</i>. It will show the kernel version string and
392 the kernel cmdline line. You can edit the cmdline. Most users can just press Enter.
393 </p>
395 <?php
396 if ($count >= 2) {
397 ?>
398 <p>
399 The floppy is then loaded into memory (one dot each 64k) and you will be prompted to
400 insert the next floppy, <i>fd002.img</i>. And so on.
401 </p>
403 <p>
404 The floppy set detects disk swaps and can be used without keyboard.
405 </p>
406 <?php
407 }
408 ?>
409 <p>
410 Good luck.
411 </p>
412 <?php
413 }
414 ?>
416 <!-- End of content with round corner -->
417 </div>
418 <div id="content_bottom">
419 <div class="bottom_left"></div>
420 <div class="bottom_right"></div>
421 </div>
423 <!-- Start of footer and copy notice -->
424 <div id="copy">
425 <p>
426 Copyright &copy; <?php echo date('Y'); ?> <a href="http://www.slitaz.org/">SliTaz</a> -
427 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
428 </p>
429 <!-- End of copy -->
430 </div>
432 <!-- Bottom and logo's -->
433 <div id="bottom">
434 <p>
435 <a href="http://validator.w3.org/check?uri=referer"><img src="../../css/pics/website/xhtml10.png" alt="Valid XHTML 1.0" title="Code validé XHTML 1.0" style="width: 80px; height: 15px;" /></a>
436 </p>
437 </div>
439 </body>
440 </html>