Project

General

Profile

Download (20.7 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 = $_POST['stepid'];
40
if (!$stepid) $stepid = "0";
41

    
42
// XXX: Make this input safe.
43
$xml = $_GET['xml'];
44
if($_POST['xml']) $xml = $_POST['xml'];
45

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
152
?>
153
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
154
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
155
<script language="JavaScript">
156
<!--
157

    
158
function  FieldValidate(userinput,  regexp,  message)
159
{
160
                if(!userinput.match(regexp))
161
                                alert(message);
162
}
163

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

    
205
<form action="wizard.php" method="post" name="iform" id="iform">
206
<input type="hidden" name="xml" value="<?= $xml ?>">
207
<input type="hidden" name="stepid" value="<?= $stepid ?>">
208
<?php if ($savemsg) print_info_box($savemsg); ?>
209

    
210
<center>
211

    
212
&nbsp;<br>
213

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

    
245
    <?php
246
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
247
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
248

    
249
		    $value = $field['value'];
250
		    $name  = $field['name'];
251

    
252
		    $name = ereg_replace(" ", "", $name);
253
		    $name = strtolower($name);
254

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

    
271
		    if(!$field['combinefieldsend'])
272
			echo "<tr>";
273

    
274
		    if ($field['type'] == "input") {
275
			if(!$field['dontdisplayname']) {
276
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
277
				echo fixup_string($field['name']);
278
				echo ":</td>\n";
279
			}
280
			if(!$field['dontcombinecells'])
281
				echo "<td class=\"vtable\">\n";
282

    
283
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'";
284
			if($field['validate'])
285
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
286
			echo ">\n";
287

    
288

    
289

    
290
		    } else if ($field['type'] == "inputalias") {
291
			if(!$field['dontdisplayname']) {
292
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
293
				echo fixup_string($field['name']);
294
				echo ":</td>\n";
295
			}
296
			if(!$field['dontcombinecells'])
297
				echo "<td class=\"vtable\">\n";
298

    
299
			echo "<input  autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
300
			if($field['validate'])
301
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
302
			echo ">\n";
303

    
304

    
305

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

    
453
		    if($field['typehint'] <> "") {
454
			echo $field['typehint'];
455
		    }
456

    
457
		    if($field['description'] <> "") {
458
			echo "<br>" . $field['description'];
459
			echo "</td>";
460
		    }
461

    
462
		    if(!$field['combinefieldsbegin'])
463
			 echo "</tr>\n";
464

    
465
		    if($field['warning'] <> "") {
466
			echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
467
		    }
468

    
469
		}
470
	}
471
    ?>
472
</table>
473
<br>&nbsp;
474
</div>
475
</form>
476
<script language="JavaScript">
477
<!--
478
	if (typeof ext_change != 'undefined') {
479
		ext_change();
480
	}
481
	if (typeof proto_change != 'undefined') {
482
		ext_change();
483
	}
484
	if (typeof proto_change != 'undefined') {
485
		proto_change();
486
	}
487

    
488
<?php
489
	$isfirst = 0;
490
	$aliases = "";
491
	$addrisfirst = 0;
492
	$aliasesaddr = "";
493
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
494
		foreach($config['aliases']['alias'] as $alias_name) {
495
			if(!stristr($alias_name['address'], ".")) {
496
				if($isfirst == 1) $aliases .= ",";
497
				$aliases .= "'" . $alias_name['name'] . "'";
498
				$isfirst = 1;
499
			} else {
500
				if($addrisfirst == 1) $aliasesaddr .= ",";
501
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
502
				$addrisfirst = 1;
503
			}
504
		}
505
?>
506

    
507
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
508
	var customarray=new Array(<?php echo $aliases; ?>);
509

    
510
//-->
511
</script>
512
<script type="text/javascript">
513
NiftyCheck();
514
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
515
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
516
</script>
517

    
518
<?php
519

    
520
$fieldnames_array = Array();
521
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
522
	// create a fieldname loop that can be used with javascript
523
	// hide and enable features.
524
	echo "\n<script language=\"JavaScript\">\n";
525
	echo "function disableall() {\n";
526
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
527
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
528
			if(!$field['donotdisable'] <> "") {
529
				array_push($fieldnames_array, $field['name']);
530
				$fieldname = ereg_replace(" ", "", $field['name']);
531
				$fieldname = strtolower($fieldname);
532
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
533
			}
534
		}
535
	}
536
	echo "}\ndisableall();\n";
537
	echo "function enableitems(selectedindex) {\n";
538
	echo "disableall();\n";
539
	$idcounter = 0;
540
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
541
		echo "\tswitch(selectedindex) {\n";
542
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
543
			if($field['options']['option'] <> "") {
544
				foreach ($field['options']['option'] as $opt) {
545
					if($opt['enablefields'] <> "") {
546
						echo "\t\tcase " . $idcounter . ":\n";
547
						$enablefields_split = split(",", $opt['enablefields']);
548
						foreach ($enablefields_split as $efs) {
549
							$fieldname = ereg_replace(" ", "", $efs);
550
							$fieldname = strtolower($fieldname);
551
							if($fieldname <> "") {
552
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
553
								echo $onchange;
554
							}
555
						}
556
						echo "\t\t\tbreak;\n";
557
					}
558
					$idcounter = $idcounter + 1;
559
				}
560
			}
561
		}
562
		echo "\t}\n";
563
	}
564
	echo "}\n";
565
	echo "disableall();\n";
566
	echo "</script>\n\n";
567
}
568

    
569

    
570
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
571
	// handle after form display event.
572
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
573
}
574

    
575
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
576
	// handle after form display event.
577
        echo "\n<script language=\"JavaScript\">\n";
578
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
579
	echo "</script>\n\n";
580
}
581

    
582
/*
583
 *  HELPER FUNCTIONS
584
 */
585

    
586
function fixup_string($string) {
587
	global $config, $myurl;
588
	$newstring = $string;
589
	// fixup #1: $myurl -> http[s]://ip_address:port/
590
	switch($config['system']['webguiproto']) {
591
		case "http":
592
			$proto = "http";
593
			break;
594
		case "https":
595
			$proto = "https";
596
			break;
597
		default:
598
			$proto = "http";
599
			break;
600
	}
601
	$port = $config['system']['webguiport'];
602
	if($port != "") {
603
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
604
			$urlport = ":" . $port;
605
		} elseif ($port != "80" and $port != "443") {
606
			$urlport = ":" . $port;
607
		} else {
608
			$urlport = "";
609
		}
610
	}
611
	$myurl = $proto . "://" . $config['interfaces']['lan']['ipaddr'] . $urlport . "/";
612
	$newstring = str_replace("\$myurl", $myurl, $newstring);
613
	// fixup #2: $wanip
614
	$curwanip = get_current_wan_address();
615
	$newstring = str_replace("\$wanip", $curwanip, $newstring);
616
	// fixup #3: $lanip
617
	$lanip = $config['interfaces']['lan']['ipaddr'];
618
	$newstring = str_replace("\$lanip", $lanip, $newstring);
619
	// fixup #4: fix'r'up here.
620
	return $newstring;
621
}
622

    
623
function is_timezone($elt) {
624
	return !preg_match("/\/$/", $elt);
625
}
626

    
627
?>
628

    
629
</body>
630
</html>
631

    
(185-185/186)