mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 20:10:40 +03:00
Added IP list to forum internal
This commit is contained in:
parent
e1cca3966e
commit
34444c65db
5 changed files with 26 additions and 11 deletions
9
index.js
9
index.js
|
@ -4,6 +4,7 @@ const { def_theme, forum_name, desp } = require("./config.json"),
|
|||
ipBlock = require('express-ip-block'),
|
||||
session = require('express-session'),
|
||||
bodyParser = require('body-parser'),
|
||||
requestIp = require('request-ip'),
|
||||
port = process.env.PORT || 3000,
|
||||
mongoose = require("mongoose"),
|
||||
express = require('express'),
|
||||
|
@ -20,9 +21,11 @@ app.set("view engine", "ejs");
|
|||
|
||||
app.use(
|
||||
session({ secret: 'secret', resave: true, saveUninitialized: true }),
|
||||
express.static("public"), express.json(), ipBlock(app.ips),
|
||||
express.static("public"), express.json(), ipBlock(app.ips), requestIp.mw(),
|
||||
async (req, res, next) => {
|
||||
req.user = req.session.userID ? await UserModel.findOneAndUpdate({ id: req.session.userID }, { lastSeen: Date.now() }) : null;
|
||||
req.user = req.session.userID ? await UserModel.findOneAndUpdate({ id: req.session.userID }, {
|
||||
lastSeen: Date.now(), $addToSet: { ips: req.clientIp }
|
||||
}) : null;
|
||||
|
||||
res.reply = (page, options = {}, status = 200) => res.status(status)
|
||||
.render(page, { user: req.user, theme: req.user?.theme || def_theme, forum_name, desp, ...options });
|
||||
|
@ -45,4 +48,4 @@ for (const file of fs.readdirSync("./routes"))
|
|||
|
||||
app.all("*", (req, res) => res.error(404, "We have not got this page."));
|
||||
|
||||
app.listen(port, () => console.log(forum_name + "-forum on port:", port));
|
||||
app.listen(port, () => console.log(`${forum_name}-forum on port:`, port));
|
|
@ -2,7 +2,7 @@ const mongoose = require("mongoose")
|
|||
|
||||
const schema = new mongoose.Schema({
|
||||
username: { type: String, unique: true },
|
||||
password: String, ips: [String],
|
||||
password: String,
|
||||
id: { type: String, unique: true }
|
||||
});
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ const schema = new mongoose.Schema({
|
|||
admin: { type: Boolean, default: false },
|
||||
theme: { type: String, default: def_theme },
|
||||
lastSeen: { type: Date, default: Date.now, select: false },
|
||||
hideLastSeen: { type: Boolean, default: false }
|
||||
|
||||
hideLastSeen: { type: Boolean, default: false },
|
||||
ips: { type: [String], select: false }
|
||||
});
|
||||
|
||||
schema.methods.takeId = async function () {
|
||||
|
|
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -18,7 +18,8 @@
|
|||
"express-rate-limit": "^6.6.0",
|
||||
"express-session": "^1.17.2",
|
||||
"mongoose": "^6.6.0",
|
||||
"multer": "^1.4.5-lts.1"
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"request-ip": "^3.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
|
@ -1415,6 +1416,11 @@
|
|||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/request-ip": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz",
|
||||
"integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA=="
|
||||
},
|
||||
"node_modules/rimraf": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||
|
@ -2828,6 +2834,11 @@
|
|||
"util-deprecate": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"request-ip": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz",
|
||||
"integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA=="
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
"express-rate-limit": "^6.6.0",
|
||||
"express-session": "^1.17.2",
|
||||
"mongoose": "^6.6.0",
|
||||
"multer": "^1.4.5-lts.1"
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"request-ip": "^3.3.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue