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

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

开发环境: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...\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","user","password");
freeswitch.consoleLog("NOTICE","start connect DB...\r\n");
assert(dbh:connected());
dbh:query("select password from Users where id="..req_user,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");
 
 
修改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脚本,则不需要如上操作。
 
来源:http://linyu19872008.iteye.com/blog/1736641

freeswitch用户整合(使用mysql数据库的用户表)的更多相关文章

  1. 通过批处理(bat)命令创建mysql数据库及用户等

    1.建立数据库文件:mysqlCreatDB.sql create database Mydb 2.为用户赋予权限文件:grantUser.sql grant select,insert,update ...

  2. MySQL 数据库赋予用户权限操作表

    MySQL清空数据库的操作:truncate table tablename; MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户  一.grant 普通数 ...

  3. MYSQL数据库、用户、表等基础构建

    MYSQL数据库.用户.表等基础构建: 1.->:创建数据库: 1.1. create schema [数据库名称] default character set utf8 collate utf ...

  4. Mysql数据库的用户和日志管理

    Mysql数据库的用户和日志管理 数据库的用户管理 1.mysql用户账号管理 用户账号 user@host user:账户名称 host:此账户可通过哪些客户端主机请求创建连接线程,可以是ip.主机 ...

  5. python实现用户登陆(sqlite数据库存储用户信息)

    python实现用户登陆(sqlite数据库存储用户信息) 目录 创建数据库 数据库管理 简单登陆 有些地方还未完善. 创建数据库 import sqlite3 #建一个数据库 def create_ ...

  6. php面试专题---mysql数据库分库分表

    php面试专题---mysql数据库分库分表 一.总结 一句话总结: 通过数据切分技术将一个大的MySQLServer切分成多个小的MySQLServer,既攻克了写入性能瓶颈问题,同一时候也再一次提 ...

  7. 4.mysql数据库创建,表中创建模具模板脚本,mysql_SQL99标准连接查询(恩,外部连接,全外连接,交叉连接)

     mysql数据库创建,表创建模等模板脚本 -- 用root用户登录系统,运行脚本 -- 创建数据库 create database mydb61 character set utf8 ; -- ...

  8. 利用navcat为mysql数据库单独的表赋权限及表结构同步

    为mysql数据库单独的表赋权限 场景:考勤系统需要拿OA数据库td_oa中的flow_run和flow_run_data表中的数据做考勤计算 考勤系统只需要读取这两张表的数据,所以只需要开通一个单独 ...

  9. MySQL数据库的库表迁移

    最近在研究MySQL数据库的库表迁移问题,主要分为两种情况,一种情况是迁移数据库的表的全部字段,另一种是迁移数据库的表的部分字段.前一种情况是直接使用mysqldump命令来实现,后一种情况则是采用数 ...

随机推荐

  1. 树莓派 3b 串口启用

    网上搜到的方法都没用,不知道是不是系统版本的原因.以下方法是试出来的... uname -aLinux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:5 ...

  2. java代码示例(4)

    /** * 需求分析:计算100以内的和,用while * @author chenyanlong * 日期:2017/10/14 */ package com.hp.test04; public c ...

  3. 聊一聊docker存储驱动

    目录 镜像的分层特性 容器读写层的工作原理 写时复制 用时配置 Docker存储驱动 AUFS OverlayFS Devicemapper 常用存储驱动对比 AUFS VS OverlayFS Ov ...

  4. nxlog windows安装部署

    nxlog 介绍 nxlog 是用 C 语言写的一个跨平台日志收集处理软件.其内部支持使用 Perl 正则和语法来进行数据结构化和逻辑判断操作.不过,其最常用的场景.是在 windows 服务器上,作 ...

  5. P4891 序列

    P4891 序列 题目描述 给定两个长度为 n 的序列 A 和 B,定义序列 \(C_i=\max\limits_{j=1}^i A_j\) 定义当前的价值是 $\prod\limits_{i=1}^ ...

  6. UVALive - 3266 Tian Ji -- The Horse Racing(贪心)

    题目链接 题意 两人赛马,每居获胜得200,平局无事发生,输了也输200.求最优的策略使赢的钱最多. 分析 排序,从最快的开始比,若比不过,则用最弱的消耗最强的.模拟即可. #include<i ...

  7. Spring第一个helloWorld

    Spring 简介: 轻量级:Spring是非侵入性的-基于Spring开发的应用中的对象可以不依赖于Spring的API 依赖注入(DI—dependdency injection.IOC) 面向切 ...

  8. linux4.10.8 内核移植(二)---初步裁剪、分区修改和文件系统

    一.初步裁剪 在内核根目录下 执行: make menuconfig 1.1 system type裁剪 选择 SAMSUNG S3C24XX SoCs Support 进入其中,这里是配置我们的单板 ...

  9. Redis 主从 keepalived高可用 实现 VIP 自动漂移

    Redis 多主写多从度 配置启动OK :直接配 keepalived  相关配置: redis 默认路径 :/usr/local/redis keepalived 默认路径 :/etc/keepal ...

  10. luogu P3191 [HNOI2007]紧急疏散EVACUATE

    传送门 qwq这题好大力 首先可以预处理出每个人到每个门前面那个格子的最早时间,然后答案如果比最小答案大的话也是合法的,所以可以二分最终答案.检查\(mid\)是否合法就考虑每个人要去哪个门才会合法, ...