UM updates and fixes

Former-commit-id: 1c06fca2174091a1a18de3d88724dc4243306b39
This commit is contained in:
fbsanchez 2019-05-14 13:41:21 +02:00
parent 5f87b13e13
commit 6e35f6aec7
2 changed files with 577 additions and 268 deletions

View File

@ -1,22 +1,32 @@
<?php <?php
/** /**
Pandora FMS - http://pandorafms.com * Extension to self monitor Pandora FMS Console
* ================================================== *
* @category Update Manager
* @package Pandora FMS
* @subpackage Update Manager Online
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas * Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list * Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 * as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * ============================================================================
* @package category
* @subpackage category
*/ */
// Begin.
global $config; global $config;
check_login(); check_login();
@ -36,62 +46,100 @@ if (!is_metaconsole()) {
enterprise_include_once('include/functions_update_manager.php'); enterprise_include_once('include/functions_update_manager.php');
$current_package = update_manager_get_current_package(); require_once 'include/functions_config.php';
if (!enterprise_installed()) { $memory_limit_min = '500M';
$post_max_size_min = '800M';
$upload_max_filesize_min = '800M';
$PHPmemory_limit_min = config_return_in_bytes($memory_limit_min);
$PHPpost_max_size_min = config_return_in_bytes($upload_max_filesize_min);
$PHPupload_max_filesize_min = config_return_in_bytes($post_max_size);
$php_settings_fine = 0;
$PHP_SETTINGS_REQUIRED = 3;
$memory_limit = config_return_in_bytes(ini_get('memory_limit'));
if ($memory_limit < $PHPmemory_limit_min) {
ui_print_error_message(
sprintf(
__('Your PHP has set memory limit in %s. To use Update Manager Online, please set it to %s'),
ini_get('memory_limit'),
$memory_limit_min
)
);
} else {
$php_settings_fine++;
}
$post_max_size = config_return_in_bytes(ini_get('post_max_size'));
if ($post_max_size < $PHPpost_max_size_min) {
ui_print_error_message(
sprintf(
__('Your PHP has post_max_size limited to %s. To use Update Manager Online, please set it to %s'),
ini_get('post_max_size'),
$post_max_size_min
)
);
} else {
$php_settings_fine++;
}
$upload_max_filesize = config_return_in_bytes(ini_get('upload_max_filesize'));
if ($upload_max_filesize < $PHPupload_max_filesize_min) {
ui_print_error_message(
sprintf(
__('Your PHP has set maximum allowed size for uploaded files limit in %s. To use Update Manager Online, please set it to %s'),
ini_get('upload_max_filesize'),
$upload_max_filesize_min
)
);
} else {
$php_settings_fine++;
}
// Verify registry.
if (update_manager_verify_registration() === false) {
ui_require_css_file('register');
registration_wiz_modal(false, true, 'location.reload()');
ui_print_error_message(
__('Update Manager Online requires registration')
);
} else {
// Console registered.
$current_package = update_manager_get_current_package();
if (!enterprise_installed()) {
$open = true; $open = true;
} }
$memory_limit = ini_get('memory_limit'); // Translators: Do not translade Update Manager, it's the name of the program.
$memory_limit = str_replace('M', '', $memory_limit); if (is_metaconsole()) {
$memory_limit = (int) $memory_limit;
if ($memory_limit < 500) {
ui_print_error_message(
sprintf(__('Your PHP has set memory limit in %s. For avoid problems with big updates please set to 500M'), ini_get('memory_limit'))
);
}
$post_max_size = ini_get('post_max_size');
$post_max_size = str_replace('M', '', $post_max_size);
if ($memory_limit < 100) {
ui_print_error_message(
sprintf(__('Your PHP has set post parameter max size limit in %s. For avoid problems with big updates please set to 100M'), ini_get('post_max_size'))
);
}
$upload_max_filesize = ini_get('upload_max_filesize');
$upload_max_filesize = str_replace('M', '', $upload_max_filesize);
if ($memory_limit < 100) {
ui_print_error_message(
sprintf(__('Your PHP has set maximum allowed size for uploaded files limit in %s. For avoid problems with big updates please set to 100M'), ini_get('upload_max_filesize'))
);
}
// Translators: Do not translade Update Manager, it's the name of the program.
if (is_metaconsole()) {
echo "<style type='text/css' media='screen'> echo "<style type='text/css' media='screen'>
@import 'styles/meta_pandora.css'; @import 'styles/meta_pandora.css';
</style>"; </style>";
} }
if (is_metaconsole()) { if (is_metaconsole()) {
$baseurl = ui_get_full_url(false, false, false, false); $baseurl = ui_get_full_url(false, false, false, false);
echo ' <link rel="stylesheet" type="text/css" href="'.$baseurl.'/godmode/update_manager/update_manager.css">'; echo ' <link rel="stylesheet" type="text/css" href="'.$baseurl.'/godmode/update_manager/update_manager.css">';
echo "<div id='box_online' class='box_online_meta'>"; echo "<div id='box_online' class='box_online_meta'>";
} else { } else {
echo "<div id='box_online'>"; echo "<div id='box_online'>";
} }
echo "<span class='loading' style='font-size:18pt;'>"; if ($php_settings_fine >= $PHP_SETTINGS_REQUIRED) {
echo "<img src='images/wait.gif' />"; echo "<span class='loading' style='font-size:18pt;'>";
echo '</span>'; echo "<img src='images/wait.gif' />";
echo '</span>';
}
echo '<p style="font-weight: 600;">'.__('The latest version of package installed is:').'</p>'; echo '<p style="font-weight: 600;">'.__('The latest version of package installed is:').'</p>';
if ($open) { if ($open) {
echo '<div id="pkg_version" style="font-size:40pt;">'.$build_version.'</div>'; echo '<div id="pkg_version" style="font-size:40pt;">'.$build_version.'</div>';
} else { } else {
echo '<div id="pkg_version">'.$current_package.'</div>'; echo '<div id="pkg_version">'.$current_package.'</div>';
} }
echo "<div class='checking_package' style='font-size:18pt;width:100%; display: none;'>"; echo "<div class='checking_package' style='font-size:18pt;width:100%; display: none;'>";
echo __('Checking for the newest package.'); echo __('Checking for the newest package.');
@ -107,34 +155,35 @@ if ($open) {
/* /*
------------------------------------------------------------------------- * -------------------------------------------------------------------------
* Hello there! :)
Hello there! :) * We added some of what seems to be "buggy" messages to the openSource
* version recently. This is not to force open-source users to move to the
We added some of what seems to be "buggy" messages to the openSource version * enterprise version, this is just to inform people using Pandora FMS open
recently. This is not to force open-source users to move to the enterprise * source that it requires skilled people to maintain and keep it running
version, this is just to inform people using Pandora FMS open source that it * smoothly without professional support. This does not imply open-source
requires skilled people to maintain and keep it running smoothly without * version is limited in any way. If you check the recently added code, it
professional support. This does not imply open-source version is limited * contains only warnings and messages, no limitations except one:
in any way. If you check the recently added code, it contains only warnings * we removed the option to add custom logo in header.
and messages, no limitations except one: we removed the option to add custom *
logo in header. In the Update Manager section, it warns about the 'danger * In the Update Manager section, it warns about the 'danger of applying
of applying automated updates without a proper backup, remembering in the * automated updates without a proper backup, remembering in the process
process that the Enterprise version comes with a human-tested package. * that the Enterprise version comes with a human-tested package.
Maintaining an OpenSource version with more than 500 agents is not so *
easy, that's why someone using a Pandora with 8000 agents should consider * Maintaining an OpenSource version with more than 500 agents is not so
asking for support. It's not a joke, we know of many setups with a huge * easy, that's why someone using a Pandora with 8000 agents should consider
number of agents, and we hate to hear that “its becoming unstable and slow” :( * asking for support. It's not a joke, we know of many setups with a huge
* number of agents, and we hate to hear that “its becoming unstable and
You can of course remove the warnings, that's why we include the source and * slow” :(
do not use any kind of trick. And that's why we added here this comment, to *
let you know this does not reflect any change in our opensource mentality of * You can of course remove the warnings, that's why we include the source
does the last 14 years. * and do not use any kind of trick. And that's why we added here this
* comment, to let you know this does not reflect any change in our
------------------------------------------------------------------------- * opensource mentality of does the last 14 years.
* -------------------------------------------------------------------------
*/ */
if ($open) { if ($open) {
echo "<div class='update_manager_open'> echo "<div class='update_manager_open'>
<div class='update_manager_warning'> <div class='update_manager_warning'>
<div><img src='images/icono_info.png'></div> <div><img src='images/icono_info.png'></div>
@ -144,20 +193,21 @@ if ($open) {
<a class='update_manager_button_open' href='https://pandorafms.com/pandora-fms-enterprise/' target='_blank'>About Enterprise</a> <a class='update_manager_button_open' href='https://pandorafms.com/pandora-fms-enterprise/' target='_blank'>About Enterprise</a>
</div> </div>
</div>"; </div>";
} }
$enterprise = enterprise_hook('update_manager_enterprise_main'); if ($php_settings_fine >= $PHP_SETTINGS_REQUIRED) {
$enterprise = enterprise_hook('update_manager_enterprise_main');
if ($enterprise == ENTERPRISE_NOT_HOOK) { if ($enterprise == ENTERPRISE_NOT_HOOK) {
// Open view. // Open view.
update_manager_main(); update_manager_main();
} }
?> ?>
<script> <script type="text/javascript">
var isopen = "<?php echo $open; ?>"; var isopen = "<?php echo $open; ?>";
if(isopen){ if(isopen){
$(document).ready(function() { $(document).ready(function() {
$('body').append( "<div id='opacidad' style='position:fixed;background:black;opacity:0.6;z-index:1'></div>" ); $('body').append( "<div id='opacidad' style='position:fixed;background:black;opacity:0.6;z-index:1'></div>" );
jQuery.post ("ajax.php", jQuery.post ("ajax.php",
@ -174,8 +224,11 @@ if(isopen){
"html" "html"
); );
return false; return false;
}); });
}
</script>
<?php
}
} }
</script>

View File

@ -34,6 +34,27 @@
*/ */
/**
* 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;
}
/** /**
* Parses responses from configuration wizard. * Parses responses from configuration wizard.
* *
@ -347,9 +368,9 @@ function show_configuration_wizard() {
<?php <?php
if ($launch === true) { if ($launch === true) {
?> ?>
$(document).ready (function () { $(document).ready (function () {
show_configuration_wizard(); show_configuration_wizard();
}); });
<?php <?php
} }
?> ?>
@ -604,9 +625,9 @@ function show_registration_wizard() {
<?php <?php
if ($launch === true) { if ($launch === true) {
?> ?>
$(document).ready (function () { $(document).ready (function () {
show_registration_wizard(); show_registration_wizard();
}); });
<?php <?php
} }
?> ?>
@ -895,9 +916,9 @@ function show_newsletter_wizard() {
<?php <?php
if ($launch === true) { if ($launch === true) {
?> ?>
$(document).ready (function () { $(document).ready (function () {
show_newsletter_wizard(); show_newsletter_wizard();
}); });
<?php <?php
} }
?> ?>
@ -922,6 +943,12 @@ $(document).ready (function () {
* *
*/ */
/**
* Prepare configuration values.
*
* @return array UM Configuration tokens.
*/
function update_manager_get_config_values() function update_manager_get_config_values()
{ {
global $config; global $config;
@ -943,11 +970,18 @@ function update_manager_get_config_values()
'limit_count' => $limit_count, 'limit_count' => $limit_count,
'build' => $build_version, 'build' => $build_version,
'version' => $pandora_version, 'version' => $pandora_version,
'puid' => $config['pandora_uid'],
]; ];
} }
// Function to remove dir and files inside /**
* Function to remove dir and files inside.
*
* @param string $dir Path to dir.
*
* @return void
*/
function rrmdir($dir) function rrmdir($dir)
{ {
if (is_dir($dir)) { if (is_dir($dir)) {
@ -971,6 +1005,11 @@ function rrmdir($dir)
} }
/**
* Install updates step2.
*
* @return void
*/
function update_manager_install_package_step2() function update_manager_install_package_step2()
{ {
global $config; global $config;
@ -984,9 +1023,9 @@ function update_manager_install_package_step2()
$path = sys_get_temp_dir().'/pandora_oum/'.$package; $path = sys_get_temp_dir().'/pandora_oum/'.$package;
// All files extracted // All files extracted.
$files_total = $path.'/files.txt'; $files_total = $path.'/files.txt';
// Files copied // Files copied.
$files_copied = $path.'/files.copied.txt'; $files_copied = $path.'/files.copied.txt';
$return = []; $return = [];
@ -995,16 +1034,24 @@ function update_manager_install_package_step2()
} }
if (file_exists($path)) { if (file_exists($path)) {
if ($files_h = fopen($files_total, 'r')) { $files_h = fopen($files_total, 'r');
if ($files_h === false) {
$return['status'] = 'error';
$return['message'] = __('An error ocurred while reading a file.');
echo json_encode($return);
return;
}
while ($line = stream_get_line($files_h, 65535, "\n")) { while ($line = stream_get_line($files_h, 65535, "\n")) {
$line = trim($line); $line = trim($line);
// Tries to move the old file to the directory backup inside the extracted package // Tries to move the old file to the directory backup
// inside the extracted package.
if (file_exists($config['homedir'].'/'.$line)) { if (file_exists($config['homedir'].'/'.$line)) {
rename($config['homedir'].'/'.$line, $path.'/backup/'.$line); rename($config['homedir'].'/'.$line, $path.'/backup/'.$line);
} }
// Tries to move the new file to the Integria directory // Tries to move the new file to the Integria directory.
$dirname = dirname($line); $dirname = dirname($line);
if (!file_exists($config['homedir'].'/'.$dirname)) { if (!file_exists($config['homedir'].'/'.$dirname)) {
$dir_array = explode('/', $dirname); $dir_array = explode('/', $dirname);
@ -1023,12 +1070,16 @@ function update_manager_install_package_step2()
file_put_contents($files_copied, $line."\n", (FILE_APPEND | LOCK_EX)); file_put_contents($files_copied, $line."\n", (FILE_APPEND | LOCK_EX));
} }
} else { } else {
// Copy the new file // Copy the new file.
if (rename($path.'/'.$line, $config['homedir'].'/'.$line)) { if (rename($path.'/'.$line, $config['homedir'].'/'.$line)) {
// Append the moved file to the copied files txt // Append the moved file to the copied files txt.
if (!file_put_contents($files_copied, $line."\n", (FILE_APPEND | LOCK_EX))) { if (!file_put_contents($files_copied, $line."\n", (FILE_APPEND | LOCK_EX))) {
// If the copy process fail, this code tries to restore the files backed up before // If the copy process fail, this code tries to
if ($files_copied_h = fopen($files_copied, 'r')) { // restore the files backed up before.
$files_copied_h = fopen($files_copied, 'r');
if ($files_copied_h === false) {
$backup_status = __('Some of your old files might not be recovered.');
} else {
while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) { while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) {
$line_c = trim($line_c); $line_c = trim($line_c);
if (!rename($path.'/backup/'.$line, $config['homedir'].'/'.$line_c)) { if (!rename($path.'/backup/'.$line, $config['homedir'].'/'.$line_c)) {
@ -1041,34 +1092,44 @@ function update_manager_install_package_step2()
} }
fclose($files_copied_h); fclose($files_copied_h);
} else {
$backup_status = __('Some of your old files might not be recovered.');
} }
fclose($files_h); fclose($files_h);
$return['status'] = 'error'; $return['status'] = 'error';
$return['message'] = __("Line '$line' not copied to the progress file.").'&nbsp;'.$backup_status; $return['message'] = __(
'Line "%s" not copied to the progress file.',
$line
).'&nbsp;'.$backup_status;
echo json_encode($return); echo json_encode($return);
return; return;
} }
} else { } else {
// If the copy process fail, this code tries to restore the files backed up before // If the copy process fail, this code tries to restore
if ($files_copied_h = fopen($files_copied, 'r')) { // the files backed up before.
$files_copied_h = fopen($files_copied, 'r');
if ($files_copied_h === false) {
$backup_status = __('Some of your files might not be recovered.');
} else {
while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) { while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) {
$line_c = trim($line_c); $line_c = trim($line_c);
if (!rename($path.'/backup/'.$line, $config['homedir'].'/'.$line)) { if (!rename(
$path.'/backup/'.$line,
$config['homedir'].'/'.$line
)
) {
$backup_status = __('Some of your old files might not be recovered.'); $backup_status = __('Some of your old files might not be recovered.');
} }
} }
fclose($files_copied_h); fclose($files_copied_h);
} else {
$backup_status = __('Some of your files might not be recovered.');
} }
fclose($files_h); fclose($files_h);
$return['status'] = 'error'; $return['status'] = 'error';
$return['message'] = __("File '$line' not copied.").'&nbsp;'.$backup_status; $return['message'] = __(
'Line "%s" not copied to the progress file.',
$line
).'&nbsp;'.$backup_status;
echo json_encode($return); echo json_encode($return);
return; return;
} }
@ -1076,12 +1137,6 @@ function update_manager_install_package_step2()
} }
fclose($files_h); fclose($files_h);
} else {
$return['status'] = 'error';
$return['message'] = __('An error ocurred while reading a file.');
echo json_encode($return);
return;
}
} else { } else {
$return['status'] = 'error'; $return['status'] = 'error';
$return['message'] = __('The package does not exist'); $return['message'] = __('The package does not exist');
@ -1091,16 +1146,25 @@ function update_manager_install_package_step2()
update_manager_enterprise_set_version($version); update_manager_enterprise_set_version($version);
$product_name = get_product_name(); $product_name = get_product_name();
db_pandora_audit("Update $product_name", "Update version: $version of $product_name by ".$config['id_user']);
// Generate audit entry.
db_pandora_audit(
'Update '.$product_name,
'Update version: '.$version.' of '.$product_name.' by '.$config['id_user']
);
$return['status'] = 'success'; $return['status'] = 'success';
$return['message'] = __('The package is installed.'); $return['message'] = __('The package is installed.');
echo json_encode($return); echo json_encode($return);
return;
} }
/**
* Launch update manager client.
*
* @return void
*/
function update_manager_main() function update_manager_main()
{ {
global $config; global $config;
@ -1123,6 +1187,11 @@ function update_manager_main()
} }
/**
* Check updates available (opensource).
*
* @return boolean Packages available or not.
*/
function update_manager_check_online_free_packages_available() function update_manager_check_online_free_packages_available()
{ {
global $config; global $config;
@ -1138,6 +1207,7 @@ function update_manager_check_online_free_packages_available()
'current_package' => $um_config_values['current_update'], 'current_package' => $um_config_values['current_update'],
'version' => $um_config_values['version'], 'version' => $um_config_values['version'],
'build' => $um_config_values['build'], 'build' => $um_config_values['build'],
'puid' => $um_config_values['puid'],
]; ];
$curlObj = curl_init(); $curlObj = curl_init();
@ -1182,6 +1252,13 @@ function update_manager_check_online_free_packages_available()
} }
/**
* Update process, online packages.
*
* @param boolean $is_ajax Is ajax call o direct call.
*
* @return string HTML update message.
*/
function update_manager_check_online_free_packages($is_ajax=true) function update_manager_check_online_free_packages($is_ajax=true)
{ {
global $config; global $config;
@ -1197,11 +1274,14 @@ function update_manager_check_online_free_packages($is_ajax=true)
'current_package' => $um_config_values['current_update'], 'current_package' => $um_config_values['current_update'],
'version' => $um_config_values['version'], 'version' => $um_config_values['version'],
'build' => $um_config_values['build'], 'build' => $um_config_values['build'],
'puid' => $um_config_values['puid'],
]; ];
// For to test in the shell
/* /*
wget https://artica.es/pandoraupdate7/server.php -O- --no-check-certificate --post-data "action=newest_package&license=PANDORA_FREE&limit_count=1&current_package=1&version=v5.1RC1&build=PC140625" * To test using shell execute:
* wget https://artica.es/pandoraupdate7/server.php -O- \
* --no-check-certificate --post-data \
* "action=newest_package&license=PANDORA_FREE&limit_count=1&current_package=1&version=v5.1RC1&build=PC140625"
*/ */
$curlObj = curl_init(); $curlObj = curl_init();
@ -1211,15 +1291,27 @@ function update_manager_check_online_free_packages($is_ajax=true)
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false);
if (isset($config['update_manager_proxy_server'])) { if (isset($config['update_manager_proxy_server'])) {
curl_setopt($curlObj, CURLOPT_PROXY, $config['update_manager_proxy_server']); curl_setopt(
$curlObj,
CURLOPT_PROXY,
$config['update_manager_proxy_server']
);
} }
if (isset($config['update_manager_proxy_port'])) { if (isset($config['update_manager_proxy_port'])) {
curl_setopt($curlObj, CURLOPT_PROXYPORT, $config['update_manager_proxy_port']); curl_setopt(
$curlObj,
CURLOPT_PROXYPORT,
$config['update_manager_proxy_port']
);
} }
if (isset($config['update_manager_proxy_user'])) { if (isset($config['update_manager_proxy_user'])) {
curl_setopt($curlObj, CURLOPT_PROXYUSERPWD, $config['update_manager_proxy_user'].':'.$config['update_manager_proxy_password']); curl_setopt(
$curlObj,
CURLOPT_PROXYUSERPWD,
$config['update_manager_proxy_user'].':'.$config['update_manager_proxy_password']
);
} }
$result = curl_exec($curlObj); $result = curl_exec($curlObj);
@ -1295,7 +1387,7 @@ function update_manager_check_online_free_packages($is_ajax=true)
echo __('There is no update available.'); echo __('There is no update available.');
} }
return; return $update_message;
} else { } else {
if (!empty($result)) { if (!empty($result)) {
$result = json_decode($result, true); $result = json_decode($result, true);
@ -1309,6 +1401,14 @@ function update_manager_check_online_free_packages($is_ajax=true)
} }
/**
* Executes an action against UpdateManager.
*
* @param string $action Action to perform.
* @param boolean $additional_params Extra parameters (optional).
*
* @return array With UM response.
*/
function update_manager_curl_request($action, $additional_params=false) function update_manager_curl_request($action, $additional_params=false)
{ {
global $config; global $config;
@ -1327,6 +1427,7 @@ function update_manager_curl_request($action, $additional_params=false)
'current_package' => $um_config_values['current_update'], 'current_package' => $um_config_values['current_update'],
'version' => $um_config_values['version'], 'version' => $um_config_values['version'],
'build' => $um_config_values['build'], 'build' => $um_config_values['build'],
'puid' => $um_config_values['puid'],
]; ];
if ($additional_params !== false) { if ($additional_params !== false) {
$params = array_merge($params, $additional_params); $params = array_merge($params, $additional_params);
@ -1483,18 +1584,30 @@ function update_manager_register_instance()
switch ($result['http_status']) { switch ($result['http_status']) {
case 200: case 200:
// Retrieve the PUID // Retrieve the PUID.
$message = json_decode($result['update_message'], true); $message = json_decode($result['update_message'], true);
if ($message['success'] == 1) { if ($message['success'] == 1) {
$puid = $message['pandora_uid']; $puid = $message['pandora_uid'];
config_update_value('pandora_uid', $puid); config_update_value('pandora_uid', $puid);
// The tupdate table is reused to display messages. A specific entry to tupdate_package is required. // The tupdate table is reused to display messages.
// Then, this tupdate_package id is saved in tconfig // A specific entry to tupdate_package is required.
db_process_sql_insert('tupdate_package', ['description' => '__UMMESSAGES__']); // Then, this tupdate_package id is saved in tconfig.
$id_um_package_messages = db_get_value('id', 'tupdate_package', 'description', '__UMMESSAGES__'); db_process_sql_insert(
config_update_value('id_um_package_messages', $id_um_package_messages); 'tupdate_package',
['description' => '__UMMESSAGES__']
);
$id_um_package_messages = db_get_value(
'id',
'tupdate_package',
'description',
'__UMMESSAGES__'
);
config_update_value(
'id_um_package_messages',
$id_um_package_messages
);
return [ return [
'success' => true, 'success' => true,
'message' => __('Pandora successfully subscribed with UID: ').$puid.'.', 'message' => __('Pandora successfully subscribed with UID: ').$puid.'.',
@ -1515,6 +1628,11 @@ function update_manager_register_instance()
} }
/**
* Deprecated? study.
*
* @return void
*/
function update_manager_download_messages() function update_manager_download_messages()
{ {
include_once 'include/functions_io.php'; include_once 'include/functions_io.php';
@ -1524,13 +1642,16 @@ function update_manager_download_messages()
return; return;
} }
// Do not ask in next 2 hours // Do not ask in next 2 hours.
$future = (time() + 2 * SECONDS_1HOUR); $future = (time() + 2 * SECONDS_1HOUR);
config_update_value('last_um_check', $future); config_update_value('last_um_check', $future);
// Delete old messages /*
// db_get_sql('DELETE FROM tupdate WHERE UNIX_TIMESTAMP(filename) < UNIX_TIMESTAMP(NOW())'); * Delete old messages
// Build the curl request * db_get_sql('DELETE FROM tupdate WHERE UNIX_TIMESTAMP(filename) < UNIX_TIMESTAMP(NOW())');
* Build the curl request
*/
$params = [ $params = [
'pandora_uid' => $config['pandora_uid'], 'pandora_uid' => $config['pandora_uid'],
'timezone' => $config['timezone'], 'timezone' => $config['timezone'],
@ -1549,32 +1670,55 @@ function update_manager_download_messages()
if ($message['success'] == 1) { if ($message['success'] == 1) {
foreach ($message['messages'] as $single_message) { foreach ($message['messages'] as $single_message) {
// Convert subject -> db_field_value; message_html -> data; expiration -> filename; message_id -> svn_version // Convert subject -> db_field_value;.
$single_message['db_field_value'] = io_safe_input($single_message['subject']); // message_html -> data;
// expiration -> filename;
// message_id -> svn_version;.
$single_message['db_field_value'] = io_safe_input(
$single_message['subject']
);
unset($single_message['subject']); unset($single_message['subject']);
$single_message['data'] = io_safe_input_html($single_message['message_html']); $single_message['data'] = io_safe_input_html(
// It is mandatory to prepend a backslash to all single quotes $single_message['message_html']
$single_message['data'] = preg_replace('/\'/', '\\\'', $single_message['data']); );
// It is mandatory to prepend a backslash to all
// single quotes.
$single_message['data'] = preg_replace(
'/\'/',
'\\\'',
$single_message['data']
);
unset($single_message['message_html']); unset($single_message['message_html']);
$single_message['filename'] = $single_message['expiration']; $single_message['filename'] = $single_message['expiration'];
unset($single_message['expiration']); unset($single_message['expiration']);
$single_message['svn_version'] = $single_message['message_id']; $single_message['svn_version'] = $single_message['message_id'];
unset($single_message['message_id']); unset($single_message['message_id']);
// Add common tconfig id_update_package // Add common tconfig id_update_package.
$single_message['id_update_package'] = $config['id_um_package_messages']; $single_message['id_update_package'] = $config['id_um_package_messages'];
$result = db_process_sql_insert('tupdate', $single_message); $result = db_process_sql_insert(
'tupdate',
$single_message
);
} }
} }
break; break;
default: default:
// Ignore.
break; break;
} }
} }
/**
* Deprecated? review.
*
* @param integer $id_message Message id.
*
* @return boolean Result.
*/
function update_manager_remote_read_messages($id_message) function update_manager_remote_read_messages($id_message)
{ {
global $config; global $config;
@ -1590,6 +1734,11 @@ function update_manager_remote_read_messages($id_message)
} }
/**
* Extracts OUM package.
*
* @return boolean Success or not.
*/
function update_manager_extract_package() function update_manager_extract_package()
{ {
global $config; global $config;
@ -1600,16 +1749,23 @@ function update_manager_extract_package()
if (!defined('PHP_VERSION_ID')) { if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION); $version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); define(
'PHP_VERSION_ID',
($version[0] * 10000 + $version[1] * 100 + $version[2])
);
} }
$extracted = false; $extracted = false;
// Phar and exception working fine in 5.5.0 or higher // Phar and exception working fine in 5.5.0 or higher.
if (PHP_VERSION_ID >= 50505) { if (PHP_VERSION_ID >= 50505) {
$phar = new PharData($path_package); $phar = new PharData($path_package);
try { try {
$result = $phar->extractTo($config['attachment_store'].'/downloads/', null, true); $result = $phar->extractTo(
$config['attachment_store'].'/downloads/',
null,
true
);
$extracted = true; $extracted = true;
} catch (Exception $e) { } catch (Exception $e) {
echo ' There\'s a problem ... -> '.$e->getMessage(); echo ' There\'s a problem ... -> '.$e->getMessage();
@ -1620,10 +1776,11 @@ function update_manager_extract_package()
$return = true; $return = true;
if ($extracted === false) { if ($extracted === false) {
// Phar extraction failed. Fallback to OS extraction.
$return = false; $return = false;
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
// unsupported OS // Unsupported OS.
echo 'This OS ['.PHP_OS.'] does not support direct extraction of tgz files. Upgrade PHP version to be > 5.5.0'; echo 'This OS ['.PHP_OS.'] does not support direct extraction of tgz files. Upgrade PHP version to be > 5.5.0';
} else { } else {
$return = true; $return = true;
@ -1663,8 +1820,11 @@ function update_manager_extract_package()
/** /**
* The update copy entirire the tgz or fail (leave some parts copies and some part not). * The update copy entire tgz or fail (leaving some parts copied
* This does make any thing with the BD. * and others not).
* This does not make changes on DB.
*
* @return boolean Success or not.
*/ */
function update_manager_starting_update() function update_manager_starting_update()
{ {
@ -1721,6 +1881,15 @@ function update_manager_starting_update()
} }
/**
* Copies recursively extracted package updates to target path.
*
* @param string $src Path.
* @param string $dst Path.
* @param string $black_list Path.
*
* @return boolean Success or not.
*/
function update_manager_recurse_copy($src, $dst, $black_list) function update_manager_recurse_copy($src, $dst, $black_list)
{ {
$dir = opendir($src); $dir = opendir($src);
@ -1730,7 +1899,12 @@ function update_manager_recurse_copy($src, $dst, $black_list)
while (false !== ( $file = readdir($dir))) { while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' ) && (!in_array($file, $black_list))) { if (( $file != '.' ) && ( $file != '..' ) && (!in_array($file, $black_list))) {
if (is_dir($src.'/'.$file)) { if (is_dir($src.'/'.$file)) {
if (!update_manager_recurse_copy($src.'/'.$file, $dst.'/'.$file, $black_list)) { if (!update_manager_recurse_copy(
$src.'/'.$file,
$dst.'/'.$file,
$black_list
)
) {
return false; return false;
} }
} else { } else {
@ -1750,6 +1924,13 @@ function update_manager_recurse_copy($src, $dst, $black_list)
} }
/**
* Updates current update (DB).
*
* @param string $current_package Current package.
*
* @return void
*/
function update_manager_set_current_package($current_package) function update_manager_set_current_package($current_package)
{ {
if (enterprise_installed()) { if (enterprise_installed()) {
@ -1786,6 +1967,11 @@ function update_manager_set_current_package($current_package)
} }
/**
* Retrieves current update from DB.
*
* @return string Current update.
*/
function update_manager_get_current_package() function update_manager_get_current_package()
{ {
global $config; global $config;
@ -1814,32 +2000,64 @@ function update_manager_get_current_package()
} }
// Set the read or not read status message of current user /**
* Deprecated? verify.
* Set the read or not read status message of current user.
*
* @param integer $message_id Message id.
* @param string $status Status.
*
* @return void
*/
function update_manger_set_read_message($message_id, $status) function update_manger_set_read_message($message_id, $status)
{ {
global $config; global $config;
$rollback = db_get_value('data_rollback', 'tupdate', 'svn_version', $message_id); $rollback = db_get_value(
'data_rollback',
'tupdate',
'svn_version',
$message_id
);
$users_read = json_decode($rollback, true); $users_read = json_decode($rollback, true);
$users_read[$config['id_user']] = $status; $users_read[$config['id_user']] = $status;
$rollback = json_encode($users_read); $rollback = json_encode($users_read);
db_process_sql_update('tupdate', ['data_rollback' => $rollback], ['svn_version' => $message_id]); db_process_sql_update(
'tupdate',
['data_rollback' => $rollback],
['svn_version' => $message_id]
);
} }
// Get the read or not read status message /**
* Deprecated? verify.
* Get the read or not read status message
*
* @param integer $message_id Message id.
* @param boolean $rollback Rollback or not.
*
* @return boolean Success or not.
*/
function update_manger_get_read_message($message_id, $rollback=false) function update_manger_get_read_message($message_id, $rollback=false)
{ {
global $config; global $config;
if ($rollback === false) { if ($rollback === false) {
$rollback = db_get_value('data_rollback', 'tupdate', 'svn_version', $message_id); $rollback = db_get_value(
'data_rollback',
'tupdate',
'svn_version',
$message_id
);
} }
$users_read = json_decode($rollback, true); $users_read = json_decode($rollback, true);
if (isset($users_read[$config['id_user']]) && ($users_read[$config['id_user']] == 1)) { if (isset($users_read[$config['id_user']])
&& ($users_read[$config['id_user']] == 1)
) {
return true; return true;
} }
@ -1847,7 +2065,12 @@ function update_manger_get_read_message($message_id, $rollback=false)
} }
// Get the last message /**
* Deprecated? verify.
* Get the last message.
*
* @return array Latest message.
*/
function update_manger_get_last_message() function update_manger_get_last_message()
{ {
global $config; global $config;
@ -1862,7 +2085,14 @@ function update_manger_get_last_message()
} }
// Get the a single message message /**
* Deprecated? verify.
* Get the a single message message.
*
* @param integer $message_id Message id.
*
* @return array Target message.
*/
function update_manger_get_single_message($message_id) function update_manger_get_single_message($message_id)
{ {
global $config; global $config;
@ -1875,6 +2105,12 @@ function update_manger_get_single_message($message_id)
} }
/**
* Deprecated? verify.
* Count messages (local).
*
* @return integer Count.
*/
function update_manager_get_total_messages() function update_manager_get_total_messages()
{ {
global $config; global $config;
@ -1884,6 +2120,12 @@ function update_manager_get_total_messages()
} }
/**
* Deprecated? verify.
* Retrieves unread messages count.
*
* @return integer Pending read messages.
*/
function update_manager_get_unread_messages() function update_manager_get_unread_messages()
{ {
global $config; global $config;
@ -1896,6 +2138,12 @@ function update_manager_get_unread_messages()
} }
/**
* Deprecated? verify.
* Retrieves some messages count.
*
* @return integer Pending read messages.
*/
function update_manager_get_not_deleted_messages() function update_manager_get_not_deleted_messages()
{ {
global $config; global $config;
@ -1908,6 +2156,14 @@ function update_manager_get_not_deleted_messages()
} }
/**
* Deprecated? verify.
* Deletes message.
*
* @param integer $message_id Message id.
*
* @return void
*/
function update_manger_set_deleted_message($message_id) function update_manger_set_deleted_message($message_id)
{ {
global $config; global $config;