Project

General

Profile

Download (25.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * wizard.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-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 %s/wizards/%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
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
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 ($_GET['message'] != "") {
408
	print_info_box(htmlspecialchars($_GET['message']));
409
}
410
if ($_POST['message'] != "") {
411
	print_info_box(htmlspecialchars($_POST['message']));
412
}
413

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

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

    
423
<?php
424

    
425
$form = new Form(false);
426

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

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

    
441
$section = new Form_Section(fixup_string($title));
442

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

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

    
454
		$value = $field['value'];
455
		$name  = $field['name'];
456

    
457
		$name = preg_replace("/\s+/", "", $name);
458
		$name = strtolower($name);
459

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

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

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

    
480
			eval($toeval);
481
		}
482

    
483

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

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

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

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

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

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

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

    
521
				$onchange = "";
522

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

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

    
536
				break;
537
			case "interfaces_selection":
538
			case "interface_select":
539

    
540
				$name = strtolower($name);
541
				$options = array();
542
				$selected = array();
543

    
544
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
545

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

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

    
557
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
558
				}
559

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

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

    
574
					if ($value == $ifname) {
575
						array_push($selected, $value);
576
					}
577

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

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

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

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

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

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

    
621
				$name = strtolower($name);
622

    
623
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
624

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

    
630
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
631
				}
632

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

    
636
					if ($value == $caname) {
637
						$selected = $value;
638
					}
639

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

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

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

    
665
				$multiple = false;
666
				$name = strtolower($name);
667

    
668
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
669

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

    
675
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
676
				}
677

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

    
683
					$caname = htmlspecialchars($ca['descr']);
684

    
685
					if ($value == $caname) {
686
						array_push($selected, $value);
687
					}
688

    
689

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

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

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

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

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

    
724
				$multiple = ($field['multiple'] == "yes");
725

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

    
733
				$options = array();
734
				$selected = array();
735

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

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

    
747
				}
748

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

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

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

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

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

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

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

    
802
				break;
803
			case "timezone_select":
804
				$timezonelist = system_get_timezone_list();
805

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

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

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

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

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

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

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

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

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

    
857
$form->add($section);
858
print($form);
859
?>
860

    
861
<script type="text/javascript">
862
//<![CDATA[
863

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

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

    
890
		var customarray=new Array(<?=$aliases; ?>);
891

    
892
		window.onload = function () {
893

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

    
906
//]]>
907
</script>
908

    
909
<?php
910

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

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

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

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

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