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-2019 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

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

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

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

    
42
global $g;
43

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

    
46

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

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

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

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

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

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

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

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

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

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

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

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

    
122
	$stepid++;
123
}
124

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

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

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

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

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

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

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

    
196
	if (!eval($tsttext)) {
197
		config_array_from_str($field_conv);
198
	}
199

    
200
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
201
	eval($text);
202

    
203
	$thisvar = $updatetext;
204
}
205

    
206
$title	   = $pkg['step'][$stepid]['title'];
207
$description = $pkg['step'][$stepid]['description'];
208

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

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

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

    
228

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

    
235
	function enablechange() {
236

    
237
	<?php
238

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

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

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

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

    
266
					}
267
				}
268

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

    
277
				print "\t" . '}' . "\n";
278
			}
279
		}
280
	?>
281

    
282
	}
283

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

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

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

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

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

    
355
//]]>
356
</script>
357
<?php }
358

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

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

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

    
408
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
409

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

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

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

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

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

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

    
459
<?php
460

    
461
$form = new Form(false);
462

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

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

    
477
$section = new Form_Section(fixup_string($title));
478

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

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

    
490
		$value = $field['value'];
491
		$name  = $field['name'];
492

    
493
		$name = preg_replace("/\s+/", "", $name);
494
		$name = strtolower($name);
495

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

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

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

    
516
			eval($toeval);
517
		}
518

    
519

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

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

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

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

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

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

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

    
557
				$onchange = "";
558

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

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

    
572
				break;
573
			case "interfaces_selection":
574
			case "interface_select":
575

    
576
				$name = strtolower($name);
577
				$options = array();
578
				$selected = array();
579

    
580
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
581

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

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

    
593
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
594
				}
595

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

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

    
610
					if ($value == $ifname) {
611
						array_push($selected, $value);
612
					}
613

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

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

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

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

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

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

    
657
				$name = strtolower($name);
658

    
659
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
660

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

    
666
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
667
				}
668

    
669
				if (!is_array($config['ca'])) {
670
					$config['ca'] = array();
671
				}
672

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

    
676
					if ($value == $caname) {
677
						$selected = $value;
678
					}
679

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

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

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

    
705
				$multiple = false;
706
				$name = strtolower($name);
707

    
708
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
709

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

    
715
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
716
				}
717

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

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

    
727
					$caname = htmlspecialchars($ca['descr']);
728

    
729
					if ($value == $caname) {
730
						array_push($selected, $value);
731
					}
732

    
733

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

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

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

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

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

    
768
				$multiple = ($field['multiple'] == "yes");
769

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

    
777
				$options = array();
778
				$selected = array();
779

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

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

    
791
				}
792

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

    
801
				$tmpselect->setHelp($field['description'])->setOnchange($onchange);
802

    
803
				if (isset($field['size'])) {
804
					$tmpselect->setAttribute('size', $field['size']);
805
				}
806

    
807
				$section->addInput($tmpselect);
808

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

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

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

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

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

    
848
				$srcoptions = array();
849
				$srcselected = array();
850

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

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

    
861
				$descr = (isset($field['description'])) ? $field['description'] : "";
862

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

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

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

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

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

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

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

    
916
				break;
917
			case "timezone_select":
918
				$timezonelist = system_get_timezone_list();
919

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

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

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

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

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

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

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

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

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

    
971
$form->add($section);
972
print($form);
973
?>
974

    
975
<script type="text/javascript">
976
//<![CDATA[
977

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

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

    
1004
		var customarray=new Array(<?=$aliases; ?>);
1005

    
1006
		window.onload = function () {
1007

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

    
1020
//]]>
1021
</script>
1022

    
1023
<?php
1024

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

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

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

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

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