slitaz-forge view mirror/floppies/builder/index.php @ rev 596

Web floppy builder: multiple initrd upload
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Aug 03 09:47:23 2015 +0200 (2015-08-03)
parents 8c02c699a951
children 4ea260d6c590
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://mirror1.slitaz.org/floppies/builder/index.php">
14 </head>
15 <body>
16 <script type="text/javascript">
17 window.location.replace('http://mirror1.slitaz.org/floppies/builder/index.php')
18 </script>
19 <noscript>
20 <frameset rows="100%">
21 <frame src="http://mirror1.slitaz.org/floppies/builder/index.php">
22 <noframes>
23 <body>Please follow <a href="http://mirror1.slitaz.org/floppies/builder/index.php
24 ">this link</a>.</body>
25 </noframes>
26 </frameset>
27 </noscript>
28 </body>
29 </html>
30 <?php
31 }
32 ini_set('upload_max_filesize','16M');
33 ini_set('post_max_size','16M');
34 if (isset($_GET['id']) && is_file("/tmp/".$_GET['id']."/fd")) {
36 // Download a floppy image
38 $size = $_GET['s'];
39 if ($size == 0)
40 $size = filesize("/tmp/".$_GET['id']."/fd");
41 header("Content-Type: application/octet-stream");
42 header("Content-Length: ".$size);
43 header("Content-Disposition: attachment; filename=".
44 sprintf("fd%03d.img",$_GET['n']));
45 $cmd = "cat /tmp/".$_GET['id']."/fd";
46 if ($_GET['s'] != 0) {
47 $cmd .= " /dev/zero | dd count=1 bs=".$_GET['s'];
48 if ($_GET['n'] > 1)
49 $cmd .= " skip=".($_GET['n']-1);
50 }
51 echo `$cmd 2> /dev/null`;
52 exit;
53 }
54 ?>
55 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
56 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
57 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
58 <head>
59 <title>SliTaz Boot Floppies</title>
60 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
61 <meta name="description" content="slitaz boot floppies builder" />
62 <meta name="robots" content="index, nofollow" />
63 <meta name="author" content="SliTaz Contributors" />
64 <link rel="shortcut icon" href="../static/favicon.ico" />
65 <link rel="stylesheet" type="text/css" href="../static/slitaz.css" />
66 <style type="text/css">
68 // input[type=submit] {
69 // cursor: pointer;
70 // }
72 input[type=text] {
73 width: inherit;
74 }
76 #content {
77 margin: 6px 280px 0px 0px;
78 padding: 0px 3% 20px 4%;
79 }
81 #nav {
82 right: 4%;
83 }
85 #copy {
86 text-align: center;
87 }
89 #bottom {
90 text-align: center;
91 }
93 // #cmdline:hover, #cmdline:foqus, #cmdline:not([value=""]) { width: 200px; }
94 // #cmdline { width: 50px; }
96 </style>
97 </head>
98 <body bgcolor="#ffffff">
99 <!-- Header -->
100 <div id="header">
101 <a name="top"></a>
102 <div id="logo"></div>
103 <div id="network">
104 <a href="http://www.slitaz.org/">
105 <img src="../static/home.png" alt="[ home ]" /></a>
106 <a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a> |
107 <a href="../floppy-grub4dos" title="Boot tools">Generic boot floppy</a>
108 </div>
109 <h1><a href="http://www.slitaz.org/">Boot floppies builder</a></h1>
110 </div>
112 <!-- Navigation menu -->
113 <div id="nav">
115 <?php
117 // Cleanup old sessions
119 $dir = opendir("/tmp");
120 while (($name = readdir($dir)) !== false) {
121 if (preg_match('/^fdbuild/',$name) == 0) continue;
122 if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
123 system("rm -rf /tmp/$name");
124 }
125 closedir($dir);
127 function get_long($file, $offset)
128 {
129 $value = 0;
130 if ($fp = fopen($file,"r")) {
131 fseek($fp,$offset,SEEK_SET);
132 for ($i = 0; $i < 32; $i += 8) {
133 $value += ord(fgetc($fp)) << $i;
134 }
135 fclose($fp);
136 }
137 return $value;
138 }
140 function error($string, $title="Error")
141 {
142 echo <<<EOT
143 <div class="nav_box">
144 <h4>$title</h4>
145 <p>
146 $string
147 </p>
148 </div>
149 EOT;
150 }
152 $size = 0;
153 $initrd_size = 0;
154 $info_size = 0;
156 // Upload kernel
158 foreach($_FILES as $data) {
159 $msg="The file ".$data['name']." ";
160 switch ($data["error"]) {
161 case UPLOAD_ERR_INI_SIZE :
162 error($msg."exceeds upload_max_filesize.");
163 break;
164 case UPLOAD_ERR_FORM_SIZE :
165 error($msg."exceeds max_post_size.");
166 break;
167 case UPLOAD_ERR_PARTIAL :
168 error($msg."was only partially uploaded.");
169 break;
170 case UPLOAD_ERR_NO_TMP_DIR :
171 error("Missing a temporary folder.");
172 break;
173 case UPLOAD_ERR_CANT_WRITE :
174 error("Failed to write file to disk.");
175 break;
176 }
177 }
178 if (isset($_FILES["kernel"]['tmp_name']) &&
179 is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
180 $tmp_dir = tempnam('','fdbuild');
181 if (file_exists($tmp_dir)) unlink($tmp_dir);
182 mkdir($tmp_dir);
183 $tmp_dir .= '/';
184 move_uploaded_file($_FILES["kernel"]['tmp_name'],
185 $tmp_dir."kernel");
186 $kernel = $tmp_dir."kernel";
187 $boot_version = get_long($kernel,0x206) & 255;
188 if (get_long($kernel,0x202) != 0x53726448) // 'HdrS' magic
189 $boot_version = 0;
190 $size = get_long($kernel,0x1F4); // syssize paragraphs
191 if ($boot_version < 4) $size &= 0xFFFF; // 16 bits before 2.4
192 $size = ($size + 0xFFF) & 0xFFFF000; // round up to 64K
193 $size <<= 4; // paragraphs -> bytes
194 $msg = "The size of the file ".$_FILES["kernel"]['name'];
195 }
197 if ($size && isset($_FILES["info"]['tmp_name']) &&
198 is_uploaded_file($_FILES["info"]['tmp_name'])) {
199 move_uploaded_file($_FILES["info"]['tmp_name'],
200 $tmp_dir."info");
201 $info_size = $_FILES["info"]['size'];
202 }
204 // Upload initrd
206 if ($size) for ($i = 0; $i < count($_FILES["initrd"]['name']); $i++)
207 if (isset($_FILES["initrd"]['tmp_name'][$i]) &&
208 is_uploaded_file($_FILES["initrd"]['tmp_name'][$i])) {
209 move_uploaded_file($_FILES["initrd"]['tmp_name'][$i],
210 $tmp_dir."initrd.".$i);
211 $initrd_cmd .= " --initrd ".$tmp_dir."initrd.".$i;
212 $initrd_size = $_FILES["initrd"]['size'][$i];
213 $size += $initrd_size;
214 if ($i == 0)
215 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
216 " and ".$_FILES["initrd"]['name'][$i];
217 else $msg .= ", ".$FILE["initrd"]['name'][$i];
218 }
219 if ($initrd_size) for ($i = 0; $i < count($_FILES["initrd2"]['name']); $i++)
220 if (isset($_FILES["initrd2"]['tmp_name'][$i]) &&
221 is_uploaded_file($_FILES["initrd2"]['tmp_name'][$i])) {
222 move_uploaded_file($_FILES["initrd2"]['tmp_name'][$i],
223 $tmp_dir."initrd2.".$i);
224 $initrd2_cmd .= " --initrd ".$tmp_dir."initrd2.".$i;
225 $initrd2_size = $_FILES["initrd2"]['size'][$i];
226 $size += $initrd2_size;
227 $msg .= ", ".$FILE["initrd2"]['name'][$i];
228 }
229 if ($size == 0) {
230 if (isset($tmp_dir))
231 system("rm -f $tmp_dir");
232 }
233 else {
234 $cmd = "./bootloader ".$tmp_dir."kernel --prefix "
235 . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
236 . " --video ".$_POST['video']." --mem ".$_POST['ram'];
237 if ($_POST['edit'] == "")
238 $cmd .= " --dont-edit-cmdline";
239 if ($_POST['cmdline'])
240 $cmd .= " --cmdline '".$_POST['cmdline']."'";
241 if ($info_size)
242 $cmd .= " --info ".$tmp_dir."info";
243 if (file_exists($_POST['rdev']))
244 $cmd .= " --rdev ".$_POST['rdev'];
245 if ($initrd_size)
246 $cmd .= $initrd_cmd;
247 if ($initrd2_size)
248 $cmd .= $initrd2_cmd;
249 switch ($_POST['size']) {
250 case 1763328 :
251 case 2015232 :
252 case 3526656 :
253 case 4030464 :
254 $cmd .= " --tracks 82"; break;
255 case 1784832 :
256 $cmd .= " --tracks 83"; break;
257 }
258 shell_exec($cmd);
259 $count = 1;
260 if ($_POST['size'] != 0) {
261 $count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
262 $padding = $_POST['size'] -
263 (filesize($tmp_dir."fd") % $_POST['size']);
264 }
265 }
266 $sizes = array(
267 "368640" => "360 KB", "737280" => "720 KB",
268 "1228800" => "1.20 MB",
269 "1474560" => "1.44 MB", "1638400" => "1.60 MB",
270 "1720320" => "1.68 MB", "1763328" => "1.72 MB",
271 "1784832" => "1.74 MB", "1802240" => "1.76 MB",
272 "1884160" => "1.84 MB", "1966080" => "1.92 MB",
273 "2015232" => "1.96 MB", "2949120" => "2.88 MB",
274 "3440640" => "3.36 MB", "3526656" => "3.44 MB",
275 "3932160" => "3.84 MB", "4030464" => "3.92 MB",
276 "0" => "no limit"
277 );
279 function show_size($size)
280 {
281 global $sizes;
282 if ($size != 0) return " ".$sizes[$size];
283 }
284 ?>
286 <!-- End navigation menu -->
287 </div>
289 <!-- Content top. -->
290 <div id="content_top">
291 <div class="top_left"></div>
292 <div class="top_right"></div>
293 </div>
295 <!-- Content -->
296 <div id="content">
298 <h2>Floppy image set builder</h2>
300 <?php
301 if (!isset($count)) {
302 $max = rtrim(ini_get('upload_max_filesize'),"M");
303 $max_post = rtrim(ini_get('post_max_size'),"M");
304 if ($max_post < $max) $max = $max_post;
305 $msg = "the web server can't upload more than $max MB";
306 ?>
307 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
308 <table>
309 <tr>
310 <td>Linux kernel:</td>
311 <td><input type="file" name="kernel" size="37" /> <i>required</i></td>
312 </tr>
313 <tr>
314 <td>Initramfs / Initrd:</td>
315 <td><input type="file" name="initrd[]" size="37" multiple /> <i>optional</i></td>
316 </tr>
317 <tr>
318 <td>Extra initramfs:</td>
319 <td><input type="file" name="initrd2[]" size="37" multiple /> <i>optional</i></td>
320 </tr>
321 <tr>
322 <td>Boot message:</td>
323 <td><input type="file" name="info" size="37" /> <i>optional</i></td>
324 </tr>
325 <tr>
326 <td>Default cmdline:</td>
327 <td id="cmdline"><input type="text" name="cmdline" size="36" <?php
328 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
329 ?>/> <input type="checkbox" name="edit" checked="checked" />edit
330 <i>optional</i></td>
331 </tr>
332 <tr>
333 <td>Root device:</td>
334 <td><input type="text" name="rdev" size="8" value="<?php
335 if (isset($_GET['rdev'])) echo $_GET['rdev'];
336 else echo "/dev/ram0";
337 ?>" />
338 &nbsp;&nbsp;Flags: <select name="flags">
339 <option value="1">R/O</option>
340 <option value="0" <?php
341 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
342 echo ' selected="selected"'
343 ?>>R/W</option>
344 </select>
345 &nbsp;&nbsp;VESA: <select name="video">
346 <?php
347 $selected=-1;
348 if (isset($_GET['video'])) $selected = $_GET['video'];
349 $options = array();
350 $options[-3] = "Ask";
351 $options[-2] = "Extended";
352 $options[-1] = "Standard";
353 for ($i = 0; $i < 16; $i++) $options[$i] = $i;
354 $options[0xF00] = "80x25";
355 $options[0xF01] = "80x50";
356 $options[0xF02] = "80x43";
357 $options[0xF03] = "80x28";
358 $options[0xF05] = "80x30";
359 $options[0xF06] = "80x34";
360 $options[0xF07] = "80x60";
361 $options[0x30A] = "132x43";
362 $options[0x309] = "132x25";
363 $options[0x338] = "320x200x8"; // 382?
364 $options[0x30D] = "320x200x15";
365 $options[0x30E] = "320x200x16";
366 $options[0x30F] = "320x200x24";
367 $options[0x320] = "320x200x32";
368 $options[0x332] = "320x240x8"; // 392?
369 $options[0x393] = "320x240x15";
370 $options[0x335] = "320x240x16";// 394?
371 $options[0x395] = "320x240x24";
372 $options[0x396] = "320x240x32";
373 $options[0x333] = "400x300x8";// 3A2?
374 $options[0x3A3] = "400x300x15";
375 $options[0x336] = "400x300x16";// 3A4?
376 $options[0x3A5] = "400x300x24";
377 $options[0x3A6] = "400x300x32";
378 $options[0x334] = "512x384x8";// 3B2?
379 $options[0x3B3] = "512x384x15";
380 $options[0x337] = "512x384x16";// 3B4?
381 $options[0x3B5] = "512x384x24";
382 $options[0x3B6] = "512x384x32";
383 $options[0x3C2] = "640x350x8";
384 $options[0x3C3] = "640x350x15";
385 $options[0x3C4] = "640x350x16";
386 $options[0x3C5] = "640x350x24";
387 $options[0x3C6] = "640x350x32";
388 $options[0x300] = "640x400x8";
389 $options[0x383] = "640x400x15";
390 $options[0x339] = "640x400x16";// 384?
391 $options[0x385] = "640x400x24";
392 $options[0x386] = "640x400x32";
393 $options[0x301] = "640x480x8";
394 $options[0x310] = "640x480x15";
395 $options[0x311] = "640x480x16";
396 $options[0x312] = "640x480x24";
397 $options[0x33A] = "640x480x32";// 321?
398 $options[879] = "800x500x8";
399 $options[880] = "800x500x15";
400 $options[881] = "800x500x16";
401 $options[882] = "800x500x24";
402 $options[883] = "800x500x32";
403 //$options[770] = "800x600x4";
404 $options[0x303] = "800x600x8";
405 $options[0x313] = "800x600x15";
406 $options[0x314] = "800x600x16";
407 $options[0x315] = "800x600x24";
408 $options[0x33B] = "800x600x32";//322?
409 $options[815] = "896x672x8";
410 $options[816] = "896x672x15";
411 $options[817] = "896x672x16";
412 $options[818] = "896x672x24";
413 $options[819] = "896x672x32";
414 $options[874] = "1024x640x8";
415 $options[875] = "1024x640x15";
416 $options[876] = "1024x640x16";
417 $options[877] = "1024x640x24";
418 $options[878] = "1024x640x32";
419 //$options[772] = "1024x768x4";
420 $options[0x305] = "1024x768x8";
421 $options[0x316] = "1024x768x15";
422 $options[0x317] = "1024x768x16";
423 $options[0x318] = "1024x768x24";
424 $options[0x33C] = "1024x768x32";//323?
425 $options[869] = "1152x720x8";
426 $options[870] = "1152x720x15";
427 $options[871] = "1152x720x16";
428 $options[872] = "1152x720x24";
429 $options[873] = "1152x720x32";
430 $options[0x307] = "1280x1024x8";
431 $options[0x319] = "1280x1024x15";
432 $options[0x31A] = "1280x1024x16";
433 $options[0x31B] = "1280x1024x24";
434 $options[0x33D] = "1280x1024x32";
435 $options[835] = "1400x1050x8";
436 $options[837] = "1400x1050x16";
437 $options[838] = "1400x1040x24";
438 $options[864] = "1440x900x8";
439 $options[864] = "1440x900x15";
440 $options[866] = "1440x900x16";
441 $options[867] = "1440x900x24";
442 $options[868] = "1440x900x32";
443 $options[0x330] = "1600x1200x8";
444 $options[0x331] = "1600x1200x16";
445 $options[893] = "1920x1200x8";
446 foreach ($options as $key => $value) {
447 echo '<option value="'.$key.'"';
448 if ($key == $selected || $value == $selected)
449 echo ' selected="selected"';
450 echo '>'.$value."</option>\n";
451 }
452 ?>
453 </select>
454 </td>
455 </tr>
456 <tr>
457 <td>Floppy size:</td>
458 <td><select name="size">
459 <?php
460 foreach ($sizes as $key => $value) {
461 switch ($key) {
462 case "368640" :
463 echo " <optgroup label=\"5&frac14; SD\">\n";
464 break;
465 case "737280" :
466 echo " </optgroup>\n";
467 echo " <optgroup label=\"3&frac12; SD\">\n";
468 break;
469 case "1228800" :
470 echo " </optgroup>\n";
471 echo " <optgroup label=\"5&frac14; HD\">\n";
472 break;
473 case "1474560" :
474 echo " </optgroup>\n";
475 echo " <optgroup label=\"3&frac12; HD\">\n";
476 break;
477 case "2949120" :
478 echo " </optgroup>\n";
479 echo " <optgroup label=\"3&frac12; ED\">\n";
480 break;
481 case "0" :
482 echo " </optgroup>\n";
483 break;
484 }
485 echo " <option value=\"$key\"";
486 if ($key == "1474560") echo " selected='selected'";
487 echo ">$value</option>\n";
488 }
489 ?>
490 </select>&nbsp;
491 RAM used&nbsp;<select name="ram">
492 <?php
493 for ($i = 16; $i >= 4; $i--)
494 echo " <option value=\"$i\">$i MB</option>\n";
495 ?>
496 </select>&nbsp;
497 <input name="build" value="Build floppy set" type="submit" />
498 </td>
499 </tr>
500 </table>
501 </form>
502 <?php
503 echo <<<EOT
504 <p>
505 Note 1: $msg of files (kernel and initramfs) in memory.
506 </p>
507 <p>
508 Note 2: the extra initramfs may be useful to add your own configuration files.
509 </p>
510 <p>
511 Note 3: the keyboard is read for ESC or ENTER on every form feed (ASCII 12) in the boot message.
512 </p>
513 EOT;
514 }
515 else {
516 ?>
517 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
518 <ul>
519 <?php
520 for ($i = 1; $i <= $count; $i++) {
521 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
522 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
523 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
524 show_size($_POST["size"])."</a></li>\n";
525 }
526 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
527 ?>
529 <p>
530 You can write floppies with SliTaz <i>bootfloppybox</i>,
531 <a href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply dd:
532 </p>
533 <pre># dd if=fd001.img of=/dev/fd0
534 </pre>
536 <p>
537 Start your computer with <i>fd001.img</i>. It will show the kernel version string and
538 the kernel cmdline line. You can edit the cmdline. Most users can just press Enter.
539 </p>
541 <?php
542 if ($count >= 2) {
543 ?>
544 <p>
545 The floppy is then loaded into memory (one dot each 64k) and you will be prompted to
546 insert the next floppy, <i>fd002.img</i>. And so on.
547 </p>
549 <p>
550 The floppy set detects disk swaps and can be used without a keyboard.
551 </p>
552 <?php
553 }
554 ?>
555 <p>
556 Good luck.
557 </p>
558 <?php
559 }
560 ?>
562 <div class="nav_box">
563 <h4>How does it work ?</h4>
564 <p>
565 This tool updates the boot sector of your kernel with
566 <a href="http://hg.slitaz.org/wok/raw-file/13835bce7189/syslinux/stuff/iso2exe/bootloader.S">this code</a>.
567 You may add a default cmdline and an initramfs. The cmdline can be edited at boot
568 time but the <acronym title="Check for disk swap every 5 seconds">keyboard is not mandatory</acronym>.
569 A <a href="bootloader"> standalone version</a> is available to break the web server upload limit.
570 </p>
571 <p>
572 Each part (boot, setup, boot message, cmdline, kernel, initramfs) is aligned to 512 bytes.
573 The result is split to fit the floppy size.
574 The last floppy image is padded with zeros.
575 </p>
576 <p>
577 You can extract the <u>kernel</u>, <u>cmdline</u> and <u>rootfs</u> files with
578 <a href="bootloader" title="./bootloader --extract floppy.*">this tool</a> from the floppy images.
579 </p>
580 </div>
582 <!-- End of content with round corner -->
583 </div>
584 <div id="content_bottom">
585 <div class="bottom_left"></div>
586 <div class="bottom_right"></div>
587 </div>
589 <!-- Start of footer and copy notice -->
590 <div id="copy">
591 <p>
592 Copyright &copy; <?php echo date('Y'); ?> <a href="http://www.slitaz.org/">SliTaz</a> -
593 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
594 </p>
595 <!-- End of copy -->
596 </div>
598 <!-- Bottom and logo's -->
599 <div id="bottom">
600 <p>
601 <a href="http://validator.w3.org/check?uri=referer"><img src="../static/xhtml10.png" alt="Valid XHTML 1.0" title="Code validé XHTML 1.0" style="width: 80px; height: 15px;" /></a>
602 </p>
603 <p>
604 <img src="#" id="qrcodeimg" alt="#" width="60" height="60"
605 onmouseover= "this.title = location.href"
606 onclick= "this.width = this.height = 300;" />
607 <script type="text/javascript" src="../static/qrcode.js"></script>
608 <script type="text/javascript">
609 document.getElementById('qrcodeimg').src =
610 QRCode.generatePNG(location.href, {ecclevel: 'H'});
611 </script>
612 </p>
613 </div>
615 </body>
616 </html>