diff --git a/extras/Dockerfile b/extras/Dockerfile deleted file mode 100644 index 8f27c730b8..0000000000 --- a/extras/Dockerfile +++ /dev/null @@ -1,62 +0,0 @@ -# Dockerfile for the Pandora FMS image. -FROM debian:jessie - -# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added -RUN groupadd -r mysql && useradd -r -g mysql mysql - -RUN mkdir /docker-entrypoint-initdb.d - -# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db: -# File::Basename -# File::Copy -# Sys::Hostname -# Data::Dumper -RUN apt-get update && apt-get install -y perl pwgen git openssh-client --no-install-recommends && rm -rf /var/lib/apt/lists/* - -# gpg: key 5072E1F5: public key "MySQL Release Engineering " imported -RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5 - -ENV MYSQL_MAJOR 5.6 -ENV MYSQL_VERSION 5.6.29-1debian8 - -RUN echo "deb http://repo.mysql.com/apt/debian/ jessie mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list - -# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql) -# also, we set debconf keys to make APT a little quieter -RUN { \ - echo mysql-community-server mysql-community-server/data-dir select ''; \ - echo mysql-community-server mysql-community-server/root-pass password ''; \ - echo mysql-community-server mysql-community-server/re-root-pass password ''; \ - echo mysql-community-server mysql-community-server/remove-test-db select false; \ - } | debconf-set-selections \ - && apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* \ - && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql - -# comment out a few problematic configuration values -# don't reverse lookup hostnames, they are usually another container -RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \ - && echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf \ - && mv /tmp/my.cnf /etc/mysql/my.cnf - -VOLUME /var/lib/mysql - -COPY docker-entrypoint.sh /entrypoint.sh -COPY pandora.cnf /etc/mysql/conf.d -COPY pandora_initdb.sh /docker-entrypoint-initdb.d -ENTRYPOINT ["/entrypoint.sh"] - -# Make ssh dir -RUN mkdir /root/.ssh/ -# Copy over private key, and set permissions -RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config -RUN chown -R root:root /root/.ssh - - -#Clone the repo -RUN git config --global http.sslVerify false -RUN git clone -b develop --single-branch https://github.com/pandorafms/pandorafms.git /tmp/pandorafms -#RUN mv -f /tmp/pandorafms/pandora_console/pandoradb.sql /docker-entrypoint-initdb.d -#RUN mv -f /tmp/pandorafms/pandora_console/pandoradb_data.sql /docker-entrypoint-initdb.d - -EXPOSE 3306 -CMD ["mysqld"] diff --git a/extras/deploy-scripts/pandora_deploy_community.sh b/extras/deploy-scripts/pandora_deploy_community.sh index a0f08822e1..f660d5338d 100644 --- a/extras/deploy-scripts/pandora_deploy_community.sh +++ b/extras/deploy-scripts/pandora_deploy_community.sh @@ -72,7 +72,7 @@ check_pre_pandora () { export MYSQL_PWD=$DBPASS echo -en "${cyan}Checking environment ... ${reset}" - rpm -qa | grep pandora &>> /dev/null && local fail=true + rpm -qa | grep 'pandorafms_' &>> /dev/null && local fail=true [ -d "$PANDORA_CONSOLE" ] && local fail=true [ -f /usr/bin/pandora_server ] && local fail=true echo "use $DBNAME" | mysql -uroot -P$DBPORT -h$DBHOST &>> /dev/null && local fail=true diff --git a/extras/deploy-scripts/pandora_deploy_community_el8.sh b/extras/deploy-scripts/pandora_deploy_community_el8.sh index 5b549a2933..a4a80af6c5 100644 --- a/extras/deploy-scripts/pandora_deploy_community_el8.sh +++ b/extras/deploy-scripts/pandora_deploy_community_el8.sh @@ -76,7 +76,7 @@ check_pre_pandora () { export MYSQL_PWD=$DBPASS echo -en "${cyan}Checking environment ... ${reset}" - rpm -qa | grep pandora &>> /dev/null && local fail=true + rpm -qa | grep 'pandorafms_' &>> /dev/null && local fail=true [ -d "$PANDORA_CONSOLE" ] && local fail=true [ -f /usr/bin/pandora_server ] && local fail=true echo "use $DBNAME" | mysql -uroot -P$DBPORT -h$DBHOST &>> /dev/null && local fail=true @@ -350,8 +350,8 @@ vmware_dependencies=" \ perl-Crypt-Random-Seed \ perl-Math-Random-ISAAC \ perl-JSON \ + perl-Crypt-SSLeay \ http://firefly.artica.es/centos8/perl-Crypt-OpenSSL-AES-0.02-1.el8.x86_64.rpm \ - http://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/perl-Crypt-SSLeay-0.73_07-1.gf.el8.x86_64.rpm \ http://firefly.artica.es/centos8/VMware-vSphere-Perl-SDK-6.5.0-4566394.x86_64.rpm" execute_cmd "dnf install -y $vmware_dependencies" "Installing SDK VMware perl dependencies" diff --git a/extras/docker-entrypoint.sh b/extras/docker-entrypoint.sh deleted file mode 100755 index 90833a3eea..0000000000 --- a/extras/docker-entrypoint.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# if command starts with an option, prepend mysqld -if [ "${1:0:1}" = '-' ]; then - set -- mysqld "$@" -fi - -if [ "$1" = 'mysqld' ]; then - # Get config - DATADIR="$("$@" --verbose --help --log-bin-index=`mktemp -u` 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')" - - if [ ! -d "$DATADIR/mysql" ]; then - if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then - echo >&2 'error: database is uninitialized and password option is not specified ' - echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD' - exit 1 - fi - - mkdir -p "$DATADIR" - chown -R mysql:mysql "$DATADIR" - - echo 'Initializing database' - mysql_install_db --user=mysql --datadir="$DATADIR" --rpm --keep-my-cnf - echo 'Database initialized' - - "$@" --skip-networking & - pid="$!" - - mysql=( mysql --protocol=socket -uroot ) - - for i in {30..0}; do - if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then - break - fi - echo 'MySQL init process in progress...' - sleep 1 - done - if [ "$i" = 0 ]; then - echo >&2 'MySQL init process failed.' - exit 1 - fi - - if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then - # sed is for https://bugs.mysql.com/bug.php?id=20545 - mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql - fi - - if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then - MYSQL_ROOT_PASSWORD="$(pwgen -1 32)" - echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD" - fi - "${mysql[@]}" <<-EOSQL - -- What's done in this file shouldn't be replicated - -- or products like mysql-fabric won't work - SET @@SESSION.SQL_LOG_BIN=0; - - DELETE FROM mysql.user ; - CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; - GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; - DROP DATABASE IF EXISTS test ; - FLUSH PRIVILEGES ; - EOSQL - - if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then - mysql+=( -p"${MYSQL_ROOT_PASSWORD}" ) - fi - - if [ "$MYSQL_DATABASE" ]; then - echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}" - mysql+=( "$MYSQL_DATABASE" ) - fi - - if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then - echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}" - - if [ "$MYSQL_DATABASE" ]; then - echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}" - fi - - echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}" - fi - - echo - for f in /docker-entrypoint-initdb.d/*; do - case "$f" in - *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; - *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; - *) echo "$0: ignoring $f" ;; - esac - echo - done - - if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then - "${mysql[@]}" <<-EOSQL - ALTER USER 'root'@'%' PASSWORD EXPIRE; - EOSQL - fi - if ! kill -s TERM "$pid" || ! wait "$pid"; then - echo >&2 'MySQL init process failed.' - exit 1 - fi - - echo - echo 'MySQL init process done. Ready for start up.' - echo - fi - - chown -R mysql:mysql "$DATADIR" -fi - -exec "$@" diff --git a/extras/docker/Dockerfile b/extras/docker/Dockerfile deleted file mode 100644 index fbe8b38107..0000000000 --- a/extras/docker/Dockerfile +++ /dev/null @@ -1,57 +0,0 @@ -FROM pandorafms/pandorafms-base:centos7 - -# Build variables. -ARG BRANCH=develop -ARG DB_PASS=pandora - -# Clone the Pandora FMS repo. -RUN git clone --depth 1 -b "$BRANCH" https://github.com/pandorafms/pandorafms.git /tmp/pandorafms || \ - git clone --depth 1 -b develop https://github.com/pandorafms/pandorafms.git /tmp/pandorafms - -# Install the Pandora FMS Server. -RUN cd /tmp/pandorafms/pandora_server && \ -yes | ./pandora_server_installer --install && \ -sed -i "s/^dbuser.*/dbuser root/" /etc/pandora/pandora_server.conf && \ -sed -i "s/^dbpass.*/dbpass $DB_PASS/" /etc/pandora/pandora_server.conf - -# Install the Pandora FMS Agent. -RUN cd /tmp/pandorafms/pandora_agents/unix && \ -./pandora_agent_installer --install - -# Set the server's name in Apache's configuration file to avoid warnings. -RUN sed -i "s/#ServerName.*/ServerName localhost:80/" /etc/httpd/conf/httpd.conf - -# Install the Pandora FMS Console. -RUN rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql && \ - mkdir -p /var/log/mysql/ && chown mysql. /var/log/mysql && \ - chown mysql. -R /var/lib/mysql && \ - sudo -u mysql mysqld --initialize --explicit_defaults_for_timestamp && \ - sudo -u mysql mysqld --daemonize & \ - sleep 50 && \ - mysql_default_pass=$(cat /var/log/mysqld.log | grep "temporary password" | awk '{print $NF}') && \ - mysqladmin -u root -p"$mysql_default_pass" --user=root password 'pandora' && \ - httpd -k start && \ - cp -r /tmp/pandorafms/pandora_console /var/www/html && \ - chown -R apache.apache /var/www/html/pandora_console/ && \ - python /tmp/pandorafms/tests/install_console.py - -# Redirect HTTP requests to / to the Pandora FMS Console. -RUN echo '' > /var/www/html/index.html - -# Create the entrypoint script. -RUN echo -e '#/bin/bash\n \ -sudo -u mysql mysqld --daemonize &&\n \ -httpd -k start &&\n \ -/usr/sbin/crond &&\n \ -/etc/init.d/pandora_agent_daemon start && \ -/etc/init.d/pandora_server start && \ -tail -f /var/log/pandora/pandora_server.log' \ ->> /entrypoint.sh && \ -chmod +x /entrypoint.sh - -# Clean-up. -RUN rm -rf /tmp/pandorafms -RUN yum clean all - -EXPOSE 80 3306 41121 -ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/extras/docker/build_and_push.sh b/extras/docker/build_and_push.sh deleted file mode 100755 index c58a73bf8e..0000000000 --- a/extras/docker/build_and_push.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -docker build --rm=true --pull --no-cache --build-arg BRANCH="develop" --build-arg DB_PASS="pandora" -t pandorafms/pandorafms:7 . && \ -[ "$QA_ENV" == "" ] && \ -docker push pandorafms/pandorafms:7 diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index ef8ca498c6..bace91d6ca 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.763, AIX version +# Version 7.0NG.764, 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 d2c0f24d97..5f2ef51b98 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.763, FreeBSD Version +# Version 7.0NG.764, 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 8c95d1c74f..c93161f99e 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.763, HP-UX Version +# Version 7.0NG.764, 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 b93c5160c5..643a24089e 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.763, GNU/Linux +# Version 7.0NG.764, 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 2ee611a89f..23759866fa 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.763, GNU/Linux +# Version 7.0NG.764, 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 b709ffa298..c4efd11a0d 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.763, Solaris Version +# Version 7.0NG.764, 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 1f034d834d..50c64e6c12 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.763 +# Version 7.0NG.764 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software # Foundation; either version 2 of the Licence or any later version diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index 1b8d89e078..341b5d3b3f 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.763, AIX version +# Version 7.0NG.764, 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 442a93f6e8..1253fa53e1 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.763 +# Version 7.0NG.764 # 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 3843656944..68195f8778 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.763, HPUX Version +# Version 7.0NG.764, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 2ac7522aa8..7052f344e5 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.763 +# Version 7.0NG.764 # Licensed under GPL license v2, # (c) 2003-2021 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index f2f6e7c873..a8c124927c 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.763 +# Version 7.0NG.764 # 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 9c2f026dbf..8fba4818dc 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.763 +# Version 7.0NG.764 # 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 578dc0c8e3..cd656519e4 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.763, Solaris version +# Version 7.0NG.764, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 62cd823d30..1227b36daf 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.763, AIX version +# Version 7.0NG.764, 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 f6d4dc3ab5..53bc403e77 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.763-220727 +Version: 7.0NG.764-220906 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 758a583cb4..06a8cf8871 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.763-220727" +pandora_version="7.0NG.764-220906" 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 c144a8662c..7ae20d616f 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.763" + VERSION="7.0NG.764" 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 aac2c6f6f6..854c5bcefc 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/logon_ok.php b/pandora_console/general/logon_ok.php index 89b7c56a3e..972e6f37ca 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -137,7 +137,16 @@ $table->data[] = $tdata; // Modules by status. $tdata = []; -$tdata[0] = reporting_get_stats_modules_status($data, 180, 100); + +$data_agents = [ + __('Critical') => $data['monitor_critical'], + __('Warning') => $data['monitor_warning'], + __('Normal') => $data['monitor_ok'], + __('Unknown') => $data['monitor_unknown'], + __('Not init') => $data['monitor_not_init'], +]; + +$tdata[0] = reporting_get_stats_modules_status($data, 180, 100, false, $data_agents); $table->rowclass[] = ''; $table->data[] = $tdata; diff --git a/pandora_console/general/main_menu.php b/pandora_console/general/main_menu.php index 590dbe328a..3ce49b646a 100644 --- a/pandora_console/general/main_menu.php +++ b/pandora_console/general/main_menu.php @@ -58,6 +58,10 @@ if (isset($config['autohidden_menu']) === true && (bool) $config['autohidden_men // Start of full lateral menu. echo sprintf(' + '; if ($id_downtime > 0) { @@ -797,13 +1079,29 @@ $table = new StdClass(); $table->class = 'databox filters'; $table->width = '100%'; $table->data = []; +$table->size[0] = '25%'; $table->data[0][0] = __('Group filter'); -$table->data[0][1] = html_print_select_groups(false, $access, $return_all_group, 'filter_group', $filter_group, '', '', '', true, false, true, '', false, 'min-width:180px;margin-right:15px;'); +$table->data[0][1] = html_print_select_groups( + false, + $access, + $return_all_group, + 'filter_group', + $filter_group, + '', + '', + '', + true, + false, + true, + '', + false, + 'min-width:180px;margin-right:15px;' +); $table->data[0][2] = __('Recursion').'  '.html_print_checkbox('recursion', 1, $recursion, true, false, ''); $table->data[1][0] = __('Available agents'); -$table->data[1][1] = html_print_select($agents, 'id_agents[]', -1, '', _('Any'), -2, true, true, true, '', false, 'width: 180px;'); +$table->data[1][1] = html_print_select($agents, 'id_agents[]', -1, '', _('Any'), -2, true, true, true, '', false, 'min-width: 250px;width: 70%;'); if ($type_downtime != 'quiet') { @@ -855,7 +1153,7 @@ $table->data[3][1] = html_print_select( true, '', false, - 'width: 180px;' + 'min-width: 250px;width: 70%;' ); echo ''; @@ -1238,12 +1536,19 @@ function insert_downtime_agent($id_downtime, $user_groups_ad) switch ($("#type_execution").val()) { case 'once': $("#periodically_time").hide(); + $("#cron_time").hide(); $("#once_time").show(); break; case 'periodically': $("#once_time").hide(); + $("#cron_time").hide(); $("#periodically_time").show(); break; + case 'cron': + $("#once_time").hide(); + $("#periodically_time").hide(); + $("#cron_time").show(); + break; } } diff --git a/pandora_console/godmode/agentes/planned_downtime.list.php b/pandora_console/godmode/agentes/planned_downtime.list.php index a1e352fa1e..78f717d7d1 100755 --- a/pandora_console/godmode/agentes/planned_downtime.list.php +++ b/pandora_console/godmode/agentes/planned_downtime.list.php @@ -317,6 +317,7 @@ $row = []; $execution_type_fields = [ 'once' => __('Once'), 'periodically' => __('Periodically'), + 'cron' => __('Cron'), ]; $row[] = __('Execution type').' '.html_print_select( $execution_type_fields, @@ -460,10 +461,15 @@ if (empty($groups) === false) { strtotime($date_to.' 23:59:59') ); + $cron = sprintf( + 'type_execution = "cron"' + ); + $where_values .= sprintf( - ' AND ((%s) OR (%s))', + ' AND ((%s) OR (%s) OR (%s))', $periodically_w, - $once_w + $once_w, + $cron ); } @@ -471,6 +477,7 @@ if (empty($groups) === false) { $filter_performed = true; $where_values .= sprintf( ' AND (type_execution = "periodically" + OR type_execution = "cron" OR (type_execution = "once" AND date_to >= "%s"))', time() @@ -530,6 +537,8 @@ if (empty($groups) === false) { 'type_execution', 'type_periodicity', 'id_user', + 'cron_interval_from', + 'cron_interval_to', ]; $columns_str = implode(',', $columns); @@ -660,8 +669,9 @@ if ($downtimes === false && $filter_performed === false) { $data['type'] = $type_text[$downtime['type_downtime']]; $execution_text = [ - 'once' => __('once'), + 'once' => __('Once'), 'periodically' => __('Periodically'), + 'cron' => __('Cron'), ]; $data['execution'] = $execution_text[$downtime['type_execution']]; diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 77fdc4f99b..24b19f1586 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -195,56 +195,55 @@ $simple_alerts = []; $total = 0; $where = ''; -if ($searchFlag) { - if ($status_alert === 'fired') { - $where .= ' AND talert_template_modules.times_fired > 0'; - } - if ($status_alert === 'notfired') { - $where .= ' AND talert_template_modules.times_fired = 0'; - } +if ($status_alert === 'fired') { + $where .= ' AND talert_template_modules.times_fired > 0'; +} - if ($priority != -1 && $priority != '') { - $where .= ' AND id_alert_template IN (SELECT id FROM talert_templates WHERE priority = '.$priority.')'; - } +if ($status_alert === 'notfired') { + $where .= ' AND talert_template_modules.times_fired = 0'; +} - if (strlen(trim($templateName)) > 0) { - $where .= " AND id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE '%".trim($templateName)."%')"; - } +if ($priority != -1 && $priority != '') { + $where .= ' AND id_alert_template IN (SELECT id FROM talert_templates WHERE priority = '.$priority.')'; +} - if (strlen(trim($fieldContent)) > 0) { - $where .= " AND id_alert_template IN (SELECT id FROM talert_templates +if (strlen(trim($templateName)) > 0) { + $where .= " AND id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE '%".trim($templateName)."%')"; +} + +if (strlen(trim($fieldContent)) > 0) { + $where .= " AND id_alert_template IN (SELECT id FROM talert_templates WHERE field1 LIKE '%".trim($fieldContent)."%' OR field2 LIKE '%".trim($fieldContent)."%' OR field3 LIKE '%".trim($fieldContent)."%' OR field2_recovery LIKE '%".trim($fieldContent)."%' OR field3_recovery LIKE '%".trim($fieldContent)."%')"; - } +} - if (strlen(trim($moduleName)) > 0) { - $where .= " AND id_agent_module IN (SELECT id_agente_modulo FROM tagente_modulo WHERE nombre LIKE '%".trim($moduleName)."%')"; - } +if (strlen(trim($moduleName)) > 0) { + $where .= " AND id_agent_module IN (SELECT id_agente_modulo FROM tagente_modulo WHERE nombre LIKE '%".trim($moduleName)."%')"; +} - if (strlen(trim($agentName)) > 0) { - $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo +if (strlen(trim($agentName)) > 0) { + $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo FROM tagente t1 INNER JOIN tagente_modulo t2 ON t1.id_agente = t2.id_agente WHERE t1.alias LIKE '".trim($agentName)."')"; - } +} - if ($actionID != -1 && $actionID != '') { - $where .= ' AND talert_template_modules.id IN (SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action = '.$actionID.') OR talert_template_modules.id IN (SELECT id FROM talert_template_modules ttm WHERE ttm.id_alert_template IN (SELECT tat.id FROM talert_templates tat WHERE tat.id_alert_action = '.$actionID.'))'; - } +if ($actionID != -1 && $actionID != '') { + $where .= ' AND talert_template_modules.id IN (SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action = '.$actionID.') OR talert_template_modules.id IN (SELECT id FROM talert_template_modules ttm WHERE ttm.id_alert_template IN (SELECT tat.id FROM talert_templates tat WHERE tat.id_alert_action = '.$actionID.'))'; +} - if ($status_alert === 'disabled') { - $where .= ' AND talert_template_modules.disabled = 1'; - } +if ($status_alert === 'disabled') { + $where .= ' AND talert_template_modules.disabled = 1'; +} - if ($status_alert === 'all_enabled') { - $where .= ' AND talert_template_modules.disabled = 0'; - } +if ($status_alert === 'all_enabled') { + $where .= ' AND talert_template_modules.disabled = 0'; +} - if ($standby != -1 && $standby != '') { - $where .= ' AND talert_template_modules.standby = '.$standby; - } +if ($standby != -1 && $standby != '') { + $where .= ' AND talert_template_modules.standby = '.$standby; } $id_agents = array_keys($agents); diff --git a/pandora_console/godmode/massive/massive_delete_agents.php b/pandora_console/godmode/massive/massive_delete_agents.php index cc87efebed..7a42dc721d 100755 --- a/pandora_console/godmode/massive/massive_delete_agents.php +++ b/pandora_console/godmode/massive/massive_delete_agents.php @@ -169,154 +169,6 @@ if ($delete === true) { } } -$table = new stdClass; -$table->id = 'delete_table'; -$table->class = 'databox filters'; -$table->width = '100%'; -$table->data = []; -$table->style = []; -$table->style[0] = 'font-weight: bold;'; -$table->style[2] = 'font-weight: bold'; -$table->size = []; -$table->size[0] = '15%'; -$table->size[1] = '35%'; -$table->size[2] = '15%'; -$table->size[3] = '35%'; - -$table->data = []; -$table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select_groups( - false, - 'AW', - true, - 'id_group', - $id_group, - false, - '', - '', - true -); -$table->data[0][2] = __('Group recursion'); -$table->data[0][3] = html_print_checkbox( - 'recursion', - 1, - $recursion, - true, - false -); - -$status_list = []; -$status_list[AGENT_STATUS_NORMAL] = __('Normal'); -$status_list[AGENT_STATUS_WARNING] = __('Warning'); -$status_list[AGENT_STATUS_CRITICAL] = __('Critical'); -$status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); -$status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); -$status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); -$table->data[1][0] = __('Status'); -$table->data[1][1] = html_print_select( - $status_list, - 'status_agents', - 'selected', - '', - __('All'), - AGENT_STATUS_ALL, - true -); - -$table->data[1][2] = __('Show agents'); -$table->data[1][3] = html_print_select( - [ - 0 => 'Only enabled', - 1 => 'Only disabled', - ], - 'disabled', - 2, - '', - __('All'), - 2, - true, - false, - true, - '', - false, - 'width:30%;' -); - -if (is_metaconsole() === true) { - $servers = metaconsole_get_servers(); - $server_fields = []; - foreach ($servers as $key => $server) { - $server_fields[$key] = $server['server_name']; - } - - $table->data[2][2] = __('Node'); - $table->data[2][3] = html_print_select( - $server_fields, - 'nodes[]', - 0, - false, - '', - '', - true, - true, - true, - '', - false, - 'min-width: 500px; max-width: 500px; max-height: 100px', - false, - false, - false, - '', - false, - false, - false, - false, - true, - true, - true - ); -} - -$table->data[3][0] = __('Agents'); -$table->data[3][0] .= ''; - -$agents = []; -if (is_metaconsole() === false) { - $agents = agents_get_group_agents( - array_keys(users_get_groups($config['id_user'], 'AW', false)), - ['disabled' => 2], - 'none' - ); -} - - -$table->data[3][1] = html_print_select( - $agents, - 'id_agents[]', - 0, - false, - '', - '', - true, - true, - true, - '', - false, - 'min-width: 500px; max-width: 500px; max-height: 100px', - false, - false, - false, - '', - false, - false, - false, - false, - true, - true, - true -); $url = 'index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_agents'; if (is_metaconsole() === true) { @@ -324,10 +176,15 @@ if (is_metaconsole() === true) { } echo '
'; -html_print_table($table); + +$params = [ + 'id_group' => $id_group, + 'recursion' => $recursion, +]; +echo get_table_inputs_masive_agents($params); if (is_metaconsole() === true || is_management_allowed() === true) { - attachActionButton('delete', 'delete', $table->width); + attachActionButton('delete', 'delete', '100%'); } echo '
'; @@ -342,54 +199,6 @@ ui_require_jquery_file('pandora.controls'); $(document).ready (function () { // Check Metaconsole. var metaconsole = ''; - - // Listeners. - var recursion; - $("#checkbox-recursion").click(function () { - recursion = this.checked ? 1 : 0; - $("#id_group").trigger("change"); - }); - - var disabled; - $("#disabled").change(function () { - disabled = this.value; - $("#id_group").trigger("change"); - }); - - var nodes; - $("#nodes").change(function () { - nodes = $("#nodes").val(); - $("#id_group").trigger("change"); - }); - - $("#status_agents").change(function() { - $("#id_group").trigger("change"); - }); - - // Build data. - var data = { - status_agents: function () { - return $("#status_agents").val(); - }, - agentSelect: "select#id_agents", - privilege: "AW", - recursion: function() { - return recursion; - }, - disabled: function() { - return disabled; - }, - } - - if (metaconsole == 1) { - data.serialized = true; - data.serialized_separator = '|'; - data.nodes = function() { - return nodes; - }; - } - - // Change agents. - $("#id_group").pandoraSelectGroupAgent(data); + form_controls_massive_operations_agents(metaconsole); }); diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index a68104f4e4..b5da8ca9ae 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -26,6 +26,9 @@ * ============================================================================ */ +use PandoraFMS\Agent; +use PandoraFMS\Enterprise\Metaconsole\Node; + // Begin. check_login(); @@ -48,17 +51,47 @@ require_once $config['homedir'].'/include/functions_users.php'; enterprise_include_once('include/functions_config_agents.php'); if (is_ajax() === true) { - $get_n_conf_files = (bool) get_parameter('get_n_conf_files', false); - $groups_secondary_selected = (bool) get_parameter('groups_secondary_selected', false); + $get_n_conf_files = (bool) get_parameter( + 'get_n_conf_files', + false + ); + + $groups_secondary_selected = (bool) get_parameter( + 'groups_secondary_selected', + false + ); if ($get_n_conf_files === true) { $id_agents = get_parameter('id_agents'); $cont = 0; foreach ($id_agents as $id_agent) { - $name = agents_get_name($id_agent); - $agent_md5 = md5($name); - if (file_exists($config['remote_config'].'/md5/'.$agent_md5.'.md5') === true) { - $cont++; + if (is_metaconsole() === true) { + $array_id = explode('|', $id_agent); + try { + $node = new Node((int) $array_id[0]); + $node->connect(); + + $agent = new Agent((int) $array_id[1]); + if ($agent->hasRemoteConf() === true) { + $cont++; + } + + $node->disconnect(); + } catch (\Exception $e) { + // Unexistent agent. + $cont = 0; + $node->disconnect(); + } + } else { + try { + $agent = new Agent((int) $array_id[1]); + if ($agent->hasRemoteConf() === true) { + $cont++; + } + } catch (\Exception $e) { + // Unexistent agent. + $cont = 0; + } } } @@ -88,12 +121,15 @@ $recursion = get_parameter('recursion'); if ($update_agents) { $values = []; - if (get_parameter('group', '') != -1) { + + if ((int) get_parameter('group', '') !== -1) { $values['id_grupo'] = get_parameter('group'); } - if (!(get_parameter('interval_select') == -1 && empty(get_parameter('interval_text')))) { - if (get_parameter('interval', 0) != 0) { + if (!(get_parameter('interval_select') === -1 + && empty(get_parameter('interval_text'))) + ) { + if (get_parameter('interval') != -2) { $values['intervalo'] = get_parameter('interval'); } } @@ -158,8 +194,14 @@ if ($update_agents) { $values['safe_mode_module'] = '0'; } - $secondary_groups_added = (array) get_parameter('secondary_groups_added', []); - $secondary_groups_removed = (array) get_parameter('secondary_groups_removed', []); + $secondary_groups_added = (array) get_parameter( + 'secondary_groups_added', + [] + ); + $secondary_groups_removed = (array) get_parameter( + 'secondary_groups_removed', + [] + ); $fields = db_get_all_fields_in_table('tagent_custom_fields'); @@ -178,22 +220,27 @@ if ($update_agents) { } } - // Get the id_agente_modulo to update the 'safe_operation_mode' field. - if (isset($values['safe_mode_module']) && ($values['safe_mode_module'] != '0')) { - foreach ($id_agents as $id_agent) { - $id_module_safe[$id_agent] = db_get_value_filter( - 'id_agente_modulo', - 'tagente_modulo', - [ - 'id_agente' => $id_agent, - 'nombre' => $values['safe_mode_module'], - ] - ); + $id_module_safe = []; + if (is_metaconsole() === false) { + // Get the id_agente_modulo to update the 'safe_operation_mode' field. + if (isset($values['safe_mode_module']) === true + && ($values['safe_mode_module'] != '0') + ) { + foreach ($id_agents as $id_agent) { + $id_module_safe[$id_agent] = db_get_value_filter( + 'id_agente_modulo', + 'tagente_modulo', + [ + 'id_agente' => $id_agent, + 'nombre' => $values['safe_mode_module'], + ] + ); + } } } // CONF FILE DELETION. - if (isset($values['delete_conf'])) { + if (isset($values['delete_conf']) === true) { unset($values['delete_conf']); $n_deleted = 0; foreach ($id_agents as $id_agent) { @@ -229,141 +276,56 @@ if ($update_agents) { ); } - if (empty($values) && empty($fields)) { + if (empty($values) === true + && empty($fields) === true + ) { $id_agents = []; } - $n_edited = 0; $result = []; foreach ($id_agents as $id_agent) { - $old_interval_value = db_get_value_filter('intervalo', 'tagente', ['id_agente' => $id_agent]); - - if (!empty($values)) { - $disabled_old = false; - if ($values['id_grupo'] || isset($values['disabled'])) { - $values_old = db_get_row_filter('tagente', ['id_agente' => $id_agent], ['id_grupo', 'disabled']); - if (isset($values['disabled'])) { - $disabled_old = $values_old['disabled']; - } - } - - // Get the id_agent_module for this agent to update the 'safe_operation_mode' field. - if (isset($values['safe_mode_module']) && ($values['safe_mode_module'] != '0')) { - $values['safe_mode_module'] = $id_module_safe[$id_agent]; - } - - $result[$id_agent]['db'] = db_process_sql_update( - 'tagente', - $values, - ['id_agente' => $id_agent] - ); - - if ($result[$id_agent]['db'] && $config['metaconsole_agent_cache'] == 1) { - $server_name['server_name'] = db_get_sql('SELECT server_name FROM tagente WHERE id_agente ='.$id_agent); - // Force an update of the agent cache. - $result_metaconsole = agent_update_from_cache($id_agent, $values, $server_name); - } - - // Update the configuration files. - if ($result[$id_agent]['db'] && ($old_interval_value != $values['intervalo']) && !empty($values['intervalo'])) { - enterprise_hook( - 'config_agents_update_config_token', - [ - $id_agent, - 'interval', - $values['intervalo'], - ] - ); - } - - if ($disabled_old !== false && $disabled_old != $values['disabled']) { - enterprise_hook( - 'config_agents_update_config_token', - [ - $id_agent, - 'standby', - $values['disabled'], - ] - ); - // Validate alerts for disabled agents. - if ($values['disabled'] == 1) { - alerts_validate_alert_agent($id_agent); - } - } - } - - $info = []; - // Update Custom Fields. - foreach ($fields as $field) { - $info[$field['id_field']] = $field['name']; - $value = get_parameter('customvalue_'.$field['id_field']); - if (empty($value) === false) { - $key = $field['id_field']; - $old_value = db_get_all_rows_filter( - 'tagent_custom_data', - [ - 'id_agent' => $id_agent, - 'id_field' => $key, - ] - ); - - if ($old_value === false) { - // Create custom field if not exist. - $result[$id_agent]['fields'][$field['id_field']] = db_process_sql_insert( - 'tagent_custom_data', - [ - 'id_field' => $key, - 'id_agent' => $id_agent, - 'description' => $value, - ] - ); - } else { - if ($old_value[0]['description'] !== $value) { - $result[$id_agent]['fields'][$field['id_field']] = db_process_sql_update( - 'tagent_custom_data', - ['description' => $value], - [ - 'id_field' => $key, - 'id_agent' => $id_agent, - ] - ); - } - } - } - } - - // Create or Remove the secondary groups. - if (empty($secondary_groups_added) === false - || empty($secondary_groups_removed) === false - ) { - $result[$id_agent]['secondary'] = enterprise_hook( - 'agents_update_secondary_groups', - [ - $id_agent, + if (is_metaconsole() === true) { + $array_id = explode('|', $id_agent); + try { + $node = new Node((int) $array_id[0]); + $node->connect(); + $result[$id_agent] = edit_massive_agent( + (int) $array_id[1], + $values, + $id_module_safe, + $fields, $secondary_groups_added, - $secondary_groups_removed, - true, - ] - ); - } - - if ($result['db'] !== false) { - db_pandora_audit( - AUDIT_LOG_MASSIVE_MANAGEMENT, - 'Update agent '.$id_agent, - false, - false, - json_encode($info) - ); - } else { - if (isset($id_agent) === true) { - db_pandora_audit( - AUDIT_LOG_MASSIVE_MANAGEMENT, - 'Try to update agent '.$id_agent, - false, - false, - json_encode($info) + $secondary_groups_removed ); + + $agents_values = agents_get_agent((int) $array_id[1]); + $node->disconnect(); + + if (empty($values) === false) { + update_agents_in_metaconsole( + (int) $array_id[1], + $values, + $agents_values + ); + } + } catch (\Exception $e) { + // Unexistent agent. + $result = []; + $node->disconnect(); + } + } else { + try { + $result[$id_agent] = edit_massive_agent( + $id_agent, + $values, + $id_module_safe, + $fields, + $secondary_groups_added, + $secondary_groups_removed + ); + } catch (\Exception $e) { + // Unexistent agent. + $result = []; } } } @@ -488,121 +450,160 @@ if ($update_agents) { } } -$id_group = 0; -$table = new StdClass(); -$table->id = 'delete_table'; -$table->class = 'databox filters'; -$table->width = '100%'; -$table->data = []; -$table->style = []; -$table->style[0] = 'font-weight: bold;'; -$table->style[2] = 'font-weight: bold'; -$table->size = []; -$table->size[0] = '15%'; -$table->size[1] = '35%'; -$table->size[2] = '15%'; -$table->size[3] = '35%'; +/** + * Edit massive agent. + * + * @param integer $id_agent + * @param array $values + * @param array $id_module_safe + * @param array $fields + * @param array $secondary_groups_added + * @param array $secondary_groups_removed + * @return void + */ +function edit_massive_agent( + int $id_agent, + array $values, + array $id_module_safe, + array $fields, + array $secondary_groups_added, + array $secondary_groups_removed +) { + global $config; + $result = false; -$table->data = []; -$table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select_groups( - false, - 'AW', - true, - 'id_group', - $id_group, - false, - '', - '', - true -); -$table->data[0][2] = __('Group recursion'); -$table->data[0][3] = html_print_checkbox( - 'recursion2', - 1, - $recursion, - true, - false -); + if (empty($values) === false) { + $agent = new Agent($id_agent); + $disabled_old = $agent->disabled(); + + foreach ($values as $key => $value) { + $agent->{$key}($value); + } + + if (is_metaconsole() === false) { + // Get the id_agent_module for this agent to update the 'safe_operation_mode' field. + if (isset($values['safe_mode_module']) === true + && ($values['safe_mode_module'] != '0') + ) { + $values['safe_mode_module'] = $id_module_safe[$id_agent]; + } + } + + $result['db'] = $agent->save(); + + if (is_metaconsole() === false) { + if ($result['db'] !== false + && (bool) $config['metaconsole_agent_cache'] === true + ) { + // Force an update of the agent cache. + $agent->updateFromCache(); + } + } + + if ($disabled_old !== $values['disabled']) { + // Validate alerts for disabled agents. + if ($values['disabled'] == 1) { + alerts_validate_alert_agent($id_agent); + } + } + } + + $info = []; + // Update Custom Fields. + if (isset($fields) === true + && empty($fields) === false + ) { + foreach ($fields as $field) { + $info[$field['id_field']] = $field['name']; + $value = get_parameter('customvalue_'.$field['id_field']); + if (empty($value) === false) { + $key = $field['id_field']; + $old_value = db_get_all_rows_filter( + 'tagent_custom_data', + [ + 'id_agent' => $id_agent, + 'id_field' => $key, + ] + ); + + if ($old_value === false) { + // Create custom field if not exist. + $result['fields'][$field['id_field']] = db_process_sql_insert( + 'tagent_custom_data', + [ + 'id_field' => $key, + 'id_agent' => $id_agent, + 'description' => $value, + ] + ); + } else { + if ($old_value[0]['description'] !== $value) { + $result['fields'][$field['id_field']] = db_process_sql_update( + 'tagent_custom_data', + ['description' => $value], + [ + 'id_field' => $key, + 'id_agent' => $id_agent, + ] + ); + } + } + } + } + } + + // Create or Remove the secondary groups. + if (empty($secondary_groups_added) === false + || empty($secondary_groups_removed) === false + ) { + $result['secondary'] = enterprise_hook( + 'agents_update_secondary_groups', + [ + $id_agent, + $secondary_groups_added, + $secondary_groups_removed, + true, + ] + ); + } + + if ($result['db'] !== false) { + db_pandora_audit( + AUDIT_LOG_MASSIVE_MANAGEMENT, + 'Update agent '.$id_agent, + false, + false, + json_encode($info) + ); + } else { + if (isset($id_agent) === true) { + db_pandora_audit( + AUDIT_LOG_MASSIVE_MANAGEMENT, + 'Try to update agent '.$id_agent, + false, + false, + json_encode($info) + ); + } + } + + return $result; +} -$status_list = []; -$status_list[AGENT_STATUS_NORMAL] = __('Normal'); -$status_list[AGENT_STATUS_WARNING] = __('Warning'); -$status_list[AGENT_STATUS_CRITICAL] = __('Critical'); -$status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); -$status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); -$status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); -$table->data[1][0] = __('Status'); -$table->data[1][1] = html_print_select( - $status_list, - 'status_agents', - 'selected', - '', - __('All'), - AGENT_STATUS_ALL, - true -); -$table->data[1][2] = __('Show agents'); -$table->data[1][3] = html_print_select( - [ - 0 => 'Only enabled', - 1 => 'Only disabled', - ], - 'disabled', - 2, - '', - __('All'), - 2, - true, - false, - true, - '', - false, - 'width:30%;' -); +$url = 'index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=edit_agents'; +if (is_metaconsole() === true) { + $url = 'index.php?sec=advanced&sec2=advanced/massive_operations&tab=massive_agents&pure=0&option=edit_agents'; +} -$table->data[2][0] = __('Agents'); -$table->data[2][0] .= ''; -$all_agents = agents_get_group_agents( - array_keys(users_get_groups($config['id_user'], 'AW', false)), - ['disabled' => 2], - 'none' -); - -$table->data[2][1] = html_print_select( - $all_agents, - 'id_agents[]', - 0, - false, - '', - '', - true, - true, - true, - '', - false, - 'min-width: 500px; max-width: 500px; max-height: 100px', - false, - false, - false, - '', - false, - false, - false, - false, - true, - true, - true -); - -echo '
'; +echo ''; echo html_print_avoid_autocomplete(); - -html_print_table($table); +$params = [ + 'id_group' => $id_group, + 'recursion' => $recursion, +]; +echo get_table_inputs_masive_agents($params); $nombre_agente = ''; $direccion_agente = ''; @@ -620,7 +621,6 @@ echo '