f022e6fc091eb611d7379de70694047ece4dc757
[project/luci.git] / contrib / package / 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=
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                 logdebug 1 "Adding in order options"
58                 for i in password name email pager ; do
59                         eval "local value=\"\${voicebox_$i}\""
60                         line="${line}${value},"
61                 done
62
63                 # Then add named options.
64                 logdebug 2 "Adding in named options"
65                 for i in ${voicebox_listopt} ; do
66                         eval val=\${voicebox_$i}
67                         [ -z "${val}" ] || append  line "$i=$val" \|
68                 done
69
70                 logdebug 2 "Check for empty"
71                 # Check if the current voicebox context has anything
72                 eval local cur="\${voicebox_section_$voicebox_context}"
73                 # if not add it to the list of contexts used
74                 [ -z "$cur" ] && append voice_contextlist "${voicebox_context}" " "
75
76                 # Then add the voicebox line to the context
77                 logdebug 4 "Add Voicebox $line to ${voicebox_context}"
78                 append voicebox_section_${voicebox_context} "$line" "$N"
79         fi
80
81         # Then clear the settings for the next one.
82         for i in ${voicebox_list} ${voicebox_listopt} ; do
83                 eval unset voicebox_$i
84         done
85 }
86
87 create_voicemailconf() {
88         # Construct the file
89         file=${DEST_DIR}/voicemail.conf
90         get_checksum voicemail_conf $file
91
92         local isempty=1
93         if [ -z "${voice_contextlist}" ] ; then
94                 local isempty=2
95                 rm -f $file
96         else
97
98                 [ -z "${voice_format}" ] && voice_format="wav49|gsm|wav"
99                 echo "${asteriskuci_gen}[general]" > $file
100                 for i in ${voicegeneral_list} ; do
101                         eval value=\${voice_$i}
102                         if [ ! -z "$value" ] ; then
103                                 echo "$i=$value" >> $file
104                         fi
105                 done
106                 echo "${N}[zonemessages]" >> $file
107                 echo "homeloc=${asterisk_zone}| Q IMp" >> $file
108                 echo "${voicezone_list}" >> $file
109                 for i in ${voice_contextlist} ; do
110                         echo "${N}[$i]" >> $file
111                         eval "local cursection=\"\${voicebox_section_${i}}\""
112                         echo "$cursection" >> $file
113                         eval unset voicebox_section_${i}
114                 done
115                 unset voice_contexts
116         fi
117         check_checksum "$voicemail_conf" "$file" || ast_voicemail_restart=$isempty
118 }
119
120 handle_voicegeneral() {
121         option_cb() {
122                 case "$1" in
123                         format|format_ITEM*) append voice_format "$2" "|" ;;
124                         format_LENGTH) ;;
125                   *)
126                         if valid_voicemail $1 $2 ; then
127                                 eval voice_$1="$2"
128                         else
129                                 logerror "Invalid general voice option: $1"
130                         fi
131                 esac
132         }
133 }
134
135 handle_voicemail() {
136         check_add voicebox
137         voicebox_context="${1%[-_]*}"
138         if [ "${voicebox_context}" == "$1" ] ; then
139                 voicebox_context=default
140         fi
141         voicebox_number=${1#*[-_]}
142         option_cb() {
143                 case $1 in
144                         zone) voicebox_tz="$2" ;;
145                         *)
146                                 if valid_voicebox $1 $2 ; then
147                                         eval "voicebox_$1=\"$2\""
148                                 else
149                                         logerror "Invalid voicebox option: $1"
150                                 fi
151                 esac
152         }
153 }
154
155 # Locality options for voicemail
156
157 check_add_voicezone() {
158         if [ ! -z "${voicezone_name}" ] ; then
159                 [ -z "${voicezone_zone}" ] && voicezone_zone=${asterisk_zone}
160                 if [ -z "${voicezone_message}" ] ; then
161                         voicezone_message="Q IMp"
162                 else
163                         voicezone_message=`echo "$voicezone_message"|tr \" \'`
164                 fi
165                 append voicezone_list "${voicezone_name}=${voicezone_zone}|${voicezone_message}" "${N}"
166         fi
167         unset voicezone_name
168         unset voicezone_zone
169         unset voicezone_message
170 }
171
172 handle_voicezone() {
173         voicezone_name=$1
174         option_cb() {
175                 case $1 in
176                         name) voicezone_name="$2" ;;
177                         zone) voicezone_zone="$2" ;;
178                         message) voicezone_message="$2" ;;
179                         *) logerror "Invalid voicezone option: $1"
180                 esac
181         }
182 }
183
184 handle_dialplanvoice() {
185         check_add dialplanvoice
186         option_cb() {
187                 case $1 in
188                         dialplan|extension|voicecontext|voicebox)
189                                 eval "dial_voice_$1=\"$2\"" ;;
190                         *) logerror "Invalid option: $1 for dialplanvoice"
191                 esac
192         }
193 }
194
195 check_add_dialplanvoice() {
196         if [ ! -z "${dial_voice_dialplan}" -a ! -z "${dial_voice_extension}" ] ; then
197                 local ext="exten => ${dial_voice_extension},"
198                 [ -z "${dial_voice_voicebox}" ] && dial_voice_voicebox=default
199                 if [ -z "${dial_voice_voicebox}" ] ; then
200                         logerror "Expecting voicebox for ${dial_voice_dialplan}/${dial_voice_extension}"
201                 else
202                         check_add_context ${dial_voice_dialplan}
203                         local voiceext="${dial_voice_voicebox}@${dial_voice_voicecontext}"
204                         enable_voicemail
205                         append dialplan_context_${dial_voice_dialplan} "${ext}1,VoiceMailMain(${voiceext})" "${N}"
206                 fi
207         fi
208         for i in dialplan extension voicecontext voicebox ; do
209                 eval "unset dial_voice_$i"
210         done
211 }
212
213 enable_voicemail() {
214         enable_module res_adsi
215         enable_module app_voicemail
216         enable_format gsm
217 }
218
219
220 add_dialplan_voice() {
221         local context=$1
222         logdebug 1 "Adding Dialplan voice $1 $2"
223         check_add_context "$context"
224         local ext="exten => $2,"
225         enable_voicemail
226         append dialplan_context_${context} "${ext}1,VoiceMailMain($3)" "${N}"
227 }
228
229
230
231 reload_voicemail() astcmd "module reload app_voicemail.so"
232 unload_voicemail() astcmd "module unload app_voicemail.so"
233
234
235 # vim: ts=2 sw=2 noet foldmethod=indent