提交 07ac5996 编写于 作者: C CodFrm

Merge branch 'master' of github.com:CodFrm/cxmooc-tools

{
"name": "cxmooc-tools",
"version": "2.0.0",
"version": "2.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -1331,6 +1331,11 @@
"domelementtype": "1"
}
},
"double-ended-queue": {
"version": "2.1.0-0",
"resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz",
"integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw="
},
"duplexify": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.6.1.tgz",
......@@ -2847,6 +2852,7 @@
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz",
"integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==",
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -3741,6 +3747,26 @@
}
}
},
"redis": {
"version": "2.8.0",
"resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz",
"integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==",
"requires": {
"double-ended-queue": "^2.1.0-0",
"redis-commands": "^1.2.0",
"redis-parser": "^2.6.0"
}
},
"redis-commands": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.4.0.tgz",
"integrity": "sha512-cu8EF+MtkwI4DLIT0x9P8qNTLFhQD4jLfxLR0cCNkeGzs87FN6879JOJwNQR/1zD7aSYNbU0hgsV9zGY71Itvw=="
},
"redis-parser": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
"integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
},
"regex-not": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz",
......
......@@ -8,6 +8,7 @@ var path = require('path');
var fs = require('fs');
const http = require('http');
const https = require('https');
const redisCli = require('./redis');
var privateKey = fs.readFileSync(path.join(__dirname, './certificate/private.key'), 'utf8');
var certificate = fs.readFileSync(path.join(__dirname, './certificate/file.crt'), 'utf8');
......@@ -32,6 +33,7 @@ httpsServer.listen(SSLPORT, function () {
var mooc = new moocModel();
var redis = new redisCli();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
......@@ -49,6 +51,13 @@ app.use(express.static(path.join(__dirname, 'static'), {
maxage: '7d'
}));
//在线人数中间件
app.use(function (req, res, next) {
var ip = getClientIp(req);
redis.onlineAdd(ip);
next();
});
app.get('/', function (req, res) {
ret = '<h2>欢迎使用超星慕课刷课插件</h2><p>这个服务器将会记录你正确的答题答案,并不会记录你的任何账号信息</p>';
ret += '<p>并且接口没有任何权限,全由插件提交上传,还请大家不要故意上传错误的答案 (๑• . •๑) </p><br/>';
......@@ -143,11 +152,14 @@ function mergeAnswer(source, answer) {
}
app.get('/update', function (req, res) {
res.send({
version: config.version,
url: config.update,
enforce: config.enforce,
injection: config.injection
redis.onlineNum(function (err, data) {
res.send({
version: config.version,
url: config.update,
enforce: config.enforce,
injection: config.injection,
onlinenum: data
});
});
})
......
var redis = require('redis');
module.exports = function () {
var client = redis.createClient(6379,"127.0.0.1");
client.on("error", function (err) {
console.log("Redis error:" + err);
});
this.onlineAdd = function (ip) {
client.zadd("cxmooc:online", [Date.parse(new Date()), ip]);
}
this.onlineNum = function (call) {
var time = Date.parse(new Date());
client.zcount("cxmooc:online", [time - (5 * 60 * 1000), time], function (err, res) {
call(err, res)
});
}
return this
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册