forked from shaba/openuds
Fixed OS Managers to work "nice" with new Actors (and olders)
This commit is contained in:
parent
722c8b2b61
commit
35b27acee3
@ -168,6 +168,7 @@ class Actor(Handler):
|
||||
except Exception:
|
||||
return Actor.result(_('User service not found'), error=ERR_USER_SERVICE_NOT_FOUND)
|
||||
|
||||
logger.debug('In use: {}'.format(service.in_use))
|
||||
inUse = service.in_use
|
||||
|
||||
username = ''
|
||||
@ -191,6 +192,7 @@ class Actor(Handler):
|
||||
|
||||
# Force service reload to check if inUse has changed, so we can log login/logout
|
||||
service = UserService.objects.get(uuid=uuid)
|
||||
logger.debug('service in use: {}, {}'.format(service.in_use, inUse))
|
||||
if service.in_use != inUse: # If state changed, log it
|
||||
instance = service.getInstance()
|
||||
type_ = 'login' if service.in_use else 'logout'
|
||||
|
@ -428,6 +428,7 @@ class UserServiceManager(object):
|
||||
return True
|
||||
|
||||
def isReady(self, uService):
|
||||
return True
|
||||
UserService.objects.update()
|
||||
uService = UserService.objects.get(id=uService.id)
|
||||
logger.debug('Checking ready of {0}'.format(uService))
|
||||
|
@ -129,7 +129,6 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
logger.info("Invoked LinuxOsManager for {0} with params: {1},{2}".format(service, msg, data))
|
||||
# We get from storage the name for this service. If no name, we try to assign a new one
|
||||
ret = "ok"
|
||||
inUse = False
|
||||
notifyReady = False
|
||||
doRemove = False
|
||||
state = service.os_state
|
||||
@ -144,11 +143,12 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
elif msg == "log":
|
||||
self.doLog(service, data, log.ACTOR)
|
||||
elif msg == "login":
|
||||
service.setInUse(True)
|
||||
si = service.getInstance()
|
||||
si.userLoggedIn(data)
|
||||
service.updateData(si)
|
||||
inUse = True
|
||||
elif msg == "logout":
|
||||
service.setInUse(False)
|
||||
si = service.getInstance()
|
||||
si.userLoggedOut(data)
|
||||
service.updateData(si)
|
||||
@ -167,7 +167,6 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
self.notifyIp(service.unique_id, si, data)
|
||||
service.updateData(si)
|
||||
|
||||
service.setInUse(inUse)
|
||||
service.setOsState(state)
|
||||
|
||||
# If notifyReady is not true, save state, let UserServiceManager do it for us else
|
||||
|
@ -23,40 +23,6 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Base script for allowing RDP access
|
||||
baseScript = '''from __future__ import unicode_literals
|
||||
|
||||
import win32security
|
||||
import win32net
|
||||
from udsactor.httpserver import scriptsOnLogout
|
||||
|
||||
# Well known SSID for Remote Desktop Users
|
||||
REMOTE_USERS_SID = 'S-1-5-32-555'
|
||||
|
||||
user = '{user}'
|
||||
|
||||
p = win32security.GetBinarySid(REMOTE_USERS_SID)
|
||||
groupName = win32security.LookupAccountSid(None, p)[0]
|
||||
|
||||
useraAlreadyInGroup = False
|
||||
resumeHandle = 0
|
||||
while True:
|
||||
users, total, resumeHandle = win32net.NetLocalGroupGetMembers(None, groupName, 1, resumeHandle, 32768)
|
||||
if user in [u['name'] for u in users]:
|
||||
useraAlreadyInGroup = True
|
||||
break
|
||||
if resumeHandle == 0:
|
||||
break
|
||||
|
||||
if useraAlreadyInGroup is False:
|
||||
try:
|
||||
userSSID = win32security.LookupAccountName(None, user)[0]
|
||||
win32net.NetLocalGroupAddMembers(None, groupName, 0, [{'sid': userSSID}])
|
||||
except Exception as e:
|
||||
logger.exception('Exception adding user to Remote Desktop Users: {}'.format(e))
|
||||
'''
|
||||
|
||||
|
||||
def scrambleMsg(data):
|
||||
'''
|
||||
Simple scrambler so password are not seen at source page
|
||||
@ -166,7 +132,6 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
logger.info("Invoked WindowsOsManager for {0} with params: {1},{2}".format(service, msg, data))
|
||||
# We get from storage the name for this service. If no name, we try to assign a new one
|
||||
ret = "ok"
|
||||
inUse = False
|
||||
notifyReady = False
|
||||
doRemove = False
|
||||
state = service.os_state
|
||||
@ -179,6 +144,7 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
elif msg == "log":
|
||||
self.doLog(service, data, log.ACTOR)
|
||||
elif msg == "logon" or msg == 'login':
|
||||
service.setInUse(True)
|
||||
si = service.getInstance()
|
||||
si.userLoggedIn(data)
|
||||
service.updateData(si)
|
||||
@ -186,8 +152,8 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
# We get the service logged hostname & ip and returns this
|
||||
ip, hostname = service.getConnectionSource()
|
||||
ret = "{0}\t{1}".format(ip, hostname)
|
||||
inUse = True
|
||||
elif msg == "logoff" or msg == 'logout':
|
||||
service.setInUse(False)
|
||||
si = service.getInstance()
|
||||
si.userLoggedOut(data)
|
||||
service.updateData(si)
|
||||
@ -207,7 +173,6 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
self.notifyIp(service.unique_id, si, data)
|
||||
service.updateData(si)
|
||||
|
||||
service.setInUse(inUse)
|
||||
service.setOsState(state)
|
||||
|
||||
# If notifyReady is not true, save state, let UserServiceManager do it for us else
|
||||
@ -217,6 +182,7 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
if notifyReady is False:
|
||||
service.save()
|
||||
else:
|
||||
logger.debug('Notifying ready')
|
||||
UserServiceManager.manager().notifyReadyFromOsManager(service, '')
|
||||
logger.debug('Returning {} to {} message'.format(ret, msg))
|
||||
if options is not None and options.get('scramble', True) is False:
|
||||
|
Loading…
Reference in New Issue
Block a user