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

mirror: add QR code
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Mar 20 18:32:44 2013 +0100 (2013-03-20)
parents dea449c5be89
children 41bfd0397973
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="/static/favicon.ico" />
50 <link rel="stylesheet" type="text/css" href="/static/slitaz.css" />
51 <style type="text/css">
53 input[type=text] {
54 width: inherit;
55 }
57 #content {
58 margin: 6px 280px 0px 0px;
59 padding: 0px 3% 20px 4%;
60 }
62 #nav {
63 right: 4%;
64 }
66 #copy {
67 text-align: center;
68 }
70 #bottom {
71 text-align: center;
72 }
74 </style>
75 </head>
76 <body bgcolor="#ffffff">
77 <!-- Header -->
78 <div id="header">
79 <a name="top"></a>
80 <div id="logo"></div>
81 <div id="network">
82 <a href="http://www.slitaz.org/">
83 <img src="/static/home.png" alt="[ home ]" /></a>
84 <a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a> |
85 <a href="../floppy-grub4dos" title="Boot tools">Generic boot floppy</a>
86 </div>
87 <h1><a href="http://www.slitaz.org/">Boot floppies builder</a></h1>
88 </div>
90 <!-- Navigation menu -->
91 <div id="nav">
93 <?php
95 // Cleanup old sessions
97 $dir = opendir("/tmp");
98 while (($name = readdir($dir)) !== false) {
99 if (preg_match('/^fdbuild/',$name) == 0) continue;
100 if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
101 system("rm -rf /tmp/$name");
102 }
103 closedir($dir);
105 function get_long($file, $offset)
106 {
107 $value = 0;
108 if ($fp = fopen($file,"r")) {
109 fseek($fp,$offset,SEEK_SET);
110 for ($i = 0; $i < 32; $i += 8) {
111 $value += ord(fgetc($fp)) << $i;
112 }
113 fclose($fp);
114 }
115 return $value;
116 }
118 function error($string, $title="Error")
119 {
120 echo <<<EOT
121 <div class="nav_box">
122 <h4>$title</h4>
123 <p>
124 $string
125 </p>
126 </div>
127 EOT;
128 }
130 $size = 0;
131 $initrd_size = 0;
133 // Upload kernel
135 foreach($_FILES as $data) {
136 $msg="The file ".$data['name']." ";
137 switch ($data["error"]) {
138 case UPLOAD_ERR_INI_SIZE :
139 error($msg."exceeds upload_max_filesize.");
140 break;
141 case UPLOAD_ERR_FORM_SIZE :
142 error($msg."exceeds max_post_size.");
143 break;
144 case UPLOAD_ERR_PARTIAL :
145 error($msg."was only partially uploaded.");
146 break;
147 case UPLOAD_ERR_NO_TMP_DIR :
148 error("Missing a temporary folder.");
149 break;
150 case UPLOAD_ERR_CANT_WRITE :
151 error("Failed to write file to disk.");
152 break;
153 }
154 }
155 if (isset($_FILES["kernel"]['tmp_name']) &&
156 is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
157 $tmp_dir = tempnam('','fdbuild');
158 if (file_exists($tmp_dir)) unlink($tmp_dir);
159 mkdir($tmp_dir);
160 $tmp_dir .= '/';
161 move_uploaded_file($_FILES["kernel"]['tmp_name'],
162 $tmp_dir."kernel");
163 $kernel = $tmp_dir."kernel";
164 $boot_version = get_long($kernel,0x206) & 255;
165 $size = get_long($kernel,0x1F4); // syssize paragraphs
166 if ($boot_version < 4) $size &= 0xFFFF; // 16 bits before 2.4
167 $size = ($size + 0xFFF) & 0xFFFF000; // round up to 64K
168 $size <<= 4; // paragraphs -> bytes
169 if (get_long($kernel,0x202) != 0x53726448 || // 'HdrS' magic
170 (get_long($kernel,0x211) & 1 != 1)) { // bzImage flag
171 error("The file ".$_FILES["kernel"]['name'].
172 " is not a bzImage Linux kernel.");
173 $size = 0;
174 }
175 else if ($boot_version < 2 && $_POST['cmdline']) { // before 2.2
176 unset($_POST['cmdline']);
177 error("This boot loader does not support Linux kernel ".
178 "prior 2.4.0-test3-pre3 command line.",
179 "Warning");
180 }
181 $msg = "The size of the file ".$_FILES["kernel"]['name'];
182 }
184 // Upload initrd
186 if ($size && isset($_FILES["initrd"]['tmp_name']) &&
187 is_uploaded_file($_FILES["initrd"]['tmp_name'])) {
188 move_uploaded_file($_FILES["initrd"]['tmp_name'],
189 $tmp_dir."initrd");
190 $initrd_size = $_FILES["initrd"]['size'];
191 $size += $initrd_size;
192 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
193 " and ".$_FILES["initrd"]['name'];
194 }
195 if ($initrd_size && isset($_FILES["initrd2"]['tmp_name']) &&
196 is_uploaded_file($_FILES["initrd2"]['tmp_name'])) {
197 move_uploaded_file($_FILES["initrd2"]['tmp_name'],
198 $tmp_dir."initrd2");
199 $initrd2_size = $_FILES["initrd2"]['size'];
200 $size += $initrd2_size;
201 $msg = "The total size of the files ".$_FILES["kernel"]['name'].
202 ", ".$_FILES["initrd"]['name'].
203 " and ".$_FILES["initrd2"]['name'];
204 }
205 if ($size >= 15 * 1024 * 1024) {
206 error($msg." exceeds 15 MB.");
207 $size = 0;
208 }
209 if ($size == 0) {
210 if (isset($tmp_dir))
211 system("rm -f $tmp_dir");
212 }
213 else {
214 $cmd = "./bootloader ".$tmp_dir."kernel --prefix "
215 . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
216 . " --video ".$_POST['video'];
217 if ($_POST['cmdline'])
218 $cmd .= " --cmdline '".$_POST['cmdline']."'";
219 if (file_exists($_POST['rdev']))
220 $cmd .= " --rdev ".$_POST['rdev'];
221 if ($initrd_size)
222 $cmd .= " --initrd ".$tmp_dir."initrd";
223 if ($initrd2_size)
224 $cmd .= " --initrd ".$tmp_dir."initrd2";
225 switch ($_POST['size']) {
226 case 1763328 :
227 case 2015232 :
228 case 3526656 :
229 case 4030464 :
230 $cmd .= " --tracks 82"; break;
231 case 1784832 :
232 $cmd .= " --tracks 83"; break;
233 }
234 shell_exec($cmd);
235 $count = 1;
236 if ($_POST['size'] != 0) {
237 $count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
238 $padding = $_POST['size'] -
239 (filesize($tmp_dir."fd") % $_POST['size']);
240 }
241 }
242 $sizes = array(
243 "368640" => "360 KB", "737280" => "720 KB",
244 "1228800" => "1.20 MB",
245 "1474560" => "1.44 MB", "1638400" => "1.60 MB",
246 "1720320" => "1.68 MB", "1763328" => "1.72 MB",
247 "1784832" => "1.74 MB", "1802240" => "1.76 MB",
248 "1884160" => "1.84 MB", "1966080" => "1.92 MB",
249 "2015232" => "1.96 MB", "2949120" => "2.88 MB",
250 "3440640" => "3.36 MB", "3526656" => "3.44 MB",
251 "3932160" => "3.84 MB", "4030464" => "3.92 MB",
252 "0" => "no limit"
253 );
255 function show_size($size)
256 {
257 global $sizes;
258 if ($size != 0) return " ".$sizes[$size];
259 }
260 ?>
262 <!-- End navigation menu -->
263 </div>
265 <!-- Content top. -->
266 <div id="content_top">
267 <div class="top_left"></div>
268 <div class="top_right"></div>
269 </div>
271 <!-- Content -->
272 <div id="content">
274 <h2>Floppy image set builder</h2>
276 <?php
277 if (!isset($count)) {
278 $max = rtrim(ini_get('upload_max_filesize'),"M");
279 $max_post = rtrim(ini_get('post_max_size'),"M");
280 if ($max_post < $max) $max = $max_post;
281 $msg = "the tiny boot loader can't load more than 15 MB";
282 if ($max < 16)
283 $msg = "the web server can't upload more than $max MB";
284 ?>
285 <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
286 <table>
287 <tr>
288 <td>Linux kernel:</td>
289 <td><input type="file" name="kernel" size="25" /> <i>required</i></td>
290 </tr>
291 <tr>
292 <td>Initramfs / Initrd:</td>
293 <td><input type="file" name="initrd" size="25" /> <i>optional</i></td>
294 </tr>
295 <tr>
296 <td>Extra initramfs:</td>
297 <td><input type="file" name="initrd2" size="25" /> <i>optional</i></td>
298 </tr>
299 <tr>
300 <td>Default cmdline:</td>
301 <td><input type="text" name="cmdline" size="36" <?php
302 if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
303 ?>/> <i>optional</i></td>
304 </tr>
305 <tr>
306 <td>Root device:</td>
307 <td><input type="text" name="rdev" size="8" value="<?php
308 if (isset($_GET['rdev'])) echo $_GET['rdev'];
309 else echo "/dev/fd0";
310 ?>" />
311 &nbsp;&nbsp;Flags: <select name="flags">
312 <option value="1">R/O</option>
313 <option value="0" <?php
314 if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
315 echo ' selected="selected"'
316 ?>>R/W</option>
317 </select>
318 &nbsp;&nbsp;VESA: <select name="video">
319 <?php
320 $selected=-1;
321 if (isset($_GET['video'])) $selected = $_GET['video'];
322 $options = array();
323 $options[-3] = "Ask";
324 $options[-2] = "Extended";
325 $options[-1] = "Standard";
326 for ($i = 0; $i < 16; $i++) $options[$i] = $i;
327 $options[0xF00] = "80x25";
328 $options[0xF01] = "80x50";
329 $options[0xF02] = "80x43";
330 $options[0xF03] = "80x28";
331 $options[0xF05] = "80x30";
332 $options[0xF06] = "80x34";
333 $options[0xF07] = "80x60";
334 $options[0x30A] = "132x43";
335 $options[0x309] = "132x25";
336 $options[0x338] = "320x200x8";
337 $options[0x30D] = "320x200x15";
338 $options[0x30E] = "320x200x16";
339 $options[0x332] = "320x240x8";
340 $options[0x335] = "320x240x16";
341 $options[0x333] = "400x300x8";
342 $options[0x336] = "400x300x16";
343 $options[0x334] = "512x384x8";
344 $options[0x337] = "512x384x16";
345 $options[0x300] = "640x400x8";
346 $options[0x339] = "640x400x16";
347 $options[0x301] = "640x480x8";
348 $options[0x310] = "640x480x15";
349 $options[0x311] = "640x480x16";
350 $options[0x312] = "640x480x24";
351 $options[0x33A] = "640x480x32";
352 //$options[770] = "800x600x4";
353 $options[0x303] = "800x600x8";
354 $options[0x313] = "800x600x15";
355 $options[0x314] = "800x600x16";
356 $options[0x315] = "800x600x24";
357 $options[0x33B] = "800x600x32";
358 //$options[772] = "1024x768x4";
359 $options[0x305] = "1024x768x8";
360 $options[0x316] = "1024x768x15";
361 $options[0x317] = "1024x768x16";
362 $options[0x318] = "1024x768x24";
363 $options[0x33C] = "1024x768x32";
364 $options[0x307] = "1280x1024x8";
365 $options[0x319] = "1280x1024x15";
366 $options[0x31A] = "1280x1024x16";
367 $options[0x31B] = "1280x1024x24";
368 $options[0x33D] = "1280x1024x32";
369 $options[0x330] = "1600x1200x8";
370 $options[0x331] = "1600x1200x16";
371 foreach ($options as $key => $value) {
372 echo '<option value="'.$key.'"';
373 if ($key == $selected || $value == $selected)
374 echo ' selected="selected"';
375 echo '>'.$value."</option>\n";
376 }
377 ?>
378 </select>
379 </td>
380 </tr>
381 <tr>
382 <td>Floppy size:</td>
383 <td><select name="size">
384 <?php
385 foreach ($sizes as $key => $value) {
386 echo " <option value=\"$key\"";
387 if ($key == "1474560") echo " selected='selected'";
388 echo ">$value</option>\n";
389 }
390 ?>
391 </select>&nbsp;
392 <input name="build" value="Build floppy set" type="submit" />
393 </td>
394 </tr>
395 </table>
396 </form>
397 <?php
398 echo <<<EOT
399 <p>
400 Note 1: $msg of files (kernel and initramfs) in memory.
401 </p>
402 <p>
403 Note 2: the extra initramfs may be useful to add your own configuration files.
404 </p>
405 EOT;
406 }
407 else {
408 ?>
409 <h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
410 <ul>
411 <?php
412 for ($i = 1; $i <= $count; $i++) {
413 echo ' <li><a href="'.$_SERVER["PHP_SELF"].
414 "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
415 $_POST["size"].'">'.sprintf("fd%03d.img",$i).
416 show_size($_POST["size"])."</a></li>\n";
417 }
418 echo "</ul>\n".floor($padding/1024)."KB padding.\n";
419 ?>
421 <p>
422 You can write floppies with SliTaz <i>bootfloppybox</i>,
423 <a href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply dd:
424 </p>
425 <pre># dd if=fd001.img of=/dev/fd0
426 </pre>
428 <p>
429 Start your computer with <i>fd001.img</i>. It will show the kernel version string and
430 the kernel cmdline line. You can edit the cmdline. Most users can just press Enter.
431 </p>
433 <?php
434 if ($count >= 2) {
435 ?>
436 <p>
437 The floppy is then loaded into memory (one dot each 64k) and you will be prompted to
438 insert the next floppy, <i>fd002.img</i>. And so on.
439 </p>
441 <p>
442 The floppy set detects disk swaps and can be used without a keyboard.
443 </p>
444 <?php
445 }
446 ?>
447 <p>
448 Good luck.
449 </p>
450 <?php
451 }
452 ?>
454 <div class="nav_box">
455 <h4>How does it work ?</h4>
456 <p>
457 This tool updates the boot sector of your kernel with
458 <a href="http://hg.slitaz.org/wok/raw-file/b84ff32e3457/linux/stuff/linux-header-2.6.34.u">this patch</a>.
459 You may add a default cmdline and an initramfs. The cmdline can be edited at boot
460 time but the keyboard is not mandatory.
461 A <a href="bootloader"> standalone version</a> is available.
462 </p>
463 <p>
464 Each part (boot, setup, cmdline, kernel, initramfs) is aligned to 512 bytes.
465 The result is split to fit the floppy size.
466 The last floppy image is padded with zeros.
467 </p>
468 <p>
469 You can extract the <u>kernel</u>, <u>cmdline</u> and <u>rootfs</u> files with
470 <a href="../floppies">this tool</a> from the floppy images.
471 </p>
472 </div>
474 <!-- End of content with round corner -->
475 </div>
476 <div id="content_bottom">
477 <div class="bottom_left"></div>
478 <div class="bottom_right"></div>
479 </div>
481 <!-- Start of footer and copy notice -->
482 <div id="copy">
483 <p>
484 Copyright &copy; <?php echo date('Y'); ?> <a href="http://www.slitaz.org/">SliTaz</a> -
485 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
486 </p>
487 <!-- End of copy -->
488 </div>
490 <!-- Bottom and logo's -->
491 <div id="bottom">
492 <p>
493 <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>
494 </p>
495 <p>
496 <img src="#" id="qrcodeimg" alt="#" width="60" height="60"
497 onclick= "this.width = this.height = 300;" />
498 <script type="text/javascript" src="/static/qrcode.js"></script>
499 <script type="text/javascript">
500 document.getElementById('qrcodeimg').src =
501 QRCode.generatePNG(location.href, {ecclevel: 'H'});
502 </script>
503 </p>
504 </div>
506 </body>
507 </html>