summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/client.c14
-rw-r--r--src/core.c1
-rw-r--r--src/rest.c38
-rw-r--r--src/rest.h1
4 files changed, 10 insertions, 44 deletions
diff --git a/src/client.c b/src/client.c
index ad4c5d3..9796005 100644
--- a/src/client.c
+++ b/src/client.c
@@ -135,11 +135,9 @@ static int og_resp_probe(struct og_client *cli, json_t *data)
static int og_resp_shell_run(struct og_client *cli, json_t *data)
{
const char *output = NULL;
- char filename[4096];
const char *key;
json_t *value;
int err = -1;
- FILE *file;
if (json_typeof(data) != JSON_OBJECT)
return -1;
@@ -158,16 +156,8 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data)
return -1;
}
- sprintf(filename, "/tmp/_Seconsola_%s", inet_ntoa(cli->addr.sin_addr));
- file = fopen(filename, "wt");
- if (!file) {
- syslog(LOG_ERR, "cannot open file %s: %s\n",
- filename, strerror(errno));
- return -1;
- }
-
- fprintf(file, "%s", output);
- fclose(file);
+ free((void *)cli->shell_output);
+ cli->shell_output = strdup(output);
return 0;
}
diff --git a/src/core.c b/src/core.c
index 0f95ad9..b15efc9 100644
--- a/src/core.c
+++ b/src/core.c
@@ -32,6 +32,7 @@ static void og_client_release(struct ev_loop *loop, struct og_client *cli)
ev_timer_stop(loop, &cli->timer);
ev_io_stop(loop, &cli->io);
close(cli->io.fd);
+ free((void *)cli->shell_output);
free(cli);
}
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);
diff --git a/src/rest.h b/src/rest.h
index 6cbf224..fb1c1b6 100644
--- a/src/rest.h
+++ b/src/rest.h
@@ -61,6 +61,7 @@ struct og_client {
unsigned int last_cmd_id;
bool autorun;
uint32_t speed;
+ const char *shell_output;
};
void og_client_add(struct og_client *cli);