Project

General

Profile

Download (10.6 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    wizard.php
5
    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
	global $config;
35
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
36
}
37

    
38
$stepid = $_GET['stepid'];
39
if (isset($_POST['stepid']))
40
    $stepid = $_POST['stepid'];
41
if (!$stepid) $stepid = "0";
42

    
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
            $pkg = parse_xml_config_pkg("/usr/local/www/wizards/" . $xml, "pfsensewizard");
53
}
54

    
55
$title          = $pkg['step'][$stepid]['title'];
56
$description    = $pkg['step'][$stepid]['description'];
57
$totalsteps     = $pkg['totalsteps'];
58

    
59
if ($_POST) {
60
    foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
61
        if($field['bindstofield'] <> "" and $field['type'] <> "submit") {
62
		$fieldname = $field['name'];
63
		$unset_fields = "";
64
		$fieldname = ereg_replace(" ", "", $fieldname);
65
		$fieldname = strtolower($fieldname);
66
		// update field with posted values.
67
                if($field['unsetfield'] <> "") $unset_fields = "yes";
68
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
69
		if($field['bindstofield'])
70
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum);
71
        }
72
        if($pkg['step'][$stepid]['stepsubmitphpaction']) {
73
		// run custom php code embedded in xml config.
74
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
75
        }
76
	write_config();
77
    }
78
    $stepid++;
79
    if($stepid > $totalsteps) $stepid = $totalsteps;
80
}
81

    
82
$title          = $pkg['step'][$stepid]['title'];
83
$description    = $pkg['step'][$stepid]['description'];
84

    
85
function update_config_field($field, $updatetext, $unset, $arraynum) {
86
	global $config;
87
	$field_split = split("->",$field);
88
	foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
89
	if($field_conv == "") return;
90
	if($unset <> "") {
91
		$text = "unset(\$config" . $field_conv . ");";
92
		eval($text);
93
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
94
		eval($text);
95
	} else {
96
		if($arraynum <> "") {
97
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
98
		} else {
99
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
100
		}
101
		eval($text);
102
	}
103
}
104

    
105
if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "") {
106
	// handle before form display event.
107
        // good for modifying posted values, etc.
108
	eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
109
}
110

    
111
?>
112
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
113
<html>
114
<head>
115
<title><?=gentitle_pkg($title);?></title>
116
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
117
<link href="gui.css" rel="stylesheet" type="text/css">
118
</head>
119

    
120
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
121
<form action="wizard.php" method="post">
122
<input type="hidden" name="xml" value="<?= $xml ?>">
123
<input type="hidden" name="stepid" value="<?= $stepid ?>">
124
<?php if ($savemsg) print_info_box($savemsg); ?>
125

    
126
<center>
127

    
128
&nbsp;<br>
129

    
130
<img src="/logo.gif"><p>
131

    
132
<table width="600" cellspacing="0" cellpadding="3">
133
    <!-- wizard goes here -->
134
    <tr><td>&nbsp;</td></tr>
135
    <tr><td colspan='2'><center><b><?= $description ?></b></center></td></tr><tr><td>&nbsp;</td></tr>
136
    <?php
137
	if(!$pkg['step'][$stepid]['disableheader'])
138
		echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $title . "</td></tr>";
139
    ?>
140

    
141
    <?php
142
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
143
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
144

    
145
		    $value = $field['value'];
146
		    $name  = $field['name'];
147

    
148
		    $name = ereg_replace(" ", "", $name);
149
		    $name = strtolower($name);
150

    
151
		    if($field['bindstofield'] <> "") {
152
			$arraynum = "";
153
			$field_conv = "";
154
			$field_split = split("->", $field['bindstofield']);
155
			// arraynum is used in cases where there is an array of the same field
156
			// name such as dnsserver (2 of them)
157
			if($field['arraynum'] <> "") $arraynum = "[" . $field['arraynum'] . "]";
158
			foreach ($field_split as $f) $field_conv .= "['" . $f . "']";
159
			$toeval = "\$value = \$config" . $field_conv . $arraynum . ";";
160
			eval($toeval);
161
		    }
162

    
163
		    if(!$field['combinefieldsend'])
164
			echo "<tr>";
