Project

General

Profile

Download (7.93 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) 2005 Scott Ullrich and Colin Smith
7
    All rights reserved.
8

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

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

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

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

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

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46
require_once("pkg-utils.inc");
47

    
48
$static_output = "";
49
$static_status = "";
50
$sendto = "output";
51

    
52
$todo = array();
53

    
54
$pgtitle = array("System","Package Manager","Install Package");
55
include("head.inc");
56

    
57
?>
58

    
59
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
60
<?php include("fbegin.inc"); ?>
61
	<form action="pkg_mgr_install.php" method="post">
62
		<div id="mainareapkg">
63
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
64
				<tr>
65
					<td>
66
						<?php
67
							$version = file_get_contents("/etc/version");
68
							$tab_array = array();
69
							$tab_array[] = array("{$version} packages", false, "pkg_mgr.php");
70
//							$tab_array[] = array("Packages for any platform", false, "pkg_mgr.php?ver=none");
71
//							$tab_array[] = array("Packages for a different platform", $requested_version == "other" ? true : false, "pkg_mgr.php?ver=other");
72
							$tab_array[] = array("Installed packages", false, "pkg_mgr_installed.php");
73
							$tab_array[] = array("Package Installer", true, "");
74
							display_top_tabs($tab_array);
75
						?>
76
					</td>
77
				</tr>
78
				<tr>
79
					<td class="tabcont">
80
						<center>
81
							<table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
82
								<tr>
83
									<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_left.gif" height='15' width='5'>
84
									</td>
85
									<td>
86
										<table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
87
											<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_gray.gif" valign="top" align="left">
88
												<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
89
											</td>
90
										</table>
91
									</td>
92
									<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_right.gif" height='15' width='5'>
93
									</td>
94
								</tr>
95
							</table>
96
							<br>
97
							<!-- status box -->
98
							<textarea cols="60" rows="1" name="status" id="status" wrap="hard">Beginning package installation.</textarea>
99
							<!-- command output box -->
100
							<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea>
101
						</center>
102
					</td>
103
				</tr>
104
			</table>
105
		</div>
106
	</form>
107
<?php include("fend.inc"); ?>
108
<script type="text/javascript">
109
NiftyCheck();
110
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
111
</script>
112
</body>
113
</html>
114

    
115

    
116
<?php
117

    
118
ob_flush();
119

    
120
// Write out configuration to creatae a backup prior to pkg install
121
write_config("Creating restore point before package installation.");
122

    
123
/* mount rw fs */
124
conf_mount_rw();
125

    
126
switch($_GET['mode']) {
127
	case "delete":
128
		$id = get_pkg_id($_GET['pkg']);
129
		delete_package_xml(htmlspecialchars($_GET['pkg']));
130
		update_status("Package deleted.");
131
		$static_output .= "\nPackage deleted.";
132
		update_output_window($static_output);
133
		filter_configure();
134
		break;
135
	case "showlog":
136
		$id = htmlspecialchars($_GET['pkg']);
137
		if(strpos($id, "."))
138
			exit;
139
		update_output_window(file_get_contents("/tmp/pkg_mgr_{$id}.log"));
140
		break;
141
	case "reinstallpkg":
142
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
143
		delete_package_xml(htmlspecialchars($_GET['pkg']));
144
		install_package(htmlspecialchars($_GET['pkg']));
145
		update_status("Package reinstalled.");
146
		$static_output .= "\n\nPackage reinstalled.";
147
		start_service(htmlspecialchars($_GET['pkg']));
148
		update_output_window($static_output);
149
		filter_configure();
150
		break;
151
	case "reinstallxml":
152
		delete_package_xml(htmlspecialchars($_GET['pkg']));
153
		install_package(htmlspecialchars($_GET['pkg']));
154
		$static_output .= "\n\nPackage reinstalled.";
155
		start_service(htmlspecialchars($_GET['pkg']));
156
		update_output_window($static_output);
157
		filter_configure();
158
		break;
159
	case "installedinfo":
160
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
161
		if(file_exists("/tmp/{$_GET['pkg']}.info")) {
162
			$filename = escapeshellcmd("/tmp/" . $_GET['pkg']  . ".info");
163
			$status = file_get_contents($filename);
164
			update_status($_GET['pkg']  . " installation completed.");
165
			update_output_window($status);
166
		} else {
167
			update_output_window("Could not find {$_GET['pkg']}.");
168
		}
169
		break;
170
	case "reinstallall":
171
		if ($config['installedpackages']['package'])
172
			exec("rm -rf /var/db/pkg/*");
173
		if (is_array($config['installedpackages']['package']))
174
			foreach($config['installedpackages']['package'] as $package)
175
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
176
		$pkg_id = 0;
177
		foreach($todo as $pkgtodo) {
178
			$static_output = "";
179
			if($pkgtodo['name']) {
180
				update_output_window($static_output);
181
				delete_package($pkgtodo['name'] . '-' . $pkgtodo['version'], $pkg_id);
182
				delete_package_xml($pkgtodo['name']);
183
				install_package($pkgtodo['name']);
184
				$pkg_id++;
185
			}
186
		}
187
		update_status("All packages reinstalled.");
188
		$static_output .= "\n\nAll packages reinstalled.";
189
		start_service(htmlspecialchars($_GET['pkg']));
190
		update_output_window($static_output);
191
		filter_configure();
192
		break;
193
	default:
194
		$status = install_package(htmlspecialchars($_GET['id']));
195
		if($status == -1) {
196
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " FAILED!");
197
			$static_output .= "\n\nInstallation halted.";
198
			update_output_window($static_output);
199
		} else {
200
			$filename = escapeshellcmd("/tmp/" . $_GET['id']  . ".info");
201
			$fd = fopen($filename, "w");
202
			$status_a = "Installation of " . htmlspecialchars($_GET['id']) . " completed.";
203
			update_status($status_a);
204
			$status = get_after_install_info($_GET['id']);
205
			if($status) 
206
				$static_output .= "\nInstallation completed.\n\n{$_GET['id']} setup instructions:\n\n{$status}";
207
			else
208
				$static_output .= "\nInstallation completed.   Please check to make sure that the package is configured from the respective menu then start the package.";
209
			fwrite($fd, $status_a . "\n\n". $static_output);
210
			fclose($fd);
211
			echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$_GET['id']}\";</script>";
212
		}
213
		filter_configure();
214
		break;
215
}
216

    
217
// Delete all temporary package tarballs and staging areas.
218
unlink_if_exists("/tmp/apkg_*");
219
rmdir_recursive("/var/tmp/instmp*");
220

    
221
/* read only fs */
222
conf_mount_ro();
223

    
224
// close log
225
if($fd_log)
226
	fclose($fd_log);
227

    
228
?>
(113-113/214)