Project

General

Profile

Download (33.3 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
		    case "interface_select":
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
			if($field['type'] == "interface_select")
453
				$interfaces = get_interface_list();
454
			else
455
				$interfaces = get_configured_interface_with_descr();
456
			foreach ($interfaces as $ifname => $iface) {
457
				if (is_array($iface)) {
458
						if ($iface['mac'])
459
							$iface = $ifname. " ({$iface['mac']})";	
460
					} else
461
						$iface = $ifname;
462
			  $SELECTED = "";
463
			  if ($value == $ifname) $SELECTED = " SELECTED";
464
			  $to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $iface . "</option>\n";
465
			  $to_echo .= "<!-- {$value} -->";
466
			  $canecho = 0;
467
			  if($field['interface_filter'] <> "") {
468
				if(stristr($ifname, $field['interface_filter']) == true)
469
					$canecho = 1;
470
			  } else {
471
				$canecho = 1;
472
			  }
473
			  if($canecho == 1)
474
				echo $to_echo;
475
			}
476
				echo "</select>\n";
477

    
478
			if($field['description'] <> "") {
479
				echo "<br /> " . $field['description'];
480
		    	}
481

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

    
500
			if($field['description'] <> "") {
501
				echo "<br /> " . $field['description'];
502
		    	}
503

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

    
538
			if($field['description'] <> "") {
539
				echo "<br /> " . $field['description'];
540
		    	}
541

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

    
578
			if($field['description'] <> "") {
579
				echo "<br /> " . $field['description'];
580
		    	}
581

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

    
618
			if($field['description'] <> "") {
619
				echo $field['description'];
620
		    	}
621

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

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

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

    
653
			if($field['description'] <> "") {
654
				echo "<br /> " . $field['description'];
655
		    	}
656

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

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

    
684
			if($field['description'] <> "") {
685
				echo "<br /> " . $field['description'];
686
		    	}
687

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

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

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

    
721
			if($field['description'] <> "") {
722
				echo "<br /> " . $field['description'];
723
		    	}
724

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

    
746
			if($field['description'] <> "") {
747
				echo $field['description'];
748
		    	}
749

    
750
			break;
751
		    }
752

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

    
760
		    if(!$field['combinefieldsbegin']) {
761
		    	if (!$field['dontcombinecells'])
762
		    		echo "</td>";
763

    
764
			 echo "</tr>\n";
765
		    }
766

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

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

    
802
	var customarray=new Array(<?php echo $aliases; ?>);
803

    
804
	window.onload = function () {
805

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

    
814
	}
815

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

    
827
<?php
828

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

    
877

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

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

    
890
/*
891
 *  HELPER FUNCTIONS
892
 */
893

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

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

    
937
function is_timezone($elt) {
938
	return !preg_match("/\/$/", $elt);
939
}
940

    
941
?>
942

    
943
</body>
944
</html>
945

    
(219-219/220)