diff --git a/main.js b/main.js index c4ec696..918a065 100644 --- a/main.js +++ b/main.js @@ -18,61 +18,19 @@ ------------------------------------------------------------------------- */ -const startHTTPS = true -const siteUrl = 'https://qmining.tk' // http(s)//asd.basd -const ircURL = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' - const express = require('express') const bodyParser = require('body-parser') const busboy = require('connect-busboy') const fs = require('fs') const app = express() -// const http = require('http') -// const https = require('https') const logger = require('./logger.js') -const utils = require('./utils.js') -const actions = require('./actions.js') -const stat = require('./stat.js') +// const utils = require('./utils.js') +// const actions = require('./actions.js') const listedFiles = './public/files' -const recivedFiles = 'public/recivedfiles' -const uloadFiles = 'public/f' -const staticFile = 'public/data/static' -const dataFile = 'public/data.json' -const msgFile = 'stats/msgs' - -// https://certbot.eff.org/ -const privkeyFile = '/etc/letsencrypt/live/qmining.tk/privkey.pem' -const fullchainFile = '/etc/letsencrypt/live/qmining.tk/fullchain.pem' -const chainFile = '/etc/letsencrypt/live/qmining.tk/chain.pem' - -var certsLoaded = false -if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists( - chainFile)) { - try { - const key = fs.readFileSync(privkeyFile, 'utf8') - const cert = fs.readFileSync(fullchainFile, 'utf8') - const ca = fs.readFileSync(chainFile, 'utf8') - var certs = { - key: key, - cert: cert, - ca: ca - } - certsLoaded = true - } catch (e) { - logger.Log('Error loading cert files!', logger.GetColor('redbg')) - } -} app.set('view engine', 'ejs') -app.use(function (req, res, next) { - res.on('finish', function () { - logger.LogReq(req, true, res.statusCode) - if (res.statusCode !== 404) { stat.LogStat(req.url) } - }) - next() -}) app.use(express.static('public')) app.use(busboy({ limits: { @@ -91,9 +49,7 @@ app.use(bodyParser.json({ // -------------------------------------------------------------- app.get('/', function (req, res) { - // req.hostname - - //res.render() + // res.render() res.end('henlo') }) @@ -161,9 +117,6 @@ app.post('*', function (req, res) { // utils.AppendToFile(logger.GetDateString() + ": " + "404 POST", logFile); }) -var msg = '' -stat.Load() - exports.app = app logger.Log('Main module started', logger.GetColor('yellow')) diff --git a/qmining.js b/qmining.js index a2bbf7c..c40b19d 100644 --- a/qmining.js +++ b/qmining.js @@ -18,9 +18,7 @@ ------------------------------------------------------------------------- */ -const startHTTPS = true -const siteUrl = 'https://qmining.tk' // http(s)//asd.basd -const ircURL = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' +const siteUrl = 'https://frylabs.net' // http(s)//asd.basd const express = require('express') const bodyParser = require('body-parser') @@ -33,46 +31,14 @@ const app = express() const logger = require('./logger.js') const utils = require('./utils.js') const actions = require('./actions.js') -const stat = require('./stat.js') -const listedFiles = './public/files' const recivedFiles = 'public/recivedfiles' const uloadFiles = 'public/f' const staticFile = 'public/data/static' const dataFile = 'public/data.json' const msgFile = 'stats/msgs' -// https://certbot.eff.org/ -const privkeyFile = '/etc/letsencrypt/live/qmining.tk/privkey.pem' -const fullchainFile = '/etc/letsencrypt/live/qmining.tk/fullchain.pem' -const chainFile = '/etc/letsencrypt/live/qmining.tk/chain.pem' - -var certsLoaded = false -if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists( - chainFile)) { - try { - const key = fs.readFileSync(privkeyFile, 'utf8') - const cert = fs.readFileSync(fullchainFile, 'utf8') - const ca = fs.readFileSync(chainFile, 'utf8') - var certs = { - key: key, - cert: cert, - ca: ca - } - certsLoaded = true - } catch (e) { - logger.Log('Error loading cert files!', logger.GetColor('redbg')) - } -} - app.set('view engine', 'ejs') -app.use(function (req, res, next) { - res.on('finish', function () { - logger.LogReq(req, true, res.statusCode) - if (res.statusCode !== 404) { stat.LogStat(req.url) } - }) - next() -}) app.use(express.static('public')) app.use(busboy({ limits: { @@ -175,12 +141,6 @@ app.get('/menuClick', function (req, res) { logger.LogReq(req) }) -app.get('/irc', function (req, res) { - res.redirect(ircURL) - res.end() - logger.LogReq(req) -}) - // all questions readable app.get('/allqr', function (req, res) { var f = utils.ReadFile(dataFile) @@ -257,9 +217,6 @@ app.post('*', function (req, res) { // utils.AppendToFile(logger.GetDateString() + ": " + "404 POST", logFile); }) -var msg = '' -stat.Load() - exports.app = app logger.Log('Qmining module started', logger.GetColor('yellow')) diff --git a/server.js b/server.js index 77a2846..0ced543 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,23 @@ +/* ---------------------------------------------------------------------------- + + Question Server + GitLab: + + 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 . + + ------------------------------------------------------------------------- */ + const express = require('express') const vhost = require('vhost') const logger = require('./logger.js') @@ -5,15 +25,52 @@ const logger = require('./logger.js') const qmining = require('./qmining.js').app const main = require('./main.js').app +const stat = require('./stat.js') +stat.Load() + const port = 8080 +function AddLogger (app) { + app.use(function (req, res, next) { + res.on('finish', function () { + logger.LogReq(req, true, res.statusCode) + if (res.statusCode !== 404) { stat.LogStat(req.url) } + }) + next() + }) +} + +AddLogger(qmining) +AddLogger(main) + +// // https://certbot.eff.org/ +// const privkeyFile = '/etc/letsencrypt/live/qmining.tk/privkey.pem' +// const fullchainFile = '/etc/letsencrypt/live/qmining.tk/fullchain.pem' +// const chainFile = '/etc/letsencrypt/live/qmining.tk/chain.pem' +// +// var certsLoaded = false +// if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists( +// chainFile)) { +// try { +// const key = fs.readFileSync(privkeyFile, 'utf8') +// const cert = fs.readFileSync(fullchainFile, 'utf8') +// const ca = fs.readFileSync(chainFile, 'utf8') +// var certs = { +// key: key, +// cert: cert, +// ca: ca +// } +// certsLoaded = true +// } catch (e) { +// logger.Log('Error loading cert files!', logger.GetColor('redbg')) +// } +// } + express() .use(vhost('qmining.frylabs.net', qmining)) .use(vhost('frylabs.net', main)) .use(vhost('qmining.tk', qmining)) .listen(port) - logger.Log('Node version: ' + process.version) logger.Log('Listening on port: ' + port) -