Skip to content

Commit

Permalink
Merge pull request #3 from haraka/2-enable-flags
Browse files Browse the repository at this point in the history
add enable flags to each limit type
  • Loading branch information
msimerson committed Mar 23, 2017
2 parents 63a8fa6 + 8b5e204 commit f7d4c6c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 25 deletions.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

## 1.0.3 - 2017-03-09

- add `enabled=false` flag for each limit type, defaults to off, matching the docs.


## 1.0.2 - 2017-02-06

- when redis handle goes away, skip processing
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Apply many types of limits to SMTP connections:
- by sender
- max null recipients / period

Each limit type has values that can be defined in limit.ini. The default is empty / disabled until a value has been set.


## Installation

Expand All @@ -29,6 +27,15 @@ npm i haraka-plugin-limit
echo 'limit' >> config/plugins
```

## Configure

Each limit type has values that can be defined in limit.ini. See the default limit.ini in this packages config directory.

Each limit type is disabled until `enabled=true` is set within it's block in limit.ini.

Haraka's config loader loads the defaults from limit.ini within this plugins installed config directory and applies any overrides found in the limit.ini within your Haraka install/config directory.


### [main]

- tarpit_delay = seconds *(optional)*
Expand Down
13 changes: 11 additions & 2 deletions config/limit.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ db=4

; CONNECTION CONCURRENCY LIMITS
[concurrency]
; enabled=false
max=3


Expand All @@ -28,6 +29,7 @@ none=2
; RECIPIENT LIMITS

[recipients]
; enabled=false
; max=20
; max_relaying=100

Expand All @@ -43,17 +45,20 @@ good=50
; UNRECOGNIZED COMMAND LIMITS

[unrecognized_commands]
; max=10
; enabled=false
max=10


; ERRORS COMMAND LIMITS
[errors]
; max=10
; enabled=false
max=10


; CONNECTION RATE LIMITS

[rate_conn]
; enabled=false
; Maximum number of connections from an IP or host over an interval

127=0
Expand All @@ -72,6 +77,7 @@ good=15/1m
; RECIPIENT RATE LIMITS by HOST

[rate_rcpt_host]
; enabled=false
; Maximum number of recipients from an IP or host over an interval

127=0
Expand All @@ -83,6 +89,7 @@ default=50/5m
; RECIPIENT RATE LIMITS by Sender

[rate_rcpt_sender]
; enabled=false
; Maximum number of recipients from a sender over an interval

127=0
Expand All @@ -92,13 +99,15 @@ default=50/5m
; RECIPIENT RATE LIMITS by Recipient

[rate_rcpt]
; enabled=false
; Limit the rate of message attempts over a interval to a recipient

127=0
default=50/5m


[rate_rcpt_null]
; enabled=false
; Limit the number of DSN/MDN messages by recipient

default=1
Expand Down
28 changes: 18 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ exports.register = function () {

plugin.load_limit_ini();

if (plugin.cfg.concurrency) {
if (plugin.cfg.concurrency.enabled) {
plugin.register_hook('connect_init', 'conn_concur_incr');
plugin.register_hook('connect', 'check_concurrency');
plugin.register_hook('disconnect', 'conn_concur_decr');
}

if (plugin.cfg.errors) {
if (plugin.cfg.errors.enabled) {
['helo','ehlo','mail','rcpt','data'].forEach(function (hook) {
plugin.register_hook(hook, 'max_errors');
});
}

if (plugin.cfg.recipients) {
if (plugin.cfg.recipients.enabled) {
plugin.register_hook('rcpt', 'max_recipients');
}

if (plugin.cfg.unrecognized_commands) {
if (plugin.cfg.unrecognized_commands.enabled) {
plugin.register_hook('unrecognized_command', 'max_unrecognized_commands');
}

if (plugin.cfg.rate_conn) {
if (plugin.cfg.rate_conn.enabled) {
plugin.register_hook('connect_init', 'rate_conn_incr');
plugin.register_hook('connect', 'rate_conn_enforce');
}
if (plugin.cfg.rate_rcpt_host) {
if (plugin.cfg.rate_rcpt_host.enabled) {
plugin.register_hook('connect', 'rate_rcpt_host_enforce');
plugin.register_hook('rcpt', 'rate_rcpt_host_incr');
}
if (plugin.cfg.rate_rcpt_sender) {
if (plugin.cfg.rate_rcpt_sender.enabled) {
plugin.register_hook('rcpt', 'rate_rcpt_sender');
}
if (plugin.cfg.rate_rcpt_null) {
if (plugin.cfg.rate_rcpt_null.enabled) {
plugin.register_hook('rcpt', 'rate_rcpt_null');
}
if (plugin.cfg.rate_rcpt) {
if (plugin.cfg.rate_rcpt.enabled) {
plugin.register_hook('rcpt', 'rate_rcpt');
}

Expand All @@ -62,7 +62,15 @@ exports.load_limit_ini = function () {
var plugin = this;
plugin.cfg = plugin.config.get('limit.ini', {
booleans: [
'-outbound.enabled'
'-outbound.enabled',
'-recipients.enabled',
'-unrecognized_commands.enabled',
'-errors.enabled',
'-rate_conn.enabled',
'-rate_rcpt.enabled',
'-rate_rcpt_host.enabled',
'-rate_rcpt_sender.enabled',
'-rate_rcpt_null.enabled',
]
},
function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-limit",
"version": "1.0.2",
"version": "1.0.3",
"description": "enforce various types of limits on remote MTAs",
"main": "limit.js",
"directories": {
Expand Down
20 changes: 10 additions & 10 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ var _set_up = function (done) {
var default_config = {
main: { tarpit_delay: 0 },
outbound: { enabled: false },
recipients: { enabled: false },
unrecognized_commands: { enabled: false },
errors: { enabled: false },
rate_conn: { '127': 0, enabled: false, default: 5 },
rate_rcpt: { '127': 0, enabled: false, default: '50/5m' },
rate_rcpt_host: { '127': 0, enabled: false, default: '50/5m' },
rate_rcpt_sender: { '127': 0, enabled: false, default: '50/5m' },
rate_rcpt_null: { enabled: false, default: 1 },
redis: { db: 4, host: '127.0.0.1', port: '6379' },
concurrency: { plugin: 'karma', good: 10, bad: 1, none: 2 },
recipients: {},
unrecognized_commands: {},
errors: {},
rate_conn: { '127': 0, default: 5 },
rate_rcpt_host: { '127': 0, default: '50/5m' },
rate_rcpt_sender: { '127': 0, default: '50/5m' },
rate_rcpt: { '127': 0, default: '50/5m' },
rate_rcpt_null: { default: 1 }
concurrency: { plugin: 'karma', good: 10, bad: 1, none: 2 }
};

exports.plugin_setup = {
Expand All @@ -41,4 +41,4 @@ exports.plugin_setup = {
test.done();
},

};
};

0 comments on commit f7d4c6c

Please sign in to comment.