📜 ⬆️ ⬇️

Configure Kannel SMS Gateway

Several times there have been mentions of such wonderful software as kannel, but for some reason there are no specific descriptions of examples of its integration. Here is an example of a service that can be implemented with an agreement with the mobile operator (Opsos), but it is still not clear how to do this. I'll try to fix this situation.

Offtopic. Why did I need it?


I have been working on a single project for a long time, the essence of which is to conduct real city games under the flag of MegaFon. At first they were games for which a simple online service on the Zend Framework was created, in which you could register, form teams, participate in games, get tasks, enter answers. However, the organizers and I wondered how this process could be made more accessible to the masses and more mobile. We decided to remake this platform for working with SMS. It is said - done, I contacted Megaphone technicians, found out how we could receive and send SMS (of course, it was much more preferable to use http, because no effort was required to integrate it and many sms services provide such an opportunity) , in Megaphone gave only bare SMPP. Nothing to do, I had to get out.

I’ve been looking for a good option for the gateway for a long time. Kannel has become such an option - an open-ended SMS, WAP gateway. I was not interested in the WAP component, but it turned out to be a really high-quality solution for the SMPP-HTTP gateway (you can also use it to send and receive SMS using SMPP as a server, MySQL to receive and send messages as DB lines).

Let's go to practice.


In many ways, configs duplicate what I cited in my article on integration with Multifon , however, here is an example of working with a cellular operator's SMPP.
')
I will skip part of the installation and initial configuration, you can read about them in the previously mentioned article.

A bit of theory. This system is a bit non-standard. It consists of several detached demons. There is a demon who oversees the others, and if the process dies, he starts it up again. This daemon is registered at startup from rc.d or init.d; you can familiarize yourself with its parameters in launch scripts.

bearerbox is the main daemon that keeps the SMPP connection as a client, works with 3G dongles, listens to the port for connecting other daemons.
smsbox - a daemon responsible for receiving messages from a web service and sending them to bearerbox for sending
opensmppbox is a daemon that works as an SMPP server to connect other clients. It also connects to bearerbox and works through it.
wapbox is a daemon that works as a wap gate. Honestly, I really did not understand him.
sqlbox is a great interesting daemon that can record incoming messages in MySQL database of a certain structure, as well as send SMS messages that are added to MySQL database. This makes it possible to integrate sms directly into the model via MVC. That is, sending is just creating and saving an sms object inside your MVC application, cool, huh? And the reception is similar, however, in this case you will not receive a callback about the fact that you have received sms, you will have to run the script on the crown and it will be no longer realtime.
Each of these daemons must have its own run_kannel_box attached . This is a daemon warden, for which you need to additionally register in the startup scripts, if you want to run more than one bearerbox / smsbox / wapbox in your configuration or attach other daemons. Or write your own scripts using the command line parameter --parachute (-P), as suggested in the zerkms comments.

Config with comments

group = core admin-port = 13000 #,             admin-password = pass #-,     (..    ) log-file = "/var/log/kannel/bearerbox.log" log-level = 1 #  ,    0. 1      . access-log = "/var/log/kannel/access_kannel.log" store-file = "/var/log/kannel/store_sms" smsbox-port = 13001 #,     - dlr-storage = internal sms-resend-retry = 1 # 1   . group = smsc smsc-id = povoljye smsc = smpp host = xxx.xxx.xxx.xxx #,     port = xxxx smsc-username = "name" smsc-password = "pass" source-addr-ton = 0 # 4      .      . source-addr-npi = 1 #   -  . dest-addr-ton = 1 dest-addr-npi = 1 system-type = VMA #-     ) throughput = 1000 #.   reconnect-delay = 5 #   connection-timeout = 120 # ,        N . transceiver-mode = true #,    !    ,        -   .       ,    ,    . denied-smsc-id = kemerovo #   -         SMS    SMSC.  SMS   round-robin,   ,    ,    SMS     . allowed-smsc-id = povoljye preferred-smsc-id = povoljye group = smsc #   smsc   .    -   ,    . smsc-id = kemerovo smsc = smpp host = xxx.xxx.xxx.xxx #  port = xxxx receive-port = xxxx smsc-username = "kemerovo" smsc-password = "pass" source-addr-ton = 0 source-addr-npi = 1 dest-addr-ton = 1 dest-addr-npi = 1 reconnect-delay = 5 system-type = VMA throughput = 1000 connection-timeout = 120 transceiver-mode = true denied-smsc-id = povoljye allowed-smsc-id = kemerovo preferred-smsc-id = kemerovo group = smsbox bearerbox-host = localhost sendsms-port = 13003 #,   smsbox  http    global-sender = 000037 #     log-file = /var/log/kannel/smsbox.log log-level = 0 access-log = /var/log/kannel/access_smsbox.log group = sendsms-user username = "user1" #,       SMS   http  password = "pass" concatenation = true #   max-messages = 20 #    default-smsc = povoljye group = sendsms-user username = "user2" password = "pass" concatenation = true max-messages = 20 default-smsc = kemerovo #ENGINE group = sms-service keyword = default # sms   .       . post-url = "http://example.com:8080/controller/action/tel/%p/time/%t/coding/%c/smsc/%i" # url   concatenation = true max-messages = 0 #  kannel  ,     http response.    , ..       . 


So, in this case, we looked at connecting to 2M MegaFon sms centers with separate sending, depending on the smsc parameter.

So we send SMS (see previous post to the account of problems with encodings)
  http://example.com:13003/cgi-bin/sendsms?smsc=$smsc&username=user1&password=pass&coding=2&to=79277777777&text=some_text 


And so we get the text of the SMS in our script (for example, PHP), in this case it is transmitted in the body of the POST request.
 $msg = file_get_contents('php://input'); 


Again, in the presence of a firewall, it is necessary to open the corresponding ports when accessing outside or open a loopback when working from the inside.

Of the links again cite usergide , because he is quite exhaustive. For experiencing problems with the connection - write in the comments or in the dev mailing list , there will help.

Source: https://habr.com/ru/post/124302/


All Articles