]>
Commit | Line | Data |
---|---|---|
9e769c12 CP |
1 | from zope.interface import implements |
2 | ||
3 | from twisted.python import usage | |
4 | from twisted.internet import task | |
5 | from twisted.plugin import IPlugin | |
6 | from twisted.application.service import IServiceMaker | |
7 | from twisted.application import internet, strports | |
8 | from twisted.web import static, server | |
9 | ||
10 | from qwebirc import RootSite | |
265f5ce3 | 11 | import config as CONFIG |
9e769c12 CP |
12 | |
13 | class Options(usage.Options): | |
14 | optParameters = [["port", "p", "9090","Port to start the server on."], | |
15 | ["logfile", "l", None, "Path to web CLF (Combined Log Format) log file."], | |
16 | ["https", None, None, "Port to listen on for Secure HTTP."], | |
17 | ["certificate", "c", "server.pem", "SSL certificate to use for HTTPS. "], | |
18 | ["privkey", "k", "server.pem", "SSL certificate to use for HTTPS."], | |
19 | ["staticpath", "s", "static", "Path to static content"], | |
20 | ] | |
21 | ||
22 | optFlags = [["notracebacks", "n", "Display tracebacks in broken web pages. " + | |
23 | "Displaying tracebacks to users may be security risk!"], | |
24 | ] | |
25 | ||
26 | zsh_actions = {"logfile" : "_files -g '*.log'", "certificate" : "_files -g '*.pem'", | |
27 | "privkey" : "_files -g '*.pem'"} | |
28 | ||
29 | def postOptions(self): | |
30 | if self['https']: | |
31 | try: | |
32 | from twisted.internet.ssl import DefaultOpenSSLContextFactory | |
33 | except ImportError: | |
34 | raise usage.UsageError("SSL support not installed") | |
35 | ||
36 | class QWebIRCServiceMaker(object): | |
37 | implements(IServiceMaker, IPlugin) | |
38 | tapname = "qwebirc" | |
39 | description = "QuakeNet web-based IRC client" | |
40 | options = Options | |
9e769c12 CP |
41 | |
42 | def makeService(self, config): | |
43 | if config['logfile']: | |
44 | site = RootSite(config['staticpath'], logPath=config['logfile']) | |
45 | else: | |
46 | site = RootSite(config['staticpath']) | |
47 | ||
265f5ce3 | 48 | site.timeOut = CONFIG.HTTP_REQUEST_TIMEOUT |
e854a5f3 | 49 | |
9e769c12 CP |
50 | site.displayTracebacks = not config["notracebacks"] |
51 | if config['https']: | |
52 | from twisted.internet.ssl import DefaultOpenSSLContextFactory | |
53 | i = internet.SSLServer(int(config['https']), site, DefaultOpenSSLContextFactory(config['privkey'], config['certificate'])) | |
54 | else: | |
55 | i = internet.TCPServer(int(config['port']), site) | |
56 | ||
57 | return i | |
58 | ||
d4e3371b | 59 | serviceMaker = QWebIRCServiceMaker() |