Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1 ee11cc6e Scott Ullrich
<?php
2
/*
3 29840546 Renato Botelho
	pkg_mgr.php
4 ee11cc6e Scott Ullrich
*/
5 239b5161 Stephen Beaver
/* ====================================================================
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 ee11cc6e Scott Ullrich
57 6b07c15a Matthew Grooms
##|+PRIV
58
##|*IDENT=page-system-packagemanager
59 5230f468 jim-p
##|*NAME=System: Package Manager
60 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Package Manager' page.
61
##|*MATCH=pkg_mgr.php*
62
##|-PRIV
63
64 0089af7c Scott Ullrich
ini_set('max_execution_time', '0');
65
66 9bcf197e Scott Ullrich
require_once("globals.inc");
67 9f9dcd98 Scott Ullrich
require_once("guiconfig.inc");
68 f8e335a3 Scott Ullrich
require_once("pkg-utils.inc");
69 ee11cc6e Scott Ullrich
70 4832ed98 BBcan177
// if upgrade in progress, alert user
71 0f649c97 Phil Davis
if (is_subsystem_dirty('packagelock')) {
72
	$pgtitle = array(gettext("System"), gettext("Package Manager"));
73 261c7de8 jim-p
	include("head.inc");
74 3b3a95e5 Phil Davis
	print_info_box("Please wait while packages are reinstalled in the background.");
75 31f03b6c Sjon Hortensius
	include("foot.inc");
76 261c7de8 jim-p
	exit;
77
}
78 31f03b6c Sjon Hortensius
79 875a9486 Stephen Beaver
// We are being called only to get the pacakge data, not to display anything
80
if (($_REQUEST) && ($_REQUEST['ajax'])) {
81
	print(get_pkg_table());
82
	exit;
83
}
84 7409fde6 Stephen Beaver
85 875a9486 Stephen Beaver
// THe content for the table of packages is created here and fetched by Ajax. This allows us to draw the page and dispay
86
// any required messages while the table it being downloaded/populated. On very small/slow systems, that can take a while
87
function get_pkg_table() {
88 31f03b6c Sjon Hortensius
89 875a9486 Stephen Beaver
	$pkg_info = get_pkg_info();
90 5c22f8ef Stephen Beaver
91 875a9486 Stephen Beaver
	if (!$pkg_info) {
92
		print("error");
93
		exit;
94 0f649c97 Phil Davis
	}
95 31f03b6c Sjon Hortensius
96 875a9486 Stephen Beaver
	$pkgtbl = 	'<table id="pkgtable" class="table table-striped table-hover">' . "\n";
97
	$pkgtbl .= 		'<thead>' . "\n";
98
	$pkgtbl .= 			'<tr>' . "\n";
99
	$pkgtbl .= 				'<th>' . gettext("Name") . "</th>\n";
100
	$pkgtbl .= 				'<th>' . gettext("Version") . "</th>\n";
101
	$pkgtbl .= 				'<th>' . gettext("Description") . "</th>\n";
102
	$pkgtbl .= 				'<th></th>' . "\n";
103
	$pkgtbl .= 			'</tr>' . "\n";
104
	$pkgtbl .= 		'</thead>' . "\n";
105
	$pkgtbl .= 		'<tbody>' . "\n";
106
107
	foreach ($pkg_info as $index) {
108
		if (isset($index['installed'])) {
109
			continue;
110
		}
111
112
		$pkgtbl .= 	'<tr>' . "\n";
113
		$pkgtbl .= 	'<td>' . "\n";
114
115
		if ($index['www']) {
116
			$pkgtbl .= 	'<a title="' . gettext("Visit official website") . '" target="_blank" href="' . htmlspecialchars($index['www']) . '">' . "\n";
117
		}
118
119
		$pkgtbl .= htmlspecialchars($index['shortname']);
120
		$pkgtbl .= 		'</a>' . "\n";
121
		$pkgtbl .= 	'</td>' . "\n";
122
		$pkgtbl .= 	'<td>' . "\n";
123
124
		if (!$g['disablepackagehistory']) {
125
			$pkgtbl .= '<a target="_blank" title="' . gettext("View changelog") . '" href="' . htmlspecialchars($index['changeloglink']) . '">' . "\n";
126
			$pkgtbl .= htmlspecialchars($index['version']) . '</a>' . "\n";
127
		} else {
128
			$pkgtbl .= htmlspecialchars($index['version']);
129
		}
130
131
		$pkgtbl .= 	'</td>' . "\n";
132
		$pkgtbl .= 	'<td>' . "\n";
133
		$pkgtbl .= 		$index['desc'];
134
135
		if (is_array($index['deps']) && count($index['deps'])) {
136 0a5fbe89 jim-p
			$pkgtbl .= 	'<br /><br />' . gettext("Package Dependencies") . ":<br/>\n";
137 875a9486 Stephen Beaver
138
			foreach ($index['deps'] as $pdep) {
139 0a5fbe89 jim-p
				$pkgtbl .= '<a target="_blank" href="https://freshports.org/' . $pdep['origin'] . '">&nbsp;<i class="fa fa-paperclip"></i> ' . basename($pdep['origin']) . '-' . $pdep['version'] . '</a>&emsp;' . "\n";
140 875a9486 Stephen Beaver
			}
141
142 0a5fbe89 jim-p
			$pkgtbl .= "\n";
143 875a9486 Stephen Beaver
		}
144
145
		$pkgtbl .= 	'</td>' . "\n";
146
		$pkgtbl .= '<td>' . "\n";
147
		$pkgtbl .= '<a title="' . gettext("Click to install") . '" href="pkg_mgr_install.php?id=' . $index['name'] . '" class="btn btn-success btn-sm">install</a>' . "\n";
148 31f03b6c Sjon Hortensius
149 875a9486 Stephen Beaver
		if (!$g['disablepackageinfo'] && $index['pkginfolink'] && $index['pkginfolink'] != $index['www']) {
150
			$pkgtbl .= '<a target="_blank" title="' . gettext("View more information") . '" href="' . htmlspecialchars($index['pkginfolink']) . '" class="btn btn-default btn-sm">info</a>' . "\n";
151 31f03b6c Sjon Hortensius
		}
152 875a9486 Stephen Beaver
153
		$pkgtbl .= 	'</td>' . "\n";
154
		$pkgtbl .= 	'</tr>' . "\n";
155 f70121be Renato Botelho
	}
156 5c22f8ef Stephen Beaver
157 875a9486 Stephen Beaver
	$pkgtbl .= 	'</tbody>' . "\n";
158
	$pkgtbl .= '</table>' . "\n";
159 29840546 Renato Botelho
160 875a9486 Stephen Beaver
	return ($pkgtbl);
161
}
162 4832ed98 BBcan177
163 875a9486 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
164
include("head.inc");
165 98dfca18 Stephen Beaver
166 875a9486 Stephen Beaver
$tab_array = array();
167
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
168
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
169
display_top_tabs($tab_array);
170
?>
171
<div class="panel panel-default" id="search-panel" style="display: none;">
172 95fa5cce Phil Davis
	<div class="panel-heading">
173
		<h2 class="panel-title">
174
			<?=gettext('Search')?>
175
			<span class="widget-heading-icon pull-right">
176
				<a data-toggle="collapse" href="#search-panel_panel-body">
177
					<i class="fa fa-plus-circle"></i>
178
				</a>
179
			</span>
180
		</h2>
181 98dfca18 Stephen Beaver
	</div>
182 4832ed98 BBcan177
	<div id="search-panel_panel-body" class="panel-body collapse in">
183 98dfca18 Stephen Beaver
		<div class="form-group">
184
			<label class="col-sm-2 control-label">
185 4832ed98 BBcan177
				<?=gettext("Search term")?>
186 98dfca18 Stephen Beaver
			</label>
187
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
188 3a28934c Stephen Beaver
			<div class="col-sm-2">
189
				<select id="where" class="form-control">
190
					<option value="0"><?=gettext("Name")?></option>
191
					<option value="1"><?=gettext("Description")?></option>
192 1da8a2e3 Stephen Beaver
					<option value="2" selected><?=gettext("Both")?></option>
193 3a28934c Stephen Beaver
				</select>
194
			</div>
195 995df6c3 Stephen Beaver
			<div class="col-sm-3">
196 f2c6628a NOYB
				<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><?=gettext("Search")?></a>
197
				<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-default btn-sm"><?=gettext("Clear")?></a>
198 995df6c3 Stephen Beaver
			</div>
199 98dfca18 Stephen Beaver
			<div class="col-sm-10 col-sm-offset-2">
200 cadeb9fd Phil Davis
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
201 98dfca18 Stephen Beaver
			</div>
202
		</div>
203
	</div>
204
</div>
205
206
<div class="panel panel-default">
207
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
208 875a9486 Stephen Beaver
	<div id="pkgtbl" class="panel-body table-responsive">
209
		<div id="waitmsg">
210
			<?=print_info_box(gettext("Please wait while the list of packages is retrieved and formatted") . '&nbsp;<i class="fa fa-cog fa-spin"></i>')?>
211
		</div>
212 0071ef19 Stephen Beaver
213 875a9486 Stephen Beaver
		<div id="errmsg" style="display: none;">
214
			<?=print_info_box("<ul><li>" . gettext("Error: Unable to retrieve package information.") . "</li></ul>", 'danger')?>
215
		</div>
216 89f64f0f Sander van Leeuwen
	</div>
217 98dfca18 Stephen Beaver
</div>
218
219 8fd9052f Colin Fleming
<script type="text/javascript">
220 98dfca18 Stephen Beaver
//<![CDATA[
221 875a9486 Stephen Beaver
222 0f649c97 Phil Davis
events.push(function() {
223 98dfca18 Stephen Beaver
224 6c36aab3 Stephen Beaver
	// Initial state & toggle icons of collapsed panel
225 0f649c97 Phil Davis
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el) {
226 6c36aab3 Stephen Beaver
		var body = $(el).parents('.panel').children('.panel-body')
227
		var isOpen = body.hasClass('in');
228
229 1b7379f9 Jared Dillard
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
230
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
231 6c36aab3 Stephen Beaver
232 0f649c97 Phil Davis
		body.on('shown.bs.collapse', function() {
233 1b7379f9 Jared Dillard
			$(el).children('i').toggleClass('fa-minus-circle', true);
234
			$(el).children('i').toggleClass('fa-plus-circle', false);
235 6c36aab3 Stephen Beaver
		});
236
	});
237
238 1da8a2e3 Stephen Beaver
	// Make these controls plain buttons
239 0f649c97 Phil Davis
	$("#btnsearch").prop('type', 'button');
240
	$("#btnclear").prop('type', 'button');
241 919d91f9 Phil Davis
242 1da8a2e3 Stephen Beaver
	// Search for a term in the package name and/or description
243 3a28934c Stephen Beaver
	$("#btnsearch").click(function() {
244
		var searchstr = $('#searchstr').val().toLowerCase();
245
		var table = $("table tbody");
246
		var where = $('#where').val();
247
248
		table.find('tr').each(function (i) {
249
			var $tds = $(this).find('td'),
250
				shortname = $tds.eq(0).text().trim().toLowerCase(),
251
				descr = $tds.eq(2).text().trim().toLowerCase();
252
253
			regexp = new RegExp(searchstr);
254 0f649c97 Phil Davis
			if (searchstr.length > 0) {
255
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
256 3a28934c Stephen Beaver
					$(this).hide();
257
				} else {
258
					$(this).show();
259
				}
260
			} else {
261 d2364df7 Stephen Beaver
				$(this).show();	// A blank search string shows all
262 3a28934c Stephen Beaver
			}
263
		});
264
	});
265
266 1da8a2e3 Stephen Beaver
	// Clear the search term and unhide all rows (that were hidden during a previous search)
267 3a28934c Stephen Beaver
	$("#btnclear").click(function() {
268
		var table = $("table tbody");
269
270 1da8a2e3 Stephen Beaver
		$('#searchstr').val("");
271
272 3a28934c Stephen Beaver
		table.find('tr').each(function (i) {
273
			$(this).show();
274
		});
275
	});
276 919d91f9 Phil Davis
277 1da8a2e3 Stephen Beaver
	// Hitting the enter key will do the same as clicking the search button
278
	$("#searchstr").on("keyup", function (event) {
279 0f649c97 Phil Davis
	    if (event.keyCode == 13) {
280 1da8a2e3 Stephen Beaver
	        $("#btnsearch").get(0).click();
281
	    }
282
	});
283 d2364df7 Stephen Beaver
284 875a9486 Stephen Beaver
	// Retrieve the table formatted pacakge information and display it in the "Packages" panel
285
	// (Or display an appropriate error message)
286
	var ajaxRequest;
287
288
	$.ajax({
289
		url: "/pkg_mgr.php",
290
		type: "post",
291
		data: { ajax: "ajax"},
292
		success: function(data) {
293
			if (data == "error") {
294
				$('#waitmsg').hide();
295
				$('#errmsg').show();
296
			} else {
297
				$('#pkgtbl').html(data);
298
				$('#search-panel').show();
299
			}
300
		},
301
		error: function() {
302
			$('#waitmsg').hide();
303
			$('#errmsg').show();
304
		}
305
	});
306
307 98dfca18 Stephen Beaver
});
308
//]]>
309
</script>
310
311 6c36aab3 Stephen Beaver
<?php include("foot.inc");
312 4832ed98 BBcan177
?>