Project

General

Profile

Download (44.4 KB) Statistics
| Branch: | Tag: | Revision:
1 7597c8e8 Colin Smith
<?php
2 8c6516d1 Colin Smith
/****h* pfSense/pkg-utils
3
 * NAME
4
 *   pkg-utils.inc - Package subsystem
5
 * DESCRIPTION
6 33b7cc0d Colin Smith
 *   This file contains various functions used by the pfSense package system.
7 8c6516d1 Colin Smith
 * HISTORY
8
 *   $Id$
9
 ******
10
 *
11 84d50fe7 Phil Davis
 * Copyright (C) 2010 Ermal Lu�i
12 0e16b9ca Scott Ullrich
 * Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
13 8c6516d1 Colin Smith
 * All rights reserved.
14
 * Redistribution and use in source and binary forms, with or without
15
 * modification, are permitted provided that the following conditions are met:
16
 *
17
 * 1. Redistributions of source code must retain the above copyright notice,
18
 * this list of conditions and the following disclaimer.
19
 *
20
 * 2. Redistributions in binary form must reproduce the above copyright
21
 * notice, this list of conditions and the following disclaimer in the
22
 * documentation and/or other materials provided with the distribution.
23
 *
24
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
 * RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
 * POSSIBILITY OF SUCH DAMAGE.
34
 *
35
 */
36 523855b0 Scott Ullrich
37
/*
38 b098343a Ermal
	pfSense_BUILDER_BINARIES:	/usr/bin/cd	/usr/bin/tar	/usr/sbin/fifolog_create	/bin/chmod
39
	pfSense_BUILDER_BINARIES:	/usr/sbin/pkg_add	/usr/sbin/pkg_info	/usr/sbin/pkg_delete	/bin/rm
40 523855b0 Scott Ullrich
	pfSense_MODULE:	pkg
41
*/
42
43 01a6e665 Ermal
require_once("globals.inc");
44 33b7cc0d Colin Smith
require_once("xmlrpc.inc");
45 7eea4407 Ermal
require_once("service-utils.inc");
46 093bcebc Scott Ullrich
if(file_exists("/cf/conf/use_xmlreader"))
47
	require_once("xmlreader.inc");
48
else
49
	require_once("xmlparse.inc");
50 3c41c4ab Colin Smith
require_once("service-utils.inc");
51 7597c8e8 Colin Smith
require_once("pfsense-utils.inc");
52 33b7cc0d Colin Smith
53 f041d58b Scott Ullrich
if(!function_exists("update_status")) {
54
	function update_status($status) {
55
		echo $status . "\n";
56 b47833cc Scott Ullrich
	}
57
}
58 762cb660 Scott Ullrich
if(!function_exists("update_output_window")) {
59
	function update_output_window($status) {
60
		echo $status . "\n";
61
	}
62
}
63 b47833cc Scott Ullrich
64 eab543ed Ermal
if (!function_exists("pkg_debug")) {
65
	/* set up logging if needed */
66
	function pkg_debug($msg) {
67
		global $g, $debug, $fd_log;
68
69
		if (!$debug)
70
			return;
71
72
		if (!$fd_log) {
73
			if (!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$package}.log", "w"))
74
				update_output_window("Warning, could not open log for writing.");
75
		}
76
		@fwrite($fd_log, $msg);
77
	}
78
}
79
80 1b28121f Ermal
$vardb = "/var/db/pkg";
81
safe_mkdir($vardb);
82 eab543ed Ermal
$g['platform'] = trim(file_get_contents("/etc/platform"));
83 7955cde8 Scott Ullrich
84 43ad432c Ermal Lu?i
conf_mount_rw();
85
if(!is_dir("/usr/local/pkg") or !is_dir("/usr/local/pkg/pf")) {
86 d3c02149 Scott Ullrich
	safe_mkdir("/usr/local/pkg");
87 7955cde8 Scott Ullrich
	safe_mkdir("/usr/local/pkg/pf");	
88 e7405fbf Scott Ullrich
}
89 3339fac0 Ermal Lu?i
conf_mount_ro();
90 33b7cc0d Colin Smith
91 31e7e1bc Scott Ullrich
/****f* pkg-utils/remove_package
92
 * NAME
93
 *   remove_package - Removes package from FreeBSD if it exists
94
 * INPUTS
95
 *   $packagestring	- name/string to check for
96
 * RESULT
97
 *   none
98
 * NOTES
99
 *   
100
 ******/
101
function remove_freebsd_package($packagestring) {
102 8059acb5 Phil Davis
	// The packagestring passed in must be the full PBI package name, 
103
	// as displayed by the pbi_info utility. e.g. "package-1.2.3_4-i386" 
104
	// It must NOT have ".pbi" on the end.
105 53107064 Vinicius Coque
	exec("/usr/local/sbin/pbi_info {$packagestring} | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir);
106
	$pbidir = $pbidir[0];
107 8059acb5 Phil Davis
	if ($pbidir == "") {
108
		log_error("PBI dir for {$packagestring} was not found - cannot cleanup PBI files");
109
	}
110
	else {
111
		$linkdirs = array('bin','sbin');
112
		foreach($linkdirs as $dir) {
113
			if(is_dir("{$pbidir}/{$dir}")) {
114
				$files = scandir("{$pbidir}/{$dir}");
115
				foreach($files as $f) {
116
					if($f != '.' && $f != '..') {
117
						unlink("/usr/local/{$dir}/{$f}");
118
					}
119 53107064 Vinicius Coque
				}
120
			}
121
		}
122
123 8059acb5 Phil Davis
		exec("/usr/local/sbin/pbi_delete {$packagestring} 2>>/tmp/pbi_delete_errors.txt");
124
	}
125 31e7e1bc Scott Ullrich
}
126
127 33b7cc0d Colin Smith
/****f* pkg-utils/is_package_installed
128
 * NAME
129
 *   is_package_installed - Check whether a package is installed.
130
 * INPUTS
131
 *   $packagename	- name of the package to check
132
 * RESULT
133
 *   boolean	- true if the package is installed, false otherwise
134
 * NOTES
135
 *   This function is deprecated - get_pkg_id() can already check for installation.
136
 ******/
137 8c6516d1 Colin Smith
function is_package_installed($packagename) {
138 33b7cc0d Colin Smith
	$pkg = get_pkg_id($packagename);
139 b2a66231 Ermal
	if($pkg == -1)
140
		return false;
141 33b7cc0d Colin Smith
	return true;
142 8c6516d1 Colin Smith
}
143 43db85f8 Scott Ullrich
144 33b7cc0d Colin Smith
/****f* pkg-utils/get_pkg_id
145
 * NAME
146
 *   get_pkg_id - Find a package's numeric ID.
147
 * INPUTS
148
 *   $pkg_name	- name of the package to check
149
 * RESULT
150
 *   integer    - -1 if package is not found, >-1 otherwise
151
 ******/
152 8c6516d1 Colin Smith
function get_pkg_id($pkg_name) {
153 e65a287f Scott Ullrich
	global $config;
154
155 2addd5b2 Ermal
	if (is_array($config['installedpackages']['package'])) {
156
		foreach($config['installedpackages']['package'] as $idx => $pkg) {
157 b2a66231 Ermal
			if($pkg['name'] == $pkg_name)
158 2addd5b2 Ermal
				return $idx;
159 e65a287f Scott Ullrich
		}
160
	}
161
	return -1;
162 8c6516d1 Colin Smith
}
163
164 33b7cc0d Colin Smith
/****f* pkg-utils/get_pkg_info
165
 * NAME
166 5b542ae5 Bill Marquette
 *   get_pkg_info - Retrieve package information from pfsense.com.
167 33b7cc0d Colin Smith
 * INPUTS
168 5b542ae5 Bill Marquette
 *   $pkgs - 'all' to retrieve all packages, an array containing package names otherwise
169
 *   $info - 'all' to retrieve all information, an array containing keys otherwise
170 33b7cc0d Colin Smith
 * RESULT
171
 *   $raw_versions - Array containing retrieved information, indexed by package name.
172
 ******/
173
function get_pkg_info($pkgs = 'all', $info = 'all') {
174 7597c8e8 Colin Smith
	global $g;
175 b2a66231 Ermal
176 2addd5b2 Ermal
	$freebsd_version = php_uname("r");
177
	$freebsd_machine = php_uname("m");
178 340c0677 Scott Ullrich
	$params = array(
179
		"pkg" => $pkgs, 
180
		"info" => $info, 
181 d465a277 Ermal
		"freebsd_version" => $freebsd_version[0],
182 e4c3d767 sullrich
		"freebsd_machine" => $freebsd_machine
183
	);
184 e65a287f Scott Ullrich
	$resp = call_pfsense_method('pfsense.get_pkgs', $params, 10);
185
	return $resp ? $resp : array();
186
}
187
188
function get_pkg_sizes($pkgs = 'all') {
189 2addd5b2 Ermal
	global $config, $g;
190 b2a66231 Ermal
191 2addd5b2 Ermal
	$freebsd_version = php_uname("r");
192
	$freebsd_machine = php_uname("m");
193
	$params = array(
194
		"pkg" => $pkgs, 
195
		"freebsd_version" => $freebsd_version,
196
		"freebsd_machine" => $freebsd_machine
197
	);
198 e65a287f Scott Ullrich
	$msg = new XML_RPC_Message('pfsense.get_pkg_sizes', array(php_value_to_xmlrpc($params)));
199 ffba4976 jim-p
	$xmlrpc_base_url = isset($config['system']['altpkgrepo']['enable']) ? $config['system']['altpkgrepo']['xmlrpcbaseurl'] : $g['xmlrpcbaseurl'];
200
	$cli = new XML_RPC_Client($g['xmlrpcpath'], $xmlrpc_base_url);
201 43db85f8 Scott Ullrich
	$resp = $cli->send($msg, 10);
202 2addd5b2 Ermal
	if(!is_object($resp))
203
		log_error("Could not get response from XMLRPC server!");
204
 	else if (!$resp->faultCode()) {
205 e65a287f Scott Ullrich
		$raw_versions = $resp->value();
206 34da63c3 Colin Smith
		return xmlrpc_value_to_php($raw_versions);
207
	}
208 b2a66231 Ermal
209
	return array();
210 8c6516d1 Colin Smith
}
211
212
/*
213
 * resync_all_package_configs() Force packages to setup their configuration and rc.d files.
214
 * This function may also print output to the terminal indicating progress.
215
 */
216
function resync_all_package_configs($show_message = false) {
217 b1224cdc jim-p
	global $config, $pkg_interface, $g;
218 b2a66231 Ermal
219 6acdf659 Carlos Eduardo Ramos
	log_error(gettext("Resyncing configuration for all packages."));
220 06e57df8 Scott Ullrich
221 2addd5b2 Ermal
	if (!is_array($config['installedpackages']['package']))
222 3a9eb3c9 Ermal
		return;
223 06e57df8 Scott Ullrich
224 3a9eb3c9 Ermal
	if($show_message == true)
225
		echo "Syncing packages:";
226 b2a66231 Ermal
227 78b94214 Ermal
	conf_mount_rw();
228 06e57df8 Scott Ullrich
229 2addd5b2 Ermal
	foreach($config['installedpackages']['package'] as $idx => $package) {
230
		if (empty($package['name']))
231
			continue;
232
		if($show_message == true)
233
			echo " " . $package['name'];
234
		get_pkg_depends($package['name'], "all");
235 b1224cdc jim-p
		if($g['booting'] != true)
236 06e57df8 Scott Ullrich
			stop_service($package['name']);
237 2addd5b2 Ermal
		sync_package($idx, true, true);
238
		if($pkg_interface == "console") 
239 c92ccac7 Vinicius Coque
			echo "\n" . gettext("Syncing packages:");
240 e65a287f Scott Ullrich
	}
241 06e57df8 Scott Ullrich
242 b2a66231 Ermal
	if($show_message == true)
243 08452bff Warren Baker
		echo " done.\n";
244 06e57df8 Scott Ullrich
245 3a9eb3c9 Ermal
	@unlink("/conf/needs_package_sync");
246 78b94214 Ermal
	conf_mount_ro();
247 8c6516d1 Colin Smith
}
248
249 7597c8e8 Colin Smith
/*
250
 * is_freebsd_pkg_installed() - Check /var/db/pkg to determine whether or not a FreeBSD
251
 *				package is installed.
252
 */
253
function is_freebsd_pkg_installed($pkg) {
254 86af45ec Scott Ullrich
	if(!$pkg) 
255
		return;
256 fcf92dae Ermal
	$output = "";
257 a5566aa8 Vinicius Coque
	exec("/usr/local/sbin/pbi_info \"{$pkg}\"", $output, $retval);
258 b2a66231 Ermal
259 fcf92dae Ermal
	return (intval($retval) == 0);
260 7597c8e8 Colin Smith
}
261
262 8c6516d1 Colin Smith
/*
263
 * get_pkg_depends($pkg_name, $filetype = ".xml", $format = "files", return_nosync = 1):  Return a package's dependencies.
264
 *
265
 * $filetype = "all" || ".xml", ".tgz", etc.
266
 * $format = "files" (full filenames) || "names" (stripped / parsed depend names)
267
 * $return_nosync = 1 (return depends that have nosync set) | 0 (ignore packages with nosync)
268
 *
269
 */
270
function get_pkg_depends($pkg_name, $filetype = ".xml", $format = "files", $return_nosync = 1) {
271 e65a287f Scott Ullrich
	global $config;
272 b2a66231 Ermal
273 e65a287f Scott Ullrich
	$pkg_id = get_pkg_id($pkg_name);
274 b2a66231 Ermal
	if($pkg_id == -1)
275
		return -1; // This package doesn't really exist - exit the function.
276
	else if (!isset($config['installedpackages']['package'][$pkg_id]))
277
		return; // No package belongs to the pkg_id passed to this function.
278
279
	$package =& $config['installedpackages']['package'][$pkg_id];
280 e65a287f Scott Ullrich
	if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
281 addc0439 Renato Botelho
		log_error(sprintf(gettext('The %1$s package is missing required dependencies and must be reinstalled. %2$s'), $package['name'], $package['configurationfile']));
282 2c794549 Ermal
		uninstall_package($package['name']);
283 2addd5b2 Ermal
		if (install_package($package['name']) < 0) {
284
			log_error("Failed reinstalling package {$package['name']}.");
285 2c794549 Ermal
			return false;
286 2addd5b2 Ermal
		}
287 093441f0 Colin Smith
	}
288 19a11678 Colin Smith
	$pkg_xml = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
289 b2a66231 Ermal
	if (!empty($pkg_xml['additional_files_needed'])) {
290 e65a287f Scott Ullrich
		foreach($pkg_xml['additional_files_needed'] as $item) {
291 b2a66231 Ermal
			if ($return_nosync == 0 && isset($item['nosync']))
292
				continue; // Do not return depends with nosync set if not required.
293 e65a287f Scott Ullrich
			$depend_file = substr(strrchr($item['item']['0'], '/'),1); // Strip URLs down to filenames.
294
			$depend_name = substr(substr($depend_file,0,strpos($depend_file,".")+1),0,-1); // Strip filename down to dependency name.
295 b2a66231 Ermal
			if (($filetype != "all") && (!preg_match("/{$filetype}/i", $depend_file)))
296
					continue;
297 2c794549 Ermal
			if ($item['prefix'] != "")
298 e65a287f Scott Ullrich
				$prefix = $item['prefix'];
299 2c794549 Ermal
			else
300 e65a287f Scott Ullrich
				$prefix = "/usr/local/pkg/";
301 017d381c Scott Ullrich
			// Ensure that the prefix exists to avoid installation errors.
302
			if(!is_dir($prefix)) 
303 b2a66231 Ermal
				exec("/bin/mkdir -p {$prefix}");
304 3e155fab Scott Ullrich
			if(!file_exists($prefix . $depend_file))
305 6acdf659 Carlos Eduardo Ramos
				log_error(sprintf(gettext("The %s package is missing required dependencies and must be reinstalled."), $package['name']));
306 e65a287f Scott Ullrich
			switch ($format) {
307 b2a66231 Ermal
			case "files":
308
				$depends[] = $prefix . $depend_file;
309
				break;
310
			case "names":
311
				switch ($filetype) {
312
				case "all":
313
					if(preg_match("/\.xml/i", $depend_file)) {
314
						$depend_xml = parse_xml_config_pkg("/usr/local/pkg/{$depend_file}", "packagegui");
315
						if (!empty($depend_xml))
316 017d381c Scott Ullrich
							$depends[] = $depend_xml['name'];
317 b2a66231 Ermal
					} else
318
						$depends[] = $depend_name; // If this dependency isn't package XML, use the stripped filename.
319
					break;
320
				case ".xml":
321
					$depend_xml = parse_xml_config_pkg("/usr/local/pkg/" . $depend_file, "packagegui");
322
					if (!empty($depend_xml))
323
						$depends[] = $depend_xml['name'];
324
					break;
325
				default:
326
					$depends[] = $depend_name; // If we aren't looking for XML, use the stripped filename (it's all we have).
327
					break;
328
				}
329 e65a287f Scott Ullrich
			}
330 b2a66231 Ermal
		}
331 e65a287f Scott Ullrich
		return $depends;
332
	}
333 8c6516d1 Colin Smith
}
334
335 2c794549 Ermal
function uninstall_package($pkg_name) {
336 fcf92dae Ermal
	global $config, $static_output;
337 f0695975 Scott Ullrich
	global $builder_package_install;
338 b2a66231 Ermal
339 09e11b69 Scott Ullrich
	// Back up /usr/local/lib libraries first if
340
	// not running from the builder code.
341 d2a08a06 Scott Ullrich
	// also take into account rrd binaries
342 f0695975 Scott Ullrich
	if(!$builder_package_install) {
343
		if(!file_exists("/tmp/pkg_libs.tgz")) {
344
			$static_output .= "Backing up libraries... ";
345
			update_output_window($static_output);
346
			exec("/usr/bin/tar czPf /tmp/pkg_libs.tgz `/bin/cat /etc/pfSense_md5.txt | /usr/bin/grep 'local/lib' | /usr/bin/awk '{ print $2 }' | /usr/bin/cut -d'(' -f2 | /usr/bin/cut -d')' -f1`");
347 cb6630e5 Scott Ullrich
			exec("/usr/bin/tar czPf /tmp/pkg_bins.tgz `/bin/cat /etc/pfSense_md5.txt | /usr/bin/grep 'rrd' | /usr/bin/awk '{ print $2 }' | /usr/bin/cut -d'(' -f2 | /usr/bin/cut -d')' -f1`");
348 f0695975 Scott Ullrich
			$static_output .= "\n";
349
		}
350 4c6a49d7 Scott Ullrich
	}
351 b2a66231 Ermal
352 7eea4407 Ermal
	stop_service($pkg_name);
353
354 f898cf33 Scott Ullrich
	$id = get_pkg_id($pkg_name);
355 df5da531 Ermal
	if ($id >= 0) {
356 a5566aa8 Vinicius Coque
		$pkg_depends =& $config['installedpackages']['package'][$id]['depends_on_package_pbi'];
357 fcf92dae Ermal
		$static_output .= "Removing package...\n";
358
		update_output_window($static_output);
359 b7729cee Ermal
		if (is_array($pkg_depends)) {
360
			foreach ($pkg_depends as $pkg_depend)
361 fcf92dae Ermal
				delete_package($pkg_depend);
362 569aeae7 Vinicius Coque
		} else {
363 8059acb5 Phil Davis
			// The packages (1 or more) are all in one long string.
364
			// We need to pass them 1 at a time to delete_package.
365
			// Compress any multiple whitespace (sp, tab, cr, lf...) into a single space char.
366
			$pkg_dep_str = preg_replace("'\s+'", ' ', $pkg_depends);
367
			// Get rid of any leading or trailing space.
368
			$pkg_dep_str = trim($pkg_dep_str);
369
			// Now we have a space-separated string. Make it into an array and process it.
370
			$pkg_dep_array = explode(" ", $pkg_dep_str);
371
			foreach ($pkg_dep_array as $pkg_depend) {
372
				delete_package($pkg_depend);
373
			}
374 b7729cee Ermal
		}
375 1570d27a Ermal Lu?i
	}
376 f898cf33 Scott Ullrich
	delete_package_xml($pkg_name);
377 4c6a49d7 Scott Ullrich
378 09e11b69 Scott Ullrich
	// Restore libraries that we backed up if not 
379
	// running from the builder code.
380 f0695975 Scott Ullrich
	if(!$builder_package_install) {
381
		$static_output .= "Cleaning up... ";
382
		update_output_window($static_output);
383
		exec("/usr/bin/tar xzPfU /tmp/pkg_libs.tgz -C /");
384 efea7969 Scott Ullrich
		exec("/usr/bin/tar xzPfU /tmp/pkg_bins.tgz -C /");
385
		@unlink("/tmp/pkg_libs.tgz");
386
		@unlink("/tmp/pkg_bins.tgz");
387 f0695975 Scott Ullrich
	}
388 f898cf33 Scott Ullrich
}
389
390 7bbfe007 Scott Ullrich
function force_remove_package($pkg_name) {
391
	delete_package_xml($pkg_name);
392
}
393
394 8c6516d1 Colin Smith
/*
395
 * sync_package($pkg_name, $sync_depends = true, $show_message = false) Force a package to setup its configuration and rc.d files.
396
 */
