Projet

Général

Profil

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

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

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
						<br />
171
						<!-- command output box -->
172
						<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
173
					</td>
174
				</tr>
175
<?php endif; ?>
176
			</table>
177
		</div>
178
	</form>
179
<?php include("fend.inc"); ?>
180
<script type="text/javascript">
181
//<![CDATA[
182
NiftyCheck();
183
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
184
//]]>
185
</script>
186

    
187
<?php
188

    
189
ob_flush();
190

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

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

    
221
	switch ($_POST['mode']) {
222
		case 'delete':
223
			uninstall_package($pkgid);
224
			update_status(gettext("Package deleted."));
225
			$static_output .= "\n" . gettext("Package deleted.");
226
			update_output_window($static_output);
227
			filter_configure();
228
			break;
229
		case 'reinstallxml':
230
			pkg_fetch_config_file($pkgid);
231
			pkg_fetch_additional_files($pkgid);
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>
(133-133/256)