Project

General

Profile

Download (11.9 KB) Statistics
| Branch: | Tag: | Revision:
1 658292ef Scott Ullrich
#!/usr/local/bin/php
2
<?php
3
/*
4 57333fa0 Scott Ullrich
    wizard.php
5 658292ef Scott Ullrich
    Copyright (C) 2004 Scott Ullrich
6
    All rights reserved.
7
8
    Redistribution and use in source and binary forms, with or without
9
    modification, are permitted provided that the following conditions are met:
10
11
    1. Redistributions of source code must retain the above copyright notice,
12
       this list of conditions and the following disclaimer.
13
14
    2. Redistributions in binary form must reproduce the above copyright
15
       notice, this list of conditions and the following disclaimer in the
16
       documentation and/or other materials provided with the distribution.
17
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
require("guiconfig.inc");
31
require("xmlparse_pkg.inc");
32
33
function gentitle_pkg($pgname) {
34 2fbd6806 Scott Ullrich
	global $config;
35
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
36 658292ef Scott Ullrich
}
37
38
$stepid = $_GET['stepid'];
39
if (isset($_POST['stepid']))
40
    $stepid = $_POST['stepid'];
41 2fbd6806 Scott Ullrich
if (!$stepid) $stepid = "0";
42 658292ef Scott Ullrich
43
// XXX: Make this input safe.
44
$xml = $_GET['xml'];
45
if($_POST['xml']) $xml = $_POST['xml'];
46
47
if($xml == "") {
48
            $xml = "not_defined";
49
            print_info_box_np("ERROR:  Could not open " . $xml . ".");
50
            die;
51
} else {
52 2fbd6806 Scott Ullrich
            $pkg = parse_xml_config_pkg("/usr/local/www/wizards/" . $xml, "pfsensewizard");
53 658292ef Scott Ullrich
}
54
55
$title          = $pkg['step'][$stepid]['title'];
56
$description    = $pkg['step'][$stepid]['description'];
57 46985f19 Scott Ullrich
$totalsteps     = $pkg['totalsteps'];
58 658292ef Scott Ullrich
59 e1e7a425 Scott Ullrich
if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
60
		eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
61
}
62
63 658292ef Scott Ullrich
if ($_POST) {
64 e48fc17d Scott Ullrich
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
65
        if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
66
		$fieldname = $field['name'];
67
		$unset_fields = "";
68
		$fieldname = ereg_replace(" ", "", $fieldname);
69
		$fieldname = strtolower($fieldname);
70
		// update field with posted values.
71
                if($field['unsetfield'] <> "") $unset_fields = "yes";
72 46985f19 Scott Ullrich
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
73 e48fc17d Scott Ullrich
		if($field['bindstofield'])
74 46985f19 Scott Ullrich
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum);
75 658292ef Scott Ullrich
        }
76 3ed807e4 Scott Ullrich
77 2fbd6806 Scott Ullrich
    }
78 3ed807e4 Scott Ullrich
    // run custom php code embedded in xml config.
79
    if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
80
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
81
    }
82
	write_config();
83 e48fc17d Scott Ullrich
    $stepid++;
84 46985f19 Scott Ullrich
    if($stepid > $totalsteps) $stepid = $totalsteps;
85 658292ef Scott Ullrich
}
86
87 46985f19 Scott Ullrich
$title          = $pkg['step'][$stepid]['title'];
88
$description    = $pkg['step'][$stepid]['description'];
89
90
function update_config_field($field, $updatetext, $unset, $arraynum) {
91 e48fc17d Scott Ullrich
	global $config;
92
	$field_split = split("->",$field);
93
	foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
94
	if($field_conv == "") return;
95
	if($unset <> "") {
96
		$text = "unset(\$config" . $field_conv . ");";
97
		eval($text);
98 46985f19 Scott Ullrich
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
99 e48fc17d Scott Ullrich
		eval($text);
100
	} else {
101 46985f19 Scott Ullrich
		if($arraynum <> "") {
102
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
103
		} else {
104
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
105
		}
106 e48fc17d Scott Ullrich
		eval($text);
107
	}
108 658292ef Scott Ullrich
}
109
110 34b5c5a0 Scott Ullrich
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
111
	// handle before form display event.
112
        // good for modifying posted values, etc.
113
	eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
114
}
115
116 658292ef Scott Ullrich
?>
117
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
118
<html>
119
<head>
120
<title><?=gentitle_pkg($title);?></title>
121
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
122
<link href="gui.css" rel="stylesheet" type="text/css">
123
</head>
124
125
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
126
<form action="wizard.php" method="post">
127
<input type="hidden" name="xml" value="<?= $xml ?>">
128 e48fc17d Scott Ullrich
<input type="hidden" name="stepid" value="<?= $stepid ?>">
129 658292ef Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
130
131 e48fc17d Scott Ullrich
<center>
132
133
&nbsp;<br>
134
135 d51f86e0 Scott Ullrich
<a href="http://<?= getenv("HTTP_HOST") ?>"><img border="0" src="/logo.gif"></a>
136
<p>
137 e48fc17d Scott Ullrich
138 34b5c5a0 Scott Ullrich
<table width="600" cellspacing="0" cellpadding="3">
139
    <!-- wizard goes here -->
140
    <tr><td>&nbsp;</td></tr>
141 d51f86e0 Scott Ullrich
    <tr><td colspan='2'><center><b><?= fixup_string($description) ?></b></center></td></tr><tr><td>&nbsp;</td></tr>
142 34b5c5a0 Scott Ullrich
    <?php
143
	if(!$pkg['step'][$stepid]['disableheader'])
144 d51f86e0 Scott Ullrich
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . fixup_string($title) . "</td></tr>";
145 34b5c5a0 Scott Ullrich
    ?>
146
147
    <?php
148
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
149
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
150
151
		    $value = $field['value'];
152 2fbd6806 Scott Ullrich
		    $name  = $field['name'];
153 658292ef Scott Ullrich
154 2fbd6806 Scott Ullrich
		    $name = ereg_replace(" ", "", $name);
155
		    $name = strtolower($name);
156 658292ef Scott Ullrich
157 a8df0181 Scott Ullrich
		    if($field['bindstofield'] <> "") {
158 b1919dd0 Scott Ullrich
				$arraynum = "";
159
				$field_conv = "";
160
				$field_split = split("->", $field['bindstofield']);
161
				// arraynum is used in cases where there is an array of the same field
162
				// name such as dnsserver (2 of them)
163
				if($field['arraynum'] <> "") $arraynum = "[" . $field['arraynum'] . "]";
164
				foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
165
					$toeval = "\$value = \$config" . $field_conv . $arraynum . ";";
166
					eval($toeval);
167 f2ec2c48 Scott Ullrich
					if ($field['type'] == "checkbox") {
168 35fecd55 Scott Ullrich
						$toeval = "if(isset(\$config" . $field_conv . $arraynum . ")) \$value = \" CHECKED\";";
169 f2ec2c48 Scott Ullrich
						eval($toeval);
170
					}
171 a8df0181 Scott Ullrich
		    }
172
173 34b5c5a0 Scott Ullrich
		    if(!$field['combinefieldsend'])
174
			echo "<tr>";
175
176
		    if ($field['type'] == "input") {
177
			if(!$field['dontdisplayname']) {
178
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
179 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
180 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
181
			}
182
			if(!$field['dontcombinecells'])
183
				echo "<td class=\"vtable\">\n";
184
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'>\n";
185
		    } else if ($field['type'] == "password") {
186
			if(!$field['dontdisplayname']) {
187
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
188 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
189 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
190
			}
191
			if(!$field['dontcombinecells'])
192
				echo "<td class=\"vtable\">";
193
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
194
		    } else if ($field['type'] == "select") {
195
			if(!$field['dontdisplayname']) {
196
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
197 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
198 34b5c5a0 Scott Ullrich
				echo ":</td>\n";
199
			}
200
			// XXX: TODO: set $selected
201
			if($field['size']) $size = " size='" . $field['size'] . "' ";
202
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
203
			if(!$field['dontcombinecells'])
204
				echo "<td class=\"vtable\">\n";
205
			$onchange = "";
206
			foreach ($field['options']['option'] as $opt) {
207
				if($opt['enablefields'] <> "") {
208
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
209
				}
210
			}
211
			echo "<select " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
212
			foreach ($field['options']['option'] as $opt) {
213 46985f19 Scott Ullrich
				$selected = "";
214
				if($value == $opt['value']) $selected = " SELECTED";
215 34b5c5a0 Scott Ullrich
			    echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
216
			}
217
			echo "</select>\n";
218
		    } else if ($field['type'] == "textarea") {
219
			if(!$field['dontdisplayname']) {
220
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
221 d51f86e0 Scott Ullrich
				echo fixup_string($field['name']);
222 34b5c5a0 Scott Ullrich
				echo ":</td>";
223
			}
224
			if(!$field['dontcombinecells'])
225
				echo "<td class=\"vtable\">";
226
			echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
227
		    } else if ($field['type'] == "submit") {
228
			echo "<td>&nbsp;<br></td></tr>";
229 2fbd6806 Scott Ullrich
			echo "<tr><td colspan='2'><center>";
230
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
231 34b5c5a0 Scott Ullrich
		    } else if ($field['type'] == "listtopic") {
232
			echo "<td>&nbsp;</td><tr>";
233
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
234
		    } else if ($field['type'] == "checkbox") {
235
			if(!$field['dontdisplayname']) {
236
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
237
				echo $field['name'];
238
				echo ":</td>";
239
			}
240
			$checked = "";
241 f2ec2c48 Scott Ullrich
			if($value <> "") $checked = " CHECKED";
242 34b5c5a0 Scott Ullrich
			echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked . ">\n";
243
		    }
244
245
		    if($field['typehint'] <> "") {
246
			echo $field['typehint'];
247 2fbd6806 Scott Ullrich
		    }
248 34b5c5a0 Scott Ullrich
249 788ff7cb Scott Ullrich
		    if($field['description'] <> "") {
250
			echo "<br>" . $field['description'];
251 34b5c5a0 Scott Ullrich
			echo "</td>";
252 788ff7cb Scott Ullrich
		    }
253 34b5c5a0 Scott Ullrich
254
		    if(!$field['combinefieldsbegin'])
255
			 echo "</tr>\n";
256
		}
257
	}
258
    ?>
259 658292ef Scott Ullrich
</table>
260
261
</form>
262
</body>
263
</html>
264 34b5c5a0 Scott Ullrich
265
<?php
266
267
$fieldnames_array = Array();
268
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
269
	// create a fieldname loop that can be used with javascript
270
	// hide and enable features.
271
	echo "\n<script language=\"JavaScript\">\n";
272
	echo "function disableall() {\n";
273
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
274
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
275
			if(!$field['donotdisable'] <> "") {
276
				array_push($fieldnames_array, $field['name']);
277
				$fieldname = ereg_replace(" ", "", $field['name']);
278
				$fieldname = strtolower($fieldname);
279
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
280
			}
281
		}
282
	}
283
	echo "}\ndisableall();\n";
284
	echo "function enableitems(selectedindex) {\n";
285
	echo "disableall();\n";
286
	$idcounter = 0;
287
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
288
		echo "\tswitch(selectedindex) {\n";
289
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
290
			if($field['options']['option'] <> "") {
291
				foreach ($field['options']['option'] as $opt) {
292
					if($opt['enablefields'] <> "") {
293
						echo "\t\tcase " . $idcounter . ":\n";
294
						$enablefields_split = split(",", $opt['enablefields']);
295
						foreach ($enablefields_split as $efs) {
296
							$fieldname = ereg_replace(" ", "", $efs);
297
							$fieldname = strtolower($fieldname);
298
							if($fieldname <> "") {
299
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
300
								echo $onchange;
301
							}
302
						}
303
						echo "\t\t\tbreak;\n";
304
					}
305
					$idcounter = $idcounter + 1;
306
				}
307
			}
308
		}
309
		echo "\t}\n";
310
	}
311
	echo "}\n";
312
	echo "disableall();\n";
313
	echo "</script>\n\n";
314
}
315
316
317
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
318
	// handle after form display event.
319
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
320
}
321
322
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
323
	// handle after form display event.
324
        echo "\n<script language=\"JavaScript\">\n";
325
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
326
	echo "</script>\n\n";
327
}
328
329 d51f86e0 Scott Ullrich
/*
330
 *  HELPER FUNCTIONS
331
 */
332
333
function fixup_string($string) {
334 d2133701 Scott Ullrich
	global $config;
335 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
336
	$https = "";
337
	$port = "";
338
	$urlport = "";
339
	$port = $config['system']['webguiport'];
340
	if($port <> "443" and $port <> "80") $urlport = ":" . $port;
341
	if($config['system']['webguiproto'] == "https") $https = "s";
342
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlportport;
343
	$newstring = str_replace("\$myurl", $myurl, $string);
344 d2133701 Scott Ullrich
	$string = $newstring;
345
	// fixup #2: $wanip
346
	$curwanip = get_current_wan_address();
347
	$newstring = str_replace("\$wanip", $curwanip, $string);
348
	$string = $newstring;
349
	// fixup #3: $lanip
350
	$lancfg = $config['interfaces']['lan'];
351
	$lanip = $lancfg['ipaddr'];
352
	$newstring = str_replace("\$lanip", $lanip, $string);
353
	$string = $newstring;
354
	// fixup #4: fix'r'up here.
355 d51f86e0 Scott Ullrich
	return $newstring;
356
}
357
358 34b5c5a0 Scott Ullrich
?>