Project

General

Profile

Download (32.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    wizard.php
5
    Copyright (C) 2004 Scott Ullrich
6
    Copyright (C) 2010 Ermal Lu?i
7
    All rights reserved.
8

    
9
    Redistribution and use in source and binary forms, with or without
10
    modification, are permitted provided that the following conditions are met:
11

    
12
    1. Redistributions of source code must retain the above copyright notice,
13
       this list of conditions and the following disclaimer.
14

    
15
    2. Redistributions in binary form must reproduce the above copyright
16
       notice, this list of conditions and the following disclaimer in the
17
       documentation and/or other materials provided with the distribution.
18

    
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29
*/
30

    
31
##|+PRIV
32
##|*IDENT=page-pfsensewizardsubsystem
33
##|*NAME=pfSense wizard subsystem page
34
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
35
##|*MATCH=wizard.php*
36
##|-PRIV
37

    
38

    
39
require("guiconfig.inc");
40
require("functions.inc");
41
require("filter.inc");
42
require("shaper.inc");
43
require("rrd.inc");
44

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

    
50
$stepid = htmlspecialchars($_GET['stepid']);
51
if (isset($_POST['stepid']))
52
    $stepid = htmlspecialchars($_POST['stepid']);
53
if (!$stepid)
54
	$stepid = "0";
55

    
56
$xml = htmlspecialchars($_GET['xml']);
57
if($_POST['xml'])
58
	$xml = htmlspecialchars($_POST['xml']);
59

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

    
73
if (!is_array($pkg)) {
74
	print_info_box_np("ERROR: Could not parse {$g['www_path']}/wizards/{$xml} file.");
75
	die;
76
}
77

    
78
$title          = $pkg['step'][$stepid]['title'];
79
$description    = $pkg['step'][$stepid]['description'];
80
$totalsteps     = $pkg['totalsteps'];
81

    
82
if ($pkg['includefile'])
83
        require_once($pkg['includefile']);
84

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

    
88
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
89
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
90
}
91

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

    
108
		update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
109
        }
110

    
111
    }
112
    // run custom php code embedded in xml config.
113
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
114
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
115
    }
116
	write_config();
117
    $stepid++;
118
    if($stepid > $totalsteps)
119
	$stepid = $totalsteps;
120
}
121

    
122
$title          = $pkg['step'][$stepid]['title'];
123
$description    = $pkg['step'][$stepid]['description'];
124

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

    
142
	if($field_type == "interfaces_selection") {
143
		$text = "unset(\$config" . $field_conv . ");";
144
		eval($text);
145
		$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
146
		eval($text);
147
		return;
148
	}
149

    
150
	if($unset <> "") {
151
		$text = "unset(\$config" . $field_conv . ");";
152
		eval($text);
153
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
154
		eval($text);
155
	} else {
156
		if($arraynum <> "") {
157
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
158
		} else {
159
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
160
		}
161
		eval($text);
162
	}
163
}
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
691
			if ($field['displayname']) {
692
                                echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
693
                                echo $field['displayname'];
694
                                echo ":</td>\n";
695
			} else if(!$field['dontdisplayname']) {
696
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
697
				echo fixup_string($field['name']);
698
				echo ":</td>";
699
			}
700
			if(!$field['dontcombinecells'])
701
				echo "<td class=\"vtable\">";
702
			echo "<select class='formselect' name='{$name}'>\n";
703
			foreach ($timezonelist as $tz) {
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

    
(217-217/218)