Project

General

Profile

Download (38.4 KB) Statistics
| Branch: | Tag: | Revision:
1 8b590740 Scott Ullrich
<?php
2
/*
3 01184e21 Scott Ullrich
	installer.php (pfSense webInstaller)
4 8b590740 Scott Ullrich
	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
$nocsrf = true;
31
32
require("globals.inc");
33
require("guiconfig.inc");
34
35
define('PC_SYSINSTALL', '/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh');
36
37
if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") {
38 75a28755 Scott Ullrich
	Header("Location: /");
39 8b590740 Scott Ullrich
	exit;
40
}
41
42
// Main switch dispatcher
43
switch ($_REQUEST['state']) {
44
	case "update_installer_status":
45
		update_installer_status();
46
		exit;
47
	case "custominstall":
48
		installer_custom();
49
		exit;
50
	case "begin_install":
51
		installing_gui();
52
		begin_install();
53
		exit;
54
	case "verify_before_install":
55
		verify_before_install();
56
		exit;
57 60e70198 Scott Ullrich
	case "easy_install_ufs":
58
		easy_install("UFS+S");
59
		exit;
60
	case "easy_install_ufs":
61
		easy_install("ZFS");
62
		exit;
63
64 8b590740 Scott Ullrich
	default:
65
		installer_main();	
66
}
67
68 60e70198 Scott Ullrich
function easy_install($fstype = "UFS+S") {
69
	// Calculate swap and disk sizes
70
	$disks = installer_find_all_disks();
71
	$memory = get_memory();
72
	$swap_size = $memory[0] * 2;
73
	$first_disk = trim(installer_find_first_disk());
74
	$disk_info = pcsysinstall_get_disk_info($first_disk);
75
	$size = $disk_info['size'];
76
	$first_disk_size = $size - $swap_size;
77
	$disk_setup = array();
78
	$tmp_array = array();
79
	// Build the disk layout for /
80
	$tmp_array['disk'] = $first_disk;
81
	$tmp_array['size'] = $first_disk_size;
82
	$tmp_array['mountpoint'] = "/";
83
	$tmp_array['fstype'] = $fstype;
84
	$disk_setup[] = $tmp_array;
85 01184e21 Scott Ullrich
	unset($tmp_array);
86
	$tmp_array = array();
87 60e70198 Scott Ullrich
	// Build the disk layout for SWAP
88
	$tmp_array['disk'] = $first_disk;
89
	$tmp_array['size'] = $swap_size;
90
	$tmp_array['mountpoint'] = "none";
91
	$tmp_array['fstype'] = "SWAP";
92
	$disk_setup[] = $tmp_array;
93
	unset($tmp_array);
94
	$bootmanager = "bsd";
95
	file_put_contents("/tmp/webInstaller_disk_layout.txt", serialize($disk_setup));
96
	file_put_contents("/tmp/webInstaller_disk_bootmanager.txt", serialize($bootmanager));
97
	Header("Location: installer.php?state=verify_before_install");
98
	exit;
99
}
100
101 8b590740 Scott Ullrich
function write_out_pc_sysinstaller_config($disks, $bootmanager = "bsd") {
102
	$diskareas = "";
103
	$fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w");
104 01184e21 Scott Ullrich
	if(!$fd) 
105 8b590740 Scott Ullrich
		return true;
106
	if($bootmanager == "") 
107
	 	$bootmanager = "none";
108 01184e21 Scott Ullrich
	// Yes, -1.  We ++ early in loop.
109 8b590740 Scott Ullrich
	$numdisks = -1;
110
	$lastdisk = "";
111
	$diskdefs = "";
112
	// Run through the disks and create the conf areas for pc-sysinstaller
113
	foreach($disks as $disksa) {
114
		$fstype = $disksa['fstype'];
115
		$size = $disksa['size'];
116
		$mountpoint = $disksa['mountpoint'];
117
		$disk = $disksa['disk'];
118
		if($disk <> $lastdisk) {
119
			$lastdisk = $disk;
120
			$numdisks++;
121 a3ccdf6e Scott Ullrich
			$diskdefs .= "# disk {$disk}\n";
122 8b590740 Scott Ullrich
			$diskdefs .= "disk{$numdisks}={$disk}\n";
123 9c7b9ba0 Scott Ullrich
			$diskdefs .= "partition=all\n";
124
			$diskdefs .= "bootManager={$bootmanager}\n";
125 a3ccdf6e Scott Ullrich
			$diskdefs .= "commitDiskPart\n\n";
126 8b590740 Scott Ullrich
		}
127
		$diskareas .= "disk{$numdisks}-part={$fstype} {$size} {$mountpoint} \n";
128
		if($encpass)
129
			$diskareas .= "encpass={$encpass}\n";
130
	}
131
	
132
	$config = <<<EOF
133
# Sample configuration file for an installation using pc-sysinstall
134 d4e79776 Scott Ullrich
# This file was automatically generated by installer.php
135
 
136 8b590740 Scott Ullrich
installMode=fresh
137
installInteractive=yes
138
installType=FreeBSD
139
installMedium=LiveCD
140
141
# Set the disk parameters
142
{$diskdefs}
143
144
# Setup the disk label
145
# All sizes are expressed in MB
146
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
147
# Size 0 means use the rest of the slice size
148
# Alternatively, you can append .eli to any of
149
# the above filesystem types to encrypt that disk.
150
# If you with to use a passphrase with this 
151
# encrypted partition, on the next line 
152
# the flag "encpass=" should be entered:
153
# encpass=mypass
154
# disk0-part=UFS 500 /boot
155
# disk0-part=UFS.eli 500 /
156
# disk0-part=UFS.eli 500 /usr
157
{$diskareas}
158
159
# Do it now!
160
commitDiskLabel
161
162
# Set if we are installing via optical, USB, or FTP
163
installType=FreeBSD
164
165
packageType=cpdup
166
167
# Optional Components
168
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,usr,var
169
170
# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh
171
EOF;
172
	fwrite($fd, $config);
173
	fclose($fd);
174
	return;
175
}
176
177
function start_installation() {
178 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
179 8b590740 Scott Ullrich
	if(file_exists("/tmp/install_complete"))
180
		return;
181 40f9accf Scott Ullrich
	$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
182 8b590740 Scott Ullrich
	if($ps_running)	
183
		return;
184
	$fd = fopen("/tmp/installer.sh", "w");
185
	if(!$fd) {
186
		die(gettext("Could not open /tmp/installer.sh for writing"));
187
		exit;
188
	}
189 40f9accf Scott Ullrich
	fwrite($fd, "/bin/rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n");
190 8b590740 Scott Ullrich
	fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n");
191 40f9accf Scott Ullrich
	fwrite($fd, "/bin/chmod a+rx /usr/local/bin/after_installation_routines.sh\n");
192 8b590740 Scott Ullrich
	fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n");
193 40f9accf Scott Ullrich
	fwrite($fd, "/bin/mkdir /mnt/tmp\n");
194
	fwrite($fd, "/usr/bin/touch /tmp/install_complete\n");
195 8b590740 Scott Ullrich
	fclose($fd);
196 40f9accf Scott Ullrich
	exec("/bin/chmod a+rx /tmp/installer.sh");
197
	mwexec_bg("/bin/sh /tmp/installer.sh");
198 8b590740 Scott Ullrich
}
199
200
function installer_find_first_disk() {
201 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
202 8b590740 Scott Ullrich
	$disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`;
203
	return trim($disk);
204
}
205
206
function pcsysinstall_get_disk_info($diskname) {
207 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
208 cfbfd941 smos
	$disk = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
209 8b590740 Scott Ullrich
	$disks_array = array();
210
	foreach($disk as $d) {
211 cfbfd941 smos
		$disks_info = explode(":", $d);
212 8b590740 Scott Ullrich
		$tmp_array = array();
213
		if($disks_info[0] == $diskname) {
214 cfbfd941 smos
			$disk_info = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
215
			$disk_info_split = explode("=", $disk_info);
216 8b590740 Scott Ullrich
			foreach($disk_info as $di) { 
217 cfbfd941 smos
				$di_s = explode("=", $di);
218 8b590740 Scott Ullrich
				if($di_s[0])
219
					$tmp_array[$di_s[0]] = $di_s[1];
220
			}
221 bfff9331 Scott Ullrich
			$tmp_array['size']--;
222 8b590740 Scott Ullrich
			$tmp_array['disk'] = trim($disks_info[0]);
223
			$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
224
			return $tmp_array;
225
		}
226
	}
227
}
228
229
// Return an array with all disks information.
230
function installer_find_all_disks() {
231 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
232 cfbfd941 smos
	$disk = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
233 8b590740 Scott Ullrich
	$disks_array = array();
234
	foreach($disk as $d) {
235
		if(!$d) 
236
			continue;
237 cfbfd941 smos
		$disks_info = explode(":", $d);
238 8b590740 Scott Ullrich
		$tmp_array = array();
239 cfbfd941 smos
		$disk_info = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
240 8b590740 Scott Ullrich
		foreach($disk_info as $di) { 
241 cfbfd941 smos
			$di_s = explode("=", $di);
242 8b590740 Scott Ullrich
			if($di_s[0])
243
				$tmp_array[$di_s[0]] = $di_s[1];
244
		}
245 bfff9331 Scott Ullrich
		$tmp_array['size']--;
246 8b590740 Scott Ullrich
		$tmp_array['disk'] = trim($disks_info[0]);
247
		$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
248
		$disks_array[] = $tmp_array;
249
	}
250
	return $disks_array;
251
}
252
253
function update_installer_status() {
254 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
255 8b590740 Scott Ullrich
	// Ensure status files exist
256
	if(!file_exists("/tmp/installer_installer_running"))
257
		touch("/tmp/installer_installer_running");
258
	$status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`;
259
	$status = str_replace("\n", "\\n", $status);
260
	$status = str_replace("\n", "\\r", $status);
261 30a8ef77 Vinicius Coque
	$status = str_replace("'", "\\'", $status);
262
	echo "document.forms[0].installeroutput.value='$status';\n";
263
	echo "document.forms[0].installeroutput.scrollTop = document.forms[0].installeroutput.scrollHeight;\n";	
264 8b590740 Scott Ullrich
	// Find out installer progress
265
	$progress = "5";
266
	if(strstr($status, "Running: dd")) 
267
		$progress = "6";
268
	if(strstr($status, "Running: gpart create -s GPT")) 
269
		$progress = "7";
270
	if(strstr($status, "Running: gpart bootcode")) 
271
		$progress = "7";
272
	if(strstr($status, "Running: newfs -U")) 
273
		$progress = "8";
274
	if(strstr($status, "Running: sync")) 
275
		$progress = "9";
276
	if(strstr($status, "/boot /mnt/boot")) 
277
		$progress = "10";
278
	if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT"))
279
		$progress = "11";
280
	if(strstr($status, "/bin /mnt/bin"))
281
		$progress = "12";
282
	if(strstr($status, "/conf /mnt/conf"))
283
		$progress = "15";
284
	if(strstr($status, "/conf.default /mnt/conf.default"))
285
		$progress = "20";
286
	if(strstr($status, "/dev /mnt/dev"))
287
		$progress = "25";
288
	if(strstr($status, "/etc /mnt/etc"))
289
		$progress = "30";
290
	if(strstr($status, "/home /mnt/home"))
291
		$progress = "35";
292
	if(strstr($status, "/kernels /mnt/kernels"))
293
		$progress = "40";
294
	if(strstr($status, "/libexec /mnt/libexec"))
295
		$progress = "50";
296
	if(strstr($status, "/lib /mnt/lib"))
297
		$progress = "60";
298
	if(strstr($status, "/root /mnt/root"))
299
		$progress = "70";
300
	if(strstr($status, "/sbin /mnt/sbin"))
301
		$progress = "75";
302
	if(strstr($status, "/sys /mnt/sys"))
303
		$progress = "80";
304
	if(strstr($status, "/usr /mnt/usr"))
305
		$progress = "95";
306
	if(strstr($status, "/usr /mnt/usr"))
307
		$progress = "90";
308
	if(strstr($status, "/var /mnt/var"))
309
		$progress = "95";
310
	if(strstr($status, "cap_mkdb /etc/login.conf"))
311
		$progress = "96";
312
	if(strstr($status, "Setting hostname"))
313
		$progress = "97";
314
	if(strstr($status, "umount -f /mnt"))
315
		$progress = "98";
316
	if(strstr($status, "umount -f /mnt"))
317
		$progress = "99";
318
	if(strstr($status, "Installation finished"))
319
		$progress = "100";
320
	// Check for error and bail if we see one.
321
	if(stristr($status, "error")) {
322
		$error = true;
323 30a8ef77 Vinicius Coque
		echo "\$('#installerrunning').html('<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred.  Aborting installation.  <a href=\"/installer\">Back</a> to webInstaller'); ";
324
		echo "\$('#progressbar').css('width','100%');\n";
325 8b590740 Scott Ullrich
		unlink_if_exists("/tmp/install_complete");
326
		return;
327
	}
328
	$running_old = trim(file_get_contents("/tmp/installer_installer_running"));
329
	if($installer_running <> "running") {
330 40f9accf Scott Ullrich
		$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
331 8b590740 Scott Ullrich
		if($ps_running)	{
332 30a8ef77 Vinicius Coque
			$running = "\$('#installerrunning').html('<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>'); ";
333 8b590740 Scott Ullrich
			if($running_old <> $running) {
334
				echo $running;
335
				file_put_contents("/tmp/installer_installer_running", "$running");			
336
			}
337
		}
338
	}
339
	if($progress) 
340 30a8ef77 Vinicius Coque
		echo "\$('#progressbar').css('width','{$progress}%');\n";
341 8b590740 Scott Ullrich
	if(file_exists("/tmp/install_complete")) {
342 30a8ef77 Vinicius Coque
		echo "\$('#installerrunning').html('<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";
343
		echo "\$('#pbdiv').fadeOut();\n";
344 8b590740 Scott Ullrich
		unlink_if_exists("/tmp/installer.sh");
345
		file_put_contents("/tmp/installer_installer_running", "finished");
346
	}
347
}
348
349
function update_installer_status_win($status) {
350 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
351 8b590740 Scott Ullrich
	echo "<script type=\"text/javascript\">\n";
352 30a8ef77 Vinicius Coque
	echo "	\$('#installeroutput').val('" . str_replace(htmlentities($status), "\n", "") . "');\n";
353 01184e21 Scott Ullrich
	echo "</script>\n";
354 8b590740 Scott Ullrich
}
355
356
function begin_install() {
357 40f9accf Scott Ullrich
	global $g, $savemsg;
358 8b590740 Scott Ullrich
	if(file_exists("/tmp/install_complete"))
359
		return;
360
	unlink_if_exists("/tmp/install_complete");
361
	update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk));
362
	start_installation();
363
}
364
365
function head_html() {
366 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
367 8b590740 Scott Ullrich
	echo <<<EOF
368
<html>
369
	<head>
370
		<style type='text/css'>
371 a97279db Scott Ullrich
			hr {
372
				border: 0;
373
				color: #000000;
374
				background-color: #000000;
375
				height: 1px;
376
				width: 100%;
377
				text-align: left;
378
			}
379 8b590740 Scott Ullrich
			a:link { 
380
				color: #000000;
381
				text-decoration:underline;
382
				font-size:14;
383
			}
384
			a:visited { 
385
				color: #000000;
386
				text-decoration:underline;
387
				font-size:14;
388
			}
389
			a:hover { 
390
				color: #FFFF00;
391
				text-decoration: none;
392
				font-size:14;
393
			}
394
			a:active { 
395
				color: #FFFF00;
396
				text-decoration:underline;
397
				font-size:14;
398
			}
399
		</style>
400
	</head>
401
EOF;
402
403
}
404
405
function body_html() {
406 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
407 8b590740 Scott Ullrich
	$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
408
	if(strstr($pfSversion, "1.2")) 
409
		$one_two = true;
410
	$pgtitle = array("{$g['product_name']}", gettext("Installer"));
411
	include("head.inc");
412
	echo <<<EOF
413
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
414 30a8ef77 Vinicius Coque
	<script type="text/javascript" src="/javascript/jquery.js"></script>
415
	<script type="text/javascript" src="/javascript/jquery/jquery-ui.custom.min.js"></script>
416 8b590740 Scott Ullrich
	<script type="text/javascript">
417
		function getinstallerprogress() {
418
			url = '/installer/installer.php';
419
			pars = 'state=update_installer_status';
420
			callajax(url, pars, installcallback);
421
		}
422
		function callajax(url, pars, activitycallback) {
423 30a8ef77 Vinicius Coque
			jQuery.ajax(
424 8b590740 Scott Ullrich
				url,
425
				{
426 30a8ef77 Vinicius Coque
					type: 'post',
427
					data: pars,
428
					complete: activitycallback
429 8b590740 Scott Ullrich
				});
430
		}
431
		function installcallback(transport) {
432
			setTimeout('getinstallerprogress()', 2000);
433
			eval(transport.responseText);
434
		}
435
	</script>
436
EOF;
437
438
	if($one_two)
439
		echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
440
441
	if ($savemsg) print_info_box($savemsg); 
442
}
443
444
function end_html() {
445 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
446 8b590740 Scott Ullrich
	echo "</form>";
447
	echo "</body>";
448
	echo "</html>";
449
}
450
451
function template() {
452 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
453 8b590740 Scott Ullrich
	head_html();
454
	body_html();
455
	echo <<<EOF
456
	<div id="mainlevel">
457
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
458
	 		<tr>
459
	    		<td>
460
					<div id="mainarea">
461
						<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
462
							<tr>
463
	     						<td class="tabcont" >
464
	      							<form action="installer.php" method="post">
465
									<div id="pfsensetemplate">
466
467
468
									</div>
469
	     						</td>
470
							</tr>
471
						</table>
472
					</div>
473
				</td>
474
			</tr>
475
		</table>
476
	</div>
477
EOF;
478
	end_html();
479
}
480
481
function verify_before_install() {
482 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
483 97e721e7 Scott Ullrich
	$encrypted_root = false;
484
	$non_encrypted_boot = false;
485
	$non_encrypted_notice = false;
486 8b590740 Scott Ullrich
	head_html();
487
	body_html();
488 be1be0b8 Scott Ullrich
	page_table_start($g['product_name'] . " installer - Verify final installation settings");
489 40f9accf Scott Ullrich
	// If we are visiting this step from anything but the row editor / custom install
490
	// then load the on disk layout contents if they are available.
491 4fdc80b1 Scott Ullrich
	if(!$_REQUEST['fstype0'] && file_exists("/tmp/webInstaller_disk_layout.txt")) {
492
		$disks = unserialize(file_get_contents("/tmp/webInstaller_disk_layout.txt"));
493 ba0c3651 Scott Ullrich
		$bootmanager = unserialize(file_get_contents("/tmp/webInstaller_disk_bootmanager.txt"));
494 4fdc80b1 Scott Ullrich
		$restored_layout_from_file = true;
495
		$restored_layout_txt = "The previous disk layout was restored from disk";
496 60e70198 Scott Ullrich
	} else {
497
		$disks = array();
498 4fdc80b1 Scott Ullrich
	}
499 ba0c3651 Scott Ullrich
	if(!$bootmanager) 
500
		$bootmanager = $_REQUEST['bootmanager'];
501 8b590740 Scott Ullrich
	echo "\n<!--" . print_r($_REQUEST, true) . " -->\n";
502
	$disk = pcsysinstall_get_disk_info(htmlspecialchars($_REQUEST['disk']));
503
	$disksize = format_bytes($disk['size'] * 1048576);
504
	// Loop through posted items and create an array
505 28f9612c Scott Ullrich
	for($x=0; $x<99; $x++) { // XXX: Make this more optimal
506 b526ca11 Scott Ullrich
		if(!$_REQUEST['fstype' . $x])
507
			continue;
508 8b590740 Scott Ullrich
		$tmparray = array();
509 97e721e7 Scott Ullrich
		if($_REQUEST['fstype' . $x] <> "SWAP") {
510 8b590740 Scott Ullrich
			$tmparray['mountpoint'] = $_REQUEST['mountpoint' . $x];
511 28f9612c Scott Ullrich
			// Check for encrypted slice /
512
			if(stristr($_REQUEST['fstype' . $x], ".eli")) {
513
				if($tmparray['mountpoint'] == "/") 
514 97e721e7 Scott Ullrich
					$encrypted_root = true;
515 28f9612c Scott Ullrich
			}
516
			// Check if we have a non-encrypted /boot
517
			if($tmparray['mountpoint'] == "/boot") 	{
518
				if(!stristr($_REQUEST['fstype' . $x], ".eli"))
519 97e721e7 Scott Ullrich
					$non_encrypted_boot = true;
520 28f9612c Scott Ullrich
			}
521 99a20c51 Scott Ullrich
			if($tmparray['mountpoint'] == "/conf") {	
522 4b54648c Scott Ullrich
				$tmparray['mountpoint'] = "/conf{$x}";
523 be1be0b8 Scott Ullrich
				$error_txt[] = "/conf is not an allowed mount point and has been renamed to /conf{$x}.";
524 99a20c51 Scott Ullrich
			}
525
		} else  {
526 8b590740 Scott Ullrich
			$tmparray['mountpoint'] = "none";
527 99a20c51 Scott Ullrich
		}
528 97e721e7 Scott Ullrich
		// If we have an encrypted /root and lack a non encrypted /boot, throw an error/warning
529
		if($encrypted_root && !$non_encrypted_boot && !$non_encrypted_notice) {
530 be1be0b8 Scott Ullrich
			$error_txt[] = "A non-encrypted /boot slice is required when encrypting the / slice";
531 97e721e7 Scott Ullrich
			$non_encrypted_notice = true;
532
		}
533 8b590740 Scott Ullrich
		$tmparray['disk'] = $_REQUEST['disk' . $x];
534
		$tmparray['fstype'] = $_REQUEST['fstype' . $x];
535
		$tmparray['size'] = $_REQUEST['size' . $x];
536
		$tmparray['encpass'] = $_REQUEST['encpass' . $x];
537
		$disks[] = $tmparray;
538
	}
539
	echo "\n<!-- " . print_r($disks, true) . " --> \n";
540 a97279db Scott Ullrich
	$bootmanagerupper = strtoupper($bootmanager);
541 8b590740 Scott Ullrich
	echo <<<EOFAMBAC
542
	<form method="post" action="installer.php">
543
	<input type="hidden" name="fstype" value="{$fstype_echo}">
544
	<input type="hidden" name="disk" value="{$disk_echo}">
545
	<input type="hidden" name="state" value="begin_install">
546
	<input type="hidden" name="swapsize" value="{$swapsize}">
547
	<input type="hidden" name="encpass" value="{$encpass}">
548
	<input type="hidden" name="bootmanager" value="{$bootmanager}">
549
	<div id="mainlevel">
550 be1be0b8 Scott Ullrich
		<table width="800" border="0" cellpadding="0" cellspacing="0">
551 8b590740 Scott Ullrich
	 		<tr>
552
	    		<td>
553
					<div id="mainarea">
554
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
555
							<tr>
556
	     						<td >
557
									<div>
558
										<center>
559
											<div id="pfsensetemplate">
560 a1532937 Scott Ullrich
												<table width='100%'>
561 be1be0b8 Scott Ullrich
EOFAMBAC;
562
												// If errors are found, throw the big red box.
563 a1532937 Scott Ullrich
												if ($error_txt) {
564
													echo "<tr><td colspan=\"5\">&nbsp;</td>";
565
													echo "<tr><td colspan=\"5\">";
566 be1be0b8 Scott Ullrich
													print_input_errors($error_txt);
567 a1532937 Scott Ullrich
													echo "</td></tr>";
568
												} else 
569
													echo "<tr><td>&nbsp;</td></tr>";
570
571 be1be0b8 Scott Ullrich
	echo <<<EOFAMBACBAF
572
573 a97279db Scott Ullrich
												<tr><td colspan='5' align="center"><b>Boot manager: {$bootmanagerupper}</td></tr>
574
												<tr><td>&nbsp;</td></tr>
575 8b590740 Scott Ullrich
												<tr>
576 a97279db Scott Ullrich
													<td align='left'>
577 8b590740 Scott Ullrich
														<b>Mount point</b>
578
													</td>
579 a97279db Scott Ullrich
													<td align='left'>
580 8206c01d Scott Ullrich
														<b>Filesysytem type</b>
581 8b590740 Scott Ullrich
													</td>
582 a97279db Scott Ullrich
													<td align='left'>
583 8b590740 Scott Ullrich
														<b>Disk</b>
584
													</td>
585 a97279db Scott Ullrich
													<td align='left'>
586 8b590740 Scott Ullrich
														<b>Size</b>
587
													</td>
588 a97279db Scott Ullrich
													<td align='left'>
589 8b590740 Scott Ullrich
														<b>Encryption password</b>
590
													</td>
591 a97279db Scott Ullrich
												</tr>
592
												<tr><td colspan='5'><hr></td></tr>
593 8b590740 Scott Ullrich
594 be1be0b8 Scott Ullrich
EOFAMBACBAF;
595 8b590740 Scott Ullrich
596
													foreach($disks as $disk) {
597
														$desc = pcsysinstall_get_disk_info($disk['disk']);
598
														echo "<tr>";
599 a97279db Scott Ullrich
														echo "<td>&nbsp;&nbsp;&nbsp;{$disk['mountpoint']}</td>";
600 8b590740 Scott Ullrich
														echo "<td>{$disk['fstype']}</td>";
601
														echo "<td>{$disk['disk']} {$desc['desc']}</td>";
602
														echo "<td>{$disk['size']}</td>";
603
														echo "<td>{$disk['encpass']}</td>";
604
														echo "</tr>";
605
													}
606
607
echo <<<EOFAMB
608 a97279db Scott Ullrich
												<tr><td colspan="5"><hr></td></tr>
609 8b590740 Scott Ullrich
												</table>
610
											</div>
611
										</center>
612
									</div>
613
	     						</td>
614
							</tr>
615
						</table>
616
					</div>
617
					<center>
618
						<p/>
619 5faeedc6 Scott Ullrich
						<input type="button" value="Cancel" onClick="javascript:document.location='installer.php?state=custominstall';"> &nbsp;&nbsp;
620 be1be0b8 Scott Ullrich
EOFAMB;
621
						if(!$error_txt) 
622 a97279db Scott Ullrich
						echo "<input type=\"submit\" value=\"Begin installation\"> <br/>&nbsp;";
623 be1be0b8 Scott Ullrich
echo <<<EOFAMBASDF
624
625 8b590740 Scott Ullrich
					</center>
626
				</td>
627
			</tr>
628
		</table>
629
	</div>
630 be1be0b8 Scott Ullrich
EOFAMBASDF;
631 8b590740 Scott Ullrich
632
633
	page_table_end();
634
	end_html();
635
	write_out_pc_sysinstaller_config($disks, $bootmanager);
636 01184e21 Scott Ullrich
	// Serialize layout to disk so it can be read in later.
637 4fdc80b1 Scott Ullrich
	file_put_contents("/tmp/webInstaller_disk_layout.txt", serialize($disks));
638 ba0c3651 Scott Ullrich
	file_put_contents("/tmp/webInstaller_disk_bootmanager.txt", serialize($bootmanager));
639 8b590740 Scott Ullrich
}
640
641
function installing_gui() {
642 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
643 8b590740 Scott Ullrich
	head_html();
644
	body_html();
645
	echo "<form action=\"installer.php\" method=\"post\" state=\"step1_post\">";
646
	page_table_start();
647
	echo <<<EOF
648
	<center>
649
		<table width="100%">
650
		<tr><td>
651
			<div id="mainlevel">
652
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
653
			 		<tr>
654
			    		<td>
655
							<div id="mainarea">
656
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
657
									<tr>
658
			     						<td>
659
											<div id="pfsenseinstaller" width="100%">
660
												<div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000">
661
													<table>
662
														<tr>
663
															<td valign="middle">
664
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
665
															</td>
666
															<td valign="middle">
667
																&nbsp;<font size="2"><b>Starting Installer...  Please wait...
668
															</td>
669
														</tr>
670
													</table>
671
												</div>
672
												<div id='pbdiv'>
673
													<br/>
674
													<center>
675
													<table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
676
														<tr>
677
															<td background="/themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
678
															</td>
679
															<td>
680
																<table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
681
																	<td background="/themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
682
																		<img src='/themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
683
																	</td>
684
																</table>
685
															</td>
686
															<td background="/themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
687
															</td>
688
														</tr>
689
													</table>
690
													<br/>
691
												</div>
692
												<textarea name='installeroutput' id='installeroutput' rows="31" cols="90">
693
												</textarea>
694
											</div>
695
			     						</td>
696
									</tr>
697
								</table>
698
							</div>
699
						</td>
700
					</tr>
701
				</table>
702
			</div>
703
		</td></tr>
704
		</table>
705
	</center>
706
	<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
707
708
EOF;
709
	page_table_end();
710
	end_html();
711
}
712
713
function page_table_start($pgtitle = "") {
714 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
715 8b590740 Scott Ullrich
	if($pgtitle == "") 
716
		$pgtitle = "{$g['product_name']} installer";
717
	echo <<<EOF
718
	<center>
719
		<img border="0" src="/themes/{$g['theme']}/images/logo.gif"></a><br/>
720
		<table cellpadding="6" cellspacing="0" width="550" style="border:1px solid #000000">
721
		<tr height="10" bgcolor="#990000">
722
			<td style="border-bottom:1px solid #000000">
723
				<font color='white'>
724
					<b>
725
						{$pgtitle}
726
					</b>
727
				</font>
728
			</td>
729
		</tr>
730
		<tr>
731
			<td>
732
733
EOF;
734
735
}
736
737
function page_table_end() {
738 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
739 8b590740 Scott Ullrich
	echo <<<EOF
740
			</td>
741
		</tr>
742
		</table>
743
	</center>
744
745
EOF;
746
	
747
}
748
749
function installer_custom() {
750 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
751 b526ca11 Scott Ullrich
	global $select_txt, $custom_disks;
752 8b590740 Scott Ullrich
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
753
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
754 19f6b3c5 Scott Ullrich
	$disks = installer_find_all_disks();
755
	// Pass size of disks down to javascript.
756
	$disk_sizes_js_txt = "var disk_sizes = new Array();\n";
757
	foreach($disks as $disk) 
758
		$disk_sizes_js_txt .= "disk_sizes['{$disk['disk']}'] = '{$disk['size']}';\n";
759 8b590740 Scott Ullrich
	head_html();
760
	body_html();
761 be1be0b8 Scott Ullrich
	page_table_start($g['product_name'] . " installer - Customize disk(s) layout");
762 8b590740 Scott Ullrich
	echo <<<EOF
763 4f646415 Scott Ullrich
		<script type="text/javascript">
764 19f6b3c5 Scott Ullrich
			Array.prototype.in_array = function(p_val) {
765
				for(var i = 0, l = this.length; i < l; i++) {
766
					if(this[i] == p_val) {
767
						return true;
768
					}
769
				}
770
				return false;
771
			}
772 346cc87f Scott Ullrich
			function row_helper_dynamic_custom() {
773
				var totalsize = 0;
774 19f6b3c5 Scott Ullrich
				{$disk_sizes_js_txt}
775 8fdc5159 Scott Ullrich
				// Run through all rows and process data
776 a17f284c Scott Ullrich
				for(var x = 0; x<99; x++) { //optimize me better
777 30a8ef77 Vinicius Coque
					if(\$('#fstype' + x).length) {
778
						if(\$('#size' + x).val() == '')
779
							\$('#size' + x).val(disk_sizes[\$('disk' + x).value]);
780
						var fstype = \$('#fstype' + x).val();
781 a17f284c Scott Ullrich
						if(fstype.substring(fstype.length - 4) == ".eli") {
782 30a8ef77 Vinicius Coque
							\$('#encpass' + x).prop('disabled',false);
783 a17f284c Scott Ullrich
							if(!encryption_warning_shown) {
784
								alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!');
785
								encryption_warning_shown = true;
786
							}
787
						} else { 
788 30a8ef77 Vinicius Coque
							\$('#encpass' + x).prop('disabled',true);
789 a17f284c Scott Ullrich
						}
790
					}
791 8fdc5159 Scott Ullrich
					// Calculate size allocations
792 30a8ef77 Vinicius Coque
					if(\$('#size' + x).length) {
793
						if(parseInt($('#size' + x).val()) > 0)
794
							totalsize += parseInt($('#size' + x).val());
795 4f646415 Scott Ullrich
					}
796
				}
797 8fdc5159 Scott Ullrich
				// If the totalsize element exists, set it and disable
798 30a8ef77 Vinicius Coque
				if(\$('#totalsize').length) {
799
					if(\$('#totalsize').val() != totalsize) {
800 fb34dd22 Scott Ullrich
						// When size allocation changes, draw attention.
801 30a8ef77 Vinicius Coque
 						jQuery('#totalsize').effect('highlight');
802
						\$('#totalsize').val(totalsize);
803 fb34dd22 Scott Ullrich
					}
804 30a8ef77 Vinicius Coque
					\$('#totalsize').prop('disabled',true);
805 346cc87f Scott Ullrich
				}
806 30a8ef77 Vinicius Coque
				if(\$('#disktotals').length) {
807 19f6b3c5 Scott Ullrich
					var disks_seen = new Array();
808
					var tmp_sizedisks = 0;
809
					var disksseen = 0;
810
					for(var xx = 0; xx<99; xx++) {
811 30a8ef77 Vinicius Coque
						if(\$('#disk' + xx).length) {
812
							if(!disks_seen.in_array(\$('#disk' + xx).val())) {
813
								tmp_sizedisks += parseInt(disk_sizes[\$('#disk' + xx).val()]);
814
								disks_seen[disksseen] = \$('#disk' + xx).val();
815 19f6b3c5 Scott Ullrich
								disksseen++;
816
							}
817
						}
818 30a8ef77 Vinicius Coque
					\$('#disktotals').val(tmp_sizedisks);
819
					\$('#disktotals').prop('disabled',true);
820
					\$('#disktotals').css('color','#000000');
821
					var remaining = parseInt(\$('#disktotals').val()) - parseInt(\$('#totalsize').val());
822 bfff9331 Scott Ullrich
						if(remaining == 0) {
823 30a8ef77 Vinicius Coque
							if(\$('#totalsize').length)
824
								\$('#totalsize').css({
825
									'background':'#00FF00',
826
									'color':'#000000'
827 ec981fc5 Scott Ullrich
								});
828
						} else {
829 30a8ef77 Vinicius Coque
							if(\$('#totalsize').length)
830
								\$('#totalsize').css({
831
									'background':'#FFFFFF',
832
									'color':'#000000'
833 ec981fc5 Scott Ullrich
								});
834 3e4fbe67 Scott Ullrich
						}
835 30a8ef77 Vinicius Coque
						if(parseInt(\$('#totalsize').val()) > parseInt(\$('#disktotals').val())) {
836
							if(\$('#totalsize'))
837
								\$('#totalsize').css({
838
									'background':'#FF0000',
839
									'color':'#000000'
840 3e4fbe67 Scott Ullrich
								});							
841 ec981fc5 Scott Ullrich
						}
842 30a8ef77 Vinicius Coque
						if(\$('#availalloc').length) {
843
							\$('#availalloc').prop('disabled',true);
844
							\$('#availalloc').val(remaining);
845
								\$('#availalloc').css({
846
									'background':'#FFFFFF',
847
									'color':'#000000'
848 bfff9331 Scott Ullrich
								});							
849
						}
850 ec981fc5 Scott Ullrich
					}
851 19f6b3c5 Scott Ullrich
				}
852 4f646415 Scott Ullrich
			}
853
		</script>
854 8b590740 Scott Ullrich
		<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
855
		<script type="text/javascript">
856
			// Setup rowhelper data types
857
			rowname[0] = "mountpoint";
858
			rowtype[0] = "textbox";
859
			rowsize[0] = "8";
860
			rowname[1] = "fstype";
861
			rowtype[1] = "select";
862
			rowsize[1] = "1";
863
			rowname[2] = "disk";
864
			rowtype[2] = "select";
865
			rowsize[2] = "1";
866
			rowname[3] = "size";
867
			rowtype[3] = "textbox";
868
			rowsize[3] = "8";
869
			rowname[4] = "encpass";
870
			rowtype[4] = "textbox";
871
			rowsize[4] = "8";
872
			field_counter_js = 5;
873
			rows = 1;
874
			totalrows = 1;
875
			loaded = 1;
876 3da60e0d Scott Ullrich
			rowhelper_onChange = 	" onChange='javascript:row_helper_dynamic_custom()' ";
877
			rowhelper_onDelete = 	"row_helper_dynamic_custom(); ";
878
			rowhelper_onAdd = 		"row_helper_dynamic_custom();";
879 8b590740 Scott Ullrich
		</script>
880
		<form action="installer.php" method="post">
881
			<input type="hidden" name="state" value="verify_before_install">
882
			<div id="mainlevel">
883
				<center>
884
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
885
			 		<tr>
886
			    		<td>
887
							<center>
888
							<div id="mainarea">
889
								<center>
890
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
891
									<tr>
892
			     						<td>
893
											<div id="pfsenseinstaller">
894
												<center>
895
												<div id='loadingdiv'>
896 47127d13 Scott Ullrich
													<table>
897
														<tr>
898 d8c96528 Scott Ullrich
															<td valign="center">
899 47127d13 Scott Ullrich
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
900
															</td>
901
															<td valign="center">
902
														 		&nbsp;Probing disks, please wait...
903
															</td>
904
														</tr>
905
													</table>
906 8b590740 Scott Ullrich
												</div>
907
EOF;
908
	ob_flush();
909 01184e21 Scott Ullrich
	// Read bootmanager setting from disk if found
910 ba0c3651 Scott Ullrich
	if(file_exists("/tmp/webInstaller_disk_bootmanager.txt"))
911
		$bootmanager = unserialize(file_get_contents("/tmp/webInstaller_disk_bootmanager.txt"));
912
	if($bootmanager == "none") 
913
		$noneselected = " SELECTED";
914
	if($bootmanager == "bsd") 
915
		$bsdeselected = " SELECTED";
916 8b590740 Scott Ullrich
	if(!$disks)  {
917
		$custom_txt = gettext("ERROR: Could not find any suitable disks for installation.");
918
	} else {
919
		// Prepare disk selection dropdown
920
		$custom_txt = <<<EOF
921
												<center>
922
												<table>
923
												<tr>
924
													<td align='right'>
925
														Boot manager:
926
													</td>
927
													<td>
928
														<select name='bootmanager'>
929 ba0c3651 Scott Ullrich
															<option value='none' $noneselected>
930 72b14823 Scott Ullrich
																None
931
															</option>
932 ba0c3651 Scott Ullrich
															<option value='bsd' $bsdeselected>
933 8b590740 Scott Ullrich
																BSD
934
															</option>
935
														</select>
936
													</td>
937
												</tr>
938
												</table>
939
												<hr>
940
												<table id='maintable'><tbody>
941
												<tr>
942 1ddd4ba3 Scott Ullrich
													<td align="middle">
943
														<b>Mount</b>
944 8b590740 Scott Ullrich
													</td>
945 8206c01d Scott Ullrich
													<td align='middle'>
946
														<b>Filesysytem</b>
947 8b590740 Scott Ullrich
													</td>
948 1ddd4ba3 Scott Ullrich
													<td align="middle">
949 8b590740 Scott Ullrich
														<b>Disk</b>
950
													</td>
951 1ddd4ba3 Scott Ullrich
													<td align="middle">
952 8b590740 Scott Ullrich
														<b>Size</b>
953
													</td>
954 1ddd4ba3 Scott Ullrich
													<td align="middle">
955 8b590740 Scott Ullrich
														<b>Encryption password</b>
956
													</td>
957
													<td>
958
														&nbsp;
959
													</td>
960
												</tr>
961
												<tr>
962
963
EOF;
964
965 4fdc80b1 Scott Ullrich
		// Calculate swap disk sizes
966 1ddd4ba3 Scott Ullrich
		$memory = get_memory();
967
		$swap_size = $memory[0] * 2;
968 8b590740 Scott Ullrich
		$first_disk = trim(installer_find_first_disk());
969
		$disk_info = pcsysinstall_get_disk_info($first_disk);
970
		$size = $disk_info['size'];
971 1ddd4ba3 Scott Ullrich
		$first_disk_size = $size - $swap_size;
972 4fdc80b1 Scott Ullrich
973
		// Debugging
974 8b590740 Scott Ullrich
		echo "\n\n<!-- $first_disk - " . print_r($disk_info, true) . " - $size  - $first_disk_size -->\n\n";
975
976 4fdc80b1 Scott Ullrich
		// Check to see if a on disk layout exists
977
		if(file_exists("/tmp/webInstaller_disk_layout.txt")) {
978
			$disks_restored = unserialize(file_get_contents("/tmp/webInstaller_disk_layout.txt"));
979
			$restored_layout_from_file = true;
980 5c5610e9 Scott Ullrich
			$restored_layout_txt = "<br/>* The previous disk layout was restored from a previous session";
981 4fdc80b1 Scott Ullrich
		}
982
983
		// If we restored disk layout(s) from a file then build the rows
984
		if($restored_layout_from_file == true) {
985
			$diskcounter = 0;
986
			foreach($disks_restored as $dr) {
987 b8791a31 Scott Ullrich
				$custom_txt .= return_rowhelper_row("$diskcounter", $dr['mountpoint'], $dr['fstype'], $dr['disk'], $dr['size'], $dr['encpass']);
988 4fdc80b1 Scott Ullrich
				$diskcounter++;
989
			}
990
		} else {		
991
			// Construct the default rows that outline the disks configuration.
992 2fa74698 Scott Ullrich
			$custom_txt .= return_rowhelper_row("0", "/", "UFS+S", $first_disk, "{$first_disk_size}", "");
993 4fdc80b1 Scott Ullrich
			$custom_txt .= return_rowhelper_row("1", "none", "SWAP", $first_disk, "$swap_size", "");
994
		}
995
996
		// tfoot and tbody are used by rowhelper
997 8b590740 Scott Ullrich
		$custom_txt .= "</tr>";
998 4f646415 Scott Ullrich
		$custom_txt .= "<tfoot></tfoot></tbody>";
999 bfff9331 Scott Ullrich
		// Total allocation box
1000 96b25714 Scott Ullrich
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Total allocated:</td><td><input style='border:0px; background-color: #FFFFFF;' size='8' id='totalsize' name='totalsize'></td>";
1001
		// Add row button
1002
		$custom_txt .= "</td><td>&nbsp;</td><td>";
1003
		$custom_txt .= "<div id=\"addrowbutton\">";
1004
		$custom_txt .= "<a onclick=\"javascript:addRowTo('maintable', 'formfldalias'); return false;\" href=\"#\">";
1005
		$custom_txt .= "<img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" alt=\"\" title=\"add another entry\" /></a>";
1006
		$custom_txt .= "</div>";
1007
		$custom_txt .= "</td></tr>";	
1008 bfff9331 Scott Ullrich
		// Disk capacity box
1009 96b25714 Scott Ullrich
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Disk(s) capacity total:</td><td><input style='border:0px; background-color: #FFFFFF;' size='8' id='disktotals' name='disktotals'></td></tr>";
1010 bfff9331 Scott Ullrich
		// Remaining allocation box
1011
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Available space for allocation:</td><td><input style='border:0px; background-color: #FFFFFF;' size='8' id='availalloc' name='availalloc'></td></tr>";
1012 4f646415 Scott Ullrich
		$custom_txt .= "</table>";
1013
		$custom_txt .= "<script type=\"text/javascript\">row_helper_dynamic_custom();</script>";
1014 8b590740 Scott Ullrich
	}
1015
	echo <<<EOF
1016
1017
												<tr>
1018
													<td colspan='4'>
1019
													<script type="text/javascript">
1020 30a8ef77 Vinicius Coque
														\$('#loadingdiv').css('visibility','hidden');
1021 8b590740 Scott Ullrich
													</script>
1022
													<div id='contentdiv' style="display:none;">
1023
														<p/>
1024
														{$custom_txt}<p/>
1025
														<hr><p/>
1026 5faeedc6 Scott Ullrich
														<input type="button" value="Cancel" onClick="javascript:document.location='/installer/installer.php';"> &nbsp;&nbsp
1027 8b590740 Scott Ullrich
														<input type="submit" value="Next">
1028
													</div>
1029
													<script type="text/javascript">
1030 cace4c41 Scott Ullrich
														var encryption_warning_shown = false;
1031 30a8ef77 Vinicius Coque
														\$('#contentdiv').fadeIn();
1032 10518768 Scott Ullrich
														row_helper_dynamic_custom();
1033 8b590740 Scott Ullrich
													</script>
1034
												</center>
1035
												</td></tr>
1036
												</table>
1037
											</div>
1038
			     						</td>
1039
									</tr>
1040
								</table>
1041
								</center>
1042
								<span class="vexpl">
1043
									<span class="red">
1044
										<strong>
1045
											NOTES:
1046
										</strong>
1047
									</span>
1048
									<br/>* Sizes are in megabytes.
1049 99a20c51 Scott Ullrich
									<br/>* Mount points named /conf are not allowed.  Use /cf if you want to make a configuration slice/mount.
1050 b8791a31 Scott Ullrich
									{$restored_layout_txt}
1051 8b590740 Scott Ullrich
								</span>
1052
								</strong>
1053
							</div>
1054
						</td>
1055
					</tr>
1056
				</table>
1057
			</div>
1058
			</center>
1059
			<script type="text/javascript">
1060
			<!--
1061
				newrow[1] = "{$select_txt}";
1062
				newrow[2] = "{$custom_disks}";
1063
			-->
1064
			</script>
1065
			
1066
1067
EOF;
1068
	page_table_end();
1069
	end_html();
1070
}
1071
1072
function installer_main() {
1073 40f9accf Scott Ullrich
	global $g, $fstype, $savemsg;
1074 8b590740 Scott Ullrich
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
1075
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
1076
	head_html();
1077
	body_html();
1078
	$disk = installer_find_first_disk();
1079
	// Only enable ZFS if this exists.  The install will fail otherwise.
1080 60e70198 Scott Ullrich
	if(file_exists("/boot/gptzfsboot")) 
1081
		$zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"installer.php?state=easy_install_zfs\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>";
1082 8b590740 Scott Ullrich
	page_table_start();
1083
	echo <<<EOF
1084
		<form action="installer.php" method="post" state="step1_post">
1085
			<div id="mainlevel">
1086
				<center>
1087
				<b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/>
1088
				<font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font>
1089
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
1090
			 		<tr>
1091
			    		<td>
1092
							<center>
1093
							<div id="mainarea">
1094
								<br/>
1095
								<center>
1096
								Please select an installer option to begin:
1097
								<p/>
1098
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
1099
									<tr>
1100
			     						<td>
1101
											<div id="pfsenseinstaller">
1102
												<center>
1103
EOF;
1104
	if(!$disk) {
1105
		echo gettext("ERROR: Could not find any suitable disks for installation.");
1106
		echo "</div></td></tr></table></div></table></div>";
1107
		end_html();
1108
		exit;
1109
	}
1110
	echo <<<EOF
1111
1112
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
1113
														<tr bgcolor="#CECECE"><td align="center">
1114 60e70198 Scott Ullrich
															<a href="installer.php?state=easy_install_ufs">Easy installation of {$g['product_name']} using the UFS filesystem on disk {$disk}</a>
1115 8b590740 Scott Ullrich
														</td></tr>
1116
													 	{$zfs_enabled}
1117
														<tr bgcolor="#AAAAAA"><td align="center">
1118
															<a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a>
1119
														</td></tr>
1120
														<tr bgcolor="#CECECE"><td align="center">
1121
															<a href='/'>Cancel and return to Dashboard</a>
1122
														</td></tr>
1123
													</table>
1124
												</center>
1125
											</div>
1126
			     						</td>
1127
									</tr>
1128
								</table>
1129
							</div>
1130
						</td>
1131
					</tr>
1132
				</table>
1133
			</div>
1134
EOF;
1135
	page_table_end();
1136
	end_html();
1137
}
1138
1139
function return_rowhelper_row($rownum, $mountpoint, $fstype, $disk, $size, $encpass) {
1140 40f9accf Scott Ullrich
		global $g, $select_txt, $custom_disks, $savemsg;
1141 37bd1cbb Scott Ullrich
		$release = php_uname("r");
1142
		$release = trim($release[0]);
1143
1144 8b590740 Scott Ullrich
		// Mount point
1145
		$disks = installer_find_all_disks();
1146
		$custom_txt .= "<tr>";
1147
		$custom_txt .=  "<td><input size='8' id='mountpoint{$rownum}' name='mountpoint{$rownum}' value='{$mountpoint}'></td>";
1148 37bd1cbb Scott Ullrich
1149
		// Filesystem type array
1150 8b590740 Scott Ullrich
		$types = array(
1151
			'UFS' => 'UFS',
1152
			'UFS+S' => 'UFS + Softupdates',
1153
			'UFS.eli' => 'Encrypted UFS',
1154
			'UFS+S.eli' => 'Encrypted UFS + Softupdates',
1155
			'SWAP' => 'SWAP'
1156
		);
1157 37bd1cbb Scott Ullrich
1158
		// UFS + Journaling was introduced in 9.0
1159 8b590740 Scott Ullrich
		if($release == "9") {
1160
			$types['UFS+J'] = "UFS + Journaling";
1161
			$types['UFS+J.eli'] = "Encrypted UFS + Journaling";
1162
		}
1163 37bd1cbb Scott Ullrich
		
1164
		// Add ZFS Boot loader if it exists
1165 8b590740 Scott Ullrich
		if(file_exists("/boot/gptzfsboot")) {
1166
			$types['ZFS'] = "Zetabyte Filesystem";
1167
			$types['ZFS.eli'] = "Encrypted Zetabyte Filesystem";
1168
		}
1169 37bd1cbb Scott Ullrich
1170
		// fstype form field
1171 346cc87f Scott Ullrich
		$custom_txt .=  "<td><select onChange='javascript:row_helper_dynamic_custom()' id='fstype{$rownum}' name='fstype{$rownum}'>";
1172 b526ca11 Scott Ullrich
		$select_txt = "";
1173 a16d38c9 Scott Ullrich
		foreach($types as $type => $desc) {
1174 8b590740 Scott Ullrich
			if($type == $fstype)
1175
				$SELECTED="SELECTED";
1176
			else 
1177
				$SELECTED="";
1178
			$select_txt .= "<option value='$type' $SELECTED>$desc</option>";
1179
		}
1180
		$custom_txt .= "{$select_txt}</select>\n";
1181
		$custom_txt .= "</td>";
1182 37bd1cbb Scott Ullrich
		
1183
		// Disk selection form field
1184 8b590740 Scott Ullrich
		$custom_txt .= "<td><select id='disk{$rownum}' name='disk{$rownum}'>\n";
1185 b526ca11 Scott Ullrich
		$custom_disks = "";
1186 8b590740 Scott Ullrich
		foreach($disks as $dsk) {
1187 65c6cdfa Scott Ullrich
			$disksize_bytes = format_bytes($dsk['size'] * 1048576);
1188
			$disksize = $dsk['size'];
1189 8b590740 Scott Ullrich
			if($disk == $dsk['disk'])
1190
				$SELECTED="SELECTED";
1191
			else 
1192
				$SELECTED="";
1193 65c6cdfa Scott Ullrich
			$custom_disks .= "<option value='{$dsk['disk']}' $SELECTED>{$dsk['disk']} - {$dsk['desc']} - {$disksize}MB ({$disksize_bytes})</option>";
1194 8b590740 Scott Ullrich
		}
1195
		$custom_txt .= "{$custom_disks}</select></td>\n";
1196
1197 37bd1cbb Scott Ullrich
		// Slice size
1198 4f646415 Scott Ullrich
		$custom_txt .= "<td><input onChange='javascript:row_helper_dynamic_custom();' name='size{$rownum}' id='size{$rownum}' size='8' type='text' value='{$size}'></td>";
1199 8b590740 Scott Ullrich
1200 37bd1cbb Scott Ullrich
		// Encryption password
1201 8b590740 Scott Ullrich
		$custom_txt .= "<td>";
1202
		$custom_txt .= "<input id='encpass{$rownum}' name='encpass{$rownum}' size='8' value='{$encpass}'>";
1203
		$custom_txt .= "</td>";
1204
	
1205
		// Add Rowhelper + button
1206 96b25714 Scott Ullrich
		if($rownum > 0) 
1207
			$custom_txt .= "<td><a onclick=\"removeRow(this); return false;\" href=\"#\"><img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_x.gif\" alt=\"\" title=\"remove this entry\"/></a></td>";
1208 8b590740 Scott Ullrich
1209
		$custom_txt .= "</tr>";	
1210
		return $custom_txt;
1211
}
1212
1213 cfbfd941 smos
?>