Project

General

Profile

Download (23.2 KB) Statistics
| Branch: | Tag: | Revision:
1 658292ef Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 658292ef Scott Ullrich
/*
4 57333fa0 Scott Ullrich
    wizard.php
5 658292ef Scott Ullrich
    Copyright (C) 2004 Scott Ullrich
6
    All rights reserved.
7
8
    Redistribution and use in source and binary forms, with or without
9
    modification, 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 the
16
       documentation and/or other materials provided with the distribution.
17
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30 6b07c15a Matthew Grooms
##|+PRIV
31
##|*IDENT=page-pfsensewizardsubsystem
32
##|*NAME=pfSense wizard subsystem page
33
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
34
##|*MATCH=wizard.php*
35
##|-PRIV
36
37
38 658292ef Scott Ullrich
require("guiconfig.inc");
39
40
function gentitle_pkg($pgname) {
41 2fbd6806 Scott Ullrich
	global $config;
42
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
43 658292ef Scott Ullrich
}
44
45 d8c1a6c5 Scott Ullrich
$stepid = htmlspecialchars($_GET['stepid']);
46 658292ef Scott Ullrich
if (isset($_POST['stepid']))
47 d8c1a6c5 Scott Ullrich
    $stepid = htmlspecialchars($_POST['stepid']);
48 2fbd6806 Scott Ullrich
if (!$stepid) $stepid = "0";
49 658292ef Scott Ullrich
50 d8c1a6c5 Scott Ullrich
$xml = htmlspecialchars($_GET['xml']);
51
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
52 658292ef Scott Ullrich
53
if($xml == "") {
54 bb0c9569 Bill Marquette
	$xml = "not_defined";
55
	print_info_box_np("ERROR:  Could not open " . $xml . ".");
56
	die;
57 658292ef Scott Ullrich
} else {
58 bd31336e Scott Ullrich
	if (file_exists("{$g['www_path']}/wizards/{$xml}"))
59 fc19d371 Scott Ullrich
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
60 bb0c9569 Bill Marquette
	else {
61
		print_info_box_np("ERROR:  Could not open " . $xml . ".");
62
		die;
63
	}
64 658292ef Scott Ullrich
}
65
66
$title          = $pkg['step'][$stepid]['title'];
67
$description    = $pkg['step'][$stepid]['description'];
68 46985f19 Scott Ullrich
$totalsteps     = $pkg['totalsteps'];
69 658292ef Scott Ullrich
70 bd31336e Scott Ullrich
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
71
$timezonelist = array_filter($timezonelist, 'is_timezone');
72
sort($timezonelist);
73
74 98b5b72b Scott Ullrich
/* kill carriage returns */
75 e881d1f3 Scott Ullrich
for($x=0; $x<count($timezonelist); $x++)
76 98b5b72b Scott Ullrich
		$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
77
78 b3f4e57c Scott Ullrich
if ($pkg['step'][$stepid]['includefile'])
79
	require($pkg['step'][$stepid]['includefile']);
80
81 e1e7a425 Scott Ullrich
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
82
		eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
83
}
84
85 658292ef Scott Ullrich
if ($_POST) {
86 e48fc17d Scott Ullrich
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
87
        if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
88
		$fieldname = $field['name'];
89
		$unset_fields = "";
90
		$fieldname = ereg_replace(" ", "", $fieldname);
91
		$fieldname = strtolower($fieldname);
92
		// update field with posted values.
93
                if($field['unsetfield'] <> "") $unset_fields = "yes";
94 46985f19 Scott Ullrich
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
95 e48fc17d Scott Ullrich
		if($field['bindstofield'])
96 3f83de3d Scott Ullrich
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
97 658292ef Scott Ullrich
        }
98 3ed807e4 Scott Ullrich
99 2fbd6806 Scott Ullrich
    }
100 3ed807e4 Scott Ullrich
    // run custom php code embedded in xml config.
101
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
102
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
103
    }
104
	write_config();
105 e48fc17d Scott Ullrich
    $stepid++;
106 46985f19 Scott Ullrich
    if($stepid > $totalsteps) $stepid = $totalsteps;
107 658292ef Scott Ullrich
}
108
109 46985f19 Scott Ullrich
$title          = $pkg['step'][$stepid]['title'];
110
$description    = $pkg['step'][$stepid]['description'];
111
112 3f83de3d Scott Ullrich
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
113 e48fc17d Scott Ullrich
	global $config;
114
	$field_split = split("->",$field);
115
	foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
116
	if($field_conv == "") return;
117 3f83de3d Scott Ullrich
	if($field_type == "checkbox" and $updatetext <> "on") {
118
		/*
119
		    item is a checkbox, it should have the value "on"
120
		    if it was checked
121
                */
122
		$text = "unset(\$config" . $field_conv . ");";
123
		eval($text);
124
		return;
125 496f9155 Scott Ullrich
	}
126 e881d1f3 Scott Ullrich
127 496f9155 Scott Ullrich
	if($field_type == "interfaces_selection") {
128
		$text = "unset(\$config" . $field_conv . ");";
129
		eval($text);
130
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
131
		eval($text);
132
		return;
133
	}
134 e881d1f3 Scott Ullrich
135 e48fc17d Scott Ullrich
	if($unset <> "") {
136
		$text = "unset(\$config" . $field_conv . ");";
137
		eval($text);
138 46985f19 Scott Ullrich
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
139 e48fc17d Scott Ullrich
		eval($text);
140
	} else {
141 46985f19 Scott Ullrich
		if($arraynum <> "") {
142
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
143
		} else {
144
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
145
		}
146 e48fc17d Scott Ullrich
		eval($text);
147
	}
148 658292ef Scott Ullrich
}
149
150 34b5c5a0 Scott Ullrich
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
151
	// handle before form display event.
152
        // good for modifying posted values, etc.
153
	eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
154
}
155
156 d88c6a9f Scott Ullrich
$pgtitle = array($title);
157 4df96eff Scott Ullrich
include("head.inc");
158 6bb5c9aa Bill Marquette
159 4df96eff Scott Ullrich
?>
160 fc7bea0e Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
161 4e3391a3 Scott Ullrich
162 8c01d3bb Scott Ullrich
<?php
163 ba21539c Scott Ullrich
	if(file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) 
164 8c01d3bb Scott Ullrich
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
165 4e3391a3 Scott Ullrich
	else 
166
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
167 8c01d3bb Scott Ullrich
?>
168
169 33a56b27 Colin Smith
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
170 44c10295 Scott Ullrich
<script type="text/javascript">
171 f9e35766 Scott Ullrich
<!--
172 38e7d556 Scott Ullrich
173 e881d1f3 Scott Ullrich
function  FieldValidate(userinput,  regexp,  message)
174
{
175
                if(!userinput.match(regexp))
176
                                alert(message);
177
}
178 38e7d556 Scott Ullrich
179 33a56b27 Colin Smith
function enablechange() {
180
<?php
181
        foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
182
                if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
183
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
184
                        if(isset($field['enablefields'])) {
185
                                $enablefields = explode(',', $field['enablefields']);
186
                                foreach($enablefields as $enablefield) {
187
                                        $enablefield = strtolower($enablefield);
188
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
189
                                }
190
                        }
191
                        if(isset($field['checkenablefields'])) {
192
                                $checkenablefields = explode(',', $field['checkenablefields']);
193
                                foreach($checkenablefields as $checkenablefield) {
194
                                        $checkenablefield = strtolower($checkenablefield);
195
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
196
                                }
197
                        }
198
                        print "\t" . '} else {' . "\n";
199
                        if(isset($field['enablefields'])) {
200
                                foreach($enablefields as $enablefield) {
201
                                        $enablefield = strtolower($enablefield);
202
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
203
                                }
204
                        }
205
                        if(isset($field['checkenablefields'])) {
206
                                foreach($checkenablefields as $checkenablefield) {
207
                                        $checkenablefield = strtolower($checkenablefield);
208
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
209
                                }
210 e881d1f3 Scott Ullrich
                        }
211 33a56b27 Colin Smith
                        print "\t" . '}' . "\n";
212
                }
