Project

General

Profile

Download (10 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">
166
				<a id="btnsearch" type="button" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><?=gettext("Search")?></a>
167
				<a id="btnclear" type="button" title="<?=gettext("Clear")?>" class="btn btn-default btn-sm"><?=gettext("Clear")?></a>
168
			</div>
169
			<div class="col-sm-10 col-sm-offset-2">
170
				<span class="help-block">Enter a search string or *nix regular expression to search package names and descriptions.</span>
171
			</div>
172
		</div>
173
	</div>
174
</div>
175

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

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

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

    
198
		$shortname = $index['name'];
199
		pkg_remove_prefix($shortname);
200

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

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

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

    
241
<script>
242
//<![CDATA[
243
events.push(function(){
244

    
245
	// Initial state & toggle icons of collapsed panel
246
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el){
247
		var body = $(el).parents('.panel').children('.panel-body')
248
		var isOpen = body.hasClass('in');
249

    
250
		$(el).children('i').toggleClass('icon-plus-sign', !isOpen);
251
		$(el).children('i').toggleClass('icon-minus-sign', isOpen);
252

    
253
		body.on('shown.bs.collapse', function(){
254
			$(el).children('i').toggleClass('icon-minus-sign', true);
255
			$(el).children('i').toggleClass('icon-plus-sign', false);
256
		});
257
	});
258

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

    
269
		table.find('tr').each(function (i) {
270
			var $tds = $(this).find('td'),
271
				shortname = $tds.eq(0).text().trim().toLowerCase(),
272
				descr = $tds.eq(2).text().trim().toLowerCase();
273

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

    
287
	// Clear the search term and unhide all rows (that were hidden during a previous search)
288
	$("#btnclear").click(function() {
289
		var table = $("table tbody");
290

    
291
		$('#searchstr').val("");
292

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

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