Project

General

Profile

Download (32.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    wizard.php
5
    Copyright (C) 2004 Scott Ullrich
6
    Copyright (C) 2010 Ermal Lu?i
7
    All rights reserved.
8

    
9
    Redistribution and use in source and binary forms, with or without
10
    modification, are permitted provided that the following conditions are met:
11

    
12
    1. Redistributions of source code must retain the above copyright notice,
13
       this list of conditions and the following disclaimer.
14

    
15
    2. Redistributions in binary form must reproduce the above copyright
16
       notice, this list of conditions and the following disclaimer in the
17
       documentation and/or other materials provided with the distribution.
18

    
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29
*/
30

    
31
##|+PRIV
32
##|*IDENT=page-pfsensewizardsubsystem
33
##|*NAME=pfSense wizard subsystem page
34
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
35
##|*MATCH=wizard.php*
36
##|-PRIV
37

    
38

    
39
require("guiconfig.inc");
40
require("functions.inc");
41
require("filter.inc");
42
require("shaper.inc");
43
require("rrd.inc");
44

    
45
function gentitle_pkg($pgname) {
46
	global $config;
47
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
48
}
49

    
50
$stepid = htmlspecialchars($_GET['stepid']);
51
if (isset($_POST['stepid']))
52
    $stepid = htmlspecialchars($_POST['stepid']);
53
if (!$stepid)
54
	$stepid = "0";
55

    
56
$xml = htmlspecialchars($_GET['xml']);
57
if($_POST['xml'])
58
	$xml = htmlspecialchars($_POST['xml']);
59

    
60
if(empty($xml)) {
61
	$xml = "not_defined";
62
	print_info_box_np("ERROR:  Could not open " . $xml . ".");
63
	die;
64
} else {
65
	if (file_exists("{$g['www_path']}/wizards/{$xml}"))
66
		$pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/" . $xml, "pfsensewizard");
67
	else {
68
		print_info_box_np("ERROR:  Could not open " . $xml . ".");
69
		die;
70
	}
71
}
72

    
73
if (!is_array($pkg)) {
74
	print_info_box_np("ERROR: Could not parse {$g['www_path']}/wizards/{$xml} file.");
75
	die;
76
}
77

    
78
$title          = $pkg['step'][$stepid]['title'];
79
$description    = $pkg['step'][$stepid]['description'];
80
$totalsteps     = $pkg['totalsteps'];
81

    
82
if ($pkg['includefile'])
83
        require_once($pkg['includefile']);
84

    
85
if ($pkg['step'][$stepid]['includefile'])
86
	require_once($pkg['step'][$stepid]['includefile']);
87

    
88
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
89
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
90
}
91

    
92
if ($_POST) {
93
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
94
        if(!empty($field['bindstofield']) and $field['type'] <> "submit") {
95
		$fieldname = $field['name'];
96
		$fieldname = str_replace(" ", "", $fieldname);
97
		$fieldname = strtolower($fieldname);
98
		// update field with posted values.
99
                if($field['unsetfield'] <> "")
100
			$unset_fields = "yes";
101
		else
102
			$unset_fields = "";
103
		if($field['arraynum'] <> "")
104
			$arraynum = $field['arraynum'];
105
		else
106
			$arraynum = "";
107

    
108
		update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
109
        }
110

    
111
    }
112
    // run custom php code embedded in xml config.
113
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
114
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
115
    }
116
	write_config();
117
    $stepid++;
118
    if($stepid > $totalsteps)
119
	$stepid = $totalsteps;
120
}
121

    
122
$title          = $pkg['step'][$stepid]['title'];
123
$description    = $pkg['step'][$stepid]['description'];
124

    
125
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
126
	global $config;
127
	$field_split = split("->",$field);
128
	foreach ($field_split as $f)
129
		$field_conv .= "['" . $f . "']";
130
	if($field_conv == "")
131
		return;
132
	if(($field_type == "checkbox" and $updatetext <> "on") || $updatetext == "") {
133
		/*
134
		    item is a checkbox, it should have the value "on"
135
		    if it was checked
136
                */
137
		$text = "unset(\$config" . $field_conv . ");";
138
		eval($text);
139
		return;
140
	}
141

    
142
	if($field_type == "interfaces_selection") {
143
		$text = "unset(\$config" . $field_conv . ");";
144
		eval($text);
145
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
146
		eval($text);
147
		return;
148
	}
149

    
150
	if($unset <> "") {
151
		$text = "unset(\$config" . $field_conv . ");";
152
		eval($text);
153
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
154
		eval($text);
155
	} else {
156
		if($arraynum <> "") {
157
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
158
		} else {
159
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
160
		}
161
		eval($text);
162
	}
163
}
164

    
165
// handle before form display event.
166
do {
167
	$oldstepid = $stepid;
168
	if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "")
169
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
170
} while ($oldstepid != $stepid);
171

    
172
$pgtitle = array($title);
173
include("head.inc");
174

    
175
?>
176
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
177

    
178
<?php
179
	if(file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) 
180
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/wizard.css\" media=\"all\" />\n";
181
	else 
182
		echo "<link rel=\"stylesheet\" href=\"/themes/{$g['theme']}/all.css\" media=\"all\" />";
183
?>
184

    
185
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
186
<script type="text/javascript">
187
<!--
188

    
189
function  FieldValidate(userinput,  regexp,  message)
190
{
191
	if(!userinput.match(regexp))
192
		alert(message);
193
}
194

    
195
function enablechange() {
196
<?php
197
        foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
198
                if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
199
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
200
                        if(isset($field['enablefields'])) {
201
                                $enablefields = explode(',', $field['enablefields']);
202
                                foreach($enablefields as $enablefield) {
203
                                        $enablefield = strtolower($enablefield);
204
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
205
                                }
206
                        }
207
                        if(isset($field['checkenablefields'])) {
208
                                $checkenablefields = explode(',', $field['checkenablefields']);
209
                                foreach($checkenablefields as $checkenablefield) {
210
                                        $checkenablefield = strtolower($checkenablefield);
211
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
212
                                }
213
                        }
214
                        print "\t" . '} else {' . "\n";
215
                        if(isset($field['enablefields'])) {
216
                                $enablefields = explode(',', $field['enablefields']);
217
                                foreach($enablefields as $enablefield) {
218
                                        $enablefield = strtolower($enablefield);
219
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
220
                                }
221
                        }
222
                        if(isset($field['checkenablefields'])) {
223
                                $checkenablefields = explode(',', $field['checkenablefields']);
224
                                foreach($checkenablefields as $checkenablefield) {
225
                                        $checkenablefield = strtolower($checkenablefield);
226
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
227
                                }
228
                        }
229
                        print "\t" . '}' . "\n";
230
                }
231
        }
232
?>
233
}
234

    
235
function disablechange() {
236
<?php
237
        foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
238
                if(isset($field['disablefields']) or isset($field['checkdisablefields'])) {
239
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
240
                        if(isset($field['disablefields'])) {
241
                                $enablefields = explode(',', $field['disablefields']);
242
                                foreach($enablefields as $enablefield) {
243
                                        $enablefield = strtolower($enablefield);
244
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
245
                                }
246
                        }
247
                        if(isset($field['checkdisablefields'])) {
248
                                $checkenablefields = explode(',', $field['checkdisablefields']);
249
                                foreach($checkenablefields as $checkenablefield) {
250
                                        $checkenablefield = strtolower($checkenablefield);
251
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
252
                                }
253
                        }
254
                        print "\t" . '} else {' . "\n";
255
                        if(isset($field['disablefields'])) {
256
                                $enablefields = explode(',', $field['disablefields']);
257
                                foreach($enablefields as $enablefield) {
258
                                        $enablefield = strtolower($enablefield);
259
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
260
                                }
261
                        }
262
                        if(isset($field['checkdisablefields'])) {
263
                                $checkenablefields = explode(',', $field['checkdisablefields']);
264
                                foreach($checkenablefields as $checkenablefield) {
265
                                        $checkenablefield = strtolower($checkenablefield);
266
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
267
                                }
268
                        }
269
                        print "\t" . '}' . "\n";
270
                }
271
        }
272
?>
273
}
274

    
275
function showchange() {
276
<?php
277
        foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
278
                if(isset($field['showfields'])) {
279
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
280
                        if(isset($field['showfields'])) {
281
                                $showfields = explode(',', $field['showfields']);
282
                                foreach($showfields as $showfield) {
283
                                        $showfield = strtolower($showfield);
284
                                        //print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
285
					print "\t\t \$('". $showfield . "').hide();";
286
                                }
287
                        }
288
                        print "\t" . '} else {' . "\n";
289
                        if(isset($field['showfields'])) {
290
                                $showfields = explode(',', $field['showfields']);
291
                                foreach($showfields as $showfield) {
292
                                        $showfield = strtolower($showfield);
293
                                        #print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
294
					print "\t\t \$('". $showfield . "').show();";
295
                                }
296
                        }
297
                        print "\t" . '}' . "\n";
298
                }
299
	}
300
?>
301
}
302
//-->
303
</script>
304
<?php } ?>
305

    
306
<form action="wizard.php" method="post" name="iform" id="iform">
307
<input type="hidden" name="xml" value="<?= $xml ?>">
308
<input type="hidden" name="stepid" value="<?= $stepid ?>">
309

    
310
<center>
311

    
312
&nbsp;<br>
313

    
314
<?php
315
	if($title == "Reload in progress") {
316
		$ip = fixup_string("\$myurl");
317
	} else {
318
		$ip = "/";
319
	}
320
	echo "<a href='$ip'>";
321
?>
322
<img border="0" src="./themes/<?= $g['theme']; ?>/images/logo.gif"></a>
323
<p>
324
<div style="width:800px;background-color:#ffffff" id="roundme">
325
<table bgcolor="#ffffff" width="95%" border="0" cellspacing="0" cellpadding="2">
326
    <!-- wizard goes here -->
327
    <tr><td>&nbsp;</td></tr>
328
    <tr><td colspan='2'>
329
<?php
330
	if ($savemsg)
331
		print_info_box($savemsg);
332
	if ($_GET['message'] != "")
333
		print_info_box(htmlspecialchars($_GET['message']));
334
	if ($_POST['message'] != "")
335
		print_info_box(htmlspecialchars($_POST['message']));
336
?></td></tr>
337
 <tr>
338
	<td class="tabcont">
339
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
340

    
341
    <tr><td colspan='2'><center><font size="2"><b><?= fixup_string($description) ?></b></font></center></td></tr><tr><td>&nbsp;</td></tr>
342
    <?php
343
	if(!$pkg['step'][$stepid]['disableheader'])
344
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
345
    ?>
346

    
347
    <?php
348
	$inputaliases = array();
349
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
350
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
351

    
352
		    $value = $field['value'];
353
		    $name  = $field['name'];
354

    
355
		    $name = ereg_replace(" ", "", $name);
356
		    $name = strtolower($name);
357

    
358
		    if($field['bindstofield'] <> "") {
359
				$arraynum = "";
360
				$field_conv = "";
361
				$field_split = split("->", $field['bindstofield']);
362
				// arraynum is used in cases where there is an array of the same field
363
				// name such as dnsserver (2 of them)
364
				if($field['arraynum'] <> "")
365
					$arraynum = "[" . $field['arraynum'] . "]";
366
				foreach ($field_split as $f)
367
					$field_conv .= "['" . $f . "']";
368
				$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
369
				eval($toeval);
370
		    }
371

    
372
		    if(!$field['combinefieldsend'])
373
			echo "<tr>";
