Project

General

Profile

Download (14.3 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 98bcf1f8 Scott Ullrich
$xml = $_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 98bcf1f8 Scott Ullrich
	else {
57
		echo "File not found " . htmlspecialchars($xml);
58
		exit;
59
	}
60 a7f908db Scott Ullrich
}
61
62 3eaeb703 Scott Ullrich
if($pkg['donotsave'] <> "") {
63 b000f96f Scott Ullrich
	Header("Location: pkg_edit.php?xml=" . $xml);
64
	exit;
65 3eaeb703 Scott Ullrich
}
66
67 7c172009 Scott Ullrich
if ($pkg['include_file'] != "") {
68
	require_once($pkg['include_file']);
69
}
70
71 a28c8b59 Scott Ullrich
$package_name = $pkg['menu'][0]['name'];
72
$section      = $pkg['menu'][0]['section'];
73 a7f908db Scott Ullrich
$config_path  = $pkg['configpath'];
74 7c172009 Scott Ullrich
$title	      = $pkg['title'];
75 e3c4b6b7 Scott Ullrich
76 32c477c5 Scott Ullrich
if($_REQUEST['startdisplayingat']) 
77
	$startdisplayingat = $_REQUEST['startdisplayingat'];
78
79 3ca50a15 Scott Ullrich
if($_REQUEST['display_maximum_rows']) 
80
	if($_REQUEST['display_maximum_rows'])
81
		$display_maximum_rows = $_REQUEST['display_maximum_rows'];
82
83 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
84 e3c4b6b7 Scott Ullrich
85
if ($_GET['act'] == "del") {
86 ef2029df Scott Ullrich
		// 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 e55a0a25 Scott Ullrich
			if($pkg['adddeleteeditpagefields']['columnitem'])
91
			  foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
92 ce696feb Colin Smith
				  ${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
93 e55a0a25 Scott Ullrich
			  }
94 ef2029df Scott Ullrich
		}
95 e3c4b6b7 Scott Ullrich
96 ef2029df Scott Ullrich
		$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
97 e3c4b6b7 Scott Ullrich
98 ef2029df Scott Ullrich
		if ($a_pkg[$_GET['id']]) {
99 8060d89a Scott Ullrich
			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 e3c4b6b7 Scott Ullrich
	    }
109
}
110
111 4b5976b5 Scott Ullrich
ob_start();
112
113 d3ab36dc Ermal Lu?i
$iflist = get_configured_interface_with_descr(false, true);
114 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
115 a7f908db Scott Ullrich
116 194b4e0a Colin Smith
if($pkg['custom_php_global_functions'] <> "")
117 ef2029df Scott Ullrich
	eval($pkg['custom_php_global_functions']);
118 194b4e0a Colin Smith
119 f9a91638 Scott Ullrich
if($pkg['custom_php_command_before_form'] <> "")
120 194b4e0a Colin Smith
	eval($pkg['custom_php_command_before_form']);
121 f9a91638 Scott Ullrich
122 d88c6a9f Scott Ullrich
$pgtitle = array($title);
123 83ddedcd Scott Ullrich
include("head.inc");
124
125 a7f908db Scott Ullrich
?>
126
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128 859329c8 Scott Ullrich
<?php
129
include("fbegin.inc");
130
?>
131 5aa9a4f2 Scott Ullrich
<form action="pkg.php" name="pkgform" method="get">
132 32c477c5 Scott Ullrich
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>'>
133 d8c1a6c5 Scott Ullrich
<? if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
134 a7f908db Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
135 79f6fe7b Colin Smith
<table width="100%" border="0" cellpadding="0" cellspacing="0">
136 7c061036 Scott Ullrich
<?php
137
if ($pkg['tabs'] <> "") {
138 90551807 Warren Baker
    $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 7c061036 Scott Ullrich
    }
177
}
178
?>
179 32c477c5 Scott Ullrich
<script>
180
	function setFilter(filtertext) {
181 bc05ef9f Scott Ullrich
		$('pkg_filter').value = filtertext;
182 32c477c5 Scott Ullrich
		document.pkgform.submit();
183
	}
184
</script>
185 79f6fe7b Colin Smith
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
186 32c477c5 Scott Ullrich
	<tr>
187
		<td class="tabcont">
188
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
189
<?php
190 ef2029df Scott Ullrich
				/* Handle filtering bar A-Z */				
