Project

General

Profile

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

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

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

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

    
74
function gentitle_pkg($pgname) {
75
	global $config;
76
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
77
}
78

    
79
global $g;
80

    
81
$stepid = htmlspecialchars($_GET['stepid']);
82
if (isset($_POST['stepid'])) {
83
	$stepid = htmlspecialchars($_POST['stepid']);
84
}
85

    
86
if (!$stepid) {
87
	$stepid = "0";
88
}
89

    
90
$xml = htmlspecialchars($_GET['xml']);
91
if ($_POST['xml']) {
92
	$xml = htmlspecialchars($_POST['xml']);
93
}
94

    
95
if (empty($xml)) {
96
	$xml = "not_defined";
97
	print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
98
	die;
99
} else {
100
	if (file_exists("{$g['www_path']}/wizards/{$xml}")) {
101
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
102
	} else {
103
		print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
104
		die;
105
	}
106
}
107

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

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

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

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

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

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

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

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

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

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

    
166
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
167
	global $config;
168
	$field_split = explode("->", $field);
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 .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
193
		eval($text);
194
		return;
195
	}
196

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

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

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

    
216
$closehead = false;
217
$pgtitle = array($title);
218
$notitle = true;
219
include("head.inc");
220

    
221
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
222
<script type="text/javascript">
223
//<![CDATA[
224

    
225

    
226
	function FieldValidate(userinput, regexp, message) {
227
		if (!userinput.match(regexp)) {
228
			alert(message);
229
		}
230
	}
231

    
232
	function enablechange() {
233

    
234
	<?php
235

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

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

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

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

    
263
					}
264
				}
265

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

    
274
				print "\t" . '}' . "\n";
275
			}
276
		}
277
	?>
278

    
279
	}
280

    
281
	function disablechange() {
282
	<?php
283
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
284
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
285

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

    
288
				if (isset($field['disablefields'])) {
289
					$enablefields = explode(',', $field['disablefields']);
290
					foreach ($enablefields as $enablefield) {
291
						$enablefield = strtolower($enablefield);
292

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

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

    
352
//]]>
353
</script>
354
<?php }
355

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

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

    
401
	if ($urlhost != $http_host) {
402
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
403
	}
404

    
405
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
406

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

    
424
function is_timezone($elt) {
425
	return !preg_match("/\/$/", $elt);
426
}
427

    
428
require('classes/Form.class.php');
429

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

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

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

    
452
<!-- Present the pfSense logo -->
453
<div style="text-align:center"><p><a href="<?=$ip?>"><img border="0" src="logo-black.png" alt="logo-black" align="middle" height="45" width="180" /></a></p></div><br /><br/>
454

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

    
461
<?php
462

    
463
$form = new Form(false);
464

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

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

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

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

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

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

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

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

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

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

    
518
			eval($toeval);
519
		}
520

    
521

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

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

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

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

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

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

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

    
559
				$onchange = "";
560

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

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

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

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

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

    
584
				if (($field['multiple'] != "") && ($field['multiple'] != "0"))
585
					$multiple = true;
586
				else
587
					$multiple = false;
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
					$canecho = 0;
615
					if ($field['interface_filter'] != "") {
616
						if (stristr($ifname, $field['interface_filter']) == true) {
617
							$canecho = 1;
618
						}
619
					} else {
620
						$canecho = 1;
621
					}
622

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

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

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

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

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

    
657
				$name = strtolower($name);
658

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

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

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

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

    
672
					if ($value == $name)
673
						$selected = $value;
674

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

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

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

    
700
				$multiple = false;
701
				$name = strtolower($name);
702

    
703
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
704

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

    
710
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
711
				}
712

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

    
718
					$name = htmlspecialchars($ca['descr']);
719

    
720
					if ($value == $name) {
721
						array_push($selected, $value);
722
					}
723

    
724

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

    
734
					if ($canecho == 1) {
735
						$options[$ca['refid']] = $name;
736
					}
737
				}
738

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

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

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

    
759
				$multiple = ($field['multiple'] == "yes");
760

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

    
768
				$options = array();
769
				$selected = array();
770

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

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

    
782
				}
783

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

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

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

    
808
				break;
809
			case "submit":
810
				$form->addGlobal(new Form_Button(
811
					$name,
812
					$field['name']
813
				));
814

    
815
				break;
816
			case "listtopic":
817
				$form->add($section);
818
				$section = new Form_Section($field['name']);
819

    
820
				break;
821
			case "subnet_select":
822
				if ($field['displayname']) {
823
					$etitle = $field['displayname'];
824
				} else /* if (!$field['dontdisplayname']) */ {
825
					$etitle =  fixup_string($field['name']);
826
				}
827

    
828
				$section->addInput(new Form_Select(
829
					$name,
830
					$etitle,
831
					$value,
832
					array_combine(range(32, 1, -1), range(32, 1, -1))
833
				))->setHelp($field['description']);
834

    
835
				break;
836
			case "timezone_select":
837
				$timezonelist = system_get_timezone_list();
838

    
839
				/* kill carriage returns */
840
				for ($x = 0; $x < count($timezonelist); $x++) {
841
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
842
				}
843

    
844
				if ($field['displayname']) {
845
					$etitle = $field['displayname'];
846
				} else if (!$field['dontdisplayname']) {
847
					$etitle =  fixup_string($field['name']);
848
				}
849

    
850
				if (!$field['dontcombinecells']) {
851
					//echo "<td class=\"vtable\">";
852
				}
853

    
854
				$section->addInput(new Form_Select(
855
					$name,
856
					$etitle,
857
					$value,
858
					array_combine($timezonelist, $timezonelist)
859
				))->setHelp($field['description']);
860

    
861
				break;
862
			case "checkbox":
863
				if ($field['displayname']) {
864
					$etitle = $field['displayname'];
865

    
866
				} else if (!$field['dontdisplayname']) {
867
					$etitle =  fixup_string($field['name']);
868
				}
869

    
870
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
871
					$onclick = "enablechange()";
872
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
873
					$onclick = "disablechange()";
874
				}
875

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

    
885
				break;
886
		} // e-o-switch
887
	} // e-o-foreach(package)
888
} // e-o- if(we have fields)
889

    
890
$form->add($section);
891
print($form);
892
?>
893

    
894
<script type="text/javascript">
895
//<![CDATA[
896

    
897
		if (typeof ext_change != 'undefined') {
898
			ext_change();
899
		}
900
		if (typeof proto_change != 'undefined') {
901
			ext_change();
902
		}
903
		if (typeof proto_change != 'undefined') {
904
			proto_change();
905
		}
906

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

    
923
		var customarray=new Array(<?=$aliases; ?>);
924

    
925
		window.onload = function () {
926

    
927
<?php
928
		$counter = 0;
929
		foreach ($inputaliases as $alias) {
930
?>
931
			$('#' + '<?php echo $alias; ?>').autocomplete({
932
				source: customarray
933
			});
934
<?php
935
		}
936
?>
937
	}
938

    
939
//]]>
940
</script>
941

    
942
<?php
943

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

    
995
<script type="text/javascript">
996
//<![CDATA[
997
events.push(function(){
998
	enablechange();
999
	disablechange();
1000
	showchange();
1001
});
1002
//]]>
1003
</script>
1004

    
1005
<?php
1006
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
1007
	// handle after form display event.
1008
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
1009
}
1010

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

    
1020
include("foot.inc");
(233-233/234)