Project

General

Profile

Download (29.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * wizard.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

    
24
##|+PRIV
25
##|*IDENT=page-pfsensewizardsubsystem
26
##|*NAME=pfSense wizard subsystem
27
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
28
##|*MATCH=wizard.php*
29
##|-PRIV
30

    
31
require_once("globals.inc");
32
require_once("guiconfig.inc");
33
require_once("functions.inc");
34
require_once("filter.inc");
35
require_once("shaper.inc");
36
require_once("rrd.inc");
37
require_once("system.inc");
38

    
39
// This causes the step #, field type and field name to be printed at the top of the page
40
define('DEBUG', false);
41

    
42
global $g;
43

    
44
$stepid = htmlspecialchars($_REQUEST['stepid']);
45

    
46

    
47
if (!$stepid) {
48
	$stepid = "0";
49
}
50

    
51
$xml = htmlspecialchars($_REQUEST['xml']);
52

    
53
if (empty($xml)) {
54
	$xml = "not_defined";
55
	print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
56
	die;
57
} else {
58
	$wizard_xml_prefix = "{$g['www_path']}/wizards";
59
	$wizard_full_path = "{$wizard_xml_prefix}/{$xml}";
60
	if (substr_compare(realpath($wizard_full_path), $wizard_xml_prefix, 0, strlen($wizard_xml_prefix))) {
61
		print_info_box(gettext("Invalid path specified."), 'danger');
62
		die;
63
	}
64
	if (file_exists($wizard_full_path)) {
65
		$pkg = parse_xml_config_pkg($wizard_full_path, "pfsensewizard");
66
	} else {
67
		print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
68
		die;
69
	}
70
}
71

    
72
if (!is_array($pkg)) {
73
	print_info_box(sprintf(gettext('Could not parse %1$s/wizards/%2$s file.'), $g['www_path'], $xml), 'danger');
74
	die;
75
}
76

    
77
$totalsteps = $pkg['totalsteps'];
78

    
79
if ($pkg['includefile']) {
80
	require_once($pkg['includefile']);
81
}
82

    
83
if ($pkg['step'][$stepid]['includefile']) {
84
	require_once($pkg['step'][$stepid]['includefile']);
85
}
86

    
87
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
88
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
89
}
90

    
91
if ($_POST && !$input_errors) {
92
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
93
		if (!empty($field['bindstofield']) and $field['type'] != "submit") {
94
			$fieldname = $field['name'];
95
			$fieldname = str_replace(" ", "", $fieldname);
96
			$fieldname = strtolower($fieldname);
97
			// update field with posted values.
98
			if ($field['unsetfield'] != "") {
99
				$unset_fields = "yes";
100
			} else {
101
				$unset_fields = "";
102
			}
103

    
104
			if ($field['arraynum'] != "") {
105
				$arraynum = $field['arraynum'];
106
			} else {
107
				$arraynum = "";
108
			}
109

    
110
			update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
111
		}
112

    
113
	}
114
	// run custom php code embedded in xml config.
115
	if ($pkg['step'][$stepid]['stepsubmitphpaction'] != "") {
116
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
117
	}
118
	if (!$input_errors) {
119
		write_config(gettext("Configuration changed via the wizard subsystem."));
120
	}
121

    
122
	$stepid++;
123
}
124

    
125
while (!empty($pkg['step'][$stepid]['skip_flavors'])) {
126
	$skip = false;
127
	foreach (explode(',', $pkg['step'][$stepid]['skip_flavors']) as $flavor) {
128
		if ($flavor == $g['default-config-flavor']) {
129
			$skip = true;
130
			break;
131
		}
132
	}
133
	if ($skip) {
134
		$stepid++;
135
	} else {
136
		break;
137
	}
138
}
139

    
140
if ($stepid > $totalsteps) {
141
	$stepid = $totalsteps;
142
}
143

    
144
// Convert a string containing a text version of a PHP array into a real $config array
145
// that can then be created. e.g.: config_array_from_str("['apple']['orange']['pear']['banana']");
146
function config_array_from_str( $text) {
147
	$t = str_replace("[", "", $text);	// Remove '['
148
	$t = str_replace("'", "", $t);		// Remove '
149
	$t = str_replace("\"", "", $t);		// Remove "
150
	$t = str_replace("]", " ", $t);		// Convert ] to space
151
	$a = explode(" ", trim($t));
152
	init_config_arr($a);
153
}
154

    
155
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
156
	global $config;
