Project

General

Profile

Download (10.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	pkg_mgr_install.php
5
	part of pfSense (http://www.pfSense.com)
6
	Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
7
 	Copyright (C) 2005 Colin Smith
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_BUILDER_BINARIES:	/bin/rm
33
	pfSense_MODULE:	pkgs
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-system-packagemanager-installpackage
38
##|*NAME=System: Package Manager: Install Package page
39
##|*DESCR=Allow access to the 'System: Package Manager: Install Package' page.
40
##|*MATCH=pkg_mgr_install.php*
41
##|-PRIV
42

    
43
ini_set('max_execution_time', '0');
44

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

    
51
global $static_output;
52

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

    
57
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
58
include("head.inc");
59

    
60
if ($_POST) {
61
	if (isset($_POST['pkgcancel']) || (empty($_POST['id']) && $_POST['mode'] != 'reinstallall')) {
62
		header("Location: pkg_mgr_installed.php");
63
		return;
64
	}
65
} else if ($_GET) {
66
	switch ($_GET['mode']) {
67
	case 'showlog':
68
		break;
69
	case 'installedinfo':
70
	case 'reinstallxml':
71
        case 'reinstallpkg':
72
	case 'delete':
73
		if (empty($_GET['pkg'])) {
74
			header("Location: pkg_mgr_installed.php");
75
			return;
76
		}
77
		break;
78
	default:
79
		if (empty($_GET['id'])) {
80
			header("Location: pkg_mgr_installed.php");
81
			return;
82
		}
83
		break;
84
	}
85
}
86

    
87
?>
88

    
89
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90
<?php include("fbegin.inc"); ?>
91
	<form action="pkg_mgr_install.php" method="post">
92
		<div id="mainareapkg">
93
			<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package manager install">
94
				<tr>
95
					<td>
96
						<?php
97
							$tab_array = array();
98
							$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
99
							$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
100
							$tab_array[] = array(gettext("Package Installer"), true, "");
101
							display_top_tabs($tab_array);
102
						?>
103
					</td>
104
				</tr>
105
<?php if ((empty($_GET['mode']) && $_GET['id']) || (!empty($_GET['mode']) && (!empty($_GET['pkg']) || $_GET['mode'] == 'reinstallall') && ($_GET['mode'] != 'installedinfo' && $_GET['mode'] != 'showlog'))):
106
	if (empty($_GET['mode']) && $_GET['id']) {
107
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
108
		$pkgmode = 'installed';
109
	} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
110
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
111
		$pkgmode = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['mode'], ENT_QUOTES | ENT_HTML401));
112
	}
113
	switch ($pkgmode) {
114
	case 'reinstallxml':
115
	case 'reinstallpkg':
116
		$pkgtxt = 'reinstalled';
117
		break;
118
	case 'delete':
119
		$pkgtxt = 'deleted';
120
		break;
121
	default:
122
		$pkgtxt = $pkgmode;
123
		break;
124
	}
125
?>
126
				<tr>
127
					<td class="tabcont" align="center">
128
						<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
129
							<tr>
130
								<td class="tabcont" align="center">Package:<b><?=$pkgname;?></b> will be <?=$pkgtxt;?>.<br/>
131
								Please confirm the action on this package.<br/>
132
								</td>
133
								<td class="tabcont" align="center">
134
									<input type="hidden" name="id" value="<?=$pkgname;?>" />
135
									<input type="hidden" name="mode" value="<?=$pkgmode;?>" />
136
									<input type="submit" name="pkgconfirm" id="pkgconfirm" value="Confirm"/>
137
									<input type="submit" name="pkgcancel" id="pkgcancel" value="Cancel"/>
138
								</td>
139
							</tr>
140
						</table>
141
					</td>
142
				</tr>
143
<?php endif; if (!empty($_POST['id']) || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))): ?>
144
				<tr>
145
					<td class="tabcont" align="center">
146
						<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
147
							<tr>
148
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5"></td>
149
								<td>
150
									<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="progress bar">
151
										<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
152
											<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width="0" height="15" name="progressbar" id="progressbar" alt="progress bar" />
153
										</td></tr>
154
									</table>
155
								</td>
156
								<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5">
157
								</td>
158
							</tr>
159
						</table>
160
						<br/>
161
						<!-- status box -->
162
						<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
163
						<!-- command output box -->
164
						<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
165
					</td>
166
				</tr>
167
<?php endif; ?>
168
			</table>
169
		</div>
170
	</form>
171
<?php include("fend.inc"); ?>
172
<script type="text/javascript">
173
//<![CDATA[
174
NiftyCheck();
175
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
176
//]]>
177
</script>
178

    
179
<?php
180

    
181
ob_flush();
182

    
183
if ($_GET) {
184
	$pkgname = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
185
	switch($_GET['mode']) {
186
	case 'showlog':
187
		if (strpos($pkgname, ".")) {
188
			update_output_window(gettext("Something is wrong on the request."));
189
		} else if (file_exists("/tmp/pkg_mgr_{$pkgname}.log"))
190
			update_output_window(@file_get_contents("/tmp/pkg_mgr_{$pkgname}.log"));
191
		else
192
			update_output_window(gettext("Log was not retrievable."));
193
		break;
194
	case 'installedinfo':
195
		if (file_exists("/tmp/{$pkgname}.info")) {
196
			$status = @file_get_contents("/tmp/{$pkgname}.info");
197
			update_status("{$pkgname} " . gettext("installation completed."));
198
			update_output_window($status);
199
		} else
200
			update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
201
		break;
202
	default:
203
		break;
204
	}
205
} else if ($_POST) {
206
	$pkgid = str_replace(array("<", ">", ";", "&", "'", '"'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
207

    
208
	/* All other cases make changes, so mount rw fs */
209
	conf_mount_rw();
210
	/* Write out configuration to create a backup prior to pkg install. */
211
	write_config(gettext("Creating restore point before package installation."));
212

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

    
274
				@file_put_contents("/tmp/{$pkgid}.info", $static_output);
275
				echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
276
			}
277
			filter_configure();
278
			break;
279
	}
280

    
281
	// Delete all temporary package tarballs and staging areas.
282
	unlink_if_exists("/tmp/apkg_*");
283
	rmdir_recursive("/var/tmp/instmp*");
284

    
285
	// close log
286
	if($fd_log)
287
		fclose($fd_log);
288

    
289
	/* Restore to read only fs */
290
	conf_mount_ro();
291
}
292
?>
293

    
294
</body>
295
</html>
(131-131/249)