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
No known key found for this signature in database
GPG Key ID: 7D2F3309CC7411FC
2 changed files with
14 additions and
2 deletions
-
src/config.js
-
src/lib/Server.js
|
|
|
@ -1,10 +1,22 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
const { release } = require('./package.json'); |
|
|
|
const {release} = require('./package.json'); |
|
|
|
const fs = require('fs'); |
|
|
|
|
|
|
|
module.exports.RELEASE = release; |
|
|
|
module.exports.PORT = process.env.PORT || 51821; |
|
|
|
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_HOST = process.env.WG_HOST; |
|
|
|
module.exports.WG_PORT = process.env.WG_PORT || 51820; |
|
|
|
|
|
|
|
@ -36,7 +36,7 @@ module.exports = class Server { |
|
|
|
|
|
|
|
// Authentication
|
|
|
|
.get('/api/session', Util.promisify(async req => { |
|
|
|
const requiresPassword = !!process.env.PASSWORD; |
|
|
|
const requiresPassword = PASSWORD !== undefined; |
|
|
|
const authenticated = requiresPassword |
|
|
|
? !!(req.session && req.session.authenticated) |
|
|
|
: true; |
|
|
|
|