Rexxer

Some tips for me and other

SMS-gate своими руками

Понадобилась отправка алертов на телефон.

Рассылку смс через почту операторы закрыли.

Самый недорогой смс-шлюз с ком-портом – около 500грн, либо искать телефон с кабелем и т.п.

Нашел в хозяйстве PCMCIA GSM-modem Sony Ericsson GC89 и переходник PCMCIA-PCI (100 + 70грн).

Вставил в имеющуюся машинку с FreeBSD 8.0, определилось как:

none1 at pci0:3:0:1:       class=0x070002 card=0x000318de chip=0x434414e4 rev=0x03 hdr=0x00
    vendor     = 'Broadcom Corporation'
    device     = 'EDGE/GPRS data and 802.11b/g combo cardbus [GC89]'
    class      = simple comms
    subclass   = UART
    bar   [10] = type I/O Port, range 32, base 0x1000, size 256, enabled

kernel: cardbus0: <simple comms, UART> at device 0.0 (no driver attached)

Порылся в инете – патчим:

add it string:
{ 0x14e4, 0x4344, 0xffff, 0, "Sony Ericsson GC89 PC Card", 0x10},
to file
sys/dev/uart/uart_bus_pci.c

пересобираем ядро: make buildkernel && make installkernel

получаем:

uart2: <16550 or compatible> port 0x1000-0x10ff irq 11 at device 0.0 on cardbus0

в девайсах появился cuau2

Проверяем отправку смс напрямую (не забыть вставить сим-карту :)):

коннектимся cu -l /dev/cuau2 -s 57600 (на скорости 115200 сыпался мусор – команды не вводились) b вводим команды:

AT+CFUN=1
AT
AT+CGREG=1
AT+CMGF=1
AT+CMGS=”+380501430001″
>test,CTRL+Z

смс прошла.

Для упрощения отправки смс поставил /usr/ports/comms/smstools3.

smsd.conf получился такой:

devices = GSM1
logfile = /var/log/smsd.log
loglevel = 5

[GSM1]
device = /dev/cuau2
baudrate = 57600
#incoming = yes
pin = ignore

Для отладки можно поставить логлевел в 7, для принятия и чтения смс – incoming=yes, пробовал инициализировать модем – были ошибки – поэтому init убрал совсем.

Кроме того, при отправке смс сыпало ошибками типа:

Cannot handle /var/spool/sms/outgoing/send_WJReV3: Access denied. Check the file and directory permissions.

Для фикса правим /usr/local/bin/sendsms, там было smsd_user=”smsd”. Меняем на smsd_user=”uucp”

Пробуем отправить смс:

sendsms 380501430001 ‘Test’

Работает!

Затем я настроил запуск скрипта на отправку с другой Freebsd машины по ssh, и тут меня ждал облом – сообщение создавалось от имени запускающего обычного юзера и снова сыпались ошибки с пермишшенами. После долгих мучений, изменил скрипт sendsms – добавил chmod 666 $TMPFILE:

chmod 666 $TMPFILE

chown $owner $TMPFILE

После этого смс стасли отправляться нормально с правами обычного пользователя.

Полезные ссылки:

http://www.lissyara.su/articles/freebsd/programms/smstools_3/

http://smstools3.kekekasvi.com/

P.S.: После перезагрузки модем не втыкал – прописал инит:

devices = GSM1
logfile = /var/log/smsd.log
loglevel = 5

[GSM1]
device = /dev/cuau2
baudrate = 57600
#rtscts = no
init = AT+CFUN=1
init2 = AT+CREG=1
incoming = yes
pin = ignore

Еще настроил обработку событий при получении смс – добавляется строка в конфиг:

devices = GSM1
logfile = /var/log/smsd.log
loglevel = 5
eventhandler = /usr/local/share/smstools/fwd2mail

[GSM1]
device = /dev/cuau2
baudrate = 57600
#rtscts = no
init = AT+CFUN=1
init2 = AT+CREG=1
incoming = yes
pin = ignore

Сам скрипт fwd2mail:

#!/bin/sh

if [ “$1” = “RECEIVED” ]; then
mail -s “SMS” youremail@domain.com < $2
fi

Smsd gives two or three arguments to the eventhandler. The first one is SENT, RECEIVED, FAILED, REPORT or CALL.

The second one is the SMS file filename. The third argument is the message id of the SENT message, it is only used if you sent a message successfully with status report enabled.

Следующим шагом будет управление чем-либо посредством смс.

Leave a Reply