Project

General

Profile

Download (18.4 KB) Statistics
| Branch: | Tag: | Revision:
1 658292ef Scott Ullrich
#!/usr/local/bin/php
2
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 658292ef Scott Ullrich
/*
5 57333fa0 Scott Ullrich
    wizard.php
6 658292ef Scott Ullrich
    Copyright (C) 2004 Scott Ullrich
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
require("guiconfig.inc");
32
33
function gentitle_pkg($pgname) {
34 2fbd6806 Scott Ullrich
	global $config;
35
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
36 658292ef Scott Ullrich
}
37
38
$stepid = $_GET['stepid'];
39
if (isset($_POST['stepid']))
40
    $stepid = $_POST['stepid'];
41 2fbd6806 Scott Ullrich
if (!$stepid) $stepid = "0";
42 658292ef Scott Ullrich
43
// XXX: Make this input safe.
44
$xml = $_GET['xml'];
45
if($_POST['xml']) $xml = $_POST['xml'];
46
47
if($xml == "") {
48 bb0c9569 Bill Marquette
	$xml = "not_defined";
49
	print_info_box_np("ERROR:  Could not open " . $xml . ".");
50
	die;
51 658292ef Scott Ullrich
} else {
52 bd31336e Scott Ullrich
	if (file_exists("{$g['www_path']}/wizards/{$xml}"))
53 fc19d371 Scott Ullrich
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
54 bb0c9569 Bill Marquette
	else {
55
		print_info_box_np("ERROR:  Could not open " . $xml . ".");
56
		die;
57
	}
58 658292ef Scott Ullrich
}
59
60
$title          = $pkg['step'][$stepid]['title'];
61
$description    = $pkg['step'][$stepid]['description'];
62 46985f19 Scott Ullrich
$totalsteps     = $pkg['totalsteps'];
63 658292ef Scott Ullrich
64 bd31336e Scott Ullrich
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
65
$timezonelist = array_filter($timezonelist, 'is_timezone');
66
sort($timezonelist);
67
68 e1e7a425 Scott Ullrich
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
69
		eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
70
}
71
72 658292ef Scott Ullrich
if ($_POST) {
73 e48fc17d Scott Ullrich
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
74
        if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
75
		$fieldname = $field['name'];
76
		$unset_fields = "";
77
		$fieldname = ereg_replace(" ", "", $fieldname);
78
		$fieldname = strtolower($fieldname);
79
		// update field with posted values.
80
                if($field['unsetfield'] <> "") $unset_fields = "yes";
81 46985f19 Scott Ullrich
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
82 e48fc17d Scott Ullrich
		if($field['bindstofield'])
83 3f83de3d Scott Ullrich
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
84 658292ef Scott Ullrich
        }
85 3ed807e4 Scott Ullrich
86 2fbd6806 Scott Ullrich
    }
87 3ed807e4 Scott Ullrich
    // run custom php code embedded in xml config.
88
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
89
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
90
    }
91
	write_config();
92 e48fc17d Scott Ullrich
    $stepid++;
93 46985f19 Scott Ullrich
    if($stepid > $totalsteps) $stepid = $totalsteps;
94 658292ef Scott Ullrich
}
95
96 46985f19 Scott Ullrich
$title          = $pkg['step'][$stepid]['title'];
97
$description    = $pkg['step'][$stepid]['description'];
98
99 3f83de3d Scott Ullrich
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
100 e48fc17d Scott Ullrich
	global $config;
101
	$field_split = split("->",$field);
102
	foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
103
	if($field_conv == "") return;
104 3f83de3d Scott Ullrich
	if($field_type == "checkbox" and $updatetext <> "on") {
105
		/*
106
		    item is a checkbox, it should have the value "on"
107
		    if it was checked
108
                */
109
		$text = "unset(\$config" . $field_conv . ");";
110
		eval($text);
111
		return;
112 496f9155 Scott Ullrich
	}
113
	
114
	if($field_type == "interfaces_selection") {
115
		$text = "unset(\$config" . $field_conv . ");";
116
		eval($text);
117
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
118
		eval($text);
119
		return;
120
	}
121
	
122 e48fc17d Scott Ullrich
	if($unset <> "") {
123
		$text = "unset(\$config" . $field_conv . ");";
124
		eval($text);
125 46985f19 Scott Ullrich
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
126 e48fc17d Scott Ullrich
		eval($text);
127
	} else {
128 46985f19 Scott Ullrich
		if($arraynum <> "") {
129
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
130
		} else {
131
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
132
		}
133 e48fc17d Scott Ullrich
		eval($text);
134
	}
135 658292ef Scott Ullrich
}
136
137 34b5c5a0 Scott Ullrich
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
138
	// handle before form display event.
139
        // good for modifying posted values, etc.
140
	eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
141
}
142
143 4df96eff Scott Ullrich
$pgtitle = $title;
144
include("head.inc");
145 6bb5c9aa Bill Marquette
146 4df96eff Scott Ullrich
?>
147 fc7bea0e Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
148 33a56b27 Colin Smith
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
149
<script language="JavaScript">
150 f9e35766 Scott Ullrich
<!--
151 33a56b27 Colin Smith
function enablechange() {
152
<?php
153
        foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
154
                if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
155
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
156
                        if(isset($field['enablefields'])) {
157
                                $enablefields = explode(',', $field['enablefields']);
158
                                foreach($enablefields as $enablefield) {
159
                                        $enablefield = strtolower($enablefield);
160
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
161
                                }
162
                        }
163
                        if(isset($field['checkenablefields'])) {
164
                                $checkenablefields = explode(',', $field['checkenablefields']);
165
                                foreach($checkenablefields as $checkenablefield) {
166
                                        $checkenablefield = strtolower($checkenablefield);
167
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
168
                                }
169
                        }
170
                        print "\t" . '} else {' . "\n";
171
                        if(isset($field['enablefields'])) {
172
                                foreach($enablefields as $enablefield) {
173
                                        $enablefield = strtolower($enablefield);
174
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
175
                                }
176
                        }
177
                        if(isset($field['checkenablefields'])) {
178
                                foreach($checkenablefields as $checkenablefield) {
179
                                        $checkenablefield = strtolower($checkenablefield);
180
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
181
                                }
182
                        }   
183
                        print "\t" . '}' . "\n";
184
                }
185
        }
186
?>
187 6bb5c9aa Bill Marquette
}
188
//-->
189
</script>
190 33a56b27 Colin Smith
<?php } ?>
191 6bb5c9aa Bill Marquette
192 33a56b27 Colin Smith
<form action="wizard.php" method="post" name="iform" id="iform">
193 658292ef Scott Ullrich
<input type="hidden" name="xml" value="<?= $xml ?>">
194 e48fc17d Scott Ullrich
<input type="hidden" name="stepid" value="<?= $stepid ?>">
195 658292ef Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
196
197 e48fc17d Scott Ullrich
<center>
198
199
&nbsp;<br>
200 fe2bfbfc Scott Ullrich
<?php
201
	if($title == "Reload in progress")
202 d1c844e1 Scott Ullrich
		$ip = "http://{$config['interfaces']['lan']['ipaddr']}";
203 fe2bfbfc Scott Ullrich
	else
204
		$ip = "/";
205
?>
206 e48fc17d Scott Ullrich
207 fe2bfbfc Scott Ullrich
<a href="<?php echo $ip; ?>"><img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif"></a>
208 d51f86e0 Scott Ullrich
<p>
209 e48fc17d Scott Ullrich
210 85dc4438 Scott Ullrich
<div style="width:700px;background-color:#ffffff" id="roundme">
211 50f60bca Scott Ullrich
<table bgcolor="#ffffff" width="600" cellspacing="0" cellpadding="3">
212 34b5c5a0 Scott Ullrich
    <!-- wizard goes here -->
213
    <tr><td>&nbsp;</td></tr>
214 d51f86e0 Scott Ullrich
    <tr><td colspan='2'><center><b><?= fixup_string($description) ?></b></center></td></tr><tr><td>&nbsp;</td></tr>
215 34b5c5a0 Scott Ullrich
    <?php
216
	if(!$pkg['step'][$stepid]['disableheader'])
217 d51f86e0 Scott Ullrich
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
218 34b5c5a0 Scott Ullrich
    ?>
219
220
    <?php
221
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
222
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
223
224
		    $value = $field['value'];
225 2fbd6806 Scott Ullrich
		    $name  = $field['name'];
226 658292ef Scott Ullrich
227 2fbd6806 Scott Ullrich
		    $name = ereg_replace(" ", "", $name);
228
		    $name = strtolower($name);
229 658292ef Scott Ullrich
230 a8df0181 Scott Ullrich
		    if($field['bindstofield'] <> "") {
231 b1919dd0 Scott Ullrich
				$arraynum = "";
232
				$field_conv = "";
233
				$field_split = split("->", $field['bindstofield']);
234
				// arraynum is used in cases where there is an array of the same field
235
				// name such as dnsserver (2 of them)
236
				if($field['arraynum'] <> "") $arraynum = "[" . $field['arraynum'] . "]";
237
				foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
238
					$toeval = "\$value = \$config" . $field_conv . $arraynum . ";";
239
					eval($toeval);
240 33a56b27 Colin Smith
					if ($field['type'] == "checkbox") {
241 35fecd55 Scott Ullrich
						$toeval = "if(isset(\$config" . $field_conv . $arraynum . ")) \$value = \" CHECKED\";";
242 f2ec2c48 Scott Ullrich
						eval($toeval);
243
					}
244 a8df0181 Scott Ullrich
		    }
245
246 34b5c5a0 Scott Ullrich
		    if(!$field['combinefieldsend'])
247
			echo "<tr>";
248
249
		    if ($field['type'] == "input") {
250
			if(!$field['dontdisplayname']) {
251
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
252 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
253 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
254
			}
255
			if(!$field['dontcombinecells'])
256
				echo "<td class=\"vtable\">\n";
257 6bb5c9aa Bill Marquette
258
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'";
259
			if($field['validate'])
260
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
261
			echo ">\n";
262 496f9155 Scott Ullrich
		    } else if($field['type'] == "interfaces_selection") {
263
			$size = "";
264
			$multiple = "";
265
			$name = strtolower($name);
266
			echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
267
			echo fixup_string($field['name']) . "\n";
268
			echo "</td>";
269
			echo "<td class=\"vtable\">\n";
270
			if($field['size'] <> "") $size = " size=\"" . $field['size'] . "\"";
271
			if($field['multiple'] <> "" and $field['multiple'] <> "0") {
272
			  $multiple = " multiple=\"multiple\"";
273
			  $name .= "[]";
274
			}
275
			echo "<select name='" . $name . "'" . $size . $multiple . ">\n";
276
			if($field['add_to_interfaces_selection'] <> "") {
277
				$SELECTED = "";
278
				if($field['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
279
				echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
280
			}
281
			$interfaces = &$config['interfaces'];
282
			if($field['all_interfaces'] <> "") {
283
				$ints = split(" ", `/sbin/ifconfig -l`);
284
				$interfaces = array();
285
				foreach ($ints as $int) {
286
					$interfaces[]['descr'] = $int;
287
					$interfaces[] = $int;
288
				}
289
			}
290
			foreach ($interfaces as $ifname => $iface) {
291
			  if ($iface['descr'])
292
				  $ifdescr = $iface['descr'];
293
			  else
294
				  $ifdescr = strtoupper($ifname);
295
			  $ifname = $iface['descr'];
296
			  $ip = "";
297
			  if($field['all_interfaces'] <> "") {
298
				$ifdescr = $iface;
299
				$ip = " " . find_interface_ip($iface);
300
			  }
301
			  $SELECTED = "";
302
			  if($value == $ifdescr) $SELECTED = " SELECTED";
303
			  $to_echo =  "<option value='" . $ifdescr . "'" . $SELECTED . ">" . $ifdescr . $ip . "</option>\n";
304
			  $to_echo .= "<!-- {$value} -->";
305
			  $canecho = 0;
306
			  if($field['interface_filter'] <> "") {
307
				if(stristr($iface, $field['interface_filter']) == true)
308
					$canecho = 1;
309
			  } else {
310
				$canecho = 1;
311
			  }
312
			  if($canecho == 1) 
313
				echo $to_echo;
314
			}
315
				echo "</select>\n";
316
			} else if ($field['type'] == "password") {
317 34b5c5a0 Scott Ullrich
			if(!$field['dontdisplayname']) {
318
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
319 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
320 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
321
			}
322
			if(!$field['dontcombinecells'])
323
				echo "<td class=\"vtable\">";
324
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
325
		    } else if ($field['type'] == "select") {
326
			if(!$field['dontdisplayname']) {
327
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
328 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
329 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
330
			}
331
			if($field['size']) $size = " size='" . $field['size'] . "' ";
332
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
333
			if(!$field['dontcombinecells'])
334
				echo "<td class=\"vtable\">\n";
335
			$onchange = "";
336
			foreach ($field['options']['option'] as $opt) {
337
				if($opt['enablefields'] <> "") {
338
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
339
				}
340
			}
341
			echo "<select " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
342
			foreach ($field['options']['option'] as $opt) {
343 46985f19 Scott Ullrich
				$selected = "";
344
				if($value == $opt['value']) $selected = " SELECTED";
345 34b5c5a0 Scott Ullrich
			    echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
346
			}
347
			echo "</select>\n";
348
		    } else if ($field['type'] == "textarea") {
349
			if(!$field['dontdisplayname']) {
350
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
351 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
352 34b5c5a0 Scott Ullrich
				echo ":</td>";
353
			}
354
			if(!$field['dontcombinecells'])
355
				echo "<td class=\"vtable\">";
356
			echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
357
		    } else if ($field['type'] == "submit") {
358
			echo "<td>&nbsp;<br></td></tr>";
359 2fbd6806 Scott Ullrich
			echo "<tr><td colspan='2'><center>";
360
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
361 34b5c5a0 Scott Ullrich
		    } else if ($field['type'] == "listtopic") {
362
			echo "<td>&nbsp;</td><tr>";
363
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
364 bd31336e Scott Ullrich
		    } else if ($field['type'] == "subnet_select") {
365
			if(!$field['dontdisplayname']) {
366
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
367
				echo fixup_string($field['name']);
368
				echo ":</td>";
369
			}
370
			if(!$field['dontcombinecells'])
371
				echo "<td class=\"vtable\">";
372
			echo "<select name='{$name}'>\n";
373
			for($x=1; $x<33; $x++) {
374
				$CHECKED = "";
375
				if($value == $x) $CHECKED = " SELECTED";
376
				if($x <> 31)
377
					echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
378
			}
379
			echo "</select>\n";
380
		    } else if ($field['type'] == "timezone_select") {
381
			if(!$field['dontdisplayname']) {
382
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
383
				echo fixup_string($field['name']);
384
				echo ":</td>";
385
			}
386
			if(!$field['dontcombinecells'])
387
				echo "<td class=\"vtable\">";
388
			echo "<select name='{$name}'>\n";
389
			foreach ($timezonelist as $tz) {
390
				$SELECTED = "";
391
				if ($value == $tz) $SELECTED = " SELECTED";
392
				echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
393
				echo htmlspecialchars($tz);
394
				echo "</option>\n";
395
			}
396
			echo "</select>\n";
397 34b5c5a0 Scott Ullrich
		    } else if ($field['type'] == "checkbox") {
398
			if(!$field['dontdisplayname']) {
399
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
400
				echo $field['name'];
401
				echo ":</td>";
402
			}
403
			$checked = "";
404 f2ec2c48 Scott Ullrich
			if($value <> "") $checked = " CHECKED";
405 33a56b27 Colin Smith
			echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
406
			if(isset($field['enablefields']) or isset($field['checkenablefields'])) echo " onClick=\"enablechange()\"";
407
			echo ">\n";
408 34b5c5a0 Scott Ullrich
		    }
409
410
		    if($field['typehint'] <> "") {
411
			echo $field['typehint'];
412 2fbd6806 Scott Ullrich
		    }
413 34b5c5a0 Scott Ullrich
414 788ff7cb Scott Ullrich
		    if($field['description'] <> "") {
415
			echo "<br>" . $field['description'];
416 34b5c5a0 Scott Ullrich
			echo "</td>";
417 788ff7cb Scott Ullrich
		    }
418 34b5c5a0 Scott Ullrich
419
		    if(!$field['combinefieldsbegin'])
420
			 echo "</tr>\n";
421 f3c6fdc0 Bill Marquette
422
		    if($field['warning'] <> "") {
423
			echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
424
		    }
425
426 34b5c5a0 Scott Ullrich
		}
427
	}
