Auto search untis server

This commit is contained in:
2023-09-12 10:53:59 +02:00
parent 4f12ac68be
commit 61249a6985
3 changed files with 45 additions and 21 deletions

View File

@@ -24,7 +24,8 @@ services:
- 'UNTIS_SCHOOLS=School1,School2' # Comma seperated list of schools (find in URL when logging in to untis, replace + with space)
- 'UNTIS_USERNAMES=USERNAME1,USERNAME2' # Usernames for untis schools
- 'UNTIS_PASSWORDS=PASSWORD1,PASSWORD2' # Passwords for untis schools
- 'UNTIS_SERVERS=cissa.webuntis.com,neilo.webuntis.com' # Servers for untis chools
```
(Nicht benötigte Umgebungsvariablen können entfernt werden)
* `docker-compose up -d` im Verzeichnis ausführen
* `docker-compose up -d` im Verzeichnis ausführen

View File

@@ -5,5 +5,4 @@ CALDAV_PASSWORD=PASSWORD # Password for the caldav server
CALDAV_CALENDAR=CALENDARNAME # Calendar name from the caldav server
UNTIS_SCHOOLS=School1,School2 # Comma seperated list of schools (find in URL when logging in to untis, replace + with space)
UNTIS_USERNAMES=USERNAME1,USERNAME2 # Usernames for untis schools
UNTIS_PASSWORDS=PASSWORD1,PASSWORD2 # Passwords for untis schools
UNTIS_SERVERS=server1.webuntis.com,server2.webuntis.com # Servers for untis chools
UNTIS_PASSWORDS=PASSWORD1,PASSWORD2 # Passwords for untis schools

View File

@@ -58,24 +58,48 @@ function getCalendarEntries(weekDate) {
return result;
}
async function getUntis(weekDate) {
let untisSchools = [];
let untisUsernames = [];
let untisPasswords = [];
let untisServers = [];
async function getUntisServer(school) {
const searchSchool = await fetch("https://mobile.webuntis.com/ms/schoolquery2", {
"method": "POST",
"body": JSON.stringify({
"id": "wu_schulsuche-" + (new Date()).getTime(),
"method": "searchSchool",
"params": [
{
"search": school
}
],
"jsonrpc": "2.0"
})
});
let optionsSuccess = true;
try {
untisSchools = process.env.UNTIS_SCHOOLS.split(",");
untisUsernames = process.env.UNTIS_USERNAMES.split(",");
untisPasswords = process.env.UNTIS_PASSWORDS.split(",");
untisServers = process.env.UNTIS_SERVERS.split(",");
} catch (error) {
optionsSuccess = false;
}
const searchSchoolJson = await searchSchool.json();
if (!optionsSuccess) {
return "Keine Untis-Optionen gefunden";
return searchSchoolJson.result.schools[0].server;
}
const untisServers = [];
let untisSchools = [];
let untisUsernames = [];
let untisPasswords = [];
async function getUntis(weekDate) {
if (untisServers.length == 0) {
let optionsSuccess = true;
try {
untisSchools = process.env.UNTIS_SCHOOLS.split(",");
untisUsernames = process.env.UNTIS_USERNAMES.split(",");
untisPasswords = process.env.UNTIS_PASSWORDS.split(",");
} catch (error) {
optionsSuccess = false;
}
if (!optionsSuccess) {
return "Keine Untis-Optionen gefunden";
}
for (school of untisSchools) {
untisServers.push(await getUntisServer(school));
}
}
let teachingContent = "";
@@ -182,7 +206,7 @@ app.get('/show', (req, res) => {
if (process.env.CALDAV_URL == undefined || process.env.CALDAV_USER == undefined || process.env.CALDAV_PASSWORD == undefined || process.env.CALDAV_CALENDAR == undefined) {
showCalendar = false;
}
if (process.env.UNTIS_SCHOOLS == undefined || process.env.UNTIS_USERNAMES == undefined || process.env.UNTIS_PASSWORDS == undefined || process.env.UNTIS_SERVERS == undefined) {
if (process.env.UNTIS_SCHOOLS == undefined || process.env.UNTIS_USERNAMES == undefined || process.env.UNTIS_PASSWORDS == undefined) {
showUntis = false;
}
}