contrib/package: change luci-app-asterisk dependency to asterisk14-xip-core
[project/luci.git] / contrib / asterisk-xip / files / uci / voicemailconf
1 #!/bin/sh
2
3 # Voicemail.conf
4
5 ast_add_conf voicemail
6
7 init_voicemailconf() {
8 ast_add_reload voicemail
9
10 ast_enable_type voicegeneral
11 ast_enable_type voicemail
12 ast_enable_type voicezone
13 ast_enable_type dialplanvoice
14
15 voice_format="wav49|gsm|wav"
16 voice_serveremail=
17 voice_attach=no
18 voice_skipms=3000
19 voice_maxsilence=10
20 voice_silencethreshold=128
21 voice_maxlogins=3
22 voice_emaildateformat="%A, %B %d, %Y at %r"
23 voice_sendvoicemail=no
24 voice_maxmsg=100
25 voice_maxmessage=180
26 voice_minmessage=3
27 voice_maxgreet=60
28 return 0
29 }
30
31 voicegeneral_list="format serveremail attach skipms maxsilence silencethreshold maxlogins emaildateformat sendvoicemail maxmsg maxmessage minmessage maxgreet"
32 voicegeneral_ext_list=""
33
34 valid_voicemail(){
35 is_in_list $1 ${voicegeneral_list} ${voicegeneral_ext_list}
36 return $?
37 }
38
39 voicebox_list="context number password name email pager"
40
41 voicebox_listopt="tz attach serveremail saycid dialout callback review operator envelope sayduration saydurationm"
42
43 valid_voicebox() {
44 is_in_list $1 ${voicebox_list} ${voicebox_listopt}
45 return $?
46 }
47
48 check_add_voicebox() {
49 if [ ! -z ${voicebox_number} ] ; then
50 [ -z "${voicebox_context}" ] && voicebox_context=default
51 logdebug 1 "Adding Voicebox ${voicebox_number} in ${voicebox_context}"
52 # Construct the voicebox line
53 local line="$voicebox_number => "
54 [ -z ${voicebox_tz} ] && voicebox_tz=homeloc
55 [ -z ${voicebox_name} ] && voicebox_name=OpenWRT
56
57 for i in password name email pager ; do
58 eval "local value=\"\${voicebox_$i}\""
59 line="${line}${value},"
60 done
61
62 # Then add named options.
63 for i in ${voicebox_listopt} ; do
64 eval val=\${voicebox_$i}
65 [ -z ${val} ] || append line "$i=$val" \|
66 done
67
68 # Check if the current voicebox context has anything
69 eval local cur=\${voicebox_section_$voicebox_context}
70 # if not add it to the list of contexts used
71 [ -z $cur ] && append voice_contextlist "${voicebox_context}" " "
72
73 # Then add the voicebox line to the context
74 logdebug 4 "Add Voicebox $line to ${voicebox_context}"
75 append voicebox_section_${voicebox_context} "$line" "$N"
76 fi
77
78 # Then clear the settings for the next one.
79 for i in ${voicebox_list} ${voicebox_listopt} ; do
80 eval unset voicebox_$i
81 done
82 }
83
84 create_voicemailconf() {
85 # Construct the file
86 file=${DEST_DIR}/voicemail.conf
87 get_checksum voicemail_conf $file
88
89 local isempty=1
90 if [ -z ${voice_contextlist} ] ; then
91 local isempty=2
92 rm -f $file
93 else
94 echo "${asteriskuci_gen}[general]" > $file
95 for i in ${voicegeneral_list} ; do
96 eval value=\${voice_$i}
97 if [ ! -z "$value" ] ; then
98 echo "$i=$value" >> $file
99 fi
100 done
101 echo "${N}[zonemessages]" >> $file
102 echo "homeloc=${asterisk_zone}| Q IMp" >> $file
103 echo "${voicezone_list}" >> $file
104 for i in ${voice_contextlist} ; do
105 echo "${N}[$i]" >> $file
106 eval "local cursection=\"\${voicebox_section_${i}}\""
107 echo "$cursection" >> $file
108 eval unset voicebox_section_${i}
109 done
110 unset voice_contexts
111 fi
112 check_checksum "$voicemail_conf" "$file" || ast_voicemail_restart=$isempty
113 }
114
115 handle_voicegeneral() {
116 option_cb() {
117 if valid_voicemail $1 $2 ; then
118 eval voice_$1="$2"
119 else
120 logerror "Invalid general voice option: $1"
121 fi
122 }
123 }
124
125 handle_voicemail() {
126 check_add voicebox
127 voicebox_context=${1%[-_]*}
128 if [ ${voicebox_context} == $1 ] ; then
129 voicebox_context=default
130 fi
131 voicebox_number=${1#*[-_]}
132 option_cb() {
133 case $1 in
134 zone) voicebox_tz="$2" ;;
135 *)
136 if valid_voicebox $1 $2 ; then
137 eval voicebox_$1="$2"
138 else
139 logerror "Invalid voicebox option: $1"
140 fi
141 esac
142 }
143 }
144
145 # Locality options for voicemail
146
147 check_add_voicezone() {
148 if [ ! -z "${voicezone_name}" ] ; then
149 [ -z "${voicezone_zone}" ] && voicezone_zone=${asterisk_zone}
150 if [ -z "${voicezone_message}" ] ; then
151 voicezone_message="Q IMp"
152 else
153 voicezone_message=`echo "$voicezone_message"|tr \" \'`
154 fi
155 append voicezone_list "${voicezone_name}=${voicezone_zone}|${voicezone_message}" "${N}"
156 fi
157 unset voicezone_name
158 unset voicezone_zone
159 unset voicezone_message
160 }
161
162 handle_voicezone() {
163 voicezone_name=$1
164 option_cb() {
165 case $1 in
166 zone) voicezone_zone="$2" ;;
167 message) voicezone_message="$2" ;;
168 *) logerror "Invalid voicezone option: $1"
169 esac
170 }
171 }
172
173 handle_dialplanvoice() {
174 check_add dialplanvoice
175 option_cb() {
176 case $1 in
177 dialplan|extension|voicecontext|voicebox)
178 eval "dial_voice_$1=\"$2\"" ;;
179 *) logerror "Invalid option: $1 for dialplanvoice"
180 esac
181 }
182 }
183
184 check_add_dialplanvoice() {
185 if [ ! -z "${dial_voice_dialplan}" -a ! -z "${dial_voice_extension}" ] ; then
186 local ext="exten => ${dial_voice_extension},"
187 [ -z ${dial_voice_voicebox} ] && dial_voice_voicebox=default
188 if [ -z ${dial_voice_voicebox} ] ; then
189 logerror "Expecting voicebox for ${dial_voice_dialplan}/${dial_voice_extension}"
190 else
191 check_add_context ${dial_voice_dialplan}
192 local voiceext="${dial_voice_voicebox}@${dial_voice_voicecontext}"
193 enable_voicemail
194 append dialplan_context_${dial_voice_dialplan} "${ext}1,VoiceMailMain(${voiceext})" "${N}"
195 fi
196 fi
197 for i in dialplan extension voicecontext voicebox ; do
198 eval "unset dial_voice_$i"
199 done
200 }
201
202 add_dialplan_voice() {
203 local context=$1
204 logdebug 1 "Adding Dialplan voice $1 $2"
205 check_add_context "$context"
206 local ext="exten => $2,"
207 enable_voicemail
208 append dialplan_context_${context} "${ext}1,VoiceMailMain($3)" "${N}"
209 }
210
211
212
213 reload_voicemail() astcmd "module reload app_voicemail.so"
214 unload_voicemail() astcmd "module unload app_voicemail.so"
215
216
217 # vim: ts=2 sw=2 noet foldmethod=indent