Project

General

Profile

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

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

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

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

    
72
global $g;
73

    
74
$stepid = htmlspecialchars($_GET['stepid']);
75
if (isset($_POST['stepid'])) {
76
	$stepid = htmlspecialchars($_POST['stepid']);
77
}
78

    
79
if (!$stepid) {
80
	$stepid = "0";
81
}
82

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

    
88
if (empty($xml)) {
89
	$xml = "not_defined";
90
	print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
91
	die;
92
} else {
93
	$wizard_xml_prefix = "{$g['www_path']}/wizards";
94
	$wizard_full_path = "{$wizard_xml_prefix}/{$xml}";
95
	if (substr_compare(realpath($wizard_full_path), $wizard_xml_prefix, 0, strlen($wizard_xml_prefix))) {
96
		print_info_box(gettext("Invalid path specified."), 'danger');
97
		die;
98
	}
99
	if (file_exists($wizard_full_path)) {
100
		$pkg = parse_xml_config_pkg($wizard_full_path, "pfsensewizard");
101
	} else {
102
		print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
103
		die;
104
	}
105
}
106

    
107
if (!is_array($pkg)) {
108
	print_info_box(sprintf(gettext("Could not parse %s/wizards/%s file."), $g['www_path'], $xml), 'danger');
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
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title']));	//First step is main title of the wizard in the breadcrumb
216
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):'&nbsp;');		//Following steps are sub-level breadcrumbs.
217
$shortcut_section = "Wizard";
218
include("head.inc");
219

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

    
224

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

    
231
	function enablechange() {
232

    
233
	<?php
234

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

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

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

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

    
262
					}
263
				}
264

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

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

    
278
	}
279

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
455
<?php
456

    
457
$form = new Form(false);
458

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

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

    
473
$section = new Form_Section(fixup_string($title));
474

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

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

    
486
		$value = $field['value'];
487
		$name  = $field['name'];
488

    
489
		$name = preg_replace("/\s+/", "", $name);
490
		$name = strtolower($name);
491

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

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

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

    
512
			eval($toeval);
513
		}
514

    
515

    
516
		if (DEBUG) {
517
			print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
518
		}
519

    
520
		switch ($field['type']) {
521
			case "input":
522
				if ($field['displayname']) {
523
					$etitle = $field['displayname'];
524

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

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

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

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

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

    
553
				$onchange = "";
554

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
653
				$name = strtolower($name);
654

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

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

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

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

    
668
					if ($value == $caname) {
669
						$selected = $value;
670
					}
671

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

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

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

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

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

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

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

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

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

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

    
721

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

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

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

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

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

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

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

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

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

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

    
779
				}
780

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

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

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

    
805
				break;
806
			case "submit":
807
				$form->addGlobal(new Form_Button(
808
					$name,
809
					$field['name'],
810
					null,
811
					'fa-angle-double-right'
812
				))->addClass('btn-primary');
813

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
924
		window.onload = function () {
925

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

    
938
//]]>
939
</script>
940

    
941
<?php
942

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

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

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

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

    
1019
include("foot.inc");
(226-226/227)