[checkmk-commits] Check_MK Git: check_mk: login: storing the users serial in a dedicated now (to make it easily readable by external auth checkers like in pnp/nagvis)

git version control git at mathias-kettner.de
Wed Nov 21 14:35:06 CET 2012


Module: check_mk
Branch: master
Commit: 529371c3e1fcdd684f568293708132b1f604aee5
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=529371c3e1fcdd684f568293708132b1f604aee5

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Thu Nov 15 11:25:33 2012 +0100

login: storing the users serial in a dedicated now (to make it easily readable by external auth checkers like in pnp/nagvis)

---

 web/htdocs/wato.py |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 2de411c..51851bc 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8382,12 +8382,14 @@ def load_users():
                     result[id] = new_user
             # Other unknown entries will silently be dropped. Sorry...
 
-    # Now read the automation secrets and add them to existing
-    # users or create new users automatically
+    # Now read the user specific files
     dir = defaults.var_dir + "/web/"
     for d in os.listdir(dir):
         if d[0] != '.':
             id = d
+
+            # read automation secrets and add them to existing
+            # users or create new users automatically
             secret_file = dir + d + "/automation.secret"
             if os.path.exists(secret_file):
                 secret = file(secret_file).read().strip()
@@ -8399,15 +8401,18 @@ def load_users():
                         "automation_secret" : secret,
                     }
 
+            # read the users serials, only process for existing users
+            if id in result:
+                serial_file = dir + d + '/serial.mk'
+                if os.path.exists(serial_file):
+                    result[id]['serial'] = saveint(file(serial_file).read().strip())
+
     return result
 
 def split_dict(d, keylist, positive):
     return dict([(k,v) for (k,v) in d.items() if (k in keylist) == positive])
 
 def save_users(profiles):
-    # TODO: delete var/check_mk/web/$USER of non-existing users. Do we
-    # need to remove other references as well?
-
     custom_values = [ name for (name, vs) in user_attributes ]
 
     # Keys not to put into contact definitions for Check_MK
@@ -8428,7 +8433,6 @@ def save_users(profiles):
         "automation_secret",
         "alias",
         "language",
-        "serial",
         "connector",
     ] + custom_values
 
@@ -8460,16 +8464,22 @@ def save_users(profiles):
     # Execute user connector save hooks
     userdb.hook_save(profiles)
 
-    # Write authentication secret for local processes
+    # Write user specific files
     for id, user in profiles.items():
-        auth_dir = defaults.var_dir + "/web/" + id
-        auth_file = auth_dir + "/automation.secret"
-        make_nagios_directory(auth_dir)
+        user_dir = defaults.var_dir + "/web/" + id
+        make_nagios_directory(user_dir)
+
+        # authentication secret for local processes
+        auth_file = user_dir + "/automation.secret"
         if "automation_secret" in user:
             create_user_file(auth_file, "w").write("%s\n" % user["automation_secret"])
         elif os.path.exists(auth_file):
             os.remove(auth_file)
 
+        # Write out the users serial
+        serial_file = user_dir + '/serial.mk'
+        create_user_file(serial_file, 'w').write('%d\n' % user.get('serial', 0))
+
     # Remove settings directories of non-existant users
     dir = defaults.var_dir + "/web"
     for e in os.listdir(dir):



More information about the checkmk-commits mailing list