wok-6.x view mirror-tools/stuff/var/www/slitaz/mirror/floppies/builder/index.php @ rev 8067

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