mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
* 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
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.models import DeployedService, getSqlDatetime
|
||||
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.util.Cache import Cache
|
||||
from uds.core.jobs.Job import Job
|
||||
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import transaction
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
|
@ -30,6 +30,8 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db.models import Q
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.models import DeployedService, getSqlDatetime
|
||||
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.managers.PublicationManager import PublicationManager
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
|
@ -29,6 +29,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.models import DeployedService
|
||||
from uds.core.util.State import State
|
||||
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import transaction
|
||||
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.managers.CryptoManager import CryptoManager
|
||||
from uds.core import osmanagers
|
||||
from WindowsOsManager import WindowsOsManager, scrambleMsg
|
||||
from WindowsOsManager import WindowsOsManager
|
||||
from uds.core.util import log
|
||||
import dns.resolver
|
||||
import ldap
|
||||
@ -124,7 +124,7 @@ class WinDomainOsManager(WindowsOsManager):
|
||||
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
|
||||
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);
|
||||
except ldap.LDAPError as e:
|
||||
except ldap.LDAPError:
|
||||
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);
|
||||
|
||||
@ -149,7 +149,7 @@ class WinDomainOsManager(WindowsOsManager):
|
||||
logger.exception('Exception ')
|
||||
return [False, str(e)]
|
||||
try:
|
||||
r = l.search_st(self._ou, ldap.SCOPE_BASE)
|
||||
l.search_st(self._ou, ldap.SCOPE_BASE)
|
||||
except ldap.LDAPError as e:
|
||||
return _('Check error: {0}').format(self.__getLdapError(e))
|
||||
|
||||
@ -213,10 +213,10 @@ class WinDomainOsManager(WindowsOsManager):
|
||||
super(WinDomainOsManager, self).unmarshal(data[5].decode('hex'))
|
||||
|
||||
def valuesDict(self):
|
||||
dict = super(WinDomainOsManager,self).valuesDict()
|
||||
dict['domain'] = self._domain
|
||||
dict['ou'] = self._ou
|
||||
dict['account'] = self._account
|
||||
dict['password'] = self._password
|
||||
return dict
|
||||
dct = super(WinDomainOsManager,self).valuesDict()
|
||||
dct['domain'] = self._domain
|
||||
dct['ou'] = self._ou
|
||||
dct['account'] = self._account
|
||||
dct['password'] = self._password
|
||||
return dct
|
||||
|
||||
|
@ -4,7 +4,8 @@ Created on Nov 15, 2012
|
||||
@author: dkmaster
|
||||
'''
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -30,9 +30,8 @@
|
||||
'''
|
||||
@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
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
.. 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 SamplePublication import SamplePublication
|
||||
from SampleUserDeploymentOne import SampleUserDeploymentOne
|
||||
|
@ -56,11 +56,11 @@ def transformId(view_func):
|
||||
return _wrapped_view
|
||||
|
||||
|
||||
def scrambleId(request, id):
|
||||
def scrambleId(request, id_):
|
||||
if request.session.get(SCRAMBLE_SES) == None:
|
||||
request.session[SCRAMBLE_SES] = ''.join(random.choice(string.letters) for i in xrange(SCRAMBLE_LEN))
|
||||
return base64.b64encode(str(id) + request.session.get(SCRAMBLE_SES)).encode('hex')
|
||||
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')
|
||||
|
||||
def unscrambleId(request, id):
|
||||
idd = base64.b64decode(id.decode('hex'))
|
||||
def unscrambleId(request, id_):
|
||||
idd = base64.b64decode(id_.decode('hex'))
|
||||
return idd[:-SCRAMBLE_LEN]
|
||||
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.db import IntegrityError
|
||||
@ -51,8 +52,8 @@ def getOSManagersTypes(credentials):
|
||||
Returns the types of services providers registered in system
|
||||
'''
|
||||
res = []
|
||||
for type in OSManagersFactory.factory().providers().values():
|
||||
val = { 'name' : type.name(), 'type' : type.type(), 'description' : type.description(), 'icon' : type.icon() }
|
||||
for type_ in OSManagersFactory.factory().providers().values():
|
||||
val = { 'name' : type_.name(), 'type' : type_.type(), 'description' : type_.description(), 'icon' : type_.icon() }
|
||||
res.append(val)
|
||||
return res
|
||||
|
||||
@ -71,19 +72,19 @@ def getOSManagers(credentials):
|
||||
return res
|
||||
|
||||
@needs_credentials
|
||||
def getOSManagerGui(credentials, type):
|
||||
def getOSManagerGui(credentials, type_):
|
||||
'''
|
||||
Returns the description of an gui for the specified service provider
|
||||
'''
|
||||
spType = OSManagersFactory.factory().lookup(type)
|
||||
spType = OSManagersFactory.factory().lookup(type_)
|
||||
return spType.guiDescription()
|
||||
|
||||
@needs_credentials
|
||||
def getOSManager(credentials, id):
|
||||
def getOSManager(credentials, id_):
|
||||
'''
|
||||
Returns the specified service provider (at database)
|
||||
'''
|
||||
data = OSManager.objects.get(pk=id)
|
||||
data = OSManager.objects.get(pk=id_)
|
||||
res = [
|
||||
{ 'name' : 'name', 'value' : data.name },
|
||||
{ 'name' : 'comments', 'value' : data.comments },
|
||||
@ -97,52 +98,52 @@ def getOSManager(credentials, id):
|
||||
return res
|
||||
|
||||
@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'.
|
||||
The expected structure is the same that provided at getServiceProvider
|
||||
'''
|
||||
dict = dictFromData(data)
|
||||
dct = dictFromData(data)
|
||||
try:
|
||||
# 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.data = sp.getInstance(dict).serialize()
|
||||
sp = OSManager.objects.create(name = dct['name'], comments = dct['comments'], data_type = type_)
|
||||
sp.data = sp.getInstance(dct).serialize()
|
||||
sp.save()
|
||||
except osmanagers.OSManager.ValidationException, e:
|
||||
sp.delete()
|
||||
raise ValidationException(str(e))
|
||||
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
|
||||
|
||||
@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'.
|
||||
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()
|
||||
if dps > 0:
|
||||
errorDps = ','.join([ o.name for o in osm.deployedServices.all()])
|
||||
raise ModifyException(_('This os mnager is being used by deployed services') + ' ' + errorDps)
|
||||
dict = dictFromData(data)
|
||||
sp = osm.getInstance(dict)
|
||||
dct = dictFromData(data)
|
||||
sp = osm.getInstance(dct)
|
||||
osm.data = sp.serialize()
|
||||
osm.name = dict['name']
|
||||
osm.comments = dict['comments']
|
||||
osm.name = dct['name']
|
||||
osm.comments = dct['comments']
|
||||
osm.save()
|
||||
return True
|
||||
|
||||
@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:
|
||||
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'))
|
||||
except OSManager.DoesNotExist:
|
||||
raise FindException(_('Can\'t find os manager'))
|
||||
@ -150,23 +151,23 @@ def removeOSManager(credentials, id):
|
||||
return True
|
||||
|
||||
@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))
|
||||
spType = OSManagersFactory.factory().lookup(type)
|
||||
logger.debug("Testing service provider, type_: {0}, data:{1}".format(type_, data))
|
||||
spType = OSManagersFactory.factory().lookup(type_)
|
||||
# We need an "temporary" environment to test this service
|
||||
dict = dictFromData(data)
|
||||
res = spType.test(Environment.getTempEnv(), dict)
|
||||
dct = dictFromData(data)
|
||||
res = spType.test(Environment.getTempEnv(), dct)
|
||||
return {'ok' : res[0], 'message' : res[1]}
|
||||
|
||||
@needs_credentials
|
||||
def checkOSManager(credentials, id):
|
||||
def checkOSManager(credentials, id_):
|
||||
'''
|
||||
Invokes the check function of the specified service provider
|
||||
'''
|
||||
prov = OSManager.objects.get(id=id)
|
||||
prov = OSManager.objects.get(pk=id_)
|
||||
sp = prov.getInstance()
|
||||
return sp.check()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user