Py3 compatibility of UiPassword plugin

This commit is contained in:
shortcutme 2019-03-16 02:23:46 +01:00
parent 40569eee2e
commit 2737425242
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -4,8 +4,10 @@ import time
import json import json
import re import re
from Config import config from Config import config
from Plugin import PluginManager from Plugin import PluginManager
from util import helper
if "sessions" not in locals().keys(): # To keep sessions between module reloads if "sessions" not in locals().keys(): # To keep sessions between module reloads
sessions = {} sessions = {}
@ -13,7 +15,7 @@ if "sessions" not in locals().keys(): # To keep sessions between module reloads
def showPasswordAdvice(password): def showPasswordAdvice(password):
error_msgs = [] error_msgs = []
if not password or not isinstance(password, (str, unicode)): if not password or not isinstance(password, str):
error_msgs.append("You have enabled <b>UiPassword</b> plugin, but you forgot to set a password!") error_msgs.append("You have enabled <b>UiPassword</b> plugin, but you forgot to set a password!")
elif len(password) < 8: elif len(password) < 8:
error_msgs.append("You are using a very short UI password!") error_msgs.append("You are using a very short UI password!")
@ -41,6 +43,7 @@ class UiRequestPlugin(object):
return super(UiRequestPlugin, self).route(path) return super(UiRequestPlugin, self).route(path)
# Action: Login # Action: Login
@helper.encodeResponse
def actionLogin(self): def actionLogin(self):
template = open("plugins/UiPassword/login.html").read() template = open("plugins/UiPassword/login.html").read()
self.sendHeader() self.sendHeader()
@ -76,7 +79,7 @@ class UiRequestPlugin(object):
@classmethod @classmethod
def cleanup(cls): def cleanup(cls):
cls.last_cleanup = time.time() cls.last_cleanup = time.time()
for session_id, session in cls.sessions.items(): for session_id, session in list(cls.sessions.items()):
if session["keep"] and time.time() - session["added"] > 60 * 60 * 24 * 60: # Max 60days for keep sessions if session["keep"] and time.time() - session["added"] > 60 * 60 * 24 * 60: # Max 60days for keep sessions
del(cls.sessions[session_id]) del(cls.sessions[session_id])
elif not session["keep"] and time.time() - session["added"] > 60 * 60 * 24: # Max 24h for non-keep sessions elif not session["keep"] and time.time() - session["added"] > 60 * 60 * 24: # Max 24h for non-keep sessions