Project

General

Profile

Download (27.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	wizard.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	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
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18
 *
19
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28
 *
29
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *	====================================================================
53
 *
54
 */
55

    
56
##|+PRIV
57
##|*IDENT=page-pfsensewizardsubsystem
58
##|*NAME=pfSense wizard subsystem
59
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
60
##|*MATCH=wizard.php*
61
##|-PRIV
62

    
63
require("globals.inc");
64
require("guiconfig.inc");
65
require("functions.inc");
66
require_once("filter.inc");
67
require("shaper.inc");
68
require_once("rrd.inc");
69
require_once("system.inc");
70

    
71
// This causes the step #, field type and field name to be printed at the top of the page
72
define(DEBUG, false);
73

    
74
function gentitle_pkg($pgname) {
75
	global $config;
76
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
77
}
78

    
79
global $g;
80

    
81
$stepid = htmlspecialchars($_GET['stepid']);
82
if (isset($_POST['stepid'])) {
83
	$stepid = htmlspecialchars($_POST['stepid']);
84
}
85

    
86
if (!$stepid) {
87
	$stepid = "0";
88
}
89

    
90
$xml = htmlspecialchars($_GET['xml']);
91
if ($_POST['xml']) {
92
	$xml = htmlspecialchars($_POST['xml']);
93
}
94

    
95
if (empty($xml)) {
96
	$xml = "not_defined";
97
	print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
98
	die;
99
} else {
100
	$wizard_xml_prefix = "{$g['www_path']}/wizards";
101
	$wizard_full_path = "{$wizard_xml_prefix}/{$xml}";
102
	if (substr_compare(realpath($wizard_full_path), $wizard_xml_prefix, 0, strlen($wizard_xml_prefix))) {
103
		print_info_box_np(gettext("ERROR: Invalid path specified."));
104
		die;
105
	}
106
	if (file_exists($wizard_full_path)) {
107
		$pkg = parse_xml_config_pkg($wizard_full_path, "pfsensewizard");
108
	} else {
109
		print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
110
		die;
111
	}
112
}
113

    
114
if (!is_array($pkg)) {
115
	print_info_box_np(sprintf(gettext("ERROR: Could not parse %s/wizards/%s file."), $g['www_path'], $xml));
116
	die;
117
}
118

    
119
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
120
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
121
$totalsteps	 = $pkg['totalsteps'];
122

    
123
if ($pkg['includefile']) {
124
	require_once($pkg['includefile']);
125
}
126

    
127
if ($pkg['step'][$stepid]['includefile']) {
128
	require_once($pkg['step'][$stepid]['includefile']);
129
}
130

    
131
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
132
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
133
}
134

    
135
if ($_POST && !$input_errors) {
136
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
137
		if (!empty($field['bindstofield']) and $field['type'] != "submit") {
138
			$fieldname = $field['name'];
139
			$fieldname = str_replace(" ", "", $fieldname);
140
			$fieldname = strtolower($fieldname);
141
			// update field with posted values.
142
			if ($field['unsetfield'] != "") {
143
				$unset_fields = "yes";
144
			} else {
145
				$unset_fields = "";
146
			}
147

    
148
			if ($field['arraynum'] != "") {
149
				$arraynum = $field['arraynum'];
150
			} else {
151
				$arraynum = "";
152
			}
153

    
154
			update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
155
		}
156

    
157
	}
158
	// run custom php code embedded in xml config.
159
	if ($pkg['step'][$stepid]['stepsubmitphpaction'] != "") {
160
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
161
	}
162
	if (!$input_errors) {
163
		write_config();
164
	}
165

    
166
	$stepid++;
167
	if ($stepid > $totalsteps) {
168
		$stepid = $totalsteps;
169
	}
170
}
171

    
172
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
173
	global $config;
174
	$field_split = explode("->", $field);
175
	foreach ($field_split as $f) {
176
		$field_conv .= "['" . $f . "']";
177
	}
178
	if ($field_conv == "") {
179
		return;
180
	}
181
	if ($arraynum != "") {
182
		$field_conv .= "[" . $arraynum . "]";
183
	}
184
	if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
185
		/*
186
		 * item is a checkbox, it should have the value "on"
187
		 * if it was checked
188
		 */
189
		$var = "\$config{$field_conv}";
190
		$text = "if (isset({$var})) unset({$var});";
191
		eval($text);
192
		return;
193
	}
194

    
195
	if ($field_type == "interfaces_selection") {
196
		$var = "\$config{$field_conv}";
197
		$text = "if (isset({$var})) unset({$var});";
198
		$text .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
199
		eval($text);
200
		return;
201
	}
202

    
203
	if ($unset == "yes") {
204
		$text = "unset(\$config" . $field_conv . ");";
205
		eval($text);
206
	}
207
	$text = "\$config" . $field_conv . " = \"" . addslashes($updatetext) . "\";";
208
	eval($text);
209
}
210

    
211
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
212
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
213

    
214
// handle before form display event.
215
do {
216
	$oldstepid = $stepid;
217
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
218
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
219
	}
220
} while ($oldstepid != $stepid);
221

    
222
$closehead = false;
223
$pgtitle = array($title);
224
$notitle = true;
225
include("head.inc");
226

    
227
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
228
<script type="text/javascript">
229
//<![CDATA[
230

    
231

    
232
	function FieldValidate(userinput, regexp, message) {
233
		if (!userinput.match(regexp)) {
234
			alert(message);
235
		}
236
	}
237

    
238
	function enablechange() {
239

    
240
	<?php
241

    
242
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
243
			if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
244
				print "\t" . 'if ( $("#" + "' . strtolower($field['name']) . '").prop("checked") ) {' . "\n";
245

    
246
				if (isset($field['enablefields'])) {
247
					$enablefields = explode(',', $field['enablefields']);
248
					foreach ($enablefields as $enablefield) {
249
						$enablefield = strtolower($enablefield);
250
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
251
					}
252
				}
253

    
254
				if (isset($field['checkenablefields'])) {
255
					$checkenablefields = explode(',', $field['checkenablefields']);
256
					foreach ($checkenablefields as $checkenablefield) {
257
						$checkenablefield = strtolower($checkenablefield);
258
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
259
					}
260
				}
261

    
262
				print "\t" . '} else {' . "\n";
263
				if (isset($field['enablefields'])) {
264
					$enablefields = explode(',', $field['enablefields']);
265
					foreach ($enablefields as $enablefield) {
266
						$enablefield = strtolower($enablefield);
267
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
268

    
269
					}
270
				}
271

    
272
			if (isset($field['checkdisablefields'])) {
273
				$checkenablefields = explode(',', $field['checkdisablefields']);
274
				foreach ($checkenablefields as $checkenablefield) {
275
					$checkenablefield = strtolower($checkenablefield);
276
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
277
					}
278
				}
279

    
280
				print "\t" . '}' . "\n";
281
			}
282
		}
283
	?>
284

    
285
	}
286

    
287
	function disablechange() {
288
	<?php
289
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
290
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
291

    
292
				print "\t" . 'if ( $("#" + "' . strtolower($field['name']) . '").prop("checked") ) {' . "\n";
293

    
294
				if (isset($field['disablefields'])) {
295
					$enablefields = explode(',', $field['disablefields']);
296
					foreach ($enablefields as $enablefield) {
297
						$enablefield = strtolower($enablefield);
298

    
299
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
300
					}
301
				}
302
				if (isset($field['checkdisablefields'])) {
303
					$checkenablefields = explode(',', $field['checkdisablefields']);
304
					foreach ($checkenablefields as $checkenablefield) {
305
						$checkenablefield = strtolower($checkenablefield);
306
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
307
					}
308
				}
309
				print "\t" . '} else {' . "\n";
310
				if (isset($field['disablefields'])) {
311
					$enablefields = explode(',', $field['disablefields']);
312
					foreach ($enablefields as $enablefield) {
313
						$enablefield = strtolower($enablefield);
314
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
315
					}
316
				}
317
				if (isset($field['checkdisablefields'])) {
318
					$checkenablefields = explode(',', $field['checkdisablefields']);
319
					foreach ($checkenablefields as $checkenablefield) {
320
						$checkenablefield = strtolower($checkenablefield);
321
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
322
					}
323
				}
324
				print "\t" . '}' . "\n";
325
			}
326
		}
327
	?>
328
	}
329

    
330
	function showchange() {
331
<?php
332
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
333
			if (isset($field['showfields'])) {
334
				print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
335
				if (isset($field['showfields'])) {
336
					$showfields = explode(',', $field['showfields']);
337
					foreach ($showfields as $showfield) {
338
						$showfield = strtolower($showfield);
339
						//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
340
						print "\t\t jQuery('#". $showfield . "').hide();";
341
					}
342
				}
343
				print "\t" . '} else {' . "\n";
344
				if (isset($field['showfields'])) {
345
					$showfields = explode(',', $field['showfields']);
346
					foreach ($showfields as $showfield) {
347
						$showfield = strtolower($showfield);
348
						#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
349
						print "\t\t jQuery('#". $showfield . "').show();";
350
					}
351
				}
352
				print "\t" . '}' . "\n";
353
			}
354
		}
355
?>
356
	}
357

    
358
//]]>
359
</script>
360
<?php }
361

    
362
function fixup_string($string) {
363
	global $config, $g, $myurl, $title;
364
	$newstring = $string;
365
	// fixup #1: $myurl -> http[s]://ip_address:port/
366
	switch ($config['system']['webgui']['protocol']) {
367
		case "http":
368
			$proto = "http";
369
			break;
370
		case "https":
371
			$proto = "https";
372
			break;
373
		default:
374
			$proto = "http";
375
			break;
376
	}
377
	$port = $config['system']['webgui']['port'];
378
	if ($port != "") {
379
		if (($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
380
			$urlport = ":" . $port;
381
		} elseif ($port != "80" and $port != "443") {
382
			$urlport = ":" . $port;
383
		} else {
384
			$urlport = "";
385
		}
386
	}
387

    
388
	$http_host = $_SERVER['SERVER_NAME'];
389
	$urlhost = $http_host;
390
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
391
	if ($title == "Reload in progress") {
392
		if (is_ipaddr($urlhost)) {
393
			$host_if = find_ip_interface($urlhost);
394
			if ($host_if) {
395
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
396
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) {
397
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
398
				}
399
			}
400
		} else if ($urlhost == $config['system']['hostname']) {
401
			$urlhost = $config['wizardtemp']['system']['hostname'];
402
		} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
403
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
404
		}
405
	}
406

    
407
	if ($urlhost != $http_host) {
408
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
409
	}
410

    
411
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
412

    
413
	if (strstr($newstring, "\$myurl")) {
414
		$newstring = str_replace("\$myurl", $myurl, $newstring);
415
	}
416
	// fixup #2: $wanip
417
	if (strstr($newstring, "\$wanip")) {
418
		$curwanip = get_interface_ip();
419
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
420
	}
421
	// fixup #3: $lanip
422
	if (strstr($newstring, "\$lanip")) {
423
		$lanip = get_interface_ip("lan");
424
		$newstring = str_replace("\$lanip", $lanip, $newstring);
425
	}
426
	// fixup #4: fix'r'up here.
427
	return $newstring;
428
}
429

    
430
function is_timezone($elt) {
431
	return !preg_match("/\/$/", $elt);
432
}
433

    
434
if ($title == "Reload in progress") {
435
	$ip = fixup_string("\$myurl");
436
} else {
437
	$ip = "/";
438
}
439

    
440
if ($input_errors) {
441
	print_input_errors($input_errors);
442
}
443
if ($savemsg) {
444
	print_info_box($savemsg, 'success');
445
}
446
if ($_GET['message'] != "") {
447
	print_info_box(htmlspecialchars($_GET['message']));
448
}
449
if ($_POST['message'] != "") {
450
	print_info_box(htmlspecialchars($_POST['message']));
451
}
452

    
453
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
454
?>
455

    
456
<!-- Present the pfSense logo -->
457
<div style="text-align:center"><p><a href="<?=$ip?>"><img border="0" src="logo-black.png" alt="logo-black" align="middle" height="45" width="180" /></a></p></div><br /><br/>
458

    
459
<!-- Draw a progress bar to show step progress -->
460
<div class="progress">
461
	<div class="progress-bar" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%">
462
	</div>
463
</div>
464

    
465
<?php
466

    
467
$form = new Form(false);
468

    
469
$form->addGlobal(new Form_Input(
470
	'stepid',
471
	null,
472
	'hidden',
473
	$stepid
474
));
475

    
476
$form->addGlobal(new Form_Input(
477
	'xml',
478
	null,
479
	'hidden',
480
	$xml
481
));
482

    
483
$section = new Form_Section(fixup_string($title));
484

    
485
if ($description) {
486
	$section->addInput(new Form_StaticText(
487
		null,
488
		fixup_string($description)
489
	));
490
}
491

    
492
$inputaliases = array();
493
if ($pkg['step'][$stepid]['fields']['field'] != "") {
494
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
495

    
496
		$value = $field['value'];
497
		$name  = $field['name'];
498

    
499
		$name = preg_replace("/\s+/", "", $name);
500
		$name = strtolower($name);
501

    
502
		if ($field['bindstofield'] != "") {
503
			$arraynum = "";
504
			$field_conv = "";
505
			$field_split = explode("->", $field['bindstofield']);
506
			// arraynum is used in cases where there is an array of the same field
507
			// name such as dnsserver (2 of them)
508
			if ($field['arraynum'] != "") {
509
				$arraynum = "[" . $field['arraynum'] . "]";
510
			}
511

    
512
			foreach ($field_split as $f) {
513
				$field_conv .= "['" . $f . "']";
514
			}
515

    
516
			if ($field['type'] == "checkbox") {
517
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
518
			} else {
519
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
520
			}
521

    
522
			eval($toeval);
523
		}
524

    
525

    
526
		if (DEBUG) {
527
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
528
		}
529

    
530
		switch ($field['type']) {
531
			case "input":
532
				if ($field['displayname']) {
533
					$etitle = $field['displayname'];
534

    
535
				} else if (!$field['dontdisplayname']) {
536
					$etitle =  fixup_string($field['name']);
537
				}
538

    
539
				$section->addInput(new Form_Input(
540
					$name,
541
					$etitle,
542
					'text',
543
					$value
544
				))->setHelp($field['description'])
545
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")":"");
546

    
547
				break;
548
			case "text":
549
				$section->addInput(new Form_StaticText(
550
					null,
551
					$field['description']
552
				));
553

    
554
				break;
555
			case "inputalias":
556
				if ($field['displayname']) {
557
					$etitle = $field['displayname'];
558

    
559
				} else if (!$field['dontdisplayname']) {
560
					$etitle =  fixup_string($field['name']);
561
				}
562

    
563
				$onchange = "";
564

    
565
				if ($field['validate']) {
566
					$onchange="FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")";
567
				}
568

    
569
				$section->addInput(new Form_Input(
570
					$name,
571
					$etitle,
572
					'text',
573
					$value
574
				))->setAttribute('autocomplete', 'off')
575
				  ->setOnchange($onchange)
576
				  ->setHelp($field['description']);
577

    
578
				break;
579
			case "interfaces_selection":
580
			case "interface_select":
581

    
582
				$name = strtolower($name);
583
				$options = array();
584
				$selected = array();
585

    
586
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
587

    
588
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
589
					$multiple = true;
590
				} else {
591
					$multiple = false;
592
				}
593

    
594
				if ($field['add_to_interfaces_selection'] != "") {
595
					if ($field['add_to_interfaces_selection'] == $value) {
596
						array_push($selected, $value);
597
					}
598

    
599
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
600
				}
601

    
602
				if ($field['type'] == "interface_select") {
603
					$interfaces = get_interface_list();
604
				} else {
605
					$interfaces = get_configured_interface_with_descr();
606
				}
