From 5f99877bf71bf01a6e65a4289ff4112df1d620c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Thu, 23 Jan 2014 16:18:47 +0000 Subject: [PATCH] Updated migration 18 (fixed) --- server/src/uds/core/managers/CryptoManager.py | 1 + .../uds/migrations/0018_security_config.py | 21 ++++++++++++++----- server/src/uds/models.py | 4 ++++ server/src/uds/web/forms/LoginForm.py | 2 +- server/src/uds/web/views.py | 5 ++++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/server/src/uds/core/managers/CryptoManager.py b/server/src/uds/core/managers/CryptoManager.py index bf3aa0e3..bf2e10e4 100644 --- a/server/src/uds/core/managers/CryptoManager.py +++ b/server/src/uds/core/managers/CryptoManager.py @@ -71,6 +71,7 @@ class CryptoManager(object): atfork() return self._rsa.decrypt(string.decode(CryptoManager.CODEC)).encode('utf-8') except: + logger.exception('Decripting') return 'decript error' def xor(self, s1, s2): diff --git a/server/src/uds/migrations/0018_security_config.py b/server/src/uds/migrations/0018_security_config.py index 8ebb5c2e..67ab6168 100644 --- a/server/src/uds/migrations/0018_security_config.py +++ b/server/src/uds/migrations/0018_security_config.py @@ -17,15 +17,26 @@ class Migration(DataMigration): # and orm['appname.ModelName'] for models in other applications. if not db.dry_run: # Remove existing secirity values if they exists before "migrating" global ones - orm.Config.objects.filter(section=SECURITY_SECTION,key__in=configKeys).delete() - orm.Config.objects.filter(section=GLOBAL_SECTION,key__in=configKeys).update(section=SECURITY_SECTION) + for k in configKeys: + try: + o = orm.Config.objects.get(section=GLOBAL_SECTION,key=k) + orm.Config.objects.filter(section=SECURITY_SECTION,key=k).delete() + o.section = SECURITY_SECTION + o.save() + except: + pass def backwards(self, orm): "Write your backwards methods here." if not db.dry_run: - # Remove existing global existing values if they exists before "migrating back" security ones - orm.Config.objects.filter(section=GLOBAL_SECTION,key__in=configKeys).delete() - orm.Config.objects.filter(section=SECURITY_SECTION,key__in=configKeys).update(section=GLOBAL_SECTION) + for k in configKeys: + try: + o = orm.Config.objects.get(section=SECURITY_SECTION,key=k) + orm.Config.objects.filter(section=GLOBAL_SECTION,key=k).delete() + o.section = GLOBAL_SECTION + o.save() + except: + pass models = { u'uds.authenticator': { diff --git a/server/src/uds/models.py b/server/src/uds/models.py index da5ad8c7..2b2d7b4c 100644 --- a/server/src/uds/models.py +++ b/server/src/uds/models.py @@ -539,6 +539,10 @@ class Authenticator(models.Model): Raises: ''' + from uds.core.auths import Authenticator as fakeAuth + if self.id is None: + return fakeAuth(self, None, values) + auType = self.getType() env = self.getEnvironment() auth = auType(self, env, values) diff --git a/server/src/uds/web/forms/LoginForm.py b/server/src/uds/web/forms/LoginForm.py index bb221765..a8474abb 100644 --- a/server/src/uds/web/forms/LoginForm.py +++ b/server/src/uds/web/forms/LoginForm.py @@ -68,7 +68,7 @@ class BaseForm(forms.Form): class LoginForm(BaseForm): user = forms.CharField(label=_('Username'), max_length=64, widget=forms.TextInput()) password = forms.CharField(label=_('Password'), widget=forms.PasswordInput(attrs={'title': _('Password')}), required=False) - authenticator = forms.ChoiceField(label=_('Authenticator'), choices = (), widget=CustomSelect()) + authenticator = forms.ChoiceField(label=_('Authenticator'), choices = (), widget=CustomSelect(), required=False) java = forms.CharField(widget = forms.HiddenInput()) standard = forms.CharField(widget = forms.HiddenInput(), required=False) nonStandard = forms.CharField(widget = forms.HiddenInput(), required=False) diff --git a/server/src/uds/web/views.py b/server/src/uds/web/views.py index c1db1f07..ad87c685 100644 --- a/server/src/uds/web/views.py +++ b/server/src/uds/web/views.py @@ -92,7 +92,10 @@ def login(request, smallName=None): if form.is_valid(): java = form.cleaned_data['java'] == 'y' os = OsDetector.getOsFromUA(request.META['HTTP_USER_AGENT']) - authenticator = Authenticator.objects.get(pk=form.cleaned_data['authenticator']) + try: + authenticator = Authenticator.objects.get(pk=form.cleaned_data['authenticator']) + except: + authenticator = Authenticator() userName = form.cleaned_data['user'] cache = Cache('auth')