157
	$field_split = explode("->", $field);
158
	$thisvar = null;
159
	foreach ($field_split as $f) {
160
		$field_conv .= "['" . $f . "']";
161
	}
162
	if ($field_conv == "") {
163
		return;
164
	}
165
	if ($arraynum != "") {
166
		$field_conv .= "[" . $arraynum . "]";
167
	}
168
	if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
169
		/*
170
		 * item is a checkbox, it should have the value "on"
171
		 * if it was checked
172
		 */
173
		$var = "\$config{$field_conv}";
174
		$text = "if (isset({$var})) unset({$var});";
175
		eval($text);
176
		return;
177
	}
178

    
179
	if ($field_type == "interfaces_selection") {
180
		$var = "\$config{$field_conv}";
181
		$text = "if (isset({$var})) unset({$var});";
182
		$text .= "\$thisvar = &\$config" . $field_conv . ";";
183
		eval($text);
184
		$thisvar = $updatetext;
185
		return;
186
	}
187

    
188
	if ($field_type == "select") {
189
		if (is_array($updatetext)) {
190
			$updatetext = implode(',', $updatetext);
191
		}
192
	}
193

    
194
	if ($unset == "yes") {
195
		$text = "unset(\$config" . $field_conv . ");";
196
		eval($text);
197
	}
198

    
199
	// Verify that the needed $config element exists. If not, create it
200
	$tsttext = 'return (isset($config' . $field_conv . '));';
201

    
202
	if (!eval($tsttext)) {
203
		config_array_from_str($field_conv);
204
	}
205

    
206
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
207
	eval($text);
208

    
209
	$thisvar = $updatetext;
210
}
211

    
212
$title	   = $pkg['step'][$stepid]['title'];
213
$description = $pkg['step'][$stepid]['description'];
214

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

    
223
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
224
$pglinks = array("", "wizard.php?xml=" . $xml);
225
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
226
$pglinks[] = ($stepid > 0 ? "wizard.php?xml=" . $xml . "&stepid=" . $stepid:'&nbsp;');
227
$shortcut_section = "Wizard";
228
include("head.inc");
229

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

    
234

    
235
	function FieldValidate(userinput, regexp, message) {
236
		if (!userinput.match(regexp)) {
237
			alert(message);
238
		}
239
	}
240

    
241
	function enablechange() {
242

    
243
	<?php
244

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

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

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

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

    
272
					}
273
				}
274

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

    
283
				print "\t" . '}' . "\n";
284
			}
285
		}
286
	?>
287

    
288
	}
289

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

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

    
297
				if (isset($field['disablefields'])) {
298
					$enablefields = explode(',', $field['disablefields']);
299
					foreach ($enablefields as $enablefield) {
300
						$enablefield = strtolower($enablefield);
301

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

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

    
361
//]]>
362
</script>
363
<?php }
364

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

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

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

    
414
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
415

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

    
433
function is_timezone($elt) {
434
	return !preg_match("/\/$/", $elt);
435
}
436

    
437
if ($title == "Reload in progress") {
438
	$ip = fixup_string("\$myurl");
439
} else {
440
	$ip = "/";
441
}
442

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

    
453
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
454
$pbclass = ($completion == 100) ? "progress-bar progress-bar-success":"progress-bar progress-bar-danger";
455
?>
456

    
457
<!-- Draw a progress bar to show step progress -->
458
<div class="progress">
459
	<div class="<?=$pbclass?>" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%; line-height: 15px;">
460
		<?php print(sprintf(gettext("Step %s of %s"), $stepid, $totalsteps-1)); ?>
461
	</div>
462
</div>
463
<br />
464

    
465
<?php
466

    
467
$form = new Form(false);
468

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

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

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

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

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

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

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

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

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

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

    
522
			eval($toeval);
523
		}
524

    
525

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

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

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

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

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

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

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

    
563
				$onchange = "";
564

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
663
				$name = strtolower($name);
664

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

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

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

    
675
				if (!is_array($config['ca'])) {
676
					$config['ca'] = array();
677
				}
