Project

General

Profile

Download (11 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-2014 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
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
59
include("head.inc");
60

    
61
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
	case 'reinstallall':
69
	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
?>
90

    
91
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
92
<?php include("fbegin.inc"); ?>
93
	<form action="pkg_mgr_install.php" method="post">
94
		<div id="mainareapkg">
95
			<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package manager install">
96
				<tr>
97
					<td>
98
						<?php
99
							$tab_array = array();
100
							$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
101
							$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
102
							$tab_array[] = array(gettext("Package Installer"), true, "");
103
							display_top_tabs($tab_array);
104
						?>
105
					</td>
106
				</tr>
107
<?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
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
110
		$pkgmode = 'installed';
111
	} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
112
		$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
	} else if ($_GET['mode'] == 'reinstallall') {
115
		$pkgmode = 'reinstallall';
116
	}
117
	switch ($pkgmode) {
118
	case 'reinstallall':
119
		$pkgname = 'All packages';
120
		$pkgtxt = 'reinstalled';
121
		break;
122
	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
								<td class="tabcont" align="center">Package: <b><?=$pkgname;?></b> will be <?=$pkgtxt;?>.<br/>
139
								Please confirm the action.<br/>
140
								</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
				<tr>
153
					<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
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5"></td>
157
								<td>
158
									<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="progress bar">
159
										<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
160
											<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
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5">
165
								</td>
166
							</tr>
167
						</table>
168
						<br />
169
						<!-- status box -->
170
						<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
171
						<br />
172
						<!-- command output box -->
173
						<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
174
					</td>
175
				</tr>
176
<?php endif; ?>
177
			</table>
178
		</div>
179
	</form>
180
<?php include("fend.inc"); ?>
181
<script type="text/javascript">
182
//<![CDATA[
183
NiftyCheck();
184
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
185
//]]>
186
</script>
187

    
188
<?php
189

    
190
ob_flush();
191

    
192
if ($_GET) {
193
	$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
194
	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
		break;
203
	case 'installedinfo':
204
		if (file_exists("/tmp/{$pkgname}.info")) {
205
			$status = @file_get_contents("/tmp/{$pkgname}.info");
206
			update_status("{$pkgname} " . gettext("installation completed."));
207
			update_output_window($status);
208
		} else
209
			update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
210
		break;
211
	default:
212
		break;
213
	}
214
} else if ($_POST) {
215
	$pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
216

    
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
			pkg_fetch_config_file($pkgid);
232
			pkg_fetch_additional_files($pkgid);
233
		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
			send_event("service restart packages");
249
			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
						install_package($pkgtodo['name'], '', true);
261
					}
262
				}
263
				update_status(gettext("All packages reinstalled."));
264
				$static_output .= "\n" . gettext("All packages reinstalled.");
265
				update_output_window($static_output);
266
				filter_configure();
267
				send_event("service restart packages");
268
			} 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
			}
290
			filter_configure();
291
			break;
292
	}
293

    
294
	// Delete all temporary package tarballs and staging areas.
295
	unlink_if_exists("/tmp/apkg_*");
296
	rmdir_recursive("/var/tmp/instmp*");
297

    
298
	// close log
299
	if($fd_log)
300
		fclose($fd_log);
301

    
302
	/* Restore to read only fs */
303
	conf_mount_ro();
304
}
305
?>
306

    
307
</body>
308
</html>
(133-133/256)