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 = $_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
	else {
57
		echo "File not found " . htmlspecialchars($xml);
58
		exit;
59
	}
60
}
61

    
62
if($pkg['donotsave'] <> "") {
63
	Header("Location: pkg_edit.php?xml=" . $xml);
64
	exit;
65
}
66

    
67
if ($pkg['include_file'] != "") {
68
	require_once($pkg['include_file']);
69
}
70

    
71
$package_name = $pkg['menu'][0]['name'];
72
$section      = $pkg['menu'][0]['section'];
73
$config_path  = $pkg['configpath'];
74
$title	      = $pkg['title'];
75

    
76
if($_REQUEST['startdisplayingat']) 
77
	$startdisplayingat = $_REQUEST['startdisplayingat'];
78

    
79
if($_REQUEST['display_maximum_rows']) 
80
	if($_REQUEST['display_maximum_rows'])
81
		$display_maximum_rows = $_REQUEST['display_maximum_rows'];
82

    
83
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
84

    
85
if ($_GET['act'] == "del") {
86
		// 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
			if($pkg['adddeleteeditpagefields']['columnitem'])
91
			  foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
92
				  ${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
93
			  }
94
		}
95

    
96
		$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
97

    
98
		if ($a_pkg[$_GET['id']]) {
99
			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
	    }
109
}
110

    
111
ob_start();
112

    
113
$iflist = get_configured_interface_with_descr(false, true);
114
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
115

    
116
if($pkg['custom_php_global_functions'] <> "")
117
	eval($pkg['custom_php_global_functions']);
118

    
119
if($pkg['custom_php_command_before_form'] <> "")
120
	eval($pkg['custom_php_command_before_form']);
121

    
122
$pgtitle = array($title);
123
include("head.inc");
124

    
125
?>
126

    
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128
<?php
129
include("fbegin.inc");
130
?>
131
<form action="pkg.php" name="pkgform" method="get">
132
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>'>
133
<? if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
134
<?php if ($savemsg) print_info_box($savemsg); ?>
135
<table width="100%" border="0" cellpadding="0" cellspacing="0">
136
<?php
137
if ($pkg['tabs'] <> "") {
138
    $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
    }
177
}
178
?>
179
<script>
180
	function setFilter(filtertext) {
181
		$('pkg_filter').value = filtertext;
182
		document.pkgform.submit();
183
	}
184
</script>
185
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
186
	<tr>
187
		<td class="tabcont">
188
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
189
<?php
190
				/* Handle filtering bar A-Z */				
191
				$include_filtering_inputbox = false;
192
				$colspan = 0;
193
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
194
					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
							if($display_maximum_rows < 1) 
203
								if($field['display_maximum_rows']) 
204
									$display_maximum_rows = $field['display_maximum_rows'];
205
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
206
							echo "Filter by: ";
207
							$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
							}
214
							echo "</td></tr>";
215
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
216
							if($field['sortablefields']) {
217
								echo "Filter field: <select name='pkg_filter_type'>";
218
								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
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
230
						}
231
					}
232
				}
233
?>
234
				<tr>
235
<?php
236
				if($display_maximum_rows) {
237
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
238
					$page = 1;
239
					$tmpcount = 0;
240
					$tmppp = 0;
241
					if(is_array($evaledvar)) {
242
				    	foreach ($evaledvar as $ipa) {
243
							if($tmpcount == $display_maximum_rows) {
244
								$page++;
245
								$tmpcount = 0;
246
							}
247
							if($tmppp == $startdisplayingat)
248
						 		break;
249
							$tmpcount++;
250
							$tmppp++;
251
						}
252
					}
253
					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
						$x=$x+4;
265
					}
266
					echo "</select></td></tr>";
267
					echo "</table>";
268
					echo "</td></tr>";
269
				}
270
				$cols = 0;
271
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
272
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
273
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
274
						$cols++;
275
				    }
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
						if ($column['fieldname'] == "description")
329
							$class = "listbg";
330
						else
331
							$class = "listlr";
332
?>
333
						<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
334
							<?php
335
								$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
336
							    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
					if($pagination_counter == ($display_maximum_rows-1) or 
365
					   $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
						$startingat = $startdisplayingat - $display_maximum_rows;
372
						if($startingat > -1) {
373
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
374
						} else {
375
							if($startingnat > 1) 
376
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
377
						}
378
						$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
						$tmppp++;
385
						$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
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
389
						$final_footer .=  "<font size='2'>Next page >></a>";	
390
						$final_footer .=  "</td></tr></table></td></tr>";
391
						$i = count($evaledvar);
392
						break;
393
					}
394
				}
395
				$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
				<?=$final_footer?>
410
		</table>
411
	</td>
412
</tr>
413
</table>
414
</div></tr></td></table>
415

    
416
</form>
417
<?php include("fend.inc"); ?>
418

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

    
424
</body>
425
</html>
(117-117/224)