Project

General

Profile

Download (9.54 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 133f8b33 Ermal
if ($_POST) {
59
	if (isset($_POST['pkgcancel']) || (empty($_POST['id']) && $_POST['mode'] != 'reinstallall')) {
60
		header("Location: pkg_mgr_installed.php");
61
		return;
62
	}
63
} else if ($_GET) {
64
	switch ($_GET['mode']) {
65 544a89c5 jim-p
	case 'reinstallall':
66 133f8b33 Ermal
	case 'showlog':
67
		break;
68
	case 'installedinfo':
69
	case 'reinstallxml':
70 2d26ee5e Sjon Hortensius
		case 'reinstallpkg':
71 133f8b33 Ermal
	case 'delete':
72
		if (empty($_GET['pkg'])) {
73
			header("Location: pkg_mgr_installed.php");
74
			return;
75
		}
76
		break;
77
	default:
78
		if (empty($_GET['id'])) {
79
			header("Location: pkg_mgr_installed.php");
80
			return;
81
		}
82
		break;
83
	}
84
}
85
86 2d26ee5e Sjon Hortensius
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
87
include("head.inc");
88 ee11cc6e Scott Ullrich
89 2d26ee5e Sjon Hortensius
$tab_array = array();
90
$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
91
$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
92
$tab_array[] = array(gettext("Package Installer"), true, "");
93
display_top_tabs($tab_array);
94
?>
95
<form action="pkg_mgr_install.php" method="post" class="form-horizontal">
96
	<h2>Add / remove package</h2>
97 133f8b33 Ermal
<?php if ((empty($_GET['mode']) && $_GET['id']) || (!empty($_GET['mode']) && (!empty($_GET['pkg']) || $_GET['mode'] == 'reinstallall') && ($_GET['mode'] != 'installedinfo' && $_GET['mode'] != 'showlog'))):
98
	if (empty($_GET['mode']) && $_GET['id']) {
99 7145cd87 Renato Botelho
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
100 133f8b33 Ermal
		$pkgmode = 'installed';
101
	} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
102 7145cd87 Renato Botelho
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
103
		$pkgmode = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['mode'], ENT_QUOTES | ENT_HTML401));
104 544a89c5 jim-p
	} else if ($_GET['mode'] == 'reinstallall') {
105
		$pkgmode = 'reinstallall';
106 133f8b33 Ermal
	}
107 2d26ee5e Sjon Hortensius
108 133f8b33 Ermal
	switch ($pkgmode) {
109 544a89c5 jim-p
	case 'reinstallall':
110
		$pkgname = 'All packages';
111
		$pkgtxt = 'reinstalled';
112
		break;
113 133f8b33 Ermal
	case 'reinstallxml':
114
	case 'reinstallpkg':
115
		$pkgtxt = 'reinstalled';
116
		break;
117
	case 'delete':
118
		$pkgtxt = 'deleted';
119
		break;
120
	default:
121
		$pkgtxt = $pkgmode;
122
		break;
123
	}
124
?>
125 2d26ee5e Sjon Hortensius
	<div class="panel panel-default">
126
		<div class="panel-body">
127
			<p>Package: <b><?=$pkgname;?></b> will be <?=$pkgtxt;?>.</p>
128
		</div>
129
		<div class="panel-footer">
130
			<input type="hidden" name="id" value="<?=$pkgname;?>" />
131
			<input type="hidden" name="mode" value="<?=$pkgmode;?>" />
132
			<input type="submit" name="pkgconfirm" class="btn btn-primary" value="Confirm"/>
133
			<input type="submit" name="pkgcancel" class="btn" value="Cancel"/>
134
		</div>
135
	</div>
136
<?php endif;?>
137
138
<?php if (!empty($_POST['id']) || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))):?>
139
	<div class="panel panel-default">
140
		<div class="panel-heading">
141
			<h2 id="status"><?=gettext("Beginning package installation.")?></h2>
142 4c951cc9 Matthew Grooms
		</div>
143 323d040b Scott Ullrich
144 2d26ee5e Sjon Hortensius
		<div class="panel-body">
145
			<textarea rows="15" class="form-control" id="output"></textarea>
146
147
			<div class="progress">
148
				<div id="progressbar" class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: 1%"><span class="sr-only">1% Complete</span></div>
149
			</div>
150
		</div>
151
	</div>
152
<?php endif?>
153
</form>
154 b4ff3ccd Scott Ullrich
<?php
155 91e58a1a Scott Ullrich
156 a3af2487 Scott Ullrich
ob_flush();
157
158 133f8b33 Ermal
if ($_GET) {
159 7145cd87 Renato Botelho
	$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
160 133f8b33 Ermal
	switch($_GET['mode']) {
161
	case 'showlog':
162
		if (strpos($pkgname, ".")) {
163
			update_output_window(gettext("Something is wrong on the request."));
164
		} else if (file_exists("/tmp/pkg_mgr_{$pkgname}.log"))
165
			update_output_window(@file_get_contents("/tmp/pkg_mgr_{$pkgname}.log"));
166
		else
167
			update_output_window(gettext("Log was not retrievable."));
168 06aa745e Phil Davis
		break;
169 133f8b33 Ermal
	case 'installedinfo':
170
		if (file_exists("/tmp/{$pkgname}.info")) {
171
			$status = @file_get_contents("/tmp/{$pkgname}.info");
172 6766e477 Ermal
			update_status("{$pkgname} " . gettext("installation completed."));
173 16654db5 Scott Ullrich
			update_output_window($status);
174 2c794549 Ermal
		} else
175 6766e477 Ermal
			update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
176 16654db5 Scott Ullrich
		break;
177 133f8b33 Ermal
	default:
178
		break;
179
	}
180
} else if ($_POST) {
181 7145cd87 Renato Botelho
	$pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
182 133f8b33 Ermal
183
	/* All other cases make changes, so mount rw fs */
184
	conf_mount_rw();
185
	/* Write out configuration to create a backup prior to pkg install. */
186
	write_config(gettext("Creating restore point before package installation."));
187
188
	switch ($_POST['mode']) {
189
		case 'delete':
190
			uninstall_package($pkgid);
191
			update_status(gettext("Package deleted."));
192
			$static_output .= "\n" . gettext("Package deleted.");
193
			update_output_window($static_output);
194
			filter_configure();
195
			break;
196
		case 'reinstallxml':
197 bfe9c9e7 jim-p
			pkg_fetch_config_file($pkgid);
198
			pkg_fetch_additional_files($pkgid);
199 133f8b33 Ermal
		case 'reinstallpkg':
200
			delete_package_xml($pkgid);
201
			if (install_package($pkgid) < 0) {
202
				update_status(gettext("Package reinstallation failed."));
203
				$static_output .= "\n" . gettext("Package reinstallation failed.");
204
				update_output_window($static_output);
205
			} else {
206
				update_status(gettext("Package reinstalled."));
207
				$static_output .= "\n" . gettext("Package reinstalled.");
208
				update_output_window($static_output);
209
				filter_configure();
210
			}
211
			@file_put_contents("/tmp/{$pkgid}.info", $static_output);
212
			$pkgid = htmlspecialchars($pkgid);
213
			echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
214 bf29a0f8 Ermal LUÇI
			send_event("service restart packages");
215 133f8b33 Ermal
			break;
216
		case 'reinstallall':
217
			if (is_array($config['installedpackages']) && is_array($config['installedpackages']['package'])) {
218
				$todo = array();
219
				foreach($config['installedpackages']['package'] as $package)
220
					$todo[] = array('name' => $package['name'], 'version' => $package['version']);
221
				foreach($todo as $pkgtodo) {
222
					$static_output = "";
223
					if($pkgtodo['name']) {
224
						update_output_window($static_output);
225
						uninstall_package($pkgtodo['name']);
226 aa324852 Ermal LUÇI
						install_package($pkgtodo['name'], '', true);
227 133f8b33 Ermal
					}
228 633d51b7 bcyrill
				}
229 133f8b33 Ermal
				update_status(gettext("All packages reinstalled."));
230
				$static_output .= "\n" . gettext("All packages reinstalled.");
231
				update_output_window($static_output);
232
				filter_configure();
233 bf29a0f8 Ermal LUÇI
				send_event("service restart packages");
234 133f8b33 Ermal
			} else
235
				update_output_window(gettext("No packages are installed."));
236
			break;
237
		case 'installed':
238
		default:
239
			$status = install_package($pkgid);
240
			if($status == -1) {
241
				update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
242
				$static_output .= "\n" . gettext("Installation halted.");
243
				update_output_window($static_output);
244
			} else {
245
				$status_a = gettext(sprintf("Installation of %s completed.", $pkgid));
246
				update_status($status_a);
247
				$status = get_after_install_info($pkgid);
248 2d26ee5e Sjon Hortensius
				if($status)
249 133f8b33 Ermal
					$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
250
				else
251
					$static_output .= "\n" . gettext("Installation completed.   Please check to make sure that the package is configured from the respective menu then start the package.");
252
253
				@file_put_contents("/tmp/{$pkgid}.info", $static_output);
254
				echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
255 4c951cc9 Matthew Grooms
			}
256 633d51b7 bcyrill
			filter_configure();
257 133f8b33 Ermal
			break;
258
	}
259 91e58a1a Scott Ullrich
260 133f8b33 Ermal
	// Delete all temporary package tarballs and staging areas.
261
	unlink_if_exists("/tmp/apkg_*");
262
	rmdir_recursive("/var/tmp/instmp*");
263 58f130e4 Colin Smith
264 133f8b33 Ermal
	// close log
265
	if($fd_log)
266
		fclose($fd_log);
267 8ccc8f1a Scott Ullrich
268 06aa745e Phil Davis
	/* Restore to read only fs */
269
	conf_mount_ro();
270
}
271 600933ee Colin Fleming
272 2d26ee5e Sjon Hortensius
include('foot.inc')?>