Project

General

Profile

Download (33.4 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 && !$input_errors) {
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
	if (!$input_errors)
120
		write_config();
121
    $stepid++;
122
    if($stepid > $totalsteps)
123
	$stepid = $totalsteps;
124
}
125

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

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

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

    
162
$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
163
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
164

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

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

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

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

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

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

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

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

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

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

    
310
<center>
311

    
312
&nbsp;<br>
313

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

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

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

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

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

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

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

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

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

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

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

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

    
481
			if($field['description'] <> "") {
482
				echo "<br /> " . $field['description'];
483
		    	}
484

    
485
			break;
486
		    case "password":
487
			if ($field['displayname']) {
488
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
489
				echo $field['displayname'];
490
				echo ":</td>\n";
491
			} else if(!$field['dontdisplayname']) {
492
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
493
				echo fixup_string($field['name']);
494
				echo ":</td>\n";
495
			}
496
			if(!$field['dontcombinecells'])
497
				echo "<td class=\"vtable\">";
498
			echo "<input class='formfld pwd' id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password' ";
499
			if($field['size'])
500
				echo " size='" . $field['size'] . "' ";
501
			echo ">\n";
502

    
503
			if($field['description'] <> "") {
504
				echo "<br /> " . $field['description'];
505
		    	}
506

    
507
			break;
508
		    case "certca_selection":
509
                        $size = "";
510
                        $multiple = "";
511
                        $name = strtolower($name);
512
                        echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
513
                        echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
514
                        echo "</td>";
515
                        echo "<td class=\"vtable\">\n";
516
                        if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
517
                        echo "<select id='{$name}' name='{$name}' {$size}>\n";
518
                        if($field['add_to_certca_selection'] <> "") {
519
                                $SELECTED = "";
520
                                if($field['add_to_certca_selection'] == $value) $SELECTED = " SELECTED";
521
                                echo "<option value='" . $field['add_to_certca_selection'] . "'" . $SELECTED . ">" . $field['add_to_certca_selection'] . "</option>\n";
522
                        }
523
			foreach($config['ca'] as $ca) {
524
				$name = htmlspecialchars($ca['descr']);
525
                          $SELECTED = "";
526
                          if ($value == $name) $SELECTED = " SELECTED";
527
                          $to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
528
                          $to_echo .= "<!-- {$value} -->";
529
                          $canecho = 0;
530
                          if($field['certca_filter'] <> "") {
531
                                if(stristr($name, $field['certca_filter']) == true)
532
                                        $canecho = 1;
533
                          } else {
534
                                $canecho = 1;
535
                          }
536
                          if($canecho == 1)
537
                                echo $to_echo;
538
                        }
539
                                echo "</select>\n";
540

    
541
			if($field['description'] <> "") {
542
				echo "<br /> " . $field['description'];
543
		    	}
544

    
545
			break;
546
		    case "cert_selection":
547
                        $size = "";
548
                        $multiple = "";
549
                        $name = strtolower($name);
550
                        echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
551
                        echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
552
                        echo "</td>";
553
                        echo "<td class=\"vtable\">\n";
554
                        if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
555
                        echo "<select id='{$name}' name='{$name}' {$size}>\n";
556
                        if($field['add_to_cert_selection'] <> "") {
557
                                $SELECTED = "";
558
                                if($field['add_to_cert_selection'] == $value) $SELECTED = " SELECTED";
559
                                echo "<option value='" . $field['add_to_cert_selection'] . "'" . $SELECTED . ">" . $field['add_to_cert_selection'] . "</option>\n";
560
                        }
561
                        foreach($config['cert'] as $ca) {
562
				if (stristr($ca['descr'], "webconf"))
563
					continue;
564
                                $name = htmlspecialchars($ca['descr']);
565
                          $SELECTED = "";
566
                          if ($value == $name) $SELECTED = " SELECTED";
567
                          $to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
568
                          $to_echo .= "<!-- {$value} -->";
569
                          $canecho = 0;
570
                          if($field['cert_filter'] <> "") {
571
                                if(stristr($name, $field['cert_filter']) == true)
572
                                        $canecho = 1;
573
                          } else {
574
                                $canecho = 1;
575
                          }
576
                          if($canecho == 1)
577
                                echo $to_echo;
578
                        }
579
                                echo "</select>\n";
580

    
581
			if($field['description'] <> "") {
582
				echo "<br /> " . $field['description'];
583
		    	}
584

    
585
			break;
586
		    case "select":
587
			if ($field['displayname']) {
588
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
589
                                echo $field['displayname'];
590
                                echo ":</td>\n";
591
			} else if(!$field['dontdisplayname']) {
592
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
593
				echo fixup_string($field['name']);
594
				echo ":</td>\n";
595
			}
596
			if($field['size']) $size = " size='" . $field['size'] . "' ";
597
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
598
			if(!$field['dontcombinecells'])
599
				echo "<td class=\"vtable\">\n";
600
			$onchange = "";
601
			foreach ($field['options']['option'] as $opt) {
602
				if($opt['enablefields'] <> "") {
603
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
604
				}
605
			}
606
			echo "<select class='formselect' " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
607
			foreach ($field['options']['option'] as $opt) {
608
				$selected = "";
609
				if($value == $opt['value'])
610
					$selected = " SELECTED";
611
				echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">";
612
				if ($opt['displayname'])
613
					echo $opt['displayname'];
614
				else
615
					echo $opt['name'];
616
				echo "</option>\n";
617
			}
618
			echo "</select>\n";
619
                        echo "<!-- {$value} -->\n";
620

    
621
			if($field['description'] <> "") {
622
				echo $field['description'];
623
		    	}
624

    
625
			break;
626
		    case "textarea":
627
			if ($field['displayname']) {
628
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
629
                                echo $field['displayname'];
630
                                echo ":</td>\n";
631
			} else if(!$field['dontdisplayname']) {
632
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
633
				echo fixup_string($field['name']);
634
				echo ":</td>";
635
			}
636
			if(!$field['dontcombinecells'])
637
				echo "<td class=\"vtable\">";
638
			echo "<textarea class='formpre' id='" . $name . "' name='" . $name . "'";
639
			if ($field['rows'])
640
				echo " rows='" . $field['rows'] . "' ";
641
			if ($field['cols'])
642
				echo " cols='" . $field['cols'] . "' ";
643
			echo ">" . $value . "</textarea>\n";
644
				
645

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

    
650
			break;
651
		    case "submit":
652
			echo "<td>&nbsp;<br></td></tr>";
653
			echo "<tr><td colspan='2'><center>";
654
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
655

    
656
			if($field['description'] <> "") {
657
				echo "<br /> " . $field['description'];
658
		    	}
659

    
660
			break;
661
		    case "listtopic":
662
			echo "<td>&nbsp;</td></tr>";
663
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br ></td>\n";
664

    
665
			break;
666
		    case "subnet_select":
667
			if ($field['displayname']) {
668
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
669
                                echo $field['displayname'];
670
                                echo ":</td>\n";
671
			} else if(!$field['dontdisplayname']) {
672
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
673
				echo fixup_string($field['name']);
674
				echo ":</td>";
675
			}
676
			if(!$field['dontcombinecells'])
677
				echo "<td class=\"vtable\">";
678
			echo "<select class='formselect' name='{$name}'>\n";
679
			for($x=1; $x<33; $x++) {
680
				$CHECKED = "";
681
				if($value == $x) $CHECKED = " SELECTED";
682
				if($x <> 31)
683
					echo "<option value='{$x}' {$CHECKED}>{$x}</option>\n";
684
			}
685
			echo "</select>\n";
686

    
687
			if($field['description'] <> "") {
688
				echo "<br /> " . $field['description'];
689
		    	}
690

    
691
			break;
692
		    case "timezone_select":
693
			exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
694
			$timezonelist = array_filter($timezonelist, 'is_timezone');
695
			sort($timezonelist);
696

    
697
			/* kill carriage returns */
698
			for($x=0; $x<count($timezonelist); $x++)
699
				$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
700

    
701
			if ($field['displayname']) {
702
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
703
                                echo $field['displayname'];
704
                                echo ":</td>\n";
705
			} else if(!$field['dontdisplayname']) {
706
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
707
				echo fixup_string($field['name']);
708
				echo ":</td>";
709
			}
710
			if(!$field['dontcombinecells'])
711
				echo "<td class=\"vtable\">";
712
			echo "<select class='formselect' name='{$name}'>\n";
713
			foreach ($timezonelist as $tz) {
714
				if(strstr($tz, "GMT"))
715
					continue;
716
				$SELECTED = "";
717
				if ($value == $tz) $SELECTED = " SELECTED";
718
				echo "<option value='" . htmlspecialchars($tz) . "' {$SELECTED}>";
719
				echo htmlspecialchars($tz);
720
				echo "</option>\n";
721
			}
722
			echo "</select>\n";
723

    
724
			if($field['description'] <> "") {
725
				echo "<br /> " . $field['description'];
726
		    	}
727

    
728
			break;
729
		    case "checkbox":
730
			if ($field['displayname']) {
731
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
732
                                echo $field['displayname'];
733
                                echo ":</td>\n";
734
			} else if(!$field['dontdisplayname']) {
735
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
736
				echo $field['name'];
737
				echo ":</td>";
738
			}
