From c4077c94e56fcf69fa271564b99c7fbb66305043 Mon Sep 17 00:00:00 2001 From: MrFry Date: Sun, 13 Oct 2019 13:07:28 +0200 Subject: [PATCH 01/11] Logging again --- public/moodle-test-userscript | 2 +- utils/logger.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/moodle-test-userscript b/public/moodle-test-userscript index de7760e..c935c9e 160000 --- a/public/moodle-test-userscript +++ b/public/moodle-test-userscript @@ -1 +1 @@ -Subproject commit de7760ea8262febe71e697c697e3c34a87eb10df +Subproject commit c935c9e078303b98d61d2d12bca3ab86e2695bdc diff --git a/utils/logger.js b/utils/logger.js index e3bc9ac..e2e0f3e 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -69,7 +69,8 @@ function LogReq (req, toFile, sc) { dl += C('red') } - logEntry += dl + req.hostname + dl + req.headers['user-agent'] + dl + req.method + dl + const hostname = req.hostname.replace('www.', '').split('.')[0] + logEntry += dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl logEntry += GetRandomColor(req.url.split('?')[0]) + req.url From b2310213b3b671351c68e62d7291908d099f7cca Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 24 Oct 2019 14:30:41 +0200 Subject: [PATCH 02/11] Module loading refactor --- public/moodle-test-userscript | 2 +- server.js | 62 ++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/public/moodle-test-userscript b/public/moodle-test-userscript index de7760e..fe74436 160000 --- a/public/moodle-test-userscript +++ b/public/moodle-test-userscript @@ -1 +1 @@ -Subproject commit de7760ea8262febe71e697c697e3c34a87eb10df +Subproject commit fe74436ab119a31fdb35f7a3bbae50a572b0fb21 diff --git a/server.js b/server.js index eef8795..f1c3fd6 100644 --- a/server.js +++ b/server.js @@ -32,11 +32,46 @@ const https = require('https') const stat = require('./utils/stat.js') stat.Load() -const qmining = require('./modules/qmining.js').app -const main = require('./modules/main.js').app -const sio = require('./modules/sio.js').app -const stuff = require('./modules/stuff.js').app -const old = require('./modules/old.js').app +const loggableKeywords = [ + 'user.js' +] +let modules = { + qmining: { + path: './modules/qmining.js', + name: 'qmining', + urls: [ 'qmining.frylabs.net', 'localhost' ] + }, + main: { + path: './modules/main.js', + name: 'main', + urls: [ 'frylabs.net', 'www.frylabs.net' ] + }, + sio: { + path: './modules/sio.js', + name: 'sio', + urls: [ 'sio.frylabs.net' ] + }, + stuff: { + path: './modules/stuff.js', + name: 'stuff', + urls: [ 'stuff.frylabs.net' ] + }, + old: { + path: './modules/old.js', + name: 'old', + urls: [ 'qmining.tk', 'www.qmining.tk' ] + } +} + +const app = express() + +Object.keys(modules).forEach(function (k, i) { + let x = modules[k] + x.app = require(x.path).app + x.urls.forEach((url) => { + app.use(vhost(url, x.app)) + }) +}) const locLogFile = './stats/logs' const allLogFile = '/nlogs/log' @@ -93,12 +128,6 @@ function setLogTimer () { setLogTimer() -const app = express() - -const loggableKeywords = [ - 'user.js' -] - app.use(function (req, res, next) { res.on('finish', function () { logger.LogReq(req, true, res.statusCode) @@ -111,17 +140,6 @@ app.use(function (req, res, next) { next() }) -app.use(vhost('qmining.frylabs.net', qmining)) -app.use(vhost('sio.frylabs.net', sio)) -app.use(vhost('stuff.frylabs.net', stuff)) -app.use(vhost('frylabs.net', main)) -app.use(vhost('www.frylabs.net', main)) - -app.use(vhost('qmining.tk', old)) -app.use(vhost('www.qmining.tk', old)) - -app.use(vhost('localhost', qmining)) - logger.Log('Node version: ' + process.version) logger.Log('Listening on port: ' + port) From bca8fa097d5bfe9941e8379bcfcb7af61f41cf69 Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 24 Oct 2019 14:31:44 +0200 Subject: [PATCH 03/11] More error resistant module loading --- server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index f1c3fd6..c59d84b 100644 --- a/server.js +++ b/server.js @@ -67,10 +67,14 @@ const app = express() Object.keys(modules).forEach(function (k, i) { let x = modules[k] - x.app = require(x.path).app - x.urls.forEach((url) => { - app.use(vhost(url, x.app)) - }) + try { + x.app = require(x.path).app + x.urls.forEach((url) => { + app.use(vhost(url, x.app)) + }) + } catch (e) { + console.log(e) + } }) const locLogFile = './stats/logs' From 90de7e926b92d5d231623ca6950b2eed485eebdf Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 24 Oct 2019 15:05:08 +0200 Subject: [PATCH 04/11] Folders view tidy up, fix path with spaces, update url added to qmining --- modules/qmining.js | 6 + modules/stuff.js | 3 +- public/moodle-test-userscript | 2 +- utils/logger.js | 244 +++++++++++++++++----------------- views/stuff/folders.ejs | 40 ++++-- 5 files changed, 160 insertions(+), 135 deletions(-) diff --git a/modules/qmining.js b/modules/qmining.js index fa8b83d..081cc39 100644 --- a/modules/qmining.js +++ b/modules/qmining.js @@ -153,6 +153,12 @@ app.get('/greasy', function (req, res) { logger.LogReq(req) }) +app.get('/update', function (req, res) { + res.redirect('http://qmining.frylabs.net/moodle-test-userscript/stable.user.js') + res.end() + logger.LogReq(req) +}) + app.get('/install', function (req, res) { res.redirect('http://qmining.frylabs.net/moodle-test-userscript/stable.user.js') res.end() diff --git a/modules/stuff.js b/modules/stuff.js index 3a09682..8ffd512 100644 --- a/modules/stuff.js +++ b/modules/stuff.js @@ -49,7 +49,8 @@ app.use(bodyParser.json({ // -------------------------------------------------------------- app.get('/*', function (req, res) { - let curr = listedFiles + '/' + req.url.substring('/'.length, req.url.length).split('?')[0] + let parsedUrl = req.url.replace(/%20/g, " ") + let curr = listedFiles + '/' + parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0] let relPath = curr.substring('./public/files'.length, curr.length) if (relPath[relPath.length - 1] !== '/') { relPath += '/' } diff --git a/public/moodle-test-userscript b/public/moodle-test-userscript index c935c9e..fe74436 160000 --- a/public/moodle-test-userscript +++ b/public/moodle-test-userscript @@ -1 +1 @@ -Subproject commit c935c9e078303b98d61d2d12bca3ab86e2695bdc +Subproject commit fe74436ab119a31fdb35f7a3bbae50a572b0fb21 diff --git a/utils/logger.js b/utils/logger.js index a22b74d..c3e7a25 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -1,122 +1,122 @@ -/* ---------------------------------------------------------------------------- - - Question Server - GitLab: - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - ------------------------------------------------------------------------- */ - -module.exports = { - GetDateString: GetDateString, - Log: Log, - GetColor: GetColor, - LogReq: LogReq -} - -const DELIM = C('green') + '|' + C() - -const utils = require('../utils/utils.js') -const locLogFile = './stats/logs' -const logFile = '/nlogs/nlogs' -const allLogFile = '/nlogs/log' - -const colors = [ - 'red', - 'green', - 'yellow', - 'blue', - 'magenta', - 'cyan' -] - -function GetDateString () { - const m = new Date() - const d = m.getFullYear() + '/' + - ('0' + (m.getMonth() + 1)).slice(-2) + '/' + - ('0' + m.getDate()).slice(-2) + ' ' + - ('0' + m.getHours()).slice(-2) + ':' + - ('0' + m.getMinutes()).slice(-2) + ':' + - ('0' + m.getSeconds()).slice(-2) - return GetRandomColor(m.getHours().toString()) + d + C() -} - -function Log (s, c) { - let dl = DELIM + C(c) - let log = C(c) + GetDateString() + dl + s - - console.log(log) - utils.AppendToFile(log, logFile) -} - -function LogReq (req, toFile, sc) { - try { - let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress - - let logEntry = GetRandomColor(ip) + ip + C() - let dl = DELIM - if (req.url.includes('lred')) { - dl += C('red') - } - - const hostname = req.hostname.replace('www.', '').split('.')[0] - logEntry += dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl - - logEntry += GetRandomColor(req.url.split('?')[0]) + req.url - - if (sc !== undefined && sc === 404) { logEntry += dl + sc } - - logEntry += C() - if (!toFile) { - Log(logEntry) - } else { - let defLogs = GetDateString() + dl + logEntry - - utils.AppendToFile(defLogs, locLogFile) - utils.AppendToFile(defLogs, allLogFile) - } - } catch (e) { - console.log(e) - Log('Error at logging lol', GetColor('redbg'), true) - } -} - -function GetRandomColor (ip) { - if (!ip) { - return 'red' - } - - let res = ip.split('').reduce((res, x) => { - return res + x.charCodeAt(0) - }, 0) - return C(colors[res % colors.length]) -} - -function GetColor (c) { - return c -} - -function C (c) { - if (c !== undefined) { c = c.toLowerCase() } - - if (c === 'redbg') { return '\x1b[41m' } - if (c === 'bluebg') { return '\x1b[44m' } - if (c === 'red') { return '\x1b[31m' } - if (c === 'green') { return '\x1b[32m' } - if (c === 'yellow') { return '\x1b[33m' } - if (c === 'blue') { return '\x1b[34m' } - if (c === 'magenta') { return '\x1b[35m' } - if (c === 'cyan') { return '\x1b[36m' } - return '\x1b[0m' -} +/* ---------------------------------------------------------------------------- + + Question Server + GitLab: + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + ------------------------------------------------------------------------- */ + +module.exports = { + GetDateString: GetDateString, + Log: Log, + GetColor: GetColor, + LogReq: LogReq +} + +const DELIM = C('green') + '|' + C() + +const utils = require('../utils/utils.js') +const locLogFile = './stats/logs' +const logFile = '/nlogs/nlogs' +const allLogFile = '/nlogs/log' + +const colors = [ + 'green', + 'red', + 'yellow', + 'blue', + 'magenta', + 'cyan' +] + +function GetDateString () { + const m = new Date() + const d = m.getFullYear() + '/' + + ('0' + (m.getMonth() + 1)).slice(-2) + '/' + + ('0' + m.getDate()).slice(-2) + ' ' + + ('0' + m.getHours()).slice(-2) + ':' + + ('0' + m.getMinutes()).slice(-2) + ':' + + ('0' + m.getSeconds()).slice(-2) + return GetRandomColor(m.getHours().toString()) + d + C() +} + +function Log (s, c) { + let dl = DELIM + C(c) + let log = C(c) + GetDateString() + dl + s + + console.log(log) + utils.AppendToFile(log, logFile) +} + +function LogReq (req, toFile, sc) { + try { + let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress + + let logEntry = GetRandomColor(ip) + ip + C() + let dl = DELIM + if (req.url.includes('lred')) { + dl += C('red') + } + + const hostname = req.hostname.replace('www.', '').split('.')[0] + logEntry += dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl + + logEntry += GetRandomColor(req.url.split('?')[0]) + req.url + + if (sc !== undefined && sc === 404) { logEntry += dl + sc } + + logEntry += C() + if (!toFile) { + Log(logEntry) + } else { + let defLogs = GetDateString() + dl + logEntry + + utils.AppendToFile(defLogs, locLogFile) + utils.AppendToFile(defLogs, allLogFile) + } + } catch (e) { + console.log(e) + Log('Error at logging lol', GetColor('redbg'), true) + } +} + +function GetRandomColor (ip) { + if (!ip) { + return 'red' + } + + let res = ip.split('').reduce((res, x) => { + return res + x.charCodeAt(0) + }, 0) + return C(colors[res % colors.length]) +} + +function GetColor (c) { + return c +} + +function C (c) { + if (c !== undefined) { c = c.toLowerCase() } + + if (c === 'redbg') { return '\x1b[41m' } + if (c === 'bluebg') { return '\x1b[44m' } + if (c === 'green') { return '\x1b[32m' } + if (c === 'red') { return '\x1b[31m' } + if (c === 'yellow') { return '\x1b[33m' } + if (c === 'blue') { return '\x1b[34m' } + if (c === 'magenta') { return '\x1b[35m' } + if (c === 'cyan') { return '\x1b[36m' } + return '\x1b[0m' +} diff --git a/views/stuff/folders.ejs b/views/stuff/folders.ejs index fd69db0..e9ae97a 100644 --- a/views/stuff/folders.ejs +++ b/views/stuff/folders.ejs @@ -5,6 +5,7 @@ <%=dirname%> +
@@ -72,13 +71,16 @@ <% for (var i = 0; i < folders.length; i++) { %> -
- > Up one level + > Up one level

From a7e014796a01300c4a41d13e216e8fbc557549ce Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 24 Oct 2019 15:20:00 +0200 Subject: [PATCH 06/11] Spaces in url fix --- modules/stuff.js | 3 ++- views/stuff/folders.ejs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/stuff.js b/modules/stuff.js index 3a09682..08c72ba 100644 --- a/modules/stuff.js +++ b/modules/stuff.js @@ -49,7 +49,8 @@ app.use(bodyParser.json({ // -------------------------------------------------------------- app.get('/*', function (req, res) { - let curr = listedFiles + '/' + req.url.substring('/'.length, req.url.length).split('?')[0] + let parsedUrl = req.url.replace(/%20/g, " ") + let curr = listedFiles + '/' + parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0] let relPath = curr.substring('./public/files'.length, curr.length) if (relPath[relPath.length - 1] !== '/') { relPath += '/' } diff --git a/views/stuff/folders.ejs b/views/stuff/folders.ejs index fd69db0..77013af 100644 --- a/views/stuff/folders.ejs +++ b/views/stuff/folders.ejs @@ -65,7 +65,7 @@ <%=dirname%> - > Up one level + " > Up one level

From 3c528734221384b887f1b8ad1229bffa038023ea Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 24 Oct 2019 15:34:57 +0200 Subject: [PATCH 07/11] Even prettier stuff page --- views/stuff/folders.ejs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/views/stuff/folders.ejs b/views/stuff/folders.ejs index db5ea6d..e0f61f5 100644 --- a/views/stuff/folders.ejs +++ b/views/stuff/folders.ejs @@ -17,7 +17,8 @@ word-wrap: break-word; word-break: break-all; table-layout: fixed; - padding: 0 12 + padding: 0 12; + vertical-align: middle; } textarea { @@ -44,7 +45,6 @@ border: none !important; } tr { - line-height: 34px; width:32%; } .butt { @@ -80,6 +80,7 @@ onmouseleave='mouseLeave(this, <%= i %>)' >
+ @@ -89,6 +90,7 @@ +
<%=folders[i].name %> <%=folders[i].size %> MB
From f7b0e727fcc6afca26105d250c8980e410bfc824 Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 24 Oct 2019 19:38:01 +0200 Subject: [PATCH 08/11] Logging fix, ignoring some ips in logging, displaying "DIR" insted of 0MB --- server.js | 25 +++++++++++++------------ utils/logger.js | 12 ++++++++++++ views/stuff/folders.ejs | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index c59d84b..de0c5e3 100644 --- a/server.js +++ b/server.js @@ -65,6 +65,19 @@ let modules = { const app = express() +app.use(function (req, res, next) { + res.on('finish', function () { + logger.LogReq(req, true, res.statusCode) + let toLog = loggableKeywords.some((x) => { + return req.url.includes(x) + }) + if (toLog) { logger.LogReq(req) } + if (res.statusCode !== 404) { stat.LogStat(req.url) } + }) + next() +}) + + Object.keys(modules).forEach(function (k, i) { let x = modules[k] try { @@ -132,18 +145,6 @@ function setLogTimer () { setLogTimer() -app.use(function (req, res, next) { - res.on('finish', function () { - logger.LogReq(req, true, res.statusCode) - let toLog = loggableKeywords.some((x) => { - return req.url.includes(x) - }) - if (toLog) { logger.LogReq(req) } - if (res.statusCode !== 404) { stat.LogStat(req.url) } - }) - next() -}) - logger.Log('Node version: ' + process.version) logger.Log('Listening on port: ' + port) diff --git a/utils/logger.js b/utils/logger.js index c3e7a25..45e224b 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -41,6 +41,11 @@ const colors = [ 'cyan' ] +let noLogips = utils.ReadFile('./nolog').split('\n') +setInterval(() => { + noLogips = utils.ReadFile('./nolog').split('\n') +}, 1000 * 60 * 30) + function GetDateString () { const m = new Date() const d = m.getFullYear() + '/' + @@ -64,6 +69,13 @@ function LogReq (req, toFile, sc) { try { let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress + let nolog = noLogips.some((x) => { + return x.includes(ip) + }) + if (nolog) { + return + } + let logEntry = GetRandomColor(ip) + ip + C() let dl = DELIM if (req.url.includes('lred')) { diff --git a/views/stuff/folders.ejs b/views/stuff/folders.ejs index e0f61f5..bf68650 100644 --- a/views/stuff/folders.ejs +++ b/views/stuff/folders.ejs @@ -88,7 +88,7 @@ <%=folders[i].mtime %> - <%=folders[i].size %> MB + <%= folders[i].size === 0 ? "Dir" : folders[i].size + 'MB' %> From 61c71e6c8dfae4ac7dfc3b5e929fed3af5eca96b Mon Sep 17 00:00:00 2001 From: MrFry Date: Sat, 26 Oct 2019 09:52:20 +0200 Subject: [PATCH 09/11] Handled no such file exception --- modules/stuff.js | 56 ++++++++++++++++++-------------- views/stuff/nofile.ejs | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 views/stuff/nofile.ejs diff --git a/modules/stuff.js b/modules/stuff.js index 08c72ba..5113387 100644 --- a/modules/stuff.js +++ b/modules/stuff.js @@ -49,7 +49,7 @@ app.use(bodyParser.json({ // -------------------------------------------------------------- app.get('/*', function (req, res) { - let parsedUrl = req.url.replace(/%20/g, " ") + let parsedUrl = req.url.replace(/%20/g, ' ') let curr = listedFiles + '/' + parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0] let relPath = curr.substring('./public/files'.length, curr.length) @@ -64,37 +64,43 @@ app.get('/*', function (req, res) { logger.LogReq(req) - if (fs.lstatSync(curr).isDirectory()) { - if (curr[curr.length - 1] !== '/') { curr += '/' } + try { + if (fs.lstatSync(curr).isDirectory()) { + if (curr[curr.length - 1] !== '/') { curr += '/' } - let f = [] + let f = [] - fs.readdirSync(curr).forEach((item) => { - if (item[0] !== '.') { - let res = { name: item } - let stats = fs.statSync(curr + '/' + item) + 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) + 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.path = relPath + if (res.path[res.path.length - 1] !== '/') { res.path += '/' } + res.path += item - res.mtime = stats['mtime'].toLocaleString() + res.mtime = stats['mtime'].toLocaleString() - f.push(res) - } + f.push(res) + } + }) + + res.render('stuff/folders', { + folders: f, + dirname: relPath, + prevDir + }) + } else { + let fileStream = fs.createReadStream(curr) + fileStream.pipe(res) + } + } catch (e) { + res.render('stuff/nofile', { + missingFile: curr }) - - res.render('stuff/folders', { - folders: f, - dirname: relPath, - prevDir - }) - } else { - let fileStream = fs.createReadStream(curr) - fileStream.pipe(res) } }) diff --git a/views/stuff/nofile.ejs b/views/stuff/nofile.ejs new file mode 100644 index 0000000..8d7c0ad --- /dev/null +++ b/views/stuff/nofile.ejs @@ -0,0 +1,74 @@ + + + + + + + No such file/folder + + + +
+

+ No such file / folder: +
+ <%= missingFile %> +
+ " > Back to root +

+
+ + From d841e464f5c1ef9b932114bfabe1d7ecf0f17e7f Mon Sep 17 00:00:00 2001 From: MrFry Date: Sat, 26 Oct 2019 10:08:56 +0200 Subject: [PATCH 10/11] Global site url source --- modules/main.js | 7 +++++-- modules/old.js | 10 +++++++--- modules/qmining.js | 11 +++++++---- modules/stuff.js | 10 ++++++++-- server.js | 8 +++++++- views/stuff/folders.ejs | 4 ++-- views/stuff/nofile.ejs | 4 +--- 7 files changed, 37 insertions(+), 17 deletions(-) diff --git a/modules/main.js b/modules/main.js index 2c508de..b7e35cf 100644 --- a/modules/main.js +++ b/modules/main.js @@ -18,7 +18,7 @@ ------------------------------------------------------------------------- */ -const siteUrl = 'https://qmining.frylabs.net' // http(s)//asd.basd +let url = '' // http(s)//asd.basd const express = require('express') const bodyParser = require('body-parser') @@ -49,7 +49,7 @@ app.use(bodyParser.json({ app.get('/', function (req, res) { res.render('main/main', { - siteurl: siteUrl + siteurl: url }) }) @@ -65,5 +65,8 @@ app.post('*', function (req, res) { }) exports.app = app +exports.setup = (x) => { + url = x.url +} logger.Log('Main module started', logger.GetColor('yellow')) diff --git a/modules/old.js b/modules/old.js index f54b7c1..680d3bc 100644 --- a/modules/old.js +++ b/modules/old.js @@ -18,6 +18,7 @@ ------------------------------------------------------------------------- */ +let url = '' const express = require('express') const app = express() @@ -26,17 +27,20 @@ const logger = require('../utils/logger.js') // -------------------------------------------------------------- app.get('/', function (req, res) { - res.redirect('https://qmining.frylabs.net' + req.url) + res.redirect(url + req.url) }) app.get('*', function (req, res) { - res.redirect('https://qmining.frylabs.net' + req.url) + res.redirect(url + req.url) }) app.post('*', function (req, res) { - res.redirect('https://qmining.frylabs.net' + req.url) + res.redirect(url + req.url) }) exports.app = app +exports.setup = (x) => { + url = x.url +} logger.Log('Old module started', logger.GetColor('yellow')) diff --git a/modules/qmining.js b/modules/qmining.js index fa8b83d..6800e21 100644 --- a/modules/qmining.js +++ b/modules/qmining.js @@ -18,7 +18,7 @@ ------------------------------------------------------------------------- */ -const siteUrl = 'https://qmining.frylabs.net' // http(s)//asd.basd +let url = '' const express = require('express') const bodyParser = require('body-parser') @@ -60,7 +60,7 @@ app.get('/', function (req, res) { // req.hostname res.render('qmining/main', { - siteurl: siteUrl, + siteurl: url, qa: actions.ProcessQA() }) res.end() @@ -97,7 +97,7 @@ app.get('/legacy', function (req, res) { data: d, scount: scount, qcount: qcount, - siteurl: siteUrl + siteurl: url }) logger.LogReq(req) @@ -154,7 +154,7 @@ app.get('/greasy', function (req, res) { }) app.get('/install', function (req, res) { - res.redirect('http://qmining.frylabs.net/moodle-test-userscript/stable.user.js') + res.redirect(url + '/moodle-test-userscript/stable.user.js') res.end() logger.LogReq(req) }) @@ -225,5 +225,8 @@ app.post('*', function (req, res) { }) exports.app = app +exports.setup = (x) => { + url = x.url +} logger.Log('Qmining module started', logger.GetColor('yellow')) diff --git a/modules/stuff.js b/modules/stuff.js index 5113387..4e174eb 100644 --- a/modules/stuff.js +++ b/modules/stuff.js @@ -23,6 +23,7 @@ const bodyParser = require('body-parser') const busboy = require('connect-busboy') const fs = require('fs') const app = express() +let url = '' const logger = require('../utils/logger.js') // const utils = require('../utils/utils.js') @@ -91,7 +92,8 @@ app.get('/*', function (req, res) { res.render('stuff/folders', { folders: f, dirname: relPath, - prevDir + prevDir, + url }) } else { let fileStream = fs.createReadStream(curr) @@ -99,7 +101,8 @@ app.get('/*', function (req, res) { } } catch (e) { res.render('stuff/nofile', { - missingFile: curr + missingFile: curr, + url }) } }) @@ -118,5 +121,8 @@ app.post('*', function (req, res) { }) exports.app = app +exports.setup = (x) => { + url = x.url +} logger.Log('Stuff module started', logger.GetColor('yellow')) diff --git a/server.js b/server.js index c59d84b..362c910 100644 --- a/server.js +++ b/server.js @@ -68,7 +68,13 @@ const app = express() Object.keys(modules).forEach(function (k, i) { let x = modules[k] try { - x.app = require(x.path).app + let mod = require(x.path) + if (mod.setup) { + mod.setup({ + url: 'http://' + x.urls[0] // TODO http https or neither + }) + } + x.app = mod.app x.urls.forEach((url) => { app.use(vhost(url, x.app)) }) diff --git a/views/stuff/folders.ejs b/views/stuff/folders.ejs index 77013af..a153dfe 100644 --- a/views/stuff/folders.ejs +++ b/views/stuff/folders.ejs @@ -65,7 +65,7 @@ <%=dirname%> - " > Up one level + Up one level

@@ -75,7 +75,7 @@
- "> <%=folders[i].name %> + <%=folders[i].name %> <%=folders[i].path %> diff --git a/views/stuff/nofile.ejs b/views/stuff/nofile.ejs index 8d7c0ad..08b74da 100644 --- a/views/stuff/nofile.ejs +++ b/views/stuff/nofile.ejs @@ -1,4 +1,3 @@ - @@ -58,7 +57,6 @@ .butt:hover { background-color: #555; } -
@@ -67,7 +65,7 @@
<%= missingFile %>
- " > Back to root + Back to root
From 462eff3c75fa0e47508e1c2d5d96b049d99a5680 Mon Sep 17 00:00:00 2001 From: MrFry Date: Sat, 26 Oct 2019 10:10:26 +0200 Subject: [PATCH 11/11] Manual update, mobile friendly sites, minor design improvements --- views/main/main.ejs | 1 + views/qmining/alldata.ejs | 76 +++++++++++++++++++++++--------------- views/qmining/allqr.ejs | 1 + views/qmining/main.ejs | 1 + views/qmining/man.ejs | 27 +++++--------- views/qmining/uploaded.ejs | 2 + 6 files changed, 60 insertions(+), 48 deletions(-) diff --git a/views/main/main.ejs b/views/main/main.ejs index 4ba198d..11d8f43 100644 --- a/views/main/main.ejs +++ b/views/main/main.ejs @@ -5,6 +5,7 @@ FryLabs.net +