397
function sync_package($pkg_name, $sync_depends = true, $show_message = false) {
398 c132bdb0 Ermal
	global $config, $config_parsed;
399 f0695975 Scott Ullrich
	global $builder_package_install;
400
	
401 09e11b69 Scott Ullrich
	// If this code is being called by pfspkg_installer 
402
	// which the builder system uses then return (ignore).
403 f0695975 Scott Ullrich
	if($builder_package_install)
404
		return;
405 b2a66231 Ermal
	
406
	if(empty($config['installedpackages']['package']))
407
		return;
408 669e1adb Bill Marquette
	if(!is_numeric($pkg_name)) {
409
		$pkg_id = get_pkg_id($pkg_name);
410 b2a66231 Ermal
		if($pkg_id == -1)
411
			return -1; // This package doesn't really exist - exit the function.
412 669e1adb Bill Marquette
	} else {
413
		$pkg_id = $pkg_name;
414 b2a66231 Ermal
		if(empty($config['installedpackages']['package'][$pkg_id]))
415
			return;  // No package belongs to the pkg_id passed to this function.
416 669e1adb Bill Marquette
	}
417 04d10bbc Scott Ullrich
        if (is_array($config['installedpackages']['package'][$pkg_id]))
418 b2a66231 Ermal
		$package =& $config['installedpackages']['package'][$pkg_id];
419 04d10bbc Scott Ullrich
        else
420 b2a66231 Ermal
		return; /* empty package tag */
421 669e1adb Bill Marquette
	if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
422 6acdf659 Carlos Eduardo Ramos
		log_error(sprintf(gettext("The %s package is missing its configuration file and must be reinstalled."), $package['name']));
423 7bbfe007 Scott Ullrich
		force_remove_package($package['name']);
424 2c794549 Ermal
		return -1;
425
	}
426
	$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
427 2addd5b2 Ermal
	if(isset($pkg_config['nosync']))
428
		return;
429 2c794549 Ermal
	/* Bring in package include files */
430
	if (!empty($pkg_config['include_file'])) {
431
		$include_file = $pkg_config['include_file'];
432
		if (file_exists($include_file))
433
			require_once($include_file);
434
		else {
435
			/* XXX: What the heck is this?! */
436
			log_error("Reinstalling package {$package['name']} because its include file({$include_file}) is missing!");
437
			uninstall_package($package['name']);
438
			if (install_package($package['name']) < 0) {
439
				log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!");
440
				return -1;
441 83cfae8d Ermal Lu?i
			}
442 30e4c34a Scott Ullrich
		}
443 2c794549 Ermal
	}
444 30e4c34a Scott Ullrich
445 2c794549 Ermal
	if(!empty($pkg_config['custom_php_global_functions']))
446
		eval($pkg_config['custom_php_global_functions']);
447
	if(!empty($pkg_config['custom_php_resync_config_command']))
448
		eval($pkg_config['custom_php_resync_config_command']);
449
	if($sync_depends == true) {
450
		$depends = get_pkg_depends($pkg_name, ".xml", "files", 1); // Call dependency handler and do a little more error checking.
451
		if(is_array($depends)) {
452
			foreach($depends as $item) {
453
				if(!file_exists($item)) {
454 2addd5b2 Ermal
					require_once("notices.inc");
455 b96f6496 Renato Botelho
					file_notice($package['name'], sprintf(gettext("The %s package is missing required dependencies and must be reinstalled."), $package['name']), "Packages", "/pkg_mgr_install.php?mode=reinstallpkg&pkg={$package['name']}", 1);
456 2c794549 Ermal
					log_error("Could not find {$item}. Reinstalling package.");
457
					uninstall_package($pkg_name);
458 2addd5b2 Ermal
					if (install_package($pkg_name) < 0) {
459
						log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!");
460
						return -1;
461
					}
462 2c794549 Ermal
				} else {
463
					$item_config = parse_xml_config_pkg($item, "packagegui");
464
					if (empty($item_config))
465
						continue;
466
					if(isset($item_config['nosync']))
467
						continue;
468 2addd5b2 Ermal
					if (!empty($item_config['include_file'])) {
469
						if (file_exists($item_config['include_file']))	
470
							require_once($item_config['include_file']);
471
						else {
472
							log_error("Not calling package sync code for dependency {$item_config['name']} of {$package['name']} because some include files are missing.");
473
							continue;
474
						}
475
					}
476
					if($item_config['custom_php_global_functions'] <> "")
477
						eval($item_config['custom_php_global_functions']);
478 2c794549 Ermal
					if($item_config['custom_php_resync_config_command'] <> "")
479
						eval($item_config['custom_php_resync_config_command']);
480
					if($show_message == true)
481
						print " " . $item_config['name'];
482 669e1adb Bill Marquette
				}
483
			}
484
		}
485
	}
486 8c6516d1 Colin Smith
}
487
488 7597c8e8 Colin Smith
/*
489 43dad535 Vinicius Coque
 * pkg_fetch_recursive: Download and install a FreeBSD PBI package. This function provides output to
490 7597c8e8 Colin Smith
 * 			a progress bar and output window.
491
 */
492 0cdf4e87 Ermal
function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = "") {
493 2addd5b2 Ermal
	global $static_output, $g;
494 b2a66231 Ermal
495 19f576fd Scott Ullrich
	// Clean up incoming filenames
496
	$filename = str_replace("  ", " ", $filename);
497
	$filename = str_replace("\n", " ", $filename);
498
	$filename = str_replace("  ", " ", $filename);
499
500 cfbfd941 smos
	$pkgs = explode(" ", $filename);
501 764bd0ac Scott Ullrich
	foreach($pkgs as $filename) {
502 21762198 jim-p
		$filename = trim($filename);
503 05ff388a Scott Ullrich
		if (($g['platform'] == "nanobsd") || ($g['platform'] == "embedded")) {
504
			$pkgtmpdir = "/usr/bin/env PKG_TMPDIR=/root/ ";
505
			$pkgstagingdir = "/root/tmp";
506
			if (!is_dir($pkgstagingdir))
507
				mkdir($pkgstagingdir);
508
			$pkgstaging = "-o {$pkgstagingdir}/instmp.XXXXXX";
509
			$fetchdir = $pkgstagingdir;
510 aeaa7358 Ermal
		} else {
511 05ff388a Scott Ullrich
			$fetchdir = $g['tmp_path'];
512 aeaa7358 Ermal
		}
513 22beab88 jim-p
514 05ff388a Scott Ullrich
		$osname = php_uname("s");
515
		$arch =  php_uname("m");
516
		$rel = strtolower(php_uname("r"));
517
		if (substr_count($rel, '-') > 1)
518
			$rel = substr($rel, 0, strrpos($rel, "-"));
519
		$priv_url = "http://ftp2.{$osname}.org/pub/{$osname}/ports/{$arch}/packages-{$rel}/All";
520
		if (empty($base_url))
521
			$base_url = $priv_url;
522
		if (substr($base_url, -1) == "/")
523
			$base_url = substr($base_url, 0, -1);
524
		$fetchto = "{$fetchdir}/apkg_{$filename}";
525
		$static_output .= "\n" . str_repeat(" ", $dependlevel * 2 + 1) . "Downloading {$base_url}/{$filename} ... ";
526
		if (download_file_with_progress_bar("{$base_url}/{$filename}", $fetchto) !== true) {
527
			if ($base_url != $priv_url && download_file_with_progress_bar("{$priv_url}/{$filename}", $fetchto) !== true) {
528
				$static_output .= " could not download from there or {$priv_url}/{$filename}.\n";
529
				update_output_window($static_output);
530
				return false;
531
			} else if ($base_url == $priv_url) {
532
				$static_output .= " failed to download.\n";
533
				update_output_window($static_output);
534
				return false;
535
			} else {
536
				$static_output .= " [{$osname} repository]\n";
537
				update_output_window($static_output);
538
			}
539
		}
540
		$static_output .= " (extracting)\n";
541
		update_output_window($static_output);
542 43dad535 Vinicius Coque
543 05ff388a Scott Ullrich
		$pkgaddout = "";
544 b2a66231 Ermal
545 05ff388a Scott Ullrich
		exec("/usr/local/sbin/pbi_add {$pkgstaging} -f -v --no-checksig {$fetchto} 2>&1", $pkgaddout);
546
		pkg_debug($pkgname . " " . print_r($pkgaddout, true) . "\npbi_add successfully completed.\n");
547
548
		exec("/usr/local/sbin/pbi_info " . preg_replace('/\.pbi$/','',$filename) . " | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir);
549
		$pbidir = $pbidir[0];
550
		$linkdirs = array('bin','sbin');
551
		foreach($linkdirs as $dir) {
552
			if(is_dir("{$pbidir}/{$dir}")) {
553
				$files = scandir("{$pbidir}/{$dir}");
554
				foreach($files as $f) {
555 44d55df6 Scott Ullrich
					if(!file_exists("/usr/local/{$dir}/{$f}")) {
556
						symlink("{$pbidir}/{$dir}/${$f}","/usr/local/{$dir}/{$f}");
557
					}
558 05ff388a Scott Ullrich
				}
559 43dad535 Vinicius Coque
			}
560
		}
561
	}
562 e65a287f Scott Ullrich
	return true;
563 8c6516d1 Colin Smith
}
564
565 7597c8e8 Colin Smith
function install_package($package, $pkg_info = "") {
566 2addd5b2 Ermal
	global $g, $config, $static_output, $pkg_interface;
567 b2a66231 Ermal
568 43ad432c Ermal Lu?i
	/* safe side. Write config below will send to ro again. */
569
	conf_mount_rw();
570
571 dbef849d Scott Ullrich
	if($pkg_interface == "console") 	
572
		echo "\n";
573 7597c8e8 Colin Smith
	/* fetch package information if needed */
574 b2a66231 Ermal
	if(empty($pkg_info) or !is_array($pkg_info[$package])) {
575 7597c8e8 Colin Smith
		$pkg_info = get_pkg_info(array($package));
576
		$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
577 1b28121f Ermal
		if (empty($pkg_info)) {
578
			conf_mount_ro();
579
			return -1;
580
		}
581 7597c8e8 Colin Smith
	}
582 c92ccac7 Vinicius Coque
	pkg_debug(gettext("Beginning package installation.") . "\n");
583
	log_error(sprintf(gettext('Beginning package installation for %s .'), $pkg_info['name']));
584
	$static_output .= sprintf(gettext("Beginning package installation for %s ."), $pkg_info['name']);
585 1b28121f Ermal
	update_status($static_output);
586 7597c8e8 Colin Smith
	/* fetch the package's configuration file */
587
	if($pkg_info['config_file'] != "") {
588 0b07c763 Chris Buechler
		$static_output .= "\n" . gettext("Downloading package configuration file... ");
589 7597c8e8 Colin Smith
		update_output_window($static_output);
590 c92ccac7 Vinicius Coque
		pkg_debug(gettext("Downloading package configuration file...") . "\n");
591 7597c8e8 Colin Smith
		$fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1);
592
		download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto);
593
		if(!file_exists('/usr/local/pkg/' . $fetchto)) {
594 84bc8eb7 jim-p
			pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n");
595 fcf92dae Ermal
			if($pkg_interface == "console")
596 3ec86ca8 Renato Botelho
				print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n";
597 fcf92dae Ermal
			else {
598 9d3d8d00 Vinicius Coque
				$static_output .= gettext("failed!\n\nInstallation aborted.\n");
599 7597c8e8 Colin Smith
				update_output_window($static_output);
600
				echo "<br>Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>";
601
			}
602 fcf92dae Ermal
			conf_mount_ro();
603
			return -1;
604 7597c8e8 Colin Smith
		}
605 6acdf659 Carlos Eduardo Ramos
		$static_output .= gettext("done.") . "\n";
606 7597c8e8 Colin Smith
		update_output_window($static_output);
607
	}
608
	/* add package information to config.xml */
609
	$pkgid = get_pkg_id($pkg_info['name']);
610 6acdf659 Carlos Eduardo Ramos
	$static_output .= gettext("Saving updated package information...") . " ";
611 7597c8e8 Colin Smith
	update_output_window($static_output);
612
	if($pkgid == -1) {
613
		$config['installedpackages']['package'][] = $pkg_info;
614 b1e4005f Vinicius Coque
		$changedesc = sprintf(gettext("Installed %s package."),$pkg_info['name']);
615 6acdf659 Carlos Eduardo Ramos
		$to_output = gettext("done.") . "\n";
616 7597c8e8 Colin Smith
	} else {
617
		$config['installedpackages']['package'][$pkgid] = $pkg_info;
618 6acdf659 Carlos Eduardo Ramos
		$changedesc = sprintf(gettext("Overwrote previous installation of %s."), $pkg_info['name']);
619
		$to_output = gettext("overwrite!") . "\n";
620 7597c8e8 Colin Smith
	}
621 6622e126 Scott Ullrich
	if(file_exists('/conf/needs_package_sync'))
622
		@unlink('/conf/needs_package_sync');
623 3339fac0 Ermal Lu?i
	conf_mount_ro();
624 f9c8e64c jim-p
	write_config("Intermediate config write during package install for {$pkg_info['name']}.");
625 7597c8e8 Colin Smith
	$static_output .= $to_output;
626
	update_output_window($static_output);
627
	/* install other package components */
628 2c794549 Ermal
	if (!install_package_xml($package)) {
629
		uninstall_package($package);
630
		write_config($changedesc);
631 b96f6496 Renato Botelho
		$static_output .= gettext("Failed to install package.") . "\n";
632 2c794549 Ermal
		update_output_window($static_output);
633
		return -1;
634
	} else {
635 b96f6496 Renato Botelho
		$static_output .= gettext("Writing configuration... ");
636 2c794549 Ermal
		update_output_window($static_output);
637
		write_config($changedesc);
638 b96f6496 Renato Botelho
		$static_output .= gettext("done.") . "\n";
639 2c794549 Ermal
		update_output_window($static_output);
640
		if($pkg_info['after_install_info']) 
641
			update_output_window($pkg_info['after_install_info']);	
642
	}
