Module: check_mk
Branch: master
Commit: 21f8c5ebcab82051b0e1e20f3d62ae92f71389e9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=21f8c5ebcab820…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 25 11:26:33 2011 +0100
cookie login: Added callable login url and made _origin var work
---
web/htdocs/index.py | 2 +-
web/htdocs/login.py | 23 ++++++++++++++++-------
web/plugins/pages/shipped.py | 1 +
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index c279a3a..5fe58db 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -256,7 +256,7 @@ def handler(req, profiling = True):
req.user = login.check_auth()
if req.user == '':
# After auth check the regular page can be shown
- result = login.page()
+ result = login.login_page()
if type(result) == tuple:
# This is the redirect to the requested page directly after
successful login
req.user = result[0]
diff --git a/web/htdocs/login.py b/web/htdocs/login.py
index c9dfd39..b84bb66 100644
--- a/web/htdocs/login.py
+++ b/web/htdocs/login.py
@@ -108,7 +108,7 @@ def check_auth_cookie():
return username
-def page():
+def login_page():
# handle the sent login form
err = None
if html.var('_login'):
@@ -121,7 +121,9 @@ def page():
if password == '':
raise MKUserError('_password', _('No password given.'))
- origin = html.var('_origin', defaults.url_prefix +
'check_mk/')
+ origin = html.var('_origin')
+ if not origin:
+ origin = defaults.url_prefix + 'check_mk/'
users = load_htpasswd()
if username in users and password_valid(users[username], password):
@@ -137,10 +139,13 @@ def page():
del html.req.vars['_login']
del html.req.vars['_origin']
- return (username, origin)
- # An alternative (and maybe cleaner) would be to use a redirect here:
- #html.set_http_header('Location', html.var('_origin',
defaults.url_prefix + 'check_mk/'))
- #return apache.HTTP_MOVED_TEMPORARILY
+ # Use redirects for URLs or simply execute other handlers for
+ # mulitsite modules
+ if '/' in origin:
+ html.set_http_header('Location', origin)
+ raise apache.SERVER_RETURN, apache.HTTP_MOVED_TEMPORARILY
+ else:
+ return (username, origin)
else:
raise MKUserError(None, _('Invalid credentials.'))
except MKUserError, e:
@@ -154,6 +159,10 @@ def page():
if err:
html.write('<div class=error>%s</div>\n' % e.message)
+ origin = html.var('_origin', '')
+ if not origin and not html.req.myfile == 'login':
+ origin = html.req.uri
+
html.write("<div id=login>")
html.write("<div id=logo></div>")
html.write("<h1>Check_MK Multisite</h2>")
@@ -161,7 +170,7 @@ def page():
html.write("<tr class=form>\n")
html.write("<td>")
html.begin_form("login", method = 'POST', add_transid = False)
- html.hidden_field('_origin', htmllib.attrencode(html.req.uri))
+ html.hidden_field('_origin', htmllib.attrencode(origin))
html.write("<div class=whiteborder>\n")
html.write("<table class=\"form\">\n")
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index e05f656..c861898 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -40,6 +40,7 @@ import login
pagehandlers.update({
"index" : main.page_index,
"main" : main.page_main,
+ "login" : login.login_page,
"logout" : login.logout,
"switch_site" : main.ajax_switch_site,
"edit_views" : views.page_edit_views,