Coder Social home page Coder Social logo

nbari / policyd-rate-limit Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 109 KB

Postfix rate limiter SMTP policy daemon

License: BSD 3-Clause "New" or "Revised" License

Rust 93.05% TSQL 6.95%
smtp postfix postfix-policy-server rate-limiting rate-limit rate limit quota

policyd-rate-limit's Introduction

policyd-rate-limit

crates.io Build Status

Postfix rate limiter SMTP policy daemon

How it works

It depends on the Postfix policy delegation protocol, it searches for the sasl_username and based on the defined limits stored in a MySQl database it rejects or allows action=DUNNO the email to be sent.

How to use

USAGE:
    policyd-rate-limit [OPTIONS] --dsn <dsn> [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -d, --dsn <dsn>          mysql://<username>:<password>@tcp(<host>:<port>)/<database>
        --max <max>          mysql pool max connections [default: 50]
        --min <min>          mysql pool min connections [default: 3]
    -s, --socket <socket>    path to Unix domain socket [default: /tmp/policy-rate-limit.sock]

SUBCOMMANDS:
    cuser    Create the user if not found, defaults: 100 messages per day
    help     Prints this message or the help of the given subcommand(s)

For the subcommand cuser:

Create the user if not found, defaults: 100 messages per day

USAGE:
    policyd-rate-limit --dsn <dsn> cuser [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -l, --limit <limit>    maximum allowed messages [default: 100]
    -r, --rate <rate>      rate in seconds, limits the messages to be sent in the defined period [default: 86400]

Use a supervisor (immortal) to run policyd-rate-limit, for example to create users if not found and to only allow 3 emails every hour use:

policyd-rate-limit -d mysql://root:test@tcp(localhost)/policyd -s /var/run/policy-rate-limit.sock cuser -l 3 -r 3600

The database schema:

CREATE SCHEMA IF NOT EXISTS `policyd` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

USE policyd;

CREATE TABLE IF NOT EXISTS `ratelimit` (
	`username` VARCHAR(128) NOT NULL COMMENT 'sender address (SASL username)',
	`quota` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'limit',
	`used` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'current recipient counter',
	`rate` INT(10) UNSIGNED DEFAULT '0' COMMENT 'seconds after which the counter gets reset',
	`rdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'datetime when counter was reset',
	PRIMARY KEY (`username`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

Postfix configuration

Add the path of the policy-rate-limit socket to smtpd_sender_restrictions for example:

smtpd_sender_restrictions: check_policy_service { unix:/tmp/policy-rate-limit.sock, default_action=DUNNO }

check the perms of the socket, you may need chmod 666

policyd-rate-limit's People

Contributors

nbari avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

policyd-rate-limit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.