213
        }
214
?>
215 6bb5c9aa Bill Marquette
}
216
//-->
217
</script>
218 33a56b27 Colin Smith
<?php } ?>
219 6bb5c9aa Bill Marquette
220 33a56b27 Colin Smith
<form action="wizard.php" method="post" name="iform" id="iform">
221 658292ef Scott Ullrich
<input type="hidden" name="xml" value="<?= $xml ?>">
222 e48fc17d Scott Ullrich
<input type="hidden" name="stepid" value="<?= $stepid ?>">
223 658292ef Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
224
225 e48fc17d Scott Ullrich
<center>
226
227
&nbsp;<br>
228 1c3d61fe Scott Ullrich
229 fe2bfbfc Scott Ullrich
<?php
230 1c3d61fe Scott Ullrich
	if($title == "Reload in progress") {
231 a55e9c70 Ermal Lu?i
		$ip = "http://" . get_interface_ip("lan");
232 1c3d61fe Scott Ullrich
	} else {
233 fe2bfbfc Scott Ullrich
		$ip = "/";
234 1c3d61fe Scott Ullrich
	}
235 2576dace Ermal Luçi
	echo "<a href='$ip'>";
236 fe2bfbfc Scott Ullrich
?>
237 1c3d61fe Scott Ullrich
<img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif"></a>
238 d51f86e0 Scott Ullrich
<p>
239 85dc4438 Scott Ullrich
<div style="width:700px;background-color:#ffffff" id="roundme">
240 50f60bca Scott Ullrich
<table bgcolor="#ffffff" width="600" cellspacing="0" cellpadding="3">
241 34b5c5a0 Scott Ullrich
    <!-- wizard goes here -->
242
    <tr><td>&nbsp;</td></tr>
243 77851510 Scott Ullrich
    <tr><td colspan='2'>
244 55b8d602 Scott Ullrich
<?php
245
	if ($_GET['message'] != "")
246 d8c1a6c5 Scott Ullrich
		print_info_box(htmlspecialchars($_GET['message']));
247 55b8d602 Scott Ullrich
	if ($_POST['message'] != "")
248 d8c1a6c5 Scott Ullrich
		print_info_box(htmlspecialchars($_POST['message']));
249 77851510 Scott Ullrich
?></td></tr>
250 d51f86e0 Scott Ullrich
    <tr><td colspan='2'><center><b><?= fixup_string($description) ?></b></center></td></tr><tr><td>&nbsp;</td></tr>
251 34b5c5a0 Scott Ullrich
    <?php
252
	if(!$pkg['step'][$stepid]['disableheader'])
253 d51f86e0 Scott Ullrich
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
254 34b5c5a0 Scott Ullrich
    ?>
255
256
    <?php
257 44c10295 Scott Ullrich
	$inputaliases = array();
258 34b5c5a0 Scott Ullrich
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
259
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
260
261
		    $value = $field['value'];
262 2fbd6806 Scott Ullrich
		    $name  = $field['name'];
263 658292ef Scott Ullrich
264 2fbd6806 Scott Ullrich
		    $name = ereg_replace(" ", "", $name);
265
		    $name = strtolower($name);
266 658292ef Scott Ullrich
267 a8df0181 Scott Ullrich
		    if($field['bindstofield'] <> "") {
268 b1919dd0 Scott Ullrich
				$arraynum = "";
269
				$field_conv = "";
270
				$field_split = split("->", $field['bindstofield']);
271
				// arraynum is used in cases where there is an array of the same field
272
				// name such as dnsserver (2 of them)
273
				if($field['arraynum'] <> "") $arraynum = "[" . $field['arraynum'] . "]";
274
				foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
275
					$toeval = "\$value = \$config" . $field_conv . $arraynum . ";";
276
					eval($toeval);
277 33a56b27 Colin Smith
					if ($field['type'] == "checkbox") {
278 35fecd55 Scott Ullrich
						$toeval = "if(isset(\$config" . $field_conv . $arraynum . ")) \$value = \" CHECKED\";";
279 f2ec2c48 Scott Ullrich
						eval($toeval);
280
					}
281 a8df0181 Scott Ullrich
		    }