428
    ?>
429 658292ef Scott Ullrich
</table>
430 85dc4438 Scott Ullrich
<br>&nbsp;
431 5adb3375 Scott Ullrich
</div>
432 658292ef Scott Ullrich
</form>
433 5adb3375 Scott Ullrich
434
<script type="text/javascript">
435
NiftyCheck();
436 b39d4999 Scott Ullrich
Rounded("div#roundme","all","#333333","#FFFFFF","smooth");
437 5adb3375 Scott Ullrich
</script>
438
439 658292ef Scott Ullrich
</body>
440
</html>
441 34b5c5a0 Scott Ullrich
442
<?php
443
444
$fieldnames_array = Array();
445
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
446
	// create a fieldname loop that can be used with javascript
447
	// hide and enable features.
448
	echo "\n<script language=\"JavaScript\">\n";
449
	echo "function disableall() {\n";
450
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
451
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
452
			if(!$field['donotdisable'] <> "") {
453
				array_push($fieldnames_array, $field['name']);
454
				$fieldname = ereg_replace(" ", "", $field['name']);
455
				$fieldname = strtolower($fieldname);
456
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
457
			}
458
		}
459
	}
460
	echo "}\ndisableall();\n";
461
	echo "function enableitems(selectedindex) {\n";
462
	echo "disableall();\n";
463
	$idcounter = 0;
464
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
465
		echo "\tswitch(selectedindex) {\n";
466
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
467
			if($field['options']['option'] <> "") {
468
				foreach ($field['options']['option'] as $opt) {
469
					if($opt['enablefields'] <> "") {
470
						echo "\t\tcase " . $idcounter . ":\n";
471
						$enablefields_split = split(",", $opt['enablefields']);
472
						foreach ($enablefields_split as $efs) {
473
							$fieldname = ereg_replace(" ", "", $efs);
474
							$fieldname = strtolower($fieldname);
475
							if($fieldname <> "") {
476
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
477
								echo $onchange;
478
							}
479
						}
480
						echo "\t\t\tbreak;\n";
481
					}
482
					$idcounter = $idcounter + 1;
483
				}
484
			}
485
		}
486
		echo "\t}\n";
487
	}
488
	echo "}\n";
489
	echo "disableall();\n";
490
	echo "</script>\n\n";
491
}
492
493
494
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
495
	// handle after form display event.
496
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
497
}
498
499
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
500
	// handle after form display event.
501
        echo "\n<script language=\"JavaScript\">\n";
502
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
503
	echo "</script>\n\n";
504
}
505
506 d51f86e0 Scott Ullrich
/*
507
 *  HELPER FUNCTIONS
508
 */
509
510
function fixup_string($string) {
511 a0190b50 Scott Ullrich
	global $config, $myurl;
512 78818d7a Scott Ullrich
	$newstring = $string;
513 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
514
	$https = "";
515
	$port = $config['system']['webguiport'];
516 63637de9 Bill Marquette
	if($port <> "443" and $port <> "80")
517
		$urlport = ":" . $port;
518
	else
519
		$urlport = "";
520
	if($config['system']['webguiproto'] == "https")
521
		$https = "s";
522
    $myurl = "http" . $https . "://" . $config['interfaces']['lan']['ipaddr'] . $urlport;
523 78818d7a Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $newstring);
524 d2133701 Scott Ullrich
	// fixup #2: $wanip
525
	$curwanip = get_current_wan_address();
526 78818d7a Scott Ullrich
	$newstring = str_replace("\$wanip", $curwanip, $newstring);
527 d2133701 Scott Ullrich
	// fixup #3: $lanip
528 78818d7a Scott Ullrich
	$lanip = $config['interfaces']['lan']['ipaddr'];
529
	$newstring = str_replace("\$lanip", $lanip, $newstring);
530 d2133701 Scott Ullrich
	// fixup #4: fix'r'up here.
531 d51f86e0 Scott Ullrich
	return $newstring;
532
}
533
534 bd31336e Scott Ullrich
function is_timezone($elt) {
535
	return !preg_match("/\/$/", $elt);
536
}
537 d51f86e0 Scott Ullrich
538 85dc4438 Scott Ullrich
?>