feat(telegram): Zugriffskontrolle mit Chat-ID-Whitelist

- TelegramService: IsChatIdAllowed() prüft Owner + Whitelist
- /start von unbekannter ChatId: Zugriff verweigert + ChatId angezeigt
- Owner wird bei Zugriffsanfrage benachrichtigt (Username + ChatId)
- Alle Commands/Messages prüfen Whitelist vor Verarbeitung
- Neues Feld telegram_allowed_chat_ids in sessions-Tabelle
- Frontend: Input für erlaubte Chat-IDs in Session-Telegram-Settings
- API: allowedChatIds in Save/Get durchgereicht
This commit is contained in:
Meleki committed 2026-03-06 13:04:02 +01:00
1 parent 5661e55898
commit 011b26c37f
7 files changed
+91 -10

No files matched your search

+3
View File
@@ -127,6 +127,9 @@
<input type="text" id="sessionTelegramToken" placeholder="123456:ABC-DEF..." autocomplete="off">
<label>Webhook-Secret</label>
<input type="text" id="sessionTelegramSecret" readonly style="opacity: var(--semi-transparent); ">
<label>Erlaubte Chat-IDs</label>
<input type="text" id="sessionTelegramAllowed" placeholder="Kommagetrennt, z.B. 123456,789012">
<small class="form-hint">Der verknüpfte Owner ist automatisch erlaubt. Weitere Chat-IDs hier eintragen.</small>
<label>Status</label>
<div id="sessionTelegramStatusBox" class="telegram-status-box">Kein Status verfügbar</div>
<div class="telegram-actions">
+2 -2
View File
@@ -271,11 +271,11 @@ async function apiSessionTelegramGet(sessionId) {
return resp.json();
}
async function apiSessionTelegramSave(sessionId, botToken, webhookSecret) {
async function apiSessionTelegramSave(sessionId, botToken, webhookSecret, allowedChatIds) {
const resp = await fetch(`/api/sessions/${sessionId}/telegram`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ botToken, webhookSecret })
body: JSON.stringify({ botToken, webhookSecret, allowedChatIds })
});
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
+5 -1
View File
@@ -180,6 +180,7 @@ registerPage('session', {
function initSessionTelegram(sessionId) {
var tokenInput = document.getElementById('sessionTelegramToken');
var secretInput = document.getElementById('sessionTelegramSecret');
var allowedInput = document.getElementById('sessionTelegramAllowed');
var registerBtn = document.getElementById('sessionTelegramRegisterBtn');
var deleteBtn = document.getElementById('sessionTelegramDeleteBtn');
var statusBox = document.getElementById('sessionTelegramStatusBox');
@@ -187,6 +188,7 @@ function initSessionTelegram(sessionId) {
// Vorhandene Config laden + Status abrufen
apiSessionTelegramGet(sessionId).then(async function(config) {
if (config.botToken) tokenInput.value = config.botToken;
if (config.allowedChatIds) allowedInput.value = config.allowedChatIds;
if (config.webhookSecret) {
secretInput.value = config.webhookSecret;
} else {
@@ -294,7 +296,9 @@ async function refreshTelegramStatus(sessionId, statusBox, registerBtn, deleteBt
async function saveTelegramConfig(sessionId, tokenInput, secretInput) {
var token = tokenInput.value.trim();
var secret = secretInput.value.trim();
await apiSessionTelegramSave(sessionId, token, secret);
var allowedInput = document.getElementById('sessionTelegramAllowed');
var allowed = allowedInput ? allowedInput.value.trim() : '';
await apiSessionTelegramSave(sessionId, token, secret, allowed);
}
function escapeHtml(str) {