forked from shaba/openuds
* Some code cleanup
* Added unicode_literals to more modules & tested it
This commit is contained in:
parent
616300decb
commit
0bf1f510dd
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from uds.core.util.Config import GlobalConfig
|
from uds.core.util.Config import GlobalConfig
|
||||||
from uds.models import DeployedService, getSqlDatetime
|
from uds.models import DeployedService, getSqlDatetime
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from uds.core.util.Cache import Cache
|
from uds.core.util.Cache import Cache
|
||||||
from uds.core.jobs.Job import Job
|
from uds.core.jobs.Job import Job
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from uds.core.util.Config import GlobalConfig
|
from uds.core.util.Config import GlobalConfig
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from uds.core.util.Config import GlobalConfig
|
from uds.core.util.Config import GlobalConfig
|
||||||
from uds.models import DeployedService, getSqlDatetime
|
from uds.models import DeployedService, getSqlDatetime
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from uds.core.managers.PublicationManager import PublicationManager
|
from uds.core.managers.PublicationManager import PublicationManager
|
||||||
from uds.core.util.Config import GlobalConfig
|
from uds.core.util.Config import GlobalConfig
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from uds.models import DeployedService
|
from uds.models import DeployedService
|
||||||
from uds.core.util.State import State
|
from uds.core.util.State import State
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||||
|
@ -13,7 +13,7 @@ from django.utils.translation import ugettext_noop as _
|
|||||||
from uds.core.ui.UserInterface import gui
|
from uds.core.ui.UserInterface import gui
|
||||||
from uds.core.managers.CryptoManager import CryptoManager
|
from uds.core.managers.CryptoManager import CryptoManager
|
||||||
from uds.core import osmanagers
|
from uds.core import osmanagers
|
||||||
from WindowsOsManager import WindowsOsManager, scrambleMsg
|
from WindowsOsManager import WindowsOsManager
|
||||||
from uds.core.util import log
|
from uds.core.util import log
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
import ldap
|
import ldap
|
||||||
@ -124,7 +124,7 @@ class WinDomainOsManager(WindowsOsManager):
|
|||||||
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
|
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
|
||||||
logger.warn('Could not find _ldap._tcp.'+self._domain)
|
logger.warn('Could not find _ldap._tcp.'+self._domain)
|
||||||
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER);
|
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER);
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError:
|
||||||
logger.exception('Ldap Exception caught')
|
logger.exception('Ldap Exception caught')
|
||||||
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER);
|
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER);
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ class WinDomainOsManager(WindowsOsManager):
|
|||||||
logger.exception('Exception ')
|
logger.exception('Exception ')
|
||||||
return [False, str(e)]
|
return [False, str(e)]
|
||||||
try:
|
try:
|
||||||
r = l.search_st(self._ou, ldap.SCOPE_BASE)
|
l.search_st(self._ou, ldap.SCOPE_BASE)
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as e:
|
||||||
return _('Check error: {0}').format(self.__getLdapError(e))
|
return _('Check error: {0}').format(self.__getLdapError(e))
|
||||||
|
|
||||||
@ -213,10 +213,10 @@ class WinDomainOsManager(WindowsOsManager):
|
|||||||
super(WinDomainOsManager, self).unmarshal(data[5].decode('hex'))
|
super(WinDomainOsManager, self).unmarshal(data[5].decode('hex'))
|
||||||
|
|
||||||
def valuesDict(self):
|
def valuesDict(self):
|
||||||
dict = super(WinDomainOsManager,self).valuesDict()
|
dct = super(WinDomainOsManager,self).valuesDict()
|
||||||
dict['domain'] = self._domain
|
dct['domain'] = self._domain
|
||||||
dict['ou'] = self._ou
|
dct['ou'] = self._ou
|
||||||
dict['account'] = self._account
|
dct['account'] = self._account
|
||||||
dict['password'] = self._password
|
dct['password'] = self._password
|
||||||
return dict
|
return dct
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@ Created on Nov 15, 2012
|
|||||||
@author: dkmaster
|
@author: dkmaster
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -30,9 +30,8 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
|
||||||
from uds.core.ui.UserInterface import gui
|
|
||||||
from uds.core import services
|
from uds.core import services
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from django.utils.translation import ugettext_noop as translatable, ugettext as _
|
from django.utils.translation import ugettext_noop as translatable
|
||||||
from uds.core.services import Service
|
from uds.core.services import Service
|
||||||
from SamplePublication import SamplePublication
|
from SamplePublication import SamplePublication
|
||||||
from SampleUserDeploymentOne import SampleUserDeploymentOne
|
from SampleUserDeploymentOne import SampleUserDeploymentOne
|
||||||
|
@ -56,11 +56,11 @@ def transformId(view_func):
|
|||||||
return _wrapped_view
|
return _wrapped_view
|
||||||
|
|
||||||
|
|
||||||
def scrambleId(request, id):
|
def scrambleId(request, id_):
|
||||||
if request.session.get(SCRAMBLE_SES) == None:
|
if request.session.get(SCRAMBLE_SES) == None:
|
||||||
request.session[SCRAMBLE_SES] = ''.join(random.choice(string.letters) for i in xrange(SCRAMBLE_LEN))
|
request.session[SCRAMBLE_SES] = ''.join(random.choice(string.letters) for _ in xrange(SCRAMBLE_LEN))
|
||||||
return base64.b64encode(str(id) + request.session.get(SCRAMBLE_SES)).encode('hex')
|
return base64.b64encode(str(id_) + request.session.get(SCRAMBLE_SES)).encode('hex')
|
||||||
|
|
||||||
def unscrambleId(request, id):
|
def unscrambleId(request, id_):
|
||||||
idd = base64.b64decode(id.decode('hex'))
|
idd = base64.b64decode(id_.decode('hex'))
|
||||||
return idd[:-SCRAMBLE_LEN]
|
return idd[:-SCRAMBLE_LEN]
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
@ -51,8 +52,8 @@ def getOSManagersTypes(credentials):
|
|||||||
Returns the types of services providers registered in system
|
Returns the types of services providers registered in system
|
||||||
'''
|
'''
|
||||||
res = []
|
res = []
|
||||||
for type in OSManagersFactory.factory().providers().values():
|
for type_ in OSManagersFactory.factory().providers().values():
|
||||||
val = { 'name' : type.name(), 'type' : type.type(), 'description' : type.description(), 'icon' : type.icon() }
|
val = { 'name' : type_.name(), 'type' : type_.type(), 'description' : type_.description(), 'icon' : type_.icon() }
|
||||||
res.append(val)
|
res.append(val)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -71,19 +72,19 @@ def getOSManagers(credentials):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def getOSManagerGui(credentials, type):
|
def getOSManagerGui(credentials, type_):
|
||||||
'''
|
'''
|
||||||
Returns the description of an gui for the specified service provider
|
Returns the description of an gui for the specified service provider
|
||||||
'''
|
'''
|
||||||
spType = OSManagersFactory.factory().lookup(type)
|
spType = OSManagersFactory.factory().lookup(type_)
|
||||||
return spType.guiDescription()
|
return spType.guiDescription()
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def getOSManager(credentials, id):
|
def getOSManager(credentials, id_):
|
||||||
'''
|
'''
|
||||||
Returns the specified service provider (at database)
|
Returns the specified service provider (at database)
|
||||||
'''
|
'''
|
||||||
data = OSManager.objects.get(pk=id)
|
data = OSManager.objects.get(pk=id_)
|
||||||
res = [
|
res = [
|
||||||
{ 'name' : 'name', 'value' : data.name },
|
{ 'name' : 'name', 'value' : data.name },
|
||||||
{ 'name' : 'comments', 'value' : data.comments },
|
{ 'name' : 'comments', 'value' : data.comments },
|
||||||
@ -97,52 +98,52 @@ def getOSManager(credentials, id):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def createOSManager(credentials, type, data):
|
def createOSManager(credentials, type_, data):
|
||||||
'''
|
'''
|
||||||
Creates a new service provider with specified type and data
|
Creates a new service provider with specified type_ and data
|
||||||
It's mandatory that data contains at least 'name' and 'comments'.
|
It's mandatory that data contains at least 'name' and 'comments'.
|
||||||
The expected structure is the same that provided at getServiceProvider
|
The expected structure is the same that provided at getServiceProvider
|
||||||
'''
|
'''
|
||||||
dict = dictFromData(data)
|
dct = dictFromData(data)
|
||||||
try:
|
try:
|
||||||
# First create data without serialization, then serialies data with correct environment
|
# First create data without serialization, then serialies data with correct environment
|
||||||
sp = OSManager.objects.create(name = dict['name'], comments = dict['comments'], data_type = type)
|
sp = OSManager.objects.create(name = dct['name'], comments = dct['comments'], data_type = type_)
|
||||||
sp.data = sp.getInstance(dict).serialize()
|
sp.data = sp.getInstance(dct).serialize()
|
||||||
sp.save()
|
sp.save()
|
||||||
except osmanagers.OSManager.ValidationException, e:
|
except osmanagers.OSManager.ValidationException, e:
|
||||||
sp.delete()
|
sp.delete()
|
||||||
raise ValidationException(str(e))
|
raise ValidationException(str(e))
|
||||||
except IntegrityError: # Must be exception at creation
|
except IntegrityError: # Must be exception at creation
|
||||||
raise InsertException(_('Name %s already exists') % (dict['name']))
|
raise InsertException(_('Name %s already exists') % (dct['name']))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def modifyOSManager(credentials, id, data):
|
def modifyOSManager(credentials, id_, data):
|
||||||
'''
|
'''
|
||||||
Modifies an existing service provider with specified id and data
|
Modifies an existing service provider with specified id_ and data
|
||||||
It's mandatory that data contains at least 'name' and 'comments'.
|
It's mandatory that data contains at least 'name' and 'comments'.
|
||||||
The expected structure is the same that provided at getServiceProvider
|
The expected structure is the same that provided at getServiceProvider
|
||||||
'''
|
'''
|
||||||
osm = OSManager.objects.get(pk=id)
|
osm = OSManager.objects.get(pk=id_)
|
||||||
dps = osm.deployedServices.all().count()
|
dps = osm.deployedServices.all().count()
|
||||||
if dps > 0:
|
if dps > 0:
|
||||||
errorDps = ','.join([ o.name for o in osm.deployedServices.all()])
|
errorDps = ','.join([ o.name for o in osm.deployedServices.all()])
|
||||||
raise ModifyException(_('This os mnager is being used by deployed services') + ' ' + errorDps)
|
raise ModifyException(_('This os mnager is being used by deployed services') + ' ' + errorDps)
|
||||||
dict = dictFromData(data)
|
dct = dictFromData(data)
|
||||||
sp = osm.getInstance(dict)
|
sp = osm.getInstance(dct)
|
||||||
osm.data = sp.serialize()
|
osm.data = sp.serialize()
|
||||||
osm.name = dict['name']
|
osm.name = dct['name']
|
||||||
osm.comments = dict['comments']
|
osm.comments = dct['comments']
|
||||||
osm.save()
|
osm.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def removeOSManager(credentials, id):
|
def removeOSManager(credentials, id_):
|
||||||
'''
|
'''
|
||||||
Removes from os manager with specified id
|
Removes from os manager with specified id_
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
if OSManager.objects.get(pk=id).remove() == False:
|
if OSManager.objects.get(pk=id_).remove() == False:
|
||||||
raise DeleteException(_('There is deployed services using this os manager'))
|
raise DeleteException(_('There is deployed services using this os manager'))
|
||||||
except OSManager.DoesNotExist:
|
except OSManager.DoesNotExist:
|
||||||
raise FindException(_('Can\'t find os manager'))
|
raise FindException(_('Can\'t find os manager'))
|
||||||
@ -150,23 +151,23 @@ def removeOSManager(credentials, id):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def testOsManager(credentials, type, data):
|
def testOsManager(credentials, type_, data):
|
||||||
'''
|
'''
|
||||||
invokes the test function of the specified service provider type, with the suplied data
|
invokes the test function of the specified service provider type_, with the suplied data
|
||||||
'''
|
'''
|
||||||
logger.debug("Testing service provider, type: {0}, data:{1}".format(type, data))
|
logger.debug("Testing service provider, type_: {0}, data:{1}".format(type_, data))
|
||||||
spType = OSManagersFactory.factory().lookup(type)
|
spType = OSManagersFactory.factory().lookup(type_)
|
||||||
# We need an "temporary" environment to test this service
|
# We need an "temporary" environment to test this service
|
||||||
dict = dictFromData(data)
|
dct = dictFromData(data)
|
||||||
res = spType.test(Environment.getTempEnv(), dict)
|
res = spType.test(Environment.getTempEnv(), dct)
|
||||||
return {'ok' : res[0], 'message' : res[1]}
|
return {'ok' : res[0], 'message' : res[1]}
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def checkOSManager(credentials, id):
|
def checkOSManager(credentials, id_):
|
||||||
'''
|
'''
|
||||||
Invokes the check function of the specified service provider
|
Invokes the check function of the specified service provider
|
||||||
'''
|
'''
|
||||||
prov = OSManager.objects.get(id=id)
|
prov = OSManager.objects.get(pk=id_)
|
||||||
sp = prov.getInstance()
|
sp = prov.getInstance()
|
||||||
return sp.check()
|
return sp.check()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user