Project

General

Profile

Download (9.01 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * pkg_mgr.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2013 Marcello Coutinho
8
 * All rights reserved.
9
 *
10
 * 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
 *
14
 * http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * 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
 */
22

    
23
##|+PRIV
24
##|*IDENT=page-system-packagemanager
25
##|*NAME=System: Package Manager
26
##|*DESCR=Allow access to the 'System: Package Manager' page.
27
##|*MATCH=pkg_mgr.php*
28
##|-PRIV
29

    
30
ini_set('max_execution_time', '0');
31

    
32
require_once("globals.inc");
33
require_once("guiconfig.inc");
34
require_once("pkg-utils.inc");
35

    
36
// if upgrade in progress, alert user
37
if (is_subsystem_dirty('packagelock')) {
38
	$pgtitle = array(gettext("System"), gettext("Package Manager"));
39
	$pglinks = array("", "@self");
40
	include("head.inc");
41
	print_info_box("Please wait while packages are reinstalled in the background.");
42
	include("foot.inc");
43
	exit;
44
}
45

    
46
// We are being called only to get the pacakge data, not to display anything
47
if (($_REQUEST) && ($_REQUEST['ajax'])) {
48
	print(get_pkg_table());
49
	exit;
50
}
51

    
52
// THe content for the table of packages is created here and fetched by Ajax. This allows us to draw the page and dispay
53
// any required messages while the table it being downloaded/populated. On very small/slow systems, that can take a while
54
function get_pkg_table() {
55

    
56
	$pkg_info = get_pkg_info();
57

    
58
	if (!$pkg_info) {
59
		print("error");
60
		exit;
61
	}
62

    
63
	$pkgtbl = 	'<table id="pkgtable" class="table table-striped table-hover">' . "\n";
64
	$pkgtbl .= 		'<thead>' . "\n";
65
	$pkgtbl .= 			'<tr>' . "\n";
66
	$pkgtbl .= 				'<th>' . gettext("Name") . "</th>\n";
67
	$pkgtbl .= 				'<th>' . gettext("Version") . "</th>\n";
68
	$pkgtbl .= 				'<th>' . gettext("Description") . "</th>\n";
69
	$pkgtbl .= 				'<th></th>' . "\n";
70
	$pkgtbl .= 			'</tr>' . "\n";
71
	$pkgtbl .= 		'</thead>' . "\n";
72
	$pkgtbl .= 		'<tbody>' . "\n";
73

    
74
	foreach ($pkg_info as $index) {
75
		if (isset($index['installed'])) {
76
			continue;
77
		}
78

    
79
		$pkgtbl .= 	'<tr>' . "\n";
80
		$pkgtbl .= 	'<td>' . "\n";
81

    
82
		if (($index['www']) && ($index['www'] != "UNKNOWN")) {
83
			$pkgtbl .= 	'<a title="' . gettext("Visit official website") . '" target="_blank" href="' . htmlspecialchars($index['www']) . '">' . "\n";
84
			$pkgtbl .= htmlspecialchars($index['shortname']) . '</a>' . "\n";
85
		} else {
86
			$pkgtbl .= htmlspecialchars($index['shortname']);
87
		}
88
		$pkgtbl .= 	'</td>' . "\n";
89
		$pkgtbl .= 	'<td>' . "\n";
90

    
91
		if (!$g['disablepackagehistory']) {
92
			$pkgtbl .= '<a target="_blank" title="' . gettext("View changelog") . '" href="' . htmlspecialchars($index['changeloglink']) . '">' . "\n";
93
			$pkgtbl .= htmlspecialchars($index['version']) . '</a>' . "\n";
94
		} else {
95
			$pkgtbl .= htmlspecialchars($index['version']);
96
		}
97

    
98
		$pkgtbl .= 	'</td>' . "\n";
99
		$pkgtbl .= 	'<td>' . "\n";
100
		$pkgtbl .= 		$index['desc'];
101

    
102
		if (is_array($index['deps']) && count($index['deps'])) {
103
			$pkgtbl .= 	'<br /><br />' . gettext("Package Dependencies") . ":<br/>\n";
104

    
105
			foreach ($index['deps'] as $pdep) {
106
				$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";
107
			}
108

    
109
			$pkgtbl .= "\n";
110
		}
111

    
112
		$pkgtbl .= 	'</td>' . "\n";
113
		$pkgtbl .= '<td>' . "\n";
114
		$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";
115

    
116
		if (!$g['disablepackageinfo'] && $index['pkginfolink'] && $index['pkginfolink'] != $index['www']) {
117
			$pkgtbl .= '<a target="_blank" title="' . gettext("View more information") . '" href="' . htmlspecialchars($index['pkginfolink']) . '" class="btn btn-default btn-sm">info</a>' . "\n";
118
		}
119

    
120
		$pkgtbl .= 	'</td>' . "\n";
121
		$pkgtbl .= 	'</tr>' . "\n";
122
	}
123

    
124
	$pkgtbl .= 	'</tbody>' . "\n";
125
	$pkgtbl .= '</table>' . "\n";
126

    
127
	return ($pkgtbl);
128
}
129

    
130
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
131
$pglinks = array("", "pkg_mgr_installed.php", "@self");
132
include("head.inc");
133

    
134
$tab_array = array();
135
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
136
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
137
display_top_tabs($tab_array);
138
?>
139
<div class="panel panel-default" id="search-panel" style="display: none;">
140
	<div class="panel-heading">
141
		<h2 class="panel-title">
142
			<?=gettext('Search')?>
143
			<span class="widget-heading-icon pull-right">
144
				<a data-toggle="collapse" href="#search-panel_panel-body">
145
					<i class="fa fa-plus-circle"></i>
146
				</a>
147
			</span>
148
		</h2>
149
	</div>
150
	<div id="search-panel_panel-body" class="panel-body collapse in">
151
		<div class="form-group">
152
			<label class="col-sm-2 control-label">
153
				<?=gettext("Search term")?>
154
			</label>
155
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
156
			<div class="col-sm-2">
157
				<select id="where" class="form-control">
158
					<option value="0"><?=gettext("Name")?></option>
159
					<option value="1"><?=gettext("Description")?></option>
160
					<option value="2" selected><?=gettext("Both")?></option>
161
				</select>
162
			</div>
163
			<div class="col-sm-3">
164
				<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
165
				<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
166
			</div>
167
			<div class="col-sm-10 col-sm-offset-2">
168
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
169
			</div>
170
		</div>
171
	</div>
172
</div>
173

    
174
<div class="panel panel-default">
175
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
176
	<div id="pkgtbl" class="panel-body table-responsive">
177
		<div id="waitmsg">
178
			<?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>'); ?>
179
		</div>
180

    
181
		<div id="errmsg" style="display: none;">
182
			<?php print_info_box("<ul><li>" . gettext("Unable to retrieve package information.") . "</li></ul>", 'danger'); ?>
183
		</div>
184
	</div>
185
</div>
186

    
187
<script type="text/javascript">
188
//<![CDATA[
189

    
190
events.push(function() {
191

    
192
	// Initial state & toggle icons of collapsed panel
193
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el) {
194
		var body = $(el).parents('.panel').children('.panel-body')
195
		var isOpen = body.hasClass('in');
196

    
197
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
198
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
199

    
200
		body.on('shown.bs.collapse', function() {
201
			$(el).children('i').toggleClass('fa-minus-circle', true);
202
			$(el).children('i').toggleClass('fa-plus-circle', false);
203
		});
204
	});
205

    
206
	// Make these controls plain buttons
207
	$("#btnsearch").prop('type', 'button');
208
	$("#btnclear").prop('type', 'button');
209

    
210
	// Search for a term in the package name and/or description
211
	$("#btnsearch").click(function() {
212
		var searchstr = $('#searchstr').val().toLowerCase();
213
		var table = $("table tbody");
214
		var where = $('#where').val();
215

    
216
		table.find('tr').each(function (i) {
217
			var $tds = $(this).find('td'),
218
				shortname = $tds.eq(0).text().trim().toLowerCase(),
219
				descr = $tds.eq(2).text().trim().toLowerCase();
220

    
221
			regexp = new RegExp(searchstr);
222
			if (searchstr.length > 0) {
223
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
224
					$(this).hide();
225
				} else {
226
					$(this).show();
227
				}
228
			} else {
229
				$(this).show();	// A blank search string shows all
230
			}
231
		});
232
	});
