默认情况下,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:
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,即可生效。