summaryrefslogtreecommitdiffstats
path: root/sources/ogAdmServer.cpp
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2019-11-12 13:51:59 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-11-12 21:37:11 +0100
commitffd2965b338476778bc3ac82e4dd4df0dd69fa38 (patch)
treea4325309d5362a2c8b43c715cc3ae4911fb0f1a2 /sources/ogAdmServer.cpp
parent280df58917f6f3200253c922682b397c4f2b0d44 (diff)
#915 Add 'echo' parameter to POST /shell/run
'echo' parameter makes possible for users to request the console output.
Diffstat (limited to 'sources/ogAdmServer.cpp')
-rw-r--r--sources/ogAdmServer.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index d626630..9f4c57a 100644
--- a/sources/ogAdmServer.cpp
+++ b/sources/ogAdmServer.cpp
@@ -3280,6 +3280,7 @@ struct og_msg_params {
const char *profile;
const char *cache;
const char *cache_size;
+ bool echo;
struct og_partition partition_setup[OG_PARTITION_MAX];
struct og_sync_params sync_setup;
uint64_t flags;
@@ -3315,6 +3316,7 @@ struct og_msg_params {
#define OG_REST_PARAM_SYNC_DIFF_NAME (1UL << 27)
#define OG_REST_PARAM_SYNC_PATH (1UL << 28)
#define OG_REST_PARAM_SYNC_METHOD (1UL << 29)
+#define OG_REST_PARAM_ECHO (1UL << 30)
static bool og_msg_params_validate(const struct og_msg_params *params,
const uint64_t flags)
@@ -3353,6 +3355,18 @@ static int og_json_parse_string(json_t *element, const char **str)
return 0;
}
+static int og_json_parse_bool(json_t *element, bool *value)
+{
+ if (json_typeof(element) == JSON_TRUE)
+ *value = true;
+ else if (json_typeof(element) == JSON_FALSE)
+ *value = false;
+ else
+ return -1;
+
+ return 0;
+}
+
static int og_json_parse_sync_params(json_t *element,
struct og_msg_params *params)
{
@@ -3724,23 +3738,36 @@ static int og_cmd_run_post(json_t *element, struct og_msg_params *params)
json_object_foreach(element, key, value) {
if (!strcmp(key, "clients"))
err = og_json_parse_clients(value, params);
- if (!strcmp(key, "run"))
+ else if (!strcmp(key, "run"))
err = og_json_parse_run(value, params);
+ else if (!strcmp(key, "echo")) {
+ err = og_json_parse_bool(value, &params->echo);
+ params->flags |= OG_REST_PARAM_ECHO;
+ }
if (err < 0)
break;
}
if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
- OG_REST_PARAM_RUN_CMD))
+ OG_REST_PARAM_RUN_CMD |
+ OG_REST_PARAM_ECHO))
return -1;
for (i = 0; i < params->ips_array_len; i++) {
len = snprintf(iph + strlen(iph), sizeof(iph), "%s;",
params->ips_array[i]);
}
- len = snprintf(buf, sizeof(buf), "nfn=ConsolaRemota\riph=%s\rscp=%s\r",
- iph, params->run_cmd);
+
+ if (params->echo) {
+ len = snprintf(buf, sizeof(buf),
+ "nfn=ConsolaRemota\riph=%s\rscp=%s\r",
+ iph, params->run_cmd);
+ } else {
+ len = snprintf(buf, sizeof(buf),
+ "nfn=EjecutarScript\riph=%s\rscp=%s\r",
+ iph, params->run_cmd);
+ }
msg = og_msg_alloc(buf, len);
if (!msg)