mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
Merge branch 'ent-11830-reemplazar-sistema-de-websocket-gotty-actual' of brutus.artica.es:artica/pandorafms into ent-11830-reemplazar-sistema-de-websocket-gotty-actual
This commit is contained in:
commit
53147d46ff
@ -6,6 +6,8 @@ mkdir -p pandora_gotty/usr/bin
|
|||||||
mkdir -p pandora_gotty/etc/pandora_gotty
|
mkdir -p pandora_gotty/etc/pandora_gotty
|
||||||
cp -a ../src/pandora_gotty pandora_gotty/usr/bin
|
cp -a ../src/pandora_gotty pandora_gotty/usr/bin
|
||||||
cp -a ../src/pandora_gotty.conf pandora_gotty/etc/pandora_gotty
|
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
|
dpkg-deb --build pandora_gotty
|
||||||
mv pandora_gotty.deb ../
|
mv pandora_gotty.deb ../
|
||||||
rm -rf pandora_gotty/usr/
|
rm -rf pandora_gotty/usr/
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
#RPM
|
#RPM
|
||||||
VERSION=$(grep '%define version' pandora_gotty.spec | awk '{print $3}')
|
VERSION=$(grep '%define version' pandora_gotty.spec | awk '{print $3}')
|
||||||
mkdir -p pandora_gotty-${VERSION}
|
mkdir -p pandora_gotty-${VERSION}
|
||||||
cp src/* 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}/*
|
tar -cvzf pandora_gotty-${VERSION}.tar.gz pandora_gotty-${VERSION}/*
|
||||||
mv pandora_gotty-${VERSION}.tar.gz ${HOME}/rpmbuild/SOURCES/
|
mv pandora_gotty-${VERSION}.tar.gz ${HOME}/rpmbuild/SOURCES/
|
||||||
rm -rf ${HOME}/rpmbuild/RPMS/x86_64/pandora_gotty*
|
rm -rf ${HOME}/rpmbuild/RPMS/x86_64/pandora_gotty*
|
||||||
|
@ -25,6 +25,7 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
|
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
|
||||||
mkdir -p %{buildroot}/etc/pandora_gotty/
|
mkdir -p %{buildroot}/etc/pandora_gotty/
|
||||||
cp %{name} $RPM_BUILD_ROOT/%{_bindir}
|
cp %{name} $RPM_BUILD_ROOT/%{_bindir}
|
||||||
|
cp pandora_gotty_exec $RPM_BUILD_ROOT/%{_bindir}
|
||||||
cp pandora_gotty.conf %{buildroot}/etc/pandora_gotty/
|
cp pandora_gotty.conf %{buildroot}/etc/pandora_gotty/
|
||||||
%clean
|
%clean
|
||||||
rm -Rf $RPM_BUILD_ROOT
|
rm -Rf $RPM_BUILD_ROOT
|
||||||
@ -33,6 +34,7 @@ rm -Rf $RPM_BUILD_ROOT
|
|||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
%config(noreplace) /etc/pandora_gotty/pandora_gotty.conf
|
%config(noreplace) /etc/pandora_gotty/pandora_gotty.conf
|
||||||
%{_bindir}/%{name}
|
%{_bindir}/%{name}
|
||||||
|
%{_bindir}/pandora_gotty_exec
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Mon Sep 18 2023 PandoraFMS - 1.0-1
|
* Mon Sep 18 2023 PandoraFMS - 1.0-1
|
||||||
|
1
extras/pandora_gotty/src/.gitignore
vendored
1
extras/pandora_gotty/src/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*rpm
|
*rpm
|
||||||
|
bin/*
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
//Pandora Gotty
|
//Pandora Gotty config file
|
||||||
|
|
||||||
// [bool] Permit clients to write to the TTY
|
// [bool] Permit clients to write to the TTY
|
||||||
permit_write = true
|
permit_write = true
|
||||||
|
|
||||||
// [bool] Enable basic authentication
|
|
||||||
enable_basic_auth = true
|
|
||||||
|
|
||||||
// [string] Default username and password of basic authentication (user:pass)
|
|
||||||
// To enable basic authentication, set `true` to `enable_basic_auth`
|
|
||||||
credential = "pandora:Pandor4!"
|
|
||||||
|
|
||||||
// [bool] Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB)
|
// [bool] Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB)
|
||||||
permit_arguments = true
|
permit_arguments = true
|
||||||
|
|
||||||
|
110
extras/pandora_gotty/src/pandora_gotty_exec.py
Normal file
110
extras/pandora_gotty/src/pandora_gotty_exec.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user