From b8b3839bba75a96acc852d83b02434d921b0e065 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Mon, 17 Jan 2022 11:39:53 +0100 Subject: #915 remove temporary file to store shell output Remove legacy behaviour, store it in the client object instead of a temporary file. --- src/rest.c | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) (limited to 'src/rest.c') diff --git a/src/rest.c b/src/rest.c index c0b4480..11ef988 100644 --- a/src/rest.c +++ b/src/rest.c @@ -646,7 +646,6 @@ static int og_cmd_run_post(json_t *element, struct og_msg_params *params) { json_t *value, *clients; const char *key; - unsigned int i; int err = 0; if (json_typeof(element) != JSON_OBJECT) @@ -674,20 +673,7 @@ static int og_cmd_run_post(json_t *element, struct og_msg_params *params) clients = json_copy(element); json_object_del(clients, "clients"); - err = og_send_request(OG_METHOD_POST, OG_CMD_SHELL_RUN, params, clients); - if (err < 0) - return err; - - for (i = 0; i < params->ips_array_len; i++) { - char filename[4096]; - FILE *f; - - sprintf(filename, "/tmp/_Seconsola_%s", params->ips_array[i]); - f = fopen(filename, "wt"); - fclose(f); - } - - return 0; + return og_send_request(OG_METHOD_POST, OG_CMD_SHELL_RUN, params, clients); } static int og_cmd_run_get(json_t *element, struct og_msg_params *params, @@ -721,23 +707,11 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params, for (i = 0; i < params->ips_array_len; i++) { json_t *object, *output, *addr; - char data[4096] = {}; - char filename[4096]; - int fd, numbytes; - - sprintf(filename, "/tmp/_Seconsola_%s", params->ips_array[i]); + struct og_client *cli; - fd = open(filename, O_RDONLY); - if (!fd) - return -1; - - numbytes = read(fd, data, sizeof(data)); - if (numbytes < 0) { - close(fd); - return -1; - } - data[sizeof(data) - 1] = '\0'; - close(fd); + cli = og_client_find(params->ips_array[i]); + if (!cli) + continue; object = json_object(); if (!object) { @@ -752,7 +726,7 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params, } json_object_set_new(object, "addr", addr); - output = json_string(data); + output = json_string(cli->shell_output); if (!output) { json_decref(object); json_decref(array); -- cgit v1.2.3-18-g5258