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-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);
|
2019-04-10 02:28:45 +00:00
|
|
|
logger.info('\r\nConf: 9: ' + JSON.stringify(Date.now()) + ': INFO: Selected Node Updated!' + JSON.stringify(common.selectedNode.ln_node));
|
2019-04-07 00:20:40 +00:00
|
|
|
res.status(200).json({status: 'Selected Node Updated!'});
|
|
|
|
};
|
|
|
|
|
2019-01-16 01:05:01 +00:00
|
|
|
exports.getRTLConfig = (req, res, next) => {
|
2019-04-06 03:40:18 +00:00
|
|
|
if(!common.multi_node_setup) {
|
|
|
|
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
|
|
|
logger.info('\r\nConf: 7: ' + JSON.stringify(Date.now()) + ': INFO: Getting RTL Config');
|
|
|
|
fs.readFile(RTLConfFile, 'utf8', function(err, data) {
|
|
|
|
if (err) {
|
|
|
|
logger.error('\r\nConf: 10: ' + JSON.stringify(Date.now()) + ': ERROR: Getting RTL Config Failed!');
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Reading RTL Config Failed!",
|
|
|
|
error: err
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const jsonConfig = ini.parse(data);
|
2019-04-06 22:42:09 +00:00
|
|
|
const sso = { rtlSSO: common.rtl_sso, logoutRedirectLink: common.logout_redirect_link };
|
|
|
|
const authentication = {
|
2019-04-06 03:40:18 +00:00
|
|
|
nodeAuthType: common.node_auth_type,
|
2019-04-06 22:42:09 +00:00
|
|
|
lndConfigPath: common.nodes[0].lnd_config_path,
|
|
|
|
bitcoindConfigPath: common.nodes[0].bitcoind_config_path
|
2019-04-06 03:40:18 +00:00
|
|
|
};
|
2019-04-10 02:28:45 +00:00
|
|
|
res.status(200).json({ selectedNodeIndex: common.selectedNode.index, sso: sso, nodes: [{
|
2019-04-07 04:04:22 +00:00
|
|
|
index: common.nodes[0].index,
|
|
|
|
lnNode: 'SingleNode',
|
|
|
|
lnImplementation: '',
|
|
|
|
settings: jsonConfig.Settings,
|
|
|
|
authentication: authentication}] });
|
2019-04-06 03:40:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var RTLMultiNodeConfFile = common.rtl_conf_file_path + '/RTL-Multi-Node-Conf.json';
|
|
|
|
logger.info('\r\nRTLConf.js: 32: ' + JSON.stringify(Date.now()) + ': INFO: Getting Multi Node Config');
|
|
|
|
fs.readFile(RTLMultiNodeConfFile, 'utf8', function(err, data) {
|
|
|
|
if (err) {
|
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
logger.error('\r\nRTLConf.js: 36: ' + JSON.stringify(Date.now()) + ': INFO: Multi Node Config does not exist!');
|
2019-04-10 02:28:45 +00:00
|
|
|
res.status(200).json({ selectedNodeIndex: {}, sso: {}, nodes: [] });
|
2019-04-06 03:40:18 +00:00
|
|
|
} else {
|
|
|
|
logger.error('\r\nRTLConf.js: 39: ' + JSON.stringify(Date.now()) + ': ERROR: Getting Multi Node Config Failed!');
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Reading Multi Node Config Failed!",
|
|
|
|
error: err
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const multiNodeConfig = JSON.parse(data);
|
2019-04-06 22:42:09 +00:00
|
|
|
const sso = { rtlSSO: common.rtl_sso, logoutRedirectLink: common.logout_redirect_link };
|
2019-04-06 03:40:18 +00:00
|
|
|
var nodesArr = [];
|
|
|
|
multiNodeConfig.nodes.forEach(node => {
|
2019-04-06 22:42:09 +00:00
|
|
|
const authentication = {};
|
|
|
|
authentication.nodeAuthType = 'CUSTOM';
|
|
|
|
if(node.Authentication.lndConfigPath) {
|
|
|
|
authentication.lndConfigPath = node.Authentication.lndConfigPath;
|
|
|
|
}
|
|
|
|
if(node.Settings.bitcoindConfigPath) {
|
|
|
|
authentication.bitcoindConfigPath = node.Settings.bitcoindConfigPath;
|
|
|
|
}
|
2019-04-07 04:04:22 +00:00
|
|
|
nodesArr.push({
|
|
|
|
index: node.index,
|
|
|
|
lnNode: node.lnNode,
|
|
|
|
lnImplementation: node.lnImplementation,
|
|
|
|
settings: node.Settings,
|
|
|
|
authentication: authentication})
|
2019-04-06 03:40:18 +00:00
|
|
|
});
|
2019-04-10 02:28:45 +00:00
|
|
|
res.status(200).json({ selectedNodeIndex: common.selectedNode.index, sso: sso, nodes: nodesArr });
|
2019-04-06 03:40:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-01-01 16:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.updateUISettings = (req, res, next) => {
|
2019-04-06 22:42:09 +00:00
|
|
|
var RTLConfFile = '';
|
|
|
|
if(common.multi_node_setup) {
|
|
|
|
RTLConfFile = common.rtl_conf_file_path + '/RTL-Multi-Node-Conf.json';
|
2019-04-07 00:20:40 +00:00
|
|
|
var config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
config.nodes.find(node => {
|
|
|
|
if(node.index == common.selectedNode.index) {
|
|
|
|
node.Settings.flgSidenavOpened = req.body.updatedSettings.flgSidenavOpened;
|
|
|
|
node.Settings.flgSidenavPinned = req.body.updatedSettings.flgSidenavPinned;
|
|
|
|
node.Settings.menu = req.body.updatedSettings.menu;
|
|
|
|
node.Settings.menuType = req.body.updatedSettings.menuType;
|
|
|
|
node.Settings.theme = req.body.updatedSettings.theme;
|
|
|
|
node.Settings.satsToBTC = req.body.updatedSettings.satsToBTC;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
2019-04-07 04:04:22 +00:00
|
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
2019-04-07 00:20:40 +00:00
|
|
|
logger.info('\r\nConf: 77: ' + JSON.stringify(Date.now()) + ': INFO: Updating UI Settings Succesful!');
|
|
|
|
res.status(201).json({message: 'UI Settings Updated Successfully'});
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
logger.error('\r\nConf: 71: ' + JSON.stringify(Date.now()) + ': ERROR: Updating UI Settings Failed!');
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Updating UI Settings Failed!",
|
|
|
|
error: 'Updating UI Settings Failed!'
|
|
|
|
});
|
|
|
|
}
|
2019-04-06 22:42:09 +00:00
|
|
|
} else {
|
|
|
|
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
|
|
|
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
2019-04-07 00:20:40 +00:00
|
|
|
const settingsTemp = config.Settings;
|
2019-04-06 22:42:09 +00:00
|
|
|
settingsTemp.flgSidenavOpened = req.body.updatedSettings.flgSidenavOpened;
|
|
|
|
settingsTemp.flgSidenavPinned = req.body.updatedSettings.flgSidenavPinned;
|
|
|
|
settingsTemp.menu = req.body.updatedSettings.menu;
|
|
|
|
settingsTemp.menuType = req.body.updatedSettings.menuType;
|
|
|
|
settingsTemp.theme = req.body.updatedSettings.theme;
|
|
|
|
settingsTemp.satsToBTC = req.body.updatedSettings.satsToBTC;
|
|
|
|
delete config.Settings;
|
|
|
|
fs.writeFileSync(RTLConfFile, ini.stringify(config));
|
|
|
|
fs.appendFile(RTLConfFile, ini.stringify(settingsTemp, { section: 'Settings' }), function(err) {
|
|
|
|
if (err) {
|
|
|
|
logger.error('\r\nConf: 71: ' + JSON.stringify(Date.now()) + ': ERROR: Updating UI Settings Failed!');
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Updating UI Settings Failed!",
|
|
|
|
error: 'Updating UI Settings Failed!'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
logger.info('\r\nConf: 77: ' + JSON.stringify(Date.now()) + ': INFO: Updating UI Settings Succesful!');
|
|
|
|
res.status(201).json({message: 'UI Settings Updated Successfully'});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-01-01 16:26:51 +00:00
|
|
|
};
|
|
|
|
|
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) {
|
|
|
|
case 'lnd':
|
2019-04-06 22:42:09 +00:00
|
|
|
JSONFormat = false;
|
2019-04-12 01:11:49 +00:00
|
|
|
confFile = common.selectedNode.lnd_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':
|
2019-04-06 22:42:09 +00:00
|
|
|
JSONFormat = (common.multi_node_setup) ? true : false;
|
|
|
|
confFile = (common.multi_node_setup) ? common.rtl_conf_file_path + '/RTL-Multi-Node-Conf.json' : common.rtl_conf_file_path + '/RTL.conf';
|
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-04-06 03:40:18 +00:00
|
|
|
logger.info('\r\nConf: 99: ' + JSON.stringify(Date.now()) + ': INFO: 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) {
|
2019-04-06 03:40:18 +00:00
|
|
|
logger.error('\r\nConf: 102: ' + JSON.stringify(Date.now()) + ': ERROR: 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);
|
2019-01-27 20:39:36 +00:00
|
|
|
if (undefined !== jsonConfig.Authentication && undefined !== jsonConfig.Authentication.rtlPass) {
|
|
|
|
jsonConfig.Authentication.rtlPass = jsonConfig.Authentication.rtlPass.replace(/./g, '*');
|
|
|
|
}
|
2019-01-01 16:26:51 +00:00
|
|
|
if (undefined !== jsonConfig.Bitcoind && undefined !== jsonConfig.Bitcoind['bitcoind.rpcpass']) {
|
|
|
|
jsonConfig.Bitcoind['bitcoind.rpcpass'] = jsonConfig.Bitcoind['bitcoind.rpcpass'].replace(/./g, '*');
|
|
|
|
}
|
2019-04-06 22:42:09 +00:00
|
|
|
if (undefined !== jsonConfig['bitcoind.rpcpass']) {
|
|
|
|
jsonConfig['bitcoind.rpcpass'] = jsonConfig['bitcoind.rpcpass'].replace(/./g, '*');
|
|
|
|
}
|
|
|
|
if (undefined !== jsonConfig['rpcpassword']) {
|
|
|
|
jsonConfig['rpcpassword'] = jsonConfig['rpcpassword'].replace(/./g, '*');
|
|
|
|
}
|
|
|
|
if (undefined !== jsonConfig.multiPass) {
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|