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 DEFAULTOUTCNTXT
=default-outgoing-call-context
33 ASTDIRSRECURSIVE
="/var/run/asterisk /var/log/asterisk /var/spool/asterisk"
34 ASTDIRS
="/usr/lib/asterisk"
36 TEMPLATEDIR
=/etc
/${MODULENAME}-asterisk
37 VMTEMPLATEDIR
=/etc
/${MODULENAME}-voicemail
38 ASTERISKDIR
=/etc
/asterisk
39 WORKDIR
=/tmp
/$MODULENAME.$$
40 MD5SUMSFILE
=/tmp
/$MODULENAME-sums.$$
42 TMPL_ASTERISK
=$TEMPLATEDIR/asterisk.conf.TEMPLATE
43 TMPL_GTALK
=$TEMPLATEDIR/gtalk.conf.TEMPLATE
44 TMPL_INDICATIONS
=$TEMPLATEDIR/indications.conf.TEMPLATE
45 TMPL_LOGGER
=$TEMPLATEDIR/logger.conf.TEMPLATE
46 TMPL_MANAGER
=$TEMPLATEDIR/manager.conf.TEMPLATE
47 TMPL_MODULES
=$TEMPLATEDIR/modules.conf.TEMPLATE
48 TMPL_RTP
=$TEMPLATEDIR/rtp.conf.TEMPLATE
50 TMPL_EXTCTHRUCHECKHDR
=$TEMPLATEDIR/extensions_disa-check_header.conf.TEMPLATE
51 TMPL_EXTCTHRUCHECK
=$TEMPLATEDIR/extensions_disa-check.conf.TEMPLATE
52 TMPL_EXTCTHRUCHECKFTR
=$TEMPLATEDIR/extensions_disa-check_footer.conf.TEMPLATE
53 TMPL_EXTCTHRUHDR
=$TEMPLATEDIR/extensions_disa_header.conf.TEMPLATE
54 TMPL_EXTCTHRU
=$TEMPLATEDIR/extensions_disa.conf.TEMPLATE
56 TMPL_EXTENSIONS
=$TEMPLATEDIR/extensions.conf.TEMPLATE
58 TMPL_EXTVMDISABLED
=$TEMPLATEDIR/extensions_voicemail_disabled.conf.TEMPLATE
59 TMPL_EXTVMENABLED
=$TEMPLATEDIR/extensions_voicemail_enabled.conf.TEMPLATE
61 TMPL_EXTBLKLIST
=$TEMPLATEDIR/extensions_blacklist.conf.TEMPLATE
62 TMPL_EXTBLKLISTFTR
=$TEMPLATEDIR/extensions_blacklist_footer.conf.TEMPLATE
63 TMPL_EXTBLKLISTHDR
=$TEMPLATEDIR/extensions_blacklist_header.conf.TEMPLATE
65 TMPL_EXTDEFAULT
=$TEMPLATEDIR/extensions_default.conf.TEMPLATE
66 TMPL_EXTDEFAULTUSER
=$TEMPLATEDIR/extensions_default_user.conf.TEMPLATE
68 TMPL_EXTINCNTXTSIP
=$TEMPLATEDIR/extensions_incoming_context_sip.conf.TEMPLATE
69 TMPL_EXTINCNTXTGTALKHDR
=$TEMPLATEDIR/extensions_incoming_context_gtalk_header.conf.TEMPLATE
70 TMPL_EXTINCNTXTGTALK
=$TEMPLATEDIR/extensions_incoming_context_gtalk.conf.TEMPLATE
72 TMPL_EXTUSERCNTXT
=$TEMPLATEDIR/extensions_user_context.conf.TEMPLATE
73 TMPL_EXTUSERCNTXTFTR
=$TEMPLATEDIR/extensions_user_context_footer.conf.TEMPLATE
74 TMPL_EXTUSERCNTXTHDR
=$TEMPLATEDIR/extensions_user_context_header.conf.TEMPLATE
76 TMPL_EXTOUTHDR
=$TEMPLATEDIR/extensions_default_outgoing_header.conf.TEMPLATE
77 TMPL_EXTOUTGTALK
=$TEMPLATEDIR/extensions_outgoing_gtalk.conf.TEMPLATE
78 TMPL_EXTOUTLOCAL
=$TEMPLATEDIR/extensions_outgoing_dial_local_user.conf.TEMPLATE
79 TMPL_EXTOUTSIP
=$TEMPLATEDIR/extensions_outgoing_sip.conf.TEMPLATE
81 TMPL_JABBER
=$TEMPLATEDIR/jabber.conf.TEMPLATE
82 TMPL_JABBERUSER
=$TEMPLATEDIR/jabber_users.conf.TEMPLATE
83 TMPL_SIP
=$TEMPLATEDIR/sip.conf.TEMPLATE
84 TMPL_SIPPEER
=$TEMPLATEDIR/sip_peer.TEMPLATE
85 TMPL_SIPREG
=$TEMPLATEDIR/sip_registration.TEMPLATE
86 TMPL_SIPUSR
=$TEMPLATEDIR/sip_user.TEMPLATE
88 TMPL_MSMTPDEFAULT
=$VMTEMPLATEDIR/pbx-msmtprc-defaults.TEMPLATE
89 TMPL_MSMTPACCOUNT
=$VMTEMPLATEDIR/pbx-msmtprc-account.TEMPLATE
90 TMPL_MSMTPAUTH
=$VMTEMPLATEDIR/pbx-msmtprc-account-auth.TEMPLATE
91 TMPL_MSMTPACCTDFLT
=$VMTEMPLATEDIR/pbx-msmtprc-account-default.TEMPLATE
94 INCLUDED_FILES
="$WORKDIR/extensions_blacklist.conf $WORKDIR/extensions_callthrough.conf\
95 $WORKDIR/extensions_incoming.conf $WORKDIR/extensions_incoming_gtalk.conf\
96 $WORKDIR/extensions_user.conf $WORKDIR/jabber_users.conf\
97 $WORKDIR/sip_peers.conf $WORKDIR/sip_registrations.conf\
98 $WORKDIR/sip_users.conf $WORKDIR/extensions_voicemail.conf\
99 $WORKDIR/extensions_default.conf"
102 # In this string, we concatenate all local users enabled to receive calls
103 # readily formatted for the Dial command.
104 localusers_to_ring
=""
106 # In this string, we keep a list of all users that are enabled for outgoing
107 # calls. It is used at the end to create the user contexts.
108 localusers_can_dial
=""
110 # In this string, we put together a space-separated list of provider names
111 # (alphanumeric, with all non-alpha characters replaced with underscores),
112 # which will be used to dial out by default (whose outgoing contexts will
113 # be included in users' contexts by default.
114 outbound_providers
=""
116 # Copies the template files which we don't edit.
117 copy_unedited_templates_over
()
119 cp $TMPL_ASTERISK $WORKDIR/asterisk.conf
120 cp $TMPL_GTALK $WORKDIR/gtalk.conf
121 cp $TMPL_INDICATIONS $WORKDIR/indications.conf
122 cp $TMPL_LOGGER $WORKDIR/logger.conf
123 cp $TMPL_MANAGER $WORKDIR/manager.conf
124 cp $TMPL_MODULES $WORKDIR/modules.conf
125 # If this file isn't present at this stage, voicemail is disabled.
126 [ ! -f $WORKDIR/extensions_voicemail.conf
] && \
127 cp $TMPL_EXTVMDISABLED $WORKDIR/extensions_voicemail.conf
130 # Touches all the included files, to prevent asterisk from refusing to
131 # start if a config item is missing and an included config file isn't created.
132 create_included_files
()
134 touch $INCLUDED_FILES
137 # Puts together all the extensions.conf related configuration.
138 pbx_create_extensions_config
()
141 config_get ringtime advanced ringtime
143 sed "s/|RINGTIME|/$ringtime/" $TMPL_EXTENSIONS > $WORKDIR/extensions.conf
144 mv $WORKDIR/inext.TMP
$WORKDIR/extensions_incoming.conf
145 cp $TMPL_EXTINCNTXTGTALKHDR $WORKDIR/extensions_incoming_gtalk.conf
146 cat $WORKDIR/outextgtalk.TMP
>> $WORKDIR/extensions_incoming_gtalk.conf
2>/dev
/null
147 rm -f $WORKDIR/outextgtalk.TMP
148 mv $WORKDIR/blacklist.TMP
$WORKDIR/extensions_blacklist.conf
149 mv $WORKDIR/userext.TMP
$WORKDIR/extensions_user.conf
150 cp $TMPL_EXTCTHRUHDR $WORKDIR/extensions_callthrough.conf
151 cat $WORKDIR/callthrough.TMP
>> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
152 rm -f $WORKDIR/callthrough.TMP
153 cat $TMPL_EXTCTHRUCHECKHDR >> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
154 cat $WORKDIR/callthroughcheck.TMP
>> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
155 rm -f $WORKDIR/callthroughcheck.TMP
156 cat $TMPL_EXTCTHRUCHECKFTR >> $WORKDIR/extensions_callthrough.conf
2>/dev
/null
157 rm -f $WORKDIR/outext-
*.TMP
158 rm -f $WORKDIR/localext.TMP
159 sed "s/|LOCALUSERS|/$localusers_to_ring/g" $TMPL_EXTDEFAULT \
160 > $WORKDIR/extensions_default.conf
161 cat $WORKDIR/inextuser.TMP
>> $WORKDIR/extensions_default.conf
162 rm -f $WORKDIR/inextuser.TMP
165 # Puts together all the sip.conf related configuration.
166 pbx_create_sip_config
()
168 mv $WORKDIR/sip_regs.TMP
$WORKDIR/sip_registrations.conf
169 mv $WORKDIR/sip_peers.TMP
$WORKDIR/sip_peers.conf
170 mv $WORKDIR/sip_users.TMP
$WORKDIR/sip_users.conf
173 # Creates the jabber.conf related config
174 pbx_create_jabber_config
()
176 cp $TMPL_JABBER $WORKDIR/jabber.conf
177 mv $WORKDIR/jabber.TMP
$WORKDIR/jabber_users.conf
180 # Gets rid of any config files from $ASTERISKDIR not found in $WORKDIR.
181 clean_up_asterisk_config_dir
()
183 for f
in $ASTERISKDIR/* ; do
184 basef
="`basename $f`"
185 if [ ! -e "$WORKDIR/$basef" ] ; then
191 # Compares md5sums of the config files in $WORKDIR to those
192 # in $ASTERISKDIR, and copies only changed files over to reduce
193 # wear on flash in embedded devices.
194 compare_configs_and_copy_changed
()
196 # First, compute md5sums of the config files in $WORKDIR.
198 md5sum * > $MD5SUMSFILE
200 # Now, check the files in $ASTERISKDIR against the md5sums.
202 changed_files
="`md5sum -c $MD5SUMSFILE 2>/dev/null | fgrep ": FAILED
" | awk -F: '{print $1}'`"
206 [ -z "$changed_files" ] && return
208 # Now copy over the changed files.
209 for f
in $changed_files ; do
210 cp "$WORKDIR/$f" "$ASTERISKDIR/$f"
214 # Calls the functions that create the final config files
215 # Calls the function which compares which files have changed
216 # Puts the final touches on $ASTERISKDIR
217 # Gets rid of $WORKDIR
218 pbx_assemble_and_copy_config
()
220 mkdir
-p $ASTERISKDIR
222 copy_unedited_templates_over
223 create_included_files
224 pbx_create_extensions_config
225 pbx_create_sip_config
226 pbx_create_jabber_config
228 touch $WORKDIR/features.conf
230 # At this point, $WORKDIR should contain a complete, working config.
231 clean_up_asterisk_config_dir
233 compare_configs_and_copy_changed
235 [ ! -d $ASTERISKDIR/manager.d
] && mkdir
-p $ASTERISKDIR/manager.d
/
237 # Get rid of the working directory
241 # Creates configuration for a user and adds it to the temporary file that holds
242 # all users configured so far.
251 config_get fullname
$1 fullname
252 config_get defaultuser
$1 defaultuser
253 config_get secret
$1 secret
254 config_get ring
$1 ring
255 config_get can_call
$1 can_call
257 [ -z "$defaultuser" -o -z "$secret" ] && return
258 [ -z "$fullname" ] && fullname
="$defaultuser"
260 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPUSR > $WORKDIR/sip_user.tmp
262 if [ "$can_call" = "yes" ] ; then
263 # Add user to list of all users that are allowed to make calls.
264 localusers_can_dial
="$localusers_can_dial $defaultuser"
265 sed -i "s/|CONTEXTNAME|/$defaultuser/g" $WORKDIR/sip_user.tmp
267 sed -i "s/|CONTEXTNAME|/$HANGUPCNTXT/g" $WORKDIR/sip_user.tmp
270 # Add this user's configuration to the temp file containing all user configs.
271 sed "s/|FULLNAME|/$fullname/" $WORKDIR/sip_user.tmp |\
272 sed "s/|SECRET|/$secret/g" >> $WORKDIR/sip_users.TMP
274 if [ "$ring" = "yes" ] ; then
275 if [ -z "$localusers_to_ring" ] ; then
276 localusers_to_ring
="SIP\/$defaultuser"
278 localusers_to_ring
="$localusers_to_ring\&SIP\/$defaultuser"
282 # Add configuration which allows local users to call each other.
283 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTOUTLOCAL >> $WORKDIR/localext.TMP
285 # Add configuration which puts calls to users through the default
286 # context, so that blacklists and voicemail take effect for this user.
287 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTDEFAULTUSER >> $WORKDIR/inextuser.TMP
289 rm -f $WORKDIR/sip_user.tmp
292 # Creates configuration for a Google account, and adds it to the temporary file that holds
293 # all accounts configured so far.
294 # Also creates the outgoing extensions which are used in users' outgoing contexts.
301 local make_outgoing_calls
307 config_get username
$1 username
308 config_get secret
$1 secret
309 config_get numprefix
$1 numprefix
310 config_get register
$1 register
311 config_get make_outgoing_calls
$1 make_outgoing_calls
312 config_get name
$1 name
313 config_get status
$1 status
314 config_get statusmessage
$1 statusmessage
316 [ -z "$username" -o -z "$secret" ] && return
318 # Construct a jabber entry for this provider.
319 sed "s/|USERNAME|/$username/g" $TMPL_JABBERUSER |\
320 sed "s/|NAME|/$name/g" > $WORKDIR/jabber.tmp
322 if [ "$register" = yes ] ; then
323 # If this provider is enabled for incoming calls, we need to set the
324 # status of the user to something other than unavailable in order to receive calls.
325 sed -i "s/|STATUS|/$status/g" $WORKDIR/jabber.tmp
326 sed -i "s/|STATUSMESSAGE|/\"$statusmessage\"/g" $WORKDIR/jabber.tmp
328 users_to_ring
="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
329 # If no users have been specified to ring, we ring all users enabled for incoming calls.
330 if [ -z "$users_to_ring" ] ; then
331 users_to_ring
=$localusers_to_ring
333 # Else, we cook up a string formatted for the Dial command
334 # with the specified users (SIP/user1&SIP/user2&...). We do it
335 # with set, shift and a loop in order to be more tolerant of ugly whitespace
336 # messes entered by users.
338 users_to_ring
="SIP\/$1" && shift
339 for u
in $@
; do users_to_ring
=$users_to_ring\\\
&SIP
\\\
/$u ; done
342 # Now, we add this account to the gtalk incoming context.
343 sed "s/|USERNAME|/$username/g" $TMPL_EXTINCNTXTGTALK |\
344 sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/outextgtalk.TMP
346 sed -i "s/|STATUS|/$GTALKUNVL/g" $WORKDIR/jabber.tmp
347 sed -i "s/|STATUSMESSAGE|/\"\"/g" $WORKDIR/jabber.tmp
350 # Add this account's configuration to the temp file containing all account configs.
351 sed "s/|SECRET|/$secret/g" $WORKDIR/jabber.tmp
>> $WORKDIR/jabber.TMP
353 # If this provider is enabled for outgoing calls.
354 if [ "$make_outgoing_calls" = "yes" ] ; then
356 numprefix
="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
358 # If no prefixes are specified, then we use "X" which matches any prefix.
359 [ -z "$numprefix" ] && numprefix
="X"
361 for p
in $numprefix ; do
362 sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTGTALK |\
363 sed "s/|NAME|/$name/g" >> $WORKDIR/outext-
$name.TMP
366 # Add this provider to the list of enabled outbound providers.
367 if [ -z "$outbound_providers" ] ; then
368 outbound_providers
="$name"
370 outbound_providers
="$outbound_providers $name"
374 rm -f $WORKDIR/jabber.tmp
377 # Creates configuration for a SIP provider account, and adds it to the temporary file that holds
378 # all accounts configured so far.
379 # Also creates the outgoing extensions which are used in users' outgoing contexts.
388 local make_outgoing_calls
394 config_get defaultuser
$1 defaultuser
395 config_get secret
$1 secret
396 config_get
host $1 host
397 config_get port
$1 port
398 config_get outbountproxy
$1 outboundproxy
399 config_get fromdomain
$1 fromdomain
400 config_get register
$1 register
401 config_get numprefix
$1 numprefix
402 config_get make_outgoing_calls
$1 make_outgoing_calls
403 config_get name
$1 name
405 [ -z "$defaultuser" -o -z "$secret" -o -z "$host" ] && return
406 [ -z "$fromdomain" ] && fromdomain
=$host
407 [ -n "$port" ] && port
="port=$port"
408 [ -n "$outboundproxy" ] && outboundproxy
="outboundproxy=$outboundproxy"
410 # Construct a sip peer entry for this provider.
411 sed "s/|DEFAULTUSER|/$defaultuser/" $TMPL_SIPPEER > $WORKDIR/sip_peer.tmp
412 sed -i "s/|NAME|/$name/" $WORKDIR/sip_peer.tmp
413 sed -i "s/|FROMUSER|/$defaultuser/" $WORKDIR/sip_peer.tmp
414 sed -i "s/|SECRET|/$secret/" $WORKDIR/sip_peer.tmp
415 sed -i "s/|HOST|/$host/" $WORKDIR/sip_peer.tmp
416 sed -i "s/|PORT|/$port/" $WORKDIR/sip_peer.tmp
417 sed -i "s/|OUTBOUNDPROXY|/$outboundproxy/" $WORKDIR/sip_peer.tmp
418 # Add this account's configuration to the temp file containing all account configs.
419 sed "s/|FROMDOMAIN|/$host/" $WORKDIR/sip_peer.tmp
>> $WORKDIR/sip_peers.TMP
421 # If this provider is enabled for incoming calls.
422 if [ "$register" = "yes" ] ; then
423 # Then we create a registration string for this provider.
424 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPREG > $WORKDIR/sip_reg.tmp
425 sed -i "s/|SECRET|/$secret/g" $WORKDIR/sip_reg.tmp
426 sed "s/|NAME|/$name/g" $WORKDIR/sip_reg.tmp
>> $WORKDIR/sip_regs.TMP
428 users_to_ring
="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
429 # If no users have been specified to ring, we ring all users enabled for incoming calls.
430 if [ -z "$users_to_ring" ] ; then
431 users_to_ring
=$localusers_to_ring
433 # Else, we cook up a string formatted for the Dial command
434 # with the specified users (SIP/user1&SIP/user2&...). We do it
435 # with set, shift and a loop in order to be more tolerant of ugly whitespace
436 # messes entered by users.
438 users_to_ring
="SIP\/$1" && shift
439 for u
in $@
; do users_to_ring
=$users_to_ring\\\
&SIP
\\\
/$u ; done
442 # And we create an incoming calls context for this provider.
443 sed "s/|NAME|/$name/g" $TMPL_EXTINCNTXTSIP |\
444 sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/inext.TMP
447 # If this provider is enabled for outgoing calls.
448 if [ "$make_outgoing_calls" = "yes" ] ; then
450 numprefix
="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
451 # If no prefixes are specified, then we use "X" which matches any prefix.
452 [ -z "$numprefix" ] && numprefix
="X"
453 for p
in $numprefix ; do
454 sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTSIP |\
455 sed "s/|NAME|/$name/g" >> $WORKDIR/outext-
$name.TMP
458 # Add this provider to the list of enabled outbound providers.
459 if [ -z "$outbound_providers" ] ; then
460 outbound_providers
="$name"
462 outbound_providers
="$outbound_providers $name"
466 rm -f $WORKDIR/sip_peer.tmp
467 rm -f $WORKDIR/sip_reg.tmp
470 # For all local users enabled for outbound calls, creates a context
471 # containing the extensions for Google and SIP accounts this user is
473 pbx_create_user_contexts
()
477 for u
in $localusers_can_dial ; do
478 sed "s/|DEFAULTUSER|/$u/g" $TMPL_EXTUSERCNTXTHDR >> $WORKDIR/userext.TMP
479 cat $WORKDIR/localext.TMP
>> $WORKDIR/userext.TMP
480 providers
="`uci -q get ${MODULENAME}-calls.providers_user_can_use.$u`"
481 [ -z "$providers" ] && providers
="$outbound_providers"
483 # For each provider, cat the contents of outext-$name.TMP into the user's outgoing calls extension
484 for p
in $providers ; do
485 [ -f $WORKDIR/outext-
$p.TMP
] && cat $WORKDIR/outext-
$p.TMP
>> $WORKDIR/userext.TMP
487 cat $TMPL_EXTUSERCNTXTFTR >> $WORKDIR/userext.TMP
491 # Creates the blacklist context which hangs up on blacklisted numbers.
497 config_get blacklist1 blacklisting blacklist1
498 config_get blacklist2 blacklisting blacklist2
500 # We create the blacklist context no matter whether the blacklist
501 # actually contains entries or not, since the PBX will send calls
502 # to the context for a check against the list anyway.
503 cp $TMPL_EXTBLKLISTHDR $WORKDIR/blacklist.TMP
504 for n
in $blacklist1 $blacklist2 ; do
505 sed "s/|BLACKLISTITEM|/$n/g" $TMPL_EXTBLKLIST >> $WORKDIR/blacklist.TMP
507 cat $TMPL_EXTBLKLISTFTR >> $WORKDIR/blacklist.TMP
510 # Creates the callthrough context which allows specified numbers to get
511 # into the PBX and dial out as the configured user.
512 pbx_add_callthrough
()
514 local callthrough_number_list
519 config_get callthrough_number_list
$1 callthrough_number_list
520 config_get defaultuser
$1 defaultuser
521 config_get pin
$1 pin
522 config_get enabled
$1 enabled
524 [ "$enabled" = "no" ] && return
525 [ "$defaultuser" = "" ] && return
527 for callthrough_number
in $callthrough_number_list ; do
528 sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRUCHECK >> $WORKDIR/callthroughcheck.TMP
530 sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRU |\
531 sed "s/|DEFAULTUSER|/$defaultuser/" |\
532 sed "s/|PIN|/$pin/" >> $WORKDIR/callthrough.TMP
536 # Creates sip.conf from its template.
537 pbx_cook_sip_template
()
543 config_get useragent advanced useragent
544 config_get externhost advanced externhost
545 config_get bindport advanced bindport
547 [ -z "$useragent" ] && useragent
="$USERAGENT"
549 sed "s/|USERAGENT|/$useragent/g" $TMPL_SIP > $WORKDIR/sip.conf
551 if [ -z "$externhost" ] ; then
552 sed -i "s/externhost=|EXTERNHOST|//g" $WORKDIR/sip.conf
554 sed -i "s/|EXTERNHOST|/$externhost/g" $WORKDIR/sip.conf
557 if [ -z "$bindport" ] ; then
558 sed -i "s/bindport=|BINDPORT|//g" $WORKDIR/sip.conf
560 sed -i "s/|BINDPORT|/$bindport/g" $WORKDIR/sip.conf
566 # Creates rtp.conf from its template.
567 pbx_cook_rtp_template
()
572 config_get rtpstart advanced rtpstart
573 config_get rtpend advanced rtpend
575 sed "s/|RTPSTART|/$rtpstart/" $TMPL_RTP |\
576 sed "s/|RTPEND|/$rtpend/" > $WORKDIR/rtp.conf
579 # Makes sure the ownership of specified directories is proper.
582 chown
$ASTUSER:$ASTGROUP $ASTDIRS
583 chown
$ASTUSER:$ASTGROUP -R $ASTDIRSRECURSIVE
587 # Creates voicemail config if installed and enabled.
588 pbx_configure_voicemail
()
592 local global_email_addresses
601 config_get enabled global_voicemail enabled
603 # First check if voicemail is enabled.
604 [ "$enabled" != "yes" ] && exit
606 config_get global_timeout global_voicemail global_timeout
607 #config_get global_email_addresses global_voicemail global_email_addresses
608 config_get smtp_auth voicemail_smtp smtp_auth
609 config_get smtp_tls voicemail_smtp smtp_tls
610 config_get smtp_server voicemail_smtp smtp_server
611 config_get smtp_port voicemail_smtp smtp_port
612 config_get smtp_user voicemail_smtp smtp_user
613 config_get smtp_password voicemail_smtp smtp_password
615 sed "s/|AUTH|/$smtp_auth/" $TMPL_MSMTPDEFAULT |\
616 sed "s/|TLS|/$smtp_tls/" > $WORKDIR/pbx-msmtprc
618 sed "s/|HOST|/$smtp_server/" $TMPL_MSMTPACCOUNT |\
619 sed "s/|PORT|/$smtp_port/" >> $WORKDIR/pbx-msmtprc
621 if [ "$smtp_auth" = "on" ] ; then
622 sed "s/|USER|/$smtp_user/" $TMPL_MSMTPAUTH |\
623 sed "s/|PASSWORD|/$smtp_password/" >> $WORKDIR/pbx-msmtprc
626 cat $TMPL_MSMTPACCTDFLT >> $WORKDIR/pbx-msmtprc
628 [ ! -f /etc
/pbx-msmtprc
] && cp $WORKDIR/pbx-msmtprc
/etc
/pbx-msmtprc
629 diff -q $WORKDIR/pbx-msmtprc
/etc
/pbx-msmtprc
1>/dev
/null \
630 ||
mv $WORKDIR/pbx-msmtprc
/etc
/pbx-msmtprc
631 chmod 600 /etc
/pbx-msmtprc
633 # Copy over the extensions file which has voicemail enabled.
634 cp $TMPL_EXTVMENABLED $WORKDIR/extensions_voicemail.conf
642 config_load
${MODULENAME}-users
643 config_foreach pbx_add_user local_user
645 # Create configuration for each google account.
647 config_load
${MODULENAME}-google
648 config_foreach pbx_add_jabber gtalk_jabber
650 # Create configuration for each voip provider.
652 config_load
${MODULENAME}-voip
653 config_foreach pbx_add_peer voip_provider
655 # Create the user contexts, and phone blacklist.
657 config_load
${MODULENAME}-calls
658 pbx_create_user_contexts
660 config_foreach pbx_add_callthrough callthrough_numbers
662 # Prepare sip.conf using settings from the "advanced" section.
664 config_load
${MODULENAME}-advanced
665 pbx_cook_sip_template
666 pbx_cook_rtp_template
668 # Prepare sip.conf using settings from the "advanced" section.
670 config_load
${MODULENAME}-voicemail
671 pbx_configure_voicemail
673 # Assemble the configuration, and copy changed files over.
675 config_load
${MODULENAME}-advanced
676 pbx_assemble_and_copy_config
678 # Enforce ownership of specified files and directories.