Skip to content

Commit

Permalink
feat: enable cookie auth for heimdall x naarad
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jun 28, 2024
1 parent a400168 commit 66ec420
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion mftp/env.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
NTFY_PASS = "fakepassword"
## Optional (specific to metakgp [naarad] architecture): Heimdall security token
HEIMDALL_COOKIE = '17ab96bd8ffbe8ca58a78657a918558'
11 changes: 8 additions & 3 deletions mftp/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)}")
Expand Down

0 comments on commit 66ec420

Please sign in to comment.