Project

General

Profile

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

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

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

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

    
78
global $g;
79

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

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

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

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

    
107
if (!is_array($pkg)) {
108
	print_info_box_np(sprintf(gettext("ERROR: Could not parse %s/wizards/%s file."), $g['www_path'], $xml));
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
	foreach ($field_split as $f) {
169
		$field_conv .= "['" . $f . "']";
170
	}
171
	if ($field_conv == "") {
172
		return;
173
	}
174
	if ($arraynum != "") {
175
		$field_conv .= "[" . $arraynum . "]";
176
	}
177
	if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
178
		/*
179
		 * item is a checkbox, it should have the value "on"
180
		 * if it was checked
181
		 */
182
		$var = "\$config{$field_conv}";
183
		$text = "if (isset({$var})) unset({$var});";
184
		eval($text);
185
		return;
186
	}
187

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

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

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

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

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

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

    
224

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

    
231
	function enablechange() {
232

    
233
	<?php
234

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

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

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

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

    
262
					}
263
				}
264

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

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

    
278
	}
279

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
451
<!-- Present the pfSense logo -->
452
<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/>
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
//		print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . '<br />');
521
		switch ($field['type']) {
522
			case "input":
523
				if ($field['displayname']) {
524
					$etitle = $field['displayname'];
525

    
526
				} else if (!$field['dontdisplayname']) {
527
					$etitle =  fixup_string($field['name']);
528
				}
529

    
530
				$section->addInput(new Form_Input(
531
					$name,
532
					$etitle,
533
					'text',
534
					$value
535
				))->setHelp($field['description'])
536
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")":"");
537

    
538
				break;
539
			case "text":
540
				$section->addInput(new Form_StaticText(
541
					null,
542
					$field['description']
543
				));
544

    
545
				break;
546
			case "inputalias":
547
				if ($field['displayname']) {
548
					$etitle = $field['displayname'];
549

    
550
				} else if (!$field['dontdisplayname']) {
551
					$etitle =  fixup_string($field['name']);
552
				}
553

    
554
				$onchange = "";
555

    
556
				if ($field['validate']) {
557
					$onchange="FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] . ")";
558
				}
559

    
560
				$section->addInput(new Form_Input(
561
					$name,
562
					$etitle,
563
					'text',
564
					$value
565
				))->setAttribute('autocomplete', 'off')
566
				  ->setOnchange($onchange)
567
				  ->setHelp($field['description']);
568

    
569
				break;
570
			case "interfaces_selection":
571
			case "interface_select":
572

    
573
				$name = strtolower($name);
574
				$options = array();
575
				$selected = array();
576

    
577
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
578

    
579
				if (($field['multiple'] != "") && ($field['multiple'] != "0"))
580
					$multiple = true;
581
				else
582
					$multiple = false;
583

    
584
				if ($field['add_to_interfaces_selection'] != "") {
585
					if ($field['add_to_interfaces_selection'] == $value) {
586
						array_push($selected, $value);
587
					}
588

    
589
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
590
				}
591

    
592
				if ($field['type'] == "interface_select") {
593
					$interfaces = get_interface_list();
594
				} else {
595
					$interfaces = get_configured_interface_with_descr();
596
				}
597

    
598
				foreach ($interfaces as $ifname => $iface) {
599
					if ($field['type'] == "interface_select") {
600
						$iface = $ifname;
601
						if ($iface['mac']) {
602
							$iface .= " ({$iface['mac']})";
603
						}
604
					}
605

    
606
					if ($value == $ifname)
607
						array_push($selected, $value);
608

    
609
					$canecho = 0;
610
					if ($field['interface_filter'] != "") {
611
						if (stristr($ifname, $field['interface_filter']) == true) {
612
							$canecho = 1;
613
						}
614
					} else {
615
						$canecho = 1;
616
					}
617

    
618
					if ($canecho == 1) {
619
						$options[$ifname] = $iface;
620
					}
621
				}
622

    
623
				$section->addInput(new Form_Select(
624
					$name,
625
					$etitle,
626
					($multiple) ? $selected:$selected[0],
627
					$options,
628
					$multiple
629
				))->setHelp($field['description']);
630

    
631
				break;
632
			case "password":
633
				if ($field['displayname']) {
634
					$etitle = $field['displayname'];
635
				} else if (!$field['dontdisplayname']) {
636
					$etitle =  fixup_string($field['name']);
637
				}
638

    
639
				$section->addInput(new Form_Input(
640
					$name,
641
					$etitle,
642
					'password',
643
					$value
644
				))->setHelp($field['description'])
645
				  ->setOnchange(($field['validate']) ? "FieldValidate(this.value, " . $field['validate'] . ", " . $field['message'] .")":"");
646

    
647
				break;
648
			case "certca_selection":
649
				$options = array();
650
				$selected = "";
651

    
652
				$name = strtolower($name);
653

    
654
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
655

    
656
				if ($field['add_to_certca_selection'] != "") {
657
					if ($field['add_to_certca_selection'] == $value) {
658
						$selected = $value;
659
					}
660

    
661
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
662
				}
663

    
664
				foreach ($config['ca'] as $ca) {
665
					$name = htmlspecialchars($ca['descr']);
666

    
667
					if ($value == $name)
668
						$selected = $value;
669

    
670
					$canecho = 0;
671
					if ($field['certca_filter'] != "") {
672
						if (stristr($name, $field['certca_filter']) == true) {
673
							$canecho = 1;
674
						}
675
					} else {
676
						$canecho = 1;
677
					}
678
					if ($canecho == 1) {
679
						$options[$ca['refid']] = $name;
680
					}
681
				}
682

    
683
				$section->addInput(new Form_Select(
684
					$name,
685
					$etitle,
686
					$selected,
687
					$options
688
				))->setHelp($field['description']);
689

    
690
				break;
691
			case "cert_selection":
692
				$options = array();
693
				$selected = array();
694

    
695
				$multiple = false;
696
				$name = strtolower($name);
697

    
698
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
699

    
700
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
701

    
702
				if ($field['add_to_cert_selection'] != "") {
703
					if ($field['add_to_cert_selection'] == $value) {
704
						array_push($selected, $value);
705
					}
706

    
707
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
708
				}
709

    
710
				foreach ($config['cert'] as $ca) {
711
					if (stristr($ca['descr'], "webconf")) {
712
						continue;
713
					}
714

    
715
					$name = htmlspecialchars($ca['descr']);
716

    
717
					if ($value == $name) {
718
						array_push($selected, $value);
719
					}
720

    
721

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

    
731
					if ($canecho == 1) {
732
						$options[$ca['refid']] = $name;
733
					}
734
				}
735

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

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

    
752
				if ($field['size']) {
753
					$size = " size='" . $field['size'] . "' ";
754
				}
755

    
756
				$multiple = ($field['multiple'] == "yes");
757

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

    
765
				$options = array();
766
				$selected = array();
767

    
768
				foreach ($field['options']['option'] as $opt) {
769
					if ($value == $opt['value']) {
770
						array_push($selected, $value);
771
					}
772

    
773
					if ($opt['displayname']) {
774
						$options[$opt['value']] = $opt['displayname'];
775
					} else {
776
						$options[$opt['value']] = $opt['name'];
777
					}
778

    
779
				}
780

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

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

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

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

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

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

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

    
832
				break;
833
			case "timezone_select":
834
				$timezonelist = system_get_timezone_list();
835

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

    
841
				if ($field['displayname']) {
842
					$etitle = $field['displayname'];
843
				} else if (!$field['dontdisplayname']) {
844
					$etitle =  fixup_string($field['name']);
845
				}
846

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

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

    
858
				break;
859
			case "checkbox":
860
				if ($field['displayname']) {
861
					$etitle = $field['displayname'];
862

    
863
				} else if (!$field['dontdisplayname']) {
864
					$etitle =  fixup_string($field['name']);
865
				}
866

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

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

    
882
				break;
883
		} // e-o-switch
884
	} // e-o-foreach(package)
885
} // e-o- if(we have fields)
886

    
887
$form->add($section);
888
print($form);
889
?>
890

    
891
<script type="text/javascript">
892
//<![CDATA[
893

    
894
		if (typeof ext_change != 'undefined') {
895
			ext_change();
896
		}
897
		if (typeof proto_change != 'undefined') {
898
			ext_change();
899
		}
900
		if (typeof proto_change != 'undefined') {
901
			proto_change();
902
		}
903

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

    
920
		var customarray=new Array(<?=$aliases; ?>);
921

    
922
		window.onload = function () {
923

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

    
936
//]]>
937
</script>
938

    
939
<?php
940

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

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

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

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

    
1017
include("foot.inc");
(234-234/235)