607

    
608
				foreach ($interfaces as $ifname => $iface) {
609
					if ($field['type'] == "interface_select") {
610
						$iface = $ifname;
611
						if ($iface['mac']) {
612
							$iface .= " ({$iface['mac']})";
613
						}
614
					}
615

    
616
					if ($value == $ifname) {
617
						array_push($selected, $value);
618
					}
619

    
620
					$canecho = 0;
621
					if ($field['interface_filter'] != "") {
622
						if (stristr($ifname, $field['interface_filter']) == true) {
623
							$canecho = 1;
624
						}
625
					} else {
626
						$canecho = 1;
627
					}
628

    
629
					if ($canecho == 1) {
630
						$options[$ifname] = $iface;
631
					}
632
				}
633

    
634
				$section->addInput(new Form_Select(
635
					$name,
636
					$etitle,
637
					($multiple) ? $selected:$selected[0],
638
					$options,
639
					$multiple
640
				))->setHelp($field['description']);
641

    
642
				break;
643
			case "password":
644
				if ($field['displayname']) {
645
					$etitle = $field['displayname'];
646
				} else if (!$field['dontdisplayname']) {
647
					$etitle =  fixup_string($field['name']);
648
				}
649

    
650
				$section->addInput(new Form_Input(
651
					$name,
652
					$etitle,
653
					'password',
654
					$value
655
				))->setHelp($field['description'])
656
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] .")":"");
657

    
658
				break;
659
			case "certca_selection":
660
				$options = array();
661
				$selected = "";
662

    
663
				$name = strtolower($name);
664

    
665
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
666

    
667
				if ($field['add_to_certca_selection'] != "") {
668
					if ($field['add_to_certca_selection'] == $value) {
669
						$selected = $value;
670
					}
671

    
672
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
673
				}
674

    
675
				foreach ($config['ca'] as $ca) {
676
					$caname = htmlspecialchars($ca['descr']);
677

    
678
					if ($value == $caname) {
679
						$selected = $value;
680
					}
681

    
682
					$canecho = 0;
683
					if ($field['certca_filter'] != "") {
684
						if (stristr($caname, $field['certca_filter']) == true) {
685
							$canecho = 1;
686
						}
687
					} else {
688
						$canecho = 1;
689
					}
690
					if ($canecho == 1) {
691
						$options[$ca['refid']] = $caname;
692
					}
693
				}
694

    
695
				$section->addInput(new Form_Select(
696
					$name,
697
					$etitle,
698
					$selected,
699
					$options
700
				))->setHelp($field['description']);
701

    
702
				break;
703
			case "cert_selection":
704
				$options = array();
705
				$selected = array();
706

    
707
				$multiple = false;
708
				$name = strtolower($name);
709

    
710
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
711

    
712
				if ($field['add_to_cert_selection'] != "") {
713
					if ($field['add_to_cert_selection'] == $value) {
714
						array_push($selected, $value);
715
					}
716

    
717
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
718
				}
719

    
720
				foreach ($config['cert'] as $ca) {
721
					if (stristr($ca['descr'], "webconf")) {
722
						continue;
723
					}
724

    
725
					$caname = htmlspecialchars($ca['descr']);
726

    
727
					if ($value == $caname) {
728
						array_push($selected, $value);
729
					}
730

    
731

    
732
					$canecho = 0;
733
					if ($field['cert_filter'] != "") {
734
						if (stristr($caname, $field['cert_filter']) == true) {
735
							$canecho = 1;
736
						}
737
					} else {
738
						$canecho = 1;
739
					}
740

    
741
					if ($canecho == 1) {
742
						$options[$ca['refid']] = $caname;
743
					}
744
				}
745

    
746
				$section->addInput(new Form_Select(
747
					$name,
748
					$etitle,
749
					($multiple) ? $selected:$selected[0],
750
					$options,
751
					$multiple
752
				))->setHelp($field['description']);
753

    
754
				break;
755
			case "select":
756
				if ($field['displayname']) {
757
					$etitle = $field['displayname'];
758
				} else if (!$field['dontdisplayname']) {
759
					$etitle =  fixup_string($field['name']);
760
				}
761

    
762
				if ($field['size']) {
763
					$size = " size='" . $field['size'] . "' ";
764
				}
765

    
766
				$multiple = ($field['multiple'] == "yes");
767

    
768
				$onchange = "";
769
				foreach ($field['options']['option'] as $opt) {
770
					if ($opt['enablefields'] != "") {
771
						$onchange = "Javascript:enableitems(this.selectedIndex);";
772
					}
773
				}
774

    
775
				$options = array();
776
				$selected = array();
777

    
778
				foreach ($field['options']['option'] as $opt) {
779
					if ($value == $opt['value']) {
780
						array_push($selected, $value);
781
					}
782

    
783
					if ($opt['displayname']) {
784
						$options[$opt['value']] = $opt['displayname'];
785
					} else {
786
						$options[$opt['value']] = $opt['name'];
787
					}
788

    
789
				}
790

    
791
				$section->addInput(new Form_Select(
792
					$name,
793
					$etitle,
794
					($multiple) ? $selected:$selected[0],
795
					$options,
796
					$multiple
797
				))->setHelp($field['description'])->setOnchange($onchange);
798

    
799
				break;
800
			case "textarea":
801
				if ($field['displayname']) {
802
					$etitle = $field['displayname'];
803
				} else if (!$field['dontdisplayname']) {
804
					$etitle =  fixup_string($field['name']);
805
				}
806

    
807
				$section->addInput(new Form_Textarea(
808
					$name,
809
					$etitle,
810
					$value
811
				))->setHelp($field['description'])
812
				  ->setAttribute('rows', $field['rows'])
813
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")":"");
814

    
815
				break;
816
			case "submit":
817
				$form->addGlobal(new Form_Button(
818
					$name,
819
					$field['name']
820
				));
821

    
822
				break;
823
			case "listtopic":
824
				$form->add($section);
825
				$section = new Form_Section($field['name']);
826

    
827
				break;
828
			case "subnet_select":
829
				if ($field['displayname']) {
830
					$etitle = $field['displayname'];
831
				} else /* if (!$field['dontdisplayname']) */ {
832
					$etitle =  fixup_string($field['name']);
833
				}
834

    
835
				$section->addInput(new Form_Select(
836
					$name,
837
					$etitle,
838
					$value,
839
					array_combine(range(32, 1, -1), range(32, 1, -1))
840
				))->setHelp($field['description']);
841

    
842
				break;
843
			case "timezone_select":
844
				$timezonelist = system_get_timezone_list();
845

    
846
				/* kill carriage returns */
847
				for ($x = 0; $x < count($timezonelist); $x++) {
848
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
849
				}
850

    
851
				if ($field['displayname']) {
852
					$etitle = $field['displayname'];
853
				} else if (!$field['dontdisplayname']) {
854
					$etitle =  fixup_string($field['name']);
855
				}
856

    
857
				if (!$field['dontcombinecells']) {
858
					//echo "<td class=\"vtable\">";
859
				}
860

    
861
				$section->addInput(new Form_Select(
862
					$name,
863
					$etitle,
864
					($value == "") ? $g['default_timezone'] : $value,
865
					array_combine($timezonelist, $timezonelist)
866
				))->setHelp($field['description']);
867

    
868
				break;
869
			case "checkbox":
870
				if ($field['displayname']) {
871
					$etitle = $field['displayname'];
872

    
873
				} else if (!$field['dontdisplayname']) {
874
					$etitle =  fixup_string($field['name']);
875
				}
876

    
877
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
878
					$onclick = "enablechange()";
879
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
880
					$onclick = "disablechange()";
881
				}
882

    
883
				$section->addInput(new Form_Checkbox(
884
					$name,
885
					$etitle,
886
					$field['typehint'],
887
					($value != ""),
888
					'on'
889
				))->setHelp($field['description'])
