Mercurial > libervia-web
changeset 59:d0fa4e96a5e4
server side: 404 error is now sent instead of directory listing when requesting a directory
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 May 2011 18:39:01 +0200 |
parents | 4fa3d57f72f8 |
children | d9f4a3256da8 |
files | libervia.tac |
diffstat | 1 files changed, 9 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia.tac Sun May 29 17:57:02 2011 +0200 +++ b/libervia.tac Sun May 29 18:39:01 2011 +0200 @@ -36,6 +36,7 @@ from twisted.web import error as weberror from twisted.web.static import File from twisted.web.resource import Resource +from twisted.web.error import NoResource from twisted.python.components import registerAdapter from twisted.words.protocols.jabber.jid import JID from txjsonrpc.web import jsonrpc @@ -85,6 +86,12 @@ if not self.__lock: server.Session.touch(self) +class ProtectedFile(File): + """A File class which doens't show directory listing""" + + def directoryListing(self): + return NoResource() + class SATActionIDHandler(object): """Manage SàT action id lifecycle""" ID_LIFETIME = 30 #after this time (in seconds), id will be suppressed and action result will be ignored @@ -571,7 +578,7 @@ class Libervia(service.Service): def __init__(self): - root = File(LIBERVIA_DIR) + root = ProtectedFile(LIBERVIA_DIR) self.signal_handler = SignalHandler(self) _register = Register(self) self.signal_handler.plugRegister(_register) @@ -595,7 +602,7 @@ root.putChild('json_api', MethodHandler(self)) root.putChild('register_api', _register) root.putChild('blog', MicroBlog(self)) - root.putChild('css', File("server_css/")) + root.putChild('css', ProtectedFile("server_css/")) self.site = server.Site(root) self.site.sessionFactory = LiberviaSession