diff --git a/pandora_agents/pc/pandora_agent b/pandora_agents/pc/pandora_agent index 88f78e31ac..50e901f0ce 100644 --- a/pandora_agents/pc/pandora_agent +++ b/pandora_agents/pc/pandora_agent @@ -585,7 +585,7 @@ sub write_broker_conf($){ # Change the agent name if ($line =~ m/^\s*#*\s*agent_name\s+/) { - $line = "agent_name $broker_agent\n"; + $line = "agent_name $broker_agent\n#broker active\n"; } # Change the logfile elsif ($line =~ m/^\s*logfile\s+(.*)/) { diff --git a/pandora_agents/pc/pandora_agent_installer b/pandora_agents/pc/pandora_agent_installer index 7d8de1134d..bcfee3eb00 100644 --- a/pandora_agents/pc/pandora_agent_installer +++ b/pandora_agents/pc/pandora_agent_installer @@ -467,7 +467,7 @@ fi # Script banner at start echo " " -echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2015 ArticaST" +echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2024 PandoraFMS" echo "This program is licensed under GPL2 Terms. http://pandorafms.com" echo " " diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index e7c241251a..613b1aa407 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.775-240123 +Version: 7.0NG.775-240219 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 00e1bec872..5775e5add8 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.775-240123" +pandora_version="7.0NG.775-240219" 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/pandora_agent b/pandora_agents/unix/pandora_agent index 40317705f1..21c40cf1f6 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1039,7 +1039,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.775'; -use constant AGENT_BUILD => '240123'; +use constant AGENT_BUILD => '240219'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; @@ -1860,7 +1860,7 @@ sub write_broker_conf($){ # Change the agent name if ($line =~ m/^\s*#*\s*agent_name\s+/) { - $line = "agent_name $broker_agent\n"; + $line = "agent_name $broker_agent\n#broker active\n"; } # Change the logfile elsif ($line =~ m/^\s*logfile\s+(.*)/) { @@ -3678,9 +3678,21 @@ sub write_module_xml ($@) { return; } - if ($module->{'func'} == \&module_logger) { - $Xml .= $data[0]; - return + # Is it an extraction log module? + if($module->{'type'} eq "log"){ + my $output = join('', @data); + + if ($output eq "") { + return; + } + + $Xml .="\n"; + $Xml .= " {'name'} . "]]>\n"; + $Xml .= " {'type'} . "]]>\n"; + $Xml .= " base64\n"; + $Xml .= " \n"; + $Xml .= "\n"; + return; } # Critical section @@ -3690,7 +3702,7 @@ sub write_module_xml ($@) { " {'name'} . "]]>\n" . " {'description'} . "]]>\n" . " " . $module->{'type'} . "\n"; - + # Interval $Xml .= " " . $module->{'interval'} . "\n"; @@ -3889,7 +3901,8 @@ sub module_logger ($) { my $status = grep_logs( $module->{'name'}, $module->{'params'}, - $module->{'filter'} + $module->{'filter'}, + $module->{'type'} ); return $status; @@ -3926,20 +3939,25 @@ my $encode_sub = defined(&MIME::Base64::encode_base64) ? \&MIME::Base64::encode_ }; sub grep_logs { - my ($str_name, $str_file, $str_regex) = @_; + my ($module_name, $log_file, $reg_exp, $module_type) = @_; - if(!$str_name){ + if(!$module_name){ log_message("module_logger", "Missing module name"); return; } - if(!$str_file){ + if(!$log_file){ log_message("module_logger", "Missing file name"); return; } - if(!$str_regex){ - $str_regex = '.*'; + if(!$module_type){ + log_message("module_logger", "Missing module type"); + return; + } + + if(!$reg_exp){ + $reg_exp = '.*'; } my $idx_dir = '/tmp/'; @@ -3947,9 +3965,6 @@ sub grep_logs { my $idx_pos = 0; my $idx_size = 0; my $idx_ino = ''; - my $module_name = $str_name; - my $log_file = $str_file; - my $reg_exp = $str_regex; # Check that log file exists if (! -e $log_file) { @@ -3975,7 +3990,7 @@ sub grep_logs { return if load_idx(\$idx_pos, \$idx_ino, \$idx_file, \$idx_size) == 1; my @data = parse_log(\$idx_pos, \$idx_ino, \$idx_file, \$log_file, \$module_name, \$reg_exp, \$idx_size); - my $output = create_log($module_name, @data); + my $output = create_log($module_name, $module_type, @data); return $output; } @@ -4090,27 +4105,32 @@ sub grep_logs { } sub create_log { - my ($module_name, @data) = @_; + my ($module_name, $module_type, @data) = @_; - # No data - if ($#data < 0) { - return; - } - - # Log module - my $output = "\n"; - $output .= "\n"; - $output .= "base64\n"; - $output .= "\n"; - $output .= "\n"; + my $data_content = process_log_monitoring($module_type, @data); - return $output; + return $data_content; } } +sub process_log_monitoring { + my ($module_type, @data) = @_; + my $output = ""; + + if ($module_type eq "log"){ + $output = &$encode_sub(join('', @data), ''); + } elsif ($module_type eq "generic_data") { + $output = scalar @data; + } elsif ($module_type eq "generic_proc"){ + $output = scalar @data > 0 ? 1 : 0; + } elsif ($module_type eq "generic_data_string" || $module_type eq "async_string"){ + $output = join('', @data); + } + + return $output; +} + ################################################################################ # TERM Handler ################################################################################ @@ -4283,6 +4303,10 @@ sub init_module ($) { $module->{'alert_template'} = undef; $module->{'filter'} = undef; $module->{'absoluteinterval'} = undef; + $module->{'each_ff'} = undef; + $module->{'min_ff_event_normal'} = undef; + $module->{'min_ff_event_warning'} = undef; + $module->{'min_ff_event_critical'} = undef; } ################################################################################ diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 8ed67cacd8..0991f751ba 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -4,7 +4,7 @@ %global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 7.0NG.775 -%define release 240123 +%define release 240219 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.redhat_bin.el8.spec b/pandora_agents/unix/pandora_agent.redhat_bin.el8.spec index e073b7a1b6..8e6422aa1b 100644 --- a/pandora_agents/unix/pandora_agent.redhat_bin.el8.spec +++ b/pandora_agents/unix/pandora_agent.redhat_bin.el8.spec @@ -5,7 +5,7 @@ %define name pandorafms_agent_linux_bin %define source_name pandorafms_agent_linux %define version 7.0NG.775 -%define release 240123 +%define release 240219 %define debug_package %{nil} Summary: Pandora FMS Linux agent, binary version diff --git a/pandora_agents/unix/pandora_agent.redhat_bin.el9.spec b/pandora_agents/unix/pandora_agent.redhat_bin.el9.spec index ca44c46126..ccd6b33a73 100644 --- a/pandora_agents/unix/pandora_agent.redhat_bin.el9.spec +++ b/pandora_agents/unix/pandora_agent.redhat_bin.el9.spec @@ -5,7 +5,7 @@ %define name pandorafms_agent_linux_bin %define source_name pandorafms_agent_linux %define version 7.0NG.775 -%define release 240123 +%define release 240219 %define debug_package %{nil} Summary: Pandora FMS Linux agent, binary version @@ -13,23 +13,22 @@ Name: %{name} Version: %{version} Release: %{release} License: GPL -Vendor: ArticaST +Vendor: PandoraFMS Source0: %{source_name}-%{version}.tar.gz -URL: http://pandorafms.org +URL: https://pandorafms.com Group: System/Monitoring -Packager: Sancho Lerena +Packager: PandoraFMS Prefix: /usr/share BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildArch: x86_64 Requires(pre): shadow-utils -Requires(post): chkconfig /bin/ln -Requires(preun): chkconfig /bin/rm /usr/sbin/userdel +Requires(post): /bin/ln +Requires(preun): /bin/rm /usr/sbin/userdel Requires: coreutils unzip Requires: util-linux procps grep Requires: /sbin/ip /bin/awk Requires: perl-interpreter Requires: perl-IO-Compress -Requires: libnsl Requires: libxcrypt-compat AutoReq: 0 Provides: %{name}-%{version} @@ -50,7 +49,7 @@ mkdir -p $RPM_BUILD_ROOT%{prefix}/pandora_agent/ mkdir -p $RPM_BUILD_ROOT/usr/bin/ mkdir -p $RPM_BUILD_ROOT/usr/sbin/ mkdir -p $RPM_BUILD_ROOT/etc/pandora/ -mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d/ +#mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d/ mkdir -p $RPM_BUILD_ROOT/var/log/pandora/ mkdir -p $RPM_BUILD_ROOT/usr/share/man/man1/ mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/ @@ -58,7 +57,7 @@ cp -aRf * $RPM_BUILD_ROOT%{prefix}/pandora_agent/ cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/tentacle_client $RPM_BUILD_ROOT/usr/bin/ cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent $RPM_BUILD_ROOT/usr/bin/ cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_exec $RPM_BUILD_ROOT/usr/bin/ -cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_daemon $RPM_BUILD_ROOT/etc/rc.d/init.d/pandora_agent_daemon +#cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_daemon $RPM_BUILD_ROOT/etc/rc.d/init.d/pandora_agent_daemon cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/man/man1/pandora_agent.1.gz $RPM_BUILD_ROOT/usr/share/man/man1/ cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/man/man1/tentacle_client.1.gz $RPM_BUILD_ROOT/usr/share/man/man1/ @@ -119,21 +118,11 @@ then cp -f /usr/share/pandora_agent/pandora_agent_daemon.service /usr/lib/systemd/system/ chmod -x /usr/lib/systemd/system/pandora_agent_daemon.service # Enable the services on SystemD + systemctl daemon-reload systemctl enable pandora_agent_daemon.service -else - /sbin/chkconfig --add pandora_agent_daemon - /sbin/chkconfig pandora_agent_daemon on -fi - -if [ "$1" -gt 1 ] -then - - echo "If Pandora Agent daemon was running with init.d script," - echo "please stop it manually and start the service with systemctl" fi - %preun # Upgrading @@ -141,8 +130,7 @@ if [ "$1" = "1" ]; then exit 0 fi -/sbin/chkconfig --del pandora_agent_daemon -/etc/rc.d/init.d/pandora_agent_daemon stop >/dev/null 2>&1 || : +systemctl stop pandora_agent_daemon.service > /dev/null 2>&1 || : # Remove symbolic links pushd /etc/pandora @@ -162,7 +150,6 @@ exit 0 %defattr(755,root,root) /usr/bin/pandora_agent_exec /usr/bin/tentacle_client -/etc/rc.d/init.d/pandora_agent_daemon %defattr(644,root,root) /usr/share/man/man1/pandora_agent.1.gz diff --git a/pandora_agents/unix/pandora_agent.redhat_bin.spec b/pandora_agents/unix/pandora_agent.redhat_bin.spec index 857491d509..5ba59b0f96 100644 --- a/pandora_agents/unix/pandora_agent.redhat_bin.spec +++ b/pandora_agents/unix/pandora_agent.redhat_bin.spec @@ -5,7 +5,7 @@ %define name pandorafms_agent_linux_bin %define source_name pandorafms_agent_linux %define version 7.0NG.775 -%define release 240123 +%define release 240219 Summary: Pandora FMS Linux agent, binary version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 1491df0b07..3e33ba4e3b 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -4,7 +4,7 @@ %global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 7.0NG.775 -%define release 240123 +%define release 240219 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 0232a6bf8c..ea2422a4d5 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.775" -PI_BUILD="240123" +PI_BUILD="240219" OS_NAME=`uname -s` FORCE=0 @@ -579,7 +579,7 @@ fi # Script banner at start echo " " -echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2015 ArticaST" +echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2024 PandoraFMS" echo "This program is licensed under GPL2 Terms. http://pandorafms.com" echo " " diff --git a/pandora_agents/win32/Makefile.am b/pandora_agents/win32/Makefile.am index 4641081570..94e77312c4 100644 --- a/pandora_agents/win32/Makefile.am +++ b/pandora_agents/win32/Makefile.am @@ -1,9 +1,9 @@ bin_PROGRAMS = PandoraAgent if DEBUG -PandoraAgent_SOURCES = misc/cron.cc misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c misc/sha256.cc windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc debug_new.cpp +PandoraAgent_SOURCES = misc/cron.cc misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_exec_powershell.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c misc/sha256.cc windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc debug_new.cpp PandoraAgent_CXXFLAGS=-g -O0 else -PandoraAgent_SOURCES = misc/cron.cc misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_logchannel.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c misc/sha256.cc windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc +PandoraAgent_SOURCES = misc/cron.cc misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_exec_powershell.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_logchannel.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c misc/sha256.cc windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc PandoraAgent_CXXFLAGS=-O2 endif diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 74ffb7b496..26c45e0ae4 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{240123} +{240219} ViewReadme {Yes} diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 2df46ad9d5..69a801e96b 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -236,6 +236,8 @@ Module_Kind Pandora_Module::parseModuleKindFromString (string kind) { if (kind == module_exec_str) { return MODULE_EXEC; + } else if (kind == module_exec_powershell_str) { + return MODULE_EXEC_POWERSHELL; } else if (kind == module_proc_str) { return MODULE_PROC; } else if (kind == module_service_str) { diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h index 111fc79c79..bb19b266b2 100644 --- a/pandora_agents/win32/modules/pandora_module.h +++ b/pandora_agents/win32/modules/pandora_module.h @@ -94,7 +94,8 @@ namespace Pandora_Modules { MODULE_REGEXP, /**< The module searches a file for matches of a regular expression */ MODULE_PLUGIN, /**< Plugin */ MODULE_PING, /**< Ping module */ - MODULE_SNMPGET /**< SNMP get module */ + MODULE_SNMPGET, /**< SNMP get module */ + MODULE_EXEC_POWERSHELL /**< The module run a custom powershell command */ } Module_Kind; /** @@ -109,24 +110,25 @@ namespace Pandora_Modules { regex_t regexp; } Condition; - const string module_exec_str = "module_exec"; - const string module_proc_str = "module_proc"; - const string module_service_str = "module_service"; - const string module_freedisk_str = "module_freedisk"; - const string module_freedisk_percent_str = "module_freedisk_percent"; - const string module_freememory_str = "module_freememory"; - const string module_freememory_percent_str = "module_freememory_percent"; - const string module_cpuusage_str = "module_cpuusage"; - const string module_inventory_str = "module_inventory"; - const string module_logevent_str = "module_logevent"; - const string module_logchannel_str = "module_logchannel"; - const string module_wmiquery_str = "module_wmiquery"; - const string module_perfcounter_str = "module_perfcounter"; - const string module_tcpcheck_str = "module_tcpcheck"; - const string module_regexp_str = "module_regexp"; - const string module_plugin_str = "module_plugin"; - const string module_ping_str = "module_ping"; - const string module_snmpget_str = "module_snmpget"; + const string module_exec_str = "module_exec"; + const string module_proc_str = "module_proc"; + const string module_service_str = "module_service"; + const string module_freedisk_str = "module_freedisk"; + const string module_freedisk_percent_str = "module_freedisk_percent"; + const string module_freememory_str = "module_freememory"; + const string module_freememory_percent_str = "module_freememory_percent"; + const string module_cpuusage_str = "module_cpuusage"; + const string module_inventory_str = "module_inventory"; + const string module_logevent_str = "module_logevent"; + const string module_logchannel_str = "module_logchannel"; + const string module_wmiquery_str = "module_wmiquery"; + const string module_perfcounter_str = "module_perfcounter"; + const string module_tcpcheck_str = "module_tcpcheck"; + const string module_regexp_str = "module_regexp"; + const string module_plugin_str = "module_plugin"; + const string module_ping_str = "module_ping"; + const string module_snmpget_str = "module_snmpget"; + const string module_exec_powershell_str = "module_exec_powershell"; /** * Pandora module super-class exception. diff --git a/pandora_agents/win32/modules/pandora_module_exec_powershell.cc b/pandora_agents/win32/modules/pandora_module_exec_powershell.cc new file mode 100644 index 0000000000..99d37b7822 --- /dev/null +++ b/pandora_agents/win32/modules/pandora_module_exec_powershell.cc @@ -0,0 +1,91 @@ +/* Pandora exec module. These modules exec a powershell command. + + Copyright (c) 2006-2023 Pandora FMS. + + 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; either version 2, or (at your option) + any later version. + + 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. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "pandora_module_exec_powershell.h" +#include "../pandora_strutils.h" + +#include +#include +#include +#include +#include +#include + +#define EXEC_OK 0 +#define EXEC_ERR -1 +#define BUFSIZE 4096 + +using namespace Pandora; +using namespace Pandora_Strutils; +using namespace Pandora_Modules; + +/** + * Creates a Pandora_Module_Exec_Powershell object. + * + * @param name Module name + * @param exec Command to be executed. + */ +Pandora_Module_Exec_Powershell::Pandora_Module_Exec_Powershell(string name, string exec) + : Pandora_Module (name) { + + string escaped_exec; + + for (char c : exec) { + if (c == '"' || c == '\\') { + escaped_exec += '\\'; + } + escaped_exec += c; + } + + this->module_exec = "powershell -C \"" + escaped_exec + "\""; + + this->setKind (module_exec_powershell_str); +} + +void Pandora_Module_Exec_Powershell::run() { + string output_result; + + this->has_output = false; + + FILE* pipe = popen(this->module_exec.c_str(), "r"); + if (!pipe) { + pandoraLog ("Error while executing command.", GetLastError ()); + return; + } + + char buffer[BUFSIZE]; + while (fgets(buffer, BUFSIZE, pipe) != NULL) { + output_result += buffer; + } + + int result = pclose(pipe); + + if (result == EXEC_ERR) { + pandoraLog ("Error while closing command process.", GetLastError ()); + return; + } + + if (result != EXEC_OK) { + pandoraLog ("Error invalid powershell command.", GetLastError ()); + return; + } + + this->has_output = true; + this->setOutput (output_result); +} \ No newline at end of file diff --git a/pandora_agents/win32/modules/pandora_module_exec_powershell.h b/pandora_agents/win32/modules/pandora_module_exec_powershell.h new file mode 100644 index 0000000000..d3c9785c29 --- /dev/null +++ b/pandora_agents/win32/modules/pandora_module_exec_powershell.h @@ -0,0 +1,43 @@ +/* Pandora exec module. These modules exec a powershell command + + Copyright (c) 2006-2023 Pandora FMS. + + 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; either version 2, or (at your option) + any later version. + + 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. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef __PANDORA_MODULE_EXEC_POWERWSHELL_H__ +#define __PANDORA_MODULE_EXEC_POWERWSHELL_H__ + +#include "pandora_module.h" + +namespace Pandora_Modules { + /** + * Module to execute a powershell command. + * + * Any custom order that want to be executed can be put in + * the util directory into the Pandora agent path. + */ + class Pandora_Module_Exec_Powershell : public Pandora_Module { + + private: + string module_exec; + + public: + Pandora_Module_Exec_Powershell (string name, string exec); + void run (); + }; +} + +#endif diff --git a/pandora_agents/win32/modules/pandora_module_factory.cc b/pandora_agents/win32/modules/pandora_module_factory.cc index de149293ff..dd71dc2dd8 100644 --- a/pandora_agents/win32/modules/pandora_module_factory.cc +++ b/pandora_agents/win32/modules/pandora_module_factory.cc @@ -22,6 +22,7 @@ #include "pandora_module_factory.h" #include "pandora_module.h" #include "pandora_module_exec.h" +#include "pandora_module_exec_powershell.h" #include "pandora_module_proc.h" #include "pandora_module_service.h" #include "pandora_module_freedisk.h" @@ -129,6 +130,7 @@ using namespace Pandora_Strutils; #define TOKEN_ALERT_TEMPLATE ("module_alert_template") #define TOKEN_USER_SESSION ("module_user_session ") #define TOKEN_WAIT_TIMEOUT ("module_wait_timeout ") +#define TOKEN_EXEC_POWERSHELL ("module_exec_powershell ") string parseLine (string line, string token) { @@ -158,7 +160,7 @@ Pandora_Module * Pandora_Module_Factory::getModuleFromDefinition (string definition) { list tokens; list::iterator iter; - string module_name, module_type, module_exec; + string module_name, module_type, module_exec, module_exec_powershell; string module_min, module_max, module_description; string module_interval, module_absoluteinterval; string module_proc, module_service; @@ -268,6 +270,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { module_user_session = ""; macro = ""; module_wait_timeout = ""; + module_exec_powershell = ""; stringtok (tokens, definition, "\n"); @@ -302,6 +305,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { if (module_exec == "") { module_exec = parseLine (line, TOKEN_EXEC); } + if (module_exec_powershell == "") { + module_exec_powershell = parseLine (line, TOKEN_EXEC_POWERSHELL); + } if (module_wait_timeout == "") { module_wait_timeout = parseLine (line, TOKEN_WAIT_TIMEOUT); } @@ -626,6 +632,13 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { } } + if (module_exec_powershell != "") { + pos_macro = module_exec_powershell.find(macro_name); + if (pos_macro != string::npos){ + module_exec_powershell.replace(pos_macro, macro_name.size(), macro_value); + } + } + if (module_proc != "") { pos_macro = module_proc.find(macro_name); if (pos_macro != string::npos){ @@ -1155,6 +1168,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { module->setWaitTimeout (atoi (module_wait_timeout.c_str ())); } + } else if (module_exec_powershell != "") { + module = new Pandora_Module_Exec_Powershell (module_name, module_exec_powershell); + } else if (module_proc != "") { module = new Pandora_Module_Proc (module_name, module_proc); diff --git a/pandora_agents/win32/modules/pandora_module_freedisk_percent.cc b/pandora_agents/win32/modules/pandora_module_freedisk_percent.cc index c061d4394b..bda0043b0d 100755 --- a/pandora_agents/win32/modules/pandora_module_freedisk_percent.cc +++ b/pandora_agents/win32/modules/pandora_module_freedisk_percent.cc @@ -48,7 +48,7 @@ Pandora_Module_Freedisk_Percent::Pandora_Module_Freedisk_Percent (string name, s void Pandora_Module_Freedisk_Percent::run () { - long res; + double res; try { Pandora_Module::run (); @@ -59,7 +59,7 @@ Pandora_Module_Freedisk_Percent::run () { try { res = Pandora_Wmi::getDiskFreeSpacePercent (this->disk_id); - this->setOutput (longtostr (res)); + this->setOutput(std::to_string(res)); } catch (Pandora_Wmi::Pandora_Wmi_Exception e) { this->has_output = false; } diff --git a/pandora_agents/win32/modules/pandora_module_list.cc b/pandora_agents/win32/modules/pandora_module_list.cc index be5cc32d45..b0612902a3 100644 --- a/pandora_agents/win32/modules/pandora_module_list.cc +++ b/pandora_agents/win32/modules/pandora_module_list.cc @@ -21,6 +21,7 @@ #include "pandora_module_factory.h" #include "pandora_module_list.h" #include "pandora_module_exec.h" +#include "pandora_module_exec_powershell.h" #include "pandora_module_proc.h" #include "pandora_module_service.h" #include "pandora_module_freedisk.h" @@ -235,6 +236,7 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) Pandora_Module_Plugin *module_plugin; Pandora_Module_Ping *module_ping; Pandora_Module_SNMPGet *module_snmpget; + Pandora_Module_Exec_Powershell *module_exec_powershell; module = Pandora_Module_Factory::getModuleFromDefinition (definition); @@ -244,6 +246,11 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) module_exec = (Pandora_Module_Exec *) module; modules->push_back (module_exec); + break; + case MODULE_EXEC_POWERSHELL: + module_exec_powershell = (Pandora_Module_Exec_Powershell *) module; + modules->push_back (module_exec_powershell); + break; case MODULE_PROC: module_proc = (Pandora_Module_Proc *) module; diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 8e094eedae..8565876bc3 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.775 Build 240123") +#define PANDORA_VERSION ("7.0NG.775 Build 240219") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index b7d17d6756..21bdebb9a1 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Pandora FMS" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.775(Build 240123))" + VALUE "ProductVersion", "(7.0NG.775(Build 240219))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_agents/win32/windows/pandora_wmi.cc b/pandora_agents/win32/windows/pandora_wmi.cc index 7bf1091602..d0b3f5dc30 100644 --- a/pandora_agents/win32/windows/pandora_wmi.cc +++ b/pandora_agents/win32/windows/pandora_wmi.cc @@ -188,11 +188,11 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) { * @exception Pandora_Wmi_Exception Throwd if an error occured when reading * from WMI database. */ -unsigned long +double Pandora_Wmi::getDiskFreeSpacePercent (string disk_id) { CDhInitialize init; CDispPtr wmi_svc, quickfixes; - double free_space = 0, size = 0; + double free_space = 0, size = 0; string query; query = "SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE DeviceID = \"" + disk_id + "\""; @@ -202,7 +202,7 @@ Pandora_Wmi::getDiskFreeSpacePercent (string disk_id) { dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc, L".ExecQuery(%T)", query.c_str ())); - + FOR_EACH (quickfix, quickfixes, NULL) { dhGetValue (L"%e", &free_space, quickfix, L".FreeSpace"); @@ -213,7 +213,7 @@ Pandora_Wmi::getDiskFreeSpacePercent (string disk_id) { return 0; } - return (unsigned long) (free_space * 100 / size); + return (free_space * 100 / size); } NEXT_THROW (quickfix); } catch (string errstr) { pandoraLog ("getDiskFreeSpace error. %s", errstr.c_str ()); diff --git a/pandora_agents/win32/windows/pandora_wmi.h b/pandora_agents/win32/windows/pandora_wmi.h index 5eeb5d6a90..857b228471 100644 --- a/pandora_agents/win32/windows/pandora_wmi.h +++ b/pandora_agents/win32/windows/pandora_wmi.h @@ -44,7 +44,7 @@ namespace Pandora_Wmi { int isProcessRunning (string process_name); int isServiceRunning (string service_name); unsigned long getDiskFreeSpace (string disk_id); - unsigned long getDiskFreeSpacePercent (string disk_id); + double getDiskFreeSpacePercent (string disk_id); int getCpuUsagePercentage (int cpu_id); long getFreememory (); long getFreememoryPercent (); diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 4d832ca478..9a6579605d 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.775-240123 +Version: 7.0NG.775-240219 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 95ee569569..efad6ffc68 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.775-240123" +pandora_version="7.0NG.775-240219" package_pear=0 package_pandora=1 diff --git a/pandora_console/extensions/dbmanager.php b/pandora_console/extensions/dbmanager.php index acaaadd12c..38bb7c2d8b 100644 --- a/pandora_console/extensions/dbmanager.php +++ b/pandora_console/extensions/dbmanager.php @@ -280,18 +280,17 @@ function dbmgr_extension_main() if (is_array($result) === false) { echo 'Output: '.$result; - - db_pandora_audit( - AUDIT_LOG_SYSTEM, - 'DB Interface Extension. SQL', - false, - false, - $sql - ); - return; } + db_pandora_audit( + AUDIT_LOG_SYSTEM, + 'DB Interface Extension. SQL', + false, + false, + $sql + ); + echo "
"; $table = new stdClass(); $table->width = '100%'; diff --git a/pandora_console/extensions/grafana/query.php b/pandora_console/extensions/grafana/query.php index 3c7a843542..ac54d98161 100644 --- a/pandora_console/extensions/grafana/query.php +++ b/pandora_console/extensions/grafana/query.php @@ -23,6 +23,9 @@ if ($headers['Authorization']) { list($user, $password) = explode(':', base64_decode($headers['Authorization'])); + // Prevent sql injection. + $user = mysqli_real_escape_string($config['dbconnection'], $user); + // Check user login $user_in_db = process_user_login($user, $password, true); diff --git a/pandora_console/extensions/grafana/search.php b/pandora_console/extensions/grafana/search.php index 9193dd290e..82b670398b 100644 --- a/pandora_console/extensions/grafana/search.php +++ b/pandora_console/extensions/grafana/search.php @@ -24,6 +24,9 @@ if ($headers['Authorization']) { list($user, $password) = explode(':', base64_decode($headers['Authorization'])); + // Prevent sql injection. + $user = mysqli_real_escape_string($config['dbconnection'], $user); + // Check user login $user_in_db = process_user_login($user, $password, true); diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index 6f09d889f7..98e8886733 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -223,7 +223,7 @@ function mainInsertData() '', empty($agent_id) ); - $table->data[1][2] = html_print_input_text('data', ($save === true) ? date(DATE_FORMAT) : $data, __('Data'), 10, 60, true); + $table->data[1][2] = html_print_input_text('date', ($save === true) ? date(DATE_FORMAT) : $data, __('Data'), 10, 60, true); $table->data[1][2] .= ' '; $table->data[1][2] .= html_print_input_text('time', ($save === true) ? date(TIME_FORMAT) : $time, '', 10, 7, true); @@ -283,8 +283,14 @@ function mainInsertData() secondText: '', currentText: '', closeText: ''}); - - $("#text-date").datepicker({dateFormat: ""}); + + $('#text-date').datepicker ({ + dateFormat: '', + changeMonth: true, + changeYear: true, + showAnim: 'slideDown', + firstDay: "", + }); $.datepicker.setDefaults($.datepicker.regional[ ""]); }); diff --git a/pandora_console/extensions/quick_shell.php b/pandora_console/extensions/quick_shell.php index 9ea79ba364..a3f5872f84 100644 --- a/pandora_console/extensions/quick_shell.php +++ b/pandora_console/extensions/quick_shell.php @@ -394,7 +394,7 @@ function quickShellSettings() __('Address'), html_print_input_text( 'gotty_addr', - $config['gotty_addr'], + ($config['gotty_addr'] ?? ''), '', 30, 100, @@ -443,9 +443,8 @@ function quickShellSettings() html_print_checkbox_switch( 'gotty_ssh_use_ssl', 1, - $config['gotty_ssh_use_ssl'], - true, - $disable_agentaccess + ($config['gotty_ssh_use_ssl'] ?? false), + true ) ); @@ -497,7 +496,7 @@ function quickShellSettings() html_print_checkbox_switch( 'gotty_telnet_use_ssl', 1, - $config['gotty_telnet_use_ssl'], + ($config['gotty_telnet_use_ssl'] ?? false), true ) ); diff --git a/pandora_console/extensions/realtime_graphs/ajax.php b/pandora_console/extensions/realtime_graphs/ajax.php index 8b633171ab..1482540f91 100644 --- a/pandora_console/extensions/realtime_graphs/ajax.php +++ b/pandora_console/extensions/realtime_graphs/ajax.php @@ -128,6 +128,6 @@ if (empty($data)) { } echo '{ - "label": "'.htmlspecialchars($graph_title, ENT_QUOTES).'", - "data": [["'.time().'", '.htmlspecialchars($data, ENT_QUOTES).']] + "label": "'.htmlspecialchars(($graph_title ?? ''), ENT_QUOTES).'", + "data": [["'.time().'", '.htmlspecialchars(($data ?? ''), ENT_QUOTES).']] }'; diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php deleted file mode 100755 index 476b7ef1bf..0000000000 --- a/pandora_console/extensions/resource_exportation.php +++ /dev/null @@ -1,497 +0,0 @@ -'."\n"; - echo "\n"; - echo '\n"; - if (isset($report['description'])) { - echo '\n"; - } - - $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $report['id_group']); - echo '\n"; - $items = db_get_all_rows_field_filter( - 'treport_content', - 'id_report', - $report['id_report'] - ); - foreach ($items as $item) { - echo "\n"; - echo ''.io_safe_output($item['type'])."\n"; - echo ''.io_safe_output($item['description'])."\n"; - echo ''.io_safe_output($item['period'])."\n"; - if ($item['id_agent'] != 0) { - $agent = db_get_value('alias', 'tagente', 'id_agente', $item['id_agent']); - } - - if ($item['id_agent_module'] != 0) { - $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']); - $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']); - $agent = db_get_value('alias', 'tagente', 'id_agente', $item['id_agent']); - - echo '\n"; - } - - if (isset($agent)) { - echo '\n"; - } - - $agent = null; - switch (io_safe_output($item['type'])) { - case 2: - case 'custom_graph': - case 'automatic_custom_graph': - $graph = db_get_value('name', 'tgraph', 'id_graph', $item['id_gs']); - echo '\n"; - break; - - case 3: - case 'SLA': - echo ''.$item['only_display_wrong']."\n"; - echo ''.$item['monday']."\n"; - echo ''.$item['tuesday']."\n"; - echo ''.$item['wednesday']."\n"; - echo ''.$item['thursday']."\n"; - echo ''.$item['friday']."\n"; - echo ''.$item['saturday']."\n"; - echo ''.$item['sunday']."\n"; - echo ''.$item['time_from']."\n"; - echo ''.$item['time_to']."\n"; - - $slas = db_get_all_rows_field_filter('treport_content_sla_combined', 'id_report_content', $item['id_rc']); - if ($slas === false) { - $slas = []; - } - - foreach ($slas as $sla) { - $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']); - $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']); - $agent = db_get_value('alias', 'tagente', 'id_agente', $item['id_agent']); - echo ''; - echo '\n"; - echo '\n"; - echo ''.$sla['sla_max']."\n"; - echo ''.$sla['sla_min']."\n"; - echo ''.$sla['sla_limit']."\n"; - echo ''; - } - break; - - case 'text': - echo '\n"; - break; - - case 'sql': - echo '\n"; - if (!empty($item['external_source'])) { - echo '\n"; - } else { - $sql = db_get_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']); - echo ''.io_safe_output($sql)."\n"; - } - break; - - case 'sql_graph_pie': - case 'sql_graph_vbar': - case 'sql_graph_hbar': - echo ''.io_safe_output($item['header_definition'])."\n"; - if (!empty($item['external_source'])) { - echo ''.io_safe_output($item['external_source'])."\n"; - } else { - $sql = db_get_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']); - echo ''.io_safe_output($sql)."\n"; - } - break; - - case 'event_report_group': - $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $item['id_agent']); - echo '\n"; - break; - - case 'url': - echo ''; - break; - - case 'database_serialized': - echo ''; - echo ''; - echo ''; - break; - - case 1: - case 'simple_graph': - case 'simple_baseline_graph': - case 6: - case 'monitor_report': - case 7: - case 'avg_value': - case 8: - case 'max_value': - case 9: - case 'min_value': - case 10: - case 'sumatory': - case 'agent_detailed_event': - case 'event_report_agent': - case 'event_report_module': - case 'alert_report_module': - case 'alert_report_agent': - case 'alert_report_group': - default: - // Do nothing. - break; - } - - echo "\n"; - } - - echo "\n"; -} - - -function output_xml_visual_console($id) -{ - $visual_map = db_get_row('tlayout', 'id', $id); - - echo ''."\n"; - echo "\n"; - echo '\n"; - if ($visual_map['id_group'] != 0) { - $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $visual_map['id_group']); - echo '\n"; - } - - echo '\n"; - echo ''.io_safe_output($visual_map['height'])."\n"; - echo ''.io_safe_output($visual_map['width'])."\n"; - $items = db_get_all_rows_field_filter('tlayout_data', 'id_layout', $visual_map['id']); - if ($items === false) { - $items = []; - } - - foreach ($items as $item) { - echo "\n"; - echo ''.$item['id']."\n"; - // OLD ID USE FOR parent item - $agent = ''; - if ($item['id_agent'] != 0) { - $agent = db_get_value('nombre', 'tagente', 'id_agente', $item['id_agent']); - } - - if (!empty($item['label'])) { - echo '\n"; - } - - echo ''.$item['pos_x']."\n"; - echo ''.$item['pos_y']."\n"; - echo ''.$item['type']."\n"; - if ($item['width'] != 0) { - echo ''.$item['width']."\n"; - } - - if ($item['height'] != 0) { - echo ''.$item['height']."\n"; - } - - if (!empty($item['image'])) { - echo ''.$item['image']."\n"; - } - - if ($item['period'] != 0) { - echo ''.$item['period']."\n"; - } - - if (isset($item['id_agente_modulo'])) { - if ($item['id_agente_modulo'] != 0) { - $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']); - $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']); - $agent = db_get_value('nombre', 'tagente', 'id_agente', $id_agent); - - echo '\n"; - } - } - - if (!empty($agent)) { - echo '\n"; - } - - if ($item['id_layout_linked'] != 0) { - echo ''.$item['id_layout_linked']."\n"; - } - - if ($item['parent_item'] != 0) { - echo ''.$item['parent_item']."\n"; - } - - if (!empty($item['clock_animation'])) { - echo ''.$item['clock_animation']."\n"; - } - - if (!empty($item['fill_color'])) { - echo ''.$item['fill_color']."\n"; - } - - if (!empty($item['type_graph'])) { - echo ''.$item['type_graph']."\n"; - } - - if (!empty($item['time_format'])) { - echo ''.$item['time_format']."\n"; - } - - if (!empty($item['timezone'])) { - echo ''.$item['timezone']."\n"; - } - - if (!empty($item['border_width'])) { - echo ''.$item['border_width']."\n"; - } - - if (!empty($item['border_color'])) { - echo ''.$item['border_color']."\n"; - } - - echo "\n"; - } - - echo "\n"; -} - - -function get_name_xml_resource($hook_enterprise) -{ - global $config; - - $type = get_parameter('type'); - $id = (int) get_parameter('id'); - - switch ($type) { - case 'report': - $name = db_get_value('name', 'treport', 'id_report', $id); - break; - - case 'visual_console': - $name = db_get_value('name', 'tlayout', 'id', $id); - break; - - default: - if ($hook_enterprise === true) { - return enterprise_get_name_xml_resource($type, $id); - } - break; - } - - $file = io_safe_output($name).'.ptr'; - - return $file; -} - - -function get_xml_resource() -{ - global $config; - - $hook_enterprise = enterprise_include('extensions/resource_exportation/functions.php'); -} - - -function resource_exportation_extension_main() -{ - global $config; - - check_login(); - - if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) { - db_pandora_audit( - AUDIT_LOG_ACL_VIOLATION, - 'Trying to access Setup Management' - ); - include 'general/noaccess.php'; - return; - } - - $hook_enterprise = enterprise_include('extensions/resource_exportation/functions.php'); - - ui_print_standard_header( - __('Resource exportation'), - 'images/extensions.png', - false, - '', - true, - [], - [ - [ - 'link' => '', - 'label' => __('Resources'), - ], - [ - 'link' => '', - 'label' => __('Resource exporting'), - ], - ] - ); - - ui_print_warning_message( - __('This extension makes exportation of resource template more easy.').'
'.__('You can export resource templates in .ptr format.') - ); - - $table = new stdClass(); - $table->class = 'databox filter-table-adv'; - $table->id = 'resource_exportation_table'; - $table->style = []; - $table->style[0] = 'width: 30%'; - $table->style[1] = 'vertical-align: bottom;'; - $table->data = []; - $table->data[0][] = html_print_label_input_block( - __('Report'), - html_print_div( - [ - 'class' => 'flex-content-left', - 'content' => html_print_select_from_sql('SELECT id_report, name FROM treport', 'report', '', '', '', 0, true), - ], - true - ) - ); - $table->data[0][] = html_print_button(__('Export'), '', false, 'export_to_ptr("report");', '', true); - - $table->data[1][] = html_print_label_input_block( - __('Visual console'), - html_print_div( - [ - 'class' => 'flex-content-left', - 'content' => html_print_select_from_sql('SELECT id, name FROM tlayout', 'visual_console', '', '', '', 0, true), - ], - true - ) - ); - $table->data[1][] = html_print_button(__('Export'), '', false, 'export_to_ptr("visual_console");', '', true); - - if ($hook_enterprise === true) { - add_rows_for_enterprise($table->data); - } - - html_print_table($table); - - ?> - - $name) { - $values['id_report'] = $id; - $result = (bool) db_process_sql_insert('treport_content', $values); - - ui_print_result_message( - $result, - sprintf( - __("Success add '%s' item in report '%s'."), - $values['type'], - $name - ), - sprintf( - __("Error create '%s' item in report '%s'."), - $values['type'], - $name - ) - ); - } -} - - -function process_upload_xml_report($xml, $group_filter=0) -{ - foreach ($xml->xpath('/report') as $reportElement) { - $values = []; - - if (isset($reportElement->name)) { - $values['name'] = $reportElement->name; - - $posible_name = $values['name']; - $exist = true; - $loops = 30; - // Loops to exit or tries. - while ($exist && $loops > 0) { - $exist = (bool) db_get_row_filter( - 'treport', - ['name' => io_safe_input($posible_name)] - ); - - if ($exist) { - $loops--; - $posible_name = $values['name'].' ('.(30 - $loops).')'; - } - } - - if ($exist) { - ui_print_error_message( - sprintf( - __("Error create '%s' report, the name exist and there aren't free name."), - $reportElement->name - ) - ); - break; - } else if ($loops != 30) { - ui_print_warning_message( - sprintf( - __("Warning create '%s' report, the name exist, the report have a name %s."), - $reportElement->name, - $posible_name - ) - ); - } - - $values['name'] = io_safe_input($posible_name); - } else { - ui_print_error_message(__("Error the report haven't name.")); - break; - } - - if (isset($reportElement->group) === true - && empty($reportElement->group) === false - ) { - $id_group = db_get_value( - 'id_grupo', - 'tgrupo', - 'nombre', - $reportElement->group - ); - if ($id_group === false) { - ui_print_error_message(__("Error the report haven't group.")); - break; - } - } - - if (isset($reportElement->description) === true) { - $values['description'] = $reportElement->description; - } - - $id_report = db_process_sql_insert('treport', $values); - - ui_print_result_message( - $id_report, - sprintf(__("Success create '%s' report."), $posible_name), - sprintf(__("Error create '%s' report."), $posible_name) - ); - - if ($id_report) { - db_pandora_audit( - AUDIT_LOG_REPORT_MANAGEMENT, - 'Create report '.$id_report, - false, - false - ); - } else { - db_pandora_audit( - AUDIT_LOG_REPORT_MANAGEMENT, - 'Fail to create report', - false, - false - ); - break; - } - - foreach ($reportElement->item as $item) { - $item = (array) $item; - - $values = []; - $values['id_report'] = $id_report; - if (isset($item['description']) === true) { - $values['description'] = io_safe_input($item['description']); - } - - if (isset($item['period']) === true) { - $values['period'] = io_safe_input($item['period']); - } - - if (isset($item['type']) === true) { - $values['type'] = io_safe_input($item['type']); - } - - $agents_item = []; - if (isset($item['agent']) === true) { - $agents = agents_get_agents( - ['id_grupo' => $group_filter], - [ - 'id_agente', - 'alias', - ] - ); - - $agent_clean = str_replace( - [ - '[', - ']', - ], - '', - io_safe_output($item['agent']) - ); - $regular_expresion = ($agent_clean != $item['agent']); - - foreach ($agents as $agent) { - if ($regular_expresion) { - if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['alias']))) { - $agents_item[$agent['id_agente']]['name'] = $agent['alias']; - } - } else { - if ($agent_clean == io_safe_output($agent['alias'])) { - $agents_item[$agent['id_agente']]['name'] = $agent['alias']; - } - } - } - } - - if (isset($item['module']) === true) { - $module_clean = str_replace(['[', ']'], '', $item['module']); - $regular_expresion = ($module_clean != $item['module']); - - foreach ($agents_item as $id => $agent) { - $modules = db_get_all_rows_filter( - 'tagente_modulo', - ['id_agente' => $id], - [ - 'id_agente_modulo', - 'nombre', - ] - ); - - $agents_item[$id]['modules'] = []; - - foreach ($modules as $module) { - if ($regular_expresion) { - if ((bool) preg_match('/'.$module_clean.'/', io_safe_output($module['nombre']))) { - $agents_item[$id]['modules'][$module['id_agente_modulo']]['name'] = $module['nombre']; - } - } else { - if ($module_clean == io_safe_output($module['nombre'])) { - $agents_item[$id]['modules'][$module['id_agente_modulo']]['name'] = $module['nombre']; - } - } - } - } - } - - switch ($item['type']) { - case 2: - case 'custom_graph': - case 'automatic_custom_graph': - $group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($item['graph'])); - $values['id_gs'] = $group; - break; - - case 3: - case 'SLA': - if (isset($item['only_display_wrong'])) { - $values['only_display_wrong'] = (string) $item['only_display_wrong']; - } - - if (isset($item['monday'])) { - $values['monday'] = (string) $item['monday']; - } - - if (isset($item['tuesday'])) { - $values['tuesday'] = (string) $item['tuesday']; - } - - if (isset($item['wednesday'])) { - $values['wednesday'] = (string) $item['wednesday']; - } - - if (isset($item['thursday'])) { - $values['thursday'] = (string) $item['thursday']; - } - - if (isset($item['friday'])) { - $values['friday'] = (string) $item['friday']; - } - - if (isset($item['saturday'])) { - $values['saturday'] = (string) $item['saturday']; - } - - if (isset($item['sunday'])) { - $values['sunday'] = (string) $item['sunday']; - } - - if (isset($item['time_from'])) { - $values['time_from'] = (string) $item['time_from']; - } - - if (isset($item['time_to'])) { - $values['time_to'] = (string) $item['time_to']; - } - - $slas = []; - if (!isset($item['sla'])) { - $item['sla'] = []; - } - - foreach ($item['sla'] as $sla_xml) { - if (isset($sla_xml->agent)) { - $agents = agents_get_agents(['id_grupo' => $group_filter], ['id_agente', 'nombre']); - - $agent_clean = str_replace(['[', ']'], '', $sla_xml->agent); - $regular_expresion = ($agent_clean != $sla_xml->agent); - - foreach ($agents as $agent) { - $id_agent = false; - if ($regular_expresion) { - if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['nombre']))) { - $id_agent = $agent['id_agente']; - } else { - if ($agent_clean == io_safe_output($agent['nombre'])) { - $id_agent = $agent['id_agente']; - } - } - } - - if ($id_agent) { - if (isset($sla_xml->module)) { - $module_clean = str_replace(['[', ']'], '', $sla_xml->module); - $regular_expresion = ($module_clean != $sla_xml->module); - - $modules = db_get_all_rows_filter( - 'tagente_modulo', - ['id_agente' => $id_agent], - [ - 'id_agente_modulo', - 'nombre', - ] - ); - - foreach ($modules as $module) { - if ($regular_expresion) { - if ((bool) preg_match('/'.$module_clean.'/', io_safe_output($module['nombre']))) { - $slas[] = [ - 'id_agent_module' => $module['id_agente_modulo'], - 'sla_max' => (string) $sla_xml->sla_max, - 'sla_min' => (string) $sla_xml->sla_min, - 'sla_limit' => (string) $sla_xml->sla_limit, - ]; - } - } else { - if ($module_clean == io_safe_output($module['nombre'])) { - $slas[] = [ - 'id_agent_module' => $module['id_agente_modulo'], - 'sla_max' => (string) $sla_xml->sla_max, - 'sla_min' => (string) $sla_xml->sla_min, - 'sla_limit' => (string) $sla_xml->sla_limit, - ]; - } - } - } - } - } - } - } - } - break; - - case 'text': - $values['text'] = io_safe_input($item['text']); - break; - - case 'sql': - $values['header_definition'] = io_safe_input($item['header_definition']); - $values['external_source'] = io_safe_input($item['sql']); - break; - - case 'sql_graph_pie': - case 'sql_graph_vbar': - case 'sql_graph_hbar': - $values['header_definition'] = io_safe_input($item['header_definition']); - $values['external_source'] = io_safe_input($item['sql']); - break; - - case 'event_report_group': - $values['id_agent'] = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($item->group)); - break; - - case 'url': - $values['external_source'] = io_safe_input($item['url']); - break; - - case 'database_serialized': - $values['header_definition'] = io_safe_input($item['header_definition']); - $values['line_separator'] = io_safe_input($item['line_separator']); - $values['column_separator'] = io_safe_input($item['column_separator']); - break; - - case 1: - case 'simple_graph': - case 'simple_baseline_graph': - case 6: - case 'monitor_report': - case 7: - case 'avg_value': - case 8: - case 'max_value': - case 9: - case 'min_value': - case 10: - case 'sumatory': - case 'event_report_module': - case 'alert_report_module': - case 'alert_report_agent': - case 'alert_report_group': - case 'agent_detailed_event': - case 'event_report_agent': - default: - // Do nothing. - break; - } - - if (empty($agents_item) === true) { - $id_content = db_process_sql_insert('treport_content', $values); - ui_print_result_message( - $id_content, - sprintf(__("Success add '%s' content."), $values['type']), - sprintf(__("Error add '%s' action."), $values['type']) - ); - - if ($item['type'] == 'SLA') { - foreach ($slas as $sla) { - $sla['id_report_content'] = $id_content; - $result = db_process_sql_insert('treport_content_sla_combined', $sla); - ui_print_result_message( - $result, - sprintf(__("Success add '%s' SLA."), $sla['id_agent_module']), - sprintf(__("Error add '%s' SLA."), $sla['id_agent_module']) - ); - } - } - } else { - foreach ($agents_item as $id_agent => $agent) { - if (empty($agent['modules'])) { - $values['id_agent'] = $id_agent; - $id_content = db_process_sql_insert('treport_content', $values); - ui_print_result_message( - $id_content, - sprintf(__("Success add '%s' content."), $values['type']), - sprintf(__("Error add '%s' action."), $values['type']) - ); - } else { - foreach ($agent['modules'] as $id_module => $module) { - $values['id_agent_module'] = $id_module; - $values['id_agent'] = $id_agent; - - $id_content = db_process_sql_insert('treport_content', $values); - ui_print_result_message( - $id_content, - sprintf(__("Success add '%s' content."), $values['type']), - sprintf(__("Error add '%s' action."), $values['type']) - ); - } - } - } - } - } - } -} - - -function process_upload_xml_visualmap($xml, $filter_group=0) -{ - global $config; - - foreach ($xml->xpath('/visual_map') as $visual_map) { - if (isset($visual_map->name)) { - $values['name'] = (string) $visual_map->name; - } else { - ui_print_error_message( - __("Error create '%s' visual map, lost tag name.") - ); - break; - } - - $values['id_group'] = 0; - if (isset($visual_map->group)) { - $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($visual_map->group)); - if ($id_group !== false) { - $values['id_group'] = $id_group; - } - } - - if (isset($visual_map->background)) { - $values['background'] = (string) $visual_map->background; - } - - $values['width'] = 0; - if (isset($visual_map->width)) { - $values['width'] = (string) $visual_map->width; - } - - $values['height'] = 0; - if (isset($visual_map->height)) { - $values['height'] = (string) $visual_map->height; - } - - $posible_name = $values['name']; - $exist = true; - $loops = 30; - // Loops to exit or tries - while ($exist && $loops > 0) { - $exist = (bool) db_get_row_filter('tlayout', ['name' => io_safe_input($posible_name)]); - - if ($exist) { - $loops--; - $posible_name = $values['name'].' ('.(30 - $loops).')'; - } - } - - if ($exist) { - ui_print_error_message( - sprintf( - __("Error create '%s' visual map, the name exist and there aren't free name."), - $values['name'] - ) - ); - continue; - } else if ($loops != 30) { - ui_print_error_message( - sprintf( - __("Warning create '%s' visual map, the name exist, the report have a name %s."), - $values['name'], - $posible_name - ) - ); - } - - $values['name'] = io_safe_input($posible_name); - $id_visual_map = db_process_sql_insert('tlayout', $values); - - ui_print_result_message( - (bool) $id_visual_map, - sprintf(__("Success create '%s' visual map."), $posible_name), - sprintf(__("Error create '%s' visual map."), $posible_name) - ); - - if ($id_visual_map !== false) { - db_pandora_audit( - AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT, - sprintf('Create Visual Console #%s', $id_visual_map), - $config['id_user'] - ); - } else { - break; - } - - $relation_other_ids = []; - - foreach ($visual_map->item as $item) { - $no_agents = true; - - if (isset($item->agent)) { - $agent_clean = str_replace(['[', ']'], '', $item->agent); - $regular_expresion = ($agent_clean != $item->agent); - - $agents = agents_get_agents(['id_grupo' => $filter_group], ['id_agente', 'nombre']); - if ($agents === false) { - $agents = []; - } - - $temp = []; - foreach ($agents as $agent) { - $temp[$agent['id_agente']] = $agent['nombre']; - } - - $agents = $temp; - - $agents_in_item = []; - foreach ($agents as $id => $agent) { - if ($regular_expresion) { - if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent))) { - $agents_in_item[$id]['name'] = $agent; - $no_agents = false; - } - } else { - if ($agent_clean == io_safe_output($agent)) { - $agents_in_item[$id]['name'] = $agent; - $no_agents = false; - break; - } - } - } - } - - $no_modules = true; - if (isset($item->module)) { - $module_clean = str_replace(['[', ']'], '', $item->module); - $regular_expresion = ($module_clean != $item->module); - - foreach ($agents_in_item as $id => $agent) { - $modules = db_get_all_rows_filter( - 'tagente_modulo', - ['id_agente' => $id], - [ - 'id_agente_modulo', - 'nombre', - ] - ); - - $modules_in_item = []; - foreach ($modules as $module) { - if ($regular_expresion) { - if ((bool) preg_match('/'.$module_clean.'/', io_safe_output($module['nombre']))) { - $modules_in_item[$module['id_agente_modulo']] = $module['nombre']; - $no_modules = false; - } - } else { - if ($module_clean == io_safe_output($module['nombre'])) { - $modules_in_item[$module['id_agente_modulo']] = $module['nombre']; - $no_modules = false; - break; - } - } - } - - $agents_in_item[$id]['modules'] = $modules_in_item; - } - } - - $values = []; - - $values['id_layout'] = $id_visual_map; - if (isset($item->label)) { - $values['label'] = io_safe_input($item->label); - } - - if (isset($item->x)) { - $values['pos_x'] = (string) $item->x; - } - - if (isset($item->y)) { - $values['pos_y'] = (string) $item->y; - } - - if (isset($item->height)) { - $values['height'] = (string) $item->height; - } - - if (isset($item->width)) { - $values['width'] = (string) $item->width; - } - - if (isset($item->image)) { - $values['image'] = (string) $item->image; - } - - if (isset($item->period)) { - $values['period'] = (string) $item->period; - } - - if (isset($item->parent_item)) { - // Hack for link the items use the OTHER_ID - // and have too OTHER_ID - // then $relation_other_ids[OTHER_ID] have the item_id in DB. - $values['parent_item'] = (string) $relation_other_ids[(string) $item->parent_item]; - } - - if (isset($item->map_linked)) { - $values['id_layout_linked'] = (string) $item->map_linked; - } - - if (isset($item->type)) { - $values['type'] = (string) $item->type; - } - - if (isset($item->clock_animation)) { - $values['clock_animation'] = (string) $item->clock_animation; - } - - if (isset($item->fill_color)) { - $values['fill_color'] = (string) $item->fill_color; - } - - if (isset($item->type_graph)) { - $values['type_graph'] = (string) $item->type_graph; - } - - if (isset($item->time_format)) { - $values['time_format'] = (string) $item->time_format; - } - - if (isset($item->timezone)) { - $values['timezone'] = (string) $item->timezone; - } - - if (isset($item->border_width)) { - $values['border_width'] = (string) $item->border_width; - } - - if (isset($item->border_color)) { - $values['border_color'] = (string) $item->border_color; - } - - if ($no_agents) { - $id_item = db_process_sql_insert('tlayout_data', $values); - - ui_print_result_message( - (bool) $id_item, - sprintf(__("Success create item type '%d' visual map."), $values['type']), - sprintf(__("Error create item type '%d' visual map."), $values['type']) - ); - - if ($id_item !== false) { - db_pandora_audit( - AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT, - sprintf('Create Item %s in Visual Console #%s', $id_item, $values['id_layout']), - $config['id_user'] - ); - } - } else { - foreach ($agents_in_item as $id => $agent) { - if ($no_modules) { - $values['id_agent'] = $id; - - $id_item = db_process_sql_insert('tlayout_data', $values); - - if (isset($item->other_id) === true) { - $relation_other_ids[(string) $item->other_id] = $id_item; - } - - ui_print_result_message( - (bool) $id_item, - sprintf(__("Success create item for agent '%s' visual map."), $agent['name']), - sprintf(__("Error create item for agent '%s' visual map."), $agent['name']) - ); - - if ($id_item !== false) { - db_pandora_audit( - AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT, - sprintf('Create Item %s in Visual Console #%s', $id_item, $values['id_layout']), - $config['id_user'] - ); - } - } else { - // TODO: Review this else. - foreach ($agent['modules'] as $id_module => $module) { - $values['id_agent'] = $id; - $values['id_agente_modulo'] = $id_module; - - db_process_sql_insert('tlayout_data', $values); - - ui_print_result_message( - (bool) $id_item, - sprintf(__("Success create item for agent '%s' visual map."), $agent['name']), - sprintf(__("Error create item for agent '%s' visual map."), $agent['name']) - ); - - if ($id_item !== false) { - db_pandora_audit( - AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT, - sprintf('Create Item %s in Visual Console #%s', $id_item, $values['id_layout']), - $config['id_user'] - ); - } - } - } - } - } - } - } -} - - -function process_upload_xml_component($xml) -{ - // Extract components. - $components = []; - foreach ($xml->xpath('/component') as $componentElement) { - $name = io_safe_input((string) $componentElement->name); - $id_os = (int) $componentElement->id_os; - $os_version = io_safe_input((string) $componentElement->os_version); - $data = io_safe_input((string) $componentElement->data); - $type = (int) $componentElement->type; - $group = (int) $componentElement->group; - $description = io_safe_input((string) $componentElement->description); - $module_interval = (int) $componentElement->module_interval; - $max = (float) $componentElement->max; - $min = (float) $componentElement->min; - $tcp_send = io_safe_input((string) $componentElement->tcp_send); - $tcp_rcv_text = io_safe_input((string) $componentElement->tcp_rcv_text); - $tcp_port = (int) $componentElement->tcp_port; - $snmp_oid = io_safe_input((string) $componentElement->snmp_oid); - $snmp_community = io_safe_input((string) $componentElement->snmp_community); - $id_module_group = (int) $componentElement->id_module_group; - $module_source = (int) $componentElement->module_source; - $plugin = (int) $componentElement->plugin; - $plugin_username = io_safe_input((string) $componentElement->plugin_username); - $plugin_password = io_safe_input((string) $componentElement->plugin_password); - $plugin_parameters = io_safe_input((string) $componentElement->plugin_parameters); - $max_timeout = (int) $componentElement->max_timeout; - $max_retries = (int) $componentElement->max_retries; - $historical_data = (int) $componentElement->historical_data; - $dynamic_interval = (int) $componentElement->dynamic_interval; - $dynamic_min = (int) $componentElement->dynamic_min; - $dynamic_max = (int) $componentElement->dynamic_max; - $dynamic_two_tailed = (int) $componentElement->dynamic_two_tailed; - $min_war = (float) $componentElement->min_war; - $max_war = (float) $componentElement->max_war; - $str_war = (string) $componentElement->str_war; - $min_cri = (float) $componentElement->min_cri; - $max_cri = (float) $componentElement->max_cri; - $str_cri = (string) $componentElement->str_cri; - $ff_treshold = (int) $componentElement->ff_treshold; - $snmp_version = (int) $componentElement->snmp_version; - $auth_user = io_safe_input((string) $componentElement->auth_user); - $auth_password = io_safe_input((string) $componentElement->auth_password); - $auth_method = io_safe_input((string) $componentElement->auth_method); - $privacy_method = io_safe_input((string) $componentElement->privacy_method); - $privacy_pass = io_safe_input((string) $componentElement->privacy_pass); - $security_level = io_safe_input((string) $componentElement->security_level); - $wmi_query = io_safe_input((string) $componentElement->wmi_query); - $key_string = io_safe_input((string) $componentElement->key_string); - $field_number = (int) $componentElement->field_number; - $namespace = io_safe_input((string) $componentElement->namespace); - $wmi_user = io_safe_input((string) $componentElement->wmi_user); - $wmi_password = io_safe_input((string) $componentElement->wmi_password); - $post_process = io_safe_input((float) $componentElement->post_process); - - $idComponent = false; - switch ((int) $componentElement->module_source) { - case 1: - // Local component. - $values = [ - 'description' => $description, - 'id_network_component_group' => $group, - 'os_version' => $os_version, - ]; - $return = enterprise_hook('local_components_create_local_component', [$name, $data, $id_os, $values]); - if ($return !== ENTERPRISE_NOT_HOOK) { - $idComponent = $return; - } - break; - - case 2: - // Network component - // for modules - // 15 = remote_snmp, 16 = remote_snmp_inc, - // 17 = remote_snmp_string, 18 = remote_snmp_proc. - $custom_string_1 = ''; - $custom_string_2 = ''; - $custom_string_3 = ''; - if ($type >= 15 && $type <= 18) { - // New support for snmp v3. - $tcp_send = $snmp_version; - $plugin_user = $auth_user; - $plugin_pass = $auth_password; - $plugin_parameters = $auth_method; - $custom_string_1 = $privacy_method; - $custom_string_2 = $privacy_pass; - $custom_string_3 = $security_level; - } - - $idComponent = network_components_create_network_component( - $name, - $type, - $group, - [ - 'description' => $description, - 'module_interval' => $module_interval, - 'max' => $max, - 'min' => $min, - 'tcp_send' => $tcp_send, - 'tcp_rcv' => $tcp_rcv_text, - 'tcp_port' => $tcp_port, - 'snmp_oid' => $snmp_oid, - 'snmp_community' => $snmp_community, - 'id_module_group' => $id_module_group, - 'id_modulo' => $module_source, - 'id_plugin' => $plugin, - 'plugin_user' => $plugin_username, - 'plugin_pass' => $plugin_password, - 'plugin_parameter' => $plugin_parameters, - 'max_timeout' => $max_timeout, - 'max_retries' => $max_retries, - 'history_data' => $historical_data, - 'dynamic_interval' => $dynamic_interval, - 'dynamic_min' => $dynamic_min, - 'dynamic_max' => $dynamic_max, - 'dynamic_two_tailed' => $dynamic_two_tailed, - 'min_warning' => $min_war, - 'max_warning' => $max_war, - 'str_warning' => $str_war, - 'min_critical' => $min_cri, - 'max_critical' => $max_cri, - 'str_critical' => $str_cri, - 'min_ff_event' => $ff_treshold, - 'custom_string_1' => $custom_string_1, - 'custom_string_2' => $custom_string_2, - 'custom_string_3' => $custom_string_3, - 'post_process' => $post_process, - ] - ); - if ((bool) $idComponent === true) { - $components[] = $idComponent; - } - break; - - case 4: - // Plugin component. - $idComponent = network_components_create_network_component( - $name, - $type, - $group, - [ - 'description' => $description, - 'module_interval' => $module_interval, - 'max' => $max, - 'min' => $min, - 'tcp_send' => $tcp_send, - 'tcp_rcv' => $tcp_rcv_text, - 'tcp_port' => $tcp_port, - 'snmp_oid' => $snmp_oid, - 'snmp_community' => $snmp_community, - 'id_module_group' => $id_module_group, - 'id_modulo' => $module_source, - 'id_plugin' => $plugin, - 'plugin_user' => $plugin_username, - 'plugin_pass' => $plugin_password, - 'plugin_parameter' => $plugin_parameters, - 'max_timeout' => $max_timeout, - 'max_retries' => $max_retries, - 'history_data' => $historical_data, - 'dynamic_interval' => $dynamic_interval, - 'dynamic_min' => $dynamic_min, - 'dynamic_max' => $dynamic_max, - 'dynamic_two_tailed' => $dynamic_two_tailed, - 'min_warning' => $min_war, - 'max_warning' => $max_war, - 'str_warning' => $str_war, - 'min_critical' => $min_cri, - 'max_critical' => $max_cri, - 'str_critical' => $str_cri, - 'min_ff_event' => $ff_treshold, - 'custom_string_1' => $custom_string_1, - 'custom_string_2' => $custom_string_2, - 'custom_string_3' => $custom_string_3, - 'post_process' => $post_process, - ] - ); - if ((bool) $idComponent === true) { - $components[] = $idComponent; - } - break; - - case 6: - // WMI component. - $idComponent = network_components_create_network_component( - $name, - $type, - $group, - [ - 'description' => $description, - 'module_interval' => $module_interval, - 'max' => $max, - 'min' => $min, - 'tcp_send' => $namespace, - // work around - 'tcp_rcv' => $tcp_rcv_text, - 'tcp_port' => $field_number, - // work around - 'snmp_oid' => $wmi_query, - // work around - 'snmp_community' => $key_string, - // work around - 'id_module_group' => $id_module_group, - 'id_modulo' => $module_source, - 'id_plugin' => $plugin, - 'plugin_user' => $wmi_user, - // work around - 'plugin_pass' => $wmi_password, - // work around - 'plugin_parameter' => $plugin_parameters, - 'max_timeout' => $max_timeout, - 'max_retries' => $max_retries, - 'history_data' => $historical_data, - 'dynamic_interval' => $dynamic_interval, - 'dynamic_min' => $dynamic_min, - 'dynamic_max' => $dynamic_max, - 'dynamic_two_tailed' => $dynamic_two_tailed, - 'min_warning' => $min_war, - 'max_warning' => $max_war, - 'str_warning' => $str_war, - 'min_critical' => $min_cri, - 'max_critical' => $max_cri, - 'str_critical' => $str_cri, - 'min_ff_event' => $ff_treshold, - 'custom_string_1' => $custom_string_1, - 'custom_string_2' => $custom_string_2, - 'custom_string_3' => $custom_string_3, - 'post_process' => $post_process, - ] - ); - if ((bool) $idComponent === true) { - $components[] = $idComponent; - } - break; - - case 5: - // Prediction component. - case 7: - // Web component. - default: - // Do nothing. - break; - } - - ui_print_result_message( - (bool) $idComponent, - sprintf(__("Success create '%s' component."), $name), - sprintf(__("Error create '%s' component."), $name) - ); - } - - // Extract the template. - $templateElement = $xml->xpath('//template'); - if (empty($templateElement) === false) { - $templateElement = $templateElement[0]; - - $templateName = (string) $templateElement->name; - $templateDescription = (string) $templateElement->description; - - $idTemplate = db_process_sql_insert('tnetwork_profile', ['name' => $templateName, 'description' => $templateDescription]); - - $result = false; - if ((bool) $idTemplate) { - foreach ($components as $idComponent) { - db_process_sql_insert('tnetwork_profile_component', ['id_nc' => $idComponent, 'id_np' => $idTemplate]); - } - } - } -} - - -function process_upload_xml($xml) -{ - $hook_enterprise = enterprise_include('extensions/resource_registration/functions.php'); - - // Extract component. - process_upload_xml_component($xml); - - $group_filter = get_parameter('group'); - - // Extract visual map. - process_upload_xml_visualmap($xml, $group_filter); - - // Extract policies. - if ($hook_enterprise === true) { - $centralized_management = is_management_allowed(); - if ($centralized_management === true) { - process_upload_xml_policy($xml, $group_filter); - } - } - - // Extract reports. - process_upload_xml_report($xml, $group_filter); -} - - -function resource_registration_extension_main() -{ - global $config; - - if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) { - db_pandora_audit( - AUDIT_LOG_ACL_VIOLATION, - 'Trying to access Setup Management' - ); - include 'general/noaccess.php'; - return; - } - - include_once $config['homedir'].'/include/functions_network_components.php'; - include_once $config['homedir'].'/include/functions_db.php'; - enterprise_include_once('include/functions_local_components.php'); - - ui_print_standard_header( - __('Resource registration'), - 'images/extensions.png', - false, - '', - true, - [], - [ - [ - 'link' => '', - 'label' => __('Resources'), - ], - [ - 'link' => '', - 'label' => __('Resource registration'), - ], - ] - ); - - if (extension_loaded('libxml') === false) { - ui_print_error_message(_('Error, please install the PHP libXML in the system.')); - - return; - } - - if (is_management_allowed() === false) { - if (is_metaconsole() === false) { - $url = ''.__('metaconsole').''; - } else { - $url = __('any node'); - } - - ui_print_warning_message( - __( - 'This node is configured with centralized mode. Go to %s to create a policy.', - $url - ) - ); - - return; - } - - ui_print_warning_message( - __('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') - ); - - $table = new stdClass(); - $table->class = 'databox filter-table-adv'; - $table->id = 'resource_registration_table'; - - $table->data = []; - - $table->data[0][] = html_print_label_input_block( - __('File to upload'), - html_print_input_file('resource_upload', true) - ); - - $table->data[0][] = html_print_label_input_block( - __('Group filter'), - html_print_select_groups(false, 'AW', true, 'group', '', '', __('All'), 0, true) - ); - - // Upload form. - echo '
'; - html_print_table($table); - html_print_action_buttons( - html_print_submit_button( - __('Upload'), - 'upload', - false, - [ 'icon' => 'wand' ], - true - ), - ['type' => 'form_action'] - ); - echo '
'; - /* - echo ''; - echo ''; - echo "'; - echo ''; - echo "'; - echo '
"; - echo ''.__('Group filter: ').''; - html_print_select_groups(false, 'AW', true, 'group'); - echo '"; - echo '
';*/ - - if (isset($_FILES['resource_upload']['tmp_name']) === false) { - return; - } - - $xml = simplexml_load_file($_FILES['resource_upload']['tmp_name'], null, LIBXML_NOCDATA); - - if ($xml === false) { - ui_print_error_message( - __('Error uploading resource. Check if the selected file is a valid resource template in .ptr format') - ); - } else { - process_upload_xml($xml); - } -} - - -extensions_add_godmode_menu_option(__('Resource registration'), 'PM', 'gagente', '', 'v1r1'); -extensions_add_godmode_function('resource_registration_extension_main'); diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index f3eada8070..b3fbea46dd 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -1736,3 +1736,5 @@ extensions/files_repo/sql/files_repo.oracle.sql extensions/files_repo/sql/files_repo.postgreSQL.sql extensions/files_repo/sql/files_repo.sql extensions/files_repo +extensions/resource_exportation.php +extensions/resource_registration.php diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index 254cb2e7c1..30762d513b 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -1,14 +1,97 @@ START TRANSACTION; +CREATE TABLE IF NOT EXISTS `tmerge_error` ( + `id` int(10) NOT NULL auto_increment, + `id_node` int(10) default 0, + `phase` int(10) default 0, + `step` int(10) default 0, + `msg` LONGTEXT default "", + `action` text default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +ALTER TABLE `tmerge_error` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `tmerge_steps` ( + `id` int(10) NOT NULL auto_increment, + `id_node` int(10) default 0, + `phase` int(10) default 0, + `total` int(10) default 0, + `step` int(10) default 0, + `debug` varchar(1024) default "", + `action` varchar(100) default "", + `affected` varchar(100) default "", + `query` mediumtext default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +ALTER TABLE `tmerge_steps` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `tmerge_queries` ( + `steps` int(10) NOT NULL auto_increment, + `action` varchar(100) default "", + `affected` varchar(100) default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + `query` LONGTEXT NOT NULL default "", + PRIMARY KEY (`steps`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +ALTER TABLE `tmerge_queries` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; + +ALTER TABLE `tevent_sound` MODIFY COLUMN `name` text NULL; +ALTER TABLE `tevent_sound` MODIFY COLUMN `sound` text NULL; +ALTER TABLE `treport_content` MODIFY COLUMN `use_prefix_notation` tinyint unsigned NOT NULL DEFAULT 1; +ALTER TABLE `treport_content_template` MODIFY COLUMN `use_prefix_notation` tinyint unsigned NOT NULL DEFAULT 1; +ALTER TABLE `tsesion_filter` MODIFY COLUMN `id_name` text NULL; +ALTER TABLE `tsesion_filter` MODIFY COLUMN `ip` text NULL; +ALTER TABLE `tsesion_filter` MODIFY COLUMN `type` text NULL; +ALTER TABLE `tsesion_filter` MODIFY COLUMN `user` text NULL; +ALTER TABLE `tncm_agent_data` +ADD COLUMN `id_agent_data` int not null default 0 AFTER `script_type`; +ALTER TABLE `tusuario` CHANGE COLUMN `metaconsole_data_section` `metaconsole_data_section` TEXT NOT NULL DEFAULT '' ; +ALTER TABLE `tmensajes` ADD COLUMN `icon_notification` VARCHAR(250) NULL DEFAULT NULL AFTER `url`; + +UPDATE `tncm_template` SET `vendors` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM vendors))), '"]'), `models` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM models))), '"]'); +UPDATE `tncm_agent_data_template` SET `vendors` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM vendors))), '"]'), `models` = CONCAT('["', TRIM(BOTH '"' FROM TRIM(BOTH ']' FROM TRIM(BOTH '[' FROM models))), '"]'); + -- Update version for plugin oracle UPDATE `tdiscovery_apps` SET `version` = '1.2' WHERE `short_name` = 'pandorafms.oracle'; -ALTER TABLE `tncm_agent_data` -ADD COLUMN `id_agent_data` int not null default 0 AFTER `script_type`; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = 'GisMap'; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,'GisMap','GisMap','Gis map','','GisMap.php'); -ALTER TABLE `tusuario` CHANGE COLUMN `metaconsole_data_section` `metaconsole_data_section` TEXT NOT NULL DEFAULT '' ; - -ALTER TABLE `tmensajes` ADD COLUMN `icon_notification` VARCHAR(250) NULL DEFAULT NULL AFTER `url`; +SET @class_name = 'ITSMIncidences'; +SET @unique_name = 'ITSMIncidences'; +SET @description = 'Pandora ITSM tickets'; +SET @page = 'ITSMIncidences.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); +-- Create SNMPv3 credentials for recon tasks and update them +SET @creds_name = 'Recon-SNMP-creds-'; +INSERT IGNORE INTO `tcredential_store` (`identifier`, `id_group`, `product`, `extra_1`) + SELECT + CONCAT(@creds_name,`id_rt`) AS `identifier`, + `id_group`, + 'SNMP' AS `product`, + CONCAT( + '{', + '"community":"',`snmp_community`,'",', + '"version":"',`snmp_version`,'",', + '"securityLevelV3":"',`snmp_security_level`,'",', + '"authUserV3":"',`snmp_auth_user`,'",', + '"authMethodV3":"',`snmp_auth_method`,'",', + '"authPassV3":"',`snmp_auth_pass`,'",', + '"privacyMethodV3":"',`snmp_privacy_method`,'",', + '"privacyPassV3":"',`snmp_privacy_pass`,'"', + '}' + ) AS `extra1` + FROM `trecon_task` WHERE `snmp_version` = 3 AND `snmp_enabled` = 1 +; +UPDATE `trecon_task` SET `auth_strings` = IF(`auth_strings` = '',CONCAT(@creds_name,`id_rt`),CONCAT(@creds_name,`id_rt`,',',`auth_strings`)) WHERE `snmp_version` = 3 AND `snmp_enabled` = 1; COMMIT; \ No newline at end of file diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 5ad89d8d31..e2573bd859 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -54,7 +54,7 @@ echo sprintf('
', $menuTypeClass); // ======= Servers List =============================================== if ((bool) check_acl($config['id_user'], 0, 'AW') !== false) { $servers = []; - $servers['all'] = (int) db_get_value('COUNT(id_server)', 'tserver'); + $servers['all'] = (int) count((servers_get_info() ?? [])); if ($servers['all'] != 0) { $servers['up'] = (int) servers_check_status(); $servers['down'] = ($servers['all'] - $servers['up']); @@ -1021,11 +1021,14 @@ echo sprintf('
', $menuTypeClass); modal: { title: "", cancel: '', - ok: '' + ok: '', + overlay: true, + overlayExtraClass: 'welcome-overlay', }, onshow: { page: 'include/ajax/welcome_window', method: 'loadWelcomeWindow', + width: 1000, }, oncancel: { page: 'include/ajax/welcome_window', @@ -1043,6 +1046,34 @@ echo sprintf('
', $menuTypeClass); } }) } + }, + onload: () => { + $(document).ready(function () { + var buttonpane = $("div[aria-describedby='welcome_modal_window'] .ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix"); + $(buttonpane).append(` +
+ + +
+ `); + + var closeWizard = $("button.close-wizard-button"); + + $(closeWizard).click(function (e) { + var close = $("div[aria-describedby='welcome_modal_window'] button.sub.ok.submit-next.ui-button"); + var cancel = $("div[aria-describedby='welcome_modal_window'] button.sub.upd.submit-cancel.ui-button"); + var checkbox = $("div[aria-describedby='welcome_modal_window'] .welcome-wizard-do-not-show:checked").length; + + if (checkbox === 1) { + $(cancel).click(); + } else { + $(close).click() + } + }); + }); } }); }); diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 759e319dbd..ed583c7ed4 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -100,7 +100,7 @@ if ($initial && users_is_admin()) { ); } -if (check_acl($config['id_user'], 0, 'AW')) { +if (check_acl($config['id_user'], 0, 'AW') && empty($sec2)) { $welcome = !$initial; try { $welcome_window = new WelcomeWindow($welcome); diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 4e62337547..18722508e9 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -357,7 +357,18 @@ if ($new_agent === false) { $tableAgent->data['caption_name'][0] = __('Agent name'); $tableAgent->rowclass['name'] = 'w540px'; $tableAgent->cellstyle['name'][0] = 'width: 100%;'; - $tableAgent->data['name'][0] = html_print_input_text('agente', $nombre_agente, '', 76, 100, true, false, false, '', 'w100p'); + $tableAgent->data['name'][0] = html_print_input_text( + 'agente', + $nombre_agente, + '', + 76, + 100, + true, + true, + false, + '', + 'w100p' + ); $tableAgent->data['name'][0] .= html_print_div( [ 'class' => 'moduleIdBox', @@ -365,6 +376,29 @@ if ($new_agent === false) { ], true ); + + // Other than Linux, Solaris, AIX, BSD, HPUX, MacOs, and Windows. + if ($id_os !== LINUX && $id_os !== SOLARIS && $id_os !== AIX + && $id_os !== BSD && $id_os !== HPUX && $id_os !== MACOS + && $id_os !== WINDOWS + ) { + $tableAgent->data['name'][0] .= html_print_anchor( + [ + 'content' => html_print_image( + 'images/edit.svg', + true, + [ + 'border' => 0, + 'title' => __('Edit agent name'), + 'class' => 'main_menu_icon invert_filter after_input_icon forced_title clickable', + 'onclick' => 'editAgent()', + ] + ), + ], + true + ); + } + // Agent options for QR code. $agent_options_update = 'agent_options_update'; } @@ -500,21 +534,42 @@ $tableAgent->data['primary_group'][0] .= ui_print_group_icon( ); $tableAgent->data['primary_group'][0] .= ''; -$tableAgent->data['caption_interval'][0] = __('Interval'); -// $tableAgent->rowstyle['interval'] = 'width: 260px'; -$tableAgent->rowclass['interval'] = 'w540px'; -$tableAgent->data['interval'][0] = html_print_extended_select_for_time( - 'intervalo', - $intervalo, - '', - '', - '0', - 10, - true, - false, - true, - 'w33p' -); +$broker = false; +if (enterprise_installed()) { + // CHECK BROKER FOR SHOW INTERVAL. + enterprise_include('include/functions_config_agents.php'); + // Read configuration file. + $files = config_agents_get_agent_config_filenames($id_agente); + $file_name = $files['conf']; + if (empty($file_name) === false) { + $agent_config = file_get_contents($file_name); + $encoding = 'UTF-8'; + $agent_config_utf8 = mb_convert_encoding($agent_config, 'UTF-8', $encoding); + if ($agent_config_utf8 !== false) { + $agent_config = $agent_config_utf8; + } + + $broker = str_contains($agent_config, '#broker active'); + } +} + +if ($broker === false) { + $tableAgent->data['caption_interval'][0] = __('Interval'); + // $tableAgent->rowstyle['interval'] = 'width: 260px'; + $tableAgent->rowclass['interval'] = 'w540px'; + $tableAgent->data['interval'][0] = html_print_extended_select_for_time( + 'intervalo', + $intervalo, + '', + '', + '0', + 10, + true, + false, + true, + 'w33p' + ); +} if ($intervalo < SECONDS_5MINUTES) { $tableAgent->data['interval'][0] .= clippy_context_help('interval_agent_min'); @@ -653,6 +708,19 @@ if (enterprise_installed()) { } } + if ($id_os === '1') { + $modules = $agent_plugin->getModules(); + foreach ($modules as $key => $row) { + if (preg_match('/Syslog/', $row['raw']) === 1) { + if ($row['disabled'] === 1) { + $enable_log_collector = 0; + } else { + $enable_log_collector = 1; + } + } + } + } + if ($id_os === '9') { $modules = $agent_plugin->getModules(); foreach ($modules as $key => $row) { @@ -1457,7 +1525,6 @@ ui_require_jquery_file('bgiframe'); 128 ); } - $("#text-agente").prop('readonly', true); $("#text-direccion").on('change',function(e){ @@ -1504,6 +1571,39 @@ ui_require_jquery_file('bgiframe'); } } + function editAgent() { + $(`#text-agente`).attr(`readonly`, false); + const title = ''; + const text = ''; + const id = uniqId(); + $("body").append('
'); + $("#" + id).empty(); + $("#" + id).append(text); + $("#" + id).dialog({ + height: 150, + width: 528, + opacity: 1, + modal: true, + position: { + my: "center", + at: "center", + of: window, + collision: "fit" + }, + title: title, + closeOnEscape: true, + buttons: [{ + text: "OK", + click: function() { + $(this).dialog("close"); + } + }], + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + }, + }).show(); + } + function check_unique_ip() { const direccion = $('#text-direccion').val(); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c2e3a2f4f6..c6b5f2b691 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -949,6 +949,13 @@ if ($update_agent) { $mssg_warning = 0; $id_agente = (int) get_parameter_post('id_agente'); $nombre_agente = str_replace('`', '‘', (string) get_parameter_post('agente', '')); + $repeated_name = db_get_row_sql( + sprintf( + 'SELECT nombre FROM tagente WHERE id_agente <> %s AND nombre like "%s"', + $id_agente, + $nombre_agente + ) + ); $alias_safe_output = strip_tags(io_safe_output(get_parameter('alias', ''))); $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output))); $alias_as_name = (int) get_parameter_post('alias_as_name', 0); @@ -1077,14 +1084,17 @@ if ($update_agent) { } } + // Verify if there is another agent with the same name but different ID. + if (empty($repeated_name) === false) { + ui_print_error_message(__('Agent with repeated name')); + } + if ($mssg_warning) { ui_print_warning_message(__('The ip or dns name entered cannot be resolved')); } - // Verify if there is another agent with the same name but different ID. if ($alias == '') { ui_print_error_message(__('No agent alias specified')); - // If there is an agent with the same name, but a different ID. } $old_group = agents_get_agent_group($id_agente); @@ -1139,13 +1149,16 @@ if ($update_agent) { 'ignore_unknown' => $ignore_unknown, ]; + if (empty($repeated_name) === true) { + $values['nombre'] = $nombre_agente; + } + if ($config['metaconsole_agent_cache'] == 1) { $values['update_module_count'] = 1; // Force an update of the agent cache. } - $result = db_process_sql_update('tagente', $values, ['id_agente' => $id_agente]); - + $result = (bool) db_process_sql_update('tagente', $values, ['id_agente' => $id_agente]); if ($result === false && $update_custom_result == false) { ui_print_error_message( __('There was a problem updating the agent') @@ -1299,8 +1312,11 @@ if ($update_agent) { } $modules = $agent->getModules(); + foreach ($modules as $key => $row) { - if (preg_match('/PandoraAgent_log/', $row['raw']) === 1) { + if (preg_match('/PandoraAgent_log/', $row['raw']) === 1 + || ($id_os === 1 && preg_match('/Syslog/', $row['raw']) === 1) + ) { if ($enable_log_collector === 1) { if ($row['disabled'] === 1) { $agent->enableModule($row['module_name'], $row); diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index a7ee6bf4c0..b0f071c1b4 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -697,7 +697,7 @@ if ($agents !== false) { $tableAgents->head = []; $tableAgents->data = []; // Header. - $tableAgents->head[0] = ''.__('Agent name').''; + $tableAgents->head[0] = ''.__('Agent alias').''; $tableAgents->head[0] .= ui_get_sorting_arrows($url_up_agente, $url_down_agente, $selectNameUp, $selectNameDown); $tableAgents->head[1] = ''.__('R').''; $tableAgents->head[1] .= ui_get_sorting_arrows($url_up_remote, $url_down_remote, $selectRemoteUp, $selectRemoteDown); diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index b4cd0e2351..c3772c00d3 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -575,7 +575,7 @@ $where = sprintf('delete_pending = 0 AND id_agente = %s', $id_agente); $search_string_entities = io_safe_input($search_string); $basic_where = sprintf( - "(REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%') AND", + "(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 130f31c79d..543d241fc9 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -150,7 +150,7 @@ if (is_ajax()) { $component = db_get_row('tlocal_component', 'id', $id_component); foreach ($component as $index => $element) { $component[$index] = html_entity_decode( - $element, + (isset($element) === true) ? $element : '', ENT_QUOTES, 'UTF-8' ); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 47c843f2d9..a9d809d29f 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -505,7 +505,7 @@ $tableBasicThresholds->data['caption_switch_warning_inverse_string'][0] = html_p $tableBasicThresholds->data['caption_warning_threshold'][0] .= '('.__('Str.').')'; $tableBasicThresholds->data['warning_threshold'][0] .= html_print_input_text( 'str_warning', - str_replace('"', '', $str_warning), + str_replace('"', '', (isset($str_warning) === true) ? $str_warning : ''), '', 10, 1024, @@ -602,7 +602,7 @@ $tableBasicThresholds->data['switch_critical_threshold'][0] .= html_print_div( $tableBasicThresholds->data['caption_critical_threshold'][0] .= '('.__('Str.').')'; $tableBasicThresholds->data['critical_threshold'][0] .= html_print_input_text( 'str_critical', - str_replace('"', '', $str_critical), + str_replace('"', '', (isset($str_critical) === true) ? $str_critical : ''), '', 10, 1024, diff --git a/pandora_console/godmode/agentes/module_manager_editor_plugin.php b/pandora_console/godmode/agentes/module_manager_editor_plugin.php index 9b5d98c27d..abbbc4d9c1 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_plugin.php +++ b/pandora_console/godmode/agentes/module_manager_editor_plugin.php @@ -60,7 +60,12 @@ $data[1] = html_print_select_from_sql( $disabledBecauseInPolicy ); // Store the macros in base64 into a hidden control to move between pages -$data[1] .= html_print_input_hidden('macros', base64_encode($macros), true); +$data[1] .= html_print_input_hidden( + 'macros', + (isset($macros) === true) ? base64_encode($macros) : '', + true +); + $table_simple->colspan['plugin_1'][2] = 2; if (!empty($id_plugin)) { diff --git a/pandora_console/godmode/alerts/alert_view.php b/pandora_console/godmode/alerts/alert_view.php index 7809742221..499bbded5e 100644 --- a/pandora_console/godmode/alerts/alert_view.php +++ b/pandora_console/godmode/alerts/alert_view.php @@ -308,13 +308,18 @@ $table->head[0] = __('Actions'); $table->style[0] = 'font-weight: bold; text-align: left;'; if (count($actions) == 1 && isset($actions[0])) { - $table->head[1] = __('Every time that the alert is fired'); - $table->data[0][0] = $actions[0]['name']; - $table->data[0][1] = html_print_image( - 'images/tick.png', - true, - ['class' => 'invert_filter'] - ); + if (!empty($actions[0]['name'])) { + $table->head[1] = __('Every time that the alert is fired'); + $table->data[0][0] = $actions[0]['name']; + $table->data[0][1] = html_print_image( + 'images/tick.png', + true, + ['class' => 'invert_filter'] + ); + } else { + $table->colspan[0] = 2; + $table->data[0] = __('No action defined.'); + } } else { foreach ($actions as $kaction => $action) { $table->data[$kaction][0] = $action['name']; diff --git a/pandora_console/godmode/events/event_responses.editor.php b/pandora_console/godmode/events/event_responses.editor.php index ae31e10ad1..52d5a48ad1 100644 --- a/pandora_console/godmode/events/event_responses.editor.php +++ b/pandora_console/godmode/events/event_responses.editor.php @@ -285,20 +285,25 @@ if (enterprise_installed()) { $data = []; $data[0] = html_print_label_input_block( '', - '