NoNewSites.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ##
  2. ## Copyright (c) 2022 caryoscelus
  3. ##
  4. ## zeronet-conservancy is free software: you can redistribute it and/or modify it under the
  5. ## terms of the GNU General Public License as published by the Free Software
  6. ## Foundation, either version 3 of the License, or (at your option) any later version.
  7. ##
  8. ## zeronet-conservancy is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. ## details.
  12. ##
  13. ## You should have received a copy of the GNU General Public License along with
  14. ## zeronet-conservancy. If not, see <https://www.gnu.org/licenses/>.
  15. ##
  16. import re
  17. from Plugin import PluginManager
  18. # based on the code from Multiuser plugin
  19. @PluginManager.registerTo("UiRequest")
  20. class NoNewSites(object):
  21. def __init__(self, *args, **kwargs):
  22. return super(NoNewSites, self).__init__(*args, **kwargs)
  23. def actionWrapper(self, path, extra_headers=None):
  24. match = re.match("/(media/)?(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
  25. if not match:
  26. self.sendHeader(500)
  27. return self.formatError("Plugin error", "No match for address found")
  28. addr = match.group("address")
  29. if not self.server.site_manager.get(addr):
  30. self.sendHeader(404)
  31. return self.formatError("Not Found", "Adding new sites disabled", details=False)
  32. return super(NoNewSites, self).actionWrapper(path, extra_headers)
  33. # def parsePath(self, path):
  34. # return super(NoNewSites, self).parsePath(path)