diff --git a/.gitignore b/.gitignore index 534a7100..ef1c1bea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *_enterprise.* .settings/ .ipynb_checkpoints +.idea/ # Debian buildings *.debhelper* diff --git a/server/src/server/wsgi.py b/server/src/server/wsgi.py index d4259b16..8d36428a 100644 --- a/server/src/server/wsgi.py +++ b/server/src/server/wsgi.py @@ -13,16 +13,22 @@ middleware here, or combine a Django application with an application of another framework. """ -import sys -reload(sys) -sys.setdefaultencoding('UTF-8') # @UndefinedVariable +from django.core.wsgi import get_wsgi_application +import six import os +if six.PY2: + import sys + + # noinspection PyCompatibility + reload(sys) + sys.setdefaultencoding('UTF-8') # @UndefinedVariable + + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. -from django.core.wsgi import get_wsgi_application application = get_wsgi_application() diff --git a/server/src/sitecustomize.py b/server/src/sitecustomize.py index 5eb7f50e..ba9788e0 100644 --- a/server/src/sitecustomize.py +++ b/server/src/sitecustomize.py @@ -1,4 +1,10 @@ -import sys -reload(sys) +import six -sys.setdefaultencoding('utf-8') # @UndefinedVariable +if six.PY2: + import sys + + # noinspection PyCompatibility + reload(sys) + + # noinspection PyUnresolvedReferences + sys.setdefaultencoding('utf-8') # @UndefinedVariable diff --git a/server/src/uds/auths/RegexLdap/Authenticator.py b/server/src/uds/auths/RegexLdap/Authenticator.py index a22c65b8..b51d3a67 100644 --- a/server/src/uds/auths/RegexLdap/Authenticator.py +++ b/server/src/uds/auths/RegexLdap/Authenticator.py @@ -150,7 +150,7 @@ class RegexLdap(auths.Authenticator): for line in field.splitlines(): equalPos = line.find('=') if equalPos == -1: - line = line + '=(.*)' + line += '=(.*)' equalPos = line.find('=') attr, pattern = (line[:equalPos], line[equalPos + 1:]) attr = attr.lower() diff --git a/server/src/uds/auths/Sample/SampleAuth.py b/server/src/uds/auths/Sample/SampleAuth.py index 9b50ad15..c75844d6 100644 --- a/server/src/uds/auths/Sample/SampleAuth.py +++ b/server/src/uds/auths/Sample/SampleAuth.py @@ -305,4 +305,4 @@ class SampleAuth(auths.Authenticator): this this kind of things) modify the userName to a new one, the original plus '-1' ''' usrData['real_name'] = usrData['name'] + ' ' + usrData['name'] - usrData['name'] = usrData['name'] + '-1' + usrData['name'] += '-1' diff --git a/server/src/uds/core/auths/BaseAuthenticator.py b/server/src/uds/core/auths/BaseAuthenticator.py index 83b93242..35897640 100644 --- a/server/src/uds/core/auths/BaseAuthenticator.py +++ b/server/src/uds/core/auths/BaseAuthenticator.py @@ -197,7 +197,7 @@ class Authenticator(Module): user param is a database user object ''' - if self.isExternalSource == True: + if self.isExternalSource: groupsManager = GroupsManager(self._dbAuth) self.getGroups(user.name, groupsManager) user.groups = [g.dbGroup() for g in groupsManager.getValidGroups()] diff --git a/server/src/uds/core/services/ClusteredServiceProvider.py b/server/src/uds/core/services/ClusteredServiceProvider.py index 22a8a9eb..01936493 100644 --- a/server/src/uds/core/services/ClusteredServiceProvider.py +++ b/server/src/uds/core/services/ClusteredServiceProvider.py @@ -35,6 +35,7 @@ from __future__ import unicode_literals from uds.core.services.BaseServiceProvider import ServiceProvider from uds.core.util.Config import GlobalConfig +import six import logging __updated__ = '2016-02-26' @@ -85,7 +86,7 @@ class ClusteredServiceProvider(ServiceProvider): maxCpuLoad = GlobalConfig.CLUSTER_MIGRATE_CPULOAD.getInt(True) minFreeMemPercent = GlobalConfig.CLUSTER_MIGRATE_MEMORYLOAD.getInt(True) - for nodeName, nodeStats in nodesStats.iteritems(): + for nodeName, nodeStats in six.iteritems(nodesStats): if nodeStats['freeMemory'] is None or nodeStats['totalMemory'] is None or nodeStats['cpuLoad'] is None: continue freeMemPercent = (nodeStats['freeMemory'] * 100) / nodeStats['totalMemory'] @@ -123,7 +124,7 @@ class ClusteredServiceProvider(ServiceProvider): maxCpuLoad = GlobalConfig.CLUSTER_ELEGIBLE_CPULOAD.getInt(True) minFreeMemPercent = GlobalConfig.CLUSTER_ELEGIBLE_MEMORYLOAD.getInt(True) - for nodeName, nodeStats in nodesStats.iteritems(): + for nodeName, nodeStats in six.iteritems(nodesStats): if nodeStats['freeMemory'] is None or nodeStats['totalMemory'] is None or nodeStats['cpuLoad'] is None: continue freeMemPercent = (nodeStats['freeMemory'] * 100) / nodeStats['totalMemory'] @@ -144,7 +145,7 @@ class ClusteredServiceProvider(ServiceProvider): def getClusterBestNodeForDeploy(self): nodesStats = self.clusterStats() - nodes = [name for name in nodesStats.iterkeys()] + nodes = [name for name in six.iteritems(nodesStats)] def getNodeStatsKey(name): ns = nodesStats[name] diff --git a/server/src/uds/core/util/FileStorage.py b/server/src/uds/core/util/FileStorage.py index 38f3633d..382f3e34 100644 --- a/server/src/uds/core/util/FileStorage.py +++ b/server/src/uds/core/util/FileStorage.py @@ -71,9 +71,9 @@ class FileStorage(Storage): self.cache._cache.flush_all() # On start, ensures that cache is empty to avoid surprises + # noinspection PyArgumentList Storage.__init__(self, *args, **kwargs) - def get_valid_name(self, name): return name.replace('\\', os.path.sep) diff --git a/server/src/uds/core/util/decorators.py b/server/src/uds/core/util/decorators.py index 0fc8e7b5..ef1dad60 100644 --- a/server/src/uds/core/util/decorators.py +++ b/server/src/uds/core/util/decorators.py @@ -46,11 +46,15 @@ logger = logging.getLogger(__name__) # Decorator that protects pages that needs at least a browser version # Default is to deny IE < 9 -def denyBrowsers(browsers=['ie<9'], errorResponse=lambda request: errors.errorView(request, errors.BROWSER_NOT_SUPPORTED)): +def denyBrowsers(browsers=None, errorResponse=lambda request: errors.errorView(request, errors.BROWSER_NOT_SUPPORTED)): ''' Decorator to set protection to access page Look for samples at uds.core.web.views ''' + + if browsers is None: + browsers = ['ie<9'] + def wrap(view_func): @wraps(view_func) def _wrapped_view(request, *args, **kwargs): diff --git a/server/src/uds/core/util/net.py b/server/src/uds/core/util/net.py index 56609638..8c06f1d1 100644 --- a/server/src/uds/core/util/net.py +++ b/server/src/uds/core/util/net.py @@ -64,7 +64,7 @@ def longToIp(n): while d > 0: m, n = divmod(n, d) q.append(str(m)) - d = d / 256 + d /= 256 return '.'.join(q) except: diff --git a/server/src/uds/core/workers/ClusteredProviderManagement.py b/server/src/uds/core/workers/ClusteredProviderManagement.py index 479e3d2a..b854767d 100644 --- a/server/src/uds/core/workers/ClusteredProviderManagement.py +++ b/server/src/uds/core/workers/ClusteredProviderManagement.py @@ -165,9 +165,9 @@ class ClusterMigrationTask(DelayedTask): logger.debug("uService instance class: {0}".format(ci.__class__)) state = ci.checkState() ClusterMigrationTask.checkAndUpdateState(uService, ci, state) - except UserService.DoesNotExist, e: + except UserService.DoesNotExist as e: logger.error('User service not found (erased from database?) {0} : {1}'.format(e.__class__, e)) - except Exception, e: + except Exception as e: # Exception caught, mark service as errored logger.exception("Error {0}, {1} :".format(e.__class__, e)) if uService is not None: diff --git a/server/src/uds/core/workers/DeployedServiceCleaner.py b/server/src/uds/core/workers/DeployedServiceCleaner.py index 493f2e1c..d3987181 100644 --- a/server/src/uds/core/workers/DeployedServiceCleaner.py +++ b/server/src/uds/core/workers/DeployedServiceCleaner.py @@ -83,7 +83,7 @@ class DeployedServiceRemover(Job): u.cancel() # Nice start of removal, maybe we need to do some limitation later, but there should not be too much services nor publications cancelable at once ds.state = State.REMOVING - ds.name = ds.name + ' (removed)' + ds.name += ' (removed)' ds.save() def continueRemovalOf(self, ds): diff --git a/server/src/uds/dispatchers/guacamole/views.py b/server/src/uds/dispatchers/guacamole/views.py index 309a5fc4..c947315e 100644 --- a/server/src/uds/dispatchers/guacamole/views.py +++ b/server/src/uds/dispatchers/guacamole/views.py @@ -34,9 +34,9 @@ from __future__ import unicode_literals from django.http import HttpResponse from uds.models import TicketStore -from uds.core.util import net from uds.core.auths import auth +import six import logging logger = logging.getLogger(__name__) @@ -48,7 +48,7 @@ CONTENT_TYPE = 'text/plain' def dict2resp(dct): - return '\r'.join((k + '\t' + v for k, v in dct.iteritems())) + return '\r'.join((k + '\t' + v for k, v in six.iteritems(dct))) @auth.trustedSourceRequired diff --git a/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py b/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py index 2346236a..ace62dc9 100644 --- a/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py +++ b/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py @@ -225,8 +225,8 @@ class WindowsOsManager(osmanagers.OSManager): 'password': password, 'domain': domain } - ticket = TicketStore.create(creds, validator=None, validity=300, owner=SECURE_OWNER, secure=True) - return (ticket, '') + ticket = TicketStore.create(creds, validator=None, validity=300) # , owner=SECURE_OWNER, secure=True) + return ticket, '' else: return osmanagers.OSManager.processUserPassword(self, service, username, password) diff --git a/server/src/uds/reports/lists/base.py b/server/src/uds/reports/lists/base.py index 7d5b807a..19240b27 100644 --- a/server/src/uds/reports/lists/base.py +++ b/server/src/uds/reports/lists/base.py @@ -39,4 +39,7 @@ __updated__ = '2015-06-21' class ListReport(reports.Report): + def generate(self): + raise NotImplementedError('ListReport generate invoked and not implemented') + group = _('Lists') # So we can make submenus with reports diff --git a/server/src/uds/services/OpenNebula/on/__init__.py b/server/src/uds/services/OpenNebula/on/__init__.py index 2b1e683d..6f5cc63a 100644 --- a/server/src/uds/services/OpenNebula/on/__init__.py +++ b/server/src/uds/services/OpenNebula/on/__init__.py @@ -64,6 +64,7 @@ from . import template from . import vm from . import storage + # Decorator def ensureConnected(fnc): def inner(*args, **kwargs): @@ -71,19 +72,22 @@ def ensureConnected(fnc): return fnc(*args, **kwargs) return inner + # Result checker def checkResult(lst, parseResult=True): - if lst[0] == False: + if not lst[0]: raise Exception('OpenNebula error {}: "{}"'.format(lst[2], lst[1])) if parseResult: return xml2dict.parse(lst[1]) else: return lst[1] + def asList(element): if isinstance(element, (tuple, list)): return element - return (element,) + return element, + class OpenNebulaClient(object): def __init__(self, username, password, endpoint): diff --git a/server/src/uds/services/OpenStack/openStack/UDSOpenStackClient.py b/server/src/uds/services/OpenStack/openStack/UDSOpenStackClient.py index 4d53c9e3..3ed9d32f 100644 --- a/server/src/uds/services/OpenStack/openStack/UDSOpenStackClient.py +++ b/server/src/uds/services/OpenStack/openStack/UDSOpenStackClient.py @@ -65,7 +65,7 @@ def ensureResponseIsValid(response, errMsg=None): if response.ok is False: try: _x, err = response.json().popitem() # Extract any key, in case of error is expected to have only one top key so this will work - errMsg = errMsg + ': {message}'.format(**err) + errMsg += ': {message}'.format(**err) except Exception: pass # If error geting error message, simply ignore it (will be loged on service log anyway) if errMsg is None: diff --git a/server/src/uds/services/Xen/XenProvider.py b/server/src/uds/services/Xen/XenProvider.py index cd813a5c..3ebbe009 100644 --- a/server/src/uds/services/Xen/XenProvider.py +++ b/server/src/uds/services/Xen/XenProvider.py @@ -37,13 +37,14 @@ from django.utils.translation import ugettext_noop as _ from uds.core.util.State import State from uds.core.services import ServiceProvider from uds.core.ui import gui -from uds.core.util import validators +# from uds.core.util import validators from xen_client import XenServer -from xen_client import XenFailure, XenFault +# from xen_client import XenFailure, XenFault from XenLinkedService import XenLinkedService +import six import logging logger = logging.getLogger(__name__) @@ -395,4 +396,4 @@ class Provider(ServiceProvider): xe.testConnection() return [True, _('Connection test successful')] except Exception as e: - return [False, _("Connection failed: {0}").format(unicode(e))] + return [False, _("Connection failed: {0}").format(six.text_type(e))] diff --git a/server/src/uds/transports/NX/NXPassword.py b/server/src/uds/transports/NX/NXPassword.py index 8013759e..ddf2b08e 100644 --- a/server/src/uds/transports/NX/NXPassword.py +++ b/server/src/uds/transports/NX/NXPassword.py @@ -68,7 +68,6 @@ class NXPassword(object): for i in range(len(p)): sPass += '{}:'.format(ord(p[i]) + i + 1) - print sPass return sPass @staticmethod diff --git a/server/src/uds/transports/NX/NXTransport.py b/server/src/uds/transports/NX/NXTransport.py index c6b71342..a31a94c5 100644 --- a/server/src/uds/transports/NX/NXTransport.py +++ b/server/src/uds/transports/NX/NXTransport.py @@ -200,6 +200,6 @@ class NXTransport(Transport): }.get(os['OS']) if os is None: - return super(NXTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/direct.py'.format(os)).format(r=r) diff --git a/server/src/uds/transports/NX/TSNXTransport.py b/server/src/uds/transports/NX/TSNXTransport.py index 2d9b5e0e..453ff7b0 100644 --- a/server/src/uds/transports/NX/TSNXTransport.py +++ b/server/src/uds/transports/NX/TSNXTransport.py @@ -236,7 +236,7 @@ class TSNXTransport(Transport): }.get(os['OS']) if os is None: - return super(TSNXTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/tunnel.py'.format(os)).format( r=r, diff --git a/server/src/uds/transports/RDP/RDPTransport.py b/server/src/uds/transports/RDP/RDPTransport.py index 8d425723..f8c779f1 100644 --- a/server/src/uds/transports/RDP/RDPTransport.py +++ b/server/src/uds/transports/RDP/RDPTransport.py @@ -145,6 +145,6 @@ class RDPTransport(BaseRDPTransport): }.get(m.os) if os is None: - return super(RDPTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m) diff --git a/server/src/uds/transports/RDP/TRDPTransport.py b/server/src/uds/transports/RDP/TRDPTransport.py index ee236cd8..d2a4b9da 100644 --- a/server/src/uds/transports/RDP/TRDPTransport.py +++ b/server/src/uds/transports/RDP/TRDPTransport.py @@ -179,6 +179,6 @@ class TRDPTransport(BaseRDPTransport): }.get(m.os) if os is None: - return super(TRDPTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m) diff --git a/server/src/uds/transports/SPICE/SPICETransport.py b/server/src/uds/transports/SPICE/SPICETransport.py index ede57d15..4d84f4c2 100644 --- a/server/src/uds/transports/SPICE/SPICETransport.py +++ b/server/src/uds/transports/SPICE/SPICETransport.py @@ -83,6 +83,6 @@ class SPICETransport(BaseSpiceTransport): }.get(os.OS) if os is None: - return super(SPICETransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m) diff --git a/server/src/uds/transports/SPICE/TSPICETransport.py b/server/src/uds/transports/SPICE/TSPICETransport.py index 9d7b3b85..5119cbd4 100644 --- a/server/src/uds/transports/SPICE/TSPICETransport.py +++ b/server/src/uds/transports/SPICE/TSPICETransport.py @@ -108,6 +108,6 @@ class TSPICETransport(BaseSpiceTransport): }.get(os.OS) if os is None: - return super(TSPICETransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m) diff --git a/server/src/uds/transports/X2GO/TX2GOTransport.py b/server/src/uds/transports/X2GO/TX2GOTransport.py index 1d8ce0d4..b6c3b16f 100644 --- a/server/src/uds/transports/X2GO/TX2GOTransport.py +++ b/server/src/uds/transports/X2GO/TX2GOTransport.py @@ -140,6 +140,6 @@ class TX2GOTransport(BaseX2GOTransport): }.get(m.os) if os is None: - return super(BaseX2GOTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m) diff --git a/server/src/uds/transports/X2GO/X2GOTransport.py b/server/src/uds/transports/X2GO/X2GOTransport.py index 6c223d06..1d21886f 100644 --- a/server/src/uds/transports/X2GO/X2GOTransport.py +++ b/server/src/uds/transports/X2GO/X2GOTransport.py @@ -38,6 +38,7 @@ from uds.core.util import tools from .BaseX2GOTransport import BaseX2GOTransport from . import x2gofile +import six import logging __updated__ = '2017-01-30' @@ -113,6 +114,6 @@ class X2GOTransport(BaseX2GOTransport): }.get(m.os) if os is None: - return super(X2GOTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request) + return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request) return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m) diff --git a/server/src/uds/transports/X2GO/scripts/authorize.py b/server/src/uds/transports/X2GO/scripts/authorize.py index c3be0e8a..a3d38daa 100644 --- a/server/src/uds/transports/X2GO/scripts/authorize.py +++ b/server/src/uds/transports/X2GO/scripts/authorize.py @@ -29,7 +29,7 @@ def updateAuthorizedKeys(user, pubKey): sshFolder = '{}/.ssh'.format(home) if not os.path.exists(sshFolder): try: - os.makedirs(sshFolder, 0700) + os.makedirs(sshFolder, 0o0700) os.chown(sshFolder, uid, -1) except OSError as e: if e.errno != errno.EEXIST: @@ -53,7 +53,7 @@ def updateAuthorizedKeys(user, pubKey): # Ensure access is correct os.chown(authorizedKeys, uid, -1) - os.chmod(authorizedKeys, 0600) + os.chmod(authorizedKeys, 0o0600) # Done diff --git a/server/src/uds/web/errors.py b/server/src/uds/web/errors.py index e9c56fa0..914e977e 100644 --- a/server/src/uds/web/errors.py +++ b/server/src/uds/web/errors.py @@ -33,7 +33,7 @@ from __future__ import unicode_literals from django.utils.translation import ugettext_lazy as _ -from django.shortcuts import render_to_response +from django.shortcuts import render from django.template import RequestContext from django.http import HttpResponseRedirect @@ -148,4 +148,4 @@ def error(request, idError): if code != 0: errStr += ' (code {0:04X})'.format(code) - return render_to_response(theme.template('error.html'), {'errorString': errStr}, context_instance=RequestContext(request)) + return render(request, theme.template('error.html'), {'errorString': errStr}) diff --git a/server/src/uds/web/views/index.py b/server/src/uds/web/views/index.py index c4eec363..1f86ec22 100644 --- a/server/src/uds/web/views/index.py +++ b/server/src/uds/web/views/index.py @@ -75,7 +75,7 @@ def index(request): :param request: http request ''' if request.session.get('ticket') == '1': - return webLogout() + return webLogout(request) # Session data os = request.os @@ -222,7 +222,8 @@ def index(request): logger.debug('Groups: {}'.format(groups)) - response = render(request, + response = render( + request, theme.template('index.html'), { 'groups': groups,