Projet

Général

Profil

Télécharger (30,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / wizard.php @ c5a12cde

1
<?php
2
/* $Id$ */
3
/*
4
	wizard.php
5
	Copyright (C) 2004 Scott Ullrich
6
	Copyright (C) 2010 Ermal Luçi
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 the
17
	   documentation and/or other materials provided with the distribution.
18

    
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30

    
31
##|+PRIV
32
##|*IDENT=page-pfsensewizardsubsystem
33
##|*NAME=pfSense wizard subsystem page
34
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
35
##|*MATCH=wizard.php*
36
##|-PRIV
37

    
38

    
39
require("globals.inc");
40
require("guiconfig.inc");
41
require("functions.inc");
42
require_once("filter.inc");
43
require("shaper.inc");
44
require_once("rrd.inc");
45

    
46
function gentitle_pkg($pgname) {
47
	global $config;
48
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
49
}
50

    
51
global $g;
52

    
53
$stepid = htmlspecialchars($_GET['stepid']);
54
if (isset($_POST['stepid']))
55
	$stepid = htmlspecialchars($_POST['stepid']);
56
if (!$stepid)
57
	$stepid = "0";
58

    
59
$xml = htmlspecialchars($_GET['xml']);
60
if($_POST['xml'])
61
	$xml = htmlspecialchars($_POST['xml']);
62

    
63
if(empty($xml)) {
64
	$xml = "not_defined";
65
	print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
66
	die;
67
} else {
68
	if (file_exists("{$g['www_path']}/wizards/{$xml}"))
69
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
70
	else {
71
		print_info_box_np(sprintf(gettext("ERROR:  Could not open %s."), $xml));
72
		die;
73
	}
74
}
75

    
76
if (!is_array($pkg)) {
77
	print_info_box_np(sprintf(gettext("ERROR: Could not parse %s/wizards/%s file."),$g['www_path'],$xml));
78
	die;
79
}
80

    
81
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
82
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
83
$totalsteps  = $pkg['totalsteps'];
84

    
85
if ($pkg['includefile'])
86
	require_once($pkg['includefile']);
87

    
88
if ($pkg['step'][$stepid]['includefile'])
89
	require_once($pkg['step'][$stepid]['includefile']);
90

    
91
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
92
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
93
}
94

    
95
if ($_POST && !$input_errors) {
96
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
97
		if(!empty($field['bindstofield']) and $field['type'] <> "submit") {
98
			$fieldname = $field['name'];
99
			$fieldname = str_replace(" ", "", $fieldname);
100
			$fieldname = strtolower($fieldname);
101
			// update field with posted values.
102
			if($field['unsetfield'] <> "")
103
				$unset_fields = "yes";
104
			else
105
				$unset_fields = "";
106
			if($field['arraynum'] <> "")
107
				$arraynum = $field['arraynum'];
108
			else
109
				$arraynum = "";
110

    
111
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
112
		}
113

    
114
	}
115
	// run custom php code embedded in xml config.
116
	if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
117
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
118
	}
119
	if (!$input_errors)
120
		write_config();
121
	$stepid++;
122
	if($stepid > $totalsteps)
123
		$stepid = $totalsteps;
124
}
125

    
126
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
127
	global $config;
128
	$field_split = explode("->",$field);
129
	foreach ($field_split as $f)
130
		$field_conv .= "['" . $f . "']";
131
	if($field_conv == "")
132
		return;
133
	if ($arraynum <> "")
134
		$field_conv .= "[" . $arraynum . "]";
135
	if(($field_type == "checkbox" and $updatetext <> "on") || $updatetext == "") {
136
		/*
137
		 * item is a checkbox, it should have the value "on"
138
		 * if it was checked
139
		 */
140
		$var = "\$config{$field_conv}";
141
		$text = "if (isset({$var})) unset({$var});";
142
		eval($text);
143
		return;
144
	}
145

    
146
	if($field_type == "interfaces_selection") {
147
		$var = "\$config{$field_conv}";
148
		$text = "if (isset({$var})) unset({$var});";
149
		$text .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
150
		eval($text);
151
		return;
152
	}
153

    
154
	if($unset == "yes") {
155
		$text = "unset(\$config" . $field_conv . ");";
156
		eval($text);
157
	}
158
	$text = "\$config" . $field_conv . " = \"" . addslashes($updatetext) . "\";";
159
	eval($text);
160
}
161

    
162
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
163
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
164

    
165
// handle before form display event.
166
do {
167
	$oldstepid = $stepid;
168
	if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "")
169
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
170
} while ($oldstepid != $stepid);
171

    
172
$closehead = false;
173
$pgtitle = array($title);
174
include("head.inc");
175

    
176
if(file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css"))
177
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
178
else
179
	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
180
?>
181
</head>
182
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
183

    
184
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
185
<script type="text/javascript">
186
//<![CDATA[
187

    
188
function  FieldValidate(userinput,  regexp,  message)
189
{
190
	if(!userinput.match(regexp))
191
		alert(message);
192
}
193

    
194
function enablechange() {
195
<?php
196
	foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
197
		if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
198
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
199
			if(isset($field['enablefields'])) {
200
				$enablefields = explode(',', $field['enablefields']);
201
				foreach($enablefields as $enablefield) {
202
					$enablefield = strtolower($enablefield);
203
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
204
				}
205
			}
206
			if(isset($field['checkenablefields'])) {
207
				$checkenablefields = explode(',', $field['checkenablefields']);
208
				foreach($checkenablefields as $checkenablefield) {
209
					$checkenablefield = strtolower($checkenablefield);
210
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
211
				}
212
			}
213
			print "\t" . '} else {' . "\n";
214
			if(isset($field['enablefields'])) {
215
				$enablefields = explode(',', $field['enablefields']);
216
				foreach($enablefields as $enablefield) {
217
					$enablefield = strtolower($enablefield);
218
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
219
				}
220
			}
221
			if(isset($field['checkenablefields'])) {
222
				$checkenablefields = explode(',', $field['checkenablefields']);
223
				foreach($checkenablefields as $checkenablefield) {
224
					$checkenablefield = strtolower($checkenablefield);
225
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
226
				}
227
			}
228
			print "\t" . '}' . "\n";
229
		}
230
	}
231
?>
232
}
233

    
234
function disablechange() {
235
<?php
236
	foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
237
		if(isset($field['disablefields']) or isset($field['checkdisablefields'])) {
238
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
239
			if(isset($field['disablefields'])) {
240
				$enablefields = explode(',', $field['disablefields']);
241
				foreach($enablefields as $enablefield) {
242
					$enablefield = strtolower($enablefield);
243
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
244
				}
245
			}
246
			if(isset($field['checkdisablefields'])) {
247
				$checkenablefields = explode(',', $field['checkdisablefields']);
248
				foreach($checkenablefields as $checkenablefield) {
249
					$checkenablefield = strtolower($checkenablefield);
250
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
251
				}
252
			}
253
			print "\t" . '} else {' . "\n";
254
			if(isset($field['disablefields'])) {
255
				$enablefields = explode(',', $field['disablefields']);
256
				foreach($enablefields as $enablefield) {
257
					$enablefield = strtolower($enablefield);
258
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
259
				}
260
			}
261
			if(isset($field['checkdisablefields'])) {
262
				$checkenablefields = explode(',', $field['checkdisablefields']);
263
				foreach($checkenablefields as $checkenablefield) {
264
					$checkenablefield = strtolower($checkenablefield);
265
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
266
				}
267
			}
268
			print "\t" . '}' . "\n";
269
		}
270
	}
271
?>
272
}
273

    
274
function showchange() {
275
<?php
276
	foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
277
		if(isset($field['showfields'])) {
278
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
279
			if(isset($field['showfields'])) {
280
				$showfields = explode(',', $field['showfields']);
281
				foreach($showfields as $showfield) {
282
					$showfield = strtolower($showfield);
283
					//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
284
					print "\t\t jQuery('#". $showfield . "').hide();";
285
				}
286
			}
287
			print "\t" . '} else {' . "\n";
288
			if(isset($field['showfields'])) {
289
				$showfields = explode(',', $field['showfields']);
290
				foreach($showfields as $showfield) {
291
					$showfield = strtolower($showfield);
292
					#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
293
					print "\t\t jQuery('#". $showfield . "').show();";
294
				}
295
			}
296
			print "\t" . '}' . "\n";
297
		}
298
	}
