概述
freeswitch是一款简单好用的的VOIP开源软交换平台。
在客户的呼叫过程中,会遇到一些异常的号码,包括高投诉风险号码、敏感号码、特殊号码等。
在客户呼叫流程中,需要针对这些异常号码做呼叫限制,最简单直接的方式就是设置号码黑名单。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.10.7
GCC:4.8.5
黑名单模块
fs自带的黑名单模块mod_blacklist,模块默认不编译安装,需要进入“src/mod/applications/mod_blacklist”目录,手动编译安装。
该模块设计的目标是作为工具模块,可以在dialplan或脚本中直接返回true或false。
模块对应的配置文件是“autoload_configs/blacklist.conf.xml”。
<configuration name="mod_blacklist.conf" description="Blacklist module">
<lists>
<list name="blocked" filename="/usr/local/freeswitch/blacklists/blocked.list"/>
</lists>
</configuration>
拨号计划示例
添加号码进黑名单
<extension name="blacklist_add" >
<condition field="destination_number" expression="^\*98(\d+)$" >
<action application="answer" />
<action application="set" data="fake=${blacklist(add blocked $1)}" />
<action application="playback" data="/usr/local/freeswitch/recordings/blk_item_saved.wav" />
<action application="event" data="${blacklist(save blocked)}" />
</condition>
</extension>
检查黑名单
<extension name="blacklist_check" >
<condition field="destination_number" expression="^\*97(\d+)$" >
<action application="answer" />
<action application="set" data="blacklist_result=${blacklist(check blocked $1)}" inline="true"/>
</condition>
<condition field="${blacklist_result}" expression="^true$" break="always" >
<action application="playback" data="/usr/local/freeswitch/recordings/blk_item_exists.wav" />
<anti-action application="playback" data="/usr/local/freeswitch/recordings/blk_not_found.wav"/>
</condition>
</extension>
删除黑名单
<extension name="blacklist_delete" >
<condition field="destination_number" expression="^\*99(\d+)$" >
<action application="answer" />
<action application="set" data="fake=${blacklist(del blocked $1)}" />
<action application="playback" data="/usr/local/freeswitch/recordings/blk_item_deleted.wav" />
<action application="event" data="${blacklist(save blocked)}" />
</condition>
</extension>
API接口
[email protected]> blacklist help
blacklist check <listname> <item>
blacklist add <listname> <item>
blacklist del <listname> <item>
blacklist save <listname>
blacklist reload
blacklist help
+OK
测试
修改“autoload_configs/modules.conf.xml”
<load module="mod_blacklist"/>
修改“autoload_configs/blacklist.conf.xml”
<list name="blocked" filename="$${conf_dir}/blacklists/blocked.list"/>
创建文件“conf/blacklists/blocked.list”,并保证fs有写权限。
测试API
[email protected]> blacklist check blocked 12345
false
[email protected]> blacklist add blocked 12345
+OK
2022-12-09 14:37:54.549789 [INFO] mod_blacklist.c:228 Added [12345] to list [blocked]
[email protected]> blacklist check blocked 12345
true
[email protected]> blacklist save blocked
2022-12-09 14:38:27.989788 [INFO] mod_blacklist.c:280 Saving blocked to ../conf-test//blacklists/blocked.list
2022-12-09 14:38:27.989788 [DEBUG] mod_blacklist.c:288 adding 12345 to the dump file
修改“dialplan/test.xml”
<extension name="test_blacklist" continue="true">
<condition field="${blacklist(check blocked ${destination_number})}" expression="^true$" break="on-true">
<action application="hangup" data="CALL_REJECTED"/>
</condition>
</extension>
发起测试呼叫,10010->12345
2022-12-09 14:58:55.049767 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->12345 in context public
Dialplan: sofia/external/[email protected] parsing [public->test_blacklist] continue=true
Dialplan: sofia/external/[email protected] Regex (PASS) [test_blacklist] ${blacklist(check blocked ${destination_number})}(true) =~ /^true$/ break=on-true
Dialplan: sofia/external/[email protected] Action hangup(CALL_REJECTED)
...
EXECUTE sofia/external/[email protected] hangup(CALL_REJECTED)
...
2022-12-09 14:58:55.049767 [DEBUG] mod_sofia.c:440 Channel sofia/external/[email protected] hanging up, cause: CALL_REJECTED
2022-12-09 14:58:55.049767 [DEBUG] mod_sofia.c:579 Responding to INVITE with: 603
2022-12-09 14:58:55.049767 [DEBUG] switch_core_state_machine.c:60 sofia/external/[email protected] Standard HANGUP, cause: CALL_REJECTED
总结
voip呼叫系统中,黑名单的需求很普遍,fs自带的mod_blacklist基本可以满足大部分场景的需求。
空空如常
求真得真
标签:号码,sofia,黑名单,blacklist,freeswitch,mod,blocked From: https://www.cnblogs.com/qiuzhendezhen/p/17086826.html