Project

General

Profile

Download (31.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	wizard.php
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	Copyright (C) 2010 Ermal Luçi
7
	Copyright (C) 2004 Scott Ullrich
8
	All rights reserved.
9

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

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

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

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

    
32
##|+PRIV
33
##|*IDENT=page-pfsensewizardsubsystem
34
##|*NAME=pfSense wizard subsystem page
35
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
36
##|*MATCH=wizard.php*
37
##|-PRIV
38

    
39

    
40
require("globals.inc");
41
require("guiconfig.inc");
42
require("functions.inc");
43
require_once("filter.inc");
44
require("shaper.inc");
45
require_once("rrd.inc");
46

    
47
function gentitle_pkg($pgname) {
48
	global $config;
49
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
50
}
51

    
52
global $g;
53

    
54
$stepid = htmlspecialchars($_GET['stepid']);
55
if (isset($_POST['stepid'])) {
56
	$stepid = htmlspecialchars($_POST['stepid']);
57
}
58
if (!$stepid) {
59
	$stepid = "0";
60
}
61

    
62
$xml = htmlspecialchars($_GET['xml']);
63
if ($_POST['xml']) {
64
	$xml = htmlspecialchars($_POST['xml']);
65
}
66

    
67
if (empty($xml)) {
68
	$xml = "not_defined";
69
	print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
70
	die;
71
} else {
72
	if (file_exists("{$g['www_path']}/wizards/{$xml}")) {
73
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
74
	} else {
75
		print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
76
		die;
77
	}
78
}
79

    
80
if (!is_array($pkg)) {
81
	print_info_box_np(sprintf(gettext("ERROR: Could not parse %s/wizards/%s file."), $g['www_path'], $xml));
82
	die;
83
}
84

    
85
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
86
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
87
$totalsteps  = $pkg['totalsteps'];
88

    
89
if ($pkg['includefile']) {
90
	require_once($pkg['includefile']);
91
}
92

    
93
if ($pkg['step'][$stepid]['includefile']) {
94
	require_once($pkg['step'][$stepid]['includefile']);
95
}
96

    
97
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
98
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
99
}
100

    
101
if ($_POST && !$input_errors) {
102
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
103
		if (!empty($field['bindstofield']) and $field['type'] <> "submit") {
104
			$fieldname = $field['name'];
105
			$fieldname = str_replace(" ", "", $fieldname);
106
			$fieldname = strtolower($fieldname);
107
			// update field with posted values.
108
			if ($field['unsetfield'] <> "") {
109
				$unset_fields = "yes";
110
			} else {
111
				$unset_fields = "";
112
			}
113
			if ($field['arraynum'] <> "") {
114
				$arraynum = $field['arraynum'];
115
			} else {
116
				$arraynum = "";
117
			}
118

    
119
			update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
120
		}
121

    
122
	}
123
	// run custom php code embedded in xml config.
124
	if ($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
125
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
126
	}
127
	if (!$input_errors) {
128
		write_config();
129
	}
130
	$stepid++;
131
	if ($stepid > $totalsteps) {
132
		$stepid = $totalsteps;
133
	}
134
}
135

    
136
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
137
	global $config;
138
	$field_split = explode("->", $field);
139
	foreach ($field_split as $f) {
140
		$field_conv .= "['" . $f . "']";
141
	}
142
	if ($field_conv == "") {
143
		return;
144
	}
145
	if ($arraynum <> "") {
146
		$field_conv .= "[" . $arraynum . "]";
147
	}
148
	if (($field_type == "checkbox" and $updatetext <> "on") || $updatetext == "") {
149
		/*
150
		 * item is a checkbox, it should have the value "on"
151
		 * if it was checked
152
		 */
153
		$var = "\$config{$field_conv}";
154
		$text = "if (isset({$var})) unset({$var});";
155
		eval($text);
156
		return;
157
	}
158

    
159
	if ($field_type == "interfaces_selection") {
160
		$var = "\$config{$field_conv}";
161
		$text = "if (isset({$var})) unset({$var});";
162
		$text .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
163
		eval($text);
164
		return;
165
	}
166

    
167
	if ($unset == "yes") {
168
		$text = "unset(\$config" . $field_conv . ");";
169
		eval($text);
170
	}
171
	$text = "\$config" . $field_conv . " = \"" . addslashes($updatetext) . "\";";
172
	eval($text);
173
}
174

    
175
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
176
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
177

    
178
// handle before form display event.
179
do {
180
	$oldstepid = $stepid;
181
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
182
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
183
	}
184
} while ($oldstepid != $stepid);
185

    
186
$closehead = false;
187
$pgtitle = array($title);
188
include("head.inc");
189

    
190
if (file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) {
191
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
192
} else {
193
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
194
}
195
?>
196
</head>
197
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
198

    
199
<?php if ($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
200
<script type="text/javascript">
201
//<![CDATA[
202

    
203
function FieldValidate(userinput, regexp, message) {
204
	if (!userinput.match(regexp)) {
205
		alert(message);
206
	}
207
}
208

    
209
function enablechange() {
210
<?php
211
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
212
		if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
213
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
214
			if (isset($field['enablefields'])) {
215
				$enablefields = explode(',', $field['enablefields']);
216
				foreach ($enablefields as $enablefield) {
217
					$enablefield = strtolower($enablefield);
218
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
219
				}
220
			}
221
			if (isset($field['checkenablefields'])) {
222
				$checkenablefields = explode(',', $field['checkenablefields']);
223
				foreach ($checkenablefields as $checkenablefield) {
224
					$checkenablefield = strtolower($checkenablefield);
225
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
226
				}
227
			}
228
			print "\t" . '} else {' . "\n";
229
			if (isset($field['enablefields'])) {
230
				$enablefields = explode(',', $field['enablefields']);
231
				foreach ($enablefields as $enablefield) {
232
					$enablefield = strtolower($enablefield);
233
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
234
				}
235
			}
236
			if (isset($field['checkenablefields'])) {
237
				$checkenablefields = explode(',', $field['checkenablefields']);
238
				foreach ($checkenablefields as $checkenablefield) {
239
					$checkenablefield = strtolower($checkenablefield);
240
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
241
				}
242
			}
243
			print "\t" . '}' . "\n";
244
		}
245
	}
246
?>
247
}
248

    
249
function disablechange() {
250
<?php
251
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
252
		if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
253
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
254
			if (isset($field['disablefields'])) {
255
				$enablefields = explode(',', $field['disablefields']);
256
				foreach ($enablefields as $enablefield) {
257
					$enablefield = strtolower($enablefield);
258
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
259
				}
260
			}
261
			if (isset($field['checkdisablefields'])) {
262
				$checkenablefields = explode(',', $field['checkdisablefields']);
263
				foreach ($checkenablefields as $checkenablefield) {
264
					$checkenablefield = strtolower($checkenablefield);
265
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
266
				}
267
			}
268
			print "\t" . '} else {' . "\n";
269
			if (isset($field['disablefields'])) {
270
				$enablefields = explode(',', $field['disablefields']);
271
				foreach ($enablefields as $enablefield) {
272
					$enablefield = strtolower($enablefield);
273
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
274
				}
275
			}
276
			if (isset($field['checkdisablefields'])) {
277
				$checkenablefields = explode(',', $field['checkdisablefields']);
278
				foreach ($checkenablefields as $checkenablefield) {
279
					$checkenablefield = strtolower($checkenablefield);
280
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
281
				}
282
			}
283
			print "\t" . '}' . "\n";
284
		}
285
	}
286
?>
287
}
288

    
289
function showchange() {
290
<?php
291
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
292
		if (isset($field['showfields'])) {
293
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
294
			if (isset($field['showfields'])) {
295
				$showfields = explode(',', $field['showfields']);
296
				foreach ($showfields as $showfield) {
297
					$showfield = strtolower($showfield);
298
					//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
299
					print "\t\t jQuery('#". $showfield . "').hide();";
300
				}
301
			}
302
			print "\t" . '} else {' . "\n";
303
			if (isset($field['showfields'])) {
304
				$showfields = explode(',', $field['showfields']);
305
				foreach ($showfields as $showfield) {
306
					$showfield = strtolower($showfield);
307
					#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
308
					print "\t\t jQuery('#". $showfield . "').show();";
309
				}
310
			}
311
			print "\t" . '}' . "\n";
312
		}
313
	}
314
?>
315
}
316
//]]>
317
</script>
318
<?php } ?>
319

    
320
<form action="wizard.php" method="post" name="iform" id="iform">
321
<input type="hidden" name="xml" value="<?= htmlspecialchars($xml) ?>" />
322
<input type="hidden" name="stepid" value="<?= htmlspecialchars($stepid) ?>" />
323

    
324
<center>
325

    
326
&nbsp;<br />
327

    
328
<?php
329
	if ($title == "Reload in progress") {
330
		$ip = fixup_string("\$myurl");
331
	} else {
332
		$ip = "/";
333
	}
334
	echo "<a href='$ip'>";
335
?>
336
<img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif" alt="logo" /></a>
337
<p>&nbsp;</p>
338
<div style="width:800px;background-color:#ffffff" id="roundme">
339
<?php
340
	if ($input_errors) {
341
		print_input_errors($input_errors);
342
	}
343
	if ($savemsg) {
344
		print_info_box($savemsg);
345
	}
346
	if ($_GET['message'] != "") {
347
		print_info_box(htmlspecialchars($_GET['message']));
348
	}
349
	if ($_POST['message'] != "") {
350
		print_info_box(htmlspecialchars($_POST['message']));
351
	}
352
?>
353
<table bgcolor="#ffffff" width="95%" border="0" cellspacing="0" cellpadding="2" summary="wizard">
354
	<!-- wizard goes here -->
355
	<tr><td>&nbsp;</td></tr>
356
	<tr>
357
		<td class="tabcont">
358
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
359
				<tr>
360
					<td colspan="2" align="center"><font size="2"><b><?= fixup_string($description) ?></b></font></td>
361
				</tr>
362
				<tr>
363
					<td>&nbsp;</td>
364
				</tr>
365
<?php
366
	if (!$pkg['step'][$stepid]['disableheader']) {
367
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
368
	}
369
?>
370

    
371
<?php
372
	$inputaliases = array();
373
	if ($pkg['step'][$stepid]['fields']['field'] <> "") {
374
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
375

    
376
			$value = $field['value'];
377
			$name  = $field['name'];
378

    
379
			$name = preg_replace("/\s+/", "", $name);
380
			$name = strtolower($name);
381

    
382
			if ($field['bindstofield'] <> "") {
383
				$arraynum = "";
384
				$field_conv = "";
385
				$field_split = explode("->", $field['bindstofield']);
386
				// arraynum is used in cases where there is an array of the same field
387
				// name such as dnsserver (2 of them)
388
				if ($field['arraynum'] <> "") {
389
					$arraynum = "[" . $field['arraynum'] . "]";
390
				}
391
				foreach ($field_split as $f) {
392
					$field_conv .= "['" . $f . "']";
393
				}
394
				if ($field['type'] == "checkbox") {
395
					$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
396
				} else {
397
					$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
398
				}
399
				eval($toeval);
400
			}
401

    
402
			if (!$field['combinefieldsend']) {
403
				echo "<tr>";
404
			}
405

    
406
			switch ($field['type']) {
407
			case "input":
408
				if ($field['displayname']) {
409
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
410
					echo $field['displayname'];
411
					echo ":</td>\n";
412
				} else if (!$field['dontdisplayname']) {
413
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
414
					echo fixup_string($field['name']);
415
					echo ":</td>\n";
416
				}
417
				if (!$field['dontcombinecells']) {
418
					echo "<td class=\"vtable\">\n";
419
				}
420

    
421
				echo "<input class='formfld unknown' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\"";
422
				if ($field['size']) {
423
					echo " size='" . $field['size'] . "' ";
424
				}
425
				if ($field['validate']) {
426
					echo " onchange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
427
				}
428
				echo " />\n";
429

    
430
				if ($field['description'] <> "") {
431
					echo "<br /> " . $field['description'];
432
				}
433
				break;
434
			case "text":
435
				echo "<td colspan=\"2\" align=\"center\" class=\"vncell\">\n";
436
				if ($field['description'] <> "") {
437
					echo "<center><br /> " . $field['description'] . "</center>";
438
				}
439
				break;
440
			case "inputalias":
441
				if ($field['displayname']) {
442
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
443
					echo $field['displayname'];
444
					echo ":</td>\n";
445
				} else if (!$field['dontdisplayname']) {
446
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
447
					echo fixup_string($field['name']);
448
					echo ":</td>\n";
449
				}
450
				if (!$field['dontcombinecells']) {
451
					echo "<td class=\"vtable\">\n";
452
				}
453

    
454
				$inputaliases[] = $name;
455
				echo "<input class='formfldalias' autocomplete='off' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\"";
456
				if ($field['size']) {
457
					echo " size='" . $field['size'] . "' ";
458
				}
459
				if ($field['validate']) {
460
					echo " onchange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
461
				}
462
				echo " />\n";
463

    
464
				if ($field['description'] <> "") {
465
					echo "<br /> " . $field['description'];
466
				}
467
				break;
468
			case "interfaces_selection":
469
			case "interface_select":
470
				$size = "";
471
				$multiple = "";
472
				$name = strtolower($name);
473
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
474
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
475
				echo "</td>";
476
				echo "<td class=\"vtable\">\n";
477
				if ($field['size'] <> "") {
478
					$size = "size=\"{$field['size']}\"";
479
				}
480
				if ($field['multiple'] <> "" and $field['multiple'] <> "0") {
481
					$multiple = "multiple=\"multiple\"";
482
					$name .= "[]";
483
				}
484
				echo "<select class='formselect' id='{$name}' name='{$name}' {$size} {$multiple}>\n";
485
				if ($field['add_to_interfaces_selection'] <> "") {
486
					$SELECTED = "";
487
					if ($field['add_to_interfaces_selection'] == $value) {
488
						$SELECTED = " selected=\"selected\"";
489
					}
490
					echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
491
				}
492
				if ($field['type'] == "interface_select") {
493
					$interfaces = get_interface_list();
494
				} else {
495
					$interfaces = get_configured_interface_with_descr();
496
				}
497
				foreach ($interfaces as $ifname => $iface) {
498
					if ($field['type'] == "interface_select") {
499
						$iface = $ifname;
500
						if ($iface['mac']) {
501
							$iface .= " ({$iface['mac']})";
502
						}
503
					}
504
					$SELECTED = "";
505
					if ($value == $ifname) $SELECTED = " selected=\"selected\"";
506
					$to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $iface . "</option>\n";
507
					$to_echo .= "<!-- {$value} -->";
508
					$canecho = 0;
509
					if ($field['interface_filter'] <> "") {
510
						if (stristr($ifname, $field['interface_filter']) == true) {
511
							$canecho = 1;
512
						}
513
					} else {
514
						$canecho = 1;
515
					}
516
					if ($canecho == 1) {
517
						echo $to_echo;
518
					}
519
				}
520
				echo "</select>\n";
521

    
522
				if ($field['description'] <> "") {
523
					echo "<br /> " . $field['description'];
524
				}
525

    
526
				break;
527
			case "password":
528
				if ($field['displayname']) {
529
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
530
					echo $field['displayname'];
531
					echo ":</td>\n";
532
				} else if (!$field['dontdisplayname']) {
533
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
534
					echo fixup_string($field['name']);
535
					echo ":</td>\n";
536
				}
537
				if (!$field['dontcombinecells']) {
538
					echo "<td class=\"vtable\">";
539
				}
540
				echo "<input class='formfld pwd' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\" type='password' ";
541
				if ($field['size']) {
542
					echo " size='" . $field['size'] . "' ";
543
				}
544
				echo " />\n";
545

    
546
				if ($field['description'] <> "") {
547
					echo "<br /> " . $field['description'];
548
				}
549

    
550
				break;
551
			case "certca_selection":
552
				$size = "";
553
				$multiple = "";
554
				$name = strtolower($name);
555
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
556
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
557
				echo "</td>";
558
				echo "<td class=\"vtable\">\n";
559
				if ($field['size'] <> "") {
560
					$size = "size=\"{$field['size']}\"";
561
				}
562
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
563
				if ($field['add_to_certca_selection'] <> "") {
564
					$SELECTED = "";
565
					if ($field['add_to_certca_selection'] == $value) {
566
						$SELECTED = " selected=\"selected\"";
567
					}
568
					echo "<option value='" . $field['add_to_certca_selection'] . "'" . $SELECTED . ">" . $field['add_to_certca_selection'] . "</option>\n";
569
				}
570
				foreach ($config['ca'] as $ca) {
571
					$name = htmlspecialchars($ca['descr']);
572
					$SELECTED = "";
573
					if ($value == $name) $SELECTED = " selected=\"selected\"";
574
					$to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
575
					$to_echo .= "<!-- {$value} -->";
576
					$canecho = 0;
577
					if ($field['certca_filter'] <> "") {
578
						if (stristr($name, $field['certca_filter']) == true) {
579
							$canecho = 1;
580
						}
581
					} else {
582
						$canecho = 1;
583
					}
584
					if ($canecho == 1) {
585
						echo $to_echo;
586
					}
587
				}
588
				echo "</select>\n";
589

    
590
				if ($field['description'] <> "") {
591
					echo "<br /> " . $field['description'];
592
				}
593

    
594
				break;
595
			case "cert_selection":
596
				$size = "";
597
				$multiple = "";
598
				$name = strtolower($name);
599
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
600
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
601
				echo "</td>";
602
				echo "<td class=\"vtable\">\n";
603
				if ($field['size'] <> "") {
604
					$size = "size=\"{$field['size']}\"";
605
				}
606
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
607
				if ($field['add_to_cert_selection'] <> "") {
608
					$SELECTED = "";
609
					if ($field['add_to_cert_selection'] == $value) {
610
						$SELECTED = " selected=\"selected\"";
611
					}
612
					echo "<option value='" . $field['add_to_cert_selection'] . "'" . $SELECTED . ">" . $field['add_to_cert_selection'] . "</option>\n";
613
				}
614
				foreach ($config['cert'] as $ca) {
615
					if (stristr($ca['descr'], "webconf")) {
616
						continue;
617
					}
618
					$name = htmlspecialchars($ca['descr']);
619
					$SELECTED = "";
620
					if ($value == $name) {
621
						$SELECTED = " selected=\"selected\"";
622
					}
623
					$to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
624
					$to_echo .= "<!-- {$value} -->";
625
					$canecho = 0;
626
					if ($field['cert_filter'] <> "") {
627
						if (stristr($name, $field['cert_filter']) == true) {
628
							$canecho = 1;
629
						}
630
					} else {
631
						$canecho = 1;
632
					}
633
					if ($canecho == 1) {
634
						echo $to_echo;
635
					}
636
				}
637
				echo "</select>\n";
638

    
639
				if ($field['description'] <> "") {
640
					echo "<br /> " . $field['description'];
641
				}
642

    
643
				break;
644
			case "select":
645
				if ($field['displayname']) {
646
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
647
					echo $field['displayname'];
648
					echo ":</td>\n";
649
				} else if (!$field['dontdisplayname']) {
650
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
651
					echo fixup_string($field['name']);
652
					echo ":</td>\n";
653
				}
654
				if ($field['size']) {
655
					$size = " size='" . $field['size'] . "' ";
656
				}
657
				if ($field['multiple'] == "yes") {
658
					$multiple = "multiple=\"multiple\" ";
659
				}
660
				if (!$field['dontcombinecells']) {
661
					echo "<td class=\"vtable\">\n";
662
				}
663
				$onchange = "";
664
				foreach ($field['options']['option'] as $opt) {
665
					if ($opt['enablefields'] <> "") {
666
						$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
667
					}
668
				}
669
				echo "<select class='formselect' " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
670
				foreach ($field['options']['option'] as $opt) {
671
					$selected = "";
672
					if ($value == $opt['value']) {
673
						$selected = " selected=\"selected\"";
674
					}
675
					echo "\t<option value='" . $opt['value'] . "'" . $selected . ">";
676
					if ($opt['displayname']) {
677
						echo $opt['displayname'];
678
					} else {
679
						echo $opt['name'];
680
					}
681
					echo "</option>\n";
682
				}
683
				echo "</select>\n";
684
				echo "<!-- {$value} -->\n";
685

    
686
				if ($field['description'] <> "") {
687
					echo $field['description'];
688
				}
689

    
690
				break;
691
			case "textarea":
692
				if ($field['displayname']) {
693
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
694
					echo $field['displayname'];
695
					echo ":</td>\n";
696
				} else if (!$field['dontdisplayname']) {
697
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
698
					echo fixup_string($field['name']);
699
					echo ":</td>";
700
				}
701
				if (!$field['dontcombinecells']) {
702
					echo "<td class=\"vtable\">";
703
				}
704
				echo "<textarea class='formpre' id='" . $name . "' name='" . $name . "'";
705
				if ($field['rows']) {
706
					echo " rows='" . $field['rows'] . "' ";
707
				}
708
				if ($field['cols']) {
709
					echo " cols='" . $field['cols'] . "' ";
710
				}
711
				echo ">" . $value . "</textarea>\n";
712

    
713

    
714
				if ($field['description'] <> "") {
715
					echo "<br /> " . $field['description'];
716
				}
717

    
718
				break;
719
			case "submit":
720
				echo "<td>&nbsp;<br /></td></tr>";
721
				echo "<tr><td colspan=\"2\" align=\"center\">";
722
				echo "<input type='submit' name='" . $name . "' value=\"" . htmlspecialchars($field['name']) . "\" />\n";
723

    
724
				if ($field['description'] <> "") {
725
					echo "<br /> " . $field['description'];
726
				}
727

    
728
				break;
729
			case "listtopic":
730
				echo "<td>&nbsp;</td></tr>";
731
				echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br />\n";
732

    
733
				break;
734
			case "subnet_select":
735
				if ($field['displayname']) {
736
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
737
					echo $field['displayname'];
738
					echo ":</td>\n";
739
				} else if (!$field['dontdisplayname']) {
740
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
741
					echo fixup_string($field['name']);
742
					echo ":</td>";
743
				}
744
				if (!$field['dontcombinecells']) {
745
					echo "<td class=\"vtable\">";
746
				}
747
				echo "<select class='formselect' name='{$name}'>\n";
748
				for ($x=1; $x<33; $x++) {
749
					$CHECKED = "";
750
					if ($value == $x) {
751
						$CHECKED = " selected=\"selected\"";
752
					}
753
					if ($x <> 31) {
754
						echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
755
					}
756
				}
757
				echo "</select>\n";
758

    
759
				if ($field['description'] <> "") {
760
					echo "<br /> " . $field['description'];
761
				}
762

    
763
				break;
764
			case "timezone_select":
765
				exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
766
				$timezonelist = array_filter($timezonelist, 'is_timezone');
767
				sort($timezonelist);
768

    
769
				/* kill carriage returns */
770
				for ($x = 0; $x < count($timezonelist); $x++) {
771
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
772
				}
773

    
774
				if ($field['displayname']) {
775
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
776
					echo $field['displayname'];
777
					echo ":</td>\n";
778
				} else if (!$field['dontdisplayname']) {
779
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
780
					echo fixup_string($field['name']);
781
					echo ":</td>";
782
				}
783
				if (!$field['dontcombinecells']) {
784
					echo "<td class=\"vtable\">";
785
				}
786
				echo "<select class='formselect' name='{$name}'>\n";
787
				foreach ($timezonelist as $tz) {
788
					if (strstr($tz, "GMT")) {
789
						continue;
790
					}
791
					$SELECTED = "";
792
					if ($value == $tz) {
793
						$SELECTED = " selected=\"selected\"";
794
					}
795
					echo "<option value=\"" . htmlspecialchars($tz) . "\" {$SELECTED}>";
796
					echo htmlspecialchars($tz);
797
					echo "</option>\n";
798
				}
799
				echo "</select>\n";
800

    
801
				if ($field['description'] <> "") {
802
					echo "<br /> " . $field['description'];
803
				}
804

    
805
				break;
806
			case "checkbox":
807
				if ($field['displayname']) {
808
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
809
					echo $field['displayname'];
810
					echo ":</td>\n";
811
				} else if (!$field['dontdisplayname']) {
812
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
813
					echo $field['name'];
814
					echo ":</td>";
815
				}
816
				$checked = "";
817
				if ($value <> "") {
818
					$checked = " checked=\"checked\"";
819
				}
820
				echo "<td class=\"vtable\"><input value=\"on\" type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
821
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
822
					echo " onclick=\"enablechange()\"";
823
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
824
					echo " onclick=\"disablechange()\"";
825
				}
826
				echo " />\n";
827

    
828
				if ($field['description'] <> "") {
829
					echo $field['description'];
830
				}
831

    
832
				break;
833
			}
