Project

General

Profile

Download (10.9 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

    
77
    }
78
    // 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
    $stepid++;
84
    if($stepid > $totalsteps) $stepid = $totalsteps;
85
}
86

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

    
90
function update_config_field($field, $updatetext, $unset, $arraynum) {
91
	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
		$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
99
		eval($text);
100
	} else {
101
		if($arraynum <> "") {
102
			$text = "\$config" . $field_conv . "[" . $arraynum . "] = \"" . $updatetext . "\";";
103
		} else {
104
			$text = "\$config" . $field_conv . " = \"" . $updatetext . "\";";
105
		}
106
		eval($text);
107
	}
108
}
109

    
110
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
?>
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
<input type="hidden" name="stepid" value="<?= $stepid ?>">
129
<?php if ($savemsg) print_info_box($savemsg); ?>
130

    
131
<center>
132

    
133
&nbsp;<br>
134

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

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

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

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

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

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

    
172
		    if(!$field['combinefieldsend'])
173
			echo "<tr>";
174

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

    
244
		    if($field['typehint'] <> "") {
245
			echo $field['typehint'];
246
		    }
247

    
248
		    if($field['description'] <> "") {
249
			echo "<br>" . $field['description'];
250
			echo "</td>";
251
		    }
252

    
253
		    if(!$field['combinefieldsbegin'])
254
			 echo "</tr>\n";
255
		}
256
	}
257
    ?>
258
</table>
259

    
260
</form>
261
</body>
262
</html>
263

    
264
<?php
265

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

    
315

    
316
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
317
	// handle after form display event.
318
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
319
}
320

    
321
if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
322
	// handle after form display event.
323
        echo "\n<script language=\"JavaScript\">\n";
324
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
325
	echo "</script>\n\n";
326
}
327

    
328
?>
(99-99/99)