Dalam artikel kami sebelumnya tentang Kannel, kami telah belajar tentang cara menginstal Kannel. Jadi, dalam konfigurasi tersebut, kami menyimpan SMS Delivery Report (DLR) di memori bearerbox proses. Dengan cara itu, jika bearerbox crash atau kami menghentikan prosesnya, tetapi masih ada DLR yang terbuka, ini dapat menyebabkan masalah bagi Pengguna SMS.
Jadi, untuk menghindari situasi ini, kita dapat menggunakan penyimpanan DLR eksternal seperti MySQL database.Pada artikel sebelumnya kami menggunakan dua kotak kannel:bearerbox dan kotak sms . Untuk menyimpan DLR di database MySQL kita akan menggunakan program Kannel lain:sqlbox . Semua komunikasi antara bearerbox dan kotak sms akan dilakukan melalui sqlbox . Dalam operasi, sqlbox akan bertindak seperti bearerbox untuk kotak sms dan kotak sms untuk bearerbox .
Komunikasi antar proses yang berbeda dapat diilustrasikan seperti di bawah ini
Lingkungan LAB:
OS Host:Debian 10 (buster)
IP Host :192.168.10.38
Kami sudah menginstal aplikasi Manajemen SMS PlaySMS di host yang sama. Untuk instalasi PlaySMS silahkan cek artikel ini.
Untuk pemahaman yang lebih baik, kami telah menunjukkan proses instalasi lengkap Kannel dengan dukungan MySQL dalam artikel ini. Silakan lihat halaman ini untuk mempersiapkan host Debian untuk Instalasi Kannel.
Instal Server MariaDB
Jadi, MySQL telah diakuisisi oleh Oracle Corporation dan memiliki edisi komunitas dan Komersial.
Di Lab ini kita akan menggunakan MariaDB database, alternatif sumber terbuka MySQL. MariaDB telah bercabang dari MySQL proyek sumber terbuka dan dikembangkan serta didukung oleh beberapa pengembang asli MySQL .
Jadi, Instal Server MariaDB dengan dependensi yang diperlukan
# apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
Letakkan info repo MariaDB di file /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
Perbarui repo dan instal MariaDB termasuk dependensi yang diperlukan
# apt-get update # apt-get install –y mariadb-server libmariadb-dev default-libmysqlclient-dev
Aktifkan dan Mulai layanan MariaDB
# systemctl enable mariadb.service # systemctl start mariadb.service
Jalankan mysql_secure_installation untuk mengatur kata sandi root dan arahan keamanan lainnya seperti di bawah ini
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
Buat MariaDB database dan pengguna untuk 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
Buat dlr tabel untuk Kannel DLR. Dua tabel lainnya send_sms dan kirim_sms akan dibuat secara otomatis oleh Kannel sqlbox proses saat dijalankan pertama
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;
Instal Kannel dengan dukungan MySQL
Untuk menyimpan DLR di MySQL kita harus mengkompilasi Kannel dengan dukungan 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
Instal kotak sms program
# cd addons/sqlbox # ./bootstrap
Karena kami telah mengubah lokasi instalasi default untuk Kannel, kami harus menyediakan direktori library yang diperlukan dan variabel flag C++ untuk Kannel dan MariaDB dengan configure skrip
Untuk menemukan variabel flag MariaDB, jalankan perintah di bawah ini
# mysql_config --cflags --libs
Keluaran:
Jalankan konfigurasi skrip
# ./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"
Kompilasi sqlbox program
# make && make install
Kemudian, buat direktori yang diperlukan
# mkdir /usr/local/kannel/etc # mkdir /usr/local/kannel/run # mkdir /var/log/kannel/
Setelah itu, letakkan konten di bawah ini di /usr/local/kannel/etc/kannel.conf berkas
##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
Buat /usr/local/kannel/etc/sqlbox.conf file termasuk konten di bawah ini
##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"
Kemudian, buat Start/Stop Script /usr/local/kannel/sbin/kannel termasuk konten di bawah ini
#!/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
Jadikan file /usr/local/kannel/sbin/kannel dapat dieksekusi
# chmod +x /usr/local/kannel/sbin/kannel
Tambahkan Kannel ke startup menggunakan systemd
Sekarang buat file unit systemd /etc/systemd/system/kannel-gateway.service termasuk konten di bawah ini
[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
Muat ulang systemd
# systemctl daemon-reload
Mulai dan aktifkan kannel-gateway layanan
# systemctl enable kannel-gateway.service # systemctl start kannel-gateway.service # systemctl status kannel-gateway.service
DLR-MASK dan URL-DLR
Kannel menyediakan jenis laporan pengiriman di bawah ini
1:keberhasilan pengiriman
2:kegagalan pengiriman
4:pesan buffered
8:kirim smsc
16:tolak smsc
Jadi, untuk beberapa jenis laporan pengiriman, Anda harus menjumlahkan nilai yang sesuai dengan setiap jenis dan harus ditetapkan sebagai dlr-mask saat mengirim pesan.
Contoh:untuk laporan status pengiriman SMS sukses, gagal dan/atau buffered, kita harus mengatur dlr-mask sebagai 1+2+4=7.
Dengan dlr-mask perlu mengirim dlr-url untuk mengirim kembali laporan pengiriman dengan SMS.
Jika kita mengikuti permintaan Kirim SMS dari aplikasi PlaySMS kita akan menemukan permintaan html seperti di bawah ini
Di sini kami memahami bahwa PlaySMS menanyakan keberhasilan, kegagalan, buffered, dan/atau permintaan pengiriman smsc di dlr-mask (15) dan juga kirimkan dlr-url dengan permintaan.
Kirim Log SMS
Jadi, kami telah mengirim SMS dari portal web PlaySMS dan memeriksa status yang berbeda dari konsol MariaDB
SMS Terkirim tetapi belum diterima oleh Penerima:
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)
Setelah SMS diterima oleh HP tujuan dan mendapat Success DLR dari GSM Modem
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 masuk:
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)
Log SMSBOX:
Log keluar Portal PlaySMS:
Dari Telepon Penerima:
Referensi
- https://www.kannel.org/download/kannel-userguide-snapshot/userguide.html