Project

General

Profile

Download (7.02 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
/* mount rw fs */
118
conf_mount_rw();
119

    
120
switch($_GET['mode']) {
121
	case "delete":
122
		$id = get_pkg_id($_GET['pkg']);
123
		$todel = substr(reverse_strrchr($config['installedpackages']['package'][$id]['depends_on_package'], "."), 0, -1);
124
		delete_package($todel, htmlspecialchars($_GET['pkg']));
125
		delete_package_xml(htmlspecialchars($_GET['pkg']));
126
		update_status("Package deleted.");
127
		$static_output .= "\nPackage deleted.";
128
		update_output_window($static_output);
129
		break;
130
	case "showlog":
131
		$id = htmlspecialchars($_GET['pkg']);
132
		if(strpos($id, "."))
133
			exit;
134
		update_output_window(file_get_contents("/tmp/pkg_mgr_{$id}.log"));
135
		break;
136
	case "reinstallpkg":
137
		$id = get_pkg_id(htmlspecialchars($_GET['pkg']));
138
		$todel = substr(reverse_strrchr($config['installedpackages']['package'][$id]['depends_on_package'], "."), 0, -1);
139
		delete_package($todel, 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
		break;
147
	case "reinstallxml":
148
		delete_package_xml(htmlspecialchars($_GET['pkg']));
149
		install_package(htmlspecialchars($_GET['pkg']));
150
		$static_output .= "\n\nPackage reinstalled.";
151
		start_service(htmlspecialchars($_GET['pkg']));
152
		update_output_window($static_output);
153
		break;
154
	case "reinstallall":
155
		if ($config['installedpackages']['package'])
156
			exec("rm -rf /var/db/pkg/*");
157
		if (is_array($config['installedpackages']['package']))
158
			foreach($config['installedpackages']['package'] as $package)
159
				$todo[] = array('name' => $package['name'], 'version' => $package['version']);
160
		$pkg_id = 0;
161
		foreach($todo as $pkgtodo) {
162
			$static_output = "";
163
			if($pkgtodo['name']) {
164
				update_output_window($static_output);
165
				delete_package($pkgtodo['name'] . '-' . $pkgtodo['version'], $pkg_id);
166
				delete_package_xml($pkgtodo['name']);
167
				install_package($pkgtodo['name']);
168
				$pkg_id++;
169
			}
170
		}
171
		update_status("All packages reinstalled.");
172
		$static_output .= "\n\nAll packages reinstalled.";
173
		start_service(htmlspecialchars($_GET['pkg']));
174
		update_output_window($static_output);
175
		break;
176
	default:
177
		$status = install_package(htmlspecialchars($_GET['id']));
178
		if($status == -1) {
179
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " FAILED!");
180
			$static_output .= "\n\nInstallation halted.";
181
		} else {
182
			update_status("Installation of " . htmlspecialchars($_GET['id']) . " completed.");
183
			$static_output .= "\n\nInstallation completed.   Please check to make sure that the package is configured from the respective menu then start the package.";
184
		}
185
		update_output_window($static_output);
186
}
187

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

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

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

    
199
?>
(110-110/210)