forked from spladug/harold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.py
37 lines (27 loc) · 909 Bytes
/
http.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from twisted.web import resource, server
from twisted.application import internet
from plugin import Plugin
from conf import PluginConfig, Option
class HttpConfig(PluginConfig):
port = Option(int, default=80)
secret = Option(str)
class ProtectedResource(resource.Resource):
def __init__(self, http):
self.http = http
def render_POST(self, request):
if request.postpath != [self.http.secret]:
return ""
self._handle_request(request)
return ""
def make_plugin(config):
http_config = HttpConfig(config)
root = resource.Resource()
harold = resource.Resource()
root.putChild('harold', harold)
site = server.Site(root)
site.displayTracebacks = False
plugin = Plugin()
plugin.root = harold
plugin.secret = http_config.secret
plugin.add_service(internet.TCPServer(http_config.port, site))
return plugin