首页 > 其他分享 >FreeSWITCH 使用 lua 脚本 接管 分机注册,鉴权等

FreeSWITCH 使用 lua 脚本 接管 分机注册,鉴权等

时间:2023-02-08 15:23:58浏览次数:39  
标签:xml .. -- 分机 req lua user FreeSWITCH

FreeSWITCH 使用 lua 脚本 接管 分机注册,鉴权等

1. 更改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="$${script_dir}/?.lua"/> -->
    <param name="script-directory" value="$${script_dir}/"/>
    <param name="script-directory" value="$${script_dir}/?.lua"/>
<!-- 接管分机注册 -->
    <param name="xml-handler-script" value="user_auth_xml.lua" />
    <param name="xml-handler-bindings" value="directory" />

    <!--<param name="xml-handler-bindings" value="dialplan"/>-->
    <!--
    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"/>-->

    <!--<hook event="CUSTOM" subclass="conference::maintenance" script="catch-event.lua"/>-->
  </settings>
</configuration>
复制代码

其中

<param name="xml-handler-script" value="user_auth_xml.lua" />
<param name="xml-handler-bindings" value="directory" />

 指定使用 user_auth_xml.lua 优先获取分机配置.

包括分机注册,拨打鉴权验证等获取分分机配置信息.

2. user_auth_xml.lua 脚本

复制代码
 1 -- user_auth_xml.lua
 2 -- example script for generating user directory XML
 3 -- comment the following line for production:
 4 --freeswitch.consoleLog("notice", "Debug from user_auth_xml.lua, provided params:\n" .. params:serialize() .. "\n")
 5 require ("config")
 6 
 7 local req_domain = params:getHeader("domain")
 8 local req_key    = params:getHeader("key")
 9 local req_user   = params:getHeader("user")
10 local req_password   = nil -- params:getHeader("pass")
11 freeswitch.consoleLog("NOTICE","lua take the key="..req_key..", user="..req_user..", domain="..req_domain.."\n");
12 
13 --[[
14 local dbh = freeswitch.Dbh("freeswitch","dbuser","dbpswd");
15 local my_query = string.format("select password from userinfo where username='%s' limit 1", req_user)
16 --freeswitch.consoleLog("NOTICE","start connect DB...\r\n");
17 assert(dbh:connected());
18 freeswitch.consoleLog("notice", "the query string is:"..my_query)
19 dbh:query(my_query,function(row)
20   --freeswitch.consoleLog("NOTICE",string.format("%s\n",row.password))
21   req_password=string.format("%s",row.password)
22 end);
23 dbh:release();
24 freeswitch.consoleLog("NOTICE","info:"..req_domain.."--"..req_key.."--"..req_user.."--"..req_password.."\n");
25 ]]--
26 for line in io.lines("scripts/users.txt") do
27   --print(line)
28   if line~=nil then
29     local arr=Split(line,' ')
30     --print( arr[1].." "..arr[2])
31     if arr[1] == req_user and arr[2]~=nil then
32       req_password=arr[2]
33       break
34     end
35   end
36 end
37 --assert (req_domain and req_key and req_user,
38 --"This example script only supports generating directory xml for a single user !\n")
39 if req_domain ~= nil and req_key=="id" and req_user~=nil and req_password~=nil  then
40     XML_STRING =
41     [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
42     <document type="freeswitch/xml">
43       <section name="directory">
44         <domain name="]]..req_domain..[[">
45           <params>
46             <param name="dial-string" value="{^^:sip_invite_domain=${dialed_domain}:presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(*/${dialed_user}@${dialed_domain})},${verto_contact(${dialed_user}@${dialed_domain})}"/>
47             <!-- These are required for Verto to function properly -->
48             <param name="jsonrpc-allowed-methods" value="verto"/>
49             <param name="jsonrpc-allowed-event-channels" value="demo,conference,presence"/>
50           </params>
51           <groups>
52             <group name="default">
53               <users>
54                 <user id="]] ..req_user..[[">
55                   <params>
56                     <param name="password" value="]]..req_password..[["/>
57                     <param name="vm-password" value="]]..req_password..[["/>
58                   </params>
59                   <variables>
60                     <variable name="toll_allow" value="domestic,international,local"/>
61                     <variable name="accountcode" value="]] ..req_user..[["/>
62                     <variable name="user_context" value="default"/>
63                     <variable name="directory-visible" value="true"/>
64                     <variable name="directory-exten-visible" value="true"/>
65                     <variable name="limit_max" value="15"/>
66                     <variable name="effective_caller_id_name" value="Extension ]] ..req_user..[["/>
67                     <variable name="effective_caller_id_number" value="]] ..req_user..[["/>
68                     <variable name="callgroup" value="chezai"/>
69                   </variables>
70                 </user>
71               </users>
72             </group>
73           </groups>
74         </domain>
75       </section>
76     </document>]]
77 else
78     XML_STRING = nil
79     --[[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
80     <document type="freeswitch/xml">
81       <section name="directory">
82       </section>
83     </document>]]
84 end
85 
86 -- comment the following line for production:
87 -- freeswitch.consoleLog("notice", "Debug from gen_dir_user_xml.lua, generated XML:\n" .. XML_STRING .. "\n");
复制代码

 

