adblock

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2021 License: MPL-2.0 Imports: 20 Imported by: 0

README

adblock RELEASE

A coredns plugin to block domains.

Usage

.:1053 {
    errors
    bind 127.0.0.1
    forward . 223.5.5.5:53

    log . {
        class all
    }

    adblock {
        # bloom filter capacity & rate. default: 300_000 0.01
        size_rate 300_000 0.01
    
        # enable log, remove is disable
        log
        
        # block_query_type, return REFUSED
        block_qtype A AAAA HTTPS MX PTR SRV CNAME
        
        # blocked_query_response, soa is default. Options: soa / zero / hinfo / no-ans
        resp_type zero
        
        # (the last cache-data will be ues) load cache file from local or remote
        cache_data https://example.com/rules.data
        cache_data <AbsolutePath>/rules.data
        
        # black list to block query, load rules from local or remote.
        # use local+ will disable the domain means allow any line exclude comment
        black_list <AbsolutePath>/list.txt
        black_list local+<AbsolutePath>/list.txt
        black_list https://example.com/reject-list.txt
        
        # white list to disable block
        white_list <AbsolutePath>/white-list.txt
        white_list https://example.com/white-list.txt
    }
}

Feature

  • 支持从远端/本地加载规则
  • 支持从远端/本地加载缓存
  • 支持多种屏蔽的返回报文
    • SOA
    • HINFO
    • ZERO
    • No-Ans
    • NX
    • REFUSED
  • 支持屏蔽指定类型查询
  • 支持多种格式的规则文件
    • hosts - HostParser
    • surge - SurgeParser
    • dnsmasq - DnsmasqParser
    • domain - DomainParser

TODO

  • Github Action 创建缓存文件
  • Github Action 创建bin文件
  • 使用缓存文件
  • 增加response的报文类型
  • Cache最近的查询
  • expose过滤器的参数
  • 增加white_list
  • 屏蔽指定类型的dns查询
  • 引入AdGuard的过滤器
  • 支持泛域名(需要考虑n级域名的问题)
  • [ ]

Documentation

Index

Constants

View Source
const (
	MINUTE = 60
	HOUR   = 60 * MINUTE
	DAY    = 24 * HOUR

	/*
	 * respType: using by switch logic
	 */
	NO_ANS  = 1
	SOA     = 2
	HINFO   = 3
	ZERO    = 4
	NX      = 5
	REFUSED = 6
)

Variables

This section is empty.

Functions

func FileToLines added in v0.0.5

func FileToLines(path string) ([]string, error)

func LinesFromReader

func LinesFromReader(r io.Reader) ([]string, error)

func LoadCacheByLocal added in v0.0.3

func LoadCacheByLocal(path string, filter *bloom.BloomFilter) error

func LoadCacheByRemote added in v0.0.3

func LoadCacheByRemote(uri string, filter *bloom.BloomFilter) error

func LoadRuleByLocal added in v0.0.3

func LoadRuleByLocal(path string, filter *bloom.BloomFilter, strictMode bool) error

func LoadRuleByRemote added in v0.0.3

func LoadRuleByRemote(uri string, filter *bloom.BloomFilter) error

func UrlToLines

func UrlToLines(url string) ([]string, error)

Types

type Adblock

type Adblock struct {
	Next    plugin.Handler
	Configs *Configs
}

func (Adblock) Name

func (app Adblock) Name() string

func (Adblock) Ready

func (app Adblock) Ready() bool

Ready implements the ready.Readiness interface, once this flips to true CoreDNS assumes this plugin is ready for queries; it is not checked again.

func (Adblock) ServeDNS

func (app Adblock) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

type Configs

type Configs struct {
	Size int
	Rate float64
	// contains filtered or unexported fields
}

func DefaultConfigs

func DefaultConfigs() *Configs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL