Project

General

Profile

Download (26 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * wizard.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 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($_GET['stepid']);
43
if (isset($_POST['stepid'])) {
44
	$stepid = htmlspecialchars($_POST['stepid']);
45
}
46

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

    
51
$xml = htmlspecialchars($_GET['xml']);
52
if ($_POST['xml']) {
53
	$xml = htmlspecialchars($_POST['xml']);
54
}
55

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

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

    
80
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
81
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
82
$totalsteps	 = $pkg['totalsteps'];
83

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

    
88
if ($pkg['step'][$stepid]['includefile']) {
89
	require_once($pkg['step'][$stepid]['includefile']);
90
}
91

    
92
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
93
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
94
}
95

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

    
109
			if ($field['arraynum'] != "") {
110
				$arraynum = $field['arraynum'];
111
			} else {
112
				$arraynum = "";
113
			}
114

    
115
			update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
116
		}
117

    
118
	}
119
	// run custom php code embedded in xml config.
120
	if ($pkg['step'][$stepid]['stepsubmitphpaction'] != "") {
121
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
122
	}
123
	if (!$input_errors) {
124
		write_config();
125
	}
126

    
127
	$stepid++;
128
	if ($stepid > $totalsteps) {
129
		$stepid = $totalsteps;
130
	}
131
}
132

    
133
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
134
	global $config;
135
	$field_split = explode("->", $field);
136
	foreach ($field_split as $f) {
137
		$field_conv .= "['" . $f . "']";
138
	}
139
	if ($field_conv == "") {
140
		return;
141
	}
142
	if ($arraynum != "") {
143
		$field_conv .= "[" . $arraynum . "]";
144
	}
145
	if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
146
		/*
147
		 * item is a checkbox, it should have the value "on"
148
		 * if it was checked
149
		 */
150
		$var = "\$config{$field_conv}";
151
		$text = "if (isset({$var})) unset({$var});";
152
		eval($text);
153
		return;
154
	}
155

    
156
	if ($field_type == "interfaces_selection") {
157
		$var = "\$config{$field_conv}";
158
		$text = "if (isset({$var})) unset({$var});";
159
		$text .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
160
		eval($text);
161
		return;
162
	}
163

    
164
	if ($unset == "yes") {
165
		$text = "unset(\$config" . $field_conv . ");";
166
		eval($text);
167
	}
168
	$text = "\$config" . $field_conv . " = \"" . addslashes($updatetext) . "\";";
169
	eval($text);
170
}
171

    
172
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
173
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
174

    
175
// handle before form display event.
176
do {
177
	$oldstepid = $stepid;
178
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
179
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
180
	}
181
} while ($oldstepid != $stepid);
182

    
183
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
184
$pglinks = array("", "wizard.php?xml=" . $xml);
185
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
186
$pglinks[] = ($stepid > 0 ? "wizard.php?xml=" . $xml . "&stepid=" . $stepid:'&nbsp;');
187
$shortcut_section = "Wizard";
188
include("head.inc");
189

    
190
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
191
<script type="text/javascript">
192
//<![CDATA[
193

    
194

    
195
	function FieldValidate(userinput, regexp, message) {
196
		if (!userinput.match(regexp)) {
197
			alert(message);
198
		}
199
	}
200

    
201
	function enablechange() {
202

    
203
	<?php
204

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

    
209
				if (isset($field['enablefields'])) {
210
					$enablefields = explode(',', $field['enablefields']);
211
					foreach ($enablefields as $enablefield) {
212
						$enablefield = strtolower($enablefield);
213
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
214
					}
215
				}
216

    
217
				if (isset($field['checkenablefields'])) {
218
					$checkenablefields = explode(',', $field['checkenablefields']);
219
					foreach ($checkenablefields as $checkenablefield) {
220
						$checkenablefield = strtolower($checkenablefield);
221
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
222
					}
223
				}
224

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

    
232
					}
233
				}
234

    
235
			if (isset($field['checkdisablefields'])) {
236
				$checkenablefields = explode(',', $field['checkdisablefields']);
237
				foreach ($checkenablefields as $checkenablefield) {
238
					$checkenablefield = strtolower($checkenablefield);
239
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
240
					}
241
				}
242

    
243
				print "\t" . '}' . "\n";
244
			}
245
		}
246
	?>
247

    
248
	}
249

    
250
	function disablechange() {
251
	<?php
252
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
253
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
254

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

    
257
				if (isset($field['disablefields'])) {
258
					$enablefields = explode(',', $field['disablefields']);
259
					foreach ($enablefields as $enablefield) {
260
						$enablefield = strtolower($enablefield);
261

    
262
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
263
					}
264
				}
265
				if (isset($field['checkdisablefields'])) {
266
					$checkenablefields = explode(',', $field['checkdisablefields']);
267
					foreach ($checkenablefields as $checkenablefield) {
268
						$checkenablefield = strtolower($checkenablefield);
269
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
270
					}
271
				}
272
				print "\t" . '} else {' . "\n";
273
				if (isset($field['disablefields'])) {
274
					$enablefields = explode(',', $field['disablefields']);
275
					foreach ($enablefields as $enablefield) {
276
						$enablefield = strtolower($enablefield);
277
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\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", false);' . "\n";
285
					}
286
				}
287
				print "\t" . '}' . "\n";
288
			}
289
		}
290
	?>
291
	}
292

    
293
	function showchange() {
294
<?php
295
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
296
			if (isset($field['showfields'])) {
297
				print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
298
				if (isset($field['showfields'])) {
299
					$showfields = explode(',', $field['showfields']);
300
					foreach ($showfields as $showfield) {
301
						$showfield = strtolower($showfield);
302
						//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
303
						print "\t\t $('#". $showfield . "').hide();";
304
					}
305
				}
306
				print "\t" . '} else {' . "\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 =\"\";\n";
312
						print "\t\t $('#". $showfield . "').show();";
313
					}
314
				}
315
				print "\t" . '}' . "\n";
316
			}
317
		}
318
?>
319
	}
320

    
321
//]]>
322
</script>
323
<?php }
324

    
325
function fixup_string($string) {
326
	global $config, $g, $myurl, $title;
327
	$newstring = $string;
328
	// fixup #1: $myurl -> http[s]://ip_address:port/
329
	switch ($config['system']['webgui']['protocol']) {
330
		case "http":
331
			$proto = "http";
332
			break;
333
		case "https":
334
			$proto = "https";
335
			break;
336
		default:
337
			$proto = "http";
338
			break;
339
	}
340
	$port = $config['system']['webgui']['port'];
341
	if ($port != "") {
342
		if (($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
343
			$urlport = ":" . $port;
344
		} elseif ($port != "80" and $port != "443") {
345
			$urlport = ":" . $port;
346
		} else {
347
			$urlport = "";
348
		}
349
	}
350

    
351
	$http_host = $_SERVER['HTTP_HOST'];
352
	$urlhost = $http_host;
353
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
354
	if ($title == "Reload in progress") {
355
		if (is_ipaddr($urlhost)) {
356
			$host_if = find_ip_interface($urlhost);
357
			if ($host_if) {
358
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
359
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) {
360
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
361
				}
362
			}
363
		} else if ($urlhost == $config['system']['hostname']) {
364
			$urlhost = $config['wizardtemp']['system']['hostname'];
365
		} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
366
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
367
		}
368
	}
369

    
370
	if ($urlhost != $http_host) {
371
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
372
	}
373

    
374
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
375

    
376
	if (strstr($newstring, "\$myurl")) {
377
		$newstring = str_replace("\$myurl", $myurl, $newstring);
378
	}
379
	// fixup #2: $wanip
380
	if (strstr($newstring, "\$wanip")) {
381
		$curwanip = get_interface_ip();
382
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
383
	}
384
	// fixup #3: $lanip
385
	if (strstr($newstring, "\$lanip")) {
386
		$lanip = get_interface_ip("lan");
387
		$newstring = str_replace("\$lanip", $lanip, $newstring);
388
	}
