From 2f982102a6633ad0fa4536112ebfcfacafc1ea99 Mon Sep 17 00:00:00 2001 From: Gianluca Ruocco Date: Thu, 18 Dec 2025 22:13:07 +0100 Subject: [PATCH 1/3] Zentik notifier agent added --- .../plugins/dynamix/agents/ZentikNotifier.xml | 119 ++++++++++++++++++ .../plugins/dynamix/icons/zentiknotifier.png | Bin 0 -> 1309 bytes 2 files changed, 119 insertions(+) create mode 100644 emhttp/plugins/dynamix/agents/ZentikNotifier.xml create mode 100644 emhttp/plugins/dynamix/icons/zentiknotifier.png diff --git a/emhttp/plugins/dynamix/agents/ZentikNotifier.xml b/emhttp/plugins/dynamix/agents/ZentikNotifier.xml new file mode 100644 index 0000000000..d31323a548 --- /dev/null +++ b/emhttp/plugins/dynamix/agents/ZentikNotifier.xml @@ -0,0 +1,119 @@ + + + ZentikNotifier + + SERVER_URL + BUCKET_ID + ACCESS_TOKEN + USER_IDS + TITLE + SUBTITLE + MESSAGE + + + diff --git a/emhttp/plugins/dynamix/icons/zentiknotifier.png b/emhttp/plugins/dynamix/icons/zentiknotifier.png new file mode 100644 index 0000000000000000000000000000000000000000..eff390525928b04406246f2d0714160b924cd230 GIT binary patch literal 1309 zcmV+&1>*XNP)n^HTmo35BBIq|(R!_@MUl$@ z35JUV5JYrPDkb6#kN^oNj38CVncCJ1Lv6Li3W%Ul5dnkJT+T`M>EwX@(3yUC=C`}& z%ro!qyR*`+T0W8_NxJwOnt~2mb*&6%SaGCV5UI_O(gew7NNRw+^^jN#JI^C_oWrr> z9K$;=(7M+wG(N}X)6DXv^xZAeQmwGP4iZeTvFiUx_#QT!V3P?ppN8$V)9k7vO_kN( zCpx(qzN|uQtU}pjLTot=AJ|$0+iGU=%=B7(l}{$vQiDh^p=>q@vF!qUQ%{tXf0gEh zv#|CA%D#HR!03C1#_bG^P4axguJUZcj_s`-oBbWTFTnQd3I4oxklv0|9(Scu-O#SA zI}O_|cpIhUCZ5Kf1Z_E@yh{N_5sUyMYI=k(ZNLj!d)}idg`1s~csds|)fU3Ul@;u% zd@5p2z($kkmlErkT2T(Gj=|R^L2|u^q*^cg>OAZ@@8#jkDc~i)+ujm(7>erd;<&z? z7uMxWb%b;BY$M^Nu%-gmR$`a7okc{K!pd^+WkfMVl|Wz~lwI{87-if!%BCtWYmZGb ze0?_~t&xniY3Q~lp)GOnc^PPrLQDl-$=6j)F)S;c#`htt2)?Zq*xlo}d4;iU3cnoa zY_DRhUBjSd1-AAW_Ep?vu@ROZQCLjP6{V51FPD>+;A*>LzWpMxbJ6yb=xqE_n zI>48)&nXqb+_<~0&k2VWCbps=dsEe|^O^QcM7gT~c7Fvsw)F_xj0X!6$Lk>0+_p!F%5vvb9q1jxh6Xs%^^!TsQ+$%{R+*hDn4Jz< z;~Q>RQn=L+Pf}?obJGOD*$x7;UHE6Y2rp8QmgLD|UYe7lc01R42e|a>6LKtX*j+Qp z{@O{BYbV)zW`YHo3dZU-Zd>9xP};(r6b}J92mV=3{B=$iW;h8il)ciTYY3X@PSMLBf{_5w4-hO@@=;PeaHa^Q9=Ze*UzWh9MQ)T>BnS(_$LcdHmnqt{5 z1sIg48l#K6mJxBV$%YTT*@mvcMplE3+~#MjKW-=e#0|<#)yz%#P}PhqOBD*gEDzB~ zlzwSR0nPpfd_O85r#Sd8a}PL~pEgBiWf#F2qb$gj)vf+3%TiGSb0M~pMk&N7qJwh< z0eY7R&^eVry;B6}odnL{8wcqf_+|X9Hcve_-SjqnmHA`~Gh8C#uprS)l=>zv$@ioM z)dJui!vQE_{P(7zYOOznQr`a9(s+D%Q7JQ-CY53V}yu_l^{@Hv*|%d`Fg4<2S; TB(jaV00000NkvXXu0mjfI|^|M literal 0 HcmV?d00001 From 910580be64da7b3bc9a7464aa2715be5a01e8c74 Mon Sep 17 00:00:00 2001 From: Gianluca Ruocco Date: Fri, 19 Dec 2025 12:04:41 +0100 Subject: [PATCH 2/3] AllowInsecure variable added ServerUrl building reordered --- .../plugins/dynamix/agents/ZentikNotifier.xml | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/emhttp/plugins/dynamix/agents/ZentikNotifier.xml b/emhttp/plugins/dynamix/agents/ZentikNotifier.xml index d31323a548..34705bfc45 100644 --- a/emhttp/plugins/dynamix/agents/ZentikNotifier.xml +++ b/emhttp/plugins/dynamix/agents/ZentikNotifier.xml @@ -3,6 +3,7 @@ ZentikNotifier SERVER_URL + ALLOW_INSECURE BUCKET_ID ACCESS_TOKEN USER_IDS @@ -67,9 +68,6 @@ esac # Timestamp (seconds) TS="$TIMESTAMP" -# Build endpoint from base server URL -SERVER_URL=${SERVER_URL%/} -ENDPOINT="${SERVER_URL}/message" if [[ -z "$SERVER_URL" ]]; then echo "Missing SERVER_URL" >>"$LOG" exit 1 @@ -79,6 +77,10 @@ if [[ -z "$BUCKET_ID" || -z "$ACCESS_TOKEN" ]]; then exit 1 fi +# Build endpoint from base server URL +SERVER_URL=${SERVER_URL%/} +ENDPOINT="${SERVER_URL}/message" + # userIds: optional comma-separated list USER_IDS_JSON="null" if [[ -n "$USER_IDS" && "$USER_IDS" != "none" ]]; then @@ -105,7 +107,7 @@ fi # POST args=( - -s -k -X POST + -s -X POST -m 10 -w "\n%{http_code}" -H "Authorization: Bearer ${ACCESS_TOKEN}" @@ -113,7 +115,16 @@ args=( --data-binary "$PAYLOAD" "$ENDPOINT" ) -curl "${args[@]}" 2>&1 +[[ "${ALLOW_INSECURE}" == "yes" ]] && args+=( -k ) + +RESPONSE=$(curl "${args[@]}" 2>&1) +HTTP_CODE=$(echo "$RESPONSE" | tail -n1) + +# Check if HTTP status indicates success (2xx) +if [[ ! "$HTTP_CODE" =~ ^2[0-9]{2}$ ]]; then + echo "HTTP request failed with status $HTTP_CODE" >>"$LOG" + exit 1 +fi ]]> From 53c32a649d212c3ad50d244772de67b89000c187 Mon Sep 17 00:00:00 2001 From: Gianluca Ruocco Date: Fri, 19 Dec 2025 12:16:11 +0100 Subject: [PATCH 3/3] Some comments added Curl exit checked first --- .../plugins/dynamix/agents/ZentikNotifier.xml | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/emhttp/plugins/dynamix/agents/ZentikNotifier.xml b/emhttp/plugins/dynamix/agents/ZentikNotifier.xml index 34705bfc45..731e69b8e0 100644 --- a/emhttp/plugins/dynamix/agents/ZentikNotifier.xml +++ b/emhttp/plugins/dynamix/agents/ZentikNotifier.xml @@ -47,10 +47,12 @@ TITLE="${TITLE:-$SUBJECT}" SUBTITLE="${SUBTITLE:-$EVENT}" MESSAGE="${MESSAGE:-$DESCRIPTION}" -# Expand multi-select values into strings -TITLE=$(echo -e "$TITLE" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | sed 's/^ //; s/ $//') -SUBTITLE=$(echo -e "$SUBTITLE" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | sed 's/^ //; s/ $//') -MESSAGE=$(echo -e "$MESSAGE") +# Expand multi-select values into strings. +# Note: Dynamix multi-select stores separators as literal "\n" sequences. +# We intentionally interpret escape sequences here to support formatted input. +TITLE=$(printf '%b' "$TITLE" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | sed 's/^ //; s/ $//') +SUBTITLE=$(printf '%b' "$SUBTITLE" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | sed 's/^ //; s/ $//') +MESSAGE=$(printf '%b' "$MESSAGE") # Map Unraid importance -> Zentik deliveryType case "$IMPORTANCE" in @@ -65,9 +67,6 @@ case "$IMPORTANCE" in ;; esac -# Timestamp (seconds) -TS="$TIMESTAMP" - if [[ -z "$SERVER_URL" ]]; then echo "Missing SERVER_URL" >>"$LOG" exit 1 @@ -84,7 +83,8 @@ ENDPOINT="${SERVER_URL}/message" # userIds: optional comma-separated list USER_IDS_JSON="null" if [[ -n "$USER_IDS" && "$USER_IDS" != "none" ]]; then - # split by comma, trim whitespace, drop empties + # Parse comma-separated list into JSON array: + # 1. Split by comma, 2. Trim whitespace, 3. Drop empties, 4. Quote as JSON strings, 5. Collect into array USER_IDS_JSON=$(printf '%s\n' "$USER_IDS" | tr ',' '\n' | sed 's/^ *//; s/ *$//' | awk 'NF' | jq -R . | jq -s .) [[ "$USER_IDS_JSON" == "[]" ]] && USER_IDS_JSON="null" fi @@ -118,6 +118,13 @@ args=( [[ "${ALLOW_INSECURE}" == "yes" ]] && args+=( -k ) RESPONSE=$(curl "${args[@]}" 2>&1) +CURL_EXIT=$? + +if [[ $CURL_EXIT -ne 0 ]]; then + echo "curl failed with exit code $CURL_EXIT" >>"$LOG" + exit 1 +fi + HTTP_CODE=$(echo "$RESPONSE" | tail -n1) # Check if HTTP status indicates success (2xx)