Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	pkg_mgr.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004, 2005 Scott Ullrich
9
 *	Copyright (c)  2013 Marcello Coutinho
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58
/*
59
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
60
	pfSense_MODULE: pkgs
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-system-packagemanager
65
##|*NAME=System: Package Manager page
66
##|*DESCR=Allow access to the 'System: Package Manager' page.
67
##|*MATCH=pkg_mgr.php*
68
##|-PRIV
69

    
70
ini_set('max_execution_time', '0');
71

    
72
require_once("globals.inc");
73
require_once("guiconfig.inc");
74
require_once("pkg-utils.inc");
75

    
76
/* if upgrade in progress, alert user */
77
if(is_subsystem_dirty('packagelock')) {
78
	$pgtitle = array(gettext("System"),gettext("Package Manager"));
79
	include("head.inc");
80
	print_info_box_np("Please wait while packages are reinstalled in the background.");
81
	include("foot.inc");
82
	exit;
83
}
84

    
85
include("head.inc");
86

    
87
$pkg_info = get_pkg_info();
88

    
89
$pgtitle = array(gettext("System"),gettext("Package Manager"));
90

    
91
$tab_array = array();
92
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
93
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
94
display_top_tabs($tab_array);
95

    
96
if($pkg_info) {
97
	//Check categories
98
	$categories=array();
99
	foreach ($pkg_info as $pkg_data) {
100
		if (isset($pkg_data['categories'][0])) {
101
			$categories[$pkg_data['categories'][0]]++;
102
		}
103
	}
104

    
105
	ksort($categories, SORT_STRING|SORT_FLAG_CASE);
106
	$cm_count=0;
107
	$tab_array = array();
108
	$visible_categories=array();
109
	$categories_min_count=($g['pkg_categories_min_count'] ? $g['pkg_categories_min_count'] : 3);
110
	$categories_max_display=($g['pkg_categories_max_display'] ? $g['pkg_categories_max_display'] : 6);
111

    
112
	/* check selected category or define default category to show */
113
	if (isset($_REQUEST['category']))
114
		$menu_category = $_REQUEST['category'];
115
	else if (isset($g['pkg_default_category']))
116
		$menu_category = $g['pkg_default_category'];
117
	else
118
		$menu_category = "All";
119

    
120
	$menu_category = (isset($_REQUEST['category']) ? $_REQUEST['category'] : "All");
121
	$show_category = ($menu_category == "Other" || $menu_category == "All");
122

    
123
	$tab_array[] = array(gettext("All"), $menu_category=="All" ? true : false, "pkg_mgr.php?category=All");
124
	foreach ($categories as $category => $c_count) {
125
		if ($c_count >= $categories_min_count && $cm_count <= $categories_max_display) {
126
			$tab_array[] = array(gettext($category) , $menu_category==$category ? true : false, "pkg_mgr.php?category={$category}");
127
			$visible_categories[]=$category;
128
			$cm_count++;
129
		}
130
	}
131

    
132
	$tab_array[] = array(gettext("Other Categories"), $menu_category=="Other" ? true : false, "pkg_mgr.php?category=Other");
133

    
134
//	if (count($categories) > 1)
135
//		display_top_tabs($tab_array);
136
}
137

    
138
if(!$pkg_info || !is_array($pkg_info)):?>
139
<div class="alert alert-warning">
140
	<?=gettext("There are currently no packages available for installation.")?>
141
</div>
142
<?php else: ?>
143

    
144
<div class="panel panel-default" id="search-panel">
145
	<div class="panel-heading"><?=gettext('Search')?>
146
		<span class="icons pull-right">
147
			<a data-toggle="collapse" href="#search-panel .panel-body" name="search-panel">
148
				<i class="icon-white icon-plus-sign"></i>
149
			</a>
150
		</span>
151
	</div>
152
	<div class="panel-body collapse in">
153
		<div class="form-group">
154
			<label class="col-sm-2 control-label">
155
				Search term
156
			</label>
157
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
158
			<div class="col-sm-2">
159
				<select id="where" class="form-control">
160
					<option value="0"><?=gettext("Name")?></option>
161
					<option value="1"><?=gettext("Description")?></option>
162
					<option value="2" selected><?=gettext("Both")?></option>
163
				</select>
164
			</div>
165
			<div class="col-sm-3"><a id="btnsearch" type="button" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><?=gettext("Search")?></a>
166
			<a id="btnclear" type="button" title="<?=gettext("Clear")?>" class="btn btn-default btn-sm"><?=gettext("Clear")?></a></div>
167
			<div class="col-sm-10 col-sm-offset-2">
168
				<span class="help-block">Enter a search string or *nix regular expression to seach package names and descriptions.</span>
169
			</div>
170
		</div>
171
	</div>
172
</div>
173

    
174
<div class="panel panel-default">
175
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
176
	<div class="panel-body table-responsive">
