1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
pkg_edit.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
|
$pfSense_config = $config; // copy this since we will be parsing
|
34
|
// another xml file which will be clobbered.
|
35
|
|
36
|
function gentitle_pkg($pgname) {
|
37
|
global $pfSense_config;
|
38
|
return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
|
39
|
}
|
40
|
|
41
|
// XXX: Make this input safe.
|
42
|
$xml = $_GET['xml'];
|
43
|
if($_POST['xml']) $xml = $_POST['xml'];
|
44
|
|
45
|
if($xml == "") {
|
46
|
$xml = "not_defined";
|
47
|
print_info_box_np("ERROR: Could not open " . $xml . ".");
|
48
|
die;
|
49
|
} else {
|
50
|
$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
|
51
|
}
|
52
|
|
53
|
$package_name = $pkg['menu']['name'];
|
54
|
$section = $pkg['menu']['section'];
|
55
|
$config_path = $pkg['configpath'];
|
56
|
$title = $section . ": " . $package_name;
|
57
|
|
58
|
$id = $_GET['id'];
|
59
|
if (isset($_POST['id']))
|
60
|
$id = $_POST['id'];
|
61
|
|
62
|
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
|
63
|
eval($toeval);
|
64
|
|
65
|
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
|
66
|
eval($toeval);
|
67
|
|
68
|
if ($_POST) {
|
69
|
if($_POST['act'] == "del") {
|
70
|
if($pkg['custom_delete_php_command']) {
|
71
|
eval($pkg['custom_delete_php_command']);
|
72
|
}
|
73
|
write_config();
|
74
|
} else {
|
75
|
if($pkg['custom_add_php_command']) {
|
76
|
if($pkg['donotsave'] <> "") {
|
77
|
?>
|
78
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
79
|
<html>
|
80
|
<head>
|
81
|
<title><?=gentitle_pkg($title);?></title>
|
82
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
83
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
84
|
</head>
|
85
|
|
86
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
87
|
<?php
|
88
|
include("fbegin.inc");
|
89
|
?>
|
90
|
<p class="pgtitle"><?=$title?></p>
|
91
|
<?php
|
92
|
}
|
93
|
if($pkg['preoutput']) echo "<pre>";
|
94
|
eval($pkg['custom_add_php_command']);
|
95
|
if($pkg['preoutput']) echo "</pre>";
|
96
|
}
|
97
|
}
|
98
|
|
99
|
// donotsave is enabled. lets simply exit.
|
100
|
if($pkg['donotsave'] <> "") exit;
|
101
|
|
102
|
$firstfield = "";
|
103
|
$rows = 0;
|
104
|
|
105
|
// store values in xml configration file.
|
106
|
if (!$input_errors) {
|
107
|
$pkgarr = array();
|
108
|
foreach ($pkg['fields']['field'] as $fields) {
|
109
|
if($fields['type'] == "rowhelper") {
|
110
|
// save rowhelper items.
|
111
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
112
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
113
|
if($firstfield == "") {
|
114
|
$firstfield = $rowhelperfield['fieldname'];
|
115
|
} else {
|
116
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
117
|
}
|
118
|
$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
|
119
|
//echo($comd . "<br>");
|
120
|
eval($comd);
|
121
|
if($value <> "") {
|
122
|
$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
|
123
|
//echo($comd . "<br>");
|
124
|
eval($comd);
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
} else {
|
129
|
// simply loop through all field names looking for posted
|
130
|
// values matching the fieldnames. if found, save to package
|
131
|
// configuration area.
|
132
|
$fieldname = $fields['fieldname'];
|
133
|
$fieldvalue = $_POST[$fieldname];
|
134
|
$toeval = "\$pkgarr['" . $fieldname . "'] = \"" . $fieldvalue . "\";";
|
135
|
eval($toeval);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if (isset($id) && $a_pkg[$id])
|
140
|
$a_pkg[$id] = $pkgarr;
|
141
|
else
|
142
|
$a_pkg[] = $pkgarr;
|
143
|
|
144
|
write_config();
|
145
|
|
146
|
if($pkg['custom_add_php_command_late'] <> "") {
|
147
|
eval($pkg['custom_add_php_command_late']);
|
148
|
}
|
149
|
|
150
|
header("Location: pkg.php?xml=" . $xml);
|
151
|
exit;
|
152
|
}
|
153
|
}
|
154
|
|
155
|
?>
|
156
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
157
|
<html>
|
158
|
<head>
|
159
|
<title><?=gentitle_pkg($title);?></title>
|
160
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
161
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
162
|
</head>
|
163
|
|
164
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
165
|
|
166
|
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
|
167
|
</script>
|
168
|
|
169
|
<?php
|
170
|
$config_tmp = $config;
|
171
|
$config = $pfSense_config;
|
172
|
include("fbegin.inc");
|
173
|
$config = $config_tmp;
|
174
|
?>
|
175
|
<p class="pgtitle"><?=$title?></p>
|
176
|
<form action="pkg_edit.php" method="post">
|
177
|
<input type="hidden" name="xml" value="<?= $xml ?>">
|
178
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
179
|
|
180
|
<br>
|
181
|
|
182
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
183
|
<tr>
|
184
|
<?php
|
185
|
$cols = 0;
|
186
|
$savevalue = "Save";
|
187
|
if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
|
188
|
foreach ($pkg['fields']['field'] as $pkga) { ?>
|
189
|
</tr>
|
190
|
<tr valign="top">
|
191
|
<td width="22%" class="vncellreq">
|
192
|
<?= $pkga['fielddescr'] ?>
|
193
|
</td>
|
194
|
<td class="vtable">
|
195
|
<?php
|
196
|
|
197
|
if($pkga['type'] == "input") {
|
198
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
199
|
echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
200
|
echo "<br>" . $pkga['description'] . "\n";
|
201
|
} else if($pkga['type'] == "password") {
|
202
|
echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
203
|
echo "<br>" . $pkga['description'] . "\n";
|
204
|
} else if($pkga['type'] == "select") {
|
205
|
// XXX: TODO: set $selected
|
206
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
207
|
if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
|
208
|
echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
|
209
|
foreach ($pkga['options']['option'] as $opt) {
|
210
|
echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'>" . $opt['name'] . "</option>\n";
|
211
|
}
|
212
|
echo "</select>\n";
|
213
|
echo "<br>" . $pkga['description'] . "\n";
|
214
|
} else if($pkga['type'] == "checkbox") {
|
215
|
echo "<input type='checkbox' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
216
|
echo "<br>" . $pkga['description'] . "\n";
|
217
|
} else if($pkga['type'] == "textarea") {
|
218
|
if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
|
219
|
if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
|
220
|
echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
|
221
|
echo "<br>" . $pkga['description'] . "\n";
|
222
|
} else if($pkga['type'] == "radio") {
|
223
|
echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
|
224
|
} else if($pkga['type'] == "rowhelper") {
|
225
|
?>
|
226
|
<script type="text/javascript" language='javascript'>
|
227
|
<!--
|
228
|
|
229
|
<?php
|
230
|
$rowcounter = 0;
|
231
|
$fieldcounter = 0;
|
232
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
233
|
echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
|
234
|
echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
|
235
|
$fieldcounter++;
|
236
|
}
|
237
|
?>
|
238
|
|
239
|
-->
|
240
|
</script>
|
241
|
|
242
|
<table name="maintable" id="maintable">
|
243
|
<tr>
|
244
|
<?php
|
245
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
246
|
echo "<td><b>" . $rowhelper['fielddescr'] . "</td>\n";
|
247
|
}
|
248
|
echo "</tr>";
|
249
|
echo "<tbody>";
|
250
|
|
251
|
echo "<tr>";
|
252
|
// XXX: traverse saved fields, add back needed rows.
|
253
|
echo "</tr>";
|
254
|
|
255
|
if($rowcounter == 0) {
|
256
|
// nothing saved. manually add the first row.
|
257
|
echo "<tr>\n";
|
258
|
$rowcounter = 0;
|
259
|
$trc = 0;
|
260
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
261
|
$temp = "";
|
262
|
$text = "";
|
263
|
$value = "";
|
264
|
if($rowhelper['value'] <> "") $value = $rowhelper['value'];
|
265
|
echo "<td>\n";
|
266
|
if($rowhelper['type'] == "input") {
|
267
|
echo "<input size='8' name='" . $rowhelper['fieldname'] . "0" . "' value='" . $value . "'>\n";
|
268
|
} else if($rowhelper['type'] == "password") {
|
269
|
echo "<input type='password' name='" . $rowhelper['fieldname'] . "0" . "' value='" . $value . "'>\n";
|
270
|
} else if($rowhelper['type'] == "textarea") {
|
271
|
echo "<textarea name='" . $rowhelper['fieldname'] . "0" . "'>" . $value . "</textarea>\n";
|
272
|
} else if($rowhelper['type'] == "select") {
|
273
|
echo "<select name='" . $rowhelper['fieldname'] . "0" . "'>\n";
|
274
|
foreach($rowhelper['options']['option'] as $rowopt) {
|
275
|
$text .= "<option value='" . $rowopt['value'] . "'>" . $rowopt['name'] . "</option>";
|
276
|
echo "<option value='" . $rowopt['value'] . "'>" . $rowopt['name'] . "</option>\n";
|
277
|
}
|
278
|
echo "</select>\n";
|
279
|
}
|
280
|
echo "</td>\n";
|
281
|
echo "<script language=\"JavaScript\">\n";
|
282
|
echo "<!--\n";
|
283
|
echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
|
284
|
echo "-->\n";
|
285
|
echo "</script>\n";
|
286
|
$trc++;
|
287
|
}
|
288
|
$rowcounter=0;
|
289
|
echo "<td>";
|
290
|
echo "<input type=\"button\" onclick=\"removeRow(this); typesel_change();\" value=\"Delete\">";
|
291
|
echo "</td>\n";
|
292
|
echo "</tr>\n";
|
293
|
}
|
294
|
?>
|
295
|
|
296
|
</tbody>
|
297
|
</table>
|
298
|
|
299
|
<br><input type="button" onclick="addRowTo('maintable'); typesel_change();" value="Add">
|
300
|
|
301
|
<script language="JavaScript">
|
302
|
<!--
|
303
|
field_counter_js = <?= $fieldcounter ?>;
|
304
|
rows = <?= $rowcounter ?>;
|
305
|
totalrows = <?php echo $rowcounter; ?>;
|
306
|
loaded = <?php echo $rowcounter; ?>;
|
307
|
typesel_change();
|
308
|
|
309
|
//-->
|
310
|
</script>
|
311
|
|
312
|
<?php
|
313
|
}
|
314
|
|
315
|
if($pkga['typehint']) echo " " . $pkga['typehint'];
|
316
|
?>
|
317
|
</td>
|
318
|
</tr>
|
319
|
<?php
|
320
|
$i++;
|
321
|
}
|
322
|
?>
|
323
|
<tr>
|
324
|
<td> </td>
|
325
|
</tr>
|
326
|
<tr>
|
327
|
<td width="22%" valign="top"> </td>
|
328
|
<td width="78%">
|
329
|
<input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
|
330
|
<?php if (isset($id) && $a_pkg[$id]): ?>
|
331
|
<input name="id" type="hidden" value="<?=$id;?>">
|
332
|
<?php endif; ?>
|
333
|
</td>
|
334
|
</tr>
|
335
|
</table>
|
336
|
|
337
|
</form>
|
338
|
<?php include("fend.inc"); ?>
|
339
|
</body>
|
340
|
</html>
|
341
|
|