2019-01-01 16:26:51 +00:00
|
|
|
var ini = require('ini');
|
|
|
|
var fs = require('fs');
|
2019-01-13 22:55:25 +00:00
|
|
|
var logger = require('./logger');
|
2019-01-19 03:04:16 +00:00
|
|
|
var common = require('../common');
|
2019-12-13 04:01:04 +00:00
|
|
|
var request = require('request-promise');
|
|
|
|
var options = {};
|
2019-01-01 16:26:51 +00:00
|
|
|
|
2019-04-07 00:20:40 +00:00
|
|
|
exports.updateSelectedNode = (req, res, next) => {
|
2019-04-07 20:50:51 +00:00
|
|
|
const selNodeIndex = req.body.selNodeIndex;
|
2019-04-07 00:20:40 +00:00
|
|
|
common.selectedNode = common.findNode(selNodeIndex);
|
2020-01-21 22:04:26 +00:00
|
|
|
const responseVal = common.selectedNode && common.selectedNode.ln_node ? common.selectedNode.ln_node : '';
|
2019-09-17 01:17:28 +00:00
|
|
|
logger.info({fileName: 'RTLConf', msg: 'Selected Node Updated To: ' + JSON.stringify(responseVal)});
|
|
|
|
res.status(200).json({status: 'Selected Node Updated To: ' + JSON.stringify(responseVal) + '!'});
|
2019-04-07 00:20:40 +00:00
|
|
|
};
|
|
|
|
|
2019-01-16 01:05:01 +00:00
|
|
|
exports.getRTLConfig = (req, res, next) => {
|
2020-01-20 16:15:04 +00:00
|
|
|
var confFile = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
|
|
|
logger.info({fileName: 'RTLConf', msg: 'Getting Node Config'});
|
|
|
|
fs.readFile(confFile, 'utf8', function(err, data) {
|
|
|
|
if (err) {
|
|
|
|
if (err.code === 'ENOENT') {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'RTLConf', lineNum: 22, msg: 'Node config does not exist!'});
|
2020-01-20 16:15:04 +00:00
|
|
|
res.status(200).json({ defaultNodeIndex: 0, selectedNodeIndex: 0, sso: {}, nodes: [] });
|
|
|
|
} else {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'RTLConf', lineNum: 25, msg: 'Getting Node Config Failed!'});
|
2019-04-06 03:40:18 +00:00
|
|
|
res.status(500).json({
|
2020-01-20 16:15:04 +00:00
|
|
|
message: "Reading Node Config Failed!",
|
2019-04-06 03:40:18 +00:00
|
|
|
error: err
|
|
|
|
});
|
|
|
|
}
|
2020-01-20 16:15:04 +00:00
|
|
|
} else {
|
|
|
|
const nodeConfData = JSON.parse(data);
|
|
|
|
const sso = { rtlSSO: common.rtl_sso, logoutRedirectLink: common.logout_redirect_link };
|
2020-03-19 01:48:53 +00:00
|
|
|
const enable2FA = !common.rtl_secret2fa ? false : true;
|
2020-01-20 16:15:04 +00:00
|
|
|
var nodesArr = [];
|
2020-01-21 22:04:26 +00:00
|
|
|
if (common.nodes && common.nodes.length > 0) {
|
|
|
|
common.nodes.forEach((node, i) => {
|
2020-01-20 16:15:04 +00:00
|
|
|
const authentication = {};
|
2020-01-21 22:04:26 +00:00
|
|
|
if(node.config_path) {
|
|
|
|
authentication.configPath = node.config_path;
|
2020-01-20 16:15:04 +00:00
|
|
|
} else {
|
|
|
|
authentication.configPath = '';
|
|
|
|
}
|
2020-01-21 22:04:26 +00:00
|
|
|
const settings = {};
|
|
|
|
settings.userPersona = node.user_persona ? node.user_persona : 'MERCHANT';
|
|
|
|
settings.themeMode = (node.theme_mode) ? node.theme_mode : 'DAY';
|
|
|
|
settings.themeColor = (node.theme_color) ? node.theme_color : 'PURPLE';
|
|
|
|
settings.fiatConversion = (node.fiat_conversion) ? !!node.fiat_conversion : false;
|
|
|
|
settings.bitcoindConfigPath = node.bitcoind_config_path;
|
|
|
|
settings.enableLogging = node.enable_logging ? !!node.enable_logging : false;
|
|
|
|
settings.lnServerUrl = node.ln_server_url;
|
2020-03-16 15:57:57 +00:00
|
|
|
settings.swapServerUrl = node.swap_server_url;
|
2020-01-21 22:04:26 +00:00
|
|
|
settings.channelBackupPath = node.channel_backup_path;
|
|
|
|
settings.currencyUnit = node.currency_unit;
|
2020-01-20 16:15:04 +00:00
|
|
|
nodesArr.push({
|
|
|
|
index: node.index,
|
2020-01-21 22:04:26 +00:00
|
|
|
lnNode: node.ln_node,
|
|
|
|
lnImplementation: node.ln_implementation,
|
|
|
|
settings: settings,
|
2020-01-20 16:15:04 +00:00
|
|
|
authentication: authentication})
|
|
|
|
});
|
2019-04-06 03:40:18 +00:00
|
|
|
}
|
2020-03-19 01:48:53 +00:00
|
|
|
res.status(200).json({ defaultNodeIndex: nodeConfData.defaultNodeIndex, selectedNodeIndex: common.selectedNode.index, sso: sso, enable2FA: enable2FA, nodes: nodesArr });
|
2020-01-20 16:15:04 +00:00
|
|
|
}
|
|
|
|
});
|
2019-01-01 16:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.updateUISettings = (req, res, next) => {
|
2020-01-20 16:15:04 +00:00
|
|
|
var RTLConfFile = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
|
|
|
var config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
config.nodes.find(node => {
|
|
|
|
if(node.index == common.selectedNode.index) {
|
|
|
|
node.Settings.userPersona = req.body.updatedSettings.userPersona;
|
|
|
|
node.Settings.themeMode = req.body.updatedSettings.themeMode;
|
|
|
|
node.Settings.themeColor = req.body.updatedSettings.themeColor;
|
|
|
|
node.Settings.fiatConversion = req.body.updatedSettings.fiatConversion;
|
|
|
|
if(req.body.updatedSettings.fiatConversion) {
|
|
|
|
node.Settings.currencyUnit = req.body.updatedSettings.currencyUnit ? req.body.updatedSettings.currencyUnit : 'USD';
|
2019-04-06 22:42:09 +00:00
|
|
|
} else {
|
2020-01-20 16:15:04 +00:00
|
|
|
delete node.Settings.currencyUnit;
|
2019-04-06 22:42:09 +00:00
|
|
|
}
|
2020-01-22 02:29:16 +00:00
|
|
|
const selectedNode = common.findNode(common.selectedNode.index);
|
|
|
|
selectedNode.user_persona = req.body.updatedSettings.userPersona;
|
|
|
|
selectedNode.theme_mode = req.body.updatedSettings.themeMode;
|
|
|
|
selectedNode.theme_color = req.body.updatedSettings.themeColor;
|
|
|
|
selectedNode.fiat_conversion = req.body.updatedSettings.fiatConversion;
|
|
|
|
if(req.body.updatedSettings.fiatConversion) {
|
|
|
|
selectedNode.currency_unit = req.body.updatedSettings.currencyUnit ? req.body.updatedSettings.currencyUnit : 'USD';
|
|
|
|
} else {
|
|
|
|
delete selectedNode.currency_unit;
|
|
|
|
}
|
|
|
|
common.replaceNode(common.selectedNode.index, selectedNode);
|
2020-01-20 16:15:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
|
|
|
logger.info({fileName: 'RTLConf', msg: 'Updating Application Node Settings Succesful!'});
|
|
|
|
res.status(201).json({message: 'Application Node Settings Updated Successfully'});
|
|
|
|
}
|
|
|
|
catch (err) {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'Conf', lineNum: 101, msg: 'Updating Application Node Settings Failed!'});
|
2020-01-20 16:15:04 +00:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Updating Application Node Settings Failed!",
|
|
|
|
error: 'Updating Application Node Settings Failed!'
|
2019-04-06 22:42:09 +00:00
|
|
|
});
|
|
|
|
}
|
2019-01-01 16:26:51 +00:00
|
|
|
};
|
|
|
|
|
2020-03-19 01:48:53 +00:00
|
|
|
exports.update2FASettings = (req, res, next) => {
|
|
|
|
var RTLConfFile = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
|
|
|
var config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
config.secret2fa = req.body.secret2fa;
|
|
|
|
let message = req.body.secret2fa.trim() === '' ? 'Two factor authentication disabled sucessfully.' : 'Two factor authentication enabled sucessfully.';
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
|
|
|
common.rtl_secret2fa = config.secret2fa;
|
|
|
|
logger.info({fileName: 'RTLConf', msg: message});
|
|
|
|
res.status(201).json({message: message});
|
|
|
|
}
|
|
|
|
catch (err) {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'Conf', lineNum: 121, msg: 'Updating 2FA Settings Failed!'});
|
2020-03-19 01:48:53 +00:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Updating 2FA Settings Failed!",
|
|
|
|
error: 'Updating 2FA Settings Failed!'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-15 05:58:00 +00:00
|
|
|
exports.updateDefaultNode = (req, res, next) => {
|
2020-01-20 16:15:04 +00:00
|
|
|
RTLConfFile = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
2019-11-15 05:58:00 +00:00
|
|
|
var config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
config.defaultNodeIndex = req.body.defaultNodeIndex;
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
|
|
|
logger.info({fileName: 'RTLConf', msg: 'Updating Default Node Succesful!'});
|
|
|
|
res.status(201).json({message: 'Default Node Updated Successfully'});
|
|
|
|
}
|
|
|
|
catch (err) {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'Conf', lineNum: 139, msg: 'Updating Default Node Failed!'});
|
2019-11-15 05:58:00 +00:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Updating Default Node Failed!",
|
|
|
|
error: 'Updating Default Node Failed!'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-19 03:04:16 +00:00
|
|
|
exports.getConfig = (req, res, next) => {
|
2019-02-12 23:13:09 +00:00
|
|
|
let confFile = '';
|
2019-04-06 22:42:09 +00:00
|
|
|
let JSONFormat = false;
|
2019-01-19 03:04:16 +00:00
|
|
|
switch (req.params.nodeType) {
|
2019-09-02 04:11:37 +00:00
|
|
|
case 'ln':
|
2019-04-06 22:42:09 +00:00
|
|
|
JSONFormat = false;
|
2019-09-02 04:11:37 +00:00
|
|
|
confFile = common.selectedNode.config_path;
|
2019-01-19 03:04:16 +00:00
|
|
|
break;
|
|
|
|
case 'bitcoind':
|
2019-04-06 22:42:09 +00:00
|
|
|
JSONFormat = false;
|
2019-04-12 01:11:49 +00:00
|
|
|
confFile = common.selectedNode.bitcoind_config_path;
|
2019-01-19 03:04:16 +00:00
|
|
|
break;
|
|
|
|
case 'rtl':
|
2020-01-20 16:15:04 +00:00
|
|
|
JSONFormat = true;
|
|
|
|
confFile = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
2019-01-19 03:04:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-04-06 22:42:09 +00:00
|
|
|
JSONFormat = false;
|
2019-02-12 23:13:09 +00:00
|
|
|
confFile = '';
|
2019-01-19 03:04:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-27 18:20:17 +00:00
|
|
|
logger.info({fileName: 'RTLConf', msg: 'Node Type: ' + req.params.nodeType + ', File Path: ' + confFile});
|
2019-02-12 23:13:09 +00:00
|
|
|
fs.readFile(confFile, 'utf8', function(err, data) {
|
2019-01-01 16:26:51 +00:00
|
|
|
if (err) {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'Conf', lineNum: 171, msg: 'Reading Conf Failed!'});
|
2019-01-01 16:26:51 +00:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Reading Config File Failed!",
|
|
|
|
error: err
|
|
|
|
});
|
|
|
|
} else {
|
2019-04-06 22:42:09 +00:00
|
|
|
const jsonConfig = (JSONFormat) ? JSON.parse(data) : ini.parse(data);
|
2020-01-17 18:45:01 +00:00
|
|
|
if (jsonConfig.Bitcoind && jsonConfig.Bitcoind['bitcoind.rpcpass']) {
|
2019-01-01 16:26:51 +00:00
|
|
|
jsonConfig.Bitcoind['bitcoind.rpcpass'] = jsonConfig.Bitcoind['bitcoind.rpcpass'].replace(/./g, '*');
|
|
|
|
}
|
2020-01-17 18:45:01 +00:00
|
|
|
if (jsonConfig['bitcoind.rpcpass']) {
|
2019-04-06 22:42:09 +00:00
|
|
|
jsonConfig['bitcoind.rpcpass'] = jsonConfig['bitcoind.rpcpass'].replace(/./g, '*');
|
|
|
|
}
|
2020-01-17 18:45:01 +00:00
|
|
|
if (jsonConfig['rpcpassword']) {
|
2019-04-06 22:42:09 +00:00
|
|
|
jsonConfig['rpcpassword'] = jsonConfig['rpcpassword'].replace(/./g, '*');
|
|
|
|
}
|
2020-07-07 17:57:15 +00:00
|
|
|
if (jsonConfig['eclair.api.password']) {
|
|
|
|
jsonConfig['eclair.api.password'] = jsonConfig['eclair.api.password'].replace(/./g, '*');
|
|
|
|
}
|
|
|
|
if (jsonConfig['eclair.bitcoind.rpcpassword']) {
|
|
|
|
jsonConfig['eclair.bitcoind.rpcpassword'] = jsonConfig['eclair.bitcoind.rpcpassword'].replace(/./g, '*');
|
|
|
|
}
|
2020-01-17 18:45:01 +00:00
|
|
|
if (jsonConfig.multiPass) {
|
2019-04-06 22:42:09 +00:00
|
|
|
jsonConfig.multiPass = jsonConfig.multiPass.replace(/./g, '*');
|
|
|
|
}
|
|
|
|
const responseJSON = (JSONFormat) ? jsonConfig : ini.stringify(jsonConfig);
|
|
|
|
res.status(200).json({format: (JSONFormat) ? 'JSON' : 'INI', data: responseJSON});
|
2019-01-01 16:26:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-12-13 04:01:04 +00:00
|
|
|
|
2020-07-07 17:57:15 +00:00
|
|
|
exports.getFile = (req, res, next) => {
|
|
|
|
let file = req.query.path ? req.query.path : (common.selectedNode.channel_backup_path + common.path_separator + 'channel-' + req.query.channel.replace(':', '-') + '.bak');
|
|
|
|
logger.info({fileName: 'Conf', msg: 'Channel Point: ' + req.query.channel + ', File Path: ' + file});
|
|
|
|
fs.readFile(file, 'utf8', function(err, data) {
|
|
|
|
if (err) {
|
|
|
|
logger.error({fileName: 'Conf', lineNum: 207, msg: 'Reading File Failed!'});
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Reading File Failed!",
|
|
|
|
error: err
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
logger.info({fileName: 'Conf', msg: 'File Data: ' + data});
|
|
|
|
res.status(200).json(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-12-13 04:01:04 +00:00
|
|
|
exports.getCurrencyRates = (req, res, next) => {
|
|
|
|
options.url = 'https://blockchain.info/ticker';
|
|
|
|
request(options).then((body) => {
|
2020-03-10 17:25:52 +00:00
|
|
|
if(!body || body.error) {
|
2019-12-13 04:01:04 +00:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Fetching Rates Failed!",
|
2020-03-10 17:25:52 +00:00
|
|
|
error: (!body) ? 'Error From External Server!' : body.error
|
2019-12-13 04:01:04 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.status(200).json(body);
|
2019-12-23 03:07:50 +00:00
|
|
|
body = JSON.parse(body);
|
2019-12-13 04:01:04 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
2020-05-03 19:52:38 +00:00
|
|
|
logger.error({fileName: 'Conf', lineNum: 210, msg: 'Fetching Rates Failed! ' + JSON.stringify(err)});
|
2019-12-13 04:01:04 +00:00
|
|
|
return res.status(500).json({
|
|
|
|
message: "Fetching Rates Failed!",
|
|
|
|
error: err.error
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|