diff options
author | ramon <ramongomez@us.es> | 2016-07-08 17:59:45 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2016-07-08 17:59:45 +0000 |
commit | 29134391404977704f85c437e8ea5c0916ed837e (patch) | |
tree | 4cef007fc2ae2b2241531a89f9fed8b5ffdcfeed /admin/WebConsole/rest/ogagent.php | |
parent | 05f472af721b96825cbd52cf4104d77276accb7e (diff) |
#718: Guardar en BD la clave de acceso a la API REST de OGAgent en la ruta REST {{{ogagent/started}}} del servidor.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@4984 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'admin/WebConsole/rest/ogagent.php')
-rw-r--r-- | admin/WebConsole/rest/ogagent.php | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/admin/WebConsole/rest/ogagent.php b/admin/WebConsole/rest/ogagent.php index a2697c26..422e7d12 100644 --- a/admin/WebConsole/rest/ogagent.php +++ b/admin/WebConsole/rest/ogagent.php @@ -12,7 +12,8 @@ define('LOG_FILE', '/opt/opengnsys/log/ogagent.log'); // OGAgent notifies that its service is started on client. $app->post('/ogagent/started', function() use ($app) { - $osType = $osVersion = ""; + global $cmd; + $osType = $osVersion = "none"; try { // Reading POST parameters in JSON format. $input = json_decode($app->request()->getBody()); @@ -22,14 +23,19 @@ $app->post('/ogagent/started', if (isset($input->osversion)) $osVersion = str_replace(",", ";", htmlspecialchars($input->osversion)); // Client secret key for secure communications. if (isset($input->secret)) { - $secret = htmlspecialchars($input->secret); // Store secret key in DB. - //... + $secret = htmlspecialchars($input->secret); + $cmd->texto = "UPDATE ordenadores + SET agentkey='$secret' + WHERE ip='$ip' AND mac=UPPER(REPLACE('$mac',':',''))"; + if ($cmd->Ejecutar() !== true) { + // DB access error. + throw new Exception("Cannot store secret key: ip=$ip, mac=$mac, os=$osType:$osVersion."); + } } else { // Insecure agent exception. throw new Exception("Insecure OGAgent started: ip=$ip, mac=$mac, os=$osType:$osVersion."); } - // 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, os=$osType:$osVersion.\n", FILE_APPEND); // Response. @@ -47,7 +53,7 @@ $app->post('/ogagent/started', // OGAgent notifies that its service is stopped on client. $app->post('/ogagent/stopped', function() use ($app) { - $osType = $osVersion = ""; + $osType = $osVersion = "none"; try { // Reading POST parameters in JSON format. $input = json_decode($app->request()->getBody()); |