Initial, very incomplete implementation of ogAdmClient in python #7

Merged
nserrano merged 17 commits from ogadmcli into main 2024-08-27 11:36:41 +02:00
Collaborator

Use story: https://ognproject.evlt.uma.es/redmine/issues/493

Gather data

Obtain local IP address: ip address show. In this PR I will use 192.168.1.249.

Obtain path to your copy of the opengnsys repository. In this PR I will use /home/user/work/opengnsys/opengnsys.

Install requisites

The agent runs browser. At this point we're not using any browser, but xeyes instead. Install xeyes (on debian, it's in the package x11-apps.

Edit source code a bit

Edit src/test_modules/server/ogAdmClient/__init__.py, function interfaceAdmin (line 234) so that the agent knows where to look for the opengnsys shell functions and helpers.

Where it says:

        devel_bash_prefix = '''
            PATH=/opt/opengnsys/scripts/:$PATH;
            for I in /opt/opengnsys/lib/engine/bin/*.lib; do source $I; done;
            for i in $(declare -F |cut -f3 -d" "); do export -f $i; done;
        '''

Adjust the paths to your environment:

        devel_bash_prefix = '''
            PATH=/home/user/opengnsys/opengnsys/client/shared/scripts:$PATH;
            for I in /home/user/opengnsys/opengnsys/client/engine/*.lib; do source $I; done;
            for i in $(declare -F |cut -f3 -d" "); do export -f $i; done;
        '''

Edit configuration of the agent:

The ogagent configuration at src/cfg/ogagent.cfg has two sections:

[opengnsys]
blah blah blah

[ogAdmClient]
blah blah blah

In section [opengnsys], change the IP address in the remote line: remote=https://192.168.1.249/opengnsys/rest

In section [ogAdmClient] change the IP too, and also add __ogAdmClient to the end: remote=https://192.168.1.249/opengnsys/rest/__ogAdmClient

In section [ogAdmClient] change pathinterface to something like /home/user/opengnsys/opengnsys/admin/Interface.

Go

Run the ogcore server mock (sudo required to listen on port 443): FLASK_APP=./ogcore-mock.py FLASK_ENV=development FLASK_RUN_CERT=adhoc sudo --preserve-env flask run --host $OGCORE_IP --port 443

In another terminal, run the agent as root. It should load two modules and talk a bit to the ogcore-mock:

$ sudo -i
# tail -f /var/log/opengnsys.log &
# cd path/to/ogagent/src
# PYTHONPATH=. python3 opengnsys/linux/OGAgentService.py fg

Also you should see good old xeyes on your screen.

Server output

When you run the agent, the output of the ogcore mock server should contain something like the following.

First, the OS agent POSTs to /started as usual. This call will probably go away in the future:

INFO:root:{'mac': '02:42:9c:87:1a:9f', 'ip': '172.18.0.1', 'secret': 's5rq30425lwy0lyn3q2jgugfk2zmmnpe', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.10', 'agent_version': '0'}
INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:16] "POST /opengnsys/rest/ogagent/started HTTP/1.1" 200 -

The oglive agent POSTs to /InclusionCliente. The parameter gives details about the disks and partitions that exist where the agent runs. Since the agent is running on your development machine, the info should match your disks and partitions:

INFO:root:{'cfg': 'ser=2SFR6D3\ndisk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=1000204632\tuso=0\ndisk=1\tpar=1\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=524288\tuso=2\ndisk=1\tpar=2\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=749568\tuso=42\ndisk=1\tpar=3\tcpt=8300\tfsi=CRYPTO_LUKS\tsoi=DATA\ttam=998929408\tuso=11421\ndisk=2\tpar=0\tcpt=3\tfsi=\tsoi=\ttam=998913024\tuso=0\ndisk=2\tpar=1\tcpt=10000\tfsi=EXT4\tsoi=Ubuntu 22.10 \ttam=975560704\tuso=61\ndisk=2\tpar=2\tcpt=10000\tfsi=LINUX-SWAP\tsoi=\ttam=999424\tuso=0', 'iph': '172.18.0.1', 'ido': None, 'npc': None, 'idc': None, 'ida': None}
INFO:root:iph (172.18.0.1) cfg (ser=2SFR6D3
disk=1  par=0   cpt=2   fsi=    soi=    tam=1000204632  uso=0
disk=1  par=1   cpt=EF00        fsi=FAT32       soi=GRUB2 Loader        tam=524288      uso=2
disk=1  par=2   cpt=8300        fsi=EXT4        soi=GRUB2 Loader        tam=749568      uso=42
disk=1  par=3   cpt=8300        fsi=CRYPTO_LUKS soi=DATA        tam=998929408   uso=11421
disk=2  par=0   cpt=3   fsi=    soi=    tam=998913024   uso=0
disk=2  par=1   cpt=10000       fsi=EXT4        soi=Ubuntu 22.10        tam=975560704   uso=61
disk=2  par=2   cpt=10000       fsi=LINUX-SWAP  soi=    tam=999424      uso=0)
INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/InclusionCliente HTTP/1.1" 200 -

The oglive agent POSTs to /AutoexecCliente:

INFO:root:{'exe': 42, 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:iph (172.18.0.1) exe (42)
INFO:root:fileautoexec (/tmp/Sautoexec-172.18.0.1)
INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/AutoexecCliente HTTP/1.1" 200 -

The oglive agent POSTs to /enviaArchivo:

INFO:root:{'nfl': '/tmp/Sautoexec-172.18.0.1', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:nfl (/tmp/Sautoexec-172.18.0.1)
INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/enviaArchivo HTTP/1.1" 200 -

The oglive agent POSTs to /ComandosPendientes:

INFO:root:{'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:iph (172.18.0.1) ido (42)
INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/ComandosPendientes HTTP/1.1" 200 -

The oglive agent POSTs to /DisponibilidadComandos:

INFO:root:{'tpc': 'OPG', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:iph (172.18.0.1) tpc (OPG)
INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:22] "POST /opengnsys/rest/__ogAdmClient/DisponibilidadComandos HTTP/1.1" 200 -

Agent log output

Basic initialisation:

root@tau:/home/nati/Downloads/work/opengnsys/ogagent/src# PYTHONPATH=. python3 opengnsys/linux/OGAgentService.py fg
INFO 2024-08-08 11:42:16,641 (MainThread) (__init__) ----------------------------------------
INFO 2024-08-08 11:42:16,641 (MainThread) (__init__) Initializing OpenGnsys Agent
DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Loaded configuration from opengnsys.cfg:
DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Section opengnsys = [('address', '0.0.0.0'), ('port', '8000'), ('path', 'test_modules/server'), ('remote', 'https://192.168.1.249/opengnsys/rest'), ('level', 'full'), ('log', 'DEBUG')]
DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Section ogAdmClient = [('remote', 'https://192.168.1.249/opengnsys/rest/__ogAdmClient'), ('log', 'DEBUG'), ('pathinterface', '/home/nati/Downloads/work/opengnsys/opengnsys/admin/Interface'), ('urlmenu', 'https://192.168.2.1/opengnsys/varios/menubrowser.php'), ('urlmsg', 'http://localhost/cgi-bin/httpd-log.sh')]
DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Socket timeout: 20

Modules are found and loaded:

DEBUG 2024-08-08 11:42:16,655 (MainThread) (loadModules) Loading modules from ('/home/nati/Downloads/work/opengnsys/ogagent/src/test_modules/server',)
DEBUG 2024-08-08 11:42:16,656 (MainThread) (doLoad) Found module package opengnsys.modules.server.Sample1
DEBUG 2024-08-08 11:42:16,656 (MainThread) (doLoad) Found module package opengnsys.modules.server.ogAdmClient
DEBUG 2024-08-08 11:42:16,656 (MainThread) (loadModules) Adding server classes
DEBUG 2024-08-08 11:42:16,656 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.OpenGnSys.OpenGnSysWorker'>
DEBUG 2024-08-08 11:42:16,656 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.Sample1.sample1.Sample1'>
DEBUG 2024-08-08 11:42:16,656 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.ogAdmClient.ogAdmClientWorker'>
DEBUG 2024-08-08 11:42:16,656 (MainThread) (__init__) Modules: ['opengnsys', 'Sample1', 'ogAdmClient']
DEBUG 2024-08-08 11:42:16,656 (MainThread) (run) ** Running Daemon **
DEBUG 2024-08-08 11:42:16,656 (MainThread) (initialize) Starting IPC listener at 10398
DEBUG 2024-08-08 11:42:16,658 (MainThread) (__init__) Initialized HTTPS Server thread on ('0.0.0.0', 8000)

Modules are activated, first the "opengnsys" module:

DEBUG 2024-08-08 11:42:16,658 (MainThread) (initialize) Activating module opengnsys
DEBUG 2024-08-08 11:42:16,662 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': '02:42:9c:87:1a:9f', 'ip': '172.18.0.1', 'secret': 's5rq30425lwy0lyn3q2jgugfk2zmmnpe', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.10', 'agent_version': '0'}
DEBUG 2024-08-08 11:42:16,662 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/ogagent/started
DEBUG 2024-08-08 11:42:16,662 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/ogagent/started, data: {"mac": "02:42:9c:87:1a:9f", "ip": "172.18.0.1", "secret": "s5rq30425lwy0lyn3q2jgugfk2zmmnpe", "ostype": "Linux", "osversion": "Ubuntu 22.10", "agent_version": "0"}
DEBUG 2024-08-08 11:42:16,663 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443
DEBUG 2024-08-08 11:42:16,668 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/ogagent/started HTTP/1.1" 200 3
DEBUG 2024-08-08 11:42:16,668 (MainThread) (onActivation) Successful connection after 0 tries

Now the "Sample1" module (a dummy one that I will probably remove in the future):

DEBUG 2024-08-08 11:42:16,668 (MainThread) (initialize) Activating module Sample1

And now the "ogAdmClient" module, which does a lot of things.

Get its own IP address:

DEBUG 2024-08-08 11:42:16,668 (MainThread) (initialize) Activating module ogAdmClient
DEBUG 2024-08-08 11:42:16,668 (MainThread) (interfaceAdmin) subprocess.run ("['bash', '-c', '\n            PATH=/home/nati/Downloads/work/opengnsys/opengnsys/client/shared/scripts:$PATH;\n            for I in /home/nati/Downloads/work/opengnsys/opengnsys/client/engine/*.lib; do source $I; done;\n            for i in $(declare -F |cut -f3 -d" "); do export -f $i; done;\n         /home/nati/Downloads/work/opengnsys/opengnsys/admin/Interface/getIpAddress']", capture_output=True)
INFO 2024-08-08 11:42:16,737 (MainThread) (tomaIPlocal) local IP is "172.18.0.1"

Sends a POST to InclusionCliente:

INFO 2024-08-08 11:42:16,738 (MainThread) (onActivation) Inicio de sesion
INFO 2024-08-08 11:42:16,738 (MainThread) (onActivation) Abriendo sesión en el servidor de Administración
DEBUG 2024-08-08 11:42:16,738 (MainThread) (interfaceAdmin) subprocess.run ("['bash', '-c', '\n            PATH=/home/nati/Downloads/work/opengnsys/opengnsys/client/shared/scripts:$PATH;\n            for I in /home/nati/Downloads/work/opengnsys/opengnsys/client/engine/*.lib; do source $I; done;\n            for i in $(declare -F |cut -f3 -d" "); do export -f $i; done;\n         /home/nati/Downloads/work/opengnsys/opengnsys/admin/Interface/getConfiguration']", capture_output=True)
DEBUG 2024-08-08 11:42:20,540 (MainThread) (LeeConfiguracion) parametroscfg (ser=2SFR6D3
disk=1	par=0	cpt=2	fsi=	soi=	tam=1000204632	uso=0
disk=1	par=1	cpt=EF00	fsi=FAT32	soi=GRUB2 Loader 	tam=524288	uso=2
disk=1	par=2	cpt=8300	fsi=EXT4	soi=GRUB2 Loader 	tam=749568	uso=42
disk=1	par=3	cpt=8300	fsi=CRYPTO_LUKS	soi=DATA	tam=998929408	uso=11421
disk=2	par=0	cpt=3	fsi=	soi=	tam=998913024	uso=0
disk=2	par=1	cpt=10000	fsi=EXT4	soi=Ubuntu 22.10 	tam=975560704	uso=61
disk=2	par=2	cpt=10000	fsi=LINUX-SWAP	soi=	tam=999424	uso=0)
DEBUG 2024-08-08 11:42:20,540 (MainThread) (sendMessage) Invoking post message InclusionCliente with data {'cfg': 'ser=2SFR6D3\ndisk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=1000204632\tuso=0\ndisk=1\tpar=1\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=524288\tuso=2\ndisk=1\tpar=2\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=749568\tuso=42\ndisk=1\tpar=3\tcpt=8300\tfsi=CRYPTO_LUKS\tsoi=DATA\ttam=998929408\tuso=11421\ndisk=2\tpar=0\tcpt=3\tfsi=\tsoi=\ttam=998913024\tuso=0\ndisk=2\tpar=1\tcpt=10000\tfsi=EXT4\tsoi=Ubuntu 22.10 \ttam=975560704\tuso=61\ndisk=2\tpar=2\tcpt=10000\tfsi=LINUX-SWAP\tsoi=\ttam=999424\tuso=0', 'iph': '172.18.0.1', 'ido': None, 'npc': None, 'idc': None, 'ida': None}
DEBUG 2024-08-08 11:42:20,540 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/InclusionCliente
DEBUG 2024-08-08 11:42:20,540 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/InclusionCliente, data: {"cfg": "ser=2SFR6D3\ndisk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=1000204632\tuso=0\ndisk=1\tpar=1\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=524288\tuso=2\ndisk=1\tpar=2\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=749568\tuso=42\ndisk=1\tpar=3\tcpt=8300\tfsi=CRYPTO_LUKS\tsoi=DATA\ttam=998929408\tuso=11421\ndisk=2\tpar=0\tcpt=3\tfsi=\tsoi=\ttam=998913024\tuso=0\ndisk=2\tpar=1\tcpt=10000\tfsi=EXT4\tsoi=Ubuntu 22.10 \ttam=975560704\tuso=61\ndisk=2\tpar=2\tcpt=10000\tfsi=LINUX-SWAP\tsoi=\ttam=999424\tuso=0", "iph": "172.18.0.1", "ido": null, "npc": null, "idc": null, "ida": null}
DEBUG 2024-08-08 11:42:20,540 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443
DEBUG 2024-08-08 11:42:20,544 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/InclusionCliente HTTP/1.1" 200 106
DEBUG 2024-08-08 11:42:20,544 (MainThread) (inclusionCliente) res ({'che': 42, 'exe': 42, 'ida': 42, 'idc': 42, 'ido': 42, 'npc': 'hal9000', 'res': 1})
INFO 2024-08-08 11:42:20,544 (MainThread) (onActivation) Cliente iniciado

Sends a POST to AutoexecCliente:

INFO 2024-08-08 11:42:20,544 (MainThread) (onActivation) Procesando caché
INFO 2024-08-08 11:42:20,544 (MainThread) (onActivation) Ejecución de archivo Autoexec
DEBUG 2024-08-08 11:42:20,544 (MainThread) (sendMessage) Invoking post message AutoexecCliente with data {'exe': 42, 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
DEBUG 2024-08-08 11:42:20,544 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/AutoexecCliente
DEBUG 2024-08-08 11:42:20,544 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/AutoexecCliente, data: {"exe": 42, "iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42}
DEBUG 2024-08-08 11:42:20,545 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443
DEBUG 2024-08-08 11:42:20,548 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/AutoexecCliente HTTP/1.1" 200 54
DEBUG 2024-08-08 11:42:20,548 (MainThread) (autoexecCliente) res ({'nfl': '/tmp/Sautoexec-172.18.0.1', 'res': 1})
INFO 2024-08-08 11:42:20,548 (MainThread) (autoexecCliente) {'nfl': '/tmp/Sautoexec-172.18.0.1', 'res': 1}
DEBUG 2024-08-08 11:42:20,548 (MainThread) (sendMessage) Invoking post message enviaArchivo with data {'nfl': '/tmp/Sautoexec-172.18.0.1', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
DEBUG 2024-08-08 11:42:20,548 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/enviaArchivo
DEBUG 2024-08-08 11:42:20,548 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/enviaArchivo, data: {"nfl": "/tmp/Sautoexec-172.18.0.1", "iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42}
DEBUG 2024-08-08 11:42:20,549 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443
DEBUG 2024-08-08 11:42:20,553 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/enviaArchivo HTTP/1.1" 200 67
DEBUG 2024-08-08 11:42:20,553 (MainThread) (autoexecCliente) fileautoexec (/tmp/_autoexec_172.18.0.1)
DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) fn (/tmp/_autoexec_172.18.0.1)

(this "popup" is development stuff)

DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) buffer (nfn=popup\rtitle=my title\rmessage=my message@)
message=my message):42:20,554 (MainThread) (ejecutaArchivo) line (nfn=popup
DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) post_params "{'nfn': 'popup', 'title': 'my title', 'message': 'my message'}"
DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) calling function "popup" with post_params "{'title': 'my title', 'message': 'my message'}"
DEBUG 2024-08-08 11:42:20,554 (MainThread) (process_popup) in process_popup, path "[]" get_params "{}" post_params "{'title': 'my title', 'message': 'my message'}" server "None"
DEBUG 2024-08-08 11:42:20,554 (MainThread) (process_popup) type(post_params) "<class 'dict'>"
DEBUG 2024-08-08 11:42:20,555 (MainThread) (ejecutaArchivo) output "{'debug': 'test'}"

Sends a POST to ComandosPendientes:

INFO 2024-08-08 11:42:20,555 (MainThread) (onActivation) Procesa comandos pendientes
DEBUG 2024-08-08 11:42:20,555 (MainThread) (sendMessage) Invoking post message ComandosPendientes with data {'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
DEBUG 2024-08-08 11:42:20,555 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/ComandosPendientes
DEBUG 2024-08-08 11:42:20,555 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/ComandosPendientes, data: {"iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42}
DEBUG 2024-08-08 11:42:20,555 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443
DEBUG 2024-08-08 11:42:20,558 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/ComandosPendientes HTTP/1.1" 200 30
INFO 2024-08-08 11:42:20,559 (MainThread) (comandosPendientes) {'nfn': 'NoComandosPtes'}
INFO 2024-08-08 11:42:20,559 (MainThread) (onActivation) Acciones pendientes procesadas

Sends a POST to DisponibilidadComandos:

DEBUG 2024-08-08 11:42:22,571 (MainThread) (sendMessage) Invoking post message DisponibilidadComandos with data {'tpc': 'OPG', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
DEBUG 2024-08-08 11:42:22,571 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/DisponibilidadComandos
DEBUG 2024-08-08 11:42:22,571 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/DisponibilidadComandos, data: {"tpc": "OPG", "iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42}
DEBUG 2024-08-08 11:42:22,573 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443
DEBUG 2024-08-08 11:42:22,582 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/DisponibilidadComandos HTTP/1.1" 200 3
DEBUG 2024-08-08 11:42:22,583 (MainThread) (procesaComandos) res ({})
INFO 2024-08-08 11:42:22,583 (MainThread) (procesaComandos) Disponibilidad de comandos activada
DEBUG 2024-08-08 11:42:22,583 (MainThread) (initialize) Modules after activation: ['opengnsys', 'Sample1', 'ogAdmClient']

Cleanup

Press ^C to terminate the agent.

Press ^C in the other terminal to terminate the ogserver.

rm -f /tmp/Sautoexec-* /tmp/_autoexec_* /var/run/opengnsys-agent.pid

Use story: https://ognproject.evlt.uma.es/redmine/issues/493 ## Gather data Obtain local IP address: `ip address show`. In this PR I will use 192.168.1.249. Obtain path to your copy of the `opengnsys` repository. In this PR I will use `/home/user/work/opengnsys/opengnsys`. ## Install requisites The agent runs `browser`. At this point we're not using any browser, but `xeyes` instead. Install xeyes (on debian, it's in the package `x11-apps`. ## Edit source code a bit Edit `src/test_modules/server/ogAdmClient/__init__.py`, function `interfaceAdmin` (line 234) so that the agent knows where to look for the opengnsys shell functions and helpers. Where it says: ``` devel_bash_prefix = ''' PATH=/opt/opengnsys/scripts/:$PATH; for I in /opt/opengnsys/lib/engine/bin/*.lib; do source $I; done; for i in $(declare -F |cut -f3 -d" "); do export -f $i; done; ''' ``` Adjust the paths to your environment: ``` devel_bash_prefix = ''' PATH=/home/user/opengnsys/opengnsys/client/shared/scripts:$PATH; for I in /home/user/opengnsys/opengnsys/client/engine/*.lib; do source $I; done; for i in $(declare -F |cut -f3 -d" "); do export -f $i; done; ''' ``` ## Edit configuration of the agent: The ogagent configuration at `src/cfg/ogagent.cfg` has two sections: ``` [opengnsys] blah blah blah [ogAdmClient] blah blah blah ``` In section `[opengnsys]`, change the IP address in the `remote` line: `remote=https://192.168.1.249/opengnsys/rest` In section `[ogAdmClient]` change the IP too, and also add `__ogAdmClient` to the end: `remote=https://192.168.1.249/opengnsys/rest/__ogAdmClient` In section `[ogAdmClient]` change `pathinterface` to something like `/home/user/opengnsys/opengnsys/admin/Interface`. ## Go Run the ogcore server mock (sudo required to listen on port 443): `FLASK_APP=./ogcore-mock.py FLASK_ENV=development FLASK_RUN_CERT=adhoc sudo --preserve-env flask run --host $OGCORE_IP --port 443` In another terminal, run the agent as root. It should load two modules and talk a bit to the ogcore-mock: ``` $ sudo -i # tail -f /var/log/opengnsys.log & # cd path/to/ogagent/src # PYTHONPATH=. python3 opengnsys/linux/OGAgentService.py fg ``` Also you should see good old `xeyes` on your screen. ### Server output When you run the agent, the output of the ogcore mock server should contain something like the following. First, the OS agent POSTs to `/started` as usual. This call will probably go away in the future: ``` INFO:root:{'mac': '02:42:9c:87:1a:9f', 'ip': '172.18.0.1', 'secret': 's5rq30425lwy0lyn3q2jgugfk2zmmnpe', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.10', 'agent_version': '0'} INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:16] "POST /opengnsys/rest/ogagent/started HTTP/1.1" 200 - ``` The oglive agent POSTs to `/InclusionCliente`. The parameter gives details about the disks and partitions that exist where the agent runs. Since the agent is running on your development machine, the info should match your disks and partitions: ``` INFO:root:{'cfg': 'ser=2SFR6D3\ndisk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=1000204632\tuso=0\ndisk=1\tpar=1\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=524288\tuso=2\ndisk=1\tpar=2\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=749568\tuso=42\ndisk=1\tpar=3\tcpt=8300\tfsi=CRYPTO_LUKS\tsoi=DATA\ttam=998929408\tuso=11421\ndisk=2\tpar=0\tcpt=3\tfsi=\tsoi=\ttam=998913024\tuso=0\ndisk=2\tpar=1\tcpt=10000\tfsi=EXT4\tsoi=Ubuntu 22.10 \ttam=975560704\tuso=61\ndisk=2\tpar=2\tcpt=10000\tfsi=LINUX-SWAP\tsoi=\ttam=999424\tuso=0', 'iph': '172.18.0.1', 'ido': None, 'npc': None, 'idc': None, 'ida': None} INFO:root:iph (172.18.0.1) cfg (ser=2SFR6D3 disk=1 par=0 cpt=2 fsi= soi= tam=1000204632 uso=0 disk=1 par=1 cpt=EF00 fsi=FAT32 soi=GRUB2 Loader tam=524288 uso=2 disk=1 par=2 cpt=8300 fsi=EXT4 soi=GRUB2 Loader tam=749568 uso=42 disk=1 par=3 cpt=8300 fsi=CRYPTO_LUKS soi=DATA tam=998929408 uso=11421 disk=2 par=0 cpt=3 fsi= soi= tam=998913024 uso=0 disk=2 par=1 cpt=10000 fsi=EXT4 soi=Ubuntu 22.10 tam=975560704 uso=61 disk=2 par=2 cpt=10000 fsi=LINUX-SWAP soi= tam=999424 uso=0) INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/InclusionCliente HTTP/1.1" 200 - ``` The oglive agent POSTs to `/AutoexecCliente`: ``` INFO:root:{'exe': 42, 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:iph (172.18.0.1) exe (42) INFO:root:fileautoexec (/tmp/Sautoexec-172.18.0.1) INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/AutoexecCliente HTTP/1.1" 200 - ``` The oglive agent POSTs to `/enviaArchivo`: ``` INFO:root:{'nfl': '/tmp/Sautoexec-172.18.0.1', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:nfl (/tmp/Sautoexec-172.18.0.1) INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/enviaArchivo HTTP/1.1" 200 - ``` The oglive agent POSTs to `/ComandosPendientes`: ``` INFO:root:{'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:iph (172.18.0.1) ido (42) INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:20] "POST /opengnsys/rest/__ogAdmClient/ComandosPendientes HTTP/1.1" 200 - ``` The oglive agent POSTs to `/DisponibilidadComandos`: ``` INFO:root:{'tpc': 'OPG', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:iph (172.18.0.1) tpc (OPG) INFO:werkzeug:192.168.1.249 - - [08/Aug/2024 11:42:22] "POST /opengnsys/rest/__ogAdmClient/DisponibilidadComandos HTTP/1.1" 200 - ``` ### Agent log output Basic initialisation: ``` root@tau:/home/nati/Downloads/work/opengnsys/ogagent/src# PYTHONPATH=. python3 opengnsys/linux/OGAgentService.py fg INFO 2024-08-08 11:42:16,641 (MainThread) (__init__) ---------------------------------------- INFO 2024-08-08 11:42:16,641 (MainThread) (__init__) Initializing OpenGnsys Agent DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Loaded configuration from opengnsys.cfg: DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Section opengnsys = [('address', '0.0.0.0'), ('port', '8000'), ('path', 'test_modules/server'), ('remote', 'https://192.168.1.249/opengnsys/rest'), ('level', 'full'), ('log', 'DEBUG')] DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Section ogAdmClient = [('remote', 'https://192.168.1.249/opengnsys/rest/__ogAdmClient'), ('log', 'DEBUG'), ('pathinterface', '/home/nati/Downloads/work/opengnsys/opengnsys/admin/Interface'), ('urlmenu', 'https://192.168.2.1/opengnsys/varios/menubrowser.php'), ('urlmsg', 'http://localhost/cgi-bin/httpd-log.sh')] DEBUG 2024-08-08 11:42:16,641 (MainThread) (__init__) Socket timeout: 20 ``` Modules are found and loaded: ``` DEBUG 2024-08-08 11:42:16,655 (MainThread) (loadModules) Loading modules from ('/home/nati/Downloads/work/opengnsys/ogagent/src/test_modules/server',) DEBUG 2024-08-08 11:42:16,656 (MainThread) (doLoad) Found module package opengnsys.modules.server.Sample1 DEBUG 2024-08-08 11:42:16,656 (MainThread) (doLoad) Found module package opengnsys.modules.server.ogAdmClient DEBUG 2024-08-08 11:42:16,656 (MainThread) (loadModules) Adding server classes DEBUG 2024-08-08 11:42:16,656 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.OpenGnSys.OpenGnSysWorker'> DEBUG 2024-08-08 11:42:16,656 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.Sample1.sample1.Sample1'> DEBUG 2024-08-08 11:42:16,656 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.ogAdmClient.ogAdmClientWorker'> DEBUG 2024-08-08 11:42:16,656 (MainThread) (__init__) Modules: ['opengnsys', 'Sample1', 'ogAdmClient'] DEBUG 2024-08-08 11:42:16,656 (MainThread) (run) ** Running Daemon ** DEBUG 2024-08-08 11:42:16,656 (MainThread) (initialize) Starting IPC listener at 10398 DEBUG 2024-08-08 11:42:16,658 (MainThread) (__init__) Initialized HTTPS Server thread on ('0.0.0.0', 8000) ``` Modules are activated, first the "opengnsys" module: ``` DEBUG 2024-08-08 11:42:16,658 (MainThread) (initialize) Activating module opengnsys DEBUG 2024-08-08 11:42:16,662 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': '02:42:9c:87:1a:9f', 'ip': '172.18.0.1', 'secret': 's5rq30425lwy0lyn3q2jgugfk2zmmnpe', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.10', 'agent_version': '0'} DEBUG 2024-08-08 11:42:16,662 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/ogagent/started DEBUG 2024-08-08 11:42:16,662 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/ogagent/started, data: {"mac": "02:42:9c:87:1a:9f", "ip": "172.18.0.1", "secret": "s5rq30425lwy0lyn3q2jgugfk2zmmnpe", "ostype": "Linux", "osversion": "Ubuntu 22.10", "agent_version": "0"} DEBUG 2024-08-08 11:42:16,663 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443 DEBUG 2024-08-08 11:42:16,668 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/ogagent/started HTTP/1.1" 200 3 DEBUG 2024-08-08 11:42:16,668 (MainThread) (onActivation) Successful connection after 0 tries ``` Now the "Sample1" module (a dummy one that I will probably remove in the future): ``` DEBUG 2024-08-08 11:42:16,668 (MainThread) (initialize) Activating module Sample1 ``` And now the "ogAdmClient" module, which does a lot of things. Get its own IP address: ``` DEBUG 2024-08-08 11:42:16,668 (MainThread) (initialize) Activating module ogAdmClient DEBUG 2024-08-08 11:42:16,668 (MainThread) (interfaceAdmin) subprocess.run ("['bash', '-c', '\n PATH=/home/nati/Downloads/work/opengnsys/opengnsys/client/shared/scripts:$PATH;\n for I in /home/nati/Downloads/work/opengnsys/opengnsys/client/engine/*.lib; do source $I; done;\n for i in $(declare -F |cut -f3 -d" "); do export -f $i; done;\n /home/nati/Downloads/work/opengnsys/opengnsys/admin/Interface/getIpAddress']", capture_output=True) INFO 2024-08-08 11:42:16,737 (MainThread) (tomaIPlocal) local IP is "172.18.0.1" ``` Sends a POST to `InclusionCliente`: ``` INFO 2024-08-08 11:42:16,738 (MainThread) (onActivation) Inicio de sesion INFO 2024-08-08 11:42:16,738 (MainThread) (onActivation) Abriendo sesión en el servidor de Administración DEBUG 2024-08-08 11:42:16,738 (MainThread) (interfaceAdmin) subprocess.run ("['bash', '-c', '\n PATH=/home/nati/Downloads/work/opengnsys/opengnsys/client/shared/scripts:$PATH;\n for I in /home/nati/Downloads/work/opengnsys/opengnsys/client/engine/*.lib; do source $I; done;\n for i in $(declare -F |cut -f3 -d" "); do export -f $i; done;\n /home/nati/Downloads/work/opengnsys/opengnsys/admin/Interface/getConfiguration']", capture_output=True) DEBUG 2024-08-08 11:42:20,540 (MainThread) (LeeConfiguracion) parametroscfg (ser=2SFR6D3 disk=1 par=0 cpt=2 fsi= soi= tam=1000204632 uso=0 disk=1 par=1 cpt=EF00 fsi=FAT32 soi=GRUB2 Loader tam=524288 uso=2 disk=1 par=2 cpt=8300 fsi=EXT4 soi=GRUB2 Loader tam=749568 uso=42 disk=1 par=3 cpt=8300 fsi=CRYPTO_LUKS soi=DATA tam=998929408 uso=11421 disk=2 par=0 cpt=3 fsi= soi= tam=998913024 uso=0 disk=2 par=1 cpt=10000 fsi=EXT4 soi=Ubuntu 22.10 tam=975560704 uso=61 disk=2 par=2 cpt=10000 fsi=LINUX-SWAP soi= tam=999424 uso=0) DEBUG 2024-08-08 11:42:20,540 (MainThread) (sendMessage) Invoking post message InclusionCliente with data {'cfg': 'ser=2SFR6D3\ndisk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=1000204632\tuso=0\ndisk=1\tpar=1\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=524288\tuso=2\ndisk=1\tpar=2\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=749568\tuso=42\ndisk=1\tpar=3\tcpt=8300\tfsi=CRYPTO_LUKS\tsoi=DATA\ttam=998929408\tuso=11421\ndisk=2\tpar=0\tcpt=3\tfsi=\tsoi=\ttam=998913024\tuso=0\ndisk=2\tpar=1\tcpt=10000\tfsi=EXT4\tsoi=Ubuntu 22.10 \ttam=975560704\tuso=61\ndisk=2\tpar=2\tcpt=10000\tfsi=LINUX-SWAP\tsoi=\ttam=999424\tuso=0', 'iph': '172.18.0.1', 'ido': None, 'npc': None, 'idc': None, 'ida': None} DEBUG 2024-08-08 11:42:20,540 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/InclusionCliente DEBUG 2024-08-08 11:42:20,540 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/InclusionCliente, data: {"cfg": "ser=2SFR6D3\ndisk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=1000204632\tuso=0\ndisk=1\tpar=1\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=524288\tuso=2\ndisk=1\tpar=2\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=749568\tuso=42\ndisk=1\tpar=3\tcpt=8300\tfsi=CRYPTO_LUKS\tsoi=DATA\ttam=998929408\tuso=11421\ndisk=2\tpar=0\tcpt=3\tfsi=\tsoi=\ttam=998913024\tuso=0\ndisk=2\tpar=1\tcpt=10000\tfsi=EXT4\tsoi=Ubuntu 22.10 \ttam=975560704\tuso=61\ndisk=2\tpar=2\tcpt=10000\tfsi=LINUX-SWAP\tsoi=\ttam=999424\tuso=0", "iph": "172.18.0.1", "ido": null, "npc": null, "idc": null, "ida": null} DEBUG 2024-08-08 11:42:20,540 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443 DEBUG 2024-08-08 11:42:20,544 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/InclusionCliente HTTP/1.1" 200 106 DEBUG 2024-08-08 11:42:20,544 (MainThread) (inclusionCliente) res ({'che': 42, 'exe': 42, 'ida': 42, 'idc': 42, 'ido': 42, 'npc': 'hal9000', 'res': 1}) INFO 2024-08-08 11:42:20,544 (MainThread) (onActivation) Cliente iniciado ``` Sends a POST to `AutoexecCliente`: ``` INFO 2024-08-08 11:42:20,544 (MainThread) (onActivation) Procesando caché INFO 2024-08-08 11:42:20,544 (MainThread) (onActivation) Ejecución de archivo Autoexec DEBUG 2024-08-08 11:42:20,544 (MainThread) (sendMessage) Invoking post message AutoexecCliente with data {'exe': 42, 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} DEBUG 2024-08-08 11:42:20,544 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/AutoexecCliente DEBUG 2024-08-08 11:42:20,544 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/AutoexecCliente, data: {"exe": 42, "iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42} DEBUG 2024-08-08 11:42:20,545 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443 DEBUG 2024-08-08 11:42:20,548 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/AutoexecCliente HTTP/1.1" 200 54 DEBUG 2024-08-08 11:42:20,548 (MainThread) (autoexecCliente) res ({'nfl': '/tmp/Sautoexec-172.18.0.1', 'res': 1}) INFO 2024-08-08 11:42:20,548 (MainThread) (autoexecCliente) {'nfl': '/tmp/Sautoexec-172.18.0.1', 'res': 1} DEBUG 2024-08-08 11:42:20,548 (MainThread) (sendMessage) Invoking post message enviaArchivo with data {'nfl': '/tmp/Sautoexec-172.18.0.1', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} DEBUG 2024-08-08 11:42:20,548 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/enviaArchivo DEBUG 2024-08-08 11:42:20,548 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/enviaArchivo, data: {"nfl": "/tmp/Sautoexec-172.18.0.1", "iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42} DEBUG 2024-08-08 11:42:20,549 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443 DEBUG 2024-08-08 11:42:20,553 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/enviaArchivo HTTP/1.1" 200 67 DEBUG 2024-08-08 11:42:20,553 (MainThread) (autoexecCliente) fileautoexec (/tmp/_autoexec_172.18.0.1) DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) fn (/tmp/_autoexec_172.18.0.1) ``` (this "popup" is development stuff) ``` DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) buffer (nfn=popup\rtitle=my title\rmessage=my message@) message=my message):42:20,554 (MainThread) (ejecutaArchivo) line (nfn=popup DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) post_params "{'nfn': 'popup', 'title': 'my title', 'message': 'my message'}" DEBUG 2024-08-08 11:42:20,554 (MainThread) (ejecutaArchivo) calling function "popup" with post_params "{'title': 'my title', 'message': 'my message'}" DEBUG 2024-08-08 11:42:20,554 (MainThread) (process_popup) in process_popup, path "[]" get_params "{}" post_params "{'title': 'my title', 'message': 'my message'}" server "None" DEBUG 2024-08-08 11:42:20,554 (MainThread) (process_popup) type(post_params) "<class 'dict'>" DEBUG 2024-08-08 11:42:20,555 (MainThread) (ejecutaArchivo) output "{'debug': 'test'}" ``` Sends a POST to `ComandosPendientes`: ``` INFO 2024-08-08 11:42:20,555 (MainThread) (onActivation) Procesa comandos pendientes DEBUG 2024-08-08 11:42:20,555 (MainThread) (sendMessage) Invoking post message ComandosPendientes with data {'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} DEBUG 2024-08-08 11:42:20,555 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/ComandosPendientes DEBUG 2024-08-08 11:42:20,555 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/ComandosPendientes, data: {"iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42} DEBUG 2024-08-08 11:42:20,555 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443 DEBUG 2024-08-08 11:42:20,558 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/ComandosPendientes HTTP/1.1" 200 30 INFO 2024-08-08 11:42:20,559 (MainThread) (comandosPendientes) {'nfn': 'NoComandosPtes'} INFO 2024-08-08 11:42:20,559 (MainThread) (onActivation) Acciones pendientes procesadas ``` Sends a POST to `DisponibilidadComandos`: ``` DEBUG 2024-08-08 11:42:22,571 (MainThread) (sendMessage) Invoking post message DisponibilidadComandos with data {'tpc': 'OPG', 'iph': '172.18.0.1', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} DEBUG 2024-08-08 11:42:22,571 (MainThread) (sendMessage) Requesting https://192.168.1.249/opengnsys/rest/__ogAdmClient/DisponibilidadComandos DEBUG 2024-08-08 11:42:22,571 (MainThread) (_request) Requesting using POST https://192.168.1.249/opengnsys/rest/__ogAdmClient/DisponibilidadComandos, data: {"tpc": "OPG", "iph": "172.18.0.1", "ido": 42, "npc": "hal9000", "idc": 42, "ida": 42} DEBUG 2024-08-08 11:42:22,573 (MainThread) (_new_conn) Starting new HTTPS connection (1): 192.168.1.249:443 DEBUG 2024-08-08 11:42:22,582 (MainThread) (_make_request) https://192.168.1.249:443 "POST /opengnsys/rest/__ogAdmClient/DisponibilidadComandos HTTP/1.1" 200 3 DEBUG 2024-08-08 11:42:22,583 (MainThread) (procesaComandos) res ({}) INFO 2024-08-08 11:42:22,583 (MainThread) (procesaComandos) Disponibilidad de comandos activada DEBUG 2024-08-08 11:42:22,583 (MainThread) (initialize) Modules after activation: ['opengnsys', 'Sample1', 'ogAdmClient'] ``` ## Cleanup Press ^C to terminate the agent. Press ^C in the other terminal to terminate the ogserver. `rm -f /tmp/Sautoexec-* /tmp/_autoexec_* /var/run/opengnsys-agent.pid`
nserrano added 14 commits 2024-08-07 15:01:01 +02:00
nserrano changed title from Initial, very incomplete implementation of ogAdmClient in python to WIP: Initial, very incomplete implementation of ogAdmClient in python 2024-08-07 15:01:25 +02:00
nserrano added 1 commit 2024-08-08 12:06:57 +02:00
nserrano requested review from lgromero 2024-08-08 12:48:37 +02:00
nserrano requested review from vtroshchinskiy 2024-08-08 12:48:37 +02:00
nserrano requested review from aguerrero 2024-08-08 12:48:37 +02:00
nserrano requested review from arantuna 2024-08-08 12:48:38 +02:00
nserrano requested review from maranda 2024-08-08 12:48:38 +02:00
nserrano requested review from ggil 2024-08-08 12:48:38 +02:00
nserrano changed title from WIP: Initial, very incomplete implementation of ogAdmClient in python to Initial, very incomplete implementation of ogAdmClient in python 2024-08-08 12:50:04 +02:00
Collaborator

Arroja error cargando librerías:

root@ubuntu2204:/home/arantuna/git/ogagent/src# PYTHONPATH=. python3 opengnsys/linux/OGAgentService.py fg
INFO 2024-08-20 18:45:04,981 (MainThread) (__init__) ----------------------------------------
INFO 2024-08-20 18:45:04,981 (MainThread) (__init__) Initializing OpenGnsys Agent
DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Loaded configuration from opengnsys.cfg:
DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Section opengnsys = [('address', '0.0.0.0'), ('port', '8000'), ('path', 'test_modules/server'), ('remote', 'https://10.80.23.229/opengnsys/rest/'), ('level', 'full'), ('log', 'DEBUG')]
DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Section ogAdmClient = [('remote', 'https://10.80.23.229/opengnsys/rest/__ogAdmClient'), ('log', 'DEBUG'), ('pathinterface', '/home/arantuna/git/opengnsys/admin/Interface'), ('urlmenu', 'https://localhost/opengnsys/varios/menubrowser.php'), ('urlmsg', 'http://localhost/cgi-bin/httpd-log.sh')]
DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Socket timeout: 20
DEBUG 2024-08-20 18:45:05,006 (MainThread) (loadModules) Loading modules from ('/home/arantuna/git/ogagent/src/test_modules/server',)
DEBUG 2024-08-20 18:45:05,006 (MainThread) (doLoad) Found module package opengnsys.modules.server.Sample1
DEBUG 2024-08-20 18:45:05,007 (MainThread) (doLoad) Found module package opengnsys.modules.server.ogAdmClient
Traceback (most recent call last):
  File "/home/arantuna/git/ogagent/src/opengnsys/linux/OGAgentService.py", line 128, in <module>
    daemon = OGAgentSvc()
  File "/home/arantuna/git/ogagent/src/opengnsys/linux/OGAgentService.py", line 56, in __init__
    CommonService.__init__(self)
  File "/home/arantuna/git/ogagent/src/opengnsys/service.py", line 83, in __init__
    self.modules = loadModules(self)
  File "/home/arantuna/git/ogagent/src/opengnsys/loader.py", line 105, in loadModules
    doLoad(paths)
  File "/home/arantuna/git/ogagent/src/opengnsys/loader.py", line 93, in doLoad
    module_loader.find_module(name).load_module(name)
  File "<frozen importlib._bootstrap_external>", line 548, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 1063, in load_module
  File "<frozen importlib._bootstrap_external>", line 888, in load_module
  File "<frozen importlib._bootstrap>", line 290, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 719, in _load
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/arantuna/git/ogagent/src/test_modules/server/ogAdmClient/__init__.py", line 51, in <module>
    from opengnsys.scriptThread import ScriptExecutorThread
ModuleNotFoundError: No module named 'opengnsys.scriptThread'
Arroja error cargando librerías: ``` root@ubuntu2204:/home/arantuna/git/ogagent/src# PYTHONPATH=. python3 opengnsys/linux/OGAgentService.py fg INFO 2024-08-20 18:45:04,981 (MainThread) (__init__) ---------------------------------------- INFO 2024-08-20 18:45:04,981 (MainThread) (__init__) Initializing OpenGnsys Agent DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Loaded configuration from opengnsys.cfg: DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Section opengnsys = [('address', '0.0.0.0'), ('port', '8000'), ('path', 'test_modules/server'), ('remote', 'https://10.80.23.229/opengnsys/rest/'), ('level', 'full'), ('log', 'DEBUG')] DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Section ogAdmClient = [('remote', 'https://10.80.23.229/opengnsys/rest/__ogAdmClient'), ('log', 'DEBUG'), ('pathinterface', '/home/arantuna/git/opengnsys/admin/Interface'), ('urlmenu', 'https://localhost/opengnsys/varios/menubrowser.php'), ('urlmsg', 'http://localhost/cgi-bin/httpd-log.sh')] DEBUG 2024-08-20 18:45:04,982 (MainThread) (__init__) Socket timeout: 20 DEBUG 2024-08-20 18:45:05,006 (MainThread) (loadModules) Loading modules from ('/home/arantuna/git/ogagent/src/test_modules/server',) DEBUG 2024-08-20 18:45:05,006 (MainThread) (doLoad) Found module package opengnsys.modules.server.Sample1 DEBUG 2024-08-20 18:45:05,007 (MainThread) (doLoad) Found module package opengnsys.modules.server.ogAdmClient Traceback (most recent call last): File "/home/arantuna/git/ogagent/src/opengnsys/linux/OGAgentService.py", line 128, in <module> daemon = OGAgentSvc() File "/home/arantuna/git/ogagent/src/opengnsys/linux/OGAgentService.py", line 56, in __init__ CommonService.__init__(self) File "/home/arantuna/git/ogagent/src/opengnsys/service.py", line 83, in __init__ self.modules = loadModules(self) File "/home/arantuna/git/ogagent/src/opengnsys/loader.py", line 105, in loadModules doLoad(paths) File "/home/arantuna/git/ogagent/src/opengnsys/loader.py", line 93, in doLoad module_loader.find_module(name).load_module(name) File "<frozen importlib._bootstrap_external>", line 548, in _check_name_wrapper File "<frozen importlib._bootstrap_external>", line 1063, in load_module File "<frozen importlib._bootstrap_external>", line 888, in load_module File "<frozen importlib._bootstrap>", line 290, in _load_module_shim File "<frozen importlib._bootstrap>", line 719, in _load File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/home/arantuna/git/ogagent/src/test_modules/server/ogAdmClient/__init__.py", line 51, in <module> from opengnsys.scriptThread import ScriptExecutorThread ModuleNotFoundError: No module named 'opengnsys.scriptThread' ```
Poster
Collaborator

Qué raro. ¿No tienes un archivo opengnsys/scriptThread.py?

$ git branch; ls -l opengnsys/scriptThread.py
  main
* ogadmcli
  ogagent-jobs
  ogagent-macos
  py3-win
  python3
  versions
  windows-fixes
-rw-r--r-- 1 nati nati 2156 20240807:140454+0200 opengnsys/scriptThread.py
Qué raro. ¿No tienes un archivo opengnsys/scriptThread.py? ``` $ git branch; ls -l opengnsys/scriptThread.py main * ogadmcli ogagent-jobs ogagent-macos py3-win python3 versions windows-fixes -rw-r--r-- 1 nati nati 2156 20240807:140454+0200 opengnsys/scriptThread.py ```
Collaborator

Hola Natalia,

no, no tengo ese archivo

arantuna@ubuntu2204:~/git/ogagent/src$` git branch; ls -l opengnsys/scriptThread.py
  main
* ogadmcli
  ogagent-jobs
  ogagent-macos
  py3-win
  remote
  remove
ls: cannot access 'opengnsys/scriptThread.py': No such file or directory
arantuna@ubuntu2204:~/git/ogagent/src$ git status
On branch ogadmcli
Your branch is up to date with 'origin/ogadmcli'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   cfg/ogagent.cfg
	modified:   test_modules/server/ogAdmClient/__init__.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	../arantuna@10.80.23.229

no changes added to commit (use "git add" and/or "git commit -a")

(Esos cambios son los que he seguido para hacer la PR; evidentemente no llevan commit).

Hola Natalia, no, no tengo ese archivo ``` arantuna@ubuntu2204:~/git/ogagent/src$` git branch; ls -l opengnsys/scriptThread.py main * ogadmcli ogagent-jobs ogagent-macos py3-win remote remove ls: cannot access 'opengnsys/scriptThread.py': No such file or directory arantuna@ubuntu2204:~/git/ogagent/src$ git status On branch ogadmcli Your branch is up to date with 'origin/ogadmcli'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: cfg/ogagent.cfg modified: test_modules/server/ogAdmClient/__init__.py Untracked files: (use "git add <file>..." to include in what will be committed) ../arantuna@10.80.23.229 no changes added to commit (use "git add" and/or "git commit -a") ``` (Esos cambios son los que he seguido para hacer la PR; evidentemente no llevan commit).
nserrano added 1 commit 2024-08-21 14:38:16 +02:00
Poster
Collaborator

La causa última es que esta rama en mi portátil se bifurcaba desde un punto anterior al mergeo del job manager, y al hacer un clone nuevo esta rama se bifurca desde un punto posterior. La rama del job manager borra el archivo que te faltaba, y de ahí la divergencia. Algún actor debe de haber hecho un rebase de esta rama pero no sé quién, ni cuándo, ni por qué.

El archivo realmente no te falta, porque no debe estar. Me sobraba a mí. He hecho un commit para borrar código inútil (que iba a borrar más tarde anyway). Ya debería funcionar.

La causa última es que esta rama en mi portátil se bifurcaba desde un punto anterior al mergeo del job manager, y al hacer un clone nuevo esta rama se bifurca desde un punto posterior. La rama del job manager borra el archivo que te faltaba, y de ahí la divergencia. Algún actor debe de haber hecho un rebase de esta rama pero no sé quién, ni cuándo, ni por qué. El archivo realmente no te falta, porque no debe estar. Me sobraba a mí. He hecho un commit para borrar código inútil (que iba a borrar más tarde anyway). Ya debería funcionar.
nserrano force-pushed ogadmcli from ded1e70ef5 to 25cfb31725 2024-08-21 14:44:35 +02:00 Compare
Collaborator

Ahora he avanzado un poco más, ya levanta, pero da problemas de SSL, ¿algún paso que falte?

INFO 2024-08-21 19:32:18,887 (MainThread) (__init__) Initializing OpenGnsys Agent
DEBUG 2024-08-21 19:32:18,888 (MainThread) (__init__) Loaded configuration from opengnsys.cfg:
DEBUG 2024-08-21 19:32:18,889 (MainThread) (__init__) Section opengnsys = [('address', '0.0.0.0'), ('port', '8000'), ('path', 'test_modules/server'), ('remote', 'https://10.80.23.229/opengnsys/rest'), ('level', 'full'), ('log', 'DEBUG')]
DEBUG 2024-08-21 19:32:18,889 (MainThread) (__init__) Section ogAdmClient = [('remote', 'https://10.80.23.229/opengnsys/rest/__ogAdmClient'), ('log', 'DEBUG'), ('pathinterface', '/home/arantuna/git/opengnsys/admin/Interface'), ('urlmenu', 'https://192.168.2.1/opengnsys/varios/menubrowser.php'), ('urlmsg', 'http://localhost/cgi-bin/httpd-log.sh')]
DEBUG 2024-08-21 19:32:18,890 (MainThread) (__init__) Socket timeout: 20
DEBUG 2024-08-21 19:32:18,928 (MainThread) (loadModules) Loading modules from ('/home/arantuna/git/ogagent/src/test_modules/server',)
DEBUG 2024-08-21 19:32:18,929 (MainThread) (doLoad) Found module package opengnsys.modules.server.Sample1
DEBUG 2024-08-21 19:32:18,930 (MainThread) (doLoad) Found module package opengnsys.modules.server.ogAdmClient
DEBUG 2024-08-21 19:32:18,935 (MainThread) (loadModules) Adding server classes
DEBUG 2024-08-21 19:32:18,935 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.OpenGnSys.OpenGnSysWorker'>
DEBUG 2024-08-21 19:32:18,935 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.Sample1.sample1.Sample1'>
DEBUG 2024-08-21 19:32:18,936 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.ogAdmClient.ogAdmClientWorker'>
DEBUG 2024-08-21 19:32:18,936 (MainThread) (__init__) Modules: ['opengnsys', 'Sample1', 'ogAdmClient']
DEBUG 2024-08-21 19:32:18,936 (MainThread) (run) ** Running Daemon **
DEBUG 2024-08-21 19:32:18,937 (MainThread) (initialize) Starting IPC listener at 10398
DEBUG 2024-08-21 19:32:18,945 (MainThread) (__init__) Initialized HTTPS Server thread on ('0.0.0.0', 8000)
DEBUG 2024-08-21 19:32:18,946 (MainThread) (initialize) Activating module opengnsys
DEBUG 2024-08-21 19:32:18,953 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '64fwk624x0rrllpq8u142dbh89s481di', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.2 LTS', 'agent_version': '0'}
DEBUG 2024-08-21 19:32:18,954 (MainThread) (sendMessage) Requesting https://10.80.23.229/opengnsys/rest/ogagent/started
DEBUG 2024-08-21 19:32:18,954 (MainThread) (_request) Requesting using POST https://10.80.23.229/opengnsys/rest/ogagent/started, data: {"mac": "c2:ad:a3:3d:1f:ef", "ip": "10.80.23.229", "secret": "64fwk624x0rrllpq8u142dbh89s481di", "ostype": "Linux", "osversion": "Ubuntu 22.04.2 LTS", "agent_version": "0"}
DEBUG 2024-08-21 19:32:18,957 (MainThread) (_new_conn) Starting new HTTPS connection (1): 10.80.23.229:443
WARNING 2024-08-21 19:32:18,960 (MainThread) (onActivation) HTTPSConnectionPool(host='10.80.23.229', port=443): Max retries exceeded with url: /opengnsys/rest/ogagent/started (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)')))
WARNING 2024-08-21 19:32:18,961 (MainThread) (onActivation) No option 'altremote' in section: 'opengnsys'
DEBUG 2024-08-21 19:32:21,964 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '64fwk624x0rrllpq8u142dbh89s481di', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.2 LTS', 'agent_version': '0'}
DEBUG 2024-08-21 19:32:21,965 (MainThread) (sendMessage) Requesting https://10.80.23.229/opengnsys/rest/ogagent/started
DEBUG 2024-08-21 19:32:21,965 (MainThread) (_request) Requesting using POST https://10.80.23.229/opengnsys/rest/ogagent/started, data: {"mac": "c2:ad:a3:3d:1f:ef", "ip": "10.80.23.229", "secret": "64fwk624x0rrllpq8u142dbh89s481di", "ostype": "Linux", "osversion": "Ubuntu 22.04.2 LTS", "agent_version": "0"}
DEBUG 2024-08-21 19:32:21,966 (MainThread) (_new_conn) Starting new HTTPS connection (1): 10.80.23.229:443
WARNING 2024-08-21 19:32:21,968 (MainThread) (onActivation) HTTPSConnectionPool(host='10.80.23.229', port=443): Max retries exceeded with url: /opengnsys/rest/ogagent/started (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)')))
WARNING 2024-08-21 19:32:21,968 (MainThread) (onActivation) No option 'altremote' in section: 'opengnsys'
DEBUG 2024-08-21 19:32:24,972 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '64fwk624x0rrllpq8u142dbh89s481di', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.2 LTS', 'agent_version': '0'}
DEBUG 2024-08-21 19:32:24,972 (MainThread) (sendMessage) Requesting https://10.80.23.229/opengnsys/rest/ogagent/started
DEBUG 2024-08-21 19:32:24,973 (MainThread) (_request) Requesting using POST https://10.80.23.229/opengnsys/rest/ogagent/started, data: {"mac": "c2:ad:a3:3d:1f:ef", "ip": "10.80.23.229", "secret": "64fwk624x0rrllpq8u142dbh89s481di", "ostype": "Linux", "osversion": "Ubuntu 22.04.2 LTS", "agent_version": "0"}
DEBUG 2024-08-21 19:32:24,974 (MainThread) (_new_conn) Starting new HTTPS connection (1): 10.80.23.229:443
WARNING 2024-08-21 19:32:24,976 (MainThread) (onActivation) HTTPSConnectionPool(host='10.80.23.229', port=443): Max retries exceeded with url: /opengnsys/rest/ogagent/started (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)')))
WARNING 2024-08-21 19:32:24,976 (MainThread) (onActivation) No option 'altremote' in section: 'opengnsys'
:

En la contra parte, se reciben estos errores

ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:56] code 400, message Bad request version ("|z´[*\x12\x11@5µ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À")
INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:56] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03\x90 K\x1eŵ\x1dí[\x1b£\x8c¥§âc­\x1aFØ\x97=%8ê\x0eÙ»\x17\x1döð <u\x9cjúôÌwº"5\x8eß\x16mD\x1d¶ç\x07\x9e\x1f|z´[*\x12\x11@5µ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST -
ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:59] code 400, message Bad request version ("\x1b.!ÍHè÷W#\x05÷\x905\x08ðy.%È(W5\x89þk^8Üéó>¿\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À")
INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:59] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03\x84Øñu\x84²\x06×\x0eKC\x0cduèza\x01~1³\x02w}?@E¨\x11¾\x1aµ \x1b.!ÍHè÷W#\x05÷\x905\x08ðy.%È(W5\x89þk^8Üéó>¿\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST -
ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:02] code 400, message Bad request version ("rV.^ó\x88lú,ÁÖ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À")
INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:02] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03¬\x0bÍ\x846iý\x01\x16\x8cN#¾Þ\x0f\x0b\x82\x97\x9e\x8díº\x12s_Ü@³}\x8d@Î \x8aú~\x1eî\x93éç\x11\x1dG\x0eÞ§ÿ°ßî\x0d© rV.^ó\x88lú,ÁÖ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST -
ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:05] code 400, message Bad request syntax ('\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03;låMè\x80ú\x919·\x94mº²¾"\x19«é\x8c"\x14\x89Ê"\x13£ñ½ÃÈ')
INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:05] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03;låMè\x80ú\x919·\x94mº²¾"\x19«é\x8c"\x14\x89Ê"\x13£ñ½ÃÈ" HTTPStatus.BAD_REQUEST -
ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:08] code 400, message Bad request version ("@Ñ\x8d\x8dMìSc³\x00\x12z\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À")
INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:08] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03\x00NüÝî\x08\x9c0|\x92#\x00Qk·È\x1fÿ-\x18±©$\x8c!è»\x08­èB\x8e ÌPò\x0b\x9e°!\x17Êëó\x8d¿>=T/n\x9e\x09@Ñ\x8d\x8dMìSc³\x00\x12z\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST -
ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:11] code 400, message Bad HTTP/0.9 request type ('\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03ãÜ\x16óC;')
INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:11] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03ãÜ\x16óC;\x0d\x1aÄ[úÈÔ8¶Vf}" HTTPStatus.BAD_REQUEST -
Ahora he avanzado un poco más, ya levanta, pero da problemas de SSL, ¿algún paso que falte? ``` INFO 2024-08-21 19:32:18,887 (MainThread) (__init__) Initializing OpenGnsys Agent DEBUG 2024-08-21 19:32:18,888 (MainThread) (__init__) Loaded configuration from opengnsys.cfg: DEBUG 2024-08-21 19:32:18,889 (MainThread) (__init__) Section opengnsys = [('address', '0.0.0.0'), ('port', '8000'), ('path', 'test_modules/server'), ('remote', 'https://10.80.23.229/opengnsys/rest'), ('level', 'full'), ('log', 'DEBUG')] DEBUG 2024-08-21 19:32:18,889 (MainThread) (__init__) Section ogAdmClient = [('remote', 'https://10.80.23.229/opengnsys/rest/__ogAdmClient'), ('log', 'DEBUG'), ('pathinterface', '/home/arantuna/git/opengnsys/admin/Interface'), ('urlmenu', 'https://192.168.2.1/opengnsys/varios/menubrowser.php'), ('urlmsg', 'http://localhost/cgi-bin/httpd-log.sh')] DEBUG 2024-08-21 19:32:18,890 (MainThread) (__init__) Socket timeout: 20 DEBUG 2024-08-21 19:32:18,928 (MainThread) (loadModules) Loading modules from ('/home/arantuna/git/ogagent/src/test_modules/server',) DEBUG 2024-08-21 19:32:18,929 (MainThread) (doLoad) Found module package opengnsys.modules.server.Sample1 DEBUG 2024-08-21 19:32:18,930 (MainThread) (doLoad) Found module package opengnsys.modules.server.ogAdmClient DEBUG 2024-08-21 19:32:18,935 (MainThread) (loadModules) Adding server classes DEBUG 2024-08-21 19:32:18,935 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.OpenGnSys.OpenGnSysWorker'> DEBUG 2024-08-21 19:32:18,935 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.Sample1.sample1.Sample1'> DEBUG 2024-08-21 19:32:18,936 (MainThread) (addCls) Found module class <class 'opengnsys.modules.server.ogAdmClient.ogAdmClientWorker'> DEBUG 2024-08-21 19:32:18,936 (MainThread) (__init__) Modules: ['opengnsys', 'Sample1', 'ogAdmClient'] DEBUG 2024-08-21 19:32:18,936 (MainThread) (run) ** Running Daemon ** DEBUG 2024-08-21 19:32:18,937 (MainThread) (initialize) Starting IPC listener at 10398 DEBUG 2024-08-21 19:32:18,945 (MainThread) (__init__) Initialized HTTPS Server thread on ('0.0.0.0', 8000) DEBUG 2024-08-21 19:32:18,946 (MainThread) (initialize) Activating module opengnsys DEBUG 2024-08-21 19:32:18,953 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '64fwk624x0rrllpq8u142dbh89s481di', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.2 LTS', 'agent_version': '0'} DEBUG 2024-08-21 19:32:18,954 (MainThread) (sendMessage) Requesting https://10.80.23.229/opengnsys/rest/ogagent/started DEBUG 2024-08-21 19:32:18,954 (MainThread) (_request) Requesting using POST https://10.80.23.229/opengnsys/rest/ogagent/started, data: {"mac": "c2:ad:a3:3d:1f:ef", "ip": "10.80.23.229", "secret": "64fwk624x0rrllpq8u142dbh89s481di", "ostype": "Linux", "osversion": "Ubuntu 22.04.2 LTS", "agent_version": "0"} DEBUG 2024-08-21 19:32:18,957 (MainThread) (_new_conn) Starting new HTTPS connection (1): 10.80.23.229:443 WARNING 2024-08-21 19:32:18,960 (MainThread) (onActivation) HTTPSConnectionPool(host='10.80.23.229', port=443): Max retries exceeded with url: /opengnsys/rest/ogagent/started (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)'))) WARNING 2024-08-21 19:32:18,961 (MainThread) (onActivation) No option 'altremote' in section: 'opengnsys' DEBUG 2024-08-21 19:32:21,964 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '64fwk624x0rrllpq8u142dbh89s481di', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.2 LTS', 'agent_version': '0'} DEBUG 2024-08-21 19:32:21,965 (MainThread) (sendMessage) Requesting https://10.80.23.229/opengnsys/rest/ogagent/started DEBUG 2024-08-21 19:32:21,965 (MainThread) (_request) Requesting using POST https://10.80.23.229/opengnsys/rest/ogagent/started, data: {"mac": "c2:ad:a3:3d:1f:ef", "ip": "10.80.23.229", "secret": "64fwk624x0rrllpq8u142dbh89s481di", "ostype": "Linux", "osversion": "Ubuntu 22.04.2 LTS", "agent_version": "0"} DEBUG 2024-08-21 19:32:21,966 (MainThread) (_new_conn) Starting new HTTPS connection (1): 10.80.23.229:443 WARNING 2024-08-21 19:32:21,968 (MainThread) (onActivation) HTTPSConnectionPool(host='10.80.23.229', port=443): Max retries exceeded with url: /opengnsys/rest/ogagent/started (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)'))) WARNING 2024-08-21 19:32:21,968 (MainThread) (onActivation) No option 'altremote' in section: 'opengnsys' DEBUG 2024-08-21 19:32:24,972 (MainThread) (sendMessage) Invoking post message ogagent/started with data {'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '64fwk624x0rrllpq8u142dbh89s481di', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.2 LTS', 'agent_version': '0'} DEBUG 2024-08-21 19:32:24,972 (MainThread) (sendMessage) Requesting https://10.80.23.229/opengnsys/rest/ogagent/started DEBUG 2024-08-21 19:32:24,973 (MainThread) (_request) Requesting using POST https://10.80.23.229/opengnsys/rest/ogagent/started, data: {"mac": "c2:ad:a3:3d:1f:ef", "ip": "10.80.23.229", "secret": "64fwk624x0rrllpq8u142dbh89s481di", "ostype": "Linux", "osversion": "Ubuntu 22.04.2 LTS", "agent_version": "0"} DEBUG 2024-08-21 19:32:24,974 (MainThread) (_new_conn) Starting new HTTPS connection (1): 10.80.23.229:443 WARNING 2024-08-21 19:32:24,976 (MainThread) (onActivation) HTTPSConnectionPool(host='10.80.23.229', port=443): Max retries exceeded with url: /opengnsys/rest/ogagent/started (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)'))) WARNING 2024-08-21 19:32:24,976 (MainThread) (onActivation) No option 'altremote' in section: 'opengnsys' : ``` En la contra parte, se reciben estos errores ``` ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:56] code 400, message Bad request version ("|z´[*\x12\x11@5µ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À") INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:56] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03\x90 K\x1eŵ\x1dí[\x1b£\x8c¥§âc­\x1aFØ\x97=%8ê\x0eÙ»\x17\x1döð <u\x9cjúôÌwº"5\x8eß\x16mD\x1d¶ç\x07\x9e\x1f|z´[*\x12\x11@5µ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST - ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:59] code 400, message Bad request version ("\x1b.!ÍHè÷W#\x05÷\x905\x08ðy.%È(W5\x89þk^8Üéó>¿\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À") INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:47:59] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03\x84Øñu\x84²\x06×\x0eKC\x0cduèza\x01~1³\x02w}?@E¨\x11¾\x1aµ \x1b.!ÍHè÷W#\x05÷\x905\x08ðy.%È(W5\x89þk^8Üéó>¿\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST - ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:02] code 400, message Bad request version ("rV.^ó\x88lú,ÁÖ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À") INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:02] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03¬\x0bÍ\x846iý\x01\x16\x8cN#¾Þ\x0f\x0b\x82\x97\x9e\x8díº\x12s_Ü@³}\x8d@Î \x8aú~\x1eî\x93éç\x11\x1dG\x0eÞ§ÿ°ßî\x0d© rV.^ó\x88lú,ÁÖ\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST - ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:05] code 400, message Bad request syntax ('\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03;låMè\x80ú\x919·\x94mº²¾"\x19«é\x8c"\x14\x89Ê"\x13£ñ½ÃÈ') INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:05] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03;låMè\x80ú\x919·\x94mº²¾"\x19«é\x8c"\x14\x89Ê"\x13£ñ½ÃÈ" HTTPStatus.BAD_REQUEST - ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:08] code 400, message Bad request version ("@Ñ\x8d\x8dMìSc³\x00\x12z\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À\xadÀ®À¬À$À(À#À'À") INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:08] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03\x00NüÝî\x08\x9c0|\x92#\x00Qk·È\x1fÿ-\x18±©$\x8c!è»\x08­èB\x8e ÌPò\x0b\x9e°!\x17Êëó\x8d¿>=T/n\x9e\x09@Ñ\x8d\x8dMìSc³\x00\x12z\x00V\x13\x02\x13\x03\x13\x01À,À0À+À/̨̩\x00\x9f\x00\x9e̪À¯À­À®À¬À$À(À#À'À" HTTPStatus.BAD_REQUEST - ERROR:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:11] code 400, message Bad HTTP/0.9 request type ('\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03ãÜ\x16óC;') INFO:werkzeug:10.80.23.229 - - [21/Aug/2024 19:48:11] "\x16\x03\x01\x02\x00\x01\x00\x01ü\x03\x03ãÜ\x16óC;\x0d\x1aÄ[úÈÔ8¶Vf}" HTTPStatus.BAD_REQUEST - ```
Poster
Collaborator

