Project

General

Profile

Download (9.03 KB) Statistics
| Branch: | Tag: | Revision:
1 ee11cc6e Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * pkg_mgr.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2013 Marcello Coutinho
8
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 c5d81585 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 239b5161 Stephen Beaver
 */
22 ee11cc6e Scott Ullrich
23 6b07c15a Matthew Grooms
##|+PRIV
24
##|*IDENT=page-system-packagemanager
25 5230f468 jim-p
##|*NAME=System: Package Manager
26 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Package Manager' page.
27
##|*MATCH=pkg_mgr.php*
28
##|-PRIV
29
30 0089af7c Scott Ullrich
ini_set('max_execution_time', '0');
31
32 9bcf197e Scott Ullrich
require_once("globals.inc");
33 9f9dcd98 Scott Ullrich
require_once("guiconfig.inc");
34 f8e335a3 Scott Ullrich
require_once("pkg-utils.inc");
35 ee11cc6e Scott Ullrich
36 4832ed98 BBcan177
// if upgrade in progress, alert user
37 0f649c97 Phil Davis
if (is_subsystem_dirty('packagelock')) {
38
	$pgtitle = array(gettext("System"), gettext("Package Manager"));
39 edcd7535 Phil Davis
	$pglinks = array("", "@self");
40 261c7de8 jim-p
	include("head.inc");
41 3b3a95e5 Phil Davis
	print_info_box("Please wait while packages are reinstalled in the background.");
42 31f03b6c Sjon Hortensius
	include("foot.inc");
43 261c7de8 jim-p
	exit;
44
}
45 31f03b6c Sjon Hortensius
46 146dbf01 Phil Davis
// We are being called only to get the package data, not to display anything
47 875a9486 Stephen Beaver
if (($_REQUEST) && ($_REQUEST['ajax'])) {
48
	print(get_pkg_table());
49
	exit;
50
}
51 7409fde6 Stephen Beaver
52 146dbf01 Phil Davis
// The content for the table of packages is created here and fetched by Ajax. This allows us to draw the page and display
53
// any required messages while the table is being downloaded/populated. On very small/slow systems, that can take a while
54 875a9486 Stephen Beaver
function get_pkg_table() {
55 cc28e9b1 Renato Botelho
	$pkg_info = get_pkg_info('all', true, false);
56 5c22f8ef Stephen Beaver
57 875a9486 Stephen Beaver
	if (!$pkg_info) {
58
		print("error");
59
		exit;
60 0f649c97 Phil Davis
	}
61 31f03b6c Sjon Hortensius
62 875a9486 Stephen Beaver
	$pkgtbl = 	'<table id="pkgtable" class="table table-striped table-hover">' . "\n";
63
	$pkgtbl .= 		'<thead>' . "\n";
64
	$pkgtbl .= 			'<tr>' . "\n";
65
	$pkgtbl .= 				'<th>' . gettext("Name") . "</th>\n";
66
	$pkgtbl .= 				'<th>' . gettext("Version") . "</th>\n";
67
	$pkgtbl .= 				'<th>' . gettext("Description") . "</th>\n";
68
	$pkgtbl .= 				'<th></th>' . "\n";
69
	$pkgtbl .= 			'</tr>' . "\n";
70
	$pkgtbl .= 		'</thead>' . "\n";
71
	$pkgtbl .= 		'<tbody>' . "\n";
72
73
	foreach ($pkg_info as $index) {
74
		if (isset($index['installed'])) {
75
			continue;
76
		}
77
78
		$pkgtbl .= 	'<tr>' . "\n";
79
		$pkgtbl .= 	'<td>' . "\n";
80
81 7940050b lukehamburg
		if (($index['www']) && ($index['www'] != "UNKNOWN")) {
82 875a9486 Stephen Beaver
			$pkgtbl .= 	'<a title="' . gettext("Visit official website") . '" target="_blank" href="' . htmlspecialchars($index['www']) . '">' . "\n";
83 7940050b lukehamburg
			$pkgtbl .= htmlspecialchars($index['shortname']) . '</a>' . "\n";
84
		} else {
85
			$pkgtbl .= htmlspecialchars($index['shortname']);
86 875a9486 Stephen Beaver
		}
87
		$pkgtbl .= 	'</td>' . "\n";
88
		$pkgtbl .= 	'<td>' . "\n";
89
90
		if (!$g['disablepackagehistory']) {
91
			$pkgtbl .= '<a target="_blank" title="' . gettext("View changelog") . '" href="' . htmlspecialchars($index['changeloglink']) . '">' . "\n";
92
			$pkgtbl .= htmlspecialchars($index['version']) . '</a>' . "\n";
93
		} else {
94
			$pkgtbl .= htmlspecialchars($index['version']);
95
		}
96
97
		$pkgtbl .= 	'</td>' . "\n";
98
		$pkgtbl .= 	'<td>' . "\n";
99
		$pkgtbl .= 		$index['desc'];
100
101
		if (is_array($index['deps']) && count($index['deps'])) {
102 0a5fbe89 jim-p
			$pkgtbl .= 	'<br /><br />' . gettext("Package Dependencies") . ":<br/>\n";
103 875a9486 Stephen Beaver
104
			foreach ($index['deps'] as $pdep) {
105 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";
106 875a9486 Stephen Beaver
			}
107
108 0a5fbe89 jim-p
			$pkgtbl .= "\n";
109 875a9486 Stephen Beaver
		}
110
111
		$pkgtbl .= 	'</td>' . "\n";
112
		$pkgtbl .= '<td>' . "\n";
113 756ef4df Renato Botelho
		$pkgtbl .= '<a title="' . gettext("Click to install") . '" href="pkg_mgr_install.php?pkg=' . $index['name'] . '" class="btn btn-success btn-sm"><i class="fa fa-plus icon-embed-btn"></i>Install</a>' . "\n";
114 31f03b6c Sjon Hortensius
115 875a9486 Stephen Beaver
		if (!$g['disablepackageinfo'] && $index['pkginfolink'] && $index['pkginfolink'] != $index['www']) {
116
			$pkgtbl .= '<a target="_blank" title="' . gettext("View more information") . '" href="' . htmlspecialchars($index['pkginfolink']) . '" class="btn btn-default btn-sm">info</a>' . "\n";
117 31f03b6c Sjon Hortensius
		}
118 875a9486 Stephen Beaver
119
		$pkgtbl .= 	'</td>' . "\n";
120
		$pkgtbl .= 	'</tr>' . "\n";
121 f70121be Renato Botelho
	}
122 5c22f8ef Stephen Beaver
123 875a9486 Stephen Beaver
	$pkgtbl .= 	'</tbody>' . "\n";
124
	$pkgtbl .= '</table>' . "\n";
125 29840546 Renato Botelho
126 875a9486 Stephen Beaver
	return ($pkgtbl);
127
}
128 4832ed98 BBcan177
129 875a9486 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
130 edcd7535 Phil Davis
$pglinks = array("", "pkg_mgr_installed.php", "@self");
131 875a9486 Stephen Beaver
include("head.inc");
132 98dfca18 Stephen Beaver
133 875a9486 Stephen Beaver
$tab_array = array();
134
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
135 3cff35f1 k-paulius
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
136 875a9486 Stephen Beaver
display_top_tabs($tab_array);
137
?>
138
<div class="panel panel-default" id="search-panel" style="display: none;">
139 95fa5cce Phil Davis
	<div class="panel-heading">
140
		<h2 class="panel-title">
141
			<?=gettext('Search')?>
142
			<span class="widget-heading-icon pull-right">
143
				<a data-toggle="collapse" href="#search-panel_panel-body">
144
					<i class="fa fa-plus-circle"></i>
145
				</a>
146
			</span>
147
		</h2>
148 98dfca18 Stephen Beaver
	</div>
149 4832ed98 BBcan177
	<div id="search-panel_panel-body" class="panel-body collapse in">
150 98dfca18 Stephen Beaver
		<div class="form-group">
151
			<label class="col-sm-2 control-label">
152 4832ed98 BBcan177
				<?=gettext("Search term")?>
153 98dfca18 Stephen Beaver
			</label>
154
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
155 3a28934c Stephen Beaver
			<div class="col-sm-2">
156
				<select id="where" class="form-control">
157
					<option value="0"><?=gettext("Name")?></option>
158
					<option value="1"><?=gettext("Description")?></option>
159 1da8a2e3 Stephen Beaver
					<option value="2" selected><?=gettext("Both")?></option>
160 3a28934c Stephen Beaver
				</select>
161
			</div>
162 995df6c3 Stephen Beaver
			<div class="col-sm-3">
163 5542d069 jim-p
				<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
164
				<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
165 995df6c3 Stephen Beaver
			</div>
166 98dfca18 Stephen Beaver
			<div class="col-sm-10 col-sm-offset-2">
167 cadeb9fd Phil Davis
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
168 98dfca18 Stephen Beaver
			</div>
169
		</div>
170
	</div>
171
</div>
172
173
<div class="panel panel-default">
174
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
175 875a9486 Stephen Beaver
	<div id="pkgtbl" class="panel-body table-responsive">
176
		<div id="waitmsg">
177 f6aebbcc NewEraCracker
			<?php print_info_box(gettext("Please wait while the list of packages is retrieved and formatted.") . '&nbsp;<i class="fa fa-cog fa-spin"></i>'); ?>
