Add client.friendlyRemoteAddress() for 'clean' remote IP

This commit is contained in:
Bryan Ashby 2022-06-04 17:39:48 -06:00
parent 0b11e629a6
commit 1ba866f2ca
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
4 changed files with 8 additions and 2 deletions

View File

@ -575,6 +575,11 @@ Client.prototype.isLocal = function() {
return [ '127.0.0.1', '::ffff:127.0.0.1' ].includes(this.remoteAddress); return [ '127.0.0.1', '::ffff:127.0.0.1' ].includes(this.remoteAddress);
}; };
Client.prototype.friendlyRemoteAddress = function() {
// convert any :ffff: IPv4's to 32bit version
return this.remoteAddress.replace(/^::ffff:/, '')
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Default error handlers // Default error handlers
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -113,6 +113,7 @@ function addNewClient(client, clientSock) {
const connInfo = { const connInfo = {
remoteAddress : remoteAddress, remoteAddress : remoteAddress,
freiendlyRemoteAddress: client.friendlyRemoteAddress(),
serverName : client.session.serverName, serverName : client.session.serverName,
isSecure : client.session.isSecure, isSecure : client.session.isSecure,
}; };

View File

@ -121,7 +121,7 @@ const PREDEFINED_MCI_GENERATORS = {
UD : function themeId(client) { return userStatAsString(client, UserProps.ThemeId, ''); }, UD : function themeId(client) { return userStatAsString(client, UserProps.ThemeId, ''); },
UC : function loginCount(client) { return userStatAsCountString(client, UserProps.LoginCount, 0); }, UC : function loginCount(client) { return userStatAsCountString(client, UserProps.LoginCount, 0); },
ND : function connectedNode(client) { return client.node.toString(); }, ND : function connectedNode(client) { return client.node.toString(); },
IP : function clientIpAddress(client) { return client.remoteAddress.replace(/^::ffff:/, ''); }, // convert any :ffff: IPv4's to 32bit version IP : function clientIpAddress(client) { return client.remoteAddress.friendlyRemoteAddress() },
ST : function serverName(client) { return client.session.serverName; }, ST : function serverName(client) { return client.session.serverName; },
FN : function activeFileBaseFilterName(client) { FN : function activeFileBaseFilterName(client) {
const activeFilter = FileBaseFilters.getActiveFilter(client); const activeFilter = FileBaseFilters.getActiveFilter(client);

View File

@ -238,6 +238,6 @@ function transformLoginError(err, client, username) {
err = Errors.BadLogin('To many failed login attempts', ErrorReasons.TooMany); err = Errors.BadLogin('To many failed login attempts', ErrorReasons.TooMany);
} }
client.log.warn( { username, ip : client.remoteAddress, reason : err.message }, `Failed login attempt for user "${username}", ${client.remoteAddress}`); client.log.warn( { username, ip : client.remoteAddress, reason : err.message }, `Failed login attempt for user "${username}", ${client.friendlyRemoteAddress()}`);
return err; return err;
} }