Project

General

Profile

Download (8.92 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 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 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 261c7de8 jim-p
	include("head.inc");
40 3b3a95e5 Phil Davis
	print_info_box("Please wait while packages are reinstalled in the background.");
41 31f03b6c Sjon Hortensius
	include("foot.inc");
42 261c7de8 jim-p
	exit;
43
}
44 31f03b6c Sjon Hortensius
45 875a9486 Stephen Beaver
// We are being called only to get the pacakge data, not to display anything
46
if (($_REQUEST) && ($_REQUEST['ajax'])) {
47
	print(get_pkg_table());
48
	exit;
49
}
50 7409fde6 Stephen Beaver
51 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
52
// any required messages while the table it being downloaded/populated. On very small/slow systems, that can take a while
53
function get_pkg_table() {
54 31f03b6c Sjon Hortensius
55 875a9486 Stephen Beaver
	$pkg_info = get_pkg_info();
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
include("head.inc");
131 98dfca18 Stephen Beaver
132 875a9486 Stephen Beaver
$tab_array = array();
133
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
134 3cff35f1 k-paulius
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
135 875a9486 Stephen Beaver
display_top_tabs($tab_array);
136
?>
137
<div class="panel panel-default" id="search-panel" style="display: none;">
138 95fa5cce Phil Davis
	<div class="panel-heading">
139
		<h2 class="panel-title">
140
			<?=gettext('Search')?>
141
			<span class="widget-heading-icon pull-right">
142
				<a data-toggle="collapse" href="#search-panel_panel-body">
143
					<i class="fa fa-plus-circle"></i>
144
				</a>
145
			</span>
146
		</h2>
147 98dfca18 Stephen Beaver
	</div>
148 4832ed98 BBcan177
	<div id="search-panel_panel-body" class="panel-body collapse in">
149 98dfca18 Stephen Beaver
		<div class="form-group">
150
			<label class="col-sm-2 control-label">
151 4832ed98 BBcan177
				<?=gettext("Search term")?>
152 98dfca18 Stephen Beaver
			</label>
153
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
154 3a28934c Stephen Beaver
			<div class="col-sm-2">
155
				<select id="where" class="form-control">
156
					<option value="0"><?=gettext("Name")?></option>
157
					<option value="1"><?=gettext("Description")?></option>
158 1da8a2e3 Stephen Beaver
					<option value="2" selected><?=gettext("Both")?></option>
159 3a28934c Stephen Beaver
				</select>
160
			</div>
161 995df6c3 Stephen Beaver
			<div class="col-sm-3">
162 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>
163
				<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
164 995df6c3 Stephen Beaver
			</div>
165 98dfca18 Stephen Beaver
			<div class="col-sm-10 col-sm-offset-2">
166 cadeb9fd Phil Davis
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
167 98dfca18 Stephen Beaver
			</div>
168
		</div>
169
	</div>
170
</div>
171
172
<div class="panel panel-default">
173
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
174 875a9486 Stephen Beaver
	<div id="pkgtbl" class="panel-body table-responsive">
175
		<div id="waitmsg">
176 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>'); ?>
177 875a9486 Stephen Beaver
		</div>
178 0071ef19 Stephen Beaver
179 875a9486 Stephen Beaver
		<div id="errmsg" style="display: none;">
180 f6aebbcc NewEraCracker
			<?php print_info_box("<ul><li>" . gettext("Unable to retrieve package information.") . "</li></ul>", 'danger'); ?>
181 875a9486 Stephen Beaver
		</div>
182 89f64f0f Sander van Leeuwen
	</div>
183 98dfca18 Stephen Beaver
</div>
184
185 8fd9052f Colin Fleming
<script type="text/javascript">
186 98dfca18 Stephen Beaver
//<![CDATA[
187 875a9486 Stephen Beaver
188 0f649c97 Phil Davis
events.push(function() {
189 98dfca18 Stephen Beaver
190 6c36aab3 Stephen Beaver
	// Initial state & toggle icons of collapsed panel
191 0f649c97 Phil Davis
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el) {
192 6c36aab3 Stephen Beaver
		var body = $(el).parents('.panel').children('.panel-body')
193
		var isOpen = body.hasClass('in');
194
195 1b7379f9 Jared Dillard
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
196
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
197 6c36aab3 Stephen Beaver
198 0f649c97 Phil Davis
		body.on('shown.bs.collapse', function() {
199 1b7379f9 Jared Dillard
			$(el).children('i').toggleClass('fa-minus-circle', true);
200
			$(el).children('i').toggleClass('fa-plus-circle', false);
201 6c36aab3 Stephen Beaver
		});
202
	});
203
204 1da8a2e3 Stephen Beaver
	// Make these controls plain buttons
205 0f649c97 Phil Davis
	$("#btnsearch").prop('type', 'button');
206
	$("#btnclear").prop('type', 'button');
207 919d91f9 Phil Davis
208 1da8a2e3 Stephen Beaver
	// Search for a term in the package name and/or description
209 3a28934c Stephen Beaver
	$("#btnsearch").click(function() {
210
		var searchstr = $('#searchstr').val().toLowerCase();
211
		var table = $("table tbody");
212
		var where = $('#where').val();
213
214
		table.find('tr').each(function (i) {
215
			var $tds = $(this).find('td'),
216
				shortname = $tds.eq(0).text().trim().toLowerCase(),
217
				descr = $tds.eq(2).text().trim().toLowerCase();
218
219
			regexp = new RegExp(searchstr);
220 0f649c97 Phil Davis
			if (searchstr.length > 0) {
221
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
222 3a28934c Stephen Beaver
					$(this).hide();
223
				} else {
224
					$(this).show();
225
				}
226
			} else {
227 d2364df7 Stephen Beaver
				$(this).show();	// A blank search string shows all
228 3a28934c Stephen Beaver
			}
229
		});
230
	});
231
232 1da8a2e3 Stephen Beaver
	// Clear the search term and unhide all rows (that were hidden during a previous search)
233 3a28934c Stephen Beaver
	$("#btnclear").click(function() {
234
		var table = $("table tbody");
235
236 1da8a2e3 Stephen Beaver
		$('#searchstr').val("");
237
238 3a28934c Stephen Beaver
		table.find('tr').each(function (i) {
239
			$(this).show();
240
		});
241
	});
242 919d91f9 Phil Davis
243 1da8a2e3 Stephen Beaver
	// Hitting the enter key will do the same as clicking the search button
244
	$("#searchstr").on("keyup", function (event) {
245 0f649c97 Phil Davis
	    if (event.keyCode == 13) {
246 1da8a2e3 Stephen Beaver
	        $("#btnsearch").get(0).click();
247
	    }
248
	});
249 d2364df7 Stephen Beaver
250 875a9486 Stephen Beaver
	// Retrieve the table formatted pacakge information and display it in the "Packages" panel
251
	// (Or display an appropriate error message)
252
	var ajaxRequest;
253
254
	$.ajax({
255
		url: "/pkg_mgr.php",
256
		type: "post",
257
		data: { ajax: "ajax"},
258
		success: function(data) {
259
			if (data == "error") {
260
				$('#waitmsg').hide();
261
				$('#errmsg').show();
262
			} else {
263
				$('#pkgtbl').html(data);
264
				$('#search-panel').show();
265
			}
266
		},
267
		error: function() {
268
			$('#waitmsg').hide();
269
			$('#errmsg').show();
270
		}
271
	});
272
273 98dfca18 Stephen Beaver
});
274
//]]>
275
</script>
276
277 6c36aab3 Stephen Beaver
<?php include("foot.inc");
278 4832ed98 BBcan177
?>