Skip to content

Commit

Permalink
lint changes, cherry picked from #3135 (#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson authored Dec 24, 2022
1 parent f37d40e commit 5fa95fa
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 116 deletions.
6 changes: 1 addition & 5 deletions dkim.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ class DKIMObject {
}
}
if (!res) return this.result('no key for signature', 'invalid');
for (let record of res) {
// Node 0.11.x compatibility
if (Array.isArray(record)) {
record = record.join('');
}
for (const record of res) {
if (!record.includes('p=')) {
this.debug(`${this.identity}: ignoring TXT record: ${record}`);
continue;
Expand Down
39 changes: 18 additions & 21 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ logger.log = (level, data, logobj) => {
if (level === 'PROTOCOL') {
data = data.replace(/\n/g, '\\n');
}
data = data.replace(/\r/g, '\\r')
.replace(/\n$/, '');
data = data.replace(/\r/g, '\\r').replace(/\n$/, '');

const item = { level, data, obj: logobj};

Expand All @@ -158,18 +157,19 @@ logger.log = (level, data, logobj) => {

logger.log_respond = (retval, msg, data) => {
// any other return code is irrelevant
if (retval !== constants.cont) { return false; }
if (retval !== constants.cont) return false;

let timestamp_string = '';
if (logger.timestamps) {
timestamp_string = `${new Date().toISOString()} `;
}
if (logger.timestamps) timestamp_string = `${new Date().toISOString()} `;

const color = logger.colors[data.level];
if (color && stdout_is_tty) {
process.stdout.write(`${timestamp_string}${logger.colorize(color,data.data)}\n`);
return true;
}
else {
process.stdout.write(`${timestamp_string}${data.data}\n`);
}

process.stdout.write(`${timestamp_string}${data.data}\n`);
return true;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ logger._init_loglevel = function () {
}

logger.would_log = level => {
if (logger.loglevel < level) { return false; }
if (logger.loglevel < level) return false;
return true;
}

Expand All @@ -229,8 +229,7 @@ logger._init_timestamps = function () {
this._init_timestamps();
});

// If we've already been toggled to true by the cfg, we should respect
// this.
// If we've already been toggled to true by the cfg, we should respect this.
this.set_timestamps(logger.timestamps || _timestamps);
}

Expand All @@ -254,9 +253,7 @@ logger.log_if_level = (level, key, plugin) => function () {
// if the object is a connection, add the connection id
if (data instanceof connection.Connection) {
logobj.uuid = data.uuid;
if (data.tran_count > 0) {
logobj.uuid += `.${data.tran_count}`;
}
if (data.tran_count > 0) logobj.uuid += `.${data.tran_count}`;
}
else if (data instanceof plugins.Plugin) {
logobj.origin = data.name;
Expand All @@ -267,10 +264,8 @@ logger.log_if_level = (level, key, plugin) => function () {
else if (data instanceof outbound.HMailItem) {
logobj.origin = 'outbound';
if (data.todo) {
if (data.todo.uuid)
logobj.uuid = data.todo.uuid;
if (data.todo.client_uuid) {
// dirty hack
if (data.todo.uuid) logobj.uuid = data.todo.uuid;
if (data.todo.client_uuid) { // dirty hack
logobj.origin = `outbound] [${data.todo.client_uuid}`;
}
}
Expand All @@ -294,32 +289,34 @@ logger.log_if_level = (level, key, plugin) => function () {
logobj.message += (util.inspect(data));
}
}

switch (logger.format) {
case logger.formats.LOGFMT:
logger.log(
level,
stringify(logobj)
);
return true;
break
case logger.formats.JSON:
logger.log(
level,
JSON.stringify(logobj)
);
return true;
break
case logger.formats.DEFAULT:
default:
logger.log(
level,
`[${logobj.level}] [${logobj.uuid}] [${logobj.origin}] ${logobj.message}`
);
return true;
}
return true;
}

logger.add_log_methods = (object, plugin) => {
if (!object) return;
if (typeof(object) !== 'object') return;

for (const level in logger.levels) {
const fname = `log${level.toLowerCase()}`;
if (object[fname]) continue; // already added
Expand Down
13 changes: 7 additions & 6 deletions plugins/auth/auth_proxy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Proxy AUTH requests selectively by domain

const sock = require('./line_socket');
const utils = require('haraka-utils');
const smtp_regexp = /^([0-9]{3})([ -])(.*)/;

const smtp_regexp = /^(\d{3})([ -])(.*)/;

exports.register = function () {
this.inherits('auth/auth_base');
Expand All @@ -25,8 +27,8 @@ exports.hook_capabilities = (next, connection) => {
}

exports.check_plain_passwd = function (connection, user, passwd, cb) {
let domain;
if ((domain = /@([^@]+)$/.exec(user))) {
let domain = /@([^@]+)$/.exec(user);
if (domain) {
domain = domain[1].toLowerCase();
}
else {
Expand Down Expand Up @@ -82,7 +84,6 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
socket.on('error', err => {
connection.logerror(self, `connection failed to host ${host}: ${err}`);
socket.end();
return;
});
socket.send_command = function (cmd, data) {
let line = cmd + (data ? (` ${data}`) : '');
Expand Down Expand Up @@ -175,8 +176,8 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
}
if (code.startsWith('5')) {
// Initial attempt failed; strip domain and retry.
let u;
if ((u = /^([^@]+)@.+$/.exec(user))) {
const u = /^([^@]+)@.+$/.exec(user)
if (u) {
user = u[1];
if (methods.includes('PLAIN')) {
socket.send_command('AUTH', `PLAIN ${utils.base64(`\0${user}\0${passwd}`)}`);
Expand Down
3 changes: 2 additions & 1 deletion plugins/avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const fs = require('fs');
const path = require('path');

const sock = require('./line_socket');
const smtp_regexp = /^([0-9]{3})([ -])(.*)/;

const smtp_regexp = /^(\d{3})([ -])(.*)/;

exports.register = function () {

Expand Down
23 changes: 12 additions & 11 deletions plugins/clamd.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,19 @@ exports.send_clamd_predata = (socket, cb) => {
}

function clamd_connect (socket, host) {
let match;

if (host.match(/^\//)) {
// assume unix socket
socket.connect(host);
}
else if ((match = /^\[([^\] ]+)\](?::(\d+))?/.exec(host))) {
// IPv6 literal
socket.connect((match[2] || 3310), match[1]);
socket.connect(host); // starts with /, unix socket
return
}
else {
// IP:port, hostname:port or hostname
const hostport = host.split(/:/);
socket.connect((hostport[1] || 3310), hostport[0]);

const match = /^\[([^\] ]+)\](?::(\d+))?/.exec(host);
if (match) {
socket.connect((match[2] || 3310), match[1]); // IPv6 literal
return
}

// IP:port, hostname:port or hostname
const hostport = host.split(/:/);
socket.connect((hostport[1] || 3310), hostport[0]);
}
6 changes: 3 additions & 3 deletions plugins/delay_deny.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exports.hook_deny = function (next, connection, params) {
// fall through
default:
// No delays
return next();
next();
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ exports.hook_rcpt_ok = function (next, connection, rcpt) {
return next(params[0], params[1]);
}
}
return next();
next();
}

exports.hook_data = (next, connection) => {
Expand All @@ -145,5 +145,5 @@ exports.hook_data = (next, connection) => {
}
if (fails.length) transaction.add_header('X-Haraka-Fail-Pre', fails.join(' '));

return next();
next();
}
15 changes: 6 additions & 9 deletions plugins/esets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ const virus_re = new RegExp('virus="([^"]+)"');

exports.hook_data_post = function (next, connection) {
const plugin = this;
const txn = connection.transaction;
const cfg = this.config.get('esets.ini');

// Write message to temporary file
const tmpdir = cfg.main.tmpdir || '/tmp';
const tmpfile = `${tmpdir}/${txn.uuid}.esets`;
const tmpfile = `${tmpdir}/${connection?.transaction?.uuid}.esets`;
const ws = fs.createWriteStream(tmpfile);

ws.once('error', err => {
connection.logerror(plugin, `Error writing temporary file: ${err.message}`);
return next();
next();
});

let start_time;
Expand All @@ -39,10 +38,8 @@ exports.hook_data_post = function (next, connection) {
});

// Get virus name
let virus;
if ((virus = virus_re.exec(stdout))) {
virus = virus[1];
}
let virus = virus_re.exec(stdout)
if (virus) virus = virus[1];

// Log a summary
const exit_code = parseInt((error) ? error.code : 0)
Expand All @@ -60,7 +57,7 @@ exports.hook_data_post = function (next, connection) {
return next(DENYSOFT, 'Virus scanner error');
}
}
return next();
next();
}

ws.once('close', () => {
Expand All @@ -70,5 +67,5 @@ exports.hook_data_post = function (next, connection) {
wsOnClose);
});

txn.message_stream.pipe(ws, { line_endings: '\r\n' });
connection.transaction.message_stream.pipe(ws, { line_endings: '\r\n' });
}
2 changes: 1 addition & 1 deletion plugins/greylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ exports.process_skip_rules = function (connection) {
}
}

return false;
return '';
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
24 changes: 11 additions & 13 deletions plugins/messagesniffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ exports.hook_connect = function (next, connection) {
default:
// Unknown
connection.logerror(this, `Unknown GBUdb range: ${gbudb.range}`);
return next();
next();
}
}
else {
return next();
next();
}
});
}
Expand Down Expand Up @@ -136,7 +136,7 @@ exports.hook_data_post = function (next, connection) {

ws.once('error', err => {
connection.logerror(this, `Error writing temporary file: ${err.message}`);
return next();
next();
});

ws.once('close', () => {
Expand Down Expand Up @@ -338,11 +338,11 @@ exports.hook_disconnect = function (next, connection) {
else {
connection.logdebug(this, `GBUdb bad encounter added for ${connection.remote.ip}`);
}
return next();
next();
});
}
else {
return next();
next();
}
}

Expand All @@ -352,7 +352,7 @@ function SNFClient (req, cb) {
sock.setTimeout(30 * 1000); // Connection timeout
sock.once('timeout', function () {
this.destroy();
return cb(new Error('connection timed out'));
cb(new Error('connection timed out'));
});
sock.once('error', err => cb(err));
sock.once('connect', function () {
Expand All @@ -367,16 +367,14 @@ function SNFClient (req, cb) {
});
sock.once('end', () => {
// Check for result
if (/<result /.exec(result)) return cb(null, result);

let match;
if (/<result /.exec(result)) {
return cb(null, result);
}
else if ((match = /<error message='([^']+)'/.exec(result))) {
if ((match = /<error message='([^']+)'/.exec(result))) {
return cb(new Error(match[1]));
}
else {
return cb(new Error(`unexpected result: ${result}`));
}

cb(new Error(`unexpected result: ${result}`));
});
// Start the sequence
sock.connect(port);
Expand Down
4 changes: 2 additions & 2 deletions plugins/prevent_credential_leaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ exports.hook_data_post = (next, connection) => {

let user = connection.notes.auth_user;
let domain;
let idx;
if ((idx = user.indexOf('@'))) {
const idx = user.indexOf('@')
if (idx) {
// If the username is qualified (e.g. [email protected])
// then we make the @domain.com part optional in the regexp.
domain = user.substr(idx);
Expand Down
Loading

0 comments on commit 5fa95fa

Please sign in to comment.