Kannel Install
Kannel Install
kannel is an open source wap and sms gateway designed to transmit SMS messages to
a cellular operator using the SMPP protocol . The application is very flexible. It is also
possible to configure the modem to transmit SMS. But the most important advantage
of this software is that it is free and works normally ( set it and forget it ).
The kannel is configured via the command line, which is not a particular problem for
me personally ( there is no GUI ). You will have to carefully read the
documentation and forget about any support. The application has not been updated by
its creators since October 20, 2010.
Monitoring of the server's operation is carried out through the Web interface - a
simple application in PHP, included in the kannel package.
1. bearerbox - the main part of the application that routes messages from any server
daemons to the operator;
2. smsbox - a daemon that allows you to send SMS via the http protocol;
3. wapbox - wap gateway (works over the UDP protocol, is used to display WML pages and
is not discussed in this article);
Additional demons:
1. sqlbox - a daemon that allows you to send SMS via writing to a MySQL database;
2. opensmppbox - SMPP gateway for connecting child servers using the SMPP protocol;
Important! This manual does not contain information on setting up USB modems for
SMS transmission.
# apt-get update && apt-get install mysql-server php5-cli nginx php5-fpm gcc make
If you install opensmppbox, sqlbox, you must not use compiled packages and ready-
made binaries. All packages need to be collected on the usage server. This is due to
the fact that when building additional packages, the newly built kannel libraries are
used. If the main server has a different version than the additional daemons, then
errors like opensmppbox multi-message die are possible ; this is due to the already
built kannel libraries.
To install kannel with database support, you need the mysql client library.
Install them:
# cd /tmp
# wget http://www.kannel.org/download/kannel-snapshot.tar.gz
# cd /tmp/kannel-snapshot
# make
# make install
# cd /tmp/kannel-snapshot/addons/sqlbox/
Next, copy the mysql header files to the source code folder.
Important! If the folder gw and headers already exist, then there is no need to copy
and you can skip the next listing.
# mkdir gw
# cp -R /usr/include/mysql/ gw/
# ./configure --with-kannel-dir=/usr/local/include/kannel/
# make
# make install
Let's immediately assemble opensmppbox so that smpp client gateways can connect to
us (continuation of the previous listing):
# cd /tmp/kannel-snapshot/addons/opensmppbox/
# ./configure --with-kannel-dir=/usr/local/include/kannel/
# make
# make install
# mysql -u root -p
# nano /tmp/kannel_dump.sql
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `sms_db` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `sms_db`;
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `smsbearerbox` /*!40100 DEFAULT CHARACTER SET utf8
*/;
USE `smsbearerbox`;
`url` text,
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `smssqlbox` /*!40100 DEFAULT CHARACTER SET utf8
*/;
USE `smssqlbox`;
`udhdata` blob,
`msgdata` text,
`udhdata` blob,
`msgdata` text,
# cd /etc/kannel
# tree
├── dlr-bearerbox.conf
│ └── users.conf
│ └── users.conf
│ └── smsc.conf
│ └── routing.conf
│ └── services.conf
Important! Pay attention to the log files, as well as the ports that are opened. All
boxes communicate with each other via TCP connections. Also look at which configs
are included in which.
Let's agree that all configuration listings contain <что-то в треугольных скобках> user
settings - logins, passwords, etc.
Configuration example:
# nano /etc/kannel/kannel.conf
group = core
wdp-interface-name = "*"
admin-port = 13000
smsbox-port = 13001
admin-password = <admin_password_for_http>
admin-deny-ip = "*.*.*.*"
admin-allow-ip = "127.0.0.1;192.168.*.*"
log-file = "/var/log/kannel/bearerbox.log"
log-level = 0
access-log = "/var/log/kannel/access.log"
box-allow-ip = "127.0.0.1;*.*.*.*"
dlr-storage = mysql
#store-type = spool
#store-location = "/var/spool/kannel"
#store-file = "/var/log/kannel/store_sms"
include = "/etc/kannel/dlr-bearerbox.conf"
include = "/etc/kannel/smsс/smsc.conf"
include = "/etc/kannel/smsbox.conf"
include = "/etc/kannel/smsbox/users.conf"
include = "/etc/kannel/routing/routing.conf"
Settings for connecting to an operator usually contain host, login, password, port, as
well as settings for converting international (national) numbers , operating mode
(transceiver - reception and transmission over one connection), interface version, etc.:
# nano /etc/kannel/smsс/smsc.conf
#smsc-id = fakesmsc
#smsc = fake
#port = 10000
group = smsc
smsc = smpp
system-type = VMA
host = <operator_host>
port = 9932
transceiver-mode = false
receive-port = 9932
interface-version = 34
smsc-username = <username>
smsc-password = <secret>
enquire-link-interval = 270
source-addr-ton = 2
source-addr-npi = 1
dest-addr-ton = 2
dest-addr-npi = 1
msg-id-type = 0x03
log-file = "/var/log/kannel/<operator>.log"
log-level = 0
Megaphone settings:
group = smsc
smsc = smpp
smsc-id = megafon
system-type = VMA
host = <megafon_host>
port = 9932
transceiver-mode = false
interface-version = 34
smsc-username = <username>
smsc-password = <secret>
enquire-link-interval = 270
reconnect-delay = 60
connection-timeout = 120
source-addr-ton = 2
source-addr-npi = 1
dest-addr-ton = 2
dest-addr-npi = 1
msg-id-type = 0x03
log-file = "/var/log/kannel/megafon.log"
log-level = 0
MTS settings:
group = smsc
smsc = smpp
smsc-id = mts
system-type = VMA
host = <mts_host>
port = 5000
transceiver-mode = true
interface-version = 34
smsc-username = <username>
smsc-password = <secret>
enquire-link-interval = 60
source-addr-ton = 1
source-addr-npi = 1
dest-addr-ton = 1
dest-addr-npi = 1
msg-id-type = 0x03
log-file = "/var/log/kannel/mts.log"
log-level = 0
Settings sms-telecom.by
group = smsc
smsc = smpp
smsc-id = smstelecom
system-type = VMA
host = <smstelecom_host>
port = 2775
transceiver-mode = false
interface-version = 34
smsc-username = <username>
smsc-password = <secret>
enquire-link-interval = 270
source-addr-ton = 2
source-addr-npi = 1
dest-addr-ton = 2
dest-addr-npi = 1
msg-id-type = 0x03
log-file = "/var/log/kannel/smstelecom.log"
log-level = 0
group = smsc
smsc = at
smsc-id = ACMZTE
modemtype = ztemodem
device = /dev/ttyUSB1
allowed-prefix = "+998;998"
sms-center = +998930190000
#sim-buffering = true
my-number = +999988888888
speed = "default"
log-file = "/var/log/kannel/zte.log"
log-level = 0
# Modem SETUP
group = modems
id = ztemodem
name = "ZTE"
#need-sleep = true
#message-storage = "SM"
no-smsc = true
keepalive-cmd = "AT+CBC;+CSQ"
broken = true
Huawei E173 modem settings as smsc (Sadulla, thank you very much for these
settings.)
group = smsc
smsc = at
connect-allow-ip = 127.0.0.1
port = 13013
host = "localhost"
smsc-id = Ucell
modemtype = auto
device = /dev/ttyUSB0
speed = 9600
sms-center = "+998000000000"
my-number = "+99888888888"
group = modems
id = huawei_e173
detect-string = "huawei"
init-string = "AT+CFUN=1"
init-string = “AT+CNMI=3,2,0,0,0″
init-string = “AT+CMEE=2;+CNMI=3,1,0,0,0″
reset-string = “ATZ”
need-sleep = true
keepalive-cmd = “AT+CBC;+CSQ”
enable-mms = true
message-storage=”SM”
smsbox settings:
# nano /etc/kannel/smsbox.conf
# ------ SMSBOX GROUP ------
group = smsbox
smsbox-id = smsbox-web
bearerbox-host = 127.0.0.1
bearerbox-port = 13005
sendsms-port = 13013
log-file = "/var/log/kannel/smsbox.log"
log-level = 0
access-log = "/var/log/kannel/sms-access.log"
sendsms-chars = "0123456789+"
global-sender = "<sender-nuber>"
Settings for smsbox users, users who send sms via http:
# nano /etc/kannel/smsbox/users.conf
group = sendsms-user
username = satssmsgateway
password = Q8EM8Q1BJ5
max-messages = 10
concatenation = true
default-smsc = megafon
# nano /etc/kannel/services/services.conf
group = sms-service
keyword = nop
group = sms-service
keyword = default
# nano /etc/kannel/routing/routing.conf
group = smsbox-route
smsbox-id = <opensmppbox-user-1>
shortcode = "<shortcode-1>"
group = smsbox-route
smsbox-id = <opensmppbox-user-2>
shortcode = "<shortcode-2>"
group = smsbox-route
smsbox-id = <opensmppbox-user-3>
shortcode = "<shortcode-3>"
sqlbox settings
# nano /etc/kannel/sqlbox.conf
group = sqlbox
id = "sqlbox-db"
sql-engine = mysql
smsbox-id = "sqlbox-mysql"
bearerbox-port = 13001
smsbox-port = 13005
smsbox-port-ssl = false
sql-log-table = sent_sms
sql-insert-table = send_sms
log-file = "/var/log/kannel/sqlbox.log"
log-level = 0
group = mysql-connection
id = "sqlbox-db"
host = localhost
username = sqlbox
password = 98D9D
database = smssqlbox
max-connections = 25
Settings for connecting to the database, as well as storing SMS delivered by smsbox
# nano dlr-bearerbox.conf
group = mysql-connection
id = bearerbox-dlr
host = localhost
username = bearerbox
password = HW4Qh
database = smsbearerbox
max-connections = 10
# ------ DLR STORAGE CONFIGURATION ------
group = dlr-db
id = bearerbox-dlr
table = dlr_sms_kannel
field-smsc = smsc
field-timestamp = ts
field-destination = destination
field-source = source
field-service = service
field-url = url
field-mask = mask
field-status = status
field-boxc-id = boxc
opensmppbox settings
opensmppbox has a separate configuration file, which contains separate routing
# opensmppbox.conf
group = core
dlr-storage = internal
store-file = "/var/log/kannel/smpp_store_sms"
group = opensmppbox
opensmppbox-id = smppbox
opensmppbox-port = 19933
bearerbox-host = 127.0.0.1
bearerbox-port = 13001
log-level = 0
log-file = "/var/log/kannel/opensmppbox.log"
our-system-id = satssmpp
route-to-smsc = <smsc-id>
smpp-logins = "/etc/kannel/opensmppbox/users.conf"
use-systemid-as-smsboxid = yes
# shortcode or both.
#group = client-route
#smsc-id = <operator>
Launch scripts
These scripts are based on the original scripts that come with kannel when installed
from the deb package. They differ from the FreeBSD startup scripts in that they use
utilities /lib/lsb/init-functions that are only available in Debian. The main task of
these scripts is to launch a process with a specific configuration file, create a PID file
if necessary and kill the process. There is no magic.
The file in which the default boxes for launch are registered
# nano /etc/default/kannel
#START_WAPBOX=1
START_SMSBOX=1
START_SQLBOX=1
START_OPENSMPPBOX=1
# nano /etc/init.d/kannel
#!/bin/sh
# Start/stop the Kannel boxes: One bearer box and one WAP box.
# Make sure that the Kannel binaries can be found in $BOXPATH or somewhere
# Provides: kannel
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
. /lib/lsb/init-functions
BOXPATH=/usr/local/sbin
PIDFILES=/var/run/kannel
CONF=/etc/kannel/kannel.conf
SMSBOX_CONF=/etc/kannel/smsbox.conf
SQL_CONF=/etc/kannel/sqlbox.conf
PATH=$BOXPATH:$PATH
# On Debian, the most likely reason for the bearerbox not being available
if [ ! -d $PIDFILES ]
then
mkdir $PIDFILES
fi
case "$1" in
start)
--pidfile $PIDFILES/kannel_bearerbox.pid \
--chuid kannel \
--exec $BOXPATH/run_kannel_box \
-- \
--pidfile $PIDFILES/kannel_bearerbox.pid \
--no-extra-args \
$BOXPATH/bearerbox -v 4 -- $CONF
sleep 1
--pidfile $PIDFILES/kannel_sqlbox.pid \
--chuid kannel \
--exec $BOXPATH/run_kannel_box \
-- \
--pidfile $PIDFILES/kannel_sqlbox.pid \
--no-extra-args \
$BOXPATH/sqlbox -v 4 -- $SQL_CONF
sleep 1
--pidfile $PIDFILES/kannel_smsbox.pid \
--chuid kannel \
--exec $BOXPATH/run_kannel_box \
-- \
--pidfile $PIDFILES/kannel_smsbox.pid \
--no-extra-args \
$BOXPATH/smsbox -v 4 -- $CONF
log_end_msg 0
;;
stop)
--pidfile $PIDFILES/kannel_smsbox.pid \
--exec $BOXPATH/run_kannel_box
--pidfile $PIDFILES/kannel_sqlbox.pid \
--exec $BOXPATH/run_kannel_box
--pidfile $PIDFILES/kannel_bearerbox.pid \
--exec $BOXPATH/run_kannel_box
log_end_msg 0
;;
reload)
exit 1
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
*)
exit 1
esac
exit 0
# nano /etc/init.d/opensmppbox
#!/bin/sh
# Start/stop the Kannel boxes: One bearer box and one WAP box.
# Make sure that the Kannel binaries can be found in $BOXPATH or somewhere
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
. /lib/lsb/init-functions
BOXPATH=/usr/local/sbin
PIDFILES=/var/run/kannel
SMPPBOX_CONF=/etc/kannel/opensmppbox.conf
PATH=$BOXPATH:$PATH
# On Debian, the most likely reason for the bearerbox not being available
if [ ! -d $PIDFILES ]
then
mkdir $PIDFILES
case "$1" in
start)
--pidfile $PIDFILES/kannel_opensmppbox.pid \
--chuid kannel \
--exec $BOXPATH/run_kannel_box \
-- \
--pidfile $PIDFILES/kannel_opensmppbox.pid \
--no-extra-args \
$BOXPATH/opensmppbox -v 4 $SMPPBOX_CONF
;;
stop)
--pidfile $PIDFILES/kannel_opensmppbox.pid \
--exec $BOXPATH/run_kannel_box
log_end_msg 0
;;
reload)
exit 1
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
*)
exit 1
esac
exit 0
# chmod +x /etc/init.d/kannel
# chmod +x /etc/init.d/opensmppbox
#!/bin/sh
# Configuration file
CONF=/usr/local/etc/kannel/kannel.conf
SQLCONF=/usr/local/etc/kannel/sqlbox.conf
# Kannel boxes
BEARERBOX=/usr/local/sbin/bearerbox
SMSBOX=/usr/local/sbin/smsbox
SQLBOX=/usr/local/sbin/sqlbox
DEBUGLEVEL=0
[ -x $BEARERBOX ] || exit 0
[ -x $SMSBOX ] || exit 0
[ -f $CONF ] || exit 0
case "$1" in
start)
echo "done"
echo -n
sleep 1
echo "done"
echo -n
sleep 1
echo "done"
;;
stop)
/etc/rc.d/killall smsbox
echo "done"
sleep 1
echo -n "Shutting down sqlbox... "
/etc/rc.d/killall sqlbox
echo "done"
sleep 1
/etc/rc.d/killall bearerbox
echo "done"
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
exit 1
esac
exit 0
Form for sending SMS via smsbox. This is a small PHP application that processes the
form, determines the presence of Russian and sends it to smsbox for conversion, while
writing the sms identifier to the dlr_sms database, and when sending it sends a
callback, thanks to which, when the status is received, it is written to the database.
[flickr:id=35805261370]
location /kannel-monitor/ {
root /usr/local/www;
index index.php;
location /kannel-sendsms/ {
root /usr/local/www;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
# cp -R /tmp/kannel-snapshot/contrib/kannel-monitor /usr/local/www/
Let's edit the lines with the settings in accordance with the settings kannel.conf :
nano /usr/local/www/kannel-monitor/index.php
$configs = array(
)/*,
),
)/**/
);
We create directories for the application to work and the necessary files
# mkdir /usr/local/www/kannel-sendsms
# cd /usr/local/www/kannel-sendsms
Settings file:
# nano config.inc
<?php
define("BEARERBOX_HOST", "localhost");
define("SENDSMS_PORT", "13013");
define("ADMIN_PORT", "13000");
define("ADMIN_PASSWORD", "fnccvjkmysq");
define("USERNAME", "satssmsgateway");
define("PASSWORD", "Q8EM8Q1BJ5");
define("GLOBAL_SENDER", "<from-number>");
?>
# nano functions.inc
<?php
if (!$connection) {
} else {
socket_set_blocking($connection, false);
echo "$URL";
while (!feof($connection)) {
switch ($myline) {
break;
case "":
break;
case "\r\n":
break;
default:
fclose($connection);
function octstr_append_cstr($mystring)
$mystring2 = "";
return ($mystring2);
?>
File index.php :
<html>
<head>
<title>Отправить СМС</title>
</head>
include("config.inc");
include("functions.inc");
$this_page = $_SERVER['PHP_SELF'];
if ($_GET['submit']) {
$to = $_POST['to'];
$text = $_POST['text'];
print $text;
$sms_id = uniqid();
$ptrn = '~([а-яА-ЯёЁ]+)~ui';
if (preg_match($ptrn, $text)) {
$coding = "&coding=2";
} else {
$coding = "&coding=0";
$text = urlencode($text);
http_send($URL, SENDSMS_PORT);
} else {
echo "Не заполнен текст или номер получателя.";
} else {
?>
<p>
<br>
</p>
<p>
Сообщение:
<br>
</p>
<br>
</form>
<?php
?>
<p>
</p>
<hr>
<tr>
<td width="100%">
</td>
</tr>
</table>
</body>
</html>
# nano dlr.php
<?php
$server = 'localhost';
$username = '<db_login>';
$password = '<db_password>';
$dbname = 'sms_db';
if (!$db) {
if (!$db_selected) {
}
$msgdata = $_GET['text'];
$original_time = $_GET['time'];
$smsc = $_GET['smsc'];
$sender = $_GET['from'];
$receiver = $_GET['to'];
$dlr = $_GET['dlr-type'];
$sms_id = $_GET['sms_id'];
$smssys_id = $_GET['smssys_id'];
$charset = $_GET['charset'];
$coding = $_GET['coding'];
$report = array(
);
switch ($dlr) {
case '8':
$dt = date("Y-m-d");
$ti = date("H:i:s");
break;
case '1':
$dt = date("Y-m-d");
$ti = date("H:i:s");
$result_1 = mysql_query("UPDATE dlr_sms SET time = '" . $time . "', mask = '" .
$dlr . "', status = '" . $report[1] . "' WHERE destination = '" . $receiver . "' AND
smssys_id = '" . $smssys_id . "';");
break;
case '2':
$dt = date("Y-m-d");
$ti = date("H:i:s");
$result_2 = mysql_query("UPDATE dlr_sms SET time = '" . $time . "', mask = '" .
$dlr . "', status = '" . $report[2] . "' WHERE destination = '" . $receiver . "' AND
smssys_id = '" . $smssys_id . "';");
break;
case '4':
$dt = date("Y-m-d");
$ti = date("H:i:s");
$result_4 = mysql_query("UPDATE dlr_sms SET time = '" . $time . "', mask = '" .
$dlr . "', status = '" . $report[4] . "' WHERE destination = '" . $receiver . "' AND
smssys_id = '" . $smssys_id . "';");
break;
case '16':
$dt = date("Y-m-d");
$ti = date("H:i:s");
$time = $dt . " " . $ti;
break;
?>
Launch
Testing the launch
All is ready! Thank you for your attention. The article turned out to be long. If you
have any questions, write.
PS To send MMS and SMS, I configured the nowsms server, I get SMS and (MMS if
there is an authentication server). It works stably, the only drawback is that it is paid
and only for Windows.
PPS I posted my application on github , which I have been using for several years to
send SMS messages via kannel in python and django.
Repository https://github.com/sinyawskiy/djkannel
If the article was useful to you, please click on the advertisement. Thank you!
Using sqlbox and triggers to keep track of Kannel message
delivery reports
/*
This is a Mini HOW-TO in order to send sms messages via Kannel and sqlbox and keep track of
status information.
Author: Rene Kluwen <rene.kluwen@chimit.nl>.
Many thanks to Alejandro to host this how-to on his Kannel blog. The text of this blog is
completely enclosed in comment blocks, so you can just copy and paste the whole post in your
favorite mysql editor and it will run the code (e.g. create the necessary tables, triggers and stored
procedures).
We only need sqlbox and bearerbox. In this example, smsbox is not used. Also we do not use an
http server for delivery reports.
Everything is done in Mysql.
To start, we assume that you have a working Kannel and Sqlbox installation. See the Kannel users
manual on how to set this up.
Next, we need to collect the following information:
– <sender_id>: The number (or text) that the messages appear to be sent from.
– <smsc>: The smsc that the messages will be submitted to.
– <sqlbox_id>: The ‘smsbox-id’ of your sqlbox instance.
We use these values as defaults in our trigger. Substitute them with your own values, below.
*/
IF ISNULL(s) THEN
RETURN NULL;
ELSE
SET s2 = '';
WHILE pointer <= length(s) DO
SET c = MID(s,pointer,1);
IF c = ' ' THEN
SET c = '+';
ELSEIF NOT (ASCII(c) BETWEEN 48 AND 57 OR
ASCII(c) BETWEEN 65 AND 90 OR
ASCII(c) BETWEEN 97 AND 122) THEN
SET c = concat("%",LPAD(CONV(ASCII(c),10,16),2,0));
END IF;
SET s2 = CONCAT(s2,c);
SET pointer = pointer + 1;
END while;
END IF;
RETURN s2;
END;
/* end of helper function urlencode */
/* Usage example; substitute the given number (and text) with your own: */
INSERT INTO snd (snd_to, snd_txt) VALUES ('1234567890', 'My first example text to
send...');
/* After inserting this message, Kannel will send it and update it’s status fields automatically. */