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 = htmlspecialchars($_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 = array($title);
149
include("head.inc");
150

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

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

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

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

    
209
<center>
210

    
211
&nbsp;<br>
212

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

    
240
    <?php
241
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
242
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
243

    
244
		    $value = $field['value'];
245
		    $name  = $field['name'];
246

    
247
		    $name = ereg_replace(" ", "", $name);
248
		    $name = strtolower($name);
249

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

    
266
		    if(!$field['combinefieldsend'])
267
			echo "<tr>";
268

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

    
278
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'";
279
			if($field['validate'])
280
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
281
			echo ">\n";
282

    
283

    
284

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

    
294
			echo "<input  autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
295
			if($field['validate'])
296
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
297
			echo ">\n";
298

    
299

    
300

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

    
448
		    if($field['typehint'] <> "") {
449
			echo $field['typehint'];
450
		    }
451

    
452
		    if($field['description'] <> "") {
453
			echo "<br>" . $field['description'];
454
			echo "</td>";
455
		    }
456

    
457
		    if(!$field['combinefieldsbegin'])
458
			 echo "</tr>\n";
459

    
460
		    if($field['warning'] <> "") {
461
			echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
462
		    }
463

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

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

    
502
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
503
	var customarray=new Array(<?php echo $aliases; ?>);
504

    
505
//-->
506
</script>
507
<script type="text/javascript">
508
NiftyCheck();
509
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
510
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
511
</script>
512

    
513
<?php
514

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

    
564

    
565
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
566
	// handle after form display event.
567
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
568
}
569

    
570
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
571
	// handle after form display event.
572
        echo "\n<script language=\"JavaScript\">\n";
573
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
574
	echo "</script>\n\n";
575
}
576

    
577
/*
578
 *  HELPER FUNCTIONS
579
 */
580

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

    
618
function is_timezone($elt) {
619
	return !preg_match("/\/$/", $elt);
620
}
621

    
622
?>
623

    
624
</body>
625
</html>
626

    
(196-196/197)