Project

General

Profile

Download (23.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	installer.php
4
	part of pfSense (http://www.pfsense.com/)
5
	Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10

    
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13

    
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
$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($disk, $fstype = "UFS+S", $swapsize = false) {
62
	$fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w");
63
	if(!$fd) {
64
		return true;
65
	}
66
	if($swapsize <> "") {
67
		$diskareas =  "disk0-part=SWAP {$swapsize} none \n";
68
		$diskareas .= "disk0-part={$fstype} 0 /\n";
69
	} else {
70
		$diskareas = "disk0-part={$fstype} 0 /\n";
71
	}
72
	$config = <<<EOF
73
# Sample configuration file for an installation using pc-sysinstall
74

    
75
installMode=fresh
76
installInteractive=yes
77
installType=FreeBSD
78
installMedium=LiveCD
79

    
80
# Set the disk parameters
81
disk0={$disk}
82
partition=all
83
bootManager=bsd
84
commitDiskPart
85

    
86
# Setup the disk label
87
# All sizes are expressed in MB
88
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
89
# Size 0 means use the rest of the slice size
90
{$diskareas}
91

    
92
# Do it now!
93
commitDiskLabel
94

    
95
# Set if we are installing via optical, USB, or FTP
96
installType=FreeBSD
97

    
98
packageType=cpdup
99

    
100
# Optional Components
101
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,sys,usr,var
102

    
103
# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh
104
EOF;
105
	fwrite($fd, $config);
106
	fclose($fd);
107
	return;
108
}
109

    
110
function start_installation() {
111
	global $g, $fstype;
112
	if(file_exists("/tmp/install_complete"))
113
		return;
114
	$ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'");
115
	if($ps_running)	
116
		return;
117
	$fd = fopen("/tmp/installer.sh", "w");
118
	if(!$fd) {
119
		die(gettext("Could not open /tmp/installer.sh for writing"));
120
		exit;
121
	}
122
	fwrite($fd, "rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n");
123
	fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n");
124
	fwrite($fd, "chmod a+rx /usr/local/bin/after_installation_routines.sh\n");
125
	fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n");
126
	fwrite($fd, "mkdir /mnt/tmp\n");
127
//	fwrite($fd, "umount /mnt\n");
128
	fwrite($fd, "touch /tmp/install_complete\n");
129
	fclose($fd);
130
	exec("chmod a+rx /tmp/installer.sh");
131
	mwexec_bg("sh /tmp/installer.sh");
132
}
133

    
134
function installer_find_first_disk() {
135
	global $g, $fstype;
136
	$disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`;
137
	return $disk;
138
}
139

    
140
function pcsysinstall_get_disk_info($diskname) {
141
	global $g, $fstype;
142
	$disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
143
	$disks_array = array();
144
	foreach($disk as $d) {
145
		if(!$d) 
146
			continue;
147
		$disks_info = split(":", $d);
148
		$tmp_array = array();
149
		if($disks_info[0] == $diskname) {
150
			$disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
151
			foreach($disk_info as $di) { 
152
				$di_s = split("=", $di);
153
				if($di_s[0])
154
					$tmp_array[$di_s[0]] = $di_s[1];
155
			}
156
			$tmp_array['disk'] = trim($disks_info[0]);
157
			$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
158
			return $tmp_array;
159
		}
160
	}
161
}
162

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

    
186
function update_installer_status() {
187
	global $g, $fstype;
188
	// Ensure status files exist
189
	if(!file_exists("/tmp/installer_installer_running"))
190
		touch("/tmp/installer_installer_running");
191
	$status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`;
192
	$status = str_replace("\n", "\\n", $status);
193
	$status = str_replace("\n", "\\r", $status);
194
	echo "this.document.forms[0].installeroutput.value='$status';\n";
195
	echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n";	
196
	// Find out installer progress
197
	$progress = "5";
198
	if(strstr($status, "Running: dd")) 
199
		$progress = "6";
200
	if(strstr($status, "Running: gpart create -s GPT")) 
201
		$progress = "7";
202
	if(strstr($status, "Running: gpart bootcode")) 
203
		$progress = "7";
204
	if(strstr($status, "Running: newfs -U")) 
205
		$progress = "8";
206
	if(strstr($status, "Running: sync")) 
207
		$progress = "9";
208
	if(strstr($status, "/boot /mnt/boot")) 
209
		$progress = "10";
210
	if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT"))
211
		$progress = "11";
212
	if(strstr($status, "/bin /mnt/bin"))
213
		$progress = "12";
214
	if(strstr($status, "/conf /mnt/conf"))
215
		$progress = "15";
216
	if(strstr($status, "/conf.default /mnt/conf.default"))
217
		$progress = "20";
218
	if(strstr($status, "/dev /mnt/dev"))
219
		$progress = "25";
220
	if(strstr($status, "/etc /mnt/etc"))
221
		$progress = "30";
222
	if(strstr($status, "/home /mnt/home"))
223
		$progress = "35";
224
	if(strstr($status, "/kernels /mnt/kernels"))
225
		$progress = "40";
226
	if(strstr($status, "/libexec /mnt/libexec"))
227
		$progress = "50";
228
	if(strstr($status, "/lib /mnt/lib"))
229
		$progress = "60";
230
	if(strstr($status, "/root /mnt/root"))
231
		$progress = "70";
232
	if(strstr($status, "/sbin /mnt/sbin"))
233
		$progress = "75";
234
	if(strstr($status, "/sys /mnt/sys"))
235
		$progress = "80";
236
	if(strstr($status, "/usr /mnt/usr"))
237
		$progress = "95";
238
	if(strstr($status, "/usr /mnt/usr"))
239
		$progress = "90";
240
	if(strstr($status, "/var /mnt/var"))
241
		$progress = "95";
242
	if(strstr($status, "cap_mkdb /etc/login.conf"))
243
		$progress = "96";
244
	if(strstr($status, "Setting hostname"))
245
		$progress = "97";
246
	if(strstr($status, "umount -f /mnt"))
247
		$progress = "98";
248
	if(strstr($status, "umount -f /mnt"))
249
		$progress = "99";
250
	if(strstr($status, "Installation finished"))
251
		$progress = "100";
252
	// Check for error and bail if we see one.
253
	if(stristr($status, "error")) {
254
		$error = true;
255
		echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred.  Aborting installation.  <a href=\"installer.php\">Back</a> to webInstaller'; ";
256
		echo "\$('progressbar').style.width='100%';\n";
257
		unlink_if_exists("/tmp/install_complete");
258
		return;
259
	}
260
	$running_old = trim(file_get_contents("/tmp/installer_installer_running"));
261
	if($installer_running <> "running") {
262
		$ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'");
263
		if($ps_running)	{
264
			$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>'; ";
265
			if($running_old <> $running) {
266
				echo $running;
267
				file_put_contents("/tmp/installer_installer_running", "$running");			
268
			}
269
		}
270
	}
271
	if($progress) 
272
		echo "\$('progressbar').style.width='{$progress}%';\n";
273
	if(file_exists("/tmp/install_complete")) {
274
		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";
275
		echo "\$('pbdiv').Fade();\n";
276
		unlink_if_exists("/tmp/installer.sh");
277
		file_put_contents("/tmp/installer_installer_running", "finished");
278
	}
279
}
280

    
281
function update_installer_status_win($status) {
282
	global $g, $fstype;
283
	echo "<script type=\"text/javascript\">\n";
284
	echo "	\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
285
	echo "</script>";
286
}
287

    
288
function begin_install() {
289
	global $g;
290
	if(file_exists("/tmp/install_complete"))
291
		return;
292
	unlink_if_exists("/tmp/install_complete");
293
	if($_REQUEST['disk'])
294
		$disk = htmlspecialchars($_REQUEST['disk']);
295
	else 
296
		$disk = installer_find_first_disk();
297
	if(!$disk) {
298
		echo "<script type=\"text/javascript\">";
299
		echo "\$('pbdiv').Fade();\n";
300
		echo "</script>";
301
		$savemsg = gettext("Could not find a suitable disk for installation");
302
		update_installer_status_win(gettext("Could not find a suitable disk for installation."));
303
		return;
304
	}
305
	// Handle other type of file systems
306
	if($_REQUEST['fstype']) 
307
		$fstype = htmlspecialchars(strtoupper($_REQUEST['fstype']));
308
	else 
309
		$fstype = "UFS+S";
310
	write_out_pc_sysinstaller_config($disk, $fstype);
311
	update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk));
312
	start_installation();
313
}
314

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

    
345
}
346

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

    
379
	if($one_two)
380
		echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
381

    
382
	if ($savemsg) print_info_box($savemsg); 
383
}
384

    
385
function end_html() {
386
	global $g, $fstype;
387
	echo "</form>";
388
	echo "</body>";
389
	echo "</html>";
390
}
391

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

    
408

    
409
									</div>
410
	     						</td>
411
							</tr>
412
						</table>
413
					</div>
414
				</td>
415
			</tr>
416
		</table>
417
	</div>
418
EOF;
419
	end_html();
420
}
421

    
422
function verify_before_install() {
423
	global $g, $fstype;
424
	head_html();
425
	body_html();
426
	page_table_start();
427
	$disk = pcsysinstall_get_disk_info(htmlspecialchars($_REQUEST['disk']));
428
	$disksize = format_bytes($disk['size'] * 1048576);
429
	$swapsize = htmlspecialchars($_REQUEST['swapsize']);
430
	$fstype_echo = htmlspecialchars($_REQUEST['fstype']);
431
	$disk_echo = htmlspecialchars($_REQUEST['disk']);
432
	$swapsize_echo = htmlspecialchars($_REQUEST['swapsize']);
433
	echo <<<EOF
434
	<form method="post" action="installer.php">
435
	<input type="hidden" name="fstype" value="{$fstype_echo}">
436
	<input type="hidden" name="disk" value="{$disk_echo}">
437
	<input type="hidden" name="state" value="begin_install">
438
	<input type="hidden" name="swapsize" value="{$swapsize_echo}">
439
	<div id="mainlevel">
440
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
441
	 		<tr>
442
	    		<td>
443
					<div id="mainarea">
444
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
445
							<tr>
446
	     						<td >
447
									<div>
448
										<center>
449
											<div id="pfsensetemplate">
450
												<table bgcolor="FFFF00" width="400" height="30" cellpadding="2" style="border:1px dashed;">
451
													<tr valign="middle">
452
														<td>
453
															<center><b>Please verify that the following is correct:</b></center>
454
														</td>
455
													</tr>
456
												</table>
457
												<p/>
458
												<table>
459
													<tr><td align="right"><b>Disk:</td><td>{$disk_echo}</td></tr>
460
													<tr><td align="right"><b>Description:</td><td>{$disk['desc']}</td></tr>
461
													<tr><td align="right"><b>Size:</td><td>{$disksize}</td></tr>
462
													<tr><td align="right"><b>SWAP Size:</td><td>{$swapsize}</td></tr>
463
													<tr><td align="right"><b>Filesystem:</td><td>{$fstype_echo}</td></tr>
464
												</table>
465
											</div>
466
										</center>
467
									</div>
468
	     						</td>
469
							</tr>
470
						</table>
471
					</div>
472
					<center>
473
						<p/>
474
						<input type="button" value="Cancel" onClick="javascript:document.location='/installer.php';"> &nbsp;&nbsp;
475
						<input type="submit" value="Begin installation"> 
476
					</center>
477
				</td>
478
			</tr>
479
		</table>
480
	</div>
481
EOF;
482
	page_table_end();
483
	end_html();
484
}
485

    
486
function installing_gui() {
487
	global $g, $fstype;
488
	head_html();
489
	body_html();
490
	echo "<form action=\"installer.php\" method=\"post\" state=\"step1_post\">";
491
	page_table_start();
492
	echo <<<EOF
493
	<center>
494
		<table width="100%">
495
		<tr><td>
496
			<div id="mainlevel">
497
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
498
			 		<tr>
499
			    		<td>
500
							<div id="mainarea">
501
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
502
									<tr>
503
			     						<td>
504
											<div id="pfsenseinstaller" width="100%">
505
												<div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000">
506
													<table>
507
														<tr>
508
															<td valign="middle">
509
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
510
															</td>
511
															<td valign="middle">
512
																&nbsp;<font size="2"><b>Starting Installer...  Please wait...
513
															</td>
514
														</tr>
515
													</table>
516
												</div>
517
												<div id='pbdiv'>
518
													<br/>
519
													<center>
520
													<table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
521
														<tr>
522
															<td background="./themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
523
															</td>
524
															<td>
525
																<table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
526
																	<td background="./themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
527
																		<img src='./themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
528
																	</td>
529
																</table>
530
															</td>
531
															<td background="./themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
532
															</td>
533
														</tr>
534
													</table>
535
													<br/>
536
												</div>
537
												<textarea name='installeroutput' id='installeroutput' rows="31" cols="90">
538
												</textarea>
539
											</div>
540
			     						</td>
541
									</tr>
542
								</table>
543
							</div>
544
						</td>
545
					</tr>
546
				</table>
547
			</div>
548
		</td></tr>
549
		</table>
550
	</center>
551
	<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
552

    
553
EOF;
554
	page_table_end();
555
	end_html();
556
}
557

    
558
function page_table_start() {
559
	global $g, $fstype;
560
	echo <<<EOF
561
	<center>
562
		<img border="0" src="./themes/{$g['theme']}/images/logo.gif"></a><br/>
563
		<table cellpadding="6" cellspacing="0" width="550" height="380" style="border:1px solid #000000">
564
		<tr height="10" bgcolor="#990000">
565
			<td style="border-bottom:1px solid #000000">
566
				<font color='white'>
567
					<b>
568
						{$g['product_name']} installer
569
					</b>
570
				</font>
571
			</td>
572
		</tr>
573
		<tr>
574
			<td>
575

    
576
EOF;
577

    
578
}
579

    
580
function page_table_end() {
581
	global $g, $fstype;
582
	echo <<<EOF
583
			</td>
584
		</tr>
585
		</table>
586
	</center>
587

    
588
EOF;
589
	
590
}
591

    
592
function installer_custom() {
593
	global $g, $fstype;
594
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
595
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
596
	head_html();
597
	body_html();
598
	page_table_start();
599
	echo <<<EOF
600
		<form action="installer.php" method="post">
601
			<input type="hidden" name="state" value="verify_before_install">
602
			<div id="mainlevel">
603
				<center>
604
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
605
			 		<tr>
606
			    		<td>
607
							<center>
608
							<div id="mainarea">
609
								<br/>
610
								<center>
611
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
612
									<tr>
613
			     						<td>
614
											<div id="pfsenseinstaller">
615
												<center>
616
												<div id='loadingdiv'>
617
													<img src="/themes/{$g['theme']}/images/misc/loader.gif"> Probing disks, please wait...
618
												</div>
619
EOF;
620
	ob_flush();
621
	$disks = installer_find_all_disks();
622
	if(!$disks)  {
623
		$custom_txt = gettext("ERROR: Could not find any suitable disks for installation.");
624
	} else {
625
		// Prepare disk selection dropdown
626
		$custom_txt = <<<EOF
627
												<table bgcolor="FFFF00" width="400" height="30" cellpadding="2" style="border:1px dashed;">
628
													<tr valign="middle">
629
														<td>
630
															<center><b>Select the installation parameters for {$g['product_name']}:</b></center>
631
														</td>
632
													</tr>
633
												</table><p/>
634
												<table>
635
EOF;
636
		$custom_txt .= "<tr><td align='right'><b>Swap size</td><td><input name='swapsize' type='text' value='200M'></td></tr>\n";
637
		$custom_txt .= "<tr><td align='right'><b>Disk:</td><td><select name='disk'>\n";
638
		foreach($disks as $disk) {
639
			$disksize = format_bytes($disk['size'] * 1048576);
640
			$custom_txt .= "<option value='{$disk['disk']}'>{$disk['disk']} - {$disksize} - {$disk['desc']}</option>\n";
641
		}
642
		$custom_txt .= "</select></td></tr>\n";
643
		// XXX: Convert to rowhelper.  Add Ajax callbacks to verify sizes, etc.
644
		// Prepare disk types
645
		$custom_txt .=  "<tr><td align='right'><b>Filesystem type:</td><td><select name='fstype'>\n";
646
		$custom_txt .=  "<option value='UFS'>UFS</option>\n";
647
		$custom_txt .=  "<option value='UFS+S'>UFS + Softupdates</option>\n";
648
		$release = trim(`uname -r | cut -d'.' -f1`);
649
		if($release == "9")
650
			$custom_txt .=  "<option value='UFS+J'>UFS + Journaling</option>\n";
651
		if(file_exists("/boot/gptzfsboot")) 
652
			$custom_txt .= "<option value='ZFS'>ZFS</option>\n";
653
		$custom_txt .= "</select>\n</td></tr></table><p/>";
654
	}
655
	echo <<<EOF
656
													<script type="text/javascript">
657
														\$('loadingdiv').style.visibility='hidden';
658
													</script>
659
													<div id='contentdiv' style="display:none;">
660
														{$custom_txt}<p/>
661
														<input type="button" value="Cancel" onClick="javascript:document.location='/installer.php';"> &nbsp;&nbsp
662
														<input type="submit" value="Next">
663
													</div>
664
													<script type="text/javascript">
665
														\$('contentdiv').appear();
666
													</script>
667
												</center>
668
												</td></tr>
669
												</table>
670
											</div>
671
			     						</td>
672
									</tr>
673
								</table>
674
							</div>
675
						</td>
676
					</tr>
677
				</table>
678
			</div>
679

    
680
EOF;
681
	page_table_end();
682
	end_html();
683
}
684

    
685
function installer_main() {
686
	global $g, $fstype;
687
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
688
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
689
	head_html();
690
	body_html();
691
	$disk = installer_find_first_disk();
692
	// Only enable ZFS if this exists.  The install will fail otherwise.
693
	if(file_exists("/boot/gptzfsboot")) 
694
		$zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"installer.php?state=verify_before_install&fstype=ZFS&swapsize=200M\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>";
695
	page_table_start();
696
	echo <<<EOF
697
		<form action="installer.php" method="post" state="step1_post">
698
			<div id="mainlevel">
699
				<center>
700
				<b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/>
701
				<font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font>
702
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
703
			 		<tr>
704
			    		<td>
705
							<center>
706
							<div id="mainarea">
707
								<br/>
708
								<center>
709
								Please select an installer option to begin:
710
								<p/>
711
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
712
									<tr>
713
			     						<td>
714
											<div id="pfsenseinstaller">
715
												<center>
716
EOF;
717
	if(!$disk) {
718
		echo gettext("ERROR: Could not find any suitable disks for installation.");
719
		echo "</div></td></tr></table></div></table></div>";
720
		end_html();
721
		exit;
722
	}
723
	echo <<<EOF
724

    
725
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
726
														<tr bgcolor="#CECECE"><td align="center">
727
															<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>
728
														</td></tr>
729
													 	{$zfs_enabled}
730
														<tr bgcolor="#AAAAAA"><td align="center">
731
															<a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a>
732
														</td></tr>
733
														<tr bgcolor="#CECECE"><td align="center">
734
															<a href='/'>Cancel and return to Dashboard</a>
735
														</td></tr>
736
													</table>
737
												</center>
738
											</div>
739
			     						</td>
740
									</tr>
741
								</table>
742
							</div>
743
						</td>
744
					</tr>
745
				</table>
746
			</div>
747
EOF;
748
	page_table_end();
749
	end_html();
750
}
751

    
752
?>
(80-80/220)