From c4f0efa295e1898d2ca179bc30b0fcacc62c9f4b Mon Sep 17 00:00:00 2001 From: ShahanaFarooqui Date: Fri, 5 Apr 2019 23:40:18 -0400 Subject: [PATCH] incomplete 3 incomplete 3 --- controllers/RTLConf.js | 105 ++++++++++++--------- controllers/UISettings.js | 35 ------- routes/RTLConf.js | 1 - routes/UISettings.js | 8 -- settings/ui.settings.json | 1 - src/app/app.component.ts | 3 +- src/app/pages/signin/signin.component.html | 14 +-- src/app/pages/signin/signin.component.ts | 6 +- src/app/shared/store/rtl.actions.ts | 17 +--- src/app/shared/store/rtl.effects.ts | 23 +---- src/app/shared/store/rtl.reducers.ts | 9 +- 11 files changed, 67 insertions(+), 155 deletions(-) delete mode 100644 controllers/UISettings.js delete mode 100644 routes/UISettings.js delete mode 100644 settings/ui.settings.json diff --git a/controllers/RTLConf.js b/controllers/RTLConf.js index 73f4de09..c7f3de3b 100644 --- a/controllers/RTLConf.js +++ b/controllers/RTLConf.js @@ -5,27 +5,60 @@ var logger = require('./logger'); var common = require('../common'); exports.getRTLConfig = (req, res, next) => { - 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); - authSettings = { - 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}); - } - }); + 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); + authSettings = { + 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({ nodes: [{settings: jsonConfig.Settings, authSettings: authSettings}] }); + } + }); + } 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!'); + res.status(200).json({ nodes: [] }); + } 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); + var nodesArr = []; + multiNodeConfig.nodes.forEach(node => { + authSettings = { + nodeAuthType: 'CUSTOM', + lndConfigPath: node.lnd_config_path, + bitcoindConfigPath: node.bitcoind_config_path, + rtlSSO: common.rtl_sso, + logoutRedirectLink: common.logout_redirect_link + }; + nodesArr.push({settings: node.Settings, authSettings: authSettings}) + }); + res.status(200).json({ nodes: nodesArr }); + } + }); + } }; exports.updateUISettings = (req, res, next) => { @@ -35,13 +68,13 @@ exports.updateUISettings = (req, res, next) => { fs.writeFileSync(RTLConfFile, ini.stringify(config)); fs.appendFile(RTLConfFile, ini.stringify(req.body.updatedSettings, { section: 'Settings' }), function(err) { if (err) { - logger.error('\r\nConf: 28: ' + JSON.stringify(Date.now()) + ': ERROR: Updating UI Settings Failed!'); + 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: 34: ' + JSON.stringify(Date.now()) + ': INFO: Updating UI Settings Succesful!'); + logger.info('\r\nConf: 77: ' + JSON.stringify(Date.now()) + ': INFO: Updating UI Settings Succesful!'); res.status(201).json({message: 'UI Settings Updated Successfully'}); } }); @@ -63,10 +96,10 @@ exports.getConfig = (req, res, next) => { confFile = ''; break; } - logger.info('\r\nConf: 43: ' + JSON.stringify(Date.now()) + ': INFO: Node Type: ' + req.params.nodeType + ', File Path: ' + confFile); + logger.info('\r\nConf: 99: ' + JSON.stringify(Date.now()) + ': INFO: Node Type: ' + req.params.nodeType + ', File Path: ' + confFile); fs.readFile(confFile, 'utf8', function(err, data) { if (err) { - logger.error('\r\nConf: 59: ' + JSON.stringify(Date.now()) + ': ERROR: Reading Conf Failed!'); + logger.error('\r\nConf: 102: ' + JSON.stringify(Date.now()) + ': ERROR: Reading Conf Failed!'); res.status(500).json({ message: "Reading Config File Failed!", error: err @@ -83,25 +116,3 @@ exports.getConfig = (req, res, next) => { } }); }; - -exports.getMultiNodeConfig = (req, res, next) => { - var RTLMultiNodeConfFile = common.rtl_conf_file_path + '/RTL-Multi-Node-Conf.json'; - logger.info('\r\nRTLConf.js: 91: ' + 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: 94: ' + JSON.stringify(Date.now()) + ': INFO: Multi Node Config does not exist!'); - res.status(200).json({ nodes: [] }); - } else { - logger.error('\r\nRTLConf.js: 94: ' + 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 = require('../RTL-Multi-Node-Conf.json'); - res.status(200).json(multiNodeConfig); - } - }); -}; \ No newline at end of file diff --git a/controllers/UISettings.js b/controllers/UISettings.js deleted file mode 100644 index 9998d4cf..00000000 --- a/controllers/UISettings.js +++ /dev/null @@ -1,35 +0,0 @@ -var path = require('path'); -var fs = require('fs'); -var file_path = path.normalize(__dirname + '/..') + '/settings/ui.settings.json'; - -exports.getUISettings = (req, res, next) => { - console.log('Getting UI Settings!'); - fs.readFile(file_path, function(err, data) { - if (err) { - console.log('Reading UI Settings Failed!'); - res.status(500).json({ - message: "Reading UI Settings Failed!", - error: err - }); - } else { - console.log('UI theme read successfully'); - console.log(JSON.parse(data)); - res.status(200).json({settings: JSON.parse(data)}); - } - }); -}; - -exports.updateUISettings = (req, res, next) => { - fs.writeFile(file_path, JSON.stringify(req.body.updatedSettings), function(err) { - if (err) { - console.log('Updating UI Settings Failed!'); - res.status(500).json({ - message: "Updating UI Settings Failed!", - error: 'Updating UI Settings Failed!' - }); - } else { - console.log('UI theme updated successfully'); - res.status(201).json({message: 'UI theme updated successfully'}); - } - }); -}; diff --git a/routes/RTLConf.js b/routes/RTLConf.js index 2d734398..c12af194 100644 --- a/routes/RTLConf.js +++ b/routes/RTLConf.js @@ -6,6 +6,5 @@ const authCheck = require("./authCheck"); router.get("/rtlconf", RTLConfController.getRTLConfig); router.post("/", authCheck, RTLConfController.updateUISettings); router.get("/config/:nodeType", authCheck, RTLConfController.getConfig); -router.get("/multinode", RTLConfController.getMultiNodeConfig); module.exports = router; diff --git a/routes/UISettings.js b/routes/UISettings.js deleted file mode 100644 index b5876cd2..00000000 --- a/routes/UISettings.js +++ /dev/null @@ -1,8 +0,0 @@ -const UISettingsController = require("../controllers/UISettings"); -const express = require("express"); -const router = express.Router(); - -router.get("/", UISettingsController.getUISettings); -router.post("/", UISettingsController.updateUISettings); - -module.exports = router; diff --git a/settings/ui.settings.json b/settings/ui.settings.json deleted file mode 100644 index ed50e0af..00000000 --- a/settings/ui.settings.json +++ /dev/null @@ -1 +0,0 @@ -{"flgSidenavOpened":true,"flgSidenavPinned":true,"menu":"Vertical","menuType":"Regular","theme":"dark-blue","lndConfigPath":"C:\\Users\\Suheb\\AppData\\Local\\Lnd\\lnd.conf","satsToBTC":false} \ No newline at end of file diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b20b65c7..5c65765c 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -34,7 +34,6 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy { private userIdle: UserIdleService, private router: Router) {} ngOnInit() { - this.store.dispatch(new RTLActions.FetchMultiNodeSettings()); this.store.dispatch(new RTLActions.FetchSettings()); this.accessKey = this.readAccessKey(); this.store.select('rtlRoot') @@ -68,7 +67,7 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy { if (actionPayload.type === RTLActions.SET_AUTH_SETTINGS) { if (!sessionStorage.getItem('token')) { if (+actionPayload.payload.rtlSSO) { - this.store.dispatch(new RTLActions.Signin({ password: window.btoa(this.accessKey), node: '' })); + this.store.dispatch(new RTLActions.Signin(window.btoa(this.accessKey))); } else { this.router.navigate([this.authSettings.logoutRedirectLink]); } diff --git a/src/app/pages/signin/signin.component.html b/src/app/pages/signin/signin.component.html index 5ba8800e..296c9bbe 100644 --- a/src/app/pages/signin/signin.component.html +++ b/src/app/pages/signin/signin.component.html @@ -8,17 +8,8 @@
-
- - - - {{multiNode.lnNode}} ({{multiNode.lnImpl}}) - - - -
- - + + {{hintStr}} @@ -28,4 +19,3 @@ - \ No newline at end of file diff --git a/src/app/pages/signin/signin.component.ts b/src/app/pages/signin/signin.component.ts index 06192bf3..0a166d32 100644 --- a/src/app/pages/signin/signin.component.ts +++ b/src/app/pages/signin/signin.component.ts @@ -3,7 +3,6 @@ import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { Store } from '@ngrx/store'; -import { MultiNode } from '../../shared/models/RTLconfig'; import { LoggerService } from '../../shared/services/logger.service'; import * as fromRTLReducer from '../../shared/store/rtl.reducers'; import * as RTLActions from '../../shared/store/rtl.actions'; @@ -14,8 +13,6 @@ import * as RTLActions from '../../shared/store/rtl.actions'; styleUrls: ['./signin.component.scss'] }) export class SigninComponent implements OnInit, OnDestroy { - multiNodes: MultiNode[] = []; - selNode = ''; password = ''; nodeAuthType = ''; rtlSSO = 0; @@ -34,7 +31,6 @@ export class SigninComponent implements OnInit, OnDestroy { rtlStore.effectErrors.forEach(effectsErr => { this.logger.error(effectsErr); }); - this.multiNodes = rtlStore.multiNodes; this.nodeAuthType = rtlStore.authSettings.nodeAuthType; this.logger.info(rtlStore); if (this.nodeAuthType.toUpperCase() === 'DEFAULT') { @@ -46,7 +42,7 @@ export class SigninComponent implements OnInit, OnDestroy { } onSignin() { - this.store.dispatch(new RTLActions.Signin({ password: window.btoa(this.password), node: this.selNode })); + this.store.dispatch(new RTLActions.Signin(window.btoa(this.password))); } resetData() { diff --git a/src/app/shared/store/rtl.actions.ts b/src/app/shared/store/rtl.actions.ts index ff2e1708..129bfffa 100644 --- a/src/app/shared/store/rtl.actions.ts +++ b/src/app/shared/store/rtl.actions.ts @@ -1,5 +1,5 @@ import { Action } from '@ngrx/store'; -import { Settings, Authentication, MultiNode } from '../models/RTLconfig'; +import { Settings, Authentication } from '../models/RTLconfig'; import { ErrorPayload } from '../models/errorPayload'; import { GetInfo, Peer, Balance, NetworkInfo, Fees, Channel, Invoice, Payment, GraphNode, AddressType, @@ -19,8 +19,6 @@ export const FETCH_STORE = 'FETCH_STORE'; export const SET_STORE = 'SET_STORE'; export const FETCH_SETTINGS = 'FETCH_SETTINGS'; export const SET_SETTINGS = 'SET_SETTINGS'; -export const FETCH_MULTI_NODE_SETTINGS = 'FETCH_MULTI_NODE_SETTINGS'; -export const SET_MULTI_NODE_SETTINGS = 'SET_MULTI_NODE_SETTINGS'; export const SET_AUTH_SETTINGS = 'SET_AUTH_SETTINGS'; export const SAVE_SETTINGS = 'SAVE_SETTINGS'; export const FETCH_INFO = 'FETCH_INFO'; @@ -123,15 +121,6 @@ export class SetSettings implements Action { constructor(public payload: Settings) {} } -export class FetchMultiNodeSettings implements Action { - readonly type = FETCH_MULTI_NODE_SETTINGS; -} - -export class SetMultiNodeSettings implements Action { - readonly type = SET_MULTI_NODE_SETTINGS; - constructor(public payload: MultiNode[]) {} -} - export class SetAuthSettings implements Action { readonly type = SET_AUTH_SETTINGS; constructor(public payload: Authentication) {} @@ -382,7 +371,7 @@ export class IsAuthorizedRes implements Action { export class Signin implements Action { readonly type = SIGNIN; - constructor(public payload: { password: string, node: string }) {} + constructor(public payload: string) {} // payload = password } export class Signout implements Action { @@ -396,7 +385,7 @@ export class InitAppData implements Action { export type RTLActions = ClearEffectError | EffectError | OpenSpinner | CloseSpinner | - FetchSettings | SetSettings | SaveSettings | SetAuthSettings | FetchMultiNodeSettings | SetMultiNodeSettings | + FetchSettings | SetSettings | SaveSettings | SetAuthSettings | OpenAlert | CloseAlert | OpenConfirmation | CloseConfirmation | FetchInfo | SetInfo | FetchPeers | SetPeers | AddPeer | DetachPeer | SaveNewPeer | RemovePeer | diff --git a/src/app/shared/store/rtl.effects.ts b/src/app/shared/store/rtl.effects.ts index 4bc6f02b..a224c6bd 100644 --- a/src/app/shared/store/rtl.effects.ts +++ b/src/app/shared/store/rtl.effects.ts @@ -107,27 +107,6 @@ export class RTLEffects implements OnDestroy { }) )); - @Effect() - multiNodeFetch = this.actions$.pipe( - ofType(RTLActions.FETCH_MULTI_NODE_SETTINGS), - mergeMap((action: RTLActions.FetchMultiNodeSettings) => { - this.store.dispatch(new RTLActions.ClearEffectError('FetchMultiNodeSettings')); - return this.httpClient.get(environment.CONF_API + '/multinode'); - }), - map((multiNodes: any) => { - this.logger.info(multiNodes); - return { - type: RTLActions.SET_MULTI_NODE_SETTINGS, - payload: (undefined !== multiNodes && undefined !== multiNodes.nodes) ? multiNodes.nodes : [] - }; - }, - catchError((err) => { - this.logger.error(err); - this.store.dispatch(new RTLActions.EffectError({ action: 'FetchMultiNodeSettings', code: err.status, message: err.error.error })); - return of(); - }) - )); - @Effect({ dispatch: false }) settingSave = this.actions$.pipe( ofType(RTLActions.SAVE_SETTINGS), @@ -923,7 +902,7 @@ export class RTLEffects implements OnDestroy { withLatestFrom(this.store.select('rtlRoot')), mergeMap(([action, store]: [RTLActions.Signin, fromRTLReducer.State]) => { this.store.dispatch(new RTLActions.ClearEffectError('Signin')); - return this.httpClient.post(environment.AUTHENTICATE_API, { password: action.payload.password, node: action.payload.node }) + return this.httpClient.post(environment.AUTHENTICATE_API, { password: action.payload }) .pipe( map((postRes: any) => { this.logger.info(postRes); diff --git a/src/app/shared/store/rtl.reducers.ts b/src/app/shared/store/rtl.reducers.ts index 78e04669..8491f4be 100644 --- a/src/app/shared/store/rtl.reducers.ts +++ b/src/app/shared/store/rtl.reducers.ts @@ -1,14 +1,13 @@ import * as RTLActions from './rtl.actions'; import { ErrorPayload } from '../models/errorPayload'; -import { Settings, Authentication, MultiNode } from '../models/RTLconfig'; +import { Settings, Authentication } from '../models/RTLconfig'; import { GetInfo, GetInfoChain, Peer, AddressType, Fees, NetworkInfo, Balance, Channel, Payment, Invoice, PendingChannels, ClosedChannel, Transaction, SwitchRes } from '../models/lndModels'; export interface State { effectErrors: ErrorPayload[]; - multiNodes: MultiNode[]; settings: Settings; authSettings: Authentication; information: GetInfo; @@ -34,7 +33,6 @@ export interface State { const initialState: State = { effectErrors: [], - multiNodes: [], settings: {flgSidenavOpened: true, flgSidenavPinned: true, menu: 'Vertical', menuType: 'Regular', theme: 'dark-blue', satsToBTC: false}, authSettings: {nodeAuthType: 'CUSTOM', lndConfigPath: '', bitcoindConfigPath: '', rtlSSO: 0, logoutRedirectLink: '/login' }, information: {}, @@ -85,11 +83,6 @@ export function RTLRootReducer(state = initialState, action: RTLActions.RTLActio ...state, settings: action.payload }; - case RTLActions.SET_MULTI_NODE_SETTINGS: - return { - ...state, - multiNodes: action.payload - }; case RTLActions.SET_AUTH_SETTINGS: return { ...state,