diff --git a/extras/deploy-scripts/deploy_ext_database_el8.sh b/extras/deploy-scripts/deploy_ext_database_el8.sh new file mode 100644 index 0000000000..52bad444fe --- /dev/null +++ b/extras/deploy-scripts/deploy_ext_database_el8.sh @@ -0,0 +1,322 @@ +#!/bin/bash +####################################################### +# PandoraFMS Community online installation script +####################################################### +## Tested versions ## +# Centos 8.4, 8.5 +# Rocky 8.4, 8.5, 8.6, 8.7 +# Almalinuz 8.4, 8.5 +# RedHat 8.5 + +#Constants +S_VERSION='202302201' +LOGFILE="/tmp/deploy-ext-db-$(date +%F).log" + + +# define default variables +[ "$TZ" ] || TZ="Europe/Madrid" +[ "$MYVER" ] || MYVER=57 +[ "$DBHOST" ] || DBHOST=127.0.0.1 +[ "$DBNAME" ] || DBNAME=pandora +[ "$DBUSER" ] || DBUSER=pandora +[ "$DBPASS" ] || DBPASS=pandora +[ "$DBPORT" ] || DBPORT=3306 +[ "$DBROOTUSER" ] || DBROOTUSER=root +[ "$DBROOTPASS" ] || DBROOTPASS=pandora +[ "$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") + +# Ansi color code variables +red="\e[0;91m" +green="\e[0;92m" +cyan="\e[0;36m" +reset="\e[0m" + +# Functions +execute_cmd () { + local cmd="$1" + local msg="$2" + + echo -e "${cyan}$msg...${reset}" + $cmd &>> "$LOGFILE" + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [ "$3" ] && echo "$3" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + rm -rf "$HOME"/pandora_deploy_tmp &>> "$LOGFILE" + exit 1 + else + echo -e "\e[1A\e ${cyan}$msg...${reset} ${green}OK${reset}" + return 0 + fi +} + +check_cmd_status () { + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [ "$1" ] && echo "$1" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + rm -rf "$HOME"/pandora_deploy_tmp/*.rpm* &>> "$LOGFILE" + exit 1 + else + echo -e "${green}OK${reset}" + return 0 + fi +} + +check_root_permissions () { + echo -en "${cyan}Checking root account... ${reset}" + if [ "$(whoami)" != "root" ]; then + echo -e "${red}Fail${reset}" + echo "Please use a root account or sudo for installing Pandora FMS" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + exit 1 + + else + echo -e "${green}OK${reset}" + fi +} + +## Main +echo "Starting PandoraFMS External DB deployment EL8 ver. $S_VERSION" + +# Centos Version +if [ ! "$(grep -Ei 'centos|rocky|Almalinux|Red Hat Enterprise' /etc/redhat-release)" ]; then + printf "\n ${red}Error this is not a Centos/Rocky/Almalinux Base system, this installer is compatible with RHEL/Almalinux/Centos/Rockylinux systems only${reset}\n" + exit 1 +fi + + +echo -en "${cyan}Check Centos Version...${reset}" +[ $(sed -nr 's/VERSION_ID+=\s*"([0-9]).*"$/\1/p' /etc/os-release) -eq '8' ] +check_cmd_status 'Error OS version, RHEL/Almalinux/Centos/Rockylinux 8+ is expected' + +#Detect OS +os_name=$(grep ^PRETTY_NAME= /etc/os-release | cut -d '=' -f2 | tr -d '"') +execute_cmd "echo $os_name" "OS detected: ${os_name}" + +# initialice logfile +execute_cmd "echo 'Starting community deployment' > $LOGFILE" "All installer activity is logged on $LOGFILE" +echo "Community installer version: $S_VERSION" >> "$LOGFILE" + +# Pre checks +# Root permisions +check_root_permissions + +# Systemd +execute_cmd "systemctl status" "Checking SystemD" 'This is not a SystemD enable system, if tryng to use in a docker env please check: https://github.com/pandorafms/pandorafms/tree/develop/extras/docker/centos8' + +# Check memomry greather or equal to 2G +execute_cmd "[ $(grep MemTotal /proc/meminfo | awk '{print $2}') -ge 1700000 ]" 'Checking memory (required: 2 GB)' + +# Check disk size at least 10 Gb free space +execute_cmd "[ $(df -BM / | tail -1 | awk '{print $4}' | tr -d M) -gt 10000 ]" 'Checking Disk (required: 10 GB free min)' + +# Setting timezone +rm -rf /etc/localtime &>> "$LOGFILE" +execute_cmd "timedatectl set-timezone $TZ" "Setting Timezone $TZ" + +# Execute tools check +execute_cmd "awk --version" 'Checking needed tools: awk' +execute_cmd "grep --version" 'Checking needed tools: grep' +execute_cmd "sed --version" 'Checking needed tools: sed' +execute_cmd "dnf --version" 'Checking needed tools: dnf' + +# Creating working directory +rm -rf "$HOME"/pandora_deploy_tmp/*.rpm* &>> "$LOGFILE" +mkdir "$HOME"/pandora_deploy_tmp &>> "$LOGFILE" +execute_cmd "cd $HOME/pandora_deploy_tmp" "Moving to workspace: $HOME/pandora_deploy_tmp" + +## Extra steps on redhat envs +if [ "$(grep -Ei 'Red Hat Enterprise' /etc/redhat-release)" ]; then + ## In case REDHAT + # Check susbscription manager status: + echo -en "${cyan}Checking Red Hat Enterprise subscription... ${reset}" + subscription-manager list &>> "$LOGFILE" + subscription-manager status &>> "$LOGFILE" + check_cmd_status 'Error checking subscription status, make sure your server is activated and suscribed to Red Hat Enterprise repositories' + + # Ckeck repolist + dnf repolist &>> "$LOGFILE" + echo -en "${cyan}Checking Red Hat Enterprise repolist... ${reset}" + dnf repolist | grep 'rhel-8-for-x86_64-baseos-rpms' &>> "$LOGFILE" + check_cmd_status 'Error checking repositories status, could try a subscription-manager attach command or contact sysadmin' + + #install extra repos + extra_repos=" \ + tar \ + dnf-utils \ + https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \ + https://repo.percona.com/yum/percona-release-latest.noarch.rpm" + + execute_cmd "dnf install -y $extra_repos" "Installing extra repositories" + execute_cmd "subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms" "Enabling subscription to codeready-builder" +else + # For alma/rocky/centos + extra_repos=" \ + tar \ + dnf-utils \ + epel-release \ + https://repo.percona.com/yum/percona-release-latest.noarch.rpm" + + execute_cmd "dnf install -y $extra_repos" "Installing extra repositories" + execute_cmd "dnf config-manager --set-enabled powertools" "Configuring Powertools" +fi + + +#Installing wget +execute_cmd "dnf install -y wget" "Installing wget" + + +# Install percona Database +execute_cmd "dnf module disable -y mysql" "Disabiling mysql module" + +if [ "$MYVER" -eq '80' ] ; then + execute_cmd "percona-release setup ps80 -y" "Enabling mysql80 module" + execute_cmd "dnf install -y percona-server-server percona-xtrabackup-24" "Installing Percona Server 80" +fi + +if [ "$MYVER" -ne '80' ] ; then + execute_cmd "dnf install -y Percona-Server-server-57 percona-xtrabackup-24" "Installing Percona Server 57" +fi + +# Disabling SELINUX and firewalld +setenforce 0 &>> "$LOGFILE" +sed -i -e "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config &>> "$LOGFILE" +systemctl disable firewalld --now &>> "$LOGFILE" + +# Adding standar cnf for initial setup. +cat > /etc/my.cnf << EO_CONFIG_TMP +[mysqld] +datadir=/var/lib/mysql +socket=/var/lib/mysql/mysql.sock +symbolic-links=0 +log-error=/var/log/mysqld.log +pid-file=/var/run/mysqld/mysqld.pid +EO_CONFIG_TMP + +#Configuring Database +if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then + execute_cmd "systemctl start mysqld" "Starting database engine" + 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 + + export MYSQL_PWD=$DBROOTPASS + echo -en "${cyan}Creating Pandora FMS database...${reset}" + echo "create database $DBNAME" | mysql -u$DBROOTUSER -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." + + echo "CREATE USER \"$DBUSER\"@'%' IDENTIFIED BY \"$DBPASS\";" | mysql -u$DBROOTUSER -P$DBPORT -h$DBHOST + echo "ALTER USER \"$DBUSER\"@'%' IDENTIFIED WITH mysql_native_password BY \"$DBPASS\"" | mysql -u$DBROOTUSER -P$DBPORT -h$DBHOST + echo "GRANT ALL PRIVILEGES ON $DBNAME.* TO \"$DBUSER\"@'%'" | mysql -u$DBROOTUSER -P$DBPORT -h$DBHOST + +#Generating my.cnf +cat > /etc/my.cnf << EO_CONFIG_F +[mysqld] +datadir=/var/lib/mysql +socket=/var/lib/mysql/mysql.sock +user=mysql +character-set-server=utf8 +skip-character-set-client-handshake +# Disabling symbolic-links is recommended to prevent assorted security risks +symbolic-links=0 +# Mysql optimizations for Pandora FMS +# Please check the documentation in http://pandorafms.com for better results + +max_allowed_packet = 64M +innodb_buffer_pool_size = $POOL_SIZE +innodb_lock_wait_timeout = 90 +innodb_file_per_table +innodb_flush_log_at_trx_commit = 0 +innodb_flush_method = O_DIRECT +innodb_log_file_size = 64M +innodb_log_buffer_size = 16M +innodb_io_capacity = 100 +thread_cache_size = 8 +thread_stack = 256K +max_connections = 100 + +key_buffer_size=4M +read_buffer_size=128K +read_rnd_buffer_size=128K +sort_buffer_size=128K +join_buffer_size=4M + +query_cache_type = 1 +query_cache_size = 64M +query_cache_min_res_unit = 2k +query_cache_limit = 256K + +#skip-log-bin + +sql_mode="" + +[mysqld_safe] +log-error=/var/log/mysqld.log +pid-file=/var/run/mysqld/mysqld.pid + +EO_CONFIG_F + + if [ "$MYVER" -eq '80' ] ; then + sed -i -e "/query_cache.*/ s/^#*/#/g" /etc/my.cnf + sed -i -e "s/#skip-log-bin/skip-log-bin/g" /etc/my.cnf + sed -i -e "s/character-set-server=utf8/character-set-server=utf8mb4/g" /etc/my.cnf + + fi + + execute_cmd "systemctl restart mysqld" "Configuring database engine" + execute_cmd "systemctl enable mysqld --now" "Enabling Database service" +fi +export MYSQL_PWD=$DBPASS + + +# Kernel optimization + +if [ "$SKIP_KERNEL_OPTIMIZATIONS" -eq '0' ] ; then +cat >> /etc/sysctl.conf < /dev/null # remove last log before start + +# define default variables +[ "$TZ" ] || TZ="Europe/Madrid" +[ "$DBHOST" ] || DBHOST=127.0.0.1 +[ "$DBNAME" ] || DBNAME=pandora +[ "$DBUSER" ] || DBUSER=pandora +[ "$DBPASS" ] || DBPASS=pandora +[ "$DBPORT" ] || DBPORT=3306 +[ "$DBROOTPASS" ] || DBROOTPASS=pandora +[ "$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") + + +# Ansi color code variables +red="\e[0;91m" +green="\e[0;92m" +cyan="\e[0;36m" +reset="\e[0m" + +# Functions + +execute_cmd () { + local cmd="$1" + local msg="$2" + + echo -e "${cyan}$msg...${reset}" + $cmd &>> "$LOGFILE" + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [ "$3" ] && echo "$3" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + rm -rf "$WORKDIR" &>> "$LOGFILE" + exit 1 + else + echo -e "\e[1A\e ${cyan}$msg...${reset} ${green}OK${reset}" + return 0 + fi +} + +check_cmd_status () { + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [ "$1" ] && echo "$1" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + rm -rf "$WORKDIR" &>> "$LOGFILE" + exit 1 + else + echo -e "${green}OK${reset}" + return 0 + fi +} + +check_root_permissions () { + echo -en "${cyan}Checking root account... ${reset}" + if [ "$(whoami)" != "root" ]; then + echo -e "${red}Fail${reset}" + echo "Please use a root account or sudo for installing Pandora FMS" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + exit 1 + + else + echo -e "${green}OK${reset}" + fi +} + +## Main +echo "Starting PandoraFMS External DB deployment Ubuntu 22.04 ver. $S_VERSION" + +# Ubuntu Version +if [ ! "$(grep -Ei 'Ubuntu' /etc/lsb-release)" ]; then + printf "\n ${red}Error this is not a Ubuntu system, this installer is compatible with Ubuntu systems only${reset}\n" + exit 1 +fi + + +echo -en "${cyan}Check Ubuntu Version...${reset}" +[ $(sed -nr 's/VERSION_ID+=\s*"([0-9][0-9].[0-9][0-9])"$/\1/p' /etc/os-release) == "22.04" ] +check_cmd_status 'Error OS version, Ubuntu 22.04 is expected' + +#Detect OS +os_name=$(grep ^PRETTY_NAME= /etc/os-release | cut -d '=' -f2 | tr -d '"') +execute_cmd "echo $os_name" "OS detected: ${os_name}" + +# initialice logfile +execute_cmd "echo 'Starting community deployment' > $LOGFILE" "All installer activity is logged on $LOGFILE" +echo "Community installer version: $S_VERSION" >> "$LOGFILE" + +# Pre checks +# Root permisions +check_root_permissions + +#Install awk, sed, grep if not present +execute_cmd "apt install -y gawk sed grep" 'Installing needed tools' + +# Systemd +execute_cmd "systemctl --version" "Checking SystemD" 'This is not a SystemD enable system, if tryng to use in a docker env please check: https://github.com/pandorafms/pandorafms/tree/develop/extras/docker/centos8' + +# Check memomry greather or equal to 2G +execute_cmd "[ $(grep MemTotal /proc/meminfo | awk '{print $2}') -ge 1700000 ]" 'Checking memory (required: 2 GB)' + +# Check disk size at least 10 Gb free space +execute_cmd "[ $(df -BM / | tail -1 | awk '{print $4}' | tr -d M) -gt 10000 ]" 'Checking Disk (required: 10 GB free min)' + +# Setting timezone +rm -rf /etc/localtime &>> "$LOGFILE" +execute_cmd "timedatectl set-timezone $TZ" "Setting Timezone $TZ" + +# Execute tools check +execute_cmd "awk --version" 'Checking needed tools: awk' +execute_cmd "grep --version" 'Checking needed tools: grep' +execute_cmd "sed --version" 'Checking needed tools: sed' +execute_cmd "apt --version" 'Checking needed tools: apt' + +# Creating working directory +rm -rf "$WORKDIR" &>> "$LOGFILE" +mkdir -p "$WORKDIR" &>> "$LOGFILE" +execute_cmd "cd $WORKDIR" "Moving to workdir: $WORKDIR" + +## Install utils +execute_cmd "apt update" "Updating repos" +execute_cmd "apt install -y net-tools vim curl wget software-properties-common apt-transport-https" "Installing utils" + +# Disabling apparmor and ufw +systemctl stop ufw.service &>> "$LOGFILE" +systemctl disable ufw &>> "$LOGFILE" +systemctl stop apparmor &>> "$LOGFILE" +systemctl disable apparmor &>> "$LOGFILE" + +#install mysql +execute_cmd "curl -O https://repo.percona.com/apt/percona-release_latest.generic_all.deb" "Downloading Percona repository for MySQL8" +execute_cmd "apt install -y gnupg2 lsb-release ./percona-release_latest.generic_all.deb" "Installing Percona repository for MySQL8" +execute_cmd "percona-release setup ps80" "Configuring Percona repository for MySQL8" + +echo -en "${cyan}Installing Percona Server for MySQL8...${reset}" + env DEBIAN_FRONTEND=noninteractive apt install -y percona-server-server &>> "$LOGFILE" +check_cmd_status "Error Installing MySql Server" + +#Configuring Database +if [ "$SKIP_DATABASE_INSTALL" -eq '0' ] ; then + execute_cmd "systemctl start mysql" "Starting database engine" + + echo """ + ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DBROOTPASS'; + """ | mysql -uroot &>> "$LOGFILE" + + export MYSQL_PWD=$DBROOTPASS + 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." + + echo "CREATE USER \"$DBUSER\"@'%' IDENTIFIED BY \"$DBPASS\";" | mysql -uroot -P$DBPORT -h$DBHOST + echo "ALTER USER \"$DBUSER\"@'%' IDENTIFIED WITH mysql_native_password BY \"$DBPASS\"" | mysql -uroot -P$DBPORT -h$DBHOST + echo "GRANT ALL PRIVILEGES ON $DBNAME.* TO \"$DBUSER\"@'%'" | mysql -uroot -P$DBPORT -h$DBHOST +fi +export MYSQL_PWD=$DBPASS + +#Generating my.cnf +cat > /etc/mysql/my.cnf << EOF_DB +[mysqld] +datadir=/var/lib/mysql +user=mysql +character-set-server=utf8mb4 +skip-character-set-client-handshake +# Disabling symbolic-links is recommended to prevent assorted security risks +symbolic-links=0 +# Mysql optimizations for Pandora FMS +# Please check the documentation in http://pandorafms.com for better results + +max_allowed_packet = 64M +innodb_buffer_pool_size = $POOL_SIZE +innodb_lock_wait_timeout = 90 +innodb_file_per_table +innodb_flush_log_at_trx_commit = 0 +innodb_flush_method = O_DIRECT +innodb_log_file_size = 64M +innodb_log_buffer_size = 16M +innodb_io_capacity = 300 +thread_cache_size = 8 +thread_stack = 256K +max_connections = 100 + +key_buffer_size=4M +read_buffer_size=128K +read_rnd_buffer_size=128K +sort_buffer_size=128K +join_buffer_size=4M + +skip-log-bin + +sql_mode="" + +log-error=/var/log/mysql/error.log +[mysqld_safe] +log-error=/var/log/mysqld.log +pid-file=/var/run/mysqld/mysqld.pid + +EOF_DB + +execute_cmd "systemctl restart mysql" "Configuring and restarting database engine" + +# Kernel optimization +if [ "$SKIP_KERNEL_OPTIMIZATIONS" -eq '0' ] ; then +cat >> /etc/sysctl.conf <> $LOGFILE execute_cmd "mv gotty /usr/bin/" 'Installing gotty util' @@ -639,8 +639,8 @@ systemctl enable tentacle_serverd &>> $LOGFILE execute_cmd "service tentacle_serverd start" "Starting Tentacle Server" # Enabling condole cron -execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" -echo "* * * * * root wget -q -O - --no-check-certificate http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab +execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" +echo "* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab ## Enabling agent systemctl enable pandora_agent_daemon &>> $LOGFILE execute_cmd "systemctl start pandora_agent_daemon" "Starting Pandora FMS Agent" diff --git a/extras/deploy-scripts/pandora_deploy_community_el8.sh b/extras/deploy-scripts/pandora_deploy_community_el8.sh index 794e11f8fe..cc14ad1ffa 100644 --- a/extras/deploy-scripts/pandora_deploy_community_el8.sh +++ b/extras/deploy-scripts/pandora_deploy_community_el8.sh @@ -5,7 +5,7 @@ ## Tested versions ## # Centos 8.4, 8.5 # Rocky 8.4, 8.5, 8.6, 8.7 -# Almalinuz 8.4, 8.5 +# Almalinux 8.4, 8.5 # RedHat 8.5 #Constants @@ -14,7 +14,7 @@ PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='202301251' +S_VERSION='202302201' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables @@ -107,6 +107,17 @@ check_root_permissions () { fi } +installing_docker () { + #Installing docker for debug + echo "Start installig docker" &>> "$LOGFILE" + dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &>> "$LOGFILE" + dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &>> "$LOGFILE" + systemctl disable --now docker &>> "$LOGFILE" + systemctl disable docker.socket --now &>> "$LOGFILE" + echo "End installig docker" &>> "$LOGFILE" +} + + ## Main echo "Starting PandoraFMS Community deployment EL8 ver. $S_VERSION" @@ -207,6 +218,7 @@ else execute_cmd "dnf config-manager --set-enabled powertools" "Configuring Powertools" fi +execute_cmd "installing_docker" "Installing Docker for debug" #Installing wget execute_cmd "dnf install -y wget" "Installing wget" @@ -454,7 +466,7 @@ innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_log_file_size = 64M innodb_log_buffer_size = 16M -innodb_io_capacity = 100 +innodb_io_capacity = 300 thread_cache_size = 8 thread_stack = 256K max_connections = 100 @@ -483,6 +495,7 @@ EO_CONFIG_F if [ "$MYVER" -eq '80' ] ; then sed -i -e "/query_cache.*/ s/^#*/#/g" /etc/my.cnf sed -i -e "s/#skip-log-bin/skip-log-bin/g" /etc/my.cnf + sed -i -e "s/character-set-server=utf8/character-set-server=utf8mb4/g" /etc/my.cnf fi execute_cmd "systemctl restart mysqld" "Configuring database engine" @@ -517,7 +530,7 @@ execute_cmd "curl -LSs --output pandorafms_agent_linux-7.0NG.noarch.rpm ${PANDOR execute_cmd "dnf install -y $HOME/pandora_deploy_tmp/pandorafms*.rpm" "Installing Pandora FMS packages" # Copy gotty utility -execute_cmd "wget https://pandorafms.com/library/wp-content/uploads/2019/11/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' +execute_cmd "wget https://firefly.pandorafms.com/pandorafms/utils/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' tar xvzf gotty_linux_amd64.tar.gz &>> $LOGFILE execute_cmd "mv gotty /usr/bin/" 'Installing gotty util' @@ -732,8 +745,8 @@ systemctl enable tentacle_serverd &>> "$LOGFILE" execute_cmd "service tentacle_serverd start" "Starting Tentacle Server" # Enabling condole cron -execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" -echo "* * * * * root wget -q -O - --no-check-certificate http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab +execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" +echo "* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab ## Enabling agent systemctl enable pandora_agent_daemon &>> "$LOGFILE" execute_cmd "systemctl start pandora_agent_daemon" "Starting Pandora FMS Agent" @@ -743,7 +756,7 @@ execute_cmd "systemctl start pandora_agent_daemon" "Starting Pandora FMS Agent" cat > /etc/issue.net << EOF_banner -Welcome to Pandora FMS appliance on CentOS +Welcome to Pandora FMS appliance on RHEL/Rocky Linux 8 ------------------------------------------ Go to Public http://$ipplublic/pandora_console$to to login web console $(ip addr | grep -w "inet" | grep -v "127.0.0.1" | grep -v "172.17.0.1" | awk '{print $2}' | awk -F '/' '{print "Go to Local http://"$1"/pandora_console to login web console"}') diff --git a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh index f52eb625e2..1446abfab3 100644 --- a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh +++ b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh @@ -4,6 +4,7 @@ ############################################################################################################## ## Tested versions ## # Ubuntu 22.04.1 +# Ubuntu 22.04.2 #avoid promps export DEBIAN_FRONTEND=noninteractive @@ -16,7 +17,7 @@ PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf WORKDIR=/opt/pandora/deploy -S_VERSION='202301251' +S_VERSION='202302201' LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" rm -f $LOGFILE &> /dev/null # remove last log before start @@ -106,6 +107,21 @@ check_root_permissions () { fi } +installing_docker () { + #Installing docker for debug + echo "Start installig docker" &>> "$LOGFILE" + mkdir -m 0755 -p /etc/apt/keyrings &>> "$LOGFILE" + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --yes --dearmor -o /etc/apt/keyrings/docker.gpg &>> "$LOGFILE" + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list &>> "$LOGFILE" + apt update -y &>> "$LOGFILE" + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &>> "$LOGFILE" + systemctl disable docker --now &>> "$LOGFILE" + systemctl disable docker.socket --now &>> "$LOGFILE" + echo "End installig docker" &>> "$LOGFILE" +} + ## Main echo "Starting PandoraFMS Community deployment Ubuntu 22.04 ver. $S_VERSION" @@ -173,7 +189,7 @@ execute_cmd "cd $WORKDIR" "Moving to workdir: $WORKDIR" ## Install utils execute_cmd "apt update" "Updating repos" -execute_cmd "apt install -y net-tools vim curl wget software-properties-common apt-transport-https" "Installing utils" +execute_cmd "apt install -y net-tools vim curl wget software-properties-common apt-transport-https ca-certificates gnupg lsb-release" "Installing utils" #Installing Apache and php-fpm [ -e "/etc/apt/sources.list.d/ondrej-ubuntu-php-jammy.list" ] || execute_cmd "add-apt-repository ppa:ondrej/php -y" "Enable ppa:ondrej/php repo" @@ -221,7 +237,8 @@ systemctl restart php$PHPVER-fpm &>> "$LOGFILE" php$PHPVER-xml \ php$PHPVER-yaml \ libnet-telnet-perl \ - whois" + whois \ + cron" execute_cmd "apt install -y $console_dependencies" "Installing Pandora FMS Console dependencies" # Server dependencies @@ -254,10 +271,13 @@ server_dependencies=" \ libnet-telnet-perl \ libjson-perl \ libencode-perl \ + cron \ libgeo-ip-perl \ openjdk-8-jdk " execute_cmd "apt install -y $server_dependencies" "Installing Pandora FMS Server dependencies" +execute_cmd "installing_docker" "Installing Docker for debug" + # wmic and pandorawmic execute_cmd "curl -O https://firefly.artica.es/pandorafms/utils/bin/wmic" "Downloading wmic" execute_cmd "curl -O https://firefly.artica.es/pandorafms/utils/bin/pandorawmic" "Downloading pandorawmic" @@ -393,7 +413,7 @@ cat > /etc/mysql/my.cnf << EOF_DB [mysqld] datadir=/var/lib/mysql user=mysql -character-set-server=utf8 +character-set-server=utf8mb4 skip-character-set-client-handshake # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 @@ -408,7 +428,7 @@ innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_log_file_size = 64M innodb_log_buffer_size = 16M -innodb_io_capacity = 100 +innodb_io_capacity = 300 thread_cache_size = 8 thread_stack = 256K max_connections = 100 @@ -477,7 +497,7 @@ check_cmd_status "Error installing PandoraFMS Agent" # Copy gotty utility cd $WORKDIR &>> "$LOGFILE" -execute_cmd "wget https://pandorafms.com/library/wp-content/uploads/2019/11/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' +execute_cmd "wget https://firefly.pandorafms.com/pandorafms/utils/gotty_linux_amd64.tar.gz" 'Dowloading gotty util' tar xvzf gotty_linux_amd64.tar.gz &>> $LOGFILE execute_cmd "mv gotty /usr/bin/" 'Installing gotty util' @@ -731,9 +751,14 @@ systemctl enable pandora_server &>> "$LOGFILE" execute_cmd "service tentacle_serverd start" "Starting Tentacle Server" systemctl enable tentacle_serverd &>> "$LOGFILE" -# Enabling condole cron -execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" -echo "* * * * * root wget -q -O - --no-check-certificate http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab +# Enabling console cron +execute_cmd "echo \"* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS Console cron" +echo "* * * * * root wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://127.0.0.1/pandora_console/enterprise/cron.php >> $PANDORA_CONSOLE/log/cron.log" >> /etc/crontab + +# Enabling pandoradb cron +execute_cmd "echo 'enabling pandoradb cron' >> $PANDORA_CONSOLE/log/cron.log\" >> /etc/crontab" "Enabling Pandora FMS pandoradb cron" +echo "@hourly root bash -c /etc/cron.hourly/pandora_db" >> /etc/crontab + ## Enabling agent adn configuring Agente sed -i "s/^remote_config.*$/remote_config 1/g" $PANDORA_AGENT_CONF &>> "$LOGFILE" @@ -748,7 +773,7 @@ sed --follow-symlinks -i -e "s/^openssl_conf = openssl_init/#openssl_conf = open cat > /etc/issue.net << EOF_banner -Welcome to Pandora FMS appliance on CentOS +Welcome to Pandora FMS appliance on Ubuntu ------------------------------------------ Go to Public http://$ipplublic/pandora_console$to to login web console $(ip addr | grep -w "inet" | grep -v "127.0.0.1" | grep -v "172.17.0.1" | awk '{print $2}' | awk -F '/' '{print "Go to Local http://"$1"/pandora_console to login web console"}') diff --git a/extras/docker/centos8/pandora-stack/sources/init_pandora.sh b/extras/docker/centos8/pandora-stack/sources/init_pandora.sh index 76a0954bb8..e9265a0981 100755 --- a/extras/docker/centos8/pandora-stack/sources/init_pandora.sh +++ b/extras/docker/centos8/pandora-stack/sources/init_pandora.sh @@ -277,8 +277,8 @@ export ORACLE_HOME=/usr/lib/oracle/$VERSION/client64 EOF_ENV echo ">> Enable discovery cron: " -#while true ; do wget -q -O - --no-check-certificate http://localhost/pandora_console/enterprise/cron.php >> /var/www/html/pandora_console/pandora_console.log && sleep 60 ; done & -echo "*/5 * * * * wget -q -O - --no-check-certificate http://localhost/pandora_console/enterprise/cron.php >> /var/www/html/pandora_console/log/cron.log" >> /opt/pandora/crontasks +#while true ; do wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://localhost/pandora_console/enterprise/cron.php >> /var/www/html/pandora_console/pandora_console.log && sleep 60 ; done & +echo "*/5 * * * * wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies http://localhost/pandora_console/enterprise/cron.php >> /var/www/html/pandora_console/log/cron.log" >> /opt/pandora/crontasks echo ">> Enable pandora_db cron: " /usr/bin/perl /usr/share/pandora_server/util/pandora_db.pl /etc/pandora/pandora_server.conf diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index c8512ffc13..9af85a5200 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, AIX version +# Version 7.0NG.769, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index c98b6c4f48..6650404c74 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, FreeBSD Version +# Version 7.0NG.769, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index a17181b6c2..957396affa 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, HP-UX Version +# Version 7.0NG.769, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 7eea50cdac..dac6aefc04 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, GNU/Linux +# Version 7.0NG.769, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index ed7aae82b3..a12c8ccce7 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, GNU/Linux +# Version 7.0NG.769, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index 8c189f05bf..75ff20dba4 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, Solaris Version +# Version 7.0NG.769, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index 46a569686d..6fca0a4523 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2021 Artica Soluciones Tecnologicas -# Version 7.0NG.768 +# Version 7.0NG.769 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software # Foundation; either version 2 of the Licence or any later version diff --git a/pandora_agents/pc/pandora_agent.redhat.spec b/pandora_agents/pc/pandora_agent.redhat.spec index ae481e3403..ce60c8841f 100644 --- a/pandora_agents/pc/pandora_agent.redhat.spec +++ b/pandora_agents/pc/pandora_agent.redhat.spec @@ -1,6 +1,7 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 4.0 %define release 1 diff --git a/pandora_agents/pc/pandora_agent.spec b/pandora_agents/pc/pandora_agent.spec index 1bfc289d52..5ad481315a 100644 --- a/pandora_agents/pc/pandora_agent.spec +++ b/pandora_agents/pc/pandora_agent.spec @@ -1,6 +1,7 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent_linux %define version 4.0.1 %define release 1 diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index a723aa503b..e47ec5442a 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.768, AIX version +# Version 7.0NG.769, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index e8dd39e1d2..bc353d4077 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.768 +# Version 7.0NG.769 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index 6b4ea56e3d..7e9f290fd0 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.768, HPUX Version +# Version 7.0NG.769, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 5ca49a15e1..674d2a3992 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768 +# Version 7.0NG.769 # Licensed under GPL license v2, # (c) 2003-2021 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/linux/pandora_agent.spec b/pandora_agents/shellscript/linux/pandora_agent.spec index 64b33bfecf..9c5e0296c6 100755 --- a/pandora_agents/shellscript/linux/pandora_agent.spec +++ b/pandora_agents/shellscript/linux/pandora_agent.spec @@ -1,6 +1,7 @@ # #Pandora FMS Linux Agent # +%global __os_install_post %{nil} %define name pandorafms_agent %define version 3.2 Summary: Pandora FMS Linux agent diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index b26ec72942..9654e1f2ee 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768 +# Version 7.0NG.769 # Licensed under GPL license v2, # (c) 2003-2021 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index b9b09e0f02..4fc7cf3202 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768 +# Version 7.0NG.769 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index 20036302b7..2113795918 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.768, Solaris version +# Version 7.0NG.769, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index e2050f1a5c..b02f88017e 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.768, AIX version +# Version 7.0NG.769, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2021 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 4cfb010cf2..14de36cabe 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.768-230209 +Version: 7.0NG.769-230309 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 38048034a1..c7bdb71c28 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.768-230209" +pandora_version="7.0NG.769-230309" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh b/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh index fd449c646b..b8862d3ee9 100644 --- a/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh +++ b/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh @@ -31,7 +31,7 @@ fi if [ "$#" -ge 2 ]; then VERSION="$2" else - VERSION="7.0NG.768" + VERSION="7.0NG.769" fi # Path for the generated DMG file diff --git a/pandora_agents/unix/Darwin/dmg/extras/distribution.xml b/pandora_agents/unix/Darwin/dmg/extras/distribution.xml index 4e4b347f08..f1aebe06a1 100644 --- a/pandora_agents/unix/Darwin/dmg/extras/distribution.xml +++ b/pandora_agents/unix/Darwin/dmg/extras/distribution.xml @@ -19,11 +19,11 @@ - pandorafms_src.pdk + pandorafms_src.pdk - pandorafms_uninstall.pdk + pandorafms_uninstall.pdk - - - - diff --git a/pandora_console/general/login_page.php b/pandora_console/general/login_page.php index bb9fa19185..8517b1c46c 100755 --- a/pandora_console/general/login_page.php +++ b/pandora_console/general/login_page.php @@ -30,16 +30,21 @@ require_once __DIR__.'/../include/functions_html.php'; if ($config['visual_animation']) { echo ''; } @@ -87,18 +92,36 @@ if (!empty($page) && !empty($sec)) { } $login_body_style = ''; -$login_body_class = ''; // Overrides the default background with the defined by the user. -if (!empty($config['login_background'])) { +$background_url = 'images/backgrounds/background_pandora_console_keys.jpg'; + +if (empty($config['random_background']) === false) { + $random_backgrounds = scandir($config['homedir'].'/images/backgrounds/random_backgrounds'); + unset($random_backgrounds[0], $random_backgrounds[1]); + $random_background = array_rand($random_backgrounds); + $background_url = 'images/backgrounds/random_backgrounds/'.$random_backgrounds[$random_background]; + $background_100 = 'background-size: 100% 100% !important; '; +} + +if (empty($config['login_background']) === false) { $background_url = 'images/backgrounds/'.$config['login_background']; - $login_body_style = "style=\"background-size: 100% 100% !important;background:linear-gradient(74deg, rgba(2, 2, 2, 0.333) 36%, transparent 36%), url('".$background_url."');\""; + $background_100 = 'background-size: 100% 100% !important; '; } // Support for Internet Explorer and Microsoft Edge browsers if (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== false) { - $login_body_class = "class='login_body_trident'"; + $background_url = 'images/backgrounds/background_pandora_console_keys.jpg'; + $background_100 = ''; } +if (empty($config['background_opacity']) === false) { + $opacity = $config['background_opacity']; +} else { + $opacity = 30; +} + +$login_body_style = 'style="'.$background_100.'background: linear-gradient(rgba(0,0,0,.'.$opacity.'), rgba(0,0,0,.'.$opacity.")), url('".$background_url."');\""; + // Get alternative custom in case of db fail. $custom_fields = [ 'custom_logo_login', @@ -123,36 +146,36 @@ foreach ($custom_fields as $field) { // Get the custom icons. $docs_logo = ui_get_docs_logo(); $support_logo = ui_get_support_logo(); -echo '
'; +echo '
'; echo '
'; echo '
'; @@ -248,15 +271,30 @@ switch ($login_screen) { echo '
'; echo ''; echo ''; echo ''; } else { echo ''; echo ''; } break; @@ -302,12 +348,13 @@ switch ($login_screen) { echo ''; echo ''; break; @@ -337,17 +384,18 @@ if ($config['enterprise_installed']) { echo ''.__('Forgot your password?'); echo ''; - echo ''; + echo '
'; echo '
'; - html_print_submit_button('Ok', 'reset_correct_button', false); + html_print_submit_button('Ok', 'reset_correct_button', false, ['class' => 'mini float-right']); echo '
'; echo '
'; echo '
'; echo ''; } else if (isset($process_error_message) && !empty($process_error_message)) { - echo '
'; + echo '
'; echo '
'; echo '
'; - echo html_print_image('images/icono_stop.png', true, ['alt' => __('Password reset'), 'border' => 0]); + echo html_print_image('images/icono_stop.png', true, ['alt' => __('Forbidden'), 'border' => 0]); echo '
'; echo '
'; echo '
'; echo '

'.__('ERROR').'

'; echo '

'.$process_error_message.'

'; + echo '
'; echo '
'; + echo '
'; echo '
'; - html_print_submit_button('Ok', 'reset_correct_button', false); + html_print_submit_button('Ok', 'reset_correct_button', false, ['class' => 'mini float-right']); echo '
'; echo '
'; echo '
'; @@ -472,8 +551,9 @@ if (isset($correct_reset_pass_process)) { echo '

'.__('SUCCESS').'

'; echo '

'.$correct_reset_pass_process.'

'; echo '
'; + echo '
'; echo '
'; - html_print_submit_button('Ok', 'final_process_correct_button', false); + html_print_submit_button('Ok', 'final_process_correct_button', false, ['class' => 'mini float-right']); echo '
'; echo '
'; echo ''; @@ -481,9 +561,36 @@ if (isset($correct_reset_pass_process)) { } if (isset($login_failed)) { - $nick = get_parameter_post('nick'); - $fails = db_get_value('failed_attempt', 'tusuario', 'id_user', $nick); + $nick = io_safe_input(get_parameter_post('nick')); + $user_in_db = db_get_row_filter( + 'tusuario', + ['id_user' => $nick], + '*' + ); + $fails = $user_in_db['failed_attempt']; + // If user not exist, and attempts its enable, lets make array and fails attemps. + if ($fails == false && $config['enable_pass_policy'] && $user_in_db === false) { + $nick_array_error = json_decode(base64_decode($config['nicks_error']), true); + $nick = strtolower($nick); + if (isset($nick_array_error[$nick]) !== false) { + $nick_array_error[$nick] += 1; + } else { + $nick_array_error[$nick] = 1; + } + + $fails = $nick_array_error[$nick]; + // Save or update the array. + if ($config['nicks_error']) { + config_update_value('nicks_error', base64_encode(json_encode($nick_array_error))); + } else { + config_create_value('nicks_error', base64_encode(json_encode($nick_array_error))); + } + } else { + $fails = ++$fails; + } + $attemps = ($config['number_attempts'] - $fails); + $attemps = ($attemps < 0) ? 0 : $attemps; echo '
'; echo '
'; echo '
'; @@ -496,12 +603,18 @@ if (isset($login_failed)) { echo '
'; if ($config['enable_pass_policy']) { echo '
'; - echo '

Remaining attempts: '.$attemps.'

'; + if ($attemps !== 0 && $user_in_db['login_blocked'] == 0) { + echo '

'.__('Remaining attempts: ').$attemps.'

'; + } else { + echo '

'.__('User is blocked').'

'; + } + echo '
'; } + echo '
'; echo '
'; - html_print_submit_button('Ok', 'hide-login-error', false); + html_print_submit_button('Ok', 'hide-login-error', false, ['class' => ' mini float-right']); echo '
'; echo '
'; echo '
'; @@ -524,8 +637,9 @@ if ($login_screen == 'logout') { } echo ''; + echo '
'; echo '
'; - html_print_submit_button('Ok', 'hide-login-logout', false); + html_print_submit_button('Ok', 'hide-login-logout', false, ['class' => ' mini float-right']); echo '
'; echo ''; echo ''; @@ -543,8 +657,9 @@ if ($login_screen === 'disabled_access_node') { echo '

'.__('Centralized user in metaconsole').'

'; echo '

'.__('This user does not have access on node, please enable node access on this user from metaconsole.').'

'; echo ''; + echo '
'; echo '
'; - html_print_submit_button('Ok', 'hide-login-logout', false); + html_print_submit_button('Ok', 'hide-login-logout', false, ['class' => 'mini float-right']); echo '
'; echo ''; echo ''; @@ -651,8 +766,9 @@ if ($login_screen == 'error_authconfig' || $login_screen == 'error_emptyconfig' echo '

'.$title.'

'; echo '

'.$message.''; echo ''; + echo '
'; echo '

