forked from Romeus/Firewall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelist.py
28 lines (22 loc) · 959 Bytes
/
whitelist.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
from libmproxy.protocol.http import HTTPResponse
from netlib.odict import ODictCaseless
"""
Reject requests contained in whitelist.txt
"""
with open ("whitelist.txt", "r") as my_whitelist_file:
whitelist = my_whitelist_file.readlines()
whitelist = map(lambda s: s.rstrip('\n'), whitelist)
print whitelist
with open ("access_denied_template.html", "r") as myfile:
template=myfile.read()
def request(context, flow):
# pretty_host(hostheader=True) takes the Host: header of the request into account,
# which is useful in transparent mode where we usually only have the IP otherwise.
# Method 1: Answer with a locally generated response
header = flow.request.pretty_host(hostheader=True)
if not header in whitelist:
resp = HTTPResponse(
[1, 1], 200, "OK",
ODictCaseless([["Content-Type", "text/html"]]),
template.replace('$URL', flow.request.url))
flow.reply(resp)