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 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 90551807 Warren Baker
    $tab_array = array();
135
    foreach($pkg['tabs']['tab'] as $tab) {
136
        if($tab['tab_level'])
137
            $tab_level = $tab['tab_level'];
138
        else
139
            $tab_level = 1;
140
        if(isset($tab['active'])) {
141
            $active = true;
142
        } else {
143
            $active = false;
144
        }
145
        $urltmp = "";
146
        if($tab['url'] <> "") $urltmp = $tab['url'];
147
        if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
148
149
        $addresswithport = getenv("HTTP_HOST");
150
        $colonpos = strpos($addresswithport, ":");
151
        if ($colonpos !== False) {
152
            //my url is actually just the IP address of the pfsense box
153
            $myurl = substr($addresswithport, 0, $colonpos);
154
        } else {
155
            $myurl = $addresswithport;
156
        }
157
        // eval url so that above $myurl item can be processed if need be.
158
        $url = str_replace('$myurl', $myurl, $urltmp);
159
160
        $tab_array[$tab_level][] = array(
161
                        $tab['text'],
162
                        $active,
163
                        $url
164
                    );
165
    }
166
167
    ksort($tab_array);
168
    foreach($tab_array as $tab) {
169
        echo '<tr><td>';
170
        display_top_tabs($tab);
171
        echo '</td></tr>';
172 7c061036 Scott Ullrich
    }
173
}
174
?>
175 32c477c5 Scott Ullrich
<script>
176
	function setFilter(filtertext) {
177 bc05ef9f Scott Ullrich
		$('pkg_filter').value = filtertext;
178 32c477c5 Scott Ullrich
		document.pkgform.submit();
179
	}
180
</script>
181 79f6fe7b Colin Smith
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
182 32c477c5 Scott Ullrich
	<tr>
183
		<td class="tabcont">
184
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
185
<?php
186 ef2029df Scott Ullrich
				/* Handle filtering bar A-Z */				
187 32c477c5 Scott Ullrich
				$include_filtering_inputbox = false;
188
				$colspan = 0;
189 ef2029df Scott Ullrich
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
190 32c477c5 Scott Ullrich
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column)
191
						$colspan++;
192
				if($pkg['fields']['field']) {
193
					// First find the sorting type field if it exists
194
					foreach($pkg['fields']['field'] as $field) {
195
						if($field['type'] == "sorting") {
196
							if(isset($field['include_filtering_inputbox'])) 
197
								$include_filtering_inputbox = true;
198 3ca50a15 Scott Ullrich
							if($display_maximum_rows < 1) 
199
								if($field['display_maximum_rows']) 
200
									$display_maximum_rows = $field['display_maximum_rows'];
201 32c477c5 Scott Ullrich
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
202 ef2029df Scott Ullrich
							echo "Filter by: ";
203 32c477c5 Scott Ullrich
							$isfirst = true;
204
							for($char = 65; $char < 91; $char++) {
205
								if(!$isfirst) 
206
									echo " | ";
207
								echo "<a href=\"#\" onClick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
208
								$isfirst = false;
209 549912e3 Scott Ullrich
							}
210 32c477c5 Scott Ullrich
							echo "</td></tr>";
211
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
212
							if($field['sortablefields']) {
213 ef2029df Scott Ullrich
								echo "Filter field: <select name='pkg_filter_type'>";
214 32c477c5 Scott Ullrich
								foreach($field['sortablefields']['item'] as $si) {
215
									if($si['name'] == $_REQUEST['pkg_filter_type']) 
216
										$SELECTED = "SELECTED";
217
									else 
218
										$SELECTED = "";
219
									echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
220
								}
221
								echo "</select>";
222
							}
223
							if($include_filtering_inputbox) 
224
								echo "&nbsp;&nbsp;Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "'> <input type='submit' value='Filter'>";
225 4b5976b5 Scott Ullrich
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
226 32c477c5 Scott Ullrich
						}
227
					}
228
				}
229
?>
230
				<tr>
231
<?php
232 37da0c50 Scott Ullrich
				if($display_maximum_rows) {
233 395dcfbe Scott Ullrich
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
234 37da0c50 Scott Ullrich
					$page = 1;
235
					$tmpcount = 0;
236
					$tmppp = 0;
237
				    foreach ($evaledvar as $ipa) {
238
						if($tmpcount == $display_maximum_rows) {
239
							$page++;
240
							$tmpcount = 0;
241
						}
242
						if($tmppp == $startdisplayingat)
243
						 	break;
244
						$tmpcount++;
245
						$tmppp++;
246
					}
247 3377a2bf Scott Ullrich
					echo "<tr><td colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
248
					echo "<table width='100%'>";
249
					echo "<tr>";
250
					echo "<td align='left'>Displaying page $page of $totalpages</b></td>";
251
					echo "<td align='right'>Rows per page: <select onChange='document.pkgform.submit();' name='display_maximum_rows'>";
252
					for($x=0; $x<250; $x++) {
253
						if($x == $display_maximum_rows)
254
							$SELECTED = "SELECTED";
255
						else 
256
							$SELECTED = "";
257
						echo "<option value='$x' $SELECTED>$x</option>\n";
258 5cdf3655 Scott Ullrich
						$x=$x+4;
259 3ca50a15 Scott Ullrich
					}
260 3377a2bf Scott Ullrich
					echo "</select></td></tr>";
261
					echo "</table>";
262
					echo "</td></tr>";
263 37da0c50 Scott Ullrich
				}
264 32c477c5 Scott Ullrich
				$cols = 0;
265
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
266
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
267 ef2029df Scott Ullrich
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
268
						$cols++;
269 32c477c5 Scott Ullrich
				    }
270
				}
271
				echo "</tr>";
272
				$i=0;
273
				$pagination_startingrow=0;
274
				$pagination_counter=0;
275
			    if($evaledvar)
276
			    foreach ($evaledvar as $ip) {
277
				if($startdisplayingat) {
278
					if($i < $startdisplayingat) {
279
						$i++;
280
						continue;
281
					}
282
				}
283
				if($_REQUEST['pkg_filter']) {
284
					// Handle filterered items
285
					if($pkg['fields']['field'] && !$filter_regex) {
286
						// First find the sorting type field if it exists
287
						foreach($pkg['fields']['field'] as $field) {
288
							if($field['type'] == "sorting") {
289
								if($field['sortablefields']['item']) {
290
									foreach($field['sortablefields']['item'] as $sf) {
291
										if($sf['name'] == $_REQUEST['pkg_filter_type']) {
292
											$filter_fieldname = $sf['fieldname'];
293
											$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
294
										}
295
									}
296
								}
297
							}
298
						}
299
					}
300
					// Do we have something to filter on?
301
					unset($filter_matches);
302
					if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
303
						foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
304
							$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
305
							if($column['fieldname'] == $filter_fieldname) {
306
								if($filter_regex) {
307
									//echo "$filter_regex - $fieldname<p/>";
308
									preg_match($filter_regex, $fieldname, $filter_matches);
309
									break;
310
								}
311
							}
312
						}
313
					}
314
					if(!$filter_matches) {
315
						$i++;
316
						continue;
317
					}
318
				}
319
				echo "<tr valign=\"top\">\n";
320
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
321
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
322 4ff99fcb Warren Baker
						if ($column['fieldname'] == "description")
323
							$class = "listbg";
324
						else
325
							$class = "listlr";
326 32c477c5 Scott Ullrich
?>
327 4ff99fcb Warren Baker
						<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
328 32c477c5 Scott Ullrich
							<?php
329 a6419492 Warren Baker
								$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
330 32c477c5 Scott Ullrich
							    if($column['type'] == "checkbox") {
331
									if($fieldname == "") {
332
								    	echo gettext("No");
333
									} else {
334
								    	echo gettext("Yes");
335
									}
336
							    } else if ($column['type'] == "interface") {
337
									echo  $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
338
							    } else {
339
									echo $column['prefix'] . $fieldname . $column['suffix'];
340
							    }
341
							?>
342
						</td>
343
<?php
344
					}
345
?>
346
				<td valign="middle" class="list" nowrap>
347
				<table border="0" cellspacing="0" cellpadding="1">
348
				<tr>
349
				<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>
350
				<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>
351
				</tr>
352
				</table>
353
				</td>
354
<?php
355
				echo "</tr>\n";
356
				// Handle pagination and display_maximum_rows
357
				if($display_maximum_rows) {
358 3ca50a15 Scott Ullrich
					if($pagination_counter == ($display_maximum_rows-1) or 
359 37da0c50 Scott Ullrich
					   $i ==  (count($evaledvar)-1)) {
360
						$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
361
						$final_footer = "";
362
						$final_footer .= "<tr><td colspan='$colcount'>";
363
						$final_footer .=  "<table width='100%'><tr>";
364
						$final_footer .=  "<td align='left'>";
365 32c477c5 Scott Ullrich
						$startingat = $startdisplayingat - $display_maximum_rows;
366
						if($startingat > -1) {
367 1336d082 Scott Ullrich
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
368 32c477c5 Scott Ullrich
						} else {
369
							if($startingnat > 1) 
370 1336d082 Scott Ullrich
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
371 32c477c5 Scott Ullrich
						}
372 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'><< Previous page</a>";
373
						if($tmppp + $display_maximum_rows > count($evaledvar)) 
374
							$endingrecord = count($evaledvar);
375
						else 
376
							$endingrecord = $tmppp + $display_maximum_rows;
377
						$final_footer .=  "</td><td align='center'>";
378 1945741b Scott Ullrich
						$tmppp++;
379 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
380
						$final_footer .=  "</td><td align='right'>&nbsp;";
381
						if(($i+1) < count($evaledvar))
382 1336d082 Scott Ullrich
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
383 37da0c50 Scott Ullrich
						$final_footer .=  "<font size='2'>Next page >></a>";	
384
						$final_footer .=  "</td></tr></table></td></tr>";
385 de9b760f Scott Ullrich
						$i = count($evaledvar);
386 32c477c5 Scott Ullrich
						break;
387
					}
388 549912e3 Scott Ullrich
				}
389 32c477c5 Scott Ullrich
				$i++;
390
				$pagination_counter++;
391
			    }
392
?>
393
				<tr>
394
					<td colspan="<?=$cols?>"></td>
395
					<td>
396
						<table border="0" cellspacing="0" cellpadding="1">
397
							<tr>
398
								<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>
399
							</tr>
400
						</table>
401
					</td>
402
				</tr>
403 37da0c50 Scott Ullrich
				<?=$final_footer?>
404 32c477c5 Scott Ullrich
		</table>
405
	</td>
406
</tr>
407 a7f908db Scott Ullrich
</table>
408 79f6fe7b Colin Smith
</div></tr></td></table>
409 3d335c4d Scott Ullrich
410 a7f908db Scott Ullrich
</form>
411
<?php include("fend.inc"); ?>
412 323d040b Scott Ullrich
413
<script type="text/javascript">
414
NiftyCheck();
415
Rounded("div#mainarea","bl br","#FFF","#eeeeee","smooth");
416
</script>
417
418 b000f96f Scott Ullrich
<?php
419
	echo "<!-- filter_fieldname: {$filter_fieldname} -->";
420
	echo "<!-- filter_regex: {$filter_regex} -->";
421
?>
422
423 a7f908db Scott Ullrich
</body>
424
</html>