mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 15:19:44 +02:00
feat: Modify logger to log to file that supports fail2ban (#284)
This commit is contained in:
parent
21ef850913
commit
6429e22d59
12 changed files with 427 additions and 7844 deletions
27
server/utils/remoteAddress.js
Normal file
27
server/utils/remoteAddress.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* The IP address of the client that just made a request to this application, whether
|
||||
* or not the TRUST_PROXY env variable is true and if endpoint accessed through a proxy.
|
||||
* @param {Request} request The endpoint Request object
|
||||
* @returns The IP address of the client that just made a request
|
||||
*/
|
||||
const getRemoteAddress = (request) => {
|
||||
let remoteAddress = request.ip;
|
||||
|
||||
// Assert if "X-Forwarded-For" header contains any addresses
|
||||
if (process.env.TRUST_PROXY && !_.isEmpty(request.ips)) {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
remoteAddress = request.ips[0];
|
||||
}
|
||||
|
||||
// Convert address from IPV6 to IPV4 if client device is IPV4.
|
||||
const defaultIPV6Regex = /^::ffff:((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/g;
|
||||
if (remoteAddress.match(defaultIPV6Regex)) {
|
||||
remoteAddress = remoteAddress.replace('::ffff:', '');
|
||||
}
|
||||
|
||||
return remoteAddress;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getRemoteAddress,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue