Projet

Général

Profil

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

univnautes / usr / local / www / pkg_mgr_install.php @ 1cfe5490

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
		ob_flush();
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
			ob_flush();
78
			return;
79
		}
80
		break;
81
	default:
82
		if (empty($_GET['id'])) {
83
			header("Location: pkg_mgr_installed.php");
84
			ob_flush();
85
			return;
86
		}
87
		break;
88
	}
89
}
90

    
91
?>
92

    
93
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
94
<?php include("fbegin.inc"); ?>
95
	<form action="pkg_mgr_install.php" method="post">
96
		<div id="mainareapkg">
97
			<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package manager install">
98
				<tr>
99
					<td>
100
						<?php
101
							$tab_array = array();
102
							$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
103
							$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
104
							$tab_array[] = array(gettext("Package Installer"), true, "");
105
							display_top_tabs($tab_array);
106
						?>
107
					</td>
108
				</tr>
109
<?php if ((empty($_GET['mode']) && $_GET['id']) || (!empty($_GET['mode']) && (!empty($_GET['pkg']) || $_GET['mode'] == 'reinstallall') && ($_GET['mode'] != 'installedinfo' && $_GET['mode'] != 'showlog'))):
110
	if (empty($_GET['mode']) && $_GET['id']) {
111
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
112
		$pkgmode = 'installed';
113
	} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
114
		$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
115
		$pkgmode = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['mode'], ENT_QUOTES | ENT_HTML401));
116
	} else if ($_GET['mode'] == 'reinstallall') {
117
		$pkgmode = 'reinstallall';
118
	}
119
	switch ($pkgmode) {
120
	case 'reinstallall':
121
		$pkgname = 'All packages';
122
		$pkgtxt = 'reinstalled';
123
		break;
124
	case 'reinstallxml':
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> 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
						<!-- command output box -->
174
						<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
175
					</td>
176
				</tr>
177
<?php endif; ?>
178
			</table>
179
		</div>
180
	</form>
181
<?php include("fend.inc"); ?>
182
<script type="text/javascript">
183
//<![CDATA[
184
NiftyCheck();
185
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
186
//]]>
187
</script>
188

    
189
<?php
190

    
191
ob_flush();
192

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

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

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

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

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

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

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

    
304
</body>
305
</html>
(131-131/246)