mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:17:08 +00:00
Read user login info from discrete file.
`$DOUGAL_ROOT/etc/users.yaml` to be exact.
This commit is contained in:
@@ -4,7 +4,7 @@ const cfg = require('../../../lib/config');
|
||||
const jwt = require('../../../lib/jwt');
|
||||
|
||||
async function authorisedIP (req, res) {
|
||||
const validIPs = cfg.global.login.ip;
|
||||
const validIPs = cfg._("global.users.login.ip") || {};
|
||||
for (const key in validIPs) {
|
||||
const block = new Netmask(key);
|
||||
if (block.contains(req.ip)) {
|
||||
@@ -19,7 +19,7 @@ async function authorisedIP (req, res) {
|
||||
}
|
||||
|
||||
async function authorisedHost (req, res) {
|
||||
const validHosts = cfg.global.login.host
|
||||
const validHosts = cfg._("global.users.login.host") || {};
|
||||
for (const key in validHosts) {
|
||||
const ip = await dns.promises.resolve(key);
|
||||
if (ip == req.ip) {
|
||||
|
||||
@@ -9,7 +9,7 @@ async function login (req, res, next) {
|
||||
const hash = crypto
|
||||
.pbkdf2Sync(password, 'Dougal'+user, 10712, 48, 'sha512')
|
||||
.toString('base64');
|
||||
for (const credentials of cfg.global.login.user) {
|
||||
for (const credentials of cfg._("global.users.login.user") || []) {
|
||||
if (credentials.name == user && credentials.hash == hash) {
|
||||
const payload = Object.assign({}, credentials);
|
||||
delete payload.hash;
|
||||
|
||||
@@ -6,6 +6,7 @@ const YAML = require('yaml');
|
||||
const cfgPrefix = process.env.DOUGAL_ROOT || ((process.env.HOME || ".") + "/software");
|
||||
const cfgPath = process.env.DOUGAL_API_CONFIG || (cfgPrefix+"/etc/www/config.json");
|
||||
const globalCfgPath = cfgPrefix+"/etc/config.yaml";
|
||||
const usersCfgPath = cfgPrefix+"/etc/users.yaml";
|
||||
|
||||
let config = {}
|
||||
|
||||
@@ -71,6 +72,17 @@ try {
|
||||
config.global = YAML.parse(text);
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.existsSync(usersCfgPath)) {
|
||||
const text = fs.readFileSync(usersCfgPath, 'utf8');
|
||||
if (text) {
|
||||
if (!config.global) {
|
||||
config.global = {};
|
||||
}
|
||||
config.global.users = YAML.parse(text);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user