Hi all,

I try to make a system where client can send their sms (contained contact file in it that compressed) to server using sms gateway concept. In this case, server must handle 3 condition : registration, request sending file to server (by client), and request take file in server (by client, and server will be send it to client).

In this case, I separate this plan by two side : client side and server side.

In client side, I'm develop an application (jar) using J2ME that can read/write phonebook (in symbian S60), compression contact (client can select how many contact that they want to compress), and send it to server via sms. My application run well in my Nokia N81 8GB when I test it.

In server side, case of this topic, I'm use sms gateway concept to send and receive sms from and to client (also using database mysql). Database will saving 4 things (in 4 field) : ID client (generate by server in client registration phase), name+phone number of client (that contained in sms of registration), and file backup phone book (that send by client in sending file phase, in form of sms). My question focus in server side.

I want to make an script for the eventhandler (will be add on /etc/smsd.conf) that contain with that three condition above. I'll explain each phase below :
1. ) In registration phase.
Check incoming sms from client that register to server via SMS.
If incoming sms contain "reg" (not case sensitive), server will generate an ID for client (ie : Cxxx) and send a sms : "$name, thanks for registration. Your ID is $id_client_that_generated_by_server_after_client_registration"
If sms didn't contain "reg", server will send client a sms that contain message "Sorry, your format is wrong. Type : REG#your_name".

2.) Request sending file to server (by client) phase.
Check incoming sms from client that contain "KRM#id_client" (KRM not case sensitive).
If incoming sms didn't contain "krm" and or wrong/not valid ID, server will send client a sms "The format of your sms and or your ID is wrong. Type KRM#ID"
If it's true, server will send a sms to client :"$name, now you may send files to server".
And after client send their file to server via sms and server received it, server will send sms report to client : "$name, your file was saved in the server".

3. Check incoming sms form client that contain "GET#id_client" (GET not case sensitive).
If incoming sms didn't contain "get" and or wrong/not valid ID, server will send client a sms "your format of sms or your ID is wrong. Type GEt#ID"
If it's true, server will send a sms to client :"$name, wait a minutes. We will send your file via SMS".

I've try to write the script (based on example of sms server tools and also my friend) to solve my problem in server side above (but "reg" only, I can't for "krm" and "get" ), in attachmnt.

I've try it at SMS Server Tools (as shell script in eventhandler /etc/smsd.conf), but it only run well when I'm send a sms that contain wrong format (ex : ref#jhon) and server will send me a sms that contain message "your format is worng. Type : reg#name".

But if my format valid, it can't generate ID for client (in this case is sender, myself), store data (name, ID, telp number) in database, and also can't send client sms that contain format "$nama, your registration is complete. your Id is xxx".

help me to solve my problem and complete my script. Thanks,

Sorry, I'm forget to show my script.
here my script. It only can generate ID for client that send sms (using format : REG#name), and server will automatically send client sms that contain message : "$name, you are registered with ID $ID"

It can't do like point 2 and 3 (GET and KRM) :(

PS :
$ID is ID that generated by server for client.
name is name of client.

#!/bin/sh
#script : BUPB_handler
#location : /usr/local/bin
#Script for input data client from SMS
#It will be run if a SMS received as the format
#Data of client will be insert (store) into DB 'bupbdb' if contain tag 'reg'

#if empty
if [ "$1" != "RECEIVED" ]; then
exit;
fi;

#parameter of my DB
SQL_HOST=localhost
SQL_USER=admin
SQL_PASSWORD=
SQL_DATABASE=bupbdb
SQL_TABLE=cltsms

#Ekstract data from  SMS that received
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`

#Setting parameter of SQL
if [ "$SQL_PASSWORD" != "" ]; then SQL_ARGS="-p $SQL_PASSWORD";
else
SQL_ARGS="";
fi

SQL_ARGS="-h $SQL_HOST -u $SQL_USER $SQL_ARGS -D $SQL_DATABASE -s -e"

#Check message if contain  tag  'reg'
TEXTS=`echo $TEXT|sed -e's/[\t]//g'`

if echo $TEXTS|grep -qi "reg"
then
KODE=`mktemp CXXXX`
NAMA=`echo $TEXTS|cut -f2 -d#`
ISITEKS=``

#Insert into table cltsms
A=`mysql $SQL_ARGS "insert into $SQL_TABLE (ID,notel,nama,file) values(\"$KODE\",\"$FROM\",\"$NAMA\",\"$ISITEKS\");"`

# NOTICE this: "$FROM\")",\"$NAME

#echo "A=mysql $SQL_ARGS insert into $SQL_TABLE (ID,notel,nama,file)
#values(\"$KODE\",\"$FROM\",\"$NAME\");"

#Create SMS confirmation to client if format is valid
#Include ID (generated by server) and client name
FILENAME=`mktemp /var/spool/sms/outgoing/REGBXXXXXX`
#FILENAME= `mktemp /tmp/REGBXXXXXX`
echo "To: $FROM" >$FILENAME
echo "" >> $FILENAME
echo "$NAMA, you are registered  with ID  $KODE" >>$FILENAME
else
#Create SMS confirmation to client if format is wrong
FILENAME=`mktemp /var/spool/sms/outgoing/REGSXXXXXX`
#FILENAME=`mktemp /tmp/REGSXXXXXX`
echo "To: $FROM" >$FILENAME
echo "" >> $FILENAME
echo "Your SMS format is wrong. Type REG#nama" >>$FILENAME

fi

Please help me to complete my script above so that point 2 and 3 can run well.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.