From f75d5c45754b94d8c29424efaa5505c808ed5115 Mon Sep 17 00:00:00 2001 From: Paul Butler Date: Sun, 13 Aug 2017 17:33:52 -0400 Subject: [PATCH] add blacklist templates and generation script --- Makefile | 3 + blacklist.json | 161 +++++++++++++++++++++++++++++++ src/generate_blacklist.py | 32 ++++++ templates/adblock-plus.txt.tmpl | 10 ++ templates/hosts-file.txt.tmpl | 12 +++ templates/ublock-origin.txt.tmpl | 8 ++ 6 files changed, 226 insertions(+) create mode 100644 blacklist.json create mode 100644 src/generate_blacklist.py create mode 100644 templates/adblock-plus.txt.tmpl create mode 100644 templates/hosts-file.txt.tmpl create mode 100644 templates/ublock-origin.txt.tmpl diff --git a/Makefile b/Makefile index a399285..3e718cc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ +blacklists/% : src/generate_blacklist.py blacklist.json templates/%.tmpl + python $^ $@ + package : cd extension; zip barbblock.zip -r ./ -x *.git* mv extension/barbblock.zip ./ diff --git a/blacklist.json b/blacklist.json new file mode 100644 index 0000000..28da99c --- /dev/null +++ b/blacklist.json @@ -0,0 +1,161 @@ +{ + "name": "BarbBlock", + "version": "1.1", + "description": "Blocks requests to sites which have used legal threats to remove themselves from other blacklists.", + "last_update": "2017-08-13", + "url_base": "https://ssl.bblck.me/blacklists", + "page_url": "https://ssl.bblck.me/", + + "blacklist": [ + { + "issues": [1], + "takedown": "https://github.com/github/dmca/blob/master/2017/2017-08-02-LevenLabs.md", + "domains": [ + "functionalclam.com" + ] + }, + { + "issues": [8], + "domains": [ + "2znp09oa.com", + "4jnzhl0d0.com", + "6ldu6qa.com", + "82o9v830.com", + "abandonedclover.com", + "abruptroad.com", + "actuallysheep.com", + "ak0gsh40.com", + "ambitiousagreement.com", + "anxiousapples.com", + "argyresthia.com", + "awzbijw.com", + "balloontexture.com", + "baskettexture.com", + "bawdybeast.com", + "beamincrease.com", + "beamkite.com", + "boilingbeetle.com", + "boredcrown.com", + "brassrule.com", + "broadboundary.com", + "broadcastbed.com", + "calmfoot.com", + "cherrythread.com", + "chiefcurrent.com", + "chinchickens.com", + "comfortablecheese.com", + "commandwalk.com", + "concernrain.com", + "consciouscabbage.com", + "copperchickens.com", + "copycarpenter.com", + "copyrightaccesscontrols.com", + "crawlclocks.com", + "critictruck.com", + "crownclam.com", + "curtaincows.com", + "cutecushion.com", + "decisiveducks.com", + "delightdriving.com", + "differentdesk.com", + "dk4ywix.com", + "docksalmon.com", + "doubtfulrainstorm.com", + "dragzebra.com", + "elasticchange.com", + "elephantqueue.com", + "exclusivebrass.com", + "flavordecision.com", + "floodprincipal.com", + "functionalclam.com", + "futuristicfairies.com", + "fuzzyflavor.com", + "ga87z2o.com", + "giddycoat.com", + "gorgeousground.com", + "greetzebra.com", + "greyinstrument.com", + "guardedgovernor.com", + "guitarbelieve.com", + "h78xb.pw", + "hfc195b.com", + "hilariouszinc.com", + "illustriousoatmeal.com", + "incrediblesugar.com", + "ivykiosk.com", + "j93557g.com", + "jewelcheese.com", + "karisimbi.net", + "limpingline.com", + "lizardslaugh.com", + "lopsidedspoon.com", + "loudloss.com", + "lp3tdqle.com", + "lumpyleaf.com", + "matchcows.com", + "messagenovice.com", + "mixedreading.com", + "mowfruit.com", + "ovalpigs.com", + "peacepowder.com", + "photographpan.com", + "pietexture.com", + "possibleboats.com", + "practicetoothpaste.com", + "presetrabbits.com", + "profitrumour.com", + "provideplant.com", + "quaintcan.com", + "quicksandear.com", + "readgoldfish.com", + "rebelsubway.com", + "receptiveink.com", + "resolutekey.com", + "rulerabbit.com", + "saysidewalk.com", + "scarcestream.com", + "scrubsky.com", + "scrubswim.com", + "separatesilver.com", + "shakesea.com", + "shakytaste.com", + "shallowschool.com", + "shelterstraw.com", + "shiveringsail.com", + "shockingswing.com", + "simplisticnose.com", + "sinceresofa.com", + "snakesort.com", + "sneaklevel.com", + "sneakystamp.com", + "spectacularsnail.com", + "spillvacation.com", + "squeamishscarecrow.com", + "storesurprise.com", + "stormyachiever.com", + "stormyshock.com", + "stormysponge.com", + "straightnest.com", + "strivesidewalk.com", + "structuresofa.com", + "succeedscene.com", + "superficialsink.com", + "terribleturkey.com", + "thirdrespect.com", + "throattrees.com", + "tidytrail.com", + "tracedesire.com", + "trickycelery.com", + "tritetongue.com", + "truckstomatoes.com", + "unknowntray.com", + "unusualtitle.com", + "voicevegetable.com", + "wateryvan.com", + "wirecomic.com", + "xovq5nemr.com", + "zbwp6ghm.com" + ] + } + ] +} diff --git a/src/generate_blacklist.py b/src/generate_blacklist.py new file mode 100644 index 0000000..1f3de4f --- /dev/null +++ b/src/generate_blacklist.py @@ -0,0 +1,32 @@ +import argparse +import os +import json + +import jinja2 + + +def run_template_engine(blacklist_file, template_file, output_file): + template_path, template_file = os.path.split(template_file) + + with open(blacklist_file) as bf: + context = json.load(bf) + + result = jinja2.Environment( + loader=jinja2.FileSystemLoader(template_path or './') + ).get_template(template_file).render(context) + + with open(output_file, 'w') as of: + of.write(result) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('blacklist') + parser.add_argument('template') + parser.add_argument('outfile') + args = parser.parse_args() + run_template_engine(args.blacklist, args.template, args.outfile) + + +if __name__ == '__main__': + main() diff --git a/templates/adblock-plus.txt.tmpl b/templates/adblock-plus.txt.tmpl new file mode 100644 index 0000000..f56d508 --- /dev/null +++ b/templates/adblock-plus.txt.tmpl @@ -0,0 +1,10 @@ +[Adblock Plus 2.0] +! Version: {{ version }} +! Title: {{ name }} +! Last modified: {{ last_update }} +! Expires: 1 days +! Homepage: {{ page_url }}{% for blockset in blacklist %} +! ============== Site group {{loop.index}} =============={% for issue in blockset.issues %} +! GitHub Issue: https://github.com/paulgb/BarbBlock/issues/{{ issue }}{% endfor %}{% if blockset.takedown %} +! Takedown URL: {{ blockset.takedown }}{% endif %}{% for domain in blockset.domains %} +||{{ domain }}^{% endfor %}{% endfor %} diff --git a/templates/hosts-file.txt.tmpl b/templates/hosts-file.txt.tmpl new file mode 100644 index 0000000..8f47621 --- /dev/null +++ b/templates/hosts-file.txt.tmpl @@ -0,0 +1,12 @@ +# {{ name }} +# Version: {{ version }} +# Last Update: {{ last_update }} +# Homepage: {{ page_url }} +# Canonical URL for this file: {{ url_base }}/hosts-file.txt +{% for blockset in blacklist %} +# ============== Site group {{loop.index}} =============={% for issue in blockset.issues %} +# GitHub Issue: https://github.com/paulgb/BarbBlock/issues/{{ issue }}{% endfor %}{% if blockset.takedown %} +# Takedown URL: {{ blockset.takedown }}{% endif %} +{% for domain in blockset.domains %} +0.0.0.0 {{ domain }}{% endfor %} +{% endfor %} diff --git a/templates/ublock-origin.txt.tmpl b/templates/ublock-origin.txt.tmpl new file mode 100644 index 0000000..f47f2ed --- /dev/null +++ b/templates/ublock-origin.txt.tmpl @@ -0,0 +1,8 @@ +! Title: {{ name }} +! Homepage: {{ page_url }} +! {{ description }} +{% for blockset in blacklist %}! ============== Site group {{loop.index}} =============={% for issue in blockset.issues %} +! GitHub Issue: https://github.com/paulgb/BarbBlock/issues/{{ issue }}{% endfor %}{% if blockset.takedown %} +! Takedown URL: {{ blockset.takedown }}{% endif %}{% for domain in blockset.domains %} +||{{ domain }}{% endfor %} +{% endfor %} \ No newline at end of file