Compare commits
No commits in common. "74f6e1ab69483d709aca781cb95e858c78a0d57f" and "f85d19bbd655ad9099688187249195c85a0198c3" have entirely different histories.
74f6e1ab69
...
f85d19bbd6
@ -360,8 +360,7 @@ function App() {
|
|||||||
<Alert variant={'primary'}>
|
<Alert variant={'primary'}>
|
||||||
Poslední změny:
|
Poslední změny:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Oprava parsování restaurace U Motlíků, pokud neexistuje nabídka pro první den v týdnu</li>
|
<li>Tolerance existence menu na více týdnů pro restauraci U Motlíků</li>
|
||||||
<li>Oprava parsování restaurace Sladovnická, pokud nabídka nezačíná pondělím</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</Alert>
|
</Alert>
|
||||||
{dayIndex != null &&
|
{dayIndex != null &&
|
||||||
|
@ -28,13 +28,3 @@
|
|||||||
#NTFY_HOST = "http://192.168.0.113:80"
|
#NTFY_HOST = "http://192.168.0.113:80"
|
||||||
#NTFY_USERNAME="username"
|
#NTFY_USERNAME="username"
|
||||||
#NTFY_PASSWD="password"
|
#NTFY_PASSWD="password"
|
||||||
|
|
||||||
# Zapne přihlašování pomocí důvěryhodných hlaviček (trusted headers). Výchozí hodnota je false.
|
|
||||||
# V případě zapnutí je nutno vyplnit také HTTP_REMOTE_TRUSTED_IPS.
|
|
||||||
# HTTP_REMOTE_USER_ENABLED=true
|
|
||||||
|
|
||||||
# Seznam IP adres nebo rozsahů oddělených čárkou, ze kterých budou akceptovány důvěryhodné hlavičky.
|
|
||||||
# HTTP_REMOTE_TRUSTED_IPS=127.0.0.1,192.168.1.0/24
|
|
||||||
|
|
||||||
# Název důvěryhodné hlavičky obsahující login uživatele. Výchozí hodnota je 'remote-user'.
|
|
||||||
# HTTP_REMOTE_USER_HEADER_NAME=remote-user
|
|
@ -31,46 +31,26 @@ app.use(cors({
|
|||||||
origin: '*'
|
origin: '*'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Zapínatelný login přes hlavičky - pokud je zapnutý nepovolí "basicauth"
|
|
||||||
const HTTP_REMOTE_USER_ENABLED = process.env.HTTP_REMOTE_USER_ENABLED || false;
|
|
||||||
const HTTP_REMOTE_USER_HEADER_NAME = process.env.HTTP_REMOTE_USER_HEADER_NAME || 'remote-user';
|
|
||||||
if (HTTP_REMOTE_USER_ENABLED) {
|
|
||||||
if (!process.env.HTTP_REMOTE_TRUSTED_IPS) {
|
|
||||||
throw new Error('Je zapnutý login z hlaviček, ale není nastaven rozsah adres ze kterých hlavička může přijít.');
|
|
||||||
}
|
|
||||||
const HTTP_REMOTE_TRUSTED_IPS = process.env.HTTP_REMOTE_TRUSTED_IPS.split(',').map(ip => ip.trim());
|
|
||||||
//TODO: nevim jak udelat console.log pouze pro "debug"
|
|
||||||
//console.log("Budu věřit hlavičkám z: " + HTTP_REMOTE_TRUSTED_IPS);
|
|
||||||
app.set('trust proxy', HTTP_REMOTE_TRUSTED_IPS);
|
|
||||||
console.log('Zapnutý login přes hlavičky z proxy.');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ----------- Metody nevyžadující token --------------
|
// ----------- Metody nevyžadující token --------------
|
||||||
|
|
||||||
app.get("/api/whoami", (req, res) => {
|
app.get("/api/whoami", (req, res) => {
|
||||||
if (!HTTP_REMOTE_USER_ENABLED) {
|
res.send(req.header('remote-user'));
|
||||||
res.status(403).json({ error: 'Není zapnuté přihlášení z hlaviček' });
|
|
||||||
}
|
|
||||||
res.send(req.header(HTTP_REMOTE_USER_HEADER_NAME));
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post("/api/login", (req, res) => {
|
app.post("/api/login", (req, res) => {
|
||||||
if (HTTP_REMOTE_USER_ENABLED) { // je rovno app.enabled('trust proxy')
|
|
||||||
// Autentizace pomocí trusted headers
|
// Autentizace pomocí trusted headers
|
||||||
const remoteUser = req.header(HTTP_REMOTE_USER_HEADER_NAME);
|
const remoteUser = req.header('remote-user');
|
||||||
const remoteName = req.header('remote-name');
|
const remoteName = req.header('remote-name');
|
||||||
if (remoteUser && remoteUser.length > 0 && remoteName && remoteName.length > 0) {
|
if (remoteUser && remoteUser.length > 0 && remoteName && remoteName.length > 0) {
|
||||||
res.status(200).json(generateToken(Buffer.from(remoteName, 'latin1').toString(), true));
|
res.status(200).json(generateToken(Buffer.from(remoteName, 'latin1').toString(), true));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Klasická autentizace loginem
|
// Klasická autentizace loginem
|
||||||
if (!req.body?.login || req.body.login.trim().length === 0) {
|
if (!req.body?.login || req.body.login.trim().length === 0) {
|
||||||
throw Error("Nebyl předán login");
|
throw Error("Nebyl předán login");
|
||||||
}
|
}
|
||||||
// TODO zavést podmínky pro délku loginu (min i max)
|
// TODO zavést podmínky pro délku loginu (min i max)
|
||||||
res.status(200).json(generateToken(req.body.login, false));
|
res.status(200).json(generateToken(req.body.login, false));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO dočasné řešení - QR se zobrazuje přes <img>, nemáme sem jak dostat token
|
// TODO dočasné řešení - QR se zobrazuje přes <img>, nemáme sem jak dostat token
|
||||||
@ -91,15 +71,13 @@ app.get("/api/qr", (req, res) => {
|
|||||||
|
|
||||||
/** Middleware ověřující JWT token */
|
/** Middleware ověřující JWT token */
|
||||||
app.use("/api/", (req, res, next) => {
|
app.use("/api/", (req, res, next) => {
|
||||||
if (HTTP_REMOTE_USER_ENABLED) {
|
const userHeader = req.header('remote-user');
|
||||||
const userHeader = req.header(HTTP_REMOTE_USER_HEADER_NAME);
|
|
||||||
const nameHeader = req.header('remote-name');
|
const nameHeader = req.header('remote-name');
|
||||||
const emailHeader = req.header('remote-email');
|
const emailHeader = req.header('remote-email');
|
||||||
if (userHeader !== undefined && nameHeader !== undefined) {
|
if (userHeader !== undefined && nameHeader !== undefined) {
|
||||||
const remoteName = Buffer.from(nameHeader, 'latin1').toString();
|
const remoteName = Buffer.from(nameHeader, 'latin1').toString();
|
||||||
console.log("Tvuj username, name a email: %s, %s, %s.", userHeader, remoteName, emailHeader);
|
console.log("Tvuj username, name a email: %s, %s, %s.", userHeader, remoteName, emailHeader);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!req.headers.authorization) {
|
if (!req.headers.authorization) {
|
||||||
return res.status(401).json({ error: 'Nebyl předán autentizační token' });
|
return res.status(401).json({ error: 'Nebyl předán autentizační token' });
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ export const getMenuSladovnicka = async (firstDayOfWeek: Date, mock: boolean = f
|
|||||||
isSoup: false,
|
isSoup: false,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
result[dayIndex] = currentDayFood;
|
result[index] = currentDayFood;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -157,30 +157,23 @@ export const getMenuUMotliku = async (firstDayOfWeek: Date, mock: boolean = fals
|
|||||||
const html = await getHtml(U_MOTLIKU_URL);
|
const html = await getHtml(U_MOTLIKU_URL);
|
||||||
const $ = load(html);
|
const $ = load(html);
|
||||||
|
|
||||||
// Najdeme první tabulku, nad kterou je v H3 datum začínající co nejdřívějším dnem v aktuálním týdnu
|
// Najdeme první tabulku, nad kterou je v H3 datum začínající prvním dnem aktuálního týdne
|
||||||
|
// To může selhat mnoha způsoby, ale ty nemá cenu řešit dokud nenastanou
|
||||||
const tables = $('table.table.table-hover.Xtable-striped');
|
const tables = $('table.table.table-hover.Xtable-striped');
|
||||||
let usedTable;
|
let usedTable;
|
||||||
let usedDate = new Date(firstDayOfWeek.getTime());
|
const firstDayOfWeekString = `${firstDayOfWeek.getDate()}.${firstDayOfWeek.getMonth() + 1}.`;
|
||||||
for (let i = 0; i < 4; i++) {
|
|
||||||
const dayOfWeekString = `${usedDate.getDate()}.${usedDate.getMonth() + 1}.`;
|
|
||||||
for (const tableNode of tables) {
|
for (const tableNode of tables) {
|
||||||
const table = $(tableNode);
|
const table = $(tableNode);
|
||||||
const h3 = table.parent().prev();
|
const h3 = table.parent().prev();
|
||||||
const s1 = h3.text().split("-")[0].split(".");
|
const s1 = h3.text().split("-")[0].split(".");
|
||||||
const foundFirstDayString = `${s1[0]}.${s1[1]}.`;
|
const foundFirstDayString = `${s1[0]}.${s1[1]}.`;
|
||||||
if (foundFirstDayString === dayOfWeekString) {
|
if (foundFirstDayString === firstDayOfWeekString) {
|
||||||
usedTable = table;
|
usedTable = table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usedTable != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
usedDate.setDate(usedDate.getDate() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usedTable == null) {
|
if (usedTable == null) {
|
||||||
const firstDayOfWeekString = `${firstDayOfWeek.getDate()}.${firstDayOfWeek.getMonth() + 1}.`;
|
throw Error(`Nepodařilo se najít tabulku pro datum ${firstDayOfWeekString}`);
|
||||||
throw Error(`Nepodařilo se najít tabulku pro týden začínající ${firstDayOfWeekString}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = usedTable.children().first();
|
const body = usedTable.children().first();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user