Project

General

Profile

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

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

    
64
ini_set('max_execution_time', '0');
65

    
66
require_once("globals.inc");
67
require_once("guiconfig.inc");
68
require_once("pkg-utils.inc");
69

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

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

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

    
89
	$pkg_info = get_pkg_info();
90

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

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

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

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

    
115
		if ($index['www']) {
116
			$pkgtbl .= 	'<a title="' . gettext("Visit official website") . '" target="_blank" href="' . htmlspecialchars($index['www']) . '">' . "\n";
117
		}
118

    
119
		$pkgtbl .= htmlspecialchars($index['shortname']);
120
		$pkgtbl .= 		'</a>' . "\n";
121
		$pkgtbl .= 	'</td>' . "\n";
122
		$pkgtbl .= 	'<td>' . "\n";
123

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

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

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

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

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

    
145
		$pkgtbl .= 	'</td>' . "\n";
146
		$pkgtbl .= '<td>' . "\n";
147
		$pkgtbl .= '<a title="' . gettext("Click to install") . '" href="pkg_mgr_install.php?id=' . $index['name'] . '" class="btn btn-success btn-sm"><i class="fa fa-plus icon-embed-btn"></i>Install</a>' . "\n";
148

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

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

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

    
160
	return ($pkgtbl);
161
}
162

    
163
$pgtitle = array(gettext("System"), gettext("Package Manager"), gettext("Available Packages"));
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 pacakge 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
?>
(102-102/225)