389
	// fixup #4: fix'r'up here.
390
	return $newstring;
391
}
392

    
393
function is_timezone($elt) {
394
	return !preg_match("/\/$/", $elt);
395
}
396

    
397
if ($title == "Reload in progress") {
398
	$ip = fixup_string("\$myurl");
399
} else {
400
	$ip = "/";
401
}
402

    
403
if ($input_errors) {
404
	print_input_errors($input_errors);
405
}
406
if ($savemsg) {
407
	print_info_box($savemsg, 'success');
408
}
409
if ($_GET['message'] != "") {
410
	print_info_box(htmlspecialchars($_GET['message']));
411
}
412
if ($_POST['message'] != "") {
413
	print_info_box(htmlspecialchars($_POST['message']));
414
}
415

    
416
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
417
?>
418

    
419
<!-- Draw a progress bar to show step progress -->
420
<div class="progress">
421
	<div class="progress-bar" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%">
422
	</div>
423
</div>
424

    
425
<?php
426

    
427
$form = new Form(false);
428

    
429
$form->addGlobal(new Form_Input(
430
	'stepid',
431
	null,
432
	'hidden',
433
	$stepid
434
));
435

    
436
$form->addGlobal(new Form_Input(
437
	'xml',
438
	null,
439
	'hidden',
440
	$xml
441
));
442

    
443
$section = new Form_Section(fixup_string($title));
444

    
445
if ($description) {
446
	$section->addInput(new Form_StaticText(
447
		null,
448
		fixup_string($description)
449
	));
450
}
451

    
452
$inputaliases = array();
453
if ($pkg['step'][$stepid]['fields']['field'] != "") {
454
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
455

    
456
		$value = $field['value'];
457
		$name  = $field['name'];
458

    
459
		$name = preg_replace("/\s+/", "", $name);
460
		$name = strtolower($name);
461

    
462
		if ($field['bindstofield'] != "") {
463
			$arraynum = "";
464
			$field_conv = "";
465
			$field_split = explode("->", $field['bindstofield']);
466
			// arraynum is used in cases where there is an array of the same field
467
			// name such as dnsserver (2 of them)
468
			if ($field['arraynum'] != "") {
469
				$arraynum = "[" . $field['arraynum'] . "]";
470
			}
471

    
472
			foreach ($field_split as $f) {
473
				$field_conv .= "['" . $f . "']";
474
			}
475

    
476
			if ($field['type'] == "checkbox") {
477
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
478
			} else {
479
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
480
			}
481

    
482
			eval($toeval);
483
		}
484

    
485

    
486
		if (DEBUG) {
487
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
488
		}
489

    
490
		switch ($field['type']) {
491
			case "input":
492
				if ($field['displayname']) {
493
					$etitle = $field['displayname'];
494

    
495
				} else if (!$field['dontdisplayname']) {
496
					$etitle =  fixup_string($field['name']);
497
				}
498

    
499
				$section->addInput(new Form_Input(
500
					$name,
501
					$etitle,
502
					'text',
503
					$value
504
				))->setHelp($field['description'])
505
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
506

    
507
				break;
508
			case "text":
509
				$section->addInput(new Form_StaticText(
510
					null,
511
					$field['description']
512
				));
513

    
514
				break;
515
			case "inputalias":
516
				if ($field['displayname']) {
517
					$etitle = $field['displayname'];
518

    
519
				} else if (!$field['dontdisplayname']) {
520
					$etitle =  fixup_string($field['name']);
521
				}
522

    
523
				$onchange = "";
524

    
525
				if ($field['validate']) {
526
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
527
				}
528

    
529
				$section->addInput(new Form_Input(
530
					$name,
531
					$etitle,
532
					'text',
533
					$value
534
				))->setAttribute('autocomplete', 'off')
535
				  ->setOnchange($onchange)
536
				  ->setHelp($field['description']);
537

    
538
				break;
539
			case "interfaces_selection":
540
			case "interface_select":
541

    
542
				$name = strtolower($name);
543
				$options = array();
544
				$selected = array();
545

    
546
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
547

    
548
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
549
					$multiple = true;
550
				} else {
551
					$multiple = false;
552
				}
553

    
554
				if ($field['add_to_interfaces_selection'] != "") {
555
					if ($field['add_to_interfaces_selection'] == $value) {
556
						array_push($selected, $value);
557
					}
558

    
559
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
560
				}
561

    
562
				if ($field['type'] == "interface_select") {
563
					$interfaces = get_interface_list();
564
				} else {
565
					$interfaces = get_configured_interface_with_descr();
566
				}
567

    
568
				foreach ($interfaces as $ifname => $iface) {
569
					if ($field['type'] == "interface_select") {
570
						$iface = $ifname;
571
						if ($iface['mac']) {
572
							$iface .= " ({$iface['mac']})";
573
						}
574
					}
575

    
576
					if ($value == $ifname) {
577
						array_push($selected, $value);
578
					}
579

    
580
					$canecho = 0;
581
					if ($field['interface_filter'] != "") {
582
						if (stristr($ifname, $field['interface_filter']) == true) {
583
							$canecho = 1;
584
						}
585
					} else {
586
						$canecho = 1;
587
					}
588

    
589
					if ($canecho == 1) {
590
						$options[$ifname] = $iface;
591
					}
592
				}
593

    
594
				$section->addInput(new Form_Select(
595
					$name,
596
					$etitle,
597
					($multiple) ? $selected:$selected[0],
598
					$options,
599
					$multiple
600
				))->setHelp($field['description']);
601

    
602
				break;
603
			case "password":
604
				if ($field['displayname']) {
605
					$etitle = $field['displayname'];
606
				} else if (!$field['dontdisplayname']) {
607
					$etitle =  fixup_string($field['name']);
608
				}
609

    
610
				$section->addInput(new Form_Input(
611
					$name,
612
					$etitle,
613
					'password',
614
					$value
615
				))->setHelp($field['description'])
616
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
617

    
618
				break;
619
			case "certca_selection":
620
				$options = array();
621
				$selected = "";
622

    
623
				$name = strtolower($name);
624

    
625
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
626

    
627
				if ($field['add_to_certca_selection'] != "") {
628
					if ($field['add_to_certca_selection'] == $value) {
629
						$selected = $value;
630
					}
631

    
632
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
633
				}
634

    
635
				foreach ($config['ca'] as $ca) {
636
					$caname = htmlspecialchars($ca['descr']);
637

    
638
					if ($value == $caname) {
639
						$selected = $value;
640
					}
641

    
642
					$canecho = 0;
643
					if ($field['certca_filter'] != "") {
644
						if (stristr($caname, $field['certca_filter']) == true) {
645
							$canecho = 1;
646
						}
647
					} else {
648
						$canecho = 1;
649
					}
650
					if ($canecho == 1) {
651
						$options[$ca['refid']] = $caname;
652
					}
653
				}
654

    
655
				$section->addInput(new Form_Select(
656
					$name,
657
					$etitle,
658
					$selected,
659
					$options
660
				))->setHelp($field['description']);
661

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

    
667
				$multiple = false;
668
				$name = strtolower($name);
669

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

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

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

    
680
				foreach ($config['cert'] as $ca) {
681
					if (stristr($ca['descr'], "webconf")) {
682
						continue;
683
					}
684

    
685
					$caname = htmlspecialchars($ca['descr']);
686

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

    
691

    
692
					$canecho = 0;
693
					if ($field['cert_filter'] != "") {
694
						if (stristr($caname, $field['cert_filter']) == true) {
695
							$canecho = 1;
696
						}
697
					} else {
698
						$canecho = 1;
699
					}
700

    
701
					if ($canecho == 1) {
702
						$options[$ca['refid']] = $caname;
703
					}
704
				}
705

    
706
				$section->addInput(new Form_Select(
707
					$name,
708
					$etitle,
709
					($multiple) ? $selected:$selected[0],
710
					$options,
711
					$multiple
712
				))->setHelp($field['description']);
713

    
714
				break;
715
			case "select":
716
				if ($field['displayname']) {
717
					$etitle = $field['displayname'];
718
				} else if (!$field['dontdisplayname']) {
719
					$etitle =  fixup_string($field['name']);
720
				}
721

    
722
				if ($field['size']) {
723
					$size = " size='" . $field['size'] . "' ";
724
				}
725

    
726
				$multiple = ($field['multiple'] == "yes");
727

    
728
				$onchange = "";
729
				foreach ($field['options']['option'] as $opt) {
730
					if ($opt['enablefields'] != "") {
731
						$onchange = "Javascript:enableitems(this.selectedIndex);";
732
					}
733
				}
734

    
735
				$options = array();
736
				$selected = array();
737

    
738
				foreach ($field['options']['option'] as $opt) {
739
					if ($value == $opt['value']) {
740
						array_push($selected, $value);
741
					}
742

    
743
					if ($opt['displayname']) {
744
						$options[$opt['value']] = $opt['displayname'];
745
					} else {
746
						$options[$opt['value']] = $opt['name'];
747
					}
748

    
749
				}
750

    
751
				$section->addInput(new Form_Select(
752
					$name,
753
					$etitle,
754
					($multiple) ? $selected:$selected[0],
755
					$options,
756
					$multiple
757
				))->setHelp($field['description'])->setOnchange($onchange);
758

    
759
				break;
760
			case "textarea":
761
				if ($field['displayname']) {
762
					$etitle = $field['displayname'];
763
				} else if (!$field['dontdisplayname']) {
764
					$etitle =  fixup_string($field['name']);
765
				}
766

    
767
				$section->addInput(new Form_Textarea(
768
					$name,
769
					$etitle,
770
					$value
771
				))->setHelp($field['description'])
772
				  ->setAttribute('rows', $field['rows'])
773
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
774

    
775
				break;
776
			case "submit":
777
				$form->addGlobal(new Form_Button(
778
					$name,
779
					$field['name'],
780
					null,
781
					'fa-angle-double-right'
782
				))->addClass('btn-primary');
783

    
784
				break;
785
			case "listtopic":
786
				$form->add($section);
787
				$section = new Form_Section($field['name']);
788

    
789
				break;
790
			case "subnet_select":
791
				if ($field['displayname']) {
792
					$etitle = $field['displayname'];
793
				} else /* if (!$field['dontdisplayname']) */ {
794
					$etitle =  fixup_string($field['name']);
795
				}
796

    
797
				$section->addInput(new Form_Select(
798
					$name,
799
					$etitle,
800
					$value,
801
					array_combine(range(32, 1, -1), range(32, 1, -1))
802
				))->setHelp($field['description']);
803

    
804
				break;
805
			case "timezone_select":
806
				$timezonelist = system_get_timezone_list();
807

    
808
				/* kill carriage returns */
809
				for ($x = 0; $x < count($timezonelist); $x++) {
810
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
811
				}
812

    
813
				if ($field['displayname']) {
814
					$etitle = $field['displayname'];
815
				} else if (!$field['dontdisplayname']) {
816
					$etitle =  fixup_string($field['name']);
817
				}
818

    
819
				if (!$field['dontcombinecells']) {
820
					//echo "<td class=\"vtable\">";
821
				}
822

    
823
				$section->addInput(new Form_Select(
824
					$name,
825
					$etitle,
826
					($value == "") ? $g['default_timezone'] : $value,
827
					array_combine($timezonelist, $timezonelist)
828
				))->setHelp($field['description']);
829

    
830
				break;
831
			case "checkbox":
832
				if ($field['displayname']) {
833
					$etitle = $field['displayname'];
834

    
835
				} else if (!$field['dontdisplayname']) {
836
					$etitle =  fixup_string($field['name']);
837
				}
838

    
839
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
840
					$onclick = "enablechange()";
841
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
842
					$onclick = "disablechange()";
843
				}
844

    
845
				$section->addInput(new Form_Checkbox(
846
					$name,
847
					$etitle,
848
					$field['typehint'],
849
					($value != ""),
850
					'on'
851
				))->setHelp($field['description'])
852
				  ->setOnclick($onclick);
853

    
854
				break;
855
		} // e-o-switch
856
	} // e-o-foreach (package)
857
} // e-o-if (we have fields)
858

    
859
$form->add($section);
860
print($form);
861
?>
862

    
863
<script type="text/javascript">
864
//<![CDATA[
865

    
866
		if (typeof ext_change != 'undefined') {
867
			ext_change();
868
		}
869
		if (typeof proto_change != 'undefined') {
870
			ext_change();
871
		}
872
		if (typeof proto_change != 'undefined') {
873
			proto_change();
874
		}
875

    
876
	<?php
877
		$isfirst = 0;
878
		$aliases = "";
879
		$addrisfirst = 0;
880
		$aliasesaddr = "";
881
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
882
			foreach ($config['aliases']['alias'] as $alias_name) {
883
				if ($isfirst == 1) {
884
					$aliases .= ",";
885
				}
886
				$aliases .= "'" . $alias_name['name'] . "'";
887
				$isfirst = 1;
888
			}
889
		}
890
	?>
891

    
892
		var customarray=new Array(<?=$aliases; ?>);
