opensips.cfg
9.66 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
####### Global Parameters #########
log_level=3
log_stderror=no
log_facility=LOG_LOCAL0
children=6
/* uncomment the following lines to enable debugging */
#debug_mode=yes
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on revers DNS on IPs */
auto_aliases=no
listen=udp:172.31.1.130:5060 # CUSTOMIZE ME
####### Modules Section ########
#set module path
mpath="/usr/local/lib64/opensips/modules"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
modparam("rr", "append_fromtag", 1)
#### MAX ForWarD module
loadmodule "maxfwd.so"
#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"
#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
#modparam("usrloc", "db_mode", 0)
#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)
#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module */
modparam("acc", "detect_direction", 0)
loadmodule "proto_udp.so"
####################################################
#loadmodule "nathelper.so"
#modparam("nathelper","natping_interval", 15)
#modparam("nathelper", "received_avp", "$avp(received)")
#loadmodule "nat_traversal.so"
loadmodule "db_postgres.so"
loadmodule "avpops.so"
modparam("avpops", "db_url", "postgres://opensips:opensips@172.31.1.130/opensips")
loadmodule "dialog.so"
#modparam("dialog", "db_mode", 1)
#modparam("dialog", "db_url", "postgres://opensips:opensips@172.31.1.130/opensips")
modparam("dialog", "hash_size", 32768)
#modparam("dialog", "hash_size", 16384)
modparam("dialog", "log_profile_hash_size", 20)
modparam("dialog", "default_timeout", 3600)
#loadmodule "dispatcher.so"
#modparam("dispatcher", "db_url", "postgres://opensips:opensips@172.31.1.130/opensips")
#modparam("dispatcher", "ds_ping_method", "OPTIONS")
#modparam("dispatcher", "ds_ping_interval", 5)
#modparam("dispatcher", "ds_probing_threshhold", 2)
#modparam("dispatcher", "ds_probing_mode", 0)
#modparam("dispatcher", "ds_probing_mode", 1)
loadmodule "drouting.so"
modparam("drouting", "db_url", "postgres://opensips:opensips@172.31.1.130/opensips")
modparam("drouting", "use_domain", 0)
#modparam("drouting", "default_group", 1)
loadmodule "load_balancer.so"
modparam("load_balancer", "db_url", "postgres://opensips:opensips@172.31.1.130/opensips")
#loadmodule "cachedb_local.so"
#modparam("cachedb_local", "cachedb_url", "local://")
#modparam("cachedb_local", "cache_collections", "default=9")
#modparam("cachedb_local", "cache_clean_period", 1200)
####################################################
# main request routing logic
route{
xlog("L_INFO", "main route start|rm:$rm|du:$du|ru:$ru|fu:$fu|si:$si|sp:$sp|\n");
# kill any requests that we do not handle
if (!is_method("INVITE|ACK|BYE|CANCEL|REFER|OPTIONS|INFO")) {
sl_send_reply("405","Method Not Allowed");
exit;
}
if (!mf_process_maxfwd_header("10")) {
send_reply("483","Too Many Hops");
exit;
}
if (is_method("OPTIONS") && is_myself("$rd")) {
sl_send_reply("200","NAT Ping");
exit;
}
if (!has_totag()) {
record_route();
} else {
xlog("L_INFO", "has to tag|rs:$rs|rm:$rm|du:$du|ru:$ru|fu:$fu|si:$si|sp:$sp|\n");
loose_route();
if (!t_relay()) {
sl_reply_error();
}
exit;
}
if (is_method("INVITE")) {
if (lb_is_destination("$si", "$sp", "6")) {
xlog("L_INFO", "rm:$rm|originated from vos sources $si \n");
#测试
route(cti);
route(verto);
} else {
xlog("L_INFO", "rm:$rm|originated from cti freeswitch sources $si \n");
if ($(ru{uri.user}) =~ '^r4\S{11}$') {
route(kxjl);
} else if ($(ru{uri.user}) =~ '^r2\S{11}$') {
route(lingban);
} else if ($(ru{uri.user}) =~ '^r5\S{11}$') {
route(jths);
} else if ($(ru{uri.user}) =~ '^[01]\S{10}$') {
route(vos);
} else if ($(ru{uri.user}) =~ '^(2\S{9})$') {
route(verto);
} else {
xlog("L_ERR", "ERROR|ru:$ru|destnation invalid\n");
send_reply("481","destnation invalid");
exit;
}
}
}
exit;
}
route[kxjl] {
xlog("L_INFO", "ru:$ru|route to kxjl_AI\n");
if (lb_start("2","pstn")) {
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|route to kxjl_AI success\n");
exit;
}
#warning
exit;
}
route[jths] {
xlog("L_INFO", "ru:$ru|route to jths_AI\n");
if (lb_start("3","pstn")) {
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|route to jths_AI success\n");
exit;
}
#warning
exit;
}
route[lingban] {
xlog("L_INFO", "ru:$ru|route to lingban_AI\n");
if (lb_start("4","pstn")) {
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|route to lingban_AI success\n");
exit;
}
#warning
exit;
}
route[vos] {
xlog("L_INFO", "ru:$ru|route to VOS\n");
t_on_reply("vos_reply");
if (!is_present_hf("X-cti_tenantid")) {
#xlog("L_ERR", "ERROR:get tenantid from sip header X-cti_tenantid failed\n");
#send_reply("401","user Unauthorized");
#exit;
}
xlog("L_INFO", "get tenantid from sip header X-cti_tenantid:$(hdr(X-cti_tenantid))\n");
$var(tenantid) = $(hdr(X-cti_tenantid));
$var(tenantid) = "100001";
if (avp_db_query("select gwlist from tenant_gw where tenantid='$var(tenantid)'","$avp(gwlist)")) {
xlog("L_INFO", "use tenantid gwlist:$avp(gwlist) from table tenant_gw\n");
if (avp_db_query("select caller_number from gw_caller_number where gw_attr_id='$var(tenantid)' order by random() limit 1","$avp(caller_number)")) {
xlog("L_INFO", "use gw_id:$var(gw_id) get caller_number:$avp(caller_number) from table gw_caller_number\n");
if(is_present_hf("Remote-Party-ID")) {
$var(Remote-Party-ID) = $(hdr(Remote-Party-ID));
$var(remote_url) = $(var(Remote-Party-ID){nameaddr.uri});
$var(rp_remote_url) = "sip:" + $avp(caller_number) + "@" + $(var(remote_url){uri.domain});
if ($(var(remote_url){uri.port})) {
$var(rp_remote_url) = $var(rp_remote_url) + ":" + $(var(remote_url){uri.port});
}
$var(remote_pama) = $(var(Remote-Party-ID){nameaddr.params});
remove_hf("Remote-Party-ID");
append_hf("Remote-Party-ID: \"$avp(caller_number)\" <$var(rp_remote_url)>;$var(remote_pama)\r\n","X-FS-Support");
} else {
$var(rp_remote_url) = "sip:" + $avp(caller_number) + "@" + $(fu{uri.domain});
if ($(fu{uri.port})) {
$var(rp_remote_url) = $var(rp_remote_url) + ":" + $(fu{uri.port});
}
append_hf("Remote-Party-ID: \"$avp(caller_number)\" <$var(rp_remote_url)>;party=calling;screen=yes;privacy=off\r\n","X-FS-Support");
}
} else {
xlog("L_INFO", "ERROR:use gw_id get caller_number by random from table gw_caller_number failed\n");
exit;
}
} else {
xlog("L_INFO", "ERROR:use tenantid get caller_number:$avp(caller_number) gwlist:$avp(gwlist) from table tenant_attr\n");
send_reply("401","user Unauthorized");
exit;
}
if (route_to_gw("$avp(gwlist)","$var(gw_id)")) {
if(lb_start("$(var(gw_id){s.int})","pstn")){
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|fu:$fu|route to VOS success\n");
exit;
}
}
}
route[verto] {
xlog("L_INFO", "ru:$ru|route to webrtc freeswitch\n");
if (lb_start("10","pstn")) {
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|route to webrtc freeswitch success\n");
exit;
}
#warning
exit;
}
route[cti] {
xlog("L_INFO", "ru:$ru|route to cti freeswitch\n");
if (lb_start("1","pstn")) {
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|route to freeswitch success\n");
exit;
}
#warning
exit;
}
onreply_route[vos_reply] {
xlog("L_INFO", "VOS return status:$rs onreply\n");
if (t_check_status("[56][0-9][0-9]") || (t_check_status("408") && t_local_replied("all"))) {
route(vos_next);
}
exit;
}
route[vos_next] {
xlog("L_INFO", "ru:$ru|vos next\n");
t_on_reply("vos_reply");
if (use_next_gw(,"$var(gw_next_id)")) {
if(lb_start("$(var(gw_next_id){s.int})","pstn")) {
t_relay();
xlog("L_INFO", "ru:$ru|du:$du|fu:$fu|route to next VOS success\n");
exit;
}
}
}