678

    
679
				foreach ($config['ca'] as $ca) {
680
					$caname = htmlspecialchars($ca['descr']);
681

    
682
					if ($value == $caname) {
683
						$selected = $value;
684
					}
685

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

    
699
				$section->addInput(new Form_Select(
700
					$name,
701
					$etitle,
702
					$selected,
703
					$options
704
				))->setHelp($field['description']);
705

    
706
				break;
707
			case "cert_selection":
708
				$options = array();
709
				$selected = array();
710

    
711
				$multiple = false;
712
				$name = strtolower($name);
713

    
714
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
715

    
716
				if ($field['add_to_cert_selection'] != "") {
717
					if ($field['add_to_cert_selection'] == $value) {
718
						array_push($selected, $value);
719
					}
720

    
721
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
722
				}
723

    
724
				if (!is_array($config['cert'])) {
725
					$config['cert'] = array();
726
				}
727

    
728
				foreach ($config['cert'] as $ca) {
729
					if (stristr($ca['descr'], "webconf")) {
730
						continue;
731
					}
732

    
733
					$caname = htmlspecialchars($ca['descr']);
734

    
735
					if ($value == $caname) {
736
						array_push($selected, $value);
737
					}
738

    
739

    
740
					$canecho = 0;
741
					if ($field['cert_filter'] != "") {
742
						if (stristr($caname, $field['cert_filter']) == true) {
743
							$canecho = 1;
744
						}
745
					} else {
746
						$canecho = 1;
747
					}
748

    
749
					if ($canecho == 1) {
750
						$options[$ca['refid']] = $caname;
751
					}
752
				}
753

    
754
				$section->addInput(new Form_Select(
755
					$name,
756
					$etitle,
757
					($multiple) ? $selected:$selected[0],
758
					$options,
759
					$multiple
760
				))->setHelp($field['description']);
761

    
762
				break;
763
			case "select":
764
				if ($field['displayname']) {
765
					$etitle = $field['displayname'];
766
				} else if (!$field['dontdisplayname']) {
767
					$etitle =  fixup_string($field['name']);
768
				}
769

    
770
				if ($field['size']) {
771
					$size = " size='" . $field['size'] . "' ";
772
				}
773

    
774
				$multiple = ($field['multiple'] == "yes");
775

    
776
				if ($multiple) {
777
					$values = explode(',', $value);
778
				} else {
779
					$values = array($value);
780
				}
781

    
782
				$onchange = "";
783
				foreach ($field['options']['option'] as $opt) {
784
					if ($opt['enablefields'] != "") {
785
						$onchange = "Javascript:enableitems(this.selectedIndex);";
786
					}
787
				}
788

    
789
				$options = array();
790
				$selected = array();
791

    
792
				foreach ($field['options']['option'] as $opt) {
793
					if (in_array($opt['value'], $values)) {
794
						array_push($selected, $opt['value']);
795
					}
796

    
797
					if ($opt['displayname']) {
798
						$options[$opt['value']] = $opt['displayname'];
799
					} else {
800
						$options[$opt['value']] = $opt['name'];
801
					}
802

    
803
				}
804

    
805
				$tmpselect = new Form_Select(
806
					$name,
807
					$etitle,
808
					($multiple) ? $selected:$selected[0],
809
					$options,
810
					$multiple
811
				);
812

    
813
				$tmpselect->setHelp($field['description'])->setOnchange($onchange);
814

    
815
				if (isset($field['size'])) {
816
					$tmpselect->setAttribute('size', $field['size']);
817
				}
818

    
819
				$section->addInput($tmpselect);
820

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

    
829
				if ($field['size']) {
830
					$size = " size='" . $field['size'] . "' ";
831
				}
832

    
833
				if (isset($field['multiple'])) {
834
					$items = explode(',', $value);
835
					$name .= "[]";
836
				} else {
837
					$items = array($value);
838
				}
839

    
840
				$onchange = (isset($field['onchange']) ? "{$field['onchange']}" : '');
841

    
842
				$source = $field['source'];
843
				try{
844
					@eval("\$wizard_source_txt = &$source;");
845
				} catch (\Throwable | \Error | \Exception $e) {
846
					//do nothing
847
				}
848
				#check if show disable option is present on xml
849
				if (!is_array($wizard_source_txt)) {
850
					$wizard_source_txt = array();
851
				}
852
				if (isset($field['show_disable_value'])) {
853
					array_push($wizard_source_txt,
854
						array(
855
							($field['source_name'] ? $field['source_name'] : $name) => $field['show_disable_value'],
856
							($field['source_value'] ? $field['source_value'] : $value) => $field['show_disable_value']
857
						));
858
				}
859

    
860
				$srcoptions = array();
861
				$srcselected = array();
862

    
863
				foreach ($wizard_source_txt as $opt) {
864
					$source_name = ($field['source_name'] ? $opt[$field['source_name']] : $opt[$name]);
865
					$source_value = ($field['source_value'] ? $opt[$field['source_value']] : $opt[$value]);
866
					$srcoptions[$source_value] = $source_name;
867

    
868
					if (in_array($source_value, $items)) {
869
						array_push($srcselected, $source_value);
870
					}
871
				}
872

    
873
				$descr = (isset($field['description'])) ? $field['description'] : "";
874

    
875
				$section->addInput(new Form_Select(
876
					$name,
877
					$etitle,
878
					isset($field['multiple']) ? $srcselected : $srcselected[0],
879
					$srcoptions,
880
					isset($field['multiple'])
881
				))->setHelp($descr)->setOnchange($onchange);
882

    
883
				break;
884
			case "textarea":
885
				if ($field['displayname']) {
886
					$etitle = $field['displayname'];
887
				} else if (!$field['dontdisplayname']) {
888
					$etitle =  fixup_string($field['name']);
889
				}
890

    
891
				$section->addInput(new Form_Textarea(
892
					$name,
893
					$etitle,
894
					$value
895
				))->setHelp($field['description'])
896
				  ->setAttribute('rows', $field['rows'])
897
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
898

    
899
				break;
900
			case "submit":
901
				$form->addGlobal(new Form_Button(
902
					$name,
903
					$field['name'],
904
					null,
905
					'fa-angle-double-right'
906
				))->addClass('btn-primary');
907

    
908
				break;
909
			case "listtopic":
910
				$form->add($section);
911
				$section = new Form_Section($field['name']);
912

    
913
				break;
914
			case "subnet_select":
915
				if ($field['displayname']) {
916
					$etitle = $field['displayname'];
917
				} else /* if (!$field['dontdisplayname']) */ {
918
					$etitle =  fixup_string($field['name']);
919
				}
920

    
921
				$section->addInput(new Form_Select(
922
					$name,
923
					$etitle,
924
					$value,
925
					array_combine(range(32, 1, -1), range(32, 1, -1))
926
				))->setHelp($field['description']);
927

    
928
				break;
929
			case "timezone_select":
930
				$timezonelist = system_get_timezone_list();
931

    
932
				/* kill carriage returns */
933
				for ($x = 0; $x < count($timezonelist); $x++) {
934
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
935
				}
936

    
937
				if ($field['displayname']) {
938
					$etitle = $field['displayname'];
939
				} else if (!$field['dontdisplayname']) {
940
					$etitle =  fixup_string($field['name']);
941
				}
942

    
943
				if (!$field['dontcombinecells']) {
944
					//echo "<td class=\"vtable\">";
945
				}
946

    
947
				$section->addInput(new Form_Select(
948
					$name,
949
					$etitle,
950
					($value == "") ? $g['default_timezone'] : $value,
951
					array_combine($timezonelist, $timezonelist)
952
				))->setHelp($field['description']);
953

    
954
				break;
955
			case "checkbox":
956
				if ($field['displayname']) {
957
					$etitle = $field['displayname'];
958

    
959
				} else if (!$field['dontdisplayname']) {
960
					$etitle =  fixup_string($field['name']);
961
				}
962

    
963
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
964
					$onclick = "enablechange()";
965
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
966
					$onclick = "disablechange()";
967
				}
