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
				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
					$canecho = 0;
619
					if ($field['interface_filter'] != "") {
620
						if (stristr($ifname, $field['interface_filter']) == true) {
621
							$canecho = 1;
622
						}
623
					} else {
624
						$canecho = 1;
625
					}
626

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

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

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

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

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

    
661
				$name = strtolower($name);
662

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

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

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

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

    
676
					if ($value == $caname)
677
						$selected = $value;
678

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

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

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

    
704
				$multiple = false;
705
				$name = strtolower($name);
706

    
707
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
708

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

    
714
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
715
				}
716

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

    
722
					$caname = htmlspecialchars($ca['descr']);
723

    
724
					if ($value == $caname) {
725
						array_push($selected, $value);
726
					}
727

    
728

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

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

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

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

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

    
763
				$multiple = ($field['multiple'] == "yes");
764

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

    
772
				$options = array();
773
				$selected = array();
774

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

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

    
786
				}
787

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

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

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

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

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

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

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

    
839
				break;
840
			case "timezone_select":
841
				$timezonelist = system_get_timezone_list();
842

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

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

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

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

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

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

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

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

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

    
894
$form->add($section);
895
print($form);
896
?>
897

    
898
<script type="text/javascript">
899
//<![CDATA[
900

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

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

    
927
		var customarray=new Array(<?=$aliases; ?>);
928

    
929
		window.onload = function () {
930

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

    
943
//]]>
944
</script>
945

    
946
<?php
947

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

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

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

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

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