Project

General

Profile

Download (8.92 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
	include("head.inc");
40
	print_info_box("Please wait while packages are reinstalled in the background.");
41
	include("foot.inc");
42
	exit;
43
}
44

    
45
// 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

    
51
// 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

    
55
	$pkg_info = get_pkg_info();
56

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

    
62
	$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
		if (($index['www']) && ($index['www'] != "UNKNOWN")) {
82
			$pkgtbl .= 	'<a title="' . gettext("Visit official website") . '" target="_blank" href="' . htmlspecialchars($index['www']) . '">' . "\n";
83
			$pkgtbl .= htmlspecialchars($index['shortname']) . '</a>' . "\n";
84
		} else {
85
			$pkgtbl .= htmlspecialchars($index['shortname']);
86
		}
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
			$pkgtbl .= 	'<br /><br />' . gettext("Package Dependencies") . ":<br/>\n";
103

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

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

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

    
115
		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
		}
118

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

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

    
126
	return ($pkgtbl);
127
}
128

    
129
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
130
include("head.inc");
131

    
132
$tab_array = array();
133
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
134
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
135
display_top_tabs($tab_array);
136
?>
137
<div class="panel panel-default" id="search-panel" style="display: none;">
138
	<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
	</div>
148
	<div id="search-panel_panel-body" class="panel-body collapse in">
149
		<div class="form-group">
150
			<label class="col-sm-2 control-label">
151
				<?=gettext("Search term")?>
152
			</label>
153
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
154
			<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
					<option value="2" selected><?=gettext("Both")?></option>
159
				</select>
160
			</div>
161
			<div class="col-sm-3">
162
				<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
			</div>
165
			<div class="col-sm-10 col-sm-offset-2">
166
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
167
			</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
	<div id="pkgtbl" class="panel-body table-responsive">
175
		<div id="waitmsg">
176
			<?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
		</div>
178

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

    
185
<script type="text/javascript">
186
//<![CDATA[
187

    
188
events.push(function() {
189

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

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

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

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

    
208
	// Search for a term in the package name and/or description
209
	$("#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
			if (searchstr.length > 0) {
221
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
222
					$(this).hide();
223
				} else {
224
					$(this).show();
225
				}
226
			} else {
227
				$(this).show();	// A blank search string shows all
228
			}
229
		});
230
	});
231

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

    
236
		$('#searchstr').val("");
237

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

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

    
250
	// 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
});
274
//]]>
275
</script>
276

    
277
<?php include("foot.inc");
278
?>
(100-100/225)