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 536755a..22f208c 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')
@@ -59,7 +59,7 @@ app.get('/', function (req, res) {
// req.hostname
res.render('qmining/main', {
- siteurl: siteUrl,
+ siteurl: url,
qa: actions.ProcessQA()
})
res.end()
@@ -82,7 +82,7 @@ app.get('/legacy', function (req, res) {
data: d,
scount: scount,
qcount: qcount,
- siteurl: siteUrl
+ siteurl: url
})
logger.LogReq(req)
@@ -135,7 +135,13 @@ app.get('/greasy', function (req, res) {
})
app.get('/install', function (req, res) {
- res.redirect(siteUrl + '/moodle-test-userscript/stable.user.js?install')
+ res.redirect(url + '/moodle-test-userscript/stable.user.js?install')
+ res.end()
+ logger.LogReq(req)
+})
+
+app.get('/install', function (req, res) {
+ res.redirect(url + '/moodle-test-userscript/stable.user.js')
res.end()
logger.LogReq(req)
})
@@ -206,5 +212,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 3a09682..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')
@@ -49,7 +50,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 += '/' }
@@ -63,37 +65,45 @@ 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,
+ url
+ })
+ } else {
+ let fileStream = fs.createReadStream(curr)
+ fileStream.pipe(res)
+ }
+ } catch (e) {
+ res.render('stuff/nofile', {
+ missingFile: curr,
+ url
})
-
- res.render('stuff/folders', {
- folders: f,
- dirname: relPath,
- prevDir
- })
- } else {
- let fileStream = fs.createReadStream(curr)
- fileStream.pipe(res)
}
})
@@ -111,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 eef8795..26fc07d 100644
--- a/server.js
+++ b/server.js
@@ -32,11 +32,69 @@ 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()
+
+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 {
+ 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))
+ })
+ } catch (e) {
+ console.log(e)
+ }
+})
const locLogFile = './stats/logs'
const allLogFile = '/nlogs/log'
@@ -93,35 +151,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)
- let toLog = loggableKeywords.some((x) => {
- return req.url.includes(x)
- })
- if (toLog) { logger.LogReq(req) }
- if (res.statusCode !== 404) { stat.LogStat(req.url) }
- })
- 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)
diff --git a/utils/logger.js b/utils/logger.js
index 8439733..45e224b 100644
--- a/utils/logger.js
+++ b/utils/logger.js
@@ -1,121 +1,134 @@
-/* ----------------------------------------------------------------------------
-
- Question Server
- GitLab:
- | @@ -93,4 +98,20 @@ <% } %>