Project

General

Profile

Download (9.54 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	pkg_mgr_install.php
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
8
 	Copyright (C) 2005 Colin Smith
9
	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
*/
32
/*
33
	pfSense_BUILDER_BINARIES:	/bin/rm
34
	pfSense_MODULE:	pkgs
35
*/
36

    
37
##|+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
ini_set('max_execution_time', '0');
45

    
46
require("guiconfig.inc");
47
require_once("functions.inc");
48
require_once("filter.inc");
49
require_once("shaper.inc");
50
require_once("pkg-utils.inc");
51

    
52
global $static_output;
53

    
54
$static_output = "";
55
$static_status = "";
56
$sendto = "output";
57

    
58
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
	case 'reinstallall':
66
	case 'showlog':
67
		break;
68
	case 'installedinfo':
69
	case 'reinstallxml':
70
		case 'reinstallpkg':
71
	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
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
87
include("head.inc");
88

    
89
$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
<?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
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
100
		$pkgmode = 'installed';
101
	} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
102
		$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
	} else if ($_GET['mode'] == 'reinstallall') {
105
		$pkgmode = 'reinstallall';
106
	}
107

    
108
	switch ($pkgmode) {
109
	case 'reinstallall':
110
		$pkgname = 'All packages';
111
		$pkgtxt = 'reinstalled';
112
		break;
113
	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
	<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
		</div>
143

    
144
		<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
<?php
155

    
156
ob_flush();
157

    
158
if ($_GET) {
159
	$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
160
	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
		break;
169
	case 'installedinfo':
170
		if (file_exists("/tmp/{$pkgname}.info")) {
171
			$status = @file_get_contents("/tmp/{$pkgname}.info");
172
			update_status("{$pkgname} " . gettext("installation completed."));
173
			update_output_window($status);
174
		} else
175
			update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
176
		break;
177
	default:
178
		break;
179
	}
180
} else if ($_POST) {
181
	$pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
182

    
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
			pkg_fetch_config_file($pkgid);
198
			pkg_fetch_additional_files($pkgid);
199
		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
			send_event("service restart packages");
215
			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
						install_package($pkgtodo['name'], '', true);
227
					}
228
				}
229
				update_status(gettext("All packages reinstalled."));
230
				$static_output .= "\n" . gettext("All packages reinstalled.");
231
				update_output_window($static_output);
232
				filter_configure();
233
				send_event("service restart packages");
234
			} 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
				if($status)
249
					$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
			}
256
			filter_configure();
257
			break;
258
	}
259

    
260
	// Delete all temporary package tarballs and staging areas.
261
	unlink_if_exists("/tmp/apkg_*");
262
	rmdir_recursive("/var/tmp/instmp*");
263

    
264
	// close log
265
	if($fd_log)
266
		fclose($fd_log);
267

    
268
	/* Restore to read only fs */
269
	conf_mount_ro();
270
}
271

    
272
include('foot.inc')?>
(130-130/252)