概述
freeswitch是一款簡單好用的的VOIP開源軟交換平臺吭服。
在客戶的呼叫過程中,會遇到一些異常的號碼尸变,包括高投訴風險號碼义图、敏感號碼、特殊號碼等召烂。
在客戶呼叫流程中碱工,需要針對這些異常號碼做呼叫限制,最簡單直接的方式就是設置號碼黑名單。
環(huán)境
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接口
freeswitch@localhost.localdomain> 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"/>
創(chuàng)建文件“conf/blacklists/blocked.list”春弥,并保證fs有寫權限。
測試API
freeswitch@localhost.localdomain> blacklist check blocked 12345
false
freeswitch@localhost.localdomain> blacklist add blocked 12345
+OK
2022-12-09 14:37:54.549789 [INFO] mod_blacklist.c:228 Added [12345] to list [blocked]
freeswitch@localhost.localdomain>
freeswitch@localhost.localdomain> blacklist check blocked 12345
true
freeswitch@localhost.localdomain> 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>
發(fā)起測試呼叫电抚,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/10011@10.55.55.138 parsing [public->test_blacklist] continue=true
Dialplan: sofia/external/10011@10.55.55.138 Regex (PASS) [test_blacklist] ${blacklist(check blocked ${destination_number})}(true) =~ /^true$/ break=on-true
Dialplan: sofia/external/10011@10.55.55.138 Action hangup(CALL_REJECTED)
...
EXECUTE sofia/external/10011@10.55.55.138 hangup(CALL_REJECTED)
...
2022-12-09 14:58:55.049767 [DEBUG] mod_sofia.c:440 Channel sofia/external/10011@10.55.55.138 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/10011@10.55.55.138 Standard HANGUP, cause: CALL_REJECTED
總結
voip呼叫系統(tǒng)中惕稻,黑名單的需求很普遍,fs自帶的mod_blacklist基本可以滿足大部分場景的需求蝙叛。
空空如常
求真得真