En nuestro artículo anterior sobre Kannel, aprendimos cómo instalar Kannel. Entonces, en esa configuración, almacenamos el Informe de entrega de SMS (DLR) en la memoria del bearerbox proceso. De esa forma, si bearerbox falla o cancelamos el proceso, pero todavía hay DLR abiertos, puede causar problemas para los usuarios de SMS.
Entonces, para evitar esta situación, podemos usar almacenamiento DLR externo como MySQL base de datos. En el artículo anterior usamos dos cajas kannel:bearerbox y smsbox . Para almacenar DLR en la base de datos MySQL usaremos otro programa Kannel:sqlbox . Toda la comunicación entre bearerbox y smsbox se hará a través de sqlbox . En funcionamiento, sqlbox actuará como bearerbox para smsbox y smsbox para caja portadora .
La comunicación entre diferentes procesos se puede ilustrar a continuación

Entorno de laboratorio:
Sistema operativo anfitrión:Debian 10 (buster)
IP del anfitrión:192.168.10.38
Ya tenemos instalada la aplicación PlaySMS SMS Management en el mismo host. Para la instalación de PlaySMS, consulte este artículo.
Para una mejor comprensión, hemos mostrado el proceso completo de instalación de Kannel con soporte MySQL en este artículo. Consulte esta página para preparar el servidor Debian para la instalación de Kannel.
Instalar servidor MariaDB
Entonces, MySQL ha adquirido Oracle Corporation y tiene ediciones comunitarias y comerciales.
En este laboratorio vamos a utilizar MariaDB base de datos, una alternativa de código abierto de MySQL. MariaDB se ha bifurcado de MySQL proyecto de código abierto y desarrollado y respaldado por algunos de los desarrolladores originales de MySQL .
Entonces, instale el servidor MariaDB con las dependencias necesarias
# apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
Coloque la información del repositorio de MariaDB en el archivo /etc/apt/sources.list.d/MariaDB.list
# MariaDB 10.3 repository list - created 2021-12-28 18:41 UTC # https://mariadb.org/download/ deb [arch=amd64,arm64,ppc64el] https://download.nus.edu.sg/mirror/mariadb/repo/10.3/debian buster main deb-src https://download.nus.edu.sg/mirror/mariadb/repo/10.3/debian buster main
Actualice el repositorio e instale MariaDB incluidas las dependencias necesarias
# apt-get update # apt-get install –y mariadb-server libmariadb-dev default-libmysqlclient-dev
Habilitar e iniciar el servicio MariaDB
# systemctl enable mariadb.service # systemctl start mariadb.service
Ejecute mysql_secure_installation para establecer la contraseña de root y otras directivas de seguridad como se muestra a continuación
Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
Crear MariaDB base de datos y usuario para Kannel.
# mysql -u root –p MariaDB [(none)]> CREATE DATABASE kannel CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; MariaDB [(none)]> CREATE USER 'kannel'@'localhost' IDENTIFIED BY 'kannelPassword'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON kannel.* TO 'kannel'@'localhost'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> quit
Crear dlr Mesa para Kannel DLR. Otras dos tablas send_sms y enviado_sms será creado automáticamente por Kannel sqlbox proceso en la primera ejecución
CREATE TABLE `dlr` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `smsc` varchar(40) DEFAULT NULL, `ts` varchar(40) DEFAULT NULL, `destination` varchar(40) DEFAULT NULL, `source` varchar(40) DEFAULT NULL, `service` varchar(40) DEFAULT NULL, `url` varchar(255) DEFAULT NULL, `mask` int(10) DEFAULT NULL, `status` int(10) DEFAULT NULL, `boxc` varchar(40) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Instalar Kannel con soporte MySQL
Para almacenar DLR en MySQL tenemos que compilar Kannel con soporte MySQL
# wget --no-check-certificate https://kannel.org/download/1.4.5/gateway-1.4.5.tar.gz # tar -zxf gateway-1.4.5.tar.gz # cd gateway-1.4.5/ # ./configure --enable-start-stop-daemon --prefix=/usr/local/kannel --with-mysql # make && make install
Instalar smsbox programa
# cd addons/sqlbox # ./bootstrap
Como hemos cambiado la ubicación de instalación predeterminada para Kannel, tendremos que proporcionar el directorio de biblioteca necesario y las variables de marca de C++ para Kannel y MariaDB con configure guión
Para encontrar la variable de marca de MariaDB, ejecute el siguiente comando
# mysql_config --cflags --libs
Salida:

Ejecute configurar guión
# ./configure --prefix=/usr/local/kannel \ --with-kannel-dir=/usr/local/kannel \ LDFLAGS="-L/usr/local/kannel/lib -L/usr/lib/x86_64-linux-gnu/ -lmariadb" \ CPPFLAGS="-I/usr/local/kannel/include/kannel -I/usr/include/mariadb -I/usr/include/mariadb/mysql"
Compilar sqlbox programa
# make && make install
Luego, cree los directorios necesarios
# mkdir /usr/local/kannel/etc # mkdir /usr/local/kannel/run # mkdir /var/log/kannel/
Después de eso, coloque el contenido a continuación en /usr/local/kannel/etc/kannel.conf archivo
##CORE group = core admin-port = 13000 smsbox-port = 13001 admin-password = sms-gw-admin-passwd status-password = sms-gw-status-passwd admin-deny-ip = "*.*.*.*" admin-allow-ip = "*.*.*.*" box-deny-ip = "*.*.*.*" box-allow-ip = "*.*.*.*" log-level = 0 log-file = "https://1118798822.rsc.cdn77.org/var/log/kannel/kannel.log" dlr-storage = mysql sms-resend-retry = 1 ##SMSC group = smsc smsc = at smsc-id = smsc01 my-number = 015XXXXXXXX allowed-smsc-id = smsc01 preferred-smsc-id = smsc01 modemtype = Huawei device = /dev/ttyUSB0 speed = 9600 alt-charset = "GSM" sim-buffering = true log-file = /var/log/kannel/smsc01-gsm1.log log-level = 0 ##MODEMS group = modems id = Huawei enable-mms = true init-string = "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0;+CNMI=1,3,2,2,1;+CMEE=1;+CPMS=\"SM\",\"SM\",\"SM\";+CMGF=0;+CSCS=GSM speed = 9600 detect-string = "huawei" ##SMSBOX group = smsbox bearerbox-host = localhost sendsms-port = 13013 bearerbox-port = 13010 mo-recode = true sendsms-chars = "0123456789 +-" log-file = "https://1118798822.rsc.cdn77.org/var/log/kannel/smsbox.log" log-level = 0 access-log = "https://1118798822.rsc.cdn77.org/var/log/kannel/access.log" ##SMS-USER group = sendsms-user user-deny-ip = "*.*.*.*" user-allow-ip = "*.*.*.*" # MAKE VERY SURE that you change the PASSWORD for security reasons username = kannel password = kannelpasswd default-smsc = smsc01 concatenation = 1 max-messages = 10 ##SMS-SERVICE group = sms-service keyword = default get-url = "http://localhost/index.php?app=call&cat=gateway&plugin=kannel&access=geturl&t=%t&q=%q&a=%a&Q=%Q&smsc=kannel" accept-x-kannel-headers = true max-messages = 10 concatenation = true catch-all = true omit-empty = true ##MySQL-Connection group = mysql-connection id = mysql-dlr host = localhost username = kannel password = kannelPassword database = kannel max-connections = 1 ##MySQL DLR Table ##You should not change this group name as bearerbox uses this name for MySQL DLR storage group = dlr-db id = mysql-dlr table = dlr 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
Crear /usr/local/kannel/etc/sqlbox.conf archivo que incluye el contenido a continuación
##MySQL Connection group = mysql-connection id = sqlbox-db host = localhost port = 3306 username = kannel password = kannelPassword database = kannel #SQL BOX CONFIG group = sqlbox id = sqlbox-db smsbox-id = sqlbox bearerbox-host = localhost bearerbox-port = 13001 smsbox-port = 13010 sql-log-table = sent_sms sql-insert-table = send_sms log-level = 0 log-file = "https://1118798822.rsc.cdn77.org/var/log/kannel/sqlbox.log"
Luego, cree el script de inicio/detención /usr/local/kannel/sbin/kannel incluyendo debajo del contenido
#!/bin/bash # 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. # BOXPATH=/usr/local/kannel/sbin PIDFILES=/usr/local/kannel/run CONFDIR=/usr/local/kannel/etc CONF=$CONFDIR/kannel.conf SQL_CONF=$CONFDIR/sqlbox.conf USER=kannel VERSION="" RB=$BOXPATH/run_kannel_box$VERSION BB=$BOXPATH/bearerbox$VERSION WB=$BOXPATH/wapbox$VERSION SB=$BOXPATH/smsbox$VERSION SSD=$BOXPATH/start-stop-daemon$VERSION 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/$BB || exit 0 case "$1" in start) echo -n "Starting WAP gateway: bearerbox" $SSD --start --quiet --pidfile $PIDFILES/kannel_bearerbox.pid --exec $RB -- --pidfile $PIDFILES/kannel_bearerbox.pid $BB -- $CONF sleep 2 echo -n " sqlbox" $BOXPATH/sqlbox -d $SQL_CONF sleep 2 echo -n " smsbox" $SSD --start --quiet --pidfile $PIDFILES/kannel_smsbox.pid --exec $RB -- --pidfile $PIDFILES/kannel_smsbox.pid $SB -- $CONF sleep 1 echo "." ;; stop) echo -n "Stopping WAP gateway: " echo -n " smsbox" $SSD --stop --quiet --pidfile $PIDFILES/kannel_smsbox.pid --exec $RB sleep 1 echo -n " sqlbox" pkill "sqlbox" sleep 1 echo -n " bearerbox" $SSD --stop --quiet --pidfile $PIDFILES/kannel_bearerbox.pid --exec $RB echo "." ;; status) CORE_CONF=$(grep -r 'group[[:space:]]*=[[:space:]]*core' $CONFDIR | cut -d: -f1) ADMIN_PORT=$(grep '^admin-port' $CORE_CONF | sed "s/.*=[[:space:]]*//") ADMIN_PASS=$(grep '^admin-password' $CORE_CONF | sed "s/.*=[[:space:]]*//") STATUS_URL="http://127.0.0.1:${ADMIN_PORT}/status.txt?password=${ADMIN_PASS}" curl $STATUS_URL ;; reload) # We don't have support for this yet. exit 1 ;; restart|force-reload) $0 stop sleep 3 $0 start ;; *) echo "Usage: $0 {start|stop|status|reload|restart|force-reload}" exit 1 esac exit 0
Cree el archivo /usr/local/kannel/sbin/kannel ejecutable
# chmod +x /usr/local/kannel/sbin/kannel
Agregue Kannel al inicio usando systemd
Ahora cree el archivo de unidad systemd /etc/systemd/system/kannel-gateway.service incluidos los contenidos a continuación
[Unit] Description=Kannel - WAP and SMS Gateway Documentation=https://www.kannel.org/doc.shtml After=network-online.target Wants=network-online.target [Service] Type=forking ExecStart=/usr/local/kannel/sbin/kannel start ExecReload=/usr/local/kannel/sbin/kannel restart ExecStop=/usr/local/kannel/sbin/kannel stop [Install] WantedBy=multi-user.target
Recargar systemd
# systemctl daemon-reload
Inicie y habilite kannel-gateway servicio
# systemctl enable kannel-gateway.service # systemctl start kannel-gateway.service # systemctl status kannel-gateway.service
MÁSCARA-DLR y URL-DLR
Kannel proporciona los siguientes tipos de informes de entrega
1:entrega exitosa
2:falla en la entrega
4:mensaje almacenado en búfer
8:enviar smsc
16:rechazo de smsc
Por lo tanto, para varios tipos de informes de entrega, debe sumar los valores correspondientes a cada tipo y configurarlos como dlr-mask mientras envía el mensaje.
Ejemplo:para el informe de estado de envío exitoso, fallido y/o almacenado en búfer de un SMS, tenemos que configurar dlr-mask como 1+2+4=7.
Con máscara dlr es necesario enviar dlr-url para devolver el informe de entrega con un SMS.
Si seguimos una solicitud Enviar SMS desde la aplicación PlaySMS, encontraremos la solicitud html como se muestra a continuación

Aquí entendemos que PlaySMS está solicitando una solicitud de envío exitosa, fallida, almacenada en búfer y/o smsc en dlr-mask (15) y también envíe su dlr-url con la solicitud.
Enviar registros de SMS
Entonces, enviamos un SMS desde el portal web PlaySMS y verificamos diferentes estados desde la consola MariaDB
SMS enviado pero aún no recibido por el destinatario:
MariaDB [kannel]> select * from dlr; +----+---------------------+--------+------+---------------+-------------+---------+------------------------------------------------------------------------------------------------------------------+------+--------+------+ | id | datetime | smsc | ts | destination | source | service | url | mask | status | boxc | +----+---------------------+--------+------+---------------+-------------+---------+------------------------------------------------------------------------------------------------------------------+------+--------+------+ | 1 | 2022-01-08 23:07:51 | smsc01 | 165 | 88017XXXXXXXX | 015XXXXXXXX | kannel | http://localhost//index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=20&uid=1&smsc=kannel | 15 | 0 | | +----+---------------------+--------+------+---------------+-------------+---------+------------------------------------------------------------------------------------------------------------------+------+--------+------+ 1 row in set (0.000 sec) MariaDB [kannel]> select * from sent_sms; +--------+------+-------------+---------------+---------+----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------+------+---------+------+---------+---------+-------+------------------------+----------+------------+ | sql_id | momt | sender | receiver | udhdata | msgdata | time | smsc_id | service | account | id | sms_type | mclass | mwi | coding | compress | validity | deferred | dlr_mask | dlr_url | pid | alt_dcs | rpi | charset | boxc_id | binfo | meta_data | priority | foreign_id | +--------+------+-------------+---------------+---------+----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------+------+---------+------+---------+---------+-------+------------------------+----------+------------+ | 1 | MT | 015XXXXXXXX | 88017XXXXXXXX | NULL | MySQL+DLR+Test | 1641661668 | smsc01 | kannel | admin | NULL | 2 | NULL | NULL | 0 | NULL | NULL | NULL | 15 | http://localhost//index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=20&uid=1&smsc=kannel | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | | 2 | DLR | 015XXXXXXXX | 88017XXXXXXXX | NULL | ACK%2F | 1641661671 | smsc01 | kannel | NULL | NULL | 3 | NULL | NULL | NULL | NULL | NULL | NULL | 8 | http://localhost//index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=20&uid=1&smsc=kannel | NULL | NULL | NULL | NULL | NULL | NULL | ?orig_msg?dlr_mask=15& | NULL | 165 | +--------+------+-------------+---------------+---------+----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------+------+---------+------+---------+---------+-------+------------------------+----------+------------+ 2 rows in set (0.001 sec)
Después de recibir el SMS en el teléfono móvil de destino y obtener el DLR correcto del módem GSM
MariaDB [kannel]> select * from dlr; Empty set (0.000 sec) MariaDB [kannel]> select * from sent_sms; +--------+------+-------------+---------------+---------+----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------+------+---------+------+---------+---------+-------+------------------------+----------+------------+ | sql_id | momt | sender | receiver | udhdata | msgdata | time | smsc_id | service | account | id | sms_type | mclass | mwi | coding | compress | validity | deferred | dlr_mask | dlr_url | pid | alt_dcs | rpi | charset | boxc_id | binfo | meta_data | priority | foreign_id | +--------+------+-------------+---------------+---------+----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------+------+---------+------+---------+---------+-------+------------------------+----------+------------+ | 1 | MT | 015XXXXXXXX | 88017XXXXXXXX | NULL | MySQL+DLR+Test | 1641661668 | smsc01 | kannel | admin | NULL | 2 | NULL | NULL | 0 | NULL | NULL | NULL | 15 | http://localhost//index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=20&uid=1&smsc=kannel | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | | 2 | DLR | 015XXXXXXXX | 88017XXXXXXXX | NULL | ACK%2F | 1641661671 | smsc01 | kannel | NULL | NULL | 3 | NULL | NULL | NULL | NULL | NULL | NULL | 8 | http://localhost//index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=20&uid=1&smsc=kannel | NULL | NULL | NULL | NULL | NULL | NULL | ?orig_msg?dlr_mask=15& | NULL | 165 | | 3 | DLR | 015XXXXXXXX | 88017XXXXXXXX | NULL | Success | 1641661727 | smsc01 | kannel | NULL | NULL | 3 | NULL | NULL | NULL | NULL | NULL | NULL | 1 | http://localhost//index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=20&uid=1&smsc=kannel | NULL | NULL | NULL | NULL | NULL | NULL | ?orig_msg?dlr_mask=15& | NULL | 165 | +--------+------+-------------+---------------+---------+----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------+------+---------+------+---------+---------+-------+------------------------+----------+------------+ 3 rows in set (0.000 sec)
SMS entrantes:
MariaDB [kannel]> select * from sent_sms where momt='MO'; +--------+------+----------------+-------------+---------+-----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+---------+------+---------+------+---------+---------+-------+-----------+----------+------------+ | sql_id | momt | sender | receiver | udhdata | msgdata | time | smsc_id | service | account | id | sms_type | mclass | mwi | coding | compress | validity | deferred | dlr_mask | dlr_url | pid | alt_dcs | rpi | charset | boxc_id | binfo | meta_data | priority | foreign_id | +--------+------+----------------+-------------+---------+-----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+---------+------+---------+------+---------+---------+-------+-----------+----------+------------+ | 4 | MO | +88017XXXXXXXX | 015XXXXXXXX | NULL | SQLBOX+incoming | 1641663435 | smsc01 | NULL | NULL | NULL | 0 | NULL | NULL | 0 | 0 | NULL | NULL | NULL | NULL | 0 | 0 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | +--------+------+----------------+-------------+---------+-----------------+------------+---------+---------+---------+------+----------+--------+------+--------+----------+----------+----------+----------+---------+------+---------+------+---------+---------+-------+-----------+----------+------------+ 1 row in set (0.000 sec)
Registro de SMSBOX:

Registro saliente del portal PlaySMS:

Desde el teléfono del destinatario:

Referencias
- https://www.kannel.org/download/kannel-userguide-snapshot/userguide.html