Project

General

Profile

Download (27.7 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
global $g;
75

    
76
$stepid = htmlspecialchars($_GET['stepid']);
77
if (isset($_POST['stepid'])) {
78
	$stepid = htmlspecialchars($_POST['stepid']);
79
}
80

    
81
if (!$stepid) {
82
	$stepid = "0";
83
}
84

    
85
$xml = htmlspecialchars($_GET['xml']);
86
if ($_POST['xml']) {
87
	$xml = htmlspecialchars($_POST['xml']);
88
}
89

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

    
109
if (!is_array($pkg)) {
110
	print_info_box_np(sprintf(gettext("ERROR: Could not parse %s/wizards/%s file."), $g['www_path'], $xml));
111
	die;
112
}
113

    
114
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
115
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
116
$totalsteps	 = $pkg['totalsteps'];
117

    
118
if ($pkg['includefile']) {
119
	require_once($pkg['includefile']);
120
}
121

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

    
126
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
127
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
128
}
129

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

    
143
			if ($field['arraynum'] != "") {
144
				$arraynum = $field['arraynum'];
145
			} else {
146
				$arraynum = "";
147
			}
148

    
149
			update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
150
		}
151

    
152
	}
153
	// run custom php code embedded in xml config.
154
	if ($pkg['step'][$stepid]['stepsubmitphpaction'] != "") {
155
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
156
	}
157
	if (!$input_errors) {
158
		write_config();
159
	}
160

    
161
	$stepid++;
162
	if ($stepid > $totalsteps) {
163
		$stepid = $totalsteps;
164
	}
165
}
166

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

    
190
	if ($field_type == "interfaces_selection") {
191
		$var = "\$config{$field_conv}";
192
		$text = "if (isset({$var})) unset({$var});";
193
		$text .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
194
		eval($text);
195
		return;
196
	}
197

    
198
	if ($unset == "yes") {
199
		$text = "unset(\$config" . $field_conv . ");";
200
		eval($text);
201
	}
202
	$text = "\$config" . $field_conv . " = \"" . addslashes($updatetext) . "\";";
203
	eval($text);
204
}
205

    
206
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
207
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
208

    
209
// handle before form display event.
210
do {
211
	$oldstepid = $stepid;
212
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
213
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
214
	}
215
} while ($oldstepid != $stepid);
216

    
217
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
218
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'');		//Following steps are sub-level breadcrumbs.
219
include("head.inc");
220

    
221
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
222
<script type="text/javascript">
223
//<![CDATA[
224

    
225

    
226
	function FieldValidate(userinput, regexp, message) {
227
		if (!userinput.match(regexp)) {
228
			alert(message);
229
		}
230
	}
231

    
232
	function enablechange() {
233

    
234
	<?php
235

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

    
240
				if (isset($field['enablefields'])) {
241
					$enablefields = explode(',', $field['enablefields']);
242
					foreach ($enablefields as $enablefield) {
243
						$enablefield = strtolower($enablefield);
244
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
245
					}
246
				}
247

    
248
				if (isset($field['checkenablefields'])) {
249
					$checkenablefields = explode(',', $field['checkenablefields']);
250
					foreach ($checkenablefields as $checkenablefield) {
251
						$checkenablefield = strtolower($checkenablefield);
252
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
253
					}
254
				}
255

    
256
				print "\t" . '} else {' . "\n";
257
				if (isset($field['enablefields'])) {
258
					$enablefields = explode(',', $field['enablefields']);
259
					foreach ($enablefields as $enablefield) {
260
						$enablefield = strtolower($enablefield);
261
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
262

    
263
					}
264
				}
265

    
266
			if (isset($field['checkdisablefields'])) {
267
				$checkenablefields = explode(',', $field['checkdisablefields']);
268
				foreach ($checkenablefields as $checkenablefield) {
269
					$checkenablefield = strtolower($checkenablefield);
270
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
271
					}
272
				}
273

    
274
				print "\t" . '}' . "\n";
275
			}
