Project

General

Profile

Download (8.22 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 600933ee Colin Fleming
			<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package manager install">
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 600933ee Colin Fleming
					<td class="tabcont" align="center">
81
						<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
82
							<tr>
83 7bc1b968 Renato Botelho
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5"></td>
84 600933ee Colin Fleming
								<td>
85
									<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="progress bar">
86 7bc1b968 Renato Botelho
										<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
87 600933ee Colin Fleming
											<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width="0" height="15" name="progressbar" id="progressbar" alt="progress bar" />
88
										</td></tr>
89
									</table>
90
								</td>
91 7bc1b968 Renato Botelho
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5">
92 600933ee Colin Fleming
								</td>
93
							</tr>
94
						</table>
95
						<br/>
96
						<!-- status box -->
97
						<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
98
						<!-- command output box -->
99
						<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
100 8c304753 Colin Smith
					</td>
101
				</tr>
102
			</table>
103 4c951cc9 Matthew Grooms
		</div>
104
	</form>
105 ee11cc6e Scott Ullrich
<?php include("fend.inc"); ?>
106 323d040b Scott Ullrich
<script type="text/javascript">
107 600933ee Colin Fleming
//<![CDATA[
108 323d040b Scott Ullrich
NiftyCheck();
109 4f409c9e Scott Ullrich
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
110 600933ee Colin Fleming
//]]>
111 323d040b Scott Ullrich
</script>
112
113 b4ff3ccd Scott Ullrich
<?php
114 91e58a1a Scott Ullrich
115 a3af2487 Scott Ullrich
ob_flush();
116
117 06aa745e Phil Davis
switch($_GET['mode']) {
118
	case "showlog":
119
	case "installedinfo":
120
		/* These cases do not make changes. */
121
		$fs_mounted_rw = false;
122
		break;
123
	default:
124
		/* All other cases make changes, so mount rw fs */
125
		conf_mount_rw();
126
		$fs_mounted_rw = true;
127
		/* Write out configuration to create a backup prior to pkg install. */
128
		write_config(gettext("Creating restore point before package installation."));
129
		break;
130
}
131 91e58a1a Scott Ullrich
132 e1531d00 Colin Smith
switch($_GET['mode']) {
133
	case "delete":
134 2c794549 Ermal
		uninstall_package($_GET['pkg']);
135 0897ff7b Renato Botelho
		update_status(gettext("Package deleted."));
136
		$static_output .= "\n" . gettext("Package deleted.");
137 4c951cc9 Matthew Grooms
		update_output_window($static_output);
138 f69d50ce Ermal Lu?i
		filter_configure();
139 4c951cc9 Matthew Grooms
		break;
140 af6f0a3a Scott Ullrich
	case "showlog":
141 4c951cc9 Matthew Grooms
		$id = htmlspecialchars($_GET['pkg']);
142
		if(strpos($id, "."))
143
			exit;
144
		update_output_window(file_get_contents("/tmp/pkg_mgr_{$id}.log"));
145
		break;
146 e1531d00 Colin Smith
	case "reinstallxml":
147 2229d94e jim-p
	case "reinstallpkg":
148 4c951cc9 Matthew Grooms
		delete_package_xml(htmlspecialchars($_GET['pkg']));
149 2c794549 Ermal
		if (install_package(htmlspecialchars($_GET['pkg'])) < 0) {
150
			update_status(gettext("Package reinstallation failed."));
151 fcf92dae Ermal
			$static_output .= "\n" . gettext("Package reinstallation failed.");
152 2c794549 Ermal
			update_output_window($static_output);
153
		} else {
154
			update_status(gettext("Package reinstalled."));
155 fcf92dae Ermal
			$static_output .= "\n" . gettext("Package reinstalled.");
156 2c794549 Ermal
			update_output_window($static_output);
157
			filter_configure();
158
		}
159 5edb6fee Scott Ullrich
		file_put_contents("/tmp/{$_GET['pkg']}.info", $static_output);
160 d98d2db3 Scott Ullrich
		echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$_GET['pkg']}\";</script>";
161 4c951cc9 Matthew Grooms
		break;
162 16654db5 Scott Ullrich
	case "installedinfo":
163
		if(file_exists("/tmp/{$_GET['pkg']}.info")) {
164
			$filename = escapeshellcmd("/tmp/" . $_GET['pkg']  . ".info");
165
			$status = file_get_contents($filename);
166 0897ff7b Renato Botelho
			update_status($_GET['pkg']  . " " . gettext("installation completed."));
167 16654db5 Scott Ullrich
			update_output_window($status);
168 2c794549 Ermal
		} else
169 33ba4131 jim-p
			update_output_window(sprintf(gettext("Could not find %s."), htmlspecialchars($_GET['pkg'])));
170 16654db5 Scott Ullrich
		break;
171 e1531d00 Colin Smith
	case "reinstallall":
172 633d51b7 bcyrill
		if (is_array($config['installedpackages']['package'])) {
173
			$todo = array();
174 4c951cc9 Matthew Grooms
			foreach($config['installedpackages']['package'] as $package)
175
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
176 633d51b7 bcyrill
			foreach($todo as $pkgtodo) {
177
				$static_output = "";
178
				if($pkgtodo['name']) {
179
					update_output_window($static_output);
180
					uninstall_package($pkgtodo['name']);
181
					install_package($pkgtodo['name']);
182
				}
183 4c951cc9 Matthew Grooms
			}
184 633d51b7 bcyrill
			update_status(gettext("All packages reinstalled."));
185
			$static_output .= "\n" . gettext("All packages reinstalled.");
186
			update_output_window($static_output);
187
			filter_configure();
188
		} else
189
			update_output_window(gettext("No packages are installed."));
190 4c951cc9 Matthew Grooms
		break;
191 e1531d00 Colin Smith
	default:
192 33ba4131 jim-p
		$pkgid = htmlspecialchars($_GET['id']);
193
		$status = install_package($pkgid);
194 4c951cc9 Matthew Grooms
		if($status == -1) {
195 33ba4131 jim-p
			update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
196 fcf92dae Ermal
			$static_output .= "\n" . gettext("Installation halted.");
197 16654db5 Scott Ullrich
			update_output_window($static_output);
198 4c951cc9 Matthew Grooms
		} else {
199 33ba4131 jim-p
			$status_a = gettext("Installation of") . " {$pkgid} " . gettext("completed.");
200 16654db5 Scott Ullrich
			update_status($status_a);
201 33ba4131 jim-p
			$status = get_after_install_info($pkgid);
202 cfde64b8 Scott Ullrich
			if($status) 
203 33ba4131 jim-p
				$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
204 cfde64b8 Scott Ullrich
			else
205 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.");
206 33ba4131 jim-p
		file_put_contents("/tmp/{$pkgid}.info", $static_output);
207
		echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
208 4c951cc9 Matthew Grooms
		}
209 f69d50ce Ermal Lu?i
		filter_configure();
210
		break;
211 efd81869 Colin Smith
}
212 91e58a1a Scott Ullrich
213 58f130e4 Colin Smith
// Delete all temporary package tarballs and staging areas.
214
unlink_if_exists("/tmp/apkg_*");
215
rmdir_recursive("/var/tmp/instmp*");
216
217 8ccc8f1a Scott Ullrich
// close log
218 276d1b95 Colin Smith
if($fd_log)
219 633d51b7 bcyrill
	fclose($fd_log);
220 8ccc8f1a Scott Ullrich
221 06aa745e Phil Davis
if($fs_mounted_rw) {
222
	/* Restore to read only fs */
223
	conf_mount_ro();
224
}
225 600933ee Colin Fleming
?>
226
227
</body>
228
</html>