diff options
author | ramon <ramongomez@us.es> | 2017-12-12 16:28:56 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2017-12-12 16:28:56 +0000 |
commit | b46042c67f764c242943be42e2fd20eb65fbd4a1 (patch) | |
tree | 56dc1d9acd31ae726791efa5ac17d09f8d3f3443 | |
parent | 30492e97bb7855c682412d02b402881112d00ef7 (diff) |
#708: API REST guarda idioma de la sesión para adaptar los mensajes de fin de acceso remoto.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5529 a21b9725-9963-47de-94b9-378ad31fedc9
-rw-r--r-- | admin/Database/ogAdmBD-1.1.0pre.sql | 9 | ||||
-rw-r--r-- | admin/Database/ogAdmBD.sql | 1 | ||||
-rw-r--r-- | admin/WebConsole/rest/ogagent.php | 16 | ||||
-rwxr-xr-x | server/bin/ogagentqueue.cron | 96 |
4 files changed, 71 insertions, 51 deletions
diff --git a/admin/Database/ogAdmBD-1.1.0pre.sql b/admin/Database/ogAdmBD-1.1.0pre.sql index e9ec87e6..8b68899d 100644 --- a/admin/Database/ogAdmBD-1.1.0pre.sql +++ b/admin/Database/ogAdmBD-1.1.0pre.sql @@ -223,16 +223,17 @@ ALTER TABLE aulas MODIFY puestos SMALLINT DEFAULT NULL; # Nuevas tablas para datos del proyecto Remote PC y operaciones de OGAgent (ticket #708). -CREATE TABLE IF NOT EXISTS remotepc ( +DROP TABLE IF EXISTS remotepc; +CREATE TABLE remotepc ( id INT(11) NOT NULL, reserved DATETIME DEFAULT NULL, urllogin VARCHAR(100), urllogout VARCHAR(100), + language VARCHAR(5), PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -ALTER TABLE remotepc - MODIFY reserved DATETIME DEFAULT NULL; -CREATE TABLE IF NOT EXISTS ogagent_queue ( +DROP TABLE IF EXISTS ogagent_queue; +CREATE TABLE ogagent_queue ( id INT(11) NOT NULL AUTO_INCREMENT, clientid INT(11) NOT NULL, exectime DATETIME DEFAULT NULL, diff --git a/admin/Database/ogAdmBD.sql b/admin/Database/ogAdmBD.sql index 55f11a2b..c126f63c 100644 --- a/admin/Database/ogAdmBD.sql +++ b/admin/Database/ogAdmBD.sql @@ -791,6 +791,7 @@ CREATE TABLE `remotepc` ( `reserved` datetime DEFAULT NULL, `urllogin` varchar(100), `urllogout` varchar(100), + `language` varchar(5), PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/admin/WebConsole/rest/ogagent.php b/admin/WebConsole/rest/ogagent.php index 26de8a10..f2e8d5d9 100644 --- a/admin/WebConsole/rest/ogagent.php +++ b/admin/WebConsole/rest/ogagent.php @@ -136,6 +136,9 @@ $app->post('/ogagent/loggedin', $input = json_decode($app->request()->getBody()); $ip = htmlspecialchars($input->ip); $user = htmlspecialchars($input->user); + $language = isset($input->language) ? substr($input->language, 0, strpos($input->language, "_")) : ""; + if (isset($input->ostype)) $osType = htmlspecialchars($input->ostype); + if (isset($input->osversion)) $osVersion = str_replace(",", ";", htmlspecialchars($input->osversion)); // Check sender IP address consistency (same as parameter value). 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']); @@ -161,7 +164,7 @@ EOD; $rs->Cerrar(); if (!is_null($id)) { // Log activity, respond to client and continue processing. - writeLog("User logged in: ip=$ip, user=$user."); + writeLog("User logged in: ip=$ip, user=$user, lang=$language, os=$osType:$osVersion."); $response = ""; jsonResponseNow(200, $response); } else { @@ -174,6 +177,13 @@ EOD; // ... (check response) //if ($result[0]['code'] != 200) { // ... + // Updating user's session language for messages. + $cmd->texto = <<<EOD +UPDATE remotepc + SET language = '$language' + WHERE id = '$id'; +EOD; + $cmd->Ejecutar(); } } else { throw new Exception("Database error"); @@ -205,6 +215,8 @@ $app->post('/ogagent/loggedout', $input = json_decode($app->request()->getBody()); $ip = htmlspecialchars($input->ip); $user = htmlspecialchars($input->user); + if (isset($input->ostype)) $osType = htmlspecialchars($input->ostype); + if (isset($input->osversion)) $osVersion = str_replace(",", ";", htmlspecialchars($input->osversion)); // Check sender agent type and IP address consistency (same as parameter value). 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']); @@ -230,7 +242,7 @@ EOD; $rs->Cerrar(); if (!is_null($id)) { // Log activity, respond to client and continue processing. - writeLog("User logged out: ip=$ip, user=$user."); + writeLog("User logged out: ip=$ip, user=$user, os=$osType:$osVersion."); $response = ""; jsonResponseNow(200, $response); } else { diff --git a/server/bin/ogagentqueue.cron b/server/bin/ogagentqueue.cron index 54a9a2b9..0cf0dd5d 100755 --- a/server/bin/ogagentqueue.cron +++ b/server/bin/ogagentqueue.cron @@ -19,12 +19,12 @@ MYCNF=/tmp/.my.cnf.$$ # Basic error control if [ ! -r "$SERVERCONF" ]; then - echo "$PROG: Cannot access to configuration file." >&2 - exit 2 + echo "$PROG: Cannot access to configuration file." >&2 + exit 2 fi if ! touch "$LOGFILE"; then - echo "$PROG: Cannot write to the log file." >&2 - exit 2 + echo "$PROG: Cannot write to log file." >&2 + exit 2 fi # Fetching database access data. @@ -42,53 +42,59 @@ trap "rm -f $MYCNF" 0 1 2 3 6 9 15 # Reading pending operations. mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse " SELECT ogagent_queue.id, ogagent_queue.exectime, ogagent_queue.operation, - ordenadores.idordenador, ordenadores.ip, ordenadores.agentkey + ordenadores.idordenador, ordenadores.ip, ordenadores.agentkey, remotepc.language FROM ogagent_queue JOIN ordenadores ON ogagent_queue.clientid=ordenadores.idordenador + JOIN remotepc ON ogagent_queue.clientid=remotepc.id WHERE exectime < NOW() ORDER BY exectime;" | \ - while read -r OPERID DATE TIME OPER CLNTID AGNTIP AGNTKEY; do - # Preparing operation data. - # TODO: preparing messages translation. - case "$OPER" in - popup-10) # Message: min. before power off. - AGNTURL=https://$AGNTIP:8000/opengnsys/popup - DATA='{"title":"Apagado en 10 min.","message":"Fin del tiempo de acceso remoto.\nEl ordenador se apagará automáticamente dentro de 10 minutos."}' - ;; - popup-5) # Message: 5 min. before power off. - AGNTURL=https://$AGNTIP:8000/opengnsys/popup - DATA='{"title":"Apagado en 5 min.","message":"El ordenador se apagará automáticamente dentro de 5 minutos.\nATENCIÓN: Este es el último aviso."}' - ;; - poweroff) # Power off client. - AGNTURL=https://$AGNTIP:8000/opengnsys/poweroff - DATA= - ;; - *) # Unknown operation. - AGNTURL= - ;; - esac - # Sending operation to OGAgent. - if [ -n "$AGNTURL" ]; then - CODE=$(curl -ksm 1 -w "%{http_code}" -o /dev/null -H "Authorization: $AGNTKEY" ${DATA:+"-d $DATA"} "$AGNTURL") - case "$CODE" in - 000) # Client does not respond may be halted). - ;; - 200) # Operation sended. - echo "$(date +"%FT%T%z"): $PROG: Operation sended to OGAgent: client=$AGNTIP, oper=$OPER, exectime=\"$DATE $TIME\"" >> $LOGFILE ;; - *) # Operation error. - echo "$(date +"%FT%T%z"): $PROG: Operation error: client=$AGNTIP, oper=$OPER, code=$CODE" >> $LOGFILE ;; - esac - else # Unknown operation. - echo "$(date +"%FT%T%z"): $PROG: Unknown operation: client=$AGNTIP, oper=$OPER" >> $LOGFILE - fi - # Deleting operation from database. - SQL="DELETE FROM ogagent_queue WHERE id='$OPERID';" - [ "$OPER" == "poweroff" ] && SQL="$SQL + while read -r OPERID DATE TIME OPER CLNTID AGNTIP AGNTKEY LANGUAGE; do + # Preparing operation data. + case "$OPER" in + popup-10) # Message: 10 min. before power off. + AGNTURL=https://$AGNTIP:8000/opengnsys/popup + case "$LANGUAGE" in + es) DATA='{"title":"Apagado en 10 min.","message":"Fin del tiempo de acceso remoto.\nEl ordenador se apagará automáticamente dentro de 10 minutos."}' ;; + *) DATA='{"title":"Shutdown after 10 min.","message":"Remote access time is ended.\nComputer will be powered off automaticly after 10 minutes."}' ;; + esac + ;; + popup-5) # Message: 5 min. before power off. + AGNTURL=https://$AGNTIP:8000/opengnsys/popup + case "$LANGUAGE" in + es) DATA='{"title":"Apagado en 5 min.","message":"El ordenador se apagará automáticamente dentro de 5 minutos.\nATENCIÓN: Este es el último aviso."}' ;; + *) DATA='{"title":"Shutdown after 5 min.","message":"The computer will be powered off automaticly after 5 minutes.\nATTENTION: This is the last warning."}' + esac + ;; + poweroff) # Power off client. + AGNTURL=https://$AGNTIP:8000/opengnsys/poweroff + DATA= + ;; + *) # Unknown operation. + AGNTURL= + ;; + esac + # Sending operation to OGAgent. + if [ -n "$AGNTURL" ]; then + CODE=$(curl -ksm 1 -w "%{http_code}" -o /dev/null -H "Authorization: $AGNTKEY" ${DATA:+"-d $DATA"} "$AGNTURL") + case "$CODE" in + 000) # Client does not respond may be halted). + ;; + 200) # Operation sended. + echo "$(date +"%FT%T%z"): $PROG: Operation sended to OGAgent: client=$AGNTIP, oper=$OPER, exectime=\"$DATE $TIME\"" >> $LOGFILE ;; + *) # Operation error. + echo "$(date +"%FT%T%z"): $PROG: Operation error: client=$AGNTIP, oper=$OPER, code=$CODE" >> $LOGFILE ;; + esac + else # Unknown operation. + echo "$(date +"%FT%T%z"): $PROG: Unknown operation: client=$AGNTIP, oper=$OPER" >> $LOGFILE + fi + # Deleting operation from database. + SQL="DELETE FROM ogagent_queue WHERE id='$OPERID';" + [ "$OPER" == "poweroff" ] && SQL="$SQL UPDATE remotepc - SET reserved = NOW() - INTERVAL 1 SECOND, urllogin=NULL, urllogout=NULL + SET reserved = NOW() - INTERVAL 1 SECOND, urllogin=NULL, urllogout=NULL, language=NULL WHERE id = '$CNLTID'; DELETE FROM acciones WHERE idordenador = '$CLNTID' AND descriaccion = 'RemotePC Session';" - mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse "$SQL" - done + mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse "$SQL" + done |