1 |
ee11cc6e
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
|
|
pkg_mgr_install.php
|
5 |
1548745b
|
Scott Ullrich
|
part of pfSense (http://www.pfSense.com)
|
6 |
ee11cc6e
|
Scott Ullrich
|
Copyright (C) 2004 Scott Ullrich
|
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 |
|
|
require("guiconfig.inc");
|
32 |
|
|
require("xmlparse_pkg.inc");
|
33 |
|
|
|
34 |
8733dcb1
|
Scott Ullrich
|
/* /usr/local/pkg/ is where xml package files are stored. */
|
35 |
425cbd0a
|
Scott Ullrich
|
if(!file_exists("/usr/local/pkg/")) mwexec("mkdir -p /usr/local/pkg/");
|
36 |
8733dcb1
|
Scott Ullrich
|
/* /usr/local/pkg/pf is where custom php hook packages live to alter the rules when needed */
|
37 |
|
|
if(!file_exists("/usr/local/pkg/pf")) mwexec("mkdir -p /usr/local/pkg/pf");
|
38 |
|
|
/* /usr/local/www/ext is where package links live for the left hand pane */
|
39 |
8aca7e9b
|
Scott Ullrich
|
if(!file_exists("/usr/local/www/ext/")) mwexec("mkdir -p /usr/local/www/ext");
|
40 |
425cbd0a
|
Scott Ullrich
|
|
41 |
b4ff3ccd
|
Scott Ullrich
|
$pb_percent = 1;
|
42 |
|
|
|
43 |
ee11cc6e
|
Scott Ullrich
|
$a_out = &$pkg_config['packages'];
|
44 |
|
|
|
45 |
8ccc8f1a
|
Scott Ullrich
|
$packages_to_install = Array();
|
46 |
|
|
|
47 |
ee11cc6e
|
Scott Ullrich
|
?>
|
48 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
49 |
|
|
<html>
|
50 |
|
|
<head>
|
51 |
|
|
<title><?=gentitle("System: Package Manager: Install Package");?></title>
|
52 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
53 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
54 |
|
|
</head>
|
55 |
|
|
|
56 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
57 |
859329c8
|
Scott Ullrich
|
<?php
|
58 |
|
|
include("fbegin.inc");
|
59 |
|
|
?>
|
60 |
ee11cc6e
|
Scott Ullrich
|
<p class="pgtitle">System: Package Manager: Install Package</p>
|
61 |
dd62c2d4
|
Scott Ullrich
|
<form action="pkg_mgr_install.php" method="post">
|
62 |
6cf08e20
|
Scott Ullrich
|
|
63 |
ee11cc6e
|
Scott Ullrich
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
64 |
|
|
<?php
|
65 |
6cf08e20
|
Scott Ullrich
|
|
66 |
|
|
if($_GET['showlog'] <> "") {
|
67 |
|
|
echo "<table>";
|
68 |
|
|
echo "<tr><td>";
|
69 |
|
|
echo "<pre>";
|
70 |
|
|
// reopen and read log in
|
71 |
0035d7a6
|
Bill Marquette
|
$fd = fopen("{$g['tmp_path']}/pkg_mgr.log", "r");
|
72 |
6cf08e20
|
Scott Ullrich
|
$tmp = "";
|
73 |
|
|
while(!feof($fd)) {
|
74 |
|
|
$tmp .= fread($fd,49);
|
75 |
|
|
}
|
76 |
|
|
fclose($fd);
|
77 |
|
|
echo $tmp;
|
78 |
|
|
echo "</pre>";
|
79 |
|
|
echo "</td></tr>";
|
80 |
|
|
echo "</table>";
|
81 |
|
|
exit;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
/*
|
85 |
|
|
* open logging facility
|
86 |
|
|
*/
|
87 |
c8c2bf0f
|
Bill Marquette
|
$fd_log = fopen("{$g['tmp_path']}/pkg_mgr.log", "w");
|
88 |
0035d7a6
|
Bill Marquette
|
if(!$fd_log) log_error("Warning, could not open {$g['tmp_path']}/pkg_mgr.log for writing");
|
89 |
6cf08e20
|
Scott Ullrich
|
fwrite($fd_log, "Begin of Package Manager installation session.\n");
|
90 |
|
|
|
91 |
0025d774
|
Scott Ullrich
|
fetch_latest_pkg_config();
|
92 |
ee11cc6e
|
Scott Ullrich
|
|
93 |
19fd2947
|
Scott Ullrich
|
$pkg_config = parse_xml_config_pkg("{$g['tmp_path']}/pkg_config.xml", "pfsensepkgs");
|
94 |
ee11cc6e
|
Scott Ullrich
|
|
95 |
8ccc8f1a
|
Scott Ullrich
|
if(!$pkg_config['packages'])
|
96 |
|
|
print_info_box_np("Could not find any packages in pkg_config.xml");
|
97 |
ee11cc6e
|
Scott Ullrich
|
|
98 |
|
|
?>
|
99 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td>
|
100 |
|
|
<ul id="tabnav">
|
101 |
55e50bd6
|
Scott Ullrich
|
<li class="tabinact"><a href="pkg_mgr.php">Available Packages</a></li>
|
102 |
|
|
<li class="tabact">Installed Packages</a></li>
|
103 |
ee11cc6e
|
Scott Ullrich
|
</ul>
|
104 |
|
|
</td></tr>
|
105 |
|
|
<tr>
|
106 |
|
|
<td class="tabcont">
|
107 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
108 |
|
|
<tr>
|
109 |
|
|
<td>
|
110 |
b4ff3ccd
|
Scott Ullrich
|
<!-- progress bar -->
|
111 |
|
|
<center>
|
112 |
|
|
<table id="progholder" name="progholder" height='20' border='1' bordercolor='black' width='420' bordercolordark='#000000' bordercolorlight='#000000' style='border-collapse: collapse' colspacing='2' cellpadding='2' cellspacing='2'><tr><td><img border='0' src='progress_bar.gif' width='280' height='23' name='progressbar' id='progressbar'></td></tr></table>
|
113 |
|
|
<br>
|
114 |
|
|
<!-- status box -->
|
115 |
|
|
<textarea cols="60" rows="1" name="status" id="status" wrap="hard">One moment please... This will take a while!</textarea>
|
116 |
|
|
<!-- command output box -->
|
117 |
|
|
<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea>
|
118 |
|
|
</center>
|
119 |
ee11cc6e
|
Scott Ullrich
|
</td>
|
120 |
|
|
</tr>
|
121 |
|
|
</table>
|
122 |
|
|
</td>
|
123 |
|
|
</tr>
|
124 |
|
|
</table>
|
125 |
|
|
</form>
|
126 |
|
|
<?php include("fend.inc"); ?>
|
127 |
|
|
</body>
|
128 |
|
|
</html>
|
129 |
|
|
|
130 |
b4ff3ccd
|
Scott Ullrich
|
<?php
|
131 |
|
|
|
132 |
98a8e831
|
Scott Ullrich
|
|
133 |
|
|
|
134 |
8ccc8f1a
|
Scott Ullrich
|
if($_GET['mode'] == "reinstallall") {
|
135 |
|
|
/*
|
136 |
|
|
* Loop through installed packages and if name matches
|
137 |
|
|
* push the package id onto array to reinstall
|
138 |
|
|
*/
|
139 |
|
|
$counter = 0;
|
140 |
|
|
foreach($pkg_config['packages']['package'] as $available_package) {
|
141 |
|
|
foreach($config['installedpackages']['package'] as $package) {
|
142 |
|
|
if($package['name'] == $available_package['name']) {
|
143 |
|
|
array_push($packages_to_install, $counter);
|
144 |
|
|
update_status("Adding package " . $package['name']);
|
145 |
|
|
fwrite($fd_log, "Adding (" . $counter . ") " . $package['name'] . " to package installation array.\n" . $status);
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
|
|
$counter++;
|
149 |
|
|
}
|
150 |
|
|
} else {
|
151 |
|
|
/*
|
152 |
|
|
* Push the desired package id onto the install packages array
|
153 |
|
|
*/
|
154 |
6cf08e20
|
Scott Ullrich
|
fwrite($fd_log, "Single package installation started.\n");
|
155 |
8ccc8f1a
|
Scott Ullrich
|
array_push($packages_to_install, $_GET['id']);
|
156 |
|
|
}
|
157 |
ee11cc6e
|
Scott Ullrich
|
|
158 |
87e94c2d
|
Scott Ullrich
|
/*
|
159 |
8ccc8f1a
|
Scott Ullrich
|
* Loop through packages_to_install, installing needed packages
|
160 |
|
|
*/
|
161 |
|
|
foreach ($packages_to_install as $id) {
|
162 |
ee11cc6e
|
Scott Ullrich
|
|
163 |
8ccc8f1a
|
Scott Ullrich
|
$pkg_config = parse_xml_config_pkg("{$g['tmp_path']}/pkg_config.xml", "pfsensepkgs");
|
164 |
79b196ee
|
Scott Ullrich
|
|
165 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
166 |
|
|
$pb_percent += 10;
|
167 |
ee11cc6e
|
Scott Ullrich
|
|
168 |
8ccc8f1a
|
Scott Ullrich
|
/*
|
169 |
|
|
* install the package
|
170 |
98a8e831
|
Scott Ullrich
|
*/
|
171 |
b4ff3ccd
|
Scott Ullrich
|
|
172 |
8ccc8f1a
|
Scott Ullrich
|
// Ensure directories are in place for pkg_add.
|
173 |
0035d7a6
|
Bill Marquette
|
mwexec("mkdir {$g['www_path']}/ext/Services >/dev/null 2>&1");
|
174 |
|
|
mwexec("mkdir {$g['www_path']}/ext/System >/dev/null 2>&1");
|
175 |
|
|
mwexec("mkdir {$g['www_path']}/ext/Interfaces >/dev/null 2>&1");
|
176 |
|
|
mwexec("mkdir {$g['www_path']}/ext/Firewall >/dev/null 2>&1");
|
177 |
|
|
mwexec("mkdir {$g['www_path']}/ext/VPN >/dev/null 2>&1");
|
178 |
|
|
mwexec("mkdir {$g['www_path']}/ext/Status >/dev/null 2>&1");
|
179 |
|
|
mwexec("mkdir {$g['www_path']}/ext/Diagnostics >/dev/null 2>&1");
|
180 |
8ccc8f1a
|
Scott Ullrich
|
mwexec("mkdir /usr/local/pkg >/dev/null 2>&1");
|
181 |
ee11cc6e
|
Scott Ullrich
|
|
182 |
19fd2947
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
183 |
|
|
$pb_percent += 10;
|
184 |
8ccc8f1a
|
Scott Ullrich
|
|
185 |
|
|
$a_out = &$pkg_config['packages']['package'];
|
186 |
960e4d4f
|
Scott Ullrich
|
|
187 |
|
|
if($pkg_config['packages']['package'][$id]['verifyinstalledpkg'] <> "")
|
188 |
|
|
$package_to_verify = $pkg_config['packages']['package'][$id]['verifyinstalledpkg'];
|
189 |
|
|
else
|
190 |
|
|
$package_to_verify = $pkg_config['packages']['package'][$id]['name'];
|
191 |
|
|
|
192 |
8ccc8f1a
|
Scott Ullrich
|
$pkgent = array();
|
193 |
|
|
$pkgent['name'] = $pkg_config['packages']['package'][$id]['name'];
|
194 |
|
|
$pkgent['descr'] = $pkg_config['packages']['package'][$id]['descr'];
|
195 |
|
|
$pkgent['category'] = $pkg_config['packages']['package'][$id]['category'];
|
196 |
|
|
|
197 |
|
|
$pkgent['version'] = $pkg_config['packages']['package'][$id]['version'];
|
198 |
|
|
|
199 |
|
|
$pkgent['depends_on_package'] = $a_out[$id]['depends_on_package'];
|
200 |
|
|
$pkgent['depends_on_package_base_url'] = $a_out[$id]['depends_on_package_base_url'];
|
201 |
|
|
$pkgent['pfsense_package'] = $a_out[$id]['pfsense_package'];
|
202 |
|
|
$pkgent['pfsense_package_base_url'] = $a_out[$id]['pfsense_package_base_url'];
|
203 |
|
|
$pkgent['configurationfile'] = $a_out[$id]['configurationfile'];
|
204 |
|
|
if($pkg_config['packages']['package'][$id]['logging']) {
|
205 |
|
|
// logging facilities.
|
206 |
|
|
$pkgent['logging']['facility'] = $pkg_config['packages']['package'][$id]['logging']['facility'];
|
207 |
|
|
$pkgent['logging']['logfile_name'] = $pkg_config['packages']['package'][$id]['logging']['logfile_name'];
|
208 |
0035d7a6
|
Bill Marquette
|
mwexec("/usr/sbin/clog -i -s 32768 {$g['varlog_path']}" . $pkgent['logging']['logfile_name']);
|
209 |
77789d1f
|
Bill Marquette
|
chmod($g['varlog_path'] . $pkgent['logging']['logfile_name'], 0600);
|
210 |
6cf08e20
|
Scott Ullrich
|
fwrite($fd_log, "Adding text to file /etc/syslog.conf\n");
|
211 |
8ccc8f1a
|
Scott Ullrich
|
add_text_to_file("/etc/syslog.conf", $pkgent['logging']['facilityname'] . "\t\t\t" . $pkgent['logging']['logfilename']);
|
212 |
|
|
mwexec("/usr/bin/killall -HUP syslogd");
|
213 |
19fd2947
|
Scott Ullrich
|
}
|
214 |
8ccc8f1a
|
Scott Ullrich
|
$a_out = &$config['packages']['package']; // save item to installedpkgs
|
215 |
|
|
fwrite($fd_log, "Begining (" . $id. ") " . $pkgent['name'] . " package installation.\n" . $status);
|
216 |
ee11cc6e
|
Scott Ullrich
|
|
217 |
7b2274cb
|
Scott Ullrich
|
log_error("Begining (" . $id. ") " . $pkgent['name'] . " package installation.");
|
218 |
6a57391a
|
Scott Ullrich
|
|
219 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
220 |
|
|
$pb_percent += 10;
|
221 |
b4ff3ccd
|
Scott Ullrich
|
|
222 |
0035d7a6
|
Bill Marquette
|
fwrite($fd_log, "ls {$g['vardb_path']}/pkg | grep " . $package_to_verify . "\n" . $status);
|
223 |
8ccc8f1a
|
Scott Ullrich
|
if($status <> "") {
|
224 |
|
|
// package is already installed!?
|
225 |
|
|
if(!$_GET['mode'] == "reinstallall")
|
226 |
|
|
print_info_box_np("NOTICE! " . $pkgent['name'] . " is already installed! Installation will be registered.");
|
227 |
|
|
}
|
228 |
ee11cc6e
|
Scott Ullrich
|
|
229 |
8ccc8f1a
|
Scott Ullrich
|
if($pkg_config['packages']['package'][$id]['config_file'] <> "") {
|
230 |
|
|
update_status("Downloading configuration file.");
|
231 |
|
|
fwrite($fd_log, "Downloading configuration file " . $pkg_config['packages']['package'][$id]['config_file'] . " ... \n");
|
232 |
|
|
update_progress_bar($pb_percent);
|
233 |
|
|
$pb_percent += 10;
|
234 |
|
|
mwexec("cd /usr/local/pkg/ && fetch " . $pkg_config['packages']['package'][$id]['config_file']);
|
235 |
|
|
if(!file_exists("/usr/local/pkg/" . $pkgent['name'] . ".xml")) {
|
236 |
98a8e831
|
Scott Ullrich
|
fwrite($fd_log, "ERROR! Could not fetch " . $pkg_config['packages']['package'][$id]['config_file']);
|
237 |
8ccc8f1a
|
Scott Ullrich
|
update_output_window("ERROR! Could not fetch " . $pkg_config['packages']['package'][$id]['config_file'] . "\n");
|
238 |
|
|
exit;
|
239 |
|
|
}
|
240 |
|
|
}
|
241 |
a4c8ccfc
|
Scott Ullrich
|
|
242 |
8ccc8f1a
|
Scott Ullrich
|
update_status("Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . " and its dependencies ... This could take a moment ...");
|
243 |
866d2813
|
Scott Ullrich
|
fwrite($fd_log, "Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . " ... \n");
|
244 |
a4c8ccfc
|
Scott Ullrich
|
|
245 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
246 |
|
|
$pb_percent += 10;
|
247 |
|
|
|
248 |
4b4d5996
|
Scott Ullrich
|
/*
|
249 |
|
|
* Open a /tmp/y file which will basically tell the
|
250 |
|
|
* pkg_delete script to delete users and such if it asks.
|
251 |
|
|
*/
|
252 |
0035d7a6
|
Bill Marquette
|
$fd = fopen("{$g['tmp_path']}/y", "w");
|
253 |
4b4d5996
|
Scott Ullrich
|
fwrite($fd, "y\n");
|
254 |
|
|
fwrite($fd, "y\n");
|
255 |
|
|
fwrite($fd, "y\n");
|
256 |
|
|
fwrite($fd, "y\n");
|
257 |
|
|
fwrite($fd, "y\n");
|
258 |
|
|
fclose($fd);
|
259 |
|
|
|
260 |
8ccc8f1a
|
Scott Ullrich
|
if ($pkgent['pfsense_package_base_url'] <> "") {
|
261 |
0035d7a6
|
Bill Marquette
|
fwrite($fd_log, "Executing: cd {$g['tmp_path']}/ && /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base_url'] . "/" . $pkgent['pfsense_package'] . "\n" . $text);
|
262 |
|
|
$text = exec_command_and_return_text("cd {$g['tmp_path']}/ && cat {$g['tmp_path']}/y | /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base_url'] . "/" . $pkgent['pfsense_package']);
|
263 |
4b4d5996
|
Scott Ullrich
|
update_output_window($text);
|
264 |
8a9e047d
|
Scott Ullrich
|
}
|
265 |
3e4caf25
|
Scott Ullrich
|
|
266 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
267 |
|
|
$pb_percent += 10;
|
268 |
|
|
|
269 |
|
|
if ($pkgent['depends_on_package_base_url'] <> "") {
|
270 |
|
|
update_status("Downloading and installing " . $pkgent['name'] . " and its dependencies ... This could take a moment ...");
|
271 |
0035d7a6
|
Bill Marquette
|
$text = exec_command_and_return_text("cd {$g['tmp_path']}/ && /usr/sbin/pkg_add -r " . $pkgent['depends_on_package_base_url'] . "/" . $pkgent['depends_on_package']);
|
272 |
8ccc8f1a
|
Scott Ullrich
|
update_output_window($text);
|
273 |
0035d7a6
|
Bill Marquette
|
fwrite($fd_log, "cd {$g['tmp_path']}/ && /usr/sbin/pkg_add -r " . $pkgent['depends_on_package_base_url'] . "/" . $pkgent['depends_on_package'] . "\n" . $text);;
|
274 |
8ccc8f1a
|
Scott Ullrich
|
}
|
275 |
|
|
|
276 |
|
|
if ($pkgent['depends_on_package_base_url'] <> "" or $pkgent['pfsense_package_base_url'] <> "") {
|
277 |
0035d7a6
|
Bill Marquette
|
$status = exec_command_and_return_text("ls {$g['vardb_path']}/pkg | grep " . $package_to_verify);
|
278 |
|
|
fwrite($fd_log, "ls {$g['vardb_path']}/pkg | grep " . $package_to_verify . "\n" . $status);
|
279 |
8ccc8f1a
|
Scott Ullrich
|
if($status <> "") {
|
280 |
|
|
update_status("Package installed. Lets finish up.");
|
281 |
|
|
fwrite($fd_log, "Package installed. Lets finish up.\n");
|
282 |
|
|
} else {
|
283 |
|
|
fwrite($fd_log, "Package WAS NOT installed properly.\n");
|
284 |
|
|
fclose($fd_log);
|
285 |
|
|
$filecontents = exec_command_and_return_text("cat " . $file);
|
286 |
|
|
update_progress_bar(100);
|
287 |
|
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
|
288 |
|
|
echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
|
289 |
|
|
update_status("Package WAS NOT installed properly...Something went wrong..\n" . $filecontents);
|
290 |
|
|
update_output_window("Error during package installation.");
|
291 |
|
|
sleep(1);
|
292 |
|
|
die;
|
293 |
|
|
}
|
294 |
|
|
}
|
295 |
b4ff3ccd
|
Scott Ullrich
|
|
296 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
297 |
|
|
$pb_percent += 10;
|
298 |
ee11cc6e
|
Scott Ullrich
|
|
299 |
8ccc8f1a
|
Scott Ullrich
|
$config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
|
300 |
|
|
|
301 |
|
|
update_progress_bar($pb_percent);
|
302 |
|
|
$pb_percent += 10;
|
303 |
b4ff3ccd
|
Scott Ullrich
|
|
304 |
8ccc8f1a
|
Scott Ullrich
|
$config['installedpackages']['package'][] = $pkgent;
|
305 |
ee11cc6e
|
Scott Ullrich
|
|
306 |
8ccc8f1a
|
Scott Ullrich
|
if (isset($id) && $a_out[$id])
|
307 |
|
|
$a_out[$id] = $pkgent;
|
308 |
|
|
else
|
309 |
|
|
$a_out[] = $pkgent;
|
310 |
ee11cc6e
|
Scott Ullrich
|
|
311 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
312 |
|
|
$pb_percent += 10;
|
313 |
b4ff3ccd
|
Scott Ullrich
|
|
314 |
866d2813
|
Scott Ullrich
|
if(!$_GET['mode'] == "reinstallall") {
|
315 |
|
|
update_output_window("Saving updated package information ...");
|
316 |
eb6116e1
|
Scott Ullrich
|
fwrite($fd_log, "Saving updated package information ...\n");
|
317 |
8ccc8f1a
|
Scott Ullrich
|
write_config();
|
318 |
866d2813
|
Scott Ullrich
|
}
|
319 |
ee11cc6e
|
Scott Ullrich
|
|
320 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
321 |
|
|
$pb_percent += 10;
|
322 |
b4ff3ccd
|
Scott Ullrich
|
|
323 |
8ccc8f1a
|
Scott Ullrich
|
$name = $pkgent['name'];
|
324 |
55e50bd6
|
Scott Ullrich
|
|
325 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
326 |
|
|
$pb_percent++;
|
327 |
b4ff3ccd
|
Scott Ullrich
|
|
328 |
8ccc8f1a
|
Scott Ullrich
|
/*
|
329 |
|
|
* parse the config file for this package and install neededtext items.
|
330 |
|
|
*
|
331 |
|
|
*/
|
332 |
|
|
if(file_exists("/usr/local/pkg/" . $pkgent['name'] . ".xml")) {
|
333 |
|
|
$package_conf = parse_xml_config_pkg("/usr/local/pkg/" . $pkgent['name'] . ".xml", "packagegui");
|
334 |
|
|
if($package_conf['modify_system']['item'] <> "") {
|
335 |
|
|
foreach ($package_conf['modify_system']['item'] as $ms) {
|
336 |
|
|
update_progress_bar($pb_percent);
|
337 |
|
|
$pb_percent += 10;
|
338 |
|
|
if($ms['textneeded']) {
|
339 |
|
|
add_text_to_file($ms['modifyfilename'],$ms['textneeded']);
|
340 |
|
|
}
|
341 |
19fd2947
|
Scott Ullrich
|
}
|
342 |
|
|
}
|
343 |
f310febe
|
Scott Ullrich
|
|
344 |
8ccc8f1a
|
Scott Ullrich
|
/*
|
345 |
|
|
* fetch additional files needed for package if defined
|
346 |
|
|
* and uncompress if needed.
|
347 |
|
|
*/
|
348 |
|
|
if ($package_conf['additional_files_needed'] <> "") {
|
349 |
d4022785
|
Scott Ullrich
|
foreach($package_conf['additional_files_needed'] as $afn) {
|
350 |
|
|
update_progress_bar($pb_percent);
|
351 |
|
|
$pb_percent += 10;
|
352 |
0d7c85a6
|
Scott Ullrich
|
$filename = get_filename_from_url($afn['item'][0]);
|
353 |
d4022785
|
Scott Ullrich
|
fwrite($fd_log, "Downloading additional files needed for package " . $filename . " ...\n");
|
354 |
|
|
update_status("Downloading additional files needed for package " . $filename . " ...\n");
|
355 |
|
|
$prefix = "/usr/local/pkg/";
|
356 |
3c338e4d
|
Scott Ullrich
|
$pkg_chmod = "";
|
357 |
d4022785
|
Scott Ullrich
|
if($afn['chmod'] <> "")
|
358 |
|
|
$pkg_chmod = $afn['chmod'];
|
359 |
|
|
if($afn['prefix'] <> "")
|
360 |
|
|
$prefix = $afn['prefix'];
|
361 |
0d7c85a6
|
Scott Ullrich
|
system("cd {$prefix} && /usr/bin/fetch " . $afn['item'][0] . " 2>/dev/null");
|
362 |
d4022785
|
Scott Ullrich
|
if(stristr($filename, ".tgz") <> "") {
|
363 |
|
|
update_status("Extracting tgz archive to -C for " . $filename);
|
364 |
|
|
fwrite($fd_log, "Extracting tgz archive to -C for " . $filename . " ...\n");
|
365 |
a842f124
|
Bill Marquette
|
system("/usr/bin/tar xzvf " . $prefix . $filename . " -C / >/dev/null 2>&1");
|
366 |
d4022785
|
Scott Ullrich
|
}
|
367 |
0d7c85a6
|
Scott Ullrich
|
if($pkg_chmod <> "") {
|
368 |
|
|
fwrite($fd_log, "Changing file mode for {$pkg_chmod} {$prefix}{$filename}\n");
|
369 |
77789d1f
|
Bill Marquette
|
chmod($prefix . $filename, $pkg_chmod);
|
370 |
0d7c85a6
|
Scott Ullrich
|
}
|
371 |
d4022785
|
Scott Ullrich
|
}
|
372 |
8ccc8f1a
|
Scott Ullrich
|
}
|
373 |
|
|
|
374 |
|
|
/*
|
375 |
|
|
* loop through menu installation items
|
376 |
|
|
* installing multiple items if need be.
|
377 |
|
|
*/
|
378 |
|
|
if(is_array($package_conf['menu']))
|
379 |
|
|
foreach ($package_conf['menu'] as $menu) {
|
380 |
d4022785
|
Scott Ullrich
|
// install menu item into the ext folder
|
381 |
|
|
fwrite($fd_log, "Adding menu option to " . $menu['section'] . "/" . $menu['name'] . "\n");
|
382 |
|
|
$fd = fopen("{$g['www_path']}/ext/" . $menu['section'] . "/" . $menu['name'] , "w");
|
383 |
|
|
if($menu['url'] <> "") {
|
384 |
|
|
// override $myurl for script.
|
385 |
|
|
$toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n";
|
386 |
677e0880
|
Scott Ullrich
|
$error_message = "";
|
387 |
|
|
if(php_check_syntax($toeval, $error_message) == false)
|
388 |
|
|
eval($toeval);
|
389 |
d4022785
|
Scott Ullrich
|
// eval url so that above $myurl item can be processed if need be.
|
390 |
|
|
$urltmp = $menu['url'];
|
391 |
|
|
$toeval = "\$url = \"" . $urltmp . "\"; \n";
|
392 |
677e0880
|
Scott Ullrich
|
if(php_check_syntax($toeval, $error_message) == false)
|
393 |
|
|
eval($toeval);
|
394 |
d4022785
|
Scott Ullrich
|
fwrite($fd, $url . "\n");
|
395 |
|
|
} else {
|
396 |
|
|
$xml = "";
|
397 |
|
|
if(stristr($menu['configfile'],".xml") == "") $xml = ".xml";
|
398 |
|
|
fwrite($fd, "/pkg.php?xml=" . $menu['configfile'] . $xml . "\n");
|
399 |
|
|
}
|
400 |
|
|
fclose($fd);
|
401 |
|
|
}
|
402 |
8ccc8f1a
|
Scott Ullrich
|
} else {
|
403 |
|
|
update_output_window("WARNING! /usr/local/pkg/" . $pkgent['name'] . ".xml" . " does not exist!\n");
|
404 |
|
|
fwrite($fd_log, "WARNING! /usr/local/pkg/" . $pkgent['name'] . ".xml" . " does not exist!\n");
|
405 |
|
|
}
|
406 |
|
|
fwrite($fd_log, "End of Package Manager installation session.\n");
|
407 |
55e50bd6
|
Scott Ullrich
|
|
408 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
409 |
|
|
$pb_percent += 10;
|
410 |
b4ff3ccd
|
Scott Ullrich
|
|
411 |
8ccc8f1a
|
Scott Ullrich
|
// return dependency list to output later.
|
412 |
|
|
$command = "TODELETE=`ls /var/db/pkg | grep " . $name . "` && /usr/sbin/pkg_info -r \$TODELETE | grep Dependency: | cut -d\" \" -f2";
|
413 |
|
|
$dependencies = exec_command_and_return_text($command);
|
414 |
866d2813
|
Scott Ullrich
|
if($dependencies == "")
|
415 |
|
|
fwrite($fd_log, "Installed package " . $name);
|
416 |
|
|
else
|
417 |
|
|
fwrite($fd_log, "Installed package " . $name . " and the following dependencies:\n" . $dependencies);
|
418 |
55e50bd6
|
Scott Ullrich
|
|
419 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
420 |
|
|
$pb_percent += 10;
|
421 |
b4ff3ccd
|
Scott Ullrich
|
|
422 |
79b196ee
|
Scott Ullrich
|
if($package_conf['custom_php_install_command']) {
|
423 |
eb6116e1
|
Scott Ullrich
|
update_status("Executing post install commands...\n");
|
424 |
87f9d450
|
Scott Ullrich
|
fwrite($fd_log, "Executing post install commands...\n");
|
425 |
677e0880
|
Scott Ullrich
|
$error_message = "";
|
426 |
87f9d450
|
Scott Ullrich
|
if($package_conf['custom_php_command_before_form'] <> "")
|
427 |
677e0880
|
Scott Ullrich
|
if(php_check_syntax($package_conf['custom_php_command_before_form'], $error_message) == false)
|
428 |
|
|
eval($package_conf['custom_php_command_before_form']);
|
429 |
457161f7
|
Scott Ullrich
|
$pb_percent += 50;
|
430 |
6cf08e20
|
Scott Ullrich
|
update_progress_bar(50);
|
431 |
677e0880
|
Scott Ullrich
|
if(php_check_syntax($package_conf['custom_php_install_command'], $error_message) == false)
|
432 |
|
|
eval($package_conf['custom_php_install_command']);
|
433 |
79b196ee
|
Scott Ullrich
|
}
|
434 |
|
|
|
435 |
|
|
$pb_percent += 10;
|
436 |
6cf08e20
|
Scott Ullrich
|
update_progress_bar($pb_percent);
|
437 |
79b196ee
|
Scott Ullrich
|
|
438 |
8ccc8f1a
|
Scott Ullrich
|
if ($pkgent['depends_on_package_base_url'] <> "" or $pkgent['pfsense_package_base_url'] <> "") {
|
439 |
0035d7a6
|
Bill Marquette
|
$status = exec_command_and_return_text("ls {$g['vardb_path']}/pkg | grep " . $package_to_verify);
|
440 |
|
|
fwrite($fd_log, "ls {$g['vardb_path']}/pkg | grep " . $package_to_verify . "\n" . $status);
|
441 |
8ccc8f1a
|
Scott Ullrich
|
if($status <> "") {
|
442 |
|
|
update_status("Package installation completed.");
|
443 |
|
|
fwrite($fd_log, "Package installation completed.\n");
|
444 |
7b2274cb
|
Scott Ullrich
|
log_error("Package " . $pkgent['name'] . " installation completed okay.");
|
445 |
960e4d4f
|
Scott Ullrich
|
update_progress_bar(100);
|
446 |
8ccc8f1a
|
Scott Ullrich
|
} else {
|
447 |
|
|
update_status("Package WAS NOT installed properly.");
|
448 |
960e4d4f
|
Scott Ullrich
|
update_output_window("Package WAS NOT installed properly.");
|
449 |
8ccc8f1a
|
Scott Ullrich
|
fwrite($fd_log, "Package WAS NOT installed properly.\n");
|
450 |
7b2274cb
|
Scott Ullrich
|
log_error("Package " . $pkgent['name'] . " did not install correctly.");
|
451 |
960e4d4f
|
Scott Ullrich
|
update_progress_bar(100);
|
452 |
8ccc8f1a
|
Scott Ullrich
|
}
|
453 |
8a9e047d
|
Scott Ullrich
|
} else {
|
454 |
8ccc8f1a
|
Scott Ullrich
|
update_status("Package installation completed.");
|
455 |
|
|
fwrite($fd_log, "Package installation completed.\n");
|
456 |
8a9e047d
|
Scott Ullrich
|
}
|
457 |
1a05a4ee
|
Scott Ullrich
|
|
458 |
8ccc8f1a
|
Scott Ullrich
|
update_progress_bar(100);
|
459 |
|
|
|
460 |
6483da5d
|
Scott Ullrich
|
}
|
461 |
|
|
|
462 |
8ccc8f1a
|
Scott Ullrich
|
// close log
|
463 |
|
|
fclose($fd_log);
|
464 |
|
|
|
465 |
6cf08e20
|
Scott Ullrich
|
echo "<p><center>Installation completed. Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>";
|
466 |
b4ff3ccd
|
Scott Ullrich
|
|
467 |
|
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
|
468 |
|
|
echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
|
469 |
|
|
|
470 |
19fd2947
|
Scott Ullrich
|
|
471 |
d2a1bba6
|
Scott Ullrich
|
|
472 |
0035d7a6
|
Bill Marquette
|
?>
|