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(sprintf(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
<?php
177

    
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
<?php
325
	if ($savemsg)
326
		print_info_box($savemsg);
327
	if ($_GET['message'] != "")
328
		print_info_box(htmlspecialchars($_GET['message']));
329
	if ($_POST['message'] != "")
330
		print_info_box(htmlspecialchars($_POST['message']));
331
?>
332
<table bgcolor="#ffffff" width="95%" border="0" cellspacing="0" cellpadding="2">
333
    <!-- wizard goes here -->
334
    <tr><td>&nbsp;</td></tr>
335
 <tr>
336
	<td class="tabcont">
337
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
338

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
741
			break;
742
		    }
743

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

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

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

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

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

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

    
795
	window.onload = function () {
796

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

    
805
	}
806

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

    
818
<?php
819

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

    
868

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

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

    
881
/*
882
 *  HELPER FUNCTIONS
883
 */
884

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

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

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

    
932
?>
933

    
934
</body>
935
</html>
936

    
(219-219/220)