Project

General

Profile

Download (27.7 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
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24
 *
25
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29
 *
30
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52
 */
53

    
54
##|+PRIV
55
##|*IDENT=page-pfsensewizardsubsystem
56
##|*NAME=pfSense wizard subsystem
57
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
58
##|*MATCH=wizard.php*
59
##|-PRIV
60

    
61
require_once("globals.inc");
62
require_once("guiconfig.inc");
63
require_once("functions.inc");
64
require_once("filter.inc");
65
require_once("shaper.inc");
66
require_once("rrd.inc");
67
require_once("system.inc");
68

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

    
72
global $g;
73

    
74
$stepid = htmlspecialchars($_GET['stepid']);
75
if (isset($_POST['stepid'])) {
76
	$stepid = htmlspecialchars($_POST['stepid']);
77
}
78

    
79
if (!$stepid) {
80
	$stepid = "0";
81
}
82

    
83
$xml = htmlspecialchars($_GET['xml']);
84
if ($_POST['xml']) {
85
	$xml = htmlspecialchars($_POST['xml']);
86
}
87

    
88
if (empty($xml)) {
89
	$xml = "not_defined";
90
	print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
91
	die;
92
} else {
93
	$wizard_xml_prefix = "{$g['www_path']}/wizards";
94
	$wizard_full_path = "{$wizard_xml_prefix}/{$xml}";
95
	if (substr_compare(realpath($wizard_full_path), $wizard_xml_prefix, 0, strlen($wizard_xml_prefix))) {
96
		print_info_box(gettext("Invalid path specified."), 'danger');
97
		die;
98
	}
99
	if (file_exists($wizard_full_path)) {
100
		$pkg = parse_xml_config_pkg($wizard_full_path, "pfsensewizard");
101
	} else {
102
		print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
103
		die;
104
	}
105
}
106

    
107
if (!is_array($pkg)) {
108
	print_info_box(sprintf(gettext("Could not parse %s/wizards/%s file."), $g['www_path'], $xml), 'danger');
109
	die;
110
}
111

    
112
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
113
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
114
$totalsteps	 = $pkg['totalsteps'];
115

    
116
if ($pkg['includefile']) {
117
	require_once($pkg['includefile']);
118
}
119

    
120
if ($pkg['step'][$stepid]['includefile']) {
121
	require_once($pkg['step'][$stepid]['includefile']);
122
}
123

    
124
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
125
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
126
}
127

    
128
if ($_POST && !$input_errors) {
129
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
130
		if (!empty($field['bindstofield']) and $field['type'] != "submit") {
131
			$fieldname = $field['name'];
132
			$fieldname = str_replace(" ", "", $fieldname);
133
			$fieldname = strtolower($fieldname);
134
			// update field with posted values.
135
			if ($field['unsetfield'] != "") {
136
				$unset_fields = "yes";
137
			} else {
138
				$unset_fields = "";
139
			}
140

    
141
			if ($field['arraynum'] != "") {
142
				$arraynum = $field['arraynum'];
143
			} else {
144
				$arraynum = "";
145
			}
146

    
147
			update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
148
		}
149

    
150
	}
151
	// run custom php code embedded in xml config.
152
	if ($pkg['step'][$stepid]['stepsubmitphpaction'] != "") {
153
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
154
	}
155
	if (!$input_errors) {
156
		write_config();
157
	}
158

    
159
	$stepid++;
160
	if ($stepid > $totalsteps) {
161
		$stepid = $totalsteps;
162
	}
163
}
164

    
165
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
166
	global $config;
167
	$field_split = explode("->", $field);
168
	$thisvar = null;
169
	foreach ($field_split as $f) {
170
		$field_conv .= "['" . $f . "']";
171
	}
172
	if ($field_conv == "") {
173
		return;
174
	}
175
	if ($arraynum != "") {
176
		$field_conv .= "[" . $arraynum . "]";
177
	}
178
	if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
179
		/*
180
		 * item is a checkbox, it should have the value "on"
181
		 * if it was checked
182
		 */
183
		$var = "\$config{$field_conv}";
184
		$text = "if (isset({$var})) unset({$var});";
185
		eval($text);
186
		return;
187
	}
188

    
189
	if ($field_type == "interfaces_selection") {
190
		$var = "\$config{$field_conv}";
191
		$text = "if (isset({$var})) unset({$var});";
192
		$text .= "\$thisvar = &\$config" . $field_conv . ";";
193
		eval($text);
194
		$thisvar = $updatetext;
195
		return;
196
	}
197

    
198
	if ($unset == "yes") {
199
		$text = "unset(\$config" . $field_conv . ");";
200
		eval($text);
201
	}
202
	$text .= "\$thisvar = &\$config" . $field_conv . ";";
203
	eval($text);
204
	$thisvar = $updatetext;
205
}
206

    
207
$title	   = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
208
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
209

    
210
// handle before form display event.
211
do {
212
	$oldstepid = $stepid;
213
	if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
214
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
215
	}
216
} while ($oldstepid != $stepid);
217

    
218
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
219
$pglinks = array("", "wizard.php?xml=" . $xml);
220
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
221
$pglinks[] = ($stepid > 0 ? "wizard.php?xml=" . $xml . "&stepid=" . $stepid:'&nbsp;');
222
$shortcut_section = "Wizard";
223
include("head.inc");
224

    
225
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
226
<script type="text/javascript">
227
//<![CDATA[
228

    
229

    
230
	function FieldValidate(userinput, regexp, message) {
231
		if (!userinput.match(regexp)) {
232
			alert(message);
233
		}
234
	}
235

    
236
	function enablechange() {
237

    
238
	<?php
239

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

    
244
				if (isset($field['enablefields'])) {
245
					$enablefields = explode(',', $field['enablefields']);
246
					foreach ($enablefields as $enablefield) {
247
						$enablefield = strtolower($enablefield);
248
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
249
					}
250
				}
251

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

    
260
				print "\t" . '} else {' . "\n";
261
				if (isset($field['enablefields'])) {
262
					$enablefields = explode(',', $field['enablefields']);
263
					foreach ($enablefields as $enablefield) {
264
						$enablefield = strtolower($enablefield);
265
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
266

    
267
					}
268
				}
269

    
270
			if (isset($field['checkdisablefields'])) {
271
				$checkenablefields = explode(',', $field['checkdisablefields']);
272
				foreach ($checkenablefields as $checkenablefield) {
273
					$checkenablefield = strtolower($checkenablefield);
274
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
275
					}
276
				}
277

    
278
				print "\t" . '}' . "\n";
279
			}
280
		}
281
	?>
282

    
283
	}
284

    
285
	function disablechange() {
286
	<?php
287
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
288
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
289

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

    
292
				if (isset($field['disablefields'])) {
293
					$enablefields = explode(',', $field['disablefields']);
294
					foreach ($enablefields as $enablefield) {
295
						$enablefield = strtolower($enablefield);
296

    
297
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
298
					}
299
				}
300
				if (isset($field['checkdisablefields'])) {
301
					$checkenablefields = explode(',', $field['checkdisablefields']);
302
					foreach ($checkenablefields as $checkenablefield) {
303
						$checkenablefield = strtolower($checkenablefield);
304
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
305
					}
306
				}
307
				print "\t" . '} else {' . "\n";
308
				if (isset($field['disablefields'])) {
309
					$enablefields = explode(',', $field['disablefields']);
310
					foreach ($enablefields as $enablefield) {
311
						$enablefield = strtolower($enablefield);
312
						print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
313
					}
314
				}
315
				if (isset($field['checkdisablefields'])) {
316
					$checkenablefields = explode(',', $field['checkdisablefields']);
317
					foreach ($checkenablefields as $checkenablefield) {
318
						$checkenablefield = strtolower($checkenablefield);
319
						print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
320
					}
321
				}
322
				print "\t" . '}' . "\n";
323
			}