834

    
835
			if ($field['typehint'] <> "") {
836
				echo $field['typehint'];
837
			}
838
			if ($field['warning'] <> "") {
839
				echo "<br /><b><font color=\"red\">" . $field['warning'] . "</font></b>";
840
			}
841

    
842
			if (!$field['combinefieldsbegin']) {
843
				if (!$field['dontcombinecells']) {
844
					echo "</td>";
845
				}
846

    
847
				echo "</tr>\n";
848
			}
849

    
850
		}
851
	}
852
?>
853
			</table>
854
		</td>
855
	</tr>
856
</table>
857
<br />&nbsp;
858
</div>
859
</center>
860
</form>
861
<script type="text/javascript">
862
//<![CDATA[
863
	if (typeof ext_change != 'undefined') {
864
		ext_change();
865
	}
866
	if (typeof proto_change != 'undefined') {
867
		ext_change();
868
	}
869
	if (typeof proto_change != 'undefined') {
870
		proto_change();
871
	}
872

    
873
<?php
874
	$isfirst = 0;
875
	$aliases = "";
876
	$addrisfirst = 0;
877
	$aliasesaddr = "";
878
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
879
		foreach ($config['aliases']['alias'] as $alias_name) {
880
			if ($isfirst == 1) {
881
				$aliases .= ",";
882
			}
883
			$aliases .= "'" . $alias_name['name'] . "'";
884
			$isfirst = 1;
885
		}