165

    
166
		    if ($field['type'] == "input") {
167
			if(!$field['dontdisplayname']) {
168
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
169
				echo $field['name'];
170
				echo ":</td>\n";
171
			}
172
			if(!$field['dontcombinecells'])
173
				echo "<td class=\"vtable\">\n";
174
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "'>\n";
175
		    } else if ($field['type'] == "password") {
176
			if(!$field['dontdisplayname']) {
177
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
178
				echo $field['name'];
179
				echo ":</td>\n";
180
			}
181
			if(!$field['dontcombinecells'])
182
				echo "<td class=\"vtable\">";
183
			echo "<input id='" . $name . "' name='" . $name . "' value='" . $value . "' type='password'>\n";
184
		    } else if ($field['type'] == "select") {
185
			if(!$field['dontdisplayname']) {
186
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
187
				echo $field['name'];
188
				echo ":</td>\n";
189
			}
190
			// XXX: TODO: set $selected
191
			if($field['size']) $size = " size='" . $field['size'] . "' ";
192
			if($field['multiple'] == "yes") $multiple = "MULTIPLE ";
193
			if(!$field['dontcombinecells'])
194
				echo "<td class=\"vtable\">\n";
195
			$onchange = "";
196
			foreach ($field['options']['option'] as $opt) {
197
				if($opt['enablefields'] <> "") {
198
					$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
199
				}
200
			}
201
			echo "<select " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
202
			foreach ($field['options']['option'] as $opt) {
203
				$selected = "";
204
				if($value == $opt['value']) $selected = " SELECTED";
205
			    echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
206
			}
207
			echo "</select>\n";
208
		    } else if ($field['type'] == "textarea") {
209
			if(!$field['dontdisplayname']) {
210
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
211
				echo $field['name'];
212
				echo ":</td>";
213
			}
214
			if(!$field['dontcombinecells'])
215
				echo "<td class=\"vtable\">";
216
			echo "<textarea id='" . $name . "' name='" . $name . ">" . $value . "</textarea>\n";
217
		    } else if ($field['type'] == "submit") {
218
			echo "<td>&nbsp;<br></td></tr>";
219
			echo "<tr><td colspan='2'><center>";
220
			echo "<input type='submit' name='" . $name . "' value='" . $field['name'] . "'>\n";
221
		    } else if ($field['type'] == "listtopic") {
222
			echo "<td>&nbsp;</td><tr>";
223
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br></td>\n";
224
		    } else if ($field['type'] == "checkbox") {
225
			if(!$field['dontdisplayname']) {
226
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
227
				echo $field['name'];
228
				echo ":</td>";
229
			}
230
			$checked = "";
231
			if($value) $checked = " CHECKED";
232
			echo "<td class=\"vtable\"><input type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked . ">\n";
233
		    }
234

    
235
		    if($field['typehint'] <> "") {
236
			echo $field['typehint'];
237
		    }
238

    
239
		    if($field['description'] <> "") {
240
			echo "<br>" . $field['description'];
241
			echo "</td>";
242
		    }
243

    
244
		    if(!$field['combinefieldsbegin'])
245
			 echo "</tr>\n";
246
		}
247
	}
248
    ?>
249
</table>
250

    
251
</form>
252
</body>
253
</html>
254

    
255
<?php
256

    
257
$fieldnames_array = Array();
258
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
259
	// create a fieldname loop that can be used with javascript
260
	// hide and enable features.
261
	echo "\n<script language=\"JavaScript\">\n";
262
	echo "function disableall() {\n";
263
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
264
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
265
			if(!$field['donotdisable'] <> "") {
266
				array_push($fieldnames_array, $field['name']);
267
				$fieldname = ereg_replace(" ", "", $field['name']);
268
				$fieldname = strtolower($fieldname);
269
				echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
270
			}
271
		}
272
	}
273
	echo "}\ndisableall();\n";
274
	echo "function enableitems(selectedindex) {\n";
275
	echo "disableall();\n";
276
	$idcounter = 0;
277
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
278
		echo "\tswitch(selectedindex) {\n";
279
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
280
			if($field['options']['option'] <> "") {
281
				foreach ($field['options']['option'] as $opt) {
282
					if($opt['enablefields'] <> "") {
283
						echo "\t\tcase " . $idcounter . ":\n";
284
						$enablefields_split = split(",", $opt['enablefields']);
285
						foreach ($enablefields_split as $efs) {
286
							$fieldname = ereg_replace(" ", "", $efs);
287
							$fieldname = strtolower($fieldname);
288
							if($fieldname <> "") {
289
								$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
290
								echo $onchange;
291
							}
292
						}
293
						echo "\t\t\tbreak;\n";
294
					}
295
					$idcounter = $idcounter + 1;
296
				}
297
			}
298
		}
299
		echo "\t}\n";
300
	}
301
	echo "}\n";
302
	echo "disableall();\n";
303
	echo "</script>\n\n";
304
}
305

    
306

    
307
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
308
	// handle after form display event.
309
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
310
}
311

    
312
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
313
	// handle after form display event.
314
        echo "\n<script language=\"JavaScript\">\n";
315
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
316
	echo "</script>\n\n";
317
}
318

    
319
?>
(97-97/97)