diff --git a/extras/deploy-scripts/deploy_ext_database_el8.sh b/extras/deploy-scripts/deploy_ext_database_el8.sh index 3ff86cc56b..4417265599 100644 --- a/extras/deploy-scripts/deploy_ext_database_el8.sh +++ b/extras/deploy-scripts/deploy_ext_database_el8.sh @@ -19,10 +19,10 @@ LOGFILE="/tmp/deploy-ext-db-$(date +%F).log" [ "$DBHOST" ] || DBHOST=127.0.0.1 [ "$DBNAME" ] || DBNAME=pandora [ "$DBUSER" ] || DBUSER=pandora -[ "$DBPASS" ] || DBPASS=pandora +[ "$DBPASS" ] || DBPASS='Pandor4!' [ "$DBPORT" ] || DBPORT=3306 [ "$DBROOTUSER" ] || DBROOTUSER=root -[ "$DBROOTPASS" ] || DBROOTPASS=pandora +[ "$DBROOTPASS" ] || DBROOTPASS='Pandor4!' [ "$SKIP_DATABASE_INSTALL" ] || SKIP_DATABASE_INSTALL=0 [ "$SKIP_KERNEL_OPTIMIZATIONS" ] || SKIP_KERNEL_OPTIMIZATIONS=0 [ "$POOL_SIZE" ] || POOL_SIZE=$(grep -i total /proc/meminfo | head -1 | awk '{printf "%.2f \n", $(NF-1)*0.4/1024}' | sed "s/\\..*$/M/g") @@ -79,6 +79,53 @@ check_root_permissions () { fi } +# Function to check if a password meets the MySQL secure password requirements +is_mysql_secure_password() { + local password=$1 + + # Check password length (at least 8 characters) + if [[ ${#password} -lt 8 ]]; then + echo "Password length should be at least 8 characters." + return 1 + fi + + # Check if password contains at least one uppercase letter + if [[ $password == ${password,,} ]]; then + echo "Password should contain at least one uppercase letter." + return 1 + fi + + # Check if password contains at least one lowercase letter + if [[ $password == ${password^^} ]]; then + echo "Password should contain at least one lowercase letter." + return 1 + fi + + # Check if password contains at least one digit + if ! [[ $password =~ [0-9] ]]; then + echo "Password should contain at least one digit." + return 1 + fi + + # Check if password contains at least one special character + if ! [[ $password =~ [[:punct:]] ]]; then + echo "Password should contain at least one special character." + return 1 + fi + + # Check if password is not a common pattern (e.g., "password", "123456") + local common_patterns=("password" "123456" "qwerty") + for pattern in "${common_patterns[@]}"; do + if [[ $password == *"$pattern"* ]]; then + echo "Password should not contain common patterns." + return 1 + fi + done + + # If all checks pass, the password is MySQL secure compliant + return 0 +} + ## Main echo "Starting PandoraFMS External DB deployment EL8 ver. $S_VERSION" @@ -128,6 +175,10 @@ execute_cmd "grep --version" 'Checking needed tools: grep' execute_cmd "sed --version" 'Checking needed tools: sed' execute_cmd "dnf --version" 'Checking needed tools: dnf' +#Check mysql pass +execute_cmd "is_mysql_secure_password $DBROOTPASS" "Checking DBROOTPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' +execute_cmd "is_mysql_secure_password $DBPASS" "Checking DBPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' + # Creating working directory rm -rf "$HOME"/pandora_deploy_tmp/*.rpm* &>> "$LOGFILE" mkdir "$HOME"/pandora_deploy_tmp &>> "$LOGFILE" @@ -207,16 +258,12 @@ if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then export MYSQL_PWD=$(grep "temporary password" /var/log/mysqld.log | rev | cut -d' ' -f1 | rev) if [ "$MYVER" -eq '80' ] ; then echo """ - SET PASSWORD FOR '$DBROOTUSER'@'localhost' = 'Pandor4!'; - UNINSTALL COMPONENT 'file://component_validate_password'; SET PASSWORD FOR '$DBROOTUSER'@'localhost' = '$DBROOTPASS'; """ | mysql --connect-expired-password -u$DBROOTUSER &>> "$LOGFILE" fi if [ "$MYVER" -ne '80' ] ; then echo """ - SET PASSWORD FOR '$DBROOTUSER'@'localhost' = PASSWORD('Pandor4!'); - UNINSTALL PLUGIN validate_password; SET PASSWORD FOR '$DBROOTUSER'@'localhost' = PASSWORD('$DBROOTPASS'); """ | mysql --connect-expired-password -u$DBROOTUSER &>> "$LOGFILE"fi fi diff --git a/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh b/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh index 21f9b21fa0..767be5632f 100644 --- a/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh +++ b/extras/deploy-scripts/deploy_ext_database_ubuntu_2204.sh @@ -26,9 +26,9 @@ rm -f $LOGFILE &> /dev/null # remove last log before start [ "$DBHOST" ] || DBHOST=127.0.0.1 [ "$DBNAME" ] || DBNAME=pandora [ "$DBUSER" ] || DBUSER=pandora -[ "$DBPASS" ] || DBPASS=pandora +[ "$DBPASS" ] || DBPASS='Pandor4!' [ "$DBPORT" ] || DBPORT=3306 -[ "$DBROOTPASS" ] || DBROOTPASS=pandora +[ "$DBROOTPASS" ] || DBROOTPASS='Pandor4!' [ "$SKIP_DATABASE_INSTALL" ] || SKIP_DATABASE_INSTALL=0 [ "$SKIP_KERNEL_OPTIMIZATIONS" ] || SKIP_KERNEL_OPTIMIZATIONS=0 [ "$POOL_SIZE" ] || POOL_SIZE=$(grep -i total /proc/meminfo | head -1 | awk '{printf "%.2f \n", $(NF-1)*0.4/1024}' | sed "s/\\..*$/M/g") @@ -86,6 +86,53 @@ check_root_permissions () { fi } +# Function to check if a password meets the MySQL secure password requirements +is_mysql_secure_password() { + local password=$1 + + # Check password length (at least 8 characters) + if [[ ${#password} -lt 8 ]]; then + echo "Password length should be at least 8 characters." + return 1 + fi + + # Check if password contains at least one uppercase letter + if [[ $password == ${password,,} ]]; then + echo "Password should contain at least one uppercase letter." + return 1 + fi + + # Check if password contains at least one lowercase letter + if [[ $password == ${password^^} ]]; then + echo "Password should contain at least one lowercase letter." + return 1 + fi + + # Check if password contains at least one digit + if ! [[ $password =~ [0-9] ]]; then + echo "Password should contain at least one digit." + return 1 + fi + + # Check if password contains at least one special character + if ! [[ $password =~ [[:punct:]] ]]; then + echo "Password should contain at least one special character." + return 1 + fi + + # Check if password is not a common pattern (e.g., "password", "123456") + local common_patterns=("password" "123456" "qwerty") + for pattern in "${common_patterns[@]}"; do + if [[ $password == *"$pattern"* ]]; then + echo "Password should not contain common patterns." + return 1 + fi + done + + # If all checks pass, the password is MySQL secure compliant + return 0 +} + ## Main echo "Starting PandoraFMS External DB deployment Ubuntu 22.04 ver. $S_VERSION" @@ -137,6 +184,10 @@ execute_cmd "grep --version" 'Checking needed tools: grep' execute_cmd "sed --version" 'Checking needed tools: sed' execute_cmd "apt --version" 'Checking needed tools: apt' +#Check mysql pass +execute_cmd "is_mysql_secure_password $DBROOTPASS" "Checking DBROOTPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' +execute_cmd "is_mysql_secure_password $DBPASS" "Checking DBPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' + # Creating working directory rm -rf "$WORKDIR" &>> "$LOGFILE" mkdir -p "$WORKDIR" &>> "$LOGFILE" @@ -170,6 +221,7 @@ if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then """ | mysql -uroot &>> "$LOGFILE" export MYSQL_PWD=$DBROOTPASS + echo "INSTALL COMPONENT 'file://component_validate_password';" | mysql -uroot -P$DBPORT -h$DBHOST &>> "$LOGFILE" echo -en "${cyan}Creating Pandora FMS database...${reset}" echo "create database $DBNAME" | mysql -uroot -P$DBPORT -h$DBHOST check_cmd_status "Error creating database $DBNAME, is this an empty node? if you have a previus installation please contact with support." diff --git a/extras/deploy-scripts/pandora_deploy_community.sh b/extras/deploy-scripts/pandora_deploy_community.sh index 2e40524588..c16729bca0 100644 --- a/extras/deploy-scripts/pandora_deploy_community.sh +++ b/extras/deploy-scripts/pandora_deploy_community.sh @@ -11,7 +11,7 @@ PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='2023050901' +S_VERSION='2023062901' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables @@ -285,8 +285,7 @@ console_dependencies=" \ mod_ssl \ libzstd \ openldap-clients \ - chromium \ - http://firefly.pandorafms.com/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm" + chromium" execute_cmd "yum install -y $console_dependencies" "Installing Pandora FMS Console dependencies" # Server dependencies @@ -313,7 +312,6 @@ server_dependencies=" \ bind-utils \ whois \ cpanminus \ - http://firefly.pandorafms.com/centos7/xprobe2-0.3-12.2.x86_64.rpm \ http://firefly.pandorafms.com/centos7/wmic-1.4-1.el7.x86_64.rpm \ https://firefly.pandorafms.com/centos7/pandorawmic-1.0.0-1.x86_64.rpm" execute_cmd "yum install -y $server_dependencies" "Installing Pandora FMS Server dependencies" @@ -341,7 +339,6 @@ execute_cmd "yum install -y $oracle_dependencies || yum reinstall -y $oracle_dep #ipam dependencies ipam_dependencies=" \ - http://firefly.pandorafms.com/centos7/xprobe2-0.3-12.2.x86_64.rpm \ perl(NetAddr::IP) \ perl(Sys::Syslog) \ perl(DBI) \ @@ -719,6 +716,9 @@ echo "* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cro systemctl enable pandora_agent_daemon &>> $LOGFILE execute_cmd "systemctl start pandora_agent_daemon" "Starting Pandora FMS Agent" +# Enable postrix +systemctl enable postfix --now &>> "$LOGFILE" + #SSH banner [ "$(curl -s ifconfig.me)" ] && ipplublic=$(curl -s ifconfig.me) diff --git a/extras/deploy-scripts/pandora_deploy_community_el8.sh b/extras/deploy-scripts/pandora_deploy_community_el8.sh index 972a094c95..32422ab98b 100644 --- a/extras/deploy-scripts/pandora_deploy_community_el8.sh +++ b/extras/deploy-scripts/pandora_deploy_community_el8.sh @@ -14,7 +14,7 @@ PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='2023050901' +S_VERSION='2023062901' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables @@ -24,10 +24,10 @@ LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" [ "$DBHOST" ] || DBHOST=127.0.0.1 [ "$DBNAME" ] || DBNAME=pandora [ "$DBUSER" ] || DBUSER=pandora -[ "$DBPASS" ] || DBPASS=pandora +[ "$DBPASS" ] || DBPASS='Pandor4!' [ "$DBPORT" ] || DBPORT=3306 [ "$DBROOTUSER" ] || DBROOTUSER=root -[ "$DBROOTPASS" ] || DBROOTPASS=pandora +[ "$DBROOTPASS" ] || DBROOTPASS='Pandor4!' [ "$SKIP_PRECHECK" ] || SKIP_PRECHECK=0 [ "$SKIP_DATABASE_INSTALL" ] || SKIP_DATABASE_INSTALL=0 [ "$SKIP_KERNEL_OPTIMIZATIONS" ] || SKIP_KERNEL_OPTIMIZATIONS=0 @@ -125,6 +125,52 @@ installing_docker () { echo "End installig docker" &>> "$LOGFILE" } +# Function to check if a password meets the MySQL secure password requirements +is_mysql_secure_password() { + local password=$1 + + # Check password length (at least 8 characters) + if [[ ${#password} -lt 8 ]]; then + echo "Password length should be at least 8 characters." + return 1 + fi + + # Check if password contains at least one uppercase letter + if [[ $password == ${password,,} ]]; then + echo "Password should contain at least one uppercase letter." + return 1 + fi + + # Check if password contains at least one lowercase letter + if [[ $password == ${password^^} ]]; then + echo "Password should contain at least one lowercase letter." + return 1 + fi + + # Check if password contains at least one digit + if ! [[ $password =~ [0-9] ]]; then + echo "Password should contain at least one digit." + return 1 + fi + + # Check if password contains at least one special character + if ! [[ $password =~ [[:punct:]] ]]; then + echo "Password should contain at least one special character." + return 1 + fi + + # Check if password is not a common pattern (e.g., "password", "123456") + local common_patterns=("password" "123456" "qwerty") + for pattern in "${common_patterns[@]}"; do + if [[ $password == *"$pattern"* ]]; then + echo "Password should not contain common patterns." + return 1 + fi + done + + # If all checks pass, the password is MySQL secure compliant + return 0 +} ## Main echo "Starting PandoraFMS Community deployment EL8 ver. $S_VERSION" @@ -189,6 +235,10 @@ execute_cmd "grep --version" 'Checking needed tools: grep' execute_cmd "sed --version" 'Checking needed tools: sed' execute_cmd "dnf --version" 'Checking needed tools: dnf' +#Check mysql pass +execute_cmd "is_mysql_secure_password $DBROOTPASS" "Checking DBROOTPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' +execute_cmd "is_mysql_secure_password $DBPASS" "Checking DBPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' + # Creating working directory rm -rf "$HOME"/pandora_deploy_tmp/*.rpm* &>> "$LOGFILE" mkdir "$HOME"/pandora_deploy_tmp &>> "$LOGFILE" @@ -344,8 +394,7 @@ console_dependencies=" \ http://firefly.pandorafms.com/centos8/chromium-110.0.5481.177-1.el7.x86_64.rpm \ http://firefly.pandorafms.com/centos8/chromium-common-110.0.5481.177-1.el7.x86_64.rpm \ http://firefly.pandorafms.com/centos8/perl-Net-Telnet-3.04-1.el8.noarch.rpm \ - http://firefly.pandorafms.com/centos7/wmic-1.4-1.el7.x86_64.rpm \ - http://firefly.pandorafms.com/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm" + http://firefly.pandorafms.com/centos7/wmic-1.4-1.el7.x86_64.rpm" execute_cmd "dnf install -y $console_dependencies" "Installing Pandora FMS Console dependencies" # Server dependencies @@ -371,7 +420,7 @@ server_dependencies=" \ java \ bind-utils \ whois \ - http://firefly.pandorafms.com/centos7/xprobe2-0.3-12.2.x86_64.rpm \ + libnsl \ http://firefly.pandorafms.com/centos7/wmic-1.4-1.el7.x86_64.rpm \ https://firefly.pandorafms.com/centos8/pandorawmic-1.0.0-1.x86_64.rpm" execute_cmd "dnf install -y $server_dependencies" "Installing Pandora FMS Server dependencies" @@ -399,7 +448,6 @@ execute_cmd "dnf install -y $oracle_dependencies" "Installing Oracle Instant cli #ipam dependencies ipam_dependencies=" \ - http://firefly.pandorafms.com/centos7/xprobe2-0.3-12.2.x86_64.rpm \ perl(NetAddr::IP) \ perl(Sys::Syslog) \ perl(DBI) \ @@ -439,7 +487,6 @@ if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then if [ "$MYVER" -eq '80' ] ; then echo """ SET PASSWORD FOR '$DBROOTUSER'@'localhost' = 'Pandor4!'; - UNINSTALL COMPONENT 'file://component_validate_password'; SET PASSWORD FOR '$DBROOTUSER'@'localhost' = '$DBROOTPASS'; """ | mysql --connect-expired-password -u$DBROOTUSER &>> "$LOGFILE" fi @@ -447,7 +494,6 @@ if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then if [ "$MYVER" -ne '80' ] ; then echo """ SET PASSWORD FOR '$DBROOTUSER'@'localhost' = PASSWORD('Pandor4!'); - UNINSTALL PLUGIN validate_password; SET PASSWORD FOR '$DBROOTUSER'@'localhost' = PASSWORD('$DBROOTPASS'); """ | mysql --connect-expired-password -u$DBROOTUSER &>> "$LOGFILE"fi fi @@ -622,8 +668,9 @@ sed -i -e "s/^upload_max_filesize.*/upload_max_filesize = 800M/g" /etc/php.ini sed -i -e "s/^memory_limit.*/memory_limit = 800M/g" /etc/php.ini sed -i -e "s/.*post_max_size =.*/post_max_size = 800M/" /etc/php.ini -#adding 900s to httpd timeout +#adding 900s to httpd timeout and 300 to ProxyTimeout echo 'TimeOut 900' > /etc/httpd/conf.d/timeout.conf +echo 'ProxyTimeout 300' >> /etc/httpd/conf.d/timeout.conf cat > /var/www/html/index.html << EOF_INDEX @@ -787,6 +834,9 @@ echo "* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cro systemctl enable pandora_agent_daemon &>> "$LOGFILE" execute_cmd "systemctl start pandora_agent_daemon" "Starting Pandora FMS Agent" +# Enable postfix +systemctl enable postfix --now &>> "$LOGFILE" + #SSH banner [ "$(curl -s ifconfig.me)" ] && ipplublic=$(curl -s ifconfig.me) diff --git a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh index 3d31ae10af..a215808d17 100644 --- a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh +++ b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh @@ -17,7 +17,7 @@ PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf WORKDIR=/opt/pandora/deploy -S_VERSION='2023050901' +S_VERSION='2023062901' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" rm -f $LOGFILE &> /dev/null # remove last log before start @@ -27,9 +27,9 @@ rm -f $LOGFILE &> /dev/null # remove last log before start [ "$DBHOST" ] || DBHOST=127.0.0.1 [ "$DBNAME" ] || DBNAME=pandora [ "$DBUSER" ] || DBUSER=pandora -[ "$DBPASS" ] || DBPASS=pandora +[ "$DBPASS" ] || DBPASS='Pandor4!' [ "$DBPORT" ] || DBPORT=3306 -[ "$DBROOTPASS" ] || DBROOTPASS=pandora +[ "$DBROOTPASS" ] || DBROOTPASS='Pandor4!' [ "$SKIP_PRECHECK" ] || SKIP_PRECHECK=0 [ "$SKIP_DATABASE_INSTALL" ] || SKIP_DATABASE_INSTALL=0 [ "$SKIP_KERNEL_OPTIMIZATIONS" ] || SKIP_KERNEL_OPTIMIZATIONS=0 @@ -113,6 +113,53 @@ check_root_permissions () { fi } +# Function to check if a password meets the MySQL secure password requirements +is_mysql_secure_password() { + local password=$1 + + # Check password length (at least 8 characters) + if [[ ${#password} -lt 8 ]]; then + echo "Password length should be at least 8 characters." + return 1 + fi + + # Check if password contains at least one uppercase letter + if [[ $password == ${password,,} ]]; then + echo "Password should contain at least one uppercase letter." + return 1 + fi + + # Check if password contains at least one lowercase letter + if [[ $password == ${password^^} ]]; then + echo "Password should contain at least one lowercase letter." + return 1 + fi + + # Check if password contains at least one digit + if ! [[ $password =~ [0-9] ]]; then + echo "Password should contain at least one digit." + return 1 + fi + + # Check if password contains at least one special character + if ! [[ $password =~ [[:punct:]] ]]; then + echo "Password should contain at least one special character." + return 1 + fi + + # Check if password is not a common pattern (e.g., "password", "123456") + local common_patterns=("password" "123456" "qwerty") + for pattern in "${common_patterns[@]}"; do + if [[ $password == *"$pattern"* ]]; then + echo "Password should not contain common patterns." + return 1 + fi + done + + # If all checks pass, the password is MySQL secure compliant + return 0 +} + installing_docker () { #Installing docker for debug echo "Start installig docker" &>> "$LOGFILE" @@ -194,6 +241,10 @@ execute_cmd "grep --version" 'Checking needed tools: grep' execute_cmd "sed --version" 'Checking needed tools: sed' execute_cmd "apt --version" 'Checking needed tools: apt' +#Check mysql pass +execute_cmd "is_mysql_secure_password $DBROOTPASS" "Checking DBROOTPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' +execute_cmd "is_mysql_secure_password $DBPASS" "Checking DBPASS password match policy" 'This password do not match minimum MySQL policy requirements, more info in: https://dev.mysql.com/doc/refman/8.0/en/validate-password.html' + # Creating working directory rm -rf "$WORKDIR" &>> "$LOGFILE" mkdir -p "$WORKDIR" &>> "$LOGFILE" @@ -265,7 +316,6 @@ server_dependencies=" \ openssh-client \ postfix \ unzip \ - xprobe \ coreutils \ libio-compress-perl \ libmoosex-role-timer-perl \ @@ -287,6 +337,8 @@ server_dependencies=" \ libgeo-ip-perl \ arping \ snmp-mibs-downloader \ + snmptrapd \ + libnsl2 \ openjdk-8-jdk " execute_cmd "apt install -y $server_dependencies" "Installing Pandora FMS Server dependencies" @@ -299,17 +351,7 @@ echo -en "${cyan}Installing wmic and pandorawmic...${reset}" chmod +x pandorawmic wmic &>> "$LOGFILE" && \ cp -a wmic /usr/bin/ &>> "$LOGFILE" && \ cp -a pandorawmic /usr/bin/ &>> "$LOGFILE" -check_cmd_status "Error Installing phanromjs" - -# phantomjs -echo -en "${cyan}Installing phantomjs...${reset}" - export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64" - export OPENSSL_CONF=/etc/ssl - curl -LSs -O "https://firefly.pandorafms.com/pandorafms/utils/$PHANTOM_JS.tar.bz2" &>> "$LOGFILE" && \ - tar xvjf "$PHANTOM_JS.tar.bz2" &>> "$LOGFILE" && \ - mv $PHANTOM_JS/bin/phantomjs /usr/bin &>> "$LOGFILE" && \ - /usr/bin/phantomjs --version &>> "$LOGFILE" -check_cmd_status "Error Installing phanromjs" +check_cmd_status "Error Installing pandorawmic/wmic" # create symlink for fping rm -f /usr/sbin/fping &>> "$LOGFILE" @@ -370,7 +412,6 @@ source '/root/.profile' &>> "$LOGFILE" #ipam dependencies ipam_dependencies=" \ - xprobe \ libnetaddr-ip-perl \ coreutils \ libdbd-mysql-perl \ @@ -413,6 +454,7 @@ if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then """ | mysql -uroot &>> "$LOGFILE" export MYSQL_PWD=$DBROOTPASS + echo "INSTALL COMPONENT 'file://component_validate_password';" | mysql -uroot -P$DBPORT -h$DBHOST &>> "$LOGFILE" echo -en "${cyan}Creating Pandora FMS database...${reset}" echo "create database $DBNAME" | mysql -uroot -P$DBPORT -h$DBHOST check_cmd_status "Error creating database $DBNAME, is this an empty node? if you have a previus installation please contact with support." @@ -619,8 +661,9 @@ sed --follow-symlinks -i -e "s/^memory_limit.*/memory_limit = 800M/g" /etc/php.i sed --follow-symlinks -i -e "s/.*post_max_size =.*/post_max_size = 800M/" /etc/php.ini sed --follow-symlinks -i -e "s/^disable_functions/;disable_functions/" /etc/php.ini -#adding 900s to httpd timeout -#echo 'TimeOut 900' > /etc/httpd/conf.d/timeout.conf +#adding 900s to httpd timeout and 300 to ProxyTimeout +echo 'TimeOut 900' > /etc/apache2/conf-enabled/timeout.conf +echo 'ProxyTimeout 300' >> /etc/apache2/conf-enabled/timeout.conf cat > /var/www/html/index.html << EOF_INDEX @@ -792,6 +835,13 @@ systemctl enable pandora_agent_daemon &>> "$LOGFILE" #fix path phantomjs sed --follow-symlinks -i -e "s/^openssl_conf = openssl_init/#openssl_conf = openssl_init/g" /etc/ssl/openssl.cnf &>> "$LOGFILE" +# Enable postfix +systemctl enable postfix --now &>> "$LOGFILE" + +# Disable snmptrapd +systemctl disable --now snmptrapd &>> "$LOGFILE" +systemctl disable --now snmptrapd.socket &>> "$LOGFILE" + #SSH banner [ "$(curl -s ifconfig.me)" ] && ipplublic=$(curl -s ifconfig.me) diff --git a/pandora_agents/pc/DEBIAN/control b/pandora_agents/pc/DEBIAN/control index cdbcc99cfe..ac23fd959f 100644 --- a/pandora_agents/pc/DEBIAN/control +++ b/pandora_agents/pc/DEBIAN/control @@ -4,7 +4,7 @@ Architecture: all Priority: optional Section: admin Installed-Size: 260 -Maintainer: ÁRTICA ST +Maintainer: Pandora FMS Homepage: https://pandorafms.org/ Depends: coreutils, perl, unzip Description: Pandora FMS agents are based on native languages in every platform: scripts that can be written in any language. It’s possible to reproduce any agent in any programming language and can be extended without difficulty the existing ones in order to cover aspects not taken into account up to the moment. These scripts are formed by modules that each one gathers a "chunk" of information. Thus, every agent gathers several "chunks" of information; this one is organized in a data set and stored in a single file, called data file. diff --git a/pandora_agents/shellscript/linux/DEBIAN/control b/pandora_agents/shellscript/linux/DEBIAN/control index 55a5168f93..2ffdee57df 100755 --- a/pandora_agents/shellscript/linux/DEBIAN/control +++ b/pandora_agents/shellscript/linux/DEBIAN/control @@ -4,7 +4,7 @@ Architecture: all Priority: optional Section: admin Installed-Size: 260 -Maintainer: ÁRTICA ST +Maintainer: Pandora FMS Homepage: http://pandorafms.org/ Depends: coreutils, perl Description: Pandora FMS agents are based on native languages in every platform: scripts that can be written in any language. It’s possible to reproduce any agent in any programming language and can be extended without difficulty the existing ones in order to cover aspects not taken into account up to the moment. These scripts are formed by modules that each one gathers a "chunk" of information. Thus, every agent gathers several "chunks" of information; this one is organized in a data set and stored in a single file, called data file. diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 9f2a0a04aa..cf664c3c2e 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,10 +1,10 @@ package: pandorafms-agent-unix -Version: 7.0NG.772-230714 +Version: 7.0NG.772-230731 Architecture: all Priority: optional Section: admin Installed-Size: 260 -Maintainer: ÁRTICA ST +Maintainer: Pandora FMS Homepage: http://pandorafms.org/ Depends: coreutils, perl, unzip Description: Pandora FMS agents are based on native languages in every platform: scripts that can be written in any language. It’s possible to reproduce any agent in any programming language and can be extended without difficulty the existing ones in order to cover aspects not taken into account up to the moment. These scripts are formed by modules that each one gathers a "chunk" of information. Thus, every agent gathers several "chunks" of information; this one is organized in a data set and stored in a single file, called data file. diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index c0704f74a7..fcd0f7713a 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.772-230714" +pandora_version="7.0NG.772-230731" 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/files/pandorafms_uninstall/PandoraFMS agent uninstaller.app/Contents/Info.plist b/pandora_agents/unix/Darwin/dmg/files/pandorafms_uninstall/PandoraFMS agent uninstaller.app/Contents/Info.plist index 4ee8965fef..e7c5fa5a91 100644 --- a/pandora_agents/unix/Darwin/dmg/files/pandorafms_uninstall/PandoraFMS agent uninstaller.app/Contents/Info.plist +++ b/pandora_agents/unix/Darwin/dmg/files/pandorafms_uninstall/PandoraFMS agent uninstaller.app/Contents/Info.plist @@ -6,7 +6,7 @@ CFBundleIdentifier com.pandorafms.pandorafms_uninstall CFBundleVersion 7.0NG.772 - CFBundleGetInfoString 7.0NG.772 Pandora FMS Agent uninstaller for MacOS by Artica ST on Aug 2020 + CFBundleGetInfoString 7.0NG.772 Pandora FMS on Aug 2020 CFBundleShortVersionString 7.0NG.772 NSPrincipalClassNSApplication diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 09aad69a9b..efb5a851ac 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1031,7 +1031,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.772'; -use constant AGENT_BUILD => '230714'; +use constant AGENT_BUILD => '230731'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 0e6440e1a7..367ce727cd 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -4,7 +4,7 @@ %global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 7.0NG.772 -%define release 230714 +%define release 230731 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.redhat_bin.spec b/pandora_agents/unix/pandora_agent.redhat_bin.spec new file mode 100644 index 0000000000..226c73426b --- /dev/null +++ b/pandora_agents/unix/pandora_agent.redhat_bin.spec @@ -0,0 +1,168 @@ +# +#Pandora FMS Linux Agent +# +%global __os_install_post %{nil} +%define name pandorafms_agent_linux_bin +%define source_name pandorafms_agent_linux +%define version 7.0NG.772 +%define release 230725 + +Summary: Pandora FMS Linux agent, binary version +Name: %{name} +Version: %{version} +Release: %{release} +License: GPL +Vendor: ArticaST +Source0: %{source_name}-%{version}.tar.gz +URL: http://pandorafms.org +Group: System/Monitoring +Packager: Sancho Lerena +Prefix: /usr/share +BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot +BuildArch: noarch +Requires(pre): shadow-utils +Requires(post): chkconfig /bin/ln +Requires(preun): chkconfig /bin/rm /usr/sbin/userdel +Requires: coreutils unzip +Requires: util-linux procps grep +Requires: /sbin/ip /bin/awk +Requires: perl(Sys::Syslog) perl(IO::Compress::Zip) +# Required by plugins +#Requires: sh-utils sed passwd net-tools rpm +AutoReq: 0 +Provides: %{name}-%{version} + +%description +Pandora FMS agent for unix. Pandora FMS is an OpenSource full-featured monitoring software. + +%prep +rm -rf $RPM_BUILD_ROOT + +%setup -q -n unix + +%build + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT%{prefix}/pandora_agent/ +mkdir -p $RPM_BUILD_ROOT/usr/bin/ +mkdir -p $RPM_BUILD_ROOT/usr/sbin/ +mkdir -p $RPM_BUILD_ROOT/etc/pandora/ +mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d/ +mkdir -p $RPM_BUILD_ROOT/var/log/pandora/ +mkdir -p $RPM_BUILD_ROOT/usr/share/man/man1/ +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/ +cp -aRf * $RPM_BUILD_ROOT%{prefix}/pandora_agent/ +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/tentacle_client $RPM_BUILD_ROOT/usr/bin/ +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent $RPM_BUILD_ROOT/usr/bin/ +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_exec $RPM_BUILD_ROOT/usr/bin/ +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_daemon $RPM_BUILD_ROOT/etc/rc.d/init.d/pandora_agent_daemon +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/man/man1/pandora_agent.1.gz $RPM_BUILD_ROOT/usr/share/man/man1/ +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/man/man1/tentacle_client.1.gz $RPM_BUILD_ROOT/usr/share/man/man1/ + +cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/Linux/pandora_agent.conf $RPM_BUILD_ROOT/usr/share/pandora_agent/pandora_agent.conf.rpmnew + +install -m 0644 pandora_agent_logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/pandora_agent + +if [ -f $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.spec ] ; then + rm $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.spec +fi + +%clean +rm -Rf $RPM_BUILD_ROOT + +%pre +getent passwd pandora >/dev/null || \ + /usr/sbin/useradd -d %{prefix}/pandora -s /bin/false -M -g 0 pandora +exit 0 +chown pandora:root /var/log/pandora + +%post +if [ ! -d /etc/pandora ] ; then + mkdir -p /etc/pandora +fi + +if [ ! -f /usr/share/pandora_agent/pandora_agent.conf ] ; then + cp /usr/share/pandora_agent/pandora_agent.conf.rpmnew /usr/share/pandora_agent/pandora_agent.conf +fi + +if [ ! -f /etc/pandora/pandora_agent.conf ] ; then + ln -s /usr/share/pandora_agent/pandora_agent.conf /etc/pandora/pandora_agent.conf +else + [[ ! -f /etc/pandora/pandora_agent.conf.rpmnew ]] && ln -s /usr/share/pandora_agent/pandora_agent.conf.rpmnew /etc/pandora/pandora_agent.conf.rpmnew +fi + +if [ ! -e /etc/pandora/plugins ]; then + ln -s /usr/share/pandora_agent/plugins /etc/pandora +fi + +if [ ! -e /etc/pandora/collections ]; then + mkdir -p /usr/share/pandora_agent/collections + ln -s /usr/share/pandora_agent/collections /etc/pandora +fi + +if [ ! -e /etc/pandora/commands ]; then + mkdir -p /usr/share/pandora_agent/commands + ln -s /usr/share/pandora_agent/commands /etc/pandora +fi + +mkdir -p /var/spool/pandora/data_out +if [ ! -d /var/log/pandora ]; then + mkdir -p /var/log/pandora +fi + +if [ `command -v systemctl` ]; +then + echo "Copying new version of pandora_agent_daemon service" + cp -f /usr/share/pandora_agent/pandora_agent_daemon.service /usr/lib/systemd/system/ + chmod -x /usr/lib/systemd/system/pandora_agent_daemon.service +# Enable the services on SystemD + systemctl enable pandora_agent_daemon.service +else + /sbin/chkconfig --add pandora_agent_daemon + /sbin/chkconfig pandora_agent_daemon on +fi + +if [ "$1" -gt 1 ] +then + + echo "If Pandora Agent daemon was running with init.d script," + echo "please stop it manually and start the service with systemctl" + +fi + + +%preun + +# Upgrading +if [ "$1" = "1" ]; then + exit 0 +fi + +/sbin/chkconfig --del pandora_agent_daemon +/etc/rc.d/init.d/pandora_agent_daemon stop >/dev/null 2>&1 || : + +# Remove symbolic links +pushd /etc/pandora +for f in pandora_agent.conf plugins collections +do + [ -L $f ] && rm -f $f +done +exit 0 + +%files +%defattr(750,root,root) +/usr/bin/pandora_agent + +%defattr(755,pandora,root) +%{prefix}/pandora_agent + +%defattr(755,root,root) +/usr/bin/pandora_agent_exec +/usr/bin/tentacle_client +/etc/rc.d/init.d/pandora_agent_daemon + +%defattr(644,root,root) +/usr/share/man/man1/pandora_agent.1.gz +/usr/share/man/man1/tentacle_client.1.gz +%config(noreplace) %{_sysconfdir}/logrotate.d/pandora_agent diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 111552facf..82db72ff9a 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -4,7 +4,7 @@ %global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 7.0NG.772 -%define release 230714 +%define release 230731 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 52f5e1635a..9b5c149c66 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.772" -PI_BUILD="230714" +PI_BUILD="230731" OS_NAME=`uname -s` FORCE=0 @@ -541,8 +541,17 @@ install () { then echo "Define 'pandora_agent=\"YES\"' in /etc/rc.conf to enable the daemon." else - echo "Check your startup configuration to be sure Pandora FMS Agent is ready " - echo "to start automatically when system restarts": + # Enable startup service + if [ `command -v systemctl` ] + then + systemctl enable pandora_agent_daemon + elif [ `command -v chkconfig` ] + then + chkconfig pandora_agent_daemon on + else + echo "Check your startup configuration to be sure Pandora FMS Agent is ready " + echo "to start automatically when system restarts": + fi fi # Restore the daemon script diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 5188111230..df59837034 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{230714} +{230731} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 24d4844aee..209bcae1d4 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.772 Build 230714") +#define PANDORA_VERSION ("7.0NG.772 Build 230731") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 7327e99e36..1d5a5afd7c 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -6,12 +6,12 @@ BEGIN BEGIN BLOCK "080904E4" BEGIN - VALUE "CompanyName", "Artica ST" + VALUE "CompanyName", "Pandora FMS" VALUE "FileDescription", "Pandora FMS Agent for Windows Platform" - VALUE "LegalCopyright", "Artica ST" + VALUE "LegalCopyright", "Pandora FMS" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.772(Build 230714))" + VALUE "ProductVersion", "(7.0NG.772(Build 230731))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 178e7e5759..2edba2be84 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,10 +1,10 @@ package: pandorafms-console -Version: 7.0NG.772-230714 +Version: 7.0NG.772-230731 Architecture: all Priority: optional Section: admin Installed-Size: 42112 -Maintainer: Artica ST +Maintainer: Pandora FMS Homepage: https://pandorafms.com/ Depends: php, php-snmp, php-gd, php-mysqlnd, php-db, php-xmlrpc, php-curl, graphviz, dbconfig-common, php-ldap, mysql-client | virtual-mysql-client, php-xmlrpc, php-zip, php-mbstring Description: Pandora FMS is an Open Source monitoring tool. It monitor your systems and applications, and allows you to control the status of any element of them. The web console is the graphical user interface (GUI) to manage the pool and to generate reports and graphs from the Pandora FMS monitoring process. diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 7ce4a5b8fa..88f61b7499 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.772-230714" +pandora_version="7.0NG.772-230731" package_pear=0 package_pandora=1 @@ -163,7 +163,7 @@ if [ $package_pear -eq 1 ] then echo "Make the package \"php-xml-rpc\"." cd temp_package - dh-make-pear --maintainer "ÁRTICA ST " XML_RPC + dh-make-pear --maintainer "Pandora FMS " XML_RPC cd php-xml-rpc-* dpkg-buildpackage -rfakeroot cd .. diff --git a/pandora_console/composer.lock b/pandora_console/composer.lock index d7a05579a9..cf6f9f2502 100644 --- a/pandora_console/composer.lock +++ b/pandora_console/composer.lock @@ -609,7 +609,7 @@ } ], "description": "PHP library for ChartJS", - "homepage": "https://artica.es/", + "homepage": "https://pandorafms.com/", "keywords": [ "chartjs", "graph", diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index 0c0e0bd7fc..5d603ac1f9 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -1692,3 +1692,14 @@ enterprise/godmode/modules/manage_inventory_modules_form.php enterprise/operation/inventory/inventory.php include/test.js include/web2image.js +enterprise/meta/monitoring/wizard/wizard.agent.php +enterprise/meta/monitoring/wizard/wizard.create_agent.php +enterprise/meta/monitoring/wizard/wizard.create_module.php +enterprise/meta/monitoring/wizard/wizard.main.php +enterprise/meta/monitoring/wizard/wizard.manage_alert.php +enterprise/meta/monitoring/wizard/wizard.module.local.php +enterprise/meta/monitoring/wizard/wizard.module.network.php +enterprise/meta/monitoring/wizard/wizard.module.web.php +enterprise/meta/monitoring/wizard/wizard.php +enterprise/meta/monitoring/wizard/wizard.update_agent.php +enterprise/meta/monitoring/wizard/wizard.update_module.php \ No newline at end of file diff --git a/pandora_console/extras/mr/65.sql b/pandora_console/extras/mr/65.sql index d635c9b002..67efb5b908 100644 --- a/pandora_console/extras/mr/65.sql +++ b/pandora_console/extras/mr/65.sql @@ -1,5 +1,67 @@ START TRANSACTION; +CREATE TABLE IF NOT EXISTS `tdiscovery_apps` ( + `id_app` int(10) auto_increment, + `short_name` varchar(250) NOT NULL DEFAULT '', + `name` varchar(250) NOT NULL DEFAULT '', + `section` varchar(250) NOT NULL DEFAULT 'custom', + `description` varchar(250) NOT NULL DEFAULT '', + `version` varchar(250) NOT NULL DEFAULT '', + PRIMARY KEY (`id_app`), + UNIQUE (`short_name`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +CREATE TABLE IF NOT EXISTS `tdiscovery_apps_scripts` ( + `id_app` int(10), + `macro` varchar(250) NOT NULL DEFAULT '', + `value` text NOT NULL DEFAULT '', + PRIMARY KEY (`id_app`, `macro`), + FOREIGN KEY (`id_app`) REFERENCES tdiscovery_apps(`id_app`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +CREATE TABLE IF NOT EXISTS `tdiscovery_apps_executions` ( + `id` int(10) unsigned NOT NULL auto_increment, + `id_app` int(10), + `execution` text NOT NULL DEFAULT '', + PRIMARY KEY (`id`, `id_app`), + FOREIGN KEY (`id_app`) REFERENCES tdiscovery_apps(`id_app`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +CREATE TABLE IF NOT EXISTS `tdiscovery_apps_tasks_macros` ( + `id_task` int(10) unsigned NOT NULL, + `macro` varchar(250) NOT NULL DEFAULT '', + `type` varchar(250) NOT NULL DEFAULT 'custom', + `value` text NOT NULL DEFAULT '', + `temp_conf` tinyint unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`id_task`, `macro`), + FOREIGN KEY (`id_task`) REFERENCES trecon_task(`id_rt`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + + +ALTER TABLE `trecon_task` + ADD COLUMN `id_app` int(10), + ADD COLUMN `setup_complete` tinyint unsigned NOT NULL DEFAULT 0, + ADD COLUMN `executions_timeout` int unsigned NOT NULL DEFAULT 60, + ADD FOREIGN KEY (`id_app`) REFERENCES tdiscovery_apps(`id_app`) ON DELETE CASCADE ON UPDATE CASCADE; + +CREATE TABLE IF NOT EXISTS `tnetwork_explorer_filter` ( +`id` INT NOT NULL, +`filter_name` VARCHAR(45) NULL, +`top` VARCHAR(45) NULL, +`action` VARCHAR(45) NULL, +`advanced_filter` TEXT NULL, +PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +CREATE TABLE IF NOT EXISTS `tnetwork_usage_filter` ( +`id` INT NOT NULL auto_increment, +`filter_name` VARCHAR(45) NULL, +`top` VARCHAR(45) NULL, +`action` VARCHAR(45) NULL, +`advanced_filter` TEXT NULL, +PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + ALTER TABLE `tlayout` ADD COLUMN `grid_color` VARCHAR(45) NOT NULL DEFAULT '#cccccc' AFTER `maintenance_mode`, ADD COLUMN `grid_size` VARCHAR(45) NOT NULL DEFAULT '10' AFTER `grid_color`; @@ -8,6 +70,7 @@ ALTER TABLE `tlayout_template` ADD COLUMN `grid_color` VARCHAR(45) NOT NULL DEFAULT '#cccccc' AFTER `maintenance_mode`, ADD COLUMN `grid_size` VARCHAR(45) NOT NULL DEFAULT '10' AFTER `grid_color`; + DELETE FROM tconfig WHERE token = 'refr'; INSERT INTO `tmodule_inventory` (`id_module_inventory`, `id_os`, `name`, `description`, `interpreter`, `data_format`, `code`, `block_mode`,`script_mode`) VALUES (37,2,'CPU','CPU','','Brand;Clock;Model','',0,2); diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 646e40481e..36090b9446 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -34,6 +34,22 @@ echo sprintf('
', $menuTypeClass); $notifications_numbers['notifications'], $notifications_numbers['last_id'] ).'
'; + $header_welcome = ''; + if (check_acl($config['id_user'], $group, 'AW')) { + $header_welcome .= '
'; + $header_welcome .= html_print_image( + 'images/wizard@svg.svg', + true, + [ + 'class' => 'main_menu_icon invert_filter', + 'title' => __('Welcome dialog'), + 'id' => 'Welcome-dialog', + 'alt' => __('Welcome dialog'), + 'style' => 'cursor: pointer;', + ] + ); + $header_welcome .= '
'; + } // ======= Servers List =============================================== if ((bool) check_acl($config['id_user'], 0, 'AW') !== false) { @@ -217,11 +233,8 @@ echo sprintf('
', $menuTypeClass); $header_autorefresh = ''; $header_autorefresh_counter = ''; - if ($config['legacy_vc'] - || ($_GET['sec2'] !== 'operation/visual_console/render_view') - || (($_GET['sec2'] !== 'operation/visual_console/render_view') - && $config['legacy_vc']) - ) { + + if (($_GET['sec2'] !== 'operation/visual_console/render_view')) { if ($autorefresh_list !== null && array_search($_GET['sec2'], $autorefresh_list) !== false ) { @@ -461,7 +474,7 @@ echo sprintf('
', $menuTypeClass); } else { echo '
'.$config['custom_title_header'].''.$config['custom_subtitle_header'].'
'.$header_searchbar.'
-
'.$header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'
'; +
'.$header_autorefresh, $header_autorefresh_counter, $header_discovery, $header_welcome, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'
'; } ?>
@@ -904,6 +917,44 @@ echo sprintf('
', $menuTypeClass); $("#agent_access").css("display",""); }); + $("#welcome-icon-header").click(function () { + if (!$('#welcome_modal_window').length){ + $(document.body).append('
'); + $(document.body).append( $('').attr('href', 'include/styles/new_installation_welcome_window.css') ); + } + // Clean DOM. + load_modal({ + target: $('#welcome_modal_window'), + url: '', + modal: { + title: "", + cancel: '', + ok: '' + }, + onshow: { + page: 'include/ajax/welcome_window', + method: 'loadWelcomeWindow', + }, + oncancel: { + page: 'include/ajax/welcome_window', + title: "", + method: 'cancelWelcome', + confirm: function (fn) { + confirmDialog({ + title: '', + message: '', + ok: '', + cancel: '', + onAccept: function() { + // Continue execution. + fn(); + } + }) + } + } + }); + }); + // Feedback. $("#feedback-header").click(function () { diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 96f9232dab..759e319dbd 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -100,21 +100,23 @@ if ($initial && users_is_admin()) { ); } -$welcome = !$initial; -try { - $welcome_window = new WelcomeWindow($welcome); - if ($welcome_window !== null) { - $welcome_window->run(); +if (check_acl($config['id_user'], 0, 'AW')) { + $welcome = !$initial; + try { + $welcome_window = new WelcomeWindow($welcome); + if ($welcome_window !== null) { + $welcome_window->run(); + } + } catch (Exception $e) { + $welcome = false; } -} catch (Exception $e) { - $welcome = false; } try { if (isset($_SESSION['showed_tips_window']) === false) { $tips_window = new TipsWindow(); if ($tips_window !== null) { - $tips_window->run(); + $tips_window->run(); } } } catch (Exception $e) { diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index b161b7ff6d..cbe7858e9e 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -212,7 +212,7 @@ $groups = users_get_groups($config['id_user'], 'AR', false); // Get modules. $modules = db_get_all_rows_sql( 'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo - WHERE id_agente = '.$id_parent + WHERE id_agente = '.$id_agente ); $modules_values = []; $modules_values[0] = __('Any'); @@ -300,7 +300,7 @@ if (enterprise_installed() === true) { // Parent agents. $paramsParentAgent = []; $paramsParentAgent['return'] = true; -$paramsParentAgent['show_helptip'] = false; +$paramsParentAgent['show_helptip'] = true; $paramsParentAgent['input_name'] = 'id_parent'; $paramsParentAgent['print_hidden_input_idagent'] = true; $paramsParentAgent['hidden_input_idagent_name'] = 'id_agent_parent'; @@ -646,7 +646,7 @@ if (enterprise_installed() === true) { // Parent agent. $tableAdvancedAgent->data['parent_agent'][] = html_print_label_input_block( - __('Parent'), + __('Agent parent'), ui_print_agent_autocomplete_input($paramsParentAgent) ); @@ -1205,15 +1205,30 @@ ui_require_jquery_file('bgiframe'); $("#cascade_protection_module").attr("disabled", 'disabled'); } - $("#checkbox-cascade_protection").change(function () { - var checked = $("#checkbox-cascade_protection").is(":checked"); - - if (checked) { + $("#text-id_parent").change(function(){ + const parent = $("#text-id_parent").val(); + if (parent != '') { + $("#checkbox-cascade_protection").prop('checked', true); $("#cascade_protection_module").removeAttr("disabled"); } else { $("#cascade_protection_module").val(0); $("#cascade_protection_module").attr("disabled", 'disabled'); + $("#text-id_parent").removeAttr("required"); + $("#cascade_protection_module").empty(); + $("#checkbox-cascade_protection").prop('checked', false); + } + }); + + $("#checkbox-cascade_protection").change(function () { + var checked = $("#checkbox-cascade_protection").is(":checked"); if (checked) { + $("#cascade_protection_module").removeAttr("disabled"); + $("#text-id_parent").attr("required", "required"); + } + else { + $("#cascade_protection_module").val(0); + $("#cascade_protection_module").attr("disabled", 'disabled'); + $("#text-id_parent").removeAttr("required"); } }); diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 163fc16af8..9c080fcf3f 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -80,7 +80,7 @@ if (isset($_POST['template_id']) === true) { $values = [ 'id_agente' => $id_agente, 'id_tipo_modulo' => $row2['type'], - 'descripcion' => __('Created by template ').$name_template.' . '.$row2['description'], + 'descripcion' => $row2['description'], 'max' => $row2['max'], 'min' => $row2['min'], 'module_interval' => $row2['module_interval'], diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c68d483eaf..b07fb5ca4f 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -460,6 +460,18 @@ if ($id_agente) { $templatetab['active'] = ($tab === 'template'); + // Policy tab. + $policyTab['text'] = html_print_menu_button( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=policy&id_agente='.$id_agente, + 'image' => 'images/policy@svg.svg', + 'title' => __('Manage policy'), + ], + true + ); + + $policyTab['active'] = ($tab === 'policy'); + // Inventory. $inventorytab['text'] = ''.html_print_image( 'images/hardware-software-component@svg.svg', @@ -638,6 +650,7 @@ if ($id_agente) { 'template' => $templatetab, 'inventory' => $inventorytab, 'pluginstab' => $pluginstab, + 'policy' => (enterprise_installed() === true) ? $policyTab : '', 'collection' => $collectiontab, 'group' => $grouptab, 'gis' => $gistab, @@ -654,11 +667,11 @@ if ($id_agente) { 'template' => $templatetab, 'inventory' => $inventorytab, 'pluginstab' => $pluginstab, + 'policy' => (enterprise_installed() === true) ? $policyTab : '', 'collection' => $collectiontab, 'group' => $grouptab, 'gis' => $gistab, 'agent_wizard' => $agent_wizard, - ]; } @@ -725,6 +738,11 @@ if ($id_agente) { $tab_name = __('Inventory'); break; + case 'policy': + $help_header = 'policy_tab'; + $tab_name = __('Policies'); + break; + case 'plugins': $help_header = 'plugins_tab'; $tab_name = __('Agent plugins'); @@ -2428,6 +2446,10 @@ switch ($tab) { include 'inventory_manager.php'; break; + case 'policy': + enterprise_include('operation/agentes/policy_manager.php'); + break; + default: if (enterprise_hook('switch_agent_tab', [$tab])) { // This will make sure that blank pages will have at least some diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 4f28d256cd..9021514178 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -1072,16 +1072,20 @@ if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { function () { $(".actions", this).css ("visibility", "hidden"); }); - + $("#ag_group").click ( function () { $(this).css ("width", "auto"); $(this).css ("min-width", "100px"); }); - + $("#ag_group").blur (function () { $(this).css ("width", "100px"); }); - + + var show_deploy_agent = ""; + if (show_deploy_agent !== '0'){ + $('#button-modal_deploy_agent').click(); + } }); diff --git a/pandora_console/godmode/agentes/planned_downtime.list.php b/pandora_console/godmode/agentes/planned_downtime.list.php index a9a65bc834..959db70ed6 100755 --- a/pandora_console/godmode/agentes/planned_downtime.list.php +++ b/pandora_console/godmode/agentes/planned_downtime.list.php @@ -89,7 +89,7 @@ if (is_ajax() === true) { [ 'id' => 'agent_modules_affected_planned_downtime', 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'godmode/agentes/planned_downtime.list', diff --git a/pandora_console/godmode/category/category.php b/pandora_console/godmode/category/category.php index 9872a002f5..46095b6efb 100755 --- a/pandora_console/godmode/category/category.php +++ b/pandora_console/godmode/category/category.php @@ -184,7 +184,7 @@ if (empty($result) === false) { ] ).'  '; $data[1] .= ''.html_print_image( - 'images/delet.svg', + 'images/delete.svg', true, [ 'title' => __('Delete'), diff --git a/pandora_console/godmode/groups/tactical.php b/pandora_console/godmode/groups/tactical.php index 067bed45be..0b09cbc789 100644 --- a/pandora_console/godmode/groups/tactical.php +++ b/pandora_console/godmode/groups/tactical.php @@ -187,7 +187,7 @@ try { [ 'id' => 'list_agents_tactical', 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columnNames, 'return' => true, diff --git a/pandora_console/godmode/massive/massive_delete_agents.php b/pandora_console/godmode/massive/massive_delete_agents.php index 5bb84b62be..1dc6397cc6 100755 --- a/pandora_console/godmode/massive/massive_delete_agents.php +++ b/pandora_console/godmode/massive/massive_delete_agents.php @@ -189,6 +189,14 @@ echo get_table_inputs_masive_agents($params); if (is_metaconsole() === true || is_management_allowed() === true) { attachActionButton('delete', 'delete', '100%', false, $SelectAction); +} else { + html_print_action_buttons( + '', + [ + 'right_content' => $SelectAction, + 'class' => 'pdd_t_15px_important pdd_b_15px_important', + ] + ); } echo ''; diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 4a0daaeed3..3f8ade2b1a 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -30,6 +30,7 @@ // Begin. require_once 'include/config.php'; require_once 'include/functions_menu.php'; +require_once $config['homedir'].'/godmode/wizards/ManageExtensions.class.php'; check_login(); @@ -78,15 +79,97 @@ if ((bool) check_acl($config['id_user'], 0, 'AR') === true } if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { - enterprise_hook('applications_menu'); - enterprise_hook('cloud_menu'); - } + // Applications. + $sub2 = []; + if (enterprise_installed() === true) { + $sub2['godmode/servers/discovery&wiz=app&mode=MicrosoftSQLServer']['text'] = __('Microsoft SQL Server'); + $sub2['godmode/servers/discovery&wiz=app&mode=mysql']['text'] = __('Mysql'); + $sub2['godmode/servers/discovery&wiz=app&mode=oracle']['text'] = __('Oracle'); + $sub2['godmode/servers/discovery&wiz=app&mode=vmware']['text'] = __('VMware'); + $sub2['godmode/servers/discovery&wiz=app&mode=SAP']['text'] = __('SAP'); + $sub2['godmode/servers/discovery&wiz=app&mode=DB2']['text'] = __('DB2'); + } - if ((bool) check_acl($config['id_user'], 0, 'RW') === true - || (bool) check_acl($config['id_user'], 0, 'RM') === true - || (bool) check_acl($config['id_user'], 0, 'PM') === true - ) { - enterprise_hook('console_task_menu'); + $extensions = ManageExtensions::getExtensionBySection('app'); + if ($extensions !== false) { + foreach ($extensions as $key => $extension) { + $url = sprintf( + 'godmode/servers/discovery&wiz=app&mode=%s', + $extension['short_name'] + ); + $sub2[$url]['text'] = __($extension['name']); + } + } + + if ($extensions !== false || enterprise_installed() === true) { + $sub['godmode/servers/discovery&wiz=app']['text'] = __('Applications'); + $sub['godmode/servers/discovery&wiz=app']['id'] = 'app'; + $sub['godmode/servers/discovery&wiz=app']['type'] = 'direct'; + $sub['godmode/servers/discovery&wiz=app']['subtype'] = 'nolink'; + $sub['godmode/servers/discovery&wiz=app']['sub2'] = $sub2; + } + + // Cloud. + $sub2 = []; + if (enterprise_installed() === true) { + $sub2['godmode/servers/discovery&wiz=cloud&mode=amazonws']['text'] = __('Amazon Web Services'); + $sub2['godmode/servers/discovery&wiz=cloud&mode=azure']['text'] = __('Microsoft Azure'); + $sub2['godmode/servers/discovery&wiz=cloud&mode=gcp']['text'] = __('Google Compute Platform'); + } + + + $extensions = ManageExtensions::getExtensionBySection('cloud'); + if ($extensions !== false) { + foreach ($extensions as $key => $extension) { + $url = sprintf( + 'godmode/servers/discovery&wiz=cloud&mode=%s', + $extension['short_name'] + ); + $sub2[$url]['text'] = __($extension['name']); + } + } + + if ($extensions !== false || enterprise_installed() === true) { + $sub['godmode/servers/discovery&wiz=cloud']['text'] = __('Cloud'); + $sub['godmode/servers/discovery&wiz=cloud']['id'] = 'cloud'; + $sub['godmode/servers/discovery&wiz=cloud']['type'] = 'direct'; + $sub['godmode/servers/discovery&wiz=cloud']['subtype'] = 'nolink'; + $sub['godmode/servers/discovery&wiz=cloud']['sub2'] = $sub2; + } + + // Custom. + $sub2 = []; + $extensions = ManageExtensions::getExtensionBySection('custom'); + if ($extensions !== false) { + foreach ($extensions as $key => $extension) { + $url = sprintf( + 'godmode/servers/discovery&wiz=custom&mode=%s', + $extension['short_name'] + ); + $sub2[$url]['text'] = __($extension['name']); + } + + $sub['godmode/servers/discovery&wiz=custom']['text'] = __('Custom'); + $sub['godmode/servers/discovery&wiz=custom']['id'] = 'customExt'; + $sub['godmode/servers/discovery&wiz=custom']['type'] = 'direct'; + $sub['godmode/servers/discovery&wiz=custom']['subtype'] = 'nolink'; + $sub['godmode/servers/discovery&wiz=custom']['sub2'] = $sub2; + } + + if (check_acl($config['id_user'], 0, 'RW') + || check_acl($config['id_user'], 0, 'RM') + || check_acl($config['id_user'], 0, 'PM') + ) { + $sub['godmode/servers/discovery&wiz=magextensions']['text'] = __('Manage disco packages'); + $sub['godmode/servers/discovery&wiz=magextensions']['id'] = 'mextensions'; + } + + if ((bool) check_acl($config['id_user'], 0, 'RW') === true + || (bool) check_acl($config['id_user'], 0, 'RM') === true + || (bool) check_acl($config['id_user'], 0, 'PM') === true + ) { + enterprise_hook('console_task_menu'); + } } } @@ -174,6 +257,13 @@ if ($access_console_node === true) { } $sub = []; + if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { + $sub['wizard']['text'] = __('Configuration wizard'); + $sub['wizard']['id'] = 'conf_wizard'; + $sub['wizard']['type'] = 'direct'; + $sub['wizard']['subtype'] = 'nolink_no_arrow'; + } + if ((bool) check_acl($config['id_user'], 0, 'PM') === true) { $sub['templates']['text'] = __('Templates'); $sub['templates']['id'] = 'Templates'; @@ -495,9 +585,13 @@ if ($access_console_node === true) { $sub2[$extmenu['sec2']]['refr'] = 0; } else { if (is_array($extmenu) === true && array_key_exists('fatherId', $extmenu) === true) { - if (strlen($extmenu['fatherId']) > 0) { + if (empty($extmenu['fatherId']) === false + && strlen($extmenu['fatherId']) > 0 + ) { if (array_key_exists('subfatherId', $extmenu) === true) { - if (strlen($extmenu['subfatherId']) > 0) { + if (empty($extmenu['subfatherId']) === false + && strlen($extmenu['subfatherId']) > 0 + ) { $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['subfatherId']]['sub2'][$extmenu['sec2']]['text'] = __($extmenu['name']); $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['subfatherId']]['sub2'][$extmenu['sec2']]['id'] = str_replace(' ', '_', $extmenu['name']); $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['subfatherId']]['sub2'][$extmenu['sec2']]['refr'] = 0; @@ -620,3 +714,55 @@ if ((bool) $config['pure'] === false) { } echo '
'; +// Need to be here because the translate string. +if (check_acl($config['id_user'], $group, 'AW')) { + ?> + + + '; + + $offset = (int) get_parameter('offset', 0); + $block_size = (int) $config['block_size']; + + $tablePagination = ui_pagination( + count($graphs), + false, + $offset, + $block_size, + true, + 'offset', + false + ); } // FALTA METER EL PRINT TABLE. html_print_table($table); - html_print_action_buttons( - implode('', $ActionButtons), - ['type' => 'form_action'] - ); + + if (is_metaconsole() === true) { + html_print_action_buttons( + implode('', $ActionButtons), + ['type' => 'form_action'] + ); + } else { + html_print_action_buttons( + implode('', $ActionButtons), + [ + 'type' => 'form_action', + 'right_content' => $tablePagination, + ] + ); + } } echo '
'; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 64fa992e76..397e533366 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -38,6 +38,9 @@ require_once $config['homedir'].'/include/db/oracle.php'; // Login check. check_login(); +// Validate enterprise. +$is_enterprise = enterprise_installed(); + if (! check_acl($config['id_user'], 0, 'RW') && ! check_acl($config['id_user'], 0, 'RM') ) { @@ -3682,25 +3685,28 @@ $class = 'databox filters'; ?> - - - - - - - - - - + + + + + + + + + + + + - - - - + } + ?> '.__('Filters').'', 'filter_form', '', - false, + true, false, '', 'white-box-content', @@ -1251,7 +1254,12 @@ switch ($action) { array_push($table->data, $data); } - html_print_table($table); + $reports_table = '
'; + $reports_table .= ''.__('Reports').''; + $reports_table .= html_print_table($table, true); + $reports_table .= '
'; + echo $reports_table; + $tablePagination = ui_pagination( $total_reports, $url, @@ -1259,7 +1267,7 @@ switch ($action) { $pagination, true, 'offset', - false, + false ); } else { ui_print_info_message( @@ -1270,6 +1278,21 @@ switch ($action) { ); } + $discovery_tasklist = new DiscoveryTaskList(); + $report_task_data = $discovery_tasklist->showListConsoleTask(true); + + if (is_array($report_task_data) === true || strpos($report_task_data, 'class="nf"') === false) { + $task_table = '
'; + $task_table .= ''.__('Report tasks'); + $task_table .= ui_print_help_tip(__('To schedule a report, do it from the editing view of each report.'), true); + $task_table .= '
'; + $task_table .= $report_task_data; + $task_table .= '
'; + echo $task_table; + } else { + ui_print_info_message($report_task_data.__('To schedule a report, do it from the editing view of each report.')); + } + if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM') ) { diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 740b97708a..9988704695 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -837,12 +837,6 @@ $buttons['wizard'] = [ 'active' => false, 'text' => '
'.html_print_image('images/wizard@svg.svg', true, ['title' => __('Wizard'), 'class' => 'invert_filter']).'', ]; -if ($config['legacy_vc']) { - $buttons['editor'] = [ - 'active' => false, - 'text' => ''.html_print_image('images/builder@svg.svg', true, ['title' => __('Builder'), 'class' => 'invert_filter']).'', - ]; -} $buttons['view'] = [ 'active' => false, diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 3df3342f52..9af4343a84 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -53,6 +53,12 @@ function get_wiz_class($str) case 'deploymentCenter': return 'DeploymentCenter'; + case 'magextensions': + return 'ManageExtensions'; + + case 'custom': + return 'Custom'; + default: // Main, show header. ui_print_standard_header( @@ -161,7 +167,7 @@ if ($classname_selected === null) { $wiz_data = []; foreach ($classes as $classpath) { if (is_reporting_console_node() === true) { - if ($classpath !== '/var/www/html/pandora_console/godmode/wizards/DiscoveryTaskList.class.php') { + if ($classpath !== $config['homedir'].'/godmode/wizards/DiscoveryTaskList.class.php') { continue; } } @@ -169,6 +175,12 @@ if ($classname_selected === null) { $classname = basename($classpath, '.class.php'); $obj = new $classname(); + if (method_exists($obj, 'isEmpty') === true) { + if ($obj->isEmpty() === true) { + continue; + } + } + $button = $obj->load(); if ($button === false) { diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index acc9ad7665..34ce122954 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -212,7 +212,7 @@ if (isset($_GET['server']) === true) { false, 'servers', true, - [], + $buttons, [ [ 'link' => '', diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 04b622e312..315702528e 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -560,7 +560,14 @@ if (empty($create) === false || empty($view) === false) { // $data[0] = html_print_div(['id' => 'command_preview', 'class' => 'mono'], true); $data[0] = html_print_label_input_block( __('Command preview'), - html_print_div(['id' => 'command_preview', 'class' => 'mono'], true) + html_print_div( + [ + 'id' => 'command_preview', + 'class' => 'mono', + 'style' => 'max-width: 1050px;overflow-wrap: break-word;', + ], + true + ) ); $table->data['plugin_preview_inputs'] = $data; $table->colspan['plugin_preview_inputs'][0] = 2; diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index cce4e1e053..35cd540e6a 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -101,6 +101,13 @@ foreach ($servers as $server) { } } +$ext = ''; + +// Check for any data-type server present in servers list. If none, enable server access for first server. +if (array_search('data', array_column($servers, 'type')) === false) { + $ext = '_server'; +} + foreach ($servers as $server) { $data = []; @@ -185,14 +192,12 @@ foreach ($servers as $server) { $data[7] = ui_print_timestamp($server['keepalive'], true); - - $ext = '_server'; - if ($server['type'] != 'data') { - $ext = ''; + if ($server['type'] === 'data') { + $ext = '_server'; } $safe_server_name = servers_get_name($server['id_server']); - if (($server['type'] == 'data' || $server['type'] == 'enterprise satellite')) { + if (($ext === '_server' || $server['type'] == 'enterprise satellite')) { if (servers_check_remote_config($safe_server_name.$ext) && enterprise_installed()) { $names_servers[$safe_server_name] = true; } else { @@ -253,7 +258,7 @@ foreach ($servers as $server) { ); $data[8] .= ''; - if (($names_servers[$safe_server_name] === true) && ($server['type'] === 'data' || $server['type'] === 'enterprise satellite')) { + if (($names_servers[$safe_server_name] === true) && ($ext === '_server' || $server['type'] === 'enterprise satellite')) { $data[8] .= ''; $data[8] .= html_print_image( 'images/agents@svg.svg', @@ -298,6 +303,8 @@ foreach ($servers as $server) { unset($data[8]); } + $ext = ''; + array_push($table->data, $data); } diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 0cd6c53d2d..51cd554a66 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -545,23 +545,8 @@ $table->data[6][0] = html_print_label_input_block( ) ); -$table->data[6][1] = html_print_label_input_block( - __('Max. days before delete old network matrix data'), - html_print_input( - [ - 'type' => 'number', - 'size' => 5, - 'max' => $performance_variables_control['delete_old_network_matrix']->max, - 'name' => 'delete_old_network_matrix', - 'value' => $config['delete_old_network_matrix'], - 'return' => true, - 'min' => $performance_variables_control['delete_old_network_matrix']->min, - ] - ) -); - if (enterprise_installed()) { - $table->data[7][0] = html_print_label_input_block( + $table->data[6][1] = html_print_label_input_block( __('Max. days before delete inventory data'), html_print_input_text( 'inventory_purge', @@ -574,6 +559,18 @@ if (enterprise_installed()) { ); } +$table->data[7][1] = html_print_label_input_block( + __('Max. days before disabled agents are deleted'), + html_print_input_text( + 'delete_disabled_agents', + $config['delete_disabled_agents'], + '', + false, + 0, + true + ) +); + $table_other = new stdClass(); $table_other->width = '100%'; $table_other->class = 'filter-table-adv'; diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php index c8413d670e..6616cd765c 100644 --- a/pandora_console/godmode/setup/setup_auth.php +++ b/pandora_console/godmode/setup/setup_auth.php @@ -210,7 +210,7 @@ if (is_ajax() === true) { // Ldapsearch timeout. // Default Ldapsearch timeout. - set_when_empty($config['ldap_searh_timeout'], 5); + set_when_empty($config['ldap_search_timeout'], 5); $row = []; $row['name'] = __('Ldap search timeout (secs)'); $row['control'] = html_print_input_text( @@ -558,7 +558,13 @@ echo ''; if ($('input[type=checkbox][name=secondary_ldap_enabled]:checked').val() == 1) { $("tr[id*='ldap_'][id$='_secondary']").show(); } else { - $( "tr[id*='ldap_'][id$='_secondary']" ).hide(); + $( "tr[id*='ldap_'][id$='_secondary']" ).hide(); + } + + if ($('input[type=checkbox][name=secondary_active_directory]:checked').val() == 1) { + $("tr[id*='ad_'][id$='_secondary']").show(); + } else { + $( "tr[id*='ad_'][id$='_secondary']" ).hide(); } } $( document ).ready(function() { diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 6d7d53a942..110281096e 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -747,6 +747,16 @@ $table->data[$i][] = html_print_label_input_block( ) ); +$table->data[$i][] = html_print_label_input_block( + __('Show experimental features'), + html_print_checkbox_switch( + 'show_experimental_features', + 1, + $config['show_experimental_features'], + true + ) +); + echo '
'; echo '
'; diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 96856a2f32..a7b64a67d7 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -1344,17 +1344,6 @@ $table_vc->style[0] = 'font-weight: bold'; $table_vc->size[0] = '50%'; $table_vc->data = []; -// Remove when the new view reaches rock solid stability. -$table_vc->data[$row][] = html_print_label_input_block( - __('Legacy Visual Console View'), - html_print_checkbox_switch( - 'legacy_vc', - 1, - (bool) $config['legacy_vc'], - true - ) -); - $table_vc->data[$row][] = html_print_label_input_block( __('Default cache expiration'), html_print_extended_select_for_time( @@ -1372,7 +1361,6 @@ $table_vc->data[$row][] = html_print_label_input_block( $intervals ) ); -$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Default interval for refresh on Visual Console'), @@ -1388,6 +1376,7 @@ $table_vc->data[$row][] = html_print_label_input_block( false ) ); +$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Type of view of visual consoles'), @@ -1401,12 +1390,12 @@ $table_vc->data[$row][] = html_print_label_input_block( true ) ); -$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Number of favorite visual consoles to show in the menu'), "" ); +$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Default line thickness for the Visual Console'), @@ -1419,7 +1408,6 @@ $table_vc->data[$row][] = html_print_label_input_block( true ) ); -$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Lock screen orientation when viewing on mobile devices'), @@ -1430,6 +1418,7 @@ $table_vc->data[$row][] = html_print_label_input_block( true ) ); +$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Display item frame on alert triggered'), diff --git a/pandora_console/godmode/update_manager/update_manager.history.php b/pandora_console/godmode/update_manager/update_manager.history.php index e827951e88..7caab40f8b 100644 --- a/pandora_console/godmode/update_manager/update_manager.history.php +++ b/pandora_console/godmode/update_manager/update_manager.history.php @@ -50,7 +50,7 @@ try { [ 'id' => $tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'include/ajax/update_manager', diff --git a/pandora_console/godmode/wizards/Applications.class.php b/pandora_console/godmode/wizards/Applications.class.php new file mode 100644 index 0000000000..2237fdbe73 --- /dev/null +++ b/pandora_console/godmode/wizards/Applications.class.php @@ -0,0 +1,221 @@ +setBreadcrum([]); + + $this->access = 'AW'; + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->class = $class_style; + $this->label = $label; + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app' + ); + + return $this; + } + + + /** + * Run wizard manager. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + + // Load current wiz. sub-styles. + ui_require_css_file( + 'application', + ENTERPRISE_DIR.'/include/styles/wizards/' + ); + + $mode = get_parameter('mode', null); + + // Load application wizards. + $enterprise_classes = glob( + $config['homedir'].'/'.ENTERPRISE_DIR.'/include/class/*.app.php' + ); + $extensions = new ExtensionsDiscovery('app', $mode); + + foreach ($enterprise_classes as $classpath) { + enterprise_include_once( + 'include/class/'.basename($classpath) + ); + } + + switch ($mode) { + case 'DB2': + $classname_selected = 'DB2'; + break; + + case 'SAP': + $classname_selected = 'SAP'; + break; + + case 'vmware': + $classname_selected = 'VMware'; + break; + + case 'mysql': + $classname_selected = 'MySQL'; + break; + + case 'oracle': + $classname_selected = 'Oracle'; + break; + + case 'MicrosoftSQLServer': + $classname_selected = 'MicrosoftSQLServer'; + break; + + default: + $classname_selected = null; + break; + } + + // Else: class not found pseudo exception. + if ($classname_selected !== null) { + $wiz = new $classname_selected($this->page); + $result = $wiz->run(); + if (is_array($result) === true) { + return $result; + } + } + + if ($classname_selected === null) { + if ($mode !== null) { + // Load extension if exist. + $extensions->run(); + return; + } + + // Load classes and print selector. + $wiz_data = []; + foreach ($enterprise_classes as $classpath) { + $classname = basename($classpath, '.app.php'); + $obj = new $classname(); + $wiz_data[] = $obj->load(); + } + + $wiz_data = array_merge($wiz_data, $extensions->loadExtensions()); + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app' + ), + 'label' => __('Applications'), + 'selected' => true, + ], + ] + ); + + // Header. + ui_print_page_header( + __('Applications'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + Wizard::printBigButtonsList($wiz_data); + + echo '
*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'
'; + } + + return $result; + } + + + /** + * Check if section have extensions. + * + * @return boolean Return true if section is empty. + */ + public function isEmpty() + { + $extensions = new ExtensionsDiscovery('app'); + $listExtensions = $extensions->getExtensionsApps(); + if ($listExtensions > 0 || enterprise_installed() === true) { + return false; + } else { + return true; + } + } + + +} diff --git a/pandora_console/godmode/wizards/Cloud.class.php b/pandora_console/godmode/wizards/Cloud.class.php new file mode 100644 index 0000000000..4664b1a566 --- /dev/null +++ b/pandora_console/godmode/wizards/Cloud.class.php @@ -0,0 +1,661 @@ +setBreadcrum([]); + + $this->access = 'AW'; + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->label = $label; + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=cloud' + ); + + return $this; + } + + + /** + * Run wizard manager. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + + // Load current wiz. sub-styles. + ui_require_css_file( + 'cloud', + ENTERPRISE_DIR.'/include/styles/wizards/' + ); + + $mode = get_parameter('mode', null); + + // Load cloud wizards. + $enterprise_classes = glob( + $config['homedir'].'/'.ENTERPRISE_DIR.'/include/class/*.cloud.php' + ); + $extensions = new ExtensionsDiscovery('cloud', $mode); + + foreach ($enterprise_classes as $classpath) { + enterprise_include_once( + 'include/class/'.basename($classpath) + ); + } + + switch ($mode) { + case 'amazonws': + $classname_selected = 'Aws'; + break; + + case 'azure': + $classname_selected = 'Azure'; + break; + + case 'gcp': + $classname_selected = 'Google'; + break; + + default: + $classname_selected = null; + break; + } + + // Else: class not found pseudo exception. + if ($classname_selected !== null) { + $wiz = new $classname_selected($this->page); + $result = $wiz->run(); + if (is_array($result) === true) { + return $result; + } + } + + if ($classname_selected === null) { + if ($mode !== null) { + // Load extension if exist. + $extensions->run(); + return; + } + + // Load classes and print selector. + $wiz_data = []; + foreach ($enterprise_classes as $classpath) { + $classname = basename($classpath, '.cloud.php'); + $obj = new $classname(); + $wiz_data[] = $obj->load(); + } + + $wiz_data = array_merge($wiz_data, $extensions->loadExtensions()); + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => $this->url, + 'label' => __('Cloud'), + 'selected' => true, + ], + ], + true + ); + + // Header. + ui_print_page_header( + __('Cloud'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + Wizard::printBigButtonsList($wiz_data); + + echo '
*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'
'; + } + + return $result; + } + + + /** + * Run credentials wizard. + * + * @return boolean True if credentials wizard is displayed and false if not. + */ + public function runCredentials() + { + global $config; + + if ($this->status === false) { + $empty_account = true; + } + + // Checks credentials. If check not passed. Show the form to fill it. + if ($this->checkCredentials()) { + return true; + } + + // Add breadcrum and print header. + $this->prepareBreadcrum( + [ + [ + 'link' => $this->url.'&credentials=1', + 'label' => __('%s credentials', $this->product), + 'selected' => true, + ], + ], + true + ); + // Header. + ui_print_page_header( + __('%s credentials', $this->product), + '', + false, + $this->product.'_credentials_tab', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + if ($this->product === 'Aws') { + ui_print_warning_message( + __( + 'If a task with the selected credentials is already running, it will be edited. To create a new one, another account from the credential store must be selected.' + ) + ); + } + + if ($this->status === true) { + ui_print_success_message($this->msg); + } else if ($this->status === false) { + ui_print_error_message($this->msg); + } + + if ($empty_account === true) { + ui_print_error_message($this->msg); + } + + $link_to_cs = ''; + if (check_acl($config['id_user'], 0, 'UM')) { + $link_to_cs = '
'; + $link_to_cs .= __('Manage accounts').''; + } + + $this->getCredentials(); + $this->printFormAsList( + [ + 'form' => [ + 'action' => $this->url, + 'method' => 'POST', + 'id' => 'form-credentials', + ], + 'inputs' => [ + [ + 'label' => __('Cloud tool full path'), + 'arguments' => [ + 'name' => 'cloud_util_path', + 'value' => isset($config['cloud_util_path']) ? io_safe_output($config['cloud_util_path']) : '/usr/bin/pandora-cm-api', + 'type' => 'text', + ], + ], + [ + 'label' => __('Account'), + 'extra' => $link_to_cs, + 'arguments' => [ + 'name' => 'account_identifier', + 'type' => 'select', + 'fields' => CredentialStore::getKeys($this->keyStoreType), + 'selected' => $this->keyIdentifier, + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'parse_credentials', + 'value' => 1, + 'type' => 'hidden', + 'return' => true, + ], + ], + ], + ] + ); + + $buttons_form = $this->printInput( + [ + 'name' => 'submit', + 'label' => __('Validate'), + 'type' => 'submit', + 'attributes' => [ + 'icon' => 'wand', + 'form' => 'form-credentials', + ], + 'return' => true, + 'width' => 'initial', + ] + ); + + $buttons_form .= $this->printGoBackButton( + ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=cloud' + ), + true + ); + + html_print_action_buttons($buttons_form); + return false; + } + + + /** + * Check credentials. + * + * @return boolean True if credentials are OK. + */ + public function checkCredentials() + { + global $config; + + $pandora = io_safe_output($config['cloud_util_path']); + + if (isset($pandora) === false) { + config_update_value('cloud_util_path', '/usr/bin/pandora-cm-api'); + } + + if ((bool) get_parameter('disconnect_account', false) === true) { + $this->status = null; + return false; + } + + if ($this->keyIdentifier === null) { + // Ask user for available credentials. + $this->msg = __('Select a set of credentials from the list'); + $this->status = null; + return false; + } + + $credentials = $this->getCredentials($this->keyIdentifier); + + if (empty($credentials['username']) === true + || empty($credentials['password']) === true + || isset($pandora) === false + || is_executable($pandora) === false + ) { + if (is_executable($pandora) === false) { + $this->msg = (__('Path %s is not executable.', $pandora)); + $this->status = false; + } else { + $this->msg = __('Invalid username or password'); + $this->status = false; + } + + return false; + } + + try { + $value = $this->executeCMCommand('--get availability'); + } catch (Exception $e) { + $this->msg = $e->getMessage(); + $this->status = false; + return false; + } + + if ($value == '1') { + return true; + } + + $this->status = false; + + // Error message directly from pandora-cm-api. + $this->msg = str_replace('"', '', $value); + + return false; + } + + + /** + * Handle the click on disconnect account link. + * + * @return void But it prints some info to user. + */ + protected function parseDisconnectAccount() + { + // Check if disconection account link is pressed. + if ((bool) get_parameter('disconnect_account') === false) { + return; + } + + $ret = $this->setCredentials(null); + if ($ret) { + $this->msg = __('Account disconnected'); + } else { + $this->msg = __('Failed disconnecting account'); + } + + $this->status = $ret; + $this->page = 0; + } + + + /** + * Build an array with Product credentials. + * + * @return array with credentials (pass and id). + */ + public function getCredentials() + { + return CredentialStore::getKey($this->keyIdentifier); + } + + + /** + * Set Product credentials. + * + * @param string|null $identifier Credential store identifier. + * + * @return boolean True if success. + */ + public function setCredentials($identifier) + { + if ($identifier === null) { + unset($this->keyIdentifier); + return true; + } + + if (isset($identifier) === false) { + return false; + } + + $all = CredentialStore::getKeys($this->type); + + if (in_array($identifier, $all) === true) { + $this->keyIdentifier = $identifier; + return true; + } + + return false; + } + + + /** + * Parse credentials form. + * + * @return void But it prints a message. + */ + protected function parseCredentials() + { + global $config; + + if (!$this->keyIdentifier) { + $this->setCredentials(get_parameter('ki', null)); + } + + // Check if credentials form is submitted. + if ((bool) get_parameter('parse_credentials') === false) { + return; + } + + $this->page = 0; + $ret = $this->setCredentials( + get_parameter('account_identifier') + ); + + $path = get_parameter('cloud_util_path'); + $ret_path = config_update_value('cloud_util_path', $path); + if ($ret_path) { + $config['cloud_util_path'] = $path; + } + + if ($ret && $ret_path) { + $this->msg = __('Credentials successfully updated'); + } else { + $this->msg = __('Failed updating credentials process'); + } + + $this->status = ($ret && $ret_path); + } + + + /** + * This method must be implemented. + * + * Execute a pandora-cm-api request. + * + * @param string $command Command to execute. + * + * @return void But must return string STDOUT of executed command. + * @throws Exception If not implemented. + */ + protected function executeCMCommand($command) + { + throw new Exception('executeCMCommand must be implemented.'); + } + + + /** + * Get a recon token value + * + * @param string $token The recon key to retrieve. + * + * @return string String with the value. + */ + protected function getConfigReconElement($token) + { + if ($this->reconConfig === false + || isset($this->reconConfig[0][$token]) === false + ) { + if (is_array($this->task) === true + && isset($this->task[$token]) === true + ) { + return $this->task[$token]; + } else { + return ''; + } + } else { + return $this->reconConfig[0][$token]; + } + } + + + /** + * Print global inputs + * + * @param boolean $last True if is last element. + * + * @return array Array with all global inputs. + */ + protected function getGlobalInputs(bool $last=false) + { + $task_id = $this->task['id_rt']; + if (!$task_id) { + $task_id = $this->getConfigReconElement('id_rt'); + } + + return [ + [ + 'arguments' => [ + 'name' => 'page', + 'value' => ($this->page + 1), + 'type' => 'hidden', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => ($last) ? __('Finish') : __('Next'), + 'type' => 'submit', + 'attributes' => 'class="sub '.(($last) ? 'wand' : 'next').'"', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'task', + 'value' => $task_id, + 'type' => 'hidden', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'parse_form', + 'value' => 1, + 'type' => 'hidden', + 'return' => true, + ], + ], + ]; + } + + + /** + * Print required css in some points. + * + * @return string With js code. + */ + protected function cloudJS() + { + return ' + function toggleCloudSubmenu(curr_elem, id_csm){ + if (document.getElementsByName(curr_elem)[0].checked){ + $("#li-"+id_csm).show(); + } else { + $("#li-"+id_csm).hide(); + } + }; + '; + } + + + /** + * Check if section have extensions. + * + * @return boolean Return true if section is empty. + */ + public function isEmpty() + { + $extensions = new ExtensionsDiscovery('cloud'); + $listExtensions = $extensions->getExtensionsApps(); + if ($listExtensions > 0 || enterprise_installed() === true) { + return false; + } else { + return true; + } + } + + +} diff --git a/pandora_console/godmode/wizards/Custom.class.php b/pandora_console/godmode/wizards/Custom.class.php new file mode 100644 index 0000000000..41a177b3e3 --- /dev/null +++ b/pandora_console/godmode/wizards/Custom.class.php @@ -0,0 +1,160 @@ +setBreadcrum([]); + + $this->access = 'AW'; + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->class = $class_style; + $this->label = $label; + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=custom' + ); + + return $this; + } + + + /** + * Run wizard manager. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + + // Load current wiz. sub-styles. + ui_require_css_file( + 'custom', + ENTERPRISE_DIR.'/include/styles/wizards/' + ); + + $mode = get_parameter('mode', null); + $extensions = new ExtensionsDiscovery('custom', $mode); + if ($mode !== null) { + // Load extension if exist. + $extensions->run(); + return; + } + + // Load classes and print selector. + $wiz_data = $extensions->loadExtensions(); + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=custom' + ), + 'label' => __('Custom'), + 'selected' => true, + ], + ] + ); + + // Header. + ui_print_page_header( + __('Custom'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + Wizard::printBigButtonsList($wiz_data); + + echo '
*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'
'; + return $result; + } + + + /** + * Check if section have extensions. + * + * @return boolean Return true if section is empty. + */ + public function isEmpty() + { + $extensions = new ExtensionsDiscovery('custom'); + $listExtensions = $extensions->getExtensionsApps(); + if ($listExtensions > 0) { + return false; + } else { + return true; + } + } + + +} diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index e659f85e9e..1c7ffe5526 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -129,6 +129,11 @@ class DiscoveryTaskList extends HTML } $delete_console_task = (bool) get_parameter('delete_console_task'); + $report_task = (bool) get_parameter('report_task', 0); + if ($report_task === true) { + $this->url = ui_get_full_url('index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'); + } + if ($delete_console_task === true) { return $this->deleteConsoleTask(); } @@ -163,7 +168,10 @@ class DiscoveryTaskList extends HTML } if (is_reporting_console_node() === false) { - $ret2 = $this->showList(); + $ret2 = $this->showList(__('Host & devices tasks'), [0, 1]); + $ret2 .= $this->showList(__('Applications tasks'), [3, 4, 5, 10, 11, 12], 'app'); + $ret2 .= $this->showList(__('Cloud tasks'), [6, 7, 8, 13, 14], 'cloud'); + $ret2 .= $this->showList(__('Custom tasks'), [-1], 'custom'); } if ($ret === false && $ret2 === false) { @@ -287,6 +295,10 @@ class DiscoveryTaskList extends HTML } $id_console_task = (int) get_parameter('id_console_task'); + $report_task = (bool) get_parameter('report_task', 0); + if ($report_task === true) { + $this->url = ui_get_full_url('index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'); + } if ($id_console_task != null) { // -------------------------------- @@ -352,6 +364,10 @@ class DiscoveryTaskList extends HTML } $id_console_task = (int) get_parameter('id_console_task'); + $report_task = (bool) get_parameter('report_task', 0); + if ($report_task === true) { + $this->url = ui_get_full_url('index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'); + } if ($id_console_task > 0) { $result = db_process_sql_update( @@ -505,9 +521,13 @@ class DiscoveryTaskList extends HTML /** * Show complete list of running tasks. * + * @param string $titleTable Title of section. + * @param array $filter Ids array from apps for filter. + * @param boolean $extension_section Extension to add in table. + * * @return boolean Success or not. */ - public function showList() + public function showList($titleTable, $filter, $extension_section=false) { global $config; @@ -531,7 +551,16 @@ class DiscoveryTaskList extends HTML include_once $config['homedir'].'/include/functions_network_profiles.php'; if (users_is_admin()) { - $recon_tasks = db_get_all_rows_sql('SELECT * FROM trecon_task'); + $recon_tasks = db_get_all_rows_sql( + sprintf( + 'SELECT tasks.*, apps.section AS section, apps.short_name AS short_name + FROM trecon_task tasks + LEFT JOIN tdiscovery_apps apps ON tasks.id_app = apps.id_app + WHERE type IN (%s) OR section = "%s"', + implode(',', $filter), + $extension_section + ) + ); } else { $user_groups = implode( ',', @@ -539,9 +568,14 @@ class DiscoveryTaskList extends HTML ); $recon_tasks = db_get_all_rows_sql( sprintf( - 'SELECT * FROM trecon_task - WHERE id_group IN (%s)', - $user_groups + 'SELECT tasks.*, apps.section AS section, apps.short_name AS short_name + FROM trecon_task + LEFT JOIN tdiscovery_apps apps ON tasks.id_app = apps.id_app + WHERE id_group IN (%s) AND + (type IN (%s) OR section = "%s")', + $user_groups, + implode(',', $filter), + $extension_section ) ); } @@ -658,7 +692,9 @@ class DiscoveryTaskList extends HTML $recon_script_name = false; } - if ($task['disabled'] == 0 && $server_name !== '') { + if (($task['disabled'] == 0 && $server_name !== '' && (int) $task['type'] !== DISCOVERY_EXTENSION) + || ((int) $task['type'] === DISCOVERY_EXTENSION && (int) $task['setup_complete'] === 1) + ) { if (check_acl($config['id_user'], 0, 'AW')) { $data[0] = ''; $data[9] .= html_print_image( 'images/web@groups.svg', @@ -999,13 +1050,24 @@ class DiscoveryTaskList extends HTML ).''; } } else { + $url_edit = sprintf( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d', + $this->getTargetWiz($task, $recon_script_data), + $task['id_rt'] + ); + + if ((int) $task['type'] === DISCOVERY_EXTENSION) { + $url_edit = sprintf( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=%s&mode=%s&id_task=%s', + $task['section'], + $task['short_name'], + $task['id_rt'], + ); + } + // Check if is a H&D, Cloud or Application or IPAM. $data[9] .= ''.html_print_image( 'images/edit.svg', true, @@ -1069,7 +1131,7 @@ class DiscoveryTaskList extends HTML $return = true; } - ui_toggle($content, __('Server Tasks'), '', '', false); + ui_toggle($content, $titleTable, '', '', false); // Div neccesary for modal map task. echo ''; @@ -1096,9 +1158,9 @@ class DiscoveryTaskList extends HTML * * @return boolean Success or not. */ - public function showListConsoleTask() + public function showListConsoleTask($report_task=false) { - return enterprise_hook('tasklist_showListConsoleTask', [$this]); + return enterprise_hook('tasklist_showListConsoleTask', [$this, $report_task]); } @@ -1227,7 +1289,7 @@ class DiscoveryTaskList extends HTML ($task['status'] < 0) ? 100 : $task['status'], 150, 150, - '#3A3A3A', + '#14524f', '%', '', '#ececec', @@ -1297,7 +1359,7 @@ class DiscoveryTaskList extends HTML $task['stats']['c_network_percent'], 150, 150, - '#3A3A3A', + '#14524f', '%', '', '#ececec', @@ -1340,14 +1402,14 @@ class DiscoveryTaskList extends HTML $output = ''; - if (is_array($task['stats']) === false) { - $task['stats'] = json_decode($task['summary'], true); + if (is_array($task['stats']) === false && (int) $task['type'] !== DISCOVERY_EXTENSION) { + $task['stats'] = json_decode(io_safe_output($task['summary']), true); if (json_last_error() !== JSON_ERROR_NONE) { return $task['summary']; } } - if (is_array($task['stats'])) { + if (is_array($task['stats']) || (int) $task['type'] === DISCOVERY_EXTENSION) { $i = 0; $table = new StdClasS(); $table->class = 'databox data'; @@ -1405,6 +1467,65 @@ class DiscoveryTaskList extends HTML $table->data[$i][1] = ''; $table->data[$i][1] .= ($total - $agents); $table->data[$i++][1] .= ''; + } else if ((int) $task['type'] === DISCOVERY_EXTENSION) { + // Content. + $countSummary = 1; + if (is_array($task['stats']) === true && count(array_filter(array_keys($task['stats']), 'is_numeric')) === count($task['stats'])) { + foreach ($task['stats'] as $key => $summary) { + $table->data[$i][0] = ''.__('Summary').' '.$countSummary.''; + $table->data[$i][1] = ''; + $countSummary++; + $i++; + if (is_array($summary) === true) { + if (empty($summary['summary']) === true && empty($summary['info']) === true) { + $table->data[$i][0] = json_encode($summary, JSON_PRETTY_PRINT); + $table->data[$i][1] = ''; + $i++; + continue; + } + + $unknownJson = $summary; + foreach ($summary as $k2 => $v) { + if (is_array($v) === true) { + if ($k2 === 'summary') { + foreach ($v as $k3 => $v2) { + $table->data[$i][0] = $k3; + $table->data[$i][1] = $v2; + $i++; + } + + unset($unknownJson[$k2]); + } + } else { + if ($k2 === 'info') { + $table->data[$i][0] = $v; + $table->data[$i][1] = ''; + $i++; + + unset($unknownJson[$k2]); + } + } + } + + if (empty($unknownJson) === false) { + $table->data[$i][0] = json_encode($unknownJson, JSON_PRETTY_PRINT); + $table->data[$i][1] = ''; + $i++; + } + } else { + $table->data[$i][0] = $summary; + $table->data[$i][1] = ''; + $i++; + } + } + } else { + $table->data[$i][0] = ''.__('Summary').''; + $table->data[$i][1] = ''; + $i++; + $table->data[$i][0] = $task['summary']; + $table->data[$i][1] = ''; + $i++; + } } else { // Content. if (is_array($task['stats']['summary']) === true) { @@ -1466,7 +1587,7 @@ class DiscoveryTaskList extends HTML } $task = db_get_row('trecon_task', 'id_rt', $id_task); - $task['stats'] = json_decode($task['summary'], true); + $task['stats'] = json_decode(io_safe_output($task['summary']), true); $summary = $this->progressTaskSummary($task); $output = ''; @@ -1859,7 +1980,11 @@ class DiscoveryTaskList extends HTML if ($task['status'] <= 0 && empty($task['summary']) === false ) { - $status = __('Done'); + if ($task['status'] == -2) { + $status = __('Failed'); + } else { + $status = __('Done'); + } } else if ($task['utimestamp'] == 0 && empty($task['summary']) ) { diff --git a/pandora_console/godmode/wizards/ManageExtensions.class.php b/pandora_console/godmode/wizards/ManageExtensions.class.php new file mode 100644 index 0000000000..03b1bdee7b --- /dev/null +++ b/pandora_console/godmode/wizards/ManageExtensions.class.php @@ -0,0 +1,1054 @@ +ajaxController = $config['homedir'].'/include/ajax/manage_extensions.ajax'; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=magextensions' + ); + } + + + /** + * Checks if target method is available to be called using AJAX. + * + * @param string $method Target method. + * + * @return boolean True allowed, false not. + */ + public function ajaxMethod($method) + { + // Check access. + check_login(); + + return in_array($method, $this->AJAXMethods); + } + + + /** + * Implements load method. + * + * @return mixed Skeleton for button. + */ + public function load() + { + return [ + 'icon' => $this->icon, + 'label' => $this->label, + 'url' => $this->url, + + ]; + + } + + + /** + * Generates a JSON error. + * + * @param string $msg Error message. + * + * @return void + */ + public function errorAjax(string $msg) + { + echo json_encode( + ['error' => $msg] + ); + } + + + /** + * Implements run method. + * + * @return void + */ + public function run() + { + global $config; + // Load styles. + parent::run(); + + $uploadDisco = get_parameter('upload_disco', ''); + $action = get_parameter('action', ''); + $shortName = get_parameter('short_name', ''); + + if (empty($uploadDisco) === false) { + if ($_FILES['file']['error'] == 0) { + $result = $this->uploadExtension($_FILES['file']); + if ($result === true) { + ui_print_success_message( + __('Uploaded extension') + ); + } else { + if (is_string($result)) { + echo $this->error($result); + } else { + echo $this->error(__('Failed to upload extension')); + } + } + } else { + echo $this->error(__('Failed to upload extension')); + } + } + + if (empty($action) === false && empty($shortName) === false) { + switch ($action) { + case 'delete': + $result = $this->uninstallExtension($shortName); + if ($result === true) { + ui_print_success_message( + __('Deleted extension') + ); + } else { + echo $this->error(__('Fail delete extension')); + } + + case 'sync_server': + $syncAction = get_parameter('sync_action', ''); + if ($syncAction === 'refresh') { + $installationFolder = $config['homedir'].'/'.$this->path.'/'.$shortName; + $result = $this->copyExtensionToServer($installationFolder, $shortName); + if ($result === true) { + ui_print_success_message( + __('Extension folder created successfully') + ); + } else { + echo $this->error(__('Fail created extension folder')); + } + } + break; + + default: + continue; + } + } + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => '', + 'label' => _('Manage disco packages'), + 'selected' => 1, + ], + ] + ); + + // Header. + ui_print_page_header( + __('Manage disco packages'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'databox filters'; + $table->size = []; + $table->size[0] = '80%'; + $table->align[3] = 'right'; + $table->data = []; + $table->data[0][0] = html_print_label_input_block( + __('Load DISCO'), + html_print_div( + [ + 'id' => 'upload_file', + 'content' => html_print_input_file( + 'file', + true, + ['style' => 'width:100%'] + ), + 'class' => 'mrgn_top_15px', + ], + true + ) + ); + $table->data[0][3] = html_print_submit_button( + __('Upload DISCO'), + 'upload_button', + false, + [ + 'class' => 'sub ok float-right', + 'icon' => 'next', + ], + true + ); + + echo ''; + html_print_input_hidden('upload_disco', 1); + html_print_table($table); + echo '
'; + + echo '
'; + echo ''; + + echo ''; + ui_require_javascript_file('manage_extensions'); + try { + $columns = [ + 'name', + 'short_name', + 'section', + 'description', + 'version', + [ + 'text' => 'actions', + 'class' => 'flex flex-items-center', + ], + ]; + + $columnNames = [ + __('Name'), + __('Short name'), + __('Section'), + __('Description'), + __('Version'), + __('Actions'), + ]; + + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => 'list_extensions', + 'class' => 'info_table', + 'style' => 'width: 99%', + 'dom_elements' => 'plfti', + 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', + 'columns' => $columns, + 'column_names' => $columnNames, + 'ajax_url' => $this->ajaxController, + 'ajax_data' => ['method' => 'getExtensionsInstalled'], + 'no_sortable_columns' => [-1], + 'order' => [ + 'field' => 'name', + 'direction' => 'asc', + ], + 'search_button_class' => 'sub filter float-right', + ] + ); + } catch (Exception $e) { + echo $e->getMessage(); + } + + } + + + /** + * Upload extension to server. + * + * @param array $disco File disco tu upload. + * + * @return boolean $result Of operation, true if is ok. + */ + private function uploadExtension($disco) + { + global $config; + if (substr($disco['name'], -6) !== '.disco') { + return false; + } + + $nameFile = str_replace('.disco', '.zip', $disco['name']); + $nameTempDir = $config['attachment_store'].'/downloads/'; + if (file_exists($nameTempDir) === false) { + mkdir($nameTempDir); + } + + $tmpPath = Files::tempdirnam( + $nameTempDir, + 'extensions_uploaded_' + ); + $result = move_uploaded_file($disco['tmp_name'], $tmpPath.'/'.$nameFile); + if ($result === true) { + $unzip = $this->unZip($tmpPath.'/'.$nameFile, $tmpPath); + if ($unzip === true) { + unlink($tmpPath.'/'.$nameFile); + db_process_sql_begin(); + $this->iniFile = parse_ini_file($tmpPath.'/discovery_definition.ini', true, INI_SCANNER_TYPED); + if ($this->iniFile === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return __('Failed to upload extension: Error while parsing dicovery_definition.ini'); + } + + $error = ExtensionsDiscovery::validateIni($this->iniFile); + if ($error !== false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return $error; + } + + $id = $this->installExtension(); + if ($id === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $result = $this->autoLoadConfigExec($id); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $result = $this->autoUpdateDefaultMacros($id); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $nameFolder = $this->iniFile['discovery_extension_definition']['short_name']; + $installationFolder = $config['homedir'].'/'.$this->path.'/'.$nameFolder; + if (file_exists($installationFolder) === false) { + mkdir($installationFolder, 0777, true); + } else { + Files::rmrf($installationFolder, true); + } + + $result = Files::move($tmpPath, $installationFolder, true); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $this->setPermissionfiles($installationFolder, $this->iniFile['discovery_extension_definition']['execution_file']); + $this->setPermissionfiles( + $installationFolder, + [ + $this->iniFile['discovery_extension_definition']['passencrypt_script'], + $this->iniFile['discovery_extension_definition']['passdecrypt_script'], + ] + ); + + $result = $this->copyExtensionToServer($installationFolder, $nameFolder); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + Files::rmrf($tmpPath); + db_process_sql_commit(); + return true; + } + } else { + Files::rmrf($tmpPath); + return false; + } + } + + + /** + * Copy the extension folder into remote path server. + * + * @param string $path Path extension folder. + * @param string $nameFolder Name of extension folder. + * + * @return boolean Result of operation. + */ + public function copyExtensionToServer($path, $nameFolder) + { + global $config; + $filesToExclude = [ + 'discovery_definition.ini', + 'logo.png', + ]; + $serverPath = $config['remote_config'].'/discovery/'.$nameFolder; + if (file_exists($serverPath) === false) { + mkdir($serverPath, 0777, true); + } else { + Files::rmrf($serverPath, true); + } + + $result = $this->copyFolder($path, $serverPath, $filesToExclude); + $this->setPermissionfiles($serverPath, $this->iniFile['discovery_extension_definition']['execution_file']); + + return $result; + } + + + /** + * Copy from $source path to $destination + * + * @param string $source Initial folder path. + * @param string $destination Destination folder path. + * @param array $exclude Files to exlcude in copy. + * + * @return boolean Result of operation. + */ + public function copyFolder($source, $destination, $exclude=[]) + { + if (file_exists($destination) === false) { + mkdir($destination, 0777, true); + } + + $files = scandir($source); + foreach ($files as $file) { + if ($file !== '.' && $file !== '..') { + if (is_dir($source.'/'.$file)) { + $result = $this->copyFolder($source.'/'.$file, $destination.'/'.$file); + if ($result === false) { + return false; + } + } else { + if (in_array($file, $exclude) === false) { + $result = copy($source.'/'.$file, $destination.'/'.$file); + if ($result === false) { + return false; + } + } + } + } + } + + return true; + } + + + /** + * Delete extension from database and delete folder + * + * @param integer $shortName Short name app for delete. + * + * @return boolean Result of operation. + */ + private function uninstallExtension($shortName) + { + global $config; + + $result = db_process_sql_delete( + 'tdiscovery_apps', + ['short_name' => $shortName] + ); + + if ($result !== false) { + Files::rmrf($config['homedir'].'/'.$this->path.'/'.$shortName); + Files::rmrf($config['remote_config'].'/discovery/'.$shortName); + return true; + } else { + return false; + } + } + + + /** + * Load the basic information of the app into database. + * + * @return boolean Result of query. + */ + private function installExtension() + { + $exist = db_get_row_filter( + 'tdiscovery_apps', + [ + 'short_name' => $this->iniFile['discovery_extension_definition']['short_name'], + ] + ); + $version = $this->iniFile['discovery_extension_definition']['version']; + if ($version === null) { + $version = ''; + } + + $description = $this->iniFile['discovery_extension_definition']['description']; + if ($description === null) { + $description = ''; + } + + if ($exist === false) { + return db_process_sql_insert( + 'tdiscovery_apps', + [ + 'short_name' => $this->iniFile['discovery_extension_definition']['short_name'], + 'name' => io_safe_input($this->iniFile['discovery_extension_definition']['name']), + 'description' => io_safe_input($description), + 'section' => $this->iniFile['discovery_extension_definition']['section'], + 'version' => $version, + ] + ); + } else { + $result = db_process_sql_update( + 'tdiscovery_apps', + [ + 'name' => io_safe_input($this->iniFile['discovery_extension_definition']['name']), + 'description' => io_safe_input($description), + 'section' => $this->iniFile['discovery_extension_definition']['section'], + 'version' => $version, + ], + [ + 'short_name' => $this->iniFile['discovery_extension_definition']['short_name'], + ] + ); + + if ($result !== false) { + return $exist['id_app']; + } + } + } + + + /** + * Return all extension installed by ajax. + * + * @return void + */ + public function getExtensionsInstalled() + { + global $config; + + $data = []; + $start = get_parameter('start', 0); + $length = get_parameter('length', $config['block_size']); + $orderDatatable = get_datatable_order(true); + $pagination = ''; + $order = ''; + + try { + ob_start(); + + if (isset($orderDatatable)) { + $order = sprintf( + ' ORDER BY %s %s', + $orderDatatable['field'], + $orderDatatable['direction'] + ); + } + + if (isset($length) && $length > 0 + && isset($start) && $start >= 0 + ) { + $pagination = sprintf( + ' LIMIT %d OFFSET %d ', + $length, + $start + ); + } + + $sql = sprintf( + 'SELECT short_name, name, section, description, version + FROM tdiscovery_apps + %s %s', + $order, + $pagination + ); + + $data = db_get_all_rows_sql($sql); + + $sqlCount = sprintf( + 'SELECT short_name, name, section, description, version + FROM tdiscovery_apps + %s', + $order, + ); + + $count = db_get_num_rows($sqlCount); + + foreach ($data as $key => $row) { + $logo = $this->path.'/'.$row['short_name'].'/logo.png'; + if (file_exists($logo) === false) { + $logo = $this->defaultLogo; + } + + $logo = html_print_image($logo, true, ['style' => 'max-width: 30px; margin-right: 15px;']); + $data[$key]['name'] = $logo.io_safe_output($row['name']); + $data[$key]['short_name'] = $row['short_name']; + $data[$key]['description'] = io_safe_output($row['description']); + $data[$key]['version'] = $row['version']; + $data[$key]['actions'] = '
'; + $data[$key]['actions'] .= html_print_input_image( + 'button_delete', + 'images/delete.svg', + '', + '', + true, + [ + 'onclick' => 'if (!confirm(\''.__('Deleting this application will also delete all the discovery tasks using it. Do you want to delete it?').'\')) return false;', + 'class' => 'main_menu_icon invert_filter action_button_hidden', + ] + ); + $data[$key]['actions'] .= html_print_input_hidden('short_name', $row['short_name'], true); + $data[$key]['actions'] .= '
'; + if ($this->checkFolderConsole($row['short_name']) === true) { + $data[$key]['actions'] .= '
'; + $data[$key]['actions'] .= html_print_input_image( + 'button_refresh', + 'images/refresh@svg.svg', + '', + '', + true, + [ + 'onclick' => 'if (!confirm(\''.__('Are you sure you want to reapply?').'\')) return false;', + 'class' => 'main_menu_icon invert_filter action_button_hidden', + ] + ); + $data[$key]['actions'] .= html_print_input_hidden('sync_action', 'refresh', true); + $data[$key]['actions'] .= html_print_input_hidden('short_name', $row['short_name'], true); + $data[$key]['actions'] .= '
'; + } else { + $data[$key]['actions'] .= html_print_image( + 'images/error_red.png', + true, + [ + 'title' => __('The extension directory or .ini does not exist in console.'), + 'alt' => __('The extension directory or .ini does not exist in console.'), + 'class' => 'main_menu_icon invert_filter', + ], + ); + } + } + + if (empty($data) === true) { + $total = 0; + $data = []; + } else { + $total = $count; + } + + echo json_encode( + [ + 'data' => $data, + 'recordsTotal' => $total, + 'recordsFiltered' => $total, + ] + ); + // Capture output. + $response = ob_get_clean(); + } catch (Exception $e) { + echo json_encode(['error' => $e->getMessage()]); + exit; + } + + json_decode($response); + if (json_last_error() === JSON_ERROR_NONE) { + echo $response; + } else { + echo json_encode( + [ + 'success' => false, + 'error' => $response, + ] + ); + } + + exit; + } + + + /** + * Insert new the default values for extension. + * + * @param integer $id Id of extension. + * + * @return boolean Result of query. + */ + private function autoUpdateDefaultMacros($id) + { + $defaultValues = $this->iniFile['discovery_extension_definition']['default_value']; + + foreach ($defaultValues as $macro => $value) { + $sql = 'INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` + (`id_task`, `macro`, `type`, `value`, `temp_conf`) + SELECT `id_rt`, "'.$macro.'", "custom", "'.(string) io_safe_input($value).'", "0" + FROM `trecon_task` + WHERE `id_app` = "'.$id.'";'; + $result = db_process_sql($sql); + if ($result === false) { + return false; + } + } + + $tempFiles = $this->iniFile['tempfile_confs']['file']; + foreach ($tempFiles as $macro => $value) { + $sql = 'UPDATE `tdiscovery_apps_tasks_macros` + SET `value` = "'.(string) io_safe_input($value).'" WHERE `id_task` + IN (SELECT `id_rt` FROM `trecon_task` WHERE `id_app` = "'.$id.'") AND `macro` = "'.$macro.'"'; + $result = db_process_sql($sql); + if ($result === false) { + return false; + } + + $sql = 'INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` + (`id_task`, `macro`, `type`, `value`, `temp_conf`) + SELECT `id_rt`, "'.$macro.'", "custom", "'.(string) io_safe_input($value).'", "1" + FROM `trecon_task` + WHERE `id_app` = "'.$id.'";'; + $result = db_process_sql($sql); + if ($result === false) { + return false; + } + } + + return true; + } + + + /** + * Load the exec files in database + * + * @param integer $id Id of extension. + * + * @return boolean Result of query. + */ + private function autoLoadConfigExec($id) + { + $executionFiles = $this->iniFile['discovery_extension_definition']['execution_file']; + + foreach ($executionFiles as $key => $value) { + $exist = db_get_row_filter( + 'tdiscovery_apps_scripts', + [ + 'id_app' => $id, + 'macro' => $key, + ] + ); + if ($exist === false) { + $result = db_process_sql_insert( + 'tdiscovery_apps_scripts', + [ + 'id_app' => $id, + 'macro' => $key, + 'value' => io_safe_input($value), + ] + ); + if ($result === false) { + return false; + } + } else { + $result = db_process_sql_update( + 'tdiscovery_apps_scripts', + ['value' => io_safe_input($value)], + [ + 'id_app' => $id, + 'macro' => $key, + ] + ); + if ($result === false) { + return false; + } + } + } + + $execCommands = $this->iniFile['discovery_extension_definition']['exec']; + $result = db_process_sql_delete( + 'tdiscovery_apps_executions', + ['id_app' => $id] + ); + if ($result === false) { + return false; + } + + foreach ($execCommands as $key => $value) { + $result = db_process_sql_insert( + 'tdiscovery_apps_executions', + [ + 'id_app' => $id, + 'execution' => io_safe_input($value), + ] + ); + if ($result === false) { + return false; + } + } + + return true; + } + + + /** + * Check if exist folder extension in console. + * + * @param string $shortName Name of folder. + * + * @return boolean Return true if exist folder + */ + private function checkFolderConsole($shortName) + { + global $config; + + $folderPath = $config['homedir'].'/'.$this->path.'/'.$shortName; + $iniPath = $config['homedir'].'/'.$this->path.'/'.$shortName.'/discovery_definition.ini'; + if (file_exists($folderPath) === false || file_exists($iniPath) === false) { + return false; + } else { + return true; + } + } + + + /** + * Validate the ini name by ajax. + * + * @return void + */ + public function validateIniName() + { + global $config; + $uploadDisco = get_parameter('upload_disco', ''); + if (empty($uploadDisco) === false) { + if ($_FILES['file']['error'] == 0) { + $disco = $_FILES['file']; + } else { + echo json_encode(['success' => false, 'message' => 'Failed to upload extension']); + return; + } + } + + if (substr($disco['name'], -6) !== '.disco') { + echo json_encode(['success' => false, 'message' => 'Failed to upload extension']); + return; + } + + $nameFile = str_replace('.disco', '.zip', $disco['name']); + $nameTempDir = $config['attachment_store'].'/downloads/'; + if (file_exists($nameTempDir) === false) { + mkdir($nameTempDir); + } + + $tmpPath = Files::tempdirnam( + $nameTempDir, + 'extensions_uploaded_' + ); + $result = move_uploaded_file($disco['tmp_name'], $tmpPath.'/'.$nameFile); + if ($result === true) { + $unzip = $this->unZip($tmpPath.'/'.$nameFile, $tmpPath, 'discovery_definition.ini'); + if ($unzip === true) { + unlink($tmpPath.'/'.$nameFile); + $this->iniFile = parse_ini_file($tmpPath.'/discovery_definition.ini', true, INI_SCANNER_TYPED); + if ($this->iniFile === false) { + Files::rmrf($tmpPath); + echo json_encode(['success' => false, 'message' => __('Failed to upload extension: Error while parsing dicovery_definition.ini')]); + return; + } + + $message = false; + $shortName = $this->iniFile['discovery_extension_definition']['short_name']; + if (strpos($shortName, 'pandorafms.') === 0) { + $message = __('The \'short_name\' starting with \'pandorafms.\' is reserved for Pandora FMS applications. If this is not an official Pandora FMS application, consider changing the \'short_name\'. Do you want to continue?'); + } + + $exist = db_get_row_filter( + 'tdiscovery_apps', + ['short_name' => $shortName] + ); + + if ($exist !== false) { + $message = __('There is another application with the same \'short_name\': \'%s\'. Do you want to overwrite the application and all of its contents?', $shortName); + } + + if ($message !== false) { + echo json_encode( + [ + 'success' => true, + 'warning' => true, + 'message' => $message, + ] + ); + } else { + echo json_encode(['success' => true]); + } + + Files::rmrf($tmpPath); + return; + } + } else { + Files::rmrf($tmpPath); + echo json_encode(['success' => false, 'message' => __('Failed to upload extension')]); + return; + } + } + + + /** + * Return all extensions from section. + * + * @param string $section Section to filter. + * + * @return array List of sections. + */ + static public function getExtensionBySection($section) + { + return db_get_all_rows_filter( + 'tdiscovery_apps', + ['section' => $section] + ); + } + + + /** + * Set execution permission in folder items and subfolders. + * + * @param string $path Array of files to apply permissions. + * @param array $filter Array of files for apply permission only. + * + * @return void + */ + private function setPermissionfiles($path, $filter=false) + { + global $config; + + if ($filter !== false && is_array($filter) === true) { + foreach ($filter as $key => $file) { + if (substr($file, 0, 1) !== '/') { + $file = $path.'/'.$file; + } + + chmod($file, 0777); + } + } else { + chmod($path, 0777); + + if (is_dir($path)) { + $items = scandir($path); + foreach ($items as $item) { + if ($item != '.' && $item != '..') { + $itemPath = $path.'/'.$item; + $this->setPermissionfiles($itemPath); + } + } + } + } + } + + + /** + * Unzip folder or only file. + * + * @param string $zipFile File to unzip. + * @param string $target_path Target path into unzip. + * @param string $file If only need unzip one file. + * + * @return boolean $result True if the file has been successfully decompressed. + */ + public function unZip($zipFile, $target_path, $file=null) + { + $zip = new \ZipArchive; + + if ($zip->open($zipFile) === true) { + $zip->extractTo($target_path, $file); + $zip->close(); + return true; + } else { + return false; + } + } + + +} diff --git a/pandora_console/images/circle_title.svg b/pandora_console/images/circle_title.svg new file mode 100644 index 0000000000..23c906e4e5 --- /dev/null +++ b/pandora_console/images/circle_title.svg @@ -0,0 +1,19 @@ + + + EB094270-FB38-4A58-BE94-D40EA44EA568 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/report-task.svg b/pandora_console/images/report-task.svg new file mode 100644 index 0000000000..b16b7144da --- /dev/null +++ b/pandora_console/images/report-task.svg @@ -0,0 +1,8 @@ + + + Reportes programados@svg + + + + + \ No newline at end of file diff --git a/pandora_console/images/widgets/AgentHive.png b/pandora_console/images/widgets/AgentHive.png new file mode 100644 index 0000000000..9a3c4623e5 Binary files /dev/null and b/pandora_console/images/widgets/AgentHive.png differ diff --git a/pandora_console/images/widgets/netflow.png b/pandora_console/images/widgets/netflow.png new file mode 100644 index 0000000000..5a34c1635f Binary files /dev/null and b/pandora_console/images/widgets/netflow.png differ diff --git a/pandora_console/images/wizard/Configurar_app@svg.svg b/pandora_console/images/wizard/Configurar_app@svg.svg new file mode 100644 index 0000000000..59507e2cf4 --- /dev/null +++ b/pandora_console/images/wizard/Configurar_app@svg.svg @@ -0,0 +1,22 @@ + + + + Configurar app@svg + Created with Sketch. + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/wizard/Custom_apps@svg.svg b/pandora_console/images/wizard/Custom_apps@svg.svg new file mode 100644 index 0000000000..23e251912d --- /dev/null +++ b/pandora_console/images/wizard/Custom_apps@svg.svg @@ -0,0 +1,21 @@ + + + + Custom apps@svg + Created with Sketch. + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/wizard/app_generico.svg b/pandora_console/images/wizard/app_generico.svg new file mode 100644 index 0000000000..99d3e5cf42 --- /dev/null +++ b/pandora_console/images/wizard/app_generico.svg @@ -0,0 +1,18 @@ + + + + App genérico@svg + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/wizard/applications.png b/pandora_console/images/wizard/applications.png new file mode 100644 index 0000000000..01c10178bd Binary files /dev/null and b/pandora_console/images/wizard/applications.png differ diff --git a/pandora_console/images/wizard/cloud.png b/pandora_console/images/wizard/cloud.png new file mode 100644 index 0000000000..a016599e2f Binary files /dev/null and b/pandora_console/images/wizard/cloud.png differ diff --git a/pandora_console/images/wizard/consoletasks.png b/pandora_console/images/wizard/consoletasks.png new file mode 100644 index 0000000000..0087897495 Binary files /dev/null and b/pandora_console/images/wizard/consoletasks.png differ diff --git a/pandora_console/include/ajax/audit_log.php b/pandora_console/include/ajax/audit_log.php index c979568b21..026d8ca881 100644 --- a/pandora_console/include/ajax/audit_log.php +++ b/pandora_console/include/ajax/audit_log.php @@ -84,7 +84,7 @@ if ($save_log_filter) { if ($recover_aduit_log_select) { - echo json_encode(audit_get_audit_filter_select()); + echo json_encode(audit_get_audit_filter_select_fix_order()); } if ($update_log_filter) { @@ -190,7 +190,7 @@ function show_filter() { draggable: true, modal: false, closeOnEscape: true, - width: 380 + width: "auto" }); } @@ -207,12 +207,13 @@ function load_filter_values() { }, success: function(data) { var options = ""; + console.log(data); $.each(data,function(i,value){ if (i == 'text'){ $("#text-filter_text").val(value); } if (i == 'period'){ - $("#text-filter_period").val(value); + $("#filter_period").val(value).change(); } if (i == 'ip'){ $("#text-filter_ip").val(value); @@ -395,7 +396,7 @@ function save_new_filter() { "save_log_filter" : 1, "id_name" : $("#text-id_name").val(), "text" : $("#text-filter_text").val(), - "period" : $("#text-filter_period").val(), + "period" : $("#filter_period :selected").val(), "ip" : $('#text-filter_ip').val(), "type" : $('#filter_type :selected').val(), "user" : $('#filter_user :selected').val(), @@ -431,7 +432,7 @@ function save_update_filter() { "update_log_filter" : 1, "id" : $("#overwrite_filter :selected").val(), "text" : $("#text-filter_text").val(), - "period" : $("#text-filter_period").val(), + "period" : $("#filter_period :selected").val(), "ip" : $('#text-filter_ip').val(), "type" : $('#filter_type :selected').val(), "user" : $('#filter_user :selected').val(), diff --git a/pandora_console/include/ajax/graph.ajax.php b/pandora_console/include/ajax/graph.ajax.php index 7b2d08970b..6ea76f373b 100644 --- a/pandora_console/include/ajax/graph.ajax.php +++ b/pandora_console/include/ajax/graph.ajax.php @@ -17,6 +17,8 @@ $save_custom_graph = (bool) get_parameter('save_custom_graph'); $print_custom_graph = (bool) get_parameter('print_custom_graph', false); $print_sparse_graph = (bool) get_parameter('print_sparse_graph'); $get_graphs = (bool) get_parameter('get_graphs_container'); +$width = get_parameter('width', 0); +$height = get_parameter('height', 0); if ($save_custom_graph) { $return = []; @@ -25,8 +27,6 @@ if ($save_custom_graph) { $name = get_parameter('name', ''); $description = get_parameter('description', ''); $stacked = get_parameter('stacked', CUSTOM_GRAPH_LINE); - $width = get_parameter('width', 0); - $height = get_parameter('height', 0); $events = get_parameter('events', 0); $period = get_parameter('period', 0); $fullscale = get_parameter('fullscale', 0); @@ -126,6 +126,8 @@ if ($print_sparse_graph) { 'force_interval' => '', 'time_interval' => 300, 'array_data_create' => 0, + 'height' => $height, + 'width' => $width, ]; echo grafico_modulo_sparse($params); diff --git a/pandora_console/include/ajax/manage_extensions.ajax.php b/pandora_console/include/ajax/manage_extensions.ajax.php new file mode 100644 index 0000000000..b116277a23 --- /dev/null +++ b/pandora_console/include/ajax/manage_extensions.ajax.php @@ -0,0 +1,60 @@ +ajaxMethod($method) === true) { + $actions->{$method}(); + } else { + $actions->errorAjax('Unavailable method.'); + } +} else { + $actions->errorAjax('Method not found. ['.$method.']'); +} + + +// Stop any execution. +exit; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 0ab70681df..8cc2eca4a5 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -98,15 +98,18 @@ if (check_login()) { } $id_plugin = get_parameter('id_plugin', 0); - $id_module_plugin = db_get_value( - 'id_plugin', - 'tagente_modulo', - 'id_agente_modulo', - $get_module_macros - ); - if ($id_plugin !== $id_module_plugin) { - $get_plugin_macros = true; - $get_module_macros = 0; + + if ($id_plugin !== 0) { + $id_module_plugin = db_get_value( + 'id_plugin', + 'tagente_modulo', + 'id_agente_modulo', + $get_module_macros + ); + if ($id_plugin !== $id_module_plugin) { + $get_plugin_macros = true; + $get_module_macros = 0; + } } if ($get_plugin_macros) { diff --git a/pandora_console/include/ajax/snmp_browser.ajax.php b/pandora_console/include/ajax/snmp_browser.ajax.php index 9461dd8ca8..7bff27da4a 100644 --- a/pandora_console/include/ajax/snmp_browser.ajax.php +++ b/pandora_console/include/ajax/snmp_browser.ajax.php @@ -182,6 +182,7 @@ try { if ($method == 'snmp_browser_create_modules') { // Get target ids from form. + $use_agent_ip = get_parameter('use_agent_ip', ''); $id_items = get_parameter('id_item2', null); $id_target = null; if (empty($id_items) === false) { @@ -209,7 +210,8 @@ try { $module_target, $snmp_conf_values, $id_target, - $server_to_exec + $server_to_exec, + $use_agent_ip ); // Return fail modules for error/success message. diff --git a/pandora_console/include/ajax/task_to_perform.php b/pandora_console/include/ajax/task_to_perform.php new file mode 100644 index 0000000000..a8a13e08f2 --- /dev/null +++ b/pandora_console/include/ajax/task_to_perform.php @@ -0,0 +1,190 @@ + SERVER_TYPE_WEB], 'status')['status']; + if ($status_webserver === '1') { + $name = array_keys(servers_get_names())[0]; + $id_group = get_parameter('id_group', 4); + + $array_other['data'] = [ + 'Web monitoring', + '', + 2, + $id_group, + 0, + 30, + 30, + 9, + $name, + 0, + 0, + 0, + __('Agent Web monitoring created on welcome'), + ]; + + $id_agent = api_set_new_agent(0, '', $array_other, '', true); + if ($id_agent > 0) { + $module_name = get_parameter('module_name', 'Web_monitoring_module'); + $text_to_search = get_parameter('text_to_search', ''); + $url_goliat = get_parameter('url_goliat', 'https://pandorafms.com/en/'); + $module_latency = create_module_latency_goliat($id_agent, $module_name, $id_group, $url_goliat, $text_to_search); + $module_status = create_module_status_goliat($id_agent, $module_name, $id_group, $url_goliat, $text_to_search); + if ($module_latency > 0 && $module_status > 0) { + ui_print_success_message(__('Your check has been created,
click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); + } + } else { + ui_print_error_message(__('The Name is not valid for the modules.')); + } + } else { + ui_print_error_message(__('Web server is not enabled.')); + } +} + +if ($check_connectivity) { + include_once '../functions_api.php'; + include_once '../functions_servers.php'; + + $status_newtwork = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_NETWORK], 'status')['status']; + $status_pluggin = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_PLUGIN], 'status')['status']; + if ($status_newtwork === '1' && $status_pluggin === '1') { + $name = array_keys(servers_get_names())[0]; + $id_group = get_parameter('id_group', 4); + $agent_name = get_parameter('agent_name', __('Agent check connectivity')); + + $array_other['data'] = [ + $agent_name, + '', + 2, + $id_group, + 0, + 30, + 30, + 9, + $name, + 0, + 0, + 0, + __('Basic connectivity'), + ]; + + $id_agent = api_set_new_agent(0, '', $array_other, '', true); + if ($id_agent > 0) { + $ip_target = get_parameter('ip_target', '127.0.0.1'); + $basic_network = create_module_basic_network($id_agent, $id_group, $ip_target); + $latency_network = create_module_latency_network($id_agent, $id_group, $ip_target); + $packet_lost = create_module_packet_lost($id_agent, $id_group, $ip_target); + if ($basic_network > 0 && $latency_network > 0 && $packet_lost > 0) { + ui_print_success_message(__('Your check has been created, click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); + } + } else { + ui_print_error_message(__('The Name is not valid for the modules.')); + } + } else { + ui_print_error_message(__('Web server is not enabled.')); + } +} + +if ($create_net_scan) { + $ip_target = get_parameter('ip_target', '192.168.10.0/24'); + $id_net_scan = create_net_scan($ip_target); + if ($id_net_scan > 0) { + $id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server']; + ui_print_success_message(__('Basic net created and scan in progress. Click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); + } else { + ui_print_error_message(__('Basic net already exists. Click here to view the data')); + } +} + +if ($create_mail_alert) { + include_once '../functions_alerts.php'; + $id_action = db_get_row_filter('talert_actions', ['name' => 'Email to '.$config['id_user']], 'id')['id']; + if (!$id_action) { + $al_action = alerts_get_alert_action($id); + $id_action = alerts_clone_alert_action(1, $al_action['id_group'], 'Email to '.$config['id_user']); + } + + $id_alert_template = get_parameter('id_condition', 0); + $id_agent_module = get_parameter('id_agent_module', 0); + + $exist = db_get_value_sql( + sprintf( + 'SELECT COUNT(id) + FROM talert_template_modules + WHERE id_agent_module = %d + AND id_alert_template = %d + AND id_policy_alerts = 0 + ', + $id_agent_module, + $id_alert_template + ) + ); + + if ($exist > 0) { + ui_print_error_message(__('Alert already exists. Click here to view the data')); + } else { + $id = alerts_create_alert_agent_module($id_agent_module, $id_alert_template); + if ($id !== false) { + $values = []; + $values['fires_min'] = (int) get_parameter('fires_min'); + $values['fires_max'] = (int) get_parameter('fires_max'); + $values['module_action_threshold'] = (int) 300; + + $alert_created = alerts_add_alert_agent_module_action($id, $id_action, $values); + } + } + + if ($alert_created === true) { + ui_print_success_message(__('Congratulations, you have already created a simple alert. You can see it. Pandora FMS alerts are very flexible, you can do many more things with them, we recommend you to read the documentation for more information. You can create advanced alerts from here.')); + } +} + +if ($create_unknown_template_alert) { + if (is_array(alerts_get_alert_templates(['name' => io_safe_input('Unknown condition')]))) { + echo 1; + } else { + echo create_template_alert_unknown(); + } +} diff --git a/pandora_console/include/ajax/welcome_window.php b/pandora_console/include/ajax/welcome_window.php index 52fdcea8d2..2ca1a5e953 100644 --- a/pandora_console/include/ajax/welcome_window.php +++ b/pandora_console/include/ajax/welcome_window.php @@ -35,6 +35,13 @@ if (is_ajax() === false) { } $ajaxPage = 'include/ajax/welcome_window'; +// Ajax controller. +$method = get_parameter('method', ''); + +if ($method === 'loadWelcomeWindow') { + unset($config['welcome_state']); +} + // Control call flow. try { @@ -44,9 +51,6 @@ try { exit; } -// Ajax controller. -$method = get_parameter('method', ''); - if (method_exists($welcome_actions, $method) === true) { if ($welcome_actions->ajaxMethod($method) === true) { $welcome_actions->{$method}(); diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 526256e260..0e6083d3e2 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -129,6 +129,14 @@ if (empty($apiPassword) === true // Compat. $config['id_user'] = 'admin'; $correctLogin = true; + // Bypass credentials if server-auth and api-pass are correct. + } else if (($config['server_unique_identifier'] === get_parameter('server_auth')) + && ($api_password === $apiPassword) + && ((bool) isInACL($ipOrigin) === true) + ) { + $config['id_usuario'] = 'admin'; + $config['id_user'] = 'admin'; + $correctLogin = true; } else if ((bool) isInACL($ipOrigin) === true) { // External access. // Token is valid. Bypass the credentials. diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index 9ebeaaf167..a24769e528 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -237,8 +237,13 @@ function process_user_login_remote($login, $pass, $api=false) // Active Directory. case 'ad': - if (enterprise_hook('ad_process_user_login', [$login, $pass]) === false) { - $config['auth_error'] = 'User not found in database or incorrect password'; + $sr = enterprise_hook('ad_process_user_login', [$login, $pass]); + // Try with secondary server. + if ($sr === false && (bool) $config['secondary_active_directory'] === true) { + $sr = enterprise_hook('ad_process_user_login', [$login, $pass, true]); + } + + if ($sr === false) { return false; } break; diff --git a/pandora_console/include/chart_generator.php b/pandora_console/include/chart_generator.php index b2eb97bd1b..e8ee5f294c 100644 --- a/pandora_console/include/chart_generator.php +++ b/pandora_console/include/chart_generator.php @@ -165,6 +165,9 @@ $hack_metaconsole = (is_metaconsole() === true) ? '../../' : ''; + diff --git a/pandora_console/include/class/AuditLog.class.php b/pandora_console/include/class/AuditLog.class.php index 98bca38e43..f35f4e4e6d 100644 --- a/pandora_console/include/class/AuditLog.class.php +++ b/pandora_console/include/class/AuditLog.class.php @@ -178,7 +178,7 @@ class AuditLog extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, @@ -469,7 +469,7 @@ class AuditLog extends HTML success: function(data) { var options = ""; $.each(data,function(key,value){ - options += ""; + options += ""; }); $('#overwrite_filter').html(options); $('#overwrite_filter').select2(); @@ -509,8 +509,12 @@ class AuditLog extends HTML /* Filter management */ $('#button-load-filter').click(function (){ if($('#load-filter-select').length) { - $('#load-filter-select').dialog({width: "20%", - maxWidth: "25%", + $('#load-filter-select').dialog({ + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + width: "auto", title: "" }); $.ajax({ @@ -523,8 +527,9 @@ class AuditLog extends HTML }, success: function(data) { var options = ""; + console.log(data) $.each(data,function(key,value){ - options += ""; + options += ""; }); $('#filter_id').html(options); $('#filter_id').select2(); diff --git a/pandora_console/include/class/CalendarManager.class.php b/pandora_console/include/class/CalendarManager.class.php index ba1761d6f9..311559c4e2 100644 --- a/pandora_console/include/class/CalendarManager.class.php +++ b/pandora_console/include/class/CalendarManager.class.php @@ -1040,7 +1040,7 @@ class CalendarManager 'id' => 'templates_alerts_special_days', 'return' => true, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'godmode/alerts/alert_special_days', diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index 2177e73a74..cea6123f08 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -612,7 +612,7 @@ class ConfigPEN extends HTML 'id' => $tableId, 'return' => true, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index cb9435b559..12ed8e56be 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -595,7 +595,6 @@ class ConsoleSupervisor 'days_delete_unknown' => 'Max. days before unknown modules are deleted', 'days_delete_not_initialized' => 'Max. days before delete not initialized modules', 'days_autodisable_deletion' => 'Max. days before autodisabled agents are deleted', - 'delete_old_network_matrix' => 'Max. days before delete old network matrix data', 'report_limit' => 'Item limit for real-time reports', 'event_view_hr' => 'Default hours for event view', 'big_operation_step_datos_purge' => 'Big Operation Step to purge old data', @@ -1807,7 +1806,8 @@ class ConsoleSupervisor $this->cleanNotifications('NOTIF.PHP.SERIALIZE_PRECISION'); } - if (version_compare('8.1', PHP_VERSION) >= 0) { + // If PHP_VERSION is lower than 8.0.27 version_compare() returns 1. + if (version_compare('8.0.27', PHP_VERSION) === 1) { $url = 'https://www.php.net/supported-versions.php'; $this->notify( [ diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index b82a129cd1..937f505f8d 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -827,7 +827,7 @@ class CredentialStore extends Wizard [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 7483cbca30..2c00a6b328 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -1579,7 +1579,7 @@ class Diagnostics extends Wizard [ 'id' => $tableId, 'class' => 'info_table caption_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columnNames, 'ajax_data' => [ @@ -1591,6 +1591,7 @@ class Diagnostics extends Wizard 'no_sortable_columns' => [-1], 'caption' => $title, 'print' => true, + 'mini_csv' => true, ] ); } else { diff --git a/pandora_console/include/class/EventSound.class.php b/pandora_console/include/class/EventSound.class.php index e485ac4dfb..5658b44324 100644 --- a/pandora_console/include/class/EventSound.class.php +++ b/pandora_console/include/class/EventSound.class.php @@ -320,7 +320,7 @@ class EventSound extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/ExtensionsDiscovery.class.php b/pandora_console/include/class/ExtensionsDiscovery.class.php new file mode 100644 index 0000000000..da26fb1780 --- /dev/null +++ b/pandora_console/include/class/ExtensionsDiscovery.class.php @@ -0,0 +1,2555 @@ +section = $_section; + $this->mode = $_mode; + $this->url = 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz='.$_section; + $this->loadConfig(); + } + + + /** + * Load config from extension. + * + * @return void + */ + private function loadConfig() + { + $row = db_get_row('tdiscovery_apps', 'short_name', $this->mode); + $this->id = $row['id_app']; + $this->name = $row['name']; + $this->description = $row['description']; + } + + + /** + * Return array extensions filtered by section + * + * @return array Extensions for + */ + public function loadExtensions() + { + global $config; + // Check access. + check_login(); + $extensions = []; + $rows = $this->getExtensionsApps(); + foreach ($rows as $key => $extension) { + $logo = $this->path.'/'.$extension['short_name'].'/'.$this->icon; + if (file_exists($config['homedir'].$logo) === false) { + $logo = $this->defaultLogo; + } + + $extensions[] = [ + 'icon' => $logo, + 'label' => $extension['name'], + 'url' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz='.$this->section.'&mode='.$extension['short_name'] + ), + ]; + } + + return $extensions; + } + + + /** + * Return all extensions from apps section + * + * @return array extensions. + */ + public function getExtensionsApps() + { + return db_get_all_rows_filter('tdiscovery_apps', ['section' => $this->section]); + + } + + + /** + * Load the extension information from discovery_definition.ini. + * + * @return array Information ini file. + */ + public function loadIni() + { + global $config; + $iniFile = parse_ini_file($config['homedir'].$this->path.'/'.$this->mode.'/discovery_definition.ini', true, INI_SCANNER_TYPED); + + return $iniFile; + } + + + /** + * Return next page from config_steps. + * + * @return integer Return the number of next page. + */ + public function nextPage() + { + $pages = array_keys($this->iniFile['config_steps']['name']); + if ($this->currentPage === 0 || empty($this->currentPage) === true) { + return $pages[0]; + } + + foreach ($pages as $k => $page) { + if ($page === $this->currentPage) { + if (end($pages) === $this->currentPage) { + return $this->currentPage; + } else { + return $pages[($k + 1)]; + } + } + } + } + + + /** + * Draw the extension forms. + * + * @return boolean Return boolean if exist error. + */ + public function run() + { + ui_require_javascript_file('extensions_discovery'); + $_iniFile = $this->loadIni(); + if ($_iniFile === false) { + include 'general/noaccess.php'; + return false; + } + + $this->iniFile = $_iniFile; + if (empty($this->iniFile['config_steps']) === false) { + $this->lastPage = end(array_keys($this->iniFile['config_steps']['name'])); + } else { + $this->lastPage = 0; + } + + $this->currentPage = (int) get_parameter('page', '0'); + $this->idTask = get_parameter('id_task', ''); + $action = get_parameter('action', ''); + $isTheEnd = get_parameter('complete_button', ''); + + // Control parameters and errors. + $error = false; + + if ($action === 'task_definition_form') { + $error = $this->processTaskDefinition(); + } + + if ($action === 'process_macro') { + $error = $this->processCustomMacro(); + } + + $task = $this->getTask(); + + if ($task === false && $this->currentPage > 0) { + $error = __('Task not defined'); + } + + // Build breadcrum. + $breadcrum = [ + [ + 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery', + 'label' => 'Discovery', + ], + ]; + + switch ($this->section) { + case 'app': + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Application'), + ]; + break; + + case 'cloud': + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Cloud'), + ]; + break; + + case 'custom': + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Custom'), + ]; + break; + + default: + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Custom'), + ]; + break; + } + + $parameters = ''; + if (empty($this->idTask) === false) { + $parameters .= '&id_task='.$this->idTask; + } + + $breadcrum[] = [ + 'link' => $this->url.'&mode='.$this->mode.$parameters, + 'label' => 'Task definition', + 'selected' => ((0 === (int) $this->currentPage) ? 1 : 0), + ]; + + foreach ($this->iniFile['config_steps']['name'] as $key => $step) { + $parameters = '&mode='.$this->mode.'&page='.$key; + if (empty($this->idTask) === false) { + $parameters .= '&id_task='.$this->idTask; + } + + $breadcrum[] = [ + 'link' => $this->url.$parameters, + 'label' => $step, + 'selected' => (($key === (int) $this->currentPage) ? 1 : 0), + ]; + } + + // Avoid to print header out of wizard. + $this->prepareBreadcrum($breadcrum); + + // Header. + ui_print_page_header( + $this->iniFile['discovery_extension_definition']['name'], + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + if ($error !== false) { + ui_print_error_message( + $error + ); + return; + } else if ($action !== '') { + ui_print_success_message(__('Operation realized')); + + if (empty($isTheEnd) === false) { + header('Location:'.$config['homeurl'].'index.php?sec=discovery&sec2=godmode/servers/discovery&wiz=tasklist'); + } + } + + $_url = ui_get_full_url( + sprintf( + $this->url.'&mode=%s&page=%s%s', + $this->mode, + $this->nextPage(), + (empty($this->idTask) === false) ? '&id_task='.$this->idTask : '', + ) + ); + + $table = new StdClass(); + $table->id = 'form_editor'; + $table->width = '100%'; + $table->class = 'databox filter-table-adv max_floating_element_size'; + + $table->style = []; + $table->style[0] = 'width: 50%'; + $table->style[1] = 'width: 50%'; + $table->data = []; + if ($this->currentPage === 0) { + // If page is 0 then create form for task definition. + $table->data = $this->viewTaskDefinition(); + } else { + // If page is bigger than 0 then render form .ini. + $table->data = $this->viewMacroForm(); + } + + echo '
'; + html_print_table($table); + + $actionButtons = ''; + + if ($this->currentPage !== $this->nextPage()) { + $actionButtons = html_print_submit_button( + __('Next'), + 'next_button', + false, + [ + 'class' => 'sub', + 'icon' => 'plus', + ], + true + ); + } + + $actionButtons .= html_print_submit_button( + __('Complete setup'), + 'complete_button', + false, + [ + 'class' => 'sub', + 'icon' => 'update', + 'value' => '1', + ], + true + ); + + html_print_action_buttons($actionButtons); + echo '
'; + + } + + + /** + * Draw a select with the pandora data + * + * @param string $selectData Type of select. + * @param string $name Name of select. + * @param string $defaultValue Default value. + * @param boolean $multiple Define if the select is multiple. + * @param boolean $required Define if field is required. + * + * @return string Return the html select. + */ + private function drawSelectPandora($selectData, $name, $defaultValue, $multiple=false, $required=false) + { + if ($multiple === true && $selectData !== 'interval') { + $name .= '[]'; + $defaultValue = json_decode($defaultValue); + } else { + $defaultValue = io_safe_input($defaultValue); + } + + switch ($selectData) { + case 'agent_groups': + $input = html_print_select_groups( + false, + 'AR', + true, + $name, + $defaultValue, + '', + '', + '', + true, + $multiple, + false, + '', + false, + false, + false, + false, + 'id_grupo', + true, + false, + false, + false, + false, + $required + ); + break; + + case 'agents': + $input = html_print_select_from_sql( + 'SELECT nombre, alias as n FROM tagente', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%;', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'module_groups': + $input = html_print_select_from_sql( + 'SELECT id_mg, name + FROM tmodule_group ORDER BY name', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'modules': + $input = html_print_select_from_sql( + 'select nombre, nombre as n from tagente_modulo', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'module_types': + $input = html_print_select_from_sql( + 'select nombre, descripcion from ttipo_modulo', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'status': + $module_status_arr = []; + // Default. + $module_status_arr[AGENT_MODULE_STATUS_NORMAL] = __('Normal'); + $module_status_arr[AGENT_MODULE_STATUS_WARNING] = __('Warning'); + $module_status_arr[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical'); + $module_status_arr[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown'); + $module_status_arr[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); + $input = html_print_select( + $module_status_arr, + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + '', + false, + 'width:100%', + false, + false, + false, + '', + false, + false, + $required, + false, + true, + true + ); + break; + + case 'alert_templates': + $input = html_print_select_from_sql( + 'select id, name from talert_templates', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'alert_actions': + $input = html_print_select_from_sql( + 'select id, name from talert_actions', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'interval': + $input = html_print_extended_select_for_time( + $name, + (string) $defaultValue, + '', + '', + '0', + false, + true + ); + break; + + case 'tags': + $input = html_print_select_from_sql( + 'select id_tag, name from ttag', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.custom': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "custom"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.aws': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "AWS"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.azure': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "AZURE"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.sap': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "SAP"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.snmp': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "SNMP"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.gcp': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "GOOGLE"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.wmi': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "WMI"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'os': + $input = html_print_select_from_sql( + 'SELECT id_os, name FROM tconfig_os ORDER BY name', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + default: + $input = html_print_select( + [], + $name, + $defaultValue, + '', + '', + 0, + true + ); + break; + } + + return $input; + } + + + /** + * Draw input from parameters of .ini. + * + * @param array $parameters Configuration of input. + * @param boolean $implicit Indicates if all the configuration is indicated in the array. + * + * @return string Html from input. + */ + public function drawInput($parameters, $implicit=false) + { + $input = ''; + $defaultValue = $this->macrosValues[$parameters['macro']]; + switch ($parameters['type']) { + case 'string': + $input = html_print_input_text( + $parameters['macro'], + $defaultValue, + '', + 50, + 255, + true, + false, + ($parameters['mandatory_field'] === false) ? false : true + ); + break; + + case 'number': + $config = [ + 'type' => 'number', + 'name' => $parameters['macro'], + 'value' => $defaultValue, + 'return' => true, + ]; + if ($parameters['mandatory_field'] !== false) { + $config['required'] = true; + } + + $input = html_print_input($config); + break; + + case 'password': + $isEncrypted = (bool) $this->macrosValues[$parameters['encrypt_on_true']]; + if ($isEncrypted === true) { + $defaultValueEncrypted = $this->encryptPassword($defaultValue, true); + if (empty($defaultValueEncrypted) === false) { + $defaultValue = $defaultValueEncrypted; + } + } + + $input = html_print_input_password( + $parameters['macro'], + $defaultValue, + '', + 50, + 255, + true, + false, + ($parameters['mandatory_field'] === false) ? false : true, + '', + 'on' + ); + if (empty($parameters['encrypt_on_true']) === false) { + $input .= html_print_input_hidden( + $parameters['macro'].'_encrypt', + $parameters['encrypt_on_true'], + true + ); + } + break; + + case 'checkbox': + $input = html_print_checkbox_switch( + $parameters['macro'], + 1, + (bool) $defaultValue, + true + ); + break; + + case 'textarea': + $input = html_print_textarea( + $parameters['macro'], + 5, + 20, + $defaultValue, + ($parameters['mandatory_field'] === false) ? '' : 'required="required"', + true + ); + break; + + case 'select': + if (in_array($parameters['select_data'], $this->pandoraSelectData) === true) { + $input = $this->drawSelectPandora( + $parameters['select_data'], + $parameters['macro'], + $defaultValue, + false, + ($parameters['mandatory_field'] === false) ? false : true, + ); + $parameters['type'] = $parameters['select_data']; + } else { + if ($implicit === false) { + $options = $this->iniFile[$parameters['select_data']]['option']; + } else { + $options = $parameters['select_data']; + } + + $input = html_print_select( + $options, + $parameters['macro'], + $defaultValue, + '', + __('None selected'), + '', + true, + false, + true, + '', + false, + 'width: 100%;', + false, + false, + false, + '', + false, + false, + ($parameters['mandatory_field'] === false) ? false : true, + ); + } + break; + + case 'multiselect': + if (in_array($parameters['select_data'], $this->pandoraSelectData) === true) { + $input = $this->drawSelectPandora( + $parameters['select_data'], + $parameters['macro'], + $defaultValue, + true, + ); + $parameters['type'] = $parameters['select_data']; + } else { + if ($implicit === false) { + $options = $this->iniFile[$parameters['select_data']]['option']; + } else { + $options = $parameters['select_data']; + } + + $input = html_print_select( + $options, + $parameters['macro'].'[]', + json_decode($defaultValue, true), + '', + '', + 0, + true, + true, + true, + '', + false, + 'width: 100%', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true + ); + } + break; + + case 'tree': + // Show bucket tree explorer. + ui_require_javascript_file('pandora_snmp_browser'); + if ($implicit === false) { + $treeData = $this->iniFile[$parameters['tree_data']]; + $treeInfo = $this->getTreeStructure($parameters, $treeData); + } else { + $treeData = $parameters['tree_data']; + $treeInfo = $this->getTreeStructureByScript($parameters, $treeData); + } + + $input = ui_print_tree( + $treeInfo, + // Id. + 0, + // Depth. + 0, + // Last. + 0, + // Last_array. + [], + // Sufix. + true, + // Return. + true, + // Descriptive ids. + false + ); + break; + + default: + $input = html_print_input_text( + $parameters['macro'], + $defaultValue, + '', + 50, + 255, + true, + false, + ($parameters['mandatory_field'] === false) ? false : true + ); + break; + } + + $input .= html_print_input_hidden( + $parameters['macro'].'type', + $parameters['type'], + true + ); + $class = ''; + if ($parameters['show_on_true'] !== null) { + $class = $parameters['macro'].'_hide'; + $input .= $this->showOnTrue($parameters['show_on_true'], $class); + } + + $name = $parameters['name']; + if (empty($parameters['tip']) === false) { + $name .= ui_print_help_tip($parameters['tip'], true); + } + + return html_print_label_input_block( + $name, + $input, + ['div_class' => $class] + ); + } + + + /** + * Return the task app from database. + * + * @return array $task Task of database. + */ + private function getTask() + { + return db_get_row_filter( + 'trecon_task', + [ + 'id_app' => $this->id, + 'id_rt' => $this->idTask, + 'type' => 15, + ], + ); + } + + + /** + * Returns the value of the macro. + * + * @param string $macro Name of macro for filter. + * + * @return mixed Value of the macro. + */ + private function getValueMacro($macro) + { + return db_get_value_filter( + 'value', + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $macro, + ] + ); + } + + + /** + * Return form for macro form. + * + * @return array $form Form macro. + */ + private function viewMacroForm() + { + $data = []; + + $macros = db_get_all_rows_filter( + 'tdiscovery_apps_tasks_macros', + ['id_task' => $this->idTask], + ['*'] + ); + if ($macros !== false) { + foreach ($macros as $key => $macro) { + $this->macrosValues[$macro['macro']] = io_safe_output($macro['value']); + } + } + + // Process ini or script. + $customFields = $this->iniFile['config_steps']['custom_fields'][$this->currentPage]; + $customFieldsByScript = $this->getStructureFormByScript($this->iniFile['config_steps']['script_data_fields'][$this->currentPage]); + + if ($customFields === null && $customFieldsByScript === null) { + $data[0][0] = html_print_image( + 'images/no_data_toshow.png', + true, + ['class' => 'w200px'] + ); + $data[1][0] = html_print_input_hidden( + 'action', + 'process_macro', + true + ); + return $data; + } + + $columns = 2; + if ($this->iniFile['config_steps']['fields_columns'][$this->currentPage] !== null + && $this->iniFile['config_steps']['fields_columns'][$this->currentPage] === 1 + ) { + $columns = 1; + } + + $row = 0; + $col = 0; + foreach ($customFieldsByScript as $key => $value) { + $this->nameFields[] = $value['macro']; + $data[$row][$col] = $this->drawInput($value, true); + $col++; + if ($col == $columns) { + $row++; + $col = 0; + } + } + + foreach ($this->iniFile[$customFields]['macro'] as $key => $id) { + $parameters = [ + 'macro' => $id, + 'name' => $this->iniFile[$customFields]['name'][$key], + 'tip' => $this->iniFile[$customFields]['tip'][$key], + 'type' => $this->iniFile[$customFields]['type'][$key], + 'placeholder' => $this->iniFile[$customFields]['placeholder'][$key], + 'mandatory_field' => $this->iniFile[$customFields]['mandatory_field'][$key], + 'show_on_true' => $this->iniFile[$customFields]['show_on_true'][$key], + 'encrypt_on_true' => $this->iniFile[$customFields]['encrypt_on_true'][$key], + 'select_data' => $this->iniFile[$customFields]['select_data'][$key], + 'tree_data' => $this->iniFile[$customFields]['tree_data'][$key], + ]; + $this->nameFields[] = $id; + $data[$row][$col] = $this->drawInput($parameters); + $col++; + if ($col == $columns) { + $row++; + $col = 0; + } + } + + $data[($row + 1)][1] = html_print_input_hidden( + 'action', + 'process_macro', + true + ); + $data[($row + 1)][1] .= html_print_input_hidden( + 'name_fields', + implode(',', $this->nameFields), + true + ); + + return $data; + } + + + /** + * Return form for task definition. + * + * @return array $form Form for task definition. + */ + private function viewTaskDefinition() + { + $task = $this->getTask(); + + $data = []; + $data[0][0] = html_print_label_input_block( + __('Task name'), + html_print_input_text( + 'task_name', + $task['name'], + '', + 50, + 255, + true, + false, + true + ) + ); + + $data[1][0] = html_print_label_input_block( + __('Description'), + html_print_textarea( + 'description', + 5, + 20, + $task['description'], + '', + true + ) + ); + + $data[2][0] = html_print_label_input_block( + __('Discovery server'), + html_print_select_from_sql( + sprintf( + 'SELECT id_server, name + FROM tserver + WHERE server_type = %d + ORDER BY name', + SERVER_TYPE_DISCOVERY + ), + 'discovery_server', + $task['id_recon_server'], + '', + '', + '0', + true, + false, + true, + false, + false, + false, + GENERIC_SIZE_TEXT, + '', + false + ) + ); + + $data[3][0] = html_print_label_input_block( + __('Group'), + html_print_select_groups( + false, + 'AR', + false, + 'group', + $task['id_group'], + '', + '', + 0, + true, + false, + false, + '', + false, + false, + false, + false, + 'id_grupo', + false, + false, + false, + false, + false, + true + ) + ); + + $inputs_interval = html_print_select( + [ + 'defined' => 'Defined', + 'manual' => 'Manual', + ], + 'mode_interval', + ($task['interval_sweep'] === '0') ? 'manual' : 'defined', + 'changeModeInterval(this)', + '', + '0', + true, + false, + true, + '', + false + ).html_print_extended_select_for_time( + 'interval', + (empty($task['interval_sweep']) === true) ? '300' : $task['interval_sweep'], + '', + '', + '0', + false, + true, + false, + true, + ); + $js_variables = ''; + $data[4][0] = html_print_label_input_block( + __('Interval'), + html_print_div( + [ + 'style' => 'display: flex;max-width: 345px; justify-content: space-between;', + 'content' => $inputs_interval.$js_variables, + ], + true + ) + ); + + $data[5][0] = html_print_label_input_block( + __('Timeout').ui_print_help_tip('This timeout will be applied for each task execution', true), + html_print_extended_select_for_time( + 'tiemout', + (empty($task['executions_timeout']) === true) ? '60' : $task['executions_timeout'], + '', + '', + '0', + false, + true + ), + ); + + $data[6][0] = html_print_input_hidden( + 'action', + 'task_definition_form', + true + ); + + $data[7][0] = html_print_input_hidden( + 'id_task', + $task['id_rt'], + true + ); + + return $data; + } + + + /** + * Sabe data from task definition form. + * + * @return string $error Error string if exist. + */ + private function processTaskDefinition() + { + $taskName = get_parameter('task_name', ''); + $description = get_parameter('description', ''); + $discoveryServer = get_parameter('discovery_server', ''); + $group = get_parameter('group', 0); + $mode_interval = get_parameter('mode_interval', 'defined'); + $interval = get_parameter('interval', ''); + $tiemout = get_parameter('tiemout', 60); + $completeTask = get_parameter('complete_button', ''); + + if ($mode_interval === 'manual') { + $interval = '0'; + } + + $error = false; + + if ($taskName === '' + || $discoveryServer === '' + || $group === '' + || $interval === '' + ) { + $error = __('Fields empties'); + return $error; + } + + if ($this->idTask === '') { + db_process_sql_begin(); + try { + $_idTask = db_process_sql_insert( + 'trecon_task', + [ + 'id_app' => $this->id, + 'name' => $taskName, + 'description' => $description, + 'id_group' => $group, + 'interval_sweep' => $interval, + 'id_recon_server' => $discoveryServer, + 'type' => 15, + 'setup_complete' => (empty($completeTask) === false) ? 1 : 0, + 'executions_timeout' => $tiemout, + ] + ); + + if ($_idTask === false) { + $error = __('Error creating the discovery task'); + } else { + $this->idTask = $_idTask; + $this->autoLoadConfigMacro(); + } + } catch (Exception $e) { + $error = __('Error creating the discovery task'); + } + + if ($error === false) { + db_process_sql_commit(); + } else { + db_process_sql_rollback(); + } + } else { + $result = db_process_sql_update( + 'trecon_task', + [ + 'id_app' => $this->id, + 'name' => $taskName, + 'description' => $description, + 'id_group' => $group, + 'interval_sweep' => $interval, + 'id_recon_server' => $discoveryServer, + 'type' => 15, + 'setup_complete' => (empty($completeTask) === false) ? 1 : 0, + 'executions_timeout' => $tiemout, + ], + ['id_rt' => $this->idTask] + ); + + if ($result === false) { + $error = __('Error updating the discovery task'); + } + } + + return $error; + } + + + /** + * Process the values of input from macro defined in .ini + * + * @return string $error Error string if exist. + */ + private function processCustomMacro() + { + $error = false; + + $keyParameters = explode(',', get_parameter('name_fields', '')); + + foreach ($keyParameters as $v => $key) { + $type = get_parameter($key.'type', ''); + switch ($type) { + case 'checkbox': + $value = get_parameter_switch($key, 0); + break; + + case 'multiselect': + $value = io_safe_input(json_encode(get_parameter($key, ''))); + break; + + case 'password': + $value = get_parameter($key, ''); + $encryptKey = get_parameter($key.'_encrypt', ''); + if ($encryptKey !== '') { + $encrypt = (bool) get_parameter_switch($encryptKey, 0); + if ($encrypt === true) { + $valueEncrypt = $this->encryptPassword($value); + if (empty($valueEncrypt) === false) { + $value = $valueEncrypt; + } + } + } + break; + + default: + $value = get_parameter($key, ''); + break; + } + + if (is_array($value) === true) { + $value = io_safe_input(json_encode($value)); + } + + $exist = db_get_row_filter( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + ] + ); + + if (in_array($type, $this->pandoraSelectData) === false) { + $type = 'custom'; + } + + if ($exist === false) { + $result = db_process_sql_insert( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + 'value' => $value, + 'type' => $type, + ] + ); + if ($result === false) { + $error = __('Field %s not insert', $key); + } + } else { + $result = db_process_sql_update( + 'tdiscovery_apps_tasks_macros', + [ + 'value' => $value, + 'type' => $type, + ], + [ + 'id_task' => $this->idTask, + 'macro' => $key, + ] + ); + if ($result === false) { + $error = __('Field %s not updated', $key); + } + } + } + + $completeTask = get_parameter('complete_button', ''); + if (empty($completeTask) === false) { + $result = db_process_sql_update( + 'trecon_task', + ['setup_complete' => 1], + ['id_rt' => $this->idTask] + ); + if ($result === false) { + $error = __('Task not updated'); + } + } + + return $error; + } + + + /** + * Check if name of input macro is correct. + * + * @param string $name Name of input. + * + * @return boolean value true if name is correct. + */ + private function isCorrectNameInput($name) + { + if (substr($name, 0, 1) === '_' && substr($name, -1) === '_') { + return true; + } else { + return false; + } + } + + + /** + * Return logic for component show on true. + * + * @param string $checkbox Name the checkbox for hide input. + * @param string $elementToHide Name the element to hide HIS PARENT. + * + * @return string String Name the element + */ + private function showOnTrue($checkbox, $elementToHide) + { + return ''; + } + + + /** + * Load the macros task in database + * + * @throws Exception Excepcion to control possible error for default value. + * + * @return void + */ + private function autoLoadConfigMacro() + { + $defaultValues = $this->iniFile['discovery_extension_definition']['default_value']; + + foreach ($defaultValues as $key => $value) { + if ($value === false) { + $value = 0; + } + + $result = db_process_sql_insert( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + 'value' => (string) io_safe_input($value), + 'type' => 'custom', + ] + ); + if ($result === false) { + throw new Exception('Error creating task'); + } + } + + $tempFiles = $this->iniFile['tempfile_confs']['file']; + + foreach ($tempFiles as $key => $value) { + $result = db_process_sql_insert( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + 'value' => (string) io_safe_input($value), + 'type' => 'custom', + 'temp_conf' => 1, + ] + ); + if ($result === false) { + throw new Exception('Error creating task'); + } + } + } + + + /** + * Return array structure for draw tree when array is by .ini. + * + * @param array $parent Parent from the tree. + * @param array $firstChildren First children from parent. + * + * @return array $treeInfo Return the array with format for render treee + */ + private function getTreeStructure($parent, $firstChildren) + { + $treeInfo = []; + foreach ($firstChildren['name'] as $key => $value) { + $checked = false; + $name = (empty($firstChildren['macro'][$key]) === false) ? $firstChildren['macro'][$key].'[]' : $parent['id'].'[]'; + $nameField = (empty($firstChildren['macro'][$key]) === false) ? $firstChildren['macro'][$key] : $parent['id']; + if (in_array($nameField, $this->nameFields) === false) { + $this->nameFields[] = $nameField; + } + + $checkedValues = json_decode(io_safe_output($this->macrosValues[$nameField]), true); + if (empty($checkedValues) === false) { + if (in_array($firstChildren['value'][$key], $checkedValues)) { + $checked = true; + } + } + + $treeInfo['__LEAVES__'][$key] = [ + 'label' => $value, + 'selectable' => (bool) $firstChildren['selectable'][$key], + 'name' => $name, + 'value' => $firstChildren['value'][$key], + 'checked' => $checked, + ]; + + if (empty($firstChildren['children'][$key]) === false) { + $children = $this->iniFile[$firstChildren['children'][$key]]; + $treeInfo['__LEAVES__'][$key]['sublevel'] = $this->getTreeStructure($parent, $children); + } + } + + return $treeInfo; + } + + + /** + * Return array structure for draw tree when array is by script. + * + * @param array $parent Parent from the tree. + * @param array $firstChildren First children from parent. + * + * @return array $treeInfo Return the array with format for render treee + */ + private function getTreeStructureByScript($parent, $firstChildren) + { + $treeInfo = []; + foreach ($firstChildren as $key => $value) { + $checked = false; + $name = (empty($value['macro']) === false) ? $value['macro'].'[]' : $parent['macro'].'[]'; + $nameField = (empty($value['macro']) === false) ? $value['macro'] : $parent['macro']; + if (in_array($nameField, $this->nameFields) === false) { + $this->nameFields[] = $nameField; + } + + $checkedValues = json_decode(io_safe_output($this->macrosValues[$nameField]), true); + if (empty($checkedValues) === false) { + if (in_array($value['value'], $checkedValues, true) === true) { + $checked = true; + } + } + + $treeInfo['__LEAVES__'][$key] = [ + 'label' => $value['name'], + 'selectable' => (bool) $value['selectable'], + 'name' => $name, + 'value' => $value['value'], + 'checked' => $checked, + ]; + + if (empty($value['children']) === false) { + $children = $value['children']; + $treeInfo['__LEAVES__'][$key]['sublevel'] = $this->getTreeStructureByScript($parent, $children); + } + } + + return $treeInfo; + } + + + /** + * Return a json with the form structure for draw. + * + * @param mixed $command String. + * + * @return array Result of command. + */ + private function getStructureFormByScript($command) + { + global $config; + $executionFiles = $this->iniFile['discovery_extension_definition']['execution_file']; + foreach ($executionFiles as $key => $file) { + $file = $config['homedir'].$this->path.'/'.$this->mode.'/'.$file; + $command = str_replace($key, $file, $command); + } + + $values = $this->replaceValues($command); + $command = $values['command']; + $toDelete = $values['delete']; + if (empty($command) === false) { + $result = $this->executeCommand($command); + } + + if (count($toDelete) > 0) { + foreach ($toDelete as $key => $folder) { + Files::rmrf($folder); + } + } + + return json_decode($result, true); + } + + + /** + * Replace values in command + * + * @param string $command String command for replace macros. + * + * @return array $values Command and files to delete. + */ + private function replaceValues($command) + { + preg_match_all('/\b_[a-zA-Z0-9]*_\b/', $command, $matches); + $foldersToDelete = []; + foreach ($matches[0] as $key => $macro) { + $row = db_get_row_filter( + 'tdiscovery_apps_tasks_macros', + [ + 'macro' => $macro, + 'id_task' => $this->idTask, + ] + ); + if ($row !== false) { + if (in_array($row['type'], $this->pandoraSelectData) === true) { + $value = $this->getValuePandoraSelect($row['type'], $row['value']); + $command = str_replace($macro, $value, $command); + } else if ((int) $row['temp_conf'] === 1) { + $nameFile = $row['id_task'].'_'.$row['id_task'].'_'.uniqid(); + $value = $this->getValueTempFile($nameFile, $row['value']); + $command = str_replace($macro, $value, $command); + $foldersToDelete[] = str_replace($nameFile, '', $value); + } else { + $command = str_replace($macro, io_safe_output($row['value']), $command); + } + } + } + + return [ + 'command' => $command, + 'delete' => $foldersToDelete, + ]; + } + + + /** + * Create a temp file for tempfile_confs macros. + * + * @param string $nameFile Name file only. + * @param string $content Content to save to file. + * + * @return string $pathNameFile Name file and with path for replace. + */ + private function getValueTempFile($nameFile, $content) + { + global $config; + $content = io_safe_output($content); + $content = $this->replaceValues($content)['command']; + $nameTempDir = $config['attachment_store'].'/temp_files/'; + if (file_exists($nameTempDir) === false) { + mkdir($nameTempDir); + } + + $tmpPath = Files::tempdirnam( + $nameTempDir, + 'temp_files_' + ); + $pathNameFile = $tmpPath.'/'.$nameFile; + file_put_contents($pathNameFile, $content); + + return $pathNameFile; + } + + + /** + * Return the correct value for pandora select + * + * @param string $type Type of input. + * @param string $id Value of the row macro. + * + * @return string $id New id with the values replaced + */ + private function getValuePandoraSelect($type, $id) + { + $id = io_safe_output($id); + $idsArray = json_decode($id); + if (is_array($idsArray) === false) { + $idsArray = [$id]; + } + + foreach ($idsArray as $key => $v) { + $value = false; + switch ($type) { + case 'agent_groups': + $value = groups_get_name($v); + break; + + case 'module_groups': + $value = modules_get_modulegroup_name($v); + break; + + case 'tags': + $value = tags_get_name($v); + break; + + case 'alert_templates': + $value = alerts_get_alert_template_name($v); + break; + + case 'alert_actions': + $value = alerts_get_alert_action_name($v); + break; + + case 'credentials.custom': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'user' => $credentials['username'], + 'password' => $credentials['password'], + ] + ) + ); + break; + + case 'credentials.aws': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'access_key_id' => $credentials['username'], + 'secret_access_key' => $credentials['password'], + ] + ) + ); + break; + + case 'credentials.azure': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'client_id' => $credentials['username'], + 'application_secret' => $credentials['password'], + 'tenant_domain' => $credentials['extra_1'], + 'subscription_id' => $credentials['extra_2'], + ] + ) + ); + break; + + case 'credentials.gcp': + $credentials = CredentialStore::getKey($v); + $value = base64_encode($credentials['extra_1']); + break; + + case 'credentials.sap': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'user' => $credentials['username'], + 'password' => $credentials['password'], + ] + ) + ); + break; + + case 'credentials.snmp': + $credentials = CredentialStore::getKey($v); + $value = base64_encode($credentials['extra_1']); + break; + + case 'credentials.wmi': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'user' => $credentials['username'], + 'password' => $credentials['password'], + 'namespace' => $credentials['extra_1'], + ] + ) + ); + break; + + case 'os': + $value = get_os_name($v); + break; + + default: + continue; + } + + if ($value !== false) { + $id = str_replace($v, io_safe_output($value), $id); + } + } + + return $id; + } + + + /** + * Encrypt and decode password with the user script. + * + * @param string $password Password to encrypt. + * @param boolean $decode True for decode password. + * + * @return string Password encrypted + */ + private function encryptPassword($password, $decode=false) + { + global $config; + if ($decode === false) { + $command = $this->iniFile['discovery_extension_definition']['passencrypt_exec']; + $nameFile = $this->iniFile['discovery_extension_definition']['passencrypt_script']; + $file = $config['homedir'].$this->path.'/'.$this->mode.'/'.$nameFile; + $command = str_replace('_passencrypt_script_', $file, $command); + } else { + $command = $this->iniFile['discovery_extension_definition']['passdecrypt_exec']; + $nameFile = $this->iniFile['discovery_extension_definition']['passdecrypt_script']; + $file = $config['homedir'].$this->path.'/'.$this->mode.'/'.$nameFile; + $command = str_replace('_passdecrypt_script_', $file, $command); + } + + $command = str_replace('_password_', $password, $command); + + if (empty($command) === false) { + return $this->executeCommand($command); + } else { + return false; + } + } + + + /** + * Valid the .ini + * + * @param array $iniForValidate IniFile to validate. + * + * @return mixed Return false if is ok and string for error. + */ + public static function validateIni($iniForValidate) + { + $discoveryExtension = $iniForValidate['discovery_extension_definition']; + + if (!$discoveryExtension) { + return __('The file does not contain the block \'discovery_extension_definition\''); + } + + if (!array_key_exists('short_name', $discoveryExtension)) { + return __('The \'discovery_extension_definition\' block must contain a \'short_name\' parameter'); + } + + $defaultValues = $discoveryExtension['default_value']; + foreach ($defaultValues as $key => $value) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $key)) { + return __( + 'The \'discovery_extension_definition\' block \'default_value\' parameter has a key with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $key + ); + } + } + + $shortName = $discoveryExtension['short_name']; + + if (!preg_match('/^[A-Za-z0-9._-]+$/', $shortName)) { + return __('The \'discovery_extension_definition\' block \'short_name\' parameter contains illegal characters. Use only letters (A-Z and a-z), numbers (0-9), points (.), hyphens (-) and underscores (_)'); + } + + if (!array_key_exists('section', $discoveryExtension) || !array_key_exists('name', $discoveryExtension)) { + return __('The \'discovery_extension_definition\' block must contain a \'section\' and a \'name\' parameters'); + } + + $section = $discoveryExtension['section']; + $name = $discoveryExtension['name']; + + if (!in_array($section, ['app', 'cloud', 'custom'])) { + return __('The \'discovery_extension_definition\' block \'section\' parameter must be \'app\', \'cloud\' or \'custom\''); + } + + if (empty($name)) { + return __('The \'discovery_extension_definition\' block \'name\' parameter can not be empty'); + } + + if (!array_key_exists('exec', $discoveryExtension)) { + return __('The \'discovery_extension_definition\' block must contain an \'exec\' parameter'); + } + + $execs = $discoveryExtension['exec']; + + foreach ($execs as $exec) { + if (empty($exec)) { + return __('All the \'discovery_extension_definition\' block \'exec\' parameter definitions can not be empty'); + } + } + + $checkEmptyFields = [ + 'passencrypt_script', + 'passencrypt_exec', + 'passdecrypt_script', + 'passdecrypt_exec', + ]; + + foreach ($checkEmptyFields as $key) { + if ($discoveryExtension[$key] !== null && empty($discoveryExtension[$key]) === true) { + return __('The \'discovery_extension_definition\' block \'%s\' parameter can not be empty', $key); + } + } + + foreach ($discoveryExtension['execution_file'] as $key => $value) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $key)) { + return __('The \'discovery_extension_definition\' block \'execution_file\' parameter has a key with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', $key); + } + + if (empty($value) === true) { + return __('All the \'discovery_extension_definition\' block \'execution_file\' parameter definitions can not be empty: \'%s\'', $key); + } + } + + if ($iniForValidate['config_steps'] !== null && empty($iniForValidate['config_steps']) === true) { + return __('The \'config_steps\' block must contain a \'name\' parameter that can not be empty.'); + } + + foreach ($iniForValidate['config_steps'] as $key => $value) { + foreach ($value as $innerKey => $inner_value) { + if (isset($inner_steps[$innerKey])) { + $inner_steps[$innerKey][$key] = $inner_value; + } else { + $inner_steps[$innerKey] = [$key => $inner_value]; + } + } + } + + $customFields = []; + foreach ($inner_steps as $key => $step) { + if (is_numeric($key) === false || $key === 0) { + return __('All the \'config_steps\' block parameters must use numbers greater than 0 as keys: \'%s\'.', $key); + } + + if (empty($step['name']) === true) { + return __('The \'config_steps\' block must contain a \'name\' parameter for all the configuration steps: \'%s\'', $key); + } + + if (empty($step['custom_fields']) === true + && empty($step['script_data_fields']) === true + ) { + return __('The \'config_steps\' block must contain a \'custom_fields\' or \'script_data_fields\' parameter that can not be empty'); + } else if (empty($step['custom_fields']) === false) { + if (empty($iniForValidate[$step['custom_fields']]) === true) { + return __('The \'config_steps\' block \'custom_fields\' parameter has a key value reference that does not exist: \'%s\'', $step['custom_fields']); + } else { + $customFields[] = $step['custom_fields']; + } + } + + $customFields[] = $step['name']; + } + + $requiredKeys = [ + 'macro', + 'name', + 'type', + ]; + + $validTypes = [ + 'string', + 'number', + 'password', + 'textarea', + 'checkbox', + 'select', + 'multiselect', + 'tree', + ]; + + $validSelectData = [ + 'agent_groups', + 'agents', + 'module_groups', + 'modules', + 'module_types', + 'status', + 'alert_templates', + 'alert_actions', + 'interval', + 'tags', + 'credentials.custom', + 'credentials.aws', + 'credentials.azure', + 'credentials.sap', + 'credentials.snmp', + 'credentials.gcp', + 'credentials.wmi', + 'os', + ]; + + $selectDataNames = []; + $treeDataNames = []; + + foreach ($customFields as $key => $customField) { + $innerFields = []; + foreach ($iniForValidate[$customField] as $key => $value) { + foreach ($value as $innerKey => $innerValue) { + if (isset($innerFields[$innerKey])) { + $innerFields[$innerKey][$key] = $innerValue; + } else { + $innerFields[$innerKey] = [$key => $innerValue]; + } + } + } + + foreach ($innerFields as $key => $field) { + if (is_numeric($key) === false || $key === 0) { + return __('All the \'%s\' block parameters must use numbers greater than 0 as keys: \'%s\'.', $customField, $key); + } + + foreach ($requiredKeys as $k => $value) { + if (empty($field[$value]) === true) { + return __('The \'%s\' block \'%s\' parameter definitions can not be empty: \'%s\'.', $customField, $value, $key); + } + } + + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $field['macro'])) { + return __('The \'%s\' block \'macro\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', $customField, $field['macro']); + } + + if (in_array($field['type'], $validTypes) === false) { + return __('The \'%s\' block \'type\' parameter has a definition with invalid value. Must be \'string\', \'number\', \'password\', \'textarea\', \'checkbox\', \'select\', \'multiselect\' or \'tree\': \'%s\'', $customField, $field['type']); + } + + if ($field['type'] === 'select' || $field['type'] === 'multiselect') { + if (empty($field['select_data']) === true) { + return __('All the \'%s\' block \'select_data\' parameter definitions can not be empty: \'%s\'.', $customField, $key); + } else if ($iniForValidate[$field['select_data']] === null && in_array($field['select_data'], $validSelectData) === false) { + return __( + 'The \'%s\' block \'select_data\' parameter has a definition with invalid select type. Must be \'agent_groups\', \'agents\', \'module_groups\', \'modules\', \'module_types\', \'tags\', \'status\', \'alert_templates\', \'alert_actions\', \'interval\', \'credentials.custom\', \'credentials.aws\', \'credentials.azure\', \'credentials.gcp\', \'credentials.sap\', \'credentials.snmp\', \'os\' or an existint reference: \'%s\'', + $customField, + $field['select_data'] + ); + } else if ($iniForValidate[$field['select_data']] !== null) { + $selectDataNames[] = $field['select_data']; + } + } + + if ($field['type'] === 'tree') { + if (empty($field['tree_data']) === true) { + return __('All the \'%s\' block \'tree_data\' parameter definitions can not be empty: \'%s\'', $field['macro'], $key); + } else if ($iniForValidate[$field['tree_data']] === null) { + return __('The \'%s\' block \'tree_data\' parameter has a key value reference that does not exist: \'%s\'', $customField, $field['tree_data']); + } else { + $treeDataNames[] = $field['tree_data']; + } + } + + if (empty($field['mandatory_field']) === false) { + $validValues = [ + 'true', + 'false', + '1', + '0', + 'yes', + 'no', + ]; + + if (in_array($field['mandatory_field'], $validValues) === false) { + return __( + 'The \'%s\' block \'mandatory_field\' parameter has a definition with invalid value. Must be \'true\' or \'false\', \'1\' or \'0\', \'yes\' or \'no\': \'%s\'', + $customField, + $field['mandatory_field'] + ); + } + } + + if ($field['tip'] !== null && empty($field['tip']) === true) { + return __('All the \'%s\' block \'tip\' parameter definitions can not be empty: \'%s\'.', $customField, $key); + } + + if ($field['placeholder'] !== null && empty($field['placeholder']) === true) { + return __('All the \'%s\' block \'placeholder\' parameter definitions can not be empty: \'%s\'.', $customField, $key); + } + + if (empty($field['show_on_true']) === false) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $field['show_on_true'])) { + return __( + 'The \'%s\' block \'show_on_true\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $customField, + $field['show_on_true'] + ); + } + } + + if (empty($field['encrypt_on_true']) === false) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $field['encrypt_on_true'])) { + return __( + 'The \'%s\' block \'encrypt_on_true\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $customField, + $field['encrypt_on_true'] + ); + } + } + } + } + + foreach ($treeDataNames as $key => $name) { + $error = self::validateTreeRecursive($name, $iniForValidate); + if ($error !== false) { + return $error; + } + } + + foreach ($selectDataNames as $key => $name) { + if (empty($iniForValidate[$name]['option']) === true) { + return __('The \'%s\' block must contain an \'option\' parameter', $name); + } + + foreach ($iniForValidate[$name]['option'] as $key => $option) { + if (empty($option) === true) { + return __('All the \'%s\' block \'option\' parameter definitions can not be empty: \'%s\'.', $name, $key); + } + } + } + + if ($iniForValidate['tempfile_confs'] !== null && empty($iniForValidate['tempfile_confs']['file']) === true) { + return __('The \'tempfile_confs\' block must contain a \'file\' parameter.'); + } + + foreach ($iniForValidate['tempfile_confs']['file'] as $key => $tempfile) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $key)) { + return __( + 'The \'tempfile_confs\' block \'file\' parameter has a key with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $key + ); + } + + if (empty($tempfile) === true) { + return __('All the \'tempfile_confs\' block \'file\' parameter definitions can not be empty: \'%s\'.', $key); + } + } + + return false; + } + + + /** + * Validate a tree recursively + * + * @param string $dataTree Name of parent data_tree. + * @param array $iniFile Inifile for search children. + * @param array $parents Array of parents for recursive action, DO NOT SET. + * + * @return boolean True if tree is correct. + */ + public static function validateTreeRecursive($dataTree, $iniFile, $parents=[]) + { + $innerData = []; + $parents[] = $dataTree; + foreach ($iniFile[$dataTree] as $key => $value) { + foreach ($value as $innerKey => $innerValue) { + if (isset($innerData[$innerKey])) { + $innerData[$innerKey][$key] = $innerValue; + } else { + $innerData[$innerKey] = [$key => $innerValue]; + } + } + } + + if (count($innerData) === 0) { + return __('The \'%s\' block must contain a \'name\' parameter that can not be empty.', $dataTree); + } + + foreach ($innerData as $key => $prop) { + if (is_numeric($key) === false || $key === 0) { + return __('All the \'%s\' block parameters must use numbers greater than 0 as keys: \'%s\'.', $dataTree, $key); + } + + if (empty($prop['name']) === true) { + return __('The \'%s\' block must contain a \'name\' parameter for all the tree elements: \'%s\'.', $dataTree, $key); + } + + if ($prop['selectable'] !== null && $prop['selectable'] === '') { + return __('All the \'%s\' block \'selectable\' parameter definitions can not be empty: \'%s\'.', $dataTree, $key); + } else { + $validValues = [ + 'true', + 'false', + '1', + '0', + 'yes', + 'no', + ]; + + if (in_array($prop['selectable'], $validValues) === false) { + return __( + 'The \'%s\' block \'selectable\' parameter has a definition with invalid value. Must be \'true\' or \'false\', \'1\' or \'0\', \'yes\' or \'no\': \'%s\'', + $dataTree, + $prop['selectable'] + ); + } + } + + if ($prop['macro'] !== null && !preg_match('/^_[a-zA-Z0-9]+_$/', $prop['macro'])) { + return __( + 'The \'%s\' block \'macro\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $dataTree, + $prop['macro'] + ); + } + + if ($prop['children'] !== null && empty($iniFile[$prop['children']]) === true) { + return __('The \'%s\' block \'children\' parameter has a key value reference that does not exist: \'%s\'', $dataTree, $prop['children']); + } else if (in_array($prop['children'], $parents) === true) { + return __('The \'%s\' block \'children\' parameter has a key value reference to a parent tree element: \'%s\'', $dataTree, $prop['children']); + } else if (empty($iniFile[$prop['children']]) === false) { + $result = self::validateTreeRecursive($prop['children'], $iniFile, $parents); + if ($result !== false) { + return $result; + } + } + } + + return false; + } + + + /** + * Excute command with the timeout of the task. + * + * @param string $command Command to execute. + * + * @return string Output of command + */ + private function executeCommand($command) + { + $task = $this->getTask(); + $timeout = $task['executions_timeout']; + + $descriptors = [ + 0 => [ + 'pipe', + 'r', + ], + 1 => [ + 'pipe', + 'w', + ], + 2 => [ + 'pipe', + 'w', + ], + ]; + + $process = proc_open($command, $descriptors, $pipes); + + if (!is_resource($process)) { + return false; + } + + stream_set_blocking($pipes[1], 0); + + stream_set_blocking($pipes[2], 0); + + if (!$timeout) { + $timeout = 5; + } + + $real_timeout = ($timeout * 1000000); + + $buffer = ''; + + while ($real_timeout > 0) { + $start = microtime(true); + + $read = [$pipes[1]]; + $other = []; + stream_select($read, $other, $other, 0, $real_timeout); + + $status = proc_get_status($process); + + $buffer .= stream_get_contents($pipes[1]); + + if ($status['running'] === false) { + break; + } + + $real_timeout -= ((microtime(true) - $start) * 1000000); + } + + if ($real_timeout <= 0) { + proc_terminate($process, 9); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + proc_close($process); + + return false; + } + + $errors = stream_get_contents($pipes[2]); + + if (empty($errors) === false && empty($buffer)) { + proc_terminate($process, 9); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + proc_close($process); + + return false; + } + + proc_terminate($process, 9); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + proc_close($process); + + return $buffer; + } + + +} diff --git a/pandora_console/include/class/SatelliteAgent.class.php b/pandora_console/include/class/SatelliteAgent.class.php index 31cd2550d9..29fa2e3b77 100644 --- a/pandora_console/include/class/SatelliteAgent.class.php +++ b/pandora_console/include/class/SatelliteAgent.class.php @@ -162,7 +162,7 @@ class SatelliteAgent extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/SatelliteCollection.class.php b/pandora_console/include/class/SatelliteCollection.class.php index 8af5f210c8..a1ef24393c 100644 --- a/pandora_console/include/class/SatelliteCollection.class.php +++ b/pandora_console/include/class/SatelliteCollection.class.php @@ -142,7 +142,7 @@ class SatelliteCollection extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/SnmpConsole.class.php b/pandora_console/include/class/SnmpConsole.class.php index e613ab57bf..4a2c32de2e 100644 --- a/pandora_console/include/class/SnmpConsole.class.php +++ b/pandora_console/include/class/SnmpConsole.class.php @@ -326,7 +326,7 @@ class SnmpConsole extends HTML [ 'id' => $tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, @@ -519,6 +519,8 @@ class SnmpConsole extends HTML $legend .= '
'; $legend .= ''; + echo '
'; + ui_toggle($legend, __('Legend')); // Load own javascript file. @@ -1331,17 +1333,8 @@ class SnmpConsole extends HTML * Show more information */ function toggleVisibleExtendedInfo(id, position) { - // Show all "Show more" - $('[id^=img_]').each(function() { - $(this).show(); - }); - // Hide all "Hide details" - $('[id^=img_hide_]').each(function() { - $(this).hide(); - }); var status = $('#eye_'+id).attr('data-show'); if(status == "show"){ - $('tr[id^=show_]').remove() $.ajax({ method: 'get', url: '', @@ -1360,14 +1353,14 @@ class SnmpConsole extends HTML datatype: "json", success: function(data) { let trap = JSON.parse(data); - var tr = $('#snmp_console tr').eq(position+1); + var tr = $('#snmp_console tr:not([id^="show_"])').eq(position+1); // Count. if ($('#filter_group_by').val() == 1) { let labelCount = '

'; let variableCount = `${trap['count']}
${trap['first']}
${trap['last']}`; - tr.after(`${labelCount}${variableCount}`); + tr.after(`${labelCount}${variableCount}`); } // Type. @@ -1405,27 +1398,27 @@ class SnmpConsole extends HTML let labelType = ''; let variableType = `${desc_trap_type}`; - tr.after(`${labelType}${variableType}`); + tr.after(`${labelType}${variableType}`); // Description. if (trap['description']) { let labelDesc = ''; let variableDesc = `${trap['description']}`; - tr.after(`${labelDesc}${variableDesc}`); + tr.after(`${labelDesc}${variableDesc}`); } // Enterprise String. let labelOid = ''; let variableOId = `${trap['oid']}`; - tr.after(`${labelOid}${variableOId}`); + tr.after(`${labelOid}${variableOId}`); // Variable bindings. let labelBindings = ''; let variableBindings = ''; if ($('#filter_group_by').val() == 1) { - labelBindings = ''; + labelBindings = ''; let new_url = 'index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view'; new_url += '&filter_severity='+$('#filter_severity').val(); @@ -1439,7 +1432,7 @@ class SnmpConsole extends HTML variableBindings = `${string}`; } else { - labelBindings = ''; + labelBindings = ''; const binding_vars = trap['oid_custom'].split("\t"); let string = ''; binding_vars.forEach(function(oid) { @@ -1448,7 +1441,7 @@ class SnmpConsole extends HTML variableBindings = `${string}`; } - tr.after(`${labelBindings}${variableBindings}`); + tr.after(`${labelBindings}${variableBindings}`); }, error: function(e) { console.error(e); @@ -1458,7 +1451,7 @@ class SnmpConsole extends HTML $('#img_'+id).hide(); $('#img_hide_'+id).show(); } else{ - $('tr[id^=show_]').remove(); + $(`tr#show_${id}`).remove(); $('#eye_'+id).attr('data-show', 'show'); $('#img_'+id).show(); $('#img_hide_'+id).hide(); diff --git a/pandora_console/include/class/TipsWindow.class.php b/pandora_console/include/class/TipsWindow.class.php index cf0824f626..ae4271fba9 100644 --- a/pandora_console/include/class/TipsWindow.class.php +++ b/pandora_console/include/class/TipsWindow.class.php @@ -475,7 +475,7 @@ class TipsWindow [ 'id' => 'list_tips_windows', 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'dom_elements' => 'lpfti', 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', 'columns' => $columns, diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 8d81ceee73..ea6f4fe92f 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -336,54 +336,7 @@ class WelcomeWindow extends Wizard public function loadWelcomeWindow() { global $config; - - $btn_configure_mail_class = 'pending'; - $btn_create_agent_class = 'pending'; - $btn_create_module_class = ''; - $btn_create_alert_class = ''; - $btn_create_discovery_class = 'pending'; - - $li_configure_mail_class = 'row_green'; - $li_create_agent_class = 'row_green'; - $li_create_module_class = 'row_grey'; - $li_create_alert_class = 'row_grey'; - $li_create_discovery_class = 'row_green'; - - if (empty($config['welcome_mail_configured']) === false) { - $btn_configure_mail_class = ' completed'; - } - - if (empty($config['welcome_id_agent']) === false) { - $btn_create_agent_class = ' completed'; - $btn_create_module_class = ' pending'; - $li_create_module_class = 'row_green'; - } - - if (empty($config['welcome_module']) === false) { - $btn_create_module_class = ' completed'; - $btn_create_alert_class = ' pending'; - $li_create_module_class = 'row_green'; - } - - if (empty($config['welcome_alert']) === false) { - $btn_create_alert_class = ' completed'; - $li_create_alert_class = 'row_green'; - } - - if (empty($config['welcome_task']) === false) { - $btn_create_discovery_class = ' completed'; - } - - if ((int) $config['welcome_state'] === WELCOME_FINISHED) { - // Nothing left to do. - $btn_configure_mail_class = ' completed'; - $btn_create_agent_class = ' completed'; - $btn_create_module_class = ' completed'; - $btn_create_alert_class = ' completed'; - $btn_create_discovery_class = ' completed'; - $li_create_module_class = 'row_green'; - $li_create_alert_class = 'row_green'; - } + $flag_task = false; $form = [ 'action' => '#', @@ -392,207 +345,279 @@ class WelcomeWindow extends Wizard 'class' => 'modal', ]; - $logo_url = 'images/custom_logo/pandora_logo_head_white_bg.png'; - if (enterprise_installed() === true) { $logo_url = ENTERPRISE_DIR.'/'.$logo_url; } - $inputs = [ - [ - 'class' => 'white_box', - 'block_content' => [ - [ - 'class' => 'centered_full', - 'arguments' => [ - 'type' => 'image', - 'src' => $logo_url, - 'value' => 1, - 'return' => true, - ], - ], - ], - ], - [ + if (check_acl($config['id_user'], 0, 'PM')) { + $flag_um = false; + $flag_cm = false; + $flag_su = false; + $flag_lv = false; + + $btn_update_manager_class = ' fail'; + $btn_configure_mail_class = ' fail'; + $btn_servers_up_class = ' fail'; + $btn_license_valid_class = ' fail'; + + $li_update_manager_class = 'row_grey'; + $li_configure_mail_class = 'row_grey'; + $li_servers_up_class = 'row_grey'; + $li_license_valid_class = 'row_grey'; + + include_once 'include/functions_update_manager.php'; + if (update_manager_verify_registration()) { + $btn_update_manager_class = ''; + $li_update_manager_class = 'row_green'; + $flag_um = true; + } + + if (empty($config['welcome_mail_configured']) === false) { + $btn_configure_mail_class = ''; + $li_configure_mail_class = 'row_green'; + $flag_cm = true; + } + + include_once 'include/functions_servers.php'; + if (check_all_servers_up() === true) { + $btn_servers_up_class = ''; + $li_servers_up_class = 'row_green'; + $flag_su = true; + } + + if (enterprise_installed()) { + $license_valid = true; + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + $days_to_expiry = ((strtotime($license['expiry_date']) - time()) / (60 * 60 * 24)); + if ($license === ENTERPRISE_NOT_HOOK || $days_to_expiry <= 30) { + $license_valid = false; + } + + if ($license_valid === true) { + $btn_license_valid_class = ''; + $li_license_valid_class = 'row_green'; + $flag_lv = true; + } else { + $btn_license_valid_class = 'fail'; + $li_license_valid_class = 'row_grey'; + $flag_lv = false; + } + } else { + $btn_license_valid_class = 'fail'; + $li_license_valid_class = 'row_grey'; + $flag_lv = false; + } + + $inputs[] = [ 'wrapper' => 'div', - 'block_id' => 'div_configure_mail', - 'class' => 'hole flex-row flex-items-center w98p '.$li_configure_mail_class, + 'block_id' => 'div_diagnosis', + 'class' => 'flex-row flex-items-center w98p ', 'direct' => 1, 'block_content' => [ [ - 'label' => __('Please ensure mail configuration matches your needs'), + 'label' => __('Post-installation status diagnostic'), 'arguments' => [ 'class' => 'first_lbl', - 'name' => 'lbl_create_agent', - 'id' => 'lbl_create_agent', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_configure_mail_class) === false) ? $btn_configure_mail_class : 'invisible_important', - 'mode' => 'onlyIcon', - ], - 'name' => 'btn_email_conf', - 'id' => 'btn_email_conf', + 'name' => 'lbl_diagnosis', + 'id' => 'lbl_diagnosis', ], ], ], - ], - [ - 'label' => 'Learn to monitor', - 'class' => 'extra', - 'arguments' => [ - 'class' => 'class="lbl_learn"', - 'name' => 'lbl_learn', - 'id' => 'lbl_learn', - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_create_agent', - 'class' => 'learn_content_indented flex-row flex-items-center w98p '.$li_create_agent_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Create an agent'), - 'arguments' => [ - 'class' => 'first_lbl', - 'name' => 'lbl_create_agent', - 'id' => 'lbl_create_agent', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_agent_class) === false) ? $btn_create_agent_class : 'invisible_important', - 'mode' => 'onlyIcon', + ]; + + if ($flag_um === false || $flag_cm === false || $flag_su === false || $flag_lv === false) { + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_update_manager', + 'class' => 'hole flex-row flex-items-center w98p '.$li_update_manager_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Warp Update registration'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_update_manager', + 'id' => 'lbl_update_manager', ], - 'name' => 'btn_create_agent', - 'id' => 'btn_create_agent', ], - ], - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_monitor_actions', - 'class' => 'learn_content_indented flex-row flex-items-center w98p '.$li_create_module_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Create a module to check if an agent is online'), - 'arguments' => [ - 'class' => 'second_lbl', - 'name' => 'lbl_check_agent', - 'id' => 'lbl_check_agent', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_module_class) === false) ? $btn_create_module_class : 'invisible_important', - 'mode' => 'onlyIcon', + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_update_manager_class) === false) ? $btn_update_manager_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_update_manager_conf', + 'id' => 'btn_update_manager_conf', ], - 'name' => 'btn_create_module', - 'id' => 'btn_create_module', ], ], - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_monitor_actions', - 'class' => 'hole learn_content_indented flex-row flex-items-center w98p '.$li_create_alert_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Be warned if something is wrong, create an alert on the module'), - 'arguments' => [ - 'class' => 'second_lbl', - 'name' => 'lbl_create_alert', - 'id' => 'lbl_create_alert', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_alert_class) === false) ? $btn_create_alert_class : 'invisible_important', - 'mode' => 'onlyIcon', + ]; + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_configure_mail', + 'class' => 'hole flex-row flex-items-center w98p '.$li_configure_mail_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Default mail to send alerts'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_create_agent', + 'id' => 'lbl_create_agent', ], - 'name' => 'btn_create_alert', - 'id' => 'btn_create_alert', ], - ], - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_discover', - 'class' => 'hole flex-row flex-items-center w98p '.$li_create_discovery_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Discover hosts and devices in your network'), - 'arguments' => [ - 'class' => 'first_lbl', - 'name' => 'lbl_discover_devices', - 'id' => 'lbl_discover_devices', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_discovery_class) === false) ? $btn_create_discovery_class : 'invisible_important', - 'mode' => 'onlyIcon', + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_configure_mail_class) === false) ? $btn_configure_mail_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_email_conf', + 'id' => 'btn_email_conf', ], - 'name' => 'btn_discover_devices', - 'id' => 'btn_discover_devices', ], ], + ]; + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_servers_up', + 'class' => 'hole flex-row flex-items-center w98p '.$li_servers_up_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('All servers running'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_servers_up', + 'id' => 'lbl_servers_up', + ], + ], + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_servers_up_class) === false) ? $btn_servers_up_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_servers_up_conf', + 'id' => 'btn_servers_up_conf', + ], + ], + ], + ]; + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_license_valid', + 'class' => 'hole flex-row flex-items-center w98p '.$li_license_valid_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Enterprise licence valid'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_license_valid', + 'id' => 'lbl_license_valid', + ], + ], + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_license_valid_class) === false) ? $btn_license_valid_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_license_valid_conf', + 'id' => 'btn_license_valid_conf', + ], + ], + ], + ]; + } else { + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_all_correct', + 'class' => 'hole flex-row flex-items-center w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('It seems that your Pandora FMS is working correctly and registered with ID:
#'.$config['pandora_uid'].'.
For more information use the self-diagnosis tool.'), + 'arguments' => [ + 'class' => 'first_lbl w98p', + 'name' => 'lbl_all_correct', + 'id' => 'lbl_all_correct', + ], + ], + ], + ]; + } + + if ($flag_um === false || $flag_cm === false || $flag_su === false || $flag_lv === false) { + $flag_task = true; + } + } + + // Task to do. + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_task_todo', + 'class' => 'flex-row flex-items-center w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Task to perform'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_task_todo', + 'id' => 'lbl_task_todo', + ], ], ], ]; - if (enterprise_installed() === true) { - $inputs[] = [ - 'wrapper' => 'div', - 'block_id' => 'div_not_working', - 'class' => 'hole flex-row flex-items-center w98p', - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('If something is not working as expected, look for this icon and report!'), - 'arguments' => [ - 'class' => 'first_lbl', - 'name' => 'lbl_not_working', - 'id' => 'lbl_not_working', - ], - ], - [ - 'label' => html_print_image( - 'images/feedback-header.png', - true, - [ - 'onclick' => '$(\'#feedback-header\').click()', - 'style' => 'cursor: pointer;', - ] - ), + $fields['wizard_agent'] = __('Agent installation wizard'); + $fields['check_web'] = __('Create WEB monitoring'); + $fields['check_connectivity'] = __('Create network monitoring'); + $fields['check_net'] = __('Discover my network'); + $fields['check_mail_alert'] = __('Create email alert'); + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_wizard_agent', + 'class' => 'flex space-between w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'task_to_perform', + 'selected' => '', + 'return' => true, + 'nothing' => \__('Please select one'), + 'nothing_value' => '', ], ], - ]; - } + [ + 'arguments' => [ + 'label' => __("Let's do it!"), + 'type' => 'button', + 'attributes' => [ + 'class' => 'secondary', + 'icon' => 'next', + ], + 'name' => 'go_wizard', + 'id' => 'go_wizard', + ], + ], + ], + ]; $output = $this->printForm( [ @@ -602,9 +627,235 @@ class WelcomeWindow extends Wizard true ); - $output .= $this->loadJS(); + $output .= $this->loadJS($flag_task); echo $output; + ?> + + + + + setHtml($response); + /* + //For debug url with parameters. + $navigation = $page->navigate($url.'?data='.urlencode(json_encode($data))); + $navigation->waitForNavigation(Page::DOM_CONTENT_LOADED); + */ // Dynamic. $dynamic_height = $page->evaluate('document.getElementById("container-chart-generator-item").clientHeight')->getReturnValue(); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 2c09fda820..940e9e3e7f 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2770,6 +2770,69 @@ function agents_delete_agent($id_agents, $disableACL=false) enterprise_include_once('include/functions_agents.php'); enterprise_hook('agent_delete_from_cache', [$id_agent]); + // Delete agent from visual console. + db_process_sql_delete( + 'tlayout_data', + ['id_agent' => $id_agent] + ); + + // Delete agent from visual dashboards. + db_process_sql( + 'UPDATE twidget_dashboard + SET options = NULL + WHERE options LIKE ("%\"agentid\":\"'.$id_agent.'\"%")' + ); + + // Delete agent from treport. + db_process_sql_delete( + 'treport_content', + ['id_agent' => $id_agent] + ); + + // Delete rules from tevent alerts (correlative alerts) + db_process_sql_delete( + 'tevent_rule', + [ + 'agent' => $id_agent, + 'operator_agent' => '==', + ] + ); + + db_process_sql_delete( + 'tevent_rule', + [ + 'log_agent' => $id_agent, + 'operator_log_agent' => '==', + ] + ); + + // Delete from gis maps history + db_process_sql_delete( + 'tgis_data_history', + ['tagente_id_agente' => $id_agent] + ); + + // Delete from policies. + db_process_sql_delete( + 'tpolicy_agents', + ['id_agent' => $id_agent] + ); + + // Delete from tnetwork maps + db_process_sql_delete( + 'titem', + ['source_data' => $id_agent] + ); + + db_process_sql_delete( + 'trel_item', + [ + 'id_parent_source_data' => $id_agent, + 'id_child_source_data' => $id_agent, + ], + 'OR' + ); + // Delete agent from fav menu. db_process_sql_delete( 'tfavmenu_user', diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index eec1ba849e..8d51a3b536 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -455,7 +455,7 @@ function alerts_delete_alert_action($id_alert_action) * * @return mixed Id of the cloned action or false in case of fail. */ -function alerts_clone_alert_action($id_alert_action, $id_group) +function alerts_clone_alert_action($id_alert_action, $id_group, $copy_name='') { $id_alert_action = safe_int($id_alert_action, 1); if (empty($id_alert_action)) { @@ -474,7 +474,13 @@ function alerts_clone_alert_action($id_alert_action, $id_group) unset($action['id']); - return alerts_create_alert_action($action['name'].' '.__('copy'), $action['id_alert_command'], $action); + if ($copy_name !== '') { + $copy_name = $copy_name; + } else { + $copy_name = $action['name'].' '.__('copy'); + } + + return alerts_create_alert_action($copy_name, $action['id_alert_command'], $action); } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 095b71f61b..16b0372f74 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1916,7 +1916,7 @@ function api_set_update_agent_field($id_agent, $use_agent_alias, $params) * * @param $thrash3 Don't use. */ -function api_set_new_agent($id_node, $thrash2, $other, $trhash3) +function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false) { global $config; @@ -2038,13 +2038,17 @@ function api_set_new_agent($id_node, $thrash2, $other, $trhash3) } } - returnData( - 'string', - [ - 'type' => 'string', - 'data' => $id_agente, - ] - ); + if ($return === false) { + returnData( + 'string', + [ + 'type' => 'string', + 'data' => $id_agente, + ] + ); + } else { + return $id_agente; + } } catch (\Exception $e) { returnError($e->getMessage()); return; diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 7a82254cf8..ea0f78b385 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -378,6 +378,10 @@ function config_update_config() $error_update[] = __('keep_in_process_status_extra_id'); } + if (config_update_value('show_experimental_features', get_parameter('show_experimental_features'), true) === false) { + $error_update[] = __('show_experimental_features'); + } + if (config_update_value('console_log_enabled', get_parameter('console_log_enabled'), true) === false) { $error_update[] = __('Console log enabled'); } @@ -627,6 +631,30 @@ function config_update_config() $error_update[] = __('Domain'); } + if (config_update_value('secondary_active_directory', get_parameter('secondary_active_directory'), true) === false) { + $error_update[] = __('Secondary active directory'); + } + + if (config_update_value('ad_server_secondary', get_parameter('ad_server_secondary'), true) === false) { + $error_update[] = __('Secondary active directory server'); + } + + if (config_update_value('ad_port_secondary', get_parameter('ad_port_secondary'), true) === false) { + $error_update[] = __('Secondary active directory port'); + } + + if (config_update_value('ad_start_tls_secondary', get_parameter('ad_start_tls_secondary'), true) === false) { + $error_update[] = __('Secondary start TLS'); + } + + if (config_update_value('ad_search_timeout', get_parameter('ad_search_timeout'), true) === false) { + $error_update[] = __('AD search timeout'); + } + + if (config_update_value('ad_domain_secondary', get_parameter('ad_domain_secondary'), true) === false) { + $error_update[] = __('Secondary domain'); + } + if (config_update_value('ad_adv_perms', get_parameter('ad_adv_perms'), true) === false) { $error_update[] = __('Advanced Permisions AD'); } @@ -946,12 +974,12 @@ function config_update_config() } } - if (config_update_value('delete_old_messages', get_parameter('delete_old_messages'), true) === false) { - $error_update[] = __('Max. days before delete old messages'); + if (config_update_value('delete_disabled_agents', get_parameter('delete_disabled_agents'), true) === false) { + $error_update[] = __('Max. days before disabled agents are deleted'); } - if (config_update_value('delete_old_network_matrix', get_parameter('delete_old_network_matrix'), true) === false) { - $error_update[] = __('Max. days before delete old network matrix data'); + if (config_update_value('delete_old_messages', get_parameter('delete_old_messages'), true) === false) { + $error_update[] = __('Max. days before delete old messages'); } if (config_update_value('max_graph_container', get_parameter('max_graph_container'), true) === false) { @@ -2207,12 +2235,12 @@ function config_process_config() } } - if (!isset($config['delete_old_messages'])) { - config_update_value('delete_old_messages', 21); + if (!isset($config['delete_disabled_agents'])) { + config_update_value('delete_disabled_agents', 0); } - if (!isset($config['delete_old_network_matrix'])) { - config_update_value('delete_old_network_matrix', 10); + if (!isset($config['delete_old_messages'])) { + config_update_value('delete_old_messages', 21); } if (!isset($config['max_graph_container'])) { @@ -2377,6 +2405,10 @@ function config_process_config() config_update_value('keep_in_process_status_extra_id', 0); } + if (!isset($config['show_experimental_features'])) { + config_update_value('show_experimental_features', 0); + } + if (!isset($config['console_log_enabled'])) { config_update_value('console_log_enabled', 0); } @@ -2478,10 +2510,6 @@ function config_process_config() 'max' => 90, 'min' => 0, ], - 'delete_old_network_matrix' => [ - 'max' => 30, - 'min' => 1, - ], 'report_limit' => [ 'max' => 500, 'min' => 1, @@ -3100,6 +3128,14 @@ function config_process_config() config_update_value('ad_port', 389); } + if (!isset($config['ad_server_secondary'])) { + config_update_value('ad_server_secondary', 'localhost'); + } + + if (!isset($config['ad_port_secondary'])) { + config_update_value('ad_port_secondary', 389); + } + if (!isset($config['ad_start_tls'])) { config_update_value('ad_start_tls', 0); } @@ -3439,10 +3475,6 @@ function config_process_config() config_update_value('dbtype', 'mysql'); } - if (!isset($config['legacy_vc'])) { - config_update_value('legacy_vc', 0); - } - if (!isset($config['vc_default_cache_expiration'])) { config_update_value('vc_default_cache_expiration', 60); } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 116deea959..c35e553235 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -4624,7 +4624,10 @@ function graph_netflow_circular_mesh($data) include_once $config['homedir'].'/include/graphs/functions_d3.php'; - return d3_relationship_graph($data['elements'], $data['matrix'], 900, true); + $width = (empty($data['width']) === false) ? $data['width'] : 900; + $height = (empty($data['height']) === false) ? $data['height'] : 900; + + return d3_relationship_graph($data['elements'], $data['matrix'], $width, true, $height); } @@ -4983,19 +4986,18 @@ function graph_monitor_wheel($width=550, $height=600, $filter=false) $filter_module_group = (!empty($filter) && !empty($filter['module_group'])) ? $filter['module_group'] : false; if ($filter['group'] != 0) { - $filter_subgroups = ''; - if (!$filter['dont_show_subgroups']) { - $filter_subgroups = ' || parent IN ('.$filter['group'].')'; + if ($filter['dont_show_subgroups'] === false) { + $groups = groups_get_children($filter['group']); + $groups_ax = []; + foreach ($groups as $g) { + $groups_ax[$g['id_grupo']] = $g; + } + + $groups = $groups_ax; + } else { + $groups = groups_get_group_by_id($filter['group']); + $groups[$group['id_grupo']] = $group; } - - $groups = db_get_all_rows_sql('SELECT * FROM tgrupo where id_grupo IN ('.$filter['group'].') '.$filter_subgroups); - - $groups_ax = []; - foreach ($groups as $g) { - $groups_ax[$g['id_grupo']] = $g; - } - - $groups = $groups_ax; } else { $groups = users_get_groups(false, 'AR', false, true, (!empty($filter) && isset($filter['group']) ? $filter['group'] : null)); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 68892247d9..c4e7c52c55 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -5516,7 +5516,10 @@ function html_print_input($data, $wrapper='div', $input_only=false) ($data['attributes'] ?? null), ((isset($data['return']) === true) ? $data['return'] : false), ((isset($data['password']) === true) ? $data['password'] : false), - ((isset($data['function']) === true) ? $data['function'] : '') + ((isset($data['function']) === true) ? $data['function'] : ''), + ((isset($data['autocomplete']) === true) ? $data['autocomplete'] : 'off'), + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['hide_div_eye']) === true) ? $data['hide_div_eye'] : false), ); break; @@ -7156,3 +7159,44 @@ function html_print_code_picker( echo $output; } } + + +function html_print_wizard_diagnosis( + $title, + $id_button, + $description='', + $status=true, + $return=false, +) { + $button = ''; + if ($status === true) { + $status = 'Connected'; + $img = '/images/configuration@svg.svg'; + } else { + $status = 'Disconnected'; + $img = '/images/change-active.svg'; + } + + $button = html_print_image( + $img, + true, + [ + 'class' => 'main_menu_icon invert_filter float-right mrgn_right_10px', + 'id' => $id_button, + ] + ); + + $output = '
+ '.__($status).$button.' +
'.html_print_image('/images/circle_title.svg', true, ['class' => 'invert_filter']).''.$title.'
+
+ '.$description.' +
+
'; + + if ($return === true) { + return $output; + } else { + echo $output; + } +} \ No newline at end of file diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 4878333071..143a538e20 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -324,6 +324,8 @@ function menu_print_menu(&$menu) if (isset($sub['subtype']) && $sub['subtype'] == 'nolink') { $submenu_output .= ''; + } else if (isset($sub['subtype']) && $sub['subtype'] == 'nolink_no_arrow') { + $submenu_output .= ''; } else if (isset($sub['subtype']) && $sub['subtype'] == 'new_blank') { $submenu_output .= '
'.$sub['text'].'
'; } else { @@ -351,7 +353,7 @@ function menu_print_menu(&$menu) $secExtensionBool = false; if ($secExtensionBool) { - if (strlen($sub['icon']) > 0) { + if (empty($sub['icon']) === false && strlen($sub['icon']) > 0) { $icon_enterprise = false; if (isset($sub['enterprise'])) { $icon_enterprise = (bool) $sub['enterprise']; @@ -378,7 +380,7 @@ function menu_print_menu(&$menu) $secExtension = $sub['sec']; } - if (strlen($secExtension) > 0) { + if (empty($secExtension) === false && strlen($secExtension) > 0) { $secUrl = $secExtension; $extensionInMenu = 'extension_in_menu='.$mainsec.'&'; } else { diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index b670088f85..a039fcbc07 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -743,7 +743,8 @@ function modules_create_agent_module( string $name, array $values=[], bool $disableACL=false, - $tags=false + $tags=false, + $use_agent_ip=false, ) { global $config; @@ -785,6 +786,10 @@ function modules_create_agent_module( return ERR_EXIST; } + if ($use_agent_ip === true) { + $values['ip_target'] = agents_get_address($id_agent); + } + // Encrypt passwords. if (isset($values['plugin_pass']) === true) { // Avoid two times encryption. diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 59d02ccb4f..79fcd9a0db 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -1233,7 +1233,9 @@ function netflow_draw_item( $max_aggregates, $connection_name='', $output='HTML', - $address_resolution=false + $address_resolution=false, + $width_content=false, + $height_content=false ) { $aggregate = $filter['aggregate']; $interval = ($end_date - $start_date); @@ -1432,6 +1434,9 @@ function netflow_draw_item( netflow_aggregate_is_ip($aggregate) ); + $data_circular['width'] = $width_content; + $data_circular['height'] = $height_content; + $html = '
'; $html .= graph_netflow_circular_mesh($data_circular); $html .= '
'; @@ -1734,7 +1739,12 @@ function netflow_get_top_summary( switch ($top_action) { case 'listeners': if (empty(!$filter)) { - $netflow_filter['ip_src'] = $filter; + if (!is_array($filter)) { + $netflow_filter['ip_src'] = $filter; + } else { + $netflow_filter['ip_src'] = $filter['ip']; + $netflow_filter['advanced_filter'] = $filter['advanced_filter']; + } } $sort = 'dstip'; @@ -1742,7 +1752,12 @@ function netflow_get_top_summary( case 'talkers': if (empty(!$filter)) { - $netflow_filter['ip_dst'] = $filter; + if (!is_array($filter)) { + $netflow_filter['ip_dst'] = $filter; + } else { + $netflow_filter['ip_dst'] = $filter['ip']; + $netflow_filter['advanced_filter'] = $filter['advanced_filter']; + } } $sort = 'srcip'; @@ -2069,7 +2084,7 @@ function netflow_aggregate_is_ip($aggregate) * * @return array With map structure. */ -function netflow_build_map_data($start_date, $end_date, $top, $aggregate) +function netflow_build_map_data($start_date, $end_date, $top, $aggregate, $advanced_filter='') { // Pass an empty filter data structure. $data = netflow_get_relationships_raw_data( @@ -2083,7 +2098,7 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate) 'ip_src' => '', 'dst_port' => '', 'src_port' => '', - 'advanced_filter' => '', + 'advanced_filter' => $advanced_filter, 'router_ip' => '', ], $top, diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index f42b791e8f..ebc2bb414d 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -1411,3 +1411,24 @@ function servers_get_master() return $result; } + + +/** + * Return true if all servers are up. + * + * @return boolean + */ +function check_all_servers_up() +{ + $status = true; + + $servers = servers_get_info(); + + foreach ($servers as $server) { + if ($server['status'] !== '1') { + return false; + } + } + + return $status; +} diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 745d61ef51..38ecabb0e0 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -1291,7 +1291,8 @@ function snmp_browser_create_modules_snmp( string $module_target, array $snmp_values, ?array $id_target, - ?string $server_to_exec=null + ?string $server_to_exec=null, + ?string $use_agent_ip='' ) { $target_ip = null; $target_port = null; @@ -1350,6 +1351,12 @@ function snmp_browser_create_modules_snmp( } } + if (empty($use_agent_ip) === false) { + $use_agent_ip = true; + } else { + $use_agent_ip = false; + } + $fail_modules = []; foreach ($targets_oids as $key => $target_oid) { @@ -1514,7 +1521,7 @@ function snmp_browser_create_modules_snmp( 'history_data' => 1, ]; foreach ($id_target as $agent) { - $ids[] = modules_create_agent_module($agent, $oid['oid'], $values); + $ids[] = modules_create_agent_module($agent, $oid['oid'], $values, false, false, $use_agent_ip); } } else if ($module_target == 'policy') { // Policies only in enterprise version. @@ -1803,6 +1810,16 @@ function snmp_browser_print_create_module_massive( true ); + $table->data[4][0] = html_print_label_input_block( + __('Use agent IP'), + html_print_checkbox( + 'use_agent_ip', + 1, + false, + true + ) + ); + $output .= html_print_table($table, true); // SNMP extradata. diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index a49beb0113..1050bde44e 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -88,8 +88,16 @@ function ui_bbcode_to_html($text, $allowed_tags=['[url]']) * * @return string Truncated text. */ -function ui_print_truncate_text($text, $numChars=GENERIC_SIZE_TEXT, $showTextInAToopTip=true, $return=true, $showTextInTitle=true, $suffix='…', $style=false) -{ +function ui_print_truncate_text( + $text, + $numChars=GENERIC_SIZE_TEXT, + $showTextInAToopTip=true, + $return=true, + $showTextInTitle=true, + $suffix='…', + $style=false, + $forced_title=false +) { global $config; if (is_string($numChars)) { @@ -190,6 +198,10 @@ function ui_print_truncate_text($text, $numChars=GENERIC_SIZE_TEXT, $showTextInA } } + if ($forced_title === true) { + $truncateText = ''.$div_content.''; + + if ($return === false) { + echo $output; + } + + return $output; +} + + /** * Get the shape of an image by assigning it a CSS class. Prints an image with CSS representing a status. * @@ -3716,28 +3754,71 @@ function ui_progress_extend( * Generate needed code to print a datatables jquery plugin. * * @param array $parameters All desired data using following format: - * [ - * 'print' => true (by default printed) - * 'id' => datatable id. - * 'class' => datatable class. - * 'style' => datatable style. - * 'order' => [ - * 'field' => column name - * 'direction' => asc or desc - * ], - * 'default_pagination' => integer, default pagination is set to block_size - * 'ajax_url' => 'include/ajax.php' ajax_url. - * 'ajax_data' => [ operation => 1 ] extra info to be sent. - * 'ajax_postprocess' => a javscript function to postprocess data received - * by ajax call. It is applied foreach row and must - * use following format: - * * [code] - * * function (item) { - * * // Process received item, for instance, name: - * * tmp = '' + item.name + ''; - * * item.name = tmp; - * * } - * * [/code] + * + * ```php + * $parameters = [ + * // JS Parameters + * 'serverside' => true, + * 'paging' => true, + * 'default_pagination' => $config['block_size'], + * 'searching' => false, + * 'dom_elements' => "plfrtiB", + * 'pagination_options' => [default_pagination, 5, 10, 20, 100, 200, 500, 1000, "All"], + * 'ordering' => true, + * 'order' => [[0, "asc"]], //['field' => 'column_name', 'direction' => 'asc/desc'] + * 'zeroRecords' => "No matching records found", + * 'emptyTable' => "No data available in table", + * 'no_sortable_columns' => [], //Allows the column name (db) from "columns" parameter + * 'csv_field_separator' => ",", + * 'csv_header' => true, + * 'mini_csv' => false, + * 'mini_pagination' => false, + * 'mini_search' => false, + * 'drawCallback' => undefined, //'console.log(123),' + * 'data_element' => undefined, //Rows processed + * 'ajax_postprocess' => undefined, //'process_datatables_item(item)' + * 'ajax_data' => undefined, //Extra data to be sent ['field1' => 1, 'field2 => 0] + * 'ajax_url' => undefined, + * 'caption' => undefined, + * + * // PHP Parameters + * 'id' => undefined, //Used for table and form id, + * 'columns' =>, + * 'column_names' =>, + * 'filter_main_class' =>, + * 'toggle_collapsed' =>true, + * 'search_button_class' => 'sub filter', + * 'csv' =>=1, + * 'form' => + * ..[ + * ....'id' => $form_id, + * ....'class' => 'flex-row', + * ....'style' => 'width: 100%,', + * ....'js' => '', + * ....'html' => $filter, + * ....'inputs' => [], + * ....'extra_buttons' => $buttons, + * ..], + * 'no_toggle' => false, + * 'form_html' => undefined, + * 'toggle_collapsed' => true, + * 'class' => "", //Datatable class. + * 'style' => "" ,//Datatable style. + * 'return' => false, + * 'print' => true, + * ] + * + * ``` + * + * ```php + * ajax_postprocess => a javscript function to postprocess data received + * by ajax call. It is applied foreach row and must + * use following format: + * function (item) { + * // Process received item, for instance, name: + * tmp = '' + item.name + ''; + * item.name = tmp; + * } * 'columns_names' => [ * 'column1' :: Used as th text. Direct text entry. It could be array: * OR @@ -3754,7 +3835,6 @@ function ui_progress_extend( * 'column2', * ... * ], - * 'no_sortable_columns' => [ indexes ] 1,2... -1 etc. Avoid sorting. * 'form' => [ * 'html' => 'html code' a directly defined inputs in HTML. * 'extra_buttons' => [ @@ -3786,12 +3866,7 @@ function ui_progress_extend( * ] * ], * 'extra_html' => HTML content to be placed after 'filter' section. - * 'drawCallback' => function to be called after draw. Sample in: - * https://datatables.net/examples/advanced_init/row_grouping.html - * ] - * 'zeroRecords' => Message when zero records obtained from filter.(Leave blank for default). - * 'emptyTable' => Message when table data empty.(Leave blank for default). - * End. + * ``` * * @return string HTML code with datatable. * @throws Exception On error. @@ -3808,6 +3883,9 @@ function ui_print_datatable(array $parameters) $form_id = uniqid('datatable_filter_'); } + $parameters['table_id'] = $table_id; + $parameters['form_id'] = $form_id; + if (!isset($parameters['columns']) || !is_array($parameters['columns'])) { throw new Exception('[ui_print_datatable]: You must define columns for datatable'); } @@ -3827,10 +3905,6 @@ function ui_print_datatable(array $parameters) $parameters['default_pagination'] = $config['block_size']; } - if (!isset($parameters['paging'])) { - $parameters['paging'] = true; - } - if (!isset($parameters['filter_main_class'])) { $parameters['filter_main_class'] = ''; } @@ -3839,13 +3913,9 @@ function ui_print_datatable(array $parameters) $parameters['toggle_collapsed'] = true; } - $no_sortable_columns = json_encode([]); - if (isset($parameters['no_sortable_columns'])) { - $no_sortable_columns = json_encode($parameters['no_sortable_columns']); - } - if (!is_array($parameters['order'])) { - $order = '0, "asc"'; + $order = 0; + $direction = 'asc'; } else { if (!isset($parameters['order']['direction'])) { $direction = 'asc'; @@ -3864,47 +3934,35 @@ function ui_print_datatable(array $parameters) } } - $order .= ', "'.$parameters['order']['direction'].'"'; + $direction = $parameters['order']['direction']; } - if (!isset($parameters['ajax_data'])) { - $parameters['ajax_data'] = ''; + $parameters['order']['order'] = $order; + $parameters['order']['direction'] = $direction; + + foreach ($parameters['no_sortable_columns'] as $key => $find) { + $found = array_search( + $parameters['no_sortable_columns'][$key], + $parameters['columns'] + ); + + if ($found !== false) { + unset($parameters['no_sortable_columns'][$key]); + array_push($parameters['no_sortable_columns'], $found); + } + + if (is_int($parameters['no_sortable_columns'][$key]) === false) { + unset($parameters['no_sortable_columns'][$key]); + } } - $search_button_class = 'sub filter'; + $parameters['csvTextInfo'] = __('Export current page to CSV'); + $parameters['csvFileTitle'] = sprintf(__('export_%s_current_page_%s'), $table_id, date('Y-m-d')); + if (isset($parameters['search_button_class'])) { $search_button_class = $parameters['search_button_class']; - } - - if (isset($parameters['pagination_options'])) { - $pagination_options = $parameters['pagination_options']; } else { - $pagination_options = [ - [ - // There is a limit of (2^32)^2 (18446744073709551615) rows in a MyISAM table, show for show all use max nrows. - // -1 Retun error or only 1 row. - $parameters['default_pagination'], - 5, - 10, - 25, - 100, - 200, - 500, - 1000, - 18446744073709551615, - ], - [ - $parameters['default_pagination'], - 5, - 10, - 25, - 100, - 200, - 500, - 1000, - 'All', - ], - ]; + $search_button_class = 'sub filter'; } if (isset($parameters['datacolumns']) === false @@ -3917,16 +3975,12 @@ function ui_print_datatable(array $parameters) $parameters['csv'] = 1; } - $dom_elements = '"plfrtiB"'; - if (isset($parameters['dom_elements'])) { - $dom_elements = '"'.$parameters['dom_elements'].'"'; - } - $filter = ''; // Datatable filter. if (isset($parameters['form']) && is_array($parameters['form'])) { if (isset($parameters['form']['id'])) { $form_id = $parameters['form']['id']; + $parameters['form_id'] = $form_id; } if (isset($parameters['form']['class'])) { @@ -4044,10 +4098,13 @@ function ui_print_datatable(array $parameters) ) ); $processing .= ''; + $parameters['processing'] = $processing; $zeroRecords = isset($parameters['zeroRecords']) === true ? $parameters['zeroRecords'] : __('No matching records found'); $emptyTable = isset($parameters['emptyTable']) === true ? $parameters['emptyTable'] : __('No data available in table'); + $parameters['zeroRecords'] = $zeroRecords; + $parameters['emptyTable'] = $emptyTable; // Extra html. $extra = ''; if (isset($parameters['extra_html']) && !empty($parameters['extra_html'])) { @@ -4056,8 +4113,8 @@ function ui_print_datatable(array $parameters) // Base table. $table = ''; + $table .= 'class="'.$parameters['class'].'"'; + $table .= 'style="box-sizing: border-box;'.$parameters['style'].'">'; $table .= ''; if (isset($parameters['column_names']) @@ -4084,335 +4141,60 @@ function ui_print_datatable(array $parameters) } $table .= ''; - - if (isset($parameters['data_element']) === true) { - $table .= ''; - foreach ($parameters['data_element'] as $row) { - $table .= ''; - foreach ($row as $td_data) { - $table .= ''; - } - - $table .= ''; - } - - $table .= ''; - - $js = ''; - } - $table .= '
'.$td_data.'
'; - $pagination_class = 'pandora_pagination'; - if (!empty($parameters['pagination_class'])) { - $pagination_class = $parameters['pagination_class']; + $parameters['ajax_url_full'] = ui_get_full_url('ajax.php', false, false, false); + + $parameters['spinnerLoading'] = html_print_image( + 'images/spinner.gif', + true, + [ + 'id' => $form_id.'_loading', + 'class' => 'loading-search-datatables-button', + ] + ); + + $language = substr(get_user_language(), 0, 2); + if (is_metaconsole() === false) { + $parameters['language'] = 'include/javascript/i18n/dataTables.'.$language.'.json'; + } else { + $parameters['language'] = '../../include/javascript/i18n/dataTables.'.$language.'.json'; } - $columns = ''; - for ($i = 1; $i <= (count($parameters['columns']) - 3); $i++) { - if ($i != (count($parameters['columns']) - 3)) { - $columns .= $i.','; - } else { - $columns .= $i; - } + $parameters['phpDate'] = date('Y-m-d'); + $parameters['dataElements'] = json_encode($parameters['data_element']); + + // * START JAVASCRIPT. + if (is_metaconsole() === false) { + $file_path = ui_get_full_url('include/javascript/datatablesFunction.js'); + } else { + $file_path = ui_get_full_url('../../include/javascript/datatablesFunction.js'); } - $export_columns = ''; - if (isset($parameters['csv_exclude_latest']) === true - && $parameters['csv_exclude_latest'] === true - ) { - $export_columns = ',columns: \'th:not(:last-child)\''; - } + $file_content = file_get_contents($file_path); + $json_data = json_encode($parameters); + $json_config = json_encode($config); - if (isset($parameters['data_element']) === false || isset($parameters['print_pagination_search_csv'])) { - if (isset($parameters['ajax_url'])) { - $type_data = 'ajax: { - url: "'.ui_get_full_url('ajax.php', false, false, false).'", - type: "POST", - dataSrc: function (json) { - if($("#'.$form_id.'_search_bt") != undefined) { - $("#'.$form_id.'_loading").remove(); - } + $js = ''; - if (json.error) { - console.error(json.error); - $("#error-'.$table_id.'").html(json.error); - $("#error-'.$table_id.'").dialog({ - title: "Filter failed", - width: 630, - resizable: true, - draggable: true, - modal: false, - closeOnEscape: true, - buttons: { - "Ok" : function () { - $(this).dialog("close"); - } - } - }).parent().addClass("ui-state-error"); - } else {'; - - if (isset($parameters['ajax_return_operation']) === true - && empty($parameters['ajax_return_operation']) === false - && isset($parameters['ajax_return_operation_function']) === true - && empty($parameters['ajax_return_operation_function']) === false - ) { - $type_data .= ' - if (json.'.$parameters['ajax_return_operation'].' !== undefined) { - '.$parameters['ajax_return_operation_function'].'(json.'.$parameters['ajax_return_operation'].'); - } - '; - } - - if (isset($parameters['ajax_postprocess'])) { - $type_data .= ' - if (json.data) { - json.data.forEach(function(item) { - '.$parameters['ajax_postprocess'].' - }); - } else { - json.data = {}; - }'; - } - - $type_data .= ' - return json.data; - } - }, - data: function (data) { - if($("#button-'.$form_id.'_search_bt") != undefined) { - var loading = \''.html_print_image( - 'images/spinner.gif', - true, - [ - 'id' => $form_id.'_loading', - 'class' => 'loading-search-datatables-button', - ] - ).'\'; - $("#button-'.$form_id.'_search_bt").parent().append(loading); - } - - inputs = $("#'.$form_id.' :input"); - - values = {}; - inputs.each(function() { - values[this.name] = $(this).val(); - }) - - $.extend(data, { - filter: values,'."\n"; - - if (is_array($parameters['ajax_data'])) { - foreach ($parameters['ajax_data'] as $k => $v) { - $type_data .= $k.':'.json_encode($v).",\n"; - } - } - - $type_data .= 'page: "'.$parameters['ajax_url'].'" - }); - - return data; - } - },'; - } else { - $type_data = 'data: '.json_encode($parameters['data_element']).','; - } - - $serverside = 'true'; - if (isset($parameters['data_element'])) { - $serverside = 'false'; - } - - // Javascript controller. - $js = ''; - } - - // Order. + $js .= ''; + // * END JAVASCRIPT. $info_msg_arr = []; $info_msg_arr['message'] = $emptyTable; $info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-msg-info-'.$table_id; - $spinner = '
'; + $spinner = '
'; $info_msg = '
'.ui_print_info_message($info_msg_arr).'
'; + $err_msg = '
'; $output = $info_msg.$err_msg.$filter.$extra.$spinner.$table.$js; if (is_ajax() === false) { @@ -4436,7 +4218,7 @@ function ui_print_datatable(array $parameters) false, false ); - $output .= '?v='.$config['current_package'].'"/>'; + $output .= '"/>'; // Load tables.css. $output .= ''; + } else { + $output .= '
    '; + } + + foreach ($tree['__LEAVES__'] as $level => $sub_level) { + // Id used to expand leafs. + $sub_id = time().rand(0, getrandmax()); + // Display the branch. + $output .= '
  • '; + + // Indent sub branches. + for ($i = 1; $i <= $depth; $i++) { + if ($last_array[$i] == 1) { + $output .= ''; + } else { + $output .= ''; + } + } + + // Branch. + if (! empty($sub_level['sublevel']['__LEAVES__'])) { + $output .= ""; + if ($depth == 0 && $count == 0) { + if ($count == $total) { + $output .= ''; + } else { + $output .= ''; + } + } else if ($count == $total) { + $output .= ''; + } else { + $output .= ''; + } + + $output .= ''; + } + + // Leave. + else { + if ($depth == 0 && $count == 0) { + if ($count == $total) { + $output .= ''; + } else { + $output .= ''; + } + } else if ($count == $total) { + $output .= ''; + } else { + $output .= ''; + } + } + + $checkbox_name_sufix = ($sufix === true) ? '_'.$level : ''; + if ($descriptive_ids === true) { + $checkbox_name = 'create_'.$sub_id.$previous_id.$checkbox_name_sufix; + } else { + $checkbox_name = 'create_'.$sub_id.$checkbox_name_sufix; + } + + $previous_id = $checkbox_name_sufix; + if ($sub_level['selectable'] === true) { + $output .= html_print_checkbox( + $sub_level['name'], + $sub_level['value'], + $sub_level['checked'], + true, + false, + '', + true + ); + } + + $output .= ' '.$sub_level['label'].''; + + $output .= '
  • '; + + // Recursively print sub levels. + $output .= ui_print_tree( + $sub_level['sublevel'], + $sub_id, + ($depth + 1), + (($count == $total) ? 1 : 0), + $last_array, + $sufix, + $descriptive_ids, + $previous_id + ); + + $count++; + } + + $output .= '
'; + + return $output; +} + + function ui_update_name_fav_element($id_element, $section, $label) { $label = io_safe_output($label); diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index f99484df1f..0170da7f07 100755 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -1274,52 +1274,50 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) ); $form_items_advance['element_group_row']['html'] .= ''; - if (!$config['legacy_vc']) { - $intervals = [ - 10 => '10 '.__('seconds'), - 30 => '30 '.__('seconds'), - 60 => '1 '.__('minutes'), - 300 => '5 '.__('minutes'), - 900 => '15 '.__('minutes'), - 1800 => '30 '.__('minutes'), - 3600 => '1 '.__('hour'), - ]; + $intervals = [ + 10 => '10 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '1 '.__('minutes'), + 300 => '5 '.__('minutes'), + 900 => '15 '.__('minutes'), + 1800 => '30 '.__('minutes'), + 3600 => '1 '.__('hour'), + ]; - $form_items_advance['cache_expiration_row'] = []; - $form_items_advance['cache_expiration_row']['items'] = [ - 'static_graph', - 'percentile_bar', - 'percentile_item', - 'module_graph', - 'simple_value', - 'datos', - 'auto_sla_graph', - 'group_item', - 'bars_graph', - 'donut_graph', - 'color_cloud', - 'service', - ]; - $form_items_advance['cache_expiration_row']['html'] = ''; - $form_items_advance['cache_expiration_row']['html'] .= __('Cache expiration'); - $form_items_advance['cache_expiration_row']['html'] .= ''; - $form_items_advance['cache_expiration_row']['html'] .= ''; - $form_items_advance['cache_expiration_row']['html'] .= html_print_extended_select_for_time( - 'cache_expiration', - $config['vc_default_cache_expiration'], - '', - __('No cache'), - 0, - false, - true, - false, - true, - '', - false, - $intervals - ); - $form_items_advance['cache_expiration_row']['html'] .= ''; - } + $form_items_advance['cache_expiration_row'] = []; + $form_items_advance['cache_expiration_row']['items'] = [ + 'static_graph', + 'percentile_bar', + 'percentile_item', + 'module_graph', + 'simple_value', + 'datos', + 'auto_sla_graph', + 'group_item', + 'bars_graph', + 'donut_graph', + 'color_cloud', + 'service', + ]; + $form_items_advance['cache_expiration_row']['html'] = ''; + $form_items_advance['cache_expiration_row']['html'] .= __('Cache expiration'); + $form_items_advance['cache_expiration_row']['html'] .= ''; + $form_items_advance['cache_expiration_row']['html'] .= ''; + $form_items_advance['cache_expiration_row']['html'] .= html_print_extended_select_for_time( + 'cache_expiration', + $config['vc_default_cache_expiration'], + '', + __('No cache'), + 0, + false, + true, + false, + true, + '', + false, + $intervals + ); + $form_items_advance['cache_expiration_row']['html'] .= ''; // Insert and modify before the buttons to create or update. if (enterprise_installed()) { @@ -1454,12 +1452,9 @@ function visual_map_editor_print_toolbox() visual_map_print_button_editor('box_item', __('Box'), 'left', false, 'box_item', true); visual_map_print_button_editor('line_item', __('Line'), 'left', false, 'line_item', true); visual_map_print_button_editor('color_cloud', __('Color cloud'), 'left', false, 'color_cloud_min', true); - if (isset($config['legacy_vc']) === false - || (bool) $config['legacy_vc'] === false - ) { - // Applies only on modern VC. - visual_map_print_button_editor('network_link', __('Network link'), 'left', false, 'network_link_min', true); - } + + // Applies only on modern VC. + visual_map_print_button_editor('network_link', __('Network link'), 'left', false, 'network_link_min', true); if (defined('METACONSOLE')) { echo ' '30', + 'descripcion' => '', + 'max' => '0', + 'min' => '0', + 'snmp_oid' => '', + 'snmp_community' => 'public', + 'id_module_group' => $id_group, + 'module_interval' => '300', + 'module_ff_interval' => '0', + 'ip_target' => '', + 'tcp_port' => '0', + 'tcp_rcv' => '', + 'tcp_send' => '', + 'id_export' => '0', + 'plugin_user' => '', + 'plugin_pass' => '0', + 'plugin_parameter' => 'task_begin +get '.$url_search.' +resource 1 +'.$str_search.' +task_end', + 'id_plugin' => '0', + 'post_process' => '0', + 'prediction_module' => '0', + 'max_timeout' => '0', + 'max_retries' => '0', + 'disabled' => '', + 'id_modulo' => '7', + 'custom_id' => '', + 'history_data' => '1', + 'dynamic_interval' => '0', + 'dynamic_max' => '0', + 'dynamic_min' => '0', + 'dynamic_two_tailed' => '0', + 'parent_module_id' => '0', + 'min_warning' => '0', + 'max_warning' => '0', + 'str_warning' => '', + 'min_critical' => '0', + 'max_critical' => '0', + 'str_critical' => '', + 'custom_string_1' => '', + 'custom_string_2' => '', + 'custom_string_3' => '', + 'custom_integer_1' => '0', + 'custom_integer_2' => '0', + 'min_ff_event' => '0', + 'min_ff_event_normal' => '0', + 'min_ff_event_warning' => '0', + 'min_ff_event_critical' => '0', + 'ff_type' => '0', + 'each_ff' => '0', + 'ff_timeout' => '0', + 'unit' => '', + 'macros' => '', + 'quiet' => '0', + 'cps' => '0', + 'critical_instructions' => '', + 'warning_instructions' => '', + 'unknown_instructions' => '', + 'critical_inverse' => '0', + 'warning_inverse' => '0', + 'percentage_critical' => '0', + 'percentage_warning' => '0', + 'cron_interval' => '* * * * *', + 'id_category' => '0', + 'disabled_types_event' => '{\"going_unknown\":0}', + 'module_macros' => 'W10=', + 'warning_time' => '0', + ]; + return modules_create_agent_module($id_agent, $module_name.'_latency', $array_values); +} + + +/** + * Create_module_status_goliat and return module id. + * + * @param mixed $id_agent Id agent. + * @param mixed $module_name Module name. + * @param mixed $id_group Id group. + * @param mixed $url_search Url to search. + * @param mixed $string_search Text to search. + * + * @return interger Module id. + */ +function create_module_status_goliat($id_agent, $module_name, $id_group, $url_search, $string_search='') +{ + if ($string_search !== '') { + $str_search = 'check_string '.$string_search.' '; + } + + include_once 'include/functions_modules.php'; + + $array_values = [ + 'id_tipo_modulo' => '31', + 'descripcion' => '', + 'max' => '0', + 'min' => '0', + 'snmp_oid' => '', + 'snmp_community' => 'public', + 'id_module_group' => $id_group, + 'module_interval' => '300', + 'module_ff_interval' => '0', + 'ip_target' => '', + 'tcp_port' => '0', + 'tcp_rcv' => '', + 'tcp_send' => '', + 'id_export' => '0', + 'plugin_user' => '', + 'plugin_pass' => '0', + 'plugin_parameter' => 'task_begin +get '.$url_search.' +resource 1 +'.$str_search.' +task_end', + 'id_plugin' => '0', + 'post_process' => '0', + 'prediction_module' => '0', + 'max_timeout' => '0', + 'max_retries' => '0', + 'disabled' => '', + 'id_modulo' => '7', + 'custom_id' => '', + 'history_data' => '1', + 'dynamic_interval' => '0', + 'dynamic_max' => '0', + 'dynamic_min' => '0', + 'dynamic_two_tailed' => '0', + 'parent_module_id' => '0', + 'min_warning' => '0', + 'max_warning' => '0', + 'str_warning' => '', + 'min_critical' => '0', + 'max_critical' => '0', + 'str_critical' => '', + 'custom_string_1' => '', + 'custom_string_2' => '', + 'custom_string_3' => '', + 'custom_integer_1' => '0', + 'custom_integer_2' => '0', + 'min_ff_event' => '0', + 'min_ff_event_normal' => '0', + 'min_ff_event_warning' => '0', + 'min_ff_event_critical' => '0', + 'ff_type' => '0', + 'each_ff' => '0', + 'ff_timeout' => '0', + 'unit' => '', + 'macros' => '', + 'quiet' => '0', + 'cps' => '0', + 'critical_instructions' => '', + 'warning_instructions' => '', + 'unknown_instructions' => '', + 'critical_inverse' => '0', + 'warning_inverse' => '0', + 'percentage_critical' => '0', + 'percentage_warning' => '0', + 'cron_interval' => '* * * * *', + 'id_category' => '0', + 'disabled_types_event' => '{\"going_unknown\":0}', + 'module_macros' => 'W10=', + 'warning_time' => '0', + ]; + return modules_create_agent_module($id_agent, $module_name.'_status', $array_values); +} + + +/** + * Create module basic network and return module id. + * + * @param mixed $id_agent Id agent. + * @param mixed $id_group Id group. + * @param mixed $ip_target Ip target. + * + * @return interger Module id. + */ +function create_module_basic_network($id_agent, $id_group, $ip_target) +{ + include_once 'include/functions_modules.php'; + + $array_values = [ + 'id_tipo_modulo' => '6', + 'descripcion' => 'Basic network check (ping)', + 'max' => '0', + 'min' => '0', + 'snmp_oid' => '', + 'snmp_community' => 'public', + 'id_module_group' => $id_group, + 'module_interval' => '300', + 'module_ff_interval' => '0', + 'ip_target' => $ip_target, + 'tcp_port' => '0', + 'tcp_rcv' => '', + 'tcp_send' => '', + 'id_export' => '0', + 'plugin_user' => '', + 'plugin_pass' => '0', + 'plugin_parameter' => '', + 'id_plugin' => '0', + 'post_process' => '0', + 'prediction_module' => '0', + 'max_timeout' => '0', + 'max_retries' => '0', + 'disabled' => '', + 'id_modulo' => '2', + 'custom_id' => '', + 'history_data' => '1', + 'dynamic_interval' => '0', + 'dynamic_max' => '0', + 'dynamic_min' => '0', + 'dynamic_two_tailed' => '0', + 'parent_module_id' => '0', + 'min_warning' => '0', + 'max_warning' => '0', + 'str_warning' => '', + 'min_critical' => '0', + 'max_critical' => '0', + 'str_critical' => '', + 'custom_string_1' => '', + 'custom_string_2' => '', + 'custom_string_3' => '', + 'custom_integer_1' => '0', + 'custom_integer_2' => '0', + 'min_ff_event' => '0', + 'min_ff_event_normal' => '0', + 'min_ff_event_warning' => '0', + 'min_ff_event_critical' => '0', + 'ff_type' => '0', + 'each_ff' => '0', + 'ff_timeout' => '0', + 'unit' => '', + 'macros' => '', + 'quiet' => '0', + 'cps' => '0', + 'critical_instructions' => '', + 'warning_instructions' => '', + 'unknown_instructions' => '', + 'critical_inverse' => '0', + 'warning_inverse' => '0', + 'percentage_critical' => '0', + 'percentage_warning' => '0', + 'cron_interval' => '* * * * *', + 'id_category' => '0', + 'disabled_types_event' => '{\"going_unknown\":0}', + 'module_macros' => 'W10=', + 'warning_time' => '0', + ]; + return modules_create_agent_module($id_agent, 'Basic_Network_Check', $array_values); +} + + +/** + * Create module latency network and return module id. + * + * @param mixed $id_agent Id agent. + * @param mixed $id_group Id group. + * @param mixed $ip_target Ip target. + * + * @return interger Module id. + */ +function create_module_latency_network($id_agent, $id_group, $ip_target) +{ + include_once 'include/functions_modules.php'; + + $array_values = [ + 'id_tipo_modulo' => '7', + 'descripcion' => 'Basic network connectivity check to measure network latency in miliseconds', + 'max' => '0', + 'min' => '0', + 'snmp_oid' => '', + 'snmp_community' => 'public', + 'id_module_group' => $id_group, + 'module_interval' => '300', + 'module_ff_interval' => '0', + 'ip_target' => $ip_target, + 'tcp_port' => '0', + 'tcp_rcv' => '', + 'tcp_send' => '', + 'id_export' => '0', + 'plugin_user' => '', + 'plugin_pass' => '0', + 'plugin_parameter' => '', + 'id_plugin' => '0', + 'post_process' => '0', + 'prediction_module' => '0', + 'max_timeout' => '0', + 'max_retries' => '0', + 'disabled' => '', + 'id_modulo' => '2', + 'custom_id' => '', + 'history_data' => '1', + 'dynamic_interval' => '0', + 'dynamic_max' => '0', + 'dynamic_min' => '0', + 'dynamic_two_tailed' => '1', + 'parent_module_id' => '0', + 'min_warning' => '0', + 'max_warning' => '0', + 'str_warning' => '', + 'min_critical' => '0', + 'max_critical' => '0', + 'str_critical' => '', + 'custom_string_1' => '', + 'custom_string_2' => '', + 'custom_string_3' => '', + 'custom_integer_1' => '0', + 'custom_integer_2' => '0', + 'min_ff_event' => '0', + 'min_ff_event_normal' => '0', + 'min_ff_event_warning' => '0', + 'min_ff_event_critical' => '0', + 'ff_type' => '0', + 'each_ff' => '0', + 'ff_timeout' => '0', + 'unit' => '', + 'macros' => '', + 'quiet' => '0', + 'cps' => '0', + 'critical_instructions' => '', + 'warning_instructions' => '', + 'unknown_instructions' => '', + 'critical_inverse' => '0', + 'warning_inverse' => '0', + 'percentage_critical' => '0', + 'percentage_warning' => '0', + 'cron_interval' => '* * * * *', + 'id_category' => '0', + 'disabled_types_event' => '{\"going_unknown\":0}', + 'module_macros' => 'W10=', + 'warning_time' => '0', + ]; + return modules_create_agent_module($id_agent, 'Basic_Network_Latency', $array_values); +} + + +/** + * Create module packet lost and return module id. + * + * @param mixed $id_agent Id agent. + * @param mixed $id_group Id group. + * @param mixed $ip_target Ip target. + * + * @return interger Module id. + */ +function create_module_packet_lost($id_agent, $id_group, $ip_target) +{ + include_once 'include/functions_modules.php'; + + $array_values = [ + 'id_tipo_modulo' => '1', + 'descripcion' => 'Basic network connectivity check to measure packet loss in %', + 'max' => '0', + 'min' => '0', + 'snmp_oid' => '', + 'snmp_community' => 'public', + 'id_module_group' => $id_group, + 'module_interval' => '300', + 'module_ff_interval' => '0', + 'ip_target' => '', + 'tcp_port' => '0', + 'tcp_rcv' => '', + 'tcp_send' => '', + 'id_export' => '0', + 'plugin_user' => '', + 'plugin_pass' => '0', + 'plugin_parameter' => '', + 'id_plugin' => '9', + 'post_process' => '0', + 'prediction_module' => '0', + 'max_timeout' => '0', + 'max_retries' => '0', + 'disabled' => '', + 'id_modulo' => '4', + 'custom_id' => '', + 'history_data' => '1', + 'dynamic_interval' => '0', + 'dynamic_max' => '0', + 'dynamic_min' => '0', + 'dynamic_two_tailed' => '1', + 'parent_module_id' => '0', + 'min_warning' => '0', + 'max_warning' => '0', + 'str_warning' => '', + 'min_critical' => '0', + 'max_critical' => '0', + 'str_critical' => '', + 'custom_string_1' => '', + 'custom_string_2' => '', + 'custom_string_3' => '', + 'custom_integer_1' => '0', + 'custom_integer_2' => '0', + 'min_ff_event' => '0', + 'min_ff_event_normal' => '0', + 'min_ff_event_warning' => '0', + 'min_ff_event_critical' => '0', + 'ff_type' => '0', + 'each_ff' => '0', + 'ff_timeout' => '0', + 'unit' => '', + 'macros' => '{"1":{"macro":"_field1_","desc":"Test time","help":"","value":"8","hide":""},"2":{"macro":"_field2_","desc":"Target IP","help":"","value":"'.$ip_target.'","hide":""}}', + 'quiet' => '0', + 'cps' => '0', + 'critical_instructions' => '', + 'warning_instructions' => '', + 'unknown_instructions' => '', + 'critical_inverse' => '0', + 'warning_inverse' => '0', + 'percentage_critical' => '0', + 'percentage_warning' => '0', + 'cron_interval' => '* * * * *', + 'id_category' => '0', + 'disabled_types_event' => '{\"going_unknown\":0}', + 'module_macros' => 'W10=', + 'warning_time' => '0', + ]; + return modules_create_agent_module($id_agent, 'Basic_Network_Packetloss', $array_values); +} + + +/** + * Create module packet lost and return module id. + * + * @param string $ip_target Ip and red mask. + * + * @return interger Module id. + */ +function create_net_scan($ip_target) +{ + global $config; + include_once $config['homedir'].'/godmode/wizards/HostDevices.class.php'; + $HostDevices = new HostDevices(1); + $id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server']; + + $_POST = [ + 'page' => '1', + 'interval_manual_defined' => '1', + 'interval_select' => '-1', + 'interval_text' => '0', + 'interval' => '0', + 'interval_units' => '1', + 'taskname' => __('Basic network'), + 'id_recon_server' => $id_recon_server, + 'network' => $ip_target, + 'id_group' => '8', + 'comment' => __('Created on welcome'), + ]; + $task_created = $HostDevices->parseNetScan(); + if ($task_created === true) { + $HostDevicesFinal = new HostDevices(2); + $_POST = [ + 'task' => $HostDevices->task['id_rt'], + 'page' => '2', + 'recon_ports' => '', + 'auto_monitor' => 'on', + 'id_network_profile' => ['0' => '2'], + 'review_results' => 'on', + 'review_limited' => '0', + 'snmp_enabled' => 'on', + 'snmp_version' => '1', + 'snmp_skip_non_enabled_ifs' => 'on', + 'community' => '', + 'snmp_context' => '', + 'snmp_auth_user' => '', + 'snmp_security_level' => 'authNoPriv', + 'snmp_auth_method' => 'MD5', + 'snmp_auth_pass' => '', + 'snmp_privacy_method' => 'AES', + 'snmp_privacy_pass' => '', + 'os_detect' => 'on', + 'resolve_names' => 'on', + 'parent_detection' => 'on', + 'parent_recursion' => 'on', + 'vlan_enabled' => 'on', + ]; + + $task_final_created = $HostDevicesFinal->parseNetScan(); + if ($task_final_created === true) { + $net_scan_id = $HostDevices->task['id_rt']; + unset($HostDevices, $HostDevicesFinal); + return $net_scan_id; + } + } else { + return 0; + } +} + + +/** + * Create new template unknown. + * + * @return boolean 1 correct create 0 bad create. + */ +function create_template_alert_unknown() +{ + $name = io_safe_input(__('Unknown condition')); + $type = 'critical'; + $values = [ + 'description' => __('This is a generic alert template to fire on UNKNOWN condition'), + 'max_value' => 0, + 'min_value' => 0, + 'id_group' => 0, + 'priority' => 4, + 'wizard_level' => 'nowizard', + 'time_threshold' => '300', + 'min_alerts_reset_counter' => 1, + 'schedule' => '{"monday":[{"start":"00:00:00","end":"00:00:00"}],"tuesday":[{"start":"00:00:00","end":"00:00:00"}],"wednesday":[{"start":"00:00:00","end":"00:00:00"}],"thursday":[{"start":"00:00:00","end":"00:00:00"}],"friday":[{"start":"00:00:00","end":"00:00:00"}],"saturday":[{"start":"00:00:00","end":"00:00:00"}],"sunday":[{"start":"00:00:00","end":"00:00:00"}]}', + 'recovery_notify' => true, + 'field2' => '[PANDORA] Alert for UNKNOWN status on _agent_ / _module_', + 'field2_recovery' => '[PANDORA] Alert RECOVERED for UNKNOWN status on _agent_ / _module_', + 'field3' => '', + 'field3_recovery' => '

Automatic alert system


We have good news for you, alert has been recovered

Monitoring details

Data: _data_ (normal)

Agent: _agent_ _address_

Module: _module_ _moduledescription_

Timestamp: _timestamp_

This is a graph of latest 24hr data for this module

_modulegraph_24h_

Contact Us  |  Support  |  Docs

', + ]; + + $result = alerts_create_alert_template($name, $type, $values); + return $result; +} diff --git a/pandora_console/include/graphs/functions_d3.php b/pandora_console/include/graphs/functions_d3.php index 4e3206840b..498602a1d1 100644 --- a/pandora_console/include/graphs/functions_d3.php +++ b/pandora_console/include/graphs/functions_d3.php @@ -57,7 +57,7 @@ function include_javascript_d3($return=false) } -function d3_relationship_graph($elements, $matrix, $width=700, $return=false) +function d3_relationship_graph($elements, $matrix, $width=700, $return=false, $height=700) { global $config; @@ -72,7 +72,7 @@ function d3_relationship_graph($elements, $matrix, $width=700, $return=false) $output = '
'; $output .= include_javascript_d3(true); $output .= ""; if (!$return) { @@ -150,7 +150,7 @@ function d3_tree_map_graph($data, $width=700, $height=700, $return=false) } -function d3_sunburst_graph($data, $width=700, $height=700, $return=false, $tooltip=true) +function d3_sunburst_graph($data, $width=700, $height=700, $return=false, $tooltip=true, $id_container=false) { global $config; @@ -158,6 +158,8 @@ function d3_sunburst_graph($data, $width=700, $height=700, $return=false, $toolt $data = json_encode($data); } + $id_container = ($id_container === false) ? '#sunburst' : $id_container; + $output = "
"; $output .= include_javascript_d3(true); $output .= ''; $output .= ""; if (!$return) { diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index bce475ad4f..6b64cae989 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -259,7 +259,7 @@ function flot_area_graph( $return .= html_print_input_hidden( 'line_width_graph', - $config['custom_graph_width'], + (empty($params['line_width']) === true) ? $config['custom_graph_width'] : $params['line_width'], true ); $return .= "
a, a => b, a => c] // [5, 0, 1], // b[b => a, b => b, b => c] // [2, 3, 0]]; // c[c => a, c => b, c => c] -function chordDiagram(recipient, elements, matrix, width) { +function chordDiagram(recipient, elements, matrix, width, height) { d3.chart = d3.chart || {}; d3.chart.chordWheel = function(options) { // Default values @@ -59,10 +59,13 @@ function chordDiagram(recipient, elements, matrix, width) { .enter() .append("svg:svg") .attr("width", width) - .attr("height", width) + .attr("height", height) .attr("class", "dependencyWheel") .append("g") - .attr("transform", "translate(" + width / 2 + "," + width / 2 + ")"); + .attr( + "transform", + "translate(" + width / 2 + "," + height / 2 + ") scale(1.2)" + ); var arc = d3.svg .arc() @@ -206,8 +209,8 @@ function chordDiagram(recipient, elements, matrix, width) { .on("mousemove", move_tooltip); function move_tooltip(d) { - x = d3.event.pageX + 10; - y = d3.event.pageY + 10; + x = d3.event.layerX + 10; + y = d3.event.layerY + 10; $("#tooltip").css("left", x + "px"); $("#tooltip").css("top", y + "px"); diff --git a/pandora_console/include/javascript/datatablesFunction.js b/pandora_console/include/javascript/datatablesFunction.js new file mode 100644 index 0000000000..41f0bbf1e2 --- /dev/null +++ b/pandora_console/include/javascript/datatablesFunction.js @@ -0,0 +1,378 @@ +var dt = dt; +var config = config; + +var datacolumns = []; +var datacolumnsTemp = []; +dt.datacolumns.forEach(column => { + if (column === null) return; + if (typeof column !== "string") { + datacolumnsTemp = { data: column.text, className: column.class }; + datacolumns.push(datacolumnsTemp); + } else { + datacolumnsTemp = { data: column, className: "no-class" }; + datacolumns.push(datacolumnsTemp); + } +}); + +var paginationClass = "pandora_pagination"; +if (typeof dt.pagination_class !== "undefined") { + paginationClass = dt.pagination_class; +} + +var processing = ""; +if (typeof dt.processing === "undefined") { + processing = dt.processing; +} + +var ajaxReturn = ""; +var ajaxReturnFunction = ""; +if ( + typeof dt.ajax_return_operation !== "undefined" && + dt.ajax_return_operation !== "" && + typeof dt.ajax_return_operation_function !== "undefined" && + dt.ajax_return_operation_function !== "" +) { + ajaxReturn = dt.ajax_return_operation; + ajaxReturnFunction = dt.ajax_return_operation_function; +} + +var serverSide = true; +if (typeof dt.data_element !== "undefined") { + serverSide = false; +} + +var paging = true; +if (typeof dt.paging !== "undefined") { + paging = dt.paging; +} + +var pageLength = parseInt(dt.default_pagination); + +var searching = false; +if (typeof dt.searching !== "undefined" && dt.searching === true) { + searching = dt.searching; +} + +var dom = "plfrtiB"; +if (typeof dt.dom_elements !== "undefined") { + dom = dt.dom_elements; +} + +var lengthMenu = [ + [pageLength, 5, 10, 20, 100, 200, 500, 1000, -1], + [pageLength, 5, 10, 20, 100, 200, 500, 1000, "All"] +]; +if (typeof dt.pagination_options !== "undefined") { + lengthMenu = dt.pagination_options; +} + +var ordering = true; +if (typeof dt.ordering !== "undefined" && dt.ordering === false) { + ordering = dt.ordering; +} + +var order = [[0, "asc"]]; +if (typeof dt.order !== "undefined") { + order = [[dt.order.order, dt.order.direction]]; +} + +var zeroRecords = ""; +if (typeof dt.zeroRecords !== "undefined") { + zeroRecords = `${dt.zeroRecords}`; +} + +var emptyTable = ""; +if (typeof dt.emptyTable !== "undefined") { + emptyTable = `${dt.emptyTable}`; +} + +var no_sortable_columns = []; +if (typeof dt.no_sortable_columns !== "undefined") { + no_sortable_columns = Object.values(dt.no_sortable_columns); +} + +var columnDefs = []; +if (typeof dt.columnDefs === "undefined") { + columnDefs = [ + { className: "no-class", targets: "_all" }, + { bSortable: false, targets: no_sortable_columns } + ]; +} else { + columnDefs = dt.columnDefs; +} + +var csvClassName = "csv-button"; +if (dt.mini_csv === true) { + csvClassName = "mini-csv-button"; +} + +var csvFieldSeparator = ";"; +if (typeof dt.csv_field_separator !== "undefined") { + csvFieldSeparator = dt.csv_field_separator; +} + +var csvHeader = true; +if (dt.csv_header === false) { + csvHeader = false; +} + +var csvExcludeLast = ""; +if (dt.csv_exclude_latest === true) { + csvExcludeLast = "th:not(:last-child)"; +} + +var ajaxData = ""; +if (typeof dt.ajax_data !== "undefined") { + ajaxData = dt.ajax_data; +} + +$(document).ready(function() { + function checkPages() { + if (dt_table.page.info().pages > 1) { + $( + "div.pagination-child-div > .dataTables_paginate.paging_simple_numbers" + ).show(); + $(`#${dt.id}_paginate`).show(); + } else { + $( + "div.pagination-child-div > .dataTables_paginate.paging_simple_numbers" + ).hide(); + $(`#${dt.id}_paginate`).hide(); + } + } + + function moveElementsToActionButtons() { + $(".action_buttons_right_content").html( + '
' + ); + $(".pagination-child-div").append( + $(`#${dt.id}_wrapper > .dataTables_paginate.paging_simple_numbers`).attr( + "style", + "margin-right: 10px;" + ) + ); + $(".pagination-child-div").append( + $(`#${dt.id}_wrapper > .dataTables_length`) + ); + $(".pagination-child-div").append($(`#${dt.id}_wrapper > .dt-buttons`)); + $(".pagination-child-div").append( + $(`#${dt.id}_wrapper > .dataTables_filter`) + ); + } + + $.fn.dataTable.ext.errMode = "none"; + $.fn.dataTable.ext.classes.sPageButton = paginationClass; + + if (dt.mini_pagination === true) { + $.fn.dataTable.ext.classes.sPageButton = `${paginationClass} mini-pandora-pagination`; + } + + var settings_datatable = { + processing: true, + responsive: true, + serverSide, + paging, + pageLength, + searching, + dom, + lengthMenu, + ordering, + order, + columns: eval(datacolumns), + columnDefs, + language: { + url: dt.language, + processing, + zeroRecords, + emptyTable + }, + buttons: + dt.csv == 1 + ? [ + { + extend: "csv", + className: csvClassName, + text: dt.csvTextInfo, + titleAttr: dt.csvTextInfo, + title: dt.csvFileTitle, + fieldSeparator: csvFieldSeparator, + header: csvHeader, + action: function(e, dt, node, config) { + blockResubmit(node); + // Call the default csvHtml5 action method to create the CSV file + $.fn.dataTable.ext.buttons.csvHtml5.action.call( + this, + e, + dt, + node, + config + ); + }, + exportOptions: { + modifier: { + // DataTables core + order: "current", + page: "All", + search: "applied" + }, + columns: csvExcludeLast + } + } + ] + : [], + initComplete: function(settings, json) { + moveElementsToActionButtons(); + + checkPages(); + + $(`div#${dt.id}-spinner`).hide(); + }, + drawCallback: function(settings) { + if ($(`#${dt.id} tr td`).length == 1) { + $(`.datatable-msg-info-${dt.id}`) + .removeClass("invisible_important") + .show(); + $(`table#${dt.id}`).hide(); + $("div.pagination-child-div").hide(); + $("div.dataTables_info").hide(); + $(`#${dt.id}_wrapper`).hide(); + $(`.action_buttons_right_content .pagination-child-div`).hide(); + } else { + $(`.datatable-msg-info-${dt.id}`).hide(); + $(`table#${dt.id}`).show(); + $("div.pagination-child-div").show(); + $("div.dataTables_info").show(); + $(`#${dt.id}_wrapper`).show(); + + if (typeof dt.drawCallback !== "undefined") { + eval(dt.drawCallback); + } + } + + $(`div#${dt.id}-spinner`).hide(); + + checkPages(); + } + }; + + var ajaxOrData = {}; + if (typeof dt.data_element == "undefined") { + ajaxOrData = { + ajax: { + url: dt.ajax_url_full, + type: "POST", + dataSrc: function(json) { + if ($(`#${dt.form_id}_search_bt`) != undefined) { + $(`#${dt.form_id}_loading`).remove(); + } + + if (json.error) { + console.error(json.error); + $(`#error-${dt.id}`).html(json.error); + $(`#error-${dt.id}`) + .dialog({ + title: "Filter failed", + width: 630, + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + buttons: { + Ok: function() { + $(this).dialog("close"); + } + } + }) + .parent() + .addClass("ui-state-error"); + } else { + if (json.ajaxReturn !== "undefined") { + eval(`${ajaxReturnFunction}(${json.ajaxReturn})`); + } + + if (typeof dt.ajax_postprocess !== "undefined") { + if (json.data) { + json.data.forEach(function(item) { + eval(dt.ajax_postprocess); + }); + } else { + json.data = {}; + } + } + + return json.data; + } + }, + data: function(data) { + $(`div#${dt.id}-spinner`).show(); + if ($(`#button-${dt.form_id}_search_bt`) != undefined) { + var loading = ``; + $(`#button-${dt.form_id}_search_bt`) + .parent() + .append(loading); + } + + var inputs = $(`#${dt.form_id} :input`); + + var values = {}; + inputs.each(function() { + values[this.name] = $(this).val(); + }); + + $.extend(data, ajaxData); + + $.extend(data, { + filter: values, + page: dt.ajax_url + }); + + return data; + } + } + }; + } else { + ajaxOrData = { data: dt.data_element }; + } + + $.extend(settings_datatable, ajaxOrData); + var dt_table = $(`#${dt.table_id}`).DataTable(settings_datatable); + + $(`#button-${dt.form_id}_search_bt`).click(function() { + dt_table.draw().page(0); + }); + + if (typeof dt.caption !== "undefined" && dt.caption !== "") { + $(`#${dt.table_id}`).append(`${dt.caption}`); + $(".datatables_thead_tr").css("height", 0); + } + + $(function() { + $(document).on("init.dt", function(ev, settings) { + if (dt.mini_search === true) { + $(`#${dt.id}_filter > label > input`).addClass("mini-search-input"); + } + + $("div.dataTables_length").show(); + $("div.dataTables_filter").show(); + $("div.dt-buttons").show(); + + if (dt_table.page.info().pages === 0) { + $(`.action_buttons_right_content .pagination-child-div`).hide(); + } + + if (dt_table.page.info().pages === 1) { + $(`div.pagination-child-div > #${dt.table_id}_paginate`).hide(); + } else { + $(`div.pagination-child-div > #${dt.table_id}_paginate`).show(); + } + }); + }); +}); + +$(function() { + $(document).on("preInit.dt", function(ev, settings) { + $(`#${dt.id}_wrapper div.dataTables_length`).hide(); + $(`#${dt.id}_wrapper div.dataTables_filter`).hide(); + $(`#${dt.id}_wrapper div.dt-buttons`).hide(); + }); +}); diff --git a/pandora_console/include/javascript/extensions_discovery.js b/pandora_console/include/javascript/extensions_discovery.js new file mode 100644 index 0000000000..a2cb6c85d0 --- /dev/null +++ b/pandora_console/include/javascript/extensions_discovery.js @@ -0,0 +1,25 @@ +/* global $, interval */ +$(document).ready(() => { + if (interval === "0") { + setTimeout(() => { + $("#mode_interval") + .parent() + .find("[id^='interval']") + .hide(); + }, 100); + } +}); + +function changeModeInterval(e) { + if ($(e).val() === "manual") { + $(e) + .parent() + .find("[id^='interval']") + .hide(); + } else { + var interval = $(e) + .parent() + .find("div[id^='interval']")[0]; + $(interval).show(); + } +} diff --git a/pandora_console/include/javascript/i18n/dataTables.en.json b/pandora_console/include/javascript/i18n/dataTables.en.json index 9ccd76c4ad..d80bbe6e75 100644 --- a/pandora_console/include/javascript/i18n/dataTables.en.json +++ b/pandora_console/include/javascript/i18n/dataTables.en.json @@ -6,7 +6,6 @@ "infoThousands": ",", "lengthMenu": "Show _MENU_ entries", "loadingRecords": "Loading...", - "processing": "Processing...", "search": "Search:", "zeroRecords": "No matching records found", "thousands": ",", diff --git a/pandora_console/include/javascript/manage_extensions.js b/pandora_console/include/javascript/manage_extensions.js new file mode 100644 index 0000000000..e5c98c6a58 --- /dev/null +++ b/pandora_console/include/javascript/manage_extensions.js @@ -0,0 +1,72 @@ +/* globals $, page, url, textsToTranslate, confirmDialog*/ +$(document).ready(function() { + function loading(status) { + if (status) { + $(".spinner-fixed").show(); + $("#button-upload_button").attr("disabled", "true"); + } else { + $(".spinner-fixed").hide(); + $("#button-upload_button").removeAttr("disabled"); + } + } + + $("#uploadExtension").submit(function(e) { + e.preventDefault(); + var formData = new FormData(this); + formData.append("page", page); + formData.append("method", "validateIniName"); + loading(true); + $.ajax({ + method: "POST", + url: url, + data: formData, + processData: false, + contentType: false, + success: function(data) { + loading(false); + data = JSON.parse(data); + if (data.success) { + if (data.warning) { + confirmDialog({ + title: textsToTranslate["Warning"], + message: data.message, + strOKButton: textsToTranslate["Confirm"], + strCancelButton: textsToTranslate["Cancel"], + onAccept: function() { + loading(true); + $("#uploadExtension")[0].submit(); + }, + onDeny: function() { + return false; + } + }); + } else { + $("#uploadExtension")[0].submit(); + } + } else { + confirmDialog({ + title: textsToTranslate["Error"], + message: data.message, + ok: textsToTranslate["Ok"], + hideCancelButton: true, + onAccept: function() { + return false; + } + }); + } + }, + error: function() { + loading(false); + confirmDialog({ + title: textsToTranslate["Error"], + message: textsToTranslate["Failed to upload extension"], + ok: textsToTranslate["Ok"], + hideCancelButton: true, + onAccept: function() { + return false; + } + }); + } + }); + }); +}); diff --git a/pandora_console/include/javascript/timezone/src/date.js b/pandora_console/include/javascript/timezone/src/date.js index 63b3a4e94a..0016caadf1 100644 --- a/pandora_console/include/javascript/timezone/src/date.js +++ b/pandora_console/include/javascript/timezone/src/date.js @@ -893,6 +893,17 @@ var utcMillis = typeof dt === "number" ? dt : new Date(dt).getTime(); var t = tz; var zoneList = _this.zones[t]; + + if (typeof zoneList === "undefined") { + zoneList = [ + [-53.46666666666666, "-", "LMT", -2422051200000], + [-60, "C-Eur", "CE%sT", -776556000000], + [-60, "SovietZone", "CE%sT", -725932800000], + [-60, "Germany", "CE%sT", 347068800000], + [-60, "EU", "CE%sT", null] + ]; + } + // Follow links to get to an actual zone while (typeof zoneList === "string") { t = zoneList; diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 245c9f0481..14712eee27 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -416,6 +416,10 @@ class Widget $className .= '\OsQuickReportWidget'; break; + case 'netflow': + $className .= '\Netflow'; + break; + case 'GroupedMeterGraphs': case 'ColorModuleTabs': case 'BlockHistogram': @@ -424,6 +428,7 @@ class Widget case 'ModulesByStatus': case 'AvgSumMaxMinModule': case 'BasicChart': + case 'AgentHive': $className .= '\\'.$name; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/AgentHive.php b/pandora_console/include/lib/Dashboard/Widgets/AgentHive.php new file mode 100644 index 0000000000..3b881ca344 --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/AgentHive.php @@ -0,0 +1,519 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Cell Id. + $this->cellId = $cellId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Agent hive'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'AgentHive'; + } + + // This forces at least a first configuration. + $this->configurationRequired = false; + if (empty($this->values['groups']) === true) { + $this->configurationRequired = true; + } + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + if (isset($decoder['groups']) === true) { + $values['groups'] = $decoder['groups']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + // Filters. + $inputs[] = [ + 'label' => __('Groups'), + 'id' => 'li_groups', + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groups[]', + 'returnAllGroup' => false, + 'privilege' => 'AR', + 'selected' => explode(',', $values['groups'][0]), + 'return' => true, + 'multiple' => true, + 'required' => true, + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost(): array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['groups'] = \get_parameter('groups', 0); + + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + $groups = $this->values['groups']; + $groups = explode(',', $groups[0]); + + $user_groups = array_keys( + users_get_groups( + false, + 'AR', + false, + false, + $groups + ) + ); + + foreach ($groups as $key => $group) { + if (in_array($group, $user_groups) === false) { + unset($groups[$key]); + } + } + + $table = 'tagente'; + if (is_metaconsole()) { + $table = 'tmetaconsole_agent'; + } + + $sql = sprintf( + 'SELECT * FROM %s WHERE id_grupo IN('.implode(',', $groups).')', + $table + ); + $all_agents = db_get_all_rows_sql($sql); + + $output = ''; + $output .= '
'; + foreach ($all_agents as $agent) { + $output .= $this->drawSquare($agent); + } + + $output .= '
'; + + $output .= ''; + + return $output; + } + + + /** + * Draw square agent. + * + * @param array $data Info agent. + * + * @return string Output. + */ + private function drawSquare(array $data): string + { + global $config; + + $id = (is_metaconsole() === true) + ? $data['id_tagente'] + : $data['id_agente']; + + $status = agents_get_status_from_counts($data); + switch ($status) { + case 1: + case 4: + case 100: + // Critical (BAD or ALERT). + $color = '#e63c52'; + break; + + case 0: + case 300: + // Normal (OK). + $color = '#82b92e'; + break; + + case 2: + case 200: + // Warning. + $color = '#f3b200'; + break; + + case 5: + // Not init. + $color = '#4a83f3'; + break; + + default: + // Default is Grey (Other). + $color = '#b2b2b2'; + break; + } + + $style_contact = 'flex-grow: 9; font-size: 8pt; display: flex; + justify-content: start;align-items: start; color: #9FA5B1; font-weight: 600;'; + // Last contact. + $lastContactDate = ui_print_timestamp( + $data['ultimo_contacto'], + true, + ['style' => $style_contact] + ); + + // Url. + $console_url = ui_get_full_url('/'); + if (is_metaconsole()) { + $server = metaconsole_get_servers($data['id_tmetaconsole_setup']); + $console_url = $server['server_url'].'/'; + } + + $url_view = $console_url.'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id; + $url_manage = $console_url.'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente='.$id; + + $output = '
'; + $output .= ''; + $output .= '
'; + $output .= '
'; + // Last contact and img. + $output .= ''; + + // OS and alias. + $output .= '
'; + $icon = (string) db_get_value( + 'icon_name', + 'tconfig_os', + 'id_os', + (int) $data['id_os'] + ); + $output .= '
'; + $output .= file_get_contents( + ui_get_full_url('images/'.$icon, false, false, false) + ); + $output .= '
'; + $output .= ui_print_truncate_text( + ucfirst(io_safe_output($data['alias'])), + 12, + false, + true, + true, + '…', + 'font-size: 11pt;color: #14524f;white-space: nowrap; + font-weight: 600;text-align: left;width: 80%; + overflow: hidden;', + ); + + $output .= '
'; + + // OS description. + $output .= html_print_div( + [ + 'content' => (empty($data['os_version']) === true) + ? get_os_name((int) $data['id_os']) + : $data['os_version'], + 'style' => 'font-size: 6pt; display: + flex;justify-content: start;align-items: start; + color: #9FA5B1; font-weight: 600;margin-bottom: 5px', + ], + true + ); + + // Description. + $output .= html_print_div( + [ + 'content' => ui_print_truncate_text( + io_safe_output($data['comentarios']), + 38, + false, + true, + true, + '…', + ), + 'style' => 'text-align: left;min-height: 42px; + font-size: 8pt;max-height: 42px; margin-bottom: 10px', + ], + true + ); + + // IP. + $output .= html_print_div( + [ + 'content' => $data['direccion'], + 'style' => 'font-size: 10pt;color: #14524f; + font-weight: 600; text-align: left', + ], + true + ); + $output .= '
'; + $output .= '
'; + + return $output; + + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Agents hive'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'AgentHive'; + } + + + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => (is_metaconsole() === true) ? 700 : 600, + 'height' => 610, + ]; + + return $size; + } + + +} diff --git a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php index ff5d22a539..85665e7e4c 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php @@ -297,6 +297,14 @@ class BasicChart extends Widget $values['label'] = $decoder['label']; } + if (isset($decoder['type_graph']) === true) { + $values['type_graph'] = $decoder['type_graph']; + } + + if (isset($decoder['line_width']) === true) { + $values['line_width'] = $decoder['line_width']; + } + return $values; } @@ -477,6 +485,22 @@ class BasicChart extends Widget ], ]; + $types_graph = [ + 'area' => __('Area'), + 'line' => __('Wire'), + ]; + + $inputs['inputs']['row1'][] = [ + 'label' => __('Type graph'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $types_graph, + 'name' => 'type_graph', + 'selected' => $values['type_graph'], + 'return' => true, + ], + ]; + $inputs['inputs']['row2'][] = [ 'label' => __('Show Value'), 'arguments' => [ @@ -520,6 +544,18 @@ class BasicChart extends Widget ], ]; + $inputs['inputs']['row2'][] = [ + 'label' => __('Graph line size'), + 'arguments' => [ + 'name' => 'line_width', + 'type' => 'number', + 'value' => (empty($values['line_width']) === true) ? 3 : $values['line_width'], + 'return' => true, + 'min' => 2, + 'max' => 10, + ], + ]; + return $inputs; } @@ -546,6 +582,8 @@ class BasicChart extends Widget $values['colorChart'] = \get_parameter('colorChart'); $values['formatData'] = \get_parameter_switch('formatData'); $values['label'] = \get_parameter('label'); + $values['type_graph'] = \get_parameter('type_graph'); + $values['line_width'] = \get_parameter('line_width'); return $values; } @@ -606,6 +644,8 @@ class BasicChart extends Widget 'title' => $module_name, 'unit' => $units_name, 'only_image' => false, + 'type_graph' => $this->values['type_graph'], + 'line_width' => (empty($this->values['line_width']) === true) ? 3 : $this->values['line_width'], 'menu' => false, 'vconsole' => true, 'return_img_base_64' => false, diff --git a/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php b/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php index b00c3ae421..10ddd2bc9c 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php +++ b/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php @@ -520,7 +520,7 @@ class DataMatrix extends Widget [ 'id' => $tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'include/ajax/module', diff --git a/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php b/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php index 86a50eefef..351d78ffec 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php +++ b/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php @@ -438,7 +438,7 @@ class ModulesByStatus extends Widget [ 'id' => $tableId, 'class' => 'info_table align-left-important', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'include/ajax/module', diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_icon.php b/pandora_console/include/lib/Dashboard/Widgets/module_icon.php index 24d1c7e207..e5c68eab11 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_icon.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_icon.php @@ -540,12 +540,6 @@ class ModuleIconWidget extends Widget $output = ''; - $id_group = \agents_get_agent_group($this->values['agentId']); - - $modulesAgent = \modules_get_agentmodule_agent( - $this->values['moduleId'] - ); - $data_module = \modules_get_last_value( $this->values['moduleId'] ); @@ -574,33 +568,37 @@ class ModuleIconWidget extends Widget // General div. $output .= '
'; - $sql = 'SELECT min_warning, - max_warning, - min_critical, - max_critical, - str_warning, - str_critical - FROM tagente_modulo - WHERE id_agente_modulo = '.(int) $this->values['moduleId']; - $sql_data = db_get_row_sql($sql); + $status = \modules_get_agentmodule_status($this->values['moduleId']); - $last = modules_get_last_value($this->values['moduleId']); + switch ($status) { + case 1: + case 4: + // Critical or critical alert (BAD). + $color_icon .= '_bad.png'; + break; - $color_icon = '_ok'; - if (($last >= $sql_data['min_warning']) && ($last < $sql_data['max_warning'])) { - $color_icon = '_warning'; + case 0: + // Normal (OK). + $color_icon .= '_ok.png'; + break; + + case 2: + case 10: + // Warning or warning alert. + $color_icon .= '_warning.png'; + break; + + case 3: + // Unknown. + default: + $color_icon .= '.png'; + // Default is Grey (Other). + break; } - if ($last >= $sql_data['max_warning']) { - $color_icon = '_bad'; - } - - // Div image. - $style_icon = 'flex: 0 1 '.$sizeIcon.'px;'; - - $output .= '
'; + $output .= '
'; $output .= html_print_image( - 'images/console/icons/'.$icon.$color_icon.'.png', + 'images/console/icons/'.$icon.$color_icon, true, ['width' => $sizeIcon] ); diff --git a/pandora_console/include/lib/Dashboard/Widgets/netflow.php b/pandora_console/include/lib/Dashboard/Widgets/netflow.php new file mode 100644 index 0000000000..be603e452b --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/netflow.php @@ -0,0 +1,465 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Options. + $this->values = $this->getOptionsWidget(); + + // Positions. + $this->position = $this->getPositionWidget(); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Netflow'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'netflow'; + } + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + // Default values. + if (isset($values['quantity']) === false) { + $values['quantity'] = 5; + } + + // Default values. + if (isset($values['period']) === false) { + $values['period'] = SECONDS_1WEEK; + } + + // Default values. + if (isset($values['max_values']) === false) { + $values['max_values'] = 10; + } + + // Period. + $inputs[] = [ + 'label' => __('Interval'), + 'arguments' => [ + 'name' => 'period', + 'type' => 'interval', + 'value' => $values['period'], + 'nothing' => __('None'), + 'nothing_value' => 0, + 'style_icon' => 'flex-grow: 0', + ], + ]; + $chart_types = netflow_get_chart_types(); + $chart_types['usage_map'] = __('Usage map'); + $inputs[] = [ + 'label' => __('Type graph'), + 'arguments' => [ + 'name' => 'chart_type', + 'type' => 'select', + 'fields' => $chart_types, + 'selected' => $values['chart_type'], + ], + ]; + + $aggregate_list = [ + 'srcip' => __('Src Ip Address'), + 'dstip' => __('Dst Ip Address'), + 'srcport' => __('Src Port'), + 'dstport' => __('Dst Port'), + ]; + $inputs[] = [ + 'label' => __('Aggregated by'), + 'id' => 'aggregated', + 'arguments' => [ + 'name' => 'aggregate', + 'type' => 'select', + 'fields' => $aggregate_list, + 'selected' => $values['aggregate'], + ], + ]; + + $inputs[] = [ + 'label' => __('Data to show'), + 'id' => 'data_to_show', + 'arguments' => [ + 'name' => 'action', + 'type' => 'select', + 'fields' => network_get_report_actions(), + 'selected' => $values['action'], + ], + ]; + + $max_values = [ + '2' => '2', + '5' => '5', + '10' => '10', + '15' => '15', + '20' => '20', + '25' => '25', + '50' => '50', + ]; + + $inputs[] = [ + 'label' => __('Max values'), + 'arguments' => [ + 'name' => 'max_values', + 'type' => 'select', + 'fields' => $max_values, + 'selected' => $values['max_values'], + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost():array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['period'] = \get_parameter('period', 0); + $values['chart_type'] = \get_parameter('chart_type', ''); + $values['aggregate'] = \get_parameter('aggregate'); + $values['max_values'] = \get_parameter('max_values', 10); + $values['action'] = \get_parameter('action', 'srcip'); + + return $values; + } + + + /** + * Draw widget. + * + * @return string + */ + public function load() + { + ui_require_css_file('netflow_widget', 'include/styles/', true); + global $config; + + $output = ''; + + $size = parent::getSize(); + + $start_date = (time() - $this->values['period']); + $end_date = time(); + if ($this->values['chart_type'] === 'usage_map') { + $map_data = netflow_build_map_data( + $start_date, + $end_date, + $this->values['max_values'], + ($this->values['action'] === 'talkers') ? 'srcip' : 'dstip' + ); + $has_data = !empty($map_data['nodes']); + + if ($has_data === true) { + $map_manager = new \NetworkMap($map_data); + $map_manager->printMap(); + } else { + ui_print_info_message(__('No data to show')); + } + } else { + $netflowContainerClass = ($this->values['chart_type'] === 'netflow_data' || $this->values['chart_type'] === 'netflow_summary' || $this->values['chart_type'] === 'netflow_top_N') ? '' : 'white_box'; + $filter = [ + 'aggregate' => $this->values['aggregate'], + 'netflow_monitoring_interval' => 300, + ]; + + $output .= html_print_input_hidden( + 'selected_style_theme', + $config['style'], + true + ); + $style = 'width:100%; height: 100%; border: none;'; + if ($this->values['chart_type'] !== 'netflow_area') { + $style .= ' width: 95%;'; + } + + if ($size['width'] > $size['height']) { + $size['width'] = $size['height']; + } + + // Draw the netflow chart. + $output .= html_print_div( + [ + 'class' => $netflowContainerClass, + 'style' => $style, + 'content' => netflow_draw_item( + $start_date, + $end_date, + 12, + $this->values['chart_type'], + $filter, + $this->values['max_values'], + '', + 'HTML', + 0, + ($size['width'] - 50), + ($size['height'] - 20), + ), + ], + true + ); + } + + return $output; + + } + + + /** + * Return aux javascript code for forms. + * + * @return string + */ + public function getFormJS() + { + return ' + $(document).ready(function(){ + //Limit 1 week + $("#period_select option").each(function(key, element){ + if(element.value > 604800){ + $(element).remove(); + } + }) + $("#period_manual option").each(function(key, element){ + if(element.value > 604800){ + $(element).remove(); + } + }); + $("#period_manual input").on("change", function(e){ + if($("#hidden-period").val() > 604800) { + $(this).val(1); + $("#hidden-period").val(604800); + $("#period_manual select option").removeAttr("selected"); + setTimeout(() => { + $("#period_default select option[value=\'604800\']").attr("selected", "selected"); + $("#period_manual select option[value=\'604800\']").attr("selected", "selected"); + $("#period_manual select").val(604800); + }, 500); + } + }); + if($("#chart_type").val() === "usage_map") { + $("#data_to_show").show(); + $("#aggregated").hide(); + } else { + $("#data_to_show").hide(); + $("#aggregated").show(); + } + $("#chart_type").on("change", function(e){ + if(this.value === "usage_map") { + $("#data_to_show").show(); + $("#aggregated").hide(); + } else { + $("#data_to_show").hide(); + $("#aggregated").show(); + } + }); + }); + '; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Netflow'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'netflow'; + } + + + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 530, + ]; + + return $size; + } + + +} diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_map.php b/pandora_console/include/lib/Dashboard/Widgets/service_map.php index 1957cf1c0a..5353ed79a9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_map.php @@ -433,7 +433,14 @@ class ServiceMapWidget extends Widget ); } else { include_once $config['homedir'].'/include/graphs/functions_d3.php'; - servicemap_print_sunburst($this->values['serviceId'], $size['width'], $size['height'], false); + $id_container = '#container_servicemap_'.$this->values['serviceId'].'_'.$this->cellId.' #sunburst'; + servicemap_print_sunburst( + $this->values['serviceId'], + $size['width'], + $size['height'], + false, + $id_container + ); } $output .= ob_get_clean(); diff --git a/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php b/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php index 7d00c43715..b026ffcd9e 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php @@ -395,7 +395,9 @@ class SystemGroupStatusWidget extends Widget $user_groups = users_get_groups(false, 'AR', $return_all_group); $selected_groups = explode(',', $this->values['groupId'][0]); + $all_group_selected = false; if (in_array(0, $selected_groups) === true) { + $all_group_selected = true; $selected_groups = []; foreach (groups_get_all() as $key => $name_group) { $selected_groups[] = groups_get_id($name_group); @@ -480,7 +482,12 @@ class SystemGroupStatusWidget extends Widget } } - $this->values['groupId'] = $selected_groups; + if ($all_group_selected === true && $this->values['groupRecursion'] === true) { + $this->values['groupId'] = array_keys($result_groups); + } else { + $this->values['groupId'] = $selected_groups; + } + $this->values['status'] = explode(',', $this->values['status'][0]); $style = 'font-size: 1.5em; font-weight: bolder;text-align: center;'; diff --git a/pandora_console/include/streams.php b/pandora_console/include/streams.php index 9097750bf7..72f62ecce8 100644 --- a/pandora_console/include/streams.php +++ b/pandora_console/include/streams.php @@ -59,6 +59,7 @@ class StreamReader { class StringReader { var $_pos; var $_str; + var $is_overloaded; function __construct($str='') { $this->_str = $str; diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index 908f673997..285e8fa481 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -654,6 +654,59 @@ form.modal-dashboard font-style: italic; } +.widget-agent-hive-square { + flex: 1; + display: flex; + flex-direction: row; + justify-content: center; + align-items: start; + min-width: 150px; + max-width: 150px; + min-height: 150px; + max-height: 150px; + margin: 8px; + padding: 5px; + border: 1px solid #eceef2; + border-radius: 5px; + cursor: pointer; +} + +.widget-agent-hive-square-status { + width: 3%; + height: 100%; + margin-left: 3%; + border-radius: 15px; +} + +.widget-agent-hive-square-info { + width: 87%; + height: 100%; + display: flex; + flex-direction: column; + margin-left: 6%; +} + +.widget-agent-hive-square-info-header { + width: 100%; + display: flex; + flex-direction: row; + margin-bottom: 10px; +} + +.widget-agent-hive-square-info-body { + width: 100%; + display: flex; + flex-direction: row; +} + +.span-alias { + font-size: 13pt; + justify-content: start; + align-items: start; + color: #14524f; + font-weight: 600; +} + .container-histograms { min-width: 400px; } diff --git a/pandora_console/include/styles/diagnostics.css b/pandora_console/include/styles/diagnostics.css index 706038cbd0..579a8777eb 100644 --- a/pandora_console/include/styles/diagnostics.css +++ b/pandora_console/include/styles/diagnostics.css @@ -8,7 +8,7 @@ text-align: center; font-size: 1.5em; font-weight: bolder; - color: #000; + color: var(--text-color); background: var(--secondary-color); padding: 8px; } @@ -47,16 +47,36 @@ font-size: 1.2em; } +.title-self-monitoring { + border-top: 1px solid var(--border-color); + border-right: 1px solid var(--border-color); + border-left: 1px solid var(--border-color); + border-top-left-radius: 8px; + border-top-right-radius: 8px; +} + .container-self-monitoring { display: flex; flex-direction: row; flex-wrap: wrap; + background-color: var(--secondary-color); + border-right: 1px solid var(--border-color); + border-bottom: 1px solid var(--border-color); + border-left: 1px solid var(--border-color); + border-bottom-left-radius: 8px; + border-bottom-right-radius: 8px; + padding-bottom: 15px; } .element-self-monitoring { flex: 2 1 600px; } +.element-self-monitoring > img[data-title="No data"] { + margin-top: 5%; + margin-left: 20%; +} + .footer-self-monitoring { margin: 30px; font-style: italic; diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 4bb7b200c6..2e6967f19a 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -4,14 +4,13 @@ ul.bigbuttonlist { min-height: 200px; + display: flex; + flex-wrap: wrap; } li.discovery { - display: inline-block; - float: left; width: 250px; margin: 15px; - padding-bottom: 50px; } li.discovery > a { @@ -37,8 +36,7 @@ div.data_container { width: 100%; height: 100%; text-align: center; - padding-top: 30px; - padding-bottom: 30px; + padding: 6px; } div.data_container:hover { diff --git a/pandora_console/include/styles/form.css b/pandora_console/include/styles/form.css index fd7e496aac..a0e5957358 100644 --- a/pandora_console/include/styles/form.css +++ b/pandora_console/include/styles/form.css @@ -365,3 +365,7 @@ form#modal_form_feedback > ul > li > textarea { form#modal_form_feedback > ul > li:not(:first-child) > label { margin-top: 20px !important; } + +table.dataTable { + box-sizing: border-box !important; +} diff --git a/pandora_console/include/styles/login.css b/pandora_console/include/styles/login.css index 4314296d15..30d29c584c 100644 --- a/pandora_console/include/styles/login.css +++ b/pandora_console/include/styles/login.css @@ -351,6 +351,7 @@ span.span1 { font-family: "lato-bolder"; color: #fff; margin-right: 30px; + text-shadow: 2px 2px #000; } span.span2 { @@ -361,6 +362,7 @@ span.span2 { font-family: "lato-bolder"; color: #fff; margin-right: 30px; + text-shadow: 2px 2px #000; } div.img_banner_login img { diff --git a/pandora_console/include/styles/netflow_widget.css b/pandora_console/include/styles/netflow_widget.css new file mode 100644 index 0000000000..c7be7fe90d --- /dev/null +++ b/pandora_console/include/styles/netflow_widget.css @@ -0,0 +1,13 @@ +.menu_graph { + display: none; +} +.parent_graph { + width: 97% !important; +} +#image_hide_show_labels { + display: none !important; +} + +.select2-search--dropdown .select2-search__field { + padding: 0px !important; +} diff --git a/pandora_console/include/styles/new_installation_welcome_window.css b/pandora_console/include/styles/new_installation_welcome_window.css index 90f96a5445..6d354b0c33 100644 --- a/pandora_console/include/styles/new_installation_welcome_window.css +++ b/pandora_console/include/styles/new_installation_welcome_window.css @@ -86,3 +86,29 @@ #welcome_form li.extra { padding-bottom: 2.5em; } + +#li-div_diagnosis, +#li-div_task_todo, +#li-div_wizard_agent { + border-left: unset !important; +} + +#div_diagnosis > label, +#div_task_todo > label { + font-weight: bold; +} + +button.buttonButton.onlyIcon.fail, +button.submitButton.onlyIcon.fail { + mask: url(../../images/fail@svg.svg) no-repeat center / contain; + -webkit-mask: url(../../images/fail@svg.svg) no-repeat center / contain; +} + +.select2-container .select2-container--default .select2-container--open { + z-index: 2000; +} + +#div_wizard_agent > .select2 { + width: 75% !important; + max-width: 75% !important; +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index d4fec36d08..b725e6260e 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -31,6 +31,8 @@ --primary-color: #14524f; --secondary-color: #ffffff; --input-border: #c0ccdc; + --border-color: #eee; + --text-color: #333; } /* @@ -4210,13 +4212,6 @@ div.simple_value > a > span.text p { } .modalokbutton { - transition-property: background-color, color; - transition-duration: 1s; - transition-timing-function: ease-out; - -webkit-transition-property: background-color, color; - -webkit-transition-duration: 1s; - -o-transition-property: background-color, color; - -o-transition-duration: 1s; cursor: pointer; text-align: center; margin-right: 45px; @@ -4227,44 +4222,24 @@ div.simple_value > a > span.text p { border-radius: 3px; width: 90px; height: 30px; - background-color: white; - border: 1px solid #82b92e; + background-color: var(--primary-color); + border: 1px solid var(--primary-color); + border-radius: 6px; } .modalokbuttontext { - transition-property: background-color, color; - transition-duration: 1s; - transition-timing-function: ease-out; - -webkit-transition-property: background-color, color; - -webkit-transition-duration: 1s; - -o-transition-property: background-color, color; - -o-transition-duration: 1s; - color: #82b92e; + color: #fff; font-size: 10pt; position: relative; top: 6px; } .modalokbutton:hover { - transition-property: background-color, color; - transition-duration: 1s; - transition-timing-function: ease-out; - -webkit-transition-property: background-color, color; - -webkit-transition-duration: 1s; - -o-transition-property: background-color, color; - -o-transition-duration: 1s; - background-color: #82b92e; + background-color: var(--primary-color); } .modalokbutton:hover .modalokbuttontext { - transition-property: background-color, color; - transition-duration: 1s; - transition-timing-function: ease-out; - -webkit-transition-property: background-color, color; - -webkit-transition-duration: 1s; - -o-transition-property: background-color, color; - -o-transition-duration: 1s; - color: white; + color: #fff; } .modaldeletebutton { @@ -7623,6 +7598,10 @@ div.graph div.legend table { padding-bottom: 10px !important; } +.pdd_b_15px_important { + padding-bottom: 15px !important; +} + .pdd_b_20px { padding-bottom: 20px; } @@ -7701,6 +7680,10 @@ div.graph div.legend table { padding-top: 15px; } +.pdd_t_15px_important { + padding-top: 15px !important; +} + .pdd_t_20px { padding-top: 20px; } @@ -9037,8 +9020,7 @@ div.graph div.legend table { } .app_mssg { - position: absolute; - bottom: 1em; + margin: 1em; clear: both; color: #888; } @@ -10804,6 +10786,10 @@ button.ui-button.ui-widget.submit-cancel:active { border-color: #96a2bf; } +.cursor-default { + cursor: default; +} + .hasColorPicker { z-index: 10; } @@ -11662,14 +11648,14 @@ p.trademark-copyright { } .show-hide-pass { - position: relative; - right: 40px; + position: absolute; + right: 9px; top: 4px; border: 0; outline: none; margin: 0; height: 30px; - width: 30px; + width: 40px; cursor: pointer; display: inline-block; } @@ -11910,10 +11896,6 @@ span.help_icon_15px > img { height: 15px !important; } -.select2-dropdown { - z-index: 1116 !important; -} - .icon_connection_check { width: 65px !important; height: 65px !important; @@ -11949,7 +11931,7 @@ span.help_icon_15px > img { /* ==== Spinner ==== */ .spinner-fixed { position: absolute; - left: 40%; + left: 45%; top: 40%; z-index: 1; width: 100px; @@ -11959,6 +11941,7 @@ span.help_icon_15px > img { animation: animate 1.2s linear infinite; margin: auto; margin-bottom: 40px; + text-align: initial; } .spinner-fixed span { position: absolute; @@ -12341,3 +12324,10 @@ tr[id^="network_component-plugin-wmi-fields-dynamicMacroRow-"] input, tr[id^="network_component-plugin-snmp-fields-dynamicMacroRow-"] input { width: 100% !important; } + +.start-end-date-log-viewer { + display: flex; + flex-direction: row !important; + flex-wrap: nowrap; + justify-content: flex-start !important; +} diff --git a/pandora_console/include/styles/pandora_black.css b/pandora_console/include/styles/pandora_black.css index 652d777f72..a37b5ad4dc 100644 --- a/pandora_console/include/styles/pandora_black.css +++ b/pandora_console/include/styles/pandora_black.css @@ -20,6 +20,13 @@ Description: The default Pandora FMS theme layout // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +:root { + /* --primary-color: #14524f; */ + --secondary-color: #222; + --text-color: #fff; + /* --input-border: #c0ccdc; */ + --border-color: #484848; +} /* General styles */ body, diff --git a/pandora_console/include/styles/select2.min.css b/pandora_console/include/styles/select2.min.css index ad21d16958..9d81e83c30 100644 --- a/pandora_console/include/styles/select2.min.css +++ b/pandora_console/include/styles/select2.min.css @@ -71,7 +71,7 @@ position: absolute; left: -100000px; width: 100%; - z-index: 1115; + z-index: 1118; } .select2-results { display: block; diff --git a/pandora_console/include/styles/tables.css b/pandora_console/include/styles/tables.css index 562ffc3c80..6974aed9e8 100644 --- a/pandora_console/include/styles/tables.css +++ b/pandora_console/include/styles/tables.css @@ -237,7 +237,8 @@ .table_action_buttons > img, .table_action_buttons > button, .table_action_buttons > form, -.table_action_buttons > div { +.table_action_buttons > div, +.table_action_buttons .action_button_hidden { visibility: hidden; } .info_table > tbody > tr:hover { @@ -250,7 +251,8 @@ .info_table > tbody > tr:hover .table_action_buttons > img, .info_table > tbody > tr:hover .table_action_buttons > button, .info_table > tbody > tr:hover .table_action_buttons > form, -.info_table > tbody > tr:hover .table_action_buttons > div { +.info_table > tbody > tr:hover .table_action_buttons > div, +.info_table > tbody > tr:hover .table_action_buttons .action_button_hidden { visibility: visible; } @@ -381,15 +383,35 @@ a.pandora_pagination.current:hover { cursor: pointer; } +.dt-button.buttons-csv.buttons-html5.mini-csv-button { + background-image: url(../../images/file-csv.svg); + background-position: 4px center; + height: 26px; + width: 31px; + margin-left: 10px; + box-shadow: 0px 0px 0px #00000000; + border: 0px; + border-radius: 0px; +} + .dt-button.buttons-csv.buttons-html5:hover { color: #1d7873 !important; border: 2px solid #1d7873 !important; } +.dt-button.buttons-csv.buttons-html5.mini-csv-button:hover { + color: #00000000 !important; + border: 0px !important; +} + .dt-button.buttons-csv.buttons-html5:before { content: "csv"; } +.dt-button.buttons-csv.buttons-html5.mini-csv-button:before { + content: ""; +} + .dt-button.buttons-csv.buttons-html5 span { font-size: 0; } diff --git a/pandora_console/index.php b/pandora_console/index.php index 96be49a6af..b3566e3589 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -292,7 +292,7 @@ enterprise_include_once('include/auth/saml.php'); if (isset($config['id_user']) === false) { // Clear error messages. unset($_COOKIE['errormsg']); - setcookie('errormsg', null, -1); + setcookie('errormsg', '', -1); if (isset($_GET['login']) === true) { include_once 'include/functions_db.php'; @@ -712,7 +712,6 @@ if (isset($config['id_user']) === false) { login_check_failed($nick); } - $config['auth_error'] = __('User is blocked'); $login_failed = true; } diff --git a/pandora_console/install.php b/pandora_console/install.php index 5627b2be25..f4513d0bb4 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -131,7 +131,7 @@
'ui-icon-menu-group ui-widget-icon-floatbeginning ui-icon-menu-square', ]; - if ((bool) $system->getConfig('legacy_vc', false) === false) { - // Show Visual consoles only if new system is enabled. - $items['visualmaps'] = [ - 'name' => __('Visual consoles'), - 'filename' => 'visualmaps.php', - 'menu_item' => true, - 'icon' => 'ui-icon-menu-visual_console ui-widget-icon-floatbeginning ui-icon-menu-square', - ]; - } + // Show Visual consoles only if new system is enabled. + $items['visualmaps'] = [ + 'name' => __('Visual consoles'), + 'filename' => 'visualmaps.php', + 'menu_item' => true, + 'icon' => 'ui-icon-menu-visual_console ui-widget-icon-floatbeginning ui-icon-menu-square', + ]; $items['alerts'] = [ 'name' => __('Alerts'), diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 4db865990f..07974af99e 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -258,7 +258,8 @@ if ((bool) check_acl($config['id_user'], $id_group, 'LW') === true || (bool) che ); } - if ($print_agent === true) { + /* + if ($print_agent === true) { array_push( $column_names, ['text' => 'Agent'] @@ -268,11 +269,12 @@ if ((bool) check_acl($config['id_user'], $id_group, 'LW') === true || (bool) che $columns, ['agent_name'] ); - } + }*/ } array_push( $column_names, + ['text' => 'Agent'], ['text' => 'Module'], ['text' => 'Template'], [ @@ -286,6 +288,7 @@ array_push( $columns = array_merge( $columns, + ['agent_name'], ['agent_module_name'], ['template_name'], ['action'], @@ -359,7 +362,7 @@ if ($agent_view_page === true) { [ 'id' => 'alerts_status_datatable', 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'no_sortable_columns' => $no_sortable_columns, diff --git a/pandora_console/operation/agentes/graphs.php b/pandora_console/operation/agentes/graphs.php index 3ba04acf7e..14b13c6893 100644 --- a/pandora_console/operation/agentes/graphs.php +++ b/pandora_console/operation/agentes/graphs.php @@ -45,7 +45,7 @@ if ((bool) check_acl($config['id_user'], $id_grupo, 'AR') === false && (bool) ch require_once $config['homedir'].'/include/functions_graph.php'; $draw_alerts = get_parameter('draw_alerts', 0); -$period = get_parameter('period', SECONDS_1HOUR); +$period = (string) get_parameter('period', SECONDS_2HOUR); $width = get_parameter('width', 555); $height = get_parameter('height', 245); $label = get_parameter('label', ''); @@ -53,8 +53,8 @@ $start_date = get_parameter('start_date', date('Y-m-d')); $draw_events = get_parameter('draw_events', 0); $modules = get_parameter('modules', []); $filter = get_parameter('filter', 0); -$combined = get_parameter('combined', 1); -$option_type = get_parameter('option_type', 0); +$combined = get_parameter('combined', 0); +$option_type = get_parameter('option_type', 2); // ---------------------------------------------------------------------- // Get modules of agent sorted as: @@ -176,11 +176,12 @@ foreach ($modules_boolean as $i => $m) { $list_modules = ($modules_networkmap_no_proc + $modules_others + $modules_boolean); +asort($list_modules); // ---------------------------------------------------------------------- if (empty($modules)) { // Selected the first 6 modules. $module_ids = array_keys($list_modules); - $module_ids = array_slice($module_ids, 0, 6); + $module_ids = array_slice($module_ids, 0, 12); $modules = $module_ids; } @@ -301,7 +302,7 @@ $htmlForm .= html_print_div( $htmlForm .= ''; -ui_toggle($htmlForm, __('Filter graphs'), __('Toggle filter(s)'), '', false); +ui_toggle($htmlForm, __('Filter graphs'), __('Toggle filter(s)'), '', true); $utime = get_system_time(); $current = date('Y-m-d', $utime); @@ -316,13 +317,17 @@ if ($combined) { // Pass the $modules before the ajax call. echo '
'.html_print_image('images/spinner.gif', true).'
'; } else { + echo '
'; foreach ($modules as $id_module) { $title = modules_get_agentmodule_name($id_module); $unit = modules_get_unit($id_module); - + echo '
'; echo '

'.$title.'

'; - echo '
'.html_print_image('images/spinner.gif', true).'
'; + echo '
'.html_print_image('images/spinner.gif', true).'
'; + echo '
'; } + + echo '
'; } echo "
"; diff --git a/pandora_console/operation/agentes/pandora_networkmap.editor.php b/pandora_console/operation/agentes/pandora_networkmap.editor.php index ac73c474aa..3dea327116 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.editor.php +++ b/pandora_console/operation/agentes/pandora_networkmap.editor.php @@ -205,9 +205,15 @@ if ($edit_networkmap) { $button = []; if ($edit_networkmap === true) { + if (empty($method) === false && $method === 'radial_dinamic') { + $url = 'index.php?sec=network&sec2=operation/agentes/networkmap.dinamic&activeTab=radial_dynamic&id_networkmap='.$id; + } else { + $url = 'index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap='.$id; + } + $button['map'] = [ 'active' => false, - 'text' => ''.html_print_image( + 'text' => ''.html_print_image( 'images/network@svg.svg', true, [ diff --git a/pandora_console/operation/agentes/pandora_networkmap.php b/pandora_console/operation/agentes/pandora_networkmap.php index 540cd8c173..52c376b4f7 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.php +++ b/pandora_console/operation/agentes/pandora_networkmap.php @@ -256,152 +256,164 @@ if ($new_networkmap || $save_networkmap) { $name = (string) get_parameter('name'); - // Default size values. - $width = $config['networkmap_max_width']; - $height = $config['networkmap_max_width']; - - $method = (string) get_parameter('method', 'fdp'); - - $recon_task_id = (int) get_parameter( - 'recon_task_id', - 0 + $exist = db_get_row_filter( + 'tmap', + [ + 'name' => $name, + 'id_group_map' => $id_group_map, + ], ); - $ip_mask = get_parameter( - 'ip_mask', - '' - ); - $source = (string) get_parameter('source', 'group'); - $dont_show_subgroups = (int) get_parameter_checkbox( - 'dont_show_subgroups', - 0 - ); - $node_radius = (int) get_parameter('node_radius', 40); - $description = get_parameter('description', ''); - $offset_x = get_parameter('pos_x', 0); - $offset_y = get_parameter('pos_y', 0); - $scale_z = get_parameter('scale_z', 0.5); + if ($exist !== false) { + $result_txt = ui_print_error_message(__('Another network map already exists with this name and group.')); + } else { + // Default size values. + $width = $config['networkmap_max_width']; + $height = $config['networkmap_max_width']; - $node_sep = get_parameter('node_sep', '0.25'); - $rank_sep = get_parameter('rank_sep', ($method === 'twopi') ? '1.0' : '0.5'); + $method = (string) get_parameter('method', 'fdp'); - $mindist = get_parameter('mindist', '1.0'); - $kval = get_parameter('kval', '0.3'); - - $refresh_time = get_parameter('refresh_time', '300'); - - $values = []; - $values['name'] = $name; - $values['id_group'] = implode(',', $id_group); - $values['source_period'] = 60; - $values['width'] = $width; - $values['height'] = $height; - $values['id_user'] = $config['id_user']; - $values['description'] = $description; - $values['id_group_map'] = $id_group_map; - $values['refresh_time'] = $refresh_time; - - switch ($method) { - case 'twopi': - $values['generation_method'] = LAYOUT_RADIAL; - break; - - case 'dot': - $values['generation_method'] = LAYOUT_FLAT; - break; - - case 'circo': - $values['generation_method'] = LAYOUT_CIRCULAR; - break; - - case 'neato': - $values['generation_method'] = LAYOUT_SPRING1; - break; - - case 'fdp': - $values['generation_method'] = LAYOUT_SPRING2; - break; - - case 'radial_dinamic': - $values['generation_method'] = LAYOUT_RADIAL_DYNAMIC; - break; - - default: - $values['generation_method'] = LAYOUT_RADIAL; - break; - } - - if ($source == 'group') { - $values['source'] = 0; - $values['source_data'] = implode(',', $id_group); - } else if ($source == 'recon_task') { - $values['source'] = 1; - $values['source_data'] = $recon_task_id; - } else if ($source == 'ip_mask') { - $values['source'] = 2; - $values['source_data'] = $ip_mask; - } - - if ($networkmap_write === false && $networkmap_manage === false) { - db_pandora_audit( - AUDIT_LOG_ACL_VIOLATION, - 'Trying to access networkmap' + $recon_task_id = (int) get_parameter( + 'recon_task_id', + 0 ); - include 'general/noaccess.php'; - return; - } - - $filter = []; - $filter['dont_show_subgroups'] = $dont_show_subgroups; - $filter['node_radius'] = $node_radius; - $filter['x_offs'] = $offset_x; - $filter['y_offs'] = $offset_y; - $filter['z_dash'] = $scale_z; - $filter['node_sep'] = $node_sep; - $filter['rank_sep'] = $rank_sep; - $filter['mindist'] = $mindist; - $filter['kval'] = $kval; - - $values['filter'] = json_encode($filter); - - $result = false; - if (!empty($name)) { - $result = db_process_sql_insert( - 'tmap', - $values + $ip_mask = get_parameter( + 'ip_mask', + '' ); - } + $source = (string) get_parameter('source', 'group'); + $dont_show_subgroups = (int) get_parameter_checkbox( + 'dont_show_subgroups', + 0 + ); + $node_radius = (int) get_parameter('node_radius', 40); + $description = get_parameter('description', ''); - $result_txt = ui_print_result_message( - $result, - __('Succesfully created'), - __('Could not be created'), - '', - true - ); + $offset_x = get_parameter('pos_x', 0); + $offset_y = get_parameter('pos_y', 0); + $scale_z = get_parameter('scale_z', 0.5); - $id = $result; - define('_id_', $id); + $node_sep = get_parameter('node_sep', '0.25'); + $rank_sep = get_parameter('rank_sep', ($method === 'twopi') ? '1.0' : '0.5'); - if ($result !== false) { - $tab = 'view'; - if ($values['generation_method'] == LAYOUT_RADIAL_DYNAMIC) { - $tab = 'r_dinamic'; - define('_activeTab_', 'radial_dynamic'); - $url = 'index.php?sec=network&sec2=operation/agentes/networkmap.dinamic&activeTab=radial_dynamic'; - header( - 'Location: '.ui_get_full_url( - $url.'&id_networkmap='.$id - ) + $mindist = get_parameter('mindist', '1.0'); + $kval = get_parameter('kval', '0.3'); + + $refresh_time = get_parameter('refresh_time', '300'); + + $values = []; + $values['name'] = $name; + $values['id_group'] = implode(',', $id_group); + $values['source_period'] = 60; + $values['width'] = $width; + $values['height'] = $height; + $values['id_user'] = $config['id_user']; + $values['description'] = $description; + $values['id_group_map'] = $id_group_map; + $values['refresh_time'] = $refresh_time; + + switch ($method) { + case 'twopi': + $values['generation_method'] = LAYOUT_RADIAL; + break; + + case 'dot': + $values['generation_method'] = LAYOUT_FLAT; + break; + + case 'circo': + $values['generation_method'] = LAYOUT_CIRCULAR; + break; + + case 'neato': + $values['generation_method'] = LAYOUT_SPRING1; + break; + + case 'fdp': + $values['generation_method'] = LAYOUT_SPRING2; + break; + + case 'radial_dinamic': + $values['generation_method'] = LAYOUT_RADIAL_DYNAMIC; + break; + + default: + $values['generation_method'] = LAYOUT_RADIAL; + break; + } + + if ($source == 'group') { + $values['source'] = 0; + $values['source_data'] = implode(',', $id_group); + } else if ($source == 'recon_task') { + $values['source'] = 1; + $values['source_data'] = $recon_task_id; + } else if ($source == 'ip_mask') { + $values['source'] = 2; + $values['source_data'] = $ip_mask; + } + + if ($networkmap_write === false && $networkmap_manage === false) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Trying to access networkmap' ); - } else { - $url = 'index.php?sec=network&sec2=operation/agentes/pandora_networkmap'; - header( - 'Location: '.ui_get_full_url( - $url.'&tab='.$tab.'&id_networkmap='.$id - ) + include 'general/noaccess.php'; + return; + } + + $filter = []; + $filter['dont_show_subgroups'] = $dont_show_subgroups; + $filter['node_radius'] = $node_radius; + $filter['x_offs'] = $offset_x; + $filter['y_offs'] = $offset_y; + $filter['z_dash'] = $scale_z; + $filter['node_sep'] = $node_sep; + $filter['rank_sep'] = $rank_sep; + $filter['mindist'] = $mindist; + $filter['kval'] = $kval; + + $values['filter'] = json_encode($filter); + + $result = false; + if (!empty($name)) { + $result = db_process_sql_insert( + 'tmap', + $values ); } + + $result_txt = ui_print_result_message( + $result, + __('Succesfully created'), + __('Could not be created'), + '', + true + ); + + $id = $result; + define('_id_', $id); + + if ($result !== false) { + $tab = 'view'; + if ($values['generation_method'] == LAYOUT_RADIAL_DYNAMIC) { + $tab = 'r_dinamic'; + define('_activeTab_', 'radial_dynamic'); + $url = 'index.php?sec=network&sec2=operation/agentes/networkmap.dinamic&activeTab=radial_dynamic'; + header( + 'Location: '.ui_get_full_url( + $url.'&id_networkmap='.$id + ) + ); + } else { + $url = 'index.php?sec=network&sec2=operation/agentes/pandora_networkmap'; + header( + 'Location: '.ui_get_full_url( + $url.'&tab='.$tab.'&id_networkmap='.$id + ) + ); + } + } } } } @@ -464,70 +476,81 @@ else if ($update_networkmap || $copy_networkmap || $delete) { } $name = (string) get_parameter('name', ''); - - $recon_task_id = (int) get_parameter( - 'recon_task_id', - 0 + $exist = db_get_row_filter( + 'tmap', + [ + 'name' => $name, + 'id_group_map' => $id_group_map, + ], ); - $source = (string) get_parameter('source', 'group'); - - $offset_x = get_parameter('pos_x', 0); - $offset_y = get_parameter('pos_y', 0); - $scale_z = get_parameter('scale_z', 0.5); - - $refresh_time = get_parameter('refresh_time', '300'); - - $values = []; - $values['name'] = $name; - $values['id_group'] = implode(',', $id_group); - $values['id_group_map'] = $id_group_map; - - $description = get_parameter('description', ''); - $values['description'] = $description; - - $values['refresh_time'] = $refresh_time; - - $dont_show_subgroups = (int) get_parameter('dont_show_subgroups', 0); - $node_radius = (int) get_parameter('node_radius', 40); - $row = db_get_row('tmap', 'id', $id); - $filter = json_decode($row['filter'], true); - $filter['dont_show_subgroups'] = $dont_show_subgroups; - $filter['node_radius'] = $node_radius; - $filter['x_offs'] = $offset_x; - $filter['y_offs'] = $offset_y; - $filter['z_dash'] = $scale_z; - - $values['filter'] = json_encode($filter); - - $result = false; - if (empty($name) === false) { - $result = db_process_sql_update( - 'tmap', - $values, - ['id' => $id] + if ($exist !== false) { + $result_txt = ui_print_error_message(__('Another network map already exists with this name and group.')); + } else { + $recon_task_id = (int) get_parameter( + 'recon_task_id', + 0 ); - ui_update_name_fav_element($id, 'Network_map', $name); - } - $result_txt = ui_print_result_message( - $result, - __('Succesfully updated'), - __('Could not be updated'), - '', - true - ); + $source = (string) get_parameter('source', 'group'); - if ($result) { - // If change the group, the map must be regenerated - if ($id_group != $id_group_old) { - networkmap_delete_nodes($id); - // Delete relations. - networkmap_delete_relations($id); + $offset_x = get_parameter('pos_x', 0); + $offset_y = get_parameter('pos_y', 0); + $scale_z = get_parameter('scale_z', 0.5); + + $refresh_time = get_parameter('refresh_time', '300'); + + $values = []; + $values['name'] = $name; + $values['id_group'] = implode(',', $id_group); + $values['id_group_map'] = $id_group_map; + + $description = get_parameter('description', ''); + $values['description'] = $description; + + $values['refresh_time'] = $refresh_time; + + $dont_show_subgroups = (int) get_parameter('dont_show_subgroups', 0); + $node_radius = (int) get_parameter('node_radius', 40); + $row = db_get_row('tmap', 'id', $id); + $filter = json_decode($row['filter'], true); + $filter['dont_show_subgroups'] = $dont_show_subgroups; + $filter['node_radius'] = $node_radius; + $filter['x_offs'] = $offset_x; + $filter['y_offs'] = $offset_y; + $filter['z_dash'] = $scale_z; + + $values['filter'] = json_encode($filter); + + $result = false; + if (empty($name) === false) { + $result = db_process_sql_update( + 'tmap', + $values, + ['id' => $id] + ); + ui_update_name_fav_element($id, 'Network_map', $name); } - $networkmap_write = $networkmap_write_new; - $networkmap_manage = $networkmap_manage_new; + $result_txt = ui_print_result_message( + $result, + __('Succesfully updated'), + __('Could not be updated'), + '', + true + ); + + if ($result) { + // If change the group, the map must be regenerated + if ($id_group != $id_group_old) { + networkmap_delete_nodes($id); + // Delete relations. + networkmap_delete_relations($id); + } + + $networkmap_write = $networkmap_write_new; + $networkmap_manage = $networkmap_manage_new; + } } } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 92f1875513..e469b9dc38 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -493,23 +493,52 @@ if (is_ajax() === true) { } } + if (strlen($tmp->server_name) >= 10) { + $tmp->server_name = ui_print_truncate_text( + $tmp->server_name, + 10, + false, + true, + false, + '…', + true, + true, + ); + } + $tmp->evento = str_replace('"', '', io_safe_output($tmp->evento)); - if (strlen($tmp->evento) >= 255) { + $event_text = $tmp->evento; + if (strlen($tmp->evento) >= 40) { $tmp->evento = ui_print_truncate_text( $tmp->evento, - 255, - $tmp->evento, + 40, + false, + true, + false, + '…', + true, true, - false ); } if (empty($tmp->module_name) === false) { $tmp->module_name = io_safe_output($tmp->module_name); + if (strlen($tmp->module_name) >= 20) { + $tmp->module_name = ui_print_truncate_text( + $tmp->module_name, + 20, + false, + true, + false, + '…', + true, + true, + ); + } } if (empty($tmp->comments) === false) { - $tmp->comments = ui_print_comments($tmp->comments); + $tmp->comments = ui_print_comments($tmp->comments, 20); } // Show last event. @@ -535,6 +564,32 @@ if (is_ajax() === true) { } $tmp->agent_name = io_safe_output($tmp->agent_name); + if (strlen($tmp->agent_name) >= 10) { + $tmp->agent_name = ui_print_truncate_text( + $tmp->agent_name, + 10, + false, + true, + false, + '…', + true, + true, + ); + } + + $tmp->id_extra = io_safe_output($tmp->id_extra); + if (strlen($tmp->id_extra) >= 10) { + $tmp->id_extra = ui_print_truncate_text( + $tmp->id_extra, + 10, + false, + true, + false, + '…', + true, + true, + ); + } $tmp->ack_utimestamp_raw = $tmp->ack_utimestamp; @@ -557,7 +612,7 @@ if (is_ajax() === true) { $total_sec = strtotime($tmp->timestamp); $total_sec += $dif; - $last_contact = date($config['date_format'], $total_sec); + $last_contact = date($confb64ig['date_format'], $total_sec); $last_contact_value = ui_print_timestamp($last_contact, true); } else { $title = date($config['date_format'], strtotime($tmp->timestamp)); @@ -583,9 +638,23 @@ if (is_ajax() === true) { } $tmp->instructions = events_get_instructions($item); + if (strlen($tmp->instructions) >= 20) { + $tmp->instructions = ui_print_truncate_text( + $tmp->instructions, + 20, + false, + true, + false, + '…', + true, + true, + ); + } + $aux_event = $tmp->evento; + $tmp->evento = $event_text; $tmp->b64 = base64_encode(json_encode($tmp)); - + $tmp->evento = $aux_event; // Show comments events. if (empty($tmp->comments) === false) { $tmp->user_comment = $tmp->comments; @@ -844,6 +913,19 @@ if (is_ajax() === true) { $tmp->owner_user = get_user_fullname($tmp->owner_user).' ('.$tmp->owner_user.')'; } + if (strlen($tmp->owner_user) >= 10) { + $tmp->owner_user = ui_print_truncate_text( + $tmp->owner_user, + 10, + false, + true, + false, + '…', + true, + true, + ); + } + // Group name. if (empty($tmp->id_grupo) === true) { $tmp->id_grupo = __('All'); @@ -851,8 +933,33 @@ if (is_ajax() === true) { $tmp->id_grupo = $tmp->group_name; } + if (strlen($tmp->id_grupo) >= 10) { + $tmp->id_grupo = ui_print_truncate_text( + $tmp->id_grupo, + 10, + false, + true, + false, + '…', + true, + true, + ); + } + // Module name. $tmp->id_agentmodule = $tmp->module_name; + if (strlen($tmp->id_agentmodule) >= 10) { + $tmp->id_agentmodule = ui_print_truncate_text( + $tmp->id_agentmodule, + 10, + false, + true, + false, + '…', + true, + true, + ); + } // Options. // Show more. @@ -1083,6 +1190,18 @@ if (is_ajax() === true) { } $tmp->custom_data = $custom_data_str; + if (strlen($tmp->custom_data) >= 20) { + $tmp->custom_data = ui_print_truncate_text( + $tmp->custom_data, + 20, + false, + true, + false, + '…', + true, + true, + ); + } } $carry[] = $tmp; @@ -2417,7 +2536,7 @@ try { if (in_array('instructions', $fields) > 0) { $fields[array_search('instructions', $fields)] = [ 'text' => 'instructions', - 'class' => 'column-instructions', + 'class' => 'column-instructions mw60px', ]; } @@ -2429,14 +2548,24 @@ try { ]; } - $comment_id = array_search('user_comment', $fields); - if ($comment_id !== false) { - $fields[$comment_id] = [ + $user_comment = array_search('user_comment', $fields); + if ($user_comment !== false) { + $fields[$user_comment] = [ 'text' => 'user_comment', - 'class' => 'nowrap_max180px', + 'class' => 'mw100px', ]; } + + foreach ($fields as $key => $field) { + if (is_array($field) === false) { + $fields[$key] = [ + 'text' => $field, + 'class' => 'mw100px', + ]; + } + } + // Always add options column. $fields = array_merge( $fields, @@ -2462,6 +2591,7 @@ try { } } + // mw60px // Open current filter quick reference. $active_filters_div = '
'; @@ -2560,7 +2690,7 @@ try { [ 'id' => $table_id, 'class' => 'info_table events', - 'style' => 'width: 99%;', + 'style' => 'width: 100%;', 'ajax_url' => 'operation/events/events', 'ajax_data' => [ 'get_events' => 1, diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index 63b302062c..536f470fe6 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -804,7 +804,7 @@ if ($inventory_module !== 'basic') { [ 'id' => $id_table, 'class' => 'info_table w100p', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columns, 'no_sortable_columns' => [], @@ -919,7 +919,7 @@ if ($inventory_module !== 'basic') { [ 'id' => $id_table, 'class' => 'info_table w100p', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columns, 'no_sortable_columns' => [], @@ -1083,7 +1083,7 @@ if ($inventory_module !== 'basic') { [ 'id' => $id_table, 'class' => 'info_table w100p', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columns, 'no_sortable_columns' => [], @@ -1173,7 +1173,7 @@ if ($inventory_module !== 'basic') { [ 'id' => $id_table, 'class' => 'info_table w100p', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columns, 'no_sortable_columns' => [], @@ -1188,6 +1188,8 @@ if ($inventory_module !== 'basic') { 'emptyTable' => __('No inventory found'), 'return' => true, 'no_sortable_columns' => [], + 'mini_search' => true, + 'mini_pagination' => true, ] ); @@ -1204,7 +1206,7 @@ if ($inventory_module !== 'basic') { [ 'id' => $id_table, 'class' => 'info_table w100p', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columns, 'no_sortable_columns' => [], @@ -1233,7 +1235,7 @@ if ($inventory_module !== 'basic') { $agentes = []; $data = []; $class = 'info_table'; - $style = 'width: 99%'; + $style = 'width: 100%'; $ordering = true; $searching = false; diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php index 15716e653c..5d402a5793 100644 --- a/pandora_console/operation/network/network_report.php +++ b/pandora_console/operation/network/network_report.php @@ -39,10 +39,26 @@ if (! check_acl($config['id_user'], 0, 'AR')) { exit; } +// Ajax callbacks. +if (is_ajax() === true) { + $get_filter_values = get_parameter('get_filter_values', 0); + // Get values of the current network filter. + if ($get_filter_values) { + $id = get_parameter('id'); + $filter_values = db_get_row_filter('tnetwork_explorer_filter', ['id' => $id]); + // Decode HTML entities. + $filter_values['advanced_filter'] = io_safe_output($filter_values['advanced_filter']); + echo json_encode($filter_values); + } + + return; +} + // Include JS timepicker. ui_include_time_picker(); // Query params and other initializations. +$filter_id = (int) get_parameter('filter_id', 0); $time_greater = get_parameter('time_greater', date(TIME_FORMAT)); $date_greater = get_parameter('date_greater', date(DATE_FORMAT)); $utimestamp_greater = strtotime($date_greater.' '.$time_greater); @@ -59,6 +75,13 @@ $top = (int) get_parameter('top', 10); $main_value = ((bool) get_parameter('remove_filter', 0)) ? '' : get_parameter('main_value', ''); if (is_numeric($main_value) && !in_array($action, ['udp', 'tcp'])) { $main_value = ''; +} else { + $filter['ip'] = $main_value; +} + +$advanced_filter = get_parameter('advanced_filter', ''); +if ($advanced_filter !== '') { + $filter['advanced_filter'] = $advanced_filter; } $order_by = get_parameter('order_by', 'bytes'); @@ -66,30 +89,143 @@ if (!in_array($order_by, ['bytes', 'pkts', 'flows'])) { $order_by = 'bytes'; } -$style_end = ($is_period) ? 'display: none;' : ''; -$style_period = ($is_period) ? '' : 'display: none;'; +$save = get_parameter('save_button', ''); +$update = get_parameter('update_button', ''); + +// Save user defined filter. +if ($save != '' && check_acl($config['id_user'], 0, 'AW')) { + // Save filter args. + $data['filter_name'] = get_parameter('filter_name'); + $data['top'] = $top; + $data['action'] = $action; + $data['advanced_filter'] = $advanced_filter; + + + $filter_id = db_process_sql_insert('tnetwork_explorer_filter', $data); + if ($filter_id === false) { + $filter_id = 0; + ui_print_error_message(__('Error creating filter')); + } else { + ui_print_success_message(__('Filter created successfully')); + } +} else if ($update != '' && check_acl($config['id_user'], 0, 'AW')) { + // Update current filter. + // Do not update the filter name and group. + $data['top'] = $top; + $data['action'] = $action; + $data['advanced_filter'] = $advanced_filter; + + $result = db_process_sql_update( + 'tnetwork_explorer_filter', + $data, + ['id' => $filter_id] + ); + ui_print_result_message( + $result, + __('Filter updated successfully'), + __('Error updating filter') + ); +} // Build the table. -$table = new stdClass(); -$table->class = 'filter-table-adv'; -$table->width = '100%'; -$table->data = []; +$filterTable = new stdClass(); +$filterTable->id = ''; +$filterTable->class = 'filter-table-adv'; +$filterTable->size = []; +$filterTable->size[0] = '33%'; +$filterTable->size[1] = '33%'; +$filterTable->size[2] = '33%'; +$filterTable->data = []; -$table->data[0][] = html_print_label_input_block( - __('Data to show'), - html_print_select( - network_get_report_actions(false), - 'action', - $action, +$filterTable->data[0][0] = html_print_label_input_block( + __('Interval'), + html_print_extended_select_for_time( + 'period', + $period, '', '', 0, + false, + true + ), + [ 'div_id' => 'period_container' ] +); + +$filterTable->data[0][0] .= html_print_label_input_block( + __('Start date'), + html_print_div( + [ + 'class' => '', + 'content' => html_print_input_text( + 'date_lower', + $date_lower, + false, + 13, + 10, + true + ).html_print_image( + 'images/calendar_view_day.png', + true, + [ + 'alt' => 'calendar', + 'class' => 'main_menu_icon invert_filter', + ] + ).html_print_input_text( + 'time_lower', + $time_lower, + false, + 10, + 8, + true + ), + ], + true + ), + [ 'div_id' => 'end_date_container' ] +); + +$filterTable->data[0][1] = html_print_label_input_block( + __('End date'), + html_print_div( + [ + 'content' => html_print_input_text( + 'date', + $date_greater, + false, + 13, + 10, + true + ).html_print_image( + 'images/calendar_view_day.png', + true, + ['alt' => 'calendar'] + ).html_print_input_text( + 'time', + $time_greater, + false, + 10, + 8, + true + ), + ], true ) ); -$table->data[0][] = html_print_label_input_block( - __('Number of result to show'), +$filterTable->data[0][2] = html_print_label_input_block( + __('Defined period'), + html_print_checkbox_switch( + 'is_period', + 1, + ($is_period === true) ? 1 : 0, + true, + false, + 'nf_view_click_period()' + ) +); + +$filterTable->data[1][] = html_print_label_input_block( + __('Results to show'), html_print_select( [ '5' => 5, @@ -110,95 +246,62 @@ $table->data[0][] = html_print_label_input_block( ) ); -$table->data[1][] = html_print_label_input_block( - __('Start date'), - html_print_div( - [ - 'id' => 'end_date_container', - 'content' => html_print_input_text( - 'date_lower', - $date_lower, - '', - 10, - 10, - true - ).html_print_input_text( - 'time_lower', - $time_lower, - '', - 7, - 8, - true - ), - ], - true - ).html_print_div( - [ - 'id' => 'period_container', - 'style' => 'display: none;', - 'content' => html_print_label_input_block( - '', - html_print_extended_select_for_time( - 'period', - $period, - '', - '', - 0, - false, - true - ), - ), - ], +$filterTable->data[1][] = html_print_label_input_block( + __('Data to show'), + html_print_select( + network_get_report_actions(), + 'action', + $action, + '', + '', + 0, true ) ); -$table->data[1][] = html_print_label_input_block( - __('End date'), - html_print_div( - [ - 'id' => '', - 'class' => '', - 'content' => html_print_input_text( - 'date_greater', - $date_greater, - '', - 10, - 10, - true - ).html_print_input_text( - 'time_greater', - $time_greater, - '', - 7, - 8, - true - ), - ], - true - ) +$advanced_toggle = new stdClass(); +$advanced_toggle->class = 'filter-table-adv'; +$advanced_toggle->size = []; +$advanced_toggle->size[0] = '50%'; +$advanced_toggle->size[1] = '50%'; +$advanced_toggle->width = '100%'; +$user_groups = users_get_groups($config['id_user'], 'AR', $own_info['is_admin'], true); +$user_groups[0] = 0; +// Add all groups. +$sql = 'SELECT * FROM tnetwork_explorer_filter'; +$advanced_toggle->data[0][0] = html_print_label_input_block( + __('Load Filter'), + html_print_select_from_sql($sql, 'filter_id', $filter_id, '', __('Select a filter'), 0, true, false, true, false, 'width:100%;') ); - -$table->data[2][] = html_print_label_input_block( - __('Defined period'), - html_print_checkbox_switch( - 'is_period', - 1, - ($is_period === true) ? 1 : 0, +$advanced_toggle->data[0][1] = html_print_label_input_block( + __('Filter name'), + html_print_input_text('filter_name', '', false, 40, 45, true, false, false, '', 'w100p') +); +$advanced_toggle->colspan[1][0] = 2; +$advanced_toggle->data[1][0] = html_print_label_input_block( + __('Filter').ui_print_help_icon('pcap_filter', true), + html_print_textarea('advanced_filter', 4, 10, $advanced_filter, 'style="width:100%"', true) +); +$filterTable->colspan[2][0] = 3; +$filterTable->data[2][0] = html_print_label_input_block( + '', + ui_toggle( + html_print_table($advanced_toggle, true), + __('Advanced'), + '', + '', true, - false, - 'network_report_click_period(event)' + true, + '', + 'white-box-content', + 'box-flat white_table_graph' ) ); -echo '
'; -html_print_input_hidden('order_by', $order_by); -if (empty($main_value) === false) { - html_print_input_hidden('main_value', $main_value); -} - -$outputTable = html_print_table($table, true); -$outputTable .= html_print_div( +$filterInputTable = ''; +$filterInputTable .= html_print_input_hidden('order_by', $order_by); +$filterInputTable .= html_print_table($filterTable, true); +$filterInputTable .= html_print_div( [ 'class' => 'action-buttons-right-forced', 'content' => html_print_submit_button( @@ -210,19 +313,48 @@ $outputTable .= html_print_div( 'mode' => 'mini', ], true + ).html_print_submit_button( + __('Save as new filter'), + 'save_button', + false, + [ + 'icon' => 'load', + 'onClick' => 'return defineFilterName();', + 'mode' => 'mini secondary', + 'class' => 'mrgn_right_10px', + ], + true + ).html_print_submit_button( + __('Update current filter'), + 'update_button', + false, + [ + 'icon' => 'load', + 'mode' => 'mini secondary', + 'class' => 'mrgn_right_10px', + ], + true ), ], true ); +$filterInputTable .= html_print_div( + [ + 'class' => 'action-buttons', + 'content' => $netflow_button, + ], + true +); +$filterInputTable .= '
'; ui_toggle( - $outputTable, - ''.__('Filters').'', - __('Filters'), - '', + $filterInputTable, + ''.__('Filter').'', + __('Filter'), + 'search', true, false, '', - 'white-box-content', + 'white-box-content no_border', 'box-flat white_table_graph fixed_filter_bar' ); html_print_action_buttons( @@ -246,7 +378,7 @@ $data = netflow_get_top_summary( $action, $utimestamp_lower, $utimestamp_greater, - $main_value, + $filter, $order_by ); @@ -450,6 +582,26 @@ if (empty($data)) { ?> diff --git a/pandora_console/operation/network/network_usage_map.php b/pandora_console/operation/network/network_usage_map.php index e3919e90b9..ff2c99869d 100644 --- a/pandora_console/operation/network/network_usage_map.php +++ b/pandora_console/operation/network/network_usage_map.php @@ -34,6 +34,21 @@ global $config; check_login(); +// Ajax callbacks. +if (is_ajax() === true) { + $get_filter_values = get_parameter('get_filter_values', 0); + // Get values of the current network filter. + if ($get_filter_values) { + $id = get_parameter('id'); + $filter_values = db_get_row_filter('tnetwork_usage_filter', ['id' => $id]); + // Decode HTML entities. + $filter_values['advanced_filter'] = io_safe_output($filter_values['advanced_filter']); + echo json_encode($filter_values); + } + + return; +} + // Header. ui_print_standard_header( __('Network usage map'), @@ -76,6 +91,7 @@ $is_period = (bool) get_parameter('is_period', false); $period = (int) get_parameter('period', SECONDS_1HOUR); $time_lower = get_parameter('time_lower', date(TIME_FORMAT, ($utimestamp_greater - $period))); $date_lower = get_parameter('date_lower', date(DATE_FORMAT, ($utimestamp_greater - $period))); +$advanced_filter = get_parameter('advanced_filter', ''); $utimestamp_lower = ($is_period) ? ($utimestamp_greater - $period) : strtotime($date_lower.' '.$time_lower); if (!$is_period) { $period = ($utimestamp_greater - $utimestamp_lower); @@ -88,6 +104,44 @@ if (in_array($order_by, ['bytes', 'pkts', 'flows']) === false) { $order_by = 'bytes'; } +$save = get_parameter('save_button', ''); +$update = get_parameter('update_button', ''); + +// Save user defined filter. +if ($save != '' && check_acl($config['id_user'], 0, 'AW')) { + // Save filter args. + $data['filter_name'] = get_parameter('filter_name'); + $data['top'] = $top; + $data['action'] = $action; + $data['advanced_filter'] = $advanced_filter; + + + $filter_id = db_process_sql_insert('tnetwork_usage_filter', $data); + if ($filter_id === false) { + $filter_id = 0; + ui_print_error_message(__('Error creating filter')); + } else { + ui_print_success_message(__('Filter created successfully')); + } +} else if ($update != '' && check_acl($config['id_user'], 0, 'AW')) { + // Update current filter. + // Do not update the filter name and group. + $data['top'] = $top; + $data['action'] = $action; + $data['advanced_filter'] = $advanced_filter; + + $result = db_process_sql_update( + 'tnetwork_usage_filter', + $data, + ['id' => $filter_id] + ); + ui_print_result_message( + $result, + __('Filter updated successfully'), + __('Error updating filter') + ); +} + if ((bool) $config['activate_netflow'] === true) { $netflow_button = html_print_submit_button( __('Show netflow map'), @@ -95,6 +149,27 @@ if ((bool) $config['activate_netflow'] === true) { false, ['icon' => 'update'], true + ).html_print_submit_button( + __('Save as new filter'), + 'save_button', + false, + [ + 'icon' => 'load', + 'onClick' => 'return defineFilterName();', + 'mode' => 'mini secondary', + 'class' => 'mrgn_right_10px', + ], + true + ).html_print_submit_button( + __('Update current filter'), + 'update_button', + false, + [ + 'icon' => 'load', + 'mode' => 'mini secondary', + 'class' => 'mrgn_right_10px', + ], + true ); } else { $netflow_button = ''; @@ -232,6 +307,44 @@ $filterTable->data[1][] = html_print_label_input_block( ) ); +$advanced_toggle = new stdClass(); +$advanced_toggle->class = 'filter-table-adv'; +$advanced_toggle->size = []; +$advanced_toggle->size[0] = '50%'; +$advanced_toggle->size[1] = '50%'; +$advanced_toggle->width = '100%'; +$user_groups = users_get_groups($config['id_user'], 'AR', $own_info['is_admin'], true); +$user_groups[0] = 0; +$sql = 'SELECT * FROM tnetwork_usage_filter'; +$advanced_toggle->data[0][0] = html_print_label_input_block( + __('Load Filter'), + html_print_select_from_sql($sql, 'filter_id', $filter_id, '', __('Select a filter'), 0, true, false, true, false, 'width:100%;') +); +$advanced_toggle->data[0][1] = html_print_label_input_block( + __('Filter name'), + html_print_input_text('filter_name', '', false, 40, 45, true, false, false, '', 'w100p') +); +$advanced_toggle->colspan[1][0] = 2; +$advanced_toggle->data[1][0] = html_print_label_input_block( + __('Filter').ui_print_help_icon('pcap_filter', true), + html_print_textarea('advanced_filter', 4, 10, $advanced_filter, 'style="width:100%"', true) +); +$filterTable->colspan[2][0] = 3; +$filterTable->data[2][0] = html_print_label_input_block( + '', + ui_toggle( + html_print_table($advanced_toggle, true), + __('Advanced'), + '', + '', + true, + true, + '', + 'white-box-content', + 'box-flat white_table_graph' + ) +); + $filterInputTable = '
'; $filterInputTable .= html_print_input_hidden('order_by', $order_by); $filterInputTable .= html_print_table($filterTable, true); @@ -263,7 +376,8 @@ if ((bool) get_parameter('update_netflow') === true) { $utimestamp_lower, $utimestamp_greater, $top, - ($action === 'talkers') ? 'srcip' : 'dstip' + ($action === 'talkers') ? 'srcip' : 'dstip', + $advanced_filter ); $has_data = !empty($map_data['nodes']); } @@ -283,10 +397,26 @@ if ($has_data === true) {