177
		<table id="pkgtable" class="table table-striped table-hover">
178
			<thead>
179
				<tr>
180
					<th><?=gettext("Name")?></th>
181
<?php if (!$g['disablepackagehistory']):?>
182
					<th><?=gettext("Version")?></th>
183
<?php endif;?>
184

    
185
					<th><?=gettext("Description")?></th>
186
				</tr>
187
			</thead>
188
			<tbody>
189
<?php
190

    
191
	foreach($pkg_info as $index):
192
		if (isset($index['installed'])) {
193
			continue;
194
		}
195

    
196
		$shortname = $index['name'];
197
		pkg_remove_prefix($shortname);
198

    
199
		if ($menu_category != "All" && $index['categories'][0] != $menu_category && !($menu_category == "Other" && !in_array($index['categories'][0], $visible_categories))) {
200
			continue;
201
		}
202

    
203
?>
204
				<tr>
205
					<td>
206
<?php if ($index['www']):?>
207
						<a title="<?=gettext("Visit official website")?>" target="_blank" href="<?=htmlspecialchars($index['www'])?>">
208
<?php endif; ?>
209
							<?=htmlspecialchars($shortname)?>
210
						</a>
211
					</td>
212

    
213
<?php
214
	 if (!$g['disablepackagehistory']):?>
215
					<td>
216
<!-- We no longer have a package revision history URL
217
	$changeloglink is undefined
218
				<a target="_blank" title="<?=gettext("View changelog")?>" href="<?=htmlspecialchars($changeloglink)?>">
219
-->
220
						<?=htmlspecialchars($index['version'])?>
221
<!--
222
				</a>
223
-->
224
					</td>
225
<?php
226
endif;
227
?>
228
					<td>
229
						<?=$index['desc']?>
230
					</td>
231
					<td>
232
						<a title="<?=gettext("Click to install")?>" href="pkg_mgr_install.php?id=<?=$index['name']?>" class="btn btn-success btn-sm">install</a>
233
<?php if(!$g['disablepackageinfo'] && $index['pkginfolink'] && $index['pkginfolink'] != $index['www']):?>
234
						<a target="_blank" title="<?=gettext("View more information")?>" href="<?=htmlspecialchars($index['pkginfolink'])?>" class="btn btn-default btn-sm">info</a>
235
<?php endif;?>
236
					</td>
237
				</tr>
238
<?php
239
	endforeach;
240
endif;?>
241
			</tbody>
242
		</table>
243
	</div>
244
</div>
245

    
246
<script>
247
//<![CDATA[
248
events.push(function(){
249

    
250
	// Initial state & toggle icons of collapsed panel
251
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el){
252
		var body = $(el).parents('.panel').children('.panel-body')
253
		var isOpen = body.hasClass('in');
254

    
255
		$(el).children('i').toggleClass('icon-plus-sign', !isOpen);
256
		$(el).children('i').toggleClass('icon-minus-sign', isOpen);
257

    
258
		body.on('shown.bs.collapse', function(){
259
			$(el).children('i').toggleClass('icon-minus-sign', true);
260
			$(el).children('i').toggleClass('icon-plus-sign', false);
261
		});
262
	});
263

    
264
	// Make these controls plain buttons
265
	$("#btnsearch").prop('type' ,'button');
266
	$("#btnclear").prop('type' ,'button');
267
	
268
	// Search for a term in the package name and/or description
269
	$("#btnsearch").click(function() {
270
		var searchstr = $('#searchstr').val().toLowerCase();
271
		var table = $("table tbody");
272
		var where = $('#where').val();
273

    
274
		table.find('tr').each(function (i) {
275
			var $tds = $(this).find('td'),
276
				shortname = $tds.eq(0).text().trim().toLowerCase(),
277
				descr = $tds.eq(2).text().trim().toLowerCase();
278

    
279
			regexp = new RegExp(searchstr);
280
			if(searchstr.length > 0) {
281
				if( !(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
282
					$(this).hide();
283
				} else {
284
					$(this).show();
285
				}
286
			} else {
287
				 $(this).show();	// A blank search string shows all
288
			}
289
		});
290
	});
291

    
292
	// Clear the search term and unhide all rows (that were hidden during a previous search)
293
	$("#btnclear").click(function() {
294
		var table = $("table tbody");
295

    
296
		$('#searchstr').val("");
297

    
298
		table.find('tr').each(function (i) {
299
			$(this).show();
300
		});
301
	});
302
	
303
	// Hitting the enter key will do the same as clicking the search button
304
	$("#searchstr").on("keyup", function (event) {
305
	    if (event.keyCode==13) {
306
	        $("#btnsearch").get(0).click();
307
	    }
308
	});
309
});
310
//]]>
311
</script>
312

    
313
<?php include("foot.inc");
(115-115/234)