Merge branch 'asa-db-mods'
authorAlex Dehnert <adehnert@mit.edu>
Mon, 6 Jun 2011 06:34:19 +0000 (02:34 -0400)
committerAlex Dehnert <adehnert@mit.edu>
Mon, 6 Jun 2011 06:34:19 +0000 (02:34 -0400)
1  2 
django/mit/__init__.py

index 1a19dc8aa42fe4fd599863ea45b068cd2273844b,8f785ae9b8b6331debfaacc5edf9ea92b115bc5e..2e6062343fc64b69aece64d7231696d247f48f82
@@@ -1,18 -1,15 +1,22 @@@
 +import subprocess
 +import ldap
 +import ldap.filter
 +
  from django.contrib.auth.middleware import RemoteUserMiddleware
  from django.contrib.auth.backends import RemoteUserBackend
+ from django.contrib.auth.views import login
+ from django.contrib.auth import REDIRECT_FIELD_NAME
+ from django.http import HttpResponseRedirect
  from django.contrib import auth
  from django.core.exceptions import ObjectDoesNotExist
+ import settings
  
  def zephyr(msg, clas='remit', instance='log', rcpt='adehnert',):
 -    import os
 -    os.system("zwrite -d -c '%s' -i '%s' '%s' -m '%s'" % (clas, instance, rcpt, msg, ))
 +    proc = subprocess.Popen(
 +        ['zwrite', '-d', '-n', '-c', clas, '-i', instance, rcpt, ],
 +        stdin=subprocess.PIPE, stdout=subprocess.PIPE
 +    )
 +    proc.communicate(msg)
  
  class ScriptsRemoteUserMiddleware(RemoteUserMiddleware):
      header = 'SSL_CLIENT_S_DN_Email'
@@@ -48,5 -43,27 +52,28 @@@ class ScriptsRemoteUserBackend(RemoteUs
              user.groups.add(auth.models.Group.objects.get(name='autocreated'))
          except ObjectDoesNotExist:
              print "Failed to retrieve autocreated group"
 +        user.save()
          return user
+ def scripts_login(request, **kwargs):
+     host = request.META['HTTP_HOST'].split(':')[0]
+     if host == 'localhost':
+         return login(request, **kwargs)
+     elif request.META['SERVER_PORT'] == '444':
+         if request.user.is_authenticated():
+             # They're already authenticated --- go ahead and redirect
+             if 'redirect_field_name' in kwargs:
+                 redirect_field_name = kwargs['redirect_field_names']
+             else:
+                 from django.contrib.auth import REDIRECT_FIELD_NAME
+                 redirect_field_name = REDIRECT_FIELD_NAME
+             redirect_to = request.REQUEST.get(redirect_field_name, '')
+             if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
+                 redirect_to = settings.LOGIN_REDIRECT_URL
+             return HttpResponseRedirect(redirect_to)
+         else:
+             return login(request, **kwargs)
+     else:
+         # Move to port 444
+         redirect_to = "https://%s:444%s" % (host, request.META['REQUEST_URI'], )
+         return HttpResponseRedirect(redirect_to)