Weak password warning (#938)
* Weak password warning * Update UiWebsocket.py * Don't implement print with an O(n^2) iteration * Rename method * Fix logging, uncaught exception in addNotes and pushes a notification when UI server is bound to the whole Internet. * Remove memo comments. Remove terminal hue.
This commit is contained in:
parent
e6680b4f60
commit
35a18bd0b2
2 changed files with 95 additions and 48 deletions
|
@ -11,6 +11,14 @@ if "sessions" not in locals().keys(): # To keep sessions between module reloads
|
|||
sessions = {}
|
||||
|
||||
|
||||
def showPasswordAdvice(password):
|
||||
error_msgs = []
|
||||
if not password or not isinstance(password, (str, unicode)):
|
||||
error_msgs.append("You have enabled <b>UiPassword</b> plugin, but you forgot to set a password!")
|
||||
elif len(password) < 8:
|
||||
error_msgs.append("You are using a very short UI password!")
|
||||
return error_msgs
|
||||
|
||||
@PluginManager.registerTo("UiRequest")
|
||||
class UiRequestPlugin(object):
|
||||
sessions = sessions
|
||||
|
@ -57,13 +65,10 @@ class UiRequestPlugin(object):
|
|||
yield template
|
||||
|
||||
def checkPassword(self, password):
|
||||
if password == config.ui_password:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return password == config.ui_password
|
||||
|
||||
def randomString(self, chars):
|
||||
return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(chars))
|
||||
def randomString(self, nchars):
|
||||
return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(nchars))
|
||||
|
||||
@classmethod
|
||||
def cleanup(cls):
|
||||
|
@ -97,6 +102,7 @@ class UiRequestPlugin(object):
|
|||
yield "Error: Invalid session id"
|
||||
|
||||
|
||||
|
||||
@PluginManager.registerTo("ConfigPlugin")
|
||||
class ConfigPlugin(object):
|
||||
def createArguments(self):
|
||||
|
@ -106,6 +112,7 @@ class ConfigPlugin(object):
|
|||
return super(ConfigPlugin, self).createArguments()
|
||||
|
||||
|
||||
from Translate import translate as lang
|
||||
@PluginManager.registerTo("UiWebsocket")
|
||||
class UiWebsocketPlugin(object):
|
||||
def actionUiLogout(self, to):
|
||||
|
@ -116,3 +123,10 @@ class UiWebsocketPlugin(object):
|
|||
session_id = self.request.getCookies().get("session_id", "")
|
||||
message = "<script>document.location.href = '/Logout?session_id=%s'</script>" % session_id
|
||||
self.cmd("notification", ["done", message])
|
||||
|
||||
def addHomepageNotifications(self):
|
||||
error_msgs = showPasswordAdvice(config.ui_password)
|
||||
for msg in error_msgs:
|
||||
self.site.notifications.append(["error", lang[msg]])
|
||||
|
||||
return super(UiWebsocketPlugin, self).addHomepageNotifications()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue