Commit 784fb6da authored by Medicean's avatar Medicean

url blacklist

parent 40b6a2e4
...@@ -89,6 +89,10 @@ class Conf { ...@@ -89,6 +89,10 @@ class Conf {
return require('../package.json'); return require('../package.json');
} }
get urlblacklist() {
return /(gov.cn|edu.cn)/
}
} }
module.exports = new Conf(); module.exports = new Conf();
...@@ -114,7 +114,10 @@ class Database { ...@@ -114,7 +114,10 @@ class Database {
*/ */
addShell(event, opts) { addShell(event, opts) {
logger.info('addShell', opts); logger.info('addShell', opts);
if(opts.base['url'].match(CONF.urlblacklist)){
event.returnValue = "Blacklist URL"
return
}
this._url2ip(opts.base['url']) this._url2ip(opts.base['url'])
.then((ret) => { .then((ret) => {
this.cursor.insert({ this.cursor.insert({
...@@ -151,7 +154,10 @@ class Database { ...@@ -151,7 +154,10 @@ class Database {
const _new = opts.new; const _new = opts.new;
const _old = opts.old; const _old = opts.old;
if(_new.base['url'].match(CONF.urlblacklist)){
event.returnValue = "Blacklist URL"
return
}
this._url2ip(_new.base['url']) this._url2ip(_new.base['url'])
.then((ret) => { .then((ret) => {
this.cursor.update({ this.cursor.update({
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
const fs = require('fs'), const fs = require('fs'),
iconv = require('iconv-lite'), iconv = require('iconv-lite'),
through = require('through'), through = require('through'),
CONF = require('./config'),
superagent = require('superagent'), superagent = require('superagent'),
superagentProxy = require('superagent-proxy'); superagentProxy = require('superagent-proxy');
...@@ -66,6 +67,9 @@ class Request { ...@@ -66,6 +67,9 @@ class Request {
*/ */
onAproxyTest(event, opts) { onAproxyTest(event, opts) {
logger.debug('aProxy::Test Proxy -', opts['aproxyuri'], '- Connect to ', opts['url']); logger.debug('aProxy::Test Proxy -', opts['aproxyuri'], '- Connect to ', opts['url']);
if(opts['url'].match(CONF.urlblacklist)) {
return event.sender.send('request-error-' + opts['hash'], "Blacklist URL");
}
superagentProxy(superagent); superagentProxy(superagent);
superagent superagent
.get(opts['url']) .get(opts['url'])
...@@ -92,7 +96,9 @@ class Request { ...@@ -92,7 +96,9 @@ class Request {
*/ */
onRequest(event, opts) { onRequest(event, opts) {
logger.debug('onRequest::opts', opts); logger.debug('onRequest::opts', opts);
if(opts['url'].match(CONF.urlblacklist)) {
return event.sender.send('request-error-' + opts['hash'], "Blacklist URL");
}
const _request = superagent.post(opts['url']); const _request = superagent.post(opts['url']);
// 设置headers // 设置headers
_request.set('User-Agent', USER_AGENT); _request.set('User-Agent', USER_AGENT);
...@@ -138,7 +144,9 @@ class Request { ...@@ -138,7 +144,9 @@ class Request {
*/ */
onDownlaod(event, opts) { onDownlaod(event, opts) {
logger.debug('onDownlaod', opts); logger.debug('onDownlaod', opts);
if(opts['url'].match(CONF.urlblacklist)) {
return event.sender.send('request-error-' + opts['hash'], "Blacklist URL");
}
// 创建文件流 // 创建文件流
const rs = fs.createWriteStream(opts['path']); const rs = fs.createWriteStream(opts['path']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment