1 |
d47013e1
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
d47013e1
|
Scott Ullrich
|
/*
|
4 |
|
|
pkg_edit.php
|
5 |
4f6a5e6a
|
Scott Ullrich
|
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
|
6 |
d47013e1
|
Scott Ullrich
|
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 |
1d333258
|
Scott Ullrich
|
/*
|
30 |
|
|
pfSense_BUILDER_BINARIES: /sbin/ifconfig
|
31 |
|
|
pfSense_MODULE: pkgs
|
32 |
|
|
*/
|
33 |
d47013e1
|
Scott Ullrich
|
|
34 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
35 |
|
|
##|*IDENT=page-package-edit
|
36 |
|
|
##|*NAME=Package: Edit page
|
37 |
|
|
##|*DESCR=Allow access to the 'Package: Edit' page.
|
38 |
|
|
##|*MATCH=pkg_edit.php*
|
39 |
|
|
##|-PRIV
|
40 |
|
|
|
41 |
0089af7c
|
Scott Ullrich
|
ini_set('max_execution_time', '0');
|
42 |
|
|
|
43 |
7a927e67
|
Scott Ullrich
|
require("guiconfig.inc");
|
44 |
|
|
require_once("functions.inc");
|
45 |
|
|
require_once("filter.inc");
|
46 |
|
|
require_once("shaper.inc");
|
47 |
f8e335a3
|
Scott Ullrich
|
require_once("pkg-utils.inc");
|
48 |
d47013e1
|
Scott Ullrich
|
|
49 |
14db714e
|
Scott Ullrich
|
/* dummy stubs needed by some code that was MFC'd */
|
50 |
916b74c6
|
Scott Ullrich
|
function pfSenseHeader($location) { header("Location: " . $location); }
|
51 |
14db714e
|
Scott Ullrich
|
|
52 |
d47013e1
|
Scott Ullrich
|
function gentitle_pkg($pgname) {
|
53 |
|
|
global $pfSense_config;
|
54 |
|
|
return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
d8c1a6c5
|
Scott Ullrich
|
$xml = htmlspecialchars($_GET['xml']);
|
58 |
|
|
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
|
59 |
d47013e1
|
Scott Ullrich
|
|
60 |
|
|
if($xml == "") {
|
61 |
b91540da
|
Scott Ullrich
|
print_info_box_np(gettext("ERROR: No package defined."));
|
62 |
d47013e1
|
Scott Ullrich
|
die;
|
63 |
|
|
} else {
|
64 |
19a11678
|
Colin Smith
|
$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
|
65 |
d47013e1
|
Scott Ullrich
|
}
|
66 |
7c172009
|
Scott Ullrich
|
|
67 |
|
|
if($pkg['include_file'] <> "") {
|
68 |
|
|
require_once($pkg['include_file']);
|
69 |
|
|
}
|
70 |
|
|
|
71 |
b91540da
|
Scott Ullrich
|
if (!isset($pkg['adddeleteeditpagefields']))
|
72 |
|
|
$only_edit = true;
|
73 |
|
|
else
|
74 |
|
|
$only_edit = false;
|
75 |
|
|
|
76 |
a28c8b59
|
Scott Ullrich
|
$package_name = $pkg['menu'][0]['name'];
|
77 |
|
|
$section = $pkg['menu'][0]['section'];
|
78 |
d47013e1
|
Scott Ullrich
|
$config_path = $pkg['configpath'];
|
79 |
bb940538
|
Scott Ullrich
|
$name = $pkg['name'];
|
80 |
b91540da
|
Scott Ullrich
|
$title = $pkg['title'];
|
81 |
96d9f5c9
|
Bill Marquette
|
$pgtitle = $title;
|
82 |
d47013e1
|
Scott Ullrich
|
|
83 |
da7bf505
|
Scott Ullrich
|
$id = $_GET['id'];
|
84 |
|
|
if (isset($_POST['id']))
|
85 |
d8c1a6c5
|
Scott Ullrich
|
$id = htmlspecialchars($_POST['id']);
|
86 |
916b74c6
|
Scott Ullrich
|
|
87 |
|
|
// Not posting? Then user is editing a record. There must be a valid id
|
88 |
|
|
// when editing a record.
|
89 |
|
|
if(!$id && !$_POST)
|
90 |
|
|
$id = "0";
|
91 |
|
|
|
92 |
529ffadb
|
Bill Marquette
|
if($pkg['custom_php_global_functions'] <> "")
|
93 |
|
|
eval($pkg['custom_php_global_functions']);
|
94 |
|
|
|
95 |
31d27c6c
|
Scott Ullrich
|
// grab the installedpackages->package_name section.
|
96 |
e315cfa1
|
Colin Smith
|
if(!is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']))
|
97 |
7db8ff99
|
Colin Smith
|
$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
|
98 |
da7bf505
|
Scott Ullrich
|
|
99 |
a2a7f74d
|
jim-p
|
// If the first entry in the array is an empty <config/> tag, kill it.
|
100 |
|
|
if ((count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0)
|
101 |
|
|
&& ($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0] == ""))
|
102 |
|
|
array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
|
103 |
|
|
|
104 |
7db8ff99
|
Colin Smith
|
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
105 |
da7bf505
|
Scott Ullrich
|
|
106 |
19d360bf
|
Scott Ullrich
|
if($_GET['savemsg'] <> "")
|
107 |
d8c1a6c5
|
Scott Ullrich
|
$savemsg = htmlspecialchars($_GET['savemsg']);
|
108 |
f9a91638
|
Scott Ullrich
|
|
109 |
194b4e0a
|
Colin Smith
|
if($pkg['custom_php_command_before_form'] <> "")
|
110 |
|
|
eval($pkg['custom_php_command_before_form']);
|
111 |
f9a91638
|
Scott Ullrich
|
|
112 |
6483da5d
|
Scott Ullrich
|
if ($_POST) {
|
113 |
b3235baa
|
Scott Ullrich
|
if($_POST['act'] == "del") {
|
114 |
|
|
if($pkg['custom_delete_php_command']) {
|
115 |
5cd30ac3
|
Scott Ullrich
|
if($pkg['custom_php_command_before_form'] <> "")
|
116 |
|
|
eval($pkg['custom_php_command_before_form']);
|
117 |
b3235baa
|
Scott Ullrich
|
eval($pkg['custom_delete_php_command']);
|
118 |
|
|
}
|
119 |
7c172009
|
Scott Ullrich
|
write_config($pkg['delete_string']);
|
120 |
facd08f9
|
Scott Ullrich
|
// resync the configuration file code if defined.
|
121 |
|
|
if($pkg['custom_php_resync_config_command'] <> "") {
|
122 |
86f3fc00
|
Scott Ullrich
|
if($pkg['custom_php_command_before_form'] <> "")
|
123 |
|
|
eval($pkg['custom_php_command_before_form']);
|
124 |
|
|
eval($pkg['custom_php_resync_config_command']);
|
125 |
facd08f9
|
Scott Ullrich
|
}
|
126 |
b3235baa
|
Scott Ullrich
|
} else {
|
127 |
|
|
if($pkg['custom_add_php_command']) {
|
128 |
90779bf7
|
Scott Ullrich
|
if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
|
129 |
12123e25
|
Colin Smith
|
?>
|
130 |
afe4a7d3
|
Erik Kristensen
|
|
131 |
539b4c44
|
Colin Smith
|
<?php include("head.inc"); ?>
|
132 |
3eaeb703
|
Scott Ullrich
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
133 |
2fe6c52b
|
Colin Smith
|
<?php include("fbegin.inc"); ?>
|
134 |
fbd14b13
|
Scott Ullrich
|
<?php
|
135 |
3eaeb703
|
Scott Ullrich
|
}
|
136 |
|
|
if($pkg['preoutput']) echo "<pre>";
|
137 |
|
|
eval($pkg['custom_add_php_command']);
|
138 |
|
|
if($pkg['preoutput']) echo "</pre>";
|
139 |
b3235baa
|
Scott Ullrich
|
}
|
140 |
6483da5d
|
Scott Ullrich
|
}
|
141 |
e3c4b6b7
|
Scott Ullrich
|
|
142 |
eec70f21
|
Scott Ullrich
|
// donotsave is enabled. lets simply exit.
|
143 |
3eaeb703
|
Scott Ullrich
|
if($pkg['donotsave'] <> "") exit;
|
144 |
|
|
|
145 |
b6e87566
|
Scott Ullrich
|
$firstfield = "";
|
146 |
|
|
$rows = 0;
|
147 |
|
|
|
148 |
7c172009
|
Scott Ullrich
|
$input_errors = array();
|
149 |
|
|
$reqfields = array();
|
150 |
|
|
$reqfieldsn = array();
|
151 |
|
|
foreach ($pkg['fields']['field'] as $field) {
|
152 |
b91540da
|
Scott Ullrich
|
if (($field['type'] == 'input') && isset($field['required'])) {
|
153 |
349ef5c9
|
Scott Ullrich
|
if($field['fieldname'])
|
154 |
|
|
$reqfields[] = $field['fieldname'];
|
155 |
|
|
if($field['fielddescr'])
|
156 |
|
|
$reqfieldsn[] = $field['fielddescr'];
|
157 |
7c172009
|
Scott Ullrich
|
}
|
158 |
|
|
}
|
159 |
|
|
do_input_validation($_POST, $reqfields, $reqfieldsn, &$input_errors);
|
160 |
|
|
|
161 |
|
|
if ($pkg['custom_php_validation_command'])
|
162 |
|
|
eval($pkg['custom_php_validation_command']);
|
163 |
|
|
|
164 |
b3235baa
|
Scott Ullrich
|
// store values in xml configration file.
|
165 |
|
|
if (!$input_errors) {
|
166 |
|
|
$pkgarr = array();
|
167 |
|
|
foreach ($pkg['fields']['field'] as $fields) {
|
168 |
41fd0445
|
Scott Ullrich
|
if($fields['type'] == "listtopic")
|
169 |
|
|
continue;
|
170 |
eec70f21
|
Scott Ullrich
|
if($fields['type'] == "rowhelper") {
|
171 |
|
|
// save rowhelper items.
|
172 |
|
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
173 |
628b33c1
|
Scott Ullrich
|
// XXX: this really is not helping embedded platforms.
|
174 |
0e730fee
|
Scott Ullrich
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
175 |
b6e87566
|
Scott Ullrich
|
if($firstfield == "") {
|
176 |
|
|
$firstfield = $rowhelperfield['fieldname'];
|
177 |
|
|
} else {
|
178 |
|
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
179 |
|
|
}
|
180 |
6e32d276
|
Scott Ullrich
|
$fieldname = str_replace("\\", "", $rowhelperfield['fieldname']);
|
181 |
13e92c36
|
Scott Ullrich
|
$comd = "\$value = \$_POST['" . $fieldname . $x . "'];";
|
182 |
eec70f21
|
Scott Ullrich
|
eval($comd);
|
183 |
|
|
if($value <> "") {
|
184 |
6e32d276
|
Scott Ullrich
|
$comd = "\$pkgarr['row'][" . $x . "]['" . $fieldname . "'] = \"" . $value . "\";";
|
185 |
b6e87566
|
Scott Ullrich
|
//echo($comd . "<br>");
|
186 |
eec70f21
|
Scott Ullrich
|
eval($comd);
|
187 |
|
|
}
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
} else {
|
191 |
|
|
$fieldname = $fields['fieldname'];
|
192 |
fbd14b13
|
Scott Ullrich
|
$fieldvalue = $_POST[$fieldname];
|
193 |
|
|
if (is_array($fieldvalue))
|
194 |
|
|
$fieldvalue = implode(',', $fieldvalue);
|
195 |
|
|
else {
|
196 |
|
|
$fieldvalue = trim($fieldvalue);
|
197 |
|
|
if ($fields['encoding'] == 'base64')
|
198 |
|
|
$fieldvalue = base64_encode($fieldvalue);
|
199 |
|
|
}
|
200 |
349ef5c9
|
Scott Ullrich
|
if($fieldname)
|
201 |
|
|
$pkgarr[$fieldname] = $fieldvalue;
|
202 |
eec70f21
|
Scott Ullrich
|
}
|
203 |
b3235baa
|
Scott Ullrich
|
}
|
204 |
0e730fee
|
Scott Ullrich
|
|
205 |
e3c4b6b7
|
Scott Ullrich
|
if (isset($id) && $a_pkg[$id])
|
206 |
|
|
$a_pkg[$id] = $pkgarr;
|
207 |
|
|
else
|
208 |
|
|
$a_pkg[] = $pkgarr;
|
209 |
0e730fee
|
Scott Ullrich
|
|
210 |
7c172009
|
Scott Ullrich
|
write_config($pkg['addedit_string']);
|
211 |
facd08f9
|
Scott Ullrich
|
// late running code
|
212 |
2a520a0a
|
Scott Ullrich
|
if($pkg['custom_add_php_command_late'] <> "") {
|
213 |
|
|
eval($pkg['custom_add_php_command_late']);
|
214 |
|
|
}
|
215 |
0e730fee
|
Scott Ullrich
|
|
216 |
b8d220ab
|
Scott Ullrich
|
if (isset($pkg['filter_rules_needed']))
|
217 |
07bcca25
|
Ermal Lu?i
|
filter_configure();
|
218 |
a9b2e638
|
Ermal Lu?i
|
|
219 |
facd08f9
|
Scott Ullrich
|
// resync the configuration file code if defined.
|
220 |
|
|
if($pkg['custom_php_resync_config_command'] <> "") {
|
221 |
|
|
eval($pkg['custom_php_resync_config_command']);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
dcbe6f52
|
Scott Ullrich
|
parse_package_templates();
|
225 |
|
|
|
226 |
a485a6f5
|
Scott Ullrich
|
/* if start_command is defined, restart w/ this */
|
227 |
|
|
if($pkg['start_command'] <> "")
|
228 |
|
|
exec($pkg['start_command'] . ">/dev/null 2&>1");
|
229 |
|
|
|
230 |
|
|
/* if restart_command is defined, restart w/ this */
|
231 |
|
|
if($pkg['restart_command'] <> "")
|
232 |
|
|
exec($pkg['restart_command'] . ">/dev/null 2&>1");
|
233 |
|
|
|
234 |
dcbe6f52
|
Scott Ullrich
|
if($pkg['aftersaveredirect'] <> "") {
|
235 |
fbd14b13
|
Scott Ullrich
|
pfSenseHeader($pkg['aftersaveredirect']);
|
236 |
3089059e
|
Colin Smith
|
} elseif(!$pkg['adddeleteeditpagefields']) {
|
237 |
fbd14b13
|
Scott Ullrich
|
pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
|
238 |
3089059e
|
Colin Smith
|
} elseif(!$pkg['preoutput']) {
|
239 |
fbd14b13
|
Scott Ullrich
|
pfSenseHeader("pkg.php?xml=" . $xml);
|
240 |
dcbe6f52
|
Scott Ullrich
|
}
|
241 |
0e730fee
|
Scott Ullrich
|
exit;
|
242 |
e3c4b6b7
|
Scott Ullrich
|
}
|
243 |
7c172009
|
Scott Ullrich
|
else
|
244 |
|
|
$get_from_post = true;
|
245 |
da7bf505
|
Scott Ullrich
|
}
|
246 |
|
|
|
247 |
b91540da
|
Scott Ullrich
|
if($pkg['title'] <> "") {
|
248 |
f0d1af93
|
Carlos Eduardo Ramos
|
$edit = ($only_edit ? '' : ": " . gettext("Edit"));
|
249 |
b91540da
|
Scott Ullrich
|
$title = $pkg['title'] . $edit;
|
250 |
|
|
}
|
251 |
83ddedcd
|
Scott Ullrich
|
else
|
252 |
b91540da
|
Scott Ullrich
|
$title = gettext("Package Editor");
|
253 |
83ddedcd
|
Scott Ullrich
|
|
254 |
|
|
$pgtitle = $title;
|
255 |
|
|
include("head.inc");
|
256 |
|
|
|
257 |
7c172009
|
Scott Ullrich
|
if ($pkg['custom_php_after_head_command'])
|
258 |
|
|
eval($pkg['custom_php_after_head_command']);
|
259 |
|
|
|
260 |
d47013e1
|
Scott Ullrich
|
?>
|
261 |
|
|
|
262 |
2fe6c52b
|
Colin Smith
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
|
263 |
|
|
<?php if($pkg['fields']['field'] <> "") { ?>
|
264 |
|
|
<script language="JavaScript">
|
265 |
|
|
<!--
|
266 |
|
|
function enablechange() {
|
267 |
3c616886
|
Scott Ullrich
|
<?php
|
268 |
fbd14b13
|
Scott Ullrich
|
foreach ($pkg['fields']['field'] as $field) {
|
269 |
|
|
if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
|
270 |
|
|
print("\tif (document.iform.elements[\"{$field['fieldname']}\"].checked == false) {\n");
|
271 |
|
|
|
272 |
|
|
if (isset($field['enablefields'])) {
|
273 |
dcf6d563
|
Manoel Carvalho
|
foreach (explode(',', $field['enablefields']) as $enablefield) {
|
274 |
|
|
print("\t\tif(document.iform.elements[\"$enablefield\"]){\n");
|
275 |
|
|
print("\t\t\tdocument.iform.elements[\"$enablefield\"].disabled = 1;\n");
|
276 |
|
|
print("\t\t}else{\n");
|
277 |
|
|
print("\t\t\tdocument.iform.elements[\"$enablefield".'[]'."\"].disabled = 1;\n");
|
278 |
|
|
print("\t\t}\n");
|
279 |
|
|
}
|
280 |
fbd14b13
|
Scott Ullrich
|
}
|
281 |
|
|
|
282 |
|
|
if (isset($field['checkenablefields'])) {
|
283 |
dcf6d563
|
Manoel Carvalho
|
foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
|
284 |
|
|
print("\t\tif(document.iform.elements[\"$checkenablefield\"]){\n");
|
285 |
|
|
print("\t\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 0;\n");
|
286 |
|
|
print("\t\t}else{\n");
|
287 |
|
|
print("\t\t\tdocument.iform.elements[\"$checkenablefield".'[]'."\"].checked = 0;\n");
|
288 |
|
|
print("\t\t}\n");
|
289 |
|
|
}
|
290 |
fbd14b13
|
Scott Ullrich
|
}
|
291 |
|
|
|
292 |
|
|
print("\t}\n\telse {\n");
|
293 |
|
|
|
294 |
|
|
if (isset($field['enablefields'])) {
|
295 |
dcf6d563
|
Manoel Carvalho
|
foreach (explode(',', $field['enablefields']) as $enablefield) {
|
296 |
|
|
print("\t\tif(document.iform.elements[\"$enablefield\"]){\n");
|
297 |
|
|
print("\t\t\tdocument.iform.elements[\"$enablefield\"].disabled = 0;\n");
|
298 |
|
|
print("\t\t}else{\n");
|
299 |
|
|
print("\t\t\tdocument.iform.elements[\"$enablefield".'[]'."\"].disabled = 0;\n");
|
300 |
|
|
print("\t\t}\n");
|
301 |
|
|
}
|
302 |
fbd14b13
|
Scott Ullrich
|
}
|
303 |
|
|
|
304 |
|
|
if (isset($field['checkenablefields'])) {
|
305 |
dcf6d563
|
Manoel Carvalho
|
foreach(explode(',', $field['checkenablefields']) as $checkenablefield) {
|
306 |
|
|
print("\t\tif(document.iform.elements[\"$checkenablefield\"]){\n");
|
307 |
|
|
print("\t\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 1;\n");
|
308 |
|
|
print("\t\t}else{\n");
|
309 |
|
|
print("\t\t\tdocument.iform.elements[\"$checkenablefield".'[]'."\"].checked = 1;\n");
|
310 |
|
|
print("\t\t}\n");
|
311 |
|
|
}
|
312 |
fbd14b13
|
Scott Ullrich
|
}
|
313 |
|
|
|
314 |
|
|
print("\t}\n");
|
315 |
|
|
}
|
316 |
|
|
}
|
317 |
2fe6c52b
|
Colin Smith
|
?>
|
318 |
|
|
}
|
319 |
|
|
//-->
|
320 |
|
|
</script>
|
321 |
|
|
<?php } ?>
|
322 |
625dcc40
|
Bill Marquette
|
<script type="text/javascript" language="javascript" src="/javascript/row_helper_dynamic.js">
|
323 |
eec70f21
|
Scott Ullrich
|
</script>
|
324 |
|
|
|
325 |
96d9f5c9
|
Bill Marquette
|
<?php include("fbegin.inc"); ?>
|
326 |
7c172009
|
Scott Ullrich
|
<?php if (!empty($input_errors)) print_input_errors($input_errors); ?>
|
327 |
|
|
<form name="iform" action="pkg_edit.php" method="post">
|
328 |
19fd2947
|
Scott Ullrich
|
<input type="hidden" name="xml" value="<?= $xml ?>">
|
329 |
d47013e1
|
Scott Ullrich
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
330 |
f4cb26b7
|
Colin Smith
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
331 |
7c061036
|
Scott Ullrich
|
<?php
|
332 |
|
|
if ($pkg['tabs'] <> "") {
|
333 |
f4cb26b7
|
Colin Smith
|
echo '<tr><td>';
|
334 |
|
|
$tab_array = array();
|
335 |
7c061036
|
Scott Ullrich
|
foreach($pkg['tabs']['tab'] as $tab) {
|
336 |
f4cb26b7
|
Colin Smith
|
if(isset($tab['active'])) {
|
337 |
|
|
$active = true;
|
338 |
|
|
} else {
|
339 |
|
|
$active = false;
|
340 |
|
|
}
|
341 |
e17ce934
|
Scott Ullrich
|
$urltmp = "";
|
342 |
|
|
if($tab['url'] <> "") $urltmp = $tab['url'];
|
343 |
|
|
if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
|
344 |
|
|
|
345 |
656a2fea
|
Seth Mos
|
$addresswithport = getenv("HTTP_HOST");
|
346 |
|
|
$colonpos = strpos($addresswithport, ":");
|
347 |
|
|
if ($colonpos !== False){
|
348 |
|
|
//my url is actually just the IP address of the pfsense box
|
349 |
|
|
$myurl = substr($addresswithport, 0, $colonpos);
|
350 |
|
|
}
|
351 |
|
|
else
|
352 |
|
|
{
|
353 |
|
|
$myurl = $addresswithport;
|
354 |
|
|
}
|
355 |
e17ce934
|
Scott Ullrich
|
// eval url so that above $myurl item can be processed if need be.
|
356 |
f4cb26b7
|
Colin Smith
|
$url = str_replace('$myurl', $myurl, $urltmp);
|
357 |
656a2fea
|
Seth Mos
|
|
358 |
f4cb26b7
|
Colin Smith
|
$tab_array[] = array(
|
359 |
|
|
$tab['text'],
|
360 |
|
|
$active,
|
361 |
|
|
$url
|
362 |
|
|
);
|
363 |
7c061036
|
Scott Ullrich
|
}
|
364 |
f4cb26b7
|
Colin Smith
|
display_top_tabs($tab_array);
|
365 |
|
|
echo '</td></tr>';
|
366 |
7c061036
|
Scott Ullrich
|
}
|
367 |
|
|
?>
|
368 |
f4cb26b7
|
Colin Smith
|
<tr><td><div id="mainarea"><table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
369 |
d47013e1
|
Scott Ullrich
|
<?php
|
370 |
|
|
$cols = 0;
|
371 |
457106da
|
Renato Botelho
|
$savevalue = gettext("Save");
|
372 |
3eaeb703
|
Scott Ullrich
|
if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
|
373 |
32487e42
|
Scott Ullrich
|
foreach ($pkg['fields']['field'] as $pkga) {
|
374 |
|
|
|
375 |
|
|
if ($pkga['type'] == "listtopic") {
|
376 |
|
|
echo "<td> </td>";
|
377 |
|
|
echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $pkga['name'] . "<br></td></tr>\n";
|
378 |
|
|
continue;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
?>
|
382 |
3c616886
|
Scott Ullrich
|
|
383 |
facd08f9
|
Scott Ullrich
|
<?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
|
384 |
|
|
|
385 |
d47013e1
|
Scott Ullrich
|
<?php
|
386 |
3c616886
|
Scott Ullrich
|
|
387 |
5c74f339
|
Scott Ullrich
|
$size = "";
|
388 |
3c616886
|
Scott Ullrich
|
|
389 |
facd08f9
|
Scott Ullrich
|
if(!$pkga['dontdisplayname']) {
|
390 |
7c172009
|
Scott Ullrich
|
unset($req);
|
391 |
b91540da
|
Scott Ullrich
|
if (isset($pkga['required']))
|
392 |
7c172009
|
Scott Ullrich
|
$req = 'req';
|
393 |
|
|
echo "<td width=\"22%\" class=\"vncell{$req}\">";
|
394 |
d51f86e0
|
Scott Ullrich
|
echo fixup_string($pkga['fielddescr']);
|
395 |
31d27c6c
|
Scott Ullrich
|
echo "</td>";
|
396 |
facd08f9
|
Scott Ullrich
|
}
|
397 |
|
|
|
398 |
|
|
if(!$pkga['dontcombinecells'])
|
399 |
|
|
echo "<td class=\"vtable\">";
|
400 |
31d27c6c
|
Scott Ullrich
|
// if user is editing a record, load in the data.
|
401 |
7c172009
|
Scott Ullrich
|
$fieldname = $pkga['fieldname'];
|
402 |
fbd14b13
|
Scott Ullrich
|
if ($get_from_post) {
|
403 |
7c172009
|
Scott Ullrich
|
$value = $_POST[$fieldname];
|
404 |
fbd14b13
|
Scott Ullrich
|
if (is_array($value)) $value = implode(',', $value);
|
405 |
|
|
}
|
406 |
7c172009
|
Scott Ullrich
|
else {
|
407 |
|
|
if (isset($id) && $a_pkg[$id])
|
408 |
|
|
$value = $a_pkg[$id][$fieldname];
|
409 |
b91540da
|
Scott Ullrich
|
else
|
410 |
|
|
$value = $pkga['default_value'];
|
411 |
31d27c6c
|
Scott Ullrich
|
}
|
412 |
|
|
|
413 |
3eaeb703
|
Scott Ullrich
|
if($pkga['type'] == "input") {
|
414 |
b6e87566
|
Scott Ullrich
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
415 |
e4f8f7d2
|
Bill Marquette
|
echo "<input " . $size . " id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' class='formfld unknown' value='" . $value . "'>\n";
|
416 |
d51f86e0
|
Scott Ullrich
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
417 |
3eaeb703
|
Scott Ullrich
|
} else if($pkga['type'] == "password") {
|
418 |
f1412ed6
|
Scott Ullrich
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
419 |
e4f8f7d2
|
Bill Marquette
|
echo "<input " . $size . " id='" . $pkga['fieldname'] . "' type='password' " . $size . " name='" . $pkga['fieldname'] . "' class='formfld pwd' value='" . $value . "'>\n";
|
420 |
d51f86e0
|
Scott Ullrich
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
421 |
3eaeb703
|
Scott Ullrich
|
} else if($pkga['type'] == "select") {
|
422 |
fbd14b13
|
Scott Ullrich
|
$fieldname = $pkga['fieldname'];
|
423 |
|
|
if (isset($pkga['multiple'])) {
|
424 |
67fa245a
|
Scott Ullrich
|
$multiple = 'multiple="multiple"';
|
425 |
fbd14b13
|
Scott Ullrich
|
$items = explode(',', $value);
|
426 |
67fa245a
|
Scott Ullrich
|
$fieldname .= "[]";
|
427 |
fbd14b13
|
Scott Ullrich
|
}
|
428 |
|
|
else {
|
429 |
|
|
$multiple = '';
|
430 |
|
|
$items = array($value);
|
431 |
|
|
}
|
432 |
|
|
$size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
|
433 |
|
|
$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
|
434 |
|
|
|
435 |
ae2ea68c
|
Scott Ullrich
|
print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
|
436 |
fbd14b13
|
Scott Ullrich
|
foreach ($pkga['options']['option'] as $opt) {
|
437 |
|
|
$selected = '';
|
438 |
67fa245a
|
Scott Ullrich
|
if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
|
439 |
fbd14b13
|
Scott Ullrich
|
print("\t<option name=\"{$opt['name']}\" value=\"{$opt['value']}\" $selected>{$opt['name']}</option>\n");
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");
|
443 |
9f65abbf
|
Scott Ullrich
|
} else if($pkga['type'] == "select_source") {
|
444 |
|
|
$fieldname = $pkga['fieldname'];
|
445 |
|
|
if (isset($pkga['multiple'])) {
|
446 |
|
|
$multiple = 'multiple="multiple"';
|
447 |
|
|
$items = explode(',', $value);
|
448 |
|
|
$fieldname .= "[]";
|
449 |
|
|
}
|
450 |
|
|
else {
|
451 |
|
|
$multiple = '';
|
452 |
|
|
$items = array($value);
|
453 |
|
|
}
|
454 |
|
|
$size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
|
455 |
|
|
$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
|
456 |
|
|
|
457 |
|
|
print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
|
458 |
|
|
$source_url = $pkga['source'];
|
459 |
|
|
eval("\$pkg_source_txt = &$source_url;");
|
460 |
|
|
foreach ($pkg_source_txt as $opt) {
|
461 |
|
|
$selected = '';
|
462 |
|
|
if($pkga['source_name']) {
|
463 |
|
|
$source_name = $opt[$pkga['source_name']];
|
464 |
|
|
} else {
|
465 |
|
|
$source_name = $opt[$pkga['name']];
|
466 |
|
|
}
|
467 |
|
|
if($pkga['source_value']) {
|
468 |
|
|
$source_value = $opt[$pkga['source_value']];
|
469 |
|
|
} else {
|
470 |
|
|
$source_value = $opt[$pkga['value']];
|
471 |
|
|
}
|
472 |
|
|
if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
|
473 |
|
|
print("\t<option name=\"{$source_name}\" value=\"{$source_value}\" $selected>{$source_name}</option>\n");
|
474 |
|
|
}
|
475 |
|
|
|
476 |
|
|
print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");
|
477 |
2c634bdd
|
Scott Ullrich
|
} else if($pkga['type'] == "vpn_selection") {
|
478 |
ae2ea68c
|
Scott Ullrich
|
echo "<select id='" . $pkga['fieldname'] . "' name='" . $vpn['name'] . "'>\n";
|
479 |
a93e56c5
|
Matthew Grooms
|
foreach ($config['ipsec']['phase1'] as $vpn) {
|
480 |
2c634bdd
|
Scott Ullrich
|
echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
|
481 |
|
|
}
|
482 |
|
|
echo "</select>\n";
|
483 |
03f0bfe7
|
Scott Ullrich
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
484 |
3eaeb703
|
Scott Ullrich
|
} else if($pkga['type'] == "checkbox") {
|
485 |
64c1ebbb
|
Scott Ullrich
|
$checkboxchecked = "";
|
486 |
34865da0
|
Scott Ullrich
|
if($value == "on") $checkboxchecked = " CHECKED";
|
487 |
b91540da
|
Scott Ullrich
|
if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
|
488 |
|
|
$onclick = ' onclick="javascript:enablechange();"';
|
489 |
ae2ea68c
|
Scott Ullrich
|
echo "<input id='" . $pkga['fieldname'] . "' type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . $onclick . ">\n";
|
490 |
d51f86e0
|
Scott Ullrich
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
491 |
3eaeb703
|
Scott Ullrich
|
} else if($pkga['type'] == "textarea") {
|
492 |
|
|
if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
|
493 |
|
|
if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
|
494 |
82458abb
|
Mark Crane
|
if($pkga['wrap'] == "off") { $wrap = 'wrap="off" style="white-space:nowrap;"'; } else { $wrap = ''; }
|
495 |
5d65350b
|
Ermal Lu?i
|
if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) $value = base64_decode($value);
|
496 |
82458abb
|
Mark Crane
|
echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "' ".$wrap.">" . $value . "</textarea>\n";
|
497 |
d51f86e0
|
Scott Ullrich
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
498 |
ab73789e
|
Scott Ullrich
|
} else if($pkga['type'] == "interfaces_selection") {
|
499 |
fbd14b13
|
Scott Ullrich
|
$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
|
500 |
|
|
$multiple = '';
|
501 |
7502342a
|
Scott Ullrich
|
$fieldname = $pkga['fieldname'];
|
502 |
fbd14b13
|
Scott Ullrich
|
if (isset($pkga['multiple'])) {
|
503 |
|
|
$fieldname .= '[]';
|
504 |
|
|
$multiple = 'multiple';
|
505 |
e4a72146
|
Scott Ullrich
|
}
|
506 |
ae2ea68c
|
Scott Ullrich
|
print("<select id='" . $pkga['fieldname'] . "' name=\"$fieldname\" $size $multiple>\n");
|
507 |
5d65350b
|
Ermal Lu?i
|
$ifaces = get_configured_interface_with_descr();
|
508 |
fbd14b13
|
Scott Ullrich
|
$additional_ifaces = $pkga['add_to_interfaces_selection'];
|
509 |
|
|
if (!empty($additional_ifaces))
|
510 |
|
|
$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
|
511 |
9996eff6
|
Scott Ullrich
|
if(is_array($value))
|
512 |
|
|
$values = $value;
|
513 |
|
|
else
|
514 |
|
|
$values = explode(',', $value);
|
515 |
fbd14b13
|
Scott Ullrich
|
foreach($ifaces as $ifname => $iface) {
|
516 |
|
|
$selected = (in_array($ifname, $values) ? 'selected' : '');
|
517 |
5d65350b
|
Ermal Lu?i
|
print("<option value=\"$ifname\" $selected>$iface</option>\n");
|
518 |
ab73789e
|
Scott Ullrich
|
}
|
519 |
fbd14b13
|
Scott Ullrich
|
print("</select>\n<br />" . fixup_string($pkga['description']) . "\n");
|
520 |
3eaeb703
|
Scott Ullrich
|
} else if($pkga['type'] == "radio") {
|
521 |
ae2ea68c
|
Scott Ullrich
|
echo "<input type='radio' id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
|
522 |
eec70f21
|
Scott Ullrich
|
} else if($pkga['type'] == "rowhelper") {
|
523 |
|
|
?>
|
524 |
|
|
<script type="text/javascript" language='javascript'>
|
525 |
|
|
<!--
|
526 |
|
|
<?php
|
527 |
|
|
$rowcounter = 0;
|
528 |
|
|
$fieldcounter = 0;
|
529 |
|
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
530 |
|
|
echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
|
531 |
|
|
echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
|
532 |
|
|
$fieldcounter++;
|
533 |
|
|
}
|
534 |
|
|
?>
|
535 |
|
|
-->
|
536 |
|
|
</script>
|
537 |
|
|
<table name="maintable" id="maintable">
|
538 |
b6e87566
|
Scott Ullrich
|
<tr>
|
539 |
eec70f21
|
Scott Ullrich
|
<?php
|
540 |
31d27c6c
|
Scott Ullrich
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
541 |
d51f86e0
|
Scott Ullrich
|
echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
|
542 |
31d27c6c
|
Scott Ullrich
|
}
|
543 |
b6e87566
|
Scott Ullrich
|
echo "</tr>";
|
544 |
|
|
|
545 |
eec70f21
|
Scott Ullrich
|
echo "<tr>";
|
546 |
|
|
// XXX: traverse saved fields, add back needed rows.
|
547 |
|
|
echo "</tr>";
|
548 |
0e730fee
|
Scott Ullrich
|
|
549 |
31d27c6c
|
Scott Ullrich
|
echo "<tr>\n";
|
550 |
|
|
$rowcounter = 0;
|
551 |
|
|
$trc = 0;
|
552 |
|
|
if(isset($a_pkg[$id]['row'])) {
|
553 |
|
|
foreach($a_pkg[$id]['row'] as $row) {
|
554 |
|
|
/*
|
555 |
|
|
* loop through saved data for record if it exists, populating rowhelper
|
556 |
bb940538
|
Scott Ullrich
|
*/
|
557 |
31d27c6c
|
Scott Ullrich
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
558 |
|
|
if($rowhelper['value'] <> "") $value = $rowhelper['value'];
|
559 |
|
|
$fieldname = $rowhelper['fieldname'];
|
560 |
|
|
// if user is editing a record, load in the data.
|
561 |
bb940538
|
Scott Ullrich
|
if (isset($id) && $a_pkg[$id]) {
|
562 |
7db8ff99
|
Colin Smith
|
$value = $row[$fieldname];
|
563 |
bb940538
|
Scott Ullrich
|
}
|
564 |
31d27c6c
|
Scott Ullrich
|
$options = "";
|
565 |
|
|
$type = $rowhelper['type'];
|
566 |
|
|
$fieldname = $rowhelper['fieldname'];
|
567 |
e54626e2
|
Ermal Lu?i
|
if($type == "option")
|
568 |
|
|
$options = &$rowhelper['options']['option'];
|
569 |
7e542bd1
|
Scott Ullrich
|
if($rowhelper['size'])
|
570 |
4c09b655
|
Scott Ullrich
|
$size = $rowhelper['size'];
|
571 |
e54626e2
|
Ermal Lu?i
|
else if ($pkga['size'])
|
572 |
|
|
$size = $pkga['size'];
|
573 |
4c09b655
|
Scott Ullrich
|
else
|
574 |
|
|
$size = "8";
|
575 |
e70e0b76
|
Scott Ullrich
|
display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
|
576 |
bb940538
|
Scott Ullrich
|
// javascript helpers for row_helper_dynamic.js
|
577 |
|
|
echo "</td>\n";
|
578 |
|
|
echo "<script language=\"JavaScript\">\n";
|
579 |
|
|
echo "<!--\n";
|
580 |
|
|
echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
|
581 |
|
|
echo "-->\n";
|
582 |
|
|
echo "</script>\n";
|
583 |
|
|
$text = "";
|
584 |
|
|
$trc++;
|
585 |
eec70f21
|
Scott Ullrich
|
}
|
586 |
bb940538
|
Scott Ullrich
|
|
587 |
31d27c6c
|
Scott Ullrich
|
$rowcounter++;
|
588 |
|
|
echo "<td>";
|
589 |
b91540da
|
Scott Ullrich
|
echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
|
590 |
eec70f21
|
Scott Ullrich
|
echo "</td>\n";
|
591 |
31d27c6c
|
Scott Ullrich
|
echo "</tr>\n";
|
592 |
|
|
}
|
593 |
|
|
}
|
594 |
|
|
if($trc == 0) {
|
595 |
|
|
/*
|
596 |
|
|
* no records loaded.
|
597 |
|
|
* just show a generic line non-populated with saved data
|
598 |
|
|
*/
|
599 |
|
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
600 |
|
|
if($rowhelper['value'] <> "") $value = $rowhelper['value'];
|
601 |
bb940538
|
Scott Ullrich
|
$fieldname = $rowhelper['fieldname'];
|
602 |
31d27c6c
|
Scott Ullrich
|
$options = "";
|
603 |
|
|
$type = $rowhelper['type'];
|
604 |
|
|
$fieldname = $rowhelper['fieldname'];
|
605 |
|
|
if($type == "option") $options = &$rowhelper['options']['option'];
|
606 |
e54626e2
|
Ermal Lu?i
|
if($rowhelper['size'] <> "")
|
607 |
|
|
$size = $rowhelper['size'];
|
608 |
|
|
else if ($pkga['size'])
|
609 |
|
|
$size = $pkga['size'];
|
610 |
|
|
else
|
611 |
|
|
$size = 8;
|
612 |
e70e0b76
|
Scott Ullrich
|
display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
|
613 |
bb940538
|
Scott Ullrich
|
// javascript helpers for row_helper_dynamic.js
|
614 |
|
|
echo "</td>\n";
|
615 |
|
|
echo "<script language=\"JavaScript\">\n";
|
616 |
|
|
echo "<!--\n";
|
617 |
|
|
echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
|
618 |
|
|
echo "-->\n";
|
619 |
|
|
echo "</script>\n";
|
620 |
|
|
$text = "";
|
621 |
eec70f21
|
Scott Ullrich
|
$trc++;
|
622 |
|
|
}
|
623 |
bb940538
|
Scott Ullrich
|
|
624 |
|
|
$rowcounter++;
|
625 |
e54626e2
|
Ermal Lu?i
|
echo "<td>";
|
626 |
|
|
echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
|
627 |
|
|
echo "</td>\n";
|
628 |
|
|
echo "</tr>\n";
|
629 |
eec70f21
|
Scott Ullrich
|
}
|
630 |
|
|
?>
|
631 |
0e730fee
|
Scott Ullrich
|
|
632 |
03664f64
|
Scott Ullrich
|
<tbody></tbody>
|
633 |
eec70f21
|
Scott Ullrich
|
</table>
|
634 |
0e730fee
|
Scott Ullrich
|
|
635 |
e54626e2
|
Ermal Lu?i
|
<?php if ($pkga['size']): ?>
|
636 |
|
|
<br><a onClick="javascript:addRowTo('maintable', <?=$pkga['size'];?>); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
|
637 |
|
|
<?php else: ?>
|
638 |
|
|
<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
|
639 |
|
|
<?php endif; ?>
|
640 |
eec70f21
|
Scott Ullrich
|
<script language="JavaScript">
|
641 |
|
|
<!--
|
642 |
|
|
field_counter_js = <?= $fieldcounter ?>;
|
643 |
|
|
rows = <?= $rowcounter ?>;
|
644 |
|
|
totalrows = <?php echo $rowcounter; ?>;
|
645 |
|
|
loaded = <?php echo $rowcounter; ?>;
|
646 |
e02a6839
|
Scott Ullrich
|
//typesel_change();
|
647 |
eec70f21
|
Scott Ullrich
|
//-->
|
648 |
|
|
</script>
|
649 |
|
|
|
650 |
|
|
<?php
|
651 |
d47013e1
|
Scott Ullrich
|
}
|
652 |
3eaeb703
|
Scott Ullrich
|
if($pkga['typehint']) echo " " . $pkga['typehint'];
|
653 |
facd08f9
|
Scott Ullrich
|
?>
|
654 |
|
|
|
655 |
d47013e1
|
Scott Ullrich
|
<?php
|
656 |
facd08f9
|
Scott Ullrich
|
if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
|
657 |
d47013e1
|
Scott Ullrich
|
$i++;
|
658 |
|
|
}
|
659 |
|
|
?>
|
660 |
b6e87566
|
Scott Ullrich
|
<tr>
|
661 |
|
|
<td> </td>
|
662 |
|
|
</tr>
|
663 |
d47013e1
|
Scott Ullrich
|
<tr>
|
664 |
|
|
<td width="22%" valign="top"> </td>
|
665 |
|
|
<td width="78%">
|
666 |
7c172009
|
Scott Ullrich
|
<?php
|
667 |
|
|
if($pkg['note'] != "")
|
668 |
b91540da
|
Scott Ullrich
|
print("<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>");
|
669 |
|
|
//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
|
670 |
7c172009
|
Scott Ullrich
|
print("<input name=\"id\" type=\"hidden\" value=\"$id\">");
|
671 |
|
|
?>
|
672 |
|
|
<input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
|
673 |
b91540da
|
Scott Ullrich
|
<?php if (!$only_edit): ?>
|
674 |
457106da
|
Renato Botelho
|
<input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
|
675 |
b91540da
|
Scott Ullrich
|
<?php endif; ?>
|
676 |
d47013e1
|
Scott Ullrich
|
</td>
|
677 |
|
|
</tr>
|
678 |
|
|
</table>
|
679 |
f4cb26b7
|
Colin Smith
|
</div></tr></td></table>
|
680 |
7c172009
|
Scott Ullrich
|
</form>
|
681 |
7c061036
|
Scott Ullrich
|
|
682 |
7c172009
|
Scott Ullrich
|
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
|
683 |
95736b54
|
Scott Ullrich
|
|
684 |
d47013e1
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
685 |
|
|
</body>
|
686 |
|
|
</html>
|
687 |
|
|
|
688 |
31d27c6c
|
Scott Ullrich
|
<?php
|
689 |
|
|
/*
|
690 |
|
|
* ROW Helpers function
|
691 |
|
|
*/
|
692 |
e70e0b76
|
Scott Ullrich
|
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
|
693 |
db3829e1
|
Scott Ullrich
|
global $text, $config;
|
694 |
31d27c6c
|
Scott Ullrich
|
echo "<td>\n";
|
695 |
|
|
if($type == "input") {
|
696 |
ae2ea68c
|
Scott Ullrich
|
echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' id='" . $fieldname . $trc . "' value='" . $value . "'>\n";
|
697 |
855cab21
|
Scott Ullrich
|
} else if($type == "checkbox") {
|
698 |
|
|
if($value)
|
699 |
ae2ea68c
|
Scott Ullrich
|
echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON' CHECKED>\n";
|
700 |
855cab21
|
Scott Ullrich
|
else
|
701 |
ae2ea68c
|
Scott Ullrich
|
echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON'>\n";
|
702 |
31d27c6c
|
Scott Ullrich
|
} else if($type == "password") {
|
703 |
e4f8f7d2
|
Bill Marquette
|
echo "<input size='" . $size . "' type='password' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' class='formfld pwd' value='" . $value . "'>\n";
|
704 |
31d27c6c
|
Scott Ullrich
|
} else if($type == "textarea") {
|
705 |
e4f8f7d2
|
Bill Marquette
|
echo "<textarea rows='2' cols='12' id='" . $fieldname . $trc . "' class='formfld unknown' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
|
706 |
31d27c6c
|
Scott Ullrich
|
} else if($type == "select") {
|
707 |
ae2ea68c
|
Scott Ullrich
|
echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
|
708 |
31d27c6c
|
Scott Ullrich
|
foreach($rowhelper['options']['option'] as $rowopt) {
|
709 |
|
|
$selected = "";
|
710 |
|
|
if($rowopt['value'] == $value) $selected = " SELECTED";
|
711 |
|
|
$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
|
712 |
|
|
echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
|
713 |
|
|
}
|
714 |
|
|
echo "</select>\n";
|
715 |
db3829e1
|
Scott Ullrich
|
} else if($type == "select_source") {
|
716 |
|
|
echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
|
717 |
|
|
$source_url = $rowhelper['source'];
|
718 |
|
|
eval("\$pkg_source_txt = &$source_url;");
|
719 |
|
|
foreach($pkg_source_txt as $opt) {
|
720 |
|
|
$selected = "";
|
721 |
|
|
if($rowhelper['source_name']) {
|
722 |
|
|
$source_name = $opt[$rowhelper['source_name']];
|
723 |
|
|
} else {
|
724 |
|
|
$source_name = $opt[$rowhelper['name']];
|
725 |
|
|
}
|
726 |
|
|
if($rowhelper['source_value']) {
|
727 |
|
|
$source_value = $opt[$rowhelper['source_value']];
|
728 |
|
|
} else {
|
729 |
|
|
$source_value = $opt[$rowhelper['value']];
|
730 |
|
|
}
|
731 |
9605d06f
|
Scott Ullrich
|
if($source_value == $value)
|
732 |
db3829e1
|
Scott Ullrich
|
$selected = " SELECTED";
|
733 |
|
|
$text .= "<option value='" . $source_value . "'" . $selected . ">" . $source_name . "</option>";
|
734 |
|
|
echo "<option value='" . $source_value . "'" . $selected . ">" . $source_name . "</option>\n";
|
735 |
|
|
}
|
736 |
|
|
echo "</select>\n";
|
737 |
31d27c6c
|
Scott Ullrich
|
}
|
738 |
|
|
}
|
739 |
|
|
|
740 |
d51f86e0
|
Scott Ullrich
|
function fixup_string($string) {
|
741 |
d2133701
|
Scott Ullrich
|
global $config;
|
742 |
d51f86e0
|
Scott Ullrich
|
// fixup #1: $myurl -> http[s]://ip_address:port/
|
743 |
|
|
$https = "";
|
744 |
|
|
$port = $config['system']['webguiport'];
|
745 |
63637de9
|
Bill Marquette
|
if($port <> "443" and $port <> "80")
|
746 |
|
|
$urlport = ":" . $port;
|
747 |
|
|
else
|
748 |
|
|
$urlport = "";
|
749 |
3c616886
|
Scott Ullrich
|
|
750 |
58362f9d
|
jim-p
|
if($config['system']['webgui']['protocol'] == "https") $https = "s";
|
751 |
63637de9
|
Bill Marquette
|
$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
|
752 |
d51f86e0
|
Scott Ullrich
|
$newstring = str_replace("\$myurl", $myurl, $string);
|
753 |
d2133701
|
Scott Ullrich
|
$string = $newstring;
|
754 |
|
|
// fixup #2: $wanip
|
755 |
85a5da13
|
Ermal Luçi
|
$curwanip = get_interface_ip();
|
756 |
d2133701
|
Scott Ullrich
|
$newstring = str_replace("\$wanip", $curwanip, $string);
|
757 |
|
|
$string = $newstring;
|
758 |
|
|
// fixup #3: $lanip
|
759 |
|
|
$lancfg = $config['interfaces']['lan'];
|
760 |
|
|
$lanip = $lancfg['ipaddr'];
|
761 |
|
|
$newstring = str_replace("\$lanip", $lanip, $string);
|
762 |
|
|
$string = $newstring;
|
763 |
|
|
// fixup #4: fix'r'up here.
|
764 |
d51f86e0
|
Scott Ullrich
|
return $newstring;
|
765 |
|
|
}
|
766 |
|
|
|
767 |
dcbe6f52
|
Scott Ullrich
|
/*
|
768 |
|
|
* Parse templates if they are defined
|
769 |
|
|
*/
|
770 |
|
|
function parse_package_templates() {
|
771 |
|
|
global $pkg, $config;
|
772 |
767a716e
|
Scott Ullrich
|
$rows = 0;
|
773 |
dcbe6f52
|
Scott Ullrich
|
if($pkg['templates']['template'] <> "")
|
774 |
|
|
foreach($pkg['templates']['template'] as $pkg_template_row) {
|
775 |
|
|
$filename = $pkg_template_row['filename'];
|
776 |
|
|
$template_text = $pkg_template_row['templatecontents'];
|
777 |
767a716e
|
Scott Ullrich
|
$firstfield = "";
|
778 |
dcbe6f52
|
Scott Ullrich
|
/* calculate total row helpers count */
|
779 |
|
|
foreach ($pkg['fields']['field'] as $fields) {
|
780 |
|
|
if($fields['type'] == "rowhelper") {
|
781 |
|
|
// save rowhelper items.
|
782 |
|
|
$row_helper_total_rows = 0;
|
783 |
|
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
784 |
|
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
785 |
|
|
if($firstfield == "") {
|
786 |
|
|
$firstfield = $rowhelperfield['fieldname'];
|
787 |
|
|
} else {
|
788 |
|
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
789 |
|
|
}
|
790 |
|
|
$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
|
791 |
767a716e
|
Scott Ullrich
|
$value = "";
|
792 |
dcbe6f52
|
Scott Ullrich
|
eval($comd);
|
793 |
|
|
if($value <> "") {
|
794 |
|
|
//$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
|
795 |
|
|
} else {
|
796 |
|
|
$row_helper_total_rows = $rows;
|
797 |
|
|
break;
|
798 |
|
|
}
|
799 |
|
|
}
|
800 |
|
|
}
|
801 |
|
|
}
|
802 |
|
|
}
|
803 |
|
|
|
804 |
|
|
/* replace $domain_total_rows with total rows */
|
805 |
|
|
$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
|
806 |
|
|
|
807 |
|
|
/* change fields defined as fieldname_fieldvalue to their value */
|
808 |
|
|
foreach ($pkg['fields']['field'] as $fields) {
|
809 |
|
|
if($fields['type'] == "rowhelper") {
|
810 |
|
|
// save rowhelper items.
|
811 |
|
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
812 |
|
|
$row_helper_data = "";
|
813 |
1be00369
|
Scott Ullrich
|
$isfirst = 0;
|
814 |
dcbe6f52
|
Scott Ullrich
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
815 |
|
|
if($firstfield == "") {
|
816 |
|
|
$firstfield = $rowhelperfield['fieldname'];
|
817 |
|
|
} else {
|
818 |
|
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
819 |
|
|
}
|
820 |
|
|
$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
|
821 |
|
|
eval($comd);
|
822 |
|
|
if($value <> "") {
|
823 |
1be00369
|
Scott Ullrich
|
if($isfirst == 1) $row_helper_data .= " " ;
|
824 |
|
|
$row_helper_data .= $value;
|
825 |
|
|
$isfirst = 1;
|
826 |
dcbe6f52
|
Scott Ullrich
|
}
|
827 |
767a716e
|
Scott Ullrich
|
$sep = "";
|
828 |
dcbe6f52
|
Scott Ullrich
|
ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
|
829 |
|
|
foreach ($sep as $se) $seperator = $se;
|
830 |
|
|
if($seperator <> "") {
|
831 |
|
|
$row_helper_data = ereg_replace(" ", $seperator, $row_helper_data);
|
832 |
|
|
$template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
|
833 |
|
|
}
|
834 |
|
|
$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
|
835 |
|
|
}
|
836 |
|
|
}
|
837 |
|
|
} else {
|
838 |
|
|
$fieldname = $fields['fieldname'];
|
839 |
|
|
$fieldvalue = $_POST[$fieldname];
|
840 |
|
|
$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
|
841 |
|
|
}
|
842 |
|
|
}
|
843 |
|
|
|
844 |
|
|
/* replace cr's */
|
845 |
|
|
$template_text = str_replace("\\n", "\n", $template_text);
|
846 |
|
|
|
847 |
|
|
/* write out new template file */
|
848 |
|
|
$fout = fopen($filename,"w");
|
849 |
|
|
fwrite($fout, $template_text);
|
850 |
|
|
fclose($fout);
|
851 |
|
|
}
|
852 |
|
|
}
|
853 |
|
|
|
854 |
c8536f7d
|
Carlos Eduardo Ramos
|
?>
|