1 |
d47013e1
|
Scott Ullrich
|
#!/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 |
19fd2947
|
Scott Ullrich
|
if($_POST['xml']) $xml = $_POST['xml'];
|
44 |
d47013e1
|
Scott Ullrich
|
|
45 |
|
|
if($xml == "") {
|
46 |
|
|
$xml = "not_defined";
|
47 |
|
|
print_info_box_np("ERROR: Could not open " . $xml . ".");
|
48 |
|
|
die;
|
49 |
|
|
} else {
|
50 |
b3235baa
|
Scott Ullrich
|
$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
|
51 |
d47013e1
|
Scott Ullrich
|
}
|
52 |
|
|
|
53 |
|
|
$package_name = $pkg['menu']['name'];
|
54 |
|
|
$section = $pkg['menu']['section'];
|
55 |
|
|
$config_path = $pkg['configpath'];
|
56 |
3eaeb703
|
Scott Ullrich
|
$title = $section . ": " . $package_name;
|
57 |
d47013e1
|
Scott Ullrich
|
|
58 |
da7bf505
|
Scott Ullrich
|
$id = $_GET['id'];
|
59 |
|
|
if (isset($_POST['id']))
|
60 |
|
|
$id = $_POST['id'];
|
61 |
9b8837be
|
Scott Ullrich
|
|
62 |
e3c4b6b7
|
Scott Ullrich
|
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
|
63 |
b3235baa
|
Scott Ullrich
|
eval($toeval);
|
64 |
da7bf505
|
Scott Ullrich
|
|
65 |
e3c4b6b7
|
Scott Ullrich
|
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
|
66 |
|
|
eval($toeval);
|
67 |
da7bf505
|
Scott Ullrich
|
|
68 |
6483da5d
|
Scott Ullrich
|
if ($_POST) {
|
69 |
b3235baa
|
Scott Ullrich
|
if($_POST['act'] == "del") {
|
70 |
|
|
if($pkg['custom_delete_php_command']) {
|
71 |
|
|
eval($pkg['custom_delete_php_command']);
|
72 |
|
|
}
|
73 |
e3c4b6b7
|
Scott Ullrich
|
write_config();
|
74 |
b3235baa
|
Scott Ullrich
|
} else {
|
75 |
|
|
if($pkg['custom_add_php_command']) {
|
76 |
3eaeb703
|
Scott Ullrich
|
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 |
b3235baa
|
Scott Ullrich
|
}
|
97 |
6483da5d
|
Scott Ullrich
|
}
|
98 |
e3c4b6b7
|
Scott Ullrich
|
|
99 |
3eaeb703
|
Scott Ullrich
|
if($pkg['donotsave'] <> "") exit;
|
100 |
|
|
|
101 |
b3235baa
|
Scott Ullrich
|
// store values in xml configration file.
|
102 |
|
|
if (!$input_errors) {
|
103 |
|
|
$pkgarr = array();
|
104 |
e3c4b6b7
|
Scott Ullrich
|
|
105 |
b3235baa
|
Scott Ullrich
|
foreach ($pkg['fields']['field'] as $fields) {
|
106 |
|
|
$fieldname = $fields['fieldname'];
|
107 |
|
|
$fieldvalue = $_POST[$fieldname];
|
108 |
|
|
$toeval = "\$pkgarr['" . $fieldname . "'] = \"" . $fieldvalue . "\";";
|
109 |
|
|
eval($toeval);
|
110 |
|
|
}
|
111 |
e3c4b6b7
|
Scott Ullrich
|
|
112 |
|
|
if (isset($id) && $a_pkg[$id])
|
113 |
|
|
$a_pkg[$id] = $pkgarr;
|
114 |
|
|
else
|
115 |
|
|
$a_pkg[] = $pkgarr;
|
116 |
|
|
|
117 |
b3235baa
|
Scott Ullrich
|
write_config();
|
118 |
6483da5d
|
Scott Ullrich
|
|
119 |
e3c4b6b7
|
Scott Ullrich
|
header("Location: pkg.php?xml=" . $xml);
|
120 |
|
|
}
|
121 |
da7bf505
|
Scott Ullrich
|
}
|
122 |
|
|
|
123 |
d47013e1
|
Scott Ullrich
|
?>
|
124 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
125 |
|
|
<html>
|
126 |
|
|
<head>
|
127 |
|
|
<title><?=gentitle_pkg($title);?></title>
|
128 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
129 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
130 |
|
|
</head>
|
131 |
|
|
|
132 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
133 |
|
|
<?php
|
134 |
|
|
$config_tmp = $config;
|
135 |
|
|
$config = $pfSense_config;
|
136 |
|
|
include("fbegin.inc");
|
137 |
|
|
$config = $config_tmp;
|
138 |
|
|
?>
|
139 |
|
|
<p class="pgtitle"><?=$title?></p>
|
140 |
19fd2947
|
Scott Ullrich
|
<form action="pkg_edit.php" method="post">
|
141 |
|
|
<input type="hidden" name="xml" value="<?= $xml ?>">
|
142 |
d47013e1
|
Scott Ullrich
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
143 |
|
|
|
144 |
3eaeb703
|
Scott Ullrich
|
<br>
|
145 |
|
|
|
146 |
d47013e1
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
147 |
|
|
<tr>
|
148 |
|
|
<?php
|
149 |
|
|
$cols = 0;
|
150 |
3eaeb703
|
Scott Ullrich
|
$savevalue = "Save";
|
151 |
|
|
if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
|
152 |
|
|
foreach ($pkg['fields']['field'] as $pkga) { ?>
|
153 |
d47013e1
|
Scott Ullrich
|
</tr>
|
154 |
|
|
<tr valign="top">
|
155 |
|
|
<td width="22%" class="vncellreq">
|
156 |
3eaeb703
|
Scott Ullrich
|
<?= $pkga['fielddescr'] ?>
|
157 |
d47013e1
|
Scott Ullrich
|
</td>
|
158 |
|
|
<td class="vtable">
|
159 |
|
|
<?php
|
160 |
3eaeb703
|
Scott Ullrich
|
|
161 |
|
|
if($pkga['type'] == "input") {
|
162 |
d47013e1
|
Scott Ullrich
|
// XXX: TODO: set $value
|
163 |
3eaeb703
|
Scott Ullrich
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
164 |
|
|
echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
165 |
|
|
echo "<br>" . $pkga['description'] . "\n";
|
166 |
|
|
} else if($pkga['type'] == "password") {
|
167 |
|
|
echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
168 |
|
|
echo "<br>" . $pkga['description'] . "\n";
|
169 |
|
|
} else if($pkga['type'] == "select") {
|
170 |
d47013e1
|
Scott Ullrich
|
// XXX: TODO: set $selected
|
171 |
3eaeb703
|
Scott Ullrich
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
172 |
|
|
if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
|
173 |
|
|
echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
|
174 |
|
|
foreach ($pkga['options']['option'] as $opt) {
|
175 |
d47013e1
|
Scott Ullrich
|
echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'>" . $opt['name'] . "</option>\n";
|
176 |
|
|
}
|
177 |
|
|
echo "</select>\n";
|
178 |
3eaeb703
|
Scott Ullrich
|
echo "<br>" . $pkga['description'] . "\n";
|
179 |
|
|
} else if($pkga['type'] == "checkbox") {
|
180 |
|
|
echo "<input type='checkbox' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
181 |
|
|
echo "<br>" . $pkga['description'] . "\n";
|
182 |
|
|
} else if($pkga['type'] == "textarea") {
|
183 |
|
|
if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
|
184 |
|
|
if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
|
185 |
|
|
echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
|
186 |
|
|
echo "<br>" . $pkga['description'] . "\n";
|
187 |
|
|
} else if($pkga['type'] == "radio") {
|
188 |
|
|
echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
|
189 |
d47013e1
|
Scott Ullrich
|
}
|
190 |
3eaeb703
|
Scott Ullrich
|
|
191 |
|
|
if($pkga['typehint']) echo " " . $pkga['typehint'];
|
192 |
d47013e1
|
Scott Ullrich
|
?>
|
193 |
|
|
</td>
|
194 |
|
|
</tr>
|
195 |
|
|
<?php
|
196 |
|
|
$i++;
|
197 |
|
|
}
|
198 |
|
|
?>
|
199 |
|
|
<tr>
|
200 |
|
|
<td width="22%" valign="top"> </td>
|
201 |
|
|
<td width="78%">
|
202 |
3eaeb703
|
Scott Ullrich
|
<input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
|
203 |
d47013e1
|
Scott Ullrich
|
<?php if (isset($id) && $a_pkg[$id]): ?>
|
204 |
|
|
<input name="id" type="hidden" value="<?=$id;?>">
|
205 |
|
|
<?php endif; ?>
|
206 |
|
|
</td>
|
207 |
|
|
</tr>
|
208 |
|
|
</table>
|
209 |
|
|
|
210 |
|
|
</form>
|
211 |
|
|
<?php include("fend.inc"); ?>
|
212 |
|
|
</body>
|
213 |
|
|
</html>
|