Project

General

Profile

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

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

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

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

    
40
global $g;
41

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

    
44

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

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

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

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

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

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

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

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

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

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

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

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

    
120
	$stepid++;
121
}
122

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

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

    
142
$title = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
143
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
144

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

    
169
	if ($field_type == "interfaces_selection") {
170
		$var = "\$config{$field_conv}";
171
		$text = "if (isset({$var})) unset({$var});";
172
		$text .= "\$thisvar = &\$config" . $field_conv . ";";
173
		eval($text);
174
		$thisvar = $updatetext;
175
		return;
176
	}
177

    
178
	if ($unset == "yes") {
179
		$text = "unset(\$config" . $field_conv . ");";
180
		eval($text);
181
	}
182
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
183
	eval($text);
184
	$thisvar = $updatetext;
185
}
186

    
187
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
188
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
189

    
190
// handle before form display event.
191
do {
192
	$oldstepid = $stepid;
193
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
194
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
195
	}
196
} while ($oldstepid != $stepid);
197

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

    
205
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
206
<script type="text/javascript">
207
//<![CDATA[
208

    
209

    
210
	function FieldValidate(userinput, regexp, message) {
211
		if (!userinput.match(regexp)) {
212
			alert(message);
213
		}
214
	}
215

    
216
	function enablechange() {
217

    
218
	<?php
219

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

    
224
				if (isset($field['enablefields'])) {
225
					$enablefields = explode(',', $field['enablefields']);
226
					foreach ($enablefields as $enablefield) {
227
						$enablefield = strtolower($enablefield);
228
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
229
					}
230
				}
231

    
232
				if (isset($field['checkenablefields'])) {
233
					$checkenablefields = explode(',', $field['checkenablefields']);
234
					foreach ($checkenablefields as $checkenablefield) {
235
						$checkenablefield = strtolower($checkenablefield);
236
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
237
					}
238
				}
239

    
240
				print "\t" . '} else {' . "\n";
241
				if (isset($field['enablefields'])) {
242
					$enablefields = explode(',', $field['enablefields']);
243
					foreach ($enablefields as $enablefield) {
244
						$enablefield = strtolower($enablefield);
245
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
246

    
247
					}
248
				}
249

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

    
258
				print "\t" . '}' . "\n";
259
			}
260
		}
261
	?>
262

    
263
	}
264

    
265
	function disablechange() {
266
	<?php
267
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
268
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
269

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

    
272
				if (isset($field['disablefields'])) {
273
					$enablefields = explode(',', $field['disablefields']);
274
					foreach ($enablefields as $enablefield) {
275
						$enablefield = strtolower($enablefield);
276

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

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

    
336
//]]>
337
</script>
338
<?php }
339

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

    
366
	$http_host = $_SERVER['HTTP_HOST'];
367
	$urlhost = $http_host;
368
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
369
	if ($title == "Reload in progress") {
370
		if (is_ipaddr($urlhost)) {
371
			$host_if = find_ip_interface($urlhost);
372
			if ($host_if) {
373
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
374
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) {
375
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
376
				}
377
			}
378
		} else if ($urlhost == $config['system']['hostname']) {
379
			$urlhost = $config['wizardtemp']['system']['hostname'];
380
		} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
381
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
382
		}
383
	}
384

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

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

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

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

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

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

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

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

    
440
<?php
441

    
442
$form = new Form(false);
443

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

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

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

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

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

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

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

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

    
487
			foreach ($field_split as $f) {
488
				$field_conv .= "['" . $f . "']";
489
			}
490

    
491
			if ($field['type'] == "checkbox") {
492
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
493
			} else {
494
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
495
			}
496

    
497
			eval($toeval);
498
		}
499

    
500

    
501
		if (DEBUG) {
502
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
503
		}
504

    
505
		switch ($field['type']) {
506
			case "input":
507
				if ($field['displayname']) {
508
					$etitle = $field['displayname'];
509

    
510
				} else if (!$field['dontdisplayname']) {
511
					$etitle =  fixup_string($field['name']);
512
				}
513

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

    
522
				break;
523
			case "text":
524
				$section->addInput(new Form_StaticText(
525
					null,
526
					$field['description']
527
				));
528

    
529
				break;
530
			case "inputalias":
531
				if ($field['displayname']) {
532
					$etitle = $field['displayname'];
533

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

    
538
				$onchange = "";
539

    
540
				if ($field['validate']) {
541
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
542
				}
543

    
544
				$section->addInput(new Form_Input(
545
					$name,
546
					$etitle,
547
					'text',
548
					$value
549
				))->setAttribute('autocomplete', 'off')
550
				  ->setOnchange($onchange)
551
				  ->setHelp($field['description']);
552

    
553
				break;
554
			case "interfaces_selection":
555
			case "interface_select":
556

    
557
				$name = strtolower($name);
558
				$options = array();
559
				$selected = array();
560

    
561
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
562

    
563
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
564
					$multiple = true;
565
				} else {
566
					$multiple = false;
567
				}
568

    
569
				if ($field['add_to_interfaces_selection'] != "") {
570
					if ($field['add_to_interfaces_selection'] == $value) {
571
						array_push($selected, $value);
572
					}
573

    
574
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
575
				}
576

    
577
				if ($field['type'] == "interface_select") {
578
					$interfaces = get_interface_list();
579
				} else {
580
					$interfaces = get_configured_interface_with_descr();
581
				}
582

    
583
				foreach ($interfaces as $ifname => $iface) {
584
					if ($field['type'] == "interface_select") {
585
						$iface = $ifname;
586
						if ($iface['mac']) {
587
							$iface .= " ({$iface['mac']})";
588
						}
589
					}
590

    
591
					if ($value == $ifname) {
592
						array_push($selected, $value);
593
					}
594

    
595
					$canecho = 0;
596
					if ($field['interface_filter'] != "") {
597
						if (stristr($ifname, $field['interface_filter']) == true) {
598
							$canecho = 1;
599
						}
600
					} else {
601
						$canecho = 1;
602
					}
603

    
604
					if ($canecho == 1) {
605
						$options[$ifname] = $iface;
606
					}
607
				}
608

    
609
				$section->addInput(new Form_Select(
610
					$name,
611
					$etitle,
612
					($multiple) ? $selected:$selected[0],
613
					$options,
614
					$multiple
615
				))->setHelp($field['description']);
616

    
617
				break;
618
			case "password":
619
				if ($field['displayname']) {
620
					$etitle = $field['displayname'];
621
				} else if (!$field['dontdisplayname']) {
622
					$etitle =  fixup_string($field['name']);
623
				}
624

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

    
633
				break;
634
			case "certca_selection":
635
				$options = array();
636
				$selected = "";
637

    
638
				$name = strtolower($name);
639

    
640
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
641

    
642
				if ($field['add_to_certca_selection'] != "") {
643
					if ($field['add_to_certca_selection'] == $value) {
644
						$selected = $value;
645
					}
646

    
647
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
648
				}
649

    
650
				foreach ($config['ca'] as $ca) {
651
					$caname = htmlspecialchars($ca['descr']);
652

    
653
					if ($value == $caname) {
654
						$selected = $value;
655
					}
656

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

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

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

    
682
				$multiple = false;
683
				$name = strtolower($name);
684

    
685
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
686

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

    
692
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
693
				}
694

    
695
				foreach ($config['cert'] as $ca) {
696
					if (stristr($ca['descr'], "webconf")) {
697
						continue;
698
					}
699

    
700
					$caname = htmlspecialchars($ca['descr']);
701

    
702
					if ($value == $caname) {
703
						array_push($selected, $value);
704
					}
705

    
706

    
707
					$canecho = 0;
708
					if ($field['cert_filter'] != "") {
709
						if (stristr($caname, $field['cert_filter']) == true) {
710
							$canecho = 1;
711
						}
712
					} else {
713
						$canecho = 1;
714
					}
715

    
716
					if ($canecho == 1) {
717
						$options[$ca['refid']] = $caname;
718
					}
719
				}
720

    
721
				$section->addInput(new Form_Select(
722
					$name,
723
					$etitle,
724
					($multiple) ? $selected:$selected[0],
725
					$options,
726
					$multiple
727
				))->setHelp($field['description']);
728

    
729
				break;
730
			case "select":
731
				if ($field['displayname']) {
732
					$etitle = $field['displayname'];
733
				} else if (!$field['dontdisplayname']) {
734
					$etitle =  fixup_string($field['name']);
735
				}
736

    
737
				if ($field['size']) {
738
					$size = " size='" . $field['size'] . "' ";
739
				}
740

    
741
				$multiple = ($field['multiple'] == "yes");
742

    
743
				$onchange = "";
744
				foreach ($field['options']['option'] as $opt) {
745
					if ($opt['enablefields'] != "") {
746
						$onchange = "Javascript:enableitems(this.selectedIndex);";
747
					}
748
				}
749

    
750
				$options = array();
751
				$selected = array();
752

    
753
				foreach ($field['options']['option'] as $opt) {
754
					if ($value == $opt['value']) {
755
						array_push($selected, $value);
756
					}
757

    
758
					if ($opt['displayname']) {
759
						$options[$opt['value']] = $opt['displayname'];
760
					} else {
761
						$options[$opt['value']] = $opt['name'];
762
					}
763

    
764
				}
765

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

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

    
782
				$section->addInput(new Form_Textarea(
783
					$name,
784
					$etitle,
785
					$value
786
				))->setHelp($field['description'])
787
				  ->setAttribute('rows', $field['rows'])
788
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
789

    
790
				break;
791
			case "submit":
792
				$form->addGlobal(new Form_Button(
793
					$name,
794
					$field['name'],
795
					null,
796
					'fa-angle-double-right'
797
				))->addClass('btn-primary');
798

    
799
				break;
800
			case "listtopic":
801
				$form->add($section);
802
				$section = new Form_Section($field['name']);
803

    
804
				break;
805
			case "subnet_select":
806
				if ($field['displayname']) {
807
					$etitle = $field['displayname'];
808
				} else /* if (!$field['dontdisplayname']) */ {
809
					$etitle =  fixup_string($field['name']);
810
				}
811

    
812
				$section->addInput(new Form_Select(
813
					$name,
814
					$etitle,
815
					$value,
816
					array_combine(range(32, 1, -1), range(32, 1, -1))
817
				))->setHelp($field['description']);
818

    
819
				break;
820
			case "timezone_select":
821
				$timezonelist = system_get_timezone_list();
822

    
823
				/* kill carriage returns */
824
				for ($x = 0; $x < count($timezonelist); $x++) {
825
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
826
				}
827

    
828
				if ($field['displayname']) {
829
					$etitle = $field['displayname'];
830
				} else if (!$field['dontdisplayname']) {
831
					$etitle =  fixup_string($field['name']);
832
				}
833

    
834
				if (!$field['dontcombinecells']) {
835
					//echo "<td class=\"vtable\">";
836
				}
837

    
838
				$section->addInput(new Form_Select(
839
					$name,
840
					$etitle,
841
					($value == "") ? $g['default_timezone'] : $value,
842
					array_combine($timezonelist, $timezonelist)
843
				))->setHelp($field['description']);
844

    
845
				break;
846
			case "checkbox":
847
				if ($field['displayname']) {
848
					$etitle = $field['displayname'];
849

    
850
				} else if (!$field['dontdisplayname']) {
851
					$etitle =  fixup_string($field['name']);
852
				}
853

    
854
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
855
					$onclick = "enablechange()";
856
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
857
					$onclick = "disablechange()";
858
				}
859

    
860
				$section->addInput(new Form_Checkbox(
861
					$name,
862
					$etitle,
863
					$field['typehint'],
864
					($value != ""),
865
					'on'
866
				))->setHelp($field['description'])
867
				  ->setOnclick($onclick);
868

    
869
				break;
870
		} // e-o-switch
871
	} // e-o-foreach (package)
872
} // e-o-if (we have fields)
873

    
874
$form->add($section);
875
print($form);
876
?>
877

    
878
<script type="text/javascript">
879
//<![CDATA[
880

    
881
		if (typeof ext_change != 'undefined') {
882
			ext_change();
883
		}
884
		if (typeof proto_change != 'undefined') {
885
			ext_change();
886
		}
887
		if (typeof proto_change != 'undefined') {
888
			proto_change();
889
		}
890

    
891
	<?php
892
		$isfirst = 0;
893
		$aliases = "";
894
		$addrisfirst = 0;
895
		$aliasesaddr = "";
896
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
897
			foreach ($config['aliases']['alias'] as $alias_name) {
898
				if ($isfirst == 1) {
899
					$aliases .= ",";
900
				}
901
				$aliases .= "'" . $alias_name['name'] . "'";
902
				$isfirst = 1;
903
			}
904
		}
905
	?>
906

    
907
		var customarray=new Array(<?=$aliases; ?>);
