forked from shaba/openuds
Refactoring, to make things easier to understand and use
This commit is contained in:
parent
3c81d4ab5a
commit
bef6a52354
@ -62,6 +62,7 @@ encoding//src/uds/core/services/ServiceProviderFactory.py=utf-8
|
||||
encoding//src/uds/core/services/__init__.py=utf-8
|
||||
encoding//src/uds/core/transports/BaseTransport.py=utf-8
|
||||
encoding//src/uds/core/transports/TransportsFactory.py=utf-8
|
||||
encoding//src/uds/core/transports/__init__.py=utf-8
|
||||
encoding//src/uds/core/ui/UserInterface.py=utf-8
|
||||
encoding//src/uds/core/util/AutoAttributes.py=utf-8
|
||||
encoding//src/uds/core/util/Cache.py=utf-8
|
||||
@ -132,6 +133,7 @@ encoding//src/uds/transports/RDP/TSRDPTransport.py=utf-8
|
||||
encoding//src/uds/transports/RDP/__init__.py=utf-8
|
||||
encoding//src/uds/transports/RDP/web.py=utf-8
|
||||
encoding//src/uds/transports/RGS-enterprise/RGSTransport.py=utf-8
|
||||
encoding//src/uds/transports/RGS-enterprise/TRGSTransport.py=utf-8
|
||||
encoding//src/uds/transports/RGS-enterprise/__init__.py=utf-8
|
||||
encoding//src/uds/transports/RGS/RGSTransport.py=utf-8
|
||||
encoding//src/uds/transports/RGS/TRGSTransport.py=utf-8
|
||||
|
@ -38,18 +38,18 @@ from django.db.models import signals
|
||||
|
||||
# Make sure that all services are "available" at service startup
|
||||
import services # to make sure that the packages are initialized at this point
|
||||
import auths# To make sure that the packages are initialized at this point
|
||||
from osmanagers import * # To make sure that packages are initialized at this point
|
||||
from transports import * # To make sure that packages are initialized at this point
|
||||
|
||||
import auths # To make sure that the packages are initialized at this point
|
||||
import osmanagers # To make sure that packages are initialized at this point
|
||||
import transports # To make sure that packages are initialized at this point
|
||||
import models
|
||||
|
||||
|
||||
def modify_MySQL_storage(sender, **kwargs):
|
||||
from django.db import connection
|
||||
cursor = connection.cursor()
|
||||
|
||||
innoDbTables = ( uds.models.UserService, uds.models.DeployedService, uds.models.DeployedServicePublication,
|
||||
uds.models.Scheduler, uds.models.DelayedTask, )
|
||||
innoDbTables = ( models.UserService, models.DeployedService, models.DeployedServicePublication,
|
||||
models.Scheduler, models.DelayedTask, )
|
||||
dicTables = { k._meta.db_table: True for k in innoDbTables }
|
||||
|
||||
for model in kwargs['created_models']:
|
||||
@ -58,4 +58,4 @@ def modify_MySQL_storage(sender, **kwargs):
|
||||
stmt = 'ALTER TABLE %s ENGINE=%s' % (db_table,'InnoDB')
|
||||
cursor.execute(stmt)
|
||||
|
||||
signals.post_syncdb.connect(modify_MySQL_storage, sender=uds.models)
|
||||
signals.post_syncdb.connect(modify_MySQL_storage, sender=models)
|
||||
|
@ -39,7 +39,7 @@ import base64, os.path, sys, logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class BaseModule(UserInterface, Environmentable, Serializable):
|
||||
class Module(UserInterface, Environmentable, Serializable):
|
||||
'''
|
||||
Base class for all modules used by UDS.
|
||||
This base module provides all the needed methods that modules must implement
|
||||
|
@ -34,8 +34,13 @@ This package contains all core-related code for UDS
|
||||
'''
|
||||
|
||||
# Core needs tasks manager to register scheduled jobs, so we ensure of that here
|
||||
from managers.TaskManager import TaskManager
|
||||
from BaseModule import Module
|
||||
import services
|
||||
import auths
|
||||
import transports
|
||||
|
||||
TaskManager.registerScheduledTask()
|
||||
def __init__():
|
||||
from managers.TaskManager import TaskManager
|
||||
TaskManager.registerScheduledTask()
|
||||
|
||||
__init__()
|
@ -31,7 +31,7 @@ Base module for all authenticators
|
||||
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from uds.core.BaseModule import BaseModule
|
||||
from uds.core import Module
|
||||
from django.utils.translation import ugettext_noop as translatable
|
||||
from GroupsManager import GroupsManager
|
||||
from Exceptions import InvalidUserException
|
||||
@ -39,7 +39,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Authenticator(BaseModule):
|
||||
class Authenticator(Module):
|
||||
'''
|
||||
This class represents the base interface to implement authenticators.
|
||||
|
||||
|
@ -33,12 +33,11 @@
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.util.State import State
|
||||
from uds.core.BaseModule import BaseModule
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
from uds.core import Module
|
||||
|
||||
STORAGE_KEY = 'osmk'
|
||||
|
||||
class BaseOSManager(BaseModule):
|
||||
class BaseOSManager(Module):
|
||||
'''
|
||||
An OS Manager is responsible for communication the service the different actions to take (i.e. adding a windows machine to a domain)
|
||||
The Service (i.e. virtual machine) communicates with the OSManager via a published web method, that must include the unique ID.
|
||||
|
@ -31,9 +31,9 @@
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from django.utils.translation import ugettext_noop as translatable
|
||||
from uds.core.BaseModule import BaseModule
|
||||
from uds.core import Module
|
||||
|
||||
class Service(BaseModule):
|
||||
class Service(Module):
|
||||
'''
|
||||
This class is in fact an interface, and represents a service, that is the
|
||||
definition of an offering for consumers (users).
|
||||
|
@ -30,13 +30,13 @@
|
||||
'''
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from uds.core.BaseModule import BaseModule
|
||||
from uds.core import Module
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ServiceProvider(BaseModule):
|
||||
class ServiceProvider(Module):
|
||||
'''
|
||||
Base Service Provider Class.
|
||||
|
||||
|
@ -30,16 +30,6 @@
|
||||
'''
|
||||
UDS Service modules interfaces and classes.
|
||||
|
||||
From 1.0 onwards, the refactoring of UDS has started.
|
||||
|
||||
We can access the base service interfaces the old method, or recommended
|
||||
and easier use the new one, that is "from uds.core.services import ..."
|
||||
|
||||
The new valid names for classes are:
|
||||
* **factory** for old ServiceProviderFactory.ServiceProviderFactory.factory()
|
||||
|
||||
I think this is an easier to use and understand way of accessing this classes
|
||||
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
|
||||
|
@ -33,9 +33,9 @@
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from uds.core.util import OsDetector
|
||||
from uds.core.BaseModule import BaseModule
|
||||
from uds.core.BaseModule import Module
|
||||
|
||||
class BaseTransport(BaseModule):
|
||||
class Transport(Module):
|
||||
'''
|
||||
An OS Manager is responsible for communication the service the different actions to take (i.e. adding a windows machine to a domain)
|
||||
The Service (i.e. virtual machine) communicates with the OSManager via a published web method, that must include the unique ID.
|
||||
@ -45,7 +45,7 @@ class BaseTransport(BaseModule):
|
||||
'''
|
||||
# Transport informational related data, inherited from BaseModule
|
||||
typeName = 'Base Transport Manager'
|
||||
typeType = 'BaseTransport'
|
||||
typeType = 'Base Transport'
|
||||
typeDescription = 'Base Transport'
|
||||
iconFile = 'transport.png'
|
||||
needsJava = False # If this transport needs java for rendering
|
||||
@ -60,7 +60,7 @@ class BaseTransport(BaseModule):
|
||||
tcTransport = False
|
||||
|
||||
def __init__(self,environment, values):
|
||||
super(BaseTransport, self).__init__(environment, values)
|
||||
super(Transport, self).__init__(environment, values)
|
||||
self.initialize(values)
|
||||
|
||||
def initialize(self, values):
|
||||
|
@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
UDS Service modules interfaces and classes.
|
||||
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from BaseTransport import Transport
|
||||
|
||||
def factory():
|
||||
'''
|
||||
Returns factory for register/access to service providers
|
||||
'''
|
||||
from TransportsFactory import TransportsFactory
|
||||
return TransportsFactory.factory()
|
@ -33,14 +33,11 @@
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import signals
|
||||
from uds.core.services.ServiceProviderFactory import ServiceProviderFactory
|
||||
from uds.core.osmanagers.OSManagersFactory import OSManagersFactory
|
||||
from uds.core.transports.TransportsFactory import TransportsFactory
|
||||
from uds.core.jobs.JobsFactory import JobsFactory
|
||||
from uds.core.Environment import Environment
|
||||
from uds.core.util.db.LockingManager import LockingManager
|
||||
from uds.core.util.State import State
|
||||
from uds.core import auths
|
||||
from uds.core.services.Exceptions import InvalidServiceException
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@ -119,6 +116,7 @@ class Provider(models.Model):
|
||||
return sp
|
||||
|
||||
def getType(self):
|
||||
from uds.core import services
|
||||
'''
|
||||
Get the type of the object this record represents.
|
||||
|
||||
@ -127,7 +125,7 @@ class Provider(models.Model):
|
||||
Returns:
|
||||
The python type for this record object
|
||||
'''
|
||||
return ServiceProviderFactory.factory().lookup(self.data_type)
|
||||
return services.factory().lookup(self.data_type)
|
||||
|
||||
def __unicode__(self):
|
||||
return "{0} of type {1} (id:{2})".format(self.name, self.data_type, self.id)
|
||||
@ -403,7 +401,9 @@ class Transport(models.Model):
|
||||
|
||||
:note: We only need to get info from this, not access specific data (class specific info)
|
||||
'''
|
||||
return TransportsFactory.factory().lookup(self.data_type)
|
||||
from uds.core import transports
|
||||
|
||||
return transports.factory().lookup(self.data_type)
|
||||
|
||||
def validForIp(self, ip):
|
||||
'''
|
||||
@ -521,6 +521,7 @@ class Authenticator(models.Model):
|
||||
|
||||
:note: We only need to get info from this, not access specific data (class specific info)
|
||||
'''
|
||||
from uds.core import auths
|
||||
return auths.factory().lookup(self.data_type)
|
||||
|
||||
def getOrCreateUser(self, username, realName = None):
|
||||
@ -896,6 +897,8 @@ class DeployedService(models.Model):
|
||||
|
||||
'''
|
||||
# We have to check if at least one group from this user is valid for this deployed service
|
||||
from uds.core import auths
|
||||
|
||||
logger.debug('User: {0}'.format(user.id))
|
||||
logger.debug('DeployedService: {0}'.format(self.id))
|
||||
if len( set(user.groups.all()) & set(self.assignedGroups.all()) ) == 0:
|
||||
@ -915,9 +918,10 @@ class DeployedService(models.Model):
|
||||
Returns:
|
||||
List of accesible deployed services
|
||||
'''
|
||||
from uds.core import services
|
||||
list1 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state__exact=State.ACTIVE, state = State.ACTIVE).distinct().annotate(cuenta=models.Count('publications')).exclude(cuenta__eq=0)
|
||||
# Now get deployed services that DO NOT NEED publication
|
||||
doNotNeedPublishing = [ t.type() for t in ServiceProviderFactory.factory().servicesThatDoNotNeedPublication() ]
|
||||
doNotNeedPublishing = [ t.type() for t in services.factory().servicesThatDoNotNeedPublication() ]
|
||||
list2 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state__exact=State.ACTIVE, service__data_type__in=doNotNeedPublishing, state = State.ACTIVE)
|
||||
return [ r for r in list1 ] + [ r for r in list2 ]
|
||||
|
||||
|
@ -28,10 +28,10 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
Authentication modules for uds are contained inside this module.
|
||||
Authentication modules for uds are contained inside this package.
|
||||
To create a new authentication module, you will need to follow this steps:
|
||||
1.- Create the authentication module, probably based on an existing one
|
||||
2.- Insert the module as child of this module
|
||||
2.- Insert the module package as child of this package
|
||||
3.- Import the class of your authentication module at __init__. For example::
|
||||
from Authenticator import SimpleAthenticator
|
||||
4.- Done. At Server restart, the module will be recognized, loaded and treated
|
||||
@ -60,4 +60,4 @@ def __init__():
|
||||
for cls in p.__subclasses__():
|
||||
services.factory().insert(cls)
|
||||
|
||||
__init__()
|
||||
__init__()
|
||||
|
@ -36,7 +36,7 @@ Created on Jul 29, 2011
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core.transports.BaseTransport import BaseTransport
|
||||
from uds.core.transports.BaseTransport import Transport
|
||||
from uds.core.util import connection
|
||||
from web import generateHtmlForNX, getHtmlComponent
|
||||
|
||||
@ -46,7 +46,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
|
||||
class NXTransport(BaseTransport):
|
||||
class NXTransport(Transport):
|
||||
'''
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
|
@ -12,7 +12,7 @@
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core.transports.BaseTransport import BaseTransport
|
||||
from uds.core.transports.BaseTransport import Transport
|
||||
from uds.core.util import connection
|
||||
from web import generateHtmlForRdp, getHtmlComponent
|
||||
|
||||
@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
|
||||
class RDPTransport(BaseTransport):
|
||||
class RDPTransport(Transport):
|
||||
'''
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
|
@ -12,7 +12,7 @@
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core.transports.BaseTransport import BaseTransport
|
||||
from uds.core.transports.BaseTransport import Transport
|
||||
from uds.core.util import connection
|
||||
from uds.core.util.Cache import Cache
|
||||
from web import generateHtmlForRdp, getHtmlComponent
|
||||
@ -23,7 +23,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
|
||||
class TSRDPTransport(BaseTransport):
|
||||
class TSRDPTransport(Transport):
|
||||
'''
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
|
@ -36,7 +36,7 @@ Created on Jul 29, 2011
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core.transports.BaseTransport import BaseTransport
|
||||
from uds.core.transports.BaseTransport import Transport
|
||||
from uds.core.util.Cache import Cache
|
||||
from uds.core.util import connection
|
||||
from web import generateHtmlForNX, getHtmlComponent
|
||||
@ -47,7 +47,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
|
||||
class TSNXTransport(BaseTransport):
|
||||
class TSNXTransport(Transport):
|
||||
'''
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
|
@ -28,14 +28,36 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
Transport modules for UDS are contained inside this package.
|
||||
To create a new transport module, you will need to follow this steps:
|
||||
1.- Create the transport module, probably based on an existing one
|
||||
2.- Insert the module package as child of this package
|
||||
3.- Import the class of your transport module at __init__. For example::
|
||||
from Transport import SimpleTransport
|
||||
4.- Done. At Server restart, the module will be recognized, loaded and treated
|
||||
|
||||
The registration of modules is done locating subclases of :py:class:`uds.core.auths.Authentication`
|
||||
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
|
||||
import os.path, pkgutil
|
||||
import sys
|
||||
import uds.core
|
||||
|
||||
# Dinamycally import children of this package. The __init__.py files must register, if needed, inside TransportsFactory
|
||||
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
|
||||
for _, name, _ in pkgutil.iter_modules([pkgpath]):
|
||||
__import__(name, globals(), locals(), [], -1)
|
||||
def __init__():
|
||||
'''
|
||||
This imports all packages that are descendant of this package, and, after that,
|
||||
it register all subclases of service provider as
|
||||
'''
|
||||
import os.path, pkgutil
|
||||
import sys
|
||||
from uds.core import transports
|
||||
|
||||
# Dinamycally import children of this package. The __init__.py files must import classes
|
||||
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
|
||||
for _, name, _ in pkgutil.iter_modules([pkgpath]):
|
||||
__import__(name, globals(), locals(), [], -1)
|
||||
|
||||
p = transports.Transport
|
||||
# This is marked as error in IDE, but it's not (__subclasses__)
|
||||
for cls in p.__subclasses__():
|
||||
transports.factory().insert(cls)
|
||||
|
||||
__init__()
|
||||
|
Loading…
x
Reference in New Issue
Block a user