Project

General

Profile

Download (11.1 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
$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
	$pkg_gui_xml_text = "";
118
	switch ($pkgmode) {
119
	case 'reinstallall':
120
		$pkgname = 'All packages';
121
		$pkgtxt = 'reinstalled';
122
		break;
123
	case 'reinstallxml':
124
		$pkg_gui_xml_text = " GUI XML components";
125
	case 'reinstallpkg':
126
		$pkgtxt = 'reinstalled';
127
		break;
128
	case 'delete':
129
		$pkgtxt = 'deleted';
130
		break;
131
	default:
132
		$pkgtxt = $pkgmode;
133
		break;
134
	}
135
?>
136
				<tr>
137
					<td class="tabcont" align="center">
138
						<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
139
							<tr>
140
								<td class="tabcont" align="center">Package: <b><?=$pkgname;?></b><?=$pkg_gui_xml_text;?> will be <?=$pkgtxt;?>.<br/>
141
									Please confirm the action.<br/>
142
								</td>
143
								<td class="tabcont" align="center">
144
									<input type="hidden" name="id" value="<?=$pkgname;?>" />
145
									<input type="hidden" name="mode" value="<?=$pkgmode;?>" />
146
									<input type="submit" name="pkgconfirm" id="pkgconfirm" value="Confirm"/>
147
									<input type="submit" name="pkgcancel" id="pkgcancel" value="Cancel"/>
148
								</td>
149
							</tr>
150
						</table>
151
					</td>
152
				</tr>
153
<?php endif; if (!empty($_POST['id']) || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))): ?>
154
				<tr>
155
					<td class="tabcont" align="center">
156
						<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
157
							<tr>
158
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5"></td>
159
								<td>
160
									<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="progress bar">
161
										<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
162
											<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width="0" height="15" name="progressbar" id="progressbar" alt="progress bar" />
163
										</td></tr>
164
									</table>
165
								</td>
166
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5">
167
								</td>
168
							</tr>
169
						</table>
170
						<br />
171
						<!-- status box -->
172
						<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
173
						<br />
174
						<!-- command output box -->
175
						<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
176
					</td>
177
				</tr>
178
<?php endif; ?>
179
			</table>
180
		</div>
181
	</form>
182
<?php include("fend.inc"); ?>
183
<script type="text/javascript">
184
//<![CDATA[
185
NiftyCheck();
186
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
187
//]]>
188
</script>
189

    
190
<?php
191

    
192
ob_flush();
193

    
194
if ($_GET) {
195
	$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
196
	switch($_GET['mode']) {
197
	case 'showlog':
198
		if (strpos($pkgname, ".")) {
199
			update_output_window(gettext("Something is wrong on the request."));
200
		} else if (file_exists("/tmp/pkg_mgr_{$pkgname}.log"))
201
			update_output_window(@file_get_contents("/tmp/pkg_mgr_{$pkgname}.log"));
202
		else
203
			update_output_window(gettext("Log was not retrievable."));
204
		break;
205
	case 'installedinfo':
206
		if (file_exists("/tmp/{$pkgname}.info")) {
207
			$status = @file_get_contents("/tmp/{$pkgname}.info");
208
			update_status("{$pkgname} " . gettext("installation completed."));
209
			update_output_window($status);
210
		} else
211
			update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
212
		break;
213
	default:
214
		break;
215
	}
216
} else if ($_POST) {
217
	$pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
218

    
219
	/* All other cases make changes, so mount rw fs */
220
	conf_mount_rw();
221
	/* Write out configuration to create a backup prior to pkg install. */
222
	write_config(gettext("Creating restore point before package installation."));
223

    
224
	switch ($_POST['mode']) {
225
		case 'delete':
226
			uninstall_package($pkgid);
227
			update_status(gettext("Package deleted."));
228
			$static_output .= "\n" . gettext("Package deleted.");
229
			update_output_window($static_output);
230
			filter_configure();
231
			break;
232
		case 'reinstallxml':
233
			pkg_fetch_config_file($pkgid);
234
			pkg_fetch_additional_files($pkgid);
235
			break;
236
		case 'reinstallpkg':
237
			delete_package_xml($pkgid);
238
			if (install_package($pkgid) < 0) {
239
				update_status(gettext("Package reinstallation failed."));
240
				$static_output .= "\n" . gettext("Package reinstallation failed.");
241
				update_output_window($static_output);
242
			} else {
243
				update_status(gettext("Package reinstalled."));
244
				$static_output .= "\n" . gettext("Package reinstalled.");
245
				update_output_window($static_output);
246
				filter_configure();
247
			}
248
			@file_put_contents("/tmp/{$pkgid}.info", $static_output);
249
			$pkgid = htmlspecialchars($pkgid);
250
			echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
251
			send_event("service restart packages");
252
			break;
253
		case 'reinstallall':
254
			if (is_array($config['installedpackages']) && is_array($config['installedpackages']['package'])) {
255
				$todo = array();
256
				foreach($config['installedpackages']['package'] as $package)
257
					$todo[] = array('name' => $package['name'], 'version' => $package['version']);
258
				foreach($todo as $pkgtodo) {
259
					$static_output = "";
260
					if($pkgtodo['name']) {
261
						update_output_window($static_output);
262
						uninstall_package($pkgtodo['name']);
263
						install_package($pkgtodo['name'], '', true);
264
					}
265
				}
266
				update_status(gettext("All packages reinstalled."));
267
				$static_output .= "\n" . gettext("All packages reinstalled.");
268
				update_output_window($static_output);
269
				filter_configure();
270
				send_event("service restart packages");
271
			} else
272
				update_output_window(gettext("No packages are installed."));
273
			break;
274
		case 'installed':
275
		default:
276
			$status = install_package($pkgid);
277
			if($status == -1) {
278
				update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
279
				$static_output .= "\n" . gettext("Installation halted.");
280
				update_output_window($static_output);
281
			} else {
282
				$status_a = gettext(sprintf("Installation of %s completed.", $pkgid));
283
				update_status($status_a);
284
				$status = get_after_install_info($pkgid);
285
				if($status) 
286
					$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
287
				else
288
					$static_output .= "\n" . gettext("Installation completed.   Please check to make sure that the package is configured from the respective menu then start the package.");
289

    
290
				@file_put_contents("/tmp/{$pkgid}.info", $static_output);
291
				echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
292
			}
293
			filter_configure();
294
			break;
295
	}
296

    
297
	// Delete all temporary package tarballs and staging areas.
298
	unlink_if_exists("/tmp/apkg_*");
299
	rmdir_recursive("/var/tmp/instmp*");
300

    
301
	// close log
302
	if($fd_log)
303
		fclose($fd_log);
304

    
305
	/* Restore to read only fs */
306
	conf_mount_ro();
307
}
308
?>
309

    
310
</body>
311
</html>
(129-129/252)