Skip to content

Commit

Permalink
emit a log entry when all DNS lists pass (to show its working)
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Apr 10, 2024
1 parent 4b0424c commit 9b31095
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [1.0.3] - 2024-04-10

- emit a log entry when all DNS lists pass (to show its working)

### [1.0.2] - 2024-04-09

- dep: eslint-plugin-haraka -> @haraka/eslint-config
Expand All @@ -18,4 +22,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
- Initial release

[1.0.1]: https://github.com/haraka/haraka-plugin-dns-list/releases/tag/1.0.1
[1.0.2]: https://github.com/haraka/haraka-plugin-dns-list/releases/tag/1.0.2
[1.0.2]: https://github.com/haraka/haraka-plugin-dns-list/releases/tag/v1.0.2
[1.0.3]: https://github.com/haraka/haraka-plugin-dns-list/releases/tag/v1.0.3
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ exports.register = function () {
this.register_hook('connect', 'onConnect')

// IMPORTANT: don't run this on hook_rcpt otherwise we're an open relay...
;['ehlo', 'helo', 'mail'].forEach((hook) => {
for (const hook of [ 'ehlo', 'helo', 'mail' ]) {
this.register_hook(hook, 'check_dnswl')
})
}
}

exports.load_config = function () {
Expand Down Expand Up @@ -67,12 +67,12 @@ exports.should_skip = function (connection) {
if (!connection) return true

if (connection.remote.is_private) {
connection.logdebug(this, `skip private: ${connection.remote.ip}`)
connection.results.add(this, { skip: `private: ${connection.remote.ip}`, emit: true})
return true
}

if (this.zones.length === 0) {
connection.logerror(this, 'no zones')
connection.results.add(this, { err: `no zones`})
return true
}

Expand All @@ -92,7 +92,6 @@ exports.eachActiveDnsList = async function (connection, zone, nextOnce) {

for (const i of ips) {
if (this.cfg[zone] && this.cfg[zone][i]) {
// console.log(`zone: ${zone} i: ${this.cfg[zone][i]}`)
connection.results.add(this, { msg: this.cfg[zone][i] })
}
}
Expand Down Expand Up @@ -122,15 +121,15 @@ exports.eachActiveDnsList = async function (connection, zone, nextOnce) {
}

exports.onConnect = function (next, connection) {
// console.log(`onConnect`)

const plugin = this
if (this.should_skip(connection)) return next()

let calledNext = false
function nextOnce(code, zones) {
// console.log(`nextOnce: ${code} : ${zones}`)
if (calledNext) return
calledNext = true
connection.results.add(plugin, { emit: true })
if (code === undefined || zones === undefined) return next()
next(
code,
Expand All @@ -140,7 +139,6 @@ exports.onConnect = function (next, connection) {

const promises = []
for (const zone of this.zones) {
// console.log(`promise zone: ${zone}`)
promises.push(this.eachActiveDnsList(connection, zone, nextOnce))
}

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-dns-list",
"version": "1.0.2",
"version": "1.0.3",
"description": "Haraka plugin for DNS lists (DNSBL, DNSWL)",
"main": "index.js",
"files": [
Expand Down

0 comments on commit 9b31095

Please sign in to comment.