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 = htmlspecialchars($_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
|
}
|
57
|
|
58
|
if($pkg['donotsave'] <> "") {
|
59
|
Header("Location: pkg_edit.php?xml=" . $xml);
|
60
|
exit;
|
61
|
}
|
62
|
|
63
|
if ($pkg['include_file'] != "") {
|
64
|
require_once($pkg['include_file']);
|
65
|
}
|
66
|
|
67
|
$package_name = $pkg['menu'][0]['name'];
|
68
|
$section = $pkg['menu'][0]['section'];
|
69
|
$config_path = $pkg['configpath'];
|
70
|
$title = $pkg['title'];
|
71
|
|
72
|
if($_REQUEST['startdisplayingat'])
|
73
|
$startdisplayingat = $_REQUEST['startdisplayingat'];
|
74
|
|
75
|
if($_REQUEST['display_maximum_rows'])
|
76
|
if($_REQUEST['display_maximum_rows'])
|
77
|
$display_maximum_rows = $_REQUEST['display_maximum_rows'];
|
78
|
|
79
|
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
80
|
|
81
|
if ($_GET['act'] == "del") {
|
82
|
// loop through our fieldnames and automatically setup the fieldnames
|
83
|
// in the environment. ie: a fieldname of username with a value of
|
84
|
// testuser would automatically eval $username = "testuser";
|
85
|
foreach ($evaledvar as $ip) {
|
86
|
if($pkg['adddeleteeditpagefields']['columnitem'])
|
87
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
88
|
${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
|
89
|
}
|
90
|
}
|
91
|
|
92
|
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
93
|
|
94
|
if ($a_pkg[$_GET['id']]) {
|
95
|
unset($a_pkg[$_GET['id']]);
|
96
|
write_config();
|
97
|
if($pkg['custom_delete_php_command'] <> "") {
|
98
|
if($pkg['custom_php_command_before_form'] <> "")
|
99
|
eval($pkg['custom_php_command_before_form']);
|
100
|
eval($pkg['custom_delete_php_command']);
|
101
|
}
|
102
|
header("Location: pkg.php?xml=" . $xml);
|
103
|
exit;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
ob_start();
|
108
|
|
109
|
$iflist = get_configured_interface_with_descr(false, true);
|
110
|
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
|
111
|
|
112
|
if($pkg['custom_php_global_functions'] <> "")
|
113
|
eval($pkg['custom_php_global_functions']);
|
114
|
|
115
|
if($pkg['custom_php_command_before_form'] <> "")
|
116
|
eval($pkg['custom_php_command_before_form']);
|
117
|
|
118
|
$pgtitle = array($title);
|
119
|
include("head.inc");
|
120
|
|
121
|
?>
|
122
|
|
123
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
124
|
<?php
|
125
|
include("fbegin.inc");
|
126
|
?>
|
127
|
<form action="pkg.php" name="pkgform" method="get">
|
128
|
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>'>
|
129
|
<? if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
|
130
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
131
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
132
|
<?php
|
133
|
if ($pkg['tabs'] <> "") {
|
134
|
echo '<tr><td>';
|
135
|
$tab_array = array();
|
136
|
foreach($pkg['tabs']['tab'] as $tab) {
|
137
|
if(isset($tab['active'])) {
|
138
|
$active = true;
|
139
|
} else {
|
140
|
$active = false;
|
141
|
}
|
142
|
$urltmp = "";
|
143
|
if($tab['url'] <> "")
|
144
|
$urltmp = $tab['url'];
|
145
|
if($tab['xml'] <> "")
|
146
|
$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
|
147
|
|
148
|
$myurl = getenv("HTTP_HOST");
|
149
|
// eval url so that above $myurl item can be processed if need be.
|
150
|
$url = str_replace('$myurl', $myurl, $urltmp);
|
151
|
$tab_array[] = array(
|
152
|
$tab['text'],
|
153
|
$active,
|
154
|
$url
|
155
|
);
|
156
|
}
|
157
|
display_top_tabs($tab_array);
|
158
|
echo '</td></tr>';
|
159
|
}
|
160
|
?>
|
161
|
<script>
|
162
|
function setFilter(filtertext) {
|
163
|
$('pkg_filter').value = filtertext;
|
164
|
document.pkgform.submit();
|
165
|
}
|
166
|
</script>
|
167
|
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
|
168
|
<tr>
|
169
|
<td class="tabcont">
|
170
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
171
|
<?php
|
172
|
/* Handle filtering bar A-Z */
|
173
|
$include_filtering_inputbox = false;
|
174
|
$colspan = 0;
|
175
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
|
176
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column)
|
177
|
$colspan++;
|
178
|
if($pkg['fields']['field']) {
|
179
|
// First find the sorting type field if it exists
|
180
|
foreach($pkg['fields']['field'] as $field) {
|
181
|
if($field['type'] == "sorting") {
|
182
|
if(isset($field['include_filtering_inputbox']))
|
183
|
$include_filtering_inputbox = true;
|
184
|
if($display_maximum_rows < 1)
|
185
|
if($field['display_maximum_rows'])
|
186
|
$display_maximum_rows = $field['display_maximum_rows'];
|
187
|
echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
|
188
|
echo "Filter by: ";
|
189
|
$isfirst = true;
|
190
|
for($char = 65; $char < 91; $char++) {
|
191
|
if(!$isfirst)
|
192
|
echo " | ";
|
193
|
echo "<a href=\"#\" onClick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
|
194
|
$isfirst = false;
|
195
|
}
|
196
|
echo "</td></tr>";
|
197
|
echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
|
198
|
if($field['sortablefields']) {
|
199
|
echo "Filter field: <select name='pkg_filter_type'>";
|
200
|
foreach($field['sortablefields']['item'] as $si) {
|
201
|
if($si['name'] == $_REQUEST['pkg_filter_type'])
|
202
|
$SELECTED = "SELECTED";
|
203
|
else
|
204
|
$SELECTED = "";
|
205
|
echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
|
206
|
}
|
207
|
echo "</select>";
|
208
|
}
|
209
|
if($include_filtering_inputbox)
|
210
|
echo " Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "'> <input type='submit' value='Filter'>";
|
211
|
echo "</td></tr><tr><td><font siez='-3'> </td></tr>";
|
212
|
}
|
213
|
}
|
214
|
}
|
215
|
?>
|
216
|
<tr>
|
217
|
<?php
|
218
|
if($display_maximum_rows) {
|
219
|
$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
|
220
|
$page = 1;
|
221
|
$tmpcount = 0;
|
222
|
$tmppp = 0;
|
223
|
foreach ($evaledvar as $ipa) {
|
224
|
if($tmpcount == $display_maximum_rows) {
|
225
|
$page++;
|
226
|
$tmpcount = 0;
|
227
|
}
|
228
|
if($tmppp == $startdisplayingat)
|
229
|
break;
|
230
|
$tmpcount++;
|
231
|
$tmppp++;
|
232
|
}
|
233
|
echo "<tr><td colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
|
234
|
echo "<table width='100%'>";
|
235
|
echo "<tr>";
|
236
|
echo "<td align='left'>Displaying page $page of $totalpages</b></td>";
|
237
|
echo "<td align='right'>Rows per page: <select onChange='document.pkgform.submit();' name='display_maximum_rows'>";
|
238
|
for($x=0; $x<250; $x++) {
|
239
|
if($x == $display_maximum_rows)
|
240
|
$SELECTED = "SELECTED";
|
241
|
else
|
242
|
$SELECTED = "";
|
243
|
echo "<option value='$x' $SELECTED>$x</option>\n";
|
244
|
$x=$x+4;
|
245
|
}
|
246
|
echo "</select></td></tr>";
|
247
|
echo "</table>";
|
248
|
echo "</td></tr>";
|
249
|
}
|
250
|
$cols = 0;
|
251
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
|
252
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
253
|
echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
|
254
|
$cols++;
|
255
|
}
|
256
|
}
|
257
|
echo "</tr>";
|
258
|
$i=0;
|
259
|
$pagination_startingrow=0;
|
260
|
$pagination_counter=0;
|
261
|
if($evaledvar)
|
262
|
foreach ($evaledvar as $ip) {
|
263
|
if($startdisplayingat) {
|
264
|
if($i < $startdisplayingat) {
|
265
|
$i++;
|
266
|
continue;
|
267
|
}
|
268
|
}
|
269
|
if($_REQUEST['pkg_filter']) {
|
270
|
// Handle filterered items
|
271
|
if($pkg['fields']['field'] && !$filter_regex) {
|
272
|
// First find the sorting type field if it exists
|
273
|
foreach($pkg['fields']['field'] as $field) {
|
274
|
if($field['type'] == "sorting") {
|
275
|
if($field['sortablefields']['item']) {
|
276
|
foreach($field['sortablefields']['item'] as $sf) {
|
277
|
if($sf['name'] == $_REQUEST['pkg_filter_type']) {
|
278
|
$filter_fieldname = $sf['fieldname'];
|
279
|
$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
|
280
|
}
|
281
|
}
|
282
|
}
|
283
|
}
|
284
|
}
|
285
|
}
|
286
|
// Do we have something to filter on?
|
287
|
unset($filter_matches);
|
288
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
|
289
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
290
|
$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
|
291
|
if($column['fieldname'] == $filter_fieldname) {
|
292
|
if($filter_regex) {
|
293
|
//echo "$filter_regex - $fieldname<p/>";
|
294
|
preg_match($filter_regex, $fieldname, $filter_matches);
|
295
|
break;
|
296
|
}
|
297
|
}
|
298
|
}
|
299
|
}
|
300
|
if(!$filter_matches) {
|
301
|
$i++;
|
302
|
continue;
|
303
|
}
|
304
|
}
|
305
|
echo "<tr valign=\"top\">\n";
|
306
|
if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
|
307
|
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
|
308
|
?>
|
309
|
<td class="listlr" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
|
310
|
<?php
|
311
|
$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
|
312
|
if($column['type'] == "checkbox") {
|
313
|
if($fieldname == "") {
|
314
|
echo gettext("No");
|
315
|
} else {
|
316
|
echo gettext("Yes");
|
317
|
}
|
318
|
} else if ($column['type'] == "interface") {
|
319
|
echo $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
|
320
|
} else {
|
321
|
echo $column['prefix'] . $fieldname . $column['suffix'];
|
322
|
}
|
323
|
?>
|
324
|
</td>
|
325
|
<?php
|
326
|
}
|
327
|
?>
|
328
|
<td valign="middle" class="list" nowrap>
|
329
|
<table border="0" cellspacing="0" cellpadding="1">
|
330
|
<tr>
|
331
|
<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>
|
332
|
<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>
|
333
|
</tr>
|
334
|
</table>
|
335
|
</td>
|
336
|
<?php
|
337
|
echo "</tr>\n";
|
338
|
// Handle pagination and display_maximum_rows
|
339
|
if($display_maximum_rows) {
|
340
|
if($pagination_counter == ($display_maximum_rows-1) or
|
341
|
$i == (count($evaledvar)-1)) {
|
342
|
$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
|
343
|
$final_footer = "";
|
344
|
$final_footer .= "<tr><td colspan='$colcount'>";
|
345
|
$final_footer .= "<table width='100%'><tr>";
|
346
|
$final_footer .= "<td align='left'>";
|
347
|
$startingat = $startdisplayingat - $display_maximum_rows;
|
348
|
if($startingat > -1) {
|
349
|
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
|
350
|
} else {
|
351
|
if($startingnat > 1)
|
352
|
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
|
353
|
}
|
354
|
$final_footer .= "<font size='2'><< Previous page</a>";
|
355
|
if($tmppp + $display_maximum_rows > count($evaledvar))
|
356
|
$endingrecord = count($evaledvar);
|
357
|
else
|
358
|
$endingrecord = $tmppp + $display_maximum_rows;
|
359
|
$final_footer .= "</td><td align='center'>";
|
360
|
$tmppp++;
|
361
|
$final_footer .= "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
|
362
|
$final_footer .= "</td><td align='right'> ";
|
363
|
if(($i+1) < count($evaledvar))
|
364
|
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
|
365
|
$final_footer .= "<font size='2'>Next page >></a>";
|
366
|
$final_footer .= "</td></tr></table></td></tr>";
|
367
|
break;
|
368
|
}
|
369
|
}
|
370
|
$i++;
|
371
|
$pagination_counter++;
|
372
|
}
|
373
|
?>
|
374
|
<tr>
|
375
|
<td colspan="<?=$cols?>"></td>
|
376
|
<td>
|
377
|
<table border="0" cellspacing="0" cellpadding="1">
|
378
|
<tr>
|
379
|
<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>
|
380
|
</tr>
|
381
|
</table>
|
382
|
</td>
|
383
|
</tr>
|
384
|
<?=$final_footer?>
|
385
|
</table>
|
386
|
</td>
|
387
|
</tr>
|
388
|
</table>
|
389
|
</div></tr></td></table>
|
390
|
|
391
|
</form>
|
392
|
<?php include("fend.inc"); ?>
|
393
|
|
394
|
<script type="text/javascript">
|
395
|
NiftyCheck();
|
396
|
Rounded("div#mainarea","bl br","#FFF","#eeeeee","smooth");
|
397
|
</script>
|
398
|
|
399
|
<?php
|
400
|
echo "<!-- filter_fieldname: {$filter_fieldname} -->";
|
401
|
echo "<!-- filter_regex: {$filter_regex} -->";
|
402
|
?>
|
403
|
|
404
|
</body>
|
405
|
</html>
|