1 |
ee11cc6e
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
ee11cc6e
|
Scott Ullrich
|
/*
|
4 |
633d51b7
|
bcyrill
|
pkg_mgr_install.php
|
5 |
34e2973e
|
Chris Buechler
|
part of pfSense (https://www.pfsense.org)
|
6 |
633d51b7
|
bcyrill
|
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
|
7 |
4f6a5e6a
|
Scott Ullrich
|
Copyright (C) 2005 Colin Smith
|
8 |
633d51b7
|
bcyrill
|
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 the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
ee11cc6e
|
Scott Ullrich
|
*/
|
31 |
1d333258
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_BUILDER_BINARIES: /bin/rm
|
33 |
|
|
pfSense_MODULE: pkgs
|
34 |
|
|
*/
|
35 |
ee11cc6e
|
Scott Ullrich
|
|
36 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
37 |
|
|
##|*IDENT=page-system-packagemanager-installpackage
|
38 |
|
|
##|*NAME=System: Package Manager: Install Package page
|
39 |
|
|
##|*DESCR=Allow access to the 'System: Package Manager: Install Package' page.
|
40 |
|
|
##|*MATCH=pkg_mgr_install.php*
|
41 |
|
|
##|-PRIV
|
42 |
|
|
|
43 |
0089af7c
|
Scott Ullrich
|
ini_set('max_execution_time', '0');
|
44 |
|
|
|
45 |
7a927e67
|
Scott Ullrich
|
require("guiconfig.inc");
|
46 |
|
|
require_once("functions.inc");
|
47 |
|
|
require_once("filter.inc");
|
48 |
|
|
require_once("shaper.inc");
|
49 |
9f9dcd98
|
Scott Ullrich
|
require_once("pkg-utils.inc");
|
50 |
ee11cc6e
|
Scott Ullrich
|
|
51 |
133f8b33
|
Ermal
|
global $static_output;
|
52 |
|
|
|
53 |
9a2d499c
|
Colin Smith
|
$static_output = "";
|
54 |
|
|
$static_status = "";
|
55 |
|
|
$sendto = "output";
|
56 |
8ccc8f1a
|
Scott Ullrich
|
|
57 |
0897ff7b
|
Renato Botelho
|
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
|
58 |
52380979
|
Scott Ullrich
|
include("head.inc");
|
59 |
|
|
|
60 |
133f8b33
|
Ermal
|
if ($_POST) {
|
61 |
|
|
if (isset($_POST['pkgcancel']) || (empty($_POST['id']) && $_POST['mode'] != 'reinstallall')) {
|
62 |
|
|
header("Location: pkg_mgr_installed.php");
|
63 |
|
|
return;
|
64 |
|
|
}
|
65 |
|
|
} else if ($_GET) {
|
66 |
|
|
switch ($_GET['mode']) {
|
67 |
544a89c5
|
jim-p
|
case 'reinstallall':
|
68 |
133f8b33
|
Ermal
|
case 'showlog':
|
69 |
|
|
break;
|
70 |
|
|
case 'installedinfo':
|
71 |
|
|
case 'reinstallxml':
|
72 |
|
|
case 'reinstallpkg':
|
73 |
|
|
case 'delete':
|
74 |
|
|
if (empty($_GET['pkg'])) {
|
75 |
|
|
header("Location: pkg_mgr_installed.php");
|
76 |
|
|
return;
|
77 |
|
|
}
|
78 |
|
|
break;
|
79 |
|
|
default:
|
80 |
|
|
if (empty($_GET['id'])) {
|
81 |
|
|
header("Location: pkg_mgr_installed.php");
|
82 |
|
|
return;
|
83 |
|
|
}
|
84 |
|
|
break;
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
ee11cc6e
|
Scott Ullrich
|
?>
|
89 |
|
|
|
90 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
91 |
96d9f5c9
|
Bill Marquette
|
<?php include("fbegin.inc"); ?>
|
92 |
4c951cc9
|
Matthew Grooms
|
<form action="pkg_mgr_install.php" method="post">
|
93 |
|
|
<div id="mainareapkg">
|
94 |
600933ee
|
Colin Fleming
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package manager install">
|
95 |
8c304753
|
Colin Smith
|
<tr>
|
96 |
|
|
<td>
|
97 |
4c951cc9
|
Matthew Grooms
|
<?php
|
98 |
|
|
$tab_array = array();
|
99 |
f0e69fca
|
Chris Buechler
|
$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
|
100 |
0897ff7b
|
Renato Botelho
|
$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
|
101 |
|
|
$tab_array[] = array(gettext("Package Installer"), true, "");
|
102 |
4c951cc9
|
Matthew Grooms
|
display_top_tabs($tab_array);
|
103 |
|
|
?>
|
104 |
8c304753
|
Colin Smith
|
</td>
|
105 |
4c951cc9
|
Matthew Grooms
|
</tr>
|
106 |
133f8b33
|
Ermal
|
<?php if ((empty($_GET['mode']) && $_GET['id']) || (!empty($_GET['mode']) && (!empty($_GET['pkg']) || $_GET['mode'] == 'reinstallall') && ($_GET['mode'] != 'installedinfo' && $_GET['mode'] != 'showlog'))):
|
107 |
|
|
if (empty($_GET['mode']) && $_GET['id']) {
|
108 |
|
|
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
|
109 |
|
|
$pkgmode = 'installed';
|
110 |
|
|
} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
|
111 |
|
|
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
|
112 |
|
|
$pkgmode = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['mode'], ENT_QUOTES | ENT_HTML401));
|
113 |
544a89c5
|
jim-p
|
} else if ($_GET['mode'] == 'reinstallall') {
|
114 |
|
|
$pkgmode = 'reinstallall';
|
115 |
133f8b33
|
Ermal
|
}
|
116 |
|
|
switch ($pkgmode) {
|
117 |
544a89c5
|
jim-p
|
case 'reinstallall':
|
118 |
|
|
$pkgname = 'All packages';
|
119 |
|
|
$pkgtxt = 'reinstalled';
|
120 |
|
|
break;
|
121 |
133f8b33
|
Ermal
|
case 'reinstallxml':
|
122 |
|
|
case 'reinstallpkg':
|
123 |
|
|
$pkgtxt = 'reinstalled';
|
124 |
|
|
break;
|
125 |
|
|
case 'delete':
|
126 |
|
|
$pkgtxt = 'deleted';
|
127 |
|
|
break;
|
128 |
|
|
default:
|
129 |
|
|
$pkgtxt = $pkgmode;
|
130 |
|
|
break;
|
131 |
|
|
}
|
132 |
|
|
?>
|
133 |
|
|
<tr>
|
134 |
|
|
<td class="tabcont" align="center">
|
135 |
|
|
<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
|
136 |
|
|
<tr>
|
137 |
544a89c5
|
jim-p
|
<td class="tabcont" align="center">Package: <b><?=$pkgname;?></b> will be <?=$pkgtxt;?>.<br/>
|
138 |
|
|
Please confirm the action.<br/>
|
139 |
133f8b33
|
Ermal
|
</td>
|
140 |
|
|
<td class="tabcont" align="center">
|
141 |
|
|
<input type="hidden" name="id" value="<?=$pkgname;?>" />
|
142 |
|
|
<input type="hidden" name="mode" value="<?=$pkgmode;?>" />
|
143 |
|
|
<input type="submit" name="pkgconfirm" id="pkgconfirm" value="Confirm"/>
|
144 |
|
|
<input type="submit" name="pkgcancel" id="pkgcancel" value="Cancel"/>
|
145 |
|
|
</td>
|
146 |
|
|
</tr>
|
147 |
|
|
</table>
|
148 |
|
|
</td>
|
149 |
|
|
</tr>
|
150 |
|
|
<?php endif; if (!empty($_POST['id']) || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))): ?>
|
151 |
4c951cc9
|
Matthew Grooms
|
<tr>
|
152 |
600933ee
|
Colin Fleming
|
<td class="tabcont" align="center">
|
153 |
|
|
<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
|
154 |
|
|
<tr>
|
155 |
7bc1b968
|
Renato Botelho
|
<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5"></td>
|
156 |
600933ee
|
Colin Fleming
|
<td>
|
157 |
|
|
<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="progress bar">
|
158 |
7bc1b968
|
Renato Botelho
|
<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
|
159 |
600933ee
|
Colin Fleming
|
<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width="0" height="15" name="progressbar" id="progressbar" alt="progress bar" />
|
160 |
|
|
</td></tr>
|
161 |
|
|
</table>
|
162 |
|
|
</td>
|
163 |
7bc1b968
|
Renato Botelho
|
<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5">
|
164 |
600933ee
|
Colin Fleming
|
</td>
|
165 |
|
|
</tr>
|
166 |
|
|
</table>
|
167 |
8cd558b6
|
ayvis
|
<br />
|
168 |
600933ee
|
Colin Fleming
|
<!-- status box -->
|
169 |
|
|
<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
|
170 |
|
|
<!-- command output box -->
|
171 |
|
|
<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
|
172 |
8c304753
|
Colin Smith
|
</td>
|
173 |
|
|
</tr>
|
174 |
133f8b33
|
Ermal
|
<?php endif; ?>
|
175 |
8c304753
|
Colin Smith
|
</table>
|
176 |
4c951cc9
|
Matthew Grooms
|
</div>
|
177 |
|
|
</form>
|
178 |
ee11cc6e
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
179 |
323d040b
|
Scott Ullrich
|
<script type="text/javascript">
|
180 |
600933ee
|
Colin Fleming
|
//<![CDATA[
|
181 |
323d040b
|
Scott Ullrich
|
NiftyCheck();
|
182 |
4f409c9e
|
Scott Ullrich
|
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
|
183 |
600933ee
|
Colin Fleming
|
//]]>
|
184 |
323d040b
|
Scott Ullrich
|
</script>
|
185 |
|
|
|
186 |
b4ff3ccd
|
Scott Ullrich
|
<?php
|
187 |
91e58a1a
|
Scott Ullrich
|
|
188 |
a3af2487
|
Scott Ullrich
|
ob_flush();
|
189 |
|
|
|
190 |
133f8b33
|
Ermal
|
if ($_GET) {
|
191 |
d291634a
|
Renato Botelho
|
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
|
192 |
133f8b33
|
Ermal
|
switch($_GET['mode']) {
|
193 |
|
|
case 'showlog':
|
194 |
|
|
if (strpos($pkgname, ".")) {
|
195 |
|
|
update_output_window(gettext("Something is wrong on the request."));
|
196 |
|
|
} else if (file_exists("/tmp/pkg_mgr_{$pkgname}.log"))
|
197 |
|
|
update_output_window(@file_get_contents("/tmp/pkg_mgr_{$pkgname}.log"));
|
198 |
|
|
else
|
199 |
|
|
update_output_window(gettext("Log was not retrievable."));
|
200 |
06aa745e
|
Phil Davis
|
break;
|
201 |
133f8b33
|
Ermal
|
case 'installedinfo':
|
202 |
|
|
if (file_exists("/tmp/{$pkgname}.info")) {
|
203 |
|
|
$status = @file_get_contents("/tmp/{$pkgname}.info");
|
204 |
6766e477
|
Ermal
|
update_status("{$pkgname} " . gettext("installation completed."));
|
205 |
16654db5
|
Scott Ullrich
|
update_output_window($status);
|
206 |
2c794549
|
Ermal
|
} else
|
207 |
6766e477
|
Ermal
|
update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
|
208 |
16654db5
|
Scott Ullrich
|
break;
|
209 |
133f8b33
|
Ermal
|
default:
|
210 |
|
|
break;
|
211 |
|
|
}
|
212 |
|
|
} else if ($_POST) {
|
213 |
|
|
$pkgid = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
|
214 |
|
|
|
215 |
|
|
/* All other cases make changes, so mount rw fs */
|
216 |
|
|
conf_mount_rw();
|
217 |
|
|
/* Write out configuration to create a backup prior to pkg install. */
|
218 |
|
|
write_config(gettext("Creating restore point before package installation."));
|
219 |
|
|
|
220 |
|
|
switch ($_POST['mode']) {
|
221 |
|
|
case 'delete':
|
222 |
|
|
uninstall_package($pkgid);
|
223 |
|
|
update_status(gettext("Package deleted."));
|
224 |
|
|
$static_output .= "\n" . gettext("Package deleted.");
|
225 |
|
|
update_output_window($static_output);
|
226 |
|
|
filter_configure();
|
227 |
|
|
break;
|
228 |
|
|
case 'reinstallxml':
|
229 |
|
|
case 'reinstallpkg':
|
230 |
|
|
delete_package_xml($pkgid);
|
231 |
|
|
if (install_package($pkgid) < 0) {
|
232 |
|
|
update_status(gettext("Package reinstallation failed."));
|
233 |
|
|
$static_output .= "\n" . gettext("Package reinstallation failed.");
|
234 |
|
|
update_output_window($static_output);
|
235 |
|
|
} else {
|
236 |
|
|
update_status(gettext("Package reinstalled."));
|
237 |
|
|
$static_output .= "\n" . gettext("Package reinstalled.");
|
238 |
|
|
update_output_window($static_output);
|
239 |
|
|
filter_configure();
|
240 |
|
|
}
|
241 |
|
|
@file_put_contents("/tmp/{$pkgid}.info", $static_output);
|
242 |
|
|
$pkgid = htmlspecialchars($pkgid);
|
243 |
|
|
echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
|
244 |
|
|
break;
|
245 |
|
|
case 'reinstallall':
|
246 |
|
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['package'])) {
|
247 |
|
|
$todo = array();
|
248 |
|
|
foreach($config['installedpackages']['package'] as $package)
|
249 |
|
|
$todo[] = array('name' => $package['name'], 'version' => $package['version']);
|
250 |
|
|
foreach($todo as $pkgtodo) {
|
251 |
|
|
$static_output = "";
|
252 |
|
|
if($pkgtodo['name']) {
|
253 |
|
|
update_output_window($static_output);
|
254 |
|
|
uninstall_package($pkgtodo['name']);
|
255 |
|
|
install_package($pkgtodo['name']);
|
256 |
|
|
}
|
257 |
633d51b7
|
bcyrill
|
}
|
258 |
133f8b33
|
Ermal
|
update_status(gettext("All packages reinstalled."));
|
259 |
|
|
$static_output .= "\n" . gettext("All packages reinstalled.");
|
260 |
|
|
update_output_window($static_output);
|
261 |
|
|
filter_configure();
|
262 |
|
|
} else
|
263 |
|
|
update_output_window(gettext("No packages are installed."));
|
264 |
|
|
break;
|
265 |
|
|
case 'installed':
|
266 |
|
|
default:
|
267 |
|
|
$status = install_package($pkgid);
|
268 |
|
|
if($status == -1) {
|
269 |
|
|
update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
|
270 |
|
|
$static_output .= "\n" . gettext("Installation halted.");
|
271 |
|
|
update_output_window($static_output);
|
272 |
|
|
} else {
|
273 |
|
|
$status_a = gettext(sprintf("Installation of %s completed.", $pkgid));
|
274 |
|
|
update_status($status_a);
|
275 |
|
|
$status = get_after_install_info($pkgid);
|
276 |
|
|
if($status)
|
277 |
|
|
$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
|
278 |
|
|
else
|
279 |
|
|
$static_output .= "\n" . gettext("Installation completed. Please check to make sure that the package is configured from the respective menu then start the package.");
|
280 |
|
|
|
281 |
|
|
@file_put_contents("/tmp/{$pkgid}.info", $static_output);
|
282 |
|
|
echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
|
283 |
4c951cc9
|
Matthew Grooms
|
}
|
284 |
633d51b7
|
bcyrill
|
filter_configure();
|
285 |
133f8b33
|
Ermal
|
break;
|
286 |
|
|
}
|
287 |
91e58a1a
|
Scott Ullrich
|
|
288 |
133f8b33
|
Ermal
|
// Delete all temporary package tarballs and staging areas.
|
289 |
|
|
unlink_if_exists("/tmp/apkg_*");
|
290 |
|
|
rmdir_recursive("/var/tmp/instmp*");
|
291 |
58f130e4
|
Colin Smith
|
|
292 |
133f8b33
|
Ermal
|
// close log
|
293 |
|
|
if($fd_log)
|
294 |
|
|
fclose($fd_log);
|
295 |
8ccc8f1a
|
Scott Ullrich
|
|
296 |
06aa745e
|
Phil Davis
|
/* Restore to read only fs */
|
297 |
|
|
conf_mount_ro();
|
298 |
|
|
}
|
299 |
600933ee
|
Colin Fleming
|
?>
|
300 |
|
|
|
301 |
|
|
</body>
|
302 |
|
|
</html>
|