|
|
|
@ -4,10 +4,7 @@ var ini = require('ini');
|
|
|
|
|
var common = require('./common');
|
|
|
|
|
var upperCase = require('upper-case');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var macaroonPath = '';
|
|
|
|
|
var options = {};
|
|
|
|
|
var file_path = path.normalize(__dirname) + '/RTL.conf';
|
|
|
|
|
var log_file_path = path.normalize(__dirname) + '/RTL.log';
|
|
|
|
|
|
|
|
|
|
var defaultConfig = {
|
|
|
|
|
Authentication: {
|
|
|
|
@ -31,53 +28,76 @@ var defaultConfig = {
|
|
|
|
|
|
|
|
|
|
var setMacaroonPath = (clArgs, config) => {
|
|
|
|
|
if(undefined !== clArgs.lndir) {
|
|
|
|
|
macaroonPath = clArgs.lndir;
|
|
|
|
|
common.macaroon_path = clArgs.lndir;
|
|
|
|
|
} else if (undefined !== clArgs.macaroonPath) {
|
|
|
|
|
common.macaroon_path = clArgs.macaroonPath;
|
|
|
|
|
} else {
|
|
|
|
|
if(undefined !== config.Authentication.macroonPath && config.Authentication.macroonPath !== '') {
|
|
|
|
|
macaroonPath = config.Authentication.macroonPath;
|
|
|
|
|
common.macaroon_path = config.Authentication.macroonPath;
|
|
|
|
|
} else if(undefined !== config.Authentication.macaroonPath && config.Authentication.macaroonPath !== '') {
|
|
|
|
|
macaroonPath = config.Authentication.macaroonPath;
|
|
|
|
|
common.macaroon_path = config.Authentication.macaroonPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var validateConfigFile = (macaroonPath, config) => {
|
|
|
|
|
if(macaroonPath === '' || undefined === macaroonPath) {
|
|
|
|
|
errMsg = 'Please set macaroon path in RTL.conf';
|
|
|
|
|
var validateConfigFile = (config) => {
|
|
|
|
|
if(common.macaroon_path === '' || undefined === common.macaroon_path) {
|
|
|
|
|
errMsg = 'Please set macaroon path through environment/RTL.conf!';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(config.Authentication.lndServerUrl === '' || undefined === config.Authentication.lndServerUrl) {
|
|
|
|
|
errMsg = errMsg + '\nPlease set LND Server URL in RTL.conf';
|
|
|
|
|
if(undefined !== clArgs.lndServerUrl) {
|
|
|
|
|
common.lnd_server_url = clArgs.lndServerUrl;
|
|
|
|
|
} else {
|
|
|
|
|
common.lnd_server_url = config.Authentication.lndServerUrl;
|
|
|
|
|
if(config.Authentication.lndServerUrl === '' || undefined === config.Authentication.lndServerUrl) {
|
|
|
|
|
errMsg = errMsg + '\nPlease set LND Server URL through environment/RTL.conf!';
|
|
|
|
|
} else {
|
|
|
|
|
common.lnd_server_url = config.Authentication.lndServerUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(config.Authentication.nodeAuthType === '' || undefined === config.Authentication.nodeAuthType) {
|
|
|
|
|
errMsg = errMsg + '\nPlease set Node Auth Type in RTL.conf';
|
|
|
|
|
|
|
|
|
|
if(undefined !== clArgs.nodeAuthType) {
|
|
|
|
|
common.node_auth_type = clArgs.nodeAuthType;
|
|
|
|
|
} else {
|
|
|
|
|
if(config.Authentication.nodeAuthType === '' || undefined === config.Authentication.nodeAuthType) {
|
|
|
|
|
errMsg = errMsg + '\nPlease set Node Auth Type through environment/RTL.conf!';
|
|
|
|
|
} else {
|
|
|
|
|
common.node_auth_type = config.Authentication.nodeAuthType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(upperCase(config.Authentication.nodeAuthType) === 'DEFAULT' && (config.Authentication.lndConfigPath === '' || undefined === config.Authentication.lndConfigPath)) {
|
|
|
|
|
errMsg = errMsg + '\nDefault Node Authentication can be set with LND Config Path only. Please set LND Config Path in RTL.conf';
|
|
|
|
|
|
|
|
|
|
if(undefined !== clArgs.lndConfigPath) {
|
|
|
|
|
common.lnd_config_path = clArgs.lndConfigPath;
|
|
|
|
|
} else {
|
|
|
|
|
common.lnd_config_path = config.Authentication.lndConfigPath;
|
|
|
|
|
if(config.Authentication.lndConfigPath !== '' && undefined !== config.Authentication.lndConfigPath) {
|
|
|
|
|
common.lnd_config_path = config.Authentication.lndConfigPath;
|
|
|
|
|
} else {
|
|
|
|
|
if(upperCase(common.node_auth_type) === 'DEFAULT') {
|
|
|
|
|
errMsg = errMsg + '\nDefault Node Authentication can be set with LND Config Path only. Please set LND Config Path through environment/RTL.conf!';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(config.Authentication.bitcoindConfigPath !== '' || undefined !== config.Authentication.bitcoindConfigPath) {
|
|
|
|
|
common.bitcoind_config_path = config.Authentication.bitcoindConfigPath;
|
|
|
|
|
if(undefined !== clArgs.bitcoindConfigPath) {
|
|
|
|
|
common.bitcoind_config_path = clArgs.bitcoindConfigPath;
|
|
|
|
|
} else {
|
|
|
|
|
if(config.Authentication.bitcoindConfigPath !== '' || undefined !== config.Authentication.bitcoindConfigPath) {
|
|
|
|
|
common.bitcoind_config_path = config.Authentication.bitcoindConfigPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(upperCase(config.Authentication.nodeAuthType) === 'CUSTOM' && (config.Authentication.rtlPass === '' || undefined === config.Authentication.rtlPass)) {
|
|
|
|
|
if(upperCase(common.node_auth_type) === 'CUSTOM' && (config.Authentication.rtlPass === '' || undefined === config.Authentication.rtlPass)) {
|
|
|
|
|
errMsg = errMsg + '\nCustom Node Authentication can be set with RTL password only. Please set RTL Password in RTL.conf';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(undefined !== config.Authentication.enableLogging) {
|
|
|
|
|
common.enable_logging = config.Authentication.enableLogging;
|
|
|
|
|
let exists = fs.existsSync(log_file_path);
|
|
|
|
|
var logFile = common.rtl_conf_file_path + '/RTL.log';
|
|
|
|
|
let exists = fs.existsSync(logFile);
|
|
|
|
|
if(exists) {
|
|
|
|
|
fs.writeFile(log_file_path, '', () => {});
|
|
|
|
|
fs.writeFile(logFile, '', () => {});
|
|
|
|
|
} else if (!exists && config.Authentication.enableLogging) {
|
|
|
|
|
try {
|
|
|
|
|
var createStream = fs.createWriteStream(log_file_path);
|
|
|
|
|
var createStream = fs.createWriteStream(logFile);
|
|
|
|
|
createStream.end();
|
|
|
|
|
}
|
|
|
|
|
catch(err) {
|
|
|
|
@ -91,8 +111,8 @@ var validateConfigFile = (macaroonPath, config) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var setOptions = (macaroonPath) => {
|
|
|
|
|
var macaroon = fs.readFileSync(macaroonPath + '/admin.macaroon').toString('hex');
|
|
|
|
|
var setOptions = () => {
|
|
|
|
|
var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
|
|
|
|
|
options = {
|
|
|
|
|
url: '',
|
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
@ -106,22 +126,25 @@ var setOptions = (macaroonPath) => {
|
|
|
|
|
|
|
|
|
|
var errMsg = '';
|
|
|
|
|
var configFileExists = () => {
|
|
|
|
|
let exists = fs.existsSync(file_path);
|
|
|
|
|
common.rtl_conf_file_path = (undefined !== clArgs.rtlConfFilePath) ? clArgs.rtlConfFilePath : path.normalize(__dirname);
|
|
|
|
|
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
|
|
|
|
let exists = fs.existsSync(RTLConfFile);
|
|
|
|
|
if (exists) {
|
|
|
|
|
var config = ini.parse(fs.readFileSync(file_path, 'utf-8'));
|
|
|
|
|
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
|
setMacaroonPath(clArgs, config)
|
|
|
|
|
validateConfigFile(macaroonPath, config);
|
|
|
|
|
setOptions(macaroonPath);
|
|
|
|
|
validateConfigFile(config);
|
|
|
|
|
setOptions();
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
fs.writeFileSync(file_path, ini.stringify(defaultConfig));
|
|
|
|
|
var config = ini.parse(fs.readFileSync(file_path, 'utf-8'));
|
|
|
|
|
fs.writeFileSync(RTLConfFile, ini.stringify(defaultConfig));
|
|
|
|
|
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
|
setMacaroonPath(clArgs, config)
|
|
|
|
|
validateConfigFile(macaroonPath, config);
|
|
|
|
|
setOptions(macaroonPath);
|
|
|
|
|
validateConfigFile(config);
|
|
|
|
|
setOptions();
|
|
|
|
|
}
|
|
|
|
|
catch(err) {
|
|
|
|
|
console.error('Something went wrong, unable to create config file!' + err);
|
|
|
|
|
console.error('Something went wrong, unable to create config file!\n' + err);
|
|
|
|
|
throw new Error(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|