324
		}
325
	?>
326
	}
327

    
328
	function showchange() {
329
<?php
330
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
331
			if (isset($field['showfields'])) {
332
				print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
333
				if (isset($field['showfields'])) {
334
					$showfields = explode(',', $field['showfields']);
335
					foreach ($showfields as $showfield) {
336
						$showfield = strtolower($showfield);
337
						//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
338
						print "\t\t $('#". $showfield . "').hide();";
339
					}
340
				}
341
				print "\t" . '} else {' . "\n";
342
				if (isset($field['showfields'])) {
343
					$showfields = explode(',', $field['showfields']);
344
					foreach ($showfields as $showfield) {
345
						$showfield = strtolower($showfield);
346
						#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
347
						print "\t\t $('#". $showfield . "').show();";
348
					}
349
				}
350
				print "\t" . '}' . "\n";
351
			}
352
		}
353
?>
354
	}
355

    
356
//]]>
357
</script>
358
<?php }
359

    
360
function fixup_string($string) {
361
	global $config, $g, $myurl, $title;
362
	$newstring = $string;
363
	// fixup #1: $myurl -> http[s]://ip_address:port/
364
	switch ($config['system']['webgui']['protocol']) {
365
		case "http":
366
			$proto = "http";
367
			break;
368
		case "https":
369
			$proto = "https";
370
			break;
371
		default:
372
			$proto = "http";
373
			break;
374
	}
375
	$port = $config['system']['webgui']['port'];
376
	if ($port != "") {
377
		if (($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
378
			$urlport = ":" . $port;
379
		} elseif ($port != "80" and $port != "443") {
380
			$urlport = ":" . $port;
381
		} else {
382
			$urlport = "";
383
		}
384
	}
385

    
386
	$http_host = $_SERVER['HTTP_HOST'];
387
	$urlhost = $http_host;
388
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
389
	if ($title == "Reload in progress") {
390
		if (is_ipaddr($urlhost)) {
391
			$host_if = find_ip_interface($urlhost);
392
			if ($host_if) {
393
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
394
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) {
395
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
396
				}
397
			}
398
		} else if ($urlhost == $config['system']['hostname']) {
399
			$urlhost = $config['wizardtemp']['system']['hostname'];
400
		} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
401
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
402
		}
403
	}
404

    
405
	if ($urlhost != $http_host) {
406
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
407
	}
408

    
409
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
410

    
411
	if (strstr($newstring, "\$myurl")) {
412
		$newstring = str_replace("\$myurl", $myurl, $newstring);
413
	}
414
	// fixup #2: $wanip
415
	if (strstr($newstring, "\$wanip")) {
416
		$curwanip = get_interface_ip();
417
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
418
	}
419
	// fixup #3: $lanip
420
	if (strstr($newstring, "\$lanip")) {
421
		$lanip = get_interface_ip("lan");
422
		$newstring = str_replace("\$lanip", $lanip, $newstring);
423
	}
424
	// fixup #4: fix'r'up here.
425
	return $newstring;
426
}
427

    
428
function is_timezone($elt) {
429
	return !preg_match("/\/$/", $elt);
430
}
431

    
432
if ($title == "Reload in progress") {
433
	$ip = fixup_string("\$myurl");
434
} else {
435
	$ip = "/";
436
}
437

    
438
if ($input_errors) {
439
	print_input_errors($input_errors);
440
}
441
if ($savemsg) {
442
	print_info_box($savemsg, 'success');
443
}
444
if ($_GET['message'] != "") {
445
	print_info_box(htmlspecialchars($_GET['message']));
446
}
447
if ($_POST['message'] != "") {
448
	print_info_box(htmlspecialchars($_POST['message']));
449
}
450

    
451
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
452
?>
453

    
454
<!-- Draw a progress bar to show step progress -->
455
<div class="progress">
456
	<div class="progress-bar" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%">
457
	</div>
458
</div>
459

    
460
<?php
461

    
462
$form = new Form(false);
463

    
464
$form->addGlobal(new Form_Input(
465
	'stepid',
466
	null,
467
	'hidden',
468
	$stepid
469
));
470

    
471
$form->addGlobal(new Form_Input(
472
	'xml',
473
	null,
474
	'hidden',
475
	$xml
476
));
477

    
478
$section = new Form_Section(fixup_string($title));
479

    
480
if ($description) {
481
	$section->addInput(new Form_StaticText(
482
		null,
483
		fixup_string($description)
484
	));
485
}
486

    
487
$inputaliases = array();
488
if ($pkg['step'][$stepid]['fields']['field'] != "") {
489
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
490

    
491
		$value = $field['value'];
492
		$name  = $field['name'];
493

    
494
		$name = preg_replace("/\s+/", "", $name);
495
		$name = strtolower($name);
496

    
497
		if ($field['bindstofield'] != "") {
498
			$arraynum = "";
499
			$field_conv = "";
500
			$field_split = explode("->", $field['bindstofield']);
501
			// arraynum is used in cases where there is an array of the same field
502
			// name such as dnsserver (2 of them)
503
			if ($field['arraynum'] != "") {
504
				$arraynum = "[" . $field['arraynum'] . "]";
505
			}
506

    
507
			foreach ($field_split as $f) {
508
				$field_conv .= "['" . $f . "']";
509
			}
510

    
511
			if ($field['type'] == "checkbox") {
512
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
513
			} else {
514
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
515
			}
516

    
517
			eval($toeval);
518
		}
519

    
520

    
521
		if (DEBUG) {
522
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
523
		}
524

    
525
		switch ($field['type']) {
526
			case "input":
527
				if ($field['displayname']) {
528
					$etitle = $field['displayname'];
529

    
530
				} else if (!$field['dontdisplayname']) {
531
					$etitle =  fixup_string($field['name']);
532
				}
533

    
534
				$section->addInput(new Form_Input(
535
					$name,
536
					$etitle,
537
					'text',
538
					$value
539
				))->setHelp($field['description'])
540
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
541

    
542
				break;
543
			case "text":
544
				$section->addInput(new Form_StaticText(
545
					null,
546
					$field['description']
547
				));
548

    
549
				break;
550
			case "inputalias":
551
				if ($field['displayname']) {
552
					$etitle = $field['displayname'];
553

    
554
				} else if (!$field['dontdisplayname']) {
555
					$etitle =  fixup_string($field['name']);
556
				}
557

    
558
				$onchange = "";
559

    
560
				if ($field['validate']) {
561
					$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
562
				}
563

    
564
				$section->addInput(new Form_Input(
565
					$name,
566
					$etitle,
567
					'text',
568
					$value
569
				))->setAttribute('autocomplete', 'off')
570
				  ->setOnchange($onchange)
571
				  ->setHelp($field['description']);
572

    
573
				break;
574
			case "interfaces_selection":
575
			case "interface_select":
576

    
577
				$name = strtolower($name);
578
				$options = array();
579
				$selected = array();
580

    
581
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
582

    
583
				if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
584
					$multiple = true;
585
				} else {
586
					$multiple = false;
587
				}
588

    
589
				if ($field['add_to_interfaces_selection'] != "") {
590
					if ($field['add_to_interfaces_selection'] == $value) {
591
						array_push($selected, $value);
592
					}
593

    
594
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
595
				}
596

    
597
				if ($field['type'] == "interface_select") {
598
					$interfaces = get_interface_list();
599
				} else {
600
					$interfaces = get_configured_interface_with_descr();
601
				}
602

    
603
				foreach ($interfaces as $ifname => $iface) {
604
					if ($field['type'] == "interface_select") {
605
						$iface = $ifname;
606
						if ($iface['mac']) {
607
							$iface .= " ({$iface['mac']})";
608
						}
609
					}
610

    
611
					if ($value == $ifname) {
612
						array_push($selected, $value);
613
					}
614

    
615
					$canecho = 0;
616
					if ($field['interface_filter'] != "") {
617
						if (stristr($ifname, $field['interface_filter']) == true) {
618
							$canecho = 1;
619
						}
620
					} else {
621
						$canecho = 1;
622
					}
623

    
624
					if ($canecho == 1) {
625
						$options[$ifname] = $iface;
626
					}
627
				}
628

    
629
				$section->addInput(new Form_Select(
630
					$name,
631
					$etitle,
632
					($multiple) ? $selected:$selected[0],
633
					$options,
634
					$multiple
635
				))->setHelp($field['description']);
636

    
637
				break;
638
			case "password":
639
				if ($field['displayname']) {
640
					$etitle = $field['displayname'];
641
				} else if (!$field['dontdisplayname']) {
642
					$etitle =  fixup_string($field['name']);
643
				}
644

    
645
				$section->addInput(new Form_Input(
646
					$name,
647
					$etitle,
648
					'password',
649
					$value
650
				))->setHelp($field['description'])
651
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
652

    
653
				break;
654
			case "certca_selection":
655
				$options = array();
656
				$selected = "";
657

    
658
				$name = strtolower($name);
659

    
660
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
661

    
662
				if ($field['add_to_certca_selection'] != "") {
663
					if ($field['add_to_certca_selection'] == $value) {
664
						$selected = $value;
665
					}
666

    
667
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
668
				}
669

    
670
				foreach ($config['ca'] as $ca) {
671
					$caname = htmlspecialchars($ca['descr']);
672

    
673
					if ($value == $caname) {
674
						$selected = $value;
675
					}
676

    
677
					$canecho = 0;
678
					if ($field['certca_filter'] != "") {
679
						if (stristr($caname, $field['certca_filter']) == true) {
680
							$canecho = 1;
681
						}
682
					} else {
683
						$canecho = 1;
684
					}
685
					if ($canecho == 1) {
686
						$options[$ca['refid']] = $caname;
687
					}
688
				}
689

    
690
				$section->addInput(new Form_Select(
691
					$name,
692
					$etitle,
693
					$selected,
694
					$options
695
				))->setHelp($field['description']);
696

    
697
				break;
698
			case "cert_selection":
699
				$options = array();
700
				$selected = array();
701

    
702
				$multiple = false;
703
				$name = strtolower($name);
704

    
705
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
706

    
707
				if ($field['add_to_cert_selection'] != "") {
708
					if ($field['add_to_cert_selection'] == $value) {
709
						array_push($selected, $value);
710
					}
711

    
712
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
713
				}
714

    
715
				foreach ($config['cert'] as $ca) {
716
					if (stristr($ca['descr'], "webconf")) {
717
						continue;
718
					}
719

    
720
					$caname = htmlspecialchars($ca['descr']);
721

    
722
					if ($value == $caname) {
723
						array_push($selected, $value);
724
					}
725

    
726

    
727
					$canecho = 0;
728
					if ($field['cert_filter'] != "") {
729
						if (stristr($caname, $field['cert_filter']) == true) {
730
							$canecho = 1;
731
						}
732
					} else {
733
						$canecho = 1;
734
					}
735

    
736
					if ($canecho == 1) {
737
						$options[$ca['refid']] = $caname;
738
					}
739
				}
740

    
741
				$section->addInput(new Form_Select(
742
					$name,
743
					$etitle,
744
					($multiple) ? $selected:$selected[0],
745
					$options,
746
					$multiple
747
				))->setHelp($field['description']);
748

    
749
				break;
750
			case "select":
751
				if ($field['displayname']) {
752
					$etitle = $field['displayname'];
753
				} else if (!$field['dontdisplayname']) {
754
					$etitle =  fixup_string($field['name']);
755
				}
756

    
757
				if ($field['size']) {
758
					$size = " size='" . $field['size'] . "' ";
759
				}
760

    
761
				$multiple = ($field['multiple'] == "yes");
762

    
763
				$onchange = "";
764
				foreach ($field['options']['option'] as $opt) {
765
					if ($opt['enablefields'] != "") {
766
						$onchange = "Javascript:enableitems(this.selectedIndex);";
767
					}
768
				}
769

    
770
				$options = array();
771
				$selected = array();
772

    
773
				foreach ($field['options']['option'] as $opt) {
774
					if ($value == $opt['value']) {
775
						array_push($selected, $value);
776
					}
777

    
778
					if ($opt['displayname']) {
779
						$options[$opt['value']] = $opt['displayname'];
780
					} else {
781
						$options[$opt['value']] = $opt['name'];
782
					}
783

    
784
				}
785

    
786
				$section->addInput(new Form_Select(
787
					$name,
788
					$etitle,
789
					($multiple) ? $selected:$selected[0],
790
					$options,
791
					$multiple
792
				))->setHelp($field['description'])->setOnchange($onchange);
793

    
794
				break;
795
			case "textarea":
796
				if ($field['displayname']) {
797
					$etitle = $field['displayname'];
798
				} else if (!$field['dontdisplayname']) {
799
					$etitle =  fixup_string($field['name']);
800
				}
801

    
802
				$section->addInput(new Form_Textarea(
803
					$name,
804
					$etitle,
805
					$value
806
				))->setHelp($field['description'])
807
				  ->setAttribute('rows', $field['rows'])
808
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
809

    
810
				break;
811
			case "submit":
812
				$form->addGlobal(new Form_Button(
813
					$name,
814
					$field['name'],
815
					null,
816
					'fa-angle-double-right'
817
				))->addClass('btn-primary');
818

    
819
				break;
820
			case "listtopic":
821
				$form->add($section);
822
				$section = new Form_Section($field['name']);
823

    
824
				break;
825
			case "subnet_select":
826
				if ($field['displayname']) {
827
					$etitle = $field['displayname'];
828
				} else /* if (!$field['dontdisplayname']) */ {
829
					$etitle =  fixup_string($field['name']);
830
				}
831

    
832
				$section->addInput(new Form_Select(
833
					$name,
834
					$etitle,
835
					$value,
836
					array_combine(range(32, 1, -1), range(32, 1, -1))
837
				))->setHelp($field['description']);
838

    
839
				break;
840
			case "timezone_select":
841
				$timezonelist = system_get_timezone_list();
842

    
843
				/* kill carriage returns */
844
				for ($x = 0; $x < count($timezonelist); $x++) {
845
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
846
				}
847

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

    
854
				if (!$field['dontcombinecells']) {
855
					//echo "<td class=\"vtable\">";
856
				}
857

    
858
				$section->addInput(new Form_Select(
859
					$name,
860
					$etitle,
861
					($value == "") ? $g['default_timezone'] : $value,
862
					array_combine($timezonelist, $timezonelist)
863
				))->setHelp($field['description']);
864

    
865
				break;
866
			case "checkbox":
867
				if ($field['displayname']) {
868
					$etitle = $field['displayname'];
869

    
870
				} else if (!$field['dontdisplayname']) {
871
					$etitle =  fixup_string($field['name']);
872
				}
873

    
874
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
875
					$onclick = "enablechange()";
876
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
877
					$onclick = "disablechange()";
878
				}
