ZiB před 4 měsíci
rodič
revize
f29f2599f6

+ 25 - 0
scripts/sieve/booking_sms.sh

@@ -0,0 +1,25 @@
+#!/bin/bash
+: ${SMS_API:=https://room-cal.sea.zi3.fi}
+: ${SMS_TOKEN:=foobar}
+if [[ -z "$SMS_API" ]]; then
+  echo "booking_sms: SMS_API not set" 1>&2
+  exit 0
+fi
+
+# Read the full email from stdin and extract the first 6-digit Extranet code.
+code=$(grep -oP 'Extranet code: \K[0-9]{6}' | head -1)
+if [[ -z "$code" ]]; then
+  echo "booking_sms: no Extranet code found in message" >&2
+  exit 0  # exit 0 so Sieve doesn't treat it as a filter failure
+fi
+
+# Upload
+echo curl -fsS \
+  -X POST \
+  -H "Content-Type: application/json" \
+  -H "X-SMS-Secret: ${SMS_TOKEN}" \
+  -d "{\"code\": \"${code}\"}" \
+  "${SMS_API%/}/sms/code"
+
+# Always clean for Sieve
+exit 0

+ 6 - 0
scripts/sieve/booking_sms.sieve

@@ -0,0 +1,6 @@
+require ["vnd.dovecot.pipe", "copy", "body"];
+
+# rule:[Booking SMS]
+if body :text :contains "Extranet code:" {
+  pipe :copy "booking_sms.sh";
+}

+ 0 - 20
scripts/sieve/sms_code.sieve

@@ -1,20 +0,0 @@
-require ["vnd.dovecot.pipe", "copy", "body"];
-
-# Forward Extranet challenge codes to the room-cal SMS endpoint.
-# The pipe target script (sms_code_filter.sh) does the extraction and POST.
-#
-# Dovecot config required in /etc/dovecot/conf.d/90-sieve.conf:
-#   plugin {
-#     sieve_plugins = sieve_extprograms
-#     sieve_pipe_socket_dir = /var/run/dovecot/sieve-pipe
-#     # or use sieve_pipe_bin_dir for direct binary execution:
-#     sieve_pipe_bin_dir = /etc/dovecot/sieve-pipe
-#   }
-#
-# Place (or symlink) sms_code_filter.sh in sieve_pipe_bin_dir and make it
-# executable.  Set SMS_API_URL and SMS_GATEWAY_SECRET in the script or via
-# the environment Dovecot inherits.
-
-if body :text :contains "Extranet code:" {
-  pipe :copy "sms_code_filter.sh";
-}

+ 0 - 33
scripts/sieve/sms_code_filter.sh

@@ -1,33 +0,0 @@
-#!/bin/bash
-# Dovecot Sieve pipe target: reads an email from stdin, extracts the Extranet
-# code, and POSTs it to the room-cal SMS endpoint.
-#
-# Required env vars (set in /etc/dovecot/sieve-pipe-env or similar):
-#   SMS_API_URL     — base URL of the room-cal API, e.g. https://cal.example.com
-#   SMS_GATEWAY_SECRET — value of SMS_GATEWAY_SECRET configured in the API
-
-set -euo pipefail
-
-API_URL="${SMS_API_URL:-}"
-SECRET="${SMS_GATEWAY_SECRET:-}"
-
-if [[ -z "$API_URL" ]]; then
-  echo "sms_code_filter: SMS_API_URL not set" >&2
-  exit 1
-fi
-
-# Read the full email from stdin and extract the first 6-digit Extranet code.
-email=$(cat)
-code=$(printf '%s' "$email" | grep -oP 'Extranet code: \K[0-9]{6}' | head -1)
-
-if [[ -z "$code" ]]; then
-  echo "sms_code_filter: no Extranet code found in message" >&2
-  exit 0  # exit 0 so Sieve doesn't treat it as a filter failure
-fi
-
-curl -fsS \
-  -X POST \
-  -H "Content-Type: application/json" \
-  -H "X-SMS-Secret: ${SECRET}" \
-  -d "{\"code\": \"${code}\"}" \
-  "${API_URL%/}/sms/code"