Moved submodules and every stuff into seperate folders neatly #4

This commit is contained in:
mrfry 2020-10-01 14:16:19 +02:00
parent 7e44ca30f1
commit ae91801fbd
51 changed files with 0 additions and 799 deletions

View file

@ -0,0 +1,218 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-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/>.
------------------------------------------------------------------------- */
// package requires
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const app = express()
// other requires
const utils = require('../../utils/utils.js')
const logger = require('../../utils/logger.js')
const auth = require('../../middlewares/auth.middleware.js')
// stuff gotten from server.js
let donateURL = ''
let publicdirs = []
let userDB
let nextdir = ''
try {
donateURL = utils.ReadFile('./data/donateURL')
} catch (e) {
logger.Log('Couldnt read donate URL file!', logger.GetColor('red'))
}
function GetApp () {
app.use(bodyParser.urlencoded({
limit: '5mb',
extended: true
}))
app.use(bodyParser.json({
limit: '5mb'
}))
app.set('view engine', 'ejs')
app.set('views', [
'./modules/qmining/views',
'./sharedViews'
])
app.use(auth({
userDB: userDB,
jsonResponse: false,
exceptions: [
'/thanks',
'/thanks.html',
'/img/thanks.gif',
'/install',
'/favicon.ico',
'/getVeteranPw',
'/moodle-test-userscript/stable.user.js',
'/donate',
'/irc'
]
}))
publicdirs.forEach((pdir) => {
logger.Log(`Using public dir: ${pdir}`)
app.use(express.static(pdir))
})
app.use(express.static(nextdir))
app.use(busboy({
limits: {
fileSize: 10000 * 1024 * 1024
}
}))
// --------------------------------------------------------------
// REDIRECTS
// --------------------------------------------------------------
// to be backwards compatible
app.get('/ask', function (req, res) {
logger.DebugLog(`Qmining module ask redirect`, 'ask', 1)
res.redirect(`http://api.frylabs.net/ask?q=${req.query.q}&subj=${req.query.subj}&data=${req.query.data}`)
})
const simpleRedirects = [
{
from: '/dataeditor',
to: 'https://dataeditor.frylabs.net'
},
{
from: '/install',
to: 'https://qmining.frylabs.net/moodle-test-userscript/stable.user.js'
},
{
from: '/servergit',
to: 'https://gitlab.com/MrFry/mrfrys-node-server'
},
{
from: '/scriptgit',
to: 'https://gitlab.com/MrFry/moodle-test-userscript'
},
{
from: '/qminingSite',
to: 'https://gitlab.com/MrFry/qmining-page'
},
{
from: '/classesgit',
to: 'https://gitlab.com/MrFry/question-classes'
},
{
from: '/menuClick',
to: '/'
},
{
from: '/lred',
to: '/allQuestions.html'
},
{
from: '/donate',
to: donateURL
},
{ // to be backwards compatible
from: '/legacy',
to: '/allQuestions.html'
},
{
from: '/allqr',
to: 'http://api.frylabs.net/allqr.txt'
},
{
from: '/allqr.txt',
to: 'http://api.frylabs.net/allqr.txt'
},
{
from: '/infos',
to: 'http://api.frylabs.net/infos?version=true&motd=true&subjinfo=true',
nolog: true
},
{
from: '/irc',
to: 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining'
}
]
simpleRedirects.forEach((redirect) => {
app.get(redirect.from, function (req, res) {
if (!redirect.nolog) {
logger.LogReq(req)
}
logger.DebugLog(`Qmining module ${redirect.from} redirect`, 'infos', 1)
res.redirect(`${redirect.to}`)
})
})
// --------------------------------------------------------------
function AddHtmlRoutes (files) {
const routes = files.reduce((acc, f) => {
if (f.includes('html')) {
acc.push(f.split('.')[0])
return acc
}
return acc
}, [])
routes.forEach((route) => {
logger.DebugLog(`Added route /${route}`, 'Qmining routes', 1)
app.get(`/${route}`, function (req, res) {
logger.LogReq(req)
res.redirect(`${route}.html`)
})
})
}
AddHtmlRoutes(utils.ReadDir(nextdir))
// --------------------------------------------------------------
app.get('/', function (req, res) {
res.end('hai')
logger.LogReq(req)
})
app.get('/getVeteranPw', function (req, res) {
res.render('veteranPw', {
cid: req.query.cid || '',
devel: process.env.NS_DEVEL
})
logger.LogReq(req)
})
app.get('*', function (req, res) {
res.status(404).render('404')
})
app.post('*', function (req, res) {
res.status(404).render('404')
})
return {
app: app
}
}
exports.name = 'Qmining'
exports.getApp = GetApp
exports.setup = (data) => {
userDB = data.userDB
publicdirs = data.publicdirs
nextdir = data.nextdir
}

