1 |
d47013e1
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
aaec5634
|
Renato Botelho
|
* pkg_edit.php
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
2a2396a6
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7 |
aaec5634
|
Renato Botelho
|
* All rights reserved.
|
8 |
|
|
*
|
9 |
|
|
* Redistribution and use in source and binary forms, with or without
|
10 |
|
|
* modification, are permitted provided that the following conditions are met:
|
11 |
|
|
*
|
12 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
* this list of conditions and the following disclaimer.
|
14 |
|
|
*
|
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
* notice, this list of conditions and the following disclaimer in
|
17 |
|
|
* the documentation and/or other materials provided with the
|
18 |
|
|
* distribution.
|
19 |
|
|
*
|
20 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
21 |
|
|
* must display the following acknowledgment:
|
22 |
|
|
* "This product includes software developed by the pfSense Project
|
23 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
24 |
|
|
*
|
25 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26 |
|
|
* endorse or promote products derived from this software without
|
27 |
|
|
* prior written permission. For written permission, please contact
|
28 |
|
|
* coreteam@pfsense.org.
|
29 |
|
|
*
|
30 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
31 |
|
|
* nor may "pfSense" appear in their names without prior written
|
32 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
33 |
|
|
*
|
34 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
35 |
|
|
* acknowledgment:
|
36 |
|
|
*
|
37 |
|
|
* "This product includes software developed by the pfSense Project
|
38 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39 |
|
|
*
|
40 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52 |
23f6cdd7
|
Stephen Beaver
|
*/
|
53 |
d47013e1
|
Scott Ullrich
|
|
54 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
55 |
|
|
##|*IDENT=page-package-edit
|
56 |
5230f468
|
jim-p
|
##|*NAME=Package: Edit
|
57 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Package: Edit' page.
|
58 |
|
|
##|*MATCH=pkg_edit.php*
|
59 |
|
|
##|-PRIV
|
60 |
|
|
|
61 |
0089af7c
|
Scott Ullrich
|
ini_set('max_execution_time', '0');
|
62 |
|
|
|
63 |
aceaf18c
|
Phil Davis
|
require_once("guiconfig.inc");
|
64 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
65 |
|
|
require_once("filter.inc");
|
66 |
|
|
require_once("shaper.inc");
|
67 |
f8e335a3
|
Scott Ullrich
|
require_once("pkg-utils.inc");
|
68 |
d47013e1
|
Scott Ullrich
|
|
69 |
14db714e
|
Scott Ullrich
|
/* dummy stubs needed by some code that was MFC'd */
|
70 |
f8ac4407
|
Phil Davis
|
function pfSenseHeader($location) {
|
71 |
|
|
header("Location: " . $location);
|
72 |
|
|
}
|
73 |
14db714e
|
Scott Ullrich
|
|
74 |
d8c1a6c5
|
Scott Ullrich
|
$xml = htmlspecialchars($_GET['xml']);
|
75 |
f8ac4407
|
Phil Davis
|
if ($_POST['xml']) {
|
76 |
|
|
$xml = htmlspecialchars($_POST['xml']);
|
77 |
|
|
}
|
78 |
d47013e1
|
Scott Ullrich
|
|
79 |
bef9f697
|
Renato Botelho
|
$xml_fullpath = realpath('/usr/local/pkg/' . $xml);
|
80 |
69eb2e29
|
Renato Botelho
|
|
81 |
f5dbca0d
|
Stephen Beaver
|
if ($xml == "" || $xml_fullpath === false || substr($xml_fullpath, 0, strlen('/usr/local/pkg/')) != '/usr/local/pkg/') {
|
82 |
84320769
|
k-paulius
|
$pgtitle = array(gettext("Package"), gettext("Editor"));
|
83 |
f5dbca0d
|
Stephen Beaver
|
include("head.inc");
|
84 |
8545adde
|
k-paulius
|
print_info_box(gettext("No valid package defined."), 'danger', false);
|
85 |
f5dbca0d
|
Stephen Beaver
|
include("foot.inc");
|
86 |
f8ac4407
|
Phil Davis
|
die;
|
87 |
d47013e1
|
Scott Ullrich
|
} else {
|
88 |
f8ac4407
|
Phil Davis
|
$pkg = parse_xml_config_pkg($xml_fullpath, "packagegui");
|
89 |
d47013e1
|
Scott Ullrich
|
}
|
90 |
7c172009
|
Scott Ullrich
|
|
91 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['include_file'] != "") {
|
92 |
7c172009
|
Scott Ullrich
|
require_once($pkg['include_file']);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
f8ac4407
|
Phil Davis
|
if (!isset($pkg['adddeleteeditpagefields'])) {
|
96 |
b91540da
|
Scott Ullrich
|
$only_edit = true;
|
97 |
f8ac4407
|
Phil Davis
|
} else {
|
98 |
b91540da
|
Scott Ullrich
|
$only_edit = false;
|
99 |
f8ac4407
|
Phil Davis
|
}
|
100 |
b91540da
|
Scott Ullrich
|
|
101 |
da7bf505
|
Scott Ullrich
|
$id = $_GET['id'];
|
102 |
f8ac4407
|
Phil Davis
|
if (isset($_POST['id'])) {
|
103 |
d8c1a6c5
|
Scott Ullrich
|
$id = htmlspecialchars($_POST['id']);
|
104 |
f8ac4407
|
Phil Davis
|
}
|
105 |
98bcf1f8
|
Scott Ullrich
|
|
106 |
23f6cdd7
|
Stephen Beaver
|
// Not posting? Then user is editing a record. There must be a valid id
|
107 |
916b74c6
|
Scott Ullrich
|
// when editing a record.
|
108 |
f8ac4407
|
Phil Davis
|
if (!$id && !$_POST) {
|
109 |
916b74c6
|
Scott Ullrich
|
$id = "0";
|
110 |
f8ac4407
|
Phil Davis
|
}
|
111 |
5a61331a
|
jim-p
|
|
112 |
f8ac4407
|
Phil Davis
|
if (!is_numeric($id)) {
|
113 |
6f3d2063
|
Renato Botelho
|
header("Location: /");
|
114 |
5a61331a
|
jim-p
|
exit;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['custom_php_global_functions'] != "") {
|
118 |
f8ac4407
|
Phil Davis
|
eval($pkg['custom_php_global_functions']);
|
119 |
|
|
}
|
120 |
529ffadb
|
Bill Marquette
|
|
121 |
31d27c6c
|
Scott Ullrich
|
// grab the installedpackages->package_name section.
|
122 |
f8ac4407
|
Phil Davis
|
if ($config['installedpackages'] && !is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'])) {
|
123 |
7db8ff99
|
Colin Smith
|
$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
|
124 |
f8ac4407
|
Phil Davis
|
}
|
125 |
da7bf505
|
Scott Ullrich
|
|
126 |
a2a7f74d
|
jim-p
|
// If the first entry in the array is an empty <config/> tag, kill it.
|
127 |
0f649c97
|
Phil Davis
|
if ($config['installedpackages'] &&
|
128 |
|
|
(count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0) &&
|
129 |
|
|
($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0] == "")) {
|
130 |
a2a7f74d
|
jim-p
|
array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
|
131 |
f8ac4407
|
Phil Davis
|
}
|
132 |
a2a7f74d
|
jim-p
|
|
133 |
7db8ff99
|
Colin Smith
|
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
134 |
da7bf505
|
Scott Ullrich
|
|
135 |
23f6cdd7
|
Stephen Beaver
|
if ($_GET['savemsg'] != "") {
|
136 |
d8c1a6c5
|
Scott Ullrich
|
$savemsg = htmlspecialchars($_GET['savemsg']);
|
137 |
f8ac4407
|
Phil Davis
|
}
|
138 |
f9a91638
|
Scott Ullrich
|
|
139 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['custom_php_command_before_form'] != "") {
|
140 |
194b4e0a
|
Colin Smith
|
eval($pkg['custom_php_command_before_form']);
|
141 |
f8ac4407
|
Phil Davis
|
}
|
142 |
f9a91638
|
Scott Ullrich
|
|
143 |
6483da5d
|
Scott Ullrich
|
if ($_POST) {
|
144 |
2c51f293
|
jim-p
|
$rows = 0;
|
145 |
|
|
|
146 |
|
|
$input_errors = array();
|
147 |
|
|
$reqfields = array();
|
148 |
|
|
$reqfieldsn = array();
|
149 |
|
|
foreach ($pkg['fields']['field'] as $field) {
|
150 |
86f28390
|
doktornotor
|
if (isset($field['required'])) {
|
151 |
f8ac4407
|
Phil Davis
|
if ($field['fieldname']) {
|
152 |
2c51f293
|
jim-p
|
$reqfields[] = $field['fieldname'];
|
153 |
f8ac4407
|
Phil Davis
|
}
|
154 |
|
|
if ($field['fielddescr']) {
|
155 |
2c51f293
|
jim-p
|
$reqfieldsn[] = $field['fielddescr'];
|
156 |
f8ac4407
|
Phil Davis
|
}
|
157 |
2c51f293
|
jim-p
|
}
|
158 |
|
|
}
|
159 |
1e9b4611
|
Renato Botelho
|
do_input_validation($_POST, $reqfields, $reqfieldsn, $input_errors);
|
160 |
2c51f293
|
jim-p
|
|
161 |
f8ac4407
|
Phil Davis
|
if ($pkg['custom_php_validation_command']) {
|
162 |
2c51f293
|
jim-p
|
eval($pkg['custom_php_validation_command']);
|
163 |
f8ac4407
|
Phil Davis
|
}
|
164 |
2c51f293
|
jim-p
|
|
165 |
f8ac4407
|
Phil Davis
|
if ($_POST['act'] == "del") {
|
166 |
|
|
if ($pkg['custom_delete_php_command']) {
|
167 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['custom_php_command_before_form'] != "") {
|
168 |
f8ac4407
|
Phil Davis
|
eval($pkg['custom_php_command_before_form']);
|
169 |
|
|
}
|
170 |
|
|
eval($pkg['custom_delete_php_command']);
|
171 |
b3235baa
|
Scott Ullrich
|
}
|
172 |
7c172009
|
Scott Ullrich
|
write_config($pkg['delete_string']);
|
173 |
facd08f9
|
Scott Ullrich
|
// resync the configuration file code if defined.
|
174 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['custom_php_resync_config_command'] != "") {
|
175 |
|
|
if ($pkg['custom_php_command_before_form'] != "") {
|
176 |
86f3fc00
|
Scott Ullrich
|
eval($pkg['custom_php_command_before_form']);
|
177 |
f8ac4407
|
Phil Davis
|
}
|
178 |
86f3fc00
|
Scott Ullrich
|
eval($pkg['custom_php_resync_config_command']);
|
179 |
facd08f9
|
Scott Ullrich
|
}
|
180 |
b3235baa
|
Scott Ullrich
|
} else {
|
181 |
f8ac4407
|
Phil Davis
|
if (!$input_errors && $pkg['custom_add_php_command']) {
|
182 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['donotsave'] != "" or $pkg['preoutput'] != "") {
|
183 |
|
|
include("head.inc");
|
184 |
3eaeb703
|
Scott Ullrich
|
}
|
185 |
23f6cdd7
|
Stephen Beaver
|
|
186 |
f8ac4407
|
Phil Davis
|
if ($pkg['preoutput']) {
|
187 |
|
|
echo "<pre>";
|
188 |
|
|
}
|
189 |
3eaeb703
|
Scott Ullrich
|
eval($pkg['custom_add_php_command']);
|
190 |
f8ac4407
|
Phil Davis
|
if ($pkg['preoutput']) {
|
191 |
|
|
echo "</pre>";
|
192 |
|
|
}
|
193 |
b3235baa
|
Scott Ullrich
|
}
|
194 |
6483da5d
|
Scott Ullrich
|
}
|
195 |
e3c4b6b7
|
Scott Ullrich
|
|
196 |
eec70f21
|
Scott Ullrich
|
// donotsave is enabled. lets simply exit.
|
197 |
f8ac4407
|
Phil Davis
|
if (empty($pkg['donotsave'])) {
|
198 |
2c51f293
|
jim-p
|
|
199 |
f8ac4407
|
Phil Davis
|
// store values in xml configuration file.
|
200 |
2c51f293
|
jim-p
|
if (!$input_errors) {
|
201 |
|
|
$pkgarr = array();
|
202 |
|
|
foreach ($pkg['fields']['field'] as $fields) {
|
203 |
f8ac4407
|
Phil Davis
|
switch ($fields['type']) {
|
204 |
2c51f293
|
jim-p
|
case "rowhelper":
|
205 |
|
|
// save rowhelper items.
|
206 |
01fb4340
|
Steve Beaver
|
$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
|
207 |
|
|
// $rowhelpername="row";
|
208 |
f8ac4407
|
Phil Davis
|
foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
209 |
|
|
foreach ($_POST as $key => $value) {
|
210 |
29fc0334
|
k-paulius
|
$matches = array();
|
211 |
6c07db48
|
Phil Davis
|
if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
|
212 |
|
|
$pkgarr[$rowhelpername][$matches[1]][$rowhelperfield['fieldname']] = $value;
|
213 |
|
|
}
|
214 |
2c51f293
|
jim-p
|
}
|
215 |
f8ac4407
|
Phil Davis
|
}
|
216 |
2c51f293
|
jim-p
|
break;
|
217 |
|
|
default:
|
218 |
6c07db48
|
Phil Davis
|
$fieldname = $fields['fieldname'];
|
219 |
2c51f293
|
jim-p
|
if ($fieldname == "interface_array") {
|
220 |
|
|
$fieldvalue = $_POST[$fieldname];
|
221 |
|
|
} elseif (is_array($_POST[$fieldname])) {
|
222 |
|
|
$fieldvalue = implode(',', $_POST[$fieldname]);
|
223 |
|
|
} else {
|
224 |
|
|
$fieldvalue = trim($_POST[$fieldname]);
|
225 |
f8ac4407
|
Phil Davis
|
if ($fields['encoding'] == 'base64') {
|
226 |
2c51f293
|
jim-p
|
$fieldvalue = base64_encode($fieldvalue);
|
227 |
f8ac4407
|
Phil Davis
|
}
|
228 |
eec70f21
|
Scott Ullrich
|
}
|
229 |
f8ac4407
|
Phil Davis
|
if ($fieldname) {
|
230 |
2c51f293
|
jim-p
|
$pkgarr[$fieldname] = $fieldvalue;
|
231 |
f8ac4407
|
Phil Davis
|
}
|
232 |
eec70f21
|
Scott Ullrich
|
}
|
233 |
2c51f293
|
jim-p
|
}
|
234 |
0e730fee
|
Scott Ullrich
|
|
235 |
f8ac4407
|
Phil Davis
|
if (isset($id) && $a_pkg[$id]) {
|
236 |
2c51f293
|
jim-p
|
$a_pkg[$id] = $pkgarr;
|
237 |
f8ac4407
|
Phil Davis
|
} else {
|
238 |
2c51f293
|
jim-p
|
$a_pkg[] = $pkgarr;
|
239 |
f8ac4407
|
Phil Davis
|
}
|
240 |
0e730fee
|
Scott Ullrich
|
|
241 |
2c51f293
|
jim-p
|
write_config($pkg['addedit_string']);
|
242 |
|
|
// late running code
|
243 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['custom_add_php_command_late'] != "") {
|
244 |
f8ac4407
|
Phil Davis
|
eval($pkg['custom_add_php_command_late']);
|
245 |
2c51f293
|
jim-p
|
}
|
246 |
0e730fee
|
Scott Ullrich
|
|
247 |
f8ac4407
|
Phil Davis
|
if (isset($pkg['filter_rules_needed'])) {
|
248 |
2c51f293
|
jim-p
|
filter_configure();
|
249 |
f8ac4407
|
Phil Davis
|
}
|
250 |
a9b2e638
|
Ermal Lu?i
|
|
251 |
2c51f293
|
jim-p
|
// resync the configuration file code if defined.
|
252 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['custom_php_resync_config_command'] != "") {
|
253 |
f8ac4407
|
Phil Davis
|
eval($pkg['custom_php_resync_config_command']);
|
254 |
2c51f293
|
jim-p
|
}
|
255 |
facd08f9
|
Scott Ullrich
|
|
256 |
2c51f293
|
jim-p
|
parse_package_templates();
|
257 |
dcbe6f52
|
Scott Ullrich
|
|
258 |
2c51f293
|
jim-p
|
/* if start_command is defined, restart w/ this */
|
259 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['start_command'] != "") {
|
260 |
f8ac4407
|
Phil Davis
|
exec($pkg['start_command'] . ">/dev/null 2&>1");
|
261 |
|
|
}
|
262 |
a485a6f5
|
Scott Ullrich
|
|
263 |
2c51f293
|
jim-p
|
/* if restart_command is defined, restart w/ this */
|
264 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['restart_command'] != "") {
|
265 |
f8ac4407
|
Phil Davis
|
exec($pkg['restart_command'] . ">/dev/null 2&>1");
|
266 |
|
|
}
|
267 |
|
|
|
268 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['aftersaveredirect'] != "") {
|
269 |
f8ac4407
|
Phil Davis
|
pfSenseHeader($pkg['aftersaveredirect']);
|
270 |
|
|
} elseif (!$pkg['adddeleteeditpagefields']) {
|
271 |
71e8cdd6
|
NewEraCracker
|
pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
|
272 |
f8ac4407
|
Phil Davis
|
} elseif (!$pkg['preoutput']) {
|
273 |
|
|
pfSenseHeader("pkg.php?xml=" . $xml);
|
274 |
2c51f293
|
jim-p
|
}
|
275 |
|
|
exit;
|
276 |
|
|
} else {
|
277 |
|
|
$get_from_post = true;
|
278 |
dcbe6f52
|
Scott Ullrich
|
}
|
279 |
2c51f293
|
jim-p
|
} elseif (!$input_errors) {
|
280 |
0e730fee
|
Scott Ullrich
|
exit;
|
281 |
e11aa161
|
Warren Baker
|
}
|
282 |
da7bf505
|
Scott Ullrich
|
}
|
283 |
|
|
|
284 |
7c172009
|
Scott Ullrich
|
|
285 |
eb3743d8
|
Stephen Beaver
|
// Turn an embedded table into a bootstrap class table. This is for backward compatibility.
|
286 |
|
|
// We remove any table attributes in the XML and replace them with Bootstrap table classes
|
287 |
|
|
function bootstrapTable($text) {
|
288 |
|
|
$t = strpos($text, '<table') + strlen('<table'); // Find the <table tag
|
289 |
|
|
$c = strpos($text, '>', $t); // And its closing bracket
|
290 |
|
|
|
291 |
|
|
// Substitute everything inbetween with our new classes
|
292 |
0f649c97
|
Phil Davis
|
if ($t && $c && (($c - $t) < 200)) {
|
293 |
eb3743d8
|
Stephen Beaver
|
return(substr_replace($text, ' class="table table-striped table-hover table-condensed"', $t, ($c - $t)));
|
294 |
|
|
}
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
/*
|
298 |
|
|
* ROW helper function. Creates one element in the row from a PHP table by adding
|
299 |
|
|
* the specified element to $group
|
300 |
|
|
*/
|
301 |
36cefd8f
|
Stephen Beaver
|
function display_row($trc, $value, $fieldname, $type, $rowhelper, $description, $ewidth = null) {
|
302 |
0aa18e14
|
Marcello Coutinho
|
global $text, $group, $config;
|
303 |
eb3743d8
|
Stephen Beaver
|
|
304 |
|
|
switch ($type) {
|
305 |
|
|
case "input":
|
306 |
bd0d36bd
|
Stephen Beaver
|
$inpt = new Form_Input(
|
307 |
eb3743d8
|
Stephen Beaver
|
$fieldname . $trc,
|
308 |
|
|
null,
|
309 |
|
|
'text',
|
310 |
|
|
$value
|
311 |
bd0d36bd
|
Stephen Beaver
|
);
|
312 |
|
|
|
313 |
|
|
$inpt->setHelp($description);
|
314 |
|
|
|
315 |
36cefd8f
|
Stephen Beaver
|
if ($ewidth) {
|
316 |
|
|
$inpt->setWidth($ewidth);
|
317 |
bd0d36bd
|
Stephen Beaver
|
}
|
318 |
eb3743d8
|
Stephen Beaver
|
|
319 |
bd0d36bd
|
Stephen Beaver
|
$group->add($inpt);
|
320 |
eb3743d8
|
Stephen Beaver
|
break;
|
321 |
|
|
case "checkbox":
|
322 |
|
|
$group->add(new Form_Checkbox(
|
323 |
|
|
$fieldname . $trc,
|
324 |
|
|
null,
|
325 |
|
|
null,
|
326 |
|
|
$value,
|
327 |
|
|
'ON'
|
328 |
|
|
))->setHelp($description);
|
329 |
|
|
|
330 |
|
|
break;
|
331 |
|
|
case "password":
|
332 |
|
|
$group->add(new Form_Input(
|
333 |
|
|
$fieldname . $trc,
|
334 |
|
|
null,
|
335 |
|
|
'password',
|
336 |
|
|
$value
|
337 |
|
|
))->setHelp($description);
|
338 |
|
|
break;
|
339 |
|
|
case "textarea":
|
340 |
3478ac16
|
Stephen Beaver
|
$group->add(new Form_Textarea(
|
341 |
eb3743d8
|
Stephen Beaver
|
$fieldname . $trc,
|
342 |
|
|
null,
|
343 |
|
|
$value
|
344 |
|
|
))->setHelp($description);
|
345 |
|
|
|
346 |
|
|
break;
|
347 |
|
|
case "select":
|
348 |
|
|
$options = array();
|
349 |
|
|
foreach ($rowhelper['options']['option'] as $rowopt) {
|
350 |
|
|
$options[$rowopt['value']] = $rowopt['name'];
|
351 |
|
|
}
|
352 |
|
|
|
353 |
57fc02b1
|
Stephen Beaver
|
$grp = new Form_Select(
|
354 |
eb3743d8
|
Stephen Beaver
|
$fieldname . $trc,
|
355 |
|
|
null,
|
356 |
|
|
$value,
|
357 |
|
|
$options
|
358 |
57fc02b1
|
Stephen Beaver
|
);
|
359 |
|
|
|
360 |
|
|
$grp->setHelp($description);
|
361 |
|
|
|
362 |
bf7ee0e0
|
BBcan177
|
if ($ewidth) {
|
363 |
|
|
$grp->setWidth($ewidth);
|
364 |
57fc02b1
|
Stephen Beaver
|
}
|
365 |
|
|
|
366 |
|
|
$group->add($grp);
|
367 |
eb3743d8
|
Stephen Beaver
|
|
368 |
|
|
break;
|
369 |
|
|
case "interfaces_selection":
|
370 |
|
|
$size = ($size ? "size=\"{$size}\"" : '');
|
371 |
|
|
$multiple = '';
|
372 |
|
|
if (isset($rowhelper['multiple'])) {
|
373 |
c4b60a9a
|
Colin Fleming
|
$multiple = "multiple";
|
374 |
eb3743d8
|
Stephen Beaver
|
}
|
375 |
|
|
echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n";
|
376 |
|
|
$ifaces = get_configured_interface_with_descr();
|
377 |
|
|
$additional_ifaces = $rowhelper['add_to_interfaces_selection'];
|
378 |
|
|
if (!empty($additional_ifaces)) {
|
379 |
|
|
$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
if (is_array($value)) {
|
383 |
|
|
$values = $value;
|
384 |
|
|
} else {
|
385 |
|
|
$values = explode(',', $value);
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
$ifaces["lo0"] = "loopback";
|
389 |
|
|
$options = array();
|
390 |
|
|
$selected = array();
|
391 |
|
|
|
392 |
|
|
foreach ($ifaces as $ifname => $iface) {
|
393 |
|
|
$options[$ifname] = $iface;
|
394 |
|
|
|
395 |
0f649c97
|
Phil Davis
|
if (in_array($ifname, $values)) {
|
396 |
eb3743d8
|
Stephen Beaver
|
array_push($selected, $ifname);
|
397 |
|
|
}
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
$group->add(new Form_Select(
|
401 |
|
|
$fieldname . $trc,
|
402 |
|
|
null,
|
403 |
|
|
($multiple) ? $selected:$selected[0],
|
404 |
|
|
$options,
|
405 |
|
|
$multiple
|
406 |
|
|
))->setHelp($description);
|
407 |
|
|
|
408 |
|
|
//echo "</select>\n";
|
409 |
|
|
break;
|
410 |
|
|
case "select_source":
|
411 |
|
|
$options = array();
|
412 |
|
|
$selected = array();
|
413 |
|
|
|
414 |
|
|
if (isset($rowhelper['show_disable_value'])) {
|
415 |
|
|
$options[$rowhelper['show_disable_value']] = $rowhelper['show_disable_value'];
|
416 |
|
|
}
|
417 |
|
|
|
418 |
|
|
$source_url = $rowhelper['source'];
|
419 |
|
|
eval("\$pkg_source_txt = &$source_url;");
|
420 |
|
|
|
421 |
|
|
foreach ($pkg_source_txt as $opt) {
|
422 |
|
|
$source_name = ($rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]);
|
423 |
|
|
$source_value = ($rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]);
|
424 |
|
|
$options[$source_value] = $source_name;
|
425 |
|
|
|
426 |
0f649c97
|
Phil Davis
|
if ($source_value == $value) {
|
427 |
eb3743d8
|
Stephen Beaver
|
array_push($selected, $value);
|
428 |
|
|
}
|
429 |
|
|
}
|
430 |
|
|
|
431 |
|
|
$group->add(new Form_Select(
|
432 |
|
|
$fieldname . $trc,
|
433 |
|
|
null,
|
434 |
|
|
($multiple) ? $selected:$selected[0],
|
435 |
|
|
$options,
|
436 |
|
|
$multiple
|
437 |
|
|
))->setHelp($description);
|
438 |
|
|
|
439 |
|
|
break;
|
440 |
|
|
}
|
441 |
|
|
}
|
442 |
|
|
|
443 |
|
|
function fixup_string($string) {
|
444 |
|
|
global $config;
|
445 |
|
|
// fixup #1: $myurl -> http[s]://ip_address:port/
|
446 |
|
|
$https = "";
|
447 |
|
|
$port = $config['system']['webguiport'];
|
448 |
|
|
if ($port != "443" and $port != "80") {
|
449 |
|
|
$urlport = ":" . $port;
|
450 |
|
|
} else {
|
451 |
|
|
$urlport = "";
|
452 |
|
|
}
|
453 |
|
|
|
454 |
|
|
if ($config['system']['webgui']['protocol'] == "https") {
|
455 |
|
|
$https = "s";
|
456 |
|
|
}
|
457 |
|
|
$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
|
458 |
|
|
$newstring = str_replace("\$myurl", $myurl, $string);
|
459 |
|
|
$string = $newstring;
|
460 |
|
|
// fixup #2: $wanip
|
461 |
|
|
$curwanip = get_interface_ip();
|
462 |
|
|
$newstring = str_replace("\$wanip", $curwanip, $string);
|
463 |
|
|
$string = $newstring;
|
464 |
|
|
// fixup #3: $lanip
|
465 |
|
|
$lancfg = $config['interfaces']['lan'];
|
466 |
|
|
$lanip = $lancfg['ipaddr'];
|
467 |
|
|
$newstring = str_replace("\$lanip", $lanip, $string);
|
468 |
|
|
$string = $newstring;
|
469 |
|
|
// fixup #4: fix'r'up here.
|
470 |
|
|
return $newstring;
|
471 |
|
|
}
|
472 |
|
|
|
473 |
|
|
/*
|
474 |
|
|
* Parse templates if they are defined
|
475 |
|
|
*/
|
476 |
|
|
function parse_package_templates() {
|
477 |
|
|
global $pkg;
|
478 |
|
|
if ($pkg['templates']['template'] != "") {
|
479 |
|
|
foreach ($pkg['templates']['template'] as $pkg_template_row) {
|
480 |
|
|
$filename = $pkg_template_row['filename'];
|
481 |
|
|
$template_text = $pkg_template_row['templatecontents'];
|
482 |
|
|
/* calculate total row helpers count and */
|
483 |
|
|
/* change fields defined as fieldname_fieldvalue to their value */
|
484 |
|
|
foreach ($pkg['fields']['field'] as $fields) {
|
485 |
|
|
switch ($fields['type']) {
|
486 |
|
|
case "rowhelper":
|
487 |
|
|
// save rowhelper items.
|
488 |
|
|
$row_helper_total_rows = 0;
|
489 |
|
|
$row_helper_data = "";
|
490 |
|
|
foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
491 |
|
|
foreach ($_POST as $key => $value) {
|
492 |
|
|
if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
|
493 |
|
|
$row_helper_total_rows++;
|
494 |
|
|
$row_helper_data .= $value;
|
495 |
|
|
$sep = "";
|
496 |
|
|
ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
|
497 |
|
|
foreach ($sep as $se) {
|
498 |
|
|
$separator = $se;
|
499 |
|
|
}
|
500 |
|
|
if ($separator != "") {
|
501 |
|
|
$row_helper_data = ereg_replace(" ", $separator, $row_helper_data);
|
502 |
|
|
$template_text = ereg_replace("\[{$separator}\]", "", $template_text);
|
503 |
|
|
}
|
504 |
|
|
$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
|
505 |
|
|
}
|
506 |
|
|
}
|
507 |
|
|
}
|
508 |
|
|
break;
|
509 |
|
|
default:
|
510 |
|
|
$fieldname = $fields['fieldname'];
|
511 |
|
|
$fieldvalue = $_POST[$fieldname];
|
512 |
|
|
$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
|
513 |
|
|
}
|
514 |
|
|
}
|
515 |
|
|
/* replace $domain_total_rows with total rows */
|
516 |
|
|
$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
|
517 |
|
|
|
518 |
|
|
/* replace cr's */
|
519 |
|
|
$template_text = str_replace("\\n", "\n", $template_text);
|
520 |
|
|
|
521 |
|
|
/* write out new template file */
|
522 |
|
|
$fout = fopen($filename, "w");
|
523 |
|
|
fwrite($fout, $template_text);
|
524 |
|
|
fclose($fout);
|
525 |
|
|
}
|
526 |
|
|
}
|
527 |
|
|
}
|
528 |
|
|
|
529 |
0a0447de
|
heper
|
//breadcrumb
|
530 |
|
|
if ($pkg['title'] != "") {
|
531 |
0f649c97
|
Phil Davis
|
if (!$only_edit) {
|
532 |
b238793b
|
Stephen Beaver
|
$pkg['title'] = $pkg['title'] . '/Edit';
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
if (strpos($pkg['title'], '/')) {
|
536 |
|
|
$title = explode('/', $pkg['title']);
|
537 |
|
|
|
538 |
|
|
foreach ($title as $subtitle) {
|
539 |
|
|
$pgtitle[] = gettext($subtitle);
|
540 |
9ec7699b
|
Stephen Beaver
|
}
|
541 |
b238793b
|
Stephen Beaver
|
} else {
|
542 |
|
|
$pgtitle = array(gettext("Package"), gettext($pkg['title']));
|
543 |
62cdbf62
|
heper
|
}
|
544 |
0a0447de
|
heper
|
} else {
|
545 |
4a457d8d
|
Stephen Beaver
|
$pgtitle = array(gettext("Package"), gettext("Editor"));
|
546 |
0a0447de
|
heper
|
}
|
547 |
b89a8cbc
|
bruno
|
|
548 |
eb3743d8
|
Stephen Beaver
|
// Create any required tabs
|
549 |
23f6cdd7
|
Stephen Beaver
|
if ($pkg['tabs'] != "") {
|
550 |
e11aa161
|
Warren Baker
|
$tab_array = array();
|
551 |
f8ac4407
|
Phil Davis
|
foreach ($pkg['tabs']['tab'] as $tab) {
|
552 |
|
|
if ($tab['tab_level']) {
|
553 |
90551807
|
Warren Baker
|
$tab_level = $tab['tab_level'];
|
554 |
f8ac4407
|
Phil Davis
|
} else {
|
555 |
90551807
|
Warren Baker
|
$tab_level = 1;
|
556 |
f8ac4407
|
Phil Davis
|
}
|
557 |
eb3743d8
|
Stephen Beaver
|
|
558 |
f8ac4407
|
Phil Davis
|
if (isset($tab['active'])) {
|
559 |
90551807
|
Warren Baker
|
$active = true;
|
560 |
b238793b
|
Stephen Beaver
|
$pgtitle[] = $tab['text'] ;
|
561 |
90551807
|
Warren Baker
|
} else {
|
562 |
|
|
$active = false;
|
563 |
|
|
}
|
564 |
eb3743d8
|
Stephen Beaver
|
|
565 |
f8ac4407
|
Phil Davis
|
if (isset($tab['no_drop_down'])) {
|
566 |
f8c462dd
|
Warren Baker
|
$no_drop_down = true;
|
567 |
f8ac4407
|
Phil Davis
|
}
|
568 |
eb3743d8
|
Stephen Beaver
|
|
569 |
90551807
|
Warren Baker
|
$urltmp = "";
|
570 |
23f6cdd7
|
Stephen Beaver
|
if ($tab['url'] != "") {
|
571 |
f8ac4407
|
Phil Davis
|
$urltmp = $tab['url'];
|
572 |
|
|
}
|
573 |
eb3743d8
|
Stephen Beaver
|
|
574 |
23f6cdd7
|
Stephen Beaver
|
if ($tab['xml'] != "") {
|
575 |
f8ac4407
|
Phil Davis
|
$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
|
576 |
|
|
}
|
577 |
90551807
|
Warren Baker
|
|
578 |
f8ac4407
|
Phil Davis
|
$addresswithport = getenv("HTTP_HOST");
|
579 |
90551807
|
Warren Baker
|
$colonpos = strpos($addresswithport, ":");
|
580 |
eb3743d8
|
Stephen Beaver
|
|
581 |
90551807
|
Warren Baker
|
if ($colonpos !== False) {
|
582 |
|
|
//my url is actually just the IP address of the pfsense box
|
583 |
|
|
$myurl = substr($addresswithport, 0, $colonpos);
|
584 |
|
|
} else {
|
585 |
|
|
$myurl = $addresswithport;
|
586 |
|
|
}
|
587 |
eb3743d8
|
Stephen Beaver
|
|
588 |
90551807
|
Warren Baker
|
// eval url so that above $myurl item can be processed if need be.
|
589 |
|
|
$url = str_replace('$myurl', $myurl, $urltmp);
|
590 |
|
|
|
591 |
|
|
$tab_array[$tab_level][] = array(
|
592 |
f8ac4407
|
Phil Davis
|
$tab['text'],
|
593 |
|
|
$active,
|
594 |
|
|
$url
|
595 |
|
|
);
|
596 |
|
|
}
|
597 |
90551807
|
Warren Baker
|
|
598 |
|
|
ksort($tab_array);
|
599 |
0a0447de
|
heper
|
}
|
600 |
23f6cdd7
|
Stephen Beaver
|
|
601 |
4b1d882f
|
Colin Fleming
|
include("head.inc");
|
602 |
0a0447de
|
heper
|
if ($pkg['custom_php_after_head_command']) {
|
603 |
|
|
eval($pkg['custom_php_after_head_command']);
|
604 |
|
|
}
|
605 |
0f649c97
|
Phil Davis
|
if (isset($tab_array)) {
|
606 |
f8ac4407
|
Phil Davis
|
foreach ($tab_array as $tabid => $tab) {
|
607 |
23f6cdd7
|
Stephen Beaver
|
display_top_tabs($tab); //, $no_drop_down, $tabid);
|
608 |
90551807
|
Warren Baker
|
}
|
609 |
7c061036
|
Scott Ullrich
|
}
|
610 |
55c846c4
|
Marcello Coutinho
|
|
611 |
0a0447de
|
heper
|
// Start of page display
|
612 |
0f649c97
|
Phil Davis
|
if ($input_errors) {
|
613 |
0a0447de
|
heper
|
print_input_errors($input_errors);
|
614 |
0f649c97
|
Phil Davis
|
}
|
615 |
0a0447de
|
heper
|
|
616 |
0f649c97
|
Phil Davis
|
if ($savemsg) {
|
617 |
0a0447de
|
heper
|
print_info_box($savemsg, 'success');
|
618 |
0f649c97
|
Phil Davis
|
}
|
619 |
55c846c4
|
Marcello Coutinho
|
|
620 |
eb3743d8
|
Stephen Beaver
|
$cols = 0;
|
621 |
|
|
$savevalue = gettext("Save");
|
622 |
|
|
if ($pkg['savetext'] != "") {
|
623 |
|
|
$savevalue = $pkg['savetext'];
|
624 |
|
|
}
|
625 |
|
|
|
626 |
e0d1a2f8
|
Renato Botelho
|
$savehelp = "";
|
627 |
608bb662
|
Stephen Beaver
|
if ($pkg['savehelp'] != "") {
|
628 |
|
|
$savehelp = $pkg['savehelp'];
|
629 |
|
|
}
|
630 |
|
|
|
631 |
f84e2105
|
jim-p
|
$saveicon = "fa-save";
|
632 |
|
|
if ($pkg['saveicon'] != "") {
|
633 |
|
|
$saveicon = $pkg['saveicon'];
|
634 |
|
|
}
|
635 |
|
|
|
636 |
|
|
$savebtnclass = "btn-primary";
|
637 |
|
|
if ($pkg['savebtnclass'] != "") {
|
638 |
|
|
$savebtnclass = $pkg['savebtnclass'];
|
639 |
|
|
}
|
640 |
|
|
|
641 |
eb3743d8
|
Stephen Beaver
|
$grouping = false; // Indicates the elements we are composing are part of a combined group
|
642 |
23f6cdd7
|
Stephen Beaver
|
|
643 |
608bb662
|
Stephen Beaver
|
$savebutton = new Form_Button(
|
644 |
eb3743d8
|
Stephen Beaver
|
'submit',
|
645 |
f84e2105
|
jim-p
|
$savevalue,
|
646 |
|
|
null,
|
647 |
|
|
$saveicon
|
648 |
608bb662
|
Stephen Beaver
|
);
|
649 |
f84e2105
|
jim-p
|
$savebutton->addClass($savebtnclass);
|
650 |
608bb662
|
Stephen Beaver
|
|
651 |
|
|
if ($savehelp) {
|
652 |
|
|
$savebutton->setHelp($savehelp);
|
653 |
|
|
}
|
654 |
|
|
|
655 |
|
|
$form = new Form($savebutton);
|
656 |
23f6cdd7
|
Stephen Beaver
|
|
657 |
eb3743d8
|
Stephen Beaver
|
$form->addGlobal(new Form_Input(
|
658 |
|
|
'xml',
|
659 |
|
|
null,
|
660 |
|
|
'hidden',
|
661 |
|
|
$xml
|
662 |
|
|
));
|
663 |
23f6cdd7
|
Stephen Beaver
|
|
664 |
eb3743d8
|
Stephen Beaver
|
/* If a package's XML has <advanced_options/> configured, then setup
|
665 |
2d911f2c
|
Phil Davis
|
* the section for the fields that have <advancedfield/> set.
|
666 |
eb3743d8
|
Stephen Beaver
|
* These fields will be placed below other fields in a separate area titled 'Advanced Features'.
|
667 |
|
|
* These advanced fields are not normally configured and generally left to default to 'default settings'.
|
668 |
|
|
*/
|
669 |
32487e42
|
Scott Ullrich
|
|
670 |
eb3743d8
|
Stephen Beaver
|
if ($pkg['advanced_options'] == "enabled") {
|
671 |
|
|
$advfield_count = 0;
|
672 |
20414655
|
k-paulius
|
$advanced = new Form_Section("Advanced Features");
|
673 |
eb3743d8
|
Stephen Beaver
|
$advanced->addClass('advancedoptions');
|
674 |
|
|
}
|
675 |
23f6cdd7
|
Stephen Beaver
|
|
676 |
eb3743d8
|
Stephen Beaver
|
$js_array = array();
|
677 |
23f6cdd7
|
Stephen Beaver
|
|
678 |
2d911f2c
|
Phil Davis
|
// Now loop through all of the fields defined in the XML
|
679 |
fff6a2af
|
jim-p
|
if (!is_array($pkg['fields']['field'])) {
|
680 |
|
|
$pkg['fields']['field'] = array();
|
681 |
|
|
}
|
682 |
eb3743d8
|
Stephen Beaver
|
foreach ($pkg['fields']['field'] as $pkga) {
|
683 |
23f6cdd7
|
Stephen Beaver
|
|
684 |
4a6272be
|
Stephen Beaver
|
$action = "";
|
685 |
|
|
$uid = "";
|
686 |
|
|
|
687 |
eb3743d8
|
Stephen Beaver
|
if ($pkga['type'] == "sorting") {
|
688 |
|
|
continue;
|
689 |
|
|
}
|
690 |
23f6cdd7
|
Stephen Beaver
|
|
691 |
eb3743d8
|
Stephen Beaver
|
// Generate a new section
|
692 |
|
|
if ($pkga['type'] == "listtopic") {
|
693 |
|
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
694 |
|
|
$advanced->addInput(new Form_StaticText(
|
695 |
|
|
strip_tags($pkga['name']),
|
696 |
|
|
null
|
697 |
|
|
));
|
698 |
1624b5f1
|
Marcello Coutinho
|
|
699 |
eb3743d8
|
Stephen Beaver
|
$advfield_count++;
|
700 |
|
|
} else {
|
701 |
0f649c97
|
Phil Davis
|
if (isset($section)) {
|
702 |
eb3743d8
|
Stephen Beaver
|
$form->add($section);
|
703 |
0f649c97
|
Phil Davis
|
}
|
704 |
1624b5f1
|
Marcello Coutinho
|
|
705 |
4a6272be
|
Stephen Beaver
|
if (isset($pkga['collapse'])) {
|
706 |
|
|
$uid = uniqid("section");
|
707 |
|
|
|
708 |
|
|
$action = COLLAPSIBLE;
|
709 |
|
|
|
710 |
|
|
if ($pkga['collapse'] == "open") {
|
711 |
|
|
$action |= SEC_OPEN;
|
712 |
|
|
} else {
|
713 |
|
|
$action |= SEC_CLOSED;
|
714 |
|
|
}
|
715 |
|
|
}
|
716 |
|
|
|
717 |
|
|
$section = new Form_Section(strip_tags($pkga['name']), $uid, $action);
|
718 |
e11aa161
|
Warren Baker
|
}
|
719 |
23f6cdd7
|
Stephen Beaver
|
|
720 |
eb3743d8
|
Stephen Beaver
|
continue;
|
721 |
|
|
}
|
722 |
1624b5f1
|
Marcello Coutinho
|
|
723 |
eb3743d8
|
Stephen Beaver
|
// 'begin' starts a form group. ('end' ends it)
|
724 |
|
|
if ($pkga['combinefields'] == "begin") {
|
725 |
|
|
$group = new Form_Group(strip_tags($pkga['fielddescr']));
|
726 |
|
|
$grouping = true;
|
727 |
|
|
}
|
728 |
|
|
|
729 |
|
|
$size = "";
|
730 |
|
|
$colspan="";
|
731 |
|
|
|
732 |
|
|
// if user is editing a record, load in the data.
|
733 |
|
|
$fieldname = $pkga['fieldname'];
|
734 |
|
|
unset($value);
|
735 |
|
|
if ($get_from_post) {
|
736 |
|
|
$value = $_POST[$fieldname];
|
737 |
|
|
if (is_array($value)) {
|
738 |
|
|
$value = implode(',', $value);
|
739 |
55c846c4
|
Marcello Coutinho
|
}
|
740 |
eb3743d8
|
Stephen Beaver
|
} else {
|
741 |
|
|
if (isset($id) && isset($a_pkg[$id][$fieldname])) {
|
742 |
|
|
$value = $a_pkg[$id][$fieldname];
|
743 |
e11aa161
|
Warren Baker
|
} else {
|
744 |
eb3743d8
|
Stephen Beaver
|
if (isset($pkga['default_value'])) {
|
745 |
|
|
$value = $pkga['default_value'];
|
746 |
f8ac4407
|
Phil Davis
|
}
|
747 |
31d27c6c
|
Scott Ullrich
|
}
|
748 |
eb3743d8
|
Stephen Beaver
|
}
|
749 |
23f6cdd7
|
Stephen Beaver
|
|
750 |
86a20575
|
Stephen Beaver
|
// If we get here but have no $section, the package config file probably had no listtopic field
|
751 |
|
|
// We can create a section with a generic name to fix that
|
752 |
0f649c97
|
Phil Davis
|
if (!$section) {
|
753 |
20414655
|
k-paulius
|
$section = new Form_Section('General Options');
|
754 |
0f649c97
|
Phil Davis
|
}
|
755 |
86a20575
|
Stephen Beaver
|
|
756 |
eb3743d8
|
Stephen Beaver
|
switch ($pkga['type']) {
|
757 |
5697a26a
|
Stephen Beaver
|
// Create an input element. The format is slightly different depending on whether we are composing a group,
|
758 |
eb3743d8
|
Stephen Beaver
|
// section, or advanced section. This is true for every element type
|
759 |
|
|
case "input":
|
760 |
6e5cec8e
|
doktornotor
|
if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
|
761 |
|
|
$value = base64_decode($value);
|
762 |
|
|
}
|
763 |
|
|
|
764 |
962ec941
|
Stephen Beaver
|
$grp = new Form_Input(
|
765 |
eb3743d8
|
Stephen Beaver
|
$pkga['fieldname'],
|
766 |
|
|
$pkga['fielddescr'],
|
767 |
|
|
'text',
|
768 |
|
|
$value
|
769 |
962ec941
|
Stephen Beaver
|
);
|
770 |
|
|
|
771 |
|
|
$grp->setHelp($pkga['description']);
|
772 |
|
|
|
773 |
|
|
if ($pkga['width']) {
|
774 |
|
|
$grp->setWidth($pkga['width']);
|
775 |
|
|
}
|
776 |
|
|
|
777 |
|
|
if ($grouping) {
|
778 |
|
|
$group->add($grp);
|
779 |
eb3743d8
|
Stephen Beaver
|
} else {
|
780 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
781 |
962ec941
|
Stephen Beaver
|
$advanced->addInput($grp);
|
782 |
f8ac4407
|
Phil Davis
|
} else {
|
783 |
962ec941
|
Stephen Beaver
|
$section->addInput($grp);
|
784 |
f8ac4407
|
Phil Davis
|
}
|
785 |
eb3743d8
|
Stephen Beaver
|
}
|
786 |
23f6cdd7
|
Stephen Beaver
|
|
787 |
eb3743d8
|
Stephen Beaver
|
break;
|
788 |
1624b5f1
|
Marcello Coutinho
|
|
789 |
eb3743d8
|
Stephen Beaver
|
case "password":
|
790 |
6e5cec8e
|
doktornotor
|
if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
|
791 |
|
|
$value = base64_decode($value);
|
792 |
|
|
}
|
793 |
|
|
|
794 |
2d911f2c
|
Phil Davis
|
// Create a password element
|
795 |
6e5cec8e
|
doktornotor
|
if ($grouping) {
|
796 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Input(
|
797 |
|
|
$pkga['fieldname'],
|
798 |
|
|
$pkga['fielddescr'],
|
799 |
|
|
'password',
|
800 |
|
|
$value
|
801 |
|
|
))->setHelp($pkga['description']);
|
802 |
|
|
} else {
|
803 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
804 |
|
|
$advanced->addInput(new Form_Input(
|
805 |
|
|
$pkga['fieldname'],
|
806 |
|
|
$pkga['fielddescr'],
|
807 |
|
|
'password',
|
808 |
|
|
$value
|
809 |
|
|
))->setHelp($pkga['description']);
|
810 |
f8ac4407
|
Phil Davis
|
} else {
|
811 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Input(
|
812 |
|
|
$pkga['fieldname'],
|
813 |
|
|
$pkga['fielddescr'],
|
814 |
|
|
'password',
|
815 |
|
|
$value
|
816 |
|
|
))->setHelp($pkga['description']);
|
817 |
f8ac4407
|
Phil Davis
|
}
|
818 |
eb3743d8
|
Stephen Beaver
|
}
|
819 |
23f6cdd7
|
Stephen Beaver
|
|
820 |
eb3743d8
|
Stephen Beaver
|
break;
|
821 |
23f6cdd7
|
Stephen Beaver
|
|
822 |
eb3743d8
|
Stephen Beaver
|
case "info":
|
823 |
2d911f2c
|
Phil Davis
|
// If the info contains a table we should detect and Bootstrap it
|
824 |
23f6cdd7
|
Stephen Beaver
|
|
825 |
0f649c97
|
Phil Davis
|
if (strpos($pkga['description'], '<table') !== FALSE) {
|
826 |
eb3743d8
|
Stephen Beaver
|
$info = bootstrapTable($pkga['description']);
|
827 |
0f649c97
|
Phil Davis
|
} else {
|
828 |
eb3743d8
|
Stephen Beaver
|
$info = $pkga['description'];
|
829 |
0f649c97
|
Phil Davis
|
}
|
830 |
23f6cdd7
|
Stephen Beaver
|
|
831 |
eb3743d8
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
832 |
|
|
$advanced->addInput(new Form_StaticText(
|
833 |
|
|
strip_tags($pkga['fielddescr']),
|
834 |
|
|
$info
|
835 |
|
|
));
|
836 |
|
|
} else {
|
837 |
|
|
$section->addInput(new Form_StaticText(
|
838 |
|
|
strip_tags($pkga['fielddescr']),
|
839 |
|
|
$info
|
840 |
|
|
));
|
841 |
|
|
}
|
842 |
23f6cdd7
|
Stephen Beaver
|
|
843 |
eb3743d8
|
Stephen Beaver
|
break;
|
844 |
1624b5f1
|
Marcello Coutinho
|
|
845 |
eb3743d8
|
Stephen Beaver
|
case "select":
|
846 |
|
|
// Create a select element
|
847 |
|
|
$optionlist = array();
|
848 |
|
|
$selectedlist = array();
|
849 |
23f6cdd7
|
Stephen Beaver
|
|
850 |
eb3743d8
|
Stephen Beaver
|
$fieldname = $pkga['fieldname'];
|
851 |
23f6cdd7
|
Stephen Beaver
|
|
852 |
eb3743d8
|
Stephen Beaver
|
if (isset($pkga['multiple'])) {
|
853 |
c4b60a9a
|
Colin Fleming
|
$multiple = 'multiple';
|
854 |
eb3743d8
|
Stephen Beaver
|
$items = explode(',', $value);
|
855 |
|
|
$fieldname .= "[]";
|
856 |
|
|
} else {
|
857 |
|
|
$multiple = '';
|
858 |
|
|
$items = array($value);
|
859 |
|
|
}
|
860 |
23f6cdd7
|
Stephen Beaver
|
|
861 |
eb3743d8
|
Stephen Beaver
|
$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
|
862 |
23f6cdd7
|
Stephen Beaver
|
|
863 |
eb3743d8
|
Stephen Beaver
|
foreach ($pkga['options']['option'] as $opt) {
|
864 |
|
|
$optionlist[$opt['value']] = $opt['name'];
|
865 |
23f6cdd7
|
Stephen Beaver
|
|
866 |
eb3743d8
|
Stephen Beaver
|
if (in_array($opt['value'], $items)) {
|
867 |
|
|
array_push($selectedlist, $opt['value']);
|
868 |
f8ac4407
|
Phil Davis
|
}
|
869 |
eb3743d8
|
Stephen Beaver
|
}
|
870 |
23f6cdd7
|
Stephen Beaver
|
|
871 |
0f649c97
|
Phil Davis
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
872 |
eb3743d8
|
Stephen Beaver
|
$function = $grouping ? $advanced->add:$advanced->addInput;
|
873 |
0f649c97
|
Phil Davis
|
} else {
|
874 |
eb3743d8
|
Stephen Beaver
|
$function = ($grouping) ? $section->add:$section->addInput;
|
875 |
0f649c97
|
Phil Davis
|
}
|
876 |
23f6cdd7
|
Stephen Beaver
|
|
877 |
57fc02b1
|
Stephen Beaver
|
$grp = new Form_Select(
|
878 |
23f6cdd7
|
Stephen Beaver
|
$pkga['fieldname'],
|
879 |
eb3743d8
|
Stephen Beaver
|
strip_tags($pkga['fielddescr']),
|
880 |
23f6cdd7
|
Stephen Beaver
|
isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
|
881 |
|
|
$optionlist,
|
882 |
|
|
isset($pkga['multiple'])
|
883 |
a1cd3857
|
Stephen Beaver
|
);
|
884 |
|
|
|
885 |
57fc02b1
|
Stephen Beaver
|
$grp ->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']);
|
886 |
a1cd3857
|
Stephen Beaver
|
|
887 |
57fc02b1
|
Stephen Beaver
|
if ($pkga['width']) {
|
888 |
|
|
$grp->setWidth($pkga['width']);
|
889 |
|
|
}
|
890 |
a1cd3857
|
Stephen Beaver
|
|
891 |
57fc02b1
|
Stephen Beaver
|
if ($grouping) {
|
892 |
|
|
$group->add($grp);
|
893 |
|
|
} else {
|
894 |
|
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
895 |
|
|
$advanced->addInput($grp);
|
896 |
|
|
} else {
|
897 |
|
|
$section->addInput($grp);
|
898 |
f8ac4407
|
Phil Davis
|
}
|
899 |
eb3743d8
|
Stephen Beaver
|
}
|
900 |
23f6cdd7
|
Stephen Beaver
|
|
901 |
eb3743d8
|
Stephen Beaver
|
break;
|
902 |
1624b5f1
|
Marcello Coutinho
|
|
903 |
eb3743d8
|
Stephen Beaver
|
case "select_source":
|
904 |
23f6cdd7
|
Stephen Beaver
|
|
905 |
eb3743d8
|
Stephen Beaver
|
if (isset($pkga['multiple'])) {
|
906 |
|
|
$items = explode(',', $value);
|
907 |
|
|
$fieldname .= "[]";
|
908 |
|
|
} else {
|
909 |
|
|
$items = array($value);
|
910 |
|
|
}
|
911 |
23f6cdd7
|
Stephen Beaver
|
|
912 |
eb3743d8
|
Stephen Beaver
|
$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
|
913 |
55c846c4
|
Marcello Coutinho
|
|
914 |
eb3743d8
|
Stephen Beaver
|
$source_url = $pkga['source'];
|
915 |
|
|
eval("\$pkg_source_txt = &$source_url;");
|
916 |
23f6cdd7
|
Stephen Beaver
|
|
917 |
eb3743d8
|
Stephen Beaver
|
#check if show disable option is present on xml
|
918 |
eeae21e8
|
jim-p
|
if (!is_array($pkg_source_txt)) {
|
919 |
|
|
$pkg_source_txt = array();
|
920 |
|
|
}
|
921 |
eb3743d8
|
Stephen Beaver
|
if (isset($pkga['show_disable_value'])) {
|
922 |
|
|
array_push($pkg_source_txt,
|
923 |
|
|
array(($pkga['source_name']? $pkga['source_name'] : $pkga['name'])=> $pkga['show_disable_value'], ($pkga['source_value']? $pkga['source_value'] : $pkga['value'])=> $pkga['show_disable_value']));
|
924 |
|
|
}
|
925 |
23f6cdd7
|
Stephen Beaver
|
|
926 |
eb3743d8
|
Stephen Beaver
|
$srcoptions = array();
|
927 |
|
|
$srcselected = array();
|
928 |
23f6cdd7
|
Stephen Beaver
|
|
929 |
eb3743d8
|
Stephen Beaver
|
foreach ($pkg_source_txt as $opt) {
|
930 |
|
|
$source_name =($pkga['source_name']? $opt[$pkga['source_name']] : $opt[$pkga['name']]);
|
931 |
|
|
$source_value =($pkga['source_value'] ? $opt[$pkga['source_value']] : $opt[$pkga['value']]);
|
932 |
|
|
$srcoptions[$source_value] = $source_name;
|
933 |
23f6cdd7
|
Stephen Beaver
|
|
934 |
0f649c97
|
Phil Davis
|
if (in_array($source_value, $items)) {
|
935 |
eb3743d8
|
Stephen Beaver
|
array_push($srcselected, $source_value);
|
936 |
0f649c97
|
Phil Davis
|
}
|
937 |
eb3743d8
|
Stephen Beaver
|
}
|
938 |
23f6cdd7
|
Stephen Beaver
|
|
939 |
83d8e9ab
|
Luiz Otavio O Souza
|
$descr = (isset($pkga['description'])) ? $pkga['description'] : "";
|
940 |
0f649c97
|
Phil Davis
|
if ($grouping) {
|
941 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Select(
|
942 |
|
|
$pkga['fieldname'],
|
943 |
2512e643
|
jim-p
|
strip_tags($pkga['fielddescr']),
|
944 |
eb3743d8
|
Stephen Beaver
|
isset($pkga['multiple']) ? $srcselected:$srcselected[0],
|
945 |
|
|
$srcoptions,
|
946 |
|
|
isset($pkga['multiple'])
|
947 |
83d8e9ab
|
Luiz Otavio O Souza
|
))->setHelp($descr)->setOnchange($onchange);
|
948 |
eb3743d8
|
Stephen Beaver
|
} else {
|
949 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
950 |
|
|
$advanced->addInput(new Form_Select(
|
951 |
|
|
$pkga['fieldname'],
|
952 |
2512e643
|
jim-p
|
strip_tags($pkga['fielddescr']),
|
953 |
23f6cdd7
|
Stephen Beaver
|
isset($pkga['multiple']) ? $srcselected:$srcselected[0],
|
954 |
eb3743d8
|
Stephen Beaver
|
$srcoptions,
|
955 |
23f6cdd7
|
Stephen Beaver
|
isset($pkga['multiple'])
|
956 |
83d8e9ab
|
Luiz Otavio O Souza
|
))->setHelp($descr)->setOnchange($onchange);
|
957 |
f8ac4407
|
Phil Davis
|
} else {
|
958 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Select(
|
959 |
|
|
$pkga['fieldname'],
|
960 |
2512e643
|
jim-p
|
strip_tags($pkga['fielddescr']),
|
961 |
23f6cdd7
|
Stephen Beaver
|
isset($pkga['multiple']) ? $srcselected:$srcselected[0],
|
962 |
eb3743d8
|
Stephen Beaver
|
$srcoptions,
|
963 |
23f6cdd7
|
Stephen Beaver
|
isset($pkga['multiple'])
|
964 |
83d8e9ab
|
Luiz Otavio O Souza
|
))->setHelp($descr)->setOnchange($onchange);
|
965 |
f8ac4407
|
Phil Davis
|
}
|
966 |
eb3743d8
|
Stephen Beaver
|
}
|
967 |
23f6cdd7
|
Stephen Beaver
|
|
968 |
eb3743d8
|
Stephen Beaver
|
break;
|
969 |
1624b5f1
|
Marcello Coutinho
|
|
970 |
eb3743d8
|
Stephen Beaver
|
case "vpn_selection" :
|
971 |
|
|
$vpnlist = array();
|
972 |
23f6cdd7
|
Stephen Beaver
|
|
973 |
eb3743d8
|
Stephen Beaver
|
foreach ($config['ipsec']['phase1'] as $vpn) {
|
974 |
|
|
$vpnlist[$vpn['descr']] = $vpn['descr'];
|
975 |
23f6cdd7
|
Stephen Beaver
|
|
976 |
eb3743d8
|
Stephen Beaver
|
}
|
977 |
55c846c4
|
Marcello Coutinho
|
|
978 |
0f649c97
|
Phil Davis
|
if ($grouping) {
|
979 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Select(
|
980 |
|
|
$pkga['fieldname'],
|
981 |
|
|
null,
|
982 |
|
|
false,
|
983 |
|
|
$vpnlist
|
984 |
|
|
))->setHelp(fixup_string($pkga['description']));
|
985 |
|
|
} else {
|
986 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
987 |
|
|
$advanced->addInput(new Form_Select(
|
988 |
|
|
$pkga['fieldname'],
|
989 |
|
|
null,
|
990 |
|
|
false,
|
991 |
|
|
$vpnlist
|
992 |
|
|
))->setHelp(fixup_string($pkga['description']));
|
993 |
f8ac4407
|
Phil Davis
|
} else {
|
994 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Select(
|
995 |
|
|
$pkga['fieldname'],
|
996 |
|
|
null,
|
997 |
|
|
false,
|
998 |
|
|
$vpnlist
|
999 |
|
|
))->setHelp(fixup_string($pkga['description']));
|
1000 |
f8ac4407
|
Phil Davis
|
}
|
1001 |
eb3743d8
|
Stephen Beaver
|
}
|
1002 |
23f6cdd7
|
Stephen Beaver
|
|
1003 |
eb3743d8
|
Stephen Beaver
|
break;
|
1004 |
23f6cdd7
|
Stephen Beaver
|
|
1005 |
eb3743d8
|
Stephen Beaver
|
// Create a checkbox element
|
1006 |
|
|
case "checkbox":
|
1007 |
|
|
$onchange = (isset($pkga['onchange']) ? "{$pkga['onchange']}" : '');
|
1008 |
0f649c97
|
Phil Davis
|
if (isset($pkga['enablefields']) || isset($pkga['checkenablefields'])) {
|
1009 |
eb3743d8
|
Stephen Beaver
|
$onclick = 'javascript:enablechange();';
|
1010 |
0f649c97
|
Phil Davis
|
} else {
|
1011 |
eb3743d8
|
Stephen Beaver
|
$onclick = '';
|
1012 |
0f649c97
|
Phil Davis
|
}
|
1013 |
eb3743d8
|
Stephen Beaver
|
|
1014 |
0f649c97
|
Phil Davis
|
if ($grouping) {
|
1015 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Checkbox(
|
1016 |
|
|
$pkga['fieldname'],
|
1017 |
|
|
$pkga['fielddescr'],
|
1018 |
86c77223
|
Stephen Beaver
|
fixup_string($pkga['description']),
|
1019 |
eb3743d8
|
Stephen Beaver
|
($value == "on"),
|
1020 |
|
|
'on'
|
1021 |
86c77223
|
Stephen Beaver
|
))->setOnclick($onclick)
|
1022 |
bb69870b
|
Stephen Beaver
|
->setOnchange($onchange)
|
1023 |
82c02c9e
|
heper
|
->setHelp($pkga['sethelp']);
|
1024 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1025 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1026 |
|
|
$advanced->addInput(new Form_Checkbox(
|
1027 |
|
|
$pkga['fieldname'],
|
1028 |
1ae171a3
|
Stephen Beaver
|
$pkga['fielddescr'],
|
1029 |
86c77223
|
Stephen Beaver
|
fixup_string($pkga['description']),
|
1030 |
23f6cdd7
|
Stephen Beaver
|
($value == "on"),
|
1031 |
|
|
'on'
|
1032 |
86c77223
|
Stephen Beaver
|
))->setOnclick($onclick)
|
1033 |
bb69870b
|
Stephen Beaver
|
->setOnchange($onchange)
|
1034 |
82c02c9e
|
heper
|
->setHelp($pkga['sethelp']);
|
1035 |
f8ac4407
|
Phil Davis
|
} else {
|
1036 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Checkbox(
|
1037 |
|
|
$pkga['fieldname'],
|
1038 |
|
|
$pkga['fielddescr'],
|
1039 |
86c77223
|
Stephen Beaver
|
fixup_string($pkga['description']),
|
1040 |
23f6cdd7
|
Stephen Beaver
|
($value == "on"),
|
1041 |
|
|
'on'
|
1042 |
86c77223
|
Stephen Beaver
|
))->setOnclick($onclick)
|
1043 |
1ae171a3
|
Stephen Beaver
|
->setOnchange($onchange)
|
1044 |
bb69870b
|
Stephen Beaver
|
->setHelp($pkga['sethelp']);
|
1045 |
f8ac4407
|
Phil Davis
|
}
|
1046 |
eb3743d8
|
Stephen Beaver
|
}
|
1047 |
23f6cdd7
|
Stephen Beaver
|
|
1048 |
eb3743d8
|
Stephen Beaver
|
break;
|
1049 |
1624b5f1
|
Marcello Coutinho
|
|
1050 |
2d911f2c
|
Phil Davis
|
// Create a textarea element
|
1051 |
eb3743d8
|
Stephen Beaver
|
case "textarea":
|
1052 |
c70b6835
|
Stephen Beaver
|
$rows = $cols = 0;
|
1053 |
|
|
|
1054 |
eb3743d8
|
Stephen Beaver
|
if ($pkga['rows']) {
|
1055 |
c70b6835
|
Stephen Beaver
|
$rows = $pkga['rows'];
|
1056 |
eb3743d8
|
Stephen Beaver
|
}
|
1057 |
|
|
if ($pkga['cols']) {
|
1058 |
c70b6835
|
Stephen Beaver
|
$cols = $pkga['cols'];
|
1059 |
eb3743d8
|
Stephen Beaver
|
}
|
1060 |
c70b6835
|
Stephen Beaver
|
|
1061 |
eb3743d8
|
Stephen Beaver
|
if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
|
1062 |
|
|
$value = base64_decode($value);
|
1063 |
|
|
}
|
1064 |
23f6cdd7
|
Stephen Beaver
|
|
1065 |
c70b6835
|
Stephen Beaver
|
$grp = new Form_Textarea(
|
1066 |
eb3743d8
|
Stephen Beaver
|
$pkga['fieldname'],
|
1067 |
|
|
$pkga['fielddescr'],
|
1068 |
|
|
$value
|
1069 |
c70b6835
|
Stephen Beaver
|
);
|
1070 |
|
|
|
1071 |
|
|
$grp->setHelp(fixup_string($pkga['description']));
|
1072 |
|
|
|
1073 |
|
|
if ($rows > 0) {
|
1074 |
|
|
$grp->setRows($rows);
|
1075 |
|
|
}
|
1076 |
|
|
|
1077 |
|
|
if ($cols > 0) {
|
1078 |
|
|
$grp->setCols($cols);
|
1079 |
|
|
}
|
1080 |
|
|
|
1081 |
|
|
if ($pkga['wrap'] == "off") {
|
1082 |
|
|
$grp->setAttribute("wrap", "off");
|
1083 |
e5274f51
|
Stephen Beaver
|
$grp->setAttribute("style", "white-space:nowrap; width: auto;");
|
1084 |
|
|
} else {
|
1085 |
|
|
$grp->setAttribute("style", "width: auto;");
|
1086 |
c70b6835
|
Stephen Beaver
|
}
|
1087 |
|
|
|
1088 |
|
|
if ($grouping) {
|
1089 |
|
|
$group->add($grp);
|
1090 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1091 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1092 |
c70b6835
|
Stephen Beaver
|
$advanced->addInput($grp);
|
1093 |
f8ac4407
|
Phil Davis
|
} else {
|
1094 |
c70b6835
|
Stephen Beaver
|
$section->addInput($grp);
|
1095 |
f8ac4407
|
Phil Davis
|
}
|
1096 |
eb3743d8
|
Stephen Beaver
|
}
|
1097 |
23f6cdd7
|
Stephen Beaver
|
|
1098 |
eb3743d8
|
Stephen Beaver
|
break;
|
1099 |
b89a8cbc
|
bruno
|
|
1100 |
eb3743d8
|
Stephen Beaver
|
case "aliases":
|
1101 |
|
|
|
1102 |
|
|
// Use xml tag <typealiases> to filter type aliases
|
1103 |
|
|
$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
|
1104 |
|
|
$fieldname = $pkga['fieldname'];
|
1105 |
|
|
$a_aliases = &$config['aliases']['alias'];
|
1106 |
|
|
$addrisfirst = 0;
|
1107 |
|
|
$aliasesaddr = "";
|
1108 |
|
|
|
1109 |
|
|
if (isset($a_aliases)) {
|
1110 |
|
|
if (!empty($pkga['typealiases'])) {
|
1111 |
|
|
foreach ($a_aliases as $alias) {
|
1112 |
|
|
if ($alias['type'] == $pkga['typealiases']) {
|
1113 |
f8ac4407
|
Phil Davis
|
if ($addrisfirst == 1) {
|
1114 |
|
|
$aliasesaddr .= ",";
|
1115 |
|
|
}
|
1116 |
b89a8cbc
|
bruno
|
$aliasesaddr .= "'" . $alias['name'] . "'";
|
1117 |
|
|
$addrisfirst = 1;
|
1118 |
|
|
}
|
1119 |
|
|
}
|
1120 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1121 |
|
|
foreach ($a_aliases as $alias) {
|
1122 |
|
|
if ($addrisfirst == 1) {
|
1123 |
|
|
$aliasesaddr .= ",";
|
1124 |
|
|
}
|
1125 |
|
|
$aliasesaddr .= "'" . $alias['name'] . "'";
|
1126 |
|
|
$addrisfirst = 1;
|
1127 |
|
|
}
|
1128 |
b89a8cbc
|
bruno
|
}
|
1129 |
eb3743d8
|
Stephen Beaver
|
}
|
1130 |
b89a8cbc
|
bruno
|
|
1131 |
962ec941
|
Stephen Beaver
|
$grp = new Form_Input(
|
1132 |
eb3743d8
|
Stephen Beaver
|
$pkga['fieldname'],
|
1133 |
|
|
$pkga['fielddescr'],
|
1134 |
|
|
'text',
|
1135 |
|
|
$value
|
1136 |
962ec941
|
Stephen Beaver
|
);
|
1137 |
|
|
|
1138 |
|
|
$grp->setHelp($pkga['description']);
|
1139 |
|
|
|
1140 |
|
|
if ($pkga['width']) {
|
1141 |
|
|
$grp->setWidth($pkga['width']);
|
1142 |
|
|
}
|
1143 |
|
|
|
1144 |
|
|
if (grouping) {
|
1145 |
|
|
$group->add($grp);
|
1146 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1147 |
|
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1148 |
962ec941
|
Stephen Beaver
|
$advanced->addInput($grp);
|
1149 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1150 |
962ec941
|
Stephen Beaver
|
$section->addInput($grp);
|
1151 |
eb3743d8
|
Stephen Beaver
|
}
|
1152 |
|
|
}
|
1153 |
b89a8cbc
|
bruno
|
|
1154 |
eb3743d8
|
Stephen Beaver
|
$script = "<script type='text/javascript'>\n";
|
1155 |
|
|
$script .= "//<![CDATA[\n";
|
1156 |
|
|
$script .= "events.push(function(){\n";
|
1157 |
|
|
$script .= " var aliasarray = new Array({$aliasesaddr})\n";
|
1158 |
|
|
$script .= " $('#' + '{$fieldname}').autocomplete({\n";
|
1159 |
|
|
$script .= " source: aliasarray\n";
|
1160 |
|
|
$script .= " })\n";
|
1161 |
|
|
$script .= "});\n";
|
1162 |
|
|
$script .= "//]]>\n";
|
1163 |
|
|
$script .= "</script>";
|
1164 |
b89a8cbc
|
bruno
|
|
1165 |
eb3743d8
|
Stephen Beaver
|
echo $script;
|
1166 |
|
|
|
1167 |
|
|
break;
|
1168 |
|
|
|
1169 |
|
|
case "interfaces_selection":
|
1170 |
|
|
$ips = array();
|
1171 |
|
|
$interface_regex=(isset($pkga['hideinterfaceregex']) ? $pkga['hideinterfaceregex'] : "nointerfacestohide");
|
1172 |
|
|
if (is_array($config['interfaces'])) {
|
1173 |
|
|
foreach ($config['interfaces'] as $iface_key=>$iface_value) {
|
1174 |
|
|
if (isset($iface_value['enable']) && !preg_match("/$interface_regex/", $iface_key)) {
|
1175 |
|
|
$iface_description=($iface_value['descr'] !="" ? strtoupper($iface_value['descr']) : strtoupper($iface_key));
|
1176 |
|
|
if (isset($pkga['showips'])) {
|
1177 |
|
|
$iface_description .= " address";
|
1178 |
f8ac4407
|
Phil Davis
|
}
|
1179 |
eb3743d8
|
Stephen Beaver
|
$ips[] = array('ip'=> $iface_key, 'description'=> $iface_description);
|
1180 |
e14fbca4
|
Marcello Coutinho
|
}
|
1181 |
f8ac4407
|
Phil Davis
|
}
|
1182 |
eb3743d8
|
Stephen Beaver
|
}
|
1183 |
23f6cdd7
|
Stephen Beaver
|
|
1184 |
eb3743d8
|
Stephen Beaver
|
if (is_array($config['virtualip']) && isset($pkga['showvirtualips'])) {
|
1185 |
|
|
foreach ($config['virtualip']['vip'] as $vip) {
|
1186 |
|
|
if (!preg_match("/$interface_regex/", $vip['interface'])) {
|
1187 |
|
|
$vip_description=($vip['descr'] !="" ? " ({$vip['descr']}) " : " ");
|
1188 |
|
|
}
|
1189 |
|
|
switch ($vip['mode']) {
|
1190 |
|
|
case "ipalias":
|
1191 |
|
|
case "carp":
|
1192 |
|
|
$ips[] = array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
|
1193 |
|
|
break;
|
1194 |
|
|
case "proxyarp":
|
1195 |
|
|
if ($vip['type'] == "network") {
|
1196 |
|
|
$start = ip2long32(gen_subnet($vip['subnet'], $vip['subnet_bits']));
|
1197 |
|
|
$end = ip2long32(gen_subnet_max($vip['subnet'], $vip['subnet_bits']));
|
1198 |
|
|
$len = $end - $start;
|
1199 |
|
|
for ($i = 0; $i <= $len; $i++) {
|
1200 |
|
|
$ips[]= array('ip' => long2ip32($start+$i), 'description' => long2ip32($start+$i)." from {$vip['subnet']}/{$vip['subnet_bits']} {$vip_description}");
|
1201 |
f8ac4407
|
Phil Davis
|
}
|
1202 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1203 |
|
|
$ips[]= array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
|
1204 |
|
|
}
|
1205 |
|
|
break;
|
1206 |
e14fbca4
|
Marcello Coutinho
|
}
|
1207 |
f8ac4407
|
Phil Davis
|
}
|
1208 |
eb3743d8
|
Stephen Beaver
|
}
|
1209 |
23f6cdd7
|
Stephen Beaver
|
|
1210 |
eb3743d8
|
Stephen Beaver
|
sort($ips);
|
1211 |
|
|
if (isset($pkga['showlistenall'])) {
|
1212 |
cadeb9fd
|
Phil Davis
|
array_unshift($ips, array('ip' => gettext('All'), 'description' => gettext('Listen on All interfaces/ip addresses ')));
|
1213 |
eb3743d8
|
Stephen Beaver
|
}
|
1214 |
e14fbca4
|
Marcello Coutinho
|
|
1215 |
eb3743d8
|
Stephen Beaver
|
if (!preg_match("/$interface_regex/", "loopback")) {
|
1216 |
cadeb9fd
|
Phil Davis
|
$loopback_text = gettext("loopback");
|
1217 |
|
|
$iface_description=(isset($pkga['showips']) ? "127.0.0.1 (" . $loopback_text . ")" : $loopback_text);
|
1218 |
eb3743d8
|
Stephen Beaver
|
array_push($ips, array('ip' => 'lo0', 'description' => $iface_description));
|
1219 |
|
|
}
|
1220 |
23f6cdd7
|
Stephen Beaver
|
|
1221 |
eb3743d8
|
Stephen Beaver
|
#show interfaces array on gui
|
1222 |
|
|
$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
|
1223 |
|
|
$multiple = '';
|
1224 |
|
|
$fieldname = $pkga['fieldname'];
|
1225 |
|
|
if (isset($pkga['multiple'])) {
|
1226 |
|
|
$fieldname .= '[]';
|
1227 |
c4b60a9a
|
Colin Fleming
|
$multiple = 'multiple';
|
1228 |
eb3743d8
|
Stephen Beaver
|
}
|
1229 |
23f6cdd7
|
Stephen Beaver
|
|
1230 |
eb3743d8
|
Stephen Beaver
|
$selectedlist = array();
|
1231 |
|
|
$optionlist = array();
|
1232 |
23f6cdd7
|
Stephen Beaver
|
|
1233 |
eb3743d8
|
Stephen Beaver
|
if (is_array($value)) {
|
1234 |
|
|
$values = $value;
|
1235 |
|
|
} else {
|
1236 |
|
|
$values = explode(',', $value);
|
1237 |
|
|
}
|
1238 |
23f6cdd7
|
Stephen Beaver
|
|
1239 |
eb3743d8
|
Stephen Beaver
|
foreach ($ips as $iface) {
|
1240 |
|
|
if (in_array($iface['ip'], $values)) {
|
1241 |
|
|
array_push($selectedlist, $iface['ip']);
|
1242 |
f8ac4407
|
Phil Davis
|
}
|
1243 |
23f6cdd7
|
Stephen Beaver
|
|
1244 |
eb3743d8
|
Stephen Beaver
|
$optionlist[$iface['ip']] = $iface['description'];
|
1245 |
|
|
}
|
1246 |
|
|
|
1247 |
0f649c97
|
Phil Davis
|
if ($grouping) {
|
1248 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Select(
|
1249 |
|
|
$pkga['fieldname'],
|
1250 |
|
|
$pkga['fielddescr'],
|
1251 |
|
|
isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
|
1252 |
|
|
$optionlist,
|
1253 |
|
|
isset($pkga['multiple'])
|
1254 |
|
|
))->setHelp($pkga['description']);
|
1255 |
|
|
} else {
|
1256 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1257 |
|
|
$advanced->addInput(new Form_Select(
|
1258 |
|
|
$pkga['fieldname'],
|
1259 |
|
|
$pkga['fielddescr'],
|
1260 |
|
|
isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
|
1261 |
|
|
$optionlist,
|
1262 |
|
|
isset($pkga['multiple'])
|
1263 |
|
|
))->setHelp($pkga['description']);
|
1264 |
f8ac4407
|
Phil Davis
|
} else {
|
1265 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Select(
|
1266 |
|
|
$pkga['fieldname'],
|
1267 |
|
|
$pkga['fielddescr'],
|
1268 |
|
|
isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
|
1269 |
|
|
$optionlist,
|
1270 |
|
|
isset($pkga['multiple'])
|
1271 |
|
|
))->setHelp($pkga['description']);
|
1272 |
f8ac4407
|
Phil Davis
|
}
|
1273 |
eb3743d8
|
Stephen Beaver
|
}
|
1274 |
23f6cdd7
|
Stephen Beaver
|
|
1275 |
eb3743d8
|
Stephen Beaver
|
break;
|
1276 |
1624b5f1
|
Marcello Coutinho
|
|
1277 |
eb3743d8
|
Stephen Beaver
|
// Create radio button
|
1278 |
|
|
case "radio":
|
1279 |
0f649c97
|
Phil Davis
|
if ($grouping) {
|
1280 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Checkbox(
|
1281 |
|
|
$pkga['fieldname'],
|
1282 |
|
|
$pkga['fielddescr'],
|
1283 |
86c77223
|
Stephen Beaver
|
fixup_string($pkga['description']),
|
1284 |
eb3743d8
|
Stephen Beaver
|
($value == "on"),
|
1285 |
|
|
'on'
|
1286 |
86c77223
|
Stephen Beaver
|
))->displayAsRadio();
|
1287 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1288 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1289 |
|
|
$advanced->addInput(new Form_Checkbox(
|
1290 |
|
|
$pkga['fieldname'],
|
1291 |
|
|
$pkga['fielddescr'],
|
1292 |
86c77223
|
Stephen Beaver
|
fixup_string($pkga['description']),
|
1293 |
23f6cdd7
|
Stephen Beaver
|
($value == "on"),
|
1294 |
|
|
'on'
|
1295 |
86c77223
|
Stephen Beaver
|
))->displayAsRadio();
|
1296 |
f8ac4407
|
Phil Davis
|
} else {
|
1297 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Checkbox(
|
1298 |
|
|
$pkga['fieldname'],
|
1299 |
|
|
$pkga['fielddescr'],
|
1300 |
86c77223
|
Stephen Beaver
|
fixup_string($pkga['description']),
|
1301 |
23f6cdd7
|
Stephen Beaver
|
($value == "on"),
|
1302 |
|
|
'on'
|
1303 |
86c77223
|
Stephen Beaver
|
))->displayAsRadio();
|
1304 |
f8ac4407
|
Phil Davis
|
}
|
1305 |
eb3743d8
|
Stephen Beaver
|
}
|
1306 |
23f6cdd7
|
Stephen Beaver
|
|
1307 |
eb3743d8
|
Stephen Beaver
|
break;
|
1308 |
1624b5f1
|
Marcello Coutinho
|
|
1309 |
eb3743d8
|
Stephen Beaver
|
// Create form button
|
1310 |
|
|
case "button":
|
1311 |
827a3812
|
jim-p
|
$newbtnicon = "fa-save";
|
1312 |
|
|
if ($pkga['buttonicon'] != "") {
|
1313 |
|
|
$newbtnicon = $pkga['buttonicon'];
|
1314 |
|
|
}
|
1315 |
|
|
$newbtnclass = "btn-primary";
|
1316 |
|
|
if ($pkga['buttonclass'] != "") {
|
1317 |
|
|
$newbtnclass = $pkga['buttonclass'];
|
1318 |
|
|
}
|
1319 |
|
|
|
1320 |
eb3743d8
|
Stephen Beaver
|
$newbtn = new Form_Button(
|
1321 |
|
|
$pkga['fieldname'],
|
1322 |
827a3812
|
jim-p
|
$pkga['fieldname'],
|
1323 |
|
|
null,
|
1324 |
|
|
$newbtnicon
|
1325 |
eb3743d8
|
Stephen Beaver
|
);
|
1326 |
827a3812
|
jim-p
|
$newbtn->addClass($newbtnclass);
|
1327 |
23f6cdd7
|
Stephen Beaver
|
|
1328 |
0f649c97
|
Phil Davis
|
if (grouping) {
|
1329 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_StaticText(
|
1330 |
|
|
null,
|
1331 |
|
|
$newbtn . '<br />' . '<div class="help-block">' . fixup_string($pkga['description']) . '</div>'
|
1332 |
|
|
));
|
1333 |
|
|
} else {
|
1334 |
|
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1335 |
0f649c97
|
Phil Davis
|
$advanced->addInput(new Form_StaticText(
|
1336 |
|
|
null,
|
1337 |
|
|
$newbtn . '<br />' . '<div class="help-block">' . fixup_string($pkga['description']) . '</div>'
|
1338 |
|
|
));
|
1339 |
eb3743d8
|
Stephen Beaver
|
} else {
|
1340 |
0f649c97
|
Phil Davis
|
$section->addInput(new Form_StaticText(
|
1341 |
|
|
null,
|
1342 |
|
|
$newbtn . '<br />' . '<div class="help-block">' . fixup_string($pkga['description']) . '</div>'
|
1343 |
|
|
));
|
1344 |
eb3743d8
|
Stephen Beaver
|
}
|
1345 |
|
|
}
|
1346 |
23f6cdd7
|
Stephen Beaver
|
|
1347 |
eb3743d8
|
Stephen Beaver
|
break;
|
1348 |
1624b5f1
|
Marcello Coutinho
|
|
1349 |
eb3743d8
|
Stephen Beaver
|
case "schedule_selection":
|
1350 |
23f6cdd7
|
Stephen Beaver
|
|
1351 |
eb3743d8
|
Stephen Beaver
|
$input = "<select id='{$pkga['fieldname']}' name='{$pkga['fieldname']}'>\n";
|
1352 |
|
|
$schedules = array();
|
1353 |
|
|
$schedules[] = "none";
|
1354 |
|
|
if (is_array($config['schedules']['schedule'])) {
|
1355 |
|
|
foreach ($config['schedules']['schedule'] as $schedule) {
|
1356 |
|
|
if ($schedule['name'] != "") {
|
1357 |
|
|
$schedules[] = $schedule['name'];
|
1358 |
c67b75d1
|
xbipin
|
}
|
1359 |
c6c71b36
|
xbipin
|
}
|
1360 |
eb3743d8
|
Stephen Beaver
|
}
|
1361 |
23f6cdd7
|
Stephen Beaver
|
|
1362 |
eb3743d8
|
Stephen Beaver
|
foreach ($schedules as $schedule) {
|
1363 |
|
|
if ($schedule == "none") {
|
1364 |
|
|
$schedlist[""] = $schedule;
|
1365 |
|
|
} else {
|
1366 |
|
|
$schedlist[$schedule] = $schedule;
|
1367 |
c6c71b36
|
xbipin
|
}
|
1368 |
eb3743d8
|
Stephen Beaver
|
}
|
1369 |
23f6cdd7
|
Stephen Beaver
|
|
1370 |
0f649c97
|
Phil Davis
|
if ($grouping) {
|
1371 |
eb3743d8
|
Stephen Beaver
|
$group->add(new Form_Select(
|
1372 |
|
|
$pkga['fieldname'],
|
1373 |
|
|
$pkga['fielddescr'],
|
1374 |
|
|
$value,
|
1375 |
|
|
$schedlist
|
1376 |
|
|
))->setHelp(fixup_string($pkga['description']));
|
1377 |
|
|
} else {
|
1378 |
23f6cdd7
|
Stephen Beaver
|
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
|
1379 |
|
|
$advanced->addInput(new Form_Select(
|
1380 |
|
|
$pkga['fieldname'],
|
1381 |
|
|
$pkga['fielddescr'],
|
1382 |
|
|
$value,
|
1383 |
|
|
$schedlist
|
1384 |
|
|
))->setHelp(fixup_string($pkga['description']));
|
1385 |
f8ac4407
|
Phil Davis
|
} else {
|
1386 |
23f6cdd7
|
Stephen Beaver
|
$section->addInput(new Form_Select(
|
1387 |
|
|
$pkga['fieldname'],
|
1388 |
|
|
$pkga['fielddescr'],
|
1389 |
|
|
$value,
|
1390 |
|
|
$schedlist
|
1391 |
|
|
))->setHelp(fixup_string($pkga['description']));
|
1392 |
f8ac4407
|
Phil Davis
|
}
|
1393 |
eb3743d8
|
Stephen Beaver
|
}
|
1394 |
f8ac4407
|
Phil Davis
|
|
1395 |
eb3743d8
|
Stephen Beaver
|
break;
|
1396 |
1624b5f1
|
Marcello Coutinho
|
|
1397 |
eb3743d8
|
Stephen Beaver
|
case "rowhelper":
|
1398 |
1624b5f1
|
Marcello Coutinho
|
|
1399 |
01fb4340
|
Steve Beaver
|
// $rowhelpername="row";
|
1400 |
|
|
$rowhelpername=($pkga['fieldname'] ? $pkga['fieldname'] : "row");
|
1401 |
eb3743d8
|
Stephen Beaver
|
$rowcounter = 0;
|
1402 |
|
|
$trc = 0;
|
1403 |
|
|
|
1404 |
|
|
//Use assigned $a_pkg or create an empty array to enter loop
|
1405 |
|
|
if (isset($a_pkg[$id][$rowhelpername])) {
|
1406 |
|
|
$saved_rows=$a_pkg[$id][$rowhelpername];
|
1407 |
|
|
} else {
|
1408 |
|
|
$saved_rows[] = array();
|
1409 |
|
|
}
|
1410 |
|
|
|
1411 |
|
|
$numrows = count($saved_rows) - 1;
|
1412 |
|
|
|
1413 |
|
|
foreach ($saved_rows as $row) {
|
1414 |
|
|
$group = new Form_Group(($rowcounter == 0) ? $pkga['fielddescr']:null);
|
1415 |
|
|
$group->addClass('repeatable');
|
1416 |
|
|
|
1417 |
|
|
foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
1418 |
|
|
unset($value);
|
1419 |
57fc02b1
|
Stephen Beaver
|
$width = null;
|
1420 |
|
|
|
1421 |
eb3743d8
|
Stephen Beaver
|
$fieldname = $rowhelper['fieldname'];
|
1422 |
|
|
$fielddescr = $rowhelper['fielddescr'];
|
1423 |
1624b5f1
|
Marcello Coutinho
|
|
1424 |
4e0f1a1e
|
Chris Buechler
|
// If input validation failed, read the value from the POST data so that the user's input is not lost
|
1425 |
07451ca8
|
Stephen Beaver
|
if ($get_from_post && isset($_POST[$fieldname.$rowcounter])) {
|
1426 |
|
|
$value = $_POST[$fieldname.$rowcounter];
|
1427 |
|
|
} elseif (isset($id) && $a_pkg[$id]) {
|
1428 |
eb3743d8
|
Stephen Beaver
|
$value = $row[$fieldname];
|
1429 |
48396f02
|
Stephen Beaver
|
} elseif ($rowhelper['value'] != "") {
|
1430 |
07451ca8
|
Stephen Beaver
|
$value = $rowhelper['value'];
|
1431 |
f8ac4407
|
Phil Davis
|
}
|
1432 |
eb3743d8
|
Stephen Beaver
|
|
1433 |
|
|
$type = $rowhelper['type'];
|
1434 |
0f649c97
|
Phil Davis
|
if ($type == "input" || $type == "password" || $type == "textarea") {
|
1435 |
6e5cec8e
|
doktornotor
|
if (($rowhelper['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
|
1436 |
|
|
$value = base64_decode($value);
|
1437 |
|
|
}
|
1438 |
|
|
}
|
1439 |
07451ca8
|
Stephen Beaver
|
|
1440 |
eb3743d8
|
Stephen Beaver
|
|
1441 |
|
|
if ($rowhelper['size']) {
|
1442 |
|
|
$size = $rowhelper['size'];
|
1443 |
|
|
} else if ($pkga['size']) {
|
1444 |
|
|
$size = $pkga['size'];
|
1445 |
|
|
} else {
|
1446 |
|
|
$size = "8";
|
1447 |
|
|
}
|
1448 |
|
|
|
1449 |
57fc02b1
|
Stephen Beaver
|
if ($rowhelper['width']) {
|
1450 |
|
|
$width = $rowhelper['width'];
|
1451 |
|
|
}
|
1452 |
|
|
|
1453 |
|
|
display_row($rowcounter, $value, $fieldname, $type, $rowhelper, ($numrows == $rowcounter) ? $fielddescr:null, $width);
|
1454 |
eb3743d8
|
Stephen Beaver
|
|
1455 |
|
|
$text = "";
|
1456 |
|
|
$trc++;
|
1457 |
f8ac4407
|
Phil Davis
|
}
|
1458 |
23f6cdd7
|
Stephen Beaver
|
|
1459 |
eb3743d8
|
Stephen Beaver
|
// Delete row button
|
1460 |
|
|
$group->add(new Form_Button(
|
1461 |
|
|
'deleterow' . $rowcounter,
|
1462 |
faab522f
|
Renato Botelho
|
'Delete',
|
1463 |
5a2512b3
|
Stephen Beaver
|
null,
|
1464 |
|
|
'fa-trash'
|
1465 |
eb3743d8
|
Stephen Beaver
|
))->removeClass('btn-primary')->addClass('btn-warning btn-sm');
|
1466 |
|
|
|
1467 |
|
|
$rowcounter++;
|
1468 |
|
|
$section->add($group);
|
1469 |
|
|
}
|
1470 |
|
|
|
1471 |
|
|
// Add row button
|
1472 |
|
|
$section->addInput(new Form_Button(
|
1473 |
|
|
'addrow',
|
1474 |
faab522f
|
Renato Botelho
|
'Add',
|
1475 |
05e539af
|
jim-p
|
null,
|
1476 |
|
|
'fa-plus'
|
1477 |
|
|
))->addClass('btn-success');
|
1478 |
eb3743d8
|
Stephen Beaver
|
|
1479 |
|
|
break;
|
1480 |
23f6cdd7
|
Stephen Beaver
|
|
1481 |
f8ac4407
|
Phil Davis
|
}
|
1482 |
55c846c4
|
Marcello Coutinho
|
|
1483 |
eb3743d8
|
Stephen Beaver
|
if ($pkga['combinefields'] == "end") {
|
1484 |
|
|
$group->add(new Form_StaticText(
|
1485 |
|
|
null,
|
1486 |
|
|
null
|
1487 |
|
|
));
|
1488 |
23f6cdd7
|
Stephen Beaver
|
|
1489 |
0f649c97
|
Phil Davis
|
if ($advanced) {
|
1490 |
eb3743d8
|
Stephen Beaver
|
$advanced->add($group);
|
1491 |
0f649c97
|
Phil Davis
|
} else {
|
1492 |
eb3743d8
|
Stephen Beaver
|
$section->add($group);
|
1493 |
0f649c97
|
Phil Davis
|
}
|
1494 |
23f6cdd7
|
Stephen Beaver
|
|
1495 |
eb3743d8
|
Stephen Beaver
|
$grouping = false;
|
1496 |
|
|
}
|
1497 |
23f6cdd7
|
Stephen Beaver
|
|
1498 |
eb3743d8
|
Stephen Beaver
|
#increment counter
|
1499 |
|
|
$i++;
|
1500 |
|
|
} // e-o-foreach field described in the XML
|
1501 |
f8ac4407
|
Phil Davis
|
|
1502 |
fff6a2af
|
jim-p
|
if ($section) {
|
1503 |
|
|
$form->add($section);
|
1504 |
|
|
}
|
1505 |
23f6cdd7
|
Stephen Beaver
|
|
1506 |
eb3743d8
|
Stephen Beaver
|
$form->addGlobal(new Form_Input(
|
1507 |
|
|
'id',
|
1508 |
|
|
null,
|
1509 |
|
|
'hidden',
|
1510 |
|
|
$id
|
1511 |
|
|
));
|
1512 |
23f6cdd7
|
Stephen Beaver
|
|
1513 |
eb3743d8
|
Stephen Beaver
|
// If we created an advanced section, add it (and a button) to the form here
|
1514 |
0f649c97
|
Phil Davis
|
if (!empty($advanced)) {
|
1515 |
eb3743d8
|
Stephen Beaver
|
$form->addGlobal(new Form_Button(
|
1516 |
|
|
'showadv',
|
1517 |
faab522f
|
Renato Botelho
|
'Show Advanced Options',
|
1518 |
827a3812
|
jim-p
|
null,
|
1519 |
|
|
'fa-cog'
|
1520 |
347c0214
|
Phil Davis
|
))->setAttribute('type','button')->addClass('btn-info');
|
1521 |
23f6cdd7
|
Stephen Beaver
|
|
1522 |
eb3743d8
|
Stephen Beaver
|
$form->add($advanced);
|
1523 |
|
|
}
|
1524 |
|
|
|
1525 |
|
|
print($form);
|
1526 |
|
|
|
1527 |
|
|
if ($pkg['note'] != "") {
|
1528 |
f78bbe16
|
Phil Davis
|
print_info_box($pkg['note'], 'info');
|
1529 |
4cb4d820
|
Phil Davis
|
}
|
1530 |
eb3743d8
|
Stephen Beaver
|
|
1531 |
4cb4d820
|
Phil Davis
|
if ($pkg['custom_php_after_form_command']) {
|
1532 |
eb3743d8
|
Stephen Beaver
|
eval($pkg['custom_php_after_form_command']);
|
1533 |
23f6cdd7
|
Stephen Beaver
|
}
|
1534 |
|
|
|
1535 |
|
|
if ($pkg['fields']['field'] != "") { ?>
|
1536 |
|
|
<script type="text/javascript">
|
1537 |
|
|
//<![CDATA[
|
1538 |
0f649c97
|
Phil Davis
|
events.push(function() {
|
1539 |
23f6cdd7
|
Stephen Beaver
|
|
1540 |
eb3743d8
|
Stephen Beaver
|
// Hide the advanced section
|
1541 |
|
|
var advanced_visible = false;
|
1542 |
|
|
|
1543 |
|
|
// Hide on page load
|
1544 |
|
|
$('.advancedoptions').hide();
|
1545 |
|
|
|
1546 |
0bc61baa
|
Stephen Beaver
|
// Suppress "Delete row" button if there are fewer than two rows
|
1547 |
|
|
checkLastRow();
|
1548 |
|
|
|
1549 |
|
|
// Show advanced section if you click the showadv button
|
1550 |
eb3743d8
|
Stephen Beaver
|
$("#showadv").click(function() {
|
1551 |
|
|
advanced_visible = !advanced_visible;
|
1552 |
|
|
|
1553 |
0f649c97
|
Phil Davis
|
if (advanced_visible) {
|
1554 |
eb3743d8
|
Stephen Beaver
|
$('.advancedoptions').show();
|
1555 |
|
|
$("#showadv").prop('value', 'Hide advanced Options');
|
1556 |
0f649c97
|
Phil Davis
|
} else {
|
1557 |
eb3743d8
|
Stephen Beaver
|
$('.advancedoptions').hide();
|
1558 |
|
|
$("#showadv").prop('value', 'Show advanced Options');
|
1559 |
|
|
}
|
1560 |
23f6cdd7
|
Stephen Beaver
|
});
|
1561 |
|
|
|
1562 |
eb3743d8
|
Stephen Beaver
|
// Call enablechange function
|
1563 |
|
|
enablechange();
|
1564 |
|
|
});
|
1565 |
|
|
|
1566 |
23f6cdd7
|
Stephen Beaver
|
function enablechange() {
|
1567 |
|
|
<?php
|
1568 |
|
|
foreach ($pkg['fields']['field'] as $field) {
|
1569 |
|
|
if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
|
1570 |
3f98044a
|
Francisco Cavalcante
|
echo "\tif ($('input[name=\"{$field['fieldname']}\"]').prop('checked') == false) {\n";
|
1571 |
23f6cdd7
|
Stephen Beaver
|
|
1572 |
|
|
if (isset($field['enablefields'])) {
|
1573 |
|
|
foreach (explode(',', $field['enablefields']) as $enablefield) {
|
1574 |
3f98044a
|
Francisco Cavalcante
|
echo "\t\tif ($('input[name=\"{$enablefield}\"]').length > 0) {\n";
|
1575 |
|
|
echo "\t\t\t$('input[name=\"{$enablefield}\"]').prop('disabled',true);\n";
|
1576 |
23f6cdd7
|
Stephen Beaver
|
echo "\t\t}\n";
|
1577 |
f8ac4407
|
Phil Davis
|
}
|
1578 |
23f6cdd7
|
Stephen Beaver
|
}
|
1579 |
|
|
|
1580 |
|
|
if (isset($field['checkenablefields'])) {
|
1581 |
|
|
foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
|
1582 |
3f98044a
|
Francisco Cavalcante
|
echo "\t\tif ($('input[name=\"{$checkenablefield}\"]').length > 0) {\n";
|
1583 |
|
|
echo "\t\t\t$('input[name=\"{$checkenablefield}\"]').prop('checked',true);\n";
|
1584 |
23f6cdd7
|
Stephen Beaver
|
echo "\t\t}\n";
|
1585 |
f8ac4407
|
Phil Davis
|
}
|
1586 |
23f6cdd7
|
Stephen Beaver
|
}
|
1587 |
55c846c4
|
Marcello Coutinho
|
|
1588 |
23f6cdd7
|
Stephen Beaver
|
echo "\t}\n\telse {\n";
|
1589 |
7c061036
|
Scott Ullrich
|
|
1590 |
23f6cdd7
|
Stephen Beaver
|
if (isset($field['enablefields'])) {
|
1591 |
|
|
foreach (explode(',', $field['enablefields']) as $enablefield) {
|
1592 |
3f98044a
|
Francisco Cavalcante
|
echo "\t\tif ($('input[name=\"{$enablefield}\"]').length > 0) {\n";
|
1593 |
|
|
echo "\t\t\t$('input[name=\"{$enablefield}\"]').prop('disabled',false);\n";
|
1594 |
23f6cdd7
|
Stephen Beaver
|
echo "\t\t}\n";
|
1595 |
|
|
}
|
1596 |
|
|
}
|
1597 |
95736b54
|
Scott Ullrich
|
|
1598 |
23f6cdd7
|
Stephen Beaver
|
if (isset($field['checkenablefields'])) {
|
1599 |
|
|
foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
|
1600 |
3f98044a
|
Francisco Cavalcante
|
echo "\t\tif ($('input[name=\"{$checkenablefield}\"]').length > 0) {\n";
|
1601 |
|
|
echo "\t\t\t$('input[name=\"{$checkenablefield}\"]').prop('checked',false);\n";
|
1602 |
23f6cdd7
|
Stephen Beaver
|
echo "\t\t}\n";
|
1603 |
|
|
}
|
1604 |
|
|
}
|
1605 |
|
|
|
1606 |
|
|
echo "\t}\n";
|
1607 |
e11aa161
|
Warren Baker
|
}
|
1608 |
|
|
}
|
1609 |
23f6cdd7
|
Stephen Beaver
|
?>
|
1610 |
|
|
}
|
1611 |
|
|
//]]>
|
1612 |
|
|
</script>
|
1613 |
d47013e1
|
Scott Ullrich
|
|
1614 |
31d27c6c
|
Scott Ullrich
|
<?php
|
1615 |
23f6cdd7
|
Stephen Beaver
|
}
|
1616 |
|
|
|
1617 |
|
|
include("foot.inc");
|