freeswitch的mod_xml_curl模块动态获取configuration
概述
freeswitch是一款简单好用的VOIP开源软交换平台。
mod_xml_curl模块支持从web服务获取xml配置,本文介绍如何动态获取acl配置。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.6.20
GCC:4.8.5
web服务
mod_xml_curl模块依赖于web服务,需要自己创建一个web接口并动态的返回xml配置。
下面是python3.10实现的一个简单的web服务接口函数,从基类“BaseHTTPRequestHandler”继承并实现简单的返回逻辑。
def fsDialplan(self):
length = int(self.headers['content-length'])
datas = self.rfile.read(length)
logging.info('/fs/dialplan request, data=%s' % urllib.parse.unquote(datas))
respcode = '''<document type="freeswitch/xml">
<section name="dialplan" description="dialplan-url">
<include>
<context name="public">
<extension name="test-url" continue="false">
<condition field="${acl(${network_addr} list_out)}" expression="true"/>
<condition field="destination_number" expression="^(\d+)$">
<action application="answer"/>
<action application="playback" data="/usr/local/freeswitch/sounds/dialplan-test-url.wav"/>
</condition>
</extension>
</context>
</include>
</section>
</document>
'''
self.send_response(200)
self.send_header('Content-Type', 'application;charset=utf-8')
self.end_headers()
self.wfile.write(respcode.encode('utf-8'))
return
def fsConfigAcl(self):
length = int(self.headers['content-length'])
datas = self.rfile.read(length)
# print('fsConfigAcl request, data=', datas.decode())
logging.info('/fs/config/acl request, data=%s' % urllib.parse.unquote(datas))
respcode = '''<document type="freeswitch/xml">
<section name="configuration" description="config-acl">
<configuration name="acl.conf" description="Network Lists">
<network-lists>
<list name="list_out" default="deny">
<node type="allow" cidr="10.55.55.138/32"/>
</list>
</network-lists>
</configuration>
</section>
</document>
'''
self.send_response(200)
self.send_header('Content-Type', 'application;charset=utf-8')
self.end_headers()
self.wfile.write(respcode.encode('utf-8'))
return
web服务响应消息格式注意事项,必须有“section”段,xml格式不能使用压缩格式,否则会解析错误。
fsDialplan函数的响应中增加了acl的条件判断。
fsConfigAcl函数响应添加“list_out”的acl规则。
配置
检查conf/autoload_configs/modules.conf.xml文件,mod_xml_curl模块要放在配置的顶部。
<load module="mod_console"/>
<load module="mod_logfile"/>
<load module="mod_xml_curl"/>
修改conf/autoload_configs/xml_curl.conf.xml文件。
<configuration name="xml_curl.conf" description="cURL XML Gateway">
<bindings>
<binding name="dialplan">
<param name="gateway-url" value="http://10.55.55.137:8080/fs/dialplan" bindings="dialplan"/>
</binding>
<binding name="configuration">
<param name="gateway-url" value="http://10.9.0.27:8080/fs/config-acl" bindings="configuration"/>
</binding>
</bindings>
</configuration>
测试
configuration动态配置需要刷新生效。
freeswitch@localhost.localdomain> reloadacl
+OK acl reloaded
2023-08-04 10:37:59.117939 [NOTICE] switch_utils.c:545 Adding 10.55.55.138/32 (allow) [] to list list_out
使用10011发起呼叫,日志如下。
2023-08-04 10:38:05.277908 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->13712345678 in context public
Dialplan: sofia/external/10011@10.55.55.138 parsing [public->test-url] continue=false
Dialplan: sofia/external/10011@10.55.55.138 Regex (PASS) [test-url] ${acl(${network_addr} list_out)}(true) =~ /true/ break=on-false
Dialplan: sofia/external/10011@10.55.55.138 Regex (PASS) [test-url] destination_number(13712345678) =~ /^(\d+)$/ break=on-false
Dialplan: sofia/external/10011@10.55.55.138 Action answer()
Dialplan: sofia/external/10011@10.55.55.138 Action playback(/usr/local/freeswitch/sounds/dialplan-test-url.wav)
呼叫结果符合预期。
总结
mod_xml_curl模块动态获取config数据,方便对批量的fs集中统一管理配置。
未解决问题。
configuration类型的配置数据动态刷新的边界在哪里,我们可以把哪些配置数据放在web服务统一管理。
如何解决web服务不可用的本地xml配置问题,本地xml配置与web动态配置不一致的问题。
空空如常
求真得真
freeswitch的mod_xml_curl模块动态获取configuration的更多相关文章
- 使用os模块动态获取目录或文件路径
在接口自动化测试框架中,我们的代码除了能在本地运行,也能在不在修改代码的前提下在其他的环境下能够运行,这样才能达到高复用性和低维护成本,我们在接口测试的模块调用中,会定义很多相关路径,而这些路径必须使 ...
- python 动态获取当前运行的类名和函数名的方法
一.使用内置方法和修饰器方法获取类名.函数名 python中获取函数名的情况分为内部.外部,从外部的情况好获取,使用指向函数的对象,然后用__name__属性 复制代码代码如下: def a():pa ...
- KTHREAD 线程调度 SDT TEB SEH shellcode中DLL模块机制动态获取 《寒江独钓》内核学习笔记(5)
目录 . 相关阅读材料 . <加密与解密3> . [经典文章翻译]A_Crash_Course_on_the_Depths_of_Win32_Structured_Exception_Ha ...
- java版gRPC实战之六:客户端动态获取服务端地址
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- map阶段动态获取CombineTextInputFormat各输入文件路径
老mr程序中map中conf的map.input.file参数只能获取获取CombineTextInputFormat的第一个输入文件,而新版mr程序则连第一个输入文件也无法获取,这是因为create ...
- Spring Security3实现,权限动态获取
Spring Security3实现,权限动态获取 原文 http://blog.csdn.net/yangwei19680827/article/details/9359113 主题 网络安全Sp ...
- 旧书重温:0day2【4】动态获取函数地址
通过以上3篇文章的学习,我们已经可以获取到kernel32.dll的地址了下一步 我们就是获取几个重要的函数 1.GetProcAddress 2.LoadLibrary 有了这两个函数很多函数都可以 ...
- echarts 柱状图和饼状图动态获取后台数据
运用echarts来实现图表 1.首先下载echarts包 http://echarts.baidu.com/echarts2/doc/example.html,在这里我下载的是 2.将echart ...
- Autofac 动态获取对象静态类获取对象
Autofac 从容器中获取对象 静态类或Service场景可以动态,可以直接动态获取对象 /// <summary> /// 从容器中获取对象 /// </summary> ...
- 使用vue-element-admin框架从后端动态获取菜单
1.前言 vue-element-admin是一个纯前端的框架,左侧菜单是根据路由生成的.实际开发中经常需要根据当前登陆人员的信息从后端获取菜单进行展示,本文将详细介绍如何实现该功能. 2.详解 ...
随机推荐
- 芯片SDC约束 -复制保存
https://www.cnblogs.com/pcc-uvm/p/16996456.html?share_token=9651df97-e94c-4653-bf71-0a0fd6ca415e& ...
- 浅谈SQL优化小技巧
回顾MySQL的执行过程,帮助介绍如何进行sql优化. (1)客户端发送一条查询语句到服务器: (2)服务器先查询缓存,如果命中缓存,则立即返回存储在缓存中的数据: (3)未命中缓存后,MySQL通过 ...
- [ARC161F] Everywhere is Sparser than Whole (Judge)
Problem Statement We define the density of a non-empty simple undirected graph as $\displaystyle\fra ...
- Spring Framework系统架构
- 文心一言 VS 讯飞星火 VS chatgpt (156)-- 算法导论12.3 3题
三.用go语言,对于给定的 n 个数的集合,可以通过先构造包含这些数据的一棵二叉搜索树(反复使用TREE-INSERT 逐个插入这些数),然后按中序遍历输出这些数的方法,来对它们排序.这个排序算法的最 ...
- Oracle参数文件spfile
spfile:server parameter file. spfile只能通过OEM(oracle enterprise manager)软件或者alter system命令进行修改. spfile ...
- 华企盾DSC忘记了数据库解锁密码
解决方法:登录数据库控制台,找到DSE所使用数据库默认名字"DSEDB",打开表"FileEncryptKey_TABLE",如下图所示: 第一行,自动生成 ...
- 数字孪生结合GIS会为智慧农业带来怎样的改变?
数字孪生是一种创新的技术,它通过将现实世界的物理实体与数字模型相结合,实现了实时.动态的仿真和预测.而地理信息系统(GIS)则是一种用于收集.管理.分析和展示地理数据的工具.当这两种技术相互融合时,将 ...
- HTML之CSS Animation 属性常用动画
引入下面的样式表后 -webkit-animation: tada 1s ease 0.3s infinite both; -webkit-animation: name duration timin ...
- 红日靶场5-wp
红日靶场5 环境搭建 win7 账密及域 leo@sun 123.com sun\Administrator dc123.com 双网卡模拟内外网 外网网卡:192.168.130.150 内网网卡: ...