Skip to content

Commit

Permalink
changes all logging calls in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Thayer committed Dec 1, 2011
1 parent 6a8aa2e commit 130162b
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 124 deletions.
2 changes: 1 addition & 1 deletion plugins/auth/auth_base.js
Expand Up @@ -158,7 +158,7 @@ exports.auth_cram_md5 = function(next, connection, params) {

var ticket = '<' + hexi(Math.floor(Math.random() * 1000000)) + '.' +
hexi(Date.now()) + '@' + this.config.get('me') + '>';
connection.loginfo("[auth/auth_base] ticket: " + ticket);
connection.loginfo(this, "ticket: " + ticket);
connection.respond(334, base64(ticket));
connection.notes.auth_ticket = ticket;
return next(OK);
Expand Down
26 changes: 13 additions & 13 deletions plugins/auth/auth_proxy.js
Expand Up @@ -22,14 +22,14 @@ exports.check_plain_passwd = function (connection, user, passwd, cb) {
var domain = domain[1].toLowerCase();
} else {
// AUTH user not in user@domain.com format
connection.logerror('[auth/auth_proxy] AUTH user="' + user + '" error="not in required format"');
connection.logerror(this, 'AUTH user="' + user + '" error="not in required format"');
return cb(false);
}

// Check if domain exists in configuration file
var config = this.config.get('auth_proxy.ini');
if (!config.domains[domain]) {
connection.logerror('[auth/auth_proxy] AUTH user="' + user + '" error="domain \'' + domain + '\' is not defined"');
connection.logerror(this, 'AUTH user="' + user + '" error="domain \'' + domain + '\' is not defined"');
return cb(false);
}

Expand All @@ -52,7 +52,7 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {

var hostport = host.split(/:/)
var socket = sock.connect(((hostport[1]) ? hostport[1] : 25), hostport[0]);
connection.logdebug('[auth/auth_proxy] attempting connection to host=' + hostport[0] + ' port=' + ((hostport[1]) ? hostport[1] : 25));
connection.logdebug(self, 'attempting connection to host=' + hostport[0] + ' port=' + ((hostport[1]) ? hostport[1] : 25));
socket.setTimeout(30 * 1000);
socket.on('connect', function () {
});
Expand All @@ -61,40 +61,40 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
// Try next host
return self.try_auth_proxy(connection, hosts, user, passwd, cb);
}
connection.loginfo('[auth/auth_proxy] AUTH user="' + user + '" host="' + host + '" success=' + auth_success);
connection.loginfo(self, 'AUTH user="' + user + '" host="' + host + '" success=' + auth_success);
return cb(auth_success);
});
socket.on('timeout', function () {
connection.logerror("[auth/auth_proxy] connection timed out");
connection.logerror(self, "connection timed out");
socket.end();
// Try next host
return self.try_auth_proxy(connection, hosts, user, passwd, cb);
});
socket.on('error', function (err) {
connection.logerror("[auth/auth_proxy] connection failed to host " + host + ": " + err);
connection.logerror(self, "connection failed to host " + host + ": " + err);
return self.try_auth_proxy(connection, hosts, user, passwd, cb);
});
socket.send_command = function (cmd, data) {
var line = cmd + (data ? (' ' + data) : '');
if (cmd === 'dot') {
line = '.';
}
connection.logprotocol("[auth/auth_proxy] C: " + line);
connection.logprotocol(self, "C: " + line);
command = cmd.toLowerCase();
this.write(line + "\r\n");
// Clear response buffer from previous command
response = [];
};
socket.on('line', function (line) {
var matches;
connection.logprotocol("[auth/auth_proxy] S: " + line);
connection.logprotocol(self, "S: " + line);
if (matches = smtp_regexp.exec(line)) {
var code = matches[1],
cont = matches[2],
rest = matches[3];
response.push(rest);
if (cont === ' ') {
connection.logdebug('[auth/auth_proxy] command state: ' + command);
connection.logdebug(self, 'command state: ' + command);
if (command === 'ehlo') {
if (code.match(/^5/)) {
// EHLO command rejected; we have to abort
Expand All @@ -120,7 +120,7 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
// Parse supported AUTH methods
var parse = /^AUTH (.+)$/.exec(response[i]);
methods = parse[1].split(/\s+/);
connection.logdebug('[auth/auth_proxy] found supported AUTH methods: ' + methods);
connection.logdebug(self, 'found supported AUTH methods: ' + methods);
// Prefer PLAIN as it's easiest
if (methods.indexOf('PLAIN') !== -1) {
socket.send_command('AUTH','PLAIN ' + self.base64("\0" + user + "\0" + passwd));
Expand All @@ -132,7 +132,7 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
}
else {
// No compatible methods; abort...
connection.logdebug('[auth/auth_proxy] no compatible AUTH methods');
connection.logdebug(self, 'no compatible AUTH methods');
socket.send_command('QUIT');
return;
}
Expand Down Expand Up @@ -170,7 +170,7 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
}
if (/^[345]/.test(code)) {
// Got an unhandled error
connection.logdebug('[auth/auth_proxy] error: ' + line);
connection.logdebug(self, 'error: ' + line);
socket.send_command('QUIT');
return;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
}
else {
// Unrecognised response.
connection.logerror("[auth/auth_proxy] unrecognised response: " + line);
connection.logerror(self, "unrecognised response: " + line);
socket.end();
return;
}
Expand Down
8 changes: 5 additions & 3 deletions plugins/block_me.js
Expand Up @@ -19,6 +19,8 @@ exports.hook_data_post = function (next, connection) {

var recip = (this.config.get('block_me.recipient') || '').toLowerCase();
var senders = this.config.get('block_me.senders', 'list');

var self = this;

// Make sure only 1 recipient
if (connection.transaction.rcpt_to.length != 1) {
Expand All @@ -39,11 +41,11 @@ exports.hook_data_post = function (next, connection) {
// Now extract the "From" from the body...
var to_block = extract_from_line(connection.transaction.body);
if (!to_block) {
connection.logerror("[block_me] No sender found in email");
connection.logerror(this, "No sender found in email");
return next();
}

connection.loginfo("[block_me] Blocking new sender: " + to_block);
connection.loginfo(this, "Blocking new sender: " + to_block);

connection.transaction.notes.block_me = 1;

Expand All @@ -55,7 +57,7 @@ exports.hook_data_post = function (next, connection) {
});
}
else {
connection.logerror("[block_me] Unable to append to mail_from.blocklist: " + err);
connection.logerror(self, "Unable to append to mail_from.blocklist: " + err);
}
});

Expand Down
20 changes: 10 additions & 10 deletions plugins/clamd.js
Expand Up @@ -20,7 +20,7 @@ exports.hook_data = function (next, connection) {
var transaction = connection.transaction;
transaction.parse_body = 1;
transaction.attachment_hooks(function (ctype, filename, body) {
connection.logdebug('[clamd] found ctype=' + ctype + ', filename=' + filename);
connection.logdebug(plugin, 'found ctype=' + ctype + ', filename=' + filename);
transaction.notes.clamd_found_attachment = 1;
});
}
Expand All @@ -41,13 +41,13 @@ exports.hook_data_post = function (next, connection) {
if (config.main['only_with_attachments'] &&
!transaction.notes.clamd_found_attachment)
{
connection.logdebug('[clamd] skipping: no attachments found');
connection.logdebug(plugin, 'skipping: no attachments found');
return next();
}

// Limit message size
if (transaction.data_bytes > config.main.max_size) {
connection.logdebug('[clamd] skipping: message too big');
connection.logdebug(plugin, 'skipping: message too big');
return next();
}

Expand Down Expand Up @@ -92,30 +92,30 @@ exports.hook_data_post = function (next, connection) {
};

socket.on('drain', function () {
connection.logdebug('[clamd] drain');
connection.logdebug(plugin, 'drain');
send_data();
});
socket.on('timeout', function () {
connection.logerror("[clamd] connection timed out");
connection.logerror(plugin, "connection timed out");
socket.destroy();
return next(DENYSOFT,'Virus scanner timed out');
});
socket.on('error', function (err) {
connection.logerror("[clamd] connection failed: " + err);
connection.logerror(plugin, "connection failed: " + err);
socket.destroy();
return next(DENYSOFT,'Error connecting to virus scanner');
});
socket.on('connect', function () {
var hp = socket.address();
connection.loginfo('[clamd] connected to host: ' + hp.address + ':' + hp.port);
connection.loginfo(plugin, 'connected to host: ' + hp.address + ':' + hp.port);
socket.write("zINSTREAM\0", function () {
send_data();
});
});

var result = "";
socket.on('line', function (line) {
connection.logprotocol('[clamd] C:' + line);
connection.logprotocol(plugin, 'C:' + line);
result = line.replace(/\r?\n/, '');
});

Expand All @@ -134,13 +134,13 @@ exports.hook_data_post = function (next, connection) {
(virus || 'UNKNOWN'));
}
else if (/size limit exceeded/.test(result)) {
connection.loginfo('[clamd] INSTREAM size limit exceeded. ' +
connection.loginfo(plugin, 'INSTREAM size limit exceeded. ' +
'Check StreamMaxLength in clamd.conf');
// Continue as StreamMaxLength default is 25Mb
return next();
} else {
// Unknown result
connection.logerror('[clamd] unknown result: ' + result);
connection.logerror(plugin, 'unknown result: ' + result);
return next(DENYSOFT, 'Error running virus scanner');
}
return next();
Expand Down
26 changes: 13 additions & 13 deletions plugins/connect.rdns_access.js
Expand Up @@ -28,45 +28,45 @@ exports.rdns_access = function(next, connection) {

// IP whitelist checks
if (connection.remote_ip) {
connection.logdebug('[rdns_access] checking ' + connection.remote_ip +
connection.logdebug(plugin, 'checking ' + connection.remote_ip +
' against connect.rdns_access.whitelist');

if (_in_whitelist(plugin, connection.remote_ip)) {
connection.logdebug("[rdns_access] Allowing " + connection.remote_ip);
if (_in_whitelist(connection, plugin, connection.remote_ip)) {
connection.logdebug(plugin, "Allowing " + connection.remote_ip);
return next();
}
}

// hostname whitelist checks
if (connection.remote_host) {
connection.logdebug('[rdns_access] checking ' + connection.remote_host +
connection.logdebug(plugin, 'checking ' + connection.remote_host +
' against connect.rdns_access.whitelist');

if (_in_whitelist(connection, plugin, connection.remote_host.toLowerCase())) {
connection.logdebug("[rdns_access] Allowing " + connection.remote_host);
connection.logdebug(plugin, "Allowing " + connection.remote_host);
return next();
}
}

// IP blacklist checks
if (connection.remote_ip) {
connection.logdebug('[rdns_access] checking ' + connection.remote_ip +
connection.logdebug(plugin, 'checking ' + connection.remote_ip +
' against connect.rdns_access.blacklist');

if (_in_blacklist(connection, plugin, connection.remote_ip)) {
connection.logdebug("[rdns_access] Rejecting, matched: " + connection.remote_ip);
connection.logdebug(plugin, "Rejecting, matched: " + connection.remote_ip);
return next(DENY, connection.remote_host.toLowerCase() + ' [' +
connection.remote_ip + '] ' + plugin.deny_msg);
}
}

// hostname blacklist checks
if (connection.remote_host) {
connection.logdebug('[rdns_access] checking ' + connection.remote_host +
connection.logdebug(plugin, 'checking ' + connection.remote_host +
' against connect.rdns_access.blacklist');

if (_in_blacklist(connection, plugin, connection.remote_host.toLowerCase())) {
connection.logdebug("[rdns_access] Rejecting, matched: " + connection.remote_host);
connection.logdebug(plugin, "Rejecting, matched: " + connection.remote_host);
return next(DENY, connection.remote_host.toLowerCase() + ' [' +
connection.remote_ip + '] ' + plugin.deny_msg);
}
Expand All @@ -78,15 +78,15 @@ exports.rdns_access = function(next, connection) {
function _in_whitelist(connection, plugin, host) {
var i;
for (i in plugin.wl) {
connection.logdebug('[rdns_access] checking ' + host + ' against ' + plugin.wl[i]);
connection.logdebug(plugin, 'checking ' + host + ' against ' + plugin.wl[i]);

if (plugin.wl[i].toLowerCase() === host) {
return 1;
}
}

if (plugin.wlregex) {
connection.logdebug('[rdns_access] checking ' + host + ' against ' +
connection.logdebug(plugin, 'checking ' + host + ' against ' +
plugin.wlregex.source);

if (host.match(plugin.wlregex)) {
Expand All @@ -100,15 +100,15 @@ function _in_whitelist(connection, plugin, host) {
function _in_blacklist(connection, plugin, host) {
var i;
for (i in plugin.bl) {
connection.logdebug('[rdns_access] checking ' + host + ' against ' + plugin.bl[i]);
connection.logdebug(plugin, 'checking ' + host + ' against ' + plugin.bl[i]);

if (plugin.bl[i].toLowerCase() === host) {
return 1;
}
}

if (plugin.blregex) {
connection.logdebug('[rdns_access] checking ' + host + ' against ' +
connection.logdebug(plugin, 'checking ' + host + ' against ' +
plugin.blregex.source);

if (host.match(plugin.blregex)) {
Expand Down

0 comments on commit 130162b

Please sign in to comment.