View file

@ -0,0 +1,150 @@
<html>
<body bgcolor="#222426">
<head>
<title>Frylabs</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style>
a {
color: lightblue;
}
.center {
width: 440px;
height: 340px;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
max-width: 100%;
max-height: 100%;
overflow: auto;
text-align: center;
}
.text {
font-size: 18px;
color: white;
margin: 20px;
}
.title {
font-size: 50px;
font-weight: bold;
color: white;
}
.inputContainer {
width: 100%;
}
.showpwContainer {
color: white;
width: 40px;
cursor: pointer;
}
input[type=text], input[type=password] {
font-size: 20px;
color: #ffffff;
background-color: #181a1b;
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 2px solid #333333;
text-align: center;
}
input[type=text], input[type=password]:focus {
border: 2px solid #000;
}
button {
width: 100px;
background-color: #9999ff;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
#irc {
display: none;
}
</style>
</head>
<div class='center'>
<div class='title'>
Frylabs
</div>
<div id='text' class='text'>
Másold be ide régi kliens ID-d, és az alapján jelszót kapsz. Ezt csak egyszer teheted meg,
ezért a kapott jelszót tuti helyre írd le!
</div>
<div id='irc'>
<a class='ircLink' href='<%= devel? 'http' : 'https' %>://qmining.frylabs.net/irc?vetPwReqClick'>IRC</a>
</div>
<div id='form'>
<div class='inputContainer'>
<input type='text' id='cid' name='pw' value='<%= cid %>' autocomplete="off"/>
</div>
<input type='hidden' name='redirect' value='asd' autocomplete="off"/>
<button id='sendButton' onclick="GetVeteranPW(this)">Submit</button>
</div>
</div>
</body>
<script>
function HandleResp (resp) {
const textNode = document.getElementById('text')
document.getElementById('sendButton').innerText = 'Submit'
if (resp.result === 'success') {
document.getElementById('form').style.display = 'none'
textNode.innerText = 'Password:'
const pwDiv = document.createElement('div')
pwDiv.innerText = resp.pw
pwDiv.style.fontSize = '20px'
textNode.appendChild(pwDiv)
} else {
textNode.innerText = resp.msg
}
}
function HandleZeroStart () {
document.getElementById('form').style.display = 'none'
document.getElementById('irc').style.display = 'block'
document.getElementById('text').innerText = 'Client ID-d 0-val kezdődik. Ez azt jelenti hogy a jelszavasítás után telepítetted a scriptet, ezért nem vagy jogosult itt jelszót kérni. Ennek ellenére más felhasználóktól (akiknek már van jelszavuk) kérhetsz. Ha úgy gondolod valami nem stimmel:'
}
async function GetVeteranPW(button) {
button.innerText = '...'
const cid = document.getElementById('cid').value
if (cid[0] === '0') {
HandleZeroStart()
return
}
const rawResponse = await fetch('<%= devel? 'http' : 'https' %>://api.frylabs.net/getveteranpw', {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
cid: cid
})
})
if (!rawResponse.ok) {
document.getElementById('text').innerText = 'Internal server error'
document.getElementById('sendButton').innerText = 'Submit'
}
try {
rawResponse.json()
.then((resp) => {
HandleResp(resp)
})
} catch (e) {
document.getElementById('text').innerText = 'Invalid data recieved from server'
document.getElementById('sendButton').innerText = 'Submit'
console.log(e)
}
}
</script>
</html>