| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This Source Code is subject to the terms of the Mozilla Public License | 3 # This Source Code is subject to the terms of the Mozilla Public License |
| 4 # version 2.0 (the "License"). You can obtain a copy of the License at | 4 # version 2.0 (the "License"). You can obtain a copy of the License at |
| 5 # http://mozilla.org/MPL/2.0/. | 5 # http://mozilla.org/MPL/2.0/. |
| 6 | 6 |
| 7 import base64 | |
| 8 from sitescripts.utils import get_config | |
| 9 | |
| 7 handlers = {} | 10 handlers = {} |
| 11 authenticated_users = {} | |
| 8 | 12 |
| 9 def url_handler(url): | 13 def url_handler(url): |
| 10 def decorator(func): | 14 def decorator(func): |
| 11 registerUrlHandler(url, func) | 15 registerUrlHandler(url, func) |
| 12 return func | 16 return func |
| 13 return decorator | 17 return decorator |
| 14 | 18 |
| 15 def registerUrlHandler(url, func): | 19 def registerUrlHandler(url, func): |
| 16 if url in handlers: | 20 if url in handlers: |
| 17 raise Exception('A handler for url %s is already registered' % url) | 21 raise Exception('A handler for url %s is already registered' % url) |
| 18 handlers[url] = func | 22 handlers[url] = func |
| 19 | 23 |
| 24 def basic_auth(f): | |
| 25 return lambda environ, start_response: authenticate(f, environ, start_response ) | |
| 26 | |
| 27 def authenticate(f, environ, start_response): | |
| 28 if "HTTP_AUTHORIZATION" in environ: | |
| 29 auth = environ["HTTP_AUTHORIZATION"].split() | |
| 30 if len(auth) == 2: | |
| 31 if auth[0].lower() == "basic": | |
| 32 username, password = base64.b64decode(auth[1]).split(":") | |
| 33 expected_username = get_config().get("DEFAULT", "basic_auth_username") | |
|
Wladimir Palant
2012/09/14 17:24:18
I don't think that these settings belong into the
Felix Dahlke
2012/09/26 15:20:30
Done.
| |
| 34 expected_password = get_config().get("DEFAULT", "basic_auth_password") | |
| 35 if username == expected_username and password == expected_password: | |
| 36 return f(environ, start_response) | |
| 37 | |
| 38 realm = get_config().get("DEFAULT", "basic_auth_realm") | |
| 39 start_response("401 UNAUTHORIZED", | |
| 40 [("WWW-Authenticate", 'Basic realm="%s"' % realm)]) | |
| 41 return "" | |
| 42 | |
| 20 import openid.web.server | 43 import openid.web.server |
| 21 import subscriptions.web.fallback | 44 import subscriptions.web.fallback |
| 22 import reports.web.submitReport | 45 import reports.web.submitReport |
| 23 import reports.web.updateReport | 46 import reports.web.updateReport |
| 24 import reports.web.showDigest | 47 import reports.web.showDigest |
| 25 import extensions.web.translationCheck | 48 import extensions.web.translationCheck |
| 26 import tasks.web.tasks | 49 import tasks.web.tasks |
| 27 import formmail.web.formmail | 50 import formmail.web.formmail |
| 28 import crawler.web.crawler | 51 import crawler.web.crawler |
| OLD | NEW |