1,在freeswitch conf 修改,使用user.lua 去做用户管理
autoload_configs/lua.conf.xml: <param name="xml-handler-script" value="user.lua" />
autoload_configs/lua.conf.xml- <param name="xml-handler-bindings" value="directory" />
2,删掉directory/default.xml 里面的内容,(也许不需要)
删除的内容如下:
<group name="default">
<users>
<X-PRE-PROCESS cmd="include" data="default/*.xml"/>
</users>
</group>
3, 安装odbc & 验证
yum install unixODBC -y
/etc/odbc.ini
修改之后,执行 isql -v freeswitch
如果出现
isql -v freeswitch
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
则代表你的unixodbc配置成功了
4.
请把aaaa,bbbb 替换你的database的用户名和密码,这里的freeswitch对应odbc的freeswitch数据库
freeswitch.consoleLog("NOTICE","lua take the users...\n");
local req_domain = params:getHeader("domain")
local req_key = params:getHeader("key")
local req_user = params:getHeader("user")
local req_password = params:getHeader("pass")
local dbh = freeswitch.Dbh("freeswitch","aaaa","bbbb");
local my_query = string.format("select password from userinfo where username='%s' limit 1", req_user)
freeswitch.consoleLog("NOTICE","start connect DB...\r\n");
assert(dbh:connected());
freeswitch.consoleLog("notice", "the query string is:"..my_query)
dbh:query(my_query,function(row)
freeswitch.consoleLog("NOTICE",string.format("%s\n",row.password))
req_password=string.format("%s",row.password)
end);
dbh:release();
freeswitch.consoleLog("NOTICE","info:"..req_domain.."--"..req_key.."--"..req_user.."--"..req_password.."\n");
--assert (req_domain and req_key and req_user,
--"This example script only supports generating directory xml for a single user !\n")
if req_domain ~= nil and req_key~=nil and req_user~=nil then
XML_STRING =
[[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
<section name="directory">
<domain name="]]..req_domain..[[">
<params>
<param name="dial-string"
value="{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"/>
</params>
<groups>
<group name="default">
<users>
<user id="]] ..req_user..[[">
<params>
<param name="password" value="]]..req_password..[["/>
<param name="vm-password" value="]]..req_password..[["/>
</params>
<variables>
<variable name="toll_allow" value="domestic,international,local"/>
<variable name="accountcode" value="]] ..req_user..[["/>
<variable name="user_context" value="default"/>
<variable name="directory-visible" value="true"/>
<variable name="directory-exten-visible" value="true"/>
<variable name="limit_max" value="15"/>
<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="${outbound_caller_name}"/>
<variable name="outbound_caller_id_number" value="${outbound_caller_id}"/>
<variable name="callgroup" value="techsupport"/>
</variables>
</user>
</users>
</group>
</groups>
</domain>
</section>
</document>]]
else
XML_STRING =
[[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
<section name="directory">
</section>
</document>]]
end
-- comment the following line for production:
freeswitch.consoleLog("notice", "Debug from gen_dir_user_xml.lua, generated XML:\n" .. XML_STRING .. "\n");
5,创建数据库数据
在freeswitch中添加表格userinfo和用户数据进去:
CREATE TABLE userinfo (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(10) DEFAULT NULL,
`password` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;
insert into userinfo (username, password) values('test1', '1234');
insert into userinfo (username, password) values('test2', '12345');
6,可以在eyeBeam中注册验证
参考文档:
https://linyu19872008.iteye.com/blog/1736641
https://blog.csdn.net/thrill008/article/details/78413260
|
请发表评论