remove third-party plugin management

refs #216
This commit is contained in:
caryoscelus 2023-07-21 11:33:46 +00:00
parent 809f138edb
commit 07b7c5824f

View file

@ -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"