From 94fd90751365d48aaf14af261a3537701474d034 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 28 Jun 2017 12:55:17 -0700 Subject: [PATCH 1/3] separating wallets to pay, claim, and change --- config/custom-environment-variables.json | 4 +++- config/default.json | 4 +++- config/development.json | 4 +++- config/production.json | 4 +++- config/test.json | 4 +++- helpers/libraries/publishHelpers.js | 8 +++++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index be110732..aa3fad52 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "LBRY_WALLET_ADDRESS" + "LbryPayAddress": "LBRY_PAY_ADDRESS", + "LbryClaimAddress": "LBRY_CLAIM_ADDRESS", + "LbryChangeAddress": "LBRY_CHANGE_ADDRESS" }, "Database": { "MySqlConnectionUri": "MYSQL_CONNECTION_STRING" diff --git a/config/default.json b/config/default.json index 546378c7..a50953a0 100644 --- a/config/default.json +++ b/config/default.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "none" diff --git a/config/development.json b/config/development.json index 38c7affe..691528f2 100644 --- a/config/development.json +++ b/config/development.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "UA-100747990-1" diff --git a/config/production.json b/config/production.json index 56fde915..05161783 100644 --- a/config/production.json +++ b/config/production.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "UA-60403362-2" diff --git a/config/test.json b/config/test.json index b74d2997..bab71bfa 100644 --- a/config/test.json +++ b/config/test.json @@ -1,6 +1,8 @@ { "WalletConfig": { - "LbryAddress": "none" + "LbryPayAddress": "none", + "LbryClaimAddress": "none", + "LbryChangeAddress": "none" }, "AnalyticsConfig":{ "GoogleId": "UA-100747990-1" diff --git a/helpers/libraries/publishHelpers.js b/helpers/libraries/publishHelpers.js index 57a87208..d483eeed 100644 --- a/helpers/libraries/publishHelpers.js +++ b/helpers/libraries/publishHelpers.js @@ -1,11 +1,13 @@ const logger = require('winston'); const config = require('config'); -const walletAddress = config.get('WalletConfig.LbryAddress'); const fs = require('fs'); module.exports = { createPublishParams: (name, filePath, license, nsfw) => { logger.debug(`Creating Publish Parameters for "${name}"`); + // const payAddress = config.get('WalletConfig.LbryPayAddress'); + const claimAddress = config.get('WalletConfig.LbryClaimAddress'); + const changeAddress = config.get('WalletConfig.LbryChangeAddress'); // ensure nsfw is a boolean if (nsfw === false) { nsfw = false; @@ -32,8 +34,8 @@ module.exports = { license, nsfw, }, - claim_address : walletAddress, - change_address: walletAddress, + claim_address : claimAddress, + change_address: changeAddress, }; logger.debug('publishParams:', publishParams); return publishParams; -- 2.45.2 From c0174fb300d10881bfe97e58c9dddd41f6a1f477 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 29 Jun 2017 10:51:23 -0700 Subject: [PATCH 2/3] added ipaddress test logs. ignored change address. --- helpers/libraries/analytics.js | 6 ++++++ helpers/libraries/publishHelpers.js | 6 +++--- routes/serve-routes.js | 18 ++++++++++-------- server.js | 4 ++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/helpers/libraries/analytics.js b/helpers/libraries/analytics.js index a91ac73b..84ee2618 100644 --- a/helpers/libraries/analytics.js +++ b/helpers/libraries/analytics.js @@ -4,9 +4,15 @@ const logger = require('winston'); module.exports = { postToAnalytics: (action, url, ipAddress, result) => { logger.silly('creating record for analytics'); + // make sure the result is a string if (result && (typeof result !== 'string')) { result = result.toString(); } + // // make sure the ip address(es) are a string + if (ipAddress && (typeof ipAddress !== 'string')) { + ipAddress = ipAddress.toString(); + } + // create record in the db db.Analytics.create({ action, url, diff --git a/helpers/libraries/publishHelpers.js b/helpers/libraries/publishHelpers.js index d483eeed..1d943054 100644 --- a/helpers/libraries/publishHelpers.js +++ b/helpers/libraries/publishHelpers.js @@ -7,7 +7,7 @@ module.exports = { logger.debug(`Creating Publish Parameters for "${name}"`); // const payAddress = config.get('WalletConfig.LbryPayAddress'); const claimAddress = config.get('WalletConfig.LbryClaimAddress'); - const changeAddress = config.get('WalletConfig.LbryChangeAddress'); + // const changeAddress = config.get('WalletConfig.LbryChangeAddress'); // ensure nsfw is a boolean if (nsfw === false) { nsfw = false; @@ -34,8 +34,8 @@ module.exports = { license, nsfw, }, - claim_address : claimAddress, - change_address: changeAddress, + claim_address: claimAddress, + //change_address: changeAddress, }; logger.debug('publishParams:', publishParams); return publishParams; diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 827054f6..d4ef52ab 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -34,31 +34,33 @@ function serveFile ({ fileName, fileType, filePath }, res) { module.exports = (app) => { // route to fetch one free public claim - app.get('/:name/:claim_id', ({ originalUrl, params, ip }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ip}`); + app.get('/:name/:claim_id', ({ originalUrl, params, ips, headers }, res) => { + logger.debug(`GET request on ${originalUrl} from ${ips}`); + logger.debug(`headers ${headers}`); // begin image-serve processes serveController .getClaimByClaimId(params.name, params.claim_id) .then(fileInfo => { - postToAnalytics('serve', originalUrl, ip, 'success'); + postToAnalytics('serve', originalUrl, ips, 'success'); serveFile(fileInfo, res); }) .catch(error => { - errorHandlers.handleRequestError('serve', originalUrl, ip, error, res); + errorHandlers.handleRequestError('serve', originalUrl, ips, error, res); }); }); // route to fetch one free public claim - app.get('/:name', ({ originalUrl, params, ip }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ip}`); + app.get('/:name', ({ originalUrl, params, ips, headers }, res) => { + logger.debug(`GET request on ${originalUrl} from ${ips}`); + logger.debug(`headers ${headers}`); // begin image-serve processes serveController .getClaimByName(params.name) .then(fileInfo => { - postToAnalytics('serve', originalUrl, ip, 'success'); + postToAnalytics('serve', originalUrl, ips, 'success'); serveFile(fileInfo, res); }) .catch(error => { - errorHandlers.handleRequestError('serve', originalUrl, ip, error, res); + errorHandlers.handleRequestError('serve', originalUrl, ips, error, res); }); }); }; diff --git a/server.js b/server.js index 22c6fca2..23e3a442 100644 --- a/server.js +++ b/server.js @@ -16,12 +16,12 @@ require('./config/loggerSetup.js')(winston, logLevel, logDir); // set port const PORT = 3000; -// initialize express app +// create an Express application const app = express(); // require our models for syncing const db = require('./models'); -// make express look in the public directory for assets (css/js/img) +// serve static files from public directory (css/js/img) app.use(express.static(`${__dirname}/public`)); // configure express app -- 2.45.2 From 461af60c1657d83656b864faf2ca351e5f71ab8e Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 29 Jun 2017 12:35:36 -0700 Subject: [PATCH 3/3] commented out change address --- helpers/libraries/publishHelpers.js | 4 ++-- routes/home-routes.js | 5 +++-- routes/serve-routes.js | 14 ++++++++------ server.js | 2 ++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/helpers/libraries/publishHelpers.js b/helpers/libraries/publishHelpers.js index 1d943054..045f5ee6 100644 --- a/helpers/libraries/publishHelpers.js +++ b/helpers/libraries/publishHelpers.js @@ -8,7 +8,7 @@ module.exports = { // const payAddress = config.get('WalletConfig.LbryPayAddress'); const claimAddress = config.get('WalletConfig.LbryClaimAddress'); // const changeAddress = config.get('WalletConfig.LbryChangeAddress'); - // ensure nsfw is a boolean + // filter nsfw and ensure it is a boolean if (nsfw === false) { nsfw = false; } else if (nsfw.toLowerCase === 'false') { @@ -35,7 +35,7 @@ module.exports = { nsfw, }, claim_address: claimAddress, - //change_address: changeAddress, + // change_address: changeAddress, }; logger.debug('publishParams:', publishParams); return publishParams; diff --git a/routes/home-routes.js b/routes/home-routes.js index 1d747edf..d36d8f6c 100644 --- a/routes/home-routes.js +++ b/routes/home-routes.js @@ -3,8 +3,9 @@ const { postToAnalytics } = require('../helpers/libraries/analytics'); module.exports = app => { // route for the home page - app.get('/', ({ originalUrl, ip }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ip}`); + app.get('/', ({ originalUrl, ip, headers }, res) => { + logger.verbose(`GET request on ${originalUrl} from ${ip}`); + logger.debug(`headers ${JSON.stringify(headers)}`); res.status(200).render('index'); }); // a catch-all route if someone visits a page that does not exist diff --git a/routes/serve-routes.js b/routes/serve-routes.js index d4ef52ab..16025638 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -34,9 +34,10 @@ function serveFile ({ fileName, fileType, filePath }, res) { module.exports = (app) => { // route to fetch one free public claim - app.get('/:name/:claim_id', ({ originalUrl, params, ips, headers }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ips}`); - logger.debug(`headers ${headers}`); + app.get('/:name/:claim_id', ({ originalUrl, params, ip, ips, headers }, res) => { + logger.verbose(`GET request on ${originalUrl} from ${ip}`); + logger.debug(`ips >> ${JSON.stringify(ips)}`); + logger.debug(`headers >> ${JSON.stringify(headers)}`); // begin image-serve processes serveController .getClaimByClaimId(params.name, params.claim_id) @@ -49,9 +50,10 @@ module.exports = (app) => { }); }); // route to fetch one free public claim - app.get('/:name', ({ originalUrl, params, ips, headers }, res) => { - logger.debug(`GET request on ${originalUrl} from ${ips}`); - logger.debug(`headers ${headers}`); + app.get('/:name', ({ originalUrl, params, ip, ips, headers }, res) => { + logger.verbose(`GET request on ${originalUrl} from ${ip}`); + logger.debug(`ips >> ${JSON.stringify(ips)}`); + logger.debug(`headers >> ${JSON.stringify(headers)}`); // begin image-serve processes serveController .getClaimByName(params.name) diff --git a/server.js b/server.js index 23e3a442..6d7e9102 100644 --- a/server.js +++ b/server.js @@ -25,6 +25,7 @@ const db = require('./models'); app.use(express.static(`${__dirname}/public`)); // configure express app +app.enable('trust proxy'); // trust the proxy to get ip address for us app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(siofu.router); @@ -68,6 +69,7 @@ const http = require('./routes/sockets-routes.js')(app, siofu, hostedContentPath // start server db.sequelize.sync().then(() => { http.listen(PORT, () => { + winston.info('Trusting proxy?', app.get('trust proxy')); winston.info(`Server is listening on PORT ${PORT}`); }); }); -- 2.45.2