"Wrong version number" ocurre cuando uno de los lados habla HTTP y el otro HTTPS. En este caso parece que el flask está hablando HTTP.

El motivo no nos importa, solo queremos que hablen entre sí, por lo que creo que bastaría con cambiar el cfg/ogagent.cfg y poner remote=http://... en lugar de remote=https://...

"Wrong version number" ocurre cuando uno de los lados habla HTTP y el otro HTTPS. En este caso parece que el flask está hablando HTTP. El motivo no nos importa, solo queremos que hablen entre sí, por lo que creo que bastaría con cambiar el `cfg/ogagent.cfg` y poner `remote=http://...` en lugar de `remote=https://...`
Collaborator

Correcto, con ese cambio, luz.

 * Running on http://10.80.23.229:80
INFO:werkzeug:Press CTRL+C to quit
INFO:root:{'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '3m6hismxo30m50pse5ooyw6nlnhiigf1', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.4 LTS', 'agent_version': '0'}
INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:04] "POST /opengnsys/rest/ogagent/started HTTP/1.1" 200 -
INFO:root:{'cfg': 'disk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=16777216\tuso=0\ndisk=1\tpar=1\tcpt=EF02\tfsi=EMPTY\tsoi=\ttam=1024\tuso=0\ndisk=1\tpar=2\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=525312\tuso=2\ndisk=1\tpar=3\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=16248832\tuso=9595', 'iph': '10.80.23.229', 'ido': None, 'npc': None, 'idc': None, 'ida': None}
INFO:root:iph (10.80.23.229) cfg (disk=1        par=0   cpt=2   fsi=    soi=    tam=16777216    uso=0
disk=1  par=1   cpt=EF02        fsi=EMPTY       soi=    tam=1024        uso=0
disk=1  par=2   cpt=EF00        fsi=FAT32       soi=GRUB2 Loader        tam=525312      uso=2
disk=1  par=3   cpt=8300        fsi=EXT4        soi=GRUB2 Loader        tam=16248832    uso=9595)
INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/InclusionCliente HTTP/1.1" 200 -
INFO:root:{'exe': 42, 'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:iph (10.80.23.229) exe (42)
INFO:root:fileautoexec (/tmp/Sautoexec-10.80.23.229)
INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/AutoexecCliente HTTP/1.1" 200 -
INFO:root:{'nfl': '/tmp/Sautoexec-10.80.23.229', 'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:nfl (/tmp/Sautoexec-10.80.23.229)
INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/enviaArchivo HTTP/1.1" 200 -
INFO:root:{'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:iph (10.80.23.229) ido (42)
INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/ComandosPendientes HTTP/1.1" 200 -
INFO:root:{'tpc': 'OPG', 'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42}
INFO:root:iph (10.80.23.229) tpc (OPG)
INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/DisponibilidadComandos HTTP/1.1" 200 -
Correcto, con ese cambio, luz. ``` * Running on http://10.80.23.229:80 INFO:werkzeug:Press CTRL+C to quit INFO:root:{'mac': 'c2:ad:a3:3d:1f:ef', 'ip': '10.80.23.229', 'secret': '3m6hismxo30m50pse5ooyw6nlnhiigf1', 'ostype': 'Linux', 'osversion': 'Ubuntu 22.04.4 LTS', 'agent_version': '0'} INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:04] "POST /opengnsys/rest/ogagent/started HTTP/1.1" 200 - INFO:root:{'cfg': 'disk=1\tpar=0\tcpt=2\tfsi=\tsoi=\ttam=16777216\tuso=0\ndisk=1\tpar=1\tcpt=EF02\tfsi=EMPTY\tsoi=\ttam=1024\tuso=0\ndisk=1\tpar=2\tcpt=EF00\tfsi=FAT32\tsoi=GRUB2 Loader \ttam=525312\tuso=2\ndisk=1\tpar=3\tcpt=8300\tfsi=EXT4\tsoi=GRUB2 Loader \ttam=16248832\tuso=9595', 'iph': '10.80.23.229', 'ido': None, 'npc': None, 'idc': None, 'ida': None} INFO:root:iph (10.80.23.229) cfg (disk=1 par=0 cpt=2 fsi= soi= tam=16777216 uso=0 disk=1 par=1 cpt=EF02 fsi=EMPTY soi= tam=1024 uso=0 disk=1 par=2 cpt=EF00 fsi=FAT32 soi=GRUB2 Loader tam=525312 uso=2 disk=1 par=3 cpt=8300 fsi=EXT4 soi=GRUB2 Loader tam=16248832 uso=9595) INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/InclusionCliente HTTP/1.1" 200 - INFO:root:{'exe': 42, 'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:iph (10.80.23.229) exe (42) INFO:root:fileautoexec (/tmp/Sautoexec-10.80.23.229) INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/AutoexecCliente HTTP/1.1" 200 - INFO:root:{'nfl': '/tmp/Sautoexec-10.80.23.229', 'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:nfl (/tmp/Sautoexec-10.80.23.229) INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/enviaArchivo HTTP/1.1" 200 - INFO:root:{'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:iph (10.80.23.229) ido (42) INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/ComandosPendientes HTTP/1.1" 200 - INFO:root:{'tpc': 'OPG', 'iph': '10.80.23.229', 'ido': 42, 'npc': 'hal9000', 'idc': 42, 'ida': 42} INFO:root:iph (10.80.23.229) tpc (OPG) INFO:werkzeug:10.80.23.229 - - [22/Aug/2024 03:27:07] "POST /opengnsys/rest/__ogAdmClient/DisponibilidadComandos HTTP/1.1" 200 - ```
nserrano added 1 commit 2024-08-27 11:36:21 +02:00
nserrano merged commit 53f44ad3ab into main 2024-08-27 11:36:41 +02:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: opengnsys/ogagent#7
There is no content yet.