Compare commits
No commits in common. "4e99509d9674895e11484412de8984dfb3ed0ad4" and "794b84a15259ccc470fa2fe406e4abbc85eabb1b" have entirely different histories.
4e99509d96
...
794b84a152
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,4 +8,3 @@
|
|||||||
!/README.md
|
!/README.md
|
||||||
!/files/www/qonq.js
|
!/files/www/qonq.js
|
||||||
!/favicon.ico
|
!/favicon.ico
|
||||||
!/antiscrape.js
|
|
@ -1,15 +0,0 @@
|
|||||||
// someone could iterate over all ~1.6 million possible file codes to download all files.
|
|
||||||
// prevent this by banning IP addresses that request too many non-existant files.
|
|
||||||
|
|
||||||
var ip404 = {};
|
|
||||||
module.exports = (req, res, next) => {
|
|
||||||
if (ip404[req.ip]?.size > 10)
|
|
||||||
return res.status(403).send("Banned");
|
|
||||||
res.on("finish", () => {
|
|
||||||
if (res.statusCode == 404 && req.filecode) {
|
|
||||||
if (!ip404[req.ip]) ip404[req.ip] = new Set();
|
|
||||||
ip404[req.ip].add(req.filecode);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
next();
|
|
||||||
};
|
|
9
qonq.js
9
qonq.js
@ -55,17 +55,16 @@ app.post("*", (req, res, next) => {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(require("./antiscrape"));
|
|
||||||
|
|
||||||
app.get(['/', '/:code/', '/:code/*'], function(req, res, next){
|
app.get(['/', '/:code/', '/:code/*'], function(req, res, next){
|
||||||
var subdomain = req.subdomains.at(-1);
|
var subdomain = req.subdomains.at(-1);
|
||||||
req.filecode = subdomain || req.params.code;
|
var filecode = subdomain || req.params.code;
|
||||||
if (!req.filecode) req.filecode = "www";
|
if (!filecode) filecode = "www";
|
||||||
var webroot = path.join(FILES_DIR, req.filecode);
|
var webroot = path.join(FILES_DIR, filecode);
|
||||||
fs.readdir(webroot, function(error, webrootdirlist) {
|
fs.readdir(webroot, function(error, webrootdirlist) {
|
||||||
if (error) return void next(error.code == "ENOENT" ? "route" : error);
|
if (error) return void next(error.code == "ENOENT" ? "route" : error);
|
||||||
if (webrootdirlist.length > 1) {
|
if (webrootdirlist.length > 1) {
|
||||||
if (subdomain) req.url = path.join(req.filecode, req.url);
|
if (subdomain) req.url = path.join(filecode, req.url);
|
||||||
next();
|
next();
|
||||||
} else if (webrootdirlist.length == 1) {
|
} else if (webrootdirlist.length == 1) {
|
||||||
res.sendFile(webrootdirlist[0], {
|
res.sendFile(webrootdirlist[0], {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user