Project

General

Profile

Download (22.9 KB) Statistics
| Branch: | Tag: | Revision:
1 58fdcb9c Scott Ullrich
<?php
2
/*
3
	installer.php
4
	part of pfSense (http://www.pfsense.com/)
5
	Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
6
	All rights reserved.
7
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30 8af6efa6 Scott Ullrich
require("globals.inc");
31 58fdcb9c Scott Ullrich
require("guiconfig.inc");
32
33 083fbdd6 Scott Ullrich
define('PC_SYSINSTALL', '/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh');
34 dd4be2d0 Scott Ullrich
35 6bd7a614 Scott Ullrich
if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") {
36
	Header("Location: /index.php");
37
	exit;
38
}
39
40 5d4f96c6 Scott Ullrich
// Main switch dispatcher
41
switch ($_REQUEST['state']) {
42
	case "update_installer_status":
43
		update_installer_status();
44
		exit;
45 f988d2d9 Scott Ullrich
	case "custominstall":
46
		installer_custom();
47
		exit;
48
	case "begin_install":
49
		installing_gui();
50
		begin_install();
51
		exit;
52
	case "verify_before_install":
53
		verify_before_install();
54
		exit;
55 5d4f96c6 Scott Ullrich
	default:
56
		installer_main();	
57
}
58
59 2b69de49 Scott Ullrich
function write_out_pc_sysinstaller_config($disk, $fstype = "UFS+S", $swapsize = false) {
60 5a69cb06 Scott Ullrich
	$fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w");
61 58fdcb9c Scott Ullrich
	if(!$fd) {
62
		return true;
63
	}
64 a83744b4 Scott Ullrich
	if($swapsize <> "") {
65 81d22665 Scott Ullrich
		$diskareas =  "disk0-part=SWAP {$swapsize} none \n";
66 a83744b4 Scott Ullrich
		$diskareas .= "disk0-part={$fstype} 0 /\n";
67 2b69de49 Scott Ullrich
	} else {
68 a83744b4 Scott Ullrich
		$diskareas = "disk0-part={$fstype} 0 /\n";
69 2b69de49 Scott Ullrich
	}
70 58fdcb9c Scott Ullrich
	$config = <<<EOF
71
# Sample configuration file for an installation using pc-sysinstall
72
73
installMode=fresh
74
installInteractive=yes
75
installType=FreeBSD
76
installMedium=LiveCD
77
78
# Set the disk parameters
79
disk0={$disk}
80
partition=all
81
bootManager=bsd
82
commitDiskPart
83
84
# Setup the disk label
85
# All sizes are expressed in MB
86
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
87
# Size 0 means use the rest of the slice size
88 2b69de49 Scott Ullrich
{$diskareas}
89
90 58fdcb9c Scott Ullrich
# Do it now!
91
commitDiskLabel
92
93
# Set if we are installing via optical, USB, or FTP
94
installType=FreeBSD
95
96
packageType=cpdup
97
98
# Optional Components
99
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,sys,usr,var
100
101 369cc155 Scott Ullrich
# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh
102 58fdcb9c Scott Ullrich
EOF;
103
	fwrite($fd, $config);
104
	fclose($fd);
105
	return;
106
}
107
108
function start_installation() {
109 a33cb07c Scott Ullrich
	global $g, $fstype;
110 dcf479cf Scott Ullrich
	if(file_exists("/tmp/install_complete"))
111
		return;
112 1810b771 Scott Ullrich
	$ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'");
113
	if($ps_running)	
114
		return;
115 58fdcb9c Scott Ullrich
	$fd = fopen("/tmp/installer.sh", "w");
116 5d4f96c6 Scott Ullrich
	if(!$fd) {
117 65effce3 Rafael Lucas
		die(gettext("Could not open /tmp/installer.sh for writing"));
118 5d4f96c6 Scott Ullrich
		exit;
119 691f8475 Scott Ullrich
	}
120 4ec765b7 Scott Ullrich
	fwrite($fd, "rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n");
121 083fbdd6 Scott Ullrich
	fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n");
122 9c6421ee Scott Ullrich
	fwrite($fd, "chmod a+rx /usr/local/bin/after_installation_routines.sh\n");
123
	fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n");
124 1a99877d Scott Ullrich
	fwrite($fd, "mkdir /mnt/tmp\n");
125 f38e4f26 Scott Ullrich
//	fwrite($fd, "umount /mnt\n");
126 9c6421ee Scott Ullrich
	fwrite($fd, "touch /tmp/install_complete\n");
127 58fdcb9c Scott Ullrich
	fclose($fd);
128
	exec("chmod a+rx /tmp/installer.sh");
129
	mwexec_bg("sh /tmp/installer.sh");
130
}
131
132
function installer_find_first_disk() {
133 a33cb07c Scott Ullrich
	global $g, $fstype;
134 083fbdd6 Scott Ullrich
	$disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`;
135 58fdcb9c Scott Ullrich
	return $disk;
136
}
137
138 e318ec08 Scott Ullrich
function pcsysinstall_get_disk_info($diskname) {
139 5576ea3e Scott Ullrich
	global $g, $fstype;
140 083fbdd6 Scott Ullrich
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
141 5576ea3e Scott Ullrich
	$disks_array = array();
142
	foreach($disk as $d) {
143
		if(!$d) 
144
			continue;
145
		$disks_info = split(":", $d);
146
		$tmp_array = array();
147
		if($disks_info[0] == $diskname) {
148 083fbdd6 Scott Ullrich
			$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
149 5576ea3e Scott Ullrich
			foreach($disk_info as $di) { 
150
				$di_s = split("=", $di);
151
				if($di_s[0])
152
					$tmp_array[$di_s[0]] = $di_s[1];
153
			}
154
			$tmp_array['disk'] = trim($disks_info[0]);
155
			$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
156
			return $tmp_array;
157
		}
158
	}
159
}
160
161 dd4be2d0 Scott Ullrich
// Return an array with all disks information.
162
function installer_find_all_disks() {
163
	global $g, $fstype;
164 30b1013b Scott Ullrich
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
165 dd4be2d0 Scott Ullrich
	$disks_array = array();
166
	foreach($disk as $d) {
167 5cdb4299 Scott Ullrich
		if(!$d) 
168
			continue;
169 dd4be2d0 Scott Ullrich
		$disks_info = split(":", $d);
170
		$tmp_array = array();
171 083fbdd6 Scott Ullrich
		$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
172 dd4be2d0 Scott Ullrich
		foreach($disk_info as $di) { 
173
			$di_s = split("=", $di);
174
			if($di_s[0])
175
				$tmp_array[$di_s[0]] = $di_s[1];
176
		}
177
		$tmp_array['disk'] = trim($disks_info[0]);
178
		$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
179
		$disks_array[] = $tmp_array;
180
	}
181
	return $disks_array;
182
}
183
184 58fdcb9c Scott Ullrich
function update_installer_status() {
185 38405d27 Scott Ullrich
	global $g, $fstype;
186 8af6efa6 Scott Ullrich
	// Ensure status files exist
187
	if(!file_exists("/tmp/installer_installer_running"))
188
		touch("/tmp/installer_installer_running");
189 429650ed Scott Ullrich
	$status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`;
190 73531eb1 Scott Ullrich
	$status = str_replace("\n", "\\n", $status);
191
	$status = str_replace("\n", "\\r", $status);
192 8af6efa6 Scott Ullrich
	echo "this.document.forms[0].installeroutput.value='$status';\n";
193 429650ed Scott Ullrich
	echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n";	
194 8af6efa6 Scott Ullrich
	// Find out installer progress
195 8a4cf948 Scott Ullrich
	$progress = "5";
196
	if(strstr($status, "Running: dd")) 
197
		$progress = "6";
198
	if(strstr($status, "Running: gpart create -s GPT")) 
199
		$progress = "7";
200
	if(strstr($status, "Running: gpart bootcode")) 
201
		$progress = "7";
202
	if(strstr($status, "Running: newfs -U")) 
203
		$progress = "8";
204
	if(strstr($status, "Running: sync")) 
205
		$progress = "9";
206 8af6efa6 Scott Ullrich
	if(strstr($status, "/boot /mnt/boot")) 
207 73531eb1 Scott Ullrich
		$progress = "10";
208 8af6efa6 Scott Ullrich
	if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT"))
209 9c6421ee Scott Ullrich
		$progress = "11";
210 8af6efa6 Scott Ullrich
	if(strstr($status, "/bin /mnt/bin"))
211 9c6421ee Scott Ullrich
		$progress = "12";
212 8af6efa6 Scott Ullrich
	if(strstr($status, "/conf /mnt/conf"))
213 9c6421ee Scott Ullrich
		$progress = "15";
214 8af6efa6 Scott Ullrich
	if(strstr($status, "/conf.default /mnt/conf.default"))
215 9c6421ee Scott Ullrich
		$progress = "20";
216 8af6efa6 Scott Ullrich
	if(strstr($status, "/dev /mnt/dev"))
217 9c6421ee Scott Ullrich
		$progress = "25";
218 8af6efa6 Scott Ullrich
	if(strstr($status, "/etc /mnt/etc"))
219 9c6421ee Scott Ullrich
		$progress = "30";
220 8af6efa6 Scott Ullrich
	if(strstr($status, "/home /mnt/home"))
221 9c6421ee Scott Ullrich
		$progress = "35";
222 8af6efa6 Scott Ullrich
	if(strstr($status, "/kernels /mnt/kernels"))
223 9c6421ee Scott Ullrich
		$progress = "40";
224 8af6efa6 Scott Ullrich
	if(strstr($status, "/libexec /mnt/libexec"))
225 9c6421ee Scott Ullrich
		$progress = "50";
226 8af6efa6 Scott Ullrich
	if(strstr($status, "/lib /mnt/lib"))
227 9c6421ee Scott Ullrich
		$progress = "60";
228 8af6efa6 Scott Ullrich
	if(strstr($status, "/root /mnt/root"))
229 73531eb1 Scott Ullrich
		$progress = "70";
230 8af6efa6 Scott Ullrich
	if(strstr($status, "/sbin /mnt/sbin"))
231 73531eb1 Scott Ullrich
		$progress = "75";
232 8af6efa6 Scott Ullrich
	if(strstr($status, "/sys /mnt/sys"))
233 73531eb1 Scott Ullrich
		$progress = "80";
234 8af6efa6 Scott Ullrich
	if(strstr($status, "/usr /mnt/usr"))
235 73531eb1 Scott Ullrich
		$progress = "95";
236 8af6efa6 Scott Ullrich
	if(strstr($status, "/usr /mnt/usr"))
237
		$progress = "90";
238 73531eb1 Scott Ullrich
	if(strstr($status, "/var /mnt/var"))
239
		$progress = "95";
240 8a4cf948 Scott Ullrich
	if(strstr($status, "cap_mkdb /etc/login.conf"))
241
		$progress = "96";
242
	if(strstr($status, "Setting hostname"))
243
		$progress = "97";
244
	if(strstr($status, "umount -f /mnt"))
245
		$progress = "98";
246
	if(strstr($status, "umount -f /mnt"))
247
		$progress = "99";
248 8af6efa6 Scott Ullrich
	if(strstr($status, "Installation finished"))
249
		$progress = "100";
250 38405d27 Scott Ullrich
	// Check for error and bail if we see one.
251
	if(stristr($status, "error")) {
252
		$error = true;
253 dc3e6dea Scott Ullrich
		echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred.  Aborting installation.  <a href=\"installer.php\">Back</a> to webInstaller'; ";
254 38405d27 Scott Ullrich
		echo "\$('progressbar').style.width='100%';\n";
255 dc3e6dea Scott Ullrich
		unlink_if_exists("/tmp/install_complete");
256 58fdcb9c Scott Ullrich
		return;
257 38405d27 Scott Ullrich
	}
258 73531eb1 Scott Ullrich
	$running_old = trim(file_get_contents("/tmp/installer_installer_running"));
259
	if($installer_running <> "running") {
260
		$ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'");
261
		if($ps_running)	{
262 a33cb07c Scott Ullrich
			$running = "\$('installerrunning').innerHTML='<table><tr><td valign=\"middle\"><img src=\"/themes/{$g['theme']}/images/misc/loader.gif\"></td><td valign=\"middle\">&nbsp;<font size=\"2\"><b>Installer running ({$progress}% completed)...</td></tr></table>'; ";
263 73531eb1 Scott Ullrich
			if($running_old <> $running) {
264
				echo $running;
265
				file_put_contents("/tmp/installer_installer_running", "$running");			
266
			}
267
		}
268
	}
269
	if($progress) 
270
		echo "\$('progressbar').style.width='{$progress}%';\n";
271 58fdcb9c Scott Ullrich
	if(file_exists("/tmp/install_complete")) {
272 b12cc599 Scott Ullrich
		echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"+1\">Installation completed.  Please <a href=\"reboot.php\">reboot</a> to continue';\n";
273 3fcc3999 Scott Ullrich
		echo "\$('pbdiv').Fade();\n";
274 58fdcb9c Scott Ullrich
		unlink_if_exists("/tmp/installer.sh");
275 8af6efa6 Scott Ullrich
		file_put_contents("/tmp/installer_installer_running", "finished");
276 58fdcb9c Scott Ullrich
	}
277
}
278
279
function update_installer_status_win($status) {
280 a33cb07c Scott Ullrich
	global $g, $fstype;
281 58fdcb9c Scott Ullrich
	echo "<script type=\"text/javascript\">\n";
282 73531eb1 Scott Ullrich
	echo "	\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
283 58fdcb9c Scott Ullrich
	echo "</script>";
284
}
285
286 f988d2d9 Scott Ullrich
function begin_install() {
287
	global $g;
288 b5cff707 Scott Ullrich
	if(file_exists("/tmp/install_complete"))
289
		return;
290 58fdcb9c Scott Ullrich
	unlink_if_exists("/tmp/install_complete");
291 f988d2d9 Scott Ullrich
	if($_REQUEST['disk'])
292
		$disk = $_REQUEST['disk'];
293
	else 
294
		$disk = installer_find_first_disk();
295 58fdcb9c Scott Ullrich
	if(!$disk) {
296 f988d2d9 Scott Ullrich
		echo "<script type=\"text/javascript\">";
297 3fcc3999 Scott Ullrich
		echo "\$('pbdiv').Fade();\n";
298 f988d2d9 Scott Ullrich
		echo "</script>";
299 65effce3 Rafael Lucas
		$savemsg = gettext("Could not find a suitable disk for installation");
300
		update_installer_status_win(gettext("Could not find a suitable disk for installation."));
301 58fdcb9c Scott Ullrich
		return;
302
	}
303 f988d2d9 Scott Ullrich
	// Handle other type of file systems
304
	if($_REQUEST['fstype']) 
305
		$fstype = strtoupper($_REQUEST['fstype']);
306
	else 
307
		$fstype = "UFS+S";
308
	write_out_pc_sysinstaller_config($disk, $fstype);
309 65effce3 Rafael Lucas
	update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk));
310 58fdcb9c Scott Ullrich
	start_installation();
311
}
312
313 38405d27 Scott Ullrich
function head_html() {
314 a33cb07c Scott Ullrich
	global $g, $fstype;
315 38405d27 Scott Ullrich
	echo <<<EOF
316
<html>
317
	<head>
318
		<style type='text/css'>
319
			a:link { 
320
				color: #000000;
321
				text-decoration:underline;
322
				font-size:14;
323
			}
324
			a:visited { 
325
				color: #000000;
326
				text-decoration:underline;
327
				font-size:14;
328
			}
329
			a:hover { 
330
				color: #FFFF00;
331
				text-decoration: none;
332
				font-size:14;
333
			}
334
			a:active { 
335
				color: #FFFF00;
336
				text-decoration:underline;
337
				font-size:14;
338
			}
339
		</style>
340
	</head>
341
EOF;
342
343
}
344
345 5d4f96c6 Scott Ullrich
function body_html() {
346 a33cb07c Scott Ullrich
	global $g, $fstype;
347 5d4f96c6 Scott Ullrich
	$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
348
	if(strstr($pfSversion, "1.2"))
349
		$one_two = true;
350 97fc7767 Vinicius Coque
	$pgtitle = "{$g['product_name']}: " . gettext("Installer");
351 5d4f96c6 Scott Ullrich
	include("head.inc");
352
	echo <<<EOF
353
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
354
	<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
355 73531eb1 Scott Ullrich
	<script type="text/javascript">
356
		function getinstallerprogress() {
357
			url = 'installer.php';
358
			pars = 'state=update_installer_status';
359
			callajax(url, pars, installcallback);
360
		}
361
		function callajax(url, pars, activitycallback) {
362
			var myAjax = new Ajax.Request(
363
				url,
364
				{
365
					method: 'post',
366
					parameters: pars,
367
					onComplete: activitycallback
368
				});
369
		}
370
		function installcallback(transport) {
371
			setTimeout('getinstallerprogress()', 2000);
372
			eval(transport.responseText);
373
		}
374 5d4f96c6 Scott Ullrich
	</script>
375
EOF;
376 58fdcb9c Scott Ullrich
377 309b3a20 Scott Ullrich
	if($one_two)
378 5d4f96c6 Scott Ullrich
		echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
379 58fdcb9c Scott Ullrich
380 5d4f96c6 Scott Ullrich
	if ($savemsg) print_info_box($savemsg); 
381 58fdcb9c Scott Ullrich
}
382
383 5d4f96c6 Scott Ullrich
function end_html() {
384 a33cb07c Scott Ullrich
	global $g, $fstype;
385 5d4f96c6 Scott Ullrich
	echo "</form>";
386
	echo "</body>";
387
	echo "</html>";
388 58fdcb9c Scott Ullrich
}
389
390
function template() {
391 a33cb07c Scott Ullrich
	global $g, $fstype;
392 38405d27 Scott Ullrich
	head_html();
393 5d4f96c6 Scott Ullrich
	body_html();
394
	echo <<<EOF
395
	<div id="mainlevel">
396
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
397
	 		<tr>
398
	    		<td>
399
					<div id="mainarea">
400
						<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
401
							<tr>
402
	     						<td class="tabcont" >
403
	      							<form action="installer.php" method="post">
404
									<div id="pfsensetemplate">
405
406
407
									</div>
408
	     						</td>
409
							</tr>
410
						</table>
411
					</div>
412
				</td>
413
			</tr>
414
		</table>
415
	</div>
416 58fdcb9c Scott Ullrich
EOF;
417 5d4f96c6 Scott Ullrich
	end_html();
418 58fdcb9c Scott Ullrich
}
419
420 f988d2d9 Scott Ullrich
function verify_before_install() {
421
	global $g, $fstype;
422
	head_html();
423
	body_html();
424
	page_table_start();
425 e318ec08 Scott Ullrich
	$disk = pcsysinstall_get_disk_info($_REQUEST['disk']);
426 5576ea3e Scott Ullrich
	$disksize = format_bytes($disk['size'] * 1048576);
427 a83744b4 Scott Ullrich
	$swapsize = $_REQUEST['swapsize'];
428 f988d2d9 Scott Ullrich
	echo <<<EOF
429
	<form method="post" action="installer.php">
430
	<input type="hidden" name="fstype" value="{$_REQUEST['fstype']}">
431
	<input type="hidden" name="disk" value="{$_REQUEST['disk']}">
432
	<input type="hidden" name="state" value="begin_install">
433 a83744b4 Scott Ullrich
	<input type="hidden" name="swapsize" value="{$_REQUEST['swapsize']}">
434 f988d2d9 Scott Ullrich
	<div id="mainlevel">
435
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
436
	 		<tr>
437
	    		<td>
438
					<div id="mainarea">
439 fde4a93d Scott Ullrich
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
440 f988d2d9 Scott Ullrich
							<tr>
441 fde4a93d Scott Ullrich
	     						<td >
442 f988d2d9 Scott Ullrich
									<div>
443
										<center>
444
											<div id="pfsensetemplate">
445 4c394c0f Scott Ullrich
												<table bgcolor="FFFF00" width="400" height="30" cellpadding="2" style="border:1px dashed;">
446
													<tr valign="middle">
447 5576ea3e Scott Ullrich
														<td>
448
															<center><b>Please verify that the following is correct:</b></center>
449
														</td>
450
													</tr>
451 f988d2d9 Scott Ullrich
												</table>
452
												<p/>
453 5576ea3e Scott Ullrich
												<table>
454 846631ac Scott Ullrich
													<tr><td align="right"><b>Disk:</td><td>{$_REQUEST['disk']}</td></tr>
455
													<tr><td align="right"><b>Description:</td><td>{$disk['desc']}</td></tr>
456
													<tr><td align="right"><b>Size:</td><td>{$disksize}</td></tr>
457 a83744b4 Scott Ullrich
													<tr><td align="right"><b>SWAP Size:</td><td>{$_REQUEST['swapsize']}</td></tr>
458 846631ac Scott Ullrich
													<tr><td align="right"><b>Filesystem:</td><td>{$_REQUEST['fstype']}</td></tr>
459 5576ea3e Scott Ullrich
												</table>
460 f988d2d9 Scott Ullrich
											</div>
461
										</center>
462
									</div>
463
	     						</td>
464
							</tr>
465
						</table>
466
					</div>
467 5576ea3e Scott Ullrich
					<center>
468
						<p/>
469 e11d8f9c Scott Ullrich
						<input type="button" value="Cancel" onClick="javascript:document.location='/installer.php';"> &nbsp;&nbsp;
470 5576ea3e Scott Ullrich
						<input type="submit" value="Begin installation"> 
471
					</center>
472 f988d2d9 Scott Ullrich
				</td>
473
			</tr>
474
		</table>
475
	</div>
476
EOF;
477
	page_table_end();
478
	end_html();
479
}
480
481
function installing_gui() {
482 a33cb07c Scott Ullrich
	global $g, $fstype;
483 38405d27 Scott Ullrich
	head_html();
484 5d4f96c6 Scott Ullrich
	body_html();
485 73531eb1 Scott Ullrich
	echo "<form action=\"installer.php\" method=\"post\" state=\"step1_post\">";
486 8af6efa6 Scott Ullrich
	page_table_start();
487 58fdcb9c Scott Ullrich
	echo <<<EOF
488 8af6efa6 Scott Ullrich
	<center>
489
		<table width="100%">
490
		<tr><td>
491
			<div id="mainlevel">
492
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
493
			 		<tr>
494
			    		<td>
495
							<div id="mainarea">
496 824f539d Scott Ullrich
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
497 8af6efa6 Scott Ullrich
									<tr>
498 824f539d Scott Ullrich
			     						<td>
499 8af6efa6 Scott Ullrich
											<div id="pfsenseinstaller" width="100%">
500 50d44909 Scott Ullrich
												<div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000">
501 73531eb1 Scott Ullrich
													<table>
502
														<tr>
503
															<td valign="middle">
504
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
505
															</td>
506
															<td valign="middle">
507
																&nbsp;<font size="2"><b>Starting Installer...  Please wait...
508
															</td>
509
														</tr>
510
													</table>
511 8af6efa6 Scott Ullrich
												</div>
512 f988d2d9 Scott Ullrich
												<div id='pbdiv'>
513
													<br/>
514
													<center>
515
													<table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
516
														<tr>
517
															<td background="./themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
518
															</td>
519
															<td>
520
																<table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
521
																	<td background="./themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
522
																		<img src='./themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
523
																	</td>
524
																</table>
525
															</td>
526
															<td background="./themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
527
															</td>
528
														</tr>
529
													</table>
530
													<br/>
531
												</div>
532 691f8475 Scott Ullrich
												<textarea name='installeroutput' id='installeroutput' rows="31" cols="90">
533 8af6efa6 Scott Ullrich
												</textarea>
534
											</div>
535
			     						</td>
536
									</tr>
537
								</table>
538
							</div>
539
						</td>
540
					</tr>
541
				</table>
542
			</div>
543
		</td></tr>
544 5d4f96c6 Scott Ullrich
		</table>
545 8af6efa6 Scott Ullrich
	</center>
546 5d4f96c6 Scott Ullrich
	<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
547 8af6efa6 Scott Ullrich
548 58fdcb9c Scott Ullrich
EOF;
549 8af6efa6 Scott Ullrich
	page_table_end();
550 5d4f96c6 Scott Ullrich
	end_html();
551 58fdcb9c Scott Ullrich
}
552
553 8af6efa6 Scott Ullrich
function page_table_start() {
554 a33cb07c Scott Ullrich
	global $g, $fstype;
555 c9418f04 Scott Ullrich
	echo <<<EOF
556 8af6efa6 Scott Ullrich
	<center>
557 50d44909 Scott Ullrich
		<img border="0" src="./themes/{$g['theme']}/images/logo.gif"></a><br/>
558 e11d8f9c Scott Ullrich
		<table cellpadding="6" cellspacing="0" width="550" height="380" style="border:1px solid #000000">
559 8af6efa6 Scott Ullrich
		<tr height="10" bgcolor="#990000">
560
			<td style="border-bottom:1px solid #000000">
561
				<font color='white'>
562
					<b>
563 50d44909 Scott Ullrich
						{$g['product_name']} installer
564 8af6efa6 Scott Ullrich
					</b>
565
				</font>
566
			</td>
567
		</tr>
568
		<tr>
569
			<td>
570
571
EOF;
572
573
}
574
575
function page_table_end() {
576 a33cb07c Scott Ullrich
	global $g, $fstype;
577 8af6efa6 Scott Ullrich
	echo <<<EOF
578
			</td>
579
		</tr>
580
		</table>
581
	</center>
582
583
EOF;
584
	
585 58fdcb9c Scott Ullrich
}
586
587 dd4be2d0 Scott Ullrich
function installer_custom() {
588
	global $g, $fstype;
589
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
590
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
591
	head_html();
592
	body_html();
593
	page_table_start();
594
	echo <<<EOF
595 f988d2d9 Scott Ullrich
		<form action="installer.php" method="post">
596
			<input type="hidden" name="state" value="verify_before_install">
597 dd4be2d0 Scott Ullrich
			<div id="mainlevel">
598
				<center>
599
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
600
			 		<tr>
601
			    		<td>
602
							<center>
603
							<div id="mainarea">
604
								<br/>
605
								<center>
606
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
607
									<tr>
608
			     						<td>
609
											<div id="pfsenseinstaller">
610
												<center>
611 f988d2d9 Scott Ullrich
												<div id='loadingdiv'>
612
													<img src="/themes/{$g['theme']}/images/misc/loader.gif"> Probing disks, please wait...
613
												</div>
614
EOF;
615 086b0a2f Scott Ullrich
	ob_flush();
616 f988d2d9 Scott Ullrich
	$disks = installer_find_all_disks();
617
	if(!$disks)  {
618 374379c6 Scott Ullrich
		$custom_txt = gettext("ERROR: Could not find any suitable disks for installation.");
619 f988d2d9 Scott Ullrich
	} else {
620
		// Prepare disk selection dropdown
621 4c394c0f Scott Ullrich
		$custom_txt = <<<EOF
622
												<table bgcolor="FFFF00" width="400" height="30" cellpadding="2" style="border:1px dashed;">
623
													<tr valign="middle">
624
														<td>
625
															<center><b>Select the installation parameters for {$g['product_name']}:</b></center>
626
														</td>
627
													</tr>
628
												</table><p/>
629 1fb1f3fe Scott Ullrich
												<table>
630 4c394c0f Scott Ullrich
EOF;
631 a83744b4 Scott Ullrich
		$custom_txt .= "<tr><td align='right'><b>Swap size</td><td><input name='swapsize' type='text' value='200M'></td></tr>\n";
632 1fb1f3fe Scott Ullrich
		$custom_txt .= "<tr><td align='right'><b>Disk:</td><td><select name='disk'>\n";
633 5576ea3e Scott Ullrich
		foreach($disks as $disk) {
634
			$disksize = format_bytes($disk['size'] * 1048576);
635
			$custom_txt .= "<option value='{$disk['disk']}'>{$disk['disk']} - {$disksize} - {$disk['desc']}</option>\n";
636
		}
637 1fb1f3fe Scott Ullrich
		$custom_txt .= "</select></td></tr>\n";
638 c2185286 Scott Ullrich
		// XXX: Convert to rowhelper.  Add Ajax callbacks to verify sizes, etc.
639 f988d2d9 Scott Ullrich
		// Prepare disk types
640 1fb1f3fe Scott Ullrich
		$custom_txt .=  "<tr><td align='right'><b>Filesystem type:</td><td><select name='fstype'>\n";
641 18a4c6c5 Scott Ullrich
		$custom_txt .=  "<option value='UFS'>UFS</option>\n";
642
		$custom_txt .=  "<option value='UFS+S'>UFS + Softupdates</option>\n";
643 779476f6 Scott Ullrich
		$release = trim(`uname -r | cut -d'.' -f1`);
644
		if($release == "9")
645
			$custom_txt .=  "<option value='UFS+J'>UFS + Journaling</option>\n";
646 f988d2d9 Scott Ullrich
		if(file_exists("/boot/gptzfsboot")) 
647 18a4c6c5 Scott Ullrich
			$custom_txt .= "<option value='ZFS'>ZFS</option>\n";
648 1fb1f3fe Scott Ullrich
		$custom_txt .= "</select>\n</td></tr></table><p/>";
649 f988d2d9 Scott Ullrich
	}
650
	echo <<<EOF
651
													<script type="text/javascript">
652 1af1b216 Scott Ullrich
														\$('loadingdiv').style.visibility='hidden';
653 f988d2d9 Scott Ullrich
													</script>
654
													<div id='contentdiv' style="display:none;">
655
														{$custom_txt}<p/>
656 e11d8f9c Scott Ullrich
														<input type="button" value="Cancel" onClick="javascript:document.location='/installer.php';"> &nbsp;&nbsp
657
														<input type="submit" value="Next">
658 f988d2d9 Scott Ullrich
													</div>
659
													<script type="text/javascript">
660
														\$('contentdiv').appear();
661
													</script>
662
												</center>
663 1fb1f3fe Scott Ullrich
												</td></tr>
664
												</table>
665 dd4be2d0 Scott Ullrich
											</div>
666
			     						</td>
667
									</tr>
668
								</table>
669
							</div>
670
						</td>
671
					</tr>
672
				</table>
673
			</div>
674 e11d8f9c Scott Ullrich
675 dd4be2d0 Scott Ullrich
EOF;
676
	page_table_end();
677
	end_html();
678
}
679
680 58fdcb9c Scott Ullrich
function installer_main() {
681 a33cb07c Scott Ullrich
	global $g, $fstype;
682 8a4cf948 Scott Ullrich
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
683
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
684 38405d27 Scott Ullrich
	head_html();
685 5d4f96c6 Scott Ullrich
	body_html();
686 cf7cd237 Scott Ullrich
	$disk = installer_find_first_disk();
687 a33cb07c Scott Ullrich
	// Only enable ZFS if this exists.  The install will fail otherwise.
688
	if(file_exists("/boot/gptzfsboot")) 
689 2b69de49 Scott Ullrich
		$zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"installer.php?state=verify_before_install&fstype=ZFS&swapsize=200M\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>";
690 8af6efa6 Scott Ullrich
	page_table_start();
691 5d4f96c6 Scott Ullrich
	echo <<<EOF
692 8a4cf948 Scott Ullrich
		<form action="installer.php" method="post" state="step1_post">
693 8af6efa6 Scott Ullrich
			<div id="mainlevel">
694 8a4cf948 Scott Ullrich
				<center>
695 c3af202c Scott Ullrich
				<b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/>
696 50d44909 Scott Ullrich
				<font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font>
697 8af6efa6 Scott Ullrich
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
698
			 		<tr>
699
			    		<td>
700 8a4cf948 Scott Ullrich
							<center>
701 8af6efa6 Scott Ullrich
							<div id="mainarea">
702
								<br/>
703 8a4cf948 Scott Ullrich
								<center>
704 8af6efa6 Scott Ullrich
								Please select an installer option to begin:
705 1af1b216 Scott Ullrich
								<p/>
706 524b7a41 Scott Ullrich
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
707 8af6efa6 Scott Ullrich
									<tr>
708 524b7a41 Scott Ullrich
			     						<td>
709 8af6efa6 Scott Ullrich
											<div id="pfsenseinstaller">
710 8a4cf948 Scott Ullrich
												<center>
711 374379c6 Scott Ullrich
EOF;
712
	if(!$disk) {
713
		echo gettext("ERROR: Could not find any suitable disks for installation.");
714
		echo "</div></td></tr></table></div></table></div>";
715
		end_html();
716
		exit;
717
	}
718
	echo <<<EOF
719
720 1af1b216 Scott Ullrich
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
721 4c394c0f Scott Ullrich
														<tr bgcolor="#CECECE"><td align="center">
722 2b69de49 Scott Ullrich
															<a href="installer.php?state=verify_before_install&disk={$disk}&fstype=UFS&swapsize=200M">Easy installation of {$g['product_name']} using the UFS filesystem on disk {$disk}</a>
723 4c394c0f Scott Ullrich
														</td></tr>
724
													 	{$zfs_enabled}
725
														<tr bgcolor="#AAAAAA"><td align="center">
726
															<a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a>
727
														</td></tr>
728
														<tr bgcolor="#CECECE"><td align="center">
729
															<a href='/'>Cancel and return to Dashboard</a>
730
														</td></tr>
731
													</table>
732 f988d2d9 Scott Ullrich
												</center>
733 8af6efa6 Scott Ullrich
											</div>
734
			     						</td>
735
									</tr>
736
								</table>
737
							</div>
738
						</td>
739
					</tr>
740
				</table>
741
			</div>
742 58fdcb9c Scott Ullrich
EOF;
743 8af6efa6 Scott Ullrich
	page_table_end();
744 5d4f96c6 Scott Ullrich
	end_html();
745 58fdcb9c Scott Ullrich
}
746
747 63d7c442 Scott Ullrich
?>