Folders view tidy up, fix path with spaces, update url added to qmining

This commit is contained in:
MrFry 2019-10-24 15:05:08 +02:00
parent d5cf846433
commit 90de7e926b
5 changed files with 160 additions and 135 deletions

View file

@ -153,6 +153,12 @@ app.get('/greasy', function (req, res) {
logger.LogReq(req) 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) { app.get('/install', function (req, res) {
res.redirect('http://qmining.frylabs.net/moodle-test-userscript/stable.user.js') res.redirect('http://qmining.frylabs.net/moodle-test-userscript/stable.user.js')
res.end() res.end()

View file

@ -49,7 +49,8 @@ app.use(bodyParser.json({
// -------------------------------------------------------------- // --------------------------------------------------------------
app.get('/*', function (req, res) { 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) let relPath = curr.substring('./public/files'.length, curr.length)
if (relPath[relPath.length - 1] !== '/') { relPath += '/' } if (relPath[relPath.length - 1] !== '/') { relPath += '/' }

@ -1 +1 @@
Subproject commit c935c9e078303b98d61d2d12bca3ab86e2695bdc Subproject commit fe74436ab119a31fdb35f7a3bbae50a572b0fb21

View file

@ -1,122 +1,122 @@
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
Question Server Question Server
GitLab: <https://gitlab.com/MrFry/question-node-server> GitLab: <https://gitlab.com/MrFry/question-node-server>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
module.exports = { module.exports = {
GetDateString: GetDateString, GetDateString: GetDateString,
Log: Log, Log: Log,
GetColor: GetColor, GetColor: GetColor,
LogReq: LogReq LogReq: LogReq
} }
const DELIM = C('green') + '|' + C() const DELIM = C('green') + '|' + C()
const utils = require('../utils/utils.js') const utils = require('../utils/utils.js')
const locLogFile = './stats/logs' const locLogFile = './stats/logs'
const logFile = '/nlogs/nlogs' const logFile = '/nlogs/nlogs'
const allLogFile = '/nlogs/log' const allLogFile = '/nlogs/log'
const colors = [ const colors = [
'red', 'green',
'green', 'red',
'yellow', 'yellow',
'blue', 'blue',
'magenta', 'magenta',
'cyan' 'cyan'
] ]
function GetDateString () { function GetDateString () {
const m = new Date() const m = new Date()
const d = m.getFullYear() + '/' + const d = m.getFullYear() + '/' +
('0' + (m.getMonth() + 1)).slice(-2) + '/' + ('0' + (m.getMonth() + 1)).slice(-2) + '/' +
('0' + m.getDate()).slice(-2) + ' ' + ('0' + m.getDate()).slice(-2) + ' ' +
('0' + m.getHours()).slice(-2) + ':' + ('0' + m.getHours()).slice(-2) + ':' +
('0' + m.getMinutes()).slice(-2) + ':' + ('0' + m.getMinutes()).slice(-2) + ':' +
('0' + m.getSeconds()).slice(-2) ('0' + m.getSeconds()).slice(-2)
return GetRandomColor(m.getHours().toString()) + d + C() return GetRandomColor(m.getHours().toString()) + d + C()
} }
function Log (s, c) { function Log (s, c) {
let dl = DELIM + C(c) let dl = DELIM + C(c)
let log = C(c) + GetDateString() + dl + s let log = C(c) + GetDateString() + dl + s
console.log(log) console.log(log)
utils.AppendToFile(log, logFile) utils.AppendToFile(log, logFile)
} }
function LogReq (req, toFile, sc) { function LogReq (req, toFile, sc) {
try { try {
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
let logEntry = GetRandomColor(ip) + ip + C() let logEntry = GetRandomColor(ip) + ip + C()
let dl = DELIM let dl = DELIM
if (req.url.includes('lred')) { if (req.url.includes('lred')) {
dl += C('red') dl += C('red')
} }
const hostname = req.hostname.replace('www.', '').split('.')[0] const hostname = req.hostname.replace('www.', '').split('.')[0]
logEntry += dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl logEntry += dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl
logEntry += GetRandomColor(req.url.split('?')[0]) + req.url logEntry += GetRandomColor(req.url.split('?')[0]) + req.url
if (sc !== undefined && sc === 404) { logEntry += dl + sc } if (sc !== undefined && sc === 404) { logEntry += dl + sc }
logEntry += C() logEntry += C()
if (!toFile) { if (!toFile) {
Log(logEntry) Log(logEntry)
} else { } else {
let defLogs = GetDateString() + dl + logEntry let defLogs = GetDateString() + dl + logEntry
utils.AppendToFile(defLogs, locLogFile) utils.AppendToFile(defLogs, locLogFile)
utils.AppendToFile(defLogs, allLogFile) utils.AppendToFile(defLogs, allLogFile)
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
Log('Error at logging lol', GetColor('redbg'), true) Log('Error at logging lol', GetColor('redbg'), true)
} }
} }
function GetRandomColor (ip) { function GetRandomColor (ip) {
if (!ip) { if (!ip) {
return 'red' return 'red'
} }
let res = ip.split('').reduce((res, x) => { let res = ip.split('').reduce((res, x) => {
return res + x.charCodeAt(0) return res + x.charCodeAt(0)
}, 0) }, 0)
return C(colors[res % colors.length]) return C(colors[res % colors.length])
} }
function GetColor (c) { function GetColor (c) {
return c return c
} }
function C (c) { function C (c) {
if (c !== undefined) { c = c.toLowerCase() } if (c !== undefined) { c = c.toLowerCase() }
if (c === 'redbg') { return '\x1b[41m' } if (c === 'redbg') { return '\x1b[41m' }
if (c === 'bluebg') { return '\x1b[44m' } if (c === 'bluebg') { return '\x1b[44m' }
if (c === 'red') { return '\x1b[31m' } if (c === 'green') { return '\x1b[32m' }
if (c === 'green') { return '\x1b[32m' } if (c === 'red') { return '\x1b[31m' }
if (c === 'yellow') { return '\x1b[33m' } if (c === 'yellow') { return '\x1b[33m' }
if (c === 'blue') { return '\x1b[34m' } if (c === 'blue') { return '\x1b[34m' }
if (c === 'magenta') { return '\x1b[35m' } if (c === 'magenta') { return '\x1b[35m' }
if (c === 'cyan') { return '\x1b[36m' } if (c === 'cyan') { return '\x1b[36m' }
return '\x1b[0m' return '\x1b[0m'
} }

View file

@ -5,6 +5,7 @@
<head> <head>
<title><%=dirname%></title> <title><%=dirname%></title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style> <style>
body { body {
font: normal 14px Verdana; font: normal 14px Verdana;
@ -12,7 +13,10 @@
} }
td { td {
vertical-align: top vertical-align: top;
word-wrap: break-word;
word-break: break-all;
table-layout: fixed;
} }
textarea { textarea {
@ -53,11 +57,6 @@
font-size: 13px; font-size: 13px;
} }
.active,
.butt:hover {
background-color: #555;
}
</style> </style>
</head> </head>
<center> <center>
@ -72,13 +71,16 @@
<% for (var i = 0; i < folders.length; i++) { %> <% for (var i = 0; i < folders.length; i++) { %>
<tr> <tr>
<td> <td>
<button class="butt"> <button
class="butt"
onclick='itemClick("<%= "http://stuff.frylabs.net" + folders[i].path %>")'
style='<%= i % 2 === 0 ? "background-color: #2f2f37" : "" %>'
onmouseenter='mouseEnter(this, <%= i %>)'
onmouseleave='mouseLeave(this, <%= i %>)'
>
<table class="subtable"> <table class="subtable">
<td style='width:30%;'> <td style='width:30%;'>
<a href="<%= "http://stuff.frylabs.net" + folders[i].path%>"> <%=folders[i].name %> </a> <%=folders[i].name %>
</td>
<td style='width:30%;'>
<%=folders[i].path %>
</td> </td>
<td style='width:20%;'> <td style='width:20%;'>
<%=folders[i].mtime %> <%=folders[i].mtime %>
@ -93,4 +95,20 @@
<% } %> <% } %>
</table> </table>
</body> </body>
<script>
console.log('hi')
function itemClick (e) {
location.href = e
}
function mouseEnter (e, i) {
e.style.backgroundColor = "#555"
}
function mouseLeave (e, i) {
if (i % 2 == 0) {
e.style.backgroundColor = "#2f2f37"
} else {
e.style.backgroundColor = "#212127"
}
}
</script>
</html> </html>