freeswitch用户整合(使用mysql数据库的用户表)

摘要:
Freeswitch是一个功能强大的voip服务器,可以提供语音和视频。完成这项任务需要三个步骤。配置unixodbc,将用户身份验证传输到Lua脚本,并修改拨号计划,以便所有号码都可以拨到开发环境:centos6.264位、freeswitch、linphone、mysql1。首先安装unixodbc-unixodbc,它是一个组件,允许您使用ODBC连接Unix/Linux系统中的数据库,就像mysql-connector-java-5.1-6-bin一样。jar语言。

freeswitch是一款强大的voip服务器,可以语音和视频。但是它默认是采用/directory文件夹下的xml来配置用户的,对于整合到现有系统或者使用数据库保存用户信息的系统都是非常不方便的,所以,本文主要描述一种方法,解决freeswitch用户整合的问题。


完成这一任务需要三步,配置unixodbc,将用户验证转接到lua脚本,修改拨号计划使得拨通所有号码


freeswitch用户整合(使用mysql数据库的用户表)第1张

开发环境:centos 6.2 64位,  freeswitch,  linphone,mysql


1  首先安装unixodbc

    unixODBC是一个可以让你在Unix/Linux系统下使用ODBC来连接数据库的组件,就像java中的mysql-connector-java-5.1.6-bin.jar一样,负责连接数据库的。


yum install unixODBC-devel.x86_64

yum install mysql-connector-odbc.x86_64


安装后修改两个文件:/etc/odbc.ini,/etc/odbcinst.ini


/etc/odbc.ini  配置要连接的数据库信息


[freeswitch]

Driver          = /usr/lib64/libmyodbc5.so

SERVER       = ip

PORT           = 3306

DATABASE    = database

USER            = user

PASSWORD   = password


/etc/odbcinst.ini 修改mysq的部分,将驱动包指向正确,这要根据你本身的包安装路径配置


# Example driver definitions


# Driver from the postgresql-odbc package

# Setup from the unixODBC package

[PostgreSQL]

Description     = ODBC for PostgreSQL

Driver          = /usr/lib/psqlodbc.so

Setup           = /usr/lib/libodbcpsqlS.so

Driver64        = /usr/lib64/psqlodbc.so

Setup64         = /usr/lib64/libodbcpsqlS.so

FileUsage       = 1



# Driver from the mysql-connector-odbc package

# Setup from the unixODBC package

[MySQL]

Description     = ODBC for MySQL

Driver          = /usr/lib64/libmyodbc5.so

Setup           = /usr/lib64/libodbcmyS.so

Driver64        = /usr/lib64/libmyodbc5.so

Setup64         = /usr/lib64/libodbcmyS.so

FileUsage       = 1



修改之后,执行  isql -v freeswitch
如果出现
[root@test etc]# isql -v freeswitch
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> 
则代表你的unixodbc配置成功了

2  修改用户注册部分,转接到lua脚本进行注册验证

修改freeswitch/conf/autoload_configs/lua.conf.xml


<configuration name="lua.conf" description="LUA Configuration">

  <settings>


    <!--

    Specify local directories that will be searched for LUA modules

    These entries will be pre-pended to the LUA_CPATH environment variable

    -->

    <!-- <param name="module-directory" value="/usr/lib/lua/5.1/?.so"/> -->

    <!-- <param name="module-directory" value="/usr/local/lib/lua/5.1/?.so"/> -->


    <!--

    Specify local directories that will be searched for LUA scripts

    These entries will be pre-pended to the LUA_PATH environment variable

    -->

    <!-- <param name="script-directory" value="/usr/local/lua/?.lua"/> -->

    <!-- <param name="script-directory" value="$${base_dir}/scripts/?.lua"/> -->


    <!--<param name="xml-handler-script" value="/dp.lua"/>-->

    <!--<param name="xml-handler-bindings" value="dialplan"/>-->

    <param name="xml-handler-script" value="gen_dir_user_xml.lua" />

    <param name="xml-handler-bindings" value="directory" />

    <!--

        The following options identifies a lua script that is launched

        at startup and may live forever in the background.

        You can define multiple lines, one for each script you

        need to run.

    -->

    <!--<param name="startup-script" value="startup_script_1.lua"/>-->

    <!--<param name="startup-script" value="startup_script_2.lua"/>-->

  </settings>

</configuration>

让lua脚本接管用户注册验证,这里默认调用的脚本是freeswitch/script/gen_dir_user_xml.lua
脚本内容如下:
freeswitch.consoleLog("NOTICE","lua take the users... ");
-- 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: " .. params:serialize() .. " ")

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","user","password");
freeswitch.consoleLog("NOTICE","start connect DB... ");
assert(dbh:connected());
dbh:query("select password from Users where id="..req_user,function(row)
        freeswitch.consoleLog("NOTICE",string.format("%s ",row.password))
        req_password=string.format("%s",row.password)
end);
dbh:release();

freeswitch.consoleLog("NOTICE","info:"..req_domain.."--"..req_key.."--"..req_user.."--"..req_password.." ");



--assert (req_domain and req_key and req_user,
--"This example script only supports generating directory xml for a single user ! ")
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: " .. XML_STRING .. " ");


修改freeswitch/conf/directory中的一部分内容,使得通过xml验证用户的功能失效,这样lua才能真正接管用户注册
删除的内容如下:
<group name="default">
        <users>
          <X-PRE-PROCESS cmd="include" data="default/*.xml"/>
        </users>
 </group>


3  修改拨号计划
修改freeswitch/conf/dialplan/default.xml
修改如下内容,好让所有的拨号通过以下的条件
 <extension name="Local_Extension">
       <!--<condition field="destination_number" expression="^(10[01][0-9])$">-->
       <condition field="destination_number" expression="^(.*)$">

完成以上步骤,就基本完成了用户整合的全部内容,但是要注意一点,第一步配置unixodbc之后,要重新编译下freeswitch的源码,即在/usr/local/src/freeswitch下执行 configure&&make install,然后重启freeswitch。
还有就是每次修改xml后都需要重新在freeswitch控制台或者fs_cli下执行reloadxml,使得修改生效,修改lua脚本,则不需要如上操作。

免责声明:文章转载自《freeswitch用户整合(使用mysql数据库的用户表)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇vue中时间控件绑定多个输入框MySQL 查询decimal字段去除自动补零下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C#连接MySQL数据库

本文章是建立在已经安装MySQL数据库的前提,默认安装在C:Program Files (x86)MySQL,建议在安装时选中Connector.NET 6.9的安装,里面有MySQL与C#连接的动态链接库。 帮助文档C:Program Files (x86)MySQLConnector.NET 6.9DocumentationConnectorNET.c...

Java项目命名规范

一、项目名称 最好用英文,所有单词全部用小写,如testjavaproject、studentmanagement等,当然也也可以用中文,如“学生管理系统”、”进销管理系统“等。 二、Java project中相关命名 1、包名:全部小写字母,最好用域名反过来写,不会冲突。如com.cnblogs.lionestking.myutil等。 2、类名:每个单...

XXE攻防总结

1、 前言与XML格式相同的web漏洞,比较广泛的共有xpath注入、xml注入、soap注入、XXE四种。2、 XML相关的介绍针对xml语言,要明白两个特性:合法性与合理性。所谓合法性,是指语法层面(比如xml标签严格区分大小写,xml文档必须有一个根元素等)。所谓的合理性是指xml文档要有意义就必须满足一定的约束要求。在xml技术里,可以编写一个文档...

YII 使用mysql语句查询

使用YII2.0提供的AR访问数据库时,功能限制较大,只好结合SQL语句如: GzhAd::findBySql('SELECT * FROM gongZhongHaoInfo where advertisementID > :start && advertisementID < :end', array(':start' =&g...

把Gitlab迁移到Docker容器里

把Gitlab迁移到Docker容器里 Apr 9, 2015. | By: 任怀林 公司的gitlab一直是运行在ovm的虚拟机里的,版本还是6.7.5。版本有点老了,最近在研究docker,于是想把gitlab迁移到docker container里去。发现真的有人已经做了gitlab的image了,真心赞。 1 规划 规划: 一个容器运行gitl...

mysql安装和遇到的问题处理

遇到需要在新系统上安装MySQL的事情,简单记录一下过程。 声明:最好的文档是官方文档,我也是看的官方文档,只是中间遇到点问题,记录一下出现的问题和处理方式。贴一些官方文档地址。 用tar包的安装方式:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html 用yum源等其他安装方式:...