Project

General

Profile

Download (10.8 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($pkg['step'][$stepid]['stepsubmitbeforesave']) {
60
		eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
61
}
62

    
63
if ($_POST) {
64
    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
		if($field['arraynum'] <> "") $arraynum = $field['arraynum'];
73
		if($field['bindstofield'])
74
			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum);
75
        }
76
		// run custom php code embedded in xml config.
77
        if($pkg['step'][$stepid]['stepsubmitphpaction']) {
78
				eval($pkg['step'][$stepid]['stepsubmitphpaction']);
79
        }
80
	write_config();
81
    }
82
    $stepid++;
83
    if($stepid > $totalsteps) $stepid = $totalsteps;
84
}
85

    
86
$title          = $pkg['step'][$stepid]['title'];
87
$description    = $pkg['step'][$stepid]['description'];
88

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

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

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

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

    
130
<center>
131

    
132
&nbsp;<br>
133

    
134
<img src="/logo.gif"><p>
135

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

    
145
    <?php
146
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
147
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
148

    
149
		    $value = $field['value'];
150
		    $name  = $field['name'];
151

    
152
		    $name = ereg_replace(" ", "", $name);
153
		    $name = strtolower($name);
154

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

    
167
		    if(!$field['combinefieldsend'])
168
			echo "<tr>";
169

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

    
239
		    if($field['typehint'] <> "") {
240
			echo $field['typehint'];
241
		    }
242

    
243
		    if($field['description'] <> "") {
244
			echo "<br>" . $field['description'];
245
			echo "</td>";
246
		    }
247

    
248
		    if(!$field['combinefieldsbegin'])
249
			 echo "</tr>\n";
250
		}
251
	}
252
    ?>
253
</table>
254

    
255
</form>
256
</body>
257
</html>
258

    
259
<?php
260

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

    
310

    
311
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
312
	// handle after form display event.
313
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
314
}
315

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

    
323
?>
(99-99/99)