]> jfr.im git - irc/quakenet/qwebirc.git/blame - qwebirc/root.py
Fix several login bugs, add bouncer auth mode.
[irc/quakenet/qwebirc.git] / qwebirc / root.py
CommitLineData
1d924d97
CP
1from twisted.web import resource, server, static, http
2from twisted.internet import error, reactor
85f01e3f 3import engines
85f01e3f 4import mimetypes
1d924d97 5import config
e44c9cdc 6import sigdebug
9e769c12
CP
7
8class RootResource(resource.Resource):
d65fe45f
CP
9 def getChild(self, name, request):
10 if name == "":
2b8e1a88 11 name = "qui.html"
d65fe45f
CP
12 return self.primaryChild.getChild(name, request)
13
1d924d97
CP
14# we do NOT use the built-in timeOut mixin as it's very very buggy!
15class TimeoutHTTPChannel(http.HTTPChannel):
16 timeout = config.HTTP_REQUEST_TIMEOUT
17
18 def connectionMade(self):
19 self.customTimeout = reactor.callLater(self.timeout, self.timeoutOccured)
20 http.HTTPChannel.connectionMade(self)
21
22 def timeoutOccured(self):
23 self.customTimeout = None
24 self.transport.loseConnection()
25
26 def cancelTimeout(self):
27 if self.customTimeout is not None:
28 try:
29 self.customTimeout.cancel()
30 self.customTimeout = None
31 except error.AlreadyCalled:
32 pass
33
34 def connectionLost(self, reason):
35 self.cancelTimeout()
36 http.HTTPChannel.connectionLost(self, reason)
37
9e769c12 38class RootSite(server.Site):
1d924d97
CP
39 # we do this ourselves as the built in timeout stuff is really really buggy
40 protocol = TimeoutHTTPChannel
41
9e769c12 42 def __init__(self, path, *args, **kwargs):
d65fe45f 43 root = RootResource()
9e769c12 44 server.Site.__init__(self, root, *args, **kwargs)
d65fe45f 45
85f01e3f
CP
46 services = {}
47 services["StaticEngine"] = root.primaryChild = engines.StaticEngine(path)
28c8008e 48
85f01e3f
CP
49 def register(service, path, *args, **kwargs):
50 sobj = service("/" + path, *args, **kwargs)
51 services[service.__name__] = sobj
52 root.putChild(path, sobj)
53
54 register(engines.AJAXEngine, "e")
55 register(engines.FeedbackEngine, "feedback")
56 register(engines.AuthgateEngine, "auth")
57 register(engines.AdminEngine, "adminengine", services)
58
28c8008e 59mimetypes.types_map[".ico"] = "image/vnd.microsoft.icon"