Project

General

Profile

Download (28.9 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=Wizard Subsystem
27
##|*DESCR=Allow access to the Wizard Subsystem (e.g. Setup Wizard, OpenVPN Wizard).
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
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
145
	$field_conv = implode('/', explode("->", $field));
146
	if ($field_conv == "") {
147
		return;
148
	}
149
	if ($arraynum != "") {
150
		$field_conv .= "/{$arraynum}";
151
	}
152
	if ($unset == "yes") {
153
		config_del_path($field_conv);
154
	}
155

    
156
	if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
157
		/*
158
		 * item is a checkbox, it should have the value "on"
159
		 * if it was checked
160
		 */
161
		return;
162
	}
163

    
164
	if ($field_type == "interfaces_selection") {
165
		config_set_path($field_conv, $updatetext);
166
		return;
167
	}
168

    
169
	if ($field_type == "select") {
170
		if (is_array($updatetext)) {
171
			$updatetext = implode(',', $updatetext);
172
		}
173
	}
174

    
175
	// Verify that the needed config array element exists. If not, create it
176
	config_init_path($field_conv);
177

    
178
	config_set_path($field_conv, $updatetext);
179
}
180

    
181
$title	   = $pkg['step'][$stepid]['title'];
182
$description = $pkg['step'][$stepid]['description'];
183

    
184
// handle before form display event.
185
do {
186
	$oldstepid = $stepid;
187
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
188
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
189
	}
190
} while ($oldstepid != $stepid);
191

    
192
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
193
$pglinks = array("", "wizard.php?xml=" . $xml);
194
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
195
$pglinks[] = ($stepid > 0 ? "wizard.php?xml=" . $xml . "&stepid=" . $stepid:'&nbsp;');
196
$shortcut_section = "Wizard";
197
include("head.inc");
198

    
199
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
200
<script type="text/javascript">
201
//<![CDATA[
202

    
203

    
204
	function FieldValidate(userinput, regexp, message) {
205
		if (!userinput.match(regexp)) {
206
			alert(message);
207
		}
208
	}
209

    
210
	function enablechange() {
211

    
212
	<?php
213

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

    
218
				if (isset($field['enablefields'])) {
219
					$enablefields = explode(',', $field['enablefields']);
220
					foreach ($enablefields as $enablefield) {
221
						$enablefield = strtolower($enablefield);
222
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
223
					}
224
				}
225

    
226
				if (isset($field['checkenablefields'])) {
227
					$checkenablefields = explode(',', $field['checkenablefields']);
228
					foreach ($checkenablefields as $checkenablefield) {
229
						$checkenablefield = strtolower($checkenablefield);
230
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
231
					}
232
				}
233

    
234
				print "\t" . '} else {' . "\n";
235
				if (isset($field['enablefields'])) {
236
					$enablefields = explode(',', $field['enablefields']);
237
					foreach ($enablefields as $enablefield) {
238
						$enablefield = strtolower($enablefield);
239
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
240

    
241
					}
242
				}
243

    
244
			if (isset($field['checkdisablefields'])) {
245
				$checkenablefields = explode(',', $field['checkdisablefields']);
246
				foreach ($checkenablefields as $checkenablefield) {
247
					$checkenablefield = strtolower($checkenablefield);
248
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
249
					}
250
				}
251

    
252
				print "\t" . '}' . "\n";
253
			}
254
		}
255
	?>
256

    
257
	}
258

    
259
	function disablechange() {
260
	<?php
261
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
262
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
263

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

    
266
				if (isset($field['disablefields'])) {
267
					$enablefields = explode(',', $field['disablefields']);
268
					foreach ($enablefields as $enablefield) {
269
						$enablefield = strtolower($enablefield);
270

    
271
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
272
					}
273
				}
274
				if (isset($field['checkdisablefields'])) {
275
					$checkenablefields = explode(',', $field['checkdisablefields']);
276
					foreach ($checkenablefields as $checkenablefield) {
277
						$checkenablefield = strtolower($checkenablefield);
278
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
279
					}
280
				}
281
				print "\t" . '} else {' . "\n";
282
				if (isset($field['disablefields'])) {
283
					$enablefields = explode(',', $field['disablefields']);
284
					foreach ($enablefields as $enablefield) {
285
						$enablefield = strtolower($enablefield);
286
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
287
					}
288
				}
289
				if (isset($field['checkdisablefields'])) {
290
					$checkenablefields = explode(',', $field['checkdisablefields']);
291
					foreach ($checkenablefields as $checkenablefield) {
292
						$checkenablefield = strtolower($checkenablefield);
293
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
294
					}
295
				}
296
				print "\t" . '}' . "\n";
297
			}
