1 #!/bin/sh /etc/rc.common
3 # Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
5 # This file is part of luci-pbx.
7 # luci-pbx is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # luci-pbx is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
24 # Some global variables
27 HANGUPCNTXT
=hangup-call-context
32 ASTDIRSRECURSIVE
="/var/run/asterisk /var/log/asterisk /var/spool/asterisk"
33 ASTDIRS
="/usr/lib/asterisk"
34 ASTSOUNDSDIR
="/usr/lib/asterisk/sounds"
36 TEMPLATEDIR
=/etc
/${MODULENAME}-asterisk
37 PBXSOUNDSDIR
=$TEMPLATEDIR/sounds
38 VMTEMPLATEDIR
=/etc
/${MODULENAME}-voicemail
39 VMSOUNDSDIR
=$VMTEMPLATEDIR/sounds
40 ASTERISKDIR
=/etc
/asterisk
41 WORKDIR
=/tmp
/$MODULENAME.$$
42 MD5SUMSFILE
=/tmp
/$MODULENAME-sums.$$
44 TMPL_ASTERISK
=$TEMPLATEDIR/asterisk.conf.TEMPLATE
45 TMPL_GTALK
=$TEMPLATEDIR/gtalk.conf.TEMPLATE
46 TMPL_INDICATIONS
=$TEMPLATEDIR/indications.conf.TEMPLATE
47 TMPL_LOGGER
=$TEMPLATEDIR/logger.conf.TEMPLATE
48 TMPL_MANAGER
=$TEMPLATEDIR/manager.conf.TEMPLATE
49 TMPL_MODULES
=$TEMPLATEDIR/modules.conf.TEMPLATE
50 TMPL_RTP
=$TEMPLATEDIR/rtp.conf.TEMPLATE
52 TMPL_EXTCTHRUCHECKHDR
=$TEMPLATEDIR/extensions_disa-check_header.conf.TEMPLATE
53 TMPL_EXTCTHRUCHECK
=$TEMPLATEDIR/extensions_disa-check.conf.TEMPLATE
54 TMPL_EXTCTHRUCHECKFTR
=$TEMPLATEDIR/extensions_disa-check_footer.conf.TEMPLATE
55 TMPL_EXTCTHRUHDR
=$TEMPLATEDIR/extensions_disa_header.conf.TEMPLATE
56 TMPL_EXTCTHRU
=$TEMPLATEDIR/extensions_disa.conf.TEMPLATE
58 TMPL_EXTENSIONS
=$TEMPLATEDIR/extensions.conf.TEMPLATE
60 TMPL_EXTVMDISABLED
=$TEMPLATEDIR/extensions_voicemail_disabled.conf.TEMPLATE
61 TMPL_EXTVMENABLED
=$TEMPLATEDIR/extensions_voicemail_enabled.conf.TEMPLATE
63 TMPL_EXTBLKLIST
=$TEMPLATEDIR/extensions_blacklist.conf.TEMPLATE
64 TMPL_EXTBLKLISTFTR
=$TEMPLATEDIR/extensions_blacklist_footer.conf.TEMPLATE
65 TMPL_EXTBLKLISTHDR
=$TEMPLATEDIR/extensions_blacklist_header.conf.TEMPLATE
67 TMPL_EXTDEFAULT
=$TEMPLATEDIR/extensions_default.conf.TEMPLATE
68 TMPL_EXTDEFAULTUSER
=$TEMPLATEDIR/extensions_default_user.conf.TEMPLATE
70 TMPL_EXTINCNTXTSIP
=$TEMPLATEDIR/extensions_incoming_context_sip.conf.TEMPLATE
71 TMPL_EXTINCNTXTGTALKHDR
=$TEMPLATEDIR/extensions_incoming_context_gtalk_header.conf.TEMPLATE
72 TMPL_EXTINCNTXTGTALK
=$TEMPLATEDIR/extensions_incoming_context_gtalk.conf.TEMPLATE
74 TMPL_EXTUSERCNTXT
=$TEMPLATEDIR/extensions_user_context.conf.TEMPLATE
75 TMPL_EXTUSERCNTXTFTR
=$TEMPLATEDIR/extensions_user_context_footer.conf.TEMPLATE
76 TMPL_EXTUSERCNTXTHDR
=$TEMPLATEDIR/extensions_user_context_header.conf.TEMPLATE
78 TMPL_EXTOUTHDR
=$TEMPLATEDIR/extensions_default_outgoing_header.conf.TEMPLATE
79 TMPL_EXTOUTGTALK
=$TEMPLATEDIR/extensions_outgoing_gtalk.conf.TEMPLATE
80 TMPL_EXTOUTLOCAL
=$TEMPLATEDIR/extensions_outgoing_dial_local_user.conf.TEMPLATE
81 TMPL_EXTOUTSIP
=$TEMPLATEDIR/extensions_outgoing_sip.conf.TEMPLATE
83 TMPL_JABBER
=$TEMPLATEDIR/jabber.conf.TEMPLATE
84 TMPL_JABBERUSER
=$TEMPLATEDIR/jabber_users.conf.TEMPLATE
85 TMPL_SIP
=$TEMPLATEDIR/sip.conf.TEMPLATE
86 TMPL_SIPPEER
=$TEMPLATEDIR/sip_peer.TEMPLATE
87 TMPL_SIPREG
=$TEMPLATEDIR/sip_registration.TEMPLATE
88 TMPL_SIPUSR
=$TEMPLATEDIR/sip_user.TEMPLATE
90 TMPL_MSMTPDEFAULT
=$VMTEMPLATEDIR/pbx-msmtprc-defaults.TEMPLATE
91 TMPL_MSMTPACCOUNT
=$VMTEMPLATEDIR/pbx-msmtprc-account.TEMPLATE
92 TMPL_MSMTPAUTH
=$VMTEMPLATEDIR/pbx-msmtprc-account-auth.TEMPLATE
93 TMPL_MSMTPACCTDFLT
=$VMTEMPLATEDIR/pbx-msmtprc-account-default.TEMPLATE
96 INCLUDED_FILES
="$WORKDIR/extensions_blacklist.conf $WORKDIR/extensions_callthrough.conf\
97 $WORKDIR/extensions_incoming.conf $WORKDIR/extensions_incoming_gtalk.conf\
98 $WORKDIR/extensions_user.conf $WORKDIR/jabber_users.conf\
99 $WORKDIR/sip_peers.conf $WORKDIR/sip_registrations.conf\
100 $WORKDIR/sip_users.conf $WORKDIR/extensions_voicemail.conf\
101 $WORKDIR/extensions_default.conf"
104 # In this string, we concatenate all local users enabled to receive calls
105 # readily formatted for the Dial command.
106 localusers_to_ring
=""
108 # In this string, we keep a list of all users that are enabled for outgoing
109 # calls. It is used at the end to create the user contexts.
110 localusers_can_dial
=""
112 # In this string, we put together a space-separated list of provider names
113 # (alphanumeric, with all non-alpha characters replaced with underscores),
114 # which will be used to dial out by default (whose outgoing contexts will
115 # be included in users' contexts by default.
116 outbound_providers
=""
118 # Copies the template files which we don't edit.
119 copy_unedited_templates_over
()
121 cp $TMPL_ASTERISK $WORKDIR/asterisk.conf
122 cp $TMPL_GTALK $WORKDIR/gtalk.conf
123 cp $TMPL_INDICATIONS $WORKDIR/indications.conf
124 cp $TMPL_LOGGER $WORKDIR/logger.conf
125 cp $TMPL_MANAGER $WORKDIR/manager.conf
126 cp $TMPL_MODULES $WORKDIR/modules.conf
127 # If this file isn't present at this stage, voicemail is disabled.
128 [ ! -f $WORKDIR/extensions_voicemail.conf
] && \
129 cp $TMPL_EXTVMDISABLED $WORKDIR/extensions_voicemail.conf
132 # Touches all the included files, to prevent asterisk from refusing to
133 # start if a config item is missing and an included config file isn't created.
134 create_included_files
()
136 touch $INCLUDED_FILES
139 # Puts together all the extensions.conf related configuration.
140 pbx_create_extensions_config
()
143 config_get ringtime advanced ringtime
145 sed "s/|RINGTIME|/$ringtime/" $TMPL_EXTENSIONS > $WORKDIR/extensions.conf
146 mv $WORKDIR/inext.TMP
$WORKDIR/extensions_incoming.conf
147 cp $TMPL_EXTINCNTXTGTALKHDR $WORKDIR/extensions_incoming_gtalk.conf
148 cat $WORKDIR/outextgtalk.TMP
>> $WORKDIR/extensions_incoming_gtalk.conf
2>/dev
/null
149 rm -f $WORKDIR/outextgtalk.TMP
150 mv $WORKDIR/blacklist.TMP
$WORKDIR/extensions_blacklist.conf
151 mv $WORKDIR/userext.TMP
$WORKDIR/extensions_user.conf
152 cp $TMPL_EXTCTHRUHDR $WORKDIR/extensions_callthrough.conf
153 cat $WORKDIR/callthrough.TMP
>> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
154 rm -f $WORKDIR/callthrough.TMP
155 cat $TMPL_EXTCTHRUCHECKHDR >> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
156 cat $WORKDIR/callthroughcheck.TMP
>> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
157 rm -f $WORKDIR/callthroughcheck.TMP
158 cat $TMPL_EXTCTHRUCHECKFTR >> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
159 rm -f $WORKDIR/outext-
*.TMP
160 rm -f $WORKDIR/localext.TMP
161 sed "s/|LOCALUSERS|/$localusers_to_ring/g" $TMPL_EXTDEFAULT \
162 > $WORKDIR/extensions_default.conf
163 cat $WORKDIR/inextuser.TMP
>> $WORKDIR/extensions_default.conf
164 rm -f $WORKDIR/inextuser.TMP
167 # Puts together all the sip.conf related configuration.
168 pbx_create_sip_config
()
170 mv $WORKDIR/sip_regs.TMP
$WORKDIR/sip_registrations.conf
171 mv $WORKDIR/sip_peers.TMP
$WORKDIR/sip_peers.conf
172 mv $WORKDIR/sip_users.TMP
$WORKDIR/sip_users.conf
175 # Creates the jabber.conf related config
176 pbx_create_jabber_config
()
178 cp $TMPL_JABBER $WORKDIR/jabber.conf
179 mv $WORKDIR/jabber.TMP
$WORKDIR/jabber_users.conf
182 # Gets rid of any config files from $ASTERISKDIR not found in $WORKDIR.
183 clean_up_asterisk_config_dir
()
185 for f
in $ASTERISKDIR/* ; do
186 basef
="`basename $f`"
187 if [ ! -e "$WORKDIR/$basef" ] ; then
193 # Compares md5sums of the config files in $WORKDIR to those
194 # in $ASTERISKDIR, and copies only changed files over to reduce
195 # wear on flash in embedded devices.
196 compare_configs_and_copy_changed
()
198 # First, compute md5sums of the config files in $WORKDIR.
200 md5sum * > $MD5SUMSFILE
202 # Now, check the files in $ASTERISKDIR against the md5sums.
204 changed_files
="`md5sum -c $MD5SUMSFILE 2>/dev/null | fgrep ": FAILED
" | awk -F: '{print $1}'`"
208 [ -z "$changed_files" ] && return
210 # Now copy over the changed files.
211 for f
in $changed_files ; do
212 cp "$WORKDIR/$f" "$ASTERISKDIR/$f"
216 # Calls the functions that create the final config files
217 # Calls the function which compares which files have changed
218 # Puts the final touches on $ASTERISKDIR
219 # Gets rid of $WORKDIR
220 pbx_assemble_and_copy_config
()
222 mkdir
-p $ASTERISKDIR
224 copy_unedited_templates_over
225 create_included_files
226 pbx_create_extensions_config
227 pbx_create_sip_config
228 pbx_create_jabber_config
230 touch $WORKDIR/features.conf
232 # At this point, $WORKDIR should contain a complete, working config.
233 clean_up_asterisk_config_dir
235 compare_configs_and_copy_changed
237 [ ! -d $ASTERISKDIR/manager.d
] && mkdir
-p $ASTERISKDIR/manager.d
/
239 # Get rid of the working directory
243 # Creates configuration for a user and adds it to the temporary file that holds
244 # all users configured so far.
253 config_get fullname
$1 fullname
254 config_get defaultuser
$1 defaultuser
255 config_get secret
$1 secret
256 config_get ring
$1 ring
257 config_get can_call
$1 can_call
259 [ -z "$defaultuser" -o -z "$secret" ] && return
260 [ -z "$fullname" ] && fullname
="$defaultuser"
262 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPUSR > $WORKDIR/sip_user.tmp
264 if [ "$can_call" = "yes" ] ; then
265 # Add user to list of all users that are allowed to make calls.
266 localusers_can_dial
="$localusers_can_dial $defaultuser"
267 sed -i "s/|CONTEXTNAME|/$defaultuser/g" $WORKDIR/sip_user.tmp
269 sed -i "s/|CONTEXTNAME|/$HANGUPCNTXT/g" $WORKDIR/sip_user.tmp
272 # Add this user's configuration to the temp file containing all user configs.
273 sed "s/|FULLNAME|/$fullname/" $WORKDIR/sip_user.tmp |\
274 sed "s/|SECRET|/$secret/g" >> $WORKDIR/sip_users.TMP
276 if [ "$ring" = "yes" ] ; then
277 if [ -z "$localusers_to_ring" ] ; then
278 localusers_to_ring
="SIP\/$defaultuser"
280 localusers_to_ring
="$localusers_to_ring\&SIP\/$defaultuser"
284 # Add configuration which allows local users to call each other.
285 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTOUTLOCAL >> $WORKDIR/localext.TMP
287 # Add configuration which puts calls to users through the default
288 # context, so that blacklists and voicemail take effect for this user.
289 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTDEFAULTUSER >> $WORKDIR/inextuser.TMP
291 rm -f $WORKDIR/sip_user.tmp
294 # Creates configuration for a Google account, and adds it to the temporary file that holds
295 # all accounts configured so far.
296 # Also creates the outgoing extensions which are used in users' outgoing contexts.
303 local make_outgoing_calls
309 config_get username
$1 username
310 config_get secret
$1 secret
311 config_get numprefix
$1 numprefix
312 config_get register
$1 register
313 config_get make_outgoing_calls
$1 make_outgoing_calls
314 config_get name
$1 name
315 config_get status
$1 status
316 config_get statusmessage
$1 statusmessage
318 [ -z "$username" -o -z "$secret" ] && return
320 # Construct a jabber entry for this provider.
321 sed "s/|USERNAME|/$username/g" $TMPL_JABBERUSER |\
322 sed "s/|NAME|/$name/g" > $WORKDIR/jabber.tmp
324 if [ "$register" = yes ] ; then
325 # If this provider is enabled for incoming calls, we need to set the
326 # status of the user to something other than unavailable in order to receive calls.
327 sed -i "s/|STATUS|/$status/g" $WORKDIR/jabber.tmp
328 sed -i "s/|STATUSMESSAGE|/\"$statusmessage\"/g" $WORKDIR/jabber.tmp
330 users_to_ring
="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
331 # If no users have been specified to ring, we ring all users enabled for incoming calls.
332 if [ -z "$users_to_ring" ] ; then
333 users_to_ring
=$localusers_to_ring
335 # Else, we cook up a string formatted for the Dial command
336 # with the specified users (SIP/user1&SIP/user2&...). We do it
337 # with set, shift and a loop in order to be more tolerant of ugly whitespace
338 # messes entered by users.
340 users_to_ring
="SIP\/$1" && shift
341 for u
in $@
; do users_to_ring
=$users_to_ring\\\
&SIP
\\\
/$u ; done
344 # Now, we add this account to the gtalk incoming context.
345 sed "s/|USERNAME|/$username/g" $TMPL_EXTINCNTXTGTALK |\
346 sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/outextgtalk.TMP
348 sed -i "s/|STATUS|/$GTALKUNVL/g" $WORKDIR/jabber.tmp
349 sed -i "s/|STATUSMESSAGE|/\"\"/g" $WORKDIR/jabber.tmp
352 # Add this account's configuration to the temp file containing all account configs.
353 sed "s/|SECRET|/$secret/g" $WORKDIR/jabber.tmp
>> $WORKDIR/jabber.TMP
355 # If this provider is enabled for outgoing calls.
356 if [ "$make_outgoing_calls" = "yes" ] ; then
358 numprefix
="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
360 # If no prefixes are specified, then we use "X" which matches any prefix.
361 [ -z "$numprefix" ] && numprefix
="X"
363 for p
in $numprefix ; do
364 sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTGTALK |\
365 sed "s/|NAME|/$name/g" >> $WORKDIR/outext-
$name.TMP
368 # Add this provider to the list of enabled outbound providers.
369 if [ -z "$outbound_providers" ] ; then
370 outbound_providers
="$name"
372 outbound_providers
="$outbound_providers $name"
376 rm -f $WORKDIR/jabber.tmp
379 # Creates configuration for a SIP provider account, and adds it to the temporary file that holds
380 # all accounts configured so far.
381 # Also creates the outgoing extensions which are used in users' outgoing contexts.
390 local make_outgoing_calls
396 config_get defaultuser
$1 defaultuser
397 config_get secret
$1 secret
398 config_get
host $1 host
399 config_get port
$1 port
400 config_get outbountproxy
$1 outboundproxy
401 config_get fromdomain
$1 fromdomain
402 config_get register
$1 register
403 config_get numprefix
$1 numprefix
404 config_get make_outgoing_calls
$1 make_outgoing_calls
405 config_get name
$1 name
407 [ -z "$defaultuser" -o -z "$secret" -o -z "$host" ] && return
408 [ -z "$fromdomain" ] && fromdomain
=$host
409 [ -n "$port" ] && port
="port=$port"
410 [ -n "$outboundproxy" ] && outboundproxy
="outboundproxy=$outboundproxy"
412 # Construct a sip peer entry for this provider.
413 sed "s/|DEFAULTUSER|/$defaultuser/" $TMPL_SIPPEER > $WORKDIR/sip_peer.tmp
414 sed -i "s/|NAME|/$name/" $WORKDIR/sip_peer.tmp
415 sed -i "s/|FROMUSER|/$defaultuser/" $WORKDIR/sip_peer.tmp
416 sed -i "s/|SECRET|/$secret/" $WORKDIR/sip_peer.tmp
417 sed -i "s/|HOST|/$host/" $WORKDIR/sip_peer.tmp
418 sed -i "s/|PORT|/$port/" $WORKDIR/sip_peer.tmp
419 sed -i "s/|OUTBOUNDPROXY|/$outboundproxy/" $WORKDIR/sip_peer.tmp
420 # Add this account's configuration to the temp file containing all account configs.
421 sed "s/|FROMDOMAIN|/$host/" $WORKDIR/sip_peer.tmp
>> $WORKDIR/sip_peers.TMP
423 # If this provider is enabled for incoming calls.
424 if [ "$register" = "yes" ] ; then
425 # Then we create a registration string for this provider.
426 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPREG > $WORKDIR/sip_reg.tmp
427 sed -i "s/|SECRET|/$secret/g" $WORKDIR/sip_reg.tmp
428 sed "s/|NAME|/$name/g" $WORKDIR/sip_reg.tmp
>> $WORKDIR/sip_regs.TMP
430 users_to_ring
="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
431 # If no users have been specified to ring, we ring all users enabled for incoming calls.
432 if [ -z "$users_to_ring" ] ; then
433 users_to_ring
=$localusers_to_ring
435 # Else, we cook up a string formatted for the Dial command
436 # with the specified users (SIP/user1&SIP/user2&...). We do it
437 # with set, shift and a loop in order to be more tolerant of ugly whitespace
438 # messes entered by users.
440 users_to_ring
="SIP\/$1" && shift
441 for u
in $@
; do users_to_ring
=$users_to_ring\\\
&SIP
\\\
/$u ; done
444 # And we create an incoming calls context for this provider.
445 sed "s/|NAME|/$name/g" $TMPL_EXTINCNTXTSIP |\
446 sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/inext.TMP
449 # If this provider is enabled for outgoing calls.
450 if [ "$make_outgoing_calls" = "yes" ] ; then
452 numprefix
="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
453 # If no prefixes are specified, then we use "X" which matches any prefix.
454 [ -z "$numprefix" ] && numprefix
="X"
455 for p
in $numprefix ; do
456 sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTSIP |\
457 sed "s/|NAME|/$name/g" >> $WORKDIR/outext-
$name.TMP
460 # Add this provider to the list of enabled outbound providers.
461 if [ -z "$outbound_providers" ] ; then
462 outbound_providers
="$name"
464 outbound_providers
="$outbound_providers $name"
468 rm -f $WORKDIR/sip_peer.tmp
469 rm -f $WORKDIR/sip_reg.tmp
472 # For all local users enabled for outbound calls, creates a context
473 # containing the extensions for Google and SIP accounts this user is
475 pbx_create_user_contexts
()
479 for u
in $localusers_can_dial ; do
480 sed "s/|DEFAULTUSER|/$u/g" $TMPL_EXTUSERCNTXTHDR >> $WORKDIR/userext.TMP
481 cat $WORKDIR/localext.TMP
>> $WORKDIR/userext.TMP
482 providers
="`uci -q get ${MODULENAME}-calls.providers_user_can_use.$u`"
483 [ -z "$providers" ] && providers
="$outbound_providers"
485 # For each provider, cat the contents of outext-$name.TMP into the user's outgoing calls extension
486 for p
in $providers ; do
487 [ -f $WORKDIR/outext-
$p.TMP
] && cat $WORKDIR/outext-
$p.TMP
>> $WORKDIR/userext.TMP
489 cat $TMPL_EXTUSERCNTXTFTR >> $WORKDIR/userext.TMP
493 # Creates the blacklist context which hangs up on blacklisted numbers.
499 config_get blacklist1 blacklisting blacklist1
500 config_get blacklist2 blacklisting blacklist2
502 # We create the blacklist context no matter whether the blacklist
503 # actually contains entries or not, since the PBX will send calls
504 # to the context for a check against the list anyway.
505 cp $TMPL_EXTBLKLISTHDR $WORKDIR/blacklist.TMP
506 for n
in $blacklist1 $blacklist2 ; do
507 sed "s/|BLACKLISTITEM|/$n/g" $TMPL_EXTBLKLIST >> $WORKDIR/blacklist.TMP
509 cat $TMPL_EXTBLKLISTFTR >> $WORKDIR/blacklist.TMP
512 # Creates the callthrough context which allows specified numbers to get
513 # into the PBX and dial out as the configured user.
514 pbx_add_callthrough
()
516 local callthrough_number_list
521 config_get callthrough_number_list
$1 callthrough_number_list
522 config_get defaultuser
$1 defaultuser
523 config_get pin
$1 pin
524 config_get enabled
$1 enabled
526 [ "$enabled" = "no" ] && return
527 [ "$defaultuser" = "" ] && return
529 for callthrough_number
in $callthrough_number_list ; do
530 sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRUCHECK >> $WORKDIR/callthroughcheck.TMP
532 sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRU |\
533 sed "s/|DEFAULTUSER|/$defaultuser/" |\
534 sed "s/|PIN|/$pin/" >> $WORKDIR/callthrough.TMP
538 # Creates sip.conf from its template.
539 pbx_cook_sip_template
()
545 config_get useragent advanced useragent
546 config_get externhost advanced externhost
547 config_get bindport advanced bindport
549 [ -z "$useragent" ] && useragent
="$USERAGENT"
551 sed "s/|USERAGENT|/$useragent/g" $TMPL_SIP > $WORKDIR/sip.conf
553 if [ -z "$externhost" ] ; then
554 sed -i "s/externhost=|EXTERNHOST|//g" $WORKDIR/sip.conf
556 sed -i "s/|EXTERNHOST|/$externhost/g" $WORKDIR/sip.conf
559 if [ -z "$bindport" ] ; then
560 sed -i "s/bindport=|BINDPORT|//g" $WORKDIR/sip.conf
562 sed -i "s/|BINDPORT|/$bindport/g" $WORKDIR/sip.conf
568 # Creates rtp.conf from its template.
569 pbx_cook_rtp_template
()
574 config_get rtpstart advanced rtpstart
575 config_get rtpend advanced rtpend
577 sed "s/|RTPSTART|/$rtpstart/" $TMPL_RTP |\
578 sed "s/|RTPEND|/$rtpend/" > $WORKDIR/rtp.conf
581 # Links any sound files found in $PBXSOUNDSDIR and $VMSOUNDSDIR
582 # into $ASTSOUNDSDIR for use by Asterisk. Does not overwrite files.
585 mkdir
-p $ASTSOUNDSDIR
587 for dir
in $PBXSOUNDSDIR $VMSOUNDSDIR ; do
588 if [ -d $dir ] ; then
590 ln -s $f $ASTSOUNDSDIR 2>/dev
/null
597 # Makes sure the ownership of specified directories is proper.
600 chown
$ASTUSER:$ASTGROUP $ASTDIRS
601 chown
$ASTUSER:$ASTGROUP -R $ASTDIRSRECURSIVE
605 # Creates voicemail config if installed and enabled.
606 pbx_configure_voicemail
()
610 local global_email_addresses
619 config_get enabled global_voicemail enabled
621 # First check if voicemail is enabled.
622 [ "$enabled" != "yes" ] && return
624 config_get global_timeout global_voicemail global_timeout
625 #config_get global_email_addresses global_voicemail global_email_addresses
626 config_get smtp_auth voicemail_smtp smtp_auth
627 config_get smtp_tls voicemail_smtp smtp_tls
628 config_get smtp_server voicemail_smtp smtp_server
629 config_get smtp_port voicemail_smtp smtp_port
630 config_get smtp_user voicemail_smtp smtp_user
631 config_get smtp_password voicemail_smtp smtp_password
633 sed "s/|AUTH|/$smtp_auth/" $TMPL_MSMTPDEFAULT |\
634 sed "s/|TLS|/$smtp_tls/" > $WORKDIR/pbx-msmtprc
636 sed "s/|HOST|/$smtp_server/" $TMPL_MSMTPACCOUNT |\
637 sed "s/|PORT|/$smtp_port/" >> $WORKDIR/pbx-msmtprc
639 if [ "$smtp_auth" = "on" ] ; then
640 sed "s/|USER|/$smtp_user/" $TMPL_MSMTPAUTH |\
641 sed "s/|PASSWORD|/$smtp_password/" >> $WORKDIR/pbx-msmtprc
644 cat $TMPL_MSMTPACCTDFLT >> $WORKDIR/pbx-msmtprc
646 [ ! -f /etc
/pbx-msmtprc
] && cp $WORKDIR/pbx-msmtprc
/etc
/pbx-msmtprc
647 diff -q $WORKDIR/pbx-msmtprc
/etc
/pbx-msmtprc
1>/dev
/null \
648 ||
mv $WORKDIR/pbx-msmtprc
/etc
/pbx-msmtprc
649 chmod 600 /etc
/pbx-msmtprc
651 # Copy over the extensions file which has voicemail enabled.
652 cp $TMPL_EXTVMENABLED $WORKDIR/extensions_voicemail.conf
660 config_load
${MODULENAME}-users
661 config_foreach pbx_add_user local_user
663 # Create configuration for each google account.
665 config_load
${MODULENAME}-google
666 config_foreach pbx_add_jabber gtalk_jabber
668 # Create configuration for each voip provider.
670 config_load
${MODULENAME}-voip
671 config_foreach pbx_add_peer voip_provider
673 # Create the user contexts, and phone blacklist.
675 config_load
${MODULENAME}-calls
676 pbx_create_user_contexts
678 config_foreach pbx_add_callthrough callthrough_numbers
680 # Prepare sip.conf using settings from the "advanced" section.
682 config_load
${MODULENAME}-advanced
683 pbx_cook_sip_template
684 pbx_cook_rtp_template
686 # Prepare voicemail config.
688 config_load
${MODULENAME}-voicemail
689 pbx_configure_voicemail
691 # Assemble the configuration, and copy changed files over.
693 config_load
${MODULENAME}-advanced
694 pbx_assemble_and_copy_config
699 # Enforce ownership of specified files and directories.