2014-06-09 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_config.php, general/login_page.php: improved
the source code style.
* godmode/setup/os.builder.php: fixed the form.
* godmode/update_manager_xxx/*, godmode/menu.php,
include/functions_update_manager.php,
include/ajax/update_manager.ajax.php,
include/graphs/functions_gd.php, include/graphs/functions_flot.php,
include/config_process.php, include/javascript/update_manager.js,
include/javascript/jquery.knob.js,
include/javascript/jquery.iframe-transport.js,
include/javascript/jquery.fileupload.js, images/check-cross.png:
first version of new update manager.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10144 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2014-06-09 15:33:55 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Update manager client auxiliary functions.
|
2019-03-14 18:04:28 +01:00
|
|
|
*
|
|
|
|
* @category Functions Update Manager
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Community
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2019-03-14 18:04:28 +01:00
|
|
|
* Please see http://pandorafms.org for full contribution list
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation for version 2.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* ============================================================================
|
2014-06-09 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_config.php, general/login_page.php: improved
the source code style.
* godmode/setup/os.builder.php: fixed the form.
* godmode/update_manager_xxx/*, godmode/menu.php,
include/functions_update_manager.php,
include/ajax/update_manager.ajax.php,
include/graphs/functions_gd.php, include/graphs/functions_flot.php,
include/config_process.php, include/javascript/update_manager.js,
include/javascript/jquery.knob.js,
include/javascript/jquery.iframe-transport.js,
include/javascript/jquery.fileupload.js, images/check-cross.png:
first version of new update manager.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10144 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2014-06-09 15:33:55 +02:00
|
|
|
*/
|
|
|
|
|
2022-03-30 14:41:47 +02:00
|
|
|
use UpdateManager\UI\Manager;
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
// Begin.
|
|
|
|
global $config;
|
|
|
|
|
2022-03-28 12:20:36 +02:00
|
|
|
require_once $config['homedir'].'/vendor/autoload.php';
|
2019-05-13 17:55:41 +02:00
|
|
|
|
|
|
|
|
2019-05-14 13:41:21 +02:00
|
|
|
/**
|
|
|
|
* Verifies registration state.
|
|
|
|
*
|
|
|
|
* @return boolean Status.
|
|
|
|
*/
|
|
|
|
function update_manager_verify_registration()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (isset($config['pandora_uid']) === true
|
|
|
|
&& $config['pandora_uid'] != ''
|
|
|
|
&& $config['pandora_uid'] != 'OFFLINE'
|
|
|
|
) {
|
|
|
|
// Verify with UpdateManager.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-01 08:12:57 +02:00
|
|
|
|
2020-07-23 15:53:38 +02:00
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Retrieves current update from DB.
|
2020-07-23 15:53:38 +02:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return string Current update.
|
2020-07-23 15:53:38 +02:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function update_manager_get_current_package()
|
2020-07-23 15:53:38 +02:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$current_update = ($config['current_package'] ?? $config['current_package_enterprise']);
|
|
|
|
|
|
|
|
if ($current_update === null) {
|
|
|
|
$current_update = db_get_value(
|
|
|
|
db_escape_key_identifier('value'),
|
|
|
|
'tupdate_settings',
|
|
|
|
db_escape_key_identifier('key'),
|
|
|
|
'current_package'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($current_update === false) {
|
|
|
|
$current_update = 0;
|
|
|
|
if (isset($config['current_package'])) {
|
|
|
|
$current_update = $config['current_package'];
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 15:53:38 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
return $current_update;
|
2020-07-23 15:53:38 +02:00
|
|
|
}
|
2019-05-14 13:41:21 +02:00
|
|
|
|
2020-09-01 08:12:57 +02:00
|
|
|
|
2020-11-10 12:10:25 +01:00
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Check if a trial license is in use.
|
2020-11-10 12:10:25 +01:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return boolean true if a trial license is in use, false otherwise.
|
2020-11-10 12:10:25 +01:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function update_manager_verify_trial()
|
2020-11-10 12:10:25 +01:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
if (isset($config['license_licensed_to'])
|
2021-11-04 16:28:15 +01:00
|
|
|
&& strstr($config['license_licensed_to'], 'info@pandorafms.com') !== false
|
2021-06-14 13:56:42 +02:00
|
|
|
) {
|
2020-11-10 12:10:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 17:55:41 +02:00
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Checks if there are packages available to be installed.
|
2019-05-13 17:55:41 +02:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return boolean
|
2019-05-13 17:55:41 +02:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function update_manager_check_updates_available()
|
2019-05-13 17:55:41 +02:00
|
|
|
{
|
2021-06-14 13:56:42 +02:00
|
|
|
$settings = update_manager_get_config_values();
|
|
|
|
$umc = new \UpdateManager\Client($settings);
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$updates = $umc->listUpdates();
|
|
|
|
if (is_array($updates) === false) {
|
|
|
|
return false;
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
return (count($updates) > 0);
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Returns current update manager url.
|
2019-05-13 17:55:41 +02:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return string
|
2019-05-13 17:55:41 +02:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function update_manager_get_url()
|
|
|
|
{
|
2019-05-13 17:55:41 +02:00
|
|
|
global $config;
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$url_update_manager = $config['url_update_manager'];
|
|
|
|
if ((bool) is_metaconsole() === false) {
|
|
|
|
if ((bool) $config['node_metaconsole'] === true) {
|
|
|
|
$url_update_manager = $config['metaconsole_base_url'];
|
|
|
|
$url_update_manager .= 'godmode/um_client/api.php';
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
return $url_update_manager;
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Prepare configuration values.
|
2019-05-13 17:55:41 +02:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return array UM Configuration tokens.
|
2019-05-13 17:55:41 +02:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function update_manager_get_config_values()
|
2019-05-13 17:55:41 +02:00
|
|
|
{
|
|
|
|
global $config;
|
2021-06-14 13:56:42 +02:00
|
|
|
global $build_version;
|
|
|
|
global $pandora_version;
|
|
|
|
static $historical_dbh;
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
enterprise_include_once('include/functions_license.php');
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$license = db_get_value(
|
|
|
|
db_escape_key_identifier('value'),
|
|
|
|
'tupdate_settings',
|
|
|
|
db_escape_key_identifier('key'),
|
|
|
|
'customer_key'
|
2019-05-13 17:55:41 +02:00
|
|
|
);
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$data = enterprise_hook('license_get_info');
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
if ($data === ENTERPRISE_NOT_HOOK) {
|
|
|
|
$limit_count = db_get_value_sql('SELECT count(*) FROM tagente');
|
|
|
|
} else {
|
|
|
|
$limit_count = $data['count_enabled'];
|
|
|
|
}
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
if ($historical_dbh === null
|
|
|
|
&& isset($config['history_db_enabled']) === true
|
|
|
|
&& (bool) $config['history_db_enabled'] === true
|
|
|
|
) {
|
|
|
|
$dbm = new \PandoraFMS\Core\DBMaintainer(
|
|
|
|
[
|
|
|
|
'host' => $config['history_db_host'],
|
|
|
|
'port' => $config['history_db_port'],
|
|
|
|
'name' => $config['history_db_name'],
|
|
|
|
'user' => $config['history_db_user'],
|
|
|
|
'pass' => $config['history_db_pass'],
|
2019-05-13 17:55:41 +02:00
|
|
|
]
|
2021-06-14 13:56:42 +02:00
|
|
|
);
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$historical_dbh = $dbm->getDBH();
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
$insecure = false;
|
|
|
|
if ($config['secure_update_manager'] === ''
|
|
|
|
|| $config['secure_update_manager'] === null
|
|
|
|
) {
|
|
|
|
$insecure = false;
|
|
|
|
} else {
|
|
|
|
// Directive defined.
|
|
|
|
$insecure = !$config['secure_update_manager'];
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
return [
|
|
|
|
'url' => update_manager_get_url(),
|
|
|
|
'insecure' => $insecure,
|
|
|
|
'license' => $license,
|
|
|
|
'current_package' => update_manager_get_current_package(),
|
|
|
|
'MR' => (int) $config['MR'],
|
|
|
|
'limit_count' => $limit_count,
|
|
|
|
'build' => $build_version,
|
|
|
|
'version' => $pandora_version,
|
|
|
|
'registration_code' => $config['pandora_uid'],
|
|
|
|
'homedir' => $config['homedir'],
|
|
|
|
'remote_config' => $config['remote_config'],
|
|
|
|
'dbconnection' => $config['dbconnection'],
|
|
|
|
'historydb' => $historical_dbh,
|
|
|
|
'language' => $config['language'],
|
|
|
|
'timezone' => $config['timezone'],
|
|
|
|
'proxy' => [
|
2022-03-29 20:58:18 +02:00
|
|
|
'host' => ($config['update_manager_proxy_host'] ?? null),
|
|
|
|
'port' => ($config['update_manager_proxy_port'] ?? null),
|
|
|
|
'user' => ($config['update_manager_proxy_user'] ?? null),
|
|
|
|
'password' => ($config['update_manager_proxy_password'] ?? null),
|
2021-06-14 13:56:42 +02:00
|
|
|
],
|
|
|
|
];
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Return ad campaigns messages from UMS.
|
2019-05-13 17:55:41 +02:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return array|null
|
2019-05-13 17:55:41 +02:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function update_manager_get_messages()
|
2019-05-13 17:55:41 +02:00
|
|
|
{
|
2021-06-14 13:56:42 +02:00
|
|
|
$settings = update_manager_get_config_values();
|
|
|
|
$umc = new UpdateManager\Client($settings);
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
return $umc->getMessages();
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-14 13:56:42 +02:00
|
|
|
* Function to remove dir and files inside.
|
2019-05-13 17:55:41 +02:00
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @param string $dir Path to dir.
|
2019-05-13 17:55:41 +02:00
|
|
|
*
|
2021-07-01 00:37:13 +02:00
|
|
|
* @deprecated 755 Use Files::rmrf.
|
|
|
|
*
|
2021-06-14 13:56:42 +02:00
|
|
|
* @return void
|
2019-05-13 17:55:41 +02:00
|
|
|
*/
|
2021-06-14 13:56:42 +02:00
|
|
|
function rrmdir($dir)
|
|
|
|
{
|
|
|
|
if (is_dir($dir)) {
|
|
|
|
$objects = scandir($dir);
|
2019-05-13 17:55:41 +02:00
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
foreach ($objects as $object) {
|
|
|
|
if ($object != '.' && $object != '..') {
|
|
|
|
if (filetype($dir.'/'.$object) == 'dir') {
|
|
|
|
rrmdir($dir.'/'.$object);
|
|
|
|
} else {
|
|
|
|
unlink($dir.'/'.$object);
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
2019-05-29 10:01:21 +02:00
|
|
|
}
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 13:56:42 +02:00
|
|
|
reset($objects);
|
|
|
|
rmdir($dir);
|
|
|
|
} else {
|
|
|
|
unlink($dir);
|
2019-05-13 17:55:41 +02:00
|
|
|
}
|
2019-03-14 18:04:28 +01:00
|
|
|
}
|
2022-03-29 20:58:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keeps an history of upgrades.
|
|
|
|
*
|
|
|
|
* @param string $version Version installed.
|
|
|
|
* @param string $type Package type (server|console).
|
|
|
|
* @param string $mode Installation style (offline|online).
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function register_upgrade($version, $type, $mode)
|
|
|
|
{
|
2022-03-30 14:41:47 +02:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
$origin = 'unknown';
|
|
|
|
if ($mode === Manager::MODE_OFFLINE) {
|
|
|
|
$origin = 'offline';
|
|
|
|
} else if ($mode === Manager::MODE_ONLINE) {
|
|
|
|
$origin = 'online';
|
|
|
|
}
|
|
|
|
|
|
|
|
db_pandora_audit(
|
|
|
|
AUDIT_LOG_UMC,
|
|
|
|
'System updated to '.$version.' ('.$type.') from '.$origin
|
|
|
|
);
|
|
|
|
|
|
|
|
db_process_sql_insert(
|
|
|
|
'tupdate_journal',
|
|
|
|
[
|
|
|
|
'version' => $version,
|
|
|
|
'type' => $type,
|
|
|
|
'origin' => $origin,
|
|
|
|
'id_user' => $config['id_user'],
|
|
|
|
'utimestamp' => time(),
|
|
|
|
]
|
|
|
|
);
|
2022-03-29 20:58:18 +02:00
|
|
|
}
|