summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-pbx/root/etc
diff options
context:
space:
mode:
authorIordan Iordanov <iiordanov@gmail.com>2011-10-28 03:44:23 +0000
committerIordan Iordanov <iiordanov@gmail.com>2011-10-28 03:44:23 +0000
commit33caee55e4e3657511a49105a1a34a15fe994e0a (patch)
tree79dc376423e6296af061ea09bae98d02bef11868 /applications/luci-pbx/root/etc
parent84acc67709d4c60470e2727ff991170739d61537 (diff)
This is the initial release of luci-pbx as submitted to the mailing list.
Diffstat (limited to 'applications/luci-pbx/root/etc')
-rw-r--r--applications/luci-pbx/root/etc/config/pbx1
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-advanced1
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-calls7
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-google0
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-users1
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-voip0
-rw-r--r--applications/luci-pbx/root/etc/init.d/pbx-asterisk638
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE17
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE30
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE3
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE4
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE11
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE9
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE9
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE8
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE3
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE10
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE733
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE4
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE8
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE7
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE7
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE31
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE6
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE37
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE13
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE11
41 files changed, 1629 insertions, 0 deletions
diff --git a/applications/luci-pbx/root/etc/config/pbx b/applications/luci-pbx/root/etc/config/pbx
new file mode 100644
index 000000000..ca7c1669d
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx
@@ -0,0 +1 @@
+config 'main' 'connection_status'
diff --git a/applications/luci-pbx/root/etc/config/pbx-advanced b/applications/luci-pbx/root/etc/config/pbx-advanced
new file mode 100644
index 000000000..e7ac0e221
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-advanced
@@ -0,0 +1 @@
+config 'settings' 'advanced'
diff --git a/applications/luci-pbx/root/etc/config/pbx-calls b/applications/luci-pbx/root/etc/config/pbx-calls
new file mode 100644
index 000000000..822bd4a1b
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/config/pbx-google b/applications/luci-pbx/root/etc/config/pbx-google
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-google
diff --git a/applications/luci-pbx/root/etc/config/pbx-users b/applications/luci-pbx/root/etc/config/pbx-users
new file mode 100644
index 000000000..a4277b1bf
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-users
@@ -0,0 +1 @@
+config 'user' 'server'
diff --git a/applications/luci-pbx/root/etc/config/pbx-voip b/applications/luci-pbx/root/etc/config/pbx-voip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-voip
diff --git a/applications/luci-pbx/root/etc/init.d/pbx-asterisk b/applications/luci-pbx/root/etc/init.d/pbx-asterisk
new file mode 100644
index 000000000..d96eb4f08
--- /dev/null
+++ b/applications/luci-pbx/root/etc/init.d/pbx-asterisk
@@ -0,0 +1,638 @@
+#!/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/>.
+
+. /etc/functions.sh
+
+START=60
+
+# Some global variables
+MODULENAME=pbx
+USERAGENT="PBX"
+DEFAULTOUTCNTXT=default-outgoing-call-context
+HANGUPCNTXT=hangup
+GTALKUNVL=unavailable
+
+ASTUSER=nobody
+ASTGROUP=nogroup
+ASTDIRSRECURSIVE="/var/run/asterisk /var/log/asterisk /var/spool/asterisk"
+ASTDIRS="/usr/lib/asterisk"
+
+FIREWALL_PATH="/etc/asterisk/firewall.$MODULENAME"
+
+TEMPLATEDIR=/etc/${MODULENAME}-asterisk
+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_EXTENSIONS=$TEMPLATEDIR/extensions.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_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_FIREWALL=$TEMPLATEDIR/firewall.$MODULENAME.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
+
+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"
+
+
+# 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=""
+
+# 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
+}
+
+# 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()
+{
+ sed "s/|LOCALUSERS|/$localusers_to_ring/g" $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
+ rm -f $WORKDIR/outext-*.TMP
+ rm -f $WORKDIR/localext.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 secret
+ local ring
+ local can_call
+
+ config_get fullname $1 fullname
+ config_get defaultuser $1 defaultuser
+ config_get secret $1 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 $defaultuser"
+ 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
+
+ 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
+ config_get secret $1 secret
+ 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
+ config_get statusmessage $1 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 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
+ 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
+ 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
+ config_get secret $1 secret
+ config_get host $1 host
+ config_get port $1 port
+ config_get outbountproxy $1 outboundproxy
+ config_get fromdomain $1 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
+ 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
+ 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
+ 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
+ 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
+
+ config_get callthrough_number_list $1 callthrough_number_list
+ config_get defaultuser $1 defaultuser
+ config_get pin $1 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
+
+ sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRU |\
+ 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
+ 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
+}
+
+# Makes sure the ownership of specified directories is proper.
+pbx_fix_ownership()
+{
+ chown $ASTUSER:$ASTGROUP $ASTDIRS
+ chown $ASTUSER:$ASTGROUP -R $ASTDIRSRECURSIVE
+}
+
+# Creates firewall configuration. However, since this functionality is now
+# taken over by pbx-advanced.lua, this function is unused.
+create_firewall_config()
+{
+ local bindport
+ local rtpstart
+ local rtpend
+ local externhost
+
+ config_get bindport advanced bindport
+ config_get externhost advanced externhost
+ config_get rtpstart advanced rtpstart
+ config_get rtpend advanced rtpend
+
+ # We need all of these parameters to be set in order to consider inserting firewall rules.
+ if [ -z "$externhost" -o -z "$bindport" -o -z "$rtpstart" -o -z "$rtpend" ] ; then
+ rm -f $FIREWALL_PATH
+ return
+ fi
+
+ sed "s/|SIPPORT|/$bindport/g" $TMPL_FIREWALL |\
+ sed "s/|RTPRANGE|/$rtpstart:$rtpend/g" > $WORKDIR/firewall.$MODULENAME
+
+ # Make sure there is an include section in the firewall configuration
+ # to include the file we just created.
+ i=0 ; found_path=0
+ while p=`uci get firewall.@include[$i].path 2>/dev/null` ; do
+ if [ "$p" = "$FIREWALL_PATH" ] ; then
+ found_path=1
+ break
+ fi
+ i=`expr $i + 1`
+ done
+
+ # If no include section was found which mentions $FIREWALL_PATH, add one.
+ if [ $found_path -eq 0 ] ; then
+ uci add firewall include 1>/dev/null 2>/dev/null
+ uci set firewall.@include[-1].path="$FIREWALL_PATH"
+ uci commit firewall
+ fi
+}
+
+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, and phone blacklist.
+ config_unset
+ config_load ${MODULENAME}-calls
+ pbx_create_user_contexts
+ pbx_add_blacklist
+ config_foreach pbx_add_callthrough callthrough_numbers
+
+ # Prepare sip.conf using settings from the "advanced" section.
+ config_unset
+ config_load ${MODULENAME}-advanced
+ pbx_cook_sip_template
+ pbx_cook_rtp_template
+
+ # Assemble the configuration, and copy changed files over.
+ pbx_assemble_and_copy_config
+
+ # Enforce ownership of specified files and directories.
+ pbx_fix_ownership
+}
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE
new file mode 100644
index 000000000..ae6340af8
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE
@@ -0,0 +1,17 @@
+[directories]
+astetcdir => /etc/asterisk
+astmoddir => /usr/lib/asterisk/modules
+astvarlibdir => /var/lib/asterisk
+astdbdir => /usr/lib/asterisk
+astkeydir => /var/lib/asterisk
+astdatadir => /usr/share/asterisk
+astagidir => /usr/share/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-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE
new file mode 100644
index 000000000..f3edac384
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE
@@ -0,0 +1,30 @@
+[general]
+static = yes
+writeprotect = yes
+clearglobalvars = no
+
+[globals]
+
+[default]
+
+[context-user-hangup]
+exten => s,1,Hangup()
+exten => _X.,1,Hangup()
+
+[context-catch-all]
+exten => _[!-~].,1,Dial(SIP/${EXTEN},60,r)
+
+[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(disa-check-call-context,s,1)
+exten => s,n(donedisacheck),Dial(|LOCALUSERS|,60,r)
+
+#include extensions_incoming.conf
+#include extensions_incoming_gtalk.conf
+#include extensions_blacklist.conf
+#include extensions_callthrough.conf
+#include extensions_user.conf
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE
new file mode 100644
index 000000000..54ee989b0
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE
new file mode 100644
index 000000000..da964f238
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE
new file mode 100644
index 000000000..de0e98465
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE
new file mode 100644
index 000000000..ba2379b73
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE
new file mode 100644
index 000000000..74056fa01
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE
new file mode 100644
index 000000000..e0d67b802
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE
new file mode 100644
index 000000000..e799d5210
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE
@@ -0,0 +1,4 @@
+exten => |NUMBER|,1,Noop()
+exten => |NUMBER|,n,Authenticate(|PIN|)
+exten => |NUMBER|,n,DISA(no-password,context-user-|DEFAULTUSER|)
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE
new file mode 100644
index 000000000..a74227114
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[disa-call-context]
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..dc0c68add
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE
@@ -0,0 +1,11 @@
+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(disa-check-call-context,s,1)
+same => n(donedisacheck),Dial(|LOCALUSERS|,60,D(:w11111111))
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE
new file mode 100644
index 000000000..f6e44a5bf
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[context-incoming-gtalk]
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE
new file mode 100644
index 000000000..12ecefc80
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE
@@ -0,0 +1,9 @@
+
+[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(disa-check-call-context,s,1)
+exten => s,n(donedisacheck),Dial(|LOCALUSERS|,60,r)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE
new file mode 100644
index 000000000..a7f36cf91
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE
@@ -0,0 +1,2 @@
+
+[context-outgoing-|NAME|]
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE
new file mode 100644
index 000000000..b81da9eab
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => |DEFAULTUSER|,1,Dial(SIP/|DEFAULTUSER|,60,r)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..259c2ceaa
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..1fa7713e2
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE
new file mode 100644
index 000000000..178b6deaa
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE
new file mode 100644
index 000000000..9b1d9addc
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE
new file mode 100644
index 000000000..7ce1060dc
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE
@@ -0,0 +1 @@
+include => context-catch-all
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE
new file mode 100644
index 000000000..5931eaf28
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE
@@ -0,0 +1,3 @@
+
+[context-user-|DEFAULTUSER|]
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE
new file mode 100644
index 000000000..91e9f66d8
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE
@@ -0,0 +1,2 @@
+iptables -I INPUT 3 -p udp -s 0/0 -d 0/0 --dport |SIPPORT| -j ACCEPT
+iptables -I INPUT 3 -p udp -s 0/0 -d 0/0 --dport |RTPRANGE| -j ACCEPT
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..4f07a7166
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE
new file mode 100644
index 000000000..d7088db7c
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE
new file mode 100644
index 000000000..cf71e1f8f
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE
@@ -0,0 +1,4 @@
+[general]
+autoregister=yes
+
+#include jabber_users.conf
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE
new file mode 100644
index 000000000..3ee2463ed
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE
new file mode 100644
index 000000000..e57325013
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE
new file mode 100644
index 000000000..2ac2f0033
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE
new file mode 100644
index 000000000..3594dad43
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE
@@ -0,0 +1,31 @@
+[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 => 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_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
+
+[global]
+chan_modem.so=no
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE
new file mode 100644
index 000000000..10d577d3a
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE
new file mode 100644
index 000000000..6069554e0
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE
@@ -0,0 +1,37 @@
+[general]
+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|
+
+#include sip_registrations.conf
+
+[authentication]
+
+#include sip_peers.conf
+#include sip_users.conf
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE
new file mode 100644
index 000000000..30abaadd5
--- /dev/null
+++ b/applications/luci-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-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE
new file mode 100644
index 000000000..e139d43f0
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE
@@ -0,0 +1,2 @@
+register => |DEFAULTUSER|:|SECRET|@peer-|NAME|
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE
new file mode 100644
index 000000000..61a8b0b86
--- /dev/null
+++ b/applications/luci-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