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
$pgtitle = array($title);
223
$notitle = true;
224
include("head.inc");
225

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

    
230

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

    
237
	function enablechange() {
238

    
239
	<?php
240

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

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

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

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

    
268
					}
269
				}
270

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

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

    
284
	}
285

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
455
<!-- Present the pfSense logo -->
456
<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/>
457

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

    
464
<?php
465

    
466
$form = new Form(false);
467

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

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

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

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

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

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

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

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

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

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

    
521
			eval($toeval);
522
		}
523

    
524

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

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

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

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

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

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

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

    
562
				$onchange = "";
563

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
662
				$name = strtolower($name);
663

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
730

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

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

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

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

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

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

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

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

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

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

    
788
				}
789

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
931
		window.onload = function () {
932

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

    
945
//]]>
946
</script>
947

    
948
<?php
949

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

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

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

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

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