Project

General

Profile

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

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

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

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

    
40
global $g;
41

    
42
$stepid = htmlspecialchars($_REQUEST['stepid']);
43

    
44

    
45
if (!$stepid) {
46
	$stepid = "0";
47
}
48

    
49
$xml = htmlspecialchars($_REQUEST['xml']);
50

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

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

    
75
$totalsteps = $pkg['totalsteps'];
76

    
77
if ($pkg['includefile']) {
78
	require_once($pkg['includefile']);
79
}
80

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

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

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

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

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

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

    
120
	$stepid++;
121
}
122

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

    
138
if ($stepid > $totalsteps) {
139
	$stepid = $totalsteps;
140
}
141

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

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

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

    
186
	if ($unset == "yes") {
187
		$text = "unset(\$config" . $field_conv . ");";
188
		eval($text);
189
	}
190

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

    
194
	if (!eval($tsttext)) {
195
		config_array_from_str($field_conv);
196
	}
197

    
198
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
199
	eval($text);
200

    
201
	$thisvar = $updatetext;
202
}
203

    
204
$title	   = $pkg['step'][$stepid]['title'];
205
$description = $pkg['step'][$stepid]['description'];
206

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

    
215
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
216
$pglinks = array("", "wizard.php?xml=" . $xml);
217
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
218
$pglinks[] = ($stepid > 0 ? "wizard.php?xml=" . $xml . "&stepid=" . $stepid:'&nbsp;');
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 ($_REQUEST['message'] != "") {
442
	print_info_box(htmlspecialchars($_REQUEST['message']));
443
}
444

    
445
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
446
$pbclass = ($completion == 100) ? "progress-bar progress-bar-success":"progress-bar progress-bar-danger";
447
?>
448

    
449
<!-- Draw a progress bar to show step progress -->
450
<div class="progress">
451
	<div class="<?=$pbclass?>" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%; line-height: 15px;">
452
		<?php print(sprintf(gettext("Step %s of %s"), $stepid, $totalsteps-1)); ?>
453
	</div>
454
</div>
455
<br />
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
				if (!is_array($config['ca'])) {
668
					$config['ca'] = array();
669
				}
670

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

    
674
					if ($value == $caname) {
675
						$selected = $value;
676
					}
677

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

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

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

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

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

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

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

    
716
				if (!is_array($config['cert'])) {
717
					$config['cert'] = array();
718
				}
719

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

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

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

    
731

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

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

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

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

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

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

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

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

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

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

    
789
				}
790

    
791
				$tmpselect = new Form_Select(
792
					$name,
793
					$etitle,
794
					($multiple) ? $selected:$selected[0],
795
					$options,
796
					$multiple
797
				);
798

    
799
				$tmpselect->setHelp($field['description'])->setOnchange($onchange);
800

    
801
				if (is_set($field['size'])) {
802
					$tmpselect->setAttribute('size', $field['size']);
803
				}
804

    
805
				$section->addInput($tmpselect);
806

    
807
				break;
808
			case "select_source":
809
				if ($field['displayname']) {
810
					$etitle = $field['displayname'];
811
				} else if (!$field['dontdisplayname']) {
812
					$etitle =  fixup_string($name);
813
				}
814

    
815
				if ($field['size']) {
816
					$size = " size='" . $field['size'] . "' ";
817
				}
818

    
819
				if (isset($field['multiple'])) {
820
					$items = explode(',', $value);
821
					$name .= "[]";
822
				} else {
823
					$items = array($value);
824
				}
825

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

    
828
				$source = $field['source'];
829
				try{
830
					@eval("\$wizard_source_txt = &$source;");
831
				} catch (\Throwable | \Error | \Exception $e) {
832
					//do nothing
833
				}
834
				#check if show disable option is present on xml
835
				if (!is_array($wizard_source_txt)) {
836
					$wizard_source_txt = array();
837
				}
838
				if (isset($field['show_disable_value'])) {
839
					array_push($wizard_source_txt,
840
						array(
841
							($field['source_name'] ? $field['source_name'] : $name) => $field['show_disable_value'],
842
							($field['source_value'] ? $field['source_value'] : $value) => $field['show_disable_value']
843
						));
844
				}
845

    
846
				$srcoptions = array();
847
				$srcselected = array();
848

    
849
				foreach ($wizard_source_txt as $opt) {
850
					$source_name = ($field['source_name'] ? $opt[$field['source_name']] : $opt[$name]);
851
					$source_value = ($field['source_value'] ? $opt[$field['source_value']] : $opt[$value]);
852
					$srcoptions[$source_value] = $source_name;
853

    
854
					if (in_array($source_value, $items)) {
855
						array_push($srcselected, $source_value);
856
					}
857
				}
858

    
859
				$descr = (isset($field['description'])) ? $field['description'] : "";
860

    
861
				$section->addInput(new Form_Select(
862
					$name,
863
					$etitle,
864
					isset($field['multiple']) ? $srcselected : $srcselected[0],
865
					$srcoptions,
866
					isset($field['multiple'])
867
				))->setHelp($descr)->setOnchange($onchange);
868

    
869
				break;
870
			case "textarea":
871
				if ($field['displayname']) {
872
					$etitle = $field['displayname'];
873
				} else if (!$field['dontdisplayname']) {
874
					$etitle =  fixup_string($field['name']);
875
				}
876

    
877
				$section->addInput(new Form_Textarea(
878
					$name,
879
					$etitle,
880
					$value
881
				))->setHelp($field['description'])
882
				  ->setAttribute('rows', $field['rows'])
883
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
884

    
885
				break;
886
			case "submit":
887
				$form->addGlobal(new Form_Button(
888
					$name,
889
					$field['name'],
890
					null,
891
					'fa-angle-double-right'
892
				))->addClass('btn-primary');
893

    
894
				break;
895
			case "listtopic":
896
				$form->add($section);
897
				$section = new Form_Section($field['name']);
898

    
899
				break;
900
			case "subnet_select":
901
				if ($field['displayname']) {
902
					$etitle = $field['displayname'];
903
				} else /* if (!$field['dontdisplayname']) */ {
904
					$etitle =  fixup_string($field['name']);
905
				}
906

    
907
				$section->addInput(new Form_Select(
908
					$name,
909
					$etitle,
910
					$value,
911
					array_combine(range(32, 1, -1), range(32, 1, -1))
912
				))->setHelp($field['description']);
913

    
914
				break;
915
			case "timezone_select":
916
				$timezonelist = system_get_timezone_list();
917

    
918
				/* kill carriage returns */
919
				for ($x = 0; $x < count($timezonelist); $x++) {
920
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
921
				}
922

    
923
				if ($field['displayname']) {
924
					$etitle = $field['displayname'];
925
				} else if (!$field['dontdisplayname']) {
926
					$etitle =  fixup_string($field['name']);
927
				}
928

    
929
				if (!$field['dontcombinecells']) {
930
					//echo "<td class=\"vtable\">";
931
				}
932

    
933
				$section->addInput(new Form_Select(
934
					$name,
935
					$etitle,
936
					($value == "") ? $g['default_timezone'] : $value,
937
					array_combine($timezonelist, $timezonelist)
938
				))->setHelp($field['description']);
939

    
940
				break;
941
			case "checkbox":
942
				if ($field['displayname']) {
943
					$etitle = $field['displayname'];
944

    
945
				} else if (!$field['dontdisplayname']) {
946
					$etitle =  fixup_string($field['name']);
947
				}
948

    
949
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
950
					$onclick = "enablechange()";
951
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
952
					$onclick = "disablechange()";
953
				}
954

    
955
				$section->addInput(new Form_Checkbox(
956
					$name,
957
					$etitle,
958
					$field['typehint'],
959
					($value != ""),
960
					'on'
961
				))->setHelp($field['description'])
962
				  ->setOnclick($onclick);
963

    
964
				break;
965
		} // e-o-switch
966
	} // e-o-foreach (package)
967
} // e-o-if (we have fields)
968

    
969
$form->add($section);
970
print($form);
971
?>
972

    
973
<script type="text/javascript">
974
//<![CDATA[
975

    
976
		if (typeof ext_change != 'undefined') {
977
			ext_change();
978
		}
979
		if (typeof proto_change != 'undefined') {
980
			ext_change();
981
		}
982
		if (typeof proto_change != 'undefined') {
983
			proto_change();
984
		}
985

    
986
	<?php
987
		$isfirst = 0;
988
		$aliases = "";
989
		$addrisfirst = 0;
990
		$aliasesaddr = "";
991
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
992
			foreach ($config['aliases']['alias'] as $alias_name) {
993
				if ($isfirst == 1) {
994
					$aliases .= ",";
995
				}
996
				$aliases .= "'" . $alias_name['name'] . "'";
997
				$isfirst = 1;
998
			}
999
		}
1000
	?>
1001

    
1002
		var customarray=new Array(<?=$aliases; ?>);
1003

    
1004
		window.onload = function () {
1005

    
1006
<?php
1007
		$counter = 0;
1008
		foreach ($inputaliases as $alias) {
1009
?>
1010
			$('#' + '<?=$alias;?>').autocomplete({
1011
				source: customarray
1012
			});
1013
<?php
1014
		}
1015
?>
1016
	}
1017

    
1018
//]]>
1019
</script>
1020

    
1021
<?php
1022

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

    
1074
<script type="text/javascript">
1075
//<![CDATA[
1076
events.push(function() {
1077
	enablechange();
1078
	disablechange();
1079
	showchange();
1080
});
1081
//]]>
1082
</script>
1083

    
1084
<?php
1085
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1086
	// handle after form display event.
1087
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1088
}
1089

    
1090
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
1091
	// handle after form display event.
1092
	echo "\n<script type=\"text/javascript\">\n";
1093
	echo "//<![CDATA[\n";
1094
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1095
	echo "//]]>\n";
1096
	echo "</script>\n\n";
1097
}
1098

    
1099
include("foot.inc");
(233-233/234)