Poprawka botto bar i wersje językowe
This commit is contained in:
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
# Blokuj publiczny dostęp do cache (mapowanie QR → stoliki, menu JSON).
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
@@ -19,14 +19,17 @@ function resolveGuestQueueTableId(string $tableId, string $qrHash): string
|
||||
{
|
||||
global $conn;
|
||||
|
||||
if ($tableId === '' && $qrHash !== '' && isset($conn)) {
|
||||
$resolved = getTableNameByHash($conn, $qrHash);
|
||||
if ($resolved !== '') {
|
||||
$tableId = $resolved;
|
||||
}
|
||||
// Wymagamy prawidłowego hasha QR — samo tableId (łatwe do odgadnięcia) nie wystarczy.
|
||||
if ($qrHash === '' || !isset($conn)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return trim($tableId);
|
||||
$resolved = getTableNameByHash($conn, $qrHash);
|
||||
if ($resolved === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return trim($resolved);
|
||||
}
|
||||
|
||||
function hasPendingGuestAction(PDO $pdo, string $tableId, string $messageType): bool
|
||||
@@ -285,7 +288,7 @@ if ($tableId === '') {
|
||||
http_response_code(422);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'tableId is required',
|
||||
'message' => 'Valid qrHash is required',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
+40
-6
@@ -1,17 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Adres IP klienta (pierwszy z X-Forwarded-For lub REMOTE_ADDR).
|
||||
* Czy REMOTE_ADDR to lokalny hop / reverse proxy, któremu wolno
|
||||
* przekazać prawdziwy IP klienta w X-Forwarded-For.
|
||||
*/
|
||||
function isTrustedForwardingHop(string $remoteAddr): bool
|
||||
{
|
||||
$ip = normalizeClientIp($remoteAddr);
|
||||
if ($ip === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in_array($ip, ['127.0.0.1', '::1'], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Proxy / Apache na LAN restauracji (goście Wi‑Fi widziani jako 10.x w XFF)
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
foreach (['10.0.0.0/8', '192.168.0.0/16', '172.16.0.0/12'] as $cidr) {
|
||||
if (ipv4InCidr($ip, $cidr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adres IP klienta.
|
||||
* X-Forwarded-For uznajemy wyłącznie, gdy połączenie przychodzi z zaufanego
|
||||
* hopa (localhost / LAN) — inaczej każdy w internecie mógłby podrobić IP
|
||||
* i ominąć geo. Bezpośredni dostęp z internetu = samo REMOTE_ADDR.
|
||||
*/
|
||||
function getRequestClientIp(): string
|
||||
{
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$parts = explode(',', (string) $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
$remote = trim((string) ($_SERVER['REMOTE_ADDR'] ?? ''));
|
||||
|
||||
return trim($parts[0]);
|
||||
if (isTrustedForwardingHop($remote) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$parts = explode(',', (string) $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
$forwarded = normalizeClientIp(trim($parts[0]));
|
||||
if ($forwarded !== '' && filter_var($forwarded, FILTER_VALIDATE_IP)) {
|
||||
return $forwarded;
|
||||
}
|
||||
}
|
||||
|
||||
return trim((string) ($_SERVER['REMOTE_ADDR'] ?? ''));
|
||||
return normalizeClientIp($remote);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +77,7 @@ function getGeoBypassTrustedIps(): array
|
||||
}
|
||||
|
||||
/**
|
||||
* Pule wewnętrznych sieci — goście widziani przez lokalny serwer (REMOTE_ADDR z LAN).
|
||||
* Pule wewnętrznych sieci — goście na Wi‑Fi restauracji.
|
||||
*/
|
||||
function getGeoBypassTrustedCidrs(): array
|
||||
{
|
||||
|
||||
@@ -4,6 +4,25 @@ header('Content-Type: application/json; charset=utf-8');
|
||||
require_once __DIR__ . '/../config/database.php';
|
||||
require_once __DIR__ . '/message_text_helper.php';
|
||||
|
||||
$waiterConfig = require __DIR__ . '/../config/waiter.php';
|
||||
$expectedToken = (string) ($waiterConfig['feed_token'] ?? '');
|
||||
$providedToken = '';
|
||||
|
||||
if (isset($_SERVER['HTTP_X_WAITER_TOKEN'])) {
|
||||
$providedToken = trim((string) $_SERVER['HTTP_X_WAITER_TOKEN']);
|
||||
} elseif (isset($_GET['token'])) {
|
||||
$providedToken = trim((string) $_GET['token']);
|
||||
}
|
||||
|
||||
if ($expectedToken === '' || !hash_equals($expectedToken, $providedToken)) {
|
||||
http_response_code(401);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Unauthorized',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
|
||||
Reference in New Issue
Block a user