Commit Graph

612 Commits (892a8fa2e5a60f2390c74d6bf0599e942a80983c)
 

Author SHA1 Message Date
OpenGnSys Support Team b4a9fddf30 #915 add POST software command to REST API in ogAdmServer
This patch implements the command "software" that fetches the software
configuration from the clients.

Request:
        POST /software
        {"clients" : [ "192.168.2.1", "192.168.2.2" ]}
Reply:
        200 OK

This allows to refresh the software inventory from clients.
2019-07-03 02:56:07 +02:00
OpenGnSys Support Team 6b30dbc65c #915 add POST hardware command to REST API in ogAdmServer
This patch implements the command "hardware" that fetches the hardware
configuration from the clients.

Request:
	POST /hardware
        {"clients" : [ "192.168.2.1", "192.168.2.2" ]}
Reply:
        200 OK

This allows to refresh the hardware inventory from clients.
2019-07-03 02:56:07 +02:00
Javier Sánchez Parra eae2385f67 #915 Add API token to tests in ogAdmServer/tests/units/*
Add token parameter in REST API test infrastructure.
2019-06-24 13:50:43 +02:00
Javier Sánchez Parra b8234523d1 #915 update installer to add APITOKEN= to ogAdmServer.cfg
This is going to be used to protect calls to ogAdmServer

Example line for ogAdmServer.cfg:

APITOKEN=9b5fddfc5d4d1daa74ffd7ce7c3c9925
2019-06-24 13:46:10 +02:00
OpenGnSys Support Team fd305405b7 #915 add support for HTTP Authorization
Add APITOKEN= field to ogAdmServer.cfg to specify the REST API key.
2019-06-24 13:42:25 +02:00
Javier Sánchez Parra e45455ec82 #915 Remove unnecessary return in ogAdmServer/tests/run-tests.py
No need to explicit return call, remove it.
2019-06-12 11:02:47 +02:00
Javier Sánchez Parra 8322fd6acb #896 Fix memory leak in wake_up_broadcast()
call freeifaddrs() after getifaddrs() to release memory.
2019-06-12 11:01:33 +02:00
Javier Sánchez Parra b35438d27e #915 add test for POST /session REST API 2019-05-31 11:39:43 +02:00
Javier Sánchez Parra 496f5ebb49 #915 add test for POST /shell/output REST API 2019-05-31 11:39:29 +02:00
Javier Sánchez Parra 5312e73c91 #915 add test for POST /shell/run REST API 2019-05-31 11:39:06 +02:00
Javier Sánchez Parra 556aa6b858 #915 add test for POST /wol REST API 2019-05-31 11:39:01 +02:00
Javier Sánchez Parra c39b1f324e #915 add test for POST /clients REST API 2019-05-31 11:38:57 +02:00
Javier Sánchez Parra 1af2f4b55e #915 add test for GET /clients REST API 2019-05-31 11:38:52 +02:00
Javier Sánchez Parra 727a109f7d #915 add unit test infrastructure for REST API
This python script creates a database and starts ogAdmServer to run the
tests.  This requires root to be launched:

	# ./run-tests.py

From the 'tests' folder.
2019-05-31 11:35:42 +02:00
OpenGnSys Support Team eb6aa82cd4 #915 validate message length based on announced Content-Length field
Otherwise, TCP segmentation leads to handle an incomplete payload, this
problems manifests with errors when parsing the json body.
2019-05-31 00:20:05 +02:00
OpenGnSys Support Team 99c6c62d81 #915 remove Actualizar(), Purgar(), Reiniciar() and IniciarSesion()
The new REST API obsoletes the following commands:

- Actualizar() has been replaced by POST /refresh.
- Purgar() has been replaced by POST /stop.
- Reiniciar() has been replaced by POST /reboot.
- IniciarSesion() has been replaced by POST /session.
2019-05-30 15:32:26 +02:00
OpenGnSys Support Team 17f55b41c3 #915 add POST refresh command to REST API in ogAdmServer
Forces client to fetch and run any pending command from the server,
reload its local configuration file and re-start its selection menu.

curl -X POST http://127.0.0.1:8888/refresh -d @refresh.json

    Request
            POST /refresh
            {"clients": [ "192.168.2.1" ] }
    Reply:
            200 OK
2019-05-30 15:32:24 +02:00
OpenGnSys Support Team 1e6c889256 #915 add POST stop command to REST API in ogAdmServer
Stop the menu selection on client (through POST method):

curl -X POST http://127.0.0.1:8888/stop -d @stop.json

Request
	POST /stop
	{"clients": [ "192.168.2.1" ] }
Reply:
	200 OK
