Project

General

Profile

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

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

    
68
ini_set('max_execution_time', '0');
69

    
70
require_once("globals.inc");
71
require_once("guiconfig.inc");
72
require_once("pkg-utils.inc");
73

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

    
83
$pkg_info = get_pkg_info();
84

    
85
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
86

    
87
include("head.inc");
88

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

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

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

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

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

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

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

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

    
137
if (!$pkg_info || !is_array($pkg_info)):
138
?>
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="widget-heading-icon pull-right">
147
			<a data-toggle="collapse" href="#search-panel .panel-body" name="search-panel">
148
				<i class="fa fa-plus-circle"></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
					<th></th>
189
				</tr>
190
			</thead>
191
			<tbody>
192
<?php
193

    
194
	foreach ($pkg_info as $index):
195
		if (isset($index['installed'])) {
196
			continue;
197
		}
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($index['shortname'])?>
210
						</a>
211
					</td>
212

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

    
245
<script type="text/javascript">
246
//<![CDATA[
247
events.push(function() {
248

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

    
254
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
255
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
256

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

    
263
	// Make these controls plain buttons
264
	$("#btnsearch").prop('type', 'button');
265
	$("#btnclear").prop('type', 'button');
266

    
267
	// Search for a term in the package name and/or description
268
	$("#btnsearch").click(function() {
269
		var searchstr = $('#searchstr').val().toLowerCase();
270
		var table = $("table tbody");
271
		var where = $('#where').val();
272

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

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

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

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

    
297
		table.find('tr').each(function (i) {
298
			$(this).show();
299
		});
300
	});
301

    
302
	// Hitting the enter key will do the same as clicking the search button
303
	$("#searchstr").on("keyup", function (event) {
304
	    if (event.keyCode == 13) {
305
	        $("#btnsearch").get(0).click();
306
	    }
307
	});
308
});
309
//]]>
310
</script>
311

    
312
<?php include("foot.inc");
(102-102/228)