1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Stabilizing for 1.7

* Fixed several IDE "false errors"
* Added several needed comments
* Added logging to base os manager to login/logout process
* Fixed Linux & Windows managers to allow use of new base os manager
feature
* Fixed coffe script error that do not allows to create e new service
This commit is contained in:
Adolfo Gómez García 2015-01-21 13:30:37 +01:00
parent 9a95d39156
commit e75c86ad58
10 changed files with 82 additions and 35 deletions

View File

@ -1,3 +1,3 @@
import sys
sys.setdefaultencoding('UTF-8')
sys.setdefaultencoding('UTF-8') # @UndefinedVariable

View File

@ -43,7 +43,7 @@ from uds.core.ui.UserInterface import gui
import logging
__updated__ = '2014-09-15'
__updated__ = '2015-01-21'
logger = logging.getLogger(__name__)
@ -70,7 +70,7 @@ class IPAuth(Authenticator):
return "IP Authenticator"
def getIp(self):
return getRequest().ip_proxy if self.acceptProxy.isTrue() else getRequest().ip
return getRequest().ip_proxy if self.acceptProxy.isTrue() else getRequest().ip # pylint: disable=maybe-no-member
def getGroups(self, ip, groupsManager):
# these groups are a bit special. They are in fact ip-ranges, and we must check that the ip is in betwen

View File

@ -44,6 +44,7 @@ from uds.core.util.Config import GlobalConfig
from uds.core.util import log
from uds.core.util.decorators import deprecated
from uds.core import auths
from uds.core.util.stats import events
from uds.core.managers.CryptoManager import CryptoManager
from uds.core.util.State import State
from uds.models import User
@ -51,7 +52,7 @@ from uds.models import User
import logging
import six
__updated__ = '2014-11-11'
__updated__ = '2015-01-21'
logger = logging.getLogger(__name__)
authLogger = logging.getLogger('authLog')
@ -162,6 +163,7 @@ def __registerUser(authenticator, authInstance, username):
if usr is not None and State.isActive(usr.state):
# Now we update database groups for this user
usr.getManager().recreateGroups(usr)
events.addEvent(authenticator, events.ET_LOGIN, fld1=username)
return usr
return None

View File

@ -44,12 +44,15 @@ import threading
import time
import logging
__updated__ = '2014-05-26'
__updated__ = '2015-01-21'
logger = logging.getLogger(__name__)
class DelayedTaskThread(threading.Thread):
'''
Class responsible of executing a delayed task in its own thread
'''
def __init__(self, taskInstance):
super(DelayedTaskThread, self).__init__()
self._taskInstance = taskInstance
@ -62,6 +65,9 @@ class DelayedTaskThread(threading.Thread):
class DelayedTaskRunner(object):
'''
Delayed task runner class
'''
CODEC = 'base64' # Can be zip, hez, bzip, base64, uuencoded
# How often tasks r checked
granularity = 2
@ -75,11 +81,20 @@ class DelayedTaskRunner(object):
self._keepRunning = True
def notifyTermination(self):
'''
Invoke this whenever you want to terminate the delayed task runner thread
It will mark the thread to "stop" ASAP
'''
self._keepRunning = False
@staticmethod
def runner():
if DelayedTaskRunner._runner == None:
'''
Static method that returns an instance (singleton instance) to a Delayed Runner.
There is only one instance of DelayedTaksRunner, but its "run" method is executed on
many thread (depending on configuration). They all share common Instance data
'''
if DelayedTaskRunner._runner is None:
DelayedTaskRunner._runner = DelayedTaskRunner()
return DelayedTaskRunner._runner
@ -90,7 +105,7 @@ class DelayedTaskRunner(object):
taskInstance = None
try:
with transaction.atomic(): # Encloses
task = dbDelayedTask.objects.select_for_update().filter(filt).order_by('execution_time')[0]
task = dbDelayedTask.objects.select_for_update().filter(filt).order_by('execution_time')[0] # @UndefinedVariable
taskInstanceDump = task.instance.decode(self.CODEC)
task.delete()
taskInstance = loads(taskInstanceDump)
@ -99,7 +114,7 @@ class DelayedTaskRunner(object):
# Note that is taskInstance can't be loaded, this task will not be retried
return
if taskInstance != None:
if taskInstance is not None:
logger.debug('Executing delayedTask:>{0}<'.format(task))
env = Environment.getEnvForType(taskInstance.__class__)
taskInstance.setEnv(env)
@ -114,8 +129,8 @@ class DelayedTaskRunner(object):
logger.debug('Inserting delayed task {0} with {1} bytes ({2})'.format(typeName, len(instanceDump), exec_time))
dbDelayedTask.objects.create(type=typeName, instance=instanceDump,
insert_date=now, execution_delay=delay, execution_time=exec_time, tag=tag)
dbDelayedTask.objects.create(type=typeName, instance=instanceDump, # @UndefinedVariable
insert_date=now, execution_delay=delay, execution_time=exec_time, tag=tag)
def insert(self, instance, delay, tag=''):
retries = 3
@ -136,7 +151,7 @@ class DelayedTaskRunner(object):
def remove(self, tag):
try:
with transaction.atomic():
dbDelayedTask.objects.select_for_update().filter(tag=tag).delete()
dbDelayedTask.objects.select_for_update().filter(tag=tag).delete() # @UndefinedVariable
except Exception as e:
logger.exception('Exception removing a delayed task {0}: {1}'.format(str(e.__class__), e))
@ -147,7 +162,7 @@ class DelayedTaskRunner(object):
number = 0
try:
number = dbDelayedTask.objects.filter(tag=tag).count()
number = dbDelayedTask.objects.filter(tag=tag).count() # @UndefinedVariable
except Exception:
logger.error('Exception looking for a delayed task tag {0}'.format(tag))
return number > 0

