Project

General

Profile

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