374

    
375
		    switch ($field['type']) {
376
		    case "input":
377
			if ($field['displayname']) {
378
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
379
				echo $field['displayname'];
380
				echo ":</td>\n";
381
			} else if(!$field['dontdisplayname']) {
382
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
383
				echo fixup_string($field['name']);
384
				echo ":</td>\n";
385
			}
386
			if(!$field['dontcombinecells'])
387
				echo "<td class=\"vtable\">\n";
388

    
389
			echo "<input class='formfld unknown' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
390
			if($field['size'])
391
				echo " size='" . $field['size'] . "' ";
392
			if($field['validate'])
393
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
394
			echo ">\n";
395

    
396
			if($field['description'] <> "") {
397
				echo "<br /> " . $field['description'];
398
		    	}
399
			break;
400
		    case "text":
401
			echo "<td colspan=\"2\" align=\"center\" class=\"vncell\">\n";
402
			if($field['description'] <> "") {
403
                                echo "<center><br /> " . $field['description'] . "</center>";
404
                        }
405
			break;
406
		    case "inputalias":
407
			if ($field['displayname']) {
408
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
409
                                echo $field['displayname'];
410
                                echo ":</td>\n";
411
			} else if(!$field['dontdisplayname']) {
412
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
413
				echo fixup_string($field['name']);
414
				echo ":</td>\n";
415
			}
416
			if(!$field['dontcombinecells'])
417
				echo "<td class=\"vtable\">\n";
418

    
419
			$inputaliases[] = $name;
420
			echo "<input class='formfldalias' autocomplete='off' class='formfldalias' id='" . $name . "' name='" . $name . "' value='" . $value . "'";
421
			if($field['size'])
422
				echo " size='" . $field['size'] . "' ";
423
			if($field['validate'])
424
				echo " onChange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
425
			echo ">\n";
426

    
427
			if($field['description'] <> "") {
428
				echo "<br /> " . $field['description'];
429
		    	}
430
			break;
431
		    case "interfaces_selection":
432
			$size = "";
433
			$multiple = "";
434
			$name = strtolower($name);
435
			echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
436
			echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
437
			echo "</td>";
438
			echo "<td class=\"vtable\">\n";
439
			if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
440
			if($field['multiple'] <> "" and $field['multiple'] <> "0") {
441
			  $multiple = "multiple=\"multiple\"";
442
			  $name .= "[]";
443
			}
444
			echo "<select class='formselect' id='{$name}' name='{$name}' {$size} {$multiple}>\n";
445
			if($field['add_to_interfaces_selection'] <> "") {
446
				$SELECTED = "";
447
				if($field['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
448
				echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
449
			}
450
			$interfaces = get_configured_interface_with_descr();
451
			foreach ($interfaces as $ifname => $iface) {
452
			  $SELECTED = "";
453
			  if ($value == $ifname) $SELECTED = " SELECTED";
454
			  $to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $iface . "</option>\n";
455
			  $to_echo .= "<!-- {$value} -->";
456
			  $canecho = 0;
457
			  if($field['interface_filter'] <> "") {
458
				if(stristr($ifname, $field['interface_filter']) == true)
459
					$canecho = 1;
460
			  } else {
461
				$canecho = 1;
462
			  }
463
			  if($canecho == 1)
464
				echo $to_echo;
465
			}
466
				echo "</select>\n";
467

    
468
			if($field['description'] <> "") {
469
				echo "<br /> " . $field['description'];
470
		    	}
471

    
472
			break;
473
		    case "password":
474
			if(!$field['dontdisplayname']) {
475
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
476
				echo fixup_string($field['name']);
477
				echo ":</td>\n";
478
			}
479
			if(!$field['dontcombinecells'])
480
				echo "<td class=\"vtable\">";
481
			echo "<input class='formfld password' id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password' ";
482
			if($field['size'])
483
				echo " size='" . $field['size'] . "' ";
484
			echo ">\n";
485

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

    
490
			break;
491
		    case "certca_selection":
492
                        $size = "";
493
                        $multiple = "";
494
                        $name = strtolower($name);
495
                        echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
496
                        echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
497
                        echo "</td>";
498
                        echo "<td class=\"vtable\">\n";
499
                        if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
500
                        echo "<select id='{$name}' name='{$name}' {$size}>\n";
501
                        if($field['add_to_certca_selection'] <> "") {
502
                                $SELECTED = "";
503
                                if($field['add_to_certca_selection'] == $value) $SELECTED = " SELECTED";
504
                                echo "<option value='" . $field['add_to_certca_selection'] . "'" . $SELECTED . ">" . $field['add_to_certca_selection'] . "</option>\n";
505
                        }
506
			foreach($config['system']['ca'] as $ca) {
507
				$name = htmlspecialchars($ca['name']);
508
                          $SELECTED = "";
509
                          if ($value == $name) $SELECTED = " SELECTED";
510
                          $to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
511
                          $to_echo .= "<!-- {$value} -->";
512
                          $canecho = 0;
513
                          if($field['certca_filter'] <> "") {
514
                                if(stristr($name, $field['certca_filter']) == true)
515
                                        $canecho = 1;
516
                          } else {
517
                                $canecho = 1;
518
                          }
519
                          if($canecho == 1)
520
                                echo $to_echo;
521
                        }
522
                                echo "</select>\n";
523

    
524
			if($field['description'] <> "") {
525
				echo "<br /> " . $field['description'];
526
		    	}
527

    
528
			break;
529
		    case "cert_selection":
530
                        $size = "";
531
                        $multiple = "";
532
                        $name = strtolower($name);
533
                        echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
534
                        echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
535
                        echo "</td>";
536
                        echo "<td class=\"vtable\">\n";
537
                        if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
538
                        echo "<select id='{$name}' name='{$name}' {$size}>\n";
539
                        if($field['add_to_cert_selection'] <> "") {
540
                                $SELECTED = "";
541
                                if($field['add_to_cert_selection'] == $value) $SELECTED = " SELECTED";
542
                                echo "<option value='" . $field['add_to_cert_selection'] . "'" . $SELECTED . ">" . $field['add_to_cert_selection'] . "</option>\n";
543
                        }
544
                        foreach($config['system']['cert'] as $ca) {
545
				if (stristr($ca['name'], "webconf"))
546
					continue;
547
                                $name = htmlspecialchars($ca['name']);
548
                          $SELECTED = "";
549
                          if ($value == $name) $SELECTED = " SELECTED";
550
                          $to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
551
                          $to_echo .= "<!-- {$value} -->";
552
                          $canecho = 0;
553
                          if($field['cert_filter'] <> "") {
554
                                if(stristr($name, $field['cert_filter']) == true)
555
                                        $canecho = 1;
556
                          } else {
557
                                $canecho = 1;
558
                          }
559
                          if($canecho == 1)
560
                                echo $to_echo;
561
                        }
562
                                echo "</select>\n";
563

    
564
			if($field['description'] <> "") {
565
				echo "<br /> " . $field['description'];
566
		    	}
567

    
568
			break;
569
		    case "select":
570
			if ($field['displayname']) {
571
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
572
                                echo $field['displayname'];
573
                                echo ":</td>\n";
574
			} else if(!$field['dontdisplayname']) {
575
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
576
				echo fixup_string($field['name']);
577
				echo ":</td>\n";
578
			}
579
			if($field['size']) $size = " size='" . $field['size'] . "' ";
580
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
581
			if(!$field['dontcombinecells'])
582
				echo "<td class=\"vtable\">\n";
583
			$onchange = "";
584
			foreach ($field['options']['option'] as $opt) {
585
				if($opt['enablefields'] <> "") {
586
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
587
				}
588
			}
589
			echo "<select class='formselect' " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
590
			foreach ($field['options']['option'] as $opt) {
591
				$selected = "";
592
				if($value == $opt['value'])
593
					$selected = " SELECTED";
594
				echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">";
595
				if ($opt['displayname'])
596
					echo $opt['displayname'];
597
				else
598
					echo $opt['name'];
599
				echo "</option>\n";
600
			}
601
			echo "</select>\n";
602
                        echo "<!-- {$value} -->\n";
603

    
604
			if($field['description'] <> "") {
605
				echo $field['description'];
606
		    	}
607

    
608
			break;
609
		    case "textarea":
610
			if ($field['displayname']) {
611
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
612
                                echo $field['displayname'];
613
                                echo ":</td>\n";
614
			} else if(!$field['dontdisplayname']) {
615
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
616
				echo fixup_string($field['name']);
617
				echo ":</td>";
618
			}
619
			if(!$field['dontcombinecells'])
620
				echo "<td class=\"vtable\">";
621
			echo "<textarea class='formpre' id='" . $name . "' name='" . $name . "'";
622
			if ($field['rows'])
623
				echo " rows='" . $field['rows'] . "' ";
624
			if ($field['cols'])
625
				echo " cols='" . $field['cols'] . "' ";
626
			echo ">" . $value . "</textarea>\n";
627
				
628

    
629
			if($field['description'] <> "") {
630
				echo "<br /> " . $field['description'];
631
		    	}
632

    
633
			break;
634
		    case "submit":
635
			echo "<td>&nbsp;<br></td></tr>";
636
			echo "<tr><td colspan='2'><center>";
637
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
638

    
639
			if($field['description'] <> "") {
640
				echo "<br /> " . $field['description'];
641
		    	}
642

    
643
			break;
644
		    case "listtopic":
645
			echo "<td>&nbsp;</td></tr>";
646
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br ></td>\n";
647

    
648
			break;
649
		    case "subnet_select":
650
			if ($field['displayname']) {
651
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
652
                                echo $field['displayname'];
653
                                echo ":</td>\n";
654
			} else if(!$field['dontdisplayname']) {
655
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
656
				echo fixup_string($field['name']);
657
				echo ":</td>";
658
			}
659
			if(!$field['dontcombinecells'])
660
				echo "<td class=\"vtable\">";
661
			echo "<select class='formselect' name='{$name}'>\n";
662
			for($x=1; $x<33; $x++) {
663
				$CHECKED = "";
664
				if($value == $x) $CHECKED = " SELECTED";
665
				if($x <> 31)
666
					echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
667
			}
668
			echo "</select>\n";
669

    
670
			if($field['description'] <> "") {
671
				echo "<br /> " . $field['description'];
672
		    	}
673

    
674
			break;
675
		    case "timezone_select":
676
			exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
677
			$timezonelist = array_filter($timezonelist, 'is_timezone');
678
			sort($timezonelist);
679

    
680
			/* kill carriage returns */
681
			for($x=0; $x<count($timezonelist); $x++)
682
				$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
683

    
684
			if ($field['displayname']) {
685
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
686
                                echo $field['displayname'];
687
                                echo ":</td>\n";
688
			} else if(!$field['dontdisplayname']) {
689
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
690
				echo fixup_string($field['name']);
691
				echo ":</td>";
692
			}
693
			if(!$field['dontcombinecells'])
694
				echo "<td class=\"vtable\">";
695
			echo "<select class='formselect' name='{$name}'>\n";
696
			foreach ($timezonelist as $tz) {
697
				$SELECTED = "";
698
				if ($value == $tz) $SELECTED = " SELECTED";
699
				echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
700
				echo htmlspecialchars($tz);
701
				echo "</option>\n";
702
			}
703
			echo "</select>\n";
704

    
705
			if($field['description'] <> "") {
706
				echo "<br /> " . $field['description'];
707
		    	}
708

    
709
			break;
710
		    case "checkbox":
711
			if ($field['displayname']) {
712
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
713
                                echo $field['displayname'];
714
                                echo ":</td>\n";
715
			} else if(!$field['dontdisplayname']) {
716
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
717
				echo $field['name'];
718
				echo ":</td>";
719
			}
720
			$checked = "";
721
			if($value <> "")
722
				$checked = " CHECKED";
723
			echo "<td class=\"vtable\"><input value=\"on\" type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
724
			if(isset($field['enablefields']) or isset($field['checkenablefields']))
725
				echo " onClick=\"enablechange()\"";
726
			else if(isset($field['disablefields']) or isset($field['checkdisablefields']))
727
				echo " onClick=\"disablechange()\"";
728
			echo ">\n";
729

    
730
			if($field['description'] <> "") {
731
				echo $field['description'];
732
		    	}
733

    
734
			break;
735
		    }
736

    
737
		    if($field['typehint'] <> "") {
738
			echo $field['typehint'];
739
		    }
740
		    if($field['warning'] <> "") {
741
			echo "<br ><b><font color=\"red\">" . $field['warning'] . "</font></b>";
742
		    }
743

    
744
		    if(!$field['combinefieldsbegin']) {
745
		    	if (!$field['dontcombinecells'])
746
		    		echo "</td>";
747

    
748
			 echo "</tr>\n";
749
		    }
750

    
751
		}
752
	}
753
    ?>
754
	</table>
755
	</td></tr>
756
</table>
757
<br>&nbsp;
758
</div>
759
</form>
760
<script type="text/javascript">
761
<!--
762
	if (typeof ext_change != 'undefined') {
763
		ext_change();
764
	}
765
	if (typeof proto_change != 'undefined') {
766
		ext_change();
767
	}
768
	if (typeof proto_change != 'undefined') {
769
		proto_change();
770
	}
771

    
772
<?php
773
	$isfirst = 0;
774
	$aliases = "";
775
	$addrisfirst = 0;
776
	$aliasesaddr = "";
777
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
778
		foreach($config['aliases']['alias'] as $alias_name) {
779
				if($isfirst == 1)
780
					$aliases .= ",";
781
				$aliases .= "'" . $alias_name['name'] . "'";
782
				$isfirst = 1;
783
		}
784
?>
785

    
786
	var customarray=new Array(<?php echo $aliases; ?>);
787

    
788
	window.onload = function () {
789

    
790
		<?php
791
			$counter=0;
792
			foreach($inputaliases as $alias) {
793
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(customarray));\n";
794
				$counter++;
795
			}
796
		?>
797

    
798
	}
799

    
800
//-->
801
</script>
802
<script type="text/javascript">
803
NiftyCheck();
804
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
805
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
806
enablechange();
807
disablechange();
808
showchange();
809
</script>
810

    
811
<?php
812

    
813
$fieldnames_array = Array();
814
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
815
	// create a fieldname loop that can be used with javascript
