1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
pkg_mgr_install.php
|
5
|
part of pfSense (http://www.pfSense.com)
|
6
|
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
|
7
|
Copyright (C) 2005 Colin Smith
|
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 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
|
*/
|
31
|
/*
|
32
|
pfSense_BUILDER_BINARIES: /bin/rm
|
33
|
pfSense_MODULE: pkgs
|
34
|
*/
|
35
|
|
36
|
##|+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
|
ini_set('max_execution_time', '0');
|
44
|
|
45
|
require("guiconfig.inc");
|
46
|
require_once("functions.inc");
|
47
|
require_once("filter.inc");
|
48
|
require_once("shaper.inc");
|
49
|
require_once("pkg-utils.inc");
|
50
|
|
51
|
$static_output = "";
|
52
|
$static_status = "";
|
53
|
$sendto = "output";
|
54
|
|
55
|
$todo = array();
|
56
|
|
57
|
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
|
58
|
include("head.inc");
|
59
|
|
60
|
?>
|
61
|
|
62
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
63
|
<?php include("fbegin.inc"); ?>
|
64
|
<form action="pkg_mgr_install.php" method="post">
|
65
|
<div id="mainareapkg">
|
66
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
67
|
<tr>
|
68
|
<td>
|
69
|
<?php
|
70
|
// $version = file_get_contents("/etc/version");
|
71
|
$tab_array = array();
|
72
|
$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
|
73
|
// $tab_array[] = array("Packages for any platform", false, "pkg_mgr.php?ver=none");
|
74
|
// $tab_array[] = array("Packages for a different platform", $requested_version == "other" ? true : false, "pkg_mgr.php?ver=other");
|
75
|
$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
|
76
|
$tab_array[] = array(gettext("Package Installer"), true, "");
|
77
|
display_top_tabs($tab_array);
|
78
|
?>
|
79
|
</td>
|
80
|
</tr>
|
81
|
<tr>
|
82
|
<td class="tabcont">
|
83
|
<center>
|
84
|
<table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
|
85
|
<tr>
|
86
|
<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_left.gif" height='15' width='5'>
|
87
|
</td>
|
88
|
<td>
|
89
|
<table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
|
90
|
<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_gray.gif" valign="top" align="left">
|
91
|
<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
|
92
|
</td>
|
93
|
</table>
|
94
|
</td>
|
95
|
<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_right.gif" height='15' width='5'>
|
96
|
</td>
|
97
|
</tr>
|
98
|
</table>
|
99
|
<br>
|
100
|
<!-- status box -->
|
101
|
<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
|
102
|
<!-- command output box -->
|
103
|
<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
|
104
|
</center>
|
105
|
</td>
|
106
|
</tr>
|
107
|
</table>
|
108
|
</div>
|
109
|
</form>
|
110
|
<?php include("fend.inc"); ?>
|
111
|
<script type="text/javascript">
|
112
|
NiftyCheck();
|
113
|
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
|
114
|
</script>
|
115
|
</body>
|
116
|
</html>
|
117
|
|
118
|
|
119
|
<?php
|
120
|
|
121
|
ob_flush();
|
122
|
|
123
|
switch($_GET['mode']) {
|
124
|
case "showlog":
|
125
|
case "installedinfo":
|
126
|
/* These cases do not make changes. */
|
127
|
$fs_mounted_rw = false;
|
128
|
break;
|
129
|
default:
|
130
|
/* All other cases make changes, so mount rw fs */
|
131
|
conf_mount_rw();
|
132
|
$fs_mounted_rw = true;
|
133
|
/* Write out configuration to create a backup prior to pkg install. */
|
134
|
write_config(gettext("Creating restore point before package installation."));
|
135
|
break;
|
136
|
}
|
137
|
|
138
|
switch($_GET['mode']) {
|
139
|
case "delete":
|
140
|
uninstall_package($_GET['pkg']);
|
141
|
update_status(gettext("Package deleted."));
|
142
|
$static_output .= "\n" . gettext("Package deleted.");
|
143
|
update_output_window($static_output);
|
144
|
filter_configure();
|
145
|
break;
|
146
|
case "showlog":
|
147
|
$id = htmlspecialchars($_GET['pkg']);
|
148
|
if(strpos($id, "."))
|
149
|
exit;
|
150
|
update_output_window(file_get_contents("/tmp/pkg_mgr_{$id}.log"));
|
151
|
break;
|
152
|
case "reinstallxml":
|
153
|
case "reinstallpkg":
|
154
|
delete_package_xml(htmlspecialchars($_GET['pkg']));
|
155
|
if (install_package(htmlspecialchars($_GET['pkg'])) < 0) {
|
156
|
update_status(gettext("Package reinstallation failed."));
|
157
|
$static_output .= "\n" . gettext("Package reinstallation failed.");
|
158
|
update_output_window($static_output);
|
159
|
} else {
|
160
|
update_status(gettext("Package reinstalled."));
|
161
|
$static_output .= "\n" . gettext("Package reinstalled.");
|
162
|
update_output_window($static_output);
|
163
|
filter_configure();
|
164
|
}
|
165
|
file_put_contents("/tmp/{$_GET['pkg']}.info", $static_output);
|
166
|
echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$_GET['pkg']}\";</script>";
|
167
|
break;
|
168
|
case "installedinfo":
|
169
|
if(file_exists("/tmp/{$_GET['pkg']}.info")) {
|
170
|
$filename = escapeshellcmd("/tmp/" . $_GET['pkg'] . ".info");
|
171
|
$status = file_get_contents($filename);
|
172
|
update_status($_GET['pkg'] . " " . gettext("installation completed."));
|
173
|
update_output_window($status);
|
174
|
} else
|
175
|
update_output_window(sprintf(gettext("Could not find %s."), htmlspecialchars($_GET['pkg'])));
|
176
|
break;
|
177
|
case "reinstallall":
|
178
|
if (is_array($config['installedpackages']['package']))
|
179
|
foreach($config['installedpackages']['package'] as $package)
|
180
|
$todo[] = array('name' => $package['name'], 'version' => $package['version']);
|
181
|
$pkg_id = 0;
|
182
|
foreach($todo as $pkgtodo) {
|
183
|
$static_output = "";
|
184
|
if($pkgtodo['name']) {
|
185
|
update_output_window($static_output);
|
186
|
uninstall_package($pkgtodo['name']);
|
187
|
install_package($pkgtodo['name']);
|
188
|
$pkg_id++;
|
189
|
}
|
190
|
}
|
191
|
update_status(gettext("All packages reinstalled."));
|
192
|
$static_output .= "\n" . gettext("All packages reinstalled.");
|
193
|
update_output_window($static_output);
|
194
|
filter_configure();
|
195
|
break;
|
196
|
default:
|
197
|
$pkgid = htmlspecialchars($_GET['id']);
|
198
|
$status = install_package($pkgid);
|
199
|
if($status == -1) {
|
200
|
update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
|
201
|
$static_output .= "\n" . gettext("Installation halted.");
|
202
|
update_output_window($static_output);
|
203
|
} else {
|
204
|
$status_a = gettext("Installation of") . " {$pkgid} " . gettext("completed.");
|
205
|
update_status($status_a);
|
206
|
$status = get_after_install_info($pkgid);
|
207
|
if($status)
|
208
|
$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
|
209
|
else
|
210
|
$static_output .= "\n" . gettext("Installation completed. Please check to make sure that the package is configured from the respective menu then start the package.");
|
211
|
file_put_contents("/tmp/{$pkgid}.info", $static_output);
|
212
|
echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
|
213
|
}
|
214
|
filter_configure();
|
215
|
break;
|
216
|
}
|
217
|
|
218
|
// Delete all temporary package tarballs and staging areas.
|
219
|
unlink_if_exists("/tmp/apkg_*");
|
220
|
rmdir_recursive("/var/tmp/instmp*");
|
221
|
|
222
|
// close log
|
223
|
if($fd_log)
|
224
|
fclose($fd_log);
|
225
|
|
226
|
if($fs_mounted_rw) {
|
227
|
/* Restore to read only fs */
|
228
|
conf_mount_ro();
|
229
|
}
|
230
|
?>
|