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