This commit is contained in:
MrFry 2019-10-26 10:11:27 +02:00
commit c9ab102927
7 changed files with 136 additions and 36 deletions

View file

@ -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'))

View file

@ -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'))

View file

@ -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)
@ -160,7 +160,7 @@ app.get('/update', 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)
})
@ -231,5 +231,8 @@ app.post('*', function (req, res) {
})
exports.app = app
exports.setup = (x) => {
url = x.url
}
logger.Log('Qmining module started', logger.GetColor('yellow'))

View file

@ -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,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 +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)
}
})
@ -112,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'))

View file

@ -81,7 +81,13 @@ app.use(function (req, res, next) {
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))
})

View file

@ -65,7 +65,7 @@
<%=dirname%>
</h1>
</center>
<a href="<%= "http://stuff.frylabs.net" + prevDir%>" > Up one level </a>
<a href="<%= url + prevDir%>" > Up one level </a>
</p>
<table class="maintable">

72
views/stuff/nofile.ejs Normal file
View file

@ -0,0 +1,72 @@
<html>
<body bgcolor="#212127">
<head>
<title>No such file/folder</title>
<meta charset="UTF-8">
<style>
body {
font: normal 14px Verdana;
color: #999999;
}
td {
vertical-align: top
}
textarea {
font: normal 14px Verdana;
color: #999999;
background-color: #212127;
width: 100%;
height: 700;
}
a {
color: #9999ff;
}
.subtable {
border-collapse: collapse;
table-layout:fixed;
width:100%
}
.maintable {
border-collapse: collapse;
table-layout:fixed;
width:100%
padding:0; margin:0;
border: none !important;
}
tr {
line-height: 29px;
width:32%;
}
.butt {
background-color: #212127;
color: #999999;
cursor: pointer;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 13px;
}
.active,
.butt:hover {
background-color: #555;
}
</style>
</head>
<center>
<h1>
No such file / folder:
</br>
<%= missingFile %>
</br>
<a href="<%= url %>" > Back to root </a>
</h1>
</center>
</body>
</html>