2019-05-30 15:32:22 +02:00
OpenGnSys Support Team 5f0191d73f #915 add POST reboot command to REST API in ogAdmServer
Reboot a client (through POST method):

        curl -X POST http://127.0.0.1:8888/reboot -d @reboot.json

Request
        POST /reboot
        {"clients": [ "192.168.2.1" ] }
Reply:
        200 OK
2019-05-30 15:32:18 +02:00
OpenGnSys Support Team 23fed47639 #915 add POST poweroff command to REST API in ogAdmServer
Power off a client (through POST method):

        curl -X POST http://127.0.0.1:8888/poweroff -d @poweroff.json

Request
        POST /poweroff
        {"clients": [ "192.168.2.1" ] }
Reply:
        200 OK
2019-05-30 15:32:01 +02:00
OpenGnSys Support Team 40023ff0b6 #915 add og_cmd_legacy_send()
Add function to send legacy command to clients.
2019-05-29 12:45:28 +02:00
OpenGnSys Support Team 8abc82f647 #915 remove Sondeo(), respuestaSondeo(), ConsolaRemota(), Arrancar() and EcoConsola()
The new REST API obsoletes the following commands:

- Sondeo() has been replaced by GET /clients.
- respuestaSondeo() has been replaced by POST /clients.
- ConsolaRemota() has been replaced by POST /shell/run.
- EcoConsola() has been replaced by POST /shell/output.
- Arrancar() has been replaced by POST /wol.
2019-05-27 13:03:14 +02:00
OpenGnSys Support Team 7ab5f0cbfb #915 add POST session command to REST API in ogAdmServer
Start a session on client (through POST method):

        curl -X POST http://127.0.0.1:8888/session -d @session.json

Request
        POST /session
        {"clients": [ "192.168.2.1" ] }
Reply:
        200 OK
2019-05-27 13:03:05 +02:00
OpenGnSys Support Team c6020f2ad1 #915 add POST shell/output command to REST API in ogAdmServer
Fetching result from run command on client (through GET method):

        curl -X POST http://127.0.0.1:8888/shell/output -d @post_shell_output.json

Request
        POST /shell/output
        {"clients": [ "192.168.2.1" ] }
Reply:
        200 OK
	{"clients": [ { "addr" : "192.168.2.1", "output" : "..." } ] }
2019-05-27 13:03:00 +02:00
OpenGnSys Support Team 7e4e5b5e08 #915 add run command to REST API in ogAdmServer
Run command on client (through POST method):

	curl -X POST http://127.0.0.1:8888/shell/run -d @post_run.json

Request
	POST /shell/run
	{"clients": [ "192.168.2.1", "192.168.2.2" ], "run" : "ls" }
Reply:
	200 OK
2019-05-27 13:02:57 +02:00
OpenGnSys Support Team 5797e0b199 #915 add wol command to REST API in ogAdmServer
Send Wake-On-Lan to clients (through POST method):

Request:
	curl -X POST http://127.0.0.1:8888/wol
	{ "type" : "unicast", "clients" : [ { "addr" : "192.168.2.1", "mac" : "00AABBCCDD01" } ] }
Reply:
	200 OK
2019-05-27 13:02:52 +02:00
OpenGnSys Support Team 507c75c337 #915 Pass array of addresses to WakeUp()
To reuse this function to the REST API.
2019-05-27 13:02:49 +02:00
OpenGnSys Support Team 7b6fcdbc62 #915 add clients command to REST API in ogAdmServer
Request for existing clients:

	curl -X GET http://127.0.0.1:8888/clients

Request:
	GET /clients
Reply:
	200 OK
	{"clients": [ { "addr" : "192.168.2.1", "state" : "OPG" }, { "addr" : "192.168.2.2", "state" : "OFF" }]}
2019-05-27 13:02:45 +02:00
OpenGnSys Support Team 95e6520c4f #915 add initial REST API for ogAdmServer
Add REST API for ogAdmServer, this API is exposed through port 8888 on
the system that runs the ogAdmServer. The body of the HTTP message is
expressed in JSON format.

This patch implements the command "clients" that maps to the existing
legacy "Sondeo" command, that is used by the web interface to poll
refresh the client state.

This patch also includes an initial test infrastructure using 'curl' to
send commands to the new REST API.

Request:
	POST /clients
	{"clients" : [ "192.168.2.1", "192.168.2.2" ]}
Reply:
	200 OK

This allows to refresh the status of the list of clients.
2019-05-27 13:02:37 +02:00
OpenGnSys Support Team 222637848b #915 add og_msg_alloc() and og_msg_free()
Add function to allocate and release the legacy message format.
2019-05-27 13:02:33 +02:00
OpenGnSys Support Team e979fd2020 #915 add og_send_cmd()
Add new function to check and send commands to the clients. This new
function takes an array of IP addresses (string) and send commands to
the clients.
2019-05-27 13:02:20 +02:00
OpenGnSys Support Team e3e4e6f677 #915 add og_socket_server_init()
Move code to create a socket into a function.
2019-05-27 13:02:06 +02:00
OpenGnSys Support Team 107b17a51b #915 add og_client_state_process_payload()
Move code that handles the message payload into function.
2019-05-27 13:02:00 +02:00
OpenGnSys Support Team d491dfdb2d #915 add og_client_state_recv_hdr()
Move code that handles the receiving header state into function.
2019-05-27 13:01:35 +02:00
OpenGnSys Support Team 0d6dc82669 #898 Remove unused encryption and decryption routines
Remove dead code to encrypt and decrypt the message.
2019-02-06 14:49:49 +01:00
OpenGnSys Support Team b38ed0dfb8 #897 Do not use socket type in ogAdmServer
No need for an extra type, socket descriptors are always integer.
2019-02-06 14:49:04 +01:00
Javier Sánchez Parra 2baf362ac2 #896: Send multicast WoL through a specific interface
* New parameter in ogAdmServer config file for setting an interface.
* ogAdmServer multicast WoL now search the interface of the config file in the
system, if the interface is found in the system the destination IP of the
packet change to a broadcast address of a specific range of addresses.
2019-02-06 14:29:52 +01:00
OpenGnSys Support Team bcc8ccce34 #891 remove function to parse string in hexadecimal to binary
Wake-on-lan does not use it anymore, this function has no clients and we
can just remove it.
2019-01-23 16:40:18 +01:00
OpenGnSys Support Team 63a3d4d8fd #891 fix wake on lan routine
Fix function to send wake-on-lan packet:

- setsockopt() expects an integer as parameter.
- zero the struct socketaddr_in local structure.
- use sscanf() to parse the mac address string.
2019-01-23 16:39:21 +01:00
OpenGnSys Support Team 9fc0037bd7 #580 ignore SIGPIPE signal
This signal is received when socket hit connection reset by peer
state, which may happen in transient network failures.
2019-01-17 13:19:02 +01:00
OpenGnSys Support Team 162d7808b0 #580 incorrect return value in handler
All handlers must return a boolean.
2019-01-17 13:18:57 +01:00
OpenGnSys Support Team effbcea987 #883 standalone log file is now deprecated
display message in old log file that ogAdmServer uses syslog.
2019-01-17 13:18:55 +01:00
OpenGnSys Support Team a1d02f4f2a #883 remove unnecessary logging
Remove redundant logging, use syslog() whenever possible.
2019-01-17 13:18:53 +01:00
OpenGnSys Support Team b56cbeb737 #883 replace standalone log file by syslog 2019-01-17 13:18:51 +01:00
OpenGnSys Support Team 2ed3a0cd1a #883 use LOG_DEBUG instead of LOG_INFO
Log file may grow in size too quickly in standard syslog configurations.
2019-01-17 13:18:49 +01:00
OpenGnSys Support Team 57c8c50524 #883 do not use argv[0] in syslog log message
Before:

Dec  3 11:18:12 ogLab /opt/opengnsys/sbin/ogAdmServer[1025]: server closing connection to 192.168.56.10:50476

After this patch:

Dec  3 11:18:12 ogLab ogAdmServer[1025]: server closing connection to 192.168.56.10:50476
2019-01-17 13:18:47 +01:00
OpenGnSys Support Team f09aca620c #580 fix management of keepalive connections to clients
OgAdmServer leaves a connection in keepalive more (similar to HTTP
keepalive feature), the existing handling is not correct. The tbsocket
table is never cleaned up and properly.

Use the new og_client object that represents connections from the
clients in tbsocket[] instead.

The keepalive field now stores the index in the tbsocket table, so there
is no need to consult mysql to fetch the slot that this client is using.

This patch also extends syslog() support to include port number when
reporting connections from clients.
2019-01-17 13:18:40 +01:00
OpenGnSys Support Team eff62ed515 #580 no need for pthread library 2019-01-17 13:18:38 +01:00
OpenGnSys Support Team 8d6d833770 #884 do not strip off symbols
Nor use -O3 since this generates code that is harder to debug.
Compile binary that can be run inside valgrind for better debugging.
2019-01-17 13:18:36 +01:00
OpenGnSys Support Team ef6e3d263c #883 add initial syslog support 2019-01-17 13:18:34 +01:00