643 7597c8e8 Colin Smith
}
644
645 cfde64b8 Scott Ullrich
function get_after_install_info($package) {
646
	global $pkg_info;
647
	/* fetch package information if needed */
648
	if(!$pkg_info or !is_array($pkg_info[$package])) {
649
		$pkg_info = get_pkg_info(array($package));
650
		$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
651
	}
652
	if($pkg_info['after_install_info'])
653
		return $pkg_info['after_install_info'];
654
}
655
656 2a0e6517 Colin Smith
function eval_once($toeval) {
657
	global $evaled;
658 57965588 Colin Smith
	if(!$evaled) $evaled = array();
659 2a0e6517 Colin Smith
	$evalmd5 = md5($toeval);
660
	if(!in_array($evalmd5, $evaled)) {
661 8604523b Ermal Lu?i
		@eval($toeval);
662 2a0e6517 Colin Smith
		$evaled[] = $evalmd5;
663
	}
664
	return;
665
}
666
667 7597c8e8 Colin Smith
function install_package_xml($pkg) {
668 c132bdb0 Ermal
	global $g, $config, $static_output, $pkg_interface, $config_parsed;
669 b2a66231 Ermal
670 7597c8e8 Colin Smith
	if(($pkgid = get_pkg_id($pkg)) == -1) {
671 6acdf659 Carlos Eduardo Ramos
		$static_output .= sprintf(gettext("The %s package is not installed.%sInstallation aborted."), $pkg, "\n\n");
672 7597c8e8 Colin Smith
		update_output_window($static_output);
673 1a22ffcd Scott Ullrich
		if($pkg_interface <> "console") {
674
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
675
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
676
		}
677 7597c8e8 Colin Smith
		sleep(1);
678 2c794549 Ermal
		return false;
679 b2a66231 Ermal
	} else
680 7597c8e8 Colin Smith
		$pkg_info = $config['installedpackages']['package'][$pkgid];
681 b2a66231 Ermal
682 a6d0d461 Colin Smith
	/* pkg_add the package and its dependencies */
683 e65a287f Scott Ullrich
	if($pkg_info['depends_on_package_base_url'] != "") {
684 dbef849d Scott Ullrich
		if($pkg_interface == "console") 
685
			echo "\n";
686 6acdf659 Carlos Eduardo Ramos
		update_status(gettext("Installing") . " " . $pkg_info['name'] . " " . gettext("and its dependencies."));
687
		$static_output .= gettext("Downloading") . " " . $pkg_info['name'] . " " . gettext("and its dependencies... ");
688 e65a287f Scott Ullrich
		$static_orig = $static_output;
689
		$static_output .= "\n";
690
		update_output_window($static_output);
691 a5566aa8 Vinicius Coque
		foreach((array) $pkg_info['depends_on_package_pbi'] as $pkgdep) {
692 e65a287f Scott Ullrich
			$pkg_name = substr(reverse_strrchr($pkgdep, "."), 0, -1);
693 b3a4ff7c Scott Ullrich
			$static_output = $static_orig . "\nChecking for package installation... ";
694 1b28121f Ermal
			update_output_window($static_output);
695 ad88ff3f Ermal
			if (!is_freebsd_pkg_installed($pkg_name)) {
696 a0b205f0 Ermal
				if (!pkg_fetch_recursive($pkg_name, $pkgdep, 0, $pkg_info['depends_on_package_base_url'])) {
697 ad88ff3f Ermal
					$static_output .= "of {$pkg_name} failed!\n\nInstallation aborted.";
698
					update_output_window($static_output);
699 c92ccac7 Vinicius Coque
					pkg_debug(gettext("Package WAS NOT installed properly.") . "\n");
700 ad88ff3f Ermal
					if($pkg_interface <> "console") {
701
						echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
702
						echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
703
					}
704
					sleep(1);
705
					return false;
706 1a22ffcd Scott Ullrich
				}
707 e65a287f Scott Ullrich
			}
708
		}
709
	}
710 7597c8e8 Colin Smith
	$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1);
711
	if(file_exists("/usr/local/pkg/" . $configfile)) {
712 9d3d8d00 Vinicius Coque
		$static_output .= gettext("Loading package configuration... ");
713 7597c8e8 Colin Smith
		update_output_window($static_output);
714 43db85f8 Scott Ullrich
		$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $configfile, "packagegui");
715 6acdf659 Carlos Eduardo Ramos
		$static_output .= gettext("done.") . "\n";
716 7597c8e8 Colin Smith
		update_output_window($static_output);
717 9d3d8d00 Vinicius Coque
		$static_output .= gettext("Configuring package components...\n");
718 8dee24a6 Ermal Lu?i
		if (!empty($pkg_config['filter_rules_needed']))
719 bc771948 Ermal Lu?i
			$config['installedpackages']['package'][$pkgid]['filter_rule_function'] = $pkg_config['filter_rules_needed'];
720 7597c8e8 Colin Smith
		update_output_window($static_output);
721
		/* modify system files */
722 fcf92dae Ermal
		if(is_array($pkg_config['modify_system']) && is_array($pkg_config['modify_system']['item'])) {
723 9d3d8d00 Vinicius Coque
			$static_output .= gettext("System files... ");
724 7597c8e8 Colin Smith
			update_output_window($static_output);
725
			foreach($pkg_config['modify_system']['item'] as $ms) {
726
				if($ms['textneeded']) {
727
					add_text_to_file($ms['modifyfilename'], $ms['textneeded']);
728
				}
729
			}
730 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
731 7597c8e8 Colin Smith
			update_output_window($static_output);
732
		}
733
		/* download additional files */
734 1570d27a Ermal Lu?i
		if(is_array($pkg_config['additional_files_needed'])) {
735 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Additional files... ");
736 7597c8e8 Colin Smith
			$static_orig = $static_output;
737
			update_output_window($static_output);
738
			foreach($pkg_config['additional_files_needed'] as $afn) {
739
				$filename = get_filename_from_url($afn['item'][0]);
740 b2a66231 Ermal
				if($afn['chmod'] <> "")
741 7597c8e8 Colin Smith
					$pkg_chmod = $afn['chmod'];
742 b2a66231 Ermal
				else
743 7597c8e8 Colin Smith
					$pkg_chmod = "";
744 b2a66231 Ermal
745
				if($afn['prefix'] <> "")
746 7597c8e8 Colin Smith
					$prefix = $afn['prefix'];
747 b2a66231 Ermal
				else
748 7597c8e8 Colin Smith
					$prefix = "/usr/local/pkg/";
749 b2a66231 Ermal
750 e6d436e8 Scott Ullrich
				if(!is_dir($prefix)) 
751
					safe_mkdir($prefix);
752
 				$static_output .= $filename . " ";
753 b2b15543 Scott Ullrich
				update_output_window($static_output);
754 fcf92dae Ermal
				if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) {
755
					$static_output .= "failed.\n";
756 6f14b34a Ermal
					@unlink($prefix . $filename);
757 fcf92dae Ermal
					update_output_window($static_output);
758
					return false;
759
				}
760 7597c8e8 Colin Smith
				if(stristr($filename, ".tgz") <> "") {
761 c92ccac7 Vinicius Coque
					pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n");
762 e65a287f Scott Ullrich
					$tarout = "";
763 c1312033 Colin Smith
					exec("/usr/bin/tar xvzf " . $prefix . $filename . " -C / 2>&1", $tarout);
764 eab543ed Ermal
					pkg_debug(print_r($tarout, true) . "\n");
765 7597c8e8 Colin Smith
				}
766
				if($pkg_chmod <> "") {
767 c92ccac7 Vinicius Coque
					pkg_debug(sprintf(gettext('Changing file mode to %1$s for %2$s%3$s%4$s'), $pkg_chmod, $prefix, $filename, "\n"));
768 6ee34f4d Ermal Lu?i
					@chmod($prefix . $filename, $pkg_chmod);
769 7597c8e8 Colin Smith
					system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
770
				}
771
				$static_output = $static_orig;
772
                                update_output_window($static_output);
773
			}
774 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
775 7597c8e8 Colin Smith
			update_output_window($static_output);
776
		}
777 2df5cb99 Scott Ullrich
		/*   if a require exists, include it.  this will
778
		 *   show us where an error exists in a package
779
		 *   instead of making us blindly guess
780
		 */
781 fcf92dae Ermal
		$missing_include = false;
