diff options
author | ramon <ramongomez@us.es> | 2016-03-17 13:40:48 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2016-03-17 13:40:48 +0000 |
commit | b1735a74d72d0af3aabe0f269ad43dd6167dc144 (patch) | |
tree | 06d708e0ae0987029883b8ac7db5ac735be7d6f5 /admin/WebConsole/rest/ogagent.php | |
parent | aad50e2614765ace4c90c334d99e555cf3409484 (diff) |
#718 #730: Incluir rutas REST que atienden las peticiones push del nuevo OGAgent y actualización de la ubicación del fichero para registrarlas.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@4837 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'admin/WebConsole/rest/ogagent.php')
-rw-r--r-- | admin/WebConsole/rest/ogagent.php | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/admin/WebConsole/rest/ogagent.php b/admin/WebConsole/rest/ogagent.php new file mode 100644 index 00000000..5fc22e74 --- /dev/null +++ b/admin/WebConsole/rest/ogagent.php @@ -0,0 +1,109 @@ +<?php + +// OpenGnsys REST routes for OGAgent communications. +// Author: Ramón M. Gómez +// Date: 2015-09-04 +// Warning: authentication/authorisation not included. + + +// OGAgent sessions log file. +define('LOG_FILE', '/opt/opengnsys/log/ogagent.log'); + +// OGAgent notifies that its service is started on client. +$app->post('/ogagent/started', + function() use ($app) { + + try { + // Reading POST parameters in JSON format. + $input = json_decode($app->request()->getBody()); + $ip = htmlspecialchars($input->ip); + $mac = htmlspecialchars($input->mac); + // May check that client is included in the server database? + // Default processing: log activity. + file_put_contents(LOG_FILE, date(DATE_RSS).": OGAgent started: ip=$ip, mac=$mac.\n", FILE_APPEND); + // Response. + $response["error"] = false; + jsonResponse(200, $response); + } catch (Exception $e) { + // Comunication error. + $response["error"] = true; + $response["message"] = $e->getMessage(); + jsonResponse(400, $response); + } + } +); + +// OGAgent notifies that its service is stopped on client. +$app->post('/ogagent/stopped', + function() use ($app) { + + try { + // Reading POST parameters in JSON format. + $input = json_decode($app->request()->getBody()); + $ip = htmlspecialchars($input->ip); + $mac = htmlspecialchars($input->mac); + // May check that client is included in the server database? + // Default processing: log activity. + file_put_contents(LOG_FILE, date(DATE_RSS).": OGAgent stopped: ip=$ip, mac=$mac.\n", FILE_APPEND); + // Response. + $response["error"] = false; + jsonResponse(200, $response); + } catch (Exception $e) { + // Comunication error. + $response["error"] = true; + $response["message"] = $e->getMessage(); + jsonResponse(400, $response); + } + } +); + +// OGAgent notifies that an user logs in. +$app->post('/ogagent/loggedin', + function() use ($app) { + + try { + // Reading POST parameters in JSON format. + $input = json_decode($app->request()->getBody()); + $ip = htmlspecialchars($input->ip); + $user = htmlspecialchars($input->user); + // May check that client is included in the server database? + // Default processing: log activity. + file_put_contents(LOG_FILE, date(DATE_RSS).": User logged in: ip=$ip, user=$user.\n", FILE_APPEND); + // Response. + $response["error"] = false; + jsonResponse(200, $response); + } catch (Exception $e) { + // Comunication error. + $response["error"] = true; + $response["message"] = $e->getMessage(); + jsonResponse(400, $response); + } + } +); + +// OGAgent notifies that an user logs out. +$app->post('/ogagent/loggedout', + function() use ($app) { + + try { + // Reading POST parameters in JSON format. + $input = json_decode($app->request()->getBody()); + $ip = htmlspecialchars($input->ip); + $user = htmlspecialchars($input->user); + // May check that client is included in the server database? + // Default processing: log activity. + file_put_contents(LOG_FILE, date(DATE_RSS).": User logged out: ip=$ip, user=$user.\n", FILE_APPEND); + // Response. + $response["error"] = false; + jsonResponse(200, $response); + } catch (Exception $e) { + // Comunication error. + $response["error"] = true; + $response["message"] = $e->getMessage(); + jsonResponse(400, $response); + } + } +); + +?> + |