Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Dec 27, 2023
1 parent 0eb5602 commit 08aa4e3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
125 changes: 63 additions & 62 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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 })
Expand All @@ -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 })
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
1 change: 0 additions & 1 deletion test/dns-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 08aa4e3

Please sign in to comment.