From 19e9c5cd73579a92fa5c1ff15baead6679b418e4 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 15 Oct 2017 02:06:31 +0800 Subject: [PATCH] blank host --- blacklist | 1 + routes/all.js | 10 ++++++++-- routes/post.js | 5 ++--- tools/blank.js | 6 ++++++ 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 tools/blank.js diff --git a/blacklist b/blacklist index e109fe7..b84d973 100644 --- a/blacklist +++ b/blacklist @@ -3,3 +3,4 @@ username 0.0.0.0 175.180.108.110 219.133.201.230 +llj22.com \ No newline at end of file diff --git a/routes/all.js b/routes/all.js index 14f97bd..2765d7a 100644 --- a/routes/all.js +++ b/routes/all.js @@ -1,7 +1,13 @@ -var https = require('https'); +var logger = require('../tools/logger'); +var blank = require('../tools/blank'); module.exports = function (req, res, next) { - https.get(`https://api.prprpr.me/count/?id=DIYgod-DPlayer&action=add`); + + if (blank(req.headers.host)) { + logger.info(`Reject POST form ${req.headers.host} for black host.`); + res.send(`{"code": -6, "msg": "Rejected for black host."}`); + return; + } res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'); diff --git a/routes/post.js b/routes/post.js index dd3dd8f..f42ecd7 100644 --- a/routes/post.js +++ b/routes/post.js @@ -1,7 +1,7 @@ -var fs = require('fs'); var logger = require('../tools/logger'); var danmaku = require('../models/danmaku'); var redis = require('../tools/redis'); +var blank = require('../tools/blank'); function htmlEncode(str) { return str.replace(/&/g, "&") @@ -23,8 +23,7 @@ module.exports = function (req, res) { req.connection.socket.remoteAddress; // check black ip - var blanklist = fs.readFileSync('blacklist').toString().split('\n'); - if (blanklist.indexOf(ip.split(',')[0]) !== -1) { + if (blank(ip)) { logger.info(`Reject POST form ${ip} for black ip.`); res.send(`{"code": -1, "msg": "Rejected for black ip."}`); return; diff --git a/tools/blank.js b/tools/blank.js new file mode 100644 index 0000000..a517232 --- /dev/null +++ b/tools/blank.js @@ -0,0 +1,6 @@ +var fs = require('fs'); +var blanklist = fs.readFileSync('blacklist').toString().split('\n'); + +module.exports = function (text) { + return blanklist.indexOf(text.split(',')[0]) !== -1; +} \ No newline at end of file