Browse Source

Add PASSWORD_FILE environmental variable support

When a PASSWORD_FILE environmental variable is provided read the
PASSWORD from it instead of using the PASSWORD environmental variable
directly.
pull/407/head
Paweł Jan Czochański 4 years ago
parent
commit
8e850bf2e6
No known key found for this signature in database GPG Key ID: 7D2F3309CC7411FC
  1. 14
      src/config.js
  2. 2
      src/lib/Server.js

14
src/config.js

@ -1,10 +1,22 @@
'use strict'; 'use strict';
const { release } = require('./package.json'); const {release} = require('./package.json');
const fs = require('fs');
module.exports.RELEASE = release; module.exports.RELEASE = release;
module.exports.PORT = process.env.PORT || 51821; module.exports.PORT = process.env.PORT || 51821;
module.exports.PASSWORD = process.env.PASSWORD; module.exports.PASSWORD = process.env.PASSWORD;
// Replace the existing password if a PASSWORD_FILE env variable is present
// if not, then print the error and proceed
if ('PASSWORD_FILE' in process.env && fs.existsSync(process.env.PASSWORD_FILE)) {
try {
module.exports.PASSWORD = fs.readFileSync(process.env.PASSWORD_FILE, 'utf8');
} catch (err) {
console.error('Could not load the PASSWORD_FILE, using the contents of the PASSWORD variable instead');
}
} else if ('PASSWORD_FILE' in process.env && !fs.existsSync(process.env.PASSWORD_FILE)) {
console.error('The declared PASSWORD_FILE does not exist, using the contents of the PASSWORD variable instead')
}
module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/'; module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/';
module.exports.WG_HOST = process.env.WG_HOST; module.exports.WG_HOST = process.env.WG_HOST;
module.exports.WG_PORT = process.env.WG_PORT || 51820; module.exports.WG_PORT = process.env.WG_PORT || 51820;

2
src/lib/Server.js

@ -36,7 +36,7 @@ module.exports = class Server {
// Authentication // Authentication
.get('/api/session', Util.promisify(async req => { .get('/api/session', Util.promisify(async req => {
const requiresPassword = !!process.env.PASSWORD; const requiresPassword = PASSWORD !== undefined;
const authenticated = requiresPassword const authenticated = requiresPassword
? !!(req.session && req.session.authenticated) ? !!(req.session && req.session.authenticated)
: true; : true;

Loading…
Cancel
Save