mirror of
https://github.com/dkmstr/openuds.git
synced 2025-02-08 05:57:39 +03:00
Several improvements
* Improved database saving model * Code cleanup improvement :)
This commit is contained in:
parent
6a7d10bf1d
commit
27a29d92e0
@ -8,4 +8,7 @@
|
||||
<key>DJANGO_SETTINGS_MODULE</key>
|
||||
<value>server.settings</value>
|
||||
</pydev_variables_property>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/${PROJECT_DIR_NAME}/src</path>
|
||||
</pydev_pathproperty>
|
||||
</pydev_project>
|
||||
|
@ -180,7 +180,7 @@ class OSManager(Module):
|
||||
def toReady(self, userService):
|
||||
userService.setProperty('loginsCounter', '0')
|
||||
|
||||
def loggedIn(self, userService, userName=None, save=True):
|
||||
def loggedIn(self, userService, userName=None):
|
||||
"""
|
||||
This method:
|
||||
- Add log in event to stats
|
||||
@ -215,7 +215,7 @@ class OSManager(Module):
|
||||
userService.setProperty('loginsCounter', six.text_type(counter))
|
||||
|
||||
|
||||
def loggedOut(self, userService, userName=None, save=True):
|
||||
def loggedOut(self, userService, userName=None):
|
||||
"""
|
||||
This method:
|
||||
- Add log in event to stats
|
||||
|
@ -37,7 +37,6 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import signals
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
from uds.core.Environment import Environment
|
||||
from uds.core.util import log
|
||||
@ -53,8 +52,6 @@ from uds.models.User import User
|
||||
from uds.models.Util import NEVER
|
||||
from uds.models.Util import getSqlDatetime
|
||||
|
||||
from uds.core.services import UserDeployment
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2019-02-06'
|
||||
@ -166,7 +163,7 @@ class UserService(UUIDModel):
|
||||
try: # We may have deleted publication...
|
||||
if self.publication is not None:
|
||||
publicationInstance = self.publication.getInstance()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
# The publication to witch this item points to, does not exists
|
||||
self.publication = None
|
||||
logger.exception("Got exception at getInstance of an userService {}".format(self))
|
||||
@ -255,7 +252,7 @@ class UserService(UUIDModel):
|
||||
"""
|
||||
self.src_ip = ip
|
||||
self.src_hostname = hostname
|
||||
self.save()
|
||||
self.save(update_fields=['src_ip', 'src_hostname'])
|
||||
|
||||
def getConnectionSource(self):
|
||||
"""
|
||||
@ -324,8 +321,6 @@ class UserService(UUIDModel):
|
||||
self.state = state
|
||||
self.save(update_fields=['state', 'state_date'])
|
||||
|
||||
self.save(update_fields=['state', 'state_date'])
|
||||
|
||||
def setOsState(self, state):
|
||||
"""
|
||||
Updates the os state (state of the os) of this object and, optionally, saves it
|
||||
@ -339,6 +334,7 @@ class UserService(UUIDModel):
|
||||
if state != self.os_state:
|
||||
self.state_date = getSqlDatetime()
|
||||
self.os_state = state
|
||||
self.save(update_fields=['os_state', 'state_date'])
|
||||
|
||||
def assignToUser(self, user):
|
||||
"""
|
||||
@ -422,7 +418,6 @@ class UserService(UUIDModel):
|
||||
Mark this user deployed service for removal
|
||||
"""
|
||||
self.setState(State.REMOVABLE)
|
||||
self.save(update_fields=['state', 'state_date'])
|
||||
|
||||
def release(self):
|
||||
"""
|
||||
|
@ -173,12 +173,12 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
elif msg == "log":
|
||||
self.doLog(userService, data, log.ACTOR)
|
||||
elif msg == "login":
|
||||
self.loggedIn(userService, data, False)
|
||||
self.loggedIn(userService, data)
|
||||
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)
|
||||
self.loggedOut(userService, data)
|
||||
doRemove = self.isRemovableOnLogout(userService)
|
||||
elif msg == "ip":
|
||||
# This ocurss on main loop inside machine, so userService is usable
|
||||
@ -196,9 +196,7 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
if doRemove is True:
|
||||
userService.release()
|
||||
else:
|
||||
if notifyReady is False:
|
||||
userService.save()
|
||||
else:
|
||||
if notifyReady:
|
||||
UserServiceManager.manager().notifyReadyFromOsManager(userService, '')
|
||||
logger.debug('Returning {0}'.format(ret))
|
||||
return ret
|
||||
|
@ -8,10 +8,7 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_noop as _, ugettext_lazy
|
||||
from django.conf import settings
|
||||
from uds.core.services import types as serviceTypes
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core import osmanagers
|
||||
@ -19,9 +16,6 @@ from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util import log
|
||||
from uds.models import TicketStore
|
||||
from uds.REST.methods.actor import SECURE_OWNER
|
||||
|
||||
import six
|
||||
|
||||
import logging
|
||||
|
||||
@ -32,14 +26,14 @@ def scrambleMsg(data):
|
||||
"""
|
||||
Simple scrambler so password are not seen at source page
|
||||
"""
|
||||
if isinstance(data, six.text_type):
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf8')
|
||||
res = []
|
||||
n = 0x32
|
||||
for c in data[::-1]:
|
||||
res.append(chr(ord(c) ^ n))
|
||||
n = (n + ord(c)) & 0xFF
|
||||
return six.text_type(b''.join(res).encode('hex'))
|
||||
return (b''.join(res).encode('hex')).decode('utf8')
|
||||
|
||||
|
||||
class WindowsOsManager(osmanagers.OSManager):
|
||||
@ -187,7 +181,7 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
self.doLog(userService, data, log.ACTOR)
|
||||
elif msg == "logon" or msg == 'login':
|
||||
if '\\' not in data:
|
||||
self.loggedIn(userService, data, False)
|
||||
self.loggedIn(userService, data)
|
||||
userService.setInUse(True)
|
||||
# We get the userService logged hostname & ip and returns this
|
||||
ip, hostname = userService.getConnectionSource()
|
||||
@ -197,7 +191,7 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
else:
|
||||
ret = "{0}\t{1}".format(ip, hostname)
|
||||
elif msg == "logoff" or msg == 'logout':
|
||||
self.loggedOut(userService, data, False)
|
||||
self.loggedOut(userService, data)
|
||||
doRemove = self.isRemovableOnLogout(userService)
|
||||
elif msg == "ip":
|
||||
# This ocurss on main loop inside machine, so userService is usable
|
||||
@ -273,7 +267,7 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
"""
|
||||
Serializes the os manager data so we can store it in database
|
||||
"""
|
||||
return '\t'.join(['v2', self._onLogout, six.text_type(self._idle)]).encode('utf8')
|
||||
return '\t'.join(['v2', self._onLogout, str(self._idle)]).encode('utf8')
|
||||
|
||||
def unmarshal(self, s):
|
||||
data = s.decode('utf8').split('\t')
|
||||
|
@ -537,25 +537,6 @@ class OVirtLinkedDeployment(UserDeployment):
|
||||
|
||||
return self.__executeQueue()
|
||||
|
||||
def userLoggedIn(self, user):
|
||||
"""
|
||||
This method must be available so os managers can invoke it whenever
|
||||
an user get logged into a service.
|
||||
|
||||
The user provided is just an string, that is provided by actor.
|
||||
"""
|
||||
# We store the value at storage, but never get used, just an example
|
||||
pass
|
||||
|
||||
def userLoggedOut(self, user):
|
||||
"""
|
||||
This method must be available so os managers can invoke it whenever
|
||||
an user get logged out if a service.
|
||||
|
||||
The user provided is just an string, that is provided by actor.
|
||||
"""
|
||||
pass
|
||||
|
||||
def reasonOfError(self):
|
||||
"""
|
||||
Returns the reason of the error.
|
||||
|
@ -473,25 +473,6 @@ class LiveDeployment(UserDeployment):
|
||||
|
||||
return self.__executeQueue()
|
||||
|
||||
def userLoggedIn(self, user):
|
||||
"""
|
||||
This method must be available so os managers can invoke it whenever
|
||||
an user get logged into a service.
|
||||
|
||||
The user provided is just an string, that is provided by actor.
|
||||
"""
|
||||
# We store the value at storage, but never get used, just an example
|
||||
pass
|
||||
|
||||
def userLoggedOut(self, user):
|
||||
"""
|
||||
This method must be available so os managers can invoke it whenever
|
||||
an user get logged out if a service.
|
||||
|
||||
The user provided is just an string, that is provided by actor.
|
||||
"""
|
||||
pass
|
||||
|
||||
def reasonOfError(self):
|
||||
"""
|
||||
Returns the reason of the error.
|
||||
|
@ -529,25 +529,6 @@ class XenLinkedDeployment(UserDeployment):
|
||||
|
||||
return self.__executeQueue()
|
||||
|
||||
def userLoggedIn(self, user):
|
||||
"""
|
||||
This method must be available so os managers can invoke it whenever
|
||||
an user get logged into a service.
|
||||
|
||||
The user provided is just an string, that is provided by actor.
|
||||
"""
|
||||
# We store the value at storage, but never get used, just an example
|
||||
pass
|
||||
|
||||
def userLoggedOut(self, user):
|
||||
"""
|
||||
This method must be available so os managers can invoke it whenever
|
||||
an user get logged out if a service.
|
||||
|
||||
The user provided is just an string, that is provided by actor.
|
||||
"""
|
||||
pass
|
||||
|
||||
def reasonOfError(self):
|
||||
"""
|
||||
Returns the reason of the error.
|
||||
|
Loading…
x
Reference in New Issue
Block a user