Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions emhttp/plugins/dynamix/agents/Apprise.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Agent>
<Name>Apprise</Name>
<Variables>
<Variable Help="The server URL including protocol and port - /notify will be automatically appended" Desc="Server URL" Default="http://localhost:8000">SERVER_URL</Variable>
<Variable Help="Optional Stateful Key (if configured in Apprise). NOTE: This will override any Stateless URLs provided. Set this field to 'none' if not being used." Desc="Stateful Key" Default="none">STATEFUL_KEY</Variable>
<Variable Help="Optional Tags (if configured in Apprise). Set to 'none' if not being used." Desc="Tags" Default="none">TAGS</Variable>
<Variable Help="Optional Comma or Space Separated List of Stateless Urls - mailto://user:pass@gmail.com, gotify://host/token. NOTE: This value is ignored if a Stateful Key is provided. Set this field to 'none' if not being used." Desc="Stateless Urls" Default="">STATELESS_URLS</Variable>
<Variable Help="Specify the fields which are included in the title of the notification." Desc="Notification Title" Default="$SUBJECT">TITLE</Variable>
<Variable Help="Specify the fields which are included in the message body of the notification." Desc="Notification Message" Default="$DESCRIPTION">MESSAGE</Variable>
</Variables>
<Script>
<![CDATA[
#!/bin/bash
############
{0}
############
MESSAGE=$(echo -e "$MESSAGE")
case "$IMPORTANCE" in
'normal' )
PRIORITY="info"
;;
'warning' )
PRIORITY="warning"
;;
'alert' )
PRIORITY="failure"
;;
esac
Comment on lines +14 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Bash script logic is clear, but input handling and quoting could be improved.

  • The mapping of IMPORTANCE to PRIORITY is correct and clear.
  • However, the script does not quote variable expansions (e.g., $STATEFUL_KEY, $STATELESS_URLS, $TAGS) in the if statements, which can cause errors if variables contain spaces or are empty.
  • Consider quoting all variable expansions to prevent word splitting and unexpected behavior.

Example fix:

-if [ $STATEFUL_KEY == 'none' ]; then STATEFUL_KEY=; fi
-if [ $STATELESS_URLS == 'none' ]; then STATELESS_URLS=; fi
-if [ $TAGS == 'none' ]; then TAGS=; fi
+if [ "$STATEFUL_KEY" == 'none' ]; then STATEFUL_KEY=; fi
+if [ "$STATELESS_URLS" == 'none' ]; then STATELESS_URLS=; fi
+if [ "$TAGS" == 'none' ]; then TAGS=; fi

Committable suggestion skipped: line range outside the PR's diff.


if [ $STATEFUL_KEY == 'none' ]; then STATEFUL_KEY=; fi
if [ $STATELESS_URLS == 'none' ]; then STATELESS_URLS=; fi
if [ $TAGS == 'none' ]; then TAGS=; fi

# Remove any trailing slash
SERVER_URL=${SERVER_URL%/}

JSON="{\"urls\":\"$STATELESS_URLS\",\"tag\":\"$TAGS\",\"type\":\"$PRIORITY\",\"title\":\"$TITLE\",\"body\":\"$MESSAGE\"}"

curl -X POST \
-H "Content-Type: application/json" \
-d "$JSON" \
$SERVER_URL/notify${STATEFUL_KEY:+/$STATEFUL_KEY} 2>&1
Comment on lines +38 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Potential JSON injection and quoting issues in payload construction.

  • The JSON payload is constructed via string interpolation, which is unsafe if any variable contains quotes, backslashes, or newlines. This can break the JSON structure and potentially cause notification failures or security issues.
  • Consider using a tool like jq -n or printf '%s' with proper escaping to build the JSON payload safely.

Example fix using jq (if available in the environment):

-JSON="{\"urls\":\"$STATELESS_URLS\",\"tag\":\"$TAGS\",\"type\":\"$PRIORITY\",\"title\":\"$TITLE\",\"body\":\"$MESSAGE\"}"
+JSON=$(jq -n \
+  --arg urls "$STATELESS_URLS" \
+  --arg tag "$TAGS" \
+  --arg type "$PRIORITY" \
+  --arg title "$TITLE" \
+  --arg body "$MESSAGE" \
+  '{urls: $urls, tag: $tag, type: $type, title: $title, body: $body}')

If jq is not available, at minimum, escape double quotes and backslashes in variables before constructing the JSON string.

  • Additionally, consider capturing the exit code of curl and logging or handling errors for better robustness.

Would you like a ready-to-use Bash snippet for safe JSON construction without jq?

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
JSON="{\"urls\":\"$STATELESS_URLS\",\"tag\":\"$TAGS\",\"type\":\"$PRIORITY\",\"title\":\"$TITLE\",\"body\":\"$MESSAGE\"}"
curl -X POST \
-H "Content-Type: application/json" \
-d "$JSON" \
$SERVER_URL/notify${STATEFUL_KEY:+/$STATEFUL_KEY} 2>&1
JSON=$(jq -n \
--arg urls "$STATELESS_URLS" \
--arg tag "$TAGS" \
--arg type "$PRIORITY" \
--arg title "$TITLE" \
--arg body "$MESSAGE" \
'{urls: $urls, tag: $tag, type: $type, title: $title, body: $body}')
curl -X POST \
-H "Content-Type: application/json" \
-d "$JSON" \
$SERVER_URL/notify${STATEFUL_KEY:+/$STATEFUL_KEY} 2>&1

]]>
</Script>
</Agent>
Binary file added emhttp/plugins/dynamix/icons/apprise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.