299
?>
300
}
301
//]]>
302
</script>
303
<?php } ?>
304

    
305
<form action="wizard.php" method="post" name="iform" id="iform">
306
<input type="hidden" name="xml" value="<?= htmlspecialchars($xml) ?>" />
307
<input type="hidden" name="stepid" value="<?= htmlspecialchars($stepid) ?>" />
308

    
309
<center>
310

    
311
&nbsp;<br />
312

    
313
<?php
314
	if($title == "Reload in progress") {
315
		$ip = fixup_string("\$myurl");
316
	} else {
317
		$ip = "/";
318
	}
319
	echo "<a href='$ip'>";
320
?>
321
<img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif" alt="logo" /></a>
322
<p>&nbsp;</p>
323
<div style="width:800px;background-color:#ffffff" id="roundme">
324
<?php
325
	if ($input_errors)
326
		print_input_errors($input_errors);
327
	if ($savemsg)
328
		print_info_box($savemsg);
329
	if ($_GET['message'] != "")
330
		print_info_box(htmlspecialchars($_GET['message']));
331
	if ($_POST['message'] != "")
332
		print_info_box(htmlspecialchars($_POST['message']));
333
?>
334
<table bgcolor="#ffffff" width="95%" border="0" cellspacing="0" cellpadding="2" summary="wizard">
335
	<!-- wizard goes here -->
336
	<tr><td>&nbsp;</td></tr>
337
	<tr>
338
		<td class="tabcont">
339
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
340

    
341
				<tr><td colspan="2" align="center"><font size="2"><b><?= fixup_string($description) ?></b></font></td></tr><tr><td>&nbsp;</td></tr>
342
<?php
343
	if(!$pkg['step'][$stepid]['disableheader'])
344
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
345
?>
346

    
347
<?php
348
	$inputaliases = array();
349
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
350
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
351

    
352
			$value = $field['value'];
353
			$name  = $field['name'];
354

    
355
			$name = preg_replace("/\s+/", "", $name);
356
			$name = strtolower($name);
357

    
358
			if($field['bindstofield'] <> "") {
359
				$arraynum = "";
360
				$field_conv = "";
361
				$field_split = explode("->", $field['bindstofield']);
362
				// arraynum is used in cases where there is an array of the same field
363
				// name such as dnsserver (2 of them)
364
				if($field['arraynum'] <> "")
365
					$arraynum = "[" . $field['arraynum'] . "]";
366
				foreach ($field_split as $f)
367
					$field_conv .= "['" . $f . "']";
368
				if($field['type'] == "checkbox")
369
					$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
370
				else
371
					$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
372
				eval($toeval);
373
			}
374

    
375
			if(!$field['combinefieldsend'])
376
				echo "<tr>";
