Updates for docker enablement 2

pull/47/head
ShahanaFarooqui 5 years ago
parent b4d26365c6
commit 812df26fca

@ -316,6 +316,15 @@ Apache-2.0
@angular/router
MIT
@angular/common
MIT
@angular/platform-browser
MIT
@ngrx/store
MIT
@ -380,12 +389,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@angular/common
MIT
@angular/platform-browser
MIT
@angular/material/datepicker
@angular/forms
@ -453,9 +456,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
@angular/material/form-field
@angular/router
MIT
@angular/material/progress-bar
@angular/material/list

@ -8,5 +8,5 @@
<link rel="stylesheet" href="styles.5e0b52f71274005aea8e.css"></head>
<body>
<rtl-app></rtl-app>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script><script type="text/javascript" src="polyfills.418928a701f2040ada02.js"></script><script type="text/javascript" src="main.a260eb3ea37c9cf9911a.js"></script></body>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script><script type="text/javascript" src="polyfills.418928a701f2040ada02.js"></script><script type="text/javascript" src="main.245aa68cd77ff4688590.js"></script></body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,12 +1,18 @@
var common = {};
common.port = 3000;
common.rtl_conf_file_path = '';
common.lnd_server_url = '';
common.lnd_config_path = '';
common.node_auth_type = '';
common.node_auth_type = 'DEFAULT';
common.macaroon_path = '';
common.bitcoind_config_path = '';
common.enable_logging = false;
common.log_file = '';
common.rtl_sso = 0;
common.rtl_cookie_file = '';
common.logout_redirect_link = '/login';
common.cookie = '';
common.convertToBTC = (num) => {
return (num / 100000000).toFixed(6);

@ -2,8 +2,9 @@ var fs = require('fs');
var clArgs = require('optimist').argv;
var ini = require('ini');
var common = require('./common');
var upperCase = require('upper-case');
var path = require('path');
var crypto = require('crypto');
var upperCase = require('upper-case');
var options = {};
var defaultConfig = {
@ -29,8 +30,8 @@ var defaultConfig = {
var setMacaroonPath = (clArgs, config) => {
if(undefined !== clArgs.lndir) {
common.macaroon_path = clArgs.lndir;
} else if (undefined !== clArgs.macaroonPath) {
common.macaroon_path = clArgs.macaroonPath;
} else if (undefined !== process.env.MACAROON_PATH) {
common.macaroon_path = process.env.MACAROON_PATH;
} else {
if(undefined !== config.Authentication.macroonPath && config.Authentication.macroonPath !== '') {
common.macaroon_path = config.Authentication.macroonPath;
@ -45,8 +46,8 @@ var validateConfigFile = (config) => {
errMsg = 'Please set macaroon path through environment/RTL.conf!';
}
if(undefined !== clArgs.lndServerUrl) {
common.lnd_server_url = clArgs.lndServerUrl;
if(undefined !== process.env.LND_SERVER_URL) {
common.lnd_server_url = process.env.LND_SERVER_URL;
} else {
if(config.Authentication.lndServerUrl === '' || undefined === config.Authentication.lndServerUrl) {
errMsg = errMsg + '\nPlease set LND Server URL through environment/RTL.conf!';
@ -55,8 +56,8 @@ var validateConfigFile = (config) => {
}
}
if(undefined !== clArgs.nodeAuthType) {
common.node_auth_type = clArgs.nodeAuthType;
if(undefined !== process.env.NODE_AUTH_TYPE) {
common.node_auth_type = process.env.NODE_AUTH_TYPE;
} else {
if(config.Authentication.nodeAuthType === '' || undefined === config.Authentication.nodeAuthType) {
errMsg = errMsg + '\nPlease set Node Auth Type through environment/RTL.conf!';
@ -65,8 +66,8 @@ var validateConfigFile = (config) => {
}
}
if(undefined !== clArgs.lndConfigPath) {
common.lnd_config_path = clArgs.lndConfigPath;
if(undefined !== process.env.LND_CONFIG_PATH) {
common.lnd_config_path = process.env.LND_CONFIG_PATH;
} else {
if(config.Authentication.lndConfigPath !== '' && undefined !== config.Authentication.lndConfigPath) {
common.lnd_config_path = config.Authentication.lndConfigPath;
@ -77,8 +78,8 @@ var validateConfigFile = (config) => {
}
}
if(undefined !== clArgs.bitcoindConfigPath) {
common.bitcoind_config_path = clArgs.bitcoindConfigPath;
if(undefined !== process.env.BITCOIND_CONFIG_PATH) {
common.bitcoind_config_path = process.env.BITCOIND_CONFIG_PATH;
} else {
if(config.Authentication.bitcoindConfigPath !== '' || undefined !== config.Authentication.bitcoindConfigPath) {
common.bitcoind_config_path = config.Authentication.bitcoindConfigPath;
@ -91,13 +92,15 @@ var validateConfigFile = (config) => {
if(undefined !== config.Authentication.enableLogging) {
common.enable_logging = config.Authentication.enableLogging;
var logFile = common.rtl_conf_file_path + '/RTL.log';
let exists = fs.existsSync(logFile);
common.log_file = common.rtl_conf_file_path + '/logs/RTL.log';
let exists = fs.existsSync(common.log_file);
if(exists) {
fs.writeFile(logFile, '', () => {});
fs.writeFile(common.log_file, '', () => {});
} else if (!exists && config.Authentication.enableLogging) {
try {
var createStream = fs.createWriteStream(logFile);
var dirname = path.dirname(common.log_file);
createDirectory(dirname);
var createStream = fs.createWriteStream(common.log_file);
createStream.end();
}
catch(err) {
@ -111,6 +114,65 @@ var validateConfigFile = (config) => {
}
}
var setSSOParams = () => {
if(undefined !== process.env.RTL_SSO) {
common.rtl_sso = process.env.RTL_SSO;
if(undefined !== process.env.LOGOUT_REDIRECT_LINK) {
common.logout_redirect_link = process.env.LOGOUT_REDIRECT_LINK;
}
if(undefined !== process.env.RTL_COOKIE_FILE) {
common.rtl_cookie_file = process.env.RTL_COOKIE_FILE;
} else {
common.rtl_cookie_file = common.rtl_conf_file_path + '/cookies/auth.cookie';
}
readCookie(common.rtl_cookie_file);
}
};
var createDirectory = (dirname) => {
try {
fs.mkdirSync(dirname);
} catch (err) {
if (err.code === 'EEXIST') {
return dirname;
}
if (err.code === 'ENOENT') {
throw new Error(`EACCES: permission denied, mkdir '${dirname}'`);
}
}
}
var readCookie = (cookieFile) => {
let exists = fs.existsSync(cookieFile);
if (exists) {
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
} else {
try {
var dirname = path.dirname(cookieFile);
createDirectory(dirname);
fs.writeFileSync(cookieFile, String.random(50));
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
}
catch(err) {
console.error('Something went wrong, unable to create cookie file!\n' + err);
throw new Error(err);
}
}
}
String.random = function (length) {
let radom13chars = function () {
return Math.random().toString(16).substring(2, 15).toUpperCase();
}
let loops = Math.ceil(length / 13);
return new Array(loops).fill(radom13chars).reduce((string, func) => {
return string + func();
}, '').substring(-length);
}
var setOptions = () => {
var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
options = {
@ -126,7 +188,7 @@ var setOptions = () => {
var errMsg = '';
var configFileExists = () => {
common.rtl_conf_file_path = (undefined !== clArgs.rtlConfFilePath) ? clArgs.rtlConfFilePath : path.normalize(__dirname);
common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH : path.normalize(__dirname);
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
let exists = fs.existsSync(RTLConfFile);
if (exists) {
@ -134,6 +196,7 @@ var configFileExists = () => {
setMacaroonPath(clArgs, config)
validateConfigFile(config);
setOptions();
setSSOParams();
} else {
try {
fs.writeFileSync(RTLConfFile, ini.stringify(defaultConfig));
@ -141,6 +204,7 @@ var configFileExists = () => {
setMacaroonPath(clArgs, config)
validateConfigFile(config);
setOptions();
setSSOParams();
}
catch(err) {
console.error('Something went wrong, unable to create config file!\n' + err);

@ -17,9 +17,11 @@ exports.getRTLConfig = (req, res, next) => {
} else {
const jsonConfig = ini.parse(data);
authSettings = {
nodeAuthType: (common.node_auth_type) ? common.node_auth_type : 'DEFAULT',
lndConfigPath: (common.lnd_config_path) ? common.lnd_config_path : '',
bitcoindConfigPath: (common.bitcoind_config_path) ? common.bitcoind_config_path : ''
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});
}

@ -7,75 +7,79 @@ var atob = require('atob');
var logger = require('./logger');
exports.authenticateUser = (req, res, next) => {
const RTLConfFilePath = common.rtl_conf_file_path + '/RTL.conf';
password = atob(req.body.password);
fs.readFile(RTLConfFilePath, 'utf8', function (err, data) {
if (err) {
logger.error('\r\nAuthenticate: 13: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!');
res.status(500).json({
message: "RTL Config Reading Failed!",
error: err
});
if(+common.rtl_sso) {
if (common.cookie === password) {
const token = jwt.sign(
{ user: 'Custom_User', lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
'default_secret_key'
);
res.status(200).json({ token: token });
} else {
const nodeAuthType = common.node_auth_type;
const macaroonPath = common.macaroon_path;
const lndConfigPath = (undefined !== common.lnd_config_path) ? common.lnd_config_path : '';
if(upperCase(nodeAuthType) === 'CUSTOM') {
const rtlPass = ini.parse(data).Authentication.rtlPass;
if (rtlPass === password) {
var rpcUser = 'Custom_User';
const token = jwt.sign(
{ user: rpcUser, lndConfigPath: lndConfigPath, macaroonPath: macaroonPath },
'RTL_default_secret_it_can_be_changed_by_user',
{ expiresIn: "1h" }
);
res.status(200).json({
token: token,
expiresIn: 3600
});
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Validation Failed!"
});
}
res.status(401).json({
message: "SSO Authentication Failed!",
error: "Please check app stack configurations!"
});
}
} else {
const RTLConfFilePath = common.rtl_conf_file_path + '/RTL.conf';
fs.readFile(RTLConfFilePath, 'utf8', function (err, data) {
if (err) {
logger.error('\r\nAuthenticate: 13: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!');
res.status(500).json({
message: "RTL Config Reading Failed!",
error: err
});
} else {
fs.readFile(lndConfigPath, 'utf8', function (err, data) {
if (err) {
logger.error('\r\nAuthenticate: 45: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!');
res.status(500).json({
message: "LND Config Reading Failed!",
error: err
});
if(upperCase(common.node_auth_type) === 'CUSTOM') {
const rtlPass = ini.parse(data).Authentication.rtlPass;
if (rtlPass === password) {
var rpcUser = 'Custom_User';
const token = jwt.sign(
{ user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
'default_secret_key'
);
res.status(200).json({ token: token });
} else {
const jsonLNDConfig = ini.parse(data);
if (undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcpass']) {
if (jsonLNDConfig.Bitcoind['bitcoind.rpcpass'] === password) {
var rpcUser = (undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcuser']) ? jsonLNDConfig.Bitcoind['bitcoind.rpcuser'] : '';
const token = jwt.sign(
{ user: rpcUser, lndConfigPath: lndConfigPath, macaroonPath: macaroonPath },
'RTL_default_secret_it_can_be_changed_by_user',
{ expiresIn: "1h" }
);
res.status(200).json({
token: token,
expiresIn: 3600
});
res.status(401).json({
message: "Authentication Failed!",
error: "Password Validation Failed!"
});
}
} else {
fs.readFile(common.lnd_config_path, 'utf8', function (err, data) {
if (err) {
logger.error('\r\nAuthenticate: 45: ' + JSON.stringify(Date.now()) + ': ERROR: RTL Config Reading Failed!');
res.status(500).json({
message: "LND Config Reading Failed!",
error: err
});
} else {
const jsonLNDConfig = ini.parse(data);
if (undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcpass']) {
if (jsonLNDConfig.Bitcoind['bitcoind.rpcpass'] === password) {
var rpcUser = (undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcuser']) ? jsonLNDConfig.Bitcoind['bitcoind.rpcuser'] : '';
const token = jwt.sign(
{ user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
'default_secret_key'
);
res.status(200).json({ token: token });
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Validation Failed!"
});
}
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Validation Failed!"
error: "Password Not Found In LND Config!"
});
}
} else {
res.status(401).json({
message: "Authentication Failed!",
error: "Password Not Found In LND Config!"
});
}
}
});
});
}
}
}
})
})
}
};

@ -1,12 +1,10 @@
var fs = require('fs');
var path = require('path');
var file_path = path.normalize(__dirname + '/..') + '/RTL.log';
var common = require('../common');
exports.info = (msgStr) => {
console.log('Console: ' + msgStr);
if(common.enable_logging) {
fs.appendFile(file_path, msgStr, function(err) {
fs.appendFile(common.log_file, msgStr, function(err) {
if (err) {
return ({ error: 'Updating Log Failed!' });
} else {
@ -19,7 +17,7 @@ exports.info = (msgStr) => {
exports.error = (msgStr) => {
console.error('Console: ' + msgStr);
if(common.enable_logging) {
fs.appendFile(file_path, msgStr, function(err) {
fs.appendFile(common.log_file, msgStr, function(err) {
if (err) {
return ({ error: 'Updating Log Failed!' });
} else {

@ -0,0 +1 @@
22678A7662FD5CB95AC8100F33F1FF248F6707B8EF87AED62DD5

2
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "rtl",
"version": "0.1.14-alpha",
"version": "0.1.15-alpha",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -1,10 +1,10 @@
{
"name": "rtl",
"version": "0.1.14-alpha",
"version": "0.1.15-alpha",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng build --prod --base-href /rtl/ && ng serve",
"start": "ng build --prod && ng serve",
"serve": "ng serve",
"prebuild": "node ./prebuild",
"build": "ng build --prod --base-href /rtl/",

@ -3,7 +3,7 @@ const jwt = require("jsonwebtoken");
module.exports = (req, res, next) => {
try {
const token = req.headers.authorization.split(" ")[1];
jwt.verify(token, "RTL_default_secret_it_can_be_changed_by_user");
jwt.verify(token, "default_secret_key");
next();
} catch (error) {
res.status(401).json({

@ -1,20 +1,17 @@
const app = require("./app");
const common = require("./common");
const debug = require("debug")("node-angular");
const http = require("http");
const normalizePort = val => {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
common.port = port;
return port;
}
return false;
};
@ -47,8 +44,7 @@ const onListening = () => {
debug("Listening on " + bind);
};
const port = normalizePort(process.env.PORT || "3000");
app.set("port", port);
const port = normalizePort(process.env.PORT || common.port);
const server = http.createServer(app);
server.on("error", onError);

Loading…
Cancel
Save