Project

General

Profile

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