Historical view for update manager

This commit is contained in:
fbsanchez 2022-03-30 14:41:47 +02:00
parent dc2d577def
commit 2d334f7860
10 changed files with 338 additions and 46 deletions

View File

@ -15,5 +15,17 @@ CREATE TABLE IF NOT EXISTS `tbackup` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
DROP TABLE `tupdate`;
DROP TABLE `tupdate_package`;
DROP TABLE `tupdate_journal`;
CREATE TABLE `tupdate_journal` (
`id` SERIAL,
`utimestamp` BIGINT DEFAULT 0,
`version` VARCHAR(25) DEFAULT '',
`type` VARCHAR(25) DEFAULT '',
`origin` VARCHAR(25) DEFAULT '',
`id_user` VARCHAR(250) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
COMMIT;

View File

@ -535,9 +535,13 @@ if (check_acl($config['id_user'], 0, 'PM') && $config['enable_update_manager'])
$sub['godmode/update_manager/update_manager&tab=online']['text'] = __('Update Manager online');
$sub['godmode/update_manager/update_manager&tab=online']['id'] = 'Online';
$sub['godmode/update_manager/update_manager&tab=setup']['text'] = __('Update Manager options');
$sub['godmode/update_manager/update_manager&tab=setup']['id'] = 'Options';
$sub['godmode/update_manager/update_manager&tab=history']['text'] = __('Update Manager journal');
$sub['godmode/update_manager/update_manager&tab=history']['id'] = 'Journal';
$menu_godmode['messages']['sub'] = $sub;
}

View File

@ -0,0 +1,79 @@
<?php
/**
* Update manager client historical updates.
*
* @category Update Manager
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* 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.
* ============================================================================
*/
// Datatables list.
try {
$columns = [
'version',
'type',
'origin',
'id_user',
'utimestamp',
];
$column_names = [
__('Version'),
__('Type'),
__('Origin'),
__('User'),
__('Timestamp'),
];
$tableId = 'ucm';
// Load datatables user interface.
ui_print_datatable(
[
'id' => $tableId,
'class' => 'info_table',
'style' => 'width: 100%',
'columns' => $columns,
'column_names' => $column_names,
'ajax_url' => 'include/ajax/update_manager',
'ajax_data' => ['method' => 'draw'],
'no_sortable_columns' => [],
'order' => [
'field' => 'utimestamp',
'direction' => 'desc',
],
'search_button_class' => 'sub filter float-right',
'form' => [
'inputs' => [
[
'label' => __('Free search'),
'type' => 'text',
'class' => 'mw250px',
'id' => 'free_search',
'name' => 'free_search',
],
],
],
]
);
} catch (Exception $e) {
echo $e->getMessage();
}

View File

