3 Commits

Author SHA1 Message Date
TheGreyDiamond
e69e40fec8 Update README.md 2021-07-09 14:42:16 +02:00
TheGreyDiamond
eadf729190 Update README.md 2021-07-09 14:42:04 +02:00
TheGreyDiamond
1377ae15ba Update README.md 2021-07-06 21:10:47 +02:00
6 changed files with 598 additions and 3752 deletions

View File

@@ -10,8 +10,7 @@
"plugin:@typescript-eslint/recommended" "plugin:@typescript-eslint/recommended"
], ],
"rules": { "rules": {
"@typescript-eslint/no-var-requires": 0, "@typescript-eslint/no-var-requires": 0
"no-control-regex": 0
} }
} }

View File

@@ -1,2 +1,20 @@
# Elevatormap Rewritten # Elevatormap Rewritten
The elevator map at thegreydiamond.de/elevatormap has been offline for some time now, as it was very ineffective and didn't accept user contributions. This is an attempted by the original author to rewrite the project in Node.js. The elevator map at thegreydiamond.de/elevatormap has been offline for some time now, as it was very ineffective and didn't accept user contributions. This is an attempted by the original author to rewrite the project in Node.js.
## Host your own
Requirements:
- Node
- MySQL Server (MariaDB)
- Accounts for Fontawesome & hCaptcha
Setup steps:
1. Setup DB access
2. Change config file to your needs
3. Install dependencies with `npm install`
4. Make .js file with `npm run makeJS` (skip if you want to test it)
5. Start it with `npm start` (or use pm2)
It will autogenerate all tables needed. And then startup.
ToDo:
- [ ] Allow user edits
- [ ] Allow moderation

View File

@@ -5,6 +5,7 @@ const Eta = require("eta");
const winston = require("winston"); const winston = require("winston");
const mysql = require("mysql"); const mysql = require("mysql");
const bodyParser = require("body-parser"); const bodyParser = require("body-parser");
// const csp = require(`helmet`);
const session = require("express-session"); const session = require("express-session");
const nodemailer = require("nodemailer"); const nodemailer = require("nodemailer");
@@ -31,12 +32,34 @@ logger.add(
const app = express(); const app = express();
/*
app.use(csp.contentSecurityPolicy({
useDefaults: true,
contentSecurityPolicy: false,
crossOriginEmbedderPolicy: false,
directives: {
"default-src": [`'self'`],
"img-src": [`'self'`],
scriptSrc: [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`, "unsafe-inline", "unsafe-eval","'unsafe-inline'"],
"script-src-attr": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`, "unsafe-inline", "unsafe-eval"],
"frame-src": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`],
"style-src": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`, `'unsafe-inline'`],
"connect-src": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`],
"font-src": [`'self'`, `https://*.fontawesome.com`],
},
}))
*/
const startUpTime = Math.floor(new Date().getTime() / 1000); const startUpTime = Math.floor(new Date().getTime() / 1000);
// Skeleton Variables
let fontawesomeKey = ""; let fontawesomeKey = "";
let mapboxAccessToken = ""; let mapboxAccessToken = "";
let mysqlData = { "user": "", "password": "", "database": "", "allowCreation": false }; let mysqlData = { "user": "", "password": "", "database": "", "allowCreation": false };
let hCaptcha = { "sitekey": "", "secret": "" };
let mailConf = { "host": "", "port": 0, "username": "", "password": "" }; let mailConf = { "host": "", "port": 0, "username": "", "password": "" };
let serverAdress = ""; let serverAdress = "";
let cookieSecret = "" let cookieSecret = ""
@@ -71,14 +94,12 @@ try {
); );
} }
// Express (server) preperation
app.use(express.static("static")); app.use(express.static("static"));
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(session({ secret: cookieSecret })); app.use(session({ secret: cookieSecret }));
app.use(function (req, res, next) { app.use(function (req, res, next) {
// PreShow Errorpage handler
const pathesWhichRequireDB = ["map", "login", "register"]; const pathesWhichRequireDB = ["map", "login", "register"];
const pathesWhichRequireLogin = ["createElevator"]; const pathesWhichRequireLogin = ["createElevator"];
const path = req.path const path = req.path
@@ -148,9 +169,9 @@ app.use(function (req, res, next) {
} else { } else {
console.log("Stopped further exec of route") console.log("Stopped further exec of route")
} }
}) })
// Mail preperation
const transport = nodemailer.createTransport({ const transport = nodemailer.createTransport({
host: mailConf.host, host: mailConf.host,
port: mailConf.port, port: mailConf.port,
@@ -158,12 +179,15 @@ const transport = nodemailer.createTransport({
secure: false, secure: false,
debug: true, debug: true,
disableFileAccess: true, disableFileAccess: true,
//authMethod: "START TLS",
auth: { auth: {
user: mailConf.username, user: mailConf.username,
pass: mailConf.password, pass: mailConf.password,
}, },
}); });
//let transporter = nodemailer.createTransport(transport)
//console.log(transport.host)
logger.info("Testing SMTP connection"); logger.info("Testing SMTP connection");
transport.verify(function (error) { transport.verify(function (error) {
if (error) { if (error) {
@@ -173,6 +197,9 @@ transport.verify(function (error) {
} }
}); });
app.use(session({ secret: cookieSecret }));
// Basic defines for html // Basic defines for html
const metainfo = { const metainfo = {
author: "TheGreydiamond", author: "TheGreydiamond",
@@ -193,6 +220,8 @@ let con = mysql.createConnection({
database: mysqlData.database, database: mysqlData.database,
}); });
function checkIfMySQLStructureIsReady() { function checkIfMySQLStructureIsReady() {
if (mysqlIsUpAndOkay) { if (mysqlIsUpAndOkay) {
// Only if MySQL is ready // Only if MySQL is ready
@@ -259,7 +288,7 @@ con.connect(function (err) {
}); });
// Routes // Routes
app.get("/", function (req, res) { // Index page app.get("/", function (req, res) {
const data = fs.readFileSync("templates/index.html", "utf8"); const data = fs.readFileSync("templates/index.html", "utf8");
res.send( res.send(
Eta.render(data, { Eta.render(data, {
@@ -271,7 +300,7 @@ app.get("/", function (req, res) { // Index page
); );
}); });
app.get("/map", function (req, res) { // Map page showing all elevators app.get("/map", function (req, res) {
const data = fs.readFileSync("templates/map.html", "utf8"); const data = fs.readFileSync("templates/map.html", "utf8");
res.send( res.send(
Eta.render(data, { Eta.render(data, {
@@ -285,7 +314,7 @@ app.get("/map", function (req, res) { // Map page showing all elevators
}); });
app.get("/createElevator", function (req, res) { // Page to create a new elvator app.get("/createElevator", function (req, res) {
const data = fs.readFileSync("templates/createElevator.html", "utf8"); const data = fs.readFileSync("templates/createElevator.html", "utf8");
res.send( res.send(
Eta.render(data, { Eta.render(data, {
@@ -302,9 +331,9 @@ require('./routes/api.route.ts')(app, con, mysqlIsUpAndOkay, logger, metainfo);
require('./routes/debug.route.ts')(app, con, logger, metainfo); require('./routes/debug.route.ts')(app, con, logger, metainfo);
require('./routes/auth.route.ts')(app, con, logger, metainfo, jsonConfigGlobal); require('./routes/auth.route.ts')(app, con, logger, metainfo, jsonConfigGlobal);
// Some loops for handeling stuff, // Some loops for handeling stuff
setInterval(() => { setInterval(() => {
if (mysqlIsUpAndOkay == false) { // SQL reconnect if (mysqlIsUpAndOkay == false) {
logger.warn("Retrying to connect to MySQL"); logger.warn("Retrying to connect to MySQL");
con = mysql.createConnection({ con = mysql.createConnection({
host: "localhost", host: "localhost",
@@ -324,7 +353,7 @@ setInterval(() => {
} }
}); });
} }
}, 60*1000); // Every minute }, 60000);
// App start // App start
app.listen(port, () => { app.listen(port, () => {

4265
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,19 +17,19 @@
"url": "git+https://github.com/TheGreyDiamond/elevatormapRewritten.git" "url": "git+https://github.com/TheGreyDiamond/elevatormapRewritten.git"
}, },
"author": "TheGreydiamond", "author": "TheGreydiamond",
"license": "MIT", "license": "ISC",
"bugs": { "bugs": {
"url": "https://github.com/TheGreyDiamond/elevatormapRewritten/issues" "url": "https://github.com/TheGreyDiamond/elevatormapRewritten/issues"
}, },
"homepage": "https://github.com/TheGreyDiamond/elevatormapRewritten", "homepage": "https://github.com/TheGreyDiamond/elevatormapRewritten#readme",
"dependencies": { "dependencies": {
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"eta": "^1.12.3", "eta": "^1.12.2",
"express": "^4.17.1", "express": "^4.17.1",
"express-session": "^1.17.2", "express-session": "^1.17.2",
"greeting-time": "^1.0.0", "greeting-time": "^1.0.0",
"hcaptcha": "0.1.0", "hcaptcha": "0.0.2",
"helmet": "^4.6.0", "helmet": "^4.6.0",
"multer": "^1.4.2", "multer": "^1.4.2",
"mysql": "^2.18.1", "mysql": "^2.18.1",
@@ -38,9 +38,9 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.0.0", "@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.33.0", "@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.32.0", "eslint": "^7.26.0",
"eslint-config-strongloop": "^2.1.0", "eslint-config-strongloop": "^2.1.0",
"typescript": "^4.2.4" "typescript": "^4.2.4"
} }

View File

@@ -58,6 +58,7 @@ module.exports = function (app, con, mysqlIsUpAndOkay, logger) {
app.get("/api/resolveNameById", function (req, res) { app.get("/api/resolveNameById", function (req, res) {
if (req.query.id != undefined && req.query.id != "") { if (req.query.id != undefined && req.query.id != "") {
const sql = "SELECT username FROM users WHERE id=?"; const sql = "SELECT username FROM users WHERE id=?";
con.query(sql, [req.query.id], function (err, result) { con.query(sql, [req.query.id], function (err, result) {
if (err) { if (err) {