View File

@ -150,6 +150,7 @@ class StatsManager(object):
'''
logger.debug('Adding event stat')
if stamp is None:
stamp = getSqlDatetime(unix=True)
else:
@ -160,7 +161,8 @@ class StatsManager(object):
fld1 = fld1 or ''
fld2 = fld2 or ''
fld3 = fld3 or ''
StatsEvents.objects.create(owner_type=owner_type, owner_id=owner_id, event_type=eventType, stamp=stamp, fld1=fld1, fld2=fld2, fld3=fld3)
obj = StatsEvents.objects.create(owner_type=owner_type, owner_id=owner_id, event_type=eventType, stamp=stamp, fld1=fld1, fld2=fld2, fld3=fld3)
logger.debug('Created event {}'.format(obj))
return True
except Exception:
logger.error('Exception handling event stats saving (maybe database is full?)')

View File

@ -34,9 +34,11 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext_noop as _
from uds.core.util.State import State
from uds.core.util.stats.events import addEvent, ET_LOGIN, ET_LOGOUT
from uds.core.util import log
from uds.core import Module
__updated__ = '2014-12-07'
__updated__ = '2015-01-21'
STORAGE_KEY = 'osmk'
@ -157,5 +159,43 @@ class OSManager(Module):
'''
pass
def loggedIn(self, userService, userName=None, save=True):
'''
This method:
- Add log in event to stats
- Sets service in use
- Invokes userLoggedIn for user service instance
'''
addEvent(userService.deployed_service, ET_LOGIN, fld1=userName)
log.doLog(userService, log.INFO, "User {0} has logged in", log.OSMANAGER)
userService.setInUse(True)
si = userService.getInstance()
si.userLoggedIn(userName)
userService.updateData(si)
if save:
userService.save()
def loggedOut(self, userService, userName=None, save=True):
'''
This method:
- Add log in event to stats
- Sets service in use
- Invokes userLoggedIn for user service instance
'''
addEvent(userService.deployed_service, ET_LOGOUT, fld1=userName)
log.doLog(userService, log.INFO, "User {0} has logged out", log.OSMANAGER)
userService.setInUse(False)
si = userService.getInstance()
si.userLoggedOut(userName)
userService.updateData(si)
if save:
userService.save()
def __str__(self):
return "Base OS Manager"
def __unicode__(self):
return self.__str__()

View File

@ -33,7 +33,7 @@
from __future__ import unicode_literals
__updated__ = '2014-09-16'
__updated__ = '2015-01-21'
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@ -74,8 +74,8 @@ class Authenticator(ManagedObjectModel):
Every single record of Provider model, represents an object.
Args:
values (list): Values to pass to constructor. If no values are especified,
the object is instantiated empty and them de-serialized from stored data.
values (list): Values to pass to constructor. If no values are specified,
the object is instantiated empty and them deserialized from stored data.
Returns:
The instance Instance of the class this provider represents

View File

@ -143,15 +143,9 @@ 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)
self.loggedIn(service, data, False)
elif msg == "logout":
service.setInUse(False)
si = service.getInstance()
si.userLoggedOut(data)
service.updateData(si)
self.loggedOut(service, data, False)
if self._onLogout == 'remove':
doRemove = True
elif msg == "ip":

View File

@ -145,20 +145,13 @@ class WindowsOsManager(osmanagers.OSManager):
elif msg == "log":
self.doLog(service, data, log.ACTOR)
elif msg == "logon" or msg == 'login':
self.loggedIn(service, data, False)
service.setInUse(True)
si = service.getInstance()
si.userLoggedIn(data)
service.updateData(si)
self.doLog(service, 'User {0} has logged IN\t{1}'.format(data, log.INFOSTR))
# We get the service logged hostname & ip and returns this
ip, hostname = service.getConnectionSource()
ret = "{0}\t{1}".format(ip, hostname)
elif msg == "logoff" or msg == 'logout':
service.setInUse(False)
si = service.getInstance()
si.userLoggedOut(data)
service.updateData(si)
self.doLog(service, 'User {0} has logged OUT\t{1}'.format(data, log.INFOSTR))
self.loggedOut(service, data, False)
if self._onLogout == 'remove':
doRemove = True
elif msg == "ip":

View File

@ -29,7 +29,8 @@
# Fix multiline text fields to textbox
f.gui.type = "textbox" if f.gui.type is "text" and f.gui.multiline
value = item[f.name]
if value is null
if !value? # If a is null or undefined
gui.doLog "Value is null"
value = f.gui.value or f.gui.defvalue
# We need to convert "array" values for multichoices to single list of ids (much more usable right here)