From 74573966f12317fd5619f0ce42675f5c3a5a33ab Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Fri, 5 Aug 2022 12:43:08 +0000 Subject: [PATCH] No new sites plugin (#26) NoNewSites plugin a small plugin that disables adding new sites (similar to multi user plugin setting), good as a source of sample plugin code --- plugins/disabled-NoNewSites/NoNewSites.py | 39 ++++++++++++++++++++ plugins/disabled-NoNewSites/__init__.py | 1 + plugins/disabled-NoNewSites/plugin_info.json | 5 +++ 3 files changed, 45 insertions(+) create mode 100644 plugins/disabled-NoNewSites/NoNewSites.py create mode 100644 plugins/disabled-NoNewSites/__init__.py create mode 100644 plugins/disabled-NoNewSites/plugin_info.json diff --git a/plugins/disabled-NoNewSites/NoNewSites.py b/plugins/disabled-NoNewSites/NoNewSites.py new file mode 100644 index 00000000..9bef8753 --- /dev/null +++ b/plugins/disabled-NoNewSites/NoNewSites.py @@ -0,0 +1,39 @@ +## +## Copyright (c) 2022 caryoscelus +## +## zeronet-conservancy is free software: you can redistribute it and/or modify it under the +## terms of the GNU General Public License as published by the Free Software +## Foundation, either version 3 of the License, or (at your option) any later version. +## +## zeronet-conservancy is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## zeronet-conservancy. If not, see . +## + +import re +from Plugin import PluginManager + +# based on the code from Multiuser plugin +@PluginManager.registerTo("UiRequest") +class NoNewSites(object): + def __init__(self, *args, **kwargs): + return super(NoNewSites, self).__init__(*args, **kwargs) + def actionWrapper(self, path, extra_headers=None): + match = re.match("/(media/)?(?P
[A-Za-z0-9\._-]+)(?P/.*|$)", path) + if not match: + self.sendHeader(500) + return self.formatError("Plugin error", "No match for address found") + + addr = match.group("address") + + if not self.server.site_manager.get(addr): + self.sendHeader(404) + return self.formatError("Not Found", "Adding new sites disabled", details=False) + return super(NoNewSites, self).actionWrapper(path, extra_headers) + + # def parsePath(self, path): + # return super(NoNewSites, self).parsePath(path) diff --git a/plugins/disabled-NoNewSites/__init__.py b/plugins/disabled-NoNewSites/__init__.py new file mode 100644 index 00000000..1781711b --- /dev/null +++ b/plugins/disabled-NoNewSites/__init__.py @@ -0,0 +1 @@ +from . import NoNewSites diff --git a/plugins/disabled-NoNewSites/plugin_info.json b/plugins/disabled-NoNewSites/plugin_info.json new file mode 100644 index 00000000..c924d126 --- /dev/null +++ b/plugins/disabled-NoNewSites/plugin_info.json @@ -0,0 +1,5 @@ +{ + "name": "NoNewSites", + "description": "disables adding new sites (e.g. for proxies)", + "default": "disabled" +}