In multiuser mode allow unrestricted access for users defined in users.json

This commit is contained in:
shortcutme 2017-02-11 18:23:52 +01:00
parent edfe760227
commit bb57120872
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -1,11 +1,16 @@
import re import re
import sys import sys
import json
from Config import config from Config import config
from Plugin import PluginManager from Plugin import PluginManager
from Crypt import CryptBitcoin from Crypt import CryptBitcoin
import UserPlugin import UserPlugin
try:
local_master_addresses = set(json.load(open("%s/users.json" % config.data_dir)).keys()) # Users in users.json
except Exception, err:
local_master_addresses = set()
@PluginManager.registerTo("UiRequest") @PluginManager.registerTo("UiRequest")
class UiRequestPlugin(object): class UiRequestPlugin(object):
@ -20,6 +25,7 @@ class UiRequestPlugin(object):
match = re.match("/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path) match = re.match("/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
if not match: if not match:
return False return False
inner_path = match.group("inner_path").lstrip("/") inner_path = match.group("inner_path").lstrip("/")
html_request = "." not in inner_path or inner_path.endswith(".html") # Only inject html to html requests html_request = "." not in inner_path or inner_path.endswith(".html") # Only inject html to html requests
@ -84,12 +90,17 @@ class UiRequestPlugin(object):
<!-- Multiser plugin --> <!-- Multiser plugin -->
<script> <script>
setTimeout(function() { setTimeout(function() {
wrapper.notifications.add("login", "done", "Hello again!<br><small>You have been logged in successfully</small>", 5000) wrapper.notifications.add("login", "done", "{message}<br><small>You have been logged in successfully</small>", 5000)
}, 1000) }, 1000)
</script> </script>
</body> </body>
</html> </html>
""".replace("\t", "") """.replace("\t", "")
if user.master_address in local_master_addresses:
message = "Hello master!"
else:
message = "Hello again!"
inject_html = inject_html.replace("{message}", message)
return iter([re.sub("</body>\s*</html>\s*$", inject_html, back)]) # Replace the </body></html> tags with the injection return iter([re.sub("</body>\s*</html>\s*$", inject_html, back)]) # Replace the </body></html> tags with the injection
else: # No injection necessary else: # No injection necessary