'; - html_print_submit_button('Ok', 'hide-login-error', false); + html_print_submit_button('Ok', 'hide-login-error', false, ['class' => 'mini float-right']); echo '
'; echo ''; echo ''; @@ -707,7 +823,7 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' }); }); - $("#submit-hide-login-error").click (function () { + $("#button-hide-login-error").click (function () { $("#modal_alert" ).dialog('close'); }); @@ -722,19 +838,23 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 220, width: 528, clickOutside: true, overlay: { opacity: 0.5, background: "black" + }, + open: function (event, ui) { + $(".ui-widget-overlay").click(function () { + $('#login_logout').dialog('close'); + }); } }); }); - $("#submit-hide-login-logout").click (function () { - document.location = ""; - }); + $("#button-hide-login-logout").click (function () { + $( "#login_logout" ).dialog( "close" ); + }); }); break; @@ -745,7 +865,6 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 220, width: 528, clickOutside: true, overlay: { @@ -755,7 +874,7 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' }); }); - $("#submit-hide-login-logout").click (function () { + $("#button-hide-login-logout").click (function () { document.location = ""; }); }); @@ -769,7 +888,6 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 400, width: 700, overlay: { opacity: 0.5, @@ -787,8 +905,8 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 220, - width: 528, + height: 230, + width: 530, overlay: { opacity: 0.5, background: "black" @@ -796,12 +914,11 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' }); }); - $("#submit-hide-login-error").click (function () { + $("#button-hide-login-error").click (function () { $("#login_failed" ).dialog('close'); $("#login_correct_pass").dialog('close'); }); }); - $('#nick').focus(); break; } @@ -812,7 +929,6 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 220, width: 528, clickOutside: true, overlay: { @@ -822,7 +938,7 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' }); }); - $("#submit-reset_correct_button").click (function () { + $("#button-reset_correct_button").click (function () { $("#reset_correct").dialog('close'); }); }); @@ -833,7 +949,6 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 220, width: 528, clickOutside: true, overlay: { @@ -853,7 +968,6 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' resizable: true, draggable: true, modal: true, - height: 220, width: 528, overlay: { opacity: 0.5, @@ -866,5 +980,18 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', ' }); } + $(document).ready(function () { + $('#submit-login_button span').removeAttr('style'); + $('#spinner_login').hide(); + }); + + $('#submit-login_button').click(function (e) { + $('.login_nick').hide(); + $('.login_pass').hide(); + $('.login_button').hide(); + $('.reset_password').hide(); + $('#spinner_login').show(); + }); + /* ]]> */ diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index 972e6f37ca..2b88b6a103 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -124,8 +124,14 @@ foreach ($stats as $stat) { } $status .= ''; +$table->rowclass = []; +$table->rowclass[0] = 'w100p'; +$table->rowclass[1] = 'w100p'; +$table->rowclass[2] = 'w100p'; +$table->rowclass[3] = 'w100p'; +$table->rowclass[4] = 'w100p'; +$table->rowclass[5] = 'w100p'; $table->data[0][0] = $status; -$table->rowclass[] = ''; $table->data[] = $tdata; diff --git a/pandora_console/general/main_menu.php b/pandora_console/general/main_menu.php index 3ce49b646a..a961a62ecb 100644 --- a/pandora_console/general/main_menu.php +++ b/pandora_console/general/main_menu.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ============================================================================ - * Copyright (c) 2005-2021 Artica Soluciones Tecnologicas + * Copyright (c) 2005-2023 Artica Soluciones Tecnologicas * Please see http://pandorafms.org for full contribution list * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,38 +26,21 @@ * ============================================================================ */ -use function PHPSTORM_META\map; - // Begin. if (isset($config['id_user']) === false) { include 'general/login_page.php'; exit(); } -?> - -', $menuTypeClass); + $url_logo = ui_get_full_url('index.php'); if (is_reporting_console_node() === true) { $url_logo = 'index.php?logged=1&sec=discovery&sec2=godmode/servers/discovery&wiz=tasklist'; @@ -76,311 +59,400 @@ html_print_div( ), ], true - ), + ).'
', ] ); -require 'operation/menu.php'; -require 'godmode/menu.php'; +$display_classic = ''; +$display_collapsed = 'display: none;'; +if ($menuTypeClass === 'collapsed') { + $display_classic = 'display: none;'; + $display_collapsed = ''; +} -html_print_div( - [ - 'id' => 'button_collapse', - 'class' => sprintf('button_collapse button_%s', $menuTypeClass), - ] -); + +// Tabs. +echo ''; -// Menu_container. -ui_require_jquery_file('cookie'); -$config_fixed_header = false; -if (isset($config['fixed_header']) === true) { - $config_fixed_header = $config['fixed_header']; -} +echo '
'; +require 'operation/menu.php'; +echo '
'; +echo '
'; +require 'godmode/menu.php'; +echo '
'; +echo ''; ?> - - - diff --git a/pandora_console/general/mysqlerr.php b/pandora_console/general/mysqlerr.php index fe24117d3a..6368122da3 100644 --- a/pandora_console/general/mysqlerr.php +++ b/pandora_console/general/mysqlerr.php @@ -1,167 +1,77 @@ - - - - - - -
- -
- - - - /images/icono_cerrar.png'> -
- -
- /images/mysqlerr.png'> -
- -
-
- $value) { - if (preg_match('/._alt/i', $key)) { - $custom_conf_enabled = true; - break; - } +$custom_conf_enabled = false; +foreach ($config as $key => $value) { + if (preg_match('/._alt/i', $key)) { + $custom_conf_enabled = true; + break; } +} - if (!$custom_conf_enabled || isset($config['custom_docs_url_alt'])) { - if (isset($config['custom_docs_url_alt'])) { - $docs_url = $config['custom_docs_url_alt']; - } else { - $docs_url = 'https://pandorafms.com/manual/en/documentation/02_installation/04_configuration'; - } - - echo ' - -
- '.__('Documentation').' - -
-
- '; +if (empty($custom_conf_enabled) === true || isset($config['custom_docs_url_alt']) === true) { + if (isset($config['custom_docs_url_alt']) === true) { + $docs_url = $config['custom_docs_url_alt']; + } else { + $docs_url = 'https://pandorafms.com/manual/en/documentation/02_installation/04_configuration'; } +} + +echo '
'; + echo '
'; + echo '
'; + echo html_print_image('images/mysqlerr.png', true, ['alt' => __('Mysql error'), 'border' => 0]); + echo '
'; + echo '
'; + echo '
'; + echo '

'.__('Database error').'

'; + echo '

'.$message.'

'; + echo '
'; + echo '
'; + echo '
'; + html_print_submit_button( + __('Documentation'), + 'mysqlerr_button', + false, + ['class' => 'mini float-right'] + ); + echo '
'; + echo '
'; + echo '
'; + echo '
'; + ?> - ?> - - - -
- -
- - - diff --git a/pandora_console/general/pandora_help.php b/pandora_console/general/pandora_help.php index 9d0a5e79d6..c78c006a9f 100644 --- a/pandora_console/general/pandora_help.php +++ b/pandora_console/general/pandora_help.php @@ -77,7 +77,7 @@ if (! $id || ! file_exists($help_file)) { echo '
'.__("%s help system has been called with a help reference that currently don't exist. There is no help content to show.", get_product_name()).'
'; echo '

'; echo ''; echo ''; ?> diff --git a/pandora_console/godmode/agentes/agent_conf_gis.php b/pandora_console/godmode/agentes/agent_conf_gis.php index 6b80ed752a..ca213bae37 100644 --- a/pandora_console/godmode/agentes/agent_conf_gis.php +++ b/pandora_console/godmode/agentes/agent_conf_gis.php @@ -59,7 +59,7 @@ ui_print_warning_message( ] ); -$table = new StdClass(); +$table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; $table->data = []; diff --git a/pandora_console/godmode/agentes/agent_incidents.php b/pandora_console/godmode/agentes/agent_incidents.php index 796a3afd77..e7e442e7e3 100644 --- a/pandora_console/godmode/agentes/agent_incidents.php +++ b/pandora_console/godmode/agentes/agent_incidents.php @@ -59,23 +59,22 @@ $result = integria_api_call(null, null, null, null, 'get_incidents', $params, fa $result = json_decode($result, true); -$count = count($result); - -$result = array_slice($result, $offset, $config['block_size']); - -if (empty($result)) { +if (empty($result) === true) { $result = []; $count = 0; echo '
'.__('No incidents associated to this agent').'

'; return; +} else { + $count = count($result); + $result = array_slice($result, $offset, $config['block_size']); } -// Show pagination +// Show pagination. ui_pagination($count, $url, $offset, 0, false, 'offset'); // ($count + $offset) it's real count of incidents because it's use LIMIT $offset in query. echo '
'; -// Show headers +// Show headers. $table->width = '100%'; $table->class = 'databox'; $table->cellpadding = 4; diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 836b68ba68..f524fb7d9e 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -1,11 +1,11 @@ '; echo '
'; // Custom ID. $custom_id_div = '
'; -$custom_id_div .= '

'.__('Custom ID').':

'; +$custom_id_div .= '

'.__('Custom ID').':

'; $custom_id_div .= html_print_input_text( 'custom_id', $custom_id, @@ -209,107 +206,214 @@ $custom_id_div .= html_print_input_text( 'agent_custom_id' ).'
'; -if (!$new_agent && $alias != '') { - $table_agent_name = '

'.__('Agent name').'

'; - $table_agent_name .= '
'; - $table_agent_name .= '
'.html_print_input_text('agente', $nombre_agente, '', 50, 100, true).'
'; - $table_agent_name .= '
'; +// Get groups. +$groups = users_get_groups($config['id_user'], 'AR', false); - if ($id_agente) { - $table_agent_name .= ''; - $table_agent_name .= ''; - $table_agent_name .= html_print_image( - 'images/zoom.png', - true, - [ - 'border' => 0, - 'title' => __('Agent detail'), - 'class' => 'invert_filter', - ] - ); - $table_agent_name .= ''; +// 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 +); +$modules_values = []; +$modules_values[0] = __('Any'); +if (is_array($modules) === true) { + foreach ($modules as $m) { + $modules_values[$m['id_module']] = $m['name']; } +} - $agent_options_update = 'agent_options_update'; - - // Delete link from here. - if (is_management_allowed() === true) { - $table_agent_name .= "".html_print_image( - 'images/cross.png', - true, - [ - 'title' => __('Delete agent'), - 'class' => 'invert_filter', - ] - ).''; - } - - // Remote configuration available. +// Remote configuration available. +if (isset($filename) === true && file_exists($filename['md5']) === true) { + $remote_agent = true; + $agent_md5 = md5(io_safe_output(agents_get_name($id_agente)), false); +} else { $remote_agent = false; - if (isset($filename)) { - if (file_exists($filename['md5'])) { - $remote_agent = true; +} - $agent_name = agents_get_name($id_agente); - $agent_name = io_safe_output($agent_name); - $agent_md5 = md5($agent_name, false); +// Get Servers. +$servers = servers_get_names(); +// Set the agent have not server. +if (array_key_exists($server_name, $servers) === false) { + $server_name = 0; +} - $table_agent_name .= ''; - $table_agent_name .= html_print_image( - 'images/application_edit.png', - true, - [ - 'border' => 0, - 'title' => __('This agent can be remotely configured'), - 'class' => 'invert_filter', - ] - ); - $table_agent_name .= ''; +if ($new_agent === true) { + // Set first server by default. + $servers_get_names = $servers; + $array_keys_servers_get_names = array_keys($servers_get_names); + $server_name = reset($array_keys_servers_get_names); +} + + +// QR Code table. +if ($new_agent === false) { + $CodeQRContent .= html_print_div(['id' => 'qr_container_image'], true); + $CodeQRContent .= html_print_anchor( + [ + 'id' => 'qr_code_agent_view', + 'href' => ui_get_full_url('mobile/index.php?page=agent&id='.$id_agente), + ], + true + ); + $CodeQRContent .= '
'.$custom_id_div; + + // QR code div. + $CodeQRTable = html_print_div( + [ + 'class' => 'agent_qr', + 'content' => $CodeQRContent, + ], + true + ); +} else { + $CodeQRTable = ''; +} + +// Advanced mode. +if (enterprise_installed() === true) { + // Safe operation mode. + if ($new_agent === false) { + $sql_modules = db_get_all_rows_sql( + 'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo + WHERE id_agente = '.$id_agente + ); + $safe_mode_modules = []; + $safe_mode_modules[0] = __('Any'); + if (is_array($sql_modules) === true) { + foreach ($sql_modules as $m) { + $safe_mode_modules[$m['id_module']] = $m['name']; + } } } - $table_agent_name .= '
'; - - // QR code div. - $table_qr_code = '
'; - $table_qr_code .= '

'.__('QR Code Agent view').'

'; - $table_qr_code .= '
'; - if ($id_agente) { - $table_qr_code .= ""; + // Calculate cps value - agents. + if ($new_agent === false) { + $cps_val = service_agents_cps($id_agente); + } else { + // No agent defined, use received cps as base value. + if ($cps >= 0) { + $cps_val = $cps; + } } - // Add Custom id div. - $table_qr_code .= '
'; - $table_qr_code .= $custom_id_div; - $table_qr_code .= '
'; + // Parent agents. + $paramsParentAgent = []; + $paramsParentAgent['return'] = true; + $paramsParentAgent['show_helptip'] = false; + $paramsParentAgent['input_name'] = 'id_parent'; + $paramsParentAgent['print_hidden_input_idagent'] = true; + $paramsParentAgent['hidden_input_idagent_name'] = 'id_agent_parent'; + $paramsParentAgent['hidden_input_idagent_value'] = $id_parent; + $paramsParentAgent['value'] = db_get_value('alias', 'tagente', 'id_agente', $id_parent); + $paramsParentAgent['selectbox_id'] = 'cascade_protection_module'; + $paramsParentAgent['javascript_is_function_select'] = true; + $paramsParentAgent['cascade_protection'] = true; + $paramsParentAgent['input_style'] = 'width: 100%;'; + + if ($id_agente !== 0) { + // Deletes the agent's offspring. + $paramsParentAgent['delete_offspring_agents'] = $id_agente; + } } -if ($new_agent) { - $label_select_child_left = 'label_select_child_left'; - $label_select_parent = 'label_select_parent'; +$listIcons = gis_get_array_list_icons(); + +$arraySelectIcon = []; +foreach ($listIcons as $index => $value) { + $arraySelectIcon[$index] = $index; } -$table_alias = '

'.__('Alias').'

'; -$table_alias .= '
'; -$table_alias .= '
'.html_print_input_text('alias', $alias, '', 50, 100, true, false, true).'
'; -if ($new_agent) { - $table_alias .= '
'.html_print_checkbox_switch('alias_as_name', 1, $config['alias_as_name'], true).__('Use alias as name').'
'; +// Agent icons. +$path = 'images/gis_map/icons/'; +// TODO set better method the path. +$table_adv_agent_icon = '

'.__('Agent icon').'

'; +if ($icon_path == '') { + $display_icons = 'none'; + // Hack to show no icon. Use any given image to fix not found image errors. + $path_without = 'images/spinner.gif'; + $path_default = 'images/spinner.gif'; + $path_ok = 'images/spinner.gif'; + $path_bad = 'images/spinner.gif'; + $path_warning = 'images/spinner.gif'; +} else { + $display_icons = ''; + $path_without = $path.$icon_path.'.default.png'; + $path_default = $path.$icon_path.'.default.png'; + $path_ok = $path.$icon_path.'.ok.png'; + $path_bad = $path.$icon_path.'.bad.png'; + $path_warning = $path.$icon_path.'.warning.png'; } -$table_alias .= '
'; +$tableAgent = new stdClass(); +$tableAgent->class = 'floating_form primary_form'; +$tableAgent->data = []; +$tableAgent->style = []; +$tableAgent->cellclass = []; +$tableAgent->colspan = []; +$tableAgent->rowspan = []; -$table_ip = '

'.__('IP Address').'

'; -$table_ip .= '
'; -$table_ip .= '
'.html_print_input_text('direccion', $direccion_agente, '', 16, 100, true).'
'; -$table_ip .= '
'.html_print_checkbox_switch('unique_ip', 1, $config['unique_ip'], true).__('Unique IP').'
'; -$table_ip .= '
'.html_print_input( +// Agent name. +if ($new_agent === false) { + $tableAgent->data['caption_name'][0] = __('Agent name'); + $tableAgent->rowclass['name'] = 'w540px'; + $tableAgent->cellstyle['name'][0] = 'width: 100%;'; + $tableAgent->data['name'][0] = html_print_input_text('agente', $nombre_agente, '', 76, 100, true, false, false, '', 'w100p'); + $tableAgent->data['name'][0] .= html_print_div( + [ + 'class' => 'moduleIdBox', + 'content' => __('ID').' '.$id_agente.'', + ], + true + ); + // Agent options for QR code. + $agent_options_update = 'agent_options_update'; +} + +// Alias. +$tableAgent->data['caption_alias'][0] = __('Alias'); +$tableAgent->rowclass['alias'] = 'w540px'; +$tableAgent->data['alias'][0] = html_print_input_text('alias', $alias, '', 50, 100, true, false, true, '', 'w540px'); +if ($new_agent === true) { + $tableAgent->rowclass['additional_alias'] = 'subinput'; + $tableAgent->data['additional_alias'][0] = html_print_checkbox_switch('alias_as_name', 1, $config['alias_as_name'], true); + $tableAgent->data['additional_alias'][1] = __('Use alias as name'); +} else { + if ($remote_agent === true) { + $tableAgent->data['alias'][0] .= html_print_anchor( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=remote_configuration&id_agente='.$id_agente.'&disk_conf='.$agent_md5, + 'content' => html_print_image( + 'images/remote-configuration@svg.svg', + true, + [ + 'border' => 0, + 'title' => __('This agent can be remotely configured'), + 'class' => 'invert_filter after_input_icon', + ] + ), + ], + true + ); + } +} + +// Ip adress. +$tableAgent->data['caption_ip_address'] = __('IP Address'); +$tableAgent->rowclass['ip_address'] = 'w540px'; +$tableAgent->data['ip_address'][0] = html_print_input_text('direccion', $direccion_agente, '', 16, 100, true, false, false, '', 'w540px'); + +$tableAgent->rowclass['additional_ip_address'] = 'subinput'; +$tableAgent->data['additional_ip_address'][0] = html_print_checkbox_switch('unique_ip', 1, $config['unique_ip'], true); +$tableAgent->data['additional_ip_address'][1] = __('Unique IP'); +$tableAgent->cellclass['additional_ip_address'][1] = 'w120px'; +$tableAgent->data['additional_ip_address'][2] = html_print_input( [ 'type' => 'switch', 'id' => 'fixed_ip', 'name' => 'fixed_ip', 'value' => $fixed_ip, ] -).__('Fix IP address').'

'.ui_print_help_tip(__('Avoid automatic IP address update when agent IP changes.'), true).'

'; +); $table_ip .= '
'; @@ -336,48 +440,73 @@ $modules = db_get_all_rows_sql( 'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo WHERE id_agente = '.$id_parent ); -$modules_values = []; -$modules_values[0] = __('Any'); -if (is_array($modules)) { - foreach ($modules as $m) { - $modules_values[$m['id_module']] = $m['name']; - } +$tableAgent->data['additional_ip_address'][3] = __('Fix IP address'); +$tableAgent->data['additional_ip_address'][3] .= ui_print_help_tip(__('Avoid automatic IP address update when agent IP changes.'), true); + +// IP Address List. +if ($new_agent === false) { + $tableAgent->data['caption_ip_address_list'] = __('IP Address list'); + $tableAgent->data['ip_address_list'][0] = html_print_select(agents_get_addresses($id_agente), 'address_list', $direccion_agente, '', '', 0, true, false, true, 'w540px'); + $tableAgent->rowclass['additional_ip_address_list'] = 'subinput'; + $tableAgent->data['additional_ip_address_list'][0] = html_print_checkbox_switch('delete_ip', 1, false, true); + $tableAgent->data['additional_ip_address_list'][1] = __('Delete selected IPs'); } -$table_primary_group = '

'.__('Primary group').'

'; -$table_primary_group .= '
'; -// Cannot change primary group if user have not permission for that group. -if (isset($groups[$grupo]) || $new_agent) { - $table_primary_group .= html_print_input( - [ - 'type' => 'select_groups', - 'returnAllGroup' => false, - 'name' => 'grupo', - 'selected' => $grupo, - 'return' => true, - 'required' => true, - 'privilege' => 'AW', - ] +// Select primary group. +$tableAgent->data['caption_primary_group'][0] = __('Primary group'); +if (isset($groups[$grupo]) === true || $new_agent === true) { + $tableAgent->rowclass['primary_group'] = 'w540px'; + // Cannot change primary group if user have not permission for that group. + $tableAgent->data['primary_group'][0] = html_print_select_groups( + false, + 'AW', + false, + 'grupo', + $grupo, + '', + '', + 0, + true, + false, + true, + '', + false, + '', + '', + false, + 'id_grupo', + false, + false, + false, + '540px', + false, + true, ); } else { - $table_primary_group .= groups_get_name($grupo); - $table_primary_group .= html_print_input_hidden('grupo', $grupo, true); + $tableAgent->data['primary_group'][0] .= groups_get_name($grupo); + $tableAgent->data['primary_group'][0] .= html_print_input_hidden('grupo', $grupo, true); } -$table_primary_group .= '
'; -if ($id_agente === 0) { - $hidden = 'display: none;'; -} else { - $hidden = ''; -} +$tableAgent->data['primary_group'][0] .= html_print_div( + [ + 'content' => ui_print_group_icon( + $grupo, + true, + '', + ($id_agente === 0) ? 'display: none;' : '', + true, + false, + false, + 'after_input_icon' + ), + ], + true +); -$table_primary_group .= ui_print_group_icon($grupo, true, 'groups_small', $hidden); - -$table_primary_group .= '
'; - -$table_interval = '

'.__('Interval').'

'; -$table_interval .= '
'; -$table_interval .= html_print_extended_select_for_time( +$tableAgent->data['caption_interval'][0] = __('Interval'); +// $tableAgent->rowstyle['interval'] = 'width: 260px'; +$tableAgent->rowclass['interval'] = 'w540px'; +$tableAgent->data['interval'][0] = html_print_extended_select_for_time( 'intervalo', $intervalo, '', @@ -387,61 +516,82 @@ $table_interval .= html_print_extended_select_for_time( true, false, true, - 'w40p' + 'w33p' ); - - if ($intervalo < SECONDS_5MINUTES) { - $table_interval .= clippy_context_help('interval_agent_min'); + $tableAgent->data['interval'][0] .= clippy_context_help('interval_agent_min'); } -$table_interval .= '
'; - -$table_os = '

'.__('OS').'

'; -$table_os .= '
'; -$table_os .= html_print_select_from_sql( +$tableAgent->data['caption_os'][0] = __('OS'); +$tableAgent->rowclass['os'] = 'w540px'; +$tableAgent->data['os'][0] = html_print_select_from_sql( 'SELECT id_os, name FROM tconfig_os', 'id_os', $id_os, '', '', '0', + true, + false, + true, + false, + 'width: 540px;' +); +$tableAgent->data['os'][0] .= html_print_div( + [ + 'class' => 'after_input_icon', + 'id' => 'os_preview', + 'content' => ui_print_os_icon( + $id_os, + false, + true + ), + ], true ); -$table_os .= '
'; -$table_os .= ui_print_os_icon($id_os, false, true); -$table_os .= '
'; -// Network server. -$servers = servers_get_names(); -// Set the agent have not server. -if (array_key_exists($server_name, $servers) === false) { - $server_name = 0; -} - -$table_server = '

'.__('Server').'

'; -$table_server .= '
'; -if ($new_agent) { - // Set first server by default. - $servers_get_names = $servers; - $array_keys_servers_get_names = array_keys($servers_get_names); - $server_name = reset($array_keys_servers_get_names); -} - -$table_server .= html_print_select( +$tableAgent->data['caption_server'][0] = __('Server'); +$tableAgent->rowclass['server'] = 'w540px'; +$tableAgent->data['server'][0] = html_print_select( $servers, 'server_name', $server_name, '', __('None'), 0, - true -).'
'; + true, + false, + true, + 'w540px', + false, + 'width: 540px;' +); +// Description. +$tableAgent->data['caption_description'][0] = __('Description'); +$tableAgent->rowclass['description'] = 'w540px'; +$tableAgent->data['description'][0] = html_print_textarea( + 'comentarios', + 3, + 80, + $comentarios, + '', + true, + 'agent_description w540px' +); -$table_satellite = ''; -if ($remote_agent === true) { +html_print_div( + [ + 'class' => 'box-flat white_table_flex white_box agent_details_col', + 'style' => 'display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px', + 'content' => html_print_table($tableAgent, true).$CodeQRTable, + ] +); +/* + TODO REVIEW + $table_satellite = ''; + if ($remote_agent === true) { // Satellite server selector. $satellite_servers = db_get_all_rows_filter( 'tserver', @@ -473,148 +623,70 @@ if ($remote_agent === true) { ] ).'
'; } -} + } +*/ -// Description. -$table_description = '

'.__('Description').'

'; -$table_description .= html_print_textarea( - 'comentarios', - 3, - 10, - $comentarios, - '', - true, - 'agent_description' -).'
'; - -// QR code. -echo '
-
-
'.$table_agent_name.$table_alias.$table_ip.$table_primary_group.'
-
'.$table_interval.$table_os.$table_server.$table_satellite.$table_description.'
-
'; -if (!$new_agent && $alias != '') { - echo $table_qr_code; -} - -echo '
'; - -if (enterprise_installed()) { - $adv_secondary_groups_label = '
'; - $adv_secondary_groups_label .= '

'; - $adv_secondary_groups_label .= __('Secondary groups'); - $adv_secondary_groups_label .= '

'; - $adv_secondary_groups_label .= '
'; - $select_agent_secondary = html_print_select_agent_secondary( +// Advanced options. +$tableAdvancedAgent = new stdClass(); +$tableAdvancedAgent->class = 'filter-table-adv floating_form primary_form'; +$tableAdvancedAgent->data = []; +$tableAdvancedAgent->style = []; +$tableAdvancedAgent->cellclass = []; +$tableAdvancedAgent->colspan = []; +$tableAdvancedAgent->rowspan = []; +// Secondary groups. +$tableAdvancedAgent->data['secondary_groups'][] = html_print_label_input_block( + __('Secondary groups'), + html_print_select_agent_secondary( $agent, $id_agente - ); + ) +); - // Safe operation mode. - if ($id_agente) { - $sql_modules = db_get_all_rows_sql( - 'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo - WHERE id_agente = '.$id_agente - ); - $safe_mode_modules = []; - $safe_mode_modules[0] = __('Any'); - if (is_array($sql_modules)) { - foreach ($sql_modules as $m) { - $safe_mode_modules[$m['id_module']] = $m['name']; - } - } - - $table_adv_safe = '

'.__('Safe operation mode').'

'; - $table_adv_safe .= html_print_checkbox_switch('safe_mode', 1, $safe_mode, true); - $table_adv_safe .= __('Module').' '.html_print_select($safe_mode_modules, 'safe_mode_module', $safe_mode_module, '', '', 0, true).'
'; - } - - // Remote configuration. - $table_adv_remote = '

'.__('Remote configuration').'

