Project

General

Profile

Download (13.5 KB) Statistics
| Branch: | Tag: | Revision:
1 a7f908db Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 a7f908db Scott Ullrich
/*
4
    pkg.php
5 4f6a5e6a Scott Ullrich
    Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
6 a7f908db Scott Ullrich
    All rights reserved.
7
8
    Redistribution and use in source and binary forms, with or without
9
    modification, are permitted provided that the following conditions are met:
10
11
    1. Redistributions of source code must retain the above copyright notice,
12
       this list of conditions and the following disclaimer.
13
14
    2. Redistributions in binary form must reproduce the above copyright
15
       notice, this list of conditions and the following disclaimer in the
16
       documentation and/or other materials provided with the distribution.
17
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29 1d333258 Scott Ullrich
/*
30
	pfSense_MODULE:	pkgs
31
*/
32 a7f908db Scott Ullrich
33 6b07c15a Matthew Grooms
##|+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 e4bf1c19 Colin Smith
require_once("guiconfig.inc");
41
require_once("pkg-utils.inc");
42 a7f908db Scott Ullrich
43
function gentitle_pkg($pgname) {
44 e3c4b6b7 Scott Ullrich
	global $config;
45
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
46 a7f908db Scott Ullrich
}
47
48 32c477c5 Scott Ullrich
$xml = htmlspecialchars($_REQUEST['xml']);
49 a7f908db Scott Ullrich
50
if($xml == "") {
51 ef2029df Scott Ullrich
	print_info_box_np(gettext("ERROR: No package defined."));
52 b000f96f Scott Ullrich
	exit;
53 a7f908db Scott Ullrich
} else {
54 b000f96f Scott Ullrich
	if(file_exists("/usr/local/pkg/" . $xml))
55
		$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
56 a7f908db Scott Ullrich
}
57
58 3eaeb703 Scott Ullrich
if($pkg['donotsave'] <> "") {
59 b000f96f Scott Ullrich
	Header("Location: pkg_edit.php?xml=" . $xml);
60
	exit;
61 3eaeb703 Scott Ullrich
}
62
63 7c172009 Scott Ullrich
if ($pkg['include_file'] != "") {
64
	require_once($pkg['include_file']);
65
}
66
67 a28c8b59 Scott Ullrich
$package_name = $pkg['menu'][0]['name'];
68
$section      = $pkg['menu'][0]['section'];
69 a7f908db Scott Ullrich
$config_path  = $pkg['configpath'];
70 7c172009 Scott Ullrich
$title	      = $pkg['title'];
71 e3c4b6b7 Scott Ullrich
72 32c477c5 Scott Ullrich
if($_REQUEST['startdisplayingat']) 
73
	$startdisplayingat = $_REQUEST['startdisplayingat'];
74
75 3ca50a15 Scott Ullrich
if($_REQUEST['display_maximum_rows']) 
76
	if($_REQUEST['display_maximum_rows'])
77
		$display_maximum_rows = $_REQUEST['display_maximum_rows'];
78
79 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
80 e3c4b6b7 Scott Ullrich
81
if ($_GET['act'] == "del") {
82 ef2029df Scott Ullrich
		// 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 e55a0a25 Scott Ullrich
			if($pkg['adddeleteeditpagefields']['columnitem'])
87
			  foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
88 ce696feb Colin Smith
				  ${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
89 e55a0a25 Scott Ullrich
			  }
90 ef2029df Scott Ullrich
		}
91 e3c4b6b7 Scott Ullrich
92 ef2029df Scott Ullrich
		$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
93 e3c4b6b7 Scott Ullrich
94 ef2029df Scott Ullrich
		if ($a_pkg[$_GET['id']]) {
95 8060d89a Scott Ullrich
			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 e3c4b6b7 Scott Ullrich
	    }
105
}
106
107 4b5976b5 Scott Ullrich
ob_start();
108
109 d3ab36dc Ermal Lu?i
$iflist = get_configured_interface_with_descr(false, true);
110 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
111 a7f908db Scott Ullrich
112 194b4e0a Colin Smith
if($pkg['custom_php_global_functions'] <> "")
113 ef2029df Scott Ullrich
	eval($pkg['custom_php_global_functions']);
114 194b4e0a Colin Smith
115 f9a91638 Scott Ullrich
if($pkg['custom_php_command_before_form'] <> "")
116 194b4e0a Colin Smith
	eval($pkg['custom_php_command_before_form']);
117 f9a91638 Scott Ullrich
118 d88c6a9f Scott Ullrich
$pgtitle = array($title);
119 83ddedcd Scott Ullrich
include("head.inc");
120
121 a7f908db Scott Ullrich
?>
122
123
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
124 859329c8 Scott Ullrich
<?php
125
include("fbegin.inc");
126
?>
127 5aa9a4f2 Scott Ullrich
<form action="pkg.php" name="pkgform" method="get">
128 32c477c5 Scott Ullrich
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>'>
129 d8c1a6c5 Scott Ullrich
<? if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
130 a7f908db Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
131 79f6fe7b Colin Smith
<table width="100%" border="0" cellpadding="0" cellspacing="0">
132 7c061036 Scott Ullrich
<?php
133
if ($pkg['tabs'] <> "") {
134 ef2029df Scott Ullrich
	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 79f6fe7b Colin Smith
148 ef2029df Scott Ullrich
		$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 7c061036 Scott Ullrich
    }
157 ef2029df Scott Ullrich
	display_top_tabs($tab_array);
158
	echo '</td></tr>';
159 7c061036 Scott Ullrich
}
160
?>
161 32c477c5 Scott Ullrich
<script>
162
	function setFilter(filtertext) {
163 bc05ef9f Scott Ullrich
		$('pkg_filter').value = filtertext;
164 32c477c5 Scott Ullrich
		document.pkgform.submit();
165
	}
166
</script>
167 79f6fe7b Colin Smith
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
168 32c477c5 Scott Ullrich
	<tr>
169
		<td class="tabcont">
170
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
171
<?php
172 ef2029df Scott Ullrich
				/* Handle filtering bar A-Z */				
173 32c477c5 Scott Ullrich
				$include_filtering_inputbox = false;
174
				$colspan = 0;
175 ef2029df Scott Ullrich
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
176 32c477c5 Scott Ullrich
					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 3ca50a15 Scott Ullrich
							if($display_maximum_rows < 1) 
185
								if($field['display_maximum_rows']) 
186
									$display_maximum_rows = $field['display_maximum_rows'];
187 32c477c5 Scott Ullrich
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
188 ef2029df Scott Ullrich
							echo "Filter by: ";
189 32c477c5 Scott Ullrich
							$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 549912e3 Scott Ullrich
							}
196 32c477c5 Scott Ullrich
							echo "</td></tr>";
197
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
198
							if($field['sortablefields']) {
199 ef2029df Scott Ullrich
								echo "Filter field: <select name='pkg_filter_type'>";
200 32c477c5 Scott Ullrich
								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 "&nbsp;&nbsp;Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "'> <input type='submit' value='Filter'>";
211 4b5976b5 Scott Ullrich
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
212 32c477c5 Scott Ullrich
						}
213
					}
214
				}
215
?>
216
				<tr>
217
<?php
218 37da0c50 Scott Ullrich
				if($display_maximum_rows) {
219 395dcfbe Scott Ullrich
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
220 37da0c50 Scott Ullrich
					$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 3377a2bf Scott Ullrich
					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 5cdf3655 Scott Ullrich
						$x=$x+4;
245 3ca50a15 Scott Ullrich
					}
246 3377a2bf Scott Ullrich
					echo "</select></td></tr>";
247
					echo "</table>";
248
					echo "</td></tr>";
249 37da0c50 Scott Ullrich
				}
250 32c477c5 Scott Ullrich
				$cols = 0;
251
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
252
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
253 ef2029df Scott Ullrich
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
254
						$cols++;
255 32c477c5 Scott Ullrich
				    }
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 3ca50a15 Scott Ullrich
					if($pagination_counter == ($display_maximum_rows-1) or 
341 37da0c50 Scott Ullrich
					   $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 32c477c5 Scott Ullrich
						$startingat = $startdisplayingat - $display_maximum_rows;
348
						if($startingat > -1) {
349 1336d082 Scott Ullrich
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
350 32c477c5 Scott Ullrich
						} else {
351
							if($startingnat > 1) 
352 1336d082 Scott Ullrich
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
353 32c477c5 Scott Ullrich
						}
354 37da0c50 Scott Ullrich
						$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 1945741b Scott Ullrich
						$tmppp++;
361 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
362
						$final_footer .=  "</td><td align='right'>&nbsp;";
363
						if(($i+1) < count($evaledvar))
364 1336d082 Scott Ullrich
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
365 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'>Next page >></a>";	
366
						$final_footer .=  "</td></tr></table></td></tr>";
367 32c477c5 Scott Ullrich
						break;
368
					}
369 549912e3 Scott Ullrich
				}
370 32c477c5 Scott Ullrich
				$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 37da0c50 Scott Ullrich
				<?=$final_footer?>
385 32c477c5 Scott Ullrich
		</table>
386
	</td>
387
</tr>
388 a7f908db Scott Ullrich
</table>
389 79f6fe7b Colin Smith
</div></tr></td></table>
390 3d335c4d Scott Ullrich
391 a7f908db Scott Ullrich
</form>
392
<?php include("fend.inc"); ?>
393 323d040b Scott Ullrich
394
<script type="text/javascript">
395
NiftyCheck();
396
Rounded("div#mainarea","bl br","#FFF","#eeeeee","smooth");
397
</script>
398
399 b000f96f Scott Ullrich
<?php
400
	echo "<!-- filter_fieldname: {$filter_fieldname} -->";
401
	echo "<!-- filter_regex: {$filter_regex} -->";
402
?>
403
404 a7f908db Scott Ullrich
</body>
405
</html>