233

    
234
	// Clear the search term and unhide all rows (that were hidden during a previous search)
235
	$("#btnclear").click(function() {
236
		var table = $("table tbody");
237

    
238
		$('#searchstr').val("");
239

    
240
		table.find('tr').each(function (i) {
241
			$(this).show();
242
		});
243
	});
244

    
245
	// Hitting the enter key will do the same as clicking the search button
246
	$("#searchstr").on("keyup", function (event) {
247
	    if (event.keyCode == 13) {
248
	        $("#btnsearch").get(0).click();
249
	    }
250
	});
251

    
252
	// Retrieve the table formatted pacakge information and display it in the "Packages" panel
253
	// (Or display an appropriate error message)
254
	var ajaxRequest;
255

    
256
	$.ajax({
257
		url: "/pkg_mgr.php",
258
		type: "post",
259
		data: { ajax: "ajax"},
260
		success: function(data) {
261
			if (data == "error") {
262
				$('#waitmsg').hide();
263
				$('#errmsg').show();
264
			} else {
265
				$('#pkgtbl').html(data);
266
				$('#search-panel').show();
267
			}
268
		},
269
		error: function() {
270
			$('#waitmsg').hide();
271
			$('#errmsg').show();
272
		}
273
	});
274

    
275
});
276
//]]>
277
</script>
278

    
279
<?php include("foot.inc");
280
?>
(98-98/223)