Project

General

Profile

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

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

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

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

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

    
79
global $g;
80

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
225

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

    
232
	function enablechange() {
233

    
234
	<?php
235

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

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

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

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

    
263
					}
264
				}
265

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

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

    
279
	}
280

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
450
<!-- Present the pfSense logo -->
451
<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/>
452

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

    
459
<?php
460

    
461
$form = new Form(false);
462

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

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

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

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

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

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

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

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

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

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

    
516
			eval($toeval);
517
		}
518

    
519

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

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

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

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

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

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

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

    
557
				$onchange = "";
558

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

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

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

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

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

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

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

    
592
					$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
593
				}
594

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

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

    
609
					if ($value == $ifname)
610
						array_push($selected, $value);
611

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

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

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

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

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

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

    
655
				$name = strtolower($name);
656

    
657
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
658

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

    
664
					$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
665
				}
666

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

    
670
					if ($value == $name)
671
						$selected = $value;
672

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

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

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

    
698
				$multiple = false;
699
				$name = strtolower($name);
700

    
701
				$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
702

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

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

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

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

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

    
722

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

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

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

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

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

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

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

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

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

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

    
780
				}
781

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

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

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

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

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

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

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

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

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

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

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

    
852
				$section->addInput(new Form_Select(
853
					$name,
854
					$etitle,
855
					($value == "") ? $g['default_timezone'] : $value,
856
					array_combine($timezonelist, $timezonelist)
857
				))->setHelp($field['description']);
858

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

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

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

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

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

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

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

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

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

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

    
923
		window.onload = function () {
924

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

    
937
//]]>
938
</script>
939

    
940
<?php
941

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

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

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

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

    
1018
include("foot.inc");
(227-227/228)