Fixed get RTL Conf

pull/1382/head
ShahanaFarooqui 4 weeks ago
parent 244bc706c4
commit a6e028c71c

@ -1,3 +1,4 @@
import jwt from 'jsonwebtoken';
import * as fs from 'fs';
import { sep } from 'path';
import ini from 'ini';
@ -7,6 +8,7 @@ import { Database } from '../../utils/database.js';
import { Logger } from '../../utils/logger.js';
import { Common } from '../../utils/common.js';
import { WSServer } from '../../utils/webSocketServer.js';
import { NodeAuthentication, SSO } from '../../models/config.model.js';
const options = { url: '' };
const logger = Logger;
const common = Common;
@ -72,23 +74,44 @@ export const getRTLConfig = (req, res, next) => {
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
else {
const nodeConfData = JSON.parse(data);
const nodesArr = [];
if (common.nodes && common.nodes.length > 0) {
common.nodes.forEach((node, i) => {
nodesArr.push({
index: node.index,
lnNode: node.lnNode,
lnImplementation: node.lnImplementation,
settings: node.settings,
authentication: req.params.init ? {} : node.authentication
});
});
}
const body = { defaultNodeIndex: nodeConfData.defaultNodeIndex, selectedNodeIndex: (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index),
sso: common.appConfig.sso, enable2FA: !!common.appConfig.rtlSecret2fa, allowPasswordUpdate: common.appConfig.allowPasswordUpdate, nodes: nodesArr };
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'RTL Configuration Received', data: body });
res.status(200).json(body);
const appConfData = JSON.parse(data);
delete appConfData.rtlConfFilePath;
delete appConfData.rtlPass;
delete appConfData.multiPass;
delete appConfData.multiPassHashed;
delete appConfData.rtlSecret2fa;
appConfData.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
appConfData.nodes.map((node) => {
node.authentication = node.Authentication;
node.settings = node.Settings;
delete node.Authentication;
delete node.Settings;
delete node.authentication.macaroonPath;
delete node.authentication.runePath;
delete node.authentication.lnApiPassword;
return node;
});
const token = req.headers.authorization ? req.headers.authorization.split(' ')[1] : '';
jwt.verify(token, common.secret_key, (err, user) => {
if (err) {
// Delete sensitive data for initial response (without security token)
const selNodeIdx = appConfData.nodes.findIndex((node) => node.index === appConfData.selectedNodeIndex) || 0;
appConfData.SSO = new SSO();
appConfData.secret2fa = '';
appConfData.dbDirectoryPath = '';
appConfData.nodes[selNodeIdx].authentication = new NodeAuthentication();
delete appConfData.nodes[selNodeIdx].settings.bitcoindConfigPath;
delete appConfData.nodes[selNodeIdx].settings.lnServerUrl;
delete appConfData.nodes[selNodeIdx].settings.swapServerUrl;
delete appConfData.nodes[selNodeIdx].settings.boltzServerUrl;
delete appConfData.nodes[selNodeIdx].settings.enableOffers;
delete appConfData.nodes[selNodeIdx].settings.enablePeerswap;
delete appConfData.nodes[selNodeIdx].settings.channelBackupPath;
appConfData.nodes = [appConfData.nodes[selNodeIdx]];
}
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'RTL Configuration Received', data: appConfData });
res.status(200).json(appConfData);
});
}
});
};
@ -235,6 +258,7 @@ export const update2FASettings = (req, res, next) => {
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
common.appConfig.rtlSecret2fa = config.secret2fa;
common.appConfig.enable2FA = !!config.secret2fa;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: message });
res.status(201).json({ message: message });
}

@ -48,13 +48,13 @@ export const verifyToken = (twoFAToken) => !!(common.appConfig.rtlSecret2fa && c
export const authenticateUser = (req, res, next) => {
const { authenticateWith, authenticationValue, twoFAToken } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Authenticating User..' });
if (+common.appConfig.sso.rtlSso) {
if (+common.appConfig.SSO.rtlSso) {
if (authenticateWith === 'JWT' && jwt.verify(authenticationValue, common.secret_key)) {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
res.status(406).json({ message: 'SSO Authentication Error', error: 'Login with Password is not allowed with SSO.' });
}
else if (authenticateWith === 'PASSWORD') {
if (common.appConfig.sso.cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.appConfig.sso.cookieValue).digest('hex'), 'utf-8'), Buffer.from(authenticationValue, 'utf-8'))) {
if (common.appConfig.SSO.cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.appConfig.SSO.cookieValue).digest('hex'), 'utf-8'), Buffer.from(authenticationValue, 'utf-8'))) {
common.refreshCookie();
if (!req.session.selectedNode) {
req.session.selectedNode = common.selectedNode;
@ -103,7 +103,7 @@ export const authenticateUser = (req, res, next) => {
export const resetPassword = (req, res, next) => {
const { currPassword, newPassword } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Resetting Password..' });
if (+common.appConfig.sso.rtlSso) {
if (+common.appConfig.SSO.rtlSso) {
const errMsg = 'Password cannot be reset for SSO authentication';
const err = common.handleError({ statusCode: 401, message: 'Password Reset Error', error: errMsg }, 'Authenticate', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error });

@ -52,15 +52,18 @@ export class SSO {
}
}
export class ApplicationConfig {
constructor(defaultNodeIndex, selectedNodeIndex, dbDirectoryPath, rtlConfFilePath, rtlPass, allowPasswordUpdate, rtlSecret2fa, sso, nodes) {
constructor(defaultNodeIndex, selectedNodeIndex, dbDirectoryPath, rtlConfFilePath, rtlPass, multiPass, multiPassHashed, allowPasswordUpdate, enable2FA, rtlSecret2fa, SSO, nodes) {
this.defaultNodeIndex = defaultNodeIndex;
this.selectedNodeIndex = selectedNodeIndex;
this.dbDirectoryPath = dbDirectoryPath;
this.rtlConfFilePath = rtlConfFilePath;
this.rtlPass = rtlPass;
this.multiPass = multiPass;
this.multiPassHashed = multiPassHashed;
this.allowPasswordUpdate = allowPasswordUpdate;
this.enable2FA = enable2FA;
this.rtlSecret2fa = rtlSecret2fa;
this.sso = sso;
this.SSO = SSO;
this.nodes = nodes;
}
}

@ -4,8 +4,8 @@ import { isAuthenticated } from '../../utils/authCheck.js';
import { getRTLConfig, updateNodeSettings, getConfig, getFile, updateSelectedNode, updateApplicationSettings, getCurrencyRates } from '../../controllers/shared/RTLConf.js';
const router = Router();
router.get('/rates', getCurrencyRates);
router.get('/rtlconf', getRTLConfig);
router.get('/file', isAuthenticated, getFile);
router.get('/rtlconf/:init', isAuthenticated, getRTLConfig);
router.get('/updateSelNode/:currNodeIndex/:prevNodeIndex', updateSelectedNode);
router.get('/config/:nodeType', isAuthenticated, getConfig);
router.post('/node', isAuthenticated, updateNodeSettings);

@ -10,7 +10,7 @@ export class CommonService {
this.nodes = [];
this.selectedNode = null;
this.ssoInit = { rtlSso: 0, rtlCookiePath: '', logoutRedirectLink: '', cookieValue: '' };
this.appConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, rtlSecret2fa: '', sso: this.ssoInit, nodes: [] };
this.appConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, enable2FA: false, rtlSecret2fa: '', SSO: this.ssoInit, nodes: [] };
this.port = 3000;
this.host = '';
this.secret_key = crypto.randomBytes(64).toString('hex');
@ -340,10 +340,10 @@ export class CommonService {
});
};
this.readCookie = () => {
const exists = fs.existsSync(this.appConfig.sso.rtlCookiePath);
const exists = fs.existsSync(this.appConfig.SSO.rtlCookiePath);
if (exists) {
try {
this.appConfig.sso.cookieValue = fs.readFileSync(this.appConfig.sso.rtlCookiePath, 'utf-8');
this.appConfig.SSO.cookieValue = fs.readFileSync(this.appConfig.SSO.rtlCookiePath, 'utf-8');
}
catch (err) {
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while reading cookie: \n' + err });
@ -352,10 +352,10 @@ export class CommonService {
}
else {
try {
const directoryName = dirname(this.appConfig.sso.rtlCookiePath);
const directoryName = dirname(this.appConfig.SSO.rtlCookiePath);
this.createDirectory(directoryName);
fs.writeFileSync(this.appConfig.sso.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.sso.cookieValue = fs.readFileSync(this.appConfig.sso.rtlCookiePath, 'utf-8');
fs.writeFileSync(this.appConfig.SSO.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.SSO.cookieValue = fs.readFileSync(this.appConfig.SSO.rtlCookiePath, 'utf-8');
}
catch (err) {
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while reading the cookie: \n' + err });
@ -365,8 +365,8 @@ export class CommonService {
};
this.refreshCookie = () => {
try {
fs.writeFileSync(this.appConfig.sso.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.sso.cookieValue = fs.readFileSync(this.appConfig.sso.rtlCookiePath, 'utf-8');
fs.writeFileSync(this.appConfig.SSO.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.SSO.cookieValue = fs.readFileSync(this.appConfig.SSO.rtlCookiePath, 'utf-8');
}
catch (err) {
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while refreshing cookie', error: err });
@ -473,7 +473,7 @@ export class CommonService {
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'PORT: ' + this.port });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'HOST: ' + this.host });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'DB_DIRECTORY_PATH: ' + this.appConfig.dbDirectoryPath });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'SSO: ' + this.appConfig.sso.rtlSso });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'SSO: ' + this.appConfig.SSO.rtlSso });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'DEFAULT NODE INDEX: ' + selNode.index });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'INDEX: ' + selNode.index });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LN NODE: ' + selNode.lnNode });
@ -481,7 +481,7 @@ export class CommonService {
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'FIAT CONVERSION: ' + selNode.settings.fiatConversion });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'CURRENCY UNIT: ' + selNode.settings.currencyUnit });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LN SERVER URL: ' + selNode.settings.lnServerUrl });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LOGOUT REDIRECT LINK: ' + this.appConfig.sso.logoutRedirectLink + '\r\n' });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LOGOUT REDIRECT LINK: ' + this.appConfig.SSO.logoutRedirectLink + '\r\n' });
}
};
this.filterData = (dataKey, lnImplementation) => {

@ -130,6 +130,7 @@ export class ConfigService {
this.errMsg = this.errMsg + '\nNode Authentication can be set with multiPass only. Please set multiPass in RTL-Config.json';
}
this.common.appConfig.rtlSecret2fa = config.secret2fa;
this.common.appConfig.enable2FA = !!config.secret2fa;
}
else {
if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {
@ -141,7 +142,7 @@ export class ConfigService {
this.common.appConfig.dbDirectoryPath = (process?.env?.DB_DIRECTORY_PATH) ? process?.env?.DB_DIRECTORY_PATH : (config.dbDirectoryPath) ? config.dbDirectoryPath : join(dirname(fileURLToPath(import.meta.url)), '..', '..');
if (config.nodes && config.nodes.length > 0) {
config.nodes.forEach((node, idx) => {
this.common.nodes[idx] = {};
this.common.nodes[idx] = { settings: {}, authentication: {} };
this.common.nodes[idx].index = node.index;
this.common.nodes[idx].lnNode = node.lnNode;
this.common.nodes[idx].lnImplementation = (process?.env?.lnImplementation) ? process?.env?.lnImplementation : node.lnImplementation ? node.lnImplementation : 'LND';
@ -315,28 +316,28 @@ export class ConfigService {
};
this.setSSOParams = (config) => {
if (process?.env?.RTL_SSO) {
this.common.appConfig.sso.rtlSso = +process?.env?.RTL_SSO;
this.common.appConfig.SSO.rtlSso = +process?.env?.RTL_SSO;
}
else if (config.SSO && config.SSO.rtlSSO) {
this.common.appConfig.sso.rtlSso = config.SSO.rtlSSO;
this.common.appConfig.SSO.rtlSso = config.SSO.rtlSSO;
}
if (process?.env?.RTL_COOKIE_PATH) {
this.common.appConfig.sso.rtlCookiePath = process?.env?.RTL_COOKIE_PATH;
this.common.appConfig.SSO.rtlCookiePath = process?.env?.RTL_COOKIE_PATH;
}
else if (config.SSO && config.SSO.rtlCookiePath) {
this.common.appConfig.sso.rtlCookiePath = config.SSO.rtlCookiePath;
this.common.appConfig.SSO.rtlCookiePath = config.SSO.rtlCookiePath;
}
else {
this.common.appConfig.sso.rtlCookiePath = '';
this.common.appConfig.SSO.rtlCookiePath = '';
}
if (process?.env?.LOGOUT_REDIRECT_LINK) {
this.common.appConfig.sso.logoutRedirectLink = process?.env?.LOGOUT_REDIRECT_LINK;
this.common.appConfig.SSO.logoutRedirectLink = process?.env?.LOGOUT_REDIRECT_LINK;
}
else if (config.SSO && config.SSO.logoutRedirectLink) {
this.common.appConfig.sso.logoutRedirectLink = config.SSO.logoutRedirectLink;
this.common.appConfig.SSO.logoutRedirectLink = config.SSO.logoutRedirectLink;
}
if (+this.common.appConfig.sso.rtlSso) {
if (!this.common.appConfig.sso.rtlCookiePath || this.common.appConfig.sso.rtlCookiePath.trim() === '') {
if (+this.common.appConfig.SSO.rtlSso) {
if (!this.common.appConfig.SSO.rtlCookiePath || this.common.appConfig.SSO.rtlCookiePath.trim() === '') {
this.errMsg = 'Please set rtlCookiePath value for single sign on option!';
}
else {

@ -1,3 +1,4 @@
import jwt from 'jsonwebtoken';
import * as fs from 'fs';
import { sep } from 'path';
import ini from 'ini';
@ -7,7 +8,7 @@ import { Database, DatabaseService } from '../../utils/database.js';
import { Logger, LoggerService } from '../../utils/logger.js';
import { Common, CommonService } from '../../utils/common.js';
import { WSServer } from '../../utils/webSocketServer.js';
import { NodeAuthentication, NodeSettings } from '../../models/config.model.js';
import { NodeAuthentication, SSO } from '../../models/config.model.js';
const options = { url: '' };
const logger: LoggerService = Logger;
@ -75,23 +76,44 @@ export const getRTLConfig = (req, res, next) => {
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
} else {
const nodeConfData = JSON.parse(data);
const nodesArr = [];
if (common.nodes && common.nodes.length > 0) {
common.nodes.forEach((node, i) => {
nodesArr.push({
index: node.index,
lnNode: node.lnNode,
lnImplementation: node.lnImplementation,
settings: node.settings,
authentication: req.params.init ? {} : node.authentication
});
});
}
const body = { defaultNodeIndex: nodeConfData.defaultNodeIndex, selectedNodeIndex: (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index),
sso: common.appConfig.sso, enable2FA: !!common.appConfig.rtlSecret2fa, allowPasswordUpdate: common.appConfig.allowPasswordUpdate, nodes: nodesArr };
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'RTL Configuration Received', data: body });
res.status(200).json(body);
const appConfData = JSON.parse(data);
delete appConfData.rtlConfFilePath;
delete appConfData.rtlPass;
delete appConfData.multiPass;
delete appConfData.multiPassHashed;
delete appConfData.rtlSecret2fa;
appConfData.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
appConfData.nodes.map((node) => {
node.authentication = node.Authentication;
node.settings = node.Settings;
delete node.Authentication;
delete node.Settings;
delete node.authentication.macaroonPath;
delete node.authentication.runePath;
delete node.authentication.lnApiPassword;
return node;
});
const token = req.headers.authorization ? req.headers.authorization.split(' ')[1] : '';
jwt.verify(token, common.secret_key, (err, user) => {
if (err) {
// Delete sensitive data for initial response (without security token)
const selNodeIdx = appConfData.nodes.findIndex((node) => node.index === appConfData.selectedNodeIndex) || 0;
appConfData.SSO = new SSO();
appConfData.secret2fa = '';
appConfData.dbDirectoryPath = '';
appConfData.nodes[selNodeIdx].authentication = new NodeAuthentication();
delete appConfData.nodes[selNodeIdx].settings.bitcoindConfigPath;
delete appConfData.nodes[selNodeIdx].settings.lnServerUrl;
delete appConfData.nodes[selNodeIdx].settings.swapServerUrl;
delete appConfData.nodes[selNodeIdx].settings.boltzServerUrl;
delete appConfData.nodes[selNodeIdx].settings.enableOffers;
delete appConfData.nodes[selNodeIdx].settings.enablePeerswap;
delete appConfData.nodes[selNodeIdx].settings.channelBackupPath;
appConfData.nodes = [appConfData.nodes[selNodeIdx]];
}
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'RTL Configuration Received', data: appConfData });
res.status(200).json(appConfData);
});
}
});
};
@ -236,6 +258,7 @@ export const update2FASettings = (req, res, next) => {
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
common.appConfig.rtlSecret2fa = config.secret2fa;
common.appConfig.enable2FA = !!config.secret2fa;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: message });
res.status(201).json({ message: message });
} catch (errRes) {

@ -52,12 +52,12 @@ export const verifyToken = (twoFAToken) => !!(common.appConfig.rtlSecret2fa && c
export const authenticateUser = (req, res, next) => {
const { authenticateWith, authenticationValue, twoFAToken } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Authenticating User..' });
if (+common.appConfig.sso.rtlSso) {
if (+common.appConfig.SSO.rtlSso) {
if (authenticateWith === 'JWT' && jwt.verify(authenticationValue, common.secret_key)) {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
res.status(406).json({ message: 'SSO Authentication Error', error: 'Login with Password is not allowed with SSO.' });
} else if (authenticateWith === 'PASSWORD') {
if (common.appConfig.sso.cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.appConfig.sso.cookieValue).digest('hex'), 'utf-8'), Buffer.from(authenticationValue, 'utf-8'))) {
if (common.appConfig.SSO.cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.appConfig.SSO.cookieValue).digest('hex'), 'utf-8'), Buffer.from(authenticationValue, 'utf-8'))) {
common.refreshCookie();
if (!req.session.selectedNode) { req.session.selectedNode = common.selectedNode; }
const token = jwt.sign({ user: 'SSO_USER' }, common.secret_key);
@ -100,7 +100,7 @@ export const authenticateUser = (req, res, next) => {
export const resetPassword = (req, res, next) => {
const { currPassword, newPassword } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Resetting Password..' });
if (+common.appConfig.sso.rtlSso) {
if (+common.appConfig.SSO.rtlSso) {
const errMsg = 'Password cannot be reset for SSO authentication';
const err = common.handleError({ statusCode: 401, message: 'Password Reset Error', error: errMsg }, 'Authenticate', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error });

@ -55,10 +55,10 @@ export class SelectedNode {
export class SSO {
constructor(
public rtlSso: number,
public rtlCookiePath: string,
public logoutRedirectLink: string,
public cookieValue: string
public rtlSso?: number,
public rtlCookiePath?: string,
public logoutRedirectLink?: string,
public cookieValue?: string
) { }
}
@ -71,9 +71,12 @@ export class ApplicationConfig {
public dbDirectoryPath?: string,
public rtlConfFilePath?: string,
public rtlPass?: string,
public multiPass?: string,
public multiPassHashed?: string,
public allowPasswordUpdate?: boolean,
public enable2FA?: boolean,
public rtlSecret2fa?: string,
public sso?: SSO,
public SSO?: SSO,
public nodes?: SelectedNode[]
) {}

@ -6,8 +6,8 @@ import { getRTLConfig, updateNodeSettings, getConfig, getFile, updateSelectedNod
const router = Router();
router.get('/rates', getCurrencyRates);
router.get('/rtlconf', getRTLConfig);
router.get('/file', isAuthenticated, getFile);
router.get('/rtlconf/:init', isAuthenticated, getRTLConfig);
router.get('/updateSelNode/:currNodeIndex/:prevNodeIndex', updateSelectedNode);
router.get('/config/:nodeType', isAuthenticated, getConfig);
router.post('/node', isAuthenticated, updateNodeSettings);

@ -12,7 +12,7 @@ export class CommonService {
public nodes: SelectedNode[] = [];
public selectedNode: SelectedNode = null;
public ssoInit = { rtlSso: 0, rtlCookiePath: '', logoutRedirectLink: '', cookieValue: '' };
public appConfig: ApplicationConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, rtlSecret2fa: '', sso: this.ssoInit, nodes: [] };
public appConfig: ApplicationConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, enable2FA: false, rtlSecret2fa: '', SSO: this.ssoInit, nodes: [] };
public port = 3000;
public host = '';
public secret_key = crypto.randomBytes(64).toString('hex');
@ -352,20 +352,20 @@ export class CommonService {
};
public readCookie = () => {
const exists = fs.existsSync(this.appConfig.sso.rtlCookiePath);
const exists = fs.existsSync(this.appConfig.SSO.rtlCookiePath);
if (exists) {
try {
this.appConfig.sso.cookieValue = fs.readFileSync(this.appConfig.sso.rtlCookiePath, 'utf-8');
this.appConfig.SSO.cookieValue = fs.readFileSync(this.appConfig.SSO.rtlCookiePath, 'utf-8');
} catch (err) {
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while reading cookie: \n' + err });
throw new Error(err);
}
} else {
try {
const directoryName = dirname(this.appConfig.sso.rtlCookiePath);
const directoryName = dirname(this.appConfig.SSO.rtlCookiePath);
this.createDirectory(directoryName);
fs.writeFileSync(this.appConfig.sso.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.sso.cookieValue = fs.readFileSync(this.appConfig.sso.rtlCookiePath, 'utf-8');
fs.writeFileSync(this.appConfig.SSO.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.SSO.cookieValue = fs.readFileSync(this.appConfig.SSO.rtlCookiePath, 'utf-8');
} catch (err) {
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while reading the cookie: \n' + err });
throw new Error(err);
@ -375,8 +375,8 @@ export class CommonService {
public refreshCookie = () => {
try {
fs.writeFileSync(this.appConfig.sso.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.sso.cookieValue = fs.readFileSync(this.appConfig.sso.rtlCookiePath, 'utf-8');
fs.writeFileSync(this.appConfig.SSO.rtlCookiePath, crypto.randomBytes(64).toString('hex'));
this.appConfig.SSO.cookieValue = fs.readFileSync(this.appConfig.SSO.rtlCookiePath, 'utf-8');
} catch (err) {
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while refreshing cookie', error: err });
throw new Error(err);
@ -481,7 +481,7 @@ export class CommonService {
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'PORT: ' + this.port });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'HOST: ' + this.host });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'DB_DIRECTORY_PATH: ' + this.appConfig.dbDirectoryPath });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'SSO: ' + this.appConfig.sso.rtlSso });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'SSO: ' + this.appConfig.SSO.rtlSso });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'DEFAULT NODE INDEX: ' + selNode.index });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'INDEX: ' + selNode.index });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LN NODE: ' + selNode.lnNode });
@ -489,7 +489,7 @@ export class CommonService {
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'FIAT CONVERSION: ' + selNode.settings.fiatConversion });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'CURRENCY UNIT: ' + selNode.settings.currencyUnit });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LN SERVER URL: ' + selNode.settings.lnServerUrl });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LOGOUT REDIRECT LINK: ' + this.appConfig.sso.logoutRedirectLink + '\r\n' });
this.logger.log({ selectedNode: selNode, level: 'INFO', fileName: 'Config Setup Variable', msg: 'LOGOUT REDIRECT LINK: ' + this.appConfig.SSO.logoutRedirectLink + '\r\n' });
}
};

@ -135,6 +135,7 @@ export class ConfigService {
this.errMsg = this.errMsg + '\nNode Authentication can be set with multiPass only. Please set multiPass in RTL-Config.json';
}
this.common.appConfig.rtlSecret2fa = config.secret2fa;
this.common.appConfig.enable2FA = !!config.secret2fa;
} else {
if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {
this.errMsg = this.errMsg + '\nRTL Password cannot be set with SSO. Please set SSO as 0 or remove password.';
@ -145,7 +146,7 @@ export class ConfigService {
this.common.appConfig.dbDirectoryPath = (process?.env?.DB_DIRECTORY_PATH) ? process?.env?.DB_DIRECTORY_PATH : (config.dbDirectoryPath) ? config.dbDirectoryPath : join(dirname(fileURLToPath(import.meta.url)), '..', '..');
if (config.nodes && config.nodes.length > 0) {
config.nodes.forEach((node, idx) => {
this.common.nodes[idx] = {};
this.common.nodes[idx] = { settings: {}, authentication: {} };
this.common.nodes[idx].index = node.index;
this.common.nodes[idx].lnNode = node.lnNode;
this.common.nodes[idx].lnImplementation = (process?.env?.lnImplementation) ? process?.env?.lnImplementation : node.lnImplementation ? node.lnImplementation : 'LND';
@ -295,27 +296,27 @@ export class ConfigService {
private setSSOParams = (config) => {
if (process?.env?.RTL_SSO) {
this.common.appConfig.sso.rtlSso = +process?.env?.RTL_SSO;
this.common.appConfig.SSO.rtlSso = +process?.env?.RTL_SSO;
} else if (config.SSO && config.SSO.rtlSSO) {
this.common.appConfig.sso.rtlSso = config.SSO.rtlSSO;
this.common.appConfig.SSO.rtlSso = config.SSO.rtlSSO;
}
if (process?.env?.RTL_COOKIE_PATH) {
this.common.appConfig.sso.rtlCookiePath = process?.env?.RTL_COOKIE_PATH;
this.common.appConfig.SSO.rtlCookiePath = process?.env?.RTL_COOKIE_PATH;
} else if (config.SSO && config.SSO.rtlCookiePath) {
this.common.appConfig.sso.rtlCookiePath = config.SSO.rtlCookiePath;
this.common.appConfig.SSO.rtlCookiePath = config.SSO.rtlCookiePath;
} else {
this.common.appConfig.sso.rtlCookiePath = '';
this.common.appConfig.SSO.rtlCookiePath = '';
}
if (process?.env?.LOGOUT_REDIRECT_LINK) {
this.common.appConfig.sso.logoutRedirectLink = process?.env?.LOGOUT_REDIRECT_LINK;
this.common.appConfig.SSO.logoutRedirectLink = process?.env?.LOGOUT_REDIRECT_LINK;
} else if (config.SSO && config.SSO.logoutRedirectLink) {
this.common.appConfig.sso.logoutRedirectLink = config.SSO.logoutRedirectLink;
this.common.appConfig.SSO.logoutRedirectLink = config.SSO.logoutRedirectLink;
}
if (+this.common.appConfig.sso.rtlSso) {
if (!this.common.appConfig.sso.rtlCookiePath || this.common.appConfig.sso.rtlCookiePath.trim() === '') {
if (+this.common.appConfig.SSO.rtlSso) {
if (!this.common.appConfig.SSO.rtlCookiePath || this.common.appConfig.SSO.rtlCookiePath.trim() === '') {
this.errMsg = 'Please set rtlCookiePath value for single sign on option!';
} else {
this.common.readCookie();

@ -212,11 +212,12 @@ export class RTLEffects implements OnDestroy {
}
this.store.dispatch(openSpinner({ payload: UI_MESSAGES.GET_RTL_CONFIG }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'FetchRTLConfig', status: APICallStatusEnum.INITIATED } }));
if (this.sessionService.getItem('token')) {
return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf');
} else {
return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconfinit');
}
return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf');
// if (this.sessionService.getItem('token')) {
// return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf');
// } else {
// return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf/true'); // Initial configuration
// }
}),
map((rtlConfig: RTLConfiguration) => {
this.logger.info(rtlConfig);

Loading…
Cancel
Save