Project

General

Profile

Download (29.4 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-2024 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_get('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_get('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 $g, $myurl, $title;
367
	$newstring = $string;
368
	// fixup #1: $myurl -> http[s]://ip_address:port/
369
	switch (config_get_path('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_get_path('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
	$hostname = config_get_path('system/hostname');
394
	$fqdn = $hostname . '.' . config_get_path('system/domain');
395
	$wizard_hostname = config_get_path('wizardtemp/system/hostname');
396
	$wizard_fqdn = $wizard_hostname . '.' . config_get_path('wizardtempsystem/domain');
397
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
398
	if ($title == "Reload in progress") {
399
		if (is_ipaddr($urlhost)) {
400
			$host_if = find_ip_interface($urlhost);
401
			if ($host_if) {
402
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
403
				$host_if_ip = config_get_path("interfaces/{$host_if}/ipaddr");
404
				if ($host_if && is_ipaddr($host_if_ip)) {
405
					$urlhost = $host_if_ip;
406
				}
407
			}
408
		} else if ($urlhost == $hostname) {
409
			$urlhost = $wizard_hostname;
410
		} else if ($urlhost == $fqdn)  {
411
			$urlhost = $wizard_fqdn;
412
		}
413
	}
414

    
415
	if ($urlhost != $http_host) {
416
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
417
	}
418

    
419
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
420

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

    
438
function is_timezone($elt) {
439
	return !preg_match("/\/$/", $elt);
440
}
441

    
442
if ($title == "Reload in progress") {
443
	$ip = fixup_string("\$myurl");
444
} else {
445
	$ip = "/";
446
}
447

    
448
if ($input_errors) {
449
	print_input_errors($input_errors);
450
}
451
if ($savemsg) {
452
	print_info_box($savemsg, 'success');
453
}
454
if ($_REQUEST['message'] != "") {
455
	print_info_box(htmlspecialchars($_REQUEST['message']));
456
}
457

    
458
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
459
$pbclass = ($completion == 100) ? "progress-bar progress-bar-success":"progress-bar progress-bar-danger";
460
?>
461

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

    
470
<?php
471

    
472
$form = new Form(false);
473

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

    
481
$form->addGlobal(new Form_Input(
482
	'xml',
483
	null,
484
	'hidden',
485
	$xml
486
));
487

    
488
$section = new Form_Section(fixup_string($title));
489

    
490
if ($description) {
491
	$section->addInput(new Form_StaticText(
492
		null,
493
		fixup_string($description)
494
	));
495
}
496

    
497
$inputaliases = array();
498
if ($pkg['step'][$stepid]['fields']['field'] != "") {
499
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
500

    
501
		$value = $field['value'];
502
		$name  = $field['name'];
503

    
504
		$name = preg_replace("/\s+/", "", $name);
505
		$name = strtolower($name);
506

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

    
517
			foreach ($field_split as $f) {
518
				$field_conv .= "['" . $f . "']";
519
			}
520

    
521
			if ($field['type'] == "checkbox") {
522
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
523
			} else {
524
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
525
			}
526

    
527
			eval($toeval);
528
		}
529

    
530

    
531
		if (DEBUG) {
532
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
533
		}
534

    
535
		switch ($field['type']) {
536
			case "input":
537
				if ($field['displayname']) {
538
					$etitle = $field['displayname'];
539

    
540
				} else if (!$field['dontdisplayname']) {
541
					$etitle =  fixup_string($field['name']);
542
				}
543

    
544
				$section->addInput(new Form_Input(
545
					$name,
546
					$etitle,
547
					'text',
548
					$value
549
				))->setHelp($field['description'])
550
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
551

    
552
				break;
553
			case "text":
554
				$section->addInput(new Form_StaticText(
555
					null,
556
					$field['description']
557
				));
558

    
559
				break;
560
			case "inputalias":
561
				if ($field['displayname']) {
562
					$etitle = $field['displayname'];
563

    
564
				} else if (!$field['dontdisplayname']) {
565
					$etitle =  fixup_string($field['name']);
566
				}
567

    
568
				$onchange = "";
569

    
570
				if ($field['validate']) {
571
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
572
				}
573

    
574
				$section->addInput(new Form_Input(
575
					$name,
576
					$etitle,
577
					'text',
578
					$value
579
				))->setAttribute('autocomplete', 'off')
580
				  ->setOnchange($onchange)
581
				  ->setHelp($field['description']);
582

    
583
				break;
584
			case "interfaces_selection":
585
			case "interface_select":
586

    
587
				$name = strtolower($name);
588
				$options = array();
589
				$selected = array();
590

    
591
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
592

    
593
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
594
					$multiple = true;
595
				} else {
596
					$multiple = false;
597
				}
598

    
599
				if ($field['add_to_interfaces_selection'] != "") {
600
					if ($field['add_to_interfaces_selection'] == $value) {
601
						array_push($selected, $value);
602
					}
603

    
604
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
605
				}
606

    
607
				if ($field['type'] == "interface_select") {
608
					$interfaces = get_interface_list();
609
				} else {
610
					$interfaces = get_configured_interface_with_descr();
611
				}
612

    
613
				foreach ($interfaces as $ifname => $iface) {
614
					if ($field['type'] == "interface_select") {
615
						$iface = $ifname;
616
						if ($iface['mac']) {
617
							$iface .= " ({$iface['mac']})";
618
						}
619
					}
620

    
621
					if ($value == $ifname) {
622
						array_push($selected, $value);
623
					}
624

    
625
					$canecho = 0;
626
					if ($field['interface_filter'] != "") {
627
						if (stristr($ifname, $field['interface_filter']) == true) {
628
							$canecho = 1;
629
						}
630
					} else {
631
						$canecho = 1;
632
					}
633

    
634
					if ($canecho == 1) {
635
						$options[$ifname] = $iface;
636
					}
637
				}
638

    
639
				$section->addInput(new Form_Select(
640
					$name,
641
					$etitle,
642
					($multiple) ? $selected:$selected[0],
643
					$options,
644
					$multiple
645
				))->setHelp($field['description']);
646

    
647
				break;
648
			case "password":
649
				if ($field['displayname']) {
650
					$etitle = $field['displayname'];
651
				} else if (!$field['dontdisplayname']) {
652
					$etitle =  fixup_string($field['name']);
653
				}
654

    
655
				$section->addInput(new Form_Input(
656
					$name,
657
					$etitle,
658
					'password',
659
					$value
660
				))->setHelp($field['description'])
661
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
662

    
663
				break;
664
			case "certca_selection":
665
				$options = array();
666
				$selected = "";
667

    
668
				$name = strtolower($name);
669

    
670
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
671

    
672
				if ($field['add_to_certca_selection'] != "") {
673
					if ($field['add_to_certca_selection'] == $value) {
674
						$selected = $value;
675
					}
676

    
677
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
678
				}
679

    
680
				if (!is_array($config['ca'])) {
681
					config_set_path('ca', array());
682
				}
683

    
684
				foreach (config_get_path('ca', []) as $ca) {
685
					$caname = htmlspecialchars($ca['descr']);
686

    
687
					if ($value == $caname) {
688
						$selected = $value;
689
					}
690

    
691
					$canecho = 0;
692
					if ($field['certca_filter'] != "") {
693
						if (stristr($caname, $field['certca_filter']) == true) {
694
							$canecho = 1;
695
						}
696
					} else {
697
						$canecho = 1;
698
					}
699
					if (($field['reject_weak'] == "yes") &&
700
					    cert_has_weak_digest($ca['crt'])) {
701
						$canecho = 0;
702
					}
703
					if ($canecho == 1) {
704
						$options[$ca['refid']] = $caname;
705
					}
706
				}
707

    
708
				$section->addInput(new Form_Select(
709
					$name,
710
					$etitle,
711
					$selected,
712
					$options
713
				))->setHelp($field['description']);
714

    
715
				break;
716
			case "cert_selection":
717
				$options = array();
718
				$selected = array();
719

    
720
				$multiple = false;
721
				$name = strtolower($name);
722

    
723
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
724

    
725
				if ($field['add_to_cert_selection'] != "") {
726
					if ($field['add_to_cert_selection'] == $value) {
727
						array_push($selected, $value);
728
					}
729

    
730
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
731
				}
732

    
733
				if (!is_array($config['cert'])) {
734
					config_set_path('cert', array());
735
				}
736

    
737
				foreach (config_get_path('cert', []) as $ca) {
738
					if (stristr($ca['descr'], "webconf")) {
739
						continue;
740
					}
741

    
742
					$caname = htmlspecialchars($ca['descr']);
743

    
744
					if ($value == $caname) {
745
						array_push($selected, $value);
746
					}
747

    
748

    
749
					$canecho = 0;
750
					if ($field['cert_filter'] != "") {
751
						if (stristr($caname, $field['cert_filter']) == true) {
752
							$canecho = 1;
753
						}
754
					} else {
755
						$canecho = 1;
756
					}
757
					if (($field['reject_weak'] == "yes") &&
758
					    cert_has_weak_digest($ca['crt'])) {
759
						$canecho = 0;
760
					}
761

    
762
					if ($canecho == 1) {
763
						$options[$ca['refid']] = $caname;
764
					}
765
				}
766

    
767
				$section->addInput(new Form_Select(
768
					$name,
769
					$etitle,
770
					($multiple) ? $selected:$selected[0],
771
					$options,
772
					$multiple
773
				))->setHelp($field['description']);
774

    
775
				break;
776
			case "select":
777
				if ($field['displayname']) {
778
					$etitle = $field['displayname'];
779
				} else if (!$field['dontdisplayname']) {
780
					$etitle =  fixup_string($field['name']);
781
				}
782

    
783
				if ($field['size']) {
784
					$size = " size='" . $field['size'] . "' ";
785
				}
786

    
787
				$multiple = ($field['multiple'] == "yes");
788

    
789
				if ($multiple) {
790
					$values = explode(',', $value);
791
				} else {
792
					$values = array($value);
793
				}
794

    
795
				$onchange = "";
796
				foreach ($field['options']['option'] as $opt) {
797
					if ($opt['enablefields'] != "") {
798
						$onchange = "javascript:enableitems(this.selectedIndex);";
799
					}
800
				}
801

    
802
				$options = array();
803
				$selected = array();
804

    
805
				foreach ($field['options']['option'] as $opt) {
806
					if (in_array($opt['value'], $values)) {
807
						array_push($selected, $opt['value']);
808
					}
809

    
810
					if ($opt['displayname']) {
811
						$options[$opt['value']] = $opt['displayname'];
812
					} else {
813
						$options[$opt['value']] = $opt['name'];
814
					}
815

    
816
				}
817

    
818
				$tmpselect = new Form_Select(
819
					$name,
820
					$etitle,
821
					($multiple) ? $selected:$selected[0],
822
					$options,
823
					$multiple
824
				);
825

    
826
				$tmpselect->setHelp($field['description'])->setOnchange($onchange);
827

    
828
				if (isset($field['size'])) {
829
					$tmpselect->setAttribute('size', $field['size']);
830
				}
831

    
832
				$section->addInput($tmpselect);
833

    
834
				break;
835
			case "select_source":
836
				if ($field['displayname']) {
837
					$etitle = $field['displayname'];
838
				} else if (!$field['dontdisplayname']) {
839
					$etitle =  fixup_string($name);
840
				}
841

    
842
				if ($field['size']) {
843
					$size = " size='" . $field['size'] . "' ";
844
				}
845

    
846
				if (isset($field['multiple'])) {
847
					$items = explode(',', $value);
848
					$name .= "[]";
849
				} else {
850
					$items = array($value);
851
				}
852

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

    
855
				$source = $field['source'];
856
				try{
857
					@eval("\$wizard_source_txt = &$source;");
858
				} catch (\Throwable | \Error | \Exception $e) {
859
					//do nothing
860
				}
861
				#check if show disable option is present on xml
862
				if (!is_array($wizard_source_txt)) {
863
					$wizard_source_txt = array();
864
				}
865
				if (isset($field['show_disable_value'])) {
866
					array_push($wizard_source_txt,
867
						array(
868
							($field['source_name'] ? $field['source_name'] : $name) => $field['show_disable_value'],
869
							($field['source_value'] ? $field['source_value'] : $value) => $field['show_disable_value']
870
						));
871
				}
872

    
873
				$srcoptions = array();
874
				$srcselected = array();
875

    
876
				foreach ($wizard_source_txt as $opt) {
877
					$source_name = ($field['source_name'] ? $opt[$field['source_name']] : $opt[$name]);
878
					$source_value = ($field['source_value'] ? $opt[$field['source_value']] : $opt[$value]);
879
					$srcoptions[$source_value] = $source_name;
880

    
881
					if (in_array($source_value, $items)) {
882
						array_push($srcselected, $source_value);
883
					}
884
				}
885

    
886
				$descr = (isset($field['description'])) ? $field['description'] : "";
887

    
888
				$section->addInput(new Form_Select(
889
					$name,
890
					$etitle,
891
					isset($field['multiple']) ? $srcselected : $srcselected[0],
892
					$srcoptions,
893
					isset($field['multiple'])
894
				))->setHelp($descr)->setOnchange($onchange);
895

    
896
				break;
897
			case "textarea":
898
				if ($field['displayname']) {
899
					$etitle = $field['displayname'];
900
				} else if (!$field['dontdisplayname']) {
901
					$etitle =  fixup_string($field['name']);
902
				}
903

    
904
				$section->addInput(new Form_Textarea(
905
					$name,
906
					$etitle,
907
					$value
908
				))->setHelp($field['description'])
909
				  ->setAttribute('rows', $field['rows'])
910
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
911

    
912
				break;
913
			case "submit":
914
				$form->addGlobal(new Form_Button(
915
					$name,
916
					$field['name'],
917
					null,
918
					'fa-solid fa-angle-double-right'
919
				))->addClass('btn-primary');
920

    
921
				break;
922
			case "listtopic":
923
				$form->add($section);
924
				$section = new Form_Section($field['name']);
925

    
926
				break;
927
			case "subnet_select":
928
				if ($field['displayname']) {
929
					$etitle = $field['displayname'];
930
				} else /* if (!$field['dontdisplayname']) */ {
931
					$etitle =  fixup_string($field['name']);
932
				}
933

    
934
				$section->addInput(new Form_Select(
935
					$name,
936
					$etitle,
937
					$value,
938
					array_combine(range(32, 1, -1), range(32, 1, -1))
939
				))->setHelp($field['description']);
940

    
941
				break;
942
			case "timezone_select":
943
				$timezonelist = system_get_timezone_list();
944

    
945
				/* kill carriage returns */
946
				for ($x = 0; $x < count($timezonelist); $x++) {
947
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
948
				}
949

    
950
				if ($field['displayname']) {
951
					$etitle = $field['displayname'];
952
				} else if (!$field['dontdisplayname']) {
953
					$etitle =  fixup_string($field['name']);
954
				}
955

    
956
				if (!$field['dontcombinecells']) {
957
					//echo "<td class=\"vtable\">";
958
				}
959

    
960
				$section->addInput(new Form_Select(
961
					$name,
962
					$etitle,
963
					($value == "") ? g_get('default_timezone') : $value,
964
					array_combine($timezonelist, $timezonelist)
965
				))->setHelp($field['description']);
966

    
967
				break;
968
			case "checkbox":
969
				if ($field['displayname']) {
970
					$etitle = $field['displayname'];
971

    
972
				} else if (!$field['dontdisplayname']) {
973
					$etitle =  fixup_string($field['name']);
974
				}
975

    
976
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
977
					$onclick = "enablechange()";
978
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
979
					$onclick = "disablechange()";
980
				}
981

    
982
				$section->addInput(new Form_Checkbox(
983
					$name,
984
					$etitle,
985
					$field['typehint'],
986
					($value != ""),
987
					'on'
988
				))->setHelp($field['description'])
989
				  ->setOnclick($onclick);
990

    
991
				break;
992
		} // e-o-switch
993
	} // e-o-foreach (package)
994
} // e-o-if (we have fields)
995

    
996
$form->add($section);
997
print($form);
998
?>
999

    
1000
<script type="text/javascript">
1001
//<![CDATA[
1002

    
1003
		if (typeof ext_change != 'undefined') {
1004
			ext_change();
1005
		}
1006
		if (typeof proto_change != 'undefined') {
1007
			ext_change();
1008
		}
1009
		if (typeof proto_change != 'undefined') {
1010
			proto_change();
1011
		}
1012

    
1013
	<?php
1014
		$isfirst = 0;
1015
		$aliases = "";
1016
		$addrisfirst = 0;
1017
		$aliasesaddr = "";
1018
		foreach (config_get_path('aliases/alias', []) as $alias_name) {
1019
			if ($isfirst == 1) {
1020
				$aliases .= ",";
1021
			}
1022
			$aliases .= "'" . $alias_name['name'] . "'";
1023
			$isfirst = 1;
1024
		}
1025
	?>
1026

    
1027
		var customarray=new Array(<?=$aliases; ?>);
1028

    
1029
		window.onload = function () {
1030

    
1031
<?php
1032
		$counter = 0;
1033
		foreach ($inputaliases as $alias) {
1034
?>
1035
			$('#' + '<?=$alias;?>').autocomplete({
1036
				source: customarray
1037
			});
1038
<?php
1039
		}
1040
?>
1041
	}
1042

    
1043
//]]>
1044
</script>
1045

    
1046
<?php
1047

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

    
1099
<script type="text/javascript">
1100
//<![CDATA[
1101
events.push(function() {
1102
	enablechange();
1103
	disablechange();
1104
	showchange();
1105
});
1106
//]]>
1107
</script>
1108

    
1109
<?php
1110
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1111
	// handle after form display event.
1112
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1113
}
1114

    
1115
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
1116
	// handle after form display event.
1117
	echo "\n<script type=\"text/javascript\">\n";
1118
	echo "//<![CDATA[\n";
1119
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1120
	echo "//]]>\n";
1121
	echo "</script>\n\n";
1122
}
1123

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