Project

General

Profile

Download (21.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    wizard.php
5
    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
require("guiconfig.inc");
31

    
32
function gentitle_pkg($pgname) {
33
	global $config;
34
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
35
}
36

    
37
$stepid = $_GET['stepid'];
38
if (isset($_POST['stepid']))
39
    $stepid = htmlspecialchars($_POST['stepid']);
40
if (!$stepid) $stepid = "0";
41

    
42
$xml = htmlspecialchars($_GET['xml']);
43
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
44

    
45
if($xml == "") {
46
	$xml = "not_defined";
47
	print_info_box_np("ERROR:  Could not open " . $xml . ".");
48
	die;
49
} else {
50
	if (file_exists("{$g['www_path']}/wizards/{$xml}"))
51
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
52
	else {
53
		print_info_box_np("ERROR:  Could not open " . $xml . ".");
54
		die;
55
	}
56
}
57

    
58
$title          = $pkg['step'][$stepid]['title'];
59
$description    = $pkg['step'][$stepid]['description'];
60
$totalsteps     = $pkg['totalsteps'];
61

    
62
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
63
$timezonelist = array_filter($timezonelist, 'is_timezone');
64
sort($timezonelist);
65

    
66
/* kill carriage returns */
67
for($x=0; $x<count($timezonelist); $x++)
68
		$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
69

    
70
if ($pkg['step'][$stepid]['includefile'])
71
	require($pkg['step'][$stepid]['includefile']);
72

    
73
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
74
		eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
75
}
76

    
77
if ($_POST) {
78
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
79
        if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
80
		$fieldname = $field['name'];
81
		$unset_fields = "";
82
		$fieldname = ereg_replace(" ", "", $fieldname);
83
		$fieldname = strtolower($fieldname);
84
		// update field with posted values.
85
                if($field['unsetfield'] <> "") $unset_fields = "yes";
86
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
87
		if($field['bindstofield'])
88
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
89
        }
90

    
91
    }
92
    // run custom php code embedded in xml config.
93
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
94
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
95
    }
96
	write_config();
97
    $stepid++;
98
    if($stepid > $totalsteps) $stepid = $totalsteps;
99
}
100

    
101
$title          = $pkg['step'][$stepid]['title'];
102
$description    = $pkg['step'][$stepid]['description'];
103

    
104
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
105
	global $config;
106
	$field_split = split("->",$field);
107
	foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
108
	if($field_conv == "") return;
109
	if($field_type == "checkbox" and $updatetext <> "on") {
110
		/*
111
		    item is a checkbox, it should have the value "on"
112
		    if it was checked
113
                */
114
		$text = "unset(\$config" . $field_conv . ");";
115
		eval($text);
116
		return;
117
	}
118

    
119
	if($field_type == "interfaces_selection") {
120
		$text = "unset(\$config" . $field_conv . ");";
121
		eval($text);
122
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
123
		eval($text);
124
		return;
125
	}
126

    
127
	if($unset <> "") {
128
		$text = "unset(\$config" . $field_conv . ");";
129
		eval($text);
130
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
131
		eval($text);
132
	} else {
133
		if($arraynum <> "") {
134
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
135
		} else {
136
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
137
		}
138
		eval($text);
139
	}
140
}
141

    
142
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
143
	// handle before form display event.
144
        // good for modifying posted values, etc.
145
	eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
146
}
147

    
148
$pgtitle = $title;
149
include("head.inc");
150

    
151
?>
152
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
153
<?php
154
	if(file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) 
155
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
156
	else 
157
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
158
?>
159

    
160
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
161
<script type="text/javascript">
162
<!--
163

    
164
function  FieldValidate(userinput,  regexp,  message)
165
{
166
                if(!userinput.match(regexp))
167
                                alert(message);
168
}
169

    
170
function enablechange() {
171
<?php
172
        foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
173
                if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
174
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
175
                        if(isset($field['enablefields'])) {
176
                                $enablefields = explode(',', $field['enablefields']);
177
                                foreach($enablefields as $enablefield) {
178
                                        $enablefield = strtolower($enablefield);
179
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
180
                                }
181
                        }
182
                        if(isset($field['checkenablefields'])) {
183
                                $checkenablefields = explode(',', $field['checkenablefields']);
184
                                foreach($checkenablefields as $checkenablefield) {
185
                                        $checkenablefield = strtolower($checkenablefield);
186
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
187
                                }
188
                        }
189
                        print "\t" . '} else {' . "\n";
190
                        if(isset($field['enablefields'])) {
191
                                foreach($enablefields as $enablefield) {
192
                                        $enablefield = strtolower($enablefield);
193
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
194
                                }
195
                        }
196
                        if(isset($field['checkenablefields'])) {
197
                                foreach($checkenablefields as $checkenablefield) {
198
                                        $checkenablefield = strtolower($checkenablefield);
199
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
200
                                }
201
                        }
202
                        print "\t" . '}' . "\n";
203
                }
204
        }
205
?>
206
}
207
//-->
208
</script>
209
<?php } ?>
210

    
211
<form action="wizard.php" method="post" name="iform" id="iform">
212
<input type="hidden" name="xml" value="<?= $xml ?>">
213
<input type="hidden" name="stepid" value="<?= $stepid ?>">
214
<?php if ($savemsg) print_info_box($savemsg); ?>
215

    
216
<center>
217

    
218
&nbsp;<br>
219

    
220
<?php
221
	if($title == "Reload in progress") {
222
		$ip = "http://{$config['interfaces']['lan']['ipaddr']}";
223
	} else {
224
		$ip = "/";
225
	}
226
	if($xml == "traffic_shaper_wizard.xml" && $_REQUEST['stepid'] > "0") {
227
		echo "<a href='/firewall_shaper.php?remove=remove'>";
228
	} else {
229
		echo "<a href='$ip'>";
230
	}
231
?>
232
<img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif"></a>
233
<p>
234
<div style="width:700px;background-color:#ffffff" id="roundme">
235
<table bgcolor="#ffffff" width="600" cellspacing="0" cellpadding="3">
236
    <!-- wizard goes here -->
237
    <tr><td>&nbsp;</td></tr>
238
    <tr><td colspan='2'>
239
<?php
240
	if ($_GET['message'] != "")
241
		print_info_box(htmlspecialchars($_GET['message']));
242
	if ($_POST['message'] != "")
243
		print_info_box(htmlspecialchars($_POST['message']));
244
?></td></tr>
245
    <tr><td colspan='2'><center><b><?= fixup_string($description) ?></b></center></td></tr><tr><td>&nbsp;</td></tr>
246
    <?php
247
	if(!$pkg['step'][$stepid]['disableheader'])
248
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
249
    ?>
250

    
251
    <?php
252
	$inputaliases = array();
253
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
254
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
255

    
256
		    $value = $field['value'];
257
		    $name  = $field['name'];
258

    
259
		    $name = ereg_replace(" ", "", $name);
260
		    $name = strtolower($name);
261

    
262
		    if($field['bindstofield'] <> "") {
263
				$arraynum = "";
264
				$field_conv = "";
265
				$field_split = split("->", $field['bindstofield']);
266
				// arraynum is used in cases where there is an array of the same field
267
				// name such as dnsserver (2 of them)
268
				if($field['arraynum'] <> "") $arraynum = "[" . $field['arraynum'] . "]";
269
				foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
270
					$toeval = "\$value = \$config" . $field_conv . $arraynum . ";";
271
					eval($toeval);
272
					if ($field['type'] == "checkbox") {
273
						$toeval = "if(isset(\$config" . $field_conv . $arraynum . ")) \$value = \" CHECKED\";";
274
						eval($toeval);
275
					}
276
		    }
277

    
278
		    if(!$field['combinefieldsend'])
279
			echo "<tr>";
