Project

General

Profile

Download (10.7 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
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions are met:
12
 *
13
 * 1. Redistributions of source code must retain the above copyright notice,
14
 *    this list of conditions and the following disclaimer.
15
 *
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in
18
 *    the documentation and/or other materials provided with the
19
 *    distribution.
20
 *
21
 * 3. All advertising materials mentioning features or use of this software
22
 *    must display the following acknowledgment:
23
 *    "This product includes software developed by the pfSense Project
24
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
25
 *
26
 * 4. The names "pfSense" and "pfSense Project" must not be used to
27
 *    endorse or promote products derived from this software without
28
 *    prior written permission. For written permission, please contact
29
 *    coreteam@pfsense.org.
30
 *
31
 * 5. Products derived from this software may not be called "pfSense"
32
 *    nor may "pfSense" appear in their names without prior written
33
 *    permission of the Electric Sheep Fencing, LLC.
34
 *
35
 * 6. Redistributions of any form whatsoever must retain the following
36
 *    acknowledgment:
37
 *
38
 * "This product includes software developed by the pfSense Project
39
 * for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 * OF THE POSSIBILITY OF SUCH DAMAGE.
53
 */
54

    
55
##|+PRIV
56
##|*IDENT=page-system-packagemanager
57
##|*NAME=System: Package Manager
58
##|*DESCR=Allow access to the 'System: Package Manager' page.
59
##|*MATCH=pkg_mgr.php*
60
##|-PRIV
61

    
62
ini_set('max_execution_time', '0');
63

    
64
require_once("globals.inc");
65
require_once("guiconfig.inc");
66
require_once("pkg-utils.inc");
67

    
68
// if upgrade in progress, alert user
69
if (is_subsystem_dirty('packagelock')) {
70
	$pgtitle = array(gettext("System"), gettext("Package Manager"));
71
	$pglinks = array("", "@self");
72
	include("head.inc");
73
	print_info_box("Please wait while packages are reinstalled in the background.");
74
	include("foot.inc");
75
	exit;
76
}
77

    
78
// We are being called only to get the package data, not to display anything
79
if (($_REQUEST) && ($_REQUEST['ajax'])) {
80
	print(get_pkg_table());
81
	exit;
82
}
83

    
84
// The content for the table of packages is created here and fetched by Ajax. This allows us to draw the page and display
85
// any required messages while the table is being downloaded/populated. On very small/slow systems, that can take a while
86
function get_pkg_table() {
87

    
88
	$pkg_info = get_pkg_info();
89

    
90
	if (!$pkg_info) {
91
		print("error");
92
		exit;
93
	}
94

    
95
	$pkgtbl = 	'<table id="pkgtable" class="table table-striped table-hover">' . "\n";
96
	$pkgtbl .= 		'<thead>' . "\n";
97
	$pkgtbl .= 			'<tr>' . "\n";
98
	$pkgtbl .= 				'<th>' . gettext("Name") . "</th>\n";
99
	$pkgtbl .= 				'<th>' . gettext("Version") . "</th>\n";
100
	$pkgtbl .= 				'<th>' . gettext("Description") . "</th>\n";
101
	$pkgtbl .= 				'<th></th>' . "\n";
102
	$pkgtbl .= 			'</tr>' . "\n";
103
	$pkgtbl .= 		'</thead>' . "\n";
104
	$pkgtbl .= 		'<tbody>' . "\n";
105

    
106
	foreach ($pkg_info as $index) {
107
		if (isset($index['installed'])) {
108
			continue;
109
		}
110

    
111
		$pkgtbl .= 	'<tr>' . "\n";
112
		$pkgtbl .= 	'<td>' . "\n";
113

    
114
		if (($index['www']) && ($index['www'] != "UNKNOWN")) {
115
			$pkgtbl .= 	'<a title="' . gettext("Visit official website") . '" target="_blank" href="' . htmlspecialchars($index['www']) . '">' . "\n";
116
			$pkgtbl .= htmlspecialchars($index['shortname']) . '</a>' . "\n";
117
		} else {
118
			$pkgtbl .= htmlspecialchars($index['shortname']);
119
		}
120
		$pkgtbl .= 	'</td>' . "\n";
121
		$pkgtbl .= 	'<td>' . "\n";
122

    
123
		if (!$g['disablepackagehistory']) {
124
			$pkgtbl .= '<a target="_blank" title="' . gettext("View changelog") . '" href="' . htmlspecialchars($index['changeloglink']) . '">' . "\n";
125
			$pkgtbl .= htmlspecialchars($index['version']) . '</a>' . "\n";
126
		} else {
127
			$pkgtbl .= htmlspecialchars($index['version']);
128
		}
129

    
130
		$pkgtbl .= 	'</td>' . "\n";
131
		$pkgtbl .= 	'<td>' . "\n";
132
		$pkgtbl .= 		$index['desc'];
133

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

    
137
			foreach ($index['deps'] as $pdep) {
138
				$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";
139
			}
140

    
141
			$pkgtbl .= "\n";
142
		}
143

    
144
		$pkgtbl .= 	'</td>' . "\n";
145
		$pkgtbl .= '<td>' . "\n";
146
		$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";
147

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

    
152
		$pkgtbl .= 	'</td>' . "\n";
153
		$pkgtbl .= 	'</tr>' . "\n";
154
	}
155

    
156
	$pkgtbl .= 	'</tbody>' . "\n";
157
	$pkgtbl .= '</table>' . "\n";
158

    
159
	return ($pkgtbl);
160
}
161

    
162
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
163
$pglinks = array("", "pkg_mgr_installed.php", "@self");
164
include("head.inc");
165

    
166
$tab_array = array();
167
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
168
$tab_array[] = array(gettext("Available Packages"), true, "pkg_mgr.php");
169
display_top_tabs($tab_array);
170
?>
171
<div class="panel panel-default" id="search-panel" style="display: none;">
172
	<div class="panel-heading">
