wiki:adblock2privoxy

Version 2 (modified by zubr, 6 years ago) (diff)

--

Adblock2Privoxy

Convert adblock config files to privoxy format

Introduction

AdBlock Plus browser plugin has great block lists provided by big community, but it is client software and cannot work on a server as proxy.

Privoxy proxy has good potential to block ads at server side, but it experiences acute shortage of updated block lists.

This software converts adblock lists to privoxy config files format.

Almost all adblock features are supported including

  • block/unblock requests (on privoxy)
    • all syntax features are supported except for regex templates matching host name
  • hide/unhide page elements (via CSS)
    • all syntax features are supported
  • all block request options except for outdated ones:
    • Supported: script, image, stylesheet, object, xmlhttprequest, object-subrequest, subdocument,document, elemhide, other, popup, third-party, domain=..., match-case, donottrack
    • Unsupported: collapse, background, xbl, ping and dtd

Tested with privoxy version 3.0.21. Element blocking feature requires a webserver to serve CSS files. See Nginx and Apache config examples provided.

Usage

adblock2privoxy [OPTION...] adblockFiles...
  -V       --version          show version number
  -p PATH  --privoxyDir=PATH  privoxy config output path (required)
  -w PATH  --webDir=PATH      css files output path (optional, privoxyDir is used by default)

Example: adblock2privoxy -p /etc/privoxy -w /var/www/privoxy easylist.txt advblock.txt my_custom.txt

How to apply results

1) Install privoxy. Optionally setup it as transparent proxy

2) Change privoxy config file: Add following lines

actionsfile ab2p.system.action
actionsfile ab2p.action
filterfile ab2p.system.filter
filterfile ab2p.filter

3) Install nginx or apache webserver

Nginx config example:

server {
        listen 80;
        #ab2p css domain name (optional)
        server_name privoxy.zubr.me;

        #root = webDir parameter value 
        root /var/www/privoxy; 

        location ~ ^/[^/.]+\..+/ab2p.css$ {
          	# first reverse domain names order
			rewrite ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css last;
        }

        location ~ (^.*/+)[^/]+/+ab2p.css {
          	# then try to get CSS for current domain
          	# if it is unavailable - get CSS for parent domain
          	try_files $uri $1ab2p.css;
        } 
}

Apache config example:

<VirtualHost *:80>
        #ab2p css domain name (optional)
        ServerName www.example.com 

        #root = webDir parameter value 
        DocumentRoot /var/www/privoxy


        RewriteEngine on

        # first reverse domain names order
        RewriteRule ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css [N]

        # then try to get CSS for current domain
        # if it is unavailable - get CSS for parent domain
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteRule (^.*/+)[^/]+/+ab2p.css$ $1ab2p.css [N]
</VirtualHost>

4) Download adblock config files. Some download locations

5) Run adblock2privoxy providing privoxy dir, web dir and adblock input files

6) Restart privoxy and apache to load updated configs

Here you can

Attachments (3)