📜 ⬆️ ⬇️

Processing sms on a heap of identical gsm modems without violence against udev

Given:
There is an accounting department that works with a variety of commercial organizations. Banking web-clients send confirmation codes for a particular banking transaction in the form of sms. Same GSM modems are plugged into the USB hub of the Linux server. The smstools3 package is installed on the server for receiving and processing sms and the usb_modeswitch package for correctly defining modems using udev.

Task:
To organize reception of sms and their submission to accountants. Mark incoming sms name of the organization.

Problems:
Modems are Chinese, without individual serial numbers and it is not possible to distinguish them using udev rules. When you restart the server or rearrange a modem, these devices are renamed.

Decision.
')
1. Create a generator (/ usr / local / bin / smsdconfgen) of the configuration file (/etc/smsd.conf) for the smsd daemon:

#!/bin/sh #  -   USB       . num=`ls /dev/ttyUSB* | awk -F tty '{print $2}' | awk -F USB '{print $2}' | awk 'BEGIN { ORS = " " } { print }' | sed 's/.$//'` devlist=`ls /dev/ttyUSB* | awk -F tty '{print $2}' | awk 'BEGIN { ORS = "," } { print }' | sed 's/.$//'` #       selection () { echo "["USB$i"]" >>/etc/smsd.conf echo 'init = AT+CPMS="ME","ME","ME"' >>/etc/smsd.conf echo "device = /dev/ttyUSB"$i >>/etc/smsd.conf echo "baudrate = 115200" >>/etc/smsd.conf echo "incoming = yes" >>/etc/smsd.conf echo "memory_start = 1" >>/etc/smsd.conf echo "eventhandler = /usr/local/bin/sms2mail" >>/etc/smsd.conf echo >>/etc/smsd.conf } #    /etc/smsd.conf echo >/etc/smsd.conf #       sms  echo "devices = "$devlist >/etc/smsd.conf echo "outgoing = /var/spool/sms/outgoing" >>/etc/smsd.conf echo "checked = /var/spool/sms/checked" >>/etc/smsd.conf echo "incoming = /var/spool/sms/incoming" >>/etc/smsd.conf echo "receive_before_send = no" >>/etc/smsd.conf echo "incoming_utf8 = yes" >>/etc/smsd.conf echo >>/etc/smsd.conf #       for i in $num; do selection; done 

This script will register all terminals available in the USB system in the smsd config. For your convenience, you can make changes to the smsd init script (usually it is located in /etc/init.d) and set the start of the config generator before starting the smsd itself. This will save you from starting manually before restarting the daemon.

2. Create a script handler incoming SMS. It will scan each incoming SMS and determine whether the SMS is specific to the SIM through the IMSI code.

 #!/bin/bash #IMSI  . # - 250014712255725 # - 250014712342902 # - 250014712553982 # - 250014710661053 #$1  $2 -    smsd    status="$1" file="$2" #  IMSI     imsi=`head -12 $file | grep -e "IMSI: " | awk -F" " '{print $2}'` #   case "$1" in RECEIVED) if [ $imsi = 250014712255725 ]; then name="" fi if [ $imsi = 250014712342902 ]; then name="" fi if [ $imsi = 250014712553982 ]; then name="" fi if [ $imsi = 250014710661053 ]; then name="" fi head -12 $file | grep -e "^From: " -e "^Sent: " -e "^Received: " >> /tmp/sms.log #     UCS,   UTF-8 if grep "Alphabet: UCS2" $file >/dev/null; then echo "$name" >> /tmp/sms.log tail -n +13 $file | iconv -f UCS-2BE -t UTF-8 >> /tmp/sms.log tail -n +13 $file | iconv -f UCS-2BE -t UTF-8 | mutt -x -s "$name" x@mail.com else echo "$name" >> /tmp/sms.log tail -n +13 $file >> /tmp/sms.log tail -n +13 $file | mutt -x -s "$name" x@mail.com fi echo >> /tmp/sms.log echo >> /tmp/sms.log ;; esac 

From the script it is clear that each SMS is signed and sent to a specific mailbox. In addition, it gets into the log file /tmp/sms.log. What to do with sms is up to you, my accountants, besides sending to the post office, I broadcast the log file to the last five sms via a web page. To do this, it is enough to raise the web server and drop the index.php file like this into the site root:

  <title>SMS-</title> <meta http-equiv="refresh" content="5;url=index.php"> <meta charset="UTF-8"> <?php $output = shell_exec('tail -n 30 /tmp/sms.log'); echo "<pre>$output</pre>"; ?> 

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


All Articles