173
		<h2 class="panel-title">
174
			<?=gettext('Search')?>
175
			<span class="widget-heading-icon pull-right">
176
				<a data-toggle="collapse" href="#search-panel_panel-body">
177
					<i class="fa fa-plus-circle"></i>
178
				</a>
179
			</span>
180
		</h2>
181
	</div>
182
	<div id="search-panel_panel-body" class="panel-body collapse in">
183
		<div class="form-group">
184
			<label class="col-sm-2 control-label">
185
				<?=gettext("Search term")?>
186
			</label>
187
			<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
188
			<div class="col-sm-2">
189
				<select id="where" class="form-control">
190
					<option value="0"><?=gettext("Name")?></option>
191
					<option value="1"><?=gettext("Description")?></option>
192
					<option value="2" selected><?=gettext("Both")?></option>
193
				</select>
194
			</div>
195
			<div class="col-sm-3">
196
				<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
197
				<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
198
			</div>
199
			<div class="col-sm-10 col-sm-offset-2">
200
				<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
201
			</div>
202
		</div>
203
	</div>
204
</div>
205

    
206
<div class="panel panel-default">
207
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Packages')?></h2></div>
208
	<div id="pkgtbl" class="panel-body table-responsive">
209
		<div id="waitmsg">
210
			<?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>'); ?>
211
		</div>
212

    
213
		<div id="errmsg" style="display: none;">
214
			<?php print_info_box("<ul><li>" . gettext("Unable to retrieve package information.") . "</li></ul>", 'danger'); ?>
215
		</div>
216
	</div>
217
</div>
218

    
219
<script type="text/javascript">
220
//<![CDATA[
221

    
222
events.push(function() {
223

    
224
	// Initial state & toggle icons of collapsed panel
225
	$('.panel-heading a[data-toggle="collapse"]').each(function (idx, el) {
226
		var body = $(el).parents('.panel').children('.panel-body')
227
		var isOpen = body.hasClass('in');
228

    
229
		$(el).children('i').toggleClass('fa-plus-circle', !isOpen);
230
		$(el).children('i').toggleClass('fa-minus-circle', isOpen);
231

    
232
		body.on('shown.bs.collapse', function() {
233
			$(el).children('i').toggleClass('fa-minus-circle', true);
234
			$(el).children('i').toggleClass('fa-plus-circle', false);
235
		});
236
	});
237

    
238
	// Make these controls plain buttons
239
	$("#btnsearch").prop('type', 'button');
240
	$("#btnclear").prop('type', 'button');
241

    
242
	// Search for a term in the package name and/or description
243
	$("#btnsearch").click(function() {
244
		var searchstr = $('#searchstr').val().toLowerCase();
245
		var table = $("table tbody");
246
		var where = $('#where').val();
247

    
248
		table.find('tr').each(function (i) {
249
			var $tds = $(this).find('td'),
250
				shortname = $tds.eq(0).text().trim().toLowerCase(),
251
				descr = $tds.eq(2).text().trim().toLowerCase();
252

    
253
			regexp = new RegExp(searchstr);
254
			if (searchstr.length > 0) {
255
				if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(descr) && (where != 0))) {
256
					$(this).hide();
257
				} else {
258
					$(this).show();
259
				}
260
			} else {
261
				$(this).show();	// A blank search string shows all
262
			}
263
		});
264
	});
265

    
266
	// Clear the search term and unhide all rows (that were hidden during a previous search)
267
	$("#btnclear").click(function() {
268
		var table = $("table tbody");
269

    
270
		$('#searchstr').val("");
271

    
272
		table.find('tr').each(function (i) {
273
			$(this).show();
274
		});
275
	});
276

    
277
	// Hitting the enter key will do the same as clicking the search button
278
	$("#searchstr").on("keyup", function (event) {
279
	    if (event.keyCode == 13) {
280
	        $("#btnsearch").get(0).click();
281
	    }
282
	});
283

    
284
	// Retrieve the table formatted package information and display it in the "Packages" panel
285
	// (Or display an appropriate error message)
286
	var ajaxRequest;
287

    
288
	$.ajax({
289
		url: "/pkg_mgr.php",
290
		type: "post",
291
		data: { ajax: "ajax"},
292
		success: function(data) {
293
			if (data == "error") {
294
				$('#waitmsg').hide();
295
				$('#errmsg').show();
296
			} else {
297
				$('#pkgtbl').html(data);
298
				$('#search-panel').show();
299
			}
300
		},
301
		error: function() {
302
			$('#waitmsg').hide();
303
			$('#errmsg').show();
304
		}
305
	});
306

    
307
});
308
//]]>
309
</script>
310

    
311
<?php include("foot.inc");
312
?>
(99-99/225)