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.详解 ...
随机推荐
- SpringCore 完整学习教程1,入门级别
1. SpringApplication SpringApplication类提供了一种方便的方式来引导从main()方法启动的Spring应用程序.在很多情况下,你可以委托给静态的SpringApp ...
- [ABC246E] Bishop
Problem Statement We have an $N \times N$ chessboard. Let $(i, j)$ denote the square at the $i$-th r ...
- ZincSearch轻量级全文搜索引擎入门到
ZincSearch轻量级全文搜索引擎入门到 Zinc是一个用于对文档进行全文搜索的搜索引擎.它是开源的,内置在 Go 中.Zinc不是从头开始构建索引引擎,而是构建在 bluge 之上,这是一个出色 ...
- 花了1块钱体验一把最近很火的ChatGPT
前言 最近 OpenAI 发布了 ChatGPT,一经发布就在科技圈火得不行. ChatGPT是什么呢? 简单得说,ChatGPT,是一种基于对话的 AI 聊天工具.我们来看看ChatGPT自己得回答 ...
- react+antd选择框输入
react+antd选择框输入 const onSearch=(fn,value)=>{ if(value){//这个if无比重要 form.setFieldsValue({"Owne ...
- MySQL进阶篇:详解存储引擎特点
MySQL进阶篇:第一章_一.四_存储引擎特点_Memory & MySQL存储引擎的区别及特点 1.1 存储引擎特点 1.1.3 Memory 1). 介绍 Memory引擎的表数据时存储在 ...
- 技术实践丨PostgreSQL插件之pg_dirtyread "闪回查询"
摘要:Oracle数据库有时候不小心删除掉数据,想查询这些数据,或者恢复数据,就可以使用带有as of子句的select语句进行闪回查询. PG粉有福了,下面介绍一种类似"闪回查询" ...
- 云原生2.0时代下,DevOps实践如何才能更加高效敏捷?
当前全球的数字化浪潮逐步加深,云计算成为当今信息化发展的重要基础设施,云原生(Cloud Native)在数字化浪潮中的角色逐步提升,成为近几年云计算领域炙手可热的话题. 首先我们来看看一张图,看看云 ...
- 手把手带你通过API创建一个loT边缘应用
摘要:使用API Arts&API Explorer调用IoT边缘服务接口创建应用,了解边缘计算在物联网行业的应用. 本文分享自华为云社区<使用API Arts&API Expl ...
- U2Net基于ModelArts Notbook的仿真实验
摘要:U2Net是一个优秀的显著性目标检测算法,由Qin Xuebin等人发表在Pattern Recognition 2020期刊[Arxiv].U2Net名称的来源在于其网络结构由两层嵌套的Une ...