282
283 34b5c5a0 Scott Ullrich
		    if(!$field['combinefieldsend'])
284
			echo "<tr>";
285
286
		    if ($field['type'] == "input") {
287 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
288
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
289 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
290 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
291
			} else if(!$field['dontdisplayname']) {
292 34b5c5a0 Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
293 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
294 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
295
			}
296
			if(!$field['dontcombinecells'])
297
				echo "<td class=\"vtable\">\n";
298 6bb5c9aa Bill Marquette
299
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'";
300
			if($field['validate'])
301
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
302
			echo ">\n";
303 62a48760 Scott Ullrich
304
305 e881d1f3 Scott Ullrich
306 62a48760 Scott Ullrich
		    } else if ($field['type'] == "inputalias") {
307 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
308
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
309 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
310 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
311
			} else if(!$field['dontdisplayname']) {
312 62a48760 Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
313
				echo fixup_string($field['name']);
314
				echo ":</td>\n";
315 44c10295 Scott Ullrich
				$inputaliases[] = $name;
316 62a48760 Scott Ullrich
			}
317
			if(!$field['dontcombinecells'])
318
				echo "<td class=\"vtable\">\n";
319
320
			echo "<input  autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
321
			if($field['validate'])
322
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
323 e881d1f3 Scott Ullrich
			echo ">\n";
