Project

General

Profile

Download (27.4 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
// This causes the step #, field type and field name to be printed at the top of the page
74
define(DEBUG, false);
75

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

    
81
global $g;
82

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

    
88
if (!$stepid) {
89
	$stepid = "0";
90
}
91

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
227

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

    
234
	function enablechange() {
235

    
236
	<?php
237

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

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

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

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

    
265
					}
266
				}
267

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

    
276
				print "\t" . '}' . "\n";
277
			}
278
		}
279
	?>
280

    
281
	}
282

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

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

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

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

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

    
354
//]]>
355
</script>
356
<?php }
357

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

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

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

    
407
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
408

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

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

    
430
require('classes/Form.class.php');
431

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

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

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

    
454
<!-- Present the pfSense logo -->
455
<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/>
456

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

    
463
<?php
464

    
465
$form = new Form(false);
466

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

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

    
481
$section = new Form_Section(fixup_string($title));
482

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

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

    
494
		$value = $field['value'];
495
		$name  = $field['name'];
496

    
497
		$name = preg_replace("/\s+/", "", $name);
498
		$name = strtolower($name);
499

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

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

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

    
520
			eval($toeval);
521
		}
522

    
523

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

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

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

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

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

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

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

    
561
				$onchange = "";
562

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

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

    
576
				break;
577
			case "interfaces_selection":
578
			case "interface_select":
579

    
580
				$name = strtolower($name);
581
				$options = array();
582
				$selected = array();
583

    
584
				$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
585

    
586
				if (($field['multiple'] != "") && ($field['multiple'] != "0"))
587
					$multiple = true;
588
				else
589
					$multiple = false;
590

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

    
596
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
597
				}
598

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

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

    
613
					if ($value == $ifname)
614
						array_push($selected, $value);
615

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

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

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

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

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

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

    
659
				$name = strtolower($name);
660

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

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

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

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

    
674
					if ($value == $name)
675
						$selected = $value;
676

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

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

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

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

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

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

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

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

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

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

    
726

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

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

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

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

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

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

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

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

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

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

    
784
				}
785

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

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

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

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

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

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

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

    
837
				break;
838
			case "timezone_select":
839
				$timezonelist = system_get_timezone_list();
840

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

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

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

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

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

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

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

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

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

    
892
$form->add($section);
893
print($form);
894
?>
895

    
896
<script type="text/javascript">
897
//<![CDATA[
898

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

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

    
925
		var customarray=new Array(<?=$aliases; ?>);
926

    
927
		window.onload = function () {
928

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

    
941
//]]>
942
</script>
943

    
944
<?php
945

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

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

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

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

    
1022
include("foot.inc");
(232-232/233)