Project

General

Profile

Download (10.7 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
##|+PRIV
58
##|*IDENT=page-system-packagemanager
59
##|*NAME=System: Package Manager
60
##|*DESCR=Allow access to the 'System: Package Manager' page.
61
##|*MATCH=pkg_mgr.php*
62
##|-PRIV
63

    
64
ini_set('max_execution_time', '0');
65

    
66
require_once("globals.inc");
67
require_once("guiconfig.inc");
68
require_once("pkg-utils.inc");
69

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

    
79
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
80
include("head.inc");
81

    
82
$tab_array = array();
83
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
84
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
85
display_top_tabs($tab_array);
86

    
87
// A crude way to display a "Please wait" message while hte page is loading
88
ob_implicit_flush(true);
89
print('<div class="temp">');
90
print_info_box(gettext("Please wait while the package data is being retrieved.") . '&nbsp<i class="fa fa-cog fa-spin"></i>');
91
echo str_repeat("<!--           -->", 1000);
92
print('</div>');
93
ob_end_flush();
94
//flush();
95

    
96
$pkg_info = get_pkg_info();
97

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

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

    
114
	// check selected category or define default category to show
115
	if (isset($_REQUEST['category'])) {
116
		$menu_category = $_REQUEST['category'];
117
	} elseif (isset($g['pkg_default_category'])) {
118
		$menu_category = $g['pkg_default_category'];
119
	} else {
120
		$menu_category = "All";
121
	}
122

    
123
	$menu_category = (isset($_REQUEST['category']) ? $_REQUEST['category'] : "All");
124
	$show_category = ($menu_category == "Other" || $menu_category == "All");
125

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

    
135
	$tab_array[] = array(gettext("Other Categories"), $menu_category == "Other" ? true : false, "pkg_mgr.php?category=Other");
136
}
137

    
138
if (!$pkg_info || !is_array($pkg_info)):?>
139

    
140
<div class="alert alert-warning">
141
	<?=gettext("There are currently no packages available for installation.")?>
142
</div>
143
<?php else:?>
144

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

    
177
<div class="panel panel-default">
178
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
179
	<div class="panel-body table-responsive">
180
		<table id="pkgtable" class="table table-striped table-hover">
181
			<thead>
182
				<tr>
183
					<th><?=gettext("Name")?></th>
184
					<th><?=gettext("Version")?></th>
185
					<th><?=gettext("Description")?></th>
186
					<th></th>
187
				</tr>
188
			</thead>
189
			<tbody>
190

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

    
196
	if ($menu_category != "All" && $index['categories'][0] != $menu_category &&
197
	    !($menu_category == "Other" && !in_array($index['categories'][0], $visible_categories))) {
198
		continue;
199
	}
200
?>
201
				<tr>
202
					<td>
203
<?php if ($index['www']):?>
204
						<a title="<?=gettext("Visit official website")?>" target="_blank" href="<?=htmlspecialchars($index['www'])?>">
205
<?php endif;?>
206
							<?=htmlspecialchars($index['shortname'])?>
207
						</a>
208
					</td>
209
					<td>
210
<?php if (!$g['disablepackagehistory']):?>
211
						<a target="_blank" title="<?=gettext("View changelog")?>" href="<?=htmlspecialchars($index['changeloglink'])?>">
212
							<?=htmlspecialchars($index['version'])?></a>
213
<?php else:?>
214
						<?=htmlspecialchars($index['version'])?>
215
<?php endif;?>
216
					</td>
217
					<td>
218
						<?=$index['desc']?>
219
<?php if (is_array($index['deps']) && count($index['deps'])):?>
220
						<br /><br /><?= gettext("Package Dependencies")?>:<ul>
221
	<?php foreach ($index['deps'] as $pdep):?>
222
						<a target="_blank" href="https://freshports.org/<?=$pdep['origin']?>" class="fa fa-globe"><small>&nbsp;<?= basename($pdep['origin']) . '-' . $pdep['version']?></small></a>&emsp;
223
	<?php endforeach;?></ul>
224
<?php endif;?>
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 endforeach;?>
234
			</tbody>
235
		</table>
236
	</div>
237
</div>
238
<?php endif;?>
239

    
240
<script type="text/javascript">
241
//<![CDATA[
242
events.push(function() {
243

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

    
249
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
250
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
251

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

    
258
	// Make these controls plain buttons
259
	$("#btnsearch").prop('type', 'button');
260
	$("#btnclear").prop('type', 'button');
261

    
262
	// Search for a term in the package name and/or description
263
	$("#btnsearch").click(function() {
264
		var searchstr = $('#searchstr').val().toLowerCase();
265
		var table = $("table tbody");
266
		var where = $('#where').val();
267

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

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

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

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

    
292
		table.find('tr').each(function (i) {
293
			$(this).show();
294
		});
295
	});
296

    
297
	// Hitting the enter key will do the same as clicking the search button
298
	$("#searchstr").on("keyup", function (event) {
299
	    if (event.keyCode == 13) {
300
	        $("#btnsearch").get(0).click();
301
	    }
302
	});
303

    
304
	$('.temp').hide();
305
});
306
//]]>
307
</script>
308

    
309
<?php include("foot.inc");
310
?>
(102-102/229)