Commit 784fb6da authored by Medicean's avatar Medicean

url blacklist

parent 40b6a2e4
......@@ -89,6 +89,10 @@ class Conf {
return require('../package.json');
}
get urlblacklist() {
return /(gov.cn|edu.cn)/
}
}
module.exports = new Conf();
......@@ -114,7 +114,10 @@ class Database {
*/
addShell(event, opts) {
logger.info('addShell', opts);
if(opts.base['url'].match(CONF.urlblacklist)){
event.returnValue = "Blacklist URL"
return
}
this._url2ip(opts.base['url'])
.then((ret) => {
this.cursor.insert({
......@@ -151,7 +154,10 @@ class Database {
const _new = opts.new;
const _old = opts.old;
if(_new.base['url'].match(CONF.urlblacklist)){
event.returnValue = "Blacklist URL"
return
}
this._url2ip(_new.base['url'])
.then((ret) => {
this.cursor.update({
......
......@@ -8,6 +8,7 @@
const fs = require('fs'),
iconv = require('iconv-lite'),
through = require('through'),
CONF = require('./config'),
superagent = require('superagent'),
superagentProxy = require('superagent-proxy');
......@@ -66,6 +67,9 @@ class Request {
*/
onAproxyTest(event, opts) {
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);
superagent
.get(opts['url'])
......@@ -92,7 +96,9 @@ class Request {
*/
onRequest(event, 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']);
// 设置headers
_request.set('User-Agent', USER_AGENT);
......@@ -138,7 +144,9 @@ class Request {
*/
onDownlaod(event, 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']);
......
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