Commit Graph

115 Commits (c1c89e196c7ecbc91dd1f3237cd546ef633490c4)

Author SHA1 Message Date
Roberto Hueso Gómez c1c89e196c #915: Return 400 status code in POST methods when no payload is attached
If no payload is attached to method that requires a payload, then the API
returns a 400 status code (following RFC 7231) instead of the previous 404.

test_0001_get_clients.py is also modified to fit the new status code.
2019-09-19 16:06:03 +02:00
Javier Sánchez Parra 36ad0061d7 #915 check HTTP Content-Length size
If Content-Length is too large ogAdmServer, close the connection..
2019-09-10 11:10:34 +02:00
Javier Sánchez Parra 64e653773e #915 fix missing null-terminated string
This patch changes the number of characters stored in cli->auth_token
from 64 to 63. This way the array has the last position available to
store the null character.
2019-09-05 13:14:33 +02:00
OpenGnSys Support Team 3e8fcf0b40 #915 do not bail out when failing to send message to stale clients
Clients might enter power saving mode, hence, closing the connection
with the server. When the server sends a request to refresh its state,
if they are gone, do not break the iteration over the list of clients.
2019-09-02 13:36:50 +02:00
Javier Sánchez Parra 3de93a9503 #559 fix out of bound array access
This patch change the size of the array ptrPar from 6 to 7.

cppcheck says:

[sources/ogAdmServer.cpp:598]: (error) Array 'ptrCfg[6]' accessed at index 6, which is out of bounds.
2019-08-28 18:39:33 +02:00
OpenGnSys Support Team 7c67487ab3 #915 trim unknown command syslog error to the initial 32 bytes
Aug 28 17:12:33 server ogAdmServer[10110]: 127.0.0.1:54640 POST /nonexistent HTTP/1.1^M Host ...
Aug 28 17:12:33 server ogAdmServer[10110]: unknown command: nonexistent HTTP/1.1^M Host: loca ...
2019-08-28 17:31:48 +02:00
OpenGnSys Support Team a12af6a6e1 #915 add syslog error when HTTP request processing fails 2019-08-28 17:22:19 +02:00
OpenGnSys Support Team 15685e618f #915 add og_server_internal_error()
This function sends a 500 HTTP error to client.
2019-08-28 17:22:12 +02:00
OpenGnSys Support Team 84a25639b3 #915 add syslog debugging for HTTP request
Display initial 32 bytes of the HTTP request.
2019-08-28 17:22:05 +02:00
OpenGnSys Support Team 20dcb0a906 #915 close connection to REST API if request is too long
If REST API request length is >= 4096 bytes, close the connection.
2019-08-28 17:16:01 +02:00
OpenGnSys Support Team 881f532ee1 #915 add OG_CLIENTS_MAX definition
This definition specifies the maximum number of clients, that is set up
to 4096.
2019-08-28 17:15:49 +02:00
OpenGnSys Support Team e80c85fbff #915 set maximum REST API response to 64 Kbytes
The existing 4 Kbytes might not be enough to store the results of the
GET /clients request, extend it up to 64 Kbytes.
2019-08-28 17:15:35 +02:00
OpenGnSys Support Team 7e6ba45f95 #915 json_dump_callback() takes flags as a parameter
Not as the buffer size, this leads to incorrectly printing the json
output since this might set on the JSON_EMBED flag on libjansson >= 2.10
2019-08-28 17:15:14 +02:00
OpenGnSys Support Team ba2e868019 #915 allow up to 4096 clients from REST API
Raise maximum number of clients to 4096.
2019-08-28 11:50:11 +02:00
Javier Sánchez Parra 7dc8fdbaff #915 reply with HTTP 405 when the method is incorrect
When a command/request exists but the method is not correct returns 405
error code.
2019-08-27 14:32:13 +02:00
OpenGnSys Support Team fbc30b2669 #915 internal error response if reply is too long
In case reply is too long, return 501 internal server error.
2019-08-27 12:02:57 +02:00
OpenGnSys Support Team 429bd3665c #891 fix crash in wol command
Irina reports a crash in the wol command on Ubuntu 18.04 and gcc 7.4.0:

==9542== Process terminating with default action of signal 6 (SIGABRT)
==9542==    at 0x6C37E97: raise (raise.c:51)
==9542==    by 0x6C39800: abort (abort.c:79)
==9542==    by 0x6C82896: __libc_message (libc_fatal.c:181)
==9542==    by 0x6D2DCD0: __fortify_fail_abort (fortify_fail.c:33)
==9542==    by 0x6D2DC91: __stack_chk_fail (stack_chk_fail.c:29)
==9542==    by 0x111DB1: WakeUp(int, char*, char*, char*) (ogAdmServer.cpp:1390)
==9542==    by 0x11199F: Levanta(char**, char**, int, char*) (ogAdmServer.cpp:1251)
==9542==    by 0x118372: og_cmd_wol(json_t*, og_msg_params*) (ogAdmServer.cpp:3580)
==9542==    by 0x119B91: og_client_state_process_payload_rest(og_client*) (ogAdmServer.cpp:4030)
==9542==    by 0x11A4E9: og_client_read_cb(ev_loop*, ev_io*, int) (ogAdmServer.cpp:4212)
==9542==    by 0x5EA1D72: ev_invoke_pending (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
==9542==    by 0x5EA53DD: ev_run (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)

sscanf() returns integers (32-bits) instead of array of 8-bits.
2019-07-29 12:37:54 +02:00
Javier Sánchez Parra 66001f0a6c #915 returns 401 when incorrect authentication happens
ogAdmServer REST API now meets the starndar RFC 7235 when incorrect auth
happens.

og_client_not_authorized() now sends "401 Unauthorized" and
"WWW-Authenticate" instead of 404.
2019-07-15 09:51:53 +02:00
Javier Sánchez Parra a927e14133 #559 fixes memory leak in tomaConfiguracion()
Calls fclose() after fopen() to release memory.
2019-07-15 09:44:42 +02:00
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
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 8322fd6acb #896 Fix memory leak in wake_up_broadcast()
call freeifaddrs() after getifaddrs() to release memory.
2019-06-12 11:01:33 +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