Download Install Kannel Send and Receive SMS via Kannel...
Install and configure Kannel for sent and receive sms message on Xenserver. Page 1 of 13
Department: JMango Vietnam Product or Process: Install and configure Kannel for sent and receive sms message on Xenserver Document Owner: Linh Nguyen (
[email protected])
Version
Date
1.0
09/23/2011
Page 2 of 13
Author
[email protected]
Change Description Create the document
Contents Install Kannel ....................................................................................................................................................... 4 Enviroment : ..................................................................................................................................................... 4 Get ting the source code .................................................................................................................................. 4 Install the Kannel.............................................................................................................................................. 4 Configuring the gateway ...................................................................................................................................... 5 Kannel.conf ...................................................................................................................................................... 5 Core configuration ........................................................................................................................................ 6 Fake SMSC .................................................................................................................................................. 7 Modem .......................................................................................................................................................... 7 SMSBox configuration .................................................................................................................................. 8 SendSMS-user configurations...................................................................................................................... 8 SMS-service configurations .......................................................................................................................... 8 Startup script: ................................................................................................................................................... 9 Using gateway ................................................................................................................................................... 12 Check status: ................................................................................................................................................. 12 Sent SMS ....................................................................................................................................................... 13 Receive SMS: ................................................................................................................................................ 13
Page 3 of 13
Install Kannel Enviroment : Ensure that you installed : gcc ; libxml2
Get ting the source code Download at:
http://www.kannel.org/download.shtml.
Extract it: tar –xvf gateway-x.x.x.tar.gz
Install the Kannel $ ./configure $ Make $ Make install
./configure
Note: Default path: /usr/local/bin/. You can set special path with option: prefix= path/to/kannel ./configure with few options. Kannel defines a few additional options: See kannel userguide for more imformation http://www.kannel.org/download/kannel-userguide snapshot/userguide.html#AEN3792 In here, we run command: $ ./configure
enable –start stop daemon
Make
After you have compiled Kannel, you need to install certain programs in a suitable place. This is most easily done by using make again: $ make bindir=/path/to/directory install Replace /path/to/directory with the pathname of the actual directory where the programs should be installed. The programs that are installed are (as filenames from the root of the source directory): Gw/bearerbox Gw/smsbox Gw/wapbox
Make install
Page 4 of 13
Configuring the gateway Kannel.conf $ emacs
/etc/kannel/kannel.conf
File kannel.conf # CORE group = core admin-port = 13000 admin-password = bar #status-password log-file = "/tmp/kannel_log/kannel.log" log-level = 0 access-log = "/tmp/kannel_log/access.log" #wapbox-port = 13002 smsbox-port = 13001 store-file = "/tmp/kannel_log/kannel.store" admin-allow-ip = localhost;127.0.0.1,192.168.1.100, 192.168.1.4 # SMSC Fake group = smsc smsc = at smsc-id = mobiphone modemtype = auto device = /dev/ttyUSB0 speed = 115200 pin = 0000 host = localhost port = 13013 connect-allow-ip = 192.168.1.100,localhost;127.0.0.1 # MODEM DEFINITIONS group = modems id = WAVECOM name = "WAVECOM" detect-string = "WAVECOM" # SMSBOX SETUP group = smsbox bearerbox-host = localhost sendsms-port = 13014 sendsms-chars = "0123456789+" global-sender = "+84900000011" log-file = "/tmp/kannel_log/smsbox.log" log-level = 0
Page 5 of 13
access-log = "/tmp/kannel_log/access.log" # SEND-SMS USERS group = sendsms-user default-smsc = mobiphone username = foo password = bar concatenation = 1 max-messages = 10 # SMS SERVICE 'default' group = sms-service keyword = nop text = "You asked nothing and I did it!" get-url = http://smart.jmango.vn/receivesms.php?sender=%p&text=%s catch-all = true # Catch all incoming messages regarding the keyword. #If you define other services, remove this line. # # # # #
SMS SERVICE for receiving sms messages If you're about to implement service to receive sms messages. group = sms-service keyword = yourkeyword get-url =
http://server.domain/moodle/receivesms.php?q=%k&sender=%p&messa ge=%a group = sms-service keyword = default catch-all = yes get-url = http://smart.jmango.vn/receivesms.php?sender=%p&text=%s text = "No service specified"thing and I did it!" catch-all = true
Note:See kannel guide for more option
Core configuration Configuration for Kannel MUST always include a group for general bearerbox configuration. This group is named as 'core' in configuration file, and should be the first group in the configuration file.
Page 6 of 13
# CORE group = core admin-port = 13000 admin-password = bar #status-password log-file = "/tmp/kannel_log/kannel.log" log-level = 0 access-log = "/tmp/kannel_log/access.log" #wapbox-port = 13002 smsbox-port = 13001 store-file = "/tmp/kannel_log/kannel.store" admin-allow-ip = localhost;127.0.0.1,192.168.1.100, 192.168.1.4
Fake SMSC Fake SMSC is a simple protocol to test out Kannel. It is not a real SMS center, and cannot be used to send or receive SMS messages from real phones. So, it is ONLY used for testing purposes. # SMSC Fake group = smsc smsc = at smsc-id = mobiphone modemtype = auto device = /dev/ttyUSB0 speed = 115200 pin = 0000 host = localhost port = 13013 connect-allow-ip = 192.168.1.100,localhost;127.0.0.1
Modem This driver allows a GSM Modem or Phone to be connected to Kannel and work as a virtual SMSC # MODEM DEFINITIONS group = modems id = WAVECOM name = "WAVECOM" detect-string = "WAVECOM"
Page 7 of 13
SMSBox configuration You must define an 'smsbox' group into the configuration file to be able to use SMS Kannel. The simplest working 'smsbox' group looks like this # SMSBOX SETUP group = smsbox bearerbox-host = localhost sendsms-port = 13014 sendsms-chars = "0123456789+" global-sender = "+84900000011" log-file = "/tmp/kannel_log/smsbox.log" log-level = 0 access-log = "/tmp/kannel_log/access.log" SendSMS-user configurations To enable an SMS push, you must set sendsms-port into the 'smsbox' group and define one or more 'sendsms-user' groups. Each of these groups define one account, which can be used for the SMS push, via HTTP interface (see below # SEND-SMS USERS group = sendsms-user default-smsc = mobiphone
SMS-service configurations Now that you have an SMS center connection to send and receive SMS messages you need to define services for incoming messages. This is done via 'sms-service' configuration groups. # SMS SERVICE 'default' group = sms-service keyword = nop text = "You asked nothing and I did it!" get-url = http://smart.jmango.vn/receivesms.php?sender=%p&text=%s catch-all = true group = sms-service keyword = default catch-all = yes get-url = http://smart.jmango.vn/receivesms.php?sender=%p&text=%s
Page 8 of 13
text = "No service specified"thing and I did it!" catch-all = true
Startup script: cd /opt/gatewayx.x.x./utils emacs kannel-init.d mv kannel-init.d kannel cp /opt/gateway-x.x.x./utils/kannel /etc/kannel/kannel
Here is startup script: #!/bin/sh # Start/stop the Kannel boxes: One bearer box and one WAP box. # This is the default init.d script for Kannel. Its configuration is appropriate for a small site running Kannel on one machine. # Make sure that the Kannel binaries can be found in $BOXPATH or somewhere # else along $PATH. run_kannel_box has to be in $BOXPATH. ### BEGIN INIT INFO # Provides: kannel # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $local_fs $network # Should-Stop: $local_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: SMS and WAP gateway # Description: Kannel is a gateway for connecting WAP phones to the # Internet. It also works as an SMS gateway. ### END INIT INFO BOXPATH=/usr/local/sbin PIDFILES=/var/run/kannel CONF=/etc/kannel/kannel.conf
Page 9 of 13
PATH=$BOXPATH:$PATH # On Debian, the most likely reason for the bearerbox not being available # is that the package is in the "removed" or "unconfigured" state, and the # init.d script is still around because it's a conffile. This is normal, # so don't generate any output. test -x $BOXPATH/bearerbox || exit 0 test -r /etc/default/kannel && . /etc/default/kannel case "$1" in start) echo -n "Starting WAP gateway:" echo -n " bearerbox" start-stop-daemon --start --quiet \ --pidfile $PIDFILES/kannel_bearerbox.pid \ --chuid root \ --exec $BOXPATH/run_kannel_box \ -- \ --pidfile $PIDFILES/kannel_bearerbox.pid \ --no-extra-args \ $BOXPATH/bearerbox -v 4 -- $CONF sleep 1 # Wait for bearerbox test ! -z $START_WAPBOX && ( echo -n " wapbox" start-stop-daemon --start --quiet \ --pidfile $PIDFILES/kannel_wapbox.pid \ --chuid root \ --exec $BOXPATH/run_kannel_box \ -- \ --pidfile $PIDFILES/kannel_wapbox.pid \ --no-extra-args \ $BOXPATH/wapbox -v 4 -- $CONF ) test ! -z $START_SMSBOX && ( echo -n " smsbox" start-stop-daemon --start --quiet \ --pidfile $PIDFILES/kannel_smsbox.pid \ --chuid root \ --exec $BOXPATH/run_kannel_box \ -- \
Page 10 of 13
--pidfile $PIDFILES/kannel_smsbox.pid \ --no-extra-args \ $BOXPATH/smsbox -v 4 -- $CONF ) echo "." ;; stop) echo -n "Stopping WAP gateway:" test ! -z $START_SMSBOX && ( echo -n " smsbox" start-stop-daemon --stop --quiet \ --pidfile $PIDFILES/kannel_smsbox.pid \ --exec $BOXPATH/run_kannel_box ) test ! -z $START_WAPBOX && ( echo -n " wapbox" start-stop-daemon --stop --quiet \ --pidfile $PIDFILES/kannel_wapbox.pid \ --exec $BOXPATH/run_kannel_box ) echo -n " bearerbox" start-stop-daemon --stop --quiet \ --pidfile $PIDFILES/kannel_bearerbox.pid \ --exec $BOXPATH/run_kannel_box echo "." ;; reload) # We don't have support for this yet. exit 1 ;; restart|force-reload) $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 {start|stop|restart|force-reload}" exit 1 esac
Page 11 of 13
exit 0 Note: in startup script, need: cp /path/to/gateway-x.x.x/debian/kannel.default /etc/default/kannel emacs /etc/default/kannel #START_WAPBOX=1 //=0 to disable START_SMSBOX=1
Using gateway Check status: To check the configuration status use: http://192.168.1.120:13000/status Web browser return: Kannel bearerbox version `1.4.3'. Build `Sep 19 2011 16:20:15', compiler `4.1.2 20080704 (Red Hat 4.1.2-51)'. System Linux, release 2.6.32.120.7.1.xs5.6.100.323.170596xen, version #1 SMP Fri Apr 8 07:25:07 EDT 2011, machine i686. Hostname blueberries, IP 127.0.0.1. Libxml version 2.6.26. Using native malloc. Status: running, uptime 0d 18h 11m 23s WDP: received 0 (0 queued), sent 0 (0 queued) SMS: received 8 (0 queued), sent 8 (1 queued), store size 1 SMS: inbound (0.02,0.01,0.00) msg/sec, outbound (0.01,0.01,0.00) msg/sec DLR: 0 queued, using internal storage Box connections: smsbox:(none), IP 127.0.0.1 (0 queued), (on-line 0d 18h 11m 22s) SMSC connections: mobiphone AT2[mobiphone] (online 65467s, rcvd 8, sent 8, failed 0, queued 0 msgs)
Page 12 of 13
Sent SMS Use url: http://192.168.1.120:13014/cgibin/sendsms?username=foo&password=bar&to=+84903460989&text=Hel lo+world5 if send successful: webbrowsner return 0: Accepted for delivery
Receive SMS: PHP Examples to Receive SMS. Evironment: PHP/Apache environment Creat a file receivesms.php on root of file web configure. In file config, # SMS SERVICE, we use option: get-url =http://smart.jmango.vn/receivesms.php?sender=%p&text=%s So, when reply or send sms via Kannel, you ‘ll get a content of receivesms.php return. (reference: http://www.visualgsm.com/tutorial011_send_sms_php.htm )
Note: -
When Kannel donot run, check file config kannel.conf. Ensure that kannel.conf obey kannel document guide.
-
When you sent sms to kannel gateway, your sms get any problem. Replaces the SMS message sent back to user , Kannel can sent back Request Failed : it mean Kannel could not contact http service Could not fetch content, sorry: Kannel could not fetch content Result could not be represented as an SMS message: Kannel could
not represent the result as a SMS message. : when Kannel get an empty sms , Kannel set to "" to enable empty messages sent back user.
Page 13 of 13