Project

General

Profile

Download (25.8 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($_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
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
76
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
77
$totalsteps	 = $pkg['totalsteps'];
78

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

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

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

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

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

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

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

    
122
	$stepid++;
123
	if ($stepid > $totalsteps) {
124
		$stepid = $totalsteps;
125
	}
126
}
127

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

    
152
	if ($field_type == "interfaces_selection") {
153
		$var = "\$config{$field_conv}";
154
		$text = "if (isset({$var})) unset({$var});";
155
		$text .= "\$thisvar = &\$config" . $field_conv . ";";
156
		eval($text);
157
		$thisvar = $updatetext;
158
		return;
159
	}
160

    
161
	if ($unset == "yes") {
162
		$text = "unset(\$config" . $field_conv . ");";
163
		eval($text);
164
	}
165
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
166
	eval($text);
167
	$thisvar = $updatetext;
168
}
169

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

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

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

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

    
192

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

    
199
	function enablechange() {
200

    
201
	<?php
202

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

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

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

    
223
				print "\t" . '} else {' . "\n";
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", true);' . "\n";
229

    
230
					}
231
				}
232

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

    
241
				print "\t" . '}' . "\n";
242
			}
243
		}
244
	?>
245

    
246
	}
247

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

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

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

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

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

    
319
//]]>
320
</script>
321
<?php }
322

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

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

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

    
372
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
373

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

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

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

    
401
if ($input_errors) {
402
	print_input_errors($input_errors);
403
}
404
if ($savemsg) {
405
	print_info_box($savemsg, 'success');
406
}
407
if ($_REQUEST['message'] != "") {
408
	print_info_box(htmlspecialchars($_REQUEST['message']));
409
}
410

    
411
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
412
?>
413

    
414
<!-- Draw a progress bar to show step progress -->
415
<div class="progress">
416
	<div class="progress-bar" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%">
417
	</div>
418
</div>
419

    
420
<?php
421

    
422
$form = new Form(false);
423

    
424
$form->addGlobal(new Form_Input(
425
	'stepid',
426
	null,
427
	'hidden',
428
	$stepid
429
));
430

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

    
438
$section = new Form_Section(fixup_string($title));
439

    
440
if ($description) {
441
	$section->addInput(new Form_StaticText(
442
		null,
443
		fixup_string($description)
444
	));
445
}
446

    
447
$inputaliases = array();
448
if ($pkg['step'][$stepid]['fields']['field'] != "") {
449
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
450

    
451
		$value = $field['value'];
452
		$name  = $field['name'];
453

    
454
		$name = preg_replace("/\s+/", "", $name);
455
		$name = strtolower($name);
456

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

    
467
			foreach ($field_split as $f) {
468
				$field_conv .= "['" . $f . "']";
469
			}
470

    
471
			if ($field['type'] == "checkbox") {
472
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
473
			} else {
474
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
475
			}
476

    
477
			eval($toeval);
478
		}
479

    
480

    
481
		if (DEBUG) {
482
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
483
		}
484

    
485
		switch ($field['type']) {
486
			case "input":
487
				if ($field['displayname']) {
488
					$etitle = $field['displayname'];
489

    
490
				} else if (!$field['dontdisplayname']) {
491
					$etitle =  fixup_string($field['name']);
492
				}
493

    
494
				$section->addInput(new Form_Input(
495
					$name,
496
					$etitle,
497
					'text',
498
					$value
499
				))->setHelp($field['description'])
500
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
501

    
502
				break;
503
			case "text":
504
				$section->addInput(new Form_StaticText(
505
					null,
506
					$field['description']
507
				));
508

    
509
				break;
510
			case "inputalias":
511
				if ($field['displayname']) {
512
					$etitle = $field['displayname'];
513

    
514
				} else if (!$field['dontdisplayname']) {
515
					$etitle =  fixup_string($field['name']);
516
				}
517

    
518
				$onchange = "";
519

    
520
				if ($field['validate']) {
521
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
522
				}
523

    
524
				$section->addInput(new Form_Input(
525
					$name,
526
					$etitle,
527
					'text',
528
					$value
529
				))->setAttribute('autocomplete', 'off')
530
				  ->setOnchange($onchange)
531
				  ->setHelp($field['description']);
532

    
533
				break;
534
			case "interfaces_selection":
535
			case "interface_select":
536

    
537
				$name = strtolower($name);
538
				$options = array();
539
				$selected = array();
540

    
541
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
542

    
543
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
544
					$multiple = true;
545
				} else {
546
					$multiple = false;
547
				}
548

    
549
				if ($field['add_to_interfaces_selection'] != "") {
550
					if ($field['add_to_interfaces_selection'] == $value) {
551
						array_push($selected, $value);
552
					}
553

    
554
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
555
				}
556

    
557
				if ($field['type'] == "interface_select") {
558
					$interfaces = get_interface_list();
559
				} else {
560
					$interfaces = get_configured_interface_with_descr();
561
				}
562

    
563
				foreach ($interfaces as $ifname => $iface) {
564
					if ($field['type'] == "interface_select") {
565
						$iface = $ifname;
566
						if ($iface['mac']) {
567
							$iface .= " ({$iface['mac']})";
568
						}
569
					}
570

    
571
					if ($value == $ifname) {
572
						array_push($selected, $value);
573
					}
574

    
575
					$canecho = 0;
576
					if ($field['interface_filter'] != "") {
577
						if (stristr($ifname, $field['interface_filter']) == true) {
578
							$canecho = 1;
579
						}
580
					} else {
581
						$canecho = 1;
582
					}
583

    
584
					if ($canecho == 1) {
585
						$options[$ifname] = $iface;
586
					}
587
				}
588

    
589
				$section->addInput(new Form_Select(
590
					$name,
591
					$etitle,
592
					($multiple) ? $selected:$selected[0],
593
					$options,
594
					$multiple
595
				))->setHelp($field['description']);
596

    
597
				break;
598
			case "password":
599
				if ($field['displayname']) {
600
					$etitle = $field['displayname'];
601
				} else if (!$field['dontdisplayname']) {
602
					$etitle =  fixup_string($field['name']);
603
				}
604

    
605
				$section->addInput(new Form_Input(
606
					$name,
607
					$etitle,
608
					'password',
609
					$value
610
				))->setHelp($field['description'])
611
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
612

    
613
				break;
614
			case "certca_selection":
615
				$options = array();
616
				$selected = "";
617

    
618
				$name = strtolower($name);
619

    
620
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
621

    
622
				if ($field['add_to_certca_selection'] != "") {
623
					if ($field['add_to_certca_selection'] == $value) {
624
						$selected = $value;
625
					}
626

    
627
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
628
				}
629

    
630
				foreach ($config['ca'] as $ca) {
631
					$caname = htmlspecialchars($ca['descr']);
632

    
633
					if ($value == $caname) {
634
						$selected = $value;
635
					}
636

    
637
					$canecho = 0;
638
					if ($field['certca_filter'] != "") {
639
						if (stristr($caname, $field['certca_filter']) == true) {
640
							$canecho = 1;
641
						}
642
					} else {
643
						$canecho = 1;
644
					}
645
					if ($canecho == 1) {
646
						$options[$ca['refid']] = $caname;
647
					}
648
				}
649

    
650
				$section->addInput(new Form_Select(
651
					$name,
652
					$etitle,
653
					$selected,
654
					$options
655
				))->setHelp($field['description']);
656

    
657
				break;
658
			case "cert_selection":
659
				$options = array();
660
				$selected = array();
661

    
662
				$multiple = false;
663
				$name = strtolower($name);
664

    
665
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
666

    
667
				if ($field['add_to_cert_selection'] != "") {
668
					if ($field['add_to_cert_selection'] == $value) {
669
						array_push($selected, $value);
670
					}
671

    
672
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
673
				}
674

    
675
				foreach ($config['cert'] as $ca) {
676
					if (stristr($ca['descr'], "webconf")) {
677
						continue;
678
					}
679

    
680
					$caname = htmlspecialchars($ca['descr']);
681

    
682
					if ($value == $caname) {
683
						array_push($selected, $value);
684
					}
685

    
686

    
687
					$canecho = 0;
688
					if ($field['cert_filter'] != "") {
689
						if (stristr($caname, $field['cert_filter']) == true) {
690
							$canecho = 1;
691
						}
692
					} else {
693
						$canecho = 1;
694
					}
695

    
696
					if ($canecho == 1) {
697
						$options[$ca['refid']] = $caname;
698
					}
699
				}
700

    
701
				$section->addInput(new Form_Select(
702
					$name,
703
					$etitle,
704
					($multiple) ? $selected:$selected[0],
705
					$options,
706
					$multiple
707
				))->setHelp($field['description']);
708

    
709
				break;
710
			case "select":
711
				if ($field['displayname']) {
712
					$etitle = $field['displayname'];
713
				} else if (!$field['dontdisplayname']) {
714
					$etitle =  fixup_string($field['name']);
715
				}
716

    
717
				if ($field['size']) {
718
					$size = " size='" . $field['size'] . "' ";
719
				}
720

    
721
				$multiple = ($field['multiple'] == "yes");
722

    
723
				$onchange = "";
