diff --git a/extras/deploy-scripts/deploy_ext_database_el8.sh b/extras/deploy-scripts/deploy_ext_database_el8.sh index 422887b0e2..52bad444fe 100644 --- a/extras/deploy-scripts/deploy_ext_database_el8.sh +++ b/extras/deploy-scripts/deploy_ext_database_el8.sh @@ -9,7 +9,7 @@ # RedHat 8.5 #Constants -S_VERSION='202302081' +S_VERSION='202302201' LOGFILE="/tmp/deploy-ext-db-$(date +%F).log" @@ -275,6 +275,8 @@ EO_CONFIG_F if [ "$MYVER" -eq '80' ] ; then sed -i -e "/query_cache.*/ s/^#*/#/g" /etc/my.cnf sed -i -e "s/#skip-log-bin/skip-log-bin/g" /etc/my.cnf + sed -i -e "s/character-set-server=utf8/character-set-server=utf8mb4/g" /etc/my.cnf + fi execute_cmd "systemctl restart mysqld" "Configuring database engine" diff --git a/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh b/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh index a82244c3b6..45a99783ab 100644 --- a/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh +++ b/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh @@ -4,6 +4,7 @@ ############################################################################################################## ## Tested versions ## # Ubuntu 22.04.1 +# Ubuntu 22.04.2 #avoid promps export DEBIAN_FRONTEND=noninteractive @@ -16,7 +17,7 @@ PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf WORKDIR=/opt/pandora/deploy -S_VERSION='202302081' +S_VERSION='202302201' LOGFILE="/tmp/deploy-ext-db-$(date +%F).log" rm -f $LOGFILE &> /dev/null # remove last log before start @@ -181,7 +182,7 @@ cat > /etc/mysql/my.cnf << EOF_DB [mysqld] datadir=/var/lib/mysql user=mysql -character-set-server=utf8 +character-set-server=utf8mb4 skip-character-set-client-handshake # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 @@ -196,7 +197,7 @@ innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_log_file_size = 64M innodb_log_buffer_size = 16M -innodb_io_capacity = 100 +innodb_io_capacity = 300 thread_cache_size = 8 thread_stack = 256K max_connections = 100 diff --git a/extras/deploy-scripts/pandora_deploy_community.sh b/extras/deploy-scripts/pandora_deploy_community.sh index 78f1ef0e41..9386d55647 100644 --- a/extras/deploy-scripts/pandora_deploy_community.sh +++ b/extras/deploy-scripts/pandora_deploy_community.sh @@ -431,7 +431,7 @@ execute_cmd "curl -LSs --output pandorafms_agent_linux-7.0NG.noarch.rpm ${PANDOR execute_cmd "yum install -y $HOME/pandora_deploy_tmp/pandorafms*.rpm" "installing PandoraFMS packages" # Copy gotty utility -execute_cmd "wget https://pandorafms.com/library/wp-content/uploads/2019/11/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' +execute_cmd "wget https://firefly.pandorafms.com/pandorafms/utils/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' tar xvzf gotty_linux_amd64.tar.gz &>> $LOGFILE execute_cmd "mv gotty /usr/bin/" 'Installing gotty util' diff --git a/extras/deploy-scripts/pandora_deploy_community_el8.sh b/extras/deploy-scripts/pandora_deploy_community_el8.sh index 13f90fcf85..cc14ad1ffa 100644 --- a/extras/deploy-scripts/pandora_deploy_community_el8.sh +++ b/extras/deploy-scripts/pandora_deploy_community_el8.sh @@ -5,7 +5,7 @@ ## Tested versions ## # Centos 8.4, 8.5 # Rocky 8.4, 8.5, 8.6, 8.7 -# Almalinuz 8.4, 8.5 +# Almalinux 8.4, 8.5 # RedHat 8.5 #Constants @@ -14,7 +14,7 @@ PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='202301251' +S_VERSION='202302201' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables @@ -107,6 +107,17 @@ check_root_permissions () { fi } +installing_docker () { + #Installing docker for debug + echo "Start installig docker" &>> "$LOGFILE" + dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &>> "$LOGFILE" + dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &>> "$LOGFILE" + systemctl disable --now docker &>> "$LOGFILE" + systemctl disable docker.socket --now &>> "$LOGFILE" + echo "End installig docker" &>> "$LOGFILE" +} + + ## Main echo "Starting PandoraFMS Community deployment EL8 ver. $S_VERSION" @@ -207,6 +218,7 @@ else execute_cmd "dnf config-manager --set-enabled powertools" "Configuring Powertools" fi +execute_cmd "installing_docker" "Installing Docker for debug" #Installing wget execute_cmd "dnf install -y wget" "Installing wget" @@ -454,7 +466,7 @@ innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_log_file_size = 64M innodb_log_buffer_size = 16M -innodb_io_capacity = 100 +innodb_io_capacity = 300 thread_cache_size = 8 thread_stack = 256K max_connections = 100 @@ -483,6 +495,7 @@ EO_CONFIG_F if [ "$MYVER" -eq '80' ] ; then sed -i -e "/query_cache.*/ s/^#*/#/g" /etc/my.cnf sed -i -e "s/#skip-log-bin/skip-log-bin/g" /etc/my.cnf + sed -i -e "s/character-set-server=utf8/character-set-server=utf8mb4/g" /etc/my.cnf fi execute_cmd "systemctl restart mysqld" "Configuring database engine" @@ -517,7 +530,7 @@ execute_cmd "curl -LSs --output pandorafms_agent_linux-7.0NG.noarch.rpm ${PANDOR execute_cmd "dnf install -y $HOME/pandora_deploy_tmp/pandorafms*.rpm" "Installing Pandora FMS packages" # Copy gotty utility -execute_cmd "wget https://pandorafms.com/library/wp-content/uploads/2019/11/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' +execute_cmd "wget https://firefly.pandorafms.com/pandorafms/utils/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' tar xvzf gotty_linux_amd64.tar.gz &>> $LOGFILE execute_cmd "mv gotty /usr/bin/" 'Installing gotty util' @@ -743,7 +756,7 @@ execute_cmd "systemctl start pandora_agent_daemon" "Starting Pandora FMS Agent" cat > /etc/issue.net << EOF_banner -Welcome to Pandora FMS appliance on CentOS +Welcome to Pandora FMS appliance on RHEL/Rocky Linux 8 ------------------------------------------ Go to Public http://$ipplublic/pandora_console$to to login web console $(ip addr | grep -w "inet" | grep -v "127.0.0.1" | grep -v "172.17.0.1" | awk '{print $2}' | awk -F '/' '{print "Go to Local http://"$1"/pandora_console to login web console"}') diff --git a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh index b22d5d163f..1446abfab3 100644 --- a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh +++ b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh @@ -4,6 +4,7 @@ ############################################################################################################## ## Tested versions ## # Ubuntu 22.04.1 +# Ubuntu 22.04.2 #avoid promps export DEBIAN_FRONTEND=noninteractive @@ -16,7 +17,7 @@ PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf WORKDIR=/opt/pandora/deploy -S_VERSION='202301251' +S_VERSION='202302201' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" rm -f $LOGFILE &> /dev/null # remove last log before start @@ -106,6 +107,21 @@ check_root_permissions () { fi } +installing_docker () { + #Installing docker for debug + echo "Start installig docker" &>> "$LOGFILE" + mkdir -m 0755 -p /etc/apt/keyrings &>> "$LOGFILE" + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --yes --dearmor -o /etc/apt/keyrings/docker.gpg &>> "$LOGFILE" + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list &>> "$LOGFILE" + apt update -y &>> "$LOGFILE" + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &>> "$LOGFILE" + systemctl disable docker --now &>> "$LOGFILE" + systemctl disable docker.socket --now &>> "$LOGFILE" + echo "End installig docker" &>> "$LOGFILE" +} + ## Main echo "Starting PandoraFMS Community deployment Ubuntu 22.04 ver. $S_VERSION" @@ -173,7 +189,7 @@ execute_cmd "cd $WORKDIR" "Moving to workdir: $WORKDIR" ## Install utils execute_cmd "apt update" "Updating repos" -execute_cmd "apt install -y net-tools vim curl wget software-properties-common apt-transport-https" "Installing utils" +execute_cmd "apt install -y net-tools vim curl wget software-properties-common apt-transport-https ca-certificates gnupg lsb-release" "Installing utils" #Installing Apache and php-fpm [ -e "/etc/apt/sources.list.d/ondrej-ubuntu-php-jammy.list" ] || execute_cmd "add-apt-repository ppa:ondrej/php -y" "Enable ppa:ondrej/php repo" @@ -221,7 +237,8 @@ systemctl restart php$PHPVER-fpm &>> "$LOGFILE" php$PHPVER-xml \ php$PHPVER-yaml \ libnet-telnet-perl \ - whois" + whois \ + cron" execute_cmd "apt install -y $console_dependencies" "Installing Pandora FMS Console dependencies" # Server dependencies @@ -254,10 +271,13 @@ server_dependencies=" \ libnet-telnet-perl \ libjson-perl \ libencode-perl \ + cron \ libgeo-ip-perl \ openjdk-8-jdk " execute_cmd "apt install -y $server_dependencies" "Installing Pandora FMS Server dependencies" +execute_cmd "installing_docker" "Installing Docker for debug" + # wmic and pandorawmic execute_cmd "curl -O https://firefly.artica.es/pandorafms/utils/bin/wmic" "Downloading wmic" execute_cmd "curl -O https://firefly.artica.es/pandorafms/utils/bin/pandorawmic" "Downloading pandorawmic" @@ -393,7 +413,7 @@ cat > /etc/mysql/my.cnf << EOF_DB [mysqld] datadir=/var/lib/mysql user=mysql -character-set-server=utf8 +character-set-server=utf8mb4 skip-character-set-client-handshake # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 @@ -408,7 +428,7 @@ innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_log_file_size = 64M innodb_log_buffer_size = 16M -innodb_io_capacity = 100 +innodb_io_capacity = 300 thread_cache_size = 8 thread_stack = 256K max_connections = 100 @@ -477,7 +497,7 @@ check_cmd_status "Error installing PandoraFMS Agent" # Copy gotty utility cd $WORKDIR &>> "$LOGFILE" -execute_cmd "wget https://pandorafms.com/library/wp-content/uploads/2019/11/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' +execute_cmd "wget https://firefly.pandorafms.com/pandorafms/utils/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' tar xvzf gotty_linux_amd64.tar.gz &>> $LOGFILE execute_cmd "mv gotty /usr/bin/" 'Installing gotty util' @@ -731,10 +751,15 @@ systemctl enable pandora_server &>> "$LOGFILE" execute_cmd "service tentacle_serverd start" "Starting Tentacle Server" systemctl enable tentacle_serverd &>> "$LOGFILE" -# Enabling condole cron +# Enabling console cron execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" echo "* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab +# Enabling pandoradb cron +execute_cmd "echo 'enabling pandoradb cron' >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS pandoradb cron" +echo "@hourly root bash -c /etc/cron.hourly/pandora_db" >> /etc/crontab + + ## Enabling agent adn configuring Agente sed -i "s/^remote_config.*$/remote_config 1/g" $PANDORA_AGENT_CONF &>> "$LOGFILE" execute_cmd "/etc/init.d/pandora_agent_daemon start" "Starting PandoraFSM Agent" @@ -748,7 +773,7 @@ sed --follow-symlinks -i -e "s/^openssl_conf = openssl_init/#openssl_conf = open cat > /etc/issue.net << EOF_banner -Welcome to Pandora FMS appliance on CentOS +Welcome to Pandora FMS appliance on Ubuntu ------------------------------------------ Go to Public http://$ipplublic/pandora_console$to to login web console $(ip addr | grep -w "inet" | grep -v "127.0.0.1" | grep -v "172.17.0.1" | awk '{print $2}' | awk -F '/' '{print "Go to Local http://"$1"/pandora_console to login web console"}') diff --git a/pandora_agents/pc/pandora_agent.redhat.spec b/pandora_agents/pc/pandora_agent.redhat.spec index ae481e3403..ce60c8841f 100644 --- a/pandora_agents/pc/pandora_agent.redhat.spec +++ b/pandora_agents/pc/pandora_agent.redhat.spec @@ -1,6 +1,7 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 4.0 %define release 1 diff --git a/pandora_agents/pc/pandora_agent.spec b/pandora_agents/pc/pandora_agent.spec index 1bfc289d52..5ad481315a 100644 --- a/pandora_agents/pc/pandora_agent.spec +++ b/pandora_agents/pc/pandora_agent.spec @@ -1,6 +1,7 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 4.0.1 %define release 1 diff --git a/pandora_agents/shellscript/linux/pandora_agent.spec b/pandora_agents/shellscript/linux/pandora_agent.spec index 64b33bfecf..9c5e0296c6 100755 --- a/pandora_agents/shellscript/linux/pandora_agent.spec +++ b/pandora_agents/shellscript/linux/pandora_agent.spec @@ -1,6 +1,7 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent %define version 3.2 Summary: Pandora FMS Linux agent diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 5f29343d22..7a6aeff356 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.769-230217 +Version: 7.0NG.769-230303 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 07e42a8119..fa61aa49c9 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.769-230217" +pandora_version="7.0NG.769-230303" 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 33f9b75177..0a12df1c9f 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1023,7 +1023,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.769'; -use constant AGENT_BUILD => '230217'; +use constant AGENT_BUILD => '230303'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index fa965af096..89ea2a0b9f 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -1,9 +1,10 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 7.0NG.769 -%define release 230217 +%define release 230303 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index f1091e07d9..aed2381793 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -1,9 +1,10 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 7.0NG.769 -%define release 230217 +%define release 230303 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 0955293f59..c63a4a6cfc 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.769" -PI_BUILD="230217" +PI_BUILD="230303" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 9d180788d6..2c51bc2a4b 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{230217} +{230303} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index b6a69e5783..acf6b701e5 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.769 Build 230217") +#define PANDORA_VERSION ("7.0NG.769 Build 230303") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 61bf76a879..c6e79f7d24 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.769(Build 230217))" + VALUE "ProductVersion", "(7.0NG.769(Build 230303))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 7eaf7524ea..57d645e9b5 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.769-230217 +Version: 7.0NG.769-230303 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 d6e24860e3..f701f80ec0 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.769-230217" +pandora_version="7.0NG.769-230303" package_pear=0 package_pandora=1 diff --git a/pandora_console/extensions/dbmanager.php b/pandora_console/extensions/dbmanager.php index db92dda0a9..3f36935e5c 100644 --- a/pandora_console/extensions/dbmanager.php +++ b/pandora_console/extensions/dbmanager.php @@ -227,7 +227,7 @@ function dbmgr_extension_main() 'dbport' => $node->dbport(), 'dbname' => $node->dbname(), 'dbuser' => $node->dbuser(), - 'dbpass' => $node->dbpass(), + 'dbpass' => io_output_password($node->dbpass()), ] ); $error = ''; diff --git a/pandora_console/extras/mr/62.sql b/pandora_console/extras/mr/62.sql index 14baa793af..e8f0cc2810 100644 --- a/pandora_console/extras/mr/62.sql +++ b/pandora_console/extras/mr/62.sql @@ -14,4 +14,31 @@ CREATE TABLE IF NOT EXISTS `tconsole` ( ALTER TABLE `tuser_task_scheduled` ADD COLUMN `id_console` BIGINT NOT NULL DEFAULT 0; +CREATE TABLE IF NOT EXISTS `tagent_filter` ( + `id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `id_name` VARCHAR(600) NOT NULL, + `id_group_filter` INT NOT NULL DEFAULT 0, + `group_id` INT NOT NULL DEFAULT 0, + `recursion` TEXT, + `status` INT NOT NULL DEFAULT -1, + `search` TEXT, + `id_os` INT NOT NULL DEFAULT 0, + `policies` TEXT, + `search_custom` TEXT, + `ag_custom_fields` TEXT, + PRIMARY KEY (`id_filter`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +CREATE TABLE `tevent_sound` ( + `id` INT NOT NULL AUTO_INCREMENT, + `name` TEXT NULL, + `sound` TEXT NULL, + `active` TINYINT NOT NULL DEFAULT '1', +PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE INDEX agente_modulo_estado ON tevento (estado, id_agentmodule); +CREATE INDEX idx_disabled ON talert_template_modules (disabled); + +INSERT INTO `treport_custom_sql` (`name`, `sql`) VALUES ('Agent safe mode not enable', 'select alias from tagente where safe_mode_module = 0'); + COMMIT; diff --git a/pandora_console/general/login_page.php b/pandora_console/general/login_page.php index bb9fa19185..cd45f34f48 100755 --- a/pandora_console/general/login_page.php +++ b/pandora_console/general/login_page.php @@ -359,6 +359,10 @@ if ($config['enterprise_installed']) { } // CSRF validation. +if (isset($_SESSION['csrf_code']) === true) { + unset($_SESSION['csrf_code']); +} + html_print_csrf_hidden(); echo ''; diff --git a/pandora_console/godmode/agentes/module_manager_editor_plugin.php b/pandora_console/godmode/agentes/module_manager_editor_plugin.php index 2cc0ec3d8e..9477091e95 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_plugin.php +++ b/pandora_console/godmode/agentes/module_manager_editor_plugin.php @@ -89,8 +89,7 @@ $password_fields = []; // If there are $macros, we create the form fields if (!empty($macros)) { - $macros = json_decode($macros, true); - + $macros = json_decode(io_safe_output($macros), true); foreach ($macros as $k => $m) { $data = []; $data[0] = $m['desc']; diff --git a/pandora_console/godmode/alerts/alert_actions.php b/pandora_console/godmode/alerts/alert_actions.php index 873d91598c..2089dc5900 100644 --- a/pandora_console/godmode/alerts/alert_actions.php +++ b/pandora_console/godmode/alerts/alert_actions.php @@ -391,7 +391,7 @@ foreach ($actions as $action) { $data = []; - $data[0] = ''.$action['name'].''; + $data[0] = ''.$action['name'].''; if ($action['id_group'] == 0 && $can_edit_all == false) { $data[0] .= ui_print_help_tip(__('You cannot edit this action, You don\'t have the permission to edit All group.'), true); } @@ -467,7 +467,7 @@ if (isset($data)) { if (is_management_allowed() === true) { echo '
'; - echo '
'; + echo ''; html_print_submit_button(__('Create'), 'create', false, 'class="sub next"'); html_print_input_hidden('create_alert', 1); echo '
'; diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index 24d07a392f..2090461050 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -795,15 +795,15 @@ foreach ($commands as $command) { ); $data['action'] = ''; $table->cellclass[]['action'] = 'action_buttons'; - + $offset_delete = ($offset >= ($total_commands - 1)) ? ($offset - $limit) : $offset; // (IMPORTANT, DO NOT CHANGE!) only users with permissions over "All" group have access to edition of commands belonging to "All" group. if ($is_management_allowed === true && !$command['internal'] && check_acl_restricted_all($config['id_user'], $command['id_group'], 'LM')) { if (is_user_admin($config['id_user']) === true) { $data['action'] = ''; - $data['action'] .= ''.html_print_image('images/copy.png', true, ['class' => 'invert_filter']).''; - $data['action'] .= ''.html_print_image('images/cross.png', true, ['class' => 'invert_filter']).''; $data['action'] .= ''; } diff --git a/pandora_console/godmode/alerts/alert_templates.php b/pandora_console/godmode/alerts/alert_templates.php index c0374c210b..cd49f7ee7c 100644 --- a/pandora_console/godmode/alerts/alert_templates.php +++ b/pandora_console/godmode/alerts/alert_templates.php @@ -352,7 +352,8 @@ if ($search_string) { $filter[] = "(name LIKE '%".$search_string."%' OR description LIKE '%".$search_string."%' OR value LIKE '%".$search_string."%')"; } -$filter['offset'] = (int) get_parameter('offset'); +$offset = (int) get_parameter('offset'); +$filter['offset'] = $offset; $filter['limit'] = (int) $config['block_size']; if (!is_user_admin($config['id_user'])) { $filter['id_group'] = array_keys(users_get_groups(false, 'LM')); @@ -420,7 +421,7 @@ foreach ($templates as $template) { && check_acl($config['id_user'], $template['id_group'], 'LM') ) { $table->cellclass[][4] = 'action_buttons'; - $data[4] = '
'; + $data[4] = ''; $data[4] .= html_print_input_hidden('duplicate_template', 1, true); $data[4] .= html_print_input_hidden('source_id', $template['id'], true); $data[4] .= html_print_input_image( diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 068026c953..240fa26fc3 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -372,8 +372,9 @@ for ($i = 1; $i <= $config['max_macro_fields']; $i++) { ); } +$offset = (int) get_parameter('offset', 0); -echo ''; +echo ''; $table_html = html_print_table($table, true); echo $table_html; diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index 8838c5c458..0269d94573 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -1147,9 +1147,10 @@ if ($step == 2) { echo ui_get_using_system_timezone_warning(); } +$offset = (int) get_parameter('offset'); // If it's the last step it will redirect to template lists. if ($step >= LAST_STEP) { - echo ''; + echo ''; } else { echo ''; } diff --git a/pandora_console/godmode/events/configuration_sounds.php b/pandora_console/godmode/events/configuration_sounds.php new file mode 100644 index 0000000000..d4e9d77688 --- /dev/null +++ b/pandora_console/godmode/events/configuration_sounds.php @@ -0,0 +1,71 @@ + '[EventSound]'.$e->getMessage() ]); + exit; + } else { + echo '[EventSound]'.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// AJAX controller. +if ((bool) is_ajax() === true) { + $method = get_parameter('method'); + + if (method_exists($controller, $method) === true) { + if ($controller->ajaxMethod($method) === true) { + $controller->{$method}(); + } else { + $controller->error('Unavailable method.'); + } + } else { + $controller->error('Method not found. ['.$method.']'); + } + + // Stop any execution. + exit; +} else { + // Run. + $controller->run(); +} diff --git a/pandora_console/godmode/groups/configure_modu_group.php b/pandora_console/godmode/groups/configure_modu_group.php index 9330aa1320..282bd81d18 100644 --- a/pandora_console/godmode/groups/configure_modu_group.php +++ b/pandora_console/godmode/groups/configure_modu_group.php @@ -40,6 +40,7 @@ $custom_id = ''; $create_group = (bool) get_parameter('create_group'); $id_group = (int) get_parameter('id_group'); +$offset = (int) get_parameter('offset', 0); if ($id_group) { $group = db_get_row('tmodule_group', 'id_mg', $id_group); @@ -70,9 +71,9 @@ $table->data[0][1] = html_print_input_text('name', $name, '', 35, 100, true); echo ''; if (is_metaconsole()) { - echo ''; + echo ''; } else { - echo ''; + echo ''; } html_print_table($table); diff --git a/pandora_console/godmode/groups/modu_group_list.php b/pandora_console/godmode/groups/modu_group_list.php index 84dc35ada8..ea74c92cf5 100644 --- a/pandora_console/godmode/groups/modu_group_list.php +++ b/pandora_console/godmode/groups/modu_group_list.php @@ -262,18 +262,18 @@ if (empty($groups) === false) { } $table->data = []; - + $offset_delete = ($offset >= $total_groups - 1) ? ($offset - $config['block_size']) : $offset; foreach ($groups as $id_group) { $data = []; $data[0] = $id_group['id_mg']; if ($is_management_allowed === true) { - $data[1] = ''.ui_print_truncate_text($id_group['name'], GENERIC_SIZE_TEXT).''; + $data[1] = ''.ui_print_truncate_text($id_group['name'], GENERIC_SIZE_TEXT).''; if (is_metaconsole() === true) { - $data[2] = ''.html_print_image('images/cross.png', true, ['border' => '0']).''; + $data[2] = ''.html_print_image('images/cross.png', true, ['border' => '0']).''; } else { $table->cellclass[][2] = 'action_buttons'; - $data[2] = ''.html_print_image('images/cross.png', true, ['border' => '0']).''; + $data[2] = ''.html_print_image('images/cross.png', true, ['border' => '0']).''; } } else { $data[1] = ''; diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 85a0006986..a03e278957 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -2094,46 +2094,21 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' switch ($field) { case 'id_plugin': if ($value != 0) { - $value_field_1 = get_parameter('_field1_', ''); - $value_field_1_desc = get_parameter('desc_field1_', ''); - - $value_field_2 = get_parameter('_field2_', ''); - $value_field_2_desc = get_parameter('desc_field2_', ''); - - $value_field_3 = get_parameter('_field3_', ''); - $value_field_3_desc = get_parameter('desc_field3_', ''); - - $value_field_4 = get_parameter('_field4_', ''); - $value_field_4_desc = get_parameter('desc_field4_', ''); - - $value_field_5 = get_parameter('_field5_', ''); - $value_field_5_desc = get_parameter('desc_field5_', ''); - - $values['macros'] = '{"1":{"macro":"_field1_","desc":"'.io_safe_input($value_field_1_desc).'","help":"'.io_safe_input($value_field_1_desc).'","value":"'.$value_field_1.'"}'; - - if ($value_field_2_desc != '') { - $values['macros'] .= ',"2":{"macro":"_field2_","desc":"'.io_safe_input($value_field_2_desc).'","help":"'.io_safe_input($value_field_2_desc).'","value":"'.$value_field_2.'"}'; - - if ($value_field_3_desc != '') { - $values['macros'] .= ',"3":{"macro":"_field3_","desc":"'.io_safe_input($value_field_3_desc).'","help":"'.io_safe_input($value_field_3_desc).'","value":"'.$value_field_3.'"}'; - - if ($value_field_4_desc != '') { - $values['macros'] .= ',"4":{"macro":"_field4_","desc":"'.io_safe_input($value_field_4_desc).'","help":"'.io_safe_input($value_field_4_desc).'","value":"'.$value_field_4.'"}'; - - if ($value_field_5_desc != '') { - $values['macros'] .= ',"5":{"macro":"_field5_","desc":"'.io_safe_input($value_field_5_desc).'","help":"'.io_safe_input($value_field_5_desc).'","value":"'.$value_field_5.'"}'; - } else { - $values['macros'] .= '}'; - } - } else { - $values['macros'] .= '}'; - } - } else { - $values['macros'] .= '}'; + for ($i = 0; $i <= 15; $i++) { + $value_field = get_parameter('_field'.$i.'_', ''); + $value_field_desc = get_parameter('desc_field'.$i.'_', ''); + if ($value_field_desc != '') { + $values['macros'][$i] = [ + 'macro' => '_field'.$i.'_', + 'desc' => io_safe_input($value_field_desc), + 'help' => io_safe_input($value_field_desc), + 'value' => $value_field, + ]; } - } else { - $values['macros'] .= '}'; } + + $values['macros'] = json_encode($values['macros']); + $values[$field] = $value; } break; @@ -2260,7 +2235,7 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' // Apply at All agents (within valid groups). $modules = db_get_all_rows_sql( sprintf( - 'SELECT tam.id_agente_modulo, tam.id_tipo_modulo + 'SELECT tam.id_agente_modulo, tam.id_tipo_modulo,tam.macros, tam.id_plugin FROM tagente_modulo tam INNER JOIN tagente ta ON ta.id_agente = tam.id_agente WHERE ta.id_grupo IN (%s) %s;', @@ -2277,6 +2252,8 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' [ 'id_agente_modulo', 'id_tipo_modulo', + 'macros', + 'id_plugin', ] ); } else { @@ -2289,6 +2266,8 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' [ 'id_agente_modulo', 'id_tipo_modulo', + 'macros', + 'id_plugin', ] ); } @@ -2346,6 +2325,23 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' } } + if ($module['macros'] && $module['id_plugin'] == $values['id_plugin']) { + $module_macros = json_decode($module['macros'], true); + $values_macros = json_decode($values['macros'], true); + + foreach ($values_macros as $k => $value_macro) { + foreach ($module_macros as $s => $module_macro) { + if ($value_macro['macro'] == $module_macro['macro'] && $value_macro['value'] !== '') { + $module_macros[$s]['value'] = $value_macro['value']; + $module_macros[$s]['desc'] = $value_macro['desc']; + $module_macros[$s]['help'] = $value_macro['help']; + } + } + } + + $values['macros'] = json_encode($module_macros); + } + $result = modules_update_agent_module( $module['id_agente_modulo'], $values, diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 9a9d11c02e..78d75a983c 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -442,6 +442,10 @@ if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) check_acl($ } } + $sub['godmode/events/configuration_sounds']['text'] = __('Accoustic console setup'); + $sub['godmode/events/configuration_sounds']['id'] = 'Accoustic console setup'; + $sub['godmode/events/configuration_sounds']['pages'] = ['godmode/events/configuration_sounds']; + $menu_godmode['gextensions']['sub'] = $sub; } diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index bdec795443..8a27800ec2 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -597,9 +597,10 @@ if ((bool) $id !== false || $new_component $search_id_group = (int) get_parameter('search_id_group'); $search_string = (string) get_parameter('search_string'); +$offset = (int) get_parameter('offset'); $url = ui_get_url_refresh( [ - 'offset' => false, + 'offset' => $offset, 'search_string' => $search_string, 'search_id_group' => $search_id_group, 'id' => $id, @@ -607,7 +608,7 @@ $url = ui_get_url_refresh( true, false ); - +$name_url = 'index.php?sec=templates&sec2=godmode/modules/manage_network_components'; $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; @@ -712,8 +713,9 @@ $total_components = network_components_get_network_components( 'COUNT(*) AS total' ); $total_components = $total_components[0]['total']; -ui_pagination($total_components, $url); -$filter['offset'] = (int) get_parameter('offset'); +$offset_delete = ($offset >= ($total_components - 1)) ? ($offset - $config['block_size']) : $offset; +ui_pagination($total_components, $name_url); +$filter['offset'] = $offset; $filter['limit'] = (int) $config['block_size']; $components = network_components_get_network_components( false, @@ -791,7 +793,7 @@ foreach ($components as $component) { true ); - $data[0] = ''; + $data[0] = ''; $data[0] .= io_safe_output($component['name']); $data[0] .= ''; } else { @@ -855,7 +857,7 @@ foreach ($components as $component) { if ($is_management_allowed === true) { $table->cellclass[][6] = 'action_buttons'; - $data[6] = ''.html_print_image( + $data[6] = ''.html_print_image( 'images/copy.png', true, [ @@ -864,7 +866,7 @@ foreach ($components as $component) { 'class' => 'invert_filter', ] ).''; - $data[6] .= ''.html_print_image( + $data[6] .= ''.html_print_image( 'images/cross.png', true, [ @@ -887,7 +889,7 @@ if (isset($data) === true) { html_print_table($table); ui_pagination( $total_components, - $url, + $name_url, 0, 0, false, diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 80e72e65cf..c6650d08fe 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -281,7 +281,7 @@ switch ($action) { $server_name = $item['server_name']; // Metaconsole db connection. - if ($meta && empty($server_name) === false) { + if ($meta && empty($server_name) === false && $server_name !== 'all') { $connection = metaconsole_get_connection($server_name); $server_id = $connection['id']; if (metaconsole_load_external_db($connection) != NOERR) { @@ -1233,6 +1233,29 @@ $class = 'databox filters'; } ?> + 'All nodes'], $servers); + if ($meta) { + ?> + + + + + + + + @@ -6334,6 +6357,7 @@ function chooseType() { $("#row_alert_templates").hide(); $("#row_alert_actions").hide(); $("#row_servers").hide(); + $("#row_servers_all_opt").hide(); $("#row_multiple_servers").hide(); $("#row_sort").hide(); $("#row_date").hide(); @@ -6648,7 +6672,7 @@ function chooseType() { $("#row_header").show(); $("#row_custom").show(); $("#row_custom_example").show(); - $("#row_servers").show(); + $("#row_servers_all_opt").show(); $("#row_historical_db_check").show(); break; diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 94ab20aebf..7b0a34efa7 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -992,7 +992,7 @@ if (($create != '') || ($view != '')) { echo ''; + ?> + + + '; + if (check_acl($config['id_user'], 0, 'AW')) { + echo '
'; + + $table = new StdClass; + $table->id = 'save_filter_form'; + $table->width = '100%'; + $table->cellspacing = 4; + $table->cellpadding = 4; + $table->class = 'databox'; + + if (is_metaconsole() === true) { + $table->class = 'databox filters'; + $table->cellspacing = 0; + $table->cellpadding = 0; + } + + $table->styleTable = 'font-weight: bold; text-align:left;'; + + if (is_metaconsole() === true) { + $table->style[0] = 'width: 50%; width:50%;'; + } + + $data = []; + $table->rowid[0] = 'update_save_selector'; + $data[0] = html_print_radio_button( + 'filter_mode', + 'new', + '', + true, + true + ).__('New filter').''; + + $data[1] = html_print_radio_button( + 'filter_mode', + 'update', + '', + false, + true + ).__('Update/delete filter').''; + + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = []; + $table->rowid[1] = 'save_filter_row1'; + $data[0] = __('Filter name').$jump; + $data[0] .= html_print_input_text('id_name', '', '', 15, 255, true); + + if (is_metaconsole() === true) { + $data[1] = __('Save in Group').$jump; + } else { + $data[1] = __('Filter group').$jump; + } + + $user_groups_array = users_get_groups_for_select( + $config['id_user'], + 'AW', + users_can_manage_group_all('AW'), + true + ); + + $data[1] .= html_print_select( + $user_groups_array, + 'id_group_filter_dialog', + $id_group_filter, + '', + '', + 0, + true, + false, + false, + 'w130' + ); + + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = []; + $table->rowid[2] = 'save_filter_row2'; + + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = []; + $table->rowid[3] = 'update_filter_row1'; + $data[0] = __('Filter').$jump; + + $user_groups = users_get_groups( + $config['id_user'], + 'AW', + users_can_manage_group_all('AW'), + true + ); + + $sql = 'SELECT id_filter, id_name + FROM tagent_filter + WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')'; + + $agent_filters = db_get_all_rows_sql($sql); + + $_filters_update = []; + + if ($agent_filters !== false) { + foreach ($agent_filters as $agent_filter) { + $_filters_update[$agent_filter['id_filter']] = $agent_filter['id_name']; + } + } + + $data[0] .= html_print_select( + $_filters_update, + 'overwrite_filter', + '', + '', + '', + 0, + true + ); + + $table->data[] = $data; + $table->rowclass[] = ''; + + html_print_table($table); + echo '

'; + echo html_print_submit_button( + __('Update filter'), + 'update_filter', + false, + 'class="sub upd" onclick="save_update_filter();"', + true + ); + echo html_print_submit_button( + __('Delete filter'), + 'delete_filter', + false, + 'class="sub delete float-right" onclick="save_delete_filter();"', + true + ); + echo '
'; + echo '

'; + echo html_print_submit_button( + __('Save current filter'), + 'save_filter', + false, + 'class="sub upd float-right" onclick="save_new_filter();"', + true + ); + echo '
'; + } else { + include 'general/noaccess.php'; + } + + echo '
'; + ?> + + 'StarTrek emergency simulation', ]; + $eventsounds = mysql_db_get_all_rows_sql('SELECT * FROM tevent_sound WHERE active = 1'); + foreach ($eventsounds as $key => $row) { + $sounds[$row['sound']] = $row['name']; + } + $inputs[] = [ 'class' => 'test-sounds', 'direct' => 1, diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 3857c5d6b2..ec87996805 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -73,6 +73,7 @@ if (check_login()) { $get_monitor_filters = get_parameter('get_monitor_filters', 0); $save_monitor_filter = get_parameter('save_monitor_filter', 0); $update_monitor_filter = get_parameter('update_monitor_filter', 0); + $delete_monitor_filter = get_parameter('delete_monitor_filter', 0); if ($get_agent_modules_json_by_name === true) { $agent_name = get_parameter('agent_name'); @@ -1740,6 +1741,29 @@ if (check_login()) { } } + if ($delete_monitor_filter) { + $id = get_parameter('id'); + + $user_groups = users_get_groups( + $config['id_user'], + 'AW', + users_can_manage_group_all('AW'), + true + ); + + $sql = 'DELETE + FROM tmonitor_filter + WHERE id_filter = '.$id.' AND id_group_filter IN ('.implode(',', array_keys($user_groups)).')'; + + $monitor_filters = db_process_sql($sql); + + if ($monitor_filters === false) { + echo 'error'; + } else { + echo 'ok'; + } + } + if ($get_monitor_filters) { $sql = 'SELECT id_filter, id_name FROM tmonitor_filter'; @@ -1760,7 +1784,7 @@ if (check_login()) { $user_groups = users_get_groups( $config['id_user'], 'AR', - users_can_manage_group_all(), + users_can_manage_group_all('AR'), true ); @@ -1886,7 +1910,7 @@ if (check_login()) { '', false, true - ).__('Update filter').''; + ).__('Update/delete filter').''; $table->data[] = $data; $table->rowclass[] = ''; @@ -1904,7 +1928,7 @@ if (check_login()) { $user_groups_array = users_get_groups_for_select( $config['id_user'], 'AW', - users_can_manage_group_all(), + users_can_manage_group_all('AW'), true ); @@ -1954,21 +1978,30 @@ if (check_login()) { 0, true ); - $data[1] = html_print_submit_button( - __('Update filter'), - 'update_filter', - false, - 'class="sub upd" onclick="save_update_filter();"', - true - ); $table->data[] = $data; $table->rowclass[] = ''; html_print_table($table); - echo '
'; + echo '

'; echo html_print_submit_button( - __('Save filter'), + __('Update filter'), + 'update_filter', + false, + 'class="sub upd" onclick="save_update_filter();"', + true + ); + echo html_print_submit_button( + __('Delete filter'), + 'delete_filter', + false, + 'class="sub delete float-right" onclick="save_delete_filter();"', + true + ); + echo '
'; + echo '

'; + echo html_print_submit_button( + __('Save current filter'), 'save_filter', false, 'class="sub upd float-right" onclick="save_new_filter();"', @@ -1986,6 +2019,7 @@ if (check_login()) { $('#save_filter_row1').show(); $('#save_filter_row2').show(); $('#update_filter_row1').hide(); + $('#update_delete_row').hide(); // Filter save mode selector $("[name='filter_mode']").click(function() { if ($(this).val() == 'new') { @@ -1993,12 +2027,14 @@ if (check_login()) { $('#save_filter_row2').show(); $('#submit-save_filter').show(); $('#update_filter_row1').hide(); + $('#update_delete_row').hide(); } else { $('#save_filter_row1').hide(); $('#save_filter_row2').hide(); $('#update_filter_row1').show(); $('#submit-save_filter').hide(); + $('#update_delete_row').show(); } }); $("#save-filter-select").dialog({ @@ -2189,6 +2225,69 @@ if (check_login()) { $('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + name_filter_update); return false; } + + function save_delete_filter() { + var id_filter_update = $("#overwrite_filter").val(); + + jQuery.post ("", + { + "page" : "include/ajax/module", + "delete_monitor_filter" : 1, + "id" : $("#overwrite_filter").val(), + }, + function (data) { + $(".info_box").hide(); + if (data == 'ok') { + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "success_update_filter") { + return true; + } + else + return false; + }).show(); + } + else { + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "error_create_filter") { + return true; + } + else + return false; + }).show(); + } + }); + + // First remove all options of filters select. + $('#filter_id').find('option').remove().end(); + + // Add 'none' option. + $('#filter_id').append ($('').html ( ).attr ("value", 0)); + + // Reload filters select. + jQuery.post ("", + { + "page" : "include/ajax/module", + "get_monitor_filters" : 1 + }, + function (data) { + jQuery.each (data, function (i, val) { + s = js_html_entity_decode(val); + if (i == id_filter_update) { + $('#filter_id').append ($('').html (s).attr ("value", i)); + } + else { + $('#filter_id').append ($('').html (s).attr ("value", i)); + } + }); + }, + "json" + ); + + // Close dialog + $('.ui-dialog-titlebar-close').trigger('click'); + + return false; + } $(document).ready(function() { show_save_filter(); diff --git a/pandora_console/include/class/AuditLog.class.php b/pandora_console/include/class/AuditLog.class.php index 235652711c..4986cc399a 100644 --- a/pandora_console/include/class/AuditLog.class.php +++ b/pandora_console/include/class/AuditLog.class.php @@ -96,7 +96,10 @@ class AuditLog extends HTML // Datatables list. try { $columns = [ - 'id_usuario', + [ + 'text' => 'id_usuario', + 'class' => 'w50px', + ], 'accion', 'fecha', 'ip_origen', @@ -116,11 +119,11 @@ class AuditLog extends HTML $columns, [ 'text' => 'security', - 'class' => 'w80px action_buttons show_security_info', + 'class' => 'w50px action_buttons show_security_info', ], [ 'text' => 'action', - 'class' => 'w80px action_buttons show_extended_info', + 'class' => 'w50px action_buttons show_extended_info', ] ); @@ -199,16 +202,28 @@ class AuditLog extends HTML [ 'label' => __('Free search').ui_print_help_tip(__('Search filter by User, Action, Date, Source IP or Comments fields content'), true), 'type' => 'text', - 'class' => 'w200px', + 'class' => 'w150px', 'id' => 'filter_text', 'name' => 'filter_text', ], [ - 'label' => __('Max. hours old'), - 'type' => 'text', - 'class' => 'w100px', - 'id' => 'filter_period', - 'name' => 'filter_period', + 'label' => __('Max. hours old'), + 'type' => 'select', + 'class' => 'w20px', + 'select2_enable' => true, + 'sort' => false, + 'selected' => 168, + 'fields' => [ + 24 => __('1 day'), + 168 => __('7 days'), + 360 => __('15 days'), + 744 => __('1 month'), + 2160 => __('3 months'), + 4320 => __('6 months'), + 8760 => __('1 Year'), + ], + 'id' => 'filter_period', + 'name' => 'filter_period', ], [ 'label' => __('IP'), @@ -223,7 +238,7 @@ class AuditLog extends HTML 'nothing' => __('All'), 'nothing_value' => '-1', 'sql' => 'SELECT DISTINCT(accion), accion AS text FROM tsesion', - 'class' => 'mw250px', + 'class' => 'mw200px', 'id' => 'filter_type', 'name' => 'filter_type', ], @@ -235,7 +250,7 @@ class AuditLog extends HTML 'sql' => 'SELECT id_user, id_user AS text FROM tusuario UNION SELECT "SYSTEM" AS id_user, "SYSTEM" AS text UNION SELECT "N/A" AS id_user, "N/A" AS text', - 'class' => 'mw250px', + 'class' => 'mw200px', 'id' => 'filter_user', 'name' => 'filter_user', ], @@ -346,9 +361,12 @@ class AuditLog extends HTML ).ui_print_timestamp($tmp->utimestamp, true); if (enterprise_installed() === true) { - $tmp->security = enterprise_hook('cell1EntepriseAudit', [$tmp->id_sesion]); - $tmp->action = enterprise_hook('cell2EntepriseAudit', []); - $tmp->extendedInfo = enterprise_hook('rowEnterpriseAudit', [$tmp->id_sesion]); + $extendedInfo = enterprise_hook('rowEnterpriseAudit', [$tmp->id_sesion]); + if (empty($extendedInfo) === false) { + $tmp->security = enterprise_hook('cell1EntepriseAudit', [$tmp->id_sesion]); + $tmp->action = enterprise_hook('cell2EntepriseAudit', []); + $tmp->extendedInfo = $extendedInfo; + } } $carry[] = $tmp; diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index bfa8e2fd68..4e14a73048 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -248,6 +248,11 @@ class ConsoleSupervisor $this->checkAuditLogOldLocation(); + /* + * Check if performance variables are corrects + */ + $this->checkPerformanceVariables(); + /* * Checks if sync queue is longer than limits. * NOTIF.SYNCQUEUE.LENGTH @@ -258,14 +263,21 @@ class ConsoleSupervisor $this->checkSyncQueueStatus(); } - /* - * Checkc agent missing libraries. - * NOTIF.AGENT.LIBRARY - */ + /* + * Check number of agents is equals and more than 200. + * NOTIF.ACCESSSTASTICS.PERFORMANCE + */ + + $this->checkAccessStatisticsPerformance(); + + /* + * Checkc agent missing libraries. + * NOTIF.AGENT.LIBRARY + */ + if ((bool) enterprise_installed() === true) { $this->checkLibaryError(); } - } @@ -517,6 +529,11 @@ class ConsoleSupervisor $this->checkAuditLogOldLocation(); + /* + * Check if performance variables are corrects + */ + $this->checkPerformanceVariables(); + /* * Checks if sync queue is longer than limits. * NOTIF.SYNCQUEUE.LENGTH @@ -527,13 +544,107 @@ class ConsoleSupervisor $this->checkSyncQueueStatus(); } + /* + * Check number of agents is equals and more than 200. + * NOTIF.ACCESSSTASTICS.PERFORMANCE + */ + + $this->checkAccessStatisticsPerformance(); + /* * Checkc agent missing libraries. * NOTIF.AGENT.LIBRARY */ + if ((bool) enterprise_installed() === true) { $this->checkLibaryError(); } + + } + + + /** + * Check if performance variables are corrects + * + * @return void + */ + public function checkPerformanceVariables() + { + global $config; + + $names = [ + 'event_purge' => 'Max. days before events are deleted', + 'trap_purge' => 'Max. days before traps are deleted', + 'audit_purge' => 'Max. days before audited events are deleted', + 'string_purge' => 'Max. days before string data is deleted', + 'gis_purge' => 'Max. days before GIS data is deleted', + 'days_purge' => 'Max. days before purge', + 'days_compact' => 'Max. days before data is compacted', + 'days_delete_unknown' => 'Max. days before unknown modules are deleted', + 'days_delete_not_initialized' => 'Max. days before delete not initialized modules', + 'days_autodisable_deletion' => 'Max. days before autodisabled agents are deleted', + 'delete_old_network_matrix' => 'Max. days before delete old network matrix data', + 'report_limit' => 'Item limit for real-time reports', + 'event_view_hr' => 'Default hours for event view', + 'big_operation_step_datos_purge' => 'Big Operation Step to purge old data', + 'small_operation_step_datos_purge' => 'Small Operation Step to purge old data', + 'row_limit_csv' => 'Row limit in csv log', + 'limit_parameters_massive' => 'Limit for bulk operations', + 'block_size' => 'Block size for pagination', + 'short_module_graph_data' => 'Data precision', + 'graph_precision' => 'Data precision in graphs', + ]; + + $variables = (array) json_decode(io_safe_output($config['performance_variables_control'])); + + foreach ($variables as $variable => $values) { + if (empty($config[$variable]) === true || $config[$variable] === '') { + continue; + } + + $message = ''; + $limit_value = ''; + if ($config[$variable] > $values->max) { + $message = 'Check the setting of %s, a value greater than %s is not recommended'; + $limit_value = $values->max; + } + + if ($config[$variable] < $values->min) { + $message = 'Check the setting of %s, a value less than %s is not recommended'; + $limit_value = $values->min; + } + + if ($limit_value !== '' && $message !== '') { + if (is_metaconsole() === true) { + $this->notify( + [ + 'type' => 'NOTIF.VARIABLES.PERFORMANCE.'.$variable, + 'title' => __('Incorrect config value'), + 'message' => __( + $message, + $names[$variable], + $limit_value + ), + 'url' => '__url__index.php?sec=advanced&sec2=advanced/metasetup', + ] + ); + } else { + $this->notify( + [ + 'type' => 'NOTIF.VARIABLES.PERFORMANCE.'.$variable, + 'title' => __('Incorrect config value'), + 'message' => __( + $message, + $names[$variable], + $limit_value + ), + 'url' => '__url__/index.php?sec=general&sec2=godmode/setup/setup', + ] + ); + } + } + } + } @@ -548,6 +659,34 @@ class ConsoleSupervisor } + /** + * Check number of agents and disable agentaccess token if number + * is equals and more than 200. + * + * @return void + */ + public function checkAccessStatisticsPerformance() + { + $total_agents = db_get_value('count(*)', 'tagente'); + + if ($total_agents >= 200) { + db_process_sql_update('tconfig', ['value' => 0], ['token' => 'agentaccess']); + $this->notify( + [ + 'type' => 'NOTIF.ACCESSSTASTICS.PERFORMANCE', + 'title' => __('Access statistics performance'), + 'message' => __( + 'Usage of agent access statistics IS NOT RECOMMENDED on systems with more than 200 agents due performance penalty' + ), + 'url' => '__url__/index.php?sec=general&sec2=godmode/setup/setup§ion=perf', + ] + ); + } else { + $this->cleanNotifications('NOTIF.ACCESSSTASTICS.PERFORMANCE'); + } + } + + /** * Update targets for given notification using object targets. * diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index b0f698252b..02bec5060d 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -104,6 +104,7 @@ class Diagnostics extends Wizard 'getChartAjax', 'formFeedback', 'createdScheduleFeedbackTask', + 'getSystemDate', ]; @@ -209,6 +210,7 @@ class Diagnostics extends Wizard 'getAttachmentFolder', 'getInfoTagenteDatos', 'getServerThreads', + 'getSystemDate', ]; if ($this->pdf === true) { @@ -278,6 +280,10 @@ class Diagnostics extends Wizard $title = __('SQL show engine innodb status'); break; + case 'getSystemDate': + $title = __('Date system'); + break; + default: // Not possible. $title = ''; @@ -516,6 +522,27 @@ class Diagnostics extends Wizard } + /** + * Date system + * + * @return string + */ + public function getSystemDate(): string + { + $result = [ + 'error' => false, + 'data' => [ + 'date' => [ + 'name' => __('System Date (Console)'), + 'value' => date('H:i:s Y-m-d'), + ], + ], + ]; + + return json_encode($result); + } + + /** * Database size stats. * @@ -619,7 +646,7 @@ class Diagnostics extends Wizard $currentTime = time(); $pandoraDbLastRun = __('Pandora DB has never been executed'); - if ($dateDbMantenaince !== false) { + if ($dateDbMantenaince !== false && empty($dateDbMantenaince) === false) { $difference = ($currentTime - $dateDbMantenaince); $pandoraDbLastRun = human_time_description_raw( $difference, diff --git a/pandora_console/include/class/EventSound.class.php b/pandora_console/include/class/EventSound.class.php new file mode 100644 index 0000000000..b943e9cce1 --- /dev/null +++ b/pandora_console/include/class/EventSound.class.php @@ -0,0 +1,495 @@ +ajaxController = $ajaxController; + } + + + /** + * Run view + * + * @return void + */ + public function run() + { + global $config; + $tab = get_parameter('tab', ''); + $action = get_parameter('action', ''); + $message_ok = 0; + $error_msg = __('Name already exist'); + $ok_msg = __('Successfully created'); + + if ($action == 'create') { + $name = get_parameter('name', ''); + $sound = get_parameter('file', ''); + + $exist = db_get_all_rows_sql(sprintf('SELECT * FROM tevent_sound WHERE name = "%s"', $name)); + + if ($exist === false) { + $uploadMaxFilesize = config_return_in_bytes(ini_get('upload_max_filesize')); + + $upload_status = get_file_upload_status('file'); + $upload_result = translate_file_upload_status($upload_status); + if ($uploadMaxFilesize < $sound['size']) { + $error_msg = __('File is too large to upload. Check the configuration in php.ini.'); + } else { + $pathname = $config['homedir'].'/include/sounds/'; + $nameSound = str_replace(' ', '_', $_FILES['file']['name']); + $target_file = $pathname.basename($nameSound); + + if (file_exists($target_file)) { + $error_msg = __('Sound already are exists.'); + } else { + if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) { + $insert = db_process_sql_insert( + 'tevent_sound', + [ + 'name' => $name, + 'sound' => $nameSound, + ] + ); + $ok_msg = __('Successfully created'); + } else { + $error_msg = __('Fail uploading the sound'); + } + } + } + + if ($insert > 0) { + $tab = ''; + $message_ok = 1; + } + } else { + $error_msg = __('Sound already are exists'); + } + } else if ($action == 'change_action') { + $id = get_parameter('id', ''); + $new_action = (int) get_parameter('set_action', '1'); + + $exist = db_get_all_rows_sql(sprintf('SELECT * FROM tevent_sound WHERE id = "%s"', $id)); + + if ($exist !== false) { + $result = db_process_sql_update( + 'tevent_sound', + ['active' => $new_action], + ['id' => $id] + ); + if (false === (bool) $result) { + $error_msg = __('Error on update status'); + } else { + $message_ok = 1; + } + } else { + $error_msg = __('Sound not exist'); + } + } + + if ($action) { + ui_print_result_message( + $message_ok, + $ok_msg, + $error_msg, + '', + false + ); + } + + $base_url = 'index.php?sec=eventos&sec2=godmode/events/configuration_sounds'; + $setup_url = $base_url.'&tab=add'; + $tabs = [ + 'list' => [ + 'text' => '
'.html_print_image( + 'images/eye_show.png', + true, + [ + 'title' => __('Sounds'), + 'class' => 'invert_filter', + ] + ).'', + 'active' => (bool) ($tab != 'add'), + ], + 'options' => [ + 'text' => ''.html_print_image( + 'images/pen.png', + true, + [ + 'title' => __('Create'), + 'class' => 'invert_filter', + ] + ).'', + 'active' => (bool) ($tab == 'add'), + ], + ]; + + if ($tab === 'add') { + $helpHeader = ''; + $titleHeader = __('Add new sound'); + } else { + $helpHeader = 'servers_ha_clusters_tab'; + $titleHeader = __('Accoustic console sound list'); + } + + // Header. + ui_print_standard_header( + $titleHeader, + 'images/gm_servers.png', + false, + $helpHeader, + false, + $tabs, + [ + [ + 'link' => '', + 'label' => __('Admin tools'), + ], + [ + 'link' => '', + 'label' => __('Accoustic console setup'), + ], + ] + ); + + // Javascript. + ui_require_jquery_file('pandora'); + // CSS. + ui_require_css_file('wizard'); + ui_require_css_file('discovery'); + + if ($tab === 'add') { + echo '
'; + $table = new stdClass(); + $table->width = '100%'; + + $table->class = 'databox filters'; + $table->data = []; + $table->data[0][0] = __('Name:'); + + $table->data[0][1] = html_print_input_text( + 'name', + '', + '', + 80, + 100, + true, + false, + true + ); + + $table->data[1][0] = __('WAV Sound'); + $table->data[1][1] = html_print_input_file('file', true, ['required' => true]); + + html_print_table($table); + + echo '
'; + html_print_submit_button( + __('Create'), + 'save_sound', + false, + 'class="sub wand"' + ); + echo '
'; + echo '
'; + + // Load own javascript file. + echo $this->loadJS(); + } else { + // Datatables list. + try { + $columns = [ + 'name', + 'sound', + [ + 'text' => 'options', + 'class' => 'action_buttons mw120px', + ], + ]; + + $column_names = [ + __('Name'), + __('Sound'), + __('Options'), + ]; + + $this->tableId = 'event_sounds'; + + if (is_metaconsole() === true) { + // Only in case of Metaconsole, format the frame. + open_meta_frame(); + } + + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $this->tableId, + 'class' => 'info_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => $this->ajaxController, + 'ajax_data' => ['method' => 'draw'], + 'no_sortable_columns' => [-1], + 'order' => [ + 'field' => 'id', + 'direction' => 'asc', + ], + 'search_button_class' => 'sub filter', + 'form' => [ + 'inputs' => [ + [ + 'label' => __('Free search').ui_print_help_tip(__('Search filter by Name or Sound fields content'), true), + 'type' => 'text', + 'class' => 'w200px', + 'id' => 'filter_text', + 'name' => 'filter_text', + ], + [ + 'label' => __('Active'), + 'type' => 'select', + 'fields' => [ + '' => __('All'), + '0' => __('No'), + '1' => __('Yes'), + ], + 'class' => 'w100px', + 'id' => 'active', + 'name' => 'active', + ], + ], + ], + ] + ); + } catch (Exception $e) { + echo $e->getMessage(); + } + + if (is_metaconsole() === true) { + // Close the frame. + close_meta_frame(); + } + + // Load own javascript file. + echo $this->loadJS(); + } + } + + + /** + * Get the data for draw the table. + * + * @return void. + */ + public function draw() + { + global $config; + // Initialice filter. + $filter = '1=1'; + // Init data. + $data = []; + // Count of total records. + $count = 0; + // Catch post parameters. + $start = get_parameter('start', 0); + $length = get_parameter('length', $config['block_size']); + // There is a limit of (2^32)^2 (18446744073709551615) rows in a MyISAM table, show for show all use max nrows. + $length = ($length != '-1') ? $length : '18446744073709551615'; + $order = get_datatable_order(); + $filters = get_parameter('filter', []); + $filterText = $filters['filter_text']; + $filterActive = $filters['active']; + + if (empty($filterText) === false) { + $filter .= sprintf( + " AND (name LIKE '%%%s%%' OR sound LIKE '%%%s%%')", + $filterText, + $filterText + ); + } + + if (in_array($filterActive, [0, 1])) { + $filter .= sprintf( + ' AND active = %s', + $filterActive, + ); + } + + $count = (int) db_get_value_sql(sprintf('SELECT COUNT(*) as "total" FROM tevent_sound WHERE %s', $filter)); + + $sql = sprintf( + 'SELECT * + FROM tevent_sound + WHERE %s + ORDER BY %s + LIMIT %d, %d', + $filter, + $order, + $start, + $length + ); + $data = db_get_all_rows_sql($sql); + + foreach ($data as $key => $row) { + if ($row['active'] === '1') { + $img = 'images/lightbulb.png'; + $action = __('Disable sound'); + $new_action = 0; + } else { + $img = 'images/lightbulb_off.png'; + $action = __('Enable sound'); + $new_action = 1; + } + + $options = ''; + $options .= html_print_image( + $img, + true, + [ + 'title' => $action, + 'class' => 'invert_filter', + ] + ); + $options .= ''; + + $data[$key]['options'] = $options; + } + + echo json_encode( + [ + 'data' => $data, + 'recordsTotal' => $count, + 'recordsFiltered' => $count, + ] + ); + } + + + /** + * Checks if target method is available to be called using AJAX. + * + * @param string $method Target method. + * + * @return boolean True allowed, false not. + */ + public function ajaxMethod(string $method) + { + return in_array($method, $this->AJAXMethods); + } + + + /** + * Load Javascript code. + * + * @return string. + */ + public function loadJS() + { + // Nothing for this moment. + ob_start(); + + // Javascript content. + ?> + + 'flex-row', 'inputs' => [ [ - 'label' => __('Alert'), - 'type' => 'select', - 'id' => 'filter_alert', - 'name' => 'filter_alert', - 'class' => 'w200px', - 'fields' => $show_alerts, - 'return' => true, - 'selected' => $this->filter_alert, + 'label' => __('Alert'), + 'type' => 'select', + 'id' => 'filter_alert', + 'input_class' => 'filter_input_datatable', + 'name' => 'filter_alert', + 'fields' => $show_alerts, + 'return' => true, + 'selected' => $this->filter_alert, ], [ - 'label' => __('Severity'), - 'type' => 'select', - 'id' => 'filter_severity', - 'name' => 'filter_severity', - 'class' => 'w200px', - 'fields' => $severities, - 'return' => true, - 'selected' => $this->filter_severity, + 'label' => __('Severity'), + 'type' => 'select', + 'id' => 'filter_severity', + 'input_class' => 'filter_input_datatable', + 'name' => 'filter_severity', + 'fields' => $severities, + 'return' => true, + 'selected' => $this->filter_severity, ], [ - 'label' => __('Free search'), - 'type' => 'text', - 'class' => 'w400px', - 'id' => 'filter_free_search', - 'name' => 'filter_free_search', - 'value' => $this->filter_free_search, + 'label' => __('Free search'), + 'type' => 'text', + 'id' => 'filter_free_search', + 'input_class' => 'filter_input_datatable', + 'name' => 'filter_free_search', + 'value' => $this->filter_free_search, ], [ - 'label' => __('Status'), - 'type' => 'select', - 'id' => 'filter_status', - 'name' => 'filter_status', - 'class' => 'w200px', - 'fields' => $status_array, - 'return' => true, - 'selected' => $this->filter_status, + 'label' => __('Status'), + 'type' => 'select', + 'id' => 'filter_status', + 'input_class' => 'filter_input_datatable', + 'name' => 'filter_status', + 'fields' => $status_array, + 'return' => true, + 'selected' => $this->filter_status, ], [ - 'label' => __('Group by Enterprise String/IP'), - 'type' => 'select', - 'name' => 'filter_group_by', - 'selected' => $this->filter_group_by, - 'disabled' => false, - 'return' => true, - 'id' => 'filter_group_by', - 'fields' => [ + 'label' => __('Group by Enterprise String/IP'), + 'type' => 'select', + 'name' => 'filter_group_by', + 'selected' => $this->filter_group_by, + 'disabled' => false, + 'return' => true, + 'id' => 'filter_group_by', + 'input_class' => 'filter_input_datatable', + 'fields' => [ 0 => __('No'), 1 => __('Yes'), ], ], [ - 'label' => __('Max. hours old'), - 'type' => 'text', - 'class' => 'w200px', - 'id' => 'filter_hours_ago', - 'name' => 'filter_hours_ago', - 'value' => $this->filter_hours_ago, + 'label' => __('Max. hours old'), + 'type' => 'text', + 'id' => 'filter_hours_ago', + 'input_class' => 'filter_input_datatable', + 'name' => 'filter_hours_ago', + 'value' => $this->filter_hours_ago, ], [ - 'label' => __('Trap type'), - 'type' => 'select', - 'id' => 'filter_trap_type', - 'name' => 'filter_trap_type', - 'class' => 'w200px', - 'fields' => $trap_types, - 'return' => true, - 'selected' => $this->filter_trap_type, + 'label' => __('Trap type'), + 'type' => 'select', + 'id' => 'filter_trap_type', + 'input_class' => 'filter_input_datatable', + 'name' => 'filter_trap_type', + 'fields' => $trap_types, + 'return' => true, + 'selected' => $this->filter_trap_type, ], ], ], diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 6b8c7c25fa..70d3efe878 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC230217'; +$build_version = 'PC230303'; $pandora_version = 'v7.0NG.769'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 5b13cac83d..4c6245b8a5 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -6399,11 +6399,34 @@ function getBearerToken() } +/** + * Check whether an instance of pandora_db is running. + * + * @return boolean Result. + */ +function is_pandora_db_running() +{ + // Get current DB name: useful for metaconsole connection to node. + $db_name = db_get_sql('SELECT DATABASE()'); + + $is_free_lock = mysql_db_process_sql( + 'SELECT IS_FREE_LOCK("'.$db_name.'_pandora_db") AS "value"', + 'affected_rows', + '', + false + ); + + $is_free_lock = (bool) $is_free_lock[0]['value']; + + return !$is_free_lock; +} + + /** * Check nms license on api. * - * @return boolean - */ + * @return boolean. + * */ function nms_check_api() { global $config; diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 6e37a1e991..bd33e1ddf8 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -519,6 +519,27 @@ function agents_get_agents( $search_custom = ''; } + if (isset($filter['id_os'])) { + $id_os = $filter['id_os']; + unset($filter['id_os']); + } else { + $id_os = ''; + } + + if (isset($filter['policies'])) { + $policies = $filter['policies']; + unset($filter['policies']); + } else { + $policies = ''; + } + + if (isset($filter['other_condition'])) { + $other_condition = $filter['other_condition']; + unset($filter['other_condition']); + } else { + $other_condition = ''; + } + if (isset($filter['offset'])) { $offset = $filter['offset']; unset($filter['offset']); @@ -692,25 +713,38 @@ function agents_get_agents( $where_nogroup = '1 = 1'; } + $policy_join = ''; + + if ($policies !== '') { + $policy_join = 'INNER JOIN tpolicy_agents + ON tpolicy_agents.id_agent=tagente.id_agente'; + } + if ($extra) { $where = sprintf( - '(%s OR (%s)) AND (%s) AND (%s) %s AND %s', + '(%s OR (%s)) AND (%s) AND (%s) %s AND %s %s %s %s', $sql_extra, $where, $where_nogroup, $status_sql, $search, - $disabled + $disabled, + $id_os, + $policies, + $other_condition ); } else { $where = sprintf( - '%s AND %s AND (%s) %s AND %s %s', + '%s AND %s AND (%s) %s AND %s %s %s %s %s', $where, $where_nogroup, $status_sql, $search, $disabled, - $search_custom + $search_custom, + $id_os, + $policies, + $other_condition ); } @@ -720,9 +754,11 @@ function agents_get_agents( FROM `%s` tagente LEFT JOIN tagent_secondary_group ON tagent_secondary_group.id_agent=tagente.id_agente + %s WHERE %s %s', implode(',', $fields), $table_name, + $policy_join, $where, $order ); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 688bdb782f..bd1577116c 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -11071,20 +11071,55 @@ function api_set_event_validate_filter($trash1, $trash2, $other, $trash3) function api_set_validate_events($id_event, $trash1, $other, $return_type, $user_in_db) { - $text = $other['data']; + $node_int = 0; + if ($other['type'] == 'string') { + returnError('Parameter error.'); + return; + } else if ($other['type'] == 'array') { + $text = $other['data'][0]; + if (is_metaconsole() === true) { + if (isset($other['data'][1]) === true + && empty($other['data'][1]) === false + ) { + $node_int = $other['data'][1]; + } + } + } - // Set off the standby mode when close an event - $event = events_get_event($id_event); - alerts_agent_module_standby($event['id_alert_am'], 0); + try { + if (is_metaconsole() === true + && (int) $node_int > 0 + ) { + $node = new Node($node_int); + $node->connect(); + } - $result = events_change_status($id_event, EVENT_VALIDATE); + // Set off the standby mode when close an event + $event = events_get_event($id_event); + alerts_agent_module_standby($event['id_alert_am'], 0); + $result = events_change_status($id_event, EVENT_VALIDATE); - if ($result) { if (!empty($text)) { // Set the comment for the validation events_comment($id_event, $text); } + } catch (\Exception $e) { + if (is_metaconsole() === true + && $node_int > 0 + ) { + $node->disconnect(); + } + $result = false; + } finally { + if (is_metaconsole() === true + && $node_int > 0 + ) { + $node->disconnect(); + } + } + + if ($result) { returnData( 'string', [ diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 1acbfa0760..7b6e133f22 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -844,6 +844,10 @@ function config_update_config() $error_update[] = __('Item limit for realtime reports)'); } + if (config_update_value('events_per_query', (int) get_parameter('events_per_query'), true) === false) { + $error_update[] = __('Limit of events per query'); + } + if (config_update_value('step_compact', (int) get_parameter('step_compact'), true) === false) { $error_update[] = __('Compact interpolation in hours (1 Fine-20 bad)'); } @@ -1982,6 +1986,10 @@ function config_process_config() config_update_value('report_limit', 100); } + if (!isset($config['events_per_query'])) { + config_update_value('events_per_query', 5000); + } + if (!isset($config['loginhash_pwd'])) { config_update_value('loginhash_pwd', io_input_password((rand(0, 1000) * rand(0, 1000)).'pandorahash')); } @@ -2289,6 +2297,96 @@ function config_process_config() config_update_value('2Fa_auth', ''); } + if (isset($config['performance_variables_control']) === false) { + config_update_value( + 'performance_variables_control', + json_encode( + [ + 'event_purge' => [ + 'max' => 45, + 'min' => 1, + ], + 'trap_purge' => [ + 'max' => 45, + 'min' => 1, + ], + 'audit_purge' => [ + 'max' => 365, + 'min' => 7, + ], + 'string_purge' => [ + 'max' => 365, + 'min' => 7, + ], + 'gis_purge' => [ + 'max' => 365, + 'min' => 7, + ], + 'days_purge' => [ + 'max' => 365, + 'min' => 7, + ], + 'days_compact' => [ + 'max' => 365, + 'min' => 0, + ], + 'days_delete_unknown' => [ + 'max' => 90, + 'min' => 0, + ], + 'days_delete_not_initialized' => [ + 'max' => 90, + 'min' => 0, + ], + 'days_autodisable_deletion' => [ + 'max' => 90, + 'min' => 0, + ], + 'delete_old_network_matrix' => [ + 'max' => 30, + 'min' => 1, + ], + 'report_limit' => [ + 'max' => 500, + 'min' => 1, + ], + 'event_view_hr' => [ + 'max' => 360, + 'min' => 1, + ], + 'big_operation_step_datos_purge' => [ + 'max' => 10000, + 'min' => 100, + ], + 'small_operation_step_datos_purge' => [ + 'max' => 10000, + 'min' => 100, + ], + 'row_limit_csv' => [ + 'max' => 1000000, + 'min' => 1, + ], + 'limit_parameters_massive' => [ + 'max' => 2000, + 'min' => 100, + ], + 'block_size' => [ + 'max' => 200, + 'min' => 10, + ], + 'short_module_graph_data' => [ + 'max' => 20, + 'min' => 1, + ], + 'graph_precision' => [ + 'max' => 5, + 'min' => 1, + ], + ] + ) + ); + } + if (isset($config['agent_wizard_defaults']) === false) { config_update_value( 'agent_wizard_defaults', diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 48ef7b2c30..c41c909c27 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2018,7 +2018,7 @@ function events_change_status( // Update ack info if the new status is validated. $ack_utimestamp = 0; $ack_user = $config['id_user']; - if ((int) $new_status === EVENT_STATUS_VALIDATED) { + if ((int) $new_status === EVENT_STATUS_VALIDATED || (int) $new_status === EVENT_STATUS_INPROCESS) { $ack_utimestamp = time(); } @@ -2412,14 +2412,17 @@ function events_create_event( $source = get_product_name(); } + // Get Timestamp. + $timestamp = time(); + $values = [ 'id_agente' => $id_agent, 'id_usuario' => $id_user, 'id_grupo' => $id_group, 'estado' => $status, - 'timestamp' => date('Y-m-d H:i:s'), + 'timestamp' => date('Y-m-d H:i:s', $timestamp), 'evento' => $event, - 'utimestamp' => time(), + 'utimestamp' => $timestamp, 'event_type' => $event_type, 'id_agentmodule' => $id_agent_module, 'id_alert_am' => $id_aam, @@ -4814,7 +4817,7 @@ function events_page_general($event) $data = []; $data[0] = __('Acknowledged by'); - if ($event['estado'] == 1) { + if ($event['estado'] == 1 || $event['estado'] == 2) { if (empty($event['id_usuario']) === true) { $user_ack = __('Autovalidated'); } else { @@ -4948,7 +4951,7 @@ function events_page_general_acknowledged($event_id) global $config; $Acknowledged = ''; $event = db_get_row('tevento', 'id_evento', $event_id); - if ($event !== false && $event['estado'] == 1) { + if ($event !== false && ($event['estado'] == 1 || $event['estado'] == 2)) { $user_ack = db_get_value( 'fullname', 'tusuario', @@ -5826,3 +5829,58 @@ function get_events_get_response_target( } } } + + +/** + * Gets the count of events by criticity. + * + * @param integer $utimestamp Utimestamp to search. + * @param integer $eventType Event type. + * @param array $groupId Groups. + * @param integer $eventStatus Event status. + * @param array $criticityId Criticity to search. + * + * @return array + */ +function get_count_event_criticity( + $utimestamp, + $eventType, + $groupId, + $eventStatus, + $criticityId +) { + $type = ' '; + if ($eventType !== '0') { + $type = 'AND event_type = "'.$eventType.'"'; + } + + $groups = ' '; + if ((int) $groupId !== 0) { + $groups = 'AND id_grupo IN ('.$groupId.')'; + } + + $status = ' '; + if ((int) $eventStatus !== -1) { + $status = 'AND estado = '.$eventStatus; + } + + $criticity = ' '; + if (empty($criticityId) === false) { + $criticity = 'AND criticity IN ('.$criticityId.')'; + } + + $sql_meta = sprintf( + 'SELECT COUNT(id_evento) AS count, + criticity + FROM tevento + WHERE utimestamp >= %d %s %s %s %s + GROUP BY criticity', + $utimestamp, + $type, + $groups, + $status, + $criticity + ); + + return db_get_all_rows_sql($sql_meta); +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 31c2e5214a..44a8289b0d 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -84,6 +84,27 @@ function html_debug_print($var, $file='', $oneline=false) } +/** + * Console log. + */ +function jslog($var) +{ + $more_info = ''; + if (is_string($var)) { + $more_info = 'size: '.strlen($var); + } else if (is_bool($var)) { + $more_info = 'val: '.($var ? 'true' : 'false'); + } else if (is_null($var)) { + $more_info = 'is null'; + } else if (is_array($var)) { + $more_info = count($var); + } + + echo ''."\n"; + echo ''; +} + + // Alias for "html_debug_print" function html_debug($var, $file='', $oneline=false) { diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 277eb8520c..2d474a9853 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -797,6 +797,7 @@ if (is_ajax()) { $db_fragmentation = json_decode($d->getTablesFragmentation()); $sys_info = json_decode($d->getSystemInfo()); $php_sys = json_decode($d->getPHPSetup()); + $system_date = json_decode($d->getSystemDate()); $fragmentation_status = ''; if ($db_fragmentation->data->tablesFragmentationStatus->status === 1) { @@ -1030,6 +1031,14 @@ if (is_ajax()) {

'.$sys_info->data->ipInfo->value.'

+ + +

'.$system_date->data->date->name.'

+ + +

'.$system_date->data->date->value.'

+ +
diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 705d67ab3b..657ce1ff35 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -159,6 +159,8 @@ function notifications_get_subtypes(?string $source=null) 'NOTIF.SERVER.STATUS', 'NOTIF.SERVER.QUEUE', 'NOTIF.SERVER.MASTER', + 'NOTIF.ACCESSSTASTICS.PERFORMANCE', + 'NOTIF.VARIABLES.PERFORMANCE', ], ]; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 637ae59752..c17745da8b 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -68,6 +68,7 @@ define('REPORT_STATUS_IGNORED', 5); // Clases. use PandoraFMS\Enterprise\Metaconsole\Node; +use PandoraFMS\Enterprise\Metaconsole\Synchronizer; use PandoraFMS\Event; use PandoraFMS\Module; @@ -7421,6 +7422,14 @@ function reporting_text($report, $content) } +/** + * Build SQL report item. + * + * @param array $report Report info. + * @param array $content Content info. + * + * @return array + */ function reporting_sql($report, $content) { global $config; @@ -7438,15 +7447,97 @@ function reporting_sql($report, $content) $return['description'] = $content['description']; $return['date'] = reporting_get_date_text(); - if ($config['metaconsole'] && !empty($content['server_name'])) { - $id_meta = metaconsole_get_id_server( + if (is_metaconsole() === true + && empty($content['server_name']) === false + && $content['server_name'] !== 'all' + ) { + $id_server = metaconsole_get_id_server( $content['server_name'] ); - - $server = metaconsole_get_connection_by_id($id_meta); - metaconsole_connect($server); } + if (is_metaconsole() === true && $content['server_name'] === 'all') { + $sync = new Synchronizer(); + $results = $sync->apply( + function ($node) use ($report, $content) { + try { + $node->connect(); + $rs = reporting_sql_auxiliary($report, $content); + $node->disconnect(); + } catch (Exception $e) { + return [ + 'error' => __( + 'Failed to connect to node %s', + $node->server_name() + ), + ]; + } + + if ($rs === false) { + return ['result' => []]; + } + + return ['result' => $rs]; + }, + false + ); + + $data = []; + $return['correct'] = 1; + $return['error'] = ''; + + foreach ($results as $id_node => $items) { + foreach ($items['result']['data'] as $key => $item) { + $items['result']['data'][$key] = ['node_id' => $id_node] + $items['result']['data'][$key]; + } + + if ((int) $items['result']['correct'] !== 1) { + $return['correct'] = 0; + } + + if ($items['result']['error'] !== '') { + $return['error'] = $items['result']['error']; + } + + $return['sql'] = $items['result']['sql']; + + $data = array_merge($data, $items['result']['data']); + } + + $return['data'] = $data; + } else { + try { + if (is_metaconsole() === true && $id_server > 0) { + $node = new Node($id_server); + $node->connect(); + } + + $query_result = reporting_sql_auxiliary($report, $content); + $return = array_merge($return, $query_result); + + if (is_metaconsole() === true && $id_server > 0) { + $node->disconnect(); + } + } catch (\Exception $e) { + if (is_metaconsole() === true && $id_server > 0) { + $node->disconnect(); + } + } + } + + return reporting_check_structure_content($return); +} + + +/** + * Auxiliary function for reporting_sql. + * + * @param array $report Report info. + * @param array $content Content info. + * + * @return array + */ +function reporting_sql_auxiliary($report, $content) { if ($content['treport_custom_sql_id'] != 0) { $sql = io_safe_output( db_get_value_filter( @@ -7459,7 +7550,7 @@ function reporting_sql($report, $content) $sql = $content['external_source']; } - // Check if exist sql macro. + // Check if SQL macro exists. $sql = reporting_sql_macro($report, $sql); // Do a security check on SQL coming from the user. @@ -7514,11 +7605,7 @@ function reporting_sql($report, $content) $return['error'] = __('Illegal query: Due security restrictions, there are some tokens or words you cannot use: *, delete, drop, alter, modify, password, pass, insert or update.'); } - if ($config['metaconsole'] && !empty($content['server_name'])) { - metaconsole_restore_db(); - } - - return reporting_check_structure_content($return); + return $return; } diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 198d4a51c8..2062ccb8c8 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -696,6 +696,8 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) $go_to_agent .= ''; $go_to_agent .= html_print_submit_button(__('Go to cluster edition'), 'upd_button', false, 'class="sub config"', true); } else { + $go_to_agent .= ''; + $go_to_agent .= html_print_submit_button(__('Go to module creation'), 'upd_button', false, 'class="sub config"', true); $go_to_agent .= ''; $go_to_agent .= html_print_submit_button(__('Go to agent edition'), 'upd_button', false, 'class="sub config"', true); } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 6a658997f6..ce17086f02 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -7084,3 +7084,21 @@ function ui_get_inventory_module_add_form( } +function ui_print_status_div($status) +{ + switch ((int) $status) { + case 0: + $return = '
 
'; + break; + + case 1: + $return = '
 
'; + break; + + default: + $return = '
 
'; + break; + } + + return $return; +} \ No newline at end of file diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 2753b8a55d..bb082de0c7 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -420,6 +420,7 @@ class Widget case 'ColorModuleTabs': case 'BlockHistogram': case 'DataMatrix': + case 'EventCardboard': $className .= '\\'.$name; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/EventCardboard.php b/pandora_console/include/lib/Dashboard/Widgets/EventCardboard.php new file mode 100644 index 0000000000..87e592c8af --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/EventCardboard.php @@ -0,0 +1,664 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Cell Id. + $this->cellId = $cellId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Positions. + $this->position = $this->getPositionWidget(); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Event cardboard'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'EventCardboard'; + } + + // This forces at least a first configuration. + $this->configurationRequired = false; + if (isset($this->values['groupId']) === false) { + $this->configurationRequired = true; + } + + $this->overflow_scrollbars = false; + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + if (isset($decoder['eventType']) === true) { + $values['eventType'] = $decoder['eventType']; + } + + if (isset($decoder['maxHours']) === true) { + $values['maxHours'] = $decoder['maxHours']; + } + + if (isset($decoder['eventStatus']) === true) { + $values['eventStatus'] = $decoder['eventStatus']; + } + + if (isset($decoder['severity']) === true) { + $values['severity'] = $decoder['severity']; + } + + if (isset($decoder['groupId']) === true) { + $values['groupId'] = $decoder['groupId']; + } + + if (isset($decoder['nodes']) === true) { + $values['nodes'] = $decoder['nodes']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + // Remove background field, this widget doesn't use it. + foreach ($inputs as $kIn => $vIn) { + if ($vIn['label'] === 'Background') { + unset($inputs[$kIn]); + } + } + + $blocks = [ + 'row1', + 'row2', + ]; + + $inputs['blocks'] = $blocks; + + foreach ($inputs as $kInput => $vInput) { + $inputs['inputs']['row1'][] = $vInput; + } + + // Event Type. + $fields = get_event_types(); + $fields['not_normal'] = __('Not normal'); + + $inputs['inputs']['row1'][] = [ + 'label' => __('Event type'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'class' => 'event-widget-input', + 'name' => 'eventType', + 'selected' => $values['eventType'], + 'return' => true, + 'nothing' => __('Any'), + 'nothing_value' => 0, + ], + ]; + + // Max. hours old. Default 8. + if (isset($values['maxHours']) === false) { + $values['maxHours'] = 8; + } + + $inputs['inputs']['row1'][] = [ + 'label' => __('Max. hours old'), + 'arguments' => [ + 'name' => 'maxHours', + 'type' => 'number', + 'class' => 'event-widget-input', + 'value' => $values['maxHours'], + 'return' => true, + 'min' => 0, + ], + ]; + + // Event status. + $fields = [ + -1 => __('All event'), + 1 => __('Only validated'), + 0 => __('Only pending'), + ]; + + $inputs['inputs']['row1'][] = [ + 'label' => __('Event status'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'class' => 'event-widget-input', + 'name' => 'eventStatus', + 'selected' => $values['eventStatus'], + 'return' => true, + ], + ]; + + // Groups. + $return_all_group = false; + $selected_groups_array = explode(',', $values['groupId'][0]); + + if (empty($values['groupId'][0]) === true) { + $selected_groups_array = [0]; + } + + if ((bool) \users_can_manage_group_all('RM') === true + || ($selected_groups_array[0] !== '' + && in_array(0, $selected_groups_array) === true) + ) { + // Return all group if user has permissions or it is a currently + // selected group. + $return_all_group = true; + } + + $inputs['inputs']['row1'][] = [ + 'label' => __('Groups'), + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groupId[]', + 'class' => 'event-widget-input', + 'returnAllGroup' => true, + 'privilege' => 'AR', + 'selected' => $selected_groups_array, + 'return' => true, + 'multiple' => true, + 'returnAllGroup' => $return_all_group, + 'required' => true, + ], + ]; + + // Nodes. + if (is_metaconsole() === true) { + $nodes_fields = []; + $servers_ids = metaconsole_get_servers(); + + foreach ($servers_ids as $server) { + $nodes_fields[$server['id']] = $server['server_name']; + } + + $nodes_fields[0] = __('Metaconsola'); + + $nodes_selected = explode(',', $values['nodes']); + + (isset($values['nodes']) === false) ? $nodes_selected = $servers_ids : ''; + + $nodes_height = count($nodes_fields); + if (count($nodes_fields) > 5) { + $nodes_height = 5; + } + + $inputs['inputs']['row2'][] = [ + 'label' => __('Servers'), + 'arguments' => [ + 'name' => 'nodes', + 'type' => 'select', + 'fields' => $nodes_fields, + 'selected' => $nodes_selected, + 'return' => true, + 'multiple' => true, + 'class' => 'overflow-hidden', + 'size' => $nodes_height, + 'select_all' => false, + 'required' => true, + ], + ]; + } + + // Severity. + $fields = get_priorities(); + + $severity_selected = explode(',', $values['severity']); + + if (isset($values['severity']) === false) { + $severity_selected = array_keys($fields); + } + + $inputs['inputs']['row2'][] = [ + 'label' => __('Severity'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'class' => 'event-widget-input', + 'name' => 'severity', + 'selected' => $severity_selected, + 'return' => true, + 'multiple' => true, + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost():array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['eventType'] = \get_parameter('eventType', 0); + $values['maxHours'] = \get_parameter('maxHours', 8); + $values['eventStatus'] = \get_parameter('eventStatus', -1); + $values['groupId'] = \get_parameter('groupId', []); + $values['severity'] = \get_parameter('severity', -1); + $values['nodes'] = \get_parameter('nodes', 0); + + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + $output = ''; + + ui_require_css_file('events', 'include/styles/', true); + ui_require_javascript_file('pandora_events', 'include/javascript/', true); + + $eventType = $this->values['eventType']; + $groupId = implode(',', $this->values['groupId']); + $utimestamp = strtotime('-'.$this->values['maxHours'].' hours'); + $eventStatus = $this->values['eventStatus']; + $severity = $this->values['severity']; + + $priorities = explode(',', $severity); + // Sort criticity array. + asort($priorities); + + $count_meta = []; + $count_meta_tmp = []; + if (is_metaconsole() === true) { + $meta = false; + $nodes = $this->values['nodes']; + + if (isset($nodes) === true) { + $servers_ids = explode(',', $nodes); + } + + if (in_array(0, $servers_ids) === true) { + $meta = true; + unset($servers_ids[0]); + } + + if (is_metaconsole() === true && $meta === true) { + $events_meta_rows = get_count_event_criticity( + $utimestamp, + $eventType, + $groupId, + $eventStatus, + $severity + ); + + array_push($count_meta_tmp, $events_meta_rows); + } + + foreach ($servers_ids as $server_id) { + try { + $node = new Node((int) $server_id); + $node->connect(); + + $events_meta_rows = get_count_event_criticity( + $utimestamp, + $eventType, + $groupId, + $eventStatus, + $severity + ); + + array_push($count_meta_tmp, $events_meta_rows); + $node->disconnect(); + } catch (\Exception $e) { + // Unexistent envents. + $node->disconnect(); + } + } + + foreach ($count_meta_tmp as $tmpValue) { + foreach ($tmpValue as $value) { + array_push($count_meta, $value); + } + } + + $events_rows = []; + foreach ($priorities as $pKey) { + $count = 0; + $tmp['criticity'] = $pKey; + foreach ($count_meta as $kEventMeta => $vEventMeta) { + if ((int) $pKey === (int) $vEventMeta['criticity']) { + $count += (int) $vEventMeta['count']; + } + } + + $tmp['count'] = $count; + array_push($events_rows, $tmp); + } + } else { + $events_rows = get_count_event_criticity( + $utimestamp, + $eventType, + $groupId, + $eventStatus, + $severity + ); + } + + $output .= ''; + + $width_td = (100 / count(explode(',', $severity))); + + $td_count = 0; + foreach ($priorities as $key) { + $count = 0; + foreach ($events_rows as $event) { + if ((int) $key === (int) $event['criticity']) { + $count = $event['count']; + } + } + + switch ((int) $key) { + case 0: + $text = __('Maintenance'); + $color = get_priority_class((int) $key); + break; + + case 1: + $text = __('Informational'); + $color = get_priority_class((int) $key); + break; + + case 2: + $text = __('Normal'); + $color = get_priority_class((int) $key); + break; + + case 3: + $text = __('Warning'); + $color = get_priority_class((int) $key); + break; + + case 4: + $text = __('Critical'); + $color = get_priority_class((int) $key); + break; + + case 5: + $text = __('Minor'); + $color = get_priority_class((int) $key); + break; + + case 6: + $text = __('Major'); + $color = get_priority_class((int) $key); + break; + + case 20: + $text = __('Not normal'); + $color = get_priority_class((int) $key); + break; + + case 21: + $text = __('Critical').'/'.__('Normal'); + $color = get_priority_class((int) $key); + break; + + case 34: + $text = __('Warning').'/'.__('Critical'); + $color = get_priority_class((int) $key); + break; + + default: + return false; + } + + $border = ''; + $td_count++; + if (count($priorities) > $td_count) { + $border = ' border-right: 1px solid white; border-collapse: collapse;'; + } + + $output .= ''; + } + + $output .= '
'; + $output .= $count; + $output .= '
'; + $output .= $text; + $output .= '
'; + + return $output; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Event cardboard'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'EventCardboard'; + } + + + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + if (is_metaconsole() === true) { + $size = [ + 'width' => 950, + 'height' => 450, + ]; + } else { + $size = [ + 'width' => 900, + 'height' => 450, + ]; + } + + return $size; + } + + +} diff --git a/pandora_console/include/rest-api/models/VisualConsole/View.php b/pandora_console/include/rest-api/models/VisualConsole/View.php index cd1e25fd49..e8305df830 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/View.php +++ b/pandora_console/include/rest-api/models/VisualConsole/View.php @@ -144,6 +144,8 @@ class View extends \HTML tinyMCE.init({ selector: "#textarea_label", theme: "advanced", + convert_urls:false, + relative_urls:false, content_css: "'.ui_get_full_url(false, false, false, false).'include/styles/pandora.css", theme_advanced_font_sizes: "4pt=.visual_font_size_4pt, " + diff --git a/pandora_console/include/styles/meta_dashboards.css b/pandora_console/include/styles/meta_dashboards.css index f75afafa93..f3716c0f81 100644 --- a/pandora_console/include/styles/meta_dashboards.css +++ b/pandora_console/include/styles/meta_dashboards.css @@ -29,3 +29,18 @@ li#select_multiple_modules_filtered { #menu_tab li.nomn form#form-select-dashboard { margin-top: 0px !important; } + +.table-border-0 { + border: none !important; + border-spacing: 0px !important; +} + +.big_data { + text-decoration: none; + font-size: 2em; +} + +.med_data { + text-decoration: none; + font-size: 1.5em; +} diff --git a/pandora_console/include/styles/tables.css b/pandora_console/include/styles/tables.css index 40ecaf11ba..30592ed6db 100644 --- a/pandora_console/include/styles/tables.css +++ b/pandora_console/include/styles/tables.css @@ -323,6 +323,27 @@ a.pandora_pagination.current:hover { cursor: default; } +.filter_input_datatable { + width: 45% !important; + display: flex; + flex-wrap: nowrap; + flex-direction: row; + max-width: 450px; + min-width: 400px; +} +.filter_input_datatable input { + flex: 1; +} +.filter_input_datatable label { + width: 93px; + max-width: 100%; +} +.filter_input_datatable .select2.select2-container { + flex: 1; +} +.datatable_filter.content li.filter_input_datatable { + margin: 1em 0; +} /* Default datatable filter style */ .datatable_filter.content { display: flex; @@ -337,6 +358,7 @@ a.pandora_pagination.current:hover { .datatable_filter.content li { flex: 1 1 auto; margin: 1em auto; + padding: 0px 10px; } .sorting_desc { background: url(../../images/sort_down_green.png) no-repeat; diff --git a/pandora_console/index.php b/pandora_console/index.php index 1826dbe789..d7f124575b 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1049,6 +1049,7 @@ if (isset($_GET['bye'])) { header_remove('Set-Cookie'); setcookie(session_name(), $_COOKIE[session_name()], (time() - 4800), '/'); + generate_csrf_code(); // Process logout. include 'general/logoff.php'; diff --git a/pandora_console/install.php b/pandora_console/install.php index 64d39e5054..f89f637f9e 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -131,7 +131,7 @@
0) { + $user_groups_fl = users_get_groups( + $config['id_user'], + 'AR', + users_can_manage_group_all('AR'), + true + ); + + $sql = sprintf( + 'SELECT id_filter, id_name + FROM tagent_filter + WHERE id_filter = %d AND id_group_filter IN (%s)', + $load_filter_id, + implode(',', array_keys($user_groups_fl)) + ); + + $loaded_filter = db_get_row_sql($sql); +} + +if ($loaded_filter['id_filter'] > 0) { + $query_filter['id_filter'] = $load_filter_id; + $filter = db_get_row_filter('tagent_filter', $query_filter, false); + + if ($filter !== false) { + $group_id = (int) $filter['group_id']; + $recursion = $filter['recursion']; + $status = $filter['status']; + $search = $filter['search']; + $os = $filter['id_os']; + $policies = json_decode($filter['policies'], true); + $search_custom = $filter['search_custom']; + $ag_custom_fields = $filter['ag_custom_fields']; + } + + + if (is_array($ag_custom_fields) === false) { + $ag_custom_fields = json_decode(io_safe_output($ag_custom_fields), true); + } + + if (is_array($policies) === false) { + $policies = json_decode(io_safe_output($policies), true); + } +} + if (check_acl($config['id_user'], 0, 'AW')) { // Prepare the tab system to the future. $tab = 'setup'; @@ -247,22 +297,47 @@ if (isset($result_delete)) { echo '
'; -echo ''; +//echo '
'; -echo ''; +html_print_table($table); -echo '
'; +//echo '
'; -echo __('Group').' '.' '.' '; +// Start Build Search Form. +// +$table = new StdClass(); +$table->width = '100%'; +$table->cellspacing = 0; +$table->cellpadding = 0; +$table->class = 'databox filters'; +$table->style[0] = 'font-weight: bold;'; +$table->style[1] = 'font-weight: bold;'; +$table->style[2] = 'font-weight: bold;'; +$table->style[3] = 'font-weight: bold;'; +$table->style[4] = 'font-weight: bold;'; + +$table->data[0][0] = __('Group'); +$table->data[0][0] .= '
'; $groups = users_get_groups(false, $access); -html_print_select_groups(false, $access, true, 'group_id', $group_id, 'this.form.submit()', '', '', false, false, true, '', false); +$table->data[0][0] .= html_print_select_groups(false, $access, true, 'group_id', $group_id, '', '', '', true, false, true, '', false); -echo '
'.' '.' '.' '.' '.' '; +//$table->data[0][1] .= '  '; -echo __('Recursion').' '.' '.' '; -html_print_checkbox('recursion', 1, $recursion, false, false, 'this.form.submit()'); +$table->data[0][0] .= '
'.__('Recursion').' '.' '.' '; +$table->data[0][0] .= html_print_input( + [ + 'type' => 'checkbox', + 'name' => 'recursion', + 'return' => true, + 'checked' => $recursion, + 'checked' => ($recursion === true || $recursion === 'true' || $recursion === '1') ? 'checked' : false, + 'value' => 1, + ] +); -echo '
'; + + +//echo ''; $fields = []; $fields[AGENT_STATUS_NORMAL] = __('Normal'); @@ -272,31 +347,125 @@ $fields[AGENT_STATUS_UNKNOWN] = __('Unknown'); $fields[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); $fields[AGENT_STATUS_NOT_INIT] = __('Not init'); -echo __('Status').' '.' '.' '; -html_print_select($fields, 'status', $status, 'this.form.submit()', __('All'), AGENT_STATUS_ALL, false, false, true, '', false, 'width: 90px;'); +$table->data[0][1] = __('Status').' '.' '.' '; +$table->data[0][1] .= html_print_select($fields, 'status', $status, '', __('All'), AGENT_STATUS_ALL, true, false, true, '', false, 'width: 90px;'); -echo ''; +$table->data[0][2] = __('Search').' '.' '.' '; +$table->data[0][2] .= html_print_input_text('search', $search, '', 15, 255, true); -echo __('Search').' '.' '.' '; -html_print_input_text('search', $search, '', 15); +$table->data[1][0] = __('Operating System').' '; -echo ''; +$pre_fields = db_get_all_rows_sql( + 'select distinct(tagente.id_os),tconfig_os.name from tagente,tconfig_os where tagente.id_os = tconfig_os.id_os' +); +$fields = []; -echo __('Search in custom fields').' '.' '.' '; -html_print_input_text('search_custom', $search_custom, '', 15); +foreach ($pre_fields as $key => $value) { + $fields[$value['id_os']] = $value['name']; +} -echo ''; +$table->data[1][0] .= html_print_select($fields, 'os', $os, '', 'All', 0, true); -html_print_submit_button( +$table->data[1][1] = __('Policies').' '; + +$pre_fields = policies_get_policies(false, ['id', 'name']); +$fields = []; + +foreach ($pre_fields as $value) { + $fields[$value['id']] = $value['name']; +} + +$table->data[1][1] .= html_print_select($fields, 'policies[]', $policies, '', 'All', 0, true, true); + +$table->data[1][2] = __('Search in custom fields').' '.' '.' '; +$table->data[1][2] .= html_print_input_text('search_custom', $search_custom, '', 15, 255, true); + + +$custom_fields = db_get_all_fields_in_table('tagent_custom_fields'); +if ($custom_fields === false) { + $custom_fields = []; +} + +$div_custom_fields = '
'; +foreach ($custom_fields as $custom_field) { + $custom_field_value = ''; + if (empty($ag_custom_fields) === false) { + $custom_field_value = $ag_custom_fields[$custom_field['id_field']]; + if (empty($custom_field_value) === true) { + $custom_field_value = ''; + } + } + + $div_custom_fields .= '
'; + + $div_custom_fields .= '
'; + $div_custom_fields .= ''.$custom_field['name'].''; + $div_custom_fields .= '
'; + + $div_custom_fields .= '
'; + $div_custom_fields .= html_print_input_text( + 'ag_custom_fields['.$custom_field['id_field'].']', + $custom_field_value, + '', + 0, + 300, + true, + false, + false, + '', + 'div-input' + ); + $div_custom_fields .= '
'; +} + +$table->colspan[2][0] = 7; +$table->cellstyle[2][0] = 'padding-left: 10px;'; +$table->data[2][0] = ui_toggle( + $div_custom_fields, + __('Agent custom fields'), + '', + '', + true, + true, + '', + 'white-box-content', + 'white_table_graph' +); + + +$table->colspan[4][0] = 4; +$table->cellstyle[4][0] = 'padding-top: 0px;'; +$table->data[4][0] = html_print_button( + __('Load filter'), + 'load-filter', + false, + '', + 'class="float-left margin-right-2 sub config"', + true +); + +$table->cellstyle[4][0] .= 'padding-top: 0px;'; +$table->data[4][0] .= html_print_button( + __('Manage filter'), + 'save-filter', + false, + '', + 'class="float-left margin-right-2 sub wand"', + true +); + +$table->cellstyle[4][2] = 'padding-top: 0px;'; +$table->data[4][2] = html_print_submit_button( __('Search'), 'srcbutton', '', - ['class' => 'sub search'] + ['class' => 'sub search'], + true ); -echo '
'; +''; if ($search != '') { $filter = ['string' => '%'.$search.'%']; @@ -320,6 +489,8 @@ $selectDescriptionUp = false; $selectDescriptionDown = false; $selectLastContactUp = false; $selectLastContactDown = false; +$selectLastStatusChangeUp = false; +$selectLastStatusChangeDown = false; $order = null; switch ($sortField) { @@ -479,6 +650,32 @@ switch ($sortField) { } break; + case 'last_status_change': + switch ($sort) { + case 'up': + $selectLastStatusChangeUp = $selected; + $order = [ + 'field' => 'last_status_change', + 'field2' => 'alias', + 'order' => 'ASC', + ]; + break; + + case 'down': + $selectLastStatusChangeDown = $selected; + $order = [ + 'field' => 'last_status_change', + 'field2' => 'alias', + 'order' => 'DESC', + ]; + break; + + default: + // Default. + break; + } + break; + case 'description': switch ($sort) { case 'up': @@ -518,6 +715,8 @@ switch ($sortField) { $selectDescriptionDown = false; $selectLastContactUp = false; $selectLastContactDown = false; + $selectLastStatusChangeUp = false; + $selectLastStatusChangeDown = false; $order = [ 'field' => 'alias', 'field2' => 'alias', @@ -577,6 +776,24 @@ if (!empty($search_custom)) { $search_sql_custom = ''; } +// Filter by agent custom fields. +$sql_conditions_custom_fields = ''; +if (empty($ag_custom_fields) === false) { + $cf_filter = []; + foreach ($ag_custom_fields as $field_id => $value) { + if (empty($value) === false) { + $cf_filter[] = '(tagent_custom_data.id_field = '.$field_id.' AND tagent_custom_data.description LIKE \'%'.$value.'%\')'; + } + } + + if (empty($cf_filter) === false) { + $sql_conditions_custom_fields = ' AND tagente.id_agente IN ( + SELECT tagent_custom_data.id_agent + FROM tagent_custom_data + WHERE '.implode(' AND ', $cf_filter).')'; + } +} + // Show only selected groups. if ($group_id > 0) { $groups = [$group_id]; @@ -589,23 +806,41 @@ if ($group_id > 0) { $groups = array_keys($user_groups); } +$all_policies = in_array(0, $policies ?? []); + +$id_os_sql = ''; +$policies_sql = ''; + +if ($os > 0) { + $id_os_sql = ' AND id_os = '.$os; +} + +if ($all_policies === false && is_array($policies) && count($policies) > 0) { + $policies_sql = ' AND tpolicy_agents.id_policy IN ('.implode(',', $policies).')'; +} if ($strict_user) { $count_filter = [ // 'order' => 'tagente.nombre ASC', - 'order' => 'tagente.nombre ASC', - 'disabled' => 0, - 'status' => $status, - 'search' => $search, + 'order' => 'tagente.nombre ASC', + 'disabled' => 0, + 'status' => $status, + 'search' => $search, + 'id_os' => $id_os_sql, + 'policies' => $policies_sql, + 'other_condition' => $sql_conditions_custom_fields, ]; $filter = [ // 'order' => 'tagente.nombre ASC', - 'order' => 'tagente.nombre ASC', - 'disabled' => 0, - 'status' => $status, - 'search' => $search, - 'offset' => (int) get_parameter('offset'), - 'limit' => (int) $config['block_size'], + 'order' => 'tagente.nombre ASC', + 'disabled' => 0, + 'status' => $status, + 'search' => $search, + 'offset' => (int) get_parameter('offset'), + 'limit' => (int) $config['block_size'], + 'id_os' => $id_os_sql, + 'policies' => $policies_sql, + 'other_condition' => $sql_conditions_custom_fields, ]; if ($group_id > 0) { @@ -644,28 +879,48 @@ if ($strict_user) { $agents = tags_get_all_user_agents(false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true); } else { + $count_filter = [ + 'disabled' => 0, + 'id_grupo' => $groups, + 'search' => $search_sql, + 'search_custom' => $search_sql_custom, + 'status' => $status, + 'id_os' => $id_os_sql, + 'policies' => $policies_sql, + 'other_condition' => $sql_conditions_custom_fields, + ]; + + $filter = [ + 'order' => 'nombre ASC', + 'id_grupo' => $groups, + 'disabled' => 0, + 'status' => $status, + 'search_custom' => $search_sql_custom, + 'search' => $search_sql, + 'offset' => (int) get_parameter('offset'), + 'limit' => (int) $config['block_size'], + 'id_os' => $id_os_sql, + 'policies' => $policies_sql, + 'other_condition' => $sql_conditions_custom_fields, + ]; + $total_agents = agents_count_agents_filter( - [ - 'disabled' => 0, - 'id_grupo' => $groups, - 'search' => $search_sql, - 'search_custom' => $search_sql_custom, - 'status' => $status, - ], + $count_filter, $access ); + $query_order = $order; + + if ($order['field'] === 'last_status_change') { + $query_order = [ + 'field' => 'alias', + 'field2' => 'alias', + 'order' => 'ASC', + ]; + } + $agents = agents_get_agents( - [ - 'order' => 'nombre '.' ASC', - 'id_grupo' => $groups, - 'disabled' => 0, - 'status' => $status, - 'search_custom' => $search_sql_custom, - 'search' => $search_sql, - 'offset' => (int) get_parameter('offset'), - 'limit' => (int) $config['block_size'], - ], + $filter, [ 'id_agente', 'id_grupo', @@ -688,7 +943,7 @@ if ($strict_user) { 'agent_version', ], $access, - $order + $query_order ); } @@ -720,7 +975,8 @@ $url_up_group = 'index.php?sec=view&sec2=operation/agentes/estado_agente& $url_down_group = 'index.php?sec=view&sec2=operation/agentes/estado_agente&refr='.$refr.'&offset='.$offset.'&group_id='.$group_id.'&recursion='.$recursion.'&search='.$search.'&status='.$status.'&sort_field=group&sort=down'; $url_up_last = 'index.php?sec=view&sec2=operation/agentes/estado_agente&refr='.$refr.'&offset='.$offset.'&group_id='.$group_id.'&recursion='.$recursion.'&search='.$search.'&status='.$status.'&sort_field=last_contact&sort=up'; $url_down_last = 'index.php?sec=view&sec2=operation/agentes/estado_agente&refr='.$refr.'&offset='.$offset.'&group_id='.$group_id.'&recursion='.$recursion.'&search='.$search.'&status='.$status.'&sort_field=last_contact&sort=down'; - +$url_up_last_status_change = 'index.php?sec=view&sec2=operation/agentes/estado_agente&refr='.$refr.'&offset='.$offset.'&group_id='.$group_id.'&recursion='.$recursion.'&search='.$search.'&status='.$status.'&sort_field=last_status_change&sort=up'; +$url_down_last_status_change = 'index.php?sec=view&sec2=operation/agentes/estado_agente&refr='.$refr.'&offset='.$offset.'&group_id='.$group_id.'&recursion='.$recursion.'&search='.$search.'&status='.$status.'&sort_field=last_status_change&sort=down'; // Prepare pagination. ui_pagination( @@ -740,16 +996,16 @@ $table->head[0] = __('Agent').ui_get_sorting_arrows($url_up_agente, $url_down_ag $table->size[0] = '12%'; $table->head[1] = __('Description').ui_get_sorting_arrows($url_up_description, $url_down_description, $selectDescriptionUp, $selectDescriptionDown); -$table->size[1] = '16%'; +$table->size[1] = '14%'; -$table->head[10] = __('Remote').ui_get_sorting_arrows($url_up_remote, $url_down_remote, $selectRemoteUp, $selectRemoteDown); -$table->size[10] = '9%'; +$table->head[12] = __('Remote').ui_get_sorting_arrows($url_up_remote, $url_down_remote, $selectRemoteUp, $selectRemoteDown); +$table->size[12] = '9%'; $table->head[2] = __('OS').ui_get_sorting_arrows($url_up_os, $url_down_os, $selectOsUp, $selectOsDown); $table->size[2] = '8%'; $table->head[3] = __('Interval').ui_get_sorting_arrows($url_up_interval, $url_down_interval, $selectIntervalUp, $selectIntervalDown); -$table->size[3] = '10%'; +$table->size[3] = '8%'; $table->head[4] = __('Group').ui_get_sorting_arrows($url_up_group, $url_down_group, $selectGroupUp, $selectGroupDown); $table->size[4] = '8%'; @@ -767,7 +1023,13 @@ $table->head[8] = __('Alerts'); $table->size[8] = '4%'; $table->head[9] = __('Last contact').ui_get_sorting_arrows($url_up_last, $url_down_last, $selectLastContactUp, $selectLastContactDown); -$table->size[9] = '15%'; +$table->size[9] = '8%'; + +$table->head[10] = __('Last status change').ui_get_sorting_arrows($url_up_last_status_change, $url_down_last_status_change, $selectLastStatusChangeUp, $selectLastStatusChangeDown); +$table->size[10] = '10%'; + +$table->head[11] = __('Agent events'); +$table->size[11] = '4%'; $table->align = []; @@ -779,6 +1041,8 @@ $table->align[6] = 'left'; $table->align[7] = 'left'; $table->align[8] = 'left'; $table->align[9] = 'left'; +$table->align[10] = 'left'; +$table->align[11] = 'left'; $table->style = []; @@ -881,12 +1145,12 @@ foreach ($agents as $agent) { $data[1] = ''.ui_print_truncate_text($agent['description'], 'description', false, true, true, '[…]').''; - $data[10] = ''; + $data[12] = ''; if (enterprise_installed()) { enterprise_include_once('include/functions_config_agents.php'); if (enterprise_hook('config_agents_has_remote_configuration', [$agent['id_agente']])) { - $data[10] = '
'.html_print_image( + $data[12] = ''.html_print_image( 'images/application_edit.png', true, [ @@ -930,6 +1194,27 @@ foreach ($agents as $agent) { $data[9] = agents_get_interval_status($agent); + $last_status_change_agent = agents_get_last_status_change($agent['id_agente']); + $time_elapsed = !empty($last_status_change_agent) ? human_time_comparation($last_status_change_agent) : ''.__('N/A').''; + $data[10] = $time_elapsed; + + $agent_event_filter = [ + 'id_agent' => $agent['id_agente'], + 'event_view_hr' => 48, + 'status' => -1, + ]; + + $fb64 = base64_encode(json_encode($agent_event_filter)); + $data[11] = ''.html_print_image( + 'images/lightning.png', + true, + [ + 'align' => 'middle', + 'title' => __('Agent events'), + 'class' => 'invert_filter', + ] + ).''; + // This old code was returning "never" on agents without modules, BAD !! // And does not print outdated agents in red. WRONG !!!! // $data[7] = ui_print_timestamp ($agent_info["last_contact"], true); @@ -937,6 +1222,20 @@ foreach ($agents as $agent) { } if (!empty($table->data)) { + if ($order['field'] === 'last_status_change') { + $order_direction = $order['order']; + usort( + $table->data, + function ($a, $b) use ($order_direction) { + if ($order_direction === 'ASC') { + return strtotime($a[10]) > strtotime($b[10]); + } else { + return strtotime($a[10]) < strtotime($b[10]); + } + } + ); + } + html_print_table($table); ui_pagination( @@ -975,10 +1274,69 @@ if (!empty($table->data)) { echo ''; echo '
'; } + +// Load filter div for dialog. +echo ''; +echo ''; + ?>