Project

General

Profile

Download (33.1 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("globals.inc");
40
require("guiconfig.inc");
41
require("functions.inc");
42
require("filter.inc");
43
require("shaper.inc");
44
require("rrd.inc");
45

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

    
51
global $g;
52

    
53
$stepid = htmlspecialchars($_GET['stepid']);
54
if (isset($_POST['stepid']))
55
    $stepid = htmlspecialchars($_POST['stepid']);
56
if (!$stepid)
57
	$stepid = "0";
58

    
59
$xml = htmlspecialchars($_GET['xml']);
60
if($_POST['xml'])
61
	$xml = htmlspecialchars($_POST['xml']);
62

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

    
76
if (!is_array($pkg)) {
77
	print_info_box_np(printf(gettext("ERROR: Could not parse %s/wizards/%s file."),$g['www_path'],$xml));
78
	die;
79
}
80

    
81
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
82
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
83
$totalsteps  = $pkg['totalsteps'];
84

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

    
88
if ($pkg['step'][$stepid]['includefile'])
89
	require_once($pkg['step'][$stepid]['includefile']);
90

    
91
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
92
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
93
}
94

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

    
111
		update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
112
        }
113

    
114
    }
115
    // run custom php code embedded in xml config.
116
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
117
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
118
    }
119
	write_config();
120
    $stepid++;
121
    if($stepid > $totalsteps)
122
	$stepid = $totalsteps;
123
}
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
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
162
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
163

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

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

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

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

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

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

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

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

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

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

    
309
<center>
310

    
311
&nbsp;<br>
312

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
713
			if($field['description'] <> "") {
714
				echo "<br /> " . $field['description'];
715
		    	}
716

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

    
738
			if($field['description'] <> "") {
739
				echo $field['description'];
740
		    	}
741

    
742
			break;
743
		    }
744

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

    
752
		    if(!$field['combinefieldsbegin']) {
753
		    	if (!$field['dontcombinecells'])
754
		    		echo "</td>";
755

    
756
			 echo "</tr>\n";
757
		    }
758

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

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

    
794
	var customarray=new Array(<?php echo $aliases; ?>);
795

    
796
	window.onload = function () {
797

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

    
806
	}
807

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

    
819
<?php
820

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

    
869

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

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

    
882
/*
883
 *  HELPER FUNCTIONS
884
 */
885

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

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

    
929
function is_timezone($elt) {
930
	return !preg_match("/\/$/", $elt);
931
}
932

    
933
?>
934

    
935
</body>
936
</html>
937

    
(221-221/222)