724
				foreach ($field['options']['option'] as $opt) {
725
					if ($opt['enablefields'] != "") {
726
						$onchange = "Javascript:enableitems(this.selectedIndex);";
727
					}
728
				}
729

    
730
				$options = array();
731
				$selected = array();
732

    
733
				foreach ($field['options']['option'] as $opt) {
734
					if ($value == $opt['value']) {
735
						array_push($selected, $value);
736
					}
737

    
738
					if ($opt['displayname']) {
739
						$options[$opt['value']] = $opt['displayname'];
740
					} else {
741
						$options[$opt['value']] = $opt['name'];
742
					}
743

    
744
				}
745

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

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

    
762
				$section->addInput(new Form_Textarea(
763
					$name,
764
					$etitle,
765
					$value
766
				))->setHelp($field['description'])
767
				  ->setAttribute('rows', $field['rows'])
768
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
769

    
770
				break;
771
			case "submit":
772
				$form->addGlobal(new Form_Button(
773
					$name,
774
					$field['name'],
775
					null,
776
					'fa-angle-double-right'
777
				))->addClass('btn-primary');
778

    
779
				break;
780
			case "listtopic":
781
				$form->add($section);
782
				$section = new Form_Section($field['name']);
783

    
784
				break;
785
			case "subnet_select":
786
				if ($field['displayname']) {
787
					$etitle = $field['displayname'];
788
				} else /* if (!$field['dontdisplayname']) */ {
789
					$etitle =  fixup_string($field['name']);
790
				}
791

    
792
				$section->addInput(new Form_Select(
793
					$name,
794
					$etitle,
795
					$value,
796
					array_combine(range(32, 1, -1), range(32, 1, -1))
797
				))->setHelp($field['description']);
798

    
799
				break;
800
			case "timezone_select":
801
				$timezonelist = system_get_timezone_list();
802

    
803
				/* kill carriage returns */
804
				for ($x = 0; $x < count($timezonelist); $x++) {
805
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
806
				}
807

    
808
				if ($field['displayname']) {
809
					$etitle = $field['displayname'];
810
				} else if (!$field['dontdisplayname']) {
811
					$etitle =  fixup_string($field['name']);
812
				}
813

    
814
				if (!$field['dontcombinecells']) {
815
					//echo "<td class=\"vtable\">";
816
				}
817

    
818
				$section->addInput(new Form_Select(
819
					$name,
820
					$etitle,
821
					($value == "") ? $g['default_timezone'] : $value,
822
					array_combine($timezonelist, $timezonelist)
823
				))->setHelp($field['description']);
824

    
825
				break;
826
			case "checkbox":
827
				if ($field['displayname']) {
828
					$etitle = $field['displayname'];
829

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

    
834
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
835
					$onclick = "enablechange()";
836
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
837
					$onclick = "disablechange()";
838
				}
839

    
840
				$section->addInput(new Form_Checkbox(
841
					$name,
842
					$etitle,
843
					$field['typehint'],
844
					($value != ""),
845
					'on'
846
				))->setHelp($field['description'])
847
				  ->setOnclick($onclick);
848

    
849
				break;
850
		} // e-o-switch
851
	} // e-o-foreach (package)
852
} // e-o-if (we have fields)
853

    
854
$form->add($section);
855
print($form);
856
?>
857

    
858
<script type="text/javascript">
859
//<![CDATA[
860

    
861
		if (typeof ext_change != 'undefined') {
862
			ext_change();
863
		}
864
		if (typeof proto_change != 'undefined') {
865
			ext_change();
866
		}
867
		if (typeof proto_change != 'undefined') {
868
			proto_change();
869
		}
870

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

    
887
		var customarray=new Array(<?=$aliases; ?>);
888

    
889
		window.onload = function () {
890

    
891
<?php
892
		$counter = 0;
893
		foreach ($inputaliases as $alias) {
894
?>
895
			$('#' + '<?=$alias;?>').autocomplete({
896
				source: customarray
897
			});
898
<?php
899
		}
900
?>
901
	}
902

    
903
//]]>
904
</script>
905

    
906
<?php
907

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

    
959
<script type="text/javascript">
960
//<![CDATA[
961
events.push(function() {
962
	enablechange();
963
	disablechange();
964
	showchange();
965
});
966
//]]>
967
</script>
968

    
969
<?php
970
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
971
	// handle after form display event.
972
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
973
}
974

    
975
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
976
	// handle after form display event.
977
	echo "\n<script type=\"text/javascript\">\n";
978
	echo "//<![CDATA[\n";
979
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
980
	echo "//]]>\n";
981
	echo "</script>\n\n";
982
}
983

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