968

    
969
				$section->addInput(new Form_Checkbox(
970
					$name,
971
					$etitle,
972
					$field['typehint'],
973
					($value != ""),
974
					'on'
975
				))->setHelp($field['description'])
976
				  ->setOnclick($onclick);
977

    
978
				break;
979
		} // e-o-switch
980
	} // e-o-foreach (package)
981
} // e-o-if (we have fields)
982

    
983
$form->add($section);
984
print($form);
985
?>
986

    
987
<script type="text/javascript">
988
//<![CDATA[
989

    
990
		if (typeof ext_change != 'undefined') {
991
			ext_change();
992
		}
993
		if (typeof proto_change != 'undefined') {
994
			ext_change();
995
		}
996
		if (typeof proto_change != 'undefined') {
997
			proto_change();
998
		}
999

    
1000
	<?php
1001
		$isfirst = 0;
1002
		$aliases = "";
1003
		$addrisfirst = 0;
1004
		$aliasesaddr = "";
1005
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
1006
			foreach ($config['aliases']['alias'] as $alias_name) {
1007
				if ($isfirst == 1) {
1008
					$aliases .= ",";
1009
				}
1010
				$aliases .= "'" . $alias_name['name'] . "'";
1011
				$isfirst = 1;
1012
			}
1013
		}
