Project

General

Profile

Download (38.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	installer.php (pfSense webInstaller)
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
	case "easy_install_ufs":
58
		easy_install("UFS+S");
59
		exit;
60
	case "easy_install_ufs":
61
		easy_install("ZFS");
62
		exit;
63

    
64
	default:
65
		installer_main();	
66
}
67

    
68
function easy_install($fstype = "UFS+S") {
69
	// Calculate swap and disk sizes
70
	$disks = installer_find_all_disks();
71
	$memory = get_memory();
72
	$swap_size = $memory[0] * 2;
73
	$first_disk = trim(installer_find_first_disk());
74
	$disk_info = pcsysinstall_get_disk_info($first_disk);
75
	$size = $disk_info['size'];
76
	$first_disk_size = $size - $swap_size;
77
	$disk_setup = array();
78
	$tmp_array = array();
79
	// Build the disk layout for /
80
	$tmp_array['disk'] = $first_disk;
81
	$tmp_array['size'] = $first_disk_size;
82
	$tmp_array['mountpoint'] = "/";
83
	$tmp_array['fstype'] = $fstype;
84
	$disk_setup[] = $tmp_array;
85
	unset($tmp_array);
86
	$tmp_array = array();
87
	// Build the disk layout for SWAP
88
	$tmp_array['disk'] = $first_disk;
89
	$tmp_array['size'] = $swap_size;
90
	$tmp_array['mountpoint'] = "none";
91
	$tmp_array['fstype'] = "SWAP";
92
	$disk_setup[] = $tmp_array;
93
	unset($tmp_array);
94
	$bootmanager = "bsd";
95
	file_put_contents("/tmp/webInstaller_disk_layout.txt", serialize($disk_setup));
96
	file_put_contents("/tmp/webInstaller_disk_bootmanager.txt", serialize($bootmanager));
97
	Header("Location: installer.php?state=verify_before_install");
98
	exit;
99
}
100

    
101
function write_out_pc_sysinstaller_config($disks, $bootmanager = "bsd") {
102
	$diskareas = "";
103
	$fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w");
104
	if(!$fd) 
105
		return true;
106
	if($bootmanager == "") 
107
	 	$bootmanager = "none";
108
	// Yes, -1.  We ++ early in loop.
109
	$numdisks = -1;
110
	$lastdisk = "";
111
	$diskdefs = "";
112
	// Run through the disks and create the conf areas for pc-sysinstaller
113
	foreach($disks as $disksa) {
114
		$fstype = $disksa['fstype'];
115
		$size = $disksa['size'];
116
		$mountpoint = $disksa['mountpoint'];
117
		$disk = $disksa['disk'];
118
		if($disk <> $lastdisk) {
119
			$lastdisk = $disk;
120
			$numdisks++;
121
			$diskdefs .= "# disk {$disk}\n";
122
			$diskdefs .= "disk{$numdisks}={$disk}\n";
123
			$diskdefs .= "partition=all\n";
124
			$diskdefs .= "bootManager={$bootmanager}\n";
125
			$diskdefs .= "commitDiskPart\n\n";
126
		}
127
		$diskareas .= "disk{$numdisks}-part={$fstype} {$size} {$mountpoint} \n";
128
		if($encpass)
129
			$diskareas .= "encpass={$encpass}\n";
130
	}
131
	
132
	$config = <<<EOF
133
# Sample configuration file for an installation using pc-sysinstall
134
# This file was automatically generated by installer.php
135
 
136
installMode=fresh
137
installInteractive=yes
138
installType=FreeBSD
139
installMedium=LiveCD
140

    
141
# Set the disk parameters
142
{$diskdefs}
143

    
144
# Setup the disk label
145
# All sizes are expressed in MB
146
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
147
# Size 0 means use the rest of the slice size
148
# Alternatively, you can append .eli to any of
149
# the above filesystem types to encrypt that disk.
150
# If you with to use a passphrase with this 
151
# encrypted partition, on the next line 
152
# the flag "encpass=" should be entered:
153
# encpass=mypass
154
# disk0-part=UFS 500 /boot
155
# disk0-part=UFS.eli 500 /
156
# disk0-part=UFS.eli 500 /usr
157
{$diskareas}
158

    
159
# Do it now!
160
commitDiskLabel
161

    
162
# Set if we are installing via optical, USB, or FTP
163
installType=FreeBSD
164

    
165
packageType=cpdup
166

    
167
# Optional Components
168
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,usr,var
169

    
170
# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh
171
EOF;
172
	fwrite($fd, $config);
173
	fclose($fd);
174
	return;
175
}
176

    
177
function start_installation() {
178
	global $g, $fstype, $savemsg;
179
	if(file_exists("/tmp/install_complete"))
180
		return;
181
	$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
182
	if($ps_running)	
183
		return;
184
	$fd = fopen("/tmp/installer.sh", "w");
185
	if(!$fd) {
186
		die(gettext("Could not open /tmp/installer.sh for writing"));
187
		exit;
188
	}
189
	fwrite($fd, "/bin/rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n");
190
	fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n");
191
	fwrite($fd, "/bin/chmod a+rx /usr/local/bin/after_installation_routines.sh\n");
192
	fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n");
193
	fwrite($fd, "/bin/mkdir /mnt/tmp\n");
194
	fwrite($fd, "/usr/bin/touch /tmp/install_complete\n");
195
	fclose($fd);
196
	exec("/bin/chmod a+rx /tmp/installer.sh");
197
	mwexec_bg("/bin/sh /tmp/installer.sh");
198
}
199

    
200
function installer_find_first_disk() {
201
	global $g, $fstype, $savemsg;
202
	$disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`;
203
	return trim($disk);
204
}
205

    
206
function pcsysinstall_get_disk_info($diskname) {
207
	global $g, $fstype, $savemsg;
208
	$disk = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
209
	$disks_array = array();
210
	foreach($disk as $d) {
211
		$disks_info = explode(":", $d);
212
		$tmp_array = array();
213
		if($disks_info[0] == $diskname) {
214
			$disk_info = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
215
			$disk_info_split = explode("=", $disk_info);
216
			foreach($disk_info as $di) { 
217
				$di_s = explode("=", $di);
218
				if($di_s[0])
219
					$tmp_array[$di_s[0]] = $di_s[1];
220
			}
221
			$tmp_array['size']--;
222
			$tmp_array['disk'] = trim($disks_info[0]);
223
			$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
224
			return $tmp_array;
225
		}
226
	}
227
}
228

    
229
// Return an array with all disks information.
230
function installer_find_all_disks() {
231
	global $g, $fstype, $savemsg;
232
	$disk = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`);
233
	$disks_array = array();
234
	foreach($disk as $d) {
235
		if(!$d) 
236
			continue;
237
		$disks_info = explode(":", $d);
238
		$tmp_array = array();
239
		$disk_info = explode("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`);
240
		foreach($disk_info as $di) { 
241
			$di_s = explode("=", $di);
242
			if($di_s[0])
243
				$tmp_array[$di_s[0]] = $di_s[1];
244
		}
245
		$tmp_array['size']--;
246
		$tmp_array['disk'] = trim($disks_info[0]);
247
		$tmp_array['desc'] = trim(htmlentities($disks_info[1]));
248
		$disks_array[] = $tmp_array;
249
	}
250
	return $disks_array;
251
}
252

    
253
function update_installer_status() {
254
	global $g, $fstype, $savemsg;
255
	// Ensure status files exist
256
	if(!file_exists("/tmp/installer_installer_running"))
257
		touch("/tmp/installer_installer_running");
258
	$status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`;
259
	$status = str_replace("\n", "\\n", $status);
260
	$status = str_replace("\n", "\\r", $status);
261
	$status = str_replace("'", "\\'", $status);
262
	echo "document.forms[0].installeroutput.value='$status';\n";
263
	echo "document.forms[0].installeroutput.scrollTop = document.forms[0].installeroutput.scrollHeight;\n";	
264
	// Find out installer progress
265
	$progress = "5";
266
	if(strstr($status, "Running: dd")) 
267
		$progress = "6";
268
	if(strstr($status, "Running: gpart create -s GPT")) 
269
		$progress = "7";
270
	if(strstr($status, "Running: gpart bootcode")) 
271
		$progress = "7";
272
	if(strstr($status, "Running: newfs -U")) 
273
		$progress = "8";
274
	if(strstr($status, "Running: sync")) 
275
		$progress = "9";
276
	if(strstr($status, "/boot /mnt/boot")) 
277
		$progress = "10";
278
	if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT"))
279
		$progress = "11";
280
	if(strstr($status, "/bin /mnt/bin"))
281
		$progress = "12";
282
	if(strstr($status, "/conf /mnt/conf"))
283
		$progress = "15";
284
	if(strstr($status, "/conf.default /mnt/conf.default"))
285
		$progress = "20";
286
	if(strstr($status, "/dev /mnt/dev"))
287
		$progress = "25";
288
	if(strstr($status, "/etc /mnt/etc"))
289
		$progress = "30";
290
	if(strstr($status, "/home /mnt/home"))
291
		$progress = "35";
292
	if(strstr($status, "/kernels /mnt/kernels"))
293
		$progress = "40";
294
	if(strstr($status, "/libexec /mnt/libexec"))
295
		$progress = "50";
296
	if(strstr($status, "/lib /mnt/lib"))
297
		$progress = "60";
298
	if(strstr($status, "/root /mnt/root"))
299
		$progress = "70";
300
	if(strstr($status, "/sbin /mnt/sbin"))
301
		$progress = "75";
302
	if(strstr($status, "/sys /mnt/sys"))
303
		$progress = "80";
304
	if(strstr($status, "/usr /mnt/usr"))
305
		$progress = "95";
306
	if(strstr($status, "/usr /mnt/usr"))
307
		$progress = "90";
308
	if(strstr($status, "/var /mnt/var"))
309
		$progress = "95";
310
	if(strstr($status, "cap_mkdb /etc/login.conf"))
311
		$progress = "96";
312
	if(strstr($status, "Setting hostname"))
313
		$progress = "97";
314
	if(strstr($status, "umount -f /mnt"))
315
		$progress = "98";
316
	if(strstr($status, "umount -f /mnt"))
317
		$progress = "99";
318
	if(strstr($status, "Installation finished"))
319
		$progress = "100";
320
	// Check for error and bail if we see one.
321
	if(stristr($status, "error")) {
322
		$error = true;
323
		echo "\$('#installerrunning').html('<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred.  Aborting installation.  <a href=\"/installer\">Back</a> to webInstaller'); ";
324
		echo "\$('#progressbar').css('width','100%');\n";
325
		unlink_if_exists("/tmp/install_complete");
326
		return;
327
	}
328
	$running_old = trim(file_get_contents("/tmp/installer_installer_running"));
329
	if($installer_running <> "running") {
330
		$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
331
		if($ps_running)	{
332
			$running = "\$('#installerrunning').html('<table><tr><td valign=\"middle\"><img src=\"/themes/{$g['theme']}/images/misc/loader.gif\"></td><td valign=\"middle\">&nbsp;<font size=\"2\"><b>Installer running ({$progress}% completed)...</td></tr></table>'); ";
333
			if($running_old <> $running) {
334
				echo $running;
335
				file_put_contents("/tmp/installer_installer_running", "$running");			
336
			}
337
		}
338
	}
339
	if($progress) 
340
		echo "\$('#progressbar').css('width','{$progress}%');\n";
341
	if(file_exists("/tmp/install_complete")) {
342
		echo "\$('#installerrunning').html('<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"+1\">Installation completed.  Please <a href=\"/reboot.php\">reboot</a> to continue');\n";
343
		echo "\$('#pbdiv').fadeOut();\n";
344
		unlink_if_exists("/tmp/installer.sh");
345
		file_put_contents("/tmp/installer_installer_running", "finished");
346
	}
347
}
348

    
349
function update_installer_status_win($status) {
350
	global $g, $fstype, $savemsg;
351
	echo "<script type=\"text/javascript\">\n";
352
	echo "	\$('#installeroutput').val('" . str_replace(htmlentities($status), "\n", "") . "');\n";
353
	echo "</script>\n";
354
}
355

    
356
function begin_install() {
357
	global $g, $savemsg;
358
	if(file_exists("/tmp/install_complete"))
359
		return;
360
	unlink_if_exists("/tmp/install_complete");
361
	update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk));
362
	start_installation();
363
}
364

    
365
function head_html() {
366
	global $g, $fstype, $savemsg;
367
	echo <<<EOF
368
<html>
369
	<head>
370
		<style type='text/css'>
371
			hr {
372
				border: 0;
373
				color: #000000;
374
				background-color: #000000;
375
				height: 1px;
376
				width: 100%;
377
				text-align: left;
378
			}
379
			a:link { 
380
				color: #000000;
381
				text-decoration:underline;
382
				font-size:14;
383
			}
384
			a:visited { 
385
				color: #000000;
386
				text-decoration:underline;
387
				font-size:14;
388
			}
389
			a:hover { 
390
				color: #FFFF00;
391
				text-decoration: none;
392
				font-size:14;
393
			}
394
			a:active { 
395
				color: #FFFF00;
396
				text-decoration:underline;
397
				font-size:14;
398
			}
399
		</style>
400
	</head>
401
EOF;
402

    
403
}
404

    
405
function body_html() {
406
	global $g, $fstype, $savemsg;
407
	$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
408
	if(strstr($pfSversion, "1.2")) 
409
		$one_two = true;
410
	$pgtitle = array("{$g['product_name']}", gettext("Installer"));
411
	include("head.inc");
412
	echo <<<EOF
413
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
414
	<script type="text/javascript" src="/javascript/jquery.js"></script>
415
	<script type="text/javascript" src="/javascript/jquery/jquery-ui.custom.min.js"></script>
416
	<script type="text/javascript">
417
		function getinstallerprogress() {
418
			url = '/installer/installer.php';
419
			pars = 'state=update_installer_status';
420
			callajax(url, pars, installcallback);
421
		}
422
		function callajax(url, pars, activitycallback) {
423
			jQuery.ajax(
424
				url,
425
				{
426
					type: 'post',
427
					data: pars,
428
					complete: activitycallback
429
				});
430
		}
431
		function installcallback(transport) {
432
			setTimeout('getinstallerprogress()', 2000);
433
			eval(transport.responseText);
434
		}
435
	</script>
436
EOF;
437

    
438
	if($one_two)
439
		echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
440

    
441
	if ($savemsg) print_info_box($savemsg); 
442
}
443

    
444
function end_html() {
445
	global $g, $fstype, $savemsg;
446
	echo "</form>";
447
	echo "</body>";
448
	echo "</html>";
449
}
450

    
451
function template() {
452
	global $g, $fstype, $savemsg;
453
	head_html();
454
	body_html();
455
	echo <<<EOF
456
	<div id="mainlevel">
457
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
458
	 		<tr>
459
	    		<td>
460
					<div id="mainarea">
461
						<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
462
							<tr>
463
	     						<td class="tabcont" >
464
	      							<form action="installer.php" method="post">
465
									<div id="pfsensetemplate">
466

    
467

    
468
									</div>
469
	     						</td>
470
							</tr>
471
						</table>
472
					</div>
473
				</td>
474
			</tr>
475
		</table>
476
	</div>
477
EOF;
478
	end_html();
479
}
480

    
481
function verify_before_install() {
482
	global $g, $fstype, $savemsg;
483
	$encrypted_root = false;
484
	$non_encrypted_boot = false;
485
	$non_encrypted_notice = false;
486
	head_html();
487
	body_html();
488
	page_table_start($g['product_name'] . " installer - Verify final installation settings");
489
	// If we are visiting this step from anything but the row editor / custom install
490
	// then load the on disk layout contents if they are available.
491
	if(!$_REQUEST['fstype0'] && file_exists("/tmp/webInstaller_disk_layout.txt")) {
492
		$disks = unserialize(file_get_contents("/tmp/webInstaller_disk_layout.txt"));
493
		$bootmanager = unserialize(file_get_contents("/tmp/webInstaller_disk_bootmanager.txt"));
494
		$restored_layout_from_file = true;
495
		$restored_layout_txt = "The previous disk layout was restored from disk";
496
	} else {
497
		$disks = array();
498
	}
499
	if(!$bootmanager) 
500
		$bootmanager = $_REQUEST['bootmanager'];
501
	echo "\n<!--" . print_r($_REQUEST, true) . " -->\n";
502
	$disk = pcsysinstall_get_disk_info(htmlspecialchars($_REQUEST['disk']));
503
	$disksize = format_bytes($disk['size'] * 1048576);
504
	// Loop through posted items and create an array
505
	for($x=0; $x<99; $x++) { // XXX: Make this more optimal
506
		if(!$_REQUEST['fstype' . $x])
507
			continue;
508
		$tmparray = array();
509
		if($_REQUEST['fstype' . $x] <> "SWAP") {
510
			$tmparray['mountpoint'] = $_REQUEST['mountpoint' . $x];
511
			// Check for encrypted slice /
512
			if(stristr($_REQUEST['fstype' . $x], ".eli")) {
513
				if($tmparray['mountpoint'] == "/") 
514
					$encrypted_root = true;
515
			}
516
			// Check if we have a non-encrypted /boot
517
			if($tmparray['mountpoint'] == "/boot") 	{
518
				if(!stristr($_REQUEST['fstype' . $x], ".eli"))
519
					$non_encrypted_boot = true;
520
			}
521
			if($tmparray['mountpoint'] == "/conf") {	
522
				$tmparray['mountpoint'] = "/conf{$x}";
523
				$error_txt[] = "/conf is not an allowed mount point and has been renamed to /conf{$x}.";
524
			}
525
		} else  {
526
			$tmparray['mountpoint'] = "none";
527
		}
528
		// If we have an encrypted /root and lack a non encrypted /boot, throw an error/warning
529
		if($encrypted_root && !$non_encrypted_boot && !$non_encrypted_notice) {
530
			$error_txt[] = "A non-encrypted /boot slice is required when encrypting the / slice";
531
			$non_encrypted_notice = true;
532
		}
533
		$tmparray['disk'] = $_REQUEST['disk' . $x];
534
		$tmparray['fstype'] = $_REQUEST['fstype' . $x];
535
		$tmparray['size'] = $_REQUEST['size' . $x];
536
		$tmparray['encpass'] = $_REQUEST['encpass' . $x];
537
		$disks[] = $tmparray;
538
	}
539
	echo "\n<!-- " . print_r($disks, true) . " --> \n";
540
	$bootmanagerupper = strtoupper($bootmanager);
541
	echo <<<EOFAMBAC
542
	<form method="post" action="installer.php">
543
	<input type="hidden" name="fstype" value="{$fstype_echo}">
544
	<input type="hidden" name="disk" value="{$disk_echo}">
545
	<input type="hidden" name="state" value="begin_install">
546
	<input type="hidden" name="swapsize" value="{$swapsize}">
547
	<input type="hidden" name="encpass" value="{$encpass}">
548
	<input type="hidden" name="bootmanager" value="{$bootmanager}">
549
	<div id="mainlevel">
550
		<table width="800" border="0" cellpadding="0" cellspacing="0">
551
	 		<tr>
552
	    		<td>
553
					<div id="mainarea">
554
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
555
							<tr>
556
	     						<td >
557
									<div>
558
										<center>
559
											<div id="pfsensetemplate">
560
												<table width='100%'>
561
EOFAMBAC;
562
												// If errors are found, throw the big red box.
563
												if ($error_txt) {
564
													echo "<tr><td colspan=\"5\">&nbsp;</td>";
565
													echo "<tr><td colspan=\"5\">";
566
													print_input_errors($error_txt);
567
													echo "</td></tr>";
568
												} else 
569
													echo "<tr><td>&nbsp;</td></tr>";
570

    
571
	echo <<<EOFAMBACBAF
572

    
573
												<tr><td colspan='5' align="center"><b>Boot manager: {$bootmanagerupper}</td></tr>
574
												<tr><td>&nbsp;</td></tr>
575
												<tr>
576
													<td align='left'>
577
														<b>Mount point</b>
578
													</td>
579
													<td align='left'>
580
														<b>Filesysytem type</b>
581
													</td>
582
													<td align='left'>
583
														<b>Disk</b>
584
													</td>
585
													<td align='left'>
586
														<b>Size</b>
587
													</td>
588
													<td align='left'>
589
														<b>Encryption password</b>
590
													</td>
591
												</tr>
592
												<tr><td colspan='5'><hr></td></tr>
593

    
594
EOFAMBACBAF;
595

    
596
													foreach($disks as $disk) {
597
														$desc = pcsysinstall_get_disk_info($disk['disk']);
598
														echo "<tr>";
599
														echo "<td>&nbsp;&nbsp;&nbsp;{$disk['mountpoint']}</td>";
600
														echo "<td>{$disk['fstype']}</td>";
601
														echo "<td>{$disk['disk']} {$desc['desc']}</td>";
602
														echo "<td>{$disk['size']}</td>";
603
														echo "<td>{$disk['encpass']}</td>";
604
														echo "</tr>";
605
													}
606

    
607
echo <<<EOFAMB
608
												<tr><td colspan="5"><hr></td></tr>
609
												</table>
610
											</div>
611
										</center>
612
									</div>
613
	     						</td>
614
							</tr>
615
						</table>
616
					</div>
617
					<center>
618
						<p/>
619
						<input type="button" value="Cancel" onClick="javascript:document.location='installer.php?state=custominstall';"> &nbsp;&nbsp;
620
EOFAMB;
621
						if(!$error_txt) 
622
						echo "<input type=\"submit\" value=\"Begin installation\"> <br/>&nbsp;";
623
echo <<<EOFAMBASDF
624

    
625
					</center>
626
				</td>
627
			</tr>
628
		</table>
629
	</div>
630
EOFAMBASDF;
631

    
632

    
633
	page_table_end();
634
	end_html();
635
	write_out_pc_sysinstaller_config($disks, $bootmanager);
636
	// Serialize layout to disk so it can be read in later.
637
	file_put_contents("/tmp/webInstaller_disk_layout.txt", serialize($disks));
638
	file_put_contents("/tmp/webInstaller_disk_bootmanager.txt", serialize($bootmanager));
639
}
640

    
641
function installing_gui() {
642
	global $g, $fstype, $savemsg;
643
	head_html();
644
	body_html();
645
	echo "<form action=\"installer.php\" method=\"post\" state=\"step1_post\">";
646
	page_table_start();
647
	echo <<<EOF
648
	<center>
649
		<table width="100%">
650
		<tr><td>
651
			<div id="mainlevel">
652
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
653
			 		<tr>
654
			    		<td>
655
							<div id="mainarea">
656
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
657
									<tr>
658
			     						<td>
659
											<div id="pfsenseinstaller" width="100%">
660
												<div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000">
661
													<table>
662
														<tr>
663
															<td valign="middle">
664
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
665
															</td>
666
															<td valign="middle">
667
																&nbsp;<font size="2"><b>Starting Installer...  Please wait...
668
															</td>
669
														</tr>
670
													</table>
671
												</div>
672
												<div id='pbdiv'>
673
													<br/>
674
													<center>
675
													<table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
676
														<tr>
677
															<td background="/themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
678
															</td>
679
															<td>
680
																<table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
681
																	<td background="/themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
682
																		<img src='/themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
683
																	</td>
684
																</table>
685
															</td>
686
															<td background="/themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
687
															</td>
688
														</tr>
689
													</table>
690
													<br/>
691
												</div>
692
												<textarea name='installeroutput' id='installeroutput' rows="31" cols="90">
693
												</textarea>
694
											</div>
695
			     						</td>
696
									</tr>
697
								</table>
698
							</div>
699
						</td>
700
					</tr>
701
				</table>
702
			</div>
703
		</td></tr>
704
		</table>
705
	</center>
706
	<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
707

    
708
EOF;
709
	page_table_end();
710
	end_html();
711
}
712

    
713
function page_table_start($pgtitle = "") {
714
	global $g, $fstype, $savemsg;
715
	if($pgtitle == "") 
716
		$pgtitle = "{$g['product_name']} installer";
717
	echo <<<EOF
718
	<center>
719
		<img border="0" src="/themes/{$g['theme']}/images/logo.gif"></a><br/>
720
		<table cellpadding="6" cellspacing="0" width="550" style="border:1px solid #000000">
721
		<tr height="10" bgcolor="#990000">
722
			<td style="border-bottom:1px solid #000000">
723
				<font color='white'>
724
					<b>
725
						{$pgtitle}
726
					</b>
727
				</font>
728
			</td>
729
		</tr>
730
		<tr>
731
			<td>
732

    
733
EOF;
734

    
735
}
736

    
737
function page_table_end() {
738
	global $g, $fstype, $savemsg;
739
	echo <<<EOF
740
			</td>
741
		</tr>
742
		</table>
743
	</center>
744

    
745
EOF;
746
	
747
}
748

    
749
function installer_custom() {
750
	global $g, $fstype, $savemsg;
751
	global $select_txt, $custom_disks;
752
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
753
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
754
	$disks = installer_find_all_disks();
755
	// Pass size of disks down to javascript.
756
	$disk_sizes_js_txt = "var disk_sizes = new Array();\n";
757
	foreach($disks as $disk) 
758
		$disk_sizes_js_txt .= "disk_sizes['{$disk['disk']}'] = '{$disk['size']}';\n";
759
	head_html();
760
	body_html();
761
	page_table_start($g['product_name'] . " installer - Customize disk(s) layout");
762
	echo <<<EOF
763
		<script type="text/javascript">
764
			Array.prototype.in_array = function(p_val) {
765
				for(var i = 0, l = this.length; i < l; i++) {
766
					if(this[i] == p_val) {
767
						return true;
768
					}
769
				}
770
				return false;
771
			}
772
			function row_helper_dynamic_custom() {
773
				var totalsize = 0;
774
				{$disk_sizes_js_txt}
775
				// Run through all rows and process data
776
				for(var x = 0; x<99; x++) { //optimize me better
777
					if(\$('#fstype' + x).length) {
778
						if(\$('#size' + x).val() == '')
779
							\$('#size' + x).val(disk_sizes[\$('disk' + x).value]);
780
						var fstype = \$('#fstype' + x).val();
781
						if(fstype.substring(fstype.length - 4) == ".eli") {
782
							\$('#encpass' + x).prop('disabled',false);
783
							if(!encryption_warning_shown) {
784
								alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!');
785
								encryption_warning_shown = true;
786
							}
787
						} else { 
788
							\$('#encpass' + x).prop('disabled',true);
789
						}
790
					}
791
					// Calculate size allocations
792
					if(\$('#size' + x).length) {
793
						if(parseInt($('#size' + x).val()) > 0)
794
							totalsize += parseInt($('#size' + x).val());
795
					}
796
				}
797
				// If the totalsize element exists, set it and disable
798
				if(\$('#totalsize').length) {
799
					if(\$('#totalsize').val() != totalsize) {
800
						// When size allocation changes, draw attention.
801
 						jQuery('#totalsize').effect('highlight');
802
						\$('#totalsize').val(totalsize);
803
					}
804
					\$('#totalsize').prop('disabled',true);
805
				}
806
				if(\$('#disktotals').length) {
807
					var disks_seen = new Array();
808
					var tmp_sizedisks = 0;
809
					var disksseen = 0;
810
					for(var xx = 0; xx<99; xx++) {
811
						if(\$('#disk' + xx).length) {
812
							if(!disks_seen.in_array(\$('#disk' + xx).val())) {
813
								tmp_sizedisks += parseInt(disk_sizes[\$('#disk' + xx).val()]);
814
								disks_seen[disksseen] = \$('#disk' + xx).val();
815
								disksseen++;
816
							}
817
						}
818
					\$('#disktotals').val(tmp_sizedisks);
819
					\$('#disktotals').prop('disabled',true);
820
					\$('#disktotals').css('color','#000000');
821
					var remaining = parseInt(\$('#disktotals').val()) - parseInt(\$('#totalsize').val());
822
						if(remaining == 0) {
823
							if(\$('#totalsize').length)
824
								\$('#totalsize').css({
825
									'background':'#00FF00',
826
									'color':'#000000'
827
								});
828
						} else {
829
							if(\$('#totalsize').length)
830
								\$('#totalsize').css({
831
									'background':'#FFFFFF',
832
									'color':'#000000'
833
								});
834
						}
835
						if(parseInt(\$('#totalsize').val()) > parseInt(\$('#disktotals').val())) {
836
							if(\$('#totalsize'))
837
								\$('#totalsize').css({
838
									'background':'#FF0000',
839
									'color':'#000000'
840
								});							
841
						}
842
						if(\$('#availalloc').length) {
843
							\$('#availalloc').prop('disabled',true);
844
							\$('#availalloc').val(remaining);
845
								\$('#availalloc').css({
846
									'background':'#FFFFFF',
847
									'color':'#000000'
848
								});							
849
						}
850
					}
851
				}
852
			}
853
		</script>
854
		<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
855
		<script type="text/javascript">
856
			// Setup rowhelper data types
857
			rowname[0] = "mountpoint";
858
			rowtype[0] = "textbox";
859
			rowsize[0] = "8";
860
			rowname[1] = "fstype";
861
			rowtype[1] = "select";
862
			rowsize[1] = "1";
863
			rowname[2] = "disk";
864
			rowtype[2] = "select";
865
			rowsize[2] = "1";
866
			rowname[3] = "size";
867
			rowtype[3] = "textbox";
868
			rowsize[3] = "8";
869
			rowname[4] = "encpass";
870
			rowtype[4] = "textbox";
871
			rowsize[4] = "8";
872
			field_counter_js = 5;
873
			rows = 1;
874
			totalrows = 1;
875
			loaded = 1;
876
			rowhelper_onChange = 	" onChange='javascript:row_helper_dynamic_custom()' ";
877
			rowhelper_onDelete = 	"row_helper_dynamic_custom(); ";
878
			rowhelper_onAdd = 		"row_helper_dynamic_custom();";
879
		</script>
880
		<form action="installer.php" method="post">
881
			<input type="hidden" name="state" value="verify_before_install">
882
			<div id="mainlevel">
883
				<center>
884
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
885
			 		<tr>
886
			    		<td>
887
							<center>
888
							<div id="mainarea">
889
								<center>
890
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
891
									<tr>
892
			     						<td>
893
											<div id="pfsenseinstaller">
894
												<center>
895
												<div id='loadingdiv'>
896
													<table>
897
														<tr>
898
															<td valign="center">
899
																<img src="/themes/{$g['theme']}/images/misc/loader.gif">
900
															</td>
901
															<td valign="center">
902
														 		&nbsp;Probing disks, please wait...
903
															</td>
904
														</tr>
905
													</table>
906
												</div>
907
EOF;
908
	ob_flush();
909
	// Read bootmanager setting from disk if found
910
	if(file_exists("/tmp/webInstaller_disk_bootmanager.txt"))
911
		$bootmanager = unserialize(file_get_contents("/tmp/webInstaller_disk_bootmanager.txt"));
912
	if($bootmanager == "none") 
913
		$noneselected = " SELECTED";
914
	if($bootmanager == "bsd") 
915
		$bsdeselected = " SELECTED";
916
	if(!$disks)  {
917
		$custom_txt = gettext("ERROR: Could not find any suitable disks for installation.");
918
	} else {
919
		// Prepare disk selection dropdown
920
		$custom_txt = <<<EOF
921
												<center>
922
												<table>
923
												<tr>
924
													<td align='right'>
925
														Boot manager:
926
													</td>
927
													<td>
928
														<select name='bootmanager'>
929
															<option value='none' $noneselected>
930
																None
931
															</option>
932
															<option value='bsd' $bsdeselected>
933
																BSD
934
															</option>
935
														</select>
936
													</td>
937
												</tr>
938
												</table>
939
												<hr>
940
												<table id='maintable'><tbody>
941
												<tr>
942
													<td align="middle">
943
														<b>Mount</b>
944
													</td>
945
													<td align='middle'>
946
														<b>Filesysytem</b>
947
													</td>
948
													<td align="middle">
949
														<b>Disk</b>
950
													</td>
951
													<td align="middle">
952
														<b>Size</b>
953
													</td>
954
													<td align="middle">
955
														<b>Encryption password</b>
956
													</td>
957
													<td>
958
														&nbsp;
959
													</td>
960
												</tr>
961
												<tr>
962

    
963
EOF;
964

    
965
		// Calculate swap disk sizes
966
		$memory = get_memory();
967
		$swap_size = $memory[0] * 2;
968
		$first_disk = trim(installer_find_first_disk());
969
		$disk_info = pcsysinstall_get_disk_info($first_disk);
970
		$size = $disk_info['size'];
971
		$first_disk_size = $size - $swap_size;
972

    
973
		// Debugging
974
		echo "\n\n<!-- $first_disk - " . print_r($disk_info, true) . " - $size  - $first_disk_size -->\n\n";
975

    
976
		// Check to see if a on disk layout exists
977
		if(file_exists("/tmp/webInstaller_disk_layout.txt")) {
978
			$disks_restored = unserialize(file_get_contents("/tmp/webInstaller_disk_layout.txt"));
979
			$restored_layout_from_file = true;
980
			$restored_layout_txt = "<br/>* The previous disk layout was restored from a previous session";
981
		}
982

    
983
		// If we restored disk layout(s) from a file then build the rows
984
		if($restored_layout_from_file == true) {
985
			$diskcounter = 0;
986
			foreach($disks_restored as $dr) {
987
				$custom_txt .= return_rowhelper_row("$diskcounter", $dr['mountpoint'], $dr['fstype'], $dr['disk'], $dr['size'], $dr['encpass']);
988
				$diskcounter++;
989
			}
990
		} else {		
991
			// Construct the default rows that outline the disks configuration.
992
			$custom_txt .= return_rowhelper_row("0", "/", "UFS+S", $first_disk, "{$first_disk_size}", "");
993
			$custom_txt .= return_rowhelper_row("1", "none", "SWAP", $first_disk, "$swap_size", "");
994
		}
995

    
996
		// tfoot and tbody are used by rowhelper
997
		$custom_txt .= "</tr>";
998
		$custom_txt .= "<tfoot></tfoot></tbody>";
999
		// Total allocation box
1000
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Total allocated:</td><td><input style='border:0px; background-color: #FFFFFF;' size='8' id='totalsize' name='totalsize'></td>";
1001
		// Add row button
1002
		$custom_txt .= "</td><td>&nbsp;</td><td>";
1003
		$custom_txt .= "<div id=\"addrowbutton\">";
1004
		$custom_txt .= "<a onclick=\"javascript:addRowTo('maintable', 'formfldalias'); return false;\" href=\"#\">";
1005
		$custom_txt .= "<img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" alt=\"\" title=\"add another entry\" /></a>";
1006
		$custom_txt .= "</div>";
1007
		$custom_txt .= "</td></tr>";	
1008
		// Disk capacity box
1009
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Disk(s) capacity total:</td><td><input style='border:0px; background-color: #FFFFFF;' size='8' id='disktotals' name='disktotals'></td></tr>";
1010
		// Remaining allocation box
1011
		$custom_txt .= "<tr><td></td><td></td><td align='right'>Available space for allocation:</td><td><input style='border:0px; background-color: #FFFFFF;' size='8' id='availalloc' name='availalloc'></td></tr>";
1012
		$custom_txt .= "</table>";
1013
		$custom_txt .= "<script type=\"text/javascript\">row_helper_dynamic_custom();</script>";
1014
	}
1015
	echo <<<EOF
1016

    
1017
												<tr>
1018
													<td colspan='4'>
1019
													<script type="text/javascript">
1020
														\$('#loadingdiv').css('visibility','hidden');
1021
													</script>
1022
													<div id='contentdiv' style="display:none;">
1023
														<p/>
1024
														{$custom_txt}<p/>
1025
														<hr><p/>
1026
														<input type="button" value="Cancel" onClick="javascript:document.location='/installer/installer.php';"> &nbsp;&nbsp
1027
														<input type="submit" value="Next">
1028
													</div>
1029
													<script type="text/javascript">
1030
														var encryption_warning_shown = false;
1031
														\$('#contentdiv').fadeIn();
1032
														row_helper_dynamic_custom();
1033
													</script>
1034
												</center>
1035
												</td></tr>
1036
												</table>
1037
											</div>
1038
			     						</td>
1039
									</tr>
1040
								</table>
1041
								</center>
1042
								<span class="vexpl">
1043
									<span class="red">
1044
										<strong>
1045
											NOTES:
1046
										</strong>
1047
									</span>
1048
									<br/>* Sizes are in megabytes.
1049
									<br/>* Mount points named /conf are not allowed.  Use /cf if you want to make a configuration slice/mount.
1050
									{$restored_layout_txt}
1051
								</span>
1052
								</strong>
1053
							</div>
1054
						</td>
1055
					</tr>
1056
				</table>
1057
			</div>
1058
			</center>
1059
			<script type="text/javascript">
1060
			<!--
1061
				newrow[1] = "{$select_txt}";
1062
				newrow[2] = "{$custom_disks}";
1063
			-->
1064
			</script>
1065
			
1066

    
1067
EOF;
1068
	page_table_end();
1069
	end_html();
1070
}
1071

    
1072
function installer_main() {
1073
	global $g, $fstype, $savemsg;
1074
	if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
1075
		unlink("/tmp/.pc-sysinstall/pc-sysinstall.log");
1076
	head_html();
1077
	body_html();
1078
	$disk = installer_find_first_disk();
1079
	// Only enable ZFS if this exists.  The install will fail otherwise.
1080
	if(file_exists("/boot/gptzfsboot")) 
1081
		$zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"installer.php?state=easy_install_zfs\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>";
1082
	page_table_start();
1083
	echo <<<EOF
1084
		<form action="installer.php" method="post" state="step1_post">
1085
			<div id="mainlevel">
1086
				<center>
1087
				<b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/>
1088
				<font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font>
1089
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
1090
			 		<tr>
1091
			    		<td>
1092
							<center>
1093
							<div id="mainarea">
1094
								<br/>
1095
								<center>
1096
								Please select an installer option to begin:
1097
								<p/>
1098
								<table width="100%" border="0" cellpadding="5" cellspacing="5">
1099
									<tr>
1100
			     						<td>
1101
											<div id="pfsenseinstaller">
1102
												<center>
1103
EOF;
1104
	if(!$disk) {
1105
		echo gettext("ERROR: Could not find any suitable disks for installation.");
1106
		echo "</div></td></tr></table></div></table></div>";
1107
		end_html();
1108
		exit;
1109
	}
1110
	echo <<<EOF
1111

    
1112
													<table cellspacing="5" cellpadding="5" style="border: 1px dashed;">
1113
														<tr bgcolor="#CECECE"><td align="center">
1114
															<a href="installer.php?state=easy_install_ufs">Easy installation of {$g['product_name']} using the UFS filesystem on disk {$disk}</a>
1115
														</td></tr>
1116
													 	{$zfs_enabled}
1117
														<tr bgcolor="#AAAAAA"><td align="center">
1118
															<a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a>
1119
														</td></tr>
1120
														<tr bgcolor="#CECECE"><td align="center">
1121
															<a href='/'>Cancel and return to Dashboard</a>
1122
														</td></tr>
1123
													</table>
1124
												</center>
1125
											</div>
1126
			     						</td>
1127
									</tr>
1128
								</table>
1129
							</div>
1130
						</td>
1131
					</tr>
1132
				</table>
1133
			</div>
1134
EOF;
1135
	page_table_end();
1136
	end_html();
1137
}
1138

    
1139
function return_rowhelper_row($rownum, $mountpoint, $fstype, $disk, $size, $encpass) {
1140
		global $g, $select_txt, $custom_disks, $savemsg;
1141
		$release = php_uname("r");
1142
		$release = trim($release[0]);
1143

    
1144
		// Mount point
1145
		$disks = installer_find_all_disks();
1146
		$custom_txt .= "<tr>";
1147
		$custom_txt .=  "<td><input size='8' id='mountpoint{$rownum}' name='mountpoint{$rownum}' value='{$mountpoint}'></td>";
1148

    
1149
		// Filesystem type array
1150
		$types = array(
1151
			'UFS' => 'UFS',
1152
			'UFS+S' => 'UFS + Softupdates',
1153
			'UFS.eli' => 'Encrypted UFS',
1154
			'UFS+S.eli' => 'Encrypted UFS + Softupdates',
1155
			'SWAP' => 'SWAP'
1156
		);
1157

    
1158
		// UFS + Journaling was introduced in 9.0
1159
		if($release == "9") {
1160
			$types['UFS+J'] = "UFS + Journaling";
1161
			$types['UFS+J.eli'] = "Encrypted UFS + Journaling";
1162
		}
1163
		
1164
		// Add ZFS Boot loader if it exists
1165
		if(file_exists("/boot/gptzfsboot")) {
1166
			$types['ZFS'] = "Zetabyte Filesystem";
1167
			$types['ZFS.eli'] = "Encrypted Zetabyte Filesystem";
1168
		}
1169

    
1170
		// fstype form field
1171
		$custom_txt .=  "<td><select onChange='javascript:row_helper_dynamic_custom()' id='fstype{$rownum}' name='fstype{$rownum}'>";
1172
		$select_txt = "";
1173
		foreach($types as $type => $desc) {
1174
			if($type == $fstype)
1175
				$SELECTED="SELECTED";
1176
			else 
1177
				$SELECTED="";
1178
			$select_txt .= "<option value='$type' $SELECTED>$desc</option>";
1179
		}
1180
		$custom_txt .= "{$select_txt}</select>\n";
1181
		$custom_txt .= "</td>";
1182
		
1183
		// Disk selection form field
1184
		$custom_txt .= "<td><select id='disk{$rownum}' name='disk{$rownum}'>\n";
1185
		$custom_disks = "";
1186
		foreach($disks as $dsk) {
1187
			$disksize_bytes = format_bytes($dsk['size'] * 1048576);
1188
			$disksize = $dsk['size'];
1189
			if($disk == $dsk['disk'])
1190
				$SELECTED="SELECTED";
1191
			else 
1192
				$SELECTED="";
1193
			$custom_disks .= "<option value='{$dsk['disk']}' $SELECTED>{$dsk['disk']} - {$dsk['desc']} - {$disksize}MB ({$disksize_bytes})</option>";
1194
		}
1195
		$custom_txt .= "{$custom_disks}</select></td>\n";
1196

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

    
1200
		// Encryption password
1201
		$custom_txt .= "<td>";
1202
		$custom_txt .= "<input id='encpass{$rownum}' name='encpass{$rownum}' size='8' value='{$encpass}'>";
1203
		$custom_txt .= "</td>";
1204
	
1205
		// Add Rowhelper + button
1206
		if($rownum > 0) 
1207
			$custom_txt .= "<td><a onclick=\"removeRow(this); return false;\" href=\"#\"><img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_x.gif\" alt=\"\" title=\"remove this entry\"/></a></td>";
1208

    
1209
		$custom_txt .= "</tr>";	
1210
		return $custom_txt;
1211
}
1212

    
1213
?>
(2-2/2)