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)
})
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()

View file

@ -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 += '/' }

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

View file

@ -1,122 +1,122 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/question-node-server>
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 <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
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: <https://gitlab.com/MrFry/question-node-server>
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 <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
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'
}

View file

@ -5,6 +5,7 @@
<head>
<title><%=dirname%></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style>
body {
font: normal 14px Verdana;
@ -12,7 +13,10 @@
}
td {
vertical-align: top
vertical-align: top;
word-wrap: break-word;
word-break: break-all;
table-layout: fixed;
}
textarea {
@ -53,11 +57,6 @@
font-size: 13px;
}
.active,
.butt:hover {
background-color: #555;
}
</style>
</head>
<center>
@ -72,13 +71,16 @@
<% for (var i = 0; i < folders.length; i++) { %>
<tr>
<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">
<td style='width:30%;'>
<a href="<%= "http://stuff.frylabs.net" + folders[i].path%>"> <%=folders[i].name %> </a>
</td>
<td style='width:30%;'>
<%=folders[i].path %>
<%=folders[i].name %>
</td>
<td style='width:20%;'>
<%=folders[i].mtime %>
@ -93,4 +95,20 @@
<% } %>
</table>
</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>