Project

General

Profile

Download (32.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	installer.php (pfSense installer)
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
$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
	Header("Location: /");
39
	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
	default:
58
		installer_main();	
59
}
60

    
61
function write_out_pc_sysinstaller_config($disks, $bootmanager = "bsd") {
62
	$diskareas = "";
63
	$fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w");
64
	if(!$fd) {
65
		return true;
66
	}
67
	if($bootmanager == "") 
68
	 	$bootmanager = "none";
69
	$numdisks = -1;
70
	$lastdisk = "";
71
	$diskdefs = "";
72
	// Run through the disks and create the conf areas for pc-sysinstaller
73
	foreach($disks as $disksa) {
74
		$fstype = $disksa['fstype'];
75
		$size = $disksa['size'];
76
		$mountpoint = $disksa['mountpoint'];
77
		$disk = $disksa['disk'];
78
		if($disk <> $lastdisk) {
79
			$lastdisk = $disk;
80
			$numdisks++;
81
			$diskdefs .= "disk{$numdisks}={$disk}\n";
82
		}
83
		$diskareas .= "disk{$numdisks}-part={$fstype} {$size} {$mountpoint} \n";
84
		if($encpass)
85
			$diskareas .= "encpass={$encpass}\n";
86
	}
87
	
88
	$config = <<<EOF
89
# Sample configuration file for an installation using pc-sysinstall
90
# This file was automatically generated by installer.php
91
 
92
installMode=fresh
93
installInteractive=yes
94
installType=FreeBSD
95
installMedium=LiveCD
96

    
97
# Set the disk parameters
98
{$diskdefs}
99
partition=all
100
bootManager={$bootmanager}
101
commitDiskPart
102

    
103
# Setup the disk label
104
# All sizes are expressed in MB
105
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
106
# Size 0 means use the rest of the slice size
107
# Alternatively, you can append .eli to any of
108
# the above filesystem types to encrypt that disk.
109
# If you with to use a passphrase with this 
110
# encrypted partition, on the next line 
111
# the flag "encpass=" should be entered:
112
# encpass=mypass
113
# disk0-part=UFS 500 /boot
114
# disk0-part=UFS.eli 500 /
115
# disk0-part=UFS.eli 500 /usr
116
{$diskareas}
117

    
118
# Do it now!
119
commitDiskLabel
120

    
121
# Set if we are installing via optical, USB, or FTP
122
installType=FreeBSD
123

    
124
packageType=cpdup
125

    
126
# Optional Components
127
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,usr,var
128

    
129
# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh
130
EOF;
131
	fwrite($fd, $config);
132
	fclose($fd);
133
	return;
134
}
135

    
136
function start_installation() {
137
	global $g, $fstype, $savemsg;
138
	if(file_exists("/tmp/install_complete"))
139
		return;
140
	$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
141
	if($ps_running)	
142
		return;
143
	$fd = fopen("/tmp/installer.sh", "w");
144
	if(!$fd) {
145
		die(gettext("Could not open /tmp/installer.sh for writing"));
146
		exit;
147
	}
148
	fwrite($fd, "/bin/rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n");
149
	fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n");
150
	fwrite($fd, "/bin/chmod a+rx /usr/local/bin/after_installation_routines.sh\n");
151
	fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n");
152
	fwrite($fd, "/bin/mkdir /mnt/tmp\n");
153
	fwrite($fd, "/usr/bin/touch /tmp/install_complete\n");
154
	fclose($fd);
155
	exec("/bin/chmod a+rx /tmp/installer.sh");
156
	mwexec_bg("/bin/sh /tmp/installer.sh");
157
}
158

    
159
function installer_find_first_disk() {
160
	global $g, $fstype, $savemsg;
161
	$disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`;
162
	return trim($disk);
163
}
164

    
165
function pcsysinstall_get_disk_info($diskname) {
166
	global $g, $fstype, $savemsg;
167
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
168
	$disks_array = array();
169
	foreach($disk as $d) {
170
		$disks_info = split(":", $d);
171
		$tmp_array = array();
172
		if($disks_info[0] == $diskname) {
173
			$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
174
			$disk_info_split = split("=", $disk_info);
175
			foreach($disk_info as $di) { 
176
				$di_s = split("=", $di);
177
				if($di_s[0])
178
					$tmp_array[$di_s[0]] = $di_s[1];
179
			}
180
			$tmp_array['disk'] = trim($disks_info[0]);
181
			$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
182
			return $tmp_array;
183
		}
184
	}
185
}
186

    
187
// Return an array with all disks information.
188
function installer_find_all_disks() {
189
	global $g, $fstype, $savemsg;
190
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
191
	$disks_array = array();
192
	foreach($disk as $d) {
193
		if(!$d) 
194
			continue;
195
		$disks_info = split(":", $d);
196
		$tmp_array = array();
197
		$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
198
		foreach($disk_info as $di) { 
199
			$di_s = split("=", $di);
200
			if($di_s[0])
201
				$tmp_array[$di_s[0]] = $di_s[1];
202
		}
203
		$tmp_array['disk'] = trim($disks_info[0]);
204
		$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
205
		$disks_array[] = $tmp_array;
206
	}
207
	return $disks_array;
208
}
209

    
210
function update_installer_status() {
211
	global $g, $fstype, $savemsg;
212
	// Ensure status files exist
213
	if(!file_exists("/tmp/installer_installer_running"))
214
		touch("/tmp/installer_installer_running");
215
	$status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`;
216
	$status = str_replace("\n", "\\n", $status);
217
	$status = str_replace("\n", "\\r", $status);
218
	echo "this.document.forms[0].installeroutput.value='$status';\n";
219
	echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n";	
220
	// Find out installer progress
221
	$progress = "5";
222
	if(strstr($status, "Running: dd")) 
223
		$progress = "6";
224
	if(strstr($status, "Running: gpart create -s GPT")) 
225
		$progress = "7";
226
	if(strstr($status, "Running: gpart bootcode")) 
227
		$progress = "7";
228
	if(strstr($status, "Running: newfs -U")) 
229
		$progress = "8";
230
	if(strstr($status, "Running: sync")) 
231
		$progress = "9";
232
	if(strstr($status, "/boot /mnt/boot")) 
233
		$progress = "10";
234
	if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT"))
235
		$progress = "11";
236
	if(strstr($status, "/bin /mnt/bin"))
237
		$progress = "12";
238
	if(strstr($status, "/conf /mnt/conf"))
239
		$progress = "15";
240
	if(strstr($status, "/conf.default /mnt/conf.default"))
241
		$progress = "20";
242
	if(strstr($status, "/dev /mnt/dev"))
243
		$progress = "25";
244
	if(strstr($status, "/etc /mnt/etc"))
245
		$progress = "30";
246
	if(strstr($status, "/home /mnt/home"))
247
		$progress = "35";
248
	if(strstr($status, "/kernels /mnt/kernels"))
249
		$progress = "40";
250
	if(strstr($status, "/libexec /mnt/libexec"))
251
		$progress = "50";
252
	if(strstr($status, "/lib /mnt/lib"))
253
		$progress = "60";
254
	if(strstr($status, "/root /mnt/root"))
255
		$progress = "70";
256
	if(strstr($status, "/sbin /mnt/sbin"))
257
		$progress = "75";
258
	if(strstr($status, "/sys /mnt/sys"))
259
		$progress = "80";
260
	if(strstr($status, "/usr /mnt/usr"))
261
		$progress = "95";
262
	if(strstr($status, "/usr /mnt/usr"))
263
		$progress = "90";
264
	if(strstr($status, "/var /mnt/var"))
265
		$progress = "95";
266
	if(strstr($status, "cap_mkdb /etc/login.conf"))
267
		$progress = "96";
268
	if(strstr($status, "Setting hostname"))
269
		$progress = "97";
270
	if(strstr($status, "umount -f /mnt"))
271
		$progress = "98";
272
	if(strstr($status, "umount -f /mnt"))
273
		$progress = "99";
274
	if(strstr($status, "Installation finished"))
275
		$progress = "100";
276
	// Check for error and bail if we see one.
277
	if(stristr($status, "error")) {
278
		$error = true;
279
		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\">Back</a> to webInstaller'; ";
280
		echo "\$('progressbar').style.width='100%';\n";
281
		unlink_if_exists("/tmp/install_complete");
282
		return;
283
	}
284
	$running_old = trim(file_get_contents("/tmp/installer_installer_running"));
285
	if($installer_running <> "running") {
286
		$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
287
		if($ps_running)	{
288
			$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>'; ";
289
			if($running_old <> $running) {
290
				echo $running;
291
				file_put_contents("/tmp/installer_installer_running", "$running");			
292
			}
293
		}
294
	}
295
	if($progress) 
296
		echo "\$('progressbar').style.width='{$progress}%';\n";
297
	if(file_exists("/tmp/install_complete")) {
298
		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";
299
		echo "\$('pbdiv').Fade();\n";
300
		unlink_if_exists("/tmp/installer.sh");
301
		file_put_contents("/tmp/installer_installer_running", "finished");
302
	}
303
}
304

    
305
function update_installer_status_win($status) {
306
	global $g, $fstype, $savemsg;
307
	echo "<script type=\"text/javascript\">\n";
308
	echo "	\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
309
	echo "</script>";
310
}
311

    
312
function begin_install() {
313
	global $g, $savemsg;
314
	if(file_exists("/tmp/install_complete"))
315
		return;
316
	unlink_if_exists("/tmp/install_complete");
317
	update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk));
318
	start_installation();
319
}
320

    
321
function head_html() {
322
	global $g, $fstype, $savemsg;
323
	echo <<<EOF
324
<html>
325
	<head>
326
		<style type='text/css'>
327
			a:link { 
328
				color: #000000;
329
				text-decoration:underline;
330
				font-size:14;
331
			}
332
			a:visited { 
333
				color: #000000;
334
				text-decoration:underline;
335
				font-size:14;
336
			}
337
			a:hover { 
338
				color: #FFFF00;
339
				text-decoration: none;
340
				font-size:14;
341
			}
342
			a:active { 
343
				color: #FFFF00;
344
				text-decoration:underline;
345
				font-size:14;
346
			}
347
		</style>
348
	</head>
349
EOF;
350

    
351
}
352

    
353
function body_html() {
354
	global $g, $fstype, $savemsg;
355
	$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
356
	if(strstr($pfSversion, "1.2")) 
357
		$one_two = true;
358
	$pgtitle = array("{$g['product_name']}", gettext("Installer"));
359
	include("head.inc");
360
	echo <<<EOF
361
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
362
	<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
363
	<script type="text/javascript">
364
		function getinstallerprogress() {
365
			url = '/installer/installer.php';
366
			pars = 'state=update_installer_status';
367
			callajax(url, pars, installcallback);
368
		}
369
		function callajax(url, pars, activitycallback) {
370
			var myAjax = new Ajax.Request(
371
				url,
372
				{
373
					method: 'post',
374
					parameters: pars,
375
					onComplete: activitycallback
376
				});
377
		}
378
		function installcallback(transport) {
379
			setTimeout('getinstallerprogress()', 2000);
380
			eval(transport.responseText);
381
		}
382
	</script>
383
EOF;
384

    
385
	if($one_two)
386
		echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
387

    
388
	if ($savemsg) print_info_box($savemsg); 
389
}
390

    
391
function end_html() {
392
	global $g, $fstype, $savemsg;
393
	echo "</form>";
394
	echo "</body>";
395
	echo "</html>";
396
}
397

    
398
function template() {
399
	global $g, $fstype, $savemsg;
400
	head_html();
401
	body_html();
402
	echo <<<EOF
403
	<div id="mainlevel">
404
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
405
	 		<tr>
406
	    		<td>
407
					<div id="mainarea">
408
						<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
409
							<tr>
410
	     						<td class="tabcont" >
411
	      							<form action="installer.php" method="post">
412
									<div id="pfsensetemplate">
413

    
414

    
415
									</div>
416
	     						</td>
417
							</tr>
418
						</table>
419
					</div>
420
				</td>
421
			</tr>
422
		</table>
423
	</div>
424
EOF;
425
	end_html();
426
}
427

    
428
function verify_before_install() {
429
	global $g, $fstype, $savemsg;
430
	$encyrpted_root = false;
431
	$non_encyrpted_boot = false;
432
	head_html();
433
	body_html();
434
	page_table_start();
435
	// If we are visiting this step from anything but the row editor / custom install
436
	// then load the on disk layout contents if they are available.
437
	if(!$_REQUEST['fstype0'] && file_exists("/tmp/webInstaller_disk_layout.txt")) {
438
		$disks = unserialize(file_get_contents("/tmp/webInstaller_disk_layout.txt"));
439
		$restored_layout_from_file = true;
440
		$restored_layout_txt = "The previous disk layout was restored from disk";
441
	}
442
	echo "\n<!--" . print_r($_REQUEST, true) . " -->\n";
443
	$disk = pcsysinstall_get_disk_info(htmlspecialchars($_REQUEST['disk']));
444
	$disksize = format_bytes($disk['size'] * 1048576);
445
	$bootmanager = htmlspecialchars($_REQUEST['bootmanager']);	
446
	$disks = array();
447
	// Loop through posted items and create an array
448
	for($x=0; $x<99; $x++) { // XXX: Make this more optimal
449
		if(!$_REQUEST['fstype' . $x])
450
			continue;
451
		$tmparray = array();
452
		if($_REQUEST['fstype' . $x] <> "SWAP") {			
453
			$tmparray['mountpoint'] = $_REQUEST['mountpoint' . $x];
454
			// Check for encrypted slice /
455
			if(stristr($_REQUEST['fstype' . $x], ".eli")) {
456
				if($tmparray['mountpoint'] == "/") 
457
					$encyrpted_root = true;
458
			}
459
			// Check if we have a non-encrypted /boot
460
			if($tmparray['mountpoint'] == "/boot") 	{
461
				if(!stristr($_REQUEST['fstype' . $x], ".eli"))
462
					$non_encyrpted_boot = true;
463
			}
464
			if($tmparray['mountpoint'] == "/conf") {	
465
				$tmparray['mountpoint'] = "/conf{$x}";
466
				$error_txt .= "<center><font color='red'>/conf is not an allowed mount point and has been renamed to /conf{$x}.</font></center><br/>";
467
			}
468
		} else  {
469
			$tmparray['mountpoint'] = "none";
470
		}
471
		// If we have an encrypted /root and lack a non encyrpted /boot, throw an error/warning
472
		if($encyrpted_root && $non_encyrpted_boot) 
473
			$error_txt .= "<center><font color='red'>A non-encrypted /boot slice is required when encrypting the / slice</font></center><br/>";
474
		$tmparray['disk'] = $_REQUEST['disk' . $x];
475
		$tmparray['fstype'] = $_REQUEST['fstype' . $x];
476
		$tmparray['size'] = $_REQUEST['size' . $x];
477
		$tmparray['encpass'] = $_REQUEST['encpass' . $x];
478
		$disks[] = $tmparray;
479
	}
480
	echo "\n<!-- " . print_r($disks, true) . " --> \n";
481
	echo <<<EOFAMBAC
482
	<form method="post" action="installer.php">
483
	<input type="hidden" name="fstype" value="{$fstype_echo}">
484
	<input type="hidden" name="disk" value="{$disk_echo}">
485
	<input type="hidden" name="state" value="begin_install">
486
	<input type="hidden" name="swapsize" value="{$swapsize}">
487
	<input type="hidden" name="encpass" value="{$encpass}">
488
	<input type="hidden" name="bootmanager" value="{$bootmanager}">
489
	<div id="mainlevel">
490
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
491
	 		<tr>
492
	    		<td>
493
					<div id="mainarea">
494
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
495
							<tr>
496
	     						<td >
497
									<div>
498
										<center>
499
											<div id="pfsensetemplate">
500
												<table bgcolor="FFFF00" width="800" height="30" cellpadding="2" style="border:1px dashed;">
501
													<tr valign="middle">
502
														<td>
503
															<center><b>Please verify that the following is correct:</b></center>
504
														</td>
505
													</tr>
506
												</table>
507
												<p/>
508
												{$error_txt}
509
												<table width='100%'>
510
												<tr><td colspan='5' align="center"><b>Boot manager: {$bootmanager}</td></tr>
511
												<tr><td colspan='5'><hr></td></tr>
512
												<tr>
513
													<td>
514
														<b>Mount point</b>
515
													</td>
516
													<td>
517
														<b>Filesysyem type</b>
518
													</td>
519
													<td>
520
														<b>Disk</b>
521
													</td>
522
													<td>
523
														<b>Size</b>
524
													</td>
525
													<td>
526
														<b>Encryption password</b>
527
													</td>
528

    
529
EOFAMBAC;
530

    
531
													foreach($disks as $disk) {
532
														$desc = pcsysinstall_get_disk_info($disk['disk']);
533
														echo "<tr>";
534
														echo "<td>{$disk['mountpoint']}</td>";
535
														echo "<td>{$disk['fstype']}</td>";
536
														echo "<td>{$disk['disk']} {$desc['desc']}</td>";
537
														echo "<td>{$disk['size']}</td>";
538
														echo "<td>{$disk['encpass']}</td>";
539
														echo "</tr>";
540
													}
541

    
542
echo <<<EOFAMB
543
												<tr><td colspan='5'><hr></td></tr>
544
												</table>
545
											</div>
546
										</center>
547
									</div>
548
	     						</td>
549
							</tr>
550
						</table>
551
					</div>
552
					<center>
553
						<p/>
554
						<input type="button" value="Cancel" onClick="javascript:document.location='installer.php?state=custominstall';"> &nbsp;&nbsp;
555
						<input type="submit" value="Begin installation"> 
556
					</center>
557
				</td>
558
			</tr>
559
		</table>
560
	</div>
561

    
562
EOFAMB;
563

    
564
	page_table_end();
565
	end_html();
566
	write_out_pc_sysinstaller_config($disks, $bootmanager);
567
	file_put_contents("/tmp/webInstaller_disk_layout.txt", serialize($disks));
568

    
569
}
570

    
571
function installing_gui() {
572
	global $g, $fstype, $savemsg;
573
	head_html();
574
	body_html();
575
	echo "<form action=\"installer.php\" method=\"post\" state=\"step1_post\">";
576
	page_table_start();
577
	echo <<<EOF
578
	<center>
579
		<table width="100%">
580
		<tr><td>
581
			<div id="mainlevel">
582
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
583
			 		<tr>
584
			    		<td>
585
							<div id="mainarea">
586
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
587
									<tr>
588
			     						<td>
589
											<div id="pfsenseinstaller" width="100%">
590
												<div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000">
591
													<table>
592
														<tr>
593
															<td valign="middle">
594
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
595
															</td>
596
															<td valign="middle">
597
																&nbsp;<font size="2"><b>Starting Installer...  Please wait...
598
															</td>
599
														</tr>
600
													</table>
601
												</div>
602
												<div id='pbdiv'>
603
													<br/>
604
													<center>
605
													<table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
606
														<tr>
607
															<td background="/themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
608
															</td>
609
															<td>
610
																<table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
611
																	<td background="/themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
612
																		<img src='/themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
613
																	</td>
614
																</table>
615
															</td>
616
															<td background="/themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
617
															</td>
618
														</tr>
619
													</table>
620
													<br/>
621
												</div>
622
												<textarea name='installeroutput' id='installeroutput' rows="31" cols="90">
623
												</textarea>
624
											</div>
625
			     						</td>
626
									</tr>
627
								</table>
628
							</div>
629
						</td>
630
					</tr>
631
				</table>
632
			</div>
633
		</td></tr>
634
		</table>
635
	</center>
636
	<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
637

    
638
EOF;
639
	page_table_end();
640
	end_html();
641
}
642

    
643
function page_table_start($pgtitle = "") {
644
	global $g, $fstype, $savemsg;
645
	if($pgtitle == "") 
646
		$pgtitle = "{$g['product_name']} installer";
647
	echo <<<EOF
648
	<center>
649
		<img border="0" src="/themes/{$g['theme']}/images/logo.gif"></a><br/>
650
		<table cellpadding="6" cellspacing="0" width="550" style="border:1px solid #000000">
651
		<tr height="10" bgcolor="#990000">
652
			<td style="border-bottom:1px solid #000000">
653
				<font color='white'>
654
					<b>
655
						{$pgtitle}
656
					</b>
657
				</font>
658
			</td>
659
		</tr>
660
		<tr>
661
			<td>
662

    
663
EOF;
664

    
665
}
666

    
667
function page_table_end() {
668
	global $g, $fstype, $savemsg;
669
	echo <<<EOF
670
			</td>
671
		</tr>
672
		</table>
673
	</center>
674

    
675
EOF;
676
	
677
}
678

    
679
function installer_custom() {
680
	global $g, $fstype, $savemsg;
681
	global $select_txt, $custom_disks;
682
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
683
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
684
	head_html();
685
	body_html();
686
	page_table_start();
687
	echo <<<EOF
688
		<script type="text/javascript">
689
			function row_helper_dynamic_custom(tr) {
690
				var totalsize = 0;
691
				for(var x = 0; x<99; x++) { //optimize me better
692
					if($('size' + x)) {
693
						totalsize += parseInt($('size' + x).value);
694
						//alert($('size' + x).value);
695
					}
696
				}
697
				$('totalsize').value = totalsize;
698
			}
699
		</script>
700
		<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
701
		<script type="text/javascript">
702
			// Setup rowhelper data types
703
			rowname[0] = "mountpoint";
704
			rowtype[0] = "textbox";
705
			rowsize[0] = "8";
706
			rowname[1] = "fstype";
707
			rowtype[1] = "select";
708
			rowsize[1] = "1";
709
			rowname[2] = "disk";
710
			rowtype[2] = "select";
711
			rowsize[2] = "1";
712
			rowname[3] = "size";
713
			rowtype[3] = "textbox";
714
			rowsize[3] = "8";
715
			rowname[4] = "encpass";
716
			rowtype[4] = "textbox";
717
			rowsize[4] = "8";
718
			field_counter_js = 5;
719
			rows = 1;
720
			totalrows = 1;
721
			loaded = 1;
722
		</script>
723
		<form action="installer.php" method="post">
724
			<input type="hidden" name="state" value="verify_before_install">
725
			<div id="mainlevel">
726
				<center>
727
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
728
			 		<tr>
729
			    		<td>
730
							<center>
731
							<div id="mainarea">
732
								<center>
733
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
734
									<tr>
735
			     						<td>
736
											<div id="pfsenseinstaller">
737
												<center>
738
												<div id='loadingdiv'>
739
													<img src="/themes/{$g['theme']}/images/misc/loader.gif"> Probing disks, please wait...
740
												</div>
741
EOF;
742
	ob_flush();
743
	$disks = installer_find_all_disks();
744
	if(!$disks)  {
745
		$custom_txt = gettext("ERROR: Could not find any suitable disks for installation.");
746
	} else {
747
		// Prepare disk selection dropdown
748
		$custom_txt = <<<EOF
749
												<center>
750
												<table>
751
												<tr>
752
													<td align='right'>
753
														Boot manager:
754
													</td>
755
													<td>
756
														<select name='bootmanager'>
757
															<option value='none'>
758
																None
759
															</option>
760
															<option value='bsd'>
761
																BSD
762
															</option>
763
														</select>
764
													</td>
765
												</tr>
766
												</table>
767
												<hr>
768
												<table id='maintable'><tbody>
769
												<tr>
770
													<td align="middle">
771
														<b>Mount</b>
772
													</td>
773
													<td>
774
														<b>Filesysyem</b>
775
													</td>
776
													<td align="middle">
777
														<b>Disk</b>
778
													</td>
779
													<td align="middle">
780
														<b>Size</b>
781
													</td>
782
													<td align="middle">
783
														<b>Encryption password</b>
784
													</td>
785
													<td>
786
														&nbsp;
787
													</td>
788
												</tr>
789
												<tr>
790

    
791
EOF;
792

    
793
		// Calculate swap disk sizes
794
		$memory = get_memory();
795
		$swap_size = $memory[0] * 2;
796
		$first_disk = trim(installer_find_first_disk());
797
		$disk_info = pcsysinstall_get_disk_info($first_disk);
798
		$size = $disk_info['size'];
799
		$first_disk_size = $size - $swap_size;
800

    
801
		// Debugging
802
		echo "\n\n<!-- $first_disk - " . print_r($disk_info, true) . " - $size  - $first_disk_size -->\n\n";
803

    
804
		// Check to see if a on disk layout exists
805
		if(file_exists("/tmp/webInstaller_disk_layout.txt")) {
806
			$disks_restored = unserialize(file_get_contents("/tmp/webInstaller_disk_layout.txt"));
807
			$restored_layout_from_file = true;
808
			$restored_layout_txt = "<br/>* The previous disk layout was restored from disk";
809
		}
810

    
811
		// If we restored disk layout(s) from a file then build the rows
812
		if($restored_layout_from_file == true) {
813
			$diskcounter = 0;
814
			foreach($disks_restored as $dr) {
815
				$custom_txt .= return_rowhelper_row("$diskcounter", $dr['mountpoint'], $dr['fstype'], $dr['disk'], $dr['size'], $dr['encpass']);
816
				$diskcounter++;
817
			}
818
		} else {		
819
			// Construct the default rows that outline the disks configuration.
820
			$custom_txt .= return_rowhelper_row("0", "/", "UFS", $first_disk, "{$first_disk_size}", "");
821
			$custom_txt .= return_rowhelper_row("1", "none", "SWAP", $first_disk, "$swap_size", "");
822
		}
823

    
824
		// tfoot and tbody are used by rowhelper
825
		$custom_txt .= "</tr>";
826
		$custom_txt .= "<tfoot></tfoot></tbody>";
827
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Total allocated:</td><td><input size=\"8\" id='totalsize' name='totalsize'></td></tr>";
828
		$custom_txt .= "</table>";
829
		$custom_txt .= "<script type=\"text/javascript\">row_helper_dynamic_custom();</script>";
830
	}
831
	echo <<<EOF
832

    
833
												<tr>
834
													<td colspan='4'>
835
													<script type="text/javascript">
836
														\$('loadingdiv').style.visibility='hidden';
837
													</script>
838
													<div id='contentdiv' style="display:none;">
839
														<p/>
840
														{$custom_txt}<p/>
841
														<hr><p/>
842
														<input type="button" value="Cancel" onClick="javascript:document.location='/installer/installer.php';"> &nbsp;&nbsp
843
														<input type="submit" value="Next">
844
													</div>
845
													<script type="text/javascript">
846
														\$('contentdiv').appear();
847
														function onfstypeChange() {
848
															for(var x = 0; x<99; x++) { //optimize me better
849
																if($('fstype' + x)) {
850
																	var fstype = \$F('fstype' + x);
851
																	if(fstype.substring(fstype.length - 4) == ".eli") {
852
																		\$('encpass' + x).disabled = 0;
853
																		alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!');
854
																	} else { 
855
																		\$('encpass' + x).disabled = 1;
856
																	}
857
																}
858
															}
859
														}
860
														onfstypeChange();
861
													</script>
862
												</center>
863
												</td></tr>
864
												</table>
865
											</div>
866
			     						</td>
867
									</tr>
868
								</table>
869
								</center>
870
								<span class="vexpl">
871
									<span class="red">
872
										<strong>
873
											NOTES:
874
										</strong>
875
									</span>
876
									<br/>* Sizes are in megabytes.
877
									<br/>* Encryption password field should only be used if a encrypted filesystem (.eli) was chosen
878
									<br/>* Mount points named /conf are not allowed.  Use /cf if you want to make a configuration slice/mount.
879
									{$restored_layout_txt}
880
								</span>
881
								</strong>
882
							</div>
883
						</td>
884
					</tr>
885
				</table>
886
			</div>
887
			</center>
888
			<script type="text/javascript">
889
			<!--
890
				newrow[1] = "{$select_txt}";
891
				newrow[2] = "{$custom_disks}";
892
			-->
893
			</script>
894
			
895

    
896
EOF;
897
	page_table_end();
898
	end_html();
899
}
900

    
901
function installer_main() {
902
	global $g, $fstype, $savemsg;
903
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
904
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
905
	head_html();
906
	body_html();
907
	$disk = installer_find_first_disk();
908
	// Only enable ZFS if this exists.  The install will fail otherwise.
909
//	if(file_exists("/boot/gptzfsboot")) 
910
//		$zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"installer.php?state=verify_before_install&fstype0=ZFS&size=200M\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>";
911
	page_table_start();
912
	echo <<<EOF
913
		<form action="installer.php" method="post" state="step1_post">
914
			<div id="mainlevel">
915
				<center>
916
				<b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/>
917
				<font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font>
918
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
919
			 		<tr>
920
			    		<td>
921
							<center>
922
							<div id="mainarea">
923
								<br/>
924
								<center>
925
								Please select an installer option to begin:
926
								<p/>
927
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
928
									<tr>
929
			     						<td>
930
											<div id="pfsenseinstaller">
931
												<center>
932
EOF;
933
	if(!$disk) {
934
		echo gettext("ERROR: Could not find any suitable disks for installation.");
935
		echo "</div></td></tr></table></div></table></div>";
936
		end_html();
937
		exit;
938
	}
939
	echo <<<EOF
940

    
941
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
942
														<tr bgcolor="#CECECE"><td align="center">
943
<!--
944
															<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>
945
-->
946
														</td></tr>
947
													 	{$zfs_enabled}
948
														<tr bgcolor="#AAAAAA"><td align="center">
949
															<a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a>
950
														</td></tr>
951
														<tr bgcolor="#CECECE"><td align="center">
952
															<a href='/'>Cancel and return to Dashboard</a>
953
														</td></tr>
954
													</table>
955
												</center>
956
											</div>
957
			     						</td>
958
									</tr>
959
								</table>
960
							</div>
961
						</td>
962
					</tr>
963
				</table>
964
			</div>
965
EOF;
966
	page_table_end();
967
	end_html();
968
}
969

    
970
function return_rowhelper_row($rownum, $mountpoint, $fstype, $disk, $size, $encpass) {
971
		global $g, $select_txt, $custom_disks, $savemsg;
972
		$release = php_uname("r");
973
		$release = trim($release[0]);
974

    
975
		// Mount point
976
		$disks = installer_find_all_disks();
977
		$custom_txt .= "<tr>";
978
		$custom_txt .=  "<td><input size='8' id='mountpoint{$rownum}' name='mountpoint{$rownum}' value='{$mountpoint}'></td>";
979

    
980
		// Filesystem type array
981
		$types = array(
982
			'UFS' => 'UFS',
983
			'UFS+S' => 'UFS + Softupdates',
984
			'UFS.eli' => 'Encrypted UFS',
985
			'UFS+S.eli' => 'Encrypted UFS + Softupdates',
986
			'SWAP' => 'SWAP'
987
		);
988

    
989
		// UFS + Journaling was introduced in 9.0
990
		if($release == "9") {
991
			$types['UFS+J'] = "UFS + Journaling";
992
			$types['UFS+J.eli'] = "Encrypted UFS + Journaling";
993
		}
994
		
995
		// Add ZFS Boot loader if it exists
996
		if(file_exists("/boot/gptzfsboot")) {
997
			$types['ZFS'] = "Zetabyte Filesystem";
998
			$types['ZFS.eli'] = "Encrypted Zetabyte Filesystem";
999
		}
1000

    
1001
		// fstype form field
1002
		$custom_txt .=  "<td><select onChange='javascript:onfstypeChange()' id='fstype{$rownum}' name='fstype{$rownum}'>";
1003
		$select_txt = "";
1004
		foreach($types as $type => $desc) {
1005
			if($type == $fstype)
1006
				$SELECTED="SELECTED";
1007
			else 
1008
				$SELECTED="";
1009
			$select_txt .= "<option value='$type' $SELECTED>$desc</option>";
1010
		}
1011
		$custom_txt .= "{$select_txt}</select>\n";
1012
		$custom_txt .= "</td>";
1013
		
1014
		// Disk selection form field
1015
		$custom_txt .= "<td><select id='disk{$rownum}' name='disk{$rownum}'>\n";
1016
		$custom_disks = "";
1017
		foreach($disks as $dsk) {
1018
			$disksize_bytes = format_bytes($dsk['size'] * 1048576);
1019
			$disksize = $dsk['size'];
1020
			if($disk == $dsk['disk'])
1021
				$SELECTED="SELECTED";
1022
			else 
1023
				$SELECTED="";
1024
			$custom_disks .= "<option value='{$dsk['disk']}' $SELECTED>{$dsk['disk']} - {$dsk['desc']} - {$disksize}MB ({$disksize_bytes})</option>";
1025
		}
1026
		$custom_txt .= "{$custom_disks}</select></td>\n";
1027

    
1028
		// Slice size
1029
		$custom_txt .= "<td><input onChange='javascript:row_helper_dynamic_custom();' name='size{$rownum}' id='size{$rownum}' size='8' type='text' value='{$size}'></td>";
1030

    
1031
		// Encryption password
1032
		$custom_txt .= "<td>";
1033
		$custom_txt .= "<input id='encpass{$rownum}' name='encpass{$rownum}' size='8' value='{$encpass}'>";
1034
		$custom_txt .= "</td>";
1035
	
1036
		// Add Rowhelper + button
1037
		if($rownum == 1) {
1038
			$custom_txt .= "<td>";
1039
			$custom_txt .= "<div id=\"addrowbutton\">";
1040
			$custom_txt .= "<a onclick=\"javascript:addRowTo('maintable', 'formfldalias'); return false;\" href=\"#\">";
1041
			$custom_txt .= "<img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" alt=\"\" title=\"add another entry\" /></a>";
1042
			$custom_txt .= "</div>";
1043
			$custom_txt .= "</td>";	
1044
		}
1045

    
1046
		$custom_txt .= "</tr>";	
1047
		return $custom_txt;
1048
}
1049

    
1050
?>
(2-2/2)