From 08aa4e36e9e0886ef3780ff244b1c391eeb5b2fa Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 27 Dec 2023 14:01:58 -0800 Subject: [PATCH] lint fixes --- index.js | 125 ++++++++++++++++++++++++----------------------- test/dns-list.js | 1 - 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/index.js b/index.js index 051146c..ad7ee42 100644 --- a/index.js +++ b/index.js @@ -9,18 +9,18 @@ let redis_client; exports.register = function () { - this.load_config(); + this.load_config(); - if (this.cfg.main.periodic_checks) { - this.check_zones(this.cfg.main.periodic_checks); - } + if (this.cfg.main.periodic_checks) { + this.check_zones(this.cfg.main.periodic_checks); + } - this.register_hook('connect', 'onConnect'); + this.register_hook('connect', 'onConnect'); - // IMPORTANT: don't run this on hook_rcpt otherwise we're an open relay... - ['ehlo','helo','mail'].forEach(hook => { - this.register_hook(hook, 'check_dnswl'); - }); + // IMPORTANT: don't run this on hook_rcpt otherwise we're an open relay... + ['ehlo','helo','mail'].forEach(hook => { + this.register_hook(hook, 'check_dnswl'); + }); } exports.load_config = function () { @@ -45,12 +45,12 @@ exports.load_config = function () { // Compatibility with old-plugin for (const z in this.config.get('dnsbl.zones', 'list')) { - this.cfg.main.zones.add(z) + this.cfg.main.zones.add(z) } for (const z in this.config.get('dnswl.zones', 'list')) { - this.cfg.main.zones.add(z) - if (this.cfg[z] === undefined) this.cfg[z] = {} - this.cfg[z].type=allow + this.cfg.main.zones.add(z) + if (this.cfg[z] === undefined) this.cfg[z] = {} + this.cfg[z].type='allow' } // active zones @@ -59,19 +59,19 @@ exports.load_config = function () { exports.should_skip = function (connection) { - if (!connection) return true; + if (!connection) return true; - if (connection.remote.is_private) { - connection.logdebug(this, `skip private: ${connection.remote.ip}`); - return true; - } + if (connection.remote.is_private) { + connection.logdebug(this, `skip private: ${connection.remote.ip}`); + return true; + } - if (this.zones.length === 0) { - connection.logerror(this, "no zones"); - return true; - } + if (this.zones.length === 0) { + connection.logerror(this, "no zones"); + return true; + } - return false; + return false; } exports.onConnect = function (next, connection) { @@ -117,7 +117,8 @@ exports.onConnect = function (next, connection) { connection.results.add(plugin, { pass: zone }) return nextOnce(OK, [zone]) case 'karma': - plugin.karmaResults(zone, ips, connection) + plugin.karmaResults(zone, ips, connection, nextOnce) + /* eslint no-fallthrough: 0 */ case 'block': default: connection.results.add(plugin, { fail: zone }) @@ -142,17 +143,17 @@ exports.onConnect = function (next, connection) { }) } -exports.karmaResults = function (zone, ips, connection) { +exports.karmaResults = function (zone, ips, connection, nextOnce) { if (ips.includes('127.0.0.1')) { - connection.results.add(plugin, { pass: zone }) + connection.results.add(this, { pass: zone }) } else if (ips.includes('127.0.0.2')) { - connection.results.add(plugin, { fail: zone }) - if (plugin.cfg.main.search === 'first') nextOnce(DENY, [zone]) + connection.results.add(this, { fail: zone }) + if (this.cfg.main.search === 'first') nextOnce(DENY, [zone]) } else { - connection.results.add(plugin, { msg: zone }) + connection.results.add(this, { msg: zone }) } } @@ -195,8 +196,8 @@ exports.lookup = async function (ip, zone) { if (/spamhaus/.test(zone)) { // https://www.spamhaus.org/news/article/807/using-our-public-mirrors-check-your-return-codes-now if (a?.includes('127.255.255.252') || a?.includes('127.255.255.254') || a?.includes('127.255.255.255')) { - this.disable_zone(zone, a); - return; + this.disable_zone(zone, a); + return; } } @@ -224,36 +225,36 @@ exports.lookup = async function (ip, zone) { } exports.stats_incr_zone = function (err, zone, start) { - if (!this.cfg.stats.enable) return; - - const rkey = `dns-list-stat:${zone}`; - const elapsed = new Date().getTime() - start; - redis_client.hIncrBy(rkey, 'TOTAL', 1); - const foo = (err) ? err.code : 'LISTED'; - redis_client.hIncrBy(rkey, foo, 1); - redis_client.hGet(rkey, 'AVG_RT').then(rt => { - const avg = parseInt(rt) ? (parseInt(elapsed) + parseInt(rt))/2 : parseInt(elapsed); - redis_client.hSet(rkey, 'AVG_RT', avg); - }); + if (!this.cfg.stats.enable) return; + + const rkey = `dns-list-stat:${zone}`; + const elapsed = new Date().getTime() - start; + redis_client.hIncrBy(rkey, 'TOTAL', 1); + const foo = (err) ? err.code : 'LISTED'; + redis_client.hIncrBy(rkey, foo, 1); + redis_client.hGet(rkey, 'AVG_RT').then(rt => { + const avg = parseInt(rt) ? (parseInt(elapsed) + parseInt(rt))/2 : parseInt(elapsed); + redis_client.hSet(rkey, 'AVG_RT', avg); + }); } exports.init_redis = function () { - if (redis_client) return; - - const redis = require('redis'); - const host_port = this.cfg.stats.redis_host.split(':'); - const host = host_port[0] || '127.0.0.1'; - const port = parseInt(host_port[1], 10) || 6379; - - redis_client = redis.createClient(port, host); - redis_client.connect().then(() => { - redis_client.on('error', err => { - this.logerror(`Redis error: ${err}`); - redis_client.quit(); - redis_client = null; // should force a reconnect - // not sure if that's the right thing but better than nothing... - }) + if (redis_client) return; + + const redis = require('redis'); + const host_port = this.cfg.stats.redis_host.split(':'); + const host = host_port[0] || '127.0.0.1'; + const port = parseInt(host_port[1], 10) || 6379; + + redis_client = redis.createClient(port, host); + redis_client.connect().then(() => { + redis_client.on('error', err => { + this.logerror(`Redis error: ${err}`); + redis_client.quit(); + redis_client = null; // should force a reconnect + // not sure if that's the right thing but better than nothing... }) + }) } exports.getListType = function (zone) { @@ -280,7 +281,7 @@ exports.checkZonePositive = async function (zone, ip) { // console.log(`${query} -> ${a}\t${txt}`) for (const e of a) { if (this.cfg[zone][e]) { - // console.log(this.cfg[zone][e]); // + // console.log(this.cfg[zone][e]); // } } return true @@ -336,7 +337,7 @@ exports.check_zone = async function (zone) { if (this.cfg[zone].ipv6 === true) { await this.checkZonePositive(zone, '::FFFF:7F00:2') - await this.checkZoneNegative(zone, '::FFFF:7F00:1') + await this.checkZoneNegative(zone, '::FFFF:7F00:1') } return true @@ -367,8 +368,8 @@ exports.check_zones = async function (interval, done) { } exports.shutdown = function () { - clearInterval(this._interval); - if (redis_client) redis_client.quit(); + clearInterval(this._interval); + if (redis_client) redis_client.quit(); } exports.enable_zone = function (zone, result) { @@ -389,5 +390,5 @@ exports.disable_zone = function (zone, result) { this.logwarn(`disabling ${type} zone '${zone}' ${result ? result : ''}`); this.zones.delete(zone) - return true + return true } diff --git a/test/dns-list.js b/test/dns-list.js index d5675dc..416480d 100644 --- a/test/dns-list.js +++ b/test/dns-list.js @@ -4,7 +4,6 @@ const assert = require('assert') // npm modules const fixtures = require('haraka-test-fixtures') -const mocha = require('mocha') beforeEach(function () { this.plugin = new fixtures.plugin('index')