Project

General

Profile

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