Module: check_mk
Branch: master
Commit: 816dfab3acb841a3f3c2c564ba667538efbeb7f7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=816dfab3acb841…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Nov 25 17:02:36 2015 +0100
New function for logging in a virtual super user
This is needed for pages without authentication that do
Livestatus queries
---
web/htdocs/config.py | 28 ++++++++++++++++++++++++++++
web/htdocs/livestatus.py | 2 +-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 0ed491c..3a399d1 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -276,6 +276,34 @@ def login(u):
# load current on/off-switching states of sites
read_site_config()
+# Login a user that has all permissions. This is needed for making
+# Livestatus queries from unauthentiated page handlers
+def login_super_user():
+ global user_id
+ user_id = None
+
+ global user_role_ids
+ user_role_ids = []
+
+ global user_baserole_ids
+ user_baserole_ids = [ "admin" ]
+
+ global user_baserole_id
+ user_baserole_id = "admin"
+
+ # Prepare user object
+ global user, user_alias
+ user = { "roles" : "admin" }
+ user_alias = "Superuser for unauthenticated pages"
+
+ # Prepare cache of already computed permissions
+ global user_permissions
+ user_permissions = {}
+
+ # All sites are enabled
+ global user_siteconf
+ user_siteconf = {}
+
def set_user_confdir(user_id):
global user_confdir
user_confdir = config_dir + "/" + user_id.encode("utf-8")
diff --git a/web/htdocs/livestatus.py b/web/htdocs/livestatus.py
index fb6865c..e5c75ae 100644
--- a/web/htdocs/livestatus.py
+++ b/web/htdocs/livestatus.py
@@ -386,7 +386,7 @@ class SingleSiteConnection(BaseConnection, Helpers):
def set_auth_user(self, domain, user):
if user:
self.auth_users[domain] = user
- else:
+ elif domain in self.auth_users:
del self.auth_users[domain]
# Switch future request to new authorization domain