http://devppp.blogspot.ru/2013/02/sms-kannel-ubuntu-1204-amd64-oracle-11g.html
Создание системного пользователя
addgroup kannel
useradd -G kannel -d /dev/null -s /bin/false -c "Kannel" kannel
Подготовим систему к конфигурированию
Создадим каталоги:
mkdir /etc/kannel
mkdir /var/log/kannel
mkdir /var/spool/kannel
Изменяем владельца каталогов на kannel:
chown -R kannel:kannel /etc/kannel
chown -R kannel:kannel /var/log/kannel
chown -R kannel:kannel /var/spool/kannel
Настройка кофнигурации box-ов
Корневая конфигурация из файла /etc/kannel/kannel.conf
group = core
admin-port = 13000
admin-password = bar
wapbox-port = 13002
smsbox-port = 13010
wdp-interface-name = "*"
log-file = "/var/log/kannel/kannel.log"
log-level = 3
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1;10.61.88.*"
admin-deny-ip = "*.*.*.*"
admin-allow-ip = "127.0.0.1;10.61.88.*"
access-log = "/var/log/kannel/access.log"
dlr-storage = oracle
store-type = file
store-location = "/var/spool/kannel"group = wapbox
bearerbox-host = localhost
log-file = "/var/log/kannel/wapbox.log"
log-level = 3
syslog-level = nonegroup = smsbox
bearerbox-host = localhost
bearerbox-port = 13007
sendsms-port = 13013
sendsms-chars = "0123456789+"
log-file = "/var/log/kannel/smsbox.log"
log-level = 3
mo-recode=true
access-log = "/var/log/kannel/smsbox.access.log"
smsbox-id = SMS_Kannel_Servergroup = smsbox-route
smsbox-id = sqlbox
smsc-id = "SMS_Box"group = sendsms-user
username = test
password = test
user-allow-ip = "127.0.0.1;10.61.88.*"
max-messages = 30group = smsc
smsc = smpp
smsc-id = "SMS_Box"
allowed-smsc-id = "SMS_Box"
host = 10.20.30.40
port = 1100
transceiver-mode = true
system-type = smpp
validityperiod = 1440
smsc-username = sender
smsc-password = sender_password
my-number = "0245"
keepalive = 25
msg-id-type = 3
interface-version = 34
source-addr-ton = 0
source-addr-npi = 1
source-addr-autodetect = no
dest-addr-ton = 1
dest-addr-npi = 1
address-range = ""
enquire-link-interval = 60
max-pending-submits = 10
reconnect-delay = 30
priority = 0group = oracle-connection
id = mydlr
tnsname = ORCL
username = kannel
password = qwe123group = dlr-db
id = mydlr
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 = boxcgroup=sms-service
keyword=default
accepted-smsc = "SMS_Box"
text=""
# max-messages = 0
# get-url = ".."
Содержимое файла /etc/kannel/sqlbox.conf
group = sqlbox
id = sqlbox-db
smsbox-id = sqlbox
global-sender = ""
bearerbox-host = localhost
bearerbox-port = 13010
smsbox-port = 13007
smsbox-port-ssl = false
sql-log-table = SENT_SMS
sql-insert-table = SEND_SMS
log-file = "/var/log/kannel/sqlbox.log"
log-level = 3# Oracle Connection
group = oracle-connection
id = sqlbox-db
username = kannel
password = kannel123
tnsname = ORCL
Скрипт автозапуска Kannel при старте системы (/etc/init.d/kannel):
#!/bin/sh
# Start/stop the Kannel boxes.### BEGIN INIT INFO
# Provides: kannel
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network $named
# Should-Stop: $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SMS and WAP gateway
# Description: Kannel is a gateway for connecting WAP phones to the
# Internet. It also works as an SMS gateway.
### END INIT INFO. /lib/lsb/init-functions
. /etc/profileBOXPATH=/opt/kannel/sbin
PIDFILES=/var/run/kannel
CONF=/etc/kannel/kannel.conf
SQL_CONF=/etc/kannel/sqlbox.conf#START_WAPBOX=1
START_SMSBOX=1
START_SQLBOX=1PATH=$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/bearerbox || exit 0if [ ! -d $PIDFILES ]
then
mkdir $PIDFILES
# chown kannel:root $PIDFILES
ficase "$1" in
start)
log_daemon_msg "Starting Kannel"
log_progress_msg "bearerbox"
start-stop-daemon --start --quiet
--background --make-pidfile
--pidfile $PIDFILES/kannel_bearerbox.pid
--exec $BOXPATH/bearerbox $CONF 2>&1>/dev/null &
sleep 3
test ! -z $START_SQLBOX && (
log_progress_msg "sqlbox"
start-stop-daemon --start --quiet
--background --make-pidfile
--pidfile $PIDFILES/kannel_sqlbox.pid
--exec $BOXPATH/sqlbox $SQL_CONF 2>&1>/dev/null &
)
sleep 3
test ! -z $START_SMSBOX && (
log_progress_msg "smsbox"
start-stop-daemon --start --quiet
--background --make-pidfile
--pidfile $PIDFILES/kannel_smsbox.pid
--exec $BOXPATH/smsbox $CONF 2>&1>/dev/null &
)
sleep 3
test ! -z $START_WAPBOX && (
log_progress_msg "wapbox"
start-stop-daemon --start --quiet
--background --make-pidfile
--pidfile $PIDFILES/kannel_wapbox.pid
--exec $BOXPATH/wapbox $CONF 2>&1>/dev/null &
)
log_end_msg 0
;;stop)
log_daemon_msg "Stopping Kannel"
test ! -z $START_WAPBOX && (
log_progress_msg "wapbox"
start-stop-daemon --stop --quiet
--pidfile $PIDFILES/kannel_wapbox.pid
--exec $BOXPATH/run_kannel_box
)
test ! -z $START_SMSBOX && (
log_progress_msg "smsbox"
start-stop-daemon --stop --quiet
--pidfile $PIDFILES/kannel_smsbox.pid
--exec $BOXPATH/run_kannel_box
)
test ! -z $START_SQLBOX && (
log_progress_msg "sqlbox"
start-stop-daemon --stop --quiet
--pidfile $PIDFILES/kannel_sqlbox.pid
--exec $BOXPATH/run_kannel_box
)
log_progress_msg "bearerbox"
start-stop-daemon --stop --quiet
--pidfile $PIDFILES/kannel_bearerbox.pid
--exec $BOXPATH/run_kannel_box
log_end_msg 0
;;reload)
# We don't have support for this yet.
exit 1
;;restart|force-reload)
$0 stop
sleep 1
$0 start
;;status)
bins="bearerbox sqlbox smsbox wapbox"
for bin in $bins; do
bin_path="$PIDFILES/kannel_${bin}.pid"
if [ -f "$bin_path" ]; then
pid="$(cat $bin_path)"
else
pid="x"
fi
if [ `pidof $bin | grep "$pid" | wc -l` -ne 0 ] ; then
printf "%-9s %sn" "$bin" "running"
else
printf "%-9s %sn" "$bin" "not_running"
fi
done
;;*)
echo "Usage: $0 {start|stop|restart|force-reload}"
exit 1esac
exit 0
Выставим права на исполнение:
chmod a+x /etc/init.d/kannel
Включим автоматический запуск данного сценария на дефолтных уровнях инициализации:
update-rc.d kannel defaults
Кстати удаление из автостарта делается так:
update-rc.d -f kannel remove
Настройка php и apache2 для работы с Oracle
apt-get install apache2 php5 libapache2-mod-php5
Специальные расширения для php не потребуются, работа с SMS-сервером реализована на уровне сокета.
Создание пользователя и таблицы для него
Подключимся к базе данных:
sqlplus /nolog
conn / as sysdba
CREATE USER kannel IDENTIFIED BY qwe123;
GRANT CONNECT TO kannel;
Сброс пароля:
alter user kannel identified by qwe123;
Создание таблицы в пределах схемы пользователя kannel.
CREATE TABLE kannel.dlr (
smsc varchar2(40),
ts varchar2(40),
destination varchar2(40),
source varchar2(40),
service varchar2(40),
url varchar2(255),
mask number(10),
status number(10)
);
Выдадим полные права на таблицу:
GRANT all on kannel.dlr TO kannel;
Если всё хорошо то выполни запрос из под пользователя kannel в sqlplus мы должны увидеть:
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
DLR
SQL> select table_name, column_name from USER_TAB_COLUMNS;
TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------
DLR STATUS
DLR MASK
DLR URL
DLR SERVICE
DLR SOURCE
DLR DESTINATION
DLR TS
DLR SMSC
8 rows selected.
SQL>
Исходники на PHP, которые работают с базой
Пример URL для отправки SMS:
http://192.168.1.2:13013/cgi-bin/sendsms?username=sender&password=sender_password&from=send-test&to=+79281112233&text=text
Коды возврата:
Ошибка Описание0: Accepted for delivery Сообщение принято на обработку операторами связи. 3: Queued for later delivery Сообщение принято и поставлено в очередь на отправку (varies) Ошибка при формировании запроса. Проверьте запрос. Temporal failure, try again later. Сервер перегружен, попробуйте запрос позже.
Теперь простая web-форма пример:
Файл /etc/kannel/www/send.php:
<?php
$host = 'localhost';
$port = '13013';$username = 'sender';
$password = 'sender_password';
$from = 'test-sms';$phone = $_GET['phone'];
$text = $_GET['text'];$url = "GET /cgi-bin/sendsms?username=".$username."&password=".$password."&from=".$from."&to=".$phone."&text=".urlencode($text)."&charset=utf8 HTTP/1.1rnrn";
$fp = fsockopen($host,$port);if($fp) {
# fputs($fp,$url);
fwrite($fp, $url);
while (!feof($fp)) {
echo "<span style='color: green;'>".fgets($fp, 128)."</span>";
}
fclose($fp);
} else {
echo "<span style='color: red;'>Error</span>";
}
?>
Содержимое файла /etc/kannel/www/form.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://yandex.st/jquery/1.6.0/jquery.min.js"></script>
</head>
<body>
<script>
function send_sms() {
$('#result').html('');
$.get(
'send.php',{text:$('#text').val(),phone:$('#phone').val()},
function(data){$('#result').html(data);}
);
}
</script>
<table>
<tr>
<td>Телефон:</td>
<td><input style='width: 200px;' type='text' id='phone'></td>
</tr><tr>
<td>Текст</td>
<td><textarea style='width: 200px;' id='text'></textarea></td>
</tr><tr>
<td></td>
<td><input id='send_sms' type='button' value='Send' OnClick='send_sms()'></td>
</tr>
</table>
<div id='result'></div>
</body>
</html>
Теперь создадим символические ссылки в корне web-сервера:
ln -s /etc/kannel/www/send.php /var/www/
ln -s /etc/kannel/www/form.html /var/www/