1014
	?>
1015

    
1016
		var customarray=new Array(<?=$aliases; ?>);
1017

    
1018
		window.onload = function () {
1019

    
1020
<?php
1021
		$counter = 0;
1022
		foreach ($inputaliases as $alias) {
1023
?>
1024
			$('#' + '<?=$alias;?>').autocomplete({
1025
				source: customarray
1026
			});
1027
<?php
1028
		}
1029
?>
1030
	}
1031

    
1032
//]]>
1033
</script>
1034

    
1035
<?php
1036

    
1037
$fieldnames_array = Array();
1038
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] != "") {
1039
	// create a fieldname loop that can be used with javascript
1040
	// hide and enable features.
1041
	echo "\n<script type=\"text/javascript\">\n";
1042
	echo "//<![CDATA[\n";
1043
	echo "function disableall() {\n";
1044
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
1045
		if ($field['type'] != "submit" and $field['type'] != "listtopic") {
1046
			if (!$field['donotdisable'] != "") {
1047
				array_push($fieldnames_array, $field['name']);
1048
				$fieldname = preg_replace("/\s+/", "", $field['name']);
1049
				$fieldname = strtolower($fieldname);
1050
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
1051
			}
1052
		}
1053
	}
1054
	echo "}\ndisableall();\n";
1055
	echo "function enableitems(selectedindex) {\n";
1056
	echo "disableall();\n";
1057
	$idcounter = 0;
1058
	if ($pkg['step'][$stepid]['fields']['field'] != "") {
1059
		echo "\tswitch (selectedindex) {\n";
1060
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
1061
			if ($field['options']['option'] != "") {
1062
				foreach ($field['options']['option'] as $opt) {
1063
					if ($opt['enablefields'] != "") {
1064
						echo "\t\tcase " . $idcounter . ":\n";
1065
						$enablefields_split = explode(",", $opt['enablefields']);
1066
						foreach ($enablefields_split as $efs) {
1067
							$fieldname = preg_replace("/\s+/", "", $efs);
1068
							$fieldname = strtolower($fieldname);
1069
							if ($fieldname != "") {
1070
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
1071
								echo $onchange;
1072
							}
1073
						}
1074
						echo "\t\t\tbreak;\n";
1075
					}
1076
					$idcounter = $idcounter + 1;
1077
				}
1078
			}
1079
		}
1080
		echo "\t}\n";
1081
	}
1082
	echo "}\n";
1083
	echo "//]]>\n";
1084
	echo "</script>\n\n";
1085
}
1086
?>
1087

    
1088
<script type="text/javascript">
1089
//<![CDATA[
1090
events.push(function() {
1091
	enablechange();
1092
	disablechange();
1093
	showchange();
1094
});
1095
//]]>
1096
</script>
1097

    
1098
<?php
1099
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1100
	// handle after form display event.
1101
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1102
}
1103

    
1104
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
1105
	// handle after form display event.
1106
	echo "\n<script type=\"text/javascript\">\n";
1107
	echo "//<![CDATA[\n";
1108
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1109
	echo "//]]>\n";
1110
	echo "</script>\n\n";
1111
}
1112

    
1113
include("foot.inc");
(226-226/227)