Project

General

Profile

Download (40.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/****h* pfSense/pkg-utils
3
 * NAME
4
 *   pkg-utils.inc - Package subsystem
5
 * DESCRIPTION
6
 *   This file contains various functions used by the pfSense package system.
7
 * HISTORY
8
 *   $Id$
9
 ******
10
 *
11
 * Copyright (C) 2010 Ermal Lu?i
12
 * Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
13
 * 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

    
37
/*
38
	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
	pfSense_MODULE:	pkg
41
*/
42

    
43
require_once("globals.inc");
44
require_once("xmlrpc.inc");
45
if(file_exists("/cf/conf/use_xmlreader"))
46
	require_once("xmlreader.inc");
47
else
48
	require_once("xmlparse.inc");
49
require_once("service-utils.inc");
50
require_once("pfsense-utils.inc");
51

    
52
if(!function_exists("update_status")) {
53
	function update_status($status) {
54
		echo $status . "\n";
55
	}
56
}
57
if(!function_exists("update_output_window")) {
58
	function update_output_window($status) {
59
		echo $status . "\n";
60
	}
61
}
62

    
63
if (!function_exists("pkg_debug")) {
64
	/* set up logging if needed */
65
	function pkg_debug($msg) {
66
		global $g, $debug, $fd_log;
67

    
68
		if (!$debug)
69
			return;
70

    
71
		if (!$fd_log) {
72
			if (!$fd_log = fopen("{$g['tmp_path']}/pkg_mgr_{$package}.log", "w"))
73
				update_output_window("Warning, could not open log for writing.");
74
		}
75
		@fwrite($fd_log, $msg);
76
	}
77
}
78

    
79
$vardb = "/var/db/pkg";
80
safe_mkdir($vardb);
81
$g['platform'] = trim(file_get_contents("/etc/platform"));
82

    
83
conf_mount_rw();
84
if(!is_dir("/usr/local/pkg") or !is_dir("/usr/local/pkg/pf")) {
85
	safe_mkdir("/usr/local/pkg");
86
	safe_mkdir("/usr/local/pkg/pf");	
87
}
88
conf_mount_ro();
89

    
90
/****f* pkg-utils/remove_package
91
 * NAME
92
 *   remove_package - Removes package from FreeBSD if it exists
93
 * INPUTS
94
 *   $packagestring	- name/string to check for
95
 * RESULT
96
 *   none
97
 * NOTES
98
 *   
99
 ******/
100
function remove_freebsd_package($packagestring) {
101
	exec("/usr/sbin/pkg_delete -x {$packagestring} 2>>/tmp/pkg_delete_errors.txt");
102
}
103

    
104
/****f* pkg-utils/is_package_installed
105
 * NAME
106
 *   is_package_installed - Check whether a package is installed.
107
 * INPUTS
108
 *   $packagename	- name of the package to check
109
 * RESULT
110
 *   boolean	- true if the package is installed, false otherwise
111
 * NOTES
112
 *   This function is deprecated - get_pkg_id() can already check for installation.
113
 ******/
114
function is_package_installed($packagename) {
115
	$pkg = get_pkg_id($packagename);
116
	if($pkg == -1)
117
		return false;
118
	return true;
119
}
120

    
121
/****f* pkg-utils/get_pkg_id
122
 * NAME
123
 *   get_pkg_id - Find a package's numeric ID.
124
 * INPUTS
125
 *   $pkg_name	- name of the package to check
126
 * RESULT
127
 *   integer    - -1 if package is not found, >-1 otherwise
128
 ******/
129
function get_pkg_id($pkg_name) {
130
	global $config;
131

    
132
	if (is_array($config['installedpackages']['package'])) {
133
		foreach($config['installedpackages']['package'] as $idx => $pkg) {
134
			if($pkg['name'] == $pkg_name)
135
				return $idx;
136
		}
137
	}
138
	return -1;
139
}
140

    
141
/****f* pkg-utils/get_pkg_info
142
 * NAME
143
 *   get_pkg_info - Retrive package information from pfsense.com.
144
 * INPUTS
145
 *   $pkgs - 'all' to retrive all packages, an array containing package names otherwise
146
 *   $info - 'all' to retrive all information, an array containing keys otherwise
147
 * RESULT
148
 *   $raw_versions - Array containing retrieved information, indexed by package name.
149
 ******/
150
function get_pkg_info($pkgs = 'all', $info = 'all') {
151
	global $g;
152

    
153
	$freebsd_version = php_uname("r");
154
	$freebsd_machine = php_uname("m");
155
	$params = array(
156
		"pkg" => $pkgs, 
157
		"info" => $info, 
158
		"freebsd_version" => $freebsd_version[0],
159
		"freebsd_machine" => $freebsd_machine
160
	);
161
	$resp = call_pfsense_method('pfsense.get_pkgs', $params, 10);
162
	return $resp ? $resp : array();
163
}
164

    
165
function get_pkg_sizes($pkgs = 'all') {
166
	global $config, $g;
167

    
168
	$freebsd_version = php_uname("r");
169
	$freebsd_machine = php_uname("m");
170
	$params = array(
171
		"pkg" => $pkgs, 
172
		"freebsd_version" => $freebsd_version,
173
		"freebsd_machine" => $freebsd_machine
174
	);
175
	$msg = new XML_RPC_Message('pfsense.get_pkg_sizes', array(php_value_to_xmlrpc($params)));
176
	$xmlrpc_base_url = isset($config['system']['altpkgrepo']['enable']) ? $config['system']['altpkgrepo']['xmlrpcbaseurl'] : $g['xmlrpcbaseurl'];
177
	$cli = new XML_RPC_Client($g['xmlrpcpath'], $xmlrpc_base_url);
178
	$resp = $cli->send($msg, 10);
179
	if(!is_object($resp))
180
		log_error("Could not get response from XMLRPC server!");
181
 	else if (!$resp->faultCode()) {
182
		$raw_versions = $resp->value();
183
		return xmlrpc_value_to_php($raw_versions);
184
	}
185

    
186
	return array();
187
}
188

    
189
/*
190
 * resync_all_package_configs() Force packages to setup their configuration and rc.d files.
191
 * This function may also print output to the terminal indicating progress.
192
 */
193
function resync_all_package_configs($show_message = false) {
194
	global $config, $pkg_interface, $g;
195

    
196
	log_error("Resyncing configuration for all packages.");
197

    
198
	if (!is_array($config['installedpackages']['package']))
199
		return;
200

    
201
	if($show_message == true)
202
		echo "Syncing packages:";
203

    
204
	conf_mount_rw();
205

    
206
	foreach($config['installedpackages']['package'] as $idx => $package) {
207
		if (empty($package['name']))
208
			continue;
209
		if($show_message == true)
210
			echo " " . $package['name'];
211
		get_pkg_depends($package['name'], "all");
212
		if($g['booting'] != true)
213
			stop_service($package['name']);
214
		sync_package($idx, true, true);
215
		if($pkg_interface == "console") 
216
			echo "\nSyncing packages:";
217
	}
218

    
219
	if($show_message == true)
220
		echo " done.\n";
221

    
222
	@unlink("/conf/needs_package_sync");
223
	conf_mount_ro();
224
}
225

    
226
/*
227
 * is_freebsd_pkg_installed() - Check /var/db/pkg to determine whether or not a FreeBSD
228
 *				package is installed.
229
 */
230
function is_freebsd_pkg_installed($pkg) {
231
	if(!$pkg) 
232
		return;
233
	$output = "";
234
	exec("/usr/sbin/pkg_info -E \"{$pkg}*\"", $output, $retval);
235

    
236
	return (intval($retval) == 0);
237
}
238

    
239
/*
240
 * get_pkg_depends($pkg_name, $filetype = ".xml", $format = "files", return_nosync = 1):  Return a package's dependencies.
241
 *
242
 * $filetype = "all" || ".xml", ".tgz", etc.
243
 * $format = "files" (full filenames) || "names" (stripped / parsed depend names)
244
 * $return_nosync = 1 (return depends that have nosync set) | 0 (ignore packages with nosync)
245
 *
246
 */
247
function get_pkg_depends($pkg_name, $filetype = ".xml", $format = "files", $return_nosync = 1) {
248
	global $config;
249

    
250
	$pkg_id = get_pkg_id($pkg_name);
251
	if($pkg_id == -1)
252
		return -1; // This package doesn't really exist - exit the function.
253
	else if (!isset($config['installedpackages']['package'][$pkg_id]))
254
		return; // No package belongs to the pkg_id passed to this function.
255

    
256
	$package =& $config['installedpackages']['package'][$pkg_id];
257
	if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
258
		log_error("The {$package['name']} package is missing required dependencies and is being reinstalled." . $package['configurationfile']);
259
		uninstall_package($package['name']);
260
		if (install_package($package['name']) < 0) {
261
			log_error("Failed reinstalling package {$package['name']}.");
262
			return false;
263
		}
264
	}
265
	$pkg_xml = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
266
	if (!empty($pkg_xml['additional_files_needed'])) {
267
		foreach($pkg_xml['additional_files_needed'] as $item) {
268
			if ($return_nosync == 0 && isset($item['nosync']))
269
				continue; // Do not return depends with nosync set if not required.
270
			$depend_file = substr(strrchr($item['item']['0'], '/'),1); // Strip URLs down to filenames.
271
			$depend_name = substr(substr($depend_file,0,strpos($depend_file,".")+1),0,-1); // Strip filename down to dependency name.
272
			if (($filetype != "all") && (!preg_match("/{$filetype}/i", $depend_file)))
273
					continue;
274
			if ($item['prefix'] != "")
275
				$prefix = $item['prefix'];
276
			else
277
				$prefix = "/usr/local/pkg/";
278
			// Ensure that the prefix exists to avoid installation errors.
279
			if(!is_dir($prefix)) 
280
				exec("/bin/mkdir -p {$prefix}");
281
			if(!file_exists($prefix . $depend_file))
282
				log_error("The {$package['name']} package is missing required dependencies and must be reinstalled.");
283
			switch ($format) {
284
			case "files":
285
				$depends[] = $prefix . $depend_file;
286
				break;
287
			case "names":
288
				switch ($filetype) {
289
				case "all":
290
					if(preg_match("/\.xml/i", $depend_file)) {
291
						$depend_xml = parse_xml_config_pkg("/usr/local/pkg/{$depend_file}", "packagegui");
292
						if (!empty($depend_xml))
293
							$depends[] = $depend_xml['name'];
294
					} else
295
						$depends[] = $depend_name; // If this dependency isn't package XML, use the stripped filename.
296
					break;
297
				case ".xml":
298
					$depend_xml = parse_xml_config_pkg("/usr/local/pkg/" . $depend_file, "packagegui");
299
					if (!empty($depend_xml))
300
						$depends[] = $depend_xml['name'];
301
					break;
302
				default:
303
					$depends[] = $depend_name; // If we aren't looking for XML, use the stripped filename (it's all we have).
304
					break;
305
				}
306
			}
307
		}
308
		return $depends;
309
	}
310
}
311

    
312
function uninstall_package($pkg_name) {
313
	global $config, $static_output;
314
	global $builder_package_install;
315

    
316
	// Back up /usr/local/lib libraries first if
317
	// not running from the builder code.
318
	if(!$builder_package_install) {
319
		if(!file_exists("/tmp/pkg_libs.tgz")) {
320
			$static_output .= "Backing up libraries... ";
321
			update_output_window($static_output);
322
			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`");
323
			$static_output .= "\n";
324
		}
325
	}
326

    
327
	$id = get_pkg_id($pkg_name);
328
	if ($id >= 0) {
329
		$pkg_depends =& $config['installedpackages']['package'][$id]['depends_on_package'];
330
		$static_output .= "Removing package...\n";
331
		update_output_window($static_output);
332
		if (is_array($pkg_depends)) {
333
			foreach ($pkg_depends as $pkg_depend)
334
				delete_package($pkg_depend);
335
		}
336
	}
337
	delete_package_xml($pkg_name);
338

    
339
	// Restore libraries that we backed up if not 
340
	// running from the builder code.
341
	if(!$builder_package_install) {
342
		$static_output .= "Cleaning up... ";
343
		update_output_window($static_output);
344
		exec("/usr/bin/tar xzPfU /tmp/pkg_libs.tgz -C /");
345
		@unlink("/tmp/pkg_libs.tgz");	
346
	}
347
}
348

    
349
function force_remove_package($pkg_name) {
350
	delete_package_xml($pkg_name);
351
}
352

    
353
/*
354
 * sync_package($pkg_name, $sync_depends = true, $show_message = false) Force a package to setup its configuration and rc.d files.
355
 */
356
function sync_package($pkg_name, $sync_depends = true, $show_message = false) {
357
	global $config, $config_parsed;
358
	global $builder_package_install;
359
	
360
	// If this code is being called by pfspkg_installer 
361
	// which the builder system uses then return (ignore).
362
	if($builder_package_install)
363
		return;
364
	
365
	if(empty($config['installedpackages']['package']))
366
		return;
367
	if(!is_numeric($pkg_name)) {
368
		$pkg_id = get_pkg_id($pkg_name);
369
		if($pkg_id == -1)
370
			return -1; // This package doesn't really exist - exit the function.
371
	} else {
372
		$pkg_id = $pkg_name;
373
		if(empty($config['installedpackages']['package'][$pkg_id]))
374
			return;  // No package belongs to the pkg_id passed to this function.
375
	}
376
        if (is_array($config['installedpackages']['package'][$pkg_id]))
377
		$package =& $config['installedpackages']['package'][$pkg_id];
378
        else
379
		return; /* empty package tag */
380
	if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
381
		log_error("The {$package['name']} package is missing its configuration file and must be reinstalled.");
382
		force_remove_package($package['name']);
383
		return -1;
384
	}
385
	$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
386
	if(isset($pkg_config['nosync']))
387
		return;
388
	/* Bring in package include files */
389
	if (!empty($pkg_config['include_file'])) {
390
		$include_file = $pkg_config['include_file'];
391
		if (file_exists($include_file))
392
			require_once($include_file);
393
		else {
394
			/* XXX: What the heck is this?! */
395
			log_error("Reinstalling package {$package['name']} because its include file({$include_file}) is missing!");
396
			uninstall_package($package['name']);
397
			if (install_package($package['name']) < 0) {
398
				log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!");
399
				return -1;
400
			}
401
		}
402
	}
403

    
404
	if(!empty($pkg_config['custom_php_global_functions']))
405
		eval($pkg_config['custom_php_global_functions']);
406
	if(!empty($pkg_config['custom_php_resync_config_command']))
407
		eval($pkg_config['custom_php_resync_config_command']);
408
	if($sync_depends == true) {
409
		$depends = get_pkg_depends($pkg_name, ".xml", "files", 1); // Call dependency handler and do a little more error checking.
410
		if(is_array($depends)) {
411
			foreach($depends as $item) {
412
				if(!file_exists($item)) {
413
					require_once("notices.inc");
414
					file_notice($package['name'], "The {$package['name']} package is missing required dependencies and must be reinstalled.", "Packages", "/pkg_mgr_install.php?mode=reinstallpkg&pkg={$package['name']}", 1);
415
					log_error("Could not find {$item}. Reinstalling package.");
416
					uninstall_package($pkg_name);
417
					if (install_package($pkg_name) < 0) {
418
						log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!");
419
						return -1;
420
					}
421
				} else {
422
					$item_config = parse_xml_config_pkg($item, "packagegui");
423
					if (empty($item_config))
424
						continue;
425
					if(isset($item_config['nosync']))
426
						continue;
427
					if (!empty($item_config['include_file'])) {
428
						if (file_exists($item_config['include_file']))	
429
							require_once($item_config['include_file']);
430
						else {
431
							log_error("Not calling package sync code for dependency {$item_config['name']} of {$package['name']} because some include files are missing.");
432
							continue;
433
						}
434
					}
435
					if($item_config['custom_php_global_functions'] <> "")
436
						eval($item_config['custom_php_global_functions']);
437
					if($item_config['custom_php_resync_config_command'] <> "")
438
						eval($item_config['custom_php_resync_config_command']);
439
					if($show_message == true)
440
						print " " . $item_config['name'];
441
				}
442
			}
443
		}
444
	}
445
}
446

    
447
/*
448
 * pkg_fetch_recursive: Download and install a FreeBSD package and its dependencies. This function provides output to
449
 * 			a progress bar and output window.
450
 */
451
function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = "") {
452
	global $static_output, $g;
453

    
454
	$osname = php_uname("s");
455
	$arch =  php_uname("m");
456
	$rel = strtolower(php_uname("r"));
457
	if (substr_count($rel, '-') > 1)
458
		$rel = substr($rel, 0, strrpos($rel, "-"));
459
	$priv_url = "http://ftp2.{$osname}.org/pub/{$osname}/ports/{$arch}/packages-{$rel}/All";
460
	if (empty($base_url))
461
		$base_url = $priv_url;
462
	if (substr($base_url, -1) == "/")
463
		$base_url = substr($base_url, 0, -1);
464
	$fetchto = "{$g['tmp_path']}/apkg_{$filename}";
465
	$static_output .= "\n" . str_repeat(" ", $dependlevel * 2 + 1) . "Downloading {$base_url}/{$filename} ... ";
466
	if (download_file_with_progress_bar("{$base_url}/{$filename}", $fetchto) !== true) {
467
		if ($base_url != $priv_url && download_file_with_progress_bar("{$priv_url}/{$filename}", $fetchto) !== true) {
468
			$static_output .= " could not download from there or {$priv_url}/{$filename}.\n";
469
			update_output_window($static_output);
470
			return false;
471
		} else if ($base_url == $priv_url) {
472
			$static_output .= " failed to download.\n";
473
			update_output_window($static_output);
474
			return false;
475
		} else {
476
			$static_output .= " [{$osname} repository]\n";
477
			update_output_window($static_output);
478
		}
479
	}
480
	$static_output .= " (extracting)";
481
	update_output_window($static_output);
482
	$slaveout = "";
483
	exec("/usr/bin/tar --fast-read -O -f {$fetchto} -x +CONTENTS 2>&1", $slaveout);
484
	$raw_depends_list = array_values(preg_grep("/\@pkgdep/", $slaveout));
485
	if ($raw_depends_list != "") {
486
		$pkg_extension = ".tbz";
487
		foreach($raw_depends_list as $adepend) {
488
			$working_depend = explode(" ", trim($adepend, "\n"));
489
			if (substr($working_depend[1], -4) != ".tbz")
490
				$depend_filename = $working_depend[1] . $pkg_extension;
491
			else
492
				$depend_filename = $working_depend[1];
493
			if (!is_freebsd_pkg_installed($working_depend[1])) {
494
				if (pkg_fetch_recursive($working_depend[1], $depend_filename, $dependlevel + 1, $base_url) == false)
495
					return false;
496
			} else {
497
				pkg_debug($working_depend[1] . "\n");
498
			}
499
		}
500
	}
501
	$pkgaddout = "";
502
	exec("/usr/sbin/pkg_add -fv {$fetchto} 2>&1", $pkgaddout);
503
	pkg_debug($pkgname . " " . print_r($pkgaddout, true) . "\npkg_add successfully completed.\n");
504

    
505
	return true;
506
}
507

    
508
function install_package($package, $pkg_info = "") {
509
	global $g, $config, $static_output, $pkg_interface;
510

    
511
	/* safe side. Write config below will send to ro again. */
512
	conf_mount_rw();
513

    
514
	if($pkg_interface == "console") 	
515
		echo "\n";
516
	/* fetch package information if needed */
517
	if(empty($pkg_info) or !is_array($pkg_info[$package])) {
518
		$pkg_info = get_pkg_info(array($package));
519
		$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
520
		if (empty($pkg_info)) {
521
			conf_mount_ro();
522
			return -1;
523
		}
524
	}
525
	pkg_debug("Beginning package installation.\n");
526
	log_error('Beginning package installation for ' . $pkg_info['name'] . '.');
527
	$static_output .= "Beginning package installation for " . $pkg_info['name'] . "...";
528
	update_status($static_output);
529
	/* fetch the package's configuration file */
530
	if($pkg_info['config_file'] != "") {
531
		$static_output .= "\nDownloading package configuration file... ";
532
		update_output_window($static_output);
533
		pkg_debug("Downloading package configuration file...\n");
534
		$fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1);
535
		download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto);
536
		if(!file_exists('/usr/local/pkg/' . $fetchto)) {
537
			pkg_debug("ERROR! Unable to fetch package configuration file. Aborting installation.\n");
538
			if($pkg_interface == "console")
539
				print "\nERROR! Unable to fetch package configuration file. Aborting package installation.\n";
540
			else {
541
				$static_output .= "failed!\n\nInstallation aborted.\n";
542
				update_output_window($static_output);
543
				echo "<br>Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>";
544
			}
545
			conf_mount_ro();
546
			return -1;
547
		}
548
		$static_output .= "done.\n";
549
		update_output_window($static_output);
550
	}
551
	/* add package information to config.xml */
552
	$pkgid = get_pkg_id($pkg_info['name']);
553
	$static_output .= "Saving updated package information... ";
554
	update_output_window($static_output);
555
	if($pkgid == -1) {
556
		$config['installedpackages']['package'][] = $pkg_info;
557
		$changedesc = "Installed {$pkg_info['name']} package.";
558
		$to_output = "done.\n";
559
	} else {
560
		$config['installedpackages']['package'][$pkgid] = $pkg_info;
561
		$changedesc = "Overwrote previous installation of {$pkg_info['name']}.";
562
		$to_output = "overwrite!\n";
563
	}
564
	if(file_exists('/conf/needs_package_sync'))
565
		@unlink('/conf/needs_package_sync');
566
	conf_mount_ro();
567
	write_config("Intermediate config write during package install for {$pkg_info['name']}.");
568
	$static_output .= $to_output;
569
	update_output_window($static_output);
570
	/* install other package components */
571
	if (!install_package_xml($package)) {
572
		uninstall_package($package);
573
		write_config($changedesc);
574
		$static_output .= "Failed to install package.\n";
575
		update_output_window($static_output);
576
		return -1;
577
	} else {
578
		$static_output .= "Writing configuration... ";
579
		update_output_window($static_output);
580
		write_config($changedesc);
581
		$static_output .= "done.\n";
582
		update_output_window($static_output);
583
		$static_output .= "Starting service.\n";
584
		update_output_window($static_output);
585
		if($pkg_info['after_install_info']) 
586
			update_output_window($pkg_info['after_install_info']);	
587
	}
588
}
589

    
590
function get_after_install_info($package) {
591
	global $pkg_info;
592
	/* fetch package information if needed */
593
	if(!$pkg_info or !is_array($pkg_info[$package])) {
594
		$pkg_info = get_pkg_info(array($package));
595
		$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
596
	}
597
	if($pkg_info['after_install_info'])
598
		return $pkg_info['after_install_info'];
599
}
600

    
601
function eval_once($toeval) {
602
	global $evaled;
603
	if(!$evaled) $evaled = array();
604
	$evalmd5 = md5($toeval);
605
	if(!in_array($evalmd5, $evaled)) {
606
		@eval($toeval);
607
		$evaled[] = $evalmd5;
608
	}
609
	return;
610
}
611

    
612
function install_package_xml($pkg) {
613
	global $g, $config, $static_output, $pkg_interface, $config_parsed;
614

    
615
	if(($pkgid = get_pkg_id($pkg)) == -1) {
616
		$static_output .= "The {$pkg} package is not installed.\n\nInstallation aborted.";
617
		update_output_window($static_output);
618
		if($pkg_interface <> "console") {
619
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
620
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
621
		}
622
		sleep(1);
623
		return false;
624
	} else
625
		$pkg_info = $config['installedpackages']['package'][$pkgid];
626

    
627
	/* pkg_add the package and its dependencies */
628
	if($pkg_info['depends_on_package_base_url'] != "") {
629
		if($pkg_interface == "console") 
630
			echo "\n";
631
		update_status("Installing " . $pkg_info['name'] . " and its dependencies.");
632
		$static_output .= "Downloading " . $pkg_info['name'] . " and its dependencies... ";
633
		$static_orig = $static_output;
634
		$static_output .= "\n";
635
		update_output_window($static_output);
636
		foreach((array) $pkg_info['depends_on_package'] as $pkgdep) {
637
			$pkg_name = substr(reverse_strrchr($pkgdep, "."), 0, -1);
638
			$static_output = $static_orig . "\nChecking for package installation... ";
639
			update_output_window($static_output);
640
			if (!is_freebsd_pkg_installed($pkg_name)) {
641
				if (!pkg_fetch_recursive($pkg_name, $pkgdep, 0, $pkg_info['depends_on_package_base_url'])) {
642
					$static_output .= "of {$pkg_name} failed!\n\nInstallation aborted.";
643
					update_output_window($static_output);
644
					pkg_debug("Package WAS NOT installed properly.\n");
645
					if($pkg_interface <> "console") {
646
						echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
647
						echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
648
					}
649
					sleep(1);
650
					return false;
651
				}
652
			}
653
		}
654
	}
655
	$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1);
656
	if(file_exists("/usr/local/pkg/" . $configfile)) {
657
		$static_output .= "Loading package configuration... ";
658
		update_output_window($static_output);
659
		$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $configfile, "packagegui");
660
		$static_output .= "done.\n";
661
		update_output_window($static_output);
662
		$static_output .= "Configuring package components...\n";
663
		if (!empty($pkg_config['filter_rules_needed']))
664
			$config['installedpackages']['package'][$pkgid]['filter_rule_function'] = $pkg_config['filter_rules_needed'];
665
		update_output_window($static_output);
666
		/* modify system files */
667
		if(is_array($pkg_config['modify_system']) && is_array($pkg_config['modify_system']['item'])) {
668
			$static_output .= "System files... ";
669
			update_output_window($static_output);
670
			foreach($pkg_config['modify_system']['item'] as $ms) {
671
				if($ms['textneeded']) {
672
					add_text_to_file($ms['modifyfilename'], $ms['textneeded']);
673
				}
674
			}
675
			$static_output .= "done.\n";
676
			update_output_window($static_output);
677
		}
678
		/* download additional files */
679
		if(is_array($pkg_config['additional_files_needed'])) {
680
			$static_output .= "Additional files... ";
681
			$static_orig = $static_output;
682
			update_output_window($static_output);
683
			foreach($pkg_config['additional_files_needed'] as $afn) {
684
				$filename = get_filename_from_url($afn['item'][0]);
685
				if($afn['chmod'] <> "")
686
					$pkg_chmod = $afn['chmod'];
687
				else
688
					$pkg_chmod = "";
689

    
690
				if($afn['prefix'] <> "")
691
					$prefix = $afn['prefix'];
692
				else
693
					$prefix = "/usr/local/pkg/";
694

    
695
				if(!is_dir($prefix)) 
696
					safe_mkdir($prefix);
697
 				$static_output .= $filename . " ";
698
				update_output_window($static_output);
699
				if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) {
700
					$static_output .= "failed.\n";
701
					update_output_window($static_output);
702
					return false;
703
				}
704
				if(stristr($filename, ".tgz") <> "") {
705
					pkg_debug("Extracting tarball to -C for " . $filename . "...\n");
706
					$tarout = "";
707
					exec("/usr/bin/tar xvzf " . $prefix . $filename . " -C / 2>&1", $tarout);
708
					pkg_debug(print_r($tarout, true) . "\n");
709
				}
710
				if($pkg_chmod <> "") {
711
					pkg_debug("Changing file mode to {$pkg_chmod} for {$prefix}{$filename}\n");
712
					@chmod($prefix . $filename, $pkg_chmod);
713
					system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
714
				}
715
				$static_output = $static_orig;
716
                                update_output_window($static_output);
717
			}
718
			$static_output .= "done.\n";
719
			update_output_window($static_output);
720
		}
721
		/*   if a require exists, include it.  this will
722
		 *   show us where an error exists in a package
723
		 *   instead of making us blindly guess
724
		 */
725
		$missing_include = false;
726
		if($pkg_config['include_file'] <> "") {
727
			$static_output .= "Loading package instructions...\n";
728
			update_output_window($static_output);
729
			pkg_debug("require_once('{$pkg_config['include_file']}')\n");
730
			if (file_exists($pkg_config['include_file']))
731
				require_once($pkg_config['include_file']);
732
			else {
733
				$missing_include = true;
734
				$static_output .= "Include " . basename($pkg_config['include_file']) . " is missing!\n";
735
				update_output_window($static_output);
736
				/* XXX: Should undo the steps before this?! */
737
				return false;
738
			}
739
		}
740
		/* sidebar items */
741
		if(is_array($pkg_config['menu'])) {
742
			$static_output .= "Menu items... ";
743
			update_output_window($static_output);
744
			foreach($pkg_config['menu'] as $menu) {
745
				if(is_array($config['installedpackages']['menu']))
746
					foreach($config['installedpackages']['menu'] as $amenu)
747
						if($amenu['name'] == $menu['name'])
748
							continue 2;
749
				$config['installedpackages']['menu'][] = $menu;
750
			}
751
			$static_output .= "done.\n";
752
			update_output_window($static_output);
753
		}
754
		/* integrated tab items */
755
		if(is_array($pkg_config['tabs']['tab'])) {
756
			$static_output .= "Integrated Tab items... ";
757
			update_output_window($static_output);
758
			foreach($pkg_config['tabs']['tab'] as $tab) {
759
				if(is_array($config['installedpackages']['tab']))
760
					foreach($config['installedpackages']['tab'] as $atab)
761
						if($atab['name'] == $tab['name'])
762
							continue 2;
763
				$config['installedpackages']['tab'][] = $tab;
764
			}
765
			$static_output .= "done.\n";
766
			update_output_window($static_output);
767
		}
768
		/* services */
769
		if(is_array($pkg_config['service'])) {
770
			$static_output .= "Services... ";
771
			update_output_window($static_output);
772
			foreach($pkg_config['service'] as $service) {
773
				if(is_array($config['installedpackages']['service']))
774
					foreach($config['installedpackages']['service'] as $aservice)
775
						if($aservice['name'] == $service['name'])
776
							continue 2;
777
				$config['installedpackages']['service'][] = $service;
778
			}
779
			$static_output .= "done.\n";
780
			update_output_window($static_output);
781
		}
782
		/* custom commands */
783
		$static_output .= "Custom commands...\n";
784
		update_output_window($static_output);
785
		if ($missing_include == false) {
786
			if($pkg_config['custom_php_global_functions'] <> "") {
787
				$static_output .= "Executing custom_php_global_functions()...";
788
				update_output_window($static_output);
789
				eval_once($pkg_config['custom_php_global_functions']);
790
				$static_output .= "done.\n";
791
				update_output_window($static_output);
792
			}
793
			if($pkg_config['custom_php_install_command']) {
794
				$static_output .= "Executing custom_php_install_command()...";
795
				update_output_window($static_output);
796
				eval_once($pkg_config['custom_php_install_command']);
797
				$static_output .= "done.\n";
798
				update_output_window($static_output);
799
			}
800
			if($pkg_config['custom_php_resync_config_command'] <> "") {
801
				$static_output .= "Executing custom_php_resync_config_command()...";
802
				update_output_window($static_output);
803
				eval_once($pkg_config['custom_php_resync_config_command']);
804
				$static_output .= "done.\n";
805
				update_output_window($static_output);
806
			}
807
		}
808
	} else {
809
		$static_output .= "Loading package configuration... failed!\n\nInstallation aborted.";
810
		update_output_window($static_output);
811
		pkg_debug("Unable to load package configuration. Installation aborted.\n");
812
		if($pkg_interface <> "console") {
813
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
814
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
815
		}
816
		sleep(1);
817
		return false;
818
	}
819

    
820
	/* set up package logging streams */
821
	if($pkg_info['logging']) {
822
		mwexec("/usr/sbin/fifolog_create -s 32768 {$g['varlog_path']}/{$pkg_info['logging']['logfilename']}");
823
		@chmod($g['varlog_path'] . '/' . $pkg_info['logging']['logfilename'], 0600);
824
		add_text_to_file("/etc/syslog.conf", $pkg_info['logging']['facilityname'] . "\t\t\t\t" . $pkg_info['logging']['logfilename']);
825
		pkg_debug("Adding text to file /etc/syslog.conf\n");
826
		system_syslogd_start();
827
	}
828

    
829
	return true;
830
}
831

    
832
function does_package_depend($pkg) {
833
	// Should not happen, but just in case.
834
	if(!$pkg)
835
		return;
836
	$pkg_var_db_dir = glob("/var/db/pkg/{$pkg}*");
837
	// If this package has dependency then return true
838
	foreach($pkg_var_db_dir as $pvdd) {
839
		if (file_exists("{$vardb}/{$pvdd}/+REQUIRED_BY") && count(file("{$vardb}/{$pvdd}/+REQUIRED_BY")) > 0) 
840
			return true;
841
	}	
842
	// Did not find a record of dependencies, so return false.
843
	return false;
844
}
845

    
846
function delete_package($pkg) {
847
	global $config, $g, $static_output, $vardb;
848

    
849
	if(!$pkg) 
850
		return;
851

    
852
	$pkg = substr(reverse_strrchr($pkg, "."), 0, -1);
853

    
854
	// If package has dependencies then skip it
855
	if(does_package_depend($pkg)) {
856
		$static_output .= "Skipping package deletion for {$pkg} because it is a dependency.\n";
857
		update_output_window($static_output);
858
		return;		
859
	} else {
860
		if($pkg)
861
			$static_output .= "Starting package deletion for {$pkg}...";
862
		update_output_window($static_output);		
863
	}
864

    
865
	$info = "";
866
	exec("/usr/sbin/pkg_info -qrx {$pkg}", $info);
867
	remove_freebsd_package($pkg);
868
	$static_output .= "done.\n";
869
	update_output_window($static_output);
870
	foreach($info as $line) {
871
		$depend = trim(str_replace("@pkgdep ", "", $line), " \n");
872
		// If package has dependencies then skip it
873
		if(!does_package_depend($depend)) 			
874
			delete_package($depend);
875
	}
876

    
877
	/* Rescan directories for what has been left and avoid fooling other programs. */
878
	mwexec("/sbin/ldconfig");
879

    
880
	return;
881
}
882

    
883
function delete_package_xml($pkg) {
884
	global $g, $config, $static_output, $pkg_interface;
885

    
886
	conf_mount_rw();
887

    
888
	$pkgid = get_pkg_id($pkg);
889
	if ($pkgid == -1) {
890
		$static_output .= "The {$pkg} package is not installed.\n\nDeletion aborted.";
891
		update_output_window($static_output);
892
		if($pkg_interface <> "console") {
893
			echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
894
			echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
895
		}
896
		ob_flush();
897
		sleep(1);
898
		conf_mount_ro();
899
		return;
900
	}
901
	pkg_debug("Removing {$pkg} package... ");
902
	$static_output .= "Removing {$pkg} components...\n";
903
	update_output_window($static_output);
904
	/* parse package configuration */
905
	$packages = &$config['installedpackages']['package'];
906
	$tabs =& $config['installedpackages']['tab'];
907
	$menus =& $config['installedpackages']['menu'];
908
	$services = &$config['installedpackages']['service'];
909
	$pkg_info =& $packages[$pkgid];
910
	if(file_exists("/usr/local/pkg/" . $pkg_info['configurationfile'])) {
911
		$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $packages[$pkgid]['configurationfile'], "packagegui");
912
		/* remove tab items */
913
		if(is_array($pkg_config['tabs'])) {
914
			$static_output .= "Tabs items... ";
915
			update_output_window($static_output);
916
			if(is_array($pkg_config['tabs']['tab']) && is_array($tabs)) {
917
				foreach($pkg_config['tabs']['tab'] as $tab) {
918
					foreach($tabs as $key => $insttab) {
919
						if($insttab['name'] == $tab['name']) {
920
							unset($tabs[$key]);
921
							break;
922
						}
923
					}
924
				}
925
			}
926
			$static_output .= "done.\n";
927
			update_output_window($static_output);
928
		}
929
		/* remove menu items */
930
		if(is_array($pkg_config['menu'])) {
931
			$static_output .= "Menu items... ";
932
			update_output_window($static_output);
933
			if (is_array($pkg_config['menu']) && is_array($menus)) {
934
				foreach($pkg_config['menu'] as $menu) {
935
					foreach($menus as $key => $instmenu) {
936
						if($instmenu['name'] == $menu['name']) {
937
							unset($menus[$key]);
938
							break;
939
						}
940
					}
941
				}
942
			}
943
			$static_output .= "done.\n";
944
			update_output_window($static_output);
945
		}
946
		/* remove services */
947
		if(is_array($pkg_config['service'])) {
948
			$static_output .= "Services... ";
949
			update_output_window($static_output);
950
			if (is_array($pkg_config['service']) && is_array($services)) {
951
				foreach($pkg_config['service'] as $service) {
952
					foreach($services as $key => $instservice) {
953
						if($instservice['name'] == $service['name']) {
954
							if($g['booting'] != true)
955
								stop_service($service['name']);
956
							unset($services[$key]);
957
						}
958
					}
959
				}
960
			}
961
			$static_output .= "done.\n";
962
			update_output_window($static_output);
963
		}
964
		/*
965
		 * XXX: Otherwise inclusion of config.inc again invalidates actions taken.
966
		 * 	Same is done during installation.
967
		 */
968
		write_config("Intermediate config write during package removal for {$pkg}.");
969

    
970
		/*
971
		 * If a require exists, include it.  this will
972
		 * show us where an error exists in a package
973
		 * instead of making us blindly guess
974
		 */
975
		$missing_include = false;
976
		if($pkg_config['include_file'] <> "") {
977
			$static_output .= "Loading package instructions...\n";
978
			update_output_window($static_output);
979
			pkg_debug("require_once(\"{$pkg_config['include_file']}\")\n");
980
			if (file_exists($pkg_config['include_file']))
981
				require_once($pkg_config['include_file']);
982
			else {
983
				$missing_include = true;
984
				update_output_window($static_output);
985
				$static_output .= "Include file " . basename($pkg_config['include_file']) . " could not be found for inclusion.\n";
986
			}
987
		}
988
		/* ermal
989
		 * NOTE: It is not possible to handle parse errors on eval.
990
		 * So we prevent it from being run at all to not interrupt all the other code.
991
		 */
992
		if ($missing_include == false) {
993
			/* evalate this package's global functions and pre deinstall commands */
994
			if($pkg_config['custom_php_global_functions'] <> "")
995
				eval_once($pkg_config['custom_php_global_functions']);
996
			if($pkg_config['custom_php_pre_deinstall_command'] <> "")
997
				eval_once($pkg_config['custom_php_pre_deinstall_command']);
998
		}
999
		/* system files */
1000
		if(is_array($pkg_config['modify_system']) && is_array($pkg_config['modify_system']['item'])) {
1001
			$static_output .= "System files... ";
1002
			update_output_window($static_output);
1003
			foreach($pkg_config['modify_system']['item'] as $ms)
1004
				if($ms['textneeded']) remove_text_from_file($ms['modifyfilename'], $ms['textneeded']);
1005

    
1006
			$static_output .= "done.\n";
1007
			update_output_window($static_output);
1008
		}
1009
		/* deinstall commands */
1010
		if($pkg_config['custom_php_deinstall_command'] <> "") {
1011
			$static_output .= "Deinstall commands... ";
1012
			update_output_window($static_output);
1013
			if ($missing_include == false) {
1014
				eval_once($pkg_config['custom_php_deinstall_command']);
1015
				$static_output .= "done.\n";
1016
			} else
1017
				$static_output .= "\nNot executing custom deinstall hook because an include is missing.\n";
1018
			update_output_window($static_output);
1019
		}
1020
		if($pkg_config['include_file'] <> "") {
1021
			$static_output .= "Removing package instructions...";
1022
			update_output_window($static_output);
1023
			pkg_debug("Remove '{$pkg_config['include_file']}'\n");
1024
			unlink_if_exists("/usr/local/pkg/" . $pkg_config['include_file']);
1025
			$static_output .= "done.\n";
1026
			update_output_window($static_output);
1027
		}
1028
		/* remove all additional files */
1029
		if(is_array($pkg_config['additional_files_needed'])) {
1030
			$static_output .= "Auxiliary files... ";
1031
			update_output_window($static_output);
1032
			foreach($pkg_config['additional_files_needed'] as $afn) {
1033
				$filename = get_filename_from_url($afn['item'][0]);
1034
				if($afn['prefix'] <> "")
1035
					$prefix = $afn['prefix'];
1036
				else
1037
					$prefix = "/usr/local/pkg/";
1038
				unlink_if_exists($prefix . $filename);
1039
			}
1040
			$static_output .= "done.\n";
1041
			update_output_window($static_output);
1042
		}
1043
		/* package XML file */
1044
		$static_output .= "Package XML... ";
1045
		update_output_window($static_output);
1046
		unlink_if_exists("/usr/local/pkg/" . $packages[$pkgid]['configurationfile']);
1047
		$static_output .= "done.\n";
1048
		update_output_window($static_output);
1049
	}
1050
	/* syslog */
1051
	if(is_array($pkg_info['logging']) && $pkg_info['logging']['logfile_name'] <> "") {
1052
		$static_output .= "Syslog entries... ";
1053
		update_output_window($static_output);
1054
		remove_text_from_file("/etc/syslog.conf", $pkg_info['logging']['facilityname'] . "\t\t\t\t" . $pkg_info['logging']['logfilename']);
1055
		system_syslogd_start();
1056
		@unlink("{$g['varlog_path']}/{$pkg_info['logging']['logfilename']}");
1057
		$static_output .= "done.\n";
1058
		update_output_window($static_output);
1059
	}
1060
	
1061
	conf_mount_ro();
1062
	/* remove config.xml entries */
1063
	$static_output .= "Configuration... ";
1064
	update_output_window($static_output);
1065
	unset($config['installedpackages']['package'][$pkgid]);
1066
	$static_output .= "done.\n";
1067
	update_output_window($static_output);
1068
	write_config("Removed {$pkg} package.\n");
1069
}
1070

    
1071
function expand_to_bytes($size) {
1072
	$conv = array(
1073
			"G" =>	"3",
1074
			"M" =>  "2",
1075
			"K" =>  "1",
1076
			"B" =>  "0"
1077
		);
1078
	$suffix = substr($size, -1);
1079
	if(!in_array($suffix, array_keys($conv))) return $size;
1080
	$size = substr($size, 0, -1);
1081
	for($i = 0; $i < $conv[$suffix]; $i++) {
1082
		$size *= 1024;
1083
	}
1084
	return $size;
1085
}
1086

    
1087
function get_pkg_db() {
1088
	global $g;
1089
	return return_dir_as_array($g['vardb_path'] . '/pkg');
1090
}
1091

    
1092
function walk_depend($depend, $pkgdb = "", $alreadyseen = "") {
1093
	if(!$pkgdb)
1094
		$pkgdb = get_pkg_db();
1095
	if(!is_array($alreadyseen))
1096
		$alreadyseen = array();
1097
	if (!is_array($depend))
1098
		$depend = array();
1099
	foreach($depend as $adepend) {
1100
		$pkgname = reverse_strrchr($adepend['name'], '.');
1101
		if(in_array($pkgname, $alreadyseen)) {
1102
			continue;
1103
		} elseif(!in_array($pkgname, $pkgdb)) {
1104
			$size += expand_to_bytes($adepend['size']);
1105
			$alreadyseen[] = $pkgname;
1106
			if(is_array($adepend['depend'])) $size += walk_depend($adepend['depend'], $pkgdb, $alreadyseen);
1107
		}
1108
	}
1109
	return $size;
1110
}
1111

    
1112
function get_package_install_size($pkg = 'all', $pkg_info = "") {
1113
	global $config, $g;
1114
	if((!is_array($pkg)) and ($pkg != 'all'))
1115
		$pkg = array($pkg);
1116
	$pkgdb = get_pkg_db();
1117
	if(!$pkg_info)
1118
		$pkg_info = get_pkg_sizes($pkg);
1119
	foreach($pkg as $apkg) {
1120
		if(!$pkg_info[$apkg])
1121
			continue;
1122
		$toreturn[$apkg] = expand_to_bytes(walk_depend(array($pkg_info[$apkg]), $pkgdb));
1123
	}
1124
	return $toreturn;
1125
}
1126

    
1127
function squash_from_bytes($size, $round = "") {
1128
	$conv = array(1 => "B", "K", "M", "G");
1129
	foreach($conv as $div => $suffix) {
1130
		$sizeorig = $size;
1131
		if(($size /= 1024) < 1) {
1132
			if($round) {
1133
				$sizeorig = round($sizeorig, $round);
1134
			}
1135
			return $sizeorig . $suffix;
1136
		}
1137
	}
1138
	return;
1139
}
1140

    
1141
function pkg_reinstall_all() {
1142
	global $g, $config;
1143
	$pkg_id = 0;
1144
	$todo = array();
1145
	if (is_array($config['installedpackages']['package']))
1146
		foreach($config['installedpackages']['package'] as $package)
1147
			$todo[] = array('name' => $package['name'], 'version' => $package['version']);
1148
	echo "One moment please, reinstalling packages...\n";
1149
	echo " >>> Trying to fetch package info...";
1150
	$pkg_info = get_pkg_info();
1151
	if ($pkg_info) {
1152
		echo " Done.\n";
1153
	} else {
1154
		$xmlrpc_base_url = isset($config['system']['altpkgrepo']['enable']) ? $config['system']['altpkgrepo']['xmlrpcbaseurl'] : $g['xmlrpcbaseurl'];
1155
		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";
1156
		return;
1157
	}
1158
	if(is_array($todo)) {
1159
		foreach($todo as $pkgtodo) {
1160
			$static_output = "";
1161
			if($pkgtodo['name']) {
1162
				uninstall_package($pkgtodo['name']);
1163
				install_package($pkgtodo['name']);
1164
				$pkg_id++;
1165
			}
1166
		}
1167
	}
1168
}
1169

    
1170
?>
(36-36/61)