908

    
909
		window.onload = function () {
910

    
911
<?php
912
		$counter = 0;
913
		foreach ($inputaliases as $alias) {
914
?>
915
			$('#' + '<?=$alias;?>').autocomplete({
916
				source: customarray
917
			});
918
<?php
919
		}
920
?>
921
	}
922

    
923
//]]>
924
</script>
925

    
926
<?php
927

    
928
$fieldnames_array = Array();
929
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] != "") {
930
	// create a fieldname loop that can be used with javascript
931
	// hide and enable features.
932
	echo "\n<script type=\"text/javascript\">\n";
933
	echo "//<![CDATA[\n";
934
	echo "function disableall() {\n";
935
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
936
		if ($field['type'] != "submit" and $field['type'] != "listtopic") {
937
			if (!$field['donotdisable'] != "") {
938
				array_push($fieldnames_array, $field['name']);
939
				$fieldname = preg_replace("/\s+/", "", $field['name']);
940
				$fieldname = strtolower($fieldname);
941
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
942
			}
943
		}
944
	}
945
	echo "}\ndisableall();\n";
946
	echo "function enableitems(selectedindex) {\n";
947
	echo "disableall();\n";
948
	$idcounter = 0;
949
	if ($pkg['step'][$stepid]['fields']['field'] != "") {
950
		echo "\tswitch (selectedindex) {\n";
951
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
952
			if ($field['options']['option'] != "") {
953
				foreach ($field['options']['option'] as $opt) {
954
					if ($opt['enablefields'] != "") {
955
						echo "\t\tcase " . $idcounter . ":\n";
956
						$enablefields_split = explode(",", $opt['enablefields']);
957
						foreach ($enablefields_split as $efs) {
958
							$fieldname = preg_replace("/\s+/", "", $efs);
959
							$fieldname = strtolower($fieldname);
960
							if ($fieldname != "") {
961
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
962
								echo $onchange;
963
							}
964
						}
965
						echo "\t\t\tbreak;\n";
966
					}
967
					$idcounter = $idcounter + 1;
968
				}
969
			}
970
		}
971
		echo "\t}\n";
972
	}
973
	echo "}\n";
974
	echo "//]]>\n";
975
	echo "</script>\n\n";
976
}
977
?>
978

    
979
<script type="text/javascript">
980
//<![CDATA[
981
events.push(function() {
982
	enablechange();
983
	disablechange();
984
	showchange();
985
});
986
//]]>
987
</script>
988

    
989
<?php
990
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
991
	// handle after form display event.
992
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
993
}
994

    
995
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
996
	// handle after form display event.
997
	echo "\n<script type=\"text/javascript\">\n";
998
	echo "//<![CDATA[\n";
999
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1000
	echo "//]]>\n";
1001
	echo "</script>\n\n";
1002
}
1003

    
1004
include("foot.inc");
(231-231/232)