mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2025-02-22 14:22:48 +01:00
incomplete 3
incomplete 3
This commit is contained in:
parent
c9717fb8f4
commit
c4f0efa295
11 changed files with 67 additions and 155 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -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'});
|
||||
}
|
||||
});
|
||||
};
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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}
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -8,17 +8,8 @@
|
|||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<form (ngSubmit)="onSignin()" #signinForm="ngForm">
|
||||
<div *ngIf="multiNodes.length > 0" fxFlex="30" tabindex="1" fxLayoutAlign="start start">
|
||||
<mat-form-field fxFlex="99">
|
||||
<mat-select [(value)]="selNode">
|
||||
<mat-option *ngFor="let multiNode of multiNodes" [value]="multiNode.index">
|
||||
{{multiNode.lnNode}} ({{multiNode.lnImpl}})
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<mat-form-field [fxFlex]="multiNodes.length > 0 ? 30 : 50" fxLayoutAlign="start">
|
||||
<input matInput placeholder="Password" type="password" id="password" name="password" [(ngModel)]="password" tabindex="2" required>
|
||||
<mat-form-field fxFlex="50" fxLayoutAlign="start">
|
||||
<input matInput placeholder="Password" type="password" id="password" name="password" [(ngModel)]="password" tabindex="1" required>
|
||||
<mat-hint>{{hintStr}}</mat-hint>
|
||||
</mat-form-field>
|
||||
<button fxFlex="10" class="mr-2" fxLayoutAlign="center center" mat-raised-button color="primary" tabindex="2" type="submit" [disabled]="!password">Login</button>
|
||||
|
@ -28,4 +19,3 @@
|
|||
</mat-card>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -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() {
|
||||
|
|
|
@ -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 |
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue