Project

General

Profile

Download (9.03 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 package 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 display
53
// any required messages while the table is being downloaded/populated. On very small/slow systems, that can take a while
54
function get_pkg_table() {
55
	$pkg_info = get_pkg_info('all', true, false);
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
$pglinks = array("", "pkg_mgr_installed.php", "@self");
131
include("head.inc");
132

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

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

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

    
189
events.push(function() {
190

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

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

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

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

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

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

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

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

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

    
251
	// Retrieve the table formatted package information and display it in the "Packages" panel
252
	// (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
});
275
//]]>
276
</script>
277

    
278
<?php include("foot.inc");
279
?>
(102-102/228)