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
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(sprintf(gettext("Could not open %s."), $xml), 'danger');
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(gettext("Invalid path specified."), 'danger');
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(sprintf(gettext("Could not open %s."), $xml), 'danger');
105
		die;
106
	}
107
}
108

    
109
if (!is_array($pkg)) {
110
	print_info_box(sprintf(gettext("Could not parse %s/wizards/%s file."), $g['www_path'], $xml), 'danger');
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']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
219
$shortcut_section = "Wizard";
220
include("head.inc");
221

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

    
226

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

    
233
	function enablechange() {
234

    
235
	<?php
236

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

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

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

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

    
264
					}
265
				}
266

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

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

    
280
	}
281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
457
<?php
458

    
459
$form = new Form(false);
460

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

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

    
475
$section = new Form_Section(fixup_string($title));
476

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

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

    
488
		$value = $field['value'];
489
		$name  = $field['name'];
490

    
491
		$name = preg_replace("/\s+/", "", $name);
492
		$name = strtolower($name);
493

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

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

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

    
514
			eval($toeval);
515
		}
516

    
517

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

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

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

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

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

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

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

    
555
				$onchange = "";
556

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

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

    
570
				break;
571
			case "interfaces_selection":
572
			case "interface_select":
573

    
574
				$name = strtolower($name);
575
				$options = array();
576
				$selected = array();
577

    
578
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
579

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

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

    
591
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
592
				}
593

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

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

    
608
					if ($value == $ifname) {
609
						array_push($selected, $value);
610
					}
611

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

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

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

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

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

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

    
655
				$name = strtolower($name);
656

    
657
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
658

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

    
664
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
665
				}
666

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

    
670
					if ($value == $caname) {
671
						$selected = $value;
672
					}
673

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

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

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

    
699
				$multiple = false;
700
				$name = strtolower($name);
701

    
702
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
703

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

    
709
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
710
				}
711

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

    
717
					$caname = htmlspecialchars($ca['descr']);
718

    
719
					if ($value == $caname) {
720
						array_push($selected, $value);
721
					}
722

    
723

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

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

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

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

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

    
758
				$multiple = ($field['multiple'] == "yes");
759

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

    
767
				$options = array();
768
				$selected = array();
769

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

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

    
781
				}
782

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

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

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

    
807
				break;
808
			case "submit":
809
				$form->addGlobal(new Form_Button(
810
					$name,
811
					$field['name'],
812
					null,
813
					'fa-angle-double-right'
814
				))->addClass('btn-primary');
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
			$('#' + '<?=$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");
(224-224/225)