1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
pkg.php
|
5
|
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
|
6
|
All rights reserved.
|
7
|
|
8
|
Redistribution and use in source and binary forms, with or without
|
9
|
modification, are permitted provided that the following conditions are met:
|
10
|
|
11
|
1. Redistributions of source code must retain the above copyright notice,
|
12
|
this list of conditions and the following disclaimer.
|
13
|
|
14
|
2. Redistributions in binary form must reproduce the above copyright
|
15
|
notice, this list of conditions and the following disclaimer in the
|
16
|
documentation and/or other materials provided with the distribution.
|
17
|
|
18
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27
|
POSSIBILITY OF SUCH DAMAGE.
|
28
|
*/
|
29
|
/*
|
30
|
pfSense_MODULE: pkgs
|
31
|
*/
|
32
|
|
33
|
##|+PRIV
|
34
|
##|*IDENT=page-package-settings
|
35
|
##|*NAME=Package: Settings page
|
36
|
##|*DESCR=Allow access to the 'Package: Settings' page.
|
37
|
##|*MATCH=pkg.php*
|
38
|
##|-PRIV
|
39
|
|
40
|
require_once("guiconfig.inc");
|
41
|
require_once("pkg-utils.inc");
|
42
|
|
43
|
function gentitle_pkg($pgname) {
|
44
|
global $config;
|
45
|
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
|
46
|
}
|
47
|
|
48
|
$xml = $_REQUEST['xml'];
|
49
|
|
50
|
if($xml == "") {
|
51
|
print_info_box_np(gettext("ERROR: No package defined."));
|
52
|
exit;
|
53
|
} else {
|
54
|
if(file_exists("/usr/local/pkg/" . $xml))
|
55
|
$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
|
56
|
else {
|
57
|
echo "File not found " . htmlspecialchars($xml);
|
58
|
exit;
|
59
|
}
|
60
|
}
|
61
|
|
62
|
if($pkg['donotsave'] <> "") {
|
63
|
Header("Location: pkg_edit.php?xml=" . $xml);
|
64
|
exit;
|
65
|
}
|
66
|
|
67
|
if ($pkg['include_file'] != "") {
|
68
|
require_once($pkg['include_file']);
|
69
|
}
|
70
|
|
71
|
$package_name = $pkg['menu'][0]['name'];
|
72
|
$section = $pkg['menu'][0]['section'];
|
73
|
$config_path = $pkg['configpath'];
|
74
|
$title = $pkg['title'];
|
75
|
|
76
|
if($_REQUEST['startdisplayingat'])
|
77
|
$startdisplayingat = $_REQUEST['startdisplayingat'];
|
78
|
|
79
|
if($_REQUEST['display_maximum_rows'])
|
80
|
if($_REQUEST['display_maximum_rows'])
|
81
|
$display_maximum_rows = $_REQUEST['display_maximum_rows'];
|
82
|
|
83
|
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
84
|
|
85
|
if ($_GET['act'] == "del") {
|
86
|
// loop through our fieldnames and automatically setup the fieldnames
|
87
|
// in the environment. ie: a fieldname of username with a value of
|
88
|
// testuser would automatically eval $username = "testuser";
|
89
|
foreach ($evaledvar as $ip) {
|
90
|
if($pkg['adddeleteeditpagefields']['columnitem'])
|
91
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
92
|
${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
|
93
|
}
|
94
|
}
|
95
|
|
96
|
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
97
|
|
98
|
if ($a_pkg[$_GET['id']]) {
|
99
|
unset($a_pkg[$_GET['id']]);
|
100
|
write_config();
|
101
|
if($pkg['custom_delete_php_command'] <> "") {
|
102
|
if($pkg['custom_php_command_before_form'] <> "")
|
103
|
eval($pkg['custom_php_command_before_form']);
|
104
|
eval($pkg['custom_delete_php_command']);
|
105
|
}
|
106
|
header("Location: pkg.php?xml=" . $xml);
|
107
|
exit;
|
108
|
}
|
109
|
}
|
110
|
|
111
|
ob_start();
|
112
|
|
113
|
$iflist = get_configured_interface_with_descr(false, true);
|
114
|
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
115
|
|
116
|
if($pkg['custom_php_global_functions'] <> "")
|
117
|
eval($pkg['custom_php_global_functions']);
|
118
|
|
119
|
if($pkg['custom_php_command_before_form'] <> "")
|
120
|
eval($pkg['custom_php_command_before_form']);
|
121
|
|
122
|
$pgtitle = array($title);
|
123
|
include("head.inc");
|
124
|
|
125
|
?>
|
126
|
|
127
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
128
|
<?php
|
129
|
include("fbegin.inc");
|
130
|
?>
|
131
|
<form action="pkg.php" name="pkgform" method="get">
|
132
|
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>'>
|
133
|
<? if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
|
134
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
135
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
136
|
<?php
|
137
|
if ($pkg['tabs'] <> "") {
|
138
|
$tab_array = array();
|
139
|
foreach($pkg['tabs']['tab'] as $tab) {
|
140
|
if($tab['tab_level'])
|
141
|
$tab_level = $tab['tab_level'];
|
142
|
else
|
143
|
$tab_level = 1;
|
144
|
if(isset($tab['active'])) {
|
145
|
$active = true;
|
146
|
} else {
|
147
|
$active = false;
|
148
|
}
|
149
|
$urltmp = "";
|
150
|
if($tab['url'] <> "") $urltmp = $tab['url'];
|
151
|
if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
|
152
|
|
153
|
$addresswithport = getenv("HTTP_HOST");
|
154
|
$colonpos = strpos($addresswithport, ":");
|
155
|
if ($colonpos !== False) {
|
156
|
//my url is actually just the IP address of the pfsense box
|
157
|
$myurl = substr($addresswithport, 0, $colonpos);
|
158
|
} else {
|
159
|
$myurl = $addresswithport;
|
160
|
}
|
161
|
// eval url so that above $myurl item can be processed if need be.
|
162
|
$url = str_replace('$myurl', $myurl, $urltmp);
|
163
|
|
164
|
$tab_array[$tab_level][] = array(
|
165
|
$tab['text'],
|
166
|
$active,
|
167
|
$url
|
168
|
);
|
169
|
}
|
170
|
|
171
|
ksort($tab_array);
|
172
|
foreach($tab_array as $tab) {
|
173
|
echo '<tr><td>';
|
174
|
display_top_tabs($tab);
|
175
|
echo '</td></tr>';
|
176
|
}
|
177
|
}
|
178
|
?>
|
179
|
<script>
|
180
|
function setFilter(filtertext) {
|
181
|
$('pkg_filter').value = filtertext;
|
182
|
document.pkgform.submit();
|
183
|
}
|
184
|
</script>
|
185
|
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
|
186
|
<tr>
|
187
|
<td class="tabcont">
|
188
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
189
|
<?php
|
190
|
/* Handle filtering bar A-Z */
|
191
|
$include_filtering_inputbox = false;
|
192
|
$colspan = 0;
|
193
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
|
194
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column)
|
195
|
$colspan++;
|
196
|
if($pkg['fields']['field']) {
|
197
|
// First find the sorting type field if it exists
|
198
|
foreach($pkg['fields']['field'] as $field) {
|
199
|
if($field['type'] == "sorting") {
|
200
|
if(isset($field['include_filtering_inputbox']))
|
201
|
$include_filtering_inputbox = true;
|
202
|
if($display_maximum_rows < 1)
|
203
|
if($field['display_maximum_rows'])
|
204
|
$display_maximum_rows = $field['display_maximum_rows'];
|
205
|
echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
|
206
|
echo "Filter by: ";
|
207
|
$isfirst = true;
|
208
|
for($char = 65; $char < 91; $char++) {
|
209
|
if(!$isfirst)
|
210
|
echo " | ";
|
211
|
echo "<a href=\"#\" onClick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
|
212
|
$isfirst = false;
|
213
|
}
|
214
|
echo "</td></tr>";
|
215
|
echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
|
216
|
if($field['sortablefields']) {
|
217
|
echo "Filter field: <select name='pkg_filter_type'>";
|
218
|
foreach($field['sortablefields']['item'] as $si) {
|
219
|
if($si['name'] == $_REQUEST['pkg_filter_type'])
|
220
|
$SELECTED = "SELECTED";
|
221
|
else
|
222
|
$SELECTED = "";
|
223
|
echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
|
224
|
}
|
225
|
echo "</select>";
|
226
|
}
|
227
|
if($include_filtering_inputbox)
|
228
|
echo " Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "'> <input type='submit' value='Filter'>";
|
229
|
echo "</td></tr><tr><td><font siez='-3'> </td></tr>";
|
230
|
}
|
231
|
}
|
232
|
}
|
233
|
?>
|
234
|
<tr>
|
235
|
<?php
|
236
|
if($display_maximum_rows) {
|
237
|
$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
|
238
|
$page = 1;
|
239
|
$tmpcount = 0;
|
240
|
$tmppp = 0;
|
241
|
foreach ($evaledvar as $ipa) {
|
242
|
if($tmpcount == $display_maximum_rows) {
|
243
|
$page++;
|
244
|
$tmpcount = 0;
|
245
|
}
|
246
|
if($tmppp == $startdisplayingat)
|
247
|
break;
|
248
|
$tmpcount++;
|
249
|
$tmppp++;
|
250
|
}
|
251
|
echo "<tr><td colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
|
252
|
echo "<table width='100%'>";
|
253
|
echo "<tr>";
|
254
|
echo "<td align='left'>Displaying page $page of $totalpages</b></td>";
|
255
|
echo "<td align='right'>Rows per page: <select onChange='document.pkgform.submit();' name='display_maximum_rows'>";
|
256
|
for($x=0; $x<250; $x++) {
|
257
|
if($x == $display_maximum_rows)
|
258
|
$SELECTED = "SELECTED";
|
259
|
else
|
260
|
$SELECTED = "";
|
261
|
echo "<option value='$x' $SELECTED>$x</option>\n";
|
262
|
$x=$x+4;
|
263
|
}
|
264
|
echo "</select></td></tr>";
|
265
|
echo "</table>";
|
266
|
echo "</td></tr>";
|
267
|
}
|
268
|
$cols = 0;
|
269
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
|
270
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
271
|
echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
|
272
|
$cols++;
|
273
|
}
|
274
|
}
|
275
|
echo "</tr>";
|
276
|
$i=0;
|
277
|
$pagination_startingrow=0;
|
278
|
$pagination_counter=0;
|
279
|
if($evaledvar)
|
280
|
foreach ($evaledvar as $ip) {
|
281
|
if($startdisplayingat) {
|
282
|
if($i < $startdisplayingat) {
|
283
|
$i++;
|
284
|
continue;
|
285
|
}
|
286
|
}
|
287
|
if($_REQUEST['pkg_filter']) {
|
288
|
// Handle filterered items
|
289
|
if($pkg['fields']['field'] && !$filter_regex) {
|
290
|
// First find the sorting type field if it exists
|
291
|
foreach($pkg['fields']['field'] as $field) {
|
292
|
if($field['type'] == "sorting") {
|
293
|
if($field['sortablefields']['item']) {
|
294
|
foreach($field['sortablefields']['item'] as $sf) {
|
295
|
if($sf['name'] == $_REQUEST['pkg_filter_type']) {
|
296
|
$filter_fieldname = $sf['fieldname'];
|
297
|
$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
|
298
|
}
|
299
|
}
|
300
|
}
|
301
|
}
|
302
|
}
|
303
|
}
|
304
|
// Do we have something to filter on?
|
305
|
unset($filter_matches);
|
306
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
|
307
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
308
|
$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
|
309
|
if($column['fieldname'] == $filter_fieldname) {
|
310
|
if($filter_regex) {
|
311
|
//echo "$filter_regex - $fieldname<p/>";
|
312
|
preg_match($filter_regex, $fieldname, $filter_matches);
|
313
|
break;
|
314
|
}
|
315
|
}
|
316
|
}
|
317
|
}
|
318
|
if(!$filter_matches) {
|
319
|
$i++;
|
320
|
continue;
|
321
|
}
|
322
|
}
|
323
|
echo "<tr valign=\"top\">\n";
|
324
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
|
325
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
326
|
if ($column['fieldname'] == "description")
|
327
|
$class = "listbg";
|
328
|
else
|
329
|
$class = "listlr";
|
330
|
?>
|
331
|
<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
|
332
|
<?php
|
333
|
$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
|
334
|
if($column['type'] == "checkbox") {
|
335
|
if($fieldname == "") {
|
336
|
echo gettext("No");
|
337
|
} else {
|
338
|
echo gettext("Yes");
|
339
|
}
|
340
|
} else if ($column['type'] == "interface") {
|
341
|
echo $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
|
342
|
} else {
|
343
|
echo $column['prefix'] . $fieldname . $column['suffix'];
|
344
|
}
|
345
|
?>
|
346
|
</td>
|
347
|
<?php
|
348
|
}
|
349
|
?>
|
350
|
<td valign="middle" class="list" nowrap>
|
351
|
<table border="0" cellspacing="0" cellpadding="1">
|
352
|
<tr>
|
353
|
<td valign="middle"><a href="pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
|
354
|
<td valign="middle"><a href="pkg.php?xml=<?=$xml?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this item?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
|
355
|
</tr>
|
356
|
</table>
|
357
|
</td>
|
358
|
<?php
|
359
|
echo "</tr>\n";
|
360
|
// Handle pagination and display_maximum_rows
|
361
|
if($display_maximum_rows) {
|
362
|
if($pagination_counter == ($display_maximum_rows-1) or
|
363
|
$i == (count($evaledvar)-1)) {
|
364
|
$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
|
365
|
$final_footer = "";
|
366
|
$final_footer .= "<tr><td colspan='$colcount'>";
|
367
|
$final_footer .= "<table width='100%'><tr>";
|
368
|
$final_footer .= "<td align='left'>";
|
369
|
$startingat = $startdisplayingat - $display_maximum_rows;
|
370
|
if($startingat > -1) {
|
371
|
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
|
372
|
} else {
|
373
|
if($startingnat > 1)
|
374
|
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
|
375
|
}
|
376
|
$final_footer .= "<font size='2'><< Previous page</a>";
|
377
|
if($tmppp + $display_maximum_rows > count($evaledvar))
|
378
|
$endingrecord = count($evaledvar);
|
379
|
else
|
380
|
$endingrecord = $tmppp + $display_maximum_rows;
|
381
|
$final_footer .= "</td><td align='center'>";
|
382
|
$tmppp++;
|
383
|
$final_footer .= "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
|
384
|
$final_footer .= "</td><td align='right'> ";
|
385
|
if(($i+1) < count($evaledvar))
|
386
|
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
|
387
|
$final_footer .= "<font size='2'>Next page >></a>";
|
388
|
$final_footer .= "</td></tr></table></td></tr>";
|
389
|
$i = count($evaledvar);
|
390
|
break;
|
391
|
}
|
392
|
}
|
393
|
$i++;
|
394
|
$pagination_counter++;
|
395
|
}
|
396
|
?>
|
397
|
<tr>
|
398
|
<td colspan="<?=$cols?>"></td>
|
399
|
<td>
|
400
|
<table border="0" cellspacing="0" cellpadding="1">
|
401
|
<tr>
|
402
|
<td valign="middle"><a href="pkg_edit.php?xml=<?=$xml?>&id=<?=$i?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
|
403
|
</tr>
|
404
|
</table>
|
405
|
</td>
|
406
|
</tr>
|
407
|
<?=$final_footer?>
|
408
|
</table>
|
409
|
</td>
|
410
|
</tr>
|
411
|
</table>
|
412
|
</div></tr></td></table>
|
413
|
|
414
|
</form>
|
415
|
<?php include("fend.inc"); ?>
|
416
|
|
417
|
<?php
|
418
|
echo "<!-- filter_fieldname: {$filter_fieldname} -->";
|
419
|
echo "<!-- filter_regex: {$filter_regex} -->";
|
420
|
?>
|
421
|
|
422
|
</body>
|
423
|
</html>
|