Commit 5a3ddb94 authored by Ad Schellevis's avatar Ad Schellevis

remove old package support

parent 6bb3ac06
......@@ -265,7 +265,6 @@ function filter_configure_sync($delete_states_if_needed = true)
$rules .= "{$altq_queues}\n";
$rules .= "{$natrules}\n";
$rules .= "{$pfrules}\n";
$rules .= discover_pkg_rules("filter");
unset($aliases, $gateways, $altq_queues, $natrules, $pfrules);
......@@ -1974,7 +1973,6 @@ function filter_nat_rules_generate() {
}
}
$natrules .= discover_pkg_rules("nat");
$natrules .= "# UPnPd rdr anchor\n";
$natrules .= "rdr-anchor \"miniupnpd\"\n";
......@@ -2620,7 +2618,6 @@ function filter_rules_generate()
$pptpdcfg = $config['pptpd'];
$ipfrules = "";
$ipfrules .= discover_pkg_rules("pfearly");
/* relayd */
$ipfrules .= "anchor \"relayd/*\"\n";
......@@ -3563,37 +3560,6 @@ EOD;
return($ipfrules);
}
function discover_pkg_rules($ruletype) {
global $config, $g, $aliases;
/* Bail if there is no pkg directory, or if the package files might be out of sync. */
if(!is_dir("/usr/local/pkg") || file_exists('/conf/needs_package_sync'))
return "";
$rules = "";
$files = glob("/usr/local/pkg/*.inc");
foreach($files as $pkg_inc) {
update_filter_reload_status(sprintf(gettext('Checking for %1$s PF hooks in package %2$s'), $ruletype, $pkg_inc));
$pkg = basename($pkg_inc, ".inc");
$pkg_generate_rules = "{$pkg}_generate_rules";
if (!function_exists($pkg_generate_rules))
require_once($pkg_inc);
if(function_exists($pkg_generate_rules)) {
update_filter_reload_status(sprintf(gettext('Processing early %1$s rules for package %2$s'), $ruletype, $pkg_inc));
$tmprules = $pkg_generate_rules("$ruletype");
file_put_contents('/tmp/rules.test.packages', $aliases . $tmprules);
$status = mwexec('/sbin/pfctl -nf /tmp/rules.test.packages');
if ($status <> 0) {
$errorrules = sprintf(gettext("There was an error while parsing the package filter rules for %s."), $pkg_inc) . "\n";
log_error($errorrules);
file_put_contents("/tmp/rules.packages.{$pkg}", "#{$errorrules}\n{$tmprules}\n");
continue;
}
$rules .= $tmprules;
}
}
return $rules;
}
function filter_get_antilockout_ports($wantarray = false) {
global $config;
......
<?php
/*
* Copyright (C) 2010 Ermal Luci
* Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
require_once("globals.inc");
require_once("xmlrpc.inc");
require_once("service-utils.inc");
require_once("xmlparse.inc");
require_once("pfsense-utils.inc");
if(!function_exists("update_status")) {
function update_status($status) {
echo $status . "\n";
}
}
if(!function_exists("update_output_window")) {
function update_output_window($status) {
echo $status . "\n";
}
}
if (!function_exists("pkg_debug")) {
/* set up logging if needed */
function pkg_debug($msg) {
global $fd_log;
if (!$fd_log) {
if (!$fd_log = fopen("/tmp/pkg_mgr_{$package}.log", "w"))
update_output_window("Warning, could not open log for writing.");
}
@fwrite($fd_log, $msg);
}
}
$vardb = "/var/db/pkg";
safe_mkdir($vardb);
$g['platform'] = trim(file_get_contents("/usr/local/etc/platform"));
if(!is_dir("/usr/local/pkg") or !is_dir("/usr/local/pkg/pf")) {
conf_mount_rw();
safe_mkdir("/usr/local/pkg");
safe_mkdir("/usr/local/pkg/pf");
conf_mount_ro();
}
/****f* pkg-utils/remove_package
* NAME
* remove_package - Removes package from FreeBSD if it exists
* INPUTS
* $packagestring - name/string to check for
* RESULT
* none
* NOTES
*
******/
function remove_freebsd_package($packagestring) {
// The packagestring passed in must be the full PBI package name,
// as displayed by the pbi_info utility. e.g. "package-1.2.3_4-i386"
// It must NOT have ".pbi" on the end.
$links = get_pbi_binaries(escapeshellarg($packagestring));
foreach($links as $link)
if (is_link("/usr/local/{$link['link_name']}"))
@unlink("/usr/local/{$link['link_name']}");
exec("/usr/local/sbin/pbi_delete " . escapeshellarg($packagestring) . " 2>>/tmp/pbi_delete_errors.txt");
}
/****f* pkg-utils/is_package_installed
* NAME
* is_package_installed - Check whether a package is installed.
* INPUTS
* $packagename - name of the package to check
* RESULT
* boolean - true if the package is installed, false otherwise
* NOTES
* This function is deprecated - get_pkg_id() can already check for installation.
******/
function is_package_installed($packagename) {
$pkg = get_pkg_id($packagename);
if($pkg == -1)
return false;
return true;
}
/****f* pkg-utils/get_pkg_id
* NAME
* get_pkg_id - Find a package's numeric ID.
* INPUTS
* $pkg_name - name of the package to check
* RESULT
* integer - -1 if package is not found, >-1 otherwise
******/
function get_pkg_id($pkg_name) {
global $config;
if (is_array($config['installedpackages']['package'])) {
foreach($config['installedpackages']['package'] as $idx => $pkg) {
if($pkg['name'] == $pkg_name)
return $idx;
}
}
return -1;
}
/****f* pkg-utils/get_pkg_internal_name
* NAME
* get_pkg_internal_name - Find a package's internal name (e.g. squid3 internal name is squid)
* INPUTS
* $package - array of package data from config
* RESULT
* string - internal name (if defined) or default to package name
******/
function get_pkg_internal_name($package) {
if (isset($package['internal_name']) && ($package['internal_name'] != "")) {
/* e.g. name is Ipguard-dev, internal name is ipguard */
$pkg_internal_name = $package['internal_name'];
} else {
$pkg_internal_name = $package['name'];
}
return $pkg_internal_name;
}
/****f* pkg-utils/get_pkg_info
* NAME
* get_pkg_info - Retrieve package information from package server.
* INPUTS
* $pkgs - 'all' to retrieve all packages, an array containing package names otherwise
* $info - 'all' to retrieve all information, an array containing keys otherwise
* RESULT
* $raw_versions - Array containing retrieved information, indexed by package name.
******/
function get_pkg_info($pkgs = 'all', $info = 'all') {
global $g;
$freebsd_machine = php_uname("m");
$params = array(
"pkg" => $pkgs,
"info" => $info,
"freebsd_version" => get_freebsd_version(),
"freebsd_machine" => $freebsd_machine
);
$resp = call_pfsense_method('pfsense.get_pkgs', $params, 10);
return $resp ? $resp : array();
}
function get_pkg_sizes($pkgs = 'all') {
global $config, $g;
$freebsd_machine = php_uname("m");
$params = array(
"pkg" => $pkgs,
"freebsd_version" => get_freebsd_version(),
"freebsd_machine" => $freebsd_machine
);
$msg = new XML_RPC_Message('pfsense.get_pkg_sizes', array(php_value_to_xmlrpc($params)));
$xmlrpc_base_url = get_active_xml_rpc_base_url();
$cli = new XML_RPC_Client($g['xmlrpcpath'], $xmlrpc_base_url);
$resp = $cli->send($msg, 10);
if(!is_object($resp))
log_error("Could not get response from XMLRPC server!");
else if (!$resp->faultCode()) {
$raw_versions = $resp->value();
return xmlrpc_value_to_php($raw_versions);
}
return array();
}
/*
* resync_all_package_configs() Force packages to setup their configuration and rc.d files.
* This function may also print output to the terminal indicating progress.
*/
function resync_all_package_configs($show_message = false) {
global $config, $pkg_interface, $g;
log_error(gettext("Resyncing configuration for all packages."));
if (!is_array($config['installedpackages']['package']))
return;
if($show_message == true)
echo "Syncing packages:";
conf_mount_rw();
foreach($config['installedpackages']['package'] as $idx => $package) {
if (empty($package['name']))
continue;
if($show_message == true)
echo " " . $package['name'];
get_pkg_depends($package['name'], "all");
if(!file_exists("/var/run/booting"))
stop_service(get_pkg_internal_name($package));
sync_package($idx, true, true);
if($pkg_interface == "console")
echo "\n" . gettext("Syncing packages:");
}
if($show_message == true)
echo " done.\n";
@unlink("/conf/needs_package_sync");
conf_mount_ro();
}
/*
* is_freebsd_pkg_installed() - Check /var/db/pkg to determine whether or not a FreeBSD
* package is installed.
*/
function is_freebsd_pkg_installed($pkg) {
if(!$pkg)
return;
$output = "";
$_gb = exec("/usr/local/sbin/pbi_info " . escapeshellarg($pkg) . ' 2>/dev/null', $output, $retval);
return (intval($retval) == 0);
}
/*
* get_pkg_depends($pkg_name, $filetype = ".xml", $format = "files", return_nosync = 1): Return a package's dependencies.
*
* $filetype = "all" || ".xml", ".tgz", etc.
* $format = "files" (full filenames) || "names" (stripped / parsed depend names)
* $return_nosync = 1 (return depends that have nosync set) | 0 (ignore packages with nosync)
*
*/
function get_pkg_depends($pkg_name, $filetype = ".xml", $format = "files", $return_nosync = 1) {
global $config;
$pkg_id = get_pkg_id($pkg_name);
if($pkg_id == -1)
return -1; // This package doesn't really exist - exit the function.
else if (!isset($config['installedpackages']['package'][$pkg_id]))
return; // No package belongs to the pkg_id passed to this function.
$package =& $config['installedpackages']['package'][$pkg_id];
if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
log_error(sprintf(gettext('The %1$s package is missing required dependencies and must be reinstalled. %2$s'), $package['name'], $package['configurationfile']));
uninstall_package($package['name']);
if (install_package($package['name']) < 0) {
log_error("Failed reinstalling package {$package['name']}.");
return false;
}
}
$pkg_xml = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
if (!empty($pkg_xml['additional_files_needed'])) {
foreach($pkg_xml['additional_files_needed'] as $item) {
if ($return_nosync == 0 && isset($item['nosync']))
continue; // Do not return depends with nosync set if not required.
$depend_file = substr(strrchr($item['item']['0'], '/'),1); // Strip URLs down to filenames.
$depend_name = substr(substr($depend_file,0,strpos($depend_file,".")+1),0,-1); // Strip filename down to dependency name.
if (($filetype != "all") && (!preg_match("/{$filetype}/i", $depend_file)))
if (($filetype != "all") && (strtolower(substr($depend_file, -strlen($filetype))) != strtolower($filetype)))
continue;
if ($item['prefix'] != "")
$prefix = $item['prefix'];
else
$prefix = "/usr/local/pkg/";
// Ensure that the prefix exists to avoid installation errors.
if(!is_dir($prefix))
exec("/bin/mkdir -p {$prefix}");
if(!file_exists($prefix . $depend_file))
log_error(sprintf(gettext("The %s package is missing required dependencies and must be reinstalled."), $package['name']));
switch ($format) {
case "files":
$depends[] = $prefix . $depend_file;
break;
case "names":
switch ($filetype) {
case "all":
if(preg_match("/\.xml/i", $depend_file)) {
$depend_xml = parse_xml_config_pkg("/usr/local/pkg/{$depend_file}", "packagegui");
if (!empty($depend_xml))
$depends[] = $depend_xml['name'];
} else
$depends[] = $depend_name; // If this dependency isn't package XML, use the stripped filename.
break;
case ".xml":
$depend_xml = parse_xml_config_pkg("/usr/local/pkg/" . $depend_file, "packagegui");
if (!empty($depend_xml))
$depends[] = $depend_xml['name'];
break;
default:
$depends[] = $depend_name; // If we aren't looking for XML, use the stripped filename (it's all we have).
break;
}
}
}
return $depends;
}
}
function uninstall_package($pkg_name) {
global $config, $static_output;
global $builder_package_install;
$id = get_pkg_id($pkg_name);
if ($id >= 0) {
stop_service(get_pkg_internal_name($config['installedpackages']['package'][$id]));
$pkg_depends =& $config['installedpackages']['package'][$id]['depends_on_package_pbi'];
$static_output .= "Removing package...\n";
update_output_window($static_output);
if (is_array($pkg_depends)) {
foreach ($pkg_depends as $pkg_depend)
delete_package($pkg_depend);
} else {
// The packages (1 or more) are all in one long string.
// We need to pass them 1 at a time to delete_package.
// Compress any multiple whitespace (sp, tab, cr, lf...) into a single space char.
$pkg_dep_str = preg_replace("'\s+'", ' ', $pkg_depends);
// Get rid of any leading or trailing space.
$pkg_dep_str = trim($pkg_dep_str);
// Now we have a space-separated string. Make it into an array and process it.
$pkg_dep_array = explode(" ", $pkg_dep_str);
foreach ($pkg_dep_array as $pkg_depend) {
delete_package($pkg_depend);
}
}
}
delete_package_xml($pkg_name);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
function force_remove_package($pkg_name) {
delete_package_xml($pkg_name);
}
/*
* sync_package($pkg_name, $sync_depends = true, $show_message = false) Force a package to setup its configuration and rc.d files.
*/
function sync_package($pkg_name, $sync_depends = true, $show_message = false) {
global $config, $config_parsed;
global $builder_package_install;
// If this code is being called by pfspkg_installer
// which the builder system uses then return (ignore).
if($builder_package_install)
return;
if(empty($config['installedpackages']['package']))
return;
if(!is_numeric($pkg_name)) {
$pkg_id = get_pkg_id($pkg_name);
if($pkg_id == -1)
return -1; // This package doesn't really exist - exit the function.
} else {
$pkg_id = $pkg_name;
if(empty($config['installedpackages']['package'][$pkg_id]))
return; // No package belongs to the pkg_id passed to this function.
}
if (is_array($config['installedpackages']['package'][$pkg_id]))
$package =& $config['installedpackages']['package'][$pkg_id];
else
return; /* empty package tag */
if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
log_error(sprintf(gettext("The %s package is missing its configuration file and must be reinstalled."), $package['name']));
force_remove_package($package['name']);
return -1;
}
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
if(isset($pkg_config['nosync']))
return;
/* Bring in package include files */
if (!empty($pkg_config['include_file'])) {
$include_file = $pkg_config['include_file'];
if (file_exists($include_file))
require_once($include_file);
else {
/* XXX: What the heck is this?! */
log_error("Reinstalling package {$package['name']} because its include file({$include_file}) is missing!");
uninstall_package($package['name']);
if (install_package($package['name']) < 0) {
log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!");
return -1;
}
}
}
if(!empty($pkg_config['custom_php_global_functions']))
eval($pkg_config['custom_php_global_functions']);
if(!empty($pkg_config['custom_php_resync_config_command']))
eval($pkg_config['custom_php_resync_config_command']);
if($sync_depends == true) {
$depends = get_pkg_depends($pkg_name, ".xml", "files", 1); // Call dependency handler and do a little more error checking.
if(is_array($depends)) {
foreach($depends as $item) {
if(!file_exists($item)) {
require_once("notices.inc");
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);
log_error("Could not find {$item}. Reinstalling package.");
uninstall_package($pkg_name);
if (install_package($pkg_name) < 0) {
log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!");
return -1;
}
} else {
$item_config = parse_xml_config_pkg($item, "packagegui");
if (empty($item_config))
continue;
if(isset($item_config['nosync']))
continue;
if (!empty($item_config['include_file'])) {
if (file_exists($item_config['include_file']))
require_once($item_config['include_file']);
else {
log_error("Not calling package sync code for dependency {$item_config['name']} of {$package['name']} because some include files are missing.");
continue;
}
}
if($item_config['custom_php_global_functions'] <> "")
eval($item_config['custom_php_global_functions']);
if($item_config['custom_php_resync_config_command'] <> "")
eval($item_config['custom_php_resync_config_command']);
if($show_message == true)
print " " . $item_config['name'];
}
}
}
}
}
/*
* pkg_fetch_recursive: Download and install a FreeBSD PBI package. This function provides output to
* a progress bar and output window.
*/
function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = "") {
global $static_output, $g, $config;
// Clean up incoming filenames
$filename = str_replace(" ", " ", $filename);
$filename = str_replace("\n", " ", $filename);
$filename = str_replace(" ", " ", $filename);
$pkgs = explode(" ", $filename);
foreach($pkgs as $filename) {
$filename = trim($filename);
if ($g['platform'] == "nanobsd") {
$pkgtmpdir = "/usr/bin/env PKG_TMPDIR=/root/ ";
$pkgstagingdir = "/root/tmp";
if (!is_dir($pkgstagingdir))
mkdir($pkgstagingdir);
$pkgstaging = "-o {$pkgstagingdir}/instmp.XXXXXX";
$fetchdir = $pkgstagingdir;
} else {
$fetchdir = '/tmp';
}
/* FreeBSD has no PBI's hosted, so fall back to our own URL for now. (Maybe fail to PC-BSD?) */
$rel = get_freebsd_version();
$priv_url = "https://files.pfsense.org/packages/{$rel}/All/";
if (empty($base_url))
$base_url = $priv_url;
if (substr($base_url, -1) == "/")
$base_url = substr($base_url, 0, -1);
$fetchto = "{$fetchdir}/apkg_{$filename}";
$static_output .= "\n" . str_repeat(" ", $dependlevel * 2 + 1) . "Downloading {$base_url}/{$filename} ... ";
if (download_file_with_progress_bar("{$base_url}/{$filename}", $fetchto) !== true) {
if ($base_url != $priv_url && download_file_with_progress_bar("{$priv_url}/{$filename}", $fetchto) !== true) {
$static_output .= " could not download from there or {$priv_url}/{$filename}.\n";
update_output_window($static_output);
return false;
} else if ($base_url == $priv_url) {
$static_output .= " failed to download.\n";
update_output_window($static_output);
return false;
} else {
$static_output .= " [{$osname} repository]\n";
update_output_window($static_output);
}
}
$static_output .= " (extracting)\n";
update_output_window($static_output);
$pkgaddout = "";
$no_checksig = "";
if (isset($config['system']['pkg_nochecksig']))
$no_checksig = "--no-checksig";
$result = exec("/usr/local/sbin/pbi_add " . $pkgstaging . " -f -v {$no_checksig} " . escapeshellarg($fetchto) . " 2>&1", $pkgaddout, $rc);
pkg_debug($pkgname . " " . print_r($pkgaddout, true) . "\n");
if ($rc == 0) {
$pbi_name = preg_replace('/\.pbi$/','',$filename);
$gb = exec("/usr/local/sbin/pbi_info {$pbi_name} | /usr/bin/awk '/Prefix/ {print $2}'", $pbi_prefix);
$pbi_prefix = $pbi_prefix[0];
$links = get_pbi_binaries(escapeshellarg($pbi_name));
foreach($links as $link) {
@unlink("/usr/local/{$link['link_name']}");
@symlink("{$link['target']}","/usr/local/{$link['link_name']}");
}
$extra_links = array(
array("target" => "bin", "link_name" => "sbin"),
array("target" => "local/lib", "link_name" => "lib"),
array("target" => "local/libexec", "link_name" => "libexec"),
array("target" => "local/share", "link_name" => "share"),
array("target" => "local/www", "link_name" => "www"),
array("target" => "local/etc", "link_name" => "etc")
);
foreach ($extra_links as $link) {
if (!file_exists($pbi_prefix . "/" . $link['target']))
continue;
@rmdir("{$pbi_prefix}/{$link['link_name']}");
unlink_if_exists("{$pbi_prefix}/{$link['link_name']}");
@symlink("{$pbi_prefix}/{$link['target']}", "{$pbi_prefix}/{$link['link_name']}");
}
pkg_debug("pbi_add successfully completed.\n");
} else {
if (is_array($pkgaddout))
foreach ($pkgaddout as $line)
$static_output .= " " . $line .= "\n";
update_output_window($static_output);
pkg_debug("pbi_add failed.\n");
return false;
}
}
return true;
}
function get_pbi_binaries($pbi) {
$result = array();
if (empty($pbi))
return $result;
$gb = exec("/usr/local/sbin/pbi_info {$pbi} | /usr/bin/awk '/Prefix/ {print $2}'", $pbi_prefix);
$pbi_prefix = $pbi_prefix[0];
if (empty($pbi_prefix))
return $result;
foreach(array('bin', 'sbin') as $dir) {
if(!is_dir("{$pbi_prefix}/{$dir}"))
continue;
$files = glob("{$pbi_prefix}/{$dir}/*.pbiopt");
foreach($files as $f) {
$pbiopts = file($f, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($pbiopts as $pbiopt) {
if (!preg_match('/^TARGET:\s+(.*)$/', $pbiopt, $matches))
continue;
$result[] = array(
'target' => preg_replace('/\.pbiopt$/', '', $f),
'link_name' => $matches[1]);
}
}
}
return $result;
}
function install_package($package, $pkg_info = "", $force_install = false) {
global $g, $config, $static_output, $pkg_interface;
/* safe side. Write config below will send to ro again. */
conf_mount_rw();
if($pkg_interface == "console")
echo "\n";
/* fetch package information if needed */
if(empty($pkg_info) or !is_array($pkg_info[$package])) {
$pkg_info = get_pkg_info(array($package));
$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
if (empty($pkg_info)) {
conf_mount_ro();
return -1;
}
}
if (!$force_install) {
$compatible = true;
$version = rtrim(file_get_contents("/usr/local/opnsense/version/opnsense"));
if (isset($pkg_info['required_version']))
$compatible = (pfs_version_compare("", $version, $pkg_info['required_version']) >= 0);
if (isset($pkg_info['maximum_version']))
$compatible = $compatible && (pfs_version_compare("", $version, $pkg_info['maximum_version']) <= 0);
if (!$compatible) {
log_error(sprintf(gettext('Package %s is not supported on this version.'), $pkg_info['name']));
$static_output .= sprintf(gettext("Package %s is not supported on this version."), $pkg_info['name']);
update_status($static_output);
conf_mount_ro();
return -1;
}
}
pkg_debug(gettext("Beginning package installation.") . "\n");
log_error(sprintf(gettext('Beginning package installation for %s .'), $pkg_info['name']));
$static_output .= sprintf(gettext("Beginning package installation for %s ."), $pkg_info['name']);
update_status($static_output);
/* fetch the package's configuration file */
pkg_fetch_config_file($package, $pkg_info);
/* add package information to config.xml */
$pkgid = get_pkg_id($pkg_info['name']);
$static_output .= gettext("Saving updated package information...") . " ";
update_output_window($static_output);
if($pkgid == -1) {
$config['installedpackages']['package'][] = $pkg_info;
$changedesc = sprintf(gettext("Installed %s package."),$pkg_info['name']);
$to_output = gettext("done.") . "\n";
} else {
$config['installedpackages']['package'][$pkgid] = $pkg_info;
$changedesc = sprintf(gettext("Overwrote previous installation of %s."), $pkg_info['name']);
$to_output = gettext("overwrite!") . "\n";
}
if(file_exists('/conf/needs_package_sync'))
@unlink('/conf/needs_package_sync');
conf_mount_ro();
write_config("Intermediate config write during package install for {$pkg_info['name']}.");
$static_output .= $to_output;
update_output_window($static_output);
/* install other package components */
if (!install_package_xml($package)) {
uninstall_package($package);
write_config($changedesc);
$static_output .= gettext("Failed to install package.") . "\n";
update_output_window($static_output);
return -1;
} else {
$static_output .= gettext("Writing configuration... ");
update_output_window($static_output);
write_config($changedesc);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
if($pkg_info['after_install_info'])
update_output_window($pkg_info['after_install_info']);
}
}
function get_after_install_info($package) {
global $pkg_info;
/* fetch package information if needed */
if(!$pkg_info or !is_array($pkg_info[$package])) {
$pkg_info = get_pkg_info(array($package));
$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
}
if($pkg_info['after_install_info'])
return $pkg_info['after_install_info'];
}
function eval_once($toeval) {
global $evaled;
if(!$evaled) $evaled = array();
$evalmd5 = md5($toeval);
if(!in_array($evalmd5, $evaled)) {
@eval($toeval);
$evaled[] = $evalmd5;
}
return;
}
function install_package_xml($pkg) {
global $g, $config, $static_output, $pkg_interface, $config_parsed;
if(($pkgid = get_pkg_id($pkg)) == -1) {
$static_output .= sprintf(gettext("The %s package is not installed.%sInstallation aborted."), $pkg, "\n\n");
update_output_window($static_output);
if($pkg_interface <> "console") {
echo "\n<script type=\"text/javascript\">document.progressbar.style.visibility='hidden';</script>";
echo "\n<script type=\"text/javascript\">document.progholder.style.visibility='hidden';</script>";
}
sleep(1);
return false;
} else
$pkg_info = $config['installedpackages']['package'][$pkgid];
/* pkg_add the package and its dependencies */
if($pkg_info['depends_on_package_base_url'] != "") {
if($pkg_interface == "console")
echo "\n";
update_status(gettext("Installing") . " " . $pkg_info['name'] . " " . gettext("and its dependencies."));
$static_output .= gettext("Downloading") . " " . $pkg_info['name'] . " " . gettext("and its dependencies... ");
$static_orig = $static_output;
$static_output .= "\n";
update_output_window($static_output);
foreach((array) $pkg_info['depends_on_package_pbi'] as $pkgdep) {
$pkg_name = substr(reverse_strrchr($pkgdep, "."), 0, -1);
$static_output = $static_orig . "\nChecking for package installation... ";
update_output_window($static_output);
if (!is_freebsd_pkg_installed($pkg_name)) {
if (!pkg_fetch_recursive($pkg_name, $pkgdep, 0, $pkg_info['depends_on_package_base_url'])) {
$static_output .= "of {$pkg_name} failed!\n\nInstallation aborted.";
update_output_window($static_output);
pkg_debug(gettext("Package WAS NOT installed properly.") . "\n");
if($pkg_interface <> "console") {
echo "\n<script type=\"text/javascript\">document.progressbar.style.visibility='hidden';</script>";
echo "\n<script type=\"text/javascript\">document.progholder.style.visibility='hidden';</script>";
}
sleep(1);
return false;
}
}
}
}
$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1);
if(file_exists("/usr/local/pkg/" . $configfile)) {
$static_output .= gettext("Loading package configuration... ");
update_output_window($static_output);
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $configfile, "packagegui");
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
$static_output .= gettext("Configuring package components...\n");
if (!empty($pkg_config['filter_rules_needed']))
$config['installedpackages']['package'][$pkgid]['filter_rule_function'] = $pkg_config['filter_rules_needed'];
update_output_window($static_output);
/* modify system files */
if(is_array($pkg_config['modify_system']) && is_array($pkg_config['modify_system']['item'])) {
$static_output .= gettext("System files... ");
update_output_window($static_output);
foreach($pkg_config['modify_system']['item'] as $ms) {
if($ms['textneeded']) {
add_text_to_file($ms['modifyfilename'], $ms['textneeded']);
}
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
pkg_fetch_additional_files($pkg, $pkg_info);
/* if a require exists, include it. this will
* show us where an error exists in a package
* instead of making us blindly guess
*/
$missing_include = false;
if($pkg_config['include_file'] <> "") {
$static_output .= gettext("Loading package instructions...") . "\n";
update_output_window($static_output);
pkg_debug("require_once('{$pkg_config['include_file']}')\n");
if (file_exists($pkg_config['include_file']))
require_once($pkg_config['include_file']);
else {
$missing_include = true;
$static_output .= "Include " . basename($pkg_config['include_file']) . " is missing!\n";
update_output_window($static_output);
/* XXX: Should undo the steps before this?! */
return false;
}
}
/* custom commands */
$static_output .= gettext("Custom commands...") . "\n";
update_output_window($static_output);
if ($missing_include == false) {
if($pkg_config['custom_php_global_functions'] <> "") {
$static_output .= gettext("Executing custom_php_global_functions()...");
update_output_window($static_output);
eval_once($pkg_config['custom_php_global_functions']);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
if($pkg_config['custom_php_install_command']) {
$static_output .= gettext("Executing custom_php_install_command()...");
update_output_window($static_output);
/* XXX: create symlinks for conf files into the PBI directories.
* change packages to store configs at /usr/pbi/pkg/etc and remove this
*/
eval_once($pkg_config['custom_php_install_command']);
// Note: pkg may be mixed-case, e.g. "squidGuard" but the PBI names are lowercase.
// e.g. "squidguard-1.4_4-i386" so feed lowercase to pbi_info below.
// Also add the "-" so that examples like "squid-" do not match "squidguard-".
$pkg_name_for_pbi_match = strtolower($pkg) . "-";
exec("/usr/local/sbin/pbi_info | grep '^{$pkg_name_for_pbi_match}' | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray);
$pbidir0 = $pbidirarray[0];
exec("find /usr/local/etc/ -name *.conf | grep " . escapeshellarg($pkg),$files);
foreach($files as $f) {
$pbiconf = str_replace('/usr/local',$pbidir0,$f);
if(is_file($pbiconf) || is_link($pbiconf)) {
unlink($pbiconf);
}
if(is_dir(dirname($pbiconf))) {
symlink($f,$pbiconf);
} else {
log_error("The dir for {$pbiconf} does not exist. Cannot add symlink to {$f}.");
}
}
eval_once($pkg_config['custom_php_install_command']);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
if($pkg_config['custom_php_resync_config_command'] <> "") {
$static_output .= gettext("Executing custom_php_resync_config_command()...");
update_output_window($static_output);
eval_once($pkg_config['custom_php_resync_config_command']);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
}
/* sidebar items */
if(is_array($pkg_config['menu'])) {
$static_output .= gettext("Menu items... ");
update_output_window($static_output);
foreach($pkg_config['menu'] as $menu) {
if(is_array($config['installedpackages']['menu'])) {
foreach($config['installedpackages']['menu'] as $amenu)
if($amenu['name'] == $menu['name'])
continue 2;
} else
$config['installedpackages']['menu'] = array();
$config['installedpackages']['menu'][] = $menu;
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* integrated tab items */
if(is_array($pkg_config['tabs']['tab'])) {
$static_output .= gettext("Integrated Tab items... ");
update_output_window($static_output);
foreach($pkg_config['tabs']['tab'] as $tab) {
if(is_array($config['installedpackages']['tab'])) {
foreach($config['installedpackages']['tab'] as $atab)
if($atab['name'] == $tab['name'])
continue 2;
} else
$config['installedpackages']['tab'] = array();
$config['installedpackages']['tab'][] = $tab;
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* services */
if(is_array($pkg_config['service'])) {
$static_output .= gettext("Services... ");
update_output_window($static_output);
foreach($pkg_config['service'] as $service) {
if(is_array($config['installedpackages']['service'])) {
foreach($config['installedpackages']['service'] as $aservice)
if($aservice['name'] == $service['name'])
continue 2;
} else
$config['installedpackages']['service'] = array();
$config['installedpackages']['service'][] = $service;
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
} else {
$static_output .= gettext("Loading package configuration... failed!") . "\n\n" . gettext("Installation aborted.");
update_output_window($static_output);
pkg_debug(gettext("Unable to load package configuration. Installation aborted.") ."\n");
if($pkg_interface <> "console") {
echo "\n<script type=\"text/javascript\">document.progressbar.style.visibility='hidden';</script>";
echo "\n<script type=\"text/javascript\">document.progholder.style.visibility='hidden';</script>";
}
sleep(1);
return false;
}
/* set up package logging streams */
if($pkg_info['logging']) {
mwexec("/usr/sbin/fifolog_create -s 32768 {$g['varlog_path']}/{$pkg_info['logging']['logfilename']}");
@chmod($g['varlog_path'] . '/' . $pkg_info['logging']['logfilename'], 0600);
add_text_to_file("/etc/syslog.conf", $pkg_info['logging']['facilityname'] . "\t\t\t\t" . $pkg_info['logging']['logfilename']);
pkg_debug("Adding text to file /etc/syslog.conf\n");
system_syslogd_start();
}
return true;
}
function does_package_depend($pkg) {
// Should not happen, but just in case.
if(!$pkg)
return;
$pkg_var_db_dir = glob("/var/db/pkg/{$pkg}*");
// If this package has dependency then return true
foreach($pkg_var_db_dir as $pvdd) {
if (file_exists("{$vardb}/{$pvdd}/+REQUIRED_BY") && count(file("{$vardb}/{$pvdd}/+REQUIRED_BY")) > 0)
return true;
}
// Did not find a record of dependencies, so return false.
return false;
}
function delete_package($pkg) {
global $config, $g, $static_output, $vardb;
if(!$pkg)
return;
// Note: $pkg has the full PBI package name followed by ".pbi". Strip off ".pbi".
$pkg = substr(reverse_strrchr($pkg, "."), 0, -1);
if($pkg)
$static_output .= sprintf(gettext("Starting package deletion for %s..."),$pkg);
update_output_window($static_output);
remove_freebsd_package($pkg);
$static_output .= "done.\n";
update_output_window($static_output);
/* Rescan directories for what has been left and avoid fooling other programs. */
mwexec("/sbin/ldconfig");
return;
}
function delete_package_xml($pkg) {
global $g, $config, $static_output, $pkg_interface;
conf_mount_rw();
$pkgid = get_pkg_id($pkg);
if ($pkgid == -1) {
$static_output .= sprintf(gettext("The %s package is not installed.%sDeletion aborted."), $pkg, "\n\n");
update_output_window($static_output);
if($pkg_interface <> "console") {
echo "\n<script type=\"text/javascript\">document.progressbar.style.visibility='hidden';</script>";
echo "\n<script type=\"text/javascript\">document.progholder.style.visibility='hidden';</script>";
}
ob_flush();
sleep(1);
conf_mount_ro();
return;
}
pkg_debug(sprintf(gettext("Removing %s package... "),$pkg));
$static_output .= sprintf(gettext("Removing %s components..."),$pkg) . "\n";
update_output_window($static_output);
/* parse package configuration */
$packages = &$config['installedpackages']['package'];
$tabs =& $config['installedpackages']['tab'];
$menus =& $config['installedpackages']['menu'];
$services = &$config['installedpackages']['service'];
$pkg_info =& $packages[$pkgid];
if(file_exists("/usr/local/pkg/" . $pkg_info['configurationfile'])) {
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $packages[$pkgid]['configurationfile'], "packagegui");
/* remove tab items */
if(is_array($pkg_config['tabs'])) {
$static_output .= gettext("Tabs items... ");
update_output_window($static_output);
if(is_array($pkg_config['tabs']['tab']) && is_array($tabs)) {
foreach($pkg_config['tabs']['tab'] as $tab) {
foreach($tabs as $key => $insttab) {
if($insttab['name'] == $tab['name']) {
unset($tabs[$key]);
break;
}
}
}
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* remove menu items */
if(is_array($pkg_config['menu'])) {
$static_output .= gettext("Menu items... ");
update_output_window($static_output);
if (is_array($pkg_config['menu']) && is_array($menus)) {
foreach($pkg_config['menu'] as $menu) {
foreach($menus as $key => $instmenu) {
if($instmenu['name'] == $menu['name']) {
unset($menus[$key]);
break;
}
}
}
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* remove services */
if(is_array($pkg_config['service'])) {
$static_output .= gettext("Services... ");
update_output_window($static_output);
if (is_array($pkg_config['service']) && is_array($services)) {
foreach($pkg_config['service'] as $service) {
foreach($services as $key => $instservice) {
if($instservice['name'] == $service['name']) {
if(!file_exists("/var/run/booting"))
stop_service($service['name']);
if($service['rcfile']) {
$prefix = RCFILEPREFIX;
if (!empty($service['prefix']))
$prefix = $service['prefix'];
if (file_exists("{$prefix}{$service['rcfile']}"))
@unlink("{$prefix}{$service['rcfile']}");
}
unset($services[$key]);
}
}
}
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/*
* XXX: Otherwise inclusion of config.inc again invalidates actions taken.
* Same is done during installation.
*/
write_config("Intermediate config write during package removal for {$pkg}.");
/*
* If a require exists, include it. this will
* show us where an error exists in a package
* instead of making us blindly guess
*/
$missing_include = false;
if($pkg_config['include_file'] <> "") {
$static_output .= gettext("Loading package instructions...") . "\n";
update_output_window($static_output);
pkg_debug("require_once(\"{$pkg_config['include_file']}\")\n");
if (file_exists($pkg_config['include_file']))
require_once($pkg_config['include_file']);
else {
$missing_include = true;
update_output_window($static_output);
$static_output .= "Include file " . basename($pkg_config['include_file']) . " could not be found for inclusion.\n";
}
}
/* ermal
* NOTE: It is not possible to handle parse errors on eval.
* So we prevent it from being run at all to not interrupt all the other code.
*/
if ($missing_include == false) {
/* evalate this package's global functions and pre deinstall commands */
if($pkg_config['custom_php_global_functions'] <> "")
eval_once($pkg_config['custom_php_global_functions']);
if($pkg_config['custom_php_pre_deinstall_command'] <> "")
eval_once($pkg_config['custom_php_pre_deinstall_command']);
}
/* system files */
if(is_array($pkg_config['modify_system']) && is_array($pkg_config['modify_system']['item'])) {
$static_output .= gettext("System files... ");
update_output_window($static_output);
foreach($pkg_config['modify_system']['item'] as $ms)
if($ms['textneeded']) remove_text_from_file($ms['modifyfilename'], $ms['textneeded']);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* deinstall commands */
if($pkg_config['custom_php_deinstall_command'] <> "") {
$static_output .= gettext("Deinstall commands... ");
update_output_window($static_output);
if ($missing_include == false) {
eval_once($pkg_config['custom_php_deinstall_command']);
$static_output .= gettext("done.") . "\n";
} else
$static_output .= "\nNot executing custom deinstall hook because an include is missing.\n";
update_output_window($static_output);
}
if($pkg_config['include_file'] <> "") {
$static_output .= gettext("Removing package instructions...");
update_output_window($static_output);
pkg_debug(sprintf(gettext("Remove '%s'"), $pkg_config['include_file']) . "\n");
unlink_if_exists("/usr/local/pkg/" . $pkg_config['include_file']);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* remove all additional files */
if(is_array($pkg_config['additional_files_needed'])) {
$static_output .= gettext("Auxiliary files... ");
update_output_window($static_output);
foreach($pkg_config['additional_files_needed'] as $afn) {
$filename = get_filename_from_url($afn['item'][0]);
if($afn['prefix'] <> "")
$prefix = $afn['prefix'];
else
$prefix = "/usr/local/pkg/";
unlink_if_exists($prefix . $filename);
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* package XML file */
$static_output .= gettext("Package XML... ");
update_output_window($static_output);
unlink_if_exists("/usr/local/pkg/" . $packages[$pkgid]['configurationfile']);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
/* syslog */
if(is_array($pkg_info['logging']) && $pkg_info['logging']['logfile_name'] <> "") {
$static_output .= "Syslog entries... ";
update_output_window($static_output);
remove_text_from_file("/etc/syslog.conf", $pkg_info['logging']['facilityname'] . "\t\t\t\t" . $pkg_info['logging']['logfilename']);
system_syslogd_start();
@unlink("{$g['varlog_path']}/{$pkg_info['logging']['logfilename']}");
$static_output .= "done.\n";
update_output_window($static_output);
}
conf_mount_ro();
/* remove config.xml entries */
$static_output .= gettext("Configuration... ");
update_output_window($static_output);
unset($config['installedpackages']['package'][$pkgid]);
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
write_config("Removed {$pkg} package.\n");
}
function expand_to_bytes($size) {
$conv = array(
"G" => "3",
"M" => "2",
"K" => "1",
"B" => "0"
);
$suffix = substr($size, -1);
if(!in_array($suffix, array_keys($conv))) return $size;
$size = substr($size, 0, -1);
for($i = 0; $i < $conv[$suffix]; $i++) {
$size *= 1024;
}
return $size;
}
function get_pkg_db() {
global $g;
return return_dir_as_array($g['vardb_path'] . '/pkg');
}
function walk_depend($depend, $pkgdb = "", $alreadyseen = "") {
if(!$pkgdb)
$pkgdb = get_pkg_db();
if(!is_array($alreadyseen))
$alreadyseen = array();
if (!is_array($depend))
$depend = array();
foreach($depend as $adepend) {
$pkgname = reverse_strrchr($adepend['name'], '.');
if(in_array($pkgname, $alreadyseen)) {
continue;
} elseif(!in_array($pkgname, $pkgdb)) {
$size += expand_to_bytes($adepend['size']);
$alreadyseen[] = $pkgname;
if(is_array($adepend['depend'])) $size += walk_depend($adepend['depend'], $pkgdb, $alreadyseen);
}
}
return $size;
}
function get_package_install_size($pkg = 'all', $pkg_info = "") {
global $config, $g;
if((!is_array($pkg)) and ($pkg != 'all'))
$pkg = array($pkg);
$pkgdb = get_pkg_db();
if(!$pkg_info)
$pkg_info = get_pkg_sizes($pkg);
foreach($pkg as $apkg) {
if(!$pkg_info[$apkg])
continue;
$toreturn[$apkg] = expand_to_bytes(walk_depend(array($pkg_info[$apkg]), $pkgdb));
}
return $toreturn;
}
function squash_from_bytes($size, $round = "") {
$conv = array(1 => "B", "K", "M", "G");
foreach($conv as $div => $suffix) {
$sizeorig = $size;
if(($size /= 1024) < 1) {
if($round) {
$sizeorig = round($sizeorig, $round);
}
return $sizeorig . $suffix;
}
}
return;
}
function pkg_reinstall_all() {
global $g, $config;
@unlink('/conf/needs_package_sync');
if (is_array($config['installedpackages']['package'])) {
echo gettext("One moment please, reinstalling packages...\n");
echo gettext(" >>> Trying to fetch package info...");
log_error(gettext("Attempting to reinstall all packages"));
$pkg_info = get_pkg_info();
if ($pkg_info) {
echo " Done.\n";
} else {
$xmlrpc_base_url = get_active_xml_rpc_base_url();
$error = 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']);
echo "\n{$error}\n";
log_error(gettext("Cannot reinstall packages: ") . $error);
return;
}
$todo = array();
$all_names = array();
foreach($config['installedpackages']['package'] as $package) {
$todo[] = array('name' => $package['name'], 'version' => $package['version']);
$all_names[] = $package['name'];
}
$package_name_list = gettext("List of packages to reinstall: ") . implode(", ", $all_names);
echo " >>> {$package_name_list}\n";
log_error($package_name_list);
foreach($todo as $pkgtodo) {
$static_output = "";
if($pkgtodo['name']) {
log_error(gettext("Uninstalling package") . " {$pkgtodo['name']}");
uninstall_package($pkgtodo['name']);
log_error(gettext("Finished uninstalling package") . " {$pkgtodo['name']}");
log_error(gettext("Reinstalling package") . " {$pkgtodo['name']}");
install_package($pkgtodo['name']);
log_error(gettext("Finished installing package") . " {$pkgtodo['name']}");
}
}
log_error(gettext("Finished reinstalling all packages."));
} else
echo "No packages are installed.";
}
function stop_packages()
{
require_once("config.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("captiveportal.inc");
require_once("pkg-utils.inc");
require_once("pfsense-utils.inc");
require_once("service-utils.inc");
global $config, $g;
log_error("Stopping all packages.");
$rcfiles = glob(RCFILEPREFIX . "*.sh");
if (!$rcfiles)
$rcfiles = array();
else {
$rcfiles = array_flip($rcfiles);
if (!$rcfiles)
$rcfiles = array();
}
if (is_array($config['installedpackages']['package'])) {
foreach($config['installedpackages']['package'] as $package) {
echo " Stopping package {$package['name']}...";
$internal_name = get_pkg_internal_name($package);
stop_service($internal_name);
unset($rcfiles[RCFILEPREFIX . strtolower($internal_name) . ".sh"]);
echo "done.\n";
}
}
foreach ($rcfiles as $rcfile => $number) {
$shell = @popen("/bin/sh", "w");
if ($shell) {
echo " Stopping {$rcfile}...";
if (!@fwrite($shell, "{$rcfile} stop >>/tmp/bootup_messages 2>&1")) {
if ($shell)
pclose($shell);
$shell = @popen("/bin/sh", "w");
}
echo "done.\n";
pclose($shell);
}
}
}
function package_skip_tests($index,$requested_version){
global $config, $g;
/* Get pfsense version*/
$version = rtrim(file_get_contents("/usr/local/opnsense/version/opnsense"));
if($g['platform'] == "nanobsd")
if($index['noembedded'])
return true;
/* If we are on not on HEAD, and the package wants it, skip */
if ($version <> "HEAD" && $index['required_version'] == "HEAD" && $requested_version <> "other")
return true;
/* If there is no required version, and the requested package version is not 'none', then skip */
if (empty($index['required_version']) && $requested_version <> "none")
return true;
/* If the requested version is not 'other', and the required version is newer than what we have, skip. */
if($requested_version <> "other" && (pfs_version_compare("", $version, $index['required_version']) < 0))
return true;
/* If the requestion version is 'other' and we are on the version requested, skip. */
if($requested_version == "other" && (pfs_version_compare("", $version, $index['required_version']) == 0))
return true;
/* Package is only for an older version, lets skip */
if($index['maximum_version'] && (pfs_version_compare("", $version, $index['maximum_version']) > 0))
return true;
/* Do not skip package list */
return false;
}
function get_pkg_interfaces_select_source($include_localhost=false) {
$interfaces = get_configured_interface_with_descr();
$ssifs = array();
foreach ($interfaces as $iface => $ifacename) {
$tmp["name"] = $ifacename;
$tmp["value"] = $iface;
$ssifs[] = $tmp;
}
if ($include_localhost) {
$tmp["name"] = "Localhost";
$tmp["value"] = "lo0";
$ssifs[] = $tmp;
}
return $ssifs;
}
function verify_all_package_servers() {
return verify_package_server(get_active_xml_rpc_base_url());
}
/* Check if the active package server is a valid default or if it has been
altered. */
function verify_package_server($server) {
/* Define the expected default package server domains. Include
preceding "." to prevent matching from being too liberal. */
$default_package_domains = array('.pfsense.org', '.pfsense.com', '.netgate.com');
/* For this test we only need to check the hostname. */
$xmlrpcbase = parse_url($server, PHP_URL_HOST);
foreach ($default_package_domains as $dom) {
if (substr($xmlrpcbase, -(strlen($dom))) == $dom) {
return true;
}
}
return false;
}
/* Test the package server certificate to ensure that it validates properly */
function check_package_server_ssl() {
global $g;
$xmlrpcurl = get_active_xml_rpc_base_url() . $g['xmlrpcpath'];
/* If the package server is using HTTP, we can't verify SSL */
if (substr($xmlrpcurl, 0, 5) == "http:") {
return "http";
}
/* Setup a basic cURL connection. We do not care about the content of
the result, only the SSL verification. */
$ch = curl_init($xmlrpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '30');
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/usr/local/opnsense/version/opnsense")));
$result_page = curl_exec($ch);
$verifyfail = curl_getinfo($ch, CURLINFO_SSL_VERIFYRESULT);
curl_close($ch);
/* The result from curl is 1 on failure, 0 on success. */
if ($verifyfail == 0)
return true;
else
return false;
}
/* Keep this message centrally since it will be used several times on pages
in the GUI. */
function package_server_ssl_failure_message() {
$msg = "The package server's SSL certificate could not be verified. "
. "The SSL certificate itself may be invalid, its chain of trust may "
. "have failed validation, or the server may have been impersonated. "
. "Downloaded packages may come from an untrusted source. "
. "Proceed with caution.";
return sprintf(gettext($msg), htmlspecialchars(get_active_xml_rpc_base_url()));
}
/* Keep this message centrally since it will be used several times on pages
in the GUI. */
function package_server_mismatch_message() {
$msg = "The package server currently configured on "
. "this firewall (%s) is NOT an official package server. The contents "
. "of such servers cannot be verified and may contain malicious files. "
. "Return the package server settings to their default values to "
. "ensure that verifiable and trusted packages are received.";
return sprintf(gettext($msg), htmlspecialchars(get_active_xml_rpc_base_url())) . '<br/><br/>'
. '<a href="/pkg_mgr_settings.php">' . gettext("Package Manager Settings") . '</a>';
}
function pkg_fetch_config_file($package, $pkg_info = "") {
global $g, $config, $static_output, $pkg_interface;
conf_mount_rw();
if(empty($pkg_info) or !is_array($pkg_info[$package])) {
$pkg_info = get_pkg_info(array($package));
$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
if (empty($pkg_info)) {
conf_mount_ro();
return -1;
}
}
/* fetch the package's configuration file */
if($pkg_info['config_file'] != "") {
$static_output .= "\n" . gettext("Downloading package configuration file... ");
update_output_window($static_output);
pkg_debug(gettext("Downloading package configuration file...") . "\n");
$fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1);
download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto);
if(!file_exists('/usr/local/pkg/' . $fetchto)) {
pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n");
if($pkg_interface == "console")
print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n";
else {
$static_output .= gettext("failed!\n\nInstallation aborted.\n");
update_output_window($static_output);
echo "<br />Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>";
}
conf_mount_ro();
return -1;
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
conf_mount_ro();
return true;
}
function pkg_fetch_additional_files($package, $pkg_info = "") {
global $g, $config, $static_output, $pkg_interface;
conf_mount_rw();
if(empty($pkg_info) or !is_array($pkg_info[$package])) {
$pkg_info = get_pkg_info(array($package));
$pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
if (empty($pkg_info)) {
conf_mount_ro();
return -1;
}
}
$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1);
if(file_exists("/usr/local/pkg/" . $configfile)) {
$static_output .= gettext("Loading package configuration... ");
update_output_window($static_output);
$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $configfile, "packagegui");
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
/* download additional files */
if(is_array($pkg_config['additional_files_needed'])) {
$static_output .= gettext("Additional files... ");
$static_orig = $static_output;
update_output_window($static_output);
foreach($pkg_config['additional_files_needed'] as $afn) {
$filename = get_filename_from_url($afn['item'][0]);
if($afn['chmod'] <> "")
$pkg_chmod = $afn['chmod'];
else
$pkg_chmod = "";
if($afn['prefix'] <> "")
$prefix = $afn['prefix'];
else
$prefix = "/usr/local/pkg/";
if(!is_dir($prefix))
safe_mkdir($prefix);
$static_output .= $filename . " ";
update_output_window($static_output);
if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) {
$static_output .= "failed.\n";
@unlink($prefix . $filename);
update_output_window($static_output);
return false;
}
if(stristr($filename, ".tgz") <> "") {
pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n");
$tarout = "";
exec("/usr/bin/tar xvzf " . escapeshellarg($prefix . $filename) . " -C / 2>&1", $tarout);
pkg_debug(print_r($tarout, true) . "\n");
}
if($pkg_chmod <> "") {
pkg_debug(sprintf(gettext('Changing file mode to %1$s for %2$s%3$s%4$s'), $pkg_chmod, $prefix, $filename, "\n"));
@chmod($prefix . $filename, $pkg_chmod);
system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
}
$static_output = $static_orig;
update_output_window($static_output);
}
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
conf_mount_ro();
return true;
}
}
?>
......@@ -1170,12 +1170,6 @@ $priv_list['page-system-firmware-manualupdate']['descr'] = gettext("Allow access
$priv_list['page-system-firmware-manualupdate']['match'] = array();
$priv_list['page-system-firmware-manualupdate']['match'][] = "system_firmware.php*";
$priv_list['page-system-firmware-checkforupdate'] = array();
$priv_list['page-system-firmware-checkforupdate']['name'] = gettext("WebCfg - System: Firmware: Check For Update page");
$priv_list['page-system-firmware-checkforupdate']['descr'] = gettext("Allow access to the 'System: Firmware: Check For Update' page.");
$priv_list['page-system-firmware-checkforupdate']['match'] = array();
$priv_list['page-system-firmware-checkforupdate']['match'][] = "system_firmware_auto.php*";
$priv_list['page-system-firmware-autoupdate'] = array();
$priv_list['page-system-firmware-autoupdate']['name'] = gettext("WebCfg - System: Firmware: Auto Update page");
$priv_list['page-system-firmware-autoupdate']['descr'] = gettext("Allow access to the 'System: Firmware: Auto Update' page.");
......
......@@ -331,16 +331,6 @@ function services_dhcpdv4_configure()
if (!is_dhcp_server_enabled())
return 0;
/* if OLSRD is enabled, allow WAN to house DHCP. */
if (!function_exists('is_package_installed'))
require_once('pkg-utils.inc');
if (is_package_installed('olsrd') && isset($config['installedpackages']['olsrd']))
foreach($config['installedpackages']['olsrd']['config'] as $olsrd)
if (isset($olsrd['enable']) && $olsrd['enable'] == "on") {
$is_olsr_enabled = true;
break;
}
if (file_exists("/var/run/booting")) {
/* restore the leases, if we have them */
if (file_exists('/conf/dhcpleases.tgz')) {
......@@ -506,10 +496,6 @@ EOPP;
if (!is_ipaddr($subnet))
continue;
if($is_olsr_enabled == true)
if($dhcpifconf['netmask'])
$subnetmask = gen_subnet_mask($dhcpifconf['netmask']);
$all_pools = array();
$all_pools[] = $dhcpifconf;
if (is_array($dhcpifconf['pool'])) {
......@@ -1098,10 +1084,6 @@ EOD;
$ifcfgsnv6 = get_interface_subnetv6($dhcpv6if);
$subnetv6 = gen_subnetv6($ifcfgipv6, $ifcfgsnv6);
if ($is_olsr_enabled == true) {
if($dhcpv6ifconf['netmask'])
$subnetmask = gen_subnet_maskv6($dhcpv6ifconf['netmask']);
}
$dnscfgv6 = "";
......@@ -2294,18 +2276,19 @@ function upnp_action ($action) {
}
}
function upnp_start() {
global $config;
global $config;
if(!isset($config['installedpackages']['miniupnpd']['config']))
return;
if(!isset($config['installedpackages']['miniupnpd']['config']))
return;
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
echo gettext("Starting UPnP service... ");
require_once('/usr/local/pkg/miniupnpd.inc');
sync_package_miniupnpd();
echo "done.\n";
}
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
echo gettext("Starting UPnP service... ");
require_once('/usr/local/pkg/miniupnpd.inc');
sync_package_miniupnpd();
echo "done.\n";
}
}
function install_cron_job($command, $active=false, $minute="0", $hour="*", $monthday="*", $month="*", $weekday="*", $who="root") {
......
......@@ -1701,8 +1701,6 @@ function system_reboot_cleanup() {
}
require_once("voucher.inc");
voucher_save_db_to_config();
require_once("pkg-utils.inc");
stop_packages();
}
function system_console_configure()
......
......@@ -372,18 +372,6 @@ prefer_ipv4_or_ipv6();
if (file_exists("/sbin/shutdown.old"))
@unlink("/sbin/shutdown.old");
/* Resync / Reinstall packages if need be */
if(file_exists('/conf/needs_package_sync')) {
if($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
require_once("pkg-utils.inc");
if($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
mark_subsystem_dirty('packagelock');
pkg_reinstall_all();
clear_subsystem_dirty('packagelock');
}
}
@unlink('/conf/needs_package_sync');
}
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
fail to route syslog messages properly on both IPv4 and IPv6 */
......
#!/usr/local/bin/php
<?php
/*
Copyright (C) 2004 Scott Ullrich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("config.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("captiveportal.inc");
require_once("pkg-utils.inc");
require_once("pfsense-utils.inc");
require_once("service-utils.inc");
log_error("Restarting/Starting all packages.");
$rcfiles = glob(RCFILEPREFIX . "*.sh");
if (!$rcfiles)
$rcfiles = array();
else {
$rcfiles = array_flip($rcfiles);
if (!$rcfiles)
$rcfiles = array();
}
if (is_array($config['installedpackages']['package'])) {
foreach($config['installedpackages']['package'] as $pkgid => $package) {
echo " Starting package {$package['name']}...";
sync_package($pkgid);
$internal_name = get_pkg_internal_name($package);
start_service($internal_name);
unset($rcfiles[RCFILEPREFIX . strtolower($internal_name) . ".sh"]);
echo "done.\n";
}
}
$shell = @popen("/bin/sh", "w");
if ($shell) {
foreach ($rcfiles as $rcfile => $number) {
echo " Starting {$rcfile}...";
fwrite($shell, "{$rcfile} start >>/tmp/bootup_messages 2>&1 &");
echo "done.\n";
}
pclose($shell);
}
#!/usr/local/bin/php
<?php
require_once("pkg-utils.inc");
stop_packages();
......@@ -112,12 +112,7 @@ page-services-ntpd=services_ntpd.php*
page-services-ntp-gps=status_ntpd_gps.php*
page-services-ntp-pps=status_ntpd_pps.php*
page-loadbalancer-virtualserver-edit=load_balancer_virtual_server_edit.php*
page-package-settings=pkg.php*
page-package-edit=pkg_edit.php*
page-system-packagemanager=pkg_mgr.php*
page-system-packagemanager-installpackage=pkg_mgr_install.php*
page-system-packagemanager-installed=pkg_mgr_installed.php*
page-pkg-mgr-settings=pkg_mgr_settings.php*
page-diagnostics-rebootsystem=reboot.php*
page-diagnostics-restart-httpd=restart_httpd.php*
page-services-captiveportal=services_captiveportal.php*
......@@ -196,7 +191,6 @@ page-system-camanager=system_camanager.php*
page-system-certmanager=system_certmanager.php*
page-system-crlmanager=system_crlmanager.php*
page-system-firmware-manualupdate=system_firmware.php*
page-system-firmware-checkforupdate=system_firmware_auto.php*
page-system-firmware-autoupdate=system_firmware_check.php*
page-system-firmware-settings=system_firmware_settings.php*
page-system-gatewaygroups=system_gateway_groups.php*
......
......@@ -46,13 +46,6 @@ parameters:
type:script
message:Starting nptd
[reload|restart.packages]
command:/usr/local/etc/rc.start_packages
parameters:
type:script
message:Starting packages
[reload|restart.sshd]
command:/usr/local/etc/rc.sshd
parameters:
......
......@@ -391,7 +391,6 @@ if ($_POST) {
/* this will be picked up by /index.php */
conf_mount_rw();
mark_subsystem_dirty("restore");
touch("/conf/needs_package_sync");
/* remove cache, we will force a config reboot */
@unlink('/tmp/config.cache');
$config = parse_config(true);
......
......@@ -39,7 +39,6 @@ ob_start(null, "1000");
require_once('functions.inc');
require_once('guiconfig.inc');
require_once('notices.inc');
require_once("pkg-utils.inc");
if(isset($_REQUEST['closenotice'])){
close_notice($_REQUEST['closenotice']);
......@@ -135,23 +134,6 @@ if(file_exists("/usr/sbin/swapinfo")) {
if(stristr($swapinfo,'%') == true) $showswap=true;
}
## User recently restored his config.
## If packages are installed lets resync
if(file_exists('/conf/needs_package_sync')) {
if($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
if($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
header('Location: pkg_mgr_install.php?mode=reinstallall');
exit;
}
} else {
conf_mount_rw();
@unlink('/conf/needs_package_sync');
conf_mount_ro();
}
}
## Find out whether there's hardware encryption or not
unset($hwcrypto);
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
......@@ -461,10 +443,6 @@ echo $jscriptstr;
<div class="row">
<?php
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
/*if (!verify_all_package_servers())
print_info_box(package_server_mismatch_message());*/
if ($savemsg)
print_info_box($savemsg);
......
<?php
/* $Id$ */
/*
pkg.php
Copyright (C) 2004-2012 Scott Ullrich <sullrich@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*
pfSense_MODULE: pkgs
*/
##|+PRIV
##|*IDENT=page-package-settings
##|*NAME=Package: Settings page
##|*DESCR=Allow access to the 'Package: Settings' page.
##|*MATCH=pkg.php*
##|-PRIV
require_once("guiconfig.inc");
require_once("pkg-utils.inc");
function gentitle_pkg($pgname) {
global $config;
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
}
function domTT_title($title_msg){
print "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '".gettext($title_msg)."', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\"";
}
$xml = $_REQUEST['xml'];
if($xml == "") {
print_info_box_np(gettext("ERROR: No package defined."));
exit;
} else {
if(file_exists("/usr/local/pkg/" . $xml))
$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
else {
echo "File not found " . htmlspecialchars($xml);
exit;
}
}
if($pkg['donotsave'] <> "") {
header("Location: pkg_edit.php?xml=" . $xml);
exit;
}
if ($pkg['include_file'] != "") {
require_once($pkg['include_file']);
}
$package_name = $pkg['menu'][0]['name'];
$section = $pkg['menu'][0]['section'];
$config_path = $pkg['configpath'];
$title = $pkg['title'];
if($_REQUEST['startdisplayingat'])
$startdisplayingat = $_REQUEST['startdisplayingat'];
if($_REQUEST['display_maximum_rows'])
if($_REQUEST['display_maximum_rows'])
$display_maximum_rows = $_REQUEST['display_maximum_rows'];
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
if ($_GET['act'] == "update") {
if(is_array($config['installedpackages'][$pkg['name']]) && $pkg['name'] != "" && $_REQUEST['ids'] !=""){
#get current values
$current_values=$config['installedpackages'][$pkg['name']]['config'];
#get updated ids
parse_str($_REQUEST['ids'], $update_list);
#sort ids to know what to change
#usefull to do not loose data when using sorting and paging
$sort_list=$update_list['ids'];
sort($sort_list);
#apply updates
foreach($update_list['ids'] as $key=> $value){
$config['installedpackages'][$pkg['name']]['config'][$sort_list[$key]]=$current_values[$update_list['ids'][$key]];
}
#save current config
write_config();
#sync package
eval ("{$pkg['custom_php_resync_config_command']}");
}
#function called via jquery, no need to continue after save changes.
exit;
}
if ($_GET['act'] == "del") {
// loop through our fieldnames and automatically setup the fieldnames
// in the environment. ie: a fieldname of username with a value of
// testuser would automatically eval $username = "testuser";
foreach ($evaledvar as $ip) {
if($pkg['adddeleteeditpagefields']['columnitem'])
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
}
}
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
if ($a_pkg[$_GET['id']]) {
unset($a_pkg[$_GET['id']]);
write_config();
if($pkg['custom_delete_php_command'] <> "") {
if($pkg['custom_php_command_before_form'] <> "")
eval($pkg['custom_php_command_before_form']);
eval($pkg['custom_delete_php_command']);
}
header("Location: pkg.php?xml=" . $xml);
exit;
}
}
ob_start();
$iflist = get_configured_interface_with_descr(false, true);
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
if($pkg['custom_php_global_functions'] <> "")
eval($pkg['custom_php_global_functions']);
if($pkg['custom_php_command_before_form'] <> "")
eval($pkg['custom_php_command_before_form']);
$pgtitle = array($title);
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<script type="text/javascript" src="javascript/domTT/domLib.js"></script>
<script type="text/javascript" src="javascript/domTT/domTT.js"></script>
<script type="text/javascript" src="javascript/domTT/behaviour.js"></script>
<script type="text/javascript" src="javascript/domTT/fadomatic.js"></script>
<script type="text/javascript">
//<![CDATA[
function setFilter(filtertext) {
jQuery('#pkg_filter').val(filtertext);
document.pkgform.submit();
}
<?php
if($pkg['adddeleteeditpagefields']['movable']){
?>
jQuery(document).ready(function(){
jQuery('#mainarea table tbody').sortable({
items: 'tr.sortable',
cursor: 'move',
distance: 10,
opacity: 0.8,
helper: function(e,ui){
ui.children().each(function(){
jQuery(this).width(jQuery(this).width());
});
return ui;
},
});
});
function save_changes_to_xml(xml) {
var ids=jQuery('#mainarea table tbody').sortable('serialize',{key:"ids[]"});
var strloading="<img src='/themes/<?= $g['theme']; ?>/images/misc/loader.gif' alt='loader' /> " + "<?=gettext('Saving changes...');?>";
if(confirm("<?=gettext("Do you really want to save changes?");?>")){
jQuery.ajax({
type: 'get',
cache: false,
url: "<?=$_SERVER['SCRIPT_NAME'];?>",
data: {xml:'<?=$xml?>', act:'update', ids: ids},
beforeSend: function(){
jQuery('#savemsg').empty().html(strloading);
},
error: function(data){
jQuery('#savemsg').empty().html('Error:' + data);
},
success: function(data){
jQuery('#savemsg').empty().html(data);
}
});
}
}
<?php
}
?>
//]]>
</script>
<form action="pkg.php" name="pkgform" method="get">
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>' />
<?php if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
<div id="savemsg"></div>
<?php if ($savemsg) print_info_box($savemsg); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package settings">
<?php
if ($pkg['tabs'] <> "") {
$tab_array = array();
foreach($pkg['tabs']['tab'] as $tab) {
if($tab['tab_level'])
$tab_level = $tab['tab_level'];
else
$tab_level = 1;
if(isset($tab['active'])) {
$active = true;
} else {
$active = false;
}
if(isset($tab['no_drop_down']))
$no_drop_down = true;
$urltmp = "";
if($tab['url'] <> "") $urltmp = $tab['url'];
if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
$addresswithport = getenv("HTTP_HOST");
$colonpos = strpos($addresswithport, ":");
if ($colonpos !== False) {
//my url is actually just the IP address of the pfsense box
$myurl = substr($addresswithport, 0, $colonpos);
} else {
$myurl = $addresswithport;
}
// eval url so that above $myurl item can be processed if need be.
$url = str_replace('$myurl', $myurl, $urltmp);
$tab_array[$tab_level][] = array(
$tab['text'],
$active,
$url
);
}
ksort($tab_array);
foreach($tab_array as $tab) {
echo '<tr><td>';
display_top_tabs($tab, $no_drop_down);
echo '</td></tr>';
}
}
?>
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
<tr>
<td class="tabcont">
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabs">
<?php
/* Handle filtering bar A-Z */
$include_filtering_inputbox = false;
$colspan = 0;
if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column)
$colspan++;
if($pkg['fields']['field']) {
// First find the sorting type field if it exists
foreach($pkg['fields']['field'] as $field) {
if($field['type'] == "sorting") {
if(isset($field['include_filtering_inputbox']))
$include_filtering_inputbox = true;
if($display_maximum_rows < 1)
if($field['display_maximum_rows'])
$display_maximum_rows = $field['display_maximum_rows'];
echo "<tr><td class='listhdrr' colspan='$colspan' align='center'>";
echo "Filter by: ";
$isfirst = true;
for($char = 65; $char < 91; $char++) {
if(!$isfirst)
echo " | ";
echo "<a href=\"#\" onclick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
$isfirst = false;
}
echo "</td></tr>";
echo "<tr><td class='listhdrr' colspan='$colspan' align='center'>";
if($field['sortablefields']) {
echo "Filter field: <select name='pkg_filter_type'>";
foreach($field['sortablefields']['item'] as $si) {
if($si['name'] == $_REQUEST['pkg_filter_type'])
$SELECTED = "selected=\"selected\"";
else
$SELECTED = "";
echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
}
echo "</select>";
}
if($include_filtering_inputbox)
echo "&nbsp;&nbsp;Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "' /> <input type='submit' value='Filter' />";
echo "</td></tr><tr><td><font size='-3'>&nbsp;</font></td></tr>";
}
}
}
?>
<tr>
<?php
if($display_maximum_rows) {
$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
$page = 1;
$tmpcount = 0;
$tmppp = 0;
if(is_array($evaledvar)) {
foreach ($evaledvar as $ipa) {
if($tmpcount == $display_maximum_rows) {
$page++;
$tmpcount = 0;
}
if($tmppp == $startdisplayingat)
break;
$tmpcount++;
$tmppp++;
}
}
echo "<tr><td colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
echo "<table width='100%' summary=''>";
echo "<tr>";
echo "<td align='left'>Displaying page $page of $totalpages</b></td>";
echo "<td align='right'>Rows per page: <select onchange='document.pkgform.submit();' name='display_maximum_rows'>";
for($x=0; $x<250; $x++) {
if($x == $display_maximum_rows)
$SELECTED = "selected=\"selected\"";
else
$SELECTED = "";
echo "<option value='$x' $SELECTED>$x</option>\n";
$x=$x+4;
}
echo "</select></td></tr>";
echo "</table>";
echo "</td></tr>";
}
$cols = 0;
if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
$cols++;
}
}
echo "</tr>";
$i=0;
$pagination_startingrow=0;
$pagination_counter=0;
if($evaledvar)
foreach ($evaledvar as $ip) {
if($startdisplayingat) {
if($i < $startdisplayingat) {
$i++;
continue;
}
}
if($_REQUEST['pkg_filter']) {
// Handle filterered items
if($pkg['fields']['field'] && !$filter_regex) {
// First find the sorting type field if it exists
foreach($pkg['fields']['field'] as $field) {
if($field['type'] == "sorting") {
if($field['sortablefields']['item']) {
foreach($field['sortablefields']['item'] as $sf) {
if($sf['name'] == $_REQUEST['pkg_filter_type']) {
$filter_fieldname = $sf['fieldname'];
#Use a default regex on sortable fields when none is declared
if($sf['regex'])
$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
else
$filter_regex = "/{$_REQUEST['pkg_filter']}/i";
}
}
}
}
}
}
// Do we have something to filter on?
unset($filter_matches);
if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
if($column['fieldname'] == $filter_fieldname) {
if($filter_regex) {
//echo "$filter_regex - $fieldname<p/>";
preg_match($filter_regex, $fieldname, $filter_matches);
break;
}
}
}
}
if(!$filter_matches) {
$i++;
continue;
}
}
if($pkg['adddeleteeditpagefields']['movable'])
echo "<tr valign=\"top\" class=\"sortable\" id=\"id_{$i}\">\n";
else
echo "<tr valign=\"top\">\n";
if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
if ($column['fieldname'] == "description")
$class = "listbg";
else
$class = "listlr";
?>
<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&amp;act=edit&amp;id=<?=$i;?>';">
<?php
$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
#Check if columnitem has a type field declared
if($column['type'] == "checkbox") {
if($fieldname == "") {
echo gettext("No");
} else {
echo gettext("Yes");
}
} else if ($column['type'] == "interface") {
echo $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
} else {
#Check if columnitem has an encoding field declared
if ($column['encoding'] == "base64")
echo $column['prefix'] . base64_decode($fieldname) . $column['suffix'];
#Check if there is a custom info to show when $fieldname is not empty
else if($column['listmodeon'] && $fieldname != "")
echo $column['prefix'] . gettext($column['listmodeon']). $column['suffix'];
#Check if there is a custom info to show when $fieldname is empty
else if($column['listmodeoff'] && $fieldname == "")
echo $column['prefix'] .gettext($column['listmodeoff']). $column['suffix'];
else
echo $column['prefix'] . $fieldname ." ". $column['suffix'];
}
?>
</td>
<?php
}
?>
<td valign="middle" class="list nowrap">
<table border="0" cellspacing="0" cellpadding="1" summary="icons">
<tr>
<?php
#Show custom description to edit button if defined
$edit_msg=($pkg['adddeleteeditpagefields']['edittext']?$pkg['adddeleteeditpagefields']['edittext']:"Edit this item");?>
<td valign="middle"><a href="pkg_edit.php?xml=<?=$xml?>&amp;act=edit&amp;id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" <?=domTT_title($edit_msg)?> alt="edit" /></a></td>
<?php
#Show custom description to delete button if defined
$delete_msg=($pkg['adddeleteeditpagefields']['deletetext']?$pkg['adddeleteeditpagefields']['deletetext']:"Delete this item");?>
<td valign="middle"><a href="pkg.php?xml=<?=$xml?>&amp;act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this item?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" <?=domTT_title($delete_msg)?> alt="delete" /></a></td>
</tr>
</table>
</td>
<?php
echo "</tr>\n";
// Handle pagination and display_maximum_rows
if($display_maximum_rows) {
if($pagination_counter == ($display_maximum_rows-1) or
$i == (count($evaledvar)-1)) {
$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
$final_footer = "";
$final_footer .= "<tr><td colspan='$colcount'>";
$final_footer .= "<table width='100%' summary=''><tr>";
$final_footer .= "<td align='left'>";
$startingat = $startdisplayingat - $display_maximum_rows;
if($startingat > -1) {
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat={$startingat}&amp;display_maximum_rows={$display_maximum_rows}'>";
} else {
if($startingnat > 1)
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat=0&amp;display_maximum_rows={$display_maximum_rows}'>";
}
$final_footer .= "<font size='2'><< Previous page</font></a>";
if($tmppp + $display_maximum_rows > count($evaledvar))
$endingrecord = count($evaledvar);
else
$endingrecord = $tmppp + $display_maximum_rows;
$final_footer .= "</td><td align='center'>";
$tmppp++;
$final_footer .= "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
$final_footer .= "</font></td><td align='right'>&nbsp;";
if(($i+1) < count($evaledvar))
$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&amp;display_maximum_rows={$display_maximum_rows}'>";
$final_footer .= "<font size='2'>Next page >></font></a>";
$final_footer .= "</td></tr></table></td></tr>";
$i = count($evaledvar);
break;
}
}
$i++;
$pagination_counter++;
}
?>
<tr>
<td colspan="<?=$cols?>"></td>
<td>
<table border="0" cellspacing="0" cellpadding="1" summary="icons">
<tr>
<?php
#Show custom description to add button if defined
$add_msg=($pkg['adddeleteeditpagefields']['addtext']?$pkg['adddeleteeditpagefields']['addtext']:"Add a new item");?>
<td valign="middle"><a href="pkg_edit.php?xml=<?=$xml?>&amp;id=<?=$i?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=domTT_title($add_msg)?> alt="add" /></a></td>
<?php
#Show description button and info if defined
if($pkg['adddeleteeditpagefields']['description']){?>
<td valign="middle"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_info_pkg.gif" width="17" height="17" border="0" <?=domTT_title($pkg['adddeleteeditpagefields']['description'])?> alt="info" /></td>
<?php }?>
</tr>
</table>
</td>
</tr>
<?=$final_footer?>
<?php
#Show save button only when movable is defined
if($pkg['adddeleteeditpagefields']['movable']){?>
<tr><td><input class="formbtn" type="button" value="Save" name="Submit" onclick="save_changes_to_xml('<?=$xml?>')" /></td></tr>
<?php }?>
</table>
</td>
</tr>
</table>
</div></td></tr></table>
</form>
<?php include("fend.inc"); ?>
<?php
echo "<!-- filter_fieldname: {$filter_fieldname} -->";
echo "<!-- filter_regex: {$filter_regex} -->";
?>
</body>
</html>
......@@ -32,7 +32,22 @@ require("guiconfig.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("pkg-utils.inc");
function get_pkg_interfaces_select_source($include_localhost=false) {
$interfaces = get_configured_interface_with_descr();
$ssifs = array();
foreach ($interfaces as $iface => $ifacename) {
$tmp["name"] = $ifacename;
$tmp["value"] = $iface;
$ssifs[] = $tmp;
}
if ($include_localhost) {
$tmp["name"] = "Localhost";
$tmp["value"] = "lo0";
$ssifs[] = $tmp;
}
return $ssifs;
}
/* dummy stubs needed by some code that was MFC'd */
function pfSenseHeader($location) { header("Location: " . $location); }
......
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004-2012 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2013 Marcello Coutinho
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* We will probably remove the current packagemanager entirely, for now it has been updated but its not in use */
ini_set('max_execution_time', '0');
require_once("globals.inc");
require_once("guiconfig.inc");
require_once("pkg-utils.inc");
$timezone = $config['system']['timezone'];
if (!$timezone)
$timezone = "Etc/UTC";
date_default_timezone_set($timezone);
/* if upgrade in progress, alert user */
if(is_subsystem_dirty('packagelock')) {
$pgtitle = array(gettext("System"),gettext("Package Manager"));
include("head.inc");
echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
include("fbegin.inc");
echo "Please wait while packages are reinstalled in the background.";
include("fend.inc");
echo "</body>";
echo "</html>";
exit;
}
//get_pkg_info only if cache file has more then $g[min_pkg_cache_file_time] seconds
$pkg_cache_file_time=($g['min_pkg_cache_file_time'] ? $g['min_pkg_cache_file_time'] : 120);
$xmlrpc_base_url = get_active_xml_rpc_base_url();
if (!file_exists('/tmp/pkg_info.cache') || (time() - filemtime('/tmp/pkg_info.cache')) > $pkg_cache_file_time) {
$pkg_info = get_pkg_info('all', array("noembedded", "name", "category", "website", "version", "status", "descr", "maintainer", "required_version", "maximum_version", "pkginfolink", "config_file"));
//create cache file after get_pkg_info
if($pkg_info) {
$fout = fopen('/tmp/pkg_info.cache', 'w');
fwrite($fout, serialize($pkg_info));
fclose($fout);
//$pkg_sizes = get_pkg_sizes();
} else {
$using_cache = true;
if (file_exists('/tmp/pkg_info.cache')) {
$savemsg = sprintf(gettext("Unable to retrieve package info from %s. Cached data will be used."), $xmlrpc_base_url);
$pkg_info = unserialize(@file_get_contents('/tmp/pkg_info.cache'));
} else {
$savemsg = 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']);
}
}
} else {
$pkg_info = unserialize(@file_get_contents('/tmp/pkg_info.cache'));
}
if (! empty($_GET))
if (isset($_GET['ver']))
$requested_version = htmlspecialchars($_GET['ver']);
$closehead = false;
$pgtitle = array(gettext("System"),gettext("Package Manager"));
include("head.inc");
?>
<body>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(){setTimeout(function(){jQuery('[data-toggle="tooltip"]').tooltip();jQuery('[data-toggle="popover"]').popover({trigger:"hover"});},500);});
//]]>
</script>
<?php
include("fbegin.inc");
?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
/*if (!verify_all_package_servers())
print_info_box(package_server_mismatch_message());*/
/* Print package server SSL warning. See https://redmine.pfsense.org/issues/484 */
if (check_package_server_ssl() === false)
print_info_box(package_server_ssl_failure_message());
if ($savemsg)
print_info_box($savemsg);
?>
<section class="col-xs-12">
<?php
$version = rtrim(file_get_contents("/usr/local/opnsense/version/opnsense"));
$tab_array = array();
$tab_array[] = array(gettext("Available Packages"), $requested_version <> "" ? false : true, "pkg_mgr.php");
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
<div class="container-fluid">
<?php
$version = rtrim(file_get_contents("/usr/local/opnsense/version/opnsense"));
if($pkg_info) {
$pkg_keys = array_keys($pkg_info);
natcasesort($pkg_keys);
//Check categories
$categories=array();
if(is_array($pkg_keys)) {
foreach($pkg_keys as $key) {
if (!package_skip_tests($pkg_info[$key],$requested_version))
$categories[$pkg_info[$key]['category']]++;
}
}
ksort($categories);
$cm_count=0;
$tab_array = array();
$visible_categories=array();
$categories_min_count=($g['pkg_categories_min_count'] ? $g['pkg_categories_min_count'] : 3);
$categories_max_display=($g['pkg_categories_max_display'] ? $g['pkg_categories_max_display'] : 6);
/* check selected category or define default category to show */
if (isset($_REQUEST['category']))
$menu_category = $_REQUEST['category'];
else if (isset($g['pkg_default_category']))
$menu_category = $g['pkg_default_category'];
else
$menu_category = "All";
$menu_category = (isset($_REQUEST['category']) ? $_REQUEST['category'] : "All");
$show_category = ($menu_category == "Other" || $menu_category == "All");
$tab_array[] = array(gettext("All"), $menu_category=="All" ? true : false, "pkg_mgr.php?category=All");
foreach ($categories as $category => $c_count) {
if ($c_count >= $categories_min_count && $cm_count <= $categories_max_display) {
$tab_array[] = array(gettext($category) , $menu_category==$category ? true : false, "pkg_mgr.php?category={$category}");
$visible_categories[]=$category;
$cm_count++;
}
}
$tab_array[] = array(gettext("Other Categories"), $menu_category=="Other" ? true : false, "pkg_mgr.php?category=Other");
}
?>
<? if (count($categories) > 0): ?>
<ul class="nav nav-pills" role="tablist"><? foreach ($tab_array as $tab): ?>
<li role="presentation" <? if ($tab[1]):?>class="active"<? endif; ?>><a href="<?=$tab[2];?>"><?=$tab[0];?></a></li>
<? endforeach; ?></ul><br />
<? endif; ?>
</div>
<div class="table-responsive">
<table class="table table-striped table-sort">
<thead>
<tr>
<th width="10%"><?=gettext("Name"); ?></th>
<?php
if ($show_category)
print '<th width="18%">'.gettext("Category").'</th>'."\n";
?>
<th width="<?php print $show_category ? "15%" : "20%"; ?>" class="listhdr"><?=gettext("Status"); ?></th>
<th width="<?php print $show_category ? "58%" : "70%"; ?>" class="listhdr"><?=gettext("Description"); ?></th>
<th width="17">&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
if(!$pkg_info) {
echo "<tr><td colspan=\"5\"><center>" . gettext("There are currently no packages available for installation.") . "</td></tr>";
} else {
if(is_array($pkg_keys)) {
foreach($pkg_keys as $key):
$index = &$pkg_info[$key];
if(get_pkg_id($index['name']) >= 0 )
continue;
if (package_skip_tests($index,$requested_version))
continue;
/* get history/changelog git dir */
$commit_dir=explode("/",$index['config_file']);
$changeloglink = "https://github.com/opsense/packages/commits/master/config/";
if ($commit_dir[(count($commit_dir)-2)] == "config")
$changeloglink .= $commit_dir[(count($commit_dir)-1)];
else
$changeloglink .= $commit_dir[(count($commit_dir)-2)];
/* Check package info link */
if($index['pkginfolink']) {
$pkginfolink = $index['pkginfolink'];
$pkginfo=gettext("Package info");
} else {
$pkginfolink = "http://forum.opsense.org/index.php";
$pkginfo=gettext("No package info, check the forum");
}
if ($menu_category == "All" || $index['category'] == $menu_category || ($menu_category == "Other" && !in_array($index['category'],$visible_categories)) ):
?>
<tr valign="top" class="<?= $index['category'] ?>">
<td class="listlr">
<a target="_blank" href="<?= $index['website'] ?>" data-toggle="tooltip" data-placement="left" title="<?=gettext("Click on package name to access its website.")?>"><?= $index['name'] ?></a>
</td>
<?php
if ($show_category)
print '<td class="listr">'.gettext($index['category']).'</td>'."\n";
if ($g['disablepackagehistory']) {
print '<td class="listr">'."\n";
} else {
print '<td class="listr" data-container="body" data-toggle="tooltip" data-placement="left" title="'.gettext("Click ").ucfirst($index['name']).gettext(" version to check its change log.").'" ';
print ">\n";
}
print "{$index['status']} <br />\n";
if ($g['disablepackagehistory'])
echo"<a>{$index['version']}</a>";
else
echo "<a target='_blank' href='{$changeloglink}'>{$index['version']}</a>";
?>
<br />
<?=gettext("platform") .": ". $index['required_version'] ?>
<br />
<?=$index['maximum_version'] ?>
</td>
<td class="listbg" style="overflow:hidden; text-align:justify;" data-container="body" data-toggle="tooltip" data-placement="left" title="<?=gettext("Click package info for more details about ".ucfirst($index['name'])." package.")?>">
<?= $index['descr'] ?>
<?php
if (! $g['disablepackageinfo']):
?>
<br /><br />
<a target='_blank' href='<?=$pkginfolink?>' style='align:center;'><?=$pkginfo?></a>
<?php
endif;
?>
</td>
<td valign="middle" class="list nowrap" width="17">
<a href="pkg_mgr_install.php?id=<?=$index['name'];?>" title="<?php echo gettext("Install ".ucfirst($index['name'])." package.")?>" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></a>
</td></tr>
<?php
endif;
endforeach;
} else {
echo "<tr><td colspan='5' align='center'>" . gettext("There are currently no packages available for installation.") . "</td></tr>";
} /* if(is_array($pkg_keys)) */
} /* if(!$pkg_info) */
?>
</tbody>
</table>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2005 Colin Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
ini_set('max_execution_time', '0');
require("guiconfig.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("pkg-utils.inc");
global $static_output;
$static_output = "";
$static_status = "";
$sendto = "output";
$pgtitle = array(gettext("System"),gettext("Package Manager"),gettext("Install Package"));
include("head.inc");
if ($_POST) {
if (isset($_POST['pkgcancel']) || (empty($_POST['id']) && $_POST['mode'] != 'reinstallall')) {
header("Location: pkg_mgr_installed.php");
return;
}
} else if ($_GET) {
switch ($_GET['mode']) {
case 'reinstallall':
case 'showlog':
break;
case 'installedinfo':
case 'reinstallxml':
case 'reinstallpkg':
case 'delete':
if (empty($_GET['pkg'])) {
header("Location: pkg_mgr_installed.php");
return;
}
break;
default:
if (empty($_GET['id'])) {
header("Location: pkg_mgr_installed.php");
return;
}
break;
}
}
?>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
/*if (!verify_all_package_servers())
print_info_box(package_server_mismatch_message());*/
/* Print package server SSL warning. See https://redmine.pfsense.org/issues/484 */
if (check_package_server_ssl() === false)
print_info_box(package_server_ssl_failure_message()); ?>
<section class="col-xs-12">
<?php
$tab_array = array();
$tab_array[] = array(gettext("Available packages"), false, "pkg_mgr.php");
$tab_array[] = array(gettext("Installed packages"), false, "pkg_mgr_installed.php");
$tab_array[] = array(gettext("Package Installer"), true, "");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
<div class="container-fluid">
<form action="pkg_mgr_install.php" method="post" name="iform">
<div class="table-responsive">
<table class="table table-striped table-sort">
<?php if ((empty($_GET['mode']) && $_GET['id']) || (!empty($_GET['mode']) && (!empty($_GET['pkg']) || $_GET['mode'] == 'reinstallall') && ($_GET['mode'] != 'installedinfo' && $_GET['mode'] != 'showlog'))):
if (empty($_GET['mode']) && $_GET['id']) {
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['id'], ENT_QUOTES | ENT_HTML401));
$pkgmode = 'installed';
} else if (!empty($_GET['mode']) && !empty($_GET['pkg'])) {
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
$pkgmode = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['mode'], ENT_QUOTES | ENT_HTML401));
} else if ($_GET['mode'] == 'reinstallall') {
$pkgmode = 'reinstallall';
}
switch ($pkgmode) {
case 'reinstallall':
$pkgname = 'All packages';
$pkgtxt = 'reinstalled';
break;
case 'reinstallxml':
case 'reinstallpkg':
$pkgtxt = 'reinstalled';
break;
case 'delete':
$pkgtxt = 'deleted';
break;
default:
$pkgtxt = $pkgmode;
break;
}
?>
<tr>
<td class="tabcont" align="center">
<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
<tr>
<td class="tabcont" align="center">Package: <b><?=$pkgname;?></b> will be <?=$pkgtxt;?>.<br/>
Please confirm the action.<br/>
</td>
<td class="tabcont" align="center">
<input type="hidden" name="id" value="<?=$pkgname;?>" />
<input type="hidden" name="mode" value="<?=$pkgmode;?>" />
<input type="submit" name="pkgconfirm" id="pkgconfirm" value="Confirm" class="btn btn-primary"/>
<input type="submit" name="pkgcancel" id="pkgcancel" value="Cancel" class="btn btn-default"/>
</td>
</tr>
</table>
</td>
</tr>
<?php endif; if (!empty($_POST['id']) || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))): ?>
<tr>
<td class="tabcont" align="center">
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 5%;">
<span class="sr-only">5% Complete</span>
</div>
</div>
<br />
<!-- status box -->
<textarea cols="80" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning package installation.");?></textarea>
<br />
<!-- command output box -->
<textarea cols="80" rows="35" name="output" id="output" wrap="hard"></textarea>
</td>
</tr>
<?php endif; ?>
</table>
</div>
</form>
</div>
</div>
</section>
</div>
</div>
</section>
<?php
ob_flush();
if ($_GET) {
$pkgname = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_GET['pkg'], ENT_QUOTES | ENT_HTML401));
switch($_GET['mode']) {
case 'showlog':
if (strpos($pkgname, ".")) {
update_output_window(gettext("Something is wrong on the request."));
} else if (file_exists("/tmp/pkg_mgr_{$pkgname}.log"))
update_output_window(@file_get_contents("/tmp/pkg_mgr_{$pkgname}.log"));
else
update_output_window(gettext("Log was not retrievable."));
break;
case 'installedinfo':
if (file_exists("/tmp/{$pkgname}.info")) {
$status = @file_get_contents("/tmp/{$pkgname}.info");
update_status("{$pkgname} " . gettext("installation completed."));
update_output_window($status);
} else
update_output_window(sprintf(gettext("Could not find %s."), $pkgname));
break;
default:
break;
}
} else if ($_POST) {
$pkgid = str_replace(array("<", ">", ";", "&", "'", '"', '.', '/'), "", htmlspecialchars_decode($_POST['id'], ENT_QUOTES | ENT_HTML401));
/* All other cases make changes, so mount rw fs */
conf_mount_rw();
/* Write out configuration to create a backup prior to pkg install. */
write_config(gettext("Creating restore point before package installation."));
switch ($_POST['mode']) {
case 'delete':
uninstall_package($pkgid);
update_status(gettext("Package deleted."));
$static_output .= "\n" . gettext("Package deleted.");
update_output_window($static_output);
filter_configure();
break;
case 'reinstallxml':
pkg_fetch_config_file($pkgid);
pkg_fetch_additional_files($pkgid);
case 'reinstallpkg':
delete_package_xml($pkgid);
if (install_package($pkgid) < 0) {
update_status(gettext("Package reinstallation failed."));
$static_output .= "\n" . gettext("Package reinstallation failed.");
update_output_window($static_output);
} else {
update_status(gettext("Package reinstalled."));
$static_output .= "\n" . gettext("Package reinstalled.");
update_output_window($static_output);
filter_configure();
}
@file_put_contents("/tmp/{$pkgid}.info", $static_output);
$pkgid = htmlspecialchars($pkgid);
echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
break;
case 'reinstallall':
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['package'])) {
$todo = array();
foreach($config['installedpackages']['package'] as $package)
$todo[] = array('name' => $package['name'], 'version' => $package['version']);
foreach($todo as $pkgtodo) {
$static_output = "";
if($pkgtodo['name']) {
update_output_window($static_output);
uninstall_package($pkgtodo['name']);
install_package($pkgtodo['name']);
}
}
update_status(gettext("All packages reinstalled."));
$static_output .= "\n" . gettext("All packages reinstalled.");
update_output_window($static_output);
filter_configure();
} else
update_output_window(gettext("No packages are installed."));
break;
case 'installed':
default:
$status = install_package($pkgid);
if($status == -1) {
update_status(gettext("Installation of") . " {$pkgid} " . gettext("FAILED!"));
$static_output .= "\n" . gettext("Installation halted.");
update_output_window($static_output);
} else {
$status_a = gettext(sprintf("Installation of %s completed.", $pkgid));
update_status($status_a);
$status = get_after_install_info($pkgid);
if($status)
$static_output .= "\n" . gettext("Installation completed.") . "\n{$pkgid} " . gettext("setup instructions") . ":\n{$status}";
else
$static_output .= "\n" . gettext("Installation completed. Please check to make sure that the package is configured from the respective menu then start the package.");
@file_put_contents("/tmp/{$pkgid}.info", $static_output);
echo "<script type='text/javascript'>document.location=\"pkg_mgr_install.php?mode=installedinfo&pkg={$pkgid}\";</script>";
}
filter_configure();
break;
}
// Delete all temporary package tarballs and staging areas.
unlink_if_exists("/tmp/apkg_*");
rmdir_recursive("/var/tmp/instmp*");
// close log
if($fd_log)
fclose($fd_log);
/* Restore to read only fs */
conf_mount_ro();
}
?>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004-2012 Scott Ullrich <sullrich@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("pkg-utils.inc");
$timezone = $config['system']['timezone'];
if (!$timezone)
$timezone = "Etc/UTC";
date_default_timezone_set($timezone);
/* if upgrade in progress, alert user */
if(is_subsystem_dirty('packagelock')) {
$pgtitle = array(gettext("System"),gettext("Package Manager"));
include("head.inc");
echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
include("fbegin.inc");
echo "Please wait while packages are reinstalled in the background.";
include("fend.inc");
echo "</body>";
echo "</html>";
exit;
}
function domTT_title($title_msg, $return="echo"){
if (!empty($title_msg)){
$title_msg=preg_replace("/\s+/"," ",$title_msg);
$title_msg=preg_replace("/'/","\'",$title_msg);
$title= "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '{$title_msg}', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\"";
if ($return =="echo")
echo $title;
else
return $title;
}
}
if(is_array($config['installedpackages']['package'])) {
foreach($config['installedpackages']['package'] as $instpkg) {
$tocheck[] = $instpkg['name'];
}
$currentvers = get_pkg_info($tocheck, array('version', 'xmlver', 'pkginfolink','descr'));
}
$closehead = false;
$pgtitle = array(gettext("System"),gettext("Package Manager"));
include("head.inc");
?>
<script type="text/javascript" src="javascript/domTT/domLib.js"></script>
<script type="text/javascript" src="javascript/domTT/domTT.js"></script>
<script type="text/javascript" src="javascript/domTT/behaviour.js"></script>
<script type="text/javascript" src="javascript/domTT/fadomatic.js"></script>
<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
</head>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
/*if (!verify_all_package_servers())
print_info_box(package_server_mismatch_message());*/
/* Print package server SSL warning. See https://redmine.pfsense.org/issues/484 */
if (check_package_server_ssl() === false)
print_info_box(package_server_ssl_failure_message()); ?>
<section class="col-xs-12">
<?php
$version = file_get_contents("/usr/local/opnsense/version/opnsense");
$tab_array = array();
$tab_array[] = array(gettext("Available Packages"), false, "pkg_mgr.php");
// $tab_array[] = array("{$version} " . gettext("packages"), false, "pkg_mgr.php");
// $tab_array[] = array("Packages for any platform", false, "pkg_mgr.php?ver=none");
// $tab_array[] = array("Packages for a different platform", $requested_version == "other" ? true : false, "pkg_mgr.php?ver=other");
$tab_array[] = array(gettext("Installed Packages"), true, "pkg_mgr_installed.php");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
<div class="table-responsive">
<table class="table table-striped table-sort">
<tr>
<td class="listhdrr"><?=gettext("Name"); ?></td>
<td class="listhdrr"><?=gettext("Category"); ?></td>
<td class="listhdrr"><?=gettext("Version"); ?></td>
<td class="listhdr"><?=gettext("Description"); ?></td>
<td width="120">&nbsp;</td>
</tr>
<?php
if(is_array($config['installedpackages']['package'])):
$instpkgs = array();
foreach($config['installedpackages']['package'] as $instpkg) {
$instpkgs[] = $instpkg['name'];
}
natcasesort($instpkgs);
foreach ($instpkgs as $index => $pkgname):
$pkg = $config['installedpackages']['package'][$index];
if(!$pkg['name'])
continue;
// get history/changelog git dir
$commit_dir=explode("/",$pkg['config_file']);
$changeloglink ="https://github.com/opsense/packages/commits/master/config/".$commit_dir[(count($commit_dir)-2)];
#check package version
$latest_package = $currentvers[$pkg['name']]['version'];
if ($latest_package) {
// we're running a newer version of the package
if(strcmp($pkg['version'], $latest_package) > 0) {
$tdclass = "listbggrey";
if ($g['disablepackagehistory'])
$pkgver = "<a>".gettext("Available") .": ". $latest_package . "<br />";
else
$pkgver = "<a target='_blank' href='$changeloglink'>".gettext("Available") .": ". $latest_package . "<br />";
$pkgver .= gettext("Installed") .": ". $pkg['version']. "</a>";
}
// we're running an older version of the package
if(strcmp($pkg['version'], $latest_package) < 0) {
$tdclass = "listbg";
if ($g['disablepackagehistory'])
$pkgver = "<a><font color='#ffffff'>" . gettext("Available") .": ". $latest_package . "</font><br />";
else
$pkgver = "<a target='_blank' href='$changeloglink'><font color='#ffffff'>" . gettext("Available") .": ". $latest_package . "<br />";
$pkgver .= gettext("Installed") .": ". $pkg['version']."</font></a>";
}
// we're running the current version
if(!strcmp($pkg['version'], $latest_package)) {
$tdclass = "listr";
if ($g['disablepackagehistory'])
$pkgver = "<a>{$pkg['version']}</a>";
else
$pkgver = "<a target='_blank' href='$changeloglink'>{$pkg['version']}</a>";
}
} else {
// unknown available package version
$pkgver = "";
if(!strcmp($pkg['version'], $latest_package)) {
$tdclass = "listr";
if ($g['disablepackagehistory'])
$pkgver = "<a>{$pkg['version']}</a>";
else
$pkgver = "<a target='_blank' href='$changeloglink'>{$pkg['version']}</a>";
}
}
/* Check package info link */
if($pkg['pkginfolink']){
$pkginfolink = $pkg['pkginfolink'];
$pkginfo=gettext("Package info");
}
else{
$pkginfolink = "http://forum.opnsense.org/index.php";
$pkginfo=gettext("No package info, check the forum");
}
?>
<tr valign="top">
<td class="listlr">
<?=$pkg['name'];?>
</td>
<td class="listr">
<?=$pkg['category'];?>
</td>
<?php
if (isset($g['disablepackagehistory']))
echo "<td class='{$tdclass}'>{$pkgver}</td>";
else
echo "<td class='{$tdclass}' ".domTT_title(gettext("Click on ".ucfirst($pkg['name'])." version to check its change log."),"return").">{$pkgver}</td>";
?>
<td class="listbg" style="overflow:hidden; text-align:justify;" <?=domTT_title(gettext("Click package info for more details about ".ucfirst($pkg['name'])." package."))?>><?=$currentvers[$pkg['name']]['descr'];?><?php if (! $g['disablepackageinfo']): ?><br /><br />
<a target='_blank' href='<?=$pkginfolink?>' style='align:center;color:#ffffff; filter:Glow(color=#ff0000, strength=12);'><?=$pkginfo?></a>
<?php endif; ?>
</td>
<td valign="middle" class="list nowrap" width="120">
<a href="pkg_mgr_install.php?mode=delete&amp;pkg=<?= $pkg['name']; ?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</a>
<a href="pkg_mgr_install.php?mode=reinstallpkg&amp;pkg=<?= $pkg['name']; ?>" title="<?=gettext("Reinstall ".ucfirst($pkg['name'])." package.");?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-repeat"></span>
</a>
<a href="pkg_mgr_install.php?mode=reinstallxml&amp;pkg=<?= $pkg['name']; ?>" title="<?=gettext("Reinstall ".ucfirst($pkg['name'])."'s GUI components.");?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-refresh"></span>
</a>
</td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="5" align="center">
<?=gettext("There are no packages currently installed."); ?>
</td>
</tr>
<?php endif; ?>
</table>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2009 Jim Pingle <jimp@pfsense.org>
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2005 Colin Smith
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
ini_set('max_execution_time', '0');
require_once("globals.inc");
require_once("guiconfig.inc");
require_once("pkg-utils.inc");
if ($_POST) {
if (!$input_errors) {
if($_POST['alturlenable'] == "yes") {
$config['system']['altpkgrepo']['enable'] = true;
$config['system']['altpkgrepo']['xmlrpcbaseurl'] = $_POST['pkgrepourl'];
} else {
unset($config['system']['altpkgrepo']['enable']);
}
write_config();
}
}
$curcfg = $config['system']['altpkgrepo'];
$closehead = false;
$pgtitle = array(gettext("System"),gettext("Package Settings"));
include("head.inc");
?>
<script type="text/javascript">
//<![CDATA[
function enable_altpkgrepourl(enable_over) {
if (document.iform.alturlenable.checked || enable_over) {
document.iform.pkgrepourl.disabled = 0;
} else {
document.iform.pkgrepourl.disabled = 1;
}
}
//]]>
</script>
</head>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc");
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
/*if (!verify_all_package_servers())
print_info_box(package_server_mismatch_message());*/
/* Print package server SSL warning. See https://redmine.pfsense.org/issues/484 */
if (check_package_server_ssl() === false)
print_info_box(package_server_ssl_failure_message()); ?>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<form action="pkg_mgr_settings.php" method="post" name="iform" id="iform">
<?php if ($savemsg) print_info_box($savemsg); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package manager settings">
<tr>
<td>
<?php
$version = file_get_contents("/usr/local/opnsense/version/opnsense");
$tab_array = array();
$tab_array[] = array(sprintf(gettext("%s packages"), $version), false, "pkg_mgr.php");
$tab_array[] = array(gettext("Installed Packages"), false, "pkg_mgr_installed.php");
$tab_array[] = array(gettext("Package Settings"), true, "pkg_mgr_settings.php");
display_top_tabs($tab_array);
?>
</td>
</tr>
<tr><td><div id="mainarea">
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
<tr>
<td colspan="2" valign="top" class="vncell">
<?PHP echo gettext("This page allows an alternate package repository to be configured, primarily for temporary use as a testing mechanism."); ?>
<?PHP echo gettext("The contents of unofficial packages servers cannot be verified and may contain malicious files."); ?>
<?PHP echo gettext("The package server settings should remain at their default values to ensure that verifiable and trusted packages are recevied."); ?>
<br/><br/>
<?PHP echo gettext("A warning is printed on the Dashboard and in the package manager when an unofficial package server is in use."); ?>
<br/><br/>
</td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("Package Repository URL");?></td>
</tr>
<tr>
<td valign="top" class="vncell"><?=gettext("Package Repository URL");?></td>
<td class="vtable">
<input name="alturlenable" type="checkbox" id="alturlenable" value="yes" onclick="enable_altpkgrepourl()" <?php if(isset($curcfg['enable'])) echo "checked=\"checked\""; ?> /> <?=gettext("Use a non-official server for packages");?> <br />
<table summary="alternative URL">
<tr><td><?=gettext("Base URL:");?></td><td><input name="pkgrepourl" type="text" class="formfld url" id="pkgrepourl" size="64" value="<?php if($curcfg['xmlrpcbaseurl']) echo $curcfg['xmlrpcbaseurl']; else echo $g['']; ?>" /></td></tr>
</table>
<span class="vexpl">
<?php printf(gettext("This is where %s will check for packages when the"),$g['product_name']);?>, <a href="pkg_mgr.php"><?=gettext("System: Packages");?></a> <?=gettext("page is viewed.");?>
</span>
</td>
</tr>
<script type="text/javascript">
//<![CDATA[
enable_altpkgrepourl();
//]]>
</script>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
</td>
</tr>
</table></div></td></tr></table>
</form>
<?php include("fend.inc"); ?>
</body>
</html>
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005, 2008 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2003-2004 Manuel Kasper
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
$nocsrf = true;
require_once('guiconfig.inc');
require_once('pfsense-utils.inc');
$curcfg = $config['system']['firmware'];
if(isset($curcfg['alturl']['enable']))
$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
else
$updater_url = $g['update_url'];
if($_POST['backupbeforeupgrade'])
touch("/tmp/perform_full_backup.txt");
$closehead = false;
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
<!-- row -->
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
if ($input_errors) print_input_errors($input_errors);
if ($savemsg) print_info_box($savemsg);
?>
<section class="col-xs-12">
<? include('system_firmware_tabs.php'); ?>
<div class="content-box tab-content">
<form action="system_firmware_auto.php" method="post">
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="outer">
<tr>
<td class="tabcont">
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="inner">
<tr>
<td align="center">
<table width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
<tr>
<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5"> </td>
<td>
<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="">
<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
<img src="./themes/<?=$g['theme'];?>/images/misc/bar_blue.gif" width="0" height="15" name="progressbar" id="progressbar" alt="" />
</td></tr>
</table>
</td>
<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5"></td>
</tr>
</table>
<br />
<script type="text/javascript">
//<![CDATA[
window.onload=function(){
document.getElementById("status").wrap='hard';
document.getElementById("output").wrap='hard';
}
//]]>
</script>
<!-- status box -->
<textarea cols="90" rows="1" name="status" id="status"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
<br />
<!-- command output box -->
<textarea cols="90" rows="25" name="output" id="output"></textarea>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
update_status(gettext("Downloading current version information") . "...");
$nanosize = "";
if ($g['platform'] == "nanobsd") {
if (file_exists("/etc/nano_use_vga.txt"))
$nanosize = "-nanobsd-vga-";
else
$nanosize = "-nanobsd-";
$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
}
@unlink("/tmp/{$g['product_name']}_version");
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
if(!$latest_version) {
update_output_window(gettext("Unable to check for updates."));
require("fend.inc");
exit;
} else {
$current_installed_buildtime = ''; /* XXX zap */
$current_installed_version = trim(file_get_contents('/usr/local/opnsense/version/opnsense'));
$latest_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
$latest_version_pfsense = strtotime($latest_version);
if(!$latest_version) {
update_output_window(gettext("Unable to check for updates."));
require("fend.inc");
exit;
} else {
if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
update_status(gettext("Downloading updates") . "...");
conf_mount_rw();
if ($g['platform'] == "nanobsd") {
$update_filename = "latest{$nanosize}.img.gz";
} else {
$update_filename = "latest.tgz";
}
$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
conf_mount_ro();
update_output_window("{$g['product_name']} " . gettext("download complete."));
} else {
update_output_window(gettext("You are on the latest version."));
require("fend.inc");
exit;
}
}
}
/* launch external upgrade helper */
$external_upgrade_helper_text = "/usr/local/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/latest.tgz";
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `/sbin/sha256 -q {$g['upload_path']}/latest.tgz`);
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `/bin/cat {$g['upload_path']}/latest.tgz.sha256 | awk '{ print $4 }'`);
if ($exitstatus) {
update_status($sig_warning);
update_output_window(gettext("Update cannot continue. You can disable this check on the Updater Settings tab."));
require("fend.inc");
exit;
}
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
update_status(gettext("The image file is corrupt."));
update_output_window(gettext("Update cannot continue"));
if (file_exists("{$g['upload_path']}/latest.tgz")) {
conf_mount_rw();
unlink("{$g['upload_path']}/latest.tgz");
conf_mount_ro();
}
require("fend.inc");
exit;
}
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
update_status(gettext("Downloading complete but sha256 does not match."));
update_output_window(gettext("Auto upgrade aborted.") . " \n\n" . gettext("Downloaded SHA256") . ": " . $downloaded_latest_tgz_sha256 . "\n\n" . gettext("Needed SHA256") . ": " . $upgrade_latest_tgz_sha256);
} else {
update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
echo "\n<script type=\"text/javascript\">";
echo "\n//<![CDATA[";
echo "\ndocument.progressbar.style.visibility='hidden';";
echo "\n//]]>";
echo "\n</script>";
mwexec_bg($external_upgrade_helper_text);
}
/*
Helper functions
*/
function read_body_firmware($ch, $string) {
global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
$length = strlen($string);
$downloaded += intval($length);
$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
$downloadProgress = 100 - $downloadProgress;
$a = $file_size;
$b = $downloaded;
$c = $downloadProgress;
$text = " " . gettext("Auto Update Download Status") . "\\n";
$text .= "----------------------------------------------------\\n";
$text .= " " . gettext("Current Version") . " : {$current_installed_version}\\n";
$text .= " " . gettext("Latest Version") . " : {$latest_version}\\n";
$text .= " " . gettext("File size") . " : {$a}\\n";
$text .= " " . gettext("Downloaded") . " : {$b}\\n";
$text .= " " . gettext("Percent") . " : {$c}%\\n";
$text .= "----------------------------------------------------\\n";
$counter++;
if($counter > 150) {
update_output_window($text);
update_progress_bar($downloadProgress);
$counter = 0;
}
fwrite($fout, $string);
return $length;
}
?>
......@@ -115,7 +115,7 @@ include("head.inc");
<div class="content-box tab-content">
<form action="system_firmware_auto.php" method="post">
<form method="post">
<div class="table table-striped">
......
......@@ -27,7 +27,6 @@
*/
require("guiconfig.inc");
require("pkg-utils.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateways.php');
......
<?php
include("pkg_mgr_installed.php");
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment