mod/notification-ntfy: support authentication with bearer token

Closes: https://github.com/eworm-de/routeros-scripts/issues/86
This commit is contained in:
Christian Hesse 2024-12-13 17:40:49 +01:00
parent a7878d664f
commit d1b9b1b410
3 changed files with 9 additions and 0 deletions

View file

@ -52,6 +52,8 @@ basic authentication. Configure `NtfyServerUser` and `NtfyServerPass` for this.
Even authentication via access token is possible, adding it as password with Even authentication via access token is possible, adding it as password with
a blank username. a blank username.
Also available is `NtfyServerToken` to add a bearer token for authentication.
For a custom service installing an additional certificate may be required. For a custom service installing an additional certificate may be required.
You may want to install that certificate manually, after finding the You may want to install that certificate manually, after finding the
[certificate name from browser](../../CERTIFICATES.md). [certificate name from browser](../../CERTIFICATES.md).

View file

@ -58,6 +58,7 @@
:global NtfyServer "ntfy.sh"; :global NtfyServer "ntfy.sh";
:global NtfyServerUser []; :global NtfyServerUser [];
:global NtfyServerPass []; :global NtfyServerPass [];
:global NtfyServerToken [];
:global NtfyTopic ""; :global NtfyTopic "";
# It is possible to override e-mail, Telegram, Matrix and Ntfy setting # It is possible to override e-mail, Telegram, Matrix and Ntfy setting

View file

@ -67,6 +67,8 @@
:global NtfyServerOverride; :global NtfyServerOverride;
:global NtfyServerPass; :global NtfyServerPass;
:global NtfyServerPassOverride; :global NtfyServerPassOverride;
:global NtfyServerToken;
:global NtfyServerTokenOverride;
:global NtfyServerUser; :global NtfyServerUser;
:global NtfyServerUserOverride; :global NtfyServerUserOverride;
:global NtfyTopic; :global NtfyTopic;
@ -83,6 +85,7 @@
:local Server [ $EitherOr ($NtfyServerOverride->($Notification->"origin")) $NtfyServer ]; :local Server [ $EitherOr ($NtfyServerOverride->($Notification->"origin")) $NtfyServer ];
:local User [ $EitherOr ($NtfyServerUserOverride->($Notification->"origin")) $NtfyServerUser ]; :local User [ $EitherOr ($NtfyServerUserOverride->($Notification->"origin")) $NtfyServerUser ];
:local Pass [ $EitherOr ($NtfyServerPassOverride->($Notification->"origin")) $NtfyServerPass ]; :local Pass [ $EitherOr ($NtfyServerPassOverride->($Notification->"origin")) $NtfyServerPass ];
:local Token [ $EitherOr ($NtfyServerTokenOverride->($Notification->"origin")) $NtfyServerToken ];
:local Topic [ $EitherOr ($NtfyTopicOverride->($Notification->"origin")) $NtfyTopic ]; :local Topic [ $EitherOr ($NtfyTopicOverride->($Notification->"origin")) $NtfyTopic ];
:if ([ :len $Topic ] = 0) do={ :if ([ :len $Topic ] = 0) do={
@ -93,6 +96,9 @@
:local Headers ({ [ $FetchUserAgentStr ($Notification->"origin") ]; \ :local Headers ({ [ $FetchUserAgentStr ($Notification->"origin") ]; \
("Priority: " . [ $IfThenElse ($Notification->"silent") "low" "default" ]); \ ("Priority: " . [ $IfThenElse ($Notification->"silent") "low" "default" ]); \
("Title: " . "[" . $IdentityExtra . $Identity . "] " . ($Notification->"subject")) }); ("Title: " . "[" . $IdentityExtra . $Identity . "] " . ($Notification->"subject")) });
:if ([ :len $Token ] > 0) do={
:set Headers ($Headers, ("Authorization: Bearer " . $Token));
}
:local Text (($Notification->"message") . "\n"); :local Text (($Notification->"message") . "\n");
:if ([ :len ($Notification->"link") ] > 0) do={ :if ([ :len ($Notification->"link") ] > 0) do={
:set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")); :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . ($Notification->"link"));