diff options
author | ramon <ramongomez@us.es> | 2017-02-13 11:00:22 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2017-02-13 11:00:22 +0000 |
commit | b94293057025cc701871809077e749a9fdced7fb (patch) | |
tree | 36f0eb47bf3a97da15e06b8da2e2970db656c00e /admin/WebConsole/rest/ogagent.php | |
parent | dcddace94541dd87a499635867632be5ba117d5b (diff) |
#708: Redirigir operación de logout a servidor UDS y dejar de usar reintentos de conexión (Slim espera hasta el final para enviar la respuesta).
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5188 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'admin/WebConsole/rest/ogagent.php')
-rw-r--r-- | admin/WebConsole/rest/ogagent.php | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/admin/WebConsole/rest/ogagent.php b/admin/WebConsole/rest/ogagent.php index 07777942..744ee586 100644 --- a/admin/WebConsole/rest/ogagent.php +++ b/admin/WebConsole/rest/ogagent.php @@ -128,8 +128,6 @@ $app->post('/ogagent/loggedin', global $cmd; $redirto = Array(); $result = Array(); - $retries = 3; // Number of retries. - $ttr = 10; // Time to retry (secs) try { // Reading POST parameters in JSON format. @@ -163,11 +161,9 @@ EOD; // Redirect notification to UDS server, if needed. $redirto[0]['post'] = $app->request()->getBody(); $result = multiRequest($redirto); - // Check result code to retry notification after time. - for ($i=1; $i<=$retries and $result[0]['code'] != 200; $i++) { - sleep($ttr); - $result = multiRequest($redirto); - } + // ... (check response) + //if ($result[0]['code'] != 200) { + // ... } } } catch (Exception $e) { @@ -188,6 +184,10 @@ EOD; */ $app->post('/ogagent/loggedout', function() use ($app) { + global $cmd; + $redirto = Array(); + $result = Array(); + try { // Reading POST parameters in JSON format. $input = json_decode($app->request()->getBody()); @@ -197,12 +197,34 @@ $app->post('/ogagent/loggedout', if (empty(preg_match('/^python-requests\//', $_SERVER['HTTP_USER_AGENT'])) or $ip !== $_SERVER['REMOTE_ADDR']) { throw new Exception("Bad OGAgent: ip=$ip, sender=".$_SERVER['REMOTE_ADDR'].", agent=".$_SERVER['HTTP_USER_AGENT']); } - // May check if client is included in the server database? - // Default processing: log activity. + // Log activity and respond to client. writeLog("User logged out: ip=$ip, user=$user."); - // Response. $response = ""; jsonResponse(200, $response); + // Check if client is included in the server database. + $cmd->texto = <<<EOD +SELECT ordenadores.idordenador, ordenadores.ip, remotepc.urllogin + FROM remotepc + RIGHT JOIN ordenadores ON remotepc.id=ordenadores.idordenador + WHERE ordenadores.ip = '$ip' + LIMIT 1; +EOD; + $rs=new Recordset; + $rs->Comando=&$cmd; + if ($rs->Abrir()) { + // Read query data. + $rs->Primero(); + $redirto[0]['url'] = $rs->campos['urllogout']; + $rs->Cerrar(); + if (!is_null($redirto[0]['url'])) { + // Redirect notification to UDS server, if needed. + $redirto[0]['post'] = $app->request()->getBody(); + $result = multiRequest($redirto); + // ... (check response) + //if ($result[0]['code'] != 200) { + // ... + } + } } catch (Exception $e) { // Comunication error. $response["message"] = $e->getMessage(); |