From 66ec420527e8cbfdda3f55228461d591511e68c0 Mon Sep 17 00:00:00 2001 From: proffapt Date: Fri, 28 Jun 2024 14:43:37 +0530 Subject: [PATCH] feat: enable cookie auth for heimdall x naarad --- mftp/env.example.py | 4 +++- mftp/ntfy.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mftp/env.example.py b/mftp/env.example.py index 2297d95..656f3e8 100644 --- a/mftp/env.example.py +++ b/mftp/env.example.py @@ -22,4 +22,6 @@ NTFY_TOPIC_ICON = "https://miro.medium.com/v2/resize:fit:600/1*O94LHxqfD_JGogOKyuBFgA.jpeg" ## Optional: only if the topic is restricted NTFY_USER = "testuser" -NTFY_PASS = "fakepassword" \ No newline at end of file +NTFY_PASS = "fakepassword" +## Optional (specific to metakgp [naarad] architecture): Heimdall security token +HEIMDALL_COOKIE = '17ab96bd8ffbe8ca58a78657a918558' diff --git a/mftp/ntfy.py b/mftp/ntfy.py index 38f034d..5943244 100644 --- a/mftp/ntfy.py +++ b/mftp/ntfy.py @@ -7,7 +7,7 @@ from bs4 import BeautifulSoup as bs from notice import update_lsni, has_idx_mutated from endpoints import NOTICE_CONTENT_URL, ATTACHMENT_URL -from env import NTFY_BASE_URL, NTFY_TOPIC, NTFY_TOPIC_ICON, NTFY_USER, NTFY_PASS +from env import NTFY_BASE_URL, NTFY_TOPIC, NTFY_TOPIC_ICON, NTFY_USER, NTFY_PASS, HEIMDALL_COOKIE def ntfy_priority(subject): match subject: @@ -107,15 +107,20 @@ def send(notifications, lsnif, notices): if NTFY_USER and NTFY_PASS: headers['Authorization'] = f"Basic {str(base64.b64encode(bytes(NTFY_USER + ':' + NTFY_PASS, 'utf-8')), 'utf-8')}" + cookies = {} + if HEIMDALL_COOKIE: + cookies = {'heimdall': HEIMDALL_COOKIE} + if notification['Attachment']: headers['Filename'] = notification['Attachment'] response = requests.put( request_url, headers=headers, - data=open(notification['Attachment'], 'rb') + data=open(notification['Attachment'], 'rb'), + cookies=cookies ) else: - response = requests.put(request_url, headers=headers) + response = requests.put(request_url, headers=headers, cookies=cookies) except Exception as e: logging.error(f" Failed to request NTFY SERVER: {notification['Title']} ~ {str(e)}")