178 875a9486 Stephen Beaver
		</div>
179 0071ef19 Stephen Beaver
180 875a9486 Stephen Beaver
		<div id="errmsg" style="display: none;">
181 f6aebbcc NewEraCracker
			<?php print_info_box("<ul><li>" . gettext("Unable to retrieve package information.") . "</li></ul>", 'danger'); ?>
182 875a9486 Stephen Beaver
		</div>
183 89f64f0f Sander van Leeuwen
	</div>
184 98dfca18 Stephen Beaver
</div>
185
186 8fd9052f Colin Fleming
<script type="text/javascript">
187 98dfca18 Stephen Beaver
//<![CDATA[
188 875a9486 Stephen Beaver
189 0f649c97 Phil Davis
events.push(function() {
190 98dfca18 Stephen Beaver
191 6c36aab3 Stephen Beaver
	// Initial state & toggle icons of collapsed panel
192 0f649c97 Phil Davis
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el) {
193 6c36aab3 Stephen Beaver
		var body = $(el).parents('.panel').children('.panel-body')
194
		var isOpen = body.hasClass('in');
195
196 1b7379f9 Jared Dillard
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
197
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
198 6c36aab3 Stephen Beaver
199 0f649c97 Phil Davis
		body.on('shown.bs.collapse', function() {
200 1b7379f9 Jared Dillard
			$(el).children('i').toggleClass('fa-minus-circle', true);
201
			$(el).children('i').toggleClass('fa-plus-circle', false);
202 6c36aab3 Stephen Beaver
		});
203
	});
204
205 1da8a2e3 Stephen Beaver
	// Make these controls plain buttons
206 0f649c97 Phil Davis
	$("#btnsearch").prop('type', 'button');
207
	$("#btnclear").prop('type', 'button');
208 919d91f9 Phil Davis
209 1da8a2e3 Stephen Beaver
	// Search for a term in the package name and/or description
210 3a28934c Stephen Beaver
	$("#btnsearch").click(function() {
211
		var searchstr = $('#searchstr').val().toLowerCase();
212
		var table = $("table tbody");
213
		var where = $('#where').val();
214
215
		table.find('tr').each(function (i) {
216
			var $tds = $(this).find('td'),
217
				shortname = $tds.eq(0).text().trim().toLowerCase(),
218
				descr = $tds.eq(2).text().trim().toLowerCase();
219
220
			regexp = new RegExp(searchstr);
221 0f649c97 Phil Davis
			if (searchstr.length > 0) {
222
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
223 3a28934c Stephen Beaver
					$(this).hide();
224
				} else {
225
					$(this).show();
226
				}
227
			} else {
228 d2364df7 Stephen Beaver
				$(this).show();	// A blank search string shows all
229 3a28934c Stephen Beaver
			}
230
		});
231
	});
232
233 1da8a2e3 Stephen Beaver
	// Clear the search term and unhide all rows (that were hidden during a previous search)
234 3a28934c Stephen Beaver
	$("#btnclear").click(function() {
235
		var table = $("table tbody");
236
237 1da8a2e3 Stephen Beaver
		$('#searchstr').val("");
238
239 3a28934c Stephen Beaver
		table.find('tr').each(function (i) {
240
			$(this).show();
241
		});
242
	});
243 919d91f9 Phil Davis
244 1da8a2e3 Stephen Beaver
	// Hitting the enter key will do the same as clicking the search button
245
	$("#searchstr").on("keyup", function (event) {
246 0f649c97 Phil Davis
	    if (event.keyCode == 13) {
247 1da8a2e3 Stephen Beaver
	        $("#btnsearch").get(0).click();
248
	    }
249
	});
250 d2364df7 Stephen Beaver
251 146dbf01 Phil Davis
	// Retrieve the table formatted package information and display it in the "Packages" panel
252 875a9486 Stephen Beaver
	// (Or display an appropriate error message)
253
	var ajaxRequest;
254
255
	$.ajax({
256
		url: "/pkg_mgr.php",
257
		type: "post",
258
		data: { ajax: "ajax"},
259
		success: function(data) {
260
			if (data == "error") {
261
				$('#waitmsg').hide();
262
				$('#errmsg').show();
263
			} else {
264
				$('#pkgtbl').html(data);
265
				$('#search-panel').show();
266
			}
267
		},
268
		error: function() {
269
			$('#waitmsg').hide();
270
			$('#errmsg').show();
271
		}
272
	});
273
274 98dfca18 Stephen Beaver
});
275
//]]>
276
</script>
277
278 6c36aab3 Stephen Beaver
<?php include("foot.inc");
279 4832ed98 BBcan177
?>