Project

General

Profile

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

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

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

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

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

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

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

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

    
287

    
288

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

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

    
303

    
304

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

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

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

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

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

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

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

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

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

    
517
<?php
518

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

    
568

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

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

    
581
/*
582
 *  HELPER FUNCTIONS
583
 */
584

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

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

    
626
?>
627

    
628
</body>
629
</html>
630

    
(172-172/173)