739
			$checked = "";
740
			if($value <> "")
741
				$checked = " CHECKED";
742
			echo "<td class=\"vtable\"><input value=\"on\" type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
743
			if(isset($field['enablefields']) or isset($field['checkenablefields']))
744
				echo " onClick=\"enablechange()\"";
745
			else if(isset($field['disablefields']) or isset($field['checkdisablefields']))
746
				echo " onClick=\"disablechange()\"";
747
			echo ">\n";
748

    
749
			if($field['description'] <> "") {
750
				echo $field['description'];
751
		    	}
752

    
753
			break;
754
		    }
755

    
756
		    if($field['typehint'] <> "") {
757
			echo $field['typehint'];
758
		    }
759
		    if($field['warning'] <> "") {
760
			echo "<br ><b><font color=\"red\">" . $field['warning'] . "</font></b>";
761
		    }
762

    
763
		    if(!$field['combinefieldsbegin']) {
764
		    	if (!$field['dontcombinecells'])
765
		    		echo "</td>";
766

    
767
			 echo "</tr>\n";
768
		    }
769

    
770
		}
771
	}
772
    ?>
773
	</table>
774
	</td></tr>
775
</table>
776
<br>&nbsp;
777
</div>
778
</form>
779
<script type="text/javascript">
780
<!--
781
	if (typeof ext_change != 'undefined') {
782
		ext_change();
783
	}
784
	if (typeof proto_change != 'undefined') {
785
		ext_change();
786
	}
787
	if (typeof proto_change != 'undefined') {
788
		proto_change();
789
	}
790

    
791
<?php
792
	$isfirst = 0;
793
	$aliases = "";
794
	$addrisfirst = 0;
795
	$aliasesaddr = "";
796
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
797
		foreach($config['aliases']['alias'] as $alias_name) {
798
				if($isfirst == 1)
799
					$aliases .= ",";
800
				$aliases .= "'" . $alias_name['name'] . "'";
801
				$isfirst = 1;
802
		}
803
?>
804

    
805
	var customarray=new Array(<?php echo $aliases; ?>);
806

    
807
	window.onload = function () {
808

    
809
		<?php
810
			$counter=0;
811
			foreach($inputaliases as $alias) {
812
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(customarray));\n";
813
				$counter++;
814
			}
815
		?>
816

    
817
	}
818

    
819
//-->
820
</script>
821
<script type="text/javascript">
822
NiftyCheck();
823
var bgcolor = document.getElementsByTagName("body")[0].style.backgroundColor;
824
Rounded("div#roundme","all",bgcolor,"#FFFFFF","smooth");
825
enablechange();
826
disablechange();
827
showchange();
828
</script>
829

    
830
<?php
831

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

    
880

    
881
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
882
	// handle after form display event.
883
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
884
}
885

    
886
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
887
	// handle after form display event.
888
        echo "\n<script type=\"text/javascript\">\n";
889
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
890
	echo "</script>\n\n";
891
}
892

    
893
/*
894
 *  HELPER FUNCTIONS
895
 */
896

    
897
function fixup_string($string) {
898
	global $config, $myurl;
899
	$newstring = $string;
900
	// fixup #1: $myurl -> http[s]://ip_address:port/
901
	switch($config['system']['webgui']['protocol']) {
902
		case "http":
903
			$proto = "http";
904
			break;
905
		case "https":
906
			$proto = "https";
907
			break;
908
		default:
909
			$proto = "http";
910
			break;
911
	}
912
	$port = $config['system']['webgui']['port'];
913
	if($port != "") {
914
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
915
			$urlport = ":" . $port;
916
		} elseif ($port != "80" and $port != "443") {
917
			$urlport = ":" . $port;
918
		} else {
919
			$urlport = "";
920
		}
921
	}
922
	$myurl = $proto . "://" . $_SERVER['HTTP_HOST'] . $urlport . "/";
923

    
924
	if (strstr($newstring, "\$myurl"))
925
		$newstring = str_replace("\$myurl", $myurl, $newstring);
926
	// fixup #2: $wanip
927
	if (strstr($newstring, "\$wanip")) {
928
		$curwanip = get_interface_ip();
929
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
930
	}
931
	// fixup #3: $lanip
932
	if (strstr($newstring, "\$lanip")) {
933
		$lanip = get_interface_ip("lan");
934
		$newstring = str_replace("\$lanip", $lanip, $newstring);
935
	}
936
	// fixup #4: fix'r'up here.
937
	return $newstring;
938
}
939

    
940
function is_timezone($elt) {
941
	return !preg_match("/\/$/", $elt);
942
}
943

    
944
?>
945

    
946
</body>
947
</html>
(219-219/220)