Project

General

Profile

Download (7.68 KB) Statistics
| Branch: | Tag: | Revision:
1 ee11cc6e Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 ee11cc6e Scott Ullrich
/*
4
    pkg_mgr_install.php
5 1548745b Scott Ullrich
    part of pfSense (http://www.pfSense.com)
6 9a2d499c Colin Smith
    Copyright (C) 2005 Scott Ullrich and Colin Smith
7 ee11cc6e Scott Ullrich
    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 6b07c15a Matthew Grooms
##|+PRIV
32
##|*IDENT=page-system-packagemanager-installpackage
33
##|*NAME=System: Package Manager: Install Package page
34
##|*DESCR=Allow access to the 'System: Package Manager: Install Package' page.
35
##|*MATCH=pkg_mgr_install.php*
36
##|-PRIV
37
38
39 9f9dcd98 Scott Ullrich
require_once("guiconfig.inc");
40
require_once("pkg-utils.inc");
41 ee11cc6e Scott Ullrich
42 9a2d499c Colin Smith
$static_output = "";
43
$static_status = "";
44
$sendto = "output";
45 8ccc8f1a Scott Ullrich
46 25cbd600 Scott Ullrich
$todo = array();
47
48 d88c6a9f Scott Ullrich
$pgtitle = array("System","Package Manager","Install Package");
49 52380979 Scott Ullrich
include("head.inc");
50
51 ee11cc6e Scott Ullrich
?>
52
53
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
54 96d9f5c9 Bill Marquette
<?php include("fbegin.inc"); ?>
55 4c951cc9 Matthew Grooms
	<form action="pkg_mgr_install.php" method="post">
56
		<div id="mainareapkg">
57
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
58 8c304753 Colin Smith
				<tr>
59
					<td>
60 4c951cc9 Matthew Grooms
						<?php
61
							$version = file_get_contents("/etc/version");
62
							$tab_array = array();
63
							$tab_array[] = array("Available {$version} packages", false, "pkg_mgr.php");
64
							$tab_array[] = array("Packages for any platform", false, "pkg_mgr.php?ver=none");
65
//							$tab_array[] = array("Packages for a different platform", $requested_version == "other" ? true : false, "pkg_mgr.php?ver=other");
66
							$tab_array[] = array("Installed packages", false, "pkg_mgr_installed.php");
67
							$tab_array[] = array("Package Installer", true, "");
68
							display_top_tabs($tab_array);
69
						?>
70 8c304753 Colin Smith
					</td>
71 4c951cc9 Matthew Grooms
				</tr>
72
				<tr>
73
					<td class="tabcont">
74
						<center>
75
							<table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
76
								<tr>
77
									<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_left.gif" height='15' width='5'>
78
									</td>
79
									<td>
80
										<table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
81
											<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_gray.gif" valign="top" align="left">
82
												<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
83
											</td>
84
										</table>
85
									</td>
86
									<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_right.gif" height='15' width='5'>
87
									</td>
88
								</tr>
89
							</table>
90
							<br>
91
							<!-- status box -->
92 f8a437b6 Bill Marquette
							<textarea cols="60" rows="1" name="status" id="status" wrap="hard">Beginning package installation.</textarea>
93 4c951cc9 Matthew Grooms
							<!-- command output box -->
94 f8a437b6 Bill Marquette
							<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea>
95 4c951cc9 Matthew Grooms
						</center>
96 8c304753 Colin Smith
					</td>
97
				</tr>
98
			</table>
99 4c951cc9 Matthew Grooms
		</div>
100
	</form>
101 ee11cc6e Scott Ullrich
<?php include("fend.inc"); ?>
102 323d040b Scott Ullrich
<script type="text/javascript">
103
NiftyCheck();
104 4f409c9e Scott Ullrich
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
105 323d040b Scott Ullrich
</script>
106 ee11cc6e Scott Ullrich
</body>
107
</html>
108
109 323d040b Scott Ullrich
110 b4ff3ccd Scott Ullrich
<?php
111 91e58a1a Scott Ullrich
112 a3af2487 Scott Ullrich
ob_flush();
113
114 864b3976 Scott Ullrich
// Write out configuration to creatae a backup prior to pkg install
115
write_config("Creating restore point before package installation.");
116
117 91e58a1a Scott Ullrich
/* mount rw fs */
118
conf_mount_rw();
119
120 e1531d00 Colin Smith
switch($_GET['mode']) {
121
	case "delete":
122 4c951cc9 Matthew Grooms
		$id = get_pkg_id($_GET['pkg']);
123
		delete_package_xml(htmlspecialchars($_GET['pkg']));
124
		update_status("Package deleted.");
125
		$static_output .= "\nPackage deleted.";
126
		update_output_window($static_output);
127
		break;
128 af6f0a3a Scott Ullrich
	case "showlog":
129 4c951cc9 Matthew Grooms
		$id = htmlspecialchars($_GET['pkg']);
130
		if(strpos($id, "."))
131
			exit;
132
		update_output_window(file_get_contents("/tmp/pkg_mgr_{$id}.log"));
133
		break;
134 e1531d00 Colin Smith
	case "reinstallpkg":
135 4c951cc9 Matthew Grooms
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
136
		delete_package_xml(htmlspecialchars($_GET['pkg']));
137
		install_package(htmlspecialchars($_GET['pkg']));
138
		update_status("Package reinstalled.");
139
		$static_output .= "\n\nPackage reinstalled.";
140
		start_service(htmlspecialchars($_GET['pkg']));
141
		update_output_window($static_output);
142
		break;
143 e1531d00 Colin Smith
	case "reinstallxml":
144 4c951cc9 Matthew Grooms
		delete_package_xml(htmlspecialchars($_GET['pkg']));
145
		install_package(htmlspecialchars($_GET['pkg']));
146
		$static_output .= "\n\nPackage reinstalled.";
147
		start_service(htmlspecialchars($_GET['pkg']));
148
		update_output_window($static_output);
149
		break;
150 16654db5 Scott Ullrich
	case "installedinfo":
151
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
152
		if(file_exists("/tmp/{$_GET['pkg']}.info")) {
153
			$filename = escapeshellcmd("/tmp/" . $_GET['pkg']  . ".info");
154
			$status = file_get_contents($filename);
155
			update_status($_GET['pkg']  . " installation completed.");
156
			update_output_window($status);
157
		} else {
158
			update_output_window("Could not find {$_GET['pkg']}.");
159
		}
160
		break;
161 e1531d00 Colin Smith
	case "reinstallall":
162 4c951cc9 Matthew Grooms
		if ($config['installedpackages']['package'])
163 7ffeba59 Scott Ullrich
			exec("rm -rf /var/db/pkg/*");
164 4c951cc9 Matthew Grooms
		if (is_array($config['installedpackages']['package']))
165
			foreach($config['installedpackages']['package'] as $package)
166
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
167
		$pkg_id = 0;
168
		foreach($todo as $pkgtodo) {
169
			$static_output = "";
170
			if($pkgtodo['name']) {
171
				update_output_window($static_output);
172
				delete_package($pkgtodo['name'] . '-' . $pkgtodo['version'], $pkg_id);
173
				delete_package_xml($pkgtodo['name']);
174
				install_package($pkgtodo['name']);
175
				$pkg_id++;
176
			}
177
		}
178
		update_status("All packages reinstalled.");
179
		$static_output .= "\n\nAll packages reinstalled.";
180
		start_service(htmlspecialchars($_GET['pkg']));
181
		update_output_window($static_output);
182
		break;
183 e1531d00 Colin Smith
	default:
184 4c951cc9 Matthew Grooms
		$status = install_package(htmlspecialchars($_GET['id']));
185
		if($status == -1) {
186
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " FAILED!");
187
			$static_output .= "\n\nInstallation halted.";
188 16654db5 Scott Ullrich
			update_output_window($static_output);
189 4c951cc9 Matthew Grooms
		} else {
190 16654db5 Scott Ullrich
			$filename = escapeshellcmd("/tmp/" . $_GET['pkg']  . ".info");
191
			$fd = fopen($filename, "w");
192
			$status_a = "Installation of " . htmlspecialchars($_GET['id']) . " completed.";
193
			update_status($status_a);
194 cfde64b8 Scott Ullrich
			$status = get_after_install_info($_GET['id']);
195
			if($status) 
196
				$static_output .= "\nInstallation completed.\n\n{$_GET['id']} setup instructions:\n\n{$status}";
197
			else
198
				$static_output .= "\nInstallation completed.   Please check to make sure that the package is configured from the respective menu then start the package.";
199 16654db5 Scott Ullrich
			fwrite($fd, $status_a . "\n\n". $static_output);
200
			fclose($fd);
201
			echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$_GET['id']}\";</script>";
202 4c951cc9 Matthew Grooms
		}
203 efd81869 Colin Smith
}
204 91e58a1a Scott Ullrich
205 58f130e4 Colin Smith
// Delete all temporary package tarballs and staging areas.
206
unlink_if_exists("/tmp/apkg_*");
207
rmdir_recursive("/var/tmp/instmp*");
208
209 91e58a1a Scott Ullrich
/* read only fs */
210
conf_mount_ro();
211
212 8ccc8f1a Scott Ullrich
// close log
213 276d1b95 Colin Smith
if($fd_log)
214
	fclose($fd_log);
215 8ccc8f1a Scott Ullrich
216 c85c6f1e Scott Ullrich
?>