Module: check_mk
Branch: master
Commit: 2ab1edefe3767950e052f2bd76a6b0186a49711f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2ab1edefe37679…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Feb 5 15:16:45 2013 +0100
Added compatibility code to use hashlib.md5() instead of md5.md5(), which is deprecated in
python > 2.5 to prevent warning messages in apache error log
---
ChangeLog | 2 ++
web/htdocs/login.py | 11 ++++++++---
web/htdocs/md5crypt.py | 11 +++++++----
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ded1aa4..8ec9788 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,8 @@
Multisite:
* Added comment painter to notification related views
+ * Added compatibility code to use hashlib.md5() instead of md5.md5(), which
+ is deprecated in python > 2.5 to prevent warning messages in apache error log
BI:
* Use Ajax to delay rendering of invisible parts of the tree (this
diff --git a/web/htdocs/login.py b/web/htdocs/login.py
index d9f843d..8af8b71 100644
--- a/web/htdocs/login.py
+++ b/web/htdocs/login.py
@@ -27,7 +27,12 @@
import defaults, htmllib, config, userdb
from lib import *
from mod_python import apache
-import os, md5, time
+import os, time
+
+try:
+ from hashlib import md5
+except ImportError:
+ from md5 import md5 # deprecated with python 2.5
def site_cookie_name(site_id = None):
if not site_id:
@@ -54,7 +59,7 @@ def load_secret():
# Create new secret when this installation has no secret
if secret == '':
- secret = md5.md5(str(time.time())).hexdigest()
+ secret = md5(str(time.time())).hexdigest()
file(secret_path, 'w').write(secret + "\n")
return secret
@@ -69,7 +74,7 @@ def load_serial(user_id):
# Generates the hash to be added into the cookie value
def generate_hash(username, now, serial):
secret = load_secret()
- return md5.md5(username + now + str(serial) + secret).hexdigest()
+ return md5(username + now + str(serial) + secret).hexdigest()
def del_auth_cookie():
name = site_cookie_name()
diff --git a/web/htdocs/md5crypt.py b/web/htdocs/md5crypt.py
index f83faf5..cd7a4a6 100644
--- a/web/htdocs/md5crypt.py
+++ b/web/htdocs/md5crypt.py
@@ -35,15 +35,18 @@
# This port adds no further stipulations. I forfeit any copyright interest.
-import md5
+try:
+ from hashlib import md5
+except ImportError:
+ from md5 import md5 # deprecated with python 2.5
def md5crypt(password, salt, magic='$1$'):
# /* The password first, since that is what is most unknown */ /* Then our magic
string */ /* Then the raw salt */
- m = md5.new()
+ m = md5()
m.update(password + magic + salt)
# /* Then just as many characters of the MD5(pw,salt,pw) */
- mixin = md5.md5(password + salt + password).digest()
+ mixin = md5(password + salt + password).digest()
for i in range(0, len(password)):
m.update(mixin[i % 16])
@@ -61,7 +64,7 @@ def md5crypt(password, salt, magic='$1$'):
# /* and now, just to make sure things don't run too fast */
for i in range(1000):
- m2 = md5.md5()
+ m2 = md5()
if i & 1:
m2.update(password)
else: