summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2018-07-05 13:50:17 +0200
committerRamón M. Gómez <ramongomez@us.es>2018-07-05 13:50:17 +0200
commitde6abb6c186b0689bfcc7e520ebef28ed157943e (patch)
treec3636d533aec9cd7fd69f044816f268f944b53ce
parentf0c2f785d8f3f1b652d8306f300543b9c4bc33a9 (diff)
#750: Renaming server REST route {{{GET /done}}} to {{{GET /command_done}}} to log commands executed on clients.
-rw-r--r--admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py12
-rw-r--r--admin/WebConsole/rest/ogagent.php48
2 files changed, 36 insertions, 24 deletions
diff --git a/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py b/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py
index 1832652e..abeeaae6 100644
--- a/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py
+++ b/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py
@@ -364,7 +364,7 @@ class OpenGnSysWorker(ServerWorker):
route = post_params.get('redirect_url')
# Checking if the thread id. exists
for c in self.commands:
- if c.getName() == op_id:
+ if c.getName() == str(op_id):
raise Exception('Task id. already exists: {}'.format(op_id))
# Launching a new thread
thr = threading.Thread(name=op_id, target=self.task_command, args=(script, route, op_id))
@@ -393,6 +393,16 @@ class OpenGnSysWorker(ServerWorker):
data.append(c.__dict__['_Thread__args'])
return data
+ def process_stopcmd(self, path, get_params, post_params, server):
+ logger.debug('Received stopcmd operation with params {}:'.format(post_params))
+ self.checkSecret(server)
+ op_id = post_params.get('trace')
+ for c in self.commands:
+ if c.is_alive() and c.getName() == str(op_id):
+ c._Thread__stop()
+ return {"stopped": op_id}
+ return {}
+
def process_hardware(self, path, get_params, post_params, server):
"""
Returns client's hardware profile
diff --git a/admin/WebConsole/rest/ogagent.php b/admin/WebConsole/rest/ogagent.php
index 445ee239..b250c6ac 100644
--- a/admin/WebConsole/rest/ogagent.php
+++ b/admin/WebConsole/rest/ogagent.php
@@ -270,35 +270,37 @@ EOD;
);
// Processing command results (TESTING).
-$app->post('/ogagent/done',
+$app->post('/ogagent/command_done',
// 'validateClient',
function() use ($app) {
global $cmd;
try {
- // Reading parameters.
- $input = json_decode($app->request()->getBody());
- $status = htmlspecialchars($input->status);
- $output = htmlspecialchars($input->output);
- $error = htmlspecialchars($input->error);
- // (... read "id" as GET parameter ...)
- // ...
- $client = $_SERVER['REMOTE_ADDR'];
- // Check sender agent type.
- if (empty(preg_match('/^python-requests\//', $_SERVER['HTTP_USER_AGENT']))) {
- throw new Exception("Bad OGAgent: sender=".$client.", agent=".$_SERVER['HTTP_USER_AGENT']);
- }
- // TODO: truncating outputs.
- if ($status == 0) {
- writeLog($app->request()->getResourceUri().": Operation OK: client=$client, id=??, output=$output");
- } else {
- writeLog($app->request()->getResourceUri().": Operation ERROR: client=$client, id=??, status=$status, error=$error");
- }
+ // Reading parameters.
+ $input = json_decode($app->request()->getBody());
+ $client = htmlspecialchars($input->client);
+ $id = htmlspecialchars($input->trace);
+ $status = htmlspecialchars($input->status);
+ $output = htmlspecialchars($input->output);
+ $error = htmlspecialchars($input->error);
+ $client = $_SERVER['REMOTE_ADDR'];
+ // Check sender agent type.
+ if (empty(preg_match('/^python-requests\//', $_SERVER['HTTP_USER_AGENT'])) or $client !== $_SERVER['REMOTE_ADDR']) {
+ throw new Exception("Bad OGAgent: client=$client, sender=".$_SERVER['REMOTE_ADDR'].", agent=".$_SERVER['HTTP_USER_AGENT']);
+ }
+ // TODO: truncating outputs.
+ if ($status == 0) {
+ writeLog($app->request()->getResourceUri().": Operation OK: client=$client, id=$id, output=$output");
+ } else {
+ writeLog($app->request()->getResourceUri().": Operation ERROR: client=$client, id=$id, status=$status, error=$error");
+ }
+ $response = "";
+ jsonResponse(200, $response);
} catch (Exception $e) {
- // Communication error.
- $response["message"] = $e->getMessage();
- writeLog($app->request()->getResourceUri().": ERROR: ".$response["message"]);
- jsonResponse(400, $response);
+ // Communication error.
+ $response["message"] = $e->getMessage();
+ writeLog($app->request()->getResourceUri().": ERROR: ".$response["message"]);
+ jsonResponse(400, $response);
}
}
);