280

    
281
		    if ($field['type'] == "input") {
282
			if(!$field['dontdisplayname']) {
283
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
284
				echo fixup_string($field['name']);
285
				echo ":</td>\n";
286
			}
287
			if(!$field['dontcombinecells'])
288
				echo "<td class=\"vtable\">\n";
289

    
290
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'";
291
			if($field['validate'])
292
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
293
			echo ">\n";
294

    
295

    
296

    
297
		    } else if ($field['type'] == "inputalias") {
298
			if(!$field['dontdisplayname']) {
299
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
300
				echo fixup_string($field['name']);
301
				echo ":</td>\n";
302
				$inputaliases[] = $name;
303
			}
304
			if(!$field['dontcombinecells'])
305
				echo "<td class=\"vtable\">\n";
306

    
307
			echo "<input  autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
308
			if($field['validate'])
309
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
310
			echo ">\n";
311

    
312

    
313

    
314
		    } else if($field['type'] == "interfaces_selection") {
315
			$size = "";
316
			$multiple = "";
317
			$name = strtolower($name);
318
			echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
319
			echo fixup_string($field['name']) . ":\n";
320
			echo "</td>";
321
			echo "<td class=\"vtable\">\n";
322
			if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
323
			if($field['multiple'] <> "" and $field['multiple'] <> "0") {
324
			  $multiple = "multiple=\"multiple\"";
325
			  $name .= "[]";
326
			}
327
			echo "<select id='{$name}' name='{$name}' {$size} {$multiple}>\n";
328
			if($field['add_to_interfaces_selection'] <> "") {
329
				$SELECTED = "";
330
				if($field['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
331
				echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
332
			}
333
			$interfaces = $config['interfaces'];
334
			if($field['all_interfaces'] <> "") {
335
				$ints = split(" ", `/sbin/ifconfig -l`);
336
				$interfaces = array();
337
				foreach ($ints as $int) {
338
					$interfaces[]['descr'] = $int;
339
					$interfaces[] = $int;
340
				}
341
			}
342
			foreach ($interfaces as $ifname => $iface) {
343
			  if ($iface['descr'])
344
				  $ifdescr = $iface['descr'];
345
			  else
346
				  $ifdescr = strtoupper($ifname);
347
			  $ip = "";
348
			  if($field['all_interfaces'] <> "") {
349
				$ifdescr = $iface;
350
				$ip = " " . find_interface_ip($iface);
351
			  }
352
			  $SELECTED = "";
353
			  if ($value == $ifname) $SELECTED = " SELECTED";
354
			  $to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $ifdescr . $ip . "</option>\n";
355
			  $to_echo .= "<!-- {$value} -->";
356
			  $canecho = 0;
357
			  if($field['interface_filter'] <> "") {
358
				if(stristr($iface, $field['interface_filter']) == true)
359
					$canecho = 1;
360
			  } else {
361
				$canecho = 1;
362
			  }
363
			  if($canecho == 1)
364
				echo $to_echo;
365
			}
366
				echo "</select>\n";
367
			} else if ($field['type'] == "password") {
368
			if(!$field['dontdisplayname']) {
369
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
370
				echo fixup_string($field['name']);
371
				echo ":</td>\n";
372
			}
373
			if(!$field['dontcombinecells'])
374
				echo "<td class=\"vtable\">";
375
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
376
		    } else if ($field['type'] == "select") {
377
			if(!$field['dontdisplayname']) {
378
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
379
				echo fixup_string($field['name']);
380
				echo ":</td>\n";
381
			}
382
			if($field['size']) $size = " size='" . $field['size'] . "' ";
383
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
384
			if(!$field['dontcombinecells'])
385
				echo "<td class=\"vtable\">\n";
386
			$onchange = "";
387
			foreach ($field['options']['option'] as $opt) {
388
				if($opt['enablefields'] <> "") {
389
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
390
				}
391
			}
392
			echo "<select " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
393
			foreach ($field['options']['option'] as $opt) {
394
				$selected = "";
395
				if($value == $opt['value']) $selected = " SELECTED";
396
			    echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
397
			}
398
			echo "</select>\n";
399
		    } else if ($field['type'] == "textarea") {
400
			if(!$field['dontdisplayname']) {
401
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
402
				echo fixup_string($field['name']);
403
				echo ":</td>";
404
			}
405
			if(!$field['dontcombinecells'])
406
				echo "<td class=\"vtable\">";
407
			echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
408
		    } else if ($field['type'] == "submit") {
409
			echo "<td>&nbsp;<br></td></tr>";
410
			echo "<tr><td colspan='2'><center>";
411
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
412
		    } else if ($field['type'] == "listtopic") {
413
			echo "<td>&nbsp;</td><tr>";
414
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
415
		    } else if ($field['type'] == "subnet_select") {
416
			if(!$field['dontdisplayname']) {
417
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
418
				echo fixup_string($field['name']);
419
				echo ":</td>";
420
			}
421
			if(!$field['dontcombinecells'])
422
				echo "<td class=\"vtable\">";
423
			echo "<select name='{$name}'>\n";
424
			for($x=1; $x<33; $x++) {
425
				$CHECKED = "";
426
				if($value == $x) $CHECKED = " SELECTED";
427
				if($x <> 31)
428
					echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
429
			}
430
			echo "</select>\n";
431
		    } else if ($field['type'] == "timezone_select") {
432
			if(!$field['dontdisplayname']) {
433
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
434
				echo fixup_string($field['name']);
435
				echo ":</td>";
436
			}
437
			if(!$field['dontcombinecells'])
438
				echo "<td class=\"vtable\">";
439
			echo "<select name='{$name}'>\n";
440
			foreach ($timezonelist as $tz) {
441
				$SELECTED = "";
442
				if ($value == $tz) $SELECTED = " SELECTED";
443
				echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
444
				echo htmlspecialchars($tz);
445
				echo "</option>\n";
446
			}
447
			echo "</select>\n";
448
		    } else if ($field['type'] == "checkbox") {
449
			if(!$field['dontdisplayname']) {
450
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
451
				echo $field['name'];
452
				echo ":</td>";
453
			}
454
			$checked = "";
455
			if($value <> "") $checked = " CHECKED";
456
			echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
457
			if(isset($field['enablefields']) or isset($field['checkenablefields'])) echo " onClick=\"enablechange()\"";
458
			echo ">\n";
459
		    }
460

    
461
		    if($field['typehint'] <> "") {
462
			echo $field['typehint'];
463
		    }
464

    
465
		    if($field['description'] <> "") {
466
			echo "<br>" . $field['description'];
467
			echo "</td>";
468
		    }
469

    
470
		    if(!$field['combinefieldsbegin'])
471
			 echo "</tr>\n";
472

    
473
		    if($field['warning'] <> "") {
474
			echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
475
		    }
476

    
477
		}
478
	}