893

    
894
		window.onload = function () {
895

    
896
<?php
897
		$counter = 0;
898
		foreach ($inputaliases as $alias) {
899
?>
900
			$('#' + '<?=$alias;?>').autocomplete({
901
				source: customarray
902
			});
903
<?php
904
		}
905
?>
906
	}
907

    
908
//]]>
909
</script>
910

    
911
<?php
912

    
913
$fieldnames_array = Array();
914
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] != "") {
915
	// create a fieldname loop that can be used with javascript
916
	// hide and enable features.
917
	echo "\n<script type=\"text/javascript\">\n";
918
	echo "//<![CDATA[\n";
919
	echo "function disableall() {\n";
920
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
921
		if ($field['type'] != "submit" and $field['type'] != "listtopic") {
922
			if (!$field['donotdisable'] != "") {
923
				array_push($fieldnames_array, $field['name']);
924
				$fieldname = preg_replace("/\s+/", "", $field['name']);
925
				$fieldname = strtolower($fieldname);
926
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
927
			}
928
		}
929
	}
930
	echo "}\ndisableall();\n";
931
	echo "function enableitems(selectedindex) {\n";
932
	echo "disableall();\n";
933
	$idcounter = 0;
934
	if ($pkg['step'][$stepid]['fields']['field'] != "") {
935
		echo "\tswitch (selectedindex) {\n";
936
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
937
			if ($field['options']['option'] != "") {
938
				foreach ($field['options']['option'] as $opt) {
939
					if ($opt['enablefields'] != "") {
940
						echo "\t\tcase " . $idcounter . ":\n";
941
						$enablefields_split = explode(",", $opt['enablefields']);
942
						foreach ($enablefields_split as $efs) {
943
							$fieldname = preg_replace("/\s+/", "", $efs);
944
							$fieldname = strtolower($fieldname);
945
							if ($fieldname != "") {
946
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
947
								echo $onchange;
948
							}
949
						}
950
						echo "\t\t\tbreak;\n";
951
					}
952
					$idcounter = $idcounter + 1;
953
				}
954
			}
955
		}
956
		echo "\t}\n";
957
	}
958
	echo "}\n";
959
	echo "//]]>\n";
960
	echo "</script>\n\n";
961
}
962
?>
963

    
964
<script type="text/javascript">
965
//<![CDATA[
966
events.push(function() {
967
	enablechange();
968
	disablechange();
969
	showchange();
970
});
971
//]]>
972
</script>
973

    
974
<?php
975
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
976
	// handle after form display event.
977
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
978
}
979

    
980
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
981
	// handle after form display event.
982
	echo "\n<script type=\"text/javascript\">\n";
983
	echo "//<![CDATA[\n";
984
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
985
	echo "//]]>\n";
986
	echo "</script>\n\n";
987
}
988

    
989
include("foot.inc");
(224-224/225)