Merge remote-tracking branch 'origin/develop' into ent-5408-consola-visual-nueva-bugs

This commit is contained in:
Daniel Barbero Martin 2020-02-05 14:05:26 +01:00
commit 902c42b559
41 changed files with 205 additions and 87 deletions

View File

@ -1,5 +1,5 @@
package: pandorafms-agent-unix
Version: 7.0NG.743-200203
Version: 7.0NG.743-200205
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.743-200203"
pandora_version="7.0NG.743-200205"
echo "Test if you has the tools for to make the packages."
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null

View File

@ -55,7 +55,7 @@ my $Sem = undef;
my $ThreadSem = undef;
use constant AGENT_VERSION => '7.0NG.743';
use constant AGENT_BUILD => '200203';
use constant AGENT_BUILD => '200205';
# Agent log default file size maximum and instances
use constant DEFAULT_MAX_LOG_SIZE => 600000;

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_agent_unix
%define version 7.0NG.743
%define release 200203
%define release 200205
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_agent_unix
%define version 7.0NG.743
%define release 200203
%define release 200205
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

View File

@ -10,7 +10,7 @@
# **********************************************************************
PI_VERSION="7.0NG.743"
PI_BUILD="200203"
PI_BUILD="200205"
OS_NAME=`uname -s`
FORCE=0

View File

@ -186,7 +186,7 @@ UpgradeApplicationID
{}
Version
{200203}
{200205}
ViewReadme
{Yes}

View File

@ -30,7 +30,7 @@ using namespace Pandora;
using namespace Pandora_Strutils;
#define PATH_SIZE _MAX_PATH+1
#define PANDORA_VERSION ("7.0NG.743(Build 200203)")
#define PANDORA_VERSION ("7.0NG.743(Build 200205)")
string pandora_path;
string pandora_dir;

View File

@ -11,7 +11,7 @@ BEGIN
VALUE "LegalCopyright", "Artica ST"
VALUE "OriginalFilename", "PandoraAgent.exe"
VALUE "ProductName", "Pandora FMS Windows Agent"
VALUE "ProductVersion", "(7.0NG.743(Build 200203))"
VALUE "ProductVersion", "(7.0NG.743(Build 200205))"
VALUE "FileVersion", "1.0.0.0"
END
END

View File

@ -1,5 +1,5 @@
package: pandorafms-console
Version: 7.0NG.743-200203
Version: 7.0NG.743-200205
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.743-200203"
pandora_version="7.0NG.743-200205"
package_pear=0
package_pandora=1

View File

