This commit is contained in:
klaas 2024-09-07 16:45:12 +02:00
parent 0030ad4216
commit 046cfaeff0
3 changed files with 47 additions and 54 deletions

81
app.js
View File

@ -1,4 +1,3 @@
<<<<<<< HEAD
const express = require("express"); const express = require("express");
const session = require("express-session"); const session = require("express-session");
const bcrypt = require("bcrypt"); const bcrypt = require("bcrypt");
@ -9,32 +8,24 @@ const path = require("path");
const moment = require("moment"); const moment = require("moment");
require("dotenv").config(); require("dotenv").config();
const log = require("node-file-logger"); const log = require("node-file-logger");
======= const QRCode = require("qrcode");
const express = require('express');
const session = require('express-session');
const bcrypt = require('bcrypt');
const crypto = require('crypto');
const nodemailer = require('nodemailer');
const { Pool } = require('pg');
const path = require('path');
const moment = require('moment');
require('dotenv').config();
const log = require('node-file-logger');
const QRCode = require('qrcode');
>>>>>>> 233dce1040dfa6dc0ac991a0ef473e58d5aa6cc1
const app = express(); const app = express();
const port = process.env.PORT; const port = process.env.PORT;
const TeleBot = require('telebot'); const TeleBot = require("telebot");
const bot = new TeleBot(process.env.TELEBOT); const bot = new TeleBot(process.env.TELEBOT);
telebotChatID=process.env.TELECHAT; telebotChatID = process.env.TELECHAT;
bot.on('text', (msg) => { bot.on("text", (msg) => {
if (msg.from.id==telebotChatID) { if (msg.from.id == telebotChatID) {
msg.reply.text(msg.text); msg.reply.text(msg.text);
} else { } else {
msg.reply.text("Entschuldige, " + msg.from.username + "\nIch darf nicht mit fremden reden."); msg.reply.text(
"Entschuldige, " +
msg.from.username +
"\nIch darf nicht mit fremden reden."
);
log.Info("Telebot-nachricht: " + msg.from.username + " - " + msg.text); log.Info("Telebot-nachricht: " + msg.from.username + " - " + msg.text);
} }
}); });
@ -462,53 +453,63 @@ app.get("/register", (req, res) => {
res.render("register", { session: req.session }); // Stelle sicher, dass es eine register.ejs gibt res.render("register", { session: req.session }); // Stelle sicher, dass es eine register.ejs gibt
}); });
app.get('/contact', (req, res) => { app.get("/contact", (req, res) => {
res.render('contact', { session: req.session }); res.render("contact", { session: req.session });
}); });
app.get('/car', (req, res) => { app.get("/car", (req, res) => {
res.render('car', { session: req.session }); res.render("car", { session: req.session });
}); });
app.post('/car', (req, res) => { app.post("/car", (req, res) => {
const { kennzeichen, message, contact } = req.body; const { kennzeichen, message, contact } = req.body;
let formattedLicensePlate = kennzeichen.replace(/[^a-zA-Z0-9]/g, '').toUpperCase(); let formattedLicensePlate = kennzeichen
.replace(/[^a-zA-Z0-9]/g, "")
.toUpperCase();
if (formattedLicensePlate=='DUKL445') { if (formattedLicensePlate == "DUKL445") {
if (contact!=""){ if (contact != "") {
bot.sendMessage(telebotChatID, contact); bot.sendMessage(telebotChatID, contact);
} }
bot.sendMessage(telebotChatID, message); bot.sendMessage(telebotChatID, message);
console.log(message + contact); console.log(message + contact);
req.session.message = ['Success', 'Nachricht versendet.', 'none'] req.session.message = ["Success", "Nachricht versendet.", "none"];
} else { } else {
log.Info("Kontakt: " + contact + " - Nachricht: " + message + " - Kennzeichen: " + kennzeichen); log.Info(
"Kontakt: " +
contact +
" - Nachricht: " +
message +
" - Kennzeichen: " +
kennzeichen
);
} }
res.render('carsend', { session: req.session }); res.render("carsend", { session: req.session });
}); });
app.get('/qr', requireAuth, (req, res)=>{ app.get("/qr", requireAuth, (req, res) => {
res.render('qrcode', { session: req.session}); res.render("qrcode", { session: req.session });
}); });
app.post('/qr', requireAuth, (req, res)=>{ app.post("/qr", requireAuth, (req, res) => {
const {text, invert} = req.body; const { text, invert } = req.body;
const options = { const options = {
color: { color: {
dark: invert ? '#FFFFFF' : '#000000', // Farbe der QR-Code-Muster dark: invert ? "#FFFFFF" : "#000000", // Farbe der QR-Code-Muster
light: invert ? '#000000' : '#FFFFFF' // Farbe des Hintergrunds light: invert ? "#000000" : "#FFFFFF", // Farbe des Hintergrunds
} },
}; };
QRCode.toDataURL(text, options, (err, url) => { QRCode.toDataURL(text, options, (err, url) => {
if (err) { if (err) {
return res.send('Fehler beim Generieren des QR-Codes'); return res.send("Fehler beim Generieren des QR-Codes");
} }
res.render('qrcodeshow', { res.render("qrcodeshow", {
session: req.session, session: req.session,
qrCodeUrl: url }); qrCodeUrl: url,
});
}); });
}); });

16
package-lock.json generated
View File

@ -20,7 +20,7 @@
"node-file-logger": "^0.9.5", "node-file-logger": "^0.9.5",
"nodemailer": "^6.9.13", "nodemailer": "^6.9.13",
"pg": "^8.11.5", "pg": "^8.11.5",
"qrcode": "^1.5.3", "qrcode": "^1.5.4",
"telebot": "^1.4.1" "telebot": "^1.4.1"
} }
}, },
@ -555,12 +555,6 @@
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
}, },
"node_modules/encode-utf8": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/encode-utf8/-/encode-utf8-1.0.3.tgz",
"integrity": "sha512-ucAnuBEhUK4boH2HjVYG5Q2mQyPorvv0u/ocS+zhdw0S8AlHYY+GOFhP1Gio5z4icpP2ivFSvhtFjQi8+T9ppw==",
"license": "MIT"
},
"node_modules/encodeurl": { "node_modules/encodeurl": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -1687,13 +1681,11 @@
} }
}, },
"node_modules/qrcode": { "node_modules/qrcode": {
"version": "1.5.3", "version": "1.5.4",
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.3.tgz", "resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
"integrity": "sha512-puyri6ApkEHYiVl4CFzo1tDkAZ+ATcnbJrJ6RiBM1Fhctdn/ix9MTE3hRph33omisEbC/2fcfemsseiKgBPKZg==", "integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==",
"license": "MIT",
"dependencies": { "dependencies": {
"dijkstrajs": "^1.0.1", "dijkstrajs": "^1.0.1",
"encode-utf8": "^1.0.3",
"pngjs": "^5.0.0", "pngjs": "^5.0.0",
"yargs": "^15.3.1" "yargs": "^15.3.1"
}, },

View File

@ -22,7 +22,7 @@
"node-file-logger": "^0.9.5", "node-file-logger": "^0.9.5",
"nodemailer": "^6.9.13", "nodemailer": "^6.9.13",
"pg": "^8.11.5", "pg": "^8.11.5",
"qrcode": "^1.5.3", "qrcode": "^1.5.4",
"telebot": "^1.4.1" "telebot": "^1.4.1"
} }
} }