Project

General

Profile

Download (27.5 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 (file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) {
221
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
222
} else {
223
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
224
}
225

    
226
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
227
<script type="text/javascript">
228
//<![CDATA[
229
events.push(function(){
230
	function FieldValidate(userinput, regexp, message) {
231
		if (!userinput.match(regexp)) {
232
			alert(message);
233
		}
234
	}
235

    
236
	function enablechange() {
237
	<?php
238
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
239
			if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
240
				print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
241
				if (isset($field['enablefields'])) {
242
					$enablefields = explode(',', $field['enablefields']);
243
					foreach ($enablefields as $enablefield) {
244
						$enablefield = strtolower($enablefield);
245
						print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
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" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
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" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
261
					}
262
				}
263
				if (isset($field['checkenablefields'])) {
264
					$checkenablefields = explode(',', $field['checkenablefields']);
265
					foreach ($checkenablefields as $checkenablefield) {
266
						$checkenablefield = strtolower($checkenablefield);
267
						print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
268
					}
269
				}
270
				print "\t" . '}' . "\n";
271
			}
272
		}
273
	?>
274
	}
275

    
276
	function disablechange() {
277
	<?php
278
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
279
			if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
280
				print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
281
				if (isset($field['disablefields'])) {
282
					$enablefields = explode(',', $field['disablefields']);
283
					foreach ($enablefields as $enablefield) {
284
						$enablefield = strtolower($enablefield);
285
						print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
286
					}
287
				}
288
				if (isset($field['checkdisablefields'])) {
289
					$checkenablefields = explode(',', $field['checkdisablefields']);
290
					foreach ($checkenablefields as $checkenablefield) {
291
						$checkenablefield = strtolower($checkenablefield);
292
						print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
293
					}
294
				}
295
				print "\t" . '} else {' . "\n";
296
				if (isset($field['disablefields'])) {
297
					$enablefields = explode(',', $field['disablefields']);
298
					foreach ($enablefields as $enablefield) {
299
						$enablefield = strtolower($enablefield);
300
						print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
301
					}
302
				}
303
				if (isset($field['checkdisablefields'])) {
304
					$checkenablefields = explode(',', $field['checkdisablefields']);
305
					foreach ($checkenablefields as $checkenablefield) {
306
						$checkenablefield = strtolower($checkenablefield);
307
						print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
308
					}
309
				}
310
				print "\t" . '}' . "\n";
311
			}
312
		}
313
	?>
314
	}
315

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

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

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

    
393
	if ($urlhost != $http_host) {
394
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
395
	}
396

    
397
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
398

    
399
	if (strstr($newstring, "\$myurl")) {
400
		$newstring = str_replace("\$myurl", $myurl, $newstring);
401
	}
402
	// fixup #2: $wanip
403
	if (strstr($newstring, "\$wanip")) {
404
		$curwanip = get_interface_ip();
405
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
406
	}
407
	// fixup #3: $lanip
408
	if (strstr($newstring, "\$lanip")) {
409
		$lanip = get_interface_ip("lan");
410
		$newstring = str_replace("\$lanip", $lanip, $newstring);
411
	}
412
	// fixup #4: fix'r'up here.
413
	return $newstring;
414
}
415

    
416
function is_timezone($elt) {
417
	return !preg_match("/\/$/", $elt);
418
}
419

    
420
require('classes/Form.class.php');
421

    
422
if ($title == "Reload in progress") {
423
	$ip = fixup_string("\$myurl");
424
} else {
425
	$ip = "/";
426
}
427

    
428
if ($input_errors) {
429
	print_input_errors($input_errors);
430
}
431
if ($savemsg) {
432
	print_info_box($savemsg, 'success');
433
}
434
if ($_GET['message'] != "") {
435
	print_info_box(htmlspecialchars($_GET['message']));
436
}
437
if ($_POST['message'] != "") {
438
	print_info_box(htmlspecialchars($_POST['message']));
439
}
440

    
441
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
442
?>
443

    
444
<!-- Present the pfSense logo -->
445
<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/>
446

    
447
<!-- Draw a progress bar to show step progress -->
448
<div class="progress">
449
	<div class="progress-bar" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%">
450
	</div>
451
</div>
452

    
453
<?php
454

    
455
$form = new Form(false);
456

    
457
$form->addGlobal(new Form_Input(
458
	'stepid',
459
	null,
460
	'hidden',
461
	$stepid
462
));
463

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

    
471
$section = new Form_Section(fixup_string($title));
472

    
473
if($description) {
474
	$section->addInput(new Form_StaticText(
475
		null,
476
		fixup_string($description)
477
	));
478
}
479

    
480
$inputaliases = array();
481
if ($pkg['step'][$stepid]['fields']['field'] != "") {
482
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
483

    
484
		$value = $field['value'];
485
		$name  = $field['name'];
486

    
487
		$name = preg_replace("/\s+/", "", $name);
488
		$name = strtolower($name);
489

    
490
		if ($field['bindstofield'] != "") {
491
			$arraynum = "";
492
			$field_conv = "";
493
			$field_split = explode("->", $field['bindstofield']);
494
			// arraynum is used in cases where there is an array of the same field
495
			// name such as dnsserver (2 of them)
496
			if ($field['arraynum'] != "") {
497
				$arraynum = "[" . $field['arraynum'] . "]";
498
			}
499

    
500
			foreach ($field_split as $f) {
501
				$field_conv .= "['" . $f . "']";
502
			}
503

    
504
			if ($field['type'] == "checkbox") {
505
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
506
			} else {
507
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
508
			}
509

    
510
			eval($toeval);
511
		}
512

    
513
		switch ($field['type']) {
514
			case "input":
515
				if ($field['displayname']) {
516
					$etitle = $field['displayname'];
517

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

    
522
				$section->addInput(new Form_Input(
523
					$name,
524
					$etitle,
525
					'text',
526
					$value
527
				))->setHelp($field['description'])
528
				  ->setOnchange(($field['validate']) ? 'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':'');
529

    
530
				break;
531
			case "text":
532
				$section->addInput(new Form_StaticText(
533
					null,
534
					$field['description']
535
				));
536

    
537
				break;
538
			case "inputalias":
539
				if ($field['displayname']) {
540
					$etitle = $field['displayname'];
541

    
542
				} else if (!$field['dontdisplayname']) {
543
					$etitle =  fixup_string($field['name']);
544
				}
545

    
546
				$onchange = "";
547

    
548
				if ($field['validate']) {
549
					$onchange="FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
550
				}
551

    
552
				$section->addInput(new Form_Input(
553
					$name,
554
					$etitle,
555
					'text',
556
					$value
557
				))->setAttribute('autocomplete', 'off')
558
				  ->setOnchange($onchange)
559
				  ->setHelp($field['description']);
560

    
561
				break;
562
			case "interfaces_selection":
563
			case "interface_select":
564

    
565
				$name = strtolower($name);
566
				$options = array();
567
				$selected = array();
568

    
569
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
570

    
571
				if (($field['multiple'] != "") && ($field['multiple'] != "0"))
572
					$multiple = true;
573
				else
574
					$multiple = false;
575

    
576
				if ($field['add_to_interfaces_selection'] != "") {
577
					if ($field['add_to_interfaces_selection'] == $value) {
578
						array_push($selected, $value);
579
					}
580

    
581
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
582
				}
583

    
584
				if ($field['type'] == "interface_select") {
585
					$interfaces = get_interface_list();
586
				} else {
587
					$interfaces = get_configured_interface_with_descr();
588
				}
589

    
590
				foreach ($interfaces as $ifname => $iface) {
591
					if ($field['type'] == "interface_select") {
592
						$iface = $ifname;
593
						if ($iface['mac']) {
594
							$iface .= " ({$iface['mac']})";
595
						}
596
					}
597

    
598
					if ($value == $ifname)
599
						array_push($selected, $value);
600

    
601
					$canecho = 0;
602
					if ($field['interface_filter'] != "") {
603
						if (stristr($ifname, $field['interface_filter']) == true) {
604
							$canecho = 1;
605
						}
606
					} else {
607
						$canecho = 1;
608
					}
609

    
610
					if ($canecho == 1) {
611
						$options[$ifname] = $iface;
612
					}
613
				}
614

    
615
				$section->addInput(new Form_Select(
616
					$name,
617
					$etitle,
618
					($multiple) ? $selected:$selected[0],
619
					$options,
620
					$multiple
621
				))->setHelp($field['description']);
622

    
623
				break;
624
			case "password":
625
				if ($field['displayname']) {
626
					$etitle = $field['displayname'];
627
				} else if (!$field['dontdisplayname']) {
628
					$etitle =  fixup_string($field['name']);
629
				}
630

    
631
				$section->addInput(new Form_Input(
632
					$name,
633
					$etitle,
634
					'password',
635
					$value
636
				))->setHelp($field['description'])
637
				  ->setOnchange(($field['validate']) ? 'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':'');
638

    
639
				break;
640
			case "certca_selection":
641
				$options = array();
642
				$selected = "";
643

    
644
				$name = strtolower($name);
645

    
646
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
647

    
648
				if ($field['add_to_certca_selection'] != "") {
649
					if ($field['add_to_certca_selection'] == $value) {
650
						$selected = $value;
651
					}
652

    
653
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
654
				}
655

    
656
				foreach ($config['ca'] as $ca) {
657
					$name = htmlspecialchars($ca['descr']);
658

    
659
					if ($value == $name)
660
						$selected = $value;
661

    
662
					$canecho = 0;
663
					if ($field['certca_filter'] != "") {
664
						if (stristr($name, $field['certca_filter']) == true) {
665
							$canecho = 1;
666
						}
667
					} else {
668
						$canecho = 1;
669
					}
670
					if ($canecho == 1) {
671
						$options[$ca['refid']] = $name;
672
					}
673
				}
674

    
675
				$section->addInput(new Form_Select(
676
					$name,
677
					$etitle,
678
					$selected,
679
					$options
680
				))->setHelp($field['description']);
681

    
682
				break;
683
			case "cert_selection":
684
				$options = array();
685
				$selected = array();
686

    
687
				$multiple = false;
688
				$name = strtolower($name);
689

    
690
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
691

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

    
694
				if ($field['add_to_cert_selection'] != "") {
695
					if ($field['add_to_cert_selection'] == $value) {
696
						array_push($selected, $value);
697
					}
698

    
699
					$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
700
				}
701

    
702
				foreach ($config['cert'] as $ca) {
703
					if (stristr($ca['descr'], "webconf")) {
704
						continue;
705
					}
706

    
707
					$name = htmlspecialchars($ca['descr']);
708

    
709
					if ($value == $name) {
710
						array_push($selected, $value);
711
					}
712

    
713

    
714
					$canecho = 0;
715
					if ($field['cert_filter'] != "") {
716
						if (stristr($name, $field['cert_filter']) == true) {
717
							$canecho = 1;
718
						}
719
					} else {
720
						$canecho = 1;
721
					}
722

    
723
					if ($canecho == 1) {
724
						$options[$ca['refid']] = $name;
725
					}
726
				}
727

    
728
				$section->addInput(new Form_Select(
729
					$name,
730
					$etitle,
731
					($multiple) ? $selected:$selected[0],
732
					$options,
733
					$multiple
734
				))->setHelp($field['description']);
735

    
736
				break;
737
			case "select":
738
				if ($field['displayname']) {
739
					$etitle = $field['displayname'];
740
				} else if (!$field['dontdisplayname']) {
741
					$etitle =  fixup_string($field['name']);
742
				}
743

    
744
				if ($field['size']) {
745
					$size = " size='" . $field['size'] . "' ";
746
				}
747

    
748
				$multiple = ($field['multiple'] == "yes");
749

    
750
				$onchange = "";
751
				foreach ($field['options']['option'] as $opt) {
752
					if ($opt['enablefields'] != "") {
753
						$onchange = "Javascript:enableitems(this.selectedIndex);";
754
					}
755
				}
756

    
757
				$options = array();
758
				$selected = array();
759

    
760
				foreach ($field['options']['option'] as $opt) {
761
					if ($value == $opt['value']) {
762
						array_push($selected, $value);
763
					}
764

    
765
					if ($opt['displayname']) {
766
						$options[$opt['value']] = $opt['displayname'];
767
					} else {
768
						$options[$opt['value']] = $opt['name'];
769
					}
770

    
771
				}
772

    
773
				$section->addInput(new Form_Select(
774
					$name,
775
					$etitle,
776
					($multiple) ? $selected:$selected[0],
777
					$options,
778
					$multiple
779
				))->setHelp($field['description'])->setOnchange($onchange);
780

    
781
				break;
782
			case "textarea":
783
				if ($field['displayname']) {
784
					$etitle = $field['displayname'];
785
				} else if (!$field['dontdisplayname']) {
786
					$etitle =  fixup_string($field['name']);
787
				}
788

    
789
				$section->addInput(new Form_TextArea(
790
					$name,
791
					$etitle,
792
					$value
793
				))->setHelp($field['description'])
794
				  ->setAttribute('rows', $field['rows'])
795
				  ->setOnchange(($field['validate']) ? 'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':'');
796

    
797
				break;
798
			case "submit":
799
				$form->addGlobal(new Form_Button(
800
					$name,
801
					$field['name']
802
				));
803

    
804
				break;
805
			case "listtopic":
806
				$form->add($section);
807
				$section = new Form_Section($field['name']);
808

    
809
				break;
810
			case "subnet_select":
811
				if ($field['displayname']) {
812
					$etitle = $field['displayname'];
813
				} else /* if (!$field['dontdisplayname']) */ {
814
					$etitle =  fixup_string($field['name']);
815
				}
816

    
817
				$section->addInput(new Form_Select(
818
					$name,
819
					$etitle,
820
					$value,
821
					array_combine(range(32, 1, -1), range(32, 1, -1))
822
				))->setHelp($field['description']);
823

    
824
				break;
825
			case "timezone_select":
826
				$timezonelist = system_get_timezone_list();
827

    
828
				/* kill carriage returns */
829
				for ($x = 0; $x < count($timezonelist); $x++) {
830
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
831
				}
832

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

    
839
				if (!$field['dontcombinecells']) {
840
					//echo "<td class=\"vtable\">";
841
				}
842

    
843
				$section->addInput(new Form_Select(
844
					$name,
845
					$etitle,
846
					$value,
847
					array_combine($timezonelist, $timezonelist)
848
				))->setHelp($field['description']);
849

    
850
				break;
851
			case "checkbox":
852
				if ($field['displayname']) {
853
					$etitle = $field['displayname'];
854

    
855
				} else if (!$field['dontdisplayname']) {
856
					$etitle =  fixup_string($field['name']);
857
				}
858

    
859
				if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
860
					$onclick = "Javascript:enablechange()";
861
				} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
862
					$onclick = "Javascript:disablechange()";
863
				}
864

    
865
				$section->addInput(new Form_Checkbox(
866
					$name,
867
					$etitle,
868
					$field['typehint'],
869
					($value != ""),
870
					'on'
871
				))->setHelp($field['description'])
872
				  ->setOnclick($onclick);
873

    
874
				break;
875
		} // e-o-switch