782 2df5cb99 Scott Ullrich
		if($pkg_config['include_file'] <> "") {
783 3ec86ca8 Renato Botelho
			$static_output = gettext("Loading package instructions...") . "\n";
784 2df5cb99 Scott Ullrich
			update_output_window($static_output);
785 eab543ed Ermal
			pkg_debug("require_once('{$pkg_config['include_file']}')\n");
786 43ad432c Ermal Lu?i
			if (file_exists($pkg_config['include_file']))
787
				require_once($pkg_config['include_file']);
788 fcf92dae Ermal
			else {
789
				$missing_include = true;
790 7dbbaecd Scott Ullrich
				$static_output .= "Include " . basename($pkg_config['include_file']) . " is missing!\n";
791 fcf92dae Ermal
				update_output_window($static_output);
792
				/* XXX: Should undo the steps before this?! */
793
				return false;
794
			}
795 43db85f8 Scott Ullrich
		}
796 57811192 Ermal
797
		/* custom commands */
798
		$static_output .= gettext("Custom commands...") . "\n";
799
		update_output_window($static_output);
800
		if ($missing_include == false) {
801
			if($pkg_config['custom_php_global_functions'] <> "") {
802
				$static_output .= gettext("Executing custom_php_global_functions()...");
803
				update_output_window($static_output);
804
				eval_once($pkg_config['custom_php_global_functions']);
805
				$static_output .= gettext("done.") . "\n";
806
				update_output_window($static_output);
807
			}
808
			if($pkg_config['custom_php_install_command']) {
809
				$static_output .= gettext("Executing custom_php_install_command()...");
810
				update_output_window($static_output);
811 169f1574 Vinicius Coque
				/* XXX: create symlinks for conf files into the PBI directories.
812
				 *	change packages to store configs at /usr/pbi/pkg/etc and remove this
813
				 */
814
				eval_once($pkg_config['custom_php_install_command']);
815 8059acb5 Phil Davis
				// Note: pkg may be mixed-case, e.g. "squidGuard" but the PBI names are lowercase.
816
				// e.g. "squidguard-1.4_4-i386" so feed lowercase to pbi_info below.
817
				// Also add the "-" so that examples like "squid-" do not match "squidguard-".
818
				$pkg_name_for_pbi_match = strtolower($pkg) . "-";
819
				exec("/usr/local/sbin/pbi_info | grep {$pkg_name_for_pbi_match}- | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray);
820 84d50fe7 Phil Davis
				$pbidir0 = $pbidirarray[0];
821 169f1574 Vinicius Coque
				exec("find /usr/local/etc/ -name *.conf | grep {$pkg}",$files);
822
				foreach($files as $f) {
823 84d50fe7 Phil Davis
					$pbiconf = str_replace('/usr/local',$pbidir0,$f);
824 8059acb5 Phil Davis
					if (is_file($pbiconf) || is_link($pbiconf)) {
825
						unlink($pbiconf);
826
					}
827 169f1574 Vinicius Coque
					symlink($f,$pbiconf);
828
				}
829 57811192 Ermal
				eval_once($pkg_config['custom_php_install_command']);
830
				$static_output .= gettext("done.") . "\n";
831
				update_output_window($static_output);
832
			}
833
			if($pkg_config['custom_php_resync_config_command'] <> "") {
834
				$static_output .= gettext("Executing custom_php_resync_config_command()...");
835
				update_output_window($static_output);
836
				eval_once($pkg_config['custom_php_resync_config_command']);
837
				$static_output .= gettext("done.") . "\n";
838
				update_output_window($static_output);
839
			}
840
		}
841 7597c8e8 Colin Smith
		/* sidebar items */
842 1570d27a Ermal Lu?i
		if(is_array($pkg_config['menu'])) {
843 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Menu items... ");
844 7597c8e8 Colin Smith
			update_output_window($static_output);
845 1570d27a Ermal Lu?i
			foreach($pkg_config['menu'] as $menu) {
846 f3a274b7 Ermal
				if(is_array($config['installedpackages']['menu'])) {
847 1570d27a Ermal Lu?i
					foreach($config['installedpackages']['menu'] as $amenu)
848
						if($amenu['name'] == $menu['name'])
849
							continue 2;
850 f3a274b7 Ermal
				} else
851 27018d3c Ermal
					$config['installedpackages']['menu'] = array();
852 1570d27a Ermal Lu?i
				$config['installedpackages']['menu'][] = $menu;
853 7597c8e8 Colin Smith
			}
854 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
855 7597c8e8 Colin Smith
			update_output_window($static_output);
856
		}
857 b63f2e8b Matthew Grooms
		/* integrated tab items */
858 1570d27a Ermal Lu?i
		if(is_array($pkg_config['tabs']['tab'])) {
859 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Integrated Tab items... ");
860 b63f2e8b Matthew Grooms
			update_output_window($static_output);
861 1570d27a Ermal Lu?i
			foreach($pkg_config['tabs']['tab'] as $tab) {
862 f3a274b7 Ermal
				if(is_array($config['installedpackages']['tab'])) {
863 1570d27a Ermal Lu?i
					foreach($config['installedpackages']['tab'] as $atab)
864
						if($atab['name'] == $tab['name'])
865
							continue 2;
866 f3a274b7 Ermal
				} else
867 27018d3c Ermal
					$config['installedpackages']['tab'] = array();
868 1570d27a Ermal Lu?i
				$config['installedpackages']['tab'][] = $tab;
869 b63f2e8b Matthew Grooms
			}
870 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
871 b63f2e8b Matthew Grooms
			update_output_window($static_output);
872
		}
873 2dc264a4 Colin Smith
		/* services */
874 1570d27a Ermal Lu?i
		if(is_array($pkg_config['service'])) {
875 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Services... ");
876 2dc264a4 Colin Smith
			update_output_window($static_output);
877
			foreach($pkg_config['service'] as $service) {
878 f3a274b7 Ermal
				if(is_array($config['installedpackages']['service'])) {
879 d282095a Renato Botelho
					foreach($config['installedpackages']['service'] as $aservice)
880
						if($aservice['name'] == $service['name'])
881
							continue 2;
882 f3a274b7 Ermal
				} else
883 27018d3c Ermal
					$config['installedpackages']['service'] = array();
884 2dc264a4 Colin Smith
				$config['installedpackages']['service'][] = $service;
885
			}
886 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
887 2dc264a4 Colin Smith
			update_output_window($static_output);
888
		}
889 7597c8e8 Colin Smith
	} else {
890 6acdf659 Carlos Eduardo Ramos
		$static_output .= gettext("Loading package configuration... failed!") . "\n\n" . gettext("Installation aborted.");
891 7597c8e8 Colin Smith
		update_output_window($static_output);
892 c92ccac7 Vinicius Coque
		pkg_debug(gettext("Unable to load package configuration. Installation aborted.") ."\n");
893 1a22ffcd Scott Ullrich
		if($pkg_interface <> "console") {
894
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
895
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
896
		}
897 e65a287f Scott Ullrich
		sleep(1);
898 2c794549 Ermal
		return false;
899 7597c8e8 Colin Smith
	}
900 2c794549 Ermal
901
	/* set up package logging streams */
902
	if($pkg_info['logging']) {
903
		mwexec("/usr/sbin/fifolog_create -s 32768 {$g['varlog_path']}/{$pkg_info['logging']['logfilename']}");
904
		@chmod($g['varlog_path'] . '/' . $pkg_info['logging']['logfilename'], 0600);
905 2addd5b2 Ermal
		add_text_to_file("/etc/syslog.conf", $pkg_info['logging']['facilityname'] . "\t\t\t\t" . $pkg_info['logging']['logfilename']);
906 eab543ed Ermal
		pkg_debug("Adding text to file /etc/syslog.conf\n");
907 2c794549 Ermal
		system_syslogd_start();
908
	}
909
910
	return true;
