From e9c2df8e9b929c521ac30b7b44a90b83fa20399e Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer
Date: Wed, 14 Aug 2019 09:05:28 +0200
Subject: [PATCH] /stuff file browser, minor tweaks
---
logger.js | 2 +-
merger.js | 5 ++++
server.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++----
views/main.ejs | 8 ++++--
views/man.ejs | 2 +-
5 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/logger.js b/logger.js
index 884698d..bd848f0 100644
--- a/logger.js
+++ b/logger.js
@@ -59,7 +59,7 @@ function Log(s, c, b) {
function LogReq(req, toFile, sc) {
try {
var ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress;
- var logEntry = ip + DELIM + req.headers['user-agent'] +
+ var logEntry = ip + DELIM + req.hostname + DELIM + req.headers['user-agent'] +
DELIM + req.method + DELIM;
logEntry += req.url;
diff --git a/merger.js b/merger.js
index de43b90..2833705 100644
--- a/merger.js
+++ b/merger.js
@@ -218,6 +218,8 @@ function PrintDB(r, olds) {
maxLength = r.Subjects[i].Name.length;
}
+ let qcount = 0;
+
for (var i = 0; i < r.length; i++) {
let line = i;
if (line < 10)
@@ -251,12 +253,15 @@ function PrintDB(r, olds) {
line += " ";
line += r.Subjects[i].length;
+ qcount += r.Subjects[i].length;
line += " db";
console.log(line);
}
+ console.log("Total questions: " + qcount);
+
PrintLN();
}
diff --git a/server.js b/server.js
index ef82325..048b79d 100644
--- a/server.js
+++ b/server.js
@@ -35,6 +35,7 @@ const utils = require('./utils.js');
const actions = require('./actions.js');
const stat = require('./stat.js');
+const listedFiles = "./public/files";
const recivedFiles = "public/recivedfiles";
const uloadFiles = "public/f";
const staticFile = "public/data/static";
@@ -84,9 +85,9 @@ app.use(function(req, res, next) {
});
app.use(express.static('public'));
app.use(busboy({
- limits: {
- fileSize: 10 * 1024 * 1024
- }
+ limits: {
+ fileSize: 10000 * 1024 * 1024
+ }
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
@@ -97,6 +98,8 @@ app.use(bodyParser.json({
limit: '5mb'
}));
+// --------------------------------------------------------------
+
app.get('/', function(req, res) {
res.render('main', {
siteurl: siteUrl,
@@ -225,9 +228,7 @@ function UploadFile(req, res, path, next) {
utils.CreatePath(path, true);
let d = new Date();
- let fsplit = filename.split('.');
- let fn = d.getHours() + "" + d.getMinutes() + "" + d.getSeconds() + "." + fsplit[fsplit.length -
- 1];
+ let fn = d.getHours() + "" + d.getMinutes() + "" + d.getSeconds() + "_" + filename;
fstream = fs.createWriteStream(path + "/" + fn);
file.pipe(fstream);
@@ -255,6 +256,68 @@ app.route('/badtestsender').post(function(req, res, next) {
logger.LogReq(req);
});
+// -----------------------------------------------------------------------------------------------
+
+app.get('/stuff*', function(req, res) {
+
+ let curr = listedFiles + "/" + req.url.substring("/stuff/".length, req.url.length).split('?')[0];
+ let relPath = curr.substring("./public/files".length, curr.length);
+
+ if (relPath[relPath.length - 1] != "/")
+ relPath += "/";
+
+ let t = relPath.split("/");
+ let prevDir = "";
+ for (let i = 0; i < t.length - 2; i++)
+ prevDir += t[i] + "/";
+
+
+ // curr = curr.replace(/\//g, "/");
+ // relPath = relPath.replace(/\//g, "/");
+
+ logger.LogReq(req);
+
+ if (fs.lstatSync(curr).isDirectory()) {
+ if (curr[curr.length - 1] != "/")
+ curr += "/";
+
+ let f = [];
+
+ fs.readdirSync(curr).forEach((item) => {
+ if (item[0] !== '.') {
+ let res = {name:item};
+ let stats = fs.statSync(curr + "/" + item);
+
+ let fileSizeInBytes = stats["size"];
+ res.size = Math.round(fileSizeInBytes / 1000000);
+
+ res.path = relPath;
+ if (res.path[res.path.length - 1] != "/")
+ res.path += "/";
+ res.path += item;
+
+ res.mtime = stats["mtime"].toLocaleString();
+
+ f.push(res);
+ }
+ });;
+
+ res.render('folders', {
+ folders: f,
+ dirname: relPath,
+ prevDir
+ });
+ } else {
+ let fileStream = fs.createReadStream(curr);
+ fileStream.pipe(res);
+ }
+
+ return;
+});
+
+
+// -----------------------------------------------------------------------------------------------
+
app.get('*', function(req, res) {
res.render('404');
res.status(404);
diff --git a/views/main.ejs b/views/main.ejs
index cbe46f5..03170e0 100644
--- a/views/main.ejs
+++ b/views/main.ejs
@@ -35,7 +35,6 @@
+ <% /*
@@ -54,18 +56,18 @@ greasyforkon |
Hibát kiváltó teszt feltöltése
-
Letiltva, mert nincs használva :c
Ha egy kérdésre mindig helytelenül talál választ a userscript (vagy egyéb hibát észlelsz), akkor azon az oldalon nyomj egy ctrl-s -t. Ez lementi a weboldalt úgy ahogy van egy mappába, és egy html fájlba. Ezt a kettőt ha berakod egy .zip-be, és ide feltöltöd, akkor ránézek mi lehet a hiba, és kijavítom. Max 10 MB!
Ha több, elég a .html. Bónusz ha mellékelsz egy readme-t, hogy mit csináljak.
+ */ %>
+
<% include aludni.ejs %>
diff --git a/views/man.ejs b/views/man.ejs
index 23c7ad1..22a0c47 100644
--- a/views/man.ejs
+++ b/views/man.ejs
@@ -154,7 +154,7 @@ változtatni akarsz, akkor illik tudni
-
+