1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
<?php
/* $Id$ */
/*
wizard.php
Copyright (C) 2004 Scott Ullrich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
##|+PRIV
##|*IDENT=page-pfsensewizardsubsystem
##|*NAME=pfSense wizard subsystem page
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
##|*MATCH=wizard.php*
##|-PRIV
require("guiconfig.inc");
function gentitle_pkg($pgname) {
global $config;
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
}
$stepid = htmlspecialchars($_GET['stepid']);
if (isset($_POST['stepid']))
$stepid = htmlspecialchars($_POST['stepid']);
if (!$stepid) $stepid = "0";
$xml = htmlspecialchars($_GET['xml']);
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
if($xml == "") {
$xml = "not_defined";
print_info_box_np("ERROR: Could not open " . $xml . ".");
die;
} else {
if (file_exists("{$g['www_path']}/wizards/{$xml}"))
$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
else {
print_info_box_np("ERROR: Could not open " . $xml . ".");
die;
}
}
$title = $pkg['step'][$stepid]['title'];
$description = $pkg['step'][$stepid]['description'];
$totalsteps = $pkg['totalsteps'];
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
$timezonelist = array_filter($timezonelist, 'is_timezone');
sort($timezonelist);
/* kill carriage returns */
for($x=0; $x<count($timezonelist); $x++)
$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
if ($pkg['step'][$stepid]['includefile'])
require($pkg['step'][$stepid]['includefile']);
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
}
if ($_POST) {
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
$fieldname = $field['name'];
$unset_fields = "";
$fieldname = ereg_replace(" ", "", $fieldname);
$fieldname = strtolower($fieldname);
// update field with posted values.
if($field['unsetfield'] <> "") $unset_fields = "yes";
if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
if($field['bindstofield'])
update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
}
}
// run custom php code embedded in xml config.
if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
eval($pkg['step'][$stepid]['stepsubmitphpaction']);
}
write_config();
$stepid++;
if($stepid > $totalsteps) $stepid = $totalsteps;
}
$title = $pkg['step'][$stepid]['title'];
$description = $pkg['step'][$stepid]['description'];
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
global $config;
$field_split = split("->",$field);
foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
if($field_conv == "") return;
if($field_type == "checkbox" and $updatetext <> "on") {
/*
item is a checkbox, it should have the value "on"
if it was checked
*/
$text = "unset(\$config" . $field_conv . ");";
eval($text);
return;
}
if($field_type == "interfaces_selection") {
$text = "unset(\$config" . $field_conv . ");";
eval($text);
$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
eval($text);
return;
}
if($unset <> "") {
$text = "unset(\$config" . $field_conv . ");";
eval($text);
$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
eval($text);
} else {
if($arraynum <> "") {
$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
} else {
$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
}
eval($text);
}
}
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
// handle before form display event.
// good for modifying posted values, etc.
eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
}
$pgtitle = array($title);
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
<?php
if(file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css"))
echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
else
echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
?>
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
<script type="text/javascript">
<!--
function FieldValidate(userinput, regexp, message)
{
if(!userinput.match(regexp))
alert(message);
}
function enablechange() {
<?php
foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
if(isset($field['enablefields'])) {
$enablefields = explode(',', $field['enablefields']);
foreach($enablefields as $enablefield) {
$enablefield = strtolower($enablefield);
print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
}
}
if(isset($field['checkenablefields'])) {
$checkenablefields = explode(',', $field['checkenablefields']);
foreach($checkenablefields as $checkenablefield) {
$checkenablefield = strtolower($checkenablefield);
print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
}
}
print "\t" . '} else {' . "\n";
if(isset($field['enablefields'])) {
foreach($enablefields as $enablefield) {
$enablefield = strtolower($enablefield);
print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
}
}
if(isset($field['checkenablefields'])) {
foreach($checkenablefields as $checkenablefield) {
$checkenablefield = strtolower($checkenablefield);
print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
}
}
print "\t" . '}' . "\n";
}
}
?>
}
//-->
</script>
<?php } ?>
<form action="wizard.php" method="post" name="iform" id="iform">
<input type="hidden" name="xml" value="<?= $xml ?>">
<input type="hidden" name="stepid" value="<?= $stepid ?>">
<?php if ($savemsg) print_info_box($savemsg); ?>
<center>
<br>
<?php
if($title == "Reload in progress") {
$ip = "http://" . get_interface_ip("lan");
} else {
$ip = "/";
}
echo "<a href='$ip'>";
?>
<img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif"></a>
<p>
<div style="width:700px;background-color:#ffffff" id="roundme">
<table bgcolor="#ffffff" width="600" cellspacing="0" cellpadding="3">
<!-- wizard goes here -->
<tr><td> </td></tr>
<tr><td colspan='2'>
<?php
if ($_GET['message'] != "")
print_info_box(htmlspecialchars($_GET['message']));
if ($_POST['message'] != "")
print_info_box(htmlspecialchars($_POST['message']));
?></td></tr>
<tr><td colspan='2'><center><b><?= fixup_string($description) ?></b></center></td></tr><tr><td> </td></tr>
<?php
if(!$pkg['step'][$stepid]['disableheader'])
echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
?>
<?php
$inputaliases = array();
if($pkg['step'][$stepid]['fields']['field'] <> "") {
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
$value = $field['value'];
$name = $field['name'];
$name = ereg_replace(" ", "", $name);
$name = strtolower($name);
if($field['bindstofield'] <> "") {
$arraynum = "";
$field_conv = "";
$field_split = split("->", $field['bindstofield']);
// arraynum is used in cases where there is an array of the same field
// name such as dnsserver (2 of them)
if($field['arraynum'] <> "") $arraynum = "[" . $field['arraynum'] . "]";
foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
$toeval = "\$value = \$config" . $field_conv . $arraynum . ";";
eval($toeval);
if ($field['type'] == "checkbox") {
$toeval = "if(isset(\$config" . $field_conv . $arraynum . ")) \$value = \" CHECKED\";";
eval($toeval);
}
}
if(!$field['combinefieldsend'])
echo "<tr>";
if ($field['type'] == "input") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>\n";
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">\n";
echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'";
if($field['validate'])
echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
echo ">\n";
} else if ($field['type'] == "inputalias") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>\n";
$inputaliases[] = $name;
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">\n";
echo "<input autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
if($field['validate'])
echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
echo ">\n";
} else if($field['type'] == "interfaces_selection") {
$size = "";
$multiple = "";
$name = strtolower($name);
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
echo "</td>";
echo "<td class=\"vtable\">\n";
if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
if($field['multiple'] <> "" and $field['multiple'] <> "0") {
$multiple = "multiple=\"multiple\"";
$name .= "[]";
}
echo "<select id='{$name}' name='{$name}' {$size} {$multiple}>\n";
if($field['add_to_interfaces_selection'] <> "") {
$SELECTED = "";
if($field['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
}
$interfaces = $config['interfaces'];
if($field['all_interfaces'] <> "") {
$ints = split(" ", `/sbin/ifconfig -l`);
$interfaces = array();
foreach ($ints as $int) {
$interfaces[]['descr'] = $int;
$interfaces[] = $int;
}
}
foreach ($interfaces as $ifname => $iface) {
if ($iface['descr'])
$ifdescr = $iface['descr'];
else
$ifdescr = strtoupper($ifname);
$ip = "";
if($field['all_interfaces'] <> "") {
$ifdescr = $iface;
$ip = " " . find_interface_ip($iface);
}
$SELECTED = "";
if ($value == $ifname) $SELECTED = " SELECTED";
$to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $ifdescr . $ip . "</option>\n";
$to_echo .= "<!-- {$value} -->";
$canecho = 0;
if($field['interface_filter'] <> "") {
if(stristr($iface, $field['interface_filter']) == true)
$canecho = 1;
} else {
$canecho = 1;
}
if($canecho == 1)
echo $to_echo;
}
echo "</select>\n";
} else if ($field['type'] == "password") {
if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>\n";
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">";
echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
} else if ($field['type'] == "select") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>\n";
}
if($field['size']) $size = " size='" . $field['size'] . "' ";
if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">\n";
$onchange = "";
foreach ($field['options']['option'] as $opt) {
if($opt['enablefields'] <> "") {
$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
}
}
echo "<select " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
foreach ($field['options']['option'] as $opt) {
$selected = "";
if($value == $opt['value']) $selected = " SELECTED";
echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">";
if ($opt['displayname'])
echo $opt['displayname'];
else
echo $opt['name'];
echo "</option>\n";
}
echo "</select>\n";
} else if ($field['type'] == "textarea") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>";
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">";
echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
} else if ($field['type'] == "submit") {
echo "<td> <br></td></tr>";
echo "<tr><td colspan='2'><center>";
echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
} else if ($field['type'] == "listtopic") {
echo "<td> </td><tr>";
echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
} else if ($field['type'] == "subnet_select") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>";
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">";
echo "<select name='{$name}'>\n";
for($x=1; $x<33; $x++) {
$CHECKED = "";
if($value == $x) $CHECKED = " SELECTED";
if($x <> 31)
echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
}
echo "</select>\n";
} else if ($field['type'] == "timezone_select") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo fixup_string($field['name']);
echo ":</td>";
}
if(!$field['dontcombinecells'])
echo "<td class=\"vtable\">";
echo "<select name='{$name}'>\n";
foreach ($timezonelist as $tz) {
$SELECTED = "";
if ($value == $tz) $SELECTED = " SELECTED";
echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
echo htmlspecialchars($tz);
echo "</option>\n";
}
echo "</select>\n";
} else if ($field['type'] == "checkbox") {
if ($field['displayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['displayname'];
echo ":</td>\n";
} else if(!$field['dontdisplayname']) {
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
echo $field['name'];
echo ":</td>";
}
$checked = "";
if($value <> "") $checked = " CHECKED";
echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
if(isset($field['enablefields']) or isset($field['checkenablefields'])) echo " onClick=\"enablechange()\"";
echo ">\n";
}
if($field['typehint'] <> "") {
echo $field['typehint'];
}
if($field['description'] <> "") {
echo "<br>" . $field['description'];
echo "</td>";
}
if(!$field['combinefieldsbegin'])
echo "</tr>\n";
if($field['warning'] <> "") {
echo "<br><b><font color=\"red\">" . $field['warning'] . "</font></b>";
}
}
}
?>
</table>
<br>
</div>
</form>
<script type="text/javascript">
<!--
if (typeof ext_change != 'undefined') {
ext_change();
}
if (typeof proto_change != 'undefined') {
ext_change();
}
if (typeof proto_change != 'undefined') {
proto_change();
}
<?php
$isfirst = 0;
$aliases = "";
$addrisfirst = 0;
$aliasesaddr = "";
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
foreach($config['aliases']['alias'] as $alias_name) {
if(!stristr($alias_name['address'], ".")) {
if($isfirst == 1) $aliases .= ",";
$aliases .= "'" . $alias_name['name'] . "'";
$isfirst = 1;
} else {
if($addrisfirst == 1) $aliasesaddr .= ",";
$aliasesaddr .= "'" . $alias_name['name'] . "'";
$addrisfirst = 1;
}
}
?>
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
var customarray=new Array(<?php echo $aliases; ?>);
window.onload = function () {
<?php
$counter=0;
foreach($inputaliases as $alias) {
echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(addressarray));\n";
$counter++;
}
?>
}
//-->
</script>
<script type="text/javascript">
NiftyCheck();
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
</script>
<?php
$fieldnames_array = Array();
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
// create a fieldname loop that can be used with javascript
// hide and enable features.
echo "\n<script type=\"text/javascript\">\n";
echo "function disableall() {\n";
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
if(!$field['donotdisable'] <> "") {
array_push($fieldnames_array, $field['name']);
$fieldname = ereg_replace(" ", "", $field['name']);
$fieldname = strtolower($fieldname);
echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
}
}
}
echo "}\ndisableall();\n";
echo "function enableitems(selectedindex) {\n";
echo "disableall();\n";
$idcounter = 0;
if($pkg['step'][$stepid]['fields']['field'] <> "") {
echo "\tswitch(selectedindex) {\n";
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
if($field['options']['option'] <> "") {
foreach ($field['options']['option'] as $opt) {
if($opt['enablefields'] <> "") {
echo "\t\tcase " . $idcounter . ":\n";
$enablefields_split = split(",", $opt['enablefields']);
foreach ($enablefields_split as $efs) {
$fieldname = ereg_replace(" ", "", $efs);
$fieldname = strtolower($fieldname);
if($fieldname <> "") {
$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
echo $onchange;
}
}
echo "\t\t\tbreak;\n";
}
$idcounter = $idcounter + 1;
}
}
}
echo "\t}\n";
}
echo "}\n";
echo "disableall();\n";
echo "</script>\n\n";
}
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
// handle after form display event.
eval($pkg['step'][$stepid]['stepafterformdisplay']);
}
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
// handle after form display event.
echo "\n<script type=\"text/javascript\">\n";
echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
echo "</script>\n\n";
}
/*
* HELPER FUNCTIONS
*/
function fixup_string($string) {
global $config, $myurl;
$newstring = $string;
// fixup #1: $myurl -> http[s]://ip_address:port/
switch($config['system']['webguiproto']) {
case "http":
$proto = "http";
break;
case "https":
$proto = "https";
break;
default:
$proto = "http";
break;
}
$port = $config['system']['webguiport'];
if($port != "") {
if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
$urlport = ":" . $port;
} elseif ($port != "80" and $port != "443") {
$urlport = ":" . $port;
} else {
$urlport = "";
}
}
$myurl = $proto . "://" . get_interface_ip("lan") . $urlport . "/";
$newstring = str_replace("\$myurl", $myurl, $newstring);
// fixup #2: $wanip
$curwanip = get_interface_ip();
$newstring = str_replace("\$wanip", $curwanip, $newstring);
// fixup #3: $lanip
$lanip = get_interface_ip("lan");
$newstring = str_replace("\$lanip", $lanip, $newstring);
// fixup #4: fix'r'up here.
return $newstring;
}
function is_timezone($elt) {
return !preg_match("/\/$/", $elt);
}
?>
</body>
</html>
|