Project

General

Profile

Download (14.4 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
		if(isset($tab['no_drop_down']))
150
			$no_drop_down = true;
151
        $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
		echo '<tr><td>';
176
		display_top_tabs($tab, $no_drop_down);
177
        echo '</td></tr>';
178
    }
179
}
180
?>
181
<script>
182
	function setFilter(filtertext) {
183
		$('pkg_filter').value = filtertext;
184
		document.pkgform.submit();
185
	}
186
</script>
187
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
188
	<tr>
189
		<td class="tabcont">
190
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
191
<?php
192
				/* Handle filtering bar A-Z */				
193
				$include_filtering_inputbox = false;
194
				$colspan = 0;
195
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
196
					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
							if($display_maximum_rows < 1) 
205
								if($field['display_maximum_rows']) 
206
									$display_maximum_rows = $field['display_maximum_rows'];
207
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
208
							echo "Filter by: ";
209
							$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
							}
216
							echo "</td></tr>";
217
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
218
							if($field['sortablefields']) {
219
								echo "Filter field: <select name='pkg_filter_type'>";
220
								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
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
232
						}
233
					}
234
				}
235
?>
236
				<tr>
237
<?php
238
				if($display_maximum_rows) {
239
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
240
					$page = 1;
241
					$tmpcount = 0;
242
					$tmppp = 0;
243
					if(is_array($evaledvar)) {
244
						foreach ($evaledvar as $ipa) {
245
							if($tmpcount == $display_maximum_rows) {
246
								$page++;
247
								$tmpcount = 0;
248
							}
249
							if($tmppp == $startdisplayingat)
250
						 		break;
251
							$tmpcount++;
252
							$tmppp++;
253
						}
254
					}
255
					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
						$x=$x+4;
267
					}
268
					echo "</select></td></tr>";
269
					echo "</table>";
270
					echo "</td></tr>";
271
				}
272
				$cols = 0;
273
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
274
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
275
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
276
						$cols++;
277
				    }
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
						if ($column['fieldname'] == "description")
331
							$class = "listbg";
332
						else
333
							$class = "listlr";
334
?>
335
						<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
336
							<?php
337
								$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
338
							    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
					if($pagination_counter == ($display_maximum_rows-1) or 
367
					   $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
						$startingat = $startdisplayingat - $display_maximum_rows;
374
						if($startingat > -1) {
375
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
376
						} else {
377
							if($startingnat > 1) 
378
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
379
						}
380
						$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
						$tmppp++;
387
						$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
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
391
						$final_footer .=  "<font size='2'>Next page >></a>";	
392
						$final_footer .=  "</td></tr></table></td></tr>";
393
						$i = count($evaledvar);
394
						break;
395
					}
396
				}
397
				$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
				<?=$final_footer?>
412
		</table>
413
	</td>
414
</tr>
415
</table>
416
</div></tr></td></table>
417

    
418
</form>
419
<?php include("fend.inc"); ?>
420

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

    
426
</body>
427
</html>
(121-121/232)