Преглед изворни кода

Add one step to the end of the upgrade migration script.
Change the /mod/ to /app/ in the xml_cdr.conf.xml file.

Mark Crane пре 13 година
комит
25daba8524

+ 325 - 0
install/centos6/install_fusionpbx.sh

@@ -0,0 +1,325 @@
+#!/bin/bash
+
+###############################################
+#
+#   Installation Script to Install FreeSWITCH, FusionPBX, PostgreSQL, PHP, Apache and required
+#   Supporting software on Centos 6.
+#   Copyright (C) 2011, Ken Rice <[email protected]>
+#  
+#   Version: MPL 1.1
+#  
+#   The contents of this file are subject to the Mozilla Public License Version
+#   1.1 (the "License"); you may not use this file except in compliance with
+#   the License. You may obtain a copy of the License at
+#   http://www.mozilla.org/MPL/
+#  
+#   Software distributed under the License is distributed on an "AS IS" basis,
+#   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+#   for the specific language governing rights and limitations under the
+#   License.
+#  
+#   The Initial Developer of the Original Code is
+#   Ken Rice <[email protected]>
+#   Portions created by the Initial Developer are Copyright (C)
+#   the Initial Developer. All Rights Reserved.
+#  
+#   Contributor(s):
+#   
+#   Ken Rice <[email protected]>
+#  
+#   Also thanks to:
+#   The FreeSWITCH, FusionPBX and PostgreSQL Crews without them, none of this would be possible
+#  
+###############################################
+VERSION="0.2"
+
+cat <<EOT
+This Script will install and create base line configs for FreeSWITCH, FusionPBX, Fail2Ban, Monit and PostgreSQL.
+It is designed to run on a Centos6 Minimal Install. EPEL will also be temporarily Enabled to get a few packages
+not in the main Centos Repositories.
+
+As with anything you will want to review the configs after the installer to make sure they are what you want.
+
+This is Version $VERSION of this script.
+
+EOT
+
+read -r -p "Are you sure? [Y/n] " response
+if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
+then
+    echo "Here we go..."
+else
+    echo "Aborting"
+    exit
+fi
+
+# Do a Yum Update to update the system and then install all other required modules 
+yum update -y
+yum -y install autoconf automake gcc-c++ git-core libjpeg-devel libtool make ncurses-devel pkgconfig unixODBC-devel openssl-devel gnutls-devel libogg-devel libvorbis-devel curl-devel libtiff-devel libjpeg-devel python-devel expat-devel zlib zlib-devel bzip2 which postgresql-devel postgresql-odbc postgresql-server subversion screen vim php* ntp
+
+#lets get the Time Right
+ntpdate pool.ntp.org
+service ntpd start
+chkconfig ntpd on
+
+#Disable SELinux (Ken hates this thing)
+if [ -x /usr/sbin/setenforce ]
+	then
+		setenforce 0
+		/bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/sysconfig/selinux
+fi
+
+# Lets go Get the FreeSWITCH Source and install it
+cd /usr/src
+git clone git://git.freeswitch.org/freeswitch.git
+cd freeswitch
+./bootstrap.sh -j
+./configure --without-libcurl -C
+make -j `cat /proc/cpuinfo |grep processor |wc -l`
+make install
+make cd-moh-install && make cd-sounds-install
+#add a user for freeswitch
+useradd freeswitch
+
+#set ownership, perms, and install init scripts 
+cd /usr/local/
+chown -R freeswitch:freeswitch freeswitch
+chmod -R g+w freeswitch
+cd /usr/src/freeswitch/build
+cp freeswitch.init.redhat /etc/init.d/freeswitch
+chmod +x /etc/init.d/freeswitch 
+cp freeswitch.sysconfig /etc/sysconfig/freeswitch
+
+#Add Settings to freeswitch sysconfig file
+cat >> /etc/sysconfig/freeswitch <<EOT
+PID_FILE=/var/run/freeswitch/freeswitch.pid
+FS_USER=freeswitch
+FS_FILE=/usr/local/freeswitch/bin/freeswitch
+FS_HOME=/usr/local/freeswitch
+EOT
+
+# sym link fs_cli into /usr/local/bin so we don't have to adjust paths
+cd /usr/local/bin/
+ln -s /usr/local/freeswitch/bin/fs_cli fs_cli
+
+#start installing FusionPBX From Subversion
+cd /var/www
+svn co http://fusionpbx.googlecode.com/svn/trunk/fusionpbx html
+
+#fix FusionPBX Ownership and Perms
+chown -R apache:apache html
+cd /usr/local/freeswitch/conf/
+chmod 770 `find . -type d`
+chmod 660 `find . -type f`
+
+# add apache to the freeswitch Group
+usermod -a -G freeswitch apache
+
+## Install EPEL so we can get monit and ngrep 
+rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
+
+#Install Monit, Fail2Ban, and ngrep 
+yum install -y monit ngrep fail2ban
+
+#Drop monit configs in the right spot
+cat > /etc/monit.d/freeswitch <<EOT
+ check process freeswitch with pidfile /usr/local/freeswitch/run/freeswitch.pid
+   group voice
+   start program = "/etc/init.d/freeswitch start"
+   stop  program = "/etc/init.d/freeswitch stop"
+   if failed port 5060 type UDP then restart
+   if 5 restarts within 5 cycles then timeout
+   depends on freeswitch_bin
+   depends on freeswitch_rc
+
+ check file freeswitch_bin with path /usr/local/freeswitch/bin/freeswitch
+   group voice
+   if failed checksum then unmonitor
+   if failed permission 755 then unmonitor
+   if failed uid freeswitch then unmonitor
+
+ check file freeswitch_rc with path /etc/init.d/freeswitch
+   group voice
+   if failed checksum then unmonitor
+   if failed permission 755 then unmonitor
+   if failed uid root then unmonitor
+   if failed gid root then unmonitor
+
+EOT
+
+#Add Fail2Ban configs for 
+echo > /etc/fail2ban/filter.d/freeswitch.conf << EOT
+# Fail2Ban configuration file
+#
+# Author: Rupa SChomaker
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\S+\' for \[.*\] from ip <HOST>
+            \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\S+\' for \[.*\] from ip <HOST>
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+EOT
+
+echo >> /etc/fail2ban/jail.conf << EOT
+[freeswitch-tcp]
+
+enabled  = true
+port     = 5060,5061,5080,5081
+protocol = tcp
+filter   = freeswitch
+logpath  = /usr/local/freeswitch/log/freeswitch.log
+action   = iptables-allports[name=freeswitch-tcp, protocol=all]
+           sendmail-whois[name=FreeSwitch, dest=root, [email protected]]
+
+[freeswitch-udp]
+
+enabled  = true
+port     = 5060,5061,5080,5081
+protocol = udp
+filter   = freeswitch
+logpath  = /usr/local/freeswitch/log/freeswitch.log
+action   = iptables-allports[name=freeswitch-udp, protocol=all]
+           sendmail-whois[name=FreeSwitch, dest=root, [email protected]]
+EOT
+
+echo > /etc/fail2ban/filter.d/fusionpbx.conf << EOT
+# Fail2Ban configuration file
+#
+# Author: soapee01
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+#failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
+#[hostname] variable doesn't seem to work in every case. Do this instead:
+failregex = .* FusionPBX: \[<HOST>\] authentication failed for
+          = .* FusionPBX: \[<HOST>\] provision attempt bad password for
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+EOT
+
+echo >> /etc/fail2ban/jail.conf << EOT
+[fusionpbx]
+
+enabled  = true
+port     = 80,443
+protocol = tcp
+filter   = fusionpbx
+logpath  = /var/log/messages
+action   = iptables-allports[name=fusionpbx, protocol=all]
+           sendmail-whois[name=FusionPBX, dest=root, [email protected]] 
+
+EOT
+
+# start up some services and set them to run at boot
+service freeswitch start
+service httpd restart
+chkconfig freeswitch on
+chkconfig httpd on
+service monit start
+chkconfig monit on
+
+# INIT Postgresql, and set it for easyness
+#quick hack to postgresql init script to init the DB with trust access **** YOU MAY NOT WANT THIS FOR PRODUCTION ****
+/bin/sed -i -e s,'ident','trust', /etc/init.d/postgresql
+service postgresql initdb
+service postgresql start
+chkconfig postgresql on
+
+#set this back to normal
+/bin/sed -i -e s,'trust','ident', /etc/init.d/postgresql
+
+#disable epel repo for normal use. Leaving it enabled canhave unintended consequences
+/bin/sed -i -e s,'enabled=1','enabled=0', /etc/yum.repos.d/epel.repo
+
+#Make the Prompt Pretty and add a few aliases that come in handy
+cat >>~/.bashrc <<EOT
+export LESSCHARSET="latin1"
+export LESS="-R"
+export CHARSET="ISO-8859-1"
+export PS1='\n\[\033[01;31m\]\u@\h\[\033[01;36m\] [\d \@] \[\033[01;33m\] \w\n\[\033[00m\]<\#>:'
+export PS2="\[\033[1m\]> \[\033[0m\]"
+export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
+export VISUAL=vim
+
+umask 022
+alias vi='vim'
+alias fstop='top -p \`cat /usr/local/freeswitch/run/freeswitch.pid\`'
+alias fsgdb='gdb /usr/local/freeswitch/bin/freeswitch \`cat /usr/local/freeswitch/run/freeswitch.pid\`'
+alias fscore='gdb /usr/local/freeswitch/bin/freeswitch \`ls -rt core.* | tail -n1\`'
+EOT
+
+#Add a screenrc with a status line, a big scroll back and ^\ as the metakey as to not screw with emacs users
+cat >> ~/.screenrc <<EOT
+hardstatus alwaysignore
+startup_message off
+escape ^\b
+defscrollback 8000
+
+# status line at the bottom
+hardstatus on
+hardstatus alwayslastline
+hardstatus string "%{.bW}%-w%{.rW}%f%n %t%{-}%+w %=%{..G}[%H %l] %{..Y} %m/%d %c "
+
+termcapinfo xterm \'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l\'
+EOT
+
+
+# and finally lets fix up IPTables so things works correctly
+
+#Block 'friendly-scanner' AKA sipvicious
+iptables -I INPUT -p udp --dport 5060 -m string --string "friendly-scanner" --algo bm -j DROP
+iptables -I INPUT -p udp --dport 5080 -m string --string "friendly-scanner" --algo bm -j DROP
+
+#rate limit registrations to keep us from getting hammered on
+iptables -I INPUT -m string --string "REGISTER sip:" --algo bm --to 65 -m hashlimit --hashlimit 4/minute --hashlimit-burst 1 --hashlimit-mode srcip,dstport --hashlimit-name sip_r_limit -j ACCEPT
+
+# FreeSwitch ports internal SIP profile
+iptables -I INPUT -p udp -m udp --dport 5060 -j ACCEPT
+iptables -I INPUT -p tcp -m tcp --dport 5060 -j ACCEPT
+
+# FreeSwitch Ports external SIP profile
+iptables -I INPUT -p udp -m udp --dport 5080 -j ACCEPT
+iptables -I INPUT -p tcp -m tcp --dport 5080 -j ACCEPT
+
+# RTP Traffic 16384-32768
+iptables -I INPUT -p udp -m udp --dport 16384:32768 -j ACCEPT
+
+# Ports for the Web GUI
+iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
+iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
+
+#save the IPTables rules for later
+service iptables save
+
+
+LOCAL_IP=`ifconfig eth0 | head -n2 | tail -n1 | cut -d' ' -f12 | cut -c 6-`
+cat <<EOT
+As long as you didnt see errors by this point, PostgreSQL, FreeSWITCH, FusionPBX, Fail2Ban, and Monit should in installed.
+Point your browser to http://$LOCAL_IP/ and let the FusionPBX installer take it from there.
+
+EOT

+ 505 - 0
install/centos6/install_fusionpbx_postgres_9.1.sh

@@ -0,0 +1,505 @@
+#!/bin/bash
+
+###############################################
+#
+#   Installation Script to Install FreeSWITCH, FusionPBX, PostgreSQL, PHP, Apache and required
+#   Supporting software on Centos 6.
+#   Copyright (C) 2011, Ken Rice <[email protected]>
+#  
+#   Version: MPL 1.1
+#  
+#   The contents of this file are subject to the Mozilla Public License Version
+#   1.1 (the "License"); you may not use this file except in compliance with
+#   the License. You may obtain a copy of the License at
+#   http://www.mozilla.org/MPL/
+#  
+#   Software distributed under the License is distributed on an "AS IS" basis,
+#   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+#   for the specific language governing rights and limitations under the
+#   License.
+#  
+#   The Initial Developer of the Original Code is
+#   Ken Rice <[email protected]>
+#   Portions created by the Initial Developer are Copyright (C)
+#   the Initial Developer. All Rights Reserved.
+#  
+#   Contributor(s):
+#   
+#   Ken Rice <[email protected]>
+#  
+#   Also thanks to:
+#   The FreeSWITCH, FusionPBX and PostgreSQL Crews without them, none of this would be possible
+#  
+###############################################
+VERSION="0.3"
+
+cat <<EOT
+This Script will install and create base line configs for FreeSWITCH, FusionPBX, Fail2Ban, Monit and PostgreSQL.
+It is designed to run on a Centos6 Minimal Install. EPEL will also be temporarily Enabled to get a few packages
+not in the main Centos Repositories.
+
+As with anything you will want to review the configs after the installer to make sure they are what you want.
+
+This is Version $VERSION of this script.
+
+EOT
+
+read -r -p "Are you sure? [Y/n] " response
+if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
+then
+    echo "Here we go..."
+else
+    echo "Aborting"
+    exit
+fi
+
+
+
+###############
+
+#dz  Install SNMP to support mod_snmp
+#dz  net-snmp-devel necessary to install net-snmp-config script
+yum -y install net-snmp net-snmp-utils net-snmp-devel
+
+mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.old 
+
+#Create a new config file.
+
+#Add Settings to freeswitch sysconfig filed
+cat >> /etc/snmp/snmpd.conf <<EOT
+rocommunity  public
+syslocation  "Helia Technologies"
+syscontact  [email protected]
+master agentx
+agentXPerms     0755 0755 freeswitch freeswitch
+EOT
+
+#Start the snmpd service
+
+/etc/init.d/snmpd start
+
+# snmpwalk -v 1 -c public -O e 127.0.0.1
+
+
+chkconfig snmpd on
+
+#################
+
+# dz move to directory that is more open so that when we su, its not restricted.
+cd /usr/local/src
+mkdir fusionpbxinstall
+cd fusionpbxinstall
+
+
+# dz add the postgresql 9.1 repository so it can be installed via yum
+wget http://yum.pgrpms.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm
+rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
+
+# Do a Yum Update to update the system and then install all other required modules 
+yum update -y
+yum -y install autoconf automake gcc-c++ git-core libjpeg-devel libtool make ncurses-devel pkgconfig unixODBC-devel openssl-devel gnutls-devel libogg-devel libvorbis-devel curl-devel libtiff-devel libjpeg-devel python-devel expat-devel zlib zlib-devel bzip2 which postgresql91-devel postgresql91-odbc postgresql91-server subversion screen vim php* ntp
+
+
+# dz Install unixodbc so we can switch from the default sqllite db to postgresql for Freeswitch
+yum -y install unixODBC-devel postgresql-odbc
+
+# dz this has not been tested.
+cat >> /etc/odbc.ini << EOT
+[freeswitch]
+; WARNING: The old psql odbc driver psqlodbc.so is now renamed psqlodbcw.so
+; in version 08.x. Note that the library can also be installed under an other
+; path than /usr/local/lib/ following your installation.
+Driver		= /usr/lib/psqlodbcw.so
+Description=Connection to LDAP/POSTGRESQL
+Servername=127.0.0.1
+Port=5432
+;Protocol=6.4  #dz does this need to be 9.1 for postgresql 9.1?
+FetchBufferSize=99
+Username=freeswitch
+;Password=password
+Database=freeswitch 
+ReadOnly=no
+Debug=1
+CommLog=1
+
+[fusionpbx]
+Driver		= /usr/lib/psqlodbcw.so
+Description=Connection to FusionPBX used for mod_CDR
+Servername=127.0.0.1
+Port=5432
+;Protocol=6.4  #dz does this need to be 9.1 for postgresql 9.1?
+FetchBufferSize=99
+Username=fusionpbx
+;Password=password
+Database=fusionpbx 
+ReadOnly=no
+Debug=1
+CommLog=1
+EOT
+
+
+#users for Postgres are added after Postgres is started
+
+#lets get the Time Right
+ntpdate pool.ntp.org
+service ntpd start
+chkconfig ntpd on
+
+#Disable SELinux (Ken hates this thing)
+if [ -x /usr/sbin/setenforce ]
+	then
+		/usr/sbin/setenforce 0
+		/bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/sysconfig/selinux
+#dz it seems both these files exist on Centos 6.2 but this next on actually controls selinux
+        /bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/selinux/config
+fi
+
+# Lets go Get the FreeSWITCH Source and install it
+cd /usr/src
+git clone git://git.freeswitch.org/freeswitch.git
+cd freeswitch
+./bootstrap.sh -j
+
+#dz modify the /usr/src/freeswitch/modules.conf file here  dz120308
+/bin/sed -i -e s,'#applications/mod_callcenter','applications/mod_callcenter', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#endpoints/mod_rtmp','endpoints/mod_rtmp', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#endpoints/mod_dingaling','endpoints/mod_dingaling', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#applications/mod_lcr','applications/mod_lcr', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#applications/mod_blacklist','applications/mod_blacklist', /usr/src/freeswitch/modules.conf
+#dz mod_cidlookup requires additional configuration which is not yet in this script
+/bin/sed -i -e s,'#applications/mod_cidlookup','applications/mod_cidlookup', /usr/src/freeswitch/modules.conf
+#/bin/sed -i -e s,'#asr_tts/mod_pocketsphinx','asr_tts/mod_pocketsphinx', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#applications/mod_voicemail_ivr','applications/mod_voicemail_ivr', /usr/src/freeswitch/modules.conf
+
+#dz mod_snmp is building with errors.  Will need to resolve first.  Currently this causes sophia not to build
+/bin/sed -i -e s,'#event_handlers/mod_snmp','event_handlers/mod_snmp', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#formats/mod_shout','formats/mod_shout', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#asr_tts/mod_tts_commandline','asr_tts/mod_tts_commandline', /usr/src/freeswitch/modules.conf
+/bin/sed -i -e s,'#asr_tts/mod_flite','asr_ttsmod_flite', /usr/src/freeswitch/modules.conf
+
+./configure --without-libcurl -C
+make -j `cat /proc/cpuinfo |grep processor |wc -l`
+make install
+make cd-moh-install && make cd-sounds-install
+#add a user for freeswitch
+useradd freeswitch
+
+#set ownership, perms, and install init scripts 
+cd /usr/local/
+chown -R freeswitch:freeswitch freeswitch
+chmod -R g+w freeswitch
+cd /usr/src/freeswitch/build
+cp freeswitch.init.redhat /etc/init.d/freeswitch
+chmod +x /etc/init.d/freeswitch 
+cp freeswitch.sysconfig /etc/sysconfig/freeswitch
+
+#Add Settings to freeswitch sysconfig filed
+cat >> /etc/sysconfig/freeswitch <<EOT
+PID_FILE=/var/run/freeswitch/freeswitch.pid
+FS_USER=freeswitch
+FS_FILE=/usr/local/freeswitch/bin/freeswitch
+FS_HOME=/usr/local/freeswitch
+EOT
+
+
+
+#configure mod_cidlookup
+#dz need to install UnixODBC first
+# see http://wiki.freeswitch.org/wiki/Using_ODBC_in_the_core
+
+mv /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml.bak
+cat >> /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml <<EOT
+<configuration name="cidlookup.conf" description="cidlookup Configuration">
+<settings>
+<param name="cache" value="true"/>
+<param name="cache-expire" value="86400"/>
+<param name="odbc-dsn" value="fusionpbx:fusionpbx:"/>
+<param name="sql" value="
+SELECT  p.contact_name_family ||', '|| p.contact_name_given as name
+FROM v_contact_phones n INNER JOIN v_contacts p ON n.contact_uuid = p.contact_uuid
+WHERE n.phone_number = '${caller_id_number}'
+LIMIT 1
+"/>
+</settings>
+</configuration>
+EOT
+
+chown  apache:apache /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml 
+
+#dz 20120401  Change Freeswitch core to use Postgres
+/bin/sed -i -e s,'<!-- <param name="core-db-dsn" value="dsn:username:password" /> -->','<param name="core-db-dsn" value="freeswitch:freeswitch:" />', /usr/local/freeswitch/conf/autoload_configs/switch.conf.xml
+
+
+#dz Change Sofia to use Postgres
+/bin/sed -i -e s,'<!--<param name="odbc-dsn" value="dsn:user:pass"/>-->','<param name="odbc-dsn" value="freeswitch:freeswitch:"/>','/usr/local/freeswitch/conf/sip_profiles/internal.xml'
+/bin/sed -i -e s,'</settings>','<param name="odbc-dsn" value="freeswitch:freeswitch:"/></settings>','/usr/local/freeswitch/conf/sip_profiles/external.xml'
+
+#dz Use Postgres for voicemail
+/bin/sed -i -e s,'<!--<param name="odbc-dsn" value="dsn:user:pass"/>-->','<param name="odbc-dsn" value="freeswitch:freeswitch:"/>','/usr/local/freeswitch/conf/autoload_configs/voicemail.conf.xml'
+
+      
+
+
+
+# sym link fs_cli into /usr/local/bin so we don't have to adjust paths
+cd /usr/local/bin/
+ln -s /usr/local/freeswitch/bin/fs_cli fs_cli
+
+#start installing FusionPBX From Subversion
+#cd /var/www
+#svn co http://fusionpbx.googlecode.com/svn/trunk/fusionpbx html
+
+cd /var/www/html
+
+mkdir fusionpbx
+svn co http://fusionpbx.googlecode.com/svn/trunk/fusionpbx fusionpbx
+
+#Add a redirect so the default doc at the web root goes to the fusionpbx login.
+cat > /var/www/html/index.php <<EOT
+<?php header( 'Location: /fusionpbx/index.php' ) ;?>
+EOT
+
+#fix FusionPBX Ownership and Perms
+#chown -R apache:apache html
+chown -R apache:apache fusionpbx
+
+cd /usr/local/freeswitch/conf/
+chmod 770 `find . -type d`
+chmod 660 `find . -type f`
+
+# add apache to the freeswitch Group
+# usermod -a -G freeswitch apache  # dz20120415  apache is always public and should not have access to core pbx files 
+usermod -a -G apache freeswitch  # Add freeswitch to the apache group.  Fusionpbx files that are modified or inserted are in the apache group
+
+## Install EPEL so we can get monit and ngrep 
+rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
+
+#Install Monit, Fail2Ban, and ngrep 
+yum install -y monit ngrep fail2ban
+
+#Drop monit configs in the right spot
+cat > /etc/monit.d/freeswitch <<EOT
+ check process freeswitch with pidfile /usr/local/freeswitch/run/freeswitch.pid
+   group voice
+   start program = "/etc/init.d/freeswitch start"
+   stop  program = "/etc/init.d/freeswitch stop"
+   if failed port 5060 type UDP then restart
+   if 5 restarts within 5 cycles then timeout
+   depends on freeswitch_bin
+   depends on freeswitch_rc
+
+ check file freeswitch_bin with path /usr/local/freeswitch/bin/freeswitch
+   group voice
+   if failed checksum then unmonitor
+   if failed permission 755 then unmonitor
+   if failed uid freeswitch then unmonitor
+
+ check file freeswitch_rc with path /etc/init.d/freeswitch
+   group voice
+   if failed checksum then unmonitor
+   if failed permission 755 then unmonitor
+   if failed uid root then unmonitor
+   if failed gid root then unmonitor
+
+EOT
+
+#Add Fail2Ban configs for 
+echo > /etc/fail2ban/filter.d/freeswitch.conf << EOT
+# Fail2Ban configuration file
+#
+# Author: Rupa SChomaker
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\S+\' for \[.*\] from ip <HOST>
+            \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\S+\' for \[.*\] from ip <HOST>
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+EOT
+
+echo >> /etc/fail2ban/jail.conf << EOT
+[freeswitch-tcp]
+
+enabled  = true
+port     = 5060,5061,5080,5081
+protocol = tcp
+filter   = freeswitch
+logpath  = /usr/local/freeswitch/log/freeswitch.log
+action   = iptables-allports[name=freeswitch-tcp, protocol=all]
+           sendmail-whois[name=FreeSwitch, dest=root, [email protected]]
+
+[freeswitch-udp]
+
+enabled  = true
+port     = 5060,5061,5080,5081
+protocol = udp
+filter   = freeswitch
+logpath  = /usr/local/freeswitch/log/freeswitch.log
+action   = iptables-allports[name=freeswitch-udp, protocol=all]
+           sendmail-whois[name=FreeSwitch, dest=root, [email protected]]
+EOT
+
+echo > /etc/fail2ban/filter.d/fusionpbx.conf << EOT
+# Fail2Ban configuration file
+#
+# Author: soapee01
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+#failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
+#[hostname] variable doesn't seem to work in every case. Do this instead:
+failregex = .* FusionPBX: \[<HOST>\] authentication failed for
+          = .* FusionPBX: \[<HOST>\] provision attempt bad password for
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+EOT
+
+echo >> /etc/fail2ban/jail.conf << EOT
+[fusionpbx]
+
+enabled  = true
+port     = 80,443
+protocol = tcp
+filter   = fusionpbx
+logpath  = /var/log/messages
+action   = iptables-allports[name=fusionpbx, protocol=all]
+           sendmail-whois[name=FusionPBX, dest=root, [email protected]] 
+
+EOT
+
+
+# INIT Postgresql, and set it for easyness
+#quick hack to postgresql init script to init the DB with trust access **** YOU MAY NOT WANT THIS FOR PRODUCTION ****
+ /bin/sed -i -e s,'ident','trust', /etc/init.d/postgresql-9.1
+service postgresql-9.1 initdb
+chkconfig postgresql-9.1 on
+service postgresql-9.1 start
+
+#set this back to normal
+/bin/sed -i -e s,'trust','ident', /etc/init.d/postgresql-9.1
+service postgresql-9.1 restart
+
+#create users for core Freeswitch
+cd /var/tmp
+sudo -u postgres createuser -s -e freeswitch
+sudo -u postgres createdb -E UTF8 -O freeswitch freeswitch
+
+# dz create a fusionpbx user and a fusionpbx database.
+cd /var/tmp
+sudo -u postgres createuser -s -e fusionpbx
+sudo -u postgres createdb -E UTF8 -O fusionpbx fusionpbx
+
+
+# start up some services and set them to run at boot
+service freeswitch start
+service httpd restart
+chkconfig freeswitch on
+chkconfig httpd on
+service monit start
+chkconfig monit on
+
+
+#disable epel repo for normal use. Leaving it enabled canhave unintended consequences
+/bin/sed -i -e s,'enabled=1','enabled=0', /etc/yum.repos.d/epel.repo
+
+#Make the Prompt Pretty and add a few aliases that come in handy
+cat >>~/.bashrc <<EOT
+export LESSCHARSET="latin1"
+export LESS="-R"
+export CHARSET="ISO-8859-1"
+export PS1='\n\[\033[01;31m\]\u@\h\[\033[01;36m\] [\d \@] \[\033[01;33m\] \w\n\[\033[00m\]<\#>:'
+export PS2="\[\033[1m\]> \[\033[0m\]"
+export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
+export VISUAL=vim
+
+umask 022
+alias vi='vim'
+alias fstop='top -p \`cat /usr/local/freeswitch/run/freeswitch.pid\`'
+alias fsgdb='gdb /usr/local/freeswitch/bin/freeswitch \`cat /usr/local/freeswitch/run/freeswitch.pid\`'
+alias fscore='gdb /usr/local/freeswitch/bin/freeswitch \`ls -rt core.* | tail -n1\`'
+EOT
+
+#Add a screenrc with a status line, a big scroll back and ^\ as the metakey as to not screw with emacs users
+cat >> ~/.screenrc <<EOT
+hardstatus alwaysignore
+startup_message off
+escape ^\b
+defscrollback 8000
+
+# status line at the bottom
+hardstatus on
+hardstatus alwayslastline
+hardstatus string "%{.bW}%-w%{.rW}%f%n %t%{-}%+w %=%{..G}[%H %l] %{..Y} %m/%d %c "
+
+termcapinfo xterm \'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l\'
+EOT
+
+
+# and finally lets fix up IPTables so things works correctly
+
+#Block 'friendly-scanner' AKA sipvicious
+iptables -I INPUT -p udp --dport 5060 -m string --string "friendly-scanner" --algo bm -j DROP
+iptables -I INPUT -p udp --dport 5080 -m string --string "friendly-scanner" --algo bm -j DROP
+
+#rate limit registrations to keep us from getting hammered on
+iptables -I INPUT -m string --string "REGISTER sip:" --algo bm --to 65 -m hashlimit --hashlimit 4/minute --hashlimit-burst 1 --hashlimit-mode srcip,dstport --hashlimit-name sip_r_limit -j ACCEPT
+
+# FreeSwitch ports internal SIP profile
+iptables -I INPUT -p udp -m udp --dport 5060 -j ACCEPT
+iptables -I INPUT -p tcp -m tcp --dport 5060 -j ACCEPT
+
+# FreeSwitch Ports external SIP profile
+iptables -I INPUT -p udp -m udp --dport 5080 -j ACCEPT
+iptables -I INPUT -p tcp -m tcp --dport 5080 -j ACCEPT
+
+# RTP Traffic 16384-32768
+iptables -I INPUT -p udp -m udp --dport 16384:32768 -j ACCEPT
+
+# Ports for the Web GUI
+iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
+iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
+
+# Ports for SNMP
+iptables -I INPUT -p udp -m udp --dport 161 -j ACCEPT
+iptables -I INPUT -p udp -m udp --dport 162 -j ACCEPT
+
+#save the IPTables rules for later
+service iptables save
+
+
+
+
+
+
+
+LOCAL_IP=`ifconfig eth0 | head -n2 | tail -n1 | cut -d' ' -f12 | cut -c 6-`
+
+cat <<EOT
+As long as you didnt see errors by this point, PostgreSQL, FreeSWITCH, FusionPBX, Fail2Ban, and Monit should be installed.
+Point your browser to http://$LOCAL_IP/ and let the FusionPBX installer take it from there.
+
+EOT

+ 2680 - 0
install/ubuntu/install_fusionpbx.sh

@@ -0,0 +1,2680 @@
+#!/bin/bash
+
+# install_fusionpbx
+
+LICENSE=$( cat << DELIM
+#------------------------------------------------------------------------------
+#
+# "THE WAF LICENSE" (version 1)
+# This is the Wife Acceptance Factor (WAF) License.  
+# jamesdotfsatstubbornrosesd0tcom  wrote this file.  As long as you retain this
+# notice you can do whatever you want with it. If you appreciate the work,
+# please consider purchasing something from my wife's wishlist. That pays
+# bigger dividends to this coder than anything else I can think of ;).  It also
+# keeps her happy while she's being ignored; so I can work on this stuff.
+#   James Rose
+#
+# latest wishlist: http://www.stubbornroses.com/waf.html
+#
+# Credit: Based off of the BEER-WARE LICENSE (REVISION 42) by Poul-Henning Kamp
+#
+#------------------------------------------------------------------------------
+DELIM
+)
+
+#---------
+#VARIABLES
+#---------
+#Variables are for the auto installation option.
+
+#for apache set to a, for nginx/php-fpm set to n -> for an auto install, user mode will prompt
+APACHENGINX=n
+
+# for mysql set m. for sqlite set s. for postgresql set p
+SQLITEMYSQL=s
+
+# for postgresql v 9.0 (from ppa) set to 9, otherwise stick with 8
+# must set SQLITEMYSQL to p
+POSTGRES9=8
+
+# to start FreeSWITCH with -nonat option set SETNONAT to y
+SETNONAT=n
+
+# rm -Rf /opt? A default install doesn't have /opt so no worries
+# if you do, set to no, and it will link /usr/local/freeswitch to /opt/freeswitch
+#REMOVED OPTION
+#RMOPT=y
+
+# use freedtm/dahdi? y/n
+DO_DAHDI=n
+
+# default distro
+DISTRO=precise
+
+#below is a list of modules we want to add to provide functionality for FusionPBX
+#don't worry about the applications/mod_ format.  This script will find that in modules.conf
+#PAY ATTENTION TO THE SPACES POST AND PRE PARENTHESIS
+#  mod_shout removed
+if [ $DO_DAHDI == "y" ]; then
+	modules_add=( ../../libs/freetdm/mod_freetdm mod_spandsp mod_dingaling mod_portaudio mod_callcenter mod_lcr mod_cidlookup mod_directory mod_flite mod_pocketsphinx mod_xml_rpc mod_xml_cdr mod_xml_curl mod_say_es )
+else
+	modules_add=( mod_spandsp mod_dingaling mod_portaudio mod_callcenter mod_lcr mod_cidlookup mod_directory mod_flite mod_pocketsphinx mod_xml_rpc mod_xml_cdr mod_xml_curl mod_say_es )
+fi
+
+#-------
+#DEFINES
+#-------
+VERSION="Version - using subversion, no longer keeping track. WAF License"
+# Modules_comp_default determined using
+#  grep -v ^$ /usr/src/freeswitch/modules.conf |grep -v ^# | tr '\n' ' '
+#  on FreeSWITCH version FreeSWITCH Version 1.0.head (git-8f2ee97 2010-12-05 17-19-28 -0600)
+#modules_comp_default=( loggers/mod_console loggers/mod_logfile loggers/mod_syslog applications/mod_commands applications/mod_conference applications/mod_dptools applications/mod_enum applications/mod_fifo applications/mod_db applications/mod_hash applications/mod_voicemail applications/mod_expr applications/mod_esf applications/mod_fsv applications/mod_spandsp applications/mod_cluechoo applications/mod_valet_parking codecs/mod_g723_1 codecs/mod_amr codecs/mod_g729 codecs/mod_h26x codecs/mod_bv codecs/mod_ilbc codecs/mod_speex codecs/mod_siren dialplans/mod_dialplan_xml dialplans/mod_dialplan_asterisk endpoints/mod_sofia endpoints/mod_loopback event_handlers/mod_event_socket event_handlers/mod_cdr_csv formats/mod_native_file formats/mod_sndfile formats/mod_local_stream formats/mod_tone_stream formats/mod_file_string languages/mod_spidermonkey languages/mod_lua say/mod_say_en say/mod_say_ru )
+#making dynamic
+#MOVING: Needs to happen after bootstrap...
+#modules_comp_default=( `/bin/grep -v ^$ /usr/src/freeswitch/modules.conf |/bin/grep -v ^# | /usr/bin/tr '\n' ' '` )
+
+#staying with default repository, feel free to change this to github. Some report faster downloads.
+FSGIT=git://git.freeswitch.org/freeswitch.git
+#FSGIT=git://github.com/FreeSWITCH/FreeSWITCH.git
+
+#right now, make -j not working. see: jira FS-3005
+#CORES=$(/bin/grep processor -c /proc/cpuinfo)
+CORES=1
+FQDN=$(hostname -f)
+#SRCPATH="/usr/src/freeswitch" #DEFAULT
+SRCPATH="/usr/src/freeswitch"
+#EN_PATH="/usr/local/freeswitch/conf/autoload_configs" #DEFAULT
+EN_PATH="/usr/local/freeswitch/conf/autoload_configs"
+WWW_PATH="/var/www"
+GUI_NAME=fusionpbx
+INST_FPBX=svn
+#INST_FPBX=tgz
+#full path required
+#TGZ_FILE="/home/coltpbx/fusionpbx-1.2.1.tar.gz"
+FSREV="187abe02af4d64cdedc598bd3dfb1cd3ed0f4a91"
+FSCHECKOUTVER=false
+FPBXREV="1876"
+FBPXCHECKOUTVER=false
+URLSCRIPT="http://fusionpbx.googlecode.com/svn/trunk/scripts/install/ubuntu/install_fusionpbx.sh"
+INSFUSION=0
+INSFREESWITCH=0
+UPGFUSION=0
+UPGFREESWITCH=0
+
+#---------
+#  NOTES
+#---------
+# This Script installs or upgrades FreeSWITCH and FusionPBX on a fresh install of 
+# Ubuntu 10.04 LTS [lucid].  It tries to edit all appropriate files, and
+# set the permissions correctly.
+
+#When you install ubuntu, you should select the "Manual package selection" option.  
+#This way we can keep the install to the bare minimum.  This script will install
+#everything you need (and nothing) - hopefully, you don't. Just quit tasksel
+
+#---------
+#FUNCTIONS
+#---------
+function nginxconfig {
+	apt-get install -y ssl-cert
+	ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
+	ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
+	ln -s /etc/ssl/certs/nginx.crt $WWW_PATH/$GUI_NAME/$HOSTNAME.crt
+	
+	#don't forget to escape 'DELIM'. otherwise the $fastcgi part
+	#gets escaped.
+	#manually escaping now. needs variables....
+	/bin/cat > /etc/nginx/sites-available/$GUI_NAME  <<DELIM
+server{
+        listen 127.0.0.1:80;
+        server_name 127.0.0.1;
+        access_log /var/log/nginx/access.log;
+        error_log /var/log/nginx/error.log;
+
+        client_max_body_size 10M;
+        client_body_buffer_size 128k;
+
+
+        location / {
+          root $WWW_PATH/$GUI_NAME;
+          index index.php;
+        }
+
+        location ~ \.php$ {
+            fastcgi_pass 127.0.0.1:9000;
+            fastcgi_index index.php;
+            include fastcgi_params;
+            fastcgi_param   SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
+        }
+
+        # Disable viewing .htaccess & .htpassword & .db
+        location ~ .htaccess {
+                deny all;
+        }
+        location ~ .htpassword {
+                deny all;
+        }
+        location ~^.+.(db)$ {
+                deny all;
+        }
+}
+
+server{
+        listen 80;
+        server_name $GUI_NAME;
+        if (\$uri !~* ^.*provision.*$) {
+                rewrite ^(.*) https://\$host\$1 permanent;
+                break;
+        }
+        access_log /var/log/nginx/access.log;
+        error_log /var/log/nginx/.error.log;
+
+        client_max_body_size 10M;
+        client_body_buffer_size 128k;
+
+
+        location / {
+          root $WWW_PATH/$GUI_NAME;
+          index index.php;
+        }
+
+        location ~ \.php$ {
+            fastcgi_pass 127.0.0.1:9000;
+            fastcgi_index index.php;
+            include fastcgi_params;
+            fastcgi_param   SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
+        }
+
+        # Disable viewing .htaccess & .htpassword & .db
+        location ~ .htaccess {
+                deny all;
+        }
+        location ~ .htpassword {
+                deny all;
+        }
+        location ~^.+.(db)$ {
+                deny all;
+        }
+}
+
+server{
+        listen 443;
+        server_name $GUI_NAME;
+        ssl                     on;
+        ssl_certificate         /etc/ssl/certs/nginx.crt;
+        ssl_certificate_key     /etc/ssl/private/nginx.key;
+        ssl_protocols           SSLv3 TLSv1;
+        ssl_ciphers     HIGH:!ADH:!MD5;
+
+        access_log /var/log/nginx/access.log;
+        error_log /var/log/nginx/.error.log;
+
+        client_max_body_size 10M;
+        client_body_buffer_size 128k;
+
+
+        location / {
+          root $WWW_PATH/$GUI_NAME;
+          index index.php;
+        }
+
+        location ~ \.php$ {
+            fastcgi_pass 127.0.0.1:9000;
+            fastcgi_index index.php;
+            include fastcgi_params;
+            fastcgi_param   SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
+        }
+
+        # Disable viewing .htaccess & .htpassword & .db
+        location ~ .htaccess {
+                deny all;
+        }
+        location ~ .htpassword {
+                deny all;
+        }
+        location ~^.+.(db)$ {
+                deny all;
+        }
+}
+DELIM
+		/bin/ln -s /etc/nginx/sites-available/$GUI_NAME /etc/nginx/sites-enabled/$GUI_NAME
+		
+		/bin/echo "document root for nginx is:"
+		/bin/echo "  $WWW_PATH/$GUI_NAME"
+		/bin/echo "  php has an upload file size limit of 10 MegaBytes"
+		/bin/echo
+		/bin/echo "now install FusionPBX. This should go fast."
+		/bin/echo
+	
+		#nginx install doesn't create /var/www
+		/bin/mkdir $WWW_PATH
+		/bin/chown -R www-data:www-data $WWW_PATH
+		/bin/chmod -R 775 $WWW_PATH
+	
+	/etc/init.d/php5-fpm
+	/etc/init.d/nginx restart
+}
+
+
+function fusionfail2ban {
+
+/bin/cat > /etc/fail2ban/filter.d/$GUI_NAME.conf  <<'DELIM'
+# Fail2Ban configuration file
+#
+# Author: soapee01
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+#failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
+#[hostname] variable doesn't seem to work in every case. Do this instead:
+failregex = .* FusionPBX: \[<HOST>\] authentication failed for
+          = .* FusionPBX: \[<HOST>\] provision attempt bad password for
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+DELIM
+
+/bin/grep -i $GUI_NAME /etc/fail2ban/jail.local > /dev/null
+
+if [ $? -eq 0 ]; then
+	/bin/echo "FusionPBX Jail already set"
+else
+	/bin/cat >> /etc/fail2ban/jail.local  <<DELIM
+[$GUI_NAME]
+
+enabled  = true
+port     = 80,443
+protocol = tcp
+filter   = $GUI_NAME
+logpath  = /var/log/auth.log
+action   = iptables-allports[name=$GUI_NAME, protocol=all]
+#          sendmail-whois[name=$GUI_NAME, dest=root, [email protected]] #no smtp server installed
+maxretry = 5
+findtime = 600
+bantime  = 600	
+DELIM
+fi
+}
+
+function www_permissions {
+	#consider not stopping here... it's causing some significant delays, or just pause until it starts back up...
+	#/etc/init.d/freeswitch stop
+	/usr/sbin/adduser www-data audio
+	/usr/sbin/adduser www-data dialout
+	/bin/echo "setting FreeSWITCH owned by www-dat.www-data"
+	/bin/chown -R www-data.www-data /usr/local/freeswitch
+	#remove 'other' permissions on freeswitch
+	/bin/chmod -R o-rwx /usr/local/freeswitch/
+	#set FreeSWITCH directories full permissions for user/group with group sticky
+	/bin/echo "Setting group ID sticky for FreeSWITCH"
+	/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
+	#make sure FreeSWITCH directories have group write
+	/bin/echo "Setting Group Write for FreeSWITCH files"
+	/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
+	#make sure FreeSWITCH files have group write
+	/bin/echo "Setting Group Write for FreeSWITCH directories"
+	/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
+	/bin/echo "setting FusionPBX owned by www-data.www-data just in case"
+	if [ -e /var/www/fusionpbx ]; then
+		/bin/chown -R www-data.www-data /var/www/fusionpbx
+	fi
+	/bin/echo "Changing /etc/init.d/freeswitch to start with user www-data"	
+	/bin/sed -i -e s,'USER=freeswitch','USER=www-data', /etc/init.d/freeswitch
+	#/etc/init.d/freeswitch start
+}
+
+function finish_fpbx_install_permissions {
+	/bin/echo
+	/bin/echo "The FusionPBX installation changed permissions of /usr/local/freeswitch/storage"
+	/bin/echo "  Waiting on you to finish installation (via browser), I'll clean up"
+	/bin/echo -ne "  the last bit of permissions when you finish."
+	/bin/echo "Waiting on $WWW_PATH/$GUI_NAME/includes/config.php"
+	while [ ! -e $WWW_PATH/$GUI_NAME/includes/config.php ]
+	do
+		/bin/echo -ne '.'
+		sleep 1
+	done
+	/bin/echo
+	/bin/echo "$WWW_PATH/$GUI_NAME/includes/config.php Found!"
+	/bin/echo "   Waiting 5 more seconds to be sure. "
+	SLEEPTIME=0
+	while [ "$SLEEPTIME" -lt 5 ]
+	do
+		/bin/echo -ne '.'
+		sleep 1
+		let "SLEEPTIME = $SLEEPTIME + 1"
+	done
+	
+	/bin/echo "   Fixing..."
+	/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
+	/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
+	/bin/echo "   FIXED"
+}
+
+function build_modules {
+	#bandaid
+	sed -i -e "s/applications\/mod_voicemail_ivr/#applications\/mod_voicemail_ivr/" $SRCPATH/modules.conf
+	#------------
+	#  new way v2
+	#------------
+	#find the default modules - redundant really...
+	modules_comp_default=( `/bin/grep -v ^$ /usr/src/freeswitch/modules.conf |/bin/grep -v ^# | /usr/bin/tr '\n' ' '` )
+	#add the directory prefixes to the modules in array so the modules we wish to add will compile
+	module_count=`echo ${#modules_add[@]}`
+	index=0
+	while [ "$index" -lt "$module_count" ]
+	do
+			modules_compile_add[$index]=`/bin/grep ${modules_add[$index]} $SRCPATH/modules.conf | sed -e "s/#//g"`
+			let "index = $index + 1"
+	done
+
+	modules_compile=( ${modules_comp_default[*]} ${modules_compile_add[*]} )
+
+
+	#BUILD MODULES.CONF for COMPILER
+	echo
+	echo
+	echo "Now enabling modules for compile in $SRCPATH/modules.conf"
+	index=0
+	module_count=`echo ${#modules_compile[@]}`
+	#get rid of funky spacing in modules.conf
+	/bin/sed -i -e "s/ *//g" $SRCPATH/modules.conf
+	while [ "$index" -lt "$module_count" ]
+	do
+			grep ${modules_compile[$index]} $SRCPATH/modules.conf > /dev/null
+			if [ $? -eq 0 ]; then
+					#module is present in file. see if we need to enable it
+					grep '#'${modules_compile[$index]} $SRCPATH/modules.conf > /dev/null
+					if [ $? -eq 0 ]; then
+							/bin/sed -i -e s,'#'${modules_compile[$index]},${modules_compile[$index]}, $SRCPATH/modules.conf
+							/bin/echo "     [ENABLED] ${modules_compile[$index]}"
+					else
+							/bin/echo "     ${modules_compile[$index]} ALREADY ENABLED!"
+					fi
+
+			else
+					#module is not present. Add to end of file
+					#/bin/echo "did not find ${modules_compile[$index]}"
+					/bin/echo ${modules_compile[$index]} >> $SRCPATH/modules.conf
+					/bin/echo "     [ADDED] ${modules_compile[$index]}"
+			fi
+	
+			let "index = $index + 1"
+	done
+	#--------------
+	#end new way v2
+	#--------------
+}
+
+function enable_modules {
+	#------------
+	#  new way v2
+	#------------
+	#ENABLE MODULES for FreeSWITCH
+	#
+	echo
+	echo
+	echo "Now enabling modules for FreeSWITCH in $EN_PATH/modules.conf.xml"
+	index=0
+	module_count=`echo ${#modules_add[@]}`
+	#get rid of any funky whitespace
+	/bin/sed -i -e s,'<!-- *<','<!--<', -e s,'> *-->','>-->', $EN_PATH/modules.conf.xml
+	while [ "$index" -lt "$module_count" ]
+	do
+		#more strangness to take care of, example:
+		#Now enabling modules for FreeSWITCH in /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
+		#[ADDED] ../../libs/freetdm/mod_freetdm
+		modules_add[$index]=`/bin/echo ${modules_add[$index]} | /bin/sed -e 's/.*mod_/mod_/'`
+		grep ${modules_add[$index]} $EN_PATH/modules.conf.xml > /dev/null
+		if [ $? -eq 0 ]; then
+			#module is present in file, see if we need to enable it.
+			grep  '<!--<load module="'${modules_add[$index]}'"/>-->' $EN_PATH/modules.conf.xml > /dev/null
+			if [ $? -eq 0 ]; then
+				#/bin/echo "found ${modules_compile[$index]}"
+				/bin/sed -i -e s,'<!--<load module="'${modules_add[$index]}'"/>-->','<load module="'${modules_add[$index]}'"/>', \
+				  $EN_PATH/modules.conf.xml
+				/bin/echo "     [ENABLED] ${modules_add[$index]}"
+			else
+				/bin/echo "     ${modules_add[$index]} ALREADY ENABLED!"
+			fi
+        else
+			#not in file. we need to add, and will do so below <modules> tag at top of file
+			/bin/sed -i -e s,'<modules>','&\n <load module="'${modules_add[$index]}'"/>',  $EN_PATH/modules.conf.xml
+			/bin/echo "     [ADDED] ${modules_add[$index]}"
+		fi
+
+		let "index = $index + 1"
+	done
+	
+	#--------------
+	#end new way v2
+	#--------------
+}
+
+function freeswitch_logfiles {
+	/bin/echo
+	/bin/echo "logrotate not happy with FS: see http://wiki.fusionpbx.com/index.php?title=RotateFSLogs doing differently now..."
+	/bin/echo "       SEE: /etc/cron.daily/freeswitch_log_rotation"
+	/bin/cat > /etc/cron.daily/freeswitch_log_rotation <<'DELIM'
+#!/bin/bash
+# logrotate replacement script
+# put in /etc/cron.daily
+# don't forget to make it executable
+# you might consider changing /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml
+#  <param name="rollover" value="0"/>
+
+#number of days of logs to keep
+NUMBERDAYS=30
+FSPATH="/usr/local/freeswitch"
+
+$FSPATH/bin/fs_cli -x "fsctl send_sighup" |grep '+OK' >/tmp/rotateFSlogs
+if [ $? -eq 0 ]; then
+       #-cmin 2 could bite us (leave some files uncompressed, eg 11M auto-rotate). Maybe -1440 is better?
+       find $FSPATH/log/ -name "freeswitch.log.*" -cmin -2 -exec gzip {} \;
+       find $FSPATH/log/ -name "freeswitch.log.*.gz" -mtime +$NUMBERDAYS -exec /bin/rm {} \;
+       chown www-data.www-data $FSPATH/log/freeswitch.log
+       chmod 660 $FSPATH/log/freeswitch.log
+       logger FreeSWITCH Logs rotated
+       /bin/rm /tmp/rotateFSlogs
+else
+       logger FreeSWITCH Log Rotation Script FAILED
+       mail -s '$HOST FS Log Rotate Error' root < /tmp/rotateFSlogs
+       /bin/rm /tmp/rotateFSlogs
+fi
+DELIM
+
+	/bin/chmod 755 /etc/cron.daily/freeswitch_log_rotation
+	
+	/bin/echo "Now dropping 10MB limit from FreeSWITCH"
+	/bin/echo "  This is so the rotation/compression part of the cron script"
+	/bin/echo "  will work properly."
+	/bin/echo "  SEE: /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml"
+	
+	# <param name="rollover" value="10485760"/>
+	/bin/sed /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml -i -e s,\<param.*name\=\"rollover\".*value\=\"10485760\".*/\>,\<\!\-\-\<param\ name\=\"rollover\"\ value\=\"10485760\"/\>\ INSTALL_SCRIPT\-\-\>,g
+}
+
+case $1 in
+	fix-https)
+		nginxconfig
+	;;
+	
+	fix-permissions)
+		/etc/init.d/freeswitch stop
+		www_permissions
+		/etc/init.d/freeswitch start
+	;;
+	
+	install-freeswitch)
+		INSFUSION=0
+		INSFREESWITCH=1
+		UPGFUSION=0
+		UPGFREESWITCH=0
+	
+	;;
+	
+	install-fusionpbx)
+		INSFUSION=1
+		INSFREESWITCH=0
+		UPGFUSION=0
+		UPGFREESWITCH=0
+	;;
+	
+	install-both)
+		INSFUSION=1
+		INSFREESWITCH=1
+		UPGFUSION=0
+		UPGFREESWITCH=0
+	;;
+	
+	upgrade-fusionpbx)
+		INSFUSION=0
+		INSFREESWITCH=0
+		UPGFUSION=1
+		UPGFREESWITCH=0
+	;;
+
+	upgrade-freeswitch)
+		INSFUSION=0
+		INSFREESWITCH=0
+		UPGFUSION=0
+		UPGFREESWITCH=1
+	;;
+	
+	upgrade-both)
+		INSFUSION=0
+		INSFREESWITCH=0
+		UPGFUSION=1
+		UPGFREESWITCH=1
+
+	;;	
+	
+	version)
+		/bin/echo "  "$VERSION
+		/bin/echo
+		/bin/echo "$LICENSE"
+		exit 0
+	;;
+	
+	-v)
+		/bin/echo "  "$VERSION
+		/bin/echo
+		/bin/echo "$LICENSE"
+		exit 0
+	;;
+	
+	--version)
+		/bin/echo "  "$VERSION
+		/bin/echo
+		/bin/echo "$LICENSE"
+		exit 0
+	;;
+	
+	*)
+		/bin/echo
+		/bin/echo "This script should be called as:"
+		/bin/echo "  install_fusionpbx option1 option2"
+		/bin/echo
+		/bin/echo "    option1:"
+		/bin/echo "      install-freeswitch"
+		/bin/echo "      install-fusionpbx"
+		/bin/echo "      install-both"
+		/bin/echo "      upgrade-freeswitch"
+		/bin/echo "      upgrade-fusionpbx"
+		/bin/echo "      fix-https"
+		/bin/echo "      fix-permissions"
+		/bin/echo "      version|--version|-v"
+		/bin/echo
+		/bin/echo "    option2:"
+		/bin/echo "      user: option waits in certain places for the user to check for errors"
+		/bin/echo "            it is interactive and prompts you about what to install"
+		/bin/echo "      auto: tries an automatic install. Get a cup of coffee, this will"
+		/bin/echo "            take a while. FOR THE BRAVE!"
+		/bin/echo 
+		/bin/echo "      EXAMPLE"
+		/bin/echo "         install_fusionpbx install-both user"
+		/bin/echo 
+		exit 0
+	;;
+esac
+
+case $2 in	
+	user)
+		DEBUG=1
+	;;
+	
+	auto)
+		DEBUG=0
+	;;
+	
+		*)
+		/bin/echo
+		/bin/echo "This script should be called as:"
+		/bin/echo "  install_fusionpbx option1 option2"
+		/bin/echo
+		/bin/echo "    option1:"
+		/bin/echo "      install-freeswitch"
+		/bin/echo "      install-fusionpbx"
+		/bin/echo "      install-both"
+		/bin/echo "      upgrade-freeswitch"
+		/bin/echo "      upgrade-fusionpbx"
+		/bin/echo "      fix-https"
+		/bin/echo "      fix-permissions"
+		/bin/echo "      version|--version|-v"
+		/bin/echo
+		/bin/echo "    option2:"
+		/bin/echo "      user: option waits in certain places for the user to check for errors"
+		/bin/echo "            it is interactive and prompts you about what to install"		
+		/bin/echo "      auto: tries an automatic install. Get a cup of coffee, this will"
+		/bin/echo "            take a while. FOR THE BRAVE!"
+		/bin/echo 
+		/bin/echo "      EXAMPLE"
+		/bin/echo "         install_fusionpbx install-both user"
+		/bin/echo 
+		exit 0
+	;;
+esac
+
+
+#---------------------
+#   ENVIRONMENT CHECKS
+#---------------------
+#check for root
+if [ $EUID -ne 0 ]; then
+   /bin/echo "This script must be run as root" 1>&2
+   exit 1
+fi
+echo "Good, you are root."
+
+if [ ! -s /usr/bin/lsb_release ]; then
+	/bin/echo "Tell your upstream distro to include lsb_release"
+	/bin/echo
+	apt-get upgrade && apt-get -y install lsb-release
+fi
+	
+#check for internet connection
+/usr/bin/wget -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
+if [ ! -s /tmp/index.google ];then
+	echo "No Internet connection. Exiting."
+	/bin/rm /tmp/index.google
+	exit 1
+else
+	echo "Internet connection is working, continuing!"
+	/bin/rm /tmp/index.google
+fi
+
+
+#check for 10.04 LTS Lucid
+
+#/bin/grep -i lucid /etc/lsb-release > /dev/null
+lsb_release -c |grep -i lucid > /dev/null
+if [ $? -eq 0 ]; then
+	DISTRO=lucid
+	/bin/echo "Good, you're running Ubuntu 10.04 LTS codename Lucid"
+	/bin/echo
+else
+	lsb_release -c |grep -i squeeze > /dev/null
+	if [ $? -eq 0 ]; then
+		DISTRO=squeeze
+		/bin/echo "OK you're running Debian Squeeze.  This script is known to work"
+		/bin/echo "   with apache/nginx and mysql|sqlite|postgres8 options"
+		/bin/echo "   Please consider providing feedback on repositories for nginx"
+		/bin/echo "   and php-fpm."
+		/bin/echo 
+		CONTINUE=YES
+	fi
+	lsb_release -c |grep -i precise > /dev/null
+	if [ $? -eq 0 ]; then
+		DISTRO=precise
+		/bin/echo "OK you're running Ubuntu 12.04 LTS [precise].  This script is"
+		/bin/echo "   a work in progress.  It is not recommended that you try it"
+		/bin/echo "   at this time."
+		/bin/echo 
+		CONTINUE=YES
+	else
+		/bin/echo "This script was written for Ubuntu 10.04 LTS codename Lucid"
+		/bin/echo
+		/bin/echo "Your OS appears to be:"
+		lsb_release -a
+		read -p "Do you want to continue [y|n]? " CONTINUE
+	
+		case "$CONTINUE" in
+		[yY]*)
+			/bin/echo "Ok, this doesn't always work..,"
+			/bin/echo "  but we'll give it a go."
+		;;
+	
+		*)
+			/bin/echo "Quitting."
+			exit 1
+		;;
+		esac
+	fi
+fi
+
+#Check for new version
+WHEREAMI=$(echo "`pwd`/`basename $0`")
+wget $URLSCRIPT -O /tmp/install_fusionpbx.latest
+CURMD5=$(md5sum "$WHEREAMI" | sed -e "s/\ .*//")
+echo "The md5sum of the current script is: $CURMD5"
+NEWMD5=$(md5sum /tmp/install_fusionpbx.latest | sed -e "s/\ .*//")
+echo "The md5sum of the latest script is: $NEWMD5"
+
+if [[ "$CURMD5" == "$NEWMD5" ]]; then
+	echo "files are the same, continuing"
+else
+	echo "There is a new version of this script."
+	echo "  It is PROBABLY a good idea use the new version"
+	echo "  the new file is saved in /tmp/install_fusionpbx.latest"
+	echo "  to see the difference, run:"
+	echo "  diff -y /tmp/install_fusionpbx.latest $WHEREAMI"
+	read -p "Continue [y/N]? " YESNO
+	case $YESNO in
+		[Yy]*)
+			echo "OK, Continuing"
+			echo "  Deleting newest script in /tmp"
+			rm /tmp/install_fusionpbx.latest
+		;;
+
+		*)
+			echo "OK, Stopping."
+			exit 0
+		;;
+	esac
+fi
+
+
+#----------------------
+#END ENVIRONMENT CHECKS
+#----------------------
+
+#---------------------------------------
+#       INSTALL    FREESWITCH
+#---------------------------------------
+if [ $INSFREESWITCH -eq 1 ]; then
+
+	/bin/echo "Upgrading the system, and adding the necessary dependencies for a FreeSWITCH compile"
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue..."
+	fi
+
+	/usr/bin/apt-get update
+	/usr/bin/apt-get -y upgrade
+	
+	if [ $DISTRO = "precise" ]; then
+		/usr/bin/apt-get -y install ssh vim git-core subversion build-essential \
+		autoconf automake libtool libncurses5 libncurses5-dev libjpeg-dev ssh \
+		screen htop pkg-config bzip2 curl libtiff4-dev ntp \
+		time bison libssl-dev \
+		unixodbc libmyodbc unixodbc-dev libtiff-tools
+	else
+		/usr/bin/apt-get -y install ssh vim git-core subversion build-essential \
+			autoconf automake libtool libncurses5 libncurses5-dev libjpeg62-dev ssh \
+			screen htop pkg-config bzip2 curl libtiff4-dev ntp \
+			time bison libssl-dev \
+			unixodbc libmyodbc unixodbc-dev libtiff-tools
+	fi
+	
+	#added libgnutls-dev libgnutls26 for dingaling...
+	#gnutls no longer required for dingaling (git around oct 17 per mailing list..)
+	# removed libgnutls-dev libgnutls26
+if [ $DO_DAHDI == "y" ]; then
+		#add stuff for free_tdm/dahdi
+		apt-get -y install linux-headers-`uname -r`
+		#add the headers so dahdi can build the modules...
+		apt-get -y install dahdi
+	fi
+
+	LDRUN=0
+	/bin/echo -ne "Waiting on ldconfig to finish so bootstrap will work"
+	while [ $LDRUN -eq 0 ]
+	do
+			echo -ne "."
+			sleep 1
+			/usr/bin/pgrep -f ldconfig > /dev/null
+			LDRUN=$?
+	done
+
+	/bin/echo
+	/bin/echo
+	/bin/echo "ldconfig is finished"
+	/bin/echo
+
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+
+	
+	#------------------------
+	# GIT FREESWITCH
+	#------------------------
+	/bin/grep 'git_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Git Already Done. Skipping"	
+	else
+		cd /usr/src
+		/usr/bin/time /usr/bin/git clone $FSGIT
+		if [ $? -ne 0 ]; then
+			#git had an error
+			/bin/echo "GIT ERROR"
+			exit 1
+		else
+			if [ $FSCHECKOUTVER == true ]; then
+				echo "OK we'll check out FreeSWITCH version $FSREV"
+				cd /usr/src/freeswitch
+				/usr/bin/git checkout $FSREV
+				if [ $? -ne 0 ]; then
+					#git checkout had an error
+					/bin/echo "GIT CHECKOUT ERROR"
+					exit 1
+				fi
+			fi
+			/bin/echo "git_done" >> /tmp/install_fusion_status
+		fi
+		
+	fi
+	
+	if [ -e /usr/src/FreeSWITCH ]; then
+		/bin/ln -s /usr/src/FreeSWITCH /usr/src/freeswitch
+	elif [ -e /usr/src/freeswitch.git ]; then
+		/bin/ln -s /usr/src/freeswitch.git /usr/src/freeswitch
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi	
+
+	#------------------------
+	# BOOTSTRAP FREESWITCH
+	#------------------------
+	/bin/grep 'bootstrap_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Bootstrap already done. skipping"
+	else
+		#might see about -j option to bootstrap.sh
+		/etc/init.d/ssh start
+		cd /usr/src/freeswitch
+		/bin/echo
+		/bin/echo "FreeSWITCH Downloaded"
+		/bin/echo 
+		/bin/echo "Bootstrapping."
+		/bin/echo
+		#next line failed (couldn't find file) not sure why.
+		#it did run fine a second time.  Go figure (really).
+		#ldconfig culprit?
+		if [ $CORES -gt 1 ]; then 
+			/bin/echo "  multicore processor detected. Starting Bootstrap with -j"
+			if [ $DEBUG -eq 1 ]; then
+				/bin/echo
+				read -p "Press Enter to continue (check for errors)"
+			fi
+			/usr/bin/time /usr/src/freeswitch/bootstrap.sh -j
+		else 
+			/bin/echo "  singlecore processor detected. Starting Bootstrap sans -j"
+			if [ $DEBUG -eq 1 ]; then
+				/bin/echo
+				read -p "Press Enter to continue (check for errors)"
+			fi			
+			/usr/bin/time /usr/src/freeswitch/bootstrap.sh
+		fi
+
+		if [ $? -ne 0 ]; then
+			#bootstrap had an error
+			/bin/echo "BOOTSTRAP ERROR"
+			exit 1
+		else
+			/bin/echo "bootstrap_done" >> /tmp/install_fusion_status
+		fi
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+
+	#------------------------
+	# build modules.conf 
+	#------------------------
+	/bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Modules.conf Already edited"	
+	else
+		#file exists and has been edited
+		build_modules
+		#check exit status
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: Failed to enable build modules in modules.conf."
+			exit 1
+		else
+			/bin/echo "build_modules" >> /tmp/install_fusion_status
+		fi
+	fi	
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+
+	#------------------------
+	# CONFIGURE FREESWITCH 
+	#------------------------
+	/bin/grep 'config_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "FreeSWITCH already Configured! Skipping."
+	else
+		/bin/echo
+		/bin/echo -ne "Configuring FreeSWITCH. This will take a while [~15 minutes]"
+		/bin/sleep 1
+		/bin/echo -ne " ."
+		/bin/sleep 1
+		/bin/echo -ne " ."
+		/bin/sleep 1
+		/bin/echo -ne " ."
+		/usr/bin/time /usr/src/freeswitch/configure
+		
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: FreeSWITCH Configure ERROR."
+			exit 1
+		else
+			/bin/echo "config_done" >> /tmp/install_fusion_status
+		fi
+	fi
+		
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+	
+	if [ -a /etc/init.d/freeswitch ]; then
+		/bin/echo " In case of an install where FS exists (iso), stop FS"
+		/etc/init.d/freeswitch stop
+	fi
+
+
+	#------------------------
+	# COMPILE FREESWITCH 
+	#------------------------	
+	/bin/grep 'compile_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "FreeSWITCH already Compiled! Skipping."
+	else
+		#might see about -j cores option to make...
+		
+		/bin/echo
+		/bin/echo -ne "Compiling FreeSWITCH. This might take a LONG while [~30 minutes]"
+		/bin/sleep 1
+		/bin/echo -ne "."
+		/bin/sleep 1
+		/bin/echo -ne "."
+		/bin/sleep 1
+		/bin/echo -ne "."
+	
+		#making sure pwd is correct
+		cd /usr/src/freeswitch
+		if [ $CORES -gt 1 ]; then 
+			/bin/echo "  multicore processor detected. Compiling with -j $CORES"
+			#per anthm compile the freeswitch core first, then the modules.
+			/usr/bin/time /usr/bin/make -j $CORES core
+			/usr/bin/time /usr/bin/make -j $CORES
+		else 
+			/bin/echo "  singlecore processor detected. Starting compile sans -j"
+			/usr/bin/time /usr/bin/make 
+		fi
+		
+	
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: FreeSWITCH Build Failure."
+			exit 1
+		else
+			/bin/echo "compile_done" >> /tmp/install_fusion_status
+		fi
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+
+	#------------------------
+	# INSTALL FREESWITCH 
+	#------------------------	
+	/bin/grep 'install_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "FreeSWITCH already Installed! Skipping."
+	else
+		#dingaling/ubuntu has an issue. let's edit the file...
+		#"--mode=relink gcc" --> "--mode=relink gcc -lgnutls" 
+		
+		#tls no longer required for dingaling, so this weird issue doesn't happen. now uses openssl.
+#		/bin/grep 'lgnutls' /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la > /dev/null
+#		if [ $? -eq 0 ]; then
+#			/bin/echo "dingaling fix already applied."
+#		else
+#			/bin/sed -i -e s,'--mode=relink gcc','--mode=relink gcc -lgnutls', /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
+#		fi
+		cd /usr/src/freeswitch
+		if [ $CORES -gt 1 ]; then 
+			/bin/echo "  multicore processor detected. Installing with -j $CORES"
+			/usr/bin/time /usr/bin/make -j $CORES install
+		else 
+			/bin/echo "  singlecore processor detected. Starting install sans -j"
+			/usr/bin/time /usr/bin/make install
+		fi
+		#/usr/bin/time /usr/bin/make install
+	
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: FreeSWITCH INSTALL Failure."
+			exit 1
+		else
+			/bin/echo "install_done" >> /tmp/install_fusion_status
+		fi
+	fi	
+	
+	#------------------------
+	# FREESWITCH  HD SOUNDS
+	#------------------------	
+	/bin/grep 'sounds_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "FreeSWITCH HD SOUNDS DONE! Skipping."
+	else
+		/bin/echo
+		/bin/echo -ne "Installing FreeSWITCH HD sounds (16/8khz). This will take a while [~10 minutes]"
+		/bin/sleep 1
+		/bin/echo -ne "."
+		/bin/sleep 1
+		/bin/echo -ne "."
+		/bin/sleep 1
+		/bin/echo "."
+		cd /usr/src/freeswitch
+		if [ $CORES -gt 1 ]; then 
+			/bin/echo "  multicore processor detected. Installing with -j $CORES"
+			/usr/bin/time /usr/bin/make -j $CORES hd-sounds-install
+		else 
+			/bin/echo "  singlecore processor detected. Starting install sans -j"
+			/usr/bin/time /usr/bin/make hd-sounds-install
+		fi
+		#/usr/bin/time /usr/bin/make hd-sounds-install
+	
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: FreeSWITCH make cdsounds-install ERROR."
+			exit 1
+		else
+			/bin/echo "sounds_done" >> /tmp/install_fusion_status
+		fi
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+	
+
+	#------------------------
+	# FREESWITCH  MOH
+	#------------------------	
+	/bin/grep 'moh_done' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "FreeSWITCH MOH DONE! Skipping."
+	else
+		/bin/echo
+		/bin/echo -ne "Installing FreeSWITCH HD Music On Hold sounds (16/8kHz). This will take a while [~10 minutes]"
+		/bin/sleep 1
+		/bin/echo -ne "."
+		/bin/sleep 1
+		/bin/echo -ne "."
+		/bin/sleep 1
+		/bin/echo "."
+		
+		cd /usr/src/freeswitch
+		if [ $CORES -gt 1 ]; then 
+			/bin/echo "  multicore processor detected. Installing with -j $CORES"
+			/usr/bin/time /usr/bin/make -j $CORES hd-moh-install
+		else 
+			/bin/echo "  singlecore processor detected. Starting install sans -j"
+			/usr/bin/time /usr/bin/make hd-moh-install
+		fi
+		#/usr/bin/make hd-moh-install
+		
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: FreeSWITCH make cd-moh-install ERROR."
+			exit 1
+		else
+			/bin/echo "moh_done" >> /tmp/install_fusion_status
+		fi
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+	
+	#------------------------
+	# FREESWITCH INIT
+	#------------------------
+	#no need for tmp file. already handled...
+	/bin/echo
+	/bin/echo "Configuring /etc/init.d/freeswitch"
+	
+	/bin/grep local /etc/init.d/freeswitch > /dev/null
+	if [ $? -eq 0 ]; then
+		#file exists and has been edited
+		/bin/echo "/etc/init.d/freeswitch already edited, skipping"
+	elif [ -e /usr/src/freeswitch/debian/freeswitch.init ]; then
+		
+		/bin/sed /usr/src/freeswitch/debian/freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
+	else
+		/bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.init  -e s,opt,usr/local, >/etc/init.d/freeswitch
+		#DAEMON
+		/bin/sed -i /etc/init.d/freeswitch -e s,^DAEMON=.*,DAEMON=/usr/local/freeswitch/bin/freeswitch,
+					
+		#DAEMON_ARGS
+		/bin/sed -i /etc/init.d/freeswitch -e s,'^DAEMON_ARGS=.*','DAEMON_ARGS="-u www-data -g www-data -rp -nc -nonat"',
+
+		#PIDFILE
+		/bin/sed -i /etc/init.d/freeswitch -e s,^PIDFILE=.*,PIDFILE=/usr/local/freeswitch/run/\$NAME.pid,
+
+		#WORKDIR
+		/bin/sed -i /etc/init.d/freeswitch -e s,^WORKDIR=.*,WORKDIR=/usr/local/freeswitch/lib/,
+	fi
+	
+	if [ $? -ne 0 ]; then
+		#previous had an error
+		/bin/echo "ERROR: Couldn't edit FreeSWITCH init script."
+		exit 1
+	fi
+	
+	/bin/chmod 755 /etc/init.d/freeswitch
+	/bin/echo "enabling FreeSWITCH to start at boot"
+	
+	/bin/grep true /etc/default/freeswitch > /dev/null
+	if [ $? -eq 0 ]; then
+		#file exists and has been edited
+		/bin/echo "/etc/default/freeswitch already edited, skipping"
+		
+	else
+		if [ -e /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default ]; then
+                        /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default -e s,false,true, > /etc/default/freeswitch
+                        if [ $? -ne 0 ]; then
+                                #previous had an error
+                                /bin/echo "ERROR: Couldn't edit freeswitch RC script."
+                                exit 1
+                        fi
+						
+		else
+			/bin/sed /usr/src/freeswitch/debian/freeswitch.default -e s,false,true, > /etc/default/freeswitch
+			if [ $? -ne 0 ]; then
+				#previous had an error
+				/bin/echo "ERROR: Couldn't edit freeswitch RC script."
+				exit 1
+			fi
+		fi
+		if [ $DEBUG -eq 1 ]; then
+			/bin/echo "Checking for a public IP Address..."
+			
+			PUBLICIP=no
+			
+			#turn off the auto-nat when we start freeswitch.
+			#nasty syntax. searches for 10.a.b.c or 192.168.x.y addresses in ifconfig.
+			/sbin/ifconfig | \
+			/bin/grep 'inet addr:' | \
+			/usr/bin/cut -d: -f2 | \
+			/usr/bin/awk '{ print $1}' | \
+			while read IPADDR; do
+				echo "$IPADDR" | \
+				/bin/grep -e '^10\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
+					-e '^192\.168\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
+					-e '^127.0.0.1$'
+					#-e '^172\.[16-31]\.[0-9]\{1,3\}\.[0-9]\{1,3\}' \
+				
+				if [ $? -ne 0 ]; then
+					PUBLICIP=yes
+				fi
+			done
+			
+			case "$PUBLICIP" in 
+				[Yy]*)
+					if [ $DEBUG -eq 1 ]; then  
+						/bin/echo "You appear to have a public IP address."
+						/bin/echo " I can make sure FreeSWITCH starts with"
+						/bin/echo " the -nonat option (starts quicker)."
+						/bin/echo 
+						read -p "Would you like for me to do this (y/n)? " SETNONAT
+					fi
+				
+				;;
+		
+				*)
+					/bin/echo "Dynamic IP. leaving FreeSWITCH for aggressive nat"
+					SETNONAT=no
+				;;
+			esac
+		fi
+		
+		case "$SETNONAT" in
+			[Yy]*)
+				/bin/sed /etc/default/freeswitch -i -e s,'FREESWITCH_PARAMS="-nc"','FREESWITCH_PARAMS="-nc -nonat"',
+				/bin/echo "init script set to start 'freeswitch -nc -nonat'"
+			;;
+				
+			*)
+						/bin/echo "OK, not using -nonat option."
+			;;
+		esac
+		/bin/echo
+		/usr/sbin/update-rc.d -f freeswitch defaults
+	fi
+	
+	
+	/bin/echo
+	
+	#don't do this.  If freeswitch is a machine name, it really screws this test.  It
+	#won't hurt to adduser a second time anyhow.
+	#/bin/grep freeswitch /etc/passwd > /dev/null
+	#if [ $? -eq 0 ]; then
+		#user already exists
+	#	/bin/echo "FreeSWITCH user already exists, skipping..."
+	#else
+	/bin/echo "adding freeswitch user"
+	/usr/sbin/adduser --disabled-password  --quiet --system \
+		--home /usr/local/freeswitch \
+		--gecos "FreeSWITCH Voice Platform" --ingroup daemon \
+		freeswitch
+
+	if [ $? -ne 0 ]; then
+		#previous had an error
+		/bin/echo "ERROR: Failed adding freeswitch user."
+		exit 1
+	fi
+	#fi
+
+	/usr/sbin/adduser freeswitch audio
+
+	if [ $DO_DAHDI == "y" ]; then
+		#dialout for dahdi
+		/usr/sbin/adduser freeswitch dialout
+	fi
+	
+	/bin/chown -R freeswitch:daemon /usr/local/freeswitch/
+	
+	/bin/echo "removing 'other' permissions on freeswitch"
+	/bin/chmod -R o-rwx /usr/local/freeswitch/
+	/bin/echo
+	cd /usr/local/
+	/bin/chown -R freeswitch:daemon /usr/local/freeswitch
+	/bin/echo "FreeSWITCH directories now owned by freeswitch.daemon"
+	/usr/bin/find freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
+	/bin/echo "FreeSWITCH directories now sticky group. This will cause any files created"
+	/bin/echo "  to default to the daemon group so FreeSWITCH can read them"
+	/bin/echo
+	#/bin/echo "removing /opt blindly (hope nothing is there) and linking it"
+	#/bin/echo "  to /usr/local so FusionPBX won't complain"
+	#Opt might have been created due to a type in adduser freeswitch (home was /opt) check...
+	#this looks to be the case.
+	#the latest FusionBPX is correctly detecting /usr/local/freeswitch
+	#   probably always did.
+	#let's try removing opt altogether...
+	#/bin/echo
+	/bin/ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
+	
+	#if [ $DEBUG -eq 1 ]; then  
+	#	/bin/echo "FreeSWITCH was installed to /usr/local."
+	#	/bin/echo " normally we don't want to see /opt"
+	#	/bin/echo " since FusionPBX. tries to find it"
+	#	/bin/echo " and you end up with having to symlink"
+	#	/bin/echo " /usr/local/freeswitch to /opt/freeswitch"
+	#	/bin/echo 
+	#	/bin/echo " It would be easier to blow /opt away; but"
+	#	/bin/echo " this may not be a fresh Ubuntu install."
+	#	/bin/echo
+	#	read -p "Can I 'rm -Rf /opt (Y/n)? " RMOPT
+	#fi
+	
+	#case "$RMOPT" in
+	#[Yy]*)
+	#	/bin/rm -Rf /opt
+	#;;
+		
+	#*)
+		#/bin/echo "OK, linking /usr/local/freeswitch to /opt/freeswitch"
+		#/bin/ln -s /usr/local/freeswitch /opt/freeswitch
+	#;;
+	
+	#esac
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		/bin/echo "Press Enter to continue (check for errors)"
+		read
+	fi
+	
+	#------------------------
+	# enable modules.conf.xml
+	#------------------------
+	/bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Modules.conf.xml Already enabled"	
+	else
+		#file exists and has been edited
+		enable_modules
+		#check exit status
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
+			exit 1
+		else
+			/bin/echo "enable_modules" >> /tmp/install_fusion_status
+		fi
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		read -p "Press Enter to continue (check for errors)"
+	fi
+
+	#-----------------
+	#Setup logrotate
+	#-----------------	
+#	if [ -a /etc/logrotate.d/freeswitch ]; then
+	if [ -a /etc/cron.daily/freeswitch_log_rotation ]; then
+		/bin/echo "Logrotate for FreeSWITCH Already Done!"
+
+		#call log script creation function
+		freeswitch_logfiles
+	fi
+
+	#-----------------
+	#harden FreeSWITCH
+	#-----------------
+	/bin/echo -ne "HARDENING"
+	sleep 1
+	/bin/echo -ne " ."
+	sleep 1
+	/bin/echo -ne " ."
+	sleep 1
+	/bin/echo -ne " ."
+	
+	/usr/bin/apt-get -y install fail2ban
+	/bin/echo
+	/bin/echo "Checking log-auth-failures"
+	/bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml > /dev/null
+	if [ $? -eq 0 ]; then
+		#see if it's uncommented
+		/bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml | /bin/grep '<!--' > /dev/null
+		if [ $? -eq 1 ]; then
+			#Check for true
+			/bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
+			if [ $? -eq 0 ]; then
+				/bin/echo "     [ENABLED] log-auth-failures - Already Done!"
+			else
+				#it's false and uncommented, change it to true
+				/bin/sed -i -e s,'<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
+					/usr/local/freeswitch/conf/sip_profiles/internal.xml
+				/bin/echo  "     [ENABLED] log-auth-failures - Was False!"
+			fi
+		else 
+			# It's commented
+			# check for true
+			/bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
+			if [ $? -eq 0 ]; then
+				#it's commented and true
+				/bin/sed -i -e s,'<!-- *<param name="log-auth-failures" value="true"/>','<param name="log-auth-failures" value="true"/>', \
+					-e s,'<param name="log-auth-failures" value="true"/> *-->','<param name="log-auth-failures" value="true"/>', \
+					-e s,'<!--<param name="log-auth-failures" value="true"/>','<param name="log-auth-failures" value="true"/>', \
+					-e s,'<param name="log-auth-failures" value="true"/>-->','<param name="log-auth-failures" value="true"/>', \
+					/usr/local/freeswitch/conf/sip_profiles/internal.xml
+				/bin/echo  "     [ENABLED] log-auth-failures - Was Commented!"
+			else
+				#it's commented and false.
+				/bin/sed -i -e s,'<!-- *<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
+					-e s,'<param name="log-auth-failures" value="false"/> *-->','<param name="log-auth-failures" value="true"/>', \
+					-e s,'<!--<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
+					-e s,'<param name="log-auth-failures" value="false"/>-->','<param name="log-auth-failures" value="true"/>', \
+					/usr/local/freeswitch/conf/sip_profiles/internal.xml
+				/bin/echo  "     [ENABLED] log-auth-failures - Was Commented and False!"
+			fi
+		fi
+	else
+		#It's not present...
+		/bin/sed -i -e s,'<settings>','&\n <param name="log-auth-failures" value="true"/>', \
+			/usr/local/freeswitch/conf/sip_profiles/internal.xml
+		/bin/echo  "     [ENABLED] log-auth-failures - Wasn't there!" 
+	fi
+
+	if [ -a /etc/fail2ban/filter.d/freeswitch.conf ]; then
+		/bin/echo "fail2ban filter for freeswitch already done!"
+
+	else
+		/bin/cat > /etc/fail2ban/filter.d/freeswitch.conf  <<"DELIM"
+# Fail2Ban configuration file
+#
+# Author: Rupa SChomaker
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
+            \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+DELIM
+
+/bin/cat > /etc/fail2ban/filter.d/freeswitch-dos.conf  <<"DELIM"
+# Fail2Ban configuration file
+#
+# Author: soapee01
+#
+
+[Definition]
+
+# Option:  failregex
+# Notes.:  regex to match the password failures messages in the logfile. The
+#          host must be matched by a group named "host". The tag "<HOST>" can
+#          be used for standard IP/hostname matching and is only an alias for
+#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
+# Values:  TEXT
+#
+failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth challenge \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
+
+# Option:  ignoreregex
+# Notes.:  regex to ignore. If this regex matches, the line is ignored.
+# Values:  TEXT
+#
+ignoreregex =
+DELIM
+
+	fi
+
+	#see if we've done this before (as in an ISO was made
+	#with this script but the source wasn't included
+	#so we have to reinstall...
+	/bin/grep freeswitch /etc/fail2ban/jail.local > /dev/null
+	if [ $? -ne 0 ]; then
+		#add the following stanzas to the end of our file (don't overwrite)
+		/bin/cat >> /etc/fail2ban/jail.local  <<'DELIM'
+[freeswitch-tcp]
+enabled  = true
+port     = 5060,5061,5080,5081
+protocol = tcp
+filter   = freeswitch
+logpath  = /usr/local/freeswitch/log/freeswitch.log
+action   = iptables-allports[name=freeswitch-tcp, protocol=all]
+maxretry = 5
+findtime = 600
+bantime  = 600
+#          sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
+
+[freeswitch-udp]
+enabled  = true
+port     = 5060,5061,5080,5081
+protocol = udp
+filter   = freeswitch
+logpath  = /usr/local/freeswitch/log/freeswitch.log
+action   = iptables-allports[name=freeswitch-udp, protocol=all]
+maxretry = 5
+findtime = 600
+bantime  = 600
+#          sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
+
+[freeswitch-dos]
+enabled = true
+port = 5060,5061,5080,5081
+protocol = udp
+filter = freeswitch-dos
+logpath = /usr/local/freeswitch/log/freeswitch.log
+action = iptables-allports[name=freeswitch-dos, protocol=all]
+maxretry = 50
+findtime = 30
+bantime  = 6000
+DELIM
+
+	else
+		/bin/echo"fail2ban jail.local for freeswitch already done!"
+	fi
+
+	#problem with the way ubuntu logs ssh failures [fail2ban]
+	#  Failed password for root from 1.2.3.4 port 22 ssh2
+	#  last message repeated 5 times
+	#  SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
+	/bin/echo "Turning off RepeatedMsgReduction in /etc/rsyslog.conf"
+	#not sure what the deal is with the single quotes here. Fixed in v4.4.0
+	#/bin/sed -i ‘s/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/’ /etc/rsyslog.conf
+	/bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
+	/etc/init.d/rsyslog restart
+	
+	#bug in fail2ban.  If you see this error
+	#2011-02-27 14:11:42,326 fail2ban.actions.action: ERROR  iptables -N fail2ban-freeswitch-tcp
+	#http://www.fail2ban.org/wiki/index.php/Fail2ban_talk:Community_Portal#fail2ban.action.action_ERROR_on_startup.2Frestart
+	
+	/bin/grep -A 1 'time.sleep(0\.1)' /usr/bin/fail2ban-client |/bin/grep beautifier > /dev/null
+	if [ $? -ne 0 ]; then
+		/bin/sed -i -e s,beautifier\.setInputCmd\(c\),'time.sleep\(0\.1\)\n\t\t\tbeautifier.setInputCmd\(c\)', /usr/bin/fail2ban-client
+		#this does slow the restart down quite a bit.
+	else
+		/bin/echo '   time.sleep(0.1) already added to /usr/bin/fail2ban-client'
+	fi
+	#still may have a problem with logrotate causing missing new FS log files.
+	#should see log lines such as:
+	#2011-02-13 06:37:59,889 fail2ban.filter : INFO   Log rotation detected for /usr/local/freeswitch/log/freeswitch.log
+	/etc/init.d/freeswitch start
+	/etc/init.d/fail2ban restart
+	
+	/bin/echo "     fail2ban for ssh enabled by default"
+	/bin/echo "     Default is 3 failures before your IP gets blocked for 600 seconds"
+	/bin/echo "      SEE http://wiki.freeswitch.org/wiki/Fail2ban"
+	
+	/bin/echo
+	/bin/echo
+	/bin/echo "FreeSWITCH Installation Completed. Have Fun!"
+	/bin/echo
+
+fi
+
+#---------------------------------------
+#     DONE INSTALLING FREESWITCH
+#---------------------------------------
+	
+  
+#---------------------------------------
+#        INSTALL FUSIONPBX
+#---------------------------------------
+
+if [ $INSFUSION -eq 1 ]; then
+
+	/bin/echo "FYI, we will need to change ownership of all FreeSWITCH"
+	/bin/echo "  Directories to www-data.www-data"
+	/bin/echo "  We will also need to change the init script to"
+	/bin/echo "  start FreeSWITCH as the www-data user."
+	/bin/echo
+	/bin/echo "This is a workaround to FreeSWITCH jira FS-3016"
+	/bin/echo "  The better way would be to have FreeSWITCH and FusionPBX"
+	/bin/echo "  share group permissions; unfortunately, FreeSWITCH writes"
+	/bin/echo "  log files, voicemail, etc with group permissions off."
+	/bin/echo
+	/bin/echo "This behavior is hard coded into FreeSWITCH."
+	/bin/echo "  For now, you need to be aware that if an"
+	/bin/echo "  exploit is found for apache2 or nginx"
+	/bin/echo "  The attacker would have access to the entire"
+	/bin/echo "  FreeSWITCH directory. This isn't quite as bad as it seems though."
+	/bin/echo "  since simply having access to configuration can do damage"
+	/bin/echo "Watch your logfiles."
+	#read -p "   press enter to continue."
+	/bin/echo
+	/bin/echo "Stopping FreeSWITCH..."
+	/etc/init.d/freeswitch stop
+	www_permissions
+
+	#Lets ask... nginx or apache -- for user option only
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo "New Option..."
+		read -p "Would you prefer Apache or Ngnix [nginx and php-fpm from ppa repos] (a/N)? " APACHENGINX
+	fi
+	
+	#remastersys iso ditches the apt data. have to update
+	/usr/bin/apt-get update
+	#get reqs for both
+	/usr/bin/apt-get -y install python-software-properties subversion ghostscript
+	  #provides apt-add-repository
+	  #installs python-software-properties unattended-upgrades
+	  #/usr/bin/apt-get -y install ppa-purge #in backports. don't want that repo
+	if [ ! -e /usr/sbin/ppa-purge ]; then
+		/usr/bin/wget http://us.archive.ubuntu.com/ubuntu/pool/universe/p/ppa-purge/ppa-purge_0+bzr46.1~lucid1_all.deb -O /var/cache/apt/archives/ppa-purge_0+bzr46.1~lucid1_all.deb
+		/usr/bin/dpkg -i /var/cache/apt/archives/ppa-purge_0+bzr46.1~lucid1_all.deb
+	fi
+	
+	/usr/bin/apt-get -y install sqlite php5-cli php5-sqlite php5-odbc 
+	if [ $DISTRO = "precise" ]; then
+		/usr/bin/apt-get -y install php-db
+	fi
+
+	#-----------------
+	# Apache
+	#-----------------	
+	case "$APACHENGINX" in
+	[Aa]*)
+	#if [ $APACHENGINX == "a" ]; then
+		
+		if [ -e /usr/sbin/nginx ]; then
+			#nginx is installed.
+			/bin/echo
+			/bin/echo "Nginx is installed, and you selected apache2."
+			if [ $DEBUG -eq 1 ]; then
+				/bin/echo
+				/bin/echo "  We need to remove nginx/php5-fpm. The packages"
+				/bin/echo "  are not purged, so configuration files will stay."
+				/bin/echo
+				read -p "  Do you want to remove nginx/php5-fpm and install apache2 (y/n)? " YESNO
+			else 
+				YESNO=y
+			fi
+			
+				case "$YESNO" in 
+					[Yy]*)
+						/bin/grep brianmercer /etc/apt/sources.list > /dev/null
+						if [ $? -eq 0 ]; then
+							/bin/echo "php-fpm ppa already add the old way. Fixing"
+							/bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
+						fi
+						/bin/grep nginx /etc/apt/sources.list > /dev/null
+						if [ $? -ne 0 ]; then
+							/bin/echo "nginx ppa already add the old way. Fixing"
+							/bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
+						fi
+						#remove ppa's
+						/usr/sbin/ppa-purge ppa:brianmercer/php
+						/usr/sbin/ppa-purge ppa:nginx/stable
+						#remove packages
+						/usr/bin/apt-get -y remove nginx nginx-full libevent-1.4-2 libt1-5 \
+						   php-apc php-pear php5-fpm php5-gd php5-memcache 
+						  #ttf-dejavu-core fontconfig-config libfontconfig1 libxpm4 #removes x/gnome
+						  #libxslt1.1 libxslt1.1 #removes midori
+						  #libgd2-xpm #removed by ppa-purge
+						  #libgd2-noxpm #removed by ppa-purge
+						/usr/bin/apt-get clean
+						/usr/bin/apt-get update
+						#re-install removed packages
+						/usr/bin/apt-get -y install libgd2-noxpm
+						/bin/echo "  NGINX/PHP5-FPM REMOVED!"
+					;;
+					
+					*)
+						/bin/echo "OK. We'll stop. Exiting!"
+						exit 1
+					;;
+				esac
+		fi
+		
+		/usr/bin/apt-get -y install apache2 libapache2-mod-php5 
+		#installs:
+		#apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
+#		/bin/grep fusionpbx /etc/apache2/sites-enabled/000-default > /dev/null
+#		if [ $? -ne 0 ]; then
+		if [ ! -e /etc/apache2/sites-enabled/$GUI_NAME ]; then
+			#disable the default 000-default site
+			/usr/sbin/a2dissite default
+			#let's use a heredoc now, and do this the right way. #no 'quotes' with variables
+			/bin/cat >> /etc/apache2/sites-available/$GUI_NAME  <<DELIM
+<VirtualHost *:80>
+	ServerAdmin webmaster@localhost
+	ServerName $FQDN
+	DocumentRoot $WWW_PATH/$GUI_NAME
+	<Directory />
+		Options FollowSymLinks
+		AllowOverride None
+	</Directory>
+	<Directory $WWW_PATH/$GUI_NAME/>
+		Options Indexes FollowSymLinks MultiViews
+		AllowOverride None
+		Order allow,deny
+		allow from all
+	</Directory>
+
+	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
+	<Directory "/usr/lib/cgi-bin">
+		AllowOverride None
+		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
+		Order allow,deny
+		Allow from all
+	</Directory>
+
+	ErrorLog /var/log/apache2/error.log
+
+	# Possible values include: debug, info, notice, warn, error, crit,
+	# alert, emerg.
+	LogLevel warn
+
+	CustomLog /var/log/apache2/access.log combined
+
+    Alias /doc/ "/usr/share/doc/"
+    <Directory "/usr/share/doc/">
+        Options Indexes MultiViews FollowSymLinks
+        AllowOverride None
+        Order deny,allow
+        Deny from all
+        Allow from 127.0.0.0/255.0.0.0 ::1/128
+    </Directory>
+
+</VirtualHost>
+DELIM
+			/usr/sbin/a2ensite $GUI_NAME
+			/bin/cat >> /etc/apache2/conf.d/securedb.conf <<'DELIM'
+#
+# The following lines prevent .db files from being
+# viewed by Web clients.
+#
+<Files ~ "^.*\.db">
+    Order allow,deny
+    Deny from all
+    Satisfy all
+</Files>
+DELIM
+			/etc/init.d/apache2 restart
+#			/bin/sed -i -e s,"DocumentRoot /var/www","DocumentRoot /var/www/fusionpbx", \
+#				-e s,"<Directory /var/www/>","<Directory /var/www/fusionpbx/>", \
+#				/etc/apache2/sites-enabled/000-default
+		
+			if [ $? -ne 0 ]; then
+				#previous had an error
+#				/bin/echo "ERROR: Failed edit of /etc/apache2/sites-enabled/000-default"
+				/bin/echo "ERROR: Failed addtion of /etc/apache2/sites-enabled/$GUI_NAME"
+				exit 1
+			else
+#				/bin/echo "/etc/apache2/sites-enabled/000-default modified."
+				/bin/echo "/etc/apache2/sites-enabled/$GUI_NAME added."
+				/bin/echo "  Root www directory is now $WWW_PATH/$GUI_NAME"
+			fi
+		else
+			/bin/echo
+			#/bin/echo "/etc/apache2/sites-enabled/000-default already edited. Skipping..."
+			/bin/echo "/etc/apache2/sites-enabled/$GUI_NAME already there. Skipping..."
+		fi
+		
+		/bin/grep 10M /etc/php5/apache2/php.ini > /dev/null
+		if [ $? -ne 0 ]; then
+			/bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", /etc/php5/apache2/php.ini
+			if [ $? -ne 0 ]; then
+				#previous had an error
+				/bin/echo "ERROR: failed edit of /etc/php5/apache2/php.ini upload_max_filesize = 10M."
+				exit 1
+			fi
+		else
+			/bin/echo
+			/bin/echo "/etc/php5/apache2/php.ini already edited. Skipping..."
+		fi
+		
+		/bin/echo "document root for apache2 is:"
+		/bin/echo "  $WWW_PATH/$GUI_NAME"
+		/bin/echo "  php has an upload file size limit of 10 MegaBytes"
+		/bin/echo
+		/bin/echo "now install FusionPBX. This should go fast."
+		/bin/echo
+	;;
+	#-----------------
+	# Apache Done
+	#-----------------	
+
+
+	#-----------------
+	# NGINX
+	#-----------------		
+	*)
+	#elif [ $APACHENGINX == "n" ] || [ $APACHENGINX == "N" ] || [ $APACHENGINX == "" ]; then
+	# ^ would be almost there. empty read isn't caught. switching to case. more flexible...
+		if [ -e /usr/sbin/apache2 ]; then
+			#apache2 is installed.
+			/bin/echo
+			/bin/echo "Apache2 is installed, and you selected nginx/php5-fpm."
+			if [ $DEBUG -eq 1 ]; then
+				/bin/echo
+				/bin/echo "  We need to remove apache2, and php5. The packages"
+				/bin/echo "  are not purged, so configuration files will stay."
+				/bin/echo
+				/bin/echo "  Do you want to remove apache2/php5 and install "
+				read -p "    nginx/php5-fpm (y/n)? " YESNO
+			else 
+				YESNO=y
+			fi
+			
+				case "$YESNO" in 
+					[Yy]*)
+						#remove packages
+						/usr/bin/apt-get -y remove apache2 apache2-mpm-prefork apache2-utils apache2.2-bin \
+						  apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 \
+						  libaprutil1-ldap ssl-cert
+						  
+						/bin/echo "  APACHE2 REMOVED!"
+						#removing libapr removes subversion!
+						/usr/bin/apt-get -y install subversion
+					;;
+					
+					*)
+						/bin/echo "OK. We'll stop. Exiting!"
+						exit 1
+					;;
+				esac
+		fi
+		
+		if [ $DISTRO = "squeeze" ]; then
+			#setup debian repos for nginx/php5-fpm
+			/bin/echo "adding dotdeb repository for php5-fpm and nginx"
+			/bin/echo "deb http://packages.dotdeb.org squeeze all" > /etc/apt/sources.list.d/squeeze-dotdeb.list
+			/usr/bin/wget -O /tmp/dotdeb.gpg http://www.dotdeb.org/dotdeb.gpg 
+			/bin/cat /tmp/dotdeb.gpg | apt-key add - 
+			/bin/rm /tmp/dotdeb.gpg
+			/usr/bin/apt-get update
+			
+		elif [ $DISTRO = "precise" ]; then
+			#included in main repo we have nginx [nginx-full] and php5-fpm
+			echo "already in 12.04 LTS [precise], nothing to add."
+			
+
+		else
+			#add-apt-repository ppa:brianmercer/php  // apt-get -y install python-software-properties	
+			#Add php5-fpm ppa to the list
+			/bin/grep brianmercer /etc/apt/sources.list > /dev/null
+			if [ $? -eq 0 ]; then
+				/bin/echo "php-fpm ppa already add the old way. Fixing"
+				/bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
+				/usr/bin/apt-add-repository ppa:brianmercer/php
+			
+			elif [ ! -e /etc/apt/sources.list.d./brianmercer-php-lucid.list ]; then
+				/bin/echo "Adding PPA for php-fpm"
+				#/bin/echo "deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucidmain" >> /etc/apt/sources.list
+				#/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F
+				/usr/bin/apt-add-repository ppa:brianmercer/php
+			
+			else
+				/bin/echo "php-fpm ppa already added."
+			fi
+		
+			#Add NGINX-ppa to src list.
+			/bin/grep nginx /etc/apt/sources.list > /dev/null
+			if [ $? -ne 0 ]; then
+				/bin/echo "nginx ppa already add the old way. Fixing"
+				/bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
+				/usr/bin/apt-add-repository ppa:nginx/stable
+			
+			elif [ ! -e /etc/apt/sources.list.d./nginx-stable-lucid.list ]; then 
+				/bin/echo "Adding PPA for latest nginx"
+				/usr/bin/apt-add-repository ppa:nginx/stable
+				#/bin/echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list	
+				#/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
+
+			else
+				/bin/echo "nginx ppa already added"
+			fi
+		fi
+					
+		/usr/bin/apt-get update && /usr/bin/apt-get upgrade -y
+		/usr/bin/apt-get -y install nginx
+			#installs libgd2-noxpm libxslt1.1 nginx nginx-full
+		
+		if [ $DISTRO = "squeeze" ]; then
+			/usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php5-apc php5-sqlite
+		else
+			#should work for precise
+			/usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php-apc
+		fi
+
+		if [ $DISTRO = "squeeze" ]; then
+			PHPINIFILE="/etc/php5/fpm/php.ini"
+			PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
+		elif [ $DISTRO = "precise" ]; then
+			PHPINIFILE="/etc/php5/fpm/php.ini"
+			#also exists, but www.conf used by default...
+			#PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
+			#max_children set in /etc/php5/fpm/pool.d/www.conf
+			PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
+				
+		else
+			PHPINIFILE="/etc/php5/fpm/php.ini"
+			PHPCONFFILE="/etc/php5/fpm/php5-fpm.conf"
+		fi
+		/bin/grep 10M /etc/php5/fpm/php.ini > /dev/null
+		if [ $? -ne 0 ]; then
+			/bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", $PHPINIFILE
+			if [ $? -ne 0 ]; then
+				#previous had an error
+				/bin/echo "ERROR: failed edit of $PHPINIFILE upload_max_filesize = 10M."
+				exit 1
+			fi
+		else
+			/bin/echo
+			/bin/echo "/etc/php5/fpm/php.ini already edited. Skipping..."
+		fi
+		
+		##Applying fix for cgi.fix_pathinfo
+		/bin/grep 'cgi\.fix_pathinfo=0' $PHPINIFILE > /dev/null
+		if [ $? -ne 0 ]; then
+			/bin/sed -i -e s,';cgi\.fix_pathinfo=1','cgi\.fix_pathinfo=0', $PHPINIFILE
+			if [ $? -ne 0 ]; then
+				/bin/echo "ERROR: failed edit of $PHPINIFILE cgi.fix_pathinfo=0"
+				exit 1
+			fi
+		else
+			/bin/echo
+			/bin/echo "/etc/php5/fpm/php.ini already edited for cgi.fix_pathinfo. Skipping..."
+		fi
+		
+		#We don't need so many php children. 1 per core should be fine FOR NOW.
+		#/bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", /etc/php5/fpm/php5-fpm.conf
+		
+		/bin/grep "pm.max_children = 4" $PHPCONFFILE > /dev/null
+		if [ $? -ne 0 ]; then
+			/bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", $PHPCONFFILE
+			if [ $? -ne 0 ]; then
+				#previous had an error
+				/bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_children = 4"
+				exit 1
+			fi
+		else
+			/bin/echo
+			/bin/echo "$PHPCONFFILE [children] already edited. Skipping..."
+		fi
+		
+		#max_servers must be <= max_children
+		/bin/grep "pm.max_spare_servers = 4" $PHPCONFFILE > /dev/null
+		if [ $? -ne 0 ]; then
+			/bin/sed -i -e s,"pm.max_spare_servers = 6","pm.max_spare_servers = 4", $PHPCONFFILE
+			if [ $? -ne 0 ]; then
+				#previous had an error
+				/bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_spare_servers = 4"
+				exit 1
+			fi
+			
+		else
+			/bin/echo
+			/bin/echo "pm.max_spare_servers not changed"
+		fi
+
+		#update auto-starts ###PHP5-fpm and nginx are wrong??
+		update-rc.d php5-fpm enable
+		/etc/init.d/php5-fpm start
+
+		##setup niginx for fusionpbx & phpmyadmin!
+		update-rc.d nginx enable
+		/etc/init.d/nginx start
+
+		#NGINX server config:
+	
+		rm /etc/nginx/sites-enabled/default
+		
+		/bin/grep '.db' /etc/nginx/sites-available/$GUI_NAME >> /dev/null
+		if [ $? -ne 0 ]; then
+			/bin/echo "Nginx insecure previous installation"
+			/bin/echo "  allows http access to FusionPBX database"
+			/bin/echo "  FIXING..."
+			/bin/rm /etc/nginx/sites-available/$GUI_NAME
+		fi
+		
+		if [ -a /etc/nginx/sites-available/$GUI_NAME ]; then
+			/bin/echo "/etc/nginx/sites-available/$GUI_NAME already exists... skipping"
+		else
+			nginxconfig
+		fi
+		if [ $DISTRO = "lucid" ]; then
+			/bin/grep fastcgi_param.*HTTPS.*\$https\; /etc/nginx/fastcgi_params
+			if [ $? -eq 0 ]; then
+				echo "Fixing a weird nginx fastcgi_parm issue"
+				echo "  you can also add the following stanzas to"
+				echo "  your /etc/nginx/sites-enabled/$GUI_NAME file"
+				echo "  set $https off; #for listen 80 and listen localhost"
+				echo "  set $https on; #for listen 443"
+				/bin/sed -i /etc/nginx/fastcgi_params -e s/fastcgi_param.*HTTPS.*\$https\;/#fastcgi_param\ HTTPS\ \$https\;/
+			fi
+		fi
+	;;
+	
+	esac
+	#-----------------
+	# NGINX Done
+	#-----------------
+	
+	#else
+	#	/bin/echo "Didn't catch that. exiting"
+	#	exit 1
+	#fi
+			
+	cd $WWW_PATH
+
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		/bin/echo "Press Enter to continue (check for errors)"
+		read
+	fi	
+	
+	/bin/echo "Stopping FreeSWITCH..."
+	#/etc/init.d/freeswitch stop
+	
+	if [[ "$INST_FPBX" == "svn" ]]; then
+			
+			if [ $FBPXCHECKOUTVER == true ]; then
+				/bin/echo "Going to install FusionPBX SVN Rev $FPBXREV"
+				/usr/bin/svn checkout -r r$FPBXREV http://fusionpbx.googlecode.com/svn/trunk/fusionpbx $WWW_PATH/$GUI_NAME
+			else	
+				/bin/echo "Going to install FusionPBX latest SVN!"
+				#removed -r r1877 r1877 from new install
+				/usr/bin/svn checkout http://fusionpbx.googlecode.com/svn/trunk/fusionpbx $WWW_PATH/$GUI_NAME
+			fi
+			
+			
+        elif [ $INST_FPBX == tgz ]; then
+			/bin/tar -C $WWW_PATH -xzvf $TGZ_FILE
+	fi
+	if [ ! -e $WWW_PATH/$GUI_NAME ]; then
+		/bin/mv $WWW_PATH/fusionpbx $WWW_PATH/$GUI_NAME
+	fi
+
+
+	/usr/sbin/adduser freeswitch www-data
+	/usr/sbin/adduser www-data daemon
+	/bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
+	/bin/echo "freeswitch is now a member of the www-data group"
+	/bin/echo "  www-data is now a member of the dameon group"
+
+	/usr/bin/find $WWW_PATH/$GUI_NAME -type f -exec /bin/chmod 644 {} \;
+	/usr/bin/find $WWW_PATH/$GUI_NAME -type d -exec /bin/chmod 755 {} \;
+
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		/bin/echo "Press Enter to continue (check for errors)"
+		read
+	fi
+
+	if [ $APACHENGINX == "a" ]; then
+		/etc/init.d/apache2 restart
+	elif [ $APACHENGINX == "n" ]; then
+		/etc/init.d/nginx restart
+	fi
+
+	/bin/echo "FusionPBX install needs Write permissions on group to remove files"
+	/bin/echo "The daemon group (of which www-data is a member) can now edit all files"
+	/bin/echo "  in your FreeSWITCH installation. This may or may not be desirable"
+	/bin/echo 
+	/bin/echo "if you want to change this, run (as root)"
+	/bin/echo "  /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g-w {} \;"
+	/bin/echo "  /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g-w {} \;"
+	/bin/echo "  however; FusionPBX won't be able to make changes anymore"
+	/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
+	/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
+	
+#	/bin/echo "go to the web address in your browser to finish configuration"
+#	/bin/echo '  http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
+	
+#	/bin/echo "don't forget to start FreeSWITCH after the install!"
+#	/bin/echo "/etc/init.d/freeswitch start"
+	
+	
+	#FreeSWITCH needs read access to scripts in /var/www/fusionpbx/secure
+	#per mcrane on IRC
+	#mcrane: the easiest way to get it to work is have FreeSWITCH and the web server run under the same user
+	# instead we made freeswitch user a member of the www-data group, and www-data user a member of the
+	# daemon group.
+
+	#added v3
+	#move the default extensions .noload
+	#The default FusionPBX install removes the default FreeSWITCH password, so anyone can register
+	#with these default FreeSWITCH extensions.  They aren't 'in' FusionPBX anyhow, so we don't need
+	#them. We will leave them for reference.
+	/bin/echo "renaming default FreeSWITCH extensions .noload"
+	for i in /usr/local/freeswitch/conf/directory/default/1*.xml;do mv $i $i.noload ; done
+
+	
+
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		/bin/echo "Press Enter to continue (check for errors)"
+		read
+	fi
+	
+	/bin/echo
+	/bin/echo "Finishing Up FusionPBX installation."
+	/bin/echo "Now for a database..."
+	/bin/echo
+	
+
+	#-----------------
+	# MySQL
+	#-----------------
+	#Lets ask... sqlite or mysql -- for user option only
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo "New Option..."
+		/bin/echo "  SQlite is already installed (and required)"
+		/bin/echo
+		read -p "  Would you like to install MySQL, PostgreSQL or stay with Sqlite (m/p/S)? " SQLITEMYSQL
+		case "$SQLITEMYSQL" in
+		  [pP]*)
+			if [ $DISTRO = "precise" ]; then
+				echo "precise is PostgreSQL 9.1 by default"
+				POSTGRES9=9
+			else
+				/bin/echo
+				/bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
+				/bin/echo "  or verion 9 from PPA?"
+				/bin/echo
+				read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9 
+			fi
+			echo
+		  ;;
+		esac
+		
+	fi
+	
+	case "$SQLITEMYSQL" in
+	[Mm]*)
+	#if [ $SQLITEMYSQL == "m" ]; then
+		/bin/echo "Installing MySQL"
+		/usr/bin/apt-get -y install mysql-server php5-mysql mysql-client
+		if [ -e /usr/sbin/nginx ]; then
+			#nginx is installed.
+			/etc/init.d/php5-fpm restart
+			/etc/init.d/nginx restart
+		elif [ -e /usr/sbin/apache2 ]; then
+			#apache2 is installed.
+			/etc/init.d/apache2 restart
+		fi
+		/bin/echo "Now you'll need to manually finish the install and come back"
+		/bin/echo "  This way I can finish up the last bit of permissions issues"
+		/bin/echo "  Just go to"
+		/bin/echo '  http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
+		/bin/echo "       MAKE SURE YOU CHOOSE MYSQL as your Database on the first page!!!"
+		/bin/echo "       ON the Second Page:"
+		/bin/echo "          Create Database Username: root"
+		/bin/echo "          Create Database Password: the_pw_you_set_during_install"
+		/bin/echo "			 other options: whatever you like"
+		/bin/echo "  I will wait here until you get done with that."
+		/bin/echo -ne "  When MySQL is configured come back and press enter. "
+		read
+	;;
+	
+	[Pp]*)
+	#elif [ $SQLITEMYSQL == "p" ]; then	
+		/bin/echo -ne "Installing PostgeSQL"
+		
+		if [ $POSTGRES9 == "9" ]; then
+			/bin/echo " version 9.1"
+			if [ $DISTRO = "squeeze" ]; then
+				#add squeeze repo
+				/bin/echo "Adding debian backports for postgres9.1"
+				/bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
+				/usr/bin/apt-get update
+				/usr/bin/apt-get -y -t squeeze-backports install postgresql-9.1 php5-pgsql
+			elif [ $DISTRO = "precise" ]; then
+				#already there...
+				/usr/bin/apt-get -y install postgresql-9.1 php5-pgsql
+			else
+				#add the ppa
+				/usr/bin/apt-add-repository ppa:pitti/postgresql
+				/usr/bin/apt-get update
+				/usr/bin/apt-get -y install postgresql-9.1 php5-pgsql
+			fi
+		else
+			/bin/echo " version 8.4"
+			/usr/bin/apt-get -y install postgresql php5-pgsql
+			#The following NEW packages will be installed:
+			#  libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
+			#  postgresql-client-common postgresql-common
+		fi
+		
+		/bin/su -l postgres -c "/usr/bin/createuser -s -e $GUI_NAME"
+		#/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O $GUI_NAME $GUI_NAME"
+		/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O $GUI_NAME $GUI_NAME"
+		PGSQLPASSWORD="dummy"
+		PGSQLPASSWORD2="dummy2"
+		while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
+		/bin/echo
+		/bin/echo
+		/bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
+		/bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
+		/bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
+		/bin/echo "psql. THE COMMAND USED IS:"
+		/bin/echo
+		/bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER $GUI_NAME with PASSWORD \$PGSQLPASSWORD;' | psql $GUI_NAME\""
+		/bin/echo
+		/bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
+		/bin/echo
+		/bin/echo "The pgsql username is $GUI_NAME"
+		/bin/echo "The pgsql database name is $GUI_NAME"
+		/bin/echo "Please provide a password for the $GUI_NAME user"
+		#/bin/stty -echo
+		read -s -p "  Password: " PGSQLPASSWORD
+		/bin/echo
+		/bin/echo "Let's repeat that"
+		read -s -p "  Password: " PGSQLPASSWORD2
+		/bin/echo
+		#/bin/stty echo
+		done
+		
+		/bin/su -l postgres -c "/bin/echo \"ALTER USER $GUI_NAME with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql $GUI_NAME"
+		/bin/echo "overwriting pgsql password variable with random data"
+		PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
+		PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
+		
+		if [ -e /usr/sbin/nginx ]; then
+			#nginx is installed.
+			/etc/init.d/php5-fpm restart
+			/etc/init.d/nginx restart
+		elif [ -e /usr/sbin/apache2 ]; then
+			#apache2 is installed.
+			/etc/init.d/apache2 restart
+		fi
+		/bin/echo "Now you'll need to manually finish the install and come back"
+		/bin/echo "  This way I can finish up the last bit of permissions issues"
+		/bin/echo "  Just go to"
+		/bin/echo '  http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
+		/bin/echo "       MAKE SURE YOU CHOOSE PostgreSQL as your Database on the first page!!!"
+		/bin/echo "       ON the Second Page:"
+		/bin/echo "          Database Name: $GUI_NAME"
+		/bin/echo "          Database Username: $GUI_NAME"
+		/bin/echo "          Database Password: whateveryouentered"
+		/bin/echo "          Database Username: Leave_Blank (remove pgsql)"
+		/bin/echo "          Create Database Password: Leave_Blank"
+		/bin/echo 
+		/bin/echo "  I will wait here until you get done with that."
+		/bin/echo -ne "  When PostgreSQL is configured come back and press enter. "
+		read
+	;;
+	
+	
+	*)
+	#elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
+		/bin/echo "SQLITE is chosen. already done. nothing left to install..."
+		if [ -e /usr/sbin/nginx ]; then
+			#nginx is installed.
+			/etc/init.d/php5-fpm restart
+			/etc/init.d/nginx restart
+		elif [ -e /usr/sbin/apache2 ]; then
+			#apache2 is installed.
+			/etc/init.d/apache2 restart
+		fi
+		#with $GUI_NAME in there, it's really hosing things up and how.
+#		/usr/bin/curl -s -d "db_type=sqlite&install_switch_base_dir=%2Fusr%2Flocal%2Ffreeswitch&install_php_dir=%2Fvar%2Fwww%2F$GUI_NAME&install_tmp_dir=%2Ftmp&install_backup_dir=%2Ftmp&install_step=2&submit=Next" http://localhost/install.php > /dev/null
+#		/usr/bin/curl -s -d "db_filename=$GUI_NAME.db&db_filepath=%2Fvar%2Fwww%2F$GUI_NAME%2Fsecure&db_type=sqlite&install_secure_dir=%2Fvar%2Fwww%2F$GUI_NAME%2Fsecure&install_switch_base_dir=%2Fusr%2Flocal%2Ffreeswitch&install_php_dir=%2Fvar%2Fwww%2F$GUI_NAME&install_tmp_dir=%2Ftmp&install_backup_dir=%2Ftmp&install_step=3&submit=Next" http://localhost/install.php > /dev/null
+		
+		#do for https too!
+#		/usr/bin/curl -k -s -d "db_type=sqlite&install_switch_base_dir=%2Fusr%2Flocal%2Ffreeswitch&install_php_dir=%2Fvar%2Fwww%2F$GUI_NAME&install_tmp_dir=%2Ftmp&install_backup_dir=%2Ftmp&install_step=2&submit=Next" https://localhost/install.php > /dev/null
+#		/usr/bin/curl -k -s -d "db_filename=$GUI_NAME.db&db_filepath=%2Fvar%2Fwww%2F$GUI_NAME%2Fsecure&db_type=sqlite&install_secure_dir=%2Fvar%2Fwww%2F$GUI_NAME%2Fsecure&install_switch_base_dir=%2Fusr%2Flocal%2Ffreeswitch&install_php_dir=%2Fvar%2Fwww%2F$GUI_NAME&install_tmp_dir=%2Ftmp&install_backup_dir=%2Ftmp&install_step=3&submit=Next" https://localhost/install.php > /dev/null
+		
+		/bin/echo "FusionPBX install.php was done automatically"
+		/bin/echo "  when sqlite was selected. "
+		/bin/echo "  FreeSWITCH Directory: /usr/local/freeswitch"
+		/bin/echo "  PHP Directory: $WWW_PATH/$GUI_NAME"
+		/bin/echo
+		/bin/echo "  Database Filename: $GUI_NAME.db"
+		/bin/echo "  Database Directory: $WWW_PATH/$GUI_NAME/secure"
+		/bin/echo
+		/bin/echo "  Just go to"
+		/bin/echo '  http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`	
+		/bin/echo
+		/bin/echo "Default login is (whatever you picked in the GUI install):"
+		/bin/echo "  User: WhateverUsernameYouPicked"
+		/bin/echo "  Passwd: YourPasswordYouPicked"
+		
+	
+	;;
+	esac
+	#else
+	#	/bin/echo "Didn't catch that. exiting"
+	#	exit 1
+	#fi
+	
+	finish_fpbx_install_permissions
+	#/bin/echo
+	#/bin/echo "The FusionPBX installation messed up permissions of /usr/local/freeswitch/storage"
+	#/bin/echo "   Fixing..."
+#	read
+	#/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
+	#/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
+	
+	#/bin/echo "Starting FreeSWITCH..."
+	#/etc/init.d/freeswitch start
+	/bin/echo "Setting up Fail2Ban for FusionPBX"
+	fusionfail2ban
+	/etc/init.d/fail2ban restart
+	
+	/bin/echo
+	/bin/echo
+	/bin/echo "Installation Completed.  Now configure FreeSWITCH via the FusionPBX browser interface"
+	/bin/echo
+	/bin/echo '  http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
+	/bin/echo "Default login is (whatever you picked in the GUI install):"
+	/bin/echo "  User: WhateverUsernameYouPicked"
+	/bin/echo "  Passwd: YourPasswordYouPicked"
+	
+	
+fi
+#------------------------------------
+#    DONE INSTALLING FUSIONPBX
+#------------------------------------
+
+
+#------------------------------------
+#       UPGRADE FREESWITCH
+#------------------------------------
+
+if [ $UPGFREESWITCH -eq 1 ]; then
+
+	#------------------------
+	# build modules.conf 
+	#------------------------
+	/bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Modules.conf Already edited"	
+	else
+		#file exists and has been edited
+		build_modules
+		#check exit status
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: Failed to enable build modules in modules.conf."
+			exit 1
+		else
+			/bin/echo "build_modules" >> /tmp/install_fusion_status
+		fi
+	fi	
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		/bin/echo "Press Enter to continue (check for errors)"
+		read
+	fi
+
+	#------------------------
+	# make current 
+	#------------------------
+	/bin/grep 'made_current' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Modules.conf Already edited"	
+	else	
+		/bin/echo
+		/bin/echo ' going to run make curent'
+		/bin/echo "   Make current completely cleans the build environment and rebuilds FreeSWITCH™"
+		/bin/echo "   so it runs a long time. However, it will not overwrite files in a pre-existing"
+		/bin/echo '   "conf" directory. Also, the clean targets leave the "modules.conf" file.'
+		/bin/echo "   This handles the git pull, cleanup, and rebuild in one step"
+		/bin/echo '       src: http://wiki.freeswitch.org/wiki/Installation_Guide'
+		cd /usr/src/freeswitch
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "/usr/local/freeswitch does not exist"
+			/bin/echo "you probably installed from a FusionPBX ISO which deleted this"
+			/bin/echo "Directory to save space.  rerun with install-freeswitch option"
+			exit 1
+		fi
+		cd /usr/src/freeswitch
+		if [ $CORES > "1" ]; then 
+			/bin/echo "  multicore processor detected. Upgrading with -j $CORES"
+			/usr/bin/time /usr/bin/make -j $CORES current
+		else 
+			/bin/echo "  singlecore processor detected. Starting upgrade sans -j"
+			/usr/bin/time /usr/bin/make current
+		fi
+		#/usr/bin/make current
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "make current error"
+			exit 1
+		fi			
+		/etc/init.d/freeswitch stop
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "Init ERROR, couldn't stop Freeswitch"
+			exit 1
+		fi
+		/usr/bin/make install
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "INSTALL ERROR!"
+			exit 1
+		else 
+			/bin/echo "made_current" >> /tmp/install_fusion_status
+		fi
+		/etc/init.d/freeswitch start
+	fi
+	
+	#------------------------
+	# enable modules.conf.xml
+	#------------------------
+	/bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
+	if [ $? -eq 0 ]; then
+		/bin/echo "Modules.conf.xml Already enabled"	
+	else
+		#file exists and has been edited
+		enable_modules
+		#check exit status
+		if [ $? -ne 0 ]; then
+			#previous had an error
+			/bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
+			exit 1
+		else
+			/bin/echo "enable_modules" >> /tmp/install_fusion_status
+		fi
+	fi
+	
+	if [ $DEBUG -eq 1 ]; then
+		/bin/echo
+		/bin/echo "Press Enter to continue (check for errors)"
+		read
+	fi
+	
+	#check for logrotate and change to cron.daily
+	if [ -a /etc/logrotate.d/freeswitch ]; then
+		/bin/echo "System configured for logrotate, changing"
+		/bin/echo "   to new way."
+		/bin/rm /etc/logrotate.d/freeswitch
+		/etc/init.d/logrotate restart
+		freeswitch_logfiles
+	fi
+fi
+#------------------------------------
+#    DONE UPGRADING FREESWITCH
+#------------------------------------
+	
+
+
+#------------------------------------
+#       UPGRADE FusionPBX
+#------------------------------------
+
+if [ $UPGFUSION -eq 1 ]; then
+	/bin/echo "Resetting FreeSWITCH permissions to www-data in case you did"
+	/bin/echo "  a FreeSWITCH upgrade as well."
+	www_permissions
+	/bin/echo
+	/bin/echo "STOP! Make sure you are logged into fusionpbx as the superadmin (via browser)!!!"
+	read -p "Have you done this yet (y/n)? " YESNO
+	if [ $YESNO == "y" ]; then
+		/bin/echo "Be really sure you are logged in as superadmin."
+		/bin/echo "  If nothing else, refresh the browser to make sure"
+		/bin/echo "  the session isn't stale."
+		/bin/echo 
+		/bin/echo "If you haven't done this you risk not being able to Upgrade->Schema"
+		/bin/echo "  which will toast your database"
+		/bin/echo
+		
+		FUSIONREV=$(svn info $WWW_PATH/$GUI_NAME |grep -i revision|sed -e s/Revision:\ //)
+		if [ $FUSIONREV -le 1877 ]; then
+			echo "The project is still working on an upgrade tool"
+			echo "    for the latest svn version.  It is recommended"
+			echo "    that you stay with revision 1877.  Your current"
+			echo "    revision is $FUSIONREV"
+			echo
+			read -p "Do we want Revision 1877, or latest (1877/latest)? " YESNO2
+		else
+				read -p "Ready to upgrade (y/n)? " YESNO2
+		fi
+		
+		case $YESNO2 in 
+		
+		[YylL]*)
+		
+			#svn...
+			
+			/usr/bin/svn update http://fusionpbx.googlecode.com/svn/trunk/fusionpbx $WWW_PATH/$GUI_NAME
+			/bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
+			#print message saying to hit advanced->upgrade schema
+			/bin/echo "Done upgrading Files"
+			/bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
+			/bin/echo "and select Advanced -> Upgrade Schema"
+		;;
+		
+		[1]*)
+			/usr/bin/svn update -r r1877 http://fusionpbx.googlecode.com/svn/trunk/fusionpbx $WWW_PATH/$GUI_NAME
+			/bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
+			#print message saying to hit advanced->upgrade schema
+			/bin/echo "Done upgrading Files"
+			/bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
+			/bin/echo "and select Advanced -> Upgrade Schema"
+		;;
+		*)
+			echo "Bad option, exiting"
+			exit 1
+		;;
+		esac
+	else
+		exit 1
+	fi
+	read -p "Do you want to try and run the auto-upgrade php script from CLI (y/n)? " YESNO
+	case $YESNO in
+	[yY]*)
+			echo "Starting... /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
+			/usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php
+			echo "Done"
+	;;
+	*)
+		echo "OK, don't forget to run it yourself via gui or here with"
+		echo "    /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
+	;;
+	esac
+	fusionfail2ban
+fi
+#------------------------------------
+#    DONE UPGRADING FusionPBX
+#------------------------------------
+
+#success!!!
+if [ -e /tmp/install_fusion_status ]; then
+	/bin/rm /tmp/install_fusion_status
+fi
+
+/bin/echo "Checking to see if FreeSWITCH is running!"
+/usr/bin/pgrep freeswitch
+if [ $? -ne 0 ]; then
+	/etc/init.d/freeswitch start
+else
+	/bin/echo "    DONE!"
+fi
+
+
+exit 0
+
+---------
+#CHANGELOG
+#---------
+# vSVN, now using SVN.... November 2011
+
+#v4.4.0pre 2011 April 12
+
+#BUGS: FS CHANGED!!! 2011-05-12
+#		Add libssl-dev
+#		currently mod_cidlookup, mod_xml_curl mod_xml_cdr busted
+
+#BUGS: FS isn't  started at end of install-both auto
+#BUGS: fix-https still throws usage help. check www-permissions too.
+#BUGS: Apache heredoc isn't escaping the variables. documentroot and servername wrong.
+#BUGS: dingaling still not compile right. let's change makefile and recompile module
+#ADD: zip compression to nginx
+#ADD: monit for freeswitch and nginx
+#add libssl-dev for secure sip.
+
+#	ADD mod_spandsp for fax and g722
+#		apt-get install libtiff4-dev
+#	Add NTP, maybe run sudo ntpdate ntp.ubuntu.com to make suer date is correct.
+# 		prevents make from dying (date in the future crap).
+#	BUGS: Had quotes around nginx config
+#			FS failed to start with script
+#			Fail2Ban FS-dos has freeswitch2 in jail.local
+#			Fail2ban not starting: 
+#			freeswitch-dos ports wrong in jail.local.
+#				build again and run fail2ban-client -d to test.
+#   Add Option to download FreeSWITCH compiled source as tar.gz for iso
+#   Added Option --fix-permissions
+#		checks FreeSWITCH init script 
+#	Added: upgrade-fusionpbx needs to fix permissions, since a FS upgrade kills them.
+#	FIXED Logrotate for nginx
+#		logfiles were: /var/log/fusionpbx_gui.*_log;
+#		logfiles now: /var/log/nginx/*.log
+#	Added: Fail2ban for FusionPBX failed login attempts
+#		Need information on attempts/rate/etc 
+#	Added: Fail2ban for FusionPBX on failed provision attempts
+#		Need information on attempts/rate/etc 
+#		Needs Testing!
+#	FIXED: RepeatedMsgReduction wasn't getting set correctly in rsyslog.conf
+#	Added Change Fail2ban on FreeSWITCH with attempts/rate/etc in config file (not default settings)
+#	Added: Option to download GIT from GitHub repository (It's faster), see DEFINES
+
+#	Make nginx/apache https by default
+#		iso needs to regenerate certificates post install, ideally with 10 year expirations. 
+#		apt-get install ssl-cert
+#		ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
+#		ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
+#		ln -s /etc/ssl/certs/nginx.crt /var/www/fusionpbx/$HOSTNAME.crt
+#		/etc/init.d/nginx restart
+		
+#	FIXED nginx config to not block html files... Don't do block ~ .ht 
+#	Added FreeTDM, and Dahdi
+
+#v4.3.3 2011 January 31
+#	Added: smp compile support. Script works, make -j doesn't. see jira FS-3005
+#	Fixed: NGinx file size error
+#	Added: Remove Nginx/php/apache properly
+#		FIXED removing nginx removes gnome/x.
+#	Added: Postgres (seems good)
+#	Fixed: Set up apache properly (fusionpbx file instead of default, use heredoc)
+#   	TODO: look into setting up FS for mysql/pgsql
+#   	Fixed: sqlite http request issue for nginx/apache
+#   	Added: now doing ppa's the ubuntu way with apt-add-repository
+#   	Added: set up auto install for nginx/apache, mysql/postgresql/sqlite, setnonat.
+#	Added: now prompts for rm -Rf /opt (or variable for auto-install).
+#	There's a bug in either ppa-purge or apt-add-repository (likely latter).
+#	  if you install nginx, change your mind, install apache, change your mind again
+#	  and re-install nginx, the repository for nginx/php5-fpm gets removed proerly
+#	  [a '#' covers repo], but when re-enabling, the '#' gets replaced, and an 'n'
+#	  is left on a newline afterward, preventing update/install from that repo.
+#	Fixed: Checking for nginx/apache2 binary instead of init scripts for if[x] restart
+
+#v4.3.2.1 2011 January 1
+#	small problem when selecting nginx and sqlite. php5-fpm needed to restart
+#	 so FusionPBX could see the FreeSWITCH directory.
+#v4.3.2 2010 December 30
+#	logrotate was improperly setup. Needed to send sighup to fs_cli
+#	  Caused FS to die the first time it tried to log after rotation.
+#	php5-cli is a dependancy. required for voicemail to email, and fax to email.
+#	added an nginx/php-fpm option.  You can change a variable (for auto run)
+#	  or it will prompt you when you install fusionpbx in user mode
+#	mysql added as an option.
+#	problem with the way ubuntu logs ssh failures [fail2ban]
+#	  Failed password for root from 1.2.3.4 port 22 ssh2
+#	  last message repeated 5 times
+#	  SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
+#	fail2ban: previous setup looked for freeswitch log in /var/log/freeswitch.log
+#	  log is actually /usr/local/freeswitch/log/freeswitch.log
+#	Tries to see if you're on a static IP address. If you are, it wants to start
+#	  FreeSWITCH with the -nonat option to save some time. Also a new variable
+#	TODO: Maybe probe cores and to the -b thing for quicker compile/bootstrap
+#	TODO: IPTABLES
+	
+#v4.3.1 2010 December 23
+#	look into make -j cores option
+#	made a state save file.  so if there's an error, don't re-bootstrap, configure, etc.
+#	  and remove it on a clean exit.
+#	requests for modules add/enable for ugrade-freeswitch. DONE
+#	mod dingaling needs libgnutls-dev libgnutls26 packages, and change: 
+#	  "--mode=relink gcc" --> "--mode=relink gcc -lgnutls" 
+#	  in /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
+#	  appears to be an ubuntu problem....
+
+#v4.3 2010 December 22
+#	under case upgrade-freeswitch, variables were not set properly.  It upgraded fusionpbx.. fixed.
+#	done: fail2ban error fixed. removed associated text
+#	done: have install check for /etc/fail2ban. reinstall (as in from iso) duplicates some txt
+#	done: remove or fix fusionpbx upgrade code. it either needs to log in
+#	  and then update and run the schema upgrade. or get rid of it. Fixed by prompting the user
+#	  to open a browser window, and warn.
+#	done: get logrotate working... let's not fill the disk.
+#	stop/start freeswitch for an upgrade, and an install...
+
+#v4.2 2010 December 17
+#	made some changes so the text flows correctly now that we use curl
+#   to do install.php.  
+#   sent curl output to dev null..
+#   added apt-get update before we install apache since remastersys removes apt data
+#   stopping FS before FusionPBX install, and starting afteward.
+#   changed license to WAF v1
+
+#v4.1 2010 December 15
+#   changing cd sounds (48/32/16/8khz) down to hd sounds (16/8Kkhz)
+
+#v4 2010 December 14
+#   now install-fusion|install-freeswitch|upgrade...
+#   also adding curl commands to finish fusionpbx install.
+
+#v3 adding fail2ban et al.
+
+#v2 2010 December 07
+#   adds arrays to process the modules.  should make this much easier to edit.
+#	just make additions to modules_add
+#	This should work fine (even on a 2nd run).
+
+#v1 2010 December 06
+# was first cut

+ 6101 - 0
upgrade/r1877-export.php

@@ -0,0 +1,6101 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/config.php";
+require_once "includes/checkauth.php";
+if (ifgroup("superadmin")) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//user defined settings
+	$export_type = "sql"; //default sql;
+	$debug = false;
+	$invoices = false; //default false;
+	$db_type = "sqlite"; //pgsql, sqlite, mysql
+
+//used for debugging
+	if ($debug) {
+		echo "<pre>\n";
+	}
+
+//set the headers
+	if ($export_type == "sql" && !$debug) {
+		header('Content-type: application/octet-binary');
+		header('Content-Disposition: attachment; filename=database_backup.sql');
+	}
+
+//add an rfc compliant version 4 uuid function
+	if (!function_exists('uuid')) {
+		function uuid() {
+			return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
+				// 32 bits for 'time_low'
+				mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
+
+				// 16 bits 'for time_mid'
+				mt_rand( 0, 0xffff ),
+
+				// 16 bits for 'time_hi_and_version',
+				// four most significant bits holds version number 4
+				mt_rand( 0, 0x0fff ) | 0x4000,
+
+				// 16 bits, 8 bits for 'clk_seq_hi_res',
+				// 8 bits for 'clk_seq_low',
+				// two most significant bits holds zero and one for variant DCE1.1
+				mt_rand( 0, 0x3fff ) | 0x8000,
+
+				// 48 bits for 'node'
+				mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
+			);
+		}
+	}
+
+$schema_pgsql = <<<EOD
+CREATE TABLE v_call_broadcasts (
+call_call_broadcast_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+broadcast_name text,
+broadcast_description text,
+broadcast_timeout numeric,
+broadcast_concurrent_limit numeric,
+recording_uuid uuid,
+broadcast_caller_id_name text,
+broadcast_caller_id_number text,
+broadcast_destination_type text,
+broadcast_phone_numbers text,
+broadcast_destination_data text);
+
+CREATE TABLE v_call_center_agents (
+call_center_agent_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+agent_name text,
+agent_type text,
+agent_call_timeout numeric,
+agent_contact text,
+agent_status text,
+agent_logout text,
+agent_max_no_answer numeric,
+agent_wrap_up_time numeric,
+agent_reject_delay_time numeric,
+agent_busy_delay_time numeric,
+agent_no_answer_delay_time text);
+
+CREATE TABLE v_call_center_logs (
+cc_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+cc_queue text,
+cc_action text,
+cc_count numeric,
+cc_agent text,
+cc_agent_system text,
+cc_agent_status text,
+cc_agent_state text,
+cc_agent_uuid uuid,
+cc_selection text,
+cc_cause text,
+cc_wait_time text,
+cc_talk_time text,
+cc_total_time text,
+cc_epoch numeric,
+cc_date timestamp,
+cc_agent_type text,
+cc_member_uuid text,
+cc_member_session_uuid text,
+cc_member_cid_name text,
+cc_member_cid_number text,
+cc_agent_called_time numeric,
+cc_agent_answered_time numeric,
+cc_member_joined_time numeric,
+cc_member_leaving_time numeric,
+cc_bridge_terminated_time numeric,
+cc_hangup_cause text);
+
+CREATE TABLE v_call_center_queues (
+call_center_queue_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+dialplan_uuid uuid,
+queue_name text,
+queue_extension text,
+queue_strategy text,
+queue_moh_sound text,
+queue_record_template text,
+queue_time_base_score text,
+queue_max_wait_time numeric,
+queue_max_wait_time_with_no_agent numeric,
+queue_tier_rules_apply text,
+queue_tier_rule_wait_second numeric,
+queue_tier_rule_no_agent_no_wait text,
+queue_timeout_action text,
+queue_discard_abandoned_after numeric,
+queue_abandoned_resume_allowed text,
+queue_tier_rule_wait_multiply_level text,
+queue_cid_prefix text,
+queue_description text);
+
+CREATE TABLE v_call_center_tiers (
+call_center_tier_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+agent_name text,
+queue_name text,
+tier_level numeric,
+tier_position numeric);
+
+CREATE TABLE v_conferences (
+domain_uuid uuid,
+conference_uuid uuid PRIMARY KEY,
+dialplan_uuid uuid,
+conference_name text,
+conference_extension text,
+conference_pin_number text,
+conference_profile text,
+conference_flags text,
+conference_order numeric,
+conference_description text,
+conference_enabled text);
+
+CREATE TABLE v_conference_users (
+conference_user_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+conference_uuid uuid,
+user_uuid uuid);
+
+CREATE TABLE v_contacts (
+contact_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+contact_type text,
+contact_organization text,
+contact_name_given text,
+contact_name_family text,
+contact_nickname text,
+contact_title text,
+contact_role text,
+contact_email text,
+contact_url text,
+contact_time_zone text,
+contact_note text);
+
+CREATE TABLE v_contact_addresses (
+contact_address_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+contact_uuid uuid,
+address_type text,
+address_street text,
+address_extended text,
+address_locality text,
+address_region text,
+address_postal_code text,
+address_country text,
+address_latitude text,
+address_longitude text);
+
+CREATE TABLE v_contact_phones (
+contact_phone_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+contact_uuid uuid,
+phone_type text,
+phone_number text);
+
+CREATE TABLE v_contact_notes (
+contact_note_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+contact_uuid uuid,
+contact_note text,
+last_mod_date text,
+last_mod_user text);
+
+CREATE TABLE v_rss (
+rss_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+rss_language text,
+rss_category text,
+rss_sub_category text,
+rss_title text,
+rss_link text,
+rss_description text,
+rss_img bytea,
+rss_optional_1 text,
+rss_optional_2 text,
+rss_optional_3 text,
+rss_optional_4 text,
+rss_optional_5 text,
+rss_add_date text,
+rss_add_user text,
+rss_del_date text,
+rss_del_user text,
+rss_order numeric,
+rss_content text,
+rss_group text);
+
+CREATE TABLE v_rss_sub (
+rss_sub_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+rss_uuid uuid,
+rss_sub_language text,
+rss_sub_title text,
+rss_sub_link text,
+rss_sub_description text,
+rss_sub_optional_1 text,
+rss_sub_optional_2 text,
+rss_sub_optional_3 text,
+rss_sub_optional_4 text,
+rss_sub_optional_5 text,
+rss_sub_add_date text,
+rss_sub_add_user text,
+rss_sub_del_user text,
+rss_sub_del_date text);
+
+CREATE TABLE v_rss_sub_category (
+rss_sub_category_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+rss_sub_category_language text,
+rss_category text,
+rss_sub_category text,
+rss_sub_category_description text,
+rss_sub_add_user text,
+rss_sub_add_date text);
+
+CREATE TABLE v_destinations (
+domain_uuid uuid,
+destination_uuid uuid PRIMARY KEY,
+destination_name text,
+destination_context text,
+destination_extension text,
+destination_enabled text,
+destination_description text);
+
+CREATE TABLE v_dialplans (
+domain_uuid uuid,
+dialplan_uuid uuid PRIMARY KEY,
+app_uuid uuid,
+dialplan_context text,
+dialplan_name text,
+dialplan_number text,
+dialplan_continue text,
+dialplan_order numeric,
+dialplan_enabled text,
+dialplan_description text);
+
+CREATE TABLE v_dialplan_details (
+domain_uuid uuid,
+dialplan_uuid uuid,
+dialplan_detail_uuid uuid PRIMARY KEY,
+dialplan_detail_tag text,
+dialplan_detail_type text,
+dialplan_detail_data text,
+dialplan_detail_break text,
+dialplan_detail_inline text,
+dialplan_detail_group numeric,
+dialplan_detail_order numeric);
+
+CREATE TABLE v_extensions (
+extension_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+extension text,
+number_alias text,
+password text,
+provisioning_list text,
+mailbox text,
+vm_password text,
+accountcode text,
+effective_caller_id_name text,
+effective_caller_id_number text,
+outbound_caller_id_name text,
+outbound_caller_id_number text,
+emergency_caller_id_number text,
+directory_full_name text,
+directory_visible text,
+directory_exten_visible text,
+limit_max numeric,
+limit_destination text,
+vm_enabled text,
+vm_mailto text,
+vm_attach_file text,
+vm_keep_local_after_email text,
+user_context text,
+toll_allow text,
+call_group text,
+hold_music text,
+auth_acl text,
+cidr text,
+sip_force_contact text,
+nibble_account numeric,
+sip_force_expires numeric,
+enabled text,
+description text,
+mwi_account text,
+sip_bypass_media text);
+
+CREATE TABLE v_extension_users (
+extension_user_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+extension_uuid uuid,
+user_uuid uuid);
+
+CREATE TABLE v_fax (
+fax_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+dialplan_uuid uuid,
+fax_extension text,
+fax_name text,
+fax_email text,
+fax_pin_number text,
+fax_caller_id_name text,
+fax_caller_id_number text,
+fax_forward_number numeric,
+fax_description text);
+
+CREATE TABLE v_fax_users (
+fax_user_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+fax_uuid uuid,
+user_uuid uuid);
+
+CREATE TABLE v_gateways (
+gateway_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+gateway text,
+username text,
+password text,
+distinct_to text,
+auth_username text,
+realm text,
+from_user text,
+from_domain text,
+proxy text,
+register_proxy text,
+outbound_proxy text,
+expire_seconds numeric,
+register text,
+register_transport text,
+retry_seconds numeric,
+extension text,
+ping text,
+caller_id_in_from text,
+supress_cng text,
+sip_cid_type text,
+extension_in_contact text,
+context text,
+profile text,
+enabled text,
+description text);
+
+CREATE TABLE v_hardware_phones (
+hardware_phone_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+phone_mac_address text,
+phone_label text,
+phone_vendor text,
+phone_model text,
+phone_firmware_version text,
+phone_provision_enable text,
+phone_template text,
+phone_username text,
+phone_password text,
+phone_time_zone text,
+phone_description text);
+
+CREATE TABLE v_hunt_groups (
+hunt_group_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+dialplan_uuid uuid,
+hunt_group_extension text,
+hunt_group_name text,
+hunt_group_type text,
+hunt_group_context text,
+hunt_group_timeout text,
+hunt_group_timeout_destination text,
+hunt_group_timeout_type text,
+hunt_group_ringback text,
+hunt_group_cid_name_prefix text,
+hunt_group_pin text,
+hunt_group_caller_announce text,
+hunt_group_call_prompt text,
+hunt_group_user_list text,
+hunt_group_enabled text,
+hunt_group_description text);
+
+CREATE TABLE v_hunt_group_destinations (
+hunt_group_destination_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+hunt_group_uuid uuid,
+destination_data text,
+destination_type text,
+destination_profile text,
+destination_timeout text,
+destination_order numeric,
+destination_enabled text,
+destination_description text);
+
+CREATE TABLE v_hunt_group_users (
+hunt_group_user_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+hunt_group_uuid uuid,
+user_uuid uuid);
+
+CREATE TABLE v_invoices (
+invoice_uuid uuid,
+domain_uuid uuid,
+contact_uuid_from uuid,
+contact_uuid_to uuid,
+invoice_number numeric,
+invoice_date timestamp with time zone,
+invoice_notes text);
+
+CREATE TABLE v_invoice_items (
+invoice_item_uuid uuid,
+domain_uuid uuid,
+invoice_uuid uuid,
+item_qty numeric,
+item_desc text,
+item_unit_price numeric);
+
+CREATE TABLE v_ivr_menus (
+ivr_menu_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+dialplan_uuid uuid,
+ivr_menu_name text,
+ivr_menu_extension numeric,
+ivr_menu_greet_long text,
+ivr_menu_greet_short text,
+ivr_menu_invalid_sound text,
+ivr_menu_exit_sound text,
+ivr_menu_confirm_macro text,
+ivr_menu_confirm_key text,
+ivr_menu_tts_engine text,
+ivr_menu_tts_voice text,
+ivr_menu_confirm_attempts numeric,
+ivr_menu_timeout numeric,
+ivr_menu_exit_app text,
+ivr_menu_exit_data text,
+ivr_menu_inter_digit_timeout numeric,
+ivr_menu_max_failures numeric,
+ivr_menu_max_timeouts numeric,
+ivr_menu_digit_len numeric,
+ivr_menu_direct_dial text,
+ivr_menu_enabled text,
+ivr_menu_description text);
+
+CREATE TABLE v_ivr_menu_options (
+ivr_menu_option_uuid uuid PRIMARY KEY,
+ivr_menu_uuid uuid,
+domain_uuid uuid,
+ivr_menu_option_digits text,
+ivr_menu_option_action text,
+ivr_menu_option_param text,
+ivr_menu_option_order numeric,
+ivr_menu_option_description text);
+
+CREATE TABLE v_modules (
+module_uuid uuid PRIMARY KEY,
+module_label text,
+module_name text,
+module_category text,
+module_enabled text,
+module_default_enabled text,
+module_description text);
+
+CREATE TABLE v_clips (
+clip_uuid uuid PRIMARY KEY,
+clip_name text,
+clip_folder text,
+clip_text_start text,
+clip_text_end text,
+clip_order text,
+clip_desc text);
+
+CREATE TABLE v_php_services (
+php_service_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+service_name text,
+service_script text,
+service_enabled text,
+service_description text);
+
+CREATE TABLE v_recordings (
+recording_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+recording_filename text,
+recording_name text,
+recording_description text);
+
+CREATE TABLE v_ring_groups (
+domain_uuid uuid,
+ring_group_uuid uuid,
+ring_group_name text,
+ring_group_extension text,
+ring_group_context text,
+ring_group_strategy text,
+ring_group_timeout_sec numeric,
+ring_group_timeout_app text,
+ring_group_timeout_data text,
+ring_group_enabled text,
+ring_group_description text,
+dialplan_uuid uuid);
+
+CREATE TABLE v_ring_group_extensions (
+ring_group_extension_uuid uuid,
+domain_uuid uuid,
+ring_group_uuid uuid,
+extension_uuid uuid);
+
+CREATE TABLE v_services (
+service_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+service_name text,
+service_type text,
+service_data text,
+service_cmd_start text,
+service_cmd_stop text,
+service_cmd_restart text,
+service_description text);
+
+CREATE TABLE v_settings (
+numbering_plan text,
+event_socket_ip_address text,
+event_socket_port text,
+event_socket_password text,
+xml_rpc_http_port text,
+xml_rpc_auth_realm text,
+xml_rpc_auth_user text,
+xml_rpc_auth_pass text,
+admin_pin numeric,
+smtp_host text,
+smtp_secure text,
+smtp_auth text,
+smtp_username text,
+smtp_password text,
+smtp_from text,
+smtp_from_name text,
+mod_shout_decoder text,
+mod_shout_volume text);
+
+CREATE TABLE v_sip_profiles (
+sip_profile_uuid uuid,
+sip_profile_name text,
+sip_profile_description text);
+
+CREATE TABLE v_sip_profile_settings (
+sip_profile_setting_uuid uuid,
+sip_profile_uuid uuid,
+sip_profile_setting_name text,
+sip_profile_setting_value text,
+sip_profile_setting_enabled text,
+sip_profile_setting_description text);
+
+CREATE TABLE v_software (
+software_name text,
+software_url text,
+software_version text);
+
+CREATE TABLE v_vars (
+var_uuid uuid PRIMARY KEY,
+var_name text,
+var_value text,
+var_cat text,
+var_enabled text,
+var_order numeric,
+var_description text);
+
+CREATE TABLE v_virtual_table_data (
+virtual_table_data_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+virtual_table_uuid uuid,
+virtual_data_row_uuid text,
+virtual_field_name text,
+virtual_data_field_value text,
+virtual_data_add_user text,
+virtual_data_add_date text,
+virtual_data_del_user text,
+virtual_data_del_date text,
+virtual_table_parent_uuid uuid,
+virtual_data_parent_row_uuid text);
+
+CREATE TABLE v_virtual_table_data_types_name_value (
+virtual_table_data_types_name_value_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+virtual_table_uuid uuid,
+virtual_table_field_uuid uuid,
+virtual_data_types_name text,
+virtual_data_types_value text);
+
+CREATE TABLE v_virtual_table_fields (
+virtual_table_field_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+virtual_table_uuid uuid,
+virtual_field_label text,
+virtual_field_name text,
+virtual_field_type text,
+virtual_field_list_hidden text,
+virtual_field_column text,
+virtual_field_required text,
+virtual_field_order numeric,
+virtual_field_order_tab numeric,
+virtual_field_description text,
+virtual_field_value text);
+
+CREATE TABLE v_virtual_tables (
+virtual_table_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+virtual_table_category text,
+virtual_table_label text,
+virtual_table_name text,
+virtual_table_auth text,
+virtual_table_captcha text,
+virtual_table_parent_uuid uuid,
+virtual_table_description text);
+
+CREATE TABLE v_voicemail_greetings (
+greeting_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+user_id text,
+greeting_name text,
+greeting_description text);
+
+CREATE TABLE v_xml_cdr (
+uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+domain_name text,
+accountcode text,
+direction text,
+default_language text,
+context text,
+xml_cdr text,
+caller_id_name text,
+caller_id_number text,
+destination_number text,
+start_epoch numeric,
+start_stamp timestamp,
+answer_stamp timestamp,
+answer_epoch numeric,
+end_epoch numeric,
+end_stamp text,
+duration numeric,
+mduration numeric,
+billsec numeric,
+billmsec numeric,
+bridge_uuid text,
+read_codec text,
+read_rate text,
+write_codec text,
+write_rate text,
+remote_media_ip text,
+network_addr text,
+recording_file text,
+leg char(1),
+pdd_ms numeric,
+last_app text,
+last_arg text,
+cc_side text,
+cc_member_uuid uuid,
+cc_queue_joined_epoch text,
+cc_queue text,
+cc_member_session_uuid uuid,
+cc_agent text,
+cc_agent_type text,
+waitsec numeric,
+conference_name text,
+conference_uuid uuid,
+conference_member_id text,
+digits_dialed text,
+hangup_cause text,
+hangup_cause_q850 numeric,
+sip_hangup_disposition text);
+
+CREATE TABLE v_xmpp (
+xmpp_profile_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+profile_name text,
+username text,
+password text,
+dialplan text,
+context text,
+rtp_ip text,
+ext_rtp_ip text,
+auto_login text,
+sasl_type text,
+xmpp_server text,
+tls_enable text,
+usr_rtp_timer text,
+default_exten text,
+vad text,
+avatar text,
+candidate_acl text,
+local_network_acl text,
+enabled text,
+description text);
+
+CREATE TABLE v_apps (
+app_uuid uuid);
+
+CREATE TABLE v_databases (
+database_uuid uuid PRIMARY KEY,
+database_type text,
+database_host text,
+database_port text,
+database_name text,
+database_username text,
+database_password text,
+database_path text,
+database_description text);
+
+CREATE TABLE v_default_settings (
+default_setting_uuid uuid PRIMARY KEY,
+default_setting_category text,
+default_setting_subcategory text,
+default_setting_name text,
+default_setting_value text,
+default_setting_enabled text,
+default_setting_description text);
+
+CREATE TABLE v_domains (
+domain_uuid uuid PRIMARY KEY,
+domain_name text,
+domain_description text);
+
+CREATE TABLE v_domain_settings (
+domain_uuid uuid,
+domain_setting_uuid uuid PRIMARY KEY,
+domain_setting_category text,
+domain_setting_subcategory text,
+domain_setting_name text,
+domain_setting_value text,
+domain_setting_enabled text,
+domain_setting_description text);
+
+CREATE TABLE v_menus (
+menu_uuid uuid PRIMARY KEY,
+menu_name text,
+menu_language text,
+menu_description text);
+
+CREATE TABLE v_menu_items (
+menu_item_uuid uuid,
+menu_uuid uuid,
+menu_item_parent_uuid uuid,
+menu_item_title text,
+menu_item_link text,
+menu_item_category text,
+menu_item_protected text,
+menu_item_order numeric,
+menu_item_description text,
+menu_item_add_user text,
+menu_item_add_date text,
+menu_item_mod_user text,
+menu_item_mod_date text);
+
+CREATE TABLE v_menu_item_groups (
+menu_uuid uuid,
+menu_item_uuid uuid,
+group_name text);
+
+CREATE TABLE v_users (
+user_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+username text,
+password text,
+salt text,
+contact_uuid uuid,
+user_status text,
+user_add_user text,
+user_add_date text);
+
+CREATE TABLE v_groups (
+group_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+group_name text,
+group_description text);
+
+CREATE TABLE v_group_users (
+group_user_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+group_name text,
+user_uuid uuid);
+
+CREATE TABLE v_group_permissions (
+group_permission_uuid uuid PRIMARY KEY,
+domain_uuid uuid,
+permission_name text,
+group_name text);
+
+CREATE TABLE v_user_settings (
+user_setting_uuid uuid PRIMARY KEY,
+user_uuid uuid,
+user_setting_category text,
+user_setting_subcategory text,
+user_setting_name text,
+user_setting_value text,
+user_setting_enabled text,
+user_setting_description text);
+EOD;
+
+$schema_sqlite = <<<EOD
+
+CREATE TABLE v_call_broadcasts (
+call_call_broadcast_uuid text PRIMARY KEY,
+domain_uuid text,
+broadcast_name text,
+broadcast_description text,
+broadcast_timeout numeric,
+broadcast_concurrent_limit numeric,
+recording_uuid text,
+broadcast_caller_id_name text,
+broadcast_caller_id_number text,
+broadcast_destination_type text,
+broadcast_phone_numbers text,
+broadcast_destination_data text);
+
+CREATE TABLE v_call_center_agents (
+call_center_agent_uuid text PRIMARY KEY,
+domain_uuid text,
+agent_name text,
+agent_type text,
+agent_call_timeout numeric,
+agent_contact text,
+agent_status text,
+agent_logout text,
+agent_max_no_answer numeric,
+agent_wrap_up_time numeric,
+agent_reject_delay_time numeric,
+agent_busy_delay_time numeric,
+agent_no_answer_delay_time text);
+
+CREATE TABLE v_call_center_logs (
+cc_uuid text PRIMARY KEY,
+domain_uuid text,
+cc_queue text,
+cc_action text,
+cc_count numeric,
+cc_agent text,
+cc_agent_system text,
+cc_agent_status text,
+cc_agent_state text,
+cc_agent_uuid text,
+cc_selection text,
+cc_cause text,
+cc_wait_time text,
+cc_talk_time text,
+cc_total_time text,
+cc_epoch numeric,
+cc_date date,
+cc_agent_type text,
+cc_member_uuid text,
+cc_member_session_uuid text,
+cc_member_cid_name text,
+cc_member_cid_number text,
+cc_agent_called_time numeric,
+cc_agent_answered_time numeric,
+cc_member_joined_time numeric,
+cc_member_leaving_time numeric,
+cc_bridge_terminated_time numeric,
+cc_hangup_cause text);
+
+CREATE TABLE v_call_center_queues (
+call_center_queue_uuid text PRIMARY KEY,
+domain_uuid text,
+dialplan_uuid text,
+queue_name text,
+queue_extension text,
+queue_strategy text,
+queue_moh_sound text,
+queue_record_template text,
+queue_time_base_score text,
+queue_max_wait_time numeric,
+queue_max_wait_time_with_no_agent numeric,
+queue_tier_rules_apply text,
+queue_tier_rule_wait_second numeric,
+queue_tier_rule_no_agent_no_wait text,
+queue_timeout_action text,
+queue_discard_abandoned_after numeric,
+queue_abandoned_resume_allowed text,
+queue_tier_rule_wait_multiply_level text,
+queue_cid_prefix text,
+queue_description text);
+
+CREATE TABLE v_call_center_tiers (
+call_center_tier_uuid text PRIMARY KEY,
+domain_uuid text,
+agent_name text,
+queue_name text,
+tier_level numeric,
+tier_position numeric);
+
+CREATE TABLE v_conferences (
+domain_uuid text,
+conference_uuid text PRIMARY KEY,
+dialplan_uuid text,
+conference_name text,
+conference_extension text,
+conference_pin_number text,
+conference_profile text,
+conference_flags text,
+conference_order numeric,
+conference_description text,
+conference_enabled text);
+
+CREATE TABLE v_conference_users (
+conference_user_uuid text PRIMARY KEY,
+domain_uuid text,
+conference_uuid text,
+user_uuid text);
+
+CREATE TABLE v_contacts (
+contact_uuid text PRIMARY KEY,
+domain_uuid text,
+contact_type text,
+contact_organization text,
+contact_name_given text,
+contact_name_family text,
+contact_nickname text,
+contact_title text,
+contact_role text,
+contact_email text,
+contact_url text,
+contact_time_zone text,
+contact_note text);
+
+CREATE TABLE v_contact_addresses (
+contact_address_uuid text PRIMARY KEY,
+domain_uuid text,
+contact_uuid text,
+address_type text,
+address_street text,
+address_extended text,
+address_locality text,
+address_region text,
+address_postal_code text,
+address_country text,
+address_latitude text,
+address_longitude text);
+
+CREATE TABLE v_contact_phones (
+contact_phone_uuid text PRIMARY KEY,
+domain_uuid text,
+contact_uuid text,
+phone_type text,
+phone_number text);
+
+CREATE TABLE v_contact_notes (
+contact_note_uuid text PRIMARY KEY,
+domain_uuid text,
+contact_uuid text,
+contact_note text,
+last_mod_date text,
+last_mod_user text);
+
+CREATE TABLE v_rss (
+rss_uuid text PRIMARY KEY,
+domain_uuid text,
+rss_language text,
+rss_category text,
+rss_sub_category text,
+rss_title text,
+rss_link text,
+rss_description text,
+rss_img blob,
+rss_optional_1 text,
+rss_optional_2 text,
+rss_optional_3 text,
+rss_optional_4 text,
+rss_optional_5 text,
+rss_add_date text,
+rss_add_user text,
+rss_del_date text,
+rss_del_user text,
+rss_order numeric,
+rss_content text,
+rss_group text);
+
+CREATE TABLE v_rss_sub (
+rss_sub_uuid text PRIMARY KEY,
+domain_uuid text,
+rss_uuid text,
+rss_sub_language text,
+rss_sub_title text,
+rss_sub_link text,
+rss_sub_description text,
+rss_sub_optional_1 text,
+rss_sub_optional_2 text,
+rss_sub_optional_3 text,
+rss_sub_optional_4 text,
+rss_sub_optional_5 text,
+rss_sub_add_date text,
+rss_sub_add_user text,
+rss_sub_del_user text,
+rss_sub_del_date text);
+
+CREATE TABLE v_rss_sub_category (
+rss_sub_category_uuid text PRIMARY KEY,
+domain_uuid text,
+rss_sub_category_language text,
+rss_category text,
+rss_sub_category text,
+rss_sub_category_description text,
+rss_sub_add_user text,
+rss_sub_add_date text);
+
+CREATE TABLE v_destinations (
+domain_uuid text,
+destination_uuid text PRIMARY KEY,
+destination_name text,
+destination_context text,
+destination_extension text,
+destination_enabled text,
+destination_description text);
+
+CREATE TABLE v_dialplans (
+domain_uuid text,
+dialplan_uuid text PRIMARY KEY,
+app_uuid text,
+dialplan_context text,
+dialplan_name text,
+dialplan_number text,
+dialplan_continue text,
+dialplan_order numeric,
+dialplan_enabled text,
+dialplan_description text);
+
+CREATE TABLE v_dialplan_details (
+domain_uuid text,
+dialplan_uuid text,
+dialplan_detail_uuid text PRIMARY KEY,
+dialplan_detail_tag text,
+dialplan_detail_type text,
+dialplan_detail_data text,
+dialplan_detail_break text,
+dialplan_detail_inline text,
+dialplan_detail_group numeric,
+dialplan_detail_order numeric);
+
+CREATE TABLE v_extensions (
+extension_uuid text PRIMARY KEY,
+domain_uuid text,
+extension text,
+number_alias text,
+password text,
+provisioning_list text,
+mailbox text,
+vm_password text,
+accountcode text,
+effective_caller_id_name text,
+effective_caller_id_number text,
+outbound_caller_id_name text,
+outbound_caller_id_number text,
+emergency_caller_id_number text,
+directory_full_name text,
+directory_visible text,
+directory_exten_visible text,
+limit_max numeric,
+limit_destination text,
+vm_enabled text,
+vm_mailto text,
+vm_attach_file text,
+vm_keep_local_after_email text,
+user_context text,
+toll_allow text,
+call_group text,
+hold_music text,
+auth_acl text,
+cidr text,
+sip_force_contact text,
+nibble_account numeric,
+sip_force_expires numeric,
+enabled text,
+description text,
+mwi_account text,
+sip_bypass_media text);
+
+CREATE TABLE v_extension_users (
+extension_user_uuid text PRIMARY KEY,
+domain_uuid text,
+extension_uuid text,
+user_uuid text);
+
+CREATE TABLE v_fax (
+fax_uuid text PRIMARY KEY,
+domain_uuid text,
+dialplan_uuid text,
+fax_extension text,
+fax_name text,
+fax_email text,
+fax_pin_number text,
+fax_caller_id_name text,
+fax_caller_id_number text,
+fax_forward_number numeric,
+fax_description text);
+
+CREATE TABLE v_fax_users (
+fax_user_uuid text PRIMARY KEY,
+domain_uuid text,
+fax_uuid text,
+user_uuid text);
+
+CREATE TABLE v_gateways (
+gateway_uuid text PRIMARY KEY,
+domain_uuid text,
+gateway text,
+username text,
+password text,
+distinct_to text,
+auth_username text,
+realm text,
+from_user text,
+from_domain text,
+proxy text,
+register_proxy text,
+outbound_proxy text,
+expire_seconds numeric,
+register text,
+register_transport text,
+retry_seconds numeric,
+extension text,
+ping text,
+caller_id_in_from text,
+supress_cng text,
+sip_cid_type text,
+extension_in_contact text,
+context text,
+profile text,
+enabled text,
+description text);
+
+CREATE TABLE v_hardware_phones (
+hardware_phone_uuid text PRIMARY KEY,
+domain_uuid text,
+phone_mac_address text,
+phone_label text,
+phone_vendor text,
+phone_model text,
+phone_firmware_version text,
+phone_provision_enable text,
+phone_template text,
+phone_username text,
+phone_password text,
+phone_time_zone text,
+phone_description text);
+
+CREATE TABLE v_hunt_groups (
+hunt_group_uuid text PRIMARY KEY,
+domain_uuid text,
+dialplan_uuid text,
+hunt_group_extension text,
+hunt_group_name text,
+hunt_group_type text,
+hunt_group_context text,
+hunt_group_timeout text,
+hunt_group_timeout_destination text,
+hunt_group_timeout_type text,
+hunt_group_ringback text,
+hunt_group_cid_name_prefix text,
+hunt_group_pin text,
+hunt_group_caller_announce text,
+hunt_group_call_prompt text,
+hunt_group_user_list text,
+hunt_group_enabled text,
+hunt_group_description text);
+
+CREATE TABLE v_hunt_group_destinations (
+hunt_group_destination_uuid text PRIMARY KEY,
+domain_uuid text,
+hunt_group_uuid text,
+destination_data text,
+destination_type text,
+destination_profile text,
+destination_timeout text,
+destination_order numeric,
+destination_enabled text,
+destination_description text);
+
+CREATE TABLE v_hunt_group_users (
+hunt_group_user_uuid text PRIMARY KEY,
+domain_uuid text,
+hunt_group_uuid text,
+user_uuid text);
+
+CREATE TABLE v_invoices (
+invoice_uuid text,
+domain_uuid text,
+contact_uuid_from text,
+contact_uuid_to text,
+invoice_number numeric,
+invoice_date datetime,
+invoice_notes text);
+
+CREATE TABLE v_invoice_items (
+invoice_item_uuid text,
+domain_uuid text,
+invoice_uuid text,
+item_qty numeric,
+item_desc text,
+item_unit_price numeric);
+
+CREATE TABLE v_ivr_menus (
+ivr_menu_uuid text PRIMARY KEY,
+domain_uuid text,
+dialplan_uuid text,
+ivr_menu_name text,
+ivr_menu_extension numeric,
+ivr_menu_greet_long text,
+ivr_menu_greet_short text,
+ivr_menu_invalid_sound text,
+ivr_menu_exit_sound text,
+ivr_menu_confirm_macro text,
+ivr_menu_confirm_key text,
+ivr_menu_tts_engine text,
+ivr_menu_tts_voice text,
+ivr_menu_confirm_attempts numeric,
+ivr_menu_timeout numeric,
+ivr_menu_exit_app text,
+ivr_menu_exit_data text,
+ivr_menu_inter_digit_timeout numeric,
+ivr_menu_max_failures numeric,
+ivr_menu_max_timeouts numeric,
+ivr_menu_digit_len numeric,
+ivr_menu_direct_dial text,
+ivr_menu_enabled text,
+ivr_menu_description text);
+
+CREATE TABLE v_ivr_menu_options (
+ivr_menu_option_uuid text PRIMARY KEY,
+ivr_menu_uuid text,
+domain_uuid text,
+ivr_menu_option_digits text,
+ivr_menu_option_action text,
+ivr_menu_option_param text,
+ivr_menu_option_order numeric,
+ivr_menu_option_description text);
+
+CREATE TABLE v_modules (
+module_uuid text PRIMARY KEY,
+module_label text,
+module_name text,
+module_category text,
+module_enabled text,
+module_default_enabled text,
+module_description text);
+
+CREATE TABLE v_clips (
+clip_uuid text PRIMARY KEY,
+clip_name text,
+clip_folder text,
+clip_text_start text,
+clip_text_end text,
+clip_order text,
+clip_desc text);
+
+CREATE TABLE v_php_services (
+php_service_uuid text PRIMARY KEY,
+domain_uuid text,
+service_name text,
+service_script text,
+service_enabled text,
+service_description text);
+
+CREATE TABLE v_recordings (
+recording_uuid text PRIMARY KEY,
+domain_uuid text,
+recording_filename text,
+recording_name text,
+recording_description text);
+
+CREATE TABLE v_ring_groups (
+domain_uuid text,
+ring_group_uuid text,
+ring_group_name text,
+ring_group_extension text,
+ring_group_context text,
+ring_group_strategy text,
+ring_group_timeout_sec numeric,
+ring_group_timeout_app text,
+ring_group_timeout_data text,
+ring_group_enabled text,
+ring_group_description text,
+dialplan_uuid text);
+
+CREATE TABLE v_ring_group_extensions (
+ring_group_extension_uuid text,
+domain_uuid text,
+ring_group_uuid text,
+extension_uuid text);
+
+CREATE TABLE v_services (
+service_uuid text PRIMARY KEY,
+domain_uuid text,
+service_name text,
+service_type text,
+service_data text,
+service_cmd_start text,
+service_cmd_stop text,
+service_cmd_restart text,
+service_description text);
+
+CREATE TABLE v_settings (
+numbering_plan text,
+event_socket_ip_address text,
+event_socket_port text,
+event_socket_password text,
+xml_rpc_http_port text,
+xml_rpc_auth_realm text,
+xml_rpc_auth_user text,
+xml_rpc_auth_pass text,
+admin_pin numeric,
+smtp_host text,
+smtp_secure text,
+smtp_auth text,
+smtp_username text,
+smtp_password text,
+smtp_from text,
+smtp_from_name text,
+mod_shout_decoder text,
+mod_shout_volume text);
+
+CREATE TABLE v_sip_profiles (
+sip_profile_uuid text,
+sip_profile_name text,
+sip_profile_description text);
+
+CREATE TABLE v_sip_profile_settings (
+sip_profile_setting_uuid text,
+sip_profile_uuid text,
+sip_profile_setting_name text,
+sip_profile_setting_value text,
+sip_profile_setting_enabled text,
+sip_profile_setting_description text);
+
+CREATE TABLE v_software (
+software_name text,
+software_url text,
+software_version text);
+
+CREATE TABLE v_vars (
+var_uuid text PRIMARY KEY,
+var_name text,
+var_value text,
+var_cat text,
+var_enabled text,
+var_order numeric,
+var_description text);
+
+CREATE TABLE v_virtual_table_data (
+virtual_table_data_uuid text PRIMARY KEY,
+domain_uuid text,
+virtual_table_uuid text,
+virtual_data_row_uuid text,
+virtual_field_name text,
+virtual_data_field_value text,
+virtual_data_add_user text,
+virtual_data_add_date text,
+virtual_data_del_user text,
+virtual_data_del_date text,
+virtual_table_parent_uuid text,
+virtual_data_parent_row_uuid text);
+
+CREATE TABLE v_virtual_table_data_types_name_value (
+virtual_table_data_types_name_value_uuid text PRIMARY KEY,
+domain_uuid text,
+virtual_table_uuid text,
+virtual_table_field_uuid text,
+virtual_data_types_name text,
+virtual_data_types_value text);
+
+CREATE TABLE v_virtual_table_fields (
+virtual_table_field_uuid text PRIMARY KEY,
+domain_uuid text,
+virtual_table_uuid text,
+virtual_field_label text,
+virtual_field_name text,
+virtual_field_type text,
+virtual_field_list_hidden text,
+virtual_field_column text,
+virtual_field_required text,
+virtual_field_order numeric,
+virtual_field_order_tab numeric,
+virtual_field_description text,
+virtual_field_value text);
+
+CREATE TABLE v_virtual_tables (
+virtual_table_uuid text PRIMARY KEY,
+domain_uuid text,
+virtual_table_category text,
+virtual_table_label text,
+virtual_table_name text,
+virtual_table_auth text,
+virtual_table_captcha text,
+virtual_table_parent_uuid text,
+virtual_table_description text);
+
+CREATE TABLE v_voicemail_greetings (
+greeting_uuid text PRIMARY KEY,
+domain_uuid text,
+user_id text,
+greeting_name text,
+greeting_description text);
+
+CREATE TABLE v_xml_cdr (
+uuid text PRIMARY KEY,
+domain_uuid text,
+domain_name text,
+accountcode text,
+direction text,
+default_language text,
+context text,
+xml_cdr text,
+caller_id_name text,
+caller_id_number text,
+destination_number text,
+start_epoch numeric,
+start_stamp date,
+answer_stamp date,
+answer_epoch numeric,
+end_epoch numeric,
+end_stamp text,
+duration numeric,
+mduration numeric,
+billsec numeric,
+billmsec numeric,
+bridge_uuid text,
+read_codec text,
+read_rate text,
+write_codec text,
+write_rate text,
+remote_media_ip text,
+network_addr text,
+recording_file text,
+leg text,
+pdd_ms numeric,
+last_app text,
+last_arg text,
+cc_side text,
+cc_member_uuid text,
+cc_queue_joined_epoch text,
+cc_queue text,
+cc_member_session_uuid text,
+cc_agent text,
+cc_agent_type text,
+waitsec numeric,
+conference_name text,
+conference_uuid text,
+conference_member_id text,
+digits_dialed text,
+hangup_cause text,
+hangup_cause_q850 numeric,
+sip_hangup_disposition text);
+
+CREATE TABLE v_xmpp (
+xmpp_profile_uuid text PRIMARY KEY,
+domain_uuid text,
+profile_name text,
+username text,
+password text,
+dialplan text,
+context text,
+rtp_ip text,
+ext_rtp_ip text,
+auto_login text,
+sasl_type text,
+xmpp_server text,
+tls_enable text,
+usr_rtp_timer text,
+default_exten text,
+vad text,
+avatar text,
+candidate_acl text,
+local_network_acl text,
+enabled text,
+description text);
+
+CREATE TABLE v_apps (
+app_uuid text);
+
+CREATE TABLE v_databases (
+database_uuid text PRIMARY KEY,
+database_type text,
+database_host text,
+database_port text,
+database_name text,
+database_username text,
+database_password text,
+database_path text,
+database_description text);
+
+CREATE TABLE v_default_settings (
+default_setting_uuid text PRIMARY KEY,
+default_setting_category text,
+default_setting_subcategory text,
+default_setting_name text,
+default_setting_value text,
+default_setting_enabled text,
+default_setting_description text);
+
+CREATE TABLE v_domains (
+domain_uuid text PRIMARY KEY,
+domain_name text,
+domain_description text);
+
+CREATE TABLE v_domain_settings (
+domain_uuid text,
+domain_setting_uuid text PRIMARY KEY,
+domain_setting_category text,
+domain_setting_subcategory text,
+domain_setting_name text,
+domain_setting_value text,
+domain_setting_enabled text,
+domain_setting_description text);
+
+CREATE TABLE v_menus (
+menu_uuid text PRIMARY KEY,
+menu_name text,
+menu_language text,
+menu_description text);
+
+CREATE TABLE v_menu_items (
+menu_item_uuid text,
+menu_uuid text,
+menu_item_parent_uuid text,
+menu_item_title text,
+menu_item_link text,
+menu_item_category text,
+menu_item_protected text,
+menu_item_order numeric,
+menu_item_description text,
+menu_item_add_user text,
+menu_item_add_date text,
+menu_item_mod_user text,
+menu_item_mod_date text);
+
+CREATE TABLE v_menu_item_groups (
+menu_uuid text,
+menu_item_uuid text,
+group_name text);
+
+CREATE TABLE v_users (
+user_uuid text PRIMARY KEY,
+domain_uuid text,
+username text,
+password text,
+salt text,
+contact_uuid text,
+user_status text,
+user_add_user text,
+user_add_date text);
+
+CREATE TABLE v_groups (
+group_uuid text PRIMARY KEY,
+domain_uuid text,
+group_name text,
+group_description text);
+
+CREATE TABLE v_group_users (
+group_user_uuid text PRIMARY KEY,
+domain_uuid text,
+group_name text,
+user_uuid text);
+
+CREATE TABLE v_group_permissions (
+group_permission_uuid text PRIMARY KEY,
+domain_uuid text,
+permission_name text,
+group_name text);
+
+CREATE TABLE v_user_settings (
+user_setting_uuid text PRIMARY KEY,
+user_uuid text,
+user_setting_category text,
+user_setting_subcategory text,
+user_setting_name text,
+user_setting_value text,
+user_setting_enabled text,
+user_setting_description text);
+EOD;
+
+$schema_mysql = <<<EOD
+CREATE TABLE v_call_broadcasts (
+call_call_broadcast_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+broadcast_name text,
+broadcast_description text,
+broadcast_timeout numeric,
+broadcast_concurrent_limit numeric,
+recording_uuid char(36),
+broadcast_caller_id_name text,
+broadcast_caller_id_number text,
+broadcast_destination_type text,
+broadcast_phone_numbers text,
+broadcast_destination_data text) ENGINE=INNODB;
+
+CREATE TABLE v_call_center_agents (
+call_center_agent_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+agent_name text,
+agent_type text,
+agent_call_timeout numeric,
+agent_contact text,
+agent_status text,
+agent_logout text,
+agent_max_no_answer numeric,
+agent_wrap_up_time numeric,
+agent_reject_delay_time numeric,
+agent_busy_delay_time numeric,
+agent_no_answer_delay_time text) ENGINE=INNODB;
+
+CREATE TABLE v_call_center_logs (
+cc_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+cc_queue text,
+cc_action text,
+cc_count numeric,
+cc_agent text,
+cc_agent_system text,
+cc_agent_status text,
+cc_agent_state text,
+cc_agent_uuid char(36),
+cc_selection text,
+cc_cause text,
+cc_wait_time text,
+cc_talk_time text,
+cc_total_time text,
+cc_epoch numeric,
+cc_date timestamp,
+cc_agent_type text,
+cc_member_uuid text,
+cc_member_session_uuid text,
+cc_member_cid_name text,
+cc_member_cid_number text,
+cc_agent_called_time numeric,
+cc_agent_answered_time numeric,
+cc_member_joined_time numeric,
+cc_member_leaving_time numeric,
+cc_bridge_terminated_time numeric,
+cc_hangup_cause text) ENGINE=INNODB;
+
+CREATE TABLE v_call_center_queues (
+call_center_queue_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+dialplan_uuid char(36),
+queue_name text,
+queue_extension text,
+queue_strategy text,
+queue_moh_sound text,
+queue_record_template text,
+queue_time_base_score text,
+queue_max_wait_time numeric,
+queue_max_wait_time_with_no_agent numeric,
+queue_tier_rules_apply text,
+queue_tier_rule_wait_second numeric,
+queue_tier_rule_no_agent_no_wait text,
+queue_timeout_action text,
+queue_discard_abandoned_after numeric,
+queue_abandoned_resume_allowed text,
+queue_tier_rule_wait_multiply_level text,
+queue_cid_prefix text,
+queue_description text) ENGINE=INNODB;
+
+CREATE TABLE v_call_center_tiers (
+call_center_tier_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+agent_name text,
+queue_name text,
+tier_level numeric,
+tier_position numeric) ENGINE=INNODB;
+
+CREATE TABLE v_conferences (
+domain_uuid char(36),
+conference_uuid char(36) PRIMARY KEY,
+dialplan_uuid char(36),
+conference_name text,
+conference_extension text,
+conference_pin_number text,
+conference_profile text,
+conference_flags text,
+conference_order numeric,
+conference_description text,
+conference_enabled text) ENGINE=INNODB;
+
+CREATE TABLE v_conference_users (
+conference_user_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+conference_uuid char(36),
+user_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_contacts (
+contact_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+contact_type text,
+contact_organization text,
+contact_name_given text,
+contact_name_family text,
+contact_nickname text,
+contact_title text,
+contact_role text,
+contact_email text,
+contact_url text,
+contact_time_zone text,
+contact_note text) ENGINE=INNODB;
+
+CREATE TABLE v_contact_addresses (
+contact_address_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+contact_uuid char(36),
+address_type text,
+address_street text,
+address_extended text,
+address_locality text,
+address_region text,
+address_postal_code text,
+address_country text,
+address_latitude text,
+address_longitude text) ENGINE=INNODB;
+
+CREATE TABLE v_contact_phones (
+contact_phone_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+contact_uuid char(36),
+phone_type text,
+phone_number text) ENGINE=INNODB;
+
+CREATE TABLE v_contact_notes (
+contact_note_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+contact_uuid char(36),
+contact_note text,
+last_mod_date text,
+last_mod_user text) ENGINE=INNODB;
+
+CREATE TABLE v_rss (
+rss_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+rss_language text,
+rss_category text,
+rss_sub_category text,
+rss_title text,
+rss_link text,
+rss_description text,
+rss_img blob,
+rss_optional_1 text,
+rss_optional_2 text,
+rss_optional_3 text,
+rss_optional_4 text,
+rss_optional_5 text,
+rss_add_date text,
+rss_add_user text,
+rss_del_date text,
+rss_del_user text,
+rss_order numeric,
+rss_content text,
+rss_group text) ENGINE=INNODB;
+
+CREATE TABLE v_rss_sub (
+rss_sub_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+rss_uuid char(36),
+rss_sub_language text,
+rss_sub_title text,
+rss_sub_link text,
+rss_sub_description text,
+rss_sub_optional_1 text,
+rss_sub_optional_2 text,
+rss_sub_optional_3 text,
+rss_sub_optional_4 text,
+rss_sub_optional_5 text,
+rss_sub_add_date text,
+rss_sub_add_user text,
+rss_sub_del_user text,
+rss_sub_del_date text) ENGINE=INNODB;
+
+CREATE TABLE v_rss_sub_category (
+rss_sub_category_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+rss_sub_category_language text,
+rss_category text,
+rss_sub_category text,
+rss_sub_category_description text,
+rss_sub_add_user text,
+rss_sub_add_date text) ENGINE=INNODB;
+
+CREATE TABLE v_destinations (
+domain_uuid char(36),
+destination_uuid char(36) PRIMARY KEY,
+destination_name text,
+destination_context text,
+destination_extension text,
+destination_enabled text,
+destination_description text) ENGINE=INNODB;
+
+CREATE TABLE v_dialplans (
+domain_uuid char(36),
+dialplan_uuid char(36) PRIMARY KEY,
+app_uuid char(36),
+dialplan_context text,
+dialplan_name text,
+dialplan_number text,
+dialplan_continue text,
+dialplan_order numeric,
+dialplan_enabled text,
+dialplan_description text) ENGINE=INNODB;
+
+CREATE TABLE v_dialplan_details (
+domain_uuid char(36),
+dialplan_uuid char(36),
+dialplan_detail_uuid char(36) PRIMARY KEY,
+dialplan_detail_tag text,
+dialplan_detail_type text,
+dialplan_detail_data text,
+dialplan_detail_break text,
+dialplan_detail_inline text,
+dialplan_detail_group numeric,
+dialplan_detail_order numeric) ENGINE=INNODB;
+
+CREATE TABLE v_extensions (
+extension_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+extension text,
+number_alias text,
+password text,
+provisioning_list text,
+mailbox text,
+vm_password text,
+accountcode text,
+effective_caller_id_name text,
+effective_caller_id_number text,
+outbound_caller_id_name text,
+outbound_caller_id_number text,
+emergency_caller_id_number text,
+directory_full_name text,
+directory_visible text,
+directory_exten_visible text,
+limit_max numeric,
+limit_destination text,
+vm_enabled text,
+vm_mailto text,
+vm_attach_file text,
+vm_keep_local_after_email text,
+user_context text,
+toll_allow text,
+call_group text,
+hold_music text,
+auth_acl text,
+cidr text,
+sip_force_contact text,
+nibble_account numeric,
+sip_force_expires numeric,
+enabled text,
+description text,
+mwi_account text,
+sip_bypass_media text) ENGINE=INNODB;
+
+CREATE TABLE v_extension_users (
+extension_user_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+extension_uuid char(36),
+user_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_fax (
+fax_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+dialplan_uuid char(36),
+fax_extension text,
+fax_name text,
+fax_email text,
+fax_pin_number text,
+fax_caller_id_name text,
+fax_caller_id_number text,
+fax_forward_number numeric,
+fax_description text) ENGINE=INNODB;
+
+CREATE TABLE v_fax_users (
+fax_user_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+fax_uuid char(36),
+user_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_gateways (
+gateway_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+gateway text,
+username text,
+password text,
+distinct_to text,
+auth_username text,
+realm text,
+from_user text,
+from_domain text,
+proxy text,
+register_proxy text,
+outbound_proxy text,
+expire_seconds numeric,
+register text,
+register_transport text,
+retry_seconds numeric,
+extension text,
+ping text,
+caller_id_in_from text,
+supress_cng text,
+sip_cid_type text,
+extension_in_contact text,
+context text,
+profile text,
+enabled text,
+description text) ENGINE=INNODB;
+
+CREATE TABLE v_hardware_phones (
+hardware_phone_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+phone_mac_address text,
+phone_label text,
+phone_vendor text,
+phone_model text,
+phone_firmware_version text,
+phone_provision_enable text,
+phone_template text,
+phone_username text,
+phone_password text,
+phone_time_zone text,
+phone_description text) ENGINE=INNODB;
+
+CREATE TABLE v_hunt_groups (
+hunt_group_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+dialplan_uuid char(36),
+hunt_group_extension text,
+hunt_group_name text,
+hunt_group_type text,
+hunt_group_context text,
+hunt_group_timeout text,
+hunt_group_timeout_destination text,
+hunt_group_timeout_type text,
+hunt_group_ringback text,
+hunt_group_cid_name_prefix text,
+hunt_group_pin text,
+hunt_group_caller_announce text,
+hunt_group_call_prompt text,
+hunt_group_user_list text,
+hunt_group_enabled text,
+hunt_group_description text) ENGINE=INNODB;
+
+CREATE TABLE v_hunt_group_destinations (
+hunt_group_destination_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+hunt_group_uuid char(36),
+destination_data text,
+destination_type text,
+destination_profile text,
+destination_timeout text,
+destination_order numeric,
+destination_enabled text,
+destination_description text) ENGINE=INNODB;
+
+CREATE TABLE v_hunt_group_users (
+hunt_group_user_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+hunt_group_uuid char(36),
+user_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_invoices (
+invoice_uuid char(36),
+domain_uuid char(36),
+contact_uuid_from char(36),
+contact_uuid_to char(36),
+invoice_number numeric,
+invoice_date timestamp,
+invoice_notes text) ENGINE=INNODB;
+
+CREATE TABLE v_invoice_items (
+invoice_item_uuid char(36),
+domain_uuid char(36),
+invoice_uuid char(36),
+item_qty numeric,
+item_desc text,
+item_unit_price decimal(10,2)) ENGINE=INNODB;
+
+CREATE TABLE v_ivr_menus (
+ivr_menu_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+dialplan_uuid char(36),
+ivr_menu_name text,
+ivr_menu_extension numeric,
+ivr_menu_greet_long text,
+ivr_menu_greet_short text,
+ivr_menu_invalid_sound text,
+ivr_menu_exit_sound text,
+ivr_menu_confirm_macro text,
+ivr_menu_confirm_key text,
+ivr_menu_tts_engine text,
+ivr_menu_tts_voice text,
+ivr_menu_confirm_attempts numeric,
+ivr_menu_timeout numeric,
+ivr_menu_exit_app text,
+ivr_menu_exit_data text,
+ivr_menu_inter_digit_timeout numeric,
+ivr_menu_max_failures numeric,
+ivr_menu_max_timeouts numeric,
+ivr_menu_digit_len numeric,
+ivr_menu_direct_dial text,
+ivr_menu_enabled text,
+ivr_menu_description text) ENGINE=INNODB;
+
+CREATE TABLE v_ivr_menu_options (
+ivr_menu_option_uuid char(36) PRIMARY KEY,
+ivr_menu_uuid char(36),
+domain_uuid char(36),
+ivr_menu_option_digits text,
+ivr_menu_option_action text,
+ivr_menu_option_param text,
+ivr_menu_option_order numeric,
+ivr_menu_option_description text) ENGINE=INNODB;
+
+CREATE TABLE v_modules (
+module_uuid char(36) PRIMARY KEY,
+module_label text,
+module_name text,
+module_category text,
+module_enabled text,
+module_default_enabled text,
+module_description text) ENGINE=INNODB;
+
+CREATE TABLE v_clips (
+clip_uuid char(36) PRIMARY KEY,
+clip_name text,
+clip_folder text,
+clip_text_start text,
+clip_text_end text,
+clip_order text,
+clip_desc text) ENGINE=INNODB;
+
+CREATE TABLE v_php_services (
+php_service_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+service_name text,
+service_script text,
+service_enabled text,
+service_description text) ENGINE=INNODB;
+
+CREATE TABLE v_recordings (
+recording_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+recording_filename text,
+recording_name text,
+recording_description text) ENGINE=INNODB;
+
+CREATE TABLE v_ring_groups (
+domain_uuid char(36),
+ring_group_uuid char(36),
+ring_group_name text,
+ring_group_extension text,
+ring_group_context text,
+ring_group_strategy text,
+ring_group_timeout_sec numeric,
+ring_group_timeout_app text,
+ring_group_timeout_data text,
+ring_group_enabled text,
+ring_group_description text,
+dialplan_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_ring_group_extensions (
+ring_group_extension_uuid char(36),
+domain_uuid char(36),
+ring_group_uuid char(36),
+extension_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_services (
+service_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+service_name text,
+service_type text,
+service_data text,
+service_cmd_start text,
+service_cmd_stop text,
+service_cmd_restart text,
+service_description text) ENGINE=INNODB;
+
+CREATE TABLE v_settings (
+numbering_plan text,
+event_socket_ip_address text,
+event_socket_port text,
+event_socket_password text,
+xml_rpc_http_port text,
+xml_rpc_auth_realm text,
+xml_rpc_auth_user text,
+xml_rpc_auth_pass text,
+admin_pin numeric,
+smtp_host text,
+smtp_secure text,
+smtp_auth text,
+smtp_username text,
+smtp_password text,
+smtp_from text,
+smtp_from_name text,
+mod_shout_decoder text,
+mod_shout_volume text) ENGINE=INNODB;
+
+CREATE TABLE v_sip_profiles (
+sip_profile_uuid char(36),
+sip_profile_name text,
+sip_profile_description text) ENGINE=INNODB;
+
+CREATE TABLE v_sip_profile_settings (
+sip_profile_setting_uuid char(36),
+sip_profile_uuid char(36),
+sip_profile_setting_name text,
+sip_profile_setting_value text,
+sip_profile_setting_enabled text,
+sip_profile_setting_description text) ENGINE=INNODB;
+
+CREATE TABLE v_software (
+software_name text,
+software_url text,
+software_version text) ENGINE=INNODB;
+
+CREATE TABLE v_vars (
+var_uuid char(36) PRIMARY KEY,
+var_name text,
+var_value text,
+var_cat text,
+var_enabled text,
+var_order numeric,
+var_description text) ENGINE=INNODB;
+
+CREATE TABLE v_virtual_table_data (
+virtual_table_data_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+virtual_table_uuid char(36),
+virtual_data_row_uuid text,
+virtual_field_name text,
+virtual_data_field_value text,
+virtual_data_add_user text,
+virtual_data_add_date text,
+virtual_data_del_user text,
+virtual_data_del_date text,
+virtual_table_parent_uuid char(36),
+virtual_data_parent_row_uuid text) ENGINE=INNODB;
+
+CREATE TABLE v_virtual_table_data_types_name_value (
+virtual_table_data_types_name_value_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+virtual_table_uuid char(36),
+virtual_table_field_uuid char(36),
+virtual_data_types_name text,
+virtual_data_types_value text) ENGINE=INNODB;
+
+CREATE TABLE v_virtual_table_fields (
+virtual_table_field_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+virtual_table_uuid char(36),
+virtual_field_label text,
+virtual_field_name text,
+virtual_field_type text,
+virtual_field_list_hidden text,
+virtual_field_column text,
+virtual_field_required text,
+virtual_field_order numeric,
+virtual_field_order_tab numeric,
+virtual_field_description text,
+virtual_field_value text) ENGINE=INNODB;
+
+CREATE TABLE v_virtual_tables (
+virtual_table_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+virtual_table_category text,
+virtual_table_label text,
+virtual_table_name text,
+virtual_table_auth text,
+virtual_table_captcha text,
+virtual_table_parent_uuid char(36),
+virtual_table_description text) ENGINE=INNODB;
+
+CREATE TABLE v_voicemail_greetings (
+greeting_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+user_id text,
+greeting_name text,
+greeting_description text) ENGINE=INNODB;
+
+CREATE TABLE v_xml_cdr (
+uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+domain_name text,
+accountcode text,
+direction text,
+default_language text,
+context text,
+xml_cdr text,
+caller_id_name text,
+caller_id_number text,
+destination_number text,
+start_epoch bigint,
+start_stamp timestamp,
+answer_stamp timestamp,
+answer_epoch bigint,
+end_epoch bigint,
+end_stamp text,
+duration numeric,
+mduration numeric,
+billsec numeric,
+billmsec numeric,
+bridge_uuid text,
+read_codec text,
+read_rate text,
+write_codec text,
+write_rate text,
+remote_media_ip text,
+network_addr text,
+recording_file text,
+leg char(1),
+pdd_ms smallint,
+last_app text,
+last_arg text,
+cc_side text,
+cc_member_uuid char(36),
+cc_queue_joined_epoch text,
+cc_queue text,
+cc_member_session_uuid char(36),
+cc_agent text,
+cc_agent_type text,
+waitsec numeric,
+conference_name text,
+conference_uuid char(36),
+conference_member_id text,
+digits_dialed text,
+hangup_cause text,
+hangup_cause_q850 numeric,
+sip_hangup_disposition text) ENGINE=INNODB;
+
+CREATE TABLE v_xmpp (
+xmpp_profile_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+profile_name text,
+username text,
+password text,
+dialplan text,
+context text,
+rtp_ip text,
+ext_rtp_ip text,
+auto_login text,
+sasl_type text,
+xmpp_server text,
+tls_enable text,
+usr_rtp_timer text,
+default_exten text,
+vad text,
+avatar text,
+candidate_acl text,
+local_network_acl text,
+enabled text,
+description text) ENGINE=INNODB;
+
+CREATE TABLE v_apps (
+app_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_databases (
+database_uuid char(36) PRIMARY KEY,
+database_type text,
+database_host text,
+database_port text,
+database_name text,
+database_username text,
+database_password text,
+database_path text,
+database_description text) ENGINE=INNODB;
+
+CREATE TABLE v_default_settings (
+default_setting_uuid char(36) PRIMARY KEY,
+default_setting_category text,
+default_setting_subcategory text,
+default_setting_name text,
+default_setting_value text,
+default_setting_enabled text,
+default_setting_description text) ENGINE=INNODB;
+
+CREATE TABLE v_domains (
+domain_uuid char(36) PRIMARY KEY,
+domain_name text,
+domain_description text) ENGINE=INNODB;
+
+CREATE TABLE v_domain_settings (
+domain_uuid char(36),
+domain_setting_uuid char(36) PRIMARY KEY,
+domain_setting_category text,
+domain_setting_subcategory text,
+domain_setting_name text,
+domain_setting_value text,
+domain_setting_enabled text,
+domain_setting_description text) ENGINE=INNODB;
+
+CREATE TABLE v_menus (
+menu_uuid char(36) PRIMARY KEY,
+menu_name text,
+menu_language text,
+menu_description text) ENGINE=INNODB;
+
+CREATE TABLE v_menu_items (
+menu_item_uuid char(36),
+menu_uuid char(36),
+menu_item_parent_uuid char(36),
+menu_item_title text,
+menu_item_link text,
+menu_item_category text,
+menu_item_protected text,
+menu_item_order numeric,
+menu_item_description text,
+menu_item_add_user text,
+menu_item_add_date text,
+menu_item_mod_user text,
+menu_item_mod_date text) ENGINE=INNODB;
+
+CREATE TABLE v_menu_item_groups (
+menu_uuid char(36),
+menu_item_uuid char(36),
+group_name text) ENGINE=INNODB;
+
+CREATE TABLE v_users (
+user_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+username text,
+password text,
+salt text,
+contact_uuid char(36),
+user_status text,
+user_add_user text,
+user_add_date text) ENGINE=INNODB;
+
+CREATE TABLE v_groups (
+group_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+group_name text,
+group_description text) ENGINE=INNODB;
+
+CREATE TABLE v_group_users (
+group_user_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+group_name text,
+user_uuid char(36)) ENGINE=INNODB;
+
+CREATE TABLE v_group_permissions (
+group_permission_uuid char(36) PRIMARY KEY,
+domain_uuid char(36),
+permission_name text,
+group_name text) ENGINE=INNODB;
+
+CREATE TABLE v_user_settings (
+user_setting_uuid char(36) PRIMARY KEY,
+user_uuid char(36),
+user_setting_category text,
+user_setting_subcategory text,
+user_setting_name text,
+user_setting_value text,
+user_setting_enabled text,
+user_setting_description text) ENGINE=INNODB;
+EOD;
+
+//add the create table statements
+	if ($db_type == "pgsql") {
+		echo $schema_pgsql."\n";
+	}
+	if ($db_type == "sqlite") {
+		echo $schema_sqlite."\n";
+	}
+	if ($db_type == "mysql") {
+		echo $schema_mysql."\n";
+	}
+
+//get the domain array and make it easily accessible by the v_id
+	$sql = "select v_id, v_domain as domain_name, v_description as domain_description from v_system_settings ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = $row['v_id'];
+		$domain_array[$v_id]['domain_name'] = check_str($row['domain_name']);
+		$domain_array[$v_id]['domain_uuid'] = uuid();
+		$domain_array[$v_id]['domain_description'] = check_str($row['domain_description']);
+
+		$sql = "insert into v_domains ";
+		$sql .= "(";
+		$sql .= "domain_uuid, ";
+		$sql .= "domain_name, ";
+		$sql .= "domain_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$domain_array[$v_id]['domain_uuid']."', ";
+		$sql .= "'".$domain_array[$v_id]['domain_name']."', ";
+		$sql .= "'".$domain_array[$v_id]['domain_description']."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; } 
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); } 
+		unset($sql);
+	}
+	unset ($prep_statement);
+
+//export the default settings path
+	$sql = "select * from v_system_settings ";
+	$sql .= "limit 1 ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		//general
+			$v_id = check_str($row["v_id"]);
+			$domain_name = check_str($row["v_domain"]);
+		//switch
+			$switch_base_dir = check_str($row["v_dir"]);
+			$switch_bin_dir = check_str($row["bin_dir"]);
+			$switch_conf_dir = check_str($row["v_conf_dir"]);
+			$switch_db_dir = check_str($row["v_db_dir"]);
+			$switch_dialplan_dir = check_str($row["v_dialplan_default_dir"]);
+			if (substr($switch_dialplan_dir, -(strlen($domain_name))) == $domain_name) {
+				$switch_dialplan_dir = substr($switch_dialplan_dir, 0, -(strlen($domain_name)+1));
+			}
+			$switch_extensions_dir = check_str($row["v_extensions_dir"]);
+			if (substr($switch_extensions_dir, -(strlen($domain_name))) == $domain_name) {
+				$switch_extensions_dir = substr($switch_extensions_dir, 0, -(strlen($domain_name)+1));
+			}
+			$switch_gateways_dir = check_str($row["v_gateways_dir"]);
+			$switch_grammar_dir = check_str($row["v_grammar_dir"]);
+			$switch_log_dir = check_str($row["v_log_dir"]);
+			$switch_mod_dir = check_str($row["v_mod_dir"]);
+			if (strlen($row["v_provisioning_tftp_dir"]) > 0) { $switch_provision_dir = check_str($row["v_provisioning_tftp_dir"]); }
+			if (strlen($row["v_provisioning_ftp_dir"]) > 0) { $switch_provision_dir = check_str($row["v_provisioning_ftp_dir"]); }
+			if (strlen($row["v_provisioning_https_dir"]) > 0) { $switch_provision_dir = check_str($row["v_provisioning_https_dir"]); }
+			if (strlen($row["v_provisioning_http_dir"]) > 0) { $switch_provision_dir = check_str($row["v_provisioning_http_dir"]); }
+			$switch_recordings_dir = check_str($row["v_recordings_dir"]);
+			if (substr($switch_recordings_dir, -(strlen($domain_name))) == $domain_name) {
+				$switch_recordings_dir = substr($switch_extensions_dir, 0, -(strlen($domain_name)+1));
+			}
+			$switch_scripts_dir = check_str($row["v_scripts_dir"]);
+			$switch_sounds_dir = check_str($row["v_sounds_dir"]);
+			$switch_storage_dir = check_str($row["v_storage_dir"]);
+			$switch_voicemail_dir = check_str($row["v_voicemail_dir"]);
+		//server
+			$server_startup_script_dir = check_str($row["v_startup_script_dir"]);
+			$server_backup_dir = check_str($row["v_backup_dir"]);
+			$server_temp_dir = check_str($row["tmp_dir"]);
+		//domain
+			$domain_menu_uuid = strtolower(check_str($row["v_menu_uuid"]));
+			$domain_time_zone =  check_str($row["v_time_zone"]);
+			$domain_template_name = check_str($row["v_template_name"]);
+
+	//add the default settings
+		$x = 0;
+		$tmp[$x]['name'] = 'uuid';
+		$tmp[$x]['value'] = $domain_menu_uuid;
+		$tmp[$x]['category'] = 'domain';
+		$tmp[$x]['subcategory'] = 'menu';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'name';
+		$tmp[$x]['value'] = $domain_time_zone;
+		$tmp[$x]['category'] = 'domain';
+		$tmp[$x]['subcategory'] = 'time_zone';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'name';
+		$tmp[$x]['value'] = $domain_template_name;
+		$tmp[$x]['category'] = 'domain';
+		$tmp[$x]['subcategory'] = 'template';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $server_temp_dir;
+		$tmp[$x]['category'] = 'server';
+		$tmp[$x]['subcategory'] = 'temp';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $server_startup_script_dir;
+		$tmp[$x]['category'] = 'server';
+		$tmp[$x]['subcategory'] = 'startup_script';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $server_backup_dir;
+		$tmp[$x]['category'] = 'server';
+		$tmp[$x]['subcategory'] = 'backup';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_bin_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'bin';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $install_switch_base_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'base';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_conf_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'conf';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_db_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'db';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_log_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'log';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_extensions_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'extensions';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_gateways_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'gateways';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_dialplan_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'dialplan';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_mod_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'mod';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_scripts_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'scripts';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_grammar_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'grammar';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_storage_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'storage';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_voicemail_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'voicemail';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_recordings_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'recordings';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_sounds_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'sounds';
+		$tmp[$x]['enabled'] = 'true';
+		$x++;
+		$tmp[$x]['name'] = 'dir';
+		$tmp[$x]['value'] = $switch_provision_dir;
+		$tmp[$x]['category'] = 'switch';
+		$tmp[$x]['subcategory'] = 'provision';
+		$tmp[$x]['enabled'] = 'false';
+		$x++;
+		//$dest_db->beginTransaction();
+		foreach($tmp as $row) {
+			$sql = "insert into v_default_settings ";
+			$sql .= "(";
+			$sql .= "default_setting_uuid, ";
+			$sql .= "default_setting_name, ";
+			$sql .= "default_setting_value, ";
+			$sql .= "default_setting_category, ";
+			$sql .= "default_setting_subcategory, ";
+			$sql .= "default_setting_enabled ";
+			$sql .= ") ";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".uuid()."', ";
+			$sql .= "'".$row['name']."', ";
+			$sql .= "'".$row['value']."', ";
+			$sql .= "'".$row['category']."', ";
+			$sql .= "'".$row['subcategory']."', ";
+			$sql .= "'".$row['enabled']."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; } 
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+			unset($sql);
+		}
+		//$dest_db->commit();
+		unset($tmp);
+	}
+	unset ($prep_statement);
+
+//get the user array
+	$sql = "select username, v_id from v_users ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$username = check_str($row["username"]);
+		$user_array[$v_id][$username]['user_uuid'] = uuid();
+		$user_array[$v_id][$username]['contact_uuid'] = uuid();
+	}
+	//print_r($user_array);
+	unset ($prep_statement);
+
+//export the group members and add them into group users
+	$sql = "select * from v_group_members ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$group_user_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$username = check_str($row["username"]);
+		$group_name = check_str($row["group_id"]);
+		$user_uuid = $user_array[$v_id][$username]['user_uuid'];
+
+		if (strlen($domain_uuid) > 0 && strlen($user_uuid) > 0) {
+			$sql = "insert into v_group_users ";
+			$sql .= "(";
+			$sql .= "group_user_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "group_name, ";
+			$sql .= "user_uuid ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$group_user_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$group_name."', ";
+			if (strlen($user_uuid) > 0) {
+				$sql .= "'".$user_uuid."' ";
+			}
+			else {
+				$sql .= "null ";
+			}
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the group permissions
+	$sql = "select * from v_group_permissions ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$group_permission_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$permission_name = check_str($row["permission_id"]);
+		$group_name = check_str($row["group_id"]);
+
+		if (strlen($domain_uuid) > 0) {
+			$sql = "insert into v_group_permissions ";
+			$sql .= "(";
+			$sql .= "group_permission_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "permission_name, ";
+			$sql .= "group_name ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$group_permission_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$permission_name."', ";
+			$sql .= "'".$group_name."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the groups
+	$sql = "select * from v_groups ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$group_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$group_name = check_str($row["group_id"]);
+		$group_description = check_str($row["group_desc"]);
+
+		if (strlen($domain_uuid) > 0) {
+			$sql = "insert into v_groups ";
+			$sql .= "(";
+			$sql .= "group_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "group_name, ";
+			$sql .= "group_description ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$group_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$group_name."', ";
+			$sql .= "'".$group_description."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the menus
+	$sql = "select * from v_menus ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$menu_uuid = check_str($row["menu_uuid"]);
+		$menu_name = check_str($row["menu_name"]);
+		$menu_language = check_str($row["menu_language"]);
+		$menu_description = check_str($row["menu_desc"]);
+
+		$sql = "insert into v_menus ";
+		$sql .= "(";
+		$sql .= "menu_uuid, ";
+		$sql .= "menu_name, ";
+		$sql .= "menu_language, ";
+		$sql .= "menu_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$menu_uuid."', ";
+		$sql .= "'".$menu_name."', ";
+		$sql .= "'".$menu_language."', ";
+		$sql .= "'".$menu_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the menu items
+	$sql = "select * from v_menu_items ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$menu_item_uuid = strtolower(check_str($row["menu_item_uuid"]));
+		$menu_uuid = strtolower(check_str($row["menu_uuid"]));
+		$menu_item_parent_uuid = strtolower(check_str($row["menu_item_parent_uuid"]));
+		$menu_item_title = check_str($row["menu_item_title"]);
+		$menu_item_link = check_str($row["menu_item_str"]);
+		$menu_item_category = check_str($row["menu_item_category"]);
+		$menu_item_protected = check_str($row["menu_item_protected"]);
+		$menu_item_order = check_str($row["menu_item_order"]);
+		$menu_item_description = check_str($row["menu_item_desc"]);
+		$menu_item_add_user = check_str($row["menu_item_add_user"]);
+		$menu_item_add_date = check_str($row["menu_item_add_date"]);
+		$menu_item_mod_user = check_str($row["menu_item_mod_user"]);
+		$menu_item_mod_date = check_str($row["menu_item_mod_date"]);
+
+		$sql = "insert into v_menu_items ";
+		$sql .= "(";
+		$sql .= "menu_item_uuid, ";
+		$sql .= "menu_uuid, ";
+		$sql .= "menu_item_parent_uuid, ";
+		$sql .= "menu_item_title, ";
+		$sql .= "menu_item_link, ";
+		$sql .= "menu_item_category, ";
+		$sql .= "menu_item_protected, ";
+		$sql .= "menu_item_order, ";
+		$sql .= "menu_item_description, ";
+		$sql .= "menu_item_add_user, ";
+		$sql .= "menu_item_add_date, ";
+		$sql .= "menu_item_mod_user, ";
+		$sql .= "menu_item_mod_date ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$menu_item_uuid."', ";
+		$sql .= "'".$menu_uuid."', ";
+		if (strlen($menu_item_parent_uuid) > 0) {
+			$sql .= "'".$menu_item_parent_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$menu_item_title."', ";
+		$sql .= "'".$menu_item_link."', ";
+		$sql .= "'".$menu_item_category."', ";
+		$sql .= "'".$menu_item_protected."', ";
+		$sql .= "'".$menu_item_order."', ";
+		$sql .= "'".$menu_item_description."', ";
+		$sql .= "'".$menu_item_add_user."', ";
+		$sql .= "'".$menu_item_add_date."', ";
+		$sql .= "'".$menu_item_mod_user."', ";
+		$sql .= "'".$menu_item_mod_date."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the groups assigned to the menu itmes
+	$sql = "select * from v_menu_item_groups ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$menu_uuid = check_str($row["menu_uuid"]);
+		$menu_item_uuid = check_str($row["menu_item_uuid"]);
+		$group_name = check_str($row["group_id"]);
+
+		if (strlen($menu_item_uuid) > 0) {
+			$sql = "insert into v_menu_item_groups ";
+			$sql .= "(";
+			$sql .= "menu_uuid, ";
+			$sql .= "menu_item_uuid, ";
+			$sql .= "group_name ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$menu_uuid."', ";
+			$sql .= "'".$menu_item_uuid."', ";
+			$sql .= "'".$group_name."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the users
+	$sql = "select * from v_users ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$username = check_str($row["username"]);
+		$user_uuid = $user_array[$v_id][$username]['user_uuid'];
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$password = check_str($row["password"]);
+		$salt = check_str($row["salt"]);
+		$contact_uuid = $user_array[$v_id][$username]['contact_uuid'];
+		$user_status = check_str($row["user_status"]);
+		$user_time_zone = check_str($row["user_time_zone"]);
+		$user_type = check_str($row["user_type"]);
+		$user_category = check_str($row["user_category"]);
+
+		if (strlen($user_uuid) == 0) {
+			$user_uuid = uuid();
+		}
+
+		if (strlen($domain_uuid) > 0) {
+			if (strlen($username) > 0) {
+				$sql = "insert into v_users ";
+				$sql .= "(";
+				$sql .= "user_uuid, ";
+				$sql .= "domain_uuid, ";
+				$sql .= "username, ";
+				$sql .= "password, ";
+				$sql .= "salt, ";
+				$sql .= "contact_uuid, ";
+				$sql .= "user_status, ";
+				$sql .= "user_add_user, ";
+				$sql .= "user_add_date ";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$user_uuid."', ";
+				$sql .= "'".$domain_uuid."', ";
+				$sql .= "'".$username."', ";
+				$sql .= "'".$password."', ";
+				$sql .= "'".$salt."', ";
+				$sql .= "'".$contact_uuid."', ";
+				$sql .= "'".$user_status."', ";
+				$sql .= "'".$user_add_user."', ";
+				$sql .= "'".$user_add_date."' ";
+				$sql .= ")";
+				if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+				if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+			}
+
+			//export contacts
+				$contact_name_given = check_str($row["user_first_name"]);
+				$contact_name_family = check_str($row["user_last_name"]);
+				$contact_organization = check_str($row["user_company_name"]);
+				$contact_email = check_str($row["user_email"]);
+				$contact_note = check_str($row["user_notes"]);
+				$contact_url = check_str($row["user_url"]);
+
+				$sql = "insert into v_contacts ";
+				$sql .= "(";
+				$sql .= "contact_uuid, ";
+				$sql .= "domain_uuid, ";
+				$sql .= "contact_type, ";
+				$sql .= "contact_organization, ";
+				$sql .= "contact_name_given, ";
+				$sql .= "contact_name_family, ";
+				$sql .= "contact_email, ";
+				$sql .= "contact_url, ";
+				$sql .= "contact_time_zone, ";
+				$sql .= "contact_note ";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$contact_uuid."', ";
+				$sql .= "'".$domain_uuid."', ";
+				if ($user_type == 'user') {
+					$sql .= "'user', ";
+				}
+				else {
+					$sql .= "'".$user_category."', ";
+				}
+				$sql .= "'".$contact_organization."', ";
+				$sql .= "'".$contact_name_given."', ";
+				$sql .= "'".$contact_name_family."', ";
+				$sql .= "'".$contact_email."', ";
+				$sql .= "'".$contact_url."', ";
+				$sql .= "'".$user_time_zone."', ";
+				$sql .= "'".$contact_note."' ";
+				$sql .= ")";
+				if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+				if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+
+			//export the contact addresses
+				$x = 0;
+				if (strlen($row["user_physical_city"]) > 0) {
+					$addresses[$x]['address_1'] = check_str($row["user_physical_address_1"]);
+					$addresses[$x]['address_2'] = check_str($row["user_physical_address_2"]);
+					$addresses[$x]['city'] = check_str($row["user_physical_city"]);
+					$addresses[$x]['state_province'] = check_str($row["user_physical_state_province"]);
+					$addresses[$x]['country'] = check_str($row["user_physical_country"]);
+					$addresses[$x]['postal_code'] = check_str($row["user_physical_postal_code"]);
+					$addresses[$x]['address_type'] = 'work';
+					$x++;
+				}
+				if (strlen($row["user_mailing_city"]) > 0) {
+					$addresses[$x]['address_1'] = check_str($row["user_mailing_address_1"]);
+					$addresses[$x]['address_2'] = check_str($row["user_mailing_address_2"]);
+					$addresses[$x]['city'] = check_str($row["user_mailing_city"]);
+					$addresses[$x]['state_province'] = check_str($row["user_mailing_state_province"]);
+					$addresses[$x]['country'] = check_str($row["user_mailing_country"]);
+					$addresses[$x]['postal_code'] = check_str($row["user_mailing_postal_code"]);
+					$addresses[$x]['address_type'] = 'work';
+					$x++;
+				}
+				if (strlen($row["user_billing_city"]) > 0) {
+					$addresses[$x]['address_1'] = check_str($row["user_billing_address_1"]);
+					$addresses[$x]['address_2'] = check_str($row["user_billing_address_2"]);
+					$addresses[$x]['city'] = check_str($row["user_billing_city"]);
+					$addresses[$x]['state_province'] = check_str($row["user_billing_state_province"]);
+					$addresses[$x]['country'] = check_str($row["user_billing_country"]);
+					$addresses[$x]['postal_code'] = check_str($row["user_billing_postal_code"]);
+					$addresses[$x]['address_type'] = 'work';
+					$x++;
+				}
+				if (strlen($row["user_shipping_city"]) > 0) {
+					$addresses[$x]['address_1'] = check_str($row["user_shipping_address_1"]);
+					$addresses[$x]['address_2'] = check_str($row["user_shipping_address_2"]);
+					$addresses[$x]['city'] = check_str($row["user_shipping_city"]);
+					$addresses[$x]['state_province'] = check_str($row["user_shipping_state_province"]);
+					$addresses[$x]['country'] = check_str($row["user_shipping_country"]);
+					$addresses[$x]['postal_code'] = check_str($row["user_shipping_postal_code"]);
+					$addresses[$x]['address_type'] = 'work';
+				}
+				foreach($addresses as $address) {
+					$sql = "insert into v_contact_addresses ";
+					$sql .= "(";
+					$sql .= "contact_address_uuid, ";
+					$sql .= "contact_uuid, ";
+					$sql .= "domain_uuid, ";
+					$sql .= "address_type, ";
+					$sql .= "address_street, ";
+					$sql .= "address_extended, ";
+					$sql .= "address_locality, ";
+					$sql .= "address_region, ";
+					$sql .= "address_postal_code, ";
+					$sql .= "address_country ";
+					$sql .= ")";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$contact_uuid."', ";
+					$sql .= "'".$domain_uuid."', ";
+					$sql .= "'".$address["address_type"]."', ";
+					$sql .= "'".$address["address_1"]."', ";
+					$sql .= "'".$address["address_2"]."', ";
+					$sql .= "'".$address["city"]."', ";
+					$sql .= "'".$address["state_province"]."', ";
+					$sql .= "'".$address["postal_code"]."', ";
+					$sql .= "'".$address["country"]."' ";
+					$sql .= ")";
+					if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+					if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+				}
+				unset($addresses);
+
+			//export the contact phone numbers
+				$x = 0;
+				if (strlen($row["user_phone_1"]) > 0) {
+					$phones[$x]['number'] = check_str($row["user_phone_1"]);
+					$phones[$x]['type'] = 'work';
+					$x++;
+				}
+				if (strlen($row["user_phone_2"]) > 0) {
+					$phones[$x]['number'] = check_str($row["user_phone_2"]);
+					$phones[$x]['type'] = 'work';
+					$x++;
+				}
+				if (strlen($row["user_phone_mobile"]) > 0) {
+					$phones[$x]['number'] = check_str($row["user_phone_mobile"]);
+					$phones[$x]['type'] = 'cell';
+					$x++;
+				}
+				if (strlen($row["user_phone_emergency_mobile"]) > 0) {
+					$phones[$x]['number'] = check_str($row["user_phone_emergency_mobile"]);
+					$phones[$x]['type'] = 'x-emergency';
+					$x++;
+				}
+				if (strlen($row["user_phone_fax"]) > 0) {
+					$phones[$x]['number'] = check_str($row["user_phone_fax"]);
+					$phones[$x]['type'] = 'fax';
+					$x++;
+				}
+				foreach($phones as $phone) {
+					$sql = "insert into v_contact_phones ";
+					$sql .= "(";
+					$sql .= "contact_phone_uuid, ";
+					$sql .= "domain_uuid, ";
+					$sql .= "contact_uuid, ";
+					$sql .= "phone_type, ";
+					$sql .= "phone_number ";
+					$sql .= ")";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$domain_uuid."', ";
+					$sql .= "'".$contact_uuid."', ";
+					$sql .= "'".$phone["type"]."', ";
+					$sql .= "'".$phone["number"]."' ";
+					$sql .= ")";
+					if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+					if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+				}
+				unset($phones);
+
+			//add to user settings
+				//$user_template_name = $row["user_template_name"];
+				if (strlen($row["user_time_zone"]) > 0) {
+					$user_settings[$x]['category'] = 'domain';
+					$user_settings[$x]['sub_category'] = 'time_zone';
+					$user_settings[$x]['name'] = "name";
+					$user_settings[$x]['value'] = check_str($row["user_time_zone"]);
+					$x++;
+				}
+				foreach($user_settings as $setting) {
+					$sql = "insert into v_user_settings ";
+					$sql .= "(";
+					$sql .= "user_setting_uuid, ";
+					$sql .= "user_setting_category, ";
+					$sql .= "user_setting_subcategory, ";
+					$sql .= "user_setting_name, ";
+					$sql .= "user_setting_value, ";
+					$sql .= "user_setting_enabled, ";
+					$sql .= "user_uuid ";
+					$sql .= ") ";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$setting["category"]."', ";
+					$sql .= "'".$setting["sub_category"]."', ";
+					$sql .= "'".$setting["name"]."', ";
+					$sql .= "'".$setting["value"]."', ";
+					$sql .= "'true', ";
+					$sql .= "'".$user_uuid."' ";
+					$sql .= ")";
+					$db->exec(check_sql($sql));
+				}
+				unset($user_settings);
+		}
+	}
+	unset ($prep_statement);
+
+//export the call broadcasts
+	$sql = "select * from v_call_broadcast ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$call_call_broadcast_uuid = uuid();
+		$broadcast_name = check_str($row["broadcast_name"]);
+		$broadcast_description = check_str($row["broadcast_desc"]);
+		$broadcast_timeout = check_str($row["broadcast_timeout"]);
+		$broadcast_concurrent_limit = check_str($row["broadcast_concurrent_limit"]);
+		$recording_uuid = check_str($row["recording_uuid"]);
+		$broadcast_caller_id_name = check_str($row["broadcast_caller_id_name"]);
+		$broadcast_caller_id_number = check_str($row["broadcast_caller_id_number"]);
+		$broadcast_destination_type = check_str($row["broadcast_destination_type"]);
+		$broadcast_phone_numbers = check_str($row["broadcast_phone_numbers"]);
+		$broadcast_destination_data = check_str($row["broadcast_destination_data"]);
+
+		$sql = "insert into v_call_broadcasts ";
+		$sql .= "(";
+		$sql .= "call_call_broadcast_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "broadcast_name, ";
+		$sql .= "broadcast_description, ";
+		$sql .= "broadcast_timeout, ";
+		$sql .= "broadcast_concurrent_limit, ";
+		$sql .= "recording_uuid, ";
+		$sql .= "broadcast_caller_id_name, ";
+		$sql .= "broadcast_caller_id_number, ";
+		$sql .= "broadcast_destination_type, ";
+		$sql .= "broadcast_phone_numbers, ";
+		$sql .= "broadcast_destination_data ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$call_call_broadcast_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$broadcast_name."', ";
+		$sql .= "'".$broadcast_description."', ";
+		$sql .= "'".$broadcast_timeout."', ";
+		$sql .= "'".$broadcast_concurrent_limit."', ";
+		$sql .= "null, ";
+		$sql .= "'".$broadcast_caller_id_name."', ";
+		$sql .= "'".$broadcast_caller_id_number."', ";
+		$sql .= "'".$broadcast_destination_type."', ";
+		$sql .= "'".$broadcast_phone_numbers."', ";
+		$sql .= "'".$broadcast_destination_data."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export call center agents
+	$sql = "select * from v_call_center_agent ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$call_center_agent_uuid = uuid();
+		$agent_name = check_str($row["agent_name"]);
+		$agent_type = check_str($row["agent_type"]);
+		$agent_call_timeout = check_str($row["agent_call_timeout"]);
+		$agent_contact = check_str($row["agent_contact"]);
+		$agent_status = check_str($row["agent_status"]);
+		$agent_logout = check_str($row["agent_logout"]);
+		$agent_max_no_answer = check_str($row["agent_max_no_answer"]);
+		$agent_wrap_up_time = check_str($row["agent_wrap_up_time"]);
+		$agent_reject_delay_time = check_str($row["agent_reject_delay_time"]);
+		$agent_busy_delay_time = check_str($row["agent_busy_delay_time"]);
+		$agent_no_answer_delay_time = check_str($row["agent_no_answer_delay_time"]);
+
+		$sql = "insert into v_call_center_agents ";
+		$sql .= "(";
+		$sql .= "call_center_agent_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "agent_name, ";
+		$sql .= "agent_type, ";
+		$sql .= "agent_call_timeout, ";
+		$sql .= "agent_contact, ";
+		$sql .= "agent_status, ";
+		$sql .= "agent_logout, ";
+		$sql .= "agent_max_no_answer, ";
+		$sql .= "agent_wrap_up_time, ";
+		$sql .= "agent_reject_delay_time, ";
+		$sql .= "agent_busy_delay_time, ";
+		$sql .= "agent_no_answer_delay_time ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$call_center_agent_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$agent_name."', ";
+		$sql .= "'".$agent_type."', ";
+		$sql .= "'".$agent_call_timeout."', ";
+		$sql .= "'".$agent_contact."', ";
+		$sql .= "'".$agent_status."', ";
+		$sql .= "'".$agent_logout."', ";
+		$sql .= "'".$agent_max_no_answer."', ";
+		$sql .= "'".$agent_wrap_up_time."', ";
+		$sql .= "'".$agent_reject_delay_time."', ";
+		$sql .= "'".$agent_busy_delay_time."', ";
+		$sql .= "'".$agent_no_answer_delay_time."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export call center logs
+	$sql = "select * from v_call_center_logs ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$cc_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$cc_queue = check_str($row["cc_queue"]);
+		$cc_action = check_str($row["cc_action"]);
+		$cc_count = check_str($row["cc_count"]);
+		$cc_agent = check_str($row["cc_agent"]);
+		$cc_agent_system = check_str($row["cc_agent_system"]);
+		$cc_agent_status = check_str($row["cc_agent_status"]);
+		$cc_agent_state = check_str($row["cc_agent_state"]);
+		$cc_agent_uuid = check_str($row["cc_agent_uuid"]);
+		$cc_selection = check_str($row["cc_selection"]);
+		$cc_cause = check_str($row["cc_cause"]);
+		$cc_wait_time = check_str($row["cc_wait_time"]);
+		$cc_talk_time = check_str($row["cc_talk_time"]);
+		$cc_total_time = check_str($row["cc_total_time"]);
+		$cc_epoch = check_str($row["cc_epoch"]);
+		$cc_date = check_str($row["cc_date"]);
+		$cc_agent_type = check_str($row["cc_agent_type"]);
+		$cc_member_uuid = check_str($row["cc_member_uuid"]);
+		$cc_member_session_uuid = check_str($row["cc_member_session_uuid"]);
+		$cc_member_cid_name = check_str($row["cc_member_cid_name"]);
+		$cc_member_cid_number = check_str($row["cc_member_cid_number"]);
+		$cc_agent_called_time = check_str($row["cc_agent_called_time"]);
+		$cc_agent_answered_time = check_str($row["cc_agent_answered_time"]);
+		$cc_member_joined_time = check_str($row["cc_member_joined_time"]);
+		$cc_member_leaving_time = check_str($row["cc_member_leaving_time"]);
+		$cc_bridge_terminated_time = check_str($row["cc_bridge_terminated_time"]);
+		$cc_hangup_cause = check_str($row["cc_hangup_cause"]);
+
+		$sql = "insert into v_call_center_logs ";
+		$sql .= "(";
+		$sql .= "cc_uuid, ";
+		$sql .= "cc_queue, ";
+		$sql .= "cc_action, ";
+		$sql .= "cc_count, ";
+		$sql .= "cc_agent, ";
+		$sql .= "cc_agent_system, ";
+		$sql .= "cc_agent_status, ";
+		$sql .= "cc_agent_state, ";
+		$sql .= "cc_agent_uuid, ";
+		$sql .= "cc_selection, ";
+		$sql .= "cc_cause, ";
+		$sql .= "cc_wait_time, ";
+		$sql .= "cc_talk_time, ";
+		$sql .= "cc_total_time, ";
+		$sql .= "cc_epoch, ";
+		$sql .= "cc_date, ";
+		$sql .= "cc_agent_type, ";
+		$sql .= "cc_member_uuid, ";
+		$sql .= "cc_member_session_uuid, ";
+		$sql .= "cc_member_cid_name, ";
+		$sql .= "cc_member_cid_number, ";
+		$sql .= "cc_agent_called_time, ";
+		$sql .= "cc_agent_answered_time, ";
+		$sql .= "cc_member_joined_time, ";
+		$sql .= "cc_member_leaving_time, ";
+		$sql .= "cc_bridge_terminated_time, ";
+		$sql .= "cc_hangup_cause ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$cc_uuid."', ";
+		$sql .= "'".$cc_queue."', ";
+		$sql .= "'".$cc_action."', ";
+		if (strlen($cc_count) > 0) {
+			$sql .= "'".$cc_count."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$cc_agent."', ";
+		$sql .= "'".$cc_agent_system."', ";
+		$sql .= "'".$cc_agent_status."', ";
+		$sql .= "'".$cc_agent_state."', ";
+		$sql .= "'".$cc_agent_uuid."', ";
+		$sql .= "'".$cc_selection."', ";
+		$sql .= "'".$cc_cause."', ";
+		$sql .= "'".$cc_wait_time."', ";
+		$sql .= "'".$cc_talk_time."', ";
+		$sql .= "'".$cc_total_time."', ";
+		if (strlen($cc_epoch) > 0) {
+			$sql .= "'".$cc_epoch."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$cc_date."', ";
+		$sql .= "'".$cc_agent_type."', ";
+		$sql .= "'".$cc_member_uuid."', ";
+		$sql .= "'".$cc_member_session_uuid."', ";
+		$sql .= "'".$cc_member_cid_name."', ";
+		$sql .= "'".$cc_member_cid_number."', ";
+		if (strlen($cc_agent_called_time) > 0) {
+			$sql .= "'".$cc_agent_called_time."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($cc_agent_answered_time) > 0) {
+			$sql .= "'".$cc_agent_answered_time."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($cc_member_joined_time) > 0) {
+			$sql .= "'".$cc_member_joined_time."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($cc_member_leaving_time) > 0) {
+			$sql .= "'".$cc_member_leaving_time."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($cc_bridge_terminated_time) > 0) {
+			$sql .= "'".$cc_bridge_terminated_time."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$cc_hangup_cause."' ";
+		$sql .= ")";
+		//if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		//if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the call center queues
+	$sql = "select * from v_call_center_queue ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$call_center_queue_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$queue_name = check_str($row["queue_name"]);
+		$queue_extension = check_str($row["queue_extension"]);
+		$queue_strategy = check_str($row["queue_strategy"]);
+		$queue_moh_sound = check_str($row["queue_moh_sound"]);
+		$queue_record_template = check_str($row["queue_record_template"]);
+		$queue_time_base_score = check_str($row["queue_time_base_score"]);
+		$queue_max_wait_time = check_str($row["queue_max_wait_time"]);
+		$queue_max_wait_time_with_no_agent = check_str($row["queue_max_wait_time_with_no_agent"]);
+		$queue_tier_rules_apply = check_str($row["queue_tier_rules_apply"]);
+		$queue_tier_rule_wait_second = check_str($row["queue_tier_rule_wait_second"]);
+		$queue_tier_rule_no_agent_no_wait = check_str($row["queue_tier_rule_no_agent_no_wait"]);
+		$queue_timeout_action = check_str($row["queue_timeout_action"]);
+		$queue_discard_abandoned_after = check_str($row["queue_discard_abandoned_after"]);
+		$queue_abandoned_resume_allowed = check_str($row["queue_abandoned_resume_allowed"]);
+		$queue_tier_rule_wait_multiply_level = check_str($row["queue_tier_rule_wait_multiply_level"]);
+		$queue_cid_prefix = check_str($row["queue_cid_prefix"]);
+		$queue_description = check_str($row["queue_description"]);
+
+		$sql = "insert into v_call_center_queues ";
+		$sql .= "(";
+		$sql .= "call_center_queue_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "queue_name, ";
+		$sql .= "queue_extension, ";
+		$sql .= "queue_strategy, ";
+		$sql .= "queue_moh_sound, ";
+		$sql .= "queue_record_template, ";
+		$sql .= "queue_time_base_score, ";
+		$sql .= "queue_max_wait_time, ";
+		$sql .= "queue_max_wait_time_with_no_agent, ";
+		$sql .= "queue_tier_rules_apply, ";
+		$sql .= "queue_tier_rule_wait_second, ";
+		$sql .= "queue_tier_rule_no_agent_no_wait, ";
+		$sql .= "queue_timeout_action, ";
+		$sql .= "queue_discard_abandoned_after, ";
+		$sql .= "queue_abandoned_resume_allowed, ";
+		$sql .= "queue_tier_rule_wait_multiply_level, ";
+		$sql .= "queue_cid_prefix, ";
+		$sql .= "queue_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$call_center_queue_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$queue_name."', ";
+		$sql .= "'".$queue_extension."', ";
+		$sql .= "'".$queue_strategy."', ";
+		$sql .= "'".$queue_moh_sound."', ";
+		$sql .= "'".$queue_record_template."', ";
+		$sql .= "'".$queue_time_base_score."', ";
+		$sql .= "'".$queue_max_wait_time."', ";
+		$sql .= "'".$queue_max_wait_time_with_no_agent."', ";
+		$sql .= "'".$queue_tier_rules_apply."', ";
+		$sql .= "'".$queue_tier_rule_wait_second."', ";
+		$sql .= "'".$queue_tier_rule_no_agent_no_wait."', ";
+		$sql .= "'".$queue_timeout_action."', ";
+		$sql .= "'".$queue_discard_abandoned_after."', ";
+		$sql .= "'".$queue_abandoned_resume_allowed."', ";
+		$sql .= "'".$queue_tier_rule_wait_multiply_level."', ";
+		$sql .= "'".$queue_cid_prefix."', ";
+		$sql .= "'".$queue_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the call center tiers
+	$sql = "select * from v_call_center_tier ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$call_center_tier_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$agent_name = check_str($row["agent_name"]);
+		$queue_name = check_str($row["queue_name"]);
+		$tier_level = check_str($row["tier_level"]);
+		$tier_position = check_str($row["tier_position"]);
+
+		$sql = "insert into v_call_center_tiers ";
+		$sql .= "(";
+		$sql .= "call_center_tier_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "agent_name, ";
+		$sql .= "queue_name, ";
+		$sql .= "tier_level, ";
+		$sql .= "tier_position ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$call_center_tier_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$agent_name."', ";
+		$sql .= "'".$queue_name."', ";
+		$sql .= "'".$tier_level."', ";
+		$sql .= "'".$tier_position."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export contacts
+	$sql = "select * from v_contacts ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$contact_id = check_str($row["contact_id"]);
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$contact_uuid = uuid();
+		$contact_type = check_str($row["type"]);
+		$contact_organization = check_str($row["org"]);
+		$contact_name_given = check_str($row["n_given"]);
+		$contact_name_family = check_str($row["n_family"]);
+		$contact_nickname = check_str($row["nickname"]);
+		$contact_title = check_str($row["title"]);
+		$contact_role = check_str($row["role"]);
+		$contact_email = check_str($row["email"]);
+		$contact_url = check_str($row["url"]);
+		$contact_time_zone = check_str($row["tz"]);
+		$contact_note = check_str($row["note"]);
+
+		//set the contact_uuid
+		$contact_array[$contact_id]['contact_uuid'] = $contact_uuid;
+
+		$sql = "insert into v_contacts ";
+		$sql .= "(";
+		$sql .= "contact_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "contact_type, ";
+		$sql .= "contact_organization, ";
+		$sql .= "contact_name_given, ";
+		$sql .= "contact_name_family, ";
+		$sql .= "contact_nickname, ";
+		$sql .= "contact_title, ";
+		$sql .= "contact_role, ";
+		$sql .= "contact_email, ";
+		$sql .= "contact_url, ";
+		$sql .= "contact_time_zone, ";
+		$sql .= "contact_note ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$contact_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$contact_type."', ";
+		$sql .= "'".$contact_organization."', ";
+		$sql .= "'".$contact_name_given."', ";
+		$sql .= "'".$contact_name_family."', ";
+		$sql .= "'".$contact_nickname."', ";
+		$sql .= "'".$contact_title."', ";
+		$sql .= "'".$contact_role."', ";
+		$sql .= "'".$contact_email."', ";
+		$sql .= "'".$contact_url."', ";
+		$sql .= "'".$contact_time_zone."', ";
+		$sql .= "'".$contact_note."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the contact addresses
+	$sql = "select * from v_contacts_adr ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$contact_address_uuid = uuid();
+		$contact_id = check_str($row["contact_id"]);
+		$address_type = check_str($row["adr_type"]);
+		$address_street = check_str($row["adr_street"]);
+		$address_extended = check_str($row["adr_extended"]);
+		$address_locality = check_str($row["adr_locality"]);
+		$address_region = check_str($row["adr_region"]);
+		$address_postal_code = check_str($row["adr_postal_code"]);
+		$address_country = check_str($row["adr_country"]);
+		$address_latitude = check_str($row["adr_latitude"]);
+		$address_longitude = check_str($row["adr_longitude"]);
+
+		//get the contact_uuid
+		$contact_uuid = $contact_array[$contact_id]['contact_uuid'];
+
+		$sql = "insert into v_contact_addresses ";
+		$sql .= "(";
+		$sql .= "contact_address_uuid, ";
+		$sql .= "contact_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "address_type, ";
+		$sql .= "address_street, ";
+		$sql .= "address_extended, ";
+		$sql .= "address_locality, ";
+		$sql .= "address_region, ";
+		$sql .= "address_postal_code, ";
+		$sql .= "address_country, ";
+		$sql .= "address_latitude, ";
+		$sql .= "address_longitude ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$contact_address_uuid."', ";
+		$sql .= "'".$contact_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$address_type."', ";
+		$sql .= "'".$address_street."', ";
+		$sql .= "'".$address_extended."', ";
+		$sql .= "'".$address_locality."', ";
+		$sql .= "'".$address_region."', ";
+		$sql .= "'".$address_postal_code."', ";
+		$sql .= "'".$address_country."', ";
+		$sql .= "'".$address_latitude."', ";
+		$sql .= "'".$address_longitude."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the contact phone numbers
+	$sql = "select * from v_contacts_tel ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$contact_phone_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$contact_id = check_str($row["contact_id"]);
+		$phone_type = check_str($row["tel_type"]);
+		$phone_number = check_str($row["tel_number"]);
+
+		//get the contact_uuid
+		$contact_uuid = $contact_array[$contact_id]['contact_uuid'];
+
+		if (strlen($contact_uuid) > 0) {
+			$sql = "insert into v_contact_phones ";
+			$sql .= "(";
+			$sql .= "contact_phone_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "phone_type, ";
+			$sql .= "phone_number ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$contact_phone_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$contact_uuid."', ";
+			$sql .= "'".$phone_type."', ";
+			$sql .= "'".$phone_number."' ";
+			$sql .= ")";
+		}
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the contact notes
+	$sql = "select * from v_contact_notes ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$contact_note_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$contact_id = check_str($row["contact_id"]);
+		$contact_note = check_str($row["notes"]);
+		$last_mod_date = check_str($row["last_mod_date"]);
+		$last_mod_user = check_str($row["last_mod_user"]);
+
+		//get the contact_uuid
+		$contact_uuid = $contact_array[$contact_id]['contact_uuid'];
+
+		$sql = "insert into v_contact_notes ";
+		$sql .= "(";
+		$sql .= "contact_note_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "contact_uuid, ";
+		$sql .= "contact_note, ";
+		$sql .= "last_mod_date, ";
+		$sql .= "last_mod_user ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$contact_note_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$contact_uuid."', ";
+		$sql .= "'".$contact_note."', ";
+		$sql .= "'".$last_mod_date."', ";
+		$sql .= "'".$last_mod_user."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the rss data
+	$sql = "select * from v_rss ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$rss_id = check_str($row["rss_id"]);
+		$rss_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$rss_language = check_str($row["rss_language"]);
+		$rss_category = check_str($row["rss_category"]);
+		$rss_sub_category = check_str($row["rss_sub_category"]);
+		$rss_title = check_str($row["rss_title"]);
+		$rss_link = check_str($row["rss_link"]);
+		$rss_description = check_str($row["rss_desc"]);
+		$rss_img = check_str($row["rss_img"]);
+		$rss_optional_1 = check_str($row["rss_optional_1"]);
+		$rss_optional_2 = check_str($row["rss_optional_2"]);
+		$rss_optional_3 = check_str($row["rss_optional_3"]);
+		$rss_optional_4 = check_str($row["rss_optional_4"]);
+		$rss_optional_5 = check_str($row["rss_optional_5"]);
+		$rss_add_date = check_str($row["rss_add_date"]);
+		$rss_add_user = check_str($row["rss_add_user"]);
+		$rss_del_date = check_str($row["rss_del_date"]);
+		$rss_del_user = check_str($row["rss_del_user"]);
+		$rss_order = check_str($row["rss_order"]);
+		$rss_content = check_str($row["rss_content"]);
+		$rss_group = check_str($row["rss_group"]);
+
+		//set the rss_uuid
+		$rss_array[$rss_id]['rss_uuid'] = $rss_uuid;
+
+		$sql = "insert into v_rss ";
+		$sql .= "(";
+		$sql .= "rss_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "rss_language, ";
+		$sql .= "rss_category, ";
+		$sql .= "rss_sub_category, ";
+		$sql .= "rss_title, ";
+		$sql .= "rss_link, ";
+		$sql .= "rss_description, ";
+		$sql .= "rss_img, ";
+		$sql .= "rss_optional_1, ";
+		$sql .= "rss_optional_2, ";
+		$sql .= "rss_optional_3, ";
+		$sql .= "rss_optional_4, ";
+		$sql .= "rss_optional_5, ";
+		$sql .= "rss_add_date, ";
+		$sql .= "rss_add_user, ";
+		$sql .= "rss_del_date, ";
+		$sql .= "rss_del_user, ";
+		$sql .= "rss_order, ";
+		$sql .= "rss_content, ";
+		$sql .= "rss_group ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$rss_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$rss_language."', ";
+		$sql .= "'".$rss_category."', ";
+		$sql .= "'".$rss_sub_category."', ";
+		$sql .= "'".$rss_title."', ";
+		$sql .= "'".$rss_link."', ";
+		$sql .= "'".$rss_description."', ";
+		$sql .= "'".$rss_img."', ";
+		$sql .= "'".$rss_optional_1."', ";
+		$sql .= "'".$rss_optional_2."', ";
+		$sql .= "'".$rss_optional_3."', ";
+		$sql .= "'".$rss_optional_4."', ";
+		$sql .= "'".$rss_optional_5."', ";
+		$sql .= "'".$rss_add_date."', ";
+		$sql .= "'".$rss_add_user."', ";
+		$sql .= "'".$rss_del_date."', ";
+		$sql .= "'".$rss_del_user."', ";
+		$sql .= "'".$rss_order."', ";
+		$sql .= "'".$rss_content."', ";
+		$sql .= "'".$rss_group."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the rss sub data
+	$sql = "select * from v_rss_sub ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$rss_sub_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$rss_id = check_str($row["rss_id"]);
+		$rss_sub_language = check_str($row["rss_sub_language"]);
+		$rss_sub_title = check_str($row["rss_sub_title"]);
+		$rss_sub_link = check_str($row["rss_sub_link"]);
+		$rss_sub_description = check_str($row["rss_sub_desc"]);
+		$rss_sub_optional_1 = check_str($row["rss_sub_optional_1"]);
+		$rss_sub_optional_2 = check_str($row["rss_sub_optional_2"]);
+		$rss_sub_optional_3 = check_str($row["rss_sub_optional_3"]);
+		$rss_sub_optional_4 = check_str($row["rss_sub_optional_4"]);
+		$rss_sub_optional_5 = check_str($row["rss_sub_optional_5"]);
+		$rss_sub_add_date = check_str($row["rss_sub_add_date"]);
+		$rss_sub_add_user = check_str($row["rss_sub_add_user"]);
+		$rss_sub_del_user = check_str($row["rss_sub_del_user"]);
+		$rss_sub_del_date = check_str($row["rss_sub_del_date"]);
+
+		//get the rss_uuid
+		$rss_uuid = $rss_array[$rss_id]['rss_uuid'];
+
+		$sql = "insert into v_rss_sub ";
+		$sql .= "(";
+		$sql .= "rss_sub_uuid, ";
+		$sql .= "rss_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "rss_sub_language, ";
+		$sql .= "rss_sub_title, ";
+		$sql .= "rss_sub_link, ";
+		$sql .= "rss_sub_description, ";
+		$sql .= "rss_sub_optional_1, ";
+		$sql .= "rss_sub_optional_2, ";
+		$sql .= "rss_sub_optional_3, ";
+		$sql .= "rss_sub_optional_4, ";
+		$sql .= "rss_sub_optional_5, ";
+		$sql .= "rss_sub_add_date, ";
+		$sql .= "rss_sub_add_user, ";
+		$sql .= "rss_sub_del_user, ";
+		$sql .= "rss_sub_del_date ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$rss_sub_uuid."', ";
+		$sql .= "'".$rss_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$rss_sub_language."', ";
+		$sql .= "'".$rss_sub_title."', ";
+		$sql .= "'".$rss_sub_link."', ";
+		$sql .= "'".$rss_sub_description."', ";
+		$sql .= "'".$rss_sub_optional_1."', ";
+		$sql .= "'".$rss_sub_optional_2."', ";
+		$sql .= "'".$rss_sub_optional_3."', ";
+		$sql .= "'".$rss_sub_optional_4."', ";
+		$sql .= "'".$rss_sub_optional_5."', ";
+		$sql .= "'".$rss_sub_add_date."', ";
+		$sql .= "'".$rss_sub_add_user."', ";
+		$sql .= "'".$rss_sub_del_user."', ";
+		$sql .= "'".$rss_sub_del_date."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the rss sub category data
+	$sql = "select * from v_rss_sub_category ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$rss_sub_category_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$rss_sub_category_language = check_str($row["rss_sub_category_language"]);
+		$rss_category = check_str($row["rss_category"]);
+		$rss_sub_category = check_str($row["rss_sub_category"]);
+		$rss_sub_category_description = check_str($row["rss_sub_category_desc"]);
+		$rss_sub_add_user = check_str($row["rss_sub_add_user"]);
+		$rss_sub_add_date = check_str($row["rss_sub_add_date"]);
+
+		$sql = "insert into v_rss_sub_category ";
+		$sql .= "(";
+		$sql .= "rss_sub_category_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "rss_sub_category_language, ";
+		$sql .= "rss_category, ";
+		$sql .= "rss_sub_category, ";
+		$sql .= "rss_sub_category_description, ";
+		$sql .= "rss_sub_add_user, ";
+		$sql .= "rss_sub_add_date ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$rss_sub_category_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$rss_sub_category_language."', ";
+		$sql .= "'".$rss_category."', ";
+		$sql .= "'".$rss_sub_category."', ";
+		$sql .= "'".$rss_sub_category_description."', ";
+		$sql .= "'".$rss_sub_add_user."', ";
+		$sql .= "'".$rss_sub_add_date."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//get the database connection information
+	$sql = "select * from v_database_connections ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$database_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$database_type = check_str($row["db_type"]);
+		$database_host = check_str($row["db_host"]);
+		$database_port = check_str($row["db_port"]);
+		$database_name = check_str($row["db_name"]);
+		$database_username = check_str($row["db_username"]);
+		$database_password = check_str($row["db_password"]);
+		$database_path = check_str($row["db_path"]);
+		$database_description = check_str($row["db_description"]);
+
+		$sql = "insert into v_databases ";
+		$sql .= "(";
+		$sql .= "database_uuid, ";
+		$sql .= "database_type, ";
+		$sql .= "database_host, ";
+		$sql .= "database_port, ";
+		$sql .= "database_name, ";
+		$sql .= "database_username, ";
+		$sql .= "database_password, ";
+		$sql .= "database_path, ";
+		$sql .= "database_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$database_uuid."', ";
+		$sql .= "'".$database_type."', ";
+		$sql .= "'".$database_host."', ";
+		$sql .= "'".$database_port."', ";
+		$sql .= "'".$database_name."', ";
+		$sql .= "'".$database_username."', ";
+		$sql .= "'".$database_password."', ";
+		$sql .= "'".$database_path."', ";
+		$sql .= "'".$database_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the dialplan
+	$sql = "select * from v_dialplan_includes ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$dialplan_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$dialplan_include_id = check_str($row["dialplan_include_id"]);
+		$app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; //dialplan app_uuid
+		$dialplan_name = check_str($row["extension_name"]);
+		$dialplan_number = check_str($row["extension_number"]);
+		//$dialplan_context = check_str($row["context"]);
+		$dialplan_continue = check_str($row["extension_continue"]);
+		$dialplan_order = check_str($row["dialplan_order"]);
+		$dialplan_enabled = check_str($row["enabled"]);
+		$dialplan_description = check_str($row["descr"]);
+		//$opt_1_name = check_str($row["opt_1_name"]);
+		//$opt_1_value = check_str($row["opt_1_value"]);
+
+		//set the dialplan order
+		if ($dialplan_order < 320) { $dialplan_order = 320; }
+
+		//set the dialplan_uuid
+		$dialplan_array[$dialplan_include_id]['dialplan_uuid'] = $dialplan_uuid;
+
+		//set the dialplan context
+		if (count($domain_array) > 1) {
+			$dialplan_context = $domain_array[$v_id]['domain_name'];
+		}
+		else {
+			$dialplan_context = "default";
+		}
+
+		if (strlen($domain_uuid) > 0) {
+			$sql = "insert into v_dialplans ";
+			$sql .= "(";
+			$sql .= "dialplan_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "app_uuid, ";
+			$sql .= "dialplan_name, ";
+			$sql .= "dialplan_number, ";
+			$sql .= "dialplan_context, ";
+			$sql .= "dialplan_continue, ";
+			$sql .= "dialplan_order, ";
+			$sql .= "dialplan_enabled, ";
+			$sql .= "dialplan_description ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$dialplan_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$app_uuid."', ";
+			$sql .= "'".$dialplan_name."', ";
+			$sql .= "'".$dialplan_number."', ";
+			$sql .= "'".$dialplan_context."', ";
+			$sql .= "'".$dialplan_continue."', ";
+			$sql .= "'".$dialplan_order."', ";
+			$sql .= "'".$dialplan_enabled."', ";
+			$sql .= "'".$dialplan_description."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the dialplan details
+	$sql = "select * from v_dialplan_includes_details ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$dialplan_detail_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$dialplan_include_id = check_str($row["dialplan_include_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$dialplan_detail_tag = check_str($row["tag"]);
+		$dialplan_detail_type = check_str($row["field_type"]);
+		$dialplan_detail_data = check_str($row["field_data"]);
+		$dialplan_detail_break = check_str($row["field_break"]);
+		$dialplan_detail_inline = check_str($row["field_inline"]);
+		$dialplan_detail_group = check_str($row["field_group"]);
+		$dialplan_detail_order = check_str($row["field_order"]);
+		$dialplan_detail_data = str_replace("\\\\", "\\", $dialplan_detail_data);
+
+		//get the dialplan_uuid
+		$dialplan_uuid = $dialplan_array[$dialplan_include_id]['dialplan_uuid'];
+
+		if (strlen($domain_uuid) > 0 && strlen($dialplan_uuid) > 0 ) {
+			$sql = "insert into v_dialplan_details ";
+			$sql .= "(";
+			$sql .= "dialplan_detail_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "dialplan_uuid, ";
+			$sql .= "dialplan_detail_tag, ";
+			$sql .= "dialplan_detail_type, ";
+			$sql .= "dialplan_detail_data, ";
+			$sql .= "dialplan_detail_break, ";
+			$sql .= "dialplan_detail_inline, ";
+			$sql .= "dialplan_detail_group, ";
+			$sql .= "dialplan_detail_order ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$dialplan_detail_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$dialplan_uuid."', ";
+			$sql .= "'".$dialplan_detail_tag."', ";
+			$sql .= "'".$dialplan_detail_type."', ";
+			$sql .= "'".$dialplan_detail_data."', ";
+			$sql .= "'".$dialplan_detail_break."', ";
+			$sql .= "'".$dialplan_detail_inline."', ";
+			if (strlen($dialplan_detail_group) > 0) {
+				$sql .= "'".$dialplan_detail_group."', ";
+			}
+			else {
+				$sql .= "null, ";
+			}
+			if (strlen($dialplan_detail_order) > 0) {
+				$sql .= "'".$dialplan_detail_order."' ";
+			}
+			else {
+				$sql .= "'330' ";
+			}
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the inbound routes
+	$sql = "select * from v_public_includes ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$public_include_id = $row["public_include_id"];
+		$dialplan_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$app_uuid = 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4';
+		$dialplan_name = check_str($row["extension_name"]);
+		$dialplan_context = 'public';
+		$dialplan_continue = check_str($row["extension_continue"]);
+		$dialplan_order = check_str($row["public_order"]);
+		$dialplan_enabled = check_str($row["enabled"]);
+		$dialplan_description = check_str($row["descr"]);
+
+		//set the dialplan_uuid
+		$public_dialplan_array[$public_include_id]['dialplan_uuid'] = $dialplan_uuid;
+
+		$sql = "insert into v_dialplans ";
+		$sql .= "(";
+		$sql .= "dialplan_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "app_uuid, ";
+		$sql .= "dialplan_name, ";
+		$sql .= "dialplan_context, ";
+		$sql .= "dialplan_continue, ";
+		$sql .= "dialplan_order, ";
+		$sql .= "dialplan_enabled, ";
+		$sql .= "dialplan_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$dialplan_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$app_uuid."', ";
+		$sql .= "'".$dialplan_name."', ";
+		$sql .= "'".$dialplan_context."', ";
+		$sql .= "'".$dialplan_continue."', ";
+		$sql .= "'".$dialplan_order."', ";
+		$sql .= "'".$dialplan_enabled."', ";
+		$sql .= "'".$dialplan_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export inbound route details
+	$sql = "select * from v_public_includes_details ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$dialplan_detail_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$public_include_id = check_str($row["public_include_id"]);
+		$dialplan_detail_tag = check_str($row["tag"]);
+		$dialplan_detail_type = check_str($row["field_type"]);
+		$dialplan_detail_data = check_str($row["field_data"]);
+		$dialplan_detail_break = check_str($row["field_break"]);
+		$dialplan_detail_inline = check_str($row["field_inline"]);
+		$dialplan_detail_group = check_str($row["field_group"]);
+		$dialplan_detail_order = check_str($row["field_order"]);
+
+		//get the dialplan_uuid
+		$dialplan_uuid = $public_dialplan_array[$public_include_id]['dialplan_uuid'];
+
+		$sql = "insert into v_dialplan_details ";
+		$sql .= "(";
+		$sql .= "dialplan_detail_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "dialplan_uuid, ";
+		$sql .= "dialplan_detail_tag, ";
+		$sql .= "dialplan_detail_type, ";
+		$sql .= "dialplan_detail_data, ";
+		$sql .= "dialplan_detail_break, ";
+		$sql .= "dialplan_detail_inline, ";
+		$sql .= "dialplan_detail_group, ";
+		$sql .= "dialplan_detail_order ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$dialplan_detail_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$dialplan_uuid."', ";
+		$sql .= "'".$dialplan_detail_tag."', ";
+		$sql .= "'".$dialplan_detail_type."', ";
+		$sql .= "'".$dialplan_detail_data."', ";
+		$sql .= "'".$dialplan_detail_break."', ";
+		$sql .= "'".$dialplan_detail_inline."', ";
+		if (strlen($dialplan_detail_group) > 0) {
+			$sql .= "'".$dialplan_detail_group."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($dialplan_detail_order) > 0) {
+			$sql .= "'".$dialplan_detail_order."' ";
+		}
+		else {
+			$sql .= "null ";
+		}
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//set the app_uuid for the dialplan outbound route
+	$sql = "select * from v_dialplan_includes_details ";
+	$sql .= "where (";
+	$sql .= "field_data like '%sofia/gateway/%' ";
+	$sql .= "or field_data like '%freetdm%' ";
+	$sql .= "or field_data like '%openzap%' ";
+	$sql .= "or field_data like '%dingaling%' ";
+	$sql .= "or field_data like '%enum_auto_route%' ";
+	$sql .= ") ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$dialplan_include_id = check_str($row["dialplan_include_id"]);
+
+		//get the dialplan_uuid
+		$dialplan_uuid = $dialplan_array[$dialplan_include_id]['dialplan_uuid'];
+
+		$sql = "update v_dialplans set ";
+		$sql .= "app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' ";
+		$sql .= "where dialplan_uuid = '$dialplan_uuid'";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		unset($sql);
+	}
+	unset ($prepstatement);
+
+//export the extensions
+	$sql = "select * from v_extensions ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$extension_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$extension = check_str($row["extension"]);
+		$number_alias = check_str($row["number_alias"]);
+		$password = check_str($row["password"]);
+		$user_list = check_str($row["user_list"]);
+		$provisioning_list = check_str($row["provisioning_list"]);
+		$mailbox = check_str($row["mailbox"]);
+		$vm_password = check_str($row["vm_password"]);
+		$accountcode = check_str($row["accountcode"]);
+		$effective_caller_id_name = check_str($row["effective_caller_id_name"]);
+		$effective_caller_id_number = check_str($row["effective_caller_id_number"]);
+		$outbound_caller_id_name = check_str($row["outbound_caller_id_name"]);
+		$outbound_caller_id_number = check_str($row["outbound_caller_id_number"]);
+		$limit_max = check_str($row["limit_max"]);
+		$limit_destination = check_str($row["limit_destination"]);
+		$vm_enabled = check_str($row["vm_enabled"]);
+		$vm_mailto = check_str($row["vm_mailto"]);
+		$vm_attach_file = check_str($row["vm_attach_file"]);
+		$vm_keep_local_after_email = check_str($row["vm_keep_local_after_email"]);
+		$user_context = check_str($row["user_context"]);
+		$toll_allow = check_str($row["toll_allow"]);
+		$call_group = check_str($row["callgroup"]);
+		$hold_music = check_str($row["hold_music"]);
+		$auth_acl = check_str($row["auth_acl"]);
+		$cidr = check_str($row["cidr"]);
+		$sip_force_contact = check_str($row["sip_force_contact"]);
+		$nibble_account = check_str($row["nibble_account"]);
+		$sip_force_expires = check_str($row["sip_force_expires"]);
+		$enabled = check_str($row["enabled"]);
+		$description = check_str($row["description"]);
+		$mwi_account = check_str($row["mwi_account"]);
+		$sip_bypass_media = check_str($row["sip_bypass_media"]);
+
+		$sql = "insert into v_extensions ";
+		$sql .= "(";
+		$sql .= "extension_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "extension, ";
+		$sql .= "number_alias, ";
+		$sql .= "password, ";
+		$sql .= "provisioning_list, ";
+		$sql .= "mailbox, ";
+		$sql .= "vm_password, ";
+		$sql .= "accountcode, ";
+		$sql .= "effective_caller_id_name, ";
+		$sql .= "effective_caller_id_number, ";
+		$sql .= "outbound_caller_id_name, ";
+		$sql .= "outbound_caller_id_number, ";
+		$sql .= "limit_max, ";
+		$sql .= "limit_destination, ";
+		$sql .= "vm_enabled, ";
+		$sql .= "vm_mailto, ";
+		$sql .= "vm_attach_file, ";
+		$sql .= "vm_keep_local_after_email, ";
+		$sql .= "user_context, ";
+		$sql .= "toll_allow, ";
+		$sql .= "call_group, ";
+		$sql .= "hold_music, ";
+		$sql .= "auth_acl, ";
+		$sql .= "cidr, ";
+		$sql .= "sip_force_contact, ";
+		$sql .= "nibble_account, ";
+		$sql .= "sip_force_expires, ";
+		$sql .= "enabled, ";
+		$sql .= "description, ";
+		$sql .= "mwi_account, ";
+		$sql .= "sip_bypass_media ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$extension_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$extension."', ";
+		$sql .= "'".$number_alias."', ";
+		$sql .= "'".$password."', ";
+		$sql .= "'".$provisioning_list."', ";
+		$sql .= "'".$mailbox."', ";
+		$sql .= "'".$vm_password."', ";
+		$sql .= "'".$accountcode."', ";
+		$sql .= "'".$effective_caller_id_name."', ";
+		$sql .= "'".$effective_caller_id_number."', ";
+		$sql .= "'".$outbound_caller_id_name."', ";
+		$sql .= "'".$outbound_caller_id_number."', ";
+		if (strlen($limit_max) > 0) {
+			$sql .= "'".$limit_max."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$limit_destination."', ";
+		$sql .= "'".$vm_enabled."', ";
+		$sql .= "'".$vm_mailto."', ";
+		$sql .= "'".$vm_attach_file."', ";
+		$sql .= "'".$vm_keep_local_after_email."', ";
+		$sql .= "'".$user_context."', ";
+		$sql .= "'".$toll_allow."', ";
+		$sql .= "'".$call_group."', ";
+		$sql .= "'".$hold_music."', ";
+		$sql .= "'".$auth_acl."', ";
+		$sql .= "'".$cidr."', ";
+		$sql .= "'".$sip_force_contact."', ";
+		if (strlen($nibble_account) > 0) {
+			$sql .= "'".$nibble_account."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($sip_force_expires) > 0) {
+			$sql .= "'".$sip_force_expires."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$enabled."', ";
+		$sql .= "'".$description."', ";
+		$sql .= "'".$mwi_account."', ";
+		$sql .= "'".$sip_bypass_media."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+
+		$user_list_array = explode("|", $user_list);
+		foreach($user_list_array as $username){
+			if (strlen($username) > 0) {
+				$user_uuid = $user_array[$v_id][$username]['user_uuid'];
+				if (strlen($user_uuid) > 0) {
+					$sql = "insert into v_extension_users ";
+					$sql .= "(";
+					$sql .= "extension_user_uuid, ";
+					$sql .= "domain_uuid, ";
+					$sql .= "extension_uuid, ";
+					$sql .= "user_uuid ";
+					$sql .= ")";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$domain_uuid."', ";
+					$sql .= "'".$extension_uuid."', ";
+					$sql .= "'".$user_uuid."' ";
+					$sql .= ")";
+					if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+					if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+				}
+			}
+		}
+		unset($user_list_array, $username, $extension_uuid);
+	}
+	unset ($prep_statement);
+
+//get the conference identifiers
+	$sql = "select * from v_dialplan_includes_details ";
+	$sql .= "where field_data like 'conference_user_list%' ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$dialplan_include_id = $row["dialplan_include_id"];
+		$field_type = $row["field_type"];
+		$conference_array[$x]['dialplan_include_id'] = $dialplan_include_id;
+		$x++;
+	}
+	unset ($prepstatement);
+
+//get the conferences
+	$sql = "select * from v_dialplan_includes ";
+	$x = 0;
+	foreach ($conference_array as &$row) {
+		if ($x == 0) {
+			$sql .= " where dialplan_include_id = '".$row['dialplan_include_id']."' \n";
+		}
+		else {
+			$sql .= " or dialplan_include_id = '".$row['dialplan_include_id']."' \n";
+		}
+		$x++;
+	}
+	$sql .= "order by dialplan_order, extension_name asc ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll();
+	foreach ($result as &$tmp) {
+		//get the values from the database
+			$v_id = check_str($tmp["v_id"]);
+			$dialplan_include_id = check_str($tmp["dialplan_include_id"]);
+		//get the dialplan
+			$sql = "select * from v_dialplan_includes ";
+			$sql .= "where v_id = '$v_id' ";
+			$sql .= "and dialplan_include_id = '$dialplan_include_id' ";
+			$row = $db->query($sql)->fetch();
+			$conference_name = $row['extension_name'];
+			$conference_name = str_replace("-", " ", $conference_name);
+			//$context = $row['context'];
+			$conference_order = $row['dialplan_order'];
+			$conference_enabled = $row['enabled'];
+			$conference_description = $row['descr'];
+		//get the dialplan details
+			$sql = "select * from v_dialplan_includes_details ";
+			$sql .= "where v_id = '$v_id' ";
+			$sql .= "and dialplan_include_id = '$dialplan_include_id' ";
+			$prepstatement = $db->prepare(check_sql($sql));
+			$prepstatement->execute();
+			$result_details = $prepstatement->fetchAll();
+			foreach ($result_details as &$row) {
+				if ($row['field_type'] == "destination_number") {
+					$conference_extension = $row['field_data'];
+					$conference_extension = trim($conference_extension, '^$');
+				}
+				$field_data_array = explode("=", $row['field_data']);
+				if ($field_data_array[0] == "conference_user_list") {
+					$user_list = $field_data_array[1];
+				}
+				if ($row['field_type'] == "conference") {
+					$field_data = $row['field_data'];
+					$tmp_pos = stripos($field_data, "@");
+					if ($tmp_pos !== false) {
+						$tmp_field_data = substr($field_data, $tmp_pos+1, strlen($field_data));
+						$tmp_field_data_array = explode("+",$tmp_field_data);
+						foreach ($tmp_field_data_array as &$tmp_row) {
+							if (is_numeric($tmp_row)) {
+								$conference_pin_number = $tmp_row;
+							}
+							if (substr($tmp_row, 0, 5) == "flags") {
+								$conference_flags = substr($tmp_row, 6, $tmp_row-1);
+							}
+						}
+						$conference_profile = $tmp_field_data_array[0];
+					}
+				}
+			}
+		//get the uuids
+			$dialplan_uuid = $dialplan_array[$dialplan_include_id]['dialplan_uuid'];
+			$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+			$conference_uuid = uuid();
+		//add the conference
+			$sql = "insert into v_conferences ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "conference_uuid, ";
+			$sql .= "dialplan_uuid, ";
+			$sql .= "conference_name, ";
+			$sql .= "conference_extension, ";
+			$sql .= "conference_pin_number, ";
+			$sql .= "conference_profile, ";
+			$sql .= "conference_flags, ";
+			$sql .= "conference_order, ";
+			$sql .= "conference_description, ";
+			$sql .= "conference_enabled ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'$domain_uuid', ";
+			$sql .= "'$conference_uuid', ";
+			$sql .= "'$dialplan_uuid', ";
+			$sql .= "'$conference_name', ";
+			$sql .= "'$conference_extension', ";
+			$sql .= "'$conference_pin_number', ";
+			$sql .= "'$conference_profile', ";
+			$sql .= "'$conference_flags', ";
+			$sql .= "'$conference_order', ";
+			$sql .= "'$conference_description', ";
+			$sql .= "'$conference_enabled' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+
+		//add the assigned users to the conference
+			$user_list_array = explode("|", $user_list);
+			foreach($user_list_array as $username){
+				if (strlen($username) > 0) {
+					$user_uuid = $user_array[$v_id][$username]['user_uuid'];
+					if (strlen($user_uuid) > 0) {
+						$sql = "insert into v_conference_users ";
+						$sql .= "(";
+						$sql .= "conference_user_uuid, ";
+						$sql .= "domain_uuid, ";
+						$sql .= "conference_uuid, ";
+						$sql .= "user_uuid ";
+						$sql .= ")";
+						$sql .= "values ";
+						$sql .= "(";
+						$sql .= "'".uuid()."', ";
+						$sql .= "'".$domain_uuid."', ";
+						$sql .= "'".$conference_uuid."', ";
+						$sql .= "'".$user_uuid."' ";
+						$sql .= ")";
+						if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+						if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+					}
+				}
+			}
+			unset($user_list_array);
+	}
+	unset ($prepstatement, $result, $sql, $user_list);
+
+//get the fax information
+	$sql = "select * from v_fax ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$fax_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$fax_extension = check_str($row["fax_extension"]);
+		$fax_name = check_str($row["fax_name"]);
+		$fax_email = check_str($row["fax_email"]);
+		$fax_pin_number = check_str($row["fax_pin_number"]);
+		$fax_caller_id_name = check_str($row["fax_caller_id_name"]);
+		$fax_caller_id_number = check_str($row["fax_caller_id_number"]);
+		$fax_user_list = check_str($row["fax_user_list"]);
+		$fax_forward_number = check_str($row["fax_forward_number"]);
+		$fax_description = check_str($row["fax_description"]);
+
+		$sql = "insert into v_fax ";
+		$sql .= "(";
+		$sql .= "fax_uuid, ";
+		$sql .= "domain_uuid, ";
+		//dialplan_uuid
+		$sql .= "fax_extension, ";
+		$sql .= "fax_name, ";
+		$sql .= "fax_email, ";
+		$sql .= "fax_pin_number, ";
+		$sql .= "fax_caller_id_name, ";
+		$sql .= "fax_caller_id_number, ";
+		$sql .= "fax_forward_number, ";
+		$sql .= "fax_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$fax_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		//dialplan_uuid
+		$sql .= "'".$fax_extension."', ";
+		$sql .= "'".$fax_name."', ";
+		$sql .= "'".$fax_email."', ";
+		$sql .= "'".$fax_pin_number."', ";
+		$sql .= "'".$fax_caller_id_name."', ";
+		$sql .= "'".$fax_caller_id_number."', ";
+		if (strlen($fax_forward_number) > 0) {
+			$sql .= "'".$fax_forward_number."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$fax_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+
+		$user_list_array = explode("|", $fax_user_list);
+		foreach($user_list_array as $username){
+			if (strlen($username) > 0) {
+				$user_uuid = $user_array[$v_id][$username]['user_uuid'];
+				if (strlen($user_uuid) > 0) {
+					$sql = "insert into v_fax_users ";
+					$sql .= "(";
+					$sql .= "fax_user_uuid, ";
+					$sql .= "domain_uuid, ";
+					$sql .= "fax_uuid, ";
+					$sql .= "user_uuid ";
+					$sql .= ")";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$domain_uuid."', ";
+					$sql .= "'".$fax_uuid."', ";
+					$sql .= "'".$user_uuid."' ";
+					$sql .= ")";
+					if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+					if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+				}
+			}
+		}
+		unset($user_list_array);
+		unset($username);
+	}
+	unset ($prep_statement);
+
+//export the gateways
+	$sql = "select * from v_gateways ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$gateway_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$gateway = check_str($row["gateway"]);
+		$username = check_str($row["username"]);
+		$password = check_str($row["password"]);
+		$auth_username = check_str($row["auth_username"]);
+		$realm = check_str($row["realm"]);
+		$from_user = check_str($row["from_user"]);
+		$from_domain = check_str($row["from_domain"]);
+		$proxy = check_str($row["proxy"]);
+		$register_proxy = check_str($row["register_proxy"]);
+		$outbound_proxy = check_str($row["outbound_proxy"]);
+		$expire_seconds = check_str($row["expire_seconds"]);
+		$register = check_str($row["register"]);
+		$register_transport = check_str($row["register_transport"]);
+		$retry_seconds = check_str($row["retry_seconds"]);
+		$extension = check_str($row["extension"]);
+		$ping = check_str($row["ping"]);
+		$caller_id_in_from = check_str($row["caller_id_in_from"]);
+		$supress_cng = check_str($row["supress_cng"]);
+		$sip_cid_type = check_str($row["sip_cid_type"]);
+		$extension_in_contact = check_str($row["extension_in_contact"]);
+		$context = check_str($row["context"]);
+		$profile = check_str($row["profile"]);
+		$enabled = check_str($row["enabled"]);
+		$description = check_str($row["description"]);
+
+		$sql = "insert into v_gateways ";
+		$sql .= "(";
+		$sql .= "gateway_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "gateway, ";
+		$sql .= "username, ";
+		$sql .= "password, ";
+		$sql .= "auth_username, ";
+		$sql .= "realm, ";
+		$sql .= "from_user, ";
+		$sql .= "from_domain, ";
+		$sql .= "proxy, ";
+		$sql .= "register_proxy, ";
+		$sql .= "outbound_proxy, ";
+		$sql .= "expire_seconds, ";
+		$sql .= "register, ";
+		$sql .= "register_transport, ";
+		$sql .= "retry_seconds, ";
+		$sql .= "extension, ";
+		$sql .= "ping, ";
+		$sql .= "caller_id_in_from, ";
+		$sql .= "supress_cng, ";
+		$sql .= "sip_cid_type, ";
+		$sql .= "extension_in_contact, ";
+		$sql .= "context, ";
+		$sql .= "profile, ";
+		$sql .= "enabled, ";
+		$sql .= "description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$gateway_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$gateway."', ";
+		$sql .= "'".$username."', ";
+		$sql .= "'".$password."', ";
+		$sql .= "'".$auth_username."', ";
+		$sql .= "'".$realm."', ";
+		$sql .= "'".$from_user."', ";
+		$sql .= "'".$from_domain."', ";
+		$sql .= "'".$proxy."', ";
+		$sql .= "'".$register_proxy."', ";
+		$sql .= "'".$outbound_proxy."', ";
+		$sql .= "'".$expire_seconds."', ";
+		$sql .= "'".$register."', ";
+		$sql .= "'".$register_transport."', ";
+		$sql .= "'".$retry_seconds."', ";
+		$sql .= "'".$extension."', ";
+		$sql .= "'".$ping."', ";
+		$sql .= "'".$caller_id_in_from."', ";
+		$sql .= "'".$supress_cng."', ";
+		$sql .= "'".$sip_cid_type."', ";
+		$sql .= "'".$extension_in_contact."', ";
+		$sql .= "'".$context."', ";
+		$sql .= "'".$profile."', ";
+		$sql .= "'".$enabled."', ";
+		$sql .= "'".$description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the provisioning information
+	$sql = "select * from v_hardware_phones ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$hardware_phone_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$phone_mac_address = check_str($row["phone_mac_address"]);
+		$phone_label = check_str($row["phone_label"]);
+		$phone_vendor = check_str($row["phone_vendor"]);
+		$phone_model = check_str($row["phone_model"]);
+		$phone_firmware_version = check_str($row["phone_firmware_version"]);
+		$phone_provision_enable = check_str($row["phone_provision_enable"]);
+		$phone_template = check_str($row["phone_template"]);
+		$phone_username = check_str($row["phone_username"]);
+		$phone_password = check_str($row["phone_password"]);
+		$phone_time_zone = check_str($row["phone_time_zone"]);
+		$phone_description = check_str($row["phone_description"]);
+
+		$sql = "insert into v_hardware_phones ";
+		$sql .= "(";
+		$sql .= "hardware_phone_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "phone_mac_address, ";
+		$sql .= "phone_label, ";
+		$sql .= "phone_vendor, ";
+		$sql .= "phone_model, ";
+		$sql .= "phone_firmware_version, ";
+		$sql .= "phone_provision_enable, ";
+		$sql .= "phone_template, ";
+		$sql .= "phone_username, ";
+		$sql .= "phone_password, ";
+		$sql .= "phone_time_zone, ";
+		$sql .= "phone_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$hardware_phone_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$phone_mac_address."', ";
+		$sql .= "'".$phone_label."', ";
+		$sql .= "'".$phone_vendor."', ";
+		$sql .= "'".$phone_model."', ";
+		$sql .= "'".$phone_firmware_version."', ";
+		$sql .= "'".$phone_provision_enable."', ";
+		$sql .= "'".$phone_template."', ";
+		$sql .= "'".$phone_username."', ";
+		$sql .= "'".$phone_password."', ";
+		$sql .= "'".$phone_time_zone."', ";
+		$sql .= "'".$phone_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the hunt groups
+	$sql = "select * from v_hunt_group ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$hunt_group_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$hunt_group_extension = check_str($row["hunt_group_extension"]);
+		$hunt_group_id = check_str($row["hunt_group_id"]);
+		$hunt_group_name = check_str($row["hunt_group_name"]);
+		$hunt_group_type = check_str($row["hunt_group_type"]);
+		$hunt_group_context = check_str($row["hunt_group_context"]);
+		$hunt_group_timeout = check_str($row["hunt_group_timeout"]);
+		$hunt_group_timeout_destination = check_str($row["hunt_group_timeout_destination"]);
+		$hunt_group_timeout_type = check_str($row["hunt_group_time_out_type"]);
+		$hunt_group_ringback = check_str($row["hunt_group_ringback"]);
+		$hunt_group_cid_name_prefix = check_str($row["hunt_group_cid_name_prefix"]);
+		$hunt_group_pin = check_str($row["hunt_group_pin"]);
+		$hunt_group_caller_announce = check_str($row["hunt_group_caller_announce"]);
+		$hunt_group_call_prompt = check_str($row["hunt_group_call_prompt"]);
+		$hunt_group_user_list = check_str($row["hunt_group_user_list"]);
+		$hunt_group_enabled = check_str($row["hunt_group_enabled"]);
+		$hunt_group_description = check_str($row["hunt_group_descr"]);
+
+		//set the hunt_group_uuid
+		$hunt_group_array[$hunt_group_id]['hunt_group_uuid'] = $hunt_group_uuid;
+
+		$sql = "insert into v_hunt_groups ";
+		$sql .= "(";
+		$sql .= "hunt_group_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "hunt_group_extension, ";
+		$sql .= "hunt_group_name, ";
+		$sql .= "hunt_group_type, ";
+		$sql .= "hunt_group_context, ";
+		$sql .= "hunt_group_timeout, ";
+		$sql .= "hunt_group_timeout_destination, ";
+		$sql .= "hunt_group_timeout_type, ";
+		$sql .= "hunt_group_ringback, ";
+		$sql .= "hunt_group_cid_name_prefix, ";
+		$sql .= "hunt_group_pin, ";
+		$sql .= "hunt_group_caller_announce, ";
+		$sql .= "hunt_group_call_prompt, ";
+		$sql .= "hunt_group_user_list, ";
+		$sql .= "hunt_group_enabled, ";
+		$sql .= "hunt_group_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$hunt_group_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$hunt_group_extension."', ";
+		$sql .= "'".$hunt_group_name."', ";
+		$sql .= "'".$hunt_group_type."', ";
+		$sql .= "'".$hunt_group_context."', ";
+		$sql .= "'".$hunt_group_timeout."', ";
+		$sql .= "'".$hunt_group_timeout_destination."', ";
+		$sql .= "'".$hunt_group_timeout_type."', ";
+		$sql .= "'".$hunt_group_ringback."', ";
+		$sql .= "'".$hunt_group_cid_name_prefix."', ";
+		$sql .= "'".$hunt_group_pin."', ";
+		$sql .= "'".$hunt_group_caller_announce."', ";
+		$sql .= "'".$hunt_group_call_prompt."', ";
+		$sql .= "'".$hunt_group_user_list."', ";
+		$sql .= "'".$hunt_group_enabled."', ";
+		$sql .= "'".$hunt_group_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the hunt group destinations
+	$sql = "select * from v_hunt_group_destinations ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$hunt_group_destination_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$hunt_group_id = check_str($row["hunt_group_id"]);
+		$destination_data = check_str($row["destination_data"]);
+		$destination_type = check_str($row["destination_type"]);
+		$destination_profile = check_str($row["destination_profile"]);
+		$destination_timeout = check_str($row["destination_timeout"]);
+		$destination_order = check_str($row["destination_order"]);
+		$destination_enabled = check_str($row["destination_enabled"]);
+		$destination_description = check_str($row["destination_descr"]);
+
+		//get the hunt_group_uuid
+		$hunt_group_uuid = $hunt_group_array[$hunt_group_id]['hunt_group_uuid'];
+
+		$sql = "insert into v_hunt_group_destinations ";
+		$sql .= "(";
+		$sql .= "hunt_group_destination_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "hunt_group_uuid, ";
+		$sql .= "destination_data, ";
+		$sql .= "destination_type, ";
+		$sql .= "destination_profile, ";
+		$sql .= "destination_timeout, ";
+		$sql .= "destination_order, ";
+		$sql .= "destination_enabled, ";
+		$sql .= "destination_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$hunt_group_destination_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$hunt_group_uuid."', ";
+		$sql .= "'".$destination_data."', ";
+		$sql .= "'".$destination_type."', ";
+		$sql .= "'".$destination_profile."', ";
+		$sql .= "'".$destination_timeout."', ";
+		if (strlen($destination_order) > 0) {
+			$sql .= "'".$destination_order."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$destination_enabled."', ";
+		$sql .= "'".$destination_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the invoices
+	if ($invoices) {
+		//get the invoices and insert them
+			$sql = "select * from v_invoices ";
+			$prep_statement = $db->prepare($sql);
+			$prep_statement->execute();
+			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+			foreach ($result as &$row) {
+				$invoice_id = check_str($row["invoice_id"]);
+				//set the invoice_uuid
+				$invoice_array[$invoice_id]['uuid'] = uuid();
+			}
+			foreach ($result as &$row) {
+				$invoice_id = check_str($row["invoice_id"]);
+				$invoice_uuid = uuid();
+				$v_id = check_str($row["v_id"]);
+				$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+				$contact_id_from = check_str($row["contact_id_from"]);
+				$contact_id_to = check_str($row["contact_id_to"]);
+				$invoice_number = check_str($row["invoice_number"]);
+				$invoice_date = check_str($row["invoice_date"]);
+				$invoice_notes = check_str($row["invoice_notes"]);
+
+				//get the uuids
+				$invoice_uuid = $invoice_array[$invoice_id]['uuid'];
+				$contact_uuid_from = $contact_array[$contact_id_from]['contact_uuid'];
+				$contact_uuid_to = $contact_array[$contact_id_to]['contact_uuid'];
+
+				$sql = "insert into v_invoices ";
+				$sql .= "(";
+				$sql .= "invoice_uuid, ";
+				$sql .= "domain_uuid, ";
+				$sql .= "contact_uuid_from, ";
+				$sql .= "contact_uuid_to, ";
+				$sql .= "invoice_number, ";
+				$sql .= "invoice_date, ";
+				$sql .= "invoice_notes ";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$invoice_uuid."', ";
+				$sql .= "'".$domain_uuid."', ";
+				if (strlen($contact_uuid_from) > 0) {
+					$sql .= "'".$contact_uuid_from."', ";
+				}
+				else {
+					$sql .= "null, ";
+				}
+				if (strlen($contact_uuid_to) > 0) {
+					$sql .= "'".$contact_uuid_to."', ";
+				}
+				else {
+					$sql .= "null, ";
+				}
+				if (strlen($invoice_number) > 0) {
+					$sql .= "'".$invoice_number."', ";
+				}
+				else {
+					$sql .= "null, ";
+				}
+				$sql .= "'".$invoice_date."', ";
+				$sql .= "'".$invoice_notes."' ";
+				$sql .= ")";
+				if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+				if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+			}
+			unset ($prep_statement);
+
+		//export invoice items
+			$sql = "select * from v_invoice_items ";
+			$prep_statement = $db->prepare($sql);
+			$prep_statement->execute();
+			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+			foreach ($result as &$row) {
+				$invoice_item_uuid = uuid();
+				$v_id = check_str($row["v_id"]);
+				$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+				$invoice_id = check_str($row["invoice_id"]);
+				$item_qty = check_str($row["item_qty"]);
+				$item_description = check_str($row["item_desc"]);
+				$item_unit_price = check_str($row["item_unit_price"]);
+
+				//get the invoice_uuid
+				$invoice_uuid = $invoice_array[$invoice_id]['uuid'];
+
+				$sql = "insert into v_invoice_items ";
+				$sql .= "(";
+				$sql .= "invoice_item_uuid, ";
+				$sql .= "domain_uuid, ";
+				$sql .= "invoice_uuid, ";
+				$sql .= "item_qty, ";
+				$sql .= "item_desc, ";
+				$sql .= "item_unit_price ";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$invoice_item_uuid."', ";
+				$sql .= "'".$domain_uuid."', ";
+				$sql .= "'".$invoice_uuid."', ";
+				if (strlen($item_qty) > 0) {
+					$sql .= "'".$item_qty."', ";
+				}
+				else {
+					$sql .= "null, ";
+				}
+				$sql .= "'".$item_desc."', ";
+				if (strlen($item_unit_price) > 0) {
+					$sql .= "'".$item_unit_price."' ";
+				}
+				else {
+					$sql .= "null ";
+				}
+				$sql .= ")";
+				if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+				if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+			}
+			unset ($prep_statement);
+	}
+
+//export the ivr menus
+	$sql = "select * from v_ivr_menu ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$ivr_menu_id = check_str($row["ivr_menu_id"]);
+		$ivr_menu_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$ivr_menu_name = check_str($row["ivr_menu_name"]);
+		$ivr_menu_extension = check_str($row["ivr_menu_extension"]);
+		$ivr_menu_greet_long = check_str($row["ivr_menu_greet_long"]);
+		$ivr_menu_greet_short = check_str($row["ivr_menu_greet_short"]);
+		$ivr_menu_invalid_sound = check_str($row["ivr_menu_invalid_sound"]);
+		$ivr_menu_exit_sound = check_str($row["ivr_menu_exit_sound"]);
+		$ivr_menu_confirm_macro = check_str($row["ivr_menu_confirm_macro"]);
+		$ivr_menu_confirm_key = check_str($row["ivr_menu_confirm_key"]);
+		$ivr_menu_tts_engine = check_str($row["ivr_menu_tts_engine"]);
+		$ivr_menu_tts_voice = check_str($row["ivr_menu_tts_voice"]);
+		$ivr_menu_confirm_attempts = check_str($row["ivr_menu_confirm_attempts"]);
+		$ivr_menu_timeout = check_str($row["ivr_menu_timeout"]);
+		$ivr_menu_exit_app = check_str($row["ivr_menu_exit_app"]);
+		$ivr_menu_exit_data = check_str($row["ivr_menu_exit_data"]);
+		$ivr_menu_inter_digit_timeout = check_str($row["ivr_menu_inter_digit_timeout"]);
+		$ivr_menu_max_failures = check_str($row["ivr_menu_max_failures"]);
+		$ivr_menu_max_timeouts = check_str($row["ivr_menu_max_timeouts"]);
+		$ivr_menu_digit_len = check_str($row["ivr_menu_digit_len"]);
+		$ivr_menu_direct_dial = check_str($row["ivr_menu_direct_dial"]);
+		$ivr_menu_enabled = check_str($row["ivr_menu_enabled"]);
+		$ivr_menu_description = check_str($row["ivr_menu_desc"]);
+
+		//set the ivr_menu_uuid
+		$ivr_menu_array[$ivr_menu_id]['ivr_menu_uuid'] = $ivr_menu_uuid;
+
+		$sql = "insert into v_ivr_menus ";
+		$sql .= "(";
+		$sql .= "ivr_menu_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "ivr_menu_name, ";
+		$sql .= "ivr_menu_extension, ";
+		$sql .= "ivr_menu_greet_long, ";
+		$sql .= "ivr_menu_greet_short, ";
+		$sql .= "ivr_menu_invalid_sound, ";
+		$sql .= "ivr_menu_exit_sound, ";
+		$sql .= "ivr_menu_confirm_macro, ";
+		$sql .= "ivr_menu_confirm_key, ";
+		$sql .= "ivr_menu_tts_engine, ";
+		$sql .= "ivr_menu_tts_voice, ";
+		$sql .= "ivr_menu_confirm_attempts, ";
+		$sql .= "ivr_menu_timeout, ";
+		$sql .= "ivr_menu_exit_app, ";
+		$sql .= "ivr_menu_exit_data, ";
+		$sql .= "ivr_menu_inter_digit_timeout, ";
+		$sql .= "ivr_menu_max_failures, ";
+		$sql .= "ivr_menu_max_timeouts, ";
+		$sql .= "ivr_menu_digit_len, ";
+		$sql .= "ivr_menu_direct_dial, ";
+		$sql .= "ivr_menu_enabled, ";
+		$sql .= "ivr_menu_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$ivr_menu_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$ivr_menu_name."', ";
+		$sql .= "'".$ivr_menu_extension."', ";
+		$sql .= "'".$ivr_menu_greet_long."', ";
+		$sql .= "'".$ivr_menu_greet_short."', ";
+		$sql .= "'".$ivr_menu_invalid_sound."', ";
+		$sql .= "'".$ivr_menu_exit_sound."', ";
+		$sql .= "'".$ivr_menu_confirm_macro."', ";
+		$sql .= "'".$ivr_menu_confirm_key."', ";
+		$sql .= "'".$ivr_menu_tts_engine."', ";
+		$sql .= "'".$ivr_menu_tts_voice."', ";
+		$sql .= "'".$ivr_menu_confirm_attempts."', ";
+		$sql .= "'".$ivr_menu_timeout."', ";
+		$sql .= "'".$ivr_menu_exit_app."', ";
+		$sql .= "'".$ivr_menu_exit_data."', ";
+		$sql .= "'".$ivr_menu_inter_digit_timeout."', ";
+		$sql .= "'".$ivr_menu_max_failures."', ";
+		$sql .= "'".$ivr_menu_max_timeouts."', ";
+		$sql .= "'".$ivr_menu_digit_len."', ";
+		$sql .= "'".$ivr_menu_direct_dial."', ";
+		$sql .= "'".$ivr_menu_enabled."', ";
+		$sql .= "'".$ivr_menu_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the ivr menu options
+	$sql = "select * from v_ivr_menu_options ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$ivr_menu_option_uuid = uuid();
+		$ivr_menu_id = check_str($row["ivr_menu_id"]);
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$ivr_menu_option_digits = check_str($row["ivr_menu_options_digits"]);
+		$ivr_menu_option_action = check_str($row["ivr_menu_options_action"]);
+		$ivr_menu_option_param = check_str($row["ivr_menu_options_param"]);
+		$ivr_menu_option_order = check_str($row["ivr_menu_options_order"]);
+		$ivr_menu_option_description = check_str($row["ivr_menu_options_desc"]);
+		$ivr_menu_options_action = str_replace("\\\\", "\\", $ivr_menu_options_action);
+
+		//get the ivr_menu_uuid
+		$ivr_menu_uuid = $ivr_menu_array[$ivr_menu_id]['ivr_menu_uuid'];
+
+		$sql = "insert into v_ivr_menu_options ";
+		$sql .= "(";
+		$sql .= "ivr_menu_option_uuid, ";
+		$sql .= "ivr_menu_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "ivr_menu_option_digits, ";
+		$sql .= "ivr_menu_option_action, ";
+		$sql .= "ivr_menu_option_param, ";
+		$sql .= "ivr_menu_option_order, ";
+		$sql .= "ivr_menu_option_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$ivr_menu_option_uuid."', ";
+		$sql .= "'".$ivr_menu_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$ivr_menu_option_digits."', ";
+		$sql .= "'".$ivr_menu_option_action."', ";
+		$sql .= "'".$ivr_menu_option_param."', ";
+		$sql .= "'".$ivr_menu_option_order."', ";
+		$sql .= "'".$ivr_menu_option_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the modules
+	$sql = "select * from v_modules ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$module_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$module_label = check_str($row["module_label"]);
+		$module_name = check_str($row["module_name"]);
+		$module_description = check_str($row["module_desc"]);
+		$module_category = check_str($row["module_category"]);
+		$module_enabled = check_str($row["module_enabled"]);
+		$module_default_enabled = check_str($row["module_default_enabled"]);
+
+		$sql = "insert into v_modules ";
+		$sql .= "(";
+		$sql .= "module_uuid, ";
+		$sql .= "module_label, ";
+		$sql .= "module_name, ";
+		$sql .= "module_description, ";
+		$sql .= "module_category, ";
+		$sql .= "module_enabled, ";
+		$sql .= "module_default_enabled ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$module_uuid."', ";
+		$sql .= "'".$module_label."', ";
+		$sql .= "'".$module_name."', ";
+		$sql .= "'".$module_description."', ";
+		$sql .= "'".$module_category."', ";
+		$sql .= "'".$module_enabled."', ";
+		$sql .= "'".$module_default_enabled."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export to php services
+	$sql = "select * from v_php_service ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$php_service_uuid = uuid();
+		$service_name = check_str($row["service_name"]);
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$service_script = check_str($row["service_script"]);
+		$service_enabled = check_str($row["service_enabled"]);
+		$service_description = check_str($row["service_description"]);
+
+		$sql = "insert into v_php_services ";
+		$sql .= "(";
+		$sql .= "php_service_uuid, ";
+		$sql .= "service_name, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "service_script, ";
+		$sql .= "service_enabled, ";
+		$sql .= "service_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$php_service_uuid."', ";
+		$sql .= "'".$service_name."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$service_script."', ";
+		$sql .= "'".$service_enabled."', ";
+		$sql .= "'".$service_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the recordings
+	$sql = "select * from v_recordings ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$recording_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$recording_filename = check_str($row["recording_filename"]);
+		$recording_name = check_str($row["recording_name"]);
+		$recording_description = check_str($row["recording_desc"]);
+
+		$sql = "insert into v_recordings ";
+		$sql .= "(";
+		$sql .= "recording_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "recording_filename, ";
+		$sql .= "recording_name, ";
+		$sql .= "recording_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$recording_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$recording_filename."', ";
+		$sql .= "'".$recording_name."', ";
+		$sql .= "'".$recording_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the services
+	$sql = "select * from v_services ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$service_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$service_name = check_str($row["v_service_name"]);
+		$service_type = check_str($row["v_service_type"]);
+		$service_data = check_str($row["v_service_data"]);
+		$service_cmd_start = check_str($row["v_service_cmd_start"]);
+		$service_cmd_stop = check_str($row["v_service_cmd_stop"]);
+		$service_cmd_restart = check_str($row["v_service_cmd_restart"]);
+		$service_description = check_str($row["v_service_desc"]);
+
+		$sql = "insert into v_services ";
+		$sql .= "(";
+		$sql .= "service_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "service_name, ";
+		$sql .= "service_type, ";
+		$sql .= "service_data, ";
+		$sql .= "service_cmd_start, ";
+		$sql .= "service_cmd_stop, ";
+		$sql .= "service_cmd_restart, ";
+		$sql .= "service_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$service_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$service_name."', ";
+		$sql .= "'".$service_type."', ";
+		$sql .= "'".$service_data."', ";
+		$sql .= "'".$service_cmd_start."', ";
+		$sql .= "'".$service_cmd_stop."', ";
+		$sql .= "'".$service_cmd_restart."', ";
+		$sql .= "'".$service_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the settings
+	$sql = "select * from v_settings ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$numbering_plan = check_str($row["numbering_plan"]);
+		$smtp_password = check_str($row["default_gateway"]);
+		$event_socket_ip_address = check_str($row["event_socket_ip_address"]);
+		$event_socket_port = check_str($row["event_socket_port"]);
+		$event_socket_password = check_str($row["event_socket_password"]);
+		$xml_rpc_http_port = check_str($row["xml_rpc_http_port"]);
+		$xml_rpc_auth_realm = check_str($row["xml_rpc_auth_realm"]);
+		$xml_rpc_auth_user = check_str($row["xml_rpc_auth_user"]);
+		$xml_rpc_auth_pass = check_str($row["xml_rpc_auth_pass"]);
+		$admin_pin = check_str($row["admin_pin"]);
+		$smtp_host = check_str($row["smtp_host"]);
+		$smtp_secure = check_str($row["smtp_secure"]);
+		$smtp_auth = check_str($row["smtp_auth"]);
+		$smtp_username = check_str($row["smtp_username"]);
+		$smtp_password = check_str($row["smtp_password"]);
+		$smtp_from = check_str($row["smtp_from"]);
+		$smtp_from_name = check_str($row["smtp_from_name"]);
+		$mod_shout_decoder = check_str($row["mod_shout_decoder"]);
+		$mod_shout_volume = check_str($row["mod_shout_volume"]);
+
+		$sql = "insert into v_settings ";
+		$sql .= "(";
+		$sql .= "numbering_plan, ";
+		$sql .= "event_socket_ip_address, ";
+		$sql .= "event_socket_port, ";
+		$sql .= "event_socket_password, ";
+		$sql .= "xml_rpc_http_port, ";
+		$sql .= "xml_rpc_auth_realm, ";
+		$sql .= "xml_rpc_auth_user, ";
+		$sql .= "xml_rpc_auth_pass, ";
+		$sql .= "admin_pin, ";
+		$sql .= "smtp_host, ";
+		$sql .= "smtp_secure, ";
+		$sql .= "smtp_auth, ";
+		$sql .= "smtp_username, ";
+		$sql .= "smtp_password, ";
+		$sql .= "smtp_from, ";
+		$sql .= "smtp_from_name, ";
+		$sql .= "mod_shout_decoder, ";
+		$sql .= "mod_shout_volume ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$numbering_plan."', ";
+		$sql .= "'".$event_socket_ip_address."', ";
+		$sql .= "'".$event_socket_port."', ";
+		$sql .= "'".$event_socket_password."', ";
+		$sql .= "'".$xml_rpc_http_port."', ";
+		$sql .= "'".$xml_rpc_auth_realm."', ";
+		$sql .= "'".$xml_rpc_auth_user."', ";
+		$sql .= "'".$xml_rpc_auth_pass."', ";
+		$sql .= "'".$admin_pin."', ";
+		$sql .= "'".$smtp_host."', ";
+		$sql .= "'".$smtp_secure."', ";
+		$sql .= "'".$smtp_auth."', ";
+		$sql .= "'".$smtp_username."', ";
+		$sql .= "'".$smtp_password."', ";
+		$sql .= "'".$smtp_from."', ";
+		$sql .= "'".$smtp_from_name."', ";
+		$sql .= "'".$mod_shout_decoder."', ";
+		$sql .= "'".$mod_shout_volume."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//get the time conditions and use diaplan_uuid to set the app_uuid
+	$sql = "select * from v_dialplan_includes_details ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$dialplan_include_id = $row["dialplan_include_id"];
+		$field_type = $row["field_type"];
+		//$field_data = $row["field_data"];
+
+		//get the dialplan_uuid
+		$dialplan_uuid = $dialplan_array[$dialplan_include_id]['dialplan_uuid'];
+
+		switch ($row['field_type']) {
+		case "hour":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "minute":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "minute-of-day":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "mday":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "mweek":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "mon":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "yday":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "year":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "wday":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		case "week":
+			$time_array[$x]['dialplan_uuid'] = $dialplan_uuid;
+			$x++;
+			break;
+		}
+	}
+	unset ($prepstatement);
+	foreach ($time_array as &$row) {
+		$sql = "update v_dialplans set ";
+		$sql .= "app_uuid = '4b821450-926b-175a-af93-a03c441818b1' ";
+		$sql .= "where dialplan_uuid = '".$row['dialplan_uuid']."' ";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		unset($sql);
+	}
+
+//get the variables
+	$sql = "select * from v_vars ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$var_uuid = uuid();
+		$var_name = check_str($row["var_name"]);
+		$var_value = check_str($row["var_value"]);
+		$var_cat = check_str($row["var_cat"]);
+		$var_enabled = check_str($row["var_enabled"]);
+		$var_order = check_str($row["var_order"]);
+		$var_description = check_str($row["var_desc"]);
+
+		$sql = "insert into v_vars ";
+		$sql .= "(";
+		$sql .= "var_uuid, ";
+		$sql .= "var_name, ";
+		$sql .= "var_value, ";
+		$sql .= "var_cat, ";
+		$sql .= "var_enabled, ";
+		$sql .= "var_order, ";
+		$sql .= "var_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$var_uuid."', ";
+		$sql .= "'".$var_name."', ";
+		$sql .= "'".$var_value."', ";
+		$sql .= "'".$var_cat."', ";
+		$sql .= "'".$var_enabled."', ";
+		$sql .= "'".$var_order."', ";
+		$sql .= "'".$var_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the virtual tables
+	$sql = "select * from v_virtual_tables ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$virtual_table_id = check_str($row["virtual_table_id"]);
+		$virtual_table_uuid = uuid();
+
+		//set the virtual_table_uuid
+		$virtual_table_array[$virtual_table_id]['virtual_table_uuid'] = $virtual_table_uuid;
+	}
+	foreach ($result as &$row) {
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$virtual_table_id = check_str($row["virtual_table_id"]);
+		$virtual_table_category = check_str($row["virtual_table_category"]);
+		$virtual_table_label = check_str($row["virtual_table_label"]);
+		$virtual_table_name = check_str($row["virtual_table_name"]);
+		$virtual_table_auth = check_str($row["virtual_table_auth"]);
+		$virtual_table_captcha = check_str($row["virtual_table_captcha"]);
+		$virtual_table_parent_id = check_str($row["virtual_table_parent_id"]);
+		$virtual_table_description = check_str($row["virtual_table_desc"]);
+
+		//get the uuids
+		$virtual_table_uuid = $virtual_table_array[$virtual_table_id]['virtual_table_uuid'];
+		if (strlen($virtual_table_parent_id) > 0) {
+			$virtual_table_parent_uuid = $virtual_table_array[$virtual_table_parent_id]['virtual_table_uuid'];
+		}
+
+		$sql = "insert into v_virtual_tables ";
+		$sql .= "(";
+		$sql .= "virtual_table_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "virtual_table_category, ";
+		$sql .= "virtual_table_label, ";
+		$sql .= "virtual_table_name, ";
+		$sql .= "virtual_table_auth, ";
+		$sql .= "virtual_table_captcha, ";
+		$sql .= "virtual_table_parent_uuid, ";
+		$sql .= "virtual_table_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$virtual_table_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$virtual_table_category."', ";
+		$sql .= "'".$virtual_table_label."', ";
+		$sql .= "'".$virtual_table_name."', ";
+		$sql .= "'".$virtual_table_auth."', ";
+		$sql .= "'".$virtual_table_captcha."', ";
+		if (strlen($virtual_table_parent_uuid) > 0) {
+			$sql .= "'".$virtual_table_parent_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$virtual_table_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//export the virtual table fields
+	$sql = "select * from v_virtual_table_fields ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$virtual_table_field_id = check_str($row["virtual_table_field_id"]);
+		$virtual_table_field_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$virtual_table_id = check_str($row["virtual_table_id"]);
+		$virtual_field_label = check_str($row["virtual_field_label"]);
+		$virtual_field_name = check_str($row["virtual_field_name"]);
+		$virtual_field_type = check_str($row["virtual_field_type"]);
+		$virtual_field_list_hidden = check_str($row["virtual_field_list_hidden"]);
+		$virtual_field_column = check_str($row["virtual_field_column"]);
+		$virtual_field_required = check_str($row["virtual_field_required"]);
+		$virtual_field_order = check_str($row["virtual_field_order"]);
+		$virtual_field_order_tab = check_str($row["virtual_field_order_tab"]);
+		$virtual_field_description = check_str($row["virtual_field_desc"]);
+		$virtual_field_value = check_str($row["virtual_field_value"]);
+
+		//get the virtual_table_uuid
+		$virtual_table_uuid = $virtual_table_array[$virtual_table_id]['virtual_table_uuid'];
+
+		//set virtual_table_field_uuid
+		$virtual_table_field_array[$virtual_table_field_id]['virtual_table_field_uuid'] = $virtual_table_field_uuid;
+		if (strlen($virtual_table_uuid) > 0) {
+			$sql = "insert into v_virtual_table_fields ";
+			$sql .= "(";
+			$sql .= "virtual_table_field_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "virtual_table_uuid, ";
+			$sql .= "virtual_field_label, ";
+			$sql .= "virtual_field_name, ";
+			$sql .= "virtual_field_type, ";
+			$sql .= "virtual_field_list_hidden, ";
+			$sql .= "virtual_field_column, ";
+			$sql .= "virtual_field_required, ";
+			$sql .= "virtual_field_order, ";
+			$sql .= "virtual_field_order_tab, ";
+			$sql .= "virtual_field_description, ";
+			$sql .= "virtual_field_value ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$virtual_table_field_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$virtual_table_uuid."', ";
+			$sql .= "'".$virtual_field_label."', ";
+			$sql .= "'".$virtual_field_name."', ";
+			$sql .= "'".$virtual_field_type."', ";
+			$sql .= "'".$virtual_field_list_hidden."', ";
+			$sql .= "'".$virtual_field_column."', ";
+			$sql .= "'".$virtual_field_required."', ";
+			$sql .= "'".$virtual_field_order."', ";
+			$sql .= "'".$virtual_field_order_tab."', ";
+			$sql .= "'".$virtual_field_description."', ";
+			$sql .= "'".$virtual_field_value."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export the virtual table data
+	$sql = "select * from v_virtual_table_data ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) {
+		$virtual_table_data_id = check_str($row["virtual_table_data_id"]);
+		$virtual_table_data_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$virtual_table_id = check_str($row["virtual_table_id"]);
+		$virtual_data_row_id = check_str($row["virtual_data_row_id"]);
+		$virtual_field_name = check_str($row["virtual_field_name"]);
+		$virtual_data_field_value = check_str($row["virtual_data_field_value"]);
+		$virtual_data_add_user = check_str($row["virtual_data_add_user"]);
+		$virtual_data_add_date = check_str($row["virtual_data_add_date"]);
+		$virtual_data_del_user = check_str($row["virtual_data_del_user"]);
+		$virtual_data_del_date = check_str($row["virtual_data_del_date"]);
+		$virtual_table_parent_id = check_str($row["virtual_table_parent_id"]);
+		$virtual_data_parent_row_uuid = check_str($row["virtual_data_parent_row_id"]);
+
+		//get the virtual_table_uuid
+		$virtual_table_uuid = $virtual_table_array[$virtual_table_id]['virtual_table_uuid'];
+		if (strlen($virtual_table_parent_id) > 0) {
+			$virtual_table_parent_uuid = $virtual_table_array[$virtual_table_parent_id]['virtual_table_uuid'];
+		}
+
+		//get or set the virtual table data row uuid
+		if (strlen($virtual_table_array[$virtual_data_row_id]['virtual_data_row_uuid']) == 0) {
+			$virtual_data_row_uuid = uuid();
+			$virtual_table_array[$virtual_data_row_id]['virtual_data_row_uuid'] = $virtual_data_row_uuid;
+		}
+		else {
+			$virtual_data_row_uuid = $virtual_table_array[$virtual_data_row_id]['virtual_data_row_uuid'];
+		}
+
+		$sql = "insert into v_virtual_table_data ";
+		$sql .= "(";
+		$sql .= "virtual_table_data_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "virtual_table_uuid, ";
+		$sql .= "virtual_data_row_uuid, ";
+		$sql .= "virtual_field_name, ";
+		$sql .= "virtual_data_field_value, ";
+		$sql .= "virtual_table_parent_uuid, ";
+		$sql .= "virtual_data_parent_row_uuid, ";
+		$sql .= "virtual_data_add_user, ";
+		$sql .= "virtual_data_add_date, ";
+		$sql .= "virtual_data_del_user, ";
+		$sql .= "virtual_data_del_date ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$virtual_table_data_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$virtual_table_uuid."', ";
+		$sql .= "'".$virtual_data_row_uuid."', ";
+		$sql .= "'".$virtual_field_name."', ";
+		$sql .= "'".$virtual_data_field_value."', ";
+		if (strlen($virtual_table_parent_uuid) > 0) {
+			$sql .= "'".$virtual_table_parent_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($virtual_data_parent_row_uuid) > 0) {
+			$sql .= "'".$virtual_data_parent_row_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$virtual_data_add_user."', ";
+		$sql .= "'".$virtual_data_add_date."', ";
+		$sql .= "'".$virtual_data_del_user."', ";
+		$sql .= "'".$virtual_data_del_date."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//get the virtual table data name value pairs
+	$sql = "select * from v_virtual_table_data_types_name_value ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$virtual_table_data_types_name_value_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$virtual_table_id = check_str($row["virtual_table_id"]);
+		$virtual_table_field_id = check_str($row["virtual_table_field_id"]);
+		$virtual_data_types_name = check_str($row["virtual_data_types_name"]);
+		$virtual_data_types_value = check_str($row["virtual_data_types_value"]);
+
+		//get the virtual_table_uuid
+		$virtual_table_uuid = $virtual_table_array[$virtual_table_id]['virtual_table_uuid'];
+
+		//get the virtual_table_field_uuid
+		$virtual_table_field_uuid = $virtual_table_field_array[$virtual_table_field_id]['virtual_table_field_uuid'];
+		if (strlen($virtual_table_uuid) > 0 && strlen($virtual_table_field_uuid) > 0) {
+			$sql = "insert into v_virtual_table_data_types_name_value ";
+			$sql .= "(";
+			$sql .= "virtual_table_data_types_name_value_uuid, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "virtual_table_uuid, ";
+			$sql .= "virtual_table_field_uuid, ";
+			$sql .= "virtual_data_types_name, ";
+			$sql .= "virtual_data_types_value ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$virtual_table_data_types_name_value_uuid."', ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$virtual_table_uuid."', ";
+			$sql .= "'".$virtual_table_field_uuid."', ";
+			$sql .= "'".$virtual_data_types_name."', ";
+			$sql .= "'".$virtual_data_types_value."' ";
+			$sql .= ")";
+			if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+			if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+		}
+	}
+	unset ($prep_statement);
+
+//export voicemail greetings
+	$sql = "select * from v_voicemail_greetings ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$greeting_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$user_id = check_str($row["user_id"]);
+		$greeting_name = check_str($row["greeting_name"]);
+		$greeting_description = check_str($row["greeting_description"]);
+
+		$sql = "insert into v_voicemail_greetings ";
+		$sql .= "(";
+		$sql .= "greeting_uuid, ";
+		$sql .= "user_id, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "greeting_name, ";
+		$sql .= "greeting_description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$greeting_uuid."', ";
+		$sql .= "'".$user_id."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$greeting_name."', ";
+		$sql .= "'".$greeting_description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//get the xmpp info
+	$sql = "select * from v_xmpp ";
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$xmpp_profile_uuid = uuid();
+		$v_id = check_str($row["v_id"]);
+		$domain_uuid = $domain_array[$v_id]['domain_uuid'];
+		$profile_name = check_str($row["profile_name"]);
+		$username = check_str($row["username"]);
+		$password = check_str($row["password"]);
+		$dialplan = check_str($row["dialplan"]);
+		$context = check_str($row["context"]);
+		$rtp_ip = check_str($row["rtp_ip"]);
+		$ext_rtp_ip = check_str($row["ext_rtp_ip"]);
+		$auto_login = check_str($row["auto_login"]);
+		$sasl_type = check_str($row["sasl_type"]);
+		$xmpp_server = check_str($row["xmpp_server"]);
+		$tls_enable = check_str($row["tls_enable"]);
+		$usr_rtp_timer = check_str($row["usr_rtp_timer"]);
+		$default_exten = check_str($row["default_exten"]);
+		$vad = check_str($row["vad"]);
+		$avatar = check_str($row["avatar"]);
+		$candidate_acl = check_str($row["candidate_acl"]);
+		$local_network_acl = check_str($row["local_network_acl"]);
+		$enabled = check_str($row["enabled"]);
+		$description = check_str($row["description"]);
+
+		$sql = "insert into v_xmpp ";
+		$sql .= "(";
+		$sql .= "xmpp_profile_uuid, ";
+		$sql .= "domain_uuid, ";
+		$sql .= "profile_name, ";
+		$sql .= "username, ";
+		$sql .= "password, ";
+		$sql .= "dialplan, ";
+		$sql .= "context, ";
+		$sql .= "rtp_ip, ";
+		$sql .= "ext_rtp_ip, ";
+		$sql .= "auto_login, ";
+		$sql .= "sasl_type, ";
+		$sql .= "xmpp_server, ";
+		$sql .= "tls_enable, ";
+		$sql .= "usr_rtp_timer, ";
+		$sql .= "default_exten, ";
+		$sql .= "vad, ";
+		$sql .= "avatar, ";
+		$sql .= "candidate_acl, ";
+		$sql .= "local_network_acl, ";
+		$sql .= "enabled, ";
+		$sql .= "description ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$xmpp_profile_uuid."', ";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$profile_name."', ";
+		$sql .= "'".$username."', ";
+		$sql .= "'".$password."', ";
+		$sql .= "'".$dialplan."', ";
+		$sql .= "'".$context."', ";
+		$sql .= "'".$rtp_ip."', ";
+		$sql .= "'".$ext_rtp_ip."', ";
+		$sql .= "'".$auto_login."', ";
+		$sql .= "'".$sasl_type."', ";
+		$sql .= "'".$xmpp_server."', ";
+		$sql .= "'".$tls_enable."', ";
+		$sql .= "'".$usr_rtp_timer."', ";
+		$sql .= "'".$default_exten."', ";
+		$sql .= "'".$vad."', ";
+		$sql .= "'".$avatar."', ";
+		$sql .= "'".$candidate_acl."', ";
+		$sql .= "'".$local_network_acl."', ";
+		$sql .= "'".$enabled."', ";
+		$sql .= "'".$description."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//get the xml cdr info
+	$sql = "select * from v_xml_cdr ";
+	if ($debug) {
+		$sql .= "limit 3 ";
+	}
+	$prep_statement = $db->prepare($sql);
+	$prep_statement->execute();
+	while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) {
+		$uuid = check_str($row["v_id"]);
+		$domain_name = check_str($row["domain_name"]);
+		$accountcode = check_str($row["accountcode"]);
+		$uuid = check_str($row["uuid"]);
+		$direction = check_str($row["direction"]);
+		$default_language = check_str($row["default_language"]);
+		$context = check_str($row["context"]);
+		$xml_cdr = check_str($row["xml_cdr"]);
+		$caller_id_name = check_str($row["caller_id_name"]);
+		$caller_id_number = check_str($row["caller_id_number"]);
+		$destination_number = check_str($row["destination_number"]);
+		$start_epoch = check_str($row["start_epoch"]);
+		$start_stamp = check_str($row["start_stamp"]);
+		$answer_stamp = check_str($row["answer_stamp"]);
+		$answer_epoch = check_str($row["answer_epoch"]);
+		$end_epoch = check_str($row["end_epoch"]);
+		$end_stamp = check_str($row["end_stamp"]);
+		$duration = check_str($row["duration"]);
+		$mduration = check_str($row["mduration"]);
+		$billsec = check_str($row["billsec"]);
+		$billmsec = check_str($row["billmsec"]);
+		$bridge_uuid = check_str($row["bridge_uuid"]);
+		$read_codec = check_str($row["read_codec"]);
+		$read_rate = check_str($row["read_rate"]);
+		$write_codec = check_str($row["write_codec"]);
+		$write_rate = check_str($row["write_rate"]);
+		$remote_media_ip = check_str($row["remote_media_ip"]);
+		$network_addr = check_str($row["network_addr"]);
+		$recording_file = check_str($row["recording_file"]);
+		$leg = check_str($row["leg"]);
+		$pdd_ms = check_str($row["pdd_ms"]);
+		$last_app = check_str($row["last_app"]);
+		$last_arg = check_str($row["last_arg"]);
+		$cc_side = check_str($row["cc_side"]);
+		$cc_member_uuid = check_str($row["cc_member_uuid"]);
+		$cc_queue_joined_epoch = check_str($row["cc_queue_joined_epoch"]);
+		$cc_queue = check_str($row["cc_queue"]);
+		$cc_member_session_uuid = check_str($row["cc_member_session_uuid"]);
+		$cc_agent = check_str($row["cc_agent"]);
+		$cc_agent_type = check_str($row["cc_agent_type"]);
+		$waitsec = check_str($row["waitsec"]);
+		$conference_name = check_str($row["conference_name"]);
+		$conference_uuid = check_str($row["conference_uuid"]);
+		$conference_member_id = check_str($row["conference_member_id"]);
+		$digits_dialed = check_str($row["digits_dialed"]);
+		$hangup_cause = check_str($row["hangup_cause"]);
+		$hangup_cause_q850 = check_str($row["hangup_cause_q850"]);
+		$sip_hangup_disposition = check_str($row["sip_hangup_disposition"]);
+
+		$sql = "insert into v_xml_cdr ";
+		$sql .= "(";
+		$sql .= "domain_uuid, ";
+		$sql .= "domain_name, ";
+		$sql .= "accountcode, ";
+		$sql .= "uuid, ";
+		$sql .= "direction, ";
+		$sql .= "default_language, ";
+		$sql .= "context, ";
+		$sql .= "xml_cdr, ";
+		$sql .= "caller_id_name, ";
+		$sql .= "caller_id_number, ";
+		$sql .= "destination_number, ";
+		$sql .= "start_epoch, ";
+		$sql .= "start_stamp, ";
+		$sql .= "answer_stamp, ";
+		$sql .= "answer_epoch, ";
+		$sql .= "end_epoch, ";
+		$sql .= "end_stamp, ";
+		$sql .= "duration, ";
+		$sql .= "mduration, ";
+		$sql .= "billsec, ";
+		$sql .= "billmsec, ";
+		$sql .= "bridge_uuid, ";
+		$sql .= "read_codec, ";
+		$sql .= "read_rate, ";
+		$sql .= "write_codec, ";
+		$sql .= "write_rate, ";
+		$sql .= "remote_media_ip, ";
+		$sql .= "network_addr, ";
+		$sql .= "recording_file, ";
+		$sql .= "leg, ";
+		$sql .= "pdd_ms, ";
+		$sql .= "last_app, ";
+		$sql .= "last_arg, ";
+		$sql .= "cc_side, ";
+		$sql .= "cc_member_uuid, ";
+		$sql .= "cc_queue_joined_epoch, ";
+		$sql .= "cc_queue, ";
+		$sql .= "cc_member_session_uuid, ";
+		$sql .= "cc_agent, ";
+		$sql .= "cc_agent_type, ";
+		$sql .= "waitsec, ";
+		$sql .= "conference_name, ";
+		$sql .= "conference_uuid, ";
+		$sql .= "conference_member_id, ";
+		$sql .= "digits_dialed, ";
+		$sql .= "hangup_cause, ";
+		$sql .= "hangup_cause_q850, ";
+		$sql .= "sip_hangup_disposition ";
+		$sql .= ")";
+		$sql .= "values ";
+		$sql .= "(";
+		$sql .= "'".$domain_uuid."', ";
+		$sql .= "'".$domain_name."', ";
+		$sql .= "'".$accountcode."', ";
+		$sql .= "'".$uuid."', ";
+		$sql .= "'".$direction."', ";
+		$sql .= "'".$default_language."', ";
+		$sql .= "'".$context."', ";
+		$sql .= "'".$xml_cdr."', ";
+		$sql .= "'".$caller_id_name."', ";
+		$sql .= "'".$caller_id_number."', ";
+		$sql .= "'".$destination_number."', ";
+		$sql .= "'".$start_epoch."', ";
+		if (strlen($start_stamp) > 0) {
+			$sql .= "'".$start_stamp."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($answer_stamp) > 0) {
+			$sql .= "'".$answer_stamp."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($answer_epoch) > 0) {
+			$sql .= "'".$answer_epoch."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$end_epoch."', ";
+		$sql .= "'".$end_stamp."', ";
+		if (strlen($duration) > 0) {
+			$sql .= "'".$duration."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		if (strlen($mduration) > 0) {
+			$sql .= "'".$mduration."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$billsec."', ";
+		$sql .= "'".$billmsec."', ";
+		$sql .= "'".$bridge_uuid."', ";
+		$sql .= "'".$read_codec."', ";
+		$sql .= "'".$read_rate."', ";
+		$sql .= "'".$write_codec."', ";
+		$sql .= "'".$write_rate."', ";
+		$sql .= "'".$remote_media_ip."', ";
+		$sql .= "'".$network_addr."', ";
+		$sql .= "'".$recording_file."', ";
+		$sql .= "'".$leg."', ";
+		if (strlen($cc_member_uuid) > 0) {
+			$sql .= "'".$pdd_ms."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$last_app."', ";
+		$sql .= "'".$last_arg."', ";
+		$sql .= "'".$cc_side."', ";
+		if (strlen($cc_member_uuid) > 0) {
+			$sql .= "'".$cc_member_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$cc_queue_joined_epoch."', ";
+		$sql .= "'".$cc_queue."', ";
+		if (strlen($cc_member_session_uuid) > 0) {
+			$sql .= "'".$cc_member_session_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$cc_agent."', ";
+		$sql .= "'".$cc_agent_type."', ";
+		if (strlen($waitsec) > 0) {
+			$sql .= "'".$waitsec."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$conference_name."', ";
+		if (strlen($conference_uuid) > 0) {
+			$sql .= "'".$conference_uuid."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$conference_member_id."', ";
+		$sql .= "'".$digits_dialed."', ";
+		$sql .= "'".$hangup_cause."', ";
+		if (strlen($hangup_cause_q850) > 0) {
+			$sql .= "'".$hangup_cause_q850."', ";
+		}
+		else {
+			$sql .= "null, ";
+		}
+		$sql .= "'".$sip_hangup_disposition."' ";
+		$sql .= ")";
+		if ($export_type == "sql") { echo check_sql($sql).";\n"; }
+		if ($export_type == "db") { $dest_db->exec(check_sql($sql)); }
+	}
+	unset ($prep_statement);
+
+//used for debugging
+	if ($debug) {
+		echo "</pre>\n";
+	}
+?>

+ 79 - 0
upgrade/r1877-readme.txt

@@ -0,0 +1,79 @@
+Migration Instructions
+	FusionPBX 2.0 to 3.0.x
+	Need assistance: http://www.fusionpbx.com/support.php
+
+1. Check revision number.
+	svn info
+
+2. If you are below version 1877 then update to the version 1877.
+	svn update -r1877
+
+3. Make sure the current system is updated with the latest database structure.
+	cd /var/www/fusionpbx
+	php /var/www/fusionpbx/core/upgrade/upgrade.php
+
+4. Ensure that you can login and see the menu before upgrading further.
+
+5. If using MySQL or Postgres Create a new database one way to do that is using advanced -> adminer.
+	Any database name you want to use will work for these instructions we will use a database name of fusionpbx3.
+
+6. Download the export PHP Script
+	http://code.google.com/p/fusionpbx/source/browse/trunk/scripts/upgrade/r1877-export.php
+
+7. Make a backup of the FusionPBX PHP directory and the FreeSWITCH conf directory.
+	cp -R /var/www/fusionpbx var/www/fusionpbx-bak
+	cp -R /usr/local/freeswitch/conf /usr/local/freeswitch/conf-bak
+
+8. Change the top of the script where and set the database you want to export the data to.
+	$db_type = "sqlite"; //pgsql, sqlite, mysql
+
+9. Upload it to the root of your server
+
+10. Login to the using the web interface.
+
+11. Run the 1877-export.php script if it was placed in the web directory you would run it with the following url.
+	http://x.x.x.x/r1877-export.php
+
+12. Save the sql file.
+
+13. Move the sql file to the server then import the sql code into the database.
+	a. For postgres you can import the sql file into the database by using the following command.
+		su postgres
+		psql -U postgres -d fusionpbx3 -f /tmp/database_backup.sql -L sql.log
+	b. For sqlite you need to use sqlite by command line.
+		1. Assuming fusionpbx is installed to /var/www/fusionpbx and the database is called fusionpbx.db
+		2. Move the old database to a new name
+			mv /var/www/fusionpbx/secure/fusionpbx.db /var/www/fusionpbx/secure/fusionpbx-version2.db
+		3. Import the sql file into the sqlite database
+			sqlite /var/www/fusionpbx/secure/fusionpbx.db < /tmp/database_backup.sql
+		4. Make sure the database is writeable
+
+14. Edit fusionpbx/includes/config.php change the database name to the new database.
+
+15. Update the source code to 3.0.x
+	svn update
+
+16. Login with the web browser.
+
+17. Update the menu by going to:
+	http://x.x.x.x/core/menu/menu.php then edit the menu and press 'restore default'
+
+18. Update the permissions.
+	Go to advanced -> group manager edit the permissions for the superadmin group
+	Select the permissions you that are not select in the list when finished press save.
+
+19. Logout of the web interface to clear the session.
+
+20. For multi-tenant systems delete the domain based dialplan xml files in.
+	rm /usr/local/freeswitch/conf/dialplans/replace_with_the_domain_name.xml
+
+21. Log back into the web interface and run.
+	Advanced -> Upgrade Schema (this will create new dialplans xml files for each domain)
+
+22.  Go to Advanced -> XML Editor
+	Expand 'autoload_configs'
+	Click on xml_cdr.conf.xml
+	At <param name="url" remove /mod/ and replace it with /app/
+	Status -> SIP Status press 'reloadxml'
+	System -> Modules restart XML CDR.
+23. Upgrade is complete.