# HG changeset patch # User Goffi # Date 1306687141 -7200 # Node ID d0fa4e96a5e41e6f323e4ee8e8ba334127c11576 # Parent 4fa3d57f72f8cfddb1893283247149b524fd7a95 server side: 404 error is now sent instead of directory listing when requesting a directory diff -r 4fa3d57f72f8 -r d0fa4e96a5e4 libervia.tac --- 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