Project

General

Profile

Download (6.82 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 "reinstallall":
154
		if ($config['installedpackages']['package'])
155
			exec("rm -rf /var/db/pkg/*");
156
		if (is_array($config['installedpackages']['package']))
157
			foreach($config['installedpackages']['package'] as $package)
158
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
159
		$pkg_id = 0;
160
		foreach($todo as $pkgtodo) {
161
			$static_output = "";
162
			if($pkgtodo['name']) {
163
				update_output_window($static_output);
164
				delete_package($pkgtodo['name'] . '-' . $pkgtodo['version'], $pkg_id);
165
				delete_package_xml($pkgtodo['name']);
166
				install_package($pkgtodo['name']);
167
				$pkg_id++;
168
			}
169
		}
170
		update_status("All packages reinstalled.");
171
		$static_output .= "\n\nAll packages reinstalled.";
172
		start_service(htmlspecialchars($_GET['pkg']));
173
		update_output_window($static_output);
174
		break;
175
	default:
176
		$status = install_package(htmlspecialchars($_GET['id']));
177
		if($status == -1) {
178
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " FAILED!");
179
			$static_output .= "\n\nInstallation halted.";
180
		} else {
181
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " completed.");
182
			$static_output .= "\n\nInstallation completed.   Please check to make sure that the package is configured from the respective menu then start the package.";
183
		}
184
		update_output_window($static_output);
185
}
186

    
187
// Delete all temporary package tarballs and staging areas.
188
unlink_if_exists("/tmp/apkg_*");
189
rmdir_recursive("/var/tmp/instmp*");
190

    
191
/* read only fs */
192
conf_mount_ro();
193

    
194
// close log
195
if($fd_log)
196
	fclose($fd_log);
197

    
198
?>
(113-113/214)