diff --git a/extras/deploy-scripts/pandora_agent_deploy.sh b/extras/deploy-scripts/pandora_agent_deploy.sh new file mode 100644 index 0000000000..eac5a02930 --- /dev/null +++ b/extras/deploy-scripts/pandora_agent_deploy.sh @@ -0,0 +1,169 @@ +#!/bin/bash + +#export PANDORA_SERVER_IP='newdemos.artica.es' && curl -sSL http://firefly.artica.es/projects/pandora_deploy_agent.sh | bash + +# define variables +PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf +S_VERSION='2021012801' +LOGFILE="/tmp/pandora-agent-deploy-$(date +%F).log" + +# Ansi color code variables +red="\e[0;91m" +green="\e[0;92m" +bold="\e[1m" +cyan="\e[0;36m" +yellow="\e[0;33m" +reset="\e[0m" + +# Functions + +execute_cmd () { + local cmd="$1" + local msg="$2" + + echo -e "${cyan}$msg...${reset}" + $cmd &>> $LOGFILE + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [[ $3 ]] && echo "$3 " + echo "Error installing Pandora FMS Agent for detailed error please check log: $LOGFILE" + rm -rf $HOME/pandora_deploy_tmp &>> $LOGFILE + exit 1 + else + echo -e "\e[1A\e ${cyan}$msg...${reset} ${green}OK${reset}" + return 0 + fi +} + +check_cmd_status () { + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [ "$1" ] && echo "$1" + echo "Error installing Pandora FMS Agent for detailed error please check log: $LOGFILE" + rm -rf $HOME/pandora_deploy_tmp/*.rpm* &>> $LOGFILE + exit 1 + else + echo -e "${green}OK${reset}" + return 0 + fi +} + +check_repo_connection () { + execute_cmd "ping -c 2 8.8.8.8" "Checking internet connection" + execute_cmd "ping -c 2 firefly.artica.es" "Checking Community repo" +} + +check_root_permissions () { + echo -en "${cyan}Checking root account... ${reset}" + if [ "$(whoami)" != "root" ]; then + echo -e "${red}Fail${reset}" + echo "Please use a root account or sudo for installing PandoraFMS" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + exit 1 + + else + echo -e "${green}OK${reset}" + fi +} + +install_autodiscover () { + local arch=$1 + wget https://pandorafms.com/library/wp-content/uploads/2020/04/autodiscover-linux.zip + unzip autodiscover-linux.zip + chmod +x $arch/autodiscover + mv -f $arch/autodiscover /etc/pandora/plugins/autodiscover +} + +## Main +echo "Starting PandoraFMS Agent deployment ver. $S_VERSION" + +execute_cmd "[ $PANDORA_SERVER_IP ]" 'Check Server IP Address' 'Please define env variable PANDORA_SERVER_IP' + +# Check OS. +OS=$([[ $(grep '^ID_LIKE=' /etc/os-release) ]] && grep ^ID_LIKE= /etc/os-release | cut -d '=' -f2 | tr -d '"' || grep ^ID= /etc/os-release | cut -d '=' -f2 | tr -d '"') + +[[ $OS == 'rhel fedora' ]] && OS_RELEASE=$OS +[[ $OS == 'centos rhel fedora' ]] && OS_RELEASE=$OS +[[ $OS == 'debian' ]] && OS_RELEASE=$OS + +# initialice logfile +execute_cmd "echo 'Starting community deployment' > $LOGFILE" "All installer activity is logged on $LOGFILE" +echo "Community installer version: $S_VERSION" >> $LOGFILE + +# Pre checks +echo -en "${cyan}Checking compatible OS... ${reset}" +[[ $OS_RELEASE ]] +check_cmd_status "Error not compatible OS, $OS" + +# Root permisions +check_root_permissions + +# Connectivity +check_repo_connection + +# Execute tools check +execute_cmd "grep --version" 'Checking needed tools: grep' +execute_cmd "sed --version" 'Checking needed tools: sed' + +# Creating working directory +rm -rf $HOME/pandora_deploy_tmp/ &>> $LOGFILE +mkdir $HOME/pandora_deploy_tmp &>> $LOGFILE +execute_cmd "cd $HOME/pandora_deploy_tmp" "Moving to workspace: $HOME/pandora_deploy_tmp" + +# Downloading and installing packages + +if [[ $OS_RELEASE == 'rhel fedora' ]] || [[ $OS_RELEASE == 'centos rhel fedora' ]]; then + yum install -y perl wget curl perl-Sys-Syslog unzip &>> $LOGFILE + echo -e "${cyan}Instaling agent dependencies...${reset}" ${green}OK${reset} + + yum install -y http://firefly.artica.es/pandorafms/latest/RHEL_CentOS/pandorafms_agent_unix-7.0NG.noarch.rpm &>> $LOGFILE + echo -e "${cyan}Instaling Pandora FMS agent...${reset}" ${green}OK${reset} +fi + +if [[ $OS_RELEASE == 'debian' ]]; then + execute_cmd "apt update" 'Updating repos' + execute_cmd "apt install -y perl wget curl unzip procps python3 python3-pip" 'Instaling agent dependencies' + execute_cmd 'wget http://firefly.artica.es/pandorafms/latest/Debian_Ubuntu/pandorafms.agent_unix_7.0NG.deb' 'Downloading Pandora FMS agent dependencies' + execute_cmd 'apt install -y ./pandorafms.agent_unix_7.0NG.deb' 'Installing Pandora FMS agent' +fi + +# Configuring Agente + +[[ $PANDORA_SERVER_IP ]] && sed -i "s/^server_ip.*$/server_ip $PANDORA_SERVER_IP/g" $PANDORA_AGENT_CONF +[[ $PANDORA_REMOTE_CONFIG ]] && sed -i "s/^remote_config.*$/remote_config $PANDORA_REMOTE_CONFIG/g" $PANDORA_AGENT_CONF +[[ $PANDORA_GROUP ]] && sed -i "s/^group.*$/group $PANDORA_GROUP/g" $PANDORA_AGENT_CONF +[[ $PANDORA_DEBUG ]] && sed -i "s/^debug.*$/debug $PANDORA_DEBUG/g" $PANDORA_AGENT_CONF +[[ $PANDORA_AGENT_NAME ]] && sed -i "s/^#agent_name.*$/agent_name $PANDORA_AGENT_NAME/g" $PANDORA_AGENT_CONF +[[ $PANDORA_AGENT_ALIAS ]] && sed -i "s/^#agent_alias.*$/agent_alias $PANDORA_AGENT_ALIAS/g" $PANDORA_AGENT_CONF +[[ $PANDORA_SECONDARY_GROUPS ]] && sed -i "s/^# secondary_groups.*$/secondary_groups $PANDORA_SECONDARY_GROUPS/g" $PANDORA_AGENT_CONF +[[ $TIMEZONE ]] && ln -sfn /usr/share/zoneinfo/$TIMEZONE /etc/localtime + + +#installing autodiscover + +arch=$(uname -m) +case $arch in + + x86_64) + execute_cmd 'install_autodiscover x86_64' "installing service autodiscover on $arch" 'Error unable to install autodiscovery' + ;; + + x86) + execute_cmd 'install_autodiscover x84' "installing service autodiscover on $arch" 'Error unable to install autodiscovery' + ;; + + armv7l) + echo -e "${cyan}Skiping autodiscover installation arch $arch not suported${reset}" + ;; + + *) + echo -e "${yellow}Skiping autodiscover installation arch $arch not suported${reset}" + ;; +esac + +#Starting pandora agent daemon. +execute_cmd '/etc/init.d/pandora_agent_daemon restart' 'Starting Pandora Agent' +cd +execute_cmd 'rm -rf $HOME/pandora_deploy_tmp' 'Cleaning up temporay files' + +echo -e "${green}PandoraFMS Agent installed and running, sending data to: $PANDORA_SERVER_IP${reset}" \ No newline at end of file diff --git a/extras/deploy-scripts/pandora_deploy_community.sh b/extras/deploy-scripts/pandora_deploy_community.sh index aa858eec3a..5e580ef1a3 100644 --- a/extras/deploy-scripts/pandora_deploy_community.sh +++ b/extras/deploy-scripts/pandora_deploy_community.sh @@ -117,7 +117,7 @@ check_pre_pandora check_repo_connection # Systemd -execute_cmd "systemctl status" "Cheking SystemD" 'This is not a SystemD enable system, if tryng to use in a docker env plese check: https://github.com/pandorafms/pandorafms/tree/develop/extras/docker/centos8' +execute_cmd "systemctl status" "Checking SystemD" 'This is not a SystemD enable system, if tryng to use in a docker env plese check: https://github.com/pandorafms/pandorafms/tree/develop/extras/docker/centos8' # Check memomry greather or equal to 2G execute_cmd "[ $(grep MemTotal /proc/meminfo | awk '{print $2}') -ge 1700000 ]" 'Checking memory (required: 2 GB)' @@ -247,7 +247,15 @@ server_dependencies=" \ perl-Time-HiRes \ nfdump \ net-snmp-utils \ - http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/wmi-1.3.14-4.el7.art.x86_64.rpm" + perl(NetAddr::IP) \ + perl(Sys::Syslog) \ + perl(DBI) \ + perl(XML::Simple) \ + perl(Geo::IP) \ + perl(IO::Socket::INET6) \ + perl(XML::Twig) \ + http://firefly.artica.es/centos7/xprobe2-0.3-12.2.x86_64.rpm \ + http://firefly.artica.es/centos7/wmic-1.4-1.el7.x86_64.rpm" execute_cmd "yum install -y $server_dependencies" "Installing Pandora FMS Server dependencies" # SDK VMware perl dependencies @@ -262,10 +270,10 @@ vmware_dependencies=" \ execute_cmd "yum install -y $vmware_dependencies" "Installing SDK VMware perl dependencies" # Instant client Oracle -oracle_dependencier=" \ +oracle_dependencies=" \ https://download.oracle.com/otn_software/linux/instantclient/19800/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm \ https://download.oracle.com/otn_software/linux/instantclient/19800/oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm" -execute_cmd "yum install -y $vmware_dependencies" "Installing Oracle Instant client" +execute_cmd "yum install -y $oracle_dependencies" "Installing Oracle Instant client" # Disabling SELINUX and firewalld setenforce 0 @@ -475,7 +483,7 @@ net.core.optmem_max = 81920 EO_KO -execute_cmd "sysctl --system" "Applying Kernel optimization" +[ -d /dev/lxd/ ] || execute_cmd "sysctl --system" "Applying Kernel optimization" # Fix pandora_server.{log,error} permissions to allow Console check them chown pandora:apache /var/log/pandora diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index 3df511bc34..597c9ed78d 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, AIX version +# Version 7.0NG.754, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index 67e18c61ce..f198a7c1aa 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, FreeBSD Version +# Version 7.0NG.754, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index 73e4aa4cbd..ff30b36ce8 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, HP-UX Version +# Version 7.0NG.754, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 251de4f671..b9aa16de5b 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, GNU/Linux +# Version 7.0NG.754, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index 4dcd110dc4..d3708080ab 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, GNU/Linux +# Version 7.0NG.754, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index 5f86dd5a56..1fba8a8397 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, Solaris Version +# Version 7.0NG.754, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index 60d0bbde2c..a12d063a6c 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2021 Artica Soluciones Tecnologicas -# Version 7.0NG.752 +# Version 7.0NG.754 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software # Foundation; either version 2 of the Licence or any later version diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index 5bc9d9ba56..856d17a6fb 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.752, AIX version +# Version 7.0NG.754, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index 4183cef424..be65a01d17 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.752 +# Version 7.0NG.754 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index 38030783ac..35835acf1e 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.752, HPUX Version +# Version 7.0NG.754, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index bbf8fffcb6..8fc3f8471b 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752 +# Version 7.0NG.754 # Licensed under GPL license v2, # (c) 2003-2021 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index e4e21da030..cda057b32f 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752 +# Version 7.0NG.754 # Licensed under GPL license v2, # (c) 2003-2021 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index f957a45b87..3043eb809e 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752 +# Version 7.0NG.754 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index be2f3b22f3..5640ff5476 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.752, Solaris version +# Version 7.0NG.754, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 1584ce4dc2..4330b6eba4 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.752, AIX version +# Version 7.0NG.754, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 020e1465c5..76acd4b169 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.752-210324 +Version: 7.0NG.754-210511 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 a04d1c2a99..ba8ff1c9f9 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.752-210324" +pandora_version="7.0NG.754-210511" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh b/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh index f21b4f0896..79078a8725 100644 --- a/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh +++ b/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh @@ -24,7 +24,7 @@ fi if [ "$#" -ge 2 ]; then VERSION="$2" else - VERSION="7.0NG.752" + VERSION="7.0NG.754" fi # Path for the generated DMG file diff --git a/pandora_agents/unix/Darwin/dmg/extras/distribution.xml b/pandora_agents/unix/Darwin/dmg/extras/distribution.xml index 14e4b9ff7a..6f5ef34343 100644 --- a/pandora_agents/unix/Darwin/dmg/extras/distribution.xml +++ b/pandora_agents/unix/Darwin/dmg/extras/distribution.xml @@ -19,11 +19,11 @@ - pandorafms_src.pdk + pandorafms_src.pdk - pandorafms_uninstall.pdk + pandorafms_uninstall.pdk var click_on_the_file_below_to_begin = "\n"; var updating = "\n"; var package_updated_successfully = "\n"; + var package_not_updated = "\n"; var if_there_are_any_database_change = "\n"; var mr_available = "\n"; var package_available = "\n"; @@ -93,7 +94,7 @@ is not working on the metaconsole and there is no time to fix it --> var mr_available_header = "\n"; var text1_mr_file = "\n"; var text2_mr_file = "\n"; - var text3_mr_file = "\n"; + var text3_mr_file = "\n"; var language = ""; var docsUrl = (language === "es") diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 2909620e3b..6948368eb1 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -1111,7 +1111,9 @@ if ($dashboards === false) { } } +$home_screen .= ''; $layouts = visual_map_get_user_layouts($config['id_user'], true); @@ -1124,6 +1126,7 @@ if ($layouts === false) { } } +$home_screen .= ''; + $home_screen .= html_print_input_text( 'data_section', $user_info['data_section'], @@ -1664,46 +1669,64 @@ function show_data_section () { $("#text-data_section").css("display", "none"); $("#dashboard").css("display", ""); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "inline-grid"); break; case : $("#text-data_section").css("display", "none"); $("#dashboard").css("display", "none"); $("#visual_console").css("display", ""); + $("#show_vc").css("display", "inline-grid"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", "none"); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", "none"); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", "none"); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", "none"); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", ""); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", ""); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; case : $("#text-data_section").css("display", "none"); $("#dashboard").css("display", "none"); $("#visual_console").css("display", "none"); + $("#show_vc").css("display", "none"); + $("#show_db").css("display", "none"); break; } } diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 5134ad0a0b..fee1a325c4 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -233,8 +233,7 @@ if (defined('METACONSOLE')) { $disable_user = get_parameter('disable_user', false); - -if (isset($_GET['user_del'])) { +if ((bool) get_parameter('user_del', false) === true) { // delete user $id_user = get_parameter('delete_user', 0); // Only allow delete user if is not the actual user @@ -260,21 +259,21 @@ if (isset($_GET['user_del'])) { if (defined('METACONSOLE') && isset($_GET['delete_all'])) { $servers = metaconsole_get_servers(); foreach ($servers as $server) { - // Connect to the remote console - metaconsole_connect($server); + // Connect to the remote console. + if (metaconsole_connect($server) === NOERR) { + // Delete the user + $result = delete_user($id_user); + if ($result) { + db_pandora_audit( + 'User management', + __('Deleted user %s from metaconsole', io_safe_input($id_user)) + ); + } - // Delete the user - $result = delete_user($id_user); - if ($result) { - db_pandora_audit( - 'User management', - __('Deleted user %s from metaconsole', io_safe_input($id_user)) - ); + // Restore the db connection. + metaconsole_restore_db(); } - // Restore the db connection - metaconsole_restore_db(); - // Log to the metaconsole too if ($result) { db_pandora_audit( @@ -312,13 +311,13 @@ if (isset($_GET['user_del'])) { $result = false; } - if ($disable_user == 1) { + if ($disable_user === 1) { ui_print_result_message( $result, __('Successfully disabled'), __('There was a problem disabling user') ); - } else { + } else if ($disable_user === 0) { ui_print_result_message( $result, __('Successfully enabled'), @@ -440,17 +439,21 @@ if (!defined('METACONSOLE')) { $table->valign[6] = 'top'; } -$group_um = users_get_groups_UM($config['id_user']); - $info1 = []; $user_is_admin = users_is_admin(); -// Is admin or has group permissions all. -if ($user_is_admin || isset($group_um[0])) { + +if ($user_is_admin) { $info1 = get_users($order); } else { - foreach ($group_um as $group => $value) { - $info1 = array_merge($info1, users_get_users_by_group($group, $value)); + $group_um = users_get_groups_UM($config['id_user']); + // 0 is the group 'all'. + if (isset($group_um[0])) { + $info1 = get_users($order); + } else { + foreach ($group_um as $group => $value) { + $info1 = array_merge($info1, users_get_users_by_group($group, $value)); + } } } @@ -558,7 +561,7 @@ foreach ($info as $user_id => $user_info) { $iterator++; if ($user_is_admin || $config['id_user'] == $user_info['id_user'] || (!$user_info['is_admin'] && (!isset($user_info['edit']) || isset($group_um[0]) || (isset($user_info['edit']) && $user_info['edit'])))) { - $data[0] = ''.$user_id.''; + $data[0] = ''.$user_id.''; } else { $data[0] = $user_id; } @@ -591,10 +594,10 @@ foreach ($info as $user_id => $user_info) { $data[4] .= '
'; foreach ($user_profiles as $row) { if ($total_profile <= 5) { - $data[4] .= "
"; + $data[4] .= "
"; $data[4] .= profile_get_name($row['id_perfil']); $data[4] .= ' /
'; - $data[4] .= "
"; + $data[4] .= "
"; $data[4] .= groups_get_name($row['id_grupo'], true); $data[4] .= '
'; @@ -638,19 +641,126 @@ foreach ($info as $user_id => $user_info) { $table->cellclass[][6] = 'action_buttons'; $data[6] = ''; if ($user_is_admin || $config['id_user'] == $user_info['id_user'] || isset($group_um[0]) || (!$user_info['is_admin'] && (!isset($user_info['edit']) || (isset($user_info['edit']) && $user_info['edit'])))) { - if (!isset($user_info['not_delete'])) { + // Disable / Enable user. + if (isset($user_info['not_delete']) === false) { if ($user_info['disabled'] == 0) { - $data[6] = ''.html_print_image('images/lightbulb.png', true, ['title' => __('Disable'), 'class' => 'invert_filter']).''; + $toDoString = __('Disable'); + $toDoAction = '1'; + $toDoImage = 'images/lightbulb.png'; } else { - $data[6] = ''.html_print_image('images/lightbulb_off.png', true, ['title' => __('Enable')]).''; + $toDoString = __('Enable'); + $toDoAction = '0'; + $toDoImage = 'images/lightbulb_off.png'; } + + $data[6] = '
'; + $data[6] .= html_print_input_hidden( + 'id', + $user_info['id_user'], + true + ); + $data[6] .= html_print_input_hidden( + 'disable_user', + $toDoAction, + true + ); + $data[6] .= html_print_input_image( + 'submit_disable_enable', + $toDoImage, + '', + '', + true, + [ + 'data-title' => $toDoString, + 'data-use_title_for_force_title' => '1', + 'class' => 'forced_title no-padding', + ] + ); + $data[6] .= '
'; } - $data[6] .= ''.html_print_image('images/config.png', true, ['title' => __('Edit'), 'class' => 'invert_filter']).''; - if ($config['admin_can_delete_user'] && $user_info['id_user'] != $config['id_user'] && !isset($user_info['not_delete'])) { - $data[6] .= "".html_print_image('images/cross.png', true, ['class' => 'invert_filter', 'title' => __('Delete'), 'onclick' => "if (! confirm ('".__('Deleting User').' '.$user_info['id_user'].'. '.__('Are you sure?')."')) return false"]).''; - if (defined('METACONSOLE')) { - $data[6] .= "".html_print_image('images/cross_double.png', true, ['class' => 'invert_filter', 'title' => __('Delete from all consoles'), 'onclick' => "if (! confirm ('".__('Deleting User %s from all consoles', $user_info['id_user']).'. '.__('Are you sure?')."')) return false"]).''; + // Edit user. + $data[6] .= '
'; + $data[6] .= html_print_input_hidden( + 'id_user', + $user_info['id_user'], + true + ); + $data[6] .= html_print_input_hidden( + 'edit_user', + '1', + true + ); + $data[6] .= html_print_input_image( + 'submit_edit_user', + 'images/config.png', + '', + 'padding:0', + true, + [ + 'data-title' => __('Edit'), + 'data-use_title_for_force_title' => '1', + 'class' => 'forced_title no-padding', + ] + ); + $data[6] .= '
'; + + if ($config['admin_can_delete_user'] && $user_info['id_user'] != $config['id_user'] && isset($user_info['not_delete']) === false) { + $data[6] .= '
'; + $data[6] .= html_print_input_hidden( + 'delete_user', + $user_info['id_user'], + true + ); + $data[6] .= html_print_input_hidden( + 'user_del', + '1', + true + ); + $data[6] .= html_print_input_image( + 'submit_delete_user', + 'images/cross.png', + '', + 'padding:0', + true, + [ + 'data-title' => __('Delete'), + 'data-use_title_for_force_title' => '1', + 'class' => 'forced_title no-padding', + ] + ); + $data[6] .= '
'; + + if (is_metaconsole() === true) { + $data[6] .= '
'; + $data[6] .= html_print_input_hidden( + 'delete_user', + $user_info['id_user'], + true + ); + $data[6] .= html_print_input_hidden( + 'user_del', + '1', + true + ); + $data[6] .= html_print_input_hidden( + 'delete_all', + '1', + true + ); + $data[6] .= html_print_input_image( + 'submit_delete_all', + 'images/cross_double.png', + '', + '', + true, + [ + 'data-title' => __('Delete from all consoles'), + 'data-use_title_for_force_title' => '1', + 'class' => 'forced_title no-padding', + ] + ); + $data[6] .= '
'; } } else { $data[6] .= ''; diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 4a919b2653..65eeb50d1a 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -515,19 +515,21 @@ class DiscoveryTaskList extends HTML } // Task name. - $table->headstyle[1] .= 'min-width: 150px; width: 300px;'; + $table->headstyle[1] .= 'min-width: 170px; width: 300px;'; + // Server Name. + $table->headstyle[2] .= 'min-width: 130px; width: 400px;'; // Name. - $table->headstyle[4] .= 'min-width: 100px; width: 400px;'; + $table->headstyle[4] .= 'min-width: 100px; width: 350px;'; // Status. - $table->headstyle[5] .= 'min-width: 50px; width: 100px;'; + $table->headstyle[5] .= 'min-width: 70px; width: 190px;'; // Task type. - $table->headstyle[6] .= 'min-width: 200px; width: 200px;'; + $table->headstyle[6] .= 'min-width: 190px; width: 200px;'; // Progress. - $table->headstyle[7] .= 'min-width: 50px; width: 150px;'; + $table->headstyle[7] .= 'min-width: 60px; width: 150px;'; // Updated at. $table->headstyle[8] .= 'min-width: 50px; width: 150px;'; // Operations. - $table->headstyle[9] .= 'min-width: 150px; width: 150px;'; + $table->headstyle[9] .= 'min-width: 150px; width: 250px;'; if (check_acl($config['id_user'], 0, 'AW')) { $table->head[0] = __('Force'); @@ -711,6 +713,19 @@ class DiscoveryTaskList extends HTML $data[6] .= __('Discovery.Cloud.Aws.RDS'); break; + case DISCOVERY_CLOUD_AWS_S3: + // Discovery Cloud S3. + $data[6] = html_print_image( + 'images/op_network.png', + true, + [ + 'title' => __('Discovery Cloud S3'), + 'class' => 'invert_filter', + ] + ).'  '; + $data[6] .= __('Discovery.Cloud.Aws.S3'); + break; + case DISCOVERY_APP_MYSQL: // Discovery Applications MySQL. $data[6] = html_print_image( @@ -850,7 +865,7 @@ class DiscoveryTaskList extends HTML $data[9] .= ''; $data[9] .= html_print_image( - 'images/eye.png', + 'images/operation.png', true, [ 'title' => __('View summary'), @@ -866,6 +881,7 @@ class DiscoveryTaskList extends HTML && $task['type'] != DISCOVERY_APP_DB2 && $task['type'] != DISCOVERY_APP_SAP && $task['type'] != DISCOVERY_CLOUD_AWS_RDS + && $task['type'] != DISCOVERY_CLOUD_AWS_S3 ) { if (check_acl($config['id_user'], 0, 'MR')) { $data[9] .= ''; @@ -1022,7 +1038,9 @@ class DiscoveryTaskList extends HTML */ public function getTargetWiz($task, $script=false) { - if ($script !== false) { + if ($script !== false + || (int) $task['type'] === DISCOVERY_HOSTDEVICES_CUSTOM + ) { switch ($script['type']) { case DISCOVERY_SCRIPT_APP_VMWARE: return 'wiz=app&mode=vmware&page=0'; @@ -1042,6 +1060,9 @@ class DiscoveryTaskList extends HTML case DISCOVERY_CLOUD_AZURE_COMPUTE: return 'wiz=cloud&mode=azure&ki='.$task['auth_strings'].'&sub=compute&page=0'; + case DISCOVERY_CLOUD_AWS_S3: + return 'wiz=cloud&mode=amazonws&ki='.$task['auth_strings'].'&sub=s3&page=0'; + default: return 'wiz=cloud'; } @@ -1489,6 +1510,9 @@ class DiscoveryTaskList extends HTML $simple_data[] = $tmp; if (is_array($data['modules'])) { + // Alphabetically sort. + ksort($data['modules'], (SORT_STRING | SORT_FLAG_CASE)); + $simple_data = array_merge( $simple_data, array_reduce( diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 892556f3fb..f2819b4e74 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -809,7 +809,7 @@ class HostDevices extends Wizard 'name' => 'interval_manual_defined', 'return' => true, ], - 'extra' => '
'.ui_print_help_tip( + 'extra' => '
'.ui_print_help_tip( __('The minimum recomended interval for Recon Task is 5 minutes'), true ).html_print_extended_select_for_time( @@ -898,7 +898,7 @@ class HostDevices extends Wizard ], [ 'label' => ''.__('Networks (current)').':'.ui_print_help_tip( - __('Plese upload a new file to overwrite this content.'), + __('Please upload a new file to overwrite this content.'), true ), 'arguments' => [ diff --git a/pandora_console/images/visual_console.menu.png b/pandora_console/images/visual_console.menu.png new file mode 100644 index 0000000000..818beae6f2 Binary files /dev/null and b/pandora_console/images/visual_console.menu.png differ diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 9476b41718..b49a884832 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -257,6 +257,11 @@ if ($save_event_filter) { $values['id_extra'] = get_parameter('id_extra'); $values['user_comment'] = get_parameter('user_comment'); $values['id_source_event'] = get_parameter('id_source_event'); + + if (is_metaconsole()) { + $values['server_id'] = get_parameter('server_id'); + } + $exists = (bool) db_get_value_filter( 'id_filter', 'tevent_filter', @@ -305,6 +310,10 @@ if ($update_event_filter) { $values['user_comment'] = get_parameter('user_comment'); $values['id_source_event'] = get_parameter('id_source_event'); + if (is_metaconsole()) { + $values['server_id'] = get_parameter('server_id'); + } + if (io_safe_output($values['tag_with']) == '["0"]') { $values['tag_with'] = '[]'; } @@ -371,6 +380,13 @@ if ($get_filter_values) { } } + if (is_metaconsole()) { + $server_name = db_get_value('server_name', 'tmetaconsole_setup', 'id', $event_filter['server_id']); + if ($server_name !== false) { + $event_filter['server_name'] = $server_name; + } + } + $event_filter['module_search'] = io_safe_output(db_get_value_filter('nombre', 'tagente_modulo', ['id_agente_modulo' => $event_filter['id_agent_module']])); } @@ -402,6 +418,8 @@ if ($load_filter_modal) { ); echo '
'; + echo '
'; + $table = new StdClass; $table->id = 'load_filter_form'; $table->width = '100%'; @@ -441,13 +459,15 @@ if ($load_filter_modal) { __('Load filter'), 'load_filter', false, - 'class="sub upd" onclick="load_form_filter();"', + 'class="sub upd"', true ); + $data[1] .= html_print_input_hidden('load_filter', 1, true); $table->data[] = $data; $table->rowclass[] = ''; html_print_table($table); + echo '
'; echo '
'; ?> '; $output .= ''; + $output .= ''; + if (isset($this->map['__simulated']) === false) { // Load context menu if manageable networkmap. - $output .= ''; + $output .= ''; } - $output .= ''; + $output .= ''; // Open networkconsole_id div. $output .= '
__('Tactical View'), 'icon' => ui_get_full_url( - 'images/op_monitoring.menu_gray.png' + 'images/menu/op_monitoring.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=view&sec2=operation/agentes/tactical' @@ -122,7 +122,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Agent Management'), 'icon' => ui_get_full_url( - 'images/gm_resources.menu_gray.png' + 'images/menu/gm_resources.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente' @@ -140,7 +140,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('General Setup'), 'icon' => ui_get_full_url( - 'images/gm_setup.menu_gray.png' + 'images/menu/gm_setup.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=general&sec2=godmode/setup/setup§ion=general' @@ -156,7 +156,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Manage Policies'), 'icon' => ui_get_full_url( - 'images/gm_configuration.menu_gray.png' + 'images/menu/gm_configuration.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=gmodules&sec2=enterprise/godmode/policies/policies' @@ -170,7 +170,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('List Alerts'), 'icon' => ui_get_full_url( - 'images/gm_alerts.menu_gray.png' + 'images/menu/gm_alerts.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=galertas&sec2=godmode/alerts/alert_list' @@ -194,7 +194,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('View Events'), 'icon' => ui_get_full_url( - 'images/op_events.menu_gray.png' + 'images/menu/op_events.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=eventos&sec2=operation/events/events' @@ -218,7 +218,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Dashboard'), 'icon' => ui_get_full_url( - 'images/op_reporting.menu_gray.png' + 'images/menu/op_reporting.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=reporting&sec2=operation/dashboard/dashboard' @@ -232,7 +232,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Visual Console'), 'icon' => ui_get_full_url( - 'images/op_network.menu_gray.png' + 'images/menu/op_network.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=network&sec2=godmode/reporting/map_builder' @@ -246,7 +246,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Manage Servers'), 'icon' => ui_get_full_url( - 'images/gm_servers.menu_gray.png' + 'images/menu/gm_servers.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server' @@ -260,7 +260,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Edit User'), 'icon' => ui_get_full_url( - 'images/gm_users.menu_gray.png' + 'images/menu/gm_users.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=workspace&sec2=operation/users/user_edit' @@ -270,7 +270,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Tree View'), 'icon' => ui_get_full_url( - 'images/op_monitoring.menu_gray.png' + 'images/menu/op_monitoring.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=view&sec2=operation/tree' @@ -280,7 +280,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Network Component'), 'icon' => ui_get_full_url( - 'images/gm_configuration.menu_gray.png' + 'images/menu/gm_configuration.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=gmodules&sec2=godmode/modules/manage_network_components' @@ -294,7 +294,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Task List'), 'icon' => ui_get_full_url( - 'images/gm_discovery.menu.png' + 'images/menu/gm_discovery.menu.png' ), 'url' => ui_get_full_url( 'index.php?sec=discovery&sec2=godmode/servers/discovery&wiz=tasklist' @@ -338,7 +338,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Update Manager'), 'icon' => ui_get_full_url( - 'images/um_messages.menu_gray.png' + 'images/menu/um_messages.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=setup' @@ -352,7 +352,7 @@ class OrderInterpreter extends Wizard [ 'name' => __('Manage Agent Groups'), 'icon' => ui_get_full_url( - 'images/gm_users.menu_gray.png' + 'images/menu/gm_users.menu_gray.png' ), 'url' => ui_get_full_url( 'index.php?sec=gagente&sec2=godmode/groups/group_list&tab=groups' diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 70fb1d4e60..dc0dca6df4 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -1,15 +1,30 @@ getAgentSearchFilter(); $agent_status_filter = $this->getAgentStatusFilter(); $module_search_filter = $this->getModuleSearchFilter(); - $module_status_filter = $this->getModuleStatusFilter(); + $module_status_filter = $this->getModuleStatusFilterFromTestado($this->filter['statusModule']); $condition = $this->L2condition; $condition_inside = $this->L2conditionInside; diff --git a/pandora_console/include/class/TreeGroup.class.php b/pandora_console/include/class/TreeGroup.class.php index 53d7f510f6..4b94cf8405 100644 --- a/pandora_console/include/class/TreeGroup.class.php +++ b/pandora_console/include/class/TreeGroup.class.php @@ -1,32 +1,86 @@ L1fieldName = 'id_group'; $this->L1extraFields = [ @@ -42,18 +96,37 @@ class TreeGroup extends Tree } + /** + * Setter propagate counters. + * + * @param boolean $value True or ffalse. + * + * @return void + */ public function setPropagateCounters($value) { $this->propagateCounters = (bool) $value; } + /** + * Setter all groups. + * + * @param boolean $value True or ffalse. + * + * @return void + */ public function setDisplayAllGroups($value) { $this->displayAllGroups = (bool) $value; } + /** + * Get data. + * + * @return void + */ protected function getData() { if ($this->id == -1) { @@ -66,22 +139,36 @@ class TreeGroup extends Tree } + /** + * Filter search groups. + * + * @return string + */ protected function getGroupSearchFilter() { return ''; } + /** + * First level tree. + * + * @return void + */ protected function getFirstLevel() { $processed_items = $this->getProcessedGroups(); - if (!empty($processed_items)) { - // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants - if (!empty($this->filter['searchGroup'])) { - // Save the groups which intersect with the user groups - $groups = db_get_all_rows_filter('tgrupo', ['nombre' => '%'.$this->filter['searchGroup'].'%']); - if ($groups == false) { + if (empty($processed_items) === false) { + // Filter by group name. This should be done after rerieving + // the items cause we need the possible items descendants. + if (empty($this->filter['searchGroup']) === false) { + // Save the groups which intersect with the user groups. + $groups = db_get_all_rows_filter( + 'tgrupo', + ['nombre' => '%'.$this->filter['searchGroup'].'%'] + ); + if ($groups === false) { $groups = []; } @@ -90,7 +177,7 @@ class TreeGroup extends Tree $groups, function ($userGroups, $group) use ($userGroupsACL) { $group_id = $group['id_grupo']; - if (isset($userGroupsACL[$group_id])) { + if (isset($userGroupsACL[$group_id]) === true) { $userGroups[$group_id] = $userGroupsACL[$group_id]; } @@ -99,14 +186,22 @@ class TreeGroup extends Tree [] ); - $result = self::extractGroupsWithIDs($processed_items, $ids_hash); + $result = self::extractGroupsWithIDs( + $processed_items, + $ids_hash + ); $processed_items = ($result === false) ? [] : $result; } - // groupID filter. To access the view from tactical views f.e. - if (!empty($this->filter['groupID'])) { - $result = self::extractItemWithID($processed_items, $this->filter['groupID'], 'group', $this->strictACL); + // GroupID filter. To access the view from tactical views f.e. + if (empty($this->filter['groupID']) === false) { + $result = self::extractItemWithID( + $processed_items, + $this->filter['groupID'], + 'group', + $this->strictACL + ); $processed_items = ($result === false) ? [] : [$result]; } @@ -116,56 +211,64 @@ class TreeGroup extends Tree } + /** + * Process group + * + * @return mixed + */ protected function getProcessedGroups() { $processed_groups = []; - // Index and process the groups + // Index and process the groups. $groups = $this->getGroupCounters(); // If user have not permissions in parent, set parent node to 0 (all) - // Avoid to do foreach for admins - if (!users_can_manage_group_all('AR')) { + // Avoid to do foreach for admins. + if (users_can_manage_group_all('AR') === false) { foreach ($groups as $id => $group) { - if (!isset($this->userGroups[$groups[$id]['parent']])) { + if (isset($this->userGroups[$groups[$id]['parent']]) === false) { $groups[$id]['parent'] = 0; } } } - // Build the group hierarchy + // Build the group hierarchy. foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + if (isset($groups[$id]['parent']) === true + && ($groups[$id]['parent'] != 0) + ) { $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { + // Parent exists. + if (isset($groups[$parent]['children']) === false) { $groups[$parent]['children'] = []; } - // Store a reference to the group into the parent + // Store a reference to the group into the parent. $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent + // This group was introduced into a parent. $groups[$id]['have_parent'] = true; } } - // Sort the children groups + // Sort the children groups. foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { + if (isset($groups[$id]['children']) === true) { usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); } } - // Filter groups and eliminates the reference to children groups out of her parent + // Filter groups and eliminates the reference to + // children groups out of her parent. $groups = array_filter( $groups, function ($group) { return !$group['have_parent']; } ); - // Propagate child counters to her parents - if ($this->propagateCounters) { + // Propagate child counters to her parents. + if ($this->propagateCounters === true) { self::processCounters($groups); - // Filter groups and eliminates the reference to empty groups + // Filter groups and eliminates the reference to empty groups. $groups = $this->deleteEmptyGroups($groups); } else { $groups = $this->deleteEmptyGroupsNotPropagate($groups); diff --git a/pandora_console/include/class/TreeGroupEdition.class.php b/pandora_console/include/class/TreeGroupEdition.class.php index f9be10ebaf..490a682865 100644 --- a/pandora_console/include/class/TreeGroupEdition.class.php +++ b/pandora_console/include/class/TreeGroupEdition.class.php @@ -1,31 +1,81 @@ id == -1) { @@ -34,46 +84,54 @@ class TreeGroupEdition extends TreeGroup } + /** + * Get process group. + * + * @return mixed + */ protected function getProcessedGroups() { $processed_groups = []; - // Index and process the groups + // Index and process the groups. $groups = $this->getGroupCounters(); // If user have not permissions in parent, set parent node to 0 (all) - // Avoid to do foreach for admins - if (!users_can_manage_group_all('AR')) { + // Avoid to do foreach for admins. + if (users_can_manage_group_all('AR') === false) { foreach ($groups as $id => $group) { - if (!isset($this->userGroups[$groups[$id]['parent']])) { + if (isset($this->userGroups[$groups[$id]['parent']]) === false) { $groups[$id]['parent'] = 0; } } } - // Build the group hierarchy + // Build the group hierarchy. foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + if (isset($groups[$id]['parent']) === true + && ($groups[$id]['parent'] != 0) + ) { $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { + // Parent exists. + if (isset($groups[$parent]['children']) === false) { $groups[$parent]['children'] = []; } - // Store a reference to the group into the parent + // Store a reference to the group into the parent. $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent + // This group was introduced into a parent. $groups[$id]['have_parent'] = true; } } - // Sort the children groups + // Sort the children groups. foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { + if (isset($groups[$id]['children']) === true) { usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); } } - // Filter groups and eliminates the reference to children groups out of her parent + // Filter groups and eliminates the reference + // to children groups out of her parent. $groups = array_filter( $groups, function ($group) { @@ -81,11 +139,25 @@ class TreeGroupEdition extends TreeGroup } ); + // Filter groups that user has permission. + $groups = array_filter( + $groups, + function ($group) { + global $config; + return check_acl($config['id_user'], $group['id'], 'AR'); + } + ); + usort($groups, ['Tree', 'cmpSortNames']); return $groups; } + /** + * Get group counters. + * + * @return mixed + */ protected function getGroupCounters() { $messages = [ @@ -93,10 +165,25 @@ class TreeGroupEdition extends TreeGroup 'cancel' => __('Cancel'), 'messg' => __('Are you sure?'), ]; - $sql = 'SELECT id_grupo AS gid, - nombre as name, parent, icon + + $group_acl = ''; + if (users_can_manage_group_all('AR') === false) { + $user_groups_str = implode(',', $this->userGroupsArray); + $group_acl = sprintf( + 'AND id_grupo IN (%s)', + $user_groups_str + ); + } + + $sql = sprintf( + 'SELECT id_grupo AS gid, + nombre as name, + parent, + icon FROM tgrupo - '; + WHERE 1=1 %s', + $group_acl + ); $stats = db_get_all_rows_sql($sql); $group_stats = []; @@ -107,7 +194,9 @@ class TreeGroupEdition extends TreeGroup $group_stats[$group['gid']]['id'] = $group['gid']; $group_stats[$group['gid']]['type'] = 'group'; - $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + $group_stats[$group['gid']] = $this->getProcessedItem( + $group_stats[$group['gid']] + ); $group_stats[$group['gid']]['delete']['messages'] = $messages; $group_stats[$group['gid']]['edit'] = 1; $group_stats[$group['gid']]['alerts'] = ''; diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 40cfe78ae0..1cd5f34cd9 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,8 +20,8 @@ /** * Pandora build version and version */ -$build_version = 'PC210324'; -$pandora_version = 'v7.0NG.752'; +$build_version = 'PC210511'; +$pandora_version = 'v7.0NG.754'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); @@ -97,7 +97,7 @@ require_once $ownDir.'functions.php'; // We need a timezone BEFORE calling config_process_config. // If not we will get ugly warnings. Set Europe/Madrid by default // Later will be replaced by the good one. -if (!is_dir($_SERVER['DOCUMENT_ROOT'].$config['homeurl']) || !is_dir($_SERVER['DOCUMENT_ROOT'].$config['homeurl_static'])) { +if (!is_dir($config['homedir'])) { $url = explode('/', $_SERVER['REQUEST_URI']); $flag_url = 0; foreach ($url as $key => $value) { diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 19520f9791..c6c4a190e4 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -626,6 +626,7 @@ define('DISCOVERY_APP_SAP', 10); define('DISCOVERY_APP_DB2', 11); define('DISCOVERY_APP_MICROSOFT_SQL_SERVER', 12); define('DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE', 13); +define('DISCOVERY_CLOUD_AWS_S3', 14); // Force task build tmp results. define('DISCOVERY_REVIEW', 0); diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 13e59f7247..8b7c81c9f9 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1496,6 +1496,7 @@ function db_run_sql_file($location) // Undo results } + $config['db_run_sql_file_error'] = $mysqli->error; return false; } } diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index f26dc60ea5..32312238ce 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2252,12 +2252,16 @@ function check_login($output=true) return true; } } else { + include_once $config['homedir'].'/mobile/include/db.class.php'; + include_once $config['homedir'].'/mobile/include/system.class.php'; include_once $config['homedir'].'/mobile/include/user.class.php'; if (isset($_SESSION['user'])) { - $user = $_SESSION['user']; + $user = User::getInstance(); $id_user = $user->getIdUser(); if (is_user($id_user)) { + $_SESSION['id_usuario'] = $id_user; + $config['id_user'] = $id_user; return true; } } @@ -2853,7 +2857,11 @@ function can_user_access_node() { global $config; - $userinfo = get_user_info($config['id_user']); + static $userinfo; + + if ($userinfo === null) { + $userinfo = get_user_info($config['id_user']); + } if (is_metaconsole()) { return $userinfo['is_admin'] == 1 ? 1 : $userinfo['metaconsole_access_node']; diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index ceef73049d..c0f27fa0a6 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1,27 +1,38 @@ . + * @param boolean $meta_fields If true, then id_agente is returned instead id_tagente. * * @return array An array with all agents in the group or an empty array */ @@ -1096,7 +1115,8 @@ function agents_get_group_agents( $serialized=false, $separator='|', $add_alert_bulk_op=false, - $force_serialized=false + $force_serialized=false, + $meta_fields=false ) { global $config; @@ -1268,11 +1288,19 @@ function agents_get_group_agents( if (is_metaconsole()) { $table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent'; - $fields = [ - 'ta.id_tagente AS id_agente', - 'alias', - 'ta.id_tmetaconsole_setup AS id_server', - ]; + if ($meta_fields === true) { + $fields = [ + 'id_agente', + 'alias', + 'ta.id_tmetaconsole_setup AS id_server', + ]; + } else { + $fields = [ + 'ta.id_tagente AS id_agente', + 'alias', + 'ta.id_tmetaconsole_setup AS id_server', + ]; + } } else { $table_name = 'tagente LEFT JOIN tagent_secondary_group ON id_agente=id_agent'; @@ -3253,6 +3281,7 @@ function agents_get_agent_custom_field($agent_id, $custom_field_name) * @param boolean $selection Show common (false) or all modules (true). * @param boolean $return Return (false) or dump to output (true). * @param boolean $index_by_name Use module name as key. + * @param boolean $pure_return Return as retrieved from DB. * * @return array With modules or null if error. */ @@ -3261,7 +3290,8 @@ function select_modules_for_agent_group( $id_agents, $selection, $return=true, - $index_by_name=false + $index_by_name=false, + $pure_return=false ) { global $config; $agents = (empty($id_agents)) ? [] : implode(',', $id_agents); @@ -3341,6 +3371,10 @@ function select_modules_for_agent_group( return; } + if ($pure_return === true) { + return $modules; + } + $modules_array = []; foreach ($modules as $value) { if ($index_by_name) { @@ -3841,6 +3875,70 @@ function agents_get_last_status_change($id_agent) } +/** + * Checks if group allow more agents due itself limitation. + * + * @param integer $id_group Id of the group. + * @param boolean $generateEvent If true and the check fails, will generate an event. + * @param string $action Action for perform (only if generateEvent is true). + * + * @return boolean True if allow more agents. + */ +function group_allow_more_agents( + int $id_group, + bool $generateEvent=false, + string $action='create' +):bool { + global $config; + + $groupMaxAgents = (int) db_get_value('max_agents', 'tgrupo', sprintf('id_grupo = %d', $id_group)); + $groupCountAgents = (int) db_get_num_rows(sprintf('SELECT nombre FROM tagente WHERE id_grupo = "%s"', $id_group)); + + // If `max_agents` is not defined or the count of agents in the group is below of max agents allowed. + $output = ($groupMaxAgents === 0 || $groupCountAgents < $groupMaxAgents); + + if ($output === false && $generateEvent === true) { + // Get the group name. + $groupName = db_get_value( + 'nombre', + 'tgrupo', + 'id_grupo', + $id_group + ); + // New event. + $evt = new Event; + // Set parameters. + $evt->evento( + sprintf( + 'Agent cannot be %sd due to the maximum agent limit for group %s', + $action, + $groupName + ) + ); + $evt->id_grupo($id_group); + $evt->id_agente(0); + $evt->id_agentmodule(0); + $evt->id_usuario($config['id_user']); + $evt->estado(EVENT_STATUS_NEW); + $evt->event_type(EVENTS_SYSTEM); + $evt->criticity(EVENT_CRIT_WARNING); + $evt->timestamp(date('Y-m-d H:i:s')); + $evt->utimestamp(time()); + $evt->data(0); + $evt->source('agent_creation'); + // Any fields are only available in meta. + if (is_metaconsole() === true) { + $evt->id_source_event(0); + } + + // Save the event. + $evt->save(); + } + + return $output; +} + + /** * Return the list of agents for a planned downtime * @@ -3850,7 +3948,7 @@ function agents_get_last_status_change($id_agent) * * @return array */ -function get_planned_downtime_agents_list($id_downtime, $filter_cond, $id_groups_str) +function get_planned_downtime_agents_list($id_downtime, $filter_cond, $id_groups_str):array { $agents = []; diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 9e27001d15..bfa2733840 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -173,13 +173,22 @@ function alerts_get_event_status_group($idGroup, $type='alert_fired', $query='AN $idAgents = array_values($agents); } - $result = db_get_all_rows_sql( + $sql = sprintf( 'SELECT id_evento - FROM tevento - WHERE estado = 0 AND id_agente IN (0,'.implode(',', $idAgents).') '.$typeWhere.$query.' - ORDER BY id_evento DESC LIMIT 1' + FROM tevento + WHERE estado = 0 + AND id_agente IN (0, %s) + %s + %s + ORDER BY id_evento DESC + LIMIT 1', + implode(',', $idAgents), + $typeWhere, + $query ); + $result = db_get_all_rows_sql($sql); + if ($result === false) { return false; } @@ -439,10 +448,11 @@ function alerts_delete_alert_action($id_alert_action) * Clone an alert action. * * @param int Id of the original alert action + * @param int Agent group id if it wants to be changed when clone. * * @return mixed Id of the cloned action or false in case of fail. */ -function alerts_clone_alert_action($id_alert_action) +function alerts_clone_alert_action($id_alert_action, $id_group) { $id_alert_action = safe_int($id_alert_action, 1); if (empty($id_alert_action)) { @@ -455,6 +465,10 @@ function alerts_clone_alert_action($id_alert_action) return false; } + if ($id_group != '') { + $action['id_group'] = $id_group; + } + unset($action['id']); return alerts_create_alert_action($action['name'].' '.__('copy'), $action['id_alert_command'], $action); @@ -1121,10 +1135,11 @@ function alerts_get_alert_template_field3_recovery($id_alert_template) * Duplicates an alert template. * * @param int Id of an alert template. + * @param int Agent group id if it wants to be changed when duplicate. * * @return mixed Duplicates an alert template or false if something goes wrong. */ -function alerts_duplicate_alert_template($id_alert_template) +function alerts_duplicate_alert_template($id_alert_template, $id_group) { $template = alerts_get_alert_template($id_alert_template); @@ -1132,6 +1147,10 @@ function alerts_duplicate_alert_template($id_alert_template) return false; } + if ($id_group != '') { + $template['id_group'] = $id_group; + } + $name = io_safe_input(__('Copy of').' ').$template['name']; $type = $template['type']; @@ -2125,8 +2144,6 @@ function get_group_alerts( $disabled = $filter; } - $filter .= ' AND talert_template_modules.disabled = 0 '; - switch ($disabled) { case 'notfired': $filter .= ' AND times_fired = 0 AND talert_template_modules.disabled = 0'; @@ -2144,9 +2161,13 @@ function get_group_alerts( $filter .= ' AND talert_template_modules.disabled = 0'; break; - default: + case 'all': $filter .= ''; break; + + default: + $filter .= ' AND talert_template_modules.disabled = 0 '; + break; } // WHEN SELECT ALL TAGS TO FILTER ALERTS @@ -2186,8 +2207,8 @@ function get_group_alerts( WHERE 1 = 0'; } else { $subQuery = 'SELECT id_agente_modulo - FROM tagente_modulo - WHERE delete_pending = 0 + FROM tagente_modulo tam + WHERE delete_pending = 0 AND tam.disabled = 0 AND id_agente IN (SELECT id_agente FROM tagente ta LEFT JOIN tagent_secondary_group tasg @@ -2734,7 +2755,7 @@ function alerts_ui_update_or_create_actions($update=true) $al_action = alerts_get_alert_action($id); if ($al_action !== false) { if ($al_action['id_group'] == 0) { - if (! check_acl($config['id_user'], 0, 'PM')) { + if (! check_acl($config['id_user'], 0, 'PM') && ! check_acl($config['id_user'], 0, 'LM')) { db_pandora_audit( 'ACL Violation', 'Trying to access Alert Management' diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index aebef6c06b..a39d9da92a 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -43,11 +43,12 @@ use PandoraFMS\Enterprise\Cluster; /** * Parse the "other" parameter. * - * @param string $other - * @param mixed $otherType + * @param string $other + * @param mixed $otherType + * @param boolean $rawDecode Decode string in which the sequences with percent (%) signs followed by two hex digits have been replaced with literal characters. * @return mixed */ -function parseOtherParameter($other, $otherType) +function parseOtherParameter($other, $otherType, $rawDecode) { switch ($otherType) { case 'url_encode': @@ -65,12 +66,12 @@ function parseOtherParameter($other, $otherType) 'data' => explode($separator, $other), ]; foreach ($returnVar['data'] as $index => $element) { - $returnVar['data'][$index] = urldecode($element); + $returnVar['data'][$index] = $rawDecode ? rawurldecode($element) : urldecode($element); } } else { $returnVar = [ 'type' => 'string', - 'data' => urldecode($other), + 'data' => $rawDecode ? rawurldecode($other) : urldecode($other), ]; } break; @@ -375,6 +376,103 @@ function api_get_test_event_replication_db() // -------------------------DEFINED OPERATIONS FUNCTIONS----------------- + + +/** + * Example: http://localhost/pandora_console/include/api.php?op=get&op2=license&user=admin&apipass=1234&pass=pandora&return_type=json + * Retrieve license information. + * + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param string $returnType Return type (string, json...). + * + * @return void + */ +function api_get_license($trash1, $trash2, $trash3, $returnType='json') +{ + global $config; + check_login(); + + if (! check_acl($config['id_user'], 0, 'PM')) { + returnError('forbidden', $returnType); + return; + } + + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + if ($license === ENTERPRISE_NOT_HOOK) { + // Not an enterprise environment? + if (license_free()) { + $license = 'PANDORA_FREE'; + } + + returnData( + $returnType, + [ + 'type' => 'array', + 'data' => ['license_mode' => $license], + ] + ); + return; + } + + returnData( + $returnType, + [ + 'type' => 'array', + 'data' => $license, + ] + ); + +} + + +/** + * Example: http://localhost/pandora_console/include/api.php?op=get&op2=license_remaining&user=admin&apipass=1234&pass=pandora&return_type=json + * Retrieve license status agents or modules left. + * + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param string $returnType Return type (string, json...). + * + * @return void + */ +function api_get_license_remaining( + $trash1, + $trash2, + $trash3, + $returnType='json' +) { + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + if ($license === ENTERPRISE_NOT_HOOK) { + if (license_free()) { + returnData( + $returnType, + [ + 'type' => 'integer', + 'data' => PHP_INT_MAX, + ] + ); + } else { + returnError('get-license', 'Failed to verify license.'); + } + + return; + } + + returnData( + $returnType, + [ + 'type' => 'integer', + 'data' => ($license['limit'] - $license['count_enabled']), + ] + ); +} + + function api_get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db) { $returnAllGroup = true; @@ -1381,6 +1479,12 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) return; } + // Check if group allow more agents or have limit stablished. + if (group_allow_more_agents($idGroup, true, 'update') === false) { + returnError('Agent cannot be updated due to the maximum agent limit for this group'); + return; + } + // Check selected parent if ($idParent != 0) { $parentCheck = agents_check_access_agent($idParent); @@ -1510,6 +1614,302 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) } +/** + * Update an agent by indicating a pair of field - value separated by comma. + * + * @param integer $id_agent Id (or alias) agent to upadate. + * @param boolean $use_agent_alias Use alias instead of id. + * @param array $params Pair of parameter/value separated by comma. Available fields are: + * 'alias', + * 'direccion', + * 'id_parent', + * 'id_grupo', + * 'cascade_protection', + * 'cascade_protection_module', + * 'intervalo', + * 'id_os', + * 'server_name', + * 'custom_id', + * 'modo', + * 'disabled', + * 'comentarios' + * + * eg . http://127.0.0.1/pandora_console/include/api.php?op=set&op2=update_agent_field&id=pandora&other=id_os,1|alias,pandora|direccion,192.168.10.16|id_parent,1cascade_protection,1|cascade_protection_module,1|intervalo,5||modo|3|&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora + */ +function api_set_update_agent_field($id_agent, $use_agent_alias, $params) +{ + global $config; + $return = false; + + if (defined('METACONSOLE')) { + return; + } + + if (!check_acl($config['id_user'], 0, 'AW')) { + returnError('forbidden', 'string'); + return; + } + + // Check the agent. + if ((bool) $use_agent_alias === true) { + $agents_by_alias = agents_get_agent_id_by_alias($id_agent); + if (empty($agents_by_alias) === false) { + foreach ($agents_by_alias as $agent) { + if (agents_check_access_agent($agent['id_agente'], 'AW') === true) { + $agents[] = $agent['id_agente']; + } + } + + if (empty($agents) === true) { + returnError('forbidden', 'string'); + return; + } + } else { + returnError('Alias does not match any agent.'); + return; + } + } else { + if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AW')) { + return; + } + + $agents[] = $id_agent; + } + + // Serialize the data for update. + if ($params['type'] === 'array') { + // Keys available to change. + $available_fields = [ + 'alias', + 'direccion', + 'id_parent', + 'id_grupo', + 'cascade_protection', + 'cascade_protection_module', + 'intervalo', + 'id_os', + 'server_name', + 'custom_id', + 'modo', + 'disabled', + 'comentarios', + ]; + + foreach ($params['data'] as $key_value) { + list($key, $value) = explode(',', $key_value, 2); + if (in_array($key, $available_fields) === true) { + $fields[$key] = $value; + } + } + } + + if (empty($fields) === true) { + returnError('Selected field not available. Please, select one the fields avove'); + return; + } + + // Check fields. + foreach ($fields as $field => $data) { + switch ($field) { + case 'alias': + if (empty($data)) { + returnError('No agent alias specified'); + return; + } + break; + + case 'id_grupo': + if (db_get_value_sql('SELECT FROM tgrupo WHERE id_grupo = '.$data) === false) { + returnError('The group doesn`t exist.'); + return; + } + break; + + case 'id_os': + if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$data) === false) { + returnError('The OS doesn`t exist.'); + return; + } + break; + + case 'server_name': + $server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$data.'"'); + if ($server_name === false) { + returnError('The server doesn`t exist.'); + return; + } + break; + + case 'cascade_protection': + if ($data == 1) { + if (($field['id_parent'] != 0) && (db_get_value_sql( + 'SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_agente = '.$fields['id_parent'].' AND id_agente_modulo = '.$fields['cascade_protection_module'] + ) === false) + ) { + returnError('Cascade protection is not applied because it is not a parent module'); + } + } else { + unset($fields['cascade_protection']); + } + break; + + case 'id_grupo': + // Check ACL group. + if (!check_acl($config['id_user'], $data, 'AW')) { + returnError('forbidden', 'string'); + return; + } + + if ($data == 0) { + $agent_update_error = 'The agent could not be modified. For security reasons, use a group other than 0.'; + returnError($agent_update_error); + return; + } + break; + + case 'id_parent': + $parentCheck = agents_check_access_agent($data); + if (is_null($parentCheck) === true) { + returnError('The parent agent does not exist.'); + return; + } + + if ($parentCheck === false) { + returnError('The user cannot access to parent agent.'); + return; + } + break; + + default: + // Default empty. + break; + } + } + + // Var applied in case there is more than one agent. + $return = false; + $applied = 0; + foreach ($agents as $agent) { + $values_old = db_get_row_filter( + 'tagente', + ['id_agente' => $agent], + [ + 'id_grupo', + 'disabled', + ] + ); + + $tpolicy_group_old = db_get_all_rows_sql( + 'SELECT id_policy FROM tpolicy_groups + WHERE id_group = '.$values_old['id_grupo'] + ); + + $return = db_process_sql_update( + 'tagente', + $fields, + ['id_agente' => $agent] + ); + + if ((count($agents) > 1) && $return !== 0) { + $applied += 1; + } + + if ($return && !isset($field['direccion'])) { + // register ip for this agent in 'taddress'. + agents_add_address($agent, $field['direccion']); + } + + if ($return) { + // Update config file + if (isset($field['disabled']) && $values_old['disabled'] != $field['disabled']) { + enterprise_hook( + 'config_agents_update_config_token', + [ + $agent, + 'standby', + $field['disabled'], + ] + ); + } + + if ($tpolicy_group_old) { + foreach ($tpolicy_group_old as $key => $value) { + $tpolicy_agents_old = db_get_sql( + 'SELECT * FROM tpolicy_agents + WHERE id_policy = '.$value['id_policy'].' AND id_agent = '.$agent + ); + + if ($tpolicy_agents_old) { + $result2 = db_process_sql_update( + 'tpolicy_agents', + ['pending_delete' => 1], + [ + 'id_agent' => $agent, + 'id_policy' => $value['id_policy'], + ] + ); + } + } + } + + $tpolicy_group = db_get_all_rows_sql( + 'SELECT id_policy FROM tpolicy_groups + WHERE id_group = '.$field['id_grupo'] + ); + + if ($tpolicy_group) { + foreach ($tpolicy_group as $key => $value) { + $tpolicy_agents = db_get_sql( + 'SELECT * FROM tpolicy_agents + WHERE id_policy = '.$value['id_policy'].' AND id_agent ='.$agent + ); + + if (!$tpolicy_agents) { + db_process_sql_insert( + 'tpolicy_agents', + [ + 'id_policy' => $value['id_policy'], + 'id_agent' => $agent, + ] + ); + } else { + $result3 = db_process_sql_update( + 'tpolicy_agents', + ['pending_delete' => 0], + [ + 'id_agent' => $agent, + 'id_policy' => $value['id_policy'], + ] + ); + } + } + } + } + } + + if (count($agents) > 1) { + returnData( + 'string', + [ + 'type' => 'string', + 'data' => __('Updated %d/%d agents', $applied, count($agents)), + ] + ); + } else { + returnData( + 'string', + [ + 'type' => 'string', + 'data' => __('Agent updated.'), + ] + ); + } + +} + + /** * Create a new agent, and print the id for new agent. * @@ -1578,10 +1978,12 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) // Check if agent exists (BUG WC-50518-2). if ($alias == '' && $alias_as_name === 0) { returnError('No agent alias specified'); - } else if (agents_get_agent_id($server_name)) { + } else if (agents_get_agent_id($nombre_agente)) { returnError('The agent name already exists in DB.'); } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { returnError('The group does not exist.'); + } else if (group_allow_more_agents($grupo, true, 'create') === false) { + returnError('Agent cannot be created due to the maximum agent limit for this group'); } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { returnError('The OS does not exist.'); } else if ($server_name === false) { @@ -2015,9 +2417,9 @@ function api_get_all_agents($thrash1, $thrash2, $other, $returnType) } $ag_groups = implode(',', (array) $ag_groups); - } - $where .= ' AND (id_grupo IN ('.$ag_groups.') OR id_group IN ('.$ag_groups.'))'; + $where .= ' AND (id_grupo IN ('.$ag_groups.') OR id_group IN ('.$ag_groups.'))'; + } } if (isset($other['data'][3])) { @@ -6276,6 +6678,136 @@ function api_set_delete_module_template_by_names($id, $id2, $other, $trash1) } +/** + * Validate an alert + * + * @param string $id1 Alert template name (eg. 'Warning condition') + * @param string $trash1 Do nnot use. + * @param array $other [1] id/name agent. + * [2] id/name module + * [3] Use agent/module alias. + * @param string $trash2 Do not use + * @return void + */ +function api_set_validate_alert($id1, $trash1, $other, $trash2) +{ + global $config; + + if (defined('METACONSOLE')) { + return; + } + + if (!check_acl($config['id_user'], 0, 'LW')) { + returnError('forbidden'); + return; + } + + if ($id1 === '') { + returnError( + 'error_validate_alert', + __('Error validating alert. Id_template cannot be left blank.') + ); + return; + } + + if ($other['data'][0] == '') { + returnError( + 'error_validate_alert', + __('Error validating alert. Id_agent cannot be left blank.') + ); + return; + } + + if ($other['data'][1] == '') { + returnError( + 'error_validate_alert', + __('Error validating alert. Id_module cannot be left blank.') + ); + return; + } + + if ($other['data'][2] == 1) { + $use_alias = true; + } + + $values = [ + 'alert_name' => $id1, + 'id_agent' => $other['data'][0], + 'id_agent_module' => $other['data'][1], + ]; + + if ($use_alias === true) { + $id_agents = agents_get_agent_id_by_alias($values['id_agent']); + + foreach ($id_agents as $id) { + $values['id_agent'] = $id['id_agente']; + $values['id_agent_module'] = db_get_value_filter( + 'id_agente_modulo as id_module', + 'tagente_modulo', + [ + 'id_agente' => $values['id_agent'], + 'nombre' => $values['id_agent_module'], + ] + ); + + $id_template = db_get_value_filter( + 'id as id_template', + 'talert_templates', + [ + 'name' => $values['alert_name'], + ] + ); + + // Get alert id. + $id_alert = db_get_value_filter( + 'id as id_alert', + 'talert_template_modules', + [ + 'id_agent_module' => $values['id_agent_module'], + 'id_alert_template' => $id_template, + ] + ); + } + + $result = alerts_validate_alert_agent_module($id_alert); + } else { + $id_template = db_get_value_filter( + 'id as id_template', + 'talert_templates', + [ + 'name' => $values['alert_name'], + ] + ); + + // Get alert id. + $id_alert = db_get_value_filter( + 'id as id_alert', + 'talert_template_modules', + [ + 'id_agent_module' => $values['id_agent_module'], + 'id_alert_template' => $id_template, + ] + ); + + if ($id_alert === false) { + returnError( + 'error_validate_alert', + __('Error validating alert. Specified alert does not exist.') + ); + return; + } + + $result = alerts_validate_alert_agent_module($id_alert); + } + + if ($result) { + returnData('string', ['type' => 'string', 'data' => 'Alert succesfully validated']); + } else { + returnData('string', ['type' => 'string', 'data' => __('Error validating alert')]); + } +} + + /** * Validate all alerts. And return a message with the result of the operation. * @@ -6481,7 +7013,7 @@ function api_set_stop_downtime($id, $thrash1, $other, $thrash3) $data = db_get_row_sql($sql); if ($data['type_execution'] == 'periodically' && $data['executed'] == 1) { - returnError('error_stop_downtime', __('Error stopping downtime. Periodical and running planned downtime cannot be stopped.')); + returnError('error_stop_downtime', __('Error stopping downtime. Periodical and running scheduled downtime cannot be stopped.')); return; } @@ -6967,7 +7499,7 @@ function api_set_planned_downtimes_additem($id, $thrash1, $other, $thrash3) } if (empty($agents)) { - returnError('No agents to create planned downtime items'); + returnError('No agents to create scheduled downtime items'); } else { if (!empty($returned['bad_modules'])) { $bad_modules = __("and this modules are doesn't exists or not applicable a this agents: ").implode(', ', $returned['bad_modules']); @@ -6992,114 +7524,6 @@ function api_set_planned_downtimes_additem($id, $thrash1, $other, $thrash3) } -/** - * Add data module to policy. And return id from new module. - * - * @param string $id Id of the target policy. - * @param $thrash1 Don't use. - * @param array $other it's array, $other as param is ;;; - * ;;;;;;;; - * ;;;;; - * ;;;;; - * ;; in this order - * and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) - * example: - * - * example: - * - * api.php?op=set&op2=add_data_module_policy&id=1&other=data_module_policy_example_name~2~data%20module%20created%20by%20Api~2~0~0~50.00~10~20~180~~21~35~~1~module_begin%0dmodule_name%20pandora_process%0dmodule_type%20generic_data%0dmodule_exec%20ps%20aux%20|%20grep%20pandora%20|%20wc%20-l%0dmodule_end&other_mode=url_encode_separator_~ - * - * @param $thrash3 Don't use - */ -function api_set_add_data_module_policy($id, $thrash1, $other, $thrash3) -{ - if (defined('METACONSOLE')) { - return; - } - - if ($id == '') { - returnError('The data module could not be added to policy. Id_policy cannot be left blank.'); - return; - } - - if (enterprise_hook('policies_check_user_policy', [$id]) === false) { - returnError('forbidden', 'string'); - return; - } - - if ($other['data'][0] == '') { - returnError('The data module could not be added to policy. Module_name cannot be left blank.'); - return; - } - - // Check if the module is already in the policy - $name_module_policy = enterprise_hook('policies_get_modules', [$id, ['name' => $other['data'][0]], 'name']); - - if ($name_module_policy === ENTERPRISE_NOT_HOOK) { - returnError('The data module could not be added to policy.'); - return; - } - - $disabled_types_event = []; - $disabled_types_event[EVENTS_GOING_UNKNOWN] = (int) !$other['data'][16]; - $disabled_types_event = json_encode($disabled_types_event); - - $values = []; - $values['id_tipo_modulo'] = $other['data'][1]; - $values['description'] = $other['data'][2]; - $values['id_module_group'] = $other['data'][3]; - $values['min'] = $other['data'][4]; - $values['max'] = $other['data'][5]; - $values['post_process'] = $other['data'][6]; - $values['module_interval'] = $other['data'][7]; - $values['min_warning'] = $other['data'][8]; - $values['max_warning'] = $other['data'][9]; - $values['str_warning'] = $other['data'][10]; - $values['min_critical'] = $other['data'][11]; - $values['max_critical'] = $other['data'][12]; - $values['str_critical'] = $other['data'][13]; - $values['history_data'] = $other['data'][14]; - $values['configuration_data'] = $other['data'][15]; - $values['disabled_types_event'] = $disabled_types_event; - $values['module_macros'] = $other['data'][17]; - $values['min_ff_event'] = $other['data'][18]; - $values['each_ff'] = $other['data'][19]; - $values['min_ff_event_normal'] = $other['data'][20]; - $values['min_ff_event_warning'] = $other['data'][21]; - $values['min_ff_event_critical'] = $other['data'][22]; - $values['ff_timeout'] = $other['data'][23]; - $values['ff_type'] = $other['data'][24]; - - if ($name_module_policy !== false) { - if ($name_module_policy[0]['name'] == $other['data'][0]) { - returnError( - 'The data module could not be added to policy. The module is already in the policy.' - ); - return; - } - } - - $success = enterprise_hook( - 'policies_create_module', - [ - $other['data'][0], - $id, - 1, - $values, - false, - ] - ); - - if ($success) { - // returnData('string', array('type' => 'string', 'data' => __('Data module added to policy. Is necessary to apply the policy in order to changes take effect.'))); - returnData('string', ['type' => 'string', 'data' => $success]); - } else { - returnError('The data module could not be added to policy.'); - } - -} - - /** * Update data module in policy. And return id from new module. * @@ -8283,6 +8707,8 @@ function api_set_create_group($id, $thrash1, $other, $thrash3) $values['custom_id'] = $safe_other_data[5]; $values['contact'] = $safe_other_data[6]; $values['other'] = $safe_other_data[7]; + $values['max_agents'] = $safe_other_data[8]; + $values['password'] = $safe_other_data[9]; $id_group = groups_create_group($group_name, $values); @@ -8362,7 +8788,8 @@ function api_set_update_group($id_group, $thrash2, $other, $thrash3) $disabled = $other['data'][5]; $custom_id = $other['data'][6]; $contact = $other['data'][7]; - $other = $other['data'][8]; + $otherData = $other['data'][8]; + $maxAgents = $other['data'][9]; $return = db_process_sql_update( 'tgrupo', @@ -8375,7 +8802,8 @@ function api_set_update_group($id_group, $thrash2, $other, $thrash3) 'disabled' => $disabled, 'custom_id' => $custom_id, 'contact' => $contact, - 'other' => $other, + 'other' => $otherData, + 'max_agents' => $maxAgents, ], ['id_grupo' => $id_group] ); @@ -11117,10 +11545,10 @@ function api_set_add_user_profile($id, $thrash1, $other, $thrash2) return; } - $group = $other['data'][0]; + $group = (int) $other['data'][0]; $profile = $other['data'][1]; - if (db_get_value('id_grupo', 'tgrupo', 'id_grupo', $group) === false) { + if ($group !== 0 && db_get_value('id_grupo', 'tgrupo', 'id_grupo', $group) === false) { returnError('There is not any group with the ID provided.'); return; } @@ -12423,6 +12851,7 @@ function api_set_create_tag($id, $trash1, $other, $returnType) // http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_event&id=name_event&other=2|system|3|admin|2|1|10|0|comments||Pandora||critical_inst|warning_inst|unknown_inst|other||&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora +// http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_event&id=name_event&other=textodelevento|10|2|0|admin|going_down_critical|4|&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora function api_set_create_event($id, $trash1, $other, $returnType) { global $config; diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 49ae33b20d..e118cf4d52 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -26,7 +26,12 @@ * ============================================================================ */ - // Config functions. +// Config functions. +require_once __DIR__.'/../vendor/autoload.php'; +require_once __DIR__.'/functions.php'; +enterprise_include_once('include/functions_config.php'); +use PandoraFMS\Core\DBMaintainer; +use PandoraFMS\Core\Config; /** @@ -147,6 +152,8 @@ function config_update_config() } $error_update = []; + $errors = []; + $warnings = []; $sec2 = get_parameter('sec2'); @@ -193,8 +200,20 @@ function config_update_config() $error_update[] = __('Use cert.'); } - if (!config_update_value('attachment_store', (string) get_parameter('attachment_store'))) { + $attachment_store = (string) get_parameter('attachment_store'); + if (file_exists($attachment_store) === false + || is_writable($attachment_store) === false + ) { $error_update[] = __('Attachment store'); + $error_update[] .= __( + "Path doesn't exists or is not writable" + ); + } else { + if (config_update_value('attachment_store', $attachment_store) === false) { + $error_update[] = __( + 'Attachment store.' + ); + } } if (!config_update_value('list_ACL_IPs_for_API', (string) get_parameter('list_ACL_IPs_for_API'))) { @@ -300,7 +319,7 @@ function config_update_config() } if (!config_update_value('past_planned_downtimes', get_parameter('past_planned_downtimes'))) { - $error_update[] = __('Allow create planned downtimes in the past'); + $error_update[] = __('Allow create scheduled downtimes in the past'); } if (!config_update_value('limit_parameters_massive', get_parameter('limit_parameters_massive'))) { @@ -1452,6 +1471,31 @@ function config_update_config() break; case 'hist_db': + if ($config['dbname'] == get_parameter('history_db_name') + && $config['dbport'] == get_parameter('history_db_port') + && $config['dbhost'] == io_input_password(get_parameter('history_db_host')) + ) { + // Same definition for active and historical database! + // This is a critical error. + $config['error_config_update_config']['correct'] = false; + $config['error_config_update_config']['message'] = __( + 'Active and historical database cannot be the same.' + ); + return; + } else { + if (!config_update_value('history_db_host', get_parameter('history_db_host'))) { + $error_update[] = __('Host'); + } + + if (!config_update_value('history_db_port', get_parameter('history_db_port'))) { + $error_update[] = __('Port'); + } + + if (!config_update_value('history_db_name', get_parameter('history_db_name'))) { + $error_update[] = __('Database name'); + } + } + if (!config_update_value('history_db_enabled', get_parameter('history_db_enabled'))) { $error_update[] = __('Enable history database'); } @@ -1460,18 +1504,6 @@ function config_update_config() $error_update[] = __('Enable history event'); } - if (!config_update_value('history_db_host', get_parameter('history_db_host'))) { - $error_update[] = __('Host'); - } - - if (!config_update_value('history_db_port', get_parameter('history_db_port'))) { - $error_update[] = __('Port'); - } - - if (!config_update_value('history_db_name', get_parameter('history_db_name'))) { - $error_update[] = __('Database name'); - } - if (!config_update_value('history_db_user', get_parameter('history_db_user'))) { $error_update[] = __('Database user'); } @@ -1511,6 +1543,68 @@ function config_update_config() ) { $error_update[] = __('Delay'); } + + if ((bool) $config['history_db_enabled'] === true) { + $dbm = new DBMaintainer( + [ + 'host' => $config['history_db_host'], + 'port' => $config['history_db_port'], + 'name' => $config['history_db_name'], + 'user' => $config['history_db_user'], + 'pass' => $config['history_db_pass'], + ] + ); + + // Performs several checks and installs if needed. + if ($dbm->checkDatabaseDefinition() === true + && $dbm->isInstalled() === false + ) { + // Target is ready but several tasks are pending. + $dbm->process(); + } else if ($dbm->check() !== true) { + $errors[] = $dbm->getLastError(); + } + } + + // Historical configuration tokens (stored in historical db). + if (Config::set( + 'days_purge', + get_parameter('history_dbh_purge'), + true + ) !== true + ) { + $error_update[] = __('Historical database purge'); + } + + if (Config::set( + 'history_partitions_auto', + get_parameter_switch('history_partitions_auto', 0), + true + ) !== true + ) { + $error_update[] = __('Historical database partitions'); + } + + if (Config::set( + 'event_purge', + get_parameter('history_dbh_events_purge'), + true + ) !== true + ) { + $error_update[] = __('Historical database events purge'); + } + + if (Config::set( + 'string_purge', + get_parameter('history_dbh_string_purge'), + true + ) !== true + ) { + $error_update[] = __('Historical database string purge'); + } + + // Disable history db in history db. + Config::set('history_db_enabled', 0, true); break; case 'ehorus': @@ -1563,7 +1657,11 @@ function config_update_config() $integria_hostname = (string) get_parameter('integria_hostname', $config['integria_hostname']); if (parse_url($integria_hostname, PHP_URL_SCHEME) === null) { - $integria_hostname = 'http://'.$integria_hostname; + if (empty($_SERVER['HTTPS']) === false) { + $integria_hostname = 'https://'.$integria_hostname; + } else { + $integria_hostname = 'http://'.$integria_hostname; + } } if (!config_update_value('integria_hostname', $integria_hostname)) { @@ -1685,6 +1783,14 @@ function config_update_config() $config['error_config_update_config']['correct'] = true; } + if (count($errors) > 0) { + $config['error_config_update_config']['errors'] = $errors; + } + + if (count($warnings) > 0) { + $config['error_config_update_config']['warnings'] = $warnings; + } + enterprise_include_once('include/functions_policies.php'); $enterprise = enterprise_include_once('include/functions_skins.php'); if ($enterprise !== ENTERPRISE_NOT_HOOK) { @@ -3268,6 +3374,32 @@ function config_user_set_custom_config() } } + if ((isset($userinfo['id_skin']) && $userinfo['id_skin'] !== 0)) { + if ((int) $userinfo['id_skin'] === 1) { + $config['style'] = 'pandora'; + } + + if ((int) $userinfo['id_skin'] === 2) { + $config['style'] = 'pandora_black'; + } + } + + $skin = get_parameter('skin', false); + $sec2_aux = get_parameter('sec2'); + + if ($sec2_aux != 'godmode/groups/group_list' && $skin !== false) { + $id_user_aux = get_parameter('id'); + if ($id_user_aux == $config['id_user']) { + if ((int) $skin === 1 || (int) $skin === 0) { + $config['style'] = 'pandora'; + } + + if ((int) $skin === 2) { + $config['style'] = 'pandora_black'; + } + } + } + if (defined('METACONSOLE')) { $config['metaconsole_access'] = $userinfo['metaconsole_access']; } diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index 0853b6ea6e..aebeeb7e42 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -697,6 +697,33 @@ function cron_list_table() $args = unserialize($task['args']); break; + case 'cron_task_generate_csv_log': + if ($manage_pandora) { + $data[0] = ''; + $data[0] .= html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ); + $data[0] .= ''; + } else { + $data[0] = ''; + } + + $data[1] = $task['id_usuario']; + $data[2] = db_get_value( + 'name', + 'tuser_task', + 'id', + $task['id_user_task'] + ); + $args = unserialize($task['args']); + break; + default: // Ignore. break; diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index e50d15fbb2..bab64dd5fe 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -113,7 +113,7 @@ function custom_graphs_create( * @param $returnAllGroup Wheter to return graphs of group All or not. * @param $privileges Privileges to check in user group * - * @return Custom graphs of a an user. Empty array if none. + * @return array graphs of a an user. Empty array if none. */ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=true, $privileges='RR') { @@ -133,9 +133,14 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t continue; } - $all_graph = db_get_all_rows_in_table('tgraph', 'name'); - if ($all_graph !== false) { - $all_graphs = array_merge($all_graphs, $all_graph); + $tmp_graphs = db_get_all_rows_in_table('tgraph', 'name'); + if ($tmp_graphs !== false) { + foreach ($tmp_graphs as $g) { + $g['id_tgraph'] = $g['id_graph']; + $g['id_graph'] = $connection['id'].'|'.$g['id_graph']; + $g['name'] = $g['name'].' ('.$connection['server_name'].')'; + $all_graphs[] = $g; + } } metaconsole_restore_db(); @@ -168,10 +173,15 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t $graphs[$graph['id_graph']] = $graph['name']; } else { $graphs[$graph['id_graph']] = $graph; + $id_graph = 'id_graph'; + if ((bool) is_metaconsole() === true) { + $id_graph = 'id_tgraph'; + } + $graphsCount = db_get_value_sql( 'SELECT COUNT(id_gs) FROM tgraph_source - WHERE id_graph = '.$graph['id_graph'] + WHERE id_graph = '.$graph[$id_graph] ); $graphs[$graph['id_graph']]['graphs_count'] = $graphsCount; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 1ca61fbe9b..1f838f34ba 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -712,6 +712,7 @@ function events_update_status($id_evento, $status, $filter=null, $history=false) * @param boolean $validatedEvents If true, evaluate validated events. * @param boolean $recursiveGroups If true, filtered groups and their children * will be search. + * @param boolean $nodeConnected Already connected to node (uses tevento). * * @return array Events. * @throws Exception On error. @@ -727,7 +728,8 @@ function events_get_all( $return_sql=false, $having='', $validatedEvents=false, - $recursiveGroups=true + $recursiveGroups=true, + $nodeConnected=false ) { global $config; @@ -1017,7 +1019,10 @@ function events_get_all( ); } - $table = events_get_events_table(is_metaconsole(), $history); + $table = events_get_events_table( + (is_metaconsole() && $nodeConnected === false), + $history + ); $tevento = sprintf( ' %s te', $table @@ -1028,7 +1033,7 @@ function events_get_all( $tagente_table = 'tagente'; $tagente_field = 'id_agente'; $conditionMetaconsole = ''; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $tagente_table = 'tmetaconsole_agent'; $tagente_field = 'id_tagente'; $conditionMetaconsole = ' AND ta.id_tmetaconsole_setup = te.server_id '; @@ -1075,7 +1080,7 @@ function events_get_all( ); } - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { // Id source event. if (!empty($filter['id_source_event'])) { $sql_filters[] = sprintf( @@ -1087,8 +1092,15 @@ function events_get_all( // User comment. if (!empty($filter['user_comment'])) { + // For filter field. $sql_filters[] = sprintf( ' AND lower(te.user_comment) like lower("%%%s%%") ', + io_safe_input($filter['user_comment']) + ); + + // For show comments on event details. + $sql_filters[] = sprintf( + ' OR lower(te.user_comment) like lower("%%%s%%") ', $filter['user_comment'] ); } @@ -1239,7 +1251,7 @@ function events_get_all( // Query_table. '', // Meta. - is_metaconsole(), + is_metaconsole() && $nodeConnected === false, // Childrens_ids. [], // Force_group_and_tag. @@ -1265,7 +1277,7 @@ function events_get_all( // Query_table. '', // Meta. - is_metaconsole(), + is_metaconsole() && $nodeConnected === false, // Childrens_ids. [], // Force_group_and_tag. @@ -1291,7 +1303,7 @@ function events_get_all( // Query_table. '', // Meta. - is_metaconsole(), + is_metaconsole() && $nodeConnected === false, // Childrens_ids. [], // Force_group_and_tag. @@ -1312,7 +1324,7 @@ function events_get_all( // Module search. $agentmodule_join = 'LEFT JOIN tagente_modulo am ON te.id_agentmodule = am.id_agente_modulo'; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $agentmodule_join = ''; } else if (!empty($filter['module_search'])) { $agentmodule_join = 'INNER JOIN tagente_modulo am ON te.id_agentmodule = am.id_agente_modulo'; @@ -1339,7 +1351,7 @@ function events_get_all( } $extra = ''; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $extra = ', server_id'; } @@ -1405,7 +1417,7 @@ function events_get_all( } $server_join = ''; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $server_join = ' LEFT JOIN tmetaconsole_setup ts ON ts.id = te.server_id'; if (!empty($filter['server_id'])) { @@ -3001,15 +3013,11 @@ function events_get_agent( ) { global $config; - if (!is_numeric($date)) { + if (is_numeric($date) === false) { $date = time_w_fixed_tz($date); } - if (is_metaconsole() && $events_group === false) { - $id_server = true; - } - - if (empty($date)) { + if (empty($date) === true) { $date = get_system_time(); } @@ -3144,7 +3152,7 @@ function events_get_agent( } } - if (is_metaconsole() && $id_server) { + if (is_metaconsole() === true && empty($id_server) === false) { $sql_where .= ' AND server_id = '.$id_server; } @@ -3161,7 +3169,7 @@ function events_get_agent( } else { return events_get_events_no_grouped( $sql_where, - (is_metaconsole() && $id_server) ? true : false, + (is_metaconsole() === true && empty($id_server) === false) ? true : false, $history ); } @@ -3664,22 +3672,37 @@ function events_page_responses($event, $childrens_ids=[]) ); } - $table_responses->data[] = $data; + if ((tags_checks_event_acl( + $config['id_user'], + $event['id_grupo'], + 'EM', + $event['clean_tags'], + $childrens_ids + )) || (tags_checks_event_acl( + $config['id_user'], + $event['id_grupo'], + 'EW', + $event['clean_tags'], + $childrens_ids + )) + ) { + $table_responses->data[] = $data; - // Comments. - $data = []; - $data[0] = __('Comment'); - $data[1] = ''; - $data[2] = html_print_button( - __('Add comment'), - 'comment_button', - false, - '$(\'#link_comments\').trigger(\'click\');', - 'class="sub next w70p"', - true - ); + // Comments. + $data = []; + $data[0] = __('Comment'); + $data[1] = ''; + $data[2] = html_print_button( + __('Add comment'), + 'comment_button', + false, + '$(\'#link_comments\').trigger(\'click\');', + 'class="sub next w70p"', + true + ); - $table_responses->data[] = $data; + $table_responses->data[] = $data; + } if (tags_checks_event_acl( $config['id_user'], @@ -3723,7 +3746,7 @@ function events_page_responses($event, $childrens_ids=[]) ['id_group' => $id_groups] ); - if (empty($event_responses)) { + if (empty($event_responses) || (!check_acl($config['id_user'], 0, 'EW') && !check_acl($config['id_user'], 0, 'EM'))) { $data[1] = ''.__('N/A').''; } else { $responses = []; @@ -4293,6 +4316,8 @@ function events_page_details($event, $server='') $serverstring = ''; } + $table_class = 'table_modal_alternate'; + // Details. $table_details = new stdClass; $table_details->width = '100%'; @@ -4300,7 +4325,7 @@ function events_page_details($event, $server='') $table_details->head = []; $table_details->cellspacing = 0; $table_details->cellpadding = 0; - $table_details->class = 'table_modal_alternate'; + $table_details->class = $table_class; /* * Useless switch. @@ -4329,7 +4354,7 @@ function events_page_details($event, $server='') if (!empty($agent)) { $data = []; - $data[0] = '
'.__('Name').'
'; + $data[0] = '
'.__('Name').'
'; if (can_user_access_node() && is_metaconsole() && empty($event['server_id']) === true) { $data[1] = ui_print_truncate_text( $agent['alias'], @@ -4362,12 +4387,12 @@ function events_page_details($event, $server='') $table_details->data[] = $data; $data = []; - $data[0] = '
'.__('IP Address').'
'; + $data[0] = '
'.__('IP Address').'
'; $data[1] = empty($agent['direccion']) ? ''.__('N/A').'' : $agent['direccion']; $table_details->data[] = $data; $data = []; - $data[0] = '
'.__('OS').'
'; + $data[0] = '
'.__('OS').'
'; $data[1] = ui_print_os_icon($agent['id_os'], true, true); if (!empty($agent['os_version'])) { $data[1] .= ' ('.$agent['os_version'].')'; @@ -4376,17 +4401,17 @@ function events_page_details($event, $server='') $table_details->data[] = $data; $data = []; - $data[0] = '
'.__('Last contact').'
'; + $data[0] = '
'.__('Last contact').'
'; $data[1] = ($agent['ultimo_contacto'] == '1970-01-01 00:00:00') ? ''.__('N/A').'' : ui_print_timestamp($agent['ultimo_contacto'], true); $table_details->data[] = $data; $data = []; - $data[0] = '
'.__('Last remote contact').'
'; + $data[0] = '
'.__('Last remote contact').'
'; $data[1] = ($agent['ultimo_contacto_remoto'] == '1970-01-01 00:00:00') ? ''.__('N/A').'' : date_w_fixed_tz($agent['ultimo_contacto_remoto']); $table_details->data[] = $data; $data = []; - $data[0] = '
'.__('Custom fields').'
'; + $data[0] = '
'.__('Custom fields').'
'; $data[1] = html_print_button( __('View custom fields'), 'custom_button', @@ -4418,13 +4443,13 @@ function events_page_details($event, $server='') if (!empty($module)) { // Module name. $data = []; - $data[0] = '
'.__('Name').'
'; + $data[0] = '
'.__('Name').'
'; $data[1] = $module['nombre']; $table_details->data[] = $data; // Module group. $data = []; - $data[0] = '
'.__('Module group').'
'; + $data[0] = '
'.__('Module group').'
'; $id_module_group = $module['id_module_group']; if ($id_module_group == 0) { $data[1] = __('No assigned'); @@ -4461,7 +4486,7 @@ function events_page_details($event, $server='') if ($acl_graph) { $data = []; - $data[0] = '
'.__('Graph').'
'; + $data[0] = '
'.__('Graph').'
'; $module_type = -1; if (isset($module['module_type'])) { @@ -4497,7 +4522,7 @@ function events_page_details($event, $server='') $link = "winopeng_var('".$url.'?'.$graph_params_str."','".$win_handle."', 800, 480)"; $data[1] = ''; - $data[1] .= html_print_image('images/chart_curve.png', true); + $data[1] .= html_print_image('images/chart_curve.png', true, ['class' => 'invert_filter']); $data[1] .= ''; $table_details->data[] = $data; } @@ -4510,20 +4535,26 @@ function events_page_details($event, $server='') if ($event['id_alert_am'] != 0) { $data = []; - $data[0] = '
'.__('Source').'
'; + $data[0] = '
'.__('Source').'
'; $data[1] = ''; $standby = db_get_value('standby', 'talert_template_modules', 'id', $event['id_alert_am']); if (!$standby) { $data[1] .= html_print_image( 'images/bell.png', true, - ['title' => __('Go to data overview')] + [ + 'title' => __('Go to data overview'), + 'class' => 'invert_filter', + ] ); } else { $data[1] .= html_print_image( 'images/bell_pause.png', true, - ['title' => __('Go to data overview')] + [ + 'title' => __('Go to data overview'), + 'class' => 'invert_filter', + ] ); } @@ -4542,7 +4573,7 @@ function events_page_details($event, $server='') $table_details->data[] = $data; $data = []; - $data[0] = '
'.__('Priority').'
'; + $data[0] = '
'.__('Priority').'
'; $priority_code = db_get_value('priority', 'talert_template_modules', 'id', $event['id_alert_am']); $alert_priority = get_priority_name($priority_code); @@ -5152,7 +5183,8 @@ function events_page_comments($event, $ajax=false) $childrens_ids ))) && $config['show_events_in_local'] == false || $config['event_replication'] == false ) { - $comments_form = '
'; + $event['evento'] = io_safe_output($event['evento']); + $comments_form = '
'; $comments_form .= html_print_textarea( 'comment', 3, @@ -5336,16 +5368,22 @@ function events_get_count_events_by_agent( $tagente = 'tagente'; $tevento = 'tevento'; + $field_type = 'ta.id_agente'; + if ($dbmeta === true) { + $tagente = 'tmetaconsole_agent'; + $tevento = 'tmetaconsole_event'; + $field_type = 'ta.id_tagente'; + } $sql = sprintf( - 'SELECT + 'SELECT ta.id_agente, ta.alias as agent_name, count(*) as count FROM %s te %s INNER JOIN %s ta - ON te.id_agente = ta.id_agente + ON te.id_agente = %s INNER JOIN tgrupo tg ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s)) OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s)) @@ -5354,6 +5392,7 @@ function events_get_count_events_by_agent( $tevento, events_get_secondary_groups_left_join($tevento), $tagente, + $field_type, implode(',', $id_group), implode(',', $id_group), $datelimit, @@ -5411,6 +5450,9 @@ function events_get_count_events_validated_by_user( ) { global $config; $tevento = 'tevento'; + if ($dbmeta === true) { + $tevento = 'tmetaconsole_event'; + } // Group. $tgroup_join = ''; @@ -5433,6 +5475,7 @@ function events_get_count_events_validated_by_user( ); } + $sql_filter = ''; if (!empty($filter['id_agent'])) { $sql_filter .= sprintf(' AND id_agente = %d ', $filter['id_agent']); } @@ -5607,6 +5650,9 @@ function events_get_count_events_by_criticity( global $config; $tevento = 'tevento'; + if ($dbmeta === true) { + $tevento = 'tmetaconsole_event'; + } $sql_filter = ''; $tgroup_join = ''; @@ -5794,6 +5840,9 @@ function events_get_count_events_validated( ) { global $config; $tevento = 'tevento'; + if ($dbmeta === true) { + $tevento = 'tmetaconsole_event'; + } // Group. $sql_filter = ''; diff --git a/pandora_console/include/functions_filemanager.php b/pandora_console/include/functions_filemanager.php index 1be3db5379..ce84201bf4 100644 --- a/pandora_console/include/functions_filemanager.php +++ b/pandora_console/include/functions_filemanager.php @@ -730,7 +730,7 @@ function filemanager_file_explorer( && (! is_dir($fileinfo['realpath']) || count(scandir($fileinfo['realpath'])) < 3) && (!$readOnly) ) { $data[4] .= '
'; - $data[4] .= ''; + $data[4] .= ''; $data[4] .= html_print_input_hidden('filename', $fileinfo['realpath'], true); $data[4] .= html_print_input_hidden('hash', md5($fileinfo['realpath'].$config['dbpass']), true); $data[4] .= html_print_input_hidden('delete_file', 1, true); diff --git a/pandora_console/include/functions_gis.php b/pandora_console/include/functions_gis.php index 870fa897b7..b49e788ddf 100644 --- a/pandora_console/include/functions_gis.php +++ b/pandora_console/include/functions_gis.php @@ -971,7 +971,7 @@ function gis_save_map( ] ); // Angent - if ((isset($layer['layer_agent_list'])) and (count($layer['layer_agent_list']) > 0)) { + if ((isset($layer['layer_agent_list'])) && (count($layer['layer_agent_list']) > 0)) { foreach ($layer['layer_agent_list'] as $agent) { db_process_sql_insert( 'tgis_map_layer_has_tagente', @@ -984,7 +984,7 @@ function gis_save_map( } // Group - if ((isset($layer['layer_group_list'])) and (count($layer['layer_group_list']) > 0)) { + if ((isset($layer['layer_group_list'])) && (count($layer['layer_group_list']) > 0)) { foreach ($layer['layer_group_list'] as $group) { db_process_sql_insert( 'tgis_map_layer_groups', @@ -1386,55 +1386,55 @@ function gis_validate_map_data( echo " + + + + '.html_print_image('images/pencil.png', true, ['title' => __('Edit ticket')]).''; - $view_tab['text'] = ''.html_print_image('images/operation.png', true, ['title' => __('View ticket')]).''; + $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('Edit ticket'), 'class' => 'invert_filter']).''; + $view_tab['text'] = ''.html_print_image('images/operation.png', true, ['title' => __('View ticket'), 'class' => 'invert_filter']).''; // When the current page is the View page. if (!$active_tab) { $view_tab['active'] = true; @@ -188,7 +188,7 @@ function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operati } // Build URL for API request. - $url = $api_hostname.'/integria/include/api.php'; + $url = $api_hostname.'/include/api.php'; // ob_start(); // $out = fopen('php://output', 'w'); diff --git a/pandora_console/include/functions_io.php b/pandora_console/include/functions_io.php index cad1dbf91a..d22641d4c7 100755 --- a/pandora_console/include/functions_io.php +++ b/pandora_console/include/functions_io.php @@ -590,3 +590,32 @@ function io_output_password($password) return io_safe_output($plaintext); } + + +/** + * Clean html tags symbols for prevent use JS + * + * @param string $string String for safe. + * + * @return string + */ +function io_safe_html_tags(string $string) +{ + // Must have safe output for work properly. + $string = io_safe_output($string); + if (strpos($string, '<') !== false && strpos($string, '>') !== false) { + $output = strstr($string, '<', true); + $tmpOutput = strstr($string, '<'); + $output .= strstr(substr($tmpOutput, 1), '>', true); + $tmpOutput = strstr($string, '>'); + $output .= substr($tmpOutput, 1); + // If the string still contains tags symbols. + if (strpos($string, '<') !== false && strpos($string, '>') !== false) { + $output = io_safe_html_tags($output); + } + } else { + $output = $string; + } + + return $output; +} diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 3337cb80de..442a18f61f 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -152,7 +152,6 @@ function menu_print_menu(&$menu) $first_sub_sec2 = ''; foreach ($main['sub'] as $subsec2 => $sub) { - // hd($sub, true); $count_sub++; // Init some variables. diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 9466b15aa1..0a643480f7 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1,22 +1,32 @@ = 15 - && $values['id_tipo_modulo'] <= 18) - && isset($values['tcp_send']) && ($values['tcp_send'] == 3) - && isset($values['custom_string_2']) + if (isset($values['id_tipo_modulo']) === true + && ((int) $values['id_tipo_modulo'] >= MODULE_TYPE_REMOTE_SNMP + && (int) $values['id_tipo_modulo'] <= MODULE_TYPE_REMOTE_SNMP_PROC) + && isset($values['tcp_send']) === true + && ((int) $values['tcp_send'] === 3) + && isset($values['custom_string_2']) === true ) { $values['custom_string_2'] = io_input_password( $values['custom_string_2'] ); } + // Only for Web server modules. + if (isset($values['id_tipo_modulo']) === true + && ($values['id_tipo_modulo'] >= MODULE_TYPE_WEB_ANALYSIS + && $values['id_tipo_modulo'] <= MODULE_TYPE_WEB_CONTENT_STRING) + ) { + $values['debug_content'] = io_safe_input($values['debug_content']); + } + $id_agent_module = db_process_sql_insert('tagente_modulo', $values); if ($id_agent_module === false) { @@ -646,7 +667,7 @@ function modules_create_agent_module( } $return_tag = true; - if (($tags !== false) || (empty($tags))) { + if (($tags !== false) || (empty($tags) === true)) { $return_tag = tags_insert_module_tag($id_agent_module, $tags); } @@ -659,10 +680,10 @@ function modules_create_agent_module( return ERR_DB; } - if (isset($values['id_tipo_modulo']) - && ($values['id_tipo_modulo'] == 21 - || $values['id_tipo_modulo'] == 22 - || $values['id_tipo_modulo'] == 23) + if (isset($values['id_tipo_modulo']) === true + && ((int) $values['id_tipo_modulo'] === MODULE_TYPE_ASYNC_PROC + || (int) $values['id_tipo_modulo'] === MODULE_TYPE_ASYNC_DATA + || (int) $values['id_tipo_modulo'] === MODULE_TYPE_ASYNC_STRING) ) { // Async modules start in normal status. $status = AGENT_MODULE_STATUS_NORMAL; @@ -706,8 +727,8 @@ function modules_create_agent_module( } // Update module status count if the module is not created disabled. - if (!isset($values['disabled']) || $values['disabled'] == 0) { - if ($status == 0) { + if (isset($values['disabled']) === false || (int) $values['disabled'] === 0) { + if ((int) $status === AGENT_MODULE_STATUS_NORMAL) { db_process_sql( 'UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 @@ -2307,7 +2328,10 @@ function modules_get_agentmodule_data_for_humans($module) switch ($module['id_tipo_modulo']) { case 15: $value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module['id_agente_modulo']); - if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0') { + if (($value == '.1.3.6.1.2.1.1.3.0' + || $value == '.1.3.6.1.2.1.25.1.1.0') + && modules_get_unit_macro($module['data'], $module['unit']) === true + ) { if ($module['post_process'] > 0) { $salida = human_milliseconds_to_string(($module['datos'] / $module['post_process'])); } else { @@ -2328,7 +2352,10 @@ function modules_get_agentmodule_data_for_humans($module) switch ($module['id_tipo_modulo']) { case 15: $value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module['id_agente_modulo']); - if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0') { + if (($value == '.1.3.6.1.2.1.1.3.0' + || $value == '.1.3.6.1.2.1.25.1.1.0') + && modules_get_unit_macro($module['data'], $module['unit']) === true + ) { if ($module['post_process'] > 0) { $salida = human_milliseconds_to_string(($module['datos'] / $module['post_process'])); } else { @@ -2356,7 +2383,7 @@ function modules_get_agentmodule_data_for_humans($module) } } else { $data_macro = modules_get_unit_macro($module['datos'], $module['unit']); - if ($data_macro) { + if ($data_macro !== false) { $salida = $data_macro; } else { $salida = ui_print_module_string_value( diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 64a0dbbfe3..ed76a6b880 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -31,6 +31,7 @@ require_once 'functions_agents.php'; require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_groups.php'; enterprise_include_once('include/functions_networkmap.php'); +enterprise_include_once('include/functions_metaconsole.php'); // Check if a node descends from a given node function networkmap_is_descendant($node, $ascendant, $parents) @@ -1228,7 +1229,7 @@ function networkmap_get_networkmap($id_networkmap, $filter=false, $fields=false, * @param array Extra filter. * @param array Fields to get. * - * @return Networkmap with the given id. False if not available or readable. + * @return array Networkmap with the given id. False if not available or readable. */ function networkmap_get_networkmaps( $id_user=null, @@ -1243,10 +1244,16 @@ function networkmap_get_networkmaps( $id_user = $config['id_user']; } - // Configure filters + // Configure filters. $where = []; $where['type'] = MAP_TYPE_NETWORKMAP; - $where['id_group'] = array_keys(users_get_groups($id_user, 'AR', $return_all_group)); + $where['id_group'] = array_keys( + users_get_groups( + $id_user, + 'AR', + $return_all_group + ) + ); if (!empty($type)) { $where['subtype'] = $type; } @@ -1256,7 +1263,30 @@ function networkmap_get_networkmaps( $where['order'][1]['field'] = 'name'; $where['order'][1]['order'] = 'ASC'; - $networkmaps_raw = db_get_all_rows_filter('tmap', $where); + if ((bool) is_metaconsole() === true) { + $servers = metaconsole_get_connection_names(); + foreach ($servers as $key => $server) { + $connection = metaconsole_get_connection($server); + if (metaconsole_connect($connection) != NOERR) { + continue; + } + + $tmp_maps = db_get_all_rows_filter('tmap', $where); + if ($tmp_maps !== false) { + foreach ($tmp_maps as $g) { + $g['id_t'] = $g['id']; + $g['id'] = $connection['id'].'_'.$g['id']; + $g['name'] = $g['name'].' ('.$connection['server_name'].')'; + $networkmaps_raw[] = $g; + } + } + + metaconsole_restore_db(); + } + } else { + $networkmaps_raw = db_get_all_rows_filter('tmap', $where); + } + if (empty($networkmaps_raw)) { return []; } diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index ef30d852f0..ba18483af0 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -239,7 +239,7 @@ function get_notification_source_targets(int $id_source, ?string $subtype=null) } $filter = sprintf( - ' AND ns.`subtype_blacklist` NOT LIKE "%%%s%%"', + ' AND (ns.`subtype_blacklist` IS NULL OR ns.`subtype_blacklist` NOT LIKE "%%%s%%") ', $subtype ); } diff --git a/pandora_console/include/functions_planned_downtimes.php b/pandora_console/include/functions_planned_downtimes.php index 116899c834..f49b0df060 100644 --- a/pandora_console/include/functions_planned_downtimes.php +++ b/pandora_console/include/functions_planned_downtimes.php @@ -95,12 +95,12 @@ function planned_downtimes_update($values, $downtime_id=0, $check_dates=true) $name_exists = (bool) db_get_value('id', 'tplanned_downtime', 'name', $values['name']); if ($name_exists) { - $result['message'] = ui_print_error_message(__('Each planned downtime must have a different name'), '', true); + $result['message'] = ui_print_error_message(__('Each scheduled downtime must have a different name'), '', true); return $result; } } else { - $result['message'] = ui_print_error_message(__('Planned downtime must have a name'), '', true); + $result['message'] = ui_print_error_message(__('Scheduled downtime must have a name'), '', true); return $result; } @@ -811,13 +811,13 @@ function planned_downtimes_created($values) } else { return [ 'return' => false, - 'message' => __('Each planned downtime must have a different name'), + 'message' => __('Each scheduled downtime must have a different name'), ]; } } else { return [ 'return' => false, - 'message' => __('Planned downtime must have a name'), + 'message' => __('Scheduled downtime must have a name'), ]; } @@ -904,16 +904,16 @@ function delete_planned_downtimes($filter) $downtime_execute = db_get_row_filter('tplanned_downtime', ['id' => $filter['id_downtime']], 'execute'); if ($downtime_execute) { - $return = __("This planned downtime are executed now. Can't delete in this moment."); + $return = __("This scheduled downtime are executed now. Can't delete in this moment."); } else { $delete = db_process_sql_delete( 'tplanned_downtime', ['id' => $filter['id_downtime']] ); if ($delete) { - $return = __('Deleted this planned downtime successfully.'); + $return = __('Deleted this scheduled downtime successfully.'); } else { - $return = __('Problems for deleted this planned downtime.'); + $return = __('Problems for deleted this scheduled downtime.'); } } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index aab903a361..e82bac98ce 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -42,6 +42,7 @@ require_once $config['homedir'].'/include/functions_users.php'; enterprise_include_once('include/functions_reporting.php'); enterprise_include_once('include/functions_metaconsole.php'); enterprise_include_once('include/functions_inventory.php'); +enterprise_include_once('include/functions_cron.php'); require_once $config['homedir'].'/include/functions_forecast.php'; require_once $config['homedir'].'/include/functions_ui.php'; require_once $config['homedir'].'/include/functions_netflow.php'; @@ -189,6 +190,14 @@ function reporting_make_reporting_data( $metaconsole_on = is_metaconsole(); $index_content = 0; + + usort( + $contents, + function ($a, $b) { + return ($a['order'] <=> $b['order']); + } + ); + foreach ($contents as $content) { $content['name'] = io_safe_input($content['name']); $content['description'] = io_safe_input($content['description']); @@ -1828,9 +1837,8 @@ function reporting_event_report_group( $content['name'] = __('Event Report Group'); } - if ($config['metaconsole']) { + if (is_metaconsole() === true && empty($content['server_name']) === false) { $id_meta = metaconsole_get_id_server($content['server_name']); - $server = metaconsole_get_connection_by_id($id_meta); metaconsole_connect($server); } @@ -1924,7 +1932,7 @@ function reporting_event_report_group( $filter_event_filter_exclude ); - if (empty($data)) { + if (empty($data) === true) { $return['failed'] = __('No events'); } else { $return['data'] = array_reverse($data); @@ -1952,10 +1960,9 @@ function reporting_event_report_group( $return['chart']['by_criticity'] = null; $return['chart']['validated_vs_unvalidated'] = null; $server_name = $content['server_name']; - if (is_metaconsole() && $server_name != '') { + $metaconsole_dbtable = false; + if (is_metaconsole() === true && empty($server_name) === true) { $metaconsole_dbtable = true; - } else { - $metaconsole_dbtable = false; } if ($event_graph_by_agent) { @@ -2065,11 +2072,11 @@ function reporting_event_report_group( ); } - if ($config['metaconsole']) { + if (is_metaconsole() === true) { metaconsole_restore_db(); } - // total_events. + // Total events. if ($return['data'] != '') { $return['total_events'] = count($return['data']); } else { @@ -5638,7 +5645,7 @@ function reporting_value($report, $content, $type, $pdf=false) ); } - $label = (isset($content['name'])) ? $content['name'] : ''; + $label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; if ($label != '') { $label = reporting_label_macro( $items_label, @@ -8581,7 +8588,7 @@ function reporting_general($report, $content) if (!is_numeric($data_res[$index])) { $return['data'][$name_agent][$mod_name] = $data_res[$index]; } else { - $return['data'][$name_agent][$mod_name] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); + $return['data'][$name_agent][$mod_name] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, ' '.$unit); } } break; @@ -8602,7 +8609,7 @@ function reporting_general($report, $content) if ($change_min) { $return['min']['value'] = $val; - $return['min']['formated_value'] = format_for_graph($val, 2, '.', ',', $divisor, $unit); + $return['min']['formated_value'] = format_for_graph($val, 2, '.', ',', $divisor, ' '.$unit); $return['min']['agent'] = $ag_name; $return['min']['module'] = $mod_name; } @@ -8618,7 +8625,7 @@ function reporting_general($report, $content) if ($change_max) { $return['max']['value'] = $val; - $return['max']['formated_value'] = format_for_graph($val, 2, '.', ',', $divisor, $unit); + $return['max']['formated_value'] = format_for_graph($val, 2, '.', ',', $divisor, ' '.$unit); $return['max']['agent'] = $ag_name; $return['max']['module'] = $mod_name; } @@ -8644,7 +8651,7 @@ function reporting_general($report, $content) if ($change_min) { $return['min']['value'] = $data_res[$index]; - $return['min']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); + $return['min']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, ' '.$unit); $return['min']['agent'] = $ag_name; $return['min']['module'] = $mod_name; } @@ -8660,7 +8667,7 @@ function reporting_general($report, $content) if ($change_max) { $return['max']['value'] = $data_res[$index]; - $return['max']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); + $return['max']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, ' '.$unit); $return['max']['agent'] = $ag_name; $return['max']['module'] = $mod_name; } @@ -8794,7 +8801,7 @@ function reporting_general($report, $content) $data['formated_value'][] = $val; } else { $data['value'][] = $val; - $data['formated_value'][] = format_for_graph($val, 2, '.', ',', $divisor, $units[$i]); + $data['formated_value'][] = format_for_graph($val, 2, '.', ',', $divisor, ' '.$units[$i]); } } } @@ -8823,7 +8830,7 @@ function reporting_general($report, $content) $data['formated_value'] = $d; } else { $data['value'] = $d; - $data['formated_value'] = format_for_graph($d, 2, '.', ',', $divisor, $units[$i]); + $data['formated_value'] = format_for_graph($d, 2, '.', ',', $divisor, ' '.$units[$i]); } } } @@ -9164,6 +9171,7 @@ function reporting_simple_graph( $return['agent_name'] = $agent_alias; $return['module_name'] = $module_name; $return['description'] = $description; + $return['label'] = $label; $return['date'] = reporting_get_date_text( $report, $content @@ -9205,7 +9213,8 @@ function reporting_simple_graph( $params = [ 'agent_module_id' => $content['id_agent_module'], 'period' => $content['period'], - 'title' => $label, + 'title' => $title, + 'label' => $label, 'pure' => false, 'date' => $report['datetime'], 'only_image' => $only_image, @@ -10337,7 +10346,7 @@ function reporting_get_stats_alerts($data, $links=false) */ if ($data['monitor_alerts'] > $data['total_agents'] && !enterprise_installed()) { - $tdata[2] = "
"; + $tdata[2] = "
"; } $tdata[3] = html_print_image( @@ -10494,7 +10503,7 @@ function reporting_get_stats_agents_monitors($data) */ if ($data['total_agents'] > 500 && !enterprise_installed()) { - $tdata[2] = "
"; + $tdata[2] = "
"; } $tdata[3] = html_print_image('images/module.png', true, ['title' => __('Monitor checks'), 'class' => 'invert_filter'], false, false, false, true); @@ -10508,7 +10517,7 @@ function reporting_get_stats_agents_monitors($data) */ if ($data['total_agents']) { if (($data['monitor_checks'] / $data['total_agents'] > 100) && !enterprise_installed()) { - $tdata[5] = "
"; + $tdata[5] = "
"; } } @@ -12807,7 +12816,7 @@ function reporting_get_stats_servers() $tdata[0] = html_print_image('images/database.png', true, ['title' => __('Local modules'), 'class' => 'invert_filter']); $tdata[1] = ''.format_numeric($server_performance['total_local_modules']).''; $tdata[2] = ''.format_numeric($server_performance['local_modules_rate'], 2).''; - $tdata[3] = html_print_image('images/database.png', true, ['title' => __('Ratio').': '.__('Modules by second'), 'class' => 'invert_filter']).'/sec '; + $tdata[3] = html_print_image('images/module.png', true, ['title' => __('Ratio').': '.__('Modules by second'), 'class' => 'invert_filter']).'/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; @@ -12822,7 +12831,7 @@ function reporting_get_stats_servers() $tdata[3] = html_print_image('images/module.png', true, ['title' => __('Ratio').': '.__('Modules by second'), 'class' => 'invert_filter']).'/sec '; if ($server_performance['total_remote_modules'] > 10000 && !enterprise_installed()) { - $tdata[4] = "
"; + $tdata[4] = "
"; } else { $tdata[4] = ' '; } @@ -12897,7 +12906,7 @@ function reporting_get_stats_servers() $tdata[1] = ''.html_print_image('images/spinner.gif', true).''; if (isset($system_events) && $system_events > 50000 && !enterprise_installed()) { - $tdata[2] = "
"; + $tdata[2] = "
"; } else { $tdata[3] = ' '; } @@ -13940,3 +13949,69 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) return reporting_check_structure_content($return); } + + +/** + * Email template for sending reports. + * + * @param string $subjectEmail Subject of email. + * @param string $bodyEmail Body of email. + * @param string $scheduled Id of schedule report. + * @param string $reportName Report name. + * @param string $email Serialized list of destination emails. + * @param array $attachments Attachments. + * + * @return void + */ +function reporting_email_template( + string $subjectEmail='', + string $bodyEmail='', + string $scheduled='', + string $reportName='', + string $email='', + array $attachments=null +) { + // Subject. + $subject = (empty($subjectEmail) === true) ? '[Pandora] '.__('Reports') : $subjectEmail; + // Body. + if (empty($bodyEmail) === true) { + $body = __('Greetings').','; + $body .= '

'; + $body .= __('Attached to this email there\'s a PDF file of the').' '; + $body .= $scheduled.' '.__('report'); + $body .= ' "'.$reportName.'"'; + $body .= '

'; + $body .= __('Generated at').' '.date('Y/m/d H:i:s'); + $body .= '

'; + $body .= __('Thanks for your time.'); + $body .= '

'; + $body .= __('Best regards, Pandora FMS'); + $body .= '

'; + $body .= ''.__('This is an automatically generated email from Pandora FMS, please do not reply.').''; + } else { + $bodyEmail = str_replace( + [ + "\r\n", + "\r", + ' ', + ], + "\n", + $bodyEmail + ); + + $body = '

'.implode("

\n

", explode("\n", $bodyEmail)).'

'; + } + + // Extract list of emails. + $destinationEmails = explode(',', io_safe_output($email)); + foreach ($destinationEmails as $destination) { + $destination = trim($destination); + + // Skip the empty 'to'. + if (empty($destination) === false) { + send_email_attachment($destination, $body, $subject, $attachments); + } else { + db_pandora_audit('ERROR:', 'Cron jobs mail, empty destination email.'); + } + } +} diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 9877842e0a..de800f09d3 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -130,17 +130,24 @@ function html_do_report_info($report) $date_today = date($config['date_format']); + $date_today = preg_split('/[\s,]+/', io_safe_output($date_today)); + + $date_today = __($date_today[0]).' '.$date_today[1].' '.$date_today[2].' '.$date_today[3].' '.$date_today[4]; $html = '
'; + + $date_before = date($config['date_format'], $report['datetime']); + $date_before = preg_split('/[\s,]+/', io_safe_output($date_before)); + $date_before = __($date_before[0]).' '.$date_before[1].' '.$date_before[2].' '.$date_before[3].' '.$date_before[4]; if (is_numeric($report['datetime']) && is_numeric($report['period']) && ($report['period'] != 0)) { $html .= ''; $html .= ''; } else { - $html .= ''; + $html .= ''; } $html .= ' @@ -849,7 +856,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0) $table1->size[10] = '2%'; $table1->data[0][10] = ''; $table1->size[11] = '15%'; - $table1->data[0][11] = ''.__('Planned Downtime').''; + $table1->data[0][11] = ''.__('Scheduled Downtime').''; if ($pdf === 0) { $table->colspan['legend']['cell'] = 2; @@ -4074,7 +4081,7 @@ function reporting_html_availability_graph($table, $item, $pdf=0) $table2->size[10] = '2%'; $table2->data[0][10] = ''; $table2->size[11] = '15%'; - $table2->data[0][11] = ''.__('Planned Downtime').''; + $table2->data[0][11] = ''.__('Scheduled Downtime').''; } if ($pdf !== 0) { @@ -5602,8 +5609,8 @@ function reporting_html_planned_downtimes_table($planned_downtimes) $table = new StdClass(); $table->width = '99%'; - $table->title = __('This SLA has been affected by the following planned downtimes').ui_print_help_tip( - __('If the duration of the planned downtime is less than 5 minutes it will not be represented in the graph'), + $table->title = __('This SLA has been affected by the following scheduled downtimes').ui_print_help_tip( + __('If the duration of the scheduled downtime is less than 5 minutes it will not be represented in the graph'), true ); $table->head = []; @@ -5641,7 +5648,7 @@ function reporting_html_planned_downtimes_table($planned_downtimes) if ($downtime_malformed) { $info_malformed = ui_print_error_message( - __('This item is affected by a malformed planned downtime').'. '.__('Go to the planned downtimes section to solve this').'.', + __('This item is affected by a malformed scheduled downtime').'. '.__('Go to the scheduled downtimes section to solve this').'.', '', true ); diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 89aacde9c6..1896078e5d 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -1187,7 +1187,7 @@ function snmp_browser_create_modules_snmp( } } - $fail_modules = []; + $fail_modules = []; foreach ($targets_oids as $key => $target_oid) { $oid = snmp_browser_get_oid( @@ -1243,7 +1243,7 @@ function snmp_browser_create_modules_snmp( 'min' => 0, 'tcp_send' => $snmp_version, 'tcp_rcv' => '', - 'tcp_port' => 0, + 'tcp_port' => $target_port, 'snmp_oid' => $oid['numeric_oid'], 'snmp_community' => $community, 'id_module_group' => 3, diff --git a/pandora_console/include/functions_tactical.php b/pandora_console/include/functions_tactical.php index 9cc891b1f1..269df899d4 100644 --- a/pandora_console/include/functions_tactical.php +++ b/pandora_console/include/functions_tactical.php @@ -343,6 +343,7 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return INNER JOIN tagente_modulo tam ON tae.id_agente_modulo = tam.id_agente_modulo AND tam.disabled = 0 + AND tam.id_modulo <> 0 GROUP BY estado', $user_groups_ids ) @@ -358,6 +359,7 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return INNER JOIN tagente_modulo tam ON tae.id_agente_modulo = tam.id_agente_modulo AND tam.disabled = 0 + AND tam.id_modulo <> 0 LEFT JOIN tagent_secondary_group tasg ON ta.id_agente = tasg.id_agent WHERE (ta.id_grupo IN ( %s ) OR tasg.id_group IN ( %s )) @@ -458,7 +460,7 @@ function tactical_monitor_alerts($group_array, $strict_user=false, $id_group_str $sql = "SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente_estado, tagente WHERE tagente.id_grupo IN $group_clause_strict AND tagente_modulo.id_agente = tagente.id_agente - AND tagente.disabled = 0 + AND tagente.disabled = 0 AND tagente_modulo.disabled = 0 AND talert_template_modules.disabled = 0 AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"; @@ -470,7 +472,7 @@ function tactical_monitor_alerts($group_array, $strict_user=false, $id_group_str "SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente_estado, tagente WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente.disabled = 0 + AND tagente.disabled = 0 AND tagente_modulo.disabled = 0 AND talert_template_modules.disabled = 0 AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo" @@ -499,7 +501,8 @@ function tactical_monitor_fired_alerts($group_array, $strict_user=false, $id_gro WHERE tagente.id_grupo IN $group_clause_strict AND tagente_modulo.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND times_fired > 0 AND talert_template_modules.disabled = 0"; + AND times_fired > 0 AND talert_template_modules.disabled = 0 + AND tagente.disabled = 0 AND tagente_modulo.disabled = 0"; $count = db_get_sql($sql); return $count; @@ -511,7 +514,8 @@ function tactical_monitor_fired_alerts($group_array, $strict_user=false, $id_gro WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND times_fired > 0 AND talert_template_modules.disabled = 0" + AND times_fired > 0 AND talert_template_modules.disabled = 0 + AND tagente.disabled = 0 AND tagente_modulo.disabled = 0" ); } diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index e5648babb8..d72abf3c33 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -290,7 +290,7 @@ function treeview_printModuleTable($id_module, $server_data=false, $no_head=fals } $last_data_str .= ' '; - $last_data_str .= html_print_image('images/clock2.png', true, ['title' => $last_data['timestamp'], 'width' => '18px']); + $last_data_str .= html_print_image('images/clock2.png', true, ['title' => $last_data['timestamp'], 'width' => '18px', 'class' => 'invert_filter']); $is_snapshot = is_snapshot_data($last_data['datos']); $is_large_image = is_text_to_black_string($last_data['datos']); @@ -307,7 +307,7 @@ function treeview_printModuleTable($id_module, $server_data=false, $no_head=fals } if ($salida !== null) { - $last_data_str = html_print_image('images/clock2.png', true, ['title' => $last_data['timestamp'], 'width' => '18px']); + $last_data_str = html_print_image('images/clock2.png', true, ['title' => $last_data['timestamp'], 'width' => '18px', 'class' => 'invert_filter']); } $last_data_str .= $salida; @@ -473,7 +473,7 @@ function treeview_printAlertsTable($id_module, $server_data=[], $no_head=false) if ($user_access_node && check_acl($config['id_user'], $id_group, 'LW')) { // Actions table - echo '
'; + echo '
'; echo ''; html_print_submit_button(__('Go to alerts edition'), 'upd_button', false, 'class="sub search"'); echo ''; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 267b5123c4..0d12af41a9 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -322,8 +322,8 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t class="info_box '.$id.' '.$class.' textodialogo" style="'.$force_style.'">
- - + - +
'.__('Generated').': '.$date_today.'
'.__('Report date').': '.__('From').' '.date($config['date_format'], ($report['datetime'] - $report['period'])).''.__('to').' '.date($config['date_format'], $report['datetime']).''.__('Items period before').' '.date($config['date_format'], $report['datetime']).''.__('Items period before').' '.$date_before.'
'.html_print_image($icon_image, true, false, false, false, false).''.$text_title.''; + '.$text_title.''; if (!$no_close_bool) { // Use the no_meta parameter because this image is only in // the base console. @@ -333,7 +333,7 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t $output .= '
'.$text_message.''.$text_message.'
'; @@ -663,12 +663,17 @@ function ui_print_group_icon($id_group, $return=false, $path='groups_small', $st if (empty($icon)) { $output .= '  '; } else { + $class = 'bot'; + if ($icon === 'transmit') { + $class .= ' invert_filter'; + } + $output .= html_print_image( 'images/'.$path.'/'.$icon.'.png', true, [ 'style' => $style, - 'class' => 'bot', + 'class' => $class, 'alt' => groups_get_name($id_group, true), 'title' => groups_get_name($id_group, true), ], @@ -1478,7 +1483,10 @@ function ui_require_css_file($name, $path='include/styles/', $echo_tag=false) return false; } - if (is_metaconsole()) { + if (is_metaconsole() + && (isset($config['requirements_use_base_url']) === false + || $config['requirements_use_base_url'] === false) + ) { $config['css'][$name] = '/../../'.$filename; } else { $config['css'][$name] = $filename; @@ -1530,7 +1538,10 @@ function ui_require_javascript_file($name, $path='include/javascript/', $echo_ta return false; } - if (is_metaconsole()) { + if (is_metaconsole() + && (isset($config['requirements_use_base_url']) === false + || $config['requirements_use_base_url'] === false) + ) { $config['js'][$name] = '../../'.$filename; } else { $config['js'][$name] = $filename; @@ -3770,6 +3781,7 @@ function ui_print_event_priority( * @param string $attributes_switch Switch attributes. * @param string $toggl_attr Main box extra attributes. * @param boolean|null $switch_on Switch enabled disabled or depending on hidden_Default. + * @param string|null $switch_name Use custom switch input name or generate one. * * @return string HTML. */ @@ -3790,7 +3802,8 @@ function ui_toggle( $switch=false, $attributes_switch='', $toggl_attr='', - $switch_on=null + $switch_on=null, + $switch_name=null ) { // Generate unique Id. $uniqid = uniqid(''); @@ -3826,7 +3839,7 @@ function ui_toggle( $main_class = ''; } - if (empty($container_class) === true) { + if ($container_class == 'white-box-content') { $container_class = 'white-box-content-clean'; } } @@ -3836,11 +3849,15 @@ function ui_toggle( $output .= '
'; if ($reverseImg === false) { if ($switch === true) { + if (empty($switch_name) === true) { + $switch_name = 'box_enable_toggle'.$uniqid; + } + $output .= html_print_div( [ 'class' => 'float-left', 'content' => html_print_checkbox_switch_extended( - 'box_enable_toggle'.$uniqid, + $switch_name, 1, ($switch_on === null) ? (($hidden_default === true) ? 0 : 1) : $switch_on, false, @@ -3910,7 +3927,7 @@ function ui_toggle( $output .= ' var hide_tgl_ctrl_'.$uniqid.' = '.(int) $hidden_default.";\n"; $output .= ' /*
+
"; } @@ -4662,6 +4681,7 @@ function ui_print_agent_autocomplete_input($parameters) { global $config; + $text_color = ''; // Normalize and extract the data from $parameters // ------------------------------------------------------------------. $return = false; @@ -4692,6 +4712,7 @@ function ui_print_agent_autocomplete_input($parameters) $icon_agent = 'images/search_agent.png'; if ($config['style'] === 'pandora_black') { + $text_color = 'style="color: white"'; $icon_agent = 'images/agent_mc.menu.png'; } @@ -5163,6 +5184,11 @@ function ui_print_agent_autocomplete_input($parameters) $javascript_function_change = ''; // Default value. $javascript_function_change .= ' + function setInputBackground(inputId, image) { + $("#"+inputId) + .css("background","url(\'"+image+"\') right center no-repeat"); + } + function set_functions_change_autocomplete_'.$input_name.'() { var cache_'.$input_name.' = {}; @@ -5177,10 +5203,9 @@ function ui_print_agent_autocomplete_input($parameters) if (cache_'.$input_name.'[groupId] == null) { cache_'.$input_name.'[groupId] = {}; } - + //Set loading - $("#'.$input_id.'") - .css("background","url(\"'.$spinner_image.'\") right center no-repeat"); + setInputBackground("'.$input_id.'", "'.$spinner_image.'"); //Function to call when the source if ('.((int) !empty($javascript_function_action_into_source_js_call)).') { @@ -5194,8 +5219,7 @@ function ui_print_agent_autocomplete_input($parameters) response(cache_'.$input_name.'[groupId][term]); //Set icon - $("#'.$input_id.'") - .css("background","url(\"'.$icon_image.'\") right center no-repeat"); + setInputBackground("'.$input_id.'", "'.$icon_image.'"); return; } else { @@ -5213,7 +5237,9 @@ function ui_print_agent_autocomplete_input($parameters) response(cache_'.$input_name.'[groupId][oldterm]); found = true; - + + //Set icon + setInputBackground("'.$input_id.'", "'.$icon_image.'"); return; } }); @@ -5229,11 +5255,10 @@ function ui_print_agent_autocomplete_input($parameters) if (found) { //Set icon - $("#'.$input_id.'") - .css("background","url(\"'.$icon_image.'\") right center no-repeat"); + setInputBackground("'.$input_id.'", "'.$icon_image.'"); select_item_click = 0; - + return; } @@ -5248,16 +5273,13 @@ function ui_print_agent_autocomplete_input($parameters) response(data); //Set icon - $("#'.$input_id.'") - .css("background", - "url(\"'.$icon_image.'\") right center no-repeat"); - - select_item_click = 0; + setInputBackground("'.$input_id.'", "'.$icon_image.'"); + select_item_click = 0; return; } }); - + return; }, //---END source----------------------------------------- @@ -5436,15 +5458,23 @@ function ui_print_agent_autocomplete_input($parameters) return; } - if ('.((int) $check_only_empty_javascript_on_blur_function).') { - return - } - - if (select_item_click) { + select_item_click = 0; + $("#'.$input_id.'") + .css("background", + "url(\"'.$icon_image.'\") right center no-repeat"); return; - } - + } else { + // Clear selectbox if item is not selected. + $("#'.$selectbox_id.'").empty(); + $("#'.$selectbox_id.'").append($("")); + $("#'.$selectbox_id.'").attr("disabled", "disabled"); + // Not allow continue on blur . + if ('.((int) $check_only_empty_javascript_on_blur_function).') { + return + } + } + //Set loading $("#'.$input_id.'") .css("background", @@ -5518,7 +5548,7 @@ function ui_print_agent_autocomplete_input($parameters) if ('.((int) !empty($javascript_function_action_after_select_js_call)).') { '.$javascript_function_action_after_select_js_call.' } - + //Set icon $("#'.$input_id.'") .css("background", @@ -5536,8 +5566,13 @@ function ui_print_agent_autocomplete_input($parameters) // ------------------------------------------------------------------. $html = ''; + $text_color = ''; + if ($config['style'] === 'pandora_black') { + $text_color = 'color: white'; + } + $attrs = []; - $attrs['style'] = 'background: url('.$icon_image.') no-repeat right;'; + $attrs['style'] = 'background: url('.$icon_image.') no-repeat right; '.$text_color.''; if (!$disabled_javascript_on_blur_function) { $attrs['onblur'] = $javascript_on_blur_function_name.'()'; @@ -5705,6 +5740,12 @@ function ui_print_module_string_value( $value = io_safe_input($value); } + $is_snapshot = is_snapshot_data($module['datos']); + $is_large_image = is_text_to_black_string($module['datos']); + if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { + $row[7] = ui_get_snapshot_image($link, $is_snapshot).'  '; + } + $is_snapshot = is_snapshot_data($value); $is_large_image = is_text_to_black_string($value); if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { diff --git a/pandora_console/include/functions_update_manager.php b/pandora_console/include/functions_update_manager.php index b641448af5..3c9d23f86c 100755 --- a/pandora_console/include/functions_update_manager.php +++ b/pandora_console/include/functions_update_manager.php @@ -763,7 +763,7 @@ function newsletter_wiz_modal( $output .= __('Do you want to be up to date?'); $output .= '" class="invisible">'; $output .= '
'; - $output .= html_print_image('image/pandora_big_circle.png', true); + $output .= html_print_image('images/pandora_circle_big.png', true); $output .= '
'; $output .= '"; $return .= "