890
				  ->setOnclick($onclick);
891

    
892
				break;
893
		} // e-o-switch
894
	} // e-o-foreach(package)
895
} // e-o- if(we have fields)
896

    
897
$form->add($section);
898
print($form);
899
?>
900

    
901
<script type="text/javascript">
902
//<![CDATA[
903

    
904
		if (typeof ext_change != 'undefined') {
905
			ext_change();
906
		}
907
		if (typeof proto_change != 'undefined') {
908
			ext_change();
909
		}
910
		if (typeof proto_change != 'undefined') {
911
			proto_change();
912
		}
913

    
914
	<?php
915
		$isfirst = 0;
916
		$aliases = "";
917
		$addrisfirst = 0;
918
		$aliasesaddr = "";
919
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
920
			foreach ($config['aliases']['alias'] as $alias_name) {
921
				if ($isfirst == 1) {
922
					$aliases .= ",";
923
				}
924
				$aliases .= "'" . $alias_name['name'] . "'";
925
				$isfirst = 1;
926
			}
927
		}
928
	?>
929

    
930
		var customarray=new Array(<?=$aliases; ?>);
931

    
932
		window.onload = function () {
933

    
934
<?php
935
		$counter = 0;
936
		foreach ($inputaliases as $alias) {
937
?>
938
			$('#' + '<?php echo $alias; ?>').autocomplete({
939
				source: customarray
940
			});
941
<?php
942
		}
943
?>
944
	}
945

    
946
//]]>
947
</script>
948

    
949
<?php
950

    
951
$fieldnames_array = Array();
952
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] != "") {
953
	// create a fieldname loop that can be used with javascript
954
	// hide and enable features.
955
	echo "\n<script type=\"text/javascript\">\n";
956
	echo "//<![CDATA[\n";
957
	echo "function disableall() {\n";
958
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
959
		if ($field['type'] != "submit" and $field['type'] != "listtopic") {
960
			if (!$field['donotdisable'] != "") {
961
				array_push($fieldnames_array, $field['name']);
962
				$fieldname = preg_replace("/\s+/", "", $field['name']);
963
				$fieldname = strtolower($fieldname);
964
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
965
			}
966
		}
967
	}
968
	echo "}\ndisableall();\n";
969
	echo "function enableitems(selectedindex) {\n";
970
	echo "disableall();\n";
971
	$idcounter = 0;
972
	if ($pkg['step'][$stepid]['fields']['field'] != "") {
973
		echo "\tswitch (selectedindex) {\n";
974
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
975
			if ($field['options']['option'] != "") {
976
				foreach ($field['options']['option'] as $opt) {
977
					if ($opt['enablefields'] != "") {
978
						echo "\t\tcase " . $idcounter . ":\n";
979
						$enablefields_split = explode(",", $opt['enablefields']);
980
						foreach ($enablefields_split as $efs) {
981
							$fieldname = preg_replace("/\s+/", "", $efs);
982
							$fieldname = strtolower($fieldname);
983
							if ($fieldname != "") {
984
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
985
								echo $onchange;
986
							}
987
						}
988
						echo "\t\t\tbreak;\n";
989
					}
990
					$idcounter = $idcounter + 1;
991
				}
992
			}
993
		}
994
		echo "\t}\n";
995
	}
996
	echo "}\n";
997
	echo "//]]>\n";
998
	echo "</script>\n\n";
999
}
1000
?>
1001

    
1002
<script type="text/javascript">
1003
//<![CDATA[
1004
events.push(function() {
1005
	enablechange();
1006
	disablechange();
1007
	showchange();
1008
});
1009
//]]>
1010
</script>
1011

    
1012
<?php
1013
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1014
	// handle after form display event.
1015
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1016
}
1017

    
1018
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
1019
	// handle after form display event.
1020
	echo "\n<script type=\"text/javascript\">\n";
1021
	echo "//<![CDATA[\n";
1022
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1023
	echo "//]]>\n";
1024
	echo "</script>\n\n";
1025
}
1026

    
1027
include("foot.inc");
(227-227/228)