如果要使用数据库, 自行取消注释并修改.

当前使用的是 从 scripts/users.txt 文件中 读取 分机号码 和 密码(空格分隔,每行一个分机).

 

scripts/users.txt 文件中没有配置 分机号和密码时,将会自动到xml 配置中去查找.

即: 此 lua 脚本 优先于 xml 配置文件执行, XML_STRING 变量为 nil 时就去查找默认的xml配置.

 当前使用的是 1.10.3 版本测试的, 较低的版本可能要执行第三步,如下

3. 更改 conf/directory/default.xml 使 其配置的分机配置失效 

红色 框里的 注释或者删掉

我用 1.10.3 版本, 不删也可以, 其他版本未测试, 更高的版本 应该也不用删掉的

不删的话, lua 脚本中 XML_STRING 变量为 nil 时就去查找默认的xml配置

标签:xml,..,--,分机,req,lua,user,FreeSWITCH
From: https://www.cnblogs.com/kn-zheng/p/17101887.html

相关文章

  • freeswitch智能语音开发之ASR
    ASR(AutomaticSpeechRecognition)自动语音识别技术是一种将人的语音转换为文本的技术。一、freeswitch如何使用asrfreeswitch提供两个app功能detect_speech和play_and_de......
  • 配置Freeswitch(mod_unimrcp)与百度Mrcp Server实现实时语音识别(ASR)
    前面我们已经搭建好了百度MrcpServer服务器,接下来我们将Freeswitch与unimrcpserver两者连接起来,配置百度unimrcpserver的文章大家去这里看一下:搭建百度MrcpServer与Fr......
  • freeSwitch入门
    简单使用windows安装FreeSwitch自己的电脑系统是xubuntu22.10UbuntuKineticKudu(developmentbranch)版本,linx安装FreeSwitch需要自己编译安装,里面安装编......
  • Freeswitch 对接 unimrcpserver ASR调用
    freeswitch部署的系统版本:Centos6.9x64unimrcp部署版本:RedHat6.4x86(32)**对接前提:freeswitch已经编译并且安装了mod_unimrcp模块unimrcp已经部署好**如果以......
  • FreeSwitch Hangup-Cause电话挂断原因速查
    Freeswitch官网太慢了,经常还打不开,把电话挂断原因大全复制一份到这里,方便日常查看ITU-TQ.850CodeSIPEquiv.EnumerationCauseDescription0 UNSPECIFIEDUnspec......
  • freeswitch笔记(9)-esl outbound中如何放音采集按键?
    关于这个功能,esl-client上给出的源码示例极具误导性,根本跑不起来,见: https://github.com/esl-client/esl-client/blob/master/src/test/java/OutboundTest.java 正确姿......
  • freeswitch笔记(8)-esl outbound 填坑笔记
    github上的esl-client已经N年未更新了,上面有一堆bug,记录一下: 一、内存泄露org.freeswitch.esl.client.transport.message.EslFrameDecoder这个类,使用了netty的ByteBuf......
  • freeswitch笔记(7)-放音控制
    来电时,播放音乐是一个很常用的功能,下面是一些相关的命令:一、单次播放playback1originateuser/1000 &playback(ivr/8000/ivr-welcome_to_freeswitch.wav)......
  • freeswitch笔记(6)-会议功能简介
    电话会议是一个常用功能,freeswitch当然支持,下面是基本用法:一、发起会议1conference test bgdialuser/1004上面的命令表示,发起1个名为test的会话,......
  • freeswitch笔记(5)-小型呼叫中心设计思路
    这一篇用esl实战一把,利用eslclient来实现一个小型呼叫中心的原型,先看看下面这张图: 企业通常会对外公布一个400之类的服务电话,当用户拨打这个电话时,实际上背后是一堆客......