...
|
...
|
@@ -4,72 +4,121 @@ const Router = require('koa-router'); |
|
|
const ApiCache = require('../../ci/api_cache');
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const getter = require('../../zookeeper/getter');
|
|
|
const setter = require('../../zookeeper/setter');
|
|
|
const tester = require('../../zookeeper/tester');
|
|
|
const ZookeeperModel = require('../models/zookeeperModel');
|
|
|
let zookeeperModel = new ZookeeperModel();
|
|
|
|
|
|
let r = new Router();
|
|
|
var process = {
|
|
|
TO_VALIDATE_CODE: '跳转全局验证码解锁',
|
|
|
REDIRECT_403: '返回403'
|
|
|
};
|
|
|
|
|
|
const risk = {
|
|
|
index: async(ctx, next) => {
|
|
|
// const regexp = /pc:limiter:faker:(.*)/;
|
|
|
// const threshold = ctx.request.query.threshold || 100;
|
|
|
// const limit = ctx.request.query.limit || 10;
|
|
|
|
|
|
// let hosts = await MemcachedHost.findAll();
|
|
|
|
|
|
// const selectedHosts = _.filter(hosts, host => {
|
|
|
// const isCurrent = host.host === ctx.request.query.node;
|
|
|
// if (isCurrent) {
|
|
|
// host.isCurrent = true;
|
|
|
// }
|
|
|
// return isCurrent;
|
|
|
// });
|
|
|
|
|
|
// let results = await Promise.all(_.map(selectedHosts, (h) => {
|
|
|
// return (new ApiCache(h.host)).find((key) => {
|
|
|
// return regexp.test(key);
|
|
|
// });
|
|
|
// }));
|
|
|
|
|
|
// let list = [];
|
|
|
|
|
|
// if (results && results[0]) {
|
|
|
// Object.keys(results[0]).forEach((key) => {
|
|
|
// const index = results[0][key];
|
|
|
|
|
|
// if (index > threshold) {
|
|
|
// list.push({
|
|
|
// ip: ((key) => {
|
|
|
// const m = key.match(regexp);
|
|
|
|
|
|
// return m && m.length > 0 ? m[1] : 'Unknown';
|
|
|
// })(key),
|
|
|
// index: index
|
|
|
// })
|
|
|
// }
|
|
|
// });
|
|
|
// }
|
|
|
|
|
|
// list = _.orderBy(list, (item) => {
|
|
|
// return item.index;
|
|
|
// }, 'desc').slice(0, limit);
|
|
|
console.log(11111)
|
|
|
let ret = await zookeeperModel.getPath('/risk');
|
|
|
|
|
|
if (ret) {
|
|
|
ret = JSON.parse(ret);
|
|
|
}
|
|
|
|
|
|
_.each(ret, function(o) {
|
|
|
o.process = process[o.process];
|
|
|
});
|
|
|
|
|
|
await ctx.render('action/risk_management', {
|
|
|
list: ret
|
|
|
});
|
|
|
},
|
|
|
add: async(ctx, next) => {
|
|
|
var data = {};
|
|
|
var key = ctx.request.query.key;
|
|
|
var oldRet = '';
|
|
|
|
|
|
if (key) {
|
|
|
oldRet = await zookeeperModel.getPath('/risk');
|
|
|
|
|
|
if (oldRet) {
|
|
|
oldRet = JSON.parse(oldRet);
|
|
|
}
|
|
|
|
|
|
data = _.find(oldRet, function(o) {
|
|
|
return `${o.app}/${o.route}` === key;
|
|
|
});
|
|
|
|
|
|
data.state = data.state === 'on';
|
|
|
data.isJump = data.process === 'TO_VALIDATE_CODE';
|
|
|
}
|
|
|
|
|
|
await ctx.render('action/add_risk', {
|
|
|
data: data
|
|
|
});
|
|
|
},
|
|
|
setter: async(ctx) => {
|
|
|
let params = ctx.request.body;
|
|
|
let path = '/risk';
|
|
|
let str = `${params.app}/${params.route}`;
|
|
|
let oldRet = await zookeeperModel.getPath('/risk');
|
|
|
|
|
|
if (!oldRet) {
|
|
|
oldRet = [];
|
|
|
} else {
|
|
|
oldRet = JSON.parse(oldRet);
|
|
|
}
|
|
|
|
|
|
_.remove(oldRet, function(o) {
|
|
|
return `${o.app}/${o.route}` === str;
|
|
|
});
|
|
|
|
|
|
oldRet.push(params);
|
|
|
|
|
|
let result = await zookeeperModel.setPath(path, JSON.stringify(oldRet));
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
ctx.body = {
|
|
|
code: 200,
|
|
|
message: 'update success'
|
|
|
};
|
|
|
} else {
|
|
|
ctx.body = {
|
|
|
code: 500,
|
|
|
message: 'update fail,Please retry'
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
remove: async(ctx) => {
|
|
|
let key = ctx.request.body.key;
|
|
|
let path = '/risk';
|
|
|
let oldRet = await zookeeperModel.getPath(path);
|
|
|
|
|
|
if (oldRet) {
|
|
|
oldRet = JSON.parse(oldRet);
|
|
|
}
|
|
|
|
|
|
_.remove(oldRet, function(o) {
|
|
|
return `${o.app}/${o.route}` === key;
|
|
|
});
|
|
|
|
|
|
let result = await zookeeperModel.setPath(path, JSON.stringify(oldRet));
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
ctx.body = {
|
|
|
code: 200,
|
|
|
message: 'remove success'
|
|
|
};
|
|
|
} else {
|
|
|
ctx.body = {
|
|
|
code: 500,
|
|
|
message: 'remove fail,Please retry'
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
r.get('/risk_management', risk.index);
|
|
|
r.get('/add_risk', risk.add);
|
|
|
r.post('/add_risk_data', risk.setter);
|
|
|
r.post('/setter', risk.setter);
|
|
|
r.post('/remove', risk.remove);
|
|
|
|
|
|
module.exports = r; |
|
|
\ No newline at end of file |
...
|
...
|
|