Project

General

Profile

Download (7.67 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("{$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">Beginning package installation.</textarea>
93
							<!-- command output box -->
94
							<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea>
95
						</center>
96
					</td>
97
				</tr>
98
			</table>
99
		</div>
100
	</form>
101
<?php include("fend.inc"); ?>
102
<script type="text/javascript">
103
NiftyCheck();
104
Rounded("div#mainareapkg","bl br","#FFF","#eeeeee","smooth");
105
</script>
106
</body>
107
</html>
108

    
109

    
110
<?php
111

    
112
ob_flush();
113

    
114
// Write out configuration to creatae a backup prior to pkg install
115
write_config("Creating restore point before package installation.");
116

    
117
/* mount rw fs */
118
conf_mount_rw();
119

    
120
switch($_GET['mode']) {
121
	case "delete":
122
		$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
	case "showlog":
129
		$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
	case "reinstallpkg":
135
		$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
	case "reinstallxml":
144
		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
	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
	case "reinstallall":
162
		if ($config['installedpackages']['package'])
163
			exec("rm -rf /var/db/pkg/*");
164
		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
	default:
184
		$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
			update_output_window($static_output);
189
		} else {
190
			$filename = escapeshellcmd("/tmp/" . $_GET['id']  . ".info");
191
			$fd = fopen($filename, "w");
192
			$status_a = "Installation of " . htmlspecialchars($_GET['id']) . " completed.";
193
			update_status($status_a);
194
			$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
			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
		}
203
}
204

    
205
// Delete all temporary package tarballs and staging areas.
206
unlink_if_exists("/tmp/apkg_*");
207
rmdir_recursive("/var/tmp/instmp*");
208

    
209
/* read only fs */
210
conf_mount_ro();
211

    
212
// close log
213
if($fd_log)
214
	fclose($fd_log);
215

    
216
?>
(115-115/217)