summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-29 12:12:46 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-30 15:32:18 +0200
commit5f0191d73ff5136a1a63b076f12a30a01e06f9dd (patch)
tree266b04358613595abf6477c7b7a6aa2bac343bbf
parent23fed47639dd4dffa477b226cc9a28075511c925 (diff)
#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
-rw-r--r--sources/ogAdmServer.cpp29
-rw-r--r--tests/reboot.json1
-rwxr-xr-xtests/run-tests.sh1
3 files changed, 31 insertions, 0 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index a86655d..78d640d 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_reboot(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, "Reiniciar", CLIENTE_OCUPADO);
+}
+
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";
@@ -4020,6 +4040,15 @@ static int og_client_state_process_payload_rest(struct og_client *cli)
return og_client_not_found(cli);
}
err = og_cmd_poweroff(root, &params);
+ } else if (!strncmp(cmd, "reboot", strlen("reboot"))) {
+ if (method != OG_METHOD_POST)
+ return -1;
+
+ if (!root) {
+ syslog(LOG_ERR, "command reboot with no payload\n");
+ return og_client_not_found(cli);
+ }
+ err = og_cmd_reboot(root, &params);
} else {
syslog(LOG_ERR, "unknown command %s\n", cmd);
err = og_client_not_found(cli);
diff --git a/tests/reboot.json b/tests/reboot.json
new file mode 100644
index 0000000..4667303
--- /dev/null
+++ b/tests/reboot.json
@@ -0,0 +1 @@
+{ "clients" : [ "192.168.2.1", "192.168.2.2" ] }
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index 8736859..ae102c9 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -5,3 +5,4 @@ curl -X POST http://127.0.0.1:8888/shell/run -d @post_shell_run.json
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