diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-05-29 12:35:15 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-05-30 15:32:24 +0200 |
commit | 17f55b41c3117c8ce90a7a4817052266d7f4de4c (patch) | |
tree | c1c1eed68a718461702ae908599f75e5a3449a5d | |
parent | 1e6c8892565ac2c0a9578cc2dc8edf3128eb1355 (diff) |
#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
-rw-r--r-- | sources/ogAdmServer.cpp | 29 | ||||
-rwxr-xr-x | tests/run-tests.sh | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index 6c83e15..9bb9b60 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -3896,6 +3896,26 @@ static int og_cmd_poweroff(json_t *element, struct og_msg_params *params) return og_cmd_legacy_send(params, "Apagar", CLIENTE_OCUPADO); } +static int og_cmd_refresh(json_t *element, struct og_msg_params *params) +{ + const char *key; + json_t *value; + int err = 0; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) + err = og_json_parse_clients(value, params); + + if (err < 0) + break; + } + + return og_cmd_legacy_send(params, "Actualizar", CLIENTE_APAGADO); +} + static int og_cmd_reboot(json_t *element, struct og_msg_params *params) { const char *key; @@ -4078,6 +4098,15 @@ static int og_client_state_process_payload_rest(struct og_client *cli) return og_client_not_found(cli); } err = og_cmd_stop(root, ¶ms); + } else if (!strncmp(cmd, "refresh", strlen("refresh"))) { + if (method != OG_METHOD_POST) + return -1; + + if (!root) { + syslog(LOG_ERR, "command refresh with no payload\n"); + return og_client_not_found(cli); + } + err = og_cmd_refresh(root, ¶ms); } else { syslog(LOG_ERR, "unknown command %s\n", cmd); err = og_client_not_found(cli); diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 138b3b2..f0cae2a 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -7,3 +7,4 @@ curl -X POST http://127.0.0.1:8888/session -d @session.json curl -X POST http://127.0.0.1:8888/poweroff -d @poweroff.json curl -X POST http://127.0.0.1:8888/reboot -d @reboot.json curl -X POST http://127.0.0.1:8888/stop -d @stop.json +curl -X POST http://127.0.0.1:8888/refresh -d @refresh.json |