caddybanip

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

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

Go to latest
Published: Oct 2, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

CaddyBanIP

A Caddy 2 module that allows you to ban IPs from visiting a part or the entirety of your website.

Go Report Card

Install

Prerequisites:

Run this command in your terminal to build a custom version of Caddy that includes CaddyBanIP.

xcaddy build --with github.com/DrivetDevelopment/CaddyBanIP

I recommend you to remove any other versions of Caddy you have installed, like the stock version of Caddy.

Linux? You might already have a systemd service for Caddy. Let's replace the binary:

mv caddy /usr/bin/caddy
chmod +x /usr/bin/caddy

systemctl restart caddy # if you have a systemd service

Setup

Add this to your Caddyfile:

{
    order caddybanip before file_server
}

This is, unfortunately, required in Caddy. It tells Caddy to load the CaddyBanIP module before the file_server module.

Now, add the following to your Caddyfile:

(bannedIPs) {
        caddybanip {
            banned_ips "127.0.0.1|192.168.10.164" # IPs you do not want to visit this path. Note: Regex
            message "You are banned from visiting this website!" # Optional, but recommended if you think the default message is an advertisement or something.
        }
}

yourwebsite.com {
    import bannedIPs
}

You can also ban specific IPs from accessing paths, with the handle_path directive.

Users of CaddyBanIP

Do you use CaddyBanIP? Let me know by opening an issue or a pull request to add yourself into this list!

Documentation

Overview

CaddyBanIP is a Caddy 2 module that allows you to ban IPs from visiting a part or the entirety of your website.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaddyBanIP

type CaddyBanIP struct {
	BannedIPs string `json:"banned_ips,omitempty"`
	Message   string `json:"message,omitempty"`
	// contains filtered or unexported fields
}

func (CaddyBanIP) CaddyModule

func (CaddyBanIP) CaddyModule() caddy.ModuleInfo

func (*CaddyBanIP) Provision

func (c *CaddyBanIP) Provision(ctx caddy.Context) error

func (CaddyBanIP) ServeHTTP

func (c CaddyBanIP) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

func (*CaddyBanIP) UnmarshalCaddyfile

func (c *CaddyBanIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

func (*CaddyBanIP) Validate

func (c *CaddyBanIP) Validate() error

Jump to

Keyboard shortcuts

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