324
325 62a48760 Scott Ullrich
326
327 496f9155 Scott Ullrich
		    } else if($field['type'] == "interfaces_selection") {
328
			$size = "";
329
			$multiple = "";
330
			$name = strtolower($name);
331
			echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
332 7a29f783 Ermal Lu?i
			echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
333 496f9155 Scott Ullrich
			echo "</td>";
334
			echo "<td class=\"vtable\">\n";
335 7b4710f9 Scott Ullrich
			if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
336 496f9155 Scott Ullrich
			if($field['multiple'] <> "" and $field['multiple'] <> "0") {
337 7b4710f9 Scott Ullrich
			  $multiple = "multiple=\"multiple\"";
338 496f9155 Scott Ullrich
			  $name .= "[]";
339
			}
340 7b4710f9 Scott Ullrich
			echo "<select id='{$name}' name='{$name}' {$size} {$multiple}>\n";
341 496f9155 Scott Ullrich
			if($field['add_to_interfaces_selection'] <> "") {
342
				$SELECTED = "";
343
				if($field['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
344
				echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
345
			}
346 62a48760 Scott Ullrich
			$interfaces = $config['interfaces'];
347 496f9155 Scott Ullrich
			if($field['all_interfaces'] <> "") {
348
				$ints = split(" ", `/sbin/ifconfig -l`);
349
				$interfaces = array();
350
				foreach ($ints as $int) {
351
					$interfaces[]['descr'] = $int;
352
					$interfaces[] = $int;
353
				}
354
			}
355
			foreach ($interfaces as $ifname => $iface) {
356
			  if ($iface['descr'])
357
				  $ifdescr = $iface['descr'];
358
			  else
359
				  $ifdescr = strtoupper($ifname);
360
			  $ip = "";
361
			  if($field['all_interfaces'] <> "") {
362
				$ifdescr = $iface;
363
				$ip = " " . find_interface_ip($iface);
364
			  }
365
			  $SELECTED = "";
366 aecffb0a Scott Ullrich
			  if ($value == $ifname) $SELECTED = " SELECTED";
367
			  $to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $ifdescr . $ip . "</option>\n";
368 496f9155 Scott Ullrich
			  $to_echo .= "<!-- {$value} -->";
369
			  $canecho = 0;
370
			  if($field['interface_filter'] <> "") {
371
				if(stristr($iface, $field['interface_filter']) == true)
372
					$canecho = 1;
373
			  } else {
374
				$canecho = 1;
375
			  }
376 e881d1f3 Scott Ullrich
			  if($canecho == 1)
377 496f9155 Scott Ullrich
				echo $to_echo;
378
			}
379
				echo "</select>\n";
380
			} else if ($field['type'] == "password") {
381 34b5c5a0 Scott Ullrich
			if(!$field['dontdisplayname']) {
382
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
383 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
384 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
385
			}
386
			if(!$field['dontcombinecells'])
387
				echo "<td class=\"vtable\">";
388
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
389
		    } else if ($field['type'] == "select") {
390 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
391
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
392 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
393 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
394
			} else if(!$field['dontdisplayname']) {
395 34b5c5a0 Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
396 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
397 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
398
			}
399
			if($field['size']) $size = " size='" . $field['size'] . "' ";
400
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
401
			if(!$field['dontcombinecells'])
402
				echo "<td class=\"vtable\">\n";
403
			$onchange = "";
404
			foreach ($field['options']['option'] as $opt) {
405
				if($opt['enablefields'] <> "") {
406
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
407
				}
408
			}
409
			echo "<select " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
410
			foreach ($field['options']['option'] as $opt) {
411 46985f19 Scott Ullrich
				$selected = "";
412
				if($value == $opt['value']) $selected = " SELECTED";
413 d6f53204 Ermal Lu?i
			    echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">";
414
				if ($opt['displayname'])
415
					echo $opt['displayname'];
416
				else
417
					echo $opt['name'];
418
				echo "</option>\n";
419 34b5c5a0 Scott Ullrich
			}
420
			echo "</select>\n";
421
		    } else if ($field['type'] == "textarea") {
422 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
423
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
424 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
425 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
426
			} else if(!$field['dontdisplayname']) {
427 34b5c5a0 Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
428 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
429 34b5c5a0 Scott Ullrich
				echo ":</td>";
430
			}
431
			if(!$field['dontcombinecells'])
432
				echo "<td class=\"vtable\">";
433
			echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
434
		    } else if ($field['type'] == "submit") {
435
			echo "<td>&nbsp;<br></td></tr>";
436 2fbd6806 Scott Ullrich
			echo "<tr><td colspan='2'><center>";
437
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
438 34b5c5a0 Scott Ullrich
		    } else if ($field['type'] == "listtopic") {
439
			echo "<td>&nbsp;</td><tr>";
440
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
441 bd31336e Scott Ullrich
		    } else if ($field['type'] == "subnet_select") {
442 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
443
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
444 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
445 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
446
			} else if(!$field['dontdisplayname']) {
447 bd31336e Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
448
				echo fixup_string($field['name']);
449
				echo ":</td>";
450
			}
451
			if(!$field['dontcombinecells'])
452
				echo "<td class=\"vtable\">";
453
			echo "<select name='{$name}'>\n";
454
			for($x=1; $x<33; $x++) {
455
				$CHECKED = "";
456
				if($value == $x) $CHECKED = " SELECTED";
457
				if($x <> 31)
458
					echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
459
			}
460
			echo "</select>\n";
461
		    } else if ($field['type'] == "timezone_select") {
462 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
463
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
464 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
465 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
466
			} else if(!$field['dontdisplayname']) {
467 bd31336e Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
468
				echo fixup_string($field['name']);
469
				echo ":</td>";
470
			}
471
			if(!$field['dontcombinecells'])
472
				echo "<td class=\"vtable\">";
473
			echo "<select name='{$name}'>\n";
474
			foreach ($timezonelist as $tz) {
475
				$SELECTED = "";
476
				if ($value == $tz) $SELECTED = " SELECTED";
477
				echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
478
				echo htmlspecialchars($tz);
479
				echo "</option>\n";
480
			}
481
			echo "</select>\n";
482 34b5c5a0 Scott Ullrich
		    } else if ($field['type'] == "checkbox") {
483 7a29f783 Ermal Lu?i
			if ($field['displayname']) {
484
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
485 d6f53204 Ermal Lu?i
                                echo $field['displayname'];
486 7a29f783 Ermal Lu?i
                                echo ":</td>\n";
487
			} else if(!$field['dontdisplayname']) {
488 34b5c5a0 Scott Ullrich
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
489
				echo $field['name'];
490
				echo ":</td>";
491
			}
492
			$checked = "";
493 f2ec2c48 Scott Ullrich
			if($value <> "") $checked = " CHECKED";
494 33a56b27 Colin Smith
			echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
495
			if(isset($field['enablefields']) or isset($field['checkenablefields'])) echo " onClick=\"enablechange()\"";
496
			echo ">\n";
497 34b5c5a0 Scott Ullrich
		    }
498
499
		    if($field['typehint'] <> "") {
500
			echo $field['typehint'];
501 2fbd6806 Scott Ullrich
		    }
502 34b5c5a0 Scott Ullrich
503 788ff7cb Scott Ullrich
		    if($field['description'] <> "") {
504
			echo "<br>" . $field['description'];
505 34b5c5a0 Scott Ullrich
			echo "</td>";
506 788ff7cb Scott Ullrich
		    }
507 34b5c5a0 Scott Ullrich
508
		    if(!$field['combinefieldsbegin'])
509
			 echo "</tr>\n";
510 f3c6fdc0 Bill Marquette
511
		    if($field['warning'] <> "") {
512
			echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
513
		    }
514
515 34b5c5a0 Scott Ullrich
		}
516
	}
517
    ?>
518 658292ef Scott Ullrich
</table>
519 85dc4438 Scott Ullrich
<br>&nbsp;
520 5adb3375 Scott Ullrich
</div>
521 658292ef Scott Ullrich
</form>
522 44c10295 Scott Ullrich
<script type="text/javascript">
523 62a48760 Scott Ullrich
<!--
524
	if (typeof ext_change != 'undefined') {
525
		ext_change();
526
	}
527
	if (typeof proto_change != 'undefined') {
528
		ext_change();
529
	}
530
	if (typeof proto_change != 'undefined') {
531
		proto_change();
532
	}
533 5adb3375 Scott Ullrich
534 62a48760 Scott Ullrich
<?php
535
	$isfirst = 0;
536
	$aliases = "";
537
	$addrisfirst = 0;
538
	$aliasesaddr = "";
539
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
540
		foreach($config['aliases']['alias'] as $alias_name) {
541
			if(!stristr($alias_name['address'], ".")) {
542
				if($isfirst == 1) $aliases .= ",";
543
				$aliases .= "'" . $alias_name['name'] . "'";
544
				$isfirst = 1;
545
			} else {
546
				if($addrisfirst == 1) $aliasesaddr .= ",";
547
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
548
				$addrisfirst = 1;
549
			}
550
		}
551
?>
552
553
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
554
	var customarray=new Array(<?php echo $aliases; ?>);
555
556 44c10295 Scott Ullrich
	window.onload = function () {
557
558
		<?php
559
			$counter=0;
560
			foreach($inputaliases as $alias) {
561
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(addressarray));\n";
562
				$counter++;
563
			}
564
		?>
565
566
	}
567
568 62a48760 Scott Ullrich
//-->
569
</script>
570 5adb3375 Scott Ullrich
<script type="text/javascript">
571
NiftyCheck();
572 e881d1f3 Scott Ullrich
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
573
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
574 5adb3375 Scott Ullrich
</script>
575
576 34b5c5a0 Scott Ullrich
<?php
577
578
$fieldnames_array = Array();
579
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
580
	// create a fieldname loop that can be used with javascript
581
	// hide and enable features.
