您的位置:首页 > 科技 > IT业 > 设计师培训计划方案_东莞网站优化中易_今天热搜前十名_网络推广和网站推广平台

设计师培训计划方案_东莞网站优化中易_今天热搜前十名_网络推广和网站推广平台

2024/9/24 20:08:47 来源:https://blog.csdn.net/jia198810/article/details/142435799  浏览:    关键词:设计师培训计划方案_东莞网站优化中易_今天热搜前十名_网络推广和网站推广平台
设计师培训计划方案_东莞网站优化中易_今天热搜前十名_网络推广和网站推广平台

FreeSWITCH 简单图形化界面29 - 使用mod_xml_curl 动态获取配置、用户、网关数据

  • FreeSWITCH GUI界面预览
  • 安装FreeSWITCH GUI先看使用手册
  • 1、简介
  • 2、安装mod_xml_curl模块
  • 3、配置mod_xml_curl模块
  • 3、编写API接口
  • 4、测试一下
  • 5、其他注意的地方


FreeSWITCH GUI界面预览

http://myfs.f3322.net:8020/
用户名:admin,密码:admin

FreeSWITCH界面安装参考:https://blog.csdn.net/jia198810/article/details/137820796

安装FreeSWITCH GUI先看使用手册

先看使用手册,先看使用手册,先看使用手册。

这里是手册,这里是手册,这里是手册,
这里是手册,这里是手册,这里是手册,
这里是手册,这里是手册,这里是手册,
这里是手册,这里是手册,这里是手册,

1、简介

在FreeSWITCH的架构中,大部分配置都是通过XML文件来定义的。传统的配置方式是直接编辑这些XML文件。然而,借助于mod_xml_curl模块,我们可以实现配置的动态加载。这意味着配置文件可以通过API接口来获取。

mod_xml_curl模块是FreeSWITCH的一个扩展,它允许系统动态地从远程服务器获取配置信息,而不是依赖静态的XML配置文件。这种灵活性可以带来许多好处,包括但不限于多实例管理、集中式配置管理以及动态配置生成。

使用mod_xml_curl模块,您可以实现以下几种典型用途:

  • 在无需维护多个服务器配置的情况下运行多个FreeSWITCH实例;
  • 中央化管理配置,避免使用复杂的shell脚本来同步配置;
  • 从连接到数据库的Web应用程序动态填充配置;
  • 提供一种简便的方法来自动化部署FreeSWITCH配置,例如在托管的VoIP平台上。

FreeSWITCH的所有配置文件都集中存储在一个主配置文件/usr/local/freeswitch/conf/freeswitch.xml中。这个主配置文件使用include指令,不仅包含各个模块的配置,还涵盖了呼叫路由规则、聊天计划、用户目录信息以及语言设置等关键配置。

<!-- /usr/local/freeswitch/conf/freeswitch.xml 主配置文件内容-->
<?xml version="1.0"?>
<document type="freeswitch/xml"><!-- 全局变量 --><X-PRE-PROCESS cmd="include" data="vars.xml"/><!-- 各个模块的配置文件 --><section name="configuration" description="Various Configuration"><X-PRE-PROCESS cmd="include" data="autoload_configs/*.xml"/></section><!-- 呼叫规则配置文件 --><section name="dialplan" description="Regex/XML Dialplan"><X-PRE-PROCESS cmd="include" data="dialplan/*.xml"/></section><!-- 聊天计划配置文件 --><section name="chatplan" description="Regex/XML Chatplan"><X-PRE-PROCESS cmd="include" data="chatplan/*.xml"/></section><!-- 用户目录(分机号、gateway)配置文件 --><section name="directory" description="User Directory"><X-PRE-PROCESS cmd="include" data="directory/*.xml"/></section><!-- 语言管理 --><section name="languages" description="Language Management"><X-PRE-PROCESS cmd="include" data="lang/en/*.xml"/><X-PRE-PROCESS cmd="include" data="lang/zh/*.xml"/></section>
</document>

我们可以使用mod_xml_curl模块,通过http访问API接口,按照此文件的格式,分别获取各个模块的配置、用户目录配置、呼叫规则配置。

2、安装mod_xml_curl模块

# 进入freeswitch源码主目录
cd /usr/local/src/freeswitch
# 单独编译安装mod_xml_curl
make mod_xml_curl-install
# 修改modules.conf,自动加载mod_xml_curl
cd /usr/local/freeswitch/conf/autoload_configs
vim modules.conf.xml # 把modules.conf里,mod_xml_curl前面的注释取消
# 尽量确保此模块首先加载,否则可能会导致加载顺序出错。
# 重新启动FreeSWITCH

3、配置mod_xml_curl模块

mod_xml_curl的配置文件路径是/usr/local/freeswitch/conf/autoload_configs/xml_curl.conf.xml,下面是一个典型的配置及注释。

./freeswitch/conf/autoload_configs/xml_curl.conf.xml<configuration name="xml_curl.conf" description="cURL XML Gateway"><bindings><!-- 请求example1.com的拨号计划配置,如果接收到有效响应,则不再继续请求example2.com。如果未接收到有效响应,则继续请求example2.com --><binding name="dialplan"><param name="gateway-url" value="http://example1.com:80/fsapi" bindings="dialplan"/></binding><!-- 如果example1.com返回无效或未找到的响应,则只在此情况下调用此备用配置。如果此网关也未能返回有效配置,则FreeSWITCH将从磁盘查找静态配置文件 --><binding name="dialplan backup"><param name="gateway-url" value="http://example2.com:80/fsapi" bindings="dialplan"/></binding><!-- 请求example1.com的用户目录配置,如果没有找到则恢复到磁盘 --><binding name="directory"><param name="gateway-url" value="http://example1:80/fsapi" bindings="directory"/></binding><!-- 请求example1.com的配置配置,如果没有找到则恢复到磁盘 --><binding name="configuration"><param name="gateway-url" value="http://example1:80/fsapi" bindings="configuration"/></binding><!-- 请求example1.com的语音短语配置,如果没有找到则恢复到磁盘 --><binding name="phrases"><param name="gateway-url" value="http://example1:80/fsapi" bindings="phrases"/></binding></bindings>
</configuration>

参考mod_xml_curl.conf的注释,我们配置一下如下:

<configuration name="xml_curl.conf" description="cURL XML Gateway"><bindings><!--通过http://127.0.0.1:9000/pbx/config接口,获取所有模块的配置文件,  也就是主配置文件freeswitch.xml里的,configuration部分。<section name="configuration" description="Various Configuration"><X-PRE-PROCESS cmd="include" data="autoload_configs/*.xml"/></section>--><binding name="all configs"><param name="gateway-url" value="http://127.0.0.1:9000/pbx/config" bindings="configuration"/><param name="timeout" value="10"/><param name="method" value="GET"/></binding><!--通过http://127.0.0.1:9000/pbx/directory接口,获取分机用户的配置文件,  也就是主配置文件freeswitch.xml里的,configuration部分。<section name="directory" description="User Directory"><X-PRE-PROCESS cmd="include" data="directory/*.xml"/></section>--><binding name="directory"><param name="gateway-url" value="http://127.0.0.1:9000/pbx/directory" bindings="directory"/><param name="timeout" value="10"/><param name="method" value="GET"/></binding><!--通过http://127.0.0.1:9000/pbx/dialplan接口,获取呼叫规则,  也就是主配置文件freeswitch.xml里的,configuration部分。<section name="dialplan" description="Regex/XML Dialplan"><X-PRE-PROCESS cmd="include" data="dialplan/*.xml"/></section>--><binding name="dialplan"><param name="gateway-url" value="http://127.0.0.1:9000/pbx/dialplan" bindings="dialplan"/><param name="timeout" value="10"/><param name="method" value="GET"/></binding></bindings>
</configuration>

其他binding选项,可参考:

名称描述示例
gateway-url绑定的URLhttp://127.0.0.1/pbx/config
gateway-credentialsURL的身份验证用户名和密码user:pass
auth-scheme使用的身份验证方案。支持的值为:basic, digest, NTLM, GSS-NEGOTIATE 或 “any” 用于自动检测basic
method是否使用GET或POST方法GET
timeoutHTTP请求的超时时间(秒)20
enable-cacert-check是否检查服务器的SSL证书以验证其是否由受信任的CA证书颁发(对于HTTPS推荐使用)true
enable-ssl-verifyhost是否检查服务器的SSL证书是否与URL的主机名匹配(对于HTTPS推荐使用)true
ssl-cacert-fileCA证书文件的路径。注意,此选项似乎是必需的,因为模块不会自动搜索系统CA证书。/etc/ssl/certs/ca-certificates.crt
ssl-cert-path客户端证书的路径/etc/ssl/certs/fs_client.crt
ssl-key-path客户端私钥的路径/etc/ssl/private/fs_client.key
ssl-key-password客户端私钥的密码mysecret
ssl-version要使用的SSL/TLS版本。支持的值为 “SSLv3” 或 “TLSv1”TLSv1
disable-100-continue禁用HTTP Expect头中的100 Continue选项,适用于不喜欢此选项的服务器true
cookie-file存储cookies的文件路径/var/run/freeswitch/fs.cookies
enable-post-var定义post参数
bind-local用于HTTP请求的网络接口名称,这可能会影响多宿主服务器上的源地址/路由eth1

3、编写API接口

简单编写api接口,返回数据,示例如下:

from flask import Flask, request, Responseapp = Flask(__name__)@app.route('/pbx/config', methods=['GET'])
def get_configuration():# 这里返回各个模块的配置信息,相关value可以从数据库获取其他数据源获取# xml_response = """<document type="freeswitch/xml"><section name="configuration" description="all configs"><!-- 生成switch.conf.xml文件 --><configuration name="post_load_switch.conf" description="Core Configuration"><settings><param name="rtp-start-port" value="10000"/><param name="rtp-end-port" value="11000"/><param name="max-sessions" value="1000"/><param name="sessions-per-second" value="100"/><param name="switchname" value="Myfs"/></settings></configuration><!-- 生成acl.conf.xml文件 --><configuration name="acl.conf" description="Network Lists"><network-lists><!--  预定义:所有IP地址  --><list name="all.auto" default="allow"> </list><!--  内网  --><list name="LocalNet" default="allow"><node host="192.168.1.0" mask="255.255.255.0" type="allow"/></list></network-lists></configuration><!-- 参考模块配置文件,动态生成其他配置文件即可 --><!-- 生成sofia.conf --><!-- 生成odbc_cdr.conf --><!-- 生成db.conf --><!-- 生成ivr.conf --><!-- 生成callcenter.conf--><!-- 生成voicemail.conf--><!-- 生成nibblebill.conf--><!-- 生成acl.conf--><!-- 生成conference.conf--><!-- 生成freetdm.conf--><!-- 生成unimrcp.conf--><!-- 生成distributor.conf.xml-->......</section></document>"""return Response(xml_response, mimetype='text/xml')@app.route('/pbx/directory', methods=['GET'])
def get_directory():# 这里返回分机用户目录信息,相关value可以从数据库获取其他数据源获取xml_response = """<document type="freeswitch/xml"><section name="directory" description="User Directory"><domain name="$${domain}"><params><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})}"/></params><groups><group name="默认部门"><users><!-- 分机1001--><user id="1001" cacheable="1800000"><params><param name="password" value="1001"/><param name="allow-empty-password" value="false"/><param name="sip-forbid-register" value="false"/></params><variables><variable name="user_context" value="默认权限"/><variable name="video_bandwidth" data="2mb"/><variable name="_jitterbuffer" data="0"/><variable name="tx_vol" data="0"/><variable name="rx_vol" data="0"/><variable name="call_timeout" data="60"/><variable name="sched_hangup" data="7200"/><variable name="limit_max" data="1"/><variable name="_absolute_codec_string" data=""/><variable name="media_processing" data="default"/><variable name="zrtp_secure_media" data="false"/><variable name="sip_secure_media" data="false"/><variable name="effective_caller_id_name" value="1001"/><variable name="outbound_caller_id_name" value="1001"/><variable name="effective_caller_id_number" value="1001"/><variable name="outbound_caller_id_number" value="1001"/><variable name="callgroup" value="1"/><variable name="limit_max" value="1"/><variable name="minimum-session-expires" value="120"/><variable name="sip-force-expires" value="1800"/><variable name="sip-expires-max-deviation" value="600"/><variable name="nibble_account" value="1001"/></variables></user><!-- 分机1002--><user id="1002" cacheable="1800000"><params><param name="password" value="1002"/><param name="allow-empty-password" value="false"/><param name="sip-forbid-register" value="false"/></params><variables><variable name="user_context" value="默认权限"/><variable name="video_bandwidth" data="2mb"/><variable name="_jitterbuffer" data="0"/><variable name="tx_vol" data="0"/><variable name="rx_vol" data="0"/><variable name="call_timeout" data="60"/><variable name="sched_hangup" data="7200"/><variable name="limit_max" data="1"/><variable name="_absolute_codec_string" data=""/><variable name="media_processing" data="default"/><variable name="zrtp_secure_media" data="false"/><variable name="sip_secure_media" data="false"/><variable name="effective_caller_id_name" value="1002"/><variable name="outbound_caller_id_name" value="1002"/><variable name="effective_caller_id_number" value="1002"/><variable name="outbound_caller_id_number" value="1002"/><variable name="callgroup" value="1"/><variable name="limit_max" value="1"/><variable name="minimum-session-expires" value="120"/><variable name="sip-force-expires" value="1800"/><variable name="sip-expires-max-deviation" value="600"/><variable name="nibble_account" value="1002"/></variables></user></users></group></groups></domain></section></document>"""return Response(xml_response, mimetype='text/xml')@app.route('/pbx/dialplan', methods=['GET'])
def get_dialplan():# 这里返回拨号计划信息,相关value可以从数据库获取其他数据源获取xml_response = """<document type="freeswitch/xml"><section name="dialplan" description="Regex/XML Dialplan"><context name="default"><extension name="11113-播放音乐号码"><condition expression="^(11113)$" field="destination_number"><action application="answer"/><action application="playback" data="$${sounds_dir}/sound/fenghuang.wav"/><action application="hangup"/></condition></extension></context></section></document>"""return Response(xml_response, mimetype='text/xml')if __name__ == '__main__':app.run(host='127.0.0.1', port=9000)

4、测试一下

先启动接口,在启动FreeSWITCH,测试一下。

如果先启动FreeSWITCH,FreeSWITCH的mod_xml_curl获取失败,还是读取的本地文件。

5、其他注意的地方

  • mod_xml_curl 从接口获取的数据大小有限制,超过限制,FreeSWITCH会报错。
    可以修改源码里的XML_CURL_MAX_BYTES的值,重新编译该模块。如下图:
    在这里插入图片描述

  • 如果分机数量巨大,接口无需返回所有分机的配置文件,返回该分机的配置文件即可,这样可以减少数据的大小。
    mod_xml_curl在访问API接口时,会传递很多参数,找到传递分机号的参数,从而生成该分机号的配置文件。(分机登录时,都会请求接口,从获取的分机目录xml中,验证用户名和密码是否正确)

  • FreeSWITCH官方文档https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_xml_curl_1049001/

祝君好运,国庆快乐

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com