diff --git a/extras/pandora_gotty/.gitattributes b/extras/pandora_gotty/.gitattributes new file mode 100644 index 0000000000..ca0a55fe2e --- /dev/null +++ b/extras/pandora_gotty/.gitattributes @@ -0,0 +1 @@ +src/pandora_gotty filter=lfs diff=lfs merge=lfs -text diff --git a/extras/pandora_gotty/.gitignore b/extras/pandora_gotty/.gitignore new file mode 100644 index 0000000000..db388678f7 --- /dev/null +++ b/extras/pandora_gotty/.gitignore @@ -0,0 +1,2 @@ +*.rpm +*.deb \ No newline at end of file diff --git a/extras/pandora_gotty/Dockerfile-RPM b/extras/pandora_gotty/Dockerfile-RPM new file mode 100644 index 0000000000..f708a6f4a7 --- /dev/null +++ b/extras/pandora_gotty/Dockerfile-RPM @@ -0,0 +1,8 @@ +FROM rockylinux:8 + +RUN dnf install -y rpm-build rpmdevtools +RUN rpmdev-setuptree +RUN mkdir /root/pandora_gotty +WORKDIR /root/pandora_gotty + +#CMD bash build.sh diff --git a/extras/pandora_gotty/Dockerfile-deb b/extras/pandora_gotty/Dockerfile-deb new file mode 100644 index 0000000000..02a30a43d3 --- /dev/null +++ b/extras/pandora_gotty/Dockerfile-deb @@ -0,0 +1,6 @@ +FROM ubuntu:22.04 + +RUN apt-get update +RUN apt-get install -y dh-make debhelper build-essential +RUN mkdir /root/pandora_gotty +WORKDIR /root/pandora_gotty \ No newline at end of file diff --git a/extras/pandora_gotty/README.md b/extras/pandora_gotty/README.md new file mode 100644 index 0000000000..c31e228c46 --- /dev/null +++ b/extras/pandora_gotty/README.md @@ -0,0 +1 @@ +To create the .deb and .rpm package need to hace docker installed on main system and execit `build_all_docker.sh` diff --git a/extras/pandora_gotty/build_all_docker.sh b/extras/pandora_gotty/build_all_docker.sh new file mode 100755 index 0000000000..cb280999ba --- /dev/null +++ b/extras/pandora_gotty/build_all_docker.sh @@ -0,0 +1,11 @@ +#Build RPM +docker build -t pandora_gotty_builder_rpm -f Dockerfile-RPM . || exit 1 +docker run --rm -it -v `pwd`:/root/pandora_gotty pandora_gotty_builder_rpm /root/pandora_gotty/build_rpm.sh || exit 1 + +#Buikd DEB +docker build -t pandora_gotty_builder_deb -f Dockerfile-deb . || exit 1 +docker run --rm -it -v `pwd`:/root/pandora_gotty pandora_gotty_builder_deb /root/pandora_gotty/build_deb.sh || exit 1 + +echo " - Done" +pwd +ls -l | grep -E "(\.deb|\.rpm)" \ No newline at end of file diff --git a/extras/pandora_gotty/build_deb.sh b/extras/pandora_gotty/build_deb.sh new file mode 100755 index 0000000000..fbcb2a6790 --- /dev/null +++ b/extras/pandora_gotty/build_deb.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#DEB +cd deb +VERSION=$(grep 'Version:' pandora_gotty/DEBIAN/control | awk '{print $2}') +mkdir -p pandora_gotty/usr/bin +mkdir -p pandora_gotty/etc/pandora_gotty +cp -a ../src/pandora_gotty pandora_gotty/usr/bin +cp -a ../src/pandora_gotty.conf pandora_gotty/etc/pandora_gotty +curl -SsL --output pandora_gotty/usr/bin/pandora_gotty_exec http://192.168.50.31/installers/installers/Linux/x86_64/pandora_gotty_exec +chmod +x pandora_gotty/usr/bin/pandora_gotty_exec +dpkg-deb --build pandora_gotty +mv pandora_gotty.deb ../ +rm -rf pandora_gotty/usr/ +rm -rf pandora_gotty/etc/ +cd .. +mv pandora_gotty.deb pandora_gotty_${VERSION}.deb +chmod 777 pandora_gotty_${VERSION}.deb diff --git a/extras/pandora_gotty/build_rpm.sh b/extras/pandora_gotty/build_rpm.sh new file mode 100755 index 0000000000..e08fa0e65b --- /dev/null +++ b/extras/pandora_gotty/build_rpm.sh @@ -0,0 +1,15 @@ +#!/bin/bash +#RPM +VERSION=$(grep '%define version' pandora_gotty.spec | awk '{print $3}') +mkdir -p pandora_gotty-${VERSION} +cp src/pandora_gotty pandora_gotty-${VERSION}/ +cp src/pandora_gotty.conf pandora_gotty-${VERSION}/ +curl -SsL --output pandora_gotty-${VERSION}/pandora_gotty_exec http://192.168.50.31/installers/installers/Linux/x86_64/pandora_gotty_exec +chmod +x pandora_gotty-${VERSION}/pandora_gotty_exec +tar -cvzf pandora_gotty-${VERSION}.tar.gz pandora_gotty-${VERSION}/* +mv pandora_gotty-${VERSION}.tar.gz ${HOME}/rpmbuild/SOURCES/ +rm -rf ${HOME}/rpmbuild/RPMS/x86_64/pandora_gotty* +rpmbuild -ba pandora_gotty.spec +rm -rf pandora_gotty-${VERSION} +mv ${HOME}/rpmbuild/RPMS/x86_64/pandora_gotty* . +chmod 777 *.rpm \ No newline at end of file diff --git a/extras/pandora_gotty/deb/.gitignore b/extras/pandora_gotty/deb/.gitignore new file mode 100644 index 0000000000..92a9f94179 --- /dev/null +++ b/extras/pandora_gotty/deb/.gitignore @@ -0,0 +1,3 @@ +*.deb +**/usr +**/etc diff --git a/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/changelog b/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/changelog new file mode 100644 index 0000000000..5d7e7f2ab6 --- /dev/null +++ b/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/changelog @@ -0,0 +1,5 @@ +pandora_gotty (1.0-1) stable; urgency=low + + * Initial release. + + -- PandoraFMS Mon, 18 Sep 2023 00:00:00 +0000 \ No newline at end of file diff --git a/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control b/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control new file mode 100644 index 0000000000..f715ee1b49 --- /dev/null +++ b/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control @@ -0,0 +1,9 @@ +Source: pandora_gotty +Section: utils +Version: 1.0.0 +Priority: optional +Maintainer: PandoraFMS +Build-Depends: debhelper (>= 12) +Package: pandora-gotty +Architecture: amd64 +Description: pandora_gotty for Pandora FMS. diff --git a/extras/pandora_gotty/pandora_gotty.spec b/extras/pandora_gotty/pandora_gotty.spec new file mode 100644 index 0000000000..813c9726c9 --- /dev/null +++ b/extras/pandora_gotty/pandora_gotty.spec @@ -0,0 +1,41 @@ +%define name pandora_gotty +%define version 1.0 +%define release 1%{?dist} +Summary: pandora_gptty for Pandora FMS +Name: %{name} +Version: %{version} +Release: %{release} +License: GPL +Vendor: PandoraFMS +Source0: %{name}-%{version}.tar.gz +URL: https://pandorafms.com +Group: System/Monitoring +Packager: PandoraFMS +BuildArch: x86_64 +Provides: %{name}-%{version} + +%description +pandora_gotty for Pandora FMS. + +%prep +%setup -q + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/%{_bindir} +mkdir -p %{buildroot}/etc/pandora_gotty/ +cp %{name} $RPM_BUILD_ROOT/%{_bindir} +cp pandora_gotty_exec $RPM_BUILD_ROOT/%{_bindir} +cp pandora_gotty.conf %{buildroot}/etc/pandora_gotty/ +%clean +rm -Rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root,-) +%config(noreplace) /etc/pandora_gotty/pandora_gotty.conf +%{_bindir}/%{name} +%{_bindir}/pandora_gotty_exec + +%changelog +* Mon Sep 18 2023 PandoraFMS - 1.0-1 +- Initial RPM release diff --git a/extras/pandora_gotty/src/.gitignore b/extras/pandora_gotty/src/.gitignore new file mode 100644 index 0000000000..a2acfc48bf --- /dev/null +++ b/extras/pandora_gotty/src/.gitignore @@ -0,0 +1,2 @@ +*rpm +bin/* diff --git a/extras/pandora_gotty/src/pandora_gotty b/extras/pandora_gotty/src/pandora_gotty new file mode 100755 index 0000000000..dc71d46eaf --- /dev/null +++ b/extras/pandora_gotty/src/pandora_gotty @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3758eddb64db79c6ea1dac4cb200ee8ec86ef3f51723dad5be4365a1315b952b +size 13642854 diff --git a/extras/pandora_gotty/src/pandora_gotty.conf b/extras/pandora_gotty/src/pandora_gotty.conf new file mode 100644 index 0000000000..09d54e64c0 --- /dev/null +++ b/extras/pandora_gotty/src/pandora_gotty.conf @@ -0,0 +1,29 @@ +//Pandora Gotty config file + +// [bool] Permit clients to write to the TTY +permit_write = true + +// [bool] Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB) +permit_arguments = true + +// [bool] Enable random URL generation +enable_random_url = true + +// [int] Default length of random strings appended to URL +// To enable random URL generation, set `true` to `enable_random_url` +random_url_length = 32 + +// [bool] Enable TLS/SSL +// enable_tls = false + +// [string] Default TLS certificate file path +// tls_crt_file = "~/.gotty.crt" + +// [string] Default TLS key file path +// tls_key_file = "~/.gotty.key" + +// [bool] Enable client certificate authentication +// enable_tls_client_auth = false + +// [string] Certificate file of CA for client certificates +// tls_ca_crt_file = "~/.gotty.ca.crt" \ No newline at end of file diff --git a/extras/pandora_gotty/src/pandora_gotty_exec.py b/extras/pandora_gotty/src/pandora_gotty_exec.py new file mode 100644 index 0000000000..1f7756745f --- /dev/null +++ b/extras/pandora_gotty/src/pandora_gotty_exec.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +__author__ = "PandoraFMS Team" +__copyright__ = "Copyright 2023, PandoraFMS" +#__credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley", "Matthew Wakefield"] +__maintainer__ = "Projects/QA department" +__status__ = "Prod" +__version__ = "1.0" + +import sys, argparse, signal, re, datetime, subprocess + +info= f""" +SSH and TELNET helper for pandora_gotty. +Version: {__version__} +""" + +parser = argparse.ArgumentParser(description= info, formatter_class=argparse.RawTextHelpFormatter) +parser.add_argument('exec_cmd', + help='Aplication to be executed, avalibles: ssh or telnet',type=str, choices=['ssh', 'telnet']) +parser.add_argument('address', + help='IP addres or dns name to connect', type=str, default="") +parser.add_argument('port', + help='Port to connect', type=int, default=23) +parser.add_argument('user', + help='Username, only requiered for ssh connection', type=str, default="", nargs='?') + +args = parser.parse_args() + +# Define a function to handle the SIGINT signal +def sigint_handler(signal, frame): + print ('\nInterrupted by user', file=sys.stderr) + sys.exit(0) +signal.signal(signal.SIGINT, sigint_handler) + +# Define a function to handle the SIGTERM signal +def sigterm_handler(signum, frame): + print("Received SIGTERM signal.", file=sys.stderr) + sys.exit(0) +signal.signal(signal.SIGTERM, sigterm_handler) + +# Functions +def is_valid_add(add:str): + # Regular expression to match an IP address + ip_pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$' + + # Regular expression to match a DNS name (domain name) + dns_pattern = r'^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' + + if re.match(ip_pattern, add) or re.match(dns_pattern, add): + return True + else: + print(f"Error not valid address: {add}", file=sys.stderr) + return False + +def is_valid_username(username:str): + # Regular expression to match a valid Linux username + username_pattern = r'^[a-zA-Z_][a-zA-Z0-9_]{0,31}$' + if re.match(username_pattern, username) is not None: + return True + else: + print(f"Error not valid username: {username}", file=sys.stderr) + return False + +def exec_ssh (user:str, add:str, port:int): + # Previus checks + if is_valid_username(user) == False: + return False + if is_valid_add(add) == False: + return False + if port == 0 : + return False + + try: + print("> Starting SSH connection...") + ssh_command = f"ssh {user}@{add} -p {port}" + subprocess.run(ssh_command, shell=True) + + except subprocess.CalledProcessError as e: + raise SystemExit(e) + return True + +def exec_telnet (add:str, port:int): + # Previus checks + if is_valid_add(add) == False: + return False + + try: + print("> Starting Telnet connection...") + ssh_command = f"telnet -E {add} {port}" + subprocess.run(ssh_command, shell=True) + + except subprocess.CalledProcessError as e: + raise SystemExit(e) + return True + + +# Main +if __name__ == "__main__": + if args.exec_cmd == "ssh": + exec_ssh(args.user, args.address, args.port) + print ("> ssh session finished") + sys.exit(0) + + if args.exec_cmd == "telnet": + exec_telnet(args.address, args.port) + print ("> telnet session finished") + sys.exit(0) + + sys.exit(0) diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index 5c5ec2d3b6..37fb9b0854 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.773.3, AIX version +# Version 7.0NG.774, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index ed33c06e4d..5a36cea140 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.773.3, FreeBSD Version +# Version 7.0NG.774, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # 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 784c729f73..52cd8e1774 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.773.3, HP-UX Version +# Version 7.0NG.774, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 0a3a48950c..4ad837f943 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.773.3, GNU/Linux +# Version 7.0NG.774, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com @@ -300,3 +300,7 @@ module_plugin grep_log /var/log/syslog Syslog ssh #module_exec echo 5 #module_description Postcondition test module #module_end + +# This plugin runs several security checks in a Linux system + +#module_plugin pandora_security_check \ No newline at end of file diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index 28ee6bd21f..efa9d79f34 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.773.3, GNU/Linux +# Version 7.0NG.774, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index 3d17139780..3a97e4a011 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.773.3, Solaris Version +# Version 7.0NG.774, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index edf5a7847a..621c1d24ac 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-2023 Pandora FMS -# Version 7.0NG.773.3 +# Version 7.0NG.774 # 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/Win32/scripts/install_service_restart.bat b/pandora_agents/pc/Win32/scripts/install_service_restart.bat index 78d2b5e2cd..a3cd46191e 100644 --- a/pandora_agents/pc/Win32/scripts/install_service_restart.bat +++ b/pandora_agents/pc/Win32/scripts/install_service_restart.bat @@ -1,2 +1,3 @@ -@at 00:00 /every:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 "%CD%\restart_pandora_agent.bat" +@at 00:00 /every:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 "'%CD%\restart_pandora_agent.bat'" +schtasks /change /tn pandora_agent_restart /tr "'%CD%\restart_pandora_agent.bat'" \ No newline at end of file diff --git a/pandora_agents/pc/pandora_agent b/pandora_agents/pc/pandora_agent index aa8208f5d0..67e603b225 100644 --- a/pandora_agents/pc/pandora_agent +++ b/pandora_agents/pc/pandora_agent @@ -54,7 +54,6 @@ if (!$@) { use constant AGENT_VERSION => '4.0.1'; use constant AGENT_BUILD => '111213'; - # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { linux => 'cat /proc/meminfo | grep MemTotal: | awk \'{ print $2 }\'', @@ -117,7 +116,6 @@ my $ConfDir = ''; # Pandora FMS agent configuration file my $ConfFile = 'pandora_agent.conf'; - # Broker agent configuration files my @BrokerPid; @@ -264,7 +262,6 @@ sub valid_regexp ($) { sub rmrf { my $path = shift; local *DIR; - if (-d $path) { opendir (DIR, $path) || return; while (defined (my $file_name = readdir(DIR))) { @@ -348,7 +345,6 @@ sub log_message ($$;$) { } } } - ################################################################################ # Add the given directory to the PATH. ################################################################################ @@ -582,7 +578,6 @@ sub write_broker_conf($){ } while (my $line = ){ - # Skip broker definitions if ($line =~ m/^\s*broker_agent/) { next; @@ -1810,7 +1805,6 @@ sub exec_plugin ($) { $Sem->down () if (defined ($Sem)); $Xml .= $output; $Sem->up () if (defined ($Sem)); - $ThreadSem->up () if (defined ($ThreadSem) && $Conf{'agent_threads'} > 1); } @@ -2287,4 +2281,4 @@ This is released under the GNU Lesser General Public License. Copyright (c) 2005-2023 Pandora FMS -=cut +=cut \ No newline at end of file diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index d2c1806dc0..74841e0515 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.773.3, AIX version +# Version 7.0NG.774, 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 69b39f6a25..7ba120ca70 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.773.3 +# Version 7.0NG.774 # 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 b27bfe9167..bcbd2dbb35 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.773.3, HPUX Version +# Version 7.0NG.774, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 23dff46fb5..98c137741e 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.773.3 +# Version 7.0NG.774 # Licensed under GPL license v2, # (c) 2003-2023 Pandora FMS # 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 3250232611..b4b3c35ac8 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.773.3 +# Version 7.0NG.774 # Licensed under GPL license v2, # (c) 2003-2023 Pandora FMS # 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 29fd1d64da..9ea0d9a2aa 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.773.3 +# Version 7.0NG.774 # 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 a4b43f1944..954c52853b 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.773.3, Solaris version +# Version 7.0NG.774, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 29fb0051d5..c3bea470ac 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.773.3, AIX version +# Version 7.0NG.774, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 4a10fb7ac8..2d70b58a57 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.773.3-230907 +Version: 7.0NG.774-231103 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 9304a38d93..fa16a33fe7 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.773.3-230907" +pandora_version="7.0NG.774-231103" 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 91907dbd82..b1d0fea6db 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.773.3" + VERSION="7.0NG.774" 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 94266e09e4..708d31a47a 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 6567347999..df6fe6e86e 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -26,14 +26,16 @@ * ============================================================================ */ +use PandoraFMS\TacticalView\GeneralTacticalView; + // Config functions. -require_once 'include/config.php'; + require_once 'include/config.php'; -// This solves problems in enterprise load. -global $config; + // This solves problems in enterprise load. + global $config; -check_login(); -// ACL Check. + check_login(); + // ACL Check. if (check_acl($config['id_user'], 0, 'AR') === 0) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, @@ -43,322 +45,5 @@ if (check_acl($config['id_user'], 0, 'AR') === 0) { exit; } -require_once 'include/functions_reporting.php'; -require_once 'include/functions_tactical.php'; -require_once $config['homedir'].'/include/functions_graph.php'; - -if (tags_has_user_acl_tags()) { - ui_print_tags_warning(); -} - -$all_data = tactical_status_modules_agents( - $config['id_user'], - false, - 'AR' -); -$data = []; - -$data['monitor_not_init'] = (int) $all_data['_monitors_not_init_']; -$data['monitor_unknown'] = (int) $all_data['_monitors_unknown_']; -$data['monitor_ok'] = (int) $all_data['_monitors_ok_']; -$data['monitor_warning'] = (int) $all_data['_monitors_warning_']; -$data['monitor_critical'] = (int) $all_data['_monitors_critical_']; -$data['monitor_not_normal'] = (int) $all_data['_monitor_not_normal_']; -$data['monitor_alerts'] = (int) $all_data['_monitors_alerts_']; -$data['monitor_alerts_fired'] = (int) $all_data['_monitors_alerts_fired_']; -$data['monitor_total'] = (int) $all_data['_monitor_total_']; - - -$data['total_agents'] = (int) $all_data['_total_agents_']; - -$data['monitor_checks'] = (int) $all_data['_monitor_checks_']; -if (!empty($all_data)) { - if ($data['monitor_not_normal'] > 0 && $data['monitor_checks'] > 0) { - $data['monitor_health'] = format_numeric((100 - ($data['monitor_not_normal'] / ($data['monitor_checks'] / 100))), 1); - } else { - $data['monitor_health'] = 100; - } - - if ($data['monitor_not_init'] > 0 && $data['monitor_checks'] > 0) { - $data['module_sanity'] = format_numeric((100 - ($data['monitor_not_init'] / ($data['monitor_checks'] / 100))), 1); - } else { - $data['module_sanity'] = 100; - } - - if (isset($data['alerts'])) { - if ($data['monitor_alerts_fired'] > 0 && $data['alerts'] > 0) { - $data['alert_level'] = format_numeric((100 - ($data['monitor_alerts_fired'] / ($data['alerts'] / 100))), 1); - } else { - $data['alert_level'] = 100; - } - } else { - $data['alert_level'] = 100; - $data['alerts'] = 0; - } - - $data['monitor_bad'] = ($data['monitor_critical'] + $data['monitor_warning']); - - if ($data['monitor_bad'] > 0 && $data['monitor_checks'] > 0) { - $data['global_health'] = format_numeric((100 - ($data['monitor_bad'] / ($data['monitor_checks'] / 100))), 1); - } else { - $data['global_health'] = 100; - } - - $data['server_sanity'] = format_numeric((100 - $data['module_sanity']), 1); -} - -ui_require_css_file('logon'); - -echo '
'; - -// -// Overview Table. -// -$table = new stdClass(); -$table->class = 'no-class'; -$table->cellpadding = 4; -$table->cellspacing = 4; -$table->head = []; -$table->data = []; -$table->headstyle[0] = 'text-align:center;'; -$table->width = '100%'; -$table->head_colspan[0] = 4; - -// Indicators. -$tdata = []; -$stats = reporting_get_stats_indicators($data, 120, 10, false); -$status = ''; -foreach ($stats as $stat) { - $status .= ''; -} - -$status .= '
'.$stat['title'].''.$stat['graph'].'
'; -$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->data[] = $tdata; - -// Alerts. -$tdata = []; -$tdata[0] = reporting_get_stats_alerts($data); -$table->rowclass[] = ''; -$table->data[] = $tdata; - -// Modules by status. -$tdata = []; - -$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; - -// Total agents and modules. -$tdata = []; -$tdata[0] = reporting_get_stats_agents_monitors($data); -$table->rowclass[] = ''; -$table->data[] = $tdata; - -// Users. -if (users_is_admin() || check_acl($config['id_user'], 0, 'UM')) { - $tdata = []; - $tdata[0] = reporting_get_stats_users($data); - $table->rowclass[] = ''; - $table->data[] = $tdata; -} - -ui_toggle( - html_print_table($table, true), - __('%s Overview', get_product_name()), - '', - 'overview', - false -); -unset($table); - -echo ''; -unset($table); -echo '

'; - -echo '
 
'; +html_print_action_buttons(''); diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 70c2b1cf60..54392630fc 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -548,6 +548,21 @@ $tableAgent->data['os'][0] .= html_print_div( true ); +$tableAgent->data['caption_os_version'][0] = __('OS version'); +$tableAgent->rowclass['os_version'] = 'w540px'; +$tableAgent->data['os_version'][0] = html_print_input_text( + 'os_version', + $os_version, + '', + 16, + 100, + true, + false, + false, + '', + 'w540px' +); + $tableAgent->data['caption_server'][0] = __('Server'); $tableAgent->rowclass['server'] = 'w540px'; $tableAgent->data['server'][0] = html_print_select( diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 701ce4894b..88d4b0e4ed 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -39,6 +39,7 @@ ui_require_javascript_file('encode_decode_base64'); ui_require_css_file('agent_manager'); use PandoraFMS\Event; +use PandoraFMS\ITSM\ITSM; check_login(); @@ -215,6 +216,7 @@ if ($create_agent) { $id_parent = (int) get_parameter_post('id_agent_parent'); $server_name = (string) get_parameter_post('server_name'); $id_os = (int) get_parameter_post('id_os'); + $os_version = (string) get_parameter_post('os_version'); $disabled = (int) get_parameter_post('disabled'); $custom_id_safe_output = strip_tags(io_safe_output(get_parameter('custom_id', ''))); $custom_id = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $custom_id_safe_output))); @@ -283,6 +285,7 @@ if ($create_agent) { 'comentarios' => $comentarios, 'modo' => $modo, 'id_os' => $id_os, + 'os_version' => $os_version, 'disabled' => $disabled, 'cascade_protection' => $cascade_protection, 'cascade_protection_module' => $cascade_protection_module, @@ -437,7 +440,7 @@ if ($id_agente) { [ 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$id_agente, 'content' => html_print_image( - 'images/alert@svg.svg', + 'images/add-alert.svg', true, [ 'title' => __('Alerts'), @@ -607,23 +610,6 @@ if ($id_agente) { $agent_wizard['active'] = false; } - - $total_incidents = agents_get_count_incidents($id_agente); - - // Incident tab. - if ($total_incidents > 0) { - $incidenttab['text'] = html_print_menu_button( - [ - 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=incident&id_agente='.$id_agente, - 'image' => 'images/logs@svg.svg', - 'title' => __('Incidents'), - ], - true - ); - - $incidenttab['active'] = ($tab === 'incident'); - } - if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === true) { if ($has_remote_conf !== false) { $agent_name = agents_get_name($id_agente); @@ -998,6 +984,7 @@ if ($update_agent) { $modo = (int) get_parameter_post('modo', 0); // Mode: Learning, Normal or Autodisabled. $id_os = (int) get_parameter_post('id_os'); + $os_version = (string) get_parameter_post('os_version'); $disabled = (bool) get_parameter_post('disabled'); $server_name = (string) get_parameter_post('server_name', ''); $id_parent = (int) get_parameter_post('id_agent_parent'); @@ -1123,6 +1110,7 @@ if ($update_agent) { 'disabled' => $disabled, 'id_parent' => $id_parent, 'id_os' => $id_os, + 'os_version' => $os_version, 'modo' => $modo, 'alias' => $alias, 'alias_as_name' => $alias_as_name, @@ -1284,6 +1272,7 @@ if ($id_agente) { $server_name = $agent['server_name']; $modo = $agent['modo']; $id_os = $agent['id_os']; + $os_version = $agent['os_version']; $disabled = $agent['disabled']; $id_parent = $agent['id_parent']; $custom_id = $agent['custom_id']; @@ -1337,6 +1326,12 @@ if ($update_module === true || $create_module === true) { */ $post_process = (string) get_parameter('post_process', 0.0); + if (modules_made_compatible($id_module_type) === true) { + $made_enabled = (bool) get_parameter_checkbox('made_enabled', 0); + } else { + $made_enabled = false; + } + $prediction_module = (int) get_parameter('prediction_module'); $max_timeout = (int) get_parameter('max_timeout'); $max_retries = (int) get_parameter('max_retries'); @@ -1359,6 +1354,14 @@ if ($update_module === true || $create_module === true) { } $configuration_data = (string) get_parameter('configuration_data'); + $array_configuration_data = explode(PHP_EOL, io_safe_output($configuration_data)); + $configuration_data = ''; + foreach ($array_configuration_data as $value) { + $configuration_data .= trim($value).PHP_EOL; + } + + $configuration_data = io_safe_input($configuration_data); + $old_configuration_data = (string) get_parameter('old_configuration_data'); $new_configuration_data = ''; @@ -1499,6 +1502,14 @@ if ($update_module === true || $create_module === true) { } $plugin_parameter = (string) get_parameter('plugin_parameter'); + + $array_plugin_parameter = explode(PHP_EOL, io_safe_output($plugin_parameter)); + $plugin_parameter = ''; + foreach ($array_plugin_parameter as $value) { + $plugin_parameter .= trim($value).PHP_EOL; + } + + $plugin_parameter = io_safe_input($plugin_parameter); } $parent_module_id = (int) get_parameter('parent_module_id'); @@ -1715,6 +1726,7 @@ if ($update_module) { 'plugin_parameter' => $plugin_parameter, 'id_plugin' => $id_plugin, 'post_process' => $post_process, + 'made_enabled' => $made_enabled, 'prediction_module' => $prediction_module, 'max_timeout' => $max_timeout, 'max_retries' => $max_retries, @@ -1913,6 +1925,7 @@ if ($create_module) { 'plugin_parameter' => $plugin_parameter, 'id_plugin' => $id_plugin, 'post_process' => $post_process, + 'made_enabled' => $made_enabled, 'prediction_module' => $prediction_module, 'max_timeout' => $max_timeout, 'max_retries' => $max_retries, @@ -2092,7 +2105,6 @@ if ($create_module) { if ($disable_module) { - hd($disable_module, true); $result = modules_change_disabled($disable_module, 1); $module_name = modules_get_agentmodule_name($disable_module); @@ -2116,13 +2128,11 @@ if ($create_module) { if ($result === NOERR) { - hd($disable_module, true); db_pandora_audit( AUDIT_LOG_MODULE_MANAGEMENT, 'Disable #'.$disable_module.' | '.$module_name.' | '.io_safe_output($agent['alias']) ); } else { - hd($disable_module, true); db_pandora_audit( AUDIT_LOG_MODULE_MANAGEMENT, 'Fail to disable #'.$disable_module.' | '.$module_name.' | '.io_safe_output($agent['alias']) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index a14bff4b92..487fe54e07 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -751,6 +751,10 @@ if ($agents !== false) { 'index.php?sec=reporting&sec2=operation/cluster/cluster&op=view&id=%s', $cluster->id() ); + $agentAlertUrl = sprintf( + 'index.php?sec=estado&sec2=operation/cluster/cluster&op=update&id=%s&page=6', + $cluster->id() + ); } else { $main_tab = ($check_aw === true) ? 'main' : 'module'; $agentNameUrl = sprintf( @@ -762,6 +766,10 @@ if ($agents !== false) { 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=%s', $agent['id_agente'] ); + $agentAlertUrl = sprintf( + 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente=%s', + $agent['id_agente'] + ); } if (empty($agent['alias']) === true) { @@ -825,7 +833,7 @@ if ($agents !== false) { ); } - if ((int) $agent['id_os'] !== 100) { + if ((int) $agent['id_os'] != CLUSTER_OS_ID) { $additionalOptionsAgentName[] = html_print_anchor( [ 'href' => ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$agent['id_agente']), @@ -837,7 +845,7 @@ if ($agents !== false) { $additionalOptionsAgentName[] = html_print_anchor( [ - 'href' => ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$agent['id_agente']), + 'href' => ui_get_full_url($agentAlertUrl), 'content' => __('Alerts'), ], true @@ -942,7 +950,7 @@ if ($agents !== false) { $os ) ), - 'onClick' => ($agent['id_os'] === CLUSTER_OS_ID) ? sprintf('if (!confirm(\'%s\')) return false', $agentDisableEnableCaption) : 'return true;', + 'onClick' => ($agent['id_os'] == CLUSTER_OS_ID) ? sprintf('if (!confirm(\'%s\')) return false', $agentDisableEnableCaption) : 'return true;', 'image' => sprintf('images/%s', $agentDisableEnableIcon), 'title' => $agentDisableEnableTitle, ], @@ -950,7 +958,7 @@ if ($agents !== false) { ); if ($check_aw === true && is_management_allowed() === true) { - if ($agent['id_os'] !== CLUSTER_OS_ID) { + if ($agent['id_os'] != CLUSTER_OS_ID) { $onClickActionDeleteAgent = 'if (!confirm(\' '.__('Are you sure?').'\')) return false;'; } else { $onClickActionDeleteAgent = 'if (!confirm(\' '.__('WARNING! - You are going to delete a cluster agent. Are you sure?').'\')) return false;'; diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 452d2a498a..a52813fbf3 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -294,6 +294,7 @@ if ($id_agent_module) { $plugin_parameter = $module['plugin_parameter']; $id_plugin = $module['id_plugin']; $post_process = $module['post_process']; + $made_enabled = $module['made_enabled']; $prediction_module = $module['prediction_module']; $custom_integer_1 = $module['custom_integer_1']; $custom_integer_2 = $module['custom_integer_2']; @@ -408,6 +409,7 @@ if ($id_agent_module) { $id_module_group = 1; $id_module_type = 1; $post_process = ''; + $made_enabled = false; $max_timeout = 0; $max_retries = 0; $min = ''; diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index f70af23627..ca74b7d171 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -1,4 +1,5 @@ data['switch_warning_threshold'][0] .= html_print_switch_ html_print_radio_button_extended('warning_thresholds_checks', 'warning_inverse', __('Inverse interval'), ($warning_inverse) ? 'warning_inverse' : false, $disabledBecauseInPolicy, '', '', true, false, '', 'radius-warning_inverse'), html_print_radio_button_extended('warning_thresholds_checks', 'percentage_warning', __('Percentage'), ($percentage_warning) ? 'percentage_warning' : false, $disabledBecauseInPolicy, '', '', true, false, '', 'radius-percentage_warning'), ], - [ 'class' => 'margin-top-10' ], + ['class' => 'margin-top-10'], true ); @@ -565,7 +566,7 @@ $tableBasicThresholds->data['switch_critical_threshold'][0] .= html_print_switch html_print_radio_button_extended('critical_thresholds_checks', 'critical_inverse', __('Inverse interval'), ($critical_inverse) ? 'critical_inverse' : false, $disabledBecauseInPolicy, '', '', true, false, '', 'radius-critical_inverse'), html_print_radio_button_extended('critical_thresholds_checks', 'percentage_critical', __('Percentage'), ($percentage_critical) ? 'percentage_critical' : false, $disabledBecauseInPolicy, '', '', true, false, '', 'radius-percentage_critical'), ], - [ 'class' => 'margin-top-10' ], + ['class' => 'margin-top-10'], true ); @@ -722,14 +723,14 @@ if ($cps_module > 0) { ob_start(); ?> data['ff_main_thresholds'][0] = html_print_switch_radio_butto html_print_radio_button_extended('each_ff', 0, __('All state changing'), $each_ff, false, 'ffStateChange(0)', '', true, false, '', 'ff_all_state'), html_print_radio_button_extended('each_ff', 1, __('Each state changing'), $each_ff, false, 'ffStateChange(1)', '', true, false, '', 'ff_each_state'), ], - [ 'add_content' => $ffThresholdsScript ], + ['add_content' => $ffThresholdsScript], true ); @@ -1376,6 +1377,24 @@ $table_advanced->data['process_unit'][1] = html_print_extended_select_for_post_p $disabledBecauseInPolicy ); +$table_advanced->rowclass['caption_made_enabled'] = 'w50p'; +$table_advanced->rowclass['made_enabled'] = 'w50p'; +$table_advanced->data['caption_made_enabled'][0] = __('MADE enabled').ui_print_help_tip( + __('By activating this option, the module data will be processed by the MADE engine (if active), and events will be generated automatically by the IA engine'), + true +); +$table_advanced->data['made_enabled'][0] = html_print_checkbox_switch( + 'made_enabled', + 1, + (bool) $made_enabled, + false, + false, + '', + false, + false, + 'wp100 static' +); + $table_advanced->data['title_5'] = html_print_subtitle_table(__('Notifications and alerts')); $table_advanced->data['caption_export_target'][0] = __('Export target'); @@ -1666,41 +1685,48 @@ ui_require_jquery_file('json'); ?> + /* ]]> */ + \ No newline at end of file diff --git a/pandora_console/godmode/agentes/module_manager_editor_web.php b/pandora_console/godmode/agentes/module_manager_editor_web.php index 727e16d5bf..6089a932ee 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_web.php +++ b/pandora_console/godmode/agentes/module_manager_editor_web.php @@ -318,7 +318,7 @@ foreach ($texts as $code => $text) { return; } - $(plugin_parameter).val('task_begin\ncookie 0\nresource 0\ntask_end'); + $(plugin_parameter).val('task_begin\nget https://demoweb.com/page/\ncheck_string text string or HTML code to search (regexp)\ntask_end\n'); $('#button-btn_loadbasic').attr('disabled', 'disabled'); diff --git a/pandora_console/godmode/alerts/alert_actions.php b/pandora_console/godmode/alerts/alert_actions.php index 97a492809e..e8915b05eb 100644 --- a/pandora_console/godmode/alerts/alert_actions.php +++ b/pandora_console/godmode/alerts/alert_actions.php @@ -405,6 +405,12 @@ $actions = array_slice($actions, $offset, $limit); $rowPair = true; $iterator = 0; foreach ($actions as $action) { + if ((isset($config['ITSM_enabled']) === false || (bool) $config['ITSM_enabled'] === false) + && $action['name'] === 'Create Pandora ITSM ticket' + ) { + continue; + } + if ($rowPair) { $table->rowclass[$iterator] = 'rowPair'; } else { diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index b6231544d1..a59de7f5e2 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -1,16 +1,33 @@ '; @@ -187,7 +215,7 @@ if (is_ajax()) { 0, '', false, - $is_management_allowed, + $management_is_not_allowed, "UndefineTinyMCE('#textarea_field".$i."_recovery_value')", '', true @@ -199,7 +227,7 @@ if (is_ajax()) { 0, '', true, - $is_management_allowed, + $management_is_not_allowed, "defineTinyMCE('#textarea_field".$i."_recovery_value')", '', true @@ -214,7 +242,7 @@ if (is_ajax()) { 'class="fields_recovery"', true, '', - $is_management_allowed + $management_is_not_allowed || $recovery_disabled ); } else if (preg_match('/^_content_type_$/i', $field_value)) { $editor_type_chkbx = '
'; @@ -228,7 +256,7 @@ if (is_ajax()) { 'text/plain', '', '', - $is_management_allowed, + $management_is_not_allowed, '', '', true @@ -240,7 +268,7 @@ if (is_ajax()) { 'text/html', '', 'text/html', - $is_management_allowed, + $management_is_not_allowed, '', '', true @@ -259,7 +287,7 @@ if (is_ajax()) { 'text/plain', '', '', - $is_management_allowed, + $management_is_not_allowed, '', '', true @@ -271,7 +299,7 @@ if (is_ajax()) { 'text/html', '', 'text/html', - $is_management_allowed, + $management_is_not_allowed, '', '', true @@ -279,78 +307,304 @@ if (is_ajax()) { $editor_type_chkbx .= '
'; $rfield = $editor_type_chkbx; // Select type. - } else if (preg_match('/^_integria_type_custom_field_$/i', $field_value)) { - $ffield = ''; - $rfield = ''; + } else if (preg_match('/^_custom_field_ITSM_$/i', $field_value)) { + $ffield = ''; + $rfield = ''; - $ffield .= '
'.html_print_switch( - [ - 'name' => 'field'.$i.'_value[]', - 'value' => '', - ] - ).'
'; - $rfield .= '
'.html_print_switch( - [ - 'name' => 'field'.$i.'_recovery_value[]', - 'value' => '', - ] - ).'
'; + $ffield .= '
'.html_print_switch( + [ + 'name' => 'field'.$i.'_value[]', + 'value' => '', + ] + ).'
'; + $rfield .= '
'.html_print_switch( + [ + 'name' => 'field'.$i.'_recovery_value[]', + 'value' => '', + 'disabled' => $management_is_not_allowed || $recovery_disabled, + ] + ).'
'; - $ffield .= html_print_select( - '', - 'field'.$i.'_value[]', + $ffield .= html_print_select( + '', + 'field'.$i.'_value[]', + '', + '', + __('None'), + '', + true, + false, + false, + 'fields', + $management_is_not_allowed, + 'width: 100%;', + false, + false, + false, + '', + false, + false, + false, + false, + false + ); + + $rfield .= html_print_select( + '', + 'field'.$i.'_recovery_value[]', + '', + '', + __('None'), + '', + true, + false, + false, + 'fields', + $management_is_not_allowed || $recovery_disabled, + 'width: 100%;', + false, + false, + false, + '', + false, + false, + false, + false, + false + ); + + $ffield .= html_print_input_text( + 'field'.$i.'_value[]', + '', + '', + 50, + 50, + true, + false, + false, + '', + 'datepicker', + '', + 'off', + false, + '', + '', + '', + $management_is_not_allowed + ); + $rfield .= html_print_input_text( + 'field'.$i.'_recovery_value[]', + '', + '', + 50, + 50, + true, + false, + false, + '', + 'datepicker', + '', + 'off', + false, + '', + '', + '', + $management_is_not_allowed || $recovery_disabled + ); + + $ffield .= html_print_textarea( + 'field'.$i.'_value[]', + 5, + 1, + '', + 'style="min-height:40px; '.$style.'" class="fields"', + true, + '', + $management_is_not_allowed + ); + + $rfield .= html_print_textarea( + 'field'.$i.'_recovery_value[]', + 5, + 1, + '', + 'style="min-height:40px; '.$style.'" class="fields_recovery', + true, + '', + $management_is_not_allowed || $recovery_disabled + ); + + $values_input_number = [ + 'name' => 'field'.$i.'_value[]', + 'value' => 0, + 'id' => 'field'.$i.'_value', + 'return' => true, + ]; + + if ($management_is_not_allowed === true) { + $values_input_number['disabled'] = true; + } + + $ffield .= html_print_input_number($values_input_number); + + $values_input_number_recovery = [ + 'name' => 'field'.$i.'_recovery_value[]', + 'value' => 0, + 'id' => 'field'.$i.'_recovery_value', + 'return' => true, + ]; + + if ($management_is_not_allowed || $recovery_disabled) { + $values_input_number_recovery['disabled'] = true; + } + + $rfield .= html_print_input_number($values_input_number_recovery); + + $ffield .= html_print_input_text( + 'field'.$i.'_value[]', + '', + '', + 50, + 255, + true, + false, + false, + '', + 'normal w98p', + '', + 'off', + false, + false, + '', + '', + $management_is_not_allowed + ); + $rfield .= html_print_input_text( + 'field'.$i.'_recovery_value[]', + '', + '', + 50, + 255, + true, + false, + false, + '', + 'normal w98p', + '', + 'off', + false, + false, + '', + '', + $management_is_not_allowed || $recovery_disabled + ); + } else if (str_starts_with($field_value, '_ITSM_')) { + $nothing = ''; + $nothing_value = 0; + $mode = 'select'; + switch ($field_value) { + case '_ITSM_groups_': + $fields_array = []; + try { + $ITSM = new ITSM(); + $fields_array = $ITSM->getGroups(); + } catch (\Throwable $th) { + $error = $th->getMessage(); + $fields_array = []; + } + break; + + case '_ITSM_priorities_': + $fields_array = []; + try { + $ITSM = new ITSM(); + $fields_array = $ITSM->getPriorities(); + } catch (\Throwable $th) { + $error = $th->getMessage(); + $fields_array = []; + } + break; + + case '_ITSM_types_': + $fields_array = []; + try { + $ITSM = new ITSM(); + $fields_array = $ITSM->getObjectypes(); + } catch (\Throwable $th) { + $error = $th->getMessage(); + $fields_array = []; + } + + $nothing = __('None'); + $nothing_value = 0; + break; + + case '_ITSM_status_': + $fields_array = []; + try { + $ITSM = new ITSM(); + $fields_array = $ITSM->getStatus(); + } catch (\Throwable $th) { + $error = $th->getMessage(); + $fields_array = []; + } + break; + + default: + // Nothing. + $mode = ''; + break; + } + + if ($mode === 'select') { + $ffield = html_print_select( + $fields_array, + 'field'.$i.'_value', '', '', - __('None'), - '', + $nothing, + $nothing_value, true, false, false, 'fields', - $is_management_allowed, - 'width: 100%;' + $management_is_not_allowed ); - $rfield .= html_print_select( - '', - 'field'.$i.'_recovery_value[]', + $rfield = html_print_select( + $fields_array, + 'field'.$i.'_recovery_value', '', '', - __('None'), - '', + $nothing, + $nothing_value, true, false, false, - 'fields', - $is_management_allowed, - 'width: 100%;' + 'fields_recovery', + $management_is_not_allowed || $recovery_disabled ); - - $ffield .= html_print_input_text('field'.$i.'_value[]', '', '', 10, 10, true, false, false, '', 'datepicker'); - $rfield .= html_print_input_text('field'.$i.'_recovery_value[]', '', '', 10, 10, true, false, false, '', 'datepicker'); - - $ffield .= html_print_textarea( - 'field'.$i.'_value[]', - 5, - 1, + } else { + $ffield = html_print_autocomplete_users_from_pandora_itsm( + 'field'.$i.'_value', '', - 'style="min-height:40px; '.$style.'" class="fields"', true, - '', - $is_management_allowed + 0, + $management_is_not_allowed, + false, + 'ITSM_users' ); - - $rfield .= html_print_textarea( - 'field'.$i.'_recovery_value[]', - 5, - 1, + $rfield = html_print_autocomplete_users_from_pandora_itsm( + 'field'.$i.'_recovery_value', '', - 'style="min-height:40px; '.$style.'" class="fields_recovery', true, - '', - $is_management_allowed + 0, + $management_is_not_allowed || $recovery_disabled, + false, + 'ITSM_users' ); + } } else { $fields_value_select = []; $force_print_select = false; @@ -468,7 +722,7 @@ if (is_ajax()) { false, false, 'fields', - $is_management_allowed + $management_is_not_allowed ); $rfield = html_print_select( $fields_value_select, @@ -481,7 +735,7 @@ if (is_ajax()) { false, false, 'fields_recovery', - $is_management_allowed + $management_is_not_allowed || $recovery_disabled ); } else { $ffield = html_print_textarea( @@ -492,7 +746,7 @@ if (is_ajax()) { 'style="'.$style.'" class="fields min-height-40px w100p"', true, '', - $is_management_allowed + $management_is_not_allowed ); $rfield = html_print_textarea( 'field'.$i.'_recovery_value', @@ -502,7 +756,7 @@ if (is_ajax()) { 'style="'.$style.'" class="fields_recovery min-height-40px w100p', true, '', - $is_management_allowed + $management_is_not_allowed || $recovery_disabled ); } } @@ -515,7 +769,7 @@ if (is_ajax()) { 'style="'.$style.'" class="fields min-height-40px w100p"', true, '', - $is_management_allowed + $management_is_not_allowed ); $rfield = html_print_textarea( 'field'.$i.'_recovery_value', @@ -525,7 +779,7 @@ if (is_ajax()) { 'style="'.$style.'" class="fields_recovery min-height-40px w100p"', true, '', - $is_management_allowed + $management_is_not_allowed || $recovery_disabled ); } @@ -684,9 +938,7 @@ if ($delete_command) { $result = alerts_delete_alert_command($id); - $auditMessage = ((bool) $result === true) - ? sprintf('Delete alert command #%s', $id) - : sprintf('Fail try to delete alert command #%s', $id); + $auditMessage = ((bool) $result === true) ? sprintf('Delete alert command #%s', $id) : sprintf('Fail try to delete alert command #%s', $id); db_pandora_audit( AUDIT_LOG_ALERT_MANAGEMENT, @@ -775,6 +1027,12 @@ $commands = array_slice($commands, $offset, $limit); foreach ($commands as $command) { $data = []; + if ((isset($config['ITSM_enabled']) === false || (bool) $config['ITSM_enabled'] === false) + && $command['name'] === 'Pandora ITSM Ticket' + ) { + continue; + } + $data['name'] = ''; // (IMPORTANT, DO NOT CHANGE!) only users with permissions over "All" group have access to edition of commands belonging to "All" group. diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index de07bce961..13151b4de9 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -105,8 +105,8 @@ $groups_user = users_get_groups($config['id_user']); if (!empty($groups_user)) { $groups = implode(',', array_keys($groups_user)); - if ($config['integria_enabled'] == 0) { - $integria_command = 'Integria IMS Ticket'; + if ($config['ITSM_enabled'] == 0) { + $integria_command = 'Pandora ITSM Ticket'; $sql = sprintf('SELECT taa.id, taa.name FROM talert_actions taa INNER JOIN talert_commands tac ON taa.id_alert_command = tac.id WHERE tac.name <> "%s" AND taa.id_group IN (%s)', $integria_command, $groups); } else { $sql = "SELECT id, name FROM talert_actions WHERE id_group IN ($groups)"; @@ -206,9 +206,10 @@ $table->data[2][0] = html_print_label_input_block( if (isset($step) === false) { echo '
'; - html_print_table($table); } +html_print_table($table); + if (isset($step) === false) { $output = ''; diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 5dc0c78019..5d71895ecd 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -620,7 +620,21 @@ foreach ($simple_alerts as $alert) { $main_tab = 'module'; } - $data[0] = ''; + if ((int) agents_get_os($id_agent) === CLUSTER_OS_ID) { + $cluster = PandoraFMS\Cluster::loadFromAgentId($id_agent); + $agentAlertUrl = sprintf( + 'index.php?sec=estado&sec2=operation/cluster/cluster&op=update&id=%s&page=6', + $cluster->id() + ); + } else { + $agentAlertUrl = sprintf( + 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=%s&id_agente=%s', + $main_tab, + $id_agent + ); + } + + $data[0] = ''; if ($alert['disabled']) { $data[0] .= ''; @@ -811,7 +825,7 @@ foreach ($simple_alerts as $alert) { $data[3] .= ''; $data[3] .= ''.html_print_label_input_block( __('Agent'), - ui_print_truncate_text($alias, 'agent_small', false, true, true, '[…]') + ui_print_truncate_text($alias, 'agent_medium', false, true, true, '[…]') ).''; $data[3] .= ''.html_print_label_input_block( __('Module'), diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 17669ab248..1dc32ba086 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -650,6 +650,11 @@ if ($id_agente) { echo $messageAction; include_once 'godmode/alerts/alert_list.list.php'; + + if (isset($step) === true && $step === true) { + return; + } + $all_groups = agents_get_all_groups_agent($id_agente, $agent['id_grupo']); if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) { include_once 'godmode/alerts/alert_list.builder.php'; diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 033171953b..4883467c10 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -11,12 +11,12 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// Load global vars +use PandoraFMS\ITSM\ITSM; +// Load global vars. global $config; require_once $config['homedir'].'/include/functions_alerts.php'; require_once $config['homedir'].'/include/functions_users.php'; -require_once $config['homedir'].'/include/functions_integriaims.php'; enterprise_include_once('meta/include/functions_alerts_meta.php'); check_login(); @@ -39,11 +39,19 @@ if (is_ajax()) { $get_integria_ticket_custom_types = (bool) get_parameter('get_integria_ticket_custom_types'); if ($get_integria_ticket_custom_types) { - $ticket_type_id = get_parameter('ticket_type_id'); + $ticket_type_id = (int) get_parameter('ticket_type_id', 0); + if (empty($ticket_type_id) === false) { + $error = ''; + try { + $ITSM = new ITSM(); + $fields = $ITSM->getObjecTypesFields($ticket_type_id); + } catch (\Throwable $th) { + $error = $th->getMessage(); + } - $api_call = integria_api_call(null, null, null, null, 'get_incident_fields', $ticket_type_id, false, 'json'); + echo json_encode($fields); + } - echo $api_call; return; } } @@ -150,6 +158,22 @@ if ($id) { $action = alerts_get_alert_action($id); $name = $action['name']; $id_command = $action['id_alert_command']; + $command = alerts_get_alert_command($id_command); + if (empty($command) === false && $command['name'] === io_safe_input('Pandora ITSM Ticket')) { + $action['field1'] = io_safe_output(($action['field1'] ?? $config['incident_title'])); + $action['field2'] = io_safe_output(($action['field2'] ?? $config['default_group'])); + $action['field3'] = io_safe_output(($action['field3'] ?? $config['default_criticity'])); + $action['field4'] = io_safe_output(($action['field4'] ?? $config['default_owner'])); + $action['field5'] = io_safe_output(($action['field5'] ?? $config['incident_type'])); + $action['field6'] = io_safe_output(($action['field6'] ?? $config['incident_status'])); + $action['field7'] = io_safe_output(($action['field7'] ?? $config['incident_content'])); + $action['field2_recovery'] = io_safe_output(($action['field2'] ?? $config['default_group'])); + $action['field3_recovery'] = io_safe_output(($action['field3'] ?? $config['default_criticity'])); + $action['field4_recovery'] = io_safe_output(($action['field4'] ?? $config['default_owner'])); + $action['field5_recovery'] = io_safe_output(($action['field5'] ?? $config['incident_type'])); + $action['field6_recovery'] = io_safe_output(($action['field6_recovery'] ?? $config['incident_status'])); + $action['field7_recovery'] = io_safe_output(($action['field7_recovery'] ?? $config['incident_content'])); + } $group = $action['id_group']; $action_threshold = $action['action_threshold']; @@ -235,11 +259,11 @@ $table->data[0][1] = html_print_label_input_block( ) ); -$create_ticket_command_id = db_get_value('id', 'talert_commands', 'name', io_safe_input('Integria IMS Ticket')); +$create_ticket_command_id = db_get_value('id', 'talert_commands', 'name', io_safe_input('Pandora ITSM Ticket')); $sql_exclude_command_id = ''; -if (!is_metaconsole() && $config['integria_enabled'] == 0 && $create_ticket_command_id !== false) { +if (!is_metaconsole() && $config['ITSM_enabled'] == 0 && $create_ticket_command_id !== false) { $sql_exclude_command_id = ' AND id <> '.$create_ticket_command_id; } @@ -355,24 +379,26 @@ $table_macros->data[1][2] = html_print_label_input_block( ) ); -// Selector will work only with Integria activated. -$integriaIdName = 'integria_wu'; -$table_macros->colspan[$integriaIdName][0] = 3; -$table_macros->data[$integriaIdName][0] = html_print_label_input_block( - __('Create workunit on recovery').ui_print_help_tip( - __('If closed status is set on recovery, a workunit will be added to the ticket in Integria IMS rather that closing the ticket.'), - true - ), - html_print_checkbox_switch_extended( - 'create_wu_integria', - 1, - $create_wu_integria, - false, - '', - $disabled_attr, - true - ) -); +if (empty($command) === false && $command['name'] === io_safe_input('Pandora ITSM Ticket')) { + // Selector will work only with Integria activated. + $integriaIdName = 'integria_wu'; + $table_macros->colspan[$integriaIdName][0] = 3; + $table_macros->data[$integriaIdName][0] = html_print_label_input_block( + __('Create workunit on recovery').ui_print_help_tip( + __('If closed status is set on recovery, a workunit will be added to the ticket in Pandora ITSM rather that closing the ticket.'), + true + ), + html_print_checkbox_switch_extended( + 'create_wu_integria', + 1, + $create_wu_integria, + false, + '', + $disabled_attr, + true + ) + ); +} for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $table_macros->data['field'.$i][0] = html_print_image( @@ -504,7 +530,6 @@ $(document).ready (function () { }, function(data) { var max_macro_fields = ; - data.forEach(function(custom_field, key) { var custom_field_key = key+8; // Custom fields start from field 8. @@ -523,9 +548,9 @@ $(document).ready (function () { custom_field_row.html(new_html_content); switch (custom_field.type) { - case 'checkbox': - var checkbox_selector = $('input:not(.datepicker)[name=field'+custom_field_key+'_value\\[\\]]'); - var checkbox_recovery_selector = $('input:not(.datepicker)[name=field'+custom_field_key+'_recovery_value\\[\\]]'); + case 'CHECKBOX': + var checkbox_selector = $('input[type="checkbox"][name=field'+custom_field_key+'_value\\[\\]]'); + var checkbox_recovery_selector = $('input[type="checkbox"][name=field'+custom_field_key+'_recovery_value\\[\\]]'); checkbox_selector.on('change', function() { if (checkbox_selector.prop('checked')) { @@ -565,17 +590,17 @@ $(document).ready (function () { $('[name=field'+custom_field_key+'_value_container]').show(); $('[name=field'+custom_field_key+'_recovery_value_container]').show(); - $('input:not(.datepicker)[name=field'+custom_field_key+'_value\\[\\]]').show(); - $('input:not(.datepicker)[name=field'+custom_field_key+'_recovery_value\\[\\]]').show(); + $('input[type="checkbox"][name=field'+custom_field_key+'_value\\[\\]]').show(); + $('input[type="checkbox"][name=field'+custom_field_key+'_recovery_value\\[\\]]').show(); break; - case 'combo': + case 'COMBO': var combo_input = $('select[name=field'+custom_field_key+'_value\\[\\]]'); var combo_input_recovery = $('select[name=field'+custom_field_key+'_recovery_value\\[\\]]'); combo_input.find('option').remove(); combo_input_recovery.find('option').remove(); - var combo_values_array = custom_field.combo_value.split(','); + var combo_values_array = custom_field.comboValue.split(','); combo_values_array.forEach(function(value) { combo_input.append($('' ); + + $table->data['math_function'][0] = html_print_label_input_block( + __('Math function'), + html_print_select( + alerts_get_alert_templates_functions(), + 'math_function', + $math_function, + '', + __('None'), + 0, + true, + false, + false, + 'w100p', + (!$is_management_allowed | $disabled) + ) + ); + + $table->data['time_window'][0] = html_print_label_input_block( + __('Time window').ui_print_help_tip(__('Limits to data in the following time window.'), true), + html_print_select( + alerts_get_alert_templates_windows(), + 'time_window', + $time_window, + '', + __('None'), + 0, + true, + false, + false, + 'w100p', + (!$is_management_allowed | $disabled) + ) + ); + + $table->data['condition'][0] = html_print_label_input_block( + __('Alert condition'), + html_print_select( + alerts_get_alert_templates_conditions(), + 'condition', + $condition, + '', + __('None'), + 0, + true, + false, + false, + 'w100p', + (!$is_management_allowed | $disabled) + ) + ); + $table->data['value'][1] = html_print_label_input_block( __('Value'), html_print_input_text( @@ -1088,6 +1149,12 @@ if ($step == 2) { $table->rowstyle['min'] = ''; break; + case 'complex': + $table->rowstyle['math_function'] = ''; + $table->rowstyle['condition'] = ''; + $table->rowstyle['time_window'] = ''; + break; + case 'onchange': $show_matches = true; break; @@ -1299,6 +1366,7 @@ var onchange_not = ; var error_message_min_max_zero = ; var not_normal = ; +var complex = within ')."'"; ?>; function check_fields_step2() { var correct = true; @@ -1361,6 +1429,68 @@ function render_example () { else { $("span#value").empty ().append (vvalue); } + + /* Set math function */ + var vfunction = $("select#math_function").val(); + var functionMessage = ""; + + if (vfunction == "0") { + functionMessage = ""; + } else { + if (vfunction == "avg"){ + $("span#value").empty (); + } + functionMessage = vfunction; + } + $("span#math_function").empty ().append (functionMessage); + + /* Set complex value */ + if($("select#type").val() == "complex"){ + var valueMessage = ""; + + if(vfunction == "avg"){ + valueMessage = ""; + }else if (vvalue == "") { + valueMessage = "" ; + } else { + valueMessage = vvalue; + } + + $("span#value").empty ().append (valueMessage); + } + + /* Set condition */ + var vCondition = $("select#condition").val(); + var conditionMessage = "" ; + switch (vCondition){ + case "greater": + conditionMessage = (vfunction == "avg") ? "increases" : "is more than"; + break + case "lower": + conditionMessage = (vfunction == "avg") ? "decreases" : "is less than"; + break + case "equal": + conditionMessage = (vfunction == "avg") ? "remains the same" : "is equal to"; + break + } + + $("span#condition").empty ().append (conditionMessage); + + var vWindow = $("select#time_window").val(); + + /* Set time window */ + var timeWindowMessages = { + "thirty_days": "the last 30 days", + "month": "the last month", + "seven_days": "the last 7 days", + "week": "the last week", + "one_day": "the last 24 hours", + "today": "today" + }; + var windowMessage = timeWindowMessages[vWindow] || ""; + + $("span#time_window").empty().append(windowMessage); + } // Fix for metaconsole toggle @@ -1388,6 +1518,18 @@ if ($step == 2) { $("input#text-value").keyup (render_example); $("input#text-max").keyup (render_example); $("input#text-min").keyup (render_example); + $("#condition").change (render_example); + $("#time_window").change (render_example); + + $("#math_function").change (function () { + if (["0", 'avg'].includes(this.value)) { + $("#template-value").hide(); + } else { + $("#template-value").show (); + } + + render_example (); + }) $("#type").change (function () { switch (this.value) { @@ -1395,6 +1537,7 @@ if ($step == 2) { case "not_equal": $("img#regex_good, img#regex_bad, span#matches_value").hide (); $("#template-max, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-value, #template-example").show (); /* Show example */ @@ -1405,6 +1548,7 @@ if ($step == 2) { break; case "regex": $("#template-max, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-value, #template-example, span#matches_value").show (); check_regex (); @@ -1416,6 +1560,7 @@ if ($step == 2) { break; case "max_min": $("#template-value").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-max, #template-min, #template-example, span#matches_value").show (); /* Show example */ @@ -1424,9 +1569,25 @@ if ($step == 2) { else $("span#example").empty ().append (between_not); + break; + case "complex": + $("pan#matches_value, #template-example, #template-value, #template-max, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").show (); + $("#template-example").show (); + + if (["0", 'avg'].includes($("#math_function").val())) { + $("#template-value").hide(); + }else { + $("#template-value").show(); + } + + /* Show example */ + $("span#example").empty ().append (complex); + break; case "max": $("#template-value, #template-min, span#matches_value").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-max, #template-example").show (); /* Show example */ @@ -1434,6 +1595,7 @@ if ($step == 2) { break; case "min": $("#template-value, #template-max, span#matches_value").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-min, #template-example").show (); /* Show example */ @@ -1441,6 +1603,7 @@ if ($step == 2) { break; case "warning": $("#template-value, #template-max, span#matches_value, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-example").show (); /* Show example */ @@ -1448,6 +1611,7 @@ if ($step == 2) { break; case "critical": $("#template-value, #template-max, span#matches_value, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-example").show (); /* Show example */ @@ -1455,6 +1619,7 @@ if ($step == 2) { break; case "not_normal": $("#template-value, #template-max, span#matches_value, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-example").show (); /* Show example */ @@ -1462,6 +1627,7 @@ if ($step == 2) { break; case "onchange": $("#template-value, #template-max, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-example, span#matches_value").show (); /* Show example */ @@ -1472,6 +1638,7 @@ if ($step == 2) { break; case "unknown": $("#template-value, #template-max, span#matches_value, #template-min").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); $("#template-example").show (); if ($("#text-min_alerts").val() > 0 ) { @@ -1483,6 +1650,7 @@ if ($step == 2) { break; default: $("#template-value, #template-max, #template-min, #template-example, span#matches_value").hide (); + $("#template-math_function, #template-condition, #template-time_window").hide (); break; } diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index e230055f1e..113c156df3 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -61,6 +61,9 @@ if ($id) { $filter = events_get_event_filter($id); $id_group_filter = $filter['id_group_filter']; $id_group = $filter['id_group']; + // Get owner user private filter. + $private_filter = ($filter['private_filter_user'] === null || $filter['private_filter_user'] === '') ? 0 : 1; + $private_filter_user = $filter['private_filter_user']; $id_name = $filter['id_name']; $event_type = $filter['event_type']; $severity = explode(',', $filter['severity']); @@ -113,6 +116,7 @@ if ($id) { $server_id = ($filter['server_id'] ?? ''); } else { $id_group = ''; + $private_filter = 0; $id_group_filter = ''; $id_name = ''; $event_type = ''; @@ -167,8 +171,8 @@ if ($update || $create) { $id_user_ack = get_parameter('id_user_ack', ''); $owner_user = get_parameter('owner_user', ''); $group_rep = get_parameter('group_rep', ''); - $date_from = get_parameter('date_from', ''); - $date_to = get_parameter('date_to', ''); + $date_from = get_parameter('date_from', '0000-00-00'); + $date_to = get_parameter('date_to', '0000-00-00'); $source = get_parameter('source'); $id_extra = get_parameter('id_extra'); $user_comment = get_parameter('user_comment'); @@ -192,6 +196,16 @@ if ($update || $create) { $server_id = implode(',', $servers_array); } + // Get private filter from user. + $private_filter = get_parameter_switch('private_filter_event', 0); + if ((int) $private_filter === 1 && $create) { + $private_filter_user = $_SESSION['id_usuario']; + } else if ((int) $private_filter === 1 && $update) { + $private_filter_user = ($private_filter_user === $_SESSION['id_usuario']) ? $private_filter_user : $_SESSION['id_usuario']; + } else if ((int) $private_filter === 0) { + $private_filter_user = null; + } + $values = [ 'id_name' => $id_name, 'id_group_filter' => $id_group_filter, @@ -222,6 +236,7 @@ if ($update || $create) { 'custom_data' => $custom_data, 'custom_data_filter_type' => $custom_data_filter_type, 'server_id' => $server_id, + 'private_filter_user' => $private_filter_user, ]; $severity = explode(',', $severity); @@ -293,6 +308,17 @@ $table->data[0][0] = html_print_label_input_block( false, '', 'w100p' + ).html_print_label_input_block( + __('Private'), + html_print_checkbox_switch( + 'private_filter_event', + $private_filter, + $private_filter, + true, + false, + 'checked_slide_events(this);', + true + ) ) ); diff --git a/pandora_console/godmode/events/event_filter.php b/pandora_console/godmode/events/event_filter.php index 533bfe1190..c4f1860e6f 100644 --- a/pandora_console/godmode/events/event_filter.php +++ b/pandora_console/godmode/events/event_filter.php @@ -133,6 +133,18 @@ $filters = db_get_all_rows_sql($sql); if ($filters === false) { $filters = []; +} else { + foreach ($filters as $key => $filter) { + $permission = users_is_admin($config['id_user']); + // Validate permission and private filter user. + if ($permission || $filter['private_filter_user'] === $config['id_user']) { + if ($filter['private_filter_user'] !== null) { + $filters[$key]['id_name'] = $filter['id_name'].' (P)'; + } + } else if ($filter['private_filter_user'] !== null) { + unset($filters[$key]); + } + } } $table = new stdClass(); diff --git a/pandora_console/godmode/events/event_responses.list.php b/pandora_console/godmode/events/event_responses.list.php index 0cf83a4eed..0e39683c7e 100644 --- a/pandora_console/godmode/events/event_responses.list.php +++ b/pandora_console/godmode/events/event_responses.list.php @@ -75,6 +75,12 @@ foreach ($event_responses as $response) { continue; } + if ((isset($config['ITSM_enabled']) === false || (bool) $config['ITSM_enabled'] === false) + && $response['name'] === 'Create ticket in Pandora ITSM from event' + ) { + continue; + } + $data = []; $data[0] = ''.$response['name'].''; $data[1] = $response['description']; diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index fbb63c49d3..156ca507d8 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -916,7 +916,24 @@ $table->data[17][0] = html_print_label_input_block( ) ); -$table->data[17][1] = html_print_label_input_block( +$table->data['made_enabled'][1] = html_print_label_input_block( + __('MADE enabled').ui_print_help_tip( + __('By activating this option, the module data will be processed by the MADE engine (if active), and events will be generated automatically by the IA engine'), + true + ), + html_print_checkbox_switch( + 'made_enabled', + 1, + false, + true, + false, + '', + false, + 'wp100 static' + ) +); + +$table->data[17][2] = html_print_label_input_block( __('SNMP community'), html_print_input_text( 'snmp_community', @@ -1653,7 +1670,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").hide(); var params = { @@ -1728,7 +1746,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").show (); switch($('#module_type').val()) { @@ -1838,7 +1857,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").hide (); $('input[type=checkbox]').attr('checked', false); $('input[type=checkbox]').attr('disabled', true); @@ -1877,7 +1897,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").show(); } else { @@ -1908,7 +1929,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").hide(); } } @@ -1932,6 +1954,9 @@ $(document).ready (function () { else if (this.id == "checkbox-dynamic_two_tailed") { return; //Do none } + else if (this.id == "checkbox-made_enabled") { + return; //Do none + } else { if (this.id == "checkbox-force_group") { $("#checkbox-recursion").prop("checked", false); @@ -1964,7 +1989,7 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + "tr#delete_table-40").show (); } else { @@ -1995,7 +2020,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").hide(); } } @@ -2085,7 +2111,8 @@ $(document).ready (function () { "tr#delete_table-36, " + "tr#delete_table-37, " + "tr#delete_table-38, " + - "tr#delete_table-39, " + + "tr#delete_table-39, " + + "tr#delete_table-made_enabled, " + "tr#delete_table-40").hide(); jQuery.post ("ajax.php", @@ -2315,6 +2342,7 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' 'module_interval', 'disabled', 'post_process', + 'made_enabled', 'unit_select', 'snmp_community', 'snmp_oid', @@ -2626,6 +2654,10 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' $values['macros'] = json_encode($module_macros); } + if (modules_made_compatible($module['id_tipo_modulo']) === false) { + $values['made_enabled'] = 0; + } + $result = modules_update_agent_module( $module['id_agente_modulo'], $values, diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 7cd504c8ac..94509ab820 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -81,13 +81,14 @@ if ((bool) check_acl($config['id_user'], 0, 'AR') === true if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { // Applications. $sub2 = []; + // Check if app has been migrated. if (enterprise_installed() === true) { - $sub2['godmode/servers/discovery&wiz=app&mode=MicrosoftSQLServer']['text'] = __('Microsoft SQL Server (legacy)'); - $sub2['godmode/servers/discovery&wiz=app&mode=mysql']['text'] = __('Mysql (legacy)'); - $sub2['godmode/servers/discovery&wiz=app&mode=oracle']['text'] = __('Oracle (legacy)'); - $sub2['godmode/servers/discovery&wiz=app&mode=vmware']['text'] = __('VMware (legacy)'); - $sub2['godmode/servers/discovery&wiz=app&mode=SAP']['text'] = __('SAP (legacy)'); - $sub2['godmode/servers/discovery&wiz=app&mode=DB2']['text'] = __('DB2 (legacy)'); + (ManageExtensions::isMigrated('pandorafms.mssql') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=MicrosoftSQLServer']['text'] = __('Microsoft SQL Server (legacy)')); + (ManageExtensions::isMigrated('pandorafms.mysql') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=mysql']['text'] = __('Mysql (legacy)')); + (ManageExtensions::isMigrated('pandorafms.oracle') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=oracle']['text'] = __('Oracle (legacy)')); + (ManageExtensions::isMigrated('pandorafms.vmware') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=vmware']['text'] = __('VMware (legacy)')); + (ManageExtensions::isMigrated('pandorafms.sap.desert') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=SAP']['text'] = __('SAP (legacy)')); + (ManageExtensions::isMigrated('pandorafms.db2') === true) ?: ($sub2['godmode/servers/discovery&wiz=app&mode=DB2']['text'] = __('DB2 (legacy)')); } $extensions = ManageExtensions::getExtensionBySection('app'); @@ -112,9 +113,9 @@ if ((bool) check_acl($config['id_user'], 0, 'AR') === true // Cloud. $sub2 = []; if (enterprise_installed() === true) { - $sub2['godmode/servers/discovery&wiz=cloud&mode=amazonws']['text'] = __('Amazon Web Services (legacy)'); - $sub2['godmode/servers/discovery&wiz=cloud&mode=azure']['text'] = __('Microsoft Azure (legacy)'); - $sub2['godmode/servers/discovery&wiz=cloud&mode=gcp']['text'] = __('Google Compute Platform (legacy)'); + (ManageExtensions::isMigrated('pandorafms.aws.ec2') === true) ?: (ManageExtensions::isMigrated('pandorafms.aws.s3') === true) ?: (ManageExtensions::isMigrated('pandorafms.aws.rds') === true) ?: ($sub2['godmode/servers/discovery&wiz=cloud&mode=amazonws']['text'] = __('Amazon Web Services (legacy)')); + (ManageExtensions::isMigrated('pandorafms.azure.mc') === true) ?: ($sub2['godmode/servers/discovery&wiz=cloud&mode=azure']['text'] = __('Microsoft Azure (legacy)')); + (ManageExtensions::isMigrated('pandorafms.azure.gcp.ce') === true) ?: ($sub2['godmode/servers/discovery&wiz=cloud&mode=gcp']['text'] = __('Google Compute Platform (legacy)')); } @@ -383,6 +384,7 @@ if ($access_console_node === true) { $sub['godmode/alerts/alert_special_days']['pages'] = ['godmode/alerts/configure_alert_special_days']; enterprise_hook('eventalerts_submenu'); + enterprise_hook('alert_log_submenu'); $sub['godmode/snmpconsole/snmp_alert']['text'] = __('SNMP alerts'); $sub['godmode/snmpconsole/snmp_alert']['id'] = 'SNMP_alerts'; enterprise_hook('alert_inventory_submenu'); @@ -474,19 +476,19 @@ if ($access_console_node === true) { } } - $sub2['godmode/setup/setup§ion=ehorus']['text'] = __('eHorus'); + $sub2['godmode/setup/setup§ion=ehorus']['text'] = __('Pandora RC'); $sub2['godmode/setup/setup§ion=ehorus']['refr'] = 0; - $sub2['godmode/setup/setup§ion=integria']['text'] = __('Integria IMS'); - $sub2['godmode/setup/setup§ion=integria']['refr'] = 0; + $sub2['godmode/setup/setup§ion=ITSM']['text'] = __('ITSM'); + $sub2['godmode/setup/setup§ion=ITSM']['refr'] = 0; enterprise_hook('module_library_submenu'); $sub2['godmode/setup/setup§ion=notifications']['text'] = __('Notifications'); $sub2['godmode/setup/setup§ion=notifications']['refr'] = 0; - $sub2['godmode/setup/setup§ion=websocket_engine']['text'] = __('Websocket Engine'); - $sub2['godmode/setup/setup§ion=websocket_engine']['refr'] = 0; + $sub2['godmode/setup/setup§ion=quickshell']['text'] = __('QuickShell'); + $sub2['godmode/setup/setup§ion=quickshell']['refr'] = 0; $sub2['godmode/setup/setup§ion=external_tools']['text'] = __('External Tools'); $sub2['godmode/setup/setup§ion=external_tools']['refr'] = 0; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index adb54f89fe..bb06d3a800 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -200,6 +200,16 @@ $text_agent_module = ''; $only_data = false; +if (enterprise_installed() === true) { + $categories_security_hardening = categories_of_cis(); + foreach ($categories_security_hardening as $key => $cat) { + $categories_security_hardening[$key] = implode(' ', $cat); + } +} else { + $categories_security_hardening = []; +} + + // Users. $id_users = []; $users_groups = []; @@ -870,6 +880,16 @@ switch ($action) { $idAgentModule = $module; break; + case 'end_of_life': + $es = json_decode($item['external_source'], true); + + $text_os_version = $es['os_version']; + $end_of_life_date = $es['end_of_life_date']; + $os_selector = $es['os_selector']; + $group = $es['group']; + $recursion = $es['recursion']; + break; + case 'alert_report_actions': $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -1019,6 +1039,51 @@ switch ($action) { $idAgent = $item['id_agent']; break; + case 'top_n_agents_sh': + $group = $item['id_group']; + $recursion = $item['recursion']; + $top_n_value = (empty($item['top_n_value']) === true) ? 10 : $item['top_n_value']; + break; + + case 'top_n_checks_failed': + $group = $item['id_group']; + $recursion = $item['recursion']; + $top_n_value = (empty($item['top_n_value']) === true) ? 10 : $item['top_n_value']; + break; + + case 'top_n_categories_checks': + $group = $item['id_group']; + $recursion = $item['recursion']; + $top_n_value = (empty($item['top_n_value']) === true) ? 10 : $item['top_n_value']; + break; + + case 'vul_by_cat': + $group = $item['id_group']; + $recursion = $item['recursion']; + $cat_selected = $item['cat_security_hardening']; + $ignore_skipped = $item['ignore_skipped']; + break; + + case 'list_checks': + $group = $item['id_group']; + $recursion = $item['recursion']; + $cat_selected = $item['cat_security_hardening']; + $status_of_check = $item['status_of_check']; + $idAgent = $item['id_agent']; + break; + + case 'scoring': + $group = $item['id_group']; + $recursion = $item['recursion']; + $period = $item['period']; + break; + + case 'evolution': + $group = $item['id_group']; + $recursion = $item['recursion']; + $period = $item['period']; + break; + default: // It's not possible. break; @@ -1183,6 +1248,88 @@ $class = 'databox filters'; + + + + + + + + + + + + + + + + + + + + 'end_of_life_date', + 'style' => '', + 'content' => html_print_div( + [ + 'class' => '', + 'content' => html_print_input_text( + 'end_of_life_date', + $end_of_life_date, + '', + 10, + 10, + true + ), + ], + true + ), + ], + true + ); + + echo implode('', $timeInputs); + ?> + + + + + + + + html_print_select( + $servers, + 'combo_server_all', + $server_name, + '', + __('All nodes'), + 'all' + ); + ?> + + + + + - $server) { - $server_ids[$server['id']] = $server['server_name']; - } + $server) { + $server_ids[$server['id']] = $server['server_name']; + } - html_print_select( - $server_ids, - 'server_multiple[]', - $server_multiple, - '', - '', - 0, - false, - true - ); - ?> + html_print_select( + $server_ids, + 'server_multiple[]', + $server_multiple, + '', + '', + 0, + false, + true + ); + ?> + } + ?> @@ -1763,33 +1932,8 @@ $class = 'databox filters'; $a) { - if ($index == 0) { - $sql_log .= ' AND (id_agente = '.$key; - } else { - $sql_log .= ' OR id_agente = '.$key; - } - - $index++; - } - - $sql_log .= ')'; - } - - html_print_select_from_sql( - $sql_log, + html_print_select( + [], 'source', $source, 'onselect=source_change_agents();', @@ -1797,7 +1941,7 @@ $class = 'databox filters'; '', false, false, - false + false, ); ?> @@ -3735,6 +3879,64 @@ $class = 'databox filters'; ?> + + + + + + + + + + + + + + + + + + + + + + + + + + __('All'), + 'PASS' => __('Passed'), + 'FAIL' => __('Failed'), + 'INVALID' => __('Skipped'), + ], + 'status_of_check', + $status_of_check, + ); + ?> + + + @@ -4147,6 +4349,8 @@ html_print_action_buttons($actionButtons, ['type' => 'form_action']); echo '
'; echo ''; +ui_require_css_file('datepicker'); +ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/'); ui_include_time_picker(); ui_require_javascript_file('pandora'); @@ -5063,6 +5267,10 @@ echo "
".__('Please select a group.').'

'; echo '
'; +echo "'; + ui_require_javascript_file( 'pandora_inventory', ENTERPRISE_DIR.'/include/javascript/' @@ -5077,6 +5285,8 @@ $(document).ready (function () { chooseType(); chooseSQLquery(); + $("#text-end_of_life_date").datepicker({dateFormat: "", showButtonPanel: true}); + $("#id_agents").change(agent_changed_by_multiple_agents); // Load selected modules by default @@ -5396,7 +5606,7 @@ $(document).ready (function () { return false; } break; - case 'permissions_report': + case 'permissions_report': if ($("#checkbox-select_by_group").prop("checked") && $("select#users_groups>option:selected").val() == undefined) { dialog_message('#message_no_group'); return false; @@ -5406,6 +5616,30 @@ $(document).ready (function () { return false; } break; + case 'list_checks': + if ($("#text-agent").val() == '') { + dialog_message('#message_no_agent'); + return false; + } + break; + case 'top_n_agents_sh': + if ($("#text-max_items").val() == '') { + dialog_message('#message_no_max_item'); + return false; + } + break; + case 'top_n_checks_failed': + if ($("#text-max_items").val() == '') { + dialog_message('#message_no_max_item'); + return false; + } + break; + case 'top_n_categories_checks': + if ($("#text-max_items").val() == '') { + dialog_message('#message_no_max_item'); + return false; + } + break; default: break; } @@ -5476,13 +5710,14 @@ $(document).ready (function () { }); - $("#submit-edit_item").click(function () { + $("#button-edit_item").click(function () { var type = $('#type').val(); if($('#text-name').val() == ''){ dialog_message('#message_no_name'); return false; } + switch (type){ case 'agent_module': case 'agent_module_status': @@ -5535,6 +5770,30 @@ $(document).ready (function () { return false; } break; + case 'list_checks': + if ($("#text-agent").val() == '') { + dialog_message('#message_no_agent'); + return false; + } + break; + case 'top_n_agents_sh': + if ($("#text-max_items").val() == '') { + dialog_message('#message_no_max_item'); + return false; + } + break; + case 'top_n_checks_failed': + if ($("#text-max_items").val() == '') { + dialog_message('#message_no_max_item'); + return false; + } + break; + case 'top_n_categories_checks': + if ($("#text-max_items").val() == '') { + dialog_message('#message_no_max_item'); + return false; + } + break; default: break; @@ -6341,7 +6600,11 @@ function addGeneralRow() { function loadGeneralAgents(agent_group) { var params = []; - var group = ; + var group = ; + if (group < 0) { + return; + } + group = agent_group || group; params.push("get_agents=1"); @@ -6414,68 +6677,41 @@ function loadGeneralAgents(agent_group) { function loadLogAgents() { var params = []; - params.push("get_log_agents=1"); - params.push("source="); - params.push('id_agents='); - params.push("page=include/ajax/reporting.ajax"); + let source = ''; + let agent = ''; + agent = JSON.parse(agent); - $('#id_agents3') - .find('option') - .remove(); + var params = {}; + params["get_agent_source"] = 1; + params["log_alert"] = 1; + params["page"] = "enterprise/include/ajax/log_viewer.ajax"; - $('#id_agents3') - .append(''); - - jQuery.ajax ({ - data: params.join ("&"), - type: 'POST', - url: action= - - + "/ajax.php", - timeout: 300000, - dataType: 'json', - success: function (data) { - if (data['correct']) { - $('#id_agents3') - .find('option') - .remove(); - - var selectElements = []; - var selectedStr = 'selected="selected"'; - - if (data['select_agents'] === null) { - return; - } - - if (Array.isArray(data['select_agents'])) { - data['select_agents'].forEach(function(agentAlias, agentID) { - var optionAttr = ''; - if (typeof data['agents_selected'][agentID] !== 'undefined') { - optionAttr = ' selected="selected"'; - } - - $('#id_agents3') - .append(''); - }); + jQuery.ajax({ + data: params, + dataType: "json", + type: "POST", + url: "ajax.php", + async: true, + success: function(data) { + $('#id_agents3') + .find('option') + .remove(); + $.each(data['source'],function(key,value) { + if (value === source) { + $('#source').append( ``); } else { - for (const [agentID, agentAlias] of Object.entries(data['select_agents'])) { - var optionAttr = ''; - if (typeof data['agents_selected'][agentID] !== 'undefined') { - optionAttr = ' selected="selected"'; - } - - $('#id_agents3') - .append(''); - } + $('#source').append( ``); } - } + }); + + $.each(data['agent'],function(key,value) { + const result = agent.includes(key); + if (result === true) { + $('#id_agents3').append( ``); + } else { + $('#id_agents3').append( ``); + } + }); } }); } @@ -6545,6 +6781,7 @@ function chooseType() { $("#row_alert_actions").hide(); $("#row_servers").hide(); $("#row_servers_all_opt").hide(); + $("#row_servers_all").hide(); $("#row_multiple_servers").hide(); $("#row_sort").hide(); $("#row_date").hide(); @@ -6607,6 +6844,12 @@ function chooseType() { $("#row_group_by").hide(); $("#row_type_show").hide(); $("#row_use_prefix_notation").hide(); + $("#row_os_selector").hide(); + $("#row_os_version_regexp").hide(); + $("#row_os_end_of_life").hide(); + $("#row_cat_security_hardening").hide(); + $("#row_ignore_skipped").hide(); + $("#row_status_check").hide(); // SLA list default state. $("#sla_list").hide(); @@ -7109,7 +7352,7 @@ function chooseType() { case 'group_report': $("#row_group").show(); - $("#row_servers_all_opt").show(); + $("#row_servers_all").show(); $("#row_description").show(); $("#row_historical_db_check").hide(); break; @@ -7187,6 +7430,13 @@ function chooseType() { }); break; + case 'end_of_life': + $("#row_os_selector").show(); + $("#row_os_version_regexp").show(); + $("#row_group").show(); + $("#row_os_end_of_life").show(); + break; + case 'inventory_changes': $("#row_description").show(); $("#row_period").show(); @@ -7461,7 +7711,44 @@ function chooseType() { case 'ncm': $("#row_agent").show(); break; - + + case 'top_n_agents_sh': + $("#row_group").show(); + $("#row_max_items").show(); + break; + + case 'top_n_checks_failed': + $("#row_group").show(); + $("#row_max_items").show(); + break; + + case 'top_n_categories_checks': + $("#row_group").show(); + $("#row_max_items").show(); + break; + + case 'vul_by_cat': + $("#row_group").show(); + $("#row_cat_security_hardening").show(); + $("#row_ignore_skipped").show(); + break; + + case 'list_checks': + $("#row_group").show(); + $("#row_agent").show(); + $("#row_cat_security_hardening").show(); + $("#row_status_check").show(); + break; + + case 'scoring': + $("#row_group").show(); + $('#row_period').show(); + break; + + case 'evolution': + $("#row_group").show(); + $('#row_period').show(); + break; } switch (type) { @@ -7609,23 +7896,46 @@ function set_last_value_period() { } function source_change_agents() { - $("#id_agents3").empty(); - $("#spinner_hack").show(); - jQuery.post ("ajax.php", - {"page" : "operation/agentes/ver_agente", - "get_agents_source_json" : 1, - "source" : $("#source").val() - }, - function (data, status) { - for (var clave in data) { - $("#id_agents3").append( - '' - ); + const source = $("#source").val(); + if (source === '') { + $("#id_agents3 option[value!=0]").attr("style","display:"); + } else { + $("#spinner_hack").show(); + $("#id_agents3 option").attr("style","display:none"); + + var params = {}; + params["get_agent_source"] = 1; + params["page"] = "enterprise/include/ajax/log_viewer.ajax"; + + jQuery.ajax({ + data: params, + dataType: "json", + type: "POST", + url: "ajax.php", + async: true, + success: function(data) { + let source_array = []; + $.each(data['source'],function(key,value) { + if (value === source) { + const split = key.split('-'); + source_array.push(split[1]); + } + }); + + $.each(data['agent'],function(key,value) { + const result = source_array.includes(key); + if (result === true) { + $(`#id_agents3 option[value*='${key}']`).attr("style","display:"); + } + }); + + $("#spinner_hack").hide(); + }, + error: function(error){ + $("#spinner_hack").hide(); } - $("#spinner_hack").hide(); - }, - "json" - ); + }); + } } function dialog_message(message_id) { diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 2600c9aea2..095f79b14a 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1759,6 +1759,17 @@ switch ($action) { $good_format = true; break; + case 'end_of_life': + $es['end_of_life_date'] = get_parameter('end_of_life_date'); + $es['os_selector'] = get_parameter('os_selector'); + $es['os_version'] = get_parameter('text_os_version', ''); + $es['group'] = get_parameter('combo_group', ''); + $es['recursion'] = get_parameter('recursion', 0); + + $values['external_source'] = json_encode($es); + $good_format = true; + break; + case 'alert_report_actions': $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); @@ -1986,7 +1997,51 @@ switch ($action) { break; case 'group_report': - $values['server_name'] = get_parameter('combo_server'); + $values['server_name'] = get_parameter('combo_server_all'); + $good_format = true; + break; + + case 'top_n_agents_sh': + $values['id_group'] = get_parameter('combo_group'); + $values['top_n_value'] = get_parameter('max_items'); + $good_format = true; + break; + + case 'top_n_checks_failed': + $values['id_group'] = get_parameter('combo_group'); + $values['top_n_value'] = get_parameter('max_items'); + $good_format = true; + break; + + case 'top_n_categories_checks': + $values['id_group'] = get_parameter('combo_group'); + $values['top_n_value'] = get_parameter('max_items'); + $good_format = true; + break; + + case 'vul_by_cat': + $values['id_group'] = get_parameter('combo_group'); + $values['cat_security_hardening'] = get_parameter('cat_security_hardening'); + $values['ignore_skipped'] = get_parameter('ignore_skipped'); + $good_format = true; + break; + + case 'list_checks': + $values['id_group'] = get_parameter('combo_group'); + $values['cat_security_hardening'] = get_parameter('cat_security_hardening'); + $values['status_of_check'] = get_parameter('status_of_check'); + $good_format = true; + break; + + case 'scoring': + $values['id_group'] = get_parameter('combo_group'); + $values['period'] = get_parameter('period'); + $good_format = true; + break; + + case 'evolution': + $values['id_group'] = get_parameter('combo_group'); + $values['period'] = get_parameter('period'); $good_format = true; break; @@ -2019,6 +2074,7 @@ switch ($action) { || ($values['type'] == 'event_report_agent') || ($values['type'] == 'agent_configuration') || ($values['type'] == 'group_configuration') + || ($values['type'] == 'list_checks') ) { $values['id_agent_module'] = ''; } else { @@ -2702,6 +2758,17 @@ switch ($action) { $good_format = true; break; + case 'end_of_life': + $es['end_of_life_date'] = get_parameter('end_of_life_date'); + $es['os_selector'] = get_parameter('os_selector'); + $es['os_version'] = get_parameter('text_os_version', ''); + $es['group'] = get_parameter('combo_group', ''); + $es['recursion'] = get_parameter('recursion', 0); + + $values['external_source'] = json_encode($es); + $good_format = true; + break; + case 'alert_report_actions': $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); @@ -2862,7 +2929,51 @@ switch ($action) { break; case 'group_report': - $values['server_name'] = get_parameter('combo_server'); + $values['server_name'] = get_parameter('combo_server_all'); + $good_format = true; + break; + + case 'top_n_agents_sh': + $values['id_group'] = get_parameter('combo_group'); + $values['top_n_value'] = get_parameter('max_items'); + $good_format = true; + break; + + case 'top_n_checks_failed': + $values['id_group'] = get_parameter('combo_group'); + $values['top_n_value'] = get_parameter('max_items'); + $good_format = true; + break; + + case 'top_n_categories_checks': + $values['id_group'] = get_parameter('combo_group'); + $values['top_n_value'] = get_parameter('max_items'); + $good_format = true; + break; + + case 'vul_by_cat': + $values['id_group'] = get_parameter('combo_group'); + $values['cat_security_hardening'] = get_parameter('cat_security_hardening'); + $values['ignore_skipped'] = get_parameter('ignore_skipped'); + $good_format = true; + break; + + case 'list_checks': + $values['id_group'] = get_parameter('combo_group'); + $values['cat_security_hardening'] = get_parameter('cat_security_hardening'); + $values['status_of_check'] = get_parameter('status_of_check'); + $good_format = true; + break; + + case 'scoring': + $values['id_group'] = get_parameter('combo_group'); + $values['period'] = get_parameter('period'); + $good_format = true; + break; + + case 'evolution': + $values['id_group'] = get_parameter('combo_group'); + $values['period'] = get_parameter('period'); $good_format = true; break; diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index 4b3f26606a..c51c0476d3 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -151,6 +151,10 @@ if (isset($_GET['server']) === true) { $title .= __('Netflow server').' ID: '.$id_server; break; + case SERVER_TYPE_MADE: + $title .= __('MADE server').' ID: '.$id_server; + break; + default: $title = __('Update server').' ID: '.$id_server; break; diff --git a/pandora_console/godmode/setup/gis_step_2.php b/pandora_console/godmode/setup/gis_step_2.php index f2dac0bf20..f2e9182a07 100644 --- a/pandora_console/godmode/setup/gis_step_2.php +++ b/pandora_console/godmode/setup/gis_step_2.php @@ -312,7 +312,7 @@ if ($mapConnectionData != null) { $mapConnectionDataUrl, '', 45, - 90, + false, true ).''; diff --git a/pandora_console/godmode/setup/os.builder.php b/pandora_console/godmode/setup/os.builder.php index afe3982d8c..2d0e54a681 100644 --- a/pandora_console/godmode/setup/os.builder.php +++ b/pandora_console/godmode/setup/os.builder.php @@ -40,6 +40,191 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user return; } +if ($idOS > 0) { + $os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]); + $name = $os['name']; + $description = $os['description']; + $icon = $os['icon_name']; +} else { + $name = io_safe_input(strip_tags(io_safe_output((string) get_parameter('name')))); + $description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description')))); + $icon = get_parameter('icon', 0); +} + +$icon_upload = get_parameter('icon_upload', null); + +$message = ''; +if ($is_management_allowed === true) { + switch ($action) { + case 'edit': + if ($idOS > 0) { + $actionHidden = 'update'; + $textButton = __('Update'); + $classButton = ['icon' => 'wand']; + } else { + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'next']; + } + break; + + case 'save': + if ($icon_upload !== null && $icon_upload['name'] !== '') { + if (isset($_FILES['icon_upload']) === true) { + $file_name = $_FILES['icon_upload']['name']; + $file_tmp = $_FILES['icon_upload']['tmp_name']; + $file_type = $_FILES['icon_upload']['type']; + $file_ext = strtolower(end(explode('.', $_FILES['icon_upload']['name']))); + + $allowed_extensions = [ + 'jpeg', + 'jpg', + 'png', + 'svg', + ]; + + $tab = 'manage_os'; + + if (in_array($file_ext, $allowed_extensions) === false) { + $message = 9; + } else { + $message = 8; + move_uploaded_file($file_tmp, $config['homedir'].'/images/os_icons/'.$file_name); + } + } + } else { + $values = []; + $values['name'] = $name; + $values['description'] = $description; + + if (($icon !== 0) && ($icon != '')) { + $values['icon_name'] = $icon; + } + + $resultOrId = false; + if ($name != '') { + $resultOrId = db_process_sql_insert('tconfig_os', $values); + } + + if ($resultOrId === false) { + $message = 2; + $tab = 'builder'; + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'wand']; + } else { + $tab = 'manage_os'; + $message = 1; + } + } + + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2=list&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + } + break; + + case 'update': + if ($icon_upload !== null && $icon_upload['name'] !== '') { + if (isset($_FILES['icon_upload']) === true) { + $file_name = $_FILES['icon_upload']['name']; + $file_tmp = $_FILES['icon_upload']['tmp_name']; + $file_type = $_FILES['icon_upload']['type']; + $file_ext = strtolower(end(explode('.', $_FILES['icon_upload']['name']))); + + $allowed_extensions = [ + 'jpeg', + 'jpg', + 'png', + 'svg', + ]; + + $tab = 'manage_os'; + + if (in_array($file_ext, $allowed_extensions) === false) { + $message = 9; + } else { + $message = 8; + move_uploaded_file($file_tmp, $config['homedir'].'/images/os_icons/'.$file_name); + } + } + } else { + $name = io_safe_input(strip_tags(io_safe_output((string) get_parameter('name')))); + $description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description')))); + $icon = get_parameter('icon', 0); + + $values = []; + $values['name'] = $name; + $values['description'] = $description; + // Only for Metaconsole. Save the previous name for synchronizing. + if (is_metaconsole() === true) { + $values['previous_name'] = db_get_value('name', 'tconfig_os', 'id_os', $idOS); + } + + if (($icon !== 0) && ($icon != '')) { + $values['icon_name'] = $icon; + } + + $result = false; + if ($name != '') { + $result = db_process_sql_update('tconfig_os', $values, ['id_os' => $idOS]); + } + + if ($result !== false) { + $message = 3; + $tab = 'manage_os'; + } else { + $message = 4; + $tab = 'builder'; + $os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]); + $name = $os['name']; + } + + $actionHidden = 'update'; + $textButton = __('Update'); + $classButton = ['icon' => 'wand']; + } + + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + } + break; + + case 'delete': + $sql = 'SELECT COUNT(id_os) AS count FROM tagente WHERE id_os = '.$idOS; + $count = db_get_all_rows_sql($sql); + $count = $count[0]['count']; + + if ($count > 0) { + $message = 5; + } else { + $result = (bool) db_process_sql_delete('tconfig_os', ['id_os' => $idOS]); + if ($result) { + $message = 6; + } else { + $message = 7; + } + } + + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=list&tab2='.$tab.'&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + } + break; + + default: + case 'new': + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'next']; + break; + } +} + $icons = get_list_os_icons_dir(); $iconData = []; @@ -62,12 +247,11 @@ $iconData[] = html_print_div( true ); -echo '
'; +echo ''; $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filter-table-adv'; -// $table->style[0] = 'width: 15%'; $table->data[0][] = html_print_label_input_block( __('Name'), html_print_input_text('name', $name, __('Name'), 20, 30, true, false, false, '', 'w250px') @@ -89,6 +273,11 @@ $table->data[1][] = html_print_label_input_block( html_print_textarea('description', 5, 20, $description, '', true, 'w250px') ); +$table->data[1][] = html_print_label_input_block( + '', + html_print_input_file('icon_upload', true, ['caption' => __('Upload icon')], 'form_setup') +); + html_print_table($table); html_print_input_hidden('id_os', $idOS); diff --git a/pandora_console/godmode/setup/os.list.php b/pandora_console/godmode/setup/os.list.php index 330071353f..20d1b41561 100644 --- a/pandora_console/godmode/setup/os.list.php +++ b/pandora_console/godmode/setup/os.list.php @@ -45,7 +45,7 @@ if (is_management_allowed() === false) { $is_management_allowed = false; if (is_metaconsole() === false) { $url = ''.__('metaconsole').''; } else { $url = __('any node'); @@ -59,115 +59,71 @@ if (is_management_allowed() === false) { ); } -$table = new stdClass(); -$table->class = 'info_table'; -$table->head[0] = __('ID'); -$table->head[1] = __('Icon'); -$table->head[2] = __('Name'); -$table->head[3] = __('Description'); -if ($is_management_allowed === true) { - $table->head[4] = __('Actions'); -} +// Datatables list. +try { + $columns = [ + 'id_os', + 'icon_img', + 'name', + 'description', + 'options', + ]; -if ($is_management_allowed === true) { - $table->align[4] = 'center'; -} + $column_names = [ + [ + 'text' => __('ID'), + 'class' => 'w50px table_action_buttons', + ], + [ + 'text' => __('Icon'), + 'class' => 'w10px table_action_buttons', + ], + __('Name'), + __('Description'), + [ + 'text' => __('Options'), + 'class' => 'w20px table_action_buttons', + ], + ]; -$table->size[0] = '5%'; -if ($is_management_allowed === true) { - $table->size[4] = '20px'; -} - -// Prepare pagination. -$offset = (int) get_parameter('offset'); -$limit = $config['block_size']; -$count_osList = db_get_value('count(*)', 'tconfig_os'); - -$osList = db_get_all_rows_filter( - 'tconfig_os', - [ - 'offset' => $offset, - 'limit' => $limit, - ] -); - -if ($osList === false) { - $osList = []; -} - -$table->data = []; -foreach ($osList as $os) { - $data = []; - $data[] = $os['id_os']; - $data[] = ui_print_os_icon($os['id_os'], false, true); - if ($is_management_allowed === true) { - if (is_metaconsole() === true) { - $osNameUrl = 'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&action=edit&tab2=builder&id_os='.$os['id_os']; - } else { - $osNameUrl = 'index.php?sec=gsetup&sec2=godmode/setup/os&action=edit&tab=builder&id_os='.$os['id_os']; - } - - $data[] = html_print_anchor( - [ - 'href' => $osNameUrl, - 'content' => io_safe_output($os['name']), + $tableId = 'os_table'; + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $tableId, + 'class' => 'info_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => 'include/ajax/os', + 'ajax_data' => ['method' => 'drawOSTable'], + 'ajax_postprocess' => 'process_datatables_item(item)', + 'no_sortable_columns' => [ + -1, + 1, ], - true - ); - } else { - $data[] = io_safe_output($os['name']); - } - - $data[] = ui_print_truncate_text(io_safe_output($os['description']), 'description', true, true); - - if ($is_management_allowed === true) { - $table->cellclass[][4] = 'table_action_buttons'; - if ($os['id_os'] > 16) { - if (is_metaconsole() === true) { - $hrefDelete = 'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&action=delete&tab2=list&id_os='.$os['id_os']; - } else { - $hrefDelete = 'index.php?sec=gsetup&sec2=godmode/setup/os&action=delete&tab=list&id_os='.$os['id_os']; - } - - $data[] = html_print_anchor( - [ - 'href' => $hrefDelete, - 'content' => html_print_image( - 'images/delete.svg', - true, - [ - 'alt' => __('Delete'), - 'title' => __('Delete'), - 'class' => 'main_menu_icon invert_filter', - ] - ), + 'order' => [ + 'field' => 'id', + 'direction' => 'asc', + ], + 'search_button_class' => 'sub filter float-right', + 'form' => [ + 'inputs' => [ + [ + 'label' => __('Free search'), + 'type' => 'text', + 'class' => 'w25p', + 'id' => 'free_search', + 'name' => 'free_search', + ], ], - true - ); - } else { - // The original icons of pandora don't delete. - $data[] = ''; - } - } - - $table->data[] = $data; -} - -$tablePagination = ''; -if (isset($data) === true) { - html_print_table($table); - $tablePagination = ui_pagination( - $count_osList, - ui_get_url_refresh(['message' => false]), - $offset, - 0, - true, - 'offset', - false, - '' + ], + 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', + 'dom_elements' => 'lftpB', + ] ); -} else { - ui_print_info_message(['no_close' => true, 'message' => __('There are no defined operating systems') ]); +} catch (Exception $e) { + echo $e->getMessage(); } $buttons = ''; @@ -191,3 +147,76 @@ html_print_action_buttons( 'right_content' => $tablePagination, ] ); + +echo ''; + +echo ''; + +html_print_action_buttons( + html_print_submit_button(__('Create OS'), 'update_button', false, ['icon' => 'next'], true), + ['type' => 'form_action'] +); + +echo '
'; + +?> + diff --git a/pandora_console/godmode/setup/os.php b/pandora_console/godmode/setup/os.php index 539189f88d..99402ff30a 100644 --- a/pandora_console/godmode/setup/os.php +++ b/pandora_console/godmode/setup/os.php @@ -40,24 +40,13 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user return; } -$action = get_parameter('action', 'new'); +$action = get_parameter('action', ''); $idOS = get_parameter('id_os', 0); $id_message = get_parameter('message', 0); if (is_metaconsole() === true) { $tab = get_parameter('tab2', 'list'); } else { - $tab = get_parameter('tab', 'list'); -} - -if ($idOS) { - $os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]); - $name = $os['name']; - $description = $os['description']; - $icon = $os['icon_name']; -} else { - $name = io_safe_input(strip_tags(io_safe_output((string) get_parameter('name')))); - $description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description')))); - $icon = get_parameter('icon', 0); + $tab = get_parameter('tab', 'manage_os'); } $is_management_allowed = true; @@ -65,150 +54,60 @@ if (is_management_allowed() === false) { $is_management_allowed = false; } -$message = ''; -if ($is_management_allowed === true) { - switch ($action) { - case 'edit': - $actionHidden = 'update'; - $textButton = __('Update'); - $classButton = ['icon' => 'wand']; - break; - - case 'save': - $values = []; - $values['name'] = $name; - $values['description'] = $description; - - if (($icon !== 0) && ($icon != '')) { - $values['icon_name'] = $icon; - } - - $resultOrId = false; - if ($name != '') { - $resultOrId = db_process_sql_insert('tconfig_os', $values); - } - - if ($resultOrId === false) { - $message = 2; - $tab = 'builder'; - $actionHidden = 'save'; - $textButton = __('Create'); - $classButton = ['icon' => 'wand']; - } else { - $tab = 'list'; - $message = 1; - } - - if (is_metaconsole() === true) { - header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); - } else { - header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); - } - break; - - case 'update': - $name = io_safe_input(strip_tags(io_safe_output((string) get_parameter('name')))); - $description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description')))); - $icon = get_parameter('icon', 0); - - $values = []; - $values['name'] = $name; - $values['description'] = $description; - // Only for Metaconsole. Save the previous name for synchronizing. - if (is_metaconsole() === true) { - $values['previous_name'] = db_get_value('name', 'tconfig_os', 'id_os', $idOS); - } - - if (($icon !== 0) && ($icon != '')) { - $values['icon_name'] = $icon; - } - - $result = false; - if ($name != '') { - $result = db_process_sql_update('tconfig_os', $values, ['id_os' => $idOS]); - } - - if ($result !== false) { - $message = 3; - $tab = 'list'; - } else { - $message = 4; - $tab = 'builder'; - $os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]); - $name = $os['name']; - } - - $actionHidden = 'update'; - $textButton = __('Update'); - $classButton = ['icon' => 'wand']; - if (is_metaconsole() === true) { - header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); - } else { - header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); - } - break; - - case 'delete': - $sql = 'SELECT COUNT(id_os) AS count FROM tagente WHERE id_os = '.$idOS; - $count = db_get_all_rows_sql($sql); - $count = $count[0]['count']; - - if ($count > 0) { - $message = 5; - } else { - $result = (bool) db_process_sql_delete('tconfig_os', ['id_os' => $idOS]); - if ($result) { - $message = 6; - } else { - $message = 7; - } - } - - if (is_metaconsole() === true) { - header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); - } else { - header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); - } - break; - - default: - case 'new': - $actionHidden = 'save'; - $textButton = __('Create'); - $classButton = ['icon' => 'next']; - break; - } -} - $buttons = []; -$buttons['list'] = [ + +$buttons['manage_os'] = [ 'active' => false, - 'text' => ''.html_print_image( - 'images/logs@svg.svg', + 'text' => ''.html_print_image( + 'images/os@svg.svg', true, [ - 'title' => __('List OS'), + 'title' => __('Manage OS types'), + 'class' => 'invert_filter main_menu_icon', + ] + ).'', +]; + +$buttons['manage_version'] = [ + 'active' => false, + 'text' => ''.html_print_image( + 'images/os_version@svg.svg', + true, + [ + 'title' => __('Manage version expiration dates'), 'class' => 'invert_filter main_menu_icon', ] ).'', ]; -if ($is_management_allowed === true) { - $buttons['builder'] = [ - 'active' => false, - 'text' => ''.html_print_image( - 'images/edit.svg', - true, - [ - 'title' => __('Builder OS'), - 'class' => 'invert_filter main_menu_icon', - ] - ).'', - ]; -} $buttons[$tab]['active'] = true; -$headerTitle = ($tab === 'builder') ? __('Edit OS') : __('List of Operating Systems'); +switch ($tab) { + case 'builder': + $headerTitle = __('Edit OS'); + break; + + case 'manage_os': + case 'list': + if ($action === 'edit') { + $headerTitle = __('Edit OS'); + } else { + $headerTitle = __('List of Operating Systems'); + } + break; + + case 'manage_version': + if ($action === 'edit') { + $headerTitle = __('Edit OS version expiration date'); + } else { + $headerTitle = __('List of version expiration dates'); + } + break; + + default: + // Default. + break; +} if (is_metaconsole() === false) { // Header. @@ -262,6 +161,14 @@ if (empty($id_message) === false) { echo ui_print_error_message(__('Error deleting'), '', true); break; + case 8: + echo ui_print_success_message(__('Icon successfuly uploaded'), '', true); + break; + + case 9: + echo ui_print_error_message(__('File must be of type JPG, JPEG, PNG or SVG'), '', true); + break; + default: // Default. break; @@ -269,12 +176,21 @@ if (empty($id_message) === false) { } switch ($tab) { + case 'manage_os': case 'list': - include_once $config['homedir'].'/godmode/setup/os.list.php'; + if (in_array($action, ['edit', 'save', 'update']) && is_management_allowed() === true) { + include_once $config['homedir'].'/godmode/setup/os.builder.php'; + } else { + include_once $config['homedir'].'/godmode/setup/os.list.php'; + } break; - case 'builder': - include_once $config['homedir'].'/godmode/setup/os.builder.php'; + case 'manage_version': + if (in_array($action, ['edit', 'save', 'update']) && is_management_allowed() === true) { + include_once $config['homedir'].'/godmode/setup/os_version.builder.php'; + } else { + include_once $config['homedir'].'/godmode/setup/os_version.list.php'; + } break; default: diff --git a/pandora_console/godmode/setup/os_version.builder.php b/pandora_console/godmode/setup/os_version.builder.php new file mode 100644 index 0000000000..8c73b4b453 --- /dev/null +++ b/pandora_console/godmode/setup/os_version.builder.php @@ -0,0 +1,211 @@ + 0) { + $os_version = db_get_row_filter('tconfig_os_version', ['id_os_version' => $idOS]); + $product = $os_version['product']; + $version = $os_version['version']; + $end_of_life_date = $os_version['end_of_support']; +} else { + $product = io_safe_input(strip_tags(io_safe_output((string) get_parameter('product')))); + $version = io_safe_input(strip_tags(io_safe_output((string) get_parameter('version')))); + $end_of_life_date = get_parameter('end_of_life_date', date('Y/m/d')); +} + +$message = ''; +if ($is_management_allowed === true) { + switch ($action) { + case 'edit': + if ($idOS > 0) { + $actionHidden = 'update'; + $textButton = __('Update'); + $classButton = ['icon' => 'wand']; + } else { + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'next']; + } + break; + + case 'save': + $values = []; + // Product and version must be stored with no entities to be able to use REGEXP in queries. + // CAREFUL! output of these fields must be encoded to avoid scripting vulnerabilities. + $values['product'] = io_safe_output($product); + $values['version'] = io_safe_output($version); + $values['end_of_support'] = $end_of_life_date; + + $result = db_process_sql_insert('tconfig_os_version', $values); + + if ($result === false) { + $message = 2; + } else { + $message = 1; + } + + $tab = 'manage_version'; + + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + break; + + case 'update': + $product = io_safe_output(get_parameter('product')); + $version = io_safe_output(get_parameter('version')); + $end_of_life_date = get_parameter('end_of_life_date', 0); + $values = []; + $values['product'] = $product; + $values['version'] = $version; + $values['end_of_support'] = $end_of_life_date; + $result = db_process_sql_update('tconfig_os_version', $values, ['id_os_version' => $idOS]); + + if ($result === false) { + $message = 4; + } else { + $message = 3; + } + + $tab = 'manage_version'; + + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + break; + + case 'delete': + $sql = 'SELECT COUNT(id_os) AS count FROM tagente WHERE id_os = '.$idOS; + $count = db_get_all_rows_sql($sql); + $count = $count[0]['count']; + + if ($count > 0) { + $message = 5; + } else { + $result = (bool) db_process_sql_delete('tconfig_os', ['id_os' => $idOS]); + if ($result) { + $message = 6; + } else { + $message = 7; + } + } + + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=list&tab2='.$tab.'&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + } + break; + + default: + case 'new': + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'next']; + break; + } +} + +echo '
'; +$table = new stdClass(); +$table->width = '100%'; +$table->class = 'databox filter-table-adv'; + +// $table->style[0] = 'width: 15%'; +$table->data[0][] = html_print_label_input_block( + __('Product'), + html_print_input_text('product', io_safe_input($product), __('Product'), 20, 300, true, false, false, '', 'w250px') +); + +$table->data[0][] = html_print_label_input_block( + __('Version'), + html_print_input_text('version', io_safe_input($version), __('Version'), 20, 300, true, false, false, '', 'w250px') +); + +$timeInputs = []; + +$timeInputs[] = html_print_div( + [ + 'id' => 'end_of_life_date', + 'style' => '', + 'content' => html_print_div( + [ + 'class' => '', + 'content' => html_print_input_text( + 'end_of_life_date', + $end_of_life_date, + '', + 10, + 10, + true + ), + ], + true + ), + ], + true +); + +$table->data[1][] = html_print_label_input_block( + __('End of life date'), + implode('', $timeInputs) +); + +html_print_table($table); + +html_print_input_hidden('id_os', $idOS); +html_print_input_hidden('action', $actionHidden); + +html_print_action_buttons( + html_print_submit_button($textButton, 'update_button', false, $classButton, true), + ['type' => 'form_action'] +); + +echo '
'; + +?> + \ No newline at end of file diff --git a/pandora_console/godmode/setup/os_version.list.php b/pandora_console/godmode/setup/os_version.list.php new file mode 100644 index 0000000000..3e15725793 --- /dev/null +++ b/pandora_console/godmode/setup/os_version.list.php @@ -0,0 +1,198 @@ + __('Options'), + 'class' => 'w100px table_action_buttons', + ], + ]; + + $tableId = 'os_version_table'; + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $tableId, + 'class' => 'info_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => 'include/ajax/os', + 'ajax_data' => ['method' => 'drawOSVersionTable'], + 'ajax_postprocess' => 'process_datatables_item(item)', + 'no_sortable_columns' => [-1], + 'order' => [ + 'field' => 'id', + 'direction' => 'asc', + ], + 'search_button_class' => 'sub filter float-right', + 'form' => [ + 'inputs' => [ + [ + 'label' => __('Free search'), + 'type' => 'text', + 'class' => 'w25p', + 'id' => 'free_search', + 'name' => 'free_search', + ], + ], + ], + 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', + 'dom_elements' => 'lftpB', + ] + ); +} catch (Exception $e) { + echo $e->getMessage(); +} + +echo ''; + +echo '
'; + +html_print_action_buttons( + html_print_submit_button(__('Create OS version'), 'update_button', false, ['icon' => 'next'], true), + ['type' => 'form_action'] +); + +echo '
'; + +echo '
'; +html_print_input_hidden('os_type_regex', ''); +html_print_input_hidden('os_version_regex', ''); + +echo '
'; + +?> + + \ No newline at end of file diff --git a/pandora_console/godmode/setup/os_version.php b/pandora_console/godmode/setup/os_version.php new file mode 100644 index 0000000000..8c9816cc7f --- /dev/null +++ b/pandora_console/godmode/setup/os_version.php @@ -0,0 +1,285 @@ + $id_os_version]); + $product = $os_version['product']; + $version = $os_version['version']; + $end_of_life_date = $os_version['end_of_life_date']; +} else { + $product = io_safe_input(strip_tags(io_safe_output((string) get_parameter('product')))); + $version = io_safe_input(strip_tags(io_safe_output((string) get_parameter('version')))); + $end_of_life_date = get_parameter('end_of_life_date', 0); +} + +$is_management_allowed = true; +if (is_management_allowed() === false) { + $is_management_allowed = false; +} + +$message = ''; +if ($is_management_allowed === true) { + switch ($action) { + case 'edit': + $action_hidden = 'update'; + $text_button = __('Update'); + $class_button = ['icon' => 'wand']; + break; + + case 'save': + $values = []; + $values['product'] = $product; + $values['version'] = $version; + $values['end_of_life_date'] = $end_of_life_date; + + $result_or_id = false; + if ($product !== '') { + $result_or_id = db_process_sql_insert('tconfig_os_version', $values); + } + + if ($result_or_id === false) { + $message = 2; + $tab = 'builder'; + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'wand']; + } else { + $tab = 'list'; + $message = 1; + } + + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + } + break; + + case 'update': + $product = io_safe_input(strip_tags(io_safe_output((string) get_parameter('product')))); + $version = io_safe_input(strip_tags(io_safe_output((string) get_parameter('version')))); + $end_of_life_date = get_parameter('end_of_life_date', 0); + + $values = []; + $values['product'] = $product; + $values['version'] = $version; + + $result = false; + $result = db_process_sql_update('tconfig_os_version', $values, ['id_os' => $id_os_version]); + + if ($result !== false) { + $message = 3; + $tab = 'list'; + } else { + $message = 4; + $tab = 'builder'; + $os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]); + $name = $os['name']; + } + + $actionHidden = 'update'; + $textButton = __('Update'); + $classButton = ['icon' => 'wand']; + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os_version&tab='.$tab.'&message='.$message); + } + break; + + case 'delete': + $sql = 'SELECT COUNT(id_os) AS count FROM tagente WHERE id_os = '.$idOS; + $count = db_get_all_rows_sql($sql); + $count = $count[0]['count']; + + if ($count > 0) { + $message = 5; + } else { + $result = (bool) db_process_sql_delete('tconfig_os', ['id_os' => $idOS]); + if ($result) { + $message = 6; + } else { + $message = 7; + } + } + + if (is_metaconsole() === true) { + header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message); + } else { + header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message); + } + break; + + default: + case 'new': + $actionHidden = 'save'; + $textButton = __('Create'); + $classButton = ['icon' => 'next']; + break; + } +} + +$buttons = []; +$buttons['list'] = [ + 'active' => false, + 'text' => ''.html_print_image( + 'images/logs@svg.svg', + true, + [ + 'title' => __('List OS'), + 'class' => 'invert_filter main_menu_icon', + ] + ).'', +]; +if ($is_management_allowed === true) { + $buttons['builder'] = [ + 'active' => false, + 'text' => ''.html_print_image( + 'images/edit.svg', + true, + [ + 'title' => __('Builder OS'), + 'class' => 'invert_filter main_menu_icon', + ] + ).'', + ]; + + $buttons['version_exp_date_editor'] = [ + 'active' => false, + 'text' => ''.html_print_image( + 'images/edit.svg', + true, + [ + 'title' => __('Version expiration date editor'), + 'class' => 'invert_filter main_menu_icon', + ] + ).'', + ]; +} + +$buttons[$tab]['active'] = true; + +switch ($tab) { + case 'builder': + $headerTitle = __('Edit OS'); + break; + + case 'manage_version': + $headerTitle = __('Version expiration date editor'); + break; + + case 'list': + $headerTitle = __('List of Operating Systems'); + break; + + default: + // Default. + break; +} + +if (is_metaconsole() === false) { + // Header. + ui_print_standard_header( + $headerTitle, + '', + false, + '', + true, + $buttons, + [ + [ + 'link' => '', + 'label' => __('Servers'), + ], + [ + 'link' => '', + 'label' => __('Edit OS'), + ], + ] + ); +} + +if (empty($id_message) === false) { + switch ($id_message) { + case 1: + echo ui_print_success_message(__('Success creating OS'), '', true); + break; + + case 2: + echo ui_print_error_message(__('Fail creating OS'), '', true); + break; + + case 3: + echo ui_print_success_message(__('Success updating OS'), '', true); + break; + + case 4: + echo ui_print_error_message(__('Error updating OS'), '', true); + break; + + case 5: + echo ui_print_error_message(__('There are agents with this OS.'), '', true); + break; + + case 6: + echo ui_print_success_message(__('Success deleting'), '', true); + break; + + case 7: + echo ui_print_error_message(__('Error deleting'), '', true); + break; + + default: + // Default. + break; + } +} + +require_once $config['homedir'].'/godmode/setup/os_version.list.php'; diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 7e17f9fe4c..0fd6bebff8 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -170,13 +170,13 @@ if (check_acl($config['id_user'], 0, 'AW')) { } } -$buttons['integria'] = [ +$buttons['ITSM'] = [ 'active' => false, - 'text' => ''.html_print_image( - 'images/integria.png', + 'text' => ''.html_print_image( + 'images/itsm.png', true, [ - 'title' => __('Integria IMS'), + 'title' => __('ITSM'), 'class' => 'invert_filter', ] ).'', @@ -185,10 +185,10 @@ $buttons['integria'] = [ $buttons['ehorus'] = [ 'active' => false, 'text' => ''.html_print_image( - 'images/ehorus/ehorus.png', + 'images/RC.png', true, [ - 'title' => __('eHorus'), + 'title' => __('Pandora RC'), 'class' => 'invert_filter', ] ).'', @@ -221,13 +221,13 @@ $buttons['notifications'] = [ ).'', ]; -$buttons['websocket_engine'] = [ +$buttons['quickshell'] = [ 'active' => false, - 'text' => ''.html_print_image( + 'text' => ''.html_print_image( 'images/websocket_small.png', true, [ - 'title' => __('Websocket engine'), + 'title' => __('QuickShell'), 'class' => 'invert_filter', ] ).'', @@ -299,14 +299,14 @@ switch ($section) { case 'ehorus': $buttons['ehorus']['active'] = true; - $subpage = __('eHorus'); + $subpage = __('Pandora RC'); $help_header = 'setup_ehorus_tab'; break; - case 'integria': - $buttons['integria']['active'] = true; - $subpage = __('Integria IMS'); - $help_header = 'setup_integria_tab'; + case 'ITSM': + $buttons['ITSM']['active'] = true; + $subpage = __('Pandora ITSM'); + $help_header = 'setup_ITSM_tab'; break; case 'module_library': @@ -325,9 +325,9 @@ switch ($section) { $subpage = __('Notifications'); break; - case 'websocket_engine': - $buttons['websocket_engine']['active'] = true; - $subpage = __('Pandora Websocket Engine'); + case 'quickshell': + $buttons['quickshell']['active'] = true; + $subpage = __('QuickShell'); $help_header = 'quickshell_settings'; break; @@ -442,8 +442,8 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_ehorus.php'; break; - case 'integria': - include_once $config['homedir'].'/godmode/setup/setup_integria.php'; + case 'ITSM': + include_once $config['homedir'].'/godmode/setup/setup_ITSM.php'; break; case 'gis': @@ -454,8 +454,8 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_notifications.php'; break; - case 'websocket_engine': - include_once $config['homedir'].'/godmode/setup/setup_websocket_engine.php'; + case 'quickshell': + include_once $config['homedir'].'/godmode/setup/setup_quickshell.php'; break; case 'external_tools': diff --git a/pandora_console/godmode/setup/setup_ITSM.php b/pandora_console/godmode/setup/setup_ITSM.php new file mode 100644 index 0000000000..3196ef677c --- /dev/null +++ b/pandora_console/godmode/setup/setup_ITSM.php @@ -0,0 +1,716 @@ +ping(); + $group_values = $ITSM->getGroups(); + $priority_values = $ITSM->getPriorities(); + $status_values = $ITSM->getStatus(); + $object_types_values = $ITSM->getObjectypes(); + if ((bool) get_parameter('update_config', 0) === true) { + $set_config_inventories = $ITSM->createNode( + [ + 'serverAuth' => $config['server_unique_identifier'], + 'apiPass' => $config['api_password'], + 'agentsForExecution' => $config['ITSM_agents_sync'], + 'path' => $config['ITSM_public_url'], + 'label' => array_keys(servers_get_names())[0], + 'nodeId' => $config['metaconsole_node_id'], + ] + ); + } + + try { + $node = $ITSM->getNode($config['server_unique_identifier']); + } catch (\Throwable $th) { + $node = []; + } +} catch (\Throwable $th) { + $error = $th->getMessage(); + $has_connection = false; +} + +if ($has_connection === false && $config['ITSM_enabled']) { + ui_print_error_message(__('ITSM API is not reachable, %s', $error)); +} + +$table_enable = new StdClass(); +$table_enable->data = []; +$table_enable->width = '100%'; +$table_enable->id = 'itsm-enable-setup'; +$table_enable->class = 'databox filters'; +$table_enable->size['name'] = '30%'; +$table_enable->style['name'] = 'font-weight: bold'; + +// Enable Pandora ITSM. +$row = []; +$row['name'] = __('Enable Pandora ITSM'); +$row['control'] = html_print_checkbox_switch('ITSM_enabled', 1, $config['ITSM_enabled'], true); +$table_enable->data['ITSM_enabled'] = $row; + +// Remote config table. +$table_remote = new StdClass(); +$table_remote->data = []; +$table_remote->width = '100%'; +$table_remote->styleTable = 'margin-bottom: 10px;'; +$table_remote->id = 'ITSM-remote-setup'; +$table_remote->class = 'databox filters filter-table-adv'; +$table_remote->size['hostname'] = '50%'; +$table_remote->size['api_pass'] = '50%'; + +// Enable ITSM user configuration. +$row = []; +$row['user_level'] = html_print_label_input_block( + __('Pandora ITSM configuration at user level'), + html_print_checkbox_switch( + 'ITSM_user_level_conf', + 1, + $config['ITSM_user_level_conf'], + true + ) +); +$table_remote->data['ITSM_user_level_conf'] = $row; + +// ITSM hostname. +$row = []; +$row['hostname'] = html_print_label_input_block( + __('URL to Pandora ITSM setup').ui_print_help_tip( + __('Full URL to your Pandora ITSM setup (e.g., http://192.168.1.20/integria/api/v1).'), + true + ), + html_print_input_text( + 'ITSM_hostname', + $config['ITSM_hostname'], + '', + 30, + 100, + true + ), + ['div_class' => 'ITSM-remote-setup-ITSM_hostname'] +); + +// ITSM token. +$row['password'] = html_print_label_input_block( + __('Token'), + html_print_input_password( + 'ITSM_token', + io_output_password($config['ITSM_token']), + '', + 30, + 100, + true + ), + ['div_class' => 'ITSM-remote-setup-ITSM_token'] +); +$table_remote->data['ITSM_token'] = $row; + +// Test. +$row = []; +$button_test = html_print_button( + __('Test'), + 'ITSM', + false, + '', + [ + 'icon' => 'cog', + 'mode' => 'secondary mini', + ], + true +); +$button_test .= ''; +$button_test .= ''; +$button_test .= ''; +$button_test .= ' '; + +$row['control'] = html_print_label_input_block( + __('Test connection pandora to ITSM'), + $button_test +); +$table_remote->data['ITSM_test'] = $row; + +$row = []; +$itsm_public_url = $config['ITSM_public_url']; +if (empty($itsm_public_url) === true) { + $itsm_public_url = $config['homeurl']; + if (isset($config['public_url']) === true && empty($config['public_url']) === false) { + $itsm_public_url = $config['public_url']; + } +} + +$row['publicUrl'] = html_print_label_input_block( + __('URL conect to API %s', get_product_name()).ui_print_help_tip( + __('Full URL to your Pandora (e.g., http://192.168.1.20).'), + true + ), + html_print_input_text( + 'ITSM_public_url', + $itsm_public_url, + '', + 30, + 100, + true + ) +); + +$row['agentsSync'] = html_print_label_input_block( + __('Number Agents to synchronize').ui_print_help_tip( + __('Number of agents that will synchronize at the same time, minimum 10 max 1000'), + true + ), + html_print_input_number( + [ + 'name' => 'ITSM_agents_sync', + 'min' => 10, + 'max' => 1000, + 'value' => ($config['ITSM_agents_sync'] ?? 20), + ] + ) +); + +$table_remote->data['ITSM_sync_inventory'] = $row; + +// Test. +$row = []; +$button_test_pandora = html_print_button( + __('Test'), + 'ITSM-pandora', + false, + '', + [ + 'icon' => 'cog', + 'mode' => 'secondary mini', + ], + true +); +$button_test_pandora .= ''; +$button_test_pandora .= ''; +$button_test_pandora .= ''; +$button_test_pandora .= ' '; + +$row['control-test'] = html_print_label_input_block( + __('Test conection ITSM to pandora'), + $button_test_pandora +); + +if (empty($node) === false) { + $progressbar = ''; + + $progress = 0; + if (empty($node['total']) === false) { + if (empty($node['accumulate']) === true) { + $node['accumulate'] = 0; + } + + $progress = round(($node['accumulate'] * 100 / $node['total'])); + } + + if (empty($node['error']) === false) { + $progressbar = $node['error']; + } else if (empty($node['total']) === false) { + $progressbar = '
'; + $progressbar .= ui_progress($progress, '150px', '1.3', '#14524f', true, '', false, 'margin-right:5px; color:#c0ccdc'); + $progressbar .= ' ( '.$node['accumulate'].' / '.$node['total'].' ) '.__('Agents'); + $progressbar .= '
'; + } else { + $progressbar = '--'; + } + + // $progressbar .= (empty($node['dateStart']) === false) ? human_time_comparation($node['dateStart']) : __('Never'); + $row['control-test-pandora'] = html_print_label_input_block( + __('Progress agents to synch'), + $progressbar + ); +} + +$table_remote->data['ITSM_test_pandora'] = $row; + +// Alert settings. +$table_alert_settings = new StdClass(); +$table_alert_settings->data = []; +$table_alert_settings->rowspan = []; +$table_alert_settings->width = '100%'; +$table_alert_settings->styleTable = 'margin-bottom: 10px;'; +$table_alert_settings->id = 'ITSM-settings-setup'; +$table_alert_settings->class = 'databox filters filter-table-adv'; +$table_alert_settings->size[0] = '50%'; +$table_alert_settings->size[1] = '50%'; + +// Alert incident title. +$table_alert_settings->data[0][0] = html_print_label_input_block( + __('Title'), + html_print_input_text( + 'incident_title', + $config['incident_title'], + __('Name'), + 50, + 100, + true, + false, + false + ) +); + +// Alert incident description. +$table_alert_settings->rowspan[0][1] = 3; +$table_alert_settings->data[0][1] = html_print_label_input_block( + __('Ticket body'), + html_print_textarea( + 'incident_content', + 9, + 25, + $config['incident_content'], + '', + true + ) +); + +// Alert default group. +$table_alert_settings->data[1][0] = html_print_label_input_block( + __('Group'), + html_print_select( + $group_values, + 'default_group', + $config['default_group'], + '', + '', + 0, + true, + false, + true, + '', + false + ) +); + +// Alert default owner. +$table_alert_settings->data[2][0] = html_print_label_input_block( + __('Owner'), + html_print_autocomplete_users_from_pandora_itsm( + 'default_owner', + $config['default_owner'], + true, + '30', + false, + false, + 'w100p' + ), + ['div_class' => 'inline'] +); + +// Alert default incident status. +$table_alert_settings->data[3][0] = html_print_label_input_block( + __('Status'), + html_print_select( + $status_values, + 'incident_status', + $config['incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Alert default criticity. +$table_alert_settings->data[3][1] = html_print_label_input_block( + __('Priority'), + html_print_select( + $priority_values, + 'default_criticity', + $config['default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Alert default incident type. +$table_alert_settings->data[4][0] = html_print_label_input_block( + __('Type'), + html_print_select( + $object_types_values, + 'incident_type', + $config['incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Custom response settings. +$table_cr_settings = new StdClass(); +$table_cr_settings->data = []; +$table_cr_settings->width = '100%'; +$table_cr_settings->styleTable = 'margin-bottom: 10px;'; +$table_cr_settings->id = 'ITSM-cr-settings-setup'; +$table_cr_settings->class = 'databox filters filter-table-adv'; +$table_cr_settings->size[0] = '50%'; +$table_cr_settings->size[1] = '50%'; + +// Custom response incident title. +$table_cr_settings->data[0][0] = html_print_label_input_block( + __('Title'), + html_print_input_text( + 'cr_incident_title', + $config['cr_incident_title'], + __('Name'), + 50, + 100, + true, + false, + false + ) +); + +// Custom response incident description. +$table_cr_settings->rowspan[0][1] = 3; +$table_cr_settings->data[0][1] = html_print_label_input_block( + __('Ticket body'), + html_print_textarea( + 'cr_incident_content', + 9, + 25, + $config['cr_incident_content'], + '', + true + ) +); + +// Custom response default group. +$table_cr_settings->data[1][0] = html_print_label_input_block( + __('Group'), + html_print_select( + $group_values, + 'cr_default_group', + $config['cr_default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Custom response default owner. +$table_cr_settings->data[2][0] = html_print_label_input_block( + __('Owner'), + html_print_autocomplete_users_from_pandora_itsm( + 'cr_default_owner', + $config['cr_default_owner'], + true, + '30', + false, + false, + 'w100p' + ), + ['div_class' => 'inline'] +); + +// Custom response default incident status. +$row = []; +$table_cr_settings->data[3][0] = html_print_label_input_block( + __('Status'), + html_print_select( + $status_values, + 'cr_incident_status', + $config['cr_incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Custom response default criticity. +$table_cr_settings->data[3][1] = html_print_label_input_block( + __('Priority'), + html_print_select( + $priority_values, + 'cr_default_criticity', + $config['cr_default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Custom response default incident type. +$table_cr_settings->data[4][0] = html_print_label_input_block( + __('Type'), + html_print_select( + $object_types_values, + 'cr_incident_type', + $config['cr_incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false + ) +); + +// Print. +echo ''; + +echo "
"; +html_print_input_hidden('update_config', 1); + +// Form enable. +echo '
'; +html_print_table($table_enable); +echo '
'; + +// Form remote. +echo '
'; +echo '
'; +echo ''.__('Pandora ITSM API settings').''; + +html_print_table($table_remote); + +echo '
'; +echo '
'; + +if ($has_connection !== false) { + // Form alert default settings. + echo '
'; + echo '
'; + echo ''.__('Alert default values').' '.ui_print_help_icon('alert_macros', true).''; + + html_print_table($table_alert_settings); + + echo '
'; + echo '
'; + + // Form custom response default settings. + echo '
'; + echo '
'; + echo ''.__('Event custom response default values').' '.ui_print_help_icon('alert_macros', true).''; + + html_print_table($table_cr_settings); + + echo '
'; + echo '
'; + + $update_button = html_print_submit_button( + __('Update'), + 'update_button', + false, + ['icon' => 'update'], + true + ); +} else { + $update_button = html_print_submit_button( + __('Update and continue'), + 'update_button', + false, + ['icon' => 'update'], + true + ); +} + +html_print_action_buttons($update_button); + +echo '
'; + +ui_require_javascript_file('ITSM'); + +?> + + diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php index 6616cd765c..40a816a6fa 100644 --- a/pandora_console/godmode/setup/setup_auth.php +++ b/pandora_console/godmode/setup/setup_auth.php @@ -371,7 +371,7 @@ if (is_ajax() === true) { case 'pandora': case 'ad': case 'saml': - case 'integria': + case 'ITSM': // Add enterprise authentication options. if (enterprise_installed() === true) { add_enterprise_auth_options($table, $type_auth); diff --git a/pandora_console/godmode/setup/setup_ehorus.php b/pandora_console/godmode/setup/setup_ehorus.php index 9a711c9a39..6f4879a4ac 100644 --- a/pandora_console/godmode/setup/setup_ehorus.php +++ b/pandora_console/godmode/setup/setup_ehorus.php @@ -64,7 +64,7 @@ $table_enable->style['name'] = 'font-weight: bold'; // Enable eHorus. $row = []; -$row['name'] = __('Enable eHorus'); +$row['name'] = __('Enable Pandora RC'); $row['control'] = html_print_checkbox_switch('ehorus_enabled', 1, $config['ehorus_enabled'], true); $table_enable->data['ehorus_enabled'] = $row; @@ -81,7 +81,7 @@ $table_remote->size['ehorus_port'] = '50%'; // Enable eHorus user configuration. $row = []; $row['ehorus_user_level_conf'] = html_print_label_input_block( - __('eHorus configuration at user level'), + __('Pandora RC configuration at user level'), html_print_checkbox_switch( 'ehorus_user_level_conf', 1, @@ -154,16 +154,16 @@ $table_remote->data['ehorus_test'] = $row; // Print. echo ''; if ($custom_field_created !== null) { - ui_print_result_message($custom_field_created, __('Custom field eHorusID created'), __('Error creating custom field')); + ui_print_result_message($custom_field_created, __('Custom field Pandora RC ID created'), __('Error creating custom field')); } if ($custom_field_created) { - $info_messsage = __('eHorus has his own agent identifiers'); + $info_messsage = __('Pandora RC has his own agent identifiers'); $info_messsage .= '. '.__('To store them, it will be necessary to use an agent custom field'); - $info_messsage .= '.
'.__('Possibly the eHorus id will have to be filled in by hand for every agent').'.'; + $info_messsage .= '.
'.__('Possibly the Pandora RC id will have to be filled in by hand for every agent').'.'; ui_print_info_message($info_messsage); } @@ -205,7 +205,7 @@ echo ''; // Form remote. echo '
'; echo '
'; - echo ''.__('eHorus API').''; + echo ''.__('Pandora RC API').''; html_print_input_hidden('update_config', 1); html_print_table($table_remote); diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php deleted file mode 100644 index a01927c017..0000000000 --- a/pandora_console/godmode/setup/setup_integria.php +++ /dev/null @@ -1,997 +0,0 @@ - ($login_result !== false) ? 1 : 0]); - - return; -} - -$has_connection = integria_api_call(null, null, null, null, 'get_login', []); - -if ($has_connection === false && $config['integria_enabled']) { - ui_print_error_message(__('Integria IMS API is not reachable')); -} - -if (get_parameter('update_config', 0) == 1) { - // Try to retrieve event response 'Create incident in IntegriaIMS from event' to check if it exists. - $event_response_exists = db_get_row_filter('tevent_response', ['name' => io_safe_input('Create ticket in IntegriaIMS from event')]); - - // Try to retrieve command 'Integia IMS Ticket' to check if it exists. - $command_exists = db_get_row_filter('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); - - if ($config['integria_enabled'] == 1) { - if ($event_response_exists === false) { - // Create 'Create incident in IntegriaIMS from event' event response only when user enables IntegriaIMS integration and it does not exist in database. - db_process_sql_insert( - 'tevent_response', - [ - 'name' => io_safe_input('Create ticket in IntegriaIMS from event'), - 'description' => io_safe_input('Create a ticket in Integria IMS from an event'), - 'target' => io_safe_input('index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&from_event=_event_id_'), - 'type' => 'url', - 'id_group' => '0', - 'modal_width' => '0', - 'modal_height' => '0', - 'new_window' => '1', - 'params' => '', - 'server_to_exec' => '0', - ] - ); - } - - $ticket_types = integria_api_call(null, null, null, null, 'get_types', '', false, 'json'); - - $types_string = ''; - - if ($ticket_types !== '') { - foreach (json_decode($ticket_types, true) as $key => $value) { - $types_string .= $value['id'].','.$value['name'].';'; - } - } - - if ($command_exists === false) { - // Create 'Integria IMS Ticket' command only when user enables IntegriaIMS integration and it does not exist in database. - $id_command_inserted = db_process_sql_insert( - 'talert_commands', - [ - 'name' => io_safe_input('Integria IMS Ticket'), - 'command' => io_safe_input('Internal type'), - 'internal' => 1, - 'description' => io_safe_input('Create a ticket in Integria IMS'), - 'fields_descriptions' => '["'.io_safe_input('Ticket title').'","'.io_safe_input('Ticket group ID').'","'.io_safe_input('Ticket priority').'","'.io_safe_input('Ticket owner').'","'.io_safe_input('Ticket type').'","'.io_safe_input('Ticket status').'","'.io_safe_input('Ticket description').'","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]', - 'fields_values' => '["", "", "","","'.$types_string.'","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]', - ] - ); - - // Create 'Create Integria IMS Ticket' action only when user enables IntegriaIMS integration and command exists in database. - $action_values = [ - 'field1' => io_safe_input($config['incident_title']), - 'field1_recovery' => io_safe_input($config['incident_title']), - 'field2' => io_safe_input($config['default_group']), - 'field2_recovery' => io_safe_input($config['default_group']), - 'field3' => io_safe_input($config['default_criticity']), - 'field3_recovery' => io_safe_input($config['default_criticity']), - 'field4' => io_safe_input($config['default_owner']), - 'field4_recovery' => io_safe_input($config['default_owner']), - 'field5' => io_safe_input($config['incident_type']), - 'field5_recovery' => io_safe_input($config['incident_type']), - 'field6' => io_safe_input($config['incident_status']), - 'field6_recovery' => io_safe_input($config['incident_status']), - 'field7' => io_safe_input($config['incident_content']), - 'field7_recovery' => io_safe_input($config['incident_content']), - 'id_group' => 0, - 'action_threshold' => 0, - ]; - - alerts_create_alert_action(io_safe_input('Create Integria IMS ticket'), $id_command_inserted, $action_values); - } else { - // Update 'Integria IMS Ticket' command with ticket types retrieved from Integria IMS. - $sql_update_command_values = sprintf( - ' - UPDATE talert_commands - SET fields_values = \'["","","","","%s","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]\' - WHERE name="%s"', - $types_string, - io_safe_input('Integria IMS Ticket') - ); - - db_process_sql($sql_update_command_values); - - // Update those actions that make use of 'Integria IMS Ticket' command when setup default fields are updated. Empty fields in actions will be filled in with default values. - $update_action_values = [ - $config['incident_title'], - $config['default_group'], - $config['default_criticity'], - $config['default_owner'], - $config['incident_type'], - $config['incident_status'], - $config['incident_content'], - ]; - - foreach ($update_action_values as $key => $value) { - $field_key = ($key + 1); - - $sql_update_action_field = sprintf( - ' - UPDATE talert_actions taa - INNER JOIN talert_commands tac - ON taa.id_alert_command=tac.id - SET field%s= "%s" - WHERE tac.name="Integria IMS Ticket" - AND ( - taa.field%s IS NULL OR taa.field%s="" - )', - $field_key, - $value, - $field_key, - $field_key, - $field_key - ); - - db_process_sql($sql_update_action_field); - } - - foreach ($update_action_values as $key => $value) { - $field_key = ($key + 1); - - $sql_update_action_recovery_field = sprintf( - ' - UPDATE talert_actions taa - INNER JOIN talert_commands tac - ON taa.id_alert_command=tac.id - SET field%s_recovery = "%s" - WHERE tac.name="Integria IMS Ticket" - AND ( - taa.field%s_recovery IS NULL OR taa.field%s_recovery="" - )', - $field_key, - $value, - $field_key, - $field_key, - $field_key - ); - - db_process_sql($sql_update_action_recovery_field); - } - } - } else { - if ($event_response_exists !== false) { - // Delete 'Create incident in IntegriaIMS from event' event response if it does exist and IntegriaIMS integration is disabled. - db_process_sql_delete('tevent_response', ['name' => io_safe_input('Create ticket in IntegriaIMS from event')]); - } - } -} - -// Get parameters from Integria IMS API. -$integria_group_values = []; -$integria_criticity_values = []; -$integria_users_values = []; -$integria_types_values = []; -$integria_status_values = []; - -$integria_groups_csv = integria_api_call(null, null, null, null, 'get_groups', []); - -get_array_from_csv_data_pair($integria_groups_csv, $integria_group_values); - -$integria_status_csv = integria_api_call(null, null, null, null, 'get_incidents_status', []); - -get_array_from_csv_data_pair($integria_status_csv, $integria_status_values); - -$integria_criticity_levels_csv = integria_api_call(null, null, null, null, 'get_incident_priorities', []); - -get_array_from_csv_data_pair($integria_criticity_levels_csv, $integria_criticity_values); - -$integria_users_csv = integria_api_call(null, null, null, null, 'get_users', []); - -$csv_array = explode("\n", $integria_users_csv); - -foreach ($csv_array as $csv_line) { - if (empty($csv_line) === false) { - $integria_users_values[$csv_line] = $csv_line; - } -} - -$integria_types_csv = integria_api_call(null, null, null, null, 'get_types', []); - -get_array_from_csv_data_pair($integria_types_csv, $integria_types_values); - -// Enable table. -$table_enable = new StdClass(); -$table_enable->data = []; -$table_enable->width = '100%'; -$table_enable->id = 'integria-enable-setup'; -$table_enable->class = 'databox filters'; -$table_enable->size['name'] = '30%'; -$table_enable->style['name'] = 'font-weight: bold'; - -// Enable Integria. -$row = []; -$row['name'] = __('Enable Integria IMS'); -$row['control'] = html_print_checkbox_switch('integria_enabled', 1, $config['integria_enabled'], true); -$table_enable->data['integria_enabled'] = $row; - -// Remote config table. -$table_remote = new StdClass(); -$table_remote->data = []; -$table_remote->width = '100%'; -$table_remote->styleTable = 'margin-bottom: 10px;'; -$table_remote->id = 'integria-remote-setup'; -$table_remote->class = 'databox filters filter-table-adv'; -$table_remote->size['hostname'] = '50%'; -$table_remote->size['api_pass'] = '50%'; - -// Enable Integria user configuration. -$row = []; -$row['user_level'] = html_print_label_input_block( - __('Integria configuration at user level'), - html_print_checkbox_switch( - 'integria_user_level_conf', - 1, - $config['integria_user_level_conf'], - true - ) -); -$table_remote->data['integria_user_level_conf'] = $row; - -// Integria user. -$row = []; -$row['user'] = html_print_label_input_block( - __('User'), - html_print_input_text( - 'integria_user', - $config['integria_user'], - '', - 30, - 100, - true - ), - ['div_class' => 'integria-remote-setup-integria_user'] -); - -// Integria password. -$row['password'] = html_print_label_input_block( - __('Password'), - html_print_input_password( - 'integria_pass', - io_output_password($config['integria_pass']), - '', - 30, - 100, - true - ), - ['div_class' => 'integria-remote-setup-integria_pass'] -); -$table_remote->data['integria_pass'] = $row; - -// Integria hostname. -$row = []; -$row['hostname'] = html_print_label_input_block( - __('URL to Integria IMS setup').ui_print_help_tip(__('Full URL to your Integria IMS setup (e.g., http://192.168.1.20/integria, https://support.mycompany.com).'), true), - html_print_input_text( - 'integria_hostname', - $config['integria_hostname'], - '', - 30, - 100, - true - ), - ['div_class' => 'integria-remote-setup-integria_hostname'] -); - -// API password. -$row['api_pass'] = html_print_label_input_block( - __('API Password'), - html_print_input_password( - 'integria_api_pass', - io_output_password($config['integria_api_pass']), - '', - 30, - 100, - true - ), - ['div_class' => 'integria-remote-setup-integria_api_pass'] -); -$table_remote->data['integria_api_pass'] = $row; - -// Request timeout. -$row = []; -$row['req_timeout'] = html_print_label_input_block( - __('Request timeout'), - html_print_input_text( - 'integria_req_timeout', - $config['integria_req_timeout'], - '', - 3, - 10, - true - ), - ['div_class' => 'integria-remote-setup-integria_req_timeout'] -); -$table_remote->data['integria_req_timeout'] = $row; - -$row = []; -$row['control'] = __('Inventory'); -$row['control'] .= html_print_button( - __('Sync inventory'), - 'sync-inventory', - false, - '', - [ - 'icon' => 'cog', - 'mode' => 'secondary mini', - ], - true -); -$row['control'] .= ''; -$row['control'] .= ''; -$row['control'] .= ''; -$table_remote->data['integria_sync_inventory'] = $row; - -// Alert settings. -$table_alert_settings = new StdClass(); -$table_alert_settings->data = []; -$table_alert_settings->width = '100%'; -$table_alert_settings->styleTable = 'margin-bottom: 10px;'; -$table_alert_settings->id = 'integria-cr-settings-setup'; -$table_alert_settings->class = 'databox filters filter-table-adv'; -$table_alert_settings->size[0] = '50%'; -$table_alert_settings->size[1] = '50%'; - -// Alert incident title. -$row = []; -$row[0] = html_print_label_input_block( - __('Title'), - html_print_input_text( - 'incident_title', - $config['incident_title'], - __('Name'), - 50, - 100, - true, - false, - false - ) -); - -// Alert incident description. -$row[1] = html_print_label_input_block( - __('Ticket body'), - html_print_textarea( - 'incident_content', - 3, - 25, - $config['incident_content'], - '', - true - ) -); -$table_alert_settings->data[0] = $row; - -// Alert default group. -$row = []; -$row[0] = html_print_label_input_block( - __('Group'), - html_print_select( - $integria_group_values, - 'default_group', - $config['default_group'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); - -// Alert default criticity. -$row[1] = html_print_label_input_block( - __('Priority'), - html_print_select( - $integria_criticity_values, - 'default_criticity', - $config['default_criticity'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); -$table_alert_settings->data[1] = $row; - -// Alert default owner. -$row = []; -$row[0] = html_print_label_input_block( - __('Owner'), - html_print_autocomplete_users_from_integria( - 'default_owner', - $config['default_owner'], - true, - '30', - false, - false, - 'w100p' - ), - ['div_class' => 'inline'] -); - -// Alert default incident type. -$row[1] = html_print_label_input_block( - __('Type'), - html_print_select( - $integria_types_values, - 'incident_type', - $config['incident_type'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); -$table_alert_settings->data[2] = $row; - -// Alert default incident status. -$row = []; -$row[0] = html_print_label_input_block( - __('Status'), - html_print_select( - $integria_status_values, - 'incident_status', - $config['incident_status'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); -$table_alert_settings->data[3] = $row; - -// Custom response settings. -$table_cr_settings = new StdClass(); -$table_cr_settings->data = []; -$table_cr_settings->width = '100%'; -$table_cr_settings->styleTable = 'margin-bottom: 10px;'; -$table_cr_settings->id = 'integria-cr-settings-setup'; -$table_cr_settings->class = 'databox filters filter-table-adv'; -$table_cr_settings->size[0] = '50%'; -$table_cr_settings->size[1] = '50%'; - -// Custom response incident title. -$row = []; -$row[0] = html_print_label_input_block( - __('Title'), - html_print_input_text( - 'cr_incident_title', - $config['cr_incident_title'], - __('Name'), - 50, - 100, - true, - false, - false - ) -); - -// Custom response incident description. -$row[1] = html_print_label_input_block( - __('Ticket body'), - html_print_textarea( - 'cr_incident_content', - 3, - 25, - $config['cr_incident_content'], - '', - true - ) -); - -$table_cr_settings->data[0] = $row; - -// Custom response default group. -$row = []; -$row[0] = html_print_label_input_block( - __('Group'), - html_print_select( - $integria_group_values, - 'cr_default_group', - $config['cr_default_group'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); - -// Custom response default criticity. -$row[1] = html_print_label_input_block( - __('Priority'), - html_print_select( - $integria_criticity_values, - 'cr_default_criticity', - $config['cr_default_criticity'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); -$table_cr_settings->data[1] = $row; - -// Custom response default owner. -$row = []; -$row[0] = html_print_label_input_block( - __('Owner'), - html_print_autocomplete_users_from_integria( - 'cr_default_owner', - $config['cr_default_owner'], - true, - '30', - false, - false, - 'w100p' - ), - ['div_class' => 'inline'] -); - -// Custom response default incident type. -$row[1] = html_print_label_input_block( - __('Type'), - html_print_select( - $integria_types_values, - 'cr_incident_type', - $config['cr_incident_type'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); -$table_cr_settings->data[2] = $row; - -// Custom response default incident status. -$row = []; -$row[0] = html_print_label_input_block( - __('Status'), - html_print_select( - $integria_status_values, - 'cr_incident_status', - $config['cr_incident_status'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false - ) -); -$table_cr_settings->data[3] = $row; - -// Test. -$row = []; -$row['control'] = __('Test connection'); -$row['control'] .= html_print_button( - __('Test'), - 'test-integria', - false, - '', - [ - 'icon' => 'cog', - 'mode' => 'secondary mini', - ], - true -); -$row['control'] .= ''; -$row['control'] .= ''; -$row['control'] .= ''; -$row['control'] .= ' '; -$table_remote->data['integria_test'] = $row; - -// Print. -echo ''; - -echo "
"; -html_print_input_hidden('update_config', 1); - -// Form enable. -echo '
'; -html_print_table($table_enable); -echo '
'; - -// Form remote. -echo '
'; -echo '
'; -echo ''.__('Integria API settings').''; - -html_print_table($table_remote); - -echo '
'; -echo '
'; - -if ($has_connection != false) { - // Form alert default settings. - echo '
'; - echo '
'; - echo ''.__('Alert default values').' '.ui_print_help_icon('alert_macros', true).''; - - html_print_table($table_alert_settings); - - echo '
'; - echo '
'; - - // Form custom response default settings. - echo '
'; - echo '
'; - echo ''.__('Event custom response default values').' '.ui_print_help_icon('alert_macros', true).''; - - html_print_table($table_cr_settings); - - echo '
'; - echo '
'; - - $update_button = html_print_submit_button( - __('Update'), - 'update_button', - false, - ['icon' => 'update'], - true - ); -} else { - $update_button = html_print_submit_button( - __('Update and continue'), - 'update_button', - false, - ['icon' => 'update'], - true - ); -} - -html_print_action_buttons($update_button); - -echo '
'; - -?> - - diff --git a/pandora_console/godmode/setup/setup_quickshell.php b/pandora_console/godmode/setup/setup_quickshell.php new file mode 100644 index 0000000000..84b3fad1d0 --- /dev/null +++ b/pandora_console/godmode/setup/setup_quickshell.php @@ -0,0 +1,53 @@ +'; + +if (function_exists('quickShellSettings') === true) { + quickShellSettings(); +} + +$action_btns = html_print_submit_button( + __('Update'), + 'update_button', + false, + [ 'icon' => 'update' ], + true +); + +html_print_action_buttons( + $action_btns +); + +echo ''; diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 68f2e1dfe2..6379f86d3a 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -1025,6 +1025,27 @@ $table_font->data[$row][] = html_print_label_input_block( ); $row++; +$table_font->data[$row][] = html_print_label_input_block( + __('Truncate agent text at end'), + html_print_checkbox_switch( + 'truncate_agent_at_end', + 1, + $config['truncate_agent_at_end'], + true + ) +); + +$table_font->data[$row][] = html_print_label_input_block( + __('Truncate module text at end'), + html_print_checkbox_switch( + 'truncate_module_at_end', + 1, + $config['truncate_module_at_end'], + true + ) +); +$row++; + $table_font->data[$row][] = html_print_label_input_block( __('Agent size text'), html_print_div( diff --git a/pandora_console/godmode/setup/setup_websocket_engine.php b/pandora_console/godmode/setup/setup_websocket_engine.php deleted file mode 100644 index 5ee134e558..0000000000 --- a/pandora_console/godmode/setup/setup_websocket_engine.php +++ /dev/null @@ -1,195 +0,0 @@ -'; - -echo '
'; -echo ''.__('WebSocket settings').''; - -$t = new StdClass(); -$t->data = []; -$t->width = '100%'; -$t->class = 'databox filter-table-adv'; -$t->data = []; - -$t->data[0][] = html_print_label_input_block( - __('Bind address'), - html_print_input_text( - 'ws_bind_address', - $config['ws_bind_address'], - '', - 30, - 100, - true - ) -); - -$t->data[0][] = html_print_label_input_block( - __('Bind port'), - html_print_input_text( - 'ws_port', - $config['ws_port'], - '', - 30, - 100, - true - ) -); - -$t->data[1][] = html_print_label_input_block( - __('WebSocket proxy url'), - html_print_input_text( - 'ws_proxy_url', - $config['ws_proxy_url'], - '', - 30, - 100, - true - ) -); - -html_print_input_hidden('update_config', 1); - -// Test. -$row = []; -$test_start = ''; -$test_start .= ' '; -$row['gotty_test'] = html_print_label_input_block( - __('Test connection'), - html_print_button( - __('Test'), - 'test-gotty', - false, - 'handleTest()', - [ - 'icon' => 'cog', - 'mode' => 'secondary mini', - 'style' => 'width: 115px;', - ], - true - ).$test_start, - ['div_class' => 'inline_flex row'] -); - -$t->data['gotty_test'] = $row; - -html_print_table($t); - -echo '
'; - -if (function_exists('quickShellSettings') === true) { - quickShellSettings(); -} - -html_print_action_buttons( - html_print_submit_button( - __('Update'), - 'update_button', - false, - [ 'icon' => 'update' ], - true - ) -); - -echo ''; - -echo ''; diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index df90f49315..08040f839c 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -333,6 +333,7 @@ if ($create_user === true) { $values['default_custom_view'] = (int) get_parameter('default_custom_view'); $values['time_autorefresh'] = (int) get_parameter('time_autorefresh', 0); $values['show_tips_startup'] = (int) get_parameter_switch('show_tips_startup'); + $values['integria_user_level_pass'] = (string) get_parameter('integria_user_level_pass'); $dashboard = get_parameter('dashboard', ''); $visual_console = get_parameter('visual_console', ''); @@ -624,6 +625,7 @@ if ($update_user) { $values['ehorus_user_level_enabled'] = (bool) get_parameter('ehorus_user_level_enabled', false); $values['ehorus_user_level_user'] = (string) get_parameter('ehorus_user_level_user'); $values['ehorus_user_level_pass'] = (string) get_parameter('ehorus_user_level_pass'); + $values['integria_user_level_pass'] = (string) get_parameter('integria_user_level_pass'); $values['middlename'] = get_parameter('middlename', 0); diff --git a/pandora_console/godmode/users/user_management.php b/pandora_console/godmode/users/user_management.php index 39995d52c2..6d5f9bf18b 100644 --- a/pandora_console/godmode/users/user_management.php +++ b/pandora_console/godmode/users/user_management.php @@ -576,6 +576,57 @@ $userManagementTable->data['fields_autorefreshTime'][0] .= ui_print_input_placeh true ); +// eHorus conf +if (isset($config['ehorus_user_level_conf']) === true && (bool) $config['ehorus_user_level_conf'] === true) { + $userManagementTable->data['captions_ehorus_user_level_enabled'][1] = __('Pandora RC user access enabled'); + $userManagementTable->data['fields_ehorus_user_level_enabled'][1] = html_print_checkbox_switch( + 'ehorus_user_level_enabled', + 1, + $user_info['ehorus_user_level_enabled'], + true + ); + + $userManagementTable->rowclass['captions_ehorus_user_level_user'] = 'field_half_width'; + $userManagementTable->rowclass['fields_ehorus_user_level_user'] = 'field_half_width'; + $userManagementTable->data['captions_ehorus_user_level_user'][1] = __('Pandora RC User'); + $userManagementTable->data['fields_ehorus_user_level_user'][1] = html_print_input_text_extended( + 'ehorus_user_level_user', + $user_info['ehorus_user_level_user'], + '', + '', + 25, + 150, + $view_mode, + '', + [ + 'class' => 'input', + 'placeholder' => __('Pandora RC User'), + ], + true + ); + + $userManagementTable->rowclass['captions_ehorus_user_level_pass'] = 'field_half_width'; + $userManagementTable->rowclass['fields_ehorus_user_level_pass'] = 'field_half_width'; + $userManagementTable->data['captions_ehorus_user_level_pass'][1] = __('Pandora RC Password'); + $userManagementTable->data['fields_ehorus_user_level_pass'][1] = html_print_input_text_extended( + 'ehorus_user_level_pass', + io_output_password($user_info['ehorus_user_level_pass']), + '', + '', + '25', + '150', + $view_mode, + '', + [ + 'class' => 'input w100p', + 'placeholder' => __('Pandora RC Password'), + ], + true, + true + ); +} + + // Title for Language and Appearance. $userManagementTable->data['title_lookAndFeel'] = html_print_subtitle_table(__('Language and Appearance')); // Language and color scheme. @@ -607,16 +658,20 @@ if (is_metaconsole() === true) { } } +$performance_variables_control = (array) json_decode(io_safe_output($config['performance_variables_control'])); + $userManagementTable->rowclass['captions_blocksize_eventfilter'] = 'field_half_width'; $userManagementTable->rowclass['fields_blocksize_eventfilter'] = 'field_half_width'; $userManagementTable->data['captions_blocksize_eventfilter'][0] = __('Block size for pagination'); -$userManagementTable->data['fields_blocksize_eventfilter'][0] = html_print_input_text( - 'block_size', - $user_info['block_size'], - '', - 5, - 5, - true +$userManagementTable->data['fields_blocksize_eventfilter'][0] = html_print_input( + [ + 'type' => 'number', + 'size' => 5, + 'max' => $performance_variables_control['block_size']->max, + 'name' => 'block_size', + 'value' => $user_info['block_size'], + 'return' => true, + ] ); if (is_metaconsole() === true && empty($user_info['metaconsole_default_event_filter']) !== true) { @@ -785,6 +840,62 @@ $userManagementTable->data['fields_addSettings'][1] .= html_print_div( true ); + +if ($config['ITSM_enabled'] && $config['ITSM_user_level_conf']) { + // Pandora ITSM user remote login. + $table_ITSM = new StdClass(); + $table_ITSM->data = []; + $table_ITSM->width = '100%'; + $table_ITSM->id = 'ITSM-remote-setup'; + $table_ITSM->class = 'white_box'; + $table_ITSM->size['name'] = '30%'; + $table_ITSM->style['name'] = 'font-weight: bold'; + + // Pandora ITSM user level authentication. + // Title. + $row = []; + $row['control'] = '

'.__('Pandora ITSM user configuration').':

'; + $table_ITSM->data['ITSM_user_level_conf'] = $row; + + // Pandora ITSM pass. + $row = []; + $row['name'] = __('Token'); + $row['control'] = html_print_input_password( + 'integria_user_level_pass', + io_output_password($user_info['integria_user_level_pass']), + '', + 100, + 100, + true + ); + $table_ITSM->data['integria_user_level_pass'] = $row; + + // Test. + $ITSM_host = db_get_value('value', 'tconfig', 'token', 'ITSM_hostname'); + + $row = []; + $row['name'] = __('Test'); + $row['control'] = html_print_button( + __('Start'), + 'ITSM', + false, + '', + [ + 'icon' => 'cog', + 'mode' => 'secondary mini', + ], + true + ); + $row['control'] .= ' '; + $row['control'] .= ' '; + $row['control'] .= ' '; + $row['control'] .= ''; + $table_ITSM->data['ITSM_test'] = $row; + + $userManagementTable->colspan['pandoraitsm'] = 2; + $userManagementTable->data['pandoraitsm'] = html_print_table($table_ITSM, true); +} + if (isset($CodeQRTable) === true || isset($apiTokenContent) === true) { // QR Code and API Token advice. $titleQr = ''.__('Contact details (QR)').''; @@ -810,20 +921,68 @@ $vcard_data['organization'] = io_safe_output(get_product_name()); $vcard_data['url'] = ui_get_full_url('index.php'); $vcard_json = json_encode($vcard_data); + +ui_require_javascript_file('ITSM'); ?> \ No newline at end of file diff --git a/pandora_console/godmode/wizards/Applications.class.php b/pandora_console/godmode/wizards/Applications.class.php index 107550c261..7458aea872 100644 --- a/pandora_console/godmode/wizards/Applications.class.php +++ b/pandora_console/godmode/wizards/Applications.class.php @@ -139,6 +139,14 @@ class Applications extends Wizard // Else: class not found pseudo exception. if ($classname_selected !== null) { $wiz = new $classname_selected($this->page); + // Check if app has been migrated. + if (method_exists($wiz, 'isMigrated') === true) { + if ($wiz->isMigrated() === true) { + ui_print_info_message(__('This legacy app has been migrated to new discovery 2.0 system')); + return false; + } + } + $result = $wiz->run(); if (is_array($result) === true) { return $result; @@ -157,6 +165,13 @@ class Applications extends Wizard foreach ($enterprise_classes as $classpath) { $classname = basename($classpath, '.app.php'); $obj = new $classname(); + + if (method_exists($obj, 'isMigrated') === true) { + if ($obj->isMigrated() === true) { + continue; + } + } + $wiz_data[] = $obj->load(); } diff --git a/pandora_console/godmode/wizards/Cloud.class.php b/pandora_console/godmode/wizards/Cloud.class.php index 4c5074cd3c..2492322f3b 100644 --- a/pandora_console/godmode/wizards/Cloud.class.php +++ b/pandora_console/godmode/wizards/Cloud.class.php @@ -160,6 +160,14 @@ class Cloud extends Wizard // Else: class not found pseudo exception. if ($classname_selected !== null) { $wiz = new $classname_selected($this->page); + // Check if app has been migrated. + if (method_exists($wiz, 'isMigrated') === true) { + if ($wiz->isMigrated() === true) { + ui_print_info_message(__('This legacy app has been migrated to new discovery 2.0 system')); + return false; + } + } + $result = $wiz->run(); if (is_array($result) === true) { return $result; @@ -178,6 +186,13 @@ class Cloud extends Wizard foreach ($enterprise_classes as $classpath) { $classname = basename($classpath, '.cloud.php'); $obj = new $classname(); + // Check if legacy has been migrated. + if (method_exists($obj, 'isMigrated') === true) { + if ($obj->isMigrated() === true) { + continue; + } + } + $wiz_data[] = $obj->load(); } diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 347458ff62..e831022c23 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -160,10 +160,9 @@ class DiscoveryTaskList extends HTML return $this->enableTask(); } - if (enterprise_installed()) { - // This check only applies to enterprise users. - enterprise_hook('tasklist_checkrunning'); + enterprise_hook('tasklist_checkrunning'); + if (enterprise_installed()) { $ret = $this->showListConsoleTask(); } else { $ret = false; @@ -761,7 +760,7 @@ class DiscoveryTaskList extends HTML $data[3] = __('Manual'); } - if ($task['id_recon_script'] == 0 || $ipam === true) { + if (($task['id_recon_script'] == 0 || $ipam === true) && (int) $task['type'] !== DISCOVERY_EXTENSION) { $data[4] = ui_print_truncate_text($subnet, 50, true, true, true, '[…]'); } else { $data[4] = '-'; @@ -998,7 +997,7 @@ class DiscoveryTaskList extends HTML && $task['type'] != DISCOVERY_CLOUD_AWS_RDS && $task['type'] != DISCOVERY_CLOUD_AWS_S3 ) { - if (check_acl($config['id_user'], 0, 'MR') && (int) $task['type'] !== 15) { + if (check_acl($config['id_user'], 0, 'MR') && (int) $task['type'] !== DISCOVERY_EXTENSION) { $data[9] .= ''; $data[9] .= html_print_image( 'images/web@groups.svg', @@ -1269,7 +1268,7 @@ class DiscoveryTaskList extends HTML $status = db_get_value('status', 'trecon_task', 'id_rt', $id_task); if ($status < 0) { - $status = 100; + $status = '100'; } echo json_encode($status); @@ -1288,7 +1287,6 @@ class DiscoveryTaskList extends HTML $result = '
'; $result .= '
'; $result .= ''._('Overall Progress').''; - $result .= '
'; $result .= progress_circular_bar( $task['id_rt'], @@ -1974,7 +1972,6 @@ class DiscoveryTaskList extends HTML { $status = ''; $can_be_reviewed = false; - if (empty($task['summary']) === false && $task['summary'] == 'cancelled' ) { @@ -1992,11 +1989,9 @@ class DiscoveryTaskList extends HTML $status = __('Done'); } } else if ($task['utimestamp'] == 0 - && empty($task['summary']) + && (bool) empty($task['summary']) === true ) { $status = __('Not started'); - } else if ($task['utimestamp'] > 0) { - $status = __('Done'); } else { $status = __('Pending'); } diff --git a/pandora_console/godmode/wizards/ManageExtensions.class.php b/pandora_console/godmode/wizards/ManageExtensions.class.php index e088278eea..91ba1926e5 100644 --- a/pandora_console/godmode/wizards/ManageExtensions.class.php +++ b/pandora_console/godmode/wizards/ManageExtensions.class.php @@ -37,6 +37,8 @@ class ManageExtensions extends HTML public $AJAXMethods = [ 'getExtensionsInstalled', 'validateIniName', + 'loadMigrateModal', + 'migrateApp', ]; /** @@ -216,6 +218,34 @@ class ManageExtensions extends HTML } } + // Check config migrated apps and create it if neccesary. + $migratedAppsJson = db_get_value('value', 'tconfig', 'token', 'migrated_discovery_apps'); + if ($migratedAppsJson === false || empty($migratedAppsJson) === true) { + // If does't exists it means is not migrated yet, insert it. + $migratedApps = [ + 'pandorafms.vmware' => 0, + 'pandorafms.mysql' => 0, + 'pandorafms.mssql' => 0, + 'pandorafms.oracle' => 0, + 'pandorafms.db2' => 0, + 'pandorafms.sap.deset' => 0, + 'pandorafms.gcp.ce' => 0, + 'pandorafms.aws.ec2' => 0, + 'pandorafms.aws.s3' => 0, + 'pandorafms.aws.rds' => 0, + 'pandorafms.azure.mc' => 0, + ]; + + $migratedAppsJson = json_encode($migratedApps); + + if (json_last_error() === JSON_ERROR_NONE) { + config_create_value( + 'migrated_discovery_apps', + io_safe_input($migratedAppsJson) + ); + } + } + $this->prepareBreadcrum( [ [ @@ -283,6 +313,12 @@ class ManageExtensions extends HTML echo '
'; html_print_input_hidden('upload_disco', 1); html_print_table($table); + // Auxiliar div ant string for migrate modal. + $modal = ''; + $modal .= ''; + + echo $modal; + echo '
'; echo '
'; @@ -297,6 +333,8 @@ class ManageExtensions extends HTML "Error": "'.__('Error').'", "Ok": "'.__('Ok').'", "Failed to upload extension": "'.__('Failed to upload extension').'", + "Migrate": "'.__('Migrate').'", + "migrationSuccess": "'.__('Migration Suceeded').'", }; var url = "'.ui_get_full_url('ajax.php', false, false, false).'"; '; @@ -687,6 +725,7 @@ class ManageExtensions extends HTML ); $data[$key]['actions'] .= html_print_input_hidden('short_name', $row['short_name'], true); $data[$key]['actions'] .= '
'; + if ($this->checkFolderConsole($row['short_name']) === true) { $data[$key]['actions'] .= '
'; $data[$key]['actions'] .= html_print_input_image( @@ -715,6 +754,24 @@ class ManageExtensions extends HTML ], ); } + + $migrationHash = $this->canMigrate($row['short_name']); + if ($migrationHash !== false && empty($migrationHash) !== true) { + // Migrate button. + $data[$key]['actions'] .= html_print_input_image( + 'button_migrate-'.$row['short_name'], + 'images/reset.png', + '', + '', + true, + [ + 'onclick' => 'show_migration_form(\''.$row['short_name'].'\',\''.$migrationHash.'\')', + 'title' => __('Migrate old discovery tasks.'), + 'alt' => __('Migrate old discovery tasks.'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + } } if (empty($data) === true) { @@ -1053,4 +1110,384 @@ class ManageExtensions extends HTML } + /** + * Checks if the discovery app can be migrated to .disco system. + * If app is migrated or is not in .ini file, it cannot be migrated. + * + * @param string $shortName Short name of the discovery app. + * + * @return string App hash, false in case hash doesnt exist on ini file, or is already migraeted.. + */ + private function canMigrate(string $shortName='') + { + global $config; + + if (empty($shortName) === true) { + return false; + } + + // 1. Check if app is already migrated: + // Get migrated Discovery Apps from config. + $migratedAppsJson = db_get_value('value', 'tconfig', 'token', 'migrated_discovery_apps'); + + if ($migratedAppsJson === false || empty($migratedAppsJson) === true) { + return false; + } + + // Decode JSON migrated apps. + $migrateApps = json_decode(io_safe_output($migratedAppsJson), true); + + if (json_last_error() !== JSON_ERROR_NONE) { + return false; + } + + // Check app migrated. + if (array_key_exists($shortName, $migrateApps)) { + if (empty($migrateApps[$shortName]) === false && (bool) $migrateApps[$shortName] === true) { + // Already migrated. + return false; + } + } + + // 2. If app not migrated yet, check DiscoveryApplicationsMigrateCodes.ini + // Path to the INI file + $filePath = $config['homedir'].'/extras/discovery/DiscoveryApplicationsMigrateCodes.ini'; + + // Parse the INI file. + $migrationCodes = parse_ini_file($filePath, true); + + if ($migrationCodes === false) { + return false; + } + + // Check shortname in ini file. + if (array_key_exists($shortName, $migrationCodes) === false) { + return false; + } else { + return $migrationCodes[$shortName]; + } + + // All checks ok, discovery app can be migrated. + return false; + + } + + + /** + * Prints html for migrate modal + * + * @return void + */ + public function loadMigrateModal() + { + $shortname = get_parameter('shortname', null); + $hash = get_parameter('hash', null); + + $form = [ + 'action' => '#', + 'id' => 'modal_migrate_form', + 'onsubmit' => 'return false;', + 'class' => 'modal', + 'name' => 'migrate_form', + ]; + + $inputs = []; + $migrateMessage = __( + 'All ‘legacy‘ tasks for this application will be migrated to the new ‘.disco’ package system. All configurations and executions will be managed with the new system. This process will not be reversible.

' + ); + $migrateMessage .= _('Please check the migration code for the application before proceeding.'); + + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_migrate_message', + 'class' => 'hole flex-row flex-items-center w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => $migrateMessage, + 'arguments' => [ + 'class' => 'first_lbl w98p', + 'name' => 'lbl_migrate_message', + 'id' => 'lbl_migrate_message', + ], + ], + ], + ]; + + $inputs[] = [ + 'label' => __('Applicattion hash'), + 'id' => 'div-hash', + 'arguments' => [ + 'name' => 'hash', + 'type' => 'text', + 'value' => $hash, + 'return' => true, + ], + ]; + + $inputs[] = [ + 'block_id' => 'migrate_buttons', + 'class' => 'flex-row flex-items-center w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'arguments' => [ + 'name' => 'cancel', + 'label' => __('Cancel'), + 'type' => 'button', + 'attributes' => [ + 'icon' => 'left', + 'mode' => 'secondary', + 'class' => 'sub cancel float-left', + ], + ], + ], + [ + 'arguments' => [ + 'name' => 'migrate', + 'label' => __('Migrate'), + 'type' => 'submit', + 'attributes' => [ + 'icon' => 'wand', + 'class' => 'sub wand float-right', + ], + ], + ], + ], + ]; + + $spinner = ''; + + $migration_form = $this->printForm( + [ + 'form' => $form, + 'inputs' => $inputs, + ], + true, + ); + + echo $migration_form.$spinner; + } + + + /** + * Migrate app to new .disco system + * + * @return true if success, false in case of error. + */ + public function migrateApp() + { + global $config; + + $hash = get_parameter('hash', false); + $shortName = get_parameter('shortName', false); + + if ($hash === false || $shortName === false) { + return false; + } + + // 1. Gets md5 + try { + $console_md5 = $this->calculateDirectoryMD5($shortName, false); + $server_md5 = $this->calculateDirectoryMD5($shortName, true); + } catch (Exception $e) { + $return = [ + 'error' => $e->getMessage(), + ]; + echo json_encode($return); + return; + } + + if ($console_md5 === false || $server_md5 === false) { + $return = [ + 'error' => __('Error calculating app MD5'), + ]; + echo json_encode($return); + return; + } + + // 2. Checks MD5 + if ($hash === $console_md5 && $hash === $server_md5) { + // Init migration script. + $return = $this->executeMigrationScript($shortName); + } else { + $return = [ + 'error' => __('App hash does not match.'), + ]; + } + + // Add shotrname to return for showing messages. + $return['shortname'] = $shortName; + + echo \json_encode($return); + } + + + /** + * Calculates directory MD% and saves it into array + * + * @param string $shortName Shorname of app. + * @param boolean $server If true, perform checks into server folder. + * + * @return $md5 Array of md5 of filess. + */ + private function calculateDirectoryMD5($shortName, $server) + { + global $config; + + $md5List = []; + + $serverPath = $config['remote_config'].'/discovery/'.$shortName; + $consolePath = $config['homedir'].'/'.$this->path.'/'.$shortName; + + if ($server === true) { + $directory = $serverPath; + } else { + $directory = $consolePath; + } + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); + + foreach ($iterator as $file) { + if ($file->isFile()) { + $md5List[] = md5_file($file->getPathname()); + } + } + + if ($server === true) { + $console_ini = $consolePath.'/discovery_definition.ini'; + $logo = $consolePath.'/logo.png'; + + if (file_exists($console_ini)) { + $md5List[] = md5_file($console_ini); + } + + if (file_exists($logo)) { + $md5List[] = md5_file($logo); + } + } + + sort($md5List); + $concatenatedChecksums = implode('', $md5List); + return md5($concatenatedChecksums); + } + + + /** + * Executed migration script for app + * + * @param string $shortName Shortname of the app. + * + * @return true on success, false in case of error. + */ + private function executeMigrationScript(string $shortName) + { + global $config; + + $dblock = db_get_lock('migrate-working'); + // Try to get a lock from DB. + if ($dblock !== 1) { + // Locked! + return false; + } + + $scriptName = preg_replace('/^pandorafms\.(\w+\.?\w*)$/m', 'migrate.$1.sql', $shortName); + + $script_path = $config['homedir'].'/extras/discovery/migration_scripts/'.$scriptName; + if (file_exists($script_path) === false) { + $return = [ + 'error' => __('Migration script '.$scriptName.' could not be found'), + ]; + } else { + try { + $res = db_process_file($script_path, false); + } catch (\Exception $e) { + $return = [ + 'error' => $e->getMessage(), + ]; + } finally { + db_release_lock('migrate_working'); + } + + if ($res === true) { + $migrateAppsJson = io_safe_output( + db_get_value( + 'value', + 'tconfig', + 'token', + 'migrated_discovery_apps' + ) + ); + + $migrateApps = json_decode( + $migrateAppsJson, + true + ); + + $migrateApps[$shortName] = 1; + + $migratedAppsJson = json_encode($migrateApps); + + if (json_last_error() === JSON_ERROR_NONE) { + config_update_value( + 'migrated_discovery_apps', + $migratedAppsJson + ); + } else { + $return = [ + 'error' => __('Error decoding migrated apps json.'), + ]; + } + + $return = [ + 'result' => __('App migrated successfully'), + 'shortName' => $shortName, + ]; + } else { + $return = [ + 'error' => __('Error migrating app'), + ]; + } + } + + return $return; + + } + + + /** + * Check if legacy app has been migrated. + * + * @param string $shortName Shorn name of the app. + * + * @return boolean + */ + static public function isMigrated($shortName) + { + global $config; + + $migrateAppsJson = io_safe_output( + db_get_value( + 'value', + 'tconfig', + 'token', + 'migrated_discovery_apps' + ) + ); + + $migratedApps = json_decode($migrateAppsJson, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + return false; + } + + if (array_key_exists($shortName, $migratedApps) === true && empty($migratedApps[$shortName] === false)) { + return (bool) $migratedApps[$shortName]; + } else { + return false; + } + + } + + } diff --git a/pandora_console/images/Anomaly-detection.png b/pandora_console/images/Anomaly-detection.png new file mode 100644 index 0000000000..cf3c346138 Binary files /dev/null and b/pandora_console/images/Anomaly-detection.png differ diff --git a/pandora_console/images/Anomaly-detection@2x.png b/pandora_console/images/Anomaly-detection@2x.png new file mode 100644 index 0000000000..ba2352fbf1 Binary files /dev/null and b/pandora_console/images/Anomaly-detection@2x.png differ diff --git a/pandora_console/images/Anomaly-detection@svg.svg b/pandora_console/images/Anomaly-detection@svg.svg new file mode 100644 index 0000000000..45abb1db7a --- /dev/null +++ b/pandora_console/images/Anomaly-detection@svg.svg @@ -0,0 +1,14 @@ + + + Anomaly detection@svg + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/RC.png b/pandora_console/images/RC.png new file mode 100644 index 0000000000..b89cd3e254 Binary files /dev/null and b/pandora_console/images/RC.png differ diff --git a/pandora_console/images/Tactical_Groups.svg b/pandora_console/images/Tactical_Groups.svg new file mode 100644 index 0000000000..99b7e64d72 --- /dev/null +++ b/pandora_console/images/Tactical_Groups.svg @@ -0,0 +1,19 @@ + + + 59DFD8E8-D019-4076-8FED-D5B81BE90197 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/Tactical_Module_template.svg b/pandora_console/images/Tactical_Module_template.svg new file mode 100644 index 0000000000..6623647c04 --- /dev/null +++ b/pandora_console/images/Tactical_Module_template.svg @@ -0,0 +1,16 @@ + + + 04A64774-B33A-4338-8092-D83F51BBE8C1 + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/Tactical_Modules.svg b/pandora_console/images/Tactical_Modules.svg new file mode 100644 index 0000000000..6dda1a9606 --- /dev/null +++ b/pandora_console/images/Tactical_Modules.svg @@ -0,0 +1,15 @@ + + + CD5F043F-0CA1-4012-8590-20C64D7E7E0D + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/Tactical_Not_init_module.svg b/pandora_console/images/Tactical_Not_init_module.svg new file mode 100644 index 0000000000..84a9cd0cc4 --- /dev/null +++ b/pandora_console/images/Tactical_Not_init_module.svg @@ -0,0 +1,15 @@ + + + E1DA8ECF-DB7D-48B5-96B0-3C6199FCC8EB + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/Tactical_Plugins.svg b/pandora_console/images/Tactical_Plugins.svg new file mode 100644 index 0000000000..99f3a0a6b1 --- /dev/null +++ b/pandora_console/images/Tactical_Plugins.svg @@ -0,0 +1,15 @@ + + + E2220716-B06D-4CCD-8005-3668217A51C4 + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/Tactical_Policies.svg b/pandora_console/images/Tactical_Policies.svg new file mode 100644 index 0000000000..4ad0ed37a7 --- /dev/null +++ b/pandora_console/images/Tactical_Policies.svg @@ -0,0 +1,15 @@ + + + 7780B3A6-04AD-41C0-83B2-12DA21E87CFC + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/Tactical_Unknown_agent.svg b/pandora_console/images/Tactical_Unknown_agent.svg new file mode 100644 index 0000000000..bda519c869 --- /dev/null +++ b/pandora_console/images/Tactical_Unknown_agent.svg @@ -0,0 +1,15 @@ + + + A8855F06-D8BF-417A-841F-4FBE78913DFF + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/add-alert.svg b/pandora_console/images/add-alert.svg new file mode 100755 index 0000000000..3dec357543 --- /dev/null +++ b/pandora_console/images/add-alert.svg @@ -0,0 +1,7 @@ + + + Add alert@svg + + + + \ No newline at end of file diff --git a/pandora_console/images/alert_recovered@svg.svg b/pandora_console/images/alert_recovered@svg.svg new file mode 100644 index 0000000000..09f84d6215 --- /dev/null +++ b/pandora_console/images/alert_recovered@svg.svg @@ -0,0 +1,9 @@ + + + + Dark / 20 / alert@svg + Created with Sketch. + + + + \ No newline at end of file diff --git a/pandora_console/images/ehorus/ehorus.png b/pandora_console/images/ehorus/ehorus.png deleted file mode 100644 index e533fe4eac..0000000000 Binary files a/pandora_console/images/ehorus/ehorus.png and /dev/null differ diff --git a/pandora_console/images/integria.png b/pandora_console/images/integria.png deleted file mode 100644 index 9dcad27e3b..0000000000 Binary files a/pandora_console/images/integria.png and /dev/null differ diff --git a/pandora_console/images/integria_logo.png b/pandora_console/images/integria_logo.png deleted file mode 100644 index f56ecfdab5..0000000000 Binary files a/pandora_console/images/integria_logo.png and /dev/null differ diff --git a/pandora_console/images/integria_logo.svg b/pandora_console/images/integria_logo.svg deleted file mode 100644 index b894a2ada3..0000000000 --- a/pandora_console/images/integria_logo.svg +++ /dev/null @@ -1,39 +0,0 @@ - - - - Integria IMS - Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pandora_console/images/integria_logo_gray.png b/pandora_console/images/integria_logo_gray.png deleted file mode 100644 index d901e72493..0000000000 Binary files a/pandora_console/images/integria_logo_gray.png and /dev/null differ diff --git a/pandora_console/images/itsm.png b/pandora_console/images/itsm.png new file mode 100644 index 0000000000..0571f55298 Binary files /dev/null and b/pandora_console/images/itsm.png differ diff --git a/pandora_console/images/log_server.svg b/pandora_console/images/log_server.svg new file mode 100644 index 0000000000..26f27c6ae9 --- /dev/null +++ b/pandora_console/images/log_server.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + diff --git a/pandora_console/images/menu/itsm.svg b/pandora_console/images/menu/itsm.svg new file mode 100644 index 0000000000..a8bcc9d3b2 --- /dev/null +++ b/pandora_console/images/menu/itsm.svg @@ -0,0 +1,7 @@ + + + ITSM icon + + + + \ No newline at end of file diff --git a/pandora_console/images/menu/security.svg b/pandora_console/images/menu/security.svg new file mode 100644 index 0000000000..64cf5252f7 --- /dev/null +++ b/pandora_console/images/menu/security.svg @@ -0,0 +1,7 @@ + + + Hardening@svg + + + + \ No newline at end of file diff --git a/pandora_console/images/module_event_critical.png b/pandora_console/images/module_event_critical.png new file mode 100644 index 0000000000..d92fd2cf07 Binary files /dev/null and b/pandora_console/images/module_event_critical.png differ diff --git a/pandora_console/images/module_event_ok.png b/pandora_console/images/module_event_ok.png new file mode 100644 index 0000000000..d92fd2cf07 Binary files /dev/null and b/pandora_console/images/module_event_ok.png differ diff --git a/pandora_console/images/module_event_unknown.png b/pandora_console/images/module_event_unknown.png new file mode 100644 index 0000000000..d92fd2cf07 Binary files /dev/null and b/pandora_console/images/module_event_unknown.png differ diff --git a/pandora_console/images/module_event_warning.png b/pandora_console/images/module_event_warning.png new file mode 100644 index 0000000000..d92fd2cf07 Binary files /dev/null and b/pandora_console/images/module_event_warning.png differ diff --git a/pandora_console/images/os@svg.svg b/pandora_console/images/os@svg.svg new file mode 100644 index 0000000000..80f8caf194 --- /dev/null +++ b/pandora_console/images/os@svg.svg @@ -0,0 +1,7 @@ + + + os@svg + + + + \ No newline at end of file diff --git a/pandora_console/images/os_version@svg.svg b/pandora_console/images/os_version@svg.svg new file mode 100644 index 0000000000..1274ccc3f8 --- /dev/null +++ b/pandora_console/images/os_version@svg.svg @@ -0,0 +1,15 @@ + + + os version@svg + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/pandoraITSM_logo.png b/pandora_console/images/pandoraITSM_logo.png new file mode 100644 index 0000000000..952c15759f Binary files /dev/null and b/pandora_console/images/pandoraITSM_logo.png differ diff --git a/pandora_console/images/pandoraITSM_logo_gray.png b/pandora_console/images/pandoraITSM_logo_gray.png new file mode 100644 index 0000000000..9a4a8bf9e4 Binary files /dev/null and b/pandora_console/images/pandoraITSM_logo_gray.png differ diff --git a/pandora_console/images/status_check@svg.svg b/pandora_console/images/status_check@svg.svg new file mode 100644 index 0000000000..78e62ea848 --- /dev/null +++ b/pandora_console/images/status_check@svg.svg @@ -0,0 +1,26 @@ + + + AE320C3A-79E4-4E24-956A-B81125ACFA52@svg + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/status_error@svg.svg b/pandora_console/images/status_error@svg.svg new file mode 100644 index 0000000000..e6502bff7e --- /dev/null +++ b/pandora_console/images/status_error@svg.svg @@ -0,0 +1,26 @@ + + + CD9D3D2F-E199-427F-BC6C-532C8382EE45@svg + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/system_event.svg b/pandora_console/images/system_event.svg new file mode 100644 index 0000000000..41a9b2c0ec --- /dev/null +++ b/pandora_console/images/system_event.svg @@ -0,0 +1,15 @@ + + + F7C0551D-EEAD-4AA0-87B8-DE2D255390BB + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/widgets/ITSMIncidences.png b/pandora_console/images/widgets/ITSMIncidences.png new file mode 100644 index 0000000000..18c83029b4 Binary files /dev/null and b/pandora_console/images/widgets/ITSMIncidences.png differ diff --git a/pandora_console/images/widgets/security_hardening.png b/pandora_console/images/widgets/security_hardening.png new file mode 100644 index 0000000000..73b4a4957e Binary files /dev/null and b/pandora_console/images/widgets/security_hardening.png differ diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 2fbda5d75c..d742f952e8 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -35,7 +35,6 @@ $disable_alert = (bool) get_parameter('disable_alert'); $enable_alert = (bool) get_parameter('enable_alert'); $get_actions_module = (bool) get_parameter('get_actions_module'); $show_update_action_menu = (bool) get_parameter('show_update_action_menu'); -$get_agent_alerts_agent_view = (bool) get_parameter('get_agent_alerts_agent_view'); $resize_event_week = (bool) get_parameter('resize_event_week'); $get_agent_alerts_datatable = (bool) get_parameter('get_agent_alerts_datatable', 0); $alert_validate = (bool) get_parameter('alert_validate', false); @@ -91,270 +90,6 @@ if ($get_agent_alerts_simple) { } -if ($get_agent_alerts_agent_view) { - include_once $config['homedir'].'/include/functions_agents.php'; - 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'); - - $free_search_alert = get_parameter('free_search_alert', ''); - $all_groups = json_decode(io_safe_output(get_parameter('all_groups'))); - $idAgent = (int) get_parameter('id_agent'); - $filter = get_parameter('filter', 'all_enabled'); - $url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$idAgent; - - $sortField = get_parameter('sort_field'); - $sort = get_parameter('sort', 'none'); - $selected = true; - $selectModuleUp = false; - $selectModuleDown = false; - $selectTemplateUp = false; - $selectTemplateDown = false; - $selectLastFiredUp = false; - $selectLastFiredDown = false; - switch ($sortField) { - case 'module': - switch ($sort) { - case 'up': - $selectModuleUp = $selected; - $order = [ - 'field' => 'agent_module_name', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectModuleDown = $selected; - $order = [ - 'field' => 'agent_module_name', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'template': - switch ($sort) { - case 'up': - $selectTemplateUp = $selected; - $order = [ - 'field' => 'template_name', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectTemplateDown = $selected; - $order = [ - 'field' => 'template_name', - 'order' => 'DESC', - ]; - break; - } - break; - - case 'last_fired': - switch ($sort) { - case 'up': - $selectLastFiredUp = $selected; - $order = [ - 'field' => 'last_fired', - 'order' => 'ASC', - ]; - break; - - case 'down': - $selectLastFiredDown = $selected; - $order = [ - 'field' => 'last_fired', - 'order' => 'DESC', - ]; - break; - } - break; - - default: - $selectDisabledUp = ''; - $selectDisabledDown = ''; - $selectModuleUp = $selected; - $selectModuleDown = false; - $selectTemplateUp = false; - $selectTemplateDown = false; - $selectLastFiredUp = false; - $selectLastFiredDown = false; - $order = [ - 'field' => 'agent_module_name', - 'order' => 'ASC', - ]; - break; - } - - if ($free_search_alert != '') { - $whereAlertSimple = 'AND ('.'id_alert_template IN ( - SELECT id - FROM talert_templates - WHERE name LIKE "%'.$free_search_alert.'%") OR '.'id_alert_template IN ( - SELECT id - FROM talert_templates - WHERE id_alert_action IN ( - SELECT id - FROM talert_actions - WHERE name LIKE "%'.$free_search_alert.'%")) OR '.'talert_template_modules.id IN ( - SELECT id_alert_template_module - FROM talert_template_module_actions - WHERE id_alert_action IN ( - SELECT id - FROM talert_actions - WHERE name LIKE "%'.$free_search_alert.'%")) OR '.'id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE nombre LIKE "%'.$free_search_alert.'%") OR '.'id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE alias LIKE "%'.$free_search_alert.'%")'.')'; - } else { - $whereAlertSimple = ''; - } - - // Add checks for user ACL. - $groups = users_get_groups($config['id_user'], $access); - $id_groups = array_keys($groups); - - if (empty($id_groups)) { - $whereAlertSimple .= ' AND (1 = 0) '; - } else { - $whereAlertSimple .= sprintf( - ' AND id_agent_module IN ( - SELECT tam.id_agente_modulo - FROM tagente_modulo tam - WHERE tam.id_agente IN ( - SELECT - ta.id_agente - FROM - tagente ta - WHERE - ta.id_grupo IN (%s) - ) - OR tam.id_agente IN ( - SELECT - DISTINCT(tasg.id_agent) - FROM - tagent_secondary_group tasg - WHERE - tasg.id_group IN (%s) - ) - ) ', - implode(',', $id_groups), - implode(',', $id_groups) - ); - } - - $alerts = []; - - $filter_alert = []; - if ($filter_standby == 'standby_on') { - $filter_alert['disabled'] = $filter; - $filter_alert['standby'] = '1'; - } else if ($filter_standby == 'standby_off') { - $filter_alert['disabled'] = $filter; - $filter_alert['standby'] = '0'; - } else { - $filter_alert['disabled'] = $filter; - } - - $options_simple = ['order' => $order]; - - $alerts['alerts_simple'] = agents_get_alerts_simple($idAgent, $filter_alert, $options_simple, $whereAlertSimple, false, false, false, false, $strict_user, $tag_filter); - $countAlertsSimple = agents_get_alerts_simple($idAgent, $filter_alert, false, $whereAlertSimple, false, false, false, true, $strict_user, $tag_filter); - - // Urls to sort the table. - $url_up_module = $url.'&sort_field=module&sort=up'; - $url_down_module = $url.'&sort_field=module&sort=down'; - $url_up_template = $url.'&sort_field=template&sort=up'; - $url_down_template = $url.'&sort_field=template&sort=down'; - $url_up_lastfired = $url.'&sort_field=last_fired&sort=up'; - $url_down_lastfired = $url.'&sort_field=last_fired&sort=down'; - - $table = new stdClass(); - $table->width = '100%'; - $table->class = 'info_table'; - $table->cellpadding = '0'; - $table->cellspacing = '0'; - $table->size = []; - $table->head = []; - $table->align = []; - - if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { - $table->size[7] = '5%'; - if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) { - $table->head[8] = __('Validate'); - $table->align[8] = 'left'; - $table->size[8] = '5%'; - } - - $table->head[0] = "".__('P.').''; - $table->head[1] = "".__('S.').''; - - if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) { - $table->head[2] = "".__('F.').''; - } - - $table->head[3] = __('Module'); - $table->head[4] = __('Template'); - $table->head[5] = __('Action'); - $table->head[6] = __('Last fired'); - $table->head[7] = __('Status'); - - $table->align[7] = 'center'; - - $table->head[3] .= ui_get_sorting_arrows($url_up_module, $url_down_module, $selectModuleUp, $selectModuleDown); - $table->head[4] .= ui_get_sorting_arrows($url_up_template, $url_down_template, $selectTemplateUp, $selectTemplateDown); - $table->head[6] .= ui_get_sorting_arrows($url_up_lastfired, $url_down_lastfired, $selectLastFiredUp, $selectLastFiredDown); - } else { - $table->size[6] = '5%'; - if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) { - $table->head[7] = __('Validate'); - $table->align[7] = 'left'; - $table->size[7] = '5%'; - } - - $table->head[0] = "".__('S.').''; - - if (check_acl($config['id_user'], $id_group, 'AW') || check_acl($config['id_user'], $id_group, 'LM')) { - $table->head[1] = "".__('F.').''; - } - - $table->head[2] = __('Module'); - $table->head[3] = __('Template'); - $table->head[4] = __('Action'); - $table->head[5] = __('Last fired'); - $table->head[6] = __('Status'); - - $table->align[6] = 'center'; - - $table->head[2] .= ui_get_sorting_arrows($url_up_module, $url_down_module, $selectModuleUp, $selectModuleDown); - $table->head[3] .= ui_get_sorting_arrows($url_up_template, $url_down_template, $selectTemplateUp, $selectTemplateDown); - $table->head[5] .= ui_get_sorting_arrows($url_up_lastfired, $url_down_lastfired, $selectLastFiredUp, $selectLastFiredDown); - } - - $table->data = []; - $rowPair = true; - $iterator = 0; - foreach ($alerts['alerts_simple'] as $alert) { - $row = ui_format_alert_row($alert, false, $url, 'font-size: 9pt;'); - $table->data[] = $row; - } - - if (empty($table->data) === false) { - html_print_table($table); - } else { - ui_print_info_message(['no_close' => true, 'message' => __('No alerts found') ]); - } -} - if ($enable_alert) { if (! check_acl($config['id_user'], 0, 'LW')) { db_pandora_audit( @@ -501,7 +236,7 @@ if ($show_update_action_menu) { $data .= ''; $data .= ui_print_truncate_text( $agent_alias, - 'agent_small', + 'agent_medium', false, true, true, diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php index a403f77748..f247c2e51e 100644 --- a/pandora_console/include/ajax/custom_fields.php +++ b/pandora_console/include/ajax/custom_fields.php @@ -65,6 +65,7 @@ if (check_login()) { } } + if ($get_custom_fields_data) { $name_custom_fields = get_parameter('name_custom_fields', 0); $array_custom_fields_data = get_custom_fields_data($name_custom_fields); @@ -110,30 +111,51 @@ if (check_login()) { // Table temporary for save array in table // by order and search custom_field data. - $table_temporary = 'CREATE TEMPORARY TABLE temp_custom_fields ( - id_server int(10), - id_agent int(10), - name_custom_fields varchar(2048), - critical_count int, - warning_count int, - unknown_count int, - notinit_count int, - normal_count int, - total_count int, - `status` int(2), - KEY `data_index_temp_1` (`id_server`, `id_agent`) - )'; - db_process_sql($table_temporary); + if (is_metaconsole() === true) { + $table_temporary = 'CREATE TEMPORARY TABLE temp_custom_fields ( + id_server int(10), + id_agent int(10), + name_custom_fields varchar(2048), + critical_count int, + warning_count int, + unknown_count int, + notinit_count int, + normal_count int, + total_count int, + `status` int(2), + KEY `data_index_temp_1` (`id_server`, `id_agent`) + )'; + } else { + $table_temporary = 'CREATE TEMPORARY TABLE temp_custom_fields ( + id_agent int(10), + name_custom_fields varchar(2048), + critical_count int, + warning_count int, + unknown_count int, + notinit_count int, + normal_count int, + total_count int, + `status` int(2), + KEY `data_index_temp_1` ( `id_agent`) + )'; + } + + $resul_tab_temp = db_process_sql($table_temporary); // Insert values array in table temporary. $values_insert = []; foreach ($indexed_descriptions as $key => $value) { - $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')'; + if (is_metaconsole() === true) { + $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')'; + } else { + $values_insert[] = '('.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')'; + } } $values_insert_implode = implode(',', $values_insert); $query_insert = 'INSERT INTO temp_custom_fields VALUES '.$values_insert_implode; - db_process_sql($query_insert); + + $result_temp = db_process_sql($query_insert); // Search table for alias, custom field data, server_name, direction. $search_query = ''; @@ -199,41 +221,17 @@ if (check_login()) { } // Query all fields result. - $query = sprintf( - 'SELECT - tma.id_agente, - tma.id_tagente, - tma.id_tmetaconsole_setup, - tma.alias, - tma.direccion, - tma.server_name, - temp.name_custom_fields, - temp.status - FROM tmetaconsole_agent tma - INNER JOIN temp_custom_fields temp - ON temp.id_agent = tma.id_tagente - AND temp.id_server = tma.id_tmetaconsole_setup - WHERE tma.disabled = 0 - %s - %s - %s - %s - LIMIT %d OFFSET %d - ', - $search_query, - $status_agent_search, - $status_module_search, - $order_by, - $length, - $start - ); - - $result = db_get_all_rows_sql($query); - - // Query count. - $query_count = sprintf( - 'SELECT - COUNT(tma.id_agente) AS `count` + if (is_metaconsole() === true) { + $query = sprintf( + 'SELECT + tma.id_agente, + tma.id_tagente, + tma.id_tmetaconsole_setup, + tma.alias, + tma.direccion, + tma.server_name, + temp.name_custom_fields, + temp.status FROM tmetaconsole_agent tma INNER JOIN temp_custom_fields temp ON temp.id_agent = tma.id_tagente @@ -242,16 +240,87 @@ if (check_login()) { %s %s %s + %s + LIMIT %d OFFSET %d ', - $search_query, - $status_agent_search, - $status_module_search - ); + $search_query, + $status_agent_search, + $status_module_search, + $order_by, + $length, + $start + ); + } else { + $query = sprintf( + 'SELECT + tma.id_agente, + tma.alias, + tma.direccion, + tma.server_name, + temp.name_custom_fields, + temp.status + FROM tagente as tma + INNER JOIN temp_custom_fields temp + ON temp.id_agent = tma.id_agente + WHERE tma.disabled = 0 + %s + %s + %s + %s + LIMIT %d OFFSET %d + ', + $search_query, + $status_agent_search, + $status_module_search, + $order_by, + $length, + $start + ); + } + + $result = db_get_all_rows_sql($query); + // Query count. + if (is_metaconsole() === true) { + $query_count = sprintf( + 'SELECT + COUNT(tma.id_agente) AS `count` + FROM tmetaconsole_agent tma + INNER JOIN temp_custom_fields temp + ON temp.id_agent = tma.id_tagente + AND temp.id_server = tma.id_tmetaconsole_setup + WHERE tma.disabled = 0 + %s + %s + %s + ', + $search_query, + $status_agent_search, + $status_module_search + ); + } else { + $query_count = sprintf( + 'SELECT + COUNT(tma.id_agente) AS `count` + FROM tagente tma + INNER JOIN temp_custom_fields temp + ON temp.id_agent = tma.id_agente + WHERE tma.disabled = 0 + %s + %s + %s + ', + $search_query, + $status_agent_search, + $status_module_search + ); + } $count = db_get_sql($query_count); - // For link nodes. - $array_nodes = metaconsole_get_connections(); + if (is_metaconsole() === true) { + $array_nodes = metaconsole_get_connections(); + } + if (isset($array_nodes) && is_array($array_nodes)) { $hash_array_nodes = []; foreach ($array_nodes as $key => $server) { @@ -280,19 +349,24 @@ if (check_login()) { $data = []; foreach ($result as $values) { $image_status = agents_get_image_status($values['status']); - // Link nodes. - $agent_link = '
'; + if (is_metaconsole() === true) { + $agent_link = ''; + $agent_alias = ui_print_truncate_text( + $values['alias'], + 'agent_small', + false, + true, + true, + '[…]', + 'font-size:7.5pt;' + ); + } else { + $agent_link = ''; + $agent_alias = $values['alias']; + } + - $agent_alias = ui_print_truncate_text( - $values['alias'], - 'agent_small', - false, - true, - true, - '[…]', - 'font-size:7.5pt;' - ); if (can_user_access_node()) { $agent = $agent_link.''.$agent_alias.''; @@ -300,6 +374,11 @@ if (check_login()) { $agent = $agent_alias; } + if (is_metaconsole() === false) { + $values['id_tagente'] = $values['id_agente']; + $values['id_tmetaconsole_setup'] = 1; + } + $data[] = [ 'ref' => $referencia, 'data_custom_field' => ui_bbcode_to_html($values['name_custom_fields']), @@ -405,7 +484,7 @@ if (check_login()) { $table_modules = new stdClass(); $table_modules->width = '100%'; - $table_modules->class = 'databox data'; + $table_modules->class = 'databox data custom_field_data'; $table_modules->head = []; $table_modules->head[0] = __('Module name'); @@ -589,7 +668,11 @@ if (check_login()) { __('Load filter'), 'load_filter', false, - 'class="sub upd"', + [ + 'icon' => 'search', + 'class' => 'sub upd', + 'onclick' => 'load_filter()', + ], true ); @@ -608,12 +691,14 @@ if (check_login()) { ), true ); - $table = new StdClass; $table->id = 'save_filter_form'; $table->width = '100%'; $table->class = 'databox'; $table->rowspan = []; + $table->style = []; + $table->cellstyle[0][0] = 'display: grid'; + $table->cellstyle[0][1] = 'display: grid'; if ($filters['id'] == 'extended_create_filter') { echo "
"; @@ -624,7 +709,7 @@ if (check_login()) { '', 15, 255, - true + true, ); $table->data[1][0] = __('Group'); @@ -650,11 +735,16 @@ if (check_login()) { ); $table->rowspan[0][2] = 2; + $table->data[0][2] = html_print_submit_button( __('Create filter'), 'create_filter', false, - 'class="sub upd"', + [ + 'icon' => 'search', + 'class' => 'sub upd', + 'onclick' => 'create_filter()', + ], true ); } else { @@ -702,14 +792,23 @@ if (check_login()) { __('Delete filter'), 'delete_filter', false, - 'class="sub upd"', + [ + 'icon' => 'delete', + 'class' => 'sub upd', + 'onclick' => 'delete_filter()', + ], true ); + $table->data[1][2] = html_print_submit_button( __('Update filter'), 'update_filter', false, - 'class="sub upd"', + [ + 'icon' => 'update', + 'class' => 'sub upd', + 'onclick' => 'update_filter()', + ], true ); } diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 7ccf17938b..7e8341c4a1 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,6 +92,9 @@ $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); $settings_modal = get_parameter('settings', 0); $parameters_modal = get_parameter('parameters', 0); +// User private filter. +$current_filter = get_parameter('current_filter', 0); +$private_filter_event = get_parameter('private_filter_event', 0); if ($get_comments === true) { global $config; @@ -337,6 +340,14 @@ if ($save_event_filter) { $values['custom_data'] = get_parameter('custom_data'); $values['custom_data_filter_type'] = get_parameter('custom_data_filter_type'); + // Get private filter from user. + $private_filter = get_parameter_switch('private_filter_user', 0); + if ((int) $private_filter === 1) { + $values['private_filter_user'] = $config['id_user']; + } else { + $values['private_filter_user'] = null; + } + if (is_metaconsole() === true) { $values['server_id'] = implode(',', get_parameter('server_id')); } @@ -397,6 +408,17 @@ if ($update_event_filter) { $values['custom_data'] = get_parameter('custom_data'); $values['custom_data_filter_type'] = get_parameter('custom_data_filter_type'); + // Get private filter from user. + $private_filter = get_parameter('private_filter_user', 0); + $user_private_filter = events_get_event_filter($id); + if ((int) $private_filter === 1 && $user_private_filter['private_filter_user'] === null) { + $values['private_filter_user'] = $config['id_user']; + } else if ($private_filter === $user_private_filter['private_filter_user'] && $user_private_filter['private_filter_user'] !== $config['id_user']) { + $values['private_filter_user'] = $user_private_filter['private_filter_user']; + } else { + $values['private_filter_user'] = null; + } + if (is_metaconsole() === true) { $values['server_id'] = implode(',', get_parameter('server_id')); } @@ -712,8 +734,8 @@ if ($save_filter_modal) { $table = new StdClass; $table->id = 'save_filter_form'; $table->width = '100%'; - $table->cellspacing = 4; - $table->cellpadding = 4; + $table->cellspacing = 5; + $table->cellpadding = 5; $table->class = 'databox'; if (is_metaconsole() === true) { $table->class = 'databox filters'; @@ -732,7 +754,7 @@ if ($save_filter_modal) { 'filter_mode', 'new', __('New filter'), - true, + ((int) $current_filter === 0) ? true : false, true ); @@ -740,7 +762,7 @@ if ($save_filter_modal) { 'filter_mode', 'update', __('Update filter'), - false, + ((int) $current_filter > 0) ? true : false, true ); @@ -755,6 +777,7 @@ if ($save_filter_modal) { $table->rowclass[2] = 'flex'; $table->rowclass[3] = 'flex'; $table->rowclass[4] = 'flex'; + $table->rowclass[5] = 'flex'; $data[0] = ''.__('Filter name').''.$jump; $data[0] .= html_print_input_text('id_name', '', '', 15, 255, true); if (is_metaconsole()) { @@ -801,9 +824,9 @@ if ($save_filter_modal) { $data[0] .= html_print_select( $_filters_update, 'overwrite_filter', + $current_filter, '', - '', - '', + __('None'), 0, true, false, @@ -814,6 +837,31 @@ if ($save_filter_modal) { $table->data[] = $data; $table->rowclass[] = ''; + $data = []; + $table->rowid[4] = 'update_filter_row2'; + + $table->data[] = $data; + $table->rowclass[] = ''; + + // Update user private filter. + $data = []; + $table->rowid[6] = 'private_filter_event_row1'; + $data[0] = html_print_label_input_block( + __('Private'), + html_print_checkbox_switch( + 'private_filter_event', + $private_filter_event, + $private_filter_event, + true, + false, + 'checked_slide_events(this);', + true + ) + ); + + $table->data[] = $data; + $table->rowclass[] = ''; + html_print_table($table); html_print_div( @@ -858,10 +906,19 @@ if ($save_filter_modal) { ?> '; + $output .= '
'; + } + $output .= ' '; + + if ($inline_upload_anchor_to_form !== '') { + $output .= '
'; + $output .= html_print_button( + __('Upload'), + 'upload-icon-btn', + false, + sprintf( + 'javascript:submitForm("%s")', + $inline_upload_anchor_to_form + ), + [ + 'mode' => 'link', + 'style' => 'min-width: initial;', + ], + true, + ); + $output .= '
'; + $output .= '
'; + } + // Add script. $output .= ''; @@ -5374,7 +5409,7 @@ function html_print_link_with_params($text, $params=[], $type='text', $style='', $formStyle = ' style="'.$formStyle.'"'; } - $html = ''; + $html = ''; switch ($type) { case 'image': $html .= html_print_input_image($text, $text, $text, $style, true); @@ -6280,6 +6315,20 @@ function html_print_input($data, $wrapper='div', $input_only=false) ); break; + case 'date_range': + $output .= html_print_select_date_range( + $data['name'], + true, + (isset($data['selected']) === true) ? $data['selected'] : SECONDS_1DAY, + (isset($data['date_init']) === true) ? $data['date_init'] : '', + (isset($data['time_init']) === true) ? $data['time_init'] : '', + (isset($data['date_end']) === true) ? $data['date_end'] : '', + (isset($data['time_end']) === true) ? $data['time_end'] : '', + (isset($data['date_text']) === true) ? $data['date_text'] : SECONDS_1DAY, + (isset($data['class']) === true) ? $data['class'] : 'w100p', + ); + break; + default: // Ignore. break; @@ -6328,7 +6377,7 @@ function html_print_input_multicheck(array $data):string /** - * Print an autocomplete input filled out with Integria IMS users. + * Print an autocomplete input filled out with Pandora ITSM users. * * @param string $name The name of ajax control, by default is "users". * @param string $default The default value to show in the ajax control. @@ -6340,7 +6389,7 @@ function html_print_input_multicheck(array $data):string * * @return mixed If the $return is true, return the output as string. */ -function html_print_autocomplete_users_from_integria( +function html_print_autocomplete_users_from_pandora_itsm( $name='users', $default='', $return=false, @@ -6368,8 +6417,6 @@ function html_print_autocomplete_users_from_integria( $attrs['class'] = $class; } - ui_print_help_tip(__('Type at least two characters to search the user.'), false); - html_print_input_text_extended( $name, $default, @@ -6381,7 +6428,7 @@ function html_print_autocomplete_users_from_integria( '', $attrs ); - html_print_input_hidden($name.'_hidden', $id_agent_module); + html_print_input_hidden($name.'_hidden', $default); $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false, false); ?> @@ -6395,52 +6442,72 @@ function html_print_autocomplete_users_from_integria( } $(document).ready (function () { - $("#text-").autocomplete({ - minLength: 2, - source: function( request, response ) { - var term = request.term; //Word to search - - data_params = { - page: "include/ajax/integria_incidents.ajax", - search_term: term, - get_users: 1, - }; - - jQuery.ajax ({ - data: data_params, - async: false, - type: "POST", - url: action="", - timeout: 10000, - dataType: "json", - success: function (data) { - temp = []; - $.each(data, function (id, module) { - temp.push({ - 'value' : id, - 'label' : module}); - }); - - response(temp); - } - }); - }, - change: function( event, ui ) { - if (!ui.item) - $("input[name='_hidden']") - .val(0); - return false; - }, - select: function( event, ui ) { - $("input[name='_hidden']") - .val(ui.item.value); - - $("#text-").val( ui.item.label ); - return false; + $("#text-").autocomplete({ + minLength: 2, + source: function( request, response ) { + var term = request.term; //Word to search + + var data_params = { + page: "operation/ITSM/itsm", + search_term: term, + method: "getUserSelect", + }; + + jQuery.ajax ({ + data: data_params, + async: false, + type: "POST", + url: action="", + timeout: 10000, + dataType: "json", + success: function (data) { + temp = []; + $.each(data, function (id, module) { + temp.push({ + 'value' : id, + 'label' : module}); + }); + + response(temp); } + }); + }, + change: function( event, ui ) { + if (!ui.item) { + $("input[name='_hidden']") + .val(0); } - ); + return false; + }, + select: function( event, ui ) { + $("input[name='_hidden']") + .val(ui.item.value); + + $("#text-").val( ui.item.label ); + return false; + } }); + + if($("input[name='_hidden']").val() !== ''){ + var data_params_initial = { + page: "operation/ITSM/itsm", + search_term: $("input[name='_hidden']").val(), + method: "getUserSelect", + }; + + jQuery.ajax ({ + data: data_params_initial, + async: false, + type: "POST", + url: action="", + timeout: 10000, + dataType: "json", + success: function (data) { + $("#text-").val(Object.entries(data)[0][1]) + } + }); + } + }); '; @@ -7382,11 +7454,15 @@ function html_print_select_date_range( $('#".$name."_default').hide(); $('#".$name."_extend').hide(); $('#hidden-custom_date').val('1'); + $('.filter_label_position_before').addClass('filter_label_position_after'); } else if ($(this).val() === 'custom') { $('#".$name."_range').hide(); $('#".$name."_default').hide(); $('#".$name."_extend').show(); $('#hidden-custom_date').val('2'); + $('.filter_label_position_before').removeClass('filter_label_position_after'); + } else { + $('.filter_label_position_before').removeClass('filter_label_position_after'); } }); @@ -7395,14 +7471,29 @@ function html_print_select_date_range( }); // To get position must to be showed, hide elements return 0 on offset function. + var def_state_range = $('#".$name."_range').is(':visible'); + var def_state_default = $('#".$name."_default').is(':visible'); + var def_state_extend = $('#".$name."_extend').is(':visible'); $('#".$name."_range').show(); $('#".$name."_default').hide(); $('#".$name."_extend').hide(); position_top_init = $('#text-date_init').offset().top + $('#text-date_init').outerHeight(); position_top_end = $('#text-date_end').offset().top + $('#text-date_end').outerHeight(); - $('#".$name."_range').hide(); - $('#".$name."_extend').hide(); - $('#".$name."_default').show(); + if(def_state_range){ + $('#".$name."_range').show(); + } else { + $('#".$name."_range').hide(); + } + if(def_state_default){ + $('#".$name."_default').show(); + } else { + $('#".$name."_default').hide(); + } + if(def_state_extend){ + $('#".$name."_extend').show(); + } else { + $('#".$name."_extend').hide(); + } }); var position_top_init = 0; @@ -7558,5 +7649,4 @@ function html_print_wizard_diagnosis( } else { echo $output; } - -} \ No newline at end of file +} diff --git a/pandora_console/include/functions_incidents.php b/pandora_console/include/functions_incidents.php deleted file mode 100644 index 5065acc155..0000000000 --- a/pandora_console/include/functions_incidents.php +++ /dev/null @@ -1,477 +0,0 @@ - __('Informative')]).html_print_image('images/dot_green.png', true, ['title' => __('Informative')]).html_print_image('images/dot_yellow.png', true, ['title' => __('Informative')]); - break; - - case 1: - $img = html_print_image('images/dot_green.png', true, ['title' => __('Low')]).html_print_image('images/dot_yellow.png', true, ['title' => __('Low')]).html_print_image('images/dot_yellow.png', true, ['title' => __('Low')]); - break; - - case 2: - $img = html_print_image('images/dot_yellow.png', true, ['title' => __('Medium')]).html_print_image('images/dot_yellow.png', true, ['title' => __('Medium')]).html_print_image('images/dot_red.png', true, ['title' => __('Medium')]); - break; - - case 3: - $img = html_print_image('images/dot_yellow.png', true, ['title' => __('Serious')]).html_print_image('images/dot_red.png', true, ['title' => __('Serious')]).html_print_image('images/dot_red.png', true, ['title' => __('Serious')]); - break; - - case 4: - $img = html_print_image('images/dot_red.png', true, ['title' => __('Very serious')]).html_print_image('images/dot_red.png', true, ['title' => __('Very serious')]).html_print_image('images/dot_red.png', true, ['title' => __('Very serious')]); - break; - - case 10: - $img = html_print_image('images/dot_green.png', true, ['title' => __('Maintenance')]).html_print_image('images/dot_green.png', true, ['title' => __('Maintenance')]).html_print_image('images/dot_green.png', true, ['title' => __('Maintenance')]); - break; - } - - if ($return === false) { - echo $img; - } - - return $img; -} - - -/** - * Gets all the possible status for incidents in an array - * - * @return array The several status with their values - */ -function incidents_get_status() -{ - $fields = []; - $fields[0] = __('Active incidents'); - $fields[1] = __('Active incidents, with comments'); - $fields[2] = __('Rejected incidents'); - $fields[3] = __('Expired incidents'); - $fields[13] = __('Closed incidents'); - - return $fields; -} - - -/** - * Prints the image tag for passed status - * - * @param integer $id_status: Which status to return the image to - * - * @return string The string with the image tag - */ -function incidents_print_status_img($id_status, $return=false) -{ - switch ($id_status) { - case 0: - $img = html_print_image('images/dot_red.png', true, ['title' => __('Active incidents')]); - break; - - case 1: - $img = html_print_image('images/dot_yellow.png', true, ['title' => __('Active incidents, with comments')]); - break; - - case 2: - $img = html_print_image('images/dot_blue.png', true, ['title' => __('Rejected incidents')]); - break; - - case 3: - $img = html_print_image('images/dot_green.png', true, ['title' => __('Expired incidents')]); - break; - - case 13: - $img = html_print_image('images/dot_white.png', true, ['title' => __('Closed incidents')]); - break; - } - - if ($return === false) { - echo $img; - } - - return $img; -} - - -/** - * Updates the last user (either by adding an attachment, note or the incident itself) - * Named after the UNIX touch utility - * - * @param integer $id_incident: A single incident or an array of incidents - * - * @return boolean True if it was done, false if it wasn't - */ -function incidents_process_touch($id_incident) -{ - global $config; - - $id_incident = (array) safe_int($id_incident, 1); - // Make sure we have all positive int's - if (empty($id_incident)) { - return false; - } - - if (empty($id_incident)) { - return false; - } - - return db_process_sql_update('tincidencia', ['id_lastupdate' => $config['id_user']], ['id_incidencia' => $id_incident]); -} - - -/** - * Updates the owner (named after the UNIX utility chown) - * - * @param integer $id_incident: A single incident or an array of incidents - * - * @return boolean True if it was done, false if it wasn't - */ -function incidents_process_chown($id_incident, $owner=false) -{ - if ($owner === false) { - global $config; - $owner = $config['id_user']; - } - - $id_incident = (array) safe_int($id_incident, 1); - // Make sure we have all positive int's - if (empty($id_incident)) { - return false; - } - - $id_incident = implode(',', $id_incident); - $sql = sprintf("UPDATE tincidencia SET id_usuario = '%s' WHERE id_incidencia IN (%s)", $owner, $id_incident); - - return db_process_sql($sql); -} - - -/** - * Get the author of an incident. - * - * @param integer $id_incident Incident id. - * - * @return string The author of an incident - */ -function incidents_get_author($id_incident) -{ - if ($id_incident < 1) { - return ''; - } - - return (string) db_get_value('id_creator', 'tincidencia', 'id_incidencia', (int) $id_incident); -} - - -/** - * Get the owner of an incident. - * - * @param integer $id_incident Incident id. - * - * @return string The last updater of an incident - */ -function incidents_get_owner($id_incident) -{ - if ($id_incident < 1) { - return ''; - } - - return (string) db_get_value('id_usuario', 'tincidencia', 'id_incidencia', (int) $id_incident); -} - - -/** - * Get the last updater of an incident. - * - * @param integer $id_incident Incident id. - * - * @return string The last updater of an incident - */ -function incidents_get_lastupdate($id_incident) -{ - if ($id_incident < 1) { - return ''; - } - - return (string) db_get_value('id_lastupdate', 'tincidencia', 'id_incidencia', (int) $id_incident); -} - - -/** - * Get the group id of an incident. - * - * @param integer $id_incident Incident id. - * - * @return integer The group id of an incident - */ -function incidents_get_group($id_incident) -{ - if ($id_incident < 1) { - return 0; - } - - return (int) db_get_value('id_grupo', 'tincidencia', 'id_incidencia', (int) $id_incident); -} - - -/** - * Delete an incident out the database. - * - * @param mixed $id_inc An int or an array of ints to be deleted - * - * @return boolean True if incident was succesfully deleted, false if not - */ -function incidents_delete_incident($id_incident) -{ - global $config; - $ids = (array) safe_int($id_incident, 1); - // Make the input an array - $notes = []; - $attachments = []; - $errors = 0; - - foreach ($ids as $id_inc) { - // Delete incident - $ret = db_process_sql_delete('tincidencia', ['id_incidencia' => $id_inc]); - if ($ret === false) { - $errors++; - } - - // We only need the ID's - $notes = array_merge($notes, array_keys(incidents_get_notes($id_inc))); - $attachments = array_merge($attachments, array_keys(incidents_get_attach($id_inc))); - - db_pandora_audit( - AUDIT_LOG_INCIDENT_MANAGEMENT, - $config['id_user'].' deleted incident #'.$id_inc - ); - } - - // Delete notes - $note_err = incidents_delete_note($notes, false); - $attach_err = incidents_delete_attach($attachments, false); - - if ($note_err === false || $attach_err === false) { - $errors++; - } - - if ($errors > 0) { - return false; - } - - return true; -} - - -/** - * Delete notes out the database. - * - * @param mixed $id_note An int or an array of ints to be deleted - * @param boolean $transact true if a transaction should be started, false if not - * - * @return boolean True if note was succesfully deleted, false if not - */ -function incidents_delete_note($id_note, $transact=true) -{ - $id_note = (array) safe_int($id_note, 1); - // cast as array - $errors = 0; - - // Delete notes - foreach ($id_note as $id) { - $ret = db_process_sql_delete('tnota', ['id_nota' => $id]); - if ($ret === false) { - $errors++; - } - } - - if ($errors > 0) { - return false; - } else { - return true; - } -} - - -/** - * Delete attachments out the database and from the machine. - * - * @param mixed $id_attach An int or an array of ints to be deleted - * @param boolean $transact true if a transaction should be started, false if not - * - * @return boolean True if attachment was succesfully deleted, false if not - */ -function incidents_delete_attach($id_attach, $transact=true) -{ - global $config; - - $id_attach = (array) safe_int($id_attach, 1); - // cast as array - $errors = 0; - - // Delete attachment - foreach ($id_attach as $id) { - $filename = db_get_value('filename', 'tattachment', 'id_attachment', $id); - - $ret = db_process_sql_delete('tattachment', ['id_attachment' => $id]); - if ($ret === false) { - $errors++; - } - - unlink($config['attachment_store'].'/pand'.$id.'_'.$filename); - } - - if ($errors > 0) { - return false; - } else { - return true; - } -} - - -/** - * Get notes based on the incident id. - * - * @param integer $id_incident An int with the incident id - * - * @return array An array of all the notes for that incident - */ -function incidents_get_notes($id_incident) -{ - $return = db_get_all_rows_field_filter('tnota', 'id_incident', (int) $id_incident); - - if ($return === false) { - $return = []; - } - - $notes = []; - foreach ($return as $row) { - $notes[$row['id_nota']] = $row; - } - - return $notes; -} - - -/** - * Get attachments based on the incident id. - * - * @param integer $id_incident An int with the incident id - * - * @return array An array of all the notes for that incident - */ -function incidents_get_attach($id_incident) -{ - $return = db_get_all_rows_field_filter('tattachment', 'id_incidencia', (int) $id_incident); - - if ($return === false) { - $return = []; - } - - $attach = []; - foreach ($return as $row) { - $attach[$row['id_attachment']] = $row; - } - - return $attach; -} - - -/** - * Get user id of a note. - * - * @param integer $id_note Note id. - * - * @return string User id of the given note. - */ -function incidents_get_notes_author($id_note) -{ - return (string) db_get_value('id_usuario', 'tnota', 'id_nota', (int) $id_note); -} - - -/** - * Interface to Integria API functionality. - * - * @param string $url Url to Integria API with user, password and option (function to use). - * @param string $postparameters Additional parameters to pass. - * - * @return variant The function result called in the API. - */ -function incidents_call_api($url, $postparameters=false) -{ - $curlObj = curl_init(); - curl_setopt($curlObj, CURLOPT_URL, $url); - curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); - if ($postparameters !== false) { - curl_setopt($curlObj, CURLOPT_POSTFIELDS, $postparameters); - } - - $result = curl_exec($curlObj); - curl_close($curlObj); - - return $result; -} - - -/** - * Converts Xml format file to an array datatype. - * - * @param string $xml Xml file to convert. - * - * @return array A Json encoded array with xml content. - */ -function incidents_xml_to_array($xml) -{ - $xmlObj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); - - return json_decode(json_encode($xmlObj), true); -} diff --git a/pandora_console/include/functions_integriaims.php b/pandora_console/include/functions_integriaims.php deleted file mode 100644 index 8fec23e210..0000000000 --- a/pandora_console/include/functions_integriaims.php +++ /dev/null @@ -1,564 +0,0 @@ -'.html_print_image('images/configuration@svg.svg', true, ['title' => __('Configure Integria IMS'), 'class' => 'main_menu_icon invert_filter']).''; - $list_tab['text'] = ''.html_print_image('images/logs@svg.svg', true, ['title' => __('Ticket list'), 'class' => 'main_menu_icon invert_filter']).''; - $create_tab['text'] = ''.html_print_image('images/edit.svg', true, ['title' => __('New ticket'), 'class' => 'main_menu_icon invert_filter']).''; - - switch ($active_tab) { - case 'setup_tab': - $setup_tab['active'] = true; - $list_tab['active'] = false; - $create_tab['active'] = false; - break; - - case 'list_tab': - $setup_tab['active'] = false; - $list_tab['active'] = true; - $create_tab['active'] = false; - break; - - case 'create_tab': - $setup_tab['active'] = false; - $list_tab['active'] = false; - $create_tab['active'] = true; - break; - - default: - $setup_tab['active'] = false; - $list_tab['active'] = false; - $create_tab['active'] = false; - break; - } - - if ($view) { - $create_tab['text'] = ''.html_print_image('images/edit.svg', true, ['title' => __('Edit ticket'), 'class' => 'main_menu_icon invert_filter']).''; - $view_tab['text'] = ''.html_print_image('images/details.svg', true, ['title' => __('View ticket'), 'class' => 'main_menu_icon invert_filter']).''; - // When the current page is the View page. - if (!$active_tab) { - $view_tab['active'] = true; - } - } - - $onheader = []; - $onheader['view'] = $view_tab; - $onheader['configure'] = $setup_tab; - $onheader['list'] = $list_tab; - $onheader['create'] = $create_tab; - - return $onheader; -} - - -/** - * Gets all the details of Integria IMS API - * - * @param string $details Type of API call. - * @param number $detail_index Send index if you want return the text. - * - * @return string or array with result of API call. - */ -function integriaims_get_details($details, $detail_index=false) -{ - global $config; - - switch ($details) { - case 'status': - $operation = 'get_incidents_status'; - break; - - case 'group': - $operation = 'get_groups'; - break; - - case 'priority': - $operation = 'get_incident_priorities'; - break; - - case 'resolution': - $operation = 'get_incidents_resolutions'; - break; - - case 'type': - $operation = 'get_types'; - break; - - default: - // code... - break; - } - - $api_call = integria_api_call(null, null, null, null, $operation); - $result = []; - get_array_from_csv_data_pair($api_call, $result); - - if ($detail_index !== false) { - if ($result[$detail_index] == '' || $result[$detail_index] === null) { - return __('None'); - } else { - return $result[$detail_index]; - } - } else { - return $result; - } -} - - -/** - * Perform an API call to Integria IMS. - * - * @param string|null $api_hostname API host URL. - * @param string|null $user User name. - * @param string|null $user_pass User password. - * @param string|null $api_pass API password. - * @param string|null $operation API Operation. - * @param mixed $params String or array with parameters required by the API function. - * @param mixed $show_credentials_error_msg Show_credentials_error_msg. - * @param mixed $return_type Return_type. - * @param mixed $token Token. - * @param mixed $user_level_conf User_level_conf. - * - * @return boolean True if API request succeeded, false if API request failed. - */ -function integria_api_call( - $api_hostname=null, - $user=null, - $user_pass=null, - $api_pass=null, - $operation=null, - $params='', - $show_credentials_error_msg=false, - $return_type='', - $token='', - $user_level_conf=null -) { - global $config; - - if (is_metaconsole()) { - $servers = metaconsole_get_connection_names(); - foreach ($servers as $key => $server) { - $connection = metaconsole_get_connection($server); - if (metaconsole_connect($connection) != NOERR) { - continue; - } - - $integria_enabled = db_get_sql( - 'SELECT `value` FROM tconfig WHERE `token` = "integria_enabled"' - ); - - if (!$integria_enabled) { - metaconsole_restore_db(); - continue; - } - - // integria_user_level_conf, integria_hostname, integria_api_pass, integria_user, integria_user_level_user, integria_pass, integria_user_level_pass - $config_aux = db_get_all_rows_sql('SELECT `token`, `value` FROM `tconfig` WHERE `token` IN ("integria_user_level_conf", "integria_hostname", "integria_api_pass", "integria_user", "integria_user_level_user", "integria_pass", "integria_user_level_pass")'); - $user_info = users_get_user_by_id($config['id_user']); - foreach ($config_aux as $key => $conf) { - if ($conf['token'] === 'integria_user_level_conf') { - $user_level_conf = $conf['value']; - } - - if ($conf['token'] === 'integria_hostname') { - $api_hostname = $conf['value']; - } - - if ($conf['token'] === 'integria_api_pass') { - $api_pass = $conf['value']; - } - - if ($conf['token'] === 'integria_user') { - $user = $conf['value']; - } - - if ($conf['token'] === 'integria_pass') { - $user_pass = $conf['value']; - } - } - - if ($user_level_conf == true) { - $user = $user_info['integria_user_level_user']; - $user_pass = $user_info['integria_user_level_pass']; - } - - metaconsole_restore_db(); - } - } else { - if ($user_level_conf === null) { - $user_level_conf = (bool) $config['integria_user_level_conf']; - } - - $user_info = users_get_user_by_id($config['id_user']); - - // API access data. - if ($api_hostname === null) { - $api_hostname = $config['integria_hostname']; - } - - if ($api_pass === null) { - $api_pass = $config['integria_api_pass']; - } - - // Integria user and password. - if ($user === null || $user_level_conf === true) { - $user = $config['integria_user']; - - if ($user_level_conf === true) { - $user = $user_info['integria_user_level_user']; - } - } - - if ($user_pass === null || $user_level_conf === true) { - $user_pass = $config['integria_pass']; - - if ($user_level_conf === true) { - $user_pass = $user_info['integria_user_level_pass']; - } - } - } - - if (is_array($params)) { - $params = implode($token, $params); - } - - $url_data = [ - 'user' => $user, - 'user_pass' => $user_pass, - 'pass' => $api_pass, - 'op' => $operation, - 'params' => io_safe_output($params), - ]; - - if ($return_type !== '') { - $url_data['return_type'] = $return_type; - } - - if ($token !== '') { - $url_data['token'] = $token; - } - - // Build URL for API request. - $url = $api_hostname.'/include/api.php'; - - // ob_start(); - // $out = fopen('php://output', 'w'); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $url_data); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_VERBOSE, true); - curl_setopt($ch, CURLOPT_STDERR, $out); - $result = curl_exec($ch); - - // fclose($out); - // $debug = ob_get_clean(); - $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - $error = false; - - if ($result === false) { - $error = curl_error($ch); - } - - curl_close($ch); - - if ($error === true || $http_status !== 200) { - if ($show_credentials_error_msg === true) { - ui_print_error_message(__('API request failed. Please check Integria IMS\' access credentials in Pandora setup.')); - } - - return false; - } else { - return $result; - } -} - - -// Parse CSV consisting of one or more lines of the form key-value pair into an array. -function get_array_from_csv_data_pair($csv_data, &$array_values) -{ - $csv_array = explode("\n", $csv_data); - - foreach ($csv_array as $csv_value) { - if (empty($csv_value)) { - continue; - } - - $new_csv_value = str_getcsv($csv_value); - - $array_values[$new_csv_value[0]] = $new_csv_value[1]; - } -} - - -/** - * Parse CSV consisting of all lines into an array. - * - * @param string $csv_data Data returned of csv api call. - * @param string $array_values Returned array. - * @param array $index Array to create an associative index (opcional). - */ -function get_array_from_csv_data_all($csv_data, &$array_values, $index=false) -{ - $csv_array = explode("\n", $csv_data); - - foreach ($csv_array as $csv_value) { - if (empty($csv_value)) { - continue; - } - - $new_csv_value = str_getcsv($csv_value); - - if ($index !== false) { - foreach ($new_csv_value as $key => $value) { - $new_csv_value_index[$index[$key]] = str_replace(':::', ',', $value); - ; - } - - $array_values[$new_csv_value[0]] = $new_csv_value_index; - } else { - $new_csv_value_comma = array_map( - function ($item) { - return str_replace(':::', ',', $item); - }, - $new_csv_value - ); - $array_values[$new_csv_value[0]] = $new_csv_value_comma; - } - } -} - - -/** - * Print priority for Integria IMS with colors. - * - * @param string $priority value of priority in Integria IMS. - * @param string $priority_label text shown in color box. - * - * @return string HTML code. code to print the color box. - */ -function ui_print_integria_incident_priority($priority, $priority_label) -{ - global $config; - - $output = ''; - switch ($priority) { - case 0: - $color = COL_UNKNOWN; - break; - - case 1: - $color = COL_NORMAL; - break; - - case 10: - $color = COL_NOTINIT; - break; - - case 2: - $color = COL_WARNING; - break; - - case 3: - $color = COL_ALERTFIRED; - break; - - case 4: - $color = COL_CRITICAL; - break; - } - - $output = '
'; - $output .= $priority_label; - $output .= '
'; - - return $output; -} - - -/** - * Get tickets from Integria IMS. - * - * @param array $tickets_filters Filters to send to API. - * - * @return array Tickets returned by API call. - */ -function get_tickets_integriaims($tickets_filters) -{ - global $config; - - // Filters. - $incident_text = $tickets_filters['incident_text']; - $incident_status = $tickets_filters['incident_status']; - $incident_group = $tickets_filters['incident_group']; - $incident_owner = $tickets_filters['incident_owner']; - $incident_creator = $tickets_filters['incident_creator']; - $incident_priority = $tickets_filters['incident_priority']; - $incident_resolution = $tickets_filters['incident_resolution']; - $created_from = $tickets_filters['created_from']; - $created_to = $tickets_filters['created_to']; - - // API call. - $result_api_call_list = integria_api_call( - null, - null, - null, - null, - 'get_incidents', - [ - $incident_text, - $incident_status, - $incident_group, - $incident_priority, - '0', - $incident_owner, - $incident_creator, - ], - false, - '', - ',' - ); - - // Return array of api call 'get_incidents'. - $array_get_incidents = []; - get_array_from_csv_data_all($result_api_call_list, $array_get_incidents); - - // Modify $array_get_incidents if filter for resolution exists. - $filter_resolution = []; - foreach ($array_get_incidents as $key => $value) { - if ($incident_resolution !== '' && ($array_get_incidents[$key][12] == $incident_resolution)) { - $filter_resolution[$key] = $array_get_incidents[$key]; - continue; - } - } - - if ($incident_resolution !== '') { - $array_get_incidents = $filter_resolution; - } - - // Modify $array_get_incidents if filter for date is selected. - if ($created_from !== '' && $created_to !== '') { - $date = []; - $date_utimestamp = []; - foreach ($array_get_incidents as $key => $value) { - // Change format date / to -. - $date[$key] = date('Y-m-d', strtotime($array_get_incidents[$key][9])); - // Covert date to utimestamp. - $date_utimestamp[$key] = strtotime($date[$key]); - } - - // Change format date / to -. - $created_from_date = date('Y-m-d', strtotime($created_from)); - $created_to_date = date('Y-m-d', strtotime($created_to)); - - // Covert date to utimestamp. - $created_from_timestamp = strtotime($created_from_date); - $created_to_timestamp = strtotime($created_to_date); - - // Dates within the selected period. - $selected_period = array_filter( - $date_utimestamp, - function ($value) use ($created_from_timestamp, $created_to_timestamp) { - return ($value >= $created_from_timestamp && $value <= $created_to_timestamp); - } - ); - - // Return incidents with the correct dates. - $filter_date = []; - foreach ($array_get_incidents as $key => $value) { - foreach ($selected_period as $index => $value) { - if ($array_get_incidents[$key][0] == $index) { - $filter_date[$key] = $array_get_incidents[$key]; - continue; - } - } - } - - $array_get_incidents = $filter_date; - } - - return $array_get_incidents; -} - - -function integriaims_upload_file($filename, $incident_id, $file_description) -{ - if ($_FILES[$filename]['name'] != '') { - $filename = io_safe_input($_FILES[$filename]['name']); - $filesize = io_safe_input($_FILES[$filename]['size']); - - $extension = pathinfo($filename, PATHINFO_EXTENSION); - $invalid_extensions = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| - pif|vb|vbscript|wsf|asp|cer|csr|jsp|drv|sys|ade|adp|bas|chm|cpl|crt|csh|fxp|hlp|hta|inf|ins|isp|jse|htaccess| - htpasswd|ksh|lnk|mdb|mde|mdt|mdw|msc|msi|msp|mst|ops|pcd|prg|reg|scr|sct|shb|shs|url|vbe|vbs|wsc|wsf|wsh)$/i'; - - if (!preg_match($invalid_extensions, $extension)) { - // The following is if you have clamavlib installed. - // (php5-clamavlib) and enabled in php.ini - // http://www.howtoforge.com/scan_viruses_with_php_clamavlib - if (extension_loaded('clamav')) { - cl_setlimits(5, 1000, 200, 0, 10485760); - $malware = cl_scanfile($_FILES['file']['tmp_name']); - if ($malware) { - $error = 'Malware detected: '.$malware.'
ClamAV version: '.clam_get_version(); - die($error); - } - } - - $filecontent = base64_encode(file_get_contents($_FILES[$filename]['tmp_name'])); - - $result_api_call = integria_api_call(null, null, null, null, 'attach_file', [$incident_id, $filename, $filesize, $file_description, $filecontent], false, '', '|;|'); - - // API method returns '0' string if success. - $file_added = ($result_api_call === '0') ? true : false; - - ui_print_result_message( - $file_added, - __('File successfully added'), - __('File could not be added') - ); - } else { - ui_print_error_message(__('File has an invalid extension')); - } - } -} diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index a1927bb60a..346dee04b5 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -147,6 +147,12 @@ function menu_print_menu(&$menu) || $sec2 === 'enterprise/godmode/servers/manage_credential_boxes' ) { $sec2 = 'enterprise/godmode/servers/list_satellite'; + } else if ($sec2 === 'operation/ITSM/itsm') { + $sec2 = (string) get_parameter('sec2'); + $operation = (string) get_parameter('operation', ''); + if (empty($operation) === false) { + $sec2 = $sec2.'&operation='.$operation; + } } else { $sec2 = (string) get_parameter('sec2'); } @@ -287,7 +293,7 @@ function menu_print_menu(&$menu) } } - // Set class. + // Set class.; if (($sec2 == $subsec2 || $allsec2 == $subsec2 || $selected_submenu2) && isset($sub[$subsec2]['options']) && (get_parameter_get($sub[$subsec2]['options']['name']) == $sub[$subsec2]['options']['value']) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index fe47857e33..de618605c8 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -701,6 +701,7 @@ function modules_update_agent_module( } // Disable action requires a special function + $result = false; if (isset($values['disabled'])) { $result_disable = modules_change_disabled($id, $values['disabled']); @@ -709,7 +710,9 @@ function modules_update_agent_module( $result_disable = true; } - $result = @db_process_sql_update('tagente_modulo', $values, $where); + if (empty($values) === false) { + $result = @db_process_sql_update('tagente_modulo', $values, $where); + } if ($result == false) { if ($result_disable === ERR_GENERIC) { @@ -4759,3 +4762,31 @@ function export_agents_module_csv($filters) return $result; } + + +/** + * Check if modules are compatible with MADE server. + * + * @param integer $id_tipo_modulo + * @retur boolean True if compatible, false otherwise. + */ +function modules_made_compatible($id_tipo_modulo) +{ + $compatible_types = [ + 1, + 4, + 5, + 8, + 15, + 16, + 22, + 30, + 34, + ]; + + if (array_search($id_tipo_modulo, $compatible_types) === false) { + return false; + } else { + return true; + } +} diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 79fcd9a0db..bc8495969f 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -498,7 +498,7 @@ function netflow_get_top_N( $options = '-o "fmt:%sap,%dap,%ibyt,%bps" -q -n '.$max.' -s record/bytes -t '.date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); - $command = netflow_get_command($options, $filter); + $command = netflow_get_command($options, $filter, $start_date, $end_date); // Execute nfdump. exec($command, $lines); @@ -656,7 +656,10 @@ function netflow_get_data( $aggregate, $max, $absolute, - $connection_name + $connection_name, + false, + $start_date, + $end_date ); foreach ($data as $line) { @@ -734,6 +737,8 @@ function netflow_get_data( * to get troughput. * @param string $connection_name Node name when data is get in meta. * @param boolean $address_resolution True to resolve ips to hostnames. + * @param integer $start_date_fixed Start date for use in command netflow. + * @param integer $end_date_fixed End date for use in command netflow. * * @return array With netflow stats. */ @@ -745,7 +750,9 @@ function netflow_get_stats( $max, $absolute=true, $connection_name='', - $address_resolution=false + $address_resolution=false, + $start_date_fixed=0, + $end_date_fixed=0, ) { global $config, $nfdump_date_format; @@ -757,8 +764,7 @@ function netflow_get_stats( // Get the command to call nfdump. $options = "-o csv -q -n $max -s $aggregate/bytes -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); - $command = netflow_get_command($options, $filter); - + $command = netflow_get_command($options, $filter, $start_date_fixed, $end_date_fixed); // Execute nfdump. exec($command, $string); @@ -845,7 +851,7 @@ function netflow_get_summary($start_date, $end_date, $filter, $connection_name=' // Get the command to call nfdump. $options = '-o csv -n 1 -s srcip/bytes -t '.date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); - $command = netflow_get_command($options, $filter); + $command = netflow_get_command($options, $filter, $start_date, $end_date); // Execute nfdump. exec($command, $string); @@ -916,7 +922,7 @@ function netflow_get_relationships_raw_data( // Get the command to call nfdump. $options = ' -q -o csv -n 10000 -s record/bytes -t '.date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); - $command = netflow_get_command($options, $filter); + $command = netflow_get_command($options, $filter, $start_date, $end_date); // Execute nfdump. // $command .= ' -q -o csv -n 10000 -s record/bytes -t '.date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); @@ -1018,7 +1024,7 @@ function netflow_parse_relationships_for_circular_mesh( * * @return string Command to run. */ -function netflow_get_command($options, $filter) +function netflow_get_command($options, $filter, $date_init=0, $date_end=0) { global $config; @@ -1030,14 +1036,46 @@ function netflow_get_command($options, $filter) && isset($config['netflow_name_dir']) && $config['netflow_name_dir'] !== '' && isset($config['general_network_path']) && $config['general_network_path'] !== '' ) { - $command .= ' -R. -M '.$config['general_network_path'].$config['netflow_name_dir'].':'.$config['sflow_name_dir']; + if ($date_init > 0 && $date_end > 0) { + $path = $config['general_network_path'].$config['sflow_name_dir']; + $range_time = find_range_files_time($path, $date_init, $date_end); + if ($range_time[0] === 0 && $range_time[1] === 0) { + $interval_files_sflow = $path; + } else { + $interval_files_sflow = $path.'/'.$range_time[0].':'.$range_time[1]; + } + + $path = $config['general_network_path'].$config['netflow_name_dir']; + $range_time = find_range_files_time($path, $date_init, $date_end); + if ($range_time[0] === 0 && $range_time[1] === 0) { + $interval_files_netflow = $path; + } else { + $interval_files_netflow = $path.'/'.$range_time[0].':'.$range_time[1]; + } + + $command .= ' -R '.$interval_files_sflow.' -R '.$interval_files_netflow; + } else { + $command .= ' -R. -M '.$config['general_network_path'].$config['netflow_name_dir'].':'.$config['sflow_name_dir']; + } } } else { if ($config['activate_sflow']) { if (isset($config['sflow_name_dir']) && $config['sflow_name_dir'] !== '' && isset($config['general_network_path']) && $config['general_network_path'] !== '' ) { - $command .= ' -R. -M '.$config['general_network_path'].$config['sflow_name_dir']; + if ($date_init > 0 && $date_end > 0) { + $path = $config['general_network_path'].$config['sflow_name_dir']; + $range_time = find_range_files_time($path, $date_init, $date_end); + if ($range_time[0] === 0 && $range_time[1] === 0) { + $interval_files = '.'; + } else { + $interval_files = $range_time[0].':'.$range_time[1]; + } + } else { + $interval_files = '.'; + } + + $command .= ' -R '.$interval_files.' -M '.$config['general_network_path'].$config['sflow_name_dir']; } } @@ -1045,7 +1083,19 @@ function netflow_get_command($options, $filter) if (isset($config['netflow_name_dir']) && $config['netflow_name_dir'] !== '' && isset($config['general_network_path']) && $config['general_network_path'] !== '' ) { - $command .= ' -R. -M '.$config['general_network_path'].$config['netflow_name_dir']; + if ($date_init > 0 && $date_end > 0) { + $path = $config['general_network_path'].$config['netflow_name_dir']; + $range_time = find_range_files_time($path, $date_init, $date_end); + if ($range_time[0] === 0 && $range_time[1] === 0) { + $interval_files = '.'; + } else { + $interval_files = $range_time[0].':'.$range_time[1]; + } + } else { + $interval_files = '.'; + } + + $command .= ' -R '.$interval_files.' -M '.$config['general_network_path'].$config['netflow_name_dir']; } } } @@ -1059,6 +1109,62 @@ function netflow_get_command($options, $filter) } +/** + * Find the two files closest to the time range. + * + * @param string $folder Folder of netflow. + * @param integer $date_init Time init for range. + * @param integer $date_end Time end for range. + * + * @return array + */ +function find_range_files_time($folder, $date_init, $date_end) +{ + $closest_init = 0; + $closest_end = 0; + $closest_init_date = 0; + $closest_end_date = 0; + $min_diff_init = PHP_INT_MAX; + $min_diff_end = PHP_INT_MAX; + $files = scandir($folder); + if ($date_init > 0) { + foreach ($files as $file) { + if (preg_match('/^nfcapd\.(\d{12})$/', $file, $matches)) { + $file_date = $matches[1]; + + $file_date = strtotime(substr($file_date, 0, 4).'-'.substr($file_date, 4, 2).'-'.substr($file_date, 6, 2).' '.substr($file_date, 8, 2).':'.substr($file_date, 10, 2)); + $diff_init = abs($file_date - $date_init); + if ($diff_init < $min_diff_init) { + $closest_init_date = $file_date; + $min_diff_init = $diff_init; + $closest_init = $file; + } + + $diff_end = abs($file_date - $date_end); + if ($diff_end < $min_diff_end) { + $closest_end_date = $file_date; + $min_diff_end = $diff_end; + $closest_end = $file; + } + } + } + } + + if ($closest_end_date < $date_init || $closest_init_date > $date_end) { + return [ + 0, + 0, + ]; + } else { + return [ + $closest_init, + $closest_end, + ]; + } + +} + + /** * Returns the nfdump command line arguments that match the given filter. * @@ -1336,7 +1442,9 @@ function netflow_draw_item( $max_aggregates, true, $connection_name, - $address_resolution + $address_resolution, + $start_date, + $end_date ); if (empty($data_pie) === true) { @@ -1451,7 +1559,9 @@ function netflow_draw_item( $max_aggregates, true, $connection_name, - $address_resolution + $address_resolution, + $start_date, + $end_date ); if (empty($data_stats) === false) { @@ -1572,7 +1682,9 @@ function netflow_get_item_data( $aggregate, $max_aggregates, true, - $connection_name + $connection_name, + $start_date, + $end_date ); $data = [ @@ -1801,7 +1913,7 @@ function netflow_get_top_summary( } $options = "-q -o csv -n $max -s $sort/$order_text -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); - $command = netflow_get_command($options, $netflow_filter); + $command = netflow_get_command($options, $netflow_filter, $start_date, $end_date); exec($command, $result); if (! is_array($result)) { @@ -1962,7 +2074,7 @@ function netflow_get_top_data( date($nfdump_date_format, $start_date), date($nfdump_date_format, $end_date) ); - $agg_command = netflow_get_command($options, $filter); + $agg_command = netflow_get_command($options, $filter, $start_date, $end_date); // Call nfdump. exec($agg_command, $string); diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 5fa9ec2a8d..f5115a73e9 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -4466,7 +4466,7 @@ function networkmap_get_new_nodes_and_links($networkmap, $x, $y) 'id_child' => $child_node, 'id_parent_source_data' => $parent, 'id_child_source_data' => $node['source_data'], - 'parent_type' => 0, + 'parent_type' => 2, 'child_type' => 0, ] ); diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 60a8e6bce0..b9393ce1c4 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -635,6 +635,12 @@ function notifications_get_user_label_status($source, $user, $label) array_keys(users_get_groups($user)), array_keys(notifications_get_group_sources_for_select($source['id'])) ); + + // Clean default common groups error for mesagges. + if ($common_groups[0] === 0) { + unset($common_groups[0]); + } + // No group found, return no permissions. $value = empty($common_groups) ? false : $source[$label]; return notifications_build_user_enable_return($value, false); @@ -760,9 +766,10 @@ function notifications_print_global_source_configuration($source) } // Generate the title. - $html_title = "
"; + $html_title = '

'.$source['description'].'

'; + $html_title .= "
"; $html_title .= html_print_switch($switch_values); - $html_title .= '

'.$source['description'].'

'; + $html_title .= '

'.__('Enable user configuration').'

'; $html_title .= '
'; // Generate the html for title. diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index c01e44157a..39f1642fa0 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -149,6 +149,26 @@ function reporting_get_name($id_report) } +/** + * Frees memory in case of fatal error. + * + * @param mixed $memory Object that reserves memory. + * + * @return void + */ +function shutdown($memory) +{ + // Unsetting $memory does not free up memory. + // I also tried unsetting a global variable which did not free up the memory. + unset($memory->reserve); + + $error = error_get_last(); + if (isset($error['type']) === true && $error['type'] === 1) { + echo __('You have no memory for this operation, increase the memory limit.'); + } +} + + function reporting_make_reporting_data( $report, $id_report, @@ -159,7 +179,10 @@ function reporting_make_reporting_data( $force_width_chart=null, $force_height_chart=null, $pdf=false, - $from_template=false + $from_template=false, + $filter_type='', + $custom_date_end='', + $custom_period=false ) { global $config; @@ -167,6 +190,11 @@ function reporting_make_reporting_data( enterprise_include_once('include/functions_metaconsole.php'); + $memory = new stdClass(); + // Reserve 3 mega bytes. + $memory->reserve = str_repeat('*', (1024 * 1024)); + register_shutdown_function('shutdown', $memory); + $return = []; if (!empty($report)) { $contents = io_safe_output($report['contents']); @@ -194,8 +222,7 @@ function reporting_make_reporting_data( if (empty($contents)) { return reporting_check_structure_report($report); - } - + }; $metaconsole_on = is_metaconsole(); $index_content = 0; @@ -562,7 +589,10 @@ function reporting_make_reporting_data( $type, $force_width_chart, $force_height_chart, - $pdf + $pdf, + $filter_type, + $custom_date_end, + $custom_period ); break; @@ -773,6 +803,13 @@ function reporting_make_reporting_data( ); break; + case 'end_of_life': + $report['contents'][] = reporting_end_of_life( + $report, + $content + ); + break; + case 'alert_report_actions': $report['contents'][] = reporting_alert_report_actions( $report, @@ -935,6 +972,57 @@ function reporting_make_reporting_data( ); break; + case 'top_n_agents_sh': + $report['contents'][] = reporting_top_n_agents_sh( + $report, + $content + ); + break; + + case 'top_n_checks_failed': + $report['contents'][] = reporting_top_n_checks_failed( + $report, + $content + ); + break; + + case 'top_n_categories_checks': + $report['contents'][] = reporting_top_n_categories_checks( + $report, + $content + ); + break; + + case 'vul_by_cat': + $report['contents'][] = reporting_vul_by_categories( + $report, + $content, + $type + ); + break; + + case 'list_checks': + $report['contents'][] = reporting_list_checks( + $report, + $content + ); + break; + + case 'scoring': + $report['contents'][] = reporting_scoring( + $report, + $content + ); + break; + + case 'evolution': + $report['contents'][] = reporting_evolution_hardening( + $report, + $content, + $type + ); + break; + default: // Default. break; @@ -3562,6 +3650,112 @@ function reporting_agent_module_status($report, $content) } +/** + * OS Version End of Life + * + * @param array $report Info Report. + * @param array $content Info content. + * + * @return array + */ +function reporting_end_of_life($report, $content) +{ + global $config; + + $return['type'] = 'end_of_life'; + + if (empty($content['name'])) { + $content['name'] = __('End of life'); + } + + $return['title'] = io_safe_output($content['name']); + $return['landscape'] = $content['landscape']; + $return['pagebreak'] = $content['pagebreak']; + $return['subtitle'] = __('End of life report'); + $return['description'] = io_safe_output($content['description']); + $return['date'] = reporting_get_date_text($report, $content); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + + $return['data'] = []; + + $external_source = json_decode( + $content['external_source'], + true + ); + + $servers_ids = [0]; + + if (is_metaconsole() === true) { + $servers_ids = array_column(metaconsole_get_servers(), 'id'); + } + + foreach ($servers_ids as $server_id) { + if (is_metaconsole() === true) { + $connection = metaconsole_get_connection_by_id($server_id); + if (metaconsole_connect($connection) != NOERR) { + continue; + } + } + + $agents = agents_get_agents( + [], + [ + 'alias', + 'direccion', + 'name', + 'os_version', + ], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + true + ); + + $es_os_version = $external_source['os_version']; + + $es_limit_eol_datetime = DateTime::createFromFormat('Y/m/d', $external_source['end_of_life_date']); + + // Post-process returned agents to filter agents using correctly formatted fields. + foreach ($agents as $idx => $agent) { + // Must perform this query and subsequent operations in each iteration (note this is costly) since OS version field may contain HTML entities in BD and decoding can't be fully handled with mysql methods when doing a REGEXP. + $result_end_of_life = db_get_value_sql('SELECT end_of_support FROM tconfig_os_version WHERE "'.io_safe_output($agent['os_version']).'" REGEXP version AND "'.io_safe_output($agent['name']).'" REGEXP product'); + $agent_eol_datetime = DateTime::createFromFormat('Y/m/d', $result_end_of_life); + + if ((preg_match('/'.$es_os_version.'/i', $agent['os_version']) || $es_os_version === '') && $result_end_of_life !== false && ($es_limit_eol_datetime === false || $es_limit_eol_datetime >= $agent_eol_datetime)) { + // Agent matches an existing OS version. + $agents[$idx]['end_of_life'] = $result_end_of_life; + } else { + // Set agent to be filtered out. + $agents[$idx] = null; + } + } + + if ($agents !== false) { + $agents = array_filter($agents); + } + + if (is_metaconsole() === true) { + $res[$connection['server_name']] = $agents; + + metaconsole_restore_db(); + } + } + + if (is_metaconsole() === true) { + $return['data'] = $res; + } else { + $return['data'] = $agents; + } + + return reporting_check_structure_content($return); +} + + function reporting_exception( $report, $content, @@ -6804,7 +6998,10 @@ function reporting_projection_graph( $type='dinamic', $force_width_chart=null, $force_height_chart=null, - $pdf=false + $pdf=false, + $filter_type='', + $custom_date_end='', + $custom_period=false ) { global $config; @@ -6870,6 +7067,7 @@ function reporting_projection_graph( $return['agent_name_db'] = $agent_name_db; $return['agent_name'] = $agent_name; $return['module_name'] = $module_name; + $return['datetime'] = $report['datetime']; set_time_limit(500); @@ -6890,8 +7088,24 @@ function reporting_projection_graph( 'return_img_base_64' => true, ]; + $top_n_value = $content['top_n_value']; + if ($filter_type === 'this_week') { + $current_date = date('Y/m/d H:i:s'); + $monday = date('Y/m/d H:i:s', strtotime('last monday')); + $sunday = date('Y/m/d H:i:s', strtotime($monday.' +6 days')); + $top_n_value = (strtotime($sunday) - strtotime($current_date)); + } else if ($filter_type === 'this_month') { + $current_date = date('Y/m/d H:i:s'); + $last_of_month = date('Y/m/d', strtotime('last day of this month')); + $top_n_value = (strtotime($last_of_month) - strtotime($current_date)); + } else if ($filter_type === 'chose_range') { + $current_date = date('Y/m/d H:i:s'); + $top_n_value = (strtotime($custom_date_end) - strtotime($current_date)); + } + $params_combined = [ - 'projection' => $content['top_n_value'], + 'projection' => $top_n_value, + 'custom_period' => $custom_period, ]; if ($pdf === true) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index eb7c555fb9..99f3af63ad 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -26,6 +26,7 @@ * GNU General Public License for more details. * ============================================================================ */ +use PandoraFMS\Enterprise\Metaconsole\Node; require_once $config['homedir'].'/include/functions.php'; require_once $config['homedir'].'/include/functions_db.php'; @@ -119,10 +120,15 @@ function reporting_html_header( } -function html_do_report_info($report) +function html_do_report_info($report, $custom_date_end=false, $custom_period=false) { global $config; + if ($custom_period !== false && $custom_date_end !== false) { + $report['datetime'] = strtotime($custom_date_end); + $report['period'] = $custom_period; + } + if ($config['style'] === 'pandora_black' && !is_metaconsole()) { $background_color = '#222'; } else { @@ -170,10 +176,10 @@ function html_do_report_info($report) * * @return array */ -function reporting_html_print_report($report, $mini=false, $report_info=1) +function reporting_html_print_report($report, $mini=false, $report_info=1, $custom_date_end=false, $custom_period=false) { if ($report_info == 1) { - html_do_report_info($report); + html_do_report_info($report, $custom_date_end, $custom_period); } foreach ($report['contents'] as $key => $item) { @@ -226,6 +232,12 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) $label = ''; } + if ($custom_date_end !== false) { + $to = strtotime($custom_date_end); + } else { + $to = $item['date']['to']; + } + reporting_html_header( $table, $mini, @@ -234,7 +246,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) $item['date']['period'], $item['date']['date'], $item['date']['from'], - $item['date']['to'], + $to, $label ); @@ -391,6 +403,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) reporting_html_agent_module_status($table, $item); break; + case 'end_of_life': + reporting_html_end_of_life($table, $item); + break; + case 'alert_report_actions': reporting_html_alert_report_actions($table, $item); break; @@ -463,6 +479,34 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) case 'ncm': reporting_html_ncm_config($table, $item); break; + + case 'top_n_agents_sh': + reporting_html_top_n_agents_sh($table, $item); + break; + + case 'top_n_checks_failed': + reporting_html_top_n_checks_failed($table, $item); + break; + + case 'top_n_categories_checks': + reporting_html_top_n_categories_checks($table, $item); + break; + + case 'vul_by_cat': + reporting_vul_by_cat_graph($table, $item); + break; + + case 'list_checks': + reporting_html_list_checks($table, $item); + break; + + case 'scoring': + reporting_html_scoring($table, $item); + break; + + case 'evolution': + reporting_evolution_graph($table, $item); + break; } if ($item['type'] == 'agent_module') { @@ -478,6 +522,280 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) } +/** + * Function to print the security hardening evolution. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * + * @return void + */ +function reporting_evolution_graph($table, $item) +{ + $table->rowclass[0] = ''; + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + + +/** + * Function to print the agents scoring. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param boolean $pdf If it comes from pdf. + * + * @return string + */ +function reporting_html_scoring($table, $item, $pdf=0) +{ + global $config; + + $table->width = '99%'; + $table->styleTable = 'border: 0px;'; + $table->colspan[2][0] = 3; + $table1 = new stdClass(); + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[1] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->width = '99%'; + $table1->class = 'info_table'; + $table1->titleclass = 'title_table_pdf'; + $table1->rowclass[0] = ''; + $table1->head[0] = ''.__('Date').''; + $table1->head[1] = ''.__('Agent').''; + $table1->head[2] = ''.__('Score').''; + + $row = 1; + foreach ($item['data'] as $key => $check) { + $table1->data[$row][1] = date($config['date_format'], $check['date']); + $table1->data[$row][2] = $check['agent']; + $table1->data[$row][3] = $check['scoring'].' %'; + $row++; + } + + if ($pdf === 1) { + $table1->title = $item['title']; + $table1->titleclass = 'title_table_pdf'; + $table1->titlestyle = 'text-align:left;'; + } + + $table->data[2][0] = html_print_table($table1, true); + + if ($pdf === 1) { + return html_print_table($table1, true); + } +} + + +/** + * Function to print HTML checks filtered by agent and category. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param boolean $pdf If it comes from pdf. + * + * @return string + */ +function reporting_html_list_checks($table, $item, $pdf=0) +{ + $table->width = '99%'; + $table->styleTable = 'border: 0px;'; + $table->colspan[2][0] = 4; + $table1 = new stdClass(); + $table1->width = '99%'; + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[1] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->class = 'info_table'; + $table1->titleclass = 'title_table_pdf'; + $table1->rowclass[0] = ''; + $table1->head[0] = ''.__('Id').''; + $table1->head[1] = ''.__('Title').''; + $table1->head[2] = ''.__('Category').''; + $table1->head[3] = ''.__('Status').''; + + $row = 2; + foreach ($item['data'] as $key => $check) { + $table1->data[$row][0] = $check['id']; + $table1->data[$row][1] = $check['title']; + $table1->data[$row][2] = $check['category']; + $table1->data[$row][3] = $check['status']; + $row++; + } + + if ($pdf === 1) { + $table1->title = $item['title']; + $table1->titleclass = 'title_table_pdf'; + $table1->titlestyle = 'text-align:left;'; + } + + $table->data[2][0] = html_print_table($table1, true); + if ($pdf === 1) { + return html_print_table($table1, true); + } +} + + +/** + * Function to print HTML top checks failed by category + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param boolean $pdf If it comes from pdf. + * + * @return string + */ +function reporting_html_top_n_categories_checks($table, $item, $pdf=0) +{ + $table->width = '99%'; + $table->styleTable = 'border: 0px;'; + $table->colspan[2][0] = 3; + $table1 = new stdClass(); + $table1->width = '99%'; + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[1] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->class = 'info_table'; + $table1->titleclass = 'title_table_pdf'; + $table1->rowclass[0] = ''; + $table1->head[0] = ''.__('Id').''; + $table1->head[1] = ''.__('Category').''; + $table1->head[2] = ''.__('Total Failed').''; + + $row = 2; + foreach ($item['data'] as $key => $check) { + $table1->data[$row][0] = $check['id']; + $table1->data[$row][1] = $check['category']; + $table1->data[$row][2] = $check['total']; + $row++; + } + + if ($pdf === 1) { + $table1->title = $item['title']; + $table1->titleclass = 'title_table_pdf'; + $table1->titlestyle = 'text-align:left;'; + } + + $table->data[2][0] = html_print_table($table1, true); + if ($pdf === 1) { + return html_print_table($table1, true); + } +} + + +/** + * Function to print HTML top checks failed. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param boolean $pdf If it comes from pdf. + * + * @return string + */ +function reporting_html_top_n_checks_failed($table, $item, $pdf=0) +{ + $table->width = '99%'; + $table->styleTable = 'border: 0px;'; + $table->colspan[2][0] = 3; + $table1 = new stdClass(); + $table1->width = '99%'; + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->class = 'info_table'; + $table1->titleclass = 'title_table_pdf'; + $table1->headstyle[1] = 'width: 10%; text-align: center;'; + $table1->style[2] = 'text-align: center;'; + $table1->rowclass[0] = ''; + $table1->head[0] = ''.__('Title').''; + $table1->head[1] = ''.__('Total Failed').''; + $table1->head[2] = ''.__('Description').''; + + $row = 2; + foreach ($item['data'] as $key => $check) { + $table1->data[$row][1] = $check['title']; + $table1->data[$row][2] = $check['total']; + $table1->data[$row][3] = $check['description']; + $row++; + } + + if ($pdf === 1) { + $table1->title = $item['title']; + $table1->titleclass = 'title_table_pdf'; + $table1->titlestyle = 'text-align:left;'; + } + + $table->data[2][0] = html_print_table($table1, true); + if ($pdf === 1) { + return html_print_table($table1, true); + } +} + + +/** + * Function to print HTML top categories in graph. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * + * @return void + */ +function reporting_vul_by_cat_graph($table, $item) +{ + $table->rowclass[0] = ''; + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + + +/** + * Function to print HTML top n agents from security hardening. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param boolean $pdf If it comes from pdf. + * + * @return string + */ +function reporting_html_top_n_agents_sh($table, $item, $pdf=0) +{ + global $config; + $table->width = '99%'; + $table->styleTable = 'border: 0px;'; + $table->colspan[2][0] = 3; + $table1 = new stdClass(); + $table1->headstyle = []; + $table1->width = '99%'; + $table1->class = 'info_table'; + $table1->titleclass = 'title_table_pdf'; + $table1->rowclass[0] = ''; + $table1->head[0] = ''.__('Agent').''; + $table1->head[1] = ''.__('Last audit scan').''; + $table1->head[2] = ''.__('Score').''; + + $row = 2; + foreach ($item['data'] as $key => $agent) { + $table1->data[$row][0] = $agent['alias']; + $table1->data[$row][1] = date($config['date_format'], $agent['utimestamp']); + $table1->data[$row][2] = $agent['datos'].' %'; + $row++; + } + + if ($pdf === 1) { + $table1->title = $item['title']; + $table1->titleclass = 'title_table_pdf'; + $table1->titlestyle = 'text-align:left;'; + } + + $table->data[2][0] = html_print_table($table1, true); + if ($pdf === 1) { + return html_print_table($table, true); + } +} + + /** * Function to print to HTML SLA report. * @@ -2440,6 +2758,123 @@ function reporting_html_agent_module_status($table, $item, $pdf=0) } +/** + * Html report end of life. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param integer $pdf Pdf output. + * + * @return mixed + */ +function reporting_html_end_of_life($table, $item, $pdf=0) +{ + global $config; + + $return_pdf = ''; + + if (empty($item['data']) === true) { + if ($pdf !== 0) { + $return_pdf .= __('No items'); + } else { + $table->colspan['group_report']['cell'] = 3; + $table->cellstyle['group_report']['cell'] = 'text-align: center;'; + $table->data['group_report']['cell'] = __('No items'); + } + } else { + $table_info = new stdClass(); + $table_info->width = '99%'; + + $table_info->align = []; + + if (is_metaconsole() === true) { + $table_info->align['server'] = 'left'; + } + + $table_info->align['agent_alias'] = 'left'; + $table_info->align['ip'] = 'left'; + $table_info->align['os_type'] = 'left'; + $table_info->align['os_version'] = 'left'; + $table_info->align['end_of_life'] = 'left'; + + $table_info->headstyle = []; + + if (is_metaconsole() === true) { + $table_info->headstyle['server'] = 'text-align: left'; + } + + $table_info->headstyle['agent_alias'] = 'text-align: left'; + $table_info->headstyle['ip'] = 'text-align: left'; + $table_info->headstyle['os_type'] = 'text-align: left'; + $table_info->headstyle['os_version'] = 'text-align: left'; + $table_info->headstyle['end_of_life'] = 'text-align: left'; + + $table_info->head = []; + if (is_metaconsole() === true) { + $table_info->head['server'] = __('Server'); + } + + $table_info->head['agent_alias'] = __('Agent alias'); + $table_info->head['ip'] = __('IP'); + $table_info->head['os_type'] = __('OS Type'); + $table_info->head['os_version'] = __('OS Version'); + $table_info->head['end_of_life'] = __('End of life'); + + $table_info->data = []; + + if (is_metaconsole() === true) { + foreach ($item['data'] as $server_name => $agents_per_server) { + foreach ($agents_per_server as $agent) { + $row = []; + + $row['server'] = $server_name; + $row['agent_alias'] = $agent['alias']; + $row['ip'] = $agent['direccion']; + $row['os_type'] = $agent['name']; + $row['os_version'] = $agent['os_version']; + $date_string = date_w_fixed_tz($agent['end_of_life']); + $timestamp = strtotime($date_string); + $date_without_time = date('F j, Y', $timestamp); + $row['end_of_life'] = $date_without_time; + + $table_info->data[] = $row; + } + } + } else { + foreach ($item['data'] as $data) { + $row = []; + + $row['agent_alias'] = $data['alias']; + $row['ip'] = $data['direccion']; + $row['os_type'] = $data['name']; + $row['os_version'] = $data['os_version']; + $date_string = date_w_fixed_tz($data['end_of_life']); + $timestamp = strtotime($date_string); + $date_without_time = date('F j, Y', $timestamp); + $row['end_of_life'] = $date_without_time; + + $table_info->data[] = $row; + } + } + + if ($pdf !== 0) { + $table_info->title = $item['title']; + $table_info->titleclass = 'title_table_pdf'; + $table_info->titlestyle = 'text-align:left;'; + $return_pdf .= html_print_table($table_info, true); + } else { + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: center;'; + $table->data['data']['cell'] = html_print_table($table_info, true); + } + } + + if ($pdf !== 0) { + return $return_pdf; + } +} + + /** * Function to print to HTML Exception report. * @@ -2582,16 +3017,66 @@ function reporting_html_group_report($table, $item, $pdf=0) $table->colspan['group_report']['cell'] = 3; $table->cellstyle['group_report']['cell'] = 'text-align: center;'; $metaconsole_connected = false; - if (is_metaconsole() === true) { + if (is_metaconsole() === true && $item['server_name'] != '0') { $connection = metaconsole_get_connection($item['server_name']); if (metaconsole_connect($connection) == NOERR) { $metaconsole_connected = true; } } + $all_group_id = []; + $group_events = []; + $group_os = []; + if ($item['subtitle'] === 'All') { + if (is_metaconsole() === true && $item['server_name'] === 'all' || $item['server_name'] === '0') { + $nodes = metaconsole_get_connections(); + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); + + $all_group_id_node = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo'); + + $group_events_node = db_get_all_rows_sql( + 'SELECT COUNT(te.id_evento) as count_events, ta.alias + FROM tevento as te + INNER JOIN tagente as ta ON te.id_agente = ta.id_agente + GROUP BY te.id_agente' + ); + $group_os_node = db_get_all_rows_sql( + 'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo + FROM tconfig_os as os + INNER JOIN tagente as ta ON ta.id_os = os.id_os GROUP by os.name' + ); + + $all_group_id = array_merge($all_group_id, $all_group_id_node); + $group_events = array_merge($group_events, $group_events_node); + $group_os = array_merge($group_os, $group_os_node); + } catch (\Exception $e) { + $nd->disconnect(); + $modules_regex_node = []; + } finally { + $nd->disconnect(); + } + } + } else { + $all_group_id = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo'); + + $group_events = db_get_all_rows_sql( + 'SELECT COUNT(te.id_evento) as count_events, ta.alias + FROM tevento as te + INNER JOIN tagente as ta ON te.id_agente = ta.id_agente + GROUP BY te.id_agente' + ); + $group_os = db_get_all_rows_sql( + 'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo + FROM tconfig_os as os + INNER JOIN tagente as ta ON ta.id_os = os.id_os GROUP by os.name' + ); + } + $group_id = []; - $all_group_id = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo'); foreach ($all_group_id as $group) { $group_id[] = $group['id_grupo']; @@ -2599,61 +3084,113 @@ function reporting_html_group_report($table, $item, $pdf=0) $description = __('Data view of all groups'); $icon = ''; - - $group_events = db_get_all_rows_sql( - 'SELECT COUNT(te.id_evento) as count_events, ta.alias - FROM tevento as te - INNER JOIN tagente as ta ON te.id_agente = ta.id_agente - GROUP BY te.id_agente' - ); - - $group_os = db_get_all_rows_sql( - 'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo - FROM tconfig_os as os - INNER JOIN tagente as ta ON ta.id_os = os.id_os GROUP by os.name' - ); } else { $group_id = db_get_value('id_grupo', 'tgrupo', 'nombre', $item['subtitle']); - $description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id); - $icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id); - $icon = html_print_image( - 'images/'.$icon_url, - true, - [ - 'title' => $item['subtitle'], - 'class' => 'main_menu_icon invert_filter', - ] - ); - $childrens = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo WHERE parent = '.$group_id); - $total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM tagente where id_grupo = '.$group_id); + if (is_metaconsole() === true && $item['server_name'] === 'all' || $item['server_name'] === '0') { + $nodes = metaconsole_get_connections(); + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - if ($childrens !== false && (int) $total_agents[0]['total'] !== $item['data']['group_stats']['total_agents']) { - $array_group_id = []; - $array_group_id[] = $group_id; - foreach ($childrens as $group) { - $array_group_id[] = $group['id_grupo']; + $group_id_node = db_get_value('id_grupo', 'tgrupo', 'nombre', $item['subtitle']); + $description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id_node); + $icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id_node); + $icon = html_print_image( + 'images/'.$icon_url, + true, + [ + 'title' => $item['subtitle'], + 'class' => 'main_menu_icon invert_filter', + ] + ); + + $childrens = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo WHERE parent = '.$group_id_node); + $total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM tagente where id_grupo = '.$group_id_node); + + if ($childrens !== false && (int) $total_agents[0]['total'] !== $item['data']['group_stats']['total_agents']) { + $array_group_id = []; + $array_group_id[] = $group_id_node; + foreach ($childrens as $group) { + $array_group_id[] = $group['id_grupo']; + } + + $group_id_node = $array_group_id; + $explode_group_id = implode(',', $group_id_node); + } else { + $explode_group_id = $group_id_node; + } + + $group_events_node = db_get_all_rows_sql( + 'SELECT COUNT(te.id_evento) as count_events, ta.alias + FROM tevento as te + INNER JOIN tagente as ta ON te.id_agente = ta.id_agente WHERE te.id_grupo IN ('.$explode_group_id.') + GROUP BY te.id_agente' + ); + + $group_os_node = db_get_all_rows_sql( + 'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo + FROM tconfig_os as os + INNER JOIN tagente as ta ON ta.id_os = os.id_os + WHERE ta.id_grupo IN ('.$explode_group_id.') GROUP by os.name' + ); + + if (is_array($group_events_node) === true) { + $group_events = array_merge($group_events, $group_events_node); + } + + if (is_array($group_os_node) === true) { + $group_os = array_merge($group_os, $group_os_node); + } + } catch (\Exception $e) { + $nd->disconnect(); + } finally { + $nd->disconnect(); + } + } + } else { + $description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id); + $icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id); + $icon = html_print_image( + 'images/'.$icon_url, + true, + [ + 'title' => $item['subtitle'], + 'class' => 'main_menu_icon invert_filter', + ] + ); + + $childrens = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo WHERE parent = '.$group_id); + $total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM tagente where id_grupo = '.$group_id); + + if ($childrens !== false && (int) $total_agents[0]['total'] !== $item['data']['group_stats']['total_agents']) { + $array_group_id = []; + $array_group_id[] = $group_id; + foreach ($childrens as $group) { + $array_group_id[] = $group['id_grupo']; + } + + $group_id = $array_group_id; + $explode_group_id = implode(',', $group_id); + } else { + $explode_group_id = $group_id; } - $group_id = $array_group_id; - $explode_group_id = implode(',', $group_id); - } else { - $explode_group_id = $group_id; + $group_events = db_get_all_rows_sql( + 'SELECT COUNT(te.id_evento) as count_events, ta.alias + FROM tevento as te + INNER JOIN tagente as ta ON te.id_agente = ta.id_agente WHERE te.id_grupo IN ('.$explode_group_id.') + GROUP BY te.id_agente' + ); + + $group_os = db_get_all_rows_sql( + 'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo + FROM tconfig_os as os + INNER JOIN tagente as ta ON ta.id_os = os.id_os + WHERE ta.id_grupo IN ('.$explode_group_id.') GROUP by os.name' + ); } - - $group_events = db_get_all_rows_sql( - 'SELECT COUNT(te.id_evento) as count_events, ta.alias - FROM tevento as te - INNER JOIN tagente as ta ON te.id_agente = ta.id_agente WHERE te.id_grupo IN ('.$explode_group_id.') - GROUP BY te.id_agente' - ); - - $group_os = db_get_all_rows_sql( - 'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo - FROM tconfig_os as os - INNER JOIN tagente as ta ON ta.id_os = os.id_os - WHERE ta.id_grupo IN ('.$explode_group_id.') GROUP by os.name' - ); } if ($metaconsole_connected === true) { @@ -2764,8 +3301,10 @@ function reporting_html_group_report($table, $item, $pdf=0) $options = []; $labels = []; foreach ($group_os as $value) { - $data[$value['name_os']] = $value['count_os']; - $labels[] = io_safe_output($value['name_os']); + $data[$value['name_os']] += $value['count_os']; + if (array_search($value['name_os'], $labels) === false) { + $labels[] = io_safe_output($value['name_os']); + } } $options = [ diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index f13e935b6a..3da9993933 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -814,6 +814,11 @@ function reports_get_report_types($template=false, $not_editor=false) 'name' => __('Agents/Modules status'), ]; + $types['end_of_life'] = [ + 'optgroup' => __('Grouped'), + 'name' => __('End of life'), + ]; + // Only pandora managers have access to the whole database. if (check_acl($config['id_user'], 0, 'PM')) { $types['sql'] = [ @@ -963,6 +968,43 @@ function reports_get_report_types($template=false, $not_editor=false) 'name' => __('Network configuration changes'), ]; + if (enterprise_installed() === true) { + $types['top_n_agents_sh'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('Top-N agents with the worst score'), + ]; + + $types['top_n_checks_failed'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('Top-N most frequent failed checks'), + ]; + + $types['top_n_categories_checks'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('Top-N checks failed by category'), + ]; + + $types['vul_by_cat'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('Vulnerabilities by category'), + ]; + + $types['list_checks'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('List of checks'), + ]; + + $types['scoring'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('Scoring by date'), + ]; + + $types['evolution'] = [ + 'optgroup' => __('Security hardening'), + 'name' => __('Evolution'), + ]; + } + return $types; } diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index e4d1f655b0..75e034ce3c 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -283,6 +283,10 @@ function servers_get_performance($filter=[]) } foreach ($counts as $c) { + if (empty($c['modules']) === true) { + continue; + } + switch ($c['server_type']) { case SERVER_TYPE_DATA: $data['total_local_modules'] = $c['modules']; @@ -292,7 +296,7 @@ function servers_get_performance($filter=[]) case SERVER_TYPE_SNMP: case SERVER_TYPE_ENTERPRISE_ICMP: case SERVER_TYPE_ENTERPRISE_SNMP: - $data['total_network_modules'] = $c['modules']; + $data['total_network_modules'] += $c['modules']; break; case SERVER_TYPE_PLUGIN: @@ -902,7 +906,7 @@ function servers_get_info($id_server=-1, $sql_limit=-1) 'images/logs@svg.svg', true, [ - 'title' => __('Log server'), + 'title' => __('Syslog server'), 'class' => 'main_menu_icon invert_filter', ] ); @@ -975,6 +979,32 @@ function servers_get_info($id_server=-1, $sql_limit=-1) $id_modulo = 0; break; + case SERVER_TYPE_LOG: + $server['img'] = html_print_image( + 'images/log_server.svg', + true, + [ + 'title' => __('Log server'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + $server['type'] = 'log'; + $id_modulo = 0; + break; + + case SERVER_TYPE_MADE: + $server['img'] = html_print_image( + 'images/Anomaly-detection@svg.svg', + true, + [ + 'title' => __('MADE server'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + $server['type'] = 'made'; + $id_modulo = 0; + break; + default: $server['img'] = ''; $server['type'] = 'unknown'; diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 025276ecef..47f861314a 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -708,6 +708,13 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) $row['data'] = human_time_description_raw($agent['intervalo']); $table->data['interval'] = $row; + if (isset($agent['quiet']) && $agent['quiet']) { + $row = []; + $row['title'] = __('Quiet mode enabled'); + $row['data'] = ui_print_help_tip(__('This agent would not raise events or alerts'), true); + $table->data['quiet'] = $row; + } + // Comments. $row = []; $row['title'] = __('Description'); diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index a57a9346b7..3b193b8975 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -99,23 +99,27 @@ function ui_print_truncate_text( $forced_title=false ) { global $config; - + $truncate_at_end = false; if (is_string($numChars)) { switch ($numChars) { case 'agent_small': $numChars = $config['agent_size_text_small']; + $truncate_at_end = (bool) $config['truncate_agent_at_end']; break; case 'agent_medium': $numChars = $config['agent_size_text_medium']; + $truncate_at_end = (bool) $config['truncate_agent_at_end']; break; case 'module_small': $numChars = $config['module_size_text_small']; + $truncate_at_end = (bool) $config['truncate_module_at_end']; break; case 'module_medium': $numChars = $config['module_size_text_medium']; + $truncate_at_end = (bool) $config['truncate_module_at_end']; break; case 'description': @@ -147,27 +151,35 @@ function ui_print_truncate_text( // '/2' because [...] is in the middle of the word. $half_length = intval(($numChars - 3) / 2); - // Depending on the strange behavior of mb_strimwidth() itself, - // the 3rd parameter is not to be $numChars but the length of - // original text (just means 'large enough'). - $truncateText2 = mb_strimwidth( - $text_html_decoded, - (mb_strlen($text_html_decoded, 'UTF-8') - $half_length), - mb_strlen($text_html_decoded, 'UTF-8'), - '', - 'UTF-8' - ); + if ($truncate_at_end === true) { + // Recover the html entities to avoid XSS attacks. + $truncateText = ($text_has_entities) ? io_safe_input(substr($text_html_decoded, 0, $numChars)) : substr($text_html_decoded, 0, $numChars); + if (strlen($text_html_decoded) > $numChars) { + $truncateText .= '...'; + } + } else { + // Depending on the strange behavior of mb_strimwidth() itself, + // the 3rd parameter is not to be $numChars but the length of + // original text (just means 'large enough'). + $truncateText2 = mb_strimwidth( + $text_html_decoded, + (mb_strlen($text_html_decoded, 'UTF-8') - $half_length), + mb_strlen($text_html_decoded, 'UTF-8'), + '', + 'UTF-8' + ); - $truncateText = mb_strimwidth( - $text_html_decoded, - 0, - ($numChars - $half_length), - '', - 'UTF-8' - ); + $truncateText = mb_strimwidth( + $text_html_decoded, + 0, + ($numChars - $half_length), + '', + 'UTF-8' + ); - // Recover the html entities to avoid XSS attacks. - $truncateText = ($text_has_entities) ? io_safe_input($truncateText).$suffix.io_safe_input($truncateText2) : $truncateText.$suffix.$truncateText2; + // Recover the html entities to avoid XSS attacks. + $truncateText = ($text_has_entities) ? io_safe_input($truncateText).$suffix.io_safe_input($truncateText2) : $truncateText.$suffix.$truncateText2; + } if ($showTextInTitle) { if ($style === null) { @@ -597,12 +609,20 @@ function ui_print_timestamp($unixtime, $return=false, $option=[]) $tag = 'span'; } - if (empty($option['style']) === true) { - $style = 'class="'.($option['class'] ?? 'nowrap').'"'; + if (empty($option['class']) === false) { + $class = 'class="nowrap '.$option['class'].'"'; } else { - $style = 'style="'.$option['style'].'"'; + $class = 'class="nowrap"'; } + if (empty($option['style']) === false) { + $style = 'style="'.$option['style'].'"'; + } else { + $style = 'style=""'; + } + + $style .= ' '.$class; + if (empty($option['prominent']) === false) { $prominent = $option['prominent']; } else { @@ -1474,32 +1494,34 @@ function ui_format_alert_row( $actionText .= ui_print_help_tip(__('The default actions will be executed every time that the alert is fired and no other action is executed'), true); // Is possible manage actions if have LW permissions in the agent group of the alert module. - if (check_acl($config['id_user'], $id_group, 'LM')) { - $actionText .= ''.html_print_image( - 'images/delete.svg', - true, - [ - 'alt' => __('Delete action'), - 'title' => __('Delete action'), - 'class' => 'main_menu_icon invert_filter vertical_baseline', - ] - ).''; - } + if (is_metaconsole() === true) { + if (check_acl($config['id_user'], $id_group, 'LM')) { + $actionText .= ''.html_print_image( + 'images/delete.svg', + true, + [ + 'alt' => __('Delete action'), + 'title' => __('Delete action'), + 'class' => 'main_menu_icon invert_filter vertical_baseline', + ] + ).''; + } - if (check_acl($config['id_user'], $id_group, 'LW')) { - $actionText .= html_print_input_image( - 'update_action', - '/images/edit.svg', - 1, - 'padding:0px;', - true, - [ - 'title' => __('Update action'), - 'class' => 'main_menu_icon invert_filter', - 'onclick' => 'show_display_update_action(\''.$action['original_id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['original_id'].'\',\''.$alert['agent_name'].'\')', - ] - ); - $actionText .= html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true); + if (check_acl($config['id_user'], $id_group, 'LW')) { + $actionText .= html_print_input_image( + 'update_action', + '/images/edit.svg', + 1, + 'padding:0px;', + true, + [ + 'title' => __('Update action'), + 'class' => 'main_menu_icon invert_filter', + 'onclick' => 'show_display_update_action(\''.$action['original_id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['original_id'].'\',\''.$alert['agent_name'].'\')', + ] + ); + $actionText .= html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true); + } } $actionText .= '