Project

General

Profile

Download (32.9 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 ($arraynum <> "")
133
		$field_conv .= "[" . $arraynum . "]";
134
	if(($field_type == "checkbox" and $updatetext <> "on") || $updatetext == "") {
135
		/*
136
		 * item is a checkbox, it should have the value "on"
137
		 * if it was checked
138
                 */
139
		$var = "\$config{$field_conv}";
140
		$text = "if (isset({$var})) unset({$var});";
141
		eval($text);
142
		return;
143
	}
144

    
145
	if($field_type == "interfaces_selection") {
146
		$var = "\$config{$field_conv}";
147
		$text = "if (isset({$var})) unset({$var});";
148
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
149
		eval($text);
150
		return;
151
	}
152

    
153
	if($unset == "yes") {
154
		$text = "unset(\$config" . $field_conv . ");";
155
		eval($text);
156
	}
157
	$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
158
	eval($text);
159
}
160

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

    
168
$pgtitle = array($title);
169
include("head.inc");
170

    
171
?>
172
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
173

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

    
181
<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
182
<script type="text/javascript">
183
<!--
184

    
185
function  FieldValidate(userinput,  regexp,  message)
186
{
187
	if(!userinput.match(regexp))
188
		alert(message);
189
}
190

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

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

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

    
302
<form action="wizard.php" method="post" name="iform" id="iform">
303
<input type="hidden" name="xml" value="<?= $xml ?>">
304
<input type="hidden" name="stepid" value="<?= $stepid ?>">
305

    
306
<center>
307

    
308
&nbsp;<br>
309

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

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

    
343
    <?php
344
	$inputaliases = array();
345
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
346
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
347

    
348
		    $value = $field['value'];
349
		    $name  = $field['name'];
350

    
351
		    $name = ereg_replace(" ", "", $name);
352
		    $name = strtolower($name);
353

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
739
			break;
740
		    }
741

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

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

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

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

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

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

    
793
	window.onload = function () {
794

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

    
803
	}
804

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

    
816
<?php
817

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

    
866

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

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

    
879
/*
880
 *  HELPER FUNCTIONS
881
 */
882

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

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

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

    
930
?>
931

    
932
</body>
933
</html>
934

    
(220-220/221)