Projet

Général

Profil

Télécharger (10,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / pkg_mgr_install.php @ bfe9c9e7

1
<?php
2
/* $Id$ */
3
/*
4
	pkg_mgr_install.php
5
	part of pfSense (https://www.pfsense.org)
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 'reinstallall':
68
	case 'showlog':
69
		break;
70
	case 'installedinfo':
71
	case 'reinstallxml':
72
        case 'reinstallpkg':
73
	case 'delete':
74
		if (empty($_GET['pkg'])) {
75
			header("Location: pkg_mgr_installed.php");
76
			return;
77
		}
78
		break;
79
	default:
80
		if (empty($_GET['id'])) {
81
			header("Location: pkg_mgr_installed.php");
82
			return;
83
		}
84
		break;
85
	}
86
}
87

    
88
?>
89

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

    
186
<?php
187

    
188
ob_flush();
189

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

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

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

    
283
				@file_put_contents("/tmp/{$pkgid}.info", $static_output);
284
				echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
285
			}
286
			filter_configure();
287
			break;
288
	}
289

    
290
	// Delete all temporary package tarballs and staging areas.
291
	unlink_if_exists("/tmp/apkg_*");
292
	rmdir_recursive("/var/tmp/instmp*");
293

    
294
	// close log
295
	if($fd_log)
296
		fclose($fd_log);
297

    
298
	/* Restore to read only fs */
299
	conf_mount_ro();
300
}
301
?>
302

    
303
</body>
304
</html>
(132-132/255)