582 44c10295 Scott Ullrich
	echo "\n<script type=\"text/javascript\">\n";
583 34b5c5a0 Scott Ullrich
	echo "function disableall() {\n";
584
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
585
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
586
			if(!$field['donotdisable'] <> "") {
587
				array_push($fieldnames_array, $field['name']);
588
				$fieldname = ereg_replace(" ", "", $field['name']);
589
				$fieldname = strtolower($fieldname);
590
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
591
			}
592
		}
593
	}
594
	echo "}\ndisableall();\n";
595
	echo "function enableitems(selectedindex) {\n";
596
	echo "disableall();\n";
597
	$idcounter = 0;
598
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
599
		echo "\tswitch(selectedindex) {\n";
600
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
601
			if($field['options']['option'] <> "") {
602
				foreach ($field['options']['option'] as $opt) {
603
					if($opt['enablefields'] <> "") {
604
						echo "\t\tcase " . $idcounter . ":\n";
605
						$enablefields_split = split(",", $opt['enablefields']);
606
						foreach ($enablefields_split as $efs) {
607
							$fieldname = ereg_replace(" ", "", $efs);
608
							$fieldname = strtolower($fieldname);
609
							if($fieldname <> "") {
610
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
611
								echo $onchange;
612
							}
613
						}
614
						echo "\t\t\tbreak;\n";
615
					}
616
					$idcounter = $idcounter + 1;
617
				}
618
			}
619
		}
620
		echo "\t}\n";
621
	}
622
	echo "}\n";
623
	echo "disableall();\n";
624
	echo "</script>\n\n";
625
}
626
627
628
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
629
	// handle after form display event.
630
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
631
}
632
633
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
634
	// handle after form display event.
635 44c10295 Scott Ullrich
        echo "\n<script type=\"text/javascript\">\n";
636 34b5c5a0 Scott Ullrich
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
637
	echo "</script>\n\n";
638
}
639
640 d51f86e0 Scott Ullrich
/*
641
 *  HELPER FUNCTIONS
642
 */
643
644
function fixup_string($string) {
645 a0190b50 Scott Ullrich
	global $config, $myurl;
646 78818d7a Scott Ullrich
	$newstring = $string;
647 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
648 037304d8 Scott Ullrich
	switch($config['system']['webguiproto']) {
649
		case "http":
650
			$proto = "http";
651
			break;
652
		case "https":
653
			$proto = "https";
654
			break;
655
		default:
656
			$proto = "http";
657
			break;
658
	}
659 d51f86e0 Scott Ullrich
	$port = $config['system']['webguiport'];
660 037304d8 Scott Ullrich
	if($port != "") {
661
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
662
			$urlport = ":" . $port;
663
		} elseif ($port != "80" and $port != "443") {
664
			$urlport = ":" . $port;
665
		} else {
666
			$urlport = "";
667
		}
668
	}
669 a55e9c70 Ermal Lu?i
	$myurl = $proto . "://" . get_interface_ip("lan") . $urlport . "/";
670 78818d7a Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $newstring);
671 d2133701 Scott Ullrich
	// fixup #2: $wanip
672 85a5da13 Ermal Luçi
	$curwanip = get_interface_ip();
673 78818d7a Scott Ullrich
	$newstring = str_replace("\$wanip", $curwanip, $newstring);
674 d2133701 Scott Ullrich
	// fixup #3: $lanip
675 a55e9c70 Ermal Lu?i
	$lanip = get_interface_ip("lan");
676 78818d7a Scott Ullrich
	$newstring = str_replace("\$lanip", $lanip, $newstring);
677 d2133701 Scott Ullrich
	// fixup #4: fix'r'up here.
678 d51f86e0 Scott Ullrich
	return $newstring;
679
}
680
681 bd31336e Scott Ullrich
function is_timezone($elt) {
682
	return !preg_match("/\/$/", $elt);
683
}
684 d51f86e0 Scott Ullrich
685 c8000491 Scott Ullrich
?>
686
687
</body>
688
</html>