Keywords: Mode: All keywords (AND) |
Fri Apr 30, 2010 21:00
|
buster: i'm using debian lenny for that,
and smsd 3.1.6.
usually i had bash instead of sh there ;)
nevertheless, it works...
|
Fri Apr 30, 2010 14:48
|
buster: this line
TEXT=`echo $TEXT | sed 's/ADMIN //'
should be
TEXT=`echo $TEXT | sed 's/^ADMIN //'
(isnt there a edit button?)
|
Fri Apr 30, 2010 13:05
|
buster: first of all:
thanks to keke for the hints!!
now with ~60 lines less
#!/bin/sh
if [ "$1" = "RECEIVED" ]; then
TEXT=`formail -I "" <$2`
#make uppercase
TEXT=`echo $TEXT | tr "a-z" "A-Z" `
FILE=`mktemp /tmp/send_XXXXXX`
KEYWORD=`echo $TEXT | cut -d" " -f1`
case $KEYWORD in
ADMIN)
for x in `cat /etc/smsgate/groups/admin`
do
FORWARD_TO=$x
TEXT=`echo $TEXT | sed 's/^ADMIN //'`
echo "To: $FORWARD_TO" >> $FILE
echo "" >> $FILE
echo "$TEXT" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2
done
;;
MAIL:*)
RCPT=`$KEYWORD | cut -d: -f2`
MAILADDR=`grep $RCPT: /etc/smsgate/mail | cut -d: -f2`
TEXT=`echo $TEXT | sed 's/^.* //'`
/usr/bin/sendEmail -f sms@domain.com -u SMS2MAIL -t "$MAILADDR" -m $TEXT
rm $2
;;
esac
fi
|
Thu Apr 29, 2010 16:37
|
buster: Comments still welcome? ;)
yes, still welcome :)
indeed in the moment its running by cronjob,
but as soon as i read more about eventhandles i wanted to change that...
thanks for all the hints so far,
i will try to get it into the script as good as i can ;)
but I think that it will fail if a SMS message is "Report: OK, Houston, we've had a problem here.".
hm... why do you think so?
|
Wed Apr 28, 2010 13:43
|
buster: here we go...
#!/bin/bash
# V0.1
/usr/bin/logger -p local7.notice "SMSGATE START `/bin/date`"
## create neccessary files and folders
## modify syslog (fac7) for smsgate
## sendEmail must be installed
## watch out for typos, there may be some :(
## mail is a matchfile, syntax: shortname email@address.xxx
## groups is a folder, in which reside the groupfiles (admin,info whatever...) with only mobilenumbers in it
##
## hope i didnt forget too much....
##
## i will have to have a look in the existing scripts for enhancement if i got the time...
##
##VARS
ROOTDIR=/var/spool/sms
INCOMING=/var/spool/sms/incoming
SENT=/var/spool/sms/sent
OUTGOING=/var/spool/sms/outgoing
CONF=/etc/smsgate
GROUPS=/etc/smsgate/groups
MAIL=/etc/smsgate/mail
for i in `ls /var/spool/sms/incoming/`
do
##Nachrichten einlesen#read message
FROM=(`grep "From:" $INCOMING/$i | cut -d" " -f2`)
##Erste Zeile einlesen
FIRSTLINE=("`grep "Length:" -A2 $INCOMING/$i | tail -n1`")
##Erstes Wort (Keyword) einlesen# read (first) keyword
FIRSTWORD=("`grep "Length:" -A2 $INCOMING/$i | tail -n1| cut -d" " -f1`")
##Wenn gültiger Sender#if sender valid
if [ "$FROM" == "49171xxxxxxxxx" ]; then
case "$FIRSTWORD" in
##BEI BULKSMS#key BULK
BULK)
##GRUPPE AUS SMS LESEN#read group
GROUP=("`grep "Length:" -A2 $INCOMING/$i | tail -n1| cut -d" " -f2`")
##PRÜFEN OB GRUPPE VORHANDEN IST#check if group is availible
if test -f /etc/smsgate/groups/$GROUP; then
##AN JEDES MITGLIED EINE SMS VERSENDEN#send a sms per member
for x in `cat /etc/smsgate/groups/$GROUP`
do
###SMS VERSENDEN##sendsms-as usual...
### sendsms .....NOCH TESTEN!!!!#to be tested - not yet implemented ;)
/usr/bin/logger -p local7.notice "BULKSMS SENT from $FROM to $x"
done
rm $INCOMING/$i
else
##WENN DIE GRUPPE NICHT VORHANDEN IST...#if group is not availible
/usr/bin/logger -p local7.error "BULKSMS NOT SENT FROM $FROM to $GROUP - $GROUP not availible - MOVED TO $ROOTDIR/failed/"
mv $INCOMING/$i $ROOTDIR/failed/
fi
/usr/bin/logger -p local7.error "BULKSMS NOT SENT FROM $FROM to $GROUP - $GROUP not availible - MOVED TO $ROOTDIR/failed/"
mv $INCOMING/$i $ROOTDIR/failed/
;;
MAIL)
##EMPFÄNGER AUSLESEN#read recipient
RCPT=("`grep "Length:" -A2 $INCOMING/$i | tail -n1| cut -d" " -f2`")
##EMPFÄNGER MAILADRESSE SUCHEN#search mailrecipient in matchfile
RCPTADDR=(`grep $RCPT $MAIL | sed 's/^.*\ //'`)
if [ "$?" = "0" ]; then
##WENN EMAIL VORHANDEN, SMS ALS MAIL ZUSTELLEN
if [ "$RCPTADDR" = '' ]; then
mv $INCOMING/$i $ROOTDIR/failed/
continue
fi
SUBJECT="SMS2MAIL"
MESSAGE=("`cat $INCOMING/$i`")
###SMS TEXT NOCH RICHTIG AUSLESEN!!!!##remove headers from received sms - todo: make nicer... its pretty ugly....
cat "$INCOMING/$i" | grep -v "^From_TOA:" | grep -v "^FROM_SMSC:" | grep -v "^Subject:" | grep -v "^Modem:" | grep -v "^IMSI:" | grep -v "^Report:" | grep -v "^Alphabet:" | grep -v "^Length:" | /usr/bin/sendEmail -f sms@sms.motiondrive.ag -u "$SUBJECT" -t "$RCPTADDR" -m
/usr/bin/logger -p local7.notice "MAIL SENT FROM $FROM TO $RCPT alias $RCPTADDR"
rm $INCOMING/$i
else
##EMAIL NICHT VORHANDEN...##rcpt not in matchfile
mv $INCOMING/$i $ROOTDIR/failed/
/usr/bin/logger -p local7.error NO MAILADDRESS IN FILE - MOVED TO $ROOTDIR/failed/$i
fi
;;
*)
mv $INCOMING/$i $ROOTDIR/failed/
/usr/bin/logger -p local7.error ERROR IN FILE - MOVED TO $ROOTDIR/failed/$i
;;
esac
##Wenn ungültiger Sender#invalid sendernumber
else
mv $INCOMING/$i $ROOTDIR/failed/
/usr/bin/logger -p local7.error NO VALID SENDER NUMBER FOR FILE - MOVED TO $ROOTDIR/failed/$i
continue
fi
done
/usr/bin/logger -p local7.notice "SMSGATE FINISH `/bin/date`"
|
Tue Apr 27, 2010 09:45
|
buster: damn...
sorry, i posted a preversion
and didnt doublecheck it :(
but generally the way should be clear...
the tcpserver testing was done in ubuntu lucid.
i'll try it this week on a debian, which will be the productive system.
be aware, i used the german word for number NUMMER for the ECHO , just if it confused someone...
hm, no i didnt recognize sendsms would work with tcpserver,
but i think any kind of passwordprotection should be used...
i got another script in progress,
which will do:
sms forwarding to (defined) groups via sms
sms forwarding to emailaddresses via shortname-email-matchfile
valid/invalid sender number (black/whitelist)
logging
but... perhaps you will tell me, everything of that is already onboard? ;)
sry, but i'm not yet so deep into sms server tools...
|
Tue Apr 27, 2010 06:49
|
buster: Hello there,
i'd like to introduce myself with a way to send SMS over TCP/IP.
Comments and enhancements welcome!!
Ok, i start with the bash-script:
#!/bin/bash
echo PASSWORT:
read PASS
PASS=(`echo $PASS | tr -d [:cntrl:]`)
if [ "$PASS" = "12345" ]; then
TMPF=(`tempfile`)
echo To: >> $TMPF
echo NUMMER:
#add error treatment
read nummer
#add error treatment
echo TEXT:
read -d^ TEXT
#quit on ^
echo $NUMMER >> $TMPF
echo $TEXT >> $TMPF
mv $TMPF /var/spool/sms/outgoing/
else
exit
fi
I think the code is very selfexplaining,
if not, let me know...
here is how i make the script talking over the network:
tcpserver <IP.ADD.DRE.SS> <PORT#> /path/to/script.sh
cheers
Ronny
|