9 Commits

Author SHA1 Message Date
TheGreyDiamond
2e1eec4b7a Merge pull request #2 from TheGreyDiamond/dependabot/npm_and_yarn/tar-6.1.11
Bump tar from 6.1.5 to 6.1.11
2021-09-01 08:17:33 +02:00
dependabot[bot]
7134466431 Bump tar from 6.1.5 to 6.1.11
Bumps [tar](https://github.com/npm/node-tar) from 6.1.5 to 6.1.11.
- [Release notes](https://github.com/npm/node-tar/releases)
- [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-tar/compare/v6.1.5...v6.1.11)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-31 23:31:45 +00:00
TheGreyDiamond
808fa94a1a Merge pull request #1 from TheGreyDiamond/dependabot/npm_and_yarn/tar-6.1.5
Bump tar from 6.1.0 to 6.1.5
2021-08-04 22:33:35 +02:00
dependabot[bot]
f2bef7aa43 Bump tar from 6.1.0 to 6.1.5
Bumps [tar](https://github.com/npm/node-tar) from 6.1.0 to 6.1.5.
- [Release notes](https://github.com/npm/node-tar/releases)
- [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-tar/compare/v6.1.0...v6.1.5)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-04 03:58:06 +00:00
TheGreyDiamond
3c0b455341 Update map.html 2021-07-11 21:47:32 +02:00
TheGreyDiamond
5a87784ceb Update map.html 2021-07-11 21:44:59 +02:00
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
7 changed files with 597 additions and 3750 deletions

View File

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

View File

@@ -1,2 +1,20 @@
# 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.
## 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 mysql = require("mysql");
const bodyParser = require("body-parser");
// const csp = require(`helmet`);
const session = require("express-session");
const nodemailer = require("nodemailer");
@@ -31,12 +32,34 @@ logger.add(
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);
// Skeleton Variables
let fontawesomeKey = "";
let mapboxAccessToken = "";
let mysqlData = { "user": "", "password": "", "database": "", "allowCreation": false };
let hCaptcha = { "sitekey": "", "secret": "" };
let mailConf = { "host": "", "port": 0, "username": "", "password": "" };
let serverAdress = "";
let cookieSecret = ""
@@ -71,14 +94,12 @@ try {
);
}
// Express (server) preperation
app.use(express.static("static"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(session({ secret: cookieSecret }));
app.use(function (req, res, next) {
// PreShow Errorpage handler
const pathesWhichRequireDB = ["map", "login", "register"];
const pathesWhichRequireLogin = ["createElevator"];
const path = req.path
@@ -148,9 +169,9 @@ app.use(function (req, res, next) {
} else {
console.log("Stopped further exec of route")
}
})
// Mail preperation
const transport = nodemailer.createTransport({
host: mailConf.host,
port: mailConf.port,
@@ -158,12 +179,15 @@ const transport = nodemailer.createTransport({
secure: false,
debug: true,
disableFileAccess: true,
//authMethod: "START TLS",
auth: {
user: mailConf.username,
pass: mailConf.password,
},
});
//let transporter = nodemailer.createTransport(transport)
//console.log(transport.host)
logger.info("Testing SMTP connection");
transport.verify(function (error) {
if (error) {
@@ -173,6 +197,9 @@ transport.verify(function (error) {
}
});
app.use(session({ secret: cookieSecret }));
// Basic defines for html
const metainfo = {
author: "TheGreydiamond",
@@ -193,6 +220,8 @@ let con = mysql.createConnection({
database: mysqlData.database,
});
function checkIfMySQLStructureIsReady() {
if (mysqlIsUpAndOkay) {
// Only if MySQL is ready
@@ -259,7 +288,7 @@ con.connect(function (err) {
});
// Routes
app.get("/", function (req, res) { // Index page
app.get("/", function (req, res) {
const data = fs.readFileSync("templates/index.html", "utf8");
res.send(
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");
res.send(
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");
res.send(
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/auth.route.ts')(app, con, logger, metainfo, jsonConfigGlobal);
// Some loops for handeling stuff,
// Some loops for handeling stuff
setInterval(() => {
if (mysqlIsUpAndOkay == false) { // SQL reconnect
if (mysqlIsUpAndOkay == false) {
logger.warn("Retrying to connect to MySQL");
con = mysql.createConnection({
host: "localhost",
@@ -324,7 +353,7 @@ setInterval(() => {
}
});
}
}, 60*1000); // Every minute
}, 60000);
// App start
app.listen(port, () => {

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

View File

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

View File

@@ -85,7 +85,8 @@ L.tileLayer(
{
attribution:
'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 3,
maxZoom: 100,
minZoom: 2,
id: "mapbox/streets-v11",
tileSize: 512,
zoomOffset: -1,