From ba619c551f4c067a7cd86362d80436c5aebeb8b0 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 25 Sep 2010 15:53:09 +0200 Subject: Implement action /add . --- localkannel-dispatch | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'localkannel-dispatch') diff --git a/localkannel-dispatch b/localkannel-dispatch index 91e5577..6d5dd9a 100755 --- a/localkannel-dispatch +++ b/localkannel-dispatch @@ -209,6 +209,33 @@ Respond \"pong\" and echo back any addition input." $sbindir/localsendsms "$to" pong "$@" exit 0 ;; + add) + if [ "help" = "$1" ]; then + $sbindir/localsendsms "$to" "Usage: +/add ID PHONE [MSG]...] + +Register PHONE as ID, +and (if included) send MSG to subscribers." + exit 0 + fi + + id="$(echo "$1" | perl -ne '/^(\d\d)$/ and print $1;')" + [ -n "$id" ] || exit1 "wrong or missing id: must be 2 digits." + shift + +# FIXME: avoid juggling with leading plus here when no longer stripped from input +# phone="$(echo "$1" | perl -ne 's/^(?=[^+])/+36/;' -e '/^(\+\d\d\d+)$/ and print $1;')" + phone="$(echo "$1" | perl -ne '/^(\d\d\d+)$/ and print $1;')" + [ -n "$phone" ] || exit1 "wrong or missing phone number: must be only digits with leading + and at least 3 digits." + targetfrom=$(lastservicephone "\+$phone") + [ -n "$targetfrom" ] || exit1 "unknown phone +$phone: it must have been used with the system recently." + phone="+$phone" + shift + + str=$($sbindir/localsmsadmin add user "$id" "$phone") + $sbindir/localsendsms "$to" "[info] \"$cmd\": $str." + exit 0 + ;; # FIXME: generalize this ugly hacks somehow, and secure against random use go|gotest|so|sotest) case "$cmd" in @@ -246,7 +273,7 @@ and (if included) send MSG to subscribers." while [ -n "$1" ]; do # targetphone="$(echo "$1" | perl -ne 's/^(?=[^+])/+36/;' -e '/^(\+\d\d\d+)$/ and print $1;')" targetphone="$(echo "$1" | perl -ne '/^(\d\d\d+)$/ and print $1;')" - [ -n "$targetphone" ] || continue + [ -n "$targetphone" ] || continue # Sanity check targetfrom=$(lastservicephone "\+$targetphone") -- cgit v1.2.3