From ed0e858e30b042e9b7043af22480ba62b8d265ee Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Fri, 11 Mar 2016 13:26:54 +0100 Subject: [PATCH] Rev989, Save users file on newsfeed follow, Local mode in Multiuser plugin to disable restrication and save users data to disk --- plugins/Newsfeed/NewsfeedPlugin.py | 1 + plugins/disabled-Multiuser/MultiuserPlugin.py | 71 ++++++++++--------- plugins/disabled-Multiuser/UserPlugin.py | 35 +++++++++ src/Config.py | 2 +- 4 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 plugins/disabled-Multiuser/UserPlugin.py diff --git a/plugins/Newsfeed/NewsfeedPlugin.py b/plugins/Newsfeed/NewsfeedPlugin.py index 86c75089..f4d42244 100644 --- a/plugins/Newsfeed/NewsfeedPlugin.py +++ b/plugins/Newsfeed/NewsfeedPlugin.py @@ -5,6 +5,7 @@ import re, time class UiWebsocketPlugin(object): def actionFeedFollow(self, to, feeds): self.user.setFeedFollow(self.site.address, feeds) + self.user.save() self.response(to, "ok") def actionFeedListFollow(self, to): diff --git a/plugins/disabled-Multiuser/MultiuserPlugin.py b/plugins/disabled-Multiuser/MultiuserPlugin.py index 263ed229..4698b159 100644 --- a/plugins/disabled-Multiuser/MultiuserPlugin.py +++ b/plugins/disabled-Multiuser/MultiuserPlugin.py @@ -1,6 +1,10 @@ import re import sys + +from Config import config from Plugin import PluginManager +from Crypt import CryptBitcoin +import UserPlugin @PluginManager.registerTo("UiRequest") @@ -93,32 +97,6 @@ class UiRequestPlugin(object): return user -@PluginManager.registerTo("UserManager") -class UserManagerPlugin(object): - # In multiuser mode do not load the users - def load(self): - if not self.users: - self.users = {} - return self.users - - # Find user by master address - # Return: User or None - def get(self, master_address=None): - users = self.list() - if master_address in users: - user = users[master_address] - else: - user = None - return user - - -@PluginManager.registerTo("User") -class UserPlugin(object): - # In multiuser mode users data only exits in memory, dont write to data/user.json - def save(self): - return False - - @PluginManager.registerTo("UiWebsocket") class UiWebsocketPlugin(object): # Let the page know we running in multiuser mode @@ -148,7 +126,8 @@ class UiWebsocketPlugin(object): # Delete from user_manager user_manager = sys.modules["User.UserManager"].user_manager if self.user.master_address in user_manager.users: - del user_manager.users[self.user.master_address] + if not config.multiuser_local: + del user_manager.users[self.user.master_address] self.response(to, "Successful logout") else: self.response(to, "User not found") @@ -160,7 +139,9 @@ class UiWebsocketPlugin(object): # Login form submit def responseUserLogin(self, master_seed): user_manager = sys.modules["User.UserManager"].user_manager - user = user_manager.create(master_seed=master_seed) + user = user_manager.get(CryptBitcoin.privatekeyToAddress(master_seed)) + if not user: + user = user_manager.create(master_seed=master_seed) if user.master_address: message = "Successfull login, reloading page..." message += "" % user.master_address @@ -172,16 +153,40 @@ class UiWebsocketPlugin(object): # Disable not Multiuser safe functions def actionSiteDelete(self, to, *args, **kwargs): - self.cmd("notification", ["info", "This function is disabled on this proxy"]) + if not config.multiuser_local: + self.cmd("notification", ["info", "This function is disabled on this proxy"]) + else: + return super(UiWebsocketPlugin, self).actionSiteDelete(to, *args, **kwargs) def actionConfigSet(self, to, *args, **kwargs): - self.cmd("notification", ["info", "This function is disabled on this proxy"]) + if not config.multiuser_local: + self.cmd("notification", ["info", "This function is disabled on this proxy"]) + else: + return super(UiWebsocketPlugin, self).actionConfigSet(to, *args, **kwargs) def actionServerShutdown(self, to, *args, **kwargs): - self.cmd("notification", ["info", "This function is disabled on this proxy"]) + if not config.multiuser_local: + self.cmd("notification", ["info", "This function is disabled on this proxy"]) + else: + return super(UiWebsocketPlugin, self).actionServerShutdown(to, *args, **kwargs) def actionServerUpdate(self, to, *args, **kwargs): - self.cmd("notification", ["info", "This function is disabled on this proxy"]) + if not config.multiuser_local: + self.cmd("notification", ["info", "This function is disabled on this proxy"]) + else: + return super(UiWebsocketPlugin, self).actionServerUpdate(to, *args, **kwargs) def actionSiteClone(self, to, *args, **kwargs): - self.cmd("notification", ["info", "This function is disabled on this proxy"]) + if not config.multiuser_local: + self.cmd("notification", ["info", "This function is disabled on this proxy"]) + else: + return super(UiWebsocketPlugin, self).actionSiteClone(to, *args, **kwargs) + + +@PluginManager.registerTo("ConfigPlugin") +class ConfigPlugin(object): + def createArguments(self): + group = self.parser.add_argument_group("Multiuser plugin") + group.add_argument('--multiuser_local', help="Enable unsafe Ui functions and write users to disk", action='store_true') + + return super(ConfigPlugin, self).createArguments() diff --git a/plugins/disabled-Multiuser/UserPlugin.py b/plugins/disabled-Multiuser/UserPlugin.py new file mode 100644 index 00000000..3c9ebae8 --- /dev/null +++ b/plugins/disabled-Multiuser/UserPlugin.py @@ -0,0 +1,35 @@ +from Config import config +from Plugin import PluginManager + +allow_reload = False + +@PluginManager.registerTo("UserManager") +class UserManagerPlugin(object): + def load(self): + if not config.multiuser_local: + # In multiuser mode do not load the users + if not self.users: + self.users = {} + return self.users + else: + return super(UserManagerPlugin, self).load() + + # Find user by master address + # Return: User or None + def get(self, master_address=None): + users = self.list() + if master_address in users: + user = users[master_address] + else: + user = None + return user + + +@PluginManager.registerTo("User") +class UserPlugin(object): + # In multiuser mode users data only exits in memory, dont write to data/user.json + def save(self): + if not config.multiuser_local: + return False + else: + return super(UserPlugin, self).save() diff --git a/src/Config.py b/src/Config.py index bb1c9342..9eacdb63 100644 --- a/src/Config.py +++ b/src/Config.py @@ -8,7 +8,7 @@ class Config(object): def __init__(self, argv): self.version = "0.3.6" - self.rev = 986 + self.rev = 989 self.argv = argv self.action = None self.config_file = "zeronet.conf"