Project

General

Profile

Download (7.85 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_once("guiconfig.inc");
43
require_once("pkg-utils.inc");
44

    
45
$static_output = "";
46
$static_status = "";
47
$sendto = "output";
48

    
49
$todo = array();
50

    
51
$pgtitle = array("System","Package Manager","Install Package");
52
include("head.inc");
53

    
54
?>
55

    
56
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
57
<?php include("fbegin.inc"); ?>
58
	<form action="pkg_mgr_install.php" method="post">
59
		<div id="mainareapkg">
60
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
61
				<tr>
62
					<td>
63
						<?php
64
							$version = file_get_contents("/etc/version");
65
							$tab_array = array();
66
							$tab_array[] = array("{$version} packages", false, "pkg_mgr.php");
67
//							$tab_array[] = array("Packages for any platform", false, "pkg_mgr.php?ver=none");
68
//							$tab_array[] = array("Packages for a different platform", $requested_version == "other" ? true : false, "pkg_mgr.php?ver=other");
69
							$tab_array[] = array("Installed packages", false, "pkg_mgr_installed.php");
70
							$tab_array[] = array("Package Installer", true, "");
71
							display_top_tabs($tab_array);
72
						?>
73
					</td>
74
				</tr>
75
				<tr>
76
					<td class="tabcont">
77
						<center>
78
							<table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
79
								<tr>
80
									<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_left.gif" height='15' width='5'>
81
									</td>
82
									<td>
83
										<table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
84
											<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_gray.gif" valign="top" align="left">
85
												<img src='./themes/<?= $g['theme']; ?>/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
86
											</td>
87
										</table>
88
									</td>
89
									<td background="./themes/<?= $g['theme']; ?>/images/misc/bar_right.gif" height='15' width='5'>
90
									</td>
91
								</tr>
92
							</table>
93
							<br>
94
							<!-- status box -->
95
							<textarea cols="60" rows="1" name="status" id="status" wrap="hard">Beginning package installation.</textarea>
96
							<!-- command output box -->
97
							<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></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
		filter_configure();
131
		break;
132
	case "showlog":
133
		$id = htmlspecialchars($_GET['pkg']);
134
		if(strpos($id, "."))
135
			exit;
136
		update_output_window(file_get_contents("/tmp/pkg_mgr_{$id}.log"));
137
		break;
138
	case "reinstallpkg":
139
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
140
		delete_package_xml(htmlspecialchars($_GET['pkg']));
141
		install_package(htmlspecialchars($_GET['pkg']));
142
		update_status("Package reinstalled.");
143
		$static_output .= "\n\nPackage reinstalled.";
144
		start_service(htmlspecialchars($_GET['pkg']));
145
		update_output_window($static_output);
146
		filter_configure();
147
		break;
148
	case "reinstallxml":
149
		delete_package_xml(htmlspecialchars($_GET['pkg']));
150
		install_package(htmlspecialchars($_GET['pkg']));
151
		$static_output .= "\n\nPackage reinstalled.";
152
		start_service(htmlspecialchars($_GET['pkg']));
153
		update_output_window($static_output);
154
		filter_configure();
155
		break;
156
	case "installedinfo":
157
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
158
		if(file_exists("/tmp/{$_GET['pkg']}.info")) {
159
			$filename = escapeshellcmd("/tmp/" . $_GET['pkg']  . ".info");
160
			$status = file_get_contents($filename);
161
			update_status($_GET['pkg']  . " installation completed.");
162
			update_output_window($status);
163
		} else {
164
			update_output_window("Could not find {$_GET['pkg']}.");
165
		}
166
		break;
167
	case "reinstallall":
168
		if ($config['installedpackages']['package'])
169
			exec("rm -rf /var/db/pkg/*");
170
		if (is_array($config['installedpackages']['package']))
171
			foreach($config['installedpackages']['package'] as $package)
172
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
173
		$pkg_id = 0;
174
		foreach($todo as $pkgtodo) {
175
			$static_output = "";
176
			if($pkgtodo['name']) {
177
				update_output_window($static_output);
178
				delete_package($pkgtodo['name'] . '-' . $pkgtodo['version'], $pkg_id);
179
				delete_package_xml($pkgtodo['name']);
180
				install_package($pkgtodo['name']);
181
				$pkg_id++;
182
			}
183
		}
184
		update_status("All packages reinstalled.");
185
		$static_output .= "\n\nAll packages reinstalled.";
186
		start_service(htmlspecialchars($_GET['pkg']));
187
		update_output_window($static_output);
188
		filter_configure();
189
		break;
190
	default:
191
		$status = install_package(htmlspecialchars($_GET['id']));
192
		if($status == -1) {
193
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " FAILED!");
194
			$static_output .= "\n\nInstallation halted.";
195
			update_output_window($static_output);
196
		} else {
197
			$filename = escapeshellcmd("/tmp/" . $_GET['id']  . ".info");
198
			$fd = fopen($filename, "w");
199
			$status_a = "Installation of " . htmlspecialchars($_GET['id']) . " completed.";
200
			update_status($status_a);
201
			$status = get_after_install_info($_GET['id']);
202
			if($status) 
203
				$static_output .= "\nInstallation completed.\n\n{$_GET['id']} setup instructions:\n\n{$status}";
204
			else
205
				$static_output .= "\nInstallation completed.   Please check to make sure that the package is configured from the respective menu then start the package.";
206
			fwrite($fd, $status_a . "\n\n". $static_output);
207
			fclose($fd);
208
			echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$_GET['id']}\";</script>";
209
		}
210
		filter_configure();
211
		break;
212
}
213

    
214
// Delete all temporary package tarballs and staging areas.
215
unlink_if_exists("/tmp/apkg_*");
216
rmdir_recursive("/var/tmp/instmp*");
217

    
218
/* read only fs */
219
conf_mount_ro();
220

    
221
// close log
222
if($fd_log)
223
	fclose($fd_log);
224

    
225
?>
(116-116/218)