-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-ruleset.py
35 lines (28 loc) · 985 Bytes
/
update-ruleset.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
import io
import json
import os
import re
TLD = "globaleaks.tor.onion"
RULESET_DIR = "rulesets"
def write_custom_ruleset(entry):
tld = "." + TLD if entry["slug"] else TLD
ruleset = "<ruleset name=\"{org_name}\">\n" \
" <target host=\"{slug}{globaleaks_tld}\" />\n" \
" <rule from=\"^http[s]?:\/\/([a-z0-9\-]+[.])?{slug}{globaleaks_tld}\" to=\"http://$1{onion_address}\" />\n" \
"</ruleset>\n".format(
org_name=entry["title"],
slug=entry["slug"],
onion_address=entry["onion_address"],
globaleaks_tld=tld
)
RULESET_OUTPUT = "globaleaks-ruleset.xml"
with open(
os.path.join(RULESET_DIR, entry["slug"] + tld + ".xml"),
"w",
) as f:
f.write(ruleset)
if __name__ == "__main__":
with io.open("directory.json", "r", encoding="utf-8") as f:
directory = json.loads(f.read().rstrip("\n"))
for entry in directory:
write_custom_ruleset(entry)