Project

General

Profile

Download (8.12 KB) Statistics
| Branch: | Tag: | Revision:
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
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
56
include("head.inc");
57

    
58
?>
59

    
60
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
61
<?php include("fbegin.inc"); ?>
62
	<form action="pkg_mgr_install.php" method="post">
63
		<div id="mainareapkg">
64
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
65
				<tr>
66
					<td>
67
						<?php
68
//							$version = file_get_contents("/etc/version");
69
							$tab_array = array();
70
							$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
71
//							$tab_array[] = array("Packages for any platform", false, "pkg_mgr.php?ver=none");
72
//							$tab_array[] = array("Packages for a different platform", $requested_version == "other" ? true : false, "pkg_mgr.php?ver=other");
73
							$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
74
							$tab_array[] = array(gettext("Package Installer"), true, "");
75
							display_top_tabs($tab_array);
76
						?>
77
					</td>
78
				</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
							<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
100
							<!-- command output box -->
101
							<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
102
						</center>
103
					</td>
104
				</tr>
105
			</table>
106
		</div>
107
	</form>
108
<?php include("fend.inc"); ?>
109
<script type="text/javascript">
110
NiftyCheck();
111
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
112
</script>
113
</body>
114
</html>
115

    
116

    
117
<?php
118

    
119
ob_flush();
120

    
121
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

    
136
switch($_GET['mode']) {
137
	case "delete":
138
		uninstall_package($_GET['pkg']);
139
		update_status(gettext("Package deleted."));
140
		$static_output .= "\n" . gettext("Package deleted.");
141
		update_output_window($static_output);
142
		filter_configure();
143
		break;
144
	case "showlog":
145
		$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
	case "reinstallxml":
151
	case "reinstallpkg":
152
		delete_package_xml(htmlspecialchars($_GET['pkg']));
153
		if (install_package(htmlspecialchars($_GET['pkg'])) < 0) {
154
			update_status(gettext("Package reinstallation failed."));
155
			$static_output .= "\n" . gettext("Package reinstallation failed.");
156
			update_output_window($static_output);
157
		} else {
158
			update_status(gettext("Package reinstalled."));
159
			$static_output .= "\n" . gettext("Package reinstalled.");
160
			update_output_window($static_output);
161
			filter_configure();
162
		}
163
		file_put_contents("/tmp/{$_GET['pkg']}.info", $static_output);
164
		echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$_GET['pkg']}\";</script>";
165
		break;
166
	case "installedinfo":
167
		if(file_exists("/tmp/{$_GET['pkg']}.info")) {
168
			$filename = escapeshellcmd("/tmp/" . $_GET['pkg']  . ".info");
169
			$status = file_get_contents($filename);
170
			update_status($_GET['pkg']  . " " . gettext("installation completed."));
171
			update_output_window($status);
172
		} else
173
			update_output_window(sprintf(gettext("Could not find %s."), htmlspecialchars($_GET['pkg'])));
174
		break;
175
	case "reinstallall":
176
		if (is_array($config['installedpackages']['package'])) {
177
			$todo = array();
178
			foreach($config['installedpackages']['package'] as $package)
179
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
180
			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
			}
188
			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
		break;
195
	default:
196
		$pkgid = htmlspecialchars($_GET['id']);
197
		$status = install_package($pkgid);
198
		if($status == -1) {
199
			update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
200
			$static_output .= "\n" . gettext("Installation halted.");
201
			update_output_window($static_output);
202
		} else {
203
			$status_a = gettext("Installation of") . " {$pkgid} " . gettext("completed.");
204
			update_status($status_a);
205
			$status = get_after_install_info($pkgid);
206
			if($status) 
207
				$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
208
			else
209
				$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
		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
		}
213
		filter_configure();
214
		break;
215
}
216

    
217
// Delete all temporary package tarballs and staging areas.
218
unlink_if_exists("/tmp/apkg_*");
219
rmdir_recursive("/var/tmp/instmp*");
220

    
221
// close log
222
if($fd_log)
223
	fclose($fd_log);
224

    
225
if($fs_mounted_rw) {
226
	/* Restore to read only fs */
227
	conf_mount_ro();
228
}
229
?>
(131-131/249)