freeswitch批量添加用户
默认情况下,freeswitch内置了1000-1019这20个用户,如果需要添加更多用户,可以按如下步骤操作:
一、复制用户文件
\FreeSWITCH\conf\directory\default 下有1000.xml ~ 1019.xml 这20个用户的配置文件,以1000.xml为例:
1 <include> 2 <user id="1000"> 3 <params> 4 <param name="password" value="$${default_password}"/> 5 <param name="vm-password" value="1000"/> 6 </params> 7 <variables> 8 <variable name="toll_allow" value="domestic,international,local"/> 9 <variable name="accountcode" value="1000"/> 10 <variable name="user_context" value="default"/> 11 <variable name="effective_caller_id_name" value="Extension 1000"/> 12 <variable name="effective_caller_id_number" value="1000"/> 13 <variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/> 14 <variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/> 15 <variable name="callgroup" value="techsupport"/> 16 </variables> 17 </user> 18 </include>
可以写一段代码,以1000.xml为模板,批量创建其它用户的xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CreateFreeswitchUser { public static void main(String[] args) throws IOException { String template = "D:\\soft\\FreeSWITCH\\conf\\directory\\default\\" ; String templateContent = read(template + "1000.xml" ); //创建99个用户 for ( int i = 1 ; i < 100 ; i++) { String newUser = "1" + StringUtils.leftPad(i + "" , 3 , '0' ); String newContent = templateContent.replaceAll( "1000" , newUser); String newFileName = template + newUser + ".xml" ; write(newFileName, newContent); System.out.println(newFileName + " done!" ); } } static String read(String fileName) throws IOException { File f = new File(fileName); if (!f.exists()) { return null ; } FileInputStream fs = new FileInputStream(f); String result = null ; byte [] b = new byte [fs.available()]; fs.read(b); fs.close(); result = new String(b); return result; } static void write(String fileName, String fileContent) throws IOException { File f = new File(fileName); if (f.exists()) { f.delete(); } FileOutputStream fs = new FileOutputStream(f); fs.write(fileContent.getBytes()); fs.flush(); fs.close(); } } |
二、调整\FreeSWITCH\conf\dialplan\default.xml
创建用户的xml后,freeswitch怎么知道加载这些新用户的xml呢?答案就在dialplan\default.xml这个文件里:
1 <extension name="Local_Extension"> 2 <!-- 这里可以修改正则范围,允许所有分机号--> 3 <condition field="destination_number" expression="^([0-9]\d+)$"> 4 5 <!-- ... --> 6 <action application="set" data="call_timeout=120"/> 7 <!-- ... --> 8 9 10 </condition> 11 </extension>
主要是改下正则表达式,允许所有数字。另外,默认还有一个N秒不接认为超时的配置,默认是30秒,如果有需要调整的,也可以一并修改。
三、调整\FreeSWITCH\conf\dialplan\public.xml
1 <extension name="public_extensions"> 2 <!-- 允许所有分机号 --> 3 <condition field="destination_number" expression="^([0-9]\d+)$"> 4 <action application="transfer" data="$1 XML default"/> 5 </condition> 6 </extension>
重启freeswitch,即可生效。
作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
分类:
09.Open Source
, 21.Others
标签:
freeswitch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· Open-Sora 2.0 重磅开源!
2011-05-17 Silverlight Telerik控件学习:带CheckBox复选框的树形TreeView控件
2011-05-17 "为帮助内容存储区指定的位置无效或者您无权访问该位置"解决方法
2010-05-17 解决JQuery中的ready函数冲突
2010-05-17 C#检测SqlServer中某张表是否存在