diff --git a/extras/build_rpm_rhel7.sh b/extras/build_rpm_rhel7.sh new file mode 100755 index 0000000000..3684bd42e5 --- /dev/null +++ b/extras/build_rpm_rhel7.sh @@ -0,0 +1,26 @@ +#!/bin/bash +source build_vars.sh + +if [ ! -d $RPMHOME/RPMS ]; then + mkdir -p $RPMHOME/RPMS || exit 1 +fi + +echo "Creating RPM packages in $RPMHOME/RPMS" + +# Console +rpmbuild -ba $CODEHOME/pandora_console/pandora_console.rhel7.spec || exit 1 + +# Server +#rpmbuild -ba $CODEHOME/pandora_server/pandora_server.rhel7.spec || exit 1 + +# Unix agent +#rpmbuild -ba $CODEHOME/pandora_agents/unix/pandora_agent.rhel7.spec || exit 1 + +# Enterprise console +rpmbuild -ba $PANDHOME_ENT/pandora_console/enterprise/pandora_console_enterprise.rhel7.spec || exit 1 + +# Enterprise server +#rpmbuild -ba $PANDHOME_ENT/pandora_server/PandoraFMS-Enterprise/pandora_server_enterprise.rhel7.spec || exit 1 + +exit 0 + diff --git a/extras/docker/build_and_push.sh b/extras/docker/build_and_push.sh index 980087cfe5..91e6fa15e5 100755 --- a/extras/docker/build_and_push.sh +++ b/extras/docker/build_and_push.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker build --rm=true --build-arg BRANCH="develop" --build-arg DB_PASS="pandora" -t pandorafms/pandorafms:7 . && \ +docker build --rm=true --pull --no-cache --build-arg BRANCH="develop" --build-arg DB_PASS="pandora" -t pandorafms/pandorafms:7 . && \ docker push pandorafms/pandorafms:7 diff --git a/extras/pandora_update_version.sh b/extras/pandora_update_version.sh index 7d143f0f03..edab1affeb 100755 --- a/extras/pandora_update_version.sh +++ b/extras/pandora_update_version.sh @@ -26,9 +26,11 @@ $CODEHOME/pandora_server/pandora_server.spec \ $PANDHOME_ENT/pandora_console/enterprise/pandora_console_enterprise.spec \ $PANDHOME_ENT/pandora_server/PandoraFMS-Enterprise/pandora_server_enterprise.spec \ $CODEHOME/pandora_console/pandora_console.redhat.spec \ +$CODEHOME/pandora_console/pandora_console.rhel7.spec \ $CODEHOME/pandora_agents/unix/pandora_agent.redhat.spec \ $CODEHOME/pandora_server/pandora_server.redhat.spec \ $PANDHOME_ENT/pandora_console/enterprise/pandora_console_enterprise.redhat.spec \ +$PANDHOME_ENT/pandora_console/enterprise/pandora_console_enterprise.rhel7.spec \ $PANDHOME_ENT/pandora_server/PandoraFMS-Enterprise/pandora_server_enterprise.redhat.spec" DEBIAN_FILES="$CODEHOME/pandora_console/DEBIAN \ $CODEHOME/pandora_server/DEBIAN \ diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index 07054ee2e1..0ff67a62d3 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, AIX version +# Version 7.0NG.735, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index 9d8a49bb99..c7c6fdd493 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, FreeBSD Version +# Version 7.0NG.735, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index c02e4647e1..1a349583dc 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, HP-UX Version +# Version 7.0NG.735, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 153113e070..dc172b7e2f 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, GNU/Linux +# Version 7.0NG.735, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index 6ddeba7edc..3d76832397 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, GNU/Linux +# Version 7.0NG.735, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index 502317f893..9b088eae51 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, Solaris Version +# Version 7.0NG.735, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index 96b20ea7e3..e2c442a520 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2010 Artica Soluciones Tecnologicas -# Version 7.0NG.732 +# Version 7.0NG.735 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index 200ff9db97..fea0cb56db 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.732, AIX version +# Version 7.0NG.735, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index 2002f4db65..f0ce5b2519 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.732 +# Version 7.0NG.735 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index f9c19dbd06..20cdfeff99 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.732, HPUX Version +# Version 7.0NG.735, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index dc272a7a71..e8ba9653ce 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732 +# Version 7.0NG.735 # Licensed under GPL license v2, # (c) 2003-2010 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index 5a466677d2..29d13ff75c 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732 +# Version 7.0NG.735 # Licensed under GPL license v2, # (c) 2003-2009 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index 170188cc6f..8ef8a6fdc1 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732 +# Version 7.0NG.735 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index aad04ca60d..1ace947818 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.732, Solaris version +# Version 7.0NG.735, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 3ce7da3c7e..c67f64d16c 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, AIX version +# Version 7.0NG.735, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 92057ef5c2..b3b665370c 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.732-190319 +Version: 7.0NG.735-190612 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 502624d1db..4068a3039c 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.732-190319" +pandora_version="7.0NG.735-190612" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/Darwin/pandora_agent.conf b/pandora_agents/unix/Darwin/pandora_agent.conf index 35202fcbe5..d7ee481255 100644 --- a/pandora_agents/unix/Darwin/pandora_agent.conf +++ b/pandora_agents/unix/Darwin/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, GNU/Linux +# Version 7.0NG.735, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2012 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/FreeBSD/pandora_agent.conf b/pandora_agents/unix/FreeBSD/pandora_agent.conf index c505d5f75e..b02b379470 100644 --- a/pandora_agents/unix/FreeBSD/pandora_agent.conf +++ b/pandora_agents/unix/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, FreeBSD Version +# Version 7.0NG.735, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2016 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/HP-UX/pandora_agent.conf b/pandora_agents/unix/HP-UX/pandora_agent.conf index 237bffb291..57e35c0a03 100644 --- a/pandora_agents/unix/HP-UX/pandora_agent.conf +++ b/pandora_agents/unix/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, HP-UX Version +# Version 7.0NG.735, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index 5a65e0e095..db07876f12 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, GNU/Linux +# Version 7.0NG.735, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2014 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NT4/pandora_agent.conf b/pandora_agents/unix/NT4/pandora_agent.conf index 1394067390..8cda0f8fe0 100644 --- a/pandora_agents/unix/NT4/pandora_agent.conf +++ b/pandora_agents/unix/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, GNU/Linux +# Version 7.0NG.735, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NetBSD/pandora_agent.conf b/pandora_agents/unix/NetBSD/pandora_agent.conf index 677615a47c..629fe6a6fb 100644 --- a/pandora_agents/unix/NetBSD/pandora_agent.conf +++ b/pandora_agents/unix/NetBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, NetBSD Version +# Version 7.0NG.735, NetBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/SunOS/pandora_agent.conf b/pandora_agents/unix/SunOS/pandora_agent.conf index 89d5b46100..8ff3c52de5 100644 --- a/pandora_agents/unix/SunOS/pandora_agent.conf +++ b/pandora_agents/unix/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.732, Solaris Version +# Version 7.0NG.735, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 81eeb9b74d..4ed107c604 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,8 +41,8 @@ my $Sem = undef; # Semaphore used to control the number of threads my $ThreadSem = undef; -use constant AGENT_VERSION => '7.0NG.732'; -use constant AGENT_BUILD => '190319'; +use constant AGENT_VERSION => '7.0NG.735'; +use constant AGENT_BUILD => '190612'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; @@ -536,6 +536,12 @@ sub parse_conf_modules($) { # Check for invalid modules next unless (($module->{'name'} ne '' && $module->{'func'} != 0) || $module->{'func'} == \&module_plugin); + # Skip disabled modules. + if (defined($module->{'disabled'}) && $module->{'disabled'} == 1) { + log_message('setup', 'Skipping disabled module "' . $module->{'name'} . '"'); + next; + } + # Set the intensive interval if ($module->{'is_intensive'} == 1) { $module->{'intensive_interval'} = $module->{'interval'}; @@ -662,6 +668,8 @@ sub parse_conf_modules($) { $module->{'ff_timeout'} = $1; } elsif ($line =~ /^\s*module_each_ff\s+(\S+)\s*$/) { $module->{'each_ff'} = $1; + } elsif ($line =~ /^\s*module_ff_type\s+(\d+)\s*$/) { + $module->{'ff_type'} = $1; # Macros } elsif ($line =~ /^\s*module_macro(\S+)\s+(.*)\s*$/) { $module->{'macros'}{$1} = $2; @@ -1073,6 +1081,10 @@ sub send_buffered_xml_files ($;$) { unlink ("$temporal_file/$xml_file"); } } + # Do not get stuck trying to send buffered XML files to a secondary server. + elsif ($flag_always == 2) { + last; + } } if (defined($flag_always) && ($flag_always == 2)){ swap_servers (); @@ -2101,45 +2113,28 @@ sub cron_next_execution { } # Get day of the week and month from cron config - my ($mday, $wday) = (split (/\s/, $cron))[2, 4]; + my ($wday) = (split (/\s/, $cron))[4]; + # Check the wday values to avoid infinite loop + my ($wday_down, $wday_up) = cron_get_interval($wday); + if ($wday_down ne "*" && ($wday_down > 6 || (defined($wday_up) && $wday_up > 6))) { + log_message('setup', "Invalid cron configuration $cron. Day of the week is out of limits."); + $wday = "*"; + } # Get current time and day of the week my $cur_time = time(); my $cur_wday = (localtime ($cur_time))[6]; - # Any day of the week - if ($wday eq '*') { - my $nex_time = cron_next_execution_date ($cron, $cur_time, $interval); - return $nex_time - time(); - } - # A range? - else { - $wday = cron_get_closest_in_range ($cur_wday, $wday); + my $nex_time = cron_next_execution_date ($cron, $cur_time, $interval); + + # Check the day + while (!cron_check_interval($wday, (localtime ($nex_time))[6])) { + # If it does not acomplish the day of the week, go to the next day. + $nex_time += 86400; + $nex_time = cron_next_execution_date ($cron, $nex_time, 0); } - # A specific day of the week - my $count = 0; - my $nex_time = $cur_time; - do { - $nex_time = cron_next_execution_date ($cron, $nex_time, $interval); - my $nex_time_wd = $nex_time; - my ($nex_mon, $nex_wday) = (localtime ($nex_time_wd))[4, 6]; - my $nex_mon_wd; - do { - # Check the day of the week - if ($nex_wday == $wday) { - return $nex_time_wd - time(); - } - - # Move to the next day of the month - $nex_time_wd += 86400; - ($nex_mon_wd, $nex_wday) = (localtime ($nex_time_wd))[4, 6]; - } while ($mday eq '*' && $nex_mon_wd == $nex_mon); - $count++; - } while ($count < 60); - - # Something went wrong, default to 5 minutes - return $interval; + return $nex_time - time(); } ############################################################################### @@ -2151,7 +2146,30 @@ sub cron_check_syntax ($) { return 0 if !defined ($cron); return ($cron =~ m/^(\d|\*|-)+ (\d|\*|-)+ (\d|\*|-)+ (\d|\*|-)+ (\d|\*|-)+$/); } +############################################################################### +# Check if a value is inside an interval. +############################################################################### +sub cron_check_interval { + my ($elem_cron, $elem_curr_time) = @_; + # Return 1 if wildcard. + return 1 if ($elem_cron eq "*"); + + my ($down, $up) = cron_get_interval($elem_cron); + # Check if it is not a range + if (!defined($up)) { + return ($down == $elem_curr_time) ? 1 : 0; + } + + # Check if it is on the range + if ($down < $up) { + return 0 if ($elem_curr_time < $down || $elem_curr_time > $up); + } else { + return 0 if ($elem_curr_time > $down || $elem_curr_time < $up); + } + + return 1; +} ############################################################################### # Get the next execution date for the given cron entry in seconds since epoch. ############################################################################### @@ -2189,8 +2207,7 @@ sub cron_next_execution_date { my @nex_time_array = @curr_time_array; # Update minutes - my ($min_down, undef) = cron_get_interval ($min); - $nex_time_array[0] = ($min_down eq '*') ? 0 : $min_down; + $nex_time_array[0] = cron_get_next_time_element($min); $nex_time = cron_valid_date(@nex_time_array, $cur_year); if ($nex_time >= $cur_time) { @@ -2224,8 +2241,7 @@ sub cron_next_execution_date { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); #Update the hour if fails - my ($hour_down, undef) = cron_get_interval ($hour); - $nex_time_array[1] = ($hour_down eq '*') ? 0 : $hour_down; + $nex_time_array[1] = cron_get_next_time_element($hour); # When an overflow is passed check the hour update again $nex_time = cron_valid_date(@nex_time_array, $cur_year); @@ -2253,10 +2269,9 @@ sub cron_next_execution_date { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); #Update the day if fails - my ($mday_down, undef) = cron_get_interval ($mday); - $nex_time_array[2] = ($mday_down eq '*') ? 1 : $mday_down; + $nex_time_array[2] = cron_get_next_time_element($mday, 1); - # When an overflow is passed check the day update in the next execution + # When an overflow is passed check the hour update in the next execution $nex_time = cron_valid_date(@nex_time_array, $cur_year); if ($nex_time >= $cur_time) { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); @@ -2276,8 +2291,7 @@ sub cron_next_execution_date { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); #Update the month if fails - my ($mon_down, undef) = cron_get_interval ($mon); - $nex_time_array[3] = ($mon_down eq '*') ? 0 : $mon_down; + $nex_time_array[3] = cron_get_next_time_element($mon); # When an overflow is passed check the month update in the next execution $nex_time = cron_valid_date(@nex_time_array, $cur_year); @@ -2308,23 +2322,30 @@ sub cron_is_in_cron { #If there is no elements means that is in cron return 1 unless (defined($elem_cron) || defined($elem_curr_time)); - # Go to last element if current is a wild card - if ($elem_cron ne '*') { - my ($down, $up) = cron_get_interval($elem_cron); - # Check if there is no a range - return 0 if (!defined($up) && ($down != $elem_curr_time)); - # Check if there is on the range - if (defined($up)) { - if ($down < $up) { - return 0 if ($elem_curr_time < $down || $elem_curr_time > $up); - } else { - return 0 if ($elem_curr_time > $down || $elem_curr_time < $up); - } - } - } + # Check the element interval + return 0 unless (cron_check_interval($elem_cron, $elem_curr_time)); + return cron_is_in_cron(\@deref_elems_cron, \@deref_elems_curr_time); } +################################################################################ +#Get the next tentative time for a cron value or interval in case of overflow. +#Floor data is the minimum localtime data for a position. Ex: +#Ex: +# * should returns floor data. +# 5 should returns 5. +# 10-55 should returns 10. +# 55-10 should retunrs floor data. +################################################################################ +sub cron_get_next_time_element { + # Default floor data is 0 + my ($curr_element, $floor_data) = @_; + $floor_data = 0 unless defined($floor_data); + my ($elem_down, $elem_up) = cron_get_interval ($curr_element); + return ($elem_down eq '*' || (defined($elem_up) && $elem_down > $elem_up)) + ? $floor_data + : $elem_down; +} ############################################################################### # Returns the interval of a cron element. If there is not a range, # returns an array with the first element in the first place of array @@ -2416,12 +2437,11 @@ sub check_module_cron { return 1 unless ($is_first); # Check if current timestamp is a valid cron date - my $next_execution = cron_next_execution_date( + my $next_execution = cron_next_execution( $module->{'cron'}, - $now - $interval, - $interval + 0 ); - return 1 if ($next_execution == $now); + return 1 if (time() + $next_execution == $now); return 0; } @@ -2532,6 +2552,7 @@ sub write_module_xml ($@) { $Xml .= " " . $module->{'min_ff_event_critical'} . "\n" if (defined ($module->{'min_ff_event_critical'})); $Xml .= " " . $module->{'ff_timeout'} . "\n" if (defined ($module->{'ff_timeout'})); $Xml .= " " . $module->{'each_ff'} . "\n" if (defined ($module->{'each_ff'})); + $Xml .= " " . $module->{'ff_type'} . "\n" if (defined ($module->{'ff_type'})); # Data list if ($#data > 0) { @@ -3017,10 +3038,10 @@ while (1) { my @address_list; if( -x "/bin/ip" || -x "/sbin/ip" || -x "/usr/sbin/ip" ) { - @address_list = `ip addr show 2>$DevNull | sed -e '/127.0.0/d' -e '/[0-9]*\\.[0-9]*\\.[0-9]*/!d' -e 's/^[ \\t]*\\([^ \\t]*\\)[ \\t]*\\([^ \\t]*\\)[ \\t].*/\\2/' -e 's/\\/.*//'`; + @address_list = `ip addr show 2>$DevNull | sed -e '/127.0.0/d' -e '/\\([0-9][0-9]*\\.\\)\\{3\\}[0-9][0-9]*/!d' -e 's/^[ \\t]*\\([^ \\t]*\\)[ \\t]*\\([^ \\t]*\\)[ \\t].*/\\2/' -e 's/\\/.*//'`; } else { - @address_list = `ifconfig -a 2>$DevNull | sed -e '/127.0.0/d' -e '/[0-9]*\\.[0-9]*\\.[0-9]*/!d' -e 's/^[ \\t]*\\([^ \\t]*\\)[ \\t]*\\([^ \\t]*\\)[ \\t].*/\\2/' -e 's/.*://'`; + @address_list = `ifconfig -a 2>$DevNull | sed -e '/127.0.0/d' -e '/\\([0-9][0-9]*\\.\\)\\{3\\}[0-9][0-9]*/!d' -e 's/^[ \\t]*\\([^ \\t]*\\)[ \\t]*\\([^ \\t]*\\)[ \\t].*/\\2/' -e 's/.*://'`; } for (my $i = 0; $i <= $#address_list; $i++) { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 895791cbdf..f09e281cfc 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.732 -%define release 190319 +%define version 7.0NG.735 +%define release 190612 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 778c5864bf..c5f3b47600 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.732 -%define release 190319 +%define version 7.0NG.735 +%define release 190612 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 5c960e5725..27ca5cb3c0 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -9,8 +9,8 @@ # Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.732" -PI_BUILD="190319" +PI_VERSION="7.0NG.735" +PI_BUILD="190612" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/unix/plugins/grep_log b/pandora_agents/unix/plugins/grep_log index 2e17210a51..76661c5230 100755 --- a/pandora_agents/unix/plugins/grep_log +++ b/pandora_agents/unix/plugins/grep_log @@ -6,17 +6,17 @@ # # grep_log Perl script to search log files for a matching pattern. The last # searched position is saved in an index file so that consecutive -# runs do not return the same results. The log file inode number is +# runs do not return the same results. The log file inode number is # also saved to detect log rotation. # # 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; version 2 of the License. -# +# # 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. +# GNU General Public License for more details. # ############################################################################### use strict; @@ -30,7 +30,7 @@ my $Output = 'module'; my $Verbose = 0; # Index file storage directory, with a trailing '/' -my $Idx_dir=($^O =~ /win/i)?'.\\':'/tmp/'; +my $Idx_dir=($^O =~ /win/i)?"$ENV{'TMP'}\\":"/tmp/"; # Log file my $Log_file = ''; @@ -64,7 +64,7 @@ if ( (defined ($ENV{GREP_LOG_TMP})) && (-d $ENV{GREP_LOG_TMP}) ) { } ######################################################################################## -# Erase blank spaces before and after the string +# Erase blank spaces before and after the string ######################################################################################## sub trim($){ my $string = shift; @@ -226,7 +226,7 @@ sub parse_log (;$$) { open(LOGFILE, $Log_file) || error_msg("Error opening file $Log_file: " . $!); - # Go to starting position. + # Go to starting position. seek(LOGFILE, $Idx_pos, 0); # Parse log file @@ -318,7 +318,7 @@ sub print_log ($) { print_summary() if ($summary_flag == 1); return; } - + # Log module if ($Output eq 'log_module') { my $output = "\n"; diff --git a/pandora_agents/unix/plugins/inventory b/pandora_agents/unix/plugins/inventory index a6d9a8bc83..6ef6233d23 100755 --- a/pandora_agents/unix/plugins/inventory +++ b/pandora_agents/unix/plugins/inventory @@ -4,23 +4,44 @@ # Copyright (c) 2009 Artica Soluciones Tecnologicas S.L. # # inventory Generate a hardware/software inventory. -# +# # Sample usage: ./inventory [cpu] [ram] [video] [nic] [hd] [cdrom] [software] [init_services] [filesystem] [process] [users] # # 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; version 2 of the License. -# +# # 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. +# GNU General Public License for more details. # ############################################################################### use strict; use constant TSTAMP_FILE => '/tmp/pandora_inventory.tstamp'; +use Scalar::Util qw(looks_like_number); +use Data::Dumper; +# Set environment language to English +$ENV{"LANG"} = "en_US"; + +# Check AIX system +my $AIX=0; +my $system = `uname -a | awk '{print $1}'`; +if ($system =~ 'AIX') { + $AIX=1; +} + +sub is_enabled { + my $value = shift; + if ((defined ($value)) && looks_like_number($value) && ($value > 0)){ + # return true + return 1; + } + #return false + return 0; +} # Operation mode (LSHW or HWINFO) my $Mode; @@ -31,12 +52,12 @@ my $Separator; sub get_module_data ($$$$) { my ($name, $hwinfo, $keys, $modules) = @_; my %module; - - # Store keys + $Separator='\s+\*\-'; + # Store keys foreach my $key (@{$keys}) { push (@{$module{'_keys'}}, $key); } - + # Parse module data while (my $line = shift (@{$hwinfo})) { if ($line =~ /$Separator/) { @@ -46,7 +67,7 @@ sub get_module_data ($$$$) { foreach my $key (@{$keys}) { if ($line =~ /$key:\s+(.+)/) { $module{$key} = $1; - # Replace semicolon by comma to avoid parse errors + # Replace semicolon by comma to avoid parse errors $module{$key} =~ s/;/,/g; } } @@ -58,12 +79,65 @@ sub get_module_data ($$$$) { push (@{$modules->{$name}}, \%module); } +sub test_contain ($$) { + my ($value, $array)=@_; + if ( grep( /$value/, @{$array} ) ) { + return 1; + } +} +sub get_module_data_aix_ram_cpu ($$$$) { + my ($name, $hwinfo, $keys, $modules) = @_; + my %module; + # Store keys + foreach my $key (@{$keys}) { + push (@{$module{'_keys'}}, $key); + } + # Parse module data + foreach my $line (@{$hwinfo}) { + foreach my $key (@{$keys}) { + if ($line =~ /$key:\s+(.+)/) { + $module{$key} = $1; + $module{$key} =~ s/,/ /g; + } + } + } + + # No data found + #my @data = keys (%module); + #return unless ($#data >= 0); + + push (@{$modules->{$name}}, \%module); +} +sub get_module_data_aix ($$$$) { + my ($name,$hwinfo,$regex,$modules) = @_; + my %module; + foreach my $line (@{$hwinfo}) { + $line =~ s/\s{2,}/;/g; + $line =~ s/\+ //g; + $line =~ s/\* //g; + } + foreach my $line (@{$hwinfo}) { + if ($line =~ /$regex/){ + my ($var1, $var2, $var3) = split /;/, $line; + my %module; + $module{'device'} = $var1; + $module{'serial'} = $var2; + $module{'description'}=$var3; + $module{'_keys'} = ['device','serial','description']; + push (@{$modules->{$name}}, \%module); + } + } +} # Get a list of information file system in machine sub get_file_system($$) { my ($name, $modules) = @_; - - my @fileSystems = `df -hP | tail -n +2`; #remove the titles of columns + my @fileSystems; + if (is_enabled $AIX){ + @fileSystems = `df -gP | tail -n +2`; + } else { + @fileSystems = `df -hP | tail -n +2`; #remove the titles of columns + } foreach my $row (@fileSystems) { next unless ($row =~ /^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)/); @@ -73,94 +147,110 @@ sub get_file_system($$) { $module{'used'} = $2; $module{'avail'} = $3; $module{'mount'} = $4; - $module{'_keys'} = ['filesystem', 'used','avail', 'mount']; - push (@{$modules->{$name}}, \%module); - } + $module{'_keys'} = ['filesystem', 'used','avail', 'mount']; + push (@{$modules->{$name}}, \%module); + } } # Get a list of services init in machine sub get_servicies_init_machine($$) { my ($name, $modules) = @_; - my $runlevel = `who -r | awk '{print \$2}'`; + my $runlevel; + if (is_enabled $AIX) { + $runlevel = `who -r | awk '{print \$3}'`; + } else { + $runlevel = `who -r | awk '{print \$2}'`; + } #ini trim($runlevel) $runlevel =~ s/^\s*//; #ltrim $runlevel =~ s/\s*$//; #rtrim #end trim($runlevel) - my $script = ""; - + my $script; + if (-e "/etc/rc" . $runlevel .".d/") { - $script = "ls /etc/rc" . $runlevel .".d/ -l | grep \"^l.*\" | awk \"{print \\\$NF}\" | sed -e \"s/\\.\\.\\///g\" | sed -e \"s/.*init\\.d\\///g\""; + $script = "ls -l /etc/rc" . $runlevel .".d/ | grep \"^l.*\" | awk \"{print \\\$NF}\" | sed -e \"s/\\.\\.\\///g\" | sed -e \"s/.*init\\.d\\///g\""; } else { - $script = "ls /etc/rc.d/rc" . $runlevel .".d/ -l | grep \"^l.*\" | grep \" S.* \" | awk \"{print \\\$NF}\" | sed -e \"s/\\.\\.\\///g\" | sed -e \"s/.*init\\.d\\///g\""; - + $script = "ls -l /etc/rc.d/rc" . $runlevel .".d/ | grep \"^l.*\" | grep \" S.* \" | awk \"{print \\\$NF}\" | sed -e \"s/\\.\\.\\///g\" | sed -e \"s/.*init\\.d\\///g\""; } - + my @services = `$script`; foreach my $row (@services) { - my %module; - $row =~ s/\n//; - $module{'service'} = $row; - $module{'_keys'} = ['service']; - push (@{$modules->{$name}}, \%module); + $row =~ s/\n//; + $module{'service'} = $row; + $module{'_keys'} = ['service']; + push (@{$modules->{$name}}, \%module); } } # Get a list of running processes sub get_processes ($$) { my ($name, $modules) = @_; + my $script; + if (is_enabled $AIX) { + $script = "ps -eo args | tail -n +2"; + } else { + $script = "ps -eo command | tail -n +2"; + } - my $script = "ps -eo command"; - - my @services = `$script`; - foreach my $row (@services) { - my %module; - # Remove carriage returns - $row =~ s/[\n\l\f]//g; - # Replace semicolon by comma to avoid parse errors - $row =~ s/;/,/g; - $module{'service'} = $row; - $module{'_keys'} = ['service']; - push (@{$modules->{$name}}, \%module); - } + my @services = `$script`; + foreach my $row (@services) { + my %module; + # Remove carriage returns + $row =~ s/[\n\l\f]//g; + # Replace semicolon by comma to avoid parse errors + $row =~ s/;/,/g; + $module{'service'} = $row; + $module{'_keys'} = ['service']; + push (@{$modules->{$name}}, \%module); + } } # Get a list of valid users in the system sub get_users ($$) { - my ($name, $modules) = @_; - - my $script = "cat /etc/passwd"; + my ($name, $modules) = @_; + my $script = "cat /etc/passwd"; my $user = ""; my $estado = ""; - my @services = `$script`; - foreach my $row (@services) { - my %module; + my @services = `$script`; + foreach my $row (@services) { + my %module; - next unless ($row =~ /^([A-Za-z0-9\-\_]*)/); - - $user = $1; - $script = `passwd -S $user`; - if ( $script =~ /^(\S+)\sP./){ - $module{'user'} = $user; - $module{'_keys'} = ['user']; - push (@{$modules->{$name}}, \%module); + next unless ($row =~ /^([A-Za-z0-9\-\_]*)/); + if (is_enabled $AIX) { + $user = $1; + $script = `lsuser $user`; + if ( $script =~ /^(\S+)\sid./){ + $module{'user'} = $user; + $module{'_keys'} = ['user']; + push (@{$modules->{$name}}, \%module); + } + } else { + $user = $1; + $script = `passwd -S $user`; + if ( $script =~ /^(\S+)\sP./){ + $module{'user'} = $user; + $module{'_keys'} = ['user']; + push (@{$modules->{$name}}, \%module); } } + + } } # Show Kernel Information sub get_kernel_info ($$) { - my ($name, $modules) = @_; - my $script = `uname -a | tr -d \";\"`; - my %module; + my ($name, $modules) = @_; + my $script = `uname -a | tr -d \";\"`; + my %module; - $module{'Kernel'} = $script; - $module{'_keys'} = ['Kernel']; - push (@{$modules->{$name}}, \%module); + $module{'Kernel'} = $script; + $module{'_keys'} = ['Kernel']; + push (@{$modules->{$name}}, \%module); } @@ -171,11 +261,13 @@ sub get_software_module_data ($$) { # Guess the current distribution my $distrib_id = ""; - if ( -e "/etc/SuSE-release"){ + if (is_enabled $AIX) { + $distrib_id = "AIX"; + }elsif ( -e "/etc/SuSE-release"){ $distrib_id = "SUSE"; - } elsif ( -e "/etc/redhat-release"){ + }elsif ( -e "/etc/redhat-release"){ $distrib_id = "REDHAT"; - } else { + }else { $distrib_id = "DEBIAN"; } @@ -183,7 +275,9 @@ sub get_software_module_data ($$) { my @soft; if ($distrib_id eq 'DEBIAN') { @soft = `dpkg -l | grep ii`; - } else { + }elsif ($distrib_id eq 'AIX') { + @soft = `lslpp -Lcq | awk -F: '{print "ii "\$1" "\$3" "\$8}'`; + }else { # Sometimes rpm return data splitted in two lines, and with dupes. Thats bad for our inventory system @soft = `rpm -q -a --qf "ii %{NAME} %{VERSION} %{SUMMARY}\n" | grep "^ii" | sort -u`; } @@ -197,7 +291,7 @@ sub get_software_module_data ($$) { $module{'program'} = $1; $module{'version'} = $2; $module{'description'} = $3; - # Replace semicolon by comma to avoid parse errors + # Replace semicolon by comma to avoid parse errors $module{'program'} =~ s/;/,/g; $module{'version'} =~ s/;/,/g; $module{'description'} =~ s/;/,/g; @@ -211,67 +305,95 @@ sub get_software_module_data ($$) { #Get the list of interfaces with the ip assigned sub get_ips ($$) { my ($name, $modules) = @_; + my @interfaces; + my $ifconfig; + if (is_enabled $AIX) { + $ifconfig = `ifconfig -a`; + } else { + $ifconfig = `ifconfig`; + } - my $ifconfig = `ifconfig`; - - my @ifconfig_array = split("\n", $ifconfig); - - for(my $i = 0; $i<$#ifconfig_array; $i++) { - - #Check for an interface - if ($ifconfig_array[$i] =~ /Link/) { - my %info; - - my @line_split = split(" ", $ifconfig_array[$i]); - - #Get interface name - $info{'interface'} = $line_split[0]; - #Get IP address - my $line = $ifconfig_array[$i+1]; - - $line =~ s/\s+//g; + my @ifconfig_array = split("\n", $ifconfig); - @line_split = split(":", $line); - - if($line_split[1] =~ /(\d+\.\d+\.\d+\.\d+).+/) { - $info{'ip'} = $1; - } - - $info{'_keys'} = ['interface', 'ip']; - push (@{$modules->{$name}}, \%info); - - } + foreach (@ifconfig_array){ + if ($_=~/(.*)flags/){ + my $match; + ($match)=$_=~/^(.*?)\: flags/; + $match=~s/://; + push @interfaces,$match; + } + } + foreach (@interfaces) { + my $ifconfig_item=`ifconfig $_`; + my $interface=$_; + my @ip_array = split("\n", $ifconfig_item); + foreach (@ip_array) { + if ($_=~/(?<=inet )(.*)(?= netmask)/){ + my $ip; + ($ip)=$_=~/inet (.*) netmask/; + my %info; + $info{'interface'} = $interface; + $info{'ip'} = $ip; + $info{'_keys'} = ['interface','ip']; + push (@{$modules->{$name}}, \%info); + } + } } } #Get route table sub get_route_table ($$) { - my ($name, $modules) = @_; - - my $route_table = `route`; - - my @table_split = split("\n", $route_table); - - for (my $i=2; $i<=$#table_split; $i++) { - - my @split = split(" ", $table_split[$i]); - - my %info; - - $info{'destination'} = $split[0]; - $info{'gateway'} = $split[1]; - $info{'mask'} = $split[2]; - $info{'flags'} = $split[3]; - $info{'metric'} = $split[4]; - $info{'ref'} = $split[5]; - $info{'use'} = $split[6]; - $info{'interface'} = $split[7]; - - $info{'_keys'} = ['destination', 'gateway', 'mask', 'flags', 'metric', 'use', 'interface']; - - push (@{$modules->{$name}}, \%info); - } + my ($name, $modules) = @_; + my $route_table; + my @table_split; + if (is_enabled $AIX) { + $route_table = `netstat -rn`; + @table_split = split("\n", $route_table); + my $length=scalar @table_split; + for (my $i=4; $i<=$length-4; $i++) { + + my @split = split(" ", $table_split[$i]); + + my %info; + + $info{'destination'} = $split[0]; + $info{'gateway'} = $split[1]; + $info{'mask'} = $split[2]; + $info{'flags'} = $split[3]; + $info{'metric'} = $split[4]; + $info{'ref'} = $split[5]; + $info{'use'} = $split[6]; + $info{'interface'} = $split[7]; + + $info{'_keys'} = ['destination', 'gateway', 'mask', 'flags', 'metric', 'use', 'interface']; + + push (@{$modules->{$name}}, \%info); + } + } else { + $route_table = `route`; + my @table_split = split("\n", $route_table); + + for (my $i=2; $i<=$#table_split; $i++) { + + my @split = split(" ", $table_split[$i]); + + my %info; + + $info{'destination'} = $split[0]; + $info{'gateway'} = $split[1]; + $info{'mask'} = $split[2]; + $info{'flags'} = $split[3]; + $info{'metric'} = $split[4]; + $info{'ref'} = $split[5]; + $info{'use'} = $split[6]; + $info{'interface'} = $split[7]; + + $info{'_keys'} = ['destination', 'gateway', 'mask', 'flags', 'metric', 'use', 'interface']; + + push (@{$modules->{$name}}, \%info); + } + } } # Print module data sub print_module ($$) { @@ -309,14 +431,18 @@ my $enable_all = 0; $interval = $ARGV[0]; if ($#ARGV == 0){ - $enable_all = 1; + $enable_all = 1; +} +if ($interval!=/[:alpha:]/){ + splice @ARGV,0,1; } -foreach my $module (@ARGV) { +foreach my $module (@ARGV) { if ($module eq "all"){ - $enable_all = 1; - } - $enabled{$module} = 1; + $enable_all = 1; + }else { + $enabled{$module} = 1; + } } # Check execution interval @@ -333,76 +459,107 @@ close (FILE); # Retrieve hardware information $Mode = 'LSHW'; $Separator = '\s+\*\-'; -my @hwinfo = `lshw 2>/dev/null`; -if ($? != 0) { - $Mode = 'HWINFO'; - $Separator = 'Hardware Class:'; - @hwinfo = `hwinfo --cpu --memory --gfxcard --netcard --cdrom --disk 2>/dev/null`; +my @hwinfo; +if (is_enabled $AIX) { + $Separator = '^\s*$'; + @hwinfo=`prtconf 2>/dev/null`; +} else { + @hwinfo = `lshw 2>/dev/null`; + if ($? != 0) { + $Mode = 'HWINFO'; + $Separator = 'Hardware Class:'; + @hwinfo = `hwinfo --cpu --memory --gfxcard --netcard --cdrom --disk 2>/dev/null`; + } } -# Parse hardware information my %modules; -while (my $line = shift (@hwinfo)) { + + if (is_enabled $AIX) { + #CPU + # VIDEO + ### Not avilable in AIX ### + # NIC + ### Not relevant in AIX ### + if ((test_contain('ent',\@hwinfo)) && ($enable_all == 1 || $enabled{'nic'} == 1)) { + get_module_data_aix ('NIC',\@hwinfo,'^ent',\%modules); + } + if ((test_contain('hdisk',\@hwinfo)) && ($enable_all == 1 || $enabled{'hd'} == 1)) { + get_module_data_aix ('HD',\@hwinfo,'^hdisk',\%modules); + } + + foreach my $line (@hwinfo) { + chomp ($line); + #CPU + if (($line =~ /^Memory Size:/) && ($enable_all == 1 || $enabled{'ram'} == 1)) { + get_module_data_aix_ram_cpu ('RAM', \@hwinfo, ['Memory Size','Good Memory Size'], \%modules); + } + + if (($line =~ /^System Model/) && ($enable_all == 1 || $enabled{'cpu'} == 1)) { + get_module_data_aix_ram_cpu ('CPU', \@hwinfo, ['System Model', 'Processor Implementation Mode', 'Number Of Processors'], \%modules); + } + } +} else { + # Parse hardware information + while (my $line= shift (@hwinfo)) { chomp ($line); + # CPU + if (($line =~ /\*\-cpu/ || $line =~ /Hardware Class: cpu/) && ($enable_all == 1 || $enabled{'cpu'} == 1)) { + if ($Mode eq 'LSHW') { + get_module_data ('CPU', \@hwinfo, ['product', 'vendor', 'capacity'], \%modules); + } else { + get_module_data ('CPU', \@hwinfo, ['Model', 'Vendor', 'Clock'], \%modules); + } + } - # CPU - if (($line =~ /\*\-cpu/ || $line =~ /Hardware Class: cpu/) && ($enable_all == 1 || $enabled{'cpu'} == 1)) { - if ($Mode eq 'LSHW') { - get_module_data ('CPU', \@hwinfo, ['product', 'vendor', 'capacity'], \%modules); - } else { - get_module_data ('CPU', \@hwinfo, ['Model', 'Vendor', 'Clock'], \%modules); - } - } + # RAM + if (($line =~ /\*\-bank/ || $line =~ /\*\-memory/ || $line =~ /Hardware Class: memory/) && ($enable_all == 1 || $enabled{'ram'} == 1)) { + if ($Mode eq 'LSHW') { + get_module_data ('RAM', \@hwinfo, ['description', 'size'], \%modules); + } else { + get_module_data ('RAM', \@hwinfo, ['Model', 'Memory Size'], \%modules); + } + } - # RAM - if (($line =~ /\*\-bank/ || $line =~ /Hardware Class: memory/) && ($enable_all == 1 || $enabled{'ram'} == 1)) { - if ($Mode eq 'LSHW') { - get_module_data ('RAM', \@hwinfo, ['description', 'size'], \%modules); - } else { - get_module_data ('RAM', \@hwinfo, ['Model', 'Memory Size'], \%modules); - } - } + # VIDEO + if (($line =~ /\*\-display/ || $line =~ /Hardware Class: graphics card/) && ($enable_all == 1 || $enabled{'video'} == 1)) { + if ($Mode eq 'LSHW') { + get_module_data ('VIDEO', \@hwinfo, ['product', 'description', 'vendor'], \%modules); + } else { + # Spaces before Device and Vendor are intentional to avoid matching SubDevice and SubVendor + get_module_data ('VIDEO', \@hwinfo, ['Model', ' Device', ' Vendor'], \%modules); + } + } - # VIDEO - if (($line =~ /\*\-display/ || $line =~ /Hardware Class: graphics card/) && ($enable_all == 1 || $enabled{'video'} == 1)) { - if ($Mode eq 'LSHW') { - get_module_data ('VIDEO', \@hwinfo, ['product', 'description', 'vendor'], \%modules); - } else { - # Spaces before Device and Vendor are intentional to avoid matching SubDevice and SubVendor - get_module_data ('VIDEO', \@hwinfo, ['Model', ' Device', ' Vendor'], \%modules); - } - } + # NIC + if (($line =~ /\*\-network/ || $line =~ /Hardware Class: network/) && ($enable_all == 1 || $enabled{'nic'} == 1)) { + if ($Mode eq 'LSHW') { + get_module_data ('NIC', \@hwinfo, ['product', 'description', 'vendor', 'serial'], \%modules); + } else { + # Spaces before Device and Vendor are intentional to avoid matching SubDevice and SubVendor + get_module_data ('NIC', \@hwinfo, ['Model', ' Device', ' Vendor', 'HW Address'], \%modules); + } + } - # NIC - if (($line =~ /\*\-network/ || $line =~ /Hardware Class: network/) && ($enable_all == 1 || $enabled{'nic'} == 1)) { - if ($Mode eq 'LSHW') { - get_module_data ('NIC', \@hwinfo, ['product', 'description', 'vendor', 'serial'], \%modules); - } else { - # Spaces before Device and Vendor are intentional to avoid matching SubDevice and SubVendor - get_module_data ('NIC', \@hwinfo, ['Model', ' Device', ' Vendor', 'HW Address'], \%modules); - } - } - - # CDROM - if (($line =~ /\*\-cdrom/ || $line =~ /Hardware Class: cdrom/) && ($enable_all == 1 || $enabled{'cdrom'} == 1)) { - if ($Mode eq 'LSHW') { - get_module_data ('CDROM', \@hwinfo, ['product', 'description', 'vendor'], \%modules); - } else { - # Spaces before Device and Vendor are intentional to avoid matching SubDevice and SubVendor - get_module_data ('CDROM', \@hwinfo, ['Model', ' Device', ' Vendor'], \%modules); - } - } + # CDROM + if (($line =~ /\*\-cdrom/ || $line =~ /Hardware Class: cdrom/) && ($enable_all == 1 || $enabled{'cdrom'} == 1)) { + if ($Mode eq 'LSHW') { + get_module_data ('CDROM', \@hwinfo, ['product', 'description', 'vendor'], \%modules); + } else { + # Spaces before Device and Vendor are intentional to avoid matching SubDevice and SubVendor + get_module_data ('CDROM', \@hwinfo, ['Model', ' Device', ' Vendor'], \%modules); + } + } - # HD - if (($line =~ /\*\-disk/ || $line =~ /Hardware Class: disk/) && ($enable_all == 1 || $enabled{'hd'} == 1)) { - if ($Mode eq 'LSHW') { - get_module_data ('HD', \@hwinfo, ['product', 'description', 'size'], \%modules); - } else { - get_module_data ('HD', \@hwinfo, ['Model', 'Serial ID', 'Size'], \%modules); - } - } + # HD + if (($line =~ /\*\-disk/ || $line =~ /Hardware Class: disk/) && ($enable_all == 1 || $enabled{'hd'} == 1)) { + if ($Mode eq 'LSHW') { + get_module_data ('HD', \@hwinfo, ['product', 'description', 'size'], \%modules); + } else { + get_module_data ('HD', \@hwinfo, ['Model', 'Serial ID', 'Size'], \%modules); + } + } + } } - # Software if ($enable_all == 1 || $enabled{'software'} == 1) { get_software_module_data ('Software', \%modules); @@ -410,12 +567,12 @@ if ($enable_all == 1 || $enabled{'software'} == 1) { #init_services if ($enable_all == 1 || $enabled{'init_services'} == 1) { - get_servicies_init_machine ('Init services', \%modules); + get_servicies_init_machine ('Init_services', \%modules); } #filesystem if ($enable_all == 1 || $enabled{'filesystem'} == 1) { - get_file_system('File system', \%modules); + get_file_system('Filesystem', \%modules); } #processes @@ -442,7 +599,6 @@ if ($enable_all == 1 || $enabled{'route'} == 1) { if ($enable_all == 1 || $enabled{'kernel'} == 1){ get_kernel_info ('Kernel', \%modules); } - # Print module data print "\n"; while (my ($name, $module) = each (%modules)) { diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index 3d1e208de8..518cd3df0e 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2017 Artica Soluciones Tecnologicas -# Version 7.0NG.732 +# Version 7.0NG.735 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software @@ -44,6 +44,8 @@ remote_config 0 #agent_name_cmd cscript.exe //B "%ProgramFiles%\Pandora_Agent\util\agentname.vbs" agent_name_cmd __rand__ +# Agent alias. Name should be unique rather than alias. Hostname by default +# agent_alias $Alias$ #Parent agent_name #parent_agent_name caprica diff --git a/pandora_agents/win32/bin/util/grep_log.exe b/pandora_agents/win32/bin/util/grep_log.exe index a21e080805..4e4029fb60 100644 Binary files a/pandora_agents/win32/bin/util/grep_log.exe and b/pandora_agents/win32/bin/util/grep_log.exe differ diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index c46da70b35..bbb5ef688d 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -3,7 +3,7 @@ AllowLanguageSelection {Yes} AppName -{Pandora FMS Windows Agent v7.0NG.732} +{Pandora FMS Windows Agent v7.0NG.735} ApplicationID {17E3D2CF-CA02-406B-8A80-9D31C17BD08F} @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{190319} +{190612} ViewReadme {Yes} diff --git a/pandora_agents/win32/misc/cron.cc b/pandora_agents/win32/misc/cron.cc index 2d3e5e0440..409a43f726 100644 --- a/pandora_agents/win32/misc/cron.cc +++ b/pandora_agents/win32/misc/cron.cc @@ -214,7 +214,7 @@ int Cron::getResetValue (int position) { int default_value = 0; // Days start in 1 if (position == 2) default_value = 1; - return isWildCard(position) + return (isWildCard(position) || !isNormalInterval(position)) ? default_value : this->params[position][CRDOWN]; } diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index eac38c8fa1..e7c751d367 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -78,6 +78,7 @@ Pandora_Module::Pandora_Module (string name) { this->warning_inverse = ""; this->quiet = ""; this->module_ff_interval = ""; + this->module_ff_type = ""; this->module_alert_template = ""; this->module_crontab = ""; } @@ -733,6 +734,13 @@ Pandora_Module::getXml () { module_xml += this->module_ff_interval; module_xml += "\n"; } + + /* Module FF type */ + if (this->module_ff_type != "") { + module_xml += "\t"; + module_xml += this->module_ff_type; + module_xml += "\n"; + } /* Module Alert template */ if (this->module_alert_template != "") { @@ -1028,6 +1036,16 @@ Pandora_Module::setModuleFFInterval (string value) { this->module_ff_interval = value; } +/** + * Set the module FF type for the module. + * + * @param value module FF type value to set. + */ +void +Pandora_Module::setModuleFFType (string value) { + this->module_ff_type = value; +} + /** * Set the module Alert template for the module. * diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h index 9fb29e1183..c766766950 100644 --- a/pandora_agents/win32/modules/pandora_module.h +++ b/pandora_agents/win32/modules/pandora_module.h @@ -176,6 +176,7 @@ namespace Pandora_Modules { string unit, custom_id, str_warning, str_critical; string module_group, warning_inverse, critical_inverse, quiet; string module_ff_interval, module_alert_template, module_crontab; + string module_ff_type; string critical_instructions, warning_instructions, unknown_instructions, tags; protected: @@ -277,6 +278,7 @@ namespace Pandora_Modules { void setWarningInverse (string value); void setQuiet (string value); void setModuleFFInterval (string value); + void setModuleFFType (string value); void setModuleAlertTemplate (string value); void setModuleCrontab (string value); diff --git a/pandora_agents/win32/modules/pandora_module_factory.cc b/pandora_agents/win32/modules/pandora_module_factory.cc index 658ff724fd..a4d9553c20 100644 --- a/pandora_agents/win32/modules/pandora_module_factory.cc +++ b/pandora_agents/win32/modules/pandora_module_factory.cc @@ -119,6 +119,7 @@ using namespace Pandora_Strutils; #define TOKEN_WARNING_INVERSE ("module_warning_inverse ") #define TOKEN_QUIET ("module_quiet ") #define TOKEN_MODULE_FF_INTERVAL ("module_ff_interval ") +#define TOKEN_MODULE_FF_TYPE ("module_ff_type ") #define TOKEN_MACRO ("module_macro") #define TOKEN_NATIVE_ENCODING ("module_native_encoding") #define TOKEN_ALERT_TEMPLATE ("module_alert_template") @@ -176,7 +177,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { string module_unit, module_group, module_custom_id, module_str_warning, module_str_critical; string module_critical_instructions, module_warning_instructions, module_unknown_instructions, module_tags; string module_critical_inverse, module_warning_inverse, module_quiet, module_ff_interval; - string module_native_encoding, module_alert_template; + string module_native_encoding, module_alert_template, module_ff_type; string macro; Pandora_Module *module; bool numeric; @@ -254,6 +255,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { module_warning_inverse = ""; module_quiet = ""; module_ff_interval = ""; + module_ff_type = ""; module_native_encoding = ""; module_alert_template = ""; module_user_session = ""; @@ -507,6 +509,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { if (module_ff_interval == "") { module_ff_interval = parseLine (line, TOKEN_MODULE_FF_INTERVAL); } + + if (module_ff_type == "") { + module_ff_type = parseLine (line, TOKEN_MODULE_FF_TYPE); + } if (module_alert_template == "") { module_alert_template = parseLine (line, TOKEN_ALERT_TEMPLATE); @@ -1087,6 +1093,13 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { } } + if (module_ff_type != "") { + pos_macro = module_ff_type.find(macro_name); + if (pos_macro != string::npos){ + module_ff_type.replace(pos_macro, macro_name.size(), macro_value); + } + } + if (module_alert_template != "") { pos_macro = module_alert_template.find(macro_name); if (pos_macro != string::npos){ @@ -1104,6 +1117,12 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { } } + /* Skip disabled modules */ + if (module_disabled == "1") { + pandoraLog ("Skipping disabled module \"%s\"", module_name.c_str ()); + return NULL; + } + /* Create module objects */ if (module_exec != "") { module = new Pandora_Module_Exec (module_name, @@ -1447,6 +1466,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { if (module_ff_interval != "") { module->setModuleFFInterval (module_ff_interval); } + + if (module_ff_type != "") { + module->setModuleFFType (module_ff_type); + } if (module_alert_template != "") { module->setModuleAlertTemplate (module_alert_template); diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 88a0ad00f3..5629c17eb2 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.732(Build 190319)") +#define PANDORA_VERSION ("7.0NG.735(Build 190612)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 759767d662..934b27fdd6 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.732(Build 190319))" + VALUE "ProductVersion", "(7.0NG.735(Build 190612))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index cc50ca91fa..1fa6b0606e 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.732-190319 +Version: 7.0NG.735-190612 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index b373a17148..c9422dc4c7 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.732-190319" +pandora_version="7.0NG.735-190612" package_pear=0 package_pandora=1 diff --git a/pandora_console/composer.json b/pandora_console/composer.json index acc6a3e352..208e2d3d14 100644 --- a/pandora_console/composer.json +++ b/pandora_console/composer.json @@ -10,5 +10,16 @@ "require": { "mpdf/mpdf": "^7.1", "swiftmailer/swiftmailer": "^6.0" + }, + "autoload": { + "psr-4": { + "Models\\": "include/rest-api/models", + "Enterprise\\Models\\": "enterprise/include/rest-api/models" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } } } diff --git a/pandora_console/extensions/agents_alerts.php b/pandora_console/extensions/agents_alerts.php index 46272504f6..54e0ec6b12 100755 --- a/pandora_console/extensions/agents_alerts.php +++ b/pandora_console/extensions/agents_alerts.php @@ -138,8 +138,15 @@ function mainAgentsAlerts() $onheader['combo_refr'] = $comborefr; } - // Header - ui_print_page_header(__('Agents/Alerts'), 'images/op_alerts.png', false, '', false, $updated_time); + // Header. + ui_print_page_header( + __('Agents/Alerts'), + 'images/op_alerts.png', + false, + 'agents_alerts_view', + false, + $updated_time + ); // Old style table, we need a lot of special formatting,don't use table function // Prepare old-style table @@ -291,7 +298,7 @@ function mainAgentsAlerts() $table2->data[2][0] = __('Threshold'); $table2->data[2][1] = html_print_input_text('module_action_threshold', '0', '', 5, 7, true); - $table2->data[2][1] .= ' '.__('seconds').ui_print_help_icon('action_threshold', true); + $table2->data[2][1] .= ' '.__('seconds'); $content2 = '
'; $content2 .= html_print_table($table2, true); @@ -378,7 +385,8 @@ function mainAgentsAlerts() 'alerts_agents' ); - echo ''; + echo '
'; + echo ''; echo "'; if ($hor_offset > 0) { @@ -421,9 +429,10 @@ function mainAgentsAlerts() continue; } - echo ''; + echo ''; } + echo ''; if (($hor_offset + $block) < $ntemplates) { $new_hor_offset = ($hor_offset + $block); echo "
".__('Agents').' / '.__('Alert templates').''.io_safe_output($tname).html_print_image('images/information_alerts.png', true, ['title' => io_safe_output($tname), 'style' => 'margin-left:5px' ]).''.io_safe_output($tname).'
@@ -455,7 +464,7 @@ function mainAgentsAlerts() $cellstyle = 'background:'.COL_ALERTFIRED.';'; } - echo ' '; + echo ' '; $uniqid = uniqid(); echo '
'; @@ -478,6 +487,23 @@ function mainAgentsAlerts() } echo '
'; + + ui_pagination( + $nagents, + false, + 0, + 0, + false, + 'offset', + true, + 'pagination-bottom', + '', + [ + 'count' => '', + 'offset' => 'offset_param', + ], + 'alerts_agents' + ); } } @@ -487,7 +513,7 @@ function mainAgentsAlerts() function print_alerts_summary_modal_window($id, $alerts) { $table->width = '98%'; - $table->class = 'databox'; + $table->class = 'info_table'; $table->data = []; $table->head[0] = __('Module'); diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 798f4e140e..b5860068d8 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -181,8 +181,15 @@ function mainAgentsModules() // Old style table, we need a lot of special formatting,don't use table function // Prepare old-style table if ($config['pure'] == 0) { - // Header - ui_print_page_header(__('Agents/Modules'), 'images/module_mc.png', false, '', false, $updated_time); + // Header. + ui_print_page_header( + __('Agents/Modules'), + 'images/module_mc.png', + false, + 'agents_module_view', + false, + $updated_time + ); echo ''; echo ''; echo "'; @@ -661,7 +668,7 @@ $ignored_params['refresh'] = ''; else { var agentes_id = $("#id_agents2").val(); - var id_agentes = $.get("full_agents_id"); + var id_agentes = getQueryParam("full_agents_id"); if (agentes_id === null && id_agentes !== null) { id_agentes = id_agentes.split(";") id_agentes.forEach(function(element) { @@ -799,7 +806,7 @@ $ignored_params['refresh'] = ''; $("#module").append (option); }); - var id_modules = $.get("full_modules_selected"); + var id_modules = getQueryParam("full_modules_selected"); if(id_modules !== null) { id_modules = id_modules.split(";"); id_modules.forEach(function(element) { @@ -812,20 +819,18 @@ $ignored_params['refresh'] = ''; ); } - (function($) { - $.get = function(key) { - key = key.replace(/[[]/, '['); - key = key.replace(/[]]/, ']'); - var pattern = "[?&]" + key + "=([^&#]*)"; - var regex = new RegExp(pattern); - var url = unescape(window.location.href); - var results = regex.exec(url); - if (results === null) { - return null; - } else { - return results[1]; - } - } - })(jQuery); + function getQueryParam (key) { + key = key.replace(/[[]/, '['); + key = key.replace(/[]]/, ']'); + var pattern = "[?&]" + key + "=([^&#]*)"; + var regex = new RegExp(pattern); + var url = unescape(window.location.href); + var results = regex.exec(url); + if (results === null) { + return null; + } else { + return results[1]; + } + } - \ No newline at end of file + diff --git a/pandora_console/extensions/db_status.php b/pandora_console/extensions/db_status.php index 435474dc53..d78ff90fc8 100755 --- a/pandora_console/extensions/db_status.php +++ b/pandora_console/extensions/db_status.php @@ -25,7 +25,7 @@ function extension_db_status() __('DB Schema check'), 'images/extensions.png', false, - '', + 'db_status_tab', true, '' ); @@ -215,7 +215,7 @@ function extension_db_check_tables_differences( $diff_tables = array_diff($tables_test, $tables_system); ui_print_result_message( - !empty($diff_tables), + empty($diff_tables), __('Success! %s DB contains all tables', get_product_name()), __( '%s DB could not retrieve all tables. The missing tables are (%s)', diff --git a/pandora_console/extensions/dbmanager.php b/pandora_console/extensions/dbmanager.php index 2aface6996..546ee463fa 100644 --- a/pandora_console/extensions/dbmanager.php +++ b/pandora_console/extensions/dbmanager.php @@ -148,7 +148,7 @@ function dbmgr_extension_main() echo "
"; $table = new stdClass(); $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->head = array_keys($result[0]); $table->data = $result; diff --git a/pandora_console/extensions/files_repo/files_repo_list.php b/pandora_console/extensions/files_repo/files_repo_list.php index 1d01cd1418..80de4563ae 100644 --- a/pandora_console/extensions/files_repo/files_repo_list.php +++ b/pandora_console/extensions/files_repo/files_repo_list.php @@ -45,11 +45,9 @@ if (!empty($files)) { $table = new stdClass(); $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->style = []; $table->style[1] = 'max-width: 200px;'; - $table->style[2] = 'text-align: center;'; - $table->style[3] = 'text-align: center;'; $table->style[4] = 'text-align: center;'; $table->head = []; $table->head[0] = __('Name'); @@ -81,6 +79,7 @@ if (!empty($files)) { // Last modification // Public URL $data[4] = ''; + $table->cellclass[][4] = 'action_buttons'; if (!empty($file['hash'])) { $public_url = ui_get_full_url(EXTENSIONS_DIR.'/files_repo/files_repo_get_file.php?file='.$file['hash']); $message = __('Copy to clipboard').': Ctrl+C -> Enter'; @@ -92,7 +91,7 @@ if (!empty($files)) { } $data[4] .= ""; - $data[4] .= html_print_image('images/download.png', true, ['title' => __('Download')]); + $data[4] .= html_print_image('images/download.png', true, ['title' => __('Download'), 'style' => 'padding:3px' ]); // Download image $data[4] .= ''; diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index 1a505538ed..9e750be932 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -192,7 +192,14 @@ function mainModuleGroups() $array_data[$value['id_grupo']][$value['id_mg']] = $value; } - ui_print_page_header(__('Combined table of agent group and module group'), 'images/module_group.png', false, '', false, ''); + ui_print_page_header( + __('Combined table of agent group and module group'), + 'images/module_group.png', + false, + 'module_groups_view', + false, + '' + ); echo "
".$fullscreen['text'].'
"; diff --git a/pandora_console/extensions/realtime_graphs.php b/pandora_console/extensions/realtime_graphs.php index 09d66abf0c..cea09fe4d5 100644 --- a/pandora_console/extensions/realtime_graphs.php +++ b/pandora_console/extensions/realtime_graphs.php @@ -29,7 +29,14 @@ function pandora_realtime_graphs() $hide_header = get_parameter('hide_header', 0); if (!$hide_header) { - ui_print_page_header(__('Realtime graphs'), 'images/extensions.png', false, '', false, $onheader); + ui_print_page_header( + __('Realtime graphs'), + 'images/extensions.png', + false, + 'real_time_view', + false, + $onheader + ); } $chart[time()]['graph'] = '0'; diff --git a/pandora_console/extensions/resource_registration.php b/pandora_console/extensions/resource_registration.php index 92d106d153..c43e2a97f2 100755 --- a/pandora_console/extensions/resource_registration.php +++ b/pandora_console/extensions/resource_registration.php @@ -998,20 +998,23 @@ function process_upload_xml($xml) { $hook_enterprise = enterprise_include('extensions/resource_registration/functions.php'); - // Extract component + // Extract component. process_upload_xml_component($xml); $group_filter = get_parameter('group'); - // Extract visual map + // Extract visual map. process_upload_xml_visualmap($xml, $group_filter); - // Extract policies + // Extract policies. if ($hook_enterprise === true) { - process_upload_xml_policy($xml, $group_filter); + $centralized_management = !is_central_policies_on_node(); + if ($centralized_management) { + process_upload_xml_policy($xml, $group_filter); + } } - // Extract reports + // Extract reports. process_upload_xml_report($xml, $group_filter); } @@ -1038,6 +1041,11 @@ function resource_registration_extension_main() return; } + $centralized_management = !is_central_policies_on_node(); + if (!$centralized_management) { + ui_print_warning_message(__('This node is configured with centralized mode. Go to metaconsole to create a policy.')); + } + echo '
'; echo __('This extension makes registering resource templates easier.').' '.__('Here you can upload a resource template in .ptr format.').' '.__('Please refer to our documentation for more information on how to obtain and use %s resources.', get_product_name()).' '.'

'.__("You can get more resurces in our Public Resource Library"); echo '
'; diff --git a/pandora_console/extensions/users_connected.php b/pandora_console/extensions/users_connected.php index 562d757a20..e26b0dab1e 100644 --- a/pandora_console/extensions/users_connected.php +++ b/pandora_console/extensions/users_connected.php @@ -66,10 +66,10 @@ function users_extension_main_god($god=true) $rows = []; echo "
".__('No other users connected').'
'; } else { - $table->cellpadding = 4; - $table->cellspacing = 4; + $table->cellpadding = 0; + $table->cellspacing = 0; $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->size = []; $table->data = []; $table->head = []; diff --git a/pandora_console/extras/delete_files/.gitignore b/pandora_console/extras/delete_files/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt new file mode 100644 index 0000000000..82ce1527aa --- /dev/null +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -0,0 +1,3 @@ +/general/login_identification_wizard.php +/general/login_required.php +/godmode/update_manager/update_manager.messages.php \ No newline at end of file diff --git a/pandora_console/extras/mr/26.sql b/pandora_console/extras/mr/26.sql index f9c904a0a3..591edd6499 100644 --- a/pandora_console/extras/mr/26.sql +++ b/pandora_console/extras/mr/26.sql @@ -1,8 +1,24 @@ START TRANSACTION; --- ---------------------------------------------------------------------- --- Add column in table `tagent_custom_fields` --- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tnetwork_matrix` ( + `id` int(10) unsigned NOT NULL auto_increment, + `source` varchar(60) default '', + `destination` varchar(60) default '', + `utimestamp` bigint(20) default 0, + `bytes` int(18) unsigned default 0, + `pkts` int(18) unsigned default 0, + PRIMARY KEY (`id`), + UNIQUE (`source`, `destination`, `utimestamp`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8 ; + +ALTER TABLE `treport_content` ADD COLUMN `show_extended_events` tinyint(1) default '0'; + +UPDATE `treport_content` SET type="netflow_summary" WHERE type="netflow_pie" OR type="netflow_statistics"; + +UPDATE `tnetflow_filter` SET aggregate="dstip" WHERE aggregate NOT IN ("dstip", "srcip", "dstport", "srcport"); + ALTER TABLE tagent_custom_fields ADD COLUMN `combo_values` VARCHAR(255) DEFAULT ''; +ALTER TABLE `trecon_task` ADD COLUMN `summary` text; + COMMIT; diff --git a/pandora_console/extras/mr/27.sql b/pandora_console/extras/mr/27.sql new file mode 100644 index 0000000000..697be21a93 --- /dev/null +++ b/pandora_console/extras/mr/27.sql @@ -0,0 +1,54 @@ +START TRANSACTION; + +ALTER TABLE `tnetflow_filter` DROP COLUMN `output`; + +ALTER TABLE `tagente_modulo` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; +ALTER TABLE `tnetwork_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; +ALTER TABLE `tlocal_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; +ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; + +ALTER TABLE `tagente_estado` ADD COLUMN `ff_normal` int(4) unsigned default '0'; +ALTER TABLE `tagente_estado` ADD COLUMN `ff_warning` int(4) unsigned default '0'; +ALTER TABLE `tagente_estado` ADD COLUMN `ff_critical` int(4) unsigned default '0'; + +UPDATE tuser_task SET parameters = 'a:5:{i:0;a:6:{s:11:\"description\";s:28:\"Report pending to be created\";s:5:\"table\";s:7:\"treport\";s:8:\"field_id\";s:9:\"id_report\";s:10:\"field_name\";s:4:\"name\";s:4:\"type\";s:3:\"int\";s:9:\"acl_group\";s:8:\"id_group\";}i:1;a:2:{s:11:\"description\";s:46:\"Send to email addresses (separated by a comma)\";s:4:\"type\";s:4:\"text\";}i:2;a:2:{s:11:\"description\";s:7:\"Subject\";s:8:\"optional\";i:1;}i:3;a:3:{s:11:\"description\";s:7:\"Message\";s:4:\"type\";s:4:\"text\";s:8:\"optional\";i:1;}i:4;a:2:{s:11:\"description\";s:11:\"Report Type\";s:4:\"type\";s:11:\"report_type\";}}' where function_name = "cron_task_generate_report"; + +ALTER TABLE `treport_content` ADD COLUMN `total_time` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_in_unknown_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_of_not_initialized_module` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_of_downtime` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `total_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `checks_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `checks_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `unknown_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `agent_max_value` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `agent_min_value` TINYINT(1) DEFAULT '1'; + +ALTER TABLE `treport_content_template` ADD COLUMN `total_time` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_in_unknown_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_of_not_initialized_module` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_of_downtime` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `total_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `checks_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `checks_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `unknown_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `agent_max_value` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `agent_min_value` TINYINT(1) DEFAULT '1'; + +ALTER TABLE `trecon_script` ADD COLUMN `type` int NOT NULL default 0; +ALTER TABLE `trecon_task` ADD COLUMN `type` int NOT NULL default 0; + +UPDATE `trecon_script` SET `type` = 1 WHERE `name`="Discovery.Application.VMware"; +UPDATE `trecon_script` SET `type` = 2 WHERE `name`="Discovery.Cloud"; +UPDATE `trecon_script` SET `type` = 3 WHERE `name` LIKE "IPAM%Recon"; +UPDATE `trecon_script` SET `type` = 4 WHERE `name` LIKE "IPMI%Recon"; + +UPDATE `trecon_task` SET `type`=3 WHERE `description`="Discovery.Application.VMware"; +UPDATE `trecon_task` SET `type`=2 WHERE `description`="Discovery.Cloud"; +UPDATE `trecon_task` SET `type`=7 WHERE `description`="Discovery.Cloud.RDS"; + +COMMIT; diff --git a/pandora_console/extras/mr/28.sql b/pandora_console/extras/mr/28.sql new file mode 100644 index 0000000000..bab07bead8 --- /dev/null +++ b/pandora_console/extras/mr/28.sql @@ -0,0 +1,45 @@ +START TRANSACTION; + +ALTER TABLE `treport_content` ADD COLUMN `current_month` TINYINT(1) DEFAULT '1'; + +ALTER TABLE `treport_content_template` ADD COLUMN `current_month` TINYINT(1) DEFAULT '1'; + +ALTER TABLE `talert_commands` ADD COLUMN `fields_hidden` text; + +ALTER TABLE `talert_templates` MODIFY COLUMN `type` ENUM('regex','max_min','max','min','equal','not_equal','warning','critical','onchange','unknown','always','not_normal'); + +DELETE FROM `tevent_response` WHERE `name` LIKE 'Create Integria IMS incident from event'; +INSERT INTO `tnews` (`id_news`, `author`, `subject`, `text`, `timestamp`) VALUES (NULL,'admin','Welcome to Pandora FMS Console', '&lt;p style="text-align: center; font-size: 13px;"&gt;Hello, congratulations, if you've arrived here you already have an operational monitoring console. Remember that our forums and online documentation are available 24x7 to get you out of any trouble. You can replace this message with a personalized one at Admin tools -&amp;gt; Site news.&lt;/p&gt; ',NOW()); + + +INSERT INTO `tnotification_source_user` (`id_source`, `id_user`, `enabled`, `also_mail`) VALUES ((SELECT `id` FROM `tnotification_source` WHERE `description`="Official communication"), "admin", 1, 0); +UPDATE `tnotification_source` SET `enabled`=1 WHERE `description` = 'System status' OR `description` = 'Official communication'; +UPDATE `tnotification_source` SET `icon`="icono_logo_pandora.png" WHERE `description` = 'Official communication'; + +-- --------------------------------------------------------------------- +-- Table `tvisual_console_items_cache` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tvisual_console_elements_cache` ( + `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `vc_id` INTEGER UNSIGNED NOT NULL, + `vc_item_id` INTEGER UNSIGNED NOT NULL, + `user_id` VARCHAR(60) DEFAULT NULL, + `data` TEXT NOT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `expiration` INTEGER UNSIGNED NOT NULL COMMENT 'Seconds to expire', + PRIMARY KEY(`id`), + FOREIGN KEY(`vc_id`) REFERENCES `tlayout`(`id`) + ON DELETE CASCADE, + FOREIGN KEY(`vc_item_id`) REFERENCES `tlayout_data`(`id`) + ON DELETE CASCADE, + FOREIGN KEY (`user_id`) REFERENCES `tusuario`(`id_user`) + ON DELETE CASCADE ON UPDATE CASCADE +) engine=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE `tlayout_data` ADD COLUMN `cache_expiration` INTEGER UNSIGNED NOT NULL DEFAULT 0; + +ALTER TABLE `tusuario` ADD COLUMN `ehorus_user_level_user` VARCHAR(60); +ALTER TABLE `tusuario` ADD COLUMN `ehorus_user_level_pass` VARCHAR(45); +ALTER TABLE `tusuario` ADD COLUMN `ehorus_user_level_enabled` TINYINT(1) DEFAULT '1'; + +COMMIT; diff --git a/pandora_console/extras/mr/29.sql b/pandora_console/extras/mr/29.sql new file mode 100644 index 0000000000..032dd407b1 --- /dev/null +++ b/pandora_console/extras/mr/29.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +DELETE FROM `ttipo_modulo` WHERE `nombre` LIKE 'log4x'; + + +COMMIT; diff --git a/pandora_console/extras/pandora_diag.php b/pandora_console/extras/pandora_diag.php index d6cd017087..f3b11177d1 100644 --- a/pandora_console/extras/pandora_diag.php +++ b/pandora_console/extras/pandora_diag.php @@ -122,7 +122,7 @@ function execution_time() if ($times[0]['datos'] > ($times[1]['datos'] * 1.2)) { return "Warning Status   The execution time could be degrading. For a more extensive information of this data consult the Execution Time graph"; } else { - return "Normal Status   The execution time is correct. For a more extensive information of this data consult the Execution Time graph"; + return "Normal Status   The execution time is correct. For more information about this data, check the Execution Time graph"; } } @@ -140,7 +140,8 @@ function get_status_logs($path) { $status_server_log = ''; $size_server_log = number_format(get_logs_size($path)); - if ($size_server_log <= 1048576) { + $size_server_log = (0 + str_replace(',', '', $size_server_log)); + if ($size_server_log <= 10485760) { $status_server_log = "Normal Status   You have less than 10 MB of logs"; } else { $status_server_log = "Warning Status   You have more than 10 MB of logs"; @@ -157,9 +158,9 @@ function percentage_modules_per_agent() $total_modules = db_get_value_sql('SELECT count(*) FROM tagente_modulo'); $average_modules_per_agent = ($total_modules / $total_agents); if ($average_modules_per_agent <= 40) { - $status_average_modules = "Normal Status   The average of modules per agent is less than 40 percent"; + $status_average_modules = "Normal Status   The average of modules per agent is less than 40"; } else { - $status_average_modules = "Warning Status  The average of modules per agent is more than 40 percent. You can have performance problems"; + $status_average_modules = "Warning Status  The average of modules per agent is more than 40. You can have performance problems"; } return $status_average_modules; @@ -173,9 +174,9 @@ function license_capacity() $status_license_capacity = ''; $current_count = db_get_value_sql('SELECT count(*) FROM tagente'); if ($current_count > ($license_limit * 90 / 100)) { - $status_license_capacity = "Warning Status   The license capacity is more than 90 percent"; + $status_license_capacity = "Warning Status   License capacity exceeds 90 percent"; } else { - $status_license_capacity = "Normal Status   The license capacity is less than 90 percent"; + $status_license_capacity = "Normal Status   License capacity is less than 90 percent"; } return $status_license_capacity; @@ -202,9 +203,9 @@ function interval_average_of_network_modules() $average_time = ((int) $total_module_interval_time / $total_network_modules); if ($average_time < 180) { - $status_average_modules = "Warning Status   The system has a lot of load and a very fine configuration is required"; + $status_average_modules = "Warning Status   The system is overloaded (average time $average_time) and a very fine configuration is required"; } else { - $status_average_modules = "Normal Status   The system has an acceptable charge"; + $status_average_modules = "Normal Status   The system is not overloaded (average time $average_time) "; } if ($average_time == 0) { @@ -221,9 +222,9 @@ $attachment_total_files = count(glob($config['homedir'].'/attachment/{*.*}', GLO function files_attachment_folder($total_files) { if ($total_files <= 700) { - $status_total_files = "Normal Status   The attachment folder has less than 700 files."; + $status_total_files = "Normal Status   The attached folder contains less than 700 files."; } else { - $status_total_files = "Warning Status   The attachment folder has more than 700 files."; + $status_total_files = "Warning Status   The attached folder contains more than 700 files."; } return $status_total_files; @@ -236,9 +237,9 @@ $tagente_datos_size = db_get_value_sql('SELECT COUNT(*) FROM tagente_datos'); function status_tagente_datos($tagente_datos_size) { if ($tagente_datos_size <= 3000000) { - $tagente_datos_size = "Normal Status   The tagente_datos table has an acceptable amount of data."; + $tagente_datos_size = "Normal Status   The tagente_datos table contains an acceptable amount of data."; } else { - $tagente_datos_size = "Warning Status   The tagente_datos table has too much data. A historical database is recommended."; + $tagente_datos_size = "Warning Status   The tagente_datos table contains too much data. A historical database is recommended."; } return $tagente_datos_size; @@ -274,6 +275,7 @@ if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { } $path_server_logs = '/log/pandora/pandora_server.log'; +$path_err_logs = '/log/pandora/pandora_server.error'; $path_console_logs = '/www/html/pandora_console/pandora_console.log'; $innodb_log_file_size_min_rec_value = '64M'; $innodb_log_buffer_size_min_rec_value = '16M'; @@ -294,16 +296,16 @@ $key_buffer_size_min_rec_value = 256; $read_buffer_size_min_rec_value = 32; $read_rnd_buffer_size_min_rec_value = 32; $query_cache_min_res_unit_min_rec_value = 2; -$innodb_file_per_table_min_rec_value = 0; +$innodb_file_per_table_min_rec_value = 1; function status_fragmentation_tables($tables_fragmentation_max_rec_value, $tables_fragmentation) { $status_tables_frag = ''; if ($tables_fragmentation > $tables_fragmentation_max_rec_value) { - $status_tables_frag = "Warning Status   The fragmentation tables is higher than recommended. You should defragment them."; + $status_tables_frag = "Warning Status   Table fragmentation is higher than recommended. They should be defragmented."; } else { - $status_tables_frag = "Normal Status   The fragmentation tables is correct."; + $status_tables_frag = "Normal Status   Table fragmentation is correct."; } return $status_tables_frag; @@ -319,9 +321,9 @@ if ($console_mode == 1) { echo "\nPandora FMS PHP diagnostic tool v3.2 (c) Artica ST 2009-2010 \n"; if ($argc == 1 || in_array($argv[1], ['--help', '-help', '-h', '-?'])) { - echo "\nThis command line script gives information about Pandora FMS database. -This program only can be executed from console, and need a parameter, the -full path to Pandora FMS 'config.php' file. + echo "\nThis command line script contains information about Pandora FMS database. + This program can only be executed from the console, and it needs a parameter, the + full path to Pandora FMS 'config.php' file. Usage: php pandora_diag.php path_to_pandora_console @@ -344,15 +346,21 @@ full path to Pandora FMS 'config.php' file. include '../include/config.php'; } - // Not from console, this is a web session - if ((!isset($config['id_user'])) or (!check_acl($config['id_user'], 0, 'PM'))) { + // Not from console, this is a web session. + if ((!isset($config['id_user'])) || (!check_acl($config['id_user'], 0, 'PM'))) { echo "

You don't have privileges to use diagnostic tool

"; echo '

Please login with an administrator account before try to use this tool

'; exit; } - // Header - ui_print_page_header(__('Pandora FMS Diagnostic tool'), '', false, '', true); + // Header. + ui_print_page_header( + __('Pandora FMS Diagnostic tool'), + '', + false, + 'diagnostic_tool_tab', + true + ); echo "
"; echo "'; @@ -677,7 +685,7 @@ render_info_data( $read_rnd_buffer_size = (db_get_value_sql('SELECT @@read_rnd_buffer_size') / 1024); $query_cache_min_res_unit = (db_get_value_sql('SELECT @@query_cache_min_res_unit') / 1024); $innodb_file_per_table = db_get_value_sql('SELECT @@innodb_file_per_table'); - echo "'; + echo "'; render_row(status_values($innodb_log_file_size_min_rec_value, $innodb_log_file_size), 'InnoDB log file size ', 'InnoDB log file size '); render_row(status_values($innodb_log_buffer_size_min_rec_value, $innodb_log_buffer_size), 'InnoDB log buffer size ', 'InnoDB log buffer size '); @@ -704,12 +712,14 @@ render_info_data( render_row($tables_fragmentation_max_rec_value.'%', 'Tables fragmentation (maximum recommended value)'); render_row(number_format($tables_fragmentation, 2).'%', 'Tables fragmentation (current value)'); - render_row(status_fragmentation_tables($tables_fragmentation_max_rec_value, $tables_fragmentation), 'Status fragmentation tables'); + render_row(status_fragmentation_tables($tables_fragmentation_max_rec_value, $tables_fragmentation), 'Table fragmentation status'); echo "'; render_row(number_format((get_logs_size($path_server_logs) / 1048576), 3).'M', 'Size server logs (current value)'); render_row(get_status_logs($path_server_logs), 'Status server logs'); + render_row(number_format((get_logs_size($path_err_logs) / 1048576), 3).'M', 'Size error logs (current value)'); + render_row(get_status_logs($path_err_logs), 'Status error logs'); render_row(number_format((get_logs_size($path_console_logs) / 1048576), 3).'M', 'Size console logs (current value)'); render_row(get_status_logs($path_console_logs), 'Status console logs'); @@ -731,14 +741,14 @@ render_info_data( echo "'; - render_row($attachment_total_files, 'Total files in the attachment folder'); + render_row($attachment_total_files, 'Total files in the attached folder'); render_row(files_attachment_folder($attachment_total_files), 'Status of the attachment folder'); echo "'; - render_row($tagente_datos_size, 'Total data in the tagente_datos table'); - render_row(status_tagente_datos($tagente_datos_size), 'Status of the tagente_datos table'); - render_row(execution_time(), 'Degradation of the execution time when executing a count'); + render_row($tagente_datos_size, 'Total data in tagente_datos table'); + render_row(status_tagente_datos($tagente_datos_size), 'Tangente_datos table status'); + render_row(execution_time(), 'Execution time degradation when executing a count'); echo "'; @@ -781,6 +791,6 @@ render_info_data( echo "
"; echo ''.__( - '(*) Please check your Pandora Server setup and be sure that database maintenance daemon is running. It\' very important to -keep up-to-date database to get the best performance and results in Pandora' + '(*) Please check your Pandora Server setup and make sure that the database maintenance daemon is running. It\' is very important to + keep the database up-to-date to get the best performance and results in Pandora' ).'


'; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index e7cedb62f5..2c9ff7e7de 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -58,6 +58,7 @@ CREATE TABLE IF NOT EXISTS `tlocal_component` ( ALTER TABLE `tlocal_component` ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0'; ALTER TABLE `tlocal_component` ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0'; +ALTER TABLE `tlocal_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; -- ----------------------------------------------------- -- Table `tpolicy_modules` @@ -136,6 +137,7 @@ CREATE TABLE IF NOT EXISTS `tpolicy_modules` ( ALTER TABLE `tpolicy_modules` ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0'; ALTER TABLE `tpolicy_modules` ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0'; +ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; -- --------------------------------------------------------------------- -- Table `tpolicies` @@ -759,11 +761,41 @@ CREATE TABLE IF NOT EXISTS `treport_content_template` ( PRIMARY KEY(`id_rc`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------------------------------------------------- +-- Table `tnews` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tnews` ( + `id_news` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `author` varchar(255) NOT NULL DEFAULT '', + `subject` varchar(255) NOT NULL DEFAULT '', + `text` TEXT NOT NULL, + `timestamp` DATETIME NOT NULL DEFAULT 0, + `id_group` int(10) NOT NULL default 0, + `modal` tinyint(1) DEFAULT 0, + `expire` tinyint(1) DEFAULT 0, + `expire_timestamp` DATETIME NOT NULL DEFAULT 0, + PRIMARY KEY(`id_news`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; + + ALTER TABLE treport_content_template ADD COLUMN `historical_db` tinyint(1) NOT NULL DEFAULT '0'; ALTER TABLE treport_content_template ADD COLUMN `lapse_calc` tinyint(1) default '0'; ALTER TABLE treport_content_template ADD COLUMN `lapse` int(11) default '300'; ALTER TABLE treport_content_template ADD COLUMN `visual_format` tinyint(1) default '0'; ALTER TABLE treport_content_template ADD COLUMN `hide_no_data` tinyint(1) default '0'; +ALTER TABLE `treport_content_template` ADD COLUMN `total_time` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_in_unknown_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_of_not_initialized_module` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `time_of_downtime` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `total_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `checks_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `checks_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `unknown_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `agent_max_value` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `agent_min_value` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content_template` ADD COLUMN `current_month` TINYINT(1) DEFAULT '1'; -- ----------------------------------------------------- -- Table `treport_content_sla_com_temp` (treport_content_sla_combined_template) @@ -1150,6 +1182,9 @@ ALTER TABLE tagente_estado MODIFY `status_changes` tinyint(4) unsigned default 0 ALTER TABLE tagente_estado CHANGE `last_known_status` `known_status` tinyint(4) default 0; ALTER TABLE tagente_estado ADD COLUMN `last_known_status` tinyint(4) default 0; ALTER TABLE tagente_estado ADD COLUMN last_unknown_update bigint(20) NOT NULL default 0; +ALTER TABLE `tagente_estado` ADD COLUMN `ff_normal` int(4) unsigned default '0'; +ALTER TABLE `tagente_estado` ADD COLUMN `ff_warning` int(4) unsigned default '0'; +ALTER TABLE `tagente_estado` ADD COLUMN `ff_critical` int(4) unsigned default '0'; -- --------------------------------------------------------------------- -- Table `talert_actions` @@ -1180,6 +1215,7 @@ ALTER TABLE talert_actions ADD COLUMN `field15_recovery` TEXT NOT NULL DEFAULT " UPDATE `talert_commands` SET `fields_descriptions` = '[\"Integria IMS API path\",\"Integria IMS API pass\",\"Integria IMS user\",\"Integria IMS user pass\",\"Ticket title\",\"Ticket group ID\",\"Ticket priority\",\"Email copy\",\"Ticket owner\",\"Ticket description\"]', `fields_values` = '[\"\",\"\",\"\",\"\",\"\",\"\",\"10,Maintenance;0,Informative;1,Low;2,Medium;3,Serious;4,Very Serious\",\"\",\"\",\"\"]' WHERE `id` = 11 AND `name` = 'Integria IMS Ticket'; UPDATE `talert_commands` SET `description` = 'This alert send an email using internal Pandora FMS Server SMTP capabilities (defined in each server, using: _field1_ as destination email address, and _field2_ as subject for message. _field3_ as text of message. _field4_ as content type (text/plain or html/text).', `fields_descriptions` = '[\"Destination address\",\"Subject\",\"Text\",\"Content Type\",\"\",\"\",\"\",\"\",\"\",\"\"]', `fields_values` = '[\"\",\"\",\"_html_editor_\",\"_content_type_\",\"\",\"\",\"\",\"\",\"\",\"\"]' WHERE id=1; ALTER TABLE `talert_commands` ADD COLUMN `id_group` mediumint(8) unsigned NULL default 0; +ALTER TABLE `talert_commands` ADD COLUMN `fields_hidden` text; UPDATE `talert_actions` SET `field4` = 'text/html', `field4_recovery` = 'text/html' WHERE id = 1; @@ -1199,13 +1235,13 @@ ALTER TABLE titem MODIFY `source_data` int(10) unsigned; INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30'); -INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 26); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 28); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_docs_logo', 'default_docs.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_support_logo', 'default_support.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'); UPDATE tconfig SET value = 'https://licensing.artica.es/pandoraupdate7/server.php' WHERE token='url_update_manager'; DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise'; -INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '733'); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '735'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,graph,warn,data,timestamp'); -- --------------------------------------------------------------------- @@ -1252,6 +1288,11 @@ alter table tusuario add autorefresh_white_list text not null default ''; ALTER TABLE tusuario ADD COLUMN `time_autorefresh` int(5) unsigned NOT NULL default '30'; ALTER TABLE `tusuario` DROP COLUMN `flash_chart`; ALTER TABLE `tusuario` ADD COLUMN `default_custom_view` int(10) unsigned NULL default '0'; +ALTER TABLE `tusuario` ADD COLUMN `ehorus_user_level_user` VARCHAR(60); +ALTER TABLE `tusuario` ADD COLUMN `ehorus_user_level_pass` VARCHAR(45); +ALTER TABLE `tusuario` ADD COLUMN `ehorus_user_level_enabled` TINYINT(1); + + -- --------------------------------------------------------------------- -- Table `tagente_modulo` @@ -1260,6 +1301,10 @@ ALTER TABLE tagente_modulo ADD COLUMN `dynamic_next` bigint(20) NOT NULL default ALTER TABLE tagente_modulo ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0'; ALTER TABLE tagente_modulo ADD COLUMN `parent_module_id` int(10) unsigned NOT NULL default 0; ALTER TABLE `tagente_modulo` ADD COLUMN `cps` int NOT NULL default 0; +ALTER TABLE `tagente_modulo` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; +ALTER TABLE `tagente_modulo` ADD COLUMN `ff_normal` int(4) unsigned default '0'; +ALTER TABLE `tagente_modulo` ADD COLUMN `ff_warning` int(4) unsigned default '0'; +ALTER TABLE `tagente_modulo` ADD COLUMN `ff_critical` int(4) unsigned default '0'; -- --------------------------------------------------------------------- -- Table `tagente_datos` @@ -1279,6 +1324,7 @@ ALTER TABLE tnetwork_component ADD COLUMN `dynamic_max` int(4) default '0'; ALTER TABLE tnetwork_component ADD COLUMN `dynamic_min` int(4) default '0'; ALTER TABLE tnetwork_component ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0'; ALTER TABLE tnetwork_component ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0'; +ALTER TABLE `tnetwork_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0'; -- --------------------------------------------------------------------- -- Table `tagente` @@ -1329,6 +1375,7 @@ ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_status_type` ENUM ('default ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0; ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_status_as_service_critical` FLOAT(20, 3) NOT NULL default 0; ALTER TABLE `tlayout_data` ADD COLUMN `linked_layout_node_id` INT(10) NOT NULL default 0; +ALTER TABLE `tlayout_data` ADD COLUMN `cache_expiration` INTEGER UNSIGNED NOT NULL DEFAULT 0; -- --------------------------------------------------------------------- -- Table `tagent_custom_fields` @@ -1355,6 +1402,7 @@ ALTER TABLE tgraph ADD COLUMN `fullscale` tinyint(1) UNSIGNED NOT NULL default ' -- Table `tnetflow_filter` -- --------------------------------------------------------------------- ALTER TABLE tnetflow_filter ADD COLUMN `router_ip` TEXT NOT NULL DEFAULT ""; +UPDATE `tnetflow_filter` SET aggregate="dstip" WHERE aggregate NOT IN ("dstip", "srcip", "dstport", "srcport"); -- --------------------------------------------------------------------- -- Table `treport_custom_sql` @@ -1369,13 +1417,27 @@ UPDATE treport_custom_sql SET `sql` = 'select t1.alias as agent_n -- ---------------------------------------------------------------------- -- Table `treport_content` -- --------------------------------------------------------------------- - ALTER TABLE treport_content ADD COLUMN `historical_db` tinyint(1) NOT NULL DEFAULT '0'; ALTER TABLE treport_content ADD COLUMN `lapse_calc` tinyint(1) default '0'; ALTER TABLE treport_content ADD COLUMN `lapse` int(11) default '300'; ALTER TABLE treport_content ADD COLUMN `visual_format` tinyint(1) default '0'; ALTER TABLE treport_content ADD COLUMN `hide_no_data` tinyint(1) default '0'; ALTER TABLE treport_content ADD COLUMN `recursion` tinyint(1) default NULL; +ALTER TABLE treport_content ADD COLUMN `show_extended_events` tinyint(1) default '0'; +UPDATE `treport_content` SET type="netflow_summary" WHERE type="netflow_pie" OR type="netflow_statistics"; +ALTER TABLE `treport_content` ADD COLUMN `total_time` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_in_unknown_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_of_not_initialized_module` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `time_of_downtime` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `total_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `checks_failed` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `checks_in_ok_status` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `unknown_checks` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `agent_max_value` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `agent_min_value` TINYINT(1) DEFAULT '1'; +ALTER TABLE `treport_content` ADD COLUMN `current_month` TINYINT(1) DEFAULT '1'; -- --------------------------------------------------------------------- -- Table `tmodule_relationship` @@ -1410,6 +1472,7 @@ ALTER TABLE trecon_task ADD `vlan_enabled` int(2) unsigned default '0'; ALTER TABLE trecon_task ADD `wmi_enabled` tinyint(1) unsigned DEFAULT '0'; ALTER TABLE trecon_task ADD `auth_strings` text; ALTER TABLE trecon_task ADD `autoconfiguration_enabled` tinyint(1) unsigned default '0'; +ALTER TABLE trecon_task ADD `summary` text; -- --------------------------------------------------------------------- -- Table `twidget` AND Table `twidget_dashboard` @@ -1912,6 +1975,47 @@ CREATE TABLE `tgis_map_layer_groups` ( CONSTRAINT `tgis_map_layer_groups_ibfk_3` FOREIGN KEY (`agent_id`) REFERENCES `tagente` (`id_agente`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tnetwork_matrix` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tnetwork_matrix` ( + `id` int(10) unsigned NOT NULL auto_increment, + `source` varchar(60) default '', + `destination` varchar(60) default '', + `utimestamp` bigint(20) default 0, + `bytes` int(18) unsigned default 0, + `pkts` int(18) unsigned default 0, + PRIMARY KEY (`id`), + UNIQUE (`source`, `destination`, `utimestamp`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8 ; + +-- --------------------------------------------------------------------- +-- Table `user_task` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tuser_task` ( + `id` int(20) unsigned NOT NULL auto_increment, + `function_name` varchar(80) NOT NULL default '', + `parameters` text NOT NULL default '', + `name` varchar(60) NOT NULL default '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `user_task_scheduled` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tuser_task_scheduled` ( + `id` int(20) unsigned NOT NULL auto_increment, + `id_usuario` varchar(60) NOT NULL default '0', + `id_user_task` int(20) unsigned NOT NULL default '0', + `args` TEXT NOT NULL, + `scheduled` enum('no','hourly','daily','weekly','monthly','yearly','custom') default 'no', + `last_run` int(20) unsigned default '0', + `custom_data` int(10) NULL default '0', + `flag_delete` tinyint(1) UNSIGNED NOT NULL default 0, + `id_grupo` int(10) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- ----------------------------------------------------- -- Table `tnotification_source` -- ----------------------------------------------------- @@ -1934,7 +2038,7 @@ INSERT INTO `tnotification_source`(`description`, `icon`, `max_postpone_time`, ` ("Message", "icono_info_mr.png", 86400, 1, 1, 0), ("Pending task", "icono_info_mr.png", 86400, 1, 1, 0), ("Advertisement", "icono_info_mr.png", 86400, 1, 1, 0), - ("Official communication", "icono_info_mr.png", 86400, 1, 1, 0), + ("Official communication", "icono_logo_pandora.png", 86400, 1, 1, 0), ("Sugerence", "icono_info_mr.png", 86400, 1, 1, 0); -- ----------------------------------------------------- @@ -2031,6 +2135,9 @@ INSERT INTO `talert_commands` (`name`, `command`, `description`, `internal`, `fi INSERT INTO `tnotification_source_user` (`id_source`, `id_user`, `enabled`, `also_mail`) VALUES ((SELECT `id` FROM `tnotification_source` WHERE `description`="System status"), "admin", 1, 0); INSERT INTO `tnotification_source_group` SELECT `id`,0 FROM `tnotification_source` WHERE `description`="Message"; INSERT INTO `tnotification_user` (`id_mensaje`, `id_user`) SELECT `id_mensaje`, `id_usuario_destino` FROM `tmensajes` WHERE `id_usuario_destino` != ''; +INSERT INTO `tnotification_source_user` (`id_source`, `id_user`, `enabled`, `also_mail`) VALUES ((SELECT `id` FROM `tnotification_source` WHERE `description`="Official communication"), "admin", 1, 0); +UPDATE `tnotification_source` SET `enabled`=1 WHERE `description` = 'System status' OR `description` = 'Official communication'; + -- ---------------------------------------------------------------------- -- Add custom internal recon scripts -- ---------------------------------------------------------------------- @@ -2040,3 +2147,48 @@ INSERT INTO `trecon_script` (`name`,`description`,`script`,`macros`) VALUES ('Di -- Add column in table `tagent_custom_fields` -- ---------------------------------------------------------------------- ALTER TABLE tagent_custom_fields ADD COLUMN `combo_values` VARCHAR(255) DEFAULT ''; + +-- ---------------------------------------------------------------------- +-- Add column in table `tnetflow_filter` +-- ---------------------------------------------------------------------- +ALTER TABLE `tnetflow_filter` DROP COLUMN `output`; + + +-- ---------------------------------------------------------------------- +-- Update table `tuser_task` +-- ---------------------------------------------------------------------- +UPDATE tuser_task set parameters = 'a:5:{i:0;a:6:{s:11:\"description\";s:28:\"Report pending to be created\";s:5:\"table\";s:7:\"treport\";s:8:\"field_id\";s:9:\"id_report\";s:10:\"field_name\";s:4:\"name\";s:4:\"type\";s:3:\"int\";s:9:\"acl_group\";s:8:\"id_group\";}i:1;a:2:{s:11:\"description\";s:46:\"Send to email addresses (separated by a comma)\";s:4:\"type\";s:4:\"text\";}i:2;a:2:{s:11:\"description\";s:7:\"Subject\";s:8:\"optional\";i:1;}i:3;a:3:{s:11:\"description\";s:7:\"Message\";s:4:\"type\";s:4:\"text\";s:8:\"optional\";i:1;}i:4;a:2:{s:11:\"description\";s:11:\"Report Type\";s:4:\"type\";s:11:\"report_type\";}}' where function_name = "cron_task_generate_report"; + +-- ---------------------------------------------------------------------- +-- ADD message in table 'tnews' +-- ---------------------------------------------------------------------- + +INSERT INTO `tnews` (`id_news`, `author`, `subject`, `text`, `timestamp`) VALUES (NULL,'admin','Welcome to Pandora FMS Console', '&lt;p style="text-align: center; font-size: 13px;"&gt;Hello, congratulations, if you've arrived here you already have an operational monitoring console. Remember that our forums and online documentation are available 24x7 to get you out of any trouble. You can replace this message with a personalized one at Admin tools -&amp;gt; Site news.&lt;/p&gt; ',NOW()); + +-- ---------------------------------------------------------------------- +-- Alter table `talert_templates` +-- ---------------------------------------------------------------------- + + ALTER TABLE `talert_templates` MODIFY COLUMN `type` ENUM('regex','max_min','max','min','equal','not_equal','warning','critical','onchange','unknown','always','not_normal'); + +-- --------------------------------------------------------------------- +-- Table `tvisual_console_items_cache` +-- --------------------------------------------------------------------- +CREATE TABLE `tvisual_console_elements_cache` ( + `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `vc_id` INTEGER UNSIGNED NOT NULL, + `vc_item_id` INTEGER UNSIGNED NOT NULL, + `user_id` VARCHAR(60) DEFAULT NULL, + `data` TEXT NOT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `expiration` INTEGER UNSIGNED NOT NULL COMMENT 'Seconds to expire', + PRIMARY KEY(`id`), + FOREIGN KEY(`vc_id`) REFERENCES `tlayout`(`id`) + ON DELETE CASCADE, + FOREIGN KEY(`vc_item_id`) REFERENCES `tlayout_data`(`id`) + ON DELETE CASCADE, + FOREIGN KEY (`user_id`) REFERENCES `tusuario`(`id_user`) + ON DELETE CASCADE + ON UPDATE CASCADE +) engine=InnoDB DEFAULT CHARSET=utf8; + diff --git a/pandora_console/general/firts_task/collections.php b/pandora_console/general/firts_task/collections.php index 269de3ba12..8e27ce6ee3 100755 --- a/pandora_console/general/firts_task/collections.php +++ b/pandora_console/general/firts_task/collections.php @@ -22,7 +22,7 @@ ui_require_css_file('firts_task'); __('Collections')]); ?>
-

+

true, 'message' => __('There are no custom __('Custom Fields')]); ?>

-

+

true, 'message' => __('There are no custom __('Custom Graphs')]); ?>

-

+

__('Fields Manager')]); ?>

-

+

__('Incidents')]); ?>

-

+

__('Visual Console')]); ?>

-

+

__('Network Map')]); ?>

-

+

__('Planned Downtime')]); ?>

-

+

__('Discovery server')]); ?>

-

+

__('Services')]); ?>

-

+

__('SNMP Filter')]); ?>

-

+

__('Tags')]); ?>

-

+

__('Transactions')]); ?>

-

+

'; -echo ''.__('Page generated at').' '.date($config['date_format']); -echo '
® '.get_copyright_notice().''; if (isset($config['debug'])) { $cache_info = []; diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 7addef057f..a093596b2b 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -18,10 +18,14 @@ require_once 'include/functions_notifications.php'; // Global errors/warnings checking. config_check(); -?> -

-
+if ($config['menu_type'] == 'classic') { + echo '
'; +} else { + echo '
'; +} +?> +
'; - // Search + // Search. $acl_head_search = true; if ($config['acl_enterprise'] == 1 && !users_is_admin()) { $acl_head_search = db_get_sql( @@ -94,7 +98,7 @@ require_once 'include/functions_notifications.php'; } if ($acl_head_search) { - // Search bar + // Search bar. $search_bar = ''; if (!isset($config['search_keywords'])) { $search_bar .= ''; @@ -116,15 +120,13 @@ require_once 'include/functions_notifications.php'; } $search_bar .= 'onfocus="javascript: if (fieldKeyWordEmpty) $(\'#keywords\').val(\'\');" - onkeyup="javascript: fieldKeyWordEmpty = false;" - style="margin-top:5px;" class="search_input" />'; + onkeyup="javascript: fieldKeyWordEmpty = false;" class="search_input" />'; // $search_bar .= 'onClick="javascript: document.quicksearch.submit()"'; $search_bar .= ""; $search_bar .= ''; - $header_searchbar = ''; + $header_searchbar = ''; } @@ -141,14 +143,74 @@ require_once 'include/functions_notifications.php'; $_GET['sec2'] = ''; } + if ($_GET['sec'] == 'main' || !isset($_GET['sec'])) { + // home screen chosen by the user + $home_page = ''; + if (isset($config['id_user'])) { + $user_info = users_get_user_by_id($config['id_user']); + $home_page = io_safe_output($user_info['section']); + $home_url = $user_info['data_section']; + } + + if ($home_page != '') { + switch ($home_page) { + case 'Event list': + $_GET['sec2'] = 'operation/events/events'; + break; + + case 'Group view': + $_GET['sec2'] = 'operation/agentes/group_view'; + break; + + case 'Alert detail': + $_GET['sec2'] = 'operation/agentes/alerts_status'; + break; + + case 'Tactical view': + $_GET['sec2'] = 'operation/agentes/tactical'; + break; + + case 'Default': + $_GET['sec2'] = 'general/logon_ok'; + break; + + case 'Dashboard': + $_GET['sec2'] = 'enterprise/dashboard/main_dashboard'; + break; + + case 'Visual console': + $_GET['sec2'] = 'operation/visual_console/render_view'; + break; + + case 'Other': + $home_url = io_safe_output($home_url); + $url_array = parse_url($home_url); + parse_str($url_array['query'], $res); + foreach ($res as $key => $param) { + $_GET[$key] = $param; + } + break; + } + } + } + if (!isset($_GET['refr'])) { $_GET['refr'] = null; } - $select = db_process_sql("SELECT autorefresh_white_list,time_autorefresh FROM tusuario WHERE id_user = '".$config['id_user']."'"); - $autorefresh_list = json_decode($select[0]['autorefresh_white_list']); + $select = db_process_sql( + "SELECT autorefresh_white_list,time_autorefresh + FROM tusuario + WHERE id_user = '".$config['id_user']."'" + ); - if ($autorefresh_list !== null && array_search($_GET['sec2'], $autorefresh_list) !== false) { + $autorefresh_list = json_decode( + $select[0]['autorefresh_white_list'] + ); + + if ($autorefresh_list !== null + && array_search($_GET['sec2'], $autorefresh_list) !== false + ) { $do_refresh = true; if ($_GET['sec2'] == 'operation/agentes/pandora_networkmap') { if ((!isset($_GET['tab'])) || ($_GET['tab'] != 'view')) { @@ -157,23 +219,65 @@ require_once 'include/functions_notifications.php'; } if ($do_refresh) { - $autorefresh_img = html_print_image('images/header_refresh_gray.png', true, ['class' => 'bot', 'alt' => 'lightning', 'title' => __('Configure autorefresh')]); + $autorefresh_img = html_print_image( + 'images/header_refresh_gray.png', + true, + [ + 'class' => 'bot', + 'alt' => 'lightning', + 'title' => __('Configure autorefresh'), + ] + ); - if ($_GET['refr']) { - $autorefresh_txt .= ' ('.date('i:s', $config['refr']).')'; + if ((isset($select[0]['time_autorefresh']) === true) + && $select[0]['time_autorefresh'] !== 0 + && $config['refr'] === null + ) { + $config['refr'] = $select[0]['time_autorefresh']; + $autorefresh_txt .= ' ('; + $autorefresh_txt .= date( + 'i:s', + $config['refr'] + ); + $autorefresh_txt .= ')'; + } else if ($_GET['refr']) { + $autorefresh_txt .= ' ('; + $autorefresh_txt .= date('i:s', $config['refr']); + $autorefresh_txt .= ')'; } $ignored_params['refr'] = ''; $values = get_refresh_time_array(); + $autorefresh_additional = ''; unset($values); + if ($home_page != '') { + $autorefresh_link_open_img = ''; + } else { + $autorefresh_link_open_img = ''; + } - $autorefresh_link_open_img = ''; - - if ($_GET['refr']) { - $autorefresh_link_open_txt = ''; + if ($_GET['refr'] + || ((isset($select[0]['time_autorefresh']) === true) + && $select[0]['time_autorefresh'] !== 0) + ) { + if ($home_page != '') { + $autorefresh_link_open_txt = ''; + } else { + $autorefresh_link_open_txt = ''; + } } else { $autorefresh_link_open_txt = ''; } @@ -192,7 +296,15 @@ require_once 'include/functions_notifications.php'; $display_counter = 'display:none'; } } else { - $autorefresh_img = html_print_image('images/header_refresh_disabled_gray.png', true, ['class' => 'bot autorefresh_disabled', 'alt' => 'lightning', 'title' => __('Disabled autorefresh')]); + $autorefresh_img = html_print_image( + 'images/header_refresh_disabled_gray.png', + true, + [ + 'class' => 'bot autorefresh_disabled', + 'alt' => 'lightning', + 'title' => __('Disabled autorefresh'), + ] + ); $ignored_params['refr'] = false; @@ -203,56 +315,80 @@ require_once 'include/functions_notifications.php'; $display_counter = 'display:none'; } - $header_autorefresh = '
'.$autorefresh_link_open_img.$autorefresh_img.$autorefresh_link_close.'
'; - $header_autorefresh_counter = '
'.$autorefresh_link_open_txt.$autorefresh_txt.$autorefresh_link_close.$autorefresh_additional.'
'; + $header_autorefresh = '
'; + $header_autorefresh .= $autorefresh_link_open_img; + $header_autorefresh .= $autorefresh_img; + $header_autorefresh .= $autorefresh_link_close; + $header_autorefresh .= '
'; + + $header_autorefresh_counter = '
'; + $header_autorefresh_counter .= $autorefresh_link_open_txt; + $header_autorefresh_counter .= $autorefresh_txt; + $header_autorefresh_counter .= $autorefresh_link_close; + $header_autorefresh_counter .= $autorefresh_additional; + $header_autorefresh_counter .= '
'; - // Qr. - if ($config['show_qr_code_header'] == 0) { - $show_qr_code_header = 'display: none;'; + // Support. + if (defined('PANDORA_ENTERPRISE')) { + $header_support_link = 'https://support.artica.es/'; } else { - $show_qr_code_header = 'display: inline;'; + $header_support_link = 'https://pandorafms.com/forums/'; } - $header_qr = '
'; + $header_support = ''; + + // Documentation. + $header_docu = ''; + - echo "'; - ?> - - __('Edit my user'), 'class' => 'bot', 'alt' => 'user']); + $header_user = html_print_image( + 'images/header_user_admin_green.png', + true, + [ + 'title' => __('Edit my user'), + 'class' => 'bot', + 'alt' => 'user', + ] + ); } else { - $header_user = html_print_image('images/header_user_green.png', true, ['title' => __('Edit my user'), 'class' => 'bot', 'alt' => 'user']); + $header_user = html_print_image( + 'images/header_user_green.png', + true, + [ + 'title' => __('Edit my user'), + 'class' => 'bot', + 'alt' => 'user', + ] + ); } $header_user = ''; // Logout. $header_logout = ''; - echo '
'.$header_autorefresh, $header_autorefresh_counter, $header_qr, $header_chat.'
-
'.$header_searchbar, $header_discovery, $servers_list.'
-
'.$header_user, $header_logout.'
'; + echo '
'.$config['custom_title_header'].''.$config['custom_subtitle_header'].'
+
'.$header_searchbar.'
+
'.$header_chat, $header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_support, $header_docu, $header_user, $header_logout.'
'; ?>
@@ -490,7 +626,12 @@ require_once 'include/functions_notifications.php'; ); - $("a.autorefresh_txt").toggle (); - $("#combo_refr").toggle (); - href = $("a.autorefresh").attr ("href"); - - var refresh = ''; - $(document).attr ("location", href + refresh); - - - if (fixed_header) { $('div#head').addClass('fixed_header'); - $('div#page') - .css('padding-top', $('div#head').innerHeight() + 'px') - .css('position', 'relative'); + $('div#main').css('padding-top', $('div#head').innerHeight() + 'px'); } check_new_chats_icon('icon_new_messages_chat'); @@ -547,14 +669,14 @@ require_once 'include/functions_notifications.php'; blinkpubli(); $("#header_autorefresh").css('padding-right', '5px'); - var refr_time = ; + var refr_time = ; var t = new Date(); - t.setTime (t.getTime () + - parseInt()); - $("#refrcounter").countdown ({until: t, + t.setTime (t.getTime () + parseInt()); + $("#refrcounter").countdown ({ + until: t, layout: '%M%nn%M:%S%nn%S', labels: ['', '', '', '', '', '', ''], onExpiry: function () { diff --git a/pandora_console/general/login_identification_wizard.php b/pandora_console/general/login_identification_wizard.php deleted file mode 100644 index 7bdb370b54..0000000000 --- a/pandora_console/general/login_identification_wizard.php +++ /dev/null @@ -1,455 +0,0 @@ - true, - 'message' => '', - ]; - - if ($register_pandora) { - // Pandora register update - $um_message = update_manager_register_instance(); - $ui_feedback['message'] .= $um_message['message'].'

'; - if ($um_message['success']) { - config_update_value('instance_registered', 1); - $ui_feedback['status'] = true && $ui_feedback['status']; - } else { - $ui_feedback['status'] = false; - } - } else if (!$forced) { - config_update_value('identification_reminder_timestamp', $future_8_days); - } - - if ($newsletter) { - // Pandora newsletter update - $email = get_parameter('email', ''); - $um_message = update_manager_insert_newsletter($email); - $ui_feedback['message'] .= $um_message['message']; - if ($um_message['success']) { - db_process_sql_update('tusuario', ['middlename' => 1], ['id_user' => $config['id_user']]); - $ui_feedback['status'] = true && $ui_feedback['status']; - } else { - $ui_feedback['status'] = false; - } - } else if (!$forced) { - db_process_sql_update('tusuario', ['lastname' => $future_8_days], ['id_user' => $config['id_user']]); - } - - // Form answer JSON - $ui_feedback['status'] = $ui_feedback['status'] ? 1 : 0; - echo io_json_mb_encode($ui_feedback); - } - - if (!$not_return) { - return; - } -} - -// Check if user is admin -if (!license_free()) { - return; -} - -if (!users_is_admin($config['id_user'])) { - return; -} - -// Get data to display properly the wizard -$wizard_data = []; - -$wizard_data['newsletter_subscribed'] = db_get_value('middlename', 'tusuario', 'id_user', $config['id_user']); -// force_* = 1 -> force show -// force_* = 0 -> force hide -// force_* = -1 -> show or hide depends reminder and timestamp -$wizard_data['force_newsletter'] = get_parameter('force_newsletter', -1); -$wizard_data['newsletter_reminder'] = db_get_value('firstname', 'tusuario', 'id_user', $config['id_user']); -$wizard_data['newsletter_reminder_timestamp'] = db_get_value('lastname', 'tusuario', 'id_user', $config['id_user']); - - -$wizard_data['instance_registered'] = $config['instance_registered']; -$wizard_data['force_register'] = get_parameter('force_register', -1); -$wizard_data['identification_reminder'] = $config['identification_reminder']; -$wizard_data['identification_reminder_timestamp'] = $config['identification_reminder_timestamp']; - -$display_newsletter = display_newsletter($wizard_data); -$display_register = display_register($wizard_data); -$display_forced = ($wizard_data['force_newsletter'] != -1) || ($wizard_data['force_register'] != -1); - -// Return if it is fully completed -if ((!$display_register) && (!$display_newsletter)) { - return false; -} - -$return_button = get_parameter('return_button', 0) == 1; - -$email = db_get_value('email', 'tusuario', 'id_user', $config['id_user']); -// Avoid to show default email -if ($email == 'admin@example.com') { - $email = ''; -} - -// Prints accept register license -echo '
'; - echo '
'; - echo html_print_image('images/pandora_circle_big.png', true); - echo '
'; - echo '
'; - echo __('Stay up to date with the %s community', get_product_name()).'.'; - echo '
'; - - echo '
'; - echo '

'.__('When you subscribe to the %s Update Manager service, you accept that we register your %s instance as an identifier on the database owned by Artica TS. This data will solely be used to provide you with information about %s and will not be conceded to third parties. You can unregister from said database at any time from the Update Manager options.', get_product_name(), get_product_name(), get_product_name()).'

'; - echo '

'.__('In the same fashion, when subscribed to the newsletter you accept that your email will pass on to a database property of Artica TS. This data will solely be used to provide you with information about %s and will not be conceded to third parties. You can unregister from said database at any time from the newsletter subscription options.', get_product_name()).'

'; - echo '
'; - - echo '
'; - echo '
'; - html_print_submit_button(__('Finish'), 'finish_dialog_button', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok" style="width:100px;"'); - echo '
'; - $display_status_return = $return_button ? 'block' : 'none'; - echo '
'; - html_print_submit_button(__('Return'), 'return_dialog_button', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd" style="width:100px;"'); - echo '
'; - echo '
'; - html_print_checkbox('register', 1, false, false, false, 'cursor: \'pointer\''); - echo ' '.__('Join the %s community!', get_product_name()).'!
'; - html_print_checkbox('newsletter', 1, false, false, false, 'cursor: \'pointer\''); - echo ' '.__('Subscribe to our newsletter').''; - echo '
'; - echo '
'; - echo ' '; - html_print_input_text_extended('email-newsletter', $email, 'text-email-newsletter', '', 30, 255, false, '', ['style' => 'display:none; width: 200px;']); -echo ' '; - echo ' *'.__('Required').' '; - echo '
'; - echo '
'; - echo '
'; -echo '
'; - -// Print yes or not dialog -echo '
'; - echo '
'; - echo __('Do you want to continue without any registration').'?'; - echo '
'; - echo '
'; - html_print_submit_button(__('No'), 'no_registration', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub cancel" style="width:100px;"'); - echo '
'; - echo '
'; - html_print_submit_button(__('Yes'), 'yes_registration', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd" style="width:100px;"'); - echo '
'; -echo '
'; - -// Print feedback user dialog -echo '
'; - echo '
'; - echo html_print_image('images/success_circle_big.png', true); - echo '
'; - echo '
'; -echo '
'; -?> - - - - - diff --git a/pandora_console/general/login_page.php b/pandora_console/general/login_page.php index ea73318e2a..86dccfa53a 100755 --- a/pandora_console/general/login_page.php +++ b/pandora_console/general/login_page.php @@ -186,7 +186,7 @@ switch ($login_screen) { echo '
'; echo ''; echo ''; echo ''; } break; @@ -245,7 +245,7 @@ switch ($login_screen) { html_print_input_text_extended('auth_code', '', 'auth_code', '', '', '', false, '', 'class="login login_password" placeholder="'.__('Authentication code').'"', false, true); echo '
'; echo ''; break; @@ -305,12 +305,12 @@ if (file_exists(ENTERPRISE_DIR.'/load_enterprise.php')) { echo ''; @@ -319,7 +319,7 @@ echo '
'; echo '
'.$pandora_version.(($develop_bypass == 1) ? ' '.__('Build').' '.$build_version : '').'
'; echo ''; -if (!isset($process_error_message) && isset($mail)) { +if (empty($process_error_message) && isset($mail)) { echo '
'; echo '
'; echo '
'; @@ -336,7 +336,7 @@ if (!isset($process_error_message) && isset($mail)) { echo '
'; echo '
'; echo '
'; -} else if (isset($process_error_message)) { +} else if (isset($process_error_message) && !empty($process_error_message)) { echo '
'; echo '
'; echo '
'; diff --git a/pandora_console/general/login_required.php b/pandora_console/general/login_required.php deleted file mode 100644 index 726d6ab5d1..0000000000 --- a/pandora_console/general/login_required.php +++ /dev/null @@ -1,273 +0,0 @@ - $email], - ['id_user' => $config['id_user']] - ); - } - - // Update the alert action Mail to XXX/Administrator if it is set to default - $mail_check = 'yourmail@domain.es'; - $mail_alert = alerts_get_alert_action_field1(1); - if ($mail_check === $mail_alert && $email !== false) { - alerts_update_alert_action( - 1, - [ - 'field1' => $email, - 'field1_recovery' => $email, - ] - ); - } - - config_update_value('initial_wizard', 1); - } - - // Change the language if is change in checkbox - if ($change_language !== 0) { - config_update_value('language', $change_language); - } - - if ($cancel_wizard !== 0) { - config_update_value('initial_wizard', 1); - } - - return; -} - -$email = db_get_value('email', 'tusuario', 'id_user', $config['id_user']); -// Avoid to show default email -if ($email == 'admin@example.com') { - $email = ''; -} - -// Prints first step pandora registration -echo ''; - - ?> - - diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index 21c9713a48..649a2d2f68 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -1,26 +1,39 @@
".__('Pandora status info').'
".__('MySQL Performance metrics').'
".__('MySQL Performance metrics').' '.ui_print_help_icon('performance_metrics_tab', true).'
".__(' Pandora FMS logs dates').'
".__(' Status of the attachment folder').'
".__(' Information from the tagente_datos table').'
".__(' Pandora FMS server threads').'
@@ -88,7 +113,7 @@ if (!empty($all_data)) { class = 'databox'; @@ -101,12 +126,12 @@ if (!empty($all_data)) { $table->head[0] = ''.__('%s Overview', get_product_name()).''; $table->head_colspan[0] = 4; - // Indicators + // Indicators. $tdata = []; $stats = reporting_get_stats_indicators($data, 120, 10, false); $status = '
'; foreach ($stats as $stat) { - $status .= ''; + $status .= ''; } $status .= '
'.$stat['title'].''.''.$stat['graph'].'
'.$stat['title'].''.$stat['graph'].'
'; @@ -115,25 +140,25 @@ if (!empty($all_data)) { $table->data[] = $tdata; - // Alerts + // Alerts. $tdata = []; $tdata[0] = reporting_get_stats_alerts($data); $table->rowclass[] = ''; $table->data[] = $tdata; - // Modules by status + // Modules by status. $tdata = []; $tdata[0] = reporting_get_stats_modules_status($data, 180, 100); $table->rowclass[] = ''; $table->data[] = $tdata; - // Total agents and modules + // Total agents and modules. $tdata = []; $tdata[0] = reporting_get_stats_agents_monitors($data); $table->rowclass[] = ''; $table->data[] = $tdata; - // Users + // Users. if (users_is_admin()) { $tdata = []; $tdata[0] = reporting_get_stats_users($data); @@ -160,7 +185,7 @@ if (!empty($all_data)) { if (!empty($news)) { - // NEWS BOARD///////////////////////////// + // NEWS BOARD. echo '
'; echo ''; @@ -172,32 +197,42 @@ if (!empty($all_data)) { } foreach ($news as $article) { - $text = io_safe_output($article['text']); - + $image = false; + if ($article['text'] == '&lt;p style="text-align: center; font-size: 13px;"&gt;Hello, congratulations, if you've arrived here you already have an operational monitoring console. Remember that our forums and online documentation are available 24x7 to get you out of any trouble. You can replace this message with a personalized one at Admin tools -&amp;gt; Site news.&lt;/p&gt; ') { + $image = true; + } + $text_bbdd = io_safe_output($article['text']); + $text = html_entity_decode($text_bbdd); echo ''; echo ''; echo ''; } echo '
'.$article['subject'].'
'.__('by').' '.$article['author'].' '.ui_print_timestamp($article['timestamp'], true).' '.$comparation_suffix.'
'; + if ($image) { + echo '
img colabora con nosotros - Support
'; + } + echo nl2br($text); echo '
'; echo '
'; - // News board + // News board. echo '

'; - // END OF NEWS BOARD///////////////////////////// + // END OF NEWS BOARD. } - // LAST ACTIVITY///////////////////////////// - // Show last activity from this user + // LAST ACTIVITY. + // Show last activity from this user. echo '
'; $table = new stdClass(); - $table->class = 'databox data'; + $table->class = 'info_table'; + $table->cellpadding = 0; + $table->cellspacing = 0; $table->width = '100%'; - // Don't specify px + // Don't specify px. $table->data = []; $table->size = []; $table->size[0] = '5%'; @@ -212,38 +247,14 @@ if (!empty($all_data)) { $table->head[3] = __('Source IP'); $table->head[4] = __('Comments'); $table->title = ''.__('This is your last activity performed on the %s console', get_product_name()).''; - - switch ($config['dbtype']) { - case 'mysql': - $sql = sprintf( - 'SELECT id_usuario,accion, ip_origen,descripcion,utimestamp + $sql = sprintf( + 'SELECT id_usuario,accion, ip_origen,descripcion,utimestamp FROM tsesion WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - '.SECONDS_1WEEK.") AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", - $config['id_user'] - ); - break; + $config['id_user'] + ); - case 'postgresql': - $sql = sprintf( - "SELECT \"id_usuario\", accion, \"ip_origen\", descripcion, utimestamp - FROM tsesion - WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - ".SECONDS_1WEEK.") - AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", - $config['id_user'] - ); - break; - - case 'oracle': - $sql = sprintf( - "SELECT id_usuario, accion, ip_origen, descripcion, utimestamp - FROM tsesion - WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (".SECONDS_1DAY.')) - '.SECONDS_1WEEK.") - AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", - $config['id_user'] - ); - break; - } $sessions = db_get_all_rows_sql($sql); @@ -253,24 +264,17 @@ if (!empty($all_data)) { foreach ($sessions as $session) { $data = []; + $session_id_usuario = $session['id_usuario']; + $session_ip_origen = $session['ip_origen']; - switch ($config['dbtype']) { - case 'mysql': - case 'oracle': - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - - case 'postgresql': - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - } $data[0] = ''.$session_id_usuario.''; $data[1] = ui_print_session_action_icon($session['accion'], true).' '.$session['accion']; - $data[2] = ui_print_help_tip(date($config['date_format'], $session['utimestamp']), true).human_time_comparation($session['utimestamp'], 'tiny'); + $data[2] = ui_print_help_tip( + date($config['date_format'], $session['utimestamp']), + true + ).human_time_comparation($session['utimestamp'], 'tiny'); $data[3] = $session_ip_origen; $description = str_replace([',', ', '], ', ', $session['descripcion']); if (strlen($description) > 100) { @@ -287,8 +291,7 @@ if (!empty($all_data)) { unset($table); echo '
'; echo ''; - // activity - // END OF LAST ACTIVIYY///////////////////////////// + // END OF LAST ACTIVIYY. ?> diff --git a/pandora_console/general/main_menu.php b/pandora_console/general/main_menu.php index cb5126b621..877f171090 100644 --- a/pandora_console/general/main_menu.php +++ b/pandora_console/general/main_menu.php @@ -20,31 +20,13 @@ if (! isset($config['id_user'])) { \ No newline at end of file diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php new file mode 100644 index 0000000000..e6a26bb250 --- /dev/null +++ b/pandora_console/general/register.php @@ -0,0 +1,184 @@ + -1], + ['id_user' => $config['id_user']] + ); + + // XXX: Also notify UpdateManager. + } + + if ($register_newsletter) { + $feedback = newsletter_wiz_process(); + } + + if (is_array($feedback)) { + echo json_encode($feedback); + } + + + // Ajax calls finish here. + exit(); +} + + +ui_require_css_file('register'); + +$initial = isset($config['initial_wizard']) !== true + || $config['initial_wizard'] != '1'; + +$newsletter = db_get_value( + 'middlename', + 'tusuario', + 'id_user', + $config['id_user'] +); +$show_newsletter = $newsletter == '0' || $newsletter == ''; + +$registration = isset($config['pandora_uid']) !== true + || $config['pandora_uid'] == ''; + + +if ($initial && users_is_admin()) { + // Show all forms in order. + // 1- Ask for email, timezone, etc. Fullfill alerts and user mail. + config_wiz_modal( + false, + true, + (($registration === true) ? 'show_registration_wizard()' : null) + ); +} + +if ($registration && users_is_admin()) { + // Prepare registration wizard, not launch. leave control to flow. + registration_wiz_modal( + false, + // Launch only if not being launch from 'initial'. + !$initial, + (($show_newsletter === true) ? 'force_run_newsletter()' : null) + ); +} else { + if ($show_newsletter) { + // Show newsletter wizard for current user. + newsletter_wiz_modal( + false, + // Launch only if not being call from 'registration'. + !$registration && !$initial + ); + } +} + + +$newsletter = null; + +?> + diff --git a/pandora_console/godmode/admin_access_logs.php b/pandora_console/godmode/admin_access_logs.php index 93c668f00c..67a933d8cb 100644 --- a/pandora_console/godmode/admin_access_logs.php +++ b/pandora_console/godmode/admin_access_logs.php @@ -183,10 +183,10 @@ if (empty($result)) { } $table = new stdClass(); -$table->cellpadding = 4; -$table->cellspacing = 4; +$table->cellpadding = 0; +$table->cellspacing = 0; $table->width = '100%'; -$table->class = 'databox data'; +$table->class = 'info_table'; $table->size = []; $table->data = []; $table->head = []; @@ -246,7 +246,18 @@ foreach ($result as $row) { } } +foreach ($table->rowclass as $key => $value) { + if (strpos($value, 'limit_scroll') !== false) { + $table->colspan[$key] = [7]; + } else { + if ($enterprise_include !== ENTERPRISE_NOT_HOOK) { + $table->cellclass[$key][6] = 'action_buttons'; + } + } +} + html_print_table($table); +ui_pagination($count, $url, 0, 0, false, 'offset', true, 'pagination-bottom'); if ($enterprise_include !== ENTERPRISE_NOT_HOOK) { enterprise_hook('enterpriseAuditFooter'); diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index a7fc1f156a..dfdd7390c3 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -1,17 +1,32 @@ $value) { - // Check if it has "ifXXXX" syntax and skip it + // Check if it has "ifXXXX" syntax and skip it. if (! preg_match('/if/', $key)) { continue; } @@ -98,7 +109,7 @@ if (is_ajax()) { echo io_json_mb_encode($out); } - // And and remove groups use the same function + // And and remove groups use the same function. $add_secondary_groups = get_parameter('add_secondary_groups'); $remove_secondary_groups = get_parameter('remove_secondary_groups'); if ($add_secondary_groups || $remove_secondary_groups) { @@ -114,12 +125,12 @@ if (is_ajax()) { 'agents_update_secondary_groups', [ $id_agent, - $add_secondary_groups ? $groups_to_add : [], - $remove_secondary_groups ? $groups_to_add : [], + ($add_secondary_groups) ? $groups_to_add : [], + ($remove_secondary_groups) ? $groups_to_add : [], ] ); // Echo 0 in case of error. 0 Otherwise. - echo $ret ? 1 : 0; + echo ($ret) ? 1 : 0; } } @@ -149,7 +160,7 @@ if ($new_agent) { } if (!$new_agent) { - // Agent remote configuration editor + // Agent remote configuration editor. enterprise_include_once('include/functions_config_agents.php'); if (enterprise_installed()) { $filename = config_agents_get_agent_config_filenames($id_agente); @@ -157,37 +168,42 @@ if (!$new_agent) { } $disk_conf_delete = (bool) get_parameter('disk_conf_delete'); -// Agent remote configuration DELETE +// Agent remote configuration DELETE. if ($disk_conf_delete) { // TODO: Get this working on computers where the Pandora server(s) are not on the webserver - // TODO: Get a remote_config editor working in the open version + // TODO: Get a remote_config editor working in the open version. @unlink($filename['md5']); @unlink($filename['conf']); } -echo '
'; +echo ''; -$table = new stdClass(); -$table->width = '100%'; -$table->class = 'databox filters'; - -$table->head = []; -$table->style = []; -$table->style[0] = 'font-weight: bold; width: 150px;'; -$table->data = []; - -$table->align[2] = 'center'; +// Custom ID. +$custom_id_div = '
'; +$custom_id_div .= '

'.__('Custom ID').':

'; +$custom_id_div .= html_print_input_text( + 'custom_id', + $custom_id, + '', + 16, + 255, + true, + false, + false, + '', + 'agent_custom_id' +).'
'; if (!$new_agent && $alias != '') { - $table->data[0][0] = __('Agent name').ui_print_help_tip(__("The agent's name must be the same as the one defined at the console"), true); - $table->data[0][1] = html_print_input_text('agente', $nombre_agente, '', 50, 100, true); - - $table->data[0][2] = __('QR Code Agent view'); + $table_agent_name = '

'.__('Agent name').': '.ui_print_help_tip(__("The agent's name must be the same as the one defined at the console"), true).'

'; + $table_agent_name .= '
'; + $table_agent_name .= '
'.html_print_input_text('agente', $nombre_agente, '', 50, 100, true).'
'; + $table_agent_name .= '
'; if ($id_agente) { - $table->data[0][1] .= ' '.__('ID')."  $id_agente  "; - $table->data[0][1] .= '  '; - $table->data[0][1] .= html_print_image( + $table_agent_name .= ''; + $table_agent_name .= ''; + $table_agent_name .= html_print_image( 'images/zoom.png', true, [ @@ -195,20 +211,23 @@ if (!$new_agent && $alias != '') { 'title' => __('Agent detail'), ] ); - $table->data[0][1] .= ''; + $table_agent_name .= ''; } -} -// Remote configuration available -if (!$new_agent) { + $agent_options_update = 'agent_options_update'; + + // Delete link from here. + $table_agent_name .= "".html_print_image('images/cross.png', true, ['title' => __('Delete agent')]).''; + + // Remote configuration available. if (isset($filename)) { if (file_exists($filename['md5'])) { $agent_name = agents_get_name($id_agente); $agent_name = io_safe_output($agent_name); $agent_md5 = md5($agent_name, false); - $table->data[0][1] .= '  '.''; - $table->data[0][1] .= html_print_image( + $table_agent_name .= ''; + $table_agent_name .= html_print_image( 'images/application_edit.png', true, [ @@ -216,35 +235,57 @@ if (!$new_agent) { 'title' => __('This agent can be remotely configured'), ] ); - $table->data[0][1] .= ''.ui_print_help_tip( + $table_agent_name .= ''.ui_print_help_tip( __('You can remotely edit this agent configuration'), true ); } } + + $table_agent_name .= '
'; + + // QR code div. + $table_qr_code = '
'; + $table_qr_code .= '

'.__('QR Code Agent view').':

'; + $table_qr_code .= '
'; + if ($id_agente) { + $table_qr_code .= ""; + } + + // Add Custom id div. + $table_qr_code .= '
'; + $table_qr_code .= $custom_id_div; + $table_qr_code .= '
'; } -// Delete link from here -if (!$new_agent) { - $table->data[0][1] .= "  ".html_print_image('images/cross.png', true, ['title' => __('Delete agent')]).''; -} - -$table->data[1][0] = __('Alias').ui_print_help_tip(__('Characters /,\,|,%,#,&,$ will be ignored'), true).''; -$table->data[1][1] = html_print_input_text('alias', $alias, '', 50, 100, true); if ($new_agent) { - $table->data[1][1] .= html_print_checkbox('alias_as_name', 1, $config['alias_as_name'], true).__('Use alias as name'); + $label_select_child_left = 'label_select_child_left'; + $label_select_parent = 'label_select_parent'; } -$table->data[2][0] = __('IP Address'); -$table->data[2][1] = html_print_input_text('direccion', $direccion_agente, '', 16, 100, true).html_print_checkbox('unique_ip', 1, $config['unique_ip'], true).__('Unique IP').ui_print_help_tip(__('Set the primary IP address as the unique IP, preventing the same primary IP address from being used in more than one agent'), true); +$table_alias = '

'.__('Alias').': '.ui_print_help_tip(__('Characters /,\,|,%,#,&,$ will be ignored'), true).'

'; +$table_alias .= '
'; +$table_alias .= '
'.html_print_input_text('alias', $alias, '', 50, 100, true).'
'; +if ($new_agent) { + $table_alias .= '
'.html_print_checkbox_switch('alias_as_name', 1, $config['alias_as_name'], true).__('Use alias as name').'
'; +} + +$table_alias .= '
'; + +$table_ip = '

'.__('IP Address').':

'; +$table_ip .= '
'; +$table_ip .= '
'.html_print_input_text('direccion', $direccion_agente, '', 16, 100, true).'
'; +$table_ip .= '
'.html_print_checkbox_switch('unique_ip', 1, $config['unique_ip'], true).__('Unique IP').ui_print_help_tip(__('Set the primary IP address as the unique IP, preventing the same primary IP address from being used in more than one agent'), true).'
'; +$table_ip .= '
'; if ($id_agente) { - $table->data[2][1] .= '    '; - $ip_all = agents_get_addresses($id_agente); - $table->data[2][1] .= html_print_select($ip_all, 'address_list', $direccion_agente, '', '', 0, true); - $table->data[2][1] .= ' '.html_print_checkbox('delete_ip', 1, false, true).__('Delete selected'); + $table_ip .= '
'; + $table_ip .= '
'; + $table_ip .= '
'.html_print_select($ip_all, 'address_list', $direccion_agente, '', '', 0, true).'
'; + $table_ip .= '
'.html_print_checkbox_switch('delete_ip', 1, false, true).__('Delete selected').'
'; + $table_ip .= '
'; } ?> @@ -254,15 +295,6 @@ if ($id_agente) { } rowspan[2][2] = 3; - if ($id_agente) { - $table->data[2][2] = ""; - } else { - $table->data[2][2] = __('Only it is show when
the agent is saved.'); - } -} - $groups = users_get_groups($config['id_user'], 'AR', false); $modules = db_get_all_rows_sql( @@ -277,28 +309,46 @@ if (is_array($modules)) { } } -$table->data[4][0] = __('Primary group'); -// Cannot change primary group if user have not permission for that group +$table_primary_group = '

'.__('Primary group').':

'; +$table_primary_group .= '
'; +// Cannot change primary group if user have not permission for that group. if (isset($groups[$grupo]) || $new_agent) { - $table->data[4][1] = html_print_select_groups(false, 'AR', false, 'grupo', $grupo, '', '', 0, true); + $table_primary_group .= html_print_select_groups(false, 'AR', false, 'grupo', $grupo, '', '', 0, true); } else { - $table->data[4][1] = groups_get_name($grupo); - $table->data[4][1] .= html_print_input_hidden('grupo', $grupo, true); + $table_primary_group .= groups_get_name($grupo); + $table_primary_group .= html_print_input_hidden('grupo', $grupo, true); } -$table->data[4][1] .= ' '; -$table->data[4][1] .= ui_print_group_icon($grupo, true); -$table->data[4][1] .= ''; +$table_primary_group .= '
'; +$table_primary_group .= ui_print_group_icon($grupo, true); +$table_primary_group .= '
'; + +$table_interval = '

'.__('Interval').':

'; +$table_interval .= '
'; +$table_interval .= html_print_extended_select_for_time( + 'intervalo', + $intervalo, + '', + '', + '0', + 10, + true, + false, + true, + 'w40p' +); + -$table->data[5][0] = __('Interval'); -$table->data[5][1] = html_print_extended_select_for_time('intervalo', $intervalo, '', '', '0', 10, true); if ($intervalo < SECONDS_5MINUTES) { - $table->data[5][1] .= clippy_context_help('interval_agent_min'); + $table_interval .= clippy_context_help('interval_agent_min'); } -$table->data[6][0] = __('OS'); -$table->data[6][1] = html_print_select_from_sql( +$table_interval .= '
'; + +$table_os = '

'.__('OS').':

'; +$table_os .= '
'; +$table_os .= html_print_select_from_sql( 'SELECT id_os, name FROM tconfig_os', 'id_os', $id_os, @@ -307,18 +357,19 @@ $table->data[6][1] = html_print_select_from_sql( '0', true ); -$table->data[6][1] .= ' '; -$table->data[6][1] .= ui_print_os_icon($id_os, false, true); -$table->data[6][1] .= ''; +$table_os .= '
'; +$table_os .= ui_print_os_icon($id_os, false, true); +$table_os .= '
'; -// Network server +// Network server. $servers = servers_get_names(); if (!array_key_exists($server_name, $servers)) { $server_Name = 0; // Set the agent have not server. } -$table->data[7][0] = __('Server'); +$table_server = '

'.__('Server').':

'; +$table_server .= '
'; if ($new_agent) { // Set first server by default. $servers_get_names = servers_get_names(); @@ -326,7 +377,7 @@ if ($new_agent) { $server_name = reset($array_keys_servers_get_names); } -$table->data[7][1] = html_print_select( +$table_server .= html_print_select( servers_get_names(), 'server_name', $server_name, @@ -334,118 +385,128 @@ $table->data[7][1] = html_print_select( __('None'), 0, true -).' '.ui_print_help_icon('agent_server', true); +).'
'; -// Description -$table->data[8][0] = __('Description'); -$table->data[8][1] = html_print_input_text( +// Description. +$table_description = '

'.__('Description').':

'; +$table_description .= html_print_textarea( 'comentarios', + 3, + 10, $comentarios, '', - 45, - 200, - true -); + true, + 'agent_description' +).'
'; -html_print_table($table); -unset($table); +// QR code. +echo '
+
+
'.$table_agent_name.$table_alias.$table_ip.$table_primary_group.'
+
'.$table_interval.$table_os.$table_server.$table_description.'
+
'; +if (!$new_agent && $alias != '') { + echo $table_qr_code; +} -$table = new stdClass(); -$table->width = '100%'; -$table->class = 'databox filters'; - -$table->head = []; -$table->style = []; -$table->style[0] = 'font-weight: bold; '; -$table->style[4] = 'font-weight: bold;'; -$table->data = []; +echo '
'; if (enterprise_installed()) { $secondary_groups_selected = enterprise_hook('agents_get_secondary_groups', [$id_agente]); - $table->data['secondary_groups'][0] = __('Secondary groups').ui_print_help_icon('secondary_groups', true); - $table->data['secondary_groups'][1] = html_print_select_groups( + $table_adv_secondary_groups = '

'.__('Secondary groups').':

'; + $table_adv_secondary_groups_left = html_print_select_groups( false, - // Use the current user to select the groups + // Use the current user to select the groups. 'AR', - // ACL permission + // ACL permission. false, - // Not all group + // Not all group. 'secondary_groups', - // HTML id + // HTML id. '', - // No select any by default + // No select any by default. '', - // Javascript onChange code + // Javascript onChange code. '', - // Do not user no selected value + // Do not user no selected value. 0, - // Do not use no selected value + // Do not use no selected value. true, - // Return HTML (not echo) + // Return HTML (not echo). true, - // Multiple selection + // Multiple selection. true, - // Sorting by default + // Sorting by default. '', - // CSS classnames (default) + // CSS classnames (default). false, - // Not disabled (default) + // Not disabled (default). + 'width:50%; min-width:170px;', + // Inline styles (default). false, - // Inline styles (default) + // Option style select (default). false, - // Option style select (default) - false, - // Do not truncate the users tree (default) + // Do not truncate the users tree (default). 'id_grupo', - // Key to get as value (default) + // Key to get as value (default). false, - // Not strict user (default) + // Not strict user (default). $secondary_groups_selected['plain'] - // Do not show the primary group in this selection + // Do not show the primary group in this selection. ); - $table->data['secondary_groups'][2] = html_print_input_image( + $table_adv_secondary_groups_arrows = html_print_input_image( 'add_secondary', - 'images/darrowright.png', + 'images/darrowright_green.png', 1, '', true, [ + 'id' => 'right_autorefreshlist', 'title' => __('Add secondary groups'), 'onclick' => 'agent_manager_add_secondary_groups(event, '.$id_agente.');', ] - ).'



'.html_print_input_image( + ).html_print_input_image( 'remove_secondary', - 'images/darrowleft.png', + 'images/darrowleft_green.png', 1, '', true, [ + 'id' => 'left_autorefreshlist', 'title' => __('Remove secondary groups'), 'onclick' => 'agent_manager_remove_secondary_groups(event, '.$id_agente.');', ] ); - $table->data['secondary_groups'][3] = html_print_select( + $table_adv_secondary_groups_right .= html_print_select( $secondary_groups_selected['for_select'], - // Values + // Values. 'secondary_groups_selected', - // HTML id + // HTML id. '', - // Selected + // Selected. '', - // Javascript onChange code + // Javascript onChange code. '', - // Nothing selected + // Nothing selected. 0, - // Nothing selected + // Nothing selected. true, - // Return HTML (not echo) - true - // Multiple selection + // Return HTML (not echo). + true, + // Multiple selection. + true, + // Sort. + '', + // Class. + false, + // Disabled. + 'width:50%; min-width:170px;' + // Style. ); - // safe operation mode + // Safe operation mode. if ($id_agente) { $sql_modules = db_get_all_rows_sql( 'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo @@ -457,70 +518,68 @@ if (enterprise_installed()) { $safe_mode_modules[$m['id_module']] = $m['name']; } - $table->data[2][0] = __('Safe operation mode').ui_print_help_tip( + $table_adv_safe = '

'.__('Safe operation mode').': '.ui_print_help_tip( __( 'This mode allow %s to disable all modules of this agent while the selected module is on CRITICAL status', get_product_name() ), true + ).'

'; + $table_adv_safe .= html_print_checkbox_switch('safe_mode', 1, $safe_mode, true); + $table_adv_safe .= __('Module').' '.html_print_select($safe_mode_modules, 'safe_mode_module', $safe_mode_module, '', '', 0, true).'
'; + } + + // Remote configuration. + $table_adv_remote = '

'.__('Remote configuration').':

'; + + if (!$new_agent && isset($filename) && file_exists($filename['md5'])) { + $table_adv_remote .= date('F d Y H:i:s', fileatime($filename['md5'])); + // Delete remote configuration. + $table_adv_remote .= ''; + $table_adv_remote .= html_print_image( + 'images/cross.png', + true, + [ + 'title' => __('Delete remote configuration file'), + 'style' => 'vertical-align: middle;', + ] + ).''; + $table_adv_remote .= ''.ui_print_help_tip( + __('Delete this conf file implies that for restore you must reactive remote config in the local agent.'), + true ); - $table->data[2][1] = html_print_checkbox('safe_mode', 1, $safe_mode, true); - $table->data[2][1] .= '  '.__('Module').' '.html_print_select($safe_mode_modules, 'safe_mode_module', $safe_mode_module, '', '', 0, true); - } - - // Remote configuration - $table->data[5][0] = __('Remote configuration'); - - if (!$new_agent) { - $table->data[5][1] = ''.__('Not available').''; - if (isset($filename)) { - if (file_exists($filename['md5'])) { - $table->data[5][1] = date('F d Y H:i:s', fileatime($filename['md5'])); - // Delete remote configuration - $table->data[5][1] .= ''; - $table->data[5][1] .= html_print_image( - 'images/cross.png', - true, - [ - 'title' => __('Delete remote configuration file'), - 'style' => 'vertical-align: middle;', - ] - ).''; - $table->data[5][1] .= ''.ui_print_help_tip( - __('Delete this conf file implies that for restore you must reactive remote config in the local agent.'), - true - ); - } - } } else { - $table->data[5][1] = ''.__('Not available').''; + $table_adv_remote .= ''.__('Not available').''; } + $table_adv_remote .= '
'; - $cps_array[-1] = __('Disabled'); - if ($cps > 0) { - $cps_array[$cps] = __('Enabled'); + // Calculate cps value - agents. + if ($id_agente) { + $cps_val = service_agents_cps($id_agente); } else { - $cps_inc = 0; - if ($id_agente) { - $cps_inc = service_agents_cps($id_agente); + // No agent defined, use received cps as base value. + if ($cps >= 0) { + $cps_val = $cps; } - - $cps_array[$cps_inc] = __('Enabled'); } - $table->data[6][0] = __('Cascade protection services'); - $table->data[6][0] .= ui_print_help_tip(__('Disable the alerts and events of the elements that belong to this service'), true); - $table->data[6][1] = html_print_select($cps_array, 'cps', $cps, '', '', 0, true); + $cps_html = '
'; + $cps_html .= html_print_checkbox_switch('cps', $cps_val, ($cps >= 0), true); + $cps_html .= __('Cascade protection services').' '; + $cps_html .= ui_print_help_tip( + __('Alerts and events will be managed by the service joined by this agent.'), + true + ); + $cps_html .= '
'; + + $table_adv_cascade .= $cps_html; } -// Custom ID -$table->data[0][0] = __('Custom ID'); -$table->data[0][1] = html_print_input_text('custom_id', $custom_id, '', 16, 255, true); -$table->data[1][0] = __('Parent'); +$table_adv_parent = '

'.__('Parent').':

'; $params = []; $params['return'] = true; $params['show_helptip'] = true; @@ -532,75 +591,97 @@ $params['value'] = db_get_value('alias', 'tagente', 'id_agente', $id_parent); $params['selectbox_id'] = 'cascade_protection_module'; $params['javascript_is_function_select'] = true; $params['cascade_protection'] = true; - -$table->data[1][1] = ui_print_agent_autocomplete_input($params); +$table_adv_parent .= '
'; +$table_adv_parent .= ui_print_agent_autocomplete_input($params); if (enterprise_installed()) { - $table->data[1][1] .= html_print_checkbox('cascade_protection', 1, $cascade_protection, true).__('Cascade protection').' '.ui_print_help_icon('cascade_protection', true); + $table_adv_parent .= html_print_checkbox_switch( + 'cascade_protection', + 1, + $cascade_protection, + true + ).__('Cascade protection').' '; } -$table->data[1][1] .= '  '.__('Module').' '.html_print_select($modules_values, 'cascade_protection_module', $cascade_protection_module, '', '', 0, true); -// Learn mode / Normal mode -$table->data[3][0] = __('Module definition').ui_print_help_icon('module_definition', true); -$table->data[3][1] = __('Learning mode').' '.html_print_radio_button_extended( +$table_adv_parent .= __('Module').' '.html_print_select( + $modules_values, + 'cascade_protection_module', + $cascade_protection_module, + '', + '', + 0, + true +).'
'; + +// Learn mode / Normal mode. +$table_adv_module_mode = '

'.__('Module definition').':

'; +$table_adv_module_mode .= '
'; +$table_adv_module_mode .= html_print_radio_button_extended( 'modo', 1, - '', + __('Learning mode'), $modo, false, 'show_modules_not_learning_mode_context_help();', - 'style="margin-right: 40px;"', + '', true ); -$table->data[3][1] .= __('Normal mode').' '.html_print_radio_button_extended( +$table_adv_module_mode .= html_print_radio_button_extended( 'modo', 0, - '', + __('Normal mode'), $modo, false, 'show_modules_not_learning_mode_context_help();', - 'style="margin-right: 40px;"', + '', true ); -$table->data[3][1] .= __('Autodisable mode').' '.html_print_radio_button_extended( +$table_adv_module_mode .= html_print_radio_button_extended( 'modo', 2, - '', + __('Autodisable mode'), $modo, false, 'show_modules_not_learning_mode_context_help();', - 'style="margin-right: 40px;"', + '', true ); +$table_adv_module_mode .= '
'; -// Status (Disabled / Enabled) -$table->data[4][0] = __('Status'); -$table->data[4][1] = __('Disabled').' '.ui_print_help_tip(__('If the remote configuration is enabled, it will also go into standby mode when disabling it.'), true).' '.html_print_radio_button_extended('disabled', 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true); -$table->data[4][1] .= __('Enabled').' '.html_print_radio_button_extended('disabled', 0, '', $disabled, false, '', 'style="margin-right: 40px;"', true); +// Status (Disabled / Enabled). +$table_adv_status = '

'.__('Disabled').': '.ui_print_help_tip(__('If the remote configuration is enabled, it will also go into standby mode when disabling it.'), true).'

'; +$table_adv_status .= html_print_checkbox_switch( + 'disabled', + 1, + $disabled, + true +).'
'; + +// Url address. if (enterprise_installed()) { - $table->data[4][2] = __('Url address').ui_print_help_tip(__('URL address must be complete, for example: https://pandorafms.com/'), true); - $table->data[4][3] = html_print_input_text( + $table_adv_url = '

'.__('Url address').': '.ui_print_help_tip(__('URL address must be complete, for example: https://pandorafms.com/'), true).'

'; + $table_adv_url .= html_print_input_text( 'url_description', $url_description, '', 45, 255, true - ); + ).'
'; } else { - $table->data[5][0] = __('Url address'); - $table->data[5][1] = html_print_input_text( + $table_adv_url = '

'.__('Url address').':

'; + $table_adv_url .= html_print_input_text( 'url_description', $url_description, '', 45, 255, true - ); + ).''; } -$table->data[5][2] = __('Quiet'); -$table->data[5][3] .= ui_print_help_tip(__('The agent still runs but the alerts and events will be stop'), true); -$table->data[5][3] = html_print_checkbox('quiet', 1, $quiet, true); +$table_adv_quiet = '

'.__('Quiet').': '; +$table_adv_quiet .= ui_print_help_tip(__('The agent still runs but the alerts and events will be stop'), true).'

'; +$table_adv_quiet .= html_print_checkbox_switch('quiet', 1, $quiet, true).'
'; $listIcons = gis_get_array_list_icons(); @@ -610,11 +691,11 @@ foreach ($listIcons as $index => $value) { } $path = 'images/gis_map/icons/'; -// TODO set better method the path -$table->data[0][2] = __('Agent icon').ui_print_help_tip(__('Agent icon for GIS Maps.'), true); +// TODO set better method the path. +$table_adv_agent_icon = '

'.__('Agent icon').': '.ui_print_help_tip(__('Agent icon for GIS Maps.'), true).'

'; if ($icon_path == '') { $display_icons = 'none'; - // Hack to show no icon. Use any given image to fix not found image errors + // Hack to show no icon. Use any given image to fix not found image errors. $path_without = 'images/spinner.png'; $path_default = 'images/spinner.png'; $path_ok = 'images/spinner.png'; @@ -629,7 +710,7 @@ if ($icon_path == '') { $path_warning = $path.$icon_path.'.warning.png'; } -$table->data[0][3] = html_print_select( +$table_adv_agent_icon .= html_print_select( $arraySelectIcon, 'icon_path', $icon_path, @@ -637,64 +718,84 @@ $table->data[0][3] = html_print_select( __('None'), '', true -).' '.html_print_image( +).html_print_image( $path_ok, true, [ 'id' => 'icon_ok', 'style' => 'display:'.$display_icons.';', ] -).' '.html_print_image( +).html_print_image( $path_bad, true, [ 'id' => 'icon_bad', 'style' => 'display:'.$display_icons.';', ] -).' '.html_print_image( +).html_print_image( $path_warning, true, [ 'id' => 'icon_warning', 'style' => 'display:'.$display_icons.';', ] -); +).'
'; if ($config['activate_gis']) { - $table->data[3][2] = __('Ignore new GIS data:'); - $table->data[3][3] = __('Yes').' '.html_print_radio_button_extended( - 'update_gis_data', - 0, - '', - $update_gis_data, - false, - '', - 'style="margin-right: 40px;"', - true - ); - $table->data[3][3] .= __('No').' '.html_print_radio_button_extended( - 'update_gis_data', - 1, - '', - $update_gis_data, - false, - '', - 'style="margin-right: 40px;"', - true - ); + $table_adv_gis = '

'.__('Ignore new GIS data:').'

'; + if ($new_agent) { + $update_gis_data = true; + } + + $table_adv_gis .= html_print_checkbox_switch('update_gis_data', 1, $update_gis_data, true).'No / Yes
'; } -ui_toggle(html_print_table($table, true), __('Advanced options')); -unset($table); + + +// General display distribution. +$table_adv_options = $table_adv_secondary_groups.'
+
+ '.$table_adv_secondary_groups_left.' +
+
+ '.$table_adv_secondary_groups_arrows.' +
+
+ '.$table_adv_secondary_groups_right.' +
+
+
+
'.$table_adv_parent.$table_adv_module_mode.$table_adv_cascade; + +if ($new_agent) { + // If agent is new, show custom id as old style format. + $table_adv_options .= $custom_id_div; +} + +$table_adv_options .= $table_adv_gis.'
+
'.$table_adv_agent_icon.$table_adv_url.$table_adv_quiet.$table_adv_status.$table_adv_remote.$table_adv_safe.'
+
'; + +echo '
'; + ui_toggle($table_adv_options, __('Advanced options'), '', true, false, 'white_box white_box_opened'); +echo '
'; + $table = new stdClass(); $table->width = '100%'; -$table->class = 'databox filters'; +$table->class = 'custom_fields_table'; -$table->head = []; +$table->head = [ + 0 => __('Click to display').ui_print_help_tip( + __('This field allows url insertion using the BBCode\'s url tag').'.
'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url]').'.

'.__('e.g.: [url=google.com]Google web search[/url]'), + true + ), +]; +$table->class = 'info_table'; $table->style = []; -$table->style[0] = 'font-weight: bold; width: 100px;'; +$table->style[0] = 'font-weight: bold;'; $table->data = []; +$table->rowstyle = []; $fields = db_get_all_fields_in_table('tagent_custom_fields'); @@ -702,12 +803,13 @@ if ($fields === false) { $fields = []; } +$i = 0; foreach ($fields as $field) { - $data[0] = ''.$field['name'].''; - $data[0] .= ui_print_help_tip( - __('This field allows url insertion using the BBCode\'s url tag').'.
'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url]').'.

'.__('e.g.: [url=google.com]Google web search[/url]'), - true - ); + $id_custom_field = $field['id_field']; + + $data[0] = '
'; + $data[0] .= ''.$field['name'].''; + $data[0] .= '
'; $combo = []; $combo = $field['combo_values']; $combo = explode(',', $combo); @@ -729,8 +831,15 @@ foreach ($fields as $field) { $custom_value = ''; } + $table->rowstyle[$i] = 'cursor: pointer;'; + if (!empty($custom_value)) { + $table->rowstyle[($i + 1)] = 'display: table-row;'; + } else { + $table->rowstyle[($i + 1)] = 'display: none;'; + } + if ($field['is_password_type']) { - $data[1] = html_print_input_text_extended( + $data_field[1] = html_print_input_text_extended( 'customvalue_'.$field['id_field'], $custom_value, 'customvalue_'.$field['id_field'], @@ -744,18 +853,18 @@ foreach ($fields as $field) { true ); } else { - $data[1] = html_print_textarea( + $data_field[1] = html_print_textarea( 'customvalue_'.$field['id_field'], 2, 65, $custom_value, - 'style="min-height: 30px; width:96%;"', + 'style="min-height: 30px;"', true ); } if ($field['combo_values'] !== '') { - $data[1] = html_print_select( + $data_field[1] = html_print_select( $combo_values, 'customvalue_'.$field['id_field'], $custom_value, @@ -776,19 +885,32 @@ foreach ($fields as $field) { ); }; - array_push($table->data, $data); + $table->rowid[] = 'name_field-'.$id_custom_field; + $table->data[] = $data; + + $table->rowid[] = 'field-'.$id_custom_field; + $table->data[] = $data_field; + $i += 2; } if (!empty($fields)) { - ui_toggle(html_print_table($table, true), __('Custom fields')); + echo '
'; + ui_toggle( + html_print_table($table, true), + __('Custom fields'), + '', + true, + false, + 'white_box white_box_opened' + ); + echo '
'; } -echo '
'; - +echo '
'; // The context help about the learning mode. if ($modo == 0) { - echo ""; + echo ""; } else { echo "'; if ($id_agente) { - echo '
'; + echo '
'; html_print_submit_button( __('Update'), 'updbutton', @@ -825,6 +947,19 @@ ui_require_jquery_file('bgiframe'); ?> diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index d6828dd599..d79ca90ca8 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -56,14 +56,20 @@ if ($a_template !== false) { if (defined('METACONSOLE')) { alerts_meta_print_header(); } else { - // ~ ui_print_page_header (__('Alerts') . - // ~ ' » ' . __('Configure alert template'), "", - // ~ false, "alerts_config", true); + $step = (int) get_parameter('step', 1); + if ($step == 1) { + $help_header = 'configure_alert_template_step_1'; + } else if ($step == 2) { + $help_header = 'configure_alert_template_step_2'; + } else if ($step == 3) { + $help_header = 'configure_alert_template_step_3'; + } + ui_print_page_header( __('Alerts').' » '.__('Configure alert template'), '', false, - '', + $help_header, true ); } @@ -83,7 +89,13 @@ if ($a_template !== false) { if (defined('METACONSOLE')) { alerts_meta_print_header(); } else { - ui_print_page_header(__('Alerts').' » '.__('Configure alert template'), 'images/gm_alerts.png', false, 'conf_alert_template', true); + ui_print_page_header( + __('Alerts').' » '.__('Configure alert template'), + 'images/gm_alerts.png', + false, + 'conf_alert_template', + true + ); } } else { db_pandora_audit( @@ -101,7 +113,22 @@ if ($a_template !== false) { if (defined('METACONSOLE')) { alerts_meta_print_header(); } else { - ui_print_page_header(__('Alerts').' » '.__('Configure alert template'), 'images/gm_alerts.png', false, 'conf_alert_template', true); + $step = (int) get_parameter('step', 1); + if ($step == 1) { + $help_header = 'configure_alert_template_step_1'; + } else if ($step == 2) { + $help_header = 'configure_alert_template_step_2'; + } else if ($step == 3) { + $help_header = 'configure_alert_template_step_3'; + } + + ui_print_page_header( + __('Alerts').' » '.__('Configure alert template'), + 'images/gm_alerts.png', + false, + $help_header, + true + ); } } @@ -679,7 +706,7 @@ if ($step == 2) { 'type', $type, '', - __('Select'), + __('None'), 0, true, false, @@ -1018,6 +1045,7 @@ var onchange_msg = ; var unknown = ; var error_message_min_max_zero = ; +var not_normal = ; function check_fields_step2() { var correct = true; @@ -1174,6 +1202,13 @@ if ($step == 2) { /* Show example */ $("span#example").empty ().append (critical); break; + case "not_normal": + $("#template-value, #template-max, span#matches_value, #template-min").hide (); + $("#template-example").show (); + + /* Show example */ + $("span#example").empty ().append (not_normal); + break; case "onchange": $("#template-value, #template-max, #template-min").hide (); $("#template-example, span#matches_value").show (); diff --git a/pandora_console/godmode/category/category.php b/pandora_console/godmode/category/category.php index 727be02057..e1a61a4db6 100755 --- a/pandora_console/godmode/category/category.php +++ b/pandora_console/godmode/category/category.php @@ -82,7 +82,13 @@ $filter['limit'] = (int) $config['block_size']; // Search action: This will filter the display category view $result = false; -$result = categories_get_all_categories(); +$result = db_get_all_rows_filter( + 'tcategory', + [ + 'limit' => $filter['limit'], + 'offset' => $filter['offset'], + ] +); // Display categories previously filtered or not $rowPair = true; @@ -94,7 +100,7 @@ if (!empty($result)) { $table = new stdClass(); $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->data = []; $table->head = []; @@ -123,7 +129,8 @@ if (!empty($result)) { $data[1] .= ''.html_print_image('images/cross.png', true, ['title' => 'Delete']).''; } else { $data[0] = "".$category['name'].''; - $data[1] = "".html_print_image('images/config.png', true, ['title' => 'Edit']).'  '; + $table->cellclass[][1] = 'action_buttons'; + $data[1] = "".html_print_image('images/config.png', true, ['title' => 'Edit']).''; $data[1] .= ''.html_print_image('images/cross.png', true, ['title' => 'Delete']).''; } @@ -131,6 +138,7 @@ if (!empty($result)) { } html_print_table($table); + ui_pagination($total_categories, $url, $offset, 0, false, 'offset', true, 'pagination-bottom'); } else { // No categories available or selected ui_print_info_message(['no_close' => true, 'message' => __('No categories found') ]); diff --git a/pandora_console/godmode/events/event_filter.php b/pandora_console/godmode/events/event_filter.php index 40d60650f6..60ba973996 100644 --- a/pandora_console/godmode/events/event_filter.php +++ b/pandora_console/godmode/events/event_filter.php @@ -113,31 +113,33 @@ if ($filters === false) { $table = new stdClass(); $table->width = '100%'; -$table->class = 'databox data'; +$table->class = 'info_table'; $table->head = []; -$table->head[0] = __('Name'); -$table->head[1] = __('Group'); -$table->head[2] = __('Event type'); -$table->head[3] = __('Event status'); -$table->head[4] = __('Severity'); -$table->head[5] = __('Action').html_print_checkbox('all_delete', 0, false, true, false); +$table->head[0] = html_print_checkbox('all_delete', 0, false, true, false); +$table->head[1] = __('Name'); +$table->head[2] = __('Group'); +$table->head[3] = __('Event type'); +$table->head[4] = __('Event status'); +$table->head[5] = __('Severity'); +$table->head[6] = __('Action'); $table->style = []; -$table->style[0] = 'font-weight: bold'; +$table->style[1] = 'font-weight: bold'; $table->align = []; -$table->align[1] = 'left'; $table->align[2] = 'left'; $table->align[3] = 'left'; - $table->align[4] = 'left'; + $table->align[5] = 'left'; +$table->align[6] = 'left'; $table->size = []; -$table->size[0] = '50%'; -$table->size[1] = '5px'; -$table->size[2] = '80px'; +$table->size[0] = '20px'; +$table->size[1] = '50%'; +$table->size[2] = '5px'; $table->size[3] = '80px'; $table->size[4] = '80px'; -$table->size[5] = '40px'; +$table->size[5] = '80px'; +$table->size[6] = '40px'; $table->data = []; $total_filters = db_get_all_rows_filter('tevent_filter', false, 'COUNT(*) AS total'); @@ -147,13 +149,14 @@ $total_filters = $total_filters[0]['total']; foreach ($filters as $filter) { $data = []; - $data[0] = ''.$filter['id_name'].''; - $data[1] = ui_print_group_icon($filter['id_group_filter'], true); - $data[2] = events_get_event_types($filter['event_type']); - $data[3] = events_get_status($filter['status']); - $data[4] = events_get_severity_types($filter['severity']); - $data[5] = "".html_print_image('images/cross.png', true, ['title' => __('Delete')]).''.html_print_checkbox_extended('delete_multiple[]', $filter['id_filter'], false, false, '', 'class="check_delete"', true); + $data[0] = html_print_checkbox_extended('delete_multiple[]', $filter['id_filter'], false, false, '', 'class="check_delete"', true); + $data[1] = ''.$filter['id_name'].''; + $data[2] = ui_print_group_icon($filter['id_group_filter'], true); + $data[3] = events_get_event_types($filter['event_type']); + $data[4] = events_get_status($filter['status']); + $data[5] = events_get_severity_types($filter['severity']); + $table->cellclass[][6] = 'action_buttons'; + $data[6] = "".html_print_image('images/cross.png', true, ['title' => __('Delete')]).''; array_push($table->data, $data); } @@ -188,8 +191,6 @@ echo '
'; ?> '; } -// Other Checks for the edit the reports +// Other Checks for the edit the reports. if ($idReport != 0) { $report = db_get_row_filter('treport', ['id_report' => $idReport]); $type_access_selected = reports_get_type_access($report); $edit = false; switch ($type_access_selected) { case 'group_view': - $edit = check_acl($config['id_user'], $report['id_group'], 'RW'); + $edit = check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ); break; case 'group_edit': - $edit = check_acl($config['id_user'], $report['id_group_edit'], 'RW'); + $edit = check_acl( + $config['id_user'], + $report['id_group_edit'], + 'RW' + ); break; case 'user_edit': @@ -162,14 +199,21 @@ if ($idReport != 0) { $edit = true; } break; + + default: + // Default. + break; } if (! $edit) { - // The user that created the report should can delete it. Despite its permissions. + // The user that created the report should can delete it. + // Despite its permissions. $delete_report_bypass = false; if ($action == 'delete_report') { - if ($config['id_user'] == $report['id_user'] || is_user_admin($config['id_user'])) { + if ($config['id_user'] == $report['id_user'] + || is_user_admin($config['id_user']) + ) { $delete_report_bypass = true; } } @@ -191,7 +235,10 @@ switch ($action) { case 'list_items': $resultOperationDB = null; $position_to_sort = (int) get_parameter('position_to_sort', 1); - $ids_serialize = (string) get_parameter('ids_items_to_sort', ''); + $ids_serialize = (string) get_parameter( + 'ids_items_to_sort', + '' + ); $move_to = (string) get_parameter('move_to', 'after'); $countItems = db_get_sql( @@ -201,40 +248,25 @@ switch ($action) { WHERE id_report = '.$idReport ); - if (($countItems < $position_to_sort) || ($position_to_sort < 1)) { + if (($countItems < $position_to_sort) + || ($position_to_sort < 1) + ) { $resultOperationDB = false; } else if (!empty($ids_serialize)) { $ids = explode('|', $ids_serialize); - - switch ($config['dbtype']) { - case 'mysql': - $items = db_get_all_rows_sql( - ' - SELECT id_rc, `order` - FROM treport_content - WHERE id_report = '.$idReport.' - ORDER BY `order`' - ); - break; - - case 'oracle': - case 'postgresql': - $items = db_get_all_rows_sql( - ' - SELECT id_rc, "order" - FROM treport_content - WHERE id_report = '.$idReport.' - ORDER BY "order"' - ); - break; - } + $items = db_get_all_rows_sql( + ' + SELECT id_rc, `order` + FROM treport_content + WHERE id_report = '.$idReport.' + ORDER BY `order`' + ); if ($items === false) { $items = []; } - - // Clean the repeated order values + // Clean the repeated order values. $order_temp = 1; foreach ($items as $item) { switch ($config['dbtype']) { @@ -254,6 +286,10 @@ switch ($action) { ['id_rc' => $item['id_rc']] ); break; + + default: + // Default. + break; } $order_temp++; @@ -281,19 +317,19 @@ switch ($action) { ORDER BY "order"' ); break; + + default: + // Default. + break; } if ($items === false) { $items = []; } - - - $temp = []; - $temp = []; foreach ($items as $item) { - // Remove the contents from the block to sort + // Remove the contents from the block to sort. if (array_search($item['id_rc'], $ids) === false) { $temp[$item['order']] = $item['id_rc']; } @@ -301,8 +337,6 @@ switch ($action) { $items = $temp; - - $sorted_items = []; foreach ($items as $pos => $id_unsort) { if ($pos == $position_to_sort) { @@ -324,8 +358,6 @@ switch ($action) { $items = $sorted_items; - - foreach ($items as $order => $id) { switch ($config['dbtype']) { case 'mysql': @@ -344,6 +376,10 @@ switch ($action) { ['id_rc' => $id] ); break; + + default: + // Default. + break; } } @@ -352,6 +388,10 @@ switch ($action) { $resultOperationDB = false; } break; + + default: + // Default. + break; } break; @@ -360,7 +400,8 @@ switch ($action) { $ids_serialize = (string) get_parameter('ids_items_to_delete', ''); if (!empty($ids_serialize)) { - $sql = "DELETE FROM treport_content WHERE id_rc IN ($ids_serialize)"; + $sql = 'DELETE FROM treport_content + WHERE id_rc IN ('.$ids_serialize.')'; $resultOperationDB = db_process_sql($sql); } else { $resultOperationDB = false; @@ -380,7 +421,9 @@ switch ($action) { if (($countItems < $position_to_delete) || ($position_to_delete < 1)) { $resultOperationDB = false; } else { - $sql = "SELECT id_rc FROM treport_content WHERE id_report=$idReport ORDER BY '`order`'"; + $sql = 'SELECT id_rc + FROM treport_content + WHERE id_report='.$idReport." ORDER BY '`order`'"; $items = db_get_all_rows_sql($sql); switch ($pos_delete) { case 'above': @@ -390,7 +433,10 @@ switch ($action) { $i = 1; foreach ($items as $key => $item) { if ($i < $position_to_delete) { - $resultOperationDB = db_process_sql_delete('treport_content', ['id_rc' => $item['id_rc']]); + $resultOperationDB = db_process_sql_delete( + 'treport_content', + ['id_rc' => $item['id_rc']] + ); } $i++; @@ -415,6 +461,10 @@ switch ($action) { } } break; + + default: + // Default. + break; } } break; @@ -433,6 +483,7 @@ switch ($action) { } $subsection = ''; + $helpers = ''; switch ($activeTab) { case 'main': $buttons['list_reports']['active'] = true; @@ -440,13 +491,20 @@ switch ($action) { break; default: - $subsection = reporting_enterprise_add_subsection_main($activeTab, $buttons); + $data_tab = reporting_enterprise_add_subsection_main( + $activeTab, + $buttons + ); + + $subsection = $data_tab['subsection']; + $buttons = $data_tab['buttons']; + $helpers = $data_tab['helpers']; break; } - // Page header for metaconsole - if ($enterpriseEnable and defined('METACONSOLE')) { - // Bread crumbs + // Page header for metaconsole. + if ($enterpriseEnable && defined('METACONSOLE')) { + // Bread crumbs. ui_meta_add_breadcrumb( [ 'link' => 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&pure='.$pure, @@ -456,12 +514,21 @@ switch ($action) { ui_meta_print_page_header($nav_bar); - // Print header + // Print header. ui_meta_print_header(__('Reporting'), '', $buttons); - } - // Page header for normal console - else { - ui_print_page_header(__('Custom reporting'), 'images/op_reporting.png', false, '', false, $buttons, false, '', 60); + } else { + // Page header for normal console. + ui_print_page_header( + __('Custom reporting'), + 'images/op_reporting.png', + false, + '', + false, + $buttons, + false, + '', + 60 + ); } @@ -469,9 +536,11 @@ switch ($action) { $delete = false; switch ($type_access_selected) { case 'group_view': - if ($config['id_user'] == $report['id_user'] || is_user_admin($config['id_user'])) { + if ($config['id_user'] == $report['id_user'] + || is_user_admin($config['id_user']) + ) { $delete = true; - // owner can delete + // Owner can delete. } else { $delete = check_acl( $config['id_user'], @@ -482,9 +551,11 @@ switch ($action) { break; case 'group_edit': - if ($config['id_user'] == $report['id_user'] || is_user_admin($config['id_user'])) { + if ($config['id_user'] == $report['id_user'] + || is_user_admin($config['id_user']) + ) { $delete = true; - // owner can delete + // Owner can delete. } else { $delete = check_acl( $config['id_user'], @@ -501,6 +572,10 @@ switch ($action) { $delete = true; } break; + + default: + // Default. + break; } if (! $delete) { @@ -514,9 +589,15 @@ switch ($action) { $result = reports_delete_report($idReport); if ($result !== false) { - db_pandora_audit('Report management', "Delete report #$idReport"); + db_pandora_audit( + 'Report management', + 'Delete report #'.$idReport + ); } else { - db_pandora_audit('Report management', "Fail try to delete report #$idReport"); + db_pandora_audit( + 'Report management', + 'Fail try to delete report #'.$idReport + ); } ui_print_result_message( @@ -531,7 +612,7 @@ switch ($action) { $search_sql = ''; if ($search != '') { - $search_name = "%$search%' OR description LIKE '%$search%"; + $search_name = '%'.$search."%' OR description LIKE '%".$search.'%'; } $table_aux = new stdClass(); @@ -543,25 +624,57 @@ switch ($action) { $table_aux->colspan[0][0] = 4; $table_aux->data[0][0] = ''.__('Group').''; - $table_aux->data[0][1] = html_print_select_groups(false, $access, true, 'id_group', $id_group, '', '', '', true, false, true, '', false, '', false, false, 'id_grupo', $strict_user).'
'; + $table_aux->data[0][1] = html_print_select_groups( + false, + $access, + true, + 'id_group', + $id_group, + '', + '', + '', + true, + false, + true, + '', + false, + '', + false, + false, + 'id_grupo' + ).'
'; - $table_aux->data[0][2] = ''.__('Free text for search: ').ui_print_help_tip( + $table_aux->data[0][2] = ''.__('Free text for search: '); + $table_aux->data[0][2] .= ui_print_help_tip( __('Search by report name or description, list matches.'), true - ).''; - $table_aux->data[0][3] = html_print_input_text('search', $search, '', 30, '', true); + ); + $table_aux->data[0][2] .= ''; + $table_aux->data[0][3] = html_print_input_text( + 'search', + $search, + '', + 30, + '', + true + ); - $table_aux->data[0][6] = html_print_submit_button(__('Search'), 'search_submit', false, 'class="sub upd"', true); + $table_aux->data[0][6] = html_print_submit_button( + __('Search'), + 'search_submit', + false, + 'class="sub upd"', + true + ); + $url_rb = 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'; if (is_metaconsole()) { - $filter = ""; + $filter = ''; $filter .= html_print_table($table_aux, true); $filter .= ''; ui_toggle($filter, __('Show Option')); } else { - echo "
"; + echo ''; html_print_table($table_aux); echo '
'; } @@ -571,9 +684,9 @@ switch ($action) { ui_require_jquery_file('bgiframe'); ui_require_jquery_file('autocomplete'); - // Show only selected groups + // Show only selected groups. if ($id_group > 0) { - $group = ["$id_group" => $id_group]; + $group = [$id_group => $id_group]; } else { $group = false; } @@ -595,16 +708,16 @@ switch ($action) { } // Fix : group filter was not working - // Show only selected groups + // Show only selected groups. if ($id_group > 0) { - $group = ["$id_group" => $id_group]; + $group = [$id_group => $id_group]; $filter['id_group'] = $id_group; } else { $group = false; } - // Filter normal and metaconsole reports - if ($config['metaconsole'] == 1 and defined('METACONSOLE')) { + // Filter normal and metaconsole reports. + if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { $filter['metaconsole'] = 1; } else { $filter['metaconsole'] = 0; @@ -623,8 +736,7 @@ switch ($action) { ], $return_all_group, $access, - $group, - $strict_user + $group ); $total_reports = (int) count( @@ -633,25 +745,27 @@ switch ($action) { ['name'], $return_all_group, $access, - $group, - $strict_user + $group ) ); - if (sizeof($reports)) { + if (count($reports)) { $url = 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'; ui_pagination($total_reports, $url, $offset, $pagination); $table = new stdClass(); $table->id = 'report_list'; $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->cellpadding = 0; $table->cellspacing = 0; $table->head = []; $table->align = []; + $table->headstyle = []; + $table->style = []; + $table->align[2] = 'left'; $table->align[3] = 'left'; $table->align[4] = 'left'; @@ -663,19 +777,29 @@ switch ($action) { $table->size[0] = '20%'; $table->size[1] = '30%'; $table->size[2] = '2%'; + $table->headstyle[2] = 'min-width: 35px;'; $table->size[3] = '2%'; + $table->headstyle[3] = 'min-width: 35px;'; $table->size[4] = '2%'; + $table->headstyle[4] = 'min-width: 35px;'; $table->size[5] = '2%'; + $table->headstyle[5] = 'min-width: 35px;'; $table->size[6] = '2%'; - $table->size['csv'] = '5%'; + $table->headstyle[6] = 'min-width: 35px;'; + $table->size[7] = '5%'; + $table->headstyle['csv'] = 'min-width: 65px;'; + $table->style[7] = 'text-align: center;'; + + $table->headstyle[9] = 'min-width: 100px;'; + $table->style[9] = 'text-align: center;'; $next = 4; - // Calculate dinamically the number of the column + // Calculate dinamically the number of the column. if (enterprise_hook('load_custom_reporting_1') !== ENTERPRISE_NOT_HOOK) { $next = 7; } - // Admin options only for RM flag + // Admin options only for RM flag. if (check_acl($config['id_user'], 0, 'RM')) { $table->head[$next] = __('Private'); $table->size[$next] = '2%'; @@ -706,7 +830,6 @@ switch ($action) { // $table->size = array (); $table->size[$next] = '10%'; $table->align[$next] = 'left'; - $table->headstyle[$next] = 'text-align:left;'; } $columnview = false; @@ -715,18 +838,44 @@ switch ($action) { foreach ($reports as $report) { if (!is_user_admin($config['id_user'])) { - if ($report['private'] && $report['id_user'] != $config['id_user']) { - if (!check_acl($config['id_user'], $report['id_group'], 'RR') - && !check_acl($config['id_user'], $report['id_group'], 'RW') - && !check_acl($config['id_user'], $report['id_group'], 'RM') + if ($report['private'] + && $report['id_user'] != $config['id_user'] + ) { + if (!check_acl( + $config['id_user'], + $report['id_group'], + 'RR' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RM' + ) ) { continue; } } - if (!check_acl($config['id_user'], $report['id_group'], 'RR') - && !check_acl($config['id_user'], $report['id_group'], 'RW') - && !check_acl($config['id_user'], $report['id_group'], 'RM') + if (!check_acl( + $config['id_user'], + $report['id_group'], + 'RR' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RM' + ) ) { continue; } @@ -734,7 +883,9 @@ switch ($action) { $data = []; - if (check_acl($config['id_user'], $report['id_group'], 'RW') || check_acl($config['id_user'], $report['id_group'], 'RM')) { + if (check_acl($config['id_user'], $report['id_group'], 'RW') + || check_acl($config['id_user'], $report['id_group'], 'RM') + ) { $data[0] = ''.ui_print_truncate_text($report['name'], 70).''; } else { $data[0] = ui_print_truncate_text($report['name'], 70); @@ -743,16 +894,36 @@ switch ($action) { $data[1] = ui_print_truncate_text($report['description'], 70); - // Remove html and xml button if items are larger than limit - $item_count = db_get_num_rows('SELECT * FROM treport_content WHERE id_report='.$report['id_report']); + // Remove html and xml button if items are larger than limit. + $item_count = db_get_num_rows( + 'SELECT * FROM treport_content + WHERE id_report='.$report['id_report'] + ); $report['overload'] = $item_count >= $config['report_limit']; if ($report['overload']) { - $data[2] = html_print_image('images/application_not_writable.png', true, ['title' => __('This report exceeds the item limit for realtime operations')]); + $data[2] = html_print_image( + 'images/application_not_writable.png', + true, + ['title' => __('This report exceeds the item limit for realtime operations')] + ); $data[3] = null; } else if (!$report['non_interactive']) { - $data[2] = ''.html_print_image('images/html.png', true, ['title' => __('HTML view')]).''; - $data[3] = ''.html_print_image('images/xml.png', true, ['title' => __('Export to XML')]).''; - // I chose ajax.php because it's supposed to give XML anyway + $data[2] = ''; + $data[2] .= html_print_image( + 'images/html.png', + true, + ['title' => __('HTML view')] + ); + $data[2] .= ''; + $data[3] = ''; + $data[3] .= html_print_image( + 'images/xml.png', + true, + ['title' => __('Export to XML')] + ); + $data[3] .= ''; + // I chose ajax.php because it's supposed + // to give XML anyway. } else { $data[2] = html_print_image( 'images/html_disabled.png', @@ -764,15 +935,13 @@ switch ($action) { ); } - - // Calculate dinamically the number of the column + // Calculate dinamically the number of the column. $next = 4; if (enterprise_hook('load_custom_reporting_2') !== ENTERPRISE_NOT_HOOK) { $next = 7; } - - // Admin options only for RM flag + // Admin options only for RM flag. if (check_acl($config['id_user'], 0, 'RM')) { if ($report['private'] == 1) { $data[$next] = __('Yes'); @@ -799,14 +968,22 @@ switch ($action) { switch ($type_access_selected) { case 'group_view': - $edit = check_acl($config['id_user'], $report['id_group'], 'RW'); + $edit = check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ); $delete = $edit || is_user_admin($config['id_user']) || $config['id_user'] == $report['id_user']; break; case 'group_edit': - $edit = check_acl($config['id_user'], $report['id_group_edit'], 'RW'); + $edit = check_acl( + $config['id_user'], + $report['id_group_edit'], + 'RW' + ); $delete = $edit || is_user_admin($config['id_user']) || $config['id_user'] == $report['id_user']; @@ -820,24 +997,24 @@ switch ($action) { $delete = true; } break; + + default: + // Default. + break; } if ($edit || $delete) { $columnview = true; + $table->cellclass[][$next] = 'action_buttons'; + if (!isset($table->head[$next])) { $table->head[$next] = ''.__('Op.').''.html_print_checkbox('all_delete', 0, false, true, false); $table->size = []; // $table->size[$next] = '80px'; - $table->style[$next] = 'text-align:left;'; } if ($edit) { $data[$next] = '
'; - $data[$next] .= html_print_input_hidden( - 'id_report', - $report['id_report'], - true - ); $data[$next] .= html_print_input_image( 'edit', 'images/config.png', @@ -846,13 +1023,16 @@ switch ($action) { true, ['title' => __('Edit')] ); + $data[$next] .= html_print_input_hidden( + 'id_report', + $report['id_report'], + true + ); $data[$next] .= '
'; } if ($delete) { $data[$next] .= '
'; - $data[$next] .= html_print_input_hidden('id_report', $report['id_report'], true); - $data[$next] .= html_print_input_hidden('action', 'delete_report', true); $data[$next] .= html_print_input_image( 'delete', 'images/cross.png', @@ -861,8 +1041,26 @@ switch ($action) { true, ['title' => __('Delete')] ); + $data[$next] .= html_print_input_hidden( + 'id_report', + $report['id_report'], + true + ); + $data[$next] .= html_print_input_hidden( + 'action', + 'delete_report', + true + ); - $data[$next] .= html_print_checkbox_extended('massive_report_check', $report['id_report'], false, false, '', 'class="check_delete"', true); + $data[$next] .= html_print_checkbox_extended( + 'massive_report_check', + $report['id_report'], + false, + false, + '', + 'class="check_delete"', + true + ); $data[$next] .= '
'; } @@ -887,11 +1085,28 @@ switch ($action) { } html_print_table($table); + ui_pagination( + $total_reports, + $url, + $offset, + $pagination, + false, + 'offset', + true, + 'pagination-bottom' + ); } else { - ui_print_info_message([ 'no_close' => true, 'message' => __('No data found.') ]); + ui_print_info_message( + [ + 'no_close' => true, + 'message' => __('No data found.'), + ] + ); } - if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM')) { + if (check_acl($config['id_user'], 0, 'RW') + || check_acl($config['id_user'], 0, 'RM') + ) { echo '
'; if (defined('METACONSOLE')) { echo '
'; @@ -899,7 +1114,12 @@ switch ($action) { echo '
'; } - html_print_submit_button(__('Create report'), 'create', false, 'class="sub next"'); + html_print_submit_button( + __('Create report'), + 'create', + false, + 'class="sub next"' + ); echo ''; echo '
'; @@ -909,13 +1129,17 @@ switch ($action) { } echo ''; - html_print_submit_button(__('Delete'), 'delete_btn', false, 'class="sub delete" style="margin-left:5px;"'); + html_print_submit_button( + __('Delete'), + 'delete_btn', + false, + 'class="sub delete" style="margin-left:5px;"' + ); echo '
'; echo '
'; } enterprise_hook('close_meta_frame'); - return; break; @@ -924,7 +1148,7 @@ switch ($action) { case 'main': $reportName = ''; $idGroupReport = 0; - // All groups + // All groups. $description = ''; $resultOperationDB = null; $report_id_user = 0; @@ -943,6 +1167,10 @@ switch ($action) { $idGroupReport = $report['id_group']; $description = $report['description']; break; + + default: + // Default. + break; } break; @@ -953,12 +1181,15 @@ switch ($action) { $reportName = get_parameter('name'); $idGroupReport = get_parameter('id_group'); $description = get_parameter('description'); - $type_access_selected = get_parameter('type_access', 'group_view'); + $type_access_selected = get_parameter( + 'type_access', + 'group_view' + ); $id_group_edit_param = (int) get_parameter('id_group_edit', 0); $report_id_user = get_parameter('report_id_user'); $non_interactive = get_parameter('non_interactive', 0); - // Pretty font by default for pdf + // Pretty font by default for pdf. $custom_font = 'FreeSans.ttf'; switch ($type_access_selected) { @@ -976,6 +1207,10 @@ switch ($action) { $id_group_edit = 0; $private = 1; break; + + default: + // Default. + break; } if ($action == 'update') { @@ -1011,12 +1246,12 @@ switch ($action) { if ($resultOperationDB !== false) { db_pandora_audit( 'Report management', - "Update report #$idReport" + 'Update report #'.$idReport ); } else { db_pandora_audit( 'Report management', - "Fail try to update report #$idReport" + 'Fail try to update report #'.$idReport ); } } else { @@ -1026,10 +1261,10 @@ switch ($action) { $action = 'edit'; } else if ($action == 'save') { if ($reportName != '' && $idGroupReport != '') { - // This flag allow to differentiate between normal console and metaconsole reports + // This flag allow to differentiate + // between normal console and metaconsole reports. $metaconsole_report = (int) is_metaconsole(); - // Juanma (07/05/2014) New feature: Custom front page for reports if ($config['custom_report_front']) { $custom_font = $config['custom_report_front_font']; $logo = $config['custom_report_front_logo']; @@ -1037,9 +1272,16 @@ switch ($action) { $first_page = $config['custom_report_front_firstpage']; $footer = $config['custom_report_front_footer']; } else { - $start_url = ui_get_full_url(false, false, false, false); + $start_url = ui_get_full_url( + false, + false, + false, + false + ); $first_page = '<p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;"><img src="'.$start_url.'/images/pandora_report_logo.png" alt="" width="800" /></p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;"><span style="font-size: xx-large;">(_REPORT_NAME_)</span></p> <p style="text-align: center;"><span style="font-size: large;">(_DATETIME_)</span></p>'; - $logo = $header = $footer = null; + $logo = null; + $header = null; + $footer = null; } $idOrResult = db_process_sql_insert( @@ -1062,9 +1304,15 @@ switch ($action) { ); if ($idOrResult !== false) { - db_pandora_audit('Report management', "Create report #$idOrResult"); + db_pandora_audit( + 'Report management', + 'Create report #'.$idOrResult + ); } else { - db_pandora_audit('Report management', 'Fail try to create report'); + db_pandora_audit( + 'Report management', + 'Fail try to create report' + ); } } else { $idOrResult = false; @@ -1078,7 +1326,7 @@ switch ($action) { $report_id_user = $config['id_user']; } - $action = $resultOperationDB ? 'edit' : 'new'; + $action = ($resultOperationDB) ? 'edit' : 'new'; } break; @@ -1089,32 +1337,31 @@ switch ($action) { ['id_report' => $idReport] ); - - - $reportName = $report['name']; $idGroupReport = $report['id_group']; $description = $report['description']; $good_format = false; switch ($action) { case 'update': - $values = []; $values['id_report'] = $idReport; - // --------------------------------------------------- - // $values['name'] = (string) get_parameter('name'); $values['description'] = get_parameter('description'); $values['type'] = get_parameter('type', null); $values['recursion'] = get_parameter('recursion', null); $label = get_parameter('label', ''); - // Add macros name + // Add macros name. $items_label = []; $items_label['type'] = get_parameter('type'); $items_label['id_agent'] = get_parameter('id_agent'); - $items_label['id_agent_module'] = get_parameter('id_agent_module'); + $items_label['id_agent_module'] = get_parameter( + 'id_agent_module' + ); $name_it = (string) get_parameter('name'); - $values['name'] = reporting_label_macro($items_label, $name_it); + $values['name'] = reporting_label_macro( + $items_label, + $name_it + ); /* Added support for projection graphs, @@ -1126,13 +1373,14 @@ switch ($action) { switch ($values['type']) { case 'projection_graph': $values['period'] = get_parameter('period1'); - $values['top_n_value'] = get_parameter('period2'); + $values['top_n_value'] = get_parameter( + 'period2' + ); $values['text'] = get_parameter('text'); $good_format = true; break; case 'event_report_log': - $agents_to_report = get_parameter('id_agents3'); $source = get_parameter('source', ''); $search = get_parameter('search', ''); @@ -1150,16 +1398,29 @@ switch ($action) { case 'prediction_date': $values['period'] = get_parameter('period1'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg'); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg' + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $interval_max = get_parameter('max_interval'); $interval_min = get_parameter('min_interval'); - // Checks intervals fields - if (preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_max) and preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_min)) { + // Checks intervals fields. + if (preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_max + ) + && preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_min + ) + ) { $good_format = true; } - $intervals = get_parameter('max_interval').';'.get_parameter('min_interval'); + $intervals = get_parameter('max_interval').';'; + $intervals .= get_parameter('min_interval'); $values['text'] = $intervals; break; @@ -1170,19 +1431,32 @@ switch ($action) { case 'SLA': case 'availability_graph': $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('combo_sla_sort_options', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'combo_sla_sort_options', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; case 'agent_module': $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter('module', ''); + $modules_to_report = get_parameter( + 'module', + '' + ); - $es['module'] = get_same_modules($agents_to_report, $modules_to_report); + $es['module'] = get_same_modules( + $agents_to_report, + $modules_to_report + ); $es['id_agents'] = $agents_to_report; $values['external_source'] = json_encode($es); @@ -1193,7 +1467,9 @@ switch ($action) { $values['period'] = 0; $es['date'] = get_parameter('date'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $description = get_parameter('description'); $values['external_source'] = json_encode($es); $good_format = true; @@ -1202,37 +1478,85 @@ switch ($action) { case 'inventory_changes': $values['period'] = get_parameter('period'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $description = get_parameter('description'); $values['external_source'] = json_encode($es); $good_format = true; break; case 'netflow_area': - case 'netflow_pie': case 'netflow_data': - case 'netflow_statistics': case 'netflow_summary': - $values['text'] = get_parameter('netflow_filter'); - $values['description'] = get_parameter('description'); + $values['text'] = get_parameter( + 'netflow_filter' + ); + $values['description'] = get_parameter( + 'description' + ); $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('resolution'); - $values['top_n_value'] = get_parameter('max_values'); + $values['top_n_value'] = get_parameter( + 'max_values' + ); $good_format = true; break; case 'availability': // HACK it is saved in show_graph field. - // Show interfaces instead the modules - $values['show_graph'] = get_parameter('checkbox_show_address_agent'); - $values['period'] = get_parameter('period'); + // Show interfaces instead the modules. + $values['show_graph'] = get_parameter( + 'checkbox_show_address_agent' + ); + $values['period'] = get_parameter( + 'period' + ); + $values['total_time'] = get_parameter( + 'total_time' + ); + $values['time_failed'] = get_parameter( + 'time_failed' + ); + $values['time_in_ok_status'] = get_parameter( + 'time_in_ok_status' + ); + $values['time_in_unknown_status'] = get_parameter( + 'time_in_unknown_status' + ); + $values['time_of_not_initialized_module'] = get_parameter( + 'time_of_not_initialized_module' + ); + $values['time_of_downtime'] = get_parameter( + 'time_of_downtime' + ); + $values['total_checks'] = get_parameter( + 'total_checks' + ); + $values['checks_failed'] = get_parameter( + 'checks_failed' + ); + $values['checks_in_ok_status'] = get_parameter( + 'checks_in_ok_status' + ); + $values['unknown_checks'] = get_parameter( + 'unknown_checks' + ); + $values['agent_max_value'] = get_parameter( + 'agent_max_value' + ); + $values['agent_min_value'] = get_parameter( + 'agent_min_value' + ); $good_format = true; break; case 'simple_graph': case 'simple_baseline_graph': // HACK it is saved in show_graph field. - $values['show_graph'] = (int) get_parameter('time_compare_overlapped'); + $values['show_graph'] = (int) get_parameter( + 'time_compare_overlapped' + ); $values['period'] = get_parameter('period'); $good_format = true; break; @@ -1241,19 +1565,39 @@ switch ($action) { case 'max_value': case 'avg_value': $values['period'] = get_parameter('period'); - $values['lapse_calc'] = get_parameter('lapse_calc'); + $values['lapse_calc'] = get_parameter( + 'lapse_calc' + ); $values['lapse'] = get_parameter('lapse'); - $values['visual_format'] = get_parameter('visual_format'); + $values['visual_format'] = get_parameter( + 'visual_format' + ); + $good_format = true; + break; + + case 'nt_top_n': + $values['period'] = get_parameter('period'); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $good_format = true; break; default: $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; + break; } $values['id_agent'] = get_parameter('id_agent'); @@ -1261,16 +1605,27 @@ switch ($action) { $values['id_agent_module'] = ''; if (isset($values['type'])) { - if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent') or ($values['type'] == 'agent_configuration') or ($values['type'] == 'group_configuration')) { + if (($values['type'] == 'alert_report_agent') + || ($values['type'] == 'event_report_agent') + || ($values['type'] == 'agent_configuration') + || ($values['type'] == 'group_configuration') + ) { $values['id_agent_module'] = ''; } else { - $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['id_agent_module'] = get_parameter( + 'id_agent_module' + ); } } else { - $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['id_agent_module'] = get_parameter( + 'id_agent_module' + ); } - $values['only_display_wrong'] = (int) get_parameter('checkbox_only_display_wrong', 0); + $values['only_display_wrong'] = (int) get_parameter( + 'checkbox_only_display_wrong', + 0 + ); $values['monday'] = get_parameter('monday', 0); $values['tuesday'] = get_parameter('tuesday', 0); $values['wednesday'] = get_parameter('wednesday', 0); @@ -1278,89 +1633,221 @@ switch ($action) { $values['friday'] = get_parameter('friday', 0); $values['saturday'] = get_parameter('saturday', 0); $values['sunday'] = get_parameter('sunday', 0); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $values['time_from'] = get_parameter('time_from'); - $values['time_to'] = get_parameter('time_to'); - break; + $values['total_time'] = get_parameter('total_time', 0); + $values['time_failed'] = get_parameter( + 'time_failed', + 0 + ); + $values['time_in_ok_status'] = get_parameter( + 'time_in_ok_status', + 0 + ); + $values['time_in_unknown_status'] = get_parameter( + 'time_in_unknown_status', + 0 + ); + $values['time_of_not_initialized_module'] = get_parameter( + 'time_of_not_initialized_module', + 0 + ); + $values['time_of_downtime'] = get_parameter( + 'time_of_downtime', + 0 + ); + $values['total_checks'] = get_parameter( + 'total_checks', + 0 + ); + $values['checks_failed'] = get_parameter( + 'checks_failed', + 0 + ); + $values['checks_in_ok_status'] = get_parameter( + 'checks_in_ok_status', + 0 + ); + $values['unknown_checks'] = get_parameter( + 'unknown_checks', + 0 + ); + $values['agent_max_value'] = get_parameter( + 'agent_max_value', + 0 + ); + $values['agent_min_value'] = get_parameter( + 'agent_min_value', + 0 + ); - case 'oracle': - $values['time_from'] = '#to_date(\''.get_parameter('time_from').'\',\'hh24:mi:ss\')'; - $values['time_to'] = '#to_date(\''.get_parameter('time_to').'\', \'hh24:mi:ss\')'; - break; - } + $values['time_from'] = get_parameter( + 'time_from' + ); + $values['time_to'] = get_parameter('time_to'); - $values['group_by_agent'] = get_parameter('checkbox_row_group_by_agent'); - $values['show_resume'] = get_parameter('checkbox_show_resume'); - $values['order_uptodown'] = get_parameter('radiobutton_order_uptodown'); - $values['exception_condition'] = (int) get_parameter('exception_condition', 0); - $values['exception_condition_value'] = get_parameter('exception_condition_value'); - $values['id_module_group'] = get_parameter('combo_modulegroup'); + $values['group_by_agent'] = get_parameter( + 'checkbox_row_group_by_agent' + ); + $values['show_resume'] = get_parameter( + 'checkbox_show_resume' + ); + $values['order_uptodown'] = get_parameter( + 'radiobutton_order_uptodown' + ); + $values['exception_condition'] = (int) get_parameter( + 'exception_condition', + 0 + ); + $values['exception_condition_value'] = get_parameter( + 'exception_condition_value' + ); + $values['id_module_group'] = get_parameter( + 'combo_modulegroup' + ); $values['id_group'] = get_parameter('combo_group'); $values['server_name'] = get_parameter('server_name'); $server_id = (int) get_parameter('server_id'); if ($server_id != 0) { - $connection = metaconsole_get_connection_by_id($server_id); + $connection = metaconsole_get_connection_by_id( + $server_id + ); $values['server_name'] = $connection['server_name']; } if ($values['server_name'] == '') { - $values['server_name'] = get_parameter('combo_server'); + $values['server_name'] = get_parameter( + 'combo_server' + ); } - if ((($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) && ($values['id_gs'] == 0 || $values['id_gs'] == '')) { + if ((($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph')) + && ($values['id_gs'] == 0 || $values['id_gs'] == '') + ) { $resultOperationDB = false; break; } - $show_summary_group = get_parameter('show_summary_group', 0); - $filter_event_severity = get_parameter('filter_event_severity', 0); - $filter_event_type = get_parameter('filter_event_type', ''); - $filter_event_status = get_parameter('filter_event_status', 0); + $show_summary_group = get_parameter( + 'show_summary_group', + 0 + ); + $filter_event_severity = get_parameter( + 'filter_event_severity', + 0 + ); + $filter_event_type = get_parameter( + 'filter_event_type', + '' + ); + $filter_event_status = get_parameter( + 'filter_event_status', + 0 + ); - $event_graph_by_agent = get_parameter('event_graph_by_agent', 0); - $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); - $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); - $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + $event_graph_by_agent = get_parameter( + 'event_graph_by_agent', + 0 + ); + $event_graph_by_user_validator = get_parameter( + 'event_graph_by_user_validator', + 0 + ); + $event_graph_by_criticity = get_parameter( + 'event_graph_by_criticity', + 0 + ); + $event_graph_validated_vs_unvalidated = get_parameter( + 'event_graph_validated_vs_unvalidated', + 0 + ); - $event_filter_search = get_parameter('filter_search', ''); + $event_filter_search = get_parameter( + 'filter_search', + '' + ); - // If metaconsole is activated - if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { - if (($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) { - $id_gs = substr($values['id_gs'], 0, strpos($values['id_gs'], '|')); + // If metaconsole is activated. + if ($config['metaconsole'] == 1 + && defined('METACONSOLE') + ) { + if (($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph') + ) { + $id_gs = substr( + $values['id_gs'], + 0, + strpos($values['id_gs'], '|') + ); if ($id_gs !== false) { - $server_name = strstr($values['id_gs'], '|'); + $server_name = strstr( + $values['id_gs'], + '|' + ); $values['id_gs'] = $id_gs; - $values['server_name'] = substr($server_name, 1, strlen($server_name)); + $values['server_name'] = substr( + $server_name, + 1, + strlen($server_name) + ); } } - // Get agent and server name - $agent_name_server = io_safe_output(get_parameter('agent')); + // Get agent and server name. + $agent_name_server = io_safe_output( + get_parameter('agent') + ); if (isset($agent_name_server)) { - $separator_pos = strpos($agent_name_server, '('); + $separator_pos = strpos( + $agent_name_server, + '(' + ); - if (($separator_pos != false) and ($separator_pos != 0)) { - $server_name = substr($agent_name_server, $separator_pos); - $server_name = str_replace('(', '', $server_name); - $server_name = str_replace(')', '', $server_name); - // Will update server_name variable + if (($separator_pos != false) + || ($separator_pos != 0) + ) { + $server_name = substr( + $agent_name_server, + $separator_pos + ); + $server_name = str_replace( + '(', + '', + $server_name + ); + $server_name = str_replace( + ')', + '', + $server_name + ); + // Will update server_name variable. $values['server_name'] = trim($server_name); - $agent_name = substr($agent_name_server, 0, $separator_pos); + $agent_name = substr( + $agent_name_server, + 0, + $separator_pos + ); } } } - if (($values['type'] == 'sql') or ($values['type'] == 'sql_graph_hbar') or ($values['type'] == 'sql_graph_vbar') or ($values['type'] == 'sql_graph_pie')) { - $values['treport_custom_sql_id'] = get_parameter('id_custom'); + if (($values['type'] == 'sql') + || ($values['type'] == 'sql_graph_hbar') + || ($values['type'] == 'sql_graph_vbar') + || ($values['type'] == 'sql_graph_pie') + ) { + $values['treport_custom_sql_id'] = get_parameter( + 'id_custom' + ); if ($values['treport_custom_sql_id'] == 0) { - $values['external_source'] = get_parameter('sql'); + $values['external_source'] = get_parameter( + 'sql' + ); } - $values['historical_db'] = get_parameter('historical_db_check'); + $values['historical_db'] = get_parameter( + 'historical_db_check' + ); $values['top_n_value'] = get_parameter('max_items'); } else if ($values['type'] == 'url') { $values['external_source'] = get_parameter('url'); @@ -1372,22 +1859,45 @@ switch ($action) { $values['column_separator'] = get_parameter('field'); $values['line_separator'] = get_parameter('line'); + $values['current_month'] = get_parameter('current_month'); + $style = []; - $style['show_in_same_row'] = get_parameter('show_in_same_row', 0); - $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); - $style['hide_notinit_agents'] = get_parameter('hide_notinit_agents', 0); - $style['priority_mode'] = get_parameter('priority_mode', REPORT_PRIORITY_MODE_OK); - $style['dyn_height'] = get_parameter('dyn_height', 230); + $style['show_in_same_row'] = get_parameter( + 'show_in_same_row', + 0 + ); + $style['show_in_landscape'] = get_parameter( + 'show_in_landscape', + 0 + ); + $style['hide_notinit_agents'] = get_parameter( + 'hide_notinit_agents', + 0 + ); + $style['priority_mode'] = get_parameter( + 'priority_mode', + REPORT_PRIORITY_MODE_OK + ); + $style['dyn_height'] = get_parameter( + 'dyn_height', + 230 + ); switch ($values['type']) { case 'event_report_agent': case 'event_report_group': case 'event_report_module': - // Added for events items - $style['show_summary_group'] = $show_summary_group; - $style['filter_event_severity'] = json_encode($filter_event_severity); - $style['filter_event_type'] = json_encode($filter_event_type); - $style['filter_event_status'] = json_encode($filter_event_status); + // Added for events items. + $style['show_summary_group'] = $show_summary_group; + $style['filter_event_severity'] = json_encode( + $filter_event_severity + ); + $style['filter_event_type'] = json_encode( + $filter_event_type + ); + $style['filter_event_status'] = json_encode( + $filter_event_status + ); $style['event_graph_by_agent'] = $event_graph_by_agent; $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; @@ -1403,10 +1913,15 @@ switch ($action) { break; case 'simple_graph': - // Warning. We are using this column to hold this value to avoid - // the modification of the database for compatibility reasons. - $style['percentil'] = (int) get_parameter('percentil'); - $style['fullscale'] = (int) get_parameter('fullscale'); + // Warning. We are using this column to hold + // this value to avoid the modification of the + // database for compatibility reasons. + $style['percentil'] = (int) get_parameter( + 'percentil' + ); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); if ($label != '') { $style['label'] = $label; } else { @@ -1415,7 +1930,9 @@ switch ($action) { break; case 'network_interfaces_report': - $style['fullscale'] = (int) get_parameter('fullscale'); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); break; case 'module_histogram_graph': @@ -1436,12 +1953,17 @@ switch ($action) { case 'MTBF': case 'MTTR': case 'simple_baseline_graph': + case 'nt_top_n': if ($label != '') { $style['label'] = $label; } else { $style['label'] = ''; } break; + + default: + // Default. + break; } $values['style'] = io_safe_input(json_encode($style)); @@ -1456,6 +1978,10 @@ switch ($action) { unset($values['type']); } break; + + default: + // Default. + break; } $resultOperationDB = db_process_sql_update( @@ -1469,54 +1995,81 @@ switch ($action) { break; case 'save': - $values = []; $values['id_report'] = $idReport; $values['type'] = get_parameter('type', null); - // $values['name'] = (string) get_parameter('name'); $values['description'] = get_parameter('description'); $label = get_parameter('label', ''); - // Add macros name + // Add macros name. $items_label = []; $items_label['type'] = get_parameter('type'); $items_label['id_agent'] = get_parameter('id_agent'); - $items_label['id_agent_module'] = get_parameter('id_agent_module'); + $items_label['id_agent_module'] = get_parameter( + 'id_agent_module' + ); $name_it = (string) get_parameter('name'); $values['recursion'] = get_parameter('recursion', null); - $values['name'] = reporting_label_macro($items_label, $name_it); + $values['name'] = reporting_label_macro( + $items_label, + $name_it + ); - // Support for projection graph, prediction date and SLA reports - // 'top_n_value', 'top_n' and 'text' fields will be reused for these types of report + // Support for projection graph, prediction date + // and SLA reports 'top_n_value', 'top_n' and 'text' + // fields will be reused for these types of report. switch ($values['type']) { case 'projection_graph': $values['period'] = get_parameter('period1'); - $values['top_n_value'] = get_parameter('period2'); + $values['top_n_value'] = get_parameter( + 'period2' + ); $values['text'] = get_parameter('text'); $good_format = true; break; case 'prediction_date': $values['period'] = get_parameter('period1'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg'); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg' + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $interval_max = get_parameter('max_interval'); $interval_min = get_parameter('min_interval'); - // Checks intervals fields - if (preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_max) and preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_min)) { + // Checks intervals fields. + if (preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_max + ) + && preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_min + ) + ) { $good_format = true; } - $intervals = get_parameter('max_interval').';'.get_parameter('min_interval'); + $intervals = get_parameter( + 'max_interval' + ).';'.get_parameter('min_interval'); $values['text'] = $intervals; break; case 'SLA': $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('combo_sla_sort_options', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'combo_sla_sort_options', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; @@ -1525,7 +2078,9 @@ switch ($action) { $values['period'] = 0; $es['date'] = get_parameter('date'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $values['external_source'] = json_encode($es); $good_format = true; break; @@ -1548,9 +2103,15 @@ switch ($action) { case 'agent_module': $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter('module', ''); + $modules_to_report = get_parameter( + 'module', + '' + ); - $es['module'] = get_same_modules($agents_to_report, $modules_to_report); + $es['module'] = get_same_modules( + $agents_to_report, + $modules_to_report + ); $es['id_agents'] = $agents_to_report; $values['external_source'] = json_encode($es); @@ -1560,7 +2121,9 @@ switch ($action) { case 'inventory_changes': $values['period'] = get_parameter('period'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $values['external_source'] = json_encode($es); $good_format = true; break; @@ -1576,30 +2139,38 @@ switch ($action) { break; case 'netflow_area': - case 'netflow_pie': case 'netflow_data': - case 'netflow_statistics': case 'netflow_summary': - $values['text'] = get_parameter('netflow_filter'); - $values['description'] = get_parameter('description'); + $values['text'] = get_parameter( + 'netflow_filter' + ); + $values['description'] = get_parameter( + 'description' + ); $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('resolution'); - $values['top_n_value'] = get_parameter('max_values'); + $values['top_n_value'] = get_parameter( + 'max_values' + ); $good_format = true; break; case 'availability': $values['period'] = get_parameter('period'); // HACK it is saved in show_graph field. - // Show interfaces instead the modules - $values['show_graph'] = get_parameter('checkbox_show_address_agent'); + // Show interfaces instead the modules. + $values['show_graph'] = get_parameter( + 'checkbox_show_address_agent' + ); $good_format = true; break; case 'simple_graph': case 'simple_baseline_graph': // HACK it is saved in show_graph field. - $values['show_graph'] = (int) get_parameter('time_compare_overlapped'); + $values['show_graph'] = (int) get_parameter( + 'time_compare_overlapped' + ); $values['period'] = get_parameter('period'); $good_format = true; break; @@ -1608,18 +2179,37 @@ switch ($action) { case 'max_value': case 'avg_value': $values['period'] = get_parameter('period'); - $values['lapse_calc'] = get_parameter('lapse_calc'); + $values['lapse_calc'] = get_parameter( + 'lapse_calc' + ); $values['lapse'] = get_parameter('lapse'); - $values['visual_format'] = get_parameter('visual_format'); + $values['visual_format'] = get_parameter( + 'visual_format' + ); + $good_format = true; + break; + + case 'nt_top_n': + $values['top_n_value'] = get_parameter( + 'quantity' + ); + $values['period'] = get_parameter('period'); $good_format = true; break; default: $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; } @@ -1629,38 +2219,37 @@ switch ($action) { $values['server_name'] = get_parameter('server_name'); $server_id = (int) get_parameter('server_id'); if ($server_id != 0) { - $connection = metaconsole_get_connection_by_id($server_id); + $connection = metaconsole_get_connection_by_id( + $server_id + ); $values['server_name'] = $connection['server_name']; } if ($values['server_name'] == '') { - $values['server_name'] = get_parameter('combo_server'); + $values['server_name'] = get_parameter( + 'combo_server' + ); } $values['id_agent'] = get_parameter('id_agent'); $values['id_gs'] = get_parameter('id_custom_graph'); - if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent') or ($values['type'] == 'agent_configuration') or ($values['type'] == 'group_configuration')) { + if (($values['type'] == 'alert_report_agent') + || ($values['type'] == 'event_report_agent') + || ($values['type'] == 'agent_configuration') + || ($values['type'] == 'group_configuration') + ) { $values['id_agent_module'] = ''; } else { - $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['id_agent_module'] = get_parameter( + 'id_agent_module' + ); } - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $values['only_display_wrong'] = (int) get_parameter('checkbox_only_display_wrong', 0); - break; - - case 'oracle': - $only_display_wrong_tmp = get_parameter('checkbox_only_display_wrong'); - if (empty($only_display_wrong_tmp)) { - $values['only_display_wrong'] = 0; - } else { - $values['only_display_wrong'] = $only_display_wrong_tmp; - } - break; - } + $values['only_display_wrong'] = (int) get_parameter( + 'checkbox_only_display_wrong', + 0 + ); $values['monday'] = get_parameter('monday', 0); $values['tuesday'] = get_parameter('tuesday', 0); @@ -1669,53 +2258,133 @@ switch ($action) { $values['friday'] = get_parameter('friday', 0); $values['saturday'] = get_parameter('saturday', 0); $values['sunday'] = get_parameter('sunday', 0); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $values['time_from'] = get_parameter('time_from'); - $values['time_to'] = get_parameter('time_to'); - break; + $values['total_time'] = get_parameter('total_time', 0); + $values['time_failed'] = get_parameter( + 'time_failed', + 0 + ); + $values['time_in_ok_status'] = get_parameter( + 'time_in_ok_status', + 0 + ); + $values['time_in_unknown_status'] = get_parameter( + 'time_in_unknown_status', + 0 + ); + $values['time_of_not_initialized_module'] = get_parameter( + 'time_of_not_initialized_module', + 0 + ); + $values['time_of_downtime'] = get_parameter( + 'time_of_downtime', + 0 + ); + $values['total_checks'] = get_parameter( + 'total_checks', + 0 + ); + $values['checks_failed'] = get_parameter( + 'checks_failed', + 0 + ); + $values['checks_in_ok_status'] = get_parameter( + 'checks_in_ok_status', + 0 + ); + $values['unknown_checks'] = get_parameter( + 'unknown_checks', + 0 + ); + $values['agent_max_value'] = get_parameter( + 'agent_max_value', + 0 + ); + $values['agent_min_value'] = get_parameter( + 'agent_min_value', + 0 + ); - case 'oracle': - $values['time_from'] = '#to_date(\''.get_parameter('time_from').'\',\'hh24:mi:ss\')'; - $values['time_to'] = '#to_date(\''.get_parameter('time_to').'\', \'hh24:mi:ss\')'; - break; - } + $values['time_from'] = get_parameter( + 'time_from' + ); + $values['time_to'] = get_parameter('time_to'); - $values['group_by_agent'] = get_parameter('checkbox_row_group_by_agent', 0); - $values['show_resume'] = get_parameter('checkbox_show_resume', 0); - $values['order_uptodown'] = get_parameter('radiobutton_order_uptodown', 0); - $values['exception_condition'] = (int) get_parameter('radiobutton_exception_condition', 0); - $values['exception_condition_value'] = get_parameter('exception_condition_value'); - $values['id_module_group'] = get_parameter('combo_modulegroup'); + $values['group_by_agent'] = get_parameter( + 'checkbox_row_group_by_agent', + 0 + ); + $values['show_resume'] = get_parameter( + 'checkbox_show_resume', + 0 + ); + $values['order_uptodown'] = get_parameter( + 'radiobutton_order_uptodown', + 0 + ); + $values['exception_condition'] = (int) get_parameter( + 'radiobutton_exception_condition', + 0 + ); + $values['exception_condition_value'] = get_parameter( + 'exception_condition_value' + ); + $values['id_module_group'] = get_parameter( + 'combo_modulegroup' + ); $values['id_group'] = get_parameter('combo_group'); - if ((($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) && ($values['id_gs'] == 0 || $values['id_gs'] == '')) { + if ((($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph')) + && ($values['id_gs'] == 0 || $values['id_gs'] == '') + ) { $resultOperationDB = false; break; } - if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { - if (($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) { - $id_gs = substr($values['id_gs'], 0, strpos($values['id_gs'], '|')); + if ($config['metaconsole'] == 1 + && defined('METACONSOLE') + ) { + if (($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph') + ) { + $id_gs = substr( + $values['id_gs'], + 0, + strpos($values['id_gs'], '|') + ); if ($id_gs !== false && $id_gs !== '') { - $server_name = strstr($values['id_gs'], '|'); + $server_name = strstr( + $values['id_gs'], + '|' + ); $values['id_gs'] = $id_gs; - $values['server_name'] = substr($server_name, 1, strlen($server_name)); + $values['server_name'] = substr( + $server_name, + 1, + strlen($server_name) + ); } } } - if (($values['type'] == 'sql') or ($values['type'] == 'sql_graph_hbar') - or ($values['type'] == 'sql_graph_vbar') or ($values['type'] == 'sql_graph_pie') + if (($values['type'] == 'sql') + || ($values['type'] == 'sql_graph_hbar') + || ($values['type'] == 'sql_graph_vbar') + || ($values['type'] == 'sql_graph_pie') ) { - $values['treport_custom_sql_id'] = get_parameter('id_custom'); + $values['treport_custom_sql_id'] = get_parameter( + 'id_custom' + ); if ($values['treport_custom_sql_id'] == 0) { - $values['external_source'] = get_parameter('sql'); + $values['external_source'] = get_parameter( + 'sql' + ); } - $values['historical_db'] = get_parameter('historical_db_check'); + $values['historical_db'] = get_parameter( + 'historical_db_check' + ); $values['top_n_value'] = get_parameter('max_items'); } else if ($values['type'] == 'url') { $values['external_source'] = get_parameter('url'); @@ -1727,38 +2396,85 @@ switch ($action) { $values['column_separator'] = get_parameter('field'); $values['line_separator'] = get_parameter('line'); + $values['current_month'] = get_parameter('current_month'); + $style = []; - $style['show_in_same_row'] = get_parameter('show_in_same_row', 0); - $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); - $style['hide_notinit_agents'] = get_parameter('hide_notinit_agents', 0); - $style['priority_mode'] = get_parameter('priority_mode', REPORT_PRIORITY_MODE_OK); + $style['show_in_same_row'] = get_parameter( + 'show_in_same_row', + 0 + ); + $style['show_in_landscape'] = get_parameter( + 'show_in_landscape', + 0 + ); + $style['hide_notinit_agents'] = get_parameter( + 'hide_notinit_agents', + 0 + ); + $style['priority_mode'] = get_parameter( + 'priority_mode', + REPORT_PRIORITY_MODE_OK + ); $style['dyn_height'] = get_parameter('dyn_height', 230); switch ($values['type']) { case 'event_report_agent': case 'event_report_group': case 'event_report_module': - $show_summary_group = get_parameter('show_summary_group', 0); - $filter_event_severity = get_parameter('filter_event_severity', ''); - $filter_event_type = get_parameter('filter_event_type', ''); - $filter_event_status = get_parameter('filter_event_status', ''); + $show_summary_group = get_parameter( + 'show_summary_group', + 0 + ); + $filter_event_severity = get_parameter( + 'filter_event_severity', + '' + ); + $filter_event_type = get_parameter( + 'filter_event_type', + '' + ); + $filter_event_status = get_parameter( + 'filter_event_status', + '' + ); - $event_graph_by_agent = get_parameter('event_graph_by_agent', 0); - $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); - $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); - $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + $event_graph_by_agent = get_parameter( + 'event_graph_by_agent', + 0 + ); + $event_graph_by_user_validator = get_parameter( + 'event_graph_by_user_validator', + 0 + ); + $event_graph_by_criticity = get_parameter( + 'event_graph_by_criticity', + 0 + ); + $event_graph_validated_vs_unvalidated = get_parameter( + 'event_graph_validated_vs_unvalidated', + 0 + ); - $event_filter_search = get_parameter('filter_search', ''); + $event_filter_search = get_parameter( + 'filter_search', + '' + ); - // Added for events items - $style['show_summary_group'] = $show_summary_group; - $style['filter_event_severity'] = json_encode($filter_event_severity); - $style['filter_event_type'] = json_encode($filter_event_type); - $style['filter_event_status'] = json_encode($filter_event_status); + // Added for events items. + $style['show_summary_group'] = $show_summary_group; + $style['filter_event_severity'] = json_encode( + $filter_event_severity + ); + $style['filter_event_type'] = json_encode( + $filter_event_type + ); + $style['filter_event_status'] = json_encode( + $filter_event_status + ); - $style['event_graph_by_agent'] = $event_graph_by_agent; - $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; - $style['event_graph_by_criticity'] = $event_graph_by_criticity; + $style['event_graph_by_agent'] = $event_graph_by_agent; + $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; + $style['event_graph_by_criticity'] = $event_graph_by_criticity; $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; @@ -1772,14 +2488,23 @@ switch ($action) { $style['label'] = ''; } break; + + default: + // Default. + break; } break; case 'simple_graph': - // Warning. We are using this column to hold this value to avoid - // the modification of the database for compatibility reasons. - $style['percentil'] = (int) get_parameter('percentil'); - $style['fullscale'] = (int) get_parameter('fullscale'); + // Warning. We are using this column to hold + // this value to avoid the modification + // of the database for compatibility reasons. + $style['percentil'] = (int) get_parameter( + 'percentil' + ); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); if ($label != '') { $style['label'] = $label; } else { @@ -1788,7 +2513,9 @@ switch ($action) { break; case 'network_interfaces_report': - $style['fullscale'] = (int) get_parameter('fullscale'); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); break; case 'module_histogram_graph': @@ -1809,28 +2536,22 @@ switch ($action) { case 'MTBF': case 'MTTR': case 'simple_baseline_graph': + case 'nt_top_n': if ($label != '') { $style['label'] = $label; } else { $style['label'] = ''; } break; + + default: + // Default. + break; } $values['style'] = io_safe_input(json_encode($style)); if ($good_format) { - switch ($config['dbtype']) { - case 'oracle': - if (isset($values['type'])) { - $values[db_escape_key_identifier( - 'type' - )] = $values['type']; - unset($values['type']); - } - break; - } - $result = db_process_sql_insert( 'treport_content', $values @@ -1841,24 +2562,11 @@ switch ($action) { } else { $idItem = $result; - switch ($config['dbtype']) { - case 'mysql': - $max = db_get_all_rows_sql( - 'SELECT max(`order`) AS max - FROM treport_content - WHERE id_report = '.$idReport.';' - ); - break; - - case 'postgresql': - case 'oracle': - $max = db_get_all_rows_sql( - 'SELECT max("order") AS max - FROM treport_content - WHERE id_report = '.$idReport - ); - break; - } + $max = db_get_all_rows_sql( + 'SELECT max(`order`) AS max + FROM treport_content + WHERE id_report = '.$idReport.';' + ); if ($max === false) { $max = 0; @@ -1866,39 +2574,30 @@ switch ($action) { $max = $max[0]['max']; } - switch ($config['dbtype']) { - case 'mysql': - db_process_sql_update( - 'treport_content', - ['`order`' => ($max + 1)], - ['id_rc' => $idItem] - ); - break; - - case 'postgresql': - case 'oracle': - db_process_sql_update( - 'treport_content', - ['"order"' => ($max + 1)], - ['id_rc' => $idItem] - ); - break; - } + db_process_sql_update( + 'treport_content', + ['`order`' => ($max + 1)], + ['id_rc' => $idItem] + ); $resultOperationDB = true; } break; - } - // If fields dont have good format - else { + } else { + // If fields dont have good format. $resultOperationDB = false; } + break; + + default: + // Default. + break; } break; default: - if ($enterpriseEnable and $activeTab != 'advanced') { + if ($enterpriseEnable && $activeTab != 'advanced') { $resultOperationDB = reporting_enterprise_update_action(); } break; @@ -1928,20 +2627,35 @@ switch ($action) { $report = db_get_row_filter('treport', ['id_report' => $idReport]); $reportName = $report['name']; - $resultOperationDB = db_process_sql_delete('treport_content_sla_combined', ['id_report_content' => $idItem]); - $resultOperationDB2 = db_process_sql_delete('treport_content_item', ['id_report_content' => $idItem]); + $resultOperationDB = db_process_sql_delete( + 'treport_content_sla_combined', + ['id_report_content' => $idItem] + ); + $resultOperationDB2 = db_process_sql_delete( + 'treport_content_item', + ['id_report_content' => $idItem] + ); if ($resultOperationDB !== false) { - $resultOperationDB = db_process_sql_delete('treport_content', ['id_rc' => $idItem]); + $resultOperationDB = db_process_sql_delete( + 'treport_content', + ['id_rc' => $idItem] + ); } if ($resultOperationDB2 !== false) { - $resultOperationDB2 = db_process_sql_delete('treport_content', ['id_rc' => $idItem]); + $resultOperationDB2 = db_process_sql_delete( + 'treport_content', + ['id_rc' => $idItem] + ); } break; case 'order': $resultOperationDB = null; - $report = db_get_row_filter('treport', ['id_report' => $idReport]); + $report = db_get_row_filter( + 'treport', + ['id_report' => $idReport] + ); $reportName = $report['name']; $idGroupReport = $report['id_group']; @@ -1956,7 +2670,7 @@ switch ($action) { case 'agent': case 'type': - // Sort functionality for normal console + // Sort functionality for normal console. if (!defined('METACONSOLE')) { switch ($field) { case 'module': @@ -1990,6 +2704,10 @@ switch ($action) { case 'type': $sql = 'SELECT id_rc FROM treport_content WHERE %s ORDER BY type %s'; break; + + default: + // Default. + break; } $sql = sprintf($sql, 'id_report = '.$idReport, '%s'); @@ -2001,17 +2719,24 @@ switch ($action) { case 'down': $sql = sprintf($sql, 'DESC'); break; + + default: + // Default. + break; } $ids = db_get_all_rows_sql($sql); - } - // Sort functionality for metaconsole - else if ($config['metaconsole'] == 1) { + } else if ($config['metaconsole'] == 1) { + // Sort functionality for metaconsole. switch ($field) { case 'agent': case 'module': $sql = 'SELECT id_rc, id_agent, id_agent_module, server_name FROM treport_content WHERE %s ORDER BY server_name'; - $sql = sprintf($sql, 'id_report = '.$idReport, '%s'); + $sql = sprintf( + $sql, + 'id_report = '.$idReport, + '%s' + ); $report_items = db_get_all_rows_sql($sql); @@ -2021,34 +2746,47 @@ switch ($action) { if (!empty($report_items)) { foreach ($report_items as $report_item) { - $connection = metaconsole_get_connection($report_item['server_name']); + $connection = metaconsole_get_connection( + $report_item['server_name'] + ); if (metaconsole_load_external_db($connection) != NOERR) { - // ui_print_error_message ("Error connecting to ".$server_name); + continue; } switch ($field) { case 'agent': - $agents_name = agents_get_agents(['id_agente' => $report_item['id_agent']], 'nombre'); + $agents_name = agents_get_agents( + ['id_agente' => $report_item['id_agent']], + 'nombre' + ); - // Item without agent + // Item without agent. if (!$agents_name) { $element_name = ''; } else { - $agent_name = array_shift($agents_name); + $agent_name = array_shift( + $agents_name + ); $element_name = $agent_name['nombre']; } break; case 'module': - $module_name = modules_get_agentmodule_name($report_item['id_agent_module']); + $module_name = modules_get_agentmodule_name( + $report_item['id_agent_module'] + ); - // Item without module + // Item without module. if (!$module_name) { $element_name = ''; } else { $element_name = $module_name; } break; + + default: + // Default. + break; } metaconsole_restore_db(); @@ -2056,7 +2794,7 @@ switch ($action) { $temp_sort[$report_item['id_rc']] = $element_name; } - // Performes sorting + // Performes sorting. switch ($dir) { case 'up': asort($temp_sort); @@ -2065,6 +2803,10 @@ switch ($action) { case 'down': arsort($temp_sort); break; + + default: + // Default. + break; } foreach ($temp_sort as $temp_element_key => $temp_element_val) { @@ -2073,13 +2815,13 @@ switch ($action) { $i++; } - // Free resources + // Free resources. unset($temp_sort); unset($report_items); } break; - // Type case only depends of local database + // Type case only depends of local database. case 'type': $sql = 'SELECT id_rc FROM treport_content @@ -2098,10 +2840,17 @@ switch ($action) { case 'down': $sql = sprintf($sql, 'DESC'); break; + + default: + // Default. + break; } $ids = db_get_all_rows_sql($sql); + break; + default: + // Default. break; } } @@ -2109,40 +2858,28 @@ switch ($action) { $count = 1; $resultOperationDB = true; foreach ($ids as $id) { - $result = db_process_sql_update('treport_content', ['order' => $count], ['id_rc' => $id['id_rc']]); + $result = db_process_sql_update( + 'treport_content', + ['order' => $count], + ['id_rc' => $id['id_rc']] + ); if ($result === false) { $resultOperationDB = false; break; } - $count = ($count + 1); + $count++; } break; default: - switch ($config['dbtype']) { - case 'mysql': - $oldOrder = db_get_value_sql( - ' - SELECT `order` - FROM treport_content - WHERE id_rc = '.$idItem - ); - break; + $oldOrder = db_get_value_sql( + 'SELECT `order` + FROM treport_content + WHERE id_rc = '.$idItem + ); - case 'postgresql': - case 'oracle': - $oldOrder = db_get_value_sql( - ' - SELECT "order" - FROM treport_content - WHERE id_rc = '.$idItem - ); - break; - } - - // db_get_value_filter('order', 'treport_content', array('id_rc' => $idItem)); switch ($dir) { case 'up': $newOrder = ($oldOrder - 1); @@ -2151,79 +2888,34 @@ switch ($action) { case 'down': $newOrder = ($oldOrder + 1); break; - } - switch ($config['dbtype']) { - case 'mysql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['`order`' => $oldOrder], - [ - '`order`' => $newOrder, - 'id_report' => $idReport, - ] - ); - break; - - case 'postgresql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $oldOrder], - [ - '"order"' => $newOrder, - 'id_report' => $idReport, - ] - ); - break; - - case 'oracle': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $oldOrder], - [ - '"order"' => $newOrder, - 'id_report' => $idReport, - ], - 'AND', - false - ); + default: + // Default. break; } + $resultOperationDB = db_process_sql_update( + 'treport_content', + ['`order`' => $oldOrder], + [ + '`order`' => $newOrder, + 'id_report' => $idReport, + ] + ); + + if ($resultOperationDB !== false) { - switch ($config['dbtype']) { - case 'mysql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['`order`' => $newOrder], - ['id_rc' => $idItem] - ); - break; - - case 'postgresql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $newOrder], - ['id_rc' => $idItem] - ); - break; - - case 'oracle': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $newOrder], - ['id_rc' => $idItem], - 'AND', - false - ); - break; - } + $resultOperationDB = db_process_sql_update( + 'treport_content', + ['`order`' => $newOrder], + ['id_rc' => $idItem] + ); } break; } break; - // Added for report templates + // Added for report templates. default: if ($enterpriseEnable) { $buttons = [ @@ -2236,6 +2928,7 @@ switch ($action) { $buttons = reporting_enterprise_add_main_Tabs($buttons); $subsection = ''; + $helpers = ''; switch ($activeTab) { case 'main': $buttons['list_reports']['active'] = true; @@ -2243,13 +2936,20 @@ switch ($action) { break; default: - $subsection = reporting_enterprise_add_subsection_main($activeTab, $buttons); + $data_tab = reporting_enterprise_add_subsection_main( + $activeTab, + $buttons + ); + + $subsection = $data_tab['subsection']; + $buttons = $data_tab['buttons']; + $helpers = $data_tab['helper']; break; } - // Page header for metaconsole - if ($enterpriseEnable and defined('METACONSOLE')) { - // Bread crumbs + // Page header for metaconsole. + if ($enterpriseEnable && defined('METACONSOLE')) { + // Bread crumbs. ui_meta_add_breadcrumb( [ 'link' => 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&pure='.$pure, @@ -2259,14 +2959,22 @@ switch ($action) { ui_meta_print_page_header($nav_bar); - // Print header + // Print header. ui_meta_print_header(__('Reporting'), '', $buttons); + } else { + // Page header for normal console. + ui_print_page_header( + $subsection, + 'images/op_reporting.png', + false, + '', + false, + $buttons, + false, + '', + 60 + ); } - // Page header for normal console - else { - ui_print_page_header($subsection, 'images/op_reporting.png', false, '', false, $buttons, false, '', 60); - } - reporting_enterprise_select_main_tab($action); } @@ -2301,7 +3009,10 @@ $buttons = [ ]; if ($enterpriseEnable) { - $buttons = reporting_enterprise_add_Tabs($buttons, $idReport); + $buttons = reporting_enterprise_add_Tabs( + $buttons, + $idReport + ); } $buttons['view'] = [ @@ -2325,9 +3036,9 @@ if ($idReport != 0) { $textReportName = __('Create Custom Report'); } -// Page header for metaconsole -if ($enterpriseEnable and defined('METACONSOLE')) { - // Bread crumbs +// Page header for metaconsole. +if ($enterpriseEnable && defined('METACONSOLE')) { + // Bread crumbs. ui_meta_add_breadcrumb( [ 'link' => 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&pure='.$pure, @@ -2337,14 +3048,24 @@ if ($enterpriseEnable and defined('METACONSOLE')) { ui_meta_print_page_header($nav_bar); - // Print header + // Print header. ui_meta_print_header(__('Reporting').$textReportName, '', $buttons); } else { + switch ($activeTab) { + case 'main': + $helpers = ''; + break; + + default: + $helpers = 'reporting_'.$activeTab.'_tab'; + break; + } + ui_print_page_header( $textReportName, 'images/op_reporting.png', false, - 'reporting_'.$activeTab.'_tab', + $helpers, false, $buttons, false, @@ -2367,7 +3088,11 @@ if ($resultOperationDB !== null) { break; } - ui_print_result_message($resultOperationDB, __('Successfull action'), __('Unsuccessful action

'.$err)); + ui_print_result_message( + $resultOperationDB, + __('Successfull action'), + __('Unsuccessful action

'.$err) + ); } switch ($activeTab) { diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index e5f1377be1..85cbd9be5e 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -1,3 +1,5 @@ +/* globals $ */ + // Pandora FMS - http://pandorafms.com // ================================================== // Copyright (c) 2005-2009 Artica Soluciones Tecnologicas @@ -31,6 +33,8 @@ var SIZE_GRID = 16; //Const the size (for width and height) of grid. var img_handler_start; var img_handler_end; +var default_cache_expiration = null; + function toggle_advance_options_palette(close) { if ($("#advance_options").css("display") == "none") { $("#advance_options").css("display", ""); @@ -679,12 +683,17 @@ function update_button_palette_callback() { return false; } } - if (values["module"] == 0) { + var radio_value = $("input[name='radio_choice']:checked").val(); + if (values["agent"] == "" && radio_value == "module_graph") { + dialog_message("#message_alert_no_agent"); + return false; + } + if (values["module"] == 0 && radio_value == "module_graph") { dialog_message("#message_alert_no_module"); return false; } - if (values["agent"] == "") { - dialog_message("#message_alert_no_agent"); + if (values["id_custom_graph"] == 0 && radio_value == "custom_graph") { + dialog_message("#message_alert_no_custom_graph"); return false; } if ($("input[name=width_module_graph]").val() == "") { @@ -1095,10 +1104,11 @@ function readFields() { var text = tinymce.get("text-label").getContent(); values["label"] = text; + values["percentile_label_color"] = $( + "input[name=percentile_label_color]" + ).val(); + if ($("input[name=percentile_label]").val().length > 0) { - values["percentile_label_color"] = $( - "input[name=percentile_label_color]" - ).val(); values["label"] = " __('View')]).''; -} - -$user_groups_w = users_get_groups(false, 'PM', true, false, null, 'id_grupo'); -$user_groups_w = array_keys($user_groups_w); - -$user_groups_r = users_get_groups(false, 'AW', true, false, null, 'id_grupo'); -$user_groups_r = array_keys($user_groups_r); - -// Headers. -ui_print_page_header( - __('Manage recontask'), - 'images/gm_servers.png', - false, - '', - true, - $options -); - - -// -------------------------------- -// DELETE A RECON TASKs. -// -------------------------------- -if (isset($_GET['delete'])) { - $id = get_parameter_get('delete'); - - $result = db_process_sql_delete('trecon_task', ['id_rt' => $id]); - - if ($result !== false) { - ui_print_success_message(__('Successfully deleted recon task')); - } else { - ui_print_error_message(__('Error deleting recon task')); - } -} else if (isset($_GET['disabled'])) { - $id = get_parameter_get('id'); - $disabled = get_parameter_get('disabled'); - - $result = db_process_sql_update( - 'trecon_task', - ['disabled' => $disabled], - ['id_rt' => $id] - ); - - if ($result !== false) { - ui_print_success_message(__('Successfully updated recon task')); - // If the action is enabled, we force recon_task to be queued asap. - if ($disabled == 0) { - servers_force_recon_task($id); - } - } else { - ui_print_error_message(__('Error updating recon task')); - } -} - -// -------------------------------- -// GET PARAMETERS IF UPDATE OR CREATE. -// -------------------------------- -if ((isset($_GET['update'])) || ((isset($_GET['create'])))) { - $name = get_parameter_post('name'); - $network = get_parameter_post('network'); - $description = get_parameter_post('description'); - $id_recon_server = get_parameter_post('id_recon_server'); - $interval = get_parameter_post('interval'); - $id_group = get_parameter_post('id_group'); - $create_incident = get_parameter_post('create_incident'); - $id_network_profile = get_parameter_post('id_network_profile'); - $recon_ports = get_parameter_post('recon_ports', ''); - $id_os = get_parameter_post('id_os', 10); - $snmp_community = get_parameter_post('snmp_community', 'public'); - $id_recon_script = get_parameter('id_recon_script', 0); - $mode = get_parameter('mode', ''); - $field1 = get_parameter('_field1_', ''); - $field2 = get_parameter('_field2_', ''); - $field3 = get_parameter('_field3_', ''); - $field4 = get_parameter('_field4_', ''); - $snmp_version = get_parameter_post('snmp_version'); - $snmp3_auth_user = get_parameter_post('snmp_auth_user'); - $snmp3_auth_pass = get_parameter_post('snmp_auth_pass'); - $snmp3_privacy_method = get_parameter_post('snmp_privacy_method'); - $snmp3_privacy_pass = get_parameter_post('snmp_privacy_pass'); - $snmp3_auth_method = get_parameter_post('snmp_auth_method'); - $snmp3_security_level = get_parameter_post('snmp_security_level'); - - - if ($mode == 'network_sweep') { - $id_recon_script = 0; - } else { - $id_network_profile = 0; - } - - $os_detect = (int) get_parameter('os_detect', 0); - $resolve_names = (int) get_parameter('resolve_names', 0); - $parent_detection = (int) get_parameter('parent_detection', 0); - $parent_recursion = (int) get_parameter('parent_recursion', 1); - $alias_as_name = (int) get_parameter('alias_as_name', 0); - $snmp_enabled = (int) get_parameter('snmp_enabled', 0); - $vlan_enabled = (int) get_parameter('vlan_enabled', 0); - // Get macros. - $macros = (string) get_parameter('macros'); - - if (!empty($macros)) { - $macros = json_decode(base64_decode($macros), true); - - if (isset($macros) === true && is_array($macros) === true) { - foreach ($macros as $k => $m) { - $macros[$k]['value'] = get_parameter($m['macro'], ''); - } - } - } - - $macros = io_json_mb_encode($macros); -} - -// -------------------------------- -// UPDATE A RECON TASK. -// -------------------------------- -if (isset($_GET['update'])) { - $id = get_parameter_get('update'); - - $values = [ - 'snmp_community' => $snmp_community, - 'id_os' => $id_os, - 'name' => $name, - 'subnet' => $network, - 'description' => $description, - 'id_recon_server' => $id_recon_server, - 'create_incident' => $create_incident, - 'id_group' => $id_group, - 'interval_sweep' => $interval, - 'id_network_profile' => $id_network_profile, - 'recon_ports' => $recon_ports, - 'id_recon_script' => $id_recon_script, - 'field1' => $field1, - 'field2' => $field2, - 'field3' => $field3, - 'field4' => $field4, - 'os_detect' => $os_detect, - 'resolve_names' => $resolve_names, - 'parent_detection' => $parent_detection, - 'parent_recursion' => $parent_recursion, - 'macros' => $macros, - 'alias_as_name' => $alias_as_name, - 'snmp_enabled' => $snmp_enabled, - 'vlan_enabled' => $vlan_enabled, - 'snmp_version' => $snmp_version, - ]; - - $values_v3 = [ - 'snmp_auth_user' => $snmp3_auth_user, - 'snmp_auth_pass' => $snmp3_auth_pass, - 'snmp_privacy_method' => $snmp3_privacy_method, - 'snmp_privacy_pass' => $snmp3_privacy_pass, - 'snmp_auth_method' => $snmp3_auth_method, - 'snmp_security_level' => $snmp3_security_level, - ]; - if ($values['snmp_version'] == '1' || $values['snmp_version'] == '2' || $values['snmp_version'] == '2c') { - $values_v3 = [ - 'snmp_auth_user' => '', - 'snmp_auth_pass' => '', - 'snmp_privacy_method' => '', - 'snmp_privacy_pass' => '', - 'snmp_auth_method' => '', - 'snmp_security_level' => '', - ]; - } - - $values = array_merge($values, $values_v3); - - $where = ['id_rt' => $id]; - - $reason = ''; - if ($name != '') { - if (empty($id_recon_script)) { - if (!preg_match('/[0-9]+.+[0-9]+.+[0-9]+.+[0-9]+\/+[0-9]/', $network)) { - $reason = __('Wrong format in Subnet field'); - $result = false; - } else { - $result = db_process_sql_update( - 'trecon_task', - $values, - $where - ); - } - } else { - $result = db_process_sql_update( - 'trecon_task', - $values, - $where - ); - } - } else { - $result = false; - } - - if ($result !== false) { - ui_print_success_message(__('Successfully updated recon task')); - } else { - ui_print_error_message(__('Error updating recon task')); - echo $reason; - include 'manage_recontask_form.php'; - return; - } -} - -// -------------------------------- -// CREATE A RECON TASK -// -------------------------------- -if (isset($_GET['create'])) { - $values = [ - 'name' => $name, - 'subnet' => $network, - 'description' => $description, - 'id_recon_server' => $id_recon_server, - 'create_incident' => $create_incident, - 'id_group' => $id_group, - 'id_network_profile' => $id_network_profile, - 'interval_sweep' => $interval, - 'id_os' => $id_os, - 'recon_ports' => $recon_ports, - 'snmp_community' => $snmp_community, - 'id_recon_script' => $id_recon_script, - 'field1' => $field1, - 'field2' => $field2, - 'field3' => $field3, - 'field4' => $field4, - 'os_detect' => $os_detect, - 'resolve_names' => $resolve_names, - 'parent_detection' => $parent_detection, - 'parent_recursion' => $parent_recursion, - 'macros' => $macros, - 'alias_as_name' => $alias_as_name, - 'snmp_enabled' => $snmp_enabled, - 'vlan_enabled' => $vlan_enabled, - 'snmp_version' => $snmp_version, - ]; - - $values_v3 = [ - 'snmp_auth_user' => $snmp3_auth_user, - 'snmp_auth_pass' => $snmp3_auth_pass, - 'snmp_privacy_method' => $snmp3_privacy_method, - 'snmp_privacy_pass' => $snmp3_privacy_pass, - 'snmp_auth_method' => $snmp3_auth_method, - 'snmp_security_level' => $snmp3_security_level, - ]; - if ($values['snmp_version'] == '1' || $values['snmp_version'] == '2' || $values['snmp_version'] == '2c') { - $values_v3 = [ - 'snmp_auth_user' => '', - 'snmp_auth_pass' => '', - 'snmp_privacy_method' => '', - 'snmp_privacy_pass' => '', - 'snmp_auth_method' => '', - 'snmp_security_level' => '', - ]; - } - - if ($values['snmp_version'] == '3') { - $values['vlan_enabled'] = 0; - } - - $values = array_merge($values, $values_v3); - - $name = io_safe_output($name); - $name = trim($name, ' '); - $name = io_safe_input($name); - $reason = ''; - - if ($name != '') { - $name_exists = (bool) db_get_value('name', 'trecon_task', 'name', $name); - - if (empty($id_recon_script)) { - if ($name_exists && (!preg_match('/[0-9]+.+[0-9]+.+[0-9]+.+[0-9]+\/+[0-9]/', $network))) { - $reason = __('Recon-task name already exists and incorrect format in Subnet field'); - $result = false; - } else if (!preg_match('/[0-9]+.+[0-9]+.+[0-9]+.+[0-9]+\/+[0-9]/', $network)) { - $reason = __('Wrong format in Subnet field'); - $result = false; - } else if ($name_exists) { - $reason = __('Recon-task name already exists'); - $result = false; - } else { - $result = db_process_sql_insert('trecon_task', $values); - } - } else { - if ($name_exists) { - $reason = __('Recon-task name already exists'); - $result = false; - } else { - $result = db_process_sql_insert('trecon_task', $values); - } - } - } else { - $reason = 'The field "Task name" is empty'; - $result = false; - } - - if ($result !== false) { - ui_print_success_message(__('Successfully created recon task')); - } else { - ui_print_error_message(__('Error creating recon task')); - echo $reason; - include 'manage_recontask_form.php'; - return; - } -} - -// -------------------------------- -// SHOW TABLE WITH ALL RECON TASKs. -// -------------------------------- -// Pandora Admin must see all columns. -if (! check_acl($config['id_user'], 0, 'PM')) { - $sql = sprintf( - 'SELECT * - FROM trecon_task RT, tusuario_perfil UP - WHERE - UP.id_usuario = "%s" AND UP.id_grupo = RT.id_group', - $config['id_user'] - ); - - $result = db_get_all_rows_sql($sql); -} else { - $result = db_get_all_rows_in_table('trecon_task'); -} - -$color = 1; -if ($result !== false) { - $table = new StdClass(); - $table->head = [ - __('Name'), - __('Network'), - __('Mode'), - __('Group'), - __('SNMP Version'), - __('Incident'), - __('OS'), - __('Interval'), - __('Ports'), - __('Action'), - ]; - $table->align = [ - 'left', - 'left', - 'left', - 'left', - 'left', - 'left', - 'left', - 'left', - ]; - $table->width = '100%'; - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->class = 'databox data'; - $table->data = []; - - $table->style[8] = 'text-align: left;'; - $table->size[8] = '15%'; - - foreach ($result as $row) { - if (in_array($row['id_group'], $user_groups_r)) { - $data = []; - $data[0] = $row['name']; - if ($row['id_recon_script'] == 0) { - $data[1] = $row['subnet']; - } else { - $data[1] = '-'; - } - - - if ($row['id_recon_script'] == 0) { - // Network recon task. - $data[2] = html_print_image('images/network.png', true, ['title' => __('Network recon task')]).'  '; - $data[2] .= network_profiles_get_name($row['id_network_profile']); - $mode_name = ''; - } else { - // APP recon task. - $data[2] = html_print_image('images/plugin.png', true).'  '; - $mode_name = db_get_sql(sprintf('SELECT name FROM trecon_script WHERE id_recon_script = %d', $row['id_recon_script'])); - $data[2] .= $mode_name; - } - - - // GROUP. - if ($row['id_recon_script'] == 0) { - $data[3] = ui_print_group_icon($row['id_group'], true); - } else { - $data[3] = '-'; - } - - // SNMP VERSION. - if ($row['snmp_version'] == '1') { - $data[4] = 'v. 1'; - } else if ($row['snmp_version'] == '2') { - $data[4] = 'v. 2'; - } else if ($row['snmp_version'] == '2c') { - $data[4] = 'v. 2c'; - } else if ($row['snmp_version'] == '3') { - $data[4] = 'v. 3'; - } - - - - // INCIDENT. - $data[5] = (($row['create_incident'] == 1) ? __('Yes') : __('No')); - - // OS. - if ($row['id_recon_script'] == 0) { - $data[6] = (($row['id_os'] > 0) ? ui_print_os_icon($row['id_os'], false, true) : __('Any')); - } else { - $data[6] = '-'; - } - - // INTERVAL. - if ($row['interval_sweep'] == 0) { - $data[7] = __('Manual'); - } else { - $data[7] = human_time_description_raw($row['interval_sweep']); - } - - // PORTS. - if ($row['id_recon_script'] == 0) { - $data[8] = substr($row['recon_ports'], 0, 15); - } else { - $data[8] = '-'; - } - - // ACTION. - $task_group = $row['id_group']; - - if (in_array($task_group, $user_groups_w)) { - $data[9] = ''.html_print_image('images/eye.png', true).''; - $data[9] .= ''.html_print_image('images/cross.png', true, ['border' => '0']).''; - if ($mode_name != 'IPAM Recon') { - $data[9] .= ''.html_print_image('images/config.png', true).''; - } else { - $sql_ipam = 'select id from tipam_network where id_recon_task ='.$row['id_rt']; - $id_recon_ipam = db_get_sql($sql_ipam); - $data[9] .= ''.html_print_image('images/config.png', true).''; - } - - if ($row['disabled'] == 0) { - $data[9] .= ''.html_print_image('images/lightbulb.png', true).''; - } else { - $data[9] .= ''.html_print_image('images/lightbulb_off.png', true).''; - } - } - - $table->data[] = $data; - } - } - - html_print_table($table); - unset($table); -} else { - echo '
'.__('There are no recon task configured').'
'; -} - -echo '
'; -echo '
'; -echo html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"', true); -echo '
'; -echo '
'; diff --git a/pandora_console/godmode/servers/manage_recontask_form.php b/pandora_console/godmode/servers/manage_recontask_form.php index 0a5967c784..cf95cc76e6 100644 --- a/pandora_console/godmode/servers/manage_recontask_form.php +++ b/pandora_console/godmode/servers/manage_recontask_form.php @@ -1,11 +1,10 @@ '; - echo __('Warning').': '.__('By default, in Windows, %s only support Standard network sweep, not custom scripts', get_product_name()); - echo '
'; -} - -$table = new stdClass(); -$table->id = 'table_recon'; -$table->width = '100%'; -$table->cellspacing = 4; -$table->cellpadding = 4; -$table->class = 'databox filters'; - -$table->rowclass[3] = 'network_sweep'; -$table->rowclass[5] = 'network_sweep'; -$table->rowclass[7] = 'network_sweep'; -$table->rowclass[8] = 'network_sweep'; -$table->rowclass[11] = 'network_sweep'; -$table->rowclass[12] = 'network_sweep'; -$table->rowclass[18] = 'network_sweep'; -$table->rowclass[19] = 'network_sweep'; -$table->rowclass[20] = 'network_sweep'; -$table->rowclass[21] = 'network_sweep'; -$table->rowclass[22] = 'network_sweep'; -$table->rowclass[23] = 'network_sweep'; -$table->rowclass[24] = 'network_sweep'; -$table->rowclass[25] = 'network_sweep recon_v3'; -$table->rowclass[26] = 'network_sweep recon_v3'; -$table->rowclass[27] = 'network_sweep recon_v3'; -$table->rowclass[28] = 'network_sweep recon_v3'; -$table->rowclass[29] = 'network_sweep recon_v3'; -$table->rowclass[30] = 'network_sweep recon_v3'; - -$table->rowclass[6] = 'recon_script'; -$table->rowclass[13] = 'recon_script'; -$table->rowclass[14] = 'recon_script'; -$table->rowclass[15] = 'recon_script'; -$table->rowclass[16] = 'recon_script'; -$table->rowclass[17] = 'recon_script'; -// Name. -$table->data[0][0] = ''.__('Task name').''; -$table->data[0][1] = html_print_input_text('name', $name, '', 25, 0, true); - -// Discovery server. -$table->data[1][0] = ''.__('Discovery server').ui_print_help_tip( - __('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), - true -); - -$sql = 'SELECT id_server, name - FROM tserver - WHERE server_type = 3 - ORDER BY name'; -$table->data[1][1] = html_print_select_from_sql( - $sql, - 'id_recon_server', - $id_recon_server, - '', - '', - '', - true -); - -$fields['network_sweep'] = __('Network sweep'); -if (!$is_windows) { - $fields['recon_script'] = __('Custom script'); -} - - -$table->data[2][0] = ''.__('Mode').''; -$table->data[2][1] = html_print_select( - $fields, - 'mode', - $mode, - '', - '', - 0, - true -); - - -// Network. -$table->data[3][0] = ''.__('Network').''; -$table->data[3][0] .= ui_print_help_tip( - __('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), - true -); -$table->data[3][1] = html_print_input_text( - 'network', - $network, - '', - 25, - 0, - true -); - -// Interval. -$interv_manual = 0; -if ((int) $interval == 0) { - $interv_manual = 1; -} - -$table->data[4][0] = ''.__('Interval'); -$table->data[4][0] .= ui_print_help_tip( - __('Manual interval means that it will be executed only On-demand'), - true -); - -$values = [ - 0 => __('Defined'), - 1 => __('Manual'), -]; -$table->data[4][1] = html_print_select( - $values, - 'interval_manual_defined', - $interv_manual, - '', - '', - '', - true -); - -$table->data[4][1] .= ''; -$table->data[4][1] .= html_print_extended_select_for_time( - 'interval', - $interval, - '', - '', - '0', - false, - true, - false, - false -); -$table->data[4][1] .= ui_print_help_tip( - __('The minimum recomended interval for Recon Task is 5 minutes'), - true -); -$table->data[4][1] .= ''; - - -// Module template. -$table->data[5][0] = ''.__('Module template').''; - -$sql = 'SELECT id_np, name - FROM tnetwork_profile - ORDER BY name'; -$table->data[5][1] = html_print_select_from_sql( - $sql, - 'id_network_profile', - $id_network_profile, - '', - __('None'), - 0, - true -); - -// Recon script. -$data[1] = ''; -$table->data[6][0] = ''.__('Recon script').''; - - -$sql = "SELECT id_recon_script, name - FROM trecon_script - WHERE name <> 'IPAM Recon' - ORDER BY name"; -if ($name_script != 'IPAM Recon') { - $table->data[6][1] = html_print_select_from_sql( - $sql, - 'id_recon_script', - $id_recon_script, - '', - '', - '', - true - ); - $table->data[6][1] .= "'; - $table->data[6][1] .= $data[1] .= html_print_input_hidden( - 'macros', - base64_encode($macros), - true - ); -} else { - $table->data[6][1] = 'IPAM Recon'; -} - -// OS. -$table->data[7][0] = ''.__('OS').''; - -$sql = 'SELECT id_os, name - FROM tconfig_os - ORDER BY name'; -$table->data[7][1] = html_print_select_from_sql( - $sql, - 'id_os', - $id_os, - '', - __('Any'), - -1, - true -); - -// Recon ports. -$table->data[8][0] = ''.__('Ports').''; -$table->data[8][1] = html_print_input_text( - 'recon_ports', - $recon_ports, - '', - 25, - 0, - true -); -$table->data[8][1] .= ui_print_help_tip( - __('Ports defined like: 80 or 80,443,512 or even 0-1024 (Like Nmap command line format). If dont want to do a sweep using portscan, left it in blank'), - true -); - -// Group. -$table->data[9][0] = ''.__('Group'); -$groups = users_get_groups(false, 'PM', false); -$table->data[9][1] = html_print_select_groups( - false, - 'PM', - false, - 'id_group', - $id_group, - '', - '', - 0, - true -); - -// Incident. -$values = [ - 0 => __('No'), - 1 => __('Yes'), -]; -$table->data[10][0] = ''.__('Incident'); -$table->data[10][1] = html_print_select( - $values, - 'create_incident', - $create_incident, - '', - '', - '', - true -).' '.ui_print_help_tip( - __('Choose if the discovery of a new system creates an incident or not.'), - true -); - -// Snmp_enabled. -$table->data[11][0] = ''.__('SNMP enabled'); -$table->data[11][1] = html_print_checkbox( - 'snmp_enabled', - 1, - $snmp_enabled, - true -); - -// SNMP default community. -$table->data[12][0] = ''.__('SNMP Default community'); -$table->data[12][0] .= ui_print_help_tip( - __('You can specify several values, separated by commas, for example: public,mysecret,1234'), - true -); -$table->data[12][1] = html_print_input_text( - 'snmp_community', - $snmp_community, - '', - 35, - 0, - true -); - -// SNMP version. -$snmp_versions['1'] = 'v. 1'; -$snmp_versions['2'] = 'v. 2'; -$snmp_versions['2c'] = 'v. 2c'; -$snmp_versions['3'] = 'v. 3'; -$table->data[24][0] = ''._('SNMP version'); -$table->data[24][1] = html_print_select( - $snmp_versions, - 'snmp_version', - $snmp_version, - '', - '', - 0, - true -); - -$table->data[25][0] = ''.__('Auth user'); -$table->data[25][1] = html_print_input_text( - 'snmp_auth_user', - $snmp3_auth_user, - '', - 15, - 60, - true, - '', - false, - '', - '' -); -$table->data[26][0] = ''.__('Auth password').ui_print_help_tip(__('The pass length must be eight character minimum.'), true); -$table->data[26][1] = html_print_input_password( - 'snmp_auth_pass', - $snmp3_auth_pass, - '', - 15, - 60, - true, - '', - false, - '' -); -$table->data[26][1] .= html_print_input_hidden_extended( - 'active_snmp_v3', - 0, - 'active_snmp_v3_mmen', - true -); - -$table->data[27][0] = ''.__('Privacy method'); -$table->data[27][1] = html_print_select( - [ - 'DES' => __('DES'), - 'AES' => __('AES'), - ], - 'snmp_privacy_method', - $snmp3_privacy_method, - '', - '', - '', - true, - false, - false, - '', - '' -); -$table->data[28][0] = ''.__('Privacy pass').ui_print_help_tip(__('The pass length must be eight character minimum.'), true); -$table->data[28][1] = html_print_input_password( - 'snmp_privacy_pass', - $snmp3_privacy_pass, - '', - 15, - 60, - true, - '', - false, - '' -); -$table->data[29][0] = ''.__('Auth method'); -$table->data[29][1] = html_print_select( - [ - 'MD5' => __('MD5'), - 'SHA' => __('SHA'), - ], - 'snmp_auth_method', - $snmp3_auth_method, - '', - '', - '', - true, - false, - false, - '', - '' -); -$table->data[30][0] = ''.__('Security level'); -$table->data[30][1] = html_print_select( - [ - 'noAuthNoPriv' => __('Not auth and not privacy method'), - 'authNoPriv' => __('Auth and not privacy method'), - 'authPriv' => __('Auth and privacy method'), - ], - 'snmp_security_level', - $snmp3_security_level, - '', - '', - '', - true, - false, - false, - '', - '' -); - -// Explanation. -$explanation = db_get_value( - 'description', - 'trecon_script', - 'id_recon_script', - $id_recon_script -); - -$table->data[13][0] = ''.__('Explanation').''; -$table->data[13][1] = "'.html_print_textarea('explanation', 4, 60, $explanation, 'style="width: 388px;"', true); - -// A hidden "model row" to clone it from javascript to add fields dynamicaly. -$data = []; -$data[0] = 'macro_desc'; -$data[0] .= ui_print_help_tip('macro_help', true); -$data[1] = html_print_input_text( - 'macro_name', - 'macro_value', - '', - 100, - 255, - true -); -$table->colspan['macro_field'][1] = 3; -$table->rowstyle['macro_field'] = 'display:none'; -$table->data['macro_field'] = $data; - -// If there are $macros, we create the form fields. -if (!empty($macros)) { - $macros = json_decode($macros, true); - - if (isset($macros) === true - && is_array($macros) === true - ) { - foreach ($macros as $k => $m) { - $data = []; - $data[0] = ''.$m['desc'].''; - if (!empty($m['help'])) { - $data[0] .= ui_print_help_tip($m['help'], true); - } - - if ($m['hide']) { - $data[1] = html_print_input_password( - $m['macro'], - $m['value'], - '', - 100, - 255, - true - ); - } else { - $data[1] = html_print_input_text( - $m['macro'], - $m['value'], - '', - 100, - 255, - true - ); - } - - $table->colspan['macro'.$m['macro']][1] = 3; - $table->rowclass['macro'.$m['macro']] = 'macro_field'; - - $table->data['macro'.$m['macro']] = $data; - } - } -} - -// Comments. -$table->data[18][0] = ''.__('Comments'); -$table->data[18][1] = html_print_input_text( - 'description', - $description, - '', - 45, - 0, - true -); - -// OS detection. -$table->data[19][0] = ''.__('OS detection'); -$table->data[19][1] = html_print_checkbox( - 'os_detect', - 1, - $os_detect, - true -); - -// Name resolution. -$table->data[20][0] = ''.__('Name resolution'); -$table->data[20][1] = html_print_checkbox( - 'resolve_names', - 1, - $resolve_names, - true -); - -// Parent detection. -$table->data[21][0] = ''.__('Parent detection'); -$table->data[21][1] = html_print_checkbox( - 'parent_detection', - 1, - $parent_detection, - true -); - -// Parent recursion. -$table->data[22][0] = ''.__('Parent recursion'); -$table->data[22][1] = html_print_input_text( - 'parent_recursion', - $parent_recursion, - '', - 5, - 0, - true -).ui_print_help_tip( - __('Maximum number of parent hosts that will be created if parent detection is enabled.'), - true -); - -// Vlan_enabled. -$table->data[23][0] = ''.__('Vlan enabled'); -$table->data[23][1] = html_print_checkbox( - 'vlan_enabled', - 1, - $vlan_enabled, - true -); - -// NOTE: The 7.0NG Recon Server will not generate random names, since IP -// address collisions could have other consequences. -// Different Form url if it's a create or if it's a update form. -echo '
'; -html_print_table($table); -echo '
'; - -if ($id_rt != -1) { - if ($name_script != 'IPAM Recon') { - html_print_submit_button(__('Update'), 'crt', false, 'class="sub upd"'); - } -} else { - html_print_submit_button(__('Add'), 'crt', false, 'class="sub wand"'); -} - -echo '
'; - -echo '
'; - -ui_require_javascript_file('pandora_modules'); - -?> - - diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index b04643e1c3..57fa1a1e67 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -242,7 +242,6 @@ if ($filemanager) { $chunck_url = '&create=1'; } - $homedir_filemanager = isset($config['homedir_filemanager']) ? $config['homedir_filemanager'] : false; filemanager_file_explorer( $real_directory, $directory, @@ -253,7 +252,7 @@ if ($filemanager) { 'index.php?sec=gservers&sec2=godmode/servers/plugin'.$chunck_url.'&plugin_command=[FILE_FULLPATH]&id_plugin='.$id_plugin, true, 0775, - $homedir_filemanager + false ); } @@ -404,7 +403,7 @@ if (($create != '') || ($view != '')) { $table->data['plugin_command'] = $data; $data = []; - $data[0] = __('Plug-in parameters').ui_print_help_icon('plugin_parameters', true); + $data[0] = __('Plug-in parameters'); $data[1] = ''; if ($locked) { $data[1] .= html_print_image('images/lock.png', true, ['class' => 'command_advanced_conf lock']); @@ -550,7 +549,7 @@ if (($create != '') || ($view != '')) { $table->headstyle[0] = 'text-align: center'; html_print_table($table); } else { - echo '
'.''.__('Parameters macros').ui_print_help_icon('macros', true).''; + echo '
'.''.__('Parameters macros').''; html_print_table($table); echo '
'; } @@ -613,7 +612,16 @@ if (($create != '') || ($view != '')) { config_update_value('metaconsole_deploy_plugin_server', 1); } } else { - ui_print_page_header(__('Plug-ins registered on %s', get_product_name()), 'images/gm_servers.png', false, '', true); + ui_print_page_header( + __( + 'Plug-ins registered on %s', + get_product_name() + ), + 'images/gm_servers.png', + false, + '', + true + ); $management_allowed = !is_central_policies_on_node(); if (!$management_allowed) { @@ -954,9 +962,10 @@ if (($create != '') || ($view != '')) { if (defined('METACONSOLE')) { echo ''; } else { - echo '
'; + echo '
'; } + echo ''; echo ''; echo ''; echo ''; @@ -964,6 +973,8 @@ if (($create != '') || ($view != '')) { echo "'; } + echo ''; + $color = 0; foreach ($rows as $row) { @@ -1187,13 +1198,13 @@ ui_require_javascript_file('pandora_modules'); } } else { - alert(''); + alert(""); } } } var macros_click_locked_event = function (event) { - alert(''); + alert(""); } if (locked) { @@ -1202,4 +1213,6 @@ ui_require_javascript_file('pandora_modules'); $('.command_macro').click(macros_click_locked_event); } + + diff --git a/pandora_console/godmode/servers/recon_script.php b/pandora_console/godmode/servers/recon_script.php index b24c2a59e2..a77f465395 100644 --- a/pandora_console/godmode/servers/recon_script.php +++ b/pandora_console/godmode/servers/recon_script.php @@ -1,401 +1,27 @@ $id_reconscript] - ); - - echo htmlentities(io_safe_output($description), ENT_QUOTES, 'UTF-8', true); - return; -} - -// Load global vars -global $config; - -check_login(); - -if (! check_acl($config['id_user'], 0, 'LM')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access recon script Management' - ); - include 'general/noaccess.php'; - return; -} - -/* - * Disabled at the moment. - if (!check_referer()) { - require ("general/noaccess.php"); - - return; - } +/** + * Deprectated. + * + * @category Deprectated + * @package Pandora FMS + * @subpackage recon script + * @version 1.0.0 + * @license See below + * + * ______ ___ _______ _______ ________ + * | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __| + * | __/| _ | | _ || _ | _| _ | | ___| |__ | + * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| + * + * ============================================================================ + * Copyright (c) 2005-2019 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. + * ============================================================================ */ - -$view = get_parameter('view', ''); -$create = get_parameter('create', ''); - -if ($view != '') { - $form_id = $view; - $reconscript = db_get_row('trecon_script', 'id_recon_script', $form_id); - $form_name = $reconscript['name']; - $form_description = $reconscript['description']; - $form_script = $reconscript['script']; - $macros = $reconscript['macros']; -} - -if ($create != '') { - $form_name = ''; - $form_description = ''; - $form_script = ''; - $macros = ''; -} - -// SHOW THE FORM -// ================================================================= -if (($create != '') or ($view != '')) { - if ($create != '') { - ui_print_page_header(__('Recon script creation'), 'images/gm_servers.png', false, 'reconscript_definition', true); - } else { - ui_print_page_header(__('Recon script update'), 'images/gm_servers.png', false, 'reconscript_definition', true); - $id_recon_script = get_parameter('view', ''); - } - - - if ($create == '') { - echo ""; - } else { - echo ""; - } - - $table = new stdClass(); - $table->width = '100%'; - $table->id = 'table-form'; - $table->class = 'databox filters'; - $table->style = []; - $table->style[0] = 'font-weight: bold'; - $table->style[2] = 'font-weight: bold'; - $table->data = []; - - $data = []; - $data[0] = __('Name'); - $data[1] = ''; - $table->data['recon_name'] = $data; - $table->colspan['recon_name'][1] = 3; - - $data = []; - $data[0] = __('Script fullpath'); - $data[1] = ''; - $table->data['recon_fullpath'] = $data; - $table->colspan['recon_fullpath'][1] = 3; - - $data = []; - $data[0] = __('Description'); - $data[1] = ''; - $table->data['recon_description'] = $data; - $table->colspan['recon_description'][1] = 3; - - $macros = json_decode($macros, true); - - // This code is ready to add locked feature as plugins - $locked = false; - - // The next row number is recon_3 - $next_name_number = 3; - $i = 1; - while (1) { - // Always print at least one macro - if ((!isset($macros[$i]) || $macros[$i]['desc'] == '') && $i > 1) { - break; - } - - $macro_desc_name = 'field'.$i.'_desc'; - $macro_desc_value = ''; - $macro_help_name = 'field'.$i.'_help'; - $macro_help_value = ''; - $macro_value_name = 'field'.$i.'_value'; - $macro_value_value = ''; - $macro_name_name = 'field'.$i.'_macro'; - $macro_name = '_field'.$i.'_'; - $macro_hide_value_name = 'field'.$i.'_hide'; - $macro_hide_value_value = 0; - - if (isset($macros[$i]['desc'])) { - $macro_desc_value = $macros[$i]['desc']; - } - - if (isset($macros[$i]['help'])) { - $macro_help_value = $macros[$i]['help']; - } - - if (isset($macros[$i]['value'])) { - $macro_value_value = $macros[$i]['value']; - } - - if (isset($macros[$i]['hide'])) { - $macro_hide_value_value = $macros[$i]['hide']; - } - - $datam = []; - $datam[0] = __('Description')." ($macro_name)"; - $datam[0] .= html_print_input_hidden($macro_name_name, $macro_name, true); - $datam[1] = html_print_input_text_extended($macro_desc_name, $macro_desc_value, 'text-'.$macro_desc_name, '', 30, 255, $locked, '', "class='command_advanced_conf'", true); - if ($locked) { - $datam[1] .= html_print_image('images/lock.png', true, ['class' => 'command_advanced_conf']); - } - - $datam[2] = __('Default value')." ($macro_name)"; - $datam[3] = html_print_input_text_extended($macro_value_name, $macro_value_value, 'text-'.$macro_value_name, '', 30, 255, $locked, '', "class='command_component command_advanced_conf'", true); - if ($locked) { - $datam[3] .= html_print_image('images/lock.png', true, ['class' => 'command_advanced_conf']); - } - - $table->data['recon_'.$next_name_number] = $datam; - - $next_name_number++; - - $table->colspan['recon_'.$next_name_number][1] = 3; - - $datam = []; - $datam[0] = __('Hide value').ui_print_help_tip(__('This field will show up as dots like a password'), true); - $datam[1] = html_print_checkbox_extended($macro_hide_value_name, 1, $macro_hide_value_value, 0, '', ['class' => 'command_advanced_conf'], true, 'checkbox-'.$macro_hide_value_name); - - $table->data['recon_'.$next_name_number] = $datam; - $next_name_number++; - - $table->colspan['recon_'.$next_name_number][1] = 3; - - $datam = []; - $datam[0] = __('Help')." ($macro_name)


"; - $tadisabled = $locked === true ? ' disabled' : ''; - $datam[1] = html_print_textarea($macro_help_name, 6, 100, $macro_help_value, 'class="command_advanced_conf" style="width: 97%;"'.$tadisabled, true); - - if ($locked) { - $datam[1] .= html_print_image('images/lock.png', true, ['class' => 'command_advanced_conf']); - } - - $datam[1] .= '


'; - - $table->data['recon_'.$next_name_number] = $datam; - $next_name_number++; - $i++; - } - - if (!$locked) { - $datam = []; - $datam[0] = ''.__('Add macro').''.html_print_image('images/add.png', true).''; - $datam[0] .= ''; - $datam[0] .= ''; - $delete_macro_style = ''; - if ($i <= 2) { - $delete_macro_style = 'display:none;'; - } - - $datam[2] = ''; - - $table->colspan['recon_action'][0] = 2; - $table->rowstyle['recon_action'] = 'text-align:center'; - $table->colspan['recon_action'][2] = 2; - $table->data['recon_action'] = $datam; - } - - html_print_table($table); - - echo '
'.__('Name').''.__('Type').''.__('Command').'".''.__('Op.').''.'
'; - echo '
'; - - if ($create != '') { - echo ""; - } else { - echo ""; - } - - echo '
'; -} else { - ui_print_page_header(__('Recon scripts registered on %s', get_product_name()), 'images/gm_servers.png', false, '', true); - - // Update reconscript - if (isset($_GET['update_reconscript'])) { - // if modified any parameter - $id_recon_script = get_parameter('update_reconscript', 0); - $reconscript_name = get_parameter('form_name', ''); - $reconscript_description = get_parameter('form_description', ''); - $reconscript_script = get_parameter('form_script', ''); - - // Get macros - $i = 1; - $macros = []; - while (1) { - $macro = (string) get_parameter('field'.$i.'_macro'); - if ($macro == '') { - break; - } - - $desc = (string) get_parameter('field'.$i.'_desc'); - $help = (string) get_parameter('field'.$i.'_help'); - $value = (string) get_parameter('field'.$i.'_value'); - $hide = get_parameter('field'.$i.'_hide'); - - $macros[$i]['macro'] = $macro; - $macros[$i]['desc'] = $desc; - $macros[$i]['help'] = $help; - $macros[$i]['value'] = $value; - $macros[$i]['hide'] = $hide; - $i++; - } - - $macros = io_json_mb_encode($macros); - - $sql_update = "UPDATE trecon_script SET - name = '$reconscript_name', - description = '$reconscript_description', - script = '$reconscript_script', - macros = '$macros' - WHERE id_recon_script = $id_recon_script"; - $result = false; - if ($reconscript_name != '' && $reconscript_script != '') { - $result = db_process_sql($sql_update); - } - - if (! $result) { - ui_print_error_message(__('Problem updating')); - } else { - ui_print_success_message(__('Updated successfully')); - } - } - - // Create reconscript - if (isset($_GET['create_reconscript'])) { - $reconscript_name = get_parameter('form_name', ''); - $reconscript_description = get_parameter('form_description', ''); - $reconscript_script = get_parameter('form_script', ''); - - // Get macros - $i = 1; - $macros = []; - while (1) { - $macro = (string) get_parameter('field'.$i.'_macro'); - if ($macro == '') { - break; - } - - $desc = (string) get_parameter('field'.$i.'_desc'); - $help = (string) get_parameter('field'.$i.'_help'); - $value = (string) get_parameter('field'.$i.'_value'); - $hide = get_parameter('field'.$i.'_hide'); - - $macros[$i]['macro'] = $macro; - $macros[$i]['desc'] = $desc; - $macros[$i]['help'] = $help; - $macros[$i]['value'] = $value; - $macros[$i]['hide'] = $hide; - $i++; - } - - $macros = io_json_mb_encode($macros); - - $values = [ - 'name' => $reconscript_name, - 'description' => $reconscript_description, - 'script' => $reconscript_script, - 'macros' => $macros, - ]; - $result = false; - if ($values['name'] != '' && $values['script'] != '') { - $result = db_process_sql_insert('trecon_script', $values); - } - - if (! $result) { - ui_print_error_message(__('Problem creating')); - } else { - ui_print_success_message(__('Created successfully')); - } - } - - if (isset($_GET['kill_reconscript'])) { - // if delete alert - $reconscript_id = get_parameter('kill_reconscript', 0); - - $result = db_process_sql_delete( - 'trecon_script', - ['id_recon_script' => $reconscript_id] - ); - - if (! $result) { - ui_print_error_message(__('Problem deleting reconscript')); - } else { - ui_print_success_message(__('reconscript deleted successfully')); - } - - if ($reconscript_id != 0) { - $result = db_process_sql_delete( - 'trecon_task', - ['id_recon_script' => $reconscript_id] - ); - } - } - - // If not edition or insert, then list available reconscripts - $rows = db_get_all_rows_in_table('trecon_script'); - - if ($rows !== false) { - echo ''; - echo ''; - echo ''; - echo ''; - $color = 0; - foreach ($rows as $row) { - if ($color == 1) { - $tdcolor = 'datos'; - $color = 0; - } else { - $tdcolor = 'datos2'; - $color = 1; - } - - echo ''; - echo "'; - echo "'; - } - - echo '
'.__('Name').''.__('Description').''.__('Delete').'
"; - echo ""; - echo $row['name']; - echo '"; - $desc = io_safe_output($row['description']); - $desc = str_replace("\n", '
', $desc); - echo $desc.'

'; - echo ''.__('Command').': '.$row['script'].''; - echo "
"; - echo "".html_print_image('images/cross.png', true, ['border' => '0']).''; - echo '
'; - } else { - ui_print_info_message(['no_close' => true, 'message' => __('There are no recon scripts in the system') ]); - } - - echo ''; - echo '
'; - echo "
"; - echo ""; - echo '
'; -} - -ui_require_javascript_file('pandora_modules'); diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 2bb4f6ab00..1b5486b570 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -40,7 +40,9 @@ if ($servers === false) { $table = new StdClass(); $table->width = '100%'; -$table->class = 'databox data'; +$table->class = 'info_table'; +$table->cellpadding = 0; +$table->cellspacing = 0; $table->size = []; $table->style = []; @@ -80,7 +82,11 @@ $names_servers = []; foreach ($servers as $server) { $data = []; - $table->cellclass[][3] = 'progress_bar'; + // $table->cellclass[][3] = 'progress_bar'; + $table->cellclass[] = [ + 3 => 'progress_bar', + 8 => 'action_buttons', + ]; $data[0] = ''.strip_tags($server['name']).''; // Status @@ -155,7 +161,7 @@ foreach ($servers as $server) { 'style' => 'width:21px;height:21px;', ] ); - $data[8] .= '  '; + $data[8] .= ''; } if ($server['type'] == 'data') { @@ -165,7 +171,7 @@ foreach ($servers as $server) { true, ['title' => __('Reset module status and fired alert counts')] ); - $data[8] .= '  '; + $data[8] .= ''; } else if ($server['type'] == 'enterprise snmp') { $data[8] .= ''; $data[8] .= html_print_image( @@ -173,7 +179,7 @@ foreach ($servers as $server) { true, ['title' => __('Claim back SNMP modules')] ); - $data[8] .= '  '; + $data[8] .= ''; } $data[8] .= ''; @@ -195,7 +201,7 @@ foreach ($servers as $server) { $names_servers[$safe_server_name] = false; } - $data[8] .= '  '; + $data[8] .= ''; $data[8] .= html_print_image( 'images/cross.png', true, @@ -225,7 +231,12 @@ if ($tiny) { } if ($tiny) { - ui_toggle(html_print_table($table, true), __('Tactical server information'), false, $hidden_toggle); + ui_toggle( + html_print_table($table, true), + __('Tactical server information'), + false, + $hidden_toggle + ); } else { html_print_table($table); } diff --git a/pandora_console/godmode/setup/file_manager.php b/pandora_console/godmode/setup/file_manager.php index 27f3e232c8..6d5e7679b7 100644 --- a/pandora_console/godmode/setup/file_manager.php +++ b/pandora_console/godmode/setup/file_manager.php @@ -66,8 +66,6 @@ $real_directory = realpath($config['homedir'].'/'.$directory); echo '

'.__('Index of %s', $directory).'

'; -$homedir_filemanager = isset($config['homedir_filemanager']) ? $config['homedir_filemanager'] : false; - filemanager_file_explorer( $real_directory, $directory, @@ -78,5 +76,5 @@ filemanager_file_explorer( '', false, '', - $homedir_filemanager + false ); diff --git a/pandora_console/godmode/setup/gis.php b/pandora_console/godmode/setup/gis.php index 946d0526ea..526abc0b0a 100755 --- a/pandora_console/godmode/setup/gis.php +++ b/pandora_console/godmode/setup/gis.php @@ -28,8 +28,14 @@ require_once 'include/functions_gis.php'; ui_require_javascript_file('openlayers.pandora'); -// Header -ui_print_page_header(__('Map conections GIS'), '', false, 'setup_gis_index', true); +// Header. +ui_print_page_header( + __('Map conections GIS'), + '', + false, + '', + true +); $action = get_parameter('action'); @@ -63,14 +69,15 @@ switch ($action) { break; } +$table->class = 'info_table'; $table->width = '98%'; $table->head[0] = __('Map connection name'); $table->head[1] = __('Group'); $table->head[3] = __('Delete'); -$table->align[1] = 'center'; -$table->align[2] = 'center'; -$table->align[3] = 'center'; +$table->align[1] = 'left'; +$table->align[2] = 'left'; +$table->align[3] = 'left'; $mapsConnections = db_get_all_rows_in_table('tgis_map_connection', 'conection_name'); @@ -84,6 +91,7 @@ if ($mapsConnections !== false) { '
'.html_print_image('images/cross.png', true).'', ]; + $table->cellclass[][2] = 'action_buttons'; } } diff --git a/pandora_console/godmode/setup/gis_step_2.php b/pandora_console/godmode/setup/gis_step_2.php index 5203bdef23..133b4fdeaa 100644 --- a/pandora_console/godmode/setup/gis_step_2.php +++ b/pandora_console/godmode/setup/gis_step_2.php @@ -13,7 +13,7 @@ * GNU General Public License for more details. */ -// Load global vars +// Load global vars. global $config; check_login(); @@ -35,8 +35,14 @@ echo ''.''.''.htmlentities(__('Tile Server URL'), ENT_QUOTES, 'UTF-8').':'.''.html_print_input_text('url', $mapConnectionDataUrl, '', 45, 90, true).''.''.''; -// Google Maps Connection +// Google Maps Connection. $gmaps_types['G_PHYSICAL_MAP'] = __('Google Physical'); $gmaps_types['G_HYBRID_MAP'] = __('Google Hybrid'); $gmaps_types['G_SATELITE_MAP'] = __('Google Satelite'); // TODO: Use label tags for the forms. $optionsConnectionGmapTable = ''.''.''.''.''.''.''.''.''.''.''.'
'.__('Google Map Type').':'.trim(html_print_select($gmaps_types, 'gmap_type', $gmap_type, '', '', 0, true)).'
'.__('Google Maps Key').':
'.html_print_input_text('gmap_key', $gmap_key, '', 90, 128, true).'
'; -// Image Map Connection +// Image Map Connection. $optionsConnectionImageTable = ''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.'
'.__('Image URL').':'.html_print_input_text('url', $mapConnectionDataUrl, '', 45, 90, true).'
'.__('Corners of the area of the image').':
'.__('Left').':'.html_print_input_text('bb_left', $bb_left, '', 25, 25, true).''.__('Bottom').':'.html_print_input_text('bb_bottom', $bb_bottom, '', 25, 25, true).'
'.__('Right').':'.html_print_input_text('bb_right', $bb_right, '', 25, 25, true).''.__('Top').':'.html_print_input_text('bb_top', $bb_top, '', 25, 25, true).'
'.__('Image Size').':
'.__('Width').':'.html_print_input_text('image_width', $image_width, '', 25, 25, true).''.__('Height').':'.html_print_input_text('image_height', $image_height, '', 25, 25, true).'
'; -// WMS Server Connection +// WMS Server Connection. $optionsConnectionWMSTable = ''.''.''.''.''.''.''.''.''.'
'.__('WMS Server URL').''.''.html_print_input_text('url', $mapConnectionDataUrl, '', 90, 255, true).'
'.__('Layers').ui_print_help_tip(__('Enter a single element or a comma separated list'), true).''.html_print_input_text('layers', $layers, '', 90, 255, true).'
'; if ($mapConnectionData != null) { @@ -274,6 +297,10 @@ if ($mapConnectionData != null) { case 'WMS': $optionsConnectionTypeTable = $optionsConnectionWMSTable; break; + + default: + // Default. + break; } } diff --git a/pandora_console/godmode/setup/license.php b/pandora_console/godmode/setup/license.php index 413b1d7fe1..f03d32ef0a 100644 --- a/pandora_console/godmode/setup/license.php +++ b/pandora_console/godmode/setup/license.php @@ -1,15 +1,32 @@ $value) { - db_process_sql_update( - 'tupdate_settings', - [db_escape_key_identifier('value') => $value], - [db_escape_key_identifier('key') => $key] - ); - } - - ui_print_success_message(__('License updated')); + ui_require_javascript_file_enterprise('load_enterprise'); + enterprise_include_once('include/functions_license.php'); +} + +if ($update_settings) { + if (!is_metaconsole()) { + // Node. + foreach ($_POST['keys'] as $key => $value) { + db_process_sql_update( + 'tupdate_settings', + [db_escape_key_identifier('value') => $value], + [db_escape_key_identifier('key') => $key] + ); + } + + ui_print_success_message(__('License updated')); + } } -ui_require_javascript_file_enterprise('load_enterprise'); -enterprise_include_once('include/functions_license.php'); $license = enterprise_hook('license_get_info'); $rows = db_get_all_rows_in_table('tupdate_settings'); @@ -55,11 +88,20 @@ if (enterprise_installed()) { echo ''; echo ''; +// Retrieve UM url configured (or default). +$url = get_um_url(); $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; +if (is_metaconsole()) { + $table->head[0] = __('Licence'); + $table->head_colspan[0] = 3; + $table->headstyle[0] = 'text-align: center'; + $table->style[0] = 'font-weight: bold;'; +} + $table->data = []; $table->data[0][0] = ''.__('Customer key').''; @@ -98,34 +140,45 @@ if (enterprise_installed()) { html_print_input_hidden('update_settings', 1); html_print_submit_button(__('Validate'), 'update_button', false, 'class="sub upd"'); echo '  '; - html_print_button(__('Request new license'), '', false, 'generate_request_code()', 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only sub next"'); + html_print_button(__('Request new license'), '', false, 'generate_request_code()', 'class="sub next"'); echo '
'; } -echo ''; -echo ''; +if (is_metaconsole()) { + ui_require_css_file('pandora_enterprise', '../../'.ENTERPRISE_DIR.'/include/styles/'); + ui_require_css_file('register', '../../include/styles/'); +} else { + ui_require_css_file('pandora'); + ui_require_css_file('pandora_enterprise', ENTERPRISE_DIR.'/include/styles/'); + ui_require_css_file('register'); +} + +if (enterprise_hook('print_activate_licence_dialog') == ENTERPRISE_NOT_HOOK) { + echo ''; + echo ''; +} diff --git a/pandora_console/godmode/setup/links.php b/pandora_console/godmode/setup/links.php index f5016e666e..c15052412b 100644 --- a/pandora_console/godmode/setup/links.php +++ b/pandora_console/godmode/setup/links.php @@ -137,9 +137,11 @@ if ((isset($_GET['form_add'])) or (isset($_GET['form_edit']))) { if (empty($rows)) { ui_print_info_message(['no_close' => true, 'message' => __("There isn't links") ]); } else { - echo ""; + echo "
"; + echo ''; echo "'; echo "'; + echo ''; $color = 1; foreach ($rows as $row) { @@ -152,7 +154,7 @@ if ((isset($_GET['form_add'])) or (isset($_GET['form_edit']))) { } echo "'; - echo ''; + echo ''; } echo '
".__('Link name').'".__('Delete').'
".$row['name'].''.html_print_image('images/cross.png', true).'
'.html_print_image('images/cross.png', true).'
'; diff --git a/pandora_console/godmode/setup/news.php b/pandora_console/godmode/setup/news.php index 7b663bad53..61491496f5 100644 --- a/pandora_console/godmode/setup/news.php +++ b/pandora_console/godmode/setup/news.php @@ -231,14 +231,15 @@ if ((isset($_GET['form_add'])) || (isset($_GET['form_edit']))) { ui_print_info_message(['no_close' => true, 'message' => __('There are no defined news') ]); } else { // Main list view for Links editor - echo ""; + echo "
"; + echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; - + echo ''; $color = 1; @@ -276,7 +277,7 @@ if ((isset($_GET['form_add'])) || (isset($_GET['form_edit']))) { echo "'; } - echo ''; + echo ''; } echo '
'.__('Subject').''.__('Type').''.__('Author').''.__('Timestamp').''.__('Expiration').''.__('Delete').'
".__('No').''.html_print_image('images/cross.png', true, ['border' => '0']).'
'.html_print_image('images/cross.png', true, ['border' => '0']).'
'; @@ -330,7 +331,7 @@ ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/'); theme : "advanced", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", - theme_advanced_buttons1 : "bold,italic, |, image, link, |, cut, copy, paste, |, undo, redo, |, forecolor, |, fontsizeselect, |, justifyleft, justifycenter, justifyright", + theme_advanced_buttons1 : "bold,italic, |, image, link, |, cut, copy, paste, |, undo, redo, |, forecolor, |, fontsizeselect, |, justifyleft, justifycenter, justifyright, | ,code", theme_advanced_buttons2 : "", theme_advanced_buttons3 : "", convert_urls : false, diff --git a/pandora_console/godmode/setup/os.list.php b/pandora_console/godmode/setup/os.list.php index f00b8cb00d..07365edc6c 100644 --- a/pandora_console/godmode/setup/os.list.php +++ b/pandora_console/godmode/setup/os.list.php @@ -25,7 +25,7 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user $table = new stdClass(); $table->width = '100%'; -$table->class = 'databox data'; +$table->class = 'info_table'; $table->head[0] = ''; $table->head[1] = __('ID'); @@ -37,7 +37,19 @@ $table->align[4] = 'center'; $table->size[0] = '20px'; $table->size[4] = '20px'; -$osList = db_get_all_rows_in_table('tconfig_os'); +// Prepare pagination. +$offset = (int) get_parameter('offset'); +$limit = $config['block_size']; +$count_osList = db_get_value('count(*)', 'tconfig_os'); + +$osList = db_get_all_rows_filter( + 'tconfig_os', + [ + 'offset' => $offset, + 'limit' => $limit, + ] +); + if ($osList === false) { $osList = []; } @@ -54,6 +66,8 @@ foreach ($osList as $os) { } $data[] = ui_print_truncate_text(io_safe_output($os['description']), 'description', true, true); + + $table->cellclass[][4] = 'action_buttons'; if ($os['id_os'] > 16) { if (is_metaconsole()) { $data[] = ''.html_print_image('images/cross.png', true).''; @@ -69,7 +83,9 @@ foreach ($osList as $os) { } if (isset($data)) { + ui_pagination($count_osList, false, $offset); html_print_table($table); + ui_pagination($count_osList, false, $offset, 0, false, 'offset', true, 'pagination-bottom'); } else { ui_print_info_message(['no_close' => true, 'message' => __('There are no defined operating systems') ]); } diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 666dd0b21c..af414d6ab3 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -200,8 +200,8 @@ if ($config['history_db_enabled'] == 1) { ); $time_pandora_db_history = false; - if ($history_connect !== false) { - if ($config['history_db_connection'] !== false) { + if ($history_connect) { + if ($config['history_db_connection']) { $time_pandora_db_history = mysql_db_process_sql( $sql, 'insert_id', @@ -247,8 +247,7 @@ $table->style[0] = 'font-weight: bold'; $table->size[0] = '70%'; $table->size[1] = '30%'; -enterprise_hook('enterprise_warnings_history_days'); - +// enterprise_hook('enterprise_warnings_history_days'); $table->data[1][0] = __('Max. days before delete events'); $table->data[1][0] .= ui_print_help_tip( __('If the compaction or purge of the data is more frequent than the events deletion, anomalies in module graphs could appear'), @@ -405,16 +404,16 @@ if ($config['history_db_enabled'] == 1) { ); } - $history_connect = @mysql_db_process_sql( - 'SELECT 1 FROM tconfig', - 'affected_rows', - $config['history_db_connection'], - false - ); - $config_history = false; - if ($history_connect !== false) { - if ($config['history_db_connection'] != false) { + if ($config['history_db_connection']) { + $history_connect = @mysql_db_process_sql( + 'SELECT 1 FROM tconfig', + 'affected_rows', + $config['history_db_connection'], + false + ); + + if ($history_connect !== false) { $config_history_array = mysql_db_process_sql( 'SELECT * FROM tconfig', 'affected_rows', @@ -427,11 +426,11 @@ if ($config['history_db_enabled'] == 1) { $config_history[$value['token']] = $value['value']; } } + } else { + echo ui_print_error_message( + __('The tconfig table does not exist in the historical database') + ); } - } else { - echo ui_print_error_message( - __('The tconfig table does not exist in the historical database') - ); } if ($config_history === false) { @@ -536,6 +535,19 @@ $table->data[] = [ ), ]; + +$table->data[] = [ + __('Max. days before delete old network matrix data'), + html_print_input_text( + 'delete_old_network_matrix', + $config['delete_old_network_matrix'], + '', + 5, + 5, + true + ), +]; + $table_other = new stdClass(); $table_other->width = '100%'; $table_other->class = 'databox filters'; @@ -615,7 +627,7 @@ $table_other->data[6][1] = html_print_input_text( true ); -$table_other->data[7][0] = __('Use agent access graph').ui_print_help_icon('agent_access', true); +$table_other->data[7][0] = __('Use agent access graph'); $table_other->data[7][1] = html_print_checkbox_switch('agentaccess', 1, $config['agentaccess'], true); $table_other->data[8][0] = __('Max. recommended number of files in attachment directory'); @@ -694,24 +706,24 @@ $table_other->data[13][1] = html_print_input_text( echo '
'; echo '
'; - echo ''.__('Database maintenance status').''; + echo ''.__('Database maintenance status').' '.ui_print_help_icon('database_maintenance_status_tab', true).''; html_print_table($table_status); echo '
'; echo '
'; - echo ''.__('Database maintenance options').''; + echo ''.__('Database maintenance options').' '.ui_print_help_icon('database_maintenance_options_tab', true).''; html_print_table($table); echo '
'; if ($config['history_db_enabled'] == 1) { echo '
'; - echo ''.__('Historical database maintenance options').''; + echo ''.__('Historical database maintenance options').' '.ui_print_help_icon('historical_database_maintenance_options_tab', true).''; html_print_table($table_historical); echo '
'; } echo '
'; - echo ''.__('Others').''; + echo ''.__('Others').' '.ui_print_help_icon('others_database_maintenance_options_tab', true).''; html_print_table($table_other); echo '
'; diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 6ee8577367..f5bfc8c635 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -135,9 +135,9 @@ if (enterprise_installed()) { switch ($section) { case 'general': - default: $buttons['general']['active'] = true; $subpage = ' » '.__('General'); + $help_header = 'setup_general_tab'; break; case 'auth': @@ -148,7 +148,7 @@ switch ($section) { case 'perf': $buttons['perf']['active'] = true; $subpage = ' » '.__('Performance'); - $help_header = 'performance'; + $help_header = ''; break; case 'vis': @@ -164,16 +164,34 @@ switch ($section) { case 'ehorus': $buttons['ehorus']['active'] = true; $subpage = ' » '.__('eHorus'); + $help_header = 'setup_ehorus_tab'; break; case 'notifications': $buttons['notifications']['active'] = true; $subpage = ' » '.__('Notifications'); break; + + case 'enterprise': + $buttons['enterprise']['active'] = true; + $subpage = ' » '.__('Enterprise'); + $help_header = 'setup_enterprise_tab'; + break; + + default: + // Default. + break; } // Header. -ui_print_page_header(__('Configuration').$subpage, '', false, $help_header, true, $buttons); +ui_print_page_header( + __('Configuration').$subpage, + '', + false, + $help_header, + true, + $buttons +); if (isset($config['error_config_update_config'])) { if ($config['error_config_update_config']['correct'] == false) { diff --git a/pandora_console/godmode/setup/setup_ehorus.php b/pandora_console/godmode/setup/setup_ehorus.php index fc2ebd3d3a..89d4ff35e8 100644 --- a/pandora_console/godmode/setup/setup_ehorus.php +++ b/pandora_console/godmode/setup/setup_ehorus.php @@ -66,6 +66,12 @@ $table_remote->class = 'databox filters'; $table_remote->size['name'] = '30%'; $table_remote->style['name'] = 'font-weight: bold'; +// Enable eHorus user configuration. +$row = []; +$row['name'] = ('eHorus configuration at user level'); +$row['control'] = html_print_checkbox_switch('ehorus_user_level_conf', 1, $config['ehorus_user_level_conf'], true); +$table_remote->data['ehorus_user_level_conf'] = $row; + // User. $row = []; $row['name'] = __('User'); @@ -139,58 +145,98 @@ if ($config['ehorus_enabled'] && !$custom_field_exists) { ui_print_error_message($error_message); } +echo ""; // Form enable. -echo ''; +echo '
'; html_print_input_hidden('update_config', 1); html_print_table($table_enable); -echo ''; +echo '
'; // Form remote. -if ($config['ehorus_enabled']) { - echo '
'; + echo '
'; echo '
'; echo ''.__('eHorus API').''; html_print_input_hidden('update_config', 1); html_print_table($table_remote); - echo '
'; + + echo '
'; + echo '
'; + echo '
'; html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); echo '
'; - echo ''; echo '
'; -} ?> diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 370df5d808..8079aee1e8 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -82,7 +82,7 @@ $table->data[2][1] = html_print_input_text('phantomjs_bin', io_safe_output($conf $table->data[6][0] = __('Auto login (hash) password'); $table->data[6][1] = html_print_input_password('loginhash_pwd', io_output_password($config['loginhash_pwd']), '', 15, 15, true); -$table->data[9][0] = __('Time source').ui_print_help_icon('timesource', true); +$table->data[9][0] = __('Time source'); $sources['system'] = __('System'); $sources['sql'] = __('Database'); $table->data[9][1] = html_print_select($sources, 'timesource', $config['timesource'], '', '', '', true); @@ -107,7 +107,7 @@ $table->data[13][1] = html_print_input_text('cert_path', io_safe_output($config[ $table->data[14][0] = __('Attachment store').ui_print_help_tip(__('Directory where temporary data is stored.'), true); $table->data[14][1] = html_print_input_text('attachment_store', io_safe_output($config['attachment_store']), '', 50, 255, true); -$table->data[15][0] = __('IP list with API access').ui_print_help_icon('ip_api_list', true); +$table->data[15][0] = __('IP list with API access'); if (isset($_POST['list_ACL_IPs_for_API'])) { $list_ACL_IPs_for_API = get_parameter_post('list_ACL_IPs_for_API'); } else { @@ -131,6 +131,14 @@ if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $table->data[19][1] = html_print_checkbox_switch_extended('activate_netflow', 1, $config['activate_netflow'], $rbt_disabled, '', '', true); +$table->data[21][0] = __('Enable Network Traffic Analyzer'); +$table->data[21][1] = html_print_switch( + [ + 'name' => 'activate_nta', + 'value' => $config['activate_nta'], + ] +); + $zone_name = [ 'Africa' => __('Africa'), diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 9ee95f78cc..8f6630d4e3 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -160,6 +160,20 @@ if (get_parameter('get_notifications_dropdown', 0)) { return; } +if (get_parameter('get_notification', 0)) { + $msg_id = get_parameter('id', 0); + + if ($msg_id > 0) { + $msg = messages_get_message($msg_id); + + $msg['mensaje'] = io_safe_output($msg['mensaje']); + $msg['subject'] = io_safe_output($msg['subject']); + echo json_encode($msg); + } + + return; +} + // Notification table. It is just a wrapper. $table_content = new StdClass(); $table_content->data = []; diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index a1ffc9008a..bcaff54d95 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -70,10 +70,6 @@ $values[SECONDS_5MINUTES] = human_time_description_raw(SECONDS_5MINUTES); $values[SECONDS_10MINUTES] = human_time_description_raw(SECONDS_10MINUTES); $values[SECONDS_30MINUTES] = human_time_description_raw(SECONDS_30MINUTES); -$table_behaviour->data[$row][0] = __('Default interval for refresh on Visual Console').ui_print_help_tip(__('This interval will affect to Visual Console pages'), true); -$table_behaviour->data[$row][1] = html_print_select($values, 'vc_refr', $config['vc_refr'], '', 'N/A', 0, true, false, false); -$row++; - $table_behaviour->data[$row][0] = __('Paginated module view'); $table_behaviour->data[$row][1] = html_print_checkbox_switch( 'paginate_module', @@ -121,7 +117,7 @@ if (enterprise_installed()) { } echo '
'; -echo ''.__('Behaviour configuration').''; +echo ''.__('Behaviour configuration').' '.ui_print_help_icon('behavoir_conf_tab', true).''; html_print_table($table_behaviour); echo '
'; // ---------------------------------------------------------------------- @@ -243,7 +239,7 @@ function logo_custom_enterprise($name, $logo) false, true, '', - $open, + false, 'width:240px' ); return $select; @@ -259,7 +255,7 @@ function logo_custom_enterprise($name, $logo) false, true, '', - $open, + true, 'width:240px' ); return $select; @@ -267,12 +263,12 @@ function logo_custom_enterprise($name, $logo) } -$table_styles->data[$row][0] = __('Custom logo (menu)').ui_print_help_icon('custom_logo', true); +$table_styles->data[$row][0] = __('Custom logo (menu)'); $table_styles->data[$row][1] = logo_custom_enterprise('custom_logo', $config['custom_logo']); $table_styles->data[$row][1] .= ' '.html_print_button(__('View'), 'custom_logo_preview', $open, '', 'class="sub camera logo_preview"', true, false, $open, 'visualmodal'); $row++; -$table_styles->data[$row][0] = __('Custom logo collapsed (menu)').ui_print_help_icon('custom_logo_collapsed', true); +$table_styles->data[$row][0] = __('Custom logo collapsed (menu)'); $table_styles->data[$row][1] = logo_custom_enterprise('custom_logo_collapsed', $config['custom_logo_collapsed']); $table_styles->data[$row][1] .= ' '.html_print_button(__('View'), 'custom_logo_collapsed_preview', $open, '', 'class="sub camera logo_preview"', true, false, $open, 'visualmodal'); $row++; @@ -316,7 +312,7 @@ if (enterprise_installed()) { $table_styles->data[$row][1] .= ' '.html_print_button(__('View'), 'custom_logo_white_bg_preview', $open, '', 'class="sub camera logo_preview"', true, false, $open, 'visualmodal'); $row++; -$table_styles->data[$row][0] = __('Custom logo (login)').ui_print_help_icon('custom_logo', true); +$table_styles->data[$row][0] = __('Custom logo (login)'); if (enterprise_installed()) { $table_styles->data[$row][1] = html_print_select( @@ -462,6 +458,20 @@ if (enterprise_installed()) { $row++; } +// Title Header +if (enterprise_installed()) { + $table_styles->data[$row][0] = __('Title (header)'); + $table_styles->data[$row][1] = html_print_input_text('custom_title_header', $config['custom_title_header'], '', 50, 40, true); + $row++; +} + +// Subtitle Header +if (enterprise_installed()) { + $table_styles->data[$row][0] = __('Subtitle (header)'); + $table_styles->data[$row][1] = html_print_input_text('custom_subtitle_header', $config['custom_subtitle_header'], '', 50, 40, true); + $row++; +} + // login title1 if (enterprise_installed()) { $table_styles->data[$row][0] = __('Title 1 (login)'); @@ -555,7 +565,7 @@ $row++; echo '
'; - echo ''.__('Style configuration').''; + echo ''.__('Style configuration').' '.ui_print_help_icon('style_conf_tab', true).''; html_print_table($table_styles); echo '
'; // ---------------------------------------------------------------------- @@ -598,7 +608,7 @@ $row++; $row++; echo '
'; - echo ''.__('GIS configuration').''; + echo ''.__('GIS configuration').' '.ui_print_help_icon('gis_conf_tab', true).''; html_print_table($table_gis); echo '
'; // ---------------------------------------------------------------------- @@ -692,7 +702,7 @@ $row++; $row++; echo '
'; - echo ''.__('Font and Text configuration').''; + echo ''.__('Font and Text configuration').' '.ui_print_help_icon('front_and_text_conf_tab', true).''; html_print_table($table_font); echo '
'; // ---------------------------------------------------------------------- @@ -880,7 +890,7 @@ $row++; */ echo '
'; - echo ''.__('Charts configuration').''; + echo ''.__('Charts configuration').' '.ui_print_help_icon('charts_conf_tab', true).''; html_print_table($table_chars); echo '
'; // ---------------------------------------------------------------------- @@ -894,6 +904,50 @@ $row++; $table_vc->size[0] = '50%'; $table_vc->data = []; + // Remove when the new view reaches rock solid stability. + $table_vc->data[$row][0] = __('Legacy Visual Console View'); + $table_vc->data[$row][0] .= ui_print_help_tip( + __('To use the old view when using the Visual Console visor'), + true + ); + $table_vc->data[$row][1] = html_print_checkbox_switch( + 'legacy_vc', + 1, + (bool) $config['legacy_vc'], + true + ); + $row++; + + $intervals = [ + 10 => '10 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '1 '.__('minutes'), + 300 => '5 '.__('minutes'), + 900 => '15 '.__('minutes'), + 1800 => '30 '.__('minutes'), + 3600 => '1 '.__('hour'), + ]; + $table_vc->data[$row][0] = __('Default cache expiration'); + $table_vc->data[$row][1] = html_print_extended_select_for_time( + 'vc_default_cache_expiration', + $config['vc_default_cache_expiration'], + '', + __('No cache'), + 0, + false, + true, + false, + false, + '', + false, + $intervals + ); + $row++; + + $table_vc->data[$row][0] = __('Default interval for refresh on Visual Console').ui_print_help_tip(__('This interval will affect to Visual Console pages'), true); + $table_vc->data[$row][1] = html_print_select($values, 'vc_refr', (int) $config['vc_refr'], '', 'N/A', 0, true, false, false); + $row++; + $vc_favourite_view_array[0] = __('Classic view'); $vc_favourite_view_array[1] = __('View of favorites'); $table_vc->data[$row][0] = __('Type of view of visual consoles').ui_print_help_tip(__('Allows you to directly display the list of favorite visual consoles'), true); @@ -904,16 +958,12 @@ $row++; $table_vc->data[$row][1] = ""; $row++; - if (empty($config['vc_line_thickness'])) { - $config['vc_line_thickness'] = 2; - } - $table_vc->data[$row][0] = __('Default line thickness for the Visual Console').ui_print_help_tip(__('This interval will affect to the lines between elements on the Visual Console'), true); - $table_vc->data[$row][1] = html_print_input_text('vc_line_thickness', $config['vc_line_thickness'], '', 5, 5, true); + $table_vc->data[$row][1] = html_print_input_text('vc_line_thickness', (int) $config['vc_line_thickness'], '', 5, 5, true); echo '
'; - echo ''.__('Visual consoles configuration').''; + echo ''.__('Visual consoles configuration').' '.ui_print_help_icon('visual_consoles_conf_tab', true).''; html_print_table($table_vc); echo '
'; @@ -931,7 +981,7 @@ $row++; $table_ser->data['number'][1] = ""; echo '
'; - echo ''.__('Services configuration').''; + echo ''.__('Services configuration').' '.ui_print_help_icon('services_conf_tab', true).''; html_print_table($table_ser); echo '
'; @@ -1110,7 +1160,7 @@ $row++; ); $row++; - $table_other->data[$row][0] = __('Date format string').ui_print_help_icon('date_format', true); + $table_other->data[$row][0] = __('Date format string'); $table_other->data[$row][1] = ''.__('Example').' '.date($config['date_format']); $table_other->data[$row][1] .= html_print_input_text('date_format', $config['date_format'], '', 30, 100, true); $row++; @@ -1123,7 +1173,7 @@ $row++; $comparation = false; } - $table_other->data[$row][0] = __('Timestamp or time comparation').ui_print_help_icon('time_stamp-comparation', true); + $table_other->data[$row][0] = __('Timestamp or time comparation'); $table_other->data[$row][1] = __('Comparation in rollover').' '; $table_other->data[$row][1] .= html_print_radio_button('prominent_time', 'comparation', '', $comparation, true); $table_other->data[$row][1] .= '
'.__('Timestamp in rollover').' '; @@ -1229,7 +1279,7 @@ $row++; echo '
'; - echo ''.__('Other configuration').''; + echo ''.__('Other configuration').' '.ui_print_help_icon('other_conf_tab', true).''; html_print_table($table_other); echo '
'; @@ -1370,6 +1420,15 @@ tinyMCE.init({ }); $(document).ready (function () { + + // Show the cache expiration conf or not. + $("input[name=legacy_vc]").change(function (e) { + if ($(this).prop("checked") === true) { + $("select#vc_default_cache_expiration_select").closest("tr").hide(); + } else { + $("select#vc_default_cache_expiration_select").closest("tr").show(); + } + }).change(); var comfort = 0; diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 677a283854..a2a1b8b811 100755 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -76,7 +76,7 @@ if ($update_alert || $modify_alert) { __('SNMP Console').' » '.__('Update alert'), 'images/op_snmp.png', false, - 'snmp_alert', + 'snmp_alert_update_tab', false ); } else if ($create_alert || $save_alert) { @@ -84,7 +84,7 @@ if ($update_alert || $modify_alert) { __('SNMP Console').' » '.__('Create alert'), 'images/op_snmp.png', false, - 'snmp_alert', + 'snmp_alert_overview_tab', false ); } else { @@ -92,7 +92,7 @@ if ($update_alert || $modify_alert) { __('SNMP Console').' » '.__('Alert overview'), 'images/op_snmp.png', false, - 'snmp_alert', + 'snmp_alert_overview_tab', false ); } @@ -757,7 +757,6 @@ if ($create_alert || $update_alert) { // Custom echo ''.__('Custom Value/OID'); - echo ui_print_help_icon('snmp_alert_custom', true); echo ''; html_print_textarea('custom_value', 2, 2, $custom_value, 'style="width:400px;"'); @@ -804,7 +803,7 @@ if ($create_alert || $update_alert) { echo ''; // Variable bindings/Data #1 - echo ''.''.__('Variable bindings/Data').ui_print_help_icon('field_match_snmp', true).''.''; + echo ''.''.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_1', $order_1, '', 4); html_print_input_text('custom_oid_data_1', $custom_oid_data_1, '', 60); @@ -1077,7 +1076,7 @@ if ($create_alert || $update_alert) { } echo ''; - echo ''.__('Position').ui_print_help_icon('snmp_alert_position', true).''; + echo ''.__('Position').''; html_print_input_text('position', $position, '', 3); echo ''; diff --git a/pandora_console/godmode/snmpconsole/snmp_filters.php b/pandora_console/godmode/snmpconsole/snmp_filters.php index b87fb4c3dd..0d8e1e9480 100644 --- a/pandora_console/godmode/snmpconsole/snmp_filters.php +++ b/pandora_console/godmode/snmpconsole/snmp_filters.php @@ -226,13 +226,13 @@ if ($edit_filter > -2) { $table->cellpadding = 4; $table->cellspacing = 4; $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->align = []; $table->head[0] = __('Description'); $table->head[1] = __('Filter'); $table->head[2] = __('Action'); - $table->size[2] = '50px'; + $table->size[2] = '65px'; $table->align[2] = 'center'; foreach ($aglomerate_result as $ind => $row) { @@ -263,6 +263,7 @@ if ($edit_filter > -2) { $data[0] = $compose_id; $data[1] = implode(' AND ', $compose_filter); $data[2] = $compose_action; + $table->cellclass[][2] = 'action_buttons'; array_push($table->data, $data); } } diff --git a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php index ec8ed20930..43ed63abec 100755 --- a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php +++ b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php @@ -33,7 +33,13 @@ $snmp_type = (int) get_parameter('snmp_type', 0); $snmp_value = (string) get_parameter('snmp_value', ''); $generate_trap = (bool) get_parameter('generate_trap', 0); -ui_print_page_header(__('SNMP Trap generator'), 'images/op_snmp.png', false, '', false); +ui_print_page_header( + __('SNMP Trap generator'), + 'images/op_snmp.png', + false, + 'snmp_trap_generator_view', + false +); if ($generate_trap) { $result = true; @@ -64,22 +70,64 @@ $table->size = []; $table->data = []; $table->data[0][0] = __('Host address'); -$table->data[0][1] = html_print_input_text('snmp_host_address', $snmp_host_address, '', 50, 255, true); +$table->data[0][1] = html_print_input_text( + 'snmp_host_address', + $snmp_host_address, + '', + 50, + 255, + true +); $table->data[0][2] = __('Community'); -$table->data[0][3] = html_print_input_text('snmp_community', $snmp_community, '', 50, 255, true); +$table->data[0][3] = html_print_input_text( + 'snmp_community', + $snmp_community, + '', + 50, + 255, + true +); $table->data[2][0] = __('Enterprise String'); -$table->data[2][1] = html_print_input_text('snmp_oid', $snmp_oid, '', 50, 255, true); +$table->data[2][1] = html_print_input_text( + 'snmp_oid', + $snmp_oid, + '', + 50, + 255, + true +); $table->data[2][2] = __('Value'); -$table->data[2][3] = html_print_input_text('snmp_value', $snmp_value, '', 50, 255, true); +$table->data[2][3] = html_print_input_text( + 'snmp_value', + $snmp_value, + '', + 50, + 255, + true +); $table->data[3][0] = __('SNMP Agent'); -$table->data[3][1] = html_print_input_text('snmp_agent', $snmp_agent, '', 50, 255, true); +$table->data[3][1] = html_print_input_text( + 'snmp_agent', + $snmp_agent, + '', + 50, + 255, + true +); -$table->data[3][2] = __('SNMP Type').' '.ui_print_help_icon('snmp_trap_types', true); -$table->data[3][3] = html_print_input_text('snmp_type', $snmp_type, '', 50, 255, true); +$table->data[3][2] = __('SNMP Type'); +$table->data[3][3] = html_print_input_text( + 'snmp_type', + $snmp_type, + '', + 50, + 255, + true +); $types = [ 0 => 'Cold start (0)', @@ -90,7 +138,17 @@ $types = [ 5 => 'EGP neighbor loss (5)', 6 => 'Enterprise (6)', ]; -$table->data[3][3] = html_print_select($types, 'snmp_type', $snmp_type, '', __('Select'), -1, true, false, false); +$table->data[3][3] = html_print_select( + $types, + 'snmp_type', + $snmp_type, + '', + __('Select'), + -1, + true, + false, + false +); $traps_generator .= html_print_table($table, true); diff --git a/pandora_console/godmode/tag/tag.php b/pandora_console/godmode/tag/tag.php index d717a9095e..8a8ddc8887 100644 --- a/pandora_console/godmode/tag/tag.php +++ b/pandora_console/godmode/tag/tag.php @@ -117,7 +117,14 @@ if (is_metaconsole()) { // ui_meta_print_header(__('Tags'), "", $buttons); } else { // Header - ui_print_page_header(__('Tags configuration'), 'images/tag.png', false, 'tags_config', true, $buttons); + ui_print_page_header( + __('Tags configuration'), + 'images/tag.png', + false, + 'tags_config', + true, + $buttons + ); } // Two actions can performed in this page: search and delete tags @@ -191,7 +198,7 @@ if (!empty($result)) { $table = new stdClass(); $table->width = '100%'; - $table->class = 'databox data'; + $table->class = 'info_table'; $table->data = []; $table->head = []; @@ -278,12 +285,14 @@ if (!empty($result)) { $data[5] = $output; - $data[6] = "".html_print_image('images/config.png', true, ['title' => 'Edit']).'  '; + $table->cellclass[][6] = 'action_buttons'; + $data[6] = "".html_print_image('images/config.png', true, ['title' => 'Edit']).''; $data[6] .= ''.html_print_image('images/cross.png', true, ['title' => 'Delete']).''; array_push($table->data, $data); } html_print_table($table); + ui_pagination($total_tags, $url, 0, 0, false, 'offset', true, 'pagination-bottom'); } else { if (is_metaconsole()) { ui_toggle($filter_form, __('Show Options')); diff --git a/pandora_console/godmode/update_manager/update_manager.css b/pandora_console/godmode/update_manager/update_manager.css index f68c92ea94..168c6fcf7a 100644 --- a/pandora_console/godmode/update_manager/update_manager.css +++ b/pandora_console/godmode/update_manager/update_manager.css @@ -140,6 +140,162 @@ } #box_online { - background-color: #e6e6e6; - padding: 10px; + background-image: url("../../images/update_manager_background.jpg"); + background-size: cover; + background-position: center center; + background-repeat: no-repeat; + background-color: #fff; + padding: 40px 50px; + border: 1px solid #f3f3f3; + border-radius: 5px; + min-height: 600px; +} + +div#box_online * { + font-size: 16pt; + font-family: "Open Sans", sans-serif; +} + +#box_online .content { + max-width: 60%; +} + +.update_popup { + display: flex; + justify-content: space-between; + align-items: center; + padding-left: 10px; + padding-right: 10px; +} + +.update_icon { + padding-left: 20px; +} + +.update_text h3 { + font-weight: bold; + font-size: 12pt; +} + +.update_text p { + font-size: 11pt; +} + +.update_text a { + font-size: 11pt; + color: #82b92e !important; +} + +.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { + float: left !important; + padding-left: 19px; + padding-bottom: 5px; +} + +.ui-dialog-buttonset > button.ui-button.ui-corner-all.ui-widget { + background-color: #cecece !important; + border: none !important; + border-radius: 2px !important; + text-transform: uppercase !important; + font-weight: bold !important; +} + +.ui-dialog-buttonset > button.success_button.ui-button.ui-corner-all.ui-widget, +.update_manager_button { + background-color: #82b92e !important; + color: #fff !important; + border-radius: 2px !important; + text-transform: uppercase !important; + font-weight: bold !important; +} + +a.update_manager_button { + padding: 10px 12px; + margin-top: 10px; + display: inline-flex; + align-items: center; + font-size: 16px !important; + border-radius: 4px !important; + text-decoration: none; + font-family: "Open Sans", sans-serif; +} + +a.update_manager_button:after { + content: url(../../images/update_manager_button.png); + padding-left: 10px; +} + +.progressbar { + margin-top: 15px; +} + +.ui-draggable, +.ui-draggable .ui-dialog-titlebar { + cursor: default !important; +} + +#box_online #pkg_version { + color: #82b92e; + font-size: 75pt; + font-weight: bold; +} + +/* METACONSOLE */ +.box_online_meta { + background: none !important; + min-height: 400px !important; + text-align: center; + border: none !important; +} + +div#box_online.box_online_meta * { + font-size: 14pt; +} + +#box_online.box_online_meta .content { + max-width: 100%; +} + +#box_online.box_online_meta #pkg_version { + font-size: 60pt; +} + +/* COMMUNITY */ +.update_manager_open { + max-width: 50%; + font-size: 10pt; + margin-top: 40px; + padding: 20px; + border: 1px solid #eaeaea; + border-radius: 5px; +} + +.update_manager_warning { + display: flex; + align-items: center; + margin-bottom: 10px; +} + +.update_manager_warning p { + font-size: 10pt !important; +} + +.update_manager_warning img { + padding-right: 20px; + width: 90px; +} + +a.update_manager_button_open { + padding: 5px 10px; + font-size: 16px !important; + border-radius: 4px !important; + text-decoration: none; + border: 1px solid #82b92e; + color: #82b92e; + border-radius: 2px; +} + +a.update_manager_button_open:hover { + color: #fff; + background-color: #82b92e; } diff --git a/pandora_console/godmode/update_manager/update_manager.messages.php b/pandora_console/godmode/update_manager/update_manager.messages.php deleted file mode 100644 index 31f9866b01..0000000000 --- a/pandora_console/godmode/update_manager/update_manager.messages.php +++ /dev/null @@ -1,340 +0,0 @@ - $message_id) { - update_manger_set_read_message($message_id, 0); - } -} - -if ($read_action !== false) { - $selected = get_parameter('select_multiple', false); - foreach ($selected as $k => $message_id) { - update_manger_set_read_message($message_id, 1); - } -} - -if ($delete_action !== false) { - $selected = get_parameter('select_multiple', false); - foreach ($selected as $k => $message_id) { - update_manger_set_deleted_message($message_id); - } -} - -$offset = (int) get_parameter('offset', 0); - -$total_messages = update_manager_get_not_deleted_messages(); -if ($total_messages) { - // Get all messages - $sql = 'SELECT data, svn_version, filename, data_rollback, db_field_value FROM tupdate '; - $sql .= 'WHERE description NOT LIKE \'%"'.$config['id_user'].'":1%\' '; - $sql .= 'OR description IS NULL '; - $sql .= 'ORDER BY svn_version DESC '; - $sql .= 'LIMIT '.$offset.','.$config['block_size'].' '; - $um_messages = []; - $um_messages = db_get_all_rows_sql($sql); - - echo '
'; - - html_print_input_hidden('tab', 'messages'); - html_print_input_hidden('offset', $offset); - echo '
'; - html_print_submit_button( - __('Delete'), - 'delete_button', - false, - 'class="sub delete"' - ); - echo '
'; - - echo '
'; - html_print_submit_button( - __('Mark as not read'), - 'not_read_button', - false, - 'class="sub wand"' - ); - echo '
'; - - echo '
'; - html_print_submit_button( - __('Mark as read'), - 'read_button', - false, - 'class="sub upd"' - ); - echo '
'; - - // Pagination - if ($total_messages > $config['block_size']) { - ui_pagination(update_manager_get_total_messages(), false, 0); - } - - $table = new stdClass(); - $table->width = '100%'; - $table->class = 'databox data'; - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->head = []; - $table->data = []; - $table->align = []; - $table->size = []; - $table->id = 'um_messages_table'; - - $table->align[0] = 'left'; - $table->align[1] = 'left'; - $table->align[2] = 'left'; - $table->align[3] = 'left'; - $table->align[4] = 'left'; - - $table->size[0] = '30px'; - $table->size[1] = '100px'; - $table->size[3] = '80px'; - $table->size[4] = '60px'; - - $table->style[0] = 'padding-left: 20px'; - $table->style[1] = 'display: none'; - - $table->head[0] = html_print_checkbox_extended('all_selection[]', 0, false, false, '', '', true); - $table->head[2] = __('Subject'); - - - $i = 0; - foreach ($um_messages as $message) { - $data[0] = html_print_checkbox_extended('select_multiple[]', $message['svn_version'], false, false, '', 'class="check_selection"', true); - $table->cellclass[count($table->data)][0] = 'um_individual_check'; - - $data[1] = $message['svn_version']; - $table->cellclass[count($table->data)][1] = 'um_individual_info'; - - $data[2] = io_safe_output($message['db_field_value']); - $table->cellclass[count($table->data)][2] = 'um_individual_subject'; - - - // Change row class if message is read or not by this user - if (update_manger_get_read_message($message['svn_version'], $message['data_rollback'])) { - $table->rowclass[count($table->data)] = 'um_read_message'; - } else { - $table->rowclass[count($table->data)] = 'um_not_read_message'; - } - - array_push($table->data, $data); - } - - html_print_table($table); - - echo '
'; - html_print_submit_button( - __('Delete'), - 'delete_button', - false, - 'class="sub delete"' - ); - echo '
'; - - echo '
'; - html_print_submit_button( - __('Mark as not read'), - 'not_read_button', - false, - 'class="sub wand"' - ); - echo '
'; - - echo '
'; - html_print_submit_button( - __('Mark as read'), - 'read_button', - false, - 'class="sub upd"' - ); - echo '
'; - echo '
'; - - // Get unread messages to update the notification ball. - // Clean the cache because the unread messages can be different. - db_clean_cache(); - $total_unread_messages = update_manager_get_unread_messages(); -} else { - ui_print_info_message([ 'no_close' => true, 'message' => __('There is not any update manager messages.') ]); -} -?> - - - - diff --git a/pandora_console/godmode/update_manager/update_manager.offline.php b/pandora_console/godmode/update_manager/update_manager.offline.php index 79f9a72d2e..24da1a341f 100644 --- a/pandora_console/godmode/update_manager/update_manager.offline.php +++ b/pandora_console/godmode/update_manager/update_manager.offline.php @@ -1,23 +1,39 @@ - + + - - \ No newline at end of file diff --git a/pandora_console/godmode/update_manager/update_manager.php b/pandora_console/godmode/update_manager/update_manager.php index db91738a17..7954fd0ada 100644 --- a/pandora_console/godmode/update_manager/update_manager.php +++ b/pandora_console/godmode/update_manager/update_manager.php @@ -45,12 +45,6 @@ $buttons = [ ], ]; -if (license_free()) { - $buttons['messages'] = [ - 'active' => ($tab == 'messages') ? true : false, - 'text' => ''.html_print_image('images/email_mc.png', true, ['title' => __('Update manager messages')]).'', - ]; -} switch ($tab) { case 'setup': @@ -59,14 +53,12 @@ switch ($tab) { case 'offline': $title = __('Update manager » Offline'); + $help_header = 'update_manager_offline_tab'; break; case 'online': $title = __('Update manager » Online'); - break; - - case 'messages': - $title = __('Update manager » Messages'); + $help_header = 'update_manager_online_tab'; break; } @@ -74,7 +66,7 @@ ui_print_page_header( $title, 'images/gm_setup.png', false, - '', + $help_header, true, $buttons ); @@ -88,10 +80,6 @@ switch ($tab) { include $config['homedir'].'/godmode/update_manager/update_manager.offline.php'; break; - case 'messages': - include $config['homedir'].'/godmode/update_manager/update_manager.messages.php'; - break; - case 'online': default: include $config['homedir'].'/godmode/update_manager/update_manager.online.php'; diff --git a/pandora_console/godmode/update_manager/update_manager.setup.php b/pandora_console/godmode/update_manager/update_manager.setup.php index 4717dd8681..1a81cf457c 100644 --- a/pandora_console/godmode/update_manager/update_manager.setup.php +++ b/pandora_console/godmode/update_manager/update_manager.setup.php @@ -1,18 +1,36 @@ data[4][1] = html_print_input_password( true ); + +$table->data[5][0] = __('Registration ID:'); +$table->data[5][1] = ''.$config['pandora_uid'].''; + +if (update_manager_verify_registration() === true && users_is_admin()) { + $table->data[6][0] = __('Cancel registration:'); + $table->data[6][1] = ''.__('Unregister').''; +} + + + if (license_free()) { $config['identification_reminder'] = isset($config['identification_reminder']) ? $config['identification_reminder'] : 1; - $table->data[6][0] = __('Pandora FMS community reminder').ui_print_help_tip(__('Every 8 days, a message is displayed to admin users to remember to register this Pandora instance'), true); - $table->data[6][1] = __('Yes').'   '.html_print_radio_button('identification_reminder', 1, '', $config['identification_reminder'], true).'  '; - $table->data[6][1] .= __('No').'   '.html_print_radio_button('identification_reminder', 0, '', $config['identification_reminder'], true); + $table->data[7][0] = __('Pandora FMS community reminder').ui_print_help_tip(__('Every 8 days, a message is displayed to admin users to remember to register this Pandora instance'), true); + $table->data[7][1] = __('Yes').'   '.html_print_radio_button('identification_reminder', 1, '', $config['identification_reminder'], true).'  '; + $table->data[7][1] .= __('No').'   '.html_print_radio_button('identification_reminder', 0, '', $config['identification_reminder'], true); } html_print_input_hidden('action_update_url_update_manager', 1); diff --git a/pandora_console/godmode/users/configure_profile.php b/pandora_console/godmode/users/configure_profile.php index a9adcd0069..418add8aa8 100644 --- a/pandora_console/godmode/users/configure_profile.php +++ b/pandora_console/godmode/users/configure_profile.php @@ -47,7 +47,14 @@ if (!is_metaconsole()) { $buttons[$tab]['active'] = true; - ui_print_page_header(__('User management').' » '.__('Profiles defined on %s', get_product_name()), 'images/gm_users.png', false, '', true, $buttons); + ui_print_page_header( + __('User management').' » '.__('Profiles defined on %s', get_product_name()), + 'images/gm_users.png', + false, + 'configure_profiles_tab', + true, + $buttons + ); $sec2 = 'gusuarios'; } else { user_meta_print_header(); diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index a06bd57f1c..47788284fe 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -90,7 +90,14 @@ if ($meta) { $buttons[$tab]['active'] = true; - ui_print_page_header(__('User detail editor'), 'images/gm_users.png', false, '', true, $buttons); + ui_print_page_header( + __('User detail editor'), + 'images/gm_users.png', + false, + 'profile_tab', + true, + $buttons + ); $sec = 'gusuarios'; } @@ -144,6 +151,12 @@ if ($new_user && $config['admin_can_add_user']) { $user_info['metaconsole_assigned_server'] = ''; $user_info['metaconsole_access_node'] = 0; } + + if ($config['ehorus_user_level_conf']) { + $user_info['ehorus_user_level_user'] = ''; + $user_info['ehorus_user_level_pass'] = ''; + $user_info['ehorus_user_level_enabled'] = true; + } } if ($create_user) { @@ -208,6 +221,19 @@ if ($create_user) { $values['strict_acl'] = (bool) get_parameter('strict_acl', false); $values['session_time'] = (int) get_parameter('session_time', 0); + // eHorus user level conf + if ($config['ehorus_user_level_conf']) { + $values['ehorus_user_level_enabled'] = (bool) get_parameter('ehorus_user_level_enabled', false); + if ($values['ehorus_user_level_enabled'] === true) { + $values['ehorus_user_level_user'] = (string) get_parameter('ehorus_user_level_user'); + $values['ehorus_user_level_pass'] = (string) get_parameter('ehorus_user_level_pass'); + } else { + $values['ehorus_user_level_user'] = null; + $values['ehorus_user_level_pass'] = null; + } + } + + if ($id == '') { ui_print_error_message(__('User ID cannot be empty')); $user_info = $values; @@ -291,6 +317,13 @@ if ($update_user) { $values['timezone'] = (string) get_parameter('timezone'); $values['default_event_filter'] = (int) get_parameter('default_event_filter'); $values['default_custom_view'] = (int) get_parameter('default_custom_view'); + // eHorus user level conf + $values['ehorus_user_level_enabled'] = (bool) get_parameter('ehorus_user_level_enabled', false); + $values['ehorus_user_level_user'] = (string) get_parameter('ehorus_user_level_user'); + $values['ehorus_user_level_pass'] = (string) get_parameter('ehorus_user_level_pass'); + + + $dashboard = get_parameter('dashboard', ''); $visual_console = get_parameter('visual_console', ''); @@ -753,6 +786,7 @@ if (enterprise_installed() && !is_metaconsole()) { $values['Dashboard'] = __('Dashboard'); } + $table->data[12][1] = html_print_select($values, 'section', io_safe_output($user_info['section']), 'show_data_section();', '', -1, true, false, false); if (enterprise_installed()) { @@ -835,6 +869,16 @@ foreach ($event_filter_data as $filter) { $table->data[16][0] = __('Default event filter'); $table->data[16][1] = html_print_select($event_filter, 'default_event_filter', $user_info['default_event_filter'], '', '', __('None'), true, false, false); +if ($config['ehorus_user_level_conf']) { + $table->data[17][0] = __('eHorus user acces enabled'); + $table->data[17][1] = html_print_checkbox('ehorus_user_level_enabled', 1, $user_info['ehorus_user_level_enabled'], true); + $table->data[18][0] = __('eHorus user'); + $table->data[19][0] = __('eHorus password'); + $table->data[18][1] = html_print_input_text('ehorus_user_level_user', $user_info['ehorus_user_level_user'], '', 15, 45, true); + $table->data[19][1] = html_print_input_password('ehorus_user_level_pass', io_output_password($user_info['ehorus_user_level_pass']), '', 15, 45, true); +} + + if ($meta) { enterprise_include_once('include/functions_metaconsole.php'); @@ -926,6 +970,11 @@ $(document).ready (function () { $('#checkbox-metaconsole_agents_manager').trigger('change'); show_data_section(); + $('#checkbox-ehorus_user_level_enabled').change(function () { + switch_ehorus_conf(); + }); + $('#checkbox-ehorus_user_level_enabled').trigger('change'); + }); function show_data_section () { @@ -980,5 +1029,21 @@ function show_data_section () { } } +function switch_ehorus_conf() +{ + if(!$('#checkbox-ehorus_user_level_enabled').prop('checked')) + { + $("#user_configuration_table-18").hide(); + $("#user_configuration_table-19").hide(); + + }else + { + $("#user_configuration_table-18").show(); + $("#user_configuration_table-19").show() + } + + +} + /* ]]> */ diff --git a/pandora_console/godmode/users/profile_list.php b/pandora_console/godmode/users/profile_list.php index 8b23527ac8..da77dffd9f 100644 --- a/pandora_console/godmode/users/profile_list.php +++ b/pandora_console/godmode/users/profile_list.php @@ -51,7 +51,14 @@ if (!defined('METACONSOLE')) { $buttons[$tab]['active'] = true; - ui_print_page_header(__('User management').' » '.__('Profiles defined on %s', get_product_name()), 'images/gm_users.png', false, 'profile', true, $buttons); + ui_print_page_header( + __('User management').' » '.__('Profiles defined on %s', get_product_name()), + 'images/gm_users.png', + false, + 'profile_tab', + true, + $buttons + ); $sec = 'gusuarios'; } else { user_meta_print_header(); @@ -258,7 +265,7 @@ if ($create_profile) { $table = new stdClass(); $table->cellpadding = 0; $table->cellspacing = 0; -$table->class = 'databox profile_list data'; +$table->class = 'info_table profile_list'; $table->width = '100%'; $table->head = []; @@ -353,8 +360,9 @@ foreach ($profiles as $profile) { $data['VW'] = ($profile['vconsole_edit'] ? $img : ''); $data['VM'] = ($profile['vconsole_management'] ? $img : ''); $data['PM'] = ($profile['pandora_management'] ? $img : ''); + $table->cellclass[]['operations'] = 'action_buttons'; $data['operations'] = ''.html_print_image('images/config.png', true, ['title' => __('Edit')]).''; - $data['operations'] .= '  '.html_print_image('images/cross.png', true).''; + $data['operations'] .= ''.html_print_image('images/cross.png', true).''; array_push($table->data, $data); } diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 6b4d19ad28..63caad6d3f 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -38,13 +38,13 @@ $sort = get_parameter('sort', 'none'); $tab = get_parameter('tab', 'user'); $pure = get_parameter('pure', 0); -$selected = 'border: 1px solid black;'; -$selectUserIDUp = ''; -$selectUserIDDown = ''; -$selectFullnameUp = ''; -$selectFullnameDown = ''; -$selectLastConnectUp = ''; -$selectLastConnectDown = ''; +$selected = true; +$selectUserIDUp = false; +$selectUserIDDown = false; +$selectFullnameUp = false; +$selectFullnameDown = false; +$selectLastConnectUp = false; +$selectLastConnectDown = false; $order = null; switch ($sortField) { @@ -110,11 +110,11 @@ switch ($sortField) { default: $selectUserIDUp = $selected; - $selectUserIDDown = ''; - $selectFullnameUp = ''; - $selectFullnameDown = ''; - $selectLastConnectUp = ''; - $selectLastConnectDown = ''; + $selectUserIDDown = false; + $selectFullnameUp = false; + $selectFullnameDown = false; + $selectLastConnectUp = false; + $selectLastConnectDown = false; $order = [ 'field' => 'id_user', 'order' => 'ASC', @@ -300,11 +300,20 @@ if (defined('METACONSOLE')) { ui_toggle($form_filter, __('Users control filter'), __('Toggle filter(s)'), !$search); } +// Urls to sort the table. +$url_up_id = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=id_user&sort=up&pure='.$pure; +$url_down_id = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=id_user&sort=down&pure='.$pure; +$url_up_name = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=fullname&sort=up&pure='.$pure; +$url_down_name = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=fullname&sort=down&pure='.$pure; +$url_up_last = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=last_connect&sort=up&pure='.$pure; +$url_down_last = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=last_connect&sort=down&pure='.$pure; + + $table = new stdClass(); $table->cellpadding = 0; $table->cellspacing = 0; $table->width = '100%'; -$table->class = 'databox data'; +$table->class = 'info_table'; $table->head = []; $table->data = []; @@ -312,9 +321,10 @@ $table->align = []; $table->size = []; $table->valign = []; -$table->head[0] = __('User ID').' '.''.html_print_image('images/sort_up.png', true, ['style' => $selectUserIDUp]).''.''.html_print_image('images/sort_down.png', true, ['style' => $selectUserIDDown]).''; -$table->head[1] = __('Name').' '.''.html_print_image('images/sort_up.png', true, ['style' => $selectFullnameUp ]).''.''.html_print_image('images/sort_down.png', true, ['style' => $selectFullnameDown]).''; -$table->head[2] = __('Last contact').' '.''.html_print_image('images/sort_up.png', true, ['style' => $selectLastConnectUp ]).''.''.html_print_image('images/sort_down.png', true, ['style' => $selectLastConnectDown]).''; +$table->head[0] = __('User ID').ui_get_sorting_arrows($url_up_id, $url_down_id, $selectUserIDUp, $selectUserIDDown); +$table->head[1] = __('Name').ui_get_sorting_arrows($url_up_name, $url_down_name, $selectFullnameUp, $selectFullnameDown); +$table->head[2] = __('Last contact').ui_get_sorting_arrows($url_up_last, $url_down_last, $selectLastConnectUp, $selectLastConnectDown); + $table->head[3] = __('Admin'); $table->head[4] = __('Profile / Group'); $table->head[5] = __('Description'); @@ -514,6 +524,7 @@ foreach ($info as $user_id => $user_info) { $data[5] = ui_print_string_substr($user_info['comments'], 24, true); + $table->cellclass[][6] = 'action_buttons'; if ($user_info['disabled'] == 0) { $data[6] = ''.html_print_image('images/lightbulb.png', true, ['title' => __('Disable')]).''; } else { @@ -535,6 +546,7 @@ foreach ($info as $user_id => $user_info) { } html_print_table($table); +ui_pagination(count($info), false, 0, 0, false, 'offset', true, 'pagination-bottom'); echo '
'; unset($table); diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 9796646fce..9392d03ad4 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -30,7 +30,10 @@ require_once __DIR__.'/Wizard.main.php'; require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_reports.php'; require_once $config['homedir'].'/include/functions_cron.php'; -enterprise_include('include/functions_tasklist.php'); +enterprise_include_once('include/functions_tasklist.php'); +enterprise_include_once('include/functions_cron.php'); + +ui_require_css_file('task_list'); /** * Defined as wizard to guide user to explore running tasks. @@ -93,7 +96,20 @@ class DiscoveryTaskList extends Wizard ] ); - $this->printHeader(); + // Header. + ui_print_page_header( + __('Task list'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); // Show redirected messages from discovery.php. if ($status === 0) { @@ -237,7 +253,7 @@ class DiscoveryTaskList extends Wizard $id_console_task = (int) get_parameter('id_console_task'); if ($id_console_task !== null) { - enterprise_include('cron_task_run', $id_console_task, true); + enterprise_hook('cron_task_run', [$id_console_task, true]); // Trick to avoid double execution. header('Location: '.$this->url); } @@ -345,48 +361,61 @@ class DiscoveryTaskList extends Wizard $recon_tasks = []; } - $table = new StdClass(); - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = '100%'; - $table->class = 'databox data'; - $table->head = []; - $table->data = []; - $table->align = []; - $table->headstyle = []; + $url_ajax = $config['homeurl'].'ajax.php'; + + $table = new StdClass(); + $table->cellpadding = 0; + $table->cellspacing = 0; + $table->width = '100%'; + $table->class = 'info_table'; + $table->head = []; + $table->data = []; + $table->align = []; + $table->headstyle = []; for ($i = 0; $i < 9; $i++) { $table->headstyle[$i] = 'text-align: left;'; } - $table->head[0] = __('Force'); - $table->align[0] = 'left'; + // Status. + $table->headstyle[5] .= 'min-width: 100px; width: 100px;'; + // Task type. + $table->headstyle[6] .= 'min-width: 200px; width: 150px;'; + // Progress. + $table->headstyle[7] .= 'min-width: 150px; width: 150px;'; + // Updated at. + $table->headstyle[8] .= 'min-width: 150px; width: 150px;'; + // Operations. + $table->headstyle[9] .= 'min-width: 150px; width: 150px;'; - $table->head[1] = __('Task name'); - $table->align[1] = 'left'; + $table->head[0] = __('Force'); + $table->align[0] = 'left'; - $table->head[2] = __('Server name'); - $table->align[2] = 'left'; + $table->head[1] = __('Task name'); + $table->align[1] = 'left'; - $table->head[3] = __('Interval'); - $table->align[3] = 'left'; + $table->head[2] = __('Server name'); + $table->align[2] = 'left'; - $table->head[4] = __('Network'); - $table->align[4] = 'left'; + $table->head[3] = __('Interval'); + $table->align[3] = 'left'; - $table->head[5] = __('Status'); - $table->align[5] = 'left'; + $table->head[4] = __('Network'); + $table->align[4] = 'left'; - $table->head[6] = __('Task type'); - $table->align[6] = 'left'; + $table->head[5] = __('Status'); + $table->align[5] = 'left'; - $table->head[7] = __('Progress'); - $table->align[7] = 'left'; + $table->head[6] = __('Task type'); + $table->align[6] = 'left'; - $table->head[8] = __('Updated at'); - $table->align[8] = 'left'; + $table->head[7] = __('Progress'); + $table->align[7] = 'left'; - $table->head[9] = __('Operations'); - $table->align[9] = 'left'; + $table->head[8] = __('Updated at'); + $table->align[8] = 'left'; + + $table->head[9] = __('Operations'); + $table->align[9] = 'left'; foreach ($recon_tasks as $task) { $data = []; @@ -398,15 +427,30 @@ class DiscoveryTaskList extends Wizard // Exceptions: IPAM. $ipam = false; if ($task['id_recon_script'] != null) { - $recon_script_name = db_get_value('name', 'trecon_script', 'id_recon_script', $task['id_recon_script']); - if (io_safe_output($recon_script_name) == 'IPAM Recon' - && enterprise_installed() - ) { - $subnet_obj = json_decode($task['macros'], true); - $subnet = $subnet_obj['1']['value']; - $tipam_task_id = db_get_value('id', 'tipam_network', 'id_recon_task', $task['id_rt']); - $ipam = true; + $recon_script_data = db_get_row( + 'trecon_script', + 'id_recon_script', + $task['id_recon_script'] + ); + if ($recon_script_data !== false) { + $recon_script_name = $recon_script_data['name']; + if (io_safe_output($recon_script_name) == 'IPAM Recon' + && enterprise_installed() + ) { + $subnet_obj = json_decode($task['macros'], true); + $subnet = $subnet_obj['1']['value']; + $tipam_task_id = db_get_value( + 'id', + 'tipam_network', + 'id_recon_task', + $task['id_rt'] + ); + $ipam = true; + } } + } else { + $recon_script_data = false; + $recon_script_name = false; } if ($task['disabled'] == 0 && $server_name !== '') { @@ -424,7 +468,16 @@ class DiscoveryTaskList extends Wizard $data[0] = ''; } - $data[1] = ''.$task['name'].''; + // Name task. + $data[1] = ''; + if ($task['disabled'] != 2) { + $data[1] .= ''; + } + + $data[1] .= ''.$task['name'].''; + if ($task['disabled'] != 2) { + $data[1] .= ''; + } $data[2] = $server_name; @@ -449,15 +502,56 @@ class DiscoveryTaskList extends Wizard } if ($task['id_recon_script'] == 0) { - // Discovery NetScan. - $data[6] = html_print_image( - 'images/network.png', - true, - ['title' => __('Discovery NetScan')] - ).'  '; - $data[6] .= network_profiles_get_name( - $task['id_network_profile'] - ); + // Internal discovery task. + switch ($task['type']) { + case DISCOVERY_CLOUD_AWS_RDS: + // Discovery Applications MySQL. + $data[6] = html_print_image( + 'images/network.png', + true, + ['title' => __('Discovery Cloud RDS')] + ).'  '; + $data[6] .= __('Discovery.Cloud.Aws.RDS'); + break; + + case DISCOVERY_APP_MYSQL: + // Discovery Applications MySQL. + $data[6] = html_print_image( + 'images/network.png', + true, + ['title' => __('Discovery Applications MySQL')] + ).'  '; + $data[6] .= __('Discovery.App.MySQL'); + break; + + case DISCOVERY_APP_ORACLE: + // Discovery Applications Oracle. + $data[6] = html_print_image( + 'images/network.png', + true, + ['title' => __('Discovery Applications Oracle')] + ).'  '; + $data[6] .= __('Discovery.App.Oracle'); + break; + + case DISCOVERY_HOSTDEVICES: + default: + // Discovery NetScan. + $data[6] = html_print_image( + 'images/network.png', + true, + ['title' => __('Discovery NetScan')] + ).'  '; + $str = network_profiles_get_name( + $task['id_network_profile'] + ); + if (!empty($str)) { + $data[6] .= $str; + } else { + $data[6] .= __('Discovery.NetScan'); + } + break; + } } else { // APP recon task. $data[6] = html_print_image( @@ -470,13 +564,7 @@ class DiscoveryTaskList extends Wizard if ($task['status'] <= 0 || $task['status'] > 100) { $data[7] = '-'; } else { - $data[7] = progress_bar( - $task['status'], - 100, - 20, - __('Progress').':'.$task['status'].'%', - 1 - ); + $data[7] = ui_progress($task['status'], '100%', 1.5); } if ($task['utimestamp'] > 0) { @@ -488,6 +576,28 @@ class DiscoveryTaskList extends Wizard $data[8] = __('Not executed yet'); } + if ($task['disabled'] != 2) { + $data[9] = ''; + $data[9] .= html_print_image( + 'images/eye.png', + true + ); + $data[9] .= ''; + } + + if ($task['disabled'] != 2 && $task['utimestamp'] > 0 + && $task['type'] != DISCOVERY_APP_MYSQL + && $task['type'] != DISCOVERY_APP_ORACLE + && $task['type'] != DISCOVERY_CLOUD_AWS_RDS + ) { + $data[9] .= ''; + $data[9] .= html_print_image( + 'images/dynamic_network_icon.png', + true + ); + $data[9] .= ''; + } + if (check_acl( $config['id_user'], $task['id_group'], @@ -495,7 +605,7 @@ class DiscoveryTaskList extends Wizard ) ) { if ($ipam === true) { - $data[9] = ''; } else { // Check if is a H&D, Cloud or Application or IPAM. - $data[9] = 'getTargetWiz($task), + $this->getTargetWiz($task, $recon_script_data), $task['id_rt'] ) ).'">'.html_print_image( @@ -533,6 +643,11 @@ class DiscoveryTaskList extends Wizard $data[9] = ''; } + $table->cellclass[][9] = 'action_buttons'; + + // Div neccesary for modal progress task. + echo ''; + array_push($table->data, $data); } @@ -544,7 +659,12 @@ class DiscoveryTaskList extends Wizard html_print_table($table); } - unset($table); + // Div neccesary for modal map task. + echo ''; + + unset($table); + + ui_require_javascript_file('pandora_taskList'); } return true; @@ -565,25 +685,51 @@ class DiscoveryTaskList extends Wizard /** * Return target url sub-string to edit target task. * - * @param array $task With all data. + * @param array $task With all data. + * @param array $script With all script data or false if undefined. * * @return string */ - public function getTargetWiz($task) + public function getTargetWiz($task, $script=false) { - // TODO: Do not use description. Use recon_script ID instead. - switch ($task['description']) { - case 'Discovery.Application.VMware': - return 'wiz=app&mode=vmware&page=0'; + if ($script !== false) { + switch ($script['type']) { + case DISCOVERY_SCRIPT_CLOUD_AWS: + return 'wiz=cloud&mode=amazonws&page=1'; - case CLOUDWIZARD_AWS_DESCRIPTION: + case DISCOVERY_SCRIPT_APP_VMWARE: + return 'wiz=app&mode=vmware&page=0'; + + case DISCOVERY_SCRIPT_IPAM_RECON: + return ''; + + case DISCOVERY_SCRIPT_IPMI_RECON: + default: + return 'wiz=hd&mode=customnetscan'; + } + } + + switch ($task['type']) { + case DISCOVERY_APP_MYSQL: + return 'wiz=app&mode=mysql&page=0'; + + case DISCOVERY_APP_ORACLE: + return 'wiz=app&mode=oracle&page=0'; + + case DISCOVERY_CLOUD_AWS: + case DISCOVERY_CLOUD_AWS_EC2: return 'wiz=cloud&mode=amazonws&page=1'; - case 'console_task': - return 'wiz=ctask'; + case DISCOVERY_CLOUD_AWS_RDS: + return 'wiz=cloud&mode=amazonws&sub=rds&page=0'; default: - return 'wiz=hd&mode=netscan'; + if ($task['description'] == 'console_task') { + return 'wiz=ctask'; + } else { + return 'wiz=hd&mode=netscan'; + } + break; } } diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index f405641fde..3cc2e3f71d 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -28,7 +28,10 @@ require_once __DIR__.'/Wizard.main.php'; require_once $config['homedir'].'/include/functions_users.php'; -enterprise_include('include/class/CSVImportAgents.class.php'); +require_once $config['homedir'].'/include/class/CustomNetScan.class.php'; +require_once $config['homedir'].'/include/class/ManageNetScanScripts.class.php'; + +enterprise_include_once('include/class/CSVImportAgents.class.php'); enterprise_include_once('include/functions_hostdevices.php'); /** @@ -117,6 +120,7 @@ class HostDevices extends Wizard 'icon' => 'images/wizard/netscan.png', 'label' => __('Net Scan'), ]; + if (enterprise_installed()) { $buttons[] = [ 'url' => $this->url.'&mode=importcsv', @@ -125,6 +129,18 @@ class HostDevices extends Wizard ]; } + $buttons[] = [ + 'url' => $this->url.'&mode=customnetscan', + 'icon' => '/images/wizard/customnetscan.png', + 'label' => __('Custom NetScan'), + ]; + + $buttons[] = [ + 'url' => $this->url.'&mode=managenetscanscripts', + 'icon' => '/images/wizard/managenetscanscripts.png', + 'label' => __('Manage NetScan scripts'), + ]; + $this->prepareBreadcrum( [ [ @@ -133,22 +149,42 @@ class HostDevices extends Wizard ), 'label' => __('Discovery'), ], - ] + ], + true ); - $this->printHeader(); + ui_print_page_header(__('Host & devices'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true)); $this->printBigButtonsList($buttons); return; } if (enterprise_installed()) { - if ($mode == 'importcsv') { - $csv_importer = new CSVImportAgents($this->page, $this->breadcrum); + if ($mode === 'importcsv') { + $csv_importer = new CSVImportAgents( + $this->page, + $this->breadcrum + ); return $csv_importer->runCSV(); } } + if ($mode === 'customnetscan') { + $customnetscan_importer = new CustomNetScan( + $this->page, + $this->breadcrum + ); + return $customnetscan_importer->runCustomNetScan(); + } + + if ($mode === 'managenetscanscripts') { + $managenetscanscript_importer = new ManageNetScanScripts( + $this->page, + $this->breadcrum + ); + return $managenetscanscript_importer->runManageNetScanScript(); + } + if ($mode == 'netscan') { return $this->runNetScan(); } @@ -477,9 +513,15 @@ class HostDevices extends Wizard $task_url = '&task='.$this->task['id_rt']; } - $breadcrum[] = [ - 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd', - 'label' => __($this->label), + $breadcrum = [ + [ + 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery', + 'label' => 'Discovery', + ], + [ + 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd', + 'label' => __($this->label), + ], ]; for ($i = 0; $i < $this->maxPagesNetScan; $i++) { $breadcrum[] = [ @@ -492,7 +534,19 @@ class HostDevices extends Wizard if ($this->page < $this->maxPagesNetScan) { // Avoid to print header out of wizard. $this->prepareBreadcrum($breadcrum); - $this->printHeader(); + ui_print_page_header( + __('NetScan'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); } if (isset($this->page) === true @@ -542,140 +596,158 @@ class HostDevices extends Wizard ) { $form = []; - // Input task name. - $form['inputs'][] = [ - 'label' => ''.__('Task name').'', - 'arguments' => [ - 'name' => 'taskname', - 'value' => $this->task['name'], - 'type' => 'text', - 'size' => 25, - ], - ]; + $str = __('Next'); if (isset($this->task['id_rt']) === true) { - // Propagate id. - $form['inputs'][] = [ - 'arguments' => [ - 'name' => 'task', - 'value' => $this->task['id_rt'], - 'type' => 'hidden', - ], - ]; + $str = __('Update and continue'); } - // Input task name. - $form['inputs'][] = [ - 'label' => ''.__('Comment').'', - 'arguments' => [ - 'name' => 'comment', - 'value' => $this->task['description'], - 'type' => 'text', - 'size' => 25, - ], - ]; - - // Input Discovery Server. - $form['inputs'][] = [ - 'label' => ''.__('Discovery server').''.ui_print_help_tip( - __('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), - true - ), - 'arguments' => [ - 'type' => 'select_from_sql', - 'sql' => sprintf( - 'SELECT id_server, name - FROM tserver - WHERE server_type = %d - ORDER BY name', - SERVER_TYPE_DISCOVERY - ), - 'name' => 'id_recon_server', - 'selected' => $this->task['id_recon_server'], - 'return' => true, - ], - ]; - - // Input Network. - $form['inputs'][] = [ - - 'label' => ''.__('Network').''.ui_print_help_tip( - __('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), - true - ), - 'arguments' => [ - 'name' => 'network', - 'value' => $this->task['subnet'], - 'type' => 'text', - 'size' => 25, - ], - ]; - - // Input Group. - $form['inputs'][] = [ - 'label' => ''.__('Group').'', - 'arguments' => [ - 'name' => 'id_group', - 'returnAllGroup' => false, - 'privilege' => 'PM', - 'type' => 'select_groups', - 'selected' => $this->task['id_group'], - 'return' => true, - ], - ]; - // Interval and schedules. $interv_manual = 0; if ((int) $this->task['interval_sweep'] == 0) { $interv_manual = 1; } - // Schedule. - $form['inputs'][] = [ - 'label' => ''.__('Interval').''.ui_print_help_tip( - __('Manual interval means that it will be executed only On-demand'), - true - ), - 'arguments' => [ - 'type' => 'select', - 'selected' => $interv_manual, - 'fields' => [ - 0 => __('Defined'), - 1 => __('Manual'), + $form['rows'][0]['new_form_block'] = true; + + $form['rows'][0]['columns'][0] = [ + 'width' => '30%', + 'style' => 'padding: 9px;', + 'inputs' => [ + '0' => [ + 'arguments' => [ + 'name' => 'submit', + 'label' => $str, + 'type' => 'submit', + 'attributes' => 'class="sub next"', + 'return' => true, + ], + ], + '1' => '
'.html_print_image('images/wizard/netscan_green.png', true, ['title' => __('Close')], false).'
', + '2' => [ + 'label' => ''.__('Interval').':'.ui_print_help_tip( + __('Manual interval means that it will be executed only On-demand'), + true + ), + 'arguments' => [ + 'type' => 'select', + 'selected' => $interv_manual, + 'fields' => [ + 0 => __('Defined'), + 1 => __('Manual'), + ], + 'name' => 'interval_manual_defined', + 'return' => true, + ], + 'extra' => ''.html_print_extended_select_for_time( + 'interval', + $this->task['interval_sweep'], + '', + '', + '0', + false, + true, + false, + false + ).ui_print_help_tip( + __('The minimum recomended interval for Recon Task is 5 minutes'), + true + ).'', + ], - 'name' => 'interval_manual_defined', - 'return' => true, ], - 'extra' => ''.html_print_extended_select_for_time( - 'interval', - $this->task['interval_sweep'], - '', - '', - '0', - false, - true, - false, - false - ).ui_print_help_tip( - __('The minimum recomended interval for Recon Task is 5 minutes'), - true - ).'', ]; - $str = __('Next'); + $form['rows'][0]['columns'][1] = [ + 'width' => '40%', + 'padding-right' => '12%', + 'padding-left' => '5%', + 'inputs' => [ + '0' => [ + 'label' => ''.__('Task name').':', + 'arguments' => [ + 'name' => 'taskname', + 'value' => $this->task['name'], + 'type' => 'text', + 'size' => 25, + 'class' => 'discovery_full_width_input', + ], + ], + '1' => [ + 'label' => ''.__('Discovery server').':'.ui_print_help_tip( + __('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), + true + ), + 'arguments' => [ + 'type' => 'select_from_sql', + 'sql' => sprintf( + 'SELECT id_server, name + FROM tserver + WHERE server_type = %d + ORDER BY name', + SERVER_TYPE_DISCOVERY + ), + 'name' => 'id_recon_server', + 'style' => 'width: 100%;', + 'selected' => $this->task['id_recon_server'], + 'return' => true, + ], + ], + '2' => [ + 'label' => ''.__('Network').':'.ui_print_help_tip( + __('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), + true + ), + 'arguments' => [ + 'name' => 'network', + 'value' => $this->task['subnet'], + 'type' => 'text', + 'size' => 25, + 'class' => 'discovery_full_width_input', + ], + ], + ], + ]; - if (isset($this->task['id_rt']) === true) { - $str = __('Update and continue'); - } + // Group select (custom for this section). + $group_select = '
'; - // Submit button. - $form['inputs'][] = [ - 'arguments' => [ - 'name' => 'submit', - 'label' => $str, - 'type' => 'submit', - 'attributes' => 'class="sub next"', - 'return' => true, + $group_select .= $this->printInput( + [ + 'name' => 'id_group', + 'returnAllGroup' => false, + 'privilege' => 'PM', + 'type' => 'select_groups', + 'selected' => $this->task['id_group'], + 'return' => true, + 'class' => 'discovery_list_input', + 'size' => 9, + 'simple_multiple_options' => true, + ] + ); + + $form['rows'][0]['columns'][2] = [ + 'width' => '30%', + 'inputs' => ['0' => $group_select], + ]; + + $form['rows'][1]['style'] = 'style de row'; + $form['rows'][1]['columns'][0] = [ + 'padding-right' => '0', + 'inputs' => [ + '0' => [ + 'label' => ''.__('Comment').':', + 'arguments' => [ + 'name' => 'comment', + 'rows' => 1, + 'columns' => 1, + 'value' => $this->task['description'], + 'type' => 'textarea', + 'size' => 25, + 'class' => 'discovery_textarea_input', + 'return' => true, + ], + ], ], ]; @@ -698,23 +770,21 @@ class HostDevices extends Wizard } $form['js'] = ' -$("select#interval_manual_defined").change(function() { - if ($("#interval_manual_defined").val() == 1) { - $("#interval_manual_container").hide(); - $("#text-interval_text").val(0); - $("#hidden-interval").val(0); - } - else { - $("#interval_manual_container").show(); - $("#text-interval_text").val(10); - $("#hidden-interval").val('.$interval.'); - $("#interval_units").val('.$unit.'); - } -}).change();'; + $("select#interval_manual_defined").change(function() { + if ($("#interval_manual_defined").val() == 1) { + $("#interval_manual_container").hide(); + $("#text-interval_text").val(0); + $("#hidden-interval").val(0); + } + else { + $("#interval_manual_container").show(); + $("#text-interval_text").val(10); + $("#hidden-interval").val('.$interval.'); + $("#interval_units").val('.$unit.'); + } + }).change();'; - // XXX: Could be improved validating inputs before continue (JS) - // Print NetScan page 0. - $this->printForm($form); + $this->printFormAsGrid($form); } } @@ -731,7 +801,6 @@ $("select#interval_manual_defined").change(function() { ], ]; - // Hidden, page. $form['inputs'][] = [ 'arguments' => [ 'name' => 'page', @@ -742,10 +811,9 @@ $("select#interval_manual_defined").change(function() { ]; $form['inputs'][] = [ - 'extra' => '

Please, configure task '.io_safe_output($this->task['name']).'

', + 'extra' => '

Please, configure task '.io_safe_output($this->task['name']).'

', ]; - // Input: Module template. $form['inputs'][] = [ 'label' => __('Module template'), 'arguments' => [ @@ -758,7 +826,6 @@ $("select#interval_manual_defined").change(function() { 'selected' => $this->task['id_network_profile'], 'nothing_value' => 0, 'nothing' => __('None'), - ], ]; @@ -809,7 +876,7 @@ $("select#interval_manual_defined").change(function() { 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'], ]; - $this->printForm($form); + $this->printFormAsList($form); } if ($this->page == 2) { diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index c763e0ff29..f76678ffb6 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -26,14 +26,15 @@ * ============================================================================ */ -define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2'); +// Begin. -/** - * Global Wizard generic class. Needs to be inherited. - * - * Used in Hostdevices class, Applications class and others, is the core of - * Discovery proyect. - */ + + /** + * Global Wizard generic class. Needs to be inherited. + * + * Used in Hostdevices class, Applications class and others, is the core of + * Discovery proyect. + */ class Wizard { @@ -190,15 +191,18 @@ class Wizard * Builder for breadcrum * * @param array $urls Array of urls to be stored in breadcrum. - * @param boolean $add True if breadcrum should be added instead of - * overwrite it. + * @param boolean $add True if breadcrum should be added + * instead of overwrite it. * * @return void */ - public function prepareBreadcrum(array $urls, bool $add=false) - { + public function prepareBreadcrum( + array $urls, + bool $add=false + ) { $bc = []; $i = 0; + foreach ($urls as $url) { if ($url['selected'] == 1) { $class = 'selected'; @@ -206,9 +210,12 @@ class Wizard $class = ''; } - $bc[$i] = '
'; - $bc[$i] .= '
'.$url['label']; - $bc[$i++] .= '
'; + $bc[$i] = ''; + $bc[$i] .= ''; + $bc[$i] .= $url['label']; + $bc[$i] .= ''; + $bc[$i] .= ''; + $i++; } if ($add === true) { @@ -216,7 +223,6 @@ class Wizard } else { $this->setBreadcrum($bc); } - } @@ -256,7 +262,10 @@ class Wizard */ public function printBreadcrum() { - return '

'.implode('', $this->breadcrum).'

'; + return implode( + ' / ', + $this->breadcrum + ); } @@ -464,7 +473,9 @@ class Wizard ((isset($data['keys_field']) === true) ? $data['keys_field'] : 'id_grupo'), ((isset($data['strict_user']) === true) ? $data['strict_user'] : false), ((isset($data['delete_groups']) === true) ? $data['delete_groups'] : false), - ((isset($data['include_groups']) === true) ? $data['include_groups'] : false) + ((isset($data['include_groups']) === true) ? $data['include_groups'] : false), + ((isset($data['size']) === true) ? $data['size'] : false), + ((isset($data['simple_multiple_options']) === true) ? $data['simple_multiple_options'] : false) ); case 'submit': @@ -572,14 +583,18 @@ class Wizard { $output = ''; if ($input['hidden'] == 1) { - $class = ' class="hidden"'; + $class = ' hidden'; } else { $class = ''; } + if (isset($input['class']) === true) { + $class = $input['class'].$class; + } + if (is_array($input['block_content']) === true) { // Print independent block of inputs. - $output .= '
  • '; + $output .= '
  • '; $output .= '
      '; foreach ($input['block_content'] as $input) { $output .= $this->printBlock($input, $return); @@ -588,7 +603,163 @@ class Wizard $output .= '
  • '; } else { if ($input['arguments']['type'] != 'hidden') { - $output .= '
  • '; + $output .= '
  • '; + $output .= ''; + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + $output .= '
  • '; + } else { + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + } + } + + if ($return === false) { + echo $output; + } + + return $output; + } + + + /** + * Print a block of inputs with grid format. + * + * @param array $input Definition of target block to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML content. + */ + public function printBlockAsGrid(array $input, bool $return=false) + { + $output = ''; + if ($input['hidden'] == 1) { + $class = ' hidden'; + } else { + $class = ''; + } + + if (isset($input['class']) === true) { + $class = $input['class'].$class; + } + + if (is_array($input['block_content']) === true) { + // Print independent block of inputs. + $output .= '
  • '; + $output .= '
      '; + foreach ($input['block_content'] as $input) { + $output .= $this->printBlockAsGrid($input, $return); + } + + $output .= '
  • '; + } else { + if ($input['arguments']['type'] != 'hidden') { + if ($input['arguments']['inline'] != 'true') { + $output .= '
    '; + } else { + $output .= '
    '; + if (!isset($input['extra'])) { + $output .= '
    '; + } + + if (isset($input['extra'])) { + $output .= '
    '; + } + } + + if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) { + $output .= '
    '; + } + + $output .= '
    '; + $output .= $input['label']; + $output .= '
    '; + + if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) { + $output .= '
    '; + } + + if ($input['arguments']['inline'] == 'true' && !isset($input['extra'])) { + $output .= '
    '; + } + + if ($input['arguments']['type'] == 'text' || $input['arguments']['type'] == 'text_extended') { + $output .= '
    '; + $output .= $this->printInput($input['arguments']); + $output .= '
    '; + } else if ($input['arguments']['inline'] == 'true') { + $output .= '
    '; + + if (isset($input['extra'])) { + $output .= '
    '; + } else { + $output .= '
    '; + } + + $output .= $this->printInput($input['arguments']); + $output .= '
    '; + $output .= '
    '; + + if (isset($input['extra'])) { + $output .= '
    '; + } + } else { + $output .= $this->printInput($input['arguments']); + } + + // Allow dynamic content. + $output .= $input['extra']; + $output .= '
    '; + } else { + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + } + } + + if ($return === false) { + echo $output; + } + + return $output; + } + + + /** + * Print a block of inputs as a list element. + * + * @param array $input Definition of target block to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML content. + */ + public function printBlockAsList(array $input, bool $return=false) + { + $output = ''; + if ($input['hidden'] == 1) { + $class = ' hidden'; + } else { + $class = ''; + } + + if (isset($input['class']) === true) { + $class = $input['class'].$class; + } + + if (is_array($input['block_content']) === true) { + // Print independent block of inputs. + $output .= '
  • '; + $output .= '
      '; + foreach ($input['block_content'] as $input) { + $output .= $this->printBlockAsList($input, $return); + } + + $output .= '
  • '; + } else { + if ($input['arguments']['type'] != 'hidden') { + $output .= '
  • '; $output .= ''; $output .= $this->printInput($input['arguments']); // Allow dynamic content. @@ -612,20 +783,24 @@ class Wizard /** * Print a form. * - * @param array $data Definition of target form to be printed. - * @param boolean $return Return as string or direct output. + * @param array $data Definition of target form to be printed. + * @param boolean $return Return as string or direct output. + * @param boolean $print_white_box Print a white box. * * @return string HTML code. */ - public function printForm(array $data, bool $return=false) - { + public function printForm( + array $data, + bool $return=false, + bool $print_white_box=false + ) { $form = $data['form']; $inputs = $data['inputs']; $js = $data['js']; $cb_function = $data['cb_function']; $cb_args = $data['cb_args']; - $output_head = '
    '; if ($return === false) { @@ -643,13 +818,187 @@ class Wizard error_log('Error executing wizard callback: ', $e->getMessage()); } - $output = '
      '; + $output_submit = ''; + $output = ''; + + if ($print_white_box === true) { + $output .= '
      '; + } + + $output .= '
        '; foreach ($inputs as $input) { - $output .= $this->printBlock($input, true); + if ($input['arguments']['type'] != 'submit') { + $output .= $this->printBlock($input, true); + } else { + $output_submit .= $this->printBlock($input, true); + } } $output .= '
      '; + + if ($print_white_box === true) { + $output .= '
      '; + } + + $output .= '
        '.$output_submit.'
      '; + $output .= ''; + $output .= ''; + + if ($return === false) { + echo $output; + } + + return $output_head.$output; + + } + + + /** + * Print a form as a grid of inputs. + * + * @param array $data Definition of target form to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML code. + */ + public function printFormAsGrid(array $data, bool $return=false) + { + $form = $data['form']; + + $rows = $data['rows']; + + $js = $data['js']; + $cb_function = $data['cb_function']; + $cb_args = $data['cb_args']; + + $output_head = '
      '; + + if ($return === false) { + echo $output_head; + } + + try { + if (isset($cb_function) === true) { + call_user_func_array( + $cb_function, + (isset($cb_args) === true) ? $cb_args : [] + ); + } + } catch (Exception $e) { + error_log('Error executing wizard callback: ', $e->getMessage()); + } + + $output_submit = ''; + $output = ''; + + $first_block_printed = false; + + foreach ($rows as $row) { + if ($row['new_form_block'] == true) { + if ($first_block_printed === true) { + // If first form block has been placed, then close it before starting a new one. + $output .= '
  • '; + $output .= '
    '; + } else { + $output .= '
    '; + } + + $first_block_printed = true; + } + + $output .= '
    '; + + foreach ($row['columns'] as $column) { + $width = isset($column['width']) ? 'width: '.$column['width'].';' : 'width: 100%;'; + $padding_left = isset($column['padding-left']) ? 'padding-left: '.$column['padding-left'].';' : 'padding-left: 0;'; + $padding_right = isset($column['padding-right']) ? 'padding-right: '.$column['padding-right'].';' : 'padding-right: 0;'; + $extra_styles = isset($column['style']) ? $column['style'] : ''; + + $output .= '
    '; + + foreach ($column['inputs'] as $input) { + if (is_array($input)) { + if ($input['arguments']['type'] != 'submit') { + $output .= $this->printBlockAsGrid($input, true); + } else { + $output_submit .= $this->printBlockAsGrid($input, true); + } + } else { + $output .= $input; + } + } + + $output .= '
    '; + } + + $output .= '
    '; + } + + $output .= '
    '; + + $output .= '
      '.$output_submit.'
    '; + $output .= ''; + $output .= ''; + + if ($return === false) { + echo $output; + } + + return $output_head.$output; + + } + + + /** + * Print a form as a list. + * + * @param array $data Definition of target form to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML code. + */ + public function printFormAsList(array $data, bool $return=false) + { + $form = $data['form']; + $inputs = $data['inputs']; + $js = $data['js']; + $cb_function = $data['cb_function']; + $cb_args = $data['cb_args']; + + $output_head = '
    '; + + if ($return === false) { + echo $output_head; + } + + try { + if (isset($cb_function) === true) { + call_user_func_array( + $cb_function, + (isset($cb_args) === true) ? $cb_args : [] + ); + } + } catch (Exception $e) { + error_log('Error executing wizard callback: ', $e->getMessage()); + } + + $output = '
    '; + $output .= '
      '; + + foreach ($inputs as $input) { + if ($input['arguments']['type'] != 'submit') { + $output .= $this->printBlockAsList($input, true); + } else { + $output_submit .= $this->printBlockAsList($input, true); + } + } + + $output .= '
    '; + $output .= '
    '; + $output .= '
      '.$output_submit.'
    '; $output .= '
    '; $output .= ''; diff --git a/pandora_console/images/arrow_down_green.png b/pandora_console/images/arrow_down_green.png new file mode 100644 index 0000000000..edc1cff1b8 Binary files /dev/null and b/pandora_console/images/arrow_down_green.png differ diff --git a/pandora_console/images/arrow_down_white.png b/pandora_console/images/arrow_down_white.png new file mode 100644 index 0000000000..7b28df71f9 Binary files /dev/null and b/pandora_console/images/arrow_down_white.png differ diff --git a/pandora_console/images/arrow_right_green.png b/pandora_console/images/arrow_right_green.png new file mode 100644 index 0000000000..a772cd6cf4 Binary files /dev/null and b/pandora_console/images/arrow_right_green.png differ diff --git a/pandora_console/images/arrow_up_green.png b/pandora_console/images/arrow_up_green.png new file mode 100644 index 0000000000..c197c2333c Binary files /dev/null and b/pandora_console/images/arrow_up_green.png differ diff --git a/pandora_console/images/arrow_up_white.png b/pandora_console/images/arrow_up_white.png new file mode 100644 index 0000000000..2fbd55b69a Binary files /dev/null and b/pandora_console/images/arrow_up_white.png differ diff --git a/pandora_console/images/custom_logo/pandora_logo_head_3.png b/pandora_console/images/custom_logo/pandora_logo_head_3.png index 5bce825279..c39d604af8 100644 Binary files a/pandora_console/images/custom_logo/pandora_logo_head_3.png and b/pandora_console/images/custom_logo/pandora_logo_head_3.png differ diff --git a/pandora_console/images/custom_logo/pandora_logo_head_4.png b/pandora_console/images/custom_logo/pandora_logo_head_4.png index 275871dca6..8bf5fbb1d3 100644 Binary files a/pandora_console/images/custom_logo/pandora_logo_head_4.png and b/pandora_console/images/custom_logo/pandora_logo_head_4.png differ diff --git a/pandora_console/images/custom_logo/pandora_logo_head_5.png b/pandora_console/images/custom_logo/pandora_logo_head_5.png new file mode 100644 index 0000000000..275871dca6 Binary files /dev/null and b/pandora_console/images/custom_logo/pandora_logo_head_5.png differ diff --git a/pandora_console/images/custom_logo/pandora_logo_head_6.png b/pandora_console/images/custom_logo/pandora_logo_head_6.png new file mode 100644 index 0000000000..5bce825279 Binary files /dev/null and b/pandora_console/images/custom_logo/pandora_logo_head_6.png differ diff --git a/pandora_console/images/custom_logo/pandora_logo_head_green.png b/pandora_console/images/custom_logo/pandora_logo_head_green.png deleted file mode 100644 index 8bf5fbb1d3..0000000000 Binary files a/pandora_console/images/custom_logo/pandora_logo_head_green.png and /dev/null differ diff --git a/pandora_console/images/darrowleft_green.png b/pandora_console/images/darrowleft_green.png new file mode 100644 index 0000000000..6262dd7e2d Binary files /dev/null and b/pandora_console/images/darrowleft_green.png differ diff --git a/pandora_console/images/darrowright_green.png b/pandora_console/images/darrowright_green.png new file mode 100644 index 0000000000..ccac0d6690 Binary files /dev/null and b/pandora_console/images/darrowright_green.png differ diff --git a/pandora_console/images/firts_task/icono_aws.png b/pandora_console/images/firts_task/icono_aws.png new file mode 100644 index 0000000000..c5f0c3a547 Binary files /dev/null and b/pandora_console/images/firts_task/icono_aws.png differ diff --git a/pandora_console/images/gm_discovery.menu.png b/pandora_console/images/gm_discovery.menu.png index b33975dcec..5c0296b562 100644 Binary files a/pandora_console/images/gm_discovery.menu.png and b/pandora_console/images/gm_discovery.menu.png differ diff --git a/pandora_console/images/gm_discovery.menu_white.png b/pandora_console/images/gm_discovery.menu_white.png index d05d5e7616..80d0913c90 100644 Binary files a/pandora_console/images/gm_discovery.menu_white.png and b/pandora_console/images/gm_discovery.menu_white.png differ diff --git a/pandora_console/images/go_first_g.png b/pandora_console/images/go_first_g.png new file mode 100644 index 0000000000..dcb0fe41b8 Binary files /dev/null and b/pandora_console/images/go_first_g.png differ diff --git a/pandora_console/images/go_last_g.png b/pandora_console/images/go_last_g.png new file mode 100644 index 0000000000..ce49963baa Binary files /dev/null and b/pandora_console/images/go_last_g.png differ diff --git a/pandora_console/images/go_next_g.png b/pandora_console/images/go_next_g.png new file mode 100644 index 0000000000..08601a2a3e Binary files /dev/null and b/pandora_console/images/go_next_g.png differ diff --git a/pandora_console/images/go_previous_g.png b/pandora_console/images/go_previous_g.png new file mode 100644 index 0000000000..84bbe0492e Binary files /dev/null and b/pandora_console/images/go_previous_g.png differ diff --git a/pandora_console/images/groups_small_white/application_osx.png b/pandora_console/images/groups_small_white/application_osx.png new file mode 100644 index 0000000000..409d9742d2 Binary files /dev/null and b/pandora_console/images/groups_small_white/application_osx.png differ diff --git a/pandora_console/images/groups_small_white/application_osx_terminal.png b/pandora_console/images/groups_small_white/application_osx_terminal.png new file mode 100644 index 0000000000..3deb76aa34 Binary files /dev/null and b/pandora_console/images/groups_small_white/application_osx_terminal.png differ diff --git a/pandora_console/images/groups_small_white/applications.png b/pandora_console/images/groups_small_white/applications.png new file mode 100644 index 0000000000..362ed8b98d Binary files /dev/null and b/pandora_console/images/groups_small_white/applications.png differ diff --git a/pandora_console/images/groups_small_white/bricks.png b/pandora_console/images/groups_small_white/bricks.png new file mode 100644 index 0000000000..b68255b88b Binary files /dev/null and b/pandora_console/images/groups_small_white/bricks.png differ diff --git a/pandora_console/images/groups_small_white/chart_organisation.png b/pandora_console/images/groups_small_white/chart_organisation.png new file mode 100644 index 0000000000..d80fc4f65f Binary files /dev/null and b/pandora_console/images/groups_small_white/chart_organisation.png differ diff --git a/pandora_console/images/groups_small_white/clock.png b/pandora_console/images/groups_small_white/clock.png new file mode 100644 index 0000000000..dc16f55773 Binary files /dev/null and b/pandora_console/images/groups_small_white/clock.png differ diff --git a/pandora_console/images/groups_small_white/computer.png b/pandora_console/images/groups_small_white/computer.png new file mode 100644 index 0000000000..5eab00e255 Binary files /dev/null and b/pandora_console/images/groups_small_white/computer.png differ diff --git a/pandora_console/images/groups_small_white/database.png b/pandora_console/images/groups_small_white/database.png new file mode 100644 index 0000000000..397f3fa5d3 Binary files /dev/null and b/pandora_console/images/groups_small_white/database.png differ diff --git a/pandora_console/images/groups_small_white/database_gear.png b/pandora_console/images/groups_small_white/database_gear.png new file mode 100644 index 0000000000..72a6b63d0f Binary files /dev/null and b/pandora_console/images/groups_small_white/database_gear.png differ diff --git a/pandora_console/images/groups_small_white/drive_network.png b/pandora_console/images/groups_small_white/drive_network.png new file mode 100644 index 0000000000..4e1cd615c6 Binary files /dev/null and b/pandora_console/images/groups_small_white/drive_network.png differ diff --git a/pandora_console/images/groups_small_white/email.png b/pandora_console/images/groups_small_white/email.png new file mode 100644 index 0000000000..496991da88 Binary files /dev/null and b/pandora_console/images/groups_small_white/email.png differ diff --git a/pandora_console/images/groups_small_white/eye.png b/pandora_console/images/groups_small_white/eye.png new file mode 100644 index 0000000000..f5c8a4e940 Binary files /dev/null and b/pandora_console/images/groups_small_white/eye.png differ diff --git a/pandora_console/images/groups_small_white/firewall.png b/pandora_console/images/groups_small_white/firewall.png new file mode 100644 index 0000000000..261adbcb1e Binary files /dev/null and b/pandora_console/images/groups_small_white/firewall.png differ diff --git a/pandora_console/images/groups_small_white/heart.png b/pandora_console/images/groups_small_white/heart.png new file mode 100644 index 0000000000..6bfec0298a Binary files /dev/null and b/pandora_console/images/groups_small_white/heart.png differ diff --git a/pandora_console/images/groups_small_white/house.png b/pandora_console/images/groups_small_white/house.png new file mode 100644 index 0000000000..72ab42dd35 Binary files /dev/null and b/pandora_console/images/groups_small_white/house.png differ diff --git a/pandora_console/images/groups_small_white/images.png b/pandora_console/images/groups_small_white/images.png new file mode 100644 index 0000000000..195c7e222b Binary files /dev/null and b/pandora_console/images/groups_small_white/images.png differ diff --git a/pandora_console/images/groups_small_white/lightning.png b/pandora_console/images/groups_small_white/lightning.png new file mode 100644 index 0000000000..31a0670a68 Binary files /dev/null and b/pandora_console/images/groups_small_white/lightning.png differ diff --git a/pandora_console/images/groups_small_white/lock.png b/pandora_console/images/groups_small_white/lock.png new file mode 100644 index 0000000000..522ff71bd6 Binary files /dev/null and b/pandora_console/images/groups_small_white/lock.png differ diff --git a/pandora_console/images/groups_small_white/network.png b/pandora_console/images/groups_small_white/network.png new file mode 100644 index 0000000000..1a8573a729 Binary files /dev/null and b/pandora_console/images/groups_small_white/network.png differ diff --git a/pandora_console/images/groups_small_white/plugin.png b/pandora_console/images/groups_small_white/plugin.png new file mode 100644 index 0000000000..051ec05d6b Binary files /dev/null and b/pandora_console/images/groups_small_white/plugin.png differ diff --git a/pandora_console/images/groups_small_white/printer.png b/pandora_console/images/groups_small_white/printer.png new file mode 100644 index 0000000000..4187e87a00 Binary files /dev/null and b/pandora_console/images/groups_small_white/printer.png differ diff --git a/pandora_console/images/groups_small_white/server_database.png b/pandora_console/images/groups_small_white/server_database.png new file mode 100644 index 0000000000..864e3cb7cb Binary files /dev/null and b/pandora_console/images/groups_small_white/server_database.png differ diff --git a/pandora_console/images/groups_small_white/transmit.png b/pandora_console/images/groups_small_white/transmit.png new file mode 100644 index 0000000000..d27f5c377d Binary files /dev/null and b/pandora_console/images/groups_small_white/transmit.png differ diff --git a/pandora_console/images/groups_small_white/without_group.png b/pandora_console/images/groups_small_white/without_group.png new file mode 100644 index 0000000000..30915bd101 Binary files /dev/null and b/pandora_console/images/groups_small_white/without_group.png differ diff --git a/pandora_console/images/groups_small_white/world.png b/pandora_console/images/groups_small_white/world.png new file mode 100644 index 0000000000..dcfd04139b Binary files /dev/null and b/pandora_console/images/groups_small_white/world.png differ diff --git a/pandora_console/images/header_docu.png b/pandora_console/images/header_docu.png new file mode 100644 index 0000000000..2a1c193bed Binary files /dev/null and b/pandora_console/images/header_docu.png differ diff --git a/pandora_console/images/header_down_gray.png b/pandora_console/images/header_down_gray.png index 0cfebc477a..68b302c3ea 100644 Binary files a/pandora_console/images/header_down_gray.png and b/pandora_console/images/header_down_gray.png differ diff --git a/pandora_console/images/header_ready_gray.png b/pandora_console/images/header_ready_gray.png index 9aadb340d5..a1fd9adfb3 100644 Binary files a/pandora_console/images/header_ready_gray.png and b/pandora_console/images/header_ready_gray.png differ diff --git a/pandora_console/images/header_support.png b/pandora_console/images/header_support.png new file mode 100644 index 0000000000..75823214b6 Binary files /dev/null and b/pandora_console/images/header_support.png differ diff --git a/pandora_console/images/header_warning_gray.png b/pandora_console/images/header_warning_gray.png index ca9954d54f..c09319fef4 100644 Binary files a/pandora_console/images/header_warning_gray.png and b/pandora_console/images/header_warning_gray.png differ diff --git a/pandora_console/images/help_g.png b/pandora_console/images/help_g.png new file mode 100644 index 0000000000..60aae95a80 Binary files /dev/null and b/pandora_console/images/help_g.png differ diff --git a/pandora_console/images/help_green.png b/pandora_console/images/help_green.png new file mode 100644 index 0000000000..0d02332988 Binary files /dev/null and b/pandora_console/images/help_green.png differ diff --git a/pandora_console/images/icon_error_db.png b/pandora_console/images/icon_error_db.png new file mode 100644 index 0000000000..1aad380c2f Binary files /dev/null and b/pandora_console/images/icon_error_db.png differ diff --git a/pandora_console/images/icon_error_mr.png b/pandora_console/images/icon_error_mr.png new file mode 100644 index 0000000000..d1e33eed42 Binary files /dev/null and b/pandora_console/images/icon_error_mr.png differ diff --git a/pandora_console/images/icon_info_mr.png b/pandora_console/images/icon_info_mr.png new file mode 100644 index 0000000000..4c0abb0585 Binary files /dev/null and b/pandora_console/images/icon_info_mr.png differ diff --git a/pandora_console/images/icon_success_db.png b/pandora_console/images/icon_success_db.png new file mode 100644 index 0000000000..38511ca06e Binary files /dev/null and b/pandora_console/images/icon_success_db.png differ diff --git a/pandora_console/images/icon_success_mr.png b/pandora_console/images/icon_success_mr.png new file mode 100644 index 0000000000..39c72ea9a1 Binary files /dev/null and b/pandora_console/images/icon_success_mr.png differ diff --git a/pandora_console/images/icon_warning_db.png b/pandora_console/images/icon_warning_db.png new file mode 100644 index 0000000000..f89a7f51b0 Binary files /dev/null and b/pandora_console/images/icon_warning_db.png differ diff --git a/pandora_console/images/imagen-no-acceso.jpg b/pandora_console/images/imagen-no-acceso.jpg new file mode 100644 index 0000000000..93b9256edb Binary files /dev/null and b/pandora_console/images/imagen-no-acceso.jpg differ diff --git a/pandora_console/images/people_1.png b/pandora_console/images/people_1.png old mode 100755 new mode 100644 index 19ad0f4e6a..aa1dd32f32 Binary files a/pandora_console/images/people_1.png and b/pandora_console/images/people_1.png differ diff --git a/pandora_console/images/people_1_old.png b/pandora_console/images/people_1_old.png new file mode 100755 index 0000000000..19ad0f4e6a Binary files /dev/null and b/pandora_console/images/people_1_old.png differ diff --git a/pandora_console/images/people_2.png b/pandora_console/images/people_2.png old mode 100755 new mode 100644 index dd38b8d758..14ba3aaaeb Binary files a/pandora_console/images/people_2.png and b/pandora_console/images/people_2.png differ diff --git a/pandora_console/images/people_2_old.png b/pandora_console/images/people_2_old.png new file mode 100755 index 0000000000..dd38b8d758 Binary files /dev/null and b/pandora_console/images/people_2_old.png differ diff --git a/pandora_console/images/sort_down_black.png b/pandora_console/images/sort_down_black.png new file mode 100644 index 0000000000..13ade460fc Binary files /dev/null and b/pandora_console/images/sort_down_black.png differ diff --git a/pandora_console/images/sort_down_green.png b/pandora_console/images/sort_down_green.png new file mode 100644 index 0000000000..dc6086912d Binary files /dev/null and b/pandora_console/images/sort_down_green.png differ diff --git a/pandora_console/images/sort_up_black.png b/pandora_console/images/sort_up_black.png new file mode 100644 index 0000000000..238d89520f Binary files /dev/null and b/pandora_console/images/sort_up_black.png differ diff --git a/pandora_console/images/sort_up_green.png b/pandora_console/images/sort_up_green.png new file mode 100644 index 0000000000..5c57937f40 Binary files /dev/null and b/pandora_console/images/sort_up_green.png differ diff --git a/pandora_console/images/status_sets/default/module_alertsfired_rounded.png b/pandora_console/images/status_sets/default/module_alertsfired_rounded.png new file mode 100644 index 0000000000..7a9b5ae0cd Binary files /dev/null and b/pandora_console/images/status_sets/default/module_alertsfired_rounded.png differ diff --git a/pandora_console/images/status_sets/default/module_critical_rounded.png b/pandora_console/images/status_sets/default/module_critical_rounded.png new file mode 100644 index 0000000000..7fceda18da Binary files /dev/null and b/pandora_console/images/status_sets/default/module_critical_rounded.png differ diff --git a/pandora_console/images/status_sets/default/module_no_data_rounded.png b/pandora_console/images/status_sets/default/module_no_data_rounded.png new file mode 100644 index 0000000000..fd5e433ece Binary files /dev/null and b/pandora_console/images/status_sets/default/module_no_data_rounded.png differ diff --git a/pandora_console/images/status_sets/default/module_ok_rounded.png b/pandora_console/images/status_sets/default/module_ok_rounded.png new file mode 100644 index 0000000000..d47f2ef4ff Binary files /dev/null and b/pandora_console/images/status_sets/default/module_ok_rounded.png differ diff --git a/pandora_console/images/status_sets/default/module_unknown_rounded.png b/pandora_console/images/status_sets/default/module_unknown_rounded.png new file mode 100644 index 0000000000..2ec6d98f39 Binary files /dev/null and b/pandora_console/images/status_sets/default/module_unknown_rounded.png differ diff --git a/pandora_console/images/status_sets/default/module_warning_rounded.png b/pandora_console/images/status_sets/default/module_warning_rounded.png new file mode 100644 index 0000000000..c28924178d Binary files /dev/null and b/pandora_console/images/status_sets/default/module_warning_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_critical_rounded.png b/pandora_console/images/status_sets/default/severity_critical_rounded.png new file mode 100644 index 0000000000..7fceda18da Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_critical_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_informational_rounded.png b/pandora_console/images/status_sets/default/severity_informational_rounded.png new file mode 100644 index 0000000000..fd5e433ece Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_informational_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_maintenance_rounded.png b/pandora_console/images/status_sets/default/severity_maintenance_rounded.png new file mode 100644 index 0000000000..2ec6d98f39 Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_maintenance_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_major_rounded.png b/pandora_console/images/status_sets/default/severity_major_rounded.png new file mode 100644 index 0000000000..cc6523e28e Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_major_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_minor_rounded.png b/pandora_console/images/status_sets/default/severity_minor_rounded.png new file mode 100644 index 0000000000..fd3ea3d2d9 Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_minor_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_normal_rounded.png b/pandora_console/images/status_sets/default/severity_normal_rounded.png new file mode 100644 index 0000000000..d47f2ef4ff Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_normal_rounded.png differ diff --git a/pandora_console/images/status_sets/default/severity_warning_rounded.png b/pandora_console/images/status_sets/default/severity_warning_rounded.png new file mode 100644 index 0000000000..c28924178d Binary files /dev/null and b/pandora_console/images/status_sets/default/severity_warning_rounded.png differ diff --git a/pandora_console/images/timestamp.png b/pandora_console/images/timestamp.png new file mode 100644 index 0000000000..1750c4acbd Binary files /dev/null and b/pandora_console/images/timestamp.png differ diff --git a/pandora_console/images/tip_help.png b/pandora_console/images/tip_help.png new file mode 100644 index 0000000000..f2704b34ac Binary files /dev/null and b/pandora_console/images/tip_help.png differ diff --git a/pandora_console/images/update_manager_background.jpg b/pandora_console/images/update_manager_background.jpg new file mode 100644 index 0000000000..121e476860 Binary files /dev/null and b/pandora_console/images/update_manager_background.jpg differ diff --git a/pandora_console/images/update_manager_button.png b/pandora_console/images/update_manager_button.png new file mode 100644 index 0000000000..b18b218d78 Binary files /dev/null and b/pandora_console/images/update_manager_button.png differ diff --git a/pandora_console/images/user_email.png b/pandora_console/images/user_email.png new file mode 100644 index 0000000000..095b012a5c Binary files /dev/null and b/pandora_console/images/user_email.png differ diff --git a/pandora_console/images/user_name.png b/pandora_console/images/user_name.png new file mode 100644 index 0000000000..20f823f40e Binary files /dev/null and b/pandora_console/images/user_name.png differ diff --git a/pandora_console/images/user_password.png b/pandora_console/images/user_password.png new file mode 100644 index 0000000000..8e81afd75e Binary files /dev/null and b/pandora_console/images/user_password.png differ diff --git a/pandora_console/images/user_phone.png b/pandora_console/images/user_phone.png new file mode 100644 index 0000000000..050559ed8d Binary files /dev/null and b/pandora_console/images/user_phone.png differ diff --git a/pandora_console/images/welcome_image.png b/pandora_console/images/welcome_image.png new file mode 100644 index 0000000000..b9b745ba33 Binary files /dev/null and b/pandora_console/images/welcome_image.png differ diff --git a/pandora_console/images/wizard/customnetscan.png b/pandora_console/images/wizard/customnetscan.png new file mode 100644 index 0000000000..edc036fa39 Binary files /dev/null and b/pandora_console/images/wizard/customnetscan.png differ diff --git a/pandora_console/images/wizard/managenetscanscripts.png b/pandora_console/images/wizard/managenetscanscripts.png new file mode 100644 index 0000000000..4694ec1e7a Binary files /dev/null and b/pandora_console/images/wizard/managenetscanscripts.png differ diff --git a/pandora_console/images/wizard/netscan_green.png b/pandora_console/images/wizard/netscan_green.png new file mode 100644 index 0000000000..faeae9b042 Binary files /dev/null and b/pandora_console/images/wizard/netscan_green.png differ diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index fef3f3c97c..b8c3705046 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -153,24 +153,48 @@ if ($show_update_action_menu) { $id_alert = (int) get_parameter('id_alert'); $module_name = modules_get_agentmodule_name($id_agent_module); - $agent_alias = modules_get_agentmodule_agent_alias($id_agent); + + $agent_alias = modules_get_agentmodule_agent_alias($id_agent_module); $id_action = (int) get_parameter('id_action'); $actions = alerts_get_alert_agent_module_actions($id_alert); - $action_opction = db_get_row('talert_template_module_actions', 'id_alert_template_module', $id_alert); + $action_opction = db_get_row( + 'talert_template_module_actions', + 'id_alert_template_module', + $id_alert + ); $data .= '
    '; $data .= ''; - $data .= html_print_input_hidden('update_action', 1, true); - $data .= html_print_input_hidden('id_module_action_ajax', $id_module_action, true); + $data .= html_print_input_hidden( + 'update_action', + 1, + true + ); + $data .= html_print_input_hidden( + 'id_module_action_ajax', + $id_module_action, + true + ); if (! $id_agente) { $data .= ''; $data .= ''; $data .= ''; $data .= ''; } @@ -180,7 +204,14 @@ if ($show_update_action_menu) { $data .= __('Module'); $data .= ''; $data .= ''; $data .= ''; $data .= ''; @@ -188,29 +219,72 @@ if ($show_update_action_menu) { $data .= __('Action'); $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= '
    '; - $data .= __('Agent'); + $data .= __('Agent').' '.ui_print_help_icon( + 'alert_scalate', + true, + ui_get_full_url(false, false, false, false) + ); $data .= ''; - $data .= ui_print_truncate_text($agent_alias, 'agent_small', false, true, true, '[…]'); + $data .= ui_print_truncate_text( + $agent_alias, + 'agent_small', + false, + true, + true, + '[…]' + ); $data .= '
    '; - $data .= ui_print_truncate_text($module_name, 'module_small', false, true, true, '[…]'); + $data .= ui_print_truncate_text( + $module_name, + 'module_small', + false, + true, + true, + '[…]' + ); $data .= '
    '; - $data .= html_print_select($actions, 'action_select_ajax', $id_action, '', __('None'), 0, true, false, true, '', false, 'width:150px'); + $data .= html_print_select( + $actions, + 'action_select_ajax', + $id_action, + '', + __('None'), + 0, + true, + false, + true, + '', + false, + 'width:150px' + ); $data .= '
    '; - $data .= __('Number of alerts match from').' '.ui_print_help_icon('alert-matches', true, ui_get_full_url(false, false, false, false)); + $data .= __('Number of alerts match from'); $data .= ''; - $data .= html_print_input_text('fires_min_ajax', $action_opction['fires_min'], '', 4, 10, true); + $data .= html_print_input_text( + 'fires_min_ajax', + $action_opction['fires_min'], + '', + 4, + 10, + true + ); $data .= ' '.__('to').' '; - $data .= html_print_input_text('fires_max_ajax', $action_opction['fires_max'], '', 4, 10, true); + $data .= html_print_input_text( + 'fires_max_ajax', + $action_opction['fires_max'], + '', + 4, + 10, + true + ); $data .= '
    '; - $data .= __('Threshold').' '.ui_print_help_icon('action_threshold', true, ui_get_full_url(false, false, false, false)); + $data .= __('Threshold'); $data .= ''; - $data .= html_print_input_text('module_action_threshold_ajax', $action_opction['module_action_threshold'], '', 4, 10, true); + $data .= html_print_input_text( + 'module_action_threshold_ajax', + $action_opction['module_action_threshold'], + '', + 4, + 10, + true + ); $data .= '
    '; - $data .= html_print_submit_button(__('Update'), 'updbutton', false, ['class' => 'sub next', 'style' => 'float:right'], true); + $data .= html_print_submit_button( + __('Update'), + 'updbutton', + false, + [ + 'class' => 'sub next', + 'style' => 'float:right', + ], + true + ); $data .= '
    '; echo $data; return; diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php index 0cb9626e7f..21d3d11085 100644 --- a/pandora_console/include/ajax/custom_fields.php +++ b/pandora_console/include/ajax/custom_fields.php @@ -1,17 +1,33 @@ $value) { - $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', ".$value['status'].')'; + $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')'; } $values_insert_implode = implode(',', $values_insert); $query_insert = 'INSERT INTO temp_custom_fields VALUES '.$values_insert_implode; db_process_sql($query_insert); - // search table for alias, custom field data, server_name, direction + // Search table for alias, custom field data, server_name, direction. $search_query = ''; if ($search['value'] != '') { $search_query = ' AND (tma.alias LIKE "%'.$search['value'].'%"'; @@ -95,7 +134,61 @@ if (check_login()) { $search_query .= ' OR temp.name_custom_fields LIKE "%'.$search['value'].'%" ) '; } - // query all fields result + // Search for status module. + $status_agent_search = ''; + if (isset($id_status) === true && is_array($id_status) === true) { + if (in_array(-1, $id_status) === false) { + if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $id_status) === false) { + $status_agent_search = ' AND temp.status IN ('.implode(',', $id_status).')'; + } else { + // Not normal statuses. + $status_agent_search = ' AND temp.status IN (1,2,3,4,5)'; + } + } + } + + // Search for status module. + $status_module_search = ''; + if (isset($module_status) === true && is_array($module_status) === true) { + if (in_array(-1, $module_status) === false) { + if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $module_status) === false) { + if (count($module_status) > 0) { + $status_module_search = ' AND ( '; + foreach ($module_status as $key => $value) { + $status_module_search .= ($key != 0) ? ' OR (' : ' ('; + switch ($value) { + default: + case AGENT_STATUS_NORMAL: + $status_module_search .= ' temp.normal_count > 0) '; + break; + case AGENT_STATUS_CRITICAL: + $status_module_search .= ' temp.critical_count > 0) '; + break; + + case AGENT_STATUS_WARNING: + $status_module_search .= ' temp.warning_count > 0) '; + break; + + case AGENT_STATUS_UNKNOWN: + $status_module_search .= ' temp.unknown_count > 0) '; + break; + + case AGENT_STATUS_NOT_INIT: + $status_module_search .= ' temp.notinit_count > 0) '; + break; + } + } + + $status_module_search .= ' ) '; + } + } else { + // Not normal. + $status_module_search = ' AND ( temp.critical_count > 0 OR temp.warning_count > 0 OR temp.unknown_count > 0 AND temp.notinit_count > 0 )'; + } + } + } + + // Query all fields result. $query = sprintf( 'SELECT tma.id_agente, @@ -112,10 +205,14 @@ if (check_login()) { AND temp.id_server = tma.id_tmetaconsole_setup WHERE tma.disabled = 0 %s + %s + %s %s LIMIT %d OFFSET %d ', $search_query, + $status_agent_search, + $status_module_search, $order_by, $length, $start @@ -123,23 +220,27 @@ if (check_login()) { $result = db_get_all_rows_sql($query); - // query count + // Query count. $query_count = sprintf( 'SELECT COUNT(tma.id_agente) AS `count` - FROM tmetaconsole_agent tma - INNER JOIN temp_custom_fields temp - ON temp.id_agent = tma.id_tagente - AND temp.id_server = tma.id_tmetaconsole_setup - WHERE tma.disabled = 0 - %s - ', - $search_query + FROM tmetaconsole_agent tma + INNER JOIN temp_custom_fields temp + ON temp.id_agent = tma.id_tagente + AND temp.id_server = tma.id_tmetaconsole_setup + WHERE tma.disabled = 0 + %s + %s + %s + ', + $search_query, + $status_agent_search, + $status_module_search ); $count = db_get_sql($query_count); - // for link nodes. + // For link nodes. $array_nodes = metaconsole_get_connections(); if (isset($array_nodes) && is_array($array_nodes)) { $hash_array_nodes = []; @@ -158,20 +259,20 @@ if (check_login()) { $user_rot13 = str_rot13($config['id_user']); $hashdata = $user.$pwd; $hashdata = md5($hashdata); - $url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13; + $url_hash = '&loginhash=auto&loginhash_data='.$hashdata.'&loginhash_user='.$user_rot13; $hash_array_nodes[$server['id']]['hashurl'] = $url_hash; $hash_array_nodes[$server['id']]['server_url'] = $server['server_url']; } } - // prepare rows for table dinamic + // Prepare rows for table dinamic. $data = []; foreach ($result as $values) { $image_status = agents_get_image_status($values['status']); - // link nodes - $agent_link = ''; + // Link nodes. + $agent_link = ''; $agent_alias = ui_print_truncate_text( $values['alias'], @@ -198,6 +299,7 @@ if (check_login()) { 'status' => "
    ".$image_status.'
    ', 'id_agent' => $values['id_tagente'], 'id_server' => $values['id_tmetaconsole_setup'], + 'status_value' => $values['status'], ]; } @@ -225,7 +327,7 @@ if (check_login()) { $name_where = " AND tam.nombre LIKE '%".$module_search."%'"; } - // filter by status module + // Filter by status module. $and_module_status = ''; if (is_array($module_status)) { if (!in_array(-1, $module_status)) { @@ -260,7 +362,7 @@ if (check_login()) { $and_module_status .= ' ) '; } } else { - // not normal + // Not normal. $and_module_status = 'AND tae.estado <> 0 AND tae.estado <> 300 '; } } @@ -314,7 +416,12 @@ if (check_login()) { && $value['id_tipo_modulo'] != 23 && $value['id_tipo_modulo'] != 33 ) { - $table_modules->data[$key][1] = remove_right_zeros(number_format($value['datos'], $config['graph_precision'])); + $table_modules->data[$key][1] = remove_right_zeros( + number_format( + $value['datos'], + $config['graph_precision'] + ) + ); } else { $table_modules->data[$key][1] = $value['datos']; } @@ -329,7 +436,10 @@ if (check_login()) { ); $table_modules->data[$key][3] = $value['current_interval']; - $table_modules->data[$key][4] = ui_print_timestamp($value['utimestamp'], true); + $table_modules->data[$key][4] = ui_print_timestamp( + $value['utimestamp'], + true + ); switch ($value['estado']) { case 0: case 300: @@ -398,7 +508,7 @@ if (check_login()) { } } - // status agents from tagente + // Status agents from tagente. $sql_info_agents = 'SELECT * fROM tagente WHERE id_agente ='.$id_agent; $info_agents = db_get_row_sql($sql_info_agents); $status_agent = agents_get_status_from_counts($info_agents); @@ -463,7 +573,13 @@ if (check_login()) { false ); - $table->data[0][3] = html_print_submit_button(__('Load filter'), 'load_filter', false, 'class="sub upd"', true); + $table->data[0][3] = html_print_submit_button( + __('Load filter'), + 'load_filter', + false, + 'class="sub upd"', + true + ); echo "
    "; html_print_table($table); @@ -474,7 +590,12 @@ if (check_login()) { } if ($append_tab_filter) { - $filters = json_decode(io_safe_output(get_parameter('filters', '')), true); + $filters = json_decode( + io_safe_output( + get_parameter('filters', '') + ), + true + ); $table = new StdClass; $table->id = 'save_filter_form'; @@ -485,7 +606,14 @@ if (check_login()) { if ($filters['id'] == 'extended_create_filter') { echo "
    "; $table->data[0][0] = __('Filter name'); - $table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true); + $table->data[0][1] = html_print_input_text( + 'id_name', + '', + '', + 15, + 255, + true + ); $table->data[1][0] = __('Group'); $table->data[1][1] = html_print_select_groups( @@ -510,7 +638,13 @@ if (check_login()) { ); $table->rowspan[0][2] = 2; - $table->data[0][2] = html_print_submit_button(__('Create filter'), 'create_filter', false, 'class="sub upd"', true); + $table->data[0][2] = html_print_submit_button( + __('Create filter'), + 'create_filter', + false, + 'class="sub upd"', + true + ); } else { echo "
    "; echo "
    "; @@ -552,8 +686,20 @@ if (check_login()) { false ); - $table->data[0][2] = html_print_submit_button(__('Delete filter'), 'delete_filter', false, 'class="sub upd"', true); - $table->data[1][2] = html_print_submit_button(__('Update filter'), 'update_filter', false, 'class="sub upd"', true); + $table->data[0][2] = html_print_submit_button( + __('Delete filter'), + 'delete_filter', + false, + 'class="sub upd"', + true + ); + $table->data[1][2] = html_print_submit_button( + __('Update filter'), + 'update_filter', + false, + 'class="sub upd"', + true + ); } html_print_table($table); @@ -561,17 +707,20 @@ if (check_login()) { } if ($create_filter_cf) { - // initialize result + // Initialize result. $result_array = []; $result_array['error'] = 0; $result_array['msg'] = ''; - // initialize vars - $filters = json_decode(io_safe_output(get_parameter('filters', '')), true); + // Initialize vars. + $filters = json_decode( + io_safe_output(get_parameter('filters', '')), + true + ); $name_filter = get_parameter('name_filter', ''); $group_search = get_parameter('group_search', 0); - // check that the name is not empty + // Check that the name is not empty. if ($name_filter == '') { $result_array['error'] = 1; $result_array['msg'] = ui_print_error_message( @@ -596,7 +745,7 @@ if (check_login()) { return; } - // check custom field is not empty + // Check custom field is not empty. if ($filters['id_custom_fields'] == '') { $result_array['error'] = 1; $result_array['msg'] = ui_print_error_message( @@ -608,13 +757,15 @@ if (check_login()) { return; } - // insert + // Insert. $values = []; $values['name'] = $name_filter; $values['group_search'] = $group_search; $values['id_group'] = $filters['group']; $values['id_custom_field'] = $filters['id_custom_fields']; - $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); + $values['id_custom_fields_data'] = json_encode( + $filters['id_custom_fields_data'] + ); $values['id_status'] = json_encode($filters['id_status']); $values['module_search'] = $filters['module_search']; $values['module_status'] = json_encode($filters['module_status']); @@ -622,7 +773,7 @@ if (check_login()) { $insert = db_process_sql_insert('tagent_custom_fields_filter', $values); - // check error insert + // Check error insert. if ($insert) { $result_array['error'] = 0; $result_array['msg'] = ui_print_success_message( @@ -644,17 +795,17 @@ if (check_login()) { } if ($update_filter_cf) { - // initialize result + // Initialize result. $result_array = []; $result_array['error'] = 0; $result_array['msg'] = ''; - // initialize vars + // Initialize vars. $filters = json_decode(io_safe_output(get_parameter('filters', '')), true); $id_filter = get_parameter('id_filter', ''); $group_search = get_parameter('group_search', 0); - // check selected filter + // Check selected filter. if ($id_filter == -1) { $result_array['error'] = 1; $result_array['msg'] = ui_print_error_message( @@ -666,11 +817,11 @@ if (check_login()) { return; } - // array condition update + // Array condition update. $condition = []; $condition['id'] = $id_filter; - // check selected custom fields + // Check selected custom fields. if ($filters['id_custom_fields'] == '') { $result_array['error'] = 1; $result_array['msg'] = ui_print_error_message( @@ -682,7 +833,7 @@ if (check_login()) { return; } - // array values update + // Array values update. $values = []; $values['id_group'] = $filters['group']; $values['group_search'] = $group_search; @@ -693,10 +844,10 @@ if (check_login()) { $values['module_status'] = json_encode($filters['module_status']); $values['recursion'] = $filters['recursion']; - // update + // Update. $update = db_process_sql_update('tagent_custom_fields_filter', $values, $condition); - // check error insert + // Check error insert. if ($update) { $result_array['error'] = 0; $result_array['msg'] = ui_print_success_message( @@ -718,16 +869,16 @@ if (check_login()) { } if ($delete_filter_cf) { - // Initialize result + // Initialize result. $result_array = []; $result_array['error'] = 0; $result_array['msg'] = ''; - // Initialize vars + // Initialize vars. $filters = json_decode(io_safe_output(get_parameter('filters', '')), true); $id_filter = get_parameter('id_filter', ''); - // Check selected filter + // Check selected filter. if ($id_filter == -1) { $result_array['error'] = 1; $result_array['msg'] = ui_print_error_message( @@ -739,14 +890,14 @@ if (check_login()) { return; } - // Array condition update + // Array condition update. $condition = []; $condition['id'] = $id_filter; - // Delete + // Delete. $delete = db_process_sql_delete('tagent_custom_fields_filter', $condition); - // Check error insert + // Check error insert. if ($delete) { $result_array['error'] = 0; $result_array['msg'] = ui_print_success_message( diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 6b7be8eb28..b58a3c2386 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -418,15 +418,15 @@ if ($get_extended_event) { } // Tabs. - $tabs = "
      "; - $tabs .= "
    • ".html_print_image('images/lightning_go.png', true)."".__('General').'
    • '; + $tabs = "
        "; + $tabs .= "
      • ".html_print_image('images/lightning_go.png', true).''.__('General').'
      • '; if (events_has_extended_info($event['id_evento']) === true) { - $tabs .= "
      • ".html_print_image('images/zoom.png', true)."".__('Related').'
      • '; + $tabs .= "
      • ".html_print_image('images/zoom.png', true).''.__('Related').'
      • '; } - $tabs .= "
      • ".html_print_image('images/zoom.png', true)."".__('Details').'
      • '; - $tabs .= "
      • ".html_print_image('images/custom_field_col.png', true)."".__('Agent fields').'
      • '; - $tabs .= "
      • ".html_print_image('images/pencil.png', true)."".__('Comments').'
      • '; + $tabs .= "
      • ".html_print_image('images/zoom.png', true).''.__('Details').'
      • '; + $tabs .= "
      • ".html_print_image('images/custom_field_col.png', true).''.__('Agent fields').'
      • '; + $tabs .= "
      • ".html_print_image('images/pencil.png', true).''.__('Comments').'
      • '; if (!$readonly && ((tags_checks_event_acl( @@ -456,30 +456,30 @@ if ($get_extended_event) { switch ($event['criticity']) { default: case 0: - $img_sev = 'images/status_sets/default/severity_maintenance.png'; + $img_sev = 'images/status_sets/default/severity_maintenance_rounded.png'; break; case 1: - $img_sev = 'images/status_sets/default/severity_informational.png'; + $img_sev = 'images/status_sets/default/severity_informational_rounded.png'; break; case 2: - $img_sev = 'images/status_sets/default/severity_normal.png'; + $img_sev = 'images/status_sets/default/severity_normal_rounded.png'; break; case 3: - $img_sev = 'images/status_sets/default/severity_warning.png'; + $img_sev = 'images/status_sets/default/severity_warning_rounded.png'; break; case 4: - $img_sev = 'images/status_sets/default/severity_critical.png'; + $img_sev = 'images/status_sets/default/severity_critical_rounded.png'; break; case 5: - $img_sev = 'images/status_sets/default/severity_minor.png'; + $img_sev = 'images/status_sets/default/severity_minor_rounded.png'; break; case 6: - $img_sev = 'images/status_sets/default/severity_major.png'; + $img_sev = 'images/status_sets/default/severity_major_rounded.png'; break; } @@ -546,7 +546,7 @@ if ($get_extended_event) { $loading = ''; - $out = '
        '.$tabs.$notifications.$loading.$general.$details.$related.$custom_fields.$comments.$responses.$custom_data.html_print_input_hidden('id_event', $event['id_evento']).'
        '; + $out = '
        '.$tabs.$notifications.$loading.$general.$details.$related.$custom_fields.$comments.$responses.$custom_data.html_print_input_hidden('id_event', $event['id_evento']).'
        '; $js = ''; + + return $output; + } + + + /** + * Generates a simple interface to interact with nodes. + * + * @return string HTML code for simple interface. + */ + public function loadSimpleInterface() + { + $output = ''; + + $output .= ''; + + return $output; + } + + + /** + * Show an advanced interface to manage dialogs. + * + * @return string HTML code with dialogs. + */ + public function loadAdvancedInterface() + { + $list_networkmaps = get_networkmaps($this->idMap); + if (empty($list_networkmaps)) { + $list_networkmaps = []; + } + + $output .= ''; + + $output .= ''; + + $output .= ''; + + $output .= ''; + + return $output; + } + + + /** + * Loads advanced map controller (JS). + * + * @return string HTML code for advanced controller. + */ + public function loadController() + { + $output = ''; + + if (enterprise_installed() + && $this->useTooltipster + ) { + $output .= ''; + } else { + // Generate JS for advanced controller. + $output .= ' + +'; + } + + if ($return === false) { + echo $output; + } + + return $output; + + } + + + /** + * Load networkmap HTML skel and JS requires. + * + * @return string HTML code for skel. + */ + public function loadMapSkel() + { + global $config; + + if (enterprise_installed() + && isset($this->useTooltipster) + && $this->useTooltipster == true + ) { + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''."\n"; + + $output .= '
        fullSize) { + $output .= ' width:100%'; + $output .= ' ;height: 100%">'; + $output .= ''; + } else { + $output .= ' width:'.$this->mapOptions['width'].'px'; + $output .= ' ;height:'.$this->mapOptions['height'].'px">'; + $output .= ''; + } + + $output .= ''; + $output .= '
        '; + } else { + // Load default interface. + ui_require_css_file('networkmap'); + ui_require_css_file('jquery.contextMenu', 'include/styles/js/'); + + $output = ''; + $minimap_display = ''; + if ($this->mapOptions['pure']) { + $minimap_display = 'none'; + } + + $networkmap = $this->map; + if (is_array($networkmap['filter']) === false) { + $networkmap['filter'] = json_decode($networkmap['filter'], true); + } + + $networkmap['filter']['l2_network_interfaces'] = 1; + + $output .= ''; + if (isset($this->map['__simulated']) === false) { + // Load context menu if manageable networkmap. + $output .= ''; + } + + $output .= ''; + + // Open networkconsole_id div. + $output .= '
        fullSize) { + $output .= ' style="width: 100%; height: 100%;position: relative; overflow: hidden; background: #FAFAFA">'; + } else { + $output .= ' style="width: '.$this->mapOptions['width'].'px; height: '.$this->mapOptions['height'].'px;position: relative; overflow: hidden; background: #FAFAFA">'; + } + + $output .= '
        '; + $output .= ''; + $output .= html_print_image('/images/minimap_open_arrow.png', true, ['id' => 'arrow_minimap_'.$networkmap['id']]); + $output .= '
        '; + + $output .= '
        '; + $output .= html_print_image('/images/icono_borrar.png', true, ['id' => 'image_hide_show_labels']); + $output .= '
        '; + + $output .= '
        'image_hide_show_labels']); + $output .= '
        '; + + // Close networkconsole_id div. + $output .= "
        \n"; + } + + return $output; + } + + + /** + * Print all components required to visualizate a network map. + * + * @param boolean $return Return as string or not. + * + * @return string HTML code. + */ + public function printMap($return=false) + { + global $config; + + // ACL. + $networkmap_read = check_acl( + $config['id_user'], + $networkmap['id_group'], + 'MR' + ); + $networkmap_write = check_acl( + $config['id_user'], + $networkmap['id_group'], + 'MW' + ); + $networkmap_manage = check_acl( + $config['id_user'], + $networkmap['id_group'], + 'MM' + ); + + if (!$networkmap_read + && !$networkmap_write + && !$networkmap_manage + ) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access networkmap' + ); + include 'general/noaccess.php'; + return ''; + } + + $user_readonly = !$networkmap_write && !$networkmap_manage; + + if (isset($this->idMap) + && isset($this->map['__simulated']) === false + ) { + $output .= $this->loadMapSkel(); + $output .= $this->loadMapData(); + $output .= $this->loadController(); + if (!$this->noPopUp) { + $output .= $this->loadAdvancedInterface(); + } + } else { + // Simulated, no tmap entries. + $output .= $this->loadMapSkel(); + $output .= $this->loadMapData(); + $output .= $this->loadController(); + if (!$this->noPopUp) { + $output .= $this->loadSimpleInterface(); + } + } + + $output .= ' + + +'; + if ($return === false) { + echo $output; + } + + return $output; + } + + +} diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 3478c10c9c..6cade00145 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,8 +20,8 @@ /** * Pandora build version and version */ -$build_version = 'PC190319'; -$pandora_version = 'v7.0NG.732'; +$build_version = 'PC190612'; +$pandora_version = 'v7.0NG.735'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); @@ -306,3 +306,9 @@ switch ($config['dbtype']) { } // ====================================================================== +// Menu display mode. +if ($_SESSION['menu_type']) { + $config['menu_type'] = $_SESSION['menu_type']; +} else { + $config['menu_type'] = 'classic'; +} diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index b472f98ad8..7266e9eff4 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -195,6 +195,14 @@ define('AGENT_STATUS_UNKNOWN', 3); define('AGENT_STATUS_ALERT_FIRED', 4); define('AGENT_STATUS_WARNING', 2); +// Pseudo criticity analysis. +define('NO_CRIT', -1); +define('CRIT_0', 0); +define('CRIT_1', 1); +define('CRIT_2', 2); +define('CRIT_3', 3); +define('CRIT_4', 4); +define('CRIT_5', 5); // Visual maps contants. // The items kind. @@ -506,6 +514,18 @@ define('OPTION_COLOR_PICKER', 11); define('NODE_TYPE', 0); define('ARROW_TYPE', 1); +// Discovery task steps. +define('STEP_SCANNING', 1); +define('STEP_AFT', 2); +define('STEP_TRACEROUTE', 3); +define('STEP_GATEWAY', 4); + +// Networkmap node types. +define('NODE_AGENT', 0); +define('NODE_MODULE', 1); +define('NODE_PANDORA', 2); +define('NODE_GENERIC', 3); + // SAML attributes constants. define('SAML_ROLE_AND_TAG', 'eduPersonEntitlement'); define('SAML_USER_DESC', 'commonName'); @@ -535,12 +555,55 @@ define('MAP_GENERATION_RADIAL', 2); define('MAP_GENERATION_SPRING1', 3); define('MAP_GENERATION_SPRING2', 4); +// Algorithm: Circo. +define('LAYOUT_CIRCULAR', 0); +// Algorithm: Dot. +define('LAYOUT_FLAT', 1); +// Algorithm: Twopi. +define('LAYOUT_RADIAL', 2); +// Algorithm: Neato. +define('LAYOUT_SPRING1', 3); +// Algorithm: Fdp. +define('LAYOUT_SPRING2', 4); +// Extra: radial dynamic. +define('LAYOUT_RADIAL_DYNAMIC', 6); + +// Map sources. +define('SOURCE_GROUP', 0); +define('SOURCE_TASK', 1); +define('SOURCE_NETWORK', 2); + +// Backward compatibility ~ Migration. define('MAP_SOURCE_GROUP', 0); define('MAP_SOURCE_IP_MASK', 1); define('NETWORKMAP_DEFAULT_WIDTH', 800); define('NETWORKMAP_DEFAULT_HEIGHT', 800); +// Discovery task types. +define('DISCOVERY_HOSTDEVICES', 0); +define('DISCOVERY_HOSTDEVICES_CUSTOM', 1); +define('DISCOVERY_CLOUD_AWS', 2); +define('DISCOVERY_APP_VMWARE', 3); +define('DISCOVERY_APP_MYSQL', 4); +define('DISCOVERY_APP_ORACLE', 5); +define('DISCOVERY_CLOUD_AWS_EC2', 6); +define('DISCOVERY_CLOUD_AWS_RDS', 7); + + +// Discovery types matching definition. +define('DISCOVERY_SCRIPT_HOSTDEVICES_CUSTOM', 0); +// Standard applications. +define('DISCOVERY_SCRIPT_APP_VMWARE', 1); +// Cloud environments. +define('DISCOVERY_SCRIPT_CLOUD_AWS', 2); +define('DISCOVERY_SCRIPT_IPAM_RECON', 3); +define('DISCOVERY_SCRIPT_IPMI_RECON', 4); + +// Discovery task descriptions. +define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2'); +define('CLOUDWIZARD_VMWARE_DESCRIPTION', 'Discovery.App.VMware'); + // Background options. define('CENTER', 0); define('MOSAIC', 1); diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 82b654e374..17f5712d2c 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -205,7 +205,7 @@ function mysql_db_get_value($field, $table, $field_search=1, $condition=1, $sear * * @return mixed The first row of a database query or false. */ -function mysql_db_get_row($table, $field_search, $condition, $fields=false) +function mysql_db_get_row($table, $field_search, $condition, $fields=false, $cache=true) { if (empty($fields)) { $fields = '*'; @@ -243,7 +243,7 @@ function mysql_db_get_row($table, $field_search, $condition, $fields=false) ); } - $result = db_get_all_rows_sql($sql); + $result = db_get_all_rows_sql($sql, false, $cache); if ($result === false) { return false; diff --git a/pandora_console/include/fonts/mem8YaGs126MiZpBA-UFW50bbck.woff2 b/pandora_console/include/fonts/mem8YaGs126MiZpBA-UFW50bbck.woff2 new file mode 100755 index 0000000000..2312604864 Binary files /dev/null and b/pandora_console/include/fonts/mem8YaGs126MiZpBA-UFW50bbck.woff2 differ diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index e1861e70a3..f299153da6 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -243,19 +243,25 @@ function format_numeric($number, $decimals=1) /** * Render numeric data for a graph. It adds magnitude suffix to the number - * (M for millions, K for thousands...) base-10 + * (M for millions, K for thousands...). Base can be modified with divider. * - * TODO: base-2 multiplication - * - * @param float $number Number to be rendered - * @param integer $decimals Numbers after comma. Default value: 1 - * @param dec_point Decimal separator character. Default value: . - * @param thousands_sep Thousands separator character. Default value: , + * @param float $number Number to be rendered. + * @param integer $decimals Numbers after comma (default 1). + * @param string $dec_point Decimal separator character (default .). + * @param string $thousands_sep Thousands separator character (default ,). + * @param integer $divider Number to divide the rendered number. + * @param string $sufix Units of the multiple. * * @return string A string with the number and the multiplier */ -function format_for_graph($number, $decimals=1, $dec_point='.', $thousands_sep=',') -{ +function format_for_graph( + $number, + $decimals=1, + $dec_point='.', + $thousands_sep=',', + $divider=1000, + $sufix='' +) { $shorts = [ '', 'K', @@ -268,15 +274,15 @@ function format_for_graph($number, $decimals=1, $dec_point='.', $thousands_sep=' 'Y', ]; $pos = 0; - while ($number >= 1000) { - // as long as the number can be divided by 1000 + while ($number >= $divider) { + // As long as the number can be divided by divider. $pos++; - // Position in array starting with 0 - $number = ($number / 1000); + // Position in array starting with 0. + $number = ($number / $divider); } - return remove_right_zeros(format_numeric($number, $decimals)).$shorts[$pos]; - // This will actually do the rounding and the decimals + // This will actually do the rounding and the decimals. + return remove_right_zeros(format_numeric($number, $decimals)).$shorts[$pos].$sufix; } @@ -865,12 +871,13 @@ function get_parameter_switch($name, $default='') $data = get_parameter($name, null); if ($data === null) { - return 0; + return (isset($default) ? $default : 0); } else if ($data == 'on') { return 1; } - return 0; + // Return value assigned to switch. + return $data; } @@ -1438,7 +1445,13 @@ function enterprise_include($filename) global $config; // Load enterprise extensions - $filepath = realpath($config['homedir'].'/'.ENTERPRISE_DIR.'/'.$filename); + if (defined('DESTDIR')) { + $destdir = DESTDIR; + } else { + $destdir = ''; + } + + $filepath = realpath($destdir.$config['homedir'].'/'.ENTERPRISE_DIR.'/'.$filename); if ($filepath === false) { return ENTERPRISE_NOT_HOOK; @@ -1750,16 +1763,22 @@ function array_key_to_offset($array, $key) /** * Make a snmpwalk and return it. * - * @param string $ip_target The target address. - * @param string $snmp_version Version of the snmp: 1,2,2c or 3. - * @param string $snmp_community. - * @param string $snmp3_auth_user. - * @param string $snmp3_security_level. - * @param string $snmp3_auth_method. - * @param string $snmp3_auth_pass. - * @param string $snmp3_privacy_method. - * @param string $snmp3_privacy_pass. - * @param integer $quick_print 0 for all details, 1 for only value. + * @param string $ip_target The target address. + * @param string $snmp_version Version of the snmp: 1,2,2c or 3. + * @param string $snmp_community Snmp_community. + * @param string $snmp3_auth_user Snmp3_auth_user. + * @param string $snmp3_security_level Snmp3_security_level. + * @param string $snmp3_auth_method Snmp3_auth_method. + * @param string $snmp3_auth_pass Snmp3_auth_pass. + * @param string $snmp3_privacy_method Snmp3_privacy_method. + * @param string $snmp3_privacy_pass Snmp3_privacy_pass. + * @param integer $quick_print To get all details 0, 1: only value. + * @param string $base_oid Base_oid. + * @param string $snmp_port Snmp_port. + * @param integer $server_to_exec Server_to_exec. + * @param string $extra_arguments Extra_arguments. + * @param string $format Format to apply, for instance, to + * retrieve hex-dumps: --hexOutputLength. * * @return array SNMP result. */ @@ -1777,7 +1796,8 @@ function get_snmpwalk( $base_oid='', $snmp_port='', $server_to_exec=0, - $extra_arguments='' + $extra_arguments='', + $format='-Oa' ) { global $config; @@ -1828,15 +1848,15 @@ function get_snmpwalk( case '3': switch ($snmp3_security_level) { case 'authNoPriv': - $command_str = $snmpwalk_bin.' -m ALL -Oa '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; case 'noAuthNoPriv': - $command_str = $snmpwalk_bin.' -m ALL -Oa '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; default: - $command_str = $snmpwalk_bin.' -m ALL -Oa '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; } break; @@ -1845,7 +1865,7 @@ function get_snmpwalk( case '2c': case '1': default: - $command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' -Oa -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; } @@ -2656,7 +2676,7 @@ function get_news($arguments) case 'mysql': case 'postgresql': $sql = sprintf( - "SELECT subject,timestamp,text,author + "SELECT id_news,subject,timestamp,text,author FROM tnews WHERE id_group IN (%s) AND modal = %s AND (expire = 0 OR (expire = 1 AND expire_timestamp > '%s')) @@ -3529,25 +3549,27 @@ function series_type_graph_array($data, $show_elements_graph) break; } - if (isset($show_elements_graph['labels']) + if (isset($show_elements_graph['labels'][$value['agent_module_id']]) && is_array($show_elements_graph['labels']) && (count($show_elements_graph['labels']) > 0) ) { if ($show_elements_graph['unit']) { - $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].' / '.__('Unit ').' '.$show_elements_graph['unit'].': '; + $name_legend = $show_elements_graph['labels'][$value['agent_module_id']].' / '.__('Unit ').' '.$show_elements_graph['unit'].': '; + $data_return['legend'][$key] = $show_elements_graph['labels'][$value['agent_module_id']].' / '.__('Unit ').' '.$show_elements_graph['unit'].': '; } else { - $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].': '; + $name_legend = $show_elements_graph['labels'][$value['agent_module_id']].': '; + $data_return['legend'][$key] = $show_elements_graph['labels'][$value['agent_module_id']].': '; } } else { if (strpos($key, 'baseline') !== false) { - if ($show_elements_graph['unit']) { - $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].' / '.__('Unit ').' '.$show_elements_graph['unit'].'Baseline '; + if ($value['unit']) { + $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].' / '.__('Unit ').' '.$value['unit'].'Baseline '; } else { $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].'Baseline '; } } else { - if ($show_elements_graph['unit']) { - $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].' / '.__('Unit ').' '.$show_elements_graph['unit'].': '; + if ($value['unit']) { + $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].' / '.__('Unit ').' '.$value['unit'].': '; } else { $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].': '; } @@ -3841,9 +3863,10 @@ function pandora_xhprof_display_result($key='', $method='link') /** * From a network with a mask remove the smallest ip and the highest * - * @param string address to identify the network. - * @param string mask to identify the mask network - * @return array or false with smallest ip and highest ip + * @param string $address Identify the network. + * @param string $mask Identify the mask network. + * + * @return array or false with smallest ip and highest ip. */ function range_ips_for_network($address, $mask) { @@ -3851,15 +3874,15 @@ function range_ips_for_network($address, $mask) return false; } - // convert ip addresses to long form + // Convert ip addresses to long form. $address_long = ip2long($address); $mask_long = ip2long($mask); - // caculate first usable address + // Calculate first usable address. $ip_host_first = ((~$mask_long) & $address_long); - $ip_first = (($address_long ^ $ip_host_first) + 1); + $ip_first = (($address_long ^ $ip_host_first)); - // caculate last usable address + // Calculate last usable address. $ip_broadcast_invert = ~$mask_long; $ip_last = (($address_long | $ip_broadcast_invert) - 1); @@ -3875,9 +3898,10 @@ function range_ips_for_network($address, $mask) /** * from two ips find out if there is such an ip * - * @param string ip ip wont validate - * @param string ip_lower - * @param string ip_upper + * @param string ip ip wont validate + * @param string ip_lower + * @param string ip_upper + * * @return boolean true or false if the ip is between the two ips */ function is_in_network($ip, $ip_lower, $ip_upper) @@ -3928,3 +3952,1337 @@ function mask2cidr($mask) $base = ip2long('255.255.255.255'); return (32 - log((($long ^ $base) + 1), 2)); } + + +function get_help_info($section_name) +{ + global $config; + // hd($section_name); + $user_language = get_user_language($id_user); + + $es = false; + $result = 'https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_en:'; + if ($user_language == 'es') { + $es = true; + $result = 'https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_es:'; + } + + switch ($section_name) { + case 'tactical_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_t.C3.A1ctica'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Tactical_view'; + } + break; + + case 'group_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_de_Grupos'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Group_view'; + } + break; + + case 'tree_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_de_.C3.A1rbol'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#The_Tree_View'; + } + break; + + case 'monitor_detail_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Detalles_Monitores'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Monitor_Details'; + } + break; + + case 'tag_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_de_etiquetas'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Tag_view'; + } + break; + + case 'alert_validation': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Detalles_de_Alertas'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Alert_Details'; + } + break; + + case 'agents_alerts_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_de_agente_.2F_alerta'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Agent.2F_Alert_View'; + } + break; + + case 'agents_module_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_de_agente_.2F_modulo'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Agents_.2F_Modules_View'; + } + break; + + case 'module_groups_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Vista_de_grupos_de_m.C3.B3dulos'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Module_Groups_View'; + } + break; + + case 'snmp_browser_view': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Navegador_SNMP_de_Pandora_FMS'; + } else { + $result .= 'Remote_Monitoring&printable=yes#Pandora_FMS_SNMP_MIB_Browser'; + } + break; + + case 'snmp_trap_generator_view': + if ($es) { + $result .= 'Monitorizacion_traps_SNMP&printable=yes#Generador_de_Traps'; + } else { + $result .= 'SNMP_traps_Monitoring&printable=yes#Trap_Generator'; + } + break; + + case 'real_time_view': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Gr.C3.A1ficas_Real-time'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Real-time_Graphs'; + } + break; + + case 'agent_status': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Detalles_del_agente'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Agent_Details'; + } + break; + + case 'agent_main_tab': + if ($es) { + $result .= 'Intro_Monitorizacion&printable=yes#Visualizaci.C3.B3n_del_agente'; + } else { + $result .= 'Intro_Monitoring&printable=yes#Agent_configuration_in_the_console_2'; + } + break; + + case 'alert_config': + if ($es) { + $result .= 'Alertas&printable=yes#Creaci.C3.B3n_de_una_Acci.C3.B3n'; + } else { + $result .= 'Alerts&printable=yes#Creating_an_Action'; + } + break; + + case 'alert_macros': + if ($es) { + $result .= 'Alertas&printable=yes#Macros_sustituibles_en_los_campos_Field1.2C_Field2.2C_Field3..._Field10'; + } else { + $result .= 'Alerts&printable=yes#Replaceable_Macros_within_Field_1_through_Field_10'; + } + break; + + case 'alerts_config': + if ($es) { + $result .= 'Alertas&printable=yes#Configuraci.C3.B3n_de_alertas_en_Pandora_FMS'; + } else { + $result .= 'Alerts&printable=yes#Alert_Configuration_in_Pandora_FMS'; + } + break; + + case 'alert_special_days': + if ($es) { + $result .= 'Alertas&printable=yes#Lista_de_d.C3.ADas_especiales'; + } else { + $result .= 'Alerts&printable=yes#List_of_special_days'; + } + break; + + case 'alerts': + if ($es) { + $result .= 'Politicas&printable=yes#Alertas'; + } else { + $result .= 'Policy&printable=yes#Alerts'; + } + break; + + case 'collections': + if ($es) { + $result .= 'Politicas&printable=yes#Colecciones_de_ficheros'; + } else { + $result .= 'Policy&printable=yes#File_Collections'; + } + break; + + case 'component_groups': + if ($es) { + $result .= 'Plantillas_y_Componentes&printable=yes#Grupos_de_componentes'; + } else { + $result .= 'Templates_and_components&printable=yes#Component_Groups'; + } + break; + + case 'configure_gis_map': + if ($es) { + $result .= 'Pandora_GIS&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'GIS&printable=yes#Introduction'; + } + break; + + case 'configure_gis_map_edit': + if ($es) { + $result .= 'Pandora_GIS&printable=yes#GIS_Maps'; + } else { + $result .= 'GIS&printable=yes#GIS_Maps'; + } + break; + + case 'event_alert': + if ($es) { + $result .= 'Eventos&printable=yes#Introducci.C3.B3n_2'; + } else { + $result .= 'Events&printable=yes#Introduction_2'; + } + break; + + case 'eventview': + if ($es) { + $result .= 'Eventos&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Events&printable=yes#Introduction'; + } + break; + + case 'export_server': + if ($es) { + $result .= 'ExportServer&printable=yes#A.C3.B1adir_un_servidor_de_destino'; + } else { + $result .= 'Export_Server&printable=yes#Adding_a_Target_Server'; + } + break; + + case 'external_alert': + if ($es) { + $result .= 'Politicas&printable=yes#Alertas_Externas'; + } else { + $result .= 'Policy&printable=yes#External_Alerts'; + } + break; + + case 'gis_tab': + if ($es) { + $result .= 'Pandora_GIS&printable=yes#Configuraci.C3.B3n_del_Agent_GIS'; + } else { + $result .= 'GIS&printable=yes#The_Agent.27s_GIS_Setup'; + } + break; + + case 'graph_builder': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Crear_Gr.C3.A1ficas_combinadas'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Creating_combined_graphs'; + } + break; + + case 'graph_editor': + if ($es) { + $result .= 'Presentacion_datos/visualizacion&printable=yes#Agregar_elementos_a_gr.C3.A1ficas_combinadas'; + } else { + $result .= 'Data_Presentation/Visualization&printable=yes#Adding_elements_to_combined_graphs'; + } + break; + + case 'dashboards_tab': + if ($es) { + $result .= 'Dashboard&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Dashboard&printable=yes#Introduction'; + } + break; + + case 'history_database': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Base_de_datos_hist.C3.B3rica'; + } else { + $result .= 'Console_Setup&printable=yes#The_History_Database'; + } + break; + + case 'inventory_tab': + if ($es) { + $result .= 'Inventario&printable=yes#M.C3.B3dulos_de_inventario'; + } else { + $result .= 'Inventory&printable=yes#Inventory_Modules'; + } + break; + + case 'ipam_list_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'IPAM&printable=yes#Introduction'; + } + break; + + case 'ipam_calculator_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Calculadora_de_subredes'; + } else { + $result .= 'IPAM&printable=yes#Subnetwork_calculator'; + } + break; + + case 'ipam_vlan_config_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Vlan_IPAM'; + } else { + $result .= 'IPAM&printable=yes#VLAN_IPAM'; + } + break; + + case 'ipam_vlan_statistics_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Estad.C3.ADsticas_IPAM_Vlan'; + } else { + $result .= 'IPAM&printable=yes#IPAM_VLAN_Stats'; + } + break; + + case 'ipam_vlan_wizard_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Wizard_IPAM_Vlan'; + } else { + $result .= 'IPAM&printable=yes#IPAM_VLAN_Wizard:'; + } + break; + + case 'ipam_supernet_config_tab': + if ($es) { + $result .= 'IPAM&printable=yes#IPAM_Supernet'; + } else { + $result .= 'IPAM&printable=yes#IPAM_Supernet'; + } + break; + + case 'ipam_supernet_map_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Mapa_Superred_IPAM'; + } else { + $result .= 'IPAM&printable=yes#IPAM_Supernet_Map'; + } + break; + + case 'ipam_supernet_statistics_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Estad.C3.ADsticas_IPAM_Superred'; + } else { + $result .= 'IPAM&printable=yes#IPAM_Supernet_Stats'; + } + break; + + case 'ipam_new_tab': + case 'ipam_edit_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Vista_de_edici.C3.B3n'; + } else { + $result .= 'IPAM&printable=yes#Edit_view'; + } + break; + + case 'ipam_massive_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Vista_Operaciones_masivas'; + } else { + $result .= 'IPAM&printable=yes#Massive_operations_view'; + } + break; + + case 'ipam_network_tab': + case 'ipam_force_tab': + if ($es) { + $result .= 'IPAM&printable=yes#Vista_de_iconos'; + } else { + $result .= 'IPAM&printable=yes#Icon_view'; + } + break; + + case 'macros_visual_maps': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Macros_en_las_consolas_visuales'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Macros_in_Visual_Consoles'; + } + break; + + case 'linked_map_status_calc': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Mapa_asociado'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Associated_Map'; + } + break; + + case 'main_tab': + if ($es) { + $result .= 'Intro_Monitorizacion&printable=yes#Configuraci.C3.B3n_del_agente_en_consola'; + } else { + $result .= 'Intro_Monitoring&printable=yes#Agent_configuration_in_the_console'; + } + break; + + case 'manage_alert_list': + if ($es) { + $result .= 'Alertas&printable=yes#Gestionar_alertas_desde_el_agente'; + } else { + $result .= 'Alerts&printable=yes#Managing_Alerts_from_within_the_Agent'; + } + break; + + case 'alert_scalate': + if ($es) { + $result .= 'Alertas&printable=yes#Escalado_de_alertas'; + } else { + $result .= 'Alerts&printable=yes#Scaling_Alerts'; + } + break; + + case 'map_builder_intro': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Introduction'; + } + break; + + case 'map_builder_favorite': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Consolas_visuales_favoritas'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Favorite_visual_consoles'; + } + break; + + case 'map_builder_template': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Plantillas_de_consolas_visuales'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Visual_Console_Templates'; + } + break; + + case 'map_builder_wizard': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Asistente_de_consola_visuales'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Wizard_Visual_Console'; + } + break; + + case 'module_linking': + if ($es) { + $result .= 'Politicas&printable=yes#Tipos_de_m.C3.B3dulos'; + } else { + $result .= 'Policy&printable=yes#Types_of_Modules'; + } + break; + + case 'network_map_enterprise_edit': + if ($es) { + $result .= 'Presentacion_datos/Mapas_de_red&printable=yes#Mapa_de_red_no_vac.C3.ADo'; + } else { + $result .= 'Data_Presentation/Network_Maps&printable=yes#Non_empty_network_map'; + } + break; + + case 'network_map_enterprise_list': + if ($es) { + $result .= 'Presentacion_datos/Mapas_de_red&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Data_Presentation/Network_Maps&printable=yes#Introduction'; + } + break; + + case 'network_map_enterprise_empty': + if ($es) { + $result .= 'Presentacion_datos/Mapas_de_red&printable=yes#Mapa_de_red_vac.C3.ADo'; + } else { + $result .= 'Data_Presentation/Network_Maps&printable=yes#Empty_network_map'; + } + break; + + case 'network_map_enterprise_view': + if ($es) { + $result .= 'Presentacion_datos/Mapas_de_red&printable=yes#Vista_de_un_mapa_de_red'; + } else { + $result .= 'Data_Presentation/Network_Maps&printable=yes#Network_map_view'; + } + break; + + case 'transactional_view': + if ($es) { + $result .= 'Monitorizacion_transaccional&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Transactional_Monitoring&printable=yes#Introduction'; + } + break; + + case 'pcap_filter': + if ($es) { + $result .= 'Netflow&printable=yes#Creaci.C3.B3n_del_filtro'; + } else { + $result .= 'Netflow&printable=yes#Filter_creation'; + } + break; + + case 'planned_downtime': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Introducci.C3.B3n_4'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Introduction_4'; + } + break; + + case 'planned_downtime_editor': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Creaci.C3.B3n_parada_planificada'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Create_a_scheduled_downtime'; + } + break; + + case 'plugin_definition': + if ($es) { + $result .= 'Anexo_Server_Plugins&printable=yes#Registro_manual_de_un_plugin_en_la_consola'; + } else { + $result .= 'Anexo_Server_plugins_developement&printable=yes#Plugin_manual_registration'; + } + break; + + case 'plugin_macros': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Macros_internas'; + } else { + $result .= 'Remote_Monitoring&printable=yes#Internal_Macros'; + } + break; + + case 'plugin_policy': + if ($es) { + $result .= 'Politicas&printable=yes#Plugins_de_agente'; + } else { + $result .= 'Policy&printable=yes#Agent_Plug_Ins'; + } + break; + + case 'policy_queue': + if ($es) { + $result .= 'Politicas&printable=yes#Gesti.C3.B3n_de_la_cola_de_pol.C3.ADticas'; + } else { + $result .= 'Policy&printable=yes#Policy_Queues_Management'; + } + break; + + case 'prediction_source_module': + if ($es) { + $result .= 'Monitorizacion_otra&printable=yes#Tipos_de_monitorizaci.C3.B3n_predictiva'; + } else { + $result .= 'Other_Monitoring&printable=yes#Types_of_predictive_monitoring'; + } + break; + + case 'wmi_module_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Monitorizaci.C3.B3n_de_Windows_remotos_con_WMI'; + } else { + $result .= 'Remote_Monitoring&printable=yes#Windows_Remote_Monitoring_with_WMI'; + } + break; + + case 'template_reporting_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#Introduction'; + } + break; + + case 'reporting_template_list_item_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Pesta.C3.B1a_List_Items'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_.27List_Items.27_Tab'; + } + break; + + case 'reporting_template_item_editor_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Pesta.C3.B1a_Item_editor'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_.27Item_Editor.27_Tab'; + } + break; + + case 'reporting_template_advanced_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Opciones_avanzadas_de_informe'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_Advanced_Options_Tab'; + } + break; + + case 'reporting_advanced_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Opciones_avanzadas_de_informe'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_Advanced_Options_Tab'; + } + break; + + case 'reporting_global_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Global'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_Global_Tab'; + } + break; + + case 'reporting_item_editor_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Pesta.C3.B1a_Item_editor'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_.27Item_Editor.27_Tab'; + } + break; + + case 'reporting_list_items_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Pesta.C3.B1a_List_Items'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_.27List_Items.27_Tab'; + } + break; + + case 'reporting_wizard_sla_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Wizard_SLA'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_SLA_Wizard_Tab'; + } + break; + + case 'reporting_wizard_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Wizard_general'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#The_Wizard_Tab'; + } + break; + + case 'response_macros': + if ($es) { + $result .= 'Eventos&printable=yes#Event_Responses_macros'; + } else { + $result .= 'Events&printable=yes#Event_Responses_macros'; + } + break; + + case 'events_responses_tab': + if ($es) { + $result .= 'Eventos&printable=yes#Introducci.C3.B3n_3'; + } else { + $result .= 'Events&printable=yes#Introduction_3'; + } + break; + + case 'servers': + if ($es) { + $result .= 'Interfaz&printable=yes#Gesti.C3.B3n_de_servidores'; + } else { + $result .= 'Interface&printable=yes#Server_management'; + } + break; + + case 'snmpwalk': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Navegador_SNMP_de_Pandora_FMS'; + } else { + $result .= 'Remote_Monitoring&printable=yes#Pandora_FMS_SNMP_MIB_Browser'; + } + break; + + case 'tags_config': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Sistemas_de_permisos_ampliados_mediante_etiquetas_.28tags.29'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Permission_system_extended_by_tags'; + } + break; + + case 'transactional_map_phases': + if ($es) { + $result .= 'Monitorizacion_transaccional&printable=yes#Creaci.C3.B3n_del_.C3.A1rbol_de_fases'; + } else { + $result .= 'Transactional_Monitoring&printable=yes#Creating_the_phase_tree'; + } + break; + + case 'transactional_map_phases_data': + if ($es) { + $result .= 'Monitorizacion_transaccional&printable=yes#Configuraci.C3.B3n_de_los_scripts_de_control'; + } else { + $result .= 'Transactional_Monitoring&printable=yes#Control_scripts_configuration'; + } + break; + + case 'wizard_reporting_tab': + if ($es) { + $result .= 'Presentacion_datos/Informes&printable=yes#Asistente_de_plantillas'; + } else { + $result .= 'Data_Presentation/Reports&printable=yes#Template_Wizard'; + } + break; + + case 'user_edit_notifications': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Configuraci.C3.B3n_de_notificaciones'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Notification_configuration'; + } + break; + + case 'view_services': + if ($es) { + $result .= 'Servicios&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Services&printable=yes#Introduction'; + } + break; + + case 'visual_console_editor_data_tab': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Creaci.C3.B3n_-_Datos_generales'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Creation_-_General_data'; + } + break; + + case 'visual_console_editor_editor_tab': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Creaci.C3.B3n_y_edici.C3.B3n_de_consolas_visuales'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Creation_and_edition_of_Visual_Consoles'; + } + break; + + case 'visual_console_editor_list_elements_tab': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Creaci.C3.B3n_-_lista_de_elementos'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Creation_-_List_of_Elements'; + } + break; + + case 'visual_console_editor_wizard_tab': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Creaci.C3.B3n_-_Wizard'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Creation_-_Wizard'; + } + break; + + case 'visual_console_editor_wizard_services_tab': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Creaci.C3.B3n_-_Wizard_de_Servicios'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Creation_-_Service_Wizard'; + } + break; + + case 'visual_console_tab': + if ($es) { + $result .= 'Presentacion_datos/Mapas_visuales&printable=yes#Mapa_asociado'; + } else { + $result .= 'Data_Presentation/Visual_Maps&printable=yes#Associated_Map'; + } + break; + + case 'view_created_map_services_tab': + if ($es) { + $result .= 'Servicios&printable=yes#Vista_de_mapa_de_servicio'; + } else { + $result .= 'Services&printable=yes#Service_Map_View'; + } + break; + + case 'view_created_services_tab': + if ($es) { + $result .= 'Servicios&printable=yes#Lista_simple_de_un_servicio_y_todos_los_elementos_que_contiene'; + } else { + $result .= 'Services&printable=yes#List-based_view_of_a_Service_and_its_Elements'; + } + break; + + case 'config_service_element_tab': + if ($es) { + $result .= 'Servicios&printable=yes#Configuraci.C3.B3n_de_elementos'; + } else { + $result .= 'Services&printable=yes#Element_Configuration'; + } + break; + + case 'config_service_tab': + if ($es) { + $result .= 'Servicios&printable=yes#Configuraci.C3.B3n_inicial'; + } else { + $result .= 'Services&printable=yes#Initial_Configuration'; + } + break; + + case 'other_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Otra_configuraci.C3.B3n'; + } else { + $result .= 'Console_Setup&printable=yes#Other_configuration'; + } + break; + + case 'services_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_servicios'; + } else { + $result .= 'Console_Setup&printable=yes#Services_configuration'; + } + break; + + case 'visual_consoles_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_de_las_consolas_visuales'; + } else { + $result .= 'Console_Setup&printable=yes#Visual_console_configuration'; + } + break; + + case 'charts_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_de_gr.C3.A1ficas'; + } else { + $result .= 'Console_Setup&printable=yes#Chart_settings'; + } + break; + + case 'front_and_text_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_de_Fuente_y_texto'; + } else { + $result .= 'Console_Setup&printable=yes#Font_and_text_settings'; + } + break; + + case 'gis_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_GIS'; + } else { + $result .= 'Console_Setup&printable=yes#GIS_configuration'; + } + break; + + case 'style_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_de_estilo'; + } else { + $result .= 'Console_Setup&printable=yes#Style_configuration'; + } + break; + + case 'behavoir_conf_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Configuraci.C3.B3n_del_comportamiento'; + } else { + $result .= 'Console_Setup&printable=yes#Behaviour_configuration'; + } + break; + + case 'setup_ehorus_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#eHorus'; + } else { + $result .= 'Console_Setup&printable=yes#EHorus'; + } + break; + + case 'diagnostic_tool_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Diagnostic_tool'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Diagnostic_tool'; + } + break; + + case 'performance_metrics_tab': + if ($es) { + $result .= 'Optimizacion&printable=yes#Comprobaci.C3.B3n_del_fichero_my.ini.2Fcnf'; + } else { + $result .= 'Optimization&printable=yes#Check_my.ini.2Fcnf_settings'; + } + break; + + case 'db_status_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#DB_Schema_Check'; + } else { + $result .= 'Managing_and_Administration&printable=yes#DB_Schema_Check'; + } + break; + + case 'database_backup_utility_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Backup'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Backup'; + } + break; + + case 'update_manager_offline_tab': + if ($es) { + $result .= 'Actualizacion&printable=yes#Actualizaciones_.22offline.22'; + } else { + $result .= 'Anexo_Upgrade&printable=yes#.22Offline.22_updates'; + } + break; + + case 'update_manager_online_tab': + if ($es) { + $result .= 'Actualizacion&printable=yes#Actualizaciones_.22online.22'; + } else { + $result .= 'Anexo_Upgrade&printable=yes#.22Online.22_updates'; + } + break; + + case 'others_database_maintenance_options_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Otros'; + } else { + $result .= 'Console_Setup&printable=yes#Others'; + } + break; + + case 'database_maintenance_options_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Opciones_de_mantenimiento_de_la_base_de_datos'; + } else { + $result .= 'Console_Setup&printable=yes#Database_maintenance_options'; + } + break; + + case 'database_maintenance_status_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Estado_del_mantenimiento_de_las_bases_de_datos'; + } else { + $result .= 'Console_Setup&printable=yes#Database_maintenance_status'; + } + break; + + case 'historical_database_maintenance_options_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Opciones_de_mantenimiento_de_la_base_de_datos_hist.C3.B3rica'; + } else { + $result .= 'Console_Setup&printable=yes#Historical_database_maintenance_options'; + } + break; + + case 'setup_enterprise_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#Enterprise'; + } else { + $result .= 'Console_Setup&printable=yes#Features_of_the_Enterprise_Version'; + } + break; + + case 'setup_general_tab': + if ($es) { + $result .= 'Configuracion_Consola&printable=yes#General_Setup'; + } else { + $result .= 'Console_Setup&printable=yes#General_Setup'; + } + break; + + case 'export_target_tab': + if ($es) { + $result .= 'ExportServer&printable=yes#A.C3.B1adir_un_servidor_de_destino'; + } else { + $result .= 'Export_Server&printable=yes#Adding_a_Target_Server'; + } + break; + + case 'servers_ha_clusters_tab': + if ($es) { + $result .= 'HA&printable=yes#Alta_disponibilidad_del_Servidor_de_Datos'; + } else { + $result .= 'HA&printable=yes#HA_of_Data_Server'; + } + break; + + case 'plugins_tab': + if ($es) { + $result .= 'Anexo_Agent_Plugins&printable=yes#Caracter.C3.ADsticas_b.C3.A1sicas_de_plugin_de_agente'; + } else { + $result .= 'Anexo_Agent_Plugins&printable=yes#Basic_Features_of_the_Agent_Plugin'; + } + break; + + case 'create_agent': + if ($es) { + $result .= 'Intro_Monitorizacion&printable=yes#Configuraci.C3.B3n_del_agente_en_consola'; + } else { + $result .= 'Intro_Monitoring&printable=yes#Agent_configuration_in_the_console'; + } + break; + + case 'agent_snmp_explorer_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Wizard_SNMP'; + } else { + $result .= 'Remote_Monitoring&printable=yes#SNMP_Wizard'; + } + break; + + case 'agent_snmp_interfaces_explorer_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#SNMP_Interfaces_wizard'; + } else { + $result .= 'Remote_Monitoring&printable=yes#SNMP_Interface_Wizard'; + } + break; + + case 'agent_snmp_wmi_explorer_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Wizard_WMI'; + } else { + $result .= 'Remote_Monitoring&printable=yes#WMI_Wizard'; + } + break; + + case 'group_list_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Introducci.C3.B3n_2'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Introduction_2'; + } + break; + + case 'acl_setup_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Introducci.C3.B3n_3'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Introduction_3'; + } + break; + + case 'profile_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Perfiles_en_Pandora_FMS'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Profiles_in_Pandora_FMS'; + } + break; + + case 'configure_profiles_tab': + if ($es) { + $result .= 'Gestion_y_Administracion&printable=yes#Perfiles_en_Pandora_FMS'; + } else { + $result .= 'Managing_and_Administration&printable=yes#Profiles_in_Pandora_FMS'; + } + break; + + case 'network_component_tab': + if ($es) { + $result .= 'Plantillas_y_Componentes&printable=yes#Componentes_de_red'; + } else { + $result .= 'Templates_and_components&printable=yes#Network_Components'; + } + break; + + case 'local_component_tab': + if ($es) { + $result .= 'Plantillas_y_Componentes&printable=yes#Componentes_locales'; + } else { + $result .= 'Templates_and_components&printable=yes#Local_Components'; + } + break; + + case 'module_template_tab': + if ($es) { + $result .= 'Plantillas_y_Componentes&printable=yes#Plantillas_de_m.C3.B3dulos'; + } else { + $result .= 'Templates_and_components&printable=yes#Module_Templates'; + } + break; + + case 'agent_autoconf_tab': + if ($es) { + $result .= 'Configuracion_Agentes&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Configuration_Agents&printable=yes#Introduction'; + } + break; + + case 'policies_management_tab': + if ($es) { + $result .= 'Politicas&printable=yes#Introducci.C3.B3n'; + } else { + $result .= 'Policy&printable=yes#Introduction'; + } + break; + + case 'massive_agents_tab': + if ($es) { + $result .= 'Operaciones_Masivas&printable=yes#Edici.C3.B3n_masiva_de_agentes'; + } else { + $result .= 'Massive_Operations&printable=yes#Agent_massive_edition'; + } + break; + + case 'massive_modules_tab': + if ($es) { + $result .= 'Operaciones_Masivas&printable=yes#Edici.C3.B3n_masiva_de_m.C3.B3dulos'; + } else { + $result .= 'Massive_Operations&printable=yes#Modules_massive_edition'; + } + break; + + case 'massive_policies_tab': + if ($es) { + $result .= 'Operaciones_Masivas&printable=yes#Editar_m.C3.B3dulos_de_pol.C3.ADticas_masivamente'; + } else { + $result .= 'Massive_Operations&printable=yes#Edit_policy_modules_massively'; + } + break; + + case 'alert_templates_tab': + if ($es) { + $result .= 'Alertas&printable=yes#Introducci.C3.B3n_4'; + } else { + $result .= 'Alerts&printable=yes#Introduction_4'; + } + break; + + case 'configure_alert_template_step_1': + if ($es) { + $result .= 'Alertas&printable=yes#Paso_1:_General'; + } else { + $result .= 'Alerts&printable=yes#Step_1:_General'; + } + break; + + case 'configure_alert_template_step_2': + if ($es) { + $result .= 'Alertas&printable=yes#Paso_2:_Condiciones'; + } else { + $result .= 'Alerts&printable=yes#Step_2:_Conditions'; + } + break; + + case 'configure_alert_template_step_3': + if ($es) { + $result .= 'Alertas&printable=yes#Paso_3:_Campos_avanzados'; + } else { + $result .= 'Alerts&printable=yes#Step_3:_Advanced_fields'; + } + break; + + case 'alerts_action': + if ($es) { + $result .= 'Alertas&printable=yes#Introducci.C3.B3n_3'; + } else { + $result .= 'Alerts&printable=yes#Introduction_3'; + } + break; + + case 'alerts_command_tab': + if ($es) { + $result .= 'Alertas&printable=yes#Introducci.C3.B3n_2'; + } else { + $result .= 'Alerts&printable=yes#Introduction_2'; + } + break; + + case 'alerts_config_command_tab': + if ($es) { + $result .= 'Alertas&printable=yes#Creaci.C3.B3n_de_un_comando_para_una_alerta'; + } else { + $result .= 'Alerts&printable=yes#Command_Creation_for_an_Alert'; + } + break; + + case 'configure_alert_event_step_1': + if ($es) { + $result .= 'Eventos&printable=yes#Creaci.C3.B3n_alerta_de_evento'; + } else { + $result .= 'Events&printable=yes#Event_Alert_creation'; + } + break; + + case 'configure_event_rule_tab': + if ($es) { + $result .= 'Eventos&printable=yes#Creaci.C3.B3n_alerta_de_evento'; + } else { + $result .= 'Events&printable=yes#Event_Alert_creation'; + } + break; + + case 'snmp_alert_overview_tab': + if ($es) { + $result .= 'Monitorizacion_traps_SNMP&printable=yes#Introducci.C3.B3n_2'; + } else { + $result .= 'SNMP_traps_Monitoring&printable=yes#Introduction_2'; + } + break; + + case 'snmp_alert_update_tab': + if ($es) { + $result .= 'Monitorizacion_traps_SNMP&printable=yes#A.C3.B1adir_una_alerta'; + } else { + $result .= 'SNMP_traps_Monitoring&printable=yes#Alert_Creation'; + } + break; + + case 'sound_console_tab': + if ($es) { + $result .= 'Eventos&printable=yes#Uso'; + } else { + $result .= 'Events&printable=yes#Use'; + } + break; + + case 'local_module_tab': + if ($es) { + $result .= 'Intro_Monitorizacion&printable=yes#Par.C3.A1metros_comunes'; + } else { + $result .= 'Intro_Monitoring&printable=yes#Common_Parameters'; + } + break; + + case 'local_module': + if ($es) { + $result .= 'Operacion&printable=yes#Tipos_de_m.C3.B3dulos'; + } else { + $result .= 'Operations&printable=yes#Types_of_Modules'; + } + break; + + case 'data_server_module_tab': + if ($es) { + $result .= 'Operacion&printable=yes#Tipos_de_m.C3.B3dulos'; + } else { + $result .= 'Operations&printable=yes#Types_of_Modules'; + } + break; + + case 'network_module_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Monitorizaci.C3.B3n_ICMP'; + } else { + $result .= 'Remote_Monitoring&printable=yes#ICMP_Monitoring'; + } + break; + + case 'wux_console': + if ($es) { + $result .= 'Monitorizacion_Usuario&printable=yes#Crear_un_m.C3.B3dulo_de_an.C3.A1lisis_web_en_Pandora_FMS_Console'; + } else { + $result .= 'User_Monitorization&printable=yes#Creating_a_Web_Analytics_module_in_Pandora_FMS_Console'; + } + break; + + case 'gis_basic_configurations_tab': + if ($es) { + $result .= 'Pandora_GIS&printable=yes#Configuraci.C3.B3n_B.C3.A1sica'; + } else { + $result .= 'GIS&printable=yes#Basic_Configuration'; + } + break; + + case 'gis_map_connection_tab': + if ($es) { + $result .= 'Pandora_GIS&printable=yes#Mapas_Open_Street'; + } else { + $result .= 'GIS&printable=yes#Open_Street_Maps'; + } + break; + + case 'icmp_module_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Monitorizaci.C3.B3n_ICMP'; + } else { + $result .= 'Remote_Monitoring&printable=yes#ICMP_Monitoring'; + } + break; + + case 'snmp_module_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Monitorizando_con_m.C3.B3dulos_de_red_tipo_SNMP'; + } else { + $result .= 'Remote_Monitoring&printable=yes#Monitoring_by_Network_Modules_with_SNMP'; + } + break; + + case 'tcp_module_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Monitorizaci.C3.B3n_TCP'; + } else { + $result .= 'Remote_Monitoring&printable=yes#TCP_Monitoring'; + } + break; + + case 'webserver_module_tab': + if ($es) { + $result .= 'Monitorizacion_web&printable=yes#Creaci.C3.B3n_de_m.C3.B3dulos_web'; + } else { + $result .= 'Web_Monitoring&printable=yes#Creating_Web_Modules'; + } + break; + + case 'wmi_query_tab': + if ($es) { + $result .= 'Monitorizacion_remota&printable=yes#Monitorizaci.C3.B3n_de_Windows_remotos_con_WMI'; + } else { + $result .= 'Remote_Monitoring&printable=yes#Windows_Remote_Monitoring_with_WMI'; + } + break; + + case 'module_type_tab': + if ($es) { + $result .= 'Operacion&printable=yes#Tipos_de_m.C3.B3dulos'; + } else { + $result .= ''; + } + break; + + case 'render_view_tab': + if ($es) { + $result .= 'Pandora_GIS&printable=yes#Operaci.C3.B3n'; + } else { + $result .= 'GIS&printable=yes#Operation'; + } + break; + } + + // hd($result); + return $result; +} diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 0ac9bb876f..fd5e922e32 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -328,14 +328,21 @@ function agents_get_alerts_simple($id_agent=false, $filter='', $options=false, $ * * By default, it will return all the agents where the user has reading access. * - * @param array filter options in an indexed array. See - * db_format_array_where_clause_sql() - * @param array Fields to get. - * @param string Access needed in the agents groups. - * @param array $order The order of agents, by default is upward for field nombre. - * @param boolean $return Whether to return array with agents or false, or sql string statement + * @param array $filter Filter options in an indexed array. + * See db_format_array_where_clause_sql(). + * @param array $fields DB fields to get. + * @param string $access ACL level needed in the agents groups. + * @param array $order The order of agents, by default is upward + * for field nombre. + * @param boolean $return Whether to return array with agents or + * the sql string statement. + * @param boolean $disabled_agent Whether to return only the enabled agents + * or not. + * @param boolean $use_meta_table Whether to use the regular or the meta table + * to retrieve the agents. * - * @return mixed An array with all alerts defined for an agent or false in case no allowed groups are specified. + * @return mixed An array with all alerts defined for an agent + * or false in case no allowed groups are specified. */ function agents_get_agents( $filter=false, @@ -346,7 +353,8 @@ function agents_get_agents( 'order' => 'ASC', ], $return=false, - $disabled_agent=0 + $disabled_agent=0, + $use_meta_table=false ) { global $config; @@ -563,11 +571,15 @@ function agents_get_agents( ); } + $table_name = ($use_meta_table === true) ? 'tmetaconsole_agent' : 'tagente'; $sql = sprintf( 'SELECT DISTINCT %s - FROM tagente LEFT JOIN tagent_secondary_group ON tagent_secondary_group.id_agent=tagente.id_agente + FROM `%s` tagente + LEFT JOIN tagent_secondary_group + ON tagent_secondary_group.id_agent=tagente.id_agente WHERE %s %s', implode(',', $fields), + $table_name, $where, $order ); @@ -578,6 +590,7 @@ function agents_get_agents( } $sql = sprintf('%s %s', $sql, $limit_sql); + if ($return) { return $sql; } else { @@ -2202,7 +2215,7 @@ function agents_delete_agent($id_agents, $disableACL=false) // Delete agent in networkmap enterprise if (enterprise_installed()) { - enterprise_include_once('include/functions_pandora_networkmap.php'); + enterprise_include_once('include/functions_networkmap.php'); networkmap_delete_nodes_by_agent([$id_agent]); } diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 6bfe709c32..011acafae9 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -664,6 +664,7 @@ function alerts_get_alert_templates_types() $types['unknown'] = __('Unknown status'); $types['onchange'] = __('On Change'); $types['always'] = __('Always'); + $types['not_normal'] = __('Not normal status'); return $types; } @@ -680,7 +681,7 @@ function alerts_get_alert_templates_type_name($type) { $types = alerts_get_alert_templates_types(); - if (! isset($type[$type])) { + if (!isset($types[$type])) { return __('Unknown'); } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index e57dd31013..3c6cdbf595 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -4584,7 +4584,7 @@ function api_set_new_snmp_component($id, $thrash1, $other, $thrash2) return; } - $id = network_components_create_network_component($id, $other['data'][0], $other['data'][25], $values); + $id = network_components_create_network_component($id, $other['data'][0], $other['data'][26], $values); if (!$id) { returnError('error_set_new_snmp_component', 'Error creating SNMP component.'); @@ -11608,7 +11608,9 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3) global $config; if (defined('METACONSOLE')) { - return; + $meta = true; + } else { + $meta = $other['data'][1]; } if (!check_acl($config['id_user'], 0, 'EW')) { @@ -11620,8 +11622,7 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3) returnError('error_parameter', 'Error in the parameters.'); return; } else if ($other['type'] == 'array') { - $comment = io_safe_input($other['data'][0]); - $meta = $other['data'][1]; + $comment = $other['data'][0]; $history = $other['data'][2]; $status = events_comment( @@ -14684,3 +14685,365 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3) } } + + +/** + * Functions por get all user to new feature for Carrefour + * It depends of returnType, the method will return csv or json data + * + * @param string $thrash1 don't use + * @param string $thrash2 don't use + * @param array $other don't use + * *@param string $returnType + * Example: + * api.php?op=get&op2=list_all_user&return_type=json&apipass=1234&user=admin&pass=pandora + * @return + */ + + +function api_get_list_all_user($thrash1, $thrash2, $other, $returnType) +{ + global $config; + + if (!check_acl($config['id_user'], 0, 'AR')) { + returnError('forbidden', 'string'); + return; + } + + $sql = 'SELECT + tup.id_usuario AS user_id, + tu.fullname AS fullname, + tp.id_perfil AS profile_id, + tup.id_up AS id_up, + tp.name AS profile_name, + tup.id_grupo AS group_id, + tgp.nombre AS group_name + FROM tperfil tp + INNER JOIN tusuario_perfil tup + ON tp.id_perfil = tup.id_perfil + LEFT OUTER JOIN tgrupo tgp + ON tup.id_grupo = tgp.id_grupo + LEFT OUTER JOIN tusuario tu + ON tu.id_user = tup.id_usuario'; + + $users = db_get_all_rows_sql($sql); + + $i = 0; + + foreach ($users as $up) { + $group_name = $up['group_name']; + if ($up['group_name'] === null) { + $group_name = 'All'; + } + + $values[$i] = [ + 'id_usuario' => $up['user_id'], + 'fullname' => $up['fullname'], + 'id_up' => $up['id_up'], + 'id_perfil' => $up['profile_id'], + 'perfil_name' => $up['profile_name'], + 'id_grupo' => $up['group_id'], + 'group_name' => $group_name, + ]; + $i += 1; + } + + if ($values === false) { + returnError('Error_user', __('Users could not be found.')); + return; + } + + $data = [ + 'type' => 'array', + 'data' => $values, + ]; + + returnData($returnType, $data, ';'); +} + + +/** + * Funtion for get all info user to new feature for Carrefour + * It depends of returnType, the method will return csv or json data + * + * @param string $thrash1 don't use + * @param string $thrash2 don't use + * @param array $other other[0] = user database + * @param string $returnType + * Example + * api.php?op=get&op2=info_user_name&return_type=json&other=admin&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora + * + * @return + */ + + +function api_get_info_user_name($thrash1, $thrash2, $other, $returnType) +{ + global $config; + + if (!check_acl($config['id_user'], 0, 'AR')) { + returnError('forbidden', 'string'); + return; + } + + $sql = sprintf( + 'SELECT tup.id_usuario AS user_id, + tu.fullname AS fullname, + tup.id_up AS id_up, + tp.id_perfil AS profile_id, + tp.name AS profile_name, + tup.id_grupo AS group_id, + tg.nombre AS group_name + FROM tperfil tp + INNER JOIN tusuario_perfil tup + ON tp.id_perfil = tup.id_perfil + LEFT OUTER JOIN tgrupo tg + ON tup.id_grupo = tg.id_grupo + LEFT OUTER JOIN tusuario tu + ON tu.id_user = tup.id_usuario + WHERE tup.id_usuario = "%s"', + io_safe_output($other['data'][0]) + ); + + $user_profile = db_get_all_rows_sql($sql); + + $i = 0; + + foreach ($user_profile as $up) { + $group_name = $up['group_name']; + if ($up['group_name'] === null) { + $group_name = 'All'; + } + + $values[$i] = [ + 'id_usuario' => $up['user_id'], + 'fullname' => $up['fullname'], + 'id_up' => $up['id_up'], + 'id_perfil' => $up['profile_id'], + 'perfil_name' => $up['profile_name'], + 'id_grupo' => $up['group_id'], + 'group_name' => $group_name, + ]; + $i += 1; + } + + $data = [ + 'type' => 'array', + 'data' => $values, + ]; + + returnData($returnType, $data, ';'); +} + + +/** + * Function for get user from a group to new feature for Carrefour. + * It depends of returnType, the method will return csv or json data. + * + * @param string $thrash1 don't use + * @param string $thrash2 don't use + * @param array $other + * $other[0] = id group + * $other[1] = is disabled or not + * @param string $returnType + * Example + * api.php?op=get&op2=filter_user_group&return_type=json&other=0|0&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora + * + * @return + */ + + +function api_get_filter_user_group($thrash1, $thrash2, $other, $returnType) +{ + global $config; + + if (!check_acl($config['id_user'], 0, 'AR')) { + returnError('forbidden', 'string'); + return; + } + + $filter = ''; + + if ($other['data'][0] !== '' && $other['data'][1] !== '') { + $filter = 'WHERE tup.id_grupo = '.$other['data'][0].' AND tu.disabled = '.$other['data'][1].''; + } else if ($other['data'][0] !== '') { + $filter = 'WHERE tup.id_grupo = '.$other['data'][0].''; + } else if ($other['data'][1] !== '') { + $filter = 'WHERE tu.disabled = '.$other['data'][1].''; + } + + $sql = sprintf( + 'SELECT DISTINCT + tup.id_usuario AS user_id, + tu.fullname AS fullname, + tup.id_up AS id_up, + tp.id_perfil AS profile_id, + tp.name AS profile_name, + tup.id_grupo AS group_id, + tg.nombre AS group_name + FROM tperfil tp + INNER JOIN tusuario_perfil tup + ON tp.id_perfil = tup.id_perfil + LEFT OUTER JOIN tgrupo tg + ON tup.id_grupo = tg.id_grupo + LEFT OUTER JOIN tusuario tu + ON tu.id_user = tup.id_usuario + '.$filter.'' + ); + + $filter_user = db_get_all_rows_sql($sql); + + $i = 0; + + foreach ($filter_user as $up) { + $group_name = $up['group_name']; + if ($up['group_name'] === null) { + $group_name = 'All'; + } + + $values[$i] = [ + 'id_usuario' => $up['user_id'], + 'fullname' => $up['fullname'], + 'id_up' => $up['id_up'], + 'id_perfil' => $up['profile_id'], + 'perfil_name' => $up['profile_name'], + 'id_grupo' => $up['group_id'], + 'group_name' => $group_name, + ]; + $i += 1; + } + + $data = [ + 'type' => 'array', + 'data' => $values, + ]; + + returnData($returnType, $data, ';'); + +} + + +/** + * Function for delete an user permission for Carrefour new feature + * The return of this function its only a message + * + * @param string $thrash1 don't use + * @param string $thrash2 don't use + * @param array $other + * $other[0] = id up + * @param string $returnType + * Example + * api.php?op=set&op2=delete_user_permission&return_type=json&other=user|2&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora + * + * @return void + */ + + +function api_set_delete_user_permission($thrash1, $thrash2, $other, $returnType) +{ + global $config; + + if (!check_acl($config['id_user'], 0, 'AW')) { + returnError('forbidden', 'string'); + return; + } + + if ($other['data'][0] != '') { + $values = [ + 'id_up' => io_safe_output($other['data'][0]), + ]; + } else { + returnError('Error_delete', __('User profile could not be deleted.')); + return; + } + + $deleted_permission = db_process_sql_delete('tusuario_perfil', $values); + + if ($deleted_permission == false) { + returnError('Error_delete', __('User profile could not be deleted.')); + return; + } + + $data = [ + 'type' => 'string', + 'data' => $deleted_permission, + ]; + + returnData('string', ['type' => 'string', 'data' => $data]); +} + + +/** + * Function for add permission a user to a group for Carrefour new feature + * It depends of returnType, the method will return csv or json data + * + * @param string $thrash1 don't use + * @param string $thrash2 don't use + * @param array $other other[0] = user database + * other[1] = id group + * other[2] = id profile + * other[3] = no_hierarchy ( 0 or 1, if empty = 0) + * other[4] = id from tusuario_perfil table (optional) + * * @param string $returnType + * Example + * api.php?op=set&op2=add_permission_user_to_group&return_type=json&other=admin|0|1|1|20&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora + * + * @return void + */ + + +function api_set_add_permission_user_to_group($thrash1, $thrash2, $other, $returnType) +{ + global $config; + + if (!check_acl($config['id_user'], 0, 'AW')) { + returnError('forbidden', 'string'); + return; + } + + $sql = 'SELECT id_up + FROM tusuario_perfil + WHERE id_up = '.$other['data'][4].''; + + $exist_profile = db_get_value_sql($sql); + + if ($other['data'][3] < 0 || $other['data'][3] > 1) { + returnError('Error_insert', __('User profile could not be available.')); + return; + } + + if ($other['data'][3] == null) { + $other['data'][3] = 0; + } + + $values = [ + 'id_usuario' => $other['data'][0], + 'id_perfil' => $other['data'][2], + 'id_grupo' => $other['data'][1], + 'no_hierarchy' => $other['data'][3], + 'assigned_by' => $config['id_user'], + 'id_policy' => 0, + 'tags' => '', + + ]; + + $where_id_up = ['id_up' => $other['data'][4]]; + if ($exist_profile === $other['data'][4] && $where_id_up !== null) { + $sucessfull_insert = db_process_sql_update('tusuario_perfil', $values, $where_id_up); + } else { + $sucessfull_insert = db_process_sql_insert('tusuario_perfil', $values); + } + + if ($sucessfull_insert == false) { + returnError('Error_insert', __('User profile could not be available.')); + return; + } + + $data = [ + 'type' => 'array', + 'data' => $values, + ]; + + returnData($returnType, $data, ';'); + +} diff --git a/pandora_console/include/functions_clippy.php b/pandora_console/include/functions_clippy.php index f3bc6a5967..67999a75e0 100644 --- a/pandora_console/include/functions_clippy.php +++ b/pandora_console/include/functions_clippy.php @@ -296,7 +296,7 @@ function clippy_context_help($help=null) $code = str_replace('{clippy}', '#'.$id, $code); $code = str_replace('{clippy_obj}', 'intro_'.$id, $code); - $return = $code.'
        '.html_print_image( + $return = $code.' diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 9ba9ace3ff..87d0601a4f 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -224,6 +224,10 @@ function config_update_config() $error_update[] = __('Enable Netflow'); } + if (!config_update_value('activate_nta', (bool) get_parameter_switch('activate_nta'))) { + $error_update[] = __('Enable Network Traffic Analyzer'); + } + $timezone = (string) get_parameter('timezone'); if ($timezone != '') { if (!config_update_value('timezone', $timezone)) { @@ -266,7 +270,7 @@ function config_update_config() $error_update[] = __('Referer security'); } - if (!config_update_value('event_storm_protection', get_parameter('event_storm_protection'))) { + if (!config_update_value('event_storm_protection', get_parameter('event_storm_protection', 0))) { $error_update[] = __('Event storm protection'); } @@ -600,6 +604,10 @@ function config_update_config() config_update_value('ldap_save_password', 1); } + if (!config_update_value('ldap_save_profile', get_parameter('ldap_save_profile'))) { + $error_update[] = __('Save profile'); + } + if (!config_update_value('rpandora_server', get_parameter('rpandora_server'))) { $error_update[] = __('MySQL host'); } @@ -756,6 +764,10 @@ function config_update_config() $error_update[] = __('Max. days before delete old messages'); } + if (!config_update_value('delete_old_network_matrix', get_parameter('delete_old_network_matrix'))) { + $error_update[] = __('Max. days before delete old network matrix data'); + } + if (!config_update_value('max_graph_container', get_parameter('max_graph_container'))) { $error_update[] = __('Graph container - Max. Items'); } @@ -896,6 +908,14 @@ function config_update_config() $error_update[] = __('Custom networkmap center logo'); } + if (!config_update_value('custom_title_header', (string) get_parameter('custom_title_header'))) { + $error_update[] = __('Custom title header'); + } + + if (!config_update_value('custom_subtitle_header', (string) get_parameter('custom_subtitle_header'))) { + $error_update[] = __('Custom subtitle header'); + } + if (!config_update_value('custom_title1_login', (string) get_parameter('custom_title1_login'))) { $error_update[] = __('Custom title1 login'); } @@ -960,7 +980,15 @@ function config_update_config() $error_update[] = __('Custom support url'); } - if (!config_update_value('vc_refr', get_parameter('vc_refr'))) { + if (!config_update_value('legacy_vc', (int) get_parameter('legacy_vc'))) { + $error_update[] = __('Use the legacy Visual Console'); + } + + if (!config_update_value('vc_default_cache_expiration', (int) get_parameter('vc_default_cache_expiration'))) { + $error_update[] = __("Default expiration of the Visual Console item's cache"); + } + + if (!config_update_value('vc_refr', (int) get_parameter('vc_refr'))) { $error_update[] = __('Default interval for refresh on Visual Console'); } @@ -1325,10 +1353,14 @@ function config_update_config() break; case 'ehorus': - if (!config_update_value('ehorus_enabled', (int) get_parameter('ehorus_enabled', $config['ehorus_enabled']))) { + if (!config_update_value('ehorus_enabled', (int) get_parameter('ehorus_enabled', 0))) { $error_update[] = __('Enable eHorus'); } + if (!config_update_value('ehorus_user_level_conf', (int) get_parameter('ehorus_user_level_conf', 0))) { + $error_update[] = __('eHorus user login'); + } + if (!config_update_value('ehorus_user', (string) get_parameter('ehorus_user', $config['ehorus_user']))) { $error_update[] = __('eHorus user'); } @@ -1547,6 +1579,10 @@ function config_process_config() config_update_value('delete_old_messages', 21); } + if (!isset($config['delete_old_network_matrix'])) { + config_update_value('delete_old_network_matrix', 10); + } + if (!isset($config['max_graph_container'])) { config_update_value('max_graph_container', 10); } @@ -1792,7 +1828,7 @@ function config_process_config() } if (!isset($config['custom_logo'])) { - config_update_value('custom_logo', 'pandora_logo_head_green.png'); + config_update_value('custom_logo', 'pandora_logo_head_4.png'); } if (!isset($config['custom_logo_collapsed'])) { @@ -1827,6 +1863,14 @@ function config_process_config() config_update_value('custom_mobile_console_logo', ''); } + if (!isset($config['custom_title_header'])) { + config_update_value('custom_title_header', __('Pandora FMS')); + } + + if (!isset($config['custom_subtitle_header'])) { + config_update_value('custom_subtitle_header', __('the Flexible Monitoring System')); + } + if (!isset($config['custom_title1_login'])) { config_update_value('custom_title1_login', __('PANDORA FMS')); } @@ -1975,6 +2019,10 @@ function config_process_config() config_update_value('activate_netflow', 0); } + if (!isset($config['activate_nta'])) { + config_update_value('activate_nta', 0); + } + if (!isset($config['netflow_path'])) { if ($is_windows) { $default = 'C:\\PandoraFMS\\Pandora_Server\\data_in\\netflow'; @@ -2119,9 +2167,9 @@ function config_process_config() if (!isset($config['ad_adv_perms'])) { config_update_value('ad_adv_perms', ''); } else { + $temp_ad_adv_perms = []; if (!json_decode(io_safe_output($config['ad_adv_perms']))) { - $temp_ad_adv_perms = []; - if (!isset($config['ad_adv_perms']) && $config['ad_adv_perms'] != '') { + if ($config['ad_adv_perms'] != '') { $perms = explode(';', io_safe_output($config['ad_adv_perms'])); foreach ($perms as $ad_adv_perm) { if (preg_match('/[\[\]]/', $ad_adv_perm)) { @@ -2184,22 +2232,26 @@ function config_process_config() if (!empty($new_ad_adv_perms)) { $temp_ad_adv_perms = json_encode($new_ad_adv_perms); } + } else { + $temp_ad_adv_perms = ''; } - - config_update_value('ad_adv_perms', $temp_ad_adv_perms); + } else { + $temp_ad_adv_perms = $config['ad_adv_perms']; } + + config_update_value('ad_adv_perms', $temp_ad_adv_perms); } if (!isset($config['ldap_adv_perms'])) { config_update_value('ldap_adv_perms', ''); } else { + $temp_ldap_adv_perms = []; if (!json_decode(io_safe_output($config['ldap_adv_perms']))) { - $temp_ldap_adv_perms = []; - if (!isset($config['ad_adv_perms']) && $config['ldap_adv_perms'] != '') { + if ($config['ldap_adv_perms'] != '') { $perms = explode(';', io_safe_output($config['ldap_adv_perms'])); - foreach ($perms as $ad_adv_perm) { - if (preg_match('/[\[\]]/', $ad_adv_perm)) { - $all_data = explode(',', io_safe_output($ad_adv_perm)); + foreach ($perms as $ldap_adv_perm) { + if (preg_match('/[\[\]]/', $ldap_adv_perm)) { + $all_data = explode(',', io_safe_output($ldap_adv_perm)); $profile = $all_data[0]; $group_pnd = $all_data[1]; $groups_ad = str_replace(['[', ']'], '', $all_data[2]); @@ -2229,7 +2281,7 @@ function config_process_config() 'groups_ldap' => $groups_ldap, ]; } else { - $all_data = explode(',', io_safe_output($ad_adv_perm)); + $all_data = explode(',', io_safe_output($ldap_adv_perm)); $profile = $all_data[0]; $group_pnd = $all_data[1]; $groups_ad = $all_data[2]; @@ -2258,10 +2310,14 @@ function config_process_config() if (!empty($new_ldap_adv_perms)) { $temp_ldap_adv_perms = json_encode($new_ldap_adv_perms); } + } else { + $temp_ldap_adv_perms = ''; } - - config_update_value('ldap_adv_perms', $temp_ldap_adv_perms); + } else { + $temp_ldap_adv_perms = $config['ldap_adv_perms']; } + + config_update_value('ldap_adv_perms', $temp_ldap_adv_perms); } if (!isset($config['rpandora_server'])) { @@ -2379,10 +2435,22 @@ function config_process_config() config_update_value('dbtype', 'mysql'); } + if (!isset($config['legacy_vc'])) { + config_update_value('legacy_vc', 1); + } + + if (!isset($config['vc_default_cache_expiration'])) { + config_update_value('vc_default_cache_expiration', 60); + } + if (!isset($config['vc_refr'])) { config_update_value('vc_refr', 300); } + if (!isset($config['vc_line_thickness'])) { + config_update_value('vc_line_thickness', 2); + } + if (!isset($config['agent_size_text_small'])) { config_update_value('agent_size_text_small', 18); } @@ -2684,9 +2752,7 @@ function config_check() if (enterprise_installed() === false) { $supervisor = new ConsoleSupervisor(false); $supervisor->run(); - } else if ($config['cron_last_run'] == 0 - || (get_system_time() - $config['cron_last_run']) > 3600 - ) { + } else { $supervisor = new ConsoleSupervisor(false); $supervisor->runBasic(); } @@ -2694,6 +2760,31 @@ function config_check() } +/** + * Retrieves base url stored for Update Manager. + * + * @return string URL. + */ +function get_um_url() +{ + global $config; + + if (isset($config['url_update_manager'])) { + $url = $config['url_update_manager']; + $url = substr($url, 0, (strlen($url) - strpos(strrev($url), '/'))); + } else { + $url = 'https://licensing.artica.es/pandoraupdate7/'; + config_update_value( + 'url_update_manager', + 'https://licensing.artica.es/pandoraupdate7/server.php' + ); + } + + return $url; + +} + + /** * Return in bytes * diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index e56a3d4a52..6a79096175 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -1,34 +1,51 @@ $module_id] - ); + $module_interval = db_get_value( + 'module_interval', + 'tagente_modulo', + 'id_agente_modulo', + $module_id + ); + + if ($cron === '* * * * *') { return db_process_sql( 'UPDATE tagente_estado SET current_interval = '.$module_interval.' WHERE id_agente_modulo = '.(int) $module_id ); @@ -41,15 +58,19 @@ function cron_update_module_interval($module_id, $cron) } -// Get the number of seconds left to the next execution of the given cron entry. +/** + * Get the number of seconds left to the next execution of the given cron entry. + * + * @param string $cron String with the Linux cron configuration. + * @param integer $module_interval Module interval. Minimum increased time. + * @param integer $module_id Module id. + * + * @return integer Time to next execution time. + */ function cron_next_execution($cron, $module_interval, $module_id) { // Get day of the week and month from cron config. $cron_array = explode(' ', $cron); - $minute = $cron_array[0]; - $hour = $cron_array[1]; - $mday = $cron_array[2]; - $month = $cron_array[3]; $wday = $cron_array[4]; // Get last execution time. @@ -60,55 +81,35 @@ function cron_next_execution($cron, $module_interval, $module_id) $module_id ); $cur_time = ($last_execution !== false) ? $last_execution : time(); - - // Any day of the way. - if ($wday == '*') { - $nex_time = cron_next_execution_date( - $cron, - $cur_time, - $module_interval - ); - return ($nex_time - $cur_time); + $nex_time = cron_next_execution_date($cron, $cur_time, $module_interval); + $nex_wday = (int) date('w', $nex_time); + // Check the wday values to avoid infinite loop. + $wday_int = cron_get_interval($wday); + if ($wday_int['down'] !== '*' && ($wday_int['down'] > 6 || ($wday_int['up'] !== false && $wday_int['up'] > 6))) { + $wday = '*'; } - // A specific day of the week. - $count = 0; - $nex_time = $cur_time; - do { - $nex_time = cron_next_execution_date( - $cron, - $nex_time, - $module_interval - ); - $nex_time_wd = $nex_time; + // Check day of the way. + while (!cron_check_interval($nex_wday, $wday)) { + // If it does not acomplish the day of the week, go to the next day. + $nex_time += SECONDS_1DAY; + $nex_time = cron_next_execution_date($cron, $nex_time, 0); + $nex_wday = (int) date('w', $nex_time); + } - $array_nex = explode(' ', date('m w', $nex_time_wd)); - $nex_mon = $array_nex[0]; - $nex_wday = $array_nex[1]; - - do { - // Check the day of the week. - if ($nex_wday == $wday) { - return ($nex_time_wd - $cur_time); - } - - // Move to the next day of the month. - $nex_time_wd += SECONDS_1DAY; - - $array_nex_w = explode(' ', date('m w', $nex_time_wd)); - $nex_mon_wd = $array_nex_w[0]; - $nex_wday = $array_nex_w[1]; - } while ($mday == '*' && $nex_mon_wd == $nex_mon); - - $count++; - } while ($count < SECONDS_1MINUTE); - - // Something went wrong, default to 5 minutes. - return SECONDS_5MINUTES; + return ($nex_time - $cur_time); } -// Get the next execution date for the given cron entry in seconds since epoch. +/** + * Get the next execution date for the given cron entry in seconds since epoch. + * + * @param string $cron String with the Linux cron configuration. + * @param integer $cur_time Current time in utimestamp. + * @param integer $module_interval Module interval. Minimum increased time. + * + * @return integer Next execution timestamp seing the cron configuration. + */ function cron_next_execution_date($cron, $cur_time=false, $module_interval=300) { // Get cron configuration. @@ -127,8 +128,7 @@ function cron_next_execution_date($cron, $cur_time=false, $module_interval=300) } // Update minutes. - $min_s = cron_get_interval($cron_array[0]); - $nex_time_array[0] = ($min_s['down'] == '*') ? 0 : $min_s['down']; + $nex_time_array[0] = cron_get_next_time_element($cron_array[0]); $nex_time = cron_valid_date($nex_time_array); if ($nex_time >= $cur_time) { @@ -166,8 +166,7 @@ function cron_next_execution_date($cron, $cur_time=false, $module_interval=300) } // Update the hour if fails. - $hour_s = cron_get_interval($cron_array[1]); - $nex_time_array[1] = ($hour_s['down'] == '*') ? 0 : $hour_s['down']; + $nex_time_array[1] = cron_get_next_time_element($cron_array[1]); // When an overflow is passed check the hour update again. $nex_time = cron_valid_date($nex_time_array); @@ -199,8 +198,7 @@ function cron_next_execution_date($cron, $cur_time=false, $module_interval=300) } // Update the day if fails. - $mday_s = cron_get_interval($cron_array[2]); - $nex_time_array[2] = ($mday_s['down'] == '*') ? 1 : $mday_s['down']; + $nex_time_array[2] = cron_get_next_time_element($cron_array[2]); // When an overflow is passed check the hour update in the next execution. $nex_time = cron_valid_date($nex_time_array); @@ -226,8 +224,7 @@ function cron_next_execution_date($cron, $cur_time=false, $module_interval=300) } // Update the month if fails. - $mon_s = cron_get_interval($cron_array[3]); - $nex_time_array[3] = ($mon_s['down'] == '*') ? 1 : $mon_s['down']; + $nex_time_array[3] = cron_get_next_time_element($cron_array[3]); // When an overflow is passed check the hour update in the next execution. $nex_time = cron_valid_date($nex_time_array); @@ -245,7 +242,33 @@ function cron_next_execution_date($cron, $cur_time=false, $module_interval=300) } -// Get an array with the cron interval. +/** + * Get the next tentative time for a cron value or interval in case of overflow. + * + * @param string $cron_array_elem Cron element. + * + * @return integer The tentative time. Ex: + * * shold returns 0. + * 5 should returns 5. + * 10-55 should returns 10. + * 55-10 should retunrs 0. + */ +function cron_get_next_time_element($cron_array_elem) +{ + $interval = cron_get_interval($cron_array_elem); + $value = ($interval['down'] == '*' || ($interval['up'] !== false && $interval['down'] > $interval['up'] )) ? 0 : $interval['down']; + return $value; +} + + +/** + * Get an array with the cron interval. + * + * @param string $element String with the elemen cron configuration. + * + * @return array With up and down elements. + * If there is not an interval, up element will be false. + */ function cron_get_interval($element) { // Not a range. @@ -263,7 +286,14 @@ function cron_get_interval($element) } -// Returns if a date is in a cron. Recursive. +/** + * Returns if a date is in a cron. Recursive. + * + * @param array $elems_cron Cron configuration in array format. + * @param integer $elems_curr_time Time to check if is in cron. + * + * @return boolean Returns true if is in cron. False if it is outside. + */ function cron_is_in_cron($elems_cron, $elems_curr_time) { $elem_cron = array_shift($elems_cron); @@ -275,31 +305,62 @@ function cron_is_in_cron($elems_cron, $elems_curr_time) } // Go to last element if current is a wild card. - if ($elem_cron != '*') { - $elem_s = cron_get_interval($elem_cron); - // Check if there is no a range - if (($elem_s['up'] === false) && ($elem_s['down'] != $elem_curr_time)) { - return false; - } - - // Check if there is on the range. - if ($elem_s['up'] !== false) { - if ($elem_s['down'] < $elem_s['up']) { - if ($elem_curr_time < $elem_s['down'] || $elem_curr_time > $elem_s['up']) { - return false; - } - } else { - if ($elem_curr_time > $elem_s['down'] || $elem_curr_time < $elem_s['up']) { - return false; - } - } - } + if (cron_check_interval($elem_curr_time, $elem_cron) === false) { + return false; } return cron_is_in_cron($elems_cron, $elems_curr_time); } +/** + * Check if an element is inside the cron interval or not. + * + * @param integer $elem_curr_time Integer that represents the time to check. + * @param string $elem_cron Cron interval (splitted by hypen) + * or cron single value (a number). + * + * @return boolean True if is in interval. + */ +function cron_check_interval($elem_curr_time, $elem_cron) +{ + // Go to last element if current is a wild card. + if ($elem_cron === '*') { + return true; + } + + $elem_s = cron_get_interval($elem_cron); + // Check if there is no a range. + if (($elem_s['up'] === false) && ($elem_s['down'] != $elem_curr_time)) { + return false; + } + + // Check if there is on the range. + if ($elem_s['up'] !== false && (int) $elem_s['up'] === (int) $elem_curr_time) { + return true; + } + + if ($elem_s['down'] < $elem_s['up']) { + if ($elem_curr_time < $elem_s['down'] || $elem_curr_time > $elem_s['up']) { + return false; + } + } else { + if ($elem_curr_time > $elem_s['down'] || $elem_curr_time < $elem_s['up']) { + return false; + } + } + + return true; +} + + +/** + * Check if a date is correct or not. + * + * @param array $da Date in array format [year, month, day, hour, minutes]. + * + * @return integer Utimestamp. False if date is incorrect. + */ function cron_valid_date($da) { $st = sprintf( @@ -315,7 +376,13 @@ function cron_valid_date($da) } -// Check if cron is properly constructed. +/** + * Check if cron is properly constructed. + * + * @param string $cron String with the Linux cron configuration. + * + * @return boolean True if is well formed. False otherwise. + */ function cron_check_syntax($cron) { return preg_match( @@ -325,6 +392,11 @@ function cron_check_syntax($cron) } +/** + * Cron list table. + * + * @return void It prints the HTML table. + */ function cron_list_table() { global $config; @@ -429,8 +501,10 @@ function cron_list_table() } $email = $args[1]; + $report_type = $args[4]; $data[2] .= '
        - '.__('Report').": "; $data[2] .= $report['name'].''; + $data[2] .= '
        - '.__('Report type').': '.$report_type; $data[2] .= '
        - '.__('Email').": "; $data[2] .= ui_print_truncate_text($email, 60, false).''; break; diff --git a/pandora_console/include/functions_custom_fields.php b/pandora_console/include/functions_custom_fields.php index 7e28b1dcd2..d1f661e874 100644 --- a/pandora_console/include/functions_custom_fields.php +++ b/pandora_console/include/functions_custom_fields.php @@ -1,16 +1,31 @@ $v) { - $array_result[$v['description']] = $v['description']; + if (isset($result) === true + && is_array($result) === true + ) { + foreach ($result as $k => $v) { + $array_result[$v['description']] = $v['description']; + } } } } @@ -189,9 +210,15 @@ function get_custom_fields_data($custom_field_name) } +/** + * Function for custom field view return all conter for agents + * + * @param array $filters Params for search. + * @return void False or array. + */ function agent_counters_custom_fields($filters) { - // filter by status agent + // Filter by status agent. $and_status = ''; $agent_state_normal = 0; @@ -262,7 +289,7 @@ function agent_counters_custom_fields($filters) } } - // filter by status module + // Filter by status module. $empty_agents_count = "UNION ALL SELECT ta.id_agente, 0 AS c_m_total, @@ -314,20 +341,20 @@ function agent_counters_custom_fields($filters) $and_module_status .= ' ) '; } } else { - // not normal + // Not normal. $and_module_status = 'AND tae.estado <> 0 AND tae.estado <> 300 '; $empty_agents_count = ''; } } } - // filters module + // Filters module. if ($filters['module_search']) { $and_module_search = 'AND tam.nombre LIKE "%'.$filters['module_search'].'%"'; $empty_agents_count = ''; } - // filter group and check ACL groups + // Filter group and check ACL groups. $groups_and = ''; if (!users_can_manage_group_all('AR')) { if ($filters['group']) { @@ -338,7 +365,7 @@ function agent_counters_custom_fields($filters) } if ($filters['group']) { - // recursion check acl + // Recursion check acl. if ($filters['recursion']) { $recursion_groups = groups_get_id_recursive($filters['group'], true); if (!users_can_manage_group_all('AR')) { @@ -362,26 +389,30 @@ function agent_counters_custom_fields($filters) } } - // filter custom data + // Filter custom data. $custom_data_and = ''; - if (!in_array(-1, $filters['id_custom_fields_data'])) { - $custom_data_array = implode("', '", $filters['id_custom_fields_data']); - $custom_data_and = "AND tcd.description IN ('".$custom_data_array."')"; + if (isset($filters['id_custom_fields_data']) === true + && is_array($filters['id_custom_fields_data']) === true + ) { + if (!in_array(-1, $filters['id_custom_fields_data'])) { + $custom_data_array = implode("', '", $filters['id_custom_fields_data']); + $custom_data_and = "AND tcd.description IN ('".$custom_data_array."')"; + } } - // filter custom name + // Filter custom name. $custom_field_name = $filters['id_custom_fields']; if (is_metaconsole()) { $metaconsole_connections = metaconsole_get_connection_names(); - // For all nodes + // For all nodes. if (isset($metaconsole_connections) && is_array($metaconsole_connections)) { $result_meta = []; $data = []; foreach ($metaconsole_connections as $metaconsole) { - // Get server connection data + // Get server connection data. $server_data = metaconsole_get_connection($metaconsole); - // Establishes connection + // Establishes connection. if (metaconsole_load_external_db($server_data) !== NOERR) { continue; } @@ -470,7 +501,13 @@ function agent_counters_custom_fields($filters) WHEN ta.total_count = ta.notinit_count THEN 5 ELSE 0 - END) AS `status` + END) AS `status`, + ta.critical_count, + ta.warning_count, + ta.unknown_count, + ta.notinit_count, + ta.normal_count, + ta.total_count FROM tagente ta LEFT JOIN tagent_secondary_group tasg ON ta.id_agente = tasg.id_agent @@ -510,7 +547,7 @@ function agent_counters_custom_fields($filters) } $data = array_merge($data, $node_result); - // Restore connection to root node + // Restore connection to root node. metaconsole_restore_db(); } } @@ -519,7 +556,7 @@ function agent_counters_custom_fields($filters) $array_data = []; if (isset($result_meta) && is_array($result_meta)) { - // initialize counters + // Initialize counters. $final_result['counters_total'] = [ 't_m_normal' => 0, 't_m_critical' => 0, @@ -538,7 +575,7 @@ function agent_counters_custom_fields($filters) foreach ($result_meta as $k => $nodo) { if (isset($nodo) && is_array($nodo)) { foreach ($nodo as $key => $value) { - // Sum counters total + // Sum counters total. $final_result['counters_total']['t_m_normal'] += $value['m_normal']; $final_result['counters_total']['t_m_critical'] += $value['m_critical']; $final_result['counters_total']['t_m_warning'] += $value['m_warning']; @@ -553,7 +590,7 @@ function agent_counters_custom_fields($filters) $final_result['counters_total']['t_a_not_init'] += $value['a_not_init']; $final_result['counters_total']['t_a_agents'] += $value['a_agents']; - // Sum counters for data + // Sum counters for data. $array_data[$value['name_data']]['m_normal'] += $value['m_normal']; $array_data[$value['name_data']]['m_critical'] += $value['m_critical']; $array_data[$value['name_data']]['m_warning'] += $value['m_warning']; @@ -576,7 +613,7 @@ function agent_counters_custom_fields($filters) $final_result['indexed_descriptions'] = $data; } else { - // TODO + // TODO. $final_result = false; } @@ -586,7 +623,7 @@ function agent_counters_custom_fields($filters) function get_filters_custom_fields_view($id=0, $for_select=false, $name='') { - // filter group and check ACL groups + // Filter group and check ACL groups. $groups_and = ''; if (!users_can_manage_group_all()) { $user_groups = array_keys(users_get_groups(false, 'AR', false)); @@ -631,3 +668,158 @@ function get_group_filter_custom_field_view($id) return false; } + + +/** + * Function for print counters agents or modules. + * + * @param array $status_array Array need value, image, title, color, counter. + * @param string $id_form Id form default value ''. + * @param string $id_input Id input default value ''. + * + * @return array Return html print div container counters. + */ +function print_counters_cfv( + array $status_array, + string $id_form='', + string $id_input='' +) { + $html_result = ''; + foreach ($status_array as $key => $value) { + $checked = ($value['checked'] === 1) ? 'checked=true' : ''; + $disabled = ($value['counter'] === 0) ? 'disabled=true' : ''; + + $html_result .= ''; + $html_result .= ''; + } + + $html_result .= ''; + return $html_result; +} + + +/** + * Function for export a csv file from Custom Fields View + * + * @param array $filters Status counters for agents and modules. + * @param array $id_status Agent status. + * @param array $module_status Module status. + * + * @return array Returns the data that will be saved in the csv file + */ +function export_custom_fields_csv($filters, $id_status, $module_status) +{ + $data = agent_counters_custom_fields($filters); + $indexed_descriptions = $data['indexed_descriptions']; + + // Table temporary for save array in table + // by order and search custom_field data. + $table_temporary = 'CREATE TEMPORARY TABLE temp_custom_fields ( + id_server int(10), + id_agent int(10), + name_custom_fields varchar(2048), + critical_count int, + warning_count int, + unknown_count int, + notinit_count int, + normal_count int, + total_count int, + `status` int(2), + KEY `data_index_temp_1` (`id_server`, `id_agent`) + )'; + db_process_sql($table_temporary); + + // Insert values array in table temporary. + $values_insert = []; + foreach ($indexed_descriptions as $key => $value) { + $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')'; + } + + $values_insert_implode = implode(',', $values_insert); + $query_insert = 'INSERT INTO temp_custom_fields VALUES '.$values_insert_implode; + db_process_sql($query_insert); + + // Search for status module. + $status_agent_search = ''; + if (isset($id_status) === true && is_array($id_status) === true) { + if (in_array(-1, $id_status) === false) { + if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $id_status) === false) { + $status_agent_search = ' AND temp.status IN ('.implode(',', $id_status).')'; + } else { + // Not normal statuses. + $status_agent_search = ' AND temp.status IN (1,2,3,4,5)'; + } + } + } + + // Search for status module. + $status_module_search = ''; + if (isset($module_status) === true && is_array($module_status) === true) { + if (in_array(-1, $module_status) === false) { + if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $module_status) === false) { + if (count($module_status) > 0) { + $status_module_search = ' AND ( '; + foreach ($module_status as $key => $value) { + $status_module_search .= ($key != 0) ? ' OR (' : ' ('; + switch ($value) { + default: + case AGENT_STATUS_NORMAL: + $status_module_search .= ' temp.normal_count > 0) '; + break; + case AGENT_STATUS_CRITICAL: + $status_module_search .= ' temp.critical_count > 0) '; + break; + + case AGENT_STATUS_WARNING: + $status_module_search .= ' temp.warning_count > 0) '; + break; + + case AGENT_STATUS_UNKNOWN: + $status_module_search .= ' temp.unknown_count > 0) '; + break; + + case AGENT_STATUS_NOT_INIT: + $status_module_search .= ' temp.notinit_count > 0) '; + break; + } + } + + $status_module_search .= ' ) '; + } + } else { + // Not normal. + $status_module_search = ' AND ( temp.critical_count > 0 OR temp.warning_count > 0 OR temp.unknown_count > 0 AND temp.notinit_count > 0 )'; + } + } + } + + // Query all fields result. + $query = sprintf( + 'SELECT + temp.name_custom_fields, + tma.alias, + tma.direccion, + tma.server_name, + temp.status + FROM tmetaconsole_agent tma + INNER JOIN temp_custom_fields temp + ON temp.id_agent = tma.id_tagente + AND temp.id_server = tma.id_tmetaconsole_setup + WHERE tma.disabled = 0 + %s + %s + ', + $status_agent_search, + $status_module_search + ); + + $result = db_get_all_rows_sql($query); + return $result; +} diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 4859f4f378..f98084f808 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -161,3 +161,35 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t return $graphs; } + + +function custom_graphs_search($id_group, $search) +{ + if ($id_group != '' && $search != '') { + $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND name LIKE "%'.$search.'%"'); + } else if ($id_group != '') { + $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.''); + } else { + $all_graphs = db_get_all_rows_sql('select * from tgraph where name LIKE "%'.$search.'%"'); + } + + if ($all_graphs === false) { + return []; + } + + $graphs = []; + foreach ($all_graphs as $graph) { + $graphsCount = db_get_value_sql( + 'SELECT COUNT(id_gs) + FROM tgraph_source + WHERE id_graph = '.$graph['id_graph'].'' + ); + + $graphs[$graph['id_graph']]['graphs_count'] = $graphsCount; + $graphs[$graph['id_graph']]['name'] = $graph['name']; + $graphs[$graph['id_graph']]['description'] = $graph['description']; + $graphs[$graph['id_graph']]['id_group'] = $graph['id_group']; + } + + return $graphs; +} diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 9018a1044d..2061ab215c 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -421,13 +421,13 @@ function db_get_row_sql($sql, $search_history_db=false) * * @return mixed The first row of a database query or false. */ -function db_get_row($table, $field_search, $condition, $fields=false) +function db_get_row($table, $field_search, $condition, $fields=false, $cache=true) { global $config; switch ($config['dbtype']) { case 'mysql': - return mysql_db_get_row($table, $field_search, $condition, $fields); + return mysql_db_get_row($table, $field_search, $condition, $fields, $cache); break; case 'postgresql': diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index dc69af7baf..3feceb847b 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -959,6 +959,8 @@ function events_print_event_table( ) { global $config; + ui_require_css_file('events'); + if ($agent_id == 0) { $agent_condition = ''; } else { @@ -997,7 +999,7 @@ function events_print_event_table( $table->cellpadding = 0; $table->cellspacing = 0; $table->width = $width; - $table->class = 'databox data'; + $table->class = 'info_table no-td-padding'; if (!$tactical_view) { $table->title = __('Latest events'); } @@ -1010,36 +1012,38 @@ function events_print_event_table( $table->cellclass = []; $table->data = []; $table->align = []; - $table->style[0] = 'width:25px;'; - $table->style[1] = 'width:25px;'; - $table->style[2] = 'width:25px;'; - if ($agent_id == 0) { - $table->style[3] = 'word-break: break-all;'; - } + $table->style = []; - $table->style[4] = 'width:120px; word-break: break-all;'; + $i = 0; + $table->head[$i] = "".__('S.').''; + $table->headstyle[$i] = 'width: 1%;text-align: center;'; + $table->style[$i++] = 'text-align: center;'; - $table->head[0] = "".__('V.').''; - $table->align[0] = 'center'; + $table->head[$i] = __('Type'); + $table->headstyle[$i] = 'width: 3%;text-align: center;'; + $table->style[$i++] = 'text-align: center;'; - $table->head[1] = "".__('S.').''; - $table->align[1] = 'center'; - - $table->head[2] = __('Type'); - $table->headclass[2] = 'datos3 f9'; - $table->align[2] = 'center'; - - $table->head[3] = __('Event name'); + $table->head[$i] = __('Event name'); + $table->headstyle[$i] = ''; + $table->style[$i++] = 'word-break: break-word;'; if ($agent_id == 0) { - $table->head[4] = __('Agent name'); - $table->size[4] = '15%'; + $table->head[$i] = __('Agent name'); + $table->headstyle[$i] = ''; + $table->style[$i++] = 'word-break: break-all;'; } - $table->head[5] = __('Timestamp'); - $table->headclass[5] = 'datos3 f9'; - $table->align[5] = 'left'; - $table->size[5] = '15%'; + $table->head[$i] = __('Timestamp'); + $table->headstyle[$i] = 'width: 120px;'; + $table->style[$i++] = 'word-break: break-word;'; + + $table->head[$i] = __('Status'); + $table->headstyle[$i] = 'width: 150px;text-align: center;'; + $table->style[$i++] = 'text-align: center;'; + + $table->head[$i] = "".__('V.').''; + $table->headstyle[$i] = 'width: 1%;text-align: center;'; + $table->style[$i++] = 'text-align: center;'; $all_groups = []; if ($agent_id != 0) { @@ -1078,53 +1082,15 @@ function events_print_event_table( break; } - $data[0] = html_print_image( - $img, - true, - [ - 'class' => 'image_status', - 'title' => $title, - ] - ); - - switch ($event['criticity']) { - default: - case EVENT_CRIT_MAINTENANCE: - $img = 'images/status_sets/default/severity_maintenance.png'; - break; - case EVENT_CRIT_INFORMATIONAL: - $img = 'images/status_sets/default/severity_informational.png'; - break; - - case EVENT_CRIT_NORMAL: - $img = 'images/status_sets/default/severity_normal.png'; - break; - - case EVENT_CRIT_WARNING: - $img = 'images/status_sets/default/severity_warning.png'; - break; - - case EVENT_CRIT_CRITICAL: - $img = 'images/status_sets/default/severity_critical.png'; - break; - } - - $data[1] = html_print_image( - $img, - true, - [ - 'class' => 'image_status', - 'width' => 12, - 'height' => 12, - 'title' => get_priority_name($event['criticity']), - ] - ); + $i = 0; + // Criticity. + $data[$i++] = ui_print_event_priority($event['criticity'], true, true); // Event type. - $data[2] = events_print_type_img($event['event_type'], true); + $data[$i++] = events_print_type_img($event['event_type'], true); // Event text. - $data[3] = ui_print_string_substr( + $data[$i++] = ui_print_string_substr( strip_tags(io_safe_output($event['evento'])), 75, true, @@ -1135,33 +1101,32 @@ function events_print_event_table( if ($event['id_agente'] > 0) { // Agent name. // Get class name, for the link color, etc. - $myclass = get_priority_class($event['criticity']); - - $data[4] = "".agents_get_alias($event['id_agente']).''; + $data[$i] = "".agents_get_alias($event['id_agente']).''; // For System or SNMP generated alerts. } else if ($event['event_type'] == 'system') { - $data[4] = __('System'); + $data[$i] = __('System'); } else { - $data[4] = __('Alert').'SNMP'; + $data[$i] = __('Alert').'SNMP'; } + + $i++; } // Timestamp. - $data[5] = ui_print_timestamp($event['timestamp'], true, ['style' => 'font-size: 7.5pt; letter-spacing: 0.3pt;']); + $data[$i++] = ui_print_timestamp($event['timestamp'], true, ['style' => 'font-size: 7.5pt; letter-spacing: 0.3pt;']); - $class = get_priority_class($event['criticity']); - $cell_classes[3] = $class; - $cell_classes[4] = $class; - $cell_classes[5] = $class; + // Status. + $data[$i++] = ui_print_event_type($event['event_type'], true); - array_push($table->cellclass, $cell_classes); - - /* - Commented out (old). - // array_push ($table->rowclass, get_priority_class ($event["criticity"])); - */ - - array_push($table->data, $data); + $data[$i++] = html_print_image( + $img, + true, + [ + 'class' => 'image_status', + 'title' => $title, + ] + ); + $table->data[] = $data; } $events_table = html_print_table($table, true); @@ -1646,7 +1611,7 @@ function events_get_agent( $sql_where, 0, 1000, - is_metaconsole(), + (is_metaconsole() && $id_server) ? true : false, false, false, $history @@ -1987,9 +1952,9 @@ function events_page_responses($event, $childrens_ids=[]) $table_responses->width = '100%'; $table_responses->data = []; $table_responses->head = []; - $table_responses->style[0] = 'width:35%; font-weight: bold; text-align: left; height: 23px;'; - $table_responses->style[1] = 'text-align: left; height: 23px; text-align: right;'; - $table_responses->class = 'alternate rounded_cells'; + $table_responses->style[0] = 'height:30px'; + $table_responses->style[2] = 'text-align:right;'; + $table_responses->class = 'table_modal_alternate'; if (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EM', $event['clean_tags'], $childrens_ids)) { // Owner. @@ -2056,7 +2021,7 @@ function events_page_responses($event, $childrens_ids=[]) -1, true ); - $data[1] .= html_print_button( + $data[2] .= html_print_button( __('Update'), 'owner_button', false, @@ -2136,7 +2101,7 @@ function events_page_responses($event, $childrens_ids=[]) ); if (!$status_blocked) { - $data[1] .= html_print_button( + $data[2] .= html_print_button( __('Update'), 'status_button', false, @@ -2151,7 +2116,8 @@ function events_page_responses($event, $childrens_ids=[]) // Comments. $data = []; $data[0] = __('Comment'); - $data[1] = html_print_button( + $data[1] = ''; + $data[2] = html_print_button( __('Add comment'), 'comment_button', false, @@ -2173,8 +2139,9 @@ function events_page_responses($event, $childrens_ids=[]) // Delete. $data = []; $data[0] = __('Delete event'); - $data[1] = '
        '; - $data[1] .= html_print_button( + $data[1] = ''; + $data[2] = ''; + $data[2] .= html_print_button( __('Delete event'), 'delete_button', false, @@ -2182,13 +2149,13 @@ function events_page_responses($event, $childrens_ids=[]) 'class="sub cancel"', true ); - $data[1] .= html_print_input_hidden('delete', 1, true); - $data[1] .= html_print_input_hidden( + $data[2] .= html_print_input_hidden('delete', 1, true); + $data[2] .= html_print_input_hidden( 'validate_ids', $event['id_evento'], true ); - $data[1] .= '
        '; + $data[2] .= ''; $table_responses->data[] = $data; } @@ -2229,7 +2196,7 @@ function events_page_responses($event, $childrens_ids=[]) $server_id = 0; } - $data[1] .= html_print_button( + $data[2] .= html_print_button( __('Execute'), 'custom_response_button', false, @@ -2249,14 +2216,14 @@ function events_page_responses($event, $childrens_ids=[]) $('.params_rows').remove(); $('#responses_table') - .append('".__('Description')."'+description+''); + .append('".__('Description')."'+description+''); if (params.length == 1 && params[0] == '') { return; } $('#responses_table') - .append('".__('Parameters')."'); + .append('".__('Parameters')."'); for (i = 0; i < params.length; i++) { add_row_param('responses_table',params[i]); @@ -2291,7 +2258,7 @@ function events_get_response_target( global $config; // If server_id > 0, it's a metaconsole query. - $meta = $server_id > 0; + $meta = $server_id > 0 || is_metaconsole(); $event_table = events_get_events_table($meta, $history); $event = db_get_row($event_table, 'id_evento', $event_id); @@ -2521,9 +2488,7 @@ function events_page_custom_fields($event) $table->width = '100%'; $table->data = []; $table->head = []; - $table->style[0] = 'width:35%; font-weight: bold; text-align: left; height: 23px;'; - $table->style[1] = 'text-align: left; height: 23px;'; - $table->class = 'alternate rounded_cells'; + $table->class = 'table_modal_alternate'; $all_customs_fields = (bool) check_acl( $config['id_user'], @@ -2671,11 +2636,9 @@ function events_page_details($event, $server='') $table_details->width = '100%'; $table_details->data = []; $table_details->head = []; - $table_details->cellspacing = 2; - $table_details->cellpadding = 2; - $table_details->style[0] = 'width:35%; font-weight: bold; text-align: left; height: 23px;'; - $table_details->style[1] = 'text-align: left; height: 23px;'; - $table_details->class = 'alternate rounded_cells'; + $table_details->cellspacing = 0; + $table_details->cellpadding = 0; + $table_details->class = 'table_modal_alternate'; /* * Useless switch. @@ -2919,9 +2882,10 @@ function events_page_details($event, $server='') true, [ 'class' => 'image_status', - 'width' => 12, - 'height' => 12, + 'width' => 61, + 'height' => 28, 'title' => $alert_priority, + 'style' => 'vertical-align:text-bottom', ] ); $data[1] .= ' '.$alert_priority; @@ -2985,9 +2949,7 @@ function events_page_custom_data($event) $table->width = '100%'; $table->data = []; $table->head = []; - $table->style[0] = 'width:35%; font-weight: bold; text-align: left;'; - $table->style[1] = 'text-align: left;'; - $table->class = 'alternate rounded_cells'; + $table->class = 'table_modal_alternate'; $json_custom_data = base64_decode($event['custom_data']); $custom_data = json_decode($json_custom_data); @@ -3137,14 +3099,12 @@ function events_page_general($event) // General. $table_general = new stdClass; - $table_general->cellspacing = 2; - $table_general->cellpadding = 2; + $table_general->cellspacing = 0; + $table_general->cellpadding = 0; $table_general->width = '100%'; $table_general->data = []; $table_general->head = []; - $table_general->style[0] = 'width:35%; font-weight: bold; text-align: left; height: 23px;'; - $table_general->style[1] = 'text-align: left; height: 23px;'; - $table_general->class = 'alternate rounded_cells'; + $table_general->class = 'table_modal_alternate'; $data = []; $data[0] = __('Event ID'); @@ -3167,8 +3127,7 @@ function events_page_general($event) $table_general->data[] = $data; - $event['owner_user'] = $event['id_usuario']; - + // $event['owner_user'] = $event['id_usuario']; $data = []; $data[0] = __('Owner'); if (empty($event['owner_user'])) { @@ -3186,10 +3145,12 @@ function events_page_general($event) $data = []; $data[0] = __('Type'); - $data[1] = events_print_type_img( + $data[1] = events_print_type_description($event['event_type'], true); + $data[2] = events_print_type_img( $event['event_type'], true - ).' '.events_print_type_description($event['event_type'], true); + ); + $table_general->data[] = $data; $data = []; @@ -3209,18 +3170,17 @@ function events_page_general($event) $data = []; $data[0] = __('Severity'); $event_criticity = get_priority_name($event['criticity']); - - $data[1] = html_print_image( + $data[1] = $event_criticity; + $data[2] = html_print_image( $img_sev, true, [ 'class' => 'image_status', - 'width' => 12, - 'height' => 12, + 'width' => 61, + 'height' => 28, 'title' => $event_criticity, ] ); - $data[1] .= ' '.$event_criticity; $table_general->data[] = $data; // Get Status. @@ -3228,7 +3188,8 @@ function events_page_general($event) $data = []; $data[0] = __('Status'); - $data[1] = html_print_image($event_st['img'], true).' '.$event_st['title']; + $data[1] = $event_st['title']; + $data[2] = html_print_image($event_st['img'], true); $table_general->data[] = $data; // If event is validated, show who and when acknowleded it. @@ -3251,12 +3212,23 @@ function events_page_general($event) $data = []; $data[0] = __('Group'); - $data[1] = ''; + $data[1] = groups_get_name($event['id_grupo']); if (!$config['show_group_name']) { - $data[1] = ui_print_group_icon($event['id_grupo'], true); + $data[2] = ui_print_group_icon($event['id_grupo'], true); + } + + $table_general->data[] = $data; + + $data = []; + $data[0] = __('Contact'); + $data[1] = ''; + $contact = db_get_value('contact', 'tgrupo', 'id_grupo', $event['id_grupo']); + if (empty($contact)) { + $data[1] = ''.__('N/A').''; + } else { + $data[1] = $contact; } - $data[1] .= groups_get_name($event['id_grupo']); $table_general->data[] = $data; $data = []; @@ -3282,6 +3254,16 @@ function events_page_general($event) $table_general->data[] = $data; + $table_data = $table_general->data; + $table_data_total = count($table_data); + + for ($i = 0; $i <= $table_data_total; $i++) { + if (count($table_data[$i]) == 2) { + $table_general->colspan[$i][1] = 2; + $table_general->style[2] = 'text-align:center; width:10%;'; + } + } + $general = '
        '.html_print_table($table_general, true).'
        '; return $general; @@ -3305,9 +3287,7 @@ function events_page_comments($event, $childrens_ids=[]) $table_comments->width = '100%'; $table_comments->data = []; $table_comments->head = []; - $table_comments->style[0] = 'width:35%; vertical-align: top; text-align: left;'; - $table_comments->style[1] = 'text-align: left;'; - $table_comments->class = 'alternate rounded_cells'; + $table_comments->class = 'table_modal_alternate'; $event_comments = $event['user_comment']; $event_comments = str_replace(["\n", ' '], '
        ', $event_comments); @@ -3412,9 +3392,9 @@ function events_page_comments($event, $childrens_ids=[]) $childrens_ids ))) && $config['show_events_in_local'] == false || $config['event_replication'] == false ) { - $comments_form = '
        '.html_print_textarea('comment', 3, 10, '', 'style="min-height: 15px; width: 100%; disabled"', true); + $comments_form = '
        '.html_print_textarea('comment', 3, 10, '', 'style="min-height: 15px; padding:0; width: 100%; disabled"', true); - $comments_form .= '
        '.html_print_button(__('Add comment'), 'comment_button', false, 'event_comment();', 'class="sub next"', true).'

        '; + $comments_form .= '
        '.html_print_button(__('Add comment'), 'comment_button', false, 'event_comment();', 'class="sub next"', true).'

        '; } else { $comments_form = ui_print_message( __('If event replication is ongoing, it won\'t be possible to enter comments here. This option is only to allow local pandora users to see comments, but not to operate with them. The operation, when event replication is enabled, must be done only in the Metaconsole.') diff --git a/pandora_console/include/functions_extensions.php b/pandora_console/include/functions_extensions.php index 8efb4c8f36..66e7ff9c3d 100755 --- a/pandora_console/include/functions_extensions.php +++ b/pandora_console/include/functions_extensions.php @@ -380,7 +380,18 @@ function extensions_load_extensions($process_login) // ~ } // ~ } // ~ else { + try { include_once $path_extension; + } + + // PHP 7 + catch (Throwable $e) { + } + + // PHP 5 + catch (Exception $e) { + } + // ~ } } } diff --git a/pandora_console/include/functions_filemanager.php b/pandora_console/include/functions_filemanager.php index 0cf2991630..b3aa490edf 100644 --- a/pandora_console/include/functions_filemanager.php +++ b/pandora_console/include/functions_filemanager.php @@ -120,18 +120,13 @@ if (!function_exists('mime_content_type')) { global $config; -if (isset($config['homedir_filemanager'])) { - $homedir_filemanager = trim(io_safe_output($config['homedir_filemanager'])); -} else { - $homedir_filemanager = trim($config['homedir']); -} +$homedir_filemanager = trim($config['homedir']); $sec2 = get_parameter('sec2'); if ($sec2 == 'enterprise/godmode/agentes/collections' || $sec2 == 'advanced/collections') { $homedir_filemanager .= '/attachment/collection/'; } - $upload_file_or_zip = (bool) get_parameter('upload_file_or_zip'); if ($upload_file_or_zip) { @@ -513,34 +508,81 @@ function filemanager_file_explorer( ?> width = '100%'; $table->id = 'table_filemanager'; if (!defined('METACONSOLE')) { - $table->class = 'databox data'; + $table->class = 'info_table'; $table->title = ''.__('Index of %s', $relative_directory).''; } if (defined('METACONSOLE')) { $table->class = 'databox_tactical'; - $table->title = ''.__('Index of images').''; + $table->title = ''.__('Index of %s', $relative_directory).''; } $table->colspan = []; @@ -582,13 +624,6 @@ function filemanager_file_explorer( $table->head[2] = __('Last modification'); $table->head[3] = __('Size'); $table->head[4] = __('Actions'); - if (!defined('METACONSOLE')) { - $table->headstyle[0] = 'background-color:#82B92E'; - $table->headstyle[1] = 'background-color:#82B92E'; - $table->headstyle[2] = 'background-color:#82B92E'; - $table->headstyle[3] = 'background-color:#82B92E'; - $table->headstyle[4] = 'background-color:#82B92E'; - } $prev_dir = explode('/', $relative_directory); $prev_dir_str = ''; @@ -608,85 +643,6 @@ function filemanager_file_explorer( $table->colspan[0][1] = 5; } - if (is_writable($real_directory)) { - $table->rowstyle[1] = 'display: none;'; - $table->data[1][0] = ''; - $table->data[1][1] = ''; - - $table->data[1][1] .= ''; - - $table->data[1][1] .= ''; - - $table->data[1][1] .= ''; - - $table->colspan[1][1] = 5; - } - foreach ($files as $fileinfo) { $fileinfo['realpath'] = str_replace('\\', '/', $fileinfo['realpath']); $relative_path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $fileinfo['realpath']); @@ -777,6 +733,7 @@ function filemanager_file_explorer( $data[4] .= html_print_input_hidden('delete_file', 1, true); $relative_dir = str_replace($homedir_filemanager, '', str_replace('\\', '/', dirname($fileinfo['realpath']))); + if ($relative_dir[0] == '/') { $relative_dir = substr($relative_dir, 1); } @@ -812,13 +769,44 @@ function filemanager_file_explorer( if (!$readOnly) { if (is_writable($real_directory)) { // The buttons to make actions - if (defined('METACONSOLE')) { - echo "
        "; - } else { - echo "
        "; - } + $tabs_dialog = ''; - echo ""; + echo ''; + + echo ''; + + echo ' '; + + echo "'; } else { - echo "
        "; + echo "
        "; echo "".__('The directory is read-only'); echo '
        '; } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 71049d7804..cde59c52bb 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1,16 +1,32 @@ 0) { - // Propagate the last known data to the end of the interval + // Propagate the last known data to the end of the interval. $nextData = [ 'datos' => $data[(count($data) - 1)]['datos'], 'utimestamp' => $date_array['final_date'], @@ -114,9 +144,8 @@ function grafico_modulo_sparse_data_chart( array_push($data, $nextData); } - // Check available data + // Check available data. if (count($data) < 1) { - // return fs_error_image (); return false; } @@ -126,7 +155,7 @@ function grafico_modulo_sparse_data_chart( $array_percentil = []; foreach ($data as $k => $v) { - // convert array + // Convert array. if ($params['flag_overlapped']) { $array_data['sum'.$series_suffix]['data'][$k] = [ (($v['utimestamp'] + $date_array['period'] ) * 1000), @@ -139,40 +168,43 @@ function grafico_modulo_sparse_data_chart( ]; } - // min + // Min. if ($min_value > $v['datos']) { $min_value = $v['datos']; } - // max + // Max. if ($max_value < $v['datos']) { $max_value = $v['datos']; } - // avg + // Avg. $sum_data += $v['datos']; $count_data++; - // percentil - if (!is_null($params['percentil']) && $params['percentil']) { + // Percentil. + if (!isset($params['percentil']) && $params['percentil']) { $array_percentil[] = $v['datos']; } } - $array_data['sum'.$series_suffix]['min'] = $min_value; - $array_data['sum'.$series_suffix]['max'] = $max_value; - $array_data['sum'.$series_suffix]['avg'] = ($sum_data / $count_data); + $array_data['sum'.$series_suffix]['min'] = $min_value; + $array_data['sum'.$series_suffix]['max'] = $max_value; + $array_data['sum'.$series_suffix]['avg'] = ($sum_data / $count_data); $array_data['sum'.$series_suffix]['agent_module_id'] = $agent_module_id; $array_data['sum'.$series_suffix]['id_module_type'] = $data_module_graph['id_module_type']; - $array_data['sum'.$series_suffix]['agent_name'] = $data_module_graph['agent_name']; - $array_data['sum'.$series_suffix]['module_name'] = $data_module_graph['module_name']; - $array_data['sum'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias']; + $array_data['sum'.$series_suffix]['agent_name'] = $data_module_graph['agent_name']; + $array_data['sum'.$series_suffix]['module_name'] = $data_module_graph['module_name']; + $array_data['sum'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias']; - if (!is_null($params['percentil']) + if (!isset($params['percentil']) && $params['percentil'] && !$params['flag_overlapped'] ) { - $percentil_result = get_percentile($params['percentil'], $array_percentil); + $percentil_result = get_percentile( + $params['percentil'], + $array_percentil + ); $array_data['percentil'.$series_suffix]['data'][0] = [ ($date_array['start_date'] * 1000), $percentil_result, @@ -188,6 +220,17 @@ function grafico_modulo_sparse_data_chart( } +/** + * Prepare data for send to function js paint charts. + * + * @param integer $agent_module_id ID. + * @param array $date_array Date stasrt finish and period. + * @param array $data_module_graph Data module. + * @param array $params Params graphs. + * @param integer $series_suffix Int. + * + * @return array Prepare data to paint js. + */ function grafico_modulo_sparse_data( $agent_module_id, $date_array, @@ -210,7 +253,7 @@ function grafico_modulo_sparse_data( $params['type_mode_graph'] ); } else { - // uncompress data except boolean and string. + // Uncompress data except boolean and string. if ($data_module_graph['id_module_type'] == 23 || $data_module_graph['id_module_type'] == 3 || $data_module_graph['id_module_type'] == 17 @@ -232,6 +275,7 @@ function grafico_modulo_sparse_data( $series_suffix ); } else { + $data_slice = ($date_array['period'] / (250 * $params['zoom']) + 100); $array_data = fullscale_data( $agent_module_id, $date_array, @@ -239,13 +283,13 @@ function grafico_modulo_sparse_data( $params['percentil'], $series_suffix, $params['flag_overlapped'], - $data_slice = ($date_array['period'] / (250 * $params['zoom']) + 100), + $data_slice, $params['type_mode_graph'] ); } } - if ($array_data === false || (!$params['graph_combined'] + if ($array_data === false && (!$params['graph_combined'] && !isset($array_data['sum1']['data'][0][1]) && !$params['baseline']) ) { return false; @@ -253,11 +297,13 @@ function grafico_modulo_sparse_data( $array_data['sum'.$series_suffix]['agent_module_id'] = $agent_module_id; $array_data['sum'.$series_suffix]['id_module_type'] = $data_module_graph['id_module_type']; - $array_data['sum'.$series_suffix]['agent_name'] = $data_module_graph['agent_name']; - $array_data['sum'.$series_suffix]['module_name'] = $data_module_graph['module_name']; - $array_data['sum'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias']; + $array_data['sum'.$series_suffix]['agent_name'] = $data_module_graph['agent_name']; + $array_data['sum'.$series_suffix]['module_name'] = $data_module_graph['module_name']; + $array_data['sum'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias']; + $array_data['sum'.$series_suffix]['unit'] = $data_module_graph['unit']; - // This is for a specific type of report that consists in passing an interval and doing the average sum and avg. + // This is for a specific type of report that consists in passing + // an interval and doing the average sum and avg. if ($params['force_interval'] != '') { $period_time_interval = ($date_array['period'] * 1000); $start_period = ($date_array['start_date'] * 1000); @@ -269,7 +315,9 @@ function grafico_modulo_sparse_data( while ($period_time_interval > 0) { foreach ($array_data['sum1']['data'] as $key => $value) { - if ($value[0] >= $start_period && $value[0] < ($start_period + $params['time_interval'] * 1000)) { + if ($value[0] >= $start_period + && $value[0] < ($start_period + $params['time_interval'] * 1000) + ) { $sum_data = $value[1]; $array_data_only[] = $value[1]; $count_data++; @@ -277,7 +325,9 @@ function grafico_modulo_sparse_data( } else { if ($params['force_interval'] == 'max_only') { $acum_array_data[$i][0] = $start_period; - if (is_array($array_data_only) && count($array_data_only) > 0) { + if (is_array($array_data_only) + && count($array_data_only) > 0 + ) { $acum_array_data[$i][1] = max($array_data_only); $data_last_acum = $array_data_only[(count($array_data_only) - 1)]; } else { @@ -287,7 +337,9 @@ function grafico_modulo_sparse_data( if ($params['force_interval'] == 'min_only') { $acum_array_data[$i][0] = $start_period; - if (is_array($array_data_only) && count($array_data_only) > 0) { + if (is_array($array_data_only) + && count($array_data_only) > 0 + ) { $acum_array_data[$i][1] = min($array_data_only); $data_last_acum = $array_data_only[(count($array_data_only) - 1)]; } else { @@ -297,7 +349,9 @@ function grafico_modulo_sparse_data( if ($params['force_interval'] == 'avg_only') { $acum_array_data[$i][0] = $start_period; - if (is_array($array_data_only) && count($array_data_only) > 0) { + if (is_array($array_data_only) + && count($array_data_only) > 0 + ) { $acum_array_data[$i][1] = ($sum_data / $count_data); } else { $acum_array_data[$i][1] = $data_last_acum; @@ -316,7 +370,7 @@ function grafico_modulo_sparse_data( $period_time_interval = ($period_time_interval - $params['time_interval']); } - // drag the last value to paint the graph correctly + // Drag the last value to paint the graph correctly. $acum_array_data[] = [ 0 => $start_period, 1 => $acum_array_data[($i - 1)][1], @@ -360,7 +414,6 @@ function grafico_modulo_sparse_data( $date_array['final_date'], $data_module_graph['history_db'], 1 - // fix the time ranges to start_date - final_date ); if ($unknown_events !== false) { @@ -495,56 +548,55 @@ function grafico_modulo_sparse_data( } -/* - $params =array( - 'agent_module_id' => $agent_module_id, - 'period' => $period, - 'show_events' => false, - 'width' => $width, - 'height' => $height, - 'title' => '', - 'unit_name' => null, - 'show_alerts' => false, - 'date' => 0, - 'unit' => '', - 'baseline' => 0, - 'return_data' => 0, - 'show_title' => true, - 'only_image' => false, - 'homeurl' => $config['homeurl'], - 'ttl' => 1, - 'adapt_key' => '', - 'compare' => false, - 'show_unknown' => false, - 'menu' => true, - 'backgroundColor' => 'white', - 'percentil' => null, - 'dashboard' => false, - 'vconsole' => false, - 'type_graph' => 'area', - 'fullscale' => false, - 'id_widget_dashboard' => false, - 'force_interval' => '', - 'time_interval' => 300, - 'array_data_create' => 0, - 'show_legend' => true, - 'show_overview' => true, - 'return_img_base_64' => false, - 'image_treshold' => false, - 'graph_combined' => false, - 'zoom' => 1, - 'server_id' => null - ); -*/ +/** + * Functions tu create graphs. + * + * @param array $params Details builds graphs. For example: + * 'agent_module_id' => $agent_module_id, + * 'period' => $period, + * 'show_events' => false, + * 'width' => $width, + * 'height' => $height, + * 'title' => '', + * 'unit_name' => null, + * 'show_alerts' => false, + * 'date' => 0, + * 'unit' => '', + * 'baseline' => 0, + * 'return_data' => 0, + * 'show_title' => true, + * 'only_image' => false, + * 'homeurl' => $config['homeurl'], + * 'ttl' => 1, + * 'adapt_key' => '', + * 'compare' => false, + * 'show_unknown' => false, + * 'menu' => true, + * 'backgroundColor' => 'white', + * 'percentil' => null, + * 'dashboard' => false, + * 'vconsole' => false, + * 'type_graph' => 'area', + * 'fullscale' => false, + * 'id_widget_dashboard' => false, + * 'force_interval' => '', + * 'time_interval' => 300, + * 'array_data_create' => 0, + * 'show_legend' => true, + * 'show_overview' => true, + * 'return_img_base_64' => false, + * 'image_treshold' => false, + * 'graph_combined' => false, + * 'zoom' => 1, + * 'server_id' => null, + * 'stacked' => 0. + * + * @return string html Content graphs. + */ function grafico_modulo_sparse($params) { global $config; - /* - XXXXXXXXXXXX Documnetar - *Set all variable - */ - if (!isset($params) || !is_array($params)) { return false; } @@ -692,11 +744,10 @@ function grafico_modulo_sparse($params) } if (!isset($params['zoom'])) { - $params['zoom'] = $config['zoom_graph'] ? $config['zoom_graph'] : 1; + $params['zoom'] = ($config['zoom_graph']) ? $config['zoom_graph'] : 1; } if (!isset($params['type_mode_graph'])) { - // $config['type_mode_graph'] $params['type_mode_graph'] = $config['type_mode_graph']; } @@ -710,10 +761,15 @@ function grafico_modulo_sparse($params) $agent_module_id = $params['agent_module_id']; } - // XXXX Configurable - $params['grid_color'] = '#C1C1C1'; + if (!isset($params['stacked'])) { + $params['stacked'] = 0; + } + + // TODO: Configurable. + $params['grid_color'] = '#C1C1C1'; $params['legend_color'] = '#636363'; - $params['font'] = $config['fontpath']; + + $params['font'] = $config['fontpath']; $params['font_size'] = $config['font_size']; $params['short_data'] = $config['short_module_graph_data']; @@ -724,8 +780,8 @@ function grafico_modulo_sparse($params) global $graphic_type; global $array_events_alerts; - $array_data = []; - $legend = []; + $array_data = []; + $legend = []; $array_events_alerts = []; $date_array = []; @@ -740,25 +796,36 @@ function grafico_modulo_sparse($params) ); $data_module_graph = []; - $data_module_graph['history_db'] = db_search_in_history_db($date_array['start_date']); - $data_module_graph['agent_name'] = modules_get_agentmodule_agent_name($agent_module_id); - $data_module_graph['agent_alias'] = modules_get_agentmodule_agent_alias($agent_module_id); - $data_module_graph['agent_id'] = $module_data['id_agente']; - $data_module_graph['module_name'] = $module_data['nombre']; + $data_module_graph['history_db'] = db_search_in_history_db( + $date_array['start_date'] + ); + $data_module_graph['agent_name'] = modules_get_agentmodule_agent_name( + $agent_module_id + ); + $data_module_graph['agent_alias'] = modules_get_agentmodule_agent_alias( + $agent_module_id + ); + $data_module_graph['agent_id'] = $module_data['id_agente']; + $data_module_graph['module_name'] = $module_data['nombre']; $data_module_graph['id_module_type'] = $module_data['id_tipo_modulo']; - $data_module_graph['module_type'] = modules_get_moduletype_name($data_module_graph['id_module_type']); - $data_module_graph['uncompressed'] = is_module_uncompressed($data_module_graph['module_type']); - $data_module_graph['w_min'] = $module_data['min_warning']; - $data_module_graph['w_max'] = $module_data['max_warning']; - $data_module_graph['w_inv'] = $module_data['warning_inverse']; - $data_module_graph['c_min'] = $module_data['min_critical']; - $data_module_graph['c_max'] = $module_data['max_critical']; - $data_module_graph['c_inv'] = $module_data['critical_inverse']; + $data_module_graph['module_type'] = modules_get_moduletype_name( + $data_module_graph['id_module_type'] + ); + $data_module_graph['uncompressed'] = is_module_uncompressed( + $data_module_graph['module_type'] + ); + $data_module_graph['w_min'] = $module_data['min_warning']; + $data_module_graph['w_max'] = $module_data['max_warning']; + $data_module_graph['w_inv'] = $module_data['warning_inverse']; + $data_module_graph['c_min'] = $module_data['min_critical']; + $data_module_graph['c_max'] = $module_data['max_critical']; + $data_module_graph['c_inv'] = $module_data['critical_inverse']; + $data_module_graph['unit'] = $module_data['unit']; } else { $data_module_graph = false; } - // format of the graph + // Format of the graph. if (empty($params['unit'])) { $params['unit'] = $module_data['unit']; if (modules_is_unit_macro($params['unit'])) { @@ -768,7 +835,12 @@ function grafico_modulo_sparse($params) if (!$params['array_data_create']) { if ($params['baseline']) { - $array_data = get_baseline_data($agent_module_id, $date_array, $data_module_graph, $params); + $array_data = get_baseline_data( + $agent_module_id, + $date_array, + $data_module_graph, + $params + ); } else { if ($params['compare'] !== false) { $series_suffix = 2; @@ -794,10 +866,14 @@ function grafico_modulo_sparse($params) switch ($params['compare']) { case 'separated': case 'overlapped': - // Store the chart calculated + // Store the chart calculated. $array_data_prev = $array_data; $legend_prev = $legend; break; + + default: + // Not defined. + break; } } @@ -850,7 +926,7 @@ function grafico_modulo_sparse($params) $data_module_graph['series_suffix'] = $series_suffix; - // Check available data + // Check available data. if ($params['compare'] === 'separated') { if (!empty($array_data)) { $return = area_graph( @@ -924,67 +1000,41 @@ function grafico_modulo_sparse($params) /** - * Produces a combined/user defined graph + * Functions tu create graphs. * - * @param array List of source modules - * @param array List of weighs for each module - * @param int Period (in seconds) - * @param int Width, in pixels - * @param int Height, in pixels - * @param string Title for graph - * @param string Unit name, for render in legend - * @param int Show events in graph (set to 1) - * @param int Show alerts in graph (set to 1) - * @param int Pure mode (without titles) (set to 1) - * @param int Date to start of getting info. - * @param mixed If is a projection graph this parameter will be module data with prediction data (the projection) - * or false in other case. - * @param array List of names for the items. Should have the same size as the module list. - * @param array List of units for the items. Should have the same size as the module list. - * @param bool Show the last value of the item on the list. - * @param bool Show the max value of the item on the list. - * @param bool Show the min value of the item on the list. - * @param bool Show the average value of the item on the list. + * @param array $module_list Array modules. + * @param array $params Details builds graphs. For example: + * 'period' => $period, + * 'show_events' => false, + * 'width' => $width, + * 'height' => $height, + * 'title' => '', + * 'unit_name' => null, + * 'show_alerts' => false, + * 'date' => 0, + * 'unit' => '', + * 'only_image' => false, + * 'homeurl' => '', + * 'ttl' => 1, + * 'percentil' => null, + * 'dashboard' => false, + * 'vconsole' => false, + * 'fullscale' => false, + * 'id_widget_dashboard' => false. + * @param array $params_combined Details builds graphs. For example: + * 'weight_list' => array(), + * 'stacked' => 0, + * 'projection' => false, + * 'labels' => array(), + * 'from_interface' => false, + * 'summatory' => 0, + * 'average' => 0, + * 'modules_series' => 0, + * 'id_graph' => 0, + * 'return' => 1. * - * @return Mixed + * @return string html Content graphs. */ - - -/* - $params =array( - 'period' => $period, - 'show_events' => false, - 'width' => $width, - 'height' => $height, - 'title' => '', - 'unit_name' => null, - 'show_alerts' => false, - 'date' => 0, - 'unit' => '', - 'only_image' => false, - 'homeurl' => '', - 'ttl' => 1, - 'percentil' => null, - 'dashboard' => false, - 'vconsole' => false, - 'fullscale' => false, - 'id_widget_dashboard' => false, - ); - - $params_combined = array( - 'weight_list' => array(), - 'stacked' => 0, - 'projection' => false, - 'labels' => array(), - 'from_interface' => false, - 'summatory' => 0, - 'average' => 0, - 'modules_series' => 0, - 'id_graph' => 0, - 'return' => 1 - ); -*/ - function graphic_combined_module( $module_list, $params, @@ -1164,18 +1214,24 @@ function graphic_combined_module( $params_combined['graph_combined'] = true; if ($params['only_image']) { - return generator_chart_to_pdf('combined', $params, $params_combined, $module_list); + return generator_chart_to_pdf( + 'combined', + $params, + $params_combined, + $module_list + ); } if (!isset($params['zoom'])) { $params['zoom'] = 1; } - // XXXX Configurable + // TODO: Configurable. $params['grid_color'] = '#C1C1C1'; $params['legend_color'] = '#636363'; - $params['font'] = $config['fontpath']; - $params['font_size'] = $config['font_size']; + + $params['font'] = $config['fontpath']; + $params['font_size'] = $config['font_size']; $params['short_data'] = $config['short_module_graph_data']; @@ -1220,11 +1276,13 @@ function graphic_combined_module( foreach ($sources as $source) { array_push($modules, $source['id_agent_module']); array_push($weights, $source['weight']); - if ($source['label'] != '') { - $item['type'] = 'custom_graph'; - $item['id_agent'] = agents_get_module_id($source['id_agent_module']); + if ($source['label'] != '' || $params_combined['labels']) { + $item['type'] = 'custom_graph'; + $item['id_agent'] = agents_get_module_id( + $source['id_agent_module'] + ); $item['id_agent_module'] = $source['id_agent_module']; - $labels[$source['id_agent_module']] = reporting_label_macro($item, $source['label']); + $labels[$source['id_agent_module']] = ($source['label'] != '') ? reporting_label_macro($item, $source['label']) : reporting_label_macro($item, $params_combined['labels']); } } } @@ -1274,13 +1332,13 @@ function graphic_combined_module( } } - $width = $params['width']; - $height = $params['height']; - $homeurl = $params['homeurl']; - $ttl = $params['ttl']; + $width = $params['width']; + $height = $params['height']; + $homeurl = $params['homeurl']; + $ttl = $params['ttl']; $background_color = $params['backgroundColor']; - $datelimit = $date_array['start_date']; - $fixed_font_size = $config['font_size']; + $datelimit = $date_array['start_date']; + $fixed_font_size = $config['font_size']; if ($config['fixed_graph'] == false) { $water_mark = [ @@ -1337,23 +1395,34 @@ function graphic_combined_module( ); $data_module_graph = []; - $data_module_graph['history_db'] = db_search_in_history_db($date_array['start_date']); - $data_module_graph['agent_name'] = modules_get_agentmodule_agent_name($agent_module_id); - $data_module_graph['agent_alias'] = modules_get_agentmodule_agent_alias($agent_module_id); - $data_module_graph['agent_id'] = $module_data['id_agente']; - $data_module_graph['module_name'] = $module_data['nombre']; + $data_module_graph['history_db'] = db_search_in_history_db( + $date_array['start_date'] + ); + $data_module_graph['agent_name'] = modules_get_agentmodule_agent_name( + $agent_module_id + ); + $data_module_graph['agent_alias'] = modules_get_agentmodule_agent_alias( + $agent_module_id + ); + $data_module_graph['agent_id'] = $module_data['id_agente']; + $data_module_graph['module_name'] = $module_data['nombre']; $data_module_graph['id_module_type'] = $module_data['id_tipo_modulo']; - $data_module_graph['module_type'] = modules_get_moduletype_name($data_module_graph['id_module_type']); - $data_module_graph['uncompressed'] = is_module_uncompressed($data_module_graph['module_type']); - $data_module_graph['w_min'] = $module_data['min_warning']; - $data_module_graph['w_max'] = $module_data['max_warning']; - $data_module_graph['w_inv'] = $module_data['warning_inverse']; - $data_module_graph['c_min'] = $module_data['min_critical']; - $data_module_graph['c_max'] = $module_data['max_critical']; - $data_module_graph['c_inv'] = $module_data['critical_inverse']; - $data_module_graph['module_id'] = $agent_module_id; + $data_module_graph['module_type'] = modules_get_moduletype_name( + $data_module_graph['id_module_type'] + ); + $data_module_graph['uncompressed'] = is_module_uncompressed( + $data_module_graph['module_type'] + ); + $data_module_graph['w_min'] = $module_data['min_warning']; + $data_module_graph['w_max'] = $module_data['max_warning']; + $data_module_graph['w_inv'] = $module_data['warning_inverse']; + $data_module_graph['c_min'] = $module_data['min_critical']; + $data_module_graph['c_max'] = $module_data['max_critical']; + $data_module_graph['c_inv'] = $module_data['critical_inverse']; + $data_module_graph['module_id'] = $agent_module_id; + $data_module_graph['unit'] = $module_data['unit']; - // stract data + // Stract data. $array_data_module = grafico_modulo_sparse_data( $agent_module_id, $date_array, @@ -1364,12 +1433,14 @@ function graphic_combined_module( $series_suffix = $i; - // convert to array graph and weight + // Convert to array graph and weight. foreach ($array_data_module as $key => $value) { $array_data[$key] = $value; - if ($params_combined['weight_list'][$i] > 1) { + if ($params_combined['weight_list'][$i] != 1) { foreach ($value['data'] as $k => $v) { - $array_data[$key]['data'][$k][1] = ($v[1] * $params_combined['weight_list'][$i]); + if ($v[1] != false) { + $array_data[$key]['data'][$k][1] = ($v[1] * $params_combined['weight_list'][$i]); + } } } } @@ -1390,10 +1461,11 @@ function graphic_combined_module( // Work around for fixed the agents name with huge size chars. $fixed_font_size = $config['font_size']; - // $array_events_alerts[$series_suffix] = $events; $i++; - if (is_metaconsole() && $params_combined['type_report'] == 'automatic_graph') { + if (is_metaconsole() + && $params_combined['type_report'] == 'automatic_graph' + ) { metaconsole_restore_db(); } } @@ -1408,7 +1480,7 @@ function graphic_combined_module( } if ($params_combined['projection']) { - // If projection doesn't have data then don't draw graph + // If projection doesn't have data then don't draw graph. if ($output_projection != null) { $date_array_projection = max($output_projection); $date_array['final_date'] = ($date_array_projection[0] / 1000); @@ -1416,9 +1488,13 @@ function graphic_combined_module( } } - // summatory and average series - if ($params_combined['stacked'] == CUSTOM_GRAPH_AREA || $params_combined['stacked'] == CUSTOM_GRAPH_LINE) { - if ($params_combined['summatory'] || $params_combined['average']) { + // Summatory and average series. + if ($params_combined['stacked'] == CUSTOM_GRAPH_AREA + || $params_combined['stacked'] == CUSTOM_GRAPH_LINE + ) { + if ($params_combined['summatory'] + || $params_combined['average'] + ) { $array_data = combined_graph_summatory_average( $array_data, $params_combined['average'], @@ -1461,9 +1537,19 @@ function graphic_combined_module( $do_it_critical_inverse = true; foreach ($module_list as $index => $id_module) { - // Get module warning_min and critical_min - $warning_min = db_get_value('min_warning', 'tagente_modulo', 'id_agente_modulo', $id_module); - $critical_min = db_get_value('min_critical', 'tagente_modulo', 'id_agente_modulo', $id_module); + // Get module warning_min and critical_min. + $warning_min = db_get_value( + 'min_warning', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); + $critical_min = db_get_value( + 'min_critical', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); if ($index == 0) { $compare_warning = $warning_min; @@ -1484,8 +1570,18 @@ function graphic_combined_module( if ($do_it_warning_min || $do_it_critical_min) { foreach ($module_list as $index => $id_module) { - $warning_max = db_get_value('max_warning', 'tagente_modulo', 'id_agente_modulo', $id_module); - $critical_max = db_get_value('max_critical', 'tagente_modulo', 'id_agente_modulo', $id_module); + $warning_max = db_get_value( + 'max_warning', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); + $critical_max = db_get_value( + 'max_critical', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); if ($index == 0) { $yellow_up = $warning_max; @@ -1507,8 +1603,18 @@ function graphic_combined_module( if ($do_it_warning_min || $do_it_critical_min) { foreach ($module_list as $index => $id_module) { - $warning_inverse = db_get_value('warning_inverse', 'tagente_modulo', 'id_agente_modulo', $id_module); - $critical_inverse = db_get_value('critical_inverse', 'tagente_modulo', 'id_agente_modulo', $id_module); + $warning_inverse = db_get_value( + 'warning_inverse', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); + $critical_inverse = db_get_value( + 'critical_inverse', + 'tagente_modulo', + 'id_agente_modulo', + $id_module + ); if ($index == 0) { $yellow_inverse = $warning_inverse; @@ -1528,18 +1634,24 @@ function graphic_combined_module( } } - if ($do_it_warning_min && $do_it_warning_max && $do_it_warning_inverse) { + if ($do_it_warning_min + && $do_it_warning_max + && $do_it_warning_inverse + ) { $yellow_threshold = $compare_warning; $threshold_data['yellow_threshold'] = $compare_warning; - $threshold_data['yellow_up'] = $yellow_up; - $threshold_data['yellow_inverse'] = (bool) $yellow_inverse; + $threshold_data['yellow_up'] = $yellow_up; + $threshold_data['yellow_inverse'] = (bool) $yellow_inverse; } - if ($do_it_critical_min && $do_it_critical_max && $do_it_critical_inverse) { + if ($do_it_critical_min + && $do_it_critical_max + && $do_it_critical_inverse + ) { $red_threshold = $compare_critical; $threshold_data['red_threshold'] = $compare_critical; - $threshold_data['red_up'] = $red_up; - $threshold_data['red_inverse'] = (bool) $red_inverse; + $threshold_data['red_up'] = $red_up; + $threshold_data['red_inverse'] = (bool) $red_inverse; } $params['threshold_data'] = $threshold_data; @@ -1586,9 +1698,12 @@ function graphic_combined_module( foreach ($module_list as $module_item) { $automatic_custom_graph_meta = false; if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the report + // template in metaconsole. if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id($module_item['server']); + $server = metaconsole_get_connection_by_id( + $module_item['server'] + ); metaconsole_connect($server); $automatic_custom_graph_meta = true; } @@ -1625,16 +1740,27 @@ function graphic_combined_module( $value = false; } - if (!empty($params_combined['labels']) && isset($params_combined['labels'][$module])) { + if (!empty($params_combined['labels']) + && isset($params_combined['labels'][$module]) + ) { $label = io_safe_input($params_combined['labels'][$module]); } else { - $alias = db_get_value('alias', 'tagente', 'id_agente', $temp[$module]['id_agente']); + $alias = db_get_value( + 'alias', + 'tagente', + 'id_agente', + $temp[$module]['id_agente'] + ); $label = $alias.': '.$temp[$module]['nombre']; } $temp[$module]['label'] = $label; $temp[$module]['value'] = $value; - $temp_max = reporting_get_agentmodule_data_max($module, $params['period'], $params['date']); + $temp_max = reporting_get_agentmodule_data_max( + $module, + $params['period'], + $params['date'] + ); if ($temp_max < 0) { $temp_max = 0; } @@ -1645,7 +1771,11 @@ function graphic_combined_module( $temp[$module]['max'] = ($temp_max === false) ? 0 : $temp_max; } - $temp_min = reporting_get_agentmodule_data_min($module, $params['period'], $params['date']); + $temp_min = reporting_get_agentmodule_data_min( + $module, + $params['period'], + $params['date'] + ); if ($temp_min < 0) { $temp_min = 0; } @@ -1653,7 +1783,8 @@ function graphic_combined_module( $temp[$module]['min'] = ($temp_min === false) ? 0 : $temp_min; if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the + // report template in metaconsole. if (is_array($module_list[0])) { metaconsole_restore_db(); } @@ -1678,7 +1809,12 @@ function graphic_combined_module( $color, $module_name_list, $long_index, - ui_get_full_url('images/image_problem_area_small.png', false, false, false), + ui_get_full_url( + 'images/image_problem_area_small.png', + false, + false, + false + ), '', '', $water_mark, @@ -1689,7 +1825,6 @@ function graphic_combined_module( $homeurl, $background_color ); - break; case CUSTOM_GRAPH_GAUGE: @@ -1698,9 +1833,12 @@ function graphic_combined_module( foreach ($module_list as $module_item) { $automatic_custom_graph_meta = false; if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from + // the report template in metaconsole. if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id($module_item['server']); + $server = metaconsole_get_connection_by_id( + $module_item['server'] + ); metaconsole_connect($server); $automatic_custom_graph_meta = true; } @@ -1737,7 +1875,14 @@ function graphic_combined_module( $temp[$module]['label'] = ($params_combined['labels'][$module] != '') ? $params_combined['labels'][$module] : $temp[$module]['nombre']; $temp[$module]['value'] = $value; - $temp[$module]['label'] = ui_print_truncate_text($temp[$module]['label'], 'module_small', false, true, false, '..'); + $temp[$module]['label'] = ui_print_truncate_text( + $temp[$module]['label'], + 'module_small', + false, + true, + false, + '..' + ); if ($temp[$module]['unit'] == '%') { $temp[$module]['min'] = 0; @@ -1745,7 +1890,11 @@ function graphic_combined_module( } else { $min = $temp[$module]['min']; if ($temp[$module]['max'] == 0) { - $max = reporting_get_agentmodule_data_max($module, $params['period'], $params['date']); + $max = reporting_get_agentmodule_data_max( + $module, + $params['period'], + $params['date'] + ); } else { $max = $temp[$module]['max']; } @@ -1757,7 +1906,8 @@ function graphic_combined_module( $temp[$module]['gauge'] = uniqid('gauge_'); if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the report + // template in metaconsole. if (is_array($module_list[0])) { metaconsole_restore_db(); } @@ -1784,13 +1934,17 @@ function graphic_combined_module( $height, $color, $module_name_list, - ui_get_full_url('images/image_problem_area_small.png', false, false, false), + ui_get_full_url( + 'images/image_problem_area_small.png', + false, + false, + false + ), $config['fontpath'], $fixed_font_size, '', $homeurl ); - break; case CUSTOM_GRAPH_HBARS: @@ -1799,9 +1953,12 @@ function graphic_combined_module( foreach ($module_list as $module_item) { $automatic_custom_graph_meta = false; if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the report + // template in metaconsole. if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id($module_item['server']); + $server = metaconsole_get_connection_by_id( + $module_item['server'] + ); metaconsole_connect($server); $automatic_custom_graph_meta = true; } @@ -1830,17 +1987,25 @@ function graphic_combined_module( modules_get_agentmodule_agent_name($module) ); - if (!empty($params_combined['labels']) && isset($params_combined['labels'][$module])) { + if (!empty($params_combined['labels']) + && isset($params_combined['labels'][$module]) + ) { $label = $params_combined['labels'][$module]; } else { - $alias = db_get_value('alias', 'tagente', 'id_agente', $module_data['id_agente']); + $alias = db_get_value( + 'alias', + 'tagente', + 'id_agente', + $module_data['id_agente'] + ); $label = $alias.' - '.$module_data['nombre']; } $temp[$label]['g'] = round($temp_data, 4); if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the report + // template in metaconsole. if (is_array($module_list[0])) { metaconsole_restore_db(); } @@ -1864,7 +2029,12 @@ function graphic_combined_module( $color, $module_name_list, $long_index, - ui_get_full_url('images/image_problem_area_small.png', false, false, false), + ui_get_full_url( + 'images/image_problem_area_small.png', + false, + false, + false + ), '', '', $water_mark, @@ -1886,7 +2056,12 @@ function graphic_combined_module( $color, $module_name_list, $long_index, - ui_get_full_url('images/image_problem_area_small.png', false, false, false), + ui_get_full_url( + 'images/image_problem_area_small.png', + false, + false, + false + ), '', '', $water_mark, @@ -1908,9 +2083,12 @@ function graphic_combined_module( foreach ($module_list as $module_item) { $automatic_custom_graph_meta = false; if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the report + // template in metaconsole. if (is_array($module_list[$i])) { - $server = metaconsole_get_connection_by_id($module_item['server']); + $server = metaconsole_get_connection_by_id( + $module_item['server'] + ); metaconsole_connect($server); $automatic_custom_graph_meta = true; } @@ -1949,10 +2127,19 @@ function graphic_combined_module( $total_modules += $value; - if (!empty($params_combined['labels']) && isset($params_combined['labels'][$module])) { - $label = io_safe_output($params_combined['labels'][$module]); + if (!empty($params_combined['labels']) + && isset($params_combined['labels'][$module]) + ) { + $label = io_safe_output( + $params_combined['labels'][$module] + ); } else { - $alias = db_get_value('alias', 'tagente', 'id_agente', $data_module['id_agente']); + $alias = db_get_value( + 'alias', + 'tagente', + 'id_agente', + $data_module['id_agente'] + ); $label = io_safe_output($alias.': '.$data_module['nombre']); } @@ -1961,7 +2148,8 @@ function graphic_combined_module( 'unit' => $data_module['unit'], ]; if ($config['metaconsole']) { - // Automatic custom graph from the report template in metaconsole + // Automatic custom graph from the report + // template in metaconsole. if (is_array($module_list[0])) { metaconsole_restore_db(); } @@ -1994,7 +2182,6 @@ function graphic_combined_module( false, $background_color ); - break; } @@ -2006,8 +2193,24 @@ function graphic_combined_module( } -function combined_graph_summatory_average($array_data, $average=false, $summatory=false, $modules_series=false, $baseline=false) -{ +/** + * Function for convert data summatory. + * + * @param array $array_data Data array. + * @param boolean $average Average. + * @param boolean $summatory Summatory. + * @param boolean $modules_series Series module. + * @param boolean $baseline Baseline data. + * + * @return array Data. + */ +function combined_graph_summatory_average( + $array_data, + $average=false, + $summatory=false, + $modules_series=false, + $baseline=false +) { if (isset($array_data) && is_array($array_data)) { foreach ($array_data as $key => $value) { if (strpos($key, 'sum') !== false) { @@ -2025,10 +2228,13 @@ function combined_graph_summatory_average($array_data, $average=false, $summator $data_array_pop = []; $count = 0; - while (count($data_array_reverse['sum0']) > 0) { + $count_data_array_reverse = count($data_array_reverse['sum0']); + while ($count_data_array_reverse > 0) { foreach ($data_array_reverse as $key_reverse => $value_reverse) { if (is_array($value_reverse) && count($value_reverse) > 0) { - $data_array_pop[$key_reverse] = array_pop($data_array_reverse[$key_reverse]); + $data_array_pop[$key_reverse] = array_pop( + $data_array_reverse[$key_reverse] + ); } } @@ -2082,12 +2288,18 @@ function combined_graph_summatory_average($array_data, $average=false, $summator $count++; } - if ($summatory && isset($array_sum_reverse) && is_array($array_sum_reverse) && count($array_sum_reverse) > 0) { + if ($summatory && isset($array_sum_reverse) + && is_array($array_sum_reverse) + && count($array_sum_reverse) > 0 + ) { $array_data['summatory']['data'] = $array_sum_reverse; $array_data['summatory']['color'] = 'purple'; } - if ($average && isset($array_avg_reverse) && is_array($array_avg_reverse) && count($array_avg_reverse) > 0) { + if ($average && isset($array_avg_reverse) + && is_array($array_avg_reverse) + && count($array_avg_reverse) > 0 + ) { if ($baseline) { $array_data['baseline']['data'] = $array_avg_reverse; $array_data['baseline']['color'] = 'green'; @@ -2108,19 +2320,28 @@ function combined_graph_summatory_average($array_data, $average=false, $summator /** * Print a graph with access data of agents * - * @param integer id_agent Agent ID - * @param integer width pie graph width - * @param integer height pie graph height - * @param integer period time period - * @param bool return or echo the result flag + * @param integer $id_agent Agent ID. + * @param integer $width Pie graph width. + * @param integer $height Pie graph height. + * @param integer $period Time period. + * @param boolean $return Return. + * @param boolean $tree View tree. + * + * @return string Return or echo the result flag. */ -function graphic_agentaccess($id_agent, $width, $height, $period=0, $return=false, $tree=false) -{ +function graphic_agentaccess( + $id_agent, + $width, + $height, + $period=0, + $return=false, + $tree=false +) { global $config; global $graphic_type; - $date = get_system_time(); - $datelimit = ($date - $period); + $date = get_system_time(); + $datelimit = ($date - $period); $data_array = []; $data = db_get_all_rows_sql( @@ -2150,7 +2371,12 @@ function graphic_agentaccess($id_agent, $width, $height, $period=0, $return=fals if ($config['fixed_graph'] == false) { $water_mark = [ 'file' => $config['homedir'].'/images/logo_vertical_water.png', - 'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false), + 'url' => ui_get_full_url( + 'images/logo_vertical_water.png', + false, + false, + false + ), ]; } @@ -2253,7 +2479,7 @@ function truncate_negatives(&$element) * @param bool return or echo flag * @param bool show_not_init flag */ -function graph_agent_status($id_agent=false, $width=300, $height=200, $return=false, $show_not_init=false, $data_agents=false) +function graph_agent_status($id_agent=false, $width=300, $height=200, $return=false, $show_not_init=false, $data_agents=false, $donut_narrow_graph=false) { global $config; @@ -2319,25 +2545,37 @@ function graph_agent_status($id_agent=false, $width=300, $height=200, $return=fa $data = []; } - $out = pie_graph( - $data, - $width, - $height, - __('other'), - ui_get_full_url(false, false, false, false), - '', - $config['fontpath'], - $config['font_size'], - 1, - 'hidden', - $colors, - 0 - ); - - if ($return) { + if ($donut_narrow_graph == true) { + $data_total = array_sum($data); + $out = print_donut_narrow_graph( + $colors, + $width, + $height, + $data, + $data_total + ); return $out; } else { - echo $out; + $out = pie_graph( + $data, + $width, + $height, + __('other'), + ui_get_full_url(false, false, false, false), + '', + $config['fontpath'], + $config['font_size'], + 1, + 'hidden', + $colors, + 0 + ); + + if ($return) { + return $out; + } else { + echo $out; + } } } @@ -3694,7 +3932,14 @@ function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $per } -// Prints an error image +/** + * Function for retun image no data. + * + * @param integer $width Width. + * @param integer $height Height. + * + * @return string Image. + */ function fs_error_image($width=300, $height=110) { global $config; @@ -3702,15 +3947,29 @@ function fs_error_image($width=300, $height=110) } +/** + * Function for uncompressed data module for cherts. + * + * @param integer $agent_module_id Id modulo. + * @param array $date_array Date start, finish, period. + * @param integer $show_unknown Show Unknown. + * @param integer $show_percentil Show Percentil. + * @param integer $series_suffix Series. + * @param boolean $compare Type compare. + * @param boolean $data_slice Size slice. + * @param string $type_mode_graph Type. + * + * @return array Return array data uncompresess. + */ function fullscale_data( $agent_module_id, $date_array, $show_unknown=0, $show_percentil=0, - $series_suffix, + $series_suffix=0, $compare=false, $data_slice=false, - $type_mode_graph + $type_mode_graph='' ) { global $config; $data_uncompress = db_uncompress_module_data( @@ -3722,218 +3981,234 @@ function fullscale_data( $data = []; $previous_data = 0; - // normal + // Normal. $min_value_total = PHP_INT_MAX; - $max_value_total = -PHP_INT_MAX; - // max + $max_value_total = (-PHP_INT_MAX); + // Max. $max_value_min = PHP_INT_MAX; - $max_value_max = -PHP_INT_MAX; - // min + $max_value_max = (-PHP_INT_MAX); + // Min. $min_value_min = PHP_INT_MAX; - $min_value_max = -PHP_INT_MAX; - // avg + $min_value_max = (-PHP_INT_MAX); + // Avg. $avg_value_min = PHP_INT_MAX; - $avg_value_max = -PHP_INT_MAX; + $avg_value_max = (-PHP_INT_MAX); $flag_unknown = 0; $array_percentil = []; if ($data_slice) { - foreach ($data_uncompress as $k) { - $sum_data = 0; - $count_data = 0; - $min_value = PHP_INT_MAX; - $max_value = -PHP_INT_MAX; - $flag_virtual_data = 0; - foreach ($k['data'] as $v) { - if (isset($v['type']) && $v['type'] == 1) { - // skip unnecesary virtual data - continue; - $flag_virtual_data = 1; - } + if (isset($data_uncompress) === true + && is_array($data_uncompress) === true + ) { + foreach ($data_uncompress as $k) { + $sum_data = 0; + $count_data = 0; + $min_value = PHP_INT_MAX; + $max_value = (-PHP_INT_MAX); + $flag_virtual_data = 0; + foreach ($k['data'] as $v) { + if (isset($v['type']) && $v['type'] == 1) { + // Skip unnecesary virtual data. + continue; + $flag_virtual_data = 1; + } - if ($compare) { - // * 1000 need js utimestam mlsecond - $real_date = (($v['utimestamp'] + $date_array['period']) * 1000); - } else { - $real_date = ($v['utimestamp'] * 1000); - } + if ($compare) { + // Data * 1000 need js utimestam mlsecond. + $real_date = (($v['utimestamp'] + $date_array['period']) * 1000); + } else { + $real_date = ($v['utimestamp'] * 1000); + } - if ($v['datos'] === null) { - // Unknown - if ($show_unknown) { - if (!$compare) { - if ($flag_unknown) { - $data['unknown'.$series_suffix]['data'][] = [ - $real_date, - 1, - ]; - } else { - $data['unknown'.$series_suffix]['data'][] = [ - ($real_date - 1), - 0, - ]; - $data['unknown'.$series_suffix]['data'][] = [ - $real_date, - 1, - ]; - $flag_unknown = 1; + if ($v['datos'] === null) { + // Unknown. + if ($show_unknown) { + if (!$compare) { + if ($flag_unknown) { + $data['unknown'.$series_suffix]['data'][] = [ + $real_date, + 1, + ]; + } else { + $data['unknown'.$series_suffix]['data'][] = [ + ($real_date - 1), + 0, + ]; + $data['unknown'.$series_suffix]['data'][] = [ + $real_date, + 1, + ]; + $flag_unknown = 1; + } + } + } + + $v['datos'] = $previous_data; + } else { + // Normal. + $previous_data = $v['datos']; + if ($show_unknown) { + if (!$compare) { + if ($flag_unknown) { + $data['unknown'.$series_suffix]['data'][] = [ + $real_date, + 0, + ]; + $flag_unknown = 0; + } } } } - $v['datos'] = $previous_data; - } else { - // normal - $previous_data = $v['datos']; - if ($show_unknown) { - if (!$compare) { - if ($flag_unknown) { - $data['unknown'.$series_suffix]['data'][] = [ - $real_date, - 0, - ]; - $flag_unknown = 0; - } + if (isset($v['datos']) && $v['datos']) { + // Max. + if ($v['datos'] >= $max_value) { + $max_value = $v['datos']; + } + + // Min. + if ($v['datos'] <= $min_value) { + $min_value = $v['datos']; + } + + // Avg sum. + $sum_data += $v['datos']; + } + + // Avg count. + $count_data++; + + if ($show_percentil && !$compare) { + $array_percentil[] = $v['datos']; + } + + $last_data = $v['datos']; + } + + if (!$flag_virtual_data) { + if ($compare) { + // Data * 1000 need js utimestam mlsecond. + $real_date = (($k['data'][0]['utimestamp'] + $date_array['period']) * 1000); + } else { + $real_date = ($k['data'][0]['utimestamp'] * 1000); + } + + $data['sum'.$series_suffix]['data'][] = [ + $real_date, + ($sum_data / $count_data), + ]; + if ($type_mode_graph && !$params['baseline']) { + if ($min_value != PHP_INT_MAX) { + $data['min'.$series_suffix]['data'][] = [ + $real_date, + $min_value, + ]; + } + + if ($max_value != (-PHP_INT_MAX)) { + $data['max'.$series_suffix]['data'][] = [ + $real_date, + $max_value, + ]; + } + } else { + if ($min_value != PHP_INT_MAX) { + $data['sum'.$series_suffix]['slice_data'][$real_date]['min'] = $min_value; + } + + $data['sum'.$series_suffix]['slice_data'][$real_date]['avg'] = ($sum_data / $count_data); + + if ($max_value != (-PHP_INT_MAX)) { + $data['sum'.$series_suffix]['slice_data'][$real_date]['max'] = $max_value; } } - } - if (isset($v['datos']) && $v['datos']) { - // max - if ($v['datos'] >= $max_value) { - $max_value = $v['datos']; + // Max total. + if ($max_value >= $max_value_total + && $max_value != (-PHP_INT_MAX) + ) { + $max_value_total = $max_value; } - // min - if ($v['datos'] <= $min_value) { - $min_value = $v['datos']; + // Min total. + if ($min_value <= $min_value_total + && $min_value != PHP_INT_MAX + ) { + $min_value_total = $min_value; } - // avg sum - $sum_data += $v['datos']; - } + // Avg sum total. + $sum_data_total += ($sum_data / $count_data); - // avg count - $count_data++; + // Avg count total. + $count_data_total++; - if ($show_percentil && !$compare) { - $array_percentil[] = $v['datos']; - } + if ($type_mode_graph && !$params['baseline']) { + // MIN. + // max min. + if ($min_value >= $min_value_max + && $min_value != PHP_INT_MAX + ) { + $min_value_max = $min_value; + } - $last_data = $v['datos']; - } + // Min min. + if ($min_value <= $min_value_min + && $min_value != PHP_INT_MAX + ) { + $min_value_min = $min_value; + } - if (!$flag_virtual_data) { - if ($compare) { - // * 1000 need js utimestam mlsecond - $real_date = (($k['data'][0]['utimestamp'] + $date_array['period']) * 1000); - } else { - $real_date = ($k['data'][0]['utimestamp'] * 1000); - } + // Avg sum min. + if ($min_value != PHP_INT_MAX) { + $sum_data_min += $min_value; + } - $data['sum'.$series_suffix]['data'][] = [ - $real_date, - ($sum_data / $count_data), - ]; - if ($type_mode_graph && !$params['baseline']) { - if ($min_value != PHP_INT_MAX) { - $data['min'.$series_suffix]['data'][] = [ - $real_date, - $min_value, - ]; + // MAX. + // Max max. + if ($max_value >= $max_value_max + && $max_value != (-PHP_INT_MAX) + ) { + $max_value_max = $max_value; + } + + // Min max. + if ($max_value <= $max_value_min + && $max_value != (-PHP_INT_MAX) + ) { + $max_value_min = $max_value; + } + + // Avg Sum max. + if ($max_value != (-PHP_INT_MAX)) { + $sum_data_max += $max_value; + } + + // AVG. + // Max max. + if (($sum_data / $count_data) >= $avg_value_max) { + $avg_value_max = ($sum_data / $count_data); + } + + // Min max. + if (($sum_data / $count_data) <= $avg_value_min) { + $avg_value_min = ($sum_data / $count_data); + } + + // Avg sum max. + $sum_data_avg += ($sum_data / $count_data); } - - if ($max_value != -PHP_INT_MAX) { - $data['max'.$series_suffix]['data'][] = [ - $real_date, - $max_value, - ]; - } - } else { - if ($min_value != PHP_INT_MAX) { - $data['sum'.$series_suffix]['slice_data'][$real_date]['min'] = $min_value; - } - - $data['sum'.$series_suffix]['slice_data'][$real_date]['avg'] = ($sum_data / $count_data); - - if ($max_value != -PHP_INT_MAX) { - $data['sum'.$series_suffix]['slice_data'][$real_date]['max'] = $max_value; - } - } - - // max_total - if ($max_value >= $max_value_total && $max_value != -PHP_INT_MAX) { - $max_value_total = $max_value; - } - - // min_total - if ($min_value <= $min_value_total && $min_value != PHP_INT_MAX) { - $min_value_total = $min_value; - } - - // avg sum_total - $sum_data_total += ($sum_data / $count_data); - - // avg count_total - $count_data_total++; - - if ($type_mode_graph && !$params['baseline']) { - /* - MIN*/ - // max_min - if ($min_value >= $min_value_max && $min_value != PHP_INT_MAX) { - $min_value_max = $min_value; - } - - // min_min - if ($min_value <= $min_value_min && $min_value != PHP_INT_MAX) { - $min_value_min = $min_value; - } - - // avg sum_min - if ($min_value != PHP_INT_MAX) { - $sum_data_min += $min_value; - } - - /* - MAX*/ - // max_max - if ($max_value >= $max_value_max && $max_value != -PHP_INT_MAX) { - $max_value_max = $max_value; - } - - // min_max - if ($max_value <= $max_value_min && $max_value != -PHP_INT_MAX) { - $max_value_min = $max_value; - } - - // avg sum_max - if ($max_value != -PHP_INT_MAX) { - $sum_data_max += $max_value; - } - - /* - AVG*/ - // max_max - if (($sum_data / $count_data) >= $avg_value_max) { - $avg_value_max = ($sum_data / $count_data); - } - - // min_max - if (($sum_data / $count_data) <= $avg_value_min) { - $avg_value_min = ($sum_data / $count_data); - } - - // avg sum_max - $sum_data_avg += ($sum_data / $count_data); } } } $data['sum'.$series_suffix]['min'] = $min_value_total; $data['sum'.$series_suffix]['max'] = $max_value_total; - $data['sum'.$series_suffix]['avg'] = ($sum_data_total / $count_data_total); + $data['sum'.$series_suffix]['avg'] = 0; + if (isset($count_data_total) === true) { + $data['sum'.$series_suffix]['avg'] = ($sum_data_total / $count_data_total); + } if ($type_mode_graph && !$params['baseline']) { $data['min'.$series_suffix]['min'] = $min_value_min; @@ -3956,19 +4231,19 @@ function fullscale_data( foreach ($data_uncompress as $k) { foreach ($k['data'] as $v) { if (isset($v['type']) && $v['type'] == 1) { - // skip unnecesary virtual data + // Skip unnecesary virtual data. continue; } if ($compare) { - // * 1000 need js utimestam mlsecond + // Data * 1000 need js utimestam mlsecond. $real_date = (($v['utimestamp'] + $date_array['period']) * 1000); } else { $real_date = ($v['utimestamp'] * 1000); } if ($v['datos'] === null) { - // Unknown + // Unknown. if ($show_unknown) { if (!$compare) { if ($flag_unknown) { @@ -3995,7 +4270,7 @@ function fullscale_data( $previous_data, ]; } else { - // normal + // Normal. $previous_data = $v['datos']; $data['sum'.$series_suffix]['data'][] = [ $real_date, @@ -4015,21 +4290,21 @@ function fullscale_data( } if (isset($v['datos']) && $v['datos']) { - // max + // Max. if ((float) $v['datos'] >= $max_value_max) { $max_value_max = $v['datos']; } - // min + // Min. if ((float) $v['datos'] <= $min_value_min) { $min_value_min = $v['datos']; } - // avg sum + // Avg sum. $sum_data += $v['datos']; } - // avg count + // Avg count. $count_data++; if ($show_percentil && !$compare) { @@ -4042,7 +4317,7 @@ function fullscale_data( $data['sum'.$series_suffix]['min'] = $min_value_min; $data['sum'.$series_suffix]['max'] = $max_value_max; - $data['sum'.$series_suffix]['avg'] = $count_data == 0 ? 0 : ($sum_data / $count_data); + $data['sum'.$series_suffix]['avg'] = ($count_data == 0) ? 0 : ($sum_data / $count_data); } if ($show_percentil && !$compare) { @@ -4068,7 +4343,7 @@ function fullscale_data( } } - // Add missed last data + // Add missed last data. if ($compare) { $data['sum'.$series_suffix]['data'][] = [ (($date_array['final_date'] + $date_array['period']) * 1000), @@ -4091,7 +4366,11 @@ function fullscale_data( ]; } else { $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['min'] = $min_value; - $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = ($sum_data / $count_data); + $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = 0; + if (isset($count_data) === true) { + $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = ($sum_data / $count_data); + } + $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['max'] = $max_value; } } @@ -4104,7 +4383,7 @@ function fullscale_data( /** * Print an area graph with netflow aggregated */ -function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='', $ttl=1, $only_image=false) +function graph_netflow_aggregate_area($data, $period, $width, $height, $ttl=1, $only_image=false, $date=null) { global $config; global $graphic_type; @@ -4114,7 +4393,7 @@ function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='', return; } - // Calculate source indexes + // Calculate source indexes. foreach ($data['sources'] as $key => $value) { $i = 0; foreach ($data['data'] as $k => $v) { @@ -4133,7 +4412,12 @@ function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='', if ($config['fixed_graph'] == false) { $water_mark = [ 'file' => $config['homedir'].'/images/logo_vertical_water.png', - 'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false), + 'url' => ui_get_full_url( + 'images/logo_vertical_water.png', + false, + false, + false + ), ]; $water_mark = $config['homedir'].'/images/logo_vertical_water.png'; @@ -4150,7 +4434,7 @@ function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='', 'period' => $period, 'width' => '90%', 'height' => 450, - 'unit' => $unit, + 'unit' => 'bytes', 'only_image' => $only_image, 'homeurl' => $homeurl, 'menu' => true, @@ -4159,6 +4443,10 @@ function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='', 'font' => $config['fontpath'], 'font_size' => $config['font_size'], 'array_data_create' => $chart, + 'stacked' => 1, + 'date' => $date, + 'show_export_csv' => false, + 'show_overview' => false, ]; return grafico_modulo_sparse($params); @@ -4280,9 +4568,16 @@ function graph_netflow_aggregate_pie($data, $aggregate, $ttl=1, $only_image=fals /** - * Print a circular graph with the data transmitted between IPs + * Print a circular mesh array. + * + * @param array $data Array with properly data structure. Array with two + * elements required: + * 'elements': Non-associative array with all the relationships. + * 'matrix': Array of arrays with value of the relationship. + * + * @return string HTML data. */ -function graph_netflow_circular_mesh($data, $unit, $radius=700) +function graph_netflow_circular_mesh($data) { global $config; @@ -4292,14 +4587,14 @@ function graph_netflow_circular_mesh($data, $unit, $radius=700) include_once $config['homedir'].'/include/graphs/functions_d3.php'; - return d3_relationship_graph($data['elements'], $data['matrix'], $unit, $radius, true); + return d3_relationship_graph($data['elements'], $data['matrix'], 700, true); } /** * Print a rectangular graph with the traffic of the ports for each IP */ -function graph_netflow_host_traffic($data, $unit, $width=700, $height=700) +function graph_netflow_host_traffic($data, $width=700, $height=700) { global $config; @@ -4928,8 +5223,22 @@ function graph_monitor_wheel($width=550, $height=600, $filter=false) } -function get_baseline_data($agent_module_id, $date_array, $data_module_graph, $params) -{ +/** + * Function that on a date requests 3 times that period and takes an average. + * + * @param integer $agent_module_id ID module. + * @param array $date_array Date array start finish period. + * @param array $data_module_graph Data module. + * @param array $params Params. + * + * @return array Data baseline graph. + */ +function get_baseline_data( + $agent_module_id, + $date_array, + $data_module_graph, + $params +) { $period = $date_array['period']; $date = $date_array['final_date']; $array_data = []; @@ -4968,8 +5277,18 @@ function get_baseline_data($agent_module_id, $date_array, $data_module_graph, $p } $result['avg'] = (($array_data[0]['sum0']['avg'] + $array_data[1]['sum1']['avg'] + $array_data[2]['sum2']['avg'] + $array_data[3]['sum3']['avg']) / 4); - $result['max'] = max($array_data[0]['sum0']['max'], $array_data[1]['sum1']['max'], $array_data[2]['sum2']['max'], $array_data[3]['sum3']['max']); - $result['min'] = min($array_data[0]['sum0']['min'], $array_data[1]['sum1']['min'], $array_data[2]['sum2']['min'], $array_data[3]['sum3']['min']); + $result['max'] = max( + $array_data[0]['sum0']['max'], + $array_data[1]['sum1']['max'], + $array_data[2]['sum2']['max'], + $array_data[3]['sum3']['max'] + ); + $result['min'] = min( + $array_data[0]['sum0']['min'], + $array_data[1]['sum1']['min'], + $array_data[2]['sum2']['min'], + $array_data[3]['sum3']['min'] + ); $result['agent_module_id'] = $array_data[0]['sum0']['agent_module_id']; $result['id_module_type'] = $array_data[0]['sum0']['id_module_type']; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 6d461350e9..010845caf6 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -436,7 +436,9 @@ function html_print_select_groups( $keys_field='id_grupo', $strict_user=false, $delete_groups=false, - $include_groups=false + $include_groups=false, + $size=false, + $simple_multiple_options=false ) { global $config; @@ -481,7 +483,12 @@ function html_print_select_groups( $class, $disabled, $style, - $option_style + $option_style, + $size, + false, + '', + false, + $simple_multiple_options ); if ($return) { @@ -529,7 +536,8 @@ function html_print_select( $size=false, $modal=false, $message='', - $select_all=false + $select_all=false, + $simple_multiple_options=false ) { $output = "\n"; @@ -557,6 +565,14 @@ function html_print_select( } } + if ($simple_multiple_options === true) { + if ($size !== false) { + $attributes .= ' size="'.$size.'"'; + } else { + $attributes .= ' size="10"'; + } + } + if (!empty($class)) { $attributes .= ' class="'.$class.'"'; } @@ -644,7 +660,7 @@ function html_print_select( } if ($optlabel === '') { - $output .= '>'.$value.''; + $output .= '>None'; } else { $output .= '>'.$optlabel.''; } @@ -1060,10 +1076,10 @@ function html_print_extended_select_for_time( 'images/pencil.png', true, [ - 'class' => $uniq_name.'_toggler', + 'class' => $uniq_name.'_toggler '.$class, 'alt' => __('Custom'), 'title' => __('Custom'), - 'style' => 'width: 18px;'.$style_icon, + 'style' => 'width: 18px; margin-bottom: -5px;'.$style_icon, ], false, false, @@ -1098,7 +1114,7 @@ function html_print_extended_select_for_time( 'class' => $uniq_name.'_toggler', 'alt' => __('List'), 'title' => __('List'), - 'style' => 'width: 18px;'.$style_icon, + 'style' => 'width: 18px;margin-bottom: -5px;'.$style_icon, ] ).'
        '; echo '
        '; @@ -1774,7 +1790,7 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ */ function html_print_textarea($name, $rows, $columns, $value='', $attributes='', $return=false, $class='') { - $output = ''; @@ -2392,12 +2408,21 @@ function html_print_checkbox_switch($name, $value, $checked=false, $return=false /** * Prints an image HTML element. * - * @param string $src Image source filename. - * @param boolean $return Whether to return or print - * @param array $options Array with optional HTML options to set. At this moment, the - * following options are supported: alt, style, title, width, height, class, pos_tree. - * @param boolean $return_src Whether to return src field of image ('images/*.*') or complete html img tag ('...'). - * @param boolean $relative Whether to use relative path to image or not (i.e. $relative= true : /pandora/). + * @param string $src Image source filename. + * @param boolean $return Whether to return or print. + * @param array $options Array with optional HTML options to set. + * At this moment, the following options are supported: + * align, border, hspace, ismap, vspace, style, title, height, + * longdesc, usemap, width, id, class, lang, xml:lang, onclick, + * ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, + * onmouseout, onkeypress, onkeydown, onkeyup, pos_tree, alt. + * @param boolean $return_src Whether to return src field of image + * ('images/*.*') or complete html img tag ('...'). + * @param boolean $relative Whether to use relative path to image or not + * (i.e. $relative= true : /pandora/). + * @param boolean $no_in_meta Do not show on metaconsole folder at first. Go + * directly to the node. + * @param boolean $isExternalLink Do not shearch for images in Pandora. * * @return string HTML code if return parameter is true. */ @@ -2412,9 +2437,9 @@ function html_print_image( ) { global $config; - // If metaconsole is in use then don't use skins + // If metaconsole is in use then don't use skins. if (!is_metaconsole()) { - // Checks if user's skin is available + // Checks if user's skin is available. $isFunctionSkins = enterprise_include_once('include/functions_skins.php'); if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { @@ -2426,11 +2451,11 @@ function html_print_image( } } - // If metaconsole is activated and image doesn't exists try to search on normal console + // If metaconsole is activated and image doesn't exists try to search on normal console. if (is_metaconsole()) { if (!$relative) { $working_dir = str_replace('\\', '/', getcwd()); - // Windows compatibility + // Windows compatibility. if ($no_in_meta) { $src = '../../'.$src; } else if (strstr($working_dir, 'enterprise/meta') === false) { @@ -2468,22 +2493,22 @@ function html_print_image( } } - // Only return src field of image + // Only return src field of image. if ($return_src) { if (!$return) { echo io_safe_input($src); - return; + return null; } return io_safe_input($src); } $output = ' '(GMT-11:00) '.__('Midway Island'), - 'US/Samoa' => '(GMT-11:00) '.__('Samoa'), - 'US/Hawaii' => '(GMT-10:00) '.__('Hawaii'), - 'US/Alaska' => '(GMT-09:00) '.__('Alaska'), - 'US/Pacific' => '(GMT-08:00) '.__('Pacific Time (US & Canada)'), - 'America/Tijuana' => '(GMT-08:00) '.__('Tijuana'), - 'US/Arizona' => '(GMT-07:00) '.__('Arizona'), - 'US/Mountain' => '(GMT-07:00) '.__('Mountain Time (US & Canada)'), - 'America/Chihuahua' => '(GMT-07:00) '.__('Chihuahua'), - 'America/Mazatlan' => '(GMT-07:00) '.__('Mazatlan'), - 'America/Mexico_City' => '(GMT-06:00) '.__('Mexico City'), - 'America/Monterrey' => '(GMT-06:00) '.__('Monterrey'), - 'Canada/Saskatchewan' => '(GMT-06:00) '.__('Saskatchewan'), - 'US/Central' => '(GMT-06:00) '.__('Central Time (US & Canada)'), - 'US/Eastern' => '(GMT-05:00) '.__('Eastern Time (US & Canada)'), - 'US/East-Indiana' => '(GMT-05:00) '.__('Indiana (East)'), - 'America/Bogota' => '(GMT-05:00) '.__('Bogota'), - 'America/Lima' => '(GMT-05:00) '.__('Lima'), - 'America/Caracas' => '(GMT-04:30) '.__('Caracas'), - 'Canada/Atlantic' => '(GMT-04:00) '.__('Atlantic Time (Canada)'), - 'America/La_Paz' => '(GMT-04:00) '.__('La Paz'), - 'America/Santiago' => '(GMT-04:00) '.__('Santiago'), - 'Canada/Newfoundland' => '(GMT-03:30) '.__('Newfoundland'), - 'America/Buenos_Aires' => '(GMT-03:00) '.__('Buenos Aires'), - "Greenland'" => '(GMT-03:00) '.__('Greenland'), - 'Atlantic/Stanley' => '(GMT-02:00) '.__('Stanley'), - 'Atlantic/Azores' => '(GMT-01:00) '.__('Azores'), - 'Atlantic/Cape_Verde' => '(GMT-01:00) '.__('Cape Verde Is.'), - 'Africa/Casablanca' => '(GMT+00:00) '.__('Casablanca'), - 'Europe/Dublin' => '(GMT+00:00) '.__('Dublin'), - 'Europe/Lisbon' => '(GMT+00:00) '.__('Lisbon'), - 'Europe/London' => '(GMT+00:00) '.__('London'), - 'Africa/Monrovia' => '(GMT+00:00) '.__('Monrovia'), - 'Europe/Amsterdam' => '(GMT+01:00) '.__('Amsterdam'), - 'Europe/Belgrade' => '(GMT+01:00) '.__('Belgrade'), - 'Europe/Berlin' => '(GMT+01:00) '.__('Berlin'), - 'Europe/Bratislava' => '(GMT+01:00) '.__('Bratislava'), - 'Europe/Brussels' => '(GMT+01:00) '.__('Brussels'), - 'Europe/Budapest' => '(GMT+01:00) '.__('Budapest'), - 'Europe/Copenhagen' => '(GMT+01:00) '.__('Copenhagen'), - 'Europe/Ljubljana' => '(GMT+01:00) '.__('Ljubljana'), - 'Europe/Madrid' => '(GMT+01:00) '.__('Madrid'), - 'Europe/Paris' => '(GMT+01:00) '.__('Paris'), - 'Europe/Prague' => '(GMT+01:00) '.__('Prague'), - 'Europe/Rome' => '(GMT+01:00) '.__('Rome'), - 'Europe/Sarajevo' => '(GMT+01:00) '.__('Sarajevo'), - 'Europe/Skopje' => '(GMT+01:00) '.__('Skopje'), - 'Europe/Stockholm' => '(GMT+01:00) '.__('Stockholm'), - 'Europe/Vienna' => '(GMT+01:00) '.__('Vienna'), - 'Europe/Warsaw' => '(GMT+01:00) '.__('Warsaw'), - 'Europe/Zagreb' => '(GMT+01:00) '.__('Zagreb'), - 'Europe/Athens' => '(GMT+02:00) '.__('Athens'), - 'Europe/Bucharest' => '(GMT+02:00) '.__('Bucharest'), - 'Africa/Cairo' => '(GMT+02:00) '.__('Cairo'), - 'Africa/Harare' => '(GMT+02:00) '.__('Harare'), - 'Europe/Helsinki' => '(GMT+02:00) '.__('Helsinki'), - 'Europe/Istanbul' => '(GMT+02:00) '.__('Istanbul'), - 'Asia/Jerusalem' => '(GMT+02:00) '.__('Jerusalem'), - 'Europe/Kiev' => '(GMT+02:00) '.__('Kyiv'), - 'Europe/Minsk' => '(GMT+02:00) '.__('Minsk'), - 'Europe/Riga' => '(GMT+02:00) '.__('Riga'), - 'Europe/Sofia' => '(GMT+02:00) '.__('Sofia'), - 'Europe/Tallinn' => '(GMT+02:00) '.__('Tallinn'), - 'Europe/Vilnius' => '(GMT+02:00) '.__('Vilnius'), - 'Asia/Baghdad' => '(GMT+03:00) '.__('Baghdad'), - 'Asia/Kuwait' => '(GMT+03:00) '.__('Kuwait'), - 'Africa/Nairobi' => '(GMT+03:00) '.__('Nairobi'), - 'Asia/Riyadh' => '(GMT+03:00) '.__('Riyadh'), - 'Europe/Moscow' => '(GMT+03:00) '.__('Moscow'), - 'Asia/Tehran' => '(GMT+03:30) '.__('Tehran'), - 'Asia/Baku' => '(GMT+04:00) '.__('Baku'), - 'Europe/Volgograd' => '(GMT+04:00) '.__('Volgograd'), - 'Asia/Muscat' => '(GMT+04:00) '.__('Muscat'), - 'Asia/Tbilisi' => '(GMT+04:00) '.__('Tbilisi'), - 'Asia/Yerevan' => '(GMT+04:00) '.__('Yerevan'), - 'Asia/Kabul' => '(GMT+04:30) '.__('Kabul'), - 'Asia/Karachi' => '(GMT+05:00) '.__('Karachi'), - 'Asia/Tashkent' => '(GMT+05:00) '.__('Tashkent'), - 'Asia/Kolkata' => '(GMT+05:30) '.__('Kolkata'), - 'Asia/Kathmandu' => '(GMT+05:45) '.__('Kathmandu'), - 'Asia/Yekaterinburg' => '(GMT+06:00) '.__('Ekaterinburg'), - 'Asia/Almaty' => '(GMT+06:00) '.__('Almaty'), - 'Asia/Dhaka' => '(GMT+06:00) '.__('Dhaka'), - 'Asia/Novosibirsk' => '(GMT+07:00) '.__('Novosibirsk'), - 'Asia/Bangkok' => '(GMT+07:00) '.__('Bangkok'), - 'Asia/Jakarta' => '(GMT+07:00) '.__('Jakarta'), - 'Asia/Krasnoyarsk' => '(GMT+08:00) '.__('Krasnoyarsk'), - 'Asia/Chongqing' => '(GMT+08:00) '.__('Chongqing'), - 'Asia/Hong_Kong' => '(GMT+08:00) '.__('Hong Kong'), - 'Asia/Kuala_Lumpur' => '(GMT+08:00) '.__('Kuala Lumpur'), - 'Australia/Perth' => '(GMT+08:00) '.__('Perth'), - 'Asia/Singapore' => '(GMT+08:00) '.__('Singapore'), - 'Asia/Taipei' => '(GMT+08:00) '.__('Taipei'), - 'Asia/Ulaanbaatar' => '(GMT+08:00) '.__('Ulaan Bataar'), - 'Asia/Urumqi' => '(GMT+08:00) '.__('Urumqi'), - 'Asia/Irkutsk' => '(GMT+09:00) '.__('Irkutsk'), - 'Asia/Seoul' => '(GMT+09:00) '.__('Seoul'), - 'Asia/Tokyo' => '(GMT+09:00) '.__('Tokyo'), - 'Australia/Adelaide' => '(GMT+09:30) '.__('Adelaide'), - 'Australia/Darwin' => '(GMT+09:30) '.__('Darwin'), - 'Asia/Yakutsk' => '(GMT+10:00) '.__('Yakutsk'), - 'Australia/Brisbane' => '(GMT+10:00) '.__('Brisbane'), - 'Australia/Canberra' => '(GMT+10:00) '.__('Canberra'), - 'Pacific/Guam' => '(GMT+10:00) '.__('Guam'), - 'Australia/Hobart' => '(GMT+10:00) '.__('Hobart'), - 'Australia/Melbourne' => '(GMT+10:00) '.__('Melbourne'), - 'Pacific/Port_Moresby' => '(GMT+10:00) '.__('Port Moresby'), - 'Australia/Sydney' => '(GMT+10:00) '.__('Sydney'), - 'Asia/Vladivostok' => '(GMT+11:00) '.__('Vladivostok'), - 'Asia/Magadan' => '(GMT+12:00) '.__('Magadan'), - 'Pacific/Auckland' => '(GMT+12:00) '.__('Auckland'), - 'Pacific/Fiji' => '(GMT+12:00) '.__('Fiji'), - ]; - + $timezones_index = timezone_identifiers_list(); + $timezones = timezone_identifiers_list(); + $timezones = array_combine($timezones_index, $timezones); return html_print_select($timezones, $name, $selected, '', __('None'), '', true, false, false); } @@ -3100,6 +2989,7 @@ function html_print_switch($attributes=[]) 'class', 'name', 'onclick', + 'onchange', ]; foreach ($valid_attrs as $va) { if (!isset($attributes[$va])) { @@ -3109,8 +2999,57 @@ function html_print_switch($attributes=[]) $html_expand .= ' '.$va.'="'.$attributes[$va].'"'; } - return "
      '; - // Invisible UL for adding border-top + // Invisible UL for adding border-top. echo '
    '; } @@ -506,7 +541,7 @@ function menu_add_extras(&$menu) $menu_extra['workspace']['sub']['operation/incidents/incident_detail']['text'] = __('Manage incident'); - // Duplicate extensions as sec=extension to check it from url + // Duplicate extensions as sec=extension to check it from url. foreach ($menu as $k => $m) { if (!isset($m['sub'])) { continue; @@ -550,7 +585,7 @@ function menu_get_sec($with_categories=false) if ($with_categories) { if (!$in_godmode && $k[0] == 'g') { // Hack to dont confuse with gis activated because godmode - // sec starts with g (like gismaps) + // sec starts with g (like gismaps). if ($k != 'gismaps') { $in_godmode = true; } @@ -619,17 +654,17 @@ function menu_get_sec_pages($sec, $menu_hash=false) $sec2_array = []; if (isset($sec)) { - // Get the sec2 of the main section + // Get the sec2 of the main section. $sec2_array[$menu[$sec]['sec2']] = $menu[$sec]['text']; - // Get the sec2 of the subsections + // Get the sec2 of the subsections. foreach ($menu[$sec]['sub'] as $k => $v) { - // Avoid special cases of standalone windows + // Avoid special cases of standalone windows. if (preg_match('/^javascript:/', $k) || preg_match('/\.php/', $k)) { continue; } - // If this value has various parameters, we only get the first + // If this value has various parameters, we only get the first. $k = explode('&', $k); $k = $k[0]; @@ -637,6 +672,7 @@ function menu_get_sec_pages($sec, $menu_hash=false) } } + $sec2_array = array_unique($sec2_array); return $sec2_array; } @@ -663,8 +699,8 @@ function menu_get_sec2_pages($sec, $sec2, $menu_hash=false) $sec3_array = []; - if (isset($menu[$sec]['sub']) and isset($menu[$sec]['sub'][$sec2]['sub2'])) { - // Get the sec2 of the subsections + if (isset($menu[$sec]['sub']) && isset($menu[$sec]['sub'][$sec2]['sub2'])) { + // Get the sec2 of the subsections. foreach ($menu[$sec]['sub'][$sec2]['sub2'] as $k => $v) { $sec3_array[$k] = $v['text']; } @@ -686,7 +722,7 @@ function menu_sec2_in_sec($sec, $sec2) { $sec2_array = menu_get_sec_pages($sec); - // If this value has various parameters, we only get the first + // If this value has various parameters, we only get the first. $sec2 = explode('&', $sec2); $sec2 = $sec2[0]; @@ -702,7 +738,7 @@ function menu_sec3_in_sec2($sec, $sec2, $sec3) { $sec3_array = menu_get_sec2_pages($sec, $sec2, $menu_hash = false); - // If this value has various parameters, we only get the first + // If this value has various parameters, we only get the first. $sec3 = explode('&', $sec3); $sec3 = $sec3[0]; diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 5374fb7b1e..1bc54c9c89 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -442,14 +442,15 @@ function messages_get_count_sent(string $user='') /** * Get message overview in array * - * @param string $order How to order them valid: - * (status (default), subject, timestamp, sender). - * @param string $order_dir Direction of order - * (ASC = Ascending, DESC = Descending). - * @param boolean $incl_read Include read messages in return. - * @param boolean $incl_source_info Include source info. - * @param integer $limit Maximum number of result in the query. - * @param array $other_filter Add a filter on main query. + * @param string $order How to order them valid: + * (status (default), subject, timestamp, sender). + * @param string $order_dir Direction of order + * (ASC = Ascending, DESC = Descending). + * @param boolean $incl_read Include read messages in return. + * @param boolean $incl_source_info Include source info. + * @param integer $limit Maximum number of result in the query. + * @param array $other_filter Add a filter on main query. + * @param string $join_other_filter How to join filter on main query. * * @return integer The number of messages this user has */ @@ -459,7 +460,8 @@ function messages_get_overview( bool $incl_read=true, bool $incl_source_info=false, int $limit=0, - array $other_filter=[] + array $other_filter=[], + string $join_other_filter='AND' ) { global $config; @@ -529,7 +531,11 @@ function messages_get_overview( $config['id_user'], $config['id_user'], $read, - db_format_array_where_clause_sql($other_filter, 'AND', ' AND '), + db_format_array_where_clause_sql( + $other_filter, + $join_other_filter, + ' AND ' + ), $order, ($limit !== 0) ? ' LIMIT '.$limit : '' ); @@ -582,6 +588,56 @@ function messages_get_overview_sent( } +/** + * Get a message interpreted as a conversation. + * + * @param mixed $data Complete message or message id. + * + * @return mixed False if fails. A string array with the conversation. + */ +function messages_get_conversation($data) +{ + if (is_array($data)) { + $message = $data; + } else { + $message = messages_get_message($data); + } + + if (!isset($message) || !is_array($message)) { + return []; + } + + $conversation = []; + $target_str = $message['mensaje']; + + while (preg_match_all( + '/(.*)On(.*)wrote:(.*)/', + $target_str, + $decoded, + PREG_PATTERN_ORDER + ) !== false && empty($target_str) !== true) { + if (empty($decoded[2]) !== true) { + array_push( + $conversation, + [ + 'message' => array_pop($decoded)[0], + 'date' => array_pop($decoded)[0], + ] + ); + } else { + array_push( + $conversation, + ['message' => $target_str] + ); + } + + $target_str = $decoded[1][0]; + } + + return $conversation; +} + + /** * Get the URL of a message. If field in db is null, it returs a link to * messages view. diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index ed19c6d2c1..b9ed8e41d5 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -663,10 +663,11 @@ function modules_create_agent_module( 'estado' => $status, 'known_status' => $status, 'id_agente' => (int) $id_agent, - 'utimestamp' => 0, + 'utimestamp' => (time() - (int) $values['interval']), 'status_changes' => 0, 'last_status' => $status, 'last_known_status' => $status, + 'current_interval' => (int) $values['interval'], ] ); @@ -2293,6 +2294,54 @@ function modules_get_modulegroup_name($modulegroup_id) } +/** + * Returns target color to be used based on the status received. + * + * @param integer $status Source information. + * + * @return string HTML tag for color. + */ +function modules_get_color_status($status) +{ + if (isset($status) === false) { + return COL_UNKNOWN; + } + + switch ($status) { + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_STATUS_NORMAL: + return COL_NORMAL; + + case AGENT_MODULE_STATUS_NOT_INIT: + case AGENT_STATUS_NOT_INIT: + return COL_NOTINIT; + + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_STATUS_CRITICAL: + return COL_CRITICAL; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_STATUS_WARNING: + return COL_WARNING; + + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_STATUS_ALERT_FIRED: + return COL_ALERTFIRED; + + case AGENT_MODULE_STATUS_UNKNOWN: + case AGENT_STATUS_UNKNOWN: + return COL_UNKNOWN; + + default: + // Ignored. + break; + } + + return COL_IGNORED; +} + + /** * Gets a module status an modify the status and title reference variables * @@ -2321,7 +2370,7 @@ function modules_get_status($id_agent_module, $db_status, $data, &$status, &$tit $status = STATUS_MODULE_OK; $title = __('NORMAL'); } else if ($db_status == AGENT_MODULE_STATUS_UNKNOWN) { - $status = STATUS_AGENT_DOWN; + $status = STATUS_MODULE_UNKNOWN; $last_status = modules_get_agentmodule_last_status($id_agent_module); switch ($last_status) { case AGENT_STATUS_NORMAL: diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 84f3c26169..69aa0a1608 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -1,36 +1,60 @@ id_name)) or filters filtered * - * @param mixed Array with filter conditions to retrieve filters or false. + * @param mixed $filter Array with filter conditions to retrieve filters or + * false. * - * @return array List of all filters + * @return array List of all filters. */ function netflow_get_filters($filter=false) { @@ -56,9 +80,10 @@ function netflow_get_filters($filter=false) /** * Selects all netflow reports (array (id_name => id_name)) or filters filtered * - * @param mixed Array with filter conditions to retrieve filters or false. + * @param mixed $filter Array with filter conditions to retrieve filters or + * false. * - * @return array List of all filters + * @return array List of all filters. */ function netflow_get_reports($filter=false) { @@ -81,14 +106,20 @@ function netflow_get_reports($filter=false) } -// permite validar si un filtro pertenece a un grupo permitido para el usuario +/** + * Check if a filter owns to a certain group. + * + * @param integer $id_sg Id group to check. + * + * @return boolean True if user manages that group. + */ function netflow_check_filter_group($id_sg) { global $config; $id_group = db_get_value('id_group', 'tnetflow_filter', 'id_sg', $id_sg); $own_info = get_user_info($config['id_user']); - // Get group list that user has access + // Get group list that user has access. $groups_user = users_get_groups($config['id_user'], 'IW', $own_info['is_admin'], true); $groups_id = []; $has_permission = false; @@ -103,44 +134,12 @@ function netflow_check_filter_group($id_sg) } -/* - Permite validar si un informe pertenece a un grupo permitido para el usuario. - * Si mode = false entonces es modo godmode y solo puede ver el grupo All el admin - * Si es modo operation (mode = true) entonces todos pueden ver el grupo All - */ - -function netflow_check_report_group($id_report, $mode=false) -{ - global $config; - - if (!$mode) { - $own_info = get_user_info($config['id_user']); - $mode = $own_info['is_admin']; - } - - $id_group = db_get_value('id_group', 'tnetflow_report', 'id_report', $id_report); - - // Get group list that user has access - $groups_user = users_get_groups($config['id_user'], 'IW', $mode, true); - $groups_id = []; - $has_permission = false; - - foreach ($groups_user as $key => $groups) { - if ($groups['id_grupo'] == $id_group) { - return true; - } - } - - return false; -} - - /** * Get a filter. * - * @param int filter id to be fetched. - * @param array Extra filter. - * @param array Fields to be fetched. + * @param integer $id_sg Filter id to be fetched. + * @param mixed $filter Extra filter. + * @param mixed $fields Fields to be fetched. * * @return array A netflow filter matching id and filter. */ @@ -156,52 +155,11 @@ function netflow_filter_get_filter($id_sg, $filter=false, $fields=false) } -/** - * Get options. - * - * @param int filter id to be fetched. - * @param array Extra filter. - * @param array Fields to be fetched. - * - * @return array A netflow filter matching id and filter. - */ -function netflow_reports_get_reports($id_report, $filter=false, $fields=false) -{ - if (empty($id_report)) { - return false; - } - - if (! is_array($filter)) { - $filter = []; - } - - $filter['id_report'] = (int) $id_report; - - return db_get_row_filter('tnetflow_report', $filter, $fields); -} - - -function netflow_reports_get_content($id_rc, $filter=false, $fields=false) -{ - if (empty($id_rc)) { - return false; - } - - if (! is_array($filter)) { - $filter = []; - } - - $filter['id_rc'] = (int) $id_rc; - - return db_get_row_filter('tnetflow_report_content', $filter, $fields); -} - - /** * Compare two flows according to the 'data' column. * - * @param array a First flow. - * @param array b Second flow. + * @param array $a First flow. + * @param array $b Second flow. * * @return Result of the comparison. */ @@ -214,7 +172,9 @@ function compare_flows($a, $b) /** * Sort netflow data according to the 'data' column. * - * @param array netflow_data Netflow data array. + * @param array $netflow_data Netflow data array. + * + * @return void (Array passed by reference) */ function sort_netflow_data(&$netflow_data) { @@ -225,22 +185,22 @@ function sort_netflow_data(&$netflow_data) /** * Show a table with netflow statistics. * - * @param array data Statistic data. - * @param string start_date Start date. - * @param string end_date End date. - * @param string aggregate Aggregate field. - * @param string unit Unit to show. + * @param array $data Statistic data. + * @param string $start_date Start date. + * @param string $end_date End date. + * @param string $aggregate Aggregate field. * - * @return The statistics table. + * @return string HTML statistics table. */ -function netflow_stat_table($data, $start_date, $end_date, $aggregate, $unit) +function netflow_stat_table($data, $start_date, $end_date, $aggregate) { global $nfdump_date_format; $start_date = date($nfdump_date_format, $start_date); $end_date = date($nfdump_date_format, $end_date); $values = []; - $table->width = '40%'; + $table = new stdClass(); + $table->width = '100%'; $table->cellspacing = 0; $table->class = 'databox'; $table->data = []; @@ -249,7 +209,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate, $unit) $table->head = []; $table->head[0] = ''.netflow_format_aggregate($aggregate).''; - $table->head[1] = ''.netflow_format_unit($unit).''; + $table->head[1] = ''.__('Value').''; $table->style[0] = 'padding: 6px;'; $table->style[1] = 'padding: 6px;'; @@ -257,14 +217,13 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate, $unit) $agg = $data[$j]['agg']; if (!isset($values[$agg])) { $values[$agg] = $data[$j]['data']; - $table->data[$x][0] = $agg; - $table->data[$x][1] = format_numeric($data[$j]['data']).' '.netflow_format_unit($unit); } else { $values[$agg] += $data[$j]['data']; - $table->data[$x][0] = $agg; - $table->data[$x][1] = format_numeric($data[$j]['data']).' '.netflow_format_unit($unit); } + $table->data[$x][0] = $agg; + $table->data[$x][1] = network_format_bytes($data[$j]['data']); + $j++; $x++; } @@ -276,14 +235,14 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate, $unit) /** * Show a table with netflow data. * - * @param array data Netflow data. - * @param string start_date Start date. - * @param string end_date End date. - * @param string aggregate Aggregate field. + * @param array $data Netflow data. + * @param string $start_date Start date. + * @param string $end_date End date. + * @param string $aggregate Aggregate field. * - * @return The statistics table. + * @return string HTML data table. */ -function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) +function netflow_data_table($data, $start_date, $end_date, $aggregate) { global $nfdump_date_format; @@ -291,7 +250,7 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) $start_date = date($nfdump_date_format, $start_date); $end_date = date($nfdump_date_format, $end_date); - // Set the format + // Set the format. if ($period <= SECONDS_6HOURS) { $time_format = 'H:i:s'; } else if ($period < SECONDS_1DAY) { @@ -305,6 +264,7 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) } $values = []; + $table = new stdClass(); $table->size = ['100%']; $table->class = 'databox'; $table->cellspacing = 0; @@ -332,7 +292,7 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) $table->style[1] = 'padding: 4px;'; } - // No aggregates + // No aggregates. if ($source_count == 0) { $table->head[1] = __('Data'); $table->align[1] = 'right'; @@ -340,21 +300,17 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) foreach ($data as $timestamp => $value) { $table->data[$i][0] = date($time_format, $timestamp); - $table->data[$i][1] = format_numeric($value['data']).' '.netflow_format_unit($unit); + $table->data[$i][1] = network_format_bytes($value['data']); $i++; } - } - // Aggregates - else { + } else { $i = 0; foreach ($data['data'] as $timestamp => $values) { $table->data[$i][0] = date($time_format, $timestamp); for ($j = 0; $j < $source_count; $j++) { - if (isset($values[$source_index[$j]])) { - $table->data[$i][($j + 1)] = format_numeric($values[$source_index[$j]]).' '.netflow_format_unit($unit); - } else { - $table->data[$i][($j + 1)] = (0).' '.netflow_format_unit($unit); - } + $table->data[$i][($j + 1)] = network_format_bytes( + $values[$source_index[$j]] + ); } $i++; @@ -368,18 +324,19 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) /** * Show a table with a traffic summary. * - * @param array data Summary data. + * @param array $data Summary data. * - * @return The statistics table. + * @return string HTML summary table. */ function netflow_summary_table($data) { global $nfdump_date_format; $values = []; - $table->size = ['50%']; + $table = new stdClass(); $table->cellspacing = 0; $table->class = 'databox'; + $table->styleTable = 'width: 100%'; $table->data = []; $table->style[0] = 'font-weight: bold; padding: 6px'; @@ -387,32 +344,32 @@ function netflow_summary_table($data) $row = []; $row[] = __('Total flows'); - $row[] = format_numeric($data['totalflows']); + $row[] = format_for_graph($data['totalflows'], 2); $table->data[] = $row; $row = []; $row[] = __('Total bytes'); - $row[] = format_numeric($data['totalbytes']); + $row[] = network_format_bytes($data['totalbytes']); $table->data[] = $row; $row = []; $row[] = __('Total packets'); - $row[] = format_numeric($data['totalpackets']); + $row[] = format_for_graph($data['totalpackets'], 2); $table->data[] = $row; $row = []; $row[] = __('Average bits per second'); - $row[] = format_numeric($data['avgbps']); + $row[] = network_format_bytes($data['avgbps']); $table->data[] = $row; $row = []; $row[] = __('Average packets per second'); - $row[] = format_numeric($data['avgpps']); + $row[] = format_for_graph($data['avgpps'], 2); $table->data[] = $row; $row = []; $row[] = __('Average bytes per packet'); - $row[] = format_numeric($data['avgbpp']); + $row[] = format_for_graph($data['avgbpp'], 2); $table->data[] = $row; $html = html_print_table($table, true); @@ -424,7 +381,7 @@ function netflow_summary_table($data) /** * Returns 1 if the given address is a network address. * - * @param string address Host or network address. + * @param string $address Host or network address. * * @return 1 if the address is a network address, 0 otherwise. */ @@ -441,225 +398,173 @@ function netflow_is_net($address) /** * Returns netflow data for the given period in an array. * - * @param string start_date Period start date. - * @param string end_date Period end date. - * @param string filter Netflow filter. - * @param string aggregate Aggregate field. - * @param int max Maximum number of aggregates. - * @param string unit Unit to show. + * @param string $start_date Period start date. + * @param string $end_date Period end date. + * @param mixed $interval_length Resolution points or hourly or daily. + * @param string $filter Netflow filter. + * @param string $aggregate Aggregate field. + * @param integer $max Maximum number of aggregates. + * @param boolean $absolute True to give the absolute data and false + * to get troughput. + * @param string $connection_name Node name when data is get in meta. + * @param boolean $address_resolution True to resolve ips to hostnames. * - * @return An array with netflow stats. + * @return array An array with netflow stats. */ -function netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max, $unit, $connection_name='', $address_resolution=false) -{ +function netflow_get_data( + $start_date, + $end_date, + $interval_length, + $filter, + $aggregate, + $max, + $absolute, + $connection_name='', + $address_resolution=false +) { global $nfdump_date_format; global $config; - // Requesting remote data + // Requesting remote data. if (defined('METACONSOLE') && $connection_name != '') { - $data = metaconsole_call_remote_api($connection_name, 'netflow_get_data', "$start_date|$end_date|$interval_length|".base64_encode(json_encode($filter))."|$aggregate|$max|$unit".(int) $address_resolution); + $data = metaconsole_call_remote_api( + $connection_name, + 'netflow_get_data', + "$start_date|$end_date|$interval_length|".base64_encode(json_encode($filter))."|$aggregate|$max|1".(int) $address_resolution + ); return json_decode($data, true); } - // Calculate the number of intervals - if ($interval_length <= 0) { - // $num_intervals = $config['graph_res'] * 50; - $num_intervals = 250; - $period = ($end_date - $start_date); - $interval_length = (int) ($period / $num_intervals); - } else { - $period = ($end_date - $start_date); - $num_intervals = (int) ($period / $interval_length); + if ($start_date > $end_date) { + return []; } - // Set a max number of intervals - if ($num_intervals > $config['netflow_max_resolution']) { - $num_intervals = $config['netflow_max_resolution']; - $interval_length = (int) ($period / $num_intervals); + // Calculate the number of intervals. + $multiplier_time = ($end_date - $start_date); + switch ($interval_length) { + case NETFLOW_RES_LOWD: + case NETFLOW_RES_MEDD: + case NETFLOW_RES_HID: + case NETFLOW_RES_ULTRAD: + $multiplier_time = ceil(($end_date - $start_date) / $interval_length); + break; + + case NETFLOW_RES_HOURLY: + $multiplier_time = SECONDS_1HOUR; + break; + + case NETFLOW_RES_DAILY: + $multiplier_time = SECONDS_1DAY; + break; + + default: + $multiplier_time = ($end_date - $start_date); + break; } - // If there is aggregation calculate the top n - if ($aggregate != 'none') { - $values['data'] = []; - $values['sources'] = []; - - // Get the command to call nfdump - $command = netflow_get_command($filter); - - // Suppress the header line and the statistics at the bottom and configure piped output - $command .= ' -q -o csv'; - - // Call nfdump - $agg_command = $command." -n $max -s $aggregate/bytes -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); - exec($agg_command, $string); - - // Remove the first line - $string[0] = ''; - - // Parse aggregates - foreach ($string as $line) { - if ($line == '') { - continue; - } - - $val = explode(',', $line); - if ($aggregate == 'proto') { - $values['sources'][$val[3]] = 1; - } else { - $values['sources'][$val[4]] = 1; - } - } - - // Update the filter - switch ($aggregate) { - case 'proto': - $extra_filter = 'proto'; - break; - - default: - case 'srcip': - $extra_filter = 'ip_src'; - break; - case 'srcport': - $extra_filter = 'src_port'; - break; - - case 'dstip': - $extra_filter = 'ip_dst'; - break; - - case 'dstport': - $extra_filter = 'dst_port'; - break; - } - - if (isset($filter[$extra_filter]) && $filter[$extra_filter] != '') { - $filter[$extra_filter] .= ','; - } - - $filter[$extra_filter] = implode( - ',', - array_keys($values['sources']) + // Recalculate to not pass of netflow_max_resolution. + if ($config['netflow_max_resolution'] > 0 + && (($end_date - $start_date) / $multiplier_time) > 50 + ) { + $multiplier_time = ceil( + (($end_date - $start_date) / $config['netflow_max_resolution']) ); - } else { - $values = []; } - // Address resolution start - $get_hostnames = false; - if ($address_resolution && ($aggregate == 'srcip' || $aggregate == 'dstip')) { - $get_hostnames = true; - global $hostnames; + // Put all points into an array. + $intervals = [($start_date - $multiplier_time)]; + while ((end($intervals) < $end_date) === true) { + $intervals[] = (end($intervals) + $multiplier_time); + } - $sources = []; - foreach ($values['sources'] as $source => $value) { - if (!isset($hostnames[$source])) { - $hostname = gethostbyaddr($source); - if ($hostname !== false) { - $hostnames[$source] = $hostname; - $source = $hostname; + if (end($intervals) != $end_date) { + $intervals[] = $end_date; + } + + // Calculate the top values. + $values = netflow_get_top_data( + $start_date, + $end_date, + $filter, + $aggregate, + $max + ); + + // Update the filter to get properly next data. + netflow_update_second_level_filter( + $filter, + $aggregate, + array_keys($values['sources']) + ); + + // Resolve addresses if required. + $get_hostnames = false; + if ($address_resolution === true) { + global $hostnames; + netflow_address_resolution($values, $get_hostnames, $aggregate); + } + + foreach ($intervals as $k => $time) { + $interval_start = $time; + if (!isset($intervals[($k + 1)])) { + continue; + } + + $interval_end = $intervals[($k + 1)]; + + // Set default values. + foreach ($values['sources'] as $source => $discard) { + $values['data'][$interval_end][$source] = 0; + } + + $data = netflow_get_stats( + $interval_start, + $interval_end, + $filter, + $aggregate, + $max, + $absolute, + $connection_name + ); + + foreach ($data as $line) { + // Address resolution start. + if ($get_hostnames) { + if (!isset($hostnames[$line['agg']])) { + $hostname = false; + // Trying to get something like an IP from the description. + if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $line['agg'], $matches) + || preg_match( + "/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:?)|\2))(?4){5}((?4){2}|(25[0-5]| + (2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})/i", + $line['agg'], + $matches + ) + ) { + if ($matches[0]) { + $hostname = gethostbyaddr($line['agg']); + } + } + + if ($hostname !== false) { + $hostnames[$line['agg']] = $hostname; + $line['agg'] = $hostname; + } + } else { + $line['agg'] = $hostnames[$line['agg']]; } - } else { - $source = $hostnames[$source]; } - $sources[$source] = $value; - } - - $values['sources'] = $sources; - } - - // Address resolution end - $interval_start = $start_date; - for ($i = 0; $i < $num_intervals; $i++, $interval_start += ($interval_length + 1)) { - $interval_end = ($interval_start + $interval_length); - if ($interval_end > $end_date) { - $interval_end = $end_date; - } - - if ($aggregate == 'none') { - $data = netflow_get_summary($interval_start, $interval_end, $filter, $connection_name); - if (! isset($data['totalbytes'])) { - $values[$interval_start]['data'] = 0; + // Address resolution end. + if (! isset($values['sources'][$line['agg']])) { continue; } - switch ($unit) { - case 'megabytes': - $values[$interval_start]['data'] = ($data['totalbytes'] / 1048576); - break; - - case 'megabytespersecond': - $values[$interval_start]['data'] = ($data['avgbps'] / 1048576 / 8); - break; - - case 'kilobytes': - $values[$interval_start]['data'] = ($data['totalbytes'] / 1024); - break; - - case 'kilobytespersecond': - $values[$interval_start]['data'] = ($data['avgbps'] / 1024 / 8); - break; - - default: - $values[$interval_start]['data'] = $data['totalbytes']; - break; - } - } else { - // Set default values - foreach ($values['sources'] as $source => $discard) { - $values['data'][$interval_start][$source] = 0; - } - - $data = netflow_get_stats( - $interval_start, - $interval_end, - $filter, - $aggregate, - $max, - $unit, - $connection_name - ); - - foreach ($data as $line) { - // Address resolution start - if ($get_hostnames) { - if (!isset($hostnames[$line['agg']])) { - $hostname = false; - // Trying to get something like an IP from the description - if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $line['agg'], $matches) - || preg_match( - "/(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:?)|\2))(?4){5}((?4){2}|(25[0-5]| - (2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})/i", - $line['agg'], - $matches - ) - ) { - if ($matches[0]) { - $hostname = gethostbyaddr($line['agg']); - } - } - - if ($hostname !== false) { - $hostnames[$line['agg']] = $hostname; - $line['agg'] = $hostname; - } - } else { - $line['agg'] = $hostnames[$line['agg']]; - } - } - - // Address resolution end - if (! isset($values['sources'][$line['agg']])) { - continue; - } - - $values['data'][$interval_start][$line['agg']] = $line['data']; - } + $values['data'][$interval_end][$line['agg']] = $line['data']; } } - if (($aggregate != 'none') && (empty($values['data']))) { + if (empty($values['data'])) { return []; } @@ -670,29 +575,40 @@ function netflow_get_data($start_date, $end_date, $interval_length, $filter, $ag /** * Returns netflow stats for the given period in an array. * - * @param string start_date Period start date. - * @param string end_date Period end date. - * @param string filter Netflow filter. - * @param string aggregate Aggregate field. - * @param int max Maximum number of aggregates. - * @param string unit Unit to show. + * @param string $start_date Period start date. + * @param string $end_date Period end date. + * @param string $filter Netflow filter. + * @param string $aggregate Aggregate field. + * @param integer $max Maximum number of aggregates. + * @param boolean $absolute True to give the absolute data and false + * to get troughput. + * @param string $connection_name Node name when data is get in meta. + * @param boolean $address_resolution True to resolve ips to hostnames. * - * @return An array with netflow stats. + * @return array With netflow stats. */ -function netflow_get_stats($start_date, $end_date, $filter, $aggregate, $max, $unit, $connection_name='', $address_resolution=false) -{ +function netflow_get_stats( + $start_date, + $end_date, + $filter, + $aggregate, + $max, + $absolute=true, + $connection_name='', + $address_resolution=false +) { global $config, $nfdump_date_format; - // Requesting remote data + // Requesting remote data. if (defined('METACONSOLE') && $connection_name != '') { - $data = metaconsole_call_remote_api($connection_name, 'netflow_get_stats', "$start_date|$end_date|".base64_encode(json_encode($filter))."|$aggregate|$max|$unit|".(int) $address_resolution); + $data = metaconsole_call_remote_api($connection_name, 'netflow_get_stats', "$start_date|$end_date|".base64_encode(json_encode($filter))."|$aggregate|$max|$absolute|".(int) $address_resolution); return json_decode($data, true); } - // Get the command to call nfdump + // Get the command to call nfdump. $command = netflow_get_command($filter); - // Execute nfdump + // Execute nfdump. $command .= " -o csv -q -n $max -s $aggregate/bytes -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); exec($command, $string); @@ -700,7 +616,7 @@ function netflow_get_stats($start_date, $end_date, $filter, $aggregate, $max, $u return []; } - // Remove the first line + // Remove the first line. $string[0] = ''; $i = 0; @@ -716,60 +632,35 @@ function netflow_get_stats($start_date, $end_date, $filter, $aggregate, $max, $u $values[$i]['date'] = $val[0]; $values[$i]['time'] = $val[1]; - // create field to sort array + // Create field to sort array. $datetime = $val[0]; $end_date = strtotime($datetime); $values[$i]['datetime'] = $end_date; - if ($aggregate == 'proto') { - $values[$i]['agg'] = $val[3]; - } else { - // Address resolution start - if ($address_resolution && ($aggregate == 'srcip' || $aggregate == 'dstip')) { - global $hostnames; + // Address resolution start. + if ($address_resolution && ($aggregate == 'srcip' || $aggregate == 'dstip')) { + global $hostnames; - if (!isset($hostnames[$val[4]])) { - $hostname = gethostbyaddr($val[4]); - if ($hostname !== false) { - $hostnames[$val[4]] = $hostname; - $val[4] = $hostname; - } - } else { - $val[4] = $hostnames[$val[4]]; + if (!isset($hostnames[$val[4]])) { + $hostname = gethostbyaddr($val[4]); + if ($hostname !== false) { + $hostnames[$val[4]] = $hostname; + $val[4] = $hostname; } + } else { + $val[4] = $hostnames[$val[4]]; } - - // Address resolution end - $values[$i]['agg'] = $val[4]; } + // Address resolution end. + $values[$i]['agg'] = $val[4]; + if (! isset($val[9])) { return []; } - switch ($unit) { - case 'megabytes': - $values[$i]['data'] = ($val[9] / 1048576); - break; - - case 'megabytespersecond': - $values[$i]['data'] = ($val[9] / 1048576 / $interval_length); - break; - - case 'kilobytes': - $values[$i]['data'] = ($val[9] / 1024); - break; - - case 'kilobytespersecond': - $values[$i]['data'] = ($val[9] / 1024 / $interval_length); - break; - - default: - case 'bytes': - $values[$i]['data'] = $val[9]; - break; - case 'bytespersecond': - $values[$i]['data'] = ($val[9] / $interval_length); - break; + $values[$i]['data'] = $val[9]; + if (!$absolute) { + $values[$i]['data'] = ($values[$i]['data'] / $interval_length); } $i++; @@ -784,27 +675,28 @@ function netflow_get_stats($start_date, $end_date, $filter, $aggregate, $max, $u /** * Returns a traffic summary for the given period in an array. * - * @param string start_date Period start date. - * @param string end_date Period end date. - * @param string filter Netflow filter. + * @param string $start_date Period start date. + * @param string $end_date Period end date. + * @param string $filter Netflow filter. + * @param string $connection_name Node name when data is get in meta. * - * @return An array with netflow stats. + * @return array With netflow summary data. */ function netflow_get_summary($start_date, $end_date, $filter, $connection_name='') { global $nfdump_date_format; global $config; - // Requesting remote data + // Requesting remote data. if (defined('METACONSOLE') && $connection_name != '') { $data = metaconsole_call_remote_api($connection_name, 'netflow_get_summary', "$start_date|$end_date|".base64_encode(json_encode($filter))); return json_decode($data, true); } - // Get the command to call nfdump + // Get the command to call nfdump. $command = netflow_get_command($filter); - // Execute nfdump + // Execute nfdump. $command .= ' -o csv -n 1 -s srcip/bytes -t '.date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); exec($command, $string); @@ -812,7 +704,7 @@ function netflow_get_summary($start_date, $end_date, $filter, $connection_name=' return []; } - // Read the summary + // Read the summary. $summary = explode(',', $string[5]); if (! isset($summary[5])) { return []; @@ -830,137 +722,174 @@ function netflow_get_summary($start_date, $end_date, $filter, $connection_name=' /** - * Returns a traffic record for the given period in an array. + * Returns a relationships data for the given period in an array. * - * @param string start_date Period start date. - * @param string end_date Period end date. - * @param string filter Netflow filter. - * @param int max Maximum number of elements. - * @param string unit to show. + * @param string $start_date Period start date. + * @param string $end_date Period end date. + * @param string $filter Netflow filter. + * @param integer $max Maximum number of elements. + * @param string $aggregate One of srcip, srcport, dstip, dstport. * - * @return An array with netflow stats. + * @return array With raw relationship data. */ -function netflow_get_record($start_date, $end_date, $filter, $max, $unit, $address_resolution=false) -{ +function netflow_get_relationships_raw_data( + $start_date, + $end_date, + $filter, + $max, + $aggregate +) { global $nfdump_date_format; global $config; - // TIME_START = 0; - // TIME_END = 1; - // DURATION = 2; - // SOURCE_ADDRESS = 3; - // DESTINATION_ADDRESS = 4; - // SOURCE_PORT = 5; - // DESTINATION_PORT = 6; - // PROTOCOL = 7; - // INPUT_BYTES = 12; - // Get the command to call nfdump + $max_data = netflow_get_top_data( + $start_date, + $end_date, + $filter, + $aggregate, + $max + ); + + // Update src and dst filter (both). + $sources_array = array_keys($max_data['sources']); + $is_ip = netflow_aggregate_is_ip($aggregate); + netflow_update_second_level_filter( + $filter, + ($is_ip === true) ? 'dstip' : 'dstport', + $sources_array + ); + netflow_update_second_level_filter( + $filter, + ($is_ip === true) ? 'srcip' : 'srcport', + $sources_array + ); + + // Get the command to call nfdump. + $command = sprintf( + '%s -q -o csv -n %s -s %s/bytes -t %s-%s', + netflow_get_command($filter), + NETFLOW_MAX_DATA_CIRCULAR_MESH, + 'record', + date($nfdump_date_format, $start_date), + date($nfdump_date_format, $end_date) + ); + + // Get the command to call nfdump. $command = netflow_get_command($filter); - // Execute nfdump - $command .= " -q -o csv -n $max -s record/bytes -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); + // Execute nfdump. + $command .= ' -q -o csv -n 10000 -s record/bytes -t '.date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); exec($command, $result); if (! is_array($result)) { + return [ + 'lines' => [], + 'sources' => [], + ]; + } + + return [ + 'lines' => $result, + 'sources' => $sources_array, + ]; +} + + +/** + * Parse the raw relationships data to be painted by circular mesh chart. + * + * @param array $result Lines gotten from nfdump call. + * @param array $sources_array Array with sources involved in the chart. + * @param boolean $is_ip Is ip or port. + * + * @return array With data to be parsed on circular mesh chart. + */ +function netflow_parse_relationships_for_circular_mesh( + $result, + $sources_array, + $is_ip +) { + if (empty($result)) { return []; } - $values = []; - foreach ($result as $key => $line) { - $data = []; + // Initialize some data structures. + $data = [ + 'elements' => [], + 'matrix' => [], + ]; + $initial_data = []; + // This array has the ips or port like keys and the array position as value. + $inverse_sources_array = array_flip($sources_array); + foreach ($sources_array as $sdata) { + $data['elements'][$inverse_sources_array[$sdata]] = $sdata; + $initial_data[$inverse_sources_array[$sdata]] = 0; + } + foreach ($sources_array as $sdata) { + $data['matrix'][$inverse_sources_array[$sdata]] = $initial_data; + } + + // Port are situated in a different places from addreses. + $src_key = ($is_ip === true) ? 3 : 5; + $dst_key = ($is_ip === true) ? 4 : 6; + // Store a footprint of initial data to be compared at the end. + $freeze_data = md5(serialize($data)); + foreach ($result as $line) { + if (empty($line) === true) { + continue; + } + + // Parse the line. $items = explode(',', $line); - $data['time_start'] = $items[0]; - $data['time_end'] = $items[1]; - $data['duration'] = ($items[2] / 1000); - $data['source_address'] = $items[3]; - $data['destination_address'] = $items[4]; - $data['source_port'] = $items[5]; - $data['destination_port'] = $items[6]; - $data['protocol'] = $items[7]; + // Get the required data. + $src_item = $inverse_sources_array[$items[$src_key]]; + $dst_item = $inverse_sources_array[$items[$dst_key]]; + $value = $items[12]; - switch ($unit) { - case 'megabytes': - $data['data'] = ($items[12] / 1048576); - break; - - case 'megabytespersecond': - $data['data'] = ($items[12] / 1048576 / $data['duration']); - break; - - case 'kilobytes': - $data['data'] = ($items[12] / 1024); - break; - - case 'kilobytespersecond': - $data['data'] = ($items[12] / 1024 / $data['duration']); - break; - - default: - case 'bytes': - $data['data'] = $items[12]; - break; - case 'bytespersecond': - $data['data'] = ($items[12] / $data['duration']); - break; + // Check if valid data. + if (!isset($value) + || !isset($data['matrix'][$dst_item][$src_item]) + || !isset($data['matrix'][$src_item][$dst_item]) + ) { + continue; } - $values[] = $data; + // Update the value. + $data['matrix'][$src_item][$dst_item] += (int) $value; } - // Address resolution start - if ($address_resolution) { - global $hostnames; - - for ($i = 0; $i < count($values); $i++) { - if (!isset($hostnames[$values[$i]['source_address']])) { - $hostname = gethostbyaddr($values[$i]['source_address']); - if ($hostname !== false) { - $hostnames[$values[$i]['source_address']] = $hostname; - $values[$i]['source_address'] = $hostname; - } - } else { - $values[$i]['source_address'] = $hostnames[$values[$i]['source_address']]; - } - - if (!isset($hostnames[$values[$i]['destination_address']])) { - $hostname = gethostbyaddr($values[$i]['destination_address']); - if ($hostname !== false) { - $hostnames[$values[$i]['destination_address']] = $hostname; - $values[$i]['destination_address'] = $hostname; - } - } else { - $values[$i]['destination_address'] = $hostnames[$values[$i]['destination_address']]; - } - } + // Comparte footprints. + if ($freeze_data === md5(serialize($data))) { + // Taht means that all relationships are 0. + return []; } - // Address resolution end - return $values; + return $data; } /** * Returns the command needed to run nfdump for the given filter. * - * @param array filter Netflow filter. + * @param array $filter Netflow filter. * - * @return Command to run. + * @return string Command to run. */ function netflow_get_command($filter) { global $config; - // Build command + // Build command. $command = io_safe_output($config['netflow_nfdump']).' -N'; - // Netflow data path + // Netflow data path. if (isset($config['netflow_path']) && $config['netflow_path'] != '') { $command .= ' -R. -M '.$config['netflow_path']; } - // Filter options + // Filter options. $command .= netflow_get_filter_arguments($filter); return $command; @@ -970,13 +899,13 @@ function netflow_get_command($filter) /** * Returns the nfdump command line arguments that match the given filter. * - * @param array filter Netflow filter. + * @param array $filter Netflow filter. * - * @return Command line argument string. + * @return string Command line argument string. */ function netflow_get_filter_arguments($filter) { - // Advanced filter + // Advanced filter. $filter_args = ''; if ($filter['advanced_filter'] != '') { $filter_args = preg_replace('/["\r\n]/', '', io_safe_output($filter['advanced_filter'])); @@ -987,7 +916,7 @@ function netflow_get_filter_arguments($filter) $filter_args .= ' "(router ip '.$filter['router_ip'].')'; } - // Normal filter + // Normal filter. if ($filter['ip_dst'] != '') { $filter_args .= ' "('; $val_ipdst = explode(',', io_safe_output($filter['ip_dst'])); @@ -1102,74 +1031,11 @@ function netflow_get_filter_arguments($filter) function netflow_get_chart_types() { return [ - 'netflow_area' => __('Area graph'), - 'netflow_pie_summatory' => __('Pie graph and Summary table'), - 'netflow_statistics' => __('Statistics table'), - 'netflow_data' => __('Data table'), - 'netflow_mesh' => __('Circular mesh'), - 'netflow_host_treemap' => __('Host detailed traffic'), - ]; -} - - -/** - * Gets valid intervals for a netflow chart in the format: - * - * interval_length => interval_description - * - * @return array of valid intervals. - */ -function netflow_get_valid_intervals() -{ - return [ - (string) SECONDS_10MINUTES => __('10 mins'), - (string) SECONDS_15MINUTES => __('15 mins'), - (string) SECONDS_30MINUTES => __('30 mins'), - (string) SECONDS_1HOUR => __('1 hour'), - (string) SECONDS_2HOUR => __('2 hours'), - (string) SECONDS_5HOUR => __('5 hours'), - (string) SECONDS_12HOURS => __('12 hours'), - (string) SECONDS_1DAY => __('1 day'), - (string) SECONDS_2DAY => __('2 days'), - (string) SECONDS_5DAY => __('5 days'), - (string) SECONDS_15DAYS => __('15 days'), - (string) SECONDS_1WEEK => __('Last week'), - (string) SECONDS_1MONTH => __('Last month'), - (string) SECONDS_2MONTHS => __('2 months'), - (string) SECONDS_3MONTHS => __('3 months'), - (string) SECONDS_6MONTHS => __('6 months'), - (string) SECONDS_1YEAR => __('Last year'), - (string) SECONDS_2YEARS => __('2 years'), - ]; -} - - -/** - * Gets valid intervals for a netflow chart in the format: - * - * interval_length => interval_description - * - * @return array of valid intervals. - */ -function netflow_get_valid_subintervals() -{ - return [ - (string) SECONDS_1MINUTE => __('1 min'), - (string) SECONDS_2MINUTES => __('2 mins'), - (string) SECONDS_5MINUTES => __('5 mins'), - (string) SECONDS_10MINUTES => __('10 mins'), - (string) SECONDS_15MINUTES => __('15 mins'), - (string) SECONDS_30MINUTES => __('30 mins'), - (string) SECONDS_1HOUR => __('1 hour'), - (string) SECONDS_2HOUR => __('2 hours'), - (string) SECONDS_5HOUR => __('5 hours'), - (string) SECONDS_12HOURS => __('12 hours'), - (string) SECONDS_1DAY => __('1 day'), - (string) SECONDS_2DAY => __('2 days'), - (string) SECONDS_5DAY => __('5 days'), - (string) SECONDS_15DAYS => __('15 days'), - (string) SECONDS_1WEEK => __('1 week'), - (string) SECONDS_1MONTH => __('1 month'), + 'netflow_area' => __('Area graph'), + 'netflow_summary' => __('Summary'), + 'netflow_data' => __('Data table'), + 'netflow_mesh' => __('Circular mesh'), + 'netflow_host_treemap' => __('Host detailed traffic'), ]; } @@ -1177,20 +1043,31 @@ function netflow_get_valid_subintervals() /** * Draw a netflow report item. * - * @param string start_date Period start date. - * @param string end_date Period end date. - * @param string interval_length Interval length in seconds (num_intervals * interval_length = start_date - end_date). - * @param string type Chart type. - * @param array filter Netflow filter. - * @param int max_aggregates Maximum number of aggregates. - * @param string output Output format. Only HTML and XML are supported. + * @param string $start_date Period start date. + * @param string $end_date Period end date. + * @param mixed $interval_length Resolution points or hourly or daily. + * @param string $type Chart type. + * @param array $filter Netflow filter. + * @param integer $max_aggregates Maximum number of aggregates. + * @param string $connection_name Node name when data is get in meta. + * @param string $output Output format. Only HTML, PDF and XML + * are supported. + * @param boolean $address_resolution True to resolve ips to hostnames. * - * @return The netflow report in the appropriate format. + * @return string The netflow report in the appropriate format. */ -function netflow_draw_item($start_date, $end_date, $interval_length, $type, $filter, $max_aggregates, $connection_name='', $output='HTML', $address_resolution=false) -{ +function netflow_draw_item( + $start_date, + $end_date, + $interval_length, + $type, + $filter, + $max_aggregates, + $connection_name='', + $output='HTML', + $address_resolution=false +) { $aggregate = $filter['aggregate']; - $unit = $filter['output']; $interval = ($end_date - $start_date); if (defined('METACONSOLE')) { $width = 950; @@ -1200,106 +1077,17 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil $height = 320; - // Process item + // Process item. switch ($type) { - case '0': case 'netflow_area': - $data = netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name, $address_resolution); - if (empty($data)) { - break; - } - - if ($aggregate != 'none') { - if ($output == 'HTML') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - $html .= ' '.__('Aggregate').': '.netflow_format_aggregate($aggregate); - if ($interval_length != 0) { - $html .= ' '._('Resolution').": $interval_length ".__('seconds'); - } - - $html .= graph_netflow_aggregate_area($data, $interval, $width, $height, netflow_format_unit($unit)); - return $html; - } else if ($output == 'PDF') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - $html .= ' '.__('Aggregate').': '.netflow_format_aggregate($aggregate); - if ($interval_length != 0) { - $html .= ' '._('Resolution').": $interval_length ".__('seconds'); - } - - $html .= graph_netflow_aggregate_area($data, $interval, $width, $height, netflow_format_unit($unit), 2, true); - return $html; - } else if ($output == 'XML') { - $xml = "$unit\n"; - $xml .= "$aggregate\n"; - $xml .= "$interval_length\n"; - $xml .= netflow_aggregate_area_xml($data); - return $xml; - } - } else { - if ($output == 'HTML') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - if ($interval_length != 0) { - $html .= ' '._('Resolution').": $interval_length ".__('seconds'); - } - - $html .= graph_netflow_total_area($data, $interval, 660, 320, netflow_format_unit($unit)); - return $html; - } else if ($output == 'PDF') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - if ($interval_length != 0) { - $html .= ' '._('Resolution').": $interval_length ".__('seconds'); - } - - $html .= graph_netflow_total_area($data, $interval, 660, 320, netflow_format_unit($unit), 2, true); - return $html; - } else if ($output == 'XML') { - $xml = "$unit\n"; - $xml .= "$interval_length\n"; - $xml .= netflow_total_area_xml($data); - return $xml; - } - } - break; - - case '2': - case 'netflow_data': - $data = netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name, $address_resolution); - - if (empty($data)) { - break; - } - - if ($output == 'HTML' || $output == 'PDF') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - $html .= ' '.__('Aggregate').': '.netflow_format_aggregate($aggregate); - if ($interval_length != 0) { - $html .= ' '._('Resolution').": $interval_length ".__('seconds'); - } - - $html .= "
    "; - $html .= netflow_data_table($data, $start_date, $end_date, $aggregate, $unit); - $html .= '
    '; - - return $html; - } else if ($output == 'XML') { - $xml = "$unit\n"; - $xml .= "$aggregate\n"; - $xml .= "$interval_length\n"; - // Same as netflow_aggregate_area_xml - $xml .= netflow_aggregate_area_xml($data); - return $xml; - } - break; - - case '3': - case 'netflow_statistics': - $data = netflow_get_stats( + $data = netflow_get_data( $start_date, $end_date, + $interval_length, $filter, $aggregate, $max_aggregates, - $unit, + false, $connection_name, $address_resolution ); @@ -1308,14 +1096,55 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil } if ($output == 'HTML' || $output == 'PDF') { - $html = netflow_stat_table($data, $start_date, $end_date, $aggregate, $unit); + $html .= graph_netflow_aggregate_area( + $data, + $interval, + $width, + $height, + ($output === 'HTML') ? 1 : 2, + ($output === 'HTML'), + $end_date + ); return $html; } else if ($output == 'XML') { - return netflow_stat_xml($data); + $xml .= ''.$aggregate."\n"; + $xml .= ''.$interval_length."\n"; + $xml .= netflow_aggregate_area_xml($data); + return $xml; + } + break; + + case 'netflow_data': + $data = netflow_get_data( + $start_date, + $end_date, + $interval_length, + $filter, + $aggregate, + $max_aggregates, + true, + $connection_name, + $address_resolution + ); + if (empty($data)) { + break; + } + + if ($output == 'HTML' || $output == 'PDF') { + $html .= "
    "; + $html .= netflow_data_table($data, $start_date, $end_date, $aggregate); + $html .= '
    '; + + return $html; + } else if ($output == 'XML') { + $xml .= ''.$aggregate."\n"; + $xml .= ''.$interval_length."\n"; + // Same as netflow_aggregate_area_xml. + $xml .= netflow_aggregate_area_xml($data); + return $xml; } break; - case '4': case 'netflow_summary': $data_summary = netflow_get_summary( $start_date, @@ -1327,22 +1156,13 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil break; } - if ($output == 'HTML' || $output == 'PDF') { - return netflow_summary_table($data_summary); - } else if ($output == 'XML') { - return netflow_summary_xml($data_summary); - } - break; - - case '1': - case 'netflow_pie': $data_pie = netflow_get_stats( $start_date, $end_date, $filter, $aggregate, $max_aggregates, - $unit, + true, $connection_name, $address_resolution ); @@ -1350,131 +1170,65 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil break; } - if ($output == 'HTML') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - $html .= ' '.__('Aggregate').': '.netflow_format_aggregate($aggregate); - $html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate)); + if ($output === 'HTML' || $output === 'PDF') { + $html = ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
    '; + $html .= netflow_summary_table($data_summary); + $html .= ''; + $html .= graph_netflow_aggregate_pie( + $data_pie, + netflow_format_aggregate($aggregate), + ($output === 'HTML') ? 1 : 2, + ($output === 'HTML') + ); + $html .= '
    '; + $html .= netflow_stat_table( + $data_pie, + $start_date, + $end_date, + $aggregate + ); return $html; - } else if ($output == 'PDF') { - $html = ''.__('Unit').': '.netflow_format_unit($unit); - $html .= ' '.__('Aggregate').": $aggregate"; - $html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate), 2, true); - return $html; - } else if ($output == 'XML') { - $xml = "$unit\n"; - $xml .= "$aggregate\n"; - $xml .= netflow_aggregate_pie_xml($data_pie); - return $xml; - } - break; - - case 'netflow_pie_summatory': - $data_summary = netflow_get_summary( - $start_date, - $end_date, - $filter, - $connection_name - ); - if (empty($data_summary)) { - break; - } - - $data_pie = netflow_get_stats( - $start_date, - $end_date, - $filter, - $aggregate, - $max_aggregates, - $unit, - $connection_name, - $address_resolution - ); - if (empty($data_pie)) { - break; - } - - switch ($output) { - case 'HTML': - $html = ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= '
    '; - $html .= netflow_summary_table($data_summary); - $html .= ''.__('Unit').': '.netflow_format_unit($unit); - $html .= ' '.__('Aggregate').': '.netflow_format_aggregate($aggregate); - $html .= ''; - $html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate)); - $html .= '
    '; - return $html; - - break; - case 'PDF': - break; - - case 'XML': - return netflow_summary_xml($data_summary); - - break; + } else if ($output === 'XML') { + return netflow_summary_xml($data_summary, $data_pie); } break; case 'netflow_mesh': - $netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit, $address_resolution); - - switch ($aggregate) { - case 'srcport': - case 'dstport': - $source_type = 'source_port'; - $destination_type = 'destination_port'; - break; - - default: - case 'dstip': - case 'srcip': - $source_type = 'source_address'; - $destination_type = 'destination_address'; - break; - } - - $data = []; - $data['elements'] = []; - $data['matrix'] = []; - foreach ($netflow_data as $record) { - if (!in_array($record[$source_type], $data['elements'])) { - $data['elements'][] = $record[$source_type]; - $data['matrix'][] = []; - } - - if (!in_array($record[$destination_type], $data['elements'])) { - $data['elements'][] = $record[$destination_type]; - $data['matrix'][] = []; - } - } - - for ($i = 0; $i < count($data['matrix']); $i++) { - $data['matrix'][$i] = array_fill(0, count($data['matrix']), 0); - } - - foreach ($netflow_data as $record) { - $source_key = array_search($record[$source_type], $data['elements']); - $destination_key = array_search($record[$destination_type], $data['elements']); - if ($source_key !== false && $destination_key !== false) { - $data['matrix'][$source_key][$destination_key] += $record['data']; - } - } + $data = netflow_get_relationships_raw_data( + $start_date, + $end_date, + $filter, + $max_aggregates, + $aggregate, + $address_resolution + ); + $data_circular = netflow_parse_relationships_for_circular_mesh( + $data['lines'], + $data['sources'], + netflow_aggregate_is_ip($aggregate) + ); $html = '
    '; - $html .= graph_netflow_circular_mesh($data, netflow_format_unit($unit), 700); + $html .= graph_netflow_circular_mesh($data_circular); $html .= '
    '; - return $html; - break; case 'netflow_host_treemap': - $netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit, $address_resolution); - + $data_stats = netflow_get_stats( + $start_date, + $end_date, + $filter, + $aggregate, + $max_aggregates, + true, + $connection_name, + $address_resolution + ); switch ($aggregate) { case 'srcip': case 'srcport': @@ -1492,51 +1246,30 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil break; } - $data_aux = []; - foreach ($netflow_data as $record) { - $address = $record[$address_type]; - $port = $record[$port_type]; - - if (!isset($data_aux[$address])) { - $data_aux[$address] = []; - } - - if (!isset($data_aux[$address][$port])) { - $data_aux[$address][$port] = 0; - } - - $data_aux[$address][$port] += $record['data']; - } - + $data_graph = [ + 'name' => __('Host detailed traffic').': '.$type, + 'children' => [], + ]; $id = -1; - $data = []; - - if (! empty($netflow_data)) { - $data['name'] = __('Host detailed traffic').': '.$type; - $data['children'] = []; - - foreach ($data_aux as $address => $ports) { - $children = []; - $children['id'] = $id++; - $children['name'] = $address; - $children['children'] = []; - foreach ($ports as $port => $value) { - $children_data = []; - $children_data['id'] = $id++; - $children_data['name'] = $port; - $children_data['value'] = $value; - $children_data['tooltip_content'] = "$port: ".format_numeric($value).' '.netflow_format_unit($unit).''; - $children['children'][] = $children_data; - } - - $data['children'][] = $children; - } + foreach ($data_stats as $sdata) { + $data_graph['children'][] = [ + 'id' => $i++, + 'name' => $sdata['agg'], + 'children' => [ + [ + 'id' => $i++, + 'name' => $sdata['agg'], + 'value' => $sdata['data'], + 'tooltip_content' => network_format_bytes($sdata['data']), + ], + ], + ]; } - return graph_netflow_host_traffic($data, netflow_format_unit($unit), 'auto', 400); + return graph_netflow_host_traffic($data_graph, 'auto', 400); - break; default: + // Nothing to do. break; } @@ -1546,107 +1279,32 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil } -/** - * Render a netflow report as an XML. - * - * @param int ID of the netflow report. - * @param string end_date Period start date. - * @param string end_date Period end date. - * @param string interval_length Interval length in seconds (num_intervals * interval_length = start_date - end_date). - */ -function netflow_xml_report($id, $start_date, $end_date, $interval_length=0) -{ - // Get report data - $report = db_get_row_sql('SELECT * FROM tnetflow_report WHERE id_report ='.(int) $id); - if ($report === false) { - echo ''.__('Error generating report')."\n"; - return; - } - - // Print report header - $time = get_system_time(); - echo ''; - echo "\n"; - echo " \n"; - echo ' '.$time."\n"; - echo ' '.date('r', $time)."\n"; - echo " \n"; - echo ' '.io_safe_output($report['id_name'])."\n"; - echo ' '.io_safe_output($report['description'])."\n"; - echo ' '.date('r', $start_date)."\n"; - echo ' '.date('r', $end_date)."\n"; - - // Get netflow item types - $item_types = netflow_get_chart_types(); - - // Print report items - $report_contents = db_get_all_rows_sql( - "SELECT * - FROM tnetflow_report_content - WHERE id_report='".$report['id_report']."' - ORDER BY `order`" - ); - foreach ($report_contents as $content) { - // Get item filters - $filter = db_get_row_sql( - "SELECT * - FROM tnetflow_filter - WHERE id_sg = '".io_safe_input($content['id_filter'])."'", - false, - true - ); - if ($filter === false) { - continue; - } - - echo " \n"; - echo ' '.io_safe_output($content['description'])."\n"; - echo ' '.io_safe_output($item_types[$content['show_graph']])."\n"; - echo ' '.$content['max']."\n"; - echo " \n"; - echo ' '.io_safe_output($filter['id_name'])."\n"; - echo ' '.io_safe_output($filter['ip_src'])."\n"; - echo ' '.io_safe_output($filter['ip_dst'])."\n"; - echo ' '.io_safe_output($filter['src_port'])."\n"; - echo ' '.io_safe_output($filter['src_port'])."\n"; - echo ' '.io_safe_output($filter['advanced_filter'])."\n"; - echo ' '.io_safe_output($filter['aggregate'])."\n"; - echo ' '.io_safe_output($filter['output'])."\n"; - echo " \n"; - - echo netflow_draw_item($start_date, $end_date, $interval_length, $content['show_graph'], $filter, $content['max'], $report['server_name'], 'XML'); - - echo " \n"; - } - - echo "\n"; -} - - /** * Render an aggregated area chart as an XML. * - * @param array Netflow data. + * @param array $data Netflow data. + * + * @return void XML is echoed. */ function netflow_aggregate_area_xml($data) { - // Print source information + // Print source information. if (isset($data['sources'])) { echo "\n"; foreach ($data['sources'] as $source => $discard) { - echo "$source\n"; + echo ''.$source."\n"; } echo "\n"; - // Print flow information + // Print flow information. echo "\n"; foreach ($data['data'] as $timestamp => $flow) { echo "\n"; echo ' '.$timestamp."\n"; echo " \n"; foreach ($flow as $source => $data) { - echo " $source\n"; + echo ' '.$source."\n"; echo ' '.$data."\n"; } @@ -1669,133 +1327,49 @@ function netflow_aggregate_area_xml($data) } -/** - * Render an area chart as an XML. - * - * @param array Netflow data. - */ -function netflow_total_area_xml($data) -{ - // Print flow information - $xml = "\n"; - foreach ($data as $timestamp => $flow) { - $xml .= "\n"; - $xml .= ' '.$timestamp."\n"; - $xml .= ' '.$flow['data']."\n"; - $xml .= "\n"; - } - - $xml .= "\n"; - - return $xml; -} - - -/** - * Render a pie chart as an XML. - * - * @param array Netflow data. - */ -function netflow_aggregate_pie_xml($data) -{ - // Calculate total - $total = 0; - foreach ($data as $flow) { - $total += $flow['data']; - } - - if ($total == 0) { - return; - } - - // Print percentages - echo "\n"; - foreach ($data as $flow) { - echo ''.$flow['agg']."\n"; - echo ''.format_numeric((100 * $flow['data'] / $total), 2)."%\n"; - } - - echo "\n"; -} - - -/** - * Render a stats table as an XML. - * - * @param array Netflow data. - */ -function netflow_stat_xml($data) -{ - // Print stats - $xml .= "\n"; - foreach ($data as $flow) { - $xml .= ''.$flow['agg']."\n"; - $xml .= ''.$flow['data']."\n"; - } - - $xml .= "\n"; - - return $xml; -} - - /** * Render a summary table as an XML. * - * @param array Netflow data. + * @param array $data Netflow data. + * @param array $rows_data Table info (top N hosts). + * + * @return string Wiht XML data. */ -function netflow_summary_xml($data) +function netflow_summary_xml($data, $rows_data) { - // Print summary + // Print summary. $xml = "\n"; - $xml .= ' '.$data['totalflows']."\n"; - $xml .= ' '.$data['totalbytes']."\n"; - $xml .= ' '.$data['totalbytes']."\n"; - $xml .= ' '.$data['avgbps']."\n"; - $xml .= ' '.$data['avgpps']."\n"; - $xml .= ' '.$data['avgpps']."\n"; + $xml = " \n"; + $xml .= ' '.$data['totalflows']."\n"; + $xml .= ' '.$data['totalbytes']."\n"; + $xml .= ' '.$data['totalbytes']."\n"; + $xml .= ' '.$data['avgbps']."\n"; + $xml .= ' '.$data['avgpps']."\n"; + $xml .= ' '.$data['avgpps']."\n"; + $xml .= " \n"; + + // Add the data table. + $xml .= " \n"; + foreach ($rows_data as $d) { + $xml .= "\n"; + $xml .= ''.$d['agg']."\n"; + $xml .= ''.$d['data']."\n"; + $xml .= "\n"; + } + + $xml .= " \n"; $xml .= "\n"; return $xml; } -/** - * Return a string describing the given unit. - * - * @param string Netflow unit. - */ -function netflow_format_unit($unit) -{ - switch ($unit) { - case 'megabytes': - return __('MB'); - - case 'megabytespersecond': - return __('MB/s'); - - case 'kilobytes': - return __('kB'); - - case 'kilobytespersecond': - return __('kB/s'); - - case 'bytes': - return __('Bytes'); - - case 'bytespersecond': - return __('B/s'); - - default: - return ''; - } -} - - /** * Return a string describing the given aggregate. * - * @param string Netflow aggregate. + * @param string $aggregate Netflow aggregate. + * + * @return string With formatted aggregate. */ function netflow_format_aggregate($aggregate) { @@ -1806,9 +1380,6 @@ function netflow_format_aggregate($aggregate) case 'dstip': return __('Dst IP'); - case 'proto': - return __('Protocol'); - case 'srcip': return __('Src IP'); @@ -1824,20 +1395,20 @@ function netflow_format_aggregate($aggregate) /** * Check the nfdump binary for compatibility. * - * @param string nfdump binary full path. + * @param string $nfdump_binary Nfdump binary full path. * - * @return 1 if the binary does not exist or is not executable, 2 if a + * @return integer 1 if the binary does not exist or is not executable, 2 if a * version older than 1.6.8 is installed or the version cannot be * determined, 0 otherwise. */ function netflow_check_nfdump_binary($nfdump_binary) { - // Check that the binary exists and is executable + // Check that the binary exists and is executable. if (! is_executable($nfdump_binary)) { return 1; } - // Check at least version 1.6.8 + // Check at least version 1.6.8. $output = ''; $rc = -1; exec($nfdump_binary.' -V', $output, $rc); @@ -1866,3 +1437,462 @@ function netflow_check_nfdump_binary($nfdump_binary) return 2; } + + +/** + * Get the netflow datas to build a netflow explorer data structure. + * + * @param integer $max Number of result displayed. + * @param string $top_action Action to do (listeners,talkers,tcp or udp). + * @param integer $start_date In utimestamp. + * @param integer $end_date In utimestamp. + * @param string $filter Ip to filter. + * @param string $order Select one of bytes,pkts,flow. + * + * @return array With data (host, sum_bytes, sum_pkts and sum_flows). + */ +function netflow_get_top_summary( + $max, + $top_action, + $start_date, + $end_date, + $filter='', + $order='bytes' +) { + global $nfdump_date_format; + $netflow_filter = []; + $sort = ''; + switch ($top_action) { + case 'listeners': + if (empty(!$filter)) { + $netflow_filter['ip_src'] = $filter; + } + + $sort = 'dstip'; + break; + + case 'talkers': + if (empty(!$filter)) { + $netflow_filter['ip_dst'] = $filter; + } + + $sort = 'srcip'; + break; + + case 'tcp': + case 'udp': + $netflow_filter['proto'] = $top_action; + $sort = 'port'; + if (empty(!$filter)) { + $netflow_filter['advanced_filter'] = sprintf( + '((dst port %s) or (src port %s)) and (proto %s)', + $filter, + $filter, + $top_action + ); + // Display ips when filter is set in port. + $sort = 'ip'; + } + break; + + default: + return []; + } + + $command = netflow_get_command($netflow_filter); + + // Execute nfdump. + $order_text = ''; + switch ($order) { + case 'flows': + $order_text = 'flows'; + break; + + case 'pkts': + $order_text = 'packets'; + break; + + case 'bytes': + default: + $order_text = 'bytes'; + break; + } + + $command .= " -q -o csv -n $max -s $sort/$order_text -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); + exec($command, $result); + + if (! is_array($result)) { + return []; + } + + // Remove first line (avoiding slow array_shift). + $result = array_reverse($result); + array_pop($result); + $result = array_reverse($result); + + $top_info = []; + foreach ($result as $line) { + if (empty($line)) { + continue; + } + + $data = explode(',', $line); + if (!isset($data[9])) { + continue; + } + + $top_info[(string) $data[4]] = [ + 'host' => $data[4], + 'sum_bytes' => $data[9], + 'sum_pkts' => $data[7], + 'sum_flows' => $data[5], + 'pct_bytes' => $data[10], + 'pct_pkts' => $data[8], + 'pct_flows' => $data[6], + ]; + } + + return $top_info; +} + + +/** + * Check the netflow version and print an error message if there is not correct. + * + * @return boolean True if version check is correct. + */ +function netflow_print_check_version_error() +{ + global $config; + + switch (netflow_check_nfdump_binary($config['netflow_nfdump'])) { + case 0: + return true; + + case 1: + ui_print_error_message( + __('nfdump binary (%s) not found!', $config['netflow_nfdump']) + ); + return false; + + case 2: + default: + ui_print_error_message( + __('Make sure nfdump version 1.6.8 or newer is installed!') + ); + return false; + } +} + + +/** + * Returns the array for netflow resolution select. + * + * @return array With all values. + */ +function netflow_resolution_select_params() +{ + return [ + NETFLOW_RES_LOWD => __('Low'), + NETFLOW_RES_MEDD => __('Medium'), + NETFLOW_RES_HID => __('High'), + NETFLOW_RES_ULTRAD => __('Ultra High'), + NETFLOW_RES_HOURLY => __('Hourly'), + NETFLOW_RES_DAILY => __('Daily'), + ]; +} + + +/** + * Get the resolution name. + * + * @param mixed $value Type. + * + * @return string Translated name. Unknown for unrecognized resolution names. + */ +function netflow_get_resolution_name($value) +{ + $resolutions = netflow_resolution_select_params(); + return (isset($resolutions[$value])) ? $resolutions[$value] : __('Unknown'); +} + + +/** + * Report formatted subtitle. + * + * @param string $aggregate Aggregate by param. + * @param string $resolution Netfow live view resolution. + * @param string $type Type of view. + * + * @return string HTML with formatted subtitle. + */ +function netflow_generate_subtitle_report($aggregate, $resolution, $type) +{ + $subt = __( + 'Agregate by %s', + netflow_format_aggregate($aggregate) + ); + + // Display the resolution only in required reports. + if (in_array($type, ['netflow_area', 'netflow_data']) === true) { + $subt .= ' - '; + $subt .= __( + 'Resolution %s', + netflow_get_resolution_name($resolution) + ); + } + + return $subt; +} + + +/** + * Returns netflow stats for the given period in an array. + * + * @param string $start_date Period start date. + * @param string $end_date Period end date. + * @param string $filter Netflow filter. + * @param string $aggregate Aggregate field. + * @param integer $max Maximum number of aggregates. + * + * @return array With netflow stats. + */ +function netflow_get_top_data( + $start_date, + $end_date, + $filter, + $aggregate, + $max +) { + global $nfdump_date_format; + + $values = [ + 'data' => [], + 'sources' => [], + ]; + + // Get the command to call nfdump. + $agg_command = sprintf( + '%s -q -o csv -n %s -s %s/bytes -t %s-%s', + netflow_get_command($filter), + $max, + $aggregate, + date($nfdump_date_format, $start_date), + date($nfdump_date_format, $end_date) + ); + + // Call nfdump. + exec($agg_command, $string); + + // Remove the first line. + $string[0] = ''; + + // Parse aggregates. + foreach ($string as $line) { + if (empty($line) === true) { + continue; + } + + $val = explode(',', $line); + $values['sources'][$val[4]] = 1; + } + + return $values; +} + + +/** + * Returns netflow stats for the given period in an array. + * + * @param string $filter Netflow filter (passed by reference). + * @param string $aggregate Aggregate field. + * @param array $sources Sources to aggregate to filter. + * + * @return void $filter is passed by reference. + */ +function netflow_update_second_level_filter(&$filter, $aggregate, $sources) +{ + // Update the filter. + switch ($aggregate) { + default: + case 'srcip': + $extra_filter = 'ip_src'; + break; + case 'srcport': + $extra_filter = 'src_port'; + break; + + case 'dstip': + $extra_filter = 'ip_dst'; + break; + + case 'dstport': + $extra_filter = 'dst_port'; + break; + } + + if (isset($filter[$extra_filter]) && $filter[$extra_filter] != '') { + $filter[$extra_filter] .= ','; + } + + $filter[$extra_filter] = implode(',', $sources); +} + + +/** + * Change some values on address resolve. + * + * @param array $values Where data will be overwritten (ref). + * @param boolean $get_hostnames Change it if address resolution es done (ref). + * @param string $aggregate One of srcip, srcport, dstip, dstport. + * + * @return void Referenced passed params will be changed. + */ +function netflow_address_resolution(&$values, &$get_hostnames, $aggregate) +{ + if ($aggregate !== 'srcip' && $aggregate !== 'dstip') { + return; + } + + $get_hostnames = true; + global $hostnames; + + $sources = []; + foreach ($values['sources'] as $source => $value) { + if (!isset($hostnames[$source])) { + $hostname = gethostbyaddr($source); + if ($hostname !== false) { + $hostnames[$source] = $hostname; + $source = $hostname; + } + } else { + $source = $hostnames[$source]; + } + + $sources[$source] = $value; + } + + $values['sources'] = $sources; +} + + +/** + * Check if is aggregate by IP or by port + * + * @param string $aggregate Aggregate tag. + * + * @return boolean True if is IP. False for port. + */ +function netflow_aggregate_is_ip($aggregate) +{ + return in_array($aggregate, ['dstip', 'srcip']); +} + + +/** + * Build netflow data structure to network map. + * + * @param integer $start_date Time in timestamp format. + * @param integer $end_date Time in timestamp format. + * @param integer $top Max data to show. + * @param integer $aggregate One of dstip or srcip. + * + * @return array With map structure. + */ +function netflow_build_map_data($start_date, $end_date, $top, $aggregate) +{ + // Pass an empty filter data structure. + $data = netflow_get_relationships_raw_data( + $start_date, + $end_date, + [ + 'id_name' => '', + 'id_group' => 0, + 'aggregate' => $aggregate, + 'id_dst' => '', + 'ip_src' => '', + 'dst_port' => '', + 'src_port' => '', + 'advanced_filter' => '', + 'router_ip' => '', + ], + $top, + $aggregate + ); + + $nodes = array_map( + function ($elem) { + return network_init_node_map($elem); + }, + array_merge($data['sources'], [__('Others')]) + ); + + $relations = []; + $inverse_nodes = array_flip($data['sources']); + + // Port are situated in a different places from addreses. + $is_ip = true; + $src_key = ($is_ip === true) ? 3 : 5; + $dst_key = ($is_ip === true) ? 4 : 6; + $retrieved_data = array_fill_keys($inverse_nodes, false); + + foreach ($data['lines'] as $line) { + if (empty($line) === true) { + continue; + } + + // Parse the line. + $items = explode(',', $line); + + // Get the required data. + $src_item = $inverse_nodes[$items[$src_key]]; + $dst_item = $inverse_nodes[$items[$dst_key]]; + $value = $items[12]; + $index_rel = $src_item.'-'.$dst_item; + + // Check if valid data. + if (!isset($value) || (!isset($src_item) && !isset($dst_item))) { + continue; + } + + // Mark as connected source and destination. + $retrieved_data[$src_item] = true; + $retrieved_data[$dst_item] = true; + + if (isset($relations[$index_rel])) { + $relations[$index_rel]['text_start'] += $value; + } else { + // Update the value. + network_init_relation_map($relations, $src_item, $dst_item, $value); + } + } + + // Format the data in edges. + array_walk( + $relations, + function (&$elem) { + $elem['text_start'] = network_format_bytes($elem['text_start']); + } + ); + + // Search for orphan nodes. + $orphan_hosts = []; + $orphan_index = (end($inverse_nodes) + 1); + foreach ($retrieved_data as $position => $rd) { + if ($rd === true) { + continue; + } + + network_init_relation_map($orphan_hosts, $position, $orphan_index); + } + + // If there is not any orphan node, delete it. + if (empty($orphan_hosts)) { + array_pop($nodes); + } + + return network_general_map_configuration( + $nodes, + array_merge($relations, $orphan_hosts) + ); +} diff --git a/pandora_console/include/functions_network.php b/pandora_console/include/functions_network.php new file mode 100644 index 0000000000..9c9e1456b4 --- /dev/null +++ b/pandora_console/include/functions_network.php @@ -0,0 +1,320 @@ + %d AND utimestamp < %d + %s + %s + GROUP BY %s + ORDER BY %s DESC + LIMIT %d', + $field_to_group, + $start, + $end, + $filter_sql, + $host_filter_sql, + $field_to_group, + $field_to_order, + $top + ); + + $data = db_get_all_rows_sql($sql); + + return ($data !== false) ? $data : []; +} + + +/** + * Get the possible actions on networking. + * + * @param boolean $network True if network. False if netflow. + * + * @return array With the actions to print in a select. + */ +function network_get_report_actions($network=true) +{ + $common_actions = [ + 'listeners' => __('Top listeners'), + 'talkers' => __('Top talkers'), + ]; + + if ($network) { + return $common_actions; + } + + return array_merge( + $common_actions, + [ + 'tcp' => __('Top TCP protocols'), + 'udp' => __('Top UDP protocols'), + ] + ); +} + + +/** + * Print the header of the network + * + * @param string $title Title of header. + * @param string $order Current ordering. + * @param string $selected Selected order. + * @param array $hidden_data All the data to hide into the button. + * + * @return string With HTML data. + */ +function network_print_explorer_header( + $title, + $order, + $selected, + $hidden_data +) { + $cell = '
    '; + $cell .= $title; + $cell .= html_print_link_with_params( + 'images/arrow-down-white.png', + array_merge($hidden_data, ['order_by' => $order]), + 'image', + ($selected === $order) ? 'opacity: 0.5' : '' + ); + $cell .= '
    '; + + return $cell; +} + + +/** + * Alias for format_for_graph to print bytes. + * + * @param integer $value Value to parse like bytes. + * + * @return string Number parsed. + */ +function network_format_bytes($value) +{ + if (!isset($value)) { + $value = 0; + } + + $value = (int) $value; + + return format_for_graph( + $value, + 2, + '.', + ',', + 1024, + 'B' + ); +} + + +/** + * Build netflow data structure to network map. + * + * @param integer $start Time in timestamp format. + * @param integer $end Time in timestamp format. + * @param integer $top Max data to show. + * @param boolean $talker True to get top tolkers. False for listeners. + * + * @return array With map structure. + */ +function network_build_map_data($start, $end, $top, $talker) +{ + $data = network_matrix_get_top($top, $talker, $start, $end); + + $hosts = array_map( + function ($elem) { + return $elem['host']; + }, + $data + ); + $inverse_hosts = array_flip($hosts); + + $nodes = array_map( + function ($elem) { + return network_init_node_map($elem); + }, + $hosts + ); + + $relations = []; + $orphan_relations = []; + foreach ($hosts as $host) { + $host_top = network_matrix_get_top( + $top, + !$talker, + $start, + $end, + $host, + true, + $hosts + ); + foreach ($host_top as $sd) { + $src_index = $inverse_hosts[$host]; + $dst_index = $inverse_hosts[$sd['host']]; + if (isset($src_index) === false || isset($dst_index) === false) { + continue; + } + + network_init_relation_map( + $relations, + $src_index, + $dst_index, + network_format_bytes($sd['sum_bytes']) + ); + } + + // Put the orphans on Other node. + if (empty($host_top)) { + $other_id = (end($inverse_hosts) + 1); + // TODOS: Add the data. + network_init_relation_map( + $orphan_relations, + $other_id, + $inverse_hosts[$host] + ); + } + } + + // Put the Others node and their relations. + if (empty($orphan_relations) === false) { + $nodes[] = network_init_node_map(__('Others')); + $relations = array_merge($relations, $orphan_relations); + } + + return network_general_map_configuration($nodes, $relations); +} + + +/** + * Return the array to pass to constructor to NetworkMap. + * + * @param array $nodes Nodes data structure. + * @param array $relations Relations data structure. + * + * @return array To be passed to NetworMap class. + */ +function network_general_map_configuration($nodes, $relations) +{ + return [ + 'nodes' => $nodes, + 'relations' => $relations, + 'pure' => 1, + 'no_pandora_node' => 1, + 'no_popup' => 1, + 'map_options' => [ + 'generation_method' => LAYOUT_SPRING1, + 'map_filter' => [ + 'node_radius' => 40, + 'node_sep' => 7, + ], + ], + ]; +} + + +/** + * Added a relation to relations array + * + * @param array $relations Relations array (passed by reference). + * @param integer $parent Parent id (numeric). + * @param integer $child Child id (numeric). + * @param string $text Text to show at the end of edge (optional). + * + * @return void Relations will be modified (passed by reference). + */ +function network_init_relation_map(&$relations, $parent, $child, $text='') +{ + $index = $parent.'-'.$child; + $relations[$index] = [ + 'id_parent' => $parent, + 'parent_type' => NODE_GENERIC, + 'child_type' => NODE_GENERIC, + 'id_child' => $child, + 'link_color' => '#82B92E', + ]; + + if (empty($text) === false) { + $relations[$index]['text_start'] = $text; + } +} + + +/** + * Initialize a node structure to NetworkMap class. + * + * @param string $name Node name. + * + * @return array Node data structure. + */ +function network_init_node_map($name) +{ + return [ + 'name' => $name, + 'type' => NODE_GENERIC, + 'width' => 20, + 'height' => 20, + 'status' => '#82B92E', + ]; +} diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index adbaa00922..af11deb541 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -1,32 +1,36 @@ = 1) { + /* + * Select data origin. + * group + * discovery task + * - Cloud + * - Application + * - Standar or custom + * network/mask + */ + + if ($group >= 0 && empty($ip_mask)) { if ($dont_show_subgroups) { $filter['id_grupo'] = $group; } else { @@ -372,22 +358,8 @@ function networkmap_generate_dot( } else if ($group == -666) { $agents = false; } else if (!empty($ip_mask)) { - $agents = networkmap_get_new_nodes_from_ip_mask( - $ip_mask, - [ - 'id_grupo', - 'nombre', - 'id_os', - 'id_parent', - 'id_agente', - 'normal_count', - 'warning_count', - 'critical_count', - 'unknown_count', - 'total_count', - 'notinit_count', - ], - $strict_user + $agents = networkmap_get_nodes_from_ip_mask( + $ip_mask ); } else { $agents = agents_get_agents( @@ -455,7 +427,6 @@ function networkmap_generate_dot( // Get agent modules data $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true); - if ($modules === false) { $modules = []; } @@ -518,11 +489,11 @@ function networkmap_generate_dot( // Create void statistics array $stats = []; - - $count = 0; - $group_nodes = 10; - $graph .= networkmap_create_transparent_node($count); - foreach (array_keys($orphans) as $node) { + /* + $count = 0; + $group_nodes = 10; + $graph .= networkmap_create_transparent_node($count); + foreach (array_keys($orphans) as $node) { if ($group_nodes == 0) { $count++; $graph .= networkmap_create_transparent_node($count); @@ -536,7 +507,8 @@ function networkmap_generate_dot( ); $group_nodes--; - } + } + */ // Create nodes foreach ($nodes as $node_id => $node) { @@ -694,17 +666,57 @@ function networkmap_generate_dot( } -// Returns an edge definition -function networkmap_create_edge($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2='operation/agentes/networkmap', $tab='topology', $id_networkmap=0) -{ +/** + * Returns an edge definition. + * + * @param mixed $head Head. + * @param mixed $tail Tail. + * @param string $layout Layout. + * @param string $nooverlap Nooverlap. + * @param integer $pure Pure. + * @param float $zoom Zoom. + * @param float $ranksep Ranksep. + * @param integer $simple Simple. + * @param integer $regen Regen. + * @param integer $font_size Font_size. + * @param integer $group Group. + * @param string $sec2 Sec2. + * @param string $tab Tab. + * @param integer $id_networkmap Id_networkmap. + * + * @return string Dot string. + */ +function networkmap_create_edge( + $head, + $tail, + $layout, + $nooverlap, + $pure, + $zoom, + $ranksep, + $simple, + $regen, + $font_size, + $group, + $sec2='operation/agentes/networkmap', + $tab='topology', + $id_networkmap=0 +) { if (defined('METACONSOLE')) { $url = ''; } else { - $url = 'index.php?sec=estado&'.'sec2='.$sec2.'&'.'tab='.$tab.'&'.'recenter_networkmap=1&'.'center='.$head.'&'.'layout='.$layout.'&'.'nooverlap='.$nooverlap.'&'.'pure='.$pure.'&'.'zoom='.$zoom.'&'.'ranksep='.$ranksep.'&'.'simple='.$simple.'&'.'regen=1'.'&'.'font_size='.$font_size.'&'.'group='.$group.'&'.'id_networkmap='.$id_networkmap; + $url = 'index.php?sec=estado&sec2='.$sec2.'&tab='.$tab.'&'; + $url .= 'recenter_networkmap=1¢er='.$head.'&'; + $url .= 'layout='.$layout.'&nooverlap='.$nooverlap.'&'; + $url .= 'pure='.$pure.'&zoom='.$zoom.'&ranksep='.$ranksep.'&'; + $url .= 'simple='.$simple.'®en=1&font_size='.$font_size.'&'; + $url .= 'group='.$group.'&id_networkmap='.$id_networkmap; } - // edgeURL allows node navigation - $edge = "\n".$head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false, edgeURL=""];'."\n"; + // Option edgeURL allows node navigation. + $edge = "\n".$head.' -- '.$tail; + $edge .= '[len='.$ranksep.', color="#BDBDBD", headclip=false, tailclip=false, edgeURL=""];'; + $edge .= "\n"; return $edge; } @@ -719,96 +731,6 @@ function networkmap_create_transparent_edge($head, $tail) } -// Returns a group node definition -function networkmap_create_group_node($group, $simple=0, $font_size=10, $metaconsole=false, $id_server=null, $strict_user=false) -{ - global $config; - global $hack_networkmap_mobile; - - $status = groups_get_status($group['id_grupo'], $strict_user); - - // Set node status - switch ($status) { - case 0: - $status_color = COL_NORMAL; - // Normal monitor - break; - - case 1: - $status_color = COL_CRITICAL; - // Critical monitor - break; - - case 2: - $status_color = COL_WARNING; - // Warning monitor - break; - - case 4: - $status_color = COL_ALERTFIRED; - // Alert fired - break; - - default: - $status_color = COL_UNKNOWN; - // Unknown monitor - break; - } - - $icon = groups_get_icon($group['id_grupo']); - - if ($simple == 0) { - // Set node icon - if ($hack_networkmap_mobile) { - $img_node = $config['homedir'].'/images/groups_small/'.$icon.'.png'; - - if (!file_exists($img_node)) { - $img_node = '-'; - } - - $img_node = ''; - } else if (file_exists(html_print_image('images/groups_small/'.$icon.'.png', true, false, true, true))) { - $img_node = html_print_image('images/groups_small/'.$icon.'.png', true, false, false, true); - } else { - $img_node = '-'; - } - - if (strlen(groups_get_name($group['id_grupo'])) > 40) { - $name = substr(groups_get_name($group['id_grupo']), 0, 40).'...'; - } else { - $name = groups_get_name($group['id_grupo']); - } - - if (defined('METACONSOLE')) { - $url = ''; - $url_tooltip = ''; - } else { - $url = 'index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$group['id_grupo']; - $url_tooltip = 'ajax.php?page=operation/agentes/ver_agente&get_group_status_tooltip=1&id_group='.$group['id_grupo']; - } - - $node = "\n".$group['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.30, height=0.30, '.'label=< -
    '.$img_node.'
    '.io_safe_output($name).'
    >, - shape="invtrapezium", URL="'.$url.'", - tooltip="'.$url_tooltip.'"];'."\n"; - } else { - if (defined('METACONSOLE')) { - $url = ''; - $url_tooltip = ''; - } else { - $url = 'index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$group['id_grupo']; - $url_tooltip = 'ajax.php?page=operation/agentes/ver_agente&get_group_status_tooltip=1&id_group='.$group['id_grupo']; - } - - $node = "\n".$group['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', shape="invtrapezium", - URL="'.$url.'", style="filled", fixedsize=true, width=0.20, height=0.20, label="", - tooltip="'.$url_tooltip.'"];'."\n"; - } - - return $node; -} - - // Returns a node definition function networkmap_create_agent_node($agent, $simple=0, $font_size=10, $cut_names=true, $relative=false, $metaconsole=false, $id_server=null, $strict_user=false) { @@ -952,76 +874,6 @@ function networkmap_create_agent_node($agent, $simple=0, $font_size=10, $cut_nam } -function networkmap_create_module_group_node($module_group, $simple=0, $font_size=10, $metaconsole=false, $id_server=null) -{ - global $config; - global $hack_networkmap_mobile; - - // Set node status - switch ($module_group['status']) { - case 0: - $status_color = COL_NORMAL; - // Normal monitor - break; - - case 1: - $status_color = COL_CRITICAL; - // Critical monitor - break; - - case 2: - $status_color = COL_WARNING; - // Warning monitor - break; - - case 4: - $status_color = COL_ALERTFIRED; - // Alert fired - break; - - default: - $status_color = COL_UNKNOWN; - // Unknown monitor - break; - } - - if ($simple == 0) { - if (defined('METACONSOLE')) { - $url = ''; - $url_tooltip = ''; - } else { - $url = ''; - $url_tooltip = ''; - } - - $node = $module_group['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", '.'fixedsize=true, width=0.30, height=0.30, '.'label=<
    '.io_safe_output($module_group['name']).'
    >, - shape="square", URL="'.$url.'", - tooltip="'.$url_tooltip.'"];'; - } else { - if ($hack_networkmap_mobile) { - $img_node = ui_print_moduletype_icon($module['id_tipo_modulo'], true, true, false, true); - - $img_node = $config['homedir'].'/'.$img_node; - $img_node = ''; - } else { - $img_node = ui_print_moduletype_icon($module['id_tipo_modulo'], true, true, false); - } - - if (defined('METACONSOLE')) { - $url = ''; - $url_tooltip = ''; - } else { - $url = ''; - $url_tooltip = ''; - } - - $node = $module_group['id_node'].' [ color="'.$status_color.'", fontsize='.$font_size.', shape="square", URL="'.$url.'", '.'style="filled", fixedsize=true, width=0.20, '.'height=0.20, label="", tooltip="'.$url_tooltip.'"];'; - } - - return $node; -} - - // Returns a module node definition function networkmap_create_module_node($module, $simple=0, $font_size=10, $metaconsole=false, $id_server=null) { @@ -1175,35 +1027,13 @@ function networkmap_create_transparent_node($count=0) } -// Opens a group definition -function networkmap_open_group($id) -{ - $img = 'images/'.groups_get_icon($id).'.png'; - $name = groups_get_name($id); - - $group = 'subgraph cluster_'.$id.' { style=filled; color=darkolivegreen3; label=< - -
    '.html_print_image($img, true).''.$name.'
    >; tooltip="'.$name.'"; - URL="index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id='.$id.'";'; - - return $group; -} - - -// Closes a group definition -function networkmap_close_group() -{ - return '}'; -} - - // Opens a graph definition function networkmap_open_graph( $layout, $nooverlap, $pure, $zoom, - $ranksep, + $rank_sep, $font_size, $size_canvas, $map_filter=[] @@ -1236,7 +1066,7 @@ function networkmap_open_graph( if (isset($map_filter['node_sep'])) { $node_sep = $map_filter['node_sep']; } else { - $node_sep = 0.25; + $node_sep = 0.1; } if (isset($map_filter['rank_sep'])) { @@ -1258,14 +1088,14 @@ function networkmap_open_graph( if (isset($map_filter['kval'])) { $kval = $map_filter['kval']; } else { - $kval = 0.3; + $kval = 0.1; } // BEWARE: graphwiz DONT use single ('), you need double (") $head = 'graph networkmap { dpi=100; bgcolor="transparent"; labeljust=l; margin=0; pad="0.75,0.75";'; if ($nooverlap != '') { $head .= 'overlap="false";'; - $head .= 'outputorder=edgesfirst;'; + $head .= 'outputorder=first;'; } if ($layout == 'flat' || $layout == 'spring1' || $layout == 'spring2') { @@ -1290,12 +1120,13 @@ function networkmap_open_graph( $head .= "mindist=\"$mindist\";"; } - $head .= 'ratio=fill;'; + $head .= 'ratio="fill";'; $head .= 'root=0;'; $head .= "nodesep=\"$node_sep\";"; $head .= "size=\"$size\";"; $head .= "\n"; + return $head; } @@ -1338,67 +1169,6 @@ function networkmap_get_filter($layout) } -/** - * Creates a networkmap. - * - * @param string Network map name. - * @param string Network map type (topology, groups or policies). - * @param layout Network map layout (circular, flat, radial, spring1 or spring2). - * @param bool overlapping activate flag. - * @param bool simple view activate flag. - * @param bool regenerate file activate flag. - * @param int font size. - * @param int group id filter (0 for all). - * @param int module group id filter (0 for all). - * @param int policy id filter (0 for all). - * @param string depth level. - * @param bool only modules with alerts flag. - * @param bool hide policy modules flag - * @param float zoom factor - * - * @return mixed New networkmap id if created. False if it could not be created. - */ -function networkmap_create_networkmap($values) -{ - global $config; - - // The name is required - if (! isset($values['name'])) { - return false; - } - - // Set defaults for the empty values - set_unless_defined($values['type'], 'topology'); - set_unless_defined($values['layout'], 'radial'); - set_unless_defined($values['nooverlap'], true); - set_unless_defined($values['simple'], false); - set_unless_defined($values['regenerate'], true); - set_unless_defined($values['font_size'], 12); - set_unless_defined($values['store_group'], 0); - set_unless_defined($values['id_group'], 0); - set_unless_defined($values['regenerate'], true); - set_unless_defined($values['id_module_group'], 0); - set_unless_defined($values['depth'], 'all'); - set_unless_defined($values['only_modules_with_alerts'], false); - set_unless_defined($values['hide_policy_modules'], false); - set_unless_defined($values['zoom'], 1); - set_unless_defined($values['distance_nodes'], 2.5); - set_unless_defined($values['center'], 0); - set_unless_defined($values['id_user'], $config['id_user']); - set_unless_defined($values['text_filter'], ''); - set_unless_defined($values['regenerate'], true); - set_unless_defined($values['dont_show_subgroups'], 0); - set_unless_defined($values['show_groups'], false); - set_unless_defined($values['pandoras_children'], false); - set_unless_defined($values['show_modules'], false); - set_unless_defined($values['show_snmp_modules'], 0); - set_unless_defined($values['l2_network'], 0); - set_unless_defined($values['server_name'], ''); - - return @db_process_sql_insert('tnetwork_map', $values); -} - - /** * Get a network map report. * @@ -1517,57 +1287,6 @@ function networkmap_type_to_str_type($type) } -/** - * Deletes a network map if the property is that user. - * - * @param string User id that call this funtion. - * @param int Map id to be deleted. - * - * @return boolean True if the map was deleted, false the map is not yours. - */ -function networkmap_delete_user_networkmap($id_user='', $id_networkmap) -{ - if ($id_user == '') { - $id_user = $config['id_user']; - } - - $id_networkmap = safe_int($id_networkmap); - if (empty($id_networkmap)) { - return false; - } - - $networkmap = networkmap_get_networkmap($id_networkmap); - if ($networkmap === false) { - return false; - } - - return @db_process_sql_delete('tnetwork_map', ['id_networkmap' => $id_networkmap, 'id_user' => $id_user]); -} - - -/** - * Updates a network map. - * - * @param int Map id. - * @param array Extra values to be set. - * - * @return boolean True if the map was updated. False otherwise. - */ -function networkmap_update_networkmap($id_networkmap, $values) -{ - $networkmap = networkmap_get_networkmap($id_networkmap); - if ($networkmap === false) { - return false; - } - - return (db_process_sql_update( - 'tnetwork_map', - $values, - ['id_networkmap' => $id_networkmap] - )) !== false; -} - - /** * Get different networkmaps types for creation. * @@ -1597,108 +1316,78 @@ function networkmap_get_types($strict_user=false) /** - * Get networkmaps types. + * Retrieve agent list matching desired network. * - * @return array Networkmap diferent types. + * @param string $ip_mask Networks. + * @param array $fields Extra fields. + * + * @return array Of agents. */ -function networkmap_get_filter_types($strict_user=false) -{ - $networkmap_types = []; - - $is_enterprise = enterprise_include_once('include/functions_policies.php'); - - $networkmap_types['topology'] = __('Topology'); - $networkmap_types['groups'] = __('Group'); - $networkmap_types['dynamic'] = __('Dynamic'); - if (!$strict_user) { - $networkmap_types['radial_dynamic'] = __('Radial dynamic'); - } - - if (($is_enterprise !== ENTERPRISE_NOT_HOOK) && (!$strict_user)) { - $enterprise_types = enterprise_hook('policies_get_networkmap_filter_types'); - - $networkmap_types = array_merge($networkmap_types, $enterprise_types); - } - - return $networkmap_types; -} - - -function networkmap_cidr_match($ip, $cidr_mask) -{ - // copy from open source code - // https://gist.github.com/linickx/1309388 - $chunks = explode('/', $cidr_mask); - $subnet = $chunks[0]; - $bits = $chunks[1]; - - $ip = ip2long($ip); - $subnet = ip2long($subnet); - $mask = (-1 << (32 - $bits)); - $subnet &= $mask; - // nb: in case the supplied subnet wasn't correctly aligned - return ($ip & $mask) == $subnet; -} - - -function networkmap_get_new_nodes_from_ip_mask( +function networkmap_get_nodes_from_ip_mask( $ip_mask, - $fields=[], - $strict_user=false + $return_ids_only=false ) { $list_ip_masks = explode(',', $ip_mask); - $list_address = db_get_all_rows_in_table('taddress'); - if (empty($address)) { - $address = []; - } - - if ($strict_user) { - $filter['group_by'] = 'tagente.id_agente'; - $fields = ['tagente.id_agente']; - $acltags = tags_get_user_groups_and_tags($config['id_user'], 'AR', $strict_user); - $user_agents = tags_get_all_user_agents(false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true); - - foreach ($all_user_agents as $agent) { - $user_agents[$agent['id_agente']] = $agent['id_agente']; - } + if (empty($list_ip_masks)) { + return []; } $agents = []; - foreach ($list_address as $address) { - foreach ($list_ip_masks as $ip_mask) { - if (networkmap_cidr_match($address['ip'], $ip_mask)) { - $id_agent = db_get_value_filter( - 'id_agent', - 'taddress_agent', - ['id_a' => $address['id_a']] - ); + foreach ($list_ip_masks as $subnet) { + $net = explode('/', $subnet); - if (empty($id_agent)) { - continue; - } + // Calculate real network address. Avoid user bad input. + $mask = ~((1 << (32 - $net[1])) - 1); + $network = long2ip(ip2long($net[0]) & $mask); - if (empty($fields)) { - if ($strict_user) { - if (array_key_exists($id_agent, $user_agents)) { - $agents[] = db_get_value_filter('id_agent', 'taddress_agent', ['id_a' => $address['id_a']]); - } - } else { - $agents[] = db_get_value_filter('id_agent', 'taddress_agent', ['id_a' => $address['id_a']]); - } - } else { - if ($strict_user) { - if (array_key_exists($id_agent, $user_agents)) { - $agents[] = db_get_row('tagente', 'id_agente', $id_agent, $fields); - } - } else { - $agents[] = db_get_row('tagente', 'id_agente', $id_agent, $fields); - } - } - } + $sql = sprintf( + 'SELECT * + FROM `tagente` + INNER JOIN + (SELECT DISTINCT `id_agent` FROM + (SELECT `id_agente` AS "id_agent", `direccion` AS "ip" + FROM `tagente` + UNION + SELECT ag.`id_agent`, a.`ip` + FROM `taddress_agent` ag + INNER JOIN `taddress` a + ON ag.id_a=a.id_a + ) t_tmp + WHERE (-1 << %d) & INET_ATON(t_tmp.ip) = INET_ATON("%s") + ) t_res + ON t_res.`id_agent` = `tagente`.`id_agente`', + (32 - $net[1]), + $network + ); + + $subnet_agents = db_get_all_rows_sql($sql); + + if ($subnet_agents !== false) { + $agents = array_merge($agents, $subnet_agents); } } + if ($return_ids_only === false) { + $agents = array_reduce( + $agents, + function ($carry, $item) { + $carry[$item['id_agente']] = $item; + return $carry; + }, + [] + ); + } else { + $agents = array_reduce( + $agents, + function ($carry, $item) { + $carry[$item['id_agente']] = $item['id_agente']; + return $carry; + }, + [] + ); + } + return $agents; } @@ -1729,7 +1418,944 @@ function modules_get_all_interfaces($id_agent) } -?> +function networkmap_delete_networkmap($id=0) +{ + if (enterprise_installed()) { + // Relations + $result = delete_relations($id); + + // Nodes + $result = delete_nodes($id); + } + + // Map + $result = db_process_sql_delete('tmap', ['id' => $id]); + + return $result; +} + + +function networkmap_delete_nodes($id_map) +{ + return db_process_sql_delete('titem', ['id_map' => $id_map]); +} + + +function get_networkmaps($id) +{ + $groups = array_keys(users_get_groups(null, 'IW')); + + $filter = []; + $filter['id_group'] = $groups; + $filter['id'] = '<>'.$id; + $networkmaps = db_get_all_rows_filter('tmap', $filter); + if ($networkmaps === false) { + $networkmaps = []; + } + + $return = []; + $return[0] = __('None'); + foreach ($networkmaps as $networkmap) { + $return[$networkmap['id']] = $networkmap['name']; + } + + return $return; +} + + +/** + * Translates node (nodes_and_relations) into JS node. + * + * @param array $node Node. + * @param integer $count Count. + * @param integer $count_item_holding_area Count_item_holding_area. + * @param boolean $simulated Simulated. + * + * @return array JS nodes. + */ +function networkmap_db_node_to_js_node( + $node, + &$count, + &$count_item_holding_area, + $simulated=false +) { + global $config; + + $networkmap = db_get_row('tmap', 'id', $node['id_map']); + + $networkmap['filter'] = json_decode($networkmap['filter'], true); + + // Hardcoded + $networkmap['filter']['holding_area'] = [ + 500, + 500, + ]; + + // 40 = DEFAULT NODE RADIUS + // 30 = for to align + $holding_area_max_y = ($networkmap['height'] + 30 + 40 * 2 - $networkmap['filter']['holding_area'][1] + 10 * 40); + + $item = []; + $item['id'] = $count; + + if (enterprise_installed() && $simulated === false) { + enterprise_include_once('include/functions_networkmap.php'); + $item['id_db'] = $node['id_in_db']; + } else { + $item['id_db'] = (int) $node['id']; + } + + if ((int) $node['type'] == 0) { + $item['type'] = 0; + $item['id_agent'] = (int) $node['source_data']; + $item['id_module'] = ''; + } else if ((int) $node['type'] == 1) { + $item['type'] = 1; + $item['id_agent'] = (int) $node['style']['id_agent']; + $item['id_module'] = (int) $node['source_data']; + } else { + $item['type'] = 3; + } + + $item['fixed'] = true; + $item['x'] = (int) $node['x']; + $item['y'] = (int) $node['y']; + $item['px'] = (int) $node['x']; + $item['py'] = (int) $node['y']; + $item['z'] = (int) $node['z']; + $item['state'] = $node['state']; + $item['deleted'] = $node['deleted']; + if ($item['state'] == 'holding_area') { + // 40 = DEFAULT NODE RADIUS + // 30 = for to align + $holding_area_x = ($networkmap['width'] + 30 + 40 * 2 - $networkmap['filter']['holding_area'][0] + ($count_item_holding_area % 11) * 40); + $holding_area_y = ($networkmap['height'] + 30 + 40 * 2 - $networkmap['filter']['holding_area'][1] + (int) (($count_item_holding_area / 11)) * 40); + + if ($holding_area_max_y <= $holding_area_y) { + $holding_area_y = $holding_area_max_y; + } + + $item['x'] = $holding_area_x; + $item['y'] = $holding_area_y; + + // Increment for the next node in holding area + $count_item_holding_area++; + } + + $item['image_url'] = ''; + $item['image_width'] = 0; + $item['image_height'] = 0; + if (!empty($node['style']['image'])) { + $item['image_url'] = html_print_image( + $node['style']['image'], + true, + false, + true + ); + $image_size = getimagesize( + $config['homedir'].'/'.$node['style']['image'] + ); + $item['image_width'] = (int) $image_size[0]; + $item['image_height'] = (int) $image_size[1]; + } + + $item['raw_text'] = $node['style']['label']; + $item['text'] = io_safe_output($node['style']['label']); + $item['shape'] = $node['style']['shape']; + + switch ($node['type']) { + case 0: + $color = get_status_color_networkmap($node['source_data']); + break; + + default: + // Old code + if ($node['source_data'] == -1) { + $color = '#364D1F'; + } else if ($node['source_data'] == -2) { + $color = '#364D1F'; + } else { + $color = get_status_color_networkmap($node['source_data']); + } + break; + } + + $item['color'] = $color; + $item['map_id'] = 0; + if (isset($node['id_map'])) { + $item['map_id'] = $node['id_map']; + } + + if (!isset($node['style']['id_networkmap']) || $node['style']['id_networkmap'] == '' || $node['style']['id_networkmap'] == 0) { + $item['networkmap_id'] = 0; + } else { + $item['networkmap_id'] = $node['style']['id_networkmap']; + } + + $count++; + + return $item; +} + + +function get_status_color_networkmap($id, $color=true) +{ + // $status = agents_get_status($id); + $agent_data = db_get_row_sql('SELECT * FROM tagente WHERE id_agente = '.$id); + + if ($agent_data === false) { + return COL_UNKNOWN; + } + + $status = agents_get_status_from_counts($agent_data); + + if (!$color) { + return $status; + } + + if ($agent_data['fired_count'] > 0) { + return COL_ALERTFIRED; + } + + // Select node color by checking status. + switch ($status) { + case AGENT_MODULE_STATUS_NORMAL: + return COL_NORMAL; + + case AGENT_MODULE_STATUS_NOT_INIT: + return COL_NOTINIT; + + case AGENT_MODULE_STATUS_CRITICAL_BAD: + return COL_CRITICAL; + + case AGENT_MODULE_STATUS_WARNING: + return COL_WARNING; + + case AGENT_MODULE_STATUS_UNKNOWN: + default: + return COL_UNKNOWN; + } + + return COL_UNKNOWN; +} + + +function networkmap_clean_relations_for_js(&$relations) +{ + do { + $cleaned = true; + + foreach ($relations as $key => $relation) { + if ($relation['id_parent_source_data'] == $relation['id_child_source_data']) { + if (($relation['child_type'] != 3) && $relation['parent_type'] != 3) { + $cleaned = false; + + if ($relation['parent_type'] == 1) { + $to_find = $relation['id_parent_source_data']; + $to_replace = $relation['id_child_source_data']; + } else if ($relation['child_type'] == 1) { + $to_find = $relation['id_child_source_data']; + $to_replace = $relation['id_parent_source_data']; + } + + // Replace and erase the links + foreach ($relations as $key2 => $relation2) { + if ($relation2['id_parent_source_data'] == $to_find) { + $relations[$key2]['id_parent_source_data'] = $to_replace; + } else if ($relation2['id_child_source_data'] == $to_find) { + $relations[$key2]['id_child_source_data'] = $to_replace; + } + } + + unset($relations[$key]); + + break; + } + } + } + } while (!$cleaned); +} + + +/** + * Transform networkmap relations into js links. + * + * @param array $relations Relations. + * @param array $nodes_graph Nodes_graph. + * @param boolean $simulated Simulated. + * + * @return array JS relations. + */ +function networkmap_links_to_js_links( + $relations, + $nodes_graph, + $simulated=false +) { + $return = []; + + if (enterprise_installed() && $simulated === false) { + enterprise_include_once('include/functions_networkmap.php'); + } + + $count = 0; + foreach ($relations as $key => $relation) { + if (($relation['parent_type'] == NODE_MODULE) + && ($relation['child_type'] == NODE_MODULE) + ) { + $id_target_agent = agents_get_agent_id_by_module_id( + $relation['id_parent_source_data'] + ); + $id_source_agent = agents_get_agent_id_by_module_id( + $relation['id_child_source_data'] + ); + $id_target_module = $relation['id_parent_source_data']; + $id_source_module = $relation['id_child_source_data']; + } else if (($relation['parent_type'] == NODE_MODULE) + && ($relation['child_type'] == NODE_AGENT) + ) { + $id_target_agent = agents_get_agent_id_by_module_id( + $relation['id_parent_source_data'] + ); + $id_target_module = $relation['id_parent_source_data']; + $id_source_agent = $relation['id_child_source_data']; + } else if (($relation['parent_type'] == NODE_AGENT) + && ($relation['child_type'] == NODE_MODULE) + ) { + $id_target_agent = $relation['id_parent_source_data']; + $id_source_module = $relation['id_child_source_data']; + $id_source_agent = agents_get_agent_id_by_module_id( + $relation['id_child_source_data'] + ); + } else { + $id_target_agent = $relation['id_parent_source_data']; + $id_source_agent = $relation['id_child_source_data']; + } + + $item = []; + $item['id'] = $count; + $count++; + if (enterprise_installed() && $simulated === false) { + $item['id_db'] = get_relation_id($relation); + } else { + $item['id_db'] = $key; + } + + $item['arrow_start'] = ''; + $item['arrow_end'] = ''; + $item['status_start'] = ''; + $item['status_end'] = ''; + $item['id_module_start'] = 0; + $item['id_agent_start'] = (int) $id_source_agent; + $item['id_module_end'] = 0; + $item['id_agent_end'] = (int) $id_target_agent; + $item['link_color'] = '#999'; + $item['target'] = -1; + $item['source'] = -1; + $item['deleted'] = $relation['deleted']; + + if (enterprise_installed() && $simulated === false) { + $target_and_source = []; + $target_and_source = get_id_target_and_source_in_db($relation); + $item['target_id_db'] = (int) $target_and_source['target']; + $item['source_id_db'] = (int) $target_and_source['source']; + } else { + if (($relation['parent_type'] == NODE_MODULE) && ($relation['child_type'] == NODE_MODULE)) { + $item['target_id_db'] = $id_target_agent; + $item['source_id_db'] = $id_source_agent; + } else if (($relation['parent_type'] == NODE_AGENT) && ($relation['child_type'] == NODE_AGENT)) { + $item['target_id_db'] = (int) $relation['id_parent_source_data']; + $item['source_id_db'] = $id_source_agent; + } else { + $item['target_id_db'] = (int) $relation['id_parent_source_data']; + $item['source_id_db'] = (int) $relation['id_child_source_data']; + } + } + + $item['text_end'] = ''; + $item['text_start'] = ''; + + if ($relation['parent_type'] == 1) { + $item['arrow_end'] = 'module'; + $item['status_end'] = modules_get_agentmodule_status((int) $id_target_module, false, false, null); + $item['id_module_end'] = (int) $id_target_module; + $text_end = modules_get_agentmodule_name((int) $id_target_module); + if (preg_match('/(.+)_ifOperStatus$/', (string) $text_end, $matches)) { + if ($matches[1]) { + // It's ok to safe_output as it inlo goint to be user into the map line + $item['text_end'] = io_safe_output($matches[1]); + } + } + } + + if ($relation['child_type'] == NODE_MODULE) { + $item['arrow_start'] = 'module'; + $item['status_start'] = modules_get_agentmodule_status((int) $id_source_module, false, false, null); + $item['id_module_start'] = (int) $id_source_module; + $text_start = modules_get_agentmodule_name((int) $id_source_module); + if (preg_match('/(.+)_ifOperStatus$/', (string) $text_start, $matches)) { + if ($matches[1]) { + // It's ok to safe_output as it inlo goint to be user into the map line + $item['text_start'] = io_safe_output($matches[1]); + } + } + } + + $agent = 0; + $agent2 = 0; + $control1 = false; + $control2 = false; + + if (($relation['parent_type'] == NODE_MODULE) && ($relation['child_type'] == NODE_MODULE)) { + if (($item['status_start'] == AGENT_MODULE_STATUS_CRITICAL_BAD) || ($item['status_end'] == AGENT_MODULE_STATUS_CRITICAL_BAD)) { + $item['link_color'] = '#FC4444'; + } else if (($item['status_start'] == AGENT_MODULE_STATUS_WARNING) || ($item['status_end'] == AGENT_MODULE_STATUS_WARNING)) { + $item['link_color'] = '#FAD403'; + } + + $agent = agents_get_agent_id_by_module_id( + $relation['id_parent_source_data'] + ); + $agent2 = agents_get_agent_id_by_module_id( + $relation['id_child_source_data'] + ); + foreach ($nodes_graph as $key2 => $node) { + if (isset($node['id_agent'])) { + if ($node['id_agent'] == $agent) { + $agent = $node['id_db']; + $control1 = true; + } + + if ($node['id_agent'] == $agent2) { + $agent2 = $node['id_db']; + $control2 = true; + } + + if ($control1 && $control2) { + break; + } + } + } + } else if ($relation['child_type'] == NODE_MODULE) { + if ($item['status_start'] == AGENT_MODULE_STATUS_CRITICAL_BAD) { + $item['link_color'] = '#FC4444'; + } else if ($item['status_start'] == AGENT_MODULE_STATUS_WARNING) { + $item['link_color'] = '#FAD403'; + } + + $agent2 = agents_get_agent_id_by_module_id( + $relation['id_child_source_data'] + ); + foreach ($nodes_graph as $key2 => $node) { + if (isset($node['id_agent'])) { + if ($node['id_agent'] == $relation['id_parent_source_data']) { + $agent = $node['id_db']; + $control1 = true; + } + + if ($node['id_agent'] == $agent2) { + $agent2 = $node['id_db']; + $control2 = true; + } + + if ($control1 && $control2) { + break; + } + } + } + } else if ($relation['parent_type'] == NODE_MODULE) { + if ($item['status_end'] == AGENT_MODULE_STATUS_CRITICAL_BAD) { + $item['link_color'] = '#FC4444'; + } else if ($item['status_end'] == AGENT_MODULE_STATUS_WARNING) { + $item['link_color'] = '#FAD403'; + } + + $agent = agents_get_agent_id_by_module_id( + $relation['id_parent_source_data'] + ); + foreach ($nodes_graph as $key2 => $node) { + if (isset($node['id_agent'])) { + if ($node['id_agent'] == $agent) { + $agent = $node['id_db']; + $control1 = true; + } + + if ($node['id_agent'] == $relation['id_child_source_data']) { + $agent2 = $node['id_db']; + $control2 = true; + } + + if ($control1 && $control2) { + break; + } + } + } + } else if (($relation['parent_type'] == NODE_PANDORA) + && ($relation['child_type'] == NODE_PANDORA) + ) { + foreach ($nodes_graph as $key2 => $node) { + if ($relation['id_parent'] == $node['id_db']) { + $agent = $node['id_db']; + } + } + + foreach ($nodes_graph as $key2 => $node) { + if ($relation['id_child'] == $node['id_db']) { + $agent2 = $node['id_db']; + } + } + } else if (($relation['parent_type'] == NODE_PANDORA) + || ($relation['child_type'] == NODE_PANDORA) + ) { + if ($relation['parent_type'] == NODE_PANDORA) { + foreach ($nodes_graph as $key2 => $node) { + if ($relation['id_parent'] == $node['id_db']) { + $agent = $node['id_db']; + } else if ($node['id_agent'] == $relation['id_child_source_data']) { + $agent2 = $node['id_db']; + } + } + } else if ($relation['child_type'] == NODE_PANDORA) { + foreach ($nodes_graph as $key2 => $node) { + if ($relation['id_child'] == $node['id_db']) { + $agent2 = $node['id_db']; + } else if ($node['id_agent'] == $relation['id_parent_source_data']) { + $agent = $node['id_db']; + } + } + } + } else { + foreach ($nodes_graph as $key2 => $node) { + if (isset($node['id_agent'])) { + if ($node['id_agent'] == $relation['id_parent_source_data']) { + $agent = $node['id_db']; + } else if ($node['id_agent'] == $relation['id_child_source_data']) { + $agent2 = $node['id_db']; + } + } + } + } + + foreach ($nodes_graph as $node) { + if ($node['id_db'] == $agent) { + $item['target'] = $node['id']; + } else if ($node['id_db'] == $agent2) { + $item['source'] = $node['id']; + } + } + + if ((($item['target'] == -1) || ($item['source'] == -1)) + && $relation['parent_type'] == NODE_MODULE + && $relation['child_type'] == NODE_MODULE + ) { + continue; + } + + $return[] = $item; + } + + return $return; +} + + +function get_status_color_module_networkmap($id_agente_modulo) +{ + $status = modules_get_agentmodule_status($id_agente_modulo); + + // Set node status + switch ($status) { + case 0: + // At the moment the networkmap enterprise does not show the + // alerts. + case AGENT_MODULE_STATUS_NORMAL_ALERT: + $status_color = COL_NORMAL; + // Normal monitor + break; + + case 1: + $status_color = COL_CRITICAL; + // Critical monitor + break; + + case 2: + $status_color = COL_WARNING; + // Warning monitor + break; + + case 4: + $status_color = COL_ALERTFIRED; + // Alert fired + break; + + default: + $status_color = COL_UNKNOWN; + // Unknown monitor + break; + } + + return $status_color; +} + + +function duplicate_networkmap($id) +{ + $return = true; + + $values = db_get_row('tmap', 'id', $id); + unset($values['id']); + $free_name = false; + $values['name'] = io_safe_input(__('Copy of ')).$values['name']; + $count = 1; + while (!$free_name) { + $exist = db_get_row_filter('tmap', ['name' => $values['name']]); + if ($exist === false) { + $free_name = true; + } else { + $values['name'] = $values['name'].io_safe_input(' '.$count); + } + } + + $correct_or_id = db_process_sql_insert('tmap', $values); + if ($correct_or_id === false) { + $return = false; + } else { + if (enterprise_installed()) { + $new_id = $correct_or_id; + duplicate_map_insert_nodes_and_relations($id, $new_id); + } + } + + if ($return) { + return true; + } else { + // Clean DB. + if (enterprise_installed()) { + // Relations + delete_relations($new_id); + + // Nodes + delete_nodes($new_id); + } + + db_process_sql_delete('tmap', ['id' => $new_id]); + + return false; + } +} + + +function clean_duplicate_links($relations) +{ + if (enterprise_installed()) { + enterprise_include_once('include/functions_networkmap.php'); + } + + $segregation_links = []; + $index = 0; + $index2 = 0; + $index3 = 0; + $index4 = 0; + foreach ($relations as $rel) { + if (($rel['parent_type'] == 0) && ($rel['child_type'] == 0)) { + $segregation_links['aa'][$index] = $rel; + $index++; + } else if (($rel['parent_type'] == 1) && ($rel['child_type'] == 1)) { + $segregation_links['mm'][$index2] = $rel; + $index2++; + } else if (($rel['parent_type'] == 3) && ($rel['child_type'] == 3)) { + $segregation_links['ff'][$index4] = $rel; + $index4++; + } else { + $segregation_links['am'][$index3] = $rel; + $index3++; + } + } + + $final_links = []; + + // ---------------------------------------------------------------- + // --------------------- Clean duplicate links -------------------- + // ---------------------------------------------------------------- + $duplicated = false; + $index_to_del = 0; + $index = 0; + if (isset($segregation_links['aa']) === true + && is_array($segregation_links['aa']) === true + ) { + foreach ($segregation_links['aa'] as $link) { + foreach ($segregation_links['aa'] as $link2) { + if ($link['id_parent'] == $link2['id_child'] + && $link['id_child'] == $link2['id_parent'] + ) { + if (enterprise_installed()) { + delete_link($segregation_links['aa'][$index_to_del]); + } + + unset($segregation_links['aa'][$index_to_del]); + } + + $index_to_del++; + } + + $final_links['aa'][$index] = $link; + $index++; + + $duplicated = false; + $index_to_del = 0; + } + } + + $duplicated = false; + $index_to_del = 0; + $index2 = 0; + if (isset($segregation_links['mm']) === true + && is_array($segregation_links['mm']) === true + ) { + foreach ($segregation_links['mm'] as $link) { + foreach ($segregation_links['mm'] as $link2) { + if ($link['id_parent'] == $link2['id_child'] + && $link['id_child'] == $link2['id_parent'] + ) { + if (enterprise_installed()) { + delete_link($segregation_links['mm'][$index_to_del]); + } + } + + $index_to_del++; + } + + $final_links['mm'][$index2] = $link; + $index2++; + + $duplicated = false; + $index_to_del = 0; + } + } + + $duplicated = false; + $index_to_del = 0; + $index3 = 0; + + if (isset($segregation_links['ff']) === true + && is_array($segregation_links['ff']) === true + ) { + foreach ($segregation_links['ff'] as $link) { + foreach ($segregation_links['ff'] as $link2) { + if ($link['id_parent'] == $link2['id_child'] + && $link['id_child'] == $link2['id_parent'] + ) { + if (enterprise_installed()) { + delete_link($segregation_links['ff'][$index_to_del]); + } + + unset($segregation_links['ff'][$index_to_del]); + } + + $index_to_del++; + } + + $final_links['ff'][$index3] = $link; + $index3++; + + $duplicated = false; + $index_to_del = 0; + } + } + + $final_links['am'] = $segregation_links['am']; + + /* + ---------------------------------------------------------------- + ----------------- AA, AM and MM links management --------------- + ------------------ Priority: ----------------------------------- + -------------------- 1 -> MM (module - module) ----------------- + -------------------- 2 -> AM (agent - module) ------------------ + -------------------- 3 -> AA (agent - agent) ------------------- + ---------------------------------------------------------------- + */ + + $final_links2 = []; + $index = 0; + $l3_link = []; + $agent1 = 0; + $agent2 = 0; + + if (isset($final_links['mm']) === true + && is_array($final_links['mm']) === true + ) { + foreach ($final_links['mm'] as $rel_mm) { + $module_parent = $rel_mm['id_parent_source_data']; + $module_children = $rel_mm['id_child_source_data']; + $agent1 = (int) agents_get_agent_id_by_module_id($module_parent); + $agent2 = (int) agents_get_agent_id_by_module_id($module_children); + foreach ($final_links['aa'] as $key => $rel_aa) { + $l3_link = $rel_aa; + $id_p_source_data = (int) $rel_aa['id_parent_source_data']; + $id_c_source_data = (int) $rel_aa['id_child_source_data']; + if ((($id_p_source_data == $agent1) + && ($id_c_source_data == $agent2)) + || (($id_p_source_data == $agent2) + && ($id_c_source_data == $agent1)) + ) { + if (enterprise_installed()) { + delete_link($final_links['aa'][$key]); + } + + unset($final_links['aa'][$key]); + } + } + } + } + + $final_links2['aa'] = $final_links['aa']; + $final_links2['mm'] = $final_links['mm']; + $final_links2['am'] = $final_links['am']; + $final_links2['ff'] = $final_links['ff']; + + $same_m = []; + $index = 0; + if (isset($final_links2['am']) === true + && is_array($final_links2['am']) === true + ) { + foreach ($final_links2['am'] as $rel_am) { + foreach ($final_links2['am'] as $rel_am2) { + if (($rel_am['id_child_source_data'] == $rel_am2['id_child_source_data']) + && ($rel_am['id_parent_source_data'] != $rel_am2['id_parent_source_data']) + ) { + $same_m[$index]['rel'] = $rel_am2; + $same_m[$index]['agent_parent'] = $rel_am['id_parent_source_data']; + $index++; + } + } + } + } + + $final_links3 = []; + $index = 0; + $l3_link = []; + $have_l3 = false; + if (isset($final_links2['aa']) === true + && is_array($final_links2['aa']) === true + ) { + foreach ($final_links2['aa'] as $key => $rel_aa) { + $l3_link = $rel_aa; + foreach ($same_m as $rel_am) { + if ((($rel_aa['id_parent_source_data'] == $rel_am['parent']['id_parent_source_data']) + && ($rel_aa['id_child_source_data'] == $rel_am['rel']['id_parent_source_data'])) + || (($rel_aa['id_child_source_data'] == $rel_am['parent']['id_parent_source_data']) + && ($rel_aa['id_parent_source_data'] == $rel_am['rel']['id_parent_source_data'])) + ) { + if (enterprise_installed()) { + delete_link($final_links2['aa'][$key]); + } + + unset($final_links2['aa'][$key]); + } + } + } + } + + $final_links3['aa'] = $final_links2['aa']; + $final_links3['mm'] = $segregation_links['mm']; + $final_links3['am'] = $segregation_links['am']; + $final_links3['ff'] = $final_links2['ff']; + + $cleaned_links = []; + if (isset($final_links3['aa']) === true + && is_array($final_links3['aa']) === true + ) { + foreach ($final_links3['aa'] as $link) { + $cleaned_links[] = $link; + } + } + + if (isset($final_links3['am']) === true + && is_array($final_links3['am']) === true + ) { + foreach ($final_links3['am'] as $link) { + $cleaned_links[] = $link; + } + } + + if (isset($final_links3['mm']) === true + && is_array($final_links3['mm']) === true + ) { + foreach ($final_links3['mm'] as $link) { + $cleaned_links[] = $link; + } + } + + if (isset($final_links3['ff']) === true + && is_array($final_links3['ff']) === true + ) { + foreach ($final_links3['ff'] as $link) { + $cleaned_links[] = $link; + } + } + + return $cleaned_links; +} + + +function migrate_older_open_maps($id) +{ + global $config; + + $old_networkmap = db_get_row_filter( + 'tnetwork_map', + ['id_networkmap' => $id] + ); + + $map_values = []; + $map_values['id_group'] = $old_networkmap['id_group']; + $map_values['id_user'] = $old_networkmap['id_user']; + $map_values['type'] = 0; + $map_values['subtype'] = 0; + $map_values['name'] = $old_networkmap['name']; + + $new_map_filter = []; + $new_map_filter['dont_show_subgroups'] = $old_networkmap['dont_show_subgroups']; + $new_map_filter['node_radius'] = 40; + $new_map_filter['id_migrate_map'] = $id; + $map_values['filter'] = json_encode($new_map_filter); + + $map_values['description'] = 'Mapa open migrado'; + $map_values['width'] = 4000; + $map_values['height'] = 4000; + $map_values['center_x'] = 2000; + $map_values['center_y'] = 2000; + $map_values['background'] = ''; + $map_values['background_options'] = 0; + $map_values['source_period'] = 60; + $map_values['source'] = 0; + $map_values['source_data'] = $old_networkmap['id_group']; + if ($old_networkmap['type'] == 'radial_dinamic') { + $map_values['generation_method'] = 6; + } else { + $map_values['generation_method'] = 4; + } + + $map_values['generated'] = 0; + + $id_new_map = db_process_sql_insert('tmap', $map_values); + + if (!$id_new_map) { + return false; + } + + return true; +} + + +/** + * Load cluetip required files and JS. + * + * @return void + */ +function networkmap_load_cluetip() +{ + ui_require_css_file('cluetip', 'include/styles/js/'); + + ?> +
    '
    +            );
    +        break;
    +    }
    +
         return sprintf(
             "
                 %s
                 
    @@ -990,10 +1009,12 @@ function notifications_print_dropdown_element($message_info)

    ", + $action.';click_on_notification_toast(event)', $message_info['id_mensaje'], messages_get_url($message_info['id_mensaje']), + $target, html_print_image('images/'.$message_info['icon'], true), - $message_info['subject'], - str_replace([io_safe_input('
    ')], ' ', $message_info['mensaje']) + io_safe_output($message_info['subject']), + $body_preview ); } diff --git a/pandora_console/include/functions_pandora_networkmap.php b/pandora_console/include/functions_pandora_networkmap.php index 9870172de4..cad7fc7edf 100644 --- a/pandora_console/include/functions_pandora_networkmap.php +++ b/pandora_console/include/functions_pandora_networkmap.php @@ -1,2189 +1,29 @@ $id]); - - return $result; -} - - -function networkmap_delete_nodes($id_map) -{ - return db_process_sql_delete('titem', ['id_map' => $id_map]); -} - - -function networkmap_process_networkmap($id=0) -{ - global $config; - - include_once 'include/functions_os.php'; - - $numNodes = (int) db_get_num_rows( - ' - SELECT * - FROM titem - WHERE id_map = '.$id.' and deleted = 0' - ); - - $networkmap = db_get_row_filter( - 'tmap', - ['id' => $id] - ); - $map_filter = json_decode($networkmap['filter'], true); - - $pure = (int) get_parameter('pure', 0); - - switch ($networkmap['generation_method']) { - case 0: - $filter = 'circo'; - $layout = 'circular'; - break; - - case 1: - $filter = 'dot'; - $layout = 'flat'; - break; - - case 2: - $filter = 'twopi'; - $layout = 'radial'; - break; - - case 3: - $filter = 'neato'; - $layout = 'spring1'; - break; - - case 4: - $filter = 'fdp'; - $layout = 'spring2'; - break; - } - - $simple = 0; - $font_size = 12; - $nooverlap = false; - $zoom = 1; - $ranksep = 0.5; - $center = 0; - $regen = 1; - $show_snmp_modules = false; - $dont_show_subgroups = false; - - $id_group = $networkmap['id_group']; - $ip_mask = ''; - switch ($networkmap['source']) { - case 1: - $recon_task = db_get_row_filter( - 'trecon_task', - ['id_rt' => $networkmap['source_data']] - ); - - $ip_mask = $recon_task['subnet']; - break; - - case 2: - $ip_mask = $networkmap['source_data']; - break; - } - - $nodes_and_relations = []; - - if (enterprise_installed() && ($numNodes > 0)) { - $nodes_and_relations = get_structure_nodes($id); - } else { - if ($map_filter['empty_map']) { - // Open Graph - $graph = networkmap_open_graph( - $layout, - $nooverlap, - $pure, - $zoom, - $ranksep, - $font_size, - null - ); - $graph .= networkmap_create_pandora_node(get_product_name(), $font_size, $simple); - $graph .= networkmap_close_graph(); - - switch (PHP_OS) { - case 'WIN32': - case 'WINNT': - case 'Windows': - $filename_dot = sys_get_temp_dir()."\\networkmap_".$filter; - break; - - default: - $filename_dot = sys_get_temp_dir().'/networkmap_'.$filter; - break; - } - - if ($simple) { - $filename_dot .= '_simple'; - } - - if ($nooverlap) { - $filename_dot .= '_nooverlap'; - } - - $filename_dot .= '_'.$id.'.dot'; - - file_put_contents($filename_dot, $graph); - - switch (PHP_OS) { - case 'WIN32': - case 'WINNT': - case 'Windows': - $filename_plain = sys_get_temp_dir().'\\plain.txt'; - - $cmd = io_safe_output( - $config['graphviz_bin_dir']."\\$filter.exe -Tplain -o ".$filename_plain.' '.$filename_dot - ); - break; - - default: - $filename_plain = sys_get_temp_dir().'/plain.txt'; - - $cmd = "$filter -Tplain -o ".$filename_plain.' '.$filename_dot; - break; - } - - system($cmd); - - unlink($filename_dot); - - $nodes = networkmap_loadfile( - $id, - $filename_plain, - $relation_nodes, - $graph - ); - - unlink($filename_plain); - - // Set the position of modules - foreach ($nodes as $key => $node) { - if ($node['type'] == 'module') { - // Search the agent of this module for to get the - // position - foreach ($nodes as $key2 => $node2) { - if ($node2['id_agent'] != 0 && $node2['type'] == 'agent') { - if ($node2['id_agent'] == $node['id_agent']) { - $nodes[$key]['coords'][0] = ($nodes[$key2]['coords'][0] + $node['height'] / 2); - $nodes[$key]['coords'][1] = ($nodes[$key2]['coords'][1] + $node['width'] / 2); - } - } - } - } - } - - $nodes_and_relations['nodes'] = []; - $index = 0; - foreach ($nodes as $key => $node) { - $nodes_and_relations['nodes'][$index]['id'] = $node['id']; - $nodes_and_relations['nodes'][$index]['id_map'] = $id; - - $nodes_and_relations['nodes'][$index]['x'] = (int) $node['coords'][0]; - $nodes_and_relations['nodes'][$index]['y'] = (int) $node['coords'][1]; - - if (($node['type'] == 'agent') || ($node['type'] == '')) { - $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent']; - $nodes_and_relations['nodes'][$index]['type'] = 0; - } else { - $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_module']; - $nodes_and_relations['nodes'][$index]['id_agent'] = $node['id_agent']; - $nodes_and_relations['nodes'][$index]['type'] = 1; - } - - $style = []; - $style['shape'] = 'circle'; - $style['image'] = $node['image']; - $style['width'] = $node['width']; - $style['height'] = $node['height']; - $style['label'] = $node['text']; - $style['id_networkmap'] = $node['networkmap']; - $nodes_and_relations['nodes'][$index]['style'] = json_encode($style); - - $index++; - } - - $nodes_and_relations['relations'] = []; - - if (enterprise_installed()) { - enterprise_include_once('include/functions_pandora_networkmap.php'); - save_generate_nodes($id, $nodes_and_relations); - } - } else { - // Generate dot file - $graph = networkmap_generate_dot( - get_product_name(), - $id_group, - $simple, - $font_size, - $layout, - $nooverlap, - $zoom, - $ranksep, - $center, - $regen, - $pure, - $id, - $show_snmp_modules, - false, - // cut_names - true, - // relative - '', - $ip_mask, - $dont_show_subgroups, - false, - null, - $old_mode, - $map_filter - ); - - switch (PHP_OS) { - case 'WIN32': - case 'WINNT': - case 'Windows': - $filename_dot = sys_get_temp_dir()."\\networkmap_".$filter; - break; - - default: - $filename_dot = sys_get_temp_dir().'/networkmap_'.$filter; - break; - } - - if ($simple) { - $filename_dot .= '_simple'; - } - - if ($nooverlap) { - $filename_dot .= '_nooverlap'; - } - - $filename_dot .= '_'.$id.'.dot'; - - file_put_contents($filename_dot, $graph); - - switch (PHP_OS) { - case 'WIN32': - case 'WINNT': - case 'Windows': - $filename_plain = sys_get_temp_dir().'\\plain.txt'; - - $cmd = io_safe_output( - $config['graphviz_bin_dir']."\\$filter.exe -Tplain -o ".$filename_plain.' '.$filename_dot - ); - break; - - default: - $filename_plain = sys_get_temp_dir().'/plain.txt'; - - $cmd = "$filter -Tplain -o ".$filename_plain.' '.$filename_dot; - break; - } - - system($cmd); - - unlink($filename_dot); - - $nodes = networkmap_loadfile( - $id, - $filename_plain, - $relation_nodes, - $graph - ); - - unlink($filename_plain); - - // Set the position of modules - foreach ($nodes as $key => $node) { - if ($node['type'] == 'module') { - // Search the agent of this module for to get the - // position - foreach ($nodes as $key2 => $node2) { - if ($node2['id_agent'] != 0 && $node2['type'] == 'agent') { - if ($node2['id_agent'] == $node['id_agent']) { - $nodes[$key]['coords'][0] = ($nodes[$key2]['coords'][0] + $node['height'] / 2); - $nodes[$key]['coords'][1] = ($nodes[$key2]['coords'][1] + $node['width'] / 2); - } - } - } - } - } - - $nodes_and_relations['nodes'] = []; - $index = 0; - $node_center = []; - foreach ($nodes as $key => $node) { - $nodes_and_relations['nodes'][$index]['id'] = $node['id']; - $nodes_and_relations['nodes'][$index]['id_map'] = $id; - - $children_count = 0; - foreach ($relation_nodes as $relation) { - if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { - if ($nodes[$relation['id_parent']]['id_agent'] == $node['id_agent']) { - $children_count++; - } - } else if ($relation['parent_type'] == 'module') { - if ($nodes[$relation['id_parent']]['id_module'] == $node['id_module']) { - $children_count++; - } - } - } - - if (empty($node_center) || $node_center['counter'] < $children_count) { - $node_center['x'] = (int) $node['coords'][0]; - $node_center['y'] = (int) $node['coords'][1]; - $node_center['counter'] = $children_count; - } - - $nodes_and_relations['nodes'][$index]['x'] = (int) $node['coords'][0]; - $nodes_and_relations['nodes'][$index]['y'] = (int) $node['coords'][1]; - - if (($node['type'] == 'agent') || ($node['type'] == '')) { - $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent']; - $nodes_and_relations['nodes'][$index]['type'] = 0; - } else { - $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_module']; - $nodes_and_relations['nodes'][$index]['id_agent'] = $node['id_agent']; - $nodes_and_relations['nodes'][$index]['type'] = 1; - } - - $style = []; - $style['shape'] = 'circle'; - $style['image'] = $node['image']; - $style['width'] = $node['width']; - $style['height'] = $node['height']; - $style['label'] = $node['text']; - $nodes_and_relations['nodes'][$index]['style'] = json_encode($style); - - $index++; - } - - $nodes_and_relations['relations'] = []; - $index = 0; - foreach ($relation_nodes as $relation) { - $nodes_and_relations['relations'][$index]['id_map'] = $id; - - if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_agent']; - $nodes_and_relations['relations'][$index]['parent_type'] = 0; - } else if ($relation['parent_type'] == 'module') { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_module']; - $nodes_and_relations['relations'][$index]['parent_type'] = 1; - } else { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; - $nodes_and_relations['relations'][$index]['parent_type'] = 3; - } - - if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_agent']; - $nodes_and_relations['relations'][$index]['child_type'] = 0; - } else if ($relation['child_type'] == 'module') { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_module']; - $nodes_and_relations['relations'][$index]['child_type'] = 1; - } else { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; - $nodes_and_relations['relations'][$index]['child_type'] = 3; - } - - $index++; - } - - if (enterprise_installed()) { - enterprise_include_once('include/functions_pandora_networkmap.php'); - save_generate_nodes($id, $nodes_and_relations); - } - - $pandorafms_node = $nodes_and_relations['nodes'][0]; - $center = [ - 'x' => $node_center['x'], - 'y' => $node_center['y'], - ]; - - $networkmap['center_x'] = $center['x']; - $networkmap['center_y'] = $center['y']; - db_process_sql_update( - 'tmap', - [ - 'center_x' => $networkmap['center_x'], - 'center_y' => $networkmap['center_y'], - ], - ['id' => $id] - ); - } - } - - return $nodes_and_relations; -} - - -function get_networkmaps($id) -{ - $groups = array_keys(users_get_groups(null, 'IW')); - - $filter = []; - $filter['id_group'] = $groups; - $filter['id'] = '<>'.$id; - $networkmaps = db_get_all_rows_filter('tmap', $filter); - if ($networkmaps === false) { - $networkmaps = []; - } - - $return = []; - $return[0] = __('None'); - foreach ($networkmaps as $networkmap) { - $return[$networkmap['id']] = $networkmap['name']; - } - - return $return; -} - - -function networkmap_db_node_to_js_node($node, &$count, &$count_item_holding_area) -{ - global $config; - - $networkmap = db_get_row('tmap', 'id', $node['id_map']); - - $networkmap['filter'] = json_decode($networkmap['filter'], true); - - // Hardcoded - $networkmap['filter']['holding_area'] = [ - 500, - 500, - ]; - - // 40 = DEFAULT NODE RADIUS - // 30 = for to align - $holding_area_max_y = ($networkmap['height'] + 30 + 40 * 2 - $networkmap['filter']['holding_area'][1] + 10 * 40); - - $item = []; - $item['id'] = $count; - - if (enterprise_installed()) { - enterprise_include_once('include/functions_pandora_networkmap.php'); - $item['id_db'] = $node['id_in_db']; - } else { - $item['id_db'] = (int) $node['id']; - } - - if ((int) $node['type'] == 0) { - $item['type'] = 0; - $item['id_agent'] = (int) $node['source_data']; - $item['id_module'] = ''; - } else if ((int) $node['type'] == 1) { - $item['type'] = 1; - $item['id_agent'] = (int) $node['style']['id_agent']; - $item['id_module'] = (int) $node['source_data']; - } else { - $item['type'] = 3; - } - - $item['fixed'] = true; - $item['x'] = (int) $node['x']; - $item['y'] = (int) $node['y']; - $item['px'] = (int) $node['x']; - $item['py'] = (int) $node['y']; - $item['z'] = (int) $node['z']; - $item['state'] = $node['state']; - $item['deleted'] = $node['deleted']; - if ($item['state'] == 'holding_area') { - // 40 = DEFAULT NODE RADIUS - // 30 = for to align - $holding_area_x = ($networkmap['width'] + 30 + 40 * 2 - $networkmap['filter']['holding_area'][0] + ($count_item_holding_area % 11) * 40); - $holding_area_y = ($networkmap['height'] + 30 + 40 * 2 - $networkmap['filter']['holding_area'][1] + (int) (($count_item_holding_area / 11)) * 40); - - if ($holding_area_max_y <= $holding_area_y) { - $holding_area_y = $holding_area_max_y; - } - - $item['x'] = $holding_area_x; - $item['y'] = $holding_area_y; - - // Increment for the next node in holding area - $count_item_holding_area++; - } - - $item['image_url'] = ''; - $item['image_width'] = 0; - $item['image_height'] = 0; - if (!empty($node['style']['image'])) { - $item['image_url'] = html_print_image( - $node['style']['image'], - true, - false, - true - ); - $image_size = getimagesize( - $config['homedir'].'/'.$node['style']['image'] - ); - $item['image_width'] = (int) $image_size[0]; - $item['image_height'] = (int) $image_size[1]; - } - - $item['raw_text'] = $node['style']['label']; - $item['text'] = io_safe_output($node['style']['label']); - $item['shape'] = $node['style']['shape']; - switch ($node['type']) { - case 0: - $color = get_status_color_networkmap($node['source_data']); - break; - - default: - // Old code - if ($node['source_data'] == -1) { - $color = '#364D1F'; - } else if ($node['source_data'] == -2) { - $color = '#364D1F'; - } else { - $color = get_status_color_networkmap($node['source_data']); - } - break; - } - - $item['color'] = $color; - $item['map_id'] = 0; - if (isset($node['id_map'])) { - $item['map_id'] = $node['id_map']; - } - - if (!isset($node['style']['id_networkmap']) || $node['style']['id_networkmap'] == '' || $node['style']['id_networkmap'] == 0) { - $item['networkmap_id'] = 0; - } else { - $item['networkmap_id'] = $node['style']['id_networkmap']; - } - - $count++; - - return $item; -} - - -function get_status_color_networkmap($id, $color=true) -{ - $status = agents_get_status($id); - - if (!$color) { - return $status; - } - - // Set node status - switch ($status) { - case 0: - $status_color = COL_NORMAL; - // Normal monitor - break; - - case 1: - $status_color = COL_CRITICAL; - // Critical monitor - break; - - case 2: - $status_color = COL_WARNING; - // Warning monitor - break; - - case 4: - $status_color = COL_ALERTFIRED; - // Alert fired - break; - - default: - $status_color = COL_UNKNOWN; - // Unknown monitor - break; - } - - return $status_color; -} - - -function networkmap_clean_relations_for_js(&$relations) -{ - do { - $cleaned = true; - - foreach ($relations as $key => $relation) { - if ($relation['id_parent_source_data'] == $relation['id_child_source_data']) { - if (($relation['child_type'] != 3) && $relation['parent_type'] != 3) { - $cleaned = false; - - if ($relation['parent_type'] == 1) { - $to_find = $relation['id_parent_source_data']; - $to_replace = $relation['id_child_source_data']; - } else if ($relation['child_type'] == 1) { - $to_find = $relation['id_child_source_data']; - $to_replace = $relation['id_parent_source_data']; - } - - // Replace and erase the links - foreach ($relations as $key2 => $relation2) { - if ($relation2['id_parent_source_data'] == $to_find) { - $relations[$key2]['id_parent_source_data'] = $to_replace; - } else if ($relation2['id_child_source_data'] == $to_find) { - $relations[$key2]['id_child_source_data'] = $to_replace; - } - } - - unset($relations[$key]); - - break; - } - } - } - } while (!$cleaned); -} - - -function networkmap_links_to_js_links($relations, $nodes_graph) -{ - $return = []; - - if (enterprise_installed()) { - enterprise_include_once('include/functions_pandora_networkmap.php'); - } - - $count = 0; - foreach ($relations as $key => $relation) { - if (($relation['parent_type'] == 1) && ($relation['child_type'] == 1)) { - $id_target_agent = agents_get_agent_id_by_module_id($relation['id_parent_source_data']); - $id_source_agent = agents_get_agent_id_by_module_id($relation['id_child_source_data']); - $id_target_module = $relation['id_parent_source_data']; - $id_source_module = $relation['id_child_source_data']; - } else if (($relation['parent_type'] == 1) && ($relation['child_type'] == 0)) { - $id_target_agent = agents_get_agent_id_by_module_id($relation['id_parent_source_data']); - $id_target_module = $relation['id_parent_source_data']; - $id_source_agent = $relation['id_child_source_data']; - } else if (($relation['parent_type'] == 0) && ($relation['child_type'] == 1)) { - $id_target_agent = $relation['id_parent_source_data']; - $id_source_module = $relation['id_child_source_data']; - $id_source_agent = agents_get_agent_id_by_module_id($relation['id_child_source_data']); - } else { - $id_target_agent = $relation['id_parent_source_data']; - $id_source_agent = $relation['id_child_source_data']; - } - - $item = []; - $item['id'] = $count; - $count++; - if (enterprise_installed()) { - $item['id_db'] = get_relation_id($relation); - } else { - $item['id_db'] = $key; - } - - $item['arrow_start'] = ''; - $item['arrow_end'] = ''; - $item['status_start'] = ''; - $item['status_end'] = ''; - $item['id_module_start'] = 0; - $item['id_agent_start'] = (int) $id_source_agent; - $item['id_module_end'] = 0; - $item['id_agent_end'] = (int) $id_target_agent; - $item['link_color'] = '#999'; - $item['target'] = -1; - $item['source'] = -1; - $item['deleted'] = $relation['deleted']; - - if (enterprise_installed()) { - $target_and_source = []; - $target_and_source = get_id_target_and_source_in_db($relation); - $item['target_id_db'] = (int) $target_and_source['target']; - $item['source_id_db'] = (int) $target_and_source['source']; - } else { - if (($relation['parent_type'] == 1) && ($relation['child_type'] == 1)) { - $item['target_id_db'] = $id_target_agent; - $item['source_id_db'] = $id_source_agent; - } else if (($relation['parent_type'] == 0) && ($relation['child_type'] == 0)) { - $item['target_id_db'] = (int) $relation['id_parent_source_data']; - $item['source_id_db'] = $id_source_agent; - } else { - $item['target_id_db'] = (int) $relation['id_parent_source_data']; - $item['source_id_db'] = (int) $relation['id_child_source_data']; - } - } - - $item['text_end'] = ''; - $item['text_start'] = ''; - - if ($relation['parent_type'] == 1) { - $item['arrow_end'] = 'module'; - $item['status_end'] = modules_get_agentmodule_status((int) $id_target_module, false, false, null); - $item['id_module_end'] = (int) $id_target_module; - $text_end = modules_get_agentmodule_name((int) $id_target_module); - if (preg_match('/(.+)_ifOperStatus$/', (string) $text_end, $matches)) { - if ($matches[1]) { - // It's ok to safe_output as it inlo goint to be user into the map line - $item['text_end'] = io_safe_output($matches[1]); - } - } - } - - if ($relation['child_type'] == 1) { - $item['arrow_start'] = 'module'; - $item['status_start'] = modules_get_agentmodule_status((int) $id_source_module, false, false, null); - $item['id_module_start'] = (int) $id_source_module; - $text_start = modules_get_agentmodule_name((int) $id_source_module); - if (preg_match('/(.+)_ifOperStatus$/', (string) $text_start, $matches)) { - if ($matches[1]) { - // It's ok to safe_output as it inlo goint to be user into the map line - $item['text_start'] = io_safe_output($matches[1]); - } - } - } - - $agent = 0; - $agent2 = 0; - - if (($relation['parent_type'] == 1) && ($relation['child_type'] == 1)) { - $mod1_status = db_get_value_filter('estado', 'tagente_estado', ['id_agente_modulo' => $relation['id_parent_source_data']]); - $mod2_status = db_get_value_filter('estado', 'tagente_estado', ['id_agente_modulo' => $relation['id_child_source_data']]); - - if (($mod1_status == AGENT_MODULE_STATUS_CRITICAL_BAD) || ($mod2_status == AGENT_MODULE_STATUS_CRITICAL_BAD)) { - $item['link_color'] = '#FC4444'; - } else if (($mod1_status == AGENT_MODULE_STATUS_WARNING) || ($mod2_status == AGENT_MODULE_STATUS_WARNING)) { - $item['link_color'] = '#FAD403'; - } - - $agent = agents_get_agent_id_by_module_id($relation['id_parent_source_data']); - $agent2 = agents_get_agent_id_by_module_id($relation['id_child_source_data']); - foreach ($nodes_graph as $key2 => $node) { - if (isset($node['id_agent'])) { - if ($node['id_agent'] == $agent) { - $agent = $node['id_db']; - } else if ($node['id_agent'] == $agent2) { - $agent2 = $node['id_db']; - } - } - } - } else if ($relation['child_type'] == 1) { - $mod1_status = db_get_value_filter('estado', 'tagente_estado', ['id_agente_modulo' => $relation['id_child_source_data']]); - - if ($mod1_status == AGENT_MODULE_STATUS_CRITICAL_BAD) { - $item['link_color'] = '#FC4444'; - } else if ($mod1_status == AGENT_MODULE_STATUS_WARNING) { - $item['link_color'] = '#FAD403'; - } - - $agent2 = agents_get_agent_id_by_module_id($relation['id_child_source_data']); - foreach ($nodes_graph as $key2 => $node) { - if (isset($node['id_agent'])) { - if ($node['id_agent'] == $relation['id_parent_source_data']) { - $agent = $node['id_db']; - } else if ($node['id_agent'] == $agent2) { - $agent2 = $node['id_db']; - } - } - } - } else if ($relation['parent_type'] == 1) { - $mod1_status = db_get_value_filter('estado', 'tagente_estado', ['id_agente_modulo' => $relation['id_parent_source_data']]); - - if ($mod1_status == AGENT_MODULE_STATUS_CRITICAL_BAD) { - $item['link_color'] = '#FC4444'; - } else if ($mod1_status == AGENT_MODULE_STATUS_WARNING) { - $item['link_color'] = '#FAD403'; - } - - $agent = agents_get_agent_id_by_module_id($relation['id_parent_source_data']); - - foreach ($nodes_graph as $key2 => $node) { - if (isset($node['id_agent'])) { - if ($node['id_agent'] == $agent) { - $agent = $node['id_db']; - } else if ($node['id_agent'] == $relation['id_child_source_data']) { - $agent2 = $node['id_db']; - } - } - } - } else if (($relation['parent_type'] == 3) && ($relation['child_type'] == 3)) { - foreach ($nodes_graph as $key2 => $node) { - if ($relation['id_parent'] == $node['id_db']) { - $agent = $node['id_db']; - } - } - - foreach ($nodes_graph as $key2 => $node) { - if ($relation['id_child'] == $node['id_db']) { - $agent2 = $node['id_db']; - } - } - } else if (($relation['parent_type'] == 3) || ($relation['child_type'] == 3)) { - if ($relation['parent_type'] == 3) { - foreach ($nodes_graph as $key2 => $node) { - if ($relation['id_parent'] == $node['id_db']) { - $agent = $node['id_db']; - } else if ($node['id_agent'] == $relation['id_child_source_data']) { - $agent2 = $node['id_db']; - } - } - } else if ($relation['child_type'] == 3) { - foreach ($nodes_graph as $key2 => $node) { - if ($relation['id_child'] == $node['id_db']) { - $agent2 = $node['id_db']; - } else if ($node['id_agent'] == $relation['id_parent_source_data']) { - $agent = $node['id_db']; - } - } - } - } else { - foreach ($nodes_graph as $key2 => $node) { - if (isset($node['id_agent'])) { - if ($node['id_agent'] == $relation['id_parent_source_data']) { - $agent = $node['id_db']; - } else if ($node['id_agent'] == $relation['id_child_source_data']) { - $agent2 = $node['id_db']; - } - } - } - } - - foreach ($nodes_graph as $node) { - if ($node['id_db'] == $agent) { - $item['target'] = $node['id']; - } else if ($node['id_db'] == $agent2) { - $item['source'] = $node['id']; - } - } - - if ((($item['target'] == -1) || ($item['source'] == -1)) && $relation['parent_type'] == 1 && $relation['child_type'] == 1) { - continue; - } - - $return[] = $item; - } - - return $return; -} - - -function networkmap_write_js_array($id, $nodes_and_relations=[], $map_dash_details=[]) -{ - global $config; - - db_clean_cache(); - - $ent_installed = (int) enterprise_installed(); - - $networkmap = db_get_row('tmap', 'id', $id); - - $networkmap['filter'] = json_decode($networkmap['filter'], true); - - // Hardcoded - $networkmap['filter']['holding_area'] = [ - 500, - 500, - ]; - - echo "\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - echo "// VARS FROM THE DB\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - echo "\n"; - echo "var url_background_grid = '".ui_get_full_url( - 'images/background_grid.png' - )."'\n"; - echo 'var networkmap_id = '.$id.";\n"; - - if (!empty($map_dash_details)) { - echo 'var x_offs = '.$map_dash_details['x_offs'].";\n"; - echo 'var y_offs = '.$map_dash_details['y_offs'].";\n"; - echo 'var z_dash = '.$map_dash_details['z_dash'].";\n"; - } else { - echo "var x_offs = null;\n"; - echo "var y_offs = null;\n"; - echo "var z_dash = null;\n"; - } - - echo 'var networkmap_refresh_time = 1000 * '.$networkmap['source_period'].";\n"; - echo 'var networkmap_center = [ '.$networkmap['center_x'].', '.$networkmap['center_y']."];\n"; - echo 'var networkmap_dimensions = [ '.$networkmap['width'].', '.$networkmap['height']."];\n"; - - echo 'var enterprise_installed = '.$ent_installed.";\n"; - - echo 'var node_radius = '.$networkmap['filter']['node_radius'].";\n"; - - echo 'var networkmap_holding_area_dimensions = '.json_encode($networkmap['filter']['holding_area']).";\n"; - - echo "var networkmap = {'nodes': [], 'links': []};\n"; - - $nodes = $nodes_and_relations['nodes']; - - if (empty($nodes)) { - $nodes = []; - } - - $count_item_holding_area = 0; - $count = 0; - $nodes_graph = []; - - foreach ($nodes as $key => $node) { - $style = json_decode($node['style'], true); - $node['style'] = json_decode($node['style'], true); - - // Only agents can be show - if (isset($node['type'])) { - if ($node['type'] == 1) { - continue; - } - } else { - $node['type'] = ''; - } - - $item = networkmap_db_node_to_js_node( - $node, - $count, - $count_item_holding_area - ); - if ($item['deleted']) { - continue; - } - - echo 'networkmap.nodes.push('.json_encode($item).");\n"; - $nodes_graph[$item['id']] = $item; - } - - $relations = $nodes_and_relations['relations']; - - if ($relations === false) { - $relations = []; - } - - // Clean the relations and transform the module relations into - // interfaces - networkmap_clean_relations_for_js($relations); - - $links_js = networkmap_links_to_js_links($relations, $nodes_graph); - - $array_aux = []; - foreach ($links_js as $link_js) { - if ($link_js['deleted']) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['target'] == -1) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['source'] == -1) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['target'] == $link_js['source']) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['arrow_start'] == 'module' && $link_js['arrow_end'] == 'module') { - echo 'networkmap.links.push('.json_encode($link_js).");\n"; - $array_aux[$link_js['id_agent_start']] = 1; - unset($links_js[$link_js['id']]); - } - } - - foreach ($links_js as $link_js) { - if (($link_js['id_agent_end'] === 0) && $array_aux[$link_js['id_agent_start']] === 1) { - continue; - } else { - echo 'networkmap.links.push('.json_encode($link_js).");\n"; - } - } - - echo "\n"; - echo "\n"; - - echo "////////////////////////////////////////////////////////////////////\n"; - echo "// INTERFACE STATUS COLORS\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - - $module_color_status = []; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_NORMAL, - 'color' => COL_NORMAL, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_CRITICAL_BAD, - 'color' => COL_CRITICAL, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_WARNING, - 'color' => COL_WARNING, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_STATUS_ALERT_FIRED, - 'color' => COL_ALERTFIRED, - ]; - $module_color_status_unknown = COL_UNKNOWN; - - echo 'var module_color_status = '.json_encode($module_color_status).";\n"; - echo "var module_color_status_unknown = '".$module_color_status_unknown."';\n"; - - echo "\n"; - echo "\n"; - - echo "////////////////////////////////////////////////////////////////////\n"; - echo "// Other vars\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - - echo "var translation_none = '".__('None')."';\n"; - echo "var dialog_node_edit_title = '".__('Edit node %s')."';\n"; - echo "var holding_area_title = '".__('Holding Area')."';\n"; - echo "var edit_menu = '".__('Show details and options')."';\n"; - echo "var interface_link_add = '".__('Add a interface link')."';\n"; - echo "var set_parent_link = '".__('Set parent interface')."';\n"; - echo "var set_as_children_menu = '".__('Set as children')."';\n"; - echo "var set_parent_menu = '".__('Set parent')."';\n"; - echo "var abort_relationship_menu = '".__('Abort the action of set relationship')."';\n"; - echo "var delete_menu = '".__('Delete')."';\n"; - echo "var add_node_menu = '".__('Add node')."';\n"; - echo "var set_center_menu = '".__('Set center')."';\n"; - echo "var refresh_menu = '".__('Refresh')."';\n"; - echo "var refresh_holding_area_menu = '".__('Refresh Holding area')."';\n"; - echo "var ok_button = '".__('Proceed')."';\n"; - echo "var message_to_confirm = '".__('Resetting the map will delete all customizations you have done, including manual relationships between elements, new items, etc.')."';\n"; - echo "var warning_message = '".__('WARNING')."';\n"; - echo "var ok_button = '".__('Proceed')."';\n"; - echo "var cancel_button = '".__('Cancel')."';\n"; - echo "var restart_map_menu = '".__('Restart map')."';\n"; - echo "var abort_relationship_interface = '".__('Abort the interface relationship')."';\n"; - echo "var abort_relationship_menu = '".__('Abort the action of set relationship')."';\n"; - - echo "\n"; - echo "\n"; -} - - -function networkmap_loadfile( - $id=0, - $file='', - &$relations_param, - $graph -) { - global $config; - - $height_map = db_get_value('height', 'tmap', 'id', $id); - - $networkmap_nodes = []; - - $relations = []; - - $other_file = file($file); - - // Remove the graph head - $graph = preg_replace('/^graph .*/', '', $graph); - // Cut in nodes the graph - $graph = explode(']', $graph); - - $ids = []; - foreach ($graph as $node) { - $line = str_replace("\n", ' ', $node); - - if (preg_match('/([0-9]+) \[.*tooltip.*id_module=([0-9]+)/', $line, $match) != 0) { - $ids[$match[1]] = [ - 'type' => 'module', - 'id_module' => $match[2], - ]; - } else if (preg_match('/([0-9]+) \[.*tooltip.*id_agent=([0-9]+)/', $line, $match) != 0) { - $ids[$match[1]] = [ - 'type' => 'agent', - 'id_agent' => $match[2], - ]; - } - } - - foreach ($other_file as $key => $line) { - // clean line a long spaces for one space caracter - $line = preg_replace('/[ ]+/', ' ', $line); - - $data = []; - - if (preg_match('/^node.*$/', $line) != 0) { - $items = explode(' ', $line); - $node_id = $items[1]; - $node_x = ($items[2] * 100); - // 200 is for show more big - $node_y = ($height_map - $items[3] * 100); - // 200 is for show more big - $data['id'] = $node_id; - $data['text'] = ''; - $data['image'] = ''; - $data['width'] = 10; - $data['height'] = 10; - $data['id_agent'] = 0; - - if (preg_match('/ $line_orig, - 'dest' => $line_dest, - ]; - } - } - - $relations_param = []; - - foreach ($relations as $rel) { - if (strpos($rel['orig'], 'transp_') !== false) { - // removed the transparent nodes - continue; - } - - if (strpos($rel['dest'], 'transp_') !== false) { - // removed the transparent nodes - continue; - } - - $row = [ - 'id_child' => $rel['orig'], - 'child_type' => $networkmap_nodes[$rel['orig']]['type'], - 'id_parent' => $rel['dest'], - 'parent_type' => $networkmap_nodes[$rel['dest']]['type'], - ]; - $relations_param[] = $row; - } - - return $networkmap_nodes; -} - - -function get_status_color_module_networkmap($id_agente_modulo) -{ - $status = modules_get_agentmodule_status($id_agente_modulo); - - // Set node status - switch ($status) { - case 0: - // At the moment the networkmap enterprise does not show the - // alerts. - case AGENT_MODULE_STATUS_NORMAL_ALERT: - $status_color = COL_NORMAL; - // Normal monitor - break; - - case 1: - $status_color = COL_CRITICAL; - // Critical monitor - break; - - case 2: - $status_color = COL_WARNING; - // Warning monitor - break; - - case 4: - $status_color = COL_ALERTFIRED; - // Alert fired - break; - - default: - $status_color = COL_UNKNOWN; - // Unknown monitor - break; - } - - return $status_color; -} - - -function duplicate_networkmap($id) -{ - $return = true; - - $values = db_get_row('tmap', 'id', $id); - unset($values['id']); - $free_name = false; - $values['name'] = io_safe_input(__('Copy of ')).$values['name']; - $count = 1; - while (!$free_name) { - $exist = db_get_row_filter('tmap', ['name' => $values['name']]); - if ($exist === false) { - $free_name = true; - } else { - $values['name'] = $values['name'].io_safe_input(' '.$count); - } - } - - $correct_or_id = db_process_sql_insert('tmap', $values); - if ($correct_or_id === false) { - $return = false; - } else { - if (enterprise_installed()) { - $new_id = $correct_or_id; - duplicate_map_insert_nodes_and_relations($id, $new_id); - } - } - - if ($return) { - return true; - } else { - // Clean DB. - if (enterprise_installed()) { - // Relations - delete_relations($new_id); - - // Nodes - delete_nodes($new_id); - } - - db_process_sql_delete('tmap', ['id' => $new_id]); - - return false; - } -} - - -function clean_duplicate_links($relations) -{ - if (enterprise_installed()) { - enterprise_include_once('include/functions_pandora_networkmap.php'); - } - - $segregation_links = []; - $index = 0; - $index2 = 0; - $index3 = 0; - $index4 = 0; - foreach ($relations as $rel) { - if (($rel['parent_type'] == 0) && ($rel['child_type'] == 0)) { - $segregation_links['aa'][$index] = $rel; - $index++; - } else if (($rel['parent_type'] == 1) && ($rel['child_type'] == 1)) { - $segregation_links['mm'][$index2] = $rel; - $index2++; - } else if (($rel['parent_type'] == 3) && ($rel['child_type'] == 3)) { - $segregation_links['ff'][$index4] = $rel; - $index4++; - } else { - $segregation_links['am'][$index3] = $rel; - $index3++; - } - } - - $final_links = []; - - // ---------------------------------------------------------------- - // --------------------- Clean duplicate links -------------------- - // ---------------------------------------------------------------- - $duplicated = false; - $index_to_del = 0; - $index = 0; - if (isset($segregation_links['aa']) === true - && is_array($segregation_links['aa']) === true - ) { - foreach ($segregation_links['aa'] as $link) { - foreach ($segregation_links['aa'] as $link2) { - if ($link['id_parent'] == $link2['id_child'] - && $link['id_child'] == $link2['id_parent'] - ) { - if (enterprise_installed()) { - delete_link($segregation_links['aa'][$index_to_del]); - } - - unset($segregation_links['aa'][$index_to_del]); - } - - $index_to_del++; - } - - $final_links['aa'][$index] = $link; - $index++; - - $duplicated = false; - $index_to_del = 0; - } - } - - $duplicated = false; - $index_to_del = 0; - $index2 = 0; - if (isset($segregation_links['mm']) === true - && is_array($segregation_links['mm']) === true - ) { - foreach ($segregation_links['mm'] as $link) { - foreach ($segregation_links['mm'] as $link2) { - if ($link['id_parent'] == $link2['id_child'] - && $link['id_child'] == $link2['id_parent'] - ) { - if (enterprise_installed()) { - delete_link($segregation_links['mm'][$index_to_del]); - } - } - - $index_to_del++; - } - - $final_links['mm'][$index2] = $link; - $index2++; - - $duplicated = false; - $index_to_del = 0; - } - } - - $duplicated = false; - $index_to_del = 0; - $index3 = 0; - - if (isset($segregation_links['ff']) === true - && is_array($segregation_links['ff']) === true - ) { - foreach ($segregation_links['ff'] as $link) { - foreach ($segregation_links['ff'] as $link2) { - if ($link['id_parent'] == $link2['id_child'] - && $link['id_child'] == $link2['id_parent'] - ) { - if (enterprise_installed()) { - delete_link($segregation_links['ff'][$index_to_del]); - } - - unset($segregation_links['ff'][$index_to_del]); - } - - $index_to_del++; - } - - $final_links['ff'][$index3] = $link; - $index3++; - - $duplicated = false; - $index_to_del = 0; - } - } - - $final_links['am'] = $segregation_links['am']; - - /* - ---------------------------------------------------------------- - ----------------- AA, AM and MM links management --------------- - ------------------ Priority: ----------------------------------- - -------------------- 1 -> MM (module - module) ----------------- - -------------------- 2 -> AM (agent - module) ------------------ - -------------------- 3 -> AA (agent - agent) ------------------- - ---------------------------------------------------------------- - */ - - $final_links2 = []; - $index = 0; - $l3_link = []; - $agent1 = 0; - $agent2 = 0; - - if (isset($final_links['mm']) === true - && is_array($final_links['mm']) === true - ) { - foreach ($final_links['mm'] as $rel_mm) { - $module_parent = $rel_mm['id_parent_source_data']; - $module_children = $rel_mm['id_child_source_data']; - $agent1 = (int) agents_get_agent_id_by_module_id($module_parent); - $agent2 = (int) agents_get_agent_id_by_module_id($module_children); - foreach ($final_links['aa'] as $key => $rel_aa) { - $l3_link = $rel_aa; - $id_p_source_data = (int) $rel_aa['id_parent_source_data']; - $id_c_source_data = (int) $rel_aa['id_child_source_data']; - if ((($id_p_source_data == $agent1) - && ($id_c_source_data == $agent2)) - || (($id_p_source_data == $agent2) - && ($id_c_source_data == $agent1)) - ) { - if (enterprise_installed()) { - delete_link($final_links['aa'][$key]); - } - - unset($final_links['aa'][$key]); - } - } - } - } - - $final_links2['aa'] = $final_links['aa']; - $final_links2['mm'] = $final_links['mm']; - $final_links2['am'] = $final_links['am']; - $final_links2['ff'] = $final_links['ff']; - - $same_m = []; - $index = 0; - if (isset($final_links2['am']) === true - && is_array($final_links2['am']) === true - ) { - foreach ($final_links2['am'] as $rel_am) { - foreach ($final_links2['am'] as $rel_am2) { - if (($rel_am['id_child_source_data'] == $rel_am2['id_child_source_data']) - && ($rel_am['id_parent_source_data'] != $rel_am2['id_parent_source_data']) - ) { - $same_m[$index]['rel'] = $rel_am2; - $same_m[$index]['agent_parent'] = $rel_am['id_parent_source_data']; - $index++; - } - } - } - } - - $final_links3 = []; - $index = 0; - $l3_link = []; - $have_l3 = false; - if (isset($final_links2['aa']) === true - && is_array($final_links2['aa']) === true - ) { - foreach ($final_links2['aa'] as $key => $rel_aa) { - $l3_link = $rel_aa; - foreach ($same_m as $rel_am) { - if ((($rel_aa['id_parent_source_data'] == $rel_am['parent']['id_parent_source_data']) - && ($rel_aa['id_child_source_data'] == $rel_am['rel']['id_parent_source_data'])) - || (($rel_aa['id_child_source_data'] == $rel_am['parent']['id_parent_source_data']) - && ($rel_aa['id_parent_source_data'] == $rel_am['rel']['id_parent_source_data'])) - ) { - if (enterprise_installed()) { - delete_link($final_links2['aa'][$key]); - } - - unset($final_links2['aa'][$key]); - } - } - } - } - - $final_links3['aa'] = $final_links2['aa']; - $final_links3['mm'] = $segregation_links['mm']; - $final_links3['am'] = $segregation_links['am']; - $final_links3['ff'] = $final_links2['ff']; - - $cleaned_links = []; - if (isset($final_links3['aa']) === true - && is_array($final_links3['aa']) === true - ) { - foreach ($final_links3['aa'] as $link) { - $cleaned_links[] = $link; - } - } - - if (isset($final_links3['am']) === true - && is_array($final_links3['am']) === true - ) { - foreach ($final_links3['am'] as $link) { - $cleaned_links[] = $link; - } - } - - if (isset($final_links3['mm']) === true - && is_array($final_links3['mm']) === true - ) { - foreach ($final_links3['mm'] as $link) { - $cleaned_links[] = $link; - } - } - - if (isset($final_links3['ff']) === true - && is_array($final_links3['ff']) === true - ) { - foreach ($final_links3['ff'] as $link) { - $cleaned_links[] = $link; - } - } - - return $cleaned_links; -} - - -function is_in_rel_array($relations, $relation) -{ - $is_in_array = false; - foreach ($relations as $rel) { - if ($rel['id_parent_source_data'] == $relation['id_parent_source_data'] - && $rel['id_child_source_data'] == $relation['id_child_source_data'] - ) { - $is_in_array = true; - } - } - - return $is_in_array; -} - - -function map_migrated($id) -{ - $new_maps = db_get_all_rows_sql('SELECT filter FROM tmap'); - $new_map_filter = json_decode($new_maps, true); - - foreach ($new_map_filter as $filter) { - if ((isset($filter['id_migrate_map'])) && ($filter['id_migrate_map'] == $id)) { - return true; - } - } - - return false; -} - - -function migrate_older_open_maps($id) -{ - global $config; - - $old_networkmap = db_get_row_filter( - 'tnetwork_map', - ['id_networkmap' => $id] - ); - - $map_values = []; - $map_values['id_group'] = $old_networkmap['id_group']; - $map_values['id_user'] = $old_networkmap['id_user']; - $map_values['type'] = 0; - $map_values['subtype'] = 0; - $map_values['name'] = $old_networkmap['name']; - - $new_map_filter = []; - $new_map_filter['dont_show_subgroups'] = $old_networkmap['dont_show_subgroups']; - $new_map_filter['node_radius'] = 40; - $new_map_filter['id_migrate_map'] = $id; - $map_values['filter'] = json_encode($new_map_filter); - - $map_values['description'] = 'Mapa open migrado'; - $map_values['width'] = 4000; - $map_values['height'] = 4000; - $map_values['center_x'] = 2000; - $map_values['center_y'] = 2000; - $map_values['background'] = ''; - $map_values['background_options'] = 0; - $map_values['source_period'] = 60; - $map_values['source'] = 0; - $map_values['source_data'] = $old_networkmap['id_group']; - if ($old_networkmap['type'] == 'radial_dinamic') { - $map_values['generation_method'] = 6; - } else { - $map_values['generation_method'] = 4; - } - - $map_values['generated'] = 0; - - $id_new_map = db_process_sql_insert('tmap', $map_values); - - if (!$id_new_map) { - return false; - } - - return true; -} - - -function show_networkmap($id=0, $user_readonly=false, $nodes_and_relations=[], $dashboard_mode=false, $map_dash_details=[]) -{ - global $config; - $clean_relations = clean_duplicate_links($nodes_and_relations['relations']); - - $hide_minimap = ''; - - $nodes_and_relations['relations'] = $clean_relations; - - $networkmap = db_get_row('tmap', 'id', $id); - $networkmap['filter'] = json_decode($networkmap['filter'], true); - - $networkmap['filter']['l2_network_interfaces'] = 1; - - echo ''; - ui_require_css_file('jquery.contextMenu', 'include/styles/js/'); - echo ''; - echo ''; - echo '
    '; - if ($dashboard_mode) { - $hide_minimap = 'none'; - } - - echo '
    '; - echo ' - '; - - echo '
    - - - -
    '; - echo '
    '; - - echo '
    - - - -
    '; - echo ''; - - echo '
    '; - - ?> - - - - - - - - - - - - - $row) { - // Metaconsole connection + // Metaconsole connection. $server_name = $row['server_name']; if (($config['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { $connection = metaconsole_get_connection($server_name); @@ -1414,7 +1411,7 @@ function reporting_event_top_n( case REPORT_TOP_N_AVG: default: - // If nothing is selected then it will be shown the average data + // If nothing is selected then it will be shown the average data. $value = reporting_get_agentmodule_data_average($row['id_agent_module'], $content['period']); break; } @@ -1428,7 +1425,7 @@ function reporting_event_top_n( $units[$key] = $unit; } - // Restore dbconnection + // Restore dbconnection. if (($config['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { metaconsole_restore_db(); } @@ -1441,21 +1438,25 @@ function reporting_event_top_n( // Order to show. switch ($order_uptodown) { - // Descending + // Descending. case 1: array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); break; - // Ascending + // Ascending. case 2: array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); break; - // By agent name or without selection + // By agent name or without selection. case 0: case 3: array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); break; + + default: + // Default. + break; } array_splice($data_top, $top_n_value); @@ -1471,7 +1472,7 @@ function reporting_event_top_n( $data_top_values['id_agent_module'] = $id_agent_module; $data_top_values['units'] = $units; - // Define truncate size depends the graph width + // Define truncate size depends the graph width. $truncate_size = ($width / (4 * ($config['font_size'])) - 1); if ($order_uptodown == 1 || $order_uptodown == 2) { @@ -1597,7 +1598,7 @@ function reporting_event_top_n( $ttl ); - // Display bars graph + // Display bars graph. $return['charts']['bars'] = hbar_graph( $data_hbar, $width, @@ -1622,7 +1623,7 @@ function reporting_event_top_n( $return['resume'] = null; if ($content['show_resume'] && count($data_top_values) > 0) { - // Get the very first not null value + // Get the very first not null value. $i = 0; do { $min = $data_top_values['data_top'][$i]; @@ -1697,18 +1698,19 @@ function reporting_event_report_group( } $return['description'] = $content['description']; + $return['show_extended_events'] = $content['show_extended_events']; $return['date'] = reporting_get_date_text($report, $content); $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; - // filter + // Filter. $show_summary_group = $event_filter['show_summary_group']; $filter_event_severity = json_decode($event_filter['filter_event_severity'], true); $filter_event_type = json_decode($event_filter['filter_event_type'], true); $filter_event_status = json_decode($event_filter['filter_event_status'], true); $filter_event_filter_search = $event_filter['event_filter_search']; - // graphs + // Graphs. $event_graph_by_agent = $event_filter['event_graph_by_agent']; $event_graph_by_user_validator = $event_filter['event_graph_by_user_validator']; $event_graph_by_criticity = $event_filter['event_graph_by_criticity']; @@ -1870,7 +1872,7 @@ function reporting_event_report_group( metaconsole_restore_db(); } - // total_events + // total_events. if ($return['data'] != '') { $return['total_events'] = count($return['data']); } else { @@ -1912,24 +1914,29 @@ function reporting_event_report_module( $return['title'] = $content['name']; $return['subtitle'] = agents_get_alias($content['id_agent']).' - '.io_safe_output(modules_get_agentmodule_name($content['id_agent_module'])); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { + $return['label'] = reporting_label_macro($content, $return['label']); + } + if (is_metaconsole()) { metaconsole_restore_db(); } $return['description'] = $content['description']; + $return['show_extended_events'] = $content['show_extended_events']; $return['date'] = reporting_get_date_text($report, $content); - $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; - // filter + // Filter. $show_summary_group = $event_filter['show_summary_group']; $filter_event_severity = json_decode($event_filter['filter_event_severity'], true); $filter_event_type = json_decode($event_filter['filter_event_type'], true); $filter_event_status = json_decode($event_filter['filter_event_status'], true); $filter_event_filter_search = $event_filter['event_filter_search']; - // graphs + // Graphs. $event_graph_by_user_validator = $event_filter['event_graph_by_user_validator']; $event_graph_by_criticity = $event_filter['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $event_filter['event_graph_validated_vs_unvalidated']; @@ -1941,7 +1948,7 @@ function reporting_event_report_module( $metaconsole_dbtable = false; } - // data events + // Data events. $data = reporting_get_module_detailed_event( $content['id_agent_module'], $content['period'], @@ -1970,7 +1977,7 @@ function reporting_event_report_module( metaconsole_restore_db(); } - // total_events + // Total_events. if ($return['data'][0]['data'] != '') { $return['total_events'] = count($return['data'][0]['data']); } else { @@ -2287,6 +2294,10 @@ function reporting_exception( $return['subtitle'] = __('Exception - Modules at critical or warning status'); $return['subtype'] = __('Modules at critical or warning status'); break; + + default: + // Default. + break; } $return['description'] = $content['description']; @@ -2297,7 +2308,7 @@ function reporting_exception( $return['resume'] = []; if (empty($content['subitems'])) { - // Get all the related data + // Get all the related data. $sql = sprintf( ' SELECT id_agent_module, server_name, operation @@ -2314,10 +2325,10 @@ function reporting_exception( if ($exceptions === false) { $return['failed'] = __('There are no Agent/Modules defined'); } else { - // Get the very first not null value + // Get the very first not null value. $i = 0; do { - // Metaconsole connection + // Metaconsole connection. $server_name = $exceptions[$i]['server_name']; if (($config['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { $connection = metaconsole_get_connection($server_name); @@ -2351,12 +2362,16 @@ function reporting_exception( $content['period'] ); break; + + default: + // Default. + break; } } $i++; - // Restore dbconnection + // Restore dbconnection. if (($config['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { metaconsole_restore_db(); } @@ -2368,7 +2383,7 @@ function reporting_exception( $i = 0; foreach ($exceptions as $exc) { - // Metaconsole connection + // Metaconsole connection. $server_name = $exc['server_name']; if (($config['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { $connection = metaconsole_get_connection($server_name); @@ -2730,6 +2745,17 @@ function reporting_group_report($report, $content) } +/** + * Create data report event agent. + * + * @param array $report Data report. + * @param array $content Content report. + * @param string $type Type report. + * @param integer $force_width_chart Force width. + * @param integer $force_height_chart Force height. + * + * @return array Data. + */ function reporting_event_report_agent( $report, $content, @@ -2750,25 +2776,26 @@ function reporting_event_report_agent( $history = true; } - $return['title'] = $content['name']; - $return['subtitle'] = agents_get_alias($content['id_agent']); - $return['description'] = $content['description']; - $return['date'] = reporting_get_date_text($report, $content); - $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + $return['title'] = $content['name']; + $return['subtitle'] = agents_get_alias($content['id_agent']); + $return['description'] = $content['description']; + $return['date'] = reporting_get_date_text($report, $content); + $return['show_summary_group'] = $content['style']['show_summary_group']; + $return['show_extended_events'] = $content['show_extended_events']; $style = $content['style']; - // filter - $show_summary_group = $style['show_summary_group']; - $filter_event_severity = json_decode($style['filter_event_severity'], true); - $filter_event_type = json_decode($style['filter_event_type'], true); - $filter_event_status = json_decode($style['filter_event_status'], true); + // Filter. + $show_summary_group = $style['show_summary_group']; + $filter_event_severity = json_decode($style['filter_event_severity'], true); + $filter_event_type = json_decode($style['filter_event_type'], true); + $filter_event_status = json_decode($style['filter_event_status'], true); $filter_event_filter_search = $style['event_filter_search']; - // graph - $event_graph_by_user_validator = $style['event_graph_by_user_validator']; - $event_graph_by_criticity = $style['event_graph_by_criticity']; + // Graph. + $event_graph_by_user_validator = $style['event_graph_by_user_validator']; + $event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; $return['data'] = reporting_get_agents_detailed_event( @@ -2813,6 +2840,13 @@ function reporting_event_report_agent( $metaconsole_dbtable = false; } + $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($label != '') { + $label = reporting_label_macro($content, $label); + } + + $return['label'] = $label; + if ($event_graph_by_user_validator) { $data_graph = events_get_count_events_validated_by_user( ['id_agent' => $content['id_agent']], @@ -2896,7 +2930,7 @@ function reporting_event_report_agent( metaconsole_restore_db(); } - // total_events + // Total events. if ($return['data'] != '') { $return['total_events'] = count($return['data']); } else { @@ -2929,7 +2963,11 @@ function reporting_historical_data($report, $content) $return['subtitle'] = $agent_name.' - '.$module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { + $return['label'] = reporting_label_macro($content, $return['label']); + } $return['keys'] = [ __('Date'), @@ -3005,7 +3043,6 @@ function reporting_database_serialized($report, $content) $return['subtitle'] = $agent_name.' - '.$module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); - $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; $keys = []; if (isset($content['header_definition']) && ($content['header_definition'] != '')) { @@ -3031,6 +3068,11 @@ function reporting_database_serialized($report, $content) metaconsole_connect($server); } + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { + $return['label'] = reporting_label_macro($content, $return['label']); + } + $datelimit = ($report['datetime'] - $content['period']); $search_in_history_db = db_search_in_history_db($datelimit); @@ -3577,7 +3619,12 @@ function reporting_alert_report_agent($report, $content) $return['subtitle'] = $agent_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { + $return['label'] = reporting_label_macro($content, $return['label']); + } + $module_list = agents_get_modules($content['id_agent']); $data = []; @@ -3709,6 +3756,9 @@ function reporting_alert_report_module($report, $content) $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { + $return['label'] = reporting_label_macro($content, $return['label']); + } $data_row = []; @@ -3911,7 +3961,6 @@ function reporting_monitor_report($report, $content) $return['subtitle'] = $agent_name.' - '.$module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); - $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($config['metaconsole']) { $id_meta = metaconsole_get_id_server($content['server_name']); @@ -3920,6 +3969,11 @@ function reporting_monitor_report($report, $content) metaconsole_connect($server); } + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + if ($return['label'] != '') { + $return['label'] = reporting_label_macro($content, $return['label']); + } + $module_name = io_safe_output( modules_get_agentmodule_name($content['id_agent_module']) ); @@ -3955,6 +4009,20 @@ function reporting_monitor_report($report, $content) } +/** + * Generates the data structure to build a netflow report. + * + * @param array $report Global report info. + * @param array $content Report item info. + * @param string $type Report type (static, dynamic, data). + * @param integer $force_width_chart Fixed width chart. + * @param integer $force_height_chart Fixed height chart. + * @param string $type_netflow One of netflow_area, netflow_data, + * netflow_summary. + * @param boolean $pdf True if a pdf report is generating. + * + * @return array Report item structure. + */ function reporting_netflow( $report, $content, @@ -3971,21 +4039,17 @@ function reporting_netflow( $return['type'] = 'netflow_area'; break; - case 'netflow_pie': - $return['type'] = 'netflow_pie'; - break; - case 'netflow_data': $return['type'] = 'netflow_data'; break; - case 'netflow_statistics': - $return['type'] = 'netflow_statistics'; - break; - case 'netflow_summary': $return['type'] = 'netflow_summary'; break; + + default: + $return['type'] = 'unknown'; + break; } if (empty($content['name'])) { @@ -3994,20 +4058,16 @@ function reporting_netflow( $content['name'] = __('Netflow Area'); break; - case 'netflow_pie': - $content['name'] = __('Netflow Pie'); + case 'netflow_summary': + $content['name'] = __('Netflow Summary'); break; case 'netflow_data': $content['name'] = __('Netflow Data'); break; - case 'netflow_statistics': - $content['name'] = __('Netflow Statistics'); - break; - - case 'netflow_summary': - $content['name'] = __('Netflow Summary'); + default: + $content['name'] = __('Unknown report'); break; } } @@ -4016,7 +4076,7 @@ function reporting_netflow( $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); - // Get chart + // Get chart. reporting_set_conf_charts( $width, $height, @@ -4034,7 +4094,7 @@ function reporting_netflow( $height = $force_height_chart; } - // Get item filters + // Get item filters. $filter = db_get_row_sql( "SELECT * FROM tnetflow_filter @@ -4059,9 +4119,17 @@ function reporting_netflow( break; case 'data': + default: + // Nothing to do. break; } + $return['subtitle'] = netflow_generate_subtitle_report( + $filter['aggregate'], + $content['top_n'], + $type_netflow + ); + return reporting_check_structure_content($return); } @@ -4413,6 +4481,9 @@ function reporting_value($report, $content, $type, $pdf=false) $return['description'] = $content['description']; $return['date'] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + $return['agents'] = [$content['id_agent']]; + $return['id_agent'] = $content['id_agent']; + $return['id_agent_module'] = $content['id_agent_module']; $return['agent_name'] = $agent_name; $return['module_name'] = $module_name; @@ -5486,6 +5557,9 @@ function reporting_advanced_sla( $max_value = 0; $min_value = 0; $inverse_interval = 1; + } else if ($agentmodule_info['id_tipo_modulo'] == '100') { + $max_value = 0.9; + $min_value = 0; } } } @@ -6266,6 +6340,19 @@ function reporting_availability($report, $content, $date=false, $time=false) $return['resume']['avg'] = $avg; $return['resume']['max_text'] = $max_text; $return['resume']['max'] = $max; + $return['fields'] = []; + $return['fields']['total_time'] = $content['total_time']; + $return['fields']['time_failed'] = $content['time_failed']; + $return['fields']['time_in_ok_status'] = $content['time_in_ok_status']; + $return['fields']['time_in_unknown_status'] = $content['time_in_unknown_status']; + $return['fields']['time_of_not_initialized_module'] = $content['time_of_not_initialized_module']; + $return['fields']['time_of_downtime'] = $content['time_of_downtime']; + $return['fields']['total_checks'] = $content['total_checks']; + $return['fields']['checks_failed'] = $content['checks_failed']; + $return['fields']['checks_in_ok_status'] = $content['checks_in_ok_status']; + $return['fields']['unknown_checks'] = $content['unknown_checks']; + $return['fields']['agent_max_value'] = $content['agent_max_value']; + $return['fields']['agent_min_value'] = $content['agent_min_value']; return reporting_check_structure_content($return); } @@ -7228,6 +7315,7 @@ function reporting_custom_graph( 'modules_series' => $graphs[0]['modules_series'], 'id_graph' => $id_graph, 'type_report' => $type_report, + 'labels' => $content['style']['label'], ]; $return['chart'] = graphic_combined_module( @@ -7288,6 +7376,7 @@ function reporting_simple_graph( $report, $content ); + $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($label != '') { $label = reporting_label_macro($content, $label); @@ -7299,7 +7388,7 @@ function reporting_simple_graph( $return['chart'] = ''; - // Get chart + // Get chart. reporting_set_conf_charts($width, $height, $only_image, $type, $content, $ttl); if (!empty($force_width_chart)) { @@ -7439,6 +7528,21 @@ function reporting_check_structure_content($report) $report['date']['to'] = ''; } + if (!isset($report['fields'])) { + $return['fields']['total_time'] = ''; + $return['fields']['time_failed'] = ''; + $return['fields']['time_in_ok_status'] = ''; + $return['fields']['time_in_unknown_status'] = ''; + $return['fields']['time_of_not_initialized_module'] = ''; + $return['fields']['time_of_downtime'] = ''; + $return['fields']['total_checks'] = ''; + $return['fields']['checks_failed'] = ''; + $return['fields']['checks_in_ok_status'] = ''; + $return['fields']['unknown_checks'] = ''; + $return['fields']['agent_max_value'] = ''; + $return['fields']['agent_min_value'] = ''; + } + return $report; } @@ -7734,6 +7838,7 @@ function reporting_get_agents_detailed_event( 'criticity' => $e['criticity'], 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp_rep'], + 'id_evento' => $e['id_evento'], ]; } else { $return_data[] = [ @@ -7743,6 +7848,7 @@ function reporting_get_agents_detailed_event( 'criticity' => $e['criticity'], 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp'], + 'id_evento' => $e['id_evento'], ]; } } @@ -7765,11 +7871,11 @@ function reporting_get_agents_detailed_event( foreach ($events as $eventRow) { foreach ($eventRow as $k => $event) { - // First pass along the class of this row + // First pass along the class of this row. $table->cellclass[$k][1] = $table->cellclass[$k][2] = $table->cellclass[$k][4] = $table->cellclass[$k][5] = $table->cellclass[$k][6] = get_priority_class($event['criticity']); $data = []; - // Colored box + // Colored box. switch ($event['estado']) { case 0: $img_st = 'images/star.png'; @@ -9284,15 +9390,34 @@ function reporting_get_agent_module_info($id_agent) $return = []; $return['last_contact'] = 0; - // Last agent contact + // Last agent contact. $return['status'] = STATUS_AGENT_NO_DATA; - $return['status_img'] = ui_print_status_image(STATUS_AGENT_NO_DATA, __('Agent without data'), true); + $return['status_img'] = ui_print_status_image( + STATUS_AGENT_NO_DATA, + __('Agent without data'), + true + ); $return['alert_status'] = 'notfired'; $return['alert_value'] = STATUS_ALERT_NOT_FIRED; - $return['alert_img'] = ui_print_status_image(STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true); - $return['agent_group'] = agents_get_agent_group($id_agent); + $return['alert_img'] = ui_print_status_image( + STATUS_ALERT_NOT_FIRED, + __('Alert not fired'), + true + ); - if (!check_acl($config['id_user'], $return['agent_group'], 'AR')) { + $return['agent_group'] = ''; + // Important agents_get_all_groups_agent check secondary groups. + $id_all_groups = agents_get_all_groups_agent($id_agent); + if (isset($id_all_groups) && is_array($id_all_groups)) { + foreach ($id_all_groups as $value) { + if (check_acl($config['id_user'], $value, 'AR')) { + $return['agent_group'] = $value; + } + } + } + + // If $return['agent_group'] is empty no access. + if ($return['agent_group'] == '') { return $return; } @@ -9305,7 +9430,7 @@ function reporting_get_agent_module_info($id_agent) $now = get_system_time(); - // Get modules status for this agent + // Get modules status for this agent. $agent = db_get_row('tagente', 'id_agente', $id_agent); $return['total_count'] = $agent['total_count']; @@ -9319,28 +9444,52 @@ function reporting_get_agent_module_info($id_agent) if ($return['total_count'] > 0) { if ($return['critical_count'] > 0) { $return['status'] = STATUS_AGENT_CRITICAL; - $return['status_img'] = ui_print_status_image(STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true); + $return['status_img'] = ui_print_status_image( + STATUS_AGENT_CRITICAL, + __('At least one module in CRITICAL status'), + true + ); } else if ($return['warning_count'] > 0) { $return['status'] = STATUS_AGENT_WARNING; - $return['status_img'] = ui_print_status_image(STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true); + $return['status_img'] = ui_print_status_image( + STATUS_AGENT_WARNING, + __('At least one module in WARNING status'), + true + ); } else if ($return['unknown_count'] > 0) { $return['status'] = STATUS_AGENT_DOWN; - $return['status_img'] = ui_print_status_image(STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true); + $return['status_img'] = ui_print_status_image( + STATUS_AGENT_DOWN, + __('At least one module is in UKNOWN status'), + true + ); } else { $return['status'] = STATUS_AGENT_OK; - $return['status_img'] = ui_print_status_image(STATUS_AGENT_OK, __('All Monitors OK'), true); + $return['status_img'] = ui_print_status_image( + STATUS_AGENT_OK, + __('All Monitors OK'), + true + ); } } - // Alert not fired is by default + // Alert not fired is by default. if ($return['fired_count'] > 0) { $return['alert_status'] = 'fired'; - $return['alert_img'] = ui_print_status_image(STATUS_ALERT_FIRED, __('Alert fired'), true); + $return['alert_img'] = ui_print_status_image( + STATUS_ALERT_FIRED, + __('Alert fired'), + true + ); $return['alert_value'] = STATUS_ALERT_FIRED; } else if (groups_give_disabled_group($return['agent_group'])) { $return['alert_status'] = 'disabled'; $return['alert_value'] = STATUS_ALERT_DISABLED; - $return['alert_img'] = ui_print_status_image(STATUS_ALERT_DISABLED, __('Alert disabled'), true); + $return['alert_img'] = ui_print_status_image( + STATUS_ALERT_DISABLED, + __('Alert disabled'), + true + ); } return $return; @@ -9350,13 +9499,23 @@ function reporting_get_agent_module_info($id_agent) /** * Print tiny statistics of the status of one agent, group, etc. * - * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts - * @param bool return or echo flag + * @param mixed $counts_info Array with the counts of the total modules, + * normal modules, critical modules, warning modules, unknown modules and + * fired alerts. + * @param boolean $return Return or echo flag. + * @param string $type agent or modules or ??. + * @param string $separator Sepearator (classic view). + * @param boolean $modern Use modern interfaces or old one. * - * @return string html formatted tiny stats of modules/alerts of an agent + * @return string HTML formatted tiny stats of modules/alerts of an agent. */ -function reporting_tiny_stats($counts_info, $return=false, $type='agent', $separator=':', $strict_user=false) -{ +function reporting_tiny_stats( + $counts_info, + $return=false, + $type='agent', + $separator=':', + $modern=false +) { global $config; $out = ''; @@ -9473,37 +9632,74 @@ function reporting_tiny_stats($counts_info, $return=false, $type='agent', $separ $out .= html_print_div($params, true); } - // If total count is less than 0, is an error. Never show negative numbers + // If total count is less than 0, is an error. Never show negative numbers. if ($total_count < 0) { $total_count = 0; } - $out .= ''.''.$total_count.''; - if (isset($fired_count) && $fired_count > 0) { - $out .= ' '.$separator.' '.$fired_count.''; - } + if ($modern === true) { + $out .= '
    '; + // $out .=''.$total_count.$separator.''; + if (isset($fired_count) && $fired_count > 0) { + $out .= '
    '; + $out .= ''.$fired_count.'
    '; + } - if (isset($critical_count) && $critical_count > 0) { - $out .= ' '.$separator.' '.$critical_count.''; - } + if (isset($critical_count) && $critical_count > 0) { + $out .= '
    '; + $out .= ''.$critical_count.'
    '; + } - if (isset($warning_count) && $warning_count > 0) { - $out .= ' '.$separator.' '.$warning_count.''; - } + if (isset($warning_count) && $warning_count > 0) { + $out .= '
    '; + $out .= ''.$warning_count.'
    '; + } - if (isset($unknown_count) && $unknown_count > 0) { - $out .= ' '.$separator.' '.$unknown_count.''; - } + if (isset($unknown_count) && $unknown_count > 0) { + $out .= '
    '; + $out .= ''.$unknown_count.'
    '; + } - if (isset($not_init_count) && $not_init_count > 0) { - $out .= ' '.$separator.' '.$not_init_count.''; - } + if (isset($not_init_count) && $not_init_count > 0) { + $out .= '
    '; + $out .= ''.$not_init_count.'
    '; + } - if (isset($normal_count) && $normal_count > 0) { - $out .= ' '.$separator.' '.$normal_count.''; - } + if (isset($normal_count) && $normal_count > 0) { + $out .= '
    '; + $out .= ''.$normal_count.'
    '; + } - $out .= '
    '; + $out .= '
    '; + } else { + // Classic ones. + $out .= ''.$total_count.''; + if (isset($fired_count) && $fired_count > 0) { + $out .= ' '.$separator.' '.$fired_count.''; + } + + if (isset($critical_count) && $critical_count > 0) { + $out .= ' '.$separator.' '.$critical_count.''; + } + + if (isset($warning_count) && $warning_count > 0) { + $out .= ' '.$separator.' '.$warning_count.''; + } + + if (isset($unknown_count) && $unknown_count > 0) { + $out .= ' '.$separator.' '.$unknown_count.''; + } + + if (isset($not_init_count) && $not_init_count > 0) { + $out .= ' '.$separator.' '.$not_init_count.''; + } + + if (isset($normal_count) && $normal_count > 0) { + $out .= ' '.$separator.' '.$normal_count.''; + } + + $out .= ''; + } if ($return) { return $out; @@ -11436,33 +11632,95 @@ function reporting_sla_is_ignored_from_array($sla_array) * * @return integer Status */ -function reporting_sla_get_status_period($sla_times, $priority_mode=REPORT_PRIORITY_MODE_OK) -{ - if ($sla_times['time_error'] > 0) { +function reporting_sla_get_status_period( + $sla, + $priority_mode=REPORT_PRIORITY_MODE_OK +) { + if ($sla['time_error'] > 0) { return REPORT_STATUS_ERR; } - if ($priority_mode == REPORT_PRIORITY_MODE_OK && $sla_times['time_ok'] > 0) { + if ($priority_mode == REPORT_PRIORITY_MODE_OK && $sla['time_ok'] > 0) { return REPORT_STATUS_OK; } - if ($sla_times['time_out'] > 0) { + if ($sla['time_out'] > 0) { return REPORT_STATUS_IGNORED; } - if ($sla_times['time_downtime'] > 0) { + if ($sla['time_downtime'] > 0) { return REPORT_STATUS_DOWNTIME; } - if ($sla_times['time_unknown'] > 0) { + if ($sla['time_unknown'] > 0) { return REPORT_STATUS_UNKNOWN; } - if ($sla_times['time_not_init'] > 0) { + if ($sla['time_not_init'] > 0) { return REPORT_STATUS_NOT_INIT; } - if ($sla_times['time_ok'] > 0) { + if ($sla['time_ok'] > 0) { + return REPORT_STATUS_OK; + } + + return REPORT_STATUS_IGNORED; +} + + +/** + * @brief Given a period, get the SLA status + * of the period compare with sla_limit. + * + * @param Array An array with all times to calculate the SLA. + * @param int Limit SLA pass for user. + * Only used for monthly, weekly And hourly report. + * + * @return integer Status + */ +function reporting_sla_get_status_period_compliance( + $sla, + $sla_limit +) { + global $config; + + $time_compliance = ( + $sla['time_ok'] + $sla['time_unknown'] + $sla['time_downtime'] + ); + + $time_total_working = ( + $time_compliance + $sla['time_error'] + ); + + $time_compliance = ($time_compliance == 0) ? 0 : (($time_compliance / $time_total_working) * 100); + + if ($sla['time_error'] > 0 && ($time_compliance < $sla_limit)) { + return REPORT_STATUS_ERR; + } + + if ($priority_mode == REPORT_PRIORITY_MODE_OK + && $sla['time_ok'] > 0 && ($time_compliance >= $sla_limit) + ) { + return REPORT_STATUS_OK; + } + + if ($sla['time_out'] > 0 && ($time_compliance < $sla_limit)) { + return REPORT_STATUS_IGNORED; + } + + if ($sla['time_downtime'] > 0 && ($time_compliance < $sla_limit)) { + return REPORT_STATUS_DOWNTIME; + } + + if ($sla['time_unknown'] > 0 && ($time_compliance < $sla_limit)) { + return REPORT_STATUS_UNKNOWN; + } + + if ($sla['time_not_init'] > 0 && ($time_compliance < $sla_limit)) { + return REPORT_STATUS_NOT_INIT; + } + + if ($sla['time_ok'] > 0 && ($time_compliance >= $sla_limit)) { return REPORT_STATUS_OK; } @@ -11498,7 +11756,7 @@ function reporting_translate_sla_status_for_graph($status) * * @return html Return table of header. */ -function reporting_header_table_for_pdf(string $title='', string $description='') +function reporting_header_table_for_pdf($title='', $description='') { $result_pdf .= ''; $result_pdf .= ''; @@ -11512,3 +11770,38 @@ function reporting_header_table_for_pdf(string $title='', string $description='' return $result_pdf; } + + +/** + * Build the required data to build network traffic top N report + * + * @param int Period (time window). + * @param array Information about the item of report. + * @param bool Pdf or not + * + * @return array With report presentation info and report data. + */ +function reporting_nt_top_n_report($period, $content, $pdf) +{ + $return = []; + $return['type'] = 'nt_top_n'; + $return['title'] = $content['name']; + $return['description'] = $content['description']; + + // Get the data sent and received + $return['data'] = []; + $start_time = ($period['datetime'] - (int) $content['period']); + $return['data']['send'] = network_matrix_get_top( + $content['top_n_value'], + true, + $start_time, + $period['datetime'] + ); + $return['data']['recv'] = network_matrix_get_top( + $content['top_n_value'], + false, + $start_time, + $period['datetime'] + ); + return $return; +} diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index b469e930c3..10bef8631f 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -271,21 +271,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) break; case 'netflow_area': - reporting_html_graph($table, $item); - break; - - case 'netflow_pie': - reporting_html_graph($table, $item); - break; - case 'netflow_data': - reporting_html_graph($table, $item); - break; - - case 'netflow_statistics': - reporting_html_graph($table, $item); - break; - case 'netflow_summary': reporting_html_graph($table, $item); break; @@ -367,6 +353,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) reporting_enterprise_html_SLA_monthly($table, $item, $mini); break; + case 'nt_top_n': + reporting_html_nt_top_n($table, $item, $mini); + break; + case 'SLA_weekly': reporting_enterprise_html_SLA_weekly($table, $item, $mini); break; @@ -549,10 +539,6 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0) foreach ($item['data'] as $sla) { if (isset($sla)) { - $the_first_men_time = get_agent_first_time( - io_safe_output($sla['agent']) - ); - // First_table. $row = []; $row[] = $sla['agent']; @@ -914,6 +900,9 @@ function reporting_html_top_n($table, $item, $pdf=0) function reporting_html_event_report_group($table, $item, $pdf=0) { global $config; + + $show_extended_events = $item['show_extended_events']; + if ($item['total_events']) { $table1 = new stdClass(); $table1->width = '99%'; @@ -1021,16 +1010,25 @@ function reporting_html_event_report_group($table, $item, $pdf=0) } array_push($table1->data, $data); + + if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { + $extended_events = events_get_extended_events($event['id_evento']); + + foreach ($extended_events as $extended_event) { + $extended_data = []; + + $extended_data[] = "'; + array_push($table1->data, $extended_data); + } + } } if ($pdf) { $table0 = new stdClass(); $table0->width = '99%'; - $table0->class = 'table-beauty'; $table0->data['count_row']['count'] = 'Total events: '.$item['total_events']; $pdf_export = html_print_table($table0, true); - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1046,7 +1044,6 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_agent']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1064,7 +1061,6 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_user_validator']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1082,7 +1078,6 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_criticity']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1100,7 +1095,6 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1117,7 +1111,6 @@ function reporting_html_event_report_group($table, $item, $pdf=0) if ($pdf) { $table0 = new stdClass(); $table0->width = '99%'; - $table0->class = 'table-beauty'; $table0->data['count_row']['count'] = 'Total events: '.$item['total_events']; $pdf_export = html_print_table($table0, true); @@ -1130,6 +1123,9 @@ function reporting_html_event_report_group($table, $item, $pdf=0) function reporting_html_event_report_module($table, $item, $pdf=0) { global $config; + + $show_extended_events = $item['show_extended_events']; + $show_summary_group = $item['show_summary_group']; if ($item['total_events']) { if (!empty($item['failed'])) { @@ -1213,17 +1209,26 @@ function reporting_html_event_report_module($table, $item, $pdf=0) } $table1->data[] = $data; + + if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { + $extended_events = events_get_extended_events($event['id_evento']); + + foreach ($extended_events as $extended_event) { + $extended_data = []; + + $extended_data[] = "'; + array_push($table1->data, $extended_data); + } + } } } if ($pdf) { $table0 = new stdClass(); $table0->width = '99%'; - $table0->class = 'table-beauty'; $table0->data['count_row']['count'] = 'Total events: '.$item['total_events']; $pdf_export = html_print_table($table0, true); - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1239,7 +1244,6 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_agent']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1257,7 +1261,6 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_user_validator']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1275,7 +1278,6 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_criticity']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1293,7 +1295,6 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -1312,7 +1313,6 @@ function reporting_html_event_report_module($table, $item, $pdf=0) if ($pdf) { $table0 = new stdClass(); $table0->width = '99%'; - $table0->class = 'table-beauty'; $table0->data['count_row']['count'] = 'Total events: '.$item['total_events']; $pdf_export = html_print_table($table0, true); @@ -1902,6 +1902,8 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) { global $config; + $show_extended_events = $item['show_extended_events']; + if ($item['total_events'] != 0) { $table1 = new stdClass(); $table1->width = '99%'; @@ -1989,16 +1991,25 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) } array_push($table1->data, $data); + + if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { + $extended_events = events_get_extended_events($event['id_evento']); + + foreach ($extended_events as $extended_event) { + $extended_data = []; + + $extended_data[] = "'; + array_push($table1->data, $extended_data); + } + } } if ($pdf) { $table0 = new stdClass(); $table0->width = '99%'; - $table0->class = 'table-beauty'; $table0->data['count_row']['count'] = 'Total events: '.$item['total_events']; $pdf_export = html_print_table($table0, true); - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -2015,7 +2026,6 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_user_validator']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -2033,7 +2043,6 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['by_criticity']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -2051,7 +2060,6 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; if ($pdf) { - $table1->class = 'table-beauty'; $pdf_export .= html_print_table($table1, true); $pdf_export .= '
    '; } else { @@ -2068,7 +2076,6 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) if ($pdf) { $table0 = new stdClass(); $table0->width = '99%'; - $table0->class = 'table-beauty'; $table0->data['count_row']['count'] = 'Total events: '.$item['total_events']; $pdf_export = html_print_table($table0, true); @@ -2411,7 +2418,7 @@ function reporting_html_alert_report($table, $item, $pdf=0) $table->data['alerts']['cell'] = html_print_table($table1, true); if ($pdf) { - $table1->class = 'table-beauty pdf_alert_table'; + $table1->class = 'pdf_alert_table'; return html_print_table($table1, true); } } @@ -2880,7 +2887,6 @@ function reporting_html_availability($table, $item, $pdf=0) io_safe_output($style), true ); - $same_agent_in_resume = ''; global $config; @@ -2900,32 +2906,62 @@ function reporting_html_availability($table, $item, $pdf=0) $table1->head[1] = __('Module'); } - $table1->head[2] = __('Total time'); - $table1->head[3] = __('Time failed'); - $table1->head[4] = __('Time OK'); - $table1->head[5] = __('Time Uknown'); - $table1->head[6] = __('Time Not Init Module'); - $table1->head[7] = __('Time Downtime'); + if ($item['fields']['total_time']) { + $table1->head[2] = __('Total time'); + } else { + $table1->head[2] = __(''); + } + + if ($item['fields']['time_failed']) { + $table1->head[3] = __('Time failed'); + } else { + $table1->head[3] = __(''); + } + + if ($item['fields']['time_in_ok_status']) { + $table1->head[4] = __('Time OK'); + } else { + $table1->head[4] = __(''); + } + + if ($item['fields']['time_in_unknown_status']) { + $table1->head[5] = __('Time Unknown'); + } else { + $table1->head[5] = __(''); + } + + if ($item['fields']['time_of_not_initialized_module']) { + $table1->head[6] = __('Time Not Init Module'); + } else { + $table1->head[6] = __(''); + } + + if ($item['fields']['time_of_downtime']) { + $table1->head[7] = __('Time Downtime'); + } else { + $table1->head[7] = __(''); + } + $table1->head[8] = __('% Ok'); $table1->headstyle = []; $table1->headstyle[0] = 'text-align: left'; $table1->headstyle[1] = 'text-align: left'; - $table1->headstyle[2] = 'text-align: right'; - $table1->headstyle[3] = 'text-align: right'; - $table1->headstyle[4] = 'text-align: right'; - $table1->headstyle[5] = 'text-align: right'; - $table1->headstyle[6] = 'text-align: right'; + $table1->headstyle[2] = 'text-align: center'; + $table1->headstyle[3] = 'text-align: center'; + $table1->headstyle[4] = 'text-align: center'; + $table1->headstyle[5] = 'text-align: center'; + $table1->headstyle[6] = 'text-align: center'; $table1->headstyle[7] = 'text-align: right'; $table1->headstyle[8] = 'text-align: right'; $table1->style[0] = 'text-align: left'; $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: right'; - $table1->style[3] = 'text-align: right'; - $table1->style[4] = 'text-align: right'; - $table1->style[5] = 'text-align: right'; - $table1->style[6] = 'text-align: right'; + $table1->style[2] = 'text-align: center'; + $table1->style[3] = 'text-align: center'; + $table1->style[4] = 'text-align: center'; + $table1->style[5] = 'text-align: center'; + $table1->style[6] = 'text-align: center'; $table1->style[7] = 'text-align: right'; $table1->style[8] = 'text-align: right'; @@ -2943,10 +2979,29 @@ function reporting_html_availability($table, $item, $pdf=0) $table2->head[1] = __('Module'); } - $table2->head[2] = __('Total checks'); - $table2->head[3] = __('Checks failed'); - $table2->head[4] = __('Checks OK'); - $table2->head[5] = __('Checks Uknown'); + if ($item['fields']['total_checks']) { + $table2->head[2] = __('Total checks'); + } else { + $table2->head[2] = __(''); + } + + if ($item['fields']['checks_failed']) { + $table2->head[3] = __('Checks failed'); + } else { + $table2->head[3] = __(''); + } + + if ($item['fields']['checks_in_ok_status']) { + $table2->head[4] = __('Checks OK'); + } else { + $table2->head[4] = __(''); + } + + if ($item['fields']['unknown_checks']) { + $table2->head[5] = __('Checks Uknown'); + } else { + $table2->head[5] = __(''); + } $table2->headstyle = []; $table2->headstyle[0] = 'text-align: left'; @@ -2964,77 +3019,101 @@ function reporting_html_availability($table, $item, $pdf=0) $table2->style[5] = 'text-align: right'; foreach ($item['data'] as $row) { - $the_first_men_time = get_agent_first_time( - io_safe_output($row['agent']) - ); - $table_row = []; $table_row[] = $row['agent']; $table_row[] = $row['availability_item']; - if ($row['time_total'] != 0) { + if ($row['time_total'] != 0 && $item['fields']['total_time']) { $table_row[] = human_time_description_raw( $row['time_total'], true ); - } else { + } else if ($row['time_total'] == 0 && $item['fields']['total_time']) { $table_row[] = '--'; - } + } else { + $table_row[] = ''; + }; - if ($row['time_error'] != 0) { + if ($row['time_error'] != 0 && $item['fields']['time_failed']) { $table_row[] = human_time_description_raw( $row['time_error'], true ); - } else { + } else if ($row['time_error'] == 0 && $item['fields']['time_failed']) { $table_row[] = '--'; - } + } else { + $table_row[] = ''; + }; - if ($row['time_ok'] != 0) { + if ($row['time_ok'] != 0 && $item['fields']['time_in_ok_status']) { $table_row[] = human_time_description_raw( $row['time_ok'], true ); - } else { + } else if ($row['time_ok'] == 0 && $item['fields']['time_in_ok_status']) { $table_row[] = '--'; - } + } else { + $table_row[] = ''; + }; - if ($row['time_unknown'] != 0) { + if ($row['time_unknown'] != 0 && $item['fields']['time_in_unknown_status']) { $table_row[] = human_time_description_raw( $row['time_unknown'], true ); - } else { + } else if ($row['time_unknown'] == 0 && $item['fields']['time_in_unknown_status']) { $table_row[] = '--'; - } + } else { + $table_row[] = ''; + }; - if ($row['time_not_init'] != 0) { + if ($row['time_not_init'] != 0 && $item['fields']['time_of_not_initialized_module']) { $table_row[] = human_time_description_raw( $row['time_not_init'], true ); - } else { + } else if ($row['time_not_init'] == 0 && $item['fields']['time_of_not_initialized_module']) { $table_row[] = '--'; - } + } else { + $table_row[] = ''; + }; - if ($row['time_downtime'] != 0) { + if ($row['time_downtime'] != 0 && $item['fields']['time_of_downtime']) { $table_row[] = human_time_description_raw( $row['time_downtime'], true ); - } else { + } else if ($row['time_downtime'] == 0 && $item['fields']['time_of_downtime']) { $table_row[] = '--'; - } + } else { + $table_row[] = ''; + }; $table_row[] = ''.sla_truncate($row['SLA'], $config['graph_precision']).'%'; $table_row2 = []; $table_row2[] = $row['agent']; $table_row2[] = $row['availability_item']; - $table_row2[] = $row['checks_total']; - $table_row2[] = $row['checks_error']; - $table_row2[] = $row['checks_ok']; - $table_row2[] = $row['checks_unknown']; + if ($item['fields']['total_checks']) { + $table_row2[] = $row['checks_total']; + } else { + $table_row2[] = ''; + }; + if ($item['fields']['checks_failed']) { + $table_row2[] = $row['checks_error']; + } else { + $table_row2[] = ''; + }; + if ($item['fields']['checks_in_ok_status']) { + $table_row2[] = $row['checks_ok']; + } else { + $table_row2[] = ''; + }; + if ($item['fields']['unknown_checks']) { + $table_row2[] = $row['checks_unknown']; + } else { + $table_row2[] = ''; + }; $table1->data[] = $table_row; $table2->data[] = $table_row2; @@ -3073,7 +3152,7 @@ function reporting_html_availability($table, $item, $pdf=0) if ($item['resume']['resume'] && !empty($item['data'])) { $table1->width = '99%'; $table1->data = []; - if ((strpos($item['resume']['min_text'], $same_agent_in_resume) === false)) { + if (empty($same_agent_in_resume) || (strpos($item['resume']['min_text'], $same_agent_in_resume) === false)) { $table1->head = []; $table1->head['max_text'] = __('Agent max value'); $table1->head['max'] = __('Max Value'); @@ -3108,6 +3187,19 @@ function reporting_html_availability($table, $item, $pdf=0) ).'%', 'avg' => ''.sla_truncate($item['resume']['avg'], $config['graph_precision']).'%', ]; + if ($item['fields']['agent_max_value'] == false) { + $table1->head['max_text'] = ''; + $table1->data[0]['max_text'] = ''; + $table1->head['max'] = ''; + $table1->data[0]['max'] = ''; + } + + if ($item['fields']['agent_min_value'] == false) { + $table1->head['min_text'] = ''; + $table1->data[0]['min_text'] = ''; + $table1->head['min'] = ''; + $table1->data[0]['min'] = ''; + } if ($pdf === 0) { $table->colspan[3][0] = 3; @@ -3276,9 +3368,8 @@ function get_agent_first_time($agent_name) $id = agents_get_agent_id($agent_name, true); $utimestamp = db_get_all_rows_sql( - 'SELECT utimestamp FROM tagente_datos WHERE id_agente_modulo IN - (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = '.$id.') - ORDER BY utimestamp ASC LIMIT 1' + 'SELECT min(utimestamp) FROM tagente_datos WHERE id_agente_modulo IN + (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = '.$id.')' ); $utimestamp = $utimestamp[0]['utimestamp']; @@ -4737,6 +4828,65 @@ function reporting_get_event_histogram_meta($width) } +/** + * Print network traffic data into top n tables + * (one for received data and another for sent) + * + * @param stdClass Table class to paint the report + * @param array Associative array with info about + * @param bool Unused + */ +function reporting_html_nt_top_n($table, $item, $mini) +{ + // Prepare the table + $table_top = new stdClass(); + $table_top->cellpadding = 0; + $table_top->cellspacing = 0; + $table_top->width = '100%'; + $table_top->class = 'databox data'; + $table_top->cellpadding = 0; + $table_top->cellspacing = 0; + $table_top->width = '100%'; + $table_top->class = 'databox data'; + $table_top->head['host'] = __('Agent'); + $table_top->head['bytes'] = __('Kilobytes'); + $table_top->head['pkts'] = __('Packages'); + + // Build the table for sent packages + if (empty($item['data']['send'])) { + $table->data['send_title'] = '

    '.__('No network traffic sent data').'

    '; + } else { + foreach ($item['data']['send'] as $s_item) { + $table_top->data[] = [ + 'host' => $s_item['host'], + 'bytes' => remove_right_zeros(number_format(($s_item['sum_bytes'] / 1024), $config['graph_precision'])), + 'pkts' => remove_right_zeros(number_format($s_item['sum_pkts'], $config['graph_precision'])), + ]; + } + + $table->data['send_title'] = '

    '.__('Network traffic sent').'

    '; + $table->data['send'] = html_print_table($table_top, true); + } + + // Reset the table and build the table for received packages + $table_top->data = []; + if (empty($item['data']['send'])) { + $table->data['recv_title'] = '

    '.__('No network traffic received data').'

    '; + } else { + foreach ($item['data']['recv'] as $s_item) { + $table_top->data[] = [ + 'host' => $s_item['host'], + 'bytes' => remove_right_zeros(number_format(($s_item['sum_bytes'] / 1024), $config['graph_precision'])), + 'pkts' => remove_right_zeros(number_format($s_item['sum_pkts'], $config['graph_precision'])), + ]; + } + + $table->data['recv_title'] = '

    '.__('Network traffic received').'

    '; + $table->data['recv'] = html_print_table($table_top, true); + } +} + + function reporting_html_planned_downtimes_table($planned_downtimes) { global $config; @@ -4767,7 +4917,7 @@ function reporting_html_planned_downtimes_table($planned_downtimes) if ($for_pdf) { $table->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey'; - $table->class = 'table_sla table_beauty'; + $table->class = 'table_sla'; for ($i = 0; $i < count($table->head); $i++) { $table->headstyle[$i] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; diff --git a/pandora_console/include/functions_reporting_xml.php b/pandora_console/include/functions_reporting_xml.php index d1b28ac2a0..91e3288d83 100644 --- a/pandora_console/include/functions_reporting_xml.php +++ b/pandora_console/include/functions_reporting_xml.php @@ -11,10 +11,10 @@ // 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. -require_once 'include/functions_modules.php'; -require_once 'include/functions_events.php'; -require_once 'include/functions_groups.php'; -require_once 'include/functions_netflow.php'; +require_once __DIR__.'/functions_modules.php'; +require_once __DIR__.'/functions_events.php'; +require_once __DIR__.'/functions_groups.php'; +require_once __DIR__.'/functions_netflow.php'; enterprise_include_once('include/functions_metaconsole.php'); @@ -31,7 +31,7 @@ function reporting_xml_get_report($report, $filename, $return=false) unset($report['private']); unset($report['custom_logo']); // ---------------------------------------------------------------------- - // change agent name + // change agent name. if (count($report['contents']) > 0) { for ($i = 0; $i < count($report['contents']); $i++) { $aux = explode('-', $report['contents'][$i]['subtitle']); @@ -44,16 +44,18 @@ function reporting_xml_get_report($report, $filename, $return=false) $xml = preg_replace('/(<[^>]+>)(<[^>]+>)(<[^>]+>)/', "$1\n$2\n$3", $xml); $xml = preg_replace('/(<[^>]+>)(<[^>]+>)/', "$1\n$2", $xml); - // Return if is marked to return + // Return if is marked to return. if ($return) { return $xml; } - // Download if marked to download - header('Content-Type: application/xml; charset=UTF-8'); - header('Content-Disposition: attachment; filename="'.$filename.'.xml"'); + // Download if marked to download. + if ($filename !== false) { + header('Content-Type: application/xml; charset=UTF-8'); + header('Content-Disposition: attachment; filename="'.$filename.'.xml"'); + } - // Clean the output buffer + // Clean the output buffer. ob_clean(); echo $xml; diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index fd68aa0da2..0bf1f8fe70 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -867,18 +867,10 @@ function reports_get_report_types($template=false, $not_editor=false) 'optgroup' => __('Netflow'), 'name' => __('Netflow area chart'), ]; - $types['netflow_pie'] = [ - 'optgroup' => __('Netflow'), - 'name' => __('Netflow pie chart'), - ]; $types['netflow_data'] = [ 'optgroup' => __('Netflow'), 'name' => __('Netflow data table'), ]; - $types['netflow_statistics'] = [ - 'optgroup' => __('Netflow'), - 'name' => __('Netflow statistics table'), - ]; $types['netflow_summary'] = [ 'optgroup' => __('Netflow'), 'name' => __('Netflow summary table'), @@ -892,5 +884,10 @@ function reports_get_report_types($template=false, $not_editor=false) ]; } + $types['nt_top_n'] = [ + 'optgroup' => __('Network traffic'), + 'name' => __('Network Traffic Top N'), + ]; + return $types; } diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index ba6659ddc1..0850dcbfac 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -88,6 +88,58 @@ function servers_force_recon_task($id_recon_task) } +/** + * Retrieves total number of modules per server. + * + * @return array Modules per server (total). + */ +function servers_get_total_modules() +{ + $modules = []; + + $modules_from_monitors = db_get_all_rows_sql( + 'SELECT + tserver.server_type, + count(tagente_estado.id_agente_modulo) as modules_assigned + FROM tserver, tagente_estado, tagente_modulo, tagente + WHERE tagente.disabled=0 + AND tagente_modulo.id_agente = tagente.id_agente + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND tagente_estado.running_by = tserver.id_server + GROUP BY tserver.server_type;' + ); + + if ($modules_from_monitors !== false) { + $modules = array_reduce( + $modules_from_monitors, + function ($carry, $item) { + $carry[$item['server_type']] = $item['modules_assigned']; + return $carry; + } + ); + } + + $modules[SERVER_TYPE_INVENTORY] = db_get_sql( + 'SELECT COUNT(tagent_module_inventory.id_agent_module_inventory) + FROM tagente, tagent_module_inventory + WHERE tagente.disabled=0 + AND tagent_module_inventory.id_agente = tagente.id_agente' + ); + + $modules[SERVER_TYPE_EXPORT] = db_get_sql( + 'SELECT COUNT(tagente_modulo.id_agente_modulo) + FROM tagente, tagente_modulo + WHERE tagente.disabled=0 + AND tagente_modulo.id_agente = tagente.id_agente + AND tagente_modulo.id_export != 0' + ); + + return $modules; + +} + + /** * This function will get several metrics from the database to get info about server performance * @@ -989,6 +1041,9 @@ function servers_get_server_string_name(int $server) case SERVER_TYPE_WUX: return __('WUX server'); + case SERVER_TYPE_ENTERPRISE_SATELLITE: + return __('Satellite'); + default: return __('N/A'); } diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index fd68b77e54..ca2b2d055b 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -41,23 +41,38 @@ $nfdump_date_format = 'Y/m/d.H:i:s'; /** - * Selects all netflow filters (array (id_name => id_name)) or filters filtered + * Generates a Tree with given $tree information. * - * @param tree string SNMP tree returned by snmp_broser_get_tree. - * @param id string Level ID. Do not set, used for recursion. - * @param depth string Branch depth. Do not set, used for recursion. + * Selects all netflow filters (array (id_name => id_name)) or filters filtered + * Used also in Cloud Wizard. + * + * @param string $tree SNMP tree returned by snmp_broser_get_tree. + * @param string $id Level ID. Do not set, used for recursion. + * @param string $depth Branch depth. Do not set, used for recursion. + * @param integer $last Last. + * @param array $last_array Last_array. + * @param string $sufix Sufix. + * @param array $checked Checked. + * @param boolean $descriptive_ids Descriptive_ids. + * @param string $previous_id Previous_id. + * + * @return string HTML code with complete tree. */ -function snmp_browser_print_tree( +function snmp_browser_get_html_tree( $tree, $id=0, $depth=0, $last=0, $last_array=[], $sufix=false, - $checked=[] + $checked=[], + $descriptive_ids=false, + $previous_id='' ) { static $url = false; + $output = ''; + // Get the base URL for images. if ($url === false) { $url = ui_get_full_url('operation/tree', false, false, false); @@ -65,17 +80,17 @@ function snmp_browser_print_tree( // Leaf. if (empty($tree['__LEAVES__'])) { - return; + return ''; } $count = 0; - $total = (sizeof(array_keys($tree['__LEAVES__'])) - 1); + $total = (count(array_keys($tree['__LEAVES__'])) - 1); $last_array[$depth] = $last; if ($depth > 0) { - echo " @@ -293,7 +314,8 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t + $form_items['percentile_item_row_6']['html'] = ''; - // Insert and modify before the buttons to create or update. + if (!$config['legacy_vc']) { + $intervals = [ + 10 => '10 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '1 '.__('minutes'), + 300 => '5 '.__('minutes'), + 900 => '15 '.__('minutes'), + 1800 => '30 '.__('minutes'), + 3600 => '1 '.__('hour'), + ]; + + $form_items_advance['cache_expiration_row'] = []; + $form_items_advance['cache_expiration_row']['items'] = [ + 'static_graph', + 'percentile_bar', + 'percentile_item', + 'module_graph', + 'simple_value', + 'datos', + 'auto_sla_graph', + 'group_item', + 'bars_graph', + 'donut_graph', + 'color_cloud', + 'service', + ]; + $form_items_advance['cache_expiration_row']['html'] = ''; + $form_items_advance['cache_expiration_row']['html'] .= ''; + } + + // Insert and modify before the buttons to create or update. if (enterprise_installed()) { - enterprise_visual_map_editor_modify_form_items_advance_palette($form_items_advance); + enterprise_visual_map_editor_modify_form_items_advance_palette( + $form_items_advance + ); } foreach ($form_items_advance as $item => $item_options) { @@ -1386,6 +1435,10 @@ function visual_map_editor_print_hack_translate_strings() echo "

    ".__('Could not be save.').'

    '; echo ''; + echo "'; + } @@ -1394,6 +1447,9 @@ function visual_map_editor_print_hack_translate_strings() "; if (!$return) { @@ -354,8 +354,19 @@ function ux_console_phases_donut($phases, $id, $return=false) } -function d3_progress_bar($id, $percentile, $width, $height, $color, $unit='%', $text='', $fill_color='#FFFFFF') -{ +function d3_progress_bar( + $id, + $percentile, + $width, + $height, + $color, + $unit='%', + $text='', + $fill_color='#FFFFFF', + $radiusx=10, + $radiusy=10, + $transition=1 +) { global $config; $recipient_name = 'progress_bar_'.$id; @@ -366,8 +377,20 @@ function d3_progress_bar($id, $percentile, $width, $height, $color, $unit='%', $ $output .= '
    "; $output .= include_javascript_d3(true); $output .= ""; + progress_bar_d3( + '".$recipient_name_to_js."', + ".(int) $percentile.', + '.(int) $width.', + '.(int) $height.", + '".$color."', + '".$unit."', + '".$text."', + '".$fill_color."', + ".(int) $radiusx.', + '.(int) $radiusy.', + '.(int) $transition.' + ); + '; return $output; } @@ -392,7 +415,7 @@ function d3_progress_bubble($id, $percentile, $width, $height, $color, $unit='%' } -function progress_circular_bar($id, $percentile, $width, $height, $color, $unit='%', $text='', $fill_color='#FFFFFF') +function progress_circular_bar($id, $percentile, $width, $height, $color, $unit='%', $text='', $fill_color='#FFFFFF', $transition=1) { global $config; @@ -404,7 +427,7 @@ function progress_circular_bar($id, $percentile, $width, $height, $color, $unit= $output .= '
    "; $output .= include_javascript_d3(true); $output .= ""; return $output; @@ -697,3 +720,48 @@ function print_clock_digital_1($time_format, $timezone, $clock_animation, $width return $output; } + + +/** + * Print dougnhnut. + * + * @param array $colors Colors. + * @param integer $width Width. + * @param integer $height Height. + * @param array $data Data. + * @param mixed $data_total Data_total. + * + * @return string HTML. + */ +function print_donut_narrow_graph( + array $colors, + $width, + $height, + array $data, + $data_total +) { + if (empty($data)) { + return graph_nodata_image($width, $height, 'pie'); + } + + $series = count($data); + if (($series != count($colors)) || ($series == 0)) { + return ''; + } + + $data = json_encode($data); + $colors = json_encode($colors); + + $graph_id = uniqid('graph_'); + + $out = "
    "; + $out .= include_javascript_d3(true); + $out .= ""; + + return $out; +} diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 637d02b34b..4492da7834 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -82,9 +82,22 @@ function include_javascript_dependencies_flot_graph($return=false) } -// -// AREA GRAPHS //////// -// +/** + * Function create container for print charts. + * + * @param integer $agent_module_id Id module. + * @param array $array_data Data. + * @param array $legend Legend. + * @param array $series_type Series. + * @param array $color Color. + * @param array $date_array Date. + * @param array $data_module_graph Data module. + * @param array $params Params. + * @param string $water_mark Water. + * @param array $array_events_alerts Events array. + * + * @return string Return graphs. + */ function flot_area_graph( $agent_module_id, $array_data, @@ -99,8 +112,7 @@ function flot_area_graph( ) { global $config; - // include_javascript_dependencies_flot_graph(); - // Get a unique identifier to graph + // Get a unique identifier to graph. $graph_id = uniqid('graph_'); $background_style = ''; @@ -126,19 +138,26 @@ function flot_area_graph( break; } - $padding_vconsole = $params['dashboard'] ? 'padding: 1px 0px 10px 10px;' : ''; + $padding_vconsole = ($params['dashboard']) ? 'padding: 1px 0px 10px 10px;' : ''; - // Parent layer + // Parent layer. $return = "
    "; + + if (empty($params['title']) === false) { + $return .= '

    '.$params['title'].'

    '; + } + // Set some containers to legend, graph, timestamp tooltip, etc. if ($params['show_legend']) { - $return .= "

    "; + $return .= '

    '; } if (isset($params['graph_combined']) && $params['graph_combined'] && (!isset($params['from_interface']) || !$params['from_interface']) ) { - if (isset($params['threshold_data']) && is_array($params['threshold_data'])) { + if (isset($params['threshold_data']) + && is_array($params['threshold_data']) + ) { $yellow_threshold = $params['threshold_data']['yellow_threshold']; $red_threshold = $params['threshold_data']['red_threshold']; $yellow_up = $params['threshold_data']['yellow_up']; @@ -154,7 +173,7 @@ function flot_area_graph( } else if (!isset($params['combined']) || !$params['combined']) { $yellow_threshold = $data_module_graph['w_min']; $red_threshold = $data_module_graph['c_min']; - // Get other required module datas to draw warning and critical + // Get other required module datas to draw warning and critical. if ($agent_module_id == 0) { $yellow_up = 0; $red_up = 0; @@ -166,8 +185,12 @@ function flot_area_graph( $yellow_inverse = !($data_module_graph['w_inv'] == 0); $red_inverse = !($data_module_graph['c_inv'] == 0); } - } else if (isset($params['from_interface']) && $params['from_interface']) { - if (isset($params['threshold_data']) && is_array($params['threshold_data'])) { + } else if (isset($params['from_interface']) + && $params['from_interface'] + ) { + if (isset($params['threshold_data']) + && is_array($params['threshold_data']) + ) { $yellow_threshold = $params['threshold_data']['yellow_threshold']; $red_threshold = $params['threshold_data']['red_threshold']; $yellow_up = $params['threshold_data']['yellow_up']; @@ -200,7 +223,11 @@ function flot_area_graph( ); } - $return .= html_print_input_hidden('line_width_graph', $config['custom_graph_width'], true); + $return .= html_print_input_hidden( + 'line_width_graph', + $config['custom_graph_width'], + true + ); $return .= "
    "; + style='font-size: ".$params['font_size'].'pt; + display:none; position:absolute; overflow: auto; + max-height: '.($params['height'] + 50).'px; + width: '.$extra_width."px; + background:#fff; padding: 2px 2px 2px 2px; + border: solid #000 1px;'>
    "; - // Trick to get translated string from javascript + // Trick to get translated string from javascript. $return .= html_print_input_hidden('unknown_text', __('Unknown'), true); - $values = json_encode($array_data); + $values = json_encode($array_data); + $legend = json_encode($legend); $series_type = json_encode($series_type); $color = json_encode($color); @@ -261,7 +289,7 @@ function flot_area_graph( $params = json_encode($params); $array_events_alerts = json_encode($array_events_alerts); - // Javascript code + // Javascript code. if ($font_size == '') { $font_size = '\'\''; } @@ -272,7 +300,7 @@ function flot_area_graph( $return .= '});'; $return .= ''; - // Parent layer + // Parent layer. $return .= ''; return $return; diff --git a/pandora_console/include/graphs/functions_gd.php b/pandora_console/include/graphs/functions_gd.php index 262ed22bb3..10f566185d 100755 --- a/pandora_console/include/graphs/functions_gd.php +++ b/pandora_console/include/graphs/functions_gd.php @@ -344,9 +344,9 @@ function drawRating($rating, $width, $height, $font, $out_of_lim_str, $mode, $fo $image = imagecreate($width, $height); // colors - $back = imagecolorallocate($image, 255, 255, 255); + $back = imagecolorallocate($image, 241, 241, 241); - $bordercolor = imagecolorallocate($image, 174, 174, 174); + $bordercolor = imagecolorallocate($image, 241, 241, 241); $text = imagecolorallocate($image, 74, 74, 74); $red = imagecolorallocate($image, 255, 60, 75); $green = imagecolorallocate($image, 50, 205, 50); @@ -483,7 +483,7 @@ function gd_progress_bar($width, $height, $progress, $title, $font, $out_of_lim_ break; case 1: - drawRating($progress, $width, $height, $font, $out_of_lim_str, $mode, 6, $value_text, $color); + drawRating($progress, $width, $height, $font, $out_of_lim_str, $mode, 9, $value_text, $color); break; diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js index 40dcd34ac1..427de827e3 100644 --- a/pandora_console/include/graphs/pandora.d3.js +++ b/pandora_console/include/graphs/pandora.d3.js @@ -20,7 +20,7 @@ // matrix = [[0, 0, 2], // a[a => a, a => b, a => c] // [5, 0, 1], // b[b => a, b => b, b => c] // [2, 3, 0]]; // c[c => a, c => b, c => c] -function chordDiagram(recipient, elements, matrix, unit, width) { +function chordDiagram(recipient, elements, matrix, width) { d3.chart = d3.chart || {}; d3.chart.chordWheel = function(options) { // Default values @@ -206,18 +206,14 @@ function chordDiagram(recipient, elements, matrix, unit, width) { " → " + elements[d.target.index] + ": " + - d.source.value.toFixed(2) + - " " + - unit + + valueToBytes(d.source.value) + "" + "
    " + elements[d.target.index] + " → " + elements[d.source.index] + ": " + - d.target.value.toFixed(2) + - " " + - unit + + valueToBytes(d.target.value) + "" ) ); @@ -227,18 +223,14 @@ function chordDiagram(recipient, elements, matrix, unit, width) { " → " + elements[d.target.index] + ": " + - d.source.value.toFixed(2) + - " " + - unit + + valueToBytes(d.source.value) + "" + "
    " + elements[d.target.index] + " → " + elements[d.source.index] + ": " + - d.target.value.toFixed(2) + - " " + - unit + + valueToBytes(d.target.value) + "" ); } @@ -1782,7 +1774,10 @@ function progress_bar_d3( color, unit, label, - label_color + label_color, + radiusx, + radiusy, + transition ) { var startPercent = 0; var endPercent = parseInt(percentile) / 100; @@ -1799,20 +1794,20 @@ function progress_bar_d3( .append("rect") .attr("fill", "#000000") .attr("fill-opacity", 0.5) - .attr("height", 20) + .attr("height", height) .attr("width", width) - .attr("rx", 10) - .attr("ry", 10) + .attr("rx", radiusx) + .attr("ry", radiusy) .attr("x", 0); var progress_front = circle .append("rect") .attr("fill", color) .attr("fill-opacity", 1) - .attr("height", 20) + .attr("height", height) .attr("width", 0) - .attr("rx", 10) - .attr("ry", 10) + .attr("rx", radiusx) + .attr("ry", radiusy) .attr("x", 0); var labelText = circle @@ -1834,7 +1829,7 @@ function progress_bar_d3( .style("font-weight", "bold") .style("font-size", 14) .attr("text-anchor", "middle") - .attr("dy", "-10"); + .attr("dy", (height - height / 2) / 4); function updateProgress(bar_progress) { var percent_value = Number(bar_progress * 100); @@ -1842,17 +1837,21 @@ function progress_bar_d3( progress_front.attr("width", width * bar_progress); } - var bar_progress = startPercent; - - (function loops() { + if (transition == 0) { + var bar_progress = endPercent; updateProgress(bar_progress); + } else { + var bar_progress = startPercent; + (function loops() { + updateProgress(bar_progress); - if (count > 0) { - count--; - bar_progress += step; - setTimeout(loops, 30); - } - })(); + if (count > 0) { + count--; + bar_progress += step; + setTimeout(loops, 30); + } + })(); + } } function progress_bubble_d3( @@ -1981,7 +1980,8 @@ function print_circular_progress_bar( color, unit, label, - label_color + label_color, + transition ) { var twoPi = Math.PI * 2; var radius = width / 2; @@ -2113,15 +2113,18 @@ function print_circular_progress_bar( var progress = startPercent; - (function loops() { - updateProgress(progress); + if (transition == 0) updateProgress(endPercent); + else { + (function loops() { + updateProgress(progress); - if (count > 0) { - count--; - progress += step; - setTimeout(loops, 30); - } - })(); + if (count > 0) { + count--; + progress += step; + setTimeout(loops, 30); + } + })(); + } } function print_interior_circular_progress_bar( @@ -2744,3 +2747,238 @@ function printClockDigital1( setTimeout(tick, 1000 - (now % 1000)); })(); } + +function valueToBytes(value) { + var shorts = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]; + var pos = 0; + while (value >= 1024) { + // As long as the number can be divided by divider. + pos++; + // Position in array starting with 0. + value = value / 1024; + } + + // This will actually do the rounding and the decimals. + return value.toFixed(2) + shorts[pos] + "B"; +} + +function donutNarrowGraph(colores, width, height, total) { + // Default settings + var donutbody = d3.select("body"); + var data = {}; + // var showTitle = true; + + if (width == "") { + width = 180; + } + + if (height == "") { + height = 180; + } + + var radius = Math.min(width, height) / 2; + + var currentVal; + //var color = d3.scale.category20(); + + var colores_index = []; + var colores_value = []; + + $.each(colores, function(index, value) { + colores_index.push(index); + colores_value.push(value); + }); + + var color = d3.scale + .ordinal() + .domain(colores_index) + .range(colores_value); + + var pie = d3.layout + .pie() + .sort(null) + .value(function(d) { + return d.value; + }); + + var svg, g, arc; + + var object = {}; + + // Method for render/refresh graph + object.render = function() { + if (!svg) { + // Show normal status by default. This variable must be initialized here, before clearing data. + var normal_status = data.Normal; + + // Don't draw 0 or invalid values. console.log(data); + var data_map = $.map(data, function(value, index) { + if (value == 0 || isNaN(value)) { + return index; + } + }); + + $.each(data_map, function(i, val) { + delete data[val]; + }); + //New data: console.log(data); + + arc = d3.svg + .arc() + .outerRadius(radius) + .innerRadius(radius - radius / 2.5); + + svg = donutbody + .append("svg") + .attr("width", width) + .attr("height", height) + .append("g") + .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); + + g = svg + .selectAll(".arc") + .data(pie(d3.entries(data))) + .enter() + .append("g") + .attr("class", "arc"); + + g.append("path") + // Attach current value to g so that we can use it for animation + .each(function(d) { + this._current = d; + }) + .attr("d", arc) + .attr("stroke", "white") + .style("stroke-width", 2) + .style("fill", function(d) { + return color(d.data.key); + }); + // This is to show labels on the graph + /* g.append("text") + .attr("transform", function(d) { + return "translate(" + arc.centroid(d) + ")"; + }) + .attr("dy", ".35em") + .style("text-anchor", "middle"); + g.select("text").text(function(d) { + return d.data.key; + });*/ + + // Show normal status by default. + var percentage_normal; + svg + .append("text") + .datum(data) + .attr("x", 0) + .attr("y", 0 + radius / 10) + .attr("class", "text-tooltip") + .style("text-anchor", "middle") + .attr("font-weight", "bold") + .style("font-family", "Arial, Verdana") + //.attr("fill", "#82b92e") + .style("font-size", function(d) { + if (normal_status) { + percentage_normal = (normal_status * 100) / total; + if (Number.isInteger(percentage_normal)) { + percentage_normal = percentage_normal.toFixed(0); + return radius / 3 + "px"; + } else { + percentage_normal = percentage_normal.toFixed(1); + return radius / 3.5 + "px"; + } + } + }) + .text(function(d) { + if (normal_status) { + return percentage_normal + "%"; + } else { + return "0%"; + } + }); + + g.on("mouseover", function(obj) { + //console.log(obj); + var percentage; + svg + .select("text.text-tooltip") + // This is to paint the text of the corresponding color. + /* .attr("fill", function(d) { + return color(obj.data.key); + })*/ + .style("font-size", function(d) { + percentage = (d[obj.data.key] * 100) / total; + if (Number.isInteger(percentage)) { + percentage = percentage.toFixed(0); + return radius / 3 + "px"; + } else { + percentage = percentage.toFixed(1); + return radius / 3.5 + "px"; + } + }) + .text(percentage + "%"); + }); + + g.on("mouseout", function(obj) { + svg.select("text.text-tooltip").text(function(d) { + if (normal_status) { + return percentage_normal + "%"; + } else { + return "0%"; + } + }); + // .attr("fill", "#82b92e"); + }); + } else { + g.data(pie(d3.entries(data))) + .exit() + .remove(); + + g.select("path") + .transition() + .duration(200) + .attrTween("d", function(a) { + var i = d3.interpolate(this._current, a); + this._current = i(0); + return function(t) { + return arc(i(t)); + }; + }); + + g.select("text").attr("transform", function(d) { + return "translate(" + arc.centroid(d) + ")"; + }); + + svg.select("text.text-tooltip").datum(data); + } + return object; + }; + + // Getter and setter methods + object.data = function(value) { + if (!arguments.length) return data; + data = value; + return object; + }; + + object.donutbody = function(value) { + if (!arguments.length) return donutbody; + donutbody = value; + return object; + }; + + object.width = function(value) { + if (!arguments.length) return width; + width = value; + radius = Math.min(width, height) / 2; + return object; + }; + + object.height = function(value) { + if (!arguments.length) return height; + height = value; + radius = Math.min(width, height) / 2; + return object; + }; + + return object; +} diff --git a/pandora_console/include/help/clippy/modules_not_learning_mode.php b/pandora_console/include/help/clippy/modules_not_learning_mode.php index 85dc5c1182..ff26b065f6 100755 --- a/pandora_console/include/help/clippy/modules_not_learning_mode.php +++ b/pandora_console/include/help/clippy/modules_not_learning_mode.php @@ -1,20 +1,30 @@ true, 'position' => 'left', - 'intro' => '
    ".io_safe_output($extended_event['description'])."".date($config['date_format'], $extended_event['utimestamp']).'".io_safe_output($extended_event['description'])."".date($config['date_format'], $extended_event['utimestamp']).'".io_safe_output($extended_event['description'])."".date($config['date_format'], $extended_event['utimestamp']).'
    '.$text_title.' '; if (!$no_close_bool) { - // Use the no_meta parameter because this image is only in the base console + // Use the no_meta parameter because this image is only in + // the base console. $output .= ''.html_print_image('images/blade.png', true, false, false, false, true).''; } @@ -330,11 +352,12 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t /** * Prints an error message. * - * @param mixed The string error message or array ('title', 'message', 'icon', 'no_close') to be displayed - * @param string Any other attributes to be set for the tag. - * @param bool Whether to output the string or return it - * @param string What tag to use (you could specify something else than - * h3 like div or h2) + * @param mixed $message The string error message or array + * ('title', 'message', 'icon', 'no_close') to be displayed. + * @param string $attributes Any other attributes to be set for the tag. + * @param boolean $return Whether to output the string or return it. + * @param string $tag What tag to use (you could specify something else + * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ @@ -347,11 +370,12 @@ function ui_print_error_message($message, $attributes='', $return=false, $tag='h /** * Prints an operation success message. * - * @param mixed The string message or array ('title', 'message', 'icon', 'no_close') to be displayed - * @param string Any other attributes to be set for the tag. - * @param bool Whether to output the string or return it - * @param string What tag to use (you could specify something else than - * h3 like div or h2) + * @param mixed $message The string message or array + * ('title', 'message', 'icon', 'no_close') to be displayed. + * @param string $attributes Any other attributes to be set for the tag. + * @param boolean $return Whether to output the string or return it. + * @param string $tag What tag to use (you could specify something else + * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ @@ -364,11 +388,12 @@ function ui_print_success_message($message, $attributes='', $return=false, $tag= /** * Prints an operation info message. * - * @param mixed The string message or array ('title', 'message', 'icon', 'no_close') to be displayed - * @param string Any other attributes to be set for the tag. - * @param bool Whether to output the string or return it - * @param string What tag to use (you could specify something else than - * h3 like div or h2) + * @param mixed $message The string message or array + * ('title', 'message', 'icon', 'no_close') to be displayed. + * @param string $attributes Any other attributes to be set for the tag. + * @param boolean $return Whether to output the string or return it. + * @param string $tag What tag to use (you could specify something else + * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ @@ -378,6 +403,18 @@ function ui_print_info_message($message, $attributes='', $return=false, $tag='h3 } +/** + * Prints an operation info message - empty data. + * + * @param mixed $message The string message or array + * ('title', 'message', 'icon', 'no_close') to be displayed. + * @param string $attributes Any other attributes to be set for the tag. + * @param boolean $return Whether to output the string or return it. + * @param string $tag What tag to use (you could specify something else + * than h3 like div or h2). + * + * @return string HTML code if return parameter is true. + */ function ui_print_empty_data($message, $attributes='', $return=false, $tag='h3') { return ui_print_message($message, 'info', $attributes, $return, $tag); @@ -387,14 +424,16 @@ function ui_print_empty_data($message, $attributes='', $return=false, $tag='h3') /** * Evaluates a result using empty() and then prints an error or success message * - * @param mixed The results to evaluate. 0, NULL, false, '' or - * array() is bad, the rest is good - * @param mixed The string or array ('title', 'message') to be displayed if the result was good - * @param mixed The string or array ('title', 'message') to be displayed if the result was bad - * @param string Any other attributes to be set for the h3 - * @param bool Whether to output the string or return it - * @param string What tag to use (you could specify something else than - * h3 like div or h2) + * @param mixed $result The results to evaluate. 0, NULL, false, '' or + * array() is bad, the rest is good. + * @param mixed $good The string or array ('title', 'message') to be + * displayed if the result was good. + * @param mixed $bad The string or array ('title', 'message') to be + * displayed if the result was bad. + * @param string $attributes Any other attributes to be set for the h3. + * @param boolean $return Whether to output the string or return it. + * @param string $tag What tag to use (you could specify something else + * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ @@ -419,11 +458,12 @@ function ui_print_result_message($result, $good='', $bad='', $attributes='', $re /** * Prints an warning message. * - * @param mixed The string warning message or array ('title', 'message', 'icon', 'no_close') to be displayed - * @param string Any other attributes to be set for the tag. - * @param bool Whether to output the string or return it - * @param string What tag to use (you could specify something else than - * h3 like div or h2) + * @param mixed $message The string message or array + * ('title', 'message', 'icon', 'no_close') to be displayed. + * @param string $attributes Any other attributes to be set for the tag. + * @param boolean $return Whether to output the string or return it. + * @param string $tag What tag to use (you could specify something else + * than h3 like div or h2). * * @return string HTML code if return parameter is true. */ @@ -438,13 +478,13 @@ function ui_print_warning_message($message, $attributes='', $return=false, $tag= * with as title the correctly formatted full timestamp and a time comparation * in the tag * - * @param int Any type of timestamp really, but we prefer unixtime - * @param bool Whether to output the string or return it - * @param array An array with different options for this function - * Key html_attr: which html attributes to add (defaults to none) - * Key tag: Which html tag to use (defaults to span) - * Key prominent: Overrides user preference and display "comparation" or "timestamp" - * key units: The type of units. + * @param integer $unixtime Any type of timestamp really, but we prefer unixtime. + * @param boolean $return Whether to output the string or return it. + * @param array $option An array with different options for this function + * Key html_attr: which html attributes to add (defaults to none) + * Key tag: Which html tag to use (defaults to span) + * Key prominent: Overrides user preference and display "comparation" or "timestamp" + * key units: The type of units. * * @return string HTML code if return parameter is true. */ @@ -452,7 +492,8 @@ function ui_print_timestamp($unixtime, $return=false, $option=[]) { global $config; - // TODO: Add/use a javascript timer for the seconds so it automatically updates as time passes by + // TODO: Add/use a javascript timer for the seconds so it automatically + // updates as time passes by. if (isset($option['html_attr'])) { $attributes = $option['html_attr']; } else { @@ -481,7 +522,7 @@ function ui_print_timestamp($unixtime, $return=false, $option=[]) $unixtime = time_w_fixed_tz($unixtime); } - // prominent_time is either timestamp or comparation + // Prominent_time is either timestamp or comparation. if ($unixtime <= 0) { $title = __('Unknown').'/'.__('Never'); $data = __('Unknown'); @@ -507,13 +548,13 @@ function ui_print_timestamp($unixtime, $return=false, $option=[]) switch ($tag) { default: // Usually tags have title attributes, so by default we add, - // then fall through to add attributes and data + // then fall through to add attributes and data. $output .= ' title="'.$title.'" '.$style.'>'.$data.''; break; case 'h1': case 'h2': case 'h3': - // Above tags don't have title attributes + // Above tags don't have title attributes. $output .= ' '.$attributes.' '.$style.'>'.$data.''; break; } @@ -529,8 +570,8 @@ function ui_print_timestamp($unixtime, $return=false, $option=[]) /** * Prints a username with real name, link to the user_edit page etc. * - * @param string The username to render - * @param bool Whether to return or print + * @param string $username The username to render. + * @param boolean $return Whether to return or print. * * @return string HTML code if return parameter is true. */ @@ -546,6 +587,13 @@ function ui_print_username($username, $return=false) } +/** + * Show a notification. + * + * @param boolean $return Return or direct echo. + * + * @return string HTML. + */ function ui_print_tags_warning($return=false) { $msg = '
    '; @@ -563,11 +611,14 @@ function ui_print_tags_warning($return=false) /** * Print group icon within a link * - * @param int Group id - * @param bool Whether to return or print - * @param string What path to use (relative to images/). Defaults to groups_small - * @param string Style for group image - * @param bool Whether the group have link or not + * @param integer $id_group Group id. + * @param boolean $return Whether to return or print. + * @param string $path What path to use (relative to images/). + * Defaults to groups_small. + * @param string $style Style for group image. + * @param boolean $link Whether the group have link or not. + * @param boolean $force_show_image Force show image. + * @param boolean $show_as_image Show as image. * * @return string HTML code if return parameter is true. */ @@ -583,7 +634,7 @@ function ui_print_group_icon($id_group, $return=false, $path='groups_small', $st $output = ''; - // Don't show link in metaconsole + // Don't show link in metaconsole. if (defined('METACONSOLE')) { $link = false; } @@ -630,9 +681,12 @@ function ui_print_group_icon($id_group, $return=false, $path='groups_small', $st /** * Print group icon within a link. Other version. * - * @param int Group id - * @param bool Whether to return or print - * @param string What path to use (relative to images/). Defaults to groups_small + * @param integer $id_group Group id. + * @param boolean $return Whether to return or print. + * @param string $path What path to use (relative to images/). + * Defaults to groups_small. + * @param string $style Extra styles. + * @param boolean $link Add anchor. * * @return string HTML code if return parameter is true. */ @@ -674,10 +728,15 @@ function ui_print_group_icon_path($id_group, $return=false, $path='images/groups /** * Get the icon of an operating system. * - * @param int Operating system id - * @param bool Whether to also append the name of the OS after the icon - * @param bool Whether to return or echo the result - * @param bool Whether to apply skin or not + * @param integer $id_os Operating system id. + * @param boolean $name Whether to also append the name of OS after icon. + * @param boolean $return Whether to return or echo the result. + * @param boolean $apply_skin Whether to apply skin or not. + * @param boolean $networkmap Networkmap. + * @param boolean $only_src Only_src. + * @param boolean $relative Relative. + * @param boolean $options Options. + * @param boolean $big_icons Big_icons. * * @return string HTML with icon of the OS */ @@ -744,6 +803,18 @@ function ui_print_os_icon( } +/** + * Print type agent icon. + * + * @param boolean $id_os Id_os. + * @param boolean $remote_contact Remote_contact. + * @param boolean $contact Contact. + * @param boolean $return Return. + * @param integer $remote Remote. + * @param string $version Version. + * + * @return string HTML. + */ function ui_print_type_agent_icon( $id_os=false, $remote_contact=false, @@ -753,15 +824,15 @@ function ui_print_type_agent_icon( $version='' ) { if ($id_os == 19) { - // Satellite + // Satellite. $options['title'] = __('Satellite'); $output = html_print_image('images/op_satellite.png', true, $options, false, false, false, true); } else if ($remote_contact == $contact && $remote == 0 && $version == '') { - // Network + // Network. $options['title'] = __('Network'); $output = html_print_image('images/network.png', true, $options, false, false, false, true); } else { - // Software + // Software. $options['title'] = __('Software'); $output = html_print_image('images/data.png', true, $options, false, false, false, true); } @@ -773,20 +844,31 @@ function ui_print_type_agent_icon( /** * Prints an agent name with the correct link * - * @param int Agent id - * @param bool Whether to return the string or echo it too - * @param int Now uses styles to accomplish this - * @param string Style of name in css. - * @param string server url to concatenate at the begin of the link - * @param string extra parameters to concatenate in the link - * @param string name of the agent to avoid the query in some cases - * @param bool if the agent will provided with link or not - * @param bool use the agent alias or the name + * @param integer $id_agent Agent id. + * @param boolean $return Whether to return the string or echo it too. + * @param integer $cutoff Now uses styles to accomplish this. + * @param string $style Style of name in css. + * @param boolean $cutname Cut names. + * @param string $server_url Server url to concatenate at the begin of the link. + * @param string $extra_params Extra parameters to concatenate in the link. + * @param string $known_agent_name Name of the agent to avoid the query in some cases. + * @param boolean $link If the agent will provided with link or not. + * @param boolean $alias Use the agent alias or the name. * * @return string HTML with agent name and link */ -function ui_print_agent_name($id_agent, $return=false, $cutoff='agent_medium', $style='', $cutname=false, $server_url='', $extra_params='', $known_agent_name=false, $link=true, $alias=true) -{ +function ui_print_agent_name( + $id_agent, + $return=false, + $cutoff='agent_medium', + $style='', + $cutname=false, + $server_url='', + $extra_params='', + $known_agent_name=false, + $link=true, + $alias=true +) { if ($known_agent_name === false) { if ($alias) { $agent_name = (string) agents_get_alias($id_agent); @@ -808,14 +890,14 @@ function ui_print_agent_name($id_agent, $return=false, $cutoff='agent_medium', $ } if ($link) { - $url = $server_url.'index.php?sec=estado&'.'sec2=operation/agentes/ver_agente&'.'id_agente='.$id_agent.$extra_params; + $url = $server_url.'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agent.$extra_params; - $output = ''.$agent_name.''; + $output = ''.$agent_name.''; } else { $output = ''.$agent_name.''; } - // TODO: Add a pretty javascript (using jQuery) popup-box with agent details + // TODO: Add a pretty javascript (using jQuery) popup-box with agent details. if ($return) { return $output; } @@ -827,16 +909,19 @@ function ui_print_agent_name($id_agent, $return=false, $cutoff='agent_medium', $ /** * Formats a row from the alert table and returns an array usable in the table function * - * @param array A valid (non empty) row from the alert table - * @param bool Whether or not this is a combined alert - * @param bool Whether to print the agent information with the module information - * @param string Tab where the function was called from (used for urls) - * @param mixed Style for agent name or default (false) + * @param array $alert A valid (non empty) row from the alert table. + * @param boolean $agent Whether or not this is a combined alert. + * @param string $url Tab where the function was called from (used for urls). + * @param mixed $agent_style Style for agent name or default (false). * * @return array A formatted array with proper html for use in $table->data (6 columns) */ -function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) -{ +function ui_format_alert_row( + $alert, + $agent=true, + $url='', + $agent_style=false +) { global $config; if (!isset($alert['server_data'])) { @@ -856,7 +941,7 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) include_once $config['homedir'].'/include/functions_alerts.php'; $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); $id_group = (int) get_parameter('ag_group', 0); - // 0 is the All group (selects all groups) + // 0 is the All group (selects all groups). if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { if ($agent) { $index = [ @@ -956,13 +1041,13 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) $server = db_get_row('tmetaconsole_setup', 'id', $alert['server_data']['id']); if (metaconsole_connect($server) == NOERR) { - // Get agent data from node + // Get agent data from node. $agente = db_get_row('tagente', 'id_agente', $alert['id_agent']); metaconsole_restore_db(); } } else { - // Get agent id + // Get agent id. $id_agent = modules_get_agentmodule_agent($alert['id_agent_module']); $agente = db_get_row('tagente', 'id_agente', $id_agent); } @@ -972,6 +1057,25 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) $data = []; + // Validate checkbox. + if (!defined('METACONSOLE')) { + if (check_acl($config['id_user'], $id_group, 'LW') + || check_acl($config['id_user'], $id_group, 'LM') + ) { + $data[$index['validate']] = ''; + + $data[$index['validate']] .= html_print_checkbox( + 'validate[]', + $alert['id'], + false, + true, + false, + '', + true + ); + } + } + if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { if (is_metaconsole()) { $node = metaconsole_get_connection_by_id($alert['server_data']['id']); @@ -979,7 +1083,6 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) // Restore the default connection. metaconsole_restore_db(); $errors++; - // break; It does not work in the php7 version remplace for: return false; } } @@ -1001,14 +1104,14 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) } } - // Standby + // Standby. $data[$index['standby']] = ''; if (isset($alert['standby']) && $alert['standby'] == 1) { $data[$index['standby']] = html_print_image('images/bell_pause.png', true, ['title' => __('Standby on')]); } if (!defined('METACONSOLE')) { - // Force alert execution + // Force alert execution. if (check_acl($config['id_user'], $id_group, 'AW') || check_acl($config['id_user'], $id_group, 'LM')) { if ($alert['force_execution'] == 0) { $data[$index['force_execution']] = ''.html_print_image('images/target.png', true, ['border' => '0', 'title' => __('Force')]).''; @@ -1078,7 +1181,12 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) $actionText .= '
    '; } else { if ($actionDefault != '') { - $actionText = db_get_sql("SELECT name FROM talert_actions WHERE id = $actionDefault").' ('.__('Default').')'; + $actionText = db_get_sql( + sprintf( + 'SELECT name FROM talert_actions WHERE id = %d', + $actionDefault + ) + ).' ('.__('Default').')'; } } @@ -1102,22 +1210,6 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) $data[$index['status']] = ui_print_status_image($status, $title, true); - if (!defined('METACONSOLE')) { - if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) { - $data[$index['validate']] = ''; - - $data[$index['validate']] .= html_print_checkbox( - 'validate[]', - $alert['id'], - false, - true, - false, - '', - true - ); - } - } - return $data; } @@ -1125,12 +1217,12 @@ function ui_format_alert_row($alert, $agent=true, $url='', $agent_style=false) /** * Prints a substracted string, length specified by cutoff, the full string will be in a rollover. * - * @param string The string to be cut - * @param int At how much characters to cut - * @param bool Whether to return or print it out - * @param int Size font (fixed) in px, applyed as CSS style (optional) + * @param string $string The string to be cut.. + * @param integer $cutoff At how much characters to cut. + * @param boolean $return Whether to return or print it out. + * @param integer $fontsize Size font (fixed) in px, applyed as CSS style (optional). * - * @return An HTML string + * @return string HTML string. */ function ui_print_string_substr($string, $cutoff=16, $return=false, $fontsize=0) { @@ -1151,7 +1243,8 @@ function ui_print_string_substr($string, $cutoff=16, $return=false, $fontsize=0) $font_size_mod = "style='font-size: ".$fontsize."pt'"; } - $string = ''.mb_substr($string2, 0, $cutoff, 'UTF-8').$string3.''; + $string = ''; + $string .= mb_substr($string2, 0, $cutoff, 'UTF-8').$string3.''; if ($return === false) { echo $string; @@ -1165,9 +1258,9 @@ function ui_print_string_substr($string, $cutoff=16, $return=false, $fontsize=0) * Gets a helper text explaining the requirement needs for an alert template * to get it fired. * - * @param int Alert template id. - * @param bool Wheter to return or print it out. - * @param bool Wheter to put the values in the string or not. + * @param integer $id_alert_template Alert template id. + * @param boolean $return Wheter to return or print it out. + * @param boolean $print_values Wheter to put the values in the string or not. * * @return An HTML string if return was true. */ @@ -1181,21 +1274,21 @@ function ui_print_alert_template_example($id_alert_template, $return=false, $pri switch ($template['type']) { case 'equal': - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is '); break; case 'not_equal': - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is not '); break; case 'regex': if ($template['matches_value']) { - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the value matches '); } else { - // end if + // End if. $output .= __('The alert would fire when the value doesn\'t match '); } @@ -1204,42 +1297,46 @@ function ui_print_alert_template_example($id_alert_template, $return=false, $pri case 'max_min': if ($template['matches_value']) { - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is between and '); } else { - // end if + // End if. $output .= __('The alert would fire when the value is not between and '); } break; case 'max': - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is over '); - break; case 'min': - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the value is under '); - break; case 'warning': - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the module is in warning status'); - break; case 'critical': - // Do not translate the HTML attributes + // Do not translate the HTML attributes. $output .= __('The alert would fire when the module is in critical status'); break; + + default: + // Do nothing. + $output .= __('Unknown option.'); + break; } if ($print_values) { /* - Replace span elements with real values. This is done in such way to avoid - duplicating strings and make it easily modificable via Javascript. */ + * Replace span elements with real values. This is done in such way to avoid + * duplicating strings and make it easily modificable via Javascript. + */ + $output = str_replace('', $template['value'], $output); $output = str_replace('', $template['max_value'], $output); $output = str_replace('', $template['min_value'], $output); @@ -1257,19 +1354,26 @@ function ui_print_alert_template_example($id_alert_template, $return=false, $pri /** * Prints a help tip icon. * - * @param string Id of the help article - * @param bool Whether to return or output the result - * @param string Home url if its necessary - * @param string Image path - * @param bool Route is relative or not + * @param string $help_id Id of the help article. + * @param boolean $return Whether to return or output the result. + * @param string $home_url Home url if its necessary. + * @param string $image Image path. + * @param boolean $is_relative Route is relative or not. + * @param string $id Target id. * * @return string The help tip */ -function ui_print_help_icon($help_id, $return=false, $home_url='', $image='images/help.png', $is_relative=false) -{ +function ui_print_help_icon( + $help_id, + $return=false, + $home_url='', + $image='images/help_green.png', + $is_relative=false, + $id='' +) { global $config; - // Do not display the help icon if help is disabled + // Do not display the help icon if help is disabled. if ($config['disable_help']) { return ''; } @@ -1282,13 +1386,16 @@ function ui_print_help_icon($help_id, $return=false, $home_url='', $image='image $home_url = '../../'.$home_url; } + $url = get_help_info($help_id); + $output = html_print_image( $image, true, [ 'class' => 'img_help', 'title' => __('Help'), - 'onclick' => "open_help ('".$help_id."','".$home_url."','".$config['id_user']."')", + 'onclick' => "open_help ('".$url."')", + 'id' => $id, ], false, $is_relative && is_metaconsole() @@ -1308,12 +1415,13 @@ function ui_print_help_icon($help_id, $return=false, $home_url='', $image='image * file name should be like "name.css". The "name" would be the value * needed to pass to this function. * - * @param string Script name to add without the "jquery." prefix and the ".js" + * @param string $name Script name to add without the "jquery." prefix and the ".js" * suffix. Example: * * ui_require_css_file ('pandora'); * // Would include include/styles/pandora.js - * + * . + * @param string $path Path where script is placed. * * @return boolean True if the file was added. False if the file doesn't exist. */ @@ -1350,13 +1458,14 @@ function ui_require_css_file($name, $path='include/styles/') * file name should be like "name.js". The "name" would be the value * needed to pass to this function. * - * @param string Script name to add without the "jquery." prefix and the ".js" - * suffix. Example: - * - * ui_require_javascript_file ('pandora'); - * // Would include include/javascript/pandora.js - * - * @param bool Just echo the script tag of the file. + * @param string $name Script name to add without the "jquery." prefix and the ".js" + * suffix. Example: + * + * ui_require_javascript_file ('pandora'); + * // Would include include/javascript/pandora.js + * . + * @param string $path Path where script is placed. + * @param boolean $echo_tag Just echo the script tag of the file. * * @return boolean True if the file was added. False if the file doesn't exist. */ @@ -1368,7 +1477,7 @@ function ui_require_javascript_file($name, $path='include/javascript/', $echo_ta if ($echo_tag) { echo ''; - return; + return null; } if (! isset($config['js'])) { @@ -1379,7 +1488,7 @@ function ui_require_javascript_file($name, $path='include/javascript/', $echo_ta return true; } - // We checks two paths because it may fails on enterprise + // We checks two paths because it may fails on enterprise. if (! file_exists($filename) && ! file_exists($config['homedir'].'/'.$filename)) { return false; } @@ -1401,12 +1510,14 @@ function ui_require_javascript_file($name, $path='include/javascript/', $echo_ta * file name should be like "name.js". The "name" would be the value * needed to pass to this function. * - * @param string Script name to add without the "jquery." prefix and the ".js" - * suffix. Example: - * - * ui_require_javascript_file ('pandora'); - * // Would include include/javascript/pandora.js - * + * @param string $name Script name to add without the "jquery." + * prefix and the ".js" + * suffix. Example: + * + * ui_require_javascript_file ('pandora'); + * // Would include include/javascript/pandora.js + * . + * @param boolean $disabled_metaconsole Disabled metaconsole. * * @return boolean True if the file was added. False if the file doesn't exist. */ @@ -1429,7 +1540,7 @@ function ui_require_javascript_file_enterprise($name, $disabled_metaconsole=fals return true; } - // We checks two paths because it may fails on enterprise + // We checks two paths because it may fails on enterprise. if (!file_exists($filename) && !file_exists($config['homedir'].'/'.$filename) ) { @@ -1450,13 +1561,14 @@ function ui_require_javascript_file_enterprise($name, $disabled_metaconsole=fals * needed to pass to this function. Notice that this function does not manage * jQuery denpendencies. * - * @param string Script name to add without the "jquery." prefix and the ".js" - * suffix. Example: - * - * ui_require_jquery_file ('form'); - * // Would include include/javascript/jquery.form.js - * - * @param bool Just echo the script tag of the file. + * @param string $name Script name to add without the "jquery." prefix and the ".js" + * suffix. Example: + * + * ui_require_jquery_file ('form'); + * // Would include include/javascript/jquery.form.js + * . + * @param string $path Path where script is placed. + * @param boolean $echo_tag Just echo the script tag of the file. * * @return boolean True if the file was added. False if the file doesn't exist. */ @@ -1468,7 +1580,7 @@ function ui_require_jquery_file($name, $path='include/javascript/', $echo_tag=fa if ($echo_tag) { echo ''; - return; + return null; } if (! isset($config['jquery'])) { @@ -1479,8 +1591,10 @@ function ui_require_jquery_file($name, $path='include/javascript/', $echo_tag=fa return true; } - // We checks two paths because it may fails on enterprise - if (! file_exists($filename) && ! file_exists($config['homedir'].'/'.$filename)) { + // We checks two paths because it may fails on enterprise. + if (! file_exists($filename) + && ! file_exists($config['homedir'].'/'.$filename) + ) { return false; } @@ -1499,8 +1613,8 @@ function ui_require_jquery_file($name, $path='include/javascript/', $echo_tag=fa * To add css just put them in include/styles and then add them to the * $config['css'] array * - * @param string Callback will fill this with the current buffer. - * @param bitfield Callback will fill this with a bitfield (see ob_start) + * @param string $string Callback will fill this with the current buffer. + * @param mixed $bitfield Callback will fill this with a bitfield (see ob_start). * * @return string String to return to the browser */ @@ -1510,7 +1624,7 @@ function ui_process_page_head($string, $bitfield) global $vc_public_view; if (isset($config['ignore_callback']) && $config['ignore_callback'] == true) { - return; + return ''; } $output = ''; @@ -1520,7 +1634,7 @@ function ui_process_page_head($string, $bitfield) $config_refr = $config['refr']; } - // If user is logged or displayed view is the public view of visual console + // If user is logged or displayed view is the public view of visual console. if ($config_refr > 0 && (isset($config['id_user']) || $vc_public_view == 1) ) { @@ -1533,8 +1647,13 @@ function ui_process_page_head($string, $bitfield) || $_GET['sec2'] == 'enterprise/dashboard/main_dashboard' ) { $query = ui_get_url_refresh(false, false); - // $output .= ''; + + /* + * $output .= ''; + */ + + // End. } } @@ -1554,7 +1673,8 @@ function ui_process_page_head($string, $bitfield) '; if ($config['language'] != 'en') { - // Load translated strings - load them last so they overload all the objects + // Load translated strings - load them last so they overload all + // the objects. ui_require_javascript_file('time_'.$config['language']); ui_require_javascript_file('date'.$config['language']); ui_require_javascript_file('countdown_'.$config['language']); @@ -1562,27 +1682,32 @@ function ui_process_page_head($string, $bitfield) $output .= "\n\t"; - // - // Load CSS - // + /* + * Load CSS + */ + if (empty($config['css'])) { $config['css'] = []; } $login_ok = true; if (! isset($config['id_user']) && isset($_GET['login'])) { - if (isset($_POST['nick']) and isset($_POST['pass'])) { + if (isset($_POST['nick']) && isset($_POST['pass'])) { $nick = get_parameter_post('nick'); - // This is the variable with the login + // This is the variable with the login. $pass = get_parameter_post('pass'); - // This is the variable with the password + // This is the variable with the password. $nick = db_escape_string_sql($nick); $pass = db_escape_string_sql($pass); - // process_user_login is a virtual function which should be defined in each auth file. - // It accepts username and password. The rest should be internal to the auth file. - // The auth file can set $config["auth_error"] to an informative error output or reference their internal error messages to it - // process_user_login should return false in case of errors or invalid login, the nickname if correct + // Process_user_login is a virtual function which should be defined + // in each auth file. + // It accepts username and password. The rest should be internal to + // the auth file. + // The auth file can set $config["auth_error"] to an informative + // error output or reference their internal error messages to it + // process_user_login should return false in case of errors or + // invalid login, the nickname if correct. $nick_in_db = process_user_login($nick, $pass); if ($nick_in_db === false) { @@ -1592,7 +1717,7 @@ function ui_process_page_head($string, $bitfield) } // First, if user has assigned a skin then try to use css files of - // skin subdirectory + // skin subdirectory. $isFunctionSkins = enterprise_include_once('include/functions_skins.php'); if (!$login_ok) { if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { @@ -1601,8 +1726,8 @@ function ui_process_page_head($string, $bitfield) } $exists_css = false; - if ($login_ok and $isFunctionSkins !== ENTERPRISE_NOT_HOOK) { - // Checks if user's skin is available + if ($login_ok && $isFunctionSkins !== ENTERPRISE_NOT_HOOK) { + // Checks if user's skin is available. $exists_skin = enterprise_hook('skins_is_path_set'); if ($exists_skin) { $skin_path = enterprise_hook('skins_get_skin_path'); @@ -1611,23 +1736,22 @@ function ui_process_page_head($string, $bitfield) } } - // Add the jquery UI styles CSS + // Add the jquery UI styles CSS. $config['css']['jquery-UI'] = 'include/styles/js/jquery-ui.min.css'; - // Add the dialog styles CSS + // Add the dialog styles CSS. $config['css']['dialog'] = 'include/styles/dialog.css'; - // Add the dialog styles CSS + // Add the dialog styles CSS. $config['css']['dialog'] = 'include/styles/js/introjs.css'; - // If skin's css files exists then add them + // If skin's css files exists then add them. if ($exists_css) { foreach ($skin_styles as $filename => $name) { $style = substr($filename, 0, (strlen($filename) - 4)); $config['css'][$style] = $skin_path.'include/styles/'.$filename; } - } - // Otherwise assign default and user's css - else { - // User style should go last so it can rewrite common styles + } else { + // Otherwise assign default and user's css. + // User style should go last so it can rewrite common styles. $config['css'] = array_merge( [ 'common' => 'include/styles/common.css', @@ -1638,7 +1762,7 @@ function ui_process_page_head($string, $bitfield) ); } - // We can't load empty and we loaded (conditionally) ie + // We can't load empty and we loaded (conditionally) ie. $loaded = [ '', 'ie', @@ -1655,33 +1779,35 @@ function ui_process_page_head($string, $bitfield) $output .= ''."\n\t"; } - // - // End load CSS - // - // - // Load JS - // + /* + * End load CSS + */ + + /* + * Load JS + */ + if (empty($config['js'])) { $config['js'] = []; - // If it's empty, false or not init set array to empty just in case + // If it's empty, false or not init set array to empty just in case. } - // Pandora specific JavaScript should go first + // Pandora specific JavaScript should go first. $config['js'] = array_merge(['pandora' => 'include/javascript/pandora.js'], $config['js']); - // Load base64 javascript library + // Load base64 javascript library. $config['js']['base64'] = 'include/javascript/encode_decode_base64.js'; - // Load webchat javascript library + // Load webchat javascript library. $config['js']['webchat'] = 'include/javascript/webchat.js'; - // Load qrcode library + // Load qrcode library. $config['js']['qrcode'] = 'include/javascript/qrcode.js'; - // Load intro.js library (for bubbles and clippy) + // Load intro.js library (for bubbles and clippy). $config['js']['intro'] = 'include/javascript/intro.js'; $config['js']['clippy'] = 'include/javascript/clippy.js'; - // Load Underscore.js library + // Load Underscore.js library. $config['js']['underscore'] = 'include/javascript/underscore-min.js'; - // Load other javascript - // We can't load empty + // Load other javascript. + // We can't load empty. $loaded = ['']; foreach ($config['js'] as $name => $filename) { if (in_array($name, $loaded)) { @@ -1694,18 +1820,20 @@ function ui_process_page_head($string, $bitfield) $output .= ''."\n\t"; } - // - // End load JS - // - // - // Load jQuery - // + /* + * End load JS + */ + + /* + * Load jQuery + */ + if (empty($config['jquery'])) { $config['jquery'] = []; - // If it's empty, false or not init set array to empty just in case + // If it's empty, false or not init set array to empty just in case. } - // Pandora specific jquery should go first + // Pandora specific jquery should go first. $black_list_pages_old_jquery = ['operation/gis_maps/index']; if (in_array(get_parameter('sec2'), $black_list_pages_old_jquery)) { $config['jquery'] = array_merge( @@ -1728,15 +1856,15 @@ function ui_process_page_head($string, $bitfield) ); } - // Include the datapicker language if exists + // Include the datapicker language if exists. if (file_exists('include/languages/datepicker/jquery.ui.datepicker-'.$config['language'].'.js')) { $config['jquery']['datepicker_language'] = 'include/languages/datepicker/jquery.ui.datepicker-'.$config['language'].'.js'; } - // Include countdown library + // Include countdown library. $config['jquery']['countdown'] = 'include/javascript/jquery.countdown.js'; - // Then add each script as necessary + // Then add each script as necessary. $loaded = ['']; foreach ($config['jquery'] as $name => $filename) { if (in_array($name, $loaded)) { @@ -1749,9 +1877,10 @@ function ui_process_page_head($string, $bitfield) $output .= ''."\n\t"; } - // - // End load JQuery - // + /* + * End load JQuery + */ + include_once __DIR__.'/graphs/functions_flot.php'; $output .= include_javascript_dependencies_flot_graph(true); @@ -1768,8 +1897,8 @@ function ui_process_page_head($string, $bitfield) /** * Callback function to add stuff to the body * - * @param string Callback will fill this with the current buffer. - * @param bitfield Callback will fill this with a bitfield (see ob_start) + * @param string $string Callback will fill this with the current buffer. + * @param mixed $bitfield Callback will fill this with a bitfield (see ob_start). * * @return string String to return to the browser */ @@ -1780,11 +1909,11 @@ function ui_process_page_body($string, $bitfield) if (isset($config['ignore_callback']) && $config['ignore_callback'] == true ) { - return; + return null; } - // Show custom background - $output = ''; + // Show custom background. + $output = ''; $output .= $string; @@ -1801,12 +1930,15 @@ function ui_process_page_body($string, $bitfield) * @param string $url URL of the pagination links. It must include all form * values as GET form. * @param integer $offset Current offset for the pagination. Default value would be - * taken from $_REQUEST['offset'] + * taken from $_REQUEST['offset']. * @param integer $pagination Current pagination size. If a user requests a larger - * pagination than config["block_size"] - * @param boolean $return Whether to return or print this + * pagination than config["block_size"]. + * @param boolean $return Whether to return or print this. * @param string $offset_name The name of parameter for the offset. * @param boolean $print_total_items Show the text with the total items. By default true. + * @param mixed $other_class Other_class. + * @param mixed $script Script. + * @param mixed $parameter_script Parameter_script. * @param string $set_id Set id of div. * * @return string The pagination div or nothing if no pagination needs to be done @@ -1847,10 +1979,12 @@ function ui_pagination( } if (!empty($set_id)) { - $set_id = " id = '$set_id'"; + $set_id = " id = '".$set_id."'"; } - // Pagination links for users include delete, create and other params, now not use these params, and not retry the previous action when go to pagination link. + // Pagination links for users include delete, create and other params, + // now not use these params, and not retry the previous action when go to + // pagination link. $remove = [ 'user_del', 'disable_user', @@ -1860,7 +1994,10 @@ function ui_pagination( $finalUrl = []; foreach ($url as $key => $value) { - if (strpos($value, $remove[0]) === false && strpos($value, $remove[1]) === false && strpos($value, $remove[2]) === false) { + if (strpos($value, $remove[0]) === false + && strpos($value, $remove[1]) === false + && strpos($value, $remove[2]) === false + ) { array_push($finalUrl, $value); } } @@ -1874,14 +2011,15 @@ function ui_pagination( Pagination needs $url to build the base URL to render links, its a base url, like " http://pandora/index.php?sec=godmode&sec2=godmode/admin_access_logs " */ + $block_limit = PAGINATION_BLOCKS_LIMIT; - // Visualize only $block_limit blocks + // Visualize only $block_limit blocks. if ($count <= $pagination) { if ($print_total_items) { - $output = "
    '.__('Label color').''.__('Value color').' '.html_print_input_text_extended( 'percentile_label_color', '#ffffff', @@ -1128,9 +1128,58 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) true ).''; + $form_items_advance['cache_expiration_row']['html'] .= __('Cache expiration'); + $form_items_advance['cache_expiration_row']['html'] .= ''; + $form_items_advance['cache_expiration_row']['html'] .= html_print_extended_select_for_time( + 'cache_expiration', + $config['vc_default_cache_expiration'], + '', + __('No cache'), + 0, + false, + true, + false, + true, + '', + false, + $intervals + ); + $form_items_advance['cache_expiration_row']['html'] .= '
    '.''.''.''.'
    '.__('Please note that you have your agent setup to do not add new modules coming from the data XML.').'
    '.__('That means if you have a local plugin or add manually new modules to the configuration file, you won\'t have it in your agent, unless you first create manually in the interface (with the exact name and type as coming in the XML file).').'
    '.__('You should use the "normal" mode (non learn) only when you don\'t intend to add more modules to the agent.').ui_print_help_icon('module_definition', true, '', 'images/help.png').'
    ', + 'intro' => '
    '.__('Please note that you have your agent setup to do not add new modules coming from the data XML.').'
    '.__('That means if you have a local plugin or add manually new modules to the configuration file, you won\'t have it in your agent, unless you first create manually in the interface (with the exact name and type as coming in the XML file).').'
    '.__('You should use the "normal" mode (non learn) only when you don\'t intend to add more modules to the agent.').'
    ', ]; $return_tours['tours']['modules_not_learning_mode']['conf'] = []; $return_tours['tours']['modules_not_learning_mode']['conf']['autostart'] = false; diff --git a/pandora_console/include/javascript/buttons.html5.min.js b/pandora_console/include/javascript/buttons.html5.min.js new file mode 100644 index 0000000000..deee7fee68 --- /dev/null +++ b/pandora_console/include/javascript/buttons.html5.min.js @@ -0,0 +1,35 @@ +/*! + HTML5 export buttons for Buttons and DataTables. + 2016 SpryMedia Ltd - datatables.net/license + + FileSaver.js (1.3.3) - MIT license + Copyright © 2016 Eli Grey - http://eligrey.com +*/ +(function(f){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(g){return f(g,window,document)}):"object"===typeof exports?module.exports=function(g,p,z,t){g||(g=window);p&&p.fn.dataTable||(p=require("datatables.net")(g,p).$);p.fn.dataTable.Buttons||require("datatables.net-buttons")(g,p);return f(p,g,g.document,z,t)}:f(jQuery,window,document)})(function(f,g,p,z,t,w){function A(a){for(var b="";0<=a;)b=String.fromCharCode(a%26+65)+b,a=Math.floor(a/ +26)-1;return b}function E(a,b){y===w&&(y=-1===C.serializeToString(f.parseXML(F["xl/worksheets/sheet1.xml"])).indexOf("xmlns:r"));f.each(b,function(b,c){if(f.isPlainObject(c))b=a.folder(b),E(b,c);else{if(y){var d=c.childNodes[0],e,h=[];for(e=d.attributes.length-1;0<=e;e--){var m=d.attributes[e].nodeName;var k=d.attributes[e].nodeValue;-1!==m.indexOf(":")&&(h.push({name:m,value:k}),d.removeAttribute(m))}e=0;for(m=h.length;e'+c),c=c.replace(/_dt_b_namespace_token_/g,":"),c=c.replace(/xmlns:NS[\d]+="" NS[\d]+:/g,""));c=c.replace(/<([^<>]*?) xmlns=""([^<>]*?)>/g,"<$1 $2>");a.file(b,c)}})}function r(a,b,d){var c=a.createElement(b);d&&(d.attr&&f(c).attr(d.attr),d.children&&f.each(d.children,function(a,b){c.appendChild(b)}),null!==d.text&&d.text!==w&&c.appendChild(a.createTextNode(d.text))); +return c}function L(a,b){var d=a.header[b].length;a.footer&&a.footer[b].length>d&&(d=a.footer[b].length);for(var c=0,f=a.body.length;cd&&(d=e);if(401*a[1]?!0:!1};try{var C=new XMLSerializer,y}catch(a){}var F={"_rels/.rels":'', +"xl/_rels/workbook.xml.rels":'',"[Content_Types].xml":'', +"xl/workbook.xml":'', +"xl/worksheets/sheet1.xml":'',"xl/styles.xml":''}, +K=[{match:/^\-?\d+\.\d%$/,style:60,fmt:function(a){return a/100}},{match:/^\-?\d+\.?\d*%$/,style:56,fmt:function(a){return a/100}},{match:/^\-?\$[\d,]+.?\d*$/,style:57},{match:/^\-?£[\d,]+.?\d*$/,style:58},{match:/^\-?€[\d,]+.?\d*$/,style:59},{match:/^\-?\d+$/,style:65},{match:/^\-?\d+\.\d{2}$/,style:66},{match:/^\([\d,]+\)$/,style:61,fmt:function(a){return-1*a.replace(/[\(\)]/g,"")}},{match:/^\([\d,]+\.\d{2}\)$/,style:62,fmt:function(a){return-1*a.replace(/[\(\)]/g,"")}},{match:/^\-?[\d,]+$/,style:63}, +{match:/^\-?[\d,]+\.\d{2}$/,style:64}];v.ext.buttons.copyHtml5={className:"buttons-copy buttons-html5",text:function(a){return a.i18n("buttons.copy","Copy")},action:function(a,b,d,c){this.processing(!0);var g=this;a=I(b,c);var e=b.buttons.exportInfo(c),h=H(c),m=a.str;d=f("
    ").css({height:1,width:1,overflow:"hidden",position:"fixed",top:0,left:0});e.title&&(m=e.title+h+h+m);e.messageTop&&(m=e.messageTop+h+h+m);e.messageBottom&&(m=m+h+h+e.messageBottom);c.customize&&(m=c.customize(m,c,b));c=f("