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 c8ee8180a7..acf998e94c 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-240126 +Version: 7.0NG.775-240222 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 fa783cc923..a3cb485e4b 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-240126" +pandora_version="7.0NG.775-240222" 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 112e0419da..0947982db3 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 => '240126'; +use constant AGENT_BUILD => '240222'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; @@ -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 5c05e6110e..31dcaffaeb 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 240126 +%define release 240222 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 78383784e9..2e29ba964f 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 240126 +%define release 240222 %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 b21d106a96..7f53a67a6b 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 240126 +%define release 240222 %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 7a15966693..d018c4679f 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 240126 +%define release 240222 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 337a0ec5f3..f7cc2a290d 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 240126 +%define release 240222 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 2f6e9c4d3d..a275fcfa5c 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="240126" +PI_BUILD="240222" 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/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 95fa0dd4a3..70c7ecb53b 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{240126} +{240222} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index f3961807fe..fa9c417123 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 240126") +#define PANDORA_VERSION ("7.0NG.775 Build 240222") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 1bb160a879..16ec5fe61c 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 240126))" + VALUE "ProductVersion", "(7.0NG.775(Build 240222))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 466722a50b..de7e2de6f5 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.775-240126 +Version: 7.0NG.775-240222 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 a47efa89c2..705993798a 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-240126" +pandora_version="7.0NG.775-240222" package_pear=0 package_pandora=1 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/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/discovery/DiscoveryApplicationsMigrateCodes.ini b/pandora_console/extras/discovery/DiscoveryApplicationsMigrateCodes.ini index d05611a6b5..ea136c996c 100644 --- a/pandora_console/extras/discovery/DiscoveryApplicationsMigrateCodes.ini +++ b/pandora_console/extras/discovery/DiscoveryApplicationsMigrateCodes.ini @@ -1,5 +1,5 @@ pandorafms.vmware=248788e0fb2cd4e11623e4a52ee7d05b -pandorafms.mysql=fadb4750d18285c0eca34f47c6aa3cfe +pandorafms.mysql=ca7dd8b80a1a03a25eb0fb077818ad63 pandorafms.mssql=1cc215409741d19080269ffba112810e pandorafms.oracle=abdfd7280f76276f696115cabdac731e pandorafms.db2=122f2abff0ec1d668c35ee0911483021 diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index ea4bf2a2a1..b41f6c3e6c 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -40,15 +40,63 @@ CREATE TABLE IF NOT EXISTS `tmerge_queries` ( ALTER TABLE `tmerge_queries` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; --- Update version for plugin oracle -UPDATE `tdiscovery_apps` SET `version` = '1.2' WHERE `short_name` = 'pandorafms.oracle'; - +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`; +ALTER TABLE `tagente_modulo` ADD COLUMN `disabled_by_safe_mode` TINYINT UNSIGNED NOT NULL DEFAULT 0; -COMMIT; +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'; +-- Update version for plugin mysql +UPDATE `tdiscovery_apps` SET `version` = '1.1' WHERE `short_name` = 'pandorafms.mysql'; + + +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'); + +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/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 80a480dd12..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'; } @@ -507,14 +541,16 @@ if (enterprise_installed()) { // Read configuration file. $files = config_agents_get_agent_config_filenames($id_agente); $file_name = $files['conf']; - $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; - } + 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'); + $broker = str_contains($agent_config, '#broker active'); + } } if ($broker === false) { @@ -672,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) { @@ -1476,7 +1525,6 @@ ui_require_jquery_file('bgiframe'); 128 ); } - $("#text-agente").prop('readonly', true); $("#text-direccion").on('change',function(e){ @@ -1523,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..affa225969 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)) { @@ -159,12 +164,13 @@ foreach ($password_fields as $k => $p) { return; } - const moduleId = ; - + const moduleId = 0) ? $module['id'] : $id_agent_module; ?>; + const isPolicy = 0) ? '1' : '0'; ?>; + load_plugin_description($("#id_plugin").val()); - - load_plugin_macros_fields('simple-macro', moduleId); - + + load_plugin_macros_fields('simple-macro', moduleId, isPolicy); + forced_title_callback(); $('select#id_plugin').select2('close'); diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index 66717bc35b..f1b40867d9 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -560,13 +560,13 @@ if ($is_management_allowed === true && $update_group === true) { } } +$id_group = (int) get_parameter('id_group'); + // Delete group. if ($is_management_allowed === true && $delete_group === true - && ((bool) check_acl($config['id_user'], 0, 'PM') === true) + && ((bool) check_acl($config['id_user'], $id_group, 'PM') === true) ) { - $id_group = (int) get_parameter('id_group'); - $usedGroup = groups_check_used($id_group); if (!$usedGroup['return']) { @@ -880,6 +880,28 @@ if ($tab == 'tree') { echo "
"; + if (users_can_manage_group_all('AR') === false) { + $user_groups_acl = users_get_groups(false, 'AR'); + $groups_acl = implode('","', $user_groups_acl); + if (empty($groups_acl) === true) { + $is_management_allowed = false; + } + } + + html_print_div( + [ + 'content' => ui_print_info_message( + [ + 'no_close' => true, + 'message' => __('There are no defined groups'), + ], + '', + true + ), + 'class' => 'invisible', + 'id' => 'message-tree-info', + ] + ); } else { /* * Group list view. @@ -1246,7 +1268,7 @@ $tab = 'group_edition'; treeController.init({ recipient: $("div#tree-controller-recipient"), page: parameters['page'], - emptyMessage: "", + emptyMessage: $("#message-tree-info").html(), foundMessage: "", tree: data.tree, baseURL: "", diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 82698266a1..9a57ef9d53 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -319,9 +319,8 @@ if ($update_agents) { $secondary_groups_removed ); - $agents_values = agents_get_agent((int) $array_id[1]); + $agents_values = db_get_row_filter('tagente', ['id_agente' => (int) $array_id[1]]); $node->disconnect(); - if (empty($values) === false) { update_agents_in_metaconsole( (int) $array_id[1], diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 9b11b86916..2b8990c065 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -768,7 +768,7 @@ $table_critical->tdid[0][0] = 'edit1-3-min'; $table_critical->data[0][0] = html_print_label_input_block( __('Min.'), html_print_input_text( - 'min_warning', + 'min_critical', '', '', false, @@ -781,7 +781,7 @@ $table_critical->tdid[0][1] = 'edit1-3-max'; $table_critical->data[0][1] = html_print_label_input_block( __('Max.'), html_print_input_text( - 'max_warning', + 'max_critical', '', '', false, @@ -1500,7 +1500,7 @@ $table->data[39][0] = html_print_label_input_block( '', '', true - ).html_print_input_hidden('macros', base64_encode($macros), true) + ).html_print_input_hidden('macros', base64_encode(($macros ?? '')), true) ); require_once $config['homedir'].'/include/class/CredentialStore.class.php'; diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index a77e63b95b..68d789cd74 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -208,6 +208,9 @@ if ($access_console_node === true) { $sub['godmode/setup/os']['text'] = __('Operating systems'); $sub['godmode/setup/os']['id'] = 'edit_OS'; + + $sub['godmode/resources/resources_export_import']['text'] = __('Resources export/import'); + $sub['godmode/resources/resources_export_import']['id'] = 'resources_export_import'; } if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { @@ -518,7 +521,18 @@ if ($access_console_node === true) { } -if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) check_acl($config['id_user'], 0, 'DM') === true) { +if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { + $show_ipam = false; + $ipam = db_get_all_rows_sql('SELECT users_operator FROM tipam_network'); + foreach ($ipam as $row) { + if (str_contains($row['users_operator'], '-1') || str_contains($row['users_operator'], $config['id_user'])) { + $show_ipam = true; + break; + } + } +} + +if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) check_acl($config['id_user'], 0, 'DM') === true || $show_ipam === true) { $menu_godmode['gextensions']['text'] = __('Admin tools'); $menu_godmode['gextensions']['sec2'] = 'godmode/extensions'; $menu_godmode['gextensions']['id'] = 'god-extensions'; @@ -535,8 +549,6 @@ if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) check_acl($ $sub['tools/diagnostics']['text'] = __('Diagnostic info'); $sub['tools/diagnostics']['id'] = 'diagnostic_info'; enterprise_hook('omnishell'); - enterprise_hook('ipam_submenu'); - $sub['godmode/setup/news']['text'] = __('Site news'); $sub['godmode/setup/news']['id'] = 'site_news'; } @@ -558,9 +570,15 @@ if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) check_acl($ } } - $sub['godmode/events/configuration_sounds']['text'] = __('Acoustic console setup'); - $sub['godmode/events/configuration_sounds']['id'] = 'Acoustic console setup'; - $sub['godmode/events/configuration_sounds']['pages'] = ['godmode/events/configuration_sounds']; + if (((bool) check_acl($config['id_user'], 0, 'PM') === true && $access_console_node === true) || $show_ipam === true) { + enterprise_hook('ipam_submenu'); + } + + if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) check_acl($config['id_user'], 0, 'DM') === true) { + $sub['godmode/events/configuration_sounds']['text'] = __('Acoustic console setup'); + $sub['godmode/events/configuration_sounds']['id'] = 'Acoustic console setup'; + $sub['godmode/events/configuration_sounds']['pages'] = ['godmode/events/configuration_sounds']; + } $menu_godmode['gextensions']['sub'] = $sub; } @@ -638,16 +656,18 @@ if ($access_console_node === true) { } // Complete the submenu. - $extension_view = []; - $extension_view['godmode/extensions']['id'] = 'extension_manager_view'; - $extension_view['godmode/extensions']['text'] = __('Extension manager view'); - $extension_submenu = array_merge($extension_view, $sub2); + if (users_is_admin($config['id_user']) === true) { + $extension_view = []; + $extension_view['godmode/extensions']['id'] = 'extension_manager_view'; + $extension_view['godmode/extensions']['text'] = __('Extension manager view'); + $extension_submenu = array_merge($extension_view, $sub2); - $sub['godmode/extensions']['sub2'] = $extension_submenu; - $sub['godmode/extensions']['text'] = __('Extension manager'); - $sub['godmode/extensions']['id'] = 'extension_manager'; - $sub['godmode/extensions']['type'] = 'direct'; - $sub['godmode/extensions']['subtype'] = 'nolink'; + $sub['godmode/extensions']['sub2'] = $extension_submenu; + $sub['godmode/extensions']['text'] = __('Extension manager'); + $sub['godmode/extensions']['id'] = 'extension_manager'; + $sub['godmode/extensions']['type'] = 'direct'; + $sub['godmode/extensions']['subtype'] = 'nolink'; + } if (is_array($menu_godmode['gextensions']['sub']) === true) { $submenu = array_merge($menu_godmode['gextensions']['sub'], $sub); diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 74d9f07527..b30f1d6c43 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -5941,6 +5941,7 @@ ui_require_javascript_file('pandora'); ?> \ No newline at end of file diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 39acc45c21..991ed52855 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -215,7 +215,7 @@ if ($create != '') { // ===================================================================== if ($filemanager) { if ($edit_file) { - $location_file = get_parameter('location_file', ''); + $location_file = io_safe_output(get_parameter('location_file', '')); $filename = array_pop(explode('/', $location_file)); $file = file_get_contents($location_file); echo '

'.__('Edit file').' '.$filename.'

'; @@ -250,7 +250,7 @@ if ($filemanager) { echo ''; } else { if ($update_file) { - $location_file = get_parameter('location_file', ''); + $location_file = io_safe_output(get_parameter('location_file', '')); $contentFile = io_safe_output(get_parameter('content_file', '')); $compatibility = get_parameter('compatibility', 'unix'); $is_win_compatible = strpos($contentFile, "\r\n"); @@ -262,7 +262,12 @@ if ($filemanager) { $contentFile = str_replace("\n", "\r\n", $contentFile); } - $result = file_put_contents($location_file, $contentFile); + if (empty($location_file) === false + && strpos($location_file, realpath('attachment/plugin')) !== false + && file_exists($location_file) === true + ) { + $result = file_put_contents($location_file, $contentFile); + } } $id_plugin = (int) get_parameter('id_plugin', 0); diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 23a284caf9..1589f33fc9 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -115,7 +115,7 @@ foreach ($servers as $server) { $table->cellclass[] = [ 3 => 'progress_bar', - 8 => 'table_action_buttons', + 9 => 'table_action_buttons', ]; $data[0] = ''.strip_tags($server['name']).''; diff --git a/pandora_console/godmode/setup/os.builder.php b/pandora_console/godmode/setup/os.builder.php index 6313aa3edd..4f7b77099b 100644 --- a/pandora_console/godmode/setup/os.builder.php +++ b/pandora_console/godmode/setup/os.builder.php @@ -48,7 +48,7 @@ if ($idOS > 0) { } else { $name = io_safe_input(strip_tags(trim(io_safe_output((string) get_parameter('name'))))); $description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description')))); - $icon = get_parameter('icon', 0); + $icon = get_parameter('icon', 'os@svg.svg'); } $icon_upload = get_parameter('icon_upload', null); @@ -246,7 +246,7 @@ $iconData[] = html_print_select( 'icon', $icon, 'show_icon_OS();', - __('None'), + '', 0, true ); @@ -356,6 +356,8 @@ function get_list_os_icons_dir() } } + $return['os@svg.svg'] = __('None'); + return $return; } diff --git a/pandora_console/godmode/setup/os.php b/pandora_console/godmode/setup/os.php index dcfe95ecdb..403232c868 100644 --- a/pandora_console/godmode/setup/os.php +++ b/pandora_console/godmode/setup/os.php @@ -88,6 +88,14 @@ switch ($tab) { break; case 'manage_os': + $id_os = get_parameter('id_os', ''); + if ($id_os !== '') { + $headerTitle = __('Edit OS'); + } else { + $headerTitle = __('Create OS'); + } + break; + case 'list': if ($action === 'edit') { $headerTitle = __('Edit OS'); diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 46a91e27c6..3366fcc6f8 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -960,60 +960,6 @@ echo ''.__('Mail configuration').''; ); echo ''; - - - /** - * Print the modal window for the summary of each alerts group - * - * @param string $id Id. - * - * @return void - */ - function print_email_test_modal_window($id) - { - // Email config table. - $table_mail_test = new stdClass(); - $table_mail_test->width = '100%'; - $table_mail_test->class = 'filter-table-adv'; - $table_mail_test->data = []; - - $table_mail_test->data[0][] = html_print_label_input_block( - __('Address'), - html_print_input_text( - 'email_test_address', - '', - '', - 35, - 100, - true - ) - ); - - $table_mail_test->data[1][] = '  Email could not be sent'; - - // $table_mail_test->colspan[2][0] = 2; - $submitButton = html_print_div( - [ - 'class' => 'action-buttons-right-forced', - 'content' => html_print_button( - __('Send'), - 'email_test', - false, - '', - [ - 'icon' => 'cog', - 'mode' => 'mini', - ], - true - ), - ], - true - ); - - echo ''; - } - - ?>