377

    
378
			switch ($field['type']) {
379
			case "input":
380
				if ($field['displayname']) {
381
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
382
					echo $field['displayname'];
383
					echo ":</td>\n";
384
				} else if(!$field['dontdisplayname']) {
385
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
386
					echo fixup_string($field['name']);
387
					echo ":</td>\n";
388
				}
389
				if(!$field['dontcombinecells'])
390
					echo "<td class=\"vtable\">\n";
391

    
392
				echo "<input class='formfld unknown' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\"";
393
				if($field['size'])
394
					echo " size='" . $field['size'] . "' ";
395
				if($field['validate'])
396
					echo " onchange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
397
				echo " />\n";
398

    
399
				if($field['description'] <> "") {
400
					echo "<br /> " . $field['description'];
401
				}
402
				break;
403
			case "text":
404
				echo "<td colspan=\"2\" align=\"center\" class=\"vncell\">\n";
405
				if($field['description'] <> "") {
406
					echo "<center><br /> " . $field['description'] . "</center>";
407
				}
408
				break;
409
			case "inputalias":
410
				if ($field['displayname']) {
411
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
412
					echo $field['displayname'];
413
					echo ":</td>\n";
414
				} else if(!$field['dontdisplayname']) {
415
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
416
					echo fixup_string($field['name']);
417
					echo ":</td>\n";
418
				}
419
				if(!$field['dontcombinecells'])
420
					echo "<td class=\"vtable\">\n";
421

    
422
				$inputaliases[] = $name;
423
				echo "<input class='formfldalias' autocomplete='off' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\"";
424
				if($field['size'])
425
					echo " size='" . $field['size'] . "' ";
426
				if($field['validate'])
427
					echo " onchange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
428
				echo " />\n";
429

    
430
				if($field['description'] <> "") {
431
					echo "<br /> " . $field['description'];
432
				}
433
				break;
434
			case "interfaces_selection":
435
			case "interface_select":
436
				$size = "";
437
				$multiple = "";
438
				$name = strtolower($name);
439
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
440
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
441
				echo "</td>";
442
				echo "<td class=\"vtable\">\n";
443
				if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
444
				if($field['multiple'] <> "" and $field['multiple'] <> "0") {
445
					$multiple = "multiple=\"multiple\"";
446
					$name .= "[]";
447
				}
448
				echo "<select class='formselect' id='{$name}' name='{$name}' {$size} {$multiple}>\n";
449
				if($field['add_to_interfaces_selection'] <> "") {
450
					$SELECTED = "";
451
					if($field['add_to_interfaces_selection'] == $value) $SELECTED = " selected=\"selected\"";
452
					echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
453
				}
454
				if($field['type'] == "interface_select")
455
					$interfaces = get_interface_list();
456
				else
457
					$interfaces = get_configured_interface_with_descr();
458
				foreach ($interfaces as $ifname => $iface) {
459
					if ($field['type'] == "interface_select") {
460
						$iface = $ifname;
461
						if ($iface['mac'])
462
							$iface .= " ({$iface['mac']})";
463
					}
464
					$SELECTED = "";
465
					if ($value == $ifname) $SELECTED = " selected=\"selected\"";
466
					$to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $iface . "</option>\n";
467
					$to_echo .= "<!-- {$value} -->";
468
					$canecho = 0;
469
					if($field['interface_filter'] <> "") {
470
						if(stristr($ifname, $field['interface_filter']) == true)
471
							$canecho = 1;
472
					} else
473
						$canecho = 1;
474
					if($canecho == 1)
475
						echo $to_echo;
476
				}
477
				echo "</select>\n";
478

    
479
				if($field['description'] <> "") {
480
					echo "<br /> " . $field['description'];
481
				}
482

    
483
				break;
484
			case "password":
485
				if ($field['displayname']) {
486
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
487
					echo $field['displayname'];
488
					echo ":</td>\n";
489
				} else if(!$field['dontdisplayname']) {
490
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
491
					echo fixup_string($field['name']);
492
					echo ":</td>\n";
493
				}
494
				if(!$field['dontcombinecells'])
495
					echo "<td class=\"vtable\">";
496
				echo "<input class='formfld pwd' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\" type='password' ";
497
				if($field['size'])
498
					echo " size='" . $field['size'] . "' ";
499
				echo " />\n";
500

    
501
				if($field['description'] <> "") {
502
					echo "<br /> " . $field['description'];
503
				}
504

    
505
				break;
506
			case "certca_selection":
507
				$size = "";
508
				$multiple = "";
509
				$name = strtolower($name);
510
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
511
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
512
				echo "</td>";
513
				echo "<td class=\"vtable\">\n";
514
				if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
515
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
516
				if($field['add_to_certca_selection'] <> "") {
517
					$SELECTED = "";
518
					if($field['add_to_certca_selection'] == $value) $SELECTED = " selected=\"selected\"";
519
					echo "<option value='" . $field['add_to_certca_selection'] . "'" . $SELECTED . ">" . $field['add_to_certca_selection'] . "</option>\n";
520
				}
521
				foreach($config['ca'] as $ca) {
522
					$name = htmlspecialchars($ca['descr']);
523
					$SELECTED = "";
524
					if ($value == $name) $SELECTED = " selected=\"selected\"";
525
					$to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
526
					$to_echo .= "<!-- {$value} -->";
527
					$canecho = 0;
528
					if($field['certca_filter'] <> "") {
529
						if(stristr($name, $field['certca_filter']) == true)
530
							$canecho = 1;
531
					} else {
532
						$canecho = 1;
533
					}
534
					if($canecho == 1)
535
						echo $to_echo;
536
				}
537
				echo "</select>\n";
538

    
539
				if($field['description'] <> "") {
540
					echo "<br /> " . $field['description'];
541
				}
542

    
543
				break;
544
			case "cert_selection":
545
				$size = "";
546
				$multiple = "";
547
				$name = strtolower($name);
548
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
549
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
550
				echo "</td>";
551
				echo "<td class=\"vtable\">\n";
552
				if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
553
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
554
				if($field['add_to_cert_selection'] <> "") {
555
					$SELECTED = "";
556
					if($field['add_to_cert_selection'] == $value) $SELECTED = " selected=\"selected\"";
557
					echo "<option value='" . $field['add_to_cert_selection'] . "'" . $SELECTED . ">" . $field['add_to_cert_selection'] . "</option>\n";
558
				}
559
				foreach($config['cert'] as $ca) {
560
					if (stristr($ca['descr'], "webconf"))
561
						continue;
562
					$name = htmlspecialchars($ca['descr']);
563
					$SELECTED = "";
564
					if ($value == $name) $SELECTED = " selected=\"selected\"";
565
					$to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
566
					$to_echo .= "<!-- {$value} -->";
567
					$canecho = 0;
568
					if($field['cert_filter'] <> "") {
569
						if(stristr($name, $field['cert_filter']) == true)
570
							$canecho = 1;
571
					} else {
572
						$canecho = 1;
573
					}
574
					if($canecho == 1)
575
						echo $to_echo;
576
				}
577
				echo "</select>\n";
578

    
579
				if($field['description'] <> "") {
580
					echo "<br /> " . $field['description'];
581
				}
582

    
583
				break;
584
			case "select":
585
				if ($field['displayname']) {
586
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
587
					echo $field['displayname'];
588
					echo ":</td>\n";
589
				} else if(!$field['dontdisplayname']) {
590
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
591
					echo fixup_string($field['name']);
592
					echo ":</td>\n";
593
				}
594
				if($field['size']) $size = " size='" . $field['size'] . "' ";
595
				if($field['multiple'] == "yes") $multiple = "multiple=\"multiple\" ";
596
				if(!$field['dontcombinecells'])
597
					echo "<td class=\"vtable\">\n";
598
				$onchange = "";
599
				foreach ($field['options']['option'] as $opt) {
600
					if($opt['enablefields'] <> "") {
601
						$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
602
					}
603
				}
604
				echo "<select class='formselect' " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
605
				foreach ($field['options']['option'] as $opt) {
606
					$selected = "";
607
					if($value == $opt['value'])
608
						$selected = " selected=\"selected\"";
609
					echo "\t<option value='" . $opt['value'] . "'" . $selected . ">";
610
					if ($opt['displayname'])
611
						echo $opt['displayname'];
612
					else
613
						echo $opt['name'];
614
					echo "</option>\n";
615
				}
616
				echo "</select>\n";
617
				echo "<!-- {$value} -->\n";
618

    
619
				if($field['description'] <> "") {
620
					echo $field['description'];
621
				}
622

    
623
				break;
624
			case "textarea":
625
				if ($field['displayname']) {
626
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
627
					echo $field['displayname'];
628
					echo ":</td>\n";
629
				} else if(!$field['dontdisplayname']) {
630
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
631
					echo fixup_string($field['name']);
632
					echo ":</td>";
633
				}
634
				if(!$field['dontcombinecells'])
635
					echo "<td class=\"vtable\">";
636
				echo "<textarea class='formpre' id='" . $name . "' name='" . $name . "'";
637
				if ($field['rows'])
638
					echo " rows='" . $field['rows'] . "' ";
639
				if ($field['cols'])
640
					echo " cols='" . $field['cols'] . "' ";
641
				echo ">" . $value . "</textarea>\n";
642

    
643

    
644
				if($field['description'] <> "") {
645
					echo "<br /> " . $field['description'];
646
				}
647

    
648
				break;
649
			case "submit":
650
				echo "<td>&nbsp;<br /></td></tr>";
651
				echo "<tr><td colspan=\"2\" align=\"center\">";
652
				echo "<input type='submit' name='" . $name . "' value=\"" . htmlspecialchars($field['name']) . "\" />\n";
653

    
654
				if($field['description'] <> "") {
655
					echo "<br /> " . $field['description'];
656
				}
657

    
658
				break;
659
			case "listtopic":
660
				echo "<td>&nbsp;</td></tr>";
661
				echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br />\n";
662

    
663
				break;
664
			case "subnet_select":
665
				if ($field['displayname']) {
666
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
667
					echo $field['displayname'];
668
					echo ":</td>\n";
669
				} else if(!$field['dontdisplayname']) {
670
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
671
					echo fixup_string($field['name']);
672
					echo ":</td>";
673
				}
674
				if(!$field['dontcombinecells'])
675
					echo "<td class=\"vtable\">";
676
				echo "<select class='formselect' name='{$name}'>\n";
677
				for($x=1; $x<33; $x++) {
678
					$CHECKED = "";
679
					if($value == $x) $CHECKED = " selected=\"selected\"";
680
					if($x <> 31)
681
						echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
682
				}
683
				echo "</select>\n";
684

    
685
				if($field['description'] <> "") {
686
					echo "<br /> " . $field['description'];
687
				}
688

    
689
				break;
690
			case "timezone_select":
691
				exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
692
				$timezonelist = array_filter($timezonelist, 'is_timezone');
693
				sort($timezonelist);
694

    
695
				/* kill carriage returns */
696
				for($x=0; $x<count($timezonelist); $x++)
697
					$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
698

    
699
				if ($field['displayname']) {
700
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
701
					echo $field['displayname'];
702
					echo ":</td>\n";
703
				} else if(!$field['dontdisplayname']) {
704
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
705
					echo fixup_string($field['name']);
706
					echo ":</td>";
707
				}
708
				if(!$field['dontcombinecells'])
709
					echo "<td class=\"vtable\">";
710
				echo "<select class='formselect' name='{$name}'>\n";
711
				foreach ($timezonelist as $tz) {
712
					if(strstr($tz, "GMT"))
713
						continue;
714
					$SELECTED = "";
715
					if ($value == $tz) $SELECTED = " selected=\"selected\"";
716
					echo "<option value=\"" . htmlspecialchars($tz) . "\" {$SELECTED}>";
717
					echo htmlspecialchars($tz);
718
					echo "</option>\n";
719
				}
720
				echo "</select>\n";
721

    
722
				if($field['description'] <> "") {
723
					echo "<br /> " . $field['description'];
724
				}
725

    
726
				break;
727
			case "checkbox":
728
				if ($field['displayname']) {
729
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
730
					echo $field['displayname'];
731
					echo ":</td>\n";
732
				} else if(!$field['dontdisplayname']) {
733
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
734
					echo $field['name'];
735
					echo ":</td>";
736
				}
737
				$checked = "";
738
				if($value <> "")
739
					$checked = " checked=\"checked\"";
740
				echo "<td class=\"vtable\"><input value=\"on\" type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
741
				if(isset($field['enablefields']) or isset($field['checkenablefields']))
742
					echo " onclick=\"enablechange()\"";
743
				else if(isset($field['disablefields']) or isset($field['checkdisablefields']))
744
					echo " onclick=\"disablechange()\"";
745
				echo " />\n";
746

    
747
				if($field['description'] <> "") {
748
					echo $field['description'];
749
				}
750

    
751
				break;
752
			}
753

    
754
			if($field['typehint'] <> "") {
755
				echo $field['typehint'];
756
			}
757
			if($field['warning'] <> "") {
758
				echo "<br /><b><font color=\"red\">" . $field['warning'] . "</font></b>";
759
			}
760

    
761
			if(!$field['combinefieldsbegin']) {
762
				if (!$field['dontcombinecells'])
763
					echo "</td>";
764

    
765
				echo "</tr>\n";
766
			}
767

    
768
		}
769
	}
770
?>
771
			</table>
772
		</td>
773
	</tr>
774
</table>
775
<br />&nbsp;
776
</div>
777
</center>
778
</form>
779
<script type="text/javascript">
780
//<![CDATA[
781
	if (typeof ext_change != 'undefined') {
782
		ext_change();
783
	}
784
	if (typeof proto_change != 'undefined') {
785
		ext_change();
786
	}
787
	if (typeof proto_change != 'undefined') {
788
		proto_change();
789
	}
790

    
791
<?php
792
	$isfirst = 0;
793
	$aliases = "";
794
	$addrisfirst = 0;
795
	$aliasesaddr = "";
796
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
797
		foreach($config['aliases']['alias'] as $alias_name) {
798
				if($isfirst == 1)
799
					$aliases .= ",";
800
				$aliases .= "'" . $alias_name['name'] . "'";
801
				$isfirst = 1;
802
		}
803
?>
804

    
805
	var customarray=new Array(<?php echo $aliases; ?>);
806

    
807
	window.onload = function () {
808

    
809
		<?php
810
			$counter=0;
811
			foreach($inputaliases as $alias) {
812
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(customarray));\n";
813
				$counter++;
814
			}
815
		?>
816

    
817
	}
818

    
819
//]]>
820
</script>
821

    
822
<?php
823

    
824
$fieldnames_array = Array();
825
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
826
	// create a fieldname loop that can be used with javascript
827
	// hide and enable features.
828
	echo "\n<script type=\"text/javascript\">\n";
829
	echo "//<![CDATA[\n";
830
	echo "function disableall() {\n";
831
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
832
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
833
			if(!$field['donotdisable'] <> "") {
834
				array_push($fieldnames_array, $field['name']);
835
				$fieldname = preg_replace("/\s+/", "", $field['name']);
836
				$fieldname = strtolower($fieldname);
837
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
838
			}
839
		}
840
	}
841
	echo "}\ndisableall();\n";
842
	echo "function enableitems(selectedindex) {\n";
843
	echo "disableall();\n";
844
	$idcounter = 0;
845
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
846
		echo "\tswitch(selectedindex) {\n";
847
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
848
			if($field['options']['option'] <> "") {
849
				foreach ($field['options']['option'] as $opt) {
850
					if($opt['enablefields'] <> "") {
851
						echo "\t\tcase " . $idcounter . ":\n";
852
						$enablefields_split = explode(",", $opt['enablefields']);
853
						foreach ($enablefields_split as $efs) {
854
							$fieldname = preg_replace("/\s+/", "", $efs);
855
							$fieldname = strtolower($fieldname);
856
							if($fieldname <> "") {
857
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
858
								echo $onchange;
859
							}
860
						}
861
						echo "\t\t\tbreak;\n";
862
					}
863
					$idcounter = $idcounter + 1;
864
				}
865
			}
