From 708996ed58f031fd31d7696a98adfc287db9905a Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Wed, 19 Jan 2022 16:23:56 +0200 Subject: Tested on Linux Mint & some bug fixes --- .gitignore | 4 ++++ README.md | 7 ++++++- scrape.js | 2 +- server.js | 9 ++++----- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ca582b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +Classes +node_modules +package-lock.json +shifts.txt \ No newline at end of file diff --git a/README.md b/README.md index 5ac073c..c593e02 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ Readme coming soon! ## Setup -If you want to set up the server, you will have to get a SSL certificate or generate one yourself. If you want to run a dedicated server that can update, you also need to add the cron jobs from crontab\_add. You must create a MySQL DB and give its login info in ../dblogin.txt. The database should have the following tables set up: +You will need a SSL certificate if you want to use https. +You need to install node.js and MySQL (+ npm install mysql2). +You will need to update the server with the help of the food shift message and a tab separated list of classes (just copypaste from excel from the Kurssitarjotin) +You probably want to set up cron to run some cronjobs from crontab_add.txt. +You need to provide the login info to the MySQL DB in ../dblogin.txt. Logging in as root was found problematic on Mint, but feel free to try if you want to. +You should create the following tables, because the server code wont do it for you. CREATE TABLE shiftnames ( day INT, diff --git a/scrape.js b/scrape.js index 0ae30aa..c7a5743 100644 --- a/scrape.js +++ b/scrape.js @@ -1,5 +1,5 @@ const https = require("https"); -const parse = require("./DBPARSE.js"); +const parse = require("./dbparse.js"); const fs = require("fs"); const events = require("events"); diff --git a/server.js b/server.js index 1431465..b01b6de 100644 --- a/server.js +++ b/server.js @@ -32,8 +32,8 @@ async function init() scrape.food(scrape.link(1)), scrape.food(scrape.link(2)), openFile("../dblogin.txt"), - openFile("../Certificate/key.pem"), - openFile("../Certificate/cert.pem") + openFile("../Certificate/key.pem"), + openFile("../Certificate/cert.pem") ]); // https options, you need to get a certificate in the file ../Certificate for the server to work @@ -93,7 +93,7 @@ async function init() } // start server - const runningServer = http.createServer(server).listen(8080); + const runningServer = https.createServer(httpsOpts, server).listen(8080); // stop server async function closeServer() { @@ -160,7 +160,7 @@ async function buildMain(args) const d = new Date(); let day = d.getDay(); day = (day + +(day === 0) * 7) - 1; - const actualDay = day; + const actualDay = day + (+(day === 0) * 7); day = +(!(day === 5) && !(day === 6)) * day; if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) >= 0) && (parseInt(query.day) < 5)) day = parseInt(query.day); @@ -216,7 +216,6 @@ async function buildMain(args) // get the food day += (day === 0) * 7; - actualDay += (actualDay === 0) * 7; let food; food = foods[ +(day < actualDay) ][day]; if (food !== undefined) -- cgit v1.2.3