Project

General

Profile

Download (27.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	index.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: /index.php");
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
	// First make sure we have a boot partition if any slices are encrypted
73
	foreach($disks as $disksa) {
74
		$fstype = $disksa['fstype'];
75
		if(stristr($fstype,".eli")) 
76
			$diskareas .=  "disk{$numdisks}-part=UFS 500 /boot\n";
77
	}
78
	// Run through the disks and create the conf areas for pc-sysinstaller
79
	foreach($disks as $disksa) {
80
		$fstype = $disksa['fstype'];
81
		$size = $disksa['size'];
82
		$mountpoint = $disksa['mountpoint'];
83
		$disk = $disksa['disk'];
84
		if($disk <> $lastdisk) {
85
			$lastdisk = $disk;
86
			$numdisks++;
87
			$diskdefs .= "disk{$numdisks}={$disk}\n";
88
		}
89
		$diskareas .= "disk{$numdisks}-part={$fstype} {$size} {$mountpoint} \n";
90
		if($encpass)
91
			$diskareas .= "encpass={$encpass}\n";
92
	}
93
	
94
	$config = <<<EOF
95
# Sample configuration file for an installation using pc-sysinstall
96

    
97
installMode=fresh
98
installInteractive=yes
99
installType=FreeBSD
100
installMedium=LiveCD
101

    
102
# Set the disk parameters
103
{$diskdefs}
104
partition=all
105
bootManager={$bootmanager}
106
commitDiskPart
107

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

    
125
# Do it now!
126
commitDiskLabel
127

    
128
# Set if we are installing via optical, USB, or FTP
129
installType=FreeBSD
130

    
131
packageType=cpdup
132

    
133
# Optional Components
134
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,usr,var
135

    
136
# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh
137
EOF;
138
	fwrite($fd, $config);
139
	fclose($fd);
140
	return;
141
}
142

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

    
167
function installer_find_first_disk() {
168
	global $g, $fstype;
169
	$disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`;
170
	return $disk;
171
}
172

    
173
function pcsysinstall_get_disk_info($diskname) {
174
	global $g, $fstype;
175
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
176
	$disks_array = array();
177
	foreach($disk as $d) {
178
		if(!$d) 
179
			continue;
180
		$disks_info = split(":", $d);
181
		$tmp_array = array();
182
		if($disks_info[0] == $diskname) {
183
			$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
184
			foreach($disk_info as $di) { 
185
				$di_s = split("=", $di);
186
				if($di_s[0])
187
					$tmp_array[$di_s[0]] = $di_s[1];
188
			}
189
			$tmp_array['disk'] = trim($disks_info[0]);
190
			$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
191
			return $tmp_array;
192
		}
193
	}
194
}
195

    
196
// Return an array with all disks information.
197
function installer_find_all_disks() {
198
	global $g, $fstype;
199
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
200
	$disks_array = array();
201
	foreach($disk as $d) {
202
		if(!$d) 
203
			continue;
204
		$disks_info = split(":", $d);
205
		$tmp_array = array();
206
		$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
207
		foreach($disk_info as $di) { 
208
			$di_s = split("=", $di);
209
			if($di_s[0])
210
				$tmp_array[$di_s[0]] = $di_s[1];
211
		}
212
		$tmp_array['disk'] = trim($disks_info[0]);
213
		$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
214
		$disks_array[] = $tmp_array;
215
	}
216
	return $disks_array;
217
}
218

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

    
314
function update_installer_status_win($status) {
315
	global $g, $fstype;
316
	echo "<script type=\"text/javascript\">\n";
317
	echo "	\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
318
	echo "</script>";
319
}
320

    
321
function begin_install() {
322
	global $g;
323
	if(file_exists("/tmp/install_complete"))
324
		return;
325
	unlink_if_exists("/tmp/install_complete");
326
	update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk));
327
	start_installation();
328
}
329

    
330
function head_html() {
331
	global $g, $fstype;
332
	echo <<<EOF
333
<html>
334
	<head>
335
		<style type='text/css'>
336
			a:link { 
337
				color: #000000;
338
				text-decoration:underline;
339
				font-size:14;
340
			}
341
			a:visited { 
342
				color: #000000;
343
				text-decoration:underline;
344
				font-size:14;
345
			}
346
			a:hover { 
347
				color: #FFFF00;
348
				text-decoration: none;
349
				font-size:14;
350
			}
351
			a:active { 
352
				color: #FFFF00;
353
				text-decoration:underline;
354
				font-size:14;
355
			}
356
		</style>
357
	</head>
358
EOF;
359

    
360
}
361

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

    
394
	if($one_two)
395
		echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
396

    
397
	if ($savemsg) print_info_box($savemsg); 
398
}
399

    
400
function end_html() {
401
	global $g, $fstype;
402
	echo "</form>";
403
	echo "</body>";
404
	echo "</html>";
405
}
406

    
407
function template() {
408
	global $g, $fstype;
409
	head_html();
410
	body_html();
411
	echo <<<EOF
412
	<div id="mainlevel">
413
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
414
	 		<tr>
415
	    		<td>
416
					<div id="mainarea">
417
						<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
418
							<tr>
419
	     						<td class="tabcont" >
420
	      							<form action="index.php" method="post">
421
									<div id="pfsensetemplate">
422

    
423

    
424
									</div>
425
	     						</td>
426
							</tr>
427
						</table>
428
					</div>
429
				</td>
430
			</tr>
431
		</table>
432
	</div>
433
EOF;
434
	end_html();
435
}
436

    
437
function verify_before_install() {
438
	global $g, $fstype;
439
	head_html();
440
	body_html();
441
	page_table_start();
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=1; isset($_REQUEST['fstype' . $x]); $x++) {
449
		$tmparray = array();
450
		$tmparray['mountpoint'] = $_REQUEST['mountpoint' . $x];
451
		$tmparray['disk'] = $_REQUEST['disk' . $x];
452
		$tmparray['fstype'] = $_REQUEST['fstype' . $x];
453
		$tmparray['size'] = $_REQUEST['size' . $x];
454
		$tmparray['encpass'] = $_REQUEST['encpass' . $x];
455
		$disks[] = $tmparray;
456
	}
457
	echo "\n<!-- " . print_r($disks, true) . " --> \n";
458
	echo <<<EOFAMBAC
459
	<form method="post" action="index.php">
460
	<input type="hidden" name="fstype" value="{$fstype_echo}">
461
	<input type="hidden" name="disk" value="{$disk_echo}">
462
	<input type="hidden" name="state" value="begin_install">
463
	<input type="hidden" name="swapsize" value="{$swapsize}">
464
	<input type="hidden" name="encpass" value="{$encpass}">
465
	<input type="hidden" name="bootmanager" value="{$bootmanager}">
466
	<div id="mainlevel">
467
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
468
	 		<tr>
469
	    		<td>
470
					<div id="mainarea">
471
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
472
							<tr>
473
	     						<td >
474
									<div>
475
										<center>
476
											<div id="pfsensetemplate">
477
												<table bgcolor="FFFF00" width="800" height="30" cellpadding="2" style="border:1px dashed;">
478
													<tr valign="middle">
479
														<td>
480
															<center><b>Please verify that the following is correct:</b></center>
481
														</td>
482
													</tr>
483
												</table>
484
												<p/>
485
												<table width='100%'>
486
												<tr><td colspan='5' align="center"><b>Boot manager: {$bootmanager}</td></tr>
487
												<tr><td colspan='5'><hr></td></tr>
488
												<tr>
489
													<td>
490
														<b>Mount point</b>
491
													</td>
492
													<td>
493
														<b>Filesysyem type</b>
494
													</td>
495
													<td>
496
														<b>Disk</b>
497
													</td>
498
													<td>
499
														<b>Size</b>
500
													</td>
501
													<td>
502
														<b>Encryption password</b>
503
													</td>
504

    
505
EOFAMBAC;
506

    
507
													foreach($disks as $disk) {
508
														$desc = pcsysinstall_get_disk_info($disk['disk']);
509
														echo "<tr>";
510
														echo "<td>{$disk['mountpoint']}</td>";
511
														echo "<td>{$disk['fstype']}</td>";
512
														echo "<td>{$disk['disk']} {$desc['desc']}</td>";
513
														echo "<td>{$disk['size']}</td>";
514
														echo "<td>{$disk['encpass']}</td>";
515
														echo "</tr>";
516
													}
517

    
518
echo <<<EOFAMB
519
												<tr><td colspan='5'><hr></td></tr>
520
												</table>
521
											</div>
522
										</center>
523
									</div>
524
	     						</td>
525
							</tr>
526
						</table>
527
					</div>
528
					<center>
529
						<p/>
530
						<input type="button" value="Cancel" onClick="javascript:document.location='/installer';"> &nbsp;&nbsp;
531
						<input type="submit" value="Begin installation"> 
532
					</center>
533
				</td>
534
			</tr>
535
		</table>
536
	</div>
537

    
538
EOFAMB;
539

    
540
	page_table_end();
541
	end_html();
542
	write_out_pc_sysinstaller_config($disks, $bootmanager);
543

    
544
}
545

    
546
function installing_gui() {
547
	global $g, $fstype;
548
	head_html();
549
	body_html();
550
	echo "<form action=\"index.php\" method=\"post\" state=\"step1_post\">";
551
	page_table_start();
552
	echo <<<EOF
553
	<center>
554
		<table width="100%">
555
		<tr><td>
556
			<div id="mainlevel">
557
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
558
			 		<tr>
559
			    		<td>
560
							<div id="mainarea">
561
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
562
									<tr>
563
			     						<td>
564
											<div id="pfsenseinstaller" width="100%">
565
												<div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000">
566
													<table>
567
														<tr>
568
															<td valign="middle">
569
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
570
															</td>
571
															<td valign="middle">
572
																&nbsp;<font size="2"><b>Starting Installer...  Please wait...
573
															</td>
574
														</tr>
575
													</table>
576
												</div>
577
												<div id='pbdiv'>
578
													<br/>
579
													<center>
580
													<table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
581
														<tr>
582
															<td background="./themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
583
															</td>
584
															<td>
585
																<table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
586
																	<td background="./themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
587
																		<img src='./themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
588
																	</td>
589
																</table>
590
															</td>
591
															<td background="./themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
592
															</td>
593
														</tr>
594
													</table>
595
													<br/>
596
												</div>
597
												<textarea name='installeroutput' id='installeroutput' rows="31" cols="90">
598
												</textarea>
599
											</div>
600
			     						</td>
601
									</tr>
602
								</table>
603
							</div>
604
						</td>
605
					</tr>
606
				</table>
607
			</div>
608
		</td></tr>
609
		</table>
610
	</center>
611
	<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
612

    
613
EOF;
614
	page_table_end();
615
	end_html();
616
}
617

    
618
function page_table_start($pgtitle = "") {
619
	global $g, $fstype;
620
	if($pgtitle == "") 
621
		$pgtitle = "{$g['product_name']} installer";
622
	echo <<<EOF
623
	<center>
624
		<img border="0" src="/themes/{$g['theme']}/images/logo.gif"></a><br/>
625
		<table cellpadding="6" cellspacing="0" width="550" style="border:1px solid #000000">
626
		<tr height="10" bgcolor="#990000">
627
			<td style="border-bottom:1px solid #000000">
628
				<font color='white'>
629
					<b>
630
						{$pgtitle}
631
					</b>
632
				</font>
633
			</td>
634
		</tr>
635
		<tr>
636
			<td>
637

    
638
EOF;
639

    
640
}
641

    
642
function page_table_end() {
643
	global $g, $fstype;
644
	echo <<<EOF
645
			</td>
646
		</tr>
647
		</table>
648
	</center>
649

    
650
EOF;
651
	
652
}
653

    
654
function installer_custom() {
655
	global $g, $fstype;
656
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
657
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
658
	head_html();
659
	body_html();
660
	page_table_start();
661
	echo <<<EOF
662
		<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
663
		<script type="text/javascript">
664
			// Setup rowhelper data types
665
			rowname[0] = "mountpoint";
666
			rowtype[0] = "textbox";
667
			rowsize[0] = "8";
668
			rowname[1] = "fstype";
669
			rowtype[1] = "select";
670
			rowsize[1] = "1";
671
			rowname[2] = "disk";
672
			rowtype[2] = "select";
673
			rowsize[2] = "1";
674
			rowname[3] = "size";
675
			rowtype[3] = "textbox";
676
			rowsize[3] = "8";
677
			rowname[4] = "encpass";
678
			rowtype[4] = "textbox";
679
			rowsize[4] = "8";
680
			field_counter_js = 5;
681
			rows = 1;
682
			totalrows = 1;
683
			loaded = 1;
684
		</script>
685
		<form action="index.php" method="post">
686
			<input type="hidden" name="state" value="verify_before_install">
687
			<div id="mainlevel">
688
				<center>
689
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
690
			 		<tr>
691
			    		<td>
692
							<center>
693
							<div id="mainarea">
694
								<center>
695
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
696
									<tr>
697
			     						<td>
698
											<div id="pfsenseinstaller">
699
												<center>
700
												<div id='loadingdiv'>
701
													<img src="/themes/{$g['theme']}/images/misc/loader.gif"> Probing disks, please wait...
702
												</div>
703
EOF;
704
	ob_flush();
705
	$disks = installer_find_all_disks();
706
	if(!$disks)  {
707
		$custom_txt = gettext("ERROR: Could not find any suitable disks for installation.");
708
	} else {
709
		// Prepare disk selection dropdown
710
		$custom_txt = <<<EOF
711
												<center>
712
												<table>
713
												<tr>
714
													<td align='right'>
715
														Boot manager:
716
													</td>
717
													<td>
718
														<select name='bootmanager'>
719
															<option value='bsd'>
720
																BSD
721
															</option>
722
															<option value='none'>
723
																None
724
														</select>
725
													</td>
726
												</tr>
727
												</table>
728
												<hr>
729
												<table id='maintable'><tbody>
730
												<tr>
731
													<td>
732
														<b>Mount point</b>
733
													</td>
734
													<td>
735
														<b>Filesysyem type</b>
736
													</td>
737
													<td>
738
														<b>Disk</b>
739
													</td>
740
													<td>
741
														<b>Size</b>
742
													</td>
743
													<td>
744
														<b>Encryption password</b>
745
													</td>
746
													<td>
747
														&nbsp;
748
													</td>
749
												</tr>
750
												<tr>
751

    
752
EOF;
753
		// Mount point
754
		$custom_txt .=  "<td><input size='8' id='mountpoint1' name='mountpoint1' value='/'></td>";
755
		// File system type
756
		$custom_txt .=  "<td><select onChange='javascript:onfstypeChange()' id='fstype1' name='fstype1'>";
757
		$select_txt .=  "<option value='UFS'>UFS</option>";
758
		$select_txt .=  "<option value='UFS+S'>UFS + Softupdates</option>";
759
		$select_txt .=  "<option value='UFS.eli'>Encrypted UFS</option>";
760
		$select_txt .=  "<option value='UFS+S.eli'>Encrypted UFS + Softupdates</option>";
761
		$release = php_uname("r");
762
		$release = $release[0];
763
		if($release == "9") {
764
			$select_txt .=  "<option value='UFS+J'>UFS + Journaling</option>";
765
			$select_txt .=  "<option value='UFS+J.eli'>Encrypted UFS + Journaling</option>";
766
		}
767
		if(file_exists("/boot/gptzfsboot")) {
768
			$select_txt .= "<option value='ZFS'>ZFS</option>";
769
			$select_txt .= "<option value='ZFS.eli'>Encrypted ZFS</option>";
770
		}
771
		$select_txt .=  "<option value='SWAP'>SWAP</option>";
772
		$custom_txt .= "{$select_txt}</select>\n";
773
		$custom_txt .= "</td>";
774
		$custom_txt .= "<td><select id='disk1' name='disk1'>\n";
775
		foreach($disks as $disk) {
776
			$disksize = format_bytes($disk['size'] * 1048576);
777
			$custom_disks .= "<option value='{$disk['disk']}'>{$disk['disk']} - {$disksize} - {$disk['desc']}</option>";
778
		}
779
		$custom_txt .= "{$custom_disks}</select></td>\n";
780

    
781
		$custom_txt .= "<td><input name='size1' id='size1' size='8' type='text' value='200M'></td>";
782

    
783
		$custom_txt .= "<td>";
784
		$custom_txt .= "<input name='encpass1' size='8' id='encpass1'>";
785
		$custom_txt .= "</td>";
786

    
787
		$custom_txt .= "<td>";
788
		$custom_txt .= "<div id=\"addrowbutton\">";
789
		$custom_txt .= "<a onclick=\"javascript:addRowTo('maintable', 'formfldalias'); return false;\" href=\"#\">";
790
		$custom_txt .= "<img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" alt=\"\" title=\"add another entry\" /></a>";
791
		$custom_txt .= "</div>";
792
		$custom_txt .= "</td>";
793

    
794
		$custom_txt .= "</tr>";
795
		$custom_txt .= "<tfoot></tfoot></tbody></table>";
796
	}
797
	echo <<<EOF
798

    
799
												<tr>
800
													<td colspan='4'>
801
													<script type="text/javascript">
802
														\$('loadingdiv').style.visibility='hidden';
803
													</script>
804
													<div id='contentdiv' style="display:none;">
805
														<p/>
806
														{$custom_txt}<p/>
807
														<hr><p/>
808
														<input type="button" value="Cancel" onClick="javascript:document.location='/index.php';"> &nbsp;&nbsp
809
														<input type="submit" value="Next">
810
													</div>
811
													<script type="text/javascript">
812
														\$('contentdiv').appear();
813
														function onfstypeChange() {
814
															var fstype = \$F('fstype');
815
															if(fstype.substring(fstype.length - 4) == ".eli") {
816
																//\$('encpass').disabled = 0;
817
																alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!');
818
															} else { 
819
																//\$('encpass').disabled = 1;
820
															}
821
														}
822
														onfstypeChange();
823
													</script>
824
												</center>
825
												</td></tr>
826
												</table>
827
											</div>
828
			     						</td>
829
									</tr>
830
								</table>
831
							</div>
832
						</td>
833
					</tr>
834
				</table>
835
			</div>
836
			<script type="text/javascript">
837
			<!--
838
				newrow[1] = "{$select_txt}";
839
				newrow[2] = "{$custom_disks}";
840
			-->
841
			</script>
842
			
843

    
844
EOF;
845
	page_table_end();
846
	end_html();
847
}
848

    
849
function installer_main() {
850
	global $g, $fstype;
851
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
852
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
853
	head_html();
854
	body_html();
855
	$disk = installer_find_first_disk();
856
	// Only enable ZFS if this exists.  The install will fail otherwise.
857
	if(file_exists("/boot/gptzfsboot")) 
858
		$zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"index.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>";
859
	page_table_start();
860
	echo <<<EOF
861
		<form action="index.php" method="post" state="step1_post">
862
			<div id="mainlevel">
863
				<center>
864
				<b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/>
865
				<font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font>
866
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
867
			 		<tr>
868
			    		<td>
869
							<center>
870
							<div id="mainarea">
871
								<br/>
872
								<center>
873
								Please select an installer option to begin:
874
								<p/>
875
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
876
									<tr>
877
			     						<td>
878
											<div id="pfsenseinstaller">
879
												<center>
880
EOF;
881
	if(!$disk) {
882
		echo gettext("ERROR: Could not find any suitable disks for installation.");
883
		echo "</div></td></tr></table></div></table></div>";
884
		end_html();
885
		exit;
886
	}
887
	echo <<<EOF
888

    
889
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
890
														<tr bgcolor="#CECECE"><td align="center">
891
															<a href="index.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>
892
														</td></tr>
893
													 	{$zfs_enabled}
894
														<tr bgcolor="#AAAAAA"><td align="center">
895
															<a href="index.php?state=custominstall">Custom installation of {$g['product_name']}</a>
896
														</td></tr>
897
														<tr bgcolor="#CECECE"><td align="center">
898
															<a href='/'>Cancel and return to Dashboard</a>
899
														</td></tr>
900
													</table>
901
												</center>
902
											</div>
903
			     						</td>
904
									</tr>
905
								</table>
906
							</div>
907
						</td>
908
					</tr>
909
				</table>
910
			</div>
911
EOF;
912
	page_table_end();
913
	end_html();
914
}
915

    
916
?>
    (1-1/1)