'; - - if (!$new_agent && isset($filename) && file_exists($filename['md5'])) { - $table_adv_remote .= date('F d Y H:i:s', fileatime($filename['md5'])); - // Delete remote configuration. - $table_adv_remote .= ''; - $table_adv_remote .= html_print_image( - 'images/cross.png', - true, - [ - 'title' => __('Delete remote configuration file'), - 'style' => 'vertical-align: middle;', - 'class' => 'invert_filter', - ] - ).''; - $table_adv_remote .= ''; - } else { - $table_adv_remote .= ''.__('Not available').''; - } - - $table_adv_remote .= '
'; +// Parent agent. +$tableAdvancedAgent->data['parent_agent'][] = html_print_label_input_block( + __('Parent'), + ui_print_agent_autocomplete_input($paramsParentAgent) +); - // Calculate cps value - agents. - if ($id_agente) { - $cps_val = service_agents_cps($id_agente); - } else { - // No agent defined, use received cps as base value. - if ($cps >= 0) { - $cps_val = $cps; - } - } - - $cps_html = '
'; - $cps_html .= html_print_checkbox_switch('cps', $cps_val, ($cps >= 0), true); - $cps_html .= __('Cascade protection services').' '; - $cps_html .= '
'; - - $table_adv_cascade .= $cps_html; -} - -$table_adv_parent = '
'; -$params = []; -$params['return'] = true; -$params['show_helptip'] = true; -$params['input_name'] = 'id_parent'; -$params['print_hidden_input_idagent'] = true; -$params['hidden_input_idagent_name'] = 'id_agent_parent'; -$params['hidden_input_idagent_value'] = $id_parent; -$params['value'] = db_get_value('alias', 'tagente', 'id_agente', $id_parent); -$params['selectbox_id'] = 'cascade_protection_module'; -$params['javascript_is_function_select'] = true; -$params['cascade_protection'] = true; -if ($id_agente !== 0) { - // Deletes the agent's offspring. - $params['delete_offspring_agents'] = $id_agente; -} - -$table_adv_parent .= '
'; -$table_adv_parent .= ui_print_agent_autocomplete_input($params); -if (enterprise_installed()) { - $table_adv_parent .= html_print_checkbox_switch( +if (enterprise_installed() === true) { + $cascadeProtectionContents = []; + $cascadeProtectionContents[] = html_print_checkbox_switch( 'cascade_protection', 1, $cascade_protection, true - ).__('Cascade protection').' '; + ); - $table_adv_parent .= __('Module').' '.html_print_select( + $cascadeProtectionContents[] = html_print_select( $modules_values, 'cascade_protection_module', $cascade_protection_module, '', '', 0, - true + true, + false, + true, + 'w220p' + ); + + $tableAdvancedAgent->data['caption_cascade_protection'][] = html_print_label_input_block( + __('Cascade protection modules'), + html_print_div( + [ + 'class' => 'flex-row-center', + 'content' => implode('', $cascadeProtectionContents), + ], + true + ) ); } -$table_adv_parent .= '
'; - -// Learn mode / Normal mode. -$table_adv_module_mode = '

'.__('Module definition').'

'; -$table_adv_module_mode .= '
'; -$table_adv_module_mode .= html_print_radio_button_extended( +// Module Definition (Learn mode). +$switchButtons = []; +$switchButtons[] = html_print_radio_button_extended( 'modo', 1, __('Learning mode'), @@ -624,7 +696,7 @@ $table_adv_module_mode .= html_print_radio_button_extended( '', true ); -$table_adv_module_mode .= html_print_radio_button_extended( +$switchButtons[] = html_print_radio_button_extended( 'modo', 0, __('Normal mode'), @@ -634,7 +706,7 @@ $table_adv_module_mode .= html_print_radio_button_extended( '', true ); -$table_adv_module_mode .= html_print_radio_button_extended( +$switchButtons[] = html_print_radio_button_extended( 'modo', 2, __('Autodisable mode'), @@ -644,23 +716,73 @@ $table_adv_module_mode .= html_print_radio_button_extended( '', true ); -$table_adv_module_mode .= '
'; -// Status (Disabled / Enabled). -$table_adv_status = '
'; -$table_adv_status .= html_print_checkbox_switch( - 'disabled', - 1, - $disabled, - true +$tableAdvancedAgent->data['module_definition'][] = html_print_label_input_block( + __('Module definition'), + html_print_div( + [ + 'class' => 'switch_radio_button', + 'content' => implode('', $switchButtons), + ], + true + ) +); + +// CPS - Cascade Protection Services. +$tableAdvancedAgent->data['cps_value'][] = html_print_label_input_block( + __('Cascade protection services'), + html_print_checkbox_switch('cps', $cps_val, ($cps >= 0), true) +); + +// Update GIS data. +if ((bool) $config['activate_gis'] === true) { + $tableAdvancedAgent->data['gis'][] = html_print_label_input_block( + __('Update new GIS data'), + html_print_checkbox_switch('update_gis_data', 1, ($new_agent === true), true) + ); +} + +// Agent Icons. +$tableAdvancedAgent->data['agent_icon'][] = html_print_label_input_block( + __('Agent icon'), + html_print_select( + $arraySelectIcon, + 'icon_path', + $icon_path, + 'changeIcons();', + __('None'), + '', + true, + false, + true, + 'w540px' + ).html_print_image( + $path_ok, + true, + [ + 'id' => 'icon_ok', + 'style' => 'display:'.$display_icons.';', + ] + ).html_print_image( + $path_bad, + true, + [ + 'id' => 'icon_bad', + 'style' => 'display:'.$display_icons.';', + ] + ).html_print_image( + $path_warning, + true, + [ + 'id' => 'icon_warning', + 'style' => 'display:'.$display_icons.';', + ] + ) ); -$table_adv_status .= '

'.__('Disabled mode').'

'; -$table_adv_status .= '
'; // Url address. -if (enterprise_installed()) { - $table_adv_url = '

'.__('Url address').'

'; - $table_adv_url .= html_print_input_text( +if (enterprise_installed() === true) { + $urlAddressInput = html_print_input_text( 'url_description', $url_description, '', @@ -670,152 +792,131 @@ if (enterprise_installed()) { false, false, '', - '', + 'w540px', '', // Autocomplete. 'new-password' - ).'
'; + ); } else { - $table_adv_url = '

'.__('Url address').'

'; - $table_adv_url .= html_print_input_text( + $urlAddressInput = html_print_input_text( 'url_description', $url_description, '', 45, 255, true - ).''; + ); } -$table_adv_quiet = '
'; -$table_adv_quiet .= html_print_checkbox_switch('quiet', 1, $quiet, true); -$table_adv_quiet .= '

'.__('Quiet').'

'; -$table_adv_quiet .= '
'; +$tableAdvancedAgent->data['url_description'][] = html_print_label_input_block( + __('URL Address'), + $urlAddressInput +); -$listIcons = gis_get_array_list_icons(); +// Agent status. +$tableAdvancedAgent->data['agent_status'][] = html_print_label_input_block( + __('Disabled mode'), + html_print_checkbox_switch( + 'disabled', + 1, + $disabled, + true + ) +); -$arraySelectIcon = []; -foreach ($listIcons as $index => $value) { - $arraySelectIcon[$index] = $index; +// Quiet mode. +$tableAdvancedAgent->data['agent_quiet'][] = html_print_label_input_block( + __('Quiet'), + html_print_checkbox_switch('quiet', 1, $quiet, true) +); + +// Remote configuration. +if ($new_agent === false && isset($filename) === true && file_exists($filename['md5']) === true) { + $remoteConfigurationElements = []; + $remoteConfigurationElements[] = html_print_input_text( + 'remote_file_timestamp', + date('F d Y H:i:s', fileatime($filename['md5'])), + '', + 0, + 100, + true, + true, + false, + '', + 'w540px' + ); + $remoteConfigurationElements[] = html_print_anchor( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&disk_conf_delete=1&id_agente='.$id_agente, + 'content' => html_print_image( + 'images/delete.svg', + true, + [ + 'border' => 0, + 'title' => __('Delete remote configuration file'), + 'class' => 'invert_filter after_input_icon', + ] + ), + ], + true + ); + + $tableAdvancedAgent->data['remote_configuration'][] = html_print_label_input_block( + __('Remote configuration'), + html_print_div( + [ + 'class' => 'flex-row-center', + 'content' => implode('', $remoteConfigurationElements), + ], + true + ) + ); } -$path = 'images/gis_map/icons/'; -// TODO set better method the path. -$table_adv_agent_icon = '

'.__('Agent icon').'

'; -if ($icon_path == '') { - $display_icons = 'none'; - // Hack to show no icon. Use any given image to fix not found image errors. - $path_without = 'images/spinner.gif'; - $path_default = 'images/spinner.gif'; - $path_ok = 'images/spinner.gif'; - $path_bad = 'images/spinner.gif'; - $path_warning = 'images/spinner.gif'; -} else { - $display_icons = ''; - $path_without = $path.$icon_path.'.default.png'; - $path_default = $path.$icon_path.'.default.png'; - $path_ok = $path.$icon_path.'.ok.png'; - $path_bad = $path.$icon_path.'.bad.png'; - $path_warning = $path.$icon_path.'.warning.png'; -} - -$table_adv_agent_icon .= html_print_select( - $arraySelectIcon, - 'icon_path', - $icon_path, - 'changeIcons();', - __('None'), - '', +// Safe operation mode. +$safeOperationElements = []; +$safeOperationElements[] = html_print_checkbox_switch( + 'safe_mode', + 1, + $safe_mode, true -).html_print_image( - $path_ok, - true, - [ - 'id' => 'icon_ok', - 'style' => 'display:'.$display_icons.';', - ] -).html_print_image( - $path_bad, - true, - [ - 'id' => 'icon_bad', - 'style' => 'display:'.$display_icons.';', - ] -).html_print_image( - $path_warning, - true, - [ - 'id' => 'icon_warning', - 'style' => 'display:'.$display_icons.';', - ] -).'
'; +); +$safeOperationElements[] = html_print_select( + $safe_mode_modules, + 'safe_mode_module', + $safe_mode_module, + '', + '', + 0, + true +); -if ($config['activate_gis']) { - $table_adv_gis = '

'.__('Update new GIS data:').'

'; - if ($new_agent) { - $update_gis_data = true; - } +$tableAdvancedAgent->data['safe_operation'][] = html_print_label_input_block( + __('Safe operation mode'), + html_print_div( + [ + 'class' => 'flex-row-center', + 'content' => implode('', $safeOperationElements), + ], + true + ) +); - $table_adv_gis .= html_print_checkbox_switch('update_gis_data', 1, $update_gis_data, true).'No / Yes
'; -} - - -if (enterprise_installed()) { - $advanced_div = '
'; -} else { - $advanced_div = ''; - -$table_adv_options .= '
'; -$table_adv_options .= $table_adv_parent; -$table_adv_options .= $table_adv_module_mode; -$table_adv_options .= $table_adv_cascade; - -if ($new_agent) { - // If agent is new, show custom id as old style format. - $table_adv_options .= $custom_id_div; -} - -$table_adv_options .= '
'; - -$table_adv_options .= ' -
- '.$table_adv_gis.$table_adv_agent_icon.$table_adv_url.$table_adv_quiet.$table_adv_status.$table_adv_remote.$table_adv_safe.' -
'; - -if (enterprise_installed()) { - echo '
'; +if (enterprise_installed() === true) { ui_toggle( - $table_adv_options, - __('Advanced options'), + html_print_table($tableAdvancedAgent, true), + ''.__('Advanced options').'', '', '', true, false, - 'white_box white_box_opened', - 'no-border flex' + 'white_box_content', + 'no-border white_table_graph' ); - echo '
'; } -$table = new stdClass(); -$table->width = '100%'; -$table->class = 'custom_fields_table'; - -$table->head = [ - 0 => __('Click to display'), -]; -$table->class = 'info_table'; -$table->style = []; -$table->style[0] = 'font-weight: bold;'; -$table->data = []; -$table->rowstyle = []; +// Custom fields. +$customOutputData = ''; $fields = db_get_all_fields_in_table('tagent_custom_fields'); @@ -823,13 +924,8 @@ if ($fields === false) { $fields = []; } -$i = 0; foreach ($fields as $field) { - $id_custom_field = $field['id_field']; - - $data[0] = '
'; - $data[0] .= ''.$field['name'].''; - $data[0] .= '
'; + // Filling the data. $combo = []; $combo = $field['combo_values']; $combo = explode(',', $combo); @@ -851,15 +947,8 @@ foreach ($fields as $field) { $custom_value = ''; } - $table->rowstyle[$i] = 'cursor: pointer;user-select: none;'; - if (!empty($custom_value)) { - $table->rowstyle[($i + 1)] = 'display: table-row;'; - } else { - $table->rowstyle[($i + 1)] = 'display: none;'; - } - - if ($field['is_password_type']) { - $data_field[1] = html_print_input_text_extended( + if ((bool) $field['is_password_type'] === true) { + $customContent = html_print_input_text_extended( 'customvalue_'.$field['id_field'], $custom_value, 'customvalue_'.$field['id_field'], @@ -887,7 +976,7 @@ foreach ($fields as $field) { 2, 65, $link_text, - 'class="min-height-30px', + 'class="min-height-30px w100p"', true ); $data_field[1] .= '
'; @@ -898,22 +987,22 @@ foreach ($fields as $field) { 2, 65, $link_url, - 'class="min-height-30px', + 'class="min-height-30px w100p"', true ); } else { - $data_field[1] = html_print_textarea( + $customContent = html_print_textarea( 'customvalue_'.$field['id_field'], 2, 65, $custom_value, - 'class="min-height-30px', + 'class="min-height-30px w100p"', true ); } - if ($field['combo_values'] !== '') { - $data_field[1] = html_print_input( + if (empty($field['combo_values']) === false) { + $customContent = html_print_input( [ 'type' => 'select_search', 'fields' => $combo_values, @@ -929,61 +1018,32 @@ foreach ($fields as $field) { ); }; - $table->rowid[] = 'name_field-'.$id_custom_field; - $table->data[] = $data; - - $table->rowid[] = 'field-'.$id_custom_field; - $table->data[] = $data_field; - $i += 2; + $customOutputData .= ui_toggle( + html_print_div( + [ 'content' => $customContent ], + true + ), + $field['name'], + $field['name'], + 'custom_field_toggle_'.$field['id_field'], + true, + true, + ); } -if (enterprise_installed()) { - if (!empty($fields)) { - echo '
'; - ui_toggle( - html_print_table($table, true), - __('Custom fields'), - '', - '', - true, - false, - 'white_box white_box_opened', - 'no-border' - ); - echo '
'; - } -} else { - echo '
'; +if (empty($fields) === false) { ui_toggle( - $table_adv_options, - __('Advanced options'), + $customOutputData, + ''.__('Custom fields').'', '', '', true, false, - 'white_box white_box_opened', - 'no-border flex' + 'white_box white_box_opened white_table_graph_fixed', + 'no-border custom_fields_elements' ); - if (!empty($fields)) { - ui_toggle( - html_print_table($table, true), - __('Custom fields'), - '', - '', - true, - false, - 'white_box white_box_opened', - 'no-border' - ); - } - - echo '
'; - - echo '
'; } -echo '
'; - // The context help about the learning mode. if ($modo == 0) { echo ""; @@ -994,28 +1054,51 @@ if ($modo == 0) { echo clippy_context_help('modules_not_learning_mode'); echo ''; - -if ($id_agente) { - echo '
'; - html_print_submit_button( +if ($new_agent === false) { + $actionButtons = html_print_submit_button( __('Update'), 'updbutton', false, - 'class="sub upd"' + [ 'icon' => 'update'], + true ); - html_print_input_hidden('update_agent', 1); - html_print_input_hidden('id_agente', $id_agente); + $actionButtons .= html_print_input_hidden('update_agent', 1); + $actionButtons .= html_print_input_hidden('id_agente', $id_agente); + + if (is_management_allowed() === true) { + $actionButtons .= html_print_button( + __('Delete agent'), + 'deleteAgent', + false, + 'deleteAgentDialog('.$id_agente.')', + [ + 'icon' => 'delete', + 'mode' => 'secondary dialog_opener', + ], + true + ); + } } else { - html_print_submit_button( + $actionButtons = html_print_input_hidden('create_agent', 1); + $actionButtons .= html_print_submit_button( __('Create'), 'crtbutton', false, - 'class="sub wand"' + [ 'icon' => 'wand'], + true ); - html_print_input_hidden('create_agent', 1); } -echo '
'; +$actionButtons .= html_print_go_back_button( + 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente', + ['button_class' => ''], + true +); + +html_print_action_buttons($actionButtons, ['type' => 'form_action']); + +echo '
'; +echo ''; ui_require_jquery_file('pandora.controls'); ui_require_jquery_file('ajaxqueue'); @@ -1035,6 +1118,15 @@ ui_require_jquery_file('bgiframe'); } } + function deleteAgentDialog($idAgente) { + confirmDialog({ + title: "", + message: "", + onAccept: function() { + window.location.assign('index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&borrar_agente='+$idAgente); + } + }); + } //Use this function for change 3 icons when change the selectbox function changeIcons() { diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 933b37fbce..ea5c8176c8 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -1,20 +1,35 @@ $id_agente, 'id_tipo_modulo' => $row2['type'], @@ -113,14 +129,14 @@ if (isset($_POST['template_id'])) { $name = $row2['name']; - // Put tags in array if the component has to add them later - if (!empty($row2['tags'])) { + // Put tags in array if the component has to add them later. + if (empty($row2['tags']) === false) { $tags = explode(',', $row2['tags']); } else { $tags = []; } - // Check if this module exists in the agent + // Check if this module exists in the agent. $module_name_check = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['delete_pending' => 0, 'nombre' => $name, 'id_agente' => $id_agente]); if ($module_name_check !== false) { @@ -132,13 +148,13 @@ if (isset($_POST['template_id'])) { if ($id_agente_modulo === false) { $error_count++; } else { - if (!empty($tags)) { - // Creating tags + if (empty($tags) === false) { + // Creating tags. $tag_ids = []; foreach ($tags as $tag_name) { $tag_id = tags_get_id($tag_name); - // If tag exists in the system we store to create it + // If tag exists in the system we store to create it. $tag_ids[] = $tag_id; } @@ -152,7 +168,7 @@ if (isset($_POST['template_id'])) { } if ($error_count > 0) { - if (empty($modules_already_added)) { + if (empty($modules_already_added) === true) { ui_print_error_message(__('Error adding modules').sprintf(' (%s)', $error_count)); } else { ui_print_error_message(__('Error adding modules. The following errors already exists: ').implode(', ', $modules_already_added)); @@ -168,8 +184,6 @@ if (isset($_POST['template_id'])) { // ========================== // TEMPLATE ASSIGMENT FORM // ========================== -echo '
'; - $nps = db_get_all_fields_in_table('tnetwork_profile', 'name'); if ($nps === false) { $nps = []; @@ -180,44 +194,45 @@ foreach ($nps as $row) { $select[$row['id_np']] = $row['name']; } -echo ''; -echo "'; -echo ''; -echo ''; -echo ''; -echo '
"; -html_print_select($select, 'template_id', '', '', '', 0, false, false, true, '', false, 'max-width: 200px !important'); -echo ''; -html_print_submit_button(__('Assign'), 'crt', false, 'class="sub next mgn_tp_0"'); -echo '
'; -echo ''; +$filterTable = new stdClass(); +$filterTable->width = '100%'; +$filterTable->class = 'fixed_filter_bar'; +$filterTable->data = []; +$filterTable->data[0][0] = __('Module templates'); +$filterTable->data[1][0] = html_print_select($select, 'template_id', '', '', '', 0, true, false, true, '', false, 'max-width: 200px !important'); +$filterTable->data[1][1] = html_print_div( + [ + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + __('Assign'), + 'crt', + false, + [ + 'icon' => 'wand', + 'mode' => 'secondary mini', + ], + true + ), + ], + true +); + +$outputFilterTable = '
'; +$outputFilterTable .= html_print_table($filterTable, true); +$outputFilterTable .= '
'; + +echo $outputFilterTable; // ========================== // MODULE VISUALIZATION TABLE // ========================== -switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $sql = sprintf( - 'SELECT * - FROM tagente_modulo - WHERE id_agente = %d AND delete_pending = false - ORDER BY id_module_group, nombre', - $id_agente - ); - break; - - case 'oracle': - $sql = sprintf( - 'SELECT * - FROM tagente_modulo - WHERE id_agente = %d - AND (delete_pending <> 1 AND delete_pending IS NOT NULL) - ORDER BY id_module_group, dbms_lob.substr(nombre,4000,1)', - $id_agente - ); - break; -} +$sql = sprintf( + 'SELECT * + FROM tagente_modulo + WHERE id_agente = %d AND delete_pending = false + ORDER BY id_module_group, nombre', + $id_agente +); $result = db_get_all_rows_sql($sql); if ($result === false) { @@ -233,10 +248,10 @@ $table->head = []; $table->data = []; $table->align = []; -$table->head[0] = __('Module name'); -$table->head[1] = __('Type'); -$table->head[2] = __('Description'); -$table->head[3] = __('Action'); +$table->head[0] = ''.__('Module name').''; +$table->head[1] = ''.__('Type').''; +$table->head[2] = ''.__('Description').''; +$table->head[3] = ''.__('Action').''; $table->align[1] = 'left'; $table->align[3] = 'left'; @@ -245,27 +260,43 @@ $table->size[1] = '5%'; $table->size[3] = '8%'; foreach ($result as $row) { + $table->cellclass[][3] = 'table_action_buttons'; + $data = []; $data[0] = ''.$row['nombre']; - if ($row['id_tipo_modulo'] > 0) { - $data[1] = html_print_image('images/'.modules_show_icon_type($row['id_tipo_modulo']), true, ['border' => '0', 'class' => 'invert_filter']); - } else { - $data[1] = ''; - } - + $data[1] = ($row['id_tipo_modulo'] > 0) ? ui_print_moduletype_icon($row['id_tipo_modulo'], true, false, true) : ''; $data[2] = mb_substr($row['descripcion'], 0, 60); - - $table->cellclass[][3] = 'action_buttons'; - $data[3] = ''.html_print_image('images/cross.png', true, ['class' => 'invert_filter', 'border' => '0', 'alt' => __('Delete'), 'onclick' => "if (!confirm('".__('Are you sure?')."')) return false;"]).''; - $data[3] .= ''.html_print_image('images/config.png', true, ['class' => 'invert_filter', 'border' => '0', 'alt' => __('Update')]).''; + $data[3] = html_print_menu_button( + [ + 'href' => 'index.php?sec=gagente&tab=module&sec2=godmode/agentes/configurar_agente&tab=template&id_agente='.$id_agente.'&delete_module='.$row['id_agente_modulo'], + 'image' => 'images/delete.svg', + 'title' => __('Delete'), + 'onClick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', + ], + true + ); + $data[3] .= html_print_menu_button( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&tab=module&edit_module=1&id_agent_module='.$row['id_agente_modulo'], + 'image' => 'images/edit.svg', + 'title' => __('Edit'), + ], + true + ); array_push($table->data, $data); } -if (!empty($table->data)) { - html_print_table($table); - unset($table); +if (empty($table->data) === false) { + $output = html_print_table($table, true); } else { - ui_print_empty_data(__('No modules')); + $output = ui_print_empty_data(__('No modules'), '', true); } + +html_print_div( + [ + 'class' => 'datatable_form', + 'content' => $output, + ] +); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index ab01bbf47f..27f3b7ea3a 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -295,7 +295,6 @@ if ($create_agent) { 'fixed_ip' => $fixed_ip, ] ); - enterprise_hook('update_agent', [$id_agente]); } else { $id_agente = false; } @@ -377,86 +376,89 @@ $img_style = [ if ($id_agente) { // View tab. - $viewtab['text'] = ''.html_print_image( - 'images/eye.png', - true, + $viewtab['text'] = html_print_anchor( [ - 'title' => __('View'), - 'class' => 'invert_filter', - ] - ).''; - - if ($tab == 'view') { - $viewtab['active'] = true; - } else { - $viewtab['active'] = false; - } + 'href' => 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente, + 'content' => html_print_image( + 'images/enable.svg', + true, + [ + 'title' => __('View'), + 'class' => 'invert_filter main_menu_icon', + ] + ), + ], + true + ); + $viewtab['active'] = ($tab === 'view'); $viewtab['operation'] = 1; // Main tab. - $maintab['text'] = ''.html_print_image( - 'images/gm_setup.png', - true, + $maintab['text'] = html_print_anchor( [ - 'title' => __('Setup'), - 'class' => 'invert_filter', - ] - ).''; - if ($tab == 'main') { - $maintab['active'] = true; - } else { - $maintab['active'] = false; - } + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente='.$id_agente, + 'content' => html_print_image( + 'images/configuration@svg.svg', + true, + [ + 'title' => __('Setup'), + 'class' => 'invert_filter main_menu_icon', + ] + ), + ], + true + ); + + $maintab['active'] = ($tab === 'main'); // Module tab. - $moduletab['text'] = ''.html_print_image( - 'images/gm_modules.png', - true, + $moduletab['text'] = html_print_anchor( [ - 'title' => __('Modules'), - 'class' => 'invert_filter', - ] - ).''; + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$id_agente, + 'content' => html_print_image( + 'images/modules@svg.svg', + true, + [ + 'title' => __('Modules'), + 'class' => 'invert_filter main_menu_icon', + ] + ), + ], + true + ); - if ($tab == 'module') { - $moduletab['active'] = true; - } else { - $moduletab['active'] = false; - } + $moduletab['active'] = ($tab === 'module'); // Alert tab. - $alerttab['text'] = ''.html_print_image( - 'images/gm_alerts.png', - true, + $alerttab['text'] = html_print_anchor( [ - 'title' => __('Alerts'), - 'class' => 'invert_filter', - ] - ).''; + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$id_agente, + 'content' => html_print_image( + 'images/alert@svg.svg', + true, + [ + 'title' => __('Alerts'), + 'class' => 'invert_filter main_menu_icon', + ] + ), + ], + true + ); - if ($tab == 'alert') { - $alerttab['active'] = true; - } else { - $alerttab['active'] = false; - } + $alerttab['active'] = ($tab === 'alert'); // Template tab. - $templatetab['text'] = ''.html_print_image( - 'images/templates.png', - true, + $templatetab['text'] = html_print_menu_button( [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=template&id_agente='.$id_agente, + 'image' => 'images/modules-group@svg.svg', 'title' => __('Module templates'), - 'class' => 'invert_filter', - ] - ).''; - - if ($tab == 'template') { - $templatetab['active'] = true; - } else { - $templatetab['active'] = false; - } + ], + true + ); + $templatetab['active'] = ($tab === 'template'); // Inventory. $inventorytab['text'] = ''.html_print_image( @@ -474,11 +476,11 @@ if ($id_agente) { $inventorytab['active'] = false; } - if ($inventorytab == -1) { + $inventorytab = enterprise_hook('inventory_tab'); + if ($inventorytab === ENTERPRISE_NOT_HOOK) { $inventorytab = ''; } - $has_remote_conf = enterprise_hook( 'config_agents_has_remote_configuration', [$id_agente] @@ -490,7 +492,7 @@ if ($id_agente) { if ($has_remote_conf === true) { // Plugins. $pluginstab = enterprise_hook('plugins_tab'); - if ($pluginstab == -1) { + if ($pluginstab === ENTERPRISE_NOT_HOOK) { $pluginstab = ''; } } else { @@ -500,60 +502,60 @@ if ($id_agente) { // Collection. if ((int) $config['license_nms'] !== 1) { $collectiontab = enterprise_hook('collection_tab'); - - if ($collectiontab == -1) { + if ($collectiontab === ENTERPRISE_NOT_HOOK) { $collectiontab = ''; } + } else { + $collectiontab = ''; } // NetworkConfigManager tab. $ncm_tab = enterprise_hook('networkconfigmanager_tab'); - if ($ncm_tab === ENTERPRISE_NOT_HOOK) { $ncm_tab = ''; } // Group tab. - $grouptab['text'] = ''.html_print_image( - 'images/group.png', - true, + $grouptab['text'] = html_print_menu_button( [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&ag_group='.$group, + 'image' => 'images/groups@svg.svg', 'title' => __('Group'), - 'class' => 'invert_filter', - ] - ).''; + ], + true + ); $grouptab['active'] = false; $gistab = []; - // GIS tab. - if ($config['activate_gis']) { - $gistab['text'] = ''.html_print_image( - 'images/gm_gis.png', - true, - [ - 'title' => __('GIS data'), - 'class' => 'invert_filter', - ] - ).''; + // TODO. OVERRIDE. + $config['activate_gis'] = true; - if ($tab == 'gis') { - $gistab['active'] = true; - } else { - $gistab['active'] = false; - } + // GIS tab. + if ((bool) $config['activate_gis'] === true) { + $gistab['text'] = html_print_menu_button( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=gis&id_agente='.$id_agente, + 'image' => 'images/poi@svg.svg', + 'title' => __('GIS data'), + ], + true + ); + + $gistab['active'] = ($tab === 'gis'); } // Agent wizard tab. - $agent_wizard['text'] = ''.html_print_image( - 'images/wand_agent.png', - true, + $agent_wizard['text'] = html_print_menu_button( [ + 'href' => 'javascript:', + 'class' => 'agent_wizard_tab', + 'image' => 'images/wizard@svg.svg', 'title' => __('Agent wizard'), - 'class' => 'invert_filter', - ] - ).''; + ], + true + ); // Hidden subtab layer. $agent_wizard['sub_menu'] = '
'; } -echo '
'; +echo '
'; +echo ''; if (!$id) { $user_id_update_view = $user_id; @@ -1637,71 +1702,139 @@ if (!$id) { if (is_metaconsole() === true) { $access_or_pagination = $meta_access; -} else { - $access_or_pagination = $size_pagination; -} + if ($id != '' && !$is_err) { + $div_user_info = ' + '; + } else { + $div_user_info = ' + '; + } -if ($id != '' && !$is_err) { - $div_user_info = ' - '; -} else { - $div_user_info = ' - '; -} + echo '
+
+ +

Extra info

'.$email.$phone.$not_login.$local_user.$session_time.'
+
+
+
'.$language.$access_or_pagination.$skin.$default_event_filter.$double_authentication.'
+ +
'.$timezone; -echo '
-
- -

Extra info

'.$email.$phone.$not_login.$local_user.$session_time.'
-
-
-
'.$language.$access_or_pagination.$skin.$home_screen.$default_event_filter.$double_authentication.'
- -
'.$timezone; -if (is_metaconsole() === false) { - echo '
- - - '.$area_data_timezone_polys.$area_data_timezone_rects.' -
'; -} else { echo $search_custom_fields_view.$metaconsole_agents_manager.$metaconsole_access_node; -} -echo '
-
+ $autorefresh_show = '

'._('Autorefresh').ui_print_help_tip( + __('This will activate autorefresh in selected pages'), + true + ).'

'; + $select_out = html_print_select( + $autorefresh_list_out, + 'autorefresh_list_out[]', + '', + '', + '', + '', + true, + true, + true, + '', + false, + 'width:100%' + ); + $arrows = ' '; + $select_in = html_print_select( + $autorefresh_list, + 'autorefresh_list[]', + '', + '', + '', + '', + true, + true, + true, + '', + false, + 'width:100%' + ); -
-
'.$comments.'
-
'; + $table_ichanges = ''; -html_print_div( - [ - 'class' => 'user_edit_third_row white_box', - 'content' => html_print_div( + $autorefresh_show .= $table_ichanges; + + // Time autorefresh. + $times = get_refresh_time_array(); + $time_autorefresh = '

'.__('Time autorefresh'); + $time_autorefresh .= ui_print_help_tip( + __('Interval of autorefresh of the elements, by default they are 30 seconds, needing to enable the autorefresh first'), + true + ).'

'; + $time_autorefresh .= html_print_select( + $times, + 'time_autorefresh', + $user_info['time_autorefresh'], + '', + '', + '', + true, + false, + false + ).'
'; + + + echo '
+
+
'.$autorefresh_show.$time_autorefresh.'
+
+
'.$comments.'
+
'; + + if (empty($ehorus) === false) { + html_print_div( [ - 'class' => 'edit_user_allowed_ip', - 'content' => $allowedIP, + 'class' => 'user_edit_third_row white_box', + 'content' => $ehorus, ], true - ), - ] -); - -if (!empty($ehorus)) { - echo '
'.$ehorus.'
'; + ); + } +} else { + $access_or_pagination = $size_pagination; + // WIP: Only for node. + include_once 'user_management.php'; } -echo '
'; -echo '
'; -if ($config['admin_can_add_user']) { +if ((bool) $config['admin_can_add_user'] === true) { html_print_csrf_hidden(); - if ($new_user) { - html_print_input_hidden('create_user', 1); - } else { - html_print_input_hidden('update_user', 1); - } + html_print_input_hidden((($new_user === true) ? 'create_user' : 'update_user'), 1); } echo '
'; @@ -1709,42 +1842,49 @@ if ($new_user === true) { html_print_input_hidden('json_profile', $json_profile); } +echo '
'; echo ''; +echo '
'; -if ($is_err === true && $new_user === true) { - profile_print_profile_table($id, io_safe_output($json_profile), false, true); -} else { - profile_print_profile_table($id, io_safe_output($json_profile)); -} +$actionButtons = []; -echo '
'; - -echo '
'; -if ($config['admin_can_add_user']) { - if ($new_user) { - html_print_submit_button( - __('Create'), - 'crtbutton', - false, - 'class="sub wand" form="user_profile_form"' - ); +if ((bool) $config['admin_can_add_user'] === true) { + if ($new_user === true) { + $submitButtonCaption = __('Create'); + $submitButtonName = 'crtbutton'; + $submitButtonIcon = 'wand'; } else { - html_print_submit_button( - __('Update'), - 'uptbutton', - false, - 'class="sub upd" form="user_profile_form"' - ); + $submitButtonCaption = __('Update'); + $submitButtonName = 'uptbutton'; + $submitButtonIcon = 'update'; } + + $actionButtons[] = html_print_submit_button( + $submitButtonCaption, + $submitButtonName, + false, + [ + 'icon' => $submitButtonIcon, + 'form' => 'user_profile_form', + ], + true + ); } -echo '
'; +if ((bool) check_acl($config['id_user'], 0, 'UM') === true) { + $actionButtons[] = html_print_go_back_button( + ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure=0'), + ['button_class' => ''], + true + ); +} +html_print_action_buttons(implode('', $actionButtons), ['type' => 'form_action']); echo ''; -enterprise_hook('close_meta_frame'); +// This is an image generated for JS. $delete_image = html_print_input_image( 'del', 'images/cross.png', @@ -1757,7 +1897,7 @@ $delete_image = html_print_input_image( ] ); -if (!is_metaconsole()) { +if (is_metaconsole() === false) { ?> + $dialogContainer + .empty() + .append(message) + .append($button); + + var request; + + $button.click(function(e) { + e.preventDefault(); + + $dialogContainer.html($loadingSpinner); + + // Deactivate the double auth + request = $.ajax({ + url: "", + type: 'POST', + dataType: 'json', + data: { + page: 'include/ajax/double_auth.ajax', + id_user: userID, + FA_forced: 1, + deactivate_double_auth: 1 + }, + complete: function(xhr, textStatus) { + + }, + success: function(data, textStatus, xhr) { + if (data === -1) { + $dialogContainer.html("
'.__('Authentication error').'
'; ?>"); + } else if (data) { + $dialogContainer.html("
'.__('The double autentication was deactivated successfully').'
'; ?>"); + $("input#checkbox-double_auth").prop("checked", false); + } else { + $dialogContainer.html("
'.__('There was an error deactivating the double autentication').'
'; ?>"); + } + }, + error: function(xhr, textStatus, errorThrown) { + $dialogContainer.html("
'.__('There was an error deactivating the double autentication').'
'; ?>"); + } + }); + }); + + + $("div#dialog-double_auth").dialog({ + resizable: true, + draggable: true, + modal: true, + title: "", + overlay: { + opacity: 0.5, + background: "black" + }, + width: 300, + height: 150, + close: function(event, ui) { + // Abort the ajax request + if (typeof request != 'undefined') + request.abort(); + // Remove the contained html + $dialogContainer.empty(); + + } + }) + .show(); + } + + + /* ]]> */ + \ No newline at end of file diff --git a/pandora_console/godmode/users/profile_list.php b/pandora_console/godmode/users/profile_list.php index 7ce7c82cc0..e47e989d0f 100644 --- a/pandora_console/godmode/users/profile_list.php +++ b/pandora_console/godmode/users/profile_list.php @@ -31,8 +31,6 @@ global $config; check_login(); -enterprise_hook('open_meta_frame'); - require_once $config['homedir'].'/include/functions_profile.php'; require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_groups.php'; @@ -57,22 +55,22 @@ if (is_metaconsole() === false) { 'user' => [ 'active' => false, 'text' => ''.html_print_image( - 'images/gm_users.png', + 'images/user.svg', true, [ 'title' => __('User management'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_user', ] ).'', ], 'profile' => [ 'active' => false, 'text' => ''.html_print_image( - 'images/profiles.png', + 'images/suitcase@svg.svg', true, [ 'title' => __('Profile management'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_user', ] ).'', ], @@ -80,13 +78,24 @@ if (is_metaconsole() === false) { $buttons[$tab]['active'] = true; - ui_print_page_header( - __('User management').' » '.__('Profiles defined on %s', get_product_name()), - 'images/gm_users.png', + // Header. + ui_print_standard_header( + __('User Profile management'), + 'images/user.svg', false, 'profile_tab', - true, - $buttons + false, + $buttons, + [ + [ + 'link' => '', + 'label' => __('Profiles'), + ], + [ + 'link' => '', + 'label' => __('Manage users'), + ], + ] ); $sec = 'gusuarios'; } else { @@ -312,8 +321,8 @@ if ($is_management_allowed === true && $create_profile === true) { $table = new stdClass(); $table->cellpadding = 0; $table->cellspacing = 0; +$table->styleTable = 'margin: 10px'; $table->class = 'info_table profile_list'; -$table->width = '100%'; $table->head = []; $table->data = []; @@ -322,36 +331,37 @@ $table->align = []; $table->head['profiles'] = __('Profiles'); -$table->head['AR'] = 'AR'; -$table->head['AW'] = 'AW'; -$table->head['AD'] = 'AD'; -$table->head['LW'] = 'LW'; -$table->head['LM'] = 'LM'; -$table->head['UM'] = 'UM'; -$table->head['DM'] = 'DM'; -$table->head['ER'] = 'ER'; -$table->head['EW'] = 'EW'; -$table->head['EM'] = 'EM'; -$table->head['RR'] = 'RR'; -$table->head['RW'] = 'RW'; -$table->head['RM'] = 'RM'; -$table->head['MR'] = 'MR'; -$table->head['MW'] = 'MW'; -$table->head['MM'] = 'MM'; -$table->head['VR'] = 'VR'; -$table->head['VW'] = 'VW'; -$table->head['VM'] = 'VM'; -$table->head['NR'] = 'NR'; -$table->head['NW'] = 'NW'; -$table->head['NM'] = 'NM'; -$table->head['PM'] = 'PM'; +$table->head['AR'] = ''.'AR'.''; +$table->head['AW'] = ''.'AW'.''; +$table->head['AD'] = ''.'AD'.''; +$table->head['LW'] = ''.'LW'.''; +$table->head['LM'] = ''.'LM'.''; +$table->head['UM'] = ''.'UM'.''; +$table->head['DM'] = ''.'DM'.''; +$table->head['ER'] = ''.'ER'.''; +$table->head['EW'] = ''.'EW'.''; +$table->head['EM'] = ''.'EM'.''; +$table->head['RR'] = ''.'RR'.''; +$table->head['RW'] = ''.'RW'.''; +$table->head['RM'] = ''.'RM'.''; +$table->head['MR'] = ''.'MR'.''; +$table->head['MW'] = ''.'MW'.''; +$table->head['MM'] = ''.'MM'.''; +$table->head['VR'] = ''.'VR'.''; +$table->head['VW'] = ''.'VW'.''; +$table->head['VM'] = ''.'VM'.''; +$table->head['NR'] = ''.'NR'.''; +$table->head['NW'] = ''.'NW'.''; +$table->head['NM'] = ''.'NM'.''; +$table->head['PM'] = ''.'PM'.''; + if ($is_management_allowed === true) { $table->head['operations'] = ''.__('Op.').''; } $table->align = array_fill(1, 11, 'center'); -$table->size['profiles'] = '200px'; +$table->size['profiles'] = '150px'; $table->size['AR'] = '10px'; $table->size['AW'] = '10px'; $table->size['AD'] = '10px'; @@ -376,7 +386,7 @@ $table->size['NW'] = '10px'; $table->size['NM'] = '10px'; $table->size['PM'] = '10px'; if ($is_management_allowed === true) { - $table->size['operations'] = '5%'; + $table->size['operations'] = '6%'; } $profiles = db_get_all_rows_in_table('tperfil'); @@ -385,11 +395,11 @@ if ($profiles === false) { } $img = html_print_image( - 'images/ok.png', + 'images/validate.svg', true, [ 'border' => 0, - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); @@ -425,25 +435,32 @@ foreach ($profiles as $profile) { $data['NW'] = (empty($profile['network_config_edit']) === false) ? $img : ''; $data['NM'] = (empty($profile['network_config_management']) === false) ? $img : ''; $data['PM'] = (empty($profile['pandora_management']) === false) ? $img : ''; - $table->cellclass[]['operations'] = 'action_buttons'; + $table->cellclass[]['operations'] = 'table_action_buttons'; if ($is_management_allowed === true) { $data['operations'] = ''.html_print_image( - 'images/config.png', + 'images/edit.svg', true, [ 'title' => __('Edit'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ).''; - if (check_acl($config['id_user'], 0, 'PM') || users_is_admin()) { - $data['operations'] .= ''.html_print_image( - 'images/cross.png', - true, + if ((bool) check_acl($config['id_user'], 0, 'PM') === true || (bool) users_is_admin() === true) { + $data['operations'] .= html_print_anchor( [ - 'title' => __('Delete'), - 'class' => 'invert_filter', - ] - ).''; + 'href' => 'index.php?sec='.$sec.'&sec2=godmode/users/profile_list&delete_profile=1&id='.$profile['id_perfil'].'&pure='.$pure, + 'onClick' => 'if (!confirm(\' '.__('Are you sure?').'\')) return false;', + 'content' => html_print_image( + 'images/delete.svg', + true, + [ + 'title' => __('Delete'), + 'class' => 'invert_filter main_menu_icon', + ] + ), + ], + true + ); } } @@ -458,13 +475,21 @@ if (isset($data) === true) { if ($is_management_allowed === true) { echo '
'; - echo '
'; html_print_input_hidden('new_profile', 1); - html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"'); - echo '
'; + html_print_action_buttons( + html_print_submit_button( + __('Create profile'), + 'crt', + false, + [ 'icon' => 'next' ], + true + ), + [ + 'type' => 'data_table', + 'class' => 'fixed_action_buttons', + ] + ); echo '
'; } unset($table); - -enterprise_hook('close_meta_frame'); diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index e5d15006fe..e4fe4225fa 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ============================================================================ - * Copyright (c) 2005-2021 Artica Soluciones Tecnologicas + * Copyright (c) 2005-2023 Artica Soluciones Tecnologicas * Please see http://pandorafms.org for full contribution list * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -132,8 +132,6 @@ if (is_ajax()) { } } -enterprise_hook('open_meta_frame'); - $sortField = get_parameter('sort_field'); $sort = get_parameter('sort', 'none'); $tab = get_parameter('tab', 'user'); @@ -247,22 +245,22 @@ if (is_metaconsole() === true) { 'user' => [ 'active' => false, 'text' => ''.html_print_image( - 'images/gm_users.png', + 'images/user.svg', true, [ 'title' => __('User management'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ).'', ], 'profile' => [ 'active' => false, 'text' => ''.html_print_image( - 'images/profiles.png', + 'images/suitcase@svg.svg', true, [ 'title' => __('Profile management'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ).'', ], @@ -272,11 +270,11 @@ if (is_metaconsole() === true) { 'user' => [ 'active' => false, 'text' => ''.html_print_image( - 'images/gm_users.png', + 'images/user.svg', true, [ 'title' => __('User management'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ).'', ], @@ -285,13 +283,24 @@ if (is_metaconsole() === true) { $buttons[$tab]['active'] = true; - ui_print_page_header( - __('User management').' » '.__('Users defined on %s', get_product_name()), - 'images/gm_users.png', + // Header. + ui_print_standard_header( + __('Users management'), + 'images/user.svg', false, '', - true, - $buttons + false, + $buttons, + [ + [ + 'link' => '', + 'label' => __('Profiles'), + ], + [ + 'link' => '', + 'label' => __('Manage users'), + ], + ] ); $sec = 'gusuarios'; @@ -326,8 +335,11 @@ if ($delete_user === true) { ); if (isset($private_dashboards) === true) { - db_process_sql_delete('tdashboard', ['id_user' => $id_user]); - header('Refresh:1'); + $dashboardRemoveResult = db_process_sql_delete('tdashboard', ['id_user' => $id_user]); + // Refresh the view when delete private dashboards. For review. + if ($dashboardRemoveResult === false || (int) $dashboardRemoveResult > 0) { + header('Refresh:1'); + } } $result = delete_user($id_user); @@ -402,6 +414,11 @@ if ($delete_user === true) { __('There was a problem deleting the profile') ); } else if ($disable_user !== false) { + // CSRF Validator. + if (html_print_csrf_error()) { + return; + } + // Disable_user. $id_user = get_parameter('id', 0); @@ -444,12 +461,14 @@ if (($filter_group == 0) && ($filter_search == '')) { $search = false; } -$table = new stdClass(); -$table->width = '100%'; -$table->class = 'databox filters'; -$table->rowclass[0] = ''; -$table->data[0][0] = ''.__('Group').''; -$table->data[0][1] = html_print_select_groups( +$filterTable = new stdClass(); +$filterTable->width = '100%'; +$filterTable->class = 'fixed_filter_bar'; +$filterTable->rowclass[0] = ''; +$filterTable->cellstyle[0][0] = 'width:0'; +$filterTable->cellstyle[0][1] = 'width:0'; +$filterTable->data[0][0] = __('Group'); +$filterTable->data[1][0] = html_print_select_groups( false, 'AR', true, @@ -460,8 +479,8 @@ $table->data[0][1] = html_print_select_groups( 0, true ); -$table->data[0][2] = ''.__('Search').''.ui_print_help_tip(__('Search by username, fullname or email'), true); -$table->data[0][3] = html_print_input_text( +$filterTable->data[0][1] = __('Search').ui_print_help_tip(__('Search by username, fullname or email'), true); +$filterTable->data[1][1] = html_print_input_text( 'filter_search', $filter_search, __('Search by username, fullname or email'), @@ -469,11 +488,16 @@ $table->data[0][3] = html_print_input_text( 90, true ); -$table->data[0][4] = html_print_submit_button( +$filterTable->cellstyle[1][2] = 'vertical-align: bottom'; +$filterTable->data[1][2] = html_print_submit_button( __('Search'), 'search', false, - ['class' => 'sub search'], + [ + 'icon' => 'search', + 'class' => 'float-right', + 'mode' => 'secondary mini', + ], true ); @@ -498,22 +522,16 @@ if (is_metaconsole() === false && is_management_allowed() === false) { if (is_metaconsole() === true) { - $table->width = '96%'; + $filterTable->width = '96%'; $form_filter = "
"; - $form_filter .= html_print_table($table, true); + $form_filter .= html_print_table($filterTable, true); $form_filter .= '
'; ui_toggle($form_filter, __('Show Options')); } else { $form_filter = "
"; - $form_filter .= html_print_table($table, true); + $form_filter .= html_print_table($filterTable, true); $form_filter .= '
'; - ui_toggle( - $form_filter, - __('Users control filter'), - __('Toggle filter(s)'), - '', - !$search - ); + echo $form_filter; } // Urls to sort the table. @@ -528,8 +546,9 @@ $url_down_last = '?sec='.$sec.'&sec2=godmode/users/user_list&sort_field=last_con $table = new stdClass(); $table->cellpadding = 0; $table->cellspacing = 0; -$table->width = '100%'; -$table->class = 'info_table'; +$table->class = 'info_table tactical_table'; +$table->id = 'user_list'; +$table->styleTable = 'margin: 0 10px'; $table->head = []; $table->data = []; @@ -537,15 +556,18 @@ $table->align = []; $table->size = []; $table->valign = []; -$table->head[0] = __('User ID').ui_get_sorting_arrows($url_up_id, $url_down_id, $selectUserIDUp, $selectUserIDDown); -$table->head[1] = __('Name').ui_get_sorting_arrows($url_up_name, $url_down_name, $selectFullnameUp, $selectFullnameDown); -$table->head[2] = __('Last contact').ui_get_sorting_arrows($url_up_last, $url_down_last, $selectLastConnectUp, $selectLastConnectDown); +$table->head[0] = ''.__('User ID').''; +$table->head[0] .= ui_get_sorting_arrows($url_up_id, $url_down_id, $selectUserIDUp, $selectUserIDDown); +$table->head[1] = ''.__('Name').''; +$table->head[1] .= ui_get_sorting_arrows($url_up_name, $url_down_name, $selectFullnameUp, $selectFullnameDown); +$table->head[2] = ''.__('Last contact').''; +$table->head[2] .= ui_get_sorting_arrows($url_up_last, $url_down_last, $selectLastConnectUp, $selectLastConnectDown); -$table->head[3] = __('Admin'); -$table->head[4] = __('Profile / Group'); -$table->head[5] = __('Description'); +$table->head[3] = ''.__('Admin').''; +$table->head[4] = ''.__('Profile / Group').''; +$table->head[5] = ''.__('Description').''; if ($is_management_allowed === true) { - $table->head[6] = ''.__('Op.').''; + $table->head[6] = ''.__('Actions').''; } if (is_metaconsole() === false) { @@ -580,7 +602,7 @@ if ($user_is_admin) { } else { $group_um = users_get_groups_UM($config['id_user']); // 0 is the group 'all'. - if (isset($group_um[0])) { + if (isset($group_um[0]) === true) { $info1 = get_users($order); } else { foreach ($group_um as $group => $value) { @@ -637,15 +659,14 @@ foreach ($info1 as $user_id => $user_info) { $info = $info1; -// Prepare pagination. -ui_pagination(count($info)); - $offset = (int) get_parameter('offset'); $limit = (int) $config['block_size']; $rowPair = true; $iterator = 0; $cont = 0; +// Creates csrf. +$csrf = html_print_csrf_hidden(true); foreach ($info as $user_id => $user_info) { if (empty($user_id) === true) { continue; @@ -707,7 +728,13 @@ foreach ($info as $user_id => $user_info) { || isset($group_um[0]) || (isset($user_info['edit']) && $user_info['edit'])))) ) { - $data[0] = ''.$user_id.''; + $data[0] = html_print_anchor( + [ + 'href' => ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/configure_user&edit_user=1&pure=0&id_user='.$user_id), + 'content' => $user_id, + ], + true + ); } else { $data[0] = $user_id; } @@ -721,12 +748,12 @@ foreach ($info as $user_id => $user_info) { if ($user_info['is_admin']) { $data[3] = html_print_image( - 'images/user_suit.png', + 'images/user.svg', true, [ 'alt' => __('Admin'), 'title' => __('Administrator'), - 'class' => 'invert_filter', + 'class' => 'main_menu_icon invert_filter', ] ).' '; } else { @@ -785,10 +812,10 @@ foreach ($info as $user_id => $user_info) { } $data[5] = ui_print_string_substr($user_info['comments'], 24, true); - + $table->cellclass[][6] = 'table_action_buttons'; + $data[6] = ''; + $userListActionButtons = []; if ($is_management_allowed === true) { - $table->cellclass[][6] = 'action_buttons'; - $data[6] = ''; if ($user_is_admin || $config['id_user'] == $user_info['id_user'] || isset($group_um[0]) @@ -797,30 +824,49 @@ foreach ($info as $user_id => $user_info) { ) { // Disable / Enable user. if (isset($user_info['not_delete']) === false) { - if ($user_info['disabled'] == 0) { + if ((int) $user_info['disabled'] === 0) { $toDoString = __('Disable'); $toDoAction = '1'; - $toDoImage = 'images/lightbulb.png'; + $toDoImage = 'images/disable.svg'; $toDoClass = ''; } else { $toDoString = __('Enable'); $toDoAction = '0'; - $toDoImage = 'images/lightbulb_off.png'; + $toDoImage = 'images/enable.svg'; $toDoClass = 'filter_none'; } - $data[6] = '
'; - $data[6] .= html_print_input_hidden( + $userListActionButtons[] = html_print_menu_button( + [ + 'href' => ui_get_full_url( + sprintf( + 'index.php?sec=%s&sec2=godmode/users/user_list&disable_user=%s&pure=%s&id=%s', + $sec, + $toDoAction, + $pure, + $user_info['id_user'] + ) + ), + 'image' => $toDoImage, + 'title' => $toDoString, + ], + true + ); + /* + $data[6] = ''; + $data[6] .= html_print_input_hidden( 'id', $user_info['id_user'], true - ); - $data[6] .= html_print_input_hidden( + ); + // Same csrf for every disable button for submit. + $data[6] .= $csrf; + $data[6] .= html_print_input_hidden( 'disable_user', $toDoAction, true - ); - $data[6] .= html_print_input_image( + ); + $data[6] .= html_print_input_image( 'submit_disable_enable', $toDoImage, '', @@ -829,66 +875,102 @@ foreach ($info as $user_id => $user_info) { [ 'data-title' => $toDoString, 'data-use_title_for_force_title' => '1', - 'class' => 'forced_title no-padding '.$toDoClass, + 'class' => 'main_menu_icon forced_title no-padding '.$toDoClass, ] - ); - $data[6] .= '
'; + ); + $data[6] .= ''; + */ } - // Edit user. - $data[6] .= '
'; - $data[6] .= html_print_input_hidden( + /* + // Edit user. + $data[6] .= ''; + $data[6] .= html_print_input_hidden( 'id_user', $user_info['id_user'], true - ); - $data[6] .= html_print_input_hidden( + ); + $data[6] .= html_print_input_hidden( 'edit_user', '1', true - ); - $data[6] .= html_print_input_image( + ); + $data[6] .= html_print_input_image( 'submit_edit_user', - 'images/config.png', + 'images/edit.svg', '', 'padding:0', true, [ 'data-title' => __('Edit'), 'data-use_title_for_force_title' => '1', - 'class' => 'forced_title no-padding', + 'class' => 'main_menu_icon forced_title no-padding', ] + ); + $data[6] .= '
';*/ + + $userListActionButtons[] = html_print_menu_button( + [ + 'href' => ui_get_full_url( + sprintf( + 'index.php?sec=%s&sec2=godmode/users/configure_user&edit_user=1&pure=%s&id_user=%s', + $sec, + $pure, + $user_info['id_user'] + ) + ), + 'image' => 'images/edit.svg', + 'title' => __('Edit user'), + ], + true ); - $data[6] .= ''; if ($config['admin_can_delete_user'] && $user_info['id_user'] != $config['id_user'] && isset($user_info['not_delete']) === false ) { - $data[6] .= '
'; - $data[6] .= html_print_input_hidden( + /* + $offset_delete = ($offset >= count($info) - 1) ? ($offset - $config['block_size']) : $offset; + $data[6] .= ''; + $data[6] .= html_print_input_hidden( 'delete_user', $user_info['id_user'], true - ); - $data[6] .= html_print_input_hidden( + ); + $data[6] .= html_print_input_hidden( 'user_del', '1', true - ); - $data[6] .= html_print_input_image( + ); + $data[6] .= html_print_input_image( 'submit_delete_user', - 'images/cross.png', + 'images/delete.svg', '', 'padding:0', true, [ 'data-title' => __('Delete'), 'data-use_title_for_force_title' => '1', - 'class' => 'forced_title no-padding', + 'class' => 'main_menu_icon forced_title no-padding', ] + ); + $data[6] .= '
'; + */ + $userListActionButtons[] = html_print_menu_button( + [ + 'href' => ui_get_full_url( + sprintf( + 'index.php?sec=%s&sec2=godmode/users/user_list&user_del=1&pure=%s&delete_user=%s', + $sec, + $pure, + $user_info['id_user'] + ) + ), + 'image' => 'images/delete.svg', + 'title' => __('Delete'), + ], + true ); - $data[6] .= ''; if (is_metaconsole() === true) { $data[6] .= '
'; @@ -908,11 +990,16 @@ foreach ($info as $user_id => $user_info) { true ); $data[6] .= '
'; + } else { + $data[6] = implode('', $userListActionButtons); } } else { $data[6] .= ''; // Delete button not in this mode. } + + // TODO. Check this in META!!! + $data[6] = implode('', $userListActionButtons); } else { $data[6] .= ''; // Delete button not in this mode. @@ -923,26 +1010,45 @@ foreach ($info as $user_id => $user_info) { } html_print_table($table); -ui_pagination(count($info), false, 0, 0, false, 'offset', true, 'pagination-bottom'); - -echo '
'; +$tablePagination = ui_pagination(count($info), false, 0, 0, true, 'offset', false, 'dataTables_paginate paging_simple_numbers'); unset($table); if ($is_management_allowed === true) { if ($config['admin_can_add_user'] !== false) { echo '
'; + html_print_action_buttons( + html_print_submit_button( + __('Create user'), + 'crt', + false, + [ 'icon' => 'wand' ], + true + ), + [ + 'type' => 'form_action', + 'right_content' => $tablePagination, + ], + ); html_print_input_hidden('new_user', 1); - html_print_submit_button(__('Create user'), 'crt', false, 'class="sub next"'); echo '
'; } else { echo ''.__("The current authentication scheme doesn't support creating users on %s", get_product_name()).''; } +} else { + html_print_action_buttons( + html_print_submit_button( + __('Create user'), + 'none', + true, + [ 'icon' => 'wand' ], + true + ), + [ + 'type' => 'form_action', + 'right_content' => $tablePagination, + ], + ); } - -echo '
'; - -enterprise_hook('close_meta_frame'); - ?> + '; + if (check_acl($config['id_user'], 0, 'AW')) { + echo '
'; + + $table = new StdClass; + $table->id = 'save_filter_form'; + $table->width = '100%'; + $table->size = []; + $table->size[0] = '50%'; + $table->size[1] = '50%'; + $table->class = 'filter-table-adv'; + $data = []; + + $table->rowid[0] = 'update_save_selector'; + $data[0][0] = html_print_label_input_block( + __('New filter'), + html_print_radio_button( + 'filter_mode', + 'new', + '', + true, + true + ) + ); + + $data[0][1] = html_print_label_input_block( + __('Update/delete filter'), + html_print_radio_button( + 'filter_mode', + 'update', + '', + false, + true + ) + ); + + $table->rowid[1] = 'save_filter_row1'; + $data[1][0] = html_print_label_input_block( + __('Filter name'), + html_print_input_text('id_name', '', '', 15, 255, true) + ); + + $labelInput = __('Filter group'); + if (is_metaconsole() === true) { + $labelInput = __('Save in Group'); + } + + $user_groups_array = users_get_groups_for_select( + $config['id_user'], + 'AW', + users_can_manage_group_all('AW'), + true + ); + + $data[1][1] = html_print_label_input_block( + $labelInput, + html_print_select( + $user_groups_array, + 'id_group_filter_dialog', + $id_group_filter, + '', + '', + 0, + true, + false, + false + ), + ['div_class' => 'filter-group-dialog'] + ); + + $table->rowid[2] = 'save_filter_row2'; + + $table->data[] = $data; + $table->rowclass[] = ''; + $user_groups = users_get_groups( + $config['id_user'], + 'AW', + users_can_manage_group_all('AW'), + true + ); + + $sql = 'SELECT id_filter, id_name + FROM tagent_filter + WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')'; + + $agent_filters = db_get_all_rows_sql($sql); + + $_filters_update = []; + + if ($agent_filters !== false) { + foreach ($agent_filters as $agent_filter) { + $_filters_update[$agent_filter['id_filter']] = $agent_filter['id_name']; + } + } + + $data[2][0] = html_print_label_input_block( + __('Filter'), + html_print_select( + $_filters_update, + 'overwrite_filter', + '', + '', + '', + 0, + true + ) + ); + + $table->data = $data; + + html_print_table($table); + html_print_div( + [ + 'id' => 'submit-save_filter', + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + __('Save current filter'), + 'srcbutton', + false, + [ + 'icon' => 'search', + 'mode' => 'mini', + 'onclick' => 'save_new_filter();', + ], + true + ), + ], + false + ); + + $input_actions = html_print_submit_button( + __('Delete filter'), + 'delete_filter', + false, + [ + 'icon' => 'delete', + 'mode' => 'mini', + 'onclick' => 'save_delete_filter();', + ], + true + ); + + $input_actions .= html_print_submit_button( + __('Update filter'), + 'srcbutton', + false, + [ + 'icon' => 'update', + 'mode' => 'mini', + 'onclick' => 'save_update_filter();', + ], + true + ); + + html_print_div( + [ + 'id' => 'update_filter_row', + 'class' => 'action-buttons', + 'content' => $input_actions, + ], + false + ); + } else { + include 'general/noaccess.php'; + } + + echo ''; + ?> + + data[] = $row; } - if (!empty($table->data)) { + if (empty($table->data) === false) { html_print_table($table); } else { ui_print_info_message(['no_close' => true, 'message' => __('No alerts found') ]); @@ -663,9 +663,9 @@ if ($get_agent_alerts_datatable === true) { include_once $config['homedir'].'/operation/agentes/alerts_status.functions.php'; include_once $config['homedir'].'/include/functions_users.php'; - $agent_a = check_acl($config['id_user'], 0, 'AR'); - $agent_w = check_acl($config['id_user'], 0, 'AW'); - $access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'); + $agent_a = (bool) check_acl($config['id_user'], 0, 'AR'); + $agent_w = (bool) check_acl($config['id_user'], 0, 'AW'); + $access = ($agent_a === true) ? 'AR' : (($agent_w === true) ? 'AW' : 'AR'); $all_groups = get_parameter('all_groups'); $idAgent = (int) get_parameter('id_agent'); @@ -861,7 +861,7 @@ if ($get_agent_alerts_datatable === true) { if (is_metaconsole() === true) { include_once $config['homedir'].'/enterprise/meta/include/functions_alerts_meta.php'; - if ($idAgent != 0) { + if ($idAgent !== 0) { $alerts['alerts_simple'] = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); $countAlertsSimple = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter); @@ -875,7 +875,7 @@ if ($get_agent_alerts_datatable === true) { $countAlertsSimple = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter); } } else { - if ($idAgent != 0) { + if ($idAgent !== 0) { $alerts['alerts_simple'] = agents_get_alerts_simple($idAgent, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter); $countAlertsSimple = agents_get_alerts_simple($idAgent, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter); diff --git a/pandora_console/include/ajax/audit_log.php b/pandora_console/include/ajax/audit_log.php index 3bf5e09d24..4d92704852 100644 --- a/pandora_console/include/ajax/audit_log.php +++ b/pandora_console/include/ajax/audit_log.php @@ -135,18 +135,15 @@ if ($load_filter_modal) { $table->width = '100%'; $table->cellspacing = 4; $table->cellpadding = 4; - $table->class = 'databox'; + $table->class = 'databox no_border'; if (is_metaconsole()) { $table->cellspacing = 0; $table->cellpadding = 0; - $table->class = 'databox filters'; + $table->class = 'databox filters no_border'; } $table->styleTable = 'font-weight: bold; color: #555; text-align:left;'; - $filter_id_width = '200px'; - if (is_metaconsole()) { - $filter_id_width = '150px'; - } + $filter_id_width = 'w100p'; $data = []; $table->rowid[3] = 'update_filter_row1'; @@ -165,11 +162,17 @@ if ($load_filter_modal) { false, 'margin-left:5px; width:'.$filter_id_width.';' ); + + $table->rowclass[] = 'display-grid'; $data[1] = html_print_submit_button( __('Load filter'), 'load_filter', false, - 'class="sub upd" onclick="load_filter_values()"', + [ + 'class' => 'mini w25p', + 'style' => 'margin-left: 73%', + 'onclick' => 'load_filter_values();', + ], true ); $data[1] .= html_print_input_hidden('load_filter', 1, true); @@ -186,7 +189,7 @@ function show_filter() { draggable: true, modal: false, closeOnEscape: true, - width: 450 + width: 500 }); } @@ -238,7 +241,7 @@ $(document).ready (function() { if ($save_filter_modal) { - echo '
'; + echo '
'; if (check_acl($config['id_user'], 0, 'EW') === 1 || check_acl($config['id_user'], 0, 'EM') === 1) { echo '
'; @@ -247,9 +250,9 @@ if ($save_filter_modal) { $table->width = '100%'; $table->cellspacing = 4; $table->cellpadding = 4; - $table->class = 'databox'; + $table->class = 'databox no_border'; if (is_metaconsole()) { - $table->class = 'databox filters'; + $table->class = 'databox filters no_border'; $table->cellspacing = 0; $table->cellpadding = 0; } @@ -289,7 +292,11 @@ if ($save_filter_modal) { __('Save filter'), 'save_filter', false, - 'class="sub wand" onclick="save_new_filter();"', + [ + 'class' => 'mini w25p', + 'style' => 'margin-left: 56%', + 'onclick' => 'save_new_filter();', + ], true ); @@ -317,11 +324,16 @@ if ($save_filter_modal) { 0, true ); + $table->rowclass[] = 'display-grid'; $data[1] = html_print_submit_button( __('Update filter'), 'update_filter', false, - 'class="sub upd" onclick="save_update_filter();"', + [ + 'class' => 'mini w25p', + 'style' => 'margin-left: 56%', + 'onclick' => 'save_update_filter();', + ], true ); @@ -359,7 +371,8 @@ function show_save_filter() { resizable: true, draggable: true, modal: false, - closeOnEscape: true + closeOnEscape: true, + width: 380 }); } diff --git a/pandora_console/include/ajax/double_auth.ajax.php b/pandora_console/include/ajax/double_auth.ajax.php index 0f85c9c0f5..3a995ce43a 100644 --- a/pandora_console/include/ajax/double_auth.ajax.php +++ b/pandora_console/include/ajax/double_auth.ajax.php @@ -1,21 +1,39 @@ $id_user]; db_process_sql_delete('tuser_double_auth', $where); - // Insert the new value + // Insert the new value. $values = [ 'id_user' => $id_user, 'secret' => $secret, @@ -116,12 +134,12 @@ if ($save_double_auth_secret) { return; } -// Disable the double auth for the user +// Disable the double auth for the user. $deactivate_double_auth = (bool) get_parameter('deactivate_double_auth'); if ($deactivate_double_auth) { $result = false; - // Delete the actual value (if exists) + // Delete the actual value (if exists). $where = ['id_user' => $id_user]; $result = db_process_sql_delete('tuser_double_auth', $where); @@ -129,7 +147,7 @@ if ($deactivate_double_auth) { return; } -// Get the info page to the container dialog +// Get the info page to the container dialog. $get_double_auth_data_page = (bool) get_parameter('get_double_auth_data_page'); if ($get_double_auth_data_page) { $secret = db_get_value('secret', 'tuser_double_auth', 'id_user', $id_user); @@ -146,7 +164,7 @@ if ($get_double_auth_data_page) { $html .= '

'; $html .= '
'; $html .= '
'; - $html .= __('Code').": $secret"; + $html .= __('Code').': '.$secret.''; $html .= '
'; $html .= __('QR').':
'; $html .= '
'; @@ -161,7 +179,7 @@ if ($get_double_auth_data_page) { var secret = ""; var id_user_auth = ""; - // QR code with the secret to add it to the app + // QR code with the secret to add it to the app. paint_qrcode("otpauth://totp/"+id_user_auth+"?secret="+secret, $("div#qr-container").get(0), 200, 200); $("div#qr-container").attr("title", "").find("canvas").remove(); @@ -179,7 +197,7 @@ if ($get_double_auth_data_page) { return; } -// Get the info page to the container dialog +// Get the info page to the container dialog. $get_double_auth_info_page = (bool) get_parameter('get_double_auth_info_page'); if ($get_double_auth_info_page) { $container_id = (string) get_parameter('containerID'); @@ -209,14 +227,14 @@ if ($get_double_auth_info_page) { ob_clean(); ?> data)) { - if ($filter_monitors) { - ui_print_info_message([ 'no_close' => true, 'message' => __('Any monitors aren\'t with this filter.') ]); - } else { - ui_print_info_message([ 'no_close' => true, 'message' => __('This agent doesn\'t have any active monitors.') ]); - } + if (empty($table->data) === true) { + ui_print_info_message( + [ + 'no_close' => true, + 'message' => ($filter_monitors === true) ? __('Any monitors aren\'t with this filter.') : __('This agent doesn\'t have any active monitors.'), + ] + ); } else { $url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&refr=&filter_monitors=1&status_filter_monitor='.$status_filter_monitor.'&status_text_monitor='.$status_text_monitor.'&status_module_group='.$status_module_group; - if ($paginate_module) { + if ($paginate_module === true) { ui_pagination( $count_modules, false, @@ -1349,7 +1376,7 @@ if (check_login()) { html_print_table($table); - if ($paginate_module) { + if ($paginate_module === true) { ui_pagination( $count_modules, false, @@ -1372,7 +1399,7 @@ if (check_login()) { unset($table_data); } - if ($get_type) { + if ($get_type === true) { $id_module = (int) get_parameter('id_module'); $module = modules_get_agentmodule($id_module); $graph_type = return_graphtype($module['id_tipo_modulo']); @@ -1626,7 +1653,7 @@ if (check_login()) { // If not valid it will throw an exception. json_decode($response); - if (json_last_error() == JSON_ERROR_NONE) { + if (json_last_error() === JSON_ERROR_NONE) { // If valid dump. echo $response; } else { @@ -1740,6 +1767,29 @@ if (check_login()) { } } + if ($delete_monitor_filter) { + $id = get_parameter('id'); + + $user_groups = users_get_groups( + $config['id_user'], + 'AW', + users_can_manage_group_all('AW'), + true + ); + + $sql = 'DELETE + FROM tmonitor_filter + WHERE id_filter = '.$id.' AND id_group_filter IN ('.implode(',', array_keys($user_groups)).')'; + + $monitor_filters = db_process_sql($sql); + + if ($monitor_filters === false) { + echo 'error'; + } else { + echo 'ok'; + } + } + if ($get_monitor_filters) { $sql = 'SELECT id_filter, id_name FROM tmonitor_filter'; @@ -1760,7 +1810,7 @@ if (check_login()) { $user_groups = users_get_groups( $config['id_user'], 'AR', - users_can_manage_group_all(), + users_can_manage_group_all('AR'), true ); @@ -1775,56 +1825,54 @@ if (check_login()) { $filters[$event_filter['id_filter']] = $event_filter['id_name']; } - echo '
'; + echo '
'; echo '
'; $table = new StdClass; $table->id = 'load_filter_form'; $table->width = '100%'; - $table->cellspacing = 4; - $table->cellpadding = 4; - $table->class = 'databox'; - if (is_metaconsole()) { - $table->cellspacing = 0; - $table->cellpadding = 0; - $table->class = 'databox filters'; - } - - $table->styleTable = 'font-weight: bold; color: #555; text-align:left;'; - $filter_id_width = '200px'; - if (is_metaconsole()) { - $filter_id_width = '150px'; - } + $table->class = 'filter-table-adv'; $data = []; $table->rowid[3] = 'update_filter_row1'; - $data[0] = __('Load filter').$jump; - $data[0] .= html_print_select( - $filters, - 'filter_id', - $current, - '', - __('None'), - 0, - true, - false, - true, - '', - false, - 'margin-left:5px; width:'.$filter_id_width.';' - ); - $data[1] = html_print_submit_button( + $data[0] = html_print_label_input_block( __('Load filter'), - 'load_filter', - false, - 'class="sub upd"', - true + html_print_select( + $filters, + 'filter_id', + $current, + '', + __('None'), + 0, + true, + false, + true, + '', + false + ) ); - $data[1] .= html_print_input_hidden('load_filter', 1, true); + $table->data[] = $data; $table->rowclass[] = ''; html_print_table($table); + html_print_div( + [ + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + __('Load filter'), + 'srcbutton', + false, + [ + 'icon' => 'search', + 'mode' => 'mini', + ], + true + ), + ], + false + ); + echo html_print_input_hidden('load_filter', 1, true); echo '
'; echo '
'; ?> @@ -1850,90 +1898,75 @@ if (check_login()) { } if ($save_filter_modal) { - echo '
'; + echo '
'; if (check_acl($config['id_user'], 0, 'AW')) { echo '
'; $table = new StdClass; $table->id = 'save_filter_form'; - $table->width = '100%'; - $table->cellspacing = 4; - $table->cellpadding = 4; - $table->class = 'databox'; - if (is_metaconsole()) { - $table->class = 'databox filters'; - $table->cellspacing = 0; - $table->cellpadding = 0; - } - - $table->styleTable = 'font-weight: bold; text-align:left;'; - if (!is_metaconsole()) { - $table->style[0] = 'width: 50%; width:50%;'; - } - + $table->size = []; + $table->size[0] = '50%'; + $table->size[1] = '50%'; + $table->class = 'filter-table-adv'; $data = []; + $table->rowid[0] = 'update_save_selector'; - $data[0] = html_print_radio_button( - 'filter_mode', - 'new', - '', - true, - true - ).__('New filter').''; + $data[0][0] = html_print_label_input_block( + __('New filter'), + html_print_radio_button( + 'filter_mode', + 'new', + '', + true, + true + ) + ); - $data[1] = html_print_radio_button( - 'filter_mode', - 'update', - '', - false, - true - ).__('Update filter').''; + $data[0][1] = html_print_label_input_block( + __('Update/delete filter'), + html_print_radio_button( + 'filter_mode', + 'update', + '', + false, + true + ) + ); - $table->data[] = $data; - $table->rowclass[] = ''; - - $data = []; $table->rowid[1] = 'save_filter_row1'; - $data[0] = __('Filter name').$jump; - $data[0] .= html_print_input_text('id_name', '', '', 15, 255, true); - if (is_metaconsole()) { - $data[1] = __('Save in Group').$jump; - } else { - $data[1] = __('Filter group').$jump; + $data[1][0] = html_print_label_input_block( + __('Filter name'), + html_print_input_text('id_name', '', '', 15, 255, true) + ); + + $labelInput = __('Filter group'); + if (is_metaconsole() === true) { + $labelInput = __('Save in Group'); } $user_groups_array = users_get_groups_for_select( $config['id_user'], 'AW', - users_can_manage_group_all(), + users_can_manage_group_all('AW'), true ); - $data[1] .= html_print_select( - $user_groups_array, - 'id_group_filter_dialog', - $id_group_filter, - '', - '', - 0, - true, - false, - false, - 'w130' + $data[1][1] = html_print_label_input_block( + $labelInput, + html_print_select( + $user_groups_array, + 'id_group_filter_dialog', + $id_group_filter, + '', + '', + 0, + true, + false, + false + ), + ['div_class' => 'filter-group-dialog'] ); - $table->data[] = $data; - $table->rowclass[] = ''; - - $data = []; $table->rowid[2] = 'save_filter_row2'; - - $table->data[] = $data; - $table->rowclass[] = ''; - - $data = []; - $table->rowid[3] = 'update_filter_row1'; - $data[0] = __('Overwrite filter').$jump; - $sql = 'SELECT id_filter, id_name FROM tmonitor_filter'; $monitor_filters = db_get_all_rows_sql($sql); @@ -1945,36 +1978,74 @@ if (check_login()) { } } - $data[0] .= html_print_select( - $_filters_update, - 'overwrite_filter', - '', - '', - '', - 0, - true - ); - $data[1] = html_print_submit_button( - __('Update filter'), - 'update_filter', - false, - 'class="sub upd" onclick="save_update_filter();"', - true + $data[2][0] = html_print_label_input_block( + __('Overwrite filter'), + html_print_select( + $_filters_update, + 'overwrite_filter', + '', + '', + '', + 0, + true + ) ); - $table->data[] = $data; - $table->rowclass[] = ''; + $table->data = $data; html_print_table($table); - echo '
'; - echo html_print_submit_button( - __('Save filter'), - 'save_filter', - false, - 'class="sub upd float-right" onclick="save_new_filter();"', - true - ); - echo '
'; + + html_print_div( + [ + 'id' => 'submit-save_filter', + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + __('Save current filter'), + 'srcbutton', + false, + [ + 'icon' => 'search', + 'mode' => 'mini', + 'onclick' => 'save_new_filter();', + ], + true + ), + ], + false + ); + + $input_actions = html_print_submit_button( + __('Delete filter'), + 'delete_filter', + false, + [ + 'icon' => 'delete', + 'mode' => 'mini', + 'onclick' => 'save_delete_filter();', + ], + true + ); + + $input_actions .= html_print_submit_button( + __('Update filter'), + 'srcbutton', + false, + [ + 'icon' => 'update', + 'mode' => 'mini', + 'onclick' => 'save_update_filter();', + ], + true + ); + + html_print_div( + [ + 'id' => 'update_filter_row', + 'class' => 'action-buttons', + 'content' => $input_actions, + ], + false + ); } else { include 'general/noaccess.php'; } @@ -1983,29 +2054,34 @@ if (check_login()) { ?> + id_agente = (int) get_parameter('id_agente', 0); - $this->operation = get_parameter('operation', 0); + $this->id_agente = (int) get_parameter('id_agente'); + $this->operation = (int) get_parameter('operation'); $this->community = (string) get_parameter('community', 'public'); $this->ip = (string) get_parameter('select_ips'); $this->snmp_version = (string) get_parameter('select_version'); @@ -389,7 +389,13 @@ class ExternalTools extends HTML 'id' => '', 'class' => 'action-buttons', 'style' => 'width: 100%', - 'content' => html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"', true), + 'content' => html_print_submit_button( + __('Update'), + 'update_button', + false, + [ 'icon' => 'update' ], + true + ), ], true ); @@ -522,14 +528,16 @@ class ExternalTools extends HTML // Form table. $table = new StdClass(); - $table->class = 'databox filters w100p'; + $table->class = 'fixed_filter_bar'; $table->id = 'externalToolTable'; - + $table->cellstyle['captions'][0] = 'width: 0'; + $table->cellstyle['captions'][1] = 'width: 0'; + $table->cellstyle['captions'][2] = 'width: 0'; $table->data = []; - $table->data[0][0] = __('Operation'); + $table->data['captions'][0] = __('Operation'); - $table->data[0][1] = html_print_select( + $table->data['inputs'][0] = html_print_select( $commandList, 'operation', $this->operation, @@ -539,8 +547,8 @@ class ExternalTools extends HTML true ); - $table->data[0][2] = __('IP Adress'); - $table->data[0][3] = html_print_select( + $table->data['captions'][1] = __('IP Adress'); + $table->data['inputs'][1] = html_print_select( $ipsSelect, 'select_ips', $principal_ip, @@ -550,10 +558,10 @@ class ExternalTools extends HTML true ); - $table->cellclass[0][4] = 'snmpcolumn'; - $table->data[0][4] = __('SNMP Version'); - $table->data[0][4] .= ' '; - $table->data[0][4] .= html_print_select( + $table->cellclass['captions'][2] = 'snmpcolumn'; + $table->cellclass['inputs'][2] = 'snmpcolumn'; + $table->data['captions'][2] = __('SNMP Version'); + $table->data['inputs'][2] = html_print_select( [ '1' => 'v1', '2c' => 'v2c', @@ -566,10 +574,10 @@ class ExternalTools extends HTML true ); - $table->cellclass[0][5] = 'snmpcolumn'; - $table->data[0][5] = __('SNMP Community'); - $table->data[0][5] .= ' '; - $table->data[0][5] .= html_print_input_text( + $table->cellclass['captions'][3] = 'snmpcolumn'; + $table->cellclass['inputs'][3] = 'snmpcolumn'; + $table->data['captions'][3] = __('SNMP Community'); + $table->data['inputs'][3] = html_print_input_text( 'community', $this->community, '', @@ -578,7 +586,22 @@ class ExternalTools extends HTML true ); - $table->data[0][6] = ""; + $table->data['inputs'][4] = html_print_div( + [ + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + __('Execute'), + 'submit', + false, + [ + 'icon' => 'cog', + 'mode' => 'mini', + ], + true + ), + ], + true + ); // Output string. $output = ''; @@ -698,10 +721,10 @@ class ExternalTools extends HTML try { // If caption is not added, don't show anything. if (empty($caption) === false) { - $output .= sprintf('

%s

', $caption); + $output .= sprintf('

%s

', $caption); } - $output .= '
';
+            $output .= '
';
 
             // Only perform an execution if command is passed. Avoid errors.
             if (empty($command) === false) {
@@ -766,7 +789,7 @@ class ExternalTools extends HTML
                     'format'         => '-Oqn',
                 ];
 
-                echo '

'.__('SNMP information for ').$ip.'

'; + echo '

'.__('SNMP information for ').$ip.'

'; $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.3.0'; $result = get_h_snmpwalk($snmp_obj); @@ -828,7 +851,7 @@ class ExternalTools extends HTML html_print_table($table); } else if ((int) $operation === COMMAND_DIGWHOIS) { - echo '

'.__('Domain and IP information for ').$ip.'

'; + echo '

'.__('Domain and IP information for ').$ip.'

'; // Dig execution. $dig = $this->whereIsTheCommand('dig'); diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index f2b6ed3630..ca74f7dc46 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -311,7 +311,7 @@ class HTML public function printBreadcrum() { return implode( - ' / ', + ' / ', $this->breadcrum ); } @@ -398,7 +398,7 @@ class HTML * * @return void */ - public static function printGoBackButton($url=null) + public static function printGoBackButton($url=null, $return=false) { if (isset($url) === false) { $url = ui_get_full_url( @@ -418,14 +418,21 @@ class HTML 'name' => 'submit', 'label' => __('Go back'), 'type' => 'submit', - 'attributes' => 'class="sub cancel"', + 'attributes' => [ + 'icon' => 'back', + 'mode' => 'secondary', + ], 'return' => true, ], ], ], ]; - self::printForm($form); + if ($return === true) { + return self::printForm($form, $return); + } + + self::printForm($form, $return); } @@ -537,7 +544,7 @@ class HTML 'container_class' => $input['toggle_container_class'], 'img_a' => $input['toggle_img_a'], 'img_b' => $input['toggle_img_b'], - 'clean' => (isset($input['toggle_clean']) ? $input['toggle_clean'] : true), + 'clean' => (isset($input['toggle_clean']) ? $input['toggle_clean'] : false), ] ); } else { @@ -803,10 +810,13 @@ class HTML $output_head .= 'id="'.$form['id'].'" '; } + $output_head .= 'class="max_floating_element_size '; if (isset($form['class']) === true) { - $output_head .= 'class="discovery '.$form['class'].'" '; + $output_head .= 'discovery '.$form['class'].' '; } + $output_head .= '"'; + if (isset($form['onsubmit']) === true) { $output_head .= 'onsubmit="'.$form['onsubmit'].'" '; } @@ -870,7 +880,7 @@ class HTML $output .= '
'; } else { if ($print_white_box === true) { - $output .= '
'; + $output .= '
'; } $output .= '
    '; @@ -936,7 +946,7 @@ class HTML $cb_function = $data['cb_function']; $cb_args = $data['cb_args']; - $output_head = '
    '; if (isset($form['title']) === true && empty($form['title']) === false) { @@ -1077,7 +1087,7 @@ class HTML $cb_function = $data['cb_function']; $cb_args = $data['cb_args']; - $output_head = ''; if ($return === false) { @@ -1095,7 +1105,7 @@ class HTML error_log('Error executing wizard callback: ', $e->getMessage()); } - $output = '
    '; + $output = '
    '; $output .= '
      '; foreach ($inputs as $input) { diff --git a/pandora_console/include/class/ManageNetScanScripts.class.php b/pandora_console/include/class/ManageNetScanScripts.class.php index a047cfcb61..a65f728ef1 100644 --- a/pandora_console/include/class/ManageNetScanScripts.class.php +++ b/pandora_console/include/class/ManageNetScanScripts.class.php @@ -451,13 +451,13 @@ class ManageNetScanScripts extends Wizard ); echo html_print_input_image( 'delete', - 'images/cross.png', + 'images/delete.svg', 1, - '', + 'width:40px;', true, [ 'title' => __('Delete Script'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); echo ''; @@ -468,7 +468,19 @@ class ManageNetScanScripts extends Wizard echo "
      "; echo html_print_input_hidden('page', 1, true); - echo ""; + html_print_div( + [ + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + __('Add'), + 'crtbutton', + false, + [ 'icon' => 'next' ], + true + ), + ], + true + ); echo '
      '; } else { ui_print_info_message( @@ -515,7 +527,7 @@ class ManageNetScanScripts extends Wizard $url .= '&wiz=hd&mode=managenetscanscripts'; if ($id_script !== 0) { - echo '
      '; + echo ''; echo html_print_input_hidden('page', 0, true); echo html_print_input_hidden( 'operation_scp', @@ -523,7 +535,7 @@ class ManageNetScanScripts extends Wizard true ); } else { - echo ''; + echo ''; echo html_print_input_hidden('page', 0, true); echo html_print_input_hidden( 'operation_scp', @@ -535,11 +547,7 @@ class ManageNetScanScripts extends Wizard $table = new stdClass(); $table->width = '100%'; $table->id = 'table-form'; - $table->class = 'databox filters'; - $table->style = []; - $table->style[0] = 'font-weight: bold'; - $table->style[2] = 'font-weight: bold'; - $table->data = []; + $table->class = 'databox filter-table-adv'; $data = []; $data[0] = __('Name'); @@ -756,16 +764,33 @@ class ManageNetScanScripts extends Wizard html_print_table($table); - echo ''; - echo '
      '; - if ($id_script === 0) { - echo ""; + $buttonName = 'crtbutton'; + $buttonCaption = __('Create'); + $buttonIcon = 'wand'; } else { - echo ""; + $buttonName = 'updbutton'; + $buttonCaption = __('Update'); + $buttonIcon = 'update'; } - echo '
      '; + html_print_action_buttons( + html_print_div( + [ + 'class' => 'action-buttons', + 'content' => html_print_submit_button( + $buttonCaption, + $buttonName, + false, + [ 'icon' => $buttonIcon ], + true + ), + ], + true + ) + ); + + echo ''; ui_require_javascript_file('pandora_modules'); } diff --git a/pandora_console/include/class/Menu.class.php b/pandora_console/include/class/Menu.class.php new file mode 100644 index 0000000000..bce38a89db --- /dev/null +++ b/pandora_console/include/class/Menu.class.php @@ -0,0 +1,126 @@ +ACL_el_que_sea') === true) { + haz cosas aqui + } + + */ + + public function __construct( + private string $name, + private array $items=[], + private array $menu=[] + ) { + + } + + + /** + * Create Item function. + * + * @param MenuItem $menuItem Item for print. + * + * @return array. + */ + public function generateItem(MenuItem $menuItem) + { + // Start with empty element. + $item = []; + if ($menuItem->canBeDisplayed() === true) { + // Handle of information. + if (empty($menuItem->getUrl()) === false) { + $urlPath = $menuItem->getUrl(); + } else { + $urlPath = ui_get_full_url( + $menuItem->getSec().'/'.$menuItem->getSec2().'/'.$menuItem->getParameters() + ); + } + + // Creation of the line. + $item[] = '
    • '; + + // Create the link if is neccesary. + if (empty($urlPath) === false) { + $item[] = sprintf( + '%s', + $urlPath, + $menuItem->getText() + ); + } + + // Check if this item has submenu. If is the case, create it. + if ($menuItem->hasSubmenu() === true) { + $item[] = '
        '; + $itemSubMenu = $menuItem->getSubmenu(); + foreach ($itemSubMenu as $subMenu) { + $item[] = $this->generateItem($subMenu); + } + + $item[] = '
      '; + } + + $item[] = '
    • '; + } + + return $item; + } + + + /** + * Generate the menu. + * + * @return void. + */ + public function generateMenu() + { + $output = []; + /* + Estructura +
        +
      • level0.item1
      • +
      • level0.item2
      • +
          +
        • level1.item1
        • +
        • level1.item2
        • +
        +
      • level0.item3
      • +
      + */ + $output[] = '
        '; + foreach ($this->items as $menuItem) { + // If the item must be displayed. + $this->generateItem($menuItem); + } + + $output[] = '
      '; + + $this->menu[] = $output; + + } + + + /** + * Prints the menu. + * + * @return void. + */ + public function printMenu() + { + if (empty($this->menu) === false) { + foreach ($this->menu as $element) { + echo $element."\n"; + } + } + } + + +} diff --git a/pandora_console/include/class/MenuItem.class.php b/pandora_console/include/class/MenuItem.class.php new file mode 100644 index 0000000000..3ec088ac72 --- /dev/null +++ b/pandora_console/include/class/MenuItem.class.php @@ -0,0 +1,431 @@ +id) === true && empty($this->text) === false) { + $this->id = str_replace(' ', '_', $text); + } + + return $this; + } + + + /** + * Set Text. The caption of the option. + * + * @param string $text Text. + * + * @return void. + */ + public function setText(string $text) + { + $this->text = $text; + } + + + /** + * Get Text + * + * @return string. + */ + public function getText() + { + return $this->text; + } + + + /** + * Set URL. Raw URL avoid sec and sec2 information. + * + * @param string $url Url. + * + * @return void. + */ + public function setUrl(string $url) + { + $this->url = $url; + } + + + /** + * Get URL + * + * @return string. + */ + public function getUrl() + { + return $this->url; + } + + + /** + * Set sec + * + * @param string $sec Sec. + * + * @return void. + */ + public function setSec(string $sec) + { + $this->sec = $sec; + } + + + /** + * Get sec + * + * @return string. + */ + public function getSec() + { + return $this->sec; + } + + + /** + * Set sec2 + * + * @param string $sec2 Sec2. + * + * @return void. + */ + public function setSec2(string $sec2) + { + $this->sec2 = $sec2; + } + + + /** + * Get sec2 + * + * @return string. + */ + public function getSec2() + { + return $this->sec2; + } + + + /** + * Set parameters. Added parameters for builded url (sec + sec2). + * + * @param string $parameters Parameters. + * + * @return void. + */ + public function setParameters(string $parameters) + { + $this->parameters = $parameters; + } + + + /** + * Get parameters + * + * @return string. + */ + public function getParameters() + { + return $this->parameters; + } + + + /** + * Set id. This is useful for identify the option selected. + * + * @param string $id Id. + * + * @return void. + */ + public function setId(string $id) + { + $this->id = $id; + } + + + /** + * Get id + * + * @return string. + */ + public function getId() + { + return $this->id; + } + + + /** + * Set icon. Must be relative path. + * + * @param string $icon Icon. + * + * @return void. + */ + public function setIcon(string $icon) + { + $this->icon = $icon; + } + + + /** + * Get icon + * + * @return string. + */ + public function getIcon() + { + return $this->icon; + } + + + /** + * Set class. + * + * @param string $class Class. + * + * @return void. + */ + public function setClass(string $class) + { + $this->class = $class; + } + + + /** + * Get class + * + * @return string. + */ + public function getClass() + { + return $this->class; + } + + + /** + * Set submenu. Array with options under this selection. + * + * @param array $submenu Submenu. + * + * @return void. + */ + public function setSubmenu(array $submenu) + { + $this->submenu = $submenu; + } + + + /** + * Get Submenu + * + * @return array. + */ + public function getSubmenu() + { + return $this->submenu; + } + + + /** + * Set ACLs. Attach only allowed ACLs in an array. + * + * @param array $acl ACL. + * + * @return void. + */ + public function setACL(array $acl) + { + $this->acl = $acl; + } + + + /** + * Get ACLs + * + * @return array. + */ + public function getACL() + { + return $this->acl; + } + + + /** + * Set activation token. + * + * @param array $activationToken ACL. + * + * @return void. + */ + public function setActivationToken(array $activationToken) + { + $this->activationToken = $activationToken; + } + + + /** + * Get activation token. + * + * @return array. + */ + public function getActivationToken() + { + return $this->activationToken; + } + + + /** + * Set refr + * + * @param integer $refr Refr. + * + * @return void. + */ + public function setRefr(int $refr) + { + $this->refr = $refr; + } + + + /** + * Get Refr + * + * @return integer. + */ + public function getRefr() + { + return $this->refr; + } + + + /** + * Set display. The item will be exists if this value is true. + * + * @param boolean $display Display. + * + * @return void. + */ + public function setDisplay(bool $display) + { + $this->display = $display; + } + + + /** + * Get Display + * + * @return boolean. + */ + public function getDisplay() + { + return $this->display; + } + + + /** + * Set enabled + * + * @param boolean $enabled Enabled. + * + * @return void. + */ + public function setEnabled(bool $enabled) + { + $this->enabled = $enabled; + } + + + /** + * Get enabled + * + * @return boolean. + */ + public function getEnabled() + { + return $this->enabled; + } + + + /** + * Returns true if this object have submenu. + * + * @return boolean. + */ + public function hasSubmenu() + { + return empty($this->getSubmenu()) === false; + } + + + /** + * Returns true if this object can be displayed. + * + * @return boolean. + */ + public function canBeDisplayed() + { + // Global config. + global $config; + $response = true; + + if ($this->getDisplay() === false) { + // Display value is false. + $response = false; + } else if (empty($this->getACL()) === false) { + // Check all the ACLs. + $acls = $this->getACL(); + foreach ($acls as $acl) { + $response = check_acl($config['id_user'], 0, $acl); + // In false case, end the check. + if ($response === false) { + break; + } + } + } + + return $response; + } + + +} diff --git a/pandora_console/include/class/ModuleTemplates.class.php b/pandora_console/include/class/ModuleTemplates.class.php index 782d3bb82d..2e777bdf4c 100644 --- a/pandora_console/include/class/ModuleTemplates.class.php +++ b/pandora_console/include/class/ModuleTemplates.class.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ============================================================================ - * Copyright (c) 2005-2021 Artica Soluciones Tecnologicas + * Copyright (c) 2005-2023 Artica Soluciones Tecnologicas * Please see http://pandorafms.org for full contribution list * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -264,27 +264,11 @@ class ModuleTemplates extends HTML */ private function ajaxMsg($type, $msg) { - if ($type == 'error') { - echo json_encode( - [ - $type => ui_print_error_message( - __($msg), - '', - true - ), - ] - ); - } else { - echo json_encode( - [ - $type => ui_print_success_message( - __($msg), - '', - true - ), - ] - ); - } + echo json_encode( + [ + $type => __($msg), + ] + ); exit; } @@ -436,64 +420,27 @@ class ModuleTemplates extends HTML return; } - // It's important to keep the structure and order in the same way for backwards compatibility. - switch ($config['dbtype']) { - case 'mysql': - $sql = sprintf( - ' - SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval, - components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid, - components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter, - components.max_timeout, components.max_retries, components.history_data, components.min_warning, components.max_warning, components.str_warning, components.min_critical, - components.max_critical, components.str_critical, components.min_ff_event, components.dynamic_interval, components.dynamic_max, components.dynamic_min, components.dynamic_two_tailed, comp_group.name AS group_name, components.critical_instructions, components.warning_instructions, components.unknown_instructions - FROM `tnetwork_component` AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group - WHERE tpc.id_nc = components.id_nc - AND components.id_group = comp_group.id_sg - AND tpc.id_np = %d', - $this->id_np - ); - break; - - case 'postgresql': - $sql = sprintf( - ' - SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval, - components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid, - components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter, - components.max_timeout, components.max_retries, components.history_data, components.min_warning, components.max_warning, components.str_warning, components.min_critical, - components.max_critical, components.str_critical, components.min_ff_event, comp_group.name AS group_name, components.critical_instructions, components.warning_instructions, components.unknown_instructions - FROM "tnetwork_component" AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group - WHERE tpc.id_nc = components.id_nc - AND components.id_group = comp_group.id_sg - AND tpc.id_np = %d', - $this->id_np - ); - break; - - case 'oracle': - $sql = sprintf( - ' - SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval, - components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid, - components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter, - components.max_timeout, components.max_retries, components.history_data, components.min_warning, components.max_warning, components.str_warning, components.min_critical, - components.max_critical, components.str_critical, components.min_ff_event, comp_group.name AS group_name, components.critical_instructions, components.warning_instructions, components.unknown_instructions - FROM tnetwork_component AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group - WHERE tpc.id_nc = components.id_nc - AND components.id_group = comp_group.id_sg - AND tpc.id_np = %d', - $this->id_np - ); - break; - } + $sql = sprintf( + ' + SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval, + components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid, + components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter, + components.max_timeout, components.max_retries, components.history_data, components.min_warning, components.max_warning, components.str_warning, components.min_critical, + components.max_critical, components.str_critical, components.min_ff_event, components.dynamic_interval, components.dynamic_max, components.dynamic_min, components.dynamic_two_tailed, comp_group.name AS group_name, components.critical_instructions, components.warning_instructions, components.unknown_instructions + FROM `tnetwork_component` AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group + WHERE tpc.id_nc = components.id_nc + AND components.id_group = comp_group.id_sg + AND tpc.id_np = %d', + $this->id_np + ); $components = db_get_all_rows_sql($sql); $row_names = []; $inv_names = []; - // Find the names of the rows that we are getting and throw away the duplicate numeric keys + // Find the names of the rows that we are getting and throw away the duplicate numeric keys. foreach ($components[0] as $row_name => $detail) { - if (is_numeric($row_name)) { + if (is_numeric($row_name) === true) { $inv_names[] = $row_name; } else { $row_names[] = $row_name; @@ -501,18 +448,18 @@ class ModuleTemplates extends HTML } $fileName = io_safe_output($profile_info['name']); - // Send headers to tell the browser we're sending a file + // Send headers to tell the browser we're sending a file. header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename='.preg_replace('/\s/', '_', $fileName).'.csv'); header('Pragma: no-cache'); header('Expires: 0'); setDownloadCookieToken(); - // Clean up output buffering + // Clean up output buffering. while (@ob_end_clean()) { } - // Then print the first line (row names) + // Then print the first line (row names). echo '"'.implode('"'.$config['csv_divider'].'"', $row_names).'"'; echo "\n"; @@ -745,7 +692,7 @@ class ModuleTemplates extends HTML 'action' => $this->baseUrl, 'id' => 'add_module_form', 'method' => 'POST', - 'class' => 'modal', + 'class' => 'modal filter-list-adv', 'extra' => '', ]; @@ -873,12 +820,20 @@ class ModuleTemplates extends HTML ] ); - ui_pagination($countModuleTemplates, $this->baseUrl, $this->offset); + $tablePagination = ui_pagination( + $countModuleTemplates, + $this->baseUrl, + $this->offset, + 0, + true, + 'offset', + false + ); // Create the table with Module Block list. - $table = new StdClasS(); + $table = new stdClass(); $table->class = 'databox data '; $table->width = '75%'; - $table->styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;'; + $table->styleTable = 'border: 1px solid #ddd;'; $table->rowid = []; $table->data = []; @@ -908,43 +863,60 @@ class ModuleTemplates extends HTML $data[0] = html_print_checkbox_extended('delete_multiple[]', $row['id_np'], false, false, '', 'class="check_delete"', true); $data[1] = ''.io_safe_output($row['name']).''; $data[2] = ui_print_truncate_text(io_safe_output($row['description']), 'description', true, true, true, '[…]'); - $table->cellclass[][3] = 'action_buttons'; + $table->cellclass[][3] = 'table_action_buttons'; $data[3] = html_print_input_image( 'delete_profile', - 'images/cross.png', + 'images/delete.svg', $row['id_np'], - '', + 'width:40px', true, [ 'onclick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); $data[3] .= html_print_input_image( 'export_profile', - 'images/csv.png', + 'images/file-csv.svg', $row['id_np'], '', true, [ 'title' => 'Export tdaso CSV', - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); - $data[3] = ''.html_print_image('images/cross.png', true, ['title' => __('Delete'), 'class' => 'invert_filter']).''; - $data[3] .= ''.html_print_image('images/csv.png', true, ['title' => __('Export to CSV'), 'class' => 'invert_filter']).''; + $data[3] = ''; + $data[3] .= html_print_image( + 'images/delete.svg', + true, + [ + 'title' => __('Delete'), + 'class' => 'invert_filter main_menu_icon', + ] + ); + $data[3] .= ''; + $data[3] .= ''; + $data[3] .= html_print_image( + 'images/file-csv.svg', + true, + [ + 'title' => __('Export to CSV'), + 'class' => 'invert_filter main_menu_icon', + ] + ); + $data[3] .= ''; array_push($table->data, $data); } html_print_table($table); - $output = '
      '; - $form = [ 'method' => 'POST', 'action' => $this->baseUrl, 'id' => 'main_management_form', + 'class' => 'flex_center', ]; $inputs[] = [ @@ -961,7 +933,7 @@ class ModuleTemplates extends HTML 'label' => __('Create'), 'name' => 'crt', 'type' => 'submit', - 'attributes' => 'class="sub wand"', + 'attributes' => ['icon' => 'wand'], 'return' => true, ], ]; @@ -971,22 +943,29 @@ class ModuleTemplates extends HTML 'label' => __('Delete selected'), 'name' => 'erase', 'type' => 'button', - 'attributes' => 'class="sub cancel"', + 'attributes' => [ + 'icon' => 'delete', + 'mode' => 'secondary', + ], 'return' => true, ], ]; - $output .= $this->printForm( + html_print_action_buttons( + $this->printForm( + [ + 'form' => $form, + 'inputs' => $inputs, + ], + true + ), [ - 'form' => $form, - 'inputs' => $inputs, - ], - true + 'type' => 'data_table', + 'class' => 'fixed_action_buttons', + 'right_content' => $tablePagination, + ] ); - $output .= '
      '; - - echo $output; } @@ -999,16 +978,16 @@ class ModuleTemplates extends HTML { global $config; - $createNewTemplate = ($this->id_np == 0) ? true : false; + $createNewTemplate = ((int) $this->id_np === 0); - if ($createNewTemplate) { + if ($createNewTemplate === true) { // Assignation for submit button. - $formButtonClass = 'sub wand'; + $formButtonClass = 'wand'; $formAction = 'create'; $formButtonLabel = __('Create'); } else { // Assignation for submit button. - $formButtonClass = 'sub upd'; + $formButtonClass = 'update'; $formAction = 'update'; $formButtonLabel = __('Update'); } @@ -1093,42 +1072,38 @@ class ModuleTemplates extends HTML ], ]; - $availableButtons = []; - - $availableButtons[] = [ - 'arguments' => [ - 'name' => 'action_button', - 'label' => $formButtonLabel, - 'type' => 'submit', - 'attributes' => 'class="float-right '.$formButtonClass.'"', - 'return' => true, - ], - ]; - - if ($createNewTemplate === false) { - $availableButtons[] = [ - 'arguments' => [ - 'name' => 'add_components_button', - 'label' => __('Add components'), - 'type' => 'button', - 'attributes' => 'class="float-right sub cog"', - 'script' => 'showAddComponent();', - 'return' => true, - ], - ]; - } - - $inputs[] = [ - 'class' => 'action_button_list', - 'direct' => false, - 'wrapper' => 'div', - 'block_content' => $availableButtons, - ]; - // Required for PEN field. ui_require_jquery_file('tag-editor'); ui_require_css_file('jquery.tag-editor'); + $buttons = $this->printInput( + [ + 'name' => 'action_button', + 'label' => $formButtonLabel, + 'type' => 'submit', + 'attributes' => [ + 'icon' => $formButtonClass, + 'form' => 'module_template_form', + ], + 'return' => true, + 'width' => 'initial', + ] + ); + + if ($createNewTemplate === false) { + $buttons .= $this->printInput( + [ + 'name' => 'add_components_button', + 'label' => __('Add components'), + 'type' => 'button', + 'attributes' => [ 'icon' => 'cog' ], + 'script' => 'showAddComponent();', + 'return' => true, + 'width' => 'initial', + ] + ); + } + if ($createNewTemplate === false) { // Get the data. $sql = sprintf( @@ -1174,18 +1149,18 @@ class ModuleTemplates extends HTML $blockComponentList = chop($blockComponentList, ','); // Title of Block. - $blockTitle = '
      '; + $blockTitle = '
      '; $blockTitle .= $blockTable['name']; $blockTitle .= '
      '; $blockTitle .= html_print_input_image( 'del_block_'.$id_group.'_', - 'images/cross.png', + 'images/delete.svg', 1, - false, + 'width: 40px', true, [ 'title' => __('Delete this block'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', 'onclick' => 'if(confirm(\''.__('Do you want delete this block?').'\')){deleteModuleTemplate(\'block\',\''.$blockComponentList.'\')};return false;', ] ); @@ -1195,7 +1170,7 @@ class ModuleTemplates extends HTML $table = new StdClasS(); $table->class = 'databox data border_bt'; $table->width = '75%'; - $table->styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;'; + $table->styleTable = 'margin: 0; border: 1px solid #ddd;'; $table->rowid = []; $table->data = []; @@ -1229,33 +1204,33 @@ class ModuleTemplates extends HTML switch ($module['id_format']) { case MODULE_NETWORK: $formatInfo = html_print_image( - 'images/network.png', + 'images/network-server@os.svg', true, [ 'title' => __('Network module'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); break; case MODULE_WMI: $formatInfo = html_print_image( - 'images/wmi.png', + 'images/WMI@svg.svg', true, [ 'title' => __('WMI module'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); break; case MODULE_PLUGIN: $formatInfo = html_print_image( - 'images/plugin.png', + 'images/plugins@svg.svg', true, [ 'title' => __('Plug-in module'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); break; @@ -1276,13 +1251,13 @@ class ModuleTemplates extends HTML $data[3] = mb_strimwidth(io_safe_output($module['description']), 0, 150, '...'); $data[4] = html_print_input_image( 'del_module_'.$module['component_id'].'_', - 'images/cross.png', + 'images/delete.svg', 1, - '', + 'width:40px;', true, [ 'title' => __('Delete this module'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', 'onclick' => 'if(confirm(\''.__('Do you want delete this module?').'\')){deleteModuleTemplate(\'module\','.$module['component_id'].')};return false;', ] ); @@ -1314,7 +1289,9 @@ class ModuleTemplates extends HTML echo ''; } - $this->printGoBackButton($this->baseUrl); + $buttons .= $this->printGoBackButton($this->baseUrl, true); + + html_print_action_buttons($buttons); } @@ -1496,30 +1473,31 @@ class ModuleTemplates extends HTML var listValidPens = $("#hidden-valid-pen").val(); try { - listValidPens = listValidPens.split(','); + if(listValidPens != undefined) { + listValidPens = listValidPens.split(','); + //Adding tagEditor for PEN management. + $("#text-pen").tagEditor({ + beforeTagSave: function(field, editor, tags, tag, val) { + if (listValidPens.indexOf(val) == -1) { + return false; + } + }, + autocomplete: { + source: penRefs); ?> + + } + }); + } } catch (e) { console.error(e); return; } - //Adding tagEditor for PEN management. - $("#text-pen").tagEditor({ - beforeTagSave: function(field, editor, tags, tag, val) { - if (listValidPens.indexOf(val) == -1) { - return false; - } - }, - autocomplete: { - source: penRefs); ?> - - } - }); //Values for add. $("#add-modules-components").change(function() { var valores = $("#add-modules-components") .val() .join(","); - //$("#hidden-add-modules-components-values").val(valores); }); }); diff --git a/pandora_console/include/class/NetworkMap.class.php b/pandora_console/include/class/NetworkMap.class.php index 7b43a3daf6..701eb4ecfb 100644 --- a/pandora_console/include/class/NetworkMap.class.php +++ b/pandora_console/include/class/NetworkMap.class.php @@ -782,7 +782,9 @@ class NetworkMap if ($this->network) { // Network map, based on direct network. $nodes = networkmap_get_nodes_from_ip_mask( - $this->network + $this->network, + false, + ' ' ); } else if ($this->mapOptions['map_filter']['empty_map']) { // Empty map returns no data. @@ -792,17 +794,22 @@ class NetworkMap || $this->mapOptions['map_filter']['dont_show_subgroups'] == 1 ) { // Show only current selected group. - $filter['id_grupo'] = $this->idGroup; + $filter['id_grupo'] = explode(',', $this->idGroup); } else { // Show current group and children. - $childrens = groups_get_children($this->idGroup, null, true); - if (!empty($childrens)) { - $childrens = array_keys($childrens); + foreach (explode(',', $this->idGroup) as $key => $group) { + $childrens = groups_get_children($group, null, true); + if (!empty($childrens)) { + $childrens = array_keys($childrens); - $filter['id_grupo'] = $childrens; - $filter['id_grupo'][] = $this->idGroup; - } else { - $filter['id_grupo'] = $this->idGroup; + if (empty($filter['id_grupo']) === false) { + $filter['id_grupo'] = array_merge($filter['id_grupo'], $childrens); + } else { + $filter['id_grupo'] = $childrens; + } + } else { + $filter['id_grupo'][] = $group; + } } } @@ -1189,6 +1196,10 @@ class NetworkMap $head .= 'overlap="scalexy";'; } + if ($layout == 'spring1' || $layout == 'spring2') { + $head .= 'sep="'.$node_sep.'";'; + } + if ($layout == 'flat') { $head .= 'ranksep="'.$rank_sep.'";'; } @@ -2558,7 +2569,7 @@ class NetworkMap false, true, true, - true, + false, true, true ); @@ -3011,17 +3022,30 @@ class NetworkMap $table = new StdClass(); $table->id = 'node_details'; + $table->class = 'filter-table-adv'; $table->width = '100%'; $table->data = []; - $table->data[0][0] = ''.__('Agent').''; - $table->data[0][1] = ''; - $table->data[1][0] = ''.__('Adresses').''; - $table->data[1][1] = ''; - $table->data[2][0] = ''.__('OS type').''; - $table->data[2][1] = ''; - $table->data[3][0] = ''.__('Group').''; - $table->data[3][1] = ''; + + $table->data[0][] = html_print_label_input_block( + __('Agent'), + html_print_div(['id' => 'content_node_details-0-1'], true) + ); + + $table->data[0][] = html_print_label_input_block( + __('Adresses'), + html_print_div(['id' => 'content_node_details-1-1'], true) + ); + + $table->data[1][] = html_print_label_input_block( + __('OS type'), + html_print_div(['id' => 'content_node_details-2-1'], true) + ); + + $table->data[1][] = html_print_label_input_block( + __('Group'), + html_print_div(['id' => 'content_node_details-3-1'], true) + ); $output .= ui_toggle( html_print_table($table, true), @@ -3060,72 +3084,94 @@ class NetworkMap $table = new StdClass(); $table->id = 'node_options'; + $table->class = 'filter-table-adv'; $table->width = '100%'; $table->data = []; - $table->data[0][0] = __('Shape'); - $table->data[0][1] = html_print_select( - [ - 'circle' => __('Circle'), - 'square' => __('Square'), - 'rhombus' => __('Rhombus'), - ], - 'shape', - '', - 'javascript:', - '', - 0, - true - ).' '; - $table->data['node_name'][0] = __('Name'); - $table->data['node_name'][1] = html_print_input_text( - 'edit_name_node', - '', - __('name node'), - '20', - '50', - true + $table->data[0][] = html_print_label_input_block( + __('Shape'), + html_print_select( + [ + 'circle' => __('Circle'), + 'square' => __('Square'), + 'rhombus' => __('Rhombus'), + ], + 'shape', + '', + 'javascript:', + '', + 0, + true + ) ); - $table->data['node_name'][2] = html_print_button( - __('Update node'), - '', + + $table->data['node_name'][] = html_print_label_input_block( + __('Name'), + html_print_input_text( + 'edit_name_node', + '', + __('name node'), + '20', + '50', + true + ) + ); + + $table->data['fictional_node_name'][] = html_print_label_input_block( + __('Name'), + html_print_input_text( + 'edit_name_fictional_node', + '', + __('name fictional node'), + '20', + '50', + true + ) + ); + + $table->data['fictional_node_networkmap_link'][] = html_print_label_input_block( + __('Networkmap to link'), + html_print_select( + $list_networkmaps, + 'edit_networkmap_to_link', + '', + '', + '', + 0, + true + ) + ); + + $buttons = []; + $buttons[] = html_print_button( + __('Update fictional node'), + 'upd_fictional_node', false, '', - 'class="sub next"', + ['icon' => 'next'], true ); - $table->data['fictional_node_name'][0] = __('Name'); - $table->data['fictional_node_name'][1] = html_print_input_text( - 'edit_name_fictional_node', - '', - __('name fictional node'), - '20', - '50', - true - ); - $table->data['fictional_node_networkmap_link'][0] = __('Networkmap to link'); - $table->data['fictional_node_networkmap_link'][1] = html_print_select( - $list_networkmaps, - 'edit_networkmap_to_link', - '', - '', - '', - 0, - true - ); - $table->data['fictional_node_update_button'][0] = ''; - $table->data['fictional_node_update_button'][1] = html_print_button( - __('Update fictional node'), - '', + $buttons[] = html_print_button( + __('Update node'), + 'upd_only_node', false, - 'add_fictional_node();', - 'class="sub next"', + 'update_node_name()', + ['icon' => 'next'], + true + ); + + $nodeUpdateTable = html_print_table($table, true); + $nodeUpdateTable .= html_print_div( + [ + 'class' => 'action-buttons w100p float-right', + 'content' => implode('', $buttons), + ], true ); $output .= ui_toggle( - html_print_table($table, true), + $nodeUpdateTable, __('Node options'), __('Node options'), '', @@ -3199,9 +3245,9 @@ class NetworkMap $table->data['template_row']['node_target'] = ''; $table->data['template_row']['edit'] = ''; - $table->data['template_row']['edit'] .= ''; + $table->data['template_row']['edit'] .= ''; // '.html_print_image('images/config.png', true, ['class' => 'invert_filter']).''; - $table->data['template_row']['edit'] .= ''.html_print_image('images/delete.png', true, ['class' => 'invert_filter']).''; + $table->data['template_row']['edit'] .= ''.html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter', 'style' => 'padding: 10px']).''; $table->colspan['no_relations']['0'] = 5; $table->cellstyle['no_relations']['0'] = 'text-align: center;'; @@ -3230,6 +3276,7 @@ class NetworkMap $table = new stdClass(); $table->id = 'interface_link_table'; + $table->class = 'info_table'; $table->width = '100%'; $table->head['node_source_interface'] = __('Node source'); $table->head['interface_source_select'] = __('Interface source'); @@ -3272,27 +3319,31 @@ class NetworkMap $output .= '
      '; - $table->data['interface_row']['interface_link_button'] = html_print_button( - __('Add interface link'), - '', - false, - 'add_interface_link_js();', - 'class="sub"', + $output .= html_print_table($table, true); + $output .= html_print_div( + [ + 'class' => 'action-buttons', + 'content' => html_print_button( + __('Add interface link'), + '', + false, + 'add_interface_link_js();', + [ + 'icon' => 'wand', + 'mode' => 'mini', + ], + true + ), + ], true ); - $output .= html_print_table($table, true); $output .= '
      '; $output .= '