479
    ?>
480
</table>
481
<br>&nbsp;
482
</div>
483
</form>
484
<script type="text/javascript">
485
	if (typeof ext_change != 'undefined') {
486
		ext_change();
487
	}
488
	if (typeof proto_change != 'undefined') {
489
		ext_change();
490
	}
491
	if (typeof proto_change != 'undefined') {
492
		proto_change();
493
	}
494

    
495
<?php
496
	$isfirst = 0;
497
	$aliases = "";
498
	$addrisfirst = 0;
499
	$aliasesaddr = "";
500
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
501
		foreach($config['aliases']['alias'] as $alias_name) {
502
			if(!stristr($alias_name['address'], ".")) {
503
				if($isfirst == 1) $aliases .= ",";
504
				$aliases .= "'" . $alias_name['name'] . "'";
505
				$isfirst = 1;
506
			} else {
507
				if($addrisfirst == 1) $aliasesaddr .= ",";
508
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
509
				$addrisfirst = 1;
510
			}
511
		}
512
?>
513

    
514
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
515
	var customarray=new Array(<?php echo $aliases; ?>);
516

    
517
	window.onload = function () {
518

    
519
		<?php
520
			$counter=0;
521
			foreach($inputaliases as $alias) {
522
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(addressarray));\n";
523
				$counter++;
524
			}
