4 add_incoming_context() {
6 eval "local added=\${dialplan_incoming_${context}_added}"
7 if [ "${added}" != "1" ] ; then
8 append dialplan_extensions_incoming "${context}" " "
9 eval "dialplan_incoming_${context}_added=1"
14 # Add to incoming ringing
18 while [ ! -z "$rhs" ] ; do
21 add_incoming_context ${cur}
22 append dialplan_incoming_${cur} "$1/$2" "&"
23 [ "$nvar" == "$rhs" ] && break
28 # Add to internal extensions
30 logdebug 1 "Adding $1/$2 extension to $3"
31 (eval [ -z "\${dialplan_ext_$2}" ] )\
32 && append dialplan_exts "$3" " "
33 local lower=`echo $1|tr [A-Z] [a-z]`
34 eval "${lower}_last_extension=\"$3\""
35 append dialplan_ext_$3 $1/${2} "&"
38 check_append_local() {
39 local extension="${1}"
40 logdebug 3 "added local context for ${1}"
41 eval "local isadded=\"\${dialplan_add_local_${extension}-0}\""
42 if [ "$isadded" != "1" ] ; then
43 eval "dialplan_add_local_${extension}=1"
44 append dialplan_locals "$extension"
45 eval "dialplan_local_${1}_context=\"${2}\""
46 eval "dialplan_local_${1}_selfmailbox=\"${3}\""
47 eval "dialplan_local_${1}_mailbox=\"${4}\""
53 append_dialplan_locals(){
54 for i in ${dialplan_locals} ; do
56 for x in context selfmailbox mailbox ; do
57 eval "x_${x}=\${dialplan_local_${i}_${x}}"
59 local newcontext=local_${extension}
61 if check_add_context ${newcontext} ; then
62 # add_dialplan_voice ${newcontext} ${x_last_extension} ${x_last_mailbox}
63 # Make sure as much is matched as possible
64 #add_dialplan_goto ${newcontext} _[0-9#*+]. ${x_last_context}
65 # add_dialplan_include ${newcontext} ${x_last_context}
67 append_dialplan_context ${newcontext} "exten => _.,1,Set(CALLERID(num)=${extension})"
68 if [ ! -z "${x_mailbox}" ] ; then
69 [ "${x_selfmailbox}" = "yes" ] && append_dialplan_context ${newcontext} "exten => ${extension},2,VoiceMailMain(${x_mailbox})"
70 [ ! -z "${dialplan_voiceboxext}" ] && append_dialplan_context ${newcontext} "exten => ${dialplan_voiceboxext},2,VoiceMailMain(${x_mailbox})"
72 append_dialplan_context ${newcontext} "exten => _.,2,Goto(${x_context},\${EXTEN},1)"
79 check_add_sipitems() {
80 if [ "${sip_doregister}" == "1" ] ; then
81 local line="register => ${sip_last_username}@${sip_last_fromdomain}:${sip_last_secret}:${sip_last_username}@${sip_sectionname}"
82 case ${sip_last_registerextension} in
83 -) line="$line/${sip_last_username}" ;;
84 .*) line="$line/${sip_last_registerextension}" ;;
86 append sip_register "$line" "$N"
89 do_check_add_items sip
91 check_add_iaxitems() {
92 do_check_add_items iax
97 for i in type last_host last_context selfmailbox last_extension last_mailbox ; do
98 eval "x_${i}=\"\${${1}_${i}-}\""
101 if [ ! -z "${x_last_context}" ] ; then
102 if [ ! -z "${x_last_extension}" ] ; then
103 [ "${x_last_context}" = "-" ] && eval "x_last_context=\"\${${1}_opt_context}\""
104 check_append_local "${x_last_extension}" "${x_last_context}" "${x_selfmailbox}" "${x_last_mailbox}"
105 x_last_context=local_${x_last_extension}
107 if [ "${x_last_context}" != "-" ] ; then
108 append ${1}_sections "context=${x_last_context}" "$N"
110 if [ "${x_type}" != "user" -a -z "${x_last_host}" ] ; then
111 append ${1}_sections "host=dynamic" "$N"
115 for i in last_username last_fromdomain last_secret last_username \
116 sectionname last_fromuser last_context last_extension last_mailbox last_type last_host ; do
120 eval ${1}_selfmailbox=no
121 eval ${1}_last_registerextension=-
128 unload_sip() astcmd "unload chan_sip.so"
130 rtp_option_list="rtpstart rtpend rtpdtmftimeout rtcpinterval rtpchecksums"
131 # Validate RTP options
133 is_in_list $1 ${rtp_option_list}
136 # Validate sip options, depending on context.
137 valid_sipiax_option() {
179 writeprotect|static) return ${use_glob_iax} ;;
188 call-limit) return ${use_glob_sip} ;;
191 externip) return ${use_glob_sip} ;;
193 localnet) return ${use_glob_sip} ;;
195 deny) return ${use_user_sip} ;;
198 domain) return ${use_glob_sip} ;;
200 context) return ${use_glob} ;;
202 notifymimetype) return ${use_glob_sip} ;;
204 canreinvite) return ${use_glob} ;;
205 nat|allowoverlap|allowsubscribe|allowtransfer|\
206 videosupport) return ${use_glob_sip} ;;
210 useclientcode) return ${use_user_sip} ;;
212 dtmfmode) return ${use_glob_sip} ;;
213 type) return ${use_user} ;;
214 insecure|callingpres|\
215 progressinband) return ${use_user_sip} ;;
218 disallow) return ${use_glob_sip} ;;
220 register) return ${use_glob_sip} ;;
222 username|secret|md5secret|host|\
223 mailbox) return ${use_user} ;;
224 auth) return ${use_user_iax} ;;
225 callgroup|pickupgroup|language|accountcode|\
226 setvar|callerid|amaflags|subscribecontext|\
227 maxcallbitrate|rfc2833compensate|\
228 mailbox) return ${use_user_sip};;
229 template|fromdomain|regexten|fromuser|\
230 qualify|defaultip|sendrpid|\
231 outboundproxy) return ${use_peer_sip};;
232 extension) return 0;;
240 ast_enable_type sipgeneral
242 ast_enable_type target
245 sip_opt_bindaddr=0.0.0.0
246 sip_opt_context=default
247 sip_opt_maxexpirey=3600
248 sip_opt_defaultexpirey=3600
249 sip_opt_notifymimetype=text/plain
250 sip_opt_rtptimeout=60
251 sip_opt_rtpholdtimeout=300
252 config_get WAN_IP wan ipaddr
253 # TODO check why the above does not work all the time
254 if [ -z "${WAN_IP}" ] ; then
255 config_get WAN_IF wan ifname
256 WAN_IP=$(ifconfig ${WAN_IF} | grep "inet addr:" | sed 's/^.*inet addr:\([^ ]*\) .*$/\1/')
259 sip_opt_externip=${WAN_IP}
261 sip_opt_realm=asterisk
262 config_get LAN_MASK lan netmask
263 config_get LAN_IP lan ipaddr
264 LAN_NET=$(/bin/ipcalc.sh $LAN_IP $LAN_MASK | grep NETWORK | cut -d= -f2)
265 sip_opt_localnet=$LAN_NET/$LAN_MASK
267 # default to ulaw only
269 sip_opt_registertimeout=20
270 sip_opt_registerattempts=10
271 sip_opt_canreinvite=no
276 sip_list="port bindaddr context maxexpirey defaultexpirey notifymimetype \
277 rtptimeout rtpholdtimeout realm domain localnet externip"
281 append_dialplan_locals
283 file=${DEST_DIR}/sip.conf
284 get_checksum sip_conf $file
286 if [ -z "${sip_sections}" ] ; then
290 [ -z "${sip_opt_domain}" ] && sip_opt_domain=${sip_opt_realm}
292 echo "${asteriskuci_gen}[general]" > $file
293 for i in ${sip_list} ; do
294 eval value=\$sip_opt_$i
295 [ ! -z "$value" ] && ( echo "$i=$value" >> $file )
297 echo "disallow=all" >> $file
298 local rhs="${sip_opt_allow}"
299 if [ -z "$rhs" ] ; then
302 while [ ! -z "$rhs" ] ; do
306 echo "allow=${cur}" >> $file
307 [ "$nvar" == "$rhs" ] && break
311 echo "${N}${sip_register}${N}${N}${sip_sections}" >> $file
315 check_checksum "$sip_conf" "$file" || ast_sip_restart=$isempty
319 handle_sipgeneral() {
321 if valid_sipiax_option globalsip $1 $2 ; then
324 if [ -z "$2" ] ; then
331 append sip_opt_allow "$2" "," ;;
332 *) eval "sip_opt_$1=\"\$2\"" ;;
334 elif valid_rtp_option $1 $2 ; then
335 eval "rtp_opt_$1=\"\$2\""
337 logerror "Invalid SIP global option: $1"
344 append sip_sections [$1] "$N$N"
345 enable_module chan_sip
346 sip_sectionname=${1#sip_}
350 sip_last_doregister=-
353 logdebug 3 "SIP/${sip_sectionname}: '$1' '$2'"
356 append sip_sections "$1=$2" "$N"
359 if [ "$2" == "yes" ]; then
362 registerextension) eval sip_last_$1="$2";;
363 allow|allow_ITEM*) split_append sip_sections allow= "$2" "${N}" enable_format ;;
364 extension|extension_ITEM*) add_extension SIP ${sip_sectionname} "$2" ;;
365 context) sip_last_context="$2" ;;
366 selfmailbox) sip_selfmailbox="$2" ;;
367 incoming|incoming_ITEM*)
368 add_incoming SIP ${sip_sectionname} "$2" ;;
369 timeout|prefix|internationalprefix|alwaysinternational|countrycode)
370 eval "target_$1_SIP_${sectionname}=\"$2\""
372 allow_LENGTH|incoming_LENGTH|extension_LENGTH) ;;
374 eval sip_last_$1="$2"
375 if valid_sipiax_option ${sip_type}sip $1 $2 ; then
376 append sip_sections "$1=$2" "$N"
378 logerror "Invalid SIP option for ${sip_type}: $1"
389 rtp_opt_rtpstart=5000
391 rtp_opt_rtpchecksums=
392 rtp_opt_rtpdtmftimeout=
393 rtp_opt_rtcpinterval=5000
397 file=${DEST_DIR}/rtp.conf
398 get_checksum rtp_conf $file
400 if module_enabled chan_sip ; then
401 echo "${asteriskuci_gen}[general]" > $file
402 for i in $rtp_option_list ; do
403 eval "local val=\"\$rtp_opt_$i\""
404 if [ ! -z "$val" ] ; then
407 rtpdtmftimeout) lhs=dtmftimeout
409 echo "$lhs=$val" >> $file
417 check_checksum "$rtp_conf" "$file" || ast_rtp_restart=$isempty
419 reload_rtp() astcmd "rtp reload"
420 unload_rtp() astcmd "unload rtp"
429 ast_enable_type iaxgeneral
436 local file=$DEST_DIR/iax.conf
437 get_checksum iax_conf $file
439 if [ -z "${iax_sections}" ] ; then
443 echo "${asteriskuci_gen}${iax_general}$N$N${iax_sections}" > $file
445 check_checksum "$iax_conf" "$file" || ast_iax_restart=${isempty}
448 handle_iaxgeneral() {
449 iax_general="[general]"
453 allow|allow_ITEM*) split_append iax_general allow= "$2" "${N}" enable_format ;;
455 if valid_sipiax_option globaliax $1 $2 ; then
456 eval "iax_opt_$1=\"$2\""
457 append iax_general "$1=$2" "$N"
459 logerror "Invalid IAX global option: $1"
467 append iax_sections "[$1]" "$N$N"
469 iax_sectionname="${1#iax_}"
472 enable_module chan_iax2
477 append iax_sections "type=$2" "$N" ;;
480 split_append iax_sections allow= "$2" "${N}" enable_format ;;
482 logdebug 1 "Adding IAX extension $2 for $iax_sectionname"
483 eval [ -z "\${dialplan_ext_$2}" ] && dialplan_exts="${dialplan_exts} $2"
484 iax_last_extension="$2"
485 append dialplan_ext_$2 "IAX2/${iax_sectionname}" "&" ;;
486 extension) add_extension IAX ${iax_sectionname} "$2" ;;
488 eval iax_last_context="$2" ;;
490 eval iax_selfmailbox="$2" ;;
492 add_incoming IAX ${iax_sectionname} "$3" ;;
493 timeout|prefix|internationalprefix|alwaysinternational|countrycode)
494 eval "target_$1_IAX_${sectionname}=\"$2\"" ;;
496 eval iax_last_$1="$2"
497 if valid_sipiax_option ${iax_type}iax $1 $2 ; then
498 append iax_sections "$1=$2" "$N"
500 logerror "Invalid IAX option for ${iax_type}: $1"
510 unload_iax() astcmd "unload chan_iax2.so"
514 targettype=${1%[-_]*}
515 if [ ${targettype} == $1 ] ; then
516 logerror "No target type specified (SIP-$1 IAX-$1)"
519 targetname=${1#*[-_]}
522 [Ss][Ii][Pp]) handle_dialtarget SIP $targetname ;;
523 [Ii][Aa][Xx]) handle_dialtarget IAX $targetname ;;
524 *) logerror "Invalid target type specified: $targettype"
528 # Set up options sip/iax targets for outgoing sip/iax
529 handle_dialtarget() {
530 # Dialzone target option
533 logdebug 1 "Dialzone Target for ${areatype}/${areaname}"
536 timeout|prefix|internationalprefix|alwaysinternational|countrycode)
537 eval target_$1_${areatype}_${areaname}=$2
540 logerror "Invalid target for $areatype/$areaname: ${1}"
545 # vim: ts=2 sw=2 noet foldmethod=indent