@ -15,7 +15,7 @@ global $config;
check_login();
// The ajax is in
// include/ajax/update_manager.ajax.php
// include/ajax/update_manager.php
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
@ -37,20 +37,32 @@ $tab = get_parameter('tab', 'online');
$buttons['setup'] = [
'active' => ($tab == 'setup') ? true : false,
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=setup">'.html_print_image('images/gm_setup.png', true, ['title' => __('Options'), 'class' => 'invert_filter']).'</a>',
'text' => '<a href="'.ui_get_full_url(
'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=setup'
).'">'.html_print_image('images/gm_setup.png', true, ['title' => __('Options'), 'class' => 'invert_filter']).'</a>',
];
$buttons['history'] = [
'active' => ($tab == 'history') ? true : false,
'text' => '<a href="'.ui_get_full_url(
'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=histo'
).'ry">'.html_print_image('images/gm_db.png', true, ['title' => __('Journal'), 'class' => 'invert_filter']).'</a>',
];
$buttons['offline'] = [
'active' => ($tab == 'offline') ? true : false,
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=offline">'.html_print_image('images/box.png', true, ['title' => __('Offline update manager'), 'class' => 'invert_filter']).'</a>',
'text' => '<a href="'.ui_get_full_url(
'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=offli'
).'ne">'.html_print_image('images/box.png', true, ['title' => __('Offline update manager'), 'class' => 'invert_filter']).'</a>',
];
$buttons['online'] = [
'active' => ($tab == 'online') ? true : false,
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=online">'.html_print_image('images/op_gis.png', true, ['title' => __('Online update manager'), 'class' => 'invert_filter']).'</a>',
'text' => '<a href="'.ui_get_full_url(
'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=onlin'
).'e">'.html_print_image('images/op_gis.png', true, ['title' => __('Online update manager'), 'class' => 'invert_filter']).'</a>',
];
switch ($tab) {
case 'setup':
$title = __('Update manager » Setup');
@ -76,6 +88,10 @@ ui_print_page_header(
);
switch ($tab) {
case 'history':
include $config['homedir'].'/godmode/update_manager/update_manager.history.php';
break;
case 'setup':
include $config['homedir'].'/godmode/update_manager/update_manager.setup.php';
break;

View File

@ -0,0 +1,174 @@
<?php
/**
* Update manager client historical updates backend.
*
* @category Update Manager
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* 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.
* ============================================================================
*/
// Begin.
global $config;
check_login();
if ((bool) check_acl($config['id_user'], 0, 'PM') === false
&& (bool) is_user_admin($config['id_user']) === false
) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access Setup Management'
);
include 'general/noaccess.php';
return;
}
$method = get_parameter('method', null);
if ($method === 'draw') {
// Datatables offset, limit and order.
$filter = get_parameter('filter', []);
$start = get_parameter('start', 0);
$length = get_parameter('length', $config['block_size']);
$orderBy = get_datatable_order(true);
$sort_field = $orderBy['field'];
$order = $orderBy['direction'];
$pagination = '';
if (isset($start) && $start > 0
&& isset($length) && $length >= 0
) {
$pagination = sprintf(
' LIMIT %d OFFSET %d ',
$start,
$length
);
}
try {
ob_start();
$fields = ['*'];
$sql_filters = [];
if (isset($filter['free_search']) === true
&& empty($filter['free_search']) === false
) {
$sql_filters[] = sprintf(
' AND (`id_user` like "%%%s%%" OR `version` like "%%%s%%") ',
$filter['free_search'],
$filter['free_search']
);
}
if (isset($order) === true) {
$dir = 'asc';
if ($order == 'desc') {
$dir = 'desc';
};
if (in_array(
$sort_field,
[
'version',
'type',
'id_user',
'utimestamp',
]
) === true
) {
$order_by = sprintf(
'ORDER BY `%s` %s',
$sort_field,
$dir
);
}
}
// Retrieve data.
$sql = sprintf(
'SELECT %s
FROM tupdate_journal
WHERE 1=1
%s
%s
%s',
join(',', $fields),
join(' ', $sql_filters),
$order_by,
$pagination
);
$return = db_get_all_rows_sql($sql);
if ($return === false) {
$data = [];
} else {
$data = $return;
}
// Retrieve counter.
$count = db_get_value('count(*)', '('.$sql.') t');
if ($data) {
$data = array_reduce(
$data,
function ($carry, $item) {
// Transforms array of arrays $data into an array
// of objects, making a post-process of certain fields.
$tmp = (object) $item;
$tmp->utimestamp = human_time_comparation($tmp->utimestamp);
$carry[] = $tmp;
return $carry;
}
);
}
// Datatables format: RecordsTotal && recordsfiltered.
echo json_encode(
[
'data' => $data,
'recordsTotal' => $count,
'recordsFiltered' => $count,
]
);
// Capture output.
$response = ob_get_clean();
} catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
exit;
}
// If not valid, show error with issue.
json_decode($response);
if (json_last_error() == JSON_ERROR_NONE) {
// If valid dump.
echo $response;
} else {
echo json_encode(
['error' => $response]
);
}
exit;
}

View File