298
		}
299
	?>
300
	}
301

    
302
	function showchange() {
303
<?php
304
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
305
			if (isset($field['showfields'])) {
306
				print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
307
				if (isset($field['showfields'])) {
308
					$showfields = explode(',', $field['showfields']);
309
					foreach ($showfields as $showfield) {
310
						$showfield = strtolower($showfield);
311
						//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
312
						print "\t\t $('#". $showfield . "').hide();";
313
					}
314
				}
315
				print "\t" . '} else {' . "\n";
316
				if (isset($field['showfields'])) {
317
					$showfields = explode(',', $field['showfields']);
318
					foreach ($showfields as $showfield) {
319
						$showfield = strtolower($showfield);
320
						#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
321
						print "\t\t $('#". $showfield . "').show();";
322
					}
323
				}
324
				print "\t" . '}' . "\n";
325
			}
326
		}
327
?>
328
	}
329

    
330
//]]>
331
</script>
332
<?php }
333

    
334
function fixup_string($string) {
335
	global $g, $myurl, $title;
336
	$newstring = $string;
337
	// fixup #1: $myurl -> http[s]://ip_address:port/
338
	switch (config_get_path('system/webgui/protocol')) {
339
		case "http":
340
			$proto = "http";
341
			break;
342
		case "https":
343
			$proto = "https";
344
			break;
345
		default:
346
			$proto = "http";
347
			break;
348
	}
349
	$port = config_get_path('system/webgui/port', "");
350
	if ($port != "") {
351
		if (($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
352
			$urlport = ":" . $port;
353
		} elseif ($port != "80" and $port != "443") {
354
			$urlport = ":" . $port;
355
		} else {
356
			$urlport = "";
357
		}
358
	}
359

    
360
	$http_host = $_SERVER['HTTP_HOST'];
361
	$urlhost = $http_host;
362
	$hostname = config_get_path('system/hostname');
363
	$fqdn = $hostname . '.' . config_get_path('system/domain');
364
	$wizard_hostname = config_get_path('wizardtemp/system/hostname');
365
	$wizard_fqdn = $wizard_hostname . '.' . config_get_path('wizardtempsystem/domain');
366
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
367
	if ($title == "Reload in progress") {
368
		if (is_ipaddr($urlhost)) {
369
			$host_if = find_ip_interface($urlhost);
370
			if ($host_if) {
371
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
372
				$host_if_ip = (!empty($host_if)) ? config_get_path("interfaces/{$host_if}/ipaddr") : null;
373
				if ($host_if && is_ipaddr($host_if_ip)) {
374
					$urlhost = $host_if_ip;
375
				}
376
			}
377
		} else if ($urlhost == $hostname) {
378
			$urlhost = $wizard_hostname;
379
		} else if ($urlhost == $fqdn)  {
380
			$urlhost = $wizard_fqdn;
381
		}
382
	}
383

    
384
	if ($urlhost != $http_host) {
385
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
386
	}
387

    
388
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
389

    
390
	if (strstr($newstring, "\$myurl")) {
391
		$newstring = str_replace("\$myurl", $myurl, $newstring);
392
	}
393
	// fixup #2: $wanip
394
	if (strstr($newstring, "\$wanip")) {
395
		$curwanip = get_interface_ip();
396
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
397
	}
398
	// fixup #3: $lanip
399
	if (strstr($newstring, "\$lanip")) {
400
		$lanip = get_interface_ip("lan");
401
		$newstring = str_replace("\$lanip", $lanip, $newstring);
402
	}
403
	// fixup #4: fix'r'up here.
404
	return $newstring;
405
}
406

    
407
function is_timezone($elt) {
408
	return !preg_match("/\/$/", $elt);
409
}
410

    
411
if ($title == "Reload in progress") {
412
	$ip = fixup_string("\$myurl");
413
} else {
414
	$ip = "/";
415
}
416

    
417
if ($input_errors) {
418
	print_input_errors($input_errors);
419
}
420
if ($savemsg) {
421
	print_info_box($savemsg, 'success');
422
}
423
if ($_REQUEST['message'] != "") {
424
	print_info_box(htmlspecialchars($_REQUEST['message']));
425
}
426

    
427
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
428
$pbclass = ($completion == 100) ? "progress-bar progress-bar-success":"progress-bar progress-bar-danger";
429
?>
430

    
431
<!-- Draw a progress bar to show step progress -->
432
<div class="progress">
433
	<div class="<?=$pbclass?>" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%; line-height: 15px;">
434
		<?php print(sprintf(gettext("Step %s of %s"), $stepid, $totalsteps-1)); ?>
435
	</div>
436
</div>
437
<br />
438

    
439
<?php
440

    
441
$form = new Form(false);
442

    
443
$form->addGlobal(new Form_Input(
444
	'stepid',
445
	null,
446
	'hidden',
447
	$stepid
448
));
449

    
450
$form->addGlobal(new Form_Input(
451
	'xml',
452
	null,
453
	'hidden',
454
	$xml
455
));
456

    
457
$section = new Form_Section(fixup_string($title));
458

    
459
if ($description) {
460
	$section->addInput(new Form_StaticText(
461
		null,
462
		fixup_string($description)
463
	));
464
}
465

    
466
$inputaliases = array();
467
if ($pkg['step'][$stepid]['fields']['field'] != "") {
468
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
469

    
470
		$value = $field['value'];
471
		$name  = $field['name'];
472

    
473
		$name = preg_replace("/\s+/", "", $name);
474
		$name = strtolower($name);
475

    
476
		if ($field['bindstofield'] != "") {
477
			$field_conv_path = implode('/', explode("->", $field['bindstofield']));
478
			// arraynum is used in cases where there is an array of the same field
479
			// name such as dnsserver (2 of them)
480
			if ($field['arraynum'] != "") {
481
				$field_conv_path .= "/{$field['arraynum']}";
482
			}
483

    
484
			if ($field['type'] == "checkbox") {
485
				$value = config_get_path($field_conv_path);
486
				if (empty($value)) {
487
					$value = true;
488
				}
489
			} else {
490
				if (config_get_path($field_conv_path) !== null) {
491
					$value = config_get_path($field_conv_path);
492
				}
493
			}
494
		}
495

    
496

    
497
		if (DEBUG) {
498
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
499
		}
500

    
501
		switch ($field['type']) {
502
			case "input":
503
				if ($field['displayname']) {
504
					$etitle = $field['displayname'];
505

    
506
				} else if (!$field['dontdisplayname']) {
507
					$etitle =  fixup_string($field['name']);
508
				}
509

    
510
				$section->addInput(new Form_Input(
511
					$name,
512
					$etitle,
513
					'text',
514
					$value
515
				))->setHelp($field['description'])
516
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
517

    
518
				break;
519
			case "text":
520
				$section->addInput(new Form_StaticText(
521
					null,
522
					$field['description']
523
				));
524

    
525
				break;
526
			case "inputalias":
527
				if ($field['displayname']) {
528
					$etitle = $field['displayname'];
529

    
530
				} else if (!$field['dontdisplayname']) {
531
					$etitle =  fixup_string($field['name']);
532
				}
533

    
534
				$onchange = "";
535

    
536
				if ($field['validate']) {
537
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
538
				}
539

    
540
				$section->addInput(new Form_Input(
541
					$name,
542
					$etitle,
543
					'text',
544
					$value
545
				))->setAttribute('autocomplete', 'off')
546
				  ->setOnchange($onchange)
547
				  ->setHelp($field['description']);
548

    
549
				break;
550
			case "interfaces_selection":
551
			case "interface_select":
552

    
553
				$name = strtolower($name);
554
				$options = array();
555
				$selected = array();
556

    
557
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
558

    
559
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
560
					$multiple = true;
561
				} else {
562
					$multiple = false;
563
				}
564

    
565
				if ($field['add_to_interfaces_selection'] != "") {
566
					if ($field['add_to_interfaces_selection'] == $value) {
567
						array_push($selected, $value);
568
					}
569

    
570
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
571
				}
572

    
573
				if ($field['type'] == "interface_select") {
574
					$interfaces = get_interface_list();
575
				} else {
576
					$interfaces = get_configured_interface_with_descr();
577
				}
578

    
579
				foreach ($interfaces as $ifname => $iface) {
580
					if ($field['type'] == "interface_select") {
581
						$iface = $ifname;
582
						if ($iface['mac']) {
583
							$iface .= " ({$iface['mac']})";
584
						}
585
					}
586

    
587
					if ($value == $ifname) {
588
						array_push($selected, $value);
589
					}
590

    
591
					$canecho = 0;
592
					if ($field['interface_filter'] != "") {
593
						if (stristr($ifname, $field['interface_filter']) == true) {
594
							$canecho = 1;
595
						}
596
					} else {
597
						$canecho = 1;
598
					}
599

    
600
					if ($canecho == 1) {
601
						$options[$ifname] = $iface;
602
					}
603
				}
604

    
605
				$section->addInput(new Form_Select(
606
					$name,
607
					$etitle,
608
					($multiple) ? $selected:$selected[0],
609
					$options,
610
					$multiple
611
				))->setHelp($field['description']);
612

    
613
				break;
614
			case "password":
615
				if ($field['displayname']) {
616
					$etitle = $field['displayname'];
617
				} else if (!$field['dontdisplayname']) {
618
					$etitle =  fixup_string($field['name']);
619
				}
620

    
621
				$section->addInput(new Form_Input(
622
					$name,
623
					$etitle,
624
					'password',
625
					$value
626
				))->setHelp($field['description'])
627
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
628

    
629
				break;
630
			case "certca_selection":
631
				$options = array();
632
				$selected = "";
633

    
634
				$name = strtolower($name);
635

    
636
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
637

    
638
				if ($field['add_to_certca_selection'] != "") {
639
					if ($field['add_to_certca_selection'] == $value) {
640
						$selected = $value;
641
					}
642

    
643
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
644
				}
645

    
646
				config_init_path('ca');
647

    
648
				foreach (config_get_path('ca', []) as $ca) {
649
					$caname = htmlspecialchars($ca['descr']);
650

    
651
					if ($value == $caname) {
652
						$selected = $value;
653
					}
654

    
655
					$canecho = 0;
656
					if ($field['certca_filter'] != "") {
657
						if (stristr($caname, $field['certca_filter']) == true) {
658
							$canecho = 1;
659
						}
660
					} else {
661
						$canecho = 1;
662
					}
663
					if (($field['reject_weak'] == "yes") &&
664
					    cert_has_weak_digest($ca['crt'])) {
665
						$canecho = 0;
666
					}
667
					if ($canecho == 1) {
668
						$options[$ca['refid']] = $caname;
669
					}
670
				}
671

    
672
				$section->addInput(new Form_Select(
673
					$name,
674
					$etitle,
675
					$selected,
676
					$options
677
				))->setHelp($field['description']);
678

    
679
				break;
680
			case "cert_selection":
681
				$options = array();
682
				$selected = array();
683

    
684
				$multiple = false;
685
				$name = strtolower($name);
686

    
687
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
688

    
689
				if ($field['add_to_cert_selection'] != "") {
690
					if ($field['add_to_cert_selection'] == $value) {
691
						array_push($selected, $value);
692
					}
693

    
694
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
695
				}
696

    
697
				config_init_path('cert');
698

    
699
				foreach (config_get_path('cert', []) as $ca) {
700
					if (stristr($ca['descr'], "webconf")) {
701
						continue;
702
					}
703

    
704
					$caname = htmlspecialchars($ca['descr']);
705

    
706
					if ($value == $caname) {
707
						array_push($selected, $value);
708
					}
709

    
710

    
711
					$canecho = 0;
712
					if ($field['cert_filter'] != "") {
713
						if (stristr($caname, $field['cert_filter']) == true) {
714
							$canecho = 1;
715
						}
716
					} else {
717
						$canecho = 1;
718
					}
719
					if (($field['reject_weak'] == "yes") &&
720
					    cert_has_weak_digest($ca['crt'])) {
721
						$canecho = 0;
722
					}
723

    
724
					if ($canecho == 1) {
725
						$options[$ca['refid']] = $caname;
726
					}
727
				}
728

    
729
				$section->addInput(new Form_Select(
730
					$name,
731
					$etitle,
732
					($multiple) ? $selected:$selected[0],
733
					$options,
734
					$multiple
735
				))->setHelp($field['description']);
736

    
737
				break;
738
			case "select":
739
				if ($field['displayname']) {
740
					$etitle = $field['displayname'];
741
				} else if (!$field['dontdisplayname']) {
742
					$etitle =  fixup_string($field['name']);
743
				}
744

    
745
				if ($field['size']) {
746
					$size = " size='" . $field['size'] . "' ";
747
				}
748

    
749
				$multiple = ($field['multiple'] == "yes");
750

    
751
				if ($multiple) {
752
					$values = explode(',', $value);
753
				} else {
754
					$values = array($value);
755
				}
756

    
757
				$onchange = "";
758
				foreach ($field['options']['option'] as $opt) {
759
					if ($opt['enablefields'] != "") {
760
						$onchange = "javascript:enableitems(this.selectedIndex);";
761
					}
762
				}
763

    
764
				$options = array();
765
				$selected = array();
766

    
767
				foreach ($field['options']['option'] as $opt) {
768
					if (in_array($opt['value'], $values)) {
769
						array_push($selected, $opt['value']);
770
					}
771

    
772
					if ($opt['displayname']) {
773
						$options[$opt['value']] = $opt['displayname'];
774
					} else {
775
						$options[$opt['value']] = $opt['name'];
776
					}
777

    
778
				}
779

    
780
				$tmpselect = new Form_Select(
781
					$name,
782
					$etitle,
783
					($multiple) ? $selected:$selected[0],
784
					$options,
785
					$multiple
786
				);
787

    
788
				$tmpselect->setHelp($field['description'])->setOnchange($onchange);
789

    
790
				if (isset($field['size'])) {
791
					$tmpselect->setAttribute('size', $field['size']);
792
				}
793

    
794
				$section->addInput($tmpselect);
795

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

    
804
				if ($field['size']) {
805
					$size = " size='" . $field['size'] . "' ";
806
				}
807

    
808
				if (isset($field['multiple'])) {
809
					$items = explode(',', $value);
810
					$name .= "[]";
811
				} else {
812
					$items = array($value);
813
				}
814

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

    
817
				$source = $field['source'];
818
				try{
819
					@eval("\$wizard_source_txt = &$source;");
820
				} catch (\Throwable | \Error | \Exception $e) {
821
					//do nothing
822
				}
823
				#check if show disable option is present on xml
824
				if (!is_array($wizard_source_txt)) {
825
					$wizard_source_txt = array();
826
				}
827
				if (isset($field['show_disable_value'])) {
828
					array_push($wizard_source_txt,
829
						array(
830
							($field['source_name'] ? $field['source_name'] : $name) => $field['show_disable_value'],
831
							($field['source_value'] ? $field['source_value'] : $value) => $field['show_disable_value']
832
						));
833
				}
834

    
835
				$srcoptions = array();
836
				$srcselected = array();
837

    
838
				foreach ($wizard_source_txt as $opt) {
839
					$source_name = ($field['source_name'] ? $opt[$field['source_name']] : $opt[$name]);
840
					$source_value = ($field['source_value'] ? $opt[$field['source_value']] : $opt[$value]);
841
					$srcoptions[$source_value] = $source_name;
842

    
843
					if (in_array($source_value, $items)) {
844
						array_push($srcselected, $source_value);
845
					}
846
				}
847

    
848
				$descr = (isset($field['description'])) ? $field['description'] : "";
849

    
850
				$section->addInput(new Form_Select(
851
					$name,
852
					$etitle,
853
					isset($field['multiple']) ? $srcselected : $srcselected[0],
854
					$srcoptions,
855
					isset($field['multiple'])
856
				))->setHelp($descr)->setOnchange($onchange);
857

    
858
				break;
859
			case "textarea":
860
				if ($field['displayname']) {
861
					$etitle = $field['displayname'];
862
				} else if (!$field['dontdisplayname']) {
863
					$etitle =  fixup_string($field['name']);
864
				}
865

    
866
				$section->addInput(new Form_Textarea(
867
					$name,
868
					$etitle,
869
					$value
870
				))->setHelp($field['description'])
871
				  ->setAttribute('rows', $field['rows'])
872
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
873

    
874
				break;
875
			case "textarea_source":
876
				if ($field['displayname']) {
877
					$etitle = $field['displayname'];
878
				} else if (!$field['dontdisplayname']) {
879
					$etitle =  fixup_string($field['name']);
880
				}
881

    
882
				$source = $field['source'];
883
				try{
884
					@eval("\$value = &$source;");
885
				} catch (\Throwable | \Error | \Exception $e) {
886
					log_error($e);
887
				}
888
				$input = $section->addInput(new Form_Textarea(
889
					$name,
890
					$etitle,
891
					$value
892
				))->setHelp($field['description'])
893
				  ->setAttribute('rows', $field['rows'])
894
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
895
				if ($field['readonly']) {
896
					$input->setReadonly();
897
				}
898
				break;
899
			case "submit":
900
				$form->addGlobal(new Form_Button(
901
					$name,
902
					$field['name'],
903
					null,
904
					'fa-solid fa-angle-double-right'
905
				))->addClass('btn-primary');
906

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1013
		var customarray=new Array(<?=$aliases; ?>);
1014

    
1015
		window.onload = function () {
1016

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

    
1029
//]]>
1030
</script>
1031

    
1032
<?php
1033

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

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

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

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

    
1110
include("foot.inc");
(231-231/232)
OSZAR »