summaryrefslogtreecommitdiff
path: root/localkannel-dispatch
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-09-25 15:53:09 +0200
committerJonas Smedegaard <dr@jones.dk>2010-09-25 15:53:09 +0200
commitba619c551f4c067a7cd86362d80436c5aebeb8b0 (patch)
treecc60abc58afc187e118e6d029e866724acc8ecdf /localkannel-dispatch
parente146188cb173dea872168cb9349a3e6e2175788d (diff)
Implement action /add .
Diffstat (limited to 'localkannel-dispatch')
-rwxr-xr-xlocalkannel-dispatch29
1 files changed, 28 insertions, 1 deletions
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")