2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-03 23:15:24 +00:00
RTL/controllers/RTLConf.js

86 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-01-01 16:26:51 +00:00
var ini = require('ini');
var path = require('path');
var fs = require('fs');
2019-01-13 22:55:25 +00:00
var logger = require('./logger');
var common = require('../common');
2019-01-01 16:26:51 +00:00
exports.getRTLConfig = (req, res, next) => {
2019-02-16 22:43:12 +00:00
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
logger.info('\r\nConf: 7: ' + JSON.stringify(Date.now()) + ': INFO: Getting RTL Config');
2019-02-12 23:13:09 +00:00
fs.readFile(RTLConfFile, 'utf8', function(err, data) {
2019-01-01 16:26:51 +00:00
if (err) {
logger.error('\r\nConf: 10: ' + JSON.stringify(Date.now()) + ': ERROR: Getting RTL Config Failed!');
2019-01-01 16:26:51 +00:00
res.status(500).json({
message: "Reading RTL Config Failed!",
2019-01-01 16:26:51 +00:00
error: err
});
} else {
const jsonConfig = ini.parse(data);
authSettings = {
2019-02-12 13:36:04 +00:00
nodeAuthType: common.node_auth_type,
lndConfigPath: common.lnd_config_path,
bitcoindConfigPath: common.bitcoind_config_path,
rtlSSO: common.rtl_sso,
logoutRedirectLink: common.logout_redirect_link
};
res.status(200).json({settings: jsonConfig.Settings, authSettings: authSettings});
2019-01-01 16:26:51 +00:00
}
});
};
exports.updateUISettings = (req, res, next) => {
2019-02-16 22:43:12 +00:00
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
2019-02-12 23:13:09 +00:00
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
2019-01-01 16:26:51 +00:00
delete config.Settings;
2019-02-12 23:13:09 +00:00
fs.writeFileSync(RTLConfFile, ini.stringify(config));
fs.appendFile(RTLConfFile, ini.stringify(req.body.updatedSettings, { section: 'Settings' }), function(err) {
2019-01-01 16:26:51 +00:00
if (err) {
2019-01-13 22:55:25 +00:00
logger.error('\r\nConf: 28: ' + JSON.stringify(Date.now()) + ': ERROR: Updating UI Settings Failed!');
2019-01-01 16:26:51 +00:00
res.status(500).json({
message: "Updating UI Settings Failed!",
error: 'Updating UI Settings Failed!'
});
} else {
2019-01-13 22:55:25 +00:00
logger.info('\r\nConf: 34: ' + JSON.stringify(Date.now()) + ': INFO: Updating UI Settings Succesful!');
2019-01-01 16:26:51 +00:00
res.status(201).json({message: 'UI Settings Updated Successfully'});
}
});
};
exports.getConfig = (req, res, next) => {
2019-02-12 23:13:09 +00:00
let confFile = '';
switch (req.params.nodeType) {
case 'lnd':
2019-02-12 23:13:09 +00:00
confFile = common.lnd_config_path
break;
case 'bitcoind':
2019-02-12 23:13:09 +00:00
confFile = common.bitcoind_config_path
break;
case 'rtl':
2019-02-12 23:13:09 +00:00
confFile = common.rtl_conf_file_path + '/RTL.conf';
break;
default:
2019-02-12 23:13:09 +00:00
confFile = '';
break;
}
2019-02-12 23:13:09 +00:00
logger.info('\r\nConf: 43: ' + JSON.stringify(Date.now()) + ': INFO: Node Type: ' + req.params.nodeType + ', File Path: ' + confFile);
fs.readFile(confFile, 'utf8', function(err, data) {
2019-01-01 16:26:51 +00:00
if (err) {
logger.error('\r\nConf: 59: ' + 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 {
const jsonConfig = 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, '*');
}
res.status(200).json(ini.stringify(jsonConfig));
}
});
};