slitaz-dev-tools diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mirror-tools/var/www/slitaz/mirror/floppies/builder/index.php	Thu Feb 24 01:29:50 2011 +0000
     1.3 @@ -0,0 +1,440 @@
     1.4 +<?php
     1.5 +if (false) { // no php support on this mirror !
     1.6 +?>
     1.7 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     1.8 +	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     1.9 +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
    1.10 +<head>
    1.11 +	<title>SliTaz Boot Floppies redirection</title>
    1.12 +	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
    1.13 +	<meta name="description" content="slitaz boot floppies builder redirection" />
    1.14 +	<meta name="robots" content="index, nofollow" />
    1.15 +	<meta name="author" content="SliTaz Contributors" />
    1.16 +	<meta http-equiv="Refresh" content="0;url=http://mirror.slitaz.org/floppies/builder/index.php">
    1.17 +</head>
    1.18 +<?php
    1.19 +}
    1.20 +ini_set('upload_max_filesize','16M');
    1.21 +ini_set('post_max_size','16M');
    1.22 +if (isset($_GET['id']) && is_file("/tmp/".$_GET['id']."/fd")) {
    1.23 +
    1.24 +	// Download a floppy image
    1.25 +	
    1.26 +    	$size = $_GET['s'];
    1.27 +    	if ($size == 0)
    1.28 +    		$size = filesize("/tmp/".$_GET['id']."/fd");
    1.29 +	header("Content-Type: application/octet-stream");
    1.30 +	header("Content-Length: ".$size);
    1.31 +	header("Content-Disposition: attachment; filename=".
    1.32 +		sprintf("fd%03d.img",$_GET['n']));
    1.33 +	$cmd = "cat /tmp/".$_GET['id']."/fd";
    1.34 +	if ($_GET['s'] != 0) {
    1.35 +		$cmd .= " /dev/zero | dd count=1 bs=".$_GET['s'];
    1.36 +		if ($_GET['n'] > 1)
    1.37 +			$cmd .= " skip=".($_GET['n']-1);
    1.38 +	}
    1.39 +	echo `$cmd 2> /dev/null`;
    1.40 +	exit;
    1.41 +}
    1.42 +?>
    1.43 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    1.44 +	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    1.45 +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
    1.46 +<head>
    1.47 +	<title>SliTaz Boot Floppies</title>
    1.48 +	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
    1.49 +	<meta name="description" content="slitaz boot floppies builder" />
    1.50 +	<meta name="robots" content="index, nofollow" />
    1.51 +	<meta name="author" content="SliTaz Contributors" />
    1.52 +	<link rel="shortcut icon" href="../../css/favicon.ico" />
    1.53 +	<link rel="stylesheet" type="text/css" href="../../css/slitaz.css" />
    1.54 +	<style>
    1.55 +input[type=text] {
    1.56 +	width: inherit;
    1.57 +}
    1.58 +	</style>
    1.59 +</head>
    1.60 +<body bgcolor="#ffffff">
    1.61 +<!-- Header -->
    1.62 +<div id="header">
    1.63 +    <a name="top"></a>
    1.64 +<!-- Access -->
    1.65 +<div id="access">
    1.66 +	<a href="bootloader" title="Build your floppy sets without Internet">Shell builder</a> |
    1.67 +	<a href="../../boot/floppy-grub4dos" title="Boot tools">Generic boot floppy</a>
    1.68 +</div>   
    1.69 +	<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>
    1.70 +	<p id="titre">#!/boot/floppies/builder</p>
    1.71 +</div>
    1.72 +
    1.73 +<!-- Navigation menu -->
    1.74 +<div id="nav">
    1.75 +
    1.76 +<?php
    1.77 +
    1.78 +	// Cleanup old sessions
    1.79 +	
    1.80 +	$dir = opendir("/tmp");
    1.81 +	while (($name = readdir($dir)) !== false) {
    1.82 +		if (preg_match('/^fdbuild/',$name) == 0) continue;
    1.83 +		if (filemtime("/tmp/$name") > strtotime("-1 hour")) continue;
    1.84 +		system("rm -rf /tmp/$name");
    1.85 +	}
    1.86 +	closedir($dir);
    1.87 +
    1.88 +function get_long($file, $offset)
    1.89 +{
    1.90 +	$value = 0;
    1.91 +	if ($fp = fopen($file,"r")) {
    1.92 +		fseek($fp,$offset,SEEK_SET);
    1.93 +		for ($i = 0; $i < 32; $i += 8) {
    1.94 +			$value += ord(fgetc($fp)) << $i;
    1.95 +		}
    1.96 +		fclose($fp);
    1.97 +	}
    1.98 +	return $value;
    1.99 +}
   1.100 +
   1.101 +function error($string, $title="Error")
   1.102 +{
   1.103 +	echo <<<EOT
   1.104 +<div class="nav_box">
   1.105 +<h4>$title</h4>
   1.106 +<p>
   1.107 +$string
   1.108 +</p>
   1.109 +</div>
   1.110 +EOT;
   1.111 +}
   1.112 +
   1.113 +	$size = 0;
   1.114 +	$initrd_size = 0;
   1.115 +	
   1.116 +	// Upload kernel
   1.117 +	
   1.118 +	foreach($_FILES as $data) {
   1.119 +		$msg="The file ".$_FILES["kernel"]['name']." ";
   1.120 +		switch ($data["error"]) {
   1.121 +		case UPLOAD_ERR_INI_SIZE   : 
   1.122 +			error($msg."exceeds upload_max_filesize.");
   1.123 +			break;
   1.124 +		case UPLOAD_ERR_FORM_SIZE  : 
   1.125 +			error($msg."exceeds max_post_size.");
   1.126 +			break;
   1.127 +		case UPLOAD_ERR_PARTIAL    : 
   1.128 +			error($msg."was only partially uploaded.");
   1.129 +			break;
   1.130 +		case UPLOAD_ERR_NO_TMP_DIR : 
   1.131 +			error("Missing a temporary folder.");
   1.132 +			break;
   1.133 +		case UPLOAD_ERR_CANT_WRITE : 
   1.134 +			error("Failed to write file to disk.");
   1.135 +			break;
   1.136 +		}
   1.137 +	}
   1.138 +	if (isset($_FILES["kernel"]['tmp_name']) &&
   1.139 +	    is_uploaded_file($_FILES["kernel"]['tmp_name'])) {
   1.140 +		$tmp_dir = tempnam('','fdbuild');
   1.141 +		if (file_exists($tmp_dir)) unlink($tmp_dir);
   1.142 +		mkdir($tmp_dir);
   1.143 +		$tmp_dir .= '/';
   1.144 +		move_uploaded_file($_FILES["kernel"]['tmp_name'],
   1.145 +				   $tmp_dir."kernel");
   1.146 +		$kernel = $tmp_dir."kernel";
   1.147 +		$boot_version = get_long($kernel,0x206) & 255;
   1.148 +		$size = get_long($kernel,0x1F4);	// syssize paragraphs
   1.149 +		if ($boot_version < 4) $size &= 0xFFFF;	// 16 bits before 2.4
   1.150 +		$size = ($size + 0xFFF) & 0xFFFF000;	// round up to 64K
   1.151 +		$size <<= 4;				// paragraphs -> bytes
   1.152 +		if (get_long($kernel,0x202) != 0x53726448 ||	// 'HdrS' magic
   1.153 +		    (get_long($kernel,0x211) & 1 != 1)) {	// bzImage flag
   1.154 +			error("The file ".$_FILES["kernel"]['name'].
   1.155 +			      " is not a bzImage Linux kernel.");
   1.156 +			$size = 0;
   1.157 +		}
   1.158 +		else if ($boot_version < 2 && $_POST['cmdline']) { // before 2.2
   1.159 +			unset($_POST['cmdline']);
   1.160 +			error("This boot loader does not support Linux kernel ".
   1.161 +			      "prior 2.4.0-test3-pre3 command line.",
   1.162 +			      "Warning");
   1.163 +		}
   1.164 +		$msg = "The size of the file ".$_FILES["kernel"]['name'];
   1.165 +	}
   1.166 +	
   1.167 +	// Upload initrd
   1.168 +	
   1.169 +	if ($size && isset($_FILES["initrd"]['tmp_name']) &&
   1.170 +	    is_uploaded_file($_FILES["initrd"]['tmp_name'])) {
   1.171 +		move_uploaded_file($_FILES["initrd"]['tmp_name'],
   1.172 +				   $tmp_dir."initrd");
   1.173 +		$initrd_size = $_FILES["initrd"]['size'];
   1.174 +		$size += $initrd_size;
   1.175 +		$msg = "The total size of the files ".$_FILES["kernel"]['name'].
   1.176 +		       " and ".$_FILES["initrd"]['name'];
   1.177 +	}
   1.178 +	if ($initrd_size && isset($_FILES["initrd2"]['tmp_name']) &&
   1.179 +	    is_uploaded_file($_FILES["initrd2"]['tmp_name'])) {
   1.180 +		move_uploaded_file($_FILES["initrd2"]['tmp_name'],
   1.181 +				   $tmp_dir."initrd2");
   1.182 +		$initrd2_size = $_FILES["initrd2"]['size'];
   1.183 +		$size += $initrd2_size;
   1.184 +		$msg = "The total size of the files ".$_FILES["kernel"]['name'].
   1.185 +		       ", ".$_FILES["initrd"]['name'].
   1.186 +		       " and ".$_FILES["initrd2"]['name'];
   1.187 +	}
   1.188 +	if ($size >= 15 * 1024 * 1024) {
   1.189 +		error($msg." exceeds 15 MB.");
   1.190 +		$size = 0;
   1.191 +	}
   1.192 +	if ($size == 0) {
   1.193 +		if (isset($tmp_dir))
   1.194 +			system("rm -f $tmp_dir");
   1.195 +	}
   1.196 +	else {
   1.197 +		$cmd = "./bootloader ".$tmp_dir."kernel --prefix "
   1.198 +		     . $tmp_dir."fd --format 0 --flags ".$_POST['flags']
   1.199 +		     . " --video ".$_POST['video'];
   1.200 +		if ($_POST['cmdline'])
   1.201 +			$cmd .= " --cmdline '".$_POST['cmdline']."'";
   1.202 +		if (file_exists($_POST['rdev']))
   1.203 +			$cmd .= " --rdev ".$_POST['rdev'];
   1.204 +		if ($initrd_size)
   1.205 +			$cmd .= " --initrd ".$tmp_dir."initrd";
   1.206 +		if ($initrd2_size)
   1.207 +			$cmd .= " --initrd ".$tmp_dir."initrd2";
   1.208 +		switch ($_POST['size']) {
   1.209 +		case 1763328 : 
   1.210 +		case 2015232 : 
   1.211 +		case 3526656 :
   1.212 +		case 4030464 :
   1.213 +			$cmd .= " --tracks 82"; break;
   1.214 +		case 1784832 : 
   1.215 +			$cmd .= " --tracks 83"; break;
   1.216 +		}
   1.217 +		shell_exec($cmd);
   1.218 +		$count = 1;
   1.219 +		if ($_POST['size'] != 0) {
   1.220 +			$count += (filesize($tmp_dir."fd") -1) / $_POST['size'];
   1.221 +			$padding = $_POST['size'] - 
   1.222 +				(filesize($tmp_dir."fd") % $_POST['size']);
   1.223 +		}
   1.224 +	}
   1.225 +	$sizes = array(
   1.226 +		"368640" => "360 KB",   "737280" => "720 KB",
   1.227 +		"1228800" => "1.20 MB",
   1.228 +		"1474560" => "1.44 MB", "1638400" => "1.60 MB",
   1.229 +		"1720320" => "1.68 MB", "1763328" => "1.72 MB",
   1.230 +		"1784832" => "1.74 MB", "1802240" => "1.76 MB",
   1.231 +		"1884160" => "1.84 MB", "1966080" => "1.92 MB", 
   1.232 +		"2015232" => "1.96 MB", "2949120" => "2.88 MB",
   1.233 +		"3440640" => "3.36 MB", "3526656" => "3.44 MB",
   1.234 +		"3932160" => "3.84 MB", "4030464" => "3.92 MB",
   1.235 +		"0"       => "no limit"
   1.236 +	);
   1.237 +
   1.238 +function show_size($size)
   1.239 +{
   1.240 +	global $sizes;
   1.241 +	if ($size != 0) return " ".$sizes[$size];
   1.242 +}
   1.243 +	if (!isset($count)) {
   1.244 +?>
   1.245 +<div class="nav_box">
   1.246 +<h4>How does it work ?</h4>
   1.247 +<p>
   1.248 +This tool updates the boot sector of your kernel with
   1.249 +<a href="http://hg.slitaz.org/wok/raw-file/b84ff32e3457/linux/stuff/linux-header-2.6.34.u">this patch</a>.
   1.250 +You may add a default cmdline and an initramfs. The cmdline can be edited at boot
   1.251 +time but the keyboard is not mandatory.
   1.252 +A <a href="bootloader"> standalone version</a> is available.
   1.253 +</p>
   1.254 +<p>
   1.255 +Each part (boot, setup, cmdline, kernel, initramfs) is aligned to 512 bytes.
   1.256 +The result is split to fit the floppy size.
   1.257 +The last floppy image is padded with zeros.
   1.258 +</p>
   1.259 +</div>
   1.260 +<?php
   1.261 +	}
   1.262 +	else {
   1.263 +?>
   1.264 +<div class="nav_box">
   1.265 +<h4>Download image<?php if ($count >= 2) echo "s"; ?></h4>
   1.266 +<ul>
   1.267 +<?php
   1.268 +		for ($i = 1; $i <= $count; $i++) {
   1.269 +			echo '	<li><a href="'.$_SERVER["PHP_SELF"].
   1.270 +			     "?id=".basename($tmp_dir)."&amp;n=$i&amp;s=".
   1.271 +			     $_POST["size"].'">'.sprintf("fd%03d.img",$i).
   1.272 +			     show_size($_POST["size"])."</a></li>\n";
   1.273 +		}
   1.274 +		echo "</ul>\n".floor($padding/1024)."KB padding.\n";
   1.275 +?>
   1.276 +</div>
   1.277 +<?php
   1.278 +	}
   1.279 +?>
   1.280 +
   1.281 +<!-- End navigation menu -->
   1.282 +</div>
   1.283 +
   1.284 +<!-- Content top. -->
   1.285 +<div id="content_top">
   1.286 +<div class="top_left"></div>
   1.287 +<div class="top_right"></div>
   1.288 +</div>
   1.289 +
   1.290 +<!-- Content -->
   1.291 +<div id="content">
   1.292 +
   1.293 +<h1><font color="#3e1220">Boot</font></h1>
   1.294 +<h2><font color="#df8f06">Floppy image set builder</font></h2>
   1.295 +
   1.296 +<?php
   1.297 +	if (!isset($count)) {
   1.298 +		$max = rtrim(ini_get('upload_max_filesize'),"M");
   1.299 +		$max_post = rtrim(ini_get('post_max_size'),"M");
   1.300 +		if ($max_post < $max) $max = $max_post;
   1.301 +		$msg = "the tiny boot loader can't load more than 15 MB";
   1.302 +		if ($max < 16)
   1.303 +			$msg = "the web server can't upload more than $max MB";
   1.304 +?>
   1.305 +<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
   1.306 +<table>
   1.307 +	<tr>
   1.308 +	<td>Linux kernel:</td>
   1.309 +	<td><input type="file" name="kernel" size="25" /> <i>required</i></td>
   1.310 +	</tr>
   1.311 +	<tr>
   1.312 +	<td>Initramfs / Initrd:</td>
   1.313 +	<td><input type="file" name="initrd" size="25" /> <i>optional</i></td>
   1.314 +	</tr>
   1.315 +	<tr>
   1.316 +	<td>Extra initramfs:</td>
   1.317 +	<td><input type="file" name="initrd2" size="25" /> <i>optional</i></td>
   1.318 +	</tr>
   1.319 +	<tr>
   1.320 +	<td>Default cmdline:</td>
   1.321 +	<td><input type="text" name="cmdline" size="36" <?php 
   1.322 +		if (isset($_GET['cmdline'])) echo 'value="'.$_GET['cmdline'].'"';
   1.323 +	?>/> <i>optional</i></td>
   1.324 +	</tr>
   1.325 +	<tr>
   1.326 +	<td>Root device:</td>
   1.327 +	<td><input type="text" name="rdev" size="8" value="<?php
   1.328 +		if (isset($_GET['rdev'])) echo $_GET['rdev'];
   1.329 +		else echo "/dev/fd0";
   1.330 +	?>" />
   1.331 +	&nbsp;&nbsp;Root flags: <select name="flags">
   1.332 +		<option value="1">R/O</option>
   1.333 +		<option value="0" <?php
   1.334 +			if (isset($_GET['rdev']) && $_GET['rdev'] == "0")
   1.335 +				echo ' selected="selected"'
   1.336 +		?>>R/W</option>
   1.337 +	</select>
   1.338 +	&nbsp;&nbsp;VGA mode: <select name="video">
   1.339 +		<?php
   1.340 +			$selected=-1;
   1.341 +			if (isset($_GET['video'])) $selected = $_GET['video'];
   1.342 +			$options = array();
   1.343 +			$options[-3] = "Ask";
   1.344 +			$options[-2] = "Ext";
   1.345 +			$options[-1] = "Std";
   1.346 +			for ($i = 0; $i < 64; $i++) $options[$i] = $i;
   1.347 +			foreach ($options as $key => $value) {
   1.348 +				echo '<option value="'.$key.'"';
   1.349 +				if ($key == $selected || $value == $selected)
   1.350 +					echo ' selected="selected"';
   1.351 +				echo '>'.$value."</option>\n";
   1.352 +			}
   1.353 +		?>
   1.354 +	</select>
   1.355 +	</td>
   1.356 +	</tr>
   1.357 +	<tr>
   1.358 +	<td>Floppy size:</td>
   1.359 +	<td><select name="size">
   1.360 +<?php
   1.361 +	foreach ($sizes as $key => $value) {
   1.362 +		echo "		<option value=\"$key\"";
   1.363 +		if ($key == "1474560") echo " selected='selected'";
   1.364 +		echo ">$value</option>\n";
   1.365 +	}
   1.366 +?>
   1.367 +	</select>
   1.368 +		<input name="build" value="Build floppy set" type="submit" />
   1.369 +	</td>
   1.370 +	</tr>
   1.371 +</table>
   1.372 +</form>
   1.373 +<?php
   1.374 +		echo <<<EOT
   1.375 +<p>
   1.376 +Note 1: $msg of files (kernel and initramfs) in memory.
   1.377 +</p>
   1.378 +<p>
   1.379 +Note 2: the extra initramfs may be useful to add your own configuration files.
   1.380 +</p>
   1.381 +EOT;
   1.382 +	}
   1.383 +	else {
   1.384 +?>
   1.385 +
   1.386 +<p>
   1.387 +You can write floppies with SliTaz <i>bootfloppybox</i>, 
   1.388 +<a href="http://en.wikipedia.org/wiki/RaWrite">Windows rawrite</a> or simply dd:
   1.389 +</p>
   1.390 +<pre># dd if=fd001.img of=/dev/fd0
   1.391 +</pre>
   1.392 +
   1.393 +<p>
   1.394 +Start your computer with <i>fd001.img</i>. It will show the kernel version string and
   1.395 +the kernel cmdline line. You can edit the cmdline. Most users can just press Enter.
   1.396 +</p>
   1.397 +
   1.398 +<?php
   1.399 +		if ($count >= 2) {
   1.400 +?>
   1.401 +<p>
   1.402 +The floppy is then loaded into memory (one dot each 64k) and you will be prompted to
   1.403 +insert the next floppy, <i>fd002.img</i>. And so on.
   1.404 +</p>
   1.405 +
   1.406 +<p>
   1.407 +The floppy set detects disk swaps and can be used without keyboard.
   1.408 +</p>
   1.409 +<?php
   1.410 +		}
   1.411 +?>
   1.412 +<p>
   1.413 +Good luck.
   1.414 +</p>
   1.415 +<?php
   1.416 +	}
   1.417 +?>
   1.418 +
   1.419 +<!-- End of content with round corner -->
   1.420 +</div>
   1.421 +<div id="content_bottom">
   1.422 +<div class="bottom_left"></div>
   1.423 +<div class="bottom_right"></div>
   1.424 +</div>
   1.425 +
   1.426 +<!-- Start of footer and copy notice -->
   1.427 +<div id="copy">
   1.428 +<p>
   1.429 +Copyright &copy; <?php echo date('Y'); ?> <a href="http://www.slitaz.org/">SliTaz</a> -
   1.430 +<a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
   1.431 +</p>
   1.432 +<!-- End of copy -->
   1.433 +</div>
   1.434 +
   1.435 +<!-- Bottom and logo's -->
   1.436 +<div id="bottom">
   1.437 +<p>
   1.438 +<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>
   1.439 +</p>
   1.440 +</div>
   1.441 +
   1.442 +</body>
   1.443 +</html>