summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-pbx/root
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-12-03 15:17:05 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-08 16:26:20 +0100
commit1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch)
tree35e16f100466e4e00657199b38bb3d87d52bf73f /applications/luci-app-pbx/root
parent9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff)
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names * Make each LuCI module its own standalone package * Deploy a shared luci.mk which is used by each module Makefile Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-pbx/root')
-rw-r--r--applications/luci-app-pbx/root/etc/config/pbx1
-rw-r--r--applications/luci-app-pbx/root/etc/config/pbx-advanced5
-rw-r--r--applications/luci-app-pbx/root/etc/config/pbx-calls7
-rw-r--r--applications/luci-app-pbx/root/etc/config/pbx-google0
-rw-r--r--applications/luci-app-pbx/root/etc/config/pbx-users1
-rw-r--r--applications/luci-app-pbx/root/etc/config/pbx-voip0
-rwxr-xr-xapplications/luci-app-pbx/root/etc/init.d/pbx-asterisk837
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE17
-rwxr-xr-xapplications/luci-app-pbx/root/etc/pbx-asterisk/delayedcallback18
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE25
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE2
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE3
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_footer.conf.TEMPLATE2
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_header.conf.TEMPLATE3
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_gtalk.conf.TEMPLATE4
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_header.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_sip.conf.TEMPLATE4
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default.conf.TEMPLATE11
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default_user.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE2
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-nopin.conf.TEMPLATE5
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE6
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE15
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE12
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE9
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE2
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE1
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE8
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE2
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE3
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_disabled.conf.TEMPLATE4
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_enabled.conf.TEMPLATE27
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE10
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE733
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE4
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE8
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE7
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE7
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE34
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE6
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE39
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE13
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE2
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE11
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-alreadyon.gsmbin0 -> 8943 bytes
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-incorrect.gsmbin0 -> 8085 bytes
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-pass.gsmbin0 -> 4752 bytes
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-incorrect.gsmbin0 -> 7458 bytes
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-thankyou.gsmbin0 -> 1353 bytes
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/beep.gsmbin0 -> 726 bytes
-rw-r--r--applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/vm-goodbye.gsmbin0 -> 1683 bytes
58 files changed, 1919 insertions, 0 deletions
diff --git a/applications/luci-app-pbx/root/etc/config/pbx b/applications/luci-app-pbx/root/etc/config/pbx
new file mode 100644
index 000000000..ca7c1669d
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/config/pbx
@@ -0,0 +1 @@
+config 'main' 'connection_status'
diff --git a/applications/luci-app-pbx/root/etc/config/pbx-advanced b/applications/luci-app-pbx/root/etc/config/pbx-advanced
new file mode 100644
index 000000000..39da6f880
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/config/pbx-advanced
@@ -0,0 +1,5 @@
+config 'settings' 'advanced'
+ option 'useragent' 'PBX'
+ option 'ringtime' '30'
+ option 'rtpstart' '19850'
+ option 'rtpend' '19900'
diff --git a/applications/luci-app-pbx/root/etc/config/pbx-calls b/applications/luci-app-pbx/root/etc/config/pbx-calls
new file mode 100644
index 000000000..822bd4a1b
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/config/pbx-calls
@@ -0,0 +1,7 @@
+config 'call_routing' 'outgoing_calls'
+
+config 'call_routing' 'incoming_calls'
+
+config 'call_routing' 'providers_user_can_use'
+
+config 'call_routing' 'blacklisting'
diff --git a/applications/luci-app-pbx/root/etc/config/pbx-google b/applications/luci-app-pbx/root/etc/config/pbx-google
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/config/pbx-google
diff --git a/applications/luci-app-pbx/root/etc/config/pbx-users b/applications/luci-app-pbx/root/etc/config/pbx-users
new file mode 100644
index 000000000..a4277b1bf
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/config/pbx-users
@@ -0,0 +1 @@
+config 'user' 'server'
diff --git a/applications/luci-app-pbx/root/etc/config/pbx-voip b/applications/luci-app-pbx/root/etc/config/pbx-voip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/config/pbx-voip
diff --git a/applications/luci-app-pbx/root/etc/init.d/pbx-asterisk b/applications/luci-app-pbx/root/etc/init.d/pbx-asterisk
new file mode 100755
index 000000000..e05ae11cd
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/init.d/pbx-asterisk
@@ -0,0 +1,837 @@
+#!/bin/sh /etc/rc.common
+#
+# Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+#
+# This file is part of luci-pbx.
+#
+# luci-pbx is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# luci-pbx is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+
+. /lib/functions.sh
+
+START=60
+
+# Some global variables
+MODULENAME=pbx
+USERAGENT="PBX"
+HANGUPCNTXT=hangup-call-context
+GTALKUNVL=unavailable
+
+ASTUSER=nobody
+ASTGROUP=nogroup
+ASTDIRSRECURSIVE="/var/run/asterisk /var/log/asterisk /var/spool/asterisk"
+ASTDIRS="/usr/lib/asterisk"
+ASTSOUNDSDIR="/usr/lib/asterisk/sounds"
+
+TEMPLATEDIR=/etc/${MODULENAME}-asterisk
+PBXSOUNDSDIR=$TEMPLATEDIR/sounds
+VMTEMPLATEDIR=/etc/${MODULENAME}-voicemail
+VMSOUNDSDIR=$VMTEMPLATEDIR/sounds
+ASTERISKDIR=/etc/asterisk
+WORKDIR=/tmp/$MODULENAME.$$
+MD5SUMSFILE=/tmp/$MODULENAME-sums.$$
+
+TMPL_ASTERISK=$TEMPLATEDIR/asterisk.conf.TEMPLATE
+TMPL_GTALK=$TEMPLATEDIR/gtalk.conf.TEMPLATE
+TMPL_INDICATIONS=$TEMPLATEDIR/indications.conf.TEMPLATE
+TMPL_LOGGER=$TEMPLATEDIR/logger.conf.TEMPLATE
+TMPL_MANAGER=$TEMPLATEDIR/manager.conf.TEMPLATE
+TMPL_MODULES=$TEMPLATEDIR/modules.conf.TEMPLATE
+TMPL_RTP=$TEMPLATEDIR/rtp.conf.TEMPLATE
+
+TMPL_EXTCTHRUCHECKHDR=$TEMPLATEDIR/extensions_disa-check_header.conf.TEMPLATE
+TMPL_EXTCTHRUCHECK=$TEMPLATEDIR/extensions_disa-check.conf.TEMPLATE
+TMPL_EXTCTHRUCHECKFTR=$TEMPLATEDIR/extensions_disa-check_footer.conf.TEMPLATE
+TMPL_EXTCTHRUHDR=$TEMPLATEDIR/extensions_disa_header.conf.TEMPLATE
+TMPL_EXTCTHRU=$TEMPLATEDIR/extensions_disa.conf.TEMPLATE
+TMPL_EXTCTHRUNOPIN=$TEMPLATEDIR/extensions_disa-nopin.conf.TEMPLATE
+
+TMPL_EXTCBACKCHECKHDR=$TEMPLATEDIR/extensions_callback-check_header.conf.TEMPLATE
+TMPL_EXTCBACKCHECK=$TEMPLATEDIR/extensions_callback-check.conf.TEMPLATE
+TMPL_EXTCBACKCHECKFTR=$TEMPLATEDIR/extensions_callback-check_footer.conf.TEMPLATE
+TMPL_EXTCBACKHDR=$TEMPLATEDIR/extensions_callback_header.conf.TEMPLATE
+TMPL_EXTCBACKSIP=$TEMPLATEDIR/extensions_callback_sip.conf.TEMPLATE
+TMPL_EXTCBACKGTALK=$TEMPLATEDIR/extensions_callback_gtalk.conf.TEMPLATE
+
+TMPL_EXTENSIONS=$TEMPLATEDIR/extensions.conf.TEMPLATE
+
+TMPL_EXTVMDISABLED=$TEMPLATEDIR/extensions_voicemail_disabled.conf.TEMPLATE
+TMPL_EXTVMENABLED=$TEMPLATEDIR/extensions_voicemail_enabled.conf.TEMPLATE
+
+TMPL_EXTBLKLIST=$TEMPLATEDIR/extensions_blacklist.conf.TEMPLATE
+TMPL_EXTBLKLISTFTR=$TEMPLATEDIR/extensions_blacklist_footer.conf.TEMPLATE
+TMPL_EXTBLKLISTHDR=$TEMPLATEDIR/extensions_blacklist_header.conf.TEMPLATE
+
+TMPL_EXTDEFAULT=$TEMPLATEDIR/extensions_default.conf.TEMPLATE
+TMPL_EXTDEFAULTUSER=$TEMPLATEDIR/extensions_default_user.conf.TEMPLATE
+
+TMPL_EXTINCNTXTSIP=$TEMPLATEDIR/extensions_incoming_context_sip.conf.TEMPLATE
+TMPL_EXTINCNTXTGTALKHDR=$TEMPLATEDIR/extensions_incoming_context_gtalk_header.conf.TEMPLATE
+TMPL_EXTINCNTXTGTALK=$TEMPLATEDIR/extensions_incoming_context_gtalk.conf.TEMPLATE
+
+TMPL_EXTUSERCNTXT=$TEMPLATEDIR/extensions_user_context.conf.TEMPLATE
+TMPL_EXTUSERCNTXTFTR=$TEMPLATEDIR/extensions_user_context_footer.conf.TEMPLATE
+TMPL_EXTUSERCNTXTHDR=$TEMPLATEDIR/extensions_user_context_header.conf.TEMPLATE
+
+TMPL_EXTOUTHDR=$TEMPLATEDIR/extensions_default_outgoing_header.conf.TEMPLATE
+TMPL_EXTOUTGTALK=$TEMPLATEDIR/extensions_outgoing_gtalk.conf.TEMPLATE
+TMPL_EXTOUTLOCAL=$TEMPLATEDIR/extensions_outgoing_dial_local_user.conf.TEMPLATE
+TMPL_EXTOUTSIP=$TEMPLATEDIR/extensions_outgoing_sip.conf.TEMPLATE
+
+TMPL_JABBER=$TEMPLATEDIR/jabber.conf.TEMPLATE
+TMPL_JABBERUSER=$TEMPLATEDIR/jabber_users.conf.TEMPLATE
+TMPL_SIP=$TEMPLATEDIR/sip.conf.TEMPLATE
+TMPL_SIPPEER=$TEMPLATEDIR/sip_peer.TEMPLATE
+TMPL_SIPREG=$TEMPLATEDIR/sip_registration.TEMPLATE
+TMPL_SIPUSR=$TEMPLATEDIR/sip_user.TEMPLATE
+
+TMPL_MSMTPDEFAULT=$VMTEMPLATEDIR/pbx-msmtprc-defaults.TEMPLATE
+TMPL_MSMTPACCOUNT=$VMTEMPLATEDIR/pbx-msmtprc-account.TEMPLATE
+TMPL_MSMTPAUTH=$VMTEMPLATEDIR/pbx-msmtprc-account-auth.TEMPLATE
+TMPL_MSMTPACCTDFLT=$VMTEMPLATEDIR/pbx-msmtprc-account-default.TEMPLATE
+
+
+INCLUDED_FILES="$WORKDIR/extensions_blacklist.conf $WORKDIR/extensions_callthrough.conf\
+ $WORKDIR/extensions_incoming.conf $WORKDIR/extensions_incoming_gtalk.conf\
+ $WORKDIR/extensions_user.conf $WORKDIR/jabber_users.conf\
+ $WORKDIR/sip_peers.conf $WORKDIR/sip_registrations.conf\
+ $WORKDIR/sip_users.conf $WORKDIR/extensions_voicemail.conf\
+ $WORKDIR/extensions_default.conf"
+
+
+# In this string, we concatenate all local users enabled to receive calls
+# readily formatted for the Dial command.
+localusers_to_ring=""
+
+# In this string, we keep a list of all users that are enabled for outgoing
+# calls. It is used at the end to create the user contexts.
+localusers_can_dial=""
+
+# In this string, we put together a space-separated list of provider names
+# (alphanumeric, with all non-alpha characters replaced with underscores),
+# which will be used to dial out by default (whose outgoing contexts will
+# be included in users' contexts by default.
+outbound_providers=""
+sip_outbound_providers=""
+gtalk_outbound_providers=""
+
+# Function which escapes non-alpha-numeric characters in a string
+escape_non_alpha() {
+ echo $@ | sed 's/\([^a-zA-Z0-9]\)/\\\1/g'
+}
+
+# Function which replaces non-alpha-numeric characters with an underscore
+sub_underscore_for_non_alpha() {
+ echo $@ | sed 's/[^a-zA-Z0-9]/_/g'
+}
+
+# Copies the template files which we don't edit.
+copy_unedited_templates_over()
+{
+ cp $TMPL_ASTERISK $WORKDIR/asterisk.conf
+ cp $TMPL_GTALK $WORKDIR/gtalk.conf
+ cp $TMPL_INDICATIONS $WORKDIR/indications.conf
+ cp $TMPL_LOGGER $WORKDIR/logger.conf
+ cp $TMPL_MANAGER $WORKDIR/manager.conf
+ cp $TMPL_MODULES $WORKDIR/modules.conf
+ # If this file isn't present at this stage, voicemail is disabled.
+ [ ! -f $WORKDIR/extensions_voicemail.conf ] && \
+ cp $TMPL_EXTVMDISABLED $WORKDIR/extensions_voicemail.conf
+}
+
+# Touches all the included files, to prevent asterisk from refusing to
+# start if a config item is missing and an included config file isn't created.
+create_included_files()
+{
+ touch $INCLUDED_FILES
+}
+
+# Puts together all the extensions.conf related configuration.
+pbx_create_extensions_config()
+{
+ local ringtime
+ config_get ringtime advanced ringtime
+
+ sed "s/|RINGTIME|/$ringtime/" $TMPL_EXTENSIONS > $WORKDIR/extensions.conf
+ mv $WORKDIR/inext.TMP $WORKDIR/extensions_incoming.conf
+ cp $TMPL_EXTINCNTXTGTALKHDR $WORKDIR/extensions_incoming_gtalk.conf
+ cat $WORKDIR/outextgtalk.TMP >> $WORKDIR/extensions_incoming_gtalk.conf 2>/dev/null
+ rm -f $WORKDIR/outextgtalk.TMP
+ mv $WORKDIR/blacklist.TMP $WORKDIR/extensions_blacklist.conf
+ mv $WORKDIR/userext.TMP $WORKDIR/extensions_user.conf
+
+ cp $TMPL_EXTCTHRUHDR $WORKDIR/extensions_callthrough.conf
+ cat $WORKDIR/callthrough.TMP >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ rm -f $WORKDIR/callthrough.TMP
+ cat $TMPL_EXTCTHRUCHECKHDR >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ cat $WORKDIR/callthroughcheck.TMP >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ rm -f $WORKDIR/callthroughcheck.TMP
+ cat $TMPL_EXTCTHRUCHECKFTR >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+
+ cp $TMPL_EXTCBACKHDR $WORKDIR/extensions_callback.conf
+ cat $WORKDIR/callback.TMP >> $WORKDIR/extensions_callback.conf 2>/dev/null
+ rm -f $WORKDIR/callback.TMP
+ cat $TMPL_EXTCBACKCHECKHDR >> $WORKDIR/extensions_callback.conf 2>/dev/null
+ cat $WORKDIR/callbackcheck.TMP >> $WORKDIR/extensions_callback.conf 2>/dev/null
+ rm -f $WORKDIR/callbackcheck.TMP
+ cat $TMPL_EXTCBACKCHECKFTR >> $WORKDIR/extensions_callback.conf 2>/dev/null
+
+ rm -f $WORKDIR/outext-*.TMP
+ rm -f $WORKDIR/localext.TMP
+ sed "s/|LOCALUSERS|/$localusers_to_ring/g" $TMPL_EXTDEFAULT \
+ > $WORKDIR/extensions_default.conf
+ cat $WORKDIR/inextuser.TMP >> $WORKDIR/extensions_default.conf
+ rm -f $WORKDIR/inextuser.TMP
+}
+
+# Puts together all the sip.conf related configuration.
+pbx_create_sip_config()
+{
+ mv $WORKDIR/sip_regs.TMP $WORKDIR/sip_registrations.conf
+ mv $WORKDIR/sip_peers.TMP $WORKDIR/sip_peers.conf
+ mv $WORKDIR/sip_users.TMP $WORKDIR/sip_users.conf
+}
+
+# Creates the jabber.conf related config
+pbx_create_jabber_config()
+{
+ cp $TMPL_JABBER $WORKDIR/jabber.conf
+ mv $WORKDIR/jabber.TMP $WORKDIR/jabber_users.conf
+}
+
+# Gets rid of any config files from $ASTERISKDIR not found in $WORKDIR.
+clean_up_asterisk_config_dir()
+{
+ for f in $ASTERISKDIR/* ; do
+ basef="`basename $f`"
+ if [ ! -e "$WORKDIR/$basef" ] ; then
+ rm -rf "$f"
+ fi
+ done
+}
+
+# Compares md5sums of the config files in $WORKDIR to those
+# in $ASTERISKDIR, and copies only changed files over to reduce
+# wear on flash in embedded devices.
+compare_configs_and_copy_changed()
+{
+ # First, compute md5sums of the config files in $WORKDIR.
+ cd $WORKDIR/
+ md5sum * > $MD5SUMSFILE
+
+ # Now, check the files in $ASTERISKDIR against the md5sums.
+ cd $ASTERISKDIR/
+ changed_files="`md5sum -c $MD5SUMSFILE 2>/dev/null | fgrep ": FAILED" | awk -F: '{print $1}'`"
+
+ rm -f $MD5SUMSFILE
+
+ [ -z "$changed_files" ] && return
+
+ # Now copy over the changed files.
+ for f in $changed_files ; do
+ cp "$WORKDIR/$f" "$ASTERISKDIR/$f"
+ done
+}
+
+# Calls the functions that create the final config files
+# Calls the function which compares which files have changed
+# Puts the final touches on $ASTERISKDIR
+# Gets rid of $WORKDIR
+pbx_assemble_and_copy_config()
+{
+ mkdir -p $ASTERISKDIR
+
+ copy_unedited_templates_over
+ create_included_files
+ pbx_create_extensions_config
+ pbx_create_sip_config
+ pbx_create_jabber_config
+
+ touch $WORKDIR/features.conf
+
+ # At this point, $WORKDIR should contain a complete, working config.
+ clean_up_asterisk_config_dir
+
+ compare_configs_and_copy_changed
+
+ [ ! -d $ASTERISKDIR/manager.d ] && mkdir -p $ASTERISKDIR/manager.d/
+
+ # Get rid of the working directory
+ rm -rf $WORKDIR/
+}
+
+# Creates configuration for a user and adds it to the temporary file that holds
+# all users configured so far.
+pbx_add_user()
+{
+ local fullname
+ local defaultuser
+ local rawdefaultuser
+ local secret
+ local ring
+ local can_call
+
+ config_get fullname $1 fullname
+ fullname=`escape_non_alpha $fullname`
+ config_get rawdefaultuser $1 defaultuser
+ defaultuser=`escape_non_alpha $rawdefaultuser`
+ config_get secret $1 secret
+ secret=`escape_non_alpha $secret`
+ config_get ring $1 ring
+ config_get can_call $1 can_call
+
+ [ -z "$defaultuser" -o -z "$secret" ] && return
+ [ -z "$fullname" ] && fullname="$defaultuser"
+
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPUSR > $WORKDIR/sip_user.tmp
+
+ if [ "$can_call" = "yes" ] ; then
+ # Add user to list of all users that are allowed to make calls.
+ localusers_can_dial="$localusers_can_dial $rawdefaultuser"
+ sed -i "s/|CONTEXTNAME|/$defaultuser/g" $WORKDIR/sip_user.tmp
+ else
+ sed -i "s/|CONTEXTNAME|/$HANGUPCNTXT/g" $WORKDIR/sip_user.tmp
+ fi
+
+ # Add this user's configuration to the temp file containing all user configs.
+ sed "s/|FULLNAME|/$fullname/" $WORKDIR/sip_user.tmp |\
+ sed "s/|SECRET|/$secret/g" >> $WORKDIR/sip_users.TMP
+
+ if [ "$ring" = "yes" ] ; then
+ if [ -z "$localusers_to_ring" ] ; then
+ localusers_to_ring="SIP\/$defaultuser"
+ else
+ localusers_to_ring="$localusers_to_ring\&SIP\/$defaultuser"
+ fi
+ fi
+
+ # Add configuration which allows local users to call each other.
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTOUTLOCAL >> $WORKDIR/localext.TMP
+
+ # Add configuration which puts calls to users through the default
+ # context, so that blacklists and voicemail take effect for this user.
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTDEFAULTUSER >> $WORKDIR/inextuser.TMP
+
+ rm -f $WORKDIR/sip_user.tmp
+}
+
+# Creates configuration for a Google account, and adds it to the temporary file that holds
+# all accounts configured so far.
+# Also creates the outgoing extensions which are used in users' outgoing contexts.
+pbx_add_jabber()
+{
+ local username
+ local secret
+ local numprefix
+ local register
+ local make_outgoing_calls
+ local name
+ local users_to_ring
+ local status
+ local statusmessage
+
+ config_get username $1 username
+ username=`escape_non_alpha $username`
+ config_get secret $1 secret
+ secret=`escape_non_alpha $secret`
+ #TODO: Is this really necessary here? Numprefix is retrieved below.
+ config_get numprefix $1 numprefix
+ config_get register $1 register
+ config_get make_outgoing_calls $1 make_outgoing_calls
+ config_get name $1 name
+ config_get status $1 status
+ status=`escape_non_alpha $status`
+ config_get statusmessage $1 statusmessage
+ statusmessage=`escape_non_alpha $statusmessage`
+
+ [ -z "$username" -o -z "$secret" ] && return
+
+ # Construct a jabber entry for this provider.
+ sed "s/|USERNAME|/$username/g" $TMPL_JABBERUSER |\
+ sed "s/|NAME|/$name/g" > $WORKDIR/jabber.tmp
+
+ if [ "$register" = yes ] ; then
+ # If this provider is enabled for incoming calls, we need to set the
+ # status of the user to something other than unavailable in order to receive calls.
+ sed -i "s/|STATUS|/$status/g" $WORKDIR/jabber.tmp
+ sed -i "s/|STATUSMESSAGE|/\"$statusmessage\"/g" $WORKDIR/jabber.tmp
+
+ users_to_ring="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
+ # If no users have been specified to ring, we ring all users enabled for incoming calls.
+ if [ -z "$users_to_ring" ] ; then
+ users_to_ring=$localusers_to_ring
+ else
+ # Else, we cook up a string formatted for the Dial command
+ # with the specified users (SIP/user1&SIP/user2&...). We do it
+ # with set, shift and a loop in order to be more tolerant of ugly whitespace
+ # messes entered by users.
+ set $users_to_ring
+ users_to_ring="SIP\/$1" && shift
+ for u in $@ ; do u=`escape_non_alpha $u` ; users_to_ring=$users_to_ring\\\&SIP\\\/$u ; done
+ fi
+
+ # Now, we add this account to the gtalk incoming context.
+ sed "s/|USERNAME|/$username/g" $TMPL_EXTINCNTXTGTALK |\
+ sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/outextgtalk.TMP
+ else
+ sed -i "s/|STATUS|/$GTALKUNVL/g" $WORKDIR/jabber.tmp
+ sed -i "s/|STATUSMESSAGE|/\"\"/g" $WORKDIR/jabber.tmp
+ fi
+
+ # Add this account's configuration to the temp file containing all account configs.
+ sed "s/|SECRET|/$secret/g" $WORKDIR/jabber.tmp >> $WORKDIR/jabber.TMP
+
+ # If this provider is enabled for outgoing calls.
+ if [ "$make_outgoing_calls" = "yes" ] ; then
+
+ numprefix="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
+
+ # If no prefixes are specified, then we use "X" which matches any prefix.
+ [ -z "$numprefix" ] && numprefix="X"
+
+ for p in $numprefix ; do
+ p=`escape_non_alpha $p`
+ sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTGTALK |\
+ sed "s/|NAME|/$name/g" >> $WORKDIR/outext-$name.TMP
+ done
+
+ # Add this provider to the list of enabled outbound providers.
+ if [ -z "$outbound_providers" ] ; then
+ outbound_providers="$name"
+ else
+ outbound_providers="$outbound_providers $name"
+ fi
+
+ # Add this provider to the list of enabled gtalk outbound providers.
+ if [ -z "$gtalk_outbound_providers" ] ; then
+ gtalk_outbound_providers="$name"
+ else
+ gtalk_outbound_providers="$gtalk_outbound_providers $name"
+ fi
+ fi
+
+ rm -f $WORKDIR/jabber.tmp
+}
+
+# Creates configuration for a SIP provider account, and adds it to the temporary file that holds
+# all accounts configured so far.
+# Also creates the outgoing extensions which are used in users' outgoing contexts.
+pbx_add_peer()
+{
+ local defaultuser
+ local secret
+ local host
+ local fromdomain
+ local register
+ local numprefix
+ local make_outgoing_calls
+ local name
+ local users_to_ring
+ local port
+ local outboundproxy
+
+ config_get defaultuser $1 defaultuser
+ defaultuser=`escape_non_alpha $defaultuser`
+ config_get secret $1 secret
+ secret=`escape_non_alpha $secret`
+ config_get host $1 host
+ host=`escape_non_alpha $host`
+ config_get port $1 port
+ config_get outbountproxy $1 outboundproxy
+ outbountproxy=`escape_non_alpha $outbountproxy`
+ config_get fromdomain $1 fromdomain
+ fromdomain=`escape_non_alpha $fromdomain`
+ config_get register $1 register
+ config_get numprefix $1 numprefix
+ config_get make_outgoing_calls $1 make_outgoing_calls
+ config_get name $1 name
+
+ [ -z "$defaultuser" -o -z "$secret" -o -z "$host" ] && return
+ [ -z "$fromdomain" ] && fromdomain=$host
+ [ -n "$port" ] && port="port=$port"
+ [ -n "$outboundproxy" ] && outboundproxy="outboundproxy=$outboundproxy"
+
+ # Construct a sip peer entry for this provider.
+ sed "s/|DEFAULTUSER|/$defaultuser/" $TMPL_SIPPEER > $WORKDIR/sip_peer.tmp
+ sed -i "s/|NAME|/$name/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|FROMUSER|/$defaultuser/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|SECRET|/$secret/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|HOST|/$host/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|PORT|/$port/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|OUTBOUNDPROXY|/$outboundproxy/" $WORKDIR/sip_peer.tmp
+ # Add this account's configuration to the temp file containing all account configs.
+ sed "s/|FROMDOMAIN|/$host/" $WORKDIR/sip_peer.tmp >> $WORKDIR/sip_peers.TMP
+
+ # If this provider is enabled for incoming calls.
+ if [ "$register" = "yes" ] ; then
+ # Then we create a registration string for this provider.
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPREG > $WORKDIR/sip_reg.tmp
+ sed -i "s/|SECRET|/$secret/g" $WORKDIR/sip_reg.tmp
+ sed "s/|NAME|/$name/g" $WORKDIR/sip_reg.tmp >> $WORKDIR/sip_regs.TMP
+
+ users_to_ring="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
+ # If no users have been specified to ring, we ring all users enabled for incoming calls.
+ if [ -z "$users_to_ring" ] ; then
+ users_to_ring=$localusers_to_ring
+ else
+ # Else, we cook up a string formatted for the Dial command
+ # with the specified users (SIP/user1&SIP/user2&...). We do it
+ # with set, shift and a loop in order to be more tolerant of ugly whitespace
+ # messes entered by users.
+ set $users_to_ring
+ users_to_ring="SIP\/$1" && shift
+ for u in $@ ; do users_to_ring=$users_to_ring\\\&SIP\\\/$u ; done
+ fi
+
+ # And we create an incoming calls context for this provider.
+ sed "s/|NAME|/$name/g" $TMPL_EXTINCNTXTSIP |\
+ sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/inext.TMP
+ fi
+
+ # If this provider is enabled for outgoing calls.
+ if [ "$make_outgoing_calls" = "yes" ] ; then
+
+ numprefix="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
+ # If no prefixes are specified, then we use "X" which matches any prefix.
+ [ -z "$numprefix" ] && numprefix="X"
+ for p in $numprefix ; do
+ p=`escape_non_alpha $p`
+ sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTSIP |\
+ sed "s/|NAME|/$name/g" >> $WORKDIR/outext-$name.TMP
+ done
+
+ # Add this provider to the list of enabled outbound providers.
+ if [ -z "$outbound_providers" ] ; then
+ outbound_providers="$name"
+ else
+ outbound_providers="$outbound_providers $name"
+ fi
+
+ # Add this provider to the list of enabled sip outbound providers.
+ if [ -z "$sip_outbound_providers" ] ; then
+ sip_outbound_providers="$name"
+ else
+ sip_outbound_providers="$sip_outbound_providers $name"
+ fi
+ fi
+
+ rm -f $WORKDIR/sip_peer.tmp
+ rm -f $WORKDIR/sip_reg.tmp
+}
+
+# For all local users enabled for outbound calls, creates a context
+# containing the extensions for Google and SIP accounts this user is
+# allowed to use.
+pbx_create_user_contexts()
+{
+ local providers
+
+ for u in $localusers_can_dial ; do
+ u=`escape_non_alpha $u`
+ sed "s/|DEFAULTUSER|/$u/g" $TMPL_EXTUSERCNTXTHDR >> $WORKDIR/userext.TMP
+ cat $WORKDIR/localext.TMP >> $WORKDIR/userext.TMP
+ providers="`uci -q get ${MODULENAME}-calls.providers_user_can_use.$u`"
+ [ -z "$providers" ] && providers="$outbound_providers"
+
+ # For each provider, cat the contents of outext-$name.TMP into the user's outgoing calls extension
+ for p in $providers ; do
+ [ -f $WORKDIR/outext-$p.TMP ] && cat $WORKDIR/outext-$p.TMP >> $WORKDIR/userext.TMP
+ done
+ cat $TMPL_EXTUSERCNTXTFTR >> $WORKDIR/userext.TMP
+ done
+}
+
+# Creates the blacklist context which hangs up on blacklisted numbers.
+pbx_add_blacklist()
+{
+ local blacklist1
+ local blacklist2
+
+ config_get blacklist1 blacklisting blacklist1
+ config_get blacklist2 blacklisting blacklist2
+
+ # We create the blacklist context no matter whether the blacklist
+ # actually contains entries or not, since the PBX will send calls
+ # to the context for a check against the list anyway.
+ cp $TMPL_EXTBLKLISTHDR $WORKDIR/blacklist.TMP
+ for n in $blacklist1 $blacklist2 ; do
+ n=`escape_non_alpha $n`
+ sed "s/|BLACKLISTITEM|/$n/g" $TMPL_EXTBLKLIST >> $WORKDIR/blacklist.TMP
+ done
+ cat $TMPL_EXTBLKLISTFTR >> $WORKDIR/blacklist.TMP
+}
+
+# Creates the callthrough context which allows specified numbers to get
+# into the PBX and dial out as the configured user.
+pbx_add_callthrough()
+{
+ local callthrough_number_list
+ local defaultuser
+ local pin
+ local enabled
+ local F
+
+ config_get callthrough_number_list $1 callthrough_number_list
+ config_get defaultuser $1 defaultuser
+ defaultuser=`escape_non_alpha $defaultuser`
+ config_get pin $1 pin
+ pin=`escape_non_alpha $pin`
+ config_get enabled $1 enabled
+
+ [ "$enabled" = "no" ] && return
+ [ "$defaultuser" = "" ] && return
+
+ for callthrough_number in $callthrough_number_list ; do
+ sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRUCHECK >> $WORKDIR/callthroughcheck.TMP
+
+ if [ -n "$pin" ] ; then F=$TMPL_EXTCTHRU ; else F=$TMPL_EXTCTHRUNOPIN ; fi
+ sed "s/|NUMBER|/$callthrough_number/g" $F |\
+ sed "s/|DEFAULTUSER|/$defaultuser/" |\
+ sed "s/|PIN|/$pin/" >> $WORKDIR/callthrough.TMP
+ done
+}
+
+
+# Creates the callback context which allows specified numbers to get
+# a callback into the PBX and dial out as the configured user.
+pbx_add_callback()
+{
+ local callback_number_list
+ local defaultuser
+ local pin
+ local enabled
+ local callback_provider
+ local callback_hangup_delay
+ local FB
+ local FT
+
+ config_get callback_number_list $1 callback_number_list
+ config_get defaultuser $1 defaultuser
+ defaultuser=`escape_non_alpha $defaultuser`
+ config_get pin $1 pin
+ pin=`escape_non_alpha $pin`
+ config_get enabled $1 enabled
+ config_get callback_provider $1 callback_provider
+ callback_provider=`sub_underscore_for_non_alpha $callback_provider`
+ config_get callback_hangup_delay $1 callback_hangup_delay
+
+ [ "$enabled" = "no" ] && return
+ [ "$defaultuser" = "" ] && return
+
+ # If the provider is a SIP provider, set the file to use to $TMPL_EXTCBACKSIP
+ # otherwise, set it to $TMPL_EXTCBACKGTALK
+ if echo $sip_outbound_providers | grep -q $callback_provider 2>/dev/null
+ then
+ FB=$TMPL_EXTCBACKSIP
+ else
+ FB=$TMPL_EXTCBACKGTALK
+ fi
+
+ for callback_number in $callback_number_list ; do
+ sed "s/|NUMBER|/$callback_number/g" $TMPL_EXTCBACKCHECK >> $WORKDIR/callbackcheck.TMP
+
+ sed "s/|NUMBER|/$callback_number/g" $FB |\
+ sed "s/|CALLBACKPROVIDER|/$callback_provider/" |\
+ sed "s/|CALLBACKHUPDELAY|/$callback_hangup_delay/" >> $WORKDIR/callback.TMP
+
+ # Perhaps a bit confusingly, we create "callthrough" configuration for callback
+ # numbers, because we use the same DISA construct as for callthrough.
+ if [ -n "$pin" ] ; then FT=$TMPL_EXTCTHRU ; else FT=$TMPL_EXTCTHRUNOPIN ; fi
+ sed "s/|NUMBER|/$callback_number/g" $FT |\
+ sed "s/|DEFAULTUSER|/$defaultuser/" |\
+ sed "s/|PIN|/$pin/" >> $WORKDIR/callthrough.TMP
+ done
+}
+
+
+# Creates sip.conf from its template.
+pbx_cook_sip_template()
+{
+ local useragent
+ local externhost
+ local bindport
+
+ config_get useragent advanced useragent
+ useragent=`escape_non_alpha $useragent`
+ config_get externhost advanced externhost
+ config_get bindport advanced bindport
+
+ [ -z "$useragent" ] && useragent="$USERAGENT"
+
+ sed "s/|USERAGENT|/$useragent/g" $TMPL_SIP > $WORKDIR/sip.conf
+
+ if [ -z "$externhost" ] ; then
+ sed -i "s/externhost=|EXTERNHOST|//g" $WORKDIR/sip.conf
+ else
+ sed -i "s/|EXTERNHOST|/$externhost/g" $WORKDIR/sip.conf
+ fi
+
+ if [ -z "$bindport" ] ; then
+ sed -i "s/bindport=|BINDPORT|//g" $WORKDIR/sip.conf
+ else
+ sed -i "s/|BINDPORT|/$bindport/g" $WORKDIR/sip.conf
+ fi
+
+
+}
+
+# Creates rtp.conf from its template.
+pbx_cook_rtp_template()
+{
+ local rtpstart
+ local rtpend
+
+ config_get rtpstart advanced rtpstart
+ config_get rtpend advanced rtpend
+
+ sed "s/|RTPSTART|/$rtpstart/" $TMPL_RTP |\
+ sed "s/|RTPEND|/$rtpend/" > $WORKDIR/rtp.conf
+}
+
+# Links any sound files found in $PBXSOUNDSDIR and $VMSOUNDSDIR
+# into $ASTSOUNDSDIR for use by Asterisk. Does not overwrite files.
+pbx_link_sounds()
+{
+ mkdir -p $ASTSOUNDSDIR
+
+ for dir in $PBXSOUNDSDIR $VMSOUNDSDIR ; do
+ if [ -d $dir ] ; then
+ for f in $dir/* ; do
+ ln -s $f $ASTSOUNDSDIR 2>/dev/null
+ done
+ fi
+ done
+}
+
+
+# Makes sure the ownership of specified directories is proper.
+pbx_fix_ownership()
+{
+ chown $ASTUSER:$ASTGROUP $ASTDIRS
+ chown $ASTUSER:$ASTGROUP -R $ASTDIRSRECURSIVE
+}
+
+
+# Creates voicemail config if installed and enabled.
+pbx_configure_voicemail()
+{
+ local enabled
+ local global_timeout
+ local global_email_addresses
+
+ local smtp_tls
+ local smtp_server
+ local smtp_port
+ local smtp_auth
+ local smtp_user
+ local smtp_password
+
+ config_get enabled global_voicemail enabled
+
+ # First check if voicemail is enabled.
+ [ "$enabled" != "yes" ] && return
+
+ config_get global_timeout global_voicemail global_timeout
+ #config_get global_email_addresses global_voicemail global_email_addresses
+ config_get smtp_auth voicemail_smtp smtp_auth
+ config_get smtp_tls voicemail_smtp smtp_tls
+ config_get smtp_server voicemail_smtp smtp_server
+ config_get smtp_port voicemail_smtp smtp_port
+ config_get smtp_user voicemail_smtp smtp_user
+ smtp_user=`escape_non_alpha $smtp_user`
+ config_get smtp_password voicemail_smtp smtp_password
+ smtp_password=`escape_non_alpha $smtp_password`
+
+ sed "s/|AUTH|/$smtp_auth/" $TMPL_MSMTPDEFAULT |\
+ sed "s/|TLS|/$smtp_tls/" > $WORKDIR/pbx-msmtprc
+
+ sed "s/|HOST|/$smtp_server/" $TMPL_MSMTPACCOUNT |\
+ sed "s/|PORT|/$smtp_port/" >> $WORKDIR/pbx-msmtprc
+
+ if [ "$smtp_auth" = "on" ] ; then
+ sed "s/|USER|/$smtp_user/" $TMPL_MSMTPAUTH |\
+ sed "s/|PASSWORD|/$smtp_password/" >> $WORKDIR/pbx-msmtprc
+ fi
+
+ cat $TMPL_MSMTPACCTDFLT >> $WORKDIR/pbx-msmtprc
+
+ [ ! -f /etc/pbx-msmtprc ] && cp $WORKDIR/pbx-msmtprc /etc/pbx-msmtprc
+ cmp -s $WORKDIR/pbx-msmtprc /etc/pbx-msmtprc 1>/dev/null \
+ || mv $WORKDIR/pbx-msmtprc /etc/pbx-msmtprc
+ chmod 600 /etc/pbx-msmtprc
+ chown nobody /etc/pbx-msmtprc
+
+ # Copy over the extensions file which has voicemail enabled.
+ cp $TMPL_EXTVMENABLED $WORKDIR/extensions_voicemail.conf
+
+ # Create the voicemail directory in /tmp
+ mkdir -p /tmp/voicemail
+ chown nobody /tmp/voicemail
+
+ # Create the recordings directory
+ mkdir -p /etc/pbx-voicemail/recordings
+ chown nobody /etc/pbx-voicemail/recordings
+
+ # Working around a bug in OpenWRT 12.09-rc1
+ # TODO: REMOVE AS SOON AS POSSIBLE
+ chmod ugo+w /tmp
+}
+
+
+start() {
+ mkdir -p $WORKDIR
+
+ # Create the users.
+ config_load ${MODULENAME}-users
+ config_foreach pbx_add_user local_user
+
+ # Create configuration for each google account.
+ config_unset
+ config_load ${MODULENAME}-google
+ config_foreach pbx_add_jabber gtalk_jabber
+
+ # Create configuration for each voip provider.
+ config_unset
+ config_load ${MODULENAME}-voip
+ config_foreach pbx_add_peer voip_provider
+
+ # Create the user contexts, callthroug/back, and phone blacklist.
+ config_unset
+ config_load ${MODULENAME}-calls
+ pbx_create_user_contexts
+ pbx_add_blacklist
+ config_foreach pbx_add_callthrough callthrough_numbers
+ config_foreach pbx_add_callback callback_numbers
+
+ # Prepare sip.conf using settings from the "advanced" section.
+ config_unset
+ config_load ${MODULENAME}-advanced
+ pbx_cook_sip_template
+ pbx_cook_rtp_template
+
+ # Prepare voicemail config.
+ config_unset
+ config_load ${MODULENAME}-voicemail
+ pbx_configure_voicemail
+
+ # Assemble the configuration, and copy changed files over.
+ config_unset
+ config_load ${MODULENAME}-advanced
+ pbx_assemble_and_copy_config
+
+ # Link sound files
+ pbx_link_sounds
+
+ # Enforce ownership of specified files and directories.
+ pbx_fix_ownership
+}
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE
new file mode 100644
index 000000000..ac5439615
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE
@@ -0,0 +1,17 @@
+[directories]
+astetcdir => /etc/asterisk
+astmoddir => /usr/lib/asterisk/modules
+astvarlibdir => /usr/lib/asterisk
+astdbdir => /usr/lib/asterisk
+astkeydir => /usr/lib/asterisk
+astdatadir => /usr/lib/asterisk
+astagidir => /usr/lib/asterisk/agi-bin
+astspooldir => /var/spool/asterisk
+astrundir => /var/run/asterisk
+astlogdir => /var/log/asterisk
+
+[options]
+languageprefix = yes
+dumpcore = no
+runuser = nobody
+rungroup = nogroup
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/delayedcallback b/applications/luci-app-pbx/root/etc/pbx-asterisk/delayedcallback
new file mode 100755
index 000000000..903efe9ad
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/delayedcallback
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Check if there are more than one instance of this command
+# with the same command line running at the same time for some
+# reason, then quit. We are checking for the same
+# commandline in order to permit two different callback
+# attempts simultaneously.
+
+if ! grep -q "$@" /dev/shm/delayedcallback.[0-9]* 2>/dev/null
+then
+ echo "$@" > /dev/shm/delayedcallback.$$
+ sleep 25
+ asterisk -r -x "$1 $2 \"$3\" $4 $5 $6"
+ rm /dev/shm/delayedcallback.$$
+# echo "`date` $@": >> /dev/shm/delayedcallback.log
+#else
+# echo "`date` ERROR: There appears to be a callback attempt in progress to: $@" >> /dev/shm/delayedcallback.err
+fi
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE
new file mode 100644
index 000000000..c8966edd8
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE
@@ -0,0 +1,25 @@
+[general]
+static = yes
+writeprotect = yes
+clearglobalvars = no
+
+[globals]
+RINGTIME => |RINGTIME|
+
+[default]
+
+[context-user-hangup-call-context]
+exten => s,1,Hangup()
+exten => _X.,1,Hangup()
+
+[context-catch-all]
+exten => _[!-~].,1,Dial(SIP/${EXTEN},60,r)
+
+#include extensions_default.conf
+#include extensions_voicemail.conf
+#include extensions_incoming.conf
+#include extensions_incoming_gtalk.conf
+#include extensions_blacklist.conf
+#include extensions_callthrough.conf
+#include extensions_callback.conf
+#include extensions_user.conf
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE
new file mode 100644
index 000000000..54ee989b0
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Gotoif($[ "${CALLERID(NUM)}" = "|BLACKLISTITEM|" ]?context-user-hangup,s,1)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE
new file mode 100644
index 000000000..da964f238
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE
@@ -0,0 +1,2 @@
+exten => s,n,Goto(${SOURCECONTEXT},${SOURCEEXTEN},doneblacklist)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE
new file mode 100644
index 000000000..de0e98465
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE
@@ -0,0 +1,3 @@
+
+[blacklist-call-context]
+exten => s,1,Noop()
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check.conf.TEMPLATE
new file mode 100644
index 000000000..06b1a4b6b
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Gotoif($[ "${CALLERID(NUM)}" =~ ".*|NUMBER|" ]?context-user-callback,|NUMBER|,1)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_footer.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_footer.conf.TEMPLATE
new file mode 100644
index 000000000..282fe9e8f
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_footer.conf.TEMPLATE
@@ -0,0 +1,2 @@
+exten => s,n,Goto(${SOURCECONTEXT},${SOURCEEXTEN},donecallback)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_header.conf.TEMPLATE
new file mode 100644
index 000000000..be289c4d3
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback-check_header.conf.TEMPLATE
@@ -0,0 +1,3 @@
+
+[callback-check-call-context]
+exten => s,1,Noop()
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_gtalk.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..43eec788f
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_gtalk.conf.TEMPLATE
@@ -0,0 +1,4 @@
+exten => |NUMBER|,1,System(/etc/pbx-asterisk/delayedcallback "channel originate Gtalk/gtalk-|CALLBACKPROVIDER|/|NUMBER|@voice.google.com extension |NUMBER|@disa-call-context" &)
+exten => |NUMBER|,n,Wait(|CALLBACKHUPDELAY|)
+exten => |NUMBER|,n,Hangup()
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_header.conf.TEMPLATE
new file mode 100644
index 000000000..0b8fb4c23
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[context-user-callback]
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_sip.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_sip.conf.TEMPLATE
new file mode 100644
index 000000000..300e9fa0e
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_callback_sip.conf.TEMPLATE
@@ -0,0 +1,4 @@
+exten => |NUMBER|,1,System(/etc/pbx-asterisk/delayedcallback "channel originate SIP/|NUMBER|@peer-|CALLBACKPROVIDER| extension |NUMBER|@disa-call-context" &)
+exten => |NUMBER|,n,Wait(|CALLBACKHUPDELAY|)
+exten => |NUMBER|,n,Hangup()
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default.conf.TEMPLATE
new file mode 100644
index 000000000..35836e290
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default.conf.TEMPLATE
@@ -0,0 +1,11 @@
+[default-incoming-call-context]
+exten => s,1,NoOp(${CALLERID})
+exten => s,n,Set(SOURCECONTEXT=default-incoming-call-context)
+exten => s,n,Set(SOURCEEXTEN=s)
+exten => s,n,Goto(blacklist-call-context,s,1)
+exten => s,n(doneblacklist),NoOp()
+exten => s,n,Goto(callback-check-call-context,s,1)
+exten => s,n(donecallback),NoOp()
+exten => s,n,Goto(disa-check-call-context,s,1)
+exten => s,n(donedisacheck),Dial(|LOCALUSERS|,${RINGTIME},r)
+exten => s,n,Goto(context-voicemail,s,1)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default_user.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default_user.conf.TEMPLATE
new file mode 100644
index 000000000..1910ff4d9
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_default_user.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => |DEFAULTUSER|,1,Goto(default-incoming-call-context,s,1)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE
new file mode 100644
index 000000000..ba2379b73
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Gotoif($[ "${CALLERID(NUM)}" =~ ".*|NUMBER|" ]?disa-call-context,|NUMBER|,1)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE
new file mode 100644
index 000000000..74056fa01
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Goto(${SOURCECONTEXT},${SOURCEEXTEN},donedisacheck)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE
new file mode 100644
index 000000000..e0d67b802
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE
@@ -0,0 +1,2 @@
+[disa-check-call-context]
+exten => s,1,Noop()
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-nopin.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-nopin.conf.TEMPLATE
new file mode 100644
index 000000000..74e48de8c
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa-nopin.conf.TEMPLATE
@@ -0,0 +1,5 @@
+exten => |NUMBER|,1,Noop()
+exten => |NUMBER|,n,Set(TIMEOUT(digit)=15)
+exten => |NUMBER|,n,Set(TIMEOUT(response)=40)
+exten => |NUMBER|,n,DISA(no-password,context-user-|DEFAULTUSER|)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE
new file mode 100644
index 000000000..3dd8fa35c
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE
@@ -0,0 +1,6 @@
+exten => |NUMBER|,1,Noop()
+exten => |NUMBER|,n,Set(TIMEOUT(digit)=7)
+exten => |NUMBER|,n,Set(TIMEOUT(response)=21)
+exten => |NUMBER|,n,Authenticate(|PIN|)
+exten => |NUMBER|,n,DISA(no-password,context-user-|DEFAULTUSER|)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE
new file mode 100644
index 000000000..a74227114
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[disa-call-context]
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..3f9cf4c7d
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE
@@ -0,0 +1,15 @@
+exten => |USERNAME|,1,NoOp(${CALLERID})
+same => n,Set(CALLERID(name)=${CUT(CALLERID(name),@,1)})
+same => n,GotoIf($["${CALLERID(name):0:2}" != "+1"]?notrim)
+same => n,Set(CALLERID(name)=${CALLERID(name):2})
+same => n(notrim),Set(CALLERID(number)=${CALLERID(name)})
+same => n,Set(SOURCECONTEXT=context-incoming-gtalk)
+same => n,Set(SOURCEEXTEN=|USERNAME|)
+same => n,Goto(blacklist-call-context,s,1)
+same => n(doneblacklist),NoOp()
+same => n,Goto(callback-check-call-context,s,1)
+same => n(donecallback),NoOp()
+same => n,Goto(disa-check-call-context,s,1)
+same => n(donedisacheck),Dial(|LOCALUSERS|,${RINGTIME},D(:w11111111))
+same => n,Goto(context-voicemail,s,1)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE
new file mode 100644
index 000000000..f6e44a5bf
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[context-incoming-gtalk]
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE
new file mode 100644
index 000000000..b2c3716bf
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE
@@ -0,0 +1,12 @@
+
+[context-incoming-|NAME|]
+exten => s,1,NoOp(${CALLERID})
+exten => s,n,Set(SOURCECONTEXT=context-incoming-|NAME|)
+exten => s,n,Set(SOURCEEXTEN=s)
+exten => s,n,Goto(blacklist-call-context,s,1)
+exten => s,n(doneblacklist),NoOp()
+exten => s,n,Goto(callback-check-call-context,s,1)
+exten => s,n(donecallback),NoOp()
+exten => s,n,Goto(disa-check-call-context,s,1)
+exten => s,n(donedisacheck),Dial(|LOCALUSERS|,${RINGTIME},r)
+exten => s,n,Goto(context-voicemail,s,1)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE
new file mode 100644
index 000000000..45e875884
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => |DEFAULTUSER|,1,Dial(SIP/|DEFAULTUSER|,${RINGTIME},r)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..259c2ceaa
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE
@@ -0,0 +1,9 @@
+exten => _|NUMPREFIX|,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN}@voice.google.com,60)
+exten => _+|NUMPREFIX|,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:1}@voice.google.com,60)
+exten => _|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN}@voice.google.com,60)
+exten => _+|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:1}@voice.google.com,60)
+exten => _00|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:2}@voice.google.com,60)
+exten => _011|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:3}@voice.google.com,60)
+exten => _010|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:3}@voice.google.com,60)
+exten => _0011|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:4}@voice.google.com,60)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..1fa7713e2
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE
@@ -0,0 +1,2 @@
+exten => |PATTERN|,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN|SYMBOLSTOREMOVE|}@voice.google.com,60)
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE
new file mode 100644
index 000000000..178b6deaa
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => |PATTERN|,1,Dial(SIP/${EXTEN|SYMBOLSTOREMOVE|}@peer-|NAME|,60,r)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE
new file mode 100644
index 000000000..9b1d9addc
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE
@@ -0,0 +1,8 @@
+exten => _|NUMPREFIX|,1,Dial(SIP/${EXTEN}@peer-|NAME|,60,r)
+exten => _+|NUMPREFIX|,1,Dial(SIP/${EXTEN}@peer-|NAME|,60,r)
+exten => _|NUMPREFIX|.,1,Dial(SIP/${EXTEN}@peer-|NAME|,60,r)
+exten => _+|NUMPREFIX|.,1,Dial(SIP/${EXTEN:1}@peer-|NAME|,60,r)
+exten => _00|NUMPREFIX|.,1,Dial(SIP/${EXTEN:2}@peer-|NAME|,60,r)
+exten => _011|NUMPREFIX|.,1,Dial(SIP/${EXTEN:3}@peer-|NAME|,60,r)
+exten => _010|NUMPREFIX|.,1,Dial(SIP/${EXTEN:3}@peer-|NAME|,60,r)
+exten => _0011|NUMPREFIX|.,1,Dial(SIP/${EXTEN:4}@peer-|NAME|,60,r)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE
new file mode 100644
index 000000000..a2ba28c05
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE
@@ -0,0 +1,2 @@
+include => context-voicemail-record-greeting
+include => context-catch-all
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE
new file mode 100644
index 000000000..5931eaf28
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE
@@ -0,0 +1,3 @@
+
+[context-user-|DEFAULTUSER|]
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_disabled.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_disabled.conf.TEMPLATE
new file mode 100644
index 000000000..be23c294d
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_disabled.conf.TEMPLATE
@@ -0,0 +1,4 @@
+[context-voicemail-record-greeting]
+
+[context-voicemail]
+exten => s,1,Hangup()
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_enabled.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_enabled.conf.TEMPLATE
new file mode 100644
index 000000000..4edd9cb42
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/extensions_voicemail_enabled.conf.TEMPLATE
@@ -0,0 +1,27 @@
+[context-voicemail-record-greeting]
+exten => *789,1,Wait(1)
+exten => *789,n,Playback(/etc/pbx-voicemail/recordings/greeting)
+exten => *789,n,Wait(1)
+exten => *789,n,Playback(beep)
+exten => *789,n,Playback(beep)
+exten => *789,n,WaitExten(30)
+
+exten => t,1,Playback(vm-goodbye)
+exten => t,n,Wait(2)
+exten => t,n,Hangup()
+
+exten => *,1,Playback(beep)
+exten => *,n,Playback(beep)
+exten => *,n,Record(/tmp/voicemail/greeting:gsm,20,120,k)
+exten => *,n,Wait(1)
+exten => *,n,Playback(/tmp/voicemail/greeting)
+
+exten => h,1,System(/etc/pbx-voicemail/pbx-move-greeting &)
+
+[context-voicemail]
+exten => s,1,Wait(2)
+exten => s,2,Playback(/etc/pbx-voicemail/recordings/greeting)
+exten => s,3,Wait(2)
+exten => s,n,Record(/tmp/voicemail/voicemail%d:WAV,20,180,k)
+
+exten => h,1,System(/etc/pbx-voicemail/pbx-send-voicemail '${RECORDED_FILE}.WAV' '${CALLERID(all)}' &)
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..4f07a7166
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE
@@ -0,0 +1,10 @@
+[general]
+context=context-incoming-gtalk
+allowguest=yes
+allowguests=yes
+bindaddr=0.0.0.0
+
+[guest]
+disallow=all
+allow=ulaw
+context=context-incoming-gtalk
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE
new file mode 100644
index 000000000..d7088db7c
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE
@@ -0,0 +1,733 @@
+; indications.conf
+; Configuration file for location specific tone indications
+; used by the pbx_indications module.
+;
+; NOTE:
+; When adding countries to this file, please keep them in alphabetical
+; order according to the 2-character country codes!
+;
+; The [general] category is for certain global variables.
+; All other categories are interpreted as location specific indications
+;
+;
+[general]
+country=us ; default location
+
+
+; [example]
+; description = string
+; The full name of your country, in English.
+; alias = iso[,iso]*
+; List of other countries 2-letter iso codes, which have the same
+; tone indications.
+; ringcadence = num[,num]*
+; List of durations the physical bell rings.
+; dial = tonelist
+; Set of tones to be played when one picks up the hook.
+; busy = tonelist
+; Set of tones played when the receiving end is busy.
+; congestion = tonelist
+; Set of tones played when there is some congestion (on the network?)
+; callwaiting = tonelist
+; Set of tones played when there is a call waiting in the background.
+; dialrecall = tonelist
+; Not well defined; many phone systems play a recall dial tone after hook
+; flash.
+; record = tonelist
+; Set of tones played when call recording is in progress.
+; info = tonelist
+; Set of tones played with special information messages (e.g., "number is
+; out of service")
+; 'name' = tonelist
+; Every other variable will be available as a shortcut for the "PlayList" command
+; but will not be used automatically by Asterisk.
+;
+;
+; The tonelist itself is defined by a comma-separated sequence of elements.
+; Each element consist of a frequency (f) with an optional duration (in ms)
+; attached to it (f/duration). The frequency component may be a mixture of two
+; frequencies (f1+f2) or a frequency modulated by another frequency (f1*f2).
+; The implicit modulation depth is fixed at 90%, though.
+; If the list element starts with a !, that element is NOT repeated,
+; therefore, only if all elements start with !, the tonelist is time-limited,
+; all others will repeat indefinitely.
+;
+; concisely:
+; element = [!]freq[+|*freq2][/duration]
+; tonelist = element[,element]*
+;
+; Please note that SPACES ARE NOT ALLOWED in tone lists!
+;
+
+[at]
+description = Austria
+ringcadence = 1000,5000
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+dial = 420
+busy = 420/400,0/400
+ring = 420/1000,0/5000
+congestion = 420/200,0/200
+callwaiting = 420/40,0/1960
+dialrecall = 420
+; RECORDTONE - not specified
+record = 1400/80,0/14920
+info = 950/330,1450/330,1850/330,0/1000
+stutter = 380+420
+
+[au]
+description = Australia
+; Reference http://www.acif.org.au/__data/page/3303/S002_2001.pdf
+; Normal Ring
+ringcadence = 400,200,400,2000
+; Distinctive Ring 1 - Forwarded Calls
+; 400,400,200,200,400,1400
+; Distinctive Ring 2 - Selective Ring 2 + Operator + Recall
+; 400,400,200,2000
+; Distinctive Ring 3 - Multiple Subscriber Number 1
+; 200,200,400,2200
+; Distinctive Ring 4 - Selective Ring 1 + Centrex
+; 400,2600
+; Distinctive Ring 5 - Selective Ring 3
+; 400,400,200,400,200,1400
+; Distinctive Ring 6 - Multiple Subscriber Number 2
+; 200,400,200,200,400,1600
+; Distinctive Ring 7 - Multiple Subscriber Number 3 + Data Privacy
+; 200,400,200,400,200,1600
+; Tones
+dial = 413+438
+busy = 425/375,0/375
+ring = 413+438/400,0/200,413+438/400,0/2000
+; XXX Congestion: Should reduce by 10 db every other cadence XXX
+congestion = 425/375,0/375,420/375,0/375
+callwaiting = 425/200,0/200,425/200,0/4400
+dialrecall = 413+438
+; Record tone used for Call Intrusion/Recording or Conference
+record = !425/1000,!0/15000,425/360,0/15000
+info = 425/2500,0/500
+; Other Australian Tones
+; The STD "pips" indicate the call is not an untimed local call
+std = !525/100,!0/100,!525/100,!0/100,!525/100,!0/100,!525/100,!0/100,!525/100
+; Facility confirmation tone (eg. Call Forward Activated)
+facility = 425
+; Message Waiting "stutter" dialtone
+stutter = 413+438/100,0/40
+; Ringtone for calls to Telstra mobiles
+ringmobile = 400+450/400,0/200,400+450/400,0/2000
+
+[bg]
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+description = Bulgaria
+ringcadence = 1000,4000
+;
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 425/150,0/150,425/150,0/4000
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+record = 1400/425,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425/1500,0/100
+
+[br]
+description = Brazil
+ringcadence = 1000,4000
+dial = 425
+busy = 425/250,0/250
+ring = 425/1000,0/4000
+congestion = 425/250,0/250,425/750,0/250
+callwaiting = 425/50,0/1000
+; Dialrecall not used in Brazil standard (using UK standard)
+dialrecall = 350+440
+; Record tone is not used in Brazil, use busy tone
+record = 425/250,0/250
+; Info not used in Brazil standard (using UK standard)
+info = 950/330,1400/330,1800/330
+stutter = 350+440
+
+[be]
+description = Belgium
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,3000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/3000
+congestion = 425/167,0/167
+callwaiting = 1400/175,0/175,1400/175,0/3500
+; DIALRECALL - not specified
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440"
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = 900/330,1400/330,1800/330,0/1000
+stutter = 425/1000,0/250
+
+[ch]
+description = Switzerland
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/200,0/200,425/200,0/4000
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; RECORDTONE - not specified
+record = 1400/80,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425+340/1100,0/1100
+
+[cl]
+description = Chile
+; According to specs from Telefonica CTC Chile
+ringcadence = 1000,3000
+dial = 400
+busy = 400/500,0/500
+ring = 400/1000,0/3000
+congestion = 400/200,0/200
+callwaiting = 400/250,0/8750
+dialrecall = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
+record = 1400/500,0/15000
+info = 950/333,1400/333,1800/333,0/1000
+stutter = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
+
+[cn]
+description = China
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 450
+busy = 450/350,0/350
+ring = 450/1000,0/4000
+congestion = 450/700,0/700
+callwaiting = 450/400,0/4000
+dialrecall = 450
+record = 950/400,0/10000
+info = 450/100,0/100,450/100,0/100,450/100,0/100,450/400,0/400
+; STUTTER - not specified
+stutter = 450+425
+
+[cz]
+description = Czech Republic
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425/330,0/330,425/660,0/660
+busy = 425/330,0/330
+ring = 425/1000,0/4000
+congestion = 425/165,0/165
+callwaiting = 425/330,0/9000
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425/330,0/330,425/660,0/660
+; RECORDTONE - not specified
+record = 1400/500,0/14000
+info = 950/330,0/30,1400/330,0/30,1800/330,0/1000
+; STUTTER - not specified
+stutter = 425/450,0/50
+
+[de]
+description = Germany
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/480,0/480
+ring = 425/1000,0/4000
+congestion = 425/240,0/240
+callwaiting = !425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,0
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; RECORDTONE - not specified
+record = 1400/80,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425+400
+
+[dk]
+description = Denmark
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = !425/200,!0/600,!425/200,!0/3000,!425/200,!0/200,!425/200,0
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; RECORDTONE - not specified
+record = 1400/80,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+; STUTTER - not specified
+stutter = 425/450,0/50
+
+[ee]
+description = Estonia
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/300,0/300
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+; CALLWAIT not in accordance to ITU
+callwaiting = 950/650,0/325,950/325,0/30,1400/1300,0/2600
+; DIALRECALL - not specified
+dialrecall = 425/650,0/25
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; INFO not in accordance to ITU
+info = 950/650,0/325,950/325,0/30,1400/1300,0/2600
+; STUTTER not specified
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[es]
+description = Spain
+ringcadence = 1500,3000
+dial = 425
+busy = 425/200,0/200
+ring = 425/1500,0/3000
+congestion = 425/200,0/200,425/200,0/200,425/200,0/600
+callwaiting = 425/175,0/175,425/175,0/3500
+dialrecall = !425/200,!0/200,!425/200,!0/200,!425/200,!0/200,425
+record = 1400/500,0/15000
+info = 950/330,0/1000
+dialout = 500
+
+
+[fi]
+description = Finland
+ringcadence = 1000,4000
+dial = 425
+busy = 425/300,0/300
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/150,0/150,425/150,0/8000
+dialrecall = 425/650,0/25
+record = 1400/500,0/15000
+info = 950/650,0/325,950/325,0/30,1400/1300,0/2600
+stutter = 425/650,0/25
+
+[fr]
+description = France
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1500,3500
+; Dialtone can also be 440+330
+dial = 440
+busy = 440/500,0/500
+ring = 440/1500,0/3500
+; CONGESTION - not specified
+congestion = 440/250,0/250
+callwait = 440/300,0/10000
+; DIALRECALL - not specified
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330
+stutter = !440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,440
+
+[gr]
+description = Greece
+ringcadence = 1000,4000
+dial = 425/200,0/300,425/700,0/800
+busy = 425/300,0/300
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/150,0/150,425/150,0/8000
+dialrecall = 425/650,0/25
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 425/650,0/25
+
+[hu]
+description = Hungary
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1250,3750
+dial = 425
+busy = 425/300,0/300
+ring = 425/1250,0/3750
+congestion = 425/300,0/300
+callwaiting = 425/40,0/1960
+dialrecall = 425+450
+; RECORDTONE - not specified
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 350+375+400
+
+[il]
+description = Israel
+ringcadence = 1000,3000
+dial = 414
+busy = 414/500,0/500
+ring = 414/1000,0/3000
+congestion = 414/250,0/250
+callwaiting = 414/100,0/100,414/100,0/100,414/600,0/3000
+dialrecall = !414/100,!0/100,!414/100,!0/100,!414/100,!0/100,414
+record = 1400/500,0/15000
+info = 1000/330,1400/330,1800/330,0/1000
+stutter = !414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,414
+
+
+[in]
+description = India
+ringcadence = 400,200,400,2000
+dial = 400*25
+busy = 400/750,0/750
+ring = 400*25/400,0/200,400*25/400,0/2000
+congestion = 400/250,0/250
+callwaiting = 400/200,0/100,400/200,0/7500
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0/1000
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[it]
+description = Italy
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425/200,0/200,425/600,0/1000
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/400,0/100,425/250,0/100,425/150,0/14000
+dialrecall = 470/400,425/400
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 470/400,425/400
+
+[lt]
+description = Lithuania
+ringcadence = 1000,4000
+dial = 425
+busy = 425/350,0/350
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/150,0/150,425/150,0/4000
+; DIALRECALL - not specified
+dialrecall = 425/500,0/50
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+; STUTTER - not specified
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[jp]
+description = Japan
+ringcadence = 1000,2000
+dial = 400
+busy = 400/500,0/500
+ring = 400+15/1000,0/2000
+congestion = 400/500,0/500
+callwaiting = 400+16/500,0/8000
+dialrecall = !400/200,!0/200,!400/200,!0/200,!400/200,!0/200,400
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
+
+[mx]
+description = Mexico
+ringcadence = 2000,4000
+dial = 425
+busy = 425/250,0/250
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 425/200,0/600,425/200,0/10000
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+record = 1400/500,0/15000
+info = 950/330,0/30,1400/330,0/30,1800/330,0/1000
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[my]
+description = Malaysia
+ringcadence = 2000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/400,0/200
+congestion = 425/500,0/500
+
+[nl]
+description = Netherlands
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+; Most of these 425's can also be 450's
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 425/500,0/9500
+; DIALRECALL - not specified
+dialrecall = 425/500,0/50
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425/500,0/50
+
+[no]
+description = Norway
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/200,0/600,425/200,0/10000
+dialrecall = 470/400,425/400
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 470/400,425/400
+
+[nz]
+description = New Zealand
+;NOTE - the ITU has different tonesets for NZ, but according to some residents there,
+; this is, indeed, the correct way to do it.
+ringcadence = 400,200,400,2000
+dial = 400
+busy = 400/250,0/250
+ring = 400+450/400,0/200,400+450/400,0/2000
+congestion = 400/375,0/375
+callwaiting = !400/200,!0/3000,!400/200,!0/3000,!400/200,!0/3000,!400/200
+dialrecall = !400/100!0/100,!400/100,!0/100,!400/100,!0/100,400
+record = 1400/425,0/15000
+info = 400/750,0/100,400/750,0/100,400/750,0/100,400/750,0/400
+stutter = !400/100!0/100,!400/100,!0/100,!400/100,!0/100,!400/100!0/100,!400/100,!0/100,!400/100,!0/100,400
+unobtainable = 400/75,0/100,400/75,0/100,400/75,0/100,400/75,0/400
+
+[ph]
+
+; reference http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+
+description = Philippines
+ringcadence = 1000,4000
+dial = 425
+busy = 480+620/500,0/500
+ring = 425+480/1000,0/4000
+congestion = 480+620/250,0/250
+callwaiting = 440/300,0/10000
+; DIALRECALL - not specified
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; INFO - not specified
+info = !950/330,!1400/330,!1800/330,0
+; STUTTER - not specified
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+
+[pl]
+description = Poland
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/500,0/500
+callwaiting = 425/150,0/150,425/150,0/4000
+; DIALRECALL - not specified
+dialrecall = 425/500,0/50
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; 950/1400/1800 3x0.33 on 1.0 off repeated 3 times
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000
+; STUTTER - not specified
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[pt]
+description = Portugal
+ringcadence = 1000,5000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/5000
+congestion = 425/200,0/200
+callwaiting = 440/300,0/10000
+dialrecall = 425/1000,0/200
+record = 1400/500,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[ru]
+; References:
+; http://www.minsvyaz.ru/site.shtml?id=1806
+; http://www.aboutphone.info/lib/gost/45-223-2001.html
+description = Russian Federation / ex Soviet Union
+ringcadence = 1000,4000
+dial = 425
+busy = 425/350,0/350
+ring = 425/1000,0/4000
+congestion = 425/175,0/175
+callwaiting = 425/200,0/5000
+record = 1400/400,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+dialrecall = 425/400,0/40
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[se]
+description = Sweden
+ringcadence = 1000,5000
+dial = 425
+busy = 425/250,0/250
+ring = 425/1000,0/5000
+congestion = 425/250,0/750
+callwaiting = 425/200,0/500,425/200,0/9100
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+record = 1400/500,0/15000
+info = !950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,0
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; stutter = 425/320,0/20 ; Real swedish standard, not used for now
+
+[sg]
+description = Singapore
+; Singapore
+; Reference: http://www.ida.gov.sg/idaweb/doc/download/I397/ida_ts_pstn1_i4r2.pdf
+; Frequency specs are: 425 Hz +/- 20Hz; 24 Hz +/- 2Hz; modulation depth 100%; SIT +/- 50Hz
+ringcadence = 400,200,400,2000
+dial = 425
+ring = 425*24/400,0/200,425*24/400,0/2000 ; modulation should be 100%, not 90%
+busy = 425/750,0/750
+congestion = 425/250,0/250
+callwaiting = 425*24/300,0/200,425*24/300,0/3200
+stutter = !425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,425
+info = 950/330,1400/330,1800/330,0/1000 ; not currently in use acc. to reference
+dialrecall = 425*24/500,0/500,425/500,0/2500 ; unspecified in IDA reference, use repeating Holding Tone A,B
+record = 1400/500,0/15000 ; unspecified in IDA reference, use 0.5s tone every 15s
+; additionally defined in reference
+nutone = 425/2500,0/500
+intrusion = 425/250,0/2000
+warning = 425/624,0/4376 ; end of period tone, warning
+acceptance = 425/125,0/125
+holdinga = !425*24/500,!0/500 ; followed by holdingb
+holdingb = !425/500,!0/2500
+
+[th]
+description = Thailand
+ringcadence = 1000,4000
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+dial = 400*50
+busy = 400/500,0/500
+ring = 420/1000,0/5000
+congestion = 400/300,0/300
+callwaiting = 1000/400,10000/400,1000/400
+; DIALRECALL - not specified - use special dial tone instead.
+dialrecall = 400*50/400,0/100,400*50/400,0/100
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; INFO - specified as an announcement - use special information tones instead
+info = 950/330,1400/330,1800/330
+; STUTTER - not specified
+stutter = !400/200,!0/200,!400/600,!0/200,!400/200,!0/200,!400/600,!0/200,!400/200,!0/200,!400/600,!0/200,!400/200,!0/200,!400/600,!0/200,400
+
+[uk]
+description = United Kingdom
+ringcadence = 400,200,400,2000
+; These are the official tones taken from BT SIN350. The actual tones
+; used by BT include some volume differences so sound slightly different
+; from Asterisk-generated ones.
+dial = 350+440
+; Special dial is the intermittent dial tone heard when, for example,
+; you have a divert active on the line
+specialdial = 350+440/750,440/750
+; Busy is also called "Engaged"
+busy = 400/375,0/375
+; "Congestion" is the Beep-bip engaged tone
+congestion = 400/400,0/350,400/225,0/525
+; "Special Congestion" is not used by BT very often if at all
+specialcongestion = 400/200,1004/300
+unobtainable = 400
+ring = 400+450/400,0/200,400+450/400,0/2000
+callwaiting = 400/100,0/4000
+; BT seem to use "Special Call Waiting" rather than just "Call Waiting" tones
+specialcallwaiting = 400/250,0/250,400/250,0/250,400/250,0/5000
+; "Pips" used by BT on payphones. (Sounds wrong, but this is what BT claim it
+; is and I've not used a payphone for years)
+creditexpired = 400/125,0/125
+; These two are used to confirm/reject service requests on exchanges that
+; don't do voice announcements.
+confirm = 1400
+switching = 400/200,0/400,400/2000,0/400
+; This is the three rising tones Doo-dah-dee "Special Information Tone",
+; usually followed by the BT woman saying an appropriate message.
+info = 950/330,0/15,1400/330,0/15,1800/330,0/1000
+; Not listed in SIN350
+record = 1400/500,0/60000
+stutter = 350+440/750,440/750
+
+[us]
+description = United States / North America
+ringcadence = 2000,4000
+dial = 350+440
+busy = 480+620/500,0/500
+ring = 440+480/2000,0/4000
+congestion = 480+620/250,0/250
+callwaiting = 440/300,0/10000
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[us-old]
+description = United States Circa 1950/ North America
+ringcadence = 2000,4000
+dial = 600*120
+busy = 500*100/500,0/500
+ring = 420*40/2000,0/4000
+congestion = 500*100/250,0/250
+callwaiting = 440/300,0/10000
+dialrecall = !600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120
+
+[tw]
+description = Taiwan
+; http://nemesis.lonestar.org/reference/telecom/signaling/dialtone.html
+; http://nemesis.lonestar.org/reference/telecom/signaling/busy.html
+; http://www.iproducts.com.tw/ee/kylink/06ky-1000a.htm
+; http://www.pbx-manufacturer.com/ky120dx.htm
+; http://www.nettwerked.net/tones.txt
+; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/taiw_sup/taiw2.htm
+;
+; busy tone 480+620Hz 0.5 sec. on ,0.5 sec. off
+; reorder tone 480+620Hz 0.25 sec. on,0.25 sec. off
+; ringing tone 440+480Hz 1 sec. on ,2 sec. off
+;
+ringcadence = 1000,4000
+dial = 350+440
+busy = 480+620/500,0/500
+ring = 440+480/1000,0/2000
+congestion = 480+620/250,0/250
+callwaiting = 350+440/250,0/250,350+440/250,0/3250
+dialrecall = 300/1500,0/500
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[ve]
+; Tone definition source for ve found on
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+description = Venezuela / South America
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 400+450/300,0/6000
+dialrecall = 425
+record = 1400/500,0/15000
+info = !950/330,!1440/330,!1800/330,0/1000
+
+
+[za]
+description = South Africa
+; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/safr_sup/saf02.htm
+; (definitions for other countries can also be found there)
+; Note, though, that South Africa uses two switch types in their network --
+; Alcatel switches -- mainly in the Western Cape, and Siemens elsewhere.
+; The former use 383+417 in dial, ringback etc. The latter use 400*33
+; I've provided both, uncomment the ones you prefer
+ringcadence = 400,200,400,2000
+; dial/ring/callwaiting for the Siemens switches:
+dial = 400*33
+ring = 400*33/400,0/200,400*33/400,0/2000
+callwaiting = 400*33/250,0/250,400*33/250,0/250,400*33/250,0/250,400*33/250,0/250
+; dial/ring/callwaiting for the Alcatel switches:
+; dial = 383+417
+; ring = 383+417/400,0/200,383+417/400,0/2000
+; callwaiting = 383+417/250,0/250,383+417/250,0/250,383+417/250,0/250,383+417/250,0/250
+congestion = 400/250,0/250
+busy = 400/500,0/500
+dialrecall = 350+440
+; XXX Not sure about the RECORDTONE
+record = 1400/500,0/10000
+info = 950/330,1400/330,1800/330,0/330
+stutter = !400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,400*33
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE
new file mode 100644
index 000000000..cf71e1f8f
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE
@@ -0,0 +1,4 @@
+[general]
+autoregister=yes
+
+#include jabber_users.conf
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE
new file mode 100644
index 000000000..3ee2463ed
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE
@@ -0,0 +1,8 @@
+[gtalk-|NAME|]
+type=client
+serverhost=talk.google.com
+username=|USERNAME|/Talk
+secret=|SECRET|
+timeout=150
+status=|STATUS|
+statusmessage=|STATUSMESSAGE|
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE
new file mode 100644
index 000000000..e57325013
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE
@@ -0,0 +1,7 @@
+[general]
+queue_log = no
+event_log = no
+
+[logfiles]
+console => notice,warning,error
+messages => error
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE
new file mode 100644
index 000000000..2ac2f0033
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE
@@ -0,0 +1,7 @@
+[general]
+enabled = no
+
+port = 5038
+bindaddr = 0.0.0.0
+
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE
new file mode 100644
index 000000000..93c74336d
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE
@@ -0,0 +1,34 @@
+[modules]
+autoload=no
+load => res_jabber.so ; Used for Gtalk
+load => res_clioriginate.so ; originate calls from commandline
+load => res_rtp_asterisk.so ; rtp "engine" is now a loadable module in asterisk 1.8
+load => pbx_config.so ; Text Extension Configuration Requires N/A
+load => func_callerid.so ; Gets or sets Caller*ID data on the channel. - Requires ?
+load => func_channel.so
+load => func_logic.so ; Logic functions (if, etc.)
+load => func_strings.so ; string manipulation functions
+load => cdr_manager.so ; Asterisk Call Manager CDR Backend - Requires N/A
+load => chan_local.so ; Show status of local channels- Requires N/A
+load => chan_gtalk.so ; Use gtalk
+load => chan_sip.so ; Session Initiation Protocol (SIP) - Requires res_features.so
+load => codec_alaw.so ; A-law Coder/Decoder - Requires N/A
+load => codec_a_mu.so ; A-law and Mulaw direct Coder/Decoder - Requires N/A
+load => codec_gsm.so ; GSM/PCM16 (signed linear) Codec Translat - Requires N/A
+load => codec_ulaw.so ; Mu-law Coder/Decoder - Requires N/A
+load => format_gsm.so ; Raw GSM data - Requires N/A
+load => format_pcm.so ; Raw uLaw 8khz Audio support (PCM) - Requires N/A
+load => format_wav_gsm.so
+load => app_dial.so ; Dialing Application - Requires res_features.so, res_musiconhold.so
+load => app_parkandannounce.so ; Call Parking and Announce Application - Requires res_features.so
+load => app_playback.so ; Sound File Playback Application - Requires N/A
+load => app_record.so ; Sound File Record Application - Requires N/A
+load => app_system.so ; Execute a system command - Requires N/A
+load => app_disa.so ; Direct Inward System Access
+load => app_authenticate.so ; Authenticate via pin
+load => app_senddtmf.so ; Ability to send DTMF tones on the line.
+load => func_cut.so ; To manipulate strings
+load => func_timeout.so ; Used for DISA timeouts
+
+[global]
+chan_modem.so=no
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE
new file mode 100644
index 000000000..10d577d3a
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE
@@ -0,0 +1,6 @@
+[general]
+rtpstart=|RTPSTART|
+rtpend=|RTPEND|
+rtpchecksums=no
+dtmftimeout=3000
+rtcpinterval = 2000
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE
new file mode 100644
index 000000000..8f3b112ff
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE
@@ -0,0 +1,39 @@
+[general]
+transport=udp
+context=default-incoming-call-context
+allowoverlap=yes
+allowtransfer=yes
+realm=asterisk
+bindaddr=0.0.0.0
+srvlookup=yes
+maxexpiry=600
+minexpiry=60
+defaultexpiry=300
+qualifyfreq=55
+disallow=all
+allow=ulaw
+allow=alaw
+dtmfmode = inband
+alwaysauthreject = yes
+t1min=100
+timert1=500
+timerb=16000
+rtptimeout=600
+rtpkeepalive=30
+useragent=|USERAGENT|
+localnet=192.168.0.0/16
+localnet=10.0.0.0/8
+localnet=172.16.0.0/12
+nat=yes
+directmedia=no
+sipdebug=no
+bindport=|BINDPORT|
+externhost=|EXTERNHOST|
+externrefresh=60
+
+#include sip_registrations.conf
+
+[authentication]
+
+#include sip_peers.conf
+#include sip_users.conf
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE
new file mode 100644
index 000000000..30abaadd5
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE
@@ -0,0 +1,13 @@
+
+[peer-|NAME|]
+type = peer
+defaultuser = |DEFAULTUSER|
+fromuser = |FROMUSER|
+secret = |SECRET|
+host = |HOST|
+fromdomain = |FROMDOMAIN|
+context = context-incoming-|NAME|
+insecure = port,invite
+qualify = 2000
+|PORT|
+|OUTBOUNDPROXY|
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE
new file mode 100644
index 000000000..e139d43f0
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE
@@ -0,0 +1,2 @@
+register => |DEFAULTUSER|:|SECRET|@peer-|NAME|
+
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE
new file mode 100644
index 000000000..61a8b0b86
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE
@@ -0,0 +1,11 @@
+
+[|DEFAULTUSER|]
+fullname = |FULLNAME|
+defaultuser = |DEFAULTUSER|
+secret = |SECRET|
+hassip = yes
+hasvoicemail = no
+host = dynamic
+type = friend
+context = context-user-|CONTEXTNAME|
+qualify = no \ No newline at end of file
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-alreadyon.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-alreadyon.gsm
new file mode 100644
index 000000000..83fe27ecf
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-alreadyon.gsm
Binary files differ
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-incorrect.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-incorrect.gsm
new file mode 100644
index 000000000..27d934beb
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-incorrect.gsm
Binary files differ
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-pass.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-pass.gsm
new file mode 100644
index 000000000..f95637bb3
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/agent-pass.gsm
Binary files differ
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-incorrect.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-incorrect.gsm
new file mode 100644
index 000000000..12fec25d5
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-incorrect.gsm
Binary files differ
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-thankyou.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-thankyou.gsm
new file mode 100644
index 000000000..93f936d1a
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/auth-thankyou.gsm
Binary files differ
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/beep.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/beep.gsm
new file mode 100644
index 000000000..d38eda9cc
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/beep.gsm
Binary files differ
diff --git a/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/vm-goodbye.gsm b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/vm-goodbye.gsm
new file mode 100644
index 000000000..735b281c8
--- /dev/null
+++ b/applications/luci-app-pbx/root/etc/pbx-asterisk/sounds/vm-goodbye.gsm
Binary files differ