RTL conf standardization

pull/53/head
ShahanaFarooqui 5 years ago
parent 5151492fee
commit b2229b2e57

@ -7,6 +7,7 @@ common.lnd_config_path = '';
common.node_auth_type = 'DEFAULT'; common.node_auth_type = 'DEFAULT';
common.macaroon_path = ''; common.macaroon_path = '';
common.bitcoind_config_path = ''; common.bitcoind_config_path = '';
common.rtl_pass = '';
common.enable_logging = false; common.enable_logging = false;
common.log_file = ''; common.log_file = '';
common.rtl_sso = 0; common.rtl_sso = 0;

@ -8,26 +8,43 @@ var logger = require('./controllers/logger');
var options = {}; var options = {};
var defaultConfig = { var defaultConfig = {
Authentication: { Authentication: {
lndServerUrl:'https://localhost:8080/v1', macaroonPath: '',
macaroonPath:'', nodeAuthType: 'DEFAULT',
nodeAuthType:'DEFAULT', lndConfigPath: '',
lndConfigPath:'', rtlPass: ''
bitcoindConfigPath: '', },
rtlPass:'', Settings: {
enableLogging: false flgSidenavOpened: true,
}, flgSidenavPinned: true,
Settings: { menu: 'Vertical',
flgSidenavOpened:true, menuType: 'Regular',
flgSidenavPinned:true, theme: 'dark-blue',
menu:'Vertical', satsToBTC: false,
menuType:'Regular', lndServerUrl: 'https://localhost:8080/v1',
theme:'dark-blue', bitcoindConfigPath: '',
satsToBTC:false enableLogging: false,
port: 3000
},
SSO: {
rtlSSO: 0,
rtlCookiePath: '',
logoutRedirectLink: '/login'
}
};
const normalizePort = val => {
var port = parseInt(val, 10);
if (isNaN(port)) {
return val;
} }
if (port >= 0) {
return port;
}
return false;
}; };
var setMacaroonPath = (clArgs, config) => { const setMacaroonPath = (clArgs, config) => {
if(undefined !== clArgs.lndir) { if(undefined !== clArgs.lndir) {
common.macaroon_path = clArgs.lndir; common.macaroon_path = clArgs.lndir;
} else if (undefined !== process.env.MACAROON_PATH) { } else if (undefined !== process.env.MACAROON_PATH) {
@ -41,7 +58,7 @@ var setMacaroonPath = (clArgs, config) => {
} }
} }
var validateConfigFile = (config) => { const validateConfigFile = (config) => {
if(common.macaroon_path === '' || undefined === common.macaroon_path) { if(common.macaroon_path === '' || undefined === common.macaroon_path) {
errMsg = 'Please set macaroon path through environment/RTL.conf!'; errMsg = 'Please set macaroon path through environment/RTL.conf!';
} }
@ -49,10 +66,14 @@ var validateConfigFile = (config) => {
if(undefined !== process.env.LND_SERVER_URL) { if(undefined !== process.env.LND_SERVER_URL) {
common.lnd_server_url = process.env.LND_SERVER_URL; common.lnd_server_url = process.env.LND_SERVER_URL;
} else { } else {
if(config.Authentication.lndServerUrl === '' || undefined === config.Authentication.lndServerUrl) { if((config.Authentication.lndServerUrl === '' || undefined === config.Authentication.lndServerUrl) && (config.Settings.lndServerUrl === '' || undefined === config.Settings.lndServerUrl)) {
errMsg = errMsg + '\nPlease set LND Server URL through environment/RTL.conf!'; errMsg = errMsg + '\nPlease set LND Server URL through environment/RTL.conf!';
} else { } else {
common.lnd_server_url = config.Authentication.lndServerUrl; if (config.Settings.lndServerUrl !== '' && undefined !== config.Settings.lndServerUrl) {
common.lnd_server_url = config.Settings.lndServerUrl;
} else if (config.Authentication.lndServerUrl !== '' && undefined !== config.Authentication.lndServerUrl) {
common.lnd_server_url = config.Authentication.lndServerUrl;
}
} }
} }
@ -81,58 +102,87 @@ var validateConfigFile = (config) => {
if(undefined !== process.env.BITCOIND_CONFIG_PATH) { if(undefined !== process.env.BITCOIND_CONFIG_PATH) {
common.bitcoind_config_path = process.env.BITCOIND_CONFIG_PATH; common.bitcoind_config_path = process.env.BITCOIND_CONFIG_PATH;
} else { } else {
if(config.Authentication.bitcoindConfigPath !== '' || undefined !== config.Authentication.bitcoindConfigPath) { if(config.Settings.bitcoindConfigPath !== '' || undefined !== config.Settings.bitcoindConfigPath) {
common.bitcoind_config_path = config.Settings.bitcoindConfigPath;
} else if(config.Authentication.bitcoindConfigPath !== '' || undefined !== config.Authentication.bitcoindConfigPath) {
common.bitcoind_config_path = config.Authentication.bitcoindConfigPath; common.bitcoind_config_path = config.Authentication.bitcoindConfigPath;
} }
} }
if(upperCase(common.node_auth_type) === 'CUSTOM' && (config.Authentication.rtlPass === '' || undefined === config.Authentication.rtlPass)) { if (undefined !== process.env.RTL_PASS) {
errMsg = errMsg + '\nCustom Node Authentication can be set with RTL password only. Please set RTL Password in RTL.conf'; common.rtl_pass = process.env.RTL_PASS;
} } else if (config.Authentication.rtlPass !== '' || undefined !== config.Authentication.rtlPass) {
common.rtl_pass = config.Authentication.rtlPass;
if(undefined !== config.Authentication.enableLogging) { }
common.enable_logging = config.Authentication.enableLogging;
common.log_file = common.rtl_conf_file_path + '/logs/RTL.log';
let exists = fs.existsSync(common.log_file);
if(exists) {
fs.writeFile(common.log_file, '', () => {});
} else if (!exists && config.Authentication.enableLogging) {
try {
var dirname = path.dirname(common.log_file);
createDirectory(dirname);
var createStream = fs.createWriteStream(common.log_file);
createStream.end();
}
catch(err) {
console.error('Something went wrong, unable to create log file!' + err);
}
}
}
if(errMsg !== '') { if (upperCase(common.node_auth_type) === 'CUSTOM' && (common.rtl_pass === '' || undefined === common.rtl_pass)) {
throw new Error(errMsg); errMsg = errMsg + '\nCustom Node Authentication can be set with RTL password only. Please set RTL Password through environment/RTL.conf';
} }
if (undefined !== process.env.ENABLE_LOGGING) {
common.enable_logging = process.env.ENABLE_LOGGING;
} else if (undefined !== config.Settings.enableLogging) {
common.enable_logging = config.Settings.enableLogging;
} else if (undefined !== config.Authentication.enableLogging) {
common.enable_logging = config.Authentication.enableLogging;
}
if (common.enable_logging) {
common.log_file = common.rtl_conf_file_path + '/logs/RTL.log';
let exists = fs.existsSync(common.log_file);
if (exists) {
fs.writeFile(common.log_file, '', () => { });
} else if (!exists && config.Authentication.enableLogging) {
try {
var dirname = path.dirname(common.log_file);
createDirectory(dirname);
var createStream = fs.createWriteStream(common.log_file);
createStream.end();
}
catch (err) {
console.error('Something went wrong: \n' + err);
}
}
}
if (undefined !== process.env.PORT) {
common.port = normalizePort(process.env.PORT);
} else if (undefined !== config.Settings.port) {
common.port = normalizePort(config.Settings.port);
}
setSSOParams(config);
if (errMsg !== '') {
throw new Error(errMsg);
}
} }
var setSSOParams = () => { const setSSOParams = (config) => {
if(undefined !== process.env.RTL_SSO) { if (undefined !== process.env.RTL_SSO) {
common.rtl_sso = process.env.RTL_SSO; common.rtl_sso = process.env.RTL_SSO;
} else if (undefined !== config.SSO.rtlSSO) {
common.rtl_sso = config.SSO.rtlSSO;
}
if(undefined !== process.env.LOGOUT_REDIRECT_LINK) { if (undefined !== process.env.LOGOUT_REDIRECT_LINK) {
common.logout_redirect_link = process.env.LOGOUT_REDIRECT_LINK; common.logout_redirect_link = process.env.LOGOUT_REDIRECT_LINK;
} } else if (undefined !== config.SSO.logoutRedirectLink) {
common.logout_redirect_link = config.SSO.logoutRedirectLink;
}
if(undefined !== process.env.RTL_COOKIE_PATH) {
common.rtl_cookie_path = process.env.RTL_COOKIE_PATH; if (undefined !== process.env.RTL_COOKIE_PATH) {
} else { common.rtl_cookie_path = process.env.RTL_COOKIE_PATH;
common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie'; } else if (undefined !== config.SSO.rtlCookiePath) {
} common.rtl_cookie_path = config.SSO.rtlCookiePath;
} else {
common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie';
}
if (+common.rtl_sso) {
readCookie(common.rtl_cookie_path); readCookie(common.rtl_cookie_path);
} }
}; };
var createDirectory = (dirname) => { const createDirectory = (dirname) => {
try { try {
fs.mkdirSync(dirname); fs.mkdirSync(dirname);
} catch (err) { } catch (err) {
@ -145,7 +195,7 @@ var createDirectory = (dirname) => {
} }
} }
var readCookie = (cookieFile) => { const readCookie = (cookieFile) => {
let exists = fs.existsSync(cookieFile); let exists = fs.existsSync(cookieFile);
if (exists) { if (exists) {
common.cookie = fs.readFileSync(cookieFile, 'utf-8'); common.cookie = fs.readFileSync(cookieFile, 'utf-8');
@ -157,7 +207,7 @@ var readCookie = (cookieFile) => {
common.cookie = fs.readFileSync(cookieFile, 'utf-8'); common.cookie = fs.readFileSync(cookieFile, 'utf-8');
} }
catch(err) { catch(err) {
console.error('Something went wrong, unable to create cookie file!\n' + err); console.error('Something went wrong: \n' + err);
throw new Error(err); throw new Error(err);
} }
} }
@ -173,7 +223,7 @@ String.random = function (length) {
}, '').substring(-length); }, '').substring(-length);
} }
var setOptions = () => { const setOptions = () => {
var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex'); var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
options = { options = {
url: '', url: '',
@ -186,7 +236,7 @@ var setOptions = () => {
}; };
} }
var logEnvVariables = () => { const logEnvVariables = () => {
if (!common.enable_logging) { if (!common.enable_logging) {
return; return;
} }
@ -203,7 +253,7 @@ var logEnvVariables = () => {
} }
var errMsg = ''; var errMsg = '';
var configFileExists = () => { const configFileExists = () => {
common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname); common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname);
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf'; RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
let exists = fs.existsSync(RTLConfFile); let exists = fs.existsSync(RTLConfFile);
@ -212,7 +262,6 @@ var configFileExists = () => {
setMacaroonPath(clArgs, config) setMacaroonPath(clArgs, config)
validateConfigFile(config); validateConfigFile(config);
setOptions(); setOptions();
setSSOParams();
logEnvVariables(); logEnvVariables();
} else { } else {
try { try {
@ -221,11 +270,10 @@ var configFileExists = () => {
setMacaroonPath(clArgs, config) setMacaroonPath(clArgs, config)
validateConfigFile(config); validateConfigFile(config);
setOptions(); setOptions();
setSSOParams();
logEnvVariables(); logEnvVariables();
} }
catch(err) { catch(err) {
console.error('Something went wrong, unable to create config file!\n' + err); console.error('Something went wrong: \n' + err);
throw new Error(err); throw new Error(err);
} }
} }

@ -3,9 +3,9 @@ var path = require('path');
var fs = require('fs'); var fs = require('fs');
var logger = require('./logger'); var logger = require('./logger');
var common = require('../common'); var common = require('../common');
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
exports.getRTLConfig = (req, res, next) => { exports.getRTLConfig = (req, res, next) => {
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
logger.info('\r\nConf: 7: ' + JSON.stringify(Date.now()) + ': INFO: Getting RTL Config'); logger.info('\r\nConf: 7: ' + JSON.stringify(Date.now()) + ': INFO: Getting RTL Config');
fs.readFile(RTLConfFile, 'utf8', function(err, data) { fs.readFile(RTLConfFile, 'utf8', function(err, data) {
if (err) { if (err) {
@ -29,6 +29,7 @@ exports.getRTLConfig = (req, res, next) => {
}; };
exports.updateUISettings = (req, res, next) => { exports.updateUISettings = (req, res, next) => {
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8')); var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
delete config.Settings; delete config.Settings;
fs.writeFileSync(RTLConfFile, ini.stringify(config)); fs.writeFileSync(RTLConfFile, ini.stringify(config));

@ -22,64 +22,52 @@ exports.authenticateUser = (req, res, next) => {
}); });
} }
} else { } else {
const RTLConfFilePath = common.rtl_conf_file_path + '/RTL.conf'; if(upperCase(common.node_auth_type) === 'CUSTOM') {
fs.readFile(RTLConfFilePath, 'utf8', function (err, data) { if (common.rtl_pass === password) {
if (err) { var rpcUser = 'Custom_User';
logger.error('\r\nAuthenticate: 13: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!'); const token = jwt.sign(
res.status(500).json({ { user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
message: "RTL Config Reading Failed!", 'default_secret_key'
error: err );
}); res.status(200).json({ token: token });
} else { } else {
if(upperCase(common.node_auth_type) === 'CUSTOM') { res.status(401).json({
const rtlPass = ini.parse(data).Authentication.rtlPass; message: "Authentication Failed!",
if (rtlPass === password) { error: "Password Validation Failed!"
var rpcUser = 'Custom_User'; });
const token = jwt.sign( }
{ user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path }, } else {
'default_secret_key' fs.readFile(common.lnd_config_path, 'utf8', function (err, data) {
); if (err) {
res.status(200).json({ token: token }); logger.error('\r\nAuthenticate: 45: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!');
res.status(500).json({
message: "LND Config Reading Failed!",
error: err
});
} else {
const jsonLNDConfig = ini.parse(data);
if (undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcpass']) {
if (jsonLNDConfig.Bitcoind['bitcoind.rpcpass'] === password) {
var rpcUser = (undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcuser']) ? jsonLNDConfig.Bitcoind['bitcoind.rpcuser'] : '';
const token = jwt.sign(
{ user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
'default_secret_key'
);
res.status(200).json({ token: token });
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Validation Failed!"
});
}
} else { } else {
res.status(401).json({ res.status(401).json({
message: "Authentication Failed!", message: "Authentication Failed!",
error: "Password Validation Failed!" error: "Password Not Found In LND Config!"
}); });
} }
} else {
fs.readFile(common.lnd_config_path, 'utf8', function (err, data) {
if (err) {
logger.error('\r\nAuthenticate: 45: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!');
res.status(500).json({
message: "LND Config Reading Failed!",
error: err
});
} else {
const jsonLNDConfig = ini.parse(data);
if (undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcpass']) {
if (jsonLNDConfig.Bitcoind['bitcoind.rpcpass'] === password) {
var rpcUser = (undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcuser']) ? jsonLNDConfig.Bitcoind['bitcoind.rpcuser'] : '';
const token = jwt.sign(
{ user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
'default_secret_key'
);
res.status(200).json({ token: token });
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Validation Failed!"
});
}
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Not Found In LND Config!"
});
}
}
});
} }
} });
}) }
} }
}; };

@ -3,18 +3,6 @@ const common = require("./common");
const debug = require("debug")("node-angular"); const debug = require("debug")("node-angular");
const http = require("http"); const http = require("http");
const normalizePort = val => {
var port = parseInt(val, 10);
if (isNaN(port)) {
return val;
}
if (port >= 0) {
common.port = port;
return port;
}
return false;
};
const onError = error => { const onError = error => {
if (error.syscall !== "listen") { if (error.syscall !== "listen") {
throw error; throw error;
@ -40,15 +28,12 @@ const onError = error => {
const onListening = () => { const onListening = () => {
const addr = server.address(); const addr = server.address();
const bind = typeof addr === "string" ? "pipe " + addr : "port " + port; const bind = typeof addr === "string" ? "pipe " + addr : "port " + common.port;
debug("Listening on " + bind); debug("Listening on " + bind);
console.log('Server is up and running, please open the UI at http://localhost:' + port); console.log('Server is up and running, please open the UI at http://localhost:' + common.port);
}; };
const port = normalizePort(process.env.PORT || common.port);
const server = http.createServer(app); const server = http.createServer(app);
server.on("error", onError); server.on("error", onError);
server.on("listening", onListening); server.on("listening", onListening);
server.listen(port); server.listen(common.port);

@ -1,10 +1,9 @@
[Authentication] [Authentication]
lndServerUrl=https://localhost:8080/v1 macaroonPath=C:\Users\suheb\AppData\Local\Lnd\data\chain\bitcoin\testnet
macroonPath=<macroonPath> nodeAuthType=CUSTOM
nodeAuthType=<DEFAULT/CUSTOM> lndConfigPath=C:\Users\Suheb\AppData\Local\Lnd\lnd.conf
lndConfigPath=<lndConfigPath> rtlPass=xxx
rtlPass=<rtlPass *If nodeAuthType is CUSTOM>
enableLogging=false
[Settings] [Settings]
flgSidenavOpened=true flgSidenavOpened=true
flgSidenavPinned=true flgSidenavPinned=true
@ -12,3 +11,12 @@ menu=Vertical
menuType=Regular menuType=Regular
theme=dark-blue theme=dark-blue
satsToBTC=false satsToBTC=false
bitcoindConfigPath=
enableLogging=true
port=3000
lndServerUrl=https://192.168.1.8:8080/v1
[SSO]
rtlSSO=0
rtlCookiePath=
logoutRedirectLink=/login

Loading…
Cancel
Save