276
		}
277
	?>
278

    
279
	}
280

    
281
	function disablechange() {
282
	<?php
283
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
284
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
285

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

    
288
				if (isset($field['disablefields'])) {
289
					$enablefields = explode(',', $field['disablefields']);
290
					foreach ($enablefields as $enablefield) {
291
						$enablefield = strtolower($enablefield);
292

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

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

    
352
//]]>
353
</script>
354
<?php }
355

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

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

    
401
	if ($urlhost != $http_host) {
402
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
403
	}
404

    
405
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
406

    
407
	if (strstr($newstring, "\$myurl")) {
408
		$newstring = str_replace("\$myurl", $myurl, $newstring);
409
	}
410
	// fixup #2: $wanip
411
	if (strstr($newstring, "\$wanip")) {
412
		$curwanip = get_interface_ip();
413
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
414
	}
415
	// fixup #3: $lanip
416
	if (strstr($newstring, "\$lanip")) {
417
		$lanip = get_interface_ip("lan");
418
		$newstring = str_replace("\$lanip", $lanip, $newstring);
419
	}
420
	// fixup #4: fix'r'up here.
421
	return $newstring;
422
}
423

    
424
function is_timezone($elt) {
425
	return !preg_match("/\/$/", $elt);
426
}
427

    
428
if ($title == "Reload in progress") {
429
	$ip = fixup_string("\$myurl");
430
} else {
431
	$ip = "/";
432
}
433

    
434
if ($input_errors) {
435
	print_input_errors($input_errors);
436
}
437
if ($savemsg) {
438
	print_info_box($savemsg, 'success');
439
}
440
if ($_GET['message'] != "") {
441
	print_info_box(htmlspecialchars($_GET['message']));
442
}
443
if ($_POST['message'] != "") {
444
	print_info_box(htmlspecialchars($_POST['message']));
445
}
446

    
447
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
448
?>
449

    
450
<!-- Present the pfSense logo -->
451
<div class="text-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/>
452

    
453
<!-- Draw a progress bar to show step progress -->
454
<div class="progress">
455
	<div class="progress-bar" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%">
456
	</div>
457
</div>
458

    
459
<?php
460

    
461
$form = new Form(false);
462

    
463
$form->addGlobal(new Form_Input(
464
	'stepid',
465
	null,
466
	'hidden',
467
	$stepid
468
));
469

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

    
477
$section = new Form_Section(fixup_string($title));
478

    
479
if ($description) {
480
	$section->addInput(new Form_StaticText(
481
		null,
482
		fixup_string($description)
483
	));
484
}
485

    
486
$inputaliases = array();
487
if ($pkg['step'][$stepid]['fields']['field'] != "") {
488
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
489

    
490
		$value = $field['value'];
491
		$name  = $field['name'];
492

    
493
		$name = preg_replace("/\s+/", "", $name);
494
		$name = strtolower($name);
495

    
496
		if ($field['bindstofield'] != "") {
497
			$arraynum = "";
498
			$field_conv = "";
499
			$field_split = explode("->", $field['bindstofield']);
500
			// arraynum is used in cases where there is an array of the same field
501
			// name such as dnsserver (2 of them)
502
			if ($field['arraynum'] != "") {
503
				$arraynum = "[" . $field['arraynum'] . "]";
504
			}
505

    
506
			foreach ($field_split as $f) {
507
				$field_conv .= "['" . $f . "']";
508
			}
509

    
510
			if ($field['type'] == "checkbox") {
511
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
512
			} else {
513
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
514
			}
515

    
516
			eval($toeval);
517
		}
518

    
519

    
520
		if (DEBUG) {
521
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
522
		}
523

    
524
		switch ($field['type']) {
525
			case "input":
526
				if ($field['displayname']) {
527
					$etitle = $field['displayname'];
528

    
529
				} else if (!$field['dontdisplayname']) {
530
					$etitle =  fixup_string($field['name']);
531
				}
532

    
533
				$section->addInput(new Form_Input(
534
					$name,
535
					$etitle,
536
					'text',
537
					$value
538
				))->setHelp($field['description'])
539
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")":"");
540

    
541
				break;
542
			case "text":
543
				$section->addInput(new Form_StaticText(
544
					null,
545
					$field['description']
546
				));
547

    
548
				break;
549
			case "inputalias":
550
				if ($field['displayname']) {
551
					$etitle = $field['displayname'];
552

    
553
				} else if (!$field['dontdisplayname']) {
554
					$etitle =  fixup_string($field['name']);
555
				}
556

    
557
				$onchange = "";
558

    
559
				if ($field['validate']) {
560
					$onchange="FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")";
561
				}
562

    
563
				$section->addInput(new Form_Input(
564
					$name,
565
					$etitle,
566
					'text',
567
					$value
568
				))->setAttribute('autocomplete', 'off')
569
				  ->setOnchange($onchange)
570
				  ->setHelp($field['description']);
571

    
572
				break;
573
			case "interfaces_selection":
574
			case "interface_select":
575

    
576
				$name = strtolower($name);
577
				$options = array();
578
				$selected = array();
579

    
580
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
581

    
582
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
583
					$multiple = true;
584
				} else {
585
					$multiple = false;
586
				}
587

    
588
				if ($field['add_to_interfaces_selection'] != "") {
589
					if ($field['add_to_interfaces_selection'] == $value) {
590
						array_push($selected, $value);
591
					}
592

    
593
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
594
				}
595

    
596
				if ($field['type'] == "interface_select") {
597
					$interfaces = get_interface_list();
598
				} else {
599
					$interfaces = get_configured_interface_with_descr();
600
				}
601

    
602
				foreach ($interfaces as $ifname => $iface) {
603
					if ($field['type'] == "interface_select") {
604
						$iface = $ifname;
605
						if ($iface['mac']) {
606
							$iface .= " ({$iface['mac']})";
607
						}
608
					}
609

    
610
					if ($value == $ifname) {
611
						array_push($selected, $value);
612
					}
613

    
614
					$canecho = 0;
615
					if ($field['interface_filter'] != "") {
616
						if (stristr($ifname, $field['interface_filter']) == true) {
617
							$canecho = 1;
618
						}
619
					} else {
620
						$canecho = 1;
621
					}
622

    
623
					if ($canecho == 1) {
624
						$options[$ifname] = $iface;
625
					}
626
				}
627

    
628
				$section->addInput(new Form_Select(
629
					$name,
630
					$etitle,
631
					($multiple) ? $selected:$selected[0],
632
					$options,
633
					$multiple
634
				))->setHelp($field['description']);
635

    
636
				break;
637
			case "password":
638
				if ($field['displayname']) {
639
					$etitle = $field['displayname'];
640
				} else if (!$field['dontdisplayname']) {
641
					$etitle =  fixup_string($field['name']);
642
				}
643

    
644
				$section->addInput(new Form_Input(
645
					$name,
646
					$etitle,
647
					'password',
648
					$value
649
				))->setHelp($field['description'])
650
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] .")":"");
651

    
652
				break;
653
			case "certca_selection":
654
				$options = array();
655
				$selected = "";
656

    
657
				$name = strtolower($name);
658

    
659
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
660

    
661
				if ($field['add_to_certca_selection'] != "") {
662
					if ($field['add_to_certca_selection'] == $value) {
663
						$selected = $value;
664
					}
665

    
666
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
667
				}
668

    
669
				foreach ($config['ca'] as $ca) {
670
					$caname = htmlspecialchars($ca['descr']);
671

    
672
					if ($value == $caname) {
673
						$selected = $value;
674
					}
675

    
676
					$canecho = 0;
677
					if ($field['certca_filter'] != "") {
678
						if (stristr($caname, $field['certca_filter']) == true) {
679
							$canecho = 1;
680
						}
681
					} else {
682
						$canecho = 1;
683
					}
684
					if ($canecho == 1) {
685
						$options[$ca['refid']] = $caname;
686
					}
687
				}
688

    
689
				$section->addInput(new Form_Select(
690
					$name,
691
					$etitle,
692
					$selected,
693
					$options
694
				))->setHelp($field['description']);
695

    
696
				break;
697
			case "cert_selection":
698
				$options = array();
699
				$selected = array();
700

    
701
				$multiple = false;
702
				$name = strtolower($name);
703

    
704
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
705

    
706
				if ($field['add_to_cert_selection'] != "") {
707
					if ($field['add_to_cert_selection'] == $value) {
708
						array_push($selected, $value);
709
					}
710

    
711
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
712
				}
713

    
714
				foreach ($config['cert'] as $ca) {
715
					if (stristr($ca['descr'], "webconf")) {
716
						continue;
717
					}
718

    
719
					$caname = htmlspecialchars($ca['descr']);
720

    
721
					if ($value == $caname) {
722
						array_push($selected, $value);
723
					}
724

    
725

    
726
					$canecho = 0;
727
					if ($field['cert_filter'] != "") {
728
						if (stristr($caname, $field['cert_filter']) == true) {
729
							$canecho = 1;
730
						}
731
					} else {
732
						$canecho = 1;
733
					}
734

    
735
					if ($canecho == 1) {
736
						$options[$ca['refid']] = $caname;
737
					}
738
				}
739

    
740
				$section->addInput(new Form_Select(
741
					$name,
742
					$etitle,
743
					($multiple) ? $selected:$selected[0],
744
					$options,
745
					$multiple
746
				))->setHelp($field['description']);
747

    
748
				break;
749
			case "select":
750
				if ($field['displayname']) {
751
					$etitle = $field['displayname'];
752
				} else if (!$field['dontdisplayname']) {
753
					$etitle =  fixup_string($field['name']);
754
				}
755

    
756
				if ($field['size']) {
757
					$size = " size='" . $field['size'] . "' ";
758
				}
759

    
760
				$multiple = ($field['multiple'] == "yes");
761

    
762
				$onchange = "";
763
				foreach ($field['options']['option'] as $opt) {
764
					if ($opt['enablefields'] != "") {
765
						$onchange = "Javascript:enableitems(this.selectedIndex);";
766
					}
767
				}
768

    
769
				$options = array();
770
				$selected = array();
771

    
772
				foreach ($field['options']['option'] as $opt) {
773
					if ($value == $opt['value']) {
774
						array_push($selected, $value);
775
					}
776

    
777
					if ($opt['displayname']) {
778
						$options[$opt['value']] = $opt['displayname'];
779
					} else {
780
						$options[$opt['value']] = $opt['name'];
781
					}
782

    
783
				}
784

    
785
				$section->addInput(new Form_Select(
786
					$name,
787
					$etitle,
788
					($multiple) ? $selected:$selected[0],
789
					$options,
790
					$multiple
791
				))->setHelp($field['description'])->setOnchange($onchange);
792

    
793
				break;
794
			case "textarea":
795
				if ($field['displayname']) {
796
					$etitle = $field['displayname'];
797
				} else if (!$field['dontdisplayname']) {
798
					$etitle =  fixup_string($field['name']);
799
				}
800

    
801
				$section->addInput(new Form_Textarea(
802
					$name,
803
					$etitle,
804
					$value
805
				))->setHelp($field['description'])
806
				  ->setAttribute('rows', $field['rows'])
807
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")":"");
808

    
809
				break;
810
			case "submit":
811
				$form->addGlobal(new Form_Button(
812
					$name,
813
					$field['name']
814
				));
815

    
816
				break;
817
			case "listtopic":
818
				$form->add($section);
819
				$section = new Form_Section($field['name']);
820

    
821
				break;
822
			case "subnet_select":
823
				if ($field['displayname']) {
824
					$etitle = $field['displayname'];
825
				} else /* if (!$field['dontdisplayname']) */ {
826
					$etitle =  fixup_string($field['name']);
827
				}
828

    
829
				$section->addInput(new Form_Select(
830
					$name,
831
					$etitle,
832
					$value,
833
					array_combine(range(32, 1, -1), range(32, 1, -1))
834
				))->setHelp($field['description']);
835

    
836
				break;
837
			case "timezone_select":
838
				$timezonelist = system_get_timezone_list();
839

    
840
				/* kill carriage returns */
841
				for ($x = 0; $x < count($timezonelist); $x++) {
842
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
843
				}
844

    
845
				if ($field['displayname']) {
846
					$etitle = $field['displayname'];
847
				} else if (!$field['dontdisplayname']) {
848
					$etitle =  fixup_string($field['name']);
849
				}
850

    
851
				if (!$field['dontcombinecells']) {
852
					//echo "<td class=\"vtable\">";
853
				}
854

    
855
				$section->addInput(new Form_Select(
856
					$name,
857
					$etitle,
858
					($value == "") ? $g['default_timezone'] : $value,
859
					array_combine($timezonelist, $timezonelist)
860
				))->setHelp($field['description']);
861

    
862
				break;
863
			case "checkbox":
864
				if ($field['displayname']) {
865
					$etitle = $field['displayname'];
866

    
867
				} else if (!$field['dontdisplayname']) {
868
					$etitle =  fixup_string($field['name']);
869
				}
870

    
871
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
872
					$onclick = "enablechange()";
873
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
874
					$onclick = "disablechange()";
875
				}
876

    
877
				$section->addInput(new Form_Checkbox(
878
					$name,
879
					$etitle,
880
					$field['typehint'],
881
					($value != ""),
882
					'on'
883
				))->setHelp($field['description'])
884
				  ->setOnclick($onclick);
885

    
886
				break;
887
		} // e-o-switch
888
	} // e-o-foreach(package)
889
} // e-o- if(we have fields)
890

    
891
$form->add($section);
892
print($form);
893
?>
894

    
895
<script type="text/javascript">
896
//<![CDATA[
897

    
898
		if (typeof ext_change != 'undefined') {
899
			ext_change();
900
		}
901
		if (typeof proto_change != 'undefined') {
902
			ext_change();
903
		}
904
		if (typeof proto_change != 'undefined') {
905
			proto_change();
906
		}
907

    
908
	<?php
909
		$isfirst = 0;
910
		$aliases = "";
911
		$addrisfirst = 0;
912
		$aliasesaddr = "";
913
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
914
			foreach ($config['aliases']['alias'] as $alias_name) {
915
				if ($isfirst == 1) {
916
					$aliases .= ",";
917
				}
918
				$aliases .= "'" . $alias_name['name'] . "'";
919
				$isfirst = 1;
920
			}
921
		}
922
	?>
923

    
924
		var customarray=new Array(<?=$aliases; ?>);
925

    
926
		window.onload = function () {
927

    
928
<?php
929
		$counter = 0;
930
		foreach ($inputaliases as $alias) {
931
?>
932
			$('#' + '<?php echo $alias; ?>').autocomplete({
933
				source: customarray
934
			});
935
<?php
936
		}
937
?>
938
	}
939

    
940
//]]>
941
</script>
942

    
943
<?php
944

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

    
996
<script type="text/javascript">
997
//<![CDATA[
998
events.push(function() {
999
	enablechange();
1000
	disablechange();
1001
	showchange();
1002
});
1003
//]]>
1004
</script>
1005

    
1006
<?php
1007
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1008
	// handle after form display event.
1009
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1010
}
1011

    
1012
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
1013
	// handle after form display event.
1014
	echo "\n<script type=\"text/javascript\">\n";
1015
	echo "//<![CDATA[\n";
1016
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1017
	echo "//]]>\n";
1018
	echo "</script>\n\n";
1019
}
1020

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