Module: check_mk
Branch: master
Commit: 4d98b96e3ac0b9b6810d94e8568b184014785a29
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4d98b96e3ac0b9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 19 09:08:09 2018 +0100
Moved gen_id() from lib to utils
Change-Id: I4cf33f39738cf13161eceaae2cd570fb3e7666e1
---
web/htdocs/lib.py | 11 -----------
web/htdocs/notify.py | 5 +++--
web/htdocs/userdb.py | 4 ++--
web/htdocs/utils.py | 13 +++++++++++++
web/htdocs/watolib.py | 4 ++--
web/htdocs/weblib.py | 6 +++---
6 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 1c0a2ff..13d4975 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -30,17 +30,6 @@ from cmk.regex import regex
import cmk.store as store
import cmk.paths
-# Generates a unique id
-def gen_id():
- try:
- return file('/proc/sys/kernel/random/uuid').read().strip()
- except IOError:
- # On platforms where the above file does not exist we try to
- # use the python uuid module which seems to be a good fallback
- # for those systems. Well, if got python < 2.5 you are lost for now.
- import uuid
- return str(uuid.uuid4())
-
# Load all files below share/check_mk/web/plugins/WHAT into a
# specified context (global variables). Also honors the
# local-hierarchy for OMD
diff --git a/web/htdocs/notify.py b/web/htdocs/notify.py
index 61f6199..73d95ea 100644
--- a/web/htdocs/notify.py
+++ b/web/htdocs/notify.py
@@ -24,7 +24,8 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import config, forms, time, lib, userdb
+import utils
+import config, forms, time, userdb
import subprocess
from valuespec import *
import cmk.store as store
@@ -202,7 +203,7 @@ def _validate_msg(msg, varprefix):
raise MKUserError('dest', _('A user with the id
"%s" does not exist.') % user_id)
def _process_notify_message(msg):
- msg['id'] = lib.gen_id()
+ msg['id'] = utils.gen_id()
msg['time'] = time.time()
# construct the list of recipients
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index 51175bb..699c3a4 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -444,7 +444,7 @@ def initialize_session(username):
# Creates a random session id for the user and returns it.
def create_session_id():
- return gen_id()
+ return utils.gen_id()
# Updates the current session of the user and returns the session_id or only
@@ -880,7 +880,7 @@ def rewrite_users():
def create_cmk_automation_user():
- secret = gen_id()
+ secret = utils.gen_id()
users = load_users(lock=True)
users["automation"] = {
diff --git a/web/htdocs/utils.py b/web/htdocs/utils.py
index 4eda962..c9efe6e 100644
--- a/web/htdocs/utils.py
+++ b/web/htdocs/utils.py
@@ -102,6 +102,7 @@ def saveint(x):
# Furthermore we filter out non-printable characters. The byte
# 0x00 for example does not make it through HTTP and the URL.
def get_random_string(size, from_ascii=48, to_ascii=90):
+ """Generate a random string (no cryptographic
safety)"""
secret = ""
urandom = file("/dev/urandom")
while len(secret) < size:
@@ -109,3 +110,15 @@ def get_random_string(size, from_ascii=48, to_ascii=90):
if ord(c) >= from_ascii and ord(c) <= to_ascii:
secret += c
return secret
+
+
+def gen_id():
+ """Generates a unique id"""
+ try:
+ return file('/proc/sys/kernel/random/uuid').read().strip()
+ except IOError:
+ # On platforms where the above file does not exist we try to
+ # use the python uuid module which seems to be a good fallback
+ # for those systems. Well, if got python < 2.5 you are lost for now.
+ import uuid
+ return str(uuid.uuid4())
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 3ea27e9..3b8c7a8 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -4839,7 +4839,7 @@ class ActivateChangesWriter(ActivateChanges):
def _new_change_id(self):
- return gen_id()
+ return utils.gen_id()
def _add_change_to_site(self, site_id, change_id, action_name, text, obj,
@@ -4994,7 +4994,7 @@ class ActivateChangesManager(ActivateChanges):
def _new_activation_id(self):
- return gen_id()
+ return utils.gen_id()
def _get_sites(self, sites):
diff --git a/web/htdocs/weblib.py b/web/htdocs/weblib.py
index 0491c24..53b9f9c 100644
--- a/web/htdocs/weblib.py
+++ b/web/htdocs/weblib.py
@@ -25,7 +25,7 @@
# Boston, MA 02110-1301 USA.
import config
-import lib
+import utils
import re
from gui_exceptions import MKUserError
@@ -79,14 +79,14 @@ def cleanup_old_selections():
# Generates a selection id or uses the given one
def selection_id():
if not html.has_var('selection'):
- sel_id = lib.gen_id()
+ sel_id = utils.gen_id()
html.set_var('selection', sel_id)
return sel_id
else:
sel_id = html.var('selection')
# Avoid illegal file access by introducing .. or /
if not re.match("^[-0-9a-zA-Z]+$", sel_id):
- new_id = lib.gen_id()
+ new_id = utils.gen_id()
html.set_var('selection', new_id)
return new_id
else: