blob: f022e6fc091eb611d7379de70694047ece4dc757 (
plain)
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
|
#!/bin/sh
# Voicemail.conf
ast_add_conf voicemail
init_voicemailconf() {
ast_add_reload voicemail
ast_enable_type voicegeneral
ast_enable_type voicemail
ast_enable_type voicezone
ast_enable_type dialplanvoice
voice_format=
voice_serveremail=
voice_attach=no
voice_skipms=3000
voice_maxsilence=10
voice_silencethreshold=128
voice_maxlogins=3
voice_emaildateformat="%A, %B %d, %Y at %r"
voice_sendvoicemail=no
voice_maxmsg=100
voice_maxmessage=180
voice_minmessage=3
voice_maxgreet=60
return 0
}
voicegeneral_list="format serveremail attach skipms maxsilence silencethreshold maxlogins emaildateformat sendvoicemail maxmsg maxmessage minmessage maxgreet"
voicegeneral_ext_list=""
valid_voicemail(){
is_in_list $1 ${voicegeneral_list} ${voicegeneral_ext_list}
return $?
}
voicebox_list="context number password name email pager"
voicebox_listopt="tz attach serveremail saycid dialout callback review operator envelope sayduration saydurationm"
valid_voicebox() {
is_in_list $1 ${voicebox_list} ${voicebox_listopt}
return $?
}
check_add_voicebox() {
if [ ! -z "${voicebox_number}" ] ; then
[ -z "${voicebox_context}" ] && voicebox_context=default
logdebug 1 "Adding Voicebox ${voicebox_number} in ${voicebox_context}"
# Construct the voicebox line
local line="$voicebox_number => "
[ -z "${voicebox_tz}" ] && voicebox_tz=homeloc
[ -z "${voicebox_name}" ] && voicebox_name=OpenWRT
logdebug 1 "Adding in order options"
for i in password name email pager ; do
eval "local value=\"\${voicebox_$i}\""
line="${line}${value},"
done
# Then add named options.
logdebug 2 "Adding in named options"
for i in ${voicebox_listopt} ; do
eval val=\${voicebox_$i}
[ -z "${val}" ] || append line "$i=$val" \|
done
logdebug 2 "Check for empty"
# Check if the current voicebox context has anything
eval local cur="\${voicebox_section_$voicebox_context}"
# if not add it to the list of contexts used
[ -z "$cur" ] && append voice_contextlist "${voicebox_context}" " "
# Then add the voicebox line to the context
logdebug 4 "Add Voicebox $line to ${voicebox_context}"
append voicebox_section_${voicebox_context} "$line" "$N"
fi
# Then clear the settings for the next one.
for i in ${voicebox_list} ${voicebox_listopt} ; do
eval unset voicebox_$i
done
}
create_voicemailconf() {
# Construct the file
file=${DEST_DIR}/voicemail.conf
get_checksum voicemail_conf $file
local isempty=1
if [ -z "${voice_contextlist}" ] ; then
local isempty=2
rm -f $file
else
[ -z "${voice_format}" ] && voice_format="wav49|gsm|wav"
echo "${asteriskuci_gen}[general]" > $file
for i in ${voicegeneral_list} ; do
eval value=\${voice_$i}
if [ ! -z "$value" ] ; then
echo "$i=$value" >> $file
fi
done
echo "${N}[zonemessages]" >> $file
echo "homeloc=${asterisk_zone}| Q IMp" >> $file
echo "${voicezone_list}" >> $file
for i in ${voice_contextlist} ; do
echo "${N}[$i]" >> $file
eval "local cursection=\"\${voicebox_section_${i}}\""
echo "$cursection" >> $file
eval unset voicebox_section_${i}
done
unset voice_contexts
fi
check_checksum "$voicemail_conf" "$file" || ast_voicemail_restart=$isempty
}
handle_voicegeneral() {
option_cb() {
case "$1" in
format|format_ITEM*) append voice_format "$2" "|" ;;
format_LENGTH) ;;
*)
if valid_voicemail $1 $2 ; then
eval voice_$1="$2"
else
logerror "Invalid general voice option: $1"
fi
esac
}
}
handle_voicemail() {
check_add voicebox
voicebox_context="${1%[-_]*}"
if [ "${voicebox_context}" == "$1" ] ; then
voicebox_context=default
fi
voicebox_number=${1#*[-_]}
option_cb() {
case $1 in
zone) voicebox_tz="$2" ;;
*)
if valid_voicebox $1 $2 ; then
eval "voicebox_$1=\"$2\""
else
logerror "Invalid voicebox option: $1"
fi
esac
}
}
# Locality options for voicemail
check_add_voicezone() {
if [ ! -z "${voicezone_name}" ] ; then
[ -z "${voicezone_zone}" ] && voicezone_zone=${asterisk_zone}
if [ -z "${voicezone_message}" ] ; then
voicezone_message="Q IMp"
else
voicezone_message=`echo "$voicezone_message"|tr \" \'`
fi
append voicezone_list "${voicezone_name}=${voicezone_zone}|${voicezone_message}" "${N}"
fi
unset voicezone_name
unset voicezone_zone
unset voicezone_message
}
handle_voicezone() {
voicezone_name=$1
option_cb() {
case $1 in
name) voicezone_name="$2" ;;
zone) voicezone_zone="$2" ;;
message) voicezone_message="$2" ;;
*) logerror "Invalid voicezone option: $1"
esac
}
}
handle_dialplanvoice() {
check_add dialplanvoice
option_cb() {
case $1 in
dialplan|extension|voicecontext|voicebox)
eval "dial_voice_$1=\"$2\"" ;;
*) logerror "Invalid option: $1 for dialplanvoice"
esac
}
}
check_add_dialplanvoice() {
if [ ! -z "${dial_voice_dialplan}" -a ! -z "${dial_voice_extension}" ] ; then
local ext="exten => ${dial_voice_extension},"
[ -z "${dial_voice_voicebox}" ] && dial_voice_voicebox=default
if [ -z "${dial_voice_voicebox}" ] ; then
logerror "Expecting voicebox for ${dial_voice_dialplan}/${dial_voice_extension}"
else
check_add_context ${dial_voice_dialplan}
local voiceext="${dial_voice_voicebox}@${dial_voice_voicecontext}"
enable_voicemail
append dialplan_context_${dial_voice_dialplan} "${ext}1,VoiceMailMain(${voiceext})" "${N}"
fi
fi
for i in dialplan extension voicecontext voicebox ; do
eval "unset dial_voice_$i"
done
}
enable_voicemail() {
enable_module res_adsi
enable_module app_voicemail
enable_format gsm
}
add_dialplan_voice() {
local context=$1
logdebug 1 "Adding Dialplan voice $1 $2"
check_add_context "$context"
local ext="exten => $2,"
enable_voicemail
append dialplan_context_${context} "${ext}1,VoiceMailMain($3)" "${N}"
}
reload_voicemail() astcmd "module reload app_voicemail.so"
unload_voicemail() astcmd "module unload app_voicemail.so"
# vim: ts=2 sw=2 noet foldmethod=indent
|