191 32c477c5 Scott Ullrich
				$include_filtering_inputbox = false;
192
				$colspan = 0;
193 ef2029df Scott Ullrich
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
194 32c477c5 Scott Ullrich
					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 3ca50a15 Scott Ullrich
							if($display_maximum_rows < 1) 
203
								if($field['display_maximum_rows']) 
204
									$display_maximum_rows = $field['display_maximum_rows'];
205 32c477c5 Scott Ullrich
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
206 ef2029df Scott Ullrich
							echo "Filter by: ";
207 32c477c5 Scott Ullrich
							$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 549912e3 Scott Ullrich
							}
214 32c477c5 Scott Ullrich
							echo "</td></tr>";
215
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
216
							if($field['sortablefields']) {
217 ef2029df Scott Ullrich
								echo "Filter field: <select name='pkg_filter_type'>";
218 32c477c5 Scott Ullrich
								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 "&nbsp;&nbsp;Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "'> <input type='submit' value='Filter'>";
229 4b5976b5 Scott Ullrich
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
230 32c477c5 Scott Ullrich
						}
231
					}
232
				}
233
?>
234
				<tr>
235
<?php
236 37da0c50 Scott Ullrich
				if($display_maximum_rows) {
237 395dcfbe Scott Ullrich
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
238 37da0c50 Scott Ullrich
					$page = 1;
239
					$tmpcount = 0;
240
					$tmppp = 0;
241 7c50552d Warren Baker
					if(is_array($evaledvar)) {
242 b85f2451 Warren Baker
						foreach ($evaledvar as $ipa) {
243 7c50552d Warren Baker
							if($tmpcount == $display_maximum_rows) {
244
								$page++;
245
								$tmpcount = 0;
246
							}
247
							if($tmppp == $startdisplayingat)
248
						 		break;
249
							$tmpcount++;
250
							$tmppp++;
251 37da0c50 Scott Ullrich
						}
252
					}
253 3377a2bf Scott Ullrich
					echo "<tr><td colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
254
					echo "<table width='100%'>";
255
					echo "<tr>";
256
					echo "<td align='left'>Displaying page $page of $totalpages</b></td>";
257
					echo "<td align='right'>Rows per page: <select onChange='document.pkgform.submit();' name='display_maximum_rows'>";
258
					for($x=0; $x<250; $x++) {
259
						if($x == $display_maximum_rows)
260
							$SELECTED = "SELECTED";
261
						else 
262
							$SELECTED = "";
263
						echo "<option value='$x' $SELECTED>$x</option>\n";
264 5cdf3655 Scott Ullrich
						$x=$x+4;
265 3ca50a15 Scott Ullrich
					}
266 3377a2bf Scott Ullrich
					echo "</select></td></tr>";
267
					echo "</table>";
268
					echo "</td></tr>";
269 37da0c50 Scott Ullrich
				}
270 32c477c5 Scott Ullrich
				$cols = 0;
271
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
272
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
273 ef2029df Scott Ullrich
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
274
						$cols++;
275 32c477c5 Scott Ullrich
				    }
276
				}
277
				echo "</tr>";
278
				$i=0;
279
				$pagination_startingrow=0;
280
				$pagination_counter=0;
281
			    if($evaledvar)
282
			    foreach ($evaledvar as $ip) {
283
				if($startdisplayingat) {
284
					if($i < $startdisplayingat) {
285
						$i++;
286
						continue;
287
					}
288
				}
289
				if($_REQUEST['pkg_filter']) {
290
					// Handle filterered items
291
					if($pkg['fields']['field'] && !$filter_regex) {
292
						// First find the sorting type field if it exists
293
						foreach($pkg['fields']['field'] as $field) {
294
							if($field['type'] == "sorting") {
295
								if($field['sortablefields']['item']) {
296
									foreach($field['sortablefields']['item'] as $sf) {
297
										if($sf['name'] == $_REQUEST['pkg_filter_type']) {
298
											$filter_fieldname = $sf['fieldname'];
299
											$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
300
										}
301
									}
302
								}
303
							}
304
						}
305
					}
306
					// Do we have something to filter on?
307
					unset($filter_matches);
308
					if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
309
						foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
310
							$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
311
							if($column['fieldname'] == $filter_fieldname) {
312
								if($filter_regex) {
313
									//echo "$filter_regex - $fieldname<p/>";
314
									preg_match($filter_regex, $fieldname, $filter_matches);
315
									break;
316
								}
317
							}
318
						}
319
					}
320
					if(!$filter_matches) {
321
						$i++;
322
						continue;
323
					}
324
				}
325
				echo "<tr valign=\"top\">\n";
326
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
327
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
328 4ff99fcb Warren Baker
						if ($column['fieldname'] == "description")
329
							$class = "listbg";
330
						else
331
							$class = "listlr";
332 32c477c5 Scott Ullrich
?>
333 4ff99fcb Warren Baker
						<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
334 32c477c5 Scott Ullrich
							<?php
335 a6419492 Warren Baker
								$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
336 32c477c5 Scott Ullrich
							    if($column['type'] == "checkbox") {
337
									if($fieldname == "") {
338
								    	echo gettext("No");
339
									} else {
340
								    	echo gettext("Yes");
341
									}
342
							    } else if ($column['type'] == "interface") {
343
									echo  $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
344
							    } else {
345
									echo $column['prefix'] . $fieldname . $column['suffix'];
346
							    }
347
							?>
348
						</td>
349
<?php
350
					}
351
?>
352
				<td valign="middle" class="list" nowrap>
353
				<table border="0" cellspacing="0" cellpadding="1">
354
				<tr>
355
				<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>
356
				<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>
357
				</tr>
358
				</table>
359
				</td>
360
<?php
361
				echo "</tr>\n";
362
				// Handle pagination and display_maximum_rows
363
				if($display_maximum_rows) {
364 3ca50a15 Scott Ullrich
					if($pagination_counter == ($display_maximum_rows-1) or 
365 37da0c50 Scott Ullrich
					   $i ==  (count($evaledvar)-1)) {
366
						$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
367
						$final_footer = "";
368
						$final_footer .= "<tr><td colspan='$colcount'>";
369
						$final_footer .=  "<table width='100%'><tr>";
370
						$final_footer .=  "<td align='left'>";
371 32c477c5 Scott Ullrich
						$startingat = $startdisplayingat - $display_maximum_rows;
372
						if($startingat > -1) {
373 1336d082 Scott Ullrich
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
374 32c477c5 Scott Ullrich
						} else {
375
							if($startingnat > 1) 
376 1336d082 Scott Ullrich
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
377 32c477c5 Scott Ullrich
						}
378 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'><< Previous page</a>";
379
						if($tmppp + $display_maximum_rows > count($evaledvar)) 
380
							$endingrecord = count($evaledvar);
381
						else 
382
							$endingrecord = $tmppp + $display_maximum_rows;
383
						$final_footer .=  "</td><td align='center'>";
384 1945741b Scott Ullrich
						$tmppp++;
385 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
386
						$final_footer .=  "</td><td align='right'>&nbsp;";
387
						if(($i+1) < count($evaledvar))
388 1336d082 Scott Ullrich
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
389 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'>Next page >></a>";	
390
						$final_footer .=  "</td></tr></table></td></tr>";
391 de9b760f Scott Ullrich
						$i = count($evaledvar);
392 32c477c5 Scott Ullrich
						break;
393
					}
394 549912e3 Scott Ullrich
				}
395 32c477c5 Scott Ullrich
				$i++;
396
				$pagination_counter++;
397
			    }
398
?>
399
				<tr>
400
					<td colspan="<?=$cols?>"></td>
401
					<td>
402
						<table border="0" cellspacing="0" cellpadding="1">
403
							<tr>
404
								<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>
405
							</tr>
406
						</table>
407
					</td>
408
				</tr>
409 37da0c50 Scott Ullrich
				<?=$final_footer?>
410 32c477c5 Scott Ullrich
		</table>
411
	</td>
412
</tr>
413 a7f908db Scott Ullrich
</table>
414 79f6fe7b Colin Smith
</div></tr></td></table>
415 3d335c4d Scott Ullrich
416 a7f908db Scott Ullrich
</form>
417
<?php include("fend.inc"); ?>
418 323d040b Scott Ullrich
419 b000f96f Scott Ullrich
<?php
420
	echo "<!-- filter_fieldname: {$filter_fieldname} -->";
421
	echo "<!-- filter_regex: {$filter_regex} -->";
422
?>
423
424 a7f908db Scott Ullrich
</body>
425
</html>