Module: check_mk
Branch: master
Commit: 39d7d7f0d59e3746bc37fb0b251ac3b784f0006b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=39d7d7f0d59e37…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 9 13:31:44 2013 +0200
First steps to save the time of the last user activity (disabled by default)
---
web/htdocs/images/icon_offline.png | Bin 0 -> 2844 bytes
web/htdocs/images/icon_online.png | Bin 0 -> 4152 bytes
web/htdocs/userdb.py | 11 +++++++++++
web/htdocs/wato.py | 11 +++++++++++
web/plugins/config/builtin.py | 14 ++++++++------
web/plugins/wato/check_mk_configuration.py | 4 ++--
6 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/web/htdocs/images/icon_offline.png b/web/htdocs/images/icon_offline.png
new file mode 100644
index 0000000..0e22744
Binary files /dev/null and b/web/htdocs/images/icon_offline.png differ
diff --git a/web/htdocs/images/icon_online.png b/web/htdocs/images/icon_online.png
new file mode 100644
index 0000000..5707ba9
Binary files /dev/null and b/web/htdocs/images/icon_online.png differ
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index 0a1db01..965dbc7 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -123,8 +123,17 @@ def user_locked(username):
def on_succeeded_login(username):
users = load_users(lock = True)
+ changed = False
+
if users[username].get('num_failed', 0) != 0:
users[username]["num_failed"] = 0
+ changed = True
+
+ if config.save_user_access_times:
+ users[username]['last_seen'] = time.time()
+ changed = True
+
+ if changed:
save_users(users)
def on_failed_login(username):
@@ -314,6 +323,7 @@ def save_users(profiles):
"serial",
"connector",
"num_failed",
+ "last_seen",
] + custom_values
# Keys to put into multisite configuration
@@ -324,6 +334,7 @@ def save_users(profiles):
"alias",
"language",
"connector",
+ "last_seen",
] + custom_values
# Remove multisite keys in contacts.
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index e914555..14ee24e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8181,6 +8181,7 @@ def mode_users(phase):
entries.sort(cmp = lambda a, b: cmp(a[1].get("alias", a[0]).lower(),
b[1].get("alias", b[0]).lower()))
table.begin("users", None, empty_text = _("There are not defined any
users yet."))
+ online_threshold = time.time() - config.user_online_maxage
for id, user in entries:
table.row()
@@ -8201,6 +8202,16 @@ def mode_users(phase):
# ID
table.cell(_("ID"), id)
+ # Online/Offline
+ if config.save_user_access_times:
+ if user.get('last_seen', 0) >= online_threshold:
+ title = _('Online')
+ img_txt = 'on'
+ else:
+ title = _('Offline')
+ img_txt = 'off'
+ table.cell(_("Act."), '<img class=icon title="%s"
src="images/icon_%sline.png" />' % (title, img_txt))
+
# Connector
if connector:
table.cell(_("Connector"), connector['short_title'])
diff --git a/web/plugins/config/builtin.py b/web/plugins/config/builtin.py
index 76bee9a..7c836f6 100644
--- a/web/plugins/config/builtin.py
+++ b/web/plugins/config/builtin.py
@@ -33,12 +33,14 @@
roles = {} # User supplied roles
# define default values for all settings
-debug = False
-profile = False
-users = []
-admin_users = []
-guest_users = []
-default_user_role = "user"
+debug = False
+profile = False
+users = []
+admin_users = []
+guest_users = []
+default_user_role = "user"
+save_user_access_times = False
+user_online_maxage = 10 # seconds
# New style, used by WATO
multisite_users = {}
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 11a9a2b..e6dbab2 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -776,11 +776,11 @@ register_configvar(group,
register_configvar(group,
"save_user_access_times",
Checkbox(
- title = _("Store access times of users"),
+ title = _("Save last access times of users"),
label = _("Save the time of the latest user activity"),
help = _("When enabled, the time of the last access is stored for each user.
The last "
"activity is shown on the users page."),
- default_value = True
+ default_value = False
),
domain = "multisite"
)