在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
mac上让freeswitch使用mysql代替sqlite1.安装unixodbc:brew install unixodbc安装到/usr/local/Cellar/unixodbc/2.3.4/下面 2.安装mysql odbc driver去到mysql官网下载mac版mysql odbc driver点击打开链接 下载的mysql-connector-odbc-5.3.9-macos10.12-x86-64bit.dmg安装后位于/usr/local/mysql-connector-odbc-5.3.9-macos10.12-x86-64bit/ 3.配置ODBCcd bin/./myodbc-installer -d -a -n "MySQL ODBC 5.3 Driver" -t "DRIVER=/usr/local/lib/libmyodbc5a.so"生成或者更新 /Library/ODBC/odbcinst.ini ./myodbc-installer -s -c2 -a -n "freeswitch" -t "DRIVER=MySQL ODBC 5.3 ANSI Driver;SERVER=localhost;DATABASE=freeswitch;UID=myuser;PWD=mypassword;OPTION=67108864" 生成或者更新 /Library/ODBC/odbc.ini 将上述两步生成的odbc.ini odbcinst.ini拷贝到/usr/local/Celler/unixodbc/2.3.4/etc/下面(覆盖原来的两个文件) 启动mysql: mysqld_safe --skip-grant-tables 或者mysql.server restart 执行isql -v freeswitch 如果出现下面的显示说明odbc安装成功: 4.准备数据库以root身份登录mysql: mysql -u root -p然后创建一个用户lifeng,密码123456: create user [email protected]'%' identified by '123456'; 授权用户新创建的用户lifeng有权访问数据库里的各类资源: grant all privileges on *.* to [email protected]'%' identified by '123456'; flush privileges; 在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'); insert into ... 5.修改用户注册部分,转接到lua脚本进行注册验证修改freeswitch/conf/autoload_configs/lua.conf.xmlgen_dir_user_xml.lua内容如下: freeswitch.consoleLog("NOTICE","lua take the users...\n"); -- gen_dir_user_xml.lua -- example script for generating user directory XML -- comment the following line for production: --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") local req_password = params:getHeader("pass") local dbh = freeswitch.Dbh("freeswitch","lifeng","123456"); 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"); 如果在fs启动过程中出现下面错误(不停地循环): 用mysql客户端登录,通过下列的sql命令手动建立channels表 CREATE TABLE `channels` ( `uuid` varchar(256) DEFAULT NULL, `direction` varchar(32) DEFAULT NULL, `created` varchar(128) DEFAULT NULL, `created_epoch` int(11) DEFAULT NULL, `name` varchar(1024) DEFAULT NULL, `state` varchar(64) DEFAULT NULL, `cid_name` varchar(1024) DEFAULT NULL, `cid_num` varchar(256) DEFAULT NULL, `ip_addr` varchar(256) DEFAULT NULL, `dest` varchar(1024) DEFAULT NULL, `application` varchar(128) DEFAULT NULL, `application_data` varchar(4096) DEFAULT NULL, `dialplan` varchar(128) DEFAULT NULL, `context` varchar(128) DEFAULT NULL, `read_codec` varchar(128) DEFAULT NULL, `read_rate` varchar(32) DEFAULT NULL, `read_bit_rate` varchar(32) DEFAULT NULL, `write_codec` varchar(128) DEFAULT NULL, `write_rate` varchar(32) DEFAULT NULL, `write_bit_rate` varchar(32) DEFAULT NULL, `secure` varchar(64) DEFAULT NULL, `hostname` varchar(256) DEFAULT NULL, `presence_id` varchar(256) DEFAULT NULL, `presence_data` varchar(256) DEFAULT NULL, `accountcode` varchar(256) DEFAULT NULL, `callstate` varchar(64) DEFAULT NULL, `callee_name` varchar(1024) DEFAULT NULL, `callee_num` varchar(256) DEFAULT NULL, `callee_direction` varchar(5) DEFAULT NULL, `call_uuid` varchar(256) DEFAULT NULL, `sent_callee_name` varchar(1024) DEFAULT NULL, `sent_callee_num` varchar(256) DEFAULT NULL, `initial_cid_name` varchar(1024) DEFAULT NULL, `initial_cid_num` varchar(256) DEFAULT NULL, `initial_ip_addr` varchar(256) DEFAULT NULL, `initial_dest` varchar(1024) DEFAULT NULL, `initial_dialplan` varchar(128) DEFAULT NULL, `initial_context` varchar(128) DEFAULT NULL, KEY `channels1` (`hostname`), KEY `chidx1` (`hostname`), KEY `uuindex` (`uuid`,`hostname`), KEY `uuindex2` (`call_uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; (注:其实改fs源码更nice,不过我不会,所以只能手动这里改了,解决问题先) 修改freeswitch/conf/directory中的一部分内容,使得通过xml验证用户的功能失效,这样lua才能真正接管用户注册 注释掉的内容如下: 注意,上图中的注释必须是一行行的注释,否则可能会出现xml错误,具体原因还不明:( 至此,所有的修改和配置都完成了,最好我们重新configure, make & make install 一遍fs,configure的时候带上参数 --enable-core-odbc-support=true cd /usr/local/freeswitch/db/ rm * 运行freeswitch: freeswitch -c -nonat |
请发表评论