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 FIREWALL_PATH="/etc/asterisk/firewall.$MODULENAME"
38 TEMPLATEDIR=/etc/${MODULENAME}-asterisk
39 ASTERISKDIR=/etc/asterisk
40 WORKDIR=/tmp/$MODULENAME.$$
41 MD5SUMSFILE=/tmp/$MODULENAME-sums.$$
43 TMPL_ASTERISK=$TEMPLATEDIR/asterisk.conf.TEMPLATE
44 TMPL_GTALK=$TEMPLATEDIR/gtalk.conf.TEMPLATE
45 TMPL_INDICATIONS=$TEMPLATEDIR/indications.conf.TEMPLATE
46 TMPL_LOGGER=$TEMPLATEDIR/logger.conf.TEMPLATE
47 TMPL_MANAGER=$TEMPLATEDIR/manager.conf.TEMPLATE
48 TMPL_MODULES=$TEMPLATEDIR/modules.conf.TEMPLATE
49 TMPL_RTP=$TEMPLATEDIR/rtp.conf.TEMPLATE
51 TMPL_EXTCTHRUCHECKHDR=$TEMPLATEDIR/extensions_disa-check_header.conf.TEMPLATE
52 TMPL_EXTCTHRUCHECK=$TEMPLATEDIR/extensions_disa-check.conf.TEMPLATE
53 TMPL_EXTCTHRUCHECKFTR=$TEMPLATEDIR/extensions_disa-check_footer.conf.TEMPLATE
54 TMPL_EXTCTHRUHDR=$TEMPLATEDIR/extensions_disa_header.conf.TEMPLATE
55 TMPL_EXTCTHRU=$TEMPLATEDIR/extensions_disa.conf.TEMPLATE
57 TMPL_EXTENSIONS=$TEMPLATEDIR/extensions.conf.TEMPLATE
59 TMPL_EXTBLKLIST=$TEMPLATEDIR/extensions_blacklist.conf.TEMPLATE
60 TMPL_EXTBLKLISTFTR=$TEMPLATEDIR/extensions_blacklist_footer.conf.TEMPLATE
61 TMPL_EXTBLKLISTHDR=$TEMPLATEDIR/extensions_blacklist_header.conf.TEMPLATE
63 TMPL_EXTINCNTXTSIP=$TEMPLATEDIR/extensions_incoming_context_sip.conf.TEMPLATE
64 TMPL_EXTINCNTXTGTALKHDR=$TEMPLATEDIR/extensions_incoming_context_gtalk_header.conf.TEMPLATE
65 TMPL_EXTINCNTXTGTALK=$TEMPLATEDIR/extensions_incoming_context_gtalk.conf.TEMPLATE
67 TMPL_EXTUSERCNTXT=$TEMPLATEDIR/extensions_user_context.conf.TEMPLATE
68 TMPL_EXTUSERCNTXTFTR=$TEMPLATEDIR/extensions_user_context_footer.conf.TEMPLATE
69 TMPL_EXTUSERCNTXTHDR=$TEMPLATEDIR/extensions_user_context_header.conf.TEMPLATE
71 TMPL_EXTOUTHDR=$TEMPLATEDIR/extensions_default_outgoing_header.conf.TEMPLATE
72 TMPL_EXTOUTGTALK=$TEMPLATEDIR/extensions_outgoing_gtalk.conf.TEMPLATE
73 TMPL_EXTOUTLOCAL=$TEMPLATEDIR/extensions_outgoing_dial_local_user.conf.TEMPLATE
74 TMPL_EXTOUTSIP=$TEMPLATEDIR/extensions_outgoing_sip.conf.TEMPLATE
76 TMPL_FIREWALL=$TEMPLATEDIR/firewall.$MODULENAME.TEMPLATE
77 TMPL_JABBER=$TEMPLATEDIR/jabber.conf.TEMPLATE
78 TMPL_JABBERUSER=$TEMPLATEDIR/jabber_users.conf.TEMPLATE
79 TMPL_SIP=$TEMPLATEDIR/sip.conf.TEMPLATE
80 TMPL_SIPPEER=$TEMPLATEDIR/sip_peer.TEMPLATE
81 TMPL_SIPREG=$TEMPLATEDIR/sip_registration.TEMPLATE
82 TMPL_SIPUSR=$TEMPLATEDIR/sip_user.TEMPLATE
84 INCLUDED_FILES="$WORKDIR/extensions_blacklist.conf $WORKDIR/extensions_callthrough.conf\
85 $WORKDIR/extensions_incoming.conf $WORKDIR/extensions_incoming_gtalk.conf\
86 $WORKDIR/extensions_user.conf $WORKDIR/jabber_users.conf\
87 $WORKDIR/sip_peers.conf $WORKDIR/sip_registrations.conf\
88 $WORKDIR/sip_users.conf"
91 # In this string, we concatenate all local users enabled to receive calls
92 # readily formatted for the Dial command.
94 # In this string, we keep a list of all users that are enabled for outgoing
95 # calls. It is used at the end to create the user contexts.
96 localusers_can_dial=""
98 # In this string, we put together a space-separated list of provider names
99 # (alphanumeric, with all non-alpha characters replaced with underscores),
100 # which will be used to dial out by default (whose outgoing contexts will
101 # be included in users' contexts by default.
102 outbound_providers=""
104 # Copies the template files which we don't edit.
105 copy_unedited_templates_over()
107 cp $TMPL_ASTERISK $WORKDIR/asterisk.conf
108 cp $TMPL_GTALK $WORKDIR/gtalk.conf
109 cp $TMPL_INDICATIONS $WORKDIR/indications.conf
110 cp $TMPL_LOGGER $WORKDIR/logger.conf
111 cp $TMPL_MANAGER $WORKDIR/manager.conf
112 cp $TMPL_MODULES $WORKDIR/modules.conf
115 # Touches all the included files, to prevent asterisk from refusing to
116 # start if a config item is missing and an included config file isn't created.
117 create_included_files()
119 touch $INCLUDED_FILES
122 # Puts together all the extensions.conf related configuration.
123 pbx_create_extensions_config()
125 sed "s/|LOCALUSERS|/$localusers_to_ring/g" $TMPL_EXTENSIONS > $WORKDIR/extensions.conf
126 mv $WORKDIR/inext.TMP $WORKDIR/extensions_incoming.conf
127 cp $TMPL_EXTINCNTXTGTALKHDR $WORKDIR/extensions_incoming_gtalk.conf
128 cat $WORKDIR/outextgtalk.TMP >> $WORKDIR/extensions_incoming_gtalk.conf 2>/dev/null
129 rm -f $WORKDIR/outextgtalk.TMP
130 mv $WORKDIR/blacklist.TMP $WORKDIR/extensions_blacklist.conf
131 mv $WORKDIR/userext.TMP $WORKDIR/extensions_user.conf
132 cp $TMPL_EXTCTHRUHDR $WORKDIR/extensions_callthrough.conf
133 cat $WORKDIR/callthrough.TMP >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
134 rm -f $WORKDIR/callthrough.TMP
135 cat $TMPL_EXTCTHRUCHECKHDR >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
136 cat $WORKDIR/callthroughcheck.TMP >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
137 rm -f $WORKDIR/callthroughcheck.TMP
138 cat $TMPL_EXTCTHRUCHECKFTR >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
139 rm -f $WORKDIR/outext-*.TMP
140 rm -f $WORKDIR/localext.TMP
143 # Puts together all the sip.conf related configuration.
144 pbx_create_sip_config()
146 mv $WORKDIR/sip_regs.TMP $WORKDIR/sip_registrations.conf
147 mv $WORKDIR/sip_peers.TMP $WORKDIR/sip_peers.conf
148 mv $WORKDIR/sip_users.TMP $WORKDIR/sip_users.conf
151 # Creates the jabber.conf related config
152 pbx_create_jabber_config()
154 cp $TMPL_JABBER $WORKDIR/jabber.conf
155 mv $WORKDIR/jabber.TMP $WORKDIR/jabber_users.conf
158 # Gets rid of any config files from $ASTERISKDIR not found in $WORKDIR.
159 clean_up_asterisk_config_dir()
161 for f in $ASTERISKDIR/* ; do
162 basef="`basename $f`"
163 if [ ! -e "$WORKDIR/$basef" ] ; then
169 # Compares md5sums of the config files in $WORKDIR to those
170 # in $ASTERISKDIR, and copies only changed files over to reduce
171 # wear on flash in embedded devices.
172 compare_configs_and_copy_changed()
174 # First, compute md5sums of the config files in $WORKDIR.
176 md5sum * > $MD5SUMSFILE
178 # Now, check the files in $ASTERISKDIR against the md5sums.
180 changed_files="`md5sum -c $MD5SUMSFILE 2>/dev/null | fgrep ": FAILED" | awk -F: '{print $1}'`"
184 [ -z "$changed_files" ] && return
186 # Now copy over the changed files.
187 for f in $changed_files ; do
188 cp "$WORKDIR/$f" "$ASTERISKDIR/$f"
192 # Calls the functions that create the final config files
193 # Calls the function which compares which files have changed
194 # Puts the final touches on $ASTERISKDIR
195 # Gets rid of $WORKDIR
196 pbx_assemble_and_copy_config()
198 mkdir -p $ASTERISKDIR
200 copy_unedited_templates_over
201 create_included_files
202 pbx_create_extensions_config
203 pbx_create_sip_config
204 pbx_create_jabber_config
206 touch $WORKDIR/features.conf
208 # At this point, $WORKDIR should contain a complete, working config.
209 clean_up_asterisk_config_dir
211 compare_configs_and_copy_changed
213 [ ! -d $ASTERISKDIR/manager.d ] && mkdir -p $ASTERISKDIR/manager.d/
215 # Get rid of the working directory
219 # Creates configuration for a user and adds it to the temporary file that holds
220 # all users configured so far.
229 config_get fullname $1 fullname
230 config_get defaultuser $1 defaultuser
231 config_get secret $1 secret
232 config_get ring $1 ring
233 config_get can_call $1 can_call
235 [ -z "$defaultuser" -o -z "$secret" ] && return
236 [ -z "$fullname" ] && fullname="$defaultuser"
238 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPUSR > $WORKDIR/sip_user.tmp
240 if [ "$can_call" = "yes" ] ; then
241 # Add user to list of all users that are allowed to make calls.
242 localusers_can_dial="$localusers_can_dial $defaultuser"
243 sed -i "s/|CONTEXTNAME|/$defaultuser/g" $WORKDIR/sip_user.tmp
245 sed -i "s/|CONTEXTNAME|/$HANGUPCNTXT/g" $WORKDIR/sip_user.tmp
248 # Add this user's configuration to the temp file containing all user configs.
249 sed "s/|FULLNAME|/$fullname/" $WORKDIR/sip_user.tmp |\
250 sed "s/|SECRET|/$secret/g" >> $WORKDIR/sip_users.TMP
252 if [ "$ring" = "yes" ] ; then
253 if [ -z "$localusers_to_ring" ] ; then
254 localusers_to_ring="SIP\/$defaultuser"
256 localusers_to_ring="$localusers_to_ring\&SIP\/$defaultuser"
260 # Add configuration which allows local users to call each other.
261 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTOUTLOCAL >> $WORKDIR/localext.TMP
263 rm -f $WORKDIR/sip_user.tmp
266 # Creates configuration for a Google account, and adds it to the temporary file that holds
267 # all accounts configured so far.
268 # Also creates the outgoing extensions which are used in users' outgoing contexts.
275 local make_outgoing_calls
281 config_get username $1 username
282 config_get secret $1 secret
283 config_get numprefix $1 numprefix
284 config_get register $1 register
285 config_get make_outgoing_calls $1 make_outgoing_calls
286 config_get name $1 name
287 config_get status $1 status
288 config_get statusmessage $1 statusmessage
290 [ -z "$username" -o -z "$secret" ] && return
292 # Construct a jabber entry for this provider.
293 sed "s/|USERNAME|/$username/g" $TMPL_JABBERUSER |\
294 sed "s/|NAME|/$name/g" > $WORKDIR/jabber.tmp
296 if [ "$register" = yes ] ; then
297 # If this provider is enabled for incoming calls, we need to set the
298 # status of the user to something other than unavailable in order to receive calls.
299 sed -i "s/|STATUS|/$status/g" $WORKDIR/jabber.tmp
300 sed -i "s/|STATUSMESSAGE|/\"$statusmessage\"/g" $WORKDIR/jabber.tmp
302 users_to_ring="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
303 # If no users have been specified to ring, we ring all users enabled for incoming calls.
304 if [ -z "$users_to_ring" ] ; then
305 users_to_ring=$localusers_to_ring
307 # Else, we cook up a string formatted for the Dial command
308 # with the specified users (SIP/user1&SIP/user2&...). We do it
309 # with set, shift and a loop in order to be more tolerant of ugly whitespace
310 # messes entered by users.
312 users_to_ring="SIP\/$1" && shift
313 for u in $@ ; do users_to_ring=$users_to_ring\\\&SIP\\\/$u ; done
316 # Now, we add this account to the gtalk incoming context.
317 sed "s/|USERNAME|/$username/g" $TMPL_EXTINCNTXTGTALK |\
318 sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/outextgtalk.TMP
320 sed -i "s/|STATUS|/$GTALKUNVL/g" $WORKDIR/jabber.tmp
321 sed -i "s/|STATUSMESSAGE|/\"\"/g" $WORKDIR/jabber.tmp
324 # Add this account's configuration to the temp file containing all account configs.
325 sed "s/|SECRET|/$secret/g" $WORKDIR/jabber.tmp >> $WORKDIR/jabber.TMP
327 # If this provider is enabled for outgoing calls.
328 if [ "$make_outgoing_calls" = "yes" ] ; then
330 numprefix="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
332 # If no prefixes are specified, then we use "X" which matches any prefix.
333 [ -z "$numprefix" ] && numprefix="X"
335 for p in $numprefix ; do
336 sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTGTALK |\
337 sed "s/|NAME|/$name/g" >> $WORKDIR/outext-$name.TMP
340 # Add this provider to the list of enabled outbound providers.
341 if [ -z "$outbound_providers" ] ; then
342 outbound_providers="$name"
344 outbound_providers="$outbound_providers $name"
348 rm -f $WORKDIR/jabber.tmp
351 # Creates configuration for a SIP provider account, and adds it to the temporary file that holds
352 # all accounts configured so far.
353 # Also creates the outgoing extensions which are used in users' outgoing contexts.
362 local make_outgoing_calls
368 config_get defaultuser $1 defaultuser
369 config_get secret $1 secret
370 config_get host $1 host
371 config_get port $1 port
372 config_get outbountproxy $1 outboundproxy
373 config_get fromdomain $1 fromdomain
374 config_get register $1 register
375 config_get numprefix $1 numprefix
376 config_get make_outgoing_calls $1 make_outgoing_calls
377 config_get name $1 name
379 [ -z "$defaultuser" -o -z "$secret" -o -z "$host" ] && return
380 [ -z "$fromdomain" ] && fromdomain=$host
381 [ -n "$port" ] && port="port=$port"
382 [ -n "$outboundproxy" ] && outboundproxy="outboundproxy=$outboundproxy"
384 # Construct a sip peer entry for this provider.
385 sed "s/|DEFAULTUSER|/$defaultuser/" $TMPL_SIPPEER > $WORKDIR/sip_peer.tmp
386 sed -i "s/|NAME|/$name/" $WORKDIR/sip_peer.tmp
387 sed -i "s/|FROMUSER|/$defaultuser/" $WORKDIR/sip_peer.tmp
388 sed -i "s/|SECRET|/$secret/" $WORKDIR/sip_peer.tmp
389 sed -i "s/|HOST|/$host/" $WORKDIR/sip_peer.tmp
390 sed -i "s/|PORT|/$port/" $WORKDIR/sip_peer.tmp
391 sed -i "s/|OUTBOUNDPROXY|/$outboundproxy/" $WORKDIR/sip_peer.tmp
392 # Add this account's configuration to the temp file containing all account configs.
393 sed "s/|FROMDOMAIN|/$host/" $WORKDIR/sip_peer.tmp >> $WORKDIR/sip_peers.TMP
395 # If this provider is enabled for incoming calls.
396 if [ "$register" = "yes" ] ; then
397 # Then we create a registration string for this provider.
398 sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPREG > $WORKDIR/sip_reg.tmp
399 sed -i "s/|SECRET|/$secret/g" $WORKDIR/sip_reg.tmp
400 sed "s/|NAME|/$name/g" $WORKDIR/sip_reg.tmp >> $WORKDIR/sip_regs.TMP
402 users_to_ring="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
403 # If no users have been specified to ring, we ring all users enabled for incoming calls.
404 if [ -z "$users_to_ring" ] ; then
405 users_to_ring=$localusers_to_ring
407 # Else, we cook up a string formatted for the Dial command
408 # with the specified users (SIP/user1&SIP/user2&...). We do it
409 # with set, shift and a loop in order to be more tolerant of ugly whitespace
410 # messes entered by users.
412 users_to_ring="SIP\/$1" && shift
413 for u in $@ ; do users_to_ring=$users_to_ring\\\&SIP\\\/$u ; done
416 # And we create an incoming calls context for this provider.
417 sed "s/|NAME|/$name/g" $TMPL_EXTINCNTXTSIP |\
418 sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/inext.TMP
421 # If this provider is enabled for outgoing calls.
422 if [ "$make_outgoing_calls" = "yes" ] ; then
424 numprefix="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
425 # If no prefixes are specified, then we use "X" which matches any prefix.
426 [ -z "$numprefix" ] && numprefix="X"
427 for p in $numprefix ; do
428 sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTSIP |\
429 sed "s/|NAME|/$name/g" >> $WORKDIR/outext-$name.TMP
432 # Add this provider to the list of enabled outbound providers.
433 if [ -z "$outbound_providers" ] ; then
434 outbound_providers="$name"
436 outbound_providers="$outbound_providers $name"
440 rm -f $WORKDIR/sip_peer.tmp
441 rm -f $WORKDIR/sip_reg.tmp
444 # For all local users enabled for outbound calls, creates a context
445 # containing the extensions for Google and SIP accounts this user is
447 pbx_create_user_contexts()
451 for u in $localusers_can_dial ; do
452 sed "s/|DEFAULTUSER|/$u/g" $TMPL_EXTUSERCNTXTHDR >> $WORKDIR/userext.TMP
453 cat $WORKDIR/localext.TMP >> $WORKDIR/userext.TMP
454 providers="`uci -q get ${MODULENAME}-calls.providers_user_can_use.$u`"
455 [ -z "$providers" ] && providers="$outbound_providers"
457 # For each provider, cat the contents of outext-$name.TMP into the user's outgoing calls extension
458 for p in $providers ; do
459 [ -f $WORKDIR/outext-$p.TMP ] && cat $WORKDIR/outext-$p.TMP >> $WORKDIR/userext.TMP
461 cat $TMPL_EXTUSERCNTXTFTR >> $WORKDIR/userext.TMP
465 # Creates the blacklist context which hangs up on blacklisted numbers.
471 config_get blacklist1 blacklisting blacklist1
472 config_get blacklist2 blacklisting blacklist2
474 # We create the blacklist context no matter whether the blacklist
475 # actually contains entries or not, since the PBX will send calls
476 # to the context for a check against the list anyway.
477 cp $TMPL_EXTBLKLISTHDR $WORKDIR/blacklist.TMP
478 for n in $blacklist1 $blacklist2 ; do
479 sed "s/|BLACKLISTITEM|/$n/g" $TMPL_EXTBLKLIST >> $WORKDIR/blacklist.TMP
481 cat $TMPL_EXTBLKLISTFTR >> $WORKDIR/blacklist.TMP
484 # Creates the callthrough context which allows specified numbers to get
485 # into the PBX and dial out as the configured user.
486 pbx_add_callthrough()
488 local callthrough_number_list
493 config_get callthrough_number_list $1 callthrough_number_list
494 config_get defaultuser $1 defaultuser
495 config_get pin $1 pin
496 config_get enabled $1 enabled
498 [ "$enabled" = "no" ] && return
499 [ "$defaultuser" = "" ] && return
501 for callthrough_number in $callthrough_number_list ; do
502 sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRUCHECK >> $WORKDIR/callthroughcheck.TMP
504 sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRU |\
505 sed "s/|DEFAULTUSER|/$defaultuser/" |\
506 sed "s/|PIN|/$pin/" >> $WORKDIR/callthrough.TMP
510 # Creates sip.conf from its template.
511 pbx_cook_sip_template()
517 config_get useragent advanced useragent
518 config_get externhost advanced externhost
519 config_get bindport advanced bindport
521 [ -z "$useragent" ] && useragent="$USERAGENT"
523 sed "s/|USERAGENT|/$useragent/g" $TMPL_SIP > $WORKDIR/sip.conf
525 if [ -z "$externhost" ] ; then
526 sed -i "s/externhost=|EXTERNHOST|//g" $WORKDIR/sip.conf
528 sed -i "s/|EXTERNHOST|/$externhost/g" $WORKDIR/sip.conf
531 if [ -z "$bindport" ] ; then
532 sed -i "s/bindport=|BINDPORT|//g" $WORKDIR/sip.conf
534 sed -i "s/|BINDPORT|/$bindport/g" $WORKDIR/sip.conf
540 # Creates rtp.conf from its template.
541 pbx_cook_rtp_template()
546 config_get rtpstart advanced rtpstart
547 config_get rtpend advanced rtpend
549 sed "s/|RTPSTART|/$rtpstart/" $TMPL_RTP |\
550 sed "s/|RTPEND|/$rtpend/" > $WORKDIR/rtp.conf
553 # Makes sure the ownership of specified directories is proper.
556 chown $ASTUSER:$ASTGROUP $ASTDIRS
557 chown $ASTUSER:$ASTGROUP -R $ASTDIRSRECURSIVE
560 # Creates firewall configuration. However, since this functionality is now
561 # taken over by pbx-advanced.lua, this function is unused.
562 create_firewall_config()
569 config_get bindport advanced bindport
570 config_get externhost advanced externhost
571 config_get rtpstart advanced rtpstart
572 config_get rtpend advanced rtpend
574 # We need all of these parameters to be set in order to consider inserting firewall rules.
575 if [ -z "$externhost" -o -z "$bindport" -o -z "$rtpstart" -o -z "$rtpend" ] ; then
580 sed "s/|SIPPORT|/$bindport/g" $TMPL_FIREWALL |\
581 sed "s/|RTPRANGE|/$rtpstart:$rtpend/g" > $WORKDIR/firewall.$MODULENAME
583 # Make sure there is an include section in the firewall configuration
584 # to include the file we just created.
586 while p=`uci get firewall.@include[$i].path 2>/dev/null` ; do
587 if [ "$p" = "$FIREWALL_PATH" ] ; then
594 # If no include section was found which mentions $FIREWALL_PATH, add one.
595 if [ $found_path -eq 0 ] ; then
596 uci add firewall include 1>/dev/null 2>/dev/null
597 uci set firewall.@include[-1].path="$FIREWALL_PATH"
606 config_load ${MODULENAME}-users
607 config_foreach pbx_add_user local_user
609 # Create configuration for each google account.
611 config_load ${MODULENAME}-google
612 config_foreach pbx_add_jabber gtalk_jabber
614 # Create configuration for each voip provider.
616 config_load ${MODULENAME}-voip
617 config_foreach pbx_add_peer voip_provider
619 # Create the user contexts, and phone blacklist.
621 config_load ${MODULENAME}-calls
622 pbx_create_user_contexts
624 config_foreach pbx_add_callthrough callthrough_numbers
626 # Prepare sip.conf using settings from the "advanced" section.
628 config_load ${MODULENAME}-advanced
629 pbx_cook_sip_template
630 pbx_cook_rtp_template
632 # Assemble the configuration, and copy changed files over.
633 pbx_assemble_and_copy_config
635 # Enforce ownership of specified files and directories.