diff options
author | Jonas <dr@jones.dk> | 2010-05-31 09:24:55 +0200 |
---|---|---|
committer | Jonas <dr@jones.dk> | 2010-05-31 09:24:55 +0200 |
commit | 3d80bf3353d786c759c3f454e3d13dfbd7ddd647 (patch) | |
tree | d8c903851f4980d967a93687a4cd9ed49d44674b /localkannel-dispatch | |
parent | 175cc7c95b2c7f36ac461b633673de18d531f205 (diff) |
Major updates to localkannel-dispatch and localsmsadmin.
Diffstat (limited to 'localkannel-dispatch')
-rwxr-xr-x | localkannel-dispatch | 91 |
1 files changed, 58 insertions, 33 deletions
diff --git a/localkannel-dispatch b/localkannel-dispatch index ecdd6ea..e1685d8 100755 --- a/localkannel-dispatch +++ b/localkannel-dispatch @@ -2,9 +2,20 @@ set -e -exit1() { - echo >&2 "Error: $1" - echo >&2 "Exiting..." +vardir=/var/lib/kannel/hello +sbindir=/usr/local/sbin + +exit0() { + [ -n "$1" ] && echo "$1" + exit 0 +} +exit1() { + [ -z "$1" ] || echo "Error: $1" || echo "Internal error!" + response="${1+Error: $1}${-Internal error!}" +# FIXME: pass error messages via stderr (not stdout) +# echo >&2 "$response" + echo "$response" + [ -z "$SMS_SMSC$SMS_URL" ] || $sbindir/localsendsms "$to" "$response" exit 1 } @@ -25,8 +36,8 @@ uriunescape() { from=`uriunescape "$1"`; shift #to=`uriunescape "$1" | sed -e 's/\+/ /g'`; shift to=`uriunescape "$1"`; shift -#set -- `uriunescape "$@" | sed -e 's/\+/ /g'` -set -- `uriunescape "$@"` +set -- `uriunescape "$@" | sed -e 's/\+/ /g'` +#set -- `uriunescape "$@"` app_raw="$1" app=`simpleword "$1"`; shift @@ -96,39 +107,53 @@ case "$provider" in ;; esac -# by now sms connection should work, so let sender get errors too -exit1() { - echo >&2 "Error: $1" - /usr/local/sbin/localsendsms "$to" "Error: $1" - echo >&2 "Exiting..." - exit 1 -} - +if [ -n "$REDIRECT_OK" ]; then case "$app" in @*) - [ -n "$REDIRECT_OK" ] || exit1 "Redirection not permitted here!" to="$(echo "$app" | perl -pe 's/^@//;' -e 's/^([^+])/+45\1/')" # TODO: silence errors - or better: bounce those back to original sender - /usr/local/sbin/localmarkdown2sms "$to" "$@" + $sbindir/localmarkdown2sms "$to" "$@" + exit 0 ;; -# !*) -# [ -n "$GROUP_OK" ] || exit1 "Redirection to group not permitted here!" -# group="$(echo "$app" | perl -pe 's/^!//;')" -# for to in $(echo "$group" | perl ...); do -# /usr/local/sbin/localmarkdown2sms "$to" "$@" -# done -# ;; - /*) - [ -n "$ADMIN_OK" ] || exit1 "Administrative commands not permitted here!" - cmd="$(echo "$app" | perl -pe 's/^\///;')" - response="$(/usr/local/sbin/localsmsadmin "$cmd" "$@")" || exit1 "$response" - /usr/local/sbin/localsendsms "$to" "$response" - ;; - yb) - s="$(links -dump "http://www.yubnub.org/parser/parse?command=$@")" - /usr/local/sbin/localsendsms "$to" "$s" +esac +fi + +if [ -n "$GROUP_OK" ]; then +case "$app" in + !*) + group="$(echo "$app" | perl -pe 's/^!//;')" + members=$(cd "$vardir/user" && grep -lF "$group" */group | perl -pe "s,/group$,,") || members= + [ -n "$members" ] || exit1 "Message redirected for none: no members resolved in group \"$group\"!" + for member in $members; do + phone=$(head -n 1 "$vardir/user/$member/phone") || nophone="${nophone+$nophone }$member" + [ -z "$phone" ] || $sbindir/localmarkdown2sms "$phone" "$@" + done + [ -n "$members" ] || exit1 "Message redirected for none: no members resolved in group \"$group\"!" + membercount=$(echo "$members" | wc --word) + [ -z "$nophone" ] || nophonecount=$(echo "$nophone" | wc --word) + [ -z "$nophone" ] || exit1 "Message redirected for $membercount members of group \"$group\", but failed for $nophonecount of them (could not resolve phone number)!" + exit0 "Message redirected for $membercount members of group \"$group\"." ;; - *) - /usr/local/sbin/localmarkdown2sms "$to" "$app_raw" "$@" +esac +fi + +case "$app" in + /*) + candidates=$(cd "$vardir/user" && grep -lF "$to" */phone | perl -pe "s,/phone$,,") || candidates= + [ -z "$candidates" ] || $(grep -vqF "$candidates" "$vardir/group/admin/user") || admin=true + if [ -n "$ADMIN_OK" ] && [ -n "$admin" ]; then + cmd="$(echo "$app" | perl -pe 's/^\///;')" + str="$($sbindir/localsmsadmin "$cmd" "$@" 2>&1)" || exit1 "$str" + $sbindir/localsendsms "$to" $str + exit 0 + fi ;; esac + +# yb) +# s="$(links -dump "http://www.yubnub.org/parser/parse?command=$@")" +# $sbindir/localsendsms "$to" "$s" +# exit 0 +# ;; + +$sbindir/localmarkdown2sms "$to" "$app_raw" "$@" |