From e8f83590eeac2ae156d0f5f9a409b32f40bff2f1 Mon Sep 17 00:00:00 2001
From: caryoscelus <caryoscelus@gmx.com>
Date: Tue, 18 Jul 2023 14:38:17 +0000
Subject: [PATCH 1/2] disable plugins in data dir

---
 src/Plugin/PluginManager.py | 33 ++-------------------------------
 1 file changed, 2 insertions(+), 31 deletions(-)

diff --git a/src/Plugin/PluginManager.py b/src/Plugin/PluginManager.py
index dbafa98f..5855c842 100644
--- a/src/Plugin/PluginManager.py
+++ b/src/Plugin/PluginManager.py
@@ -17,7 +17,6 @@ class PluginManager:
     def __init__(self):
         self.log = logging.getLogger("PluginManager")
         self.path_plugins = os.path.abspath(os.path.dirname(plugins.__file__))
-        self.path_installed_plugins = config.data_dir + "/__plugins__"
         self.plugins = defaultdict(list)  # Registered plugins (key: class name, value: list of plugins for class)
         self.subclass_order = {}  # Record the load order of the plugins, to keep it after reload
         self.pluggable = {}
@@ -93,34 +92,6 @@ class PluginManager:
             plugin["loaded"] = plugin_name in self.plugin_names
             plugins.append(plugin)
 
-        plugins += self.listInstalledPlugins(list_disabled)
-        return plugins
-
-    def listInstalledPlugins(self, list_disabled=False):
-        plugins = []
-
-        for address, site_plugins in sorted(self.config.items()):
-            if address == "builtin":
-                continue
-            for plugin_inner_path, plugin_config in sorted(site_plugins.items()):
-                is_enabled = plugin_config.get("enabled", False)
-                if not is_enabled and not list_disabled:
-                    continue
-                plugin_name = os.path.basename(plugin_inner_path)
-
-                dir_path = "%s/%s/%s" % (self.path_installed_plugins, address, plugin_inner_path)
-
-                plugin = {}
-                plugin["source"] = address
-                plugin["name"] = plugin_name
-                plugin["dir_name"] = plugin_name
-                plugin["dir_path"] = dir_path
-                plugin["inner_path"] = plugin_inner_path
-                plugin["enabled"] = is_enabled
-                plugin["rev"] = plugin_config.get("rev", 0)
-                plugin["loaded"] = plugin_name in self.plugin_names
-                plugins.append(plugin)
-
         return plugins
 
     # Load all plugin
@@ -156,10 +127,10 @@ class PluginManager:
         for module_name, module in list(sys.modules.items()):
             if not module or not getattr(module, "__file__", None):
                 continue
-            if self.path_plugins not in module.__file__ and self.path_installed_plugins not in module.__file__:
+            if self.path_plugins not in module.__file__:
                 continue
 
-            if "allow_reload" in dir(module) and not module.allow_reload:  # Reload disabled
+            if not getattr(module, 'allow_reload', True):  # Reload disabled
                 # Re-add non-reloadable plugins
                 for class_name, classes in self.plugins_before.items():
                     for c in classes:

From 07b7c5824fa57fff95d35320878cb62b4c6bc234 Mon Sep 17 00:00:00 2001
From: caryoscelus <caryoscelus@gmx.com>
Date: Fri, 21 Jul 2023 11:33:46 +0000
Subject: [PATCH 2/2] remove third-party plugin management

refs #216
---
 .../UiPluginManager/UiPluginManagerPlugin.py  | 93 -------------------
 1 file changed, 93 deletions(-)

diff --git a/plugins/UiPluginManager/UiPluginManagerPlugin.py b/plugins/UiPluginManager/UiPluginManagerPlugin.py
index 1ab80f53..0bfa8ec5 100644
--- a/plugins/UiPluginManager/UiPluginManagerPlugin.py
+++ b/plugins/UiPluginManager/UiPluginManagerPlugin.py
@@ -126,96 +126,3 @@ class UiWebsocketPlugin(object):
         plugin_manager.saveConfig()
 
         return "ok"
-
-    def pluginAction(self, action, address, inner_path):
-        site = self.server.sites.get(address)
-        plugin_manager = PluginManager.plugin_manager
-
-        # Install/update path should exists
-        if action in ("add", "update", "add_request"):
-            if not site:
-                raise Exception("Site not found")
-
-            if not site.storage.isDir(inner_path):
-                raise Exception("Directory not found on the site")
-
-            try:
-                plugin_info = site.storage.loadJson(inner_path + "/plugin_info.json")
-                plugin_data = (plugin_info["rev"], plugin_info["description"], plugin_info["name"])
-            except Exception as err:
-                raise Exception("Invalid plugin_info.json: %s" % Debug.formatExceptionMessage(err))
-
-            source_path = site.storage.getPath(inner_path)
-
-        target_path = plugin_manager.path_installed_plugins + "/" + address + "/" + inner_path
-        plugin_config = plugin_manager.config.setdefault(site.address, {}).setdefault(inner_path, {})
-
-        # Make sure plugin (not)installed
-        if action in ("add", "add_request") and os.path.isdir(target_path):
-            raise Exception("Plugin already installed")
-
-        if action in ("update", "remove") and not os.path.isdir(target_path):
-            raise Exception("Plugin not installed")
-
-        # Do actions
-        if action == "add":
-            shutil.copytree(source_path, target_path)
-
-            plugin_config["date_added"] = int(time.time())
-            plugin_config["rev"] = plugin_info["rev"]
-            plugin_config["enabled"] = True
-
-        if action == "update":
-            shutil.rmtree(target_path)
-
-            shutil.copytree(source_path, target_path)
-
-            plugin_config["rev"] = plugin_info["rev"]
-            plugin_config["date_updated"] = time.time()
-
-        if action == "remove":
-            del plugin_manager.config[address][inner_path]
-            shutil.rmtree(target_path)
-
-    def doPluginAdd(self, to, inner_path, res):
-        if not res:
-            return None
-
-        self.pluginAction("add", self.site.address, inner_path)
-        PluginManager.plugin_manager.saveConfig()
-
-        self.cmd(
-            "confirm",
-            ["Plugin installed!<br>You have to restart the client to load the plugin", "Restart"],
-            lambda res: self.actionServerShutdown(to, restart=True)
-        )
-
-        self.response(to, "ok")
-
-    @flag.no_multiuser
-    def actionPluginAddRequest(self, to, inner_path):
-        self.pluginAction("add_request", self.site.address, inner_path)
-        plugin_info = self.site.storage.loadJson(inner_path + "/plugin_info.json")
-        warning = "<b>Warning!<br/>Plugins has the same permissions as the ZeroNet client.<br/>"
-        warning += "Do not install it if you don't trust the developer.</b>"
-
-        self.cmd(
-            "confirm",
-            ["Install new plugin: %s?<br>%s" % (plugin_info["name"], warning), "Trust & Install"],
-            lambda res: self.doPluginAdd(to, inner_path, res)
-        )
-
-    @flag.admin
-    @flag.no_multiuser
-    def actionPluginRemove(self, to, address, inner_path):
-        self.pluginAction("remove", address, inner_path)
-        PluginManager.plugin_manager.saveConfig()
-        return "ok"
-
-    @flag.admin
-    @flag.no_multiuser
-    def actionPluginUpdate(self, to, address, inner_path):
-        self.pluginAction("update", address, inner_path)
-        PluginManager.plugin_manager.saveConfig()
-        PluginManager.plugin_manager.plugins_updated["%s/%s" % (address, inner_path)] = True
-        return "ok"