summaryrefslogtreecommitdiff
path: root/localkannel-dispatch
blob: ecdd6ea0f0ec034f3280d45e2b6876455a18cca5 (plain)
  1. #!/bin/sh
  2. set -e
  3. exit1() {
  4. echo >&2 "Error: $1"
  5. echo >&2 "Exiting..."
  6. exit 1
  7. }
  8. simpleword() {
  9. # echo "$1" | tr '[A-Z]' '[a-z]' | egrep '^[a-z][a-z0-9-]+$' || exit 1
  10. echo "$1" | tr '[A-Z]' '[a-z]' | egrep '^[a-zæøåÆØÅ!@/][a-zæøåÆØÅ0-9-]+$' || exit 1
  11. }
  12. uriunescape() {
  13. if [ 0 = "$urldecode" ]; then
  14. echo "$@"
  15. else
  16. echo "$@" | perl -e 'use URI::Escape; print lc(uri_unescape(<STDIN>));'
  17. fi
  18. }
  19. #from=`uriunescape "$1" | sed -e 's/\+/ /g'`; shift
  20. from=`uriunescape "$1"`; shift
  21. #to=`uriunescape "$1" | sed -e 's/\+/ /g'`; shift
  22. to=`uriunescape "$1"`; shift
  23. #set -- `uriunescape "$@" | sed -e 's/\+/ /g'`
  24. set -- `uriunescape "$@"`
  25. app_raw="$1"
  26. app=`simpleword "$1"`; shift
  27. export debug
  28. SMS_PHONE="$from"
  29. urldecode=0
  30. export SMS_PHONE urldecode
  31. case "$SMS_REALM" in
  32. test)
  33. provider="dummy"
  34. mdpath="/home/hearth/public_webdata/hearth/content/sms"
  35. export mdpath
  36. ;;
  37. hello)
  38. provider="local"
  39. # provider="coolsms"
  40. # provider="clickatell"
  41. mdpath="/home/hearth/public_webdata/hearth/content/sms"
  42. export mdpath
  43. ;;
  44. cyber)
  45. provider="local"
  46. mdpath="/home/cyberhus/public_webdata/mdsms/content/sms"
  47. export mdpath
  48. ;;
  49. *)
  50. exit1 "unknown realm \"$SMS_REALM\"!"
  51. ;;
  52. esac
  53. case "$provider" in
  54. dummy)
  55. dummy=1
  56. ADMIN_OK=1
  57. export ADMIN_OK dummy
  58. ;;
  59. local)
  60. export SMS_SMSC
  61. ;;
  62. coolsms)
  63. unset SMS_SMSC
  64. SMS_URL="https://sms.coolsmsc.dk:8081/"
  65. SMS_USER="drjones1"
  66. SMS_PW="rahYSeGY"
  67. SMS_CP="cp1252"
  68. SMS_MSGTAG="message"
  69. export SMS_URL SMS_USER SMS_PW SMS_CP SMS_MSGTAG
  70. ;;
  71. clickatell)
  72. # unset SMS_SMSC
  73. # SMS_URL="https://api.clickatell.com/http/sendmsg"
  74. # SMS_USER="jonas"
  75. # SMS_PW="inaritab6"
  76. # SMS_CP="cp1252"
  77. # SMS_USERTAG="user"
  78. # SMS_API="3231280"
  79. # SMS_CONCAT="3"
  80. # export SMS_URL SMS_USER SMS_PW SMS_CP SMS_USERTAG SMS_API SMS_CONCAT
  81. SMS_SMSC="X"
  82. SMS_DLR_MASK="7"
  83. SMS_DLR_URL="http://helloearth.jones.dk/test.cgi?type=dlr&msgid=XXX&smsid=%I&from=%p&to=%P&time=%t&unixtime=%T&dlr=%d&dlrmsg=%A"
  84. export SMS_SMSC SMS_DLR_MASK SMS_DLR_URL
  85. ;;
  86. *)
  87. exit1 "unknown provider \"$provider\"!"
  88. ;;
  89. esac
  90. # by now sms connection should work, so let sender get errors too
  91. exit1() {
  92. echo >&2 "Error: $1"
  93. /usr/local/sbin/localsendsms "$to" "Error: $1"
  94. echo >&2 "Exiting..."
  95. exit 1
  96. }
  97. case "$app" in
  98. @*)
  99. [ -n "$REDIRECT_OK" ] || exit1 "Redirection not permitted here!"
  100. to="$(echo "$app" | perl -pe 's/^@//;' -e 's/^([^+])/+45\1/')"
  101. # TODO: silence errors - or better: bounce those back to original sender
  102. /usr/local/sbin/localmarkdown2sms "$to" "$@"
  103. ;;
  104. # !*)
  105. # [ -n "$GROUP_OK" ] || exit1 "Redirection to group not permitted here!"
  106. # group="$(echo "$app" | perl -pe 's/^!//;')"
  107. # for to in $(echo "$group" | perl ...); do
  108. # /usr/local/sbin/localmarkdown2sms "$to" "$@"
  109. # done
  110. # ;;
  111. /*)
  112. [ -n "$ADMIN_OK" ] || exit1 "Administrative commands not permitted here!"
  113. cmd="$(echo "$app" | perl -pe 's/^\///;')"
  114. response="$(/usr/local/sbin/localsmsadmin "$cmd" "$@")" || exit1 "$response"
  115. /usr/local/sbin/localsendsms "$to" "$response"
  116. ;;
  117. yb)
  118. s="$(links -dump "http://www.yubnub.org/parser/parse?command=$@")"
  119. /usr/local/sbin/localsendsms "$to" "$s"
  120. ;;
  121. *)
  122. /usr/local/sbin/localmarkdown2sms "$to" "$app_raw" "$@"
  123. ;;
  124. esac