2021-12-29 23:08:41 +00:00
import * as fs from 'fs' ;
import { sep } from 'path' ;
import ini from 'ini' ;
import parseHocon from 'hocon-parser' ;
import request from 'request-promise' ;
import { Database } from '../../utils/database.js' ;
import { Logger } from '../../utils/logger.js' ;
import { Common } from '../../utils/common.js' ;
import { WSServer } from '../../utils/webSocketServer.js' ;
const options = { url : '' } ;
const logger = Logger ;
const common = Common ;
const wsServer = WSServer ;
const databaseService = Database ;
export const updateSelectedNode = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Updating Selected Node..' } ) ;
2022-08-07 21:12:47 +00:00
const selNodeIndex = req . params . currNodeIndex ? + req . params . currNodeIndex : common . initSelectedNode ? + common . initSelectedNode . index : 1 ;
2021-12-29 23:08:41 +00:00
req . session . selectedNode = common . findNode ( selNodeIndex ) ;
if ( req . headers && req . headers . authorization && req . headers . authorization !== '' ) {
2022-08-07 21:12:47 +00:00
wsServer . updateLNWSClientDetails ( req . session . id , + req . session . selectedNode . index , + req . params . prevNodeIndex ) ;
if ( req . params . prevNodeIndex !== - 1 ) {
2022-10-12 21:38:21 +00:00
databaseService . unloadDatabase ( req . params . prevNodeIndex , req . session . id ) ;
2021-12-29 23:08:41 +00:00
}
}
const responseVal = ! req . session . selectedNode . ln _node ? '' : req . session . selectedNode . ln _node ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Selected Node Updated To ' + responseVal } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 200 ) . json ( { status : 'Selected Node Updated To: ' + JSON . stringify ( responseVal ) + '!' } ) ;
} ;
export const getRTLConfigInitial = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Getting Initial RTL Configuration..' } ) ;
const confFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
fs . readFile ( confFile , 'utf8' , ( errRes , data ) => {
if ( errRes ) {
if ( errRes . code === 'ENOENT' ) {
logger . log ( { selectedNode : req . session . selectedNode , level : 'ERROR' , fileName : 'RTLConf' , msg : 'Node config does not exist!' , error : { error : 'Node config does not exist.' } } ) ;
res . status ( 200 ) . json ( { defaultNodeIndex : 0 , selectedNodeIndex : 0 , sso : { } , nodes : [ ] } ) ;
}
else {
const errMsg = 'Get Node Config Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
}
else {
const nodeConfData = JSON . parse ( data ) ;
const sso = { rtlSSO : common . rtl _sso , logoutRedirectLink : common . logout _redirect _link } ;
const enable2FA = ! ! common . rtl _secret2fa ;
const allowPasswordUpdate = common . flg _allow _password _update ;
const nodesArr = [ ] ;
if ( common . nodes && common . nodes . length > 0 ) {
common . nodes . forEach ( ( node , i ) => {
2022-11-16 03:17:23 +00:00
const settings = { unannouncedChannels : false } ;
2021-12-29 23:08:41 +00:00
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' ;
2022-11-16 03:17:23 +00:00
settings . unannouncedChannels = ! ! node . unannounced _channels || false ;
2021-12-29 23:08:41 +00:00
settings . fiatConversion = ( node . fiat _conversion ) ? ! ! node . fiat _conversion : false ;
settings . currencyUnit = node . currency _unit ;
nodesArr . push ( {
index : node . index ,
lnNode : node . ln _node ,
lnImplementation : node . ln _implementation ,
settings : settings ,
authentication : { }
} ) ;
} ) ;
}
2022-01-16 20:55:50 +00:00
const body = { defaultNodeIndex : nodeConfData . defaultNodeIndex , selectedNodeIndex : ( req . session . selectedNode && req . session . selectedNode . index ? req . session . selectedNode . index : common . initSelectedNode . index ) , sso : sso , enable2FA : enable2FA , allowPasswordUpdate : allowPasswordUpdate , nodes : nodesArr } ;
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Initial RTL Configuration Received' , data : body } ) ;
res . status ( 200 ) . json ( body ) ;
2021-12-29 23:08:41 +00:00
}
} ) ;
} ;
export const getRTLConfig = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Getting RTL Configuration..' } ) ;
const confFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
fs . readFile ( confFile , 'utf8' , ( errRes , data ) => {
if ( errRes ) {
if ( errRes . code === 'ENOENT' ) {
logger . log ( { selectedNode : req . session . selectedNode , level : 'ERROR' , fileName : 'RTLConf' , msg : 'Node config does not exist!' , error : { error : 'Node config does not exist.' } } ) ;
res . status ( 200 ) . json ( { defaultNodeIndex : 0 , selectedNodeIndex : 0 , sso : { } , nodes : [ ] } ) ;
}
else {
const errMsg = 'Get Node Config Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
}
else {
const nodeConfData = JSON . parse ( data ) ;
const sso = { rtlSSO : common . rtl _sso , logoutRedirectLink : common . logout _redirect _link } ;
const enable2FA = ! ! common . rtl _secret2fa ;
const allowPasswordUpdate = common . flg _allow _password _update ;
const nodesArr = [ ] ;
if ( common . nodes && common . nodes . length > 0 ) {
common . nodes . forEach ( ( node , i ) => {
const authentication = { } ;
authentication . configPath = ( node . config _path ) ? node . config _path : '' ;
authentication . swapMacaroonPath = ( node . swap _macaroon _path ) ? node . swap _macaroon _path : '' ;
authentication . boltzMacaroonPath = ( node . boltz _macaroon _path ) ? node . boltz _macaroon _path : '' ;
2022-11-16 03:17:23 +00:00
const settings = { unannouncedChannels : false } ;
2021-12-29 23:08:41 +00:00
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' ;
2022-11-16 03:17:23 +00:00
settings . unannouncedChannels = ! ! node . unannounced _channels || false ;
2021-12-29 23:08:41 +00:00
settings . fiatConversion = ( node . fiat _conversion ) ? ! ! node . fiat _conversion : false ;
settings . bitcoindConfigPath = node . bitcoind _config _path ;
settings . logLevel = node . log _level ? node . log _level : 'ERROR' ;
settings . lnServerUrl = node . ln _server _url ;
settings . swapServerUrl = node . swap _server _url ;
settings . boltzServerUrl = node . boltz _server _url ;
settings . enableOffers = node . enable _offers ;
2022-08-24 07:58:18 +00:00
settings . enablePeerswap = node . enable _peerswap ;
2021-12-29 23:08:41 +00:00
settings . channelBackupPath = node . channel _backup _path ;
settings . currencyUnit = node . currency _unit ;
nodesArr . push ( {
index : node . index ,
lnNode : node . ln _node ,
lnImplementation : node . ln _implementation ,
settings : settings ,
authentication : authentication
} ) ;
} ) ;
}
2022-01-16 20:55:50 +00:00
const body = { defaultNodeIndex : nodeConfData . defaultNodeIndex , selectedNodeIndex : ( req . session . selectedNode && req . session . selectedNode . index ? req . session . selectedNode . index : common . initSelectedNode . index ) , sso : sso , enable2FA : enable2FA , allowPasswordUpdate : allowPasswordUpdate , nodes : nodesArr } ;
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'RTL Configuration Received' , data : body } ) ;
res . status ( 200 ) . json ( body ) ;
2021-12-29 23:08:41 +00:00
}
} ) ;
} ;
export const updateUISettings = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Updating UI Settings..' } ) ;
const RTLConfFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
const config = JSON . parse ( fs . readFileSync ( RTLConfFile , 'utf-8' ) ) ;
const node = config . nodes . find ( ( node ) => ( node . index === req . session . selectedNode . index ) ) ;
if ( node && node . Settings ) {
node . Settings . userPersona = req . body . updatedSettings . userPersona ;
node . Settings . themeMode = req . body . updatedSettings . themeMode ;
node . Settings . themeColor = req . body . updatedSettings . themeColor ;
2022-11-16 03:17:23 +00:00
node . Settings . unannouncedChannels = req . body . updatedSettings . unannouncedChannels ;
2021-12-29 23:08:41 +00:00
node . Settings . fiatConversion = req . body . updatedSettings . fiatConversion ;
if ( req . body . updatedSettings . fiatConversion ) {
node . Settings . currencyUnit = req . body . updatedSettings . currencyUnit ? req . body . updatedSettings . currencyUnit : 'USD' ;
}
else {
delete node . Settings . currencyUnit ;
}
const selectedNode = common . findNode ( req . session . selectedNode . index ) ;
selectedNode . user _persona = req . body . updatedSettings . userPersona ;
selectedNode . theme _mode = req . body . updatedSettings . themeMode ;
selectedNode . theme _color = req . body . updatedSettings . themeColor ;
2022-11-16 03:17:23 +00:00
selectedNode . unannounced _channels = req . body . updatedSettings . unannouncedChannels ;
2021-12-29 23:08:41 +00:00
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 ( req , selectedNode ) ;
}
try {
fs . writeFileSync ( RTLConfFile , JSON . stringify ( config , null , 2 ) , 'utf-8' ) ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'UI Settings Updated' , data : maskPasswords ( config ) } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 201 ) . json ( { message : 'Node Settings Updated Successfully' } ) ;
}
catch ( errRes ) {
const errMsg = 'Update Node Settings Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
} ;
export const update2FASettings = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Updating 2FA Settings..' } ) ;
const RTLConfFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
const config = JSON . parse ( fs . readFileSync ( RTLConfFile , 'utf-8' ) ) ;
2022-01-16 20:55:50 +00:00
if ( req . body . secret2fa && req . body . secret2fa . trim ( ) !== '' ) {
config . secret2fa = req . body . secret2fa ;
}
else {
delete config . secret2fa ;
}
const message = req . body . secret2fa . trim ( ) === '' ? 'Two factor authentication disabled successfully.' : 'Two factor authentication enabled successfully.' ;
2021-12-29 23:08:41 +00:00
try {
fs . writeFileSync ( RTLConfFile , JSON . stringify ( config , null , 2 ) , 'utf-8' ) ;
common . rtl _secret2fa = config . secret2fa ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : message } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 201 ) . json ( { message : message } ) ;
}
catch ( errRes ) {
const errMsg = 'Update 2FA Settings Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
} ;
export const updateDefaultNode = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Updating Default Node..' } ) ;
const RTLConfFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
const config = JSON . parse ( fs . readFileSync ( RTLConfFile , 'utf-8' ) ) ;
config . defaultNodeIndex = req . body . defaultNodeIndex ;
try {
fs . writeFileSync ( RTLConfFile , JSON . stringify ( config , null , 2 ) , 'utf-8' ) ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Default Node Updated' , data : maskPasswords ( config ) } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 201 ) . json ( { message : 'Default Node Updated Successfully' } ) ;
}
catch ( errRes ) {
const errMsg = 'Update Default Node Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
} ;
export const getConfig = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Reading Configuration File..' } ) ;
let confFile = '' ;
let fileFormat = 'INI' ;
switch ( req . params . nodeType ) {
case 'ln' :
confFile = req . session . selectedNode . config _path ;
break ;
case 'bitcoind' :
confFile = req . session . selectedNode . bitcoind _config _path ;
break ;
case 'rtl' :
fileFormat = 'JSON' ;
confFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
break ;
default :
confFile = '' ;
break ;
}
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'DEBUG' , fileName : 'RTLConf' , msg : 'Node Type' , data : req . params . nodeType } ) ;
logger . log ( { selectedNode : req . session . selectedNode , level : 'DEBUG' , fileName : 'RTLConf' , msg : 'File Path' , data : confFile } ) ;
2021-12-29 23:08:41 +00:00
fs . readFile ( confFile , 'utf8' , ( errRes , data ) => {
2022-08-17 22:48:04 +00:00
var _a ;
2021-12-29 23:08:41 +00:00
if ( errRes ) {
const errMsg = 'Reading Config Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
else {
let jsonConfig = { } ;
if ( fileFormat === 'JSON' ) {
jsonConfig = JSON . parse ( data ) ;
}
else {
fileFormat = 'INI' ;
2022-08-17 22:48:04 +00:00
data = data === null || data === void 0 ? void 0 : data . replace ( 'color=#' , 'color=' ) ;
2021-12-29 23:08:41 +00:00
jsonConfig = ini . parse ( data ) ;
2022-01-16 20:55:50 +00:00
if ( jsonConfig [ 'Application Options' ] && jsonConfig [ 'Application Options' ] . color ) {
jsonConfig [ 'Application Options' ] . color = '#' + jsonConfig [ 'Application Options' ] . color ;
}
2022-09-29 01:15:37 +00:00
if ( req . params . nodeType === 'ln' && req . session . selectedNode . ln _implementation === 'ECL' && ! jsonConfig [ 'eclair.api.password' ] ) {
2021-12-29 23:08:41 +00:00
fileFormat = 'HOCON' ;
jsonConfig = parseHocon ( data ) ;
}
}
jsonConfig = maskPasswords ( jsonConfig ) ;
2022-08-17 22:48:04 +00:00
const responseJSON = ( fileFormat === 'JSON' ) ? jsonConfig : ( _a = ini . stringify ( jsonConfig ) ) === null || _a === void 0 ? void 0 : _a . replace ( 'color=\\#' , 'color=#' ) ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Configuration File Data Received' , data : responseJSON } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 200 ) . json ( { format : fileFormat , data : responseJSON } ) ;
}
} ) ;
} ;
export const getFile = ( req , res , next ) => {
2022-08-17 22:48:04 +00:00
var _a ;
2021-12-29 23:08:41 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Getting File..' } ) ;
2022-08-17 22:48:04 +00:00
const file = req . query . path ? req . query . path : ( req . session . selectedNode . channel _backup _path + sep + 'channel-' + ( ( _a = req . query . channel ) === null || _a === void 0 ? void 0 : _a . replace ( ':' , '-' ) ) + '.bak' ) ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'DEBUG' , fileName : 'RTLConf' , msg : 'Channel Point' , data : req . query . channel } ) ;
logger . log ( { selectedNode : req . session . selectedNode , level : 'DEBUG' , fileName : 'RTLConf' , msg : 'File Path' , data : file } ) ;
2021-12-29 23:08:41 +00:00
fs . readFile ( file , 'utf8' , ( errRes , data ) => {
if ( errRes ) {
if ( errRes . code && errRes . code === 'ENOENT' ) {
errRes . code = 'File Not Found!' ;
}
const errMsg = 'Reading File Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
else {
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'File Data Received' , data : data } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 200 ) . json ( data ) ;
}
} ) ;
} ;
export const getCurrencyRates = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Getting Currency Rates..' } ) ;
options . url = 'https://blockchain.info/ticker' ;
request ( options ) . then ( ( body ) => {
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Currency Rates Received' , data : body } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 200 ) . json ( JSON . parse ( body ) ) ;
} ) . catch ( ( errRes ) => {
const errMsg = 'Get Rates Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
} ) ;
} ;
export const updateSSO = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Updating SSO Settings..' } ) ;
const RTLConfFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
const config = JSON . parse ( fs . readFileSync ( RTLConfFile , 'utf-8' ) ) ;
delete config . SSO ;
config . SSO = req . body . SSO ;
try {
fs . writeFileSync ( RTLConfFile , JSON . stringify ( config , null , 2 ) , 'utf-8' ) ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'SSO Setting Updated' , data : maskPasswords ( config ) } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 201 ) . json ( { message : 'SSO Updated Successfully' } ) ;
}
catch ( errRes ) {
const errMsg = 'Update SSO Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
} ;
export const updateServiceSettings = ( req , res , next ) => {
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Updating Service Settings..' } ) ;
const RTLConfFile = common . rtl _conf _file _path + sep + 'RTL-Config.json' ;
const config = JSON . parse ( fs . readFileSync ( RTLConfFile , 'utf-8' ) ) ;
const selectedNode = common . findNode ( req . session . selectedNode . index ) ;
2022-08-24 07:58:18 +00:00
config . nodes . forEach ( ( node ) => {
2021-12-29 23:08:41 +00:00
if ( node . index === req . session . selectedNode . index ) {
switch ( req . body . service ) {
case 'LOOP' :
if ( req . body . settings . enable ) {
node . Settings . swapServerUrl = req . body . settings . serverUrl ;
node . Authentication . swapMacaroonPath = req . body . settings . macaroonPath ;
selectedNode . swap _server _url = req . body . settings . serverUrl ;
selectedNode . swap _macaroon _path = req . body . settings . macaroonPath ;
}
else {
delete node . Settings . swapServerUrl ;
delete node . Authentication . swapMacaroonPath ;
delete selectedNode . swap _server _url ;
delete selectedNode . swap _macaroon _path ;
}
break ;
case 'BOLTZ' :
if ( req . body . settings . enable ) {
node . Settings . boltzServerUrl = req . body . settings . serverUrl ;
node . Authentication . boltzMacaroonPath = req . body . settings . macaroonPath ;
selectedNode . boltz _server _url = req . body . settings . serverUrl ;
selectedNode . boltz _macaroon _path = req . body . settings . macaroonPath ;
}
else {
delete node . Settings . boltzServerUrl ;
delete node . Authentication . boltzMacaroonPath ;
delete selectedNode . boltz _server _url ;
delete selectedNode . boltz _macaroon _path ;
}
break ;
case 'OFFERS' :
node . Settings . enableOffers = req . body . settings . enableOffers ;
selectedNode . enable _offers = req . body . settings . enableOffers ;
break ;
2022-08-24 07:58:18 +00:00
case 'PEERSWAP' :
node . Settings . enablePeerswap = req . body . settings . enablePeerswap ;
selectedNode . enable _peerswap = req . body . settings . enablePeerswap ;
break ;
2021-12-29 23:08:41 +00:00
default :
break ;
}
common . replaceNode ( req , selectedNode ) ;
}
return node ;
} ) ;
try {
fs . writeFileSync ( RTLConfFile , JSON . stringify ( config , null , 2 ) , 'utf-8' ) ;
2022-01-16 20:55:50 +00:00
logger . log ( { selectedNode : req . session . selectedNode , level : 'INFO' , fileName : 'RTLConf' , msg : 'Service Settings Updated' , data : maskPasswords ( config ) } ) ;
2021-12-29 23:08:41 +00:00
res . status ( 201 ) . json ( { message : 'Service Settings Updated Successfully' } ) ;
}
catch ( errRes ) {
const errMsg = 'Update Service Settings Error' ;
const err = common . handleError ( { statusCode : 500 , message : errMsg , error : errRes } , 'RTLConf' , errMsg , req . session . selectedNode ) ;
return res . status ( err . statusCode ) . json ( { message : err . error , error : err . error } ) ;
}
} ;
export const maskPasswords = ( obj ) => {
const keys = Object . keys ( obj ) ;
const length = keys . length ;
if ( length !== 0 ) {
for ( let i = 0 ; i < length ; i ++ ) {
if ( typeof obj [ keys [ i ] ] === 'object' ) {
keys [ keys [ i ] ] = maskPasswords ( obj [ keys [ i ] ] ) ;
}
if ( typeof keys [ i ] === 'string' &&
( keys [ i ] . toLowerCase ( ) . includes ( 'password' ) || keys [ i ] . toLowerCase ( ) . includes ( 'multipass' ) ||
2022-09-21 01:33:08 +00:00
keys [ i ] . toLowerCase ( ) . includes ( 'rpcpass' ) || keys [ i ] . toLowerCase ( ) . includes ( 'rpcpassword' ) ||
keys [ i ] . toLowerCase ( ) . includes ( 'rpcuser' ) ) ) {
2021-12-29 23:08:41 +00:00
obj [ keys [ i ] ] = '********************' ;
}
}
}
return obj ;
} ;