816
	// hide and enable features.
817
	echo "\n<script type=\"text/javascript\">\n";
818
	echo "function disableall() {\n";
819
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
820
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
821
			if(!$field['donotdisable'] <> "") {
822
				array_push($fieldnames_array, $field['name']);
823
				$fieldname = ereg_replace(" ", "", $field['name']);
824
				$fieldname = strtolower($fieldname);
825
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
826
			}
827
		}
828
	}
829
	echo "}\ndisableall();\n";
830
	echo "function enableitems(selectedindex) {\n";
831
	echo "disableall();\n";
832
	$idcounter = 0;
833
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
834
		echo "\tswitch(selectedindex) {\n";
835
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
836
			if($field['options']['option'] <> "") {
837
				foreach ($field['options']['option'] as $opt) {
838
					if($opt['enablefields'] <> "") {
839
						echo "\t\tcase " . $idcounter . ":\n";
840
						$enablefields_split = split(",", $opt['enablefields']);
841
						foreach ($enablefields_split as $efs) {
842
							$fieldname = ereg_replace(" ", "", $efs);
843
							$fieldname = strtolower($fieldname);
844
							if($fieldname <> "") {
845
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
846
								echo $onchange;
847
							}
848
						}
849
						echo "\t\t\tbreak;\n";
850
					}
851
					$idcounter = $idcounter + 1;
852
				}
853
			}
854
		}
855
		echo "\t}\n";
856
	}
857
	echo "}\n";
858
	echo "</script>\n\n";
859
}
860

    
861

    
862
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
863
	// handle after form display event.
864
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
865
}
866

    
867
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
868
	// handle after form display event.
869
        echo "\n<script type=\"text/javascript\">\n";
870
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
871
	echo "</script>\n\n";
872
}
873

    
874
/*
875
 *  HELPER FUNCTIONS
876
 */
877

    
878
function fixup_string($string) {
879
	global $config, $myurl;
880
	$newstring = $string;
881
	// fixup #1: $myurl -> http[s]://ip_address:port/
882
	switch($config['system']['webgui']['protocol']) {
883
		case "http":
884
			$proto = "http";
885
			break;
886
		case "https":
887
			$proto = "https";
888
			break;
889
		default:
890
			$proto = "http";
891
			break;
892
	}
893
	$port = $config['system']['webgui']['port'];
894
	if($port != "") {
895
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
896
			$urlport = ":" . $port;
897
		} elseif ($port != "80" and $port != "443") {
898
			$urlport = ":" . $port;
899
		} else {
900
			$urlport = "";
901
		}
902
	}
903
	$myurl = $proto . "://" . $_SERVER['HTTP_HOST'] . $urlport . "/";
904

    
905
	if (strstr($newstring, "\$myurl"))
906
		$newstring = str_replace("\$myurl", $myurl, $newstring);
907
	// fixup #2: $wanip
908
	if (strstr($newstring, "\$wanip")) {
909
		$curwanip = get_interface_ip();
910
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
911
	}
912
	// fixup #3: $lanip
913
	if (strstr($newstring, "\$lanip")) {
914
		$lanip = get_interface_ip("lan");
915
		$newstring = str_replace("\$lanip", $lanip, $newstring);
916
	}
917
	// fixup #4: fix'r'up here.
918
	return $newstring;
919
}
920

    
921
function is_timezone($elt) {
922
	return !preg_match("/\/$/", $elt);
923
}
924

    
925
?>
926

    
927
</body>
928
</html>
929

    
(217-217/218)