866
		}
867
		echo "\t}\n";
868
	}
869
	echo "}\n";
870
	echo "//]]>\n";
871
	echo "</script>\n\n";
872
}
873
?>
874

    
875
<script type="text/javascript">
876
//<![CDATA[
877
NiftyCheck();
878
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
879
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
880
enablechange();
881
disablechange();
882
showchange();
883
//]]>
884
</script>
885

    
886
<?php
887
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
888
	// handle after form display event.
889
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
890
}
891

    
892
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
893
	// handle after form display event.
894
	echo "\n<script type=\"text/javascript\">\n";
895
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
896
	echo "</script>\n\n";
897
}
898

    
899
/*
900
 *  HELPER FUNCTIONS
901
 */
902

    
903
function fixup_string($string) {
904
	global $config, $g, $myurl, $title;
905
	$newstring = $string;
906
	// fixup #1: $myurl -> http[s]://ip_address:port/
907
	switch($config['system']['webgui']['protocol']) {
908
		case "http":
909
			$proto = "http";
910
			break;
911
		case "https":
912
			$proto = "https";
913
			break;
914
		default:
915
			$proto = "http";
916
			break;
917
	}
918
	$port = $config['system']['webgui']['port'];
919
	if($port != "") {
920
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
921
			$urlport = ":" . $port;
922
		} elseif ($port != "80" and $port != "443") {
923
			$urlport = ":" . $port;
924
		} else {
925
			$urlport = "";
926
		}
927
	}
928
	$http_host = explode(":", $_SERVER['HTTP_HOST']);
929
	$http_host = $http_host[0];
930
	$urlhost = $http_host;
931
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
932
	if($title == "Reload in progress") {
933
		if (is_ipaddr($urlhost)) {
934
			$host_if = find_ip_interface($urlhost);
935
			if ($host_if) {
936
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
937
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr']))
938
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
939
			}
940
		} else if ($urlhost == $config['system']['hostname'])
941
			$urlhost = $config['wizardtemp']['system']['hostname'];
942
		else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain'])
943
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
944
	}
945
	if($urlhost != $http_host)
946
		file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
947
	$myurl = $proto . "://" . $urlhost . $urlport . "/";
948

    
949
	if (strstr($newstring, "\$myurl"))
950
		$newstring = str_replace("\$myurl", $myurl, $newstring);
951
	// fixup #2: $wanip
952
	if (strstr($newstring, "\$wanip")) {
953
		$curwanip = get_interface_ip();
954
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
955
	}
956
	// fixup #3: $lanip
957
	if (strstr($newstring, "\$lanip")) {
958
		$lanip = get_interface_ip("lan");
959
		$newstring = str_replace("\$lanip", $lanip, $newstring);
960
	}
961
	// fixup #4: fix'r'up here.
962
	return $newstring;
963
}
964

    
965
function is_timezone($elt) {
966
	return !preg_match("/\/$/", $elt);
967
}
968

    
969
?>
970

    
971
</body>
972
</html>
(253-253/254)