Project

General

Profile

Download (22.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
##|+PRIV
31
##|*IDENT=page-pfsensewizardsubsystem
32
##|*NAME=pfSense wizard subsystem page
33
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
34
##|*MATCH=wizard.php*
35
##|-PRIV
36

    
37

    
38
require("guiconfig.inc");
39

    
40
function gentitle_pkg($pgname) {
41
	global $config;
42
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
43
}
44

    
45
$stepid = htmlspecialchars($_GET['stepid']);
46
if (isset($_POST['stepid']))
47
    $stepid = htmlspecialchars($_POST['stepid']);
48
if (!$stepid) $stepid = "0";
49

    
50
$xml = htmlspecialchars($_GET['xml']);
51
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
52

    
53
if($xml == "") {
54
	$xml = "not_defined";
55
	print_info_box_np("ERROR:  Could not open " . $xml . ".");
56
	die;
57
} else {
58
	if (file_exists("{$g['www_path']}/wizards/{$xml}"))
59
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
60
	else {
61
		print_info_box_np("ERROR:  Could not open " . $xml . ".");
62
		die;
63
	}
64
}
65

    
66
$title          = $pkg['step'][$stepid]['title'];
67
$description    = $pkg['step'][$stepid]['description'];
68
$totalsteps     = $pkg['totalsteps'];
69

    
70
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
71
$timezonelist = array_filter($timezonelist, 'is_timezone');
72
sort($timezonelist);
73

    
74
/* kill carriage returns */
75
for($x=0; $x<count($timezonelist); $x++)
76
		$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
77

    
78
if ($pkg['step'][$stepid]['includefile'])
79
	require($pkg['step'][$stepid]['includefile']);
80

    
81
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
82
		eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
83
}
84

    
85
if ($_POST) {
86
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
87
        if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
88
		$fieldname = $field['name'];
89
		$unset_fields = "";
90
		$fieldname = ereg_replace(" ", "", $fieldname);
91
		$fieldname = strtolower($fieldname);
92
		// update field with posted values.
93
                if($field['unsetfield'] <> "") $unset_fields = "yes";
94
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
95
		if($field['bindstofield'])
96
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
97
        }
98

    
99
    }
100
    // run custom php code embedded in xml config.
101
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
102
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
103
    }
104
	write_config();
105
    $stepid++;
106
    if($stepid > $totalsteps) $stepid = $totalsteps;
107
}
108

    
109
$title          = $pkg['step'][$stepid]['title'];
110
$description    = $pkg['step'][$stepid]['description'];
111

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

    
127
	if($field_type == "interfaces_selection") {
128
		$text = "unset(\$config" . $field_conv . ");";
129
		eval($text);
130
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
131
		eval($text);
132
		return;
133
	}
134

    
135
	if($unset <> "") {
136
		$text = "unset(\$config" . $field_conv . ");";
137
		eval($text);
138
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
139
		eval($text);
140
	} else {
141
		if($arraynum <> "") {
142
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
143
		} else {
144
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
145
		}
146
		eval($text);
147
	}
148
}
149

    
150
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
151
	// handle before form display event.
152
        // good for modifying posted values, etc.
153
	eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
154
}
155

    
156
$pgtitle = array($title);
157
include("head.inc");
158

    
159
?>
160
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
161

    
162
<?php
163
	if(file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) 
164
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
165
	else 
166
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
167
?>
168

    
169
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
170
<script type="text/javascript">
171
<!--
172

    
173
function  FieldValidate(userinput,  regexp,  message)
174
{
175
                if(!userinput.match(regexp))
176
                                alert(message);
177
}
178

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

    
220
<form action="wizard.php" method="post" name="iform" id="iform">
221
<input type="hidden" name="xml" value="<?= $xml ?>">
222
<input type="hidden" name="stepid" value="<?= $stepid ?>">
223
<?php if ($savemsg) print_info_box($savemsg); ?>
224

    
225
<center>
226

    
227
&nbsp;<br>
228

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

    
256
    <?php
257
	$inputaliases = array();
258
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
259
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
260

    
261
		    $value = $field['value'];
262
		    $name  = $field['name'];
263

    
264
		    $name = ereg_replace(" ", "", $name);
265
		    $name = strtolower($name);
266

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

    
283
		    if(!$field['combinefieldsend'])
284
			echo "<tr>";
285

    
286
		    if ($field['type'] == "input") {
287
			if ($field['displayname']) {
288
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
289
                                echo $field['displayname'];
290
                                echo ":</td>\n";
291
			} else 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 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'] == "inputalias") {
307
			if ($field['displayname']) {
308
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
309
                                echo $field['displayname'];
310
                                echo ":</td>\n";
311
			} else if(!$field['dontdisplayname']) {
312
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
313
				echo fixup_string($field['name']);
314
				echo ":</td>\n";
315
				$inputaliases[] = $name;
316
			}
317
			if(!$field['dontcombinecells'])
318
				echo "<td class=\"vtable\">\n";
319

    
320
			echo "<input  autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
321
			if($field['validate'])
322
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
323
			echo ">\n";
324

    
325

    
326

    
327
		    } else if($field['type'] == "interfaces_selection") {
328
			$size = "";
329
			$multiple = "";
330
			$name = strtolower($name);
331
			echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
332
			echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
333
			echo "</td>";
334
			echo "<td class=\"vtable\">\n";
335
			if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
336
			if($field['multiple'] <> "" and $field['multiple'] <> "0") {
337
			  $multiple = "multiple=\"multiple\"";
338
			  $name .= "[]";
339
			}
340
			echo "<select id='{$name}' name='{$name}' {$size} {$multiple}>\n";
341
			if($field['add_to_interfaces_selection'] <> "") {
342
				$SELECTED = "";
343
				if($field['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
344
				echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
345
			}
346
			$interfaces = get_configured_interface_with_descr();
347
			foreach ($interfaces as $ifname => $iface) {
348
			  $SELECTED = "";
349
			  if ($value == $ifname) $SELECTED = " SELECTED";
350
			  $to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $iface . "</option>\n";
351
			  $to_echo .= "<!-- {$value} -->";
352
			  $canecho = 0;
353
			  if($field['interface_filter'] <> "") {
354
				if(stristr($ifname, $field['interface_filter']) == true)
355
					$canecho = 1;
356
			  } else {
357
				$canecho = 1;
358
			  }
359
			  if($canecho == 1)
360
				echo $to_echo;
361
			}
362
				echo "</select>\n";
363
			} else if ($field['type'] == "password") {
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['dontcombinecells'])
370
				echo "<td class=\"vtable\">";
371
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
372
		    } else if ($field['type'] == "select") {
373
			if ($field['displayname']) {
374
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
375
                                echo $field['displayname'];
376
                                echo ":</td>\n";
377
			} else 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 . ">";
397
				if ($opt['displayname'])
398
					echo $opt['displayname'];
399
				else
400
					echo $opt['name'];
401
				echo "</option>\n";
402
			}
403
			echo "</select>\n";
404
		    } else if ($field['type'] == "textarea") {
405
			if ($field['displayname']) {
406
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
407
                                echo $field['displayname'];
408
                                echo ":</td>\n";
409
			} else if(!$field['dontdisplayname']) {
410
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
411
				echo fixup_string($field['name']);
412
				echo ":</td>";
413
			}
414
			if(!$field['dontcombinecells'])
415
				echo "<td class=\"vtable\">";
416
			echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
417
		    } else if ($field['type'] == "submit") {
418
			echo "<td>&nbsp;<br></td></tr>";
419
			echo "<tr><td colspan='2'><center>";
420
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
421
		    } else if ($field['type'] == "listtopic") {
422
			echo "<td>&nbsp;</td><tr>";
423
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
424
		    } else if ($field['type'] == "subnet_select") {
425
			if ($field['displayname']) {
426
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
427
                                echo $field['displayname'];
428
                                echo ":</td>\n";
429
			} else if(!$field['dontdisplayname']) {
430
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
431
				echo fixup_string($field['name']);
432
				echo ":</td>";
433
			}
434
			if(!$field['dontcombinecells'])
435
				echo "<td class=\"vtable\">";
436
			echo "<select name='{$name}'>\n";
437
			for($x=1; $x<33; $x++) {
438
				$CHECKED = "";
439
				if($value == $x) $CHECKED = " SELECTED";
440
				if($x <> 31)
441
					echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
442
			}
443
			echo "</select>\n";
444
		    } else if ($field['type'] == "timezone_select") {
445
			if ($field['displayname']) {
446
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
447
                                echo $field['displayname'];
448
                                echo ":</td>\n";
449
			} else if(!$field['dontdisplayname']) {
450
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
451
				echo fixup_string($field['name']);
452
				echo ":</td>";
453
			}
454
			if(!$field['dontcombinecells'])
455
				echo "<td class=\"vtable\">";
456
			echo "<select name='{$name}'>\n";
457
			foreach ($timezonelist as $tz) {
458
				$SELECTED = "";
459
				if ($value == $tz) $SELECTED = " SELECTED";
460
				echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
461
				echo htmlspecialchars($tz);
462
				echo "</option>\n";
463
			}
464
			echo "</select>\n";
465
		    } else if ($field['type'] == "checkbox") {
466
			if ($field['displayname']) {
467
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
468
                                echo $field['displayname'];
469
                                echo ":</td>\n";
470
			} else if(!$field['dontdisplayname']) {
471
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
472
				echo $field['name'];
473
				echo ":</td>";
474
			}
475
			$checked = "";
476
			if($value <> "") $checked = " CHECKED";
477
			echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
478
			if(isset($field['enablefields']) or isset($field['checkenablefields'])) echo " onClick=\"enablechange()\"";
479
			echo ">\n";
480
		    }
481

    
482
		    if($field['typehint'] <> "") {
483
			echo $field['typehint'];
484
		    }
485

    
486
		    if($field['description'] <> "") {
487
			echo "<br>" . $field['description'];
488
			echo "</td>";
489
		    }
490

    
491
		    if(!$field['combinefieldsbegin'])
492
			 echo "</tr>\n";
493

    
494
		    if($field['warning'] <> "") {
495
			echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
496
		    }
497

    
498
		}
499
	}
500
    ?>
501
</table>
502
<br>&nbsp;
503
</div>
504
</form>
505
<script type="text/javascript">
506
<!--
507
	if (typeof ext_change != 'undefined') {
508
		ext_change();
509
	}
510
	if (typeof proto_change != 'undefined') {
511
		ext_change();
512
	}
513
	if (typeof proto_change != 'undefined') {
514
		proto_change();
515
	}
516

    
517
<?php
518
	$isfirst = 0;
519
	$aliases = "";
520
	$addrisfirst = 0;
521
	$aliasesaddr = "";
522
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
523
		foreach($config['aliases']['alias'] as $alias_name) {
524
			if(!stristr($alias_name['address'], ".")) {
525
				if($isfirst == 1) $aliases .= ",";
526
				$aliases .= "'" . $alias_name['name'] . "'";
527
				$isfirst = 1;
528
			} else {
529
				if($addrisfirst == 1) $aliasesaddr .= ",";
530
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
531
				$addrisfirst = 1;
532
			}
533
		}
534
?>
535

    
536
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
537
	var customarray=new Array(<?php echo $aliases; ?>);
538

    
539
	window.onload = function () {
540

    
541
		<?php
542
			$counter=0;
543
			foreach($inputaliases as $alias) {
544
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(addressarray));\n";
545
				$counter++;
546
			}
547
		?>
548

    
549
	}
550

    
551
//-->
552
</script>
553
<script type="text/javascript">
554
NiftyCheck();
555
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
556
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
557
</script>
558

    
559
<?php
560

    
561
$fieldnames_array = Array();
562
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
563
	// create a fieldname loop that can be used with javascript
564
	// hide and enable features.
565
	echo "\n<script type=\"text/javascript\">\n";
566
	echo "function disableall() {\n";
567
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
568
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
569
			if(!$field['donotdisable'] <> "") {
570
				array_push($fieldnames_array, $field['name']);
571
				$fieldname = ereg_replace(" ", "", $field['name']);
572
				$fieldname = strtolower($fieldname);
573
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
574
			}
575
		}
576
	}
577
	echo "}\ndisableall();\n";
578
	echo "function enableitems(selectedindex) {\n";
579
	echo "disableall();\n";
580
	$idcounter = 0;
581
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
582
		echo "\tswitch(selectedindex) {\n";
583
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
584
			if($field['options']['option'] <> "") {
585
				foreach ($field['options']['option'] as $opt) {
586
					if($opt['enablefields'] <> "") {
587
						echo "\t\tcase " . $idcounter . ":\n";
588
						$enablefields_split = split(",", $opt['enablefields']);
589
						foreach ($enablefields_split as $efs) {
590
							$fieldname = ereg_replace(" ", "", $efs);
591
							$fieldname = strtolower($fieldname);
592
							if($fieldname <> "") {
593
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
594
								echo $onchange;
595
							}
596
						}
597
						echo "\t\t\tbreak;\n";
598
					}
599
					$idcounter = $idcounter + 1;
600
				}
601
			}
602
		}
603
		echo "\t}\n";
604
	}
605
	echo "}\n";
606
	echo "disableall();\n";
607
	echo "</script>\n\n";
608
}
609

    
610

    
611
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
612
	// handle after form display event.
613
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
614
}
615

    
616
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
617
	// handle after form display event.
618
        echo "\n<script type=\"text/javascript\">\n";
619
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
620
	echo "</script>\n\n";
621
}
622

    
623
/*
624
 *  HELPER FUNCTIONS
625
 */
626

    
627
function fixup_string($string) {
628
	global $config, $myurl;
629
	$newstring = $string;
630
	// fixup #1: $myurl -> http[s]://ip_address:port/
631
	switch($config['system']['webguiproto']) {
632
		case "http":
633
			$proto = "http";
634
			break;
635
		case "https":
636
			$proto = "https";
637
			break;
638
		default:
639
			$proto = "http";
640
			break;
641
	}
642
	$port = $config['system']['webguiport'];
643
	if($port != "") {
644
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
645
			$urlport = ":" . $port;
646
		} elseif ($port != "80" and $port != "443") {
647
			$urlport = ":" . $port;
648
		} else {
649
			$urlport = "";
650
		}
651
	}
652
	$myurl = $proto . "://" . get_interface_ip("lan") . $urlport . "/";
653
	$newstring = str_replace("\$myurl", $myurl, $newstring);
654
	// fixup #2: $wanip
655
	$curwanip = get_interface_ip();
656
	$newstring = str_replace("\$wanip", $curwanip, $newstring);
657
	// fixup #3: $lanip
658
	$lanip = get_interface_ip("lan");
659
	$newstring = str_replace("\$lanip", $lanip, $newstring);
660
	// fixup #4: fix'r'up here.
661
	return $newstring;
662
}
663

    
664
function is_timezone($elt) {
665
	return !preg_match("/\/$/", $elt);
666
}
667

    
668
?>
669

    
670
</body>
671
</html>
672

    
(216-216/217)