@ -802,6 +802,7 @@ define('AUDIT_LOG_SNMP_MANAGEMENT', 'SNMP management');
define('AUDIT_LOG_DASHBOARD_MANAGEMENT', 'Dashboard management');
define('AUDIT_LOG_SERVICE_MANAGEMENT', 'Service management');
define('AUDIT_LOG_INCIDENT_MANAGEMENT', 'Incident management');
define('AUDIT_LOG_UMC', 'Update Manager');
// MIMEs.
define(

View File

@ -4760,6 +4760,7 @@ function html_print_input($data, $wrapper='div', $input_only=false)
enterprise_include_once('include/functions_metaconsole.php');
$style = '';
if ($config['style'] === 'pandora_black' && !is_metaconsole()) {
$style = 'style="color: white"';
}
@ -4768,9 +4769,9 @@ function html_print_input($data, $wrapper='div', $input_only=false)
if (($data['label'] ?? false) && $input_only === false) {
$output = '<'.$wrapper.' id="'.$wrapper.'-'.$data['name'].'" ';
$output .= ' class="'.$data['input_class'].'">';
$output .= '<label '.$style.' class="'.$data['label_class'].'">';
$output .= $data['label'];
$output .= ' class="'.($data['input_class'] ?? '').'">';
$output .= '<label '.$style.' class="'.($data['label_class'] ?? '').'">';
$output .= ($data['label'] ?? '');
$output .= '</label>';
if (!$data['return']) {
@ -4795,7 +4796,7 @@ function html_print_input($data, $wrapper='div', $input_only=false)
case 'text':
$output .= html_print_input_text(
$data['name'],
$data['value'],
($data['value'] ?? ''),
((isset($data['alt']) === true) ? $data['alt'] : ''),
((isset($data['size']) === true) ? $data['size'] : 50),
((isset($data['maxlength']) === true) ? $data['maxlength'] : 255),

View File

@ -3320,7 +3320,9 @@ function ui_print_datatable(array $parameters)
];
}
if (!is_array($parameters['datacolumns'])) {
if (isset($parameters['datacolumns']) === false
|| is_array($parameters['datacolumns']) === false
) {
$parameters['datacolumns'] = $parameters['columns'];
}
@ -3369,7 +3371,9 @@ function ui_print_datatable(array $parameters)
$filter .= ' id="'.$form_id.'_search_bt" value="'.__('Filter').'"/>';
// Extra buttons.
if (is_array($parameters['form']['extra_buttons'])) {
if (isset($parameters['form']['extra_buttons']) === true
&& is_array($parameters['form']['extra_buttons']) === true
) {
foreach ($parameters['form']['extra_buttons'] as $button) {
$filter .= '<button id="'.$button['id'].'" ';
$filter .= ' class="'.$button['class'].'" ';
@ -3469,7 +3473,9 @@ function ui_print_datatable(array $parameters)
}
$export_columns = '';
if ($parameters['csv_exclude_latest'] === true) {
if (isset($parameters['csv_exclude_latest']) === true
&& $parameters['csv_exclude_latest'] === true
) {
$export_columns = ',columns: \'th:not(:last-child)\'';
}

View File

@ -26,6 +26,8 @@
* ============================================================================
*/
use UpdateManager\UI\Manager;
// Begin.
global $config;
@ -282,5 +284,28 @@ function rrmdir($dir)
*/
function register_upgrade($version, $type, $mode)
{
error_log(__('Installed %s version (%s) %s', $version, $type, $mode));
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(),
]
);
}

View File

@ -2236,42 +2236,16 @@ CREATE TABLE IF NOT EXISTS `tupdate_settings` (
`value` VARCHAR(255) DEFAULT '', PRIMARY KEY (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tupdate_package`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tupdate_package` (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
timestamp DATETIME NOT NULL,
description VARCHAR(255) DEFAULT '', PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tupdate`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tupdate` (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
type ENUM('code', 'db_data', 'db_schema', 'binary'),
id_update_package INT UNSIGNED NOT NULL DEFAULT 0,
filename VARCHAR(250) DEFAULT '',
checksum VARCHAR(250) DEFAULT '',
previous_checksum VARCHAR(250) DEFAULT '',
svn_version INT UNSIGNED NOT NULL DEFAULT 0,
data LONGTEXT,
data_rollback LONGTEXT,
description TEXT,
db_table_name VARCHAR(140) DEFAULT '',
db_field_name VARCHAR(140) DEFAULT '',
db_field_value VARCHAR(1024) DEFAULT '', PRIMARY KEY (`id`),
FOREIGN KEY (`id_update_package`) REFERENCES tupdate_package(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tupdate_journal`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tupdate_journal` (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
id_update INT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`),
FOREIGN KEY (`id_update`) REFERENCES tupdate(`id`) ON UPDATE CASCADE ON DELETE CASCADE
CREATE TABLE `tupdate_journal` (
`id` SERIAL,
`utimestamp` BIGINT DEFAULT 0,
`version` VARCHAR(25) DEFAULT '',
`type` VARCHAR(25) DEFAULT '',
`origin` VARCHAR(25) DEFAULT '',
`id_user` VARCHAR(250) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------