Changeset 899fa03 in adblock2privoxy


Ignore:
Timestamp:
Mar 15, 2014 9:11:16 PM (6 years ago)
Author:
zubr <a@…>
Branches:
master
Children:
80a88b2
Parents:
7575506
Message:

fine tuning before release

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • README

    r7575506 r899fa03  
    22 
    33--- Introduction --- 
     4AdBlock Plus browser plugin has great block list files provided by big community, 
     5but it is client software and cannot work on a server as proxy. 
     6 
     7Privoxy proxy has good potential to block ads at server side,  
     8but it experiences acute shortage of updated block lists. 
     9 
     10This software converts adblock lists to privoxy config files format.    
    411 
    512Almost all adblock features are supported including 
     
    1421   
    1522Tested with privoxy version 3.0.21. 
    16 Element blocking feature requires a webserver to work. See Nginx and Apache config examples provided. 
     23Element blocking feature requires a webserver to serve CSS files. See Nginx and Apache config examples provided. 
    1724 
    1825--- Usage --- 
     
    2532Example: adblock2privoxy -p /etc/privoxy -w /var/www/privoxy easylist.txt advblock.txt my_custom.txt 
    2633 
    27 --- Config examples --- 
     34--- How to apply results --- 
    2835 
    29 Privoxy config change: Add following lines at the end of config 
     361) Install privoxy. Optionally setup it as transparent proxy 
     372) Change privoxy config file: Add following lines 
    3038 
    3139actionsfile ab2p.system.action 
     
    3442filterfile ab2p.filter 
    3543 
     443) Install nginx or apache webserver 
     45 
    3646Nginx config example: 
    37 server { 
    38         listen 80; 
    39         server_name privoxy.zubr.me; #ab2p css domain name 
    4047 
    41         location ~ ^/[^/.]+\..+/ab2p.css$ { 
    42           # first reverse domain names order 
    43           rewrite ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css last; 
    44         } 
     48        server { 
     49                listen 80; 
     50                #ab2p css domain name (optional) 
     51                server_name privoxy.zubr.me; 
     52         
     53                #root = webDir parameter value  
     54                root /var/www/privoxy;  
     55         
     56                location ~ ^/[^/.]+\..+/ab2p.css$ { 
     57                        # first reverse domain names order 
     58                                rewrite ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css last; 
     59                } 
     60         
     61                location ~ (^.*/+)[^/]+/+ab2p.css { 
     62                        # then try to get CSS for current domain 
     63                        # if it is unavailable - get CSS for parent domain 
     64                        try_files $uri $1ab2p.css; 
     65                }  
     66        } 
    4567 
    46         location ~ (^.*/+)[^/]+/+ab2p.css { 
    47           # then try to get CSS for current domain 
    48           # if it is unavailable - get CSS for parent domain 
    49           try_files $uri $1ab2p.css; 
    50         } 
     68Apache config example: 
    5169 
    52         root /var/www/privoxy; #webDir 
    53 } 
     70        <VirtualHost *:80> 
     71                #ab2p css domain name (optional) 
     72                ServerName www.example.com  
     73         
     74                #root = webDir parameter value  
     75                DocumentRoot /var/www/privoxy 
     76         
     77         
     78                RewriteEngine on 
     79         
     80                # first reverse domain names order 
     81                RewriteRule ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css [N] 
     82         
     83                # then try to get CSS for current domain 
     84                # if it is unavailable - get CSS for parent domain 
     85                RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
     86                RewriteRule (^.*/+)[^/]+/+ab2p.css$ $1ab2p.css [N] 
     87        </VirtualHost> 
    5488 
    55 Apache config example: TBD 
     894) Download adblock config files. Some download locations 
     90EasyList: https://easylist.adblockplus.org/en/ 
     91Russian AD list: https://code.google.com/p/ruadlist/ 
    5692 
     935) Run adblock2privoxy providing privoxy dir, web dir and adblock input files 
     946) Restart privoxy and apache to load updated configs 
    5795 
     96  
  • adblock2privoxy.cabal

    r9dc8cfc r899fa03  
    77                templates/ab2p.system.action,  
    88                templates/ab2p.system.filter 
     9extra-source-files: README 
    910license:        GPL-3 
    10 maintainer:     a@zubr.me 
     11maintainer:     Alexey Zubritsky <a@zubr.me> 
    1112license-file:   LICENSE 
    1213stability:      stable 
    1314synopsis:       Convert adblock config files to privoxy format 
    1415description:     
     16                     AdBlock Plus browser plugin has great block list files provided by big community, 
     17                     but it is client software and cannot work on a server as proxy. 
     18                     . 
     19                     Privoxy proxy has good potential to block ads at server side,  
     20                     but it experiences acute shortage of updated block lists. 
     21                     . 
     22                     This software converts adblock lists to privoxy config files format.    
     23                     . 
    1524                     Almost all adblock features are supported including 
    1625                     - block/unblock requests (on privoxy) 
     
    2231                                  document, elemhide, other, popup, third-party, domain=..., match-case, donottrack 
    2332                       Unsupported: collapse, background, xbl, ping and dtd 
    24                      .   
    25                      Tested with privoxy version 3.0.21. 
    26                      Element blocking feature requires a webserver to work. See Nginx and Apache config examples provided. 
     33homepage:       http://zubr.me/ab2p/ 
     34category:       Web 
    2735 
    2836executable adblock2privoxy 
  • src/ElementBlocker.hs

    r9dc8cfc r899fa03  
    3232           createDirectoryIfMissing True debugPath 
    3333           writeBlockTree path debugPath rulesTree  
    34            writePatterns (path </> "ab2p.common.css") (debugPath </> "ab2p.common.css") flatPatterns       
     34           writePatterns info (path </> "ab2p.common.css") (debugPath </> "ab2p.common.css") flatPatterns       
    3535    removeOld entry' =  
    3636        let entry = path </> entry' 
     
    4040                    else when (takeExtension entry == ".css") $ removeFile entry              
    4141    writeBlockTree :: String -> String -> BlockedRulesTree -> IO () 
    42     writeBlockTree nodePath debugNodePath (Node name patterns children) = 
     42    writeBlockTree normalNodePath debugNodePath (Node name patterns children) = 
    4343        do 
    44             createDirectoryIfMissing True path' 
    45             createDirectoryIfMissing True debugPath' 
    46             _ <- sequence (writeBlockTree path' debugPath' <$> children) 
    47             writePatterns filename debugFilename patterns         
     44            createDirectoryIfMissing True normalPath 
     45            createDirectoryIfMissing True debugPath 
     46            _ <- sequence (writeBlockTree normalPath debugPath <$> children) 
     47            writePatterns ["See ab2p.common.css for sources info"] normalFilename debugFilename patterns         
    4848        where 
    49             path'  
    50                 | null name = nodePath 
    51                 | otherwise = nodePath </> name 
    52             debugPath'  
     49            normalPath  
     50                | null name = normalNodePath 
     51                | otherwise = normalNodePath </> name 
     52            debugPath  
    5353                | null name = debugNodePath 
    5454                | otherwise = debugNodePath </> name 
    55             filename = path' </> "ab2p.css" 
    56             debugFilename = debugPath' </> "ab2p.css"       
    57     writePatterns :: String -> String -> [Pattern] -> IO () 
    58     writePatterns _ _ [] = return () 
    59     writePatterns filename debugFilename patterns =  
     55            normalFilename = normalPath </> "ab2p.css" 
     56            debugFilename = debugPath </> "ab2p.css"       
     57    writePatterns :: [String] -> String -> String -> [Pattern] -> IO () 
     58    writePatterns _ _ _ [] = return () 
     59    writePatterns info' normalFilename debugFilename patterns =  
    6060         do  
    6161            writeCssFile debugFilename $ intercalate "\n" $ (++ Templates.blockCss) <$> patterns 
    62             writeCssFile filename $ intercalate "\n" $ (++ Templates.blockCss) <$> intercalate "," <$>  
     62            writeCssFile normalFilename $ intercalate "\n" $ (++ Templates.blockCss) <$> intercalate "," <$>  
    6363                                                                            splitEvery 4000 patterns 
    6464         where  
    6565         splitEvery n = takeWhile (not . null) . unfoldr (Just . splitAt n) 
    66     writeCssFile filename content =  
    67          do outFile <- openFile filename WriteMode 
    68             hPutStrLn outFile "/*" 
    69             _ <- mapM (hPutStrLn outFile) info 
    70             hPutStrLn outFile "*/" 
    71             hPutStrLn outFile content 
    72             hClose outFile  
     66         writeCssFile filename content =  
     67                do outFile <- openFile filename WriteMode 
     68                   hPutStrLn outFile "/*" 
     69                   _ <- mapM (hPutStrLn outFile) info' 
     70                   hPutStrLn outFile "*/" 
     71                   hPutStrLn outFile content 
     72                   hClose outFile  
    7373          
    7474elemBlockData :: [Line] -> ElemBlockData  
  • src/Main.hs

    r9dc8cfc r899fa03  
    2828         (ReqArg (\ f opts -> opts { _privoxyDir = f }) 
    2929                 "PATH") 
    30          "privoxy config output path" 
     30         "privoxy config output path (required)" 
    3131     , Option ['w']     ["webDir"] 
    3232         (ReqArg (\ f opts -> opts { _webDir = f }) 
    3333                 "PATH") 
    34          "css files output path" 
     34         "css files output path (optional, privoxyDir is used by default)" 
    3535     ] 
    3636 
Note: See TracChangeset for help on using the changeset viewer.