Project

General

Profile

Download (32.7 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['displayname']) {
475
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
476
				echo $field['displayname'];
477
				echo ":</td>\n";
478
			} else if(!$field['dontdisplayname']) {
479
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
480
				echo fixup_string($field['name']);
481
				echo ":</td>\n";
482
			}
483
			if(!$field['dontcombinecells'])
484
				echo "<td class=\"vtable\">";
485
			echo "<input class='formfld pwd' id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password' ";
486
			if($field['size'])
487
				echo " size='" . $field['size'] . "' ";
488
			echo ">\n";
489

    
490
			if($field['description'] <> "") {
491
				echo "<br /> " . $field['description'];
492
		    	}
493

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

    
528
			if($field['description'] <> "") {
529
				echo "<br /> " . $field['description'];
530
		    	}
531

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

    
568
			if($field['description'] <> "") {
569
				echo "<br /> " . $field['description'];
570
		    	}
571

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

    
608
			if($field['description'] <> "") {
609
				echo $field['description'];
610
		    	}
611

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

    
633
			if($field['description'] <> "") {
634
				echo "<br /> " . $field['description'];
635
		    	}
636

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

    
643
			if($field['description'] <> "") {
644
				echo "<br /> " . $field['description'];
645
		    	}
646

    
647
			break;
648
		    case "listtopic":
649
			echo "<td>&nbsp;</td></tr>";
650
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br ></td>\n";
651

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

    
674
			if($field['description'] <> "") {
675
				echo "<br /> " . $field['description'];
676
		    	}
677

    
678
			break;
679
		    case "timezone_select":
680
			exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
681
			$timezonelist = array_filter($timezonelist, 'is_timezone');
682
			sort($timezonelist);
683

    
684
			/* kill carriage returns */
685
			for($x=0; $x<count($timezonelist); $x++)
686
				$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
687

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

    
709
			if($field['description'] <> "") {
710
				echo "<br /> " . $field['description'];
711
		    	}
712

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

    
734
			if($field['description'] <> "") {
735
				echo $field['description'];
736
		    	}
737

    
738
			break;
739
		    }
740

    
741
		    if($field['typehint'] <> "") {
742
			echo $field['typehint'];
743
		    }
744
		    if($field['warning'] <> "") {
745
			echo "<br ><b><font color=\"red\">" . $field['warning'] . "</font></b>";
746
		    }
747

    
748
		    if(!$field['combinefieldsbegin']) {
749
		    	if (!$field['dontcombinecells'])
750
		    		echo "</td>";
751

    
752
			 echo "</tr>\n";
753
		    }
754

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

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

    
790
	var customarray=new Array(<?php echo $aliases; ?>);
791

    
792
	window.onload = function () {
793

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

    
802
	}
803

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

    
815
<?php
816

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

    
865

    
866
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
867
	// handle after form display event.
868
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
869
}
870

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

    
878
/*
879
 *  HELPER FUNCTIONS
880
 */
881

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

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

    
925
function is_timezone($elt) {
926
	return !preg_match("/\/$/", $elt);
927
}
928

    
929
?>
930

    
931
</body>
932
</html>
933

    
(215-215/216)