525
		?>
526

    
527
	}
528
</script>
529
<script type="text/javascript">
530
	NiftyCheck();
531
	var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
532
	Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
533
</script>
534

    
535
<?php
536

    
537
$fieldnames_array = Array();
538
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
539
	// create a fieldname loop that can be used with javascript
540
	// hide and enable features.
541
	echo "\n<script language=\"JavaScript\">\n";
542
	echo "function disableall() {\n";
543
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
544
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
545
			if(!$field['donotdisable'] <> "") {
546
				array_push($fieldnames_array, $field['name']);
547
				$fieldname = ereg_replace(" ", "", $field['name']);
548
				$fieldname = strtolower($fieldname);
549
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
550
			}
551
		}
552
	}
553
	echo "}\ndisableall();\n";
554
	echo "function enableitems(selectedindex) {\n";
555
	echo "disableall();\n";
556
	$idcounter = 0;
557
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
558
		echo "\tswitch(selectedindex) {\n";
559
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
560
			if($field['options']['option'] <> "") {
561
				foreach ($field['options']['option'] as $opt) {
562
					if($opt['enablefields'] <> "") {
563
						echo "\t\tcase " . $idcounter . ":\n";
564
						$enablefields_split = split(",", $opt['enablefields']);
565
						foreach ($enablefields_split as $efs) {
566
							$fieldname = ereg_replace(" ", "", $efs);
567
							$fieldname = strtolower($fieldname);
568
							if($fieldname <> "") {
569
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
570
								echo $onchange;
571
							}
572
						}
573
						echo "\t\t\tbreak;\n";
574
					}
575
					$idcounter = $idcounter + 1;
576
				}
577
			}
578
		}
579
		echo "\t}\n";
580
	}
581
	echo "}\n";
582
	echo "disableall();\n";
583
	echo "</script>\n\n";
584
}
585

    
586

    
587
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
588
	// handle after form display event.
589
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
590
}
591

    
592
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
593
	// handle after form display event.
594
        echo "\n<script language=\"JavaScript\">\n";
595
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
596
	echo "</script>\n\n";
597
}
598

    
599
/*
600
 *  HELPER FUNCTIONS
601
 */
602

    
603
function fixup_string($string) {
604
	global $config, $myurl;
605
	$newstring = $string;
606
	// fixup #1: $myurl -> http[s]://ip_address:port/
607
	switch($config['system']['webguiproto']) {
608
		case "http":
609
			$proto = "http";
610
			break;
611
		case "https":
612
			$proto = "https";
613
			break;
614
		default:
615
			$proto = "http";
616
			break;
617
	}
618
	$port = $config['system']['webguiport'];
619
	if($port != "") {
620
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
621
			$urlport = ":" . $port;
622
		} elseif ($port != "80" and $port != "443") {
623
			$urlport = ":" . $port;
624
		} else {
625
			$urlport = "";
626
		}
627
	}
628
	$myurl = $proto . "://" . $config['interfaces']['lan']['ipaddr'] . $urlport . "/";
629
	$newstring = str_replace("\$myurl", $myurl, $newstring);
630
	// fixup #2: $wanip
631
	$curwanip = get_current_wan_address();
632
	$newstring = str_replace("\$wanip", $curwanip, $newstring);
633
	// fixup #3: $lanip
634
	$lanip = $config['interfaces']['lan']['ipaddr'];
635
	$newstring = str_replace("\$lanip", $lanip, $newstring);
636
	// fixup #4: fix'r'up here.
637
	return $newstring;
638
}
639

    
640
function is_timezone($elt) {
641
	return !preg_match("/\/$/", $elt);
642
}
643

    
644
?>
645

    
646
</body>
647
</html>
648

    
(173-173/174)