diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-05-29 12:30:36 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-05-30 15:32:22 +0200 |
commit | 55134355b9d2126723796d567bcc2e06d523a2fb (patch) | |
tree | 47e8c99df95660e94c43155945f13318871712d1 /admin | |
parent | 68270b3cedebad9abe7f7f2c997b550bae81132c (diff) |
#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
Diffstat (limited to 'admin')
-rw-r--r-- | admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp | 29 | ||||
-rwxr-xr-x | admin/Sources/Services/ogAdmServer/tests/run-tests.sh | 1 | ||||
-rw-r--r-- | admin/Sources/Services/ogAdmServer/tests/stop.json | 1 |
3 files changed, 31 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp index 78d640d2..6c83e159 100644 --- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp +++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp @@ -3916,6 +3916,26 @@ static int og_cmd_reboot(json_t *element, struct og_msg_params *params) return og_cmd_legacy_send(params, "Reiniciar", CLIENTE_OCUPADO); } +static int og_cmd_stop(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, "Purgar", CLIENTE_APAGADO); +} + static int og_client_not_found(struct og_client *cli) { char buf[] = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n"; @@ -4049,6 +4069,15 @@ static int og_client_state_process_payload_rest(struct og_client *cli) return og_client_not_found(cli); } err = og_cmd_reboot(root, ¶ms); + } else if (!strncmp(cmd, "stop", strlen("stop"))) { + if (method != OG_METHOD_POST) + return -1; + + if (!root) { + syslog(LOG_ERR, "command stop with no payload\n"); + return og_client_not_found(cli); + } + err = og_cmd_stop(root, ¶ms); } else { syslog(LOG_ERR, "unknown command %s\n", cmd); err = og_client_not_found(cli); diff --git a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh index ae102c9c..138b3b29 100755 --- a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh +++ b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh @@ -6,3 +6,4 @@ curl -X POST http://127.0.0.1:8888/shell/output -d @post_shell_output.json 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 diff --git a/admin/Sources/Services/ogAdmServer/tests/stop.json b/admin/Sources/Services/ogAdmServer/tests/stop.json new file mode 100644 index 00000000..4667303d --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/stop.json @@ -0,0 +1 @@ +{ "clients" : [ "192.168.2.1", "192.168.2.2" ] } |