Fixes & tests on UDS Actor for honoring max session duration (got from

calendars)
This commit is contained in:
Adolfo Gómez García 2016-05-24 07:40:53 +02:00
parent 1b71fef8b4
commit c2d4e995e7
7 changed files with 50 additions and 7 deletions

View File

@ -37,6 +37,7 @@ from PyQt4 import QtGui
from PyQt4 import QtCore
import pickle
import time
import datetime
import signal
from udsactor import ipc
from udsactor import utils
@ -175,10 +176,13 @@ class UDSSystemTray(QtGui.QSystemTrayIcon):
exitAction.triggered.connect(self.about)
self.setContextMenu(self.menu)
self.ipc = MessagesProcessor()
self.sessionStart = datetime.datetime.now()
self.maxIdleTime = None
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.checkIdle)
self.showIdleWarn = True
self.maxSessionTime = None
self.showMaxSessionWarn = True
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.checkTimers)
if self.ipc.isAlive() is False:
raise Exception('No connection to service, exiting.')
@ -206,6 +210,20 @@ class UDSSystemTray(QtGui.QSystemTrayIcon):
# If this is running, it's because he have logged in
self.ipc.sendLogin(operations.getCurrentUser())
def checkTimers(self):
self.checkIdle()
self.checkMaxSession()
def checkMaxSession(self):
if self.maxSessionTime is None or self.maxSessionTime == 0:
return
remainingTime = (datetime.datetime.now() - self.sessionStart).total_seconds() - self.maxSessionTime
if self.showMaxSessionWarn is True and remainingTime < 300: # With five minutes, show a warning message
self.showMaxSessionWarn = False
self.msgDlg.displayMessage('Your session will expire in less that 5 minutes. Please, save your work and disconnect.')
def checkIdle(self):
if self.maxIdleTime is None: # No idle check
return
@ -256,6 +274,12 @@ class UDSSystemTray(QtGui.QSystemTrayIcon):
else:
self.maxIdleTime = None
if 'maxSession' in info:
maxSession = int(info['maxSession'])
# operations.initMaxSession(maxSession)
self.maxSessionTime = maxSession
logger.debug('Set maxsession to {}'.format(maxSession))
def about(self):
self.aboutDlg.exec_()

View File

@ -109,6 +109,7 @@ class Api(object):
self.mac = None
self.url = "{}://{}/rest/actor/".format(('http', 'https')[self.useSSL], self.host)
self.idle = None
self.maxSession = None
self.secretKey = six.text_type(uuid.uuid4())
try:
self.newerRequestLib = requests.__version__.split('.')[0] >= '1'

View File

@ -226,7 +226,11 @@ class CommonService(object):
return
if msg == ipc.REQ_LOGIN:
self.api.login(data)
res = self.api.login(data).split('\t')
# third parameter, if exists, sets maxSession duration to this.
# First & second parameters are ip & hostname of connection source
if len(res) >= 3:
self.api.maxSession = int(res[3]) # Third parameter is max session duration
elif msg == ipc.REQ_LOGOUT:
self.api.logout(data)
self.onLogout(data)
@ -234,6 +238,8 @@ class CommonService(object):
info = {}
if self.api.idle is not None:
info['idle'] = self.api.idle
if self.api.maxSession is not None:
info['maxSession'] = self.api.maxSession
self.ipc.sendInformationMessage(info)
def initIPC(self):

View File

@ -76,7 +76,7 @@ class SensLogon(win32com.server.policy.DesignatedWrapPolicy):
data = self.service.api.login(args[0])
logger.debug('Data received for login: {}'.format(data))
data = data.split('\t')
if len(data) == 2:
if len(data) >= 2:
logger.debug('Data is valid: {}'.format(data))
windir = os.environ['windir']
with open(os.path.join(windir, 'remoteip.txt'), 'w') as f:

View File

@ -39,7 +39,7 @@ from uds.core.util.stats.events import addEvent, ET_LOGIN, ET_LOGOUT
from uds.core.util import log
from uds.core import Module
__updated__ = '2015-05-28'
__updated__ = '2016-05-24'
STORAGE_KEY = 'osmk'
@ -129,7 +129,14 @@ class OSManager(Module):
def maxIdle(self):
'''
If os manager request "max idle", this method will return a value different to None so actors will get informed on Connection
@return Must return None (default if not overriden), or a "max idle" in seconds
@return Must return None (default if not override), or a "max idle" in seconds
'''
return None
def maxSession(self):
'''
If os manager requests "max session duration", this methos will return a value distinct of None so actors will get informed on Connection
@return Must return None (default if not override), or a "max session duration" in seconds
'''
return None

View File

@ -159,6 +159,10 @@ class LinuxOsManager(osmanagers.OSManager):
self.doLog(userService, data, log.ACTOR)
elif msg == "login":
self.loggedIn(userService, data, False)
ip, hostname = userService.getConnectionSource()
deadLine = userService.deployed_service.getDeadline()
ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine)
elif msg == "logout":
self.loggedOut(userService, data, False)
if self._onLogout == 'remove':

View File

@ -167,7 +167,8 @@ class WindowsOsManager(osmanagers.OSManager):
userService.setInUse(True)
# We get the userService logged hostname & ip and returns this
ip, hostname = userService.getConnectionSource()
ret = "{0}\t{1}".format(ip, hostname)
deadLine = userService.deployed_service.getDeadline()
ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine)
elif msg == "logoff" or msg == 'logout':
self.loggedOut(userService, data, False)
if self._onLogout == 'remove':