876
	} // e-o-foreach(package)
877
} // e-o- if(we have fields)
878

    
879
$form->add($section);
880
print($form);
881
?>
882

    
883
<script type="text/javascript">
884
//<![CDATA[
885
events.push(function(){
886
		if (typeof ext_change != 'undefined') {
887
			ext_change();
888
		}
889
		if (typeof proto_change != 'undefined') {
890
			ext_change();
891
		}
892
		if (typeof proto_change != 'undefined') {
893
			proto_change();
894
		}
895

    
896
	<?php
897
		$isfirst = 0;
898
		$aliases = "";
899
		$addrisfirst = 0;
900
		$aliasesaddr = "";
901
		if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
902
			foreach ($config['aliases']['alias'] as $alias_name) {
903
				if ($isfirst == 1) {
904
					$aliases .= ",";
905
				}
906
				$aliases .= "'" . $alias_name['name'] . "'";
907
				$isfirst = 1;
908
			}
909
		}
910
	?>
911

    
912
		var customarray=new Array(<?=$aliases; ?>);
913

    
914
		window.onload = function () {
915

    
916
<?php
917
		$counter = 0;
918
		foreach ($inputaliases as $alias) {
919
?>
920
			$('#' + '<?php echo $alias; ?>').autocomplete({
921
				source: customarray
922
			});
923
<?php
924
		}
925
?>
926
	}
927
});
928
//]]>
929
</script>
930

    
931
<?php
932

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

    
984
<script type="text/javascript">
985
//<![CDATA[
986
	enablechange();
987
	disablechange();
988
	showchange();
989
//]]>
990
</script>
991

    
992
<?php
993
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
994
	// handle after form display event.
995
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
996
}
997

    
998
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
999
	// handle after form display event.
1000
	echo "\n<script type=\"text/javascript\">\n";
1001
	echo "//<![CDATA[\n";
1002
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
1003
	echo "//]]>\n";
1004
	echo "</script>\n\n";
1005
}
1006

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