freeswitch和Mysql

ubuntu安装odbc及(mysql驱动)

一、安装odbc

apt-get install unixodbc

如果需要用到编译的头文件之类的

apt-get install unixodbc-dev

二、安装mysql驱动

apt-get install libmyodbc

多数可能出现这个报错:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package libmyodbc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'libmyodbc' has no installation candidate

三、手动下载安装驱动

驱动下载地址:https://dev.mysql.com/downloads/connector/odbc/

选择合适的版本和驱动

解压后,将库文件拷贝到合适的目录。

四、配置mysql驱动信息

文件:/etc/odbcinst.ini

[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc5a.so    //步骤3拷贝的路径
Setup=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc5S.so
FileUsage=1

五、配置需要访问的数据库信息

文件:/etc/odbc.ini

[freeswitch]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc5a.so3 SERVER = localhost
PORT = 3306
DATABASE = freeswitch
OPTION = 67108864               //这个配置是支持多线程?对于freeswitch访问来说很重要!
USER = root
PASSWORD = password

六、测试驱动

isql -v freeswitch  //先去数据库里创建一个表freeswitch

如果一切正常,能进入mysql后台。

反之,根据提示完善系统。

安装FreeSwitch

生成makefile

./configure --enable-core-odbc-support 

编译 安装

make && make install  (sudo make install)

安装成功的标志

+---------- FreeSWITCH install Complete ----------+
 + FreeSWITCH has been successfully installed.     +
 +                                                 +
 +       Install sounds:                           +
 +       (uhd-sounds includes hd-sounds, sounds)   +
 +       (hd-sounds includes sounds)               +
 +       ------------------------------------      +
 +                make cd-sounds-install           +
 +                make cd-moh-install              +
 +                                                 +
 +                make uhd-sounds-install          +
 +                make uhd-moh-install             +
 +                                                 +
 +                make hd-sounds-install           +
 +                make hd-moh-install              +
 +                                                 +
 +                make sounds-install              +
 +                make moh-install                 +
 +                                                 +
 +       Install non english sounds:               +
 +       replace XX with language                  +
 +       (ru : Russian)                            +
 +       (fr : French)                             +
 +       ------------------------------------      +
 +                make cd-sounds-XX-install        +
 +                make uhd-sounds-XX-install       +
 +                make hd-sounds-XX-install        +
 +                make sounds-XX-install           +
 +                                                 +
 +       Upgrade to latest:                        +
 +       ----------------------------------        +
 +                make current                     +
 +                                                 +
 +       Rebuild all:                              +
 +       ----------------------------------        +
 +                make sure                        +
 +                                                 +
 +       Install/Re-install default config:        +
 +       ----------------------------------        +
 +                make samples                     +
 +                                                 +
 +                                                 +
 +       Additional resources:                     +
 +       ----------------------------------        +
 +       https://www.freeswitch.org                +
 +       https://freeswitch.org/confluence         +
 +       https://freeswitch.org/jira               +
 +       http://lists.freeswitch.org               +
 +                                                 +
 +       irc.freenode.net / #freeswitch            +
 +                                                 +
 +       Register For ClueCon:                     +
 +       ----------------------------------        +
 +       https://www.cluecon.com                   +
 +                                                 +
 +-------------------------------------------------+
View Code

默认安装目录:/usr/local/freeswitch/

FreeSWITCH使用mysql存储用户 

原文地址:https://my.oschina.net/stache/blog/1552046

二、创建数据库

#创建用户表

#创建用户表
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user` varchar(10) DEFAULT NULL,
  `password` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;

#插入两个用户
insert into user (user,password) values('8001','123456')
insert into user (user,password) values('8002','123456')

三、将用户验证转接到lua脚本

1、将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" />

2、让lua脚本接管用户注册验证,这里调用的脚本是freeswitch/script/gen_dir_user_xml.lua内容如下,默认无该脚本,需自行创建

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")

freeswitch.consoleLog("NOTICE","start connect DB...\r\n");

local dbh = freeswitch.Dbh("freeswitch","root","123456");
assert(dbh:connected());
dbh:query("select password from user where user="..req_user,function(row)
        freeswitch.consoleLog("NOTICE","DB select password="..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");

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

freeswitch.consoleLog("NOTICE", "debug from gen_dir_user_xml.lua, generated XML:\n" .. XML_STRING .. "\n");

3、修改freeswitch/conf/directory/default.xml中的一部分内容,使得通过xml验证用户的功能失效,这样lua才能真正接管用户注册,删除的内容如下:

<group name="default">
    <users>
      <X-PRE-PROCESS cmd="include" data="default/*.xml"/>
    </users>
 </group>

四、测试

使用SIP软电话(zoiper、eyeBeam等)来测试8001、或8002是否能正常登陆,可登陆即为配置成功

运行freeswitch

freeswitch  -c -nonat

 

 

 

 

posted @ 2019-07-08 11:09  逐梦客!  阅读(1056)  评论(0)    收藏  举报