Project

General

Profile

Download (14.3 KB) Statistics
| Branch: | Tag: | Revision:
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
    $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
    }
173
}
174
?>
175
<script>
176
	function setFilter(filtertext) {
177
		$('pkg_filter').value = filtertext;
178
		document.pkgform.submit();
179
	}
180
</script>
181
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
182
	<tr>
183
		<td class="tabcont">
184
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
185
<?php
186
				/* Handle filtering bar A-Z */				
187
				$include_filtering_inputbox = false;
188
				$colspan = 0;
189
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
190
					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
							if($display_maximum_rows < 1) 
199
								if($field['display_maximum_rows']) 
200
									$display_maximum_rows = $field['display_maximum_rows'];
201
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
202
							echo "Filter by: ";
203
							$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
							}
210
							echo "</td></tr>";
211
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
212
							if($field['sortablefields']) {
213
								echo "Filter field: <select name='pkg_filter_type'>";
214
								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
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
226
						}
227
					}
228
				}
229
?>
230
				<tr>
231
<?php
232
				if($display_maximum_rows) {
233
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
234
					$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
					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
						$x=$x+4;
259
					}
260
					echo "</select></td></tr>";
261
					echo "</table>";
262
					echo "</td></tr>";
263
				}
264
				$cols = 0;
265
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
266
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
267
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
268
						$cols++;
269
				    }
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
						if ($column['fieldname'] == "description")
323
							$class = "listbg";
324
						else
325
							$class = "listlr";
326
?>
327
						<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
328
							<?php
329
									$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
330
							    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
					if($pagination_counter == ($display_maximum_rows-1) or 
359
					   $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
						$startingat = $startdisplayingat - $display_maximum_rows;
366
						if($startingat > -1) {
367
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
368
						} else {
369
							if($startingnat > 1) 
370
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
371
						}
372
						$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
						$tmppp++;
379
						$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
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
383
						$final_footer .=  "<font size='2'>Next page >></a>";	
384
						$final_footer .=  "</td></tr></table></td></tr>";
385
						$i = count($evaledvar);
386
						break;
387
					}
388
				}
389
				$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
				<?=$final_footer?>
404
		</table>
405
	</td>
406
</tr>
407
</table>
408
</div></tr></td></table>
409

    
410
</form>
411
<?php include("fend.inc"); ?>
412

    
413
<script type="text/javascript">
414
NiftyCheck();
415
Rounded("div#mainarea","bl br","#FFF","#eeeeee","smooth");
416
</script>
417

    
418
<?php
419
	echo "<!-- filter_fieldname: {$filter_fieldname} -->";
420
	echo "<!-- filter_regex: {$filter_regex} -->";
421
?>
422

    
423
</body>
424
</html>
(115-115/219)