879

    
880
				$section->addInput(new Form_Checkbox(
881
					$name,
882
					$etitle,
883
					$field['typehint'],
884
					($value != ""),
885
					'on'
886
				))->setHelp($field['description'])
887
				  ->setOnclick($onclick);
888

    
889
				break;
890
		} // e-o-switch
891
	} // e-o-foreach (package)
892
} // e-o-if (we have fields)
893

    
894
$form->add($section);
895
print($form);
896
?>
897

    
898
<script type="text/javascript">
899
//<![CDATA[
900

    
901
		if (typeof ext_change != 'undefined') {
902
			ext_change();
903
		}
904
		if (typeof proto_change != 'undefined') {
905
			ext_change();
906
		}
907
		if (typeof proto_change != 'undefined') {
908
			proto_change();
909
		}
910

    
911
	<?php
912
		$isfirst = 0;
913
		$aliases = "";
914
		$addrisfirst = 0;
915
		$aliasesaddr = "";
916
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
917
			foreach ($config['aliases']['alias'] as $alias_name) {
918
				if ($isfirst == 1) {
919
					$aliases .= ",";
920
				}
921
				$aliases .= "'" . $alias_name['name'] . "'";
922
				$isfirst = 1;
923
			}
924
		}
925
	?>
926

    
927
		var customarray=new Array(<?=$aliases; ?>);
928

    
929
		window.onload = function () {
930

    
931
<?php
932
		$counter = 0;
933
		foreach ($inputaliases as $alias) {
934
?>
935
			$('#' + '<?=$alias;?>').autocomplete({
936
				source: customarray
937
			});
938
<?php
939
		}
940
?>
941
	}
942

    
943
//]]>
944
</script>
945

    
946
<?php
947

    
948
$fieldnames_array = Array();
949
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] != "") {
950
	// create a fieldname loop that can be used with javascript
951
	// hide and enable features.
952
	echo "\n<script type=\"text/javascript\">\n";
953
	echo "//<![CDATA[\n";
954
	echo "function disableall() {\n";
955
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
956
		if ($field['type'] != "submit" and $field['type'] != "listtopic") {
957
			if (!$field['donotdisable'] != "") {
958
				array_push($fieldnames_array, $field['name']);
959
				$fieldname = preg_replace("/\s+/", "", $field['name']);
960
				$fieldname = strtolower($fieldname);
961
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
962
			}
963
		}
964
	}
965
	echo "}\ndisableall();\n";
966
	echo "function enableitems(selectedindex) {\n";
967
	echo "disableall();\n";
968
	$idcounter = 0;
969
	if ($pkg['step'][$stepid]['fields']['field'] != "") {
970
		echo "\tswitch (selectedindex) {\n";
971
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
972
			if ($field['options']['option'] != "") {
973
				foreach ($field['options']['option'] as $opt) {
974
					if ($opt['enablefields'] != "") {
975
						echo "\t\tcase " . $idcounter . ":\n";
976
						$enablefields_split = explode(",", $opt['enablefields']);
977
						foreach ($enablefields_split as $efs) {
978
							$fieldname = preg_replace("/\s+/", "", $efs);
979
							$fieldname = strtolower($fieldname);
980
							if ($fieldname != "") {
981
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
982
								echo $onchange;
983
							}
984
						}
985
						echo "\t\t\tbreak;\n";
986
					}
987
					$idcounter = $idcounter + 1;
988
				}
989
			}
990
		}
991
		echo "\t}\n";
992
	}
993
	echo "}\n";
994
	echo "//]]>\n";
995
	echo "</script>\n\n";
996
}
997
?>
998

    
999
<script type="text/javascript">
1000
//<![CDATA[
1001
events.push(function() {
1002
	enablechange();
1003
	disablechange();
1004
	showchange();
1005
});
1006
//]]>
1007
</script>
1008

    
1009
<?php
1010
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1011
	// handle after form display event.
1012
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1013
}
1014

    
1015
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
1016
	// handle after form display event.
1017
	echo "\n<script type=\"text/javascript\">\n";
1018
	echo "//<![CDATA[\n";
1019
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1020
	echo "//]]>\n";
1021
	echo "</script>\n\n";
1022
}
1023

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