diff --git a/cli/defaults/siteConfig.json b/cli/defaults/siteConfig.json
index 91efe08f..e84f5a45 100644
--- a/cli/defaults/siteConfig.json
+++ b/cli/defaults/siteConfig.json
@@ -30,7 +30,8 @@
"closedRegistration": false,
"serveOnlyApproved": false,
"publishOnlyApproved": false,
- "approvedChannels": []
+ "approvedChannels": [],
+ "publishingChannelWhitelist": []
},
"startup": {
"performChecks": true,
diff --git a/client/src/containers/AssetInfo/view.jsx b/client/src/containers/AssetInfo/view.jsx
index 10ec295c..a84e7062 100644
--- a/client/src/containers/AssetInfo/view.jsx
+++ b/client/src/containers/AssetInfo/view.jsx
@@ -36,7 +36,7 @@ class AssetInfo extends React.Component {
)}
- {claimViews && (
+ {claimViews ? (
- )}
+ ) : null}
{
+ if(line && line !== '') {
+ blockedAddresses.push(line);
+ }
+ });
+}
+
+const autoblockPublishMiddleware = (req, res, next) => {
+ let ip = (req.headers['x-forwarded-for'] || req.connection.remoteAddress).split(/,\s?/)[0];
+
+ if(blockedAddresses.indexOf(ip) !== -1) {
+ res.status(403).send(forbiddenMessage);
+ res.end();
+
+ return;
+ }
+
+ let count = ipCounts[ip] = (ipCounts[ip] || 0) + 1;
+
+ setTimeout(() => {
+ if(ipCounts[ip]) {
+ ipCounts[ip]--;
+ if(ipCounts[ip] === 0) {
+ delete ipCounts[ip];
+ }
+ }
+ }, 600000 /* 10 minute retainer */)
+
+ if(count === 10) {
+ logger.error(`Banning IP: ${ip}`);
+ blockedAddresses.push(ip);
+ res.status(403).send(forbiddenMessage);
+ res.end();
+
+ fs.appendFile(ipBanFile, ip + '\n', () => {});
+ } else {
+ next();
+ }
+}
+
+const autoblockPublishBodyMiddleware = (req, res, next) => {
+ console.log('REQUEST BODY', req.body)
+ if(req.body && publishingChannelWhitelist) {
+ let ip = (req.headers['x-forwarded-for'] || req.connection.remoteAddress).split(/,\s?/)[0];
+
+ const { channelName } = req.body;
+
+ console.log(channelName, publishingChannelWhitelist.indexOf(channelName) !== -1)
+ if(channelName && publishingChannelWhitelist.indexOf(channelName) !== -1) {
+ console.log('whitelisted channelName')
+ delete ipCounts[ip];
+ }
+ }
+ next();
+}
+
+module.exports = {
+ autoblockPublishMiddleware,
+ autoblockPublishBodyMiddleware,
+};
diff --git a/server/routes/api/index.js b/server/routes/api/index.js
index 6f102dac..71b673eb 100644
--- a/server/routes/api/index.js
+++ b/server/routes/api/index.js
@@ -1,6 +1,5 @@
-const fs = require('fs');
-
// middleware
+const { autoblockPublishMiddleware, autoblockPublishBodyMiddleware } = require('../../middleware/autoblockPublishMiddleware');
const multipartMiddleware = require('../../middleware/multipartMiddleware');
const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
// route handlers
@@ -25,55 +24,7 @@ const getTorList = require('../../controllers/api/tor');
const getBlockedList = require('../../controllers/api/blocked');
const getOEmbedData = require('../../controllers/api/oEmbed');
-const logger = require('winston');
-const ipBanFile = './config/ipBan.txt';
-const forbiddenMessage = 'Forbidden
If you are seeing this by mistake, please contact us using https://chat.lbry.io/';
-let ipCounts = {};
-let blockedAddresses = [];
-
-if(fs.existsSync(ipBanFile)) {
- const lineReader = require('readline').createInterface({
- input: require('fs').createReadStream(ipBanFile),
- });
-
- lineReader.on('line', (line) => {
- if(line && line !== '') {
- blockedAddresses.push(line);
- }
- });
-}
-
-const autoblockPublishMiddleware = (req, res, next) => {
- let ip = (req.headers['x-forwarded-for'] || req.connection.remoteAddress).split(/,\s?/)[0];
-
- if(blockedAddresses.indexOf(ip) !== -1) {
- res.status(403).send(forbiddenMessage);
- res.end();
-
- return;
- }
-
- let count = ipCounts[ip] = (ipCounts[ip] || 0) + 1;
-
- setTimeout(() => {
- ipCounts[ip]--;
- if(ipCounts[ip] === 0) {
- delete ipCounts[ip];
- }
- }, 600000 /* 10 minute retainer */)
-
- if(count === 10) {
- logger.error(`Banning IP: ${ip}`);
- blockedAddresses.push(ip);
- res.status(403).send(forbiddenMessage);
- res.end();
-
- fs.appendFile(ipBanFile, ip + '\n', () => {});
- } else {
- next();
- }
-}
module.exports = {
// homepage routes
@@ -95,7 +46,7 @@ module.exports = {
'/api/claim/get/:name/:claimId': { controller: [ torCheckMiddleware, claimGet ] },
'/api/claim/list/:name': { controller: [ torCheckMiddleware, claimList ] },
'/api/claim/long-id': { method: 'post', controller: [ torCheckMiddleware, claimLongId ] }, // note: should be a 'get'
- '/api/claim/publish': { method: 'post', controller: [ torCheckMiddleware, autoblockPublishMiddleware, multipartMiddleware, claimPublish ] },
+ '/api/claim/publish': { method: 'post', controller: [ torCheckMiddleware, autoblockPublishMiddleware, multipartMiddleware, autoblockPublishBodyMiddleware, claimPublish ] },
'/api/claim/resolve/:name/:claimId': { controller: [ torCheckMiddleware, claimResolve ] },
'/api/claim/short-id/:longId/:name': { controller: [ torCheckMiddleware, claimShortId ] },
'/api/claim/views/:claimId': { controller: [ torCheckMiddleware, claimViews ] },