ipfilter

package module
v0.0.0-...-f492195 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2015 License: Apache-2.0 Imports: 10 Imported by: 0

README

ipfilter

ipfilter is a middleware for Caddy

Caddyfile examples

filter clients based on a giving IP or range of IPs
ipfilter / {
	rule block
	ip 212.42.10.50-100 213.42.9.10-50 214.1.1.10
}

caddy will block any clients with IPs that fall into one of these two ranges 212.42.10.50-100, 213.42.9.10-50 , or a client that has an IP of 214.1.1.10 explicitly, ranges are inclusive, which means 212.42.10.100 will get blocked.

ipfilter / {
	rule allow
	blockpage default.html
	ip 55.3.4.20 55.3.4.30
}

caddy will serve only these 2 IPs, eveyone else will get default.html

filter clients based on their Country ISO Code

filtering with country codes requires a local copy of the Geo database, can be downloaded for free from MaxMind

ipfilter / {
	rule allow
	database /data/GeoLite.mmdb
	country US JP
}

with that in your Caddyfile caddy will only serve users from the United States or Japan

ipfilter /notglobal /secret {
	rule block
	database /data/GeoLite.mmdb
	blockpage default.html
	country US JP
}

having that in your Caddyfile caddy will ignore any requests from United States or Japan to /notglobal or /secret and it will show default.html instead, blockpage is optional.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

Setup parses the ipfilter configuration and returns the middleware handler

Types

type IPFConfig

type IPFConfig struct {
	PathScopes   []string
	Rule         string
	BlockPage    string
	CountryCodes []string
	Ranges       []Range

	DBHandler *maxminddb.Reader // Database's handler if it gets opened
}

IPFConfig holds the configuration for the ipfilter middleware

type IPFilter

type IPFilter struct {
	Next   middleware.Handler
	Config IPFConfig
}

IPFilter is a middleware for filtering clients based on their ip or country's ISO code;

func (IPFilter) ServeHTTP

func (ipf IPFilter) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

type OnlyCountry

type OnlyCountry struct {
	Country struct {
		ISOCode string `maxminddb:"iso_code"`
	} `maxminddb:"country"`
}

OnlyCountry is used to fetch only the country's code from 'mmdb'

type Range

type Range struct {
	// contains filtered or unexported fields
}

Range is a pair of two 'net.IP'

func (Range) InRange

func (rng Range) InRange(ip *net.IP) bool

InRange is a method of 'Range' takes a pointer to net.IP, returns true if in range, false otherwise

Jump to

Keyboard shortcuts

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