911 7597c8e8 Colin Smith
}
912 407bf67a Colin Smith
913 64974db7 Scott Ullrich
function does_package_depend($pkg) {
914
	// Should not happen, but just in case.
915
	if(!$pkg)
916
		return;
917
	$pkg_var_db_dir = glob("/var/db/pkg/{$pkg}*");
918
	// If this package has dependency then return true
919
	foreach($pkg_var_db_dir as $pvdd) {
920
		if (file_exists("{$vardb}/{$pvdd}/+REQUIRED_BY") && count(file("{$vardb}/{$pvdd}/+REQUIRED_BY")) > 0) 
921
			return true;
922
	}	
923
	// Did not find a record of dependencies, so return false.
924
	return false;
925
}
926
927 fcf92dae Ermal
function delete_package($pkg) {
928 1b28121f Ermal
	global $config, $g, $static_output, $vardb;
929 b2a66231 Ermal
930 86af45ec Scott Ullrich
	if(!$pkg) 
931
		return;
932 62c55268 Colin Smith
933 8059acb5 Phil Davis
	// Note: $pkg has the full PBI package name followed by ".pbi". Strip off ".pbi".
934 fcf92dae Ermal
	$pkg = substr(reverse_strrchr($pkg, "."), 0, -1);
935 b2a66231 Ermal
936 a5566aa8 Vinicius Coque
	if($pkg)
937
		$static_output .= sprintf(gettext("Starting package deletion for %s..."),$pkg);
938
	update_output_window($static_output);
939 64974db7 Scott Ullrich
940 9eeef922 Scott Ullrich
	remove_freebsd_package($pkg);
941 d9426abc Ermal
	$static_output .= "done.\n";
942
	update_output_window($static_output);
943 fcf92dae Ermal
944 b7ff3186 Ermal
	/* Rescan directories for what has been left and avoid fooling other programs. */
945
	mwexec("/sbin/ldconfig");
946
947 407bf67a Colin Smith
	return;
948
}
949
950
function delete_package_xml($pkg) {
951 941baf1e Ermal
	global $g, $config, $static_output, $pkg_interface, $rcfileprefix;
952 b2a66231 Ermal
953 232b01db jim-p
	conf_mount_rw();
954 6955830f Ermal Lu?i
955 b2a66231 Ermal
	$pkgid = get_pkg_id($pkg);
956
	if ($pkgid == -1) {
957 6acdf659 Carlos Eduardo Ramos
		$static_output .= sprintf(gettext("The %s package is not installed.%sDeletion aborted."), $pkg, "\n\n");
958 e65a287f Scott Ullrich
		update_output_window($static_output);
959 1a22ffcd Scott Ullrich
		if($pkg_interface <> "console") {
960
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
961
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
962
		}
963 e65a287f Scott Ullrich
		ob_flush();
964
		sleep(1);
965 3339fac0 Ermal Lu?i
		conf_mount_ro();
966 e65a287f Scott Ullrich
		return;
967
	}
968 c92ccac7 Vinicius Coque
	pkg_debug(sprintf(gettext("Removing %s package... "),$pkg));
969
	$static_output .= sprintf(gettext("Removing %s components..."),$pkg) . "\n";
970 407bf67a Colin Smith
	update_output_window($static_output);
971
	/* parse package configuration */
972
	$packages = &$config['installedpackages']['package'];
973 b63f2e8b Matthew Grooms
	$tabs =& $config['installedpackages']['tab'];
974
	$menus =& $config['installedpackages']['menu'];
975 3c41c4ab Colin Smith
	$services = &$config['installedpackages']['service'];
976 2addd5b2 Ermal
	$pkg_info =& $packages[$pkgid];
977
	if(file_exists("/usr/local/pkg/" . $pkg_info['configurationfile'])) {
978 19a11678 Colin Smith
		$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $packages[$pkgid]['configurationfile'], "packagegui");
979 b63f2e8b Matthew Grooms
		/* remove tab items */
980
		if(is_array($pkg_config['tabs'])) {
981 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Tabs items... ");
982 b63f2e8b Matthew Grooms
			update_output_window($static_output);
983 8604523b Ermal Lu?i
			if(is_array($pkg_config['tabs']['tab']) && is_array($tabs)) {
984
				foreach($pkg_config['tabs']['tab'] as $tab) {
985 b2a66231 Ermal
					foreach($tabs as $key => $insttab) {
986
						if($insttab['name'] == $tab['name']) {
987 5274feb0 Scott Ullrich
							unset($tabs[$key]);
988 b2a66231 Ermal
							break;
989
						}
990
					}
991 8604523b Ermal Lu?i
				}
992
			}
993 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
994 b63f2e8b Matthew Grooms
			update_output_window($static_output);
995
		}
996 3f01fe47 Colin Smith
		/* remove menu items */
997
		if(is_array($pkg_config['menu'])) {
998 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Menu items... ");
999 3f01fe47 Colin Smith
			update_output_window($static_output);
1000 8604523b Ermal Lu?i
			if (is_array($pkg_config['menu']) && is_array($menus)) {
1001
				foreach($pkg_config['menu'] as $menu) {
1002 b2a66231 Ermal
					foreach($menus as $key => $instmenu) {
1003
						if($instmenu['name'] == $menu['name']) {
1004 8604523b Ermal Lu?i
							unset($menus[$key]);
1005 b2a66231 Ermal
							break;
1006
						}
1007
					}
1008 8604523b Ermal Lu?i
				}
1009
			}
1010 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
1011 3f01fe47 Colin Smith
			update_output_window($static_output);
1012 407bf67a Colin Smith
		}
1013 3c41c4ab Colin Smith
		/* remove services */
1014
		if(is_array($pkg_config['service'])) {
1015 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Services... ");
1016 3c41c4ab Colin Smith
			update_output_window($static_output);
1017 8604523b Ermal Lu?i
			if (is_array($pkg_config['service']) && is_array($services)) {
1018
				foreach($pkg_config['service'] as $service) {
1019
					foreach($services as $key => $instservice) {
1020
						if($instservice['name'] == $service['name']) {
1021 b1224cdc jim-p
							if($g['booting'] != true)
1022 06e57df8 Scott Ullrich
								stop_service($service['name']);
1023 941baf1e Ermal
							if($service['rcfile']) {
1024
								$prefix = $rcfileprefix;
1025
								if (!empty($service['prefix']))
1026
									$prefix = $service['prefix'];
1027
								if (file_exists("{$prefix}{$service['rcfile']}"))
1028
									@unlink("{$prefix}{$service['rcfile']}");
1029
							}
1030 8604523b Ermal Lu?i
							unset($services[$key]);
1031
						}
1032 0cab7cad Colin Smith
					}
1033 3c41c4ab Colin Smith
				}
1034
			}
1035 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
1036 3c41c4ab Colin Smith
			update_output_window($static_output);
1037
		}
1038 b2a66231 Ermal
		/*
1039
		 * XXX: Otherwise inclusion of config.inc again invalidates actions taken.
1040
		 * 	Same is done during installation.
1041
		 */
1042 f9c8e64c jim-p
		write_config("Intermediate config write during package removal for {$pkg}.");
1043 b2a66231 Ermal
1044
		/*
1045
		 * If a require exists, include it.  this will
1046
		 * show us where an error exists in a package
1047
		 * instead of making us blindly guess
1048 892aef15 Scott Ullrich
		 */
1049 fcf92dae Ermal
		$missing_include = false;
1050 892aef15 Scott Ullrich
		if($pkg_config['include_file'] <> "") {
1051 3ec86ca8 Renato Botelho
			$static_output .= gettext("Loading package instructions...") . "\n";
1052 892aef15 Scott Ullrich
			update_output_window($static_output);
1053 eab543ed Ermal
			pkg_debug("require_once(\"{$pkg_config['include_file']}\")\n");
1054 fcf92dae Ermal
			if (file_exists($pkg_config['include_file']))
1055 1570d27a Ermal Lu?i
				require_once($pkg_config['include_file']);
1056 fcf92dae Ermal
			else {
1057
				$missing_include = true;
1058
				update_output_window($static_output);
1059 7dbbaecd Scott Ullrich
				$static_output .= "Include file " . basename($pkg_config['include_file']) . " could not be found for inclusion.\n";
1060 fcf92dae Ermal
			}
1061
		}
1062
		/* ermal
1063
		 * NOTE: It is not possible to handle parse errors on eval.
1064
		 * So we prevent it from being run at all to not interrupt all the other code.
1065
		 */
1066
		if ($missing_include == false) {
1067
			/* evalate this package's global functions and pre deinstall commands */
1068
			if($pkg_config['custom_php_global_functions'] <> "")
1069
				eval_once($pkg_config['custom_php_global_functions']);
1070
			if($pkg_config['custom_php_pre_deinstall_command'] <> "")
1071
				eval_once($pkg_config['custom_php_pre_deinstall_command']);
1072 43db85f8 Scott Ullrich
		}
1073 3f01fe47 Colin Smith
		/* system files */
1074 fcf92dae Ermal
		if(is_array($pkg_config['modify_system']) && is_array($pkg_config['modify_system']['item'])) {
1075 9d3d8d00 Vinicius Coque
			$static_output .= gettext("System files... ");
1076 3f01fe47 Colin Smith
			update_output_window($static_output);
1077 b2a66231 Ermal
			foreach($pkg_config['modify_system']['item'] as $ms)
1078 3f01fe47 Colin Smith
				if($ms['textneeded']) remove_text_from_file($ms['modifyfilename'], $ms['textneeded']);
1079 b2a66231 Ermal
1080 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
1081 3f01fe47 Colin Smith
			update_output_window($static_output);
1082 407bf67a Colin Smith
		}
1083 644d2d59 Colin Smith
		/* deinstall commands */
1084
		if($pkg_config['custom_php_deinstall_command'] <> "") {
1085 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Deinstall commands... ");
1086 644d2d59 Colin Smith
			update_output_window($static_output);
1087 fcf92dae Ermal
			if ($missing_include == false) {
1088
				eval_once($pkg_config['custom_php_deinstall_command']);
1089 3ec86ca8 Renato Botelho
				$static_output .= gettext("done.") . "\n";
1090 fcf92dae Ermal
			} else
1091 7dbbaecd Scott Ullrich
				$static_output .= "\nNot executing custom deinstall hook because an include is missing.\n";
1092 644d2d59 Colin Smith
			update_output_window($static_output);
1093
		}
1094 1570d27a Ermal Lu?i
		if($pkg_config['include_file'] <> "") {
1095 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Removing package instructions...");
1096 b2b15543 Scott Ullrich
			update_output_window($static_output);
1097 c92ccac7 Vinicius Coque
                        pkg_debug(sprintf(gettext("Remove '%s'"), $pkg_config['include_file']) . "\n");
1098 b2b15543 Scott Ullrich
			unlink_if_exists("/usr/local/pkg/" . $pkg_config['include_file']);
1099 9d3d8d00 Vinicius Coque
			$static_output .= gettext("done.") . "\n";
1100 b2b15543 Scott Ullrich
			update_output_window($static_output);
1101
		}
1102 af8fca8f jim-p
		/* remove all additional files */
1103
		if(is_array($pkg_config['additional_files_needed'])) {
1104 9d3d8d00 Vinicius Coque
			$static_output .= gettext("Auxiliary files... ");
1105 af8fca8f jim-p
			update_output_window($static_output);
1106
			foreach($pkg_config['additional_files_needed'] as $afn) {
1107
				$filename = get_filename_from_url($afn['item'][0]);
1108 b2a66231 Ermal
				if($afn['prefix'] <> "")
1109 af8fca8f jim-p
					$prefix = $afn['prefix'];
1110 b2a66231 Ermal
				else
1111 af8fca8f jim-p
					$prefix = "/usr/local/pkg/";
1112
				unlink_if_exists($prefix . $filename);
1113
			}
1114 6acdf659 Carlos Eduardo Ramos
			$static_output .= gettext("done.") . "\n";
1115 af8fca8f jim-p
			update_output_window($static_output);
1116
		}
1117 047c40c4 Colin Smith
		/* package XML file */
1118 9d3d8d00 Vinicius Coque
		$static_output .= gettext("Package XML... ");
1119 047c40c4 Colin Smith
		update_output_window($static_output);
1120
		unlink_if_exists("/usr/local/pkg/" . $packages[$pkgid]['configurationfile']);
1121 6acdf659 Carlos Eduardo Ramos
		$static_output .= gettext("done.") . "\n";
1122 047c40c4 Colin Smith
		update_output_window($static_output);
1123 407bf67a Colin Smith
	}
1124 2addd5b2 Ermal
	/* syslog */
1125
	if(is_array($pkg_info['logging']) && $pkg_info['logging']['logfile_name'] <> "") {
1126 7dbbaecd Scott Ullrich
		$static_output .= "Syslog entries... ";
1127 2addd5b2 Ermal
		update_output_window($static_output);
1128
		remove_text_from_file("/etc/syslog.conf", $pkg_info['logging']['facilityname'] . "\t\t\t\t" . $pkg_info['logging']['logfilename']);
1129
		system_syslogd_start();
1130
		@unlink("{$g['varlog_path']}/{$pkg_info['logging']['logfilename']}");
1131
		$static_output .= "done.\n";
1132
		update_output_window($static_output);
1133
	}
1134 e9c7a334 Scott Ullrich
	
1135 3339fac0 Ermal Lu?i
	conf_mount_ro();
1136 2addd5b2 Ermal
	/* remove config.xml entries */
1137 9d3d8d00 Vinicius Coque
	$static_output .= gettext("Configuration... ");
1138 407bf67a Colin Smith
	update_output_window($static_output);
1139
	unset($config['installedpackages']['package'][$pkgid]);
1140 6acdf659 Carlos Eduardo Ramos
	$static_output .= gettext("done.") . "\n";
1141 407bf67a Colin Smith
	update_output_window($static_output);
1142 fcf92dae Ermal
	write_config("Removed {$pkg} package.\n");
1143 407bf67a Colin Smith
}
1144 566181ea Colin Smith
1145
function expand_to_bytes($size) {
1146
	$conv = array(
1147
			"G" =>	"3",
1148
			"M" =>  "2",
1149
			"K" =>  "1",
1150
			"B" =>  "0"
1151
		);
1152
	$suffix = substr($size, -1);
1153
	if(!in_array($suffix, array_keys($conv))) return $size;
1154
	$size = substr($size, 0, -1);
1155
	for($i = 0; $i < $conv[$suffix]; $i++) {
1156
		$size *= 1024;
1157
	}
1158
	return $size;
1159
}
1160
1161
function get_pkg_db() {
1162
	global $g;
1163
	return return_dir_as_array($g['vardb_path'] . '/pkg');
1164
}
1165
1166 b8a1c2a3 Colin Smith
function walk_depend($depend, $pkgdb = "", $alreadyseen = "") {
1167 1570d27a Ermal Lu?i
	if(!$pkgdb)
1168
		$pkgdb = get_pkg_db();
1169
	if(!is_array($alreadyseen))
1170
		$alreadyseen = array();
1171
	if (!is_array($depend))
1172
		$depend = array();
1173 566181ea Colin Smith
	foreach($depend as $adepend) {
1174
		$pkgname = reverse_strrchr($adepend['name'], '.');
1175 b8a1c2a3 Colin Smith
		if(in_array($pkgname, $alreadyseen)) {
1176
			continue;
1177
		} elseif(!in_array($pkgname, $pkgdb)) {
1178
			$size += expand_to_bytes($adepend['size']);
1179
			$alreadyseen[] = $pkgname;
1180
			if(is_array($adepend['depend'])) $size += walk_depend($adepend['depend'], $pkgdb, $alreadyseen);
1181
		}
1182 566181ea Colin Smith
	}
1183
	return $size;
1184
}
1185
1186
function get_package_install_size($pkg = 'all', $pkg_info = "") {
1187
	global $config, $g;
1188 1570d27a Ermal Lu?i
	if((!is_array($pkg)) and ($pkg != 'all'))
1189
		$pkg = array($pkg);
1190 566181ea Colin Smith
	$pkgdb = get_pkg_db();
1191 1570d27a Ermal Lu?i
	if(!$pkg_info)
1192
		$pkg_info = get_pkg_sizes($pkg);
1193 566181ea Colin Smith
	foreach($pkg as $apkg) {
1194 2addd5b2 Ermal
		if(!$pkg_info[$apkg])
1195
			continue;
1196 b8a1c2a3 Colin Smith
		$toreturn[$apkg] = expand_to_bytes(walk_depend(array($pkg_info[$apkg]), $pkgdb));
1197 566181ea Colin Smith
	}
1198 b8a1c2a3 Colin Smith
	return $toreturn;
1199 566181ea Colin Smith
}
1200 f0a550fd Colin Smith
1201 e43ba9ad Colin Smith
function squash_from_bytes($size, $round = "") {
1202 f0a550fd Colin Smith
	$conv = array(1 => "B", "K", "M", "G");
1203
	foreach($conv as $div => $suffix) {
1204
		$sizeorig = $size;
1205
		if(($size /= 1024) < 1) {
1206 e43ba9ad Colin Smith
			if($round) {
1207
				$sizeorig = round($sizeorig, $round);
1208
			}
1209 f0a550fd Colin Smith
			return $sizeorig . $suffix;
1210
		}
1211
	}
1212
	return;
1213
}
1214 5025a56c Scott Ullrich
1215 9b193619 Scott Ullrich
function pkg_reinstall_all() {
1216
	global $g, $config;
1217 c53eb903 Ermal
1218
	@unlink('/conf/needs_package_sync');
1219 9b193619 Scott Ullrich
	$pkg_id = 0;
1220
	$todo = array();
1221
	if (is_array($config['installedpackages']['package']))
1222
		foreach($config['installedpackages']['package'] as $package)
1223
			$todo[] = array('name' => $package['name'], 'version' => $package['version']);
1224
	echo "One moment please, reinstalling packages...\n";
1225 ad0d6389 jim-p
	echo " >>> Trying to fetch package info...";
1226
	$pkg_info = get_pkg_info();
1227
	if ($pkg_info) {
1228
		echo " Done.\n";
1229
	} else {
1230
		$xmlrpc_base_url = isset($config['system']['altpkgrepo']['enable']) ? $config['system']['altpkgrepo']['xmlrpcbaseurl'] : $g['xmlrpcbaseurl'];
1231
		echo "\n" . sprintf(gettext(' >>> Unable to communicate with %1$s. Please verify DNS and interface configuration, and that %2$s has functional Internet connectivity.'), $xmlrpc_base_url, $g['product_name']) . "\n";
1232
		return;
1233
	}
1234 9b193619 Scott Ullrich
	if(is_array($todo)) {
1235
		foreach($todo as $pkgtodo) {
1236
			$static_output = "";
1237
			if($pkgtodo['name']) {
1238
				uninstall_package($pkgtodo['name']);
1239
				install_package($pkgtodo['name']);
1240
				$pkg_id++;
1241
			}
1242
		}
1243
	}
1244
}
1245
1246 6955830f Ermal Lu?i
?>