Commit 12a90d09 authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

Make it getConfig

parent 0cd54219
......@@ -31,13 +31,13 @@ const OPENVPN_SETTINGS_FILE_PATH = path.join(baseDir, 'openvpn.conf');
console.log(`Using app config file at ${CONFIG_FILE_PATH}`);
console.log(`Using OpenVPN settings file at ${OPENVPN_SETTINGS_FILE_PATH}`);
function reloadConfig() {
function getConfig() {
let config = {};
try {
config = ini.parse(fs.readFileSync(CONFIG_FILE_PATH, 'utf-8'));
} catch (e) {
console.log('No config file found, creating empty one');
fs.writeFileSync(CONFIG_FILE_PATH, '[roles]\n#admins=username1,username2\n');
fs.writeFileSync(CONFIG_FILE_PATH, '[roles]\n# Restart the app and re-login for role change to take effect\n#admins=username1,username2\n');
}
config.roles = config.roles || {};
config.roles.admins = config.roles.admins || '';
......@@ -46,8 +46,6 @@ function reloadConfig() {
return config;
}
let config = reloadConfig();
// This only fetches the settings supported by the UI
function getOpenVPNSetting() {
let settings = {};
......@@ -157,7 +155,7 @@ router.post('/api/login', jsonParser, (req, res, next) => {
ldap.auth(req.body.username, req.body.password)
.then(profile => {
// on login check for new roles
config = reloadConfig();
const config = getConfig();
profile.isAdmin = config.roles.admins.indexOf(profile.username) !== -1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment