Project

General

Profile

Download (22.9 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
require("globals.inc");
31
require("guiconfig.inc");
32

    
33
define('PC_SYSINSTALL', '/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh');
34

    
35
if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") {
36
	Header("Location: /index.php");
37
	exit;
38
}
39

    
40
// Main switch dispatcher
41
switch ($_REQUEST['state']) {
42
	case "update_installer_status":
43
		update_installer_status();
44
		exit;
45
	case "custominstall":
46
		installer_custom();
47
		exit;
48
	case "begin_install":
49
		installing_gui();
50
		begin_install();
51
		exit;
52
	case "verify_before_install":
53
		verify_before_install();
54
		exit;
55
	default:
56
		installer_main();	
57
}
58

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

    
73
installMode=fresh
74
installInteractive=yes
75
installType=FreeBSD
76
installMedium=LiveCD
77

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

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

    
90
# Do it now!
91
commitDiskLabel
92

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

    
96
packageType=cpdup
97

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

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

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

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

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

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

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

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

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

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

    
343
}
344

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

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

    
380
	if ($savemsg) print_info_box($savemsg); 
381
}
382

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

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

    
406

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

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

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

    
548
EOF;
549
	page_table_end();
550
	end_html();
551
}
552

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

    
571
EOF;
572

    
573
}
574

    
575
function page_table_end() {
576
	global $g, $fstype;
577
	echo <<<EOF
578
			</td>
579
		</tr>
580
		</table>
581
	</center>
582

    
583
EOF;
584
	
585
}
586

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

    
675
EOF;
676
	page_table_end();
677
	end_html();
678
}
679

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

    
720
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
721
														<tr bgcolor="#CECECE"><td align="center">
722
															<a href="installer.php?state=verify_before_install&disk={$disk}&fstype=UFS&swapsize=200M">Easy installation of {$g['product_name']} using the UFS filesystem on disk {$disk}</a>
723
														</td></tr>
724
													 	{$zfs_enabled}
725
														<tr bgcolor="#AAAAAA"><td align="center">
726
															<a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a>
727
														</td></tr>
728
														<tr bgcolor="#CECECE"><td align="center">
729
															<a href='/'>Cancel and return to Dashboard</a>
730
														</td></tr>
731
													</table>
732
												</center>
733
											</div>
734
			     						</td>
735
									</tr>
736
								</table>
737
							</div>
738
						</td>
739
					</tr>
740
				</table>
741
			</div>
742
EOF;
743
	page_table_end();
744
	end_html();
745
}
746

    
747
?>
(80-80/220)