886
	}
887
?>
888

    
889
	var customarray=new Array(<?php echo $aliases; ?>);
890

    
891
	window.onload = function () {
892

    
893
<?php
894
	$counter = 0;
895
	foreach ($inputaliases as $alias) {
896
		echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(customarray));\n";
897
		$counter++;
898
	}
899
?>
900

    
901
	}
902

    
903
//]]>
904
</script>
905

    
906
<?php
907

    
908
$fieldnames_array = Array();
909
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
910
	// create a fieldname loop that can be used with javascript
911
	// hide and enable features.
912
	echo "\n<script type=\"text/javascript\">\n";
913
	echo "//<![CDATA[\n";
914
	echo "function disableall() {\n";
915
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
916
		if ($field['type'] <> "submit" and $field['type'] <> "listtopic") {
917
			if (!$field['donotdisable'] <> "") {
918
				array_push($fieldnames_array, $field['name']);
919
				$fieldname = preg_replace("/\s+/", "", $field['name']);
920
				$fieldname = strtolower($fieldname);
921
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
922
			}
923
		}
924
	}
925
	echo "}\ndisableall();\n";
926
	echo "function enableitems(selectedindex) {\n";
927
	echo "disableall();\n";
928
	$idcounter = 0;
929
	if ($pkg['step'][$stepid]['fields']['field'] <> "") {
930
		echo "\tswitch (selectedindex) {\n";
931
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
932
			if ($field['options']['option'] <> "") {
933
				foreach ($field['options']['option'] as $opt) {
934
					if ($opt['enablefields'] <> "") {
935
						echo "\t\tcase " . $idcounter . ":\n";
936
						$enablefields_split = explode(",", $opt['enablefields']);
937
						foreach ($enablefields_split as $efs) {
938
							$fieldname = preg_replace("/\s+/", "", $efs);
939
							$fieldname = strtolower($fieldname);
940
							if ($fieldname <> "") {
941
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
942
								echo $onchange;
943
							}
944
						}
945
						echo "\t\t\tbreak;\n";
946
					}
947
					$idcounter = $idcounter + 1;
948
				}
949
			}
950
		}
951
		echo "\t}\n";
952
	}
953
	echo "}\n";
954
	echo "//]]>\n";
955
	echo "</script>\n\n";
956
}
957
?>
958

    
959
<script type="text/javascript">
960
//<![CDATA[
961
NiftyCheck();
962
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
963
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
964
enablechange();
965
disablechange();
966
showchange();
967
//]]>
968
</script>
969

    
970
<?php
971
if ($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
972
	// handle after form display event.
973
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
974
}
975

    
976
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
977
	// handle after form display event.
978
	echo "\n<script type=\"text/javascript\">\n";
979
	echo "//<![CDATA[\n";
980
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
981
	echo "//]]>\n";
982
	echo "</script>\n\n";
983
}
984

    
985
/*
986
 *  HELPER FUNCTIONS
987
 */
988

    
989
function fixup_string($string) {
990
	global $config, $g, $myurl, $title;
991
	$newstring = $string;
992
	// fixup #1: $myurl -> http[s]://ip_address:port/
993
	switch ($config['system']['webgui']['protocol']) {
994
		case "http":
995
			$proto = "http";
996
			break;
997
		case "https":
998
			$proto = "https";
999
			break;
1000
		default:
1001
			$proto = "http";
1002
			break;
1003
	}
1004
	$port = $config['system']['webgui']['port'];
1005
	if ($port != "") {
1006
		if (($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
1007
			$urlport = ":" . $port;
1008
		} elseif ($port != "80" and $port != "443") {
1009
			$urlport = ":" . $port;
1010
		} else {
1011
			$urlport = "";
1012
		}
1013
	}
1014
	$http_host = $_SERVER['SERVER_NAME'];
1015
	$urlhost = $http_host;
1016
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
1017
	if ($title == "Reload in progress") {
1018
		if (is_ipaddr($urlhost)) {
1019
			$host_if = find_ip_interface($urlhost);
1020
			if ($host_if) {
1021
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
1022
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) {
1023
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
1024
				}
1025
			}
1026
		} else if ($urlhost == $config['system']['hostname']) {
1027
			$urlhost = $config['wizardtemp']['system']['hostname'];
1028
		} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
1029
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
1030
		}
1031
	}
1032
	if ($urlhost != $http_host) {
1033
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
1034
	}
1035
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
1036

    
1037
	if (strstr($newstring, "\$myurl")) {
1038
		$newstring = str_replace("\$myurl", $myurl, $newstring);
1039
	}
1040
	// fixup #2: $wanip
1041
	if (strstr($newstring, "\$wanip")) {
1042
		$curwanip = get_interface_ip();
1043
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
1044
	}
1045
	// fixup #3: $lanip
1046
	if (strstr($newstring, "\$lanip")) {
1047
		$lanip = get_interface_ip("lan");
1048
		$newstring = str_replace("\$lanip", $lanip, $newstring);
1049
	}
1050
	// fixup #4: fix'r'up here.
1051
	return $newstring;
1052
}
1053

    
1054
function is_timezone($elt) {
1055
	return !preg_match("/\/$/", $elt);
1056
}
1057

    
1058
?>
1059

    
1060
</body>
1061
</html>
(234-234/235)