支持数据库动态管理sip账户
安装数据库驱动:
yum install -y unixODBC-devel mysql-connector-odbc
配置数据库连接
vi /etc/odbc.ini
配置数据库连接如下,注意红色配置,如果安装的是驱动5.x版本就是5a
[call_center]
Description=MySQL realtime database
Driver=/usr/lib64/libmyodbc8a.so
SERVER = 47.92.83.149
PORT =3308
DATABASE = call_center
OPTION =67108864
CHARSET = UTF8
USER = root
PASSWORD = 123456
测试驱动是否配置成功
isql -v freeswitch
数据库管理账户
vi /user/local/freeswitch/conf /autoload_configs/lua.conf.xml
# 在适当的位置添加以下:
<param name="xml-handler-script" value="gen_dir_user_xml.lua"/>
<param name="xml-handler-bindings" value="directory"/>
在freeswitch安装目录下(/usr/local/freeswitch/scripts)创建生成账户lua脚本如下
freeswitch.consoleLog("notice", "Debug from gen_dir_user_xml.lua, provided params:\n" .. params:serialize() .. "\n")
local req_domain = params:getHeader("domain")
local req_key = params:getHeader("key")
local req_user = params:getHeader("user")
assert (req_domain and req_key and req_user,
"This example script only supports generating directory xml for a single user !\n")
local dbh = freeswitch.Dbh("odbc://call_center:root:123456")
if dbh:connected() == false then
freeswitch.consoleLog("notice", "gen_dir_user_xml.lua cannot connect to database" .. dsn .. "\n")
return
end
local my_query = string.format("select * from tb_sip_account where status = 0 and account_code ='%s' limit 1", req_user)
assert (dbh:query(my_query, function(u)
XML_STRING =
[[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
<section name="directory">
<domain name="]] .. req_domain .. [[">
<user id="]] .. req_user .. [[">
<params>
<param name="password" value="]] .. u.password .. [["/>
<param name="dial-string" value="{sip_invite_domain=${dialed_domain},presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"/>
</params>
<variables>
<variable name="user_context" value="]] .. u.user_context .. [["/>
<variable name="toll_allow" value="domestic,international,local"/>
<variable name="accountcode" value="]] .. req_user .. [["/>
<variable name="effective_caller_id_name" value="Extension ]] .. req_user .. [["/>
<variable name="effective_caller_id_number" value="]] .. req_user .. [["/>
<variable name="outbound_caller_id_name" value=""/>
<variable name="outbound_caller_id_number" value=""/>
<variable name="callgroup" value="techsupport"/>
</variables>
</user>
</domain>
</section>
</document>]]
freeswitch.consoleLog("notice", "Debug from gen_dir_user_xml.lua, generated XML:\n" .. XML_STRING .. "\n")
end))
编辑 /user/local/freeswitch/conf/directory/default.xml
删除如下类容
<group name="default">
<users>
<X-PRE-PROCESS cmd="include" data="default/*.xml"/>
</users>
</group>