@ -801,31 +801,37 @@ function mainAgentsModules()
$link = "winopeng('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&'.'id='.$module_id.'&'.'refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."')";
echo '<a href="javascript:'.$link.'">';
$module_last_value = modules_get_last_value($module_id);
if (!is_numeric($module_last_value)) {
$module_last_value = htmlspecialchars($module_last_value);
}
switch ($status) {
case AGENT_MODULE_STATUS_NORMAL:
ui_print_status_image('module_ok.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_ok.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
ui_print_status_image('module_critical.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_critical.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_WARNING:
ui_print_status_image('module_warning.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_warning.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_UNKNOWN:
ui_print_status_image('module_unknown.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_unknown.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
ui_print_status_image('module_alertsfired.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_alertsfired.png', $module_last_value, false);
break;
case 4:
ui_print_status_image('module_no_data.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_no_data.png', $module_last_value, false);
break;
}

View File

@ -832,7 +832,7 @@ foreach ($modules as $module) {
$data[5] = ui_print_truncate_text($module['descripcion'], 'description', false);
$data[6] = ui_print_status_image($status, $title, true);
$data[6] = ui_print_status_image($status, htmlspecialchars($title), true);
// MAX / MIN values
if ($module['id_tipo_modulo'] != 25) {

View File

@ -320,7 +320,7 @@ if (check_acl($config['id_user'], 0, 'PM')) {
$sub2['godmode/setup/setup&amp;section=websocket_engine']['refr'] = 0;
if ($config['activate_gis']) {
$sub2['godmode/setup/gis']['text'] = __('Map conections GIS');
$sub2['godmode/setup/setup&amp;section=gis']['text'] = __('Map conections GIS');
}
$sub['general']['sub2'] = $sub2;

View File

@ -28,15 +28,6 @@ require_once 'include/functions_gis.php';
ui_require_javascript_file('openlayers.pandora');
// Header.
ui_print_page_header(
__('Map conections GIS'),
'',
false,
'',
true
);
$action = get_parameter('action');
switch ($action) {
@ -88,7 +79,7 @@ if ($mapsConnections !== false) {
$table->data[] = [
'<a href="index.php?sec=gsetup&sec2=godmode/setup/gis_step_2&amp;action=edit_connection_map&amp;id_connection_map='.$mapsConnection['id_tmap_connection'].'">'.$mapsConnection['conection_name'].'</a>',
ui_print_group_icon($mapsConnection['group_id'], true),
'<a href="index.php?sec=gsetup&sec2=godmode/setup/gis&amp;id_connection_map='.$mapsConnection['id_tmap_connection'].'&amp;action=delete_connection"
'<a href="index.php?sec=gsetup&sec2=godmode/setup/setup&amp;section=gis&amp;id_connection_map='.$mapsConnection['id_tmap_connection'].'&amp;action=delete_connection"
onClick="javascript: if (!confirm(\''.__('Do you wan delete this connection?').'\')) return false;">'.html_print_image('images/cross.png', true).'</a>',
];
$table->cellclass[][2] = 'action_buttons';

View File

@ -26,6 +26,10 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user
require_once 'include/functions_gis.php';
$buttons['gis'] = [
'text' => '<a href="'.ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup&section=gis').'">'.html_print_image('images/list.png', true, ['title' => __('GIS Maps connections')]).'</a>',
];
$action = get_parameter('action', 'create_connection_map');
if (is_ajax()) {
@ -41,7 +45,8 @@ switch ($action) {
'',
false,
'',
true
true,
$buttons
);
$mapConnection_name = '';
@ -67,7 +72,8 @@ switch ($action) {
'',
false,
'',
true
true,
$buttons
);
$idConnectionMap = get_parameter('id_connection_map');

View File

@ -138,6 +138,13 @@ $buttons['websocket_engine'] = [
'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=websocket_engine').'">'.html_print_image('images/websocket_small.png', true, ['title' => __('Websocket engine')]).'</a>',
];
if ($config['activate_gis']) {
$buttons['gis'] = [
'active' => false,
'text' => '<a href="'.ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup&section=gis').'">'.html_print_image('images/gis_tab.png', true, ['title' => __('GIS Map connection')]).'</a>',
];
}
$help_header = '';
if (enterprise_installed()) {
$subpage = setup_enterprise_add_subsection_main($section, $buttons, $help_header);
@ -183,6 +190,11 @@ switch ($section) {
$help_header = 'setup_integria_tab';
break;
case 'gis':
$buttons['gis']['active'] = true;
$subpage = ' &raquo '.__('Map conections GIS');
break;
case 'notifications':
$buttons['notifications']['active'] = true;
$subpage = ' &raquo '.__('Notifications');
@ -254,6 +266,10 @@ switch ($section) {
include_once $config['homedir'].'/godmode/setup/setup_integria.php';
break;
case 'gis':
include_once $config['homedir'].'/godmode/setup/gis.php';
break;
case 'notifications':
include_once $config['homedir'].'/godmode/setup/setup_notifications.php';
break;

View File

@ -1022,7 +1022,7 @@ if (check_login()) {
$title
);
$data[5] = ui_print_status_image($status, $title, true);
$data[5] = ui_print_status_image($status, htmlspecialchars($title), true);
if (!$show_context_help_first_time) {
$show_context_help_first_time = true;

View File

@ -123,7 +123,7 @@ class Tree
return '';
}
return " AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' ";
return " AND tam.nombre LIKE '%%".str_replace('%', '%%', $this->filter['searchModule'])."%%' ";
}
@ -133,7 +133,7 @@ class Tree
return '';
}
return " AND LOWER(ta.alias) LIKE LOWER('%%".$this->filter['searchAgent']."%%')";
return " AND LOWER(ta.alias) LIKE LOWER('%%".str_replace('%', '%%', $this->filter['searchAgent'])."%%')";
}
@ -331,7 +331,7 @@ class Tree
return '';
}
return " AND tg.nombre LIKE '%%".$this->filter['searchGroup']."%%'";
return " AND tg.nombre LIKE '%%".str_replace('%', '%%', $this->filter['searchGroup'])."%%'";
}
@ -623,7 +623,7 @@ class Tree
}
}
$module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true);
$module['statusImageHTML'] = ui_print_status_image($statusType, htmlspecialchars($statusTitle), true);
// HTML of the server type image
$module['serverTypeHTML'] = servers_show_type($module['server_type']);

View File

@ -20,7 +20,7 @@
/**
* Pandora build version and version
*/
$build_version = 'PC200203';
$build_version = 'PC200205';
$pandora_version = 'v7.0NG.743';
// Do not overwrite default timezone set if defined.

View File

@ -102,9 +102,9 @@ define('SECONDS_1MONTH', 2592000);
define('SECONDS_2MONTHS', 5184000);
define('SECONDS_3MONTHS', 7776000);
define('SECONDS_6MONTHS', 15552000);
define('SECONDS_1YEAR', 31104000);
define('SECONDS_2YEARS', 62208000);
define('SECONDS_3YEARS', 93312000);
define('SECONDS_1YEAR', 31536000);
define('SECONDS_2YEARS', 63072000);
define('SECONDS_3YEARS', 94608000);

View File

@ -301,8 +301,13 @@ function isInACL($ip)
// example lab.artica.es without '*'
$name = [];
$name = gethostbyname($acl_ip);
if (preg_match('/'.$name.'/', $ip)) {
return true;
if (preg_match('/'.$name.'/', $ip, $matches)) {
// This is for false matches, like '' or $.
if (count($matches) == 1 && $matches[0] == '') {
continue;
} else {
return true;
}
}
}
}

View File

@ -3647,7 +3647,7 @@ function events_get_response_target(
$ip = db_get_value_filter('direccion', $agente_table_name, $filter);
// If agent has not an IP, display N/A.
if ($ip === false) {
if ($ip === false || $ip === '') {
$ip = __('N/A');
}

View File

@ -3679,7 +3679,7 @@ function agents_get_network_interfaces_array(
/**
* reporting alert get fired
*/
function reporting_alert_get_fired($id_agent_module, $id_alert_template_module, $period, $datetime)
function reporting_alert_get_fired($id_agent_module, $id_alert_template_module, $period, $datetime, $return_empty=true)
{
$fired = [];
$firedTimes = get_module_alert_fired(
@ -3709,7 +3709,11 @@ function reporting_alert_get_fired($id_agent_module, $id_alert_template_module,
if ($fireTime['utimestamp'] > $datelimit && $fireTime['utimestamp'] <= $datetime) {
$fired[] = $fireTime['timestamp'];
} else {
$fired[] = $empty;
if ($return_empty === true) {
$fired[] = $empty;
} else {
continue;
}
}
}
@ -3821,10 +3825,15 @@ function reporting_alert_report_group($report, $content)
foreach ($actions['custom'] as $action) {
$data_action[$naction]['name'] = $action['name'];
$fired = $action['fired'];
if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)) {
$data_action[$naction]['fired'] = '----------------------------';
} else {
$data_action[$naction]['fired'] = $fired;
if ($fired == 0) {
$data_action[$naction]['fired'] = __('Not triggered');
} else if ($fired > 0) {
if ($fired > $datelimit && $fired < $datetime) {
$data_action[$naction]['fired'] = $fired;
} else {
continue 2;
}
}
$naction++;
@ -3833,10 +3842,15 @@ function reporting_alert_report_group($report, $content)
foreach ($actions['default'] as $action) {
$data_action[$naction]['name'] = $action['name'];
$fired = $action['fired'];
if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)) {
$data_action[$naction]['fired'] = '----------------------------';
} else {
$data_action[$naction]['fired'] = $fired;
if ($fired == 0) {
$data_action[$naction]['fired'] = __('Not triggered');
} else if ($fired > 0) {
if ($fired > $datelimit && $fired < $datetime) {
$data_action[$naction]['fired'] = $fired;
} else {
continue 2;
}
}
$naction++;
@ -3845,10 +3859,15 @@ function reporting_alert_report_group($report, $content)
foreach ($actions['unavailable'] as $action) {
$data_action[$naction]['name'] = $action['name'];
$fired = $action['fired'];
if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)) {
$data_action[$naction]['fired'] = '----------------------------';
} else {
$data_action[$naction]['fired'] = $fired;
if ($fired == 0) {
$data_action[$naction]['fired'] = __('Not triggered');
} else if ($fired > 0) {
if ($fired > $datelimit && $fired < $datetime) {
$data_action[$naction]['fired'] = $fired;
} else {
continue 2;
}
}
$naction++;
@ -3862,7 +3881,8 @@ function reporting_alert_report_group($report, $content)
$agent_module['id_agent_module'],
$actions['id'],
(int) $content['period'],
(int) $report['datetime']
(int) $report['datetime'],
false
);
$module_actions['actions'] = $data_action;

View File

@ -3822,7 +3822,7 @@ function ui_get_url_refresh($params=false, $relative=true, $add_post=true)
$url .= $key.'['.$k.']='.$v.'&';
}
} else {
$url .= $key.'='.$value.'&';
$url .= $key.'='.io_safe_input($value).'&';
}
}

View File

@ -129,7 +129,7 @@
<div style='height: 10px'>
<?php
$version = '7.0NG.743';
$build = '200203';
$build = '200205';
$banner = "v$version Build $build";
error_reporting(0);

View File

@ -1362,7 +1362,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_OK,
__('NORMAL').': '.$row['datos'],
__('NORMAL').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1376,7 +1376,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_CRITICAL,
__('CRITICAL').': '.$row['datos'],
__('CRITICAL').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1390,7 +1390,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_WARNING,
__('WARNING').': '.$row['datos'],
__('WARNING').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1404,7 +1404,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_UNKNOWN,
__('UNKNOWN').': '.$row['datos'],
__('UNKNOWN').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1418,7 +1418,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_NO_DATA,
__('NO DATA').': '.$row['datos'],
__('NO DATA').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1437,7 +1437,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_UNKNOWN,
__('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.$row['datos'],
__('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1453,7 +1453,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_UNKNOWN,
__('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.$row['datos'],
__('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.htmlspecialchars($row['datos']),
true
);
}
@ -1469,7 +1469,7 @@ if (!empty($result)) {
} else {
$data[6] = ui_print_status_image(
STATUS_MODULE_UNKNOWN,
__('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.$row['datos'],
__('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.htmlspecialchars($row['datos']),
true
);
}

View File

@ -81,6 +81,12 @@ if (!$modules || !$searchModules) {
$intervalCell = modules_get_interval($module['id_agente_modulo']);
$module_last_value = modules_get_last_value($module['id_agente_modulo']);
if (!is_numeric($module_last_value)) {
$module_last_value = htmlspecialchars($module_last_value);
}
if ($utimestamp_sql['utimestamp'] == 0
&& ( ($module['id_tipo_modulo'] < 21 || $module['id_tipo_modulo'] > 23)
&& $module['id_tipo_modulo'] != 100)
@ -93,25 +99,25 @@ if (!$modules || !$searchModules) {
} else if ($status_sql['estado'] == 0) {
$statusCell = ui_print_status_image(
STATUS_MODULE_OK,
__('NORMAL').': '.modules_get_last_value($module['id_agente_modulo']),
__('NORMAL').': '.$module_last_value,
true
);
} else if ($status_sql['estado'] == 1) {
$statusCell = ui_print_status_image(
STATUS_MODULE_CRITICAL,
__('CRITICAL').': '.modules_get_last_value($module['id_agente_modulo']),
__('CRITICAL').': '.$module_last_value,
true
);
} else if ($status_sql['estado'] == 2) {
$statusCell = ui_print_status_image(
STATUS_MODULE_WARNING,
__('WARNING').': '.modules_get_last_value($module['id_agente_modulo']),
__('WARNING').': '.$module_last_value,
true
);
} else if ($status_sql['estado'] == 3) {
$statusCell = ui_print_status_image(
STATUS_MODULE_UNKNOWN,
__('UNKNOWN').': '.modules_get_last_value($module['id_agente_modulo']),
__('UNKNOWN').': '.$module_last_value,
true
);
} else {
@ -120,7 +126,7 @@ if (!$modules || !$searchModules) {
case 0:
$statusCell = ui_print_status_image(
STATUS_MODULE_OK,
__('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.modules_get_last_value($module['id_agente_modulo']),
__('UNKNOWN').' - '.__('Last status').' '.__('NORMAL').': '.$module_last_value,
true
);
break;
@ -128,7 +134,7 @@ if (!$modules || !$searchModules) {
case 1:
$statusCell = ui_print_status_image(
STATUS_MODULE_CRITICAL,
__('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.modules_get_last_value($module['id_agente_modulo']),
__('UNKNOWN').' - '.__('Last status').' '.__('CRITICAL').': '.$module_last_value,
true
);
break;
@ -136,7 +142,7 @@ if (!$modules || !$searchModules) {
case 2:
$statusCell = ui_print_status_image(
STATUS_MODULE_WARNING,
__('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.modules_get_last_value($module['id_agente_modulo']),
__('UNKNOWN').' - '.__('Last status').' '.__('WARNING').': '.$module_last_value,
true
);
break;

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 7.0NG.743
%define release 200203
%define release 200205
# User and Group under which Apache is running
%define httpd_name httpd

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 7.0NG.743
%define release 200203
%define release 200205
# User and Group under which Apache is running
%define httpd_name httpd

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 7.0NG.743
%define release 200203
%define release 200205
%define httpd_name httpd
# User and Group under which Apache is running
%define httpd_name apache2

View File

@ -1,5 +1,5 @@
package: pandorafms-server
Version: 7.0NG.743-200203
Version: 7.0NG.743-200205
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.743-200203"
pandora_version="7.0NG.743-200205"
package_cpan=0
package_pandora=1

View File

@ -45,7 +45,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "7.0NG.743";
my $pandora_build = "200203";
my $pandora_build = "200205";
our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash

View File

@ -33,7 +33,7 @@ our @ISA = qw(Exporter);
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "7.0NG.743";
my $pandora_build = "200203";
my $pandora_build = "200205";
our $VERSION = $pandora_version." ".$pandora_build;
our %EXPORT_TAGS = ( 'all' => [ qw() ] );

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_server
%define version 7.0NG.743
%define release 200203
%define release 200205
Summary: Pandora FMS Server
Name: %{name}

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_server
%define version 7.0NG.743
%define release 200203
%define release 200205
Summary: Pandora FMS Server
Name: %{name}

View File

@ -9,7 +9,7 @@
# **********************************************************************
PI_VERSION="7.0NG.743"
PI_BUILD="200203"
PI_BUILD="200205"
MODE=$1
if [ $# -gt 1 ]; then

View File

@ -34,7 +34,7 @@ use PandoraFMS::Config;
use PandoraFMS::DB;
# version: define current version
my $version = "7.0NG.743 PS200203";
my $version = "7.0NG.743 PS200205";
# Pandora server configuration
my %conf;

View File

@ -36,7 +36,7 @@ use Encode::Locale;
Encode::Locale::decode_argv;
# version: define current version
my $version = "7.0NG.743 PS200203";
my $version = "7.0NG.743 PS200205";
# save program name for logging
my $progname = basename($0);

View File

@ -0,0 +1,68 @@
#!/usr/bin/python
# Kevin Rojas 2018
import os
import glob
import hashlib
import argparse
def main():
global args
global confdir
global md5dir
global agents
# Argument parser
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--run', required=False, dest='run', action='store_true',
help='run the tool to recreate md5 files')
parser.add_argument('-d', dest='dir', default='/var/spool/pandora/data_in',
help='data_in folder path (default /var/spool/pandora/data_in)')
parser.add_argument('-v', dest='verb', action='store_true',
help='verbose mode: Shows the files being updated')
# Definitions
args = vars(parser.parse_args())
datadir = args['dir']
confdir = datadir + '/conf/'
md5dir = datadir + '/md5/'
agents = glob.glob(confdir + '*.conf') # Check folder for .conf files
# Run script or show help
if len(args) > 0 and args['run']:
updatemd5()
else:
parser.print_help()
def md5sum(filename, blocksize=65536):
# Open files and calculate MD5 from its content
hash = hashlib.md5()
with open(filename, 'rb') as f:
for block in iter(lambda: f.read(blocksize), b''):
hash.update(block)
return hash.hexdigest()
def updatemd5():
debug = args['verb']
if not agents:
print(' ERROR: There are no .conf files at ' +
confdir + '. Please check the path provided.')
else:
count = 0
for i in agents:
agentmd5 = md5dir + os.path.basename(os.path.splitext(i)[0]) + '.md5'
with open(agentmd5, 'w') as f:
f.write(md5sum(i))
f.close()
count += 1
if debug:
print(os.path.basename(os.path.splitext(i)[0]) + '--> OK')
print('Number of configuration files updated: ' + str(count))
main()