Project

General

Profile

Download (7.7 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
##|+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
require_once("guiconfig.inc");
40
require_once("pkg-utils.inc");
41

    
42
$static_output = "";
43
$static_status = "";
44
$sendto = "output";
45

    
46
$todo = array();
47

    
48
$pgtitle = array("System","Package Manager","Install Package");
49
include("head.inc");
50

    
51
?>
52

    
53
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
54
<?php include("fbegin.inc"); ?>
55
	<form action="pkg_mgr_install.php" method="post">
56
		<div id="mainareapkg">
57
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
58
				<tr>
59
					<td>
60
						<?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
					</td>
71
				</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
							<textarea cols="60" rows="1" name="status" id="status" wrap="hard">
93
								Beginning package installation.
94
							</textarea>
95
							<!-- command output box -->
96
							<textarea cols="60" rows="25" name="output" id="output" wrap="hard">
97
							</textarea>
98
						</center>
99
					</td>
100
				</tr>
101
			</table>
102
		</div>
103
	</form>
104
<?php include("fend.inc"); ?>
105
<script type="text/javascript">
106
NiftyCheck();
107
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
108
</script>
109
</body>
110
</html>
111

    
112

    
113
<?php
114

    
115
ob_flush();
116

    
117
// Write out configuration to creatae a backup prior to pkg install
118
write_config("Creating restore point before package installation.");
119

    
120
/* mount rw fs */
121
conf_mount_rw();
122

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

    
208
// Delete all temporary package tarballs and staging areas.
209
unlink_if_exists("/tmp/apkg_*");
210
rmdir_recursive("/var/tmp/instmp*");
211

    
212
/* read only fs */
213
conf_mount_ro();
214

    
215
// close log
216
if($fd_log)
217
	fclose($fd_log);
218

    
219
?>
(113-113/217)