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

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

    
166
	if ($unset == "yes") {
167
		$text = "unset(\$config" . $field_conv . ");";
168
		eval($text);
169
	}
170
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
171
	eval($text);
172
	$thisvar = $updatetext;
173
}
174

    
175
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
176
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
177

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

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

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

    
197

    
198
	function FieldValidate(userinput, regexp, message) {
199
		if (!userinput.match(regexp)) {
200
			alert(message);
201
		}
202
	}
203

    
204
	function enablechange() {
205

    
206
	<?php
207

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

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

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

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

    
235
					}
236
				}
237

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

    
246
				print "\t" . '}' . "\n";
247
			}
248
		}
249
	?>
250

    
251
	}
252

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

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

    
260
				if (isset($field['disablefields'])) {
261
					$enablefields = explode(',', $field['disablefields']);
262
					foreach ($enablefields as $enablefield) {
263
						$enablefield = strtolower($enablefield);
264

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

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

    
324
//]]>
325
</script>
326
<?php }
327

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

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

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

    
377
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
378

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

    
396
function is_timezone($elt) {
397
	return !preg_match("/\/$/", $elt);
398
}
399

    
400
if ($title == "Reload in progress") {
401
	$ip = fixup_string("\$myurl");
402
} else {
403
	$ip = "/";
404
}
405

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

    
419
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
420
?>
421

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

    
428
<?php
429

    
430
$form = new Form(false);
431

    
432
$form->addGlobal(new Form_Input(
433
	'stepid',
434
	null,
435
	'hidden',
436
	$stepid
437
));
438

    
439
$form->addGlobal(new Form_Input(
440
	'xml',
441
	null,
442
	'hidden',
443
	$xml
444
));
445

    
446
$section = new Form_Section(fixup_string($title));
447

    
448
if ($description) {
449
	$section->addInput(new Form_StaticText(
450
		null,
451
		fixup_string($description)
452
	));
453
}
454

    
455
$inputaliases = array();
456
if ($pkg['step'][$stepid]['fields']['field'] != "") {
457
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
458

    
459
		$value = $field['value'];
460
		$name  = $field['name'];
461

    
462
		$name = preg_replace("/\s+/", "", $name);
463
		$name = strtolower($name);
464

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

    
475
			foreach ($field_split as $f) {
476
				$field_conv .= "['" . $f . "']";
477
			}
478

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

    
485
			eval($toeval);
486
		}
487

    
488

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

    
493
		switch ($field['type']) {
494
			case "input":
495
				if ($field['displayname']) {
496
					$etitle = $field['displayname'];
497

    
498
				} else if (!$field['dontdisplayname']) {
499
					$etitle =  fixup_string($field['name']);
500
				}
501

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

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

    
517
				break;
518
			case "inputalias":
519
				if ($field['displayname']) {
520
					$etitle = $field['displayname'];
521

    
522
				} else if (!$field['dontdisplayname']) {
523
					$etitle =  fixup_string($field['name']);
524
				}
525

    
526
				$onchange = "";
527

    
528
				if ($field['validate']) {
529
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
530
				}
531

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

    
541
				break;
542
			case "interfaces_selection":
543
			case "interface_select":
544

    
545
				$name = strtolower($name);
546
				$options = array();
547
				$selected = array();
548

    
549
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
550

    
551
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
552
					$multiple = true;
553
				} else {
554
					$multiple = false;
555
				}
556

    
557
				if ($field['add_to_interfaces_selection'] != "") {
558
					if ($field['add_to_interfaces_selection'] == $value) {
559
						array_push($selected, $value);
560
					}
561

    
562
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
563
				}
564

    
565
				if ($field['type'] == "interface_select") {
566
					$interfaces = get_interface_list();
567
				} else {
568
					$interfaces = get_configured_interface_with_descr();
569
				}
570

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

    
579
					if ($value == $ifname) {
580
						array_push($selected, $value);
581
					}
582

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

    
592
					if ($canecho == 1) {
593
						$options[$ifname] = $iface;
594
					}
595
				}
596

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

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

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

    
621
				break;
622
			case "certca_selection":
623
				$options = array();
624
				$selected = "";
625

    
626
				$name = strtolower($name);
627

    
628
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
629

    
630
				if ($field['add_to_certca_selection'] != "") {
631
					if ($field['add_to_certca_selection'] == $value) {
632
						$selected = $value;
633
					}
634

    
635
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
636
				}
637

    
638
				foreach ($config['ca'] as $ca) {
639
					$caname = htmlspecialchars($ca['descr']);
640

    
641
					if ($value == $caname) {
642
						$selected = $value;
643
					}
644

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

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

    
665
				break;
666
			case "cert_selection":
667
				$options = array();
668
				$selected = array();
669

    
670
				$multiple = false;
671
				$name = strtolower($name);
672

    
673
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
674

    
675
				if ($field['add_to_cert_selection'] != "") {
676
					if ($field['add_to_cert_selection'] == $value) {
677
						array_push($selected, $value);
678
					}
679

    
680
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
681
				}
682

    
683
				foreach ($config['cert'] as $ca) {
684
					if (stristr($ca['descr'], "webconf")) {
685
						continue;
686
					}
687

    
688
					$caname = htmlspecialchars($ca['descr']);
689

    
690
					if ($value == $caname) {
691
						array_push($selected, $value);
692
					}
693

    
694

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

    
704
					if ($canecho == 1) {
705
						$options[$ca['refid']] = $caname;
706
					}
707
				}
708

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

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

    
725
				if ($field['size']) {
726
					$size = " size='" . $field['size'] . "' ";
727
				}
728

    
729
				$multiple = ($field['multiple'] == "yes");
730

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

    
738
				$options = array();
739
				$selected = array();
740

    
741
				foreach ($field['options']['option'] as $opt) {
742
					if ($value == $opt['value']) {
743
						array_push($selected, $value);
744
					}
745

    
746
					if ($opt['displayname']) {
747
						$options[$opt['value']] = $opt['displayname'];
748
					} else {
749
						$options[$opt['value']] = $opt['name'];
750
					}
751

    
752
				}
753

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

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

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

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

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

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

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

    
807
				break;
808
			case "timezone_select":
809
				$timezonelist = system_get_timezone_list();
810

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

    
816
				if ($field['displayname']) {
817
					$etitle = $field['displayname'];
818
				} else if (!$field['dontdisplayname']) {
819
					$etitle =  fixup_string($field['name']);
820
				}
821

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

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

    
833
				break;
834
			case "checkbox":
835
				if ($field['displayname']) {
836
					$etitle = $field['displayname'];
837

    
838
				} else if (!$field['dontdisplayname']) {
839
					$etitle =  fixup_string($field['name']);
840
				}
841

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

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

    
857
				break;
858
		} // e-o-switch
859
	} // e-o-foreach (package)
860
} // e-o-if (we have fields)
861

    
862
$form->add($section);
863
print($form);
864
?>
865

    
866
<script type="text/javascript">
867
//<![CDATA[
868

    
869
		if (typeof ext_change != 'undefined') {
870
			ext_change();
871
		}
872
		if (typeof proto_change != 'undefined') {
873
			ext_change();
874
		}
875
		if (typeof proto_change != 'undefined') {
876
			proto_change();
877
		}
878

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

    
895
		var customarray=new Array(<?=$aliases; ?>);
896

    
897
		window.onload = function () {
898

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

    
911
//]]>
912
</script>
913

    
914
<?php
915

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

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

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

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

    
992
include("foot.inc");
(222-222/223)