--- /dev/null
+# Makefile
+# David Rowe 12 Feb 2008
+
+# Builds (almost) everything you need for FreePBX with sqlite3 from
+# scratch and configures FreePBX to run in a "sandbox" environment.
+
+TOPDIR = $(shell pwd)
+BUILD_DIR = $(TOPDIR)
+DL_DIR = $(TOPDIR)/dl
+ROOT = $(TOPDIR)/root
+export PATH:= $(ROOT)/bin:$(PATH)
+
+all: php sqlite pear-db php-sqlite3 xdebug lighttpd freepbx
+
+##############################################################
+# PHP --------------------------------------------------------
+##############################################################
+
+PHP_VERSION=5.2.5
+PHP_DIRNAME=php-$(PHP_VERSION)
+PHP_DIR=$(BUILD_DIR)/$(PHP_DIRNAME)
+PHP_SITE=http://www.php.net/distributions
+PHP_SOURCE=php-$(PHP_VERSION).tar.bz2
+PHP_CONFIGURE_OPTS=--disable-all --with-pcre-regex --enable-force-cgi-redirect \
+ --with-config-file-path=$(ROOT)/etc --prefix=$(ROOT) \
+ --with-pear --enable-xml --enable-libxml --enable-session \
+ --with-gettext --enable-debug
+
+$(DL_DIR)/$(PHP_SOURCE):
+ mkdir -p dl
+ wget -P $(DL_DIR) $(PHP_SITE)/$(PHP_SOURCE)
+
+$(PHP_DIR)/.unpacked: $(DL_DIR)/$(PHP_SOURCE)
+ bzcat $(DL_DIR)/$(PHP_SOURCE) | tar -C $(BUILD_DIR) -xf -
+ touch $(PHP_DIR)/.unpacked
+
+$(PHP_DIR)/.configured: $(PHP_DIR)/.unpacked
+ cd $(PHP_DIR); ./configure $(PHP_CONFIGURE_OPTS)
+ touch $(PHP_DIR)/.configured
+
+$(PHP_DIR)/.built: $(PHP_DIR)/.configured
+ cd $(PHP_DIR); make
+ cd $(PHP_DIR); make install
+ cp $(PHP_DIR)/php.ini-recommended $(ROOT)/etc/php.ini
+ echo include_path=\".:$(ROOT)/lib/php\" >> $(ROOT)/etc/php.ini
+ touch $(PHP_DIR)/.built
+
+php: $(PHP_DIR)/.built
+
+##############################################################
+# sqlite3 ----------------------------------------------------
+##############################################################
+
+SQLITE_VERSION=3.5.6
+SQLITE_DIRNAME=sqlite-$(SQLITE_VERSION)
+SQLITE_DIR=$(BUILD_DIR)/$(SQLITE_DIRNAME)
+SQLITE_SITE=http://www.sqlite.org/
+SQLITE_SOURCE=sqlite-amalgamation-$(SQLITE_VERSION).tar.gz
+SQLITE_CONFIGURE_OPTS = --prefix=$(ROOT)
+
+$(DL_DIR)/$(SQLITE_SOURCE):
+ mkdir -p dl
+ wget -P $(DL_DIR) $(SQLITE_SITE)/$(SQLITE_SOURCE)
+
+$(SQLITE_DIR)/.unpacked: $(DL_DIR)/$(SQLITE_SOURCE)
+ zcat $(DL_DIR)/$(SQLITE_SOURCE) | tar -C $(BUILD_DIR) -xf -
+ touch $(SQLITE_DIR)/.unpacked
+
+$(SQLITE_DIR)/.configured: $(SQLITE_DIR)/.unpacked
+ cd $(SQLITE_DIR); ./configure $(SQLITE_CONFIGURE_OPTS)
+ touch $(SQLITE_DIR)/.configured
+
+$(SQLITE_DIR)/.built: $(SQLITE_DIR)/.configured
+ cd $(SQLITE_DIR); make
+ cd $(SQLITE_DIR); make install
+ touch $(SQLITE_DIR)/.built
+
+sqlite: $(SQLITE_DIR)/.built
+
+##############################################################
+# PEAR:DB ---------------------------------------------------
+##############################################################
+
+$(ROOT)/lib/php/.db-installed:
+ pear install DB
+ cd $(ROOT)/lib/php/DB; patch -p1 < $(TOPDIR)/patch/common.patch
+ touch $(ROOT)/lib/php/.db-installed
+
+pear-db: $(ROOT)/lib/php/.db-installed
+
+##############################################################
+# php-sqlite3 ------------------------------------------------
+##############################################################
+
+PHP-SQLITE3_VERSION=0.5
+PHP-SQLITE3_DIRNAME=sqlite3-$(PHP-SQLITE3_VERSION)
+PHP-SQLITE3_DIR=$(BUILD_DIR)/$(PHP-SQLITE3_DIRNAME)
+PHP-SQLITE3_SITE=http://optusnet.dl.sourceforge.net/sourceforge/php-sqlite3/
+PHP-SQLITE3_SOURCE=sqlite3-$(PHP-SQLITE3_VERSION).tgz
+PHP-SQLITE3_CONFIGURE_OPTS=--prefix=$(ROOT) \
+ --with-sqlite3=$(ROOT) \
+ --with-php-config=$(ROOT)/bin/php-config
+
+$(DL_DIR)/$(PHP-SQLITE3_SOURCE):
+ mkdir -p dl
+ wget -P $(DL_DIR) $(PHP-SQLITE3_SITE)/$(PHP-SQLITE3_SOURCE)
+
+$(PHP-SQLITE3_DIR)/.unpacked: $(DL_DIR)/$(PHP-SQLITE3_SOURCE)
+ zcat $(DL_DIR)/$(PHP-SQLITE3_SOURCE) | tar -C $(BUILD_DIR) -xf -
+ touch $(PHP-SQLITE3_DIR)/.unpacked
+
+$(PHP-SQLITE3_DIR)/.configured: $(PHP-SQLITE3_DIR)/.unpacked
+ cd $(PHP-SQLITE3_DIR); phpize; ./configure $(PHP-SQLITE3_CONFIGURE_OPTS)
+ touch $(PHP-SQLITE3_DIR)/.configured
+
+$(PHP-SQLITE3_DIR)/.built: $(PHP-SQLITE3_DIR)/.configured
+ cd $(PHP-SQLITE3_DIR); make
+ cd $(PHP-SQLITE3_DIR); make install
+
+ # use modified sqlite3.php for PHP 5. We use a sym link so that
+ # we can edit it in place and capture changes to source control
+
+ ln -sf $(TOPDIR)/files/sqlite3.php $(ROOT)/lib/php/DB/sqlite3.php
+
+ # update php.ini extensions line for sqlite3.so
+
+ cat $(ROOT)/etc/php.ini | sed '/extension_dir/ d' > $(ROOT)/etc/php.ini.tmp
+ mv $(ROOT)/etc/php.ini.tmp $(ROOT)/etc/php.ini
+ echo extension_dir=\"`find $(ROOT) -name sqlite3.so | xargs dirname`\" >> $(ROOT)/etc/php.ini
+
+ touch $(PHP-SQLITE3_DIR)/.built
+
+php-sqlite3: $(PHP-SQLITE3_DIR)/.built
+
+##############################################################
+# xdebug -----------------------------------------------------
+##############################################################
+
+XDEBUG_VERSION=2.0.2
+XDEBUG_DIRNAME=xdebug-$(XDEBUG_VERSION)
+XDEBUG_DIR=$(BUILD_DIR)/$(XDEBUG_DIRNAME)
+XDEBUG_SITE=http://www.xdebug.org/files/
+XDEBUG_SOURCE=xdebug-$(XDEBUG_VERSION).tgz
+XDEBUG_CONFIGURE_OPTS=--prefix=$(ROOT) --enable-xdebug
+
+$(DL_DIR)/$(XDEBUG_SOURCE):
+ mkdir -p dl
+ wget -P $(DL_DIR) $(XDEBUG_SITE)/$(XDEBUG_SOURCE)
+
+$(XDEBUG_DIR)/.unpacked: $(DL_DIR)/$(XDEBUG_SOURCE)
+ zcat $(DL_DIR)/$(XDEBUG_SOURCE) | tar -C $(BUILD_DIR) -xf -
+ touch $(XDEBUG_DIR)/.unpacked
+
+$(XDEBUG_DIR)/.configured: $(XDEBUG_DIR)/.unpacked
+ cd $(XDEBUG_DIR); phpize; ./configure $(XDEBUG_CONFIGURE_OPTS)
+ touch $(XDEBUG_DIR)/.configured
+
+$(XDEBUG_DIR)/.built: $(XDEBUG_DIR)/.configured
+ cd $(XDEBUG_DIR); make
+ cp $(XDEBUG_DIR)/modules/xdebug.so $(ROOT)/lib
+
+ # update php.ini extensions line for xdebug.so
+
+ echo zend_extension=\"$(ROOT)/lib/xdebug.so\" >> $(ROOT)/etc/php.ini
+ echo "xdebug.auto_trace=On" >> $(ROOT)/etc/php.ini
+ echo "xdebug.show_exception_trace=On" >> $(ROOT)/etc/php.ini
+
+ touch $(XDEBUG_DIR)/.built
+
+xdebug: $(XDEBUG_DIR)/.built
+
+#########################################################################
+# lighttpd --------------------------------------------------------------
+#########################################################################
+
+LIGHTTPD_VERSION=1.4.18
+LIGHTTPD_DIRNAME=lighttpd-$(LIGHTTPD_VERSION)
+LIGHTTPD_DIR=$(BUILD_DIR)/$(LIGHTTPD_DIRNAME)
+LIGHTTPD_SITE=http://www.lighttpd.net/download
+LIGHTTPD_SOURCE=lighttpd-$(LIGHTTPD_VERSION).tar.gz
+LIGHTTPD_CONFIGURE_OPTS=--prefix=$(ROOT) --disable-ipv6
+
+$(DL_DIR)/$(LIGHTTPD_SOURCE):
+ mkdir -p dl
+ wget -P $(DL_DIR) $(LIGHTTPD_SITE)/$(LIGHTTPD_SOURCE)
+
+$(LIGHTTPD_DIR)/.unpacked: $(DL_DIR)/$(LIGHTTPD_SOURCE)
+ zcat $(DL_DIR)/$(LIGHTTPD_SOURCE) | tar -C $(BUILD_DIR) -xf -
+ touch $(LIGHTTPD_DIR)/.unpacked
+
+$(LIGHTTPD_DIR)/.configured: $(LIGHTTPD_DIR)/.unpacked
+ cd $(LIGHTTPD_DIR); ./configure $(LIGHTTPD_CONFIGURE_OPTS)
+ touch $(LIGHTTPD_DIR)/.configured
+
+$(LIGHTTPD_DIR)/.built: $(LIGHTTPD_DIR)/.configured
+ cd $(LIGHTTPD_DIR); make
+ cd $(LIGHTTPD_DIR); make install
+
+ cp files/lighttpd.conf $(ROOT)/etc
+ mkdir -p $(ROOT)/www
+ cp files/test.php $(ROOT)/www
+
+ # change server root and set up cgi-assign for PHP
+
+ cat $(ROOT)/etc/lighttpd.conf | sed '/server.document-root/ d' > $(ROOT)/etc/lighttpd.conf.tmp
+ mv $(ROOT)/etc/lighttpd.conf.tmp $(ROOT)/etc/lighttpd.conf
+ echo "server.document-root = \"$(ROOT)/www/\"" >> $(ROOT)/etc/lighttpd.conf
+ echo "cgi.assign = (\".php\" => \"$(ROOT)/bin/php-cgi\")" >> $(ROOT)/etc/lighttpd.conf
+
+ touch $(LIGHTTPD_DIR)/.built
+
+lighttpd: $(LIGHTTPD_DIR)/.built
+
+#########################################################################
+# freepbx ---------------------------------------------------------------
+#########################################################################
+
+FREEPBX_VERSION=2.4.0
+FREEPBX_DIRNAME=freepbx-$(FREEPBX_VERSION)
+FREEPBX_DIR=$(BUILD_DIR)/$(FREEPBX_DIRNAME)
+FREEPBX_SITE= http://mirror.freepbx.org
+FREEPBX_SOURCE=freepbx-$(FREEPBX_VERSION).tar.gz
+FREEPBX_CONFIGURE_OPTS=
+
+# sed command to change hard coded PHP /etc/amportal.conf path
+
+FREEPBX_AMP_CONF='s|"/etc/amportal.conf"|"$(ROOT)/etc/amportal.conf"|'
+
+$(DL_DIR)/$(FREEPBX_SOURCE):
+ mkdir -p dl
+ wget -P $(DL_DIR) $(FREEPBX_SITE)/$(FREEPBX_SOURCE)
+
+$(FREEPBX_DIR)/.unpacked: $(DL_DIR)/$(FREEPBX_SOURCE)
+ zcat $(DL_DIR)/$(FREEPBX_SOURCE) | tar -C $(BUILD_DIR) -xf -
+ patch -d $(FREEPBX_DIR) -p1 < patch/freepbx.patch
+
+ # additional files to implement retrieve_conf as include
+
+ cp files/retrieve_conf.inc.php files/do_reload.php \
+ $(FREEPBX_DIR)/amp_conf/htdocs/admin
+
+ touch $(FREEPBX_DIR)/.unpacked
+
+$(FREEPBX_DIR)/.installed: $(FREEPBX_DIR)/.unpacked
+
+ # initialise databases (freepbx and CDR)
+
+ mkdir -p $(ROOT)/var
+ cat $(FREEPBX_DIR)/SQL/newinstall.sqlite3.sql | sqlite3 $(ROOT)/var/freepbx.db
+ touch $(ROOT)/var/asteriskcdr.db
+
+ # edit amportal.conf
+
+ # out with the old......
+
+ cat $(FREEPBX_DIR)/amportal.conf | \
+ sed -e '/AMPDBENGINE=/ d' -e '/AMPDBFILE=/ d' \
+ -e '/AMPWEBROOT=/ d' -e '/FOPWEBROOT=/ d' \
+ -e '/AMPDBHOST=/ d' -e '/AMPDBUSER=/ d' -e '/AMPDBPASS=/ d' \
+ > $(FREEPBX_DIR)/amportal.conf.tmp
+
+ mv $(FREEPBX_DIR)/amportal.conf.tmp $(FREEPBX_DIR)/amportal.conf
+
+ # in with the new........
+
+ echo "AMPDBENGINE=sqlite3" >> $(FREEPBX_DIR)/amportal.conf
+ echo "AMPDBFILE=$(ROOT)/var/freepbx.db" >> $(FREEPBX_DIR)/amportal.conf
+ echo "AMPWEBROOT=$(ROOT)/www" >> $(FREEPBX_DIR)/amportal.conf
+ echo "FOPWEBROOT=$(ROOT)/www/panel" >> $(FREEPBX_DIR)/amportal.conf
+
+ sed -i "s|/var/www/html|$(ROOT)/www|" $(FREEPBX_DIR)/amportal.conf
+
+ # Wholesale hacking of FreePBX source to move AMP_CONF to our local conf dir:
+ # FYI to find where AMP_CONF is used:
+ # grep -r "define(\"AMP_CONF\", \"/etc/amportal.conf\")" *
+
+ cd $(FREEPBX_DIR); \
+ FILES=`grep -r "\"/etc/amportal.conf\"" * | sed 's/:.*//'`; \
+ for f in $$FILES; do \
+ sed -i $(FREEPBX_AMP_CONF) $$f; \
+ done
+
+ # change recordings/includes/main.conf.php DBENGINE and DBFILE settings which
+ # are hard coded for mysql
+
+ sed -i "s|ASTERISKCDR_DBENGINE.*|ASTERISKCDR_DBENGINE=\"sqlite3\";|" \
+ $(FREEPBX_DIR)/amp_conf/htdocs/recordings/includes/main.conf.php
+ sed -i "s|ASTERISKCDR_DBFILE.*|ASTERISKCDR_DBFILE=\"$(ROOT)/var/asteriskcdr.db\";|" \
+ $(FREEPBX_DIR)/amp_conf/htdocs/recordings/includes/main.conf.php
+
+ # change admin/cdr/lib/defines DB_TYPE and DBNAME settings
+
+ sed -i "s|\"DBNAME\".*|\"DBNAME\",\"$(ROOT)/var/asteriskcdr.db\");|" \
+ $(FREEPBX_DIR)/amp_conf/htdocs/admin/cdr/lib/defines.php
+ sed -i "s|\"DB_TYPE\".*|\"DB_TYPE\",\"sqlite3\");|" \
+ $(FREEPBX_DIR)/amp_conf/htdocs/admin/cdr/lib/defines.php
+
+ # switch off mp3 support as I dont have asterisk-addons and Asterisk keeps
+ # crashing when I start it
+
+ sed -i "s|load => format_mp3.so|;load => format_mp3.so|" \
+ $(FREEPBX_DIR)/amp_conf/astetc/modules.conf
+
+ # cp amportal.conf ourselves to bypass a lot of questions in install script
+
+ cp $(FREEPBX_DIR)/amportal.conf $(ROOT)/etc
+
+ # run installer
+
+ sudo mkdir -p $(ROOT)/var/run/asterisk; sudo chmod 777 $(ROOT)/var/run/asterisk;
+ sudo mkdir -p $(ROOT)/var/lib/asterisk/bin; sudo chmod 777 $(ROOT)/var/lib/asterisk/bin;
+ cd $(FREEPBX_DIR); sudo ./install_amp; sudo chmod 777 $(ROOT)/www -R
+
+ #touch $(FREEPBX_DIR).installed
+
+
+freepbx: $(FREEPBX_DIR)/.installed
+
+#########################################################################
+# clean ----------------------------------------------------------------
+#########################################################################
+
+clean:
+ rm -Rf $(PHP_DIR) $(SQLITE_DIR) $(PHP-SQLITE3_DIR) \
+ $(XDEBUG_DIR) $(LIGHTTPD_DIR) $(FREEPBX_DIR) root \
+ $(FREEPBX_DIR)-orig
+
+ find . -name '*~' | xargs rm -f
+ rm -f *.xml # where do these come from?
+
+#########################################################################
+# freepbx-make-patch ---------------------------------------------------
+#########################################################################
+
+# Generate patches between original tar ball $(AO) and either the
+# installed files $(AROOT), or modified tar ball $A.
+# Run this Makefile target to capture any changes to patches
+
+AO = $(FREEPBX_DIRNAME)-orig/
+AROOT = root/www
+A = $(FREEPBX_DIRNAME)/
+
+freepbx-make-patch:
+
+ # untar original, to save time we check if the orig is already there
+
+ if [ ! -d $(FREEPBX_DIR)-orig ] ; then \
+ cd $(DL_DIR); tar xvf $(FREEPBX_SOURCE); \
+ mv $(FREEPBX_DIRNAME) $(FREEPBX_DIR)-orig; \
+ fi
+
+ # make big-ass SQL statement work with sqlite3
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/admin/modules/core/functions.inc.php \
+ $(AROOT)/admin/modules/core/functions.inc.php \
+ > patch/freepbx.patch
+
+ # add $options array to help numRows() support in sqlite3
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/admin/common/db_connect.php \
+ $(AROOT)/admin/common/db_connect.php \
+ >> patch/freepbx.patch
+
+ # sqlite3 support for cdr in recordings
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/recordings/includes/database.php \
+ $(AROOT)/recordings/includes/database.php \
+ >> patch/freepbx.patch
+
+ # sqlite3 support for cdr
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/admin/cdr/lib/defines.php \
+ $(AROOT)/admin/cdr/lib/defines.php \
+ >> patch/freepbx.patch
+
+ # trap missing cdr table error in Reports menu
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/admin/cdr/lib/Class.Table.php \
+ $(AROOT)/admin/cdr/lib/Class.Table.php \
+ >> patch/freepbx.patch
+
+ # typo in newinstall.sqlite3.sql
+
+ -diff -uN \
+ $(AO)/SQL/newinstall.sqlite3.sql \
+ $(A)/SQL/newinstall.sqlite3.sql \
+ >> patch/freepbx.patch
+
+ # stop installer warning/errors when sqlite3 and blackfin used
+
+ -diff -uN \
+ $(AO)/install_amp \
+ $(A)/install_amp \
+ >> patch/freepbx.patch
+
+ # use sqlite3 SQL syntax for recording installer
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/admin/modules/recordings/install.php \
+ $(A)/amp_conf/htdocs/admin/modules/recordings/install.php \
+ >> patch/freepbx.patch
+
+ # 1/ stop perl script for flash panel being called, as
+ # this won't work on Blackfin (might work on x86 with
+ # appropriate Perl lib but not tested)
+ #
+ # 2/ Remove code to set up queues, as it seems to be killing retrive_conf
+ # Is this needed or a legacy thing?
+
+ -diff -uN \
+ $(AO)/amp_conf/bin/retrieve_conf \
+ $(A)/amp_conf/bin/retrieve_conf \
+ >> patch/freepbx.patch
+
+ # set up default AMP user and password
+
+ -diff -uN \
+ $(AO)/amp_conf/astetc/manager.conf \
+ $(A)/amp_conf/astetc/manager.conf \
+ >> patch/freepbx.patch
+
+ # make retrieve_conf an include from config.php rather
+ # than exec to save about 15M
+
+ -diff -uN \
+ $(AO)/amp_conf/htdocs/admin/config.php \
+ $(AROOT)/admin/config.php \
+ >> patch/freepbx.patch
+
+ # NOTE: common.patch was generated manually from command line
+
+ # undo sandbox path (messy! Must be a better way....)
+
+ sed -i 's|$(ROOT)||' patch/freepbx.patch
+
+
+
--- /dev/null
+README for freepbx-sandbox
+David Rowe Feb 2008
+
+Introduction
+------------
+
+This directory contains a "sandbox" type development environment for
+FreePBX using sqlite3. It was used to develop patches against FreePBX
+2.4.0 to progress sqlite3 support.
+
+The Makefile builds (almost) everything you need for FreePBX (web
+server, php etc) from scratch and runs it in a "sandbox" environment.
+The notable exception is that it doesn't build Asterisk (yet).
+
+FreePBX is configured to use lighttpd (easier than building Apache)
+and and sqlite3.
+
+Most of the files for are confined to this directory, i.e. you mostly
+(except for Asterisk) don't need to mess with your PC's configuration.
+Used to model and test configuration for Blackfin port, but may be
+useful for general FreePBX development.
+
+FreePBX Sqlite3 Status
+----------------------
+
+Most of the screens (Admin/Reports/Recording) present OK but have not
+been extensively tested. The Flash Panel isn't working/hasn't been
+tested. Reports/Recording is awaiting sqlite3 CDR support (e.g. in
+Asterisk 1.6) for further testing. The amp_conf installer works OK.
+
+I have run some basic tests such as adding an extension/route/trunk
+and made a few calls OK.
+
+This FreePBX/Sqlite3 development has been performed on a laptop
+running Ubuntu (no zaptel hardware) with Asterisk 1.4 and FreePBX
+2.4.0.
+
+Motivation
+----------
+
+1/ When I first tried to manually install FreePBX I had a lot of
+problems installing all the apps I needed, especially as I was new to
+PHP/SQL/FreePBX. So I thought about automating the installation (from
+source).
+
+2/ It may allow multiple installations of FreePBX, or for example lets
+you use a different PHP version to currently installed on your system.
+Asterisk would also need to be sandboxed for this to work.
+
+3/ It doesn't mess with your root filesystem.
+
+4/ Let me collect all the code I needed in one dir tree, making source
+control easier.
+
+5/ Stepping stone for a Blackfin port.
+
+Building and Running FreePBX-sqlite3 Sandbox
+--------------------------------------------
+
+Building:
+
+1/ Install Asterisk 1.4.x and start Asterisk.
+
+2/ Build freepbx-sandbox:
+
+[your home]$ svn co \
+ https://freetel.svn.sourceforge.net/svnroot/freetel/freepbx-sandbox \
+ freepbx-sandbox
+[your home]$ cd freepbx
+[freepbx-sandbox]$ make
+
+3/ You will eventually get prompted for your root passwd - this is
+ required for several stages of the installation.
+
+Running:
+
+1/ Start the web server:
+ [freepbx-sandbox]$ sudo ./root/sbin/lighttpd -D -f root/etc/lighttpd.conf
+2/ If not already running start Asterisk:
+ [freepbx-sandbox]$ sudo asterisk
+3/ Point your browser at locahost
+
+Manual Installation of FreePBX with sqlite3
+-------------------------------------------
+
+Here is a rough guide for a regular (non-sandbox) installation of
+FreePBX with sqlite3.
+
+The Makefile automates FreePBX/sqlite3 installation in a sandbox
+environment, use it as a reference for manual installation as I may
+have missed a step in the steps below. See also sqlite.readme in the
+FreePBX tar ball.
+
+1/ Install and test a web server with PHP 5.
+
+2/ Install PHP PEAR. Patch DB/common.php with files/common.patch to
+ enable numRows() to work.
+
+3/ Install sqlite3 (shared libs and application).
+
+4/ Install sqlite3-0.5 (PEAR/DB support for sqlite3)
+ + cp files/sqlite3.php /your/php/path/DB/sqlite3.php. This is an updated
+ version of the sqlite3.php file that comes with sqlite3-0.5
+ + make sure you install sqlite.so and update php.ini so it can find it.
+ + optional: see Test 2 in the next section
+
+5/ tar xvzf freepbx-2.4.0.tar.gz
+
+6/ Edit amportal.conf for sqlite (see sqlite.readme), manually cp to
+ /etc (that way installer ask less questions).
+
+7/ Create sqlite database (see sqlite.readme). Create a dummy cdr
+ database file using 'touch /var/asteriskcdr.db' (this last step
+ prevents reports/recording screens choking in the absence of
+ Asterisk sqlite3 CDR records).
+
+8/ Apply patch/freepbx.patch to freepbx-2.4.0 directory.
+
+9/ Manually edit recordings/includes/main.conf.php:
+ ASTERISKCDR_DBENGINE="sqlite3"
+ ASTERISKCDR_DBFILE="/var/asteriskcdr.db"
+
+ Manually edit: admin/cdr/lib/defines.php:
+ DB_TYPE="sqlite3"
+ DB_NAME="/var/asteriskcdr.db"
+
+10/ Run freepbx installer
+
+Tests
+-----
+
+1/ basic PHP support: run file/test.php on your webserver
+
+2/ PEAR/DB with sqlite3: run files/testdb.php on your webserver
+ (after freepbx.db has been created by step 9)
+
+Notes
+-----
+
+1/ The Recordings screen needs a sqlite3 CDR backend for Asterisk.
+This is available in Asterisk 1.6. This hasn't been tested yet.
+
+2/ The Makefile automates FreePBX/sqlite3 installation in a sandbox
+environment, use it as a reference for manual installation. See
+Makefile for more information.
+
+3/ Changes to FreePBX are in the patch directory. An updated
+sqlite3.php DB/PEAR backend is also required (files dir).
+
+4/ If port 80 is not available kill your existing web server.
+
+5/ Xdebug generates trace files in your /tmp directory. Useful to
+determine what went wrong. Also keep an eye on the lighttpd log.
+
+6/ I used a laptop running Ubuntu and Asterisk 1.4.4 for these tests -
+Asterisk had no analog hardware installed so I didn't install Zaptel.
+Asterisk was compiled in another directory in the usual way:
+./configure && make && sudo make install.
+
+7/ In files/testdb.php is a simple test script for exercising sqlite3
+PEAR/DB support - useful for debugging any sqlite3 problems you might
+encounter.
+
+Suggested FreePBX Changes
+-------------------------
+
+1/ Consider patch/freepbx.patch (for FreePBX) & patch/common.patch
+ (for PEAR/DB). Patches are explained at the end of Makefile
+ (freepbx-make-patch target).
+
+ Please note that some of the patches contain some hard-coded
+ information (e.g. changed paths), for example:
+
+ admin/cdr/lib/defines.php (DBNAME & DBTYPE lines)
+ install_amp (AMP_CONF)
+ retrieve_conf (AMP_CONF)
+
+ This is a consequence of the sandbox method I am using, and in some
+ cases current FreePBX sqlite3 support (e.g. the Asterisk CDR
+ database is hard coded in several places rather than being set in
+ amportal.conf). If checking into FreePBX source control this part
+ of the patch should not be applied. I will try and work out a
+ better way to generate patches in future.
+
+2/ It might be better to store the CDR database parameters in
+ amportal.conf rather than hard coding them in
+ recordings/includes/main.conf.php ($ASTERISKCDR_DBFILE,
+ $ASTERISKCDR_DBNAME) & admin/cdr/lib/defines.php (DBNAME, DB_TYPE).
+
+3/ Include sqlite3.php in FreePBX to support sqlite3 in PEAR/DB for
+ PHP 5.
+
+4/ newinstall.sqlite3.sql has a typo on line 327:
+
+ modules_xml -> module_xml
+
+ This correction is included in patch/freepbx.patch
+
+TODO
+----
+
+1/ Try to get Asterisk 1.6 CDR working with sqlite3, so we can further
+ develop the Reports/recordings menus.
+
+2/ Bunch of warnings from the web server I haven't worked out yet:
+
+ a) when saving a new extension:
+
+ <snip>
+ 2008-03-02 08:14:41: (mod_cgi.c.1231) cgi died ?
+
+ b) lots of this sort of thing:
+
+ <snip>
+ PHP Notice: Undefined offset: 2 in
+ /home/david/freepbx-sandbox/root/www/admin/modules/core/functions.inc.php
+ on line 2946
--- /dev/null
+<?php
+
+// do_reload.php
+// David Rowe March 11 2008
+// non-function version that executes in same php-cgi as config.php to
+// save run-time memory
+
+//Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+
+# this file runs inside special window that makes it hard to log
+# messages using regular HTML. So we use a log file instead.
+
+function reload_dbg($msg) {
+ $myFile = "/tmp/log.txt";
+ $fh = fopen($myFile, 'a') or die("can't open file");
+ fwrite($fh, $msg);
+ fclose($fh);
+}
+
+# This is more or less the code copied from do_reload() in
+# admin/functions.inc.php
+
+ $notify =& notifications::create($db);
+
+ $return = array('num_errors'=>0,'test'=>'abc');
+ $exit_val = null;
+
+ if (isset($amp_conf["PRE_RELOAD"]) && !empty($amp_conf['PRE_RELOAD'])) {
+ exec( $amp_conf["PRE_RELOAD"], $output, $exit_val );
+
+ if ($exit_val != 0) {
+ $desc = sprintf(_("Exit code was %s and output was: %s"), $exit_val, "\n\n".implode("\n",$output));
+ $notify->add_error('freepbx','reload_pre_script', sprintf(_('Could not run %s script.'), $amp_conf['PRE_RELOAD']), $desc);
+
+ $return['num_errors']++;
+ } else {
+ $notify->delete('freepbx', 'reload_pre_script');
+ }
+ }
+
+ // use include file in current php-cgi, avoid repeating a lot
+ // of the code
+
+ require_once('retrieve_conf.inc.php');
+ $return['retrieve_conf'] = $rc_output;
+
+ // retrive_conf html output
+ if ($exit_val != 0) {
+ $return['status'] = false;
+ $return['message'] = sprintf(_('Reload failed because retrieve_conf encountered an error: %s'),$exit_val);
+ $return['num_errors']++;
+ $notify->add_critical('freepbx','RCONFFAIL', _("retrieve_conf failed, config not applied"), $return['message']);
+ return $return;
+ }
+
+ if (!isset($astman) || !$astman) {
+ $return['status'] = false;
+ $return['message'] = _('Reload failed because FreePBX could not connect to the asterisk manager interface.');
+ $return['num_errors']++;
+ $notify->add_critical('freepbx','RCONFFAIL', _("retrieve_conf failed, config not applied"), $return['message']);
+ return $return;
+ }
+ $notify->delete('freepbx', 'RCONFFAIL');
+
+ //reload MOH to get around 'reload' not actually doing that.
+ $astman->send_request('Command', array('Command'=>'moh reload'));
+
+ //reload asterisk
+ $astman->send_request('Command', array('Command'=>'reload'));
+
+ $return['status'] = true;
+ $return['message'] = _('Successfully reloaded');
+
+ if ($amp_conf['FOPRUN']) {
+ //bounce op_server.pl
+ $wOpBounce = $amp_conf['AMPBIN'].'/bounce_op.sh';
+ exec($wOpBounce.' &>'.$asterisk_conf['astlogdir'].'/freepbx-bounce_op.log', $output, $exit_val);
+
+ if ($exit_val != 0) {
+ $desc = _('Could not reload the FOP operator panel server using the bounce_op.sh script. Configuration changes may not be reflected in the panel display.');
+ $notify->add_error('freepbx','reload_fop', _('Could not reload FOP server'), $desc);
+
+ $return['num_errors']++;
+ } else {
+ $notify->delete('freepbx','reload_fop');
+ }
+ }
+
+ //store asterisk reloaded status
+ $sql = "UPDATE admin SET value = 'false' WHERE variable = 'need_reload'";
+ $result = $db->query($sql);
+ if(DB::IsError($result)) {
+ $return['message'] = _('Successful reload, but could not clear reload flag due to a database error: ').$db->getMessage();
+ $return['num_errors']++;
+ }
+
+ if (isset($amp_conf["POST_RELOAD"]) && !empty($amp_conf['POST_RELOAD'])) {
+ exec( $amp_conf["POST_RELOAD"], $output, $exit_val );
+
+ if ($exit_val != 0) {
+ $desc = sprintf(_("Exit code was %s and output was: %s"), $exit_val, "\n\n".implode("\n",$output));
+ $notify->add_error('freepbx','reload_post_script', sprintf(_('Could not run %s script.'), 'POST_RELOAD'), $desc);
+
+ $return['num_errors']++;
+ } else {
+ $notify->delete('freepbx', 'reload_post_script');
+ }
+ }
+ $response = $return;
+
+?>
--- /dev/null
+# lighttpd configuration file
+#
+# use a it as base for lighttpd 1.0.0 and above
+#
+# $Id: lighttpd.conf,v 1.6 2004/08/29 09:44:53 weigon Exp $
+
+############ Options you really have to take care of ####################
+
+## modules to load
+# at least mod_access and mod_accesslog should be loaded
+# all other module should only be loaded if really neccesary
+# - saves some time
+# - saves memory
+server.modules = (
+# "mod_rewrite",
+# "mod_redirect",
+ "mod_access",
+# "mod_auth",
+# "mod_status",
+# "mod_fastcgi",
+# "mod_simple_vhost",
+# "mod_evhost",
+ "mod_cgi",
+# "mod_compress",
+# "mod_ssi",
+# "mod_usertrack",
+# "mod_rrdtool",
+# "mod_accesslog"
+)
+
+## a static document-root, for virtual-hosting take look at the
+## server.virtual-* options
+server.document-root = "/var/www/html"
+
+## where to send error-messages to
+# server.errorlog = ""
+
+# files to check for if .../ is requested
+server.indexfiles = ( "index.php", "index.html",
+ "index.htm", "default.htm" )
+
+# mimetype mapping
+mimetype.assign = (
+ ".pdf" => "application/pdf",
+ ".sig" => "application/pgp-signature",
+ ".spl" => "application/futuresplash",
+ ".class" => "application/octet-stream",
+ ".ps" => "application/postscript",
+ ".torrent" => "application/x-bittorrent",
+ ".dvi" => "application/x-dvi",
+ ".gz" => "application/x-gzip",
+ ".pac" => "application/x-ns-proxy-autoconfig",
+ ".swf" => "application/x-shockwave-flash",
+ ".tar.gz" => "application/x-tgz",
+ ".tgz" => "application/x-tgz",
+ ".tar" => "application/x-tar",
+ ".zip" => "application/zip",
+ ".mp3" => "audio/mpeg",
+ ".m3u" => "audio/x-mpegurl",
+ ".wma" => "audio/x-ms-wma",
+ ".wax" => "audio/x-ms-wax",
+ ".ogg" => "audio/x-wav",
+ ".wav" => "audio/x-wav",
+ ".gif" => "image/gif",
+ ".jpg" => "image/jpeg",
+ ".jpeg" => "image/jpeg",
+ ".png" => "image/png",
+ ".xbm" => "image/x-xbitmap",
+ ".xpm" => "image/x-xpixmap",
+ ".xwd" => "image/x-xwindowdump",
+ ".css" => "text/css",
+ ".html" => "text/html",
+ ".htm" => "text/html",
+ ".js" => "text/javascript",
+ ".asc" => "text/plain",
+ ".c" => "text/plain",
+ ".conf" => "text/plain",
+ ".text" => "text/plain",
+ ".txt" => "text/plain",
+ ".dtd" => "text/xml",
+ ".xml" => "text/xml",
+ ".mpeg" => "video/mpeg",
+ ".mpg" => "video/mpeg",
+ ".mov" => "video/quicktime",
+ ".qt" => "video/quicktime",
+ ".avi" => "video/x-msvideo",
+ ".asf" => "video/x-ms-asf",
+ ".asx" => "video/x-ms-asf",
+ ".wmv" => "video/x-ms-wmv"
+ )
+
+# Use the "Content-Type" extended attribute to obtain mime type if possible
+# mimetypes.use-xattr = "enable"
+
+#### accesslog module
+# accesslog.filename = "/www/logs/access.log"
+
+## deny access the file-extensions
+#
+# ~ is for backupfiles from vi, emacs, joe, ...
+# .inc is often used for code includes which should in general not be part
+# of the document-root
+url.access-deny = ( "~", ".inc" )
+
+
+
+######### Options that are good to be but not neccesary to be changed #######
+
+## bind to port (default: 80)
+#server.port = 81
+
+## bind to localhost (default: all interfaces)
+#server.bind = "grisu.home.kneschke.de"
+
+## error-handler for status 404
+#server.error-handler-404 = "/error-handler.html"
+#server.error-handler-404 = "/error-handler.php"
+
+
+###### virtual hosts
+##
+## If you want name-based virtual hosting add the next three settings and load
+## mod_simple_vhost
+##
+## document-root =
+## virtual-server-root + virtual-server-default-host + virtual-server-docroot or
+## virtual-server-root + http-host + virtual-server-docroot
+##
+#simple-vhost.server-root = "/home/weigon/wwwroot/servers/"
+#simple-vhost.default-host = "grisu.home.kneschke.de"
+#simple-vhost.document-root = "/pages/"
+
+
+##
+## Format: <errorfile-prefix><status>.html
+## -> ..../status-404.html for 'File not found'
+#server.errorfile-prefix = "/home/weigon/projects/lighttpd/doc/status-"
+
+## virtual directory listings
+#server.dir-listing = "enable"
+
+## send unhandled HTTP-header headers to error-log
+#debug.dump-unknown-headers = "enable"
+
+### only root can use these options
+#
+# chroot() to directory (default: no chroot() )
+#server.chroot = "/"
+
+## change uid to <uid> (default: don't care)
+#server.username = "wwwrun"
+
+## change uid to <uid> (default: don't care)
+#server.groupname = "wwwrun"
+
+#### compress module
+#compress.cache-dir = "/tmp/lighttpd/cache/compress/"
+#compress.filetype = ("text/plain", "text/html")
+
+#### fastcgi module
+## read fastcgi.txt for more info
+#fastcgi.server = ( ".php" =>
+# ( "grisu" =>
+# (
+# "host" => "192.168.2.10",
+# "port" => 1026
+# )
+# )
+# )
+
+#### CGI module
+#cgi.assign = ( ".pl" => "/usr/bin/perl",
+# ".cgi" => "/usr/bin/perl" )
+#
+
+#### SSL engine
+#ssl.engine = "enable"
+#ssl.pemfile = "server.pem"
+
+#### status module
+# status.status-url = "/server-status"
+# status.config-url = "/server-config"
+
+#### auth module
+## read authentification.txt for more info
+# auth.backend = "plain"
+# auth.backend.plain.userfile = "lighttpd.user"
+# auth.backend.plain.groupfile = "lighttpd.group"
+
+# auth.backend.ldap.hostname = "localhost"
+# auth.backend.ldap.base-dn = "dc=my-domain,dc=com"
+# auth.backend.ldap.filter = "(uid=$)"
+
+# auth.require = ( "/server-status" =>
+# (
+# "method" => "digest",
+# "realm" => "download archiv",
+# "require" => "group=www|user=jan|host=192.168.2.10"
+# ),
+# "/server-info" =>
+# (
+# "method" => "digest",
+# "realm" => "download archiv",
+# "require" => "group=www|user=jan|host=192.168.2.10"
+# )
+# )
+
+#### url handling modules (rewrite, redirect, access)
+# url.rewrite = ( "^/$" => "/server-status" )
+# url.redirect = ( "^/wishlist/(.+)" => "http://www.123.org/$1" )
+
+#
+# define a pattern for the host url finding
+# %% => % sign
+# %0 => domain name + tld
+# %1 => tld
+# %2 => domain name without tld
+# %3 => subdomain 1 name
+# %4 => subdomain 2 name
+#
+# evhost.path-pattern = "/home/storage/dev/www/%3/htdocs/"
+
+#### expire module
+# expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")
+
+#### ssi
+# ssi.extension = ( ".shtml" )
+
+#### rrdtool
+# rrdtool.binary = "/usr/bin/rrdtool"
+# rrdtool.db-name = "/var/www/lighttpd.rrd"
--- /dev/null
+<?php
+
+/* fairly similar to retrieve_conf, have just commented out a bunch of
+ code we don't need when used as an include file from do_update.php
+ rather than a stand alone exec. */
+
+if (! function_exists("_")) {
+ function _($str) {
+ return $str;
+ }
+}
+
+ini_set('error_reporting', E_ALL & ~E_NOTICE);
+
+define("AMP_CONF", "/home/david/freepbx-sandbox/root/etc/amportal.conf");
+$amportalconf = AMP_CONF;
+
+//define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
+define("WARNING_BANNER", "; "._("do not edit this file, this is an auto-generated file by freepbx\n")."; "._("all modifications must be done from the web gui")."\n\n\n");
+
+// Emulate gettext extension functions if gettext is not available
+if (!function_exists('_')) {
+ function _($str) {
+ return $str;
+ }
+}
+
+function out($text) {
+ global $rc_output;
+ $rc_output = $rc_output . $text. "\n";
+}
+
+function outn($text) {
+ global $rc_output;
+ $rc_output = $rc_output . $text;
+}
+
+function error($text) {
+ global $rc_output;
+ $rc_output = $rc_output . "[ERROR] ".$text."\n";
+}
+
+function fatal($text, $extended_text="", $type="FATAL") {
+ global $db;
+
+ echo "[$type] ".$text." ".$extended_text."\n";
+
+ if(!DB::isError($db)) {
+ $nt = notifications::create($db);
+ $nt->add_critical('retrieve_conf', $type, $text, $extended_text);
+ }
+
+ exit(1);
+}
+
+function debug($text) {
+ global $debug;
+
+ if ($debug) echo "[DEBUG-preDB] ".$text."\n";
+}
+
+function showHelp() {
+ out(_("Optional parameters:"));
+ out(_(" --help, -h, -? Show this help"));
+ out(_(" --debug Enable debug output"));
+ out(_(" --dry-run Don't actually do anything"));
+}
+
+
+// bootstrap retrieve_conf by getting the AMPWEBROOT since that is currently where the necessary
+// functions.inc.php resides, and then use that parser to properly parse the file and get all
+// the defaults as needed.
+//
+function parse_amportal_conf_bootstrap($filename) {
+ $file = file($filename);
+ foreach ($file as $line) {
+ if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\*\%-]*)\"?\s*([;#].*)?/",$line,$matches)) {
+ $conf[ $matches[1] ] = $matches[2];
+ }
+ }
+ if ( !isset($conf["AMPWEBROOT"]) || ($conf["AMPWEBROOT"] == "")) {
+ $conf["AMPWEBROOT"] = "/var/www/html";
+ } else {
+ $conf["AMPWEBROOT"] = rtrim($conf["AMPWEBROOT"],'/');
+ }
+
+ return $conf;
+}
+
+/** Adds a trailing slash to a directory, if it doesn't already have one
+ */
+function addslash($dir) {
+ return (($dir[ strlen($dir)-1 ] == '/') ? $dir : $dir.'/');
+}
+
+
+/********************************************************************************************************************/
+/* DR
+// **** Make sure we have STDIN etc
+
+// from ben-php dot net at efros dot com at php.net/install.unix.commandline
+if (version_compare(phpversion(),'4.3.0','<') || !defined("STDIN")) {
+ define('STDIN',fopen("php://stdin","r"));
+ define('STDOUT',fopen("php://stdout","r"));
+ define('STDERR',fopen("php://stderr","r"));
+ register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;' ) );
+}
+
+// **** Make sure we have PEAR's DB.php, and include it
+
+outn(_("Checking for PEAR DB.."));
+if (! @ include('DB.php')) {
+ out(_("FAILED"));
+ fatal(_("PEAR Missing"),sprintf(_("PEAR must be installed (requires DB.php). Include path: %s "), ini_get("include_path")));
+}
+out(_("OK"));
+
+
+// **** Make sure we have PEAR's GetOpts.php, and include it
+
+outn(_("Checking for PEAR Console::Getopt.."));
+if (! @ include("Console/Getopt.php")) {
+ out(_("FAILED"));
+ fatal(_("PEAR Getopt.php Missing"),sprintf(_("PEAR must be installed (requires Console/Getopt.php). Include path: %s"), ini_get("include_path")));
+}
+out(_("OK"));
+
+
+// **** Parse out command-line options
+
+$shortopts = "h?u:p:";
+$longopts = array("help","debug","dry-run","run-install","amportalconf=");
+
+$args = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), $shortopts, $longopts);
+if (is_object($args)) {
+ // assume it's PEAR_ERROR
+ out($args->message);
+ exit(255);
+}
+*/
+$debug = false;
+$dryrun = false;
+$run_install = false;
+
+/*
+foreach ($args[0] as $arg) {
+ switch ($arg[0]) {
+ case "--help": case "h": case "?":
+ showHelp();
+ exit(10);
+ break;
+ case "--dry-run":
+ out(_("Dry-run only, no files will be written"));
+ $dryrun = true;
+ break;
+ case "--debug":
+ $debug = true;
+ debug(_("Debug mode enabled"));
+ break;
+ case "--run-install":
+ $run_install = true;
+ out(_("Running module install.php and install.sql scripts"));
+ break;
+ case "--amportalconf":
+ $amportalconf = $arg[1];
+ out(sprintf(_("Using %s configuration file"), $amportalconf));
+ break;
+ }
+}
+
+// **** Check for amportal.conf
+
+outn(sprintf(_("Checking for %s "), $amportalconf)._(".."));
+if (!file_exists($amportalconf)) {
+ fatal(_("amportal.conf access problem: "),sprintf(_("The %s file does not exist, or is inaccessible"), $amportalconf));
+}
+out(_("OK"));
+
+// **** read amportal.conf
+
+outn(sprintf(_("Bootstrapping %s .."), $amportalconf));
+$amp_conf = parse_amportal_conf_bootstrap($amportalconf);
+if (count($amp_conf) == 0) {
+ fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf));
+}
+out(_("OK"));
+
+outn(sprintf(_("Parsing %s .."), $amportalconf));
+require_once($amp_conf['AMPWEBROOT']."/admin/functions.inc.php");
+$amp_conf = parse_amportal_conf($amportalconf);
+if (count($amp_conf) == 0) {
+ fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf));
+}
+out(_("OK"));
+
+$asterisk_conf_file = $amp_conf["ASTETCDIR"]."/asterisk.conf";
+outn(sprintf(_("Parsing %s .."), $asterisk_conf_file));
+$asterisk_conf = parse_asterisk_conf($asterisk_conf_file);
+if (count($asterisk_conf) == 0) {
+ fatal(_("asterisk.conf parsing failure"),sprintf(_("no entries found in %s"), $asterisk_conf_file));
+}
+out(_("OK"));
+
+// **** Connect to database
+
+outn(_("Connecting to database.."));
+
+# the engine to be used for the SQL queries,
+# if none supplied, backfall to mysql
+$db_engine = "mysql";
+if (isset($amp_conf["AMPDBENGINE"])){
+ $db_engine = $amp_conf["AMPDBENGINE"];
+}
+*/
+
+// Define the notification class for logging to the dashboard
+//
+$nt = notifications::create($db);
+
+// **** Create symlinks array
+$symlink_dirs = array();
+$symlink_dirs['sounds'] = $amp_conf['ASTVARLIBDIR'].'/sounds';
+$symlink_dirs['bin'] = $amp_conf['AMPBIN'];
+$symlink_dirs['etc'] = $amp_conf['ASTETCDIR'];
+$symlink_dirs['images'] = $amp_conf['AMPWEBROOT']."/admin/images";
+
+/*
+switch ($db_engine)
+{
+ case "pgsql":
+ case "mysql":
+ // datasource in in this style:
+ // dbengine://username:password@host/database
+
+ $db_user = $amp_conf["AMPDBUSER"];
+ $db_pass = $amp_conf["AMPDBPASS"];
+ $db_host = $amp_conf["AMPDBHOST"];
+ $db_name = $amp_conf["AMPDBNAME"];
+
+ $datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
+ $db = DB::connect($datasource); // attempt connection
+ break;
+
+ case "sqlite":
+ die_freepbx("SQLite2 support is deprecated. Please use sqlite3 only.");
+ break;
+
+ case "sqlite3":
+ if (!isset($amp_conf["AMPDBFILE"]))
+ fatal("You must setup properly AMPDBFILE in $amportalconf");
+
+ if (isset($amp_conf["AMPDBFILE"]) == "")
+ fatal("AMPDBFILE in $amportalconf cannot be blank");
+
+ // on centos this extension is not loaded by default
+ if (! extension_loaded('sqlite3.so') )
+ dl('sqlite3.so');
+
+ if (! @require_once('DB/sqlite3.php') )
+ {
+ die_freepbx("Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear.");
+ }
+
+ require_once('DB/sqlite3.php');
+ $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666";
+ $db = DB::connect($datasource);
+ break;
+
+ default:
+ fatal( "Unknown SQL engine: [$db_engine]");
+}
+
+if(DB::isError($db)) {
+ out(_("FAILED"));
+ debug($db->userinfo);
+ fatal(_("database connection failure"),("failed trying to connect to the configured database"));
+
+}
+
+//TODO : make this engine-neutral
+outn(_("Connecting to Asterisk manager interface.."));
+// connect to asterisk manager
+require_once($amp_conf['AMPWEBROOT'].'/admin/common/php-asmanager.php');
+$astman = new AGI_AsteriskManager();
+if (! $res = $astman->connect("127.0.0.1:".$amp_conf["ASTMANAGERPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
+ out(_("FAILED"));
+ fatal(_("Asterisk Manager Connection Failure"),sprintf(_("Failed to connect to the Asterisk manager through port: %s"), $amp_conf['ASTMANAGERPORT']));
+}
+*/
+
+//include common functions
+require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
+freepbx_log("retrieve_conf", "devel-debug", "Started retrieve_conf, DB Connection OK");
+
+// query for our modules
+// var_dump( $db );
+$modules = module_getinfo();
+
+//Putting the core module last, to move outbound-allroutes
+// last in from-internals-additional
+if (array_key_exists('core', $modules)) {
+ $core_tmp = $modules['core'];
+ unset($modules['core']);
+ $modules['core'] = $core_tmp;
+}
+
+// include any module global functions
+if(is_array($modules)){
+ foreach($modules as $key => $module) {
+ $return['retrieve_conf'] = $return['retrieve_conf'] . $key . "\n";
+ //only use this module if it's enabled (status=2)
+ if (isset($module['status']) && $module['status'] == MODULE_STATUS_ENABLED) {
+ // Make sure the module is installed and up to date
+ if ($run_install) module_install($key);
+ // active_modules array used in genConf function
+ $active_modules[] = $key;
+ //include module functions
+ if (is_file($amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php")) {
+ freepbx_log('retrieve_conf', 'devel-debug', 'Including '.$amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php");
+ include_once($amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php");
+ freepbx_log('retrieve_conf', 'devel-debug', $amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php processed OK");
+ }
+
+ // create symlinks for files in appropriate sub directories
+ symlink_subdirs( $amp_conf['AMPWEBROOT'].'/admin/modules/'.$key );
+ cp_subdirs( $amp_conf['AMPWEBROOT'].'/admin/modules/'.$key );
+ }
+ }
+}
+$return['retrieve_conf'] = $return['retrieve_conf'] . $amp_conf['AMPWEBROOT'];
+
+// create an object of the extensions class
+require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
+$ext = new extensions;
+
+// create objects for any module classes
+// currently only 1 class can be declared per module, not sure if that will be an issue
+if(isset($active_modules) && is_array($active_modules)){
+ foreach($active_modules as $active_module) {
+ freepbx_log('retrieve_conf', 'devel-debug', "Creating ".$active_module."_conf class");
+ $classname = $active_module."_conf";
+ if(class_exists($classname)) {
+ ${$classname} = new $classname;
+ }
+ }
+}
+
+$engineinfo = engine_getinfo();
+if($engineinfo['version'] == 0){
+ freepbx_log('retrieve_conf', 'fatal', "Failed to get engine information (engine_getinfo: {$engineinfo['engine']})");
+ fatal(_("Failed to get engine_info"),_("retreive_conf failed to get engine information and cannot configure up a softwitch with out it. Error: {$engineinfo['engine']}"));
+}
+// was setting these variables before, assume we still need them
+$engine = $engineinfo['engine'];
+$version = $engineinfo['version'];
+
+// Check for and report any extension conflicts
+//
+
+$extens_ok = true;
+$dests_ok = true;
+
+$nt = notifications::create($db);
+
+$my_hash = array_flip($active_modules);
+$my_prob_extens = framework_list_extension_conflicts($my_hash);
+
+if (empty($my_prob_extens)) {
+ $nt->delete('retrieve_conf', 'XTNCONFLICT');
+} else {
+ $previous = null;
+ $str = null;
+ $count = 0;
+ foreach ($my_prob_extens as $extens) {
+ foreach ($extens as $exten => $details) {
+ if ($exten != $previous) {
+ $str .= "Extension: $exten:<br />";
+ $count++;
+ }
+ $str .= sprintf("%8s: %s<br />",$details['status'], $details['description']);
+ $previous = $exten;
+ }
+ }
+ $nt->add_error('retrieve_conf', 'XTNCONFLICT', sprintf(_("There are %s conflicting extensions"),$count), $str);
+ $extens_ok = false;
+}
+
+// Check for and report any bogus destinations
+//
+$my_probs = framework_list_problem_destinations($my_hash, !$amp_conf['CUSTOMASERROR']);
+
+if (empty($my_probs)) {
+ $nt->delete('retrieve_conf', 'BADDEST');
+} else {
+ $results = array();
+ $count = 0;
+ $str = null;
+ foreach ($my_probs as $problem) {
+ //print_r($problem);
+ $results[$problem['status']][] = $problem['description'];
+ $count++;
+ }
+ foreach ($results as $status => $subjects) {
+ $str .= sprintf(_("DEST STATUS: %s%s"),$status,"\n");
+ foreach ($subjects as $subject) {
+ //$str .= $subject."<br />";
+ $str .= " ".$subject."\n";
+ }
+ }
+ $nt->add_error('retrieve_conf', 'BADDEST', sprintf(_("There are %s bad destinations"),$count), $str);
+ $dests_ok = false;
+}
+
+if ((!$exten_ok && $amp_conf['XTNCONFLICTABORT']) || (!$dest_ok && $amp_conf['BADDESTABORT'])) {
+ out(_("Aborting reload because extension conflicts or bad destinations"));
+ exit(20);
+}
+//$return['retrieve_conf'] = $return['retrieve_conf'] . "\n";
+
+// run all of the *_get_config and _hookGet_config functions, which will populate the appropriate objects
+if(isset($active_modules) && is_array($active_modules)){
+ foreach($active_modules as $module) {
+ $funcname = $module."_get_config";
+ if (function_exists($funcname)) {
+ freepbx_log('retrieve_conf', 'devel-debug', 'Calling '.$funcname.'()');
+ $return['retrieve_conf'] = $return['retrieve_conf'] . $funcname . "\n";
+ $funcname($engine);
+ }
+ }
+ foreach($active_modules as $module) {
+ $funcname = $module."_hookGet_config";
+ if (function_exists($funcname)) {
+ freepbx_log('retrieve_conf', 'devel-debug', 'Calling '.$funcname.'()');
+ $return['retrieve_conf'] = $return['retrieve_conf'] . $funcname . "\n";
+ $funcname($engine);
+ }
+ }
+}
+
+// extensions_additional.conf
+// create the from-internal-additional context so other can add to it
+$ext->add('from-internal-additional', 'h', '', new ext_hangup(''));
+//echo $ext->get_filename();
+//echo $ext->generateConf();
+write_file($ext->get_filename(),$ext->generateConf());
+
+// now we write out our conf files for modules
+// check for any objects for each of the active modules
+// ** conferences is an example of a module that write a conf
+if(isset($active_modules) && is_array($active_modules)){
+ foreach($active_modules as $active_module) {
+ $classname = $active_module."_conf";
+ if(class_exists($classname) && get_class(${$classname}) !== false) {
+ //echo ${$classname}->get_filename();
+ //echo ${$classname}->generateConf();
+
+ // if the module returns an array, it wants to write multiple files
+ // ** pinsets is an example of a module that does this
+ if (is_array(${$classname}->get_filename())) {
+ foreach(${$classname}->get_filename() as $modconf) {
+ freepbx_log('retrieve_conf', 'devel-debug', 'generateConf from '.$classname.'->'.$modconf.'');
+ write_file($modconf,${$classname}->generateConf($modconf));
+ }
+ } else {
+ freepbx_log('retrieve_conf', 'devel-debug', 'generateConf from '.$classname);
+ write_file(${$classname}->get_filename(),${$classname}->generateConf());
+ }
+ }
+ }
+}
+
+
+function write_file($filename,$contents) {
+ global $asterisk_conf;
+ freepbx_log('retrieve_conf', 'devel-debug', 'Writing '.$filename);
+ if (isset($filename) && !empty($filename)) {
+ if ($fd = fopen(addslash($asterisk_conf['astetcdir']).$filename, "w")) {
+ fwrite($fd, WARNING_BANNER );
+ fwrite($fd, $contents);
+ fclose($fd);
+ }
+ }
+}
+
+/* file_exists_wrapper()
+ * wrapper for file_exists() with the following additonal functionality.
+ * if the file is a symlink, it will check if the link exists and if not
+ * it will try to remove this file. It returns a false (file does not exists)
+ * if the file is successfully removed, true if not. If not a symlink, just
+ * returns file_exists()
+ */
+function file_exists_wrapper($string) {
+ if (is_link($string)) {
+ $linkinfo = readlink($string);
+ if ($linkinfo === false) {
+ //TODO: throw error?
+ return !unlink($string);
+ } else {
+ if (file_exists($linkinfo)) {
+ return true;
+ } else {
+ return !unlink($string);
+ }
+ }
+ } else {
+ return file_exists($string);
+ }
+}
+
+function symlink_subdirs($moduledir) {
+global $amp_conf;
+$symlink_dirs = array();
+$symlink_dirs['sounds'] = $amp_conf['ASTVARLIBDIR'].'/sounds';
+$symlink_dirs['bin'] = $amp_conf['AMPBIN'];
+$symlink_dirs['etc'] = $amp_conf['ASTETCDIR'];
+$symlink_dirs['images'] = $amp_conf['AMPWEBROOT']."/admin/images";
+
+// global $symlink_dirs;
+ $symlink_errors = false;
+
+ $nt = notifications::create($db);
+
+ foreach ($symlink_dirs as $subdir => $targetdir) {
+ $dir = addslash($moduledir).$subdir;
+ if (is_dir($dir)) {
+ $d = opendir($dir);
+ while ($file = readdir($d)) {
+ if ($file[0] != '.') {
+ $src = addslash($dir).$file;
+ $dest = addslash($targetdir).$file;
+ if (file_exists_wrapper($dest)) {
+ if (!is_link($dest)) {
+ freepbx_log('retrieve-conf', 'error', $dest.' already exists, and is not a symlink!');
+ $nt->add_error('retrieve_conf', 'SYMLINK', _("symlink from modules failed"), sprintf(_("retrieve_conf failed to sym link the %s file from modules"),$dest));
+ $symlink_errors = true;
+ } else if (readlink($dest) != $src) {
+ // TODO : is this the proper handling? should we just overwrite..?
+ freepbx_log('retrieve-conf', 'error', $dest.' already exists, and is linked to something else!');
+ $nt->add_error('retrieve_conf', 'SYMLINK', _("symlink from modules failed"), sprintf(_("retrieve_conf failed to sym link the %s file from modules"),$dest));
+ $symlink_errors = true;
+ } else {
+ freepbx_log('retrieve-conf', 'devel-debug', $dest.' already points to '.$src.' - OK');
+ }
+ } else {
+// // symlink, unlike copy, doesn't overwrite - have to delete first
+// if (is_link($dest) || file_exists($dest)) {
+// unlink($dest);
+// }
+ if (symlink($src, $dest)) {
+ freepbx_log('retrieve-conf', 'devel-debug', 'Symlinked '.$src.' to '.$dest);
+ } else {
+ freepbx_log('retreive-conf', 'devel-debug', 'Cannot symlink '.$src.' to '.$dest.'. Check Permissions?');
+ }
+ }
+ }
+ }
+ closedir($d);
+ }
+ }
+ if (!$symlink_errors) {
+ $nt->delete('retrieve_conf', 'SYMLINK');
+ }
+}
+
+// wrap copy with error handler
+//
+function err_copy($source, $dest) {
+ $ret = false;
+ set_error_handler("report_errors");
+ if (copy($source, $dest)) {
+ $ret = chmod($dest,'0754');
+ }
+ restore_error_handler();
+ return $ret;
+}
+
+// wrap unlink with error handler
+//
+function err_unlink($dest) {
+ set_error_handler("report_errors");
+ $ret = unlink($dest);
+ restore_error_handler();
+ return $ret;
+}
+
+function cp_subdirs($moduledir) {
+ global $cp_errors;
+global $amp_conf;
+$cp_dirs = array();
+$cp_dirs['agi-bin'] = $amp_conf['ASTAGIDIR'];
+// global $cp_dirs;
+
+ $cp_errors = "";
+ foreach ($cp_dirs as $subdir => $targetdir) {
+ $dir = addslash($moduledir).$subdir;
+ if (is_dir($dir)) {
+ $d = opendir($dir);
+ while ($file = readdir($d)) {
+ if ($file[0] != '.') {
+ $sourcefile = addslash($dir).$file;
+ $targetfile = addslash($targetdir).$file;
+
+ if (file_exists_wrapper($targetfile)) {
+ if (is_link($targetfile)) {
+ if (err_unlink($targetfile)) {
+ freepbx_log('retrieve-conf', 'devel-debug', "$targetfile was symbolic link, unlink successful");
+ } else {
+ freepbx_log('retrieve-conf', 'error', "$targetfile is a symblolic link, failed to unlink!");
+ break;
+ }
+ }
+ }
+ // OK, now either the file is a regular file or isn't there, so proceed
+ //
+ if (err_copy($sourcefile,$targetfile)) {
+ freepbx_log('retrieve-conf', 'devel-debug', "$targetfile successfully copied");
+ // copy was successful, make sure it has execute permissions
+ chmod($targetfile,0754);
+ } else {
+ freepbx_log('retrieve-conf', 'error', "$targetfile failed to copy from module directory");
+ }
+ }
+ }
+ closedir($d);
+ }
+ }
+ $nt = notifications::create($db);
+ if ($cp_errors) {
+ $nt->add_error('retrieve_conf', 'CPAGIBIN', _("Failed to copy from module agi-bin"), sprintf(_("Retrieve conf failed to copy file(s) from a module's agi-bin dir: %s"),$cp_errors));
+ } else {
+ $nt->delete('retrieve_conf', 'CPAGIBIN');
+ }
+}
+
+function report_errors($errno, $errstr, $errfile, $errline) {
+ global $cp_errors;
+ freepbx_log('retrieve-conf', 'error', "php reported: '".mysql_real_escape_string($errstr)."' after copy or unlink attempt!");
+ $cp_errors .= $errstr."\n";
+}
+
+/** Check if there is a job running, if one is found then all is good, if one is not found, it will be added and a
+ * notification will be sent.
+ */
+function install_cron_scheduler() {
+ global $amp_conf;
+ global $nt;
+
+ // crontab appears to return an error when no entries, os only fail if error returned AND a list of entries.
+ // Don't know if this will ever happen, but a failure and a list could indicate something wrong.
+ //
+ exec("/usr/bin/crontab -l", $outlines, $ret);
+ if ($ret && count($outlines)) {
+ $nt->add_error('retrieve_conf', 'CRONMGR', _("Failed to check crontab for cron manager"), sprintf(_("crontab returned %s error code when checking for crontab entries to start freepbx-cron-scheduler.php crontab manager"),$ret));
+ } else {
+ $nt->delete('retrieve_conf', 'CRONMGR');
+ $outlines2 = preg_grep("/freepbx-cron-scheduler.php/",$outlines);
+ $cnt = count($outlines2);
+ switch ($cnt) {
+ case 0:
+ /** grab any other cronjobs that are running as asterisk and NOT associated with backups
+ * this code was taken from the backup module for the most part. But seems to work...
+ */
+ $outlines = array();
+ exec("/usr/bin/crontab -l | grep -v ^#\ DO\ NOT | grep -v ^#\ \( | grep -v freepbx-cron-scheduler.php", $outlines, $ret);
+ $crontab_entry = "";
+ foreach ($outlines as $line) {
+ $crontab_entry .= $line."\n";
+ }
+ // schedule to run hourly, at a random time. The random time is explicit to accomodate things like module_admin online update checking
+ // since we will want a random access to the server. In the case of module_admin, that will also be scheduled randomly within the hour
+ // that it is to run
+ //
+ $crontab_entry .= rand(0,59)." * * * * ".$amp_conf['AMPBIN']."/freepbx-cron-scheduler.php";
+ system("/bin/echo '$crontab_entry' | /usr/bin/crontab -");
+ break;
+ case 1:
+ // already running, nothing to do
+ break;
+ default:
+ // error, there should never be more than one running
+ echo "TODO: deal with error here\n";
+ $nt->add_error('retrieve_conf', 'CRONMGR', _("Multiple freepbx-cron-scheduler.php running"), sprintf(_("There were %s freepbx-cron-scheduler.php instances running. There should be only 1."),$cnt));
+ }
+ }
+}
+include($amp_conf['AMPBIN']."/libfreepbx.confgen.php");
+// script to write op_server.cfg file from mysql
+//
+if ($amp_conf["AMPDBENGINE"] != 'sqlite3') {
+ // sqlite3 not supported just yet
+ $script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.pl '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
+ exec($script);
+}
+
+// generate configuration files
+//
+// Leave the legacy scripts in for a little while to help with odd-ball upgrade scenarios if they haven't gotten
+// a module upgraded yet. In particular Queues
+//
+if (!isset($core_conf) || !is_a($core_conf, "core_conf")) {
+ generate_configurations_sip($version);
+ generate_configurations_iax($version);
+ generate_configurations_zap($version);
+}
+
+// Check and install the freepbx-cron-scheduler.php manager
+//
+install_cron_scheduler();
+// run retrieve_conf_post_custom
+// If the following file exists, it will be run. This allows customization to be run automatically after the normal
+// processing. Caution should be taken using this as it is only deisgned for expert usage. Errors in the code will
+// have bad consequences and can cripple the system.
+//
+if (isset($amp_conf['AMPLOCALBIN'])) {
+$post_custom = $amp_conf['AMPLOCALBIN'].'/retrieve_conf_post_custom';
+ if (file_exists($post_custom)) {
+ outn(sprintf(_("Found script %s, executing.."), $post_custom));
+ include($post_custom);
+ out(_("OK"));
+ }
+}
+
+out("after post");
+/* As of Asterisk 1.4.16 or there abouts, a missing #include file will make the reload fail. So
+ we need to make sure that we have such for everything that is in our configs. We will simply
+ look for the #include statements and touch the files vs. trying to inventory everything we may
+ need and then forgetting something.
+*/
+
+exec("grep '#include' ".$amp_conf['ASTETCDIR']."/*.conf | sed 's/;.*//; s/#include//'",$output,$retcode);
+if ($retcode != 0) {
+ error("Error code $retcode: trying to search for missing #include files");
+}
+foreach($output as $file) {
+ if (trim($file) == '') {
+ continue;
+ }
+ $parse1 = explode(':',$file);
+ $parse2 = explode(';',$parse1[1]);
+ $rawfile = trim($parse2[0]);
+ if ($rawfile == '') {
+ continue;
+ }
+
+ $target = ($rawfile[0] == '/') ? $rawfile : $amp_conf['ASTETCDIR']."/$rawfile";
+
+ if (!file_exists($target)) {
+ exec("touch $target", $output, $retcode);
+ error("Error code $retcode: trying to create empty file $target");
+ }
+}
+
+// **** Set reload flag for AMP admin
+needreload();
+if (isset($amp_conf["AMPWEBADDRESS"]) && $amp_conf["AMPWEBADDRESS"])
+{
+ out(sprintf(_("Please update your modules and reload Asterisk by visiting %s"), "http://".$amp_conf["AMPWEBADDRESS"]."/admin"));
+}
+else
+{
+ out(_("Please update your modules and reload Asterisk by browsing to your server."));
+}
+ $nt->delete('retrieve_conf', 'FATAL');
+out("end\n");
+$exit_val = 0;
+?>
--- /dev/null
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * The PEAR DB driver for PHP's sqlite3 extension
+ * for interacting with SQLite3 databases
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Database
+ * @package DB
+ * @author Bruno Fleisch
+ * @copyright 1997-2005 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
+ * @version CVS: $Id: sqlite3.php,v 1.3 2007/04/04 14:13:19 bfleisch Exp $
+ * @link http://pear.php.net/package/DB
+ */
+
+include_once 'DB/common.php';
+
+
+
+/**
+ * The methods PEAR DB uses to interact with PHP's sqlite extension
+ * for interacting with SQLite databases
+ *
+ * These methods overload the ones declared in DB_common.
+ *
+ */
+
+class DB_sqlite3 extends DB_common
+{
+
+ // {{{ PROPERTIES
+
+
+ var $phptype = 'sqlite3';
+
+ /**
+ * The database syntax variant to be used (db2, access, etc.), if any
+ * @var string
+ */
+ var $dbsyntax = 'sqlite3';
+
+ /**
+ * The capabilities of this DB implementation
+ *
+ * The 'new_link' element contains the PHP version that first provided
+ * new_link support for this DBMS. Contains false if it's unsupported.
+ *
+ * Meaning of the 'limit' element:
+ * + 'emulate' = emulate with fetch row by number
+ * + 'alter' = alter the query
+ * + false = skip rows
+ *
+ * @var array
+ */
+ var $features = array(
+ 'limit' => 'alter',
+ 'new_link' => false,
+ 'numrows' => 'emulate',
+ 'pconnect' => true,
+ 'prepare' => false,
+ 'ssl' => false,
+ 'transactions' => false,
+ );
+
+
+ /**
+ * A mapping of native error codes to DB error codes
+ *
+ * {@internal Error codes according to sqlite_exec. See the online
+ * manual at http://sqlite.org/c_interface.html for info.
+ * This error handling based on sqlite_exec is not yet implemented.}}
+ *
+ * @var array
+ */
+ var $errorcode_map = array(
+ );
+
+ /**
+ * The raw database connection created by PHP
+ * @var resource
+ */
+ var $connection;
+
+ /* The DSN information for connecting to a database
+ * @var array
+ */
+ var $dsn = array();
+
+
+ /**
+ * SQLite data types
+ *
+ * @link http://www.sqlite.org/datatypes.html
+ *
+ * @var array
+ */
+ var $keywords = array (
+ 'BLOB' => '',
+ 'BOOLEAN' => '',
+ 'CHARACTER' => '',
+ 'CLOB' => '',
+ 'FLOAT' => '',
+ 'INTEGER' => '',
+ 'KEY' => '',
+ 'NATIONAL' => '',
+ 'NUMERIC' => '',
+ 'NVARCHAR' => '',
+ 'PRIMARY' => '',
+ 'TEXT' => '',
+ 'TIMESTAMP' => '',
+ 'UNIQUE' => '',
+ 'VARCHAR' => '',
+ 'VARYING' => '',
+ );
+
+ /**
+ * The most recent error message from $php_errormsg
+ * @var string
+ * @access private
+ */
+ var $_lasterror = '';
+
+
+
+ // }}}
+ // {{{ constructor
+
+ /**
+ * constructor
+ *
+ * @return void
+ */
+
+ function DB_sqlite3()
+ {
+ $this->DB_common();
+ }
+
+
+ // }}}
+ // {{{ string errorNative(void)
+
+ /**
+ * Gets the DBMS' native error code produced by the last query
+ *
+ * @return mixed the DBMS' error code. A DB_Error object on failure.
+ */
+
+ function errorNative()
+ {
+ return sqlite3_error ($this->connection);
+ }
+
+ // }}}
+ // {{{ mixed connect(array $dsn, bool $persitent)
+
+ /**
+ * create or connect to the specified database.
+ *
+ * @param array $dsn the data source name
+ * @param bool $persitent if the connection is persitent
+ *
+ * @return DB_OK on success or DB_error object on failure
+ */
+
+
+ function connect($dsn, $persitent = false)
+ {
+ $this->connection = sqlite3_open ($dsn['database']);
+ if (!$this->connection)
+ return $this->raiseError(DB_ERROR_NODBSELECTED);
+
+ return DB_OK;
+ }
+
+ // }}}
+ // {{{ bool disconnect (void)
+
+
+ /**
+ * release all resources for this connection, and close database
+ *
+ * @return bool TRUE on sucess, FALSE otherwise.
+ */
+
+ function disconnect()
+ {
+ return sqlite3_close ($this->connection);
+ }
+
+ // }}}
+ // {{{ mixed simpleQuery(string $sql)
+
+ /**
+ * execute a SQL query.
+ *
+ * @param string $query the SQL query
+ *
+ * @return mixed + object DB_error object on failure
+ * + object Result resource for SELECT requests
+ * + bool TRUE for other sucessful requests
+ */
+
+ function simpleQuery($query)
+ {
+
+ $isSelect = preg_match ("/^\s*SELECT/i", $query);
+
+ #$handle = fopen("/tmp/sql.txt",'a');
+ #fwrite($handle, "<strong>sqlite3 simpleQuery: $query</strong><br>\n");
+ #fclose($handle);
+
+ if (! $isSelect)
+ $this->result = sqlite3_exec($this->connection, $query);
+ else
+ $this->result = sqlite3_query($this->connection, $query);
+
+ if (!$this->result)
+ return $this->RaiseError($this->errorNative());
+
+ return $this->result;
+ }
+
+ // }}}
+ // {{{ mixed fetchInto(resource $res, array $arr, int $fetchmode [, int $rownum])
+
+ /**
+ * Fetch a row of data into an array which is passed by reference
+ *
+ * The type of array returned can be controlled either by setting this
+ * method's <var>$fetchmode</var> parameter or by changing the default
+ * fetch mode setFetchMode() before calling this method.
+ *
+ * There are two options for standardizing the information returned
+ * from databases, ensuring their values are consistent when changing
+ * DBMS's. These portability options can be turned on when creating a
+ * new DB object or by using setOption().
+ *
+ * + <var>DB_PORTABILITY_LOWERCASE</var>
+ * convert names of fields to lower case
+ *
+ * + <var>DB_PORTABILITY_RTRIM</var>
+ * right trim the data
+ *
+ * @param resource $result the result resource
+ * @param array &$arr the variable where the data should be placed
+ * @param int $fetchmode the constant indicating how to format the data
+ * @param int $rownum the row number to fetch (index starts at 0)
+ *
+ * @return mixed DB_OK if a row is processed, NULL when the end of the
+ * result set is reached or a DB_Error object on failure
+ *
+ * @see DB_common::setOption(), DB_common::setFetchMode()
+ */
+
+ function fetchInto($result, &$arr, $fetchmode, $rownum = null)
+ {
+ if ($rownum !==NULL)
+ return $this->RaiseError (DB_ERROR_NOTIMPLEMENTED);
+
+ switch ($fetchmode)
+ {
+
+ case DB_FETCHMODE_ORDERED:
+ $fetchfunc="sqlite3_fetch";
+ break;
+
+ case DB_FETCHMODE_OBJECT:
+ return $this->RaiseError(DB_ERROR_NODBSELECTED);
+ break;
+
+ case DB_FETCHMODE_ASSOC:
+ default:
+ $fetchfunc="sqlite3_fetch_array";
+ break;
+ }
+
+ $arr = $fetchfunc($result);
+
+ if ($arr)
+ return DB_OK;
+
+ return NULL;
+ }
+
+ // }}}
+ // {{{ string modifyLimitQuery(string $query, int $from, int $count [,mixed $params])
+
+
+ /**
+ * Adds LIMIT clauses to a query string according to current DBMS standards
+ *
+ * It is defined here to assure that all implementations
+ * have this method defined.
+ *
+ * @param string $query the query to modify
+ * @param int $from the row to start to fetching (0 = the first row)
+ * @param int $count the numbers of rows to fetch
+ * @param mixed $params array, string or numeric data to be used in
+ * execution of the statement. Quantity of items
+ * passed must match quantity of placeholders in
+ * query: meaning 1 placeholder for non-array
+ * parameters or 1 placeholder per array element.
+ *
+ * @return string the query string with LIMIT clauses added
+ *
+ * @access protected
+ */
+
+ function modifyLimitQuery($query, $from, $count, $params = array())
+ {
+ return "$query LIMIT $count OFFSET $from";
+ }
+
+
+ // }}}
+ // {{{ bool freeResult(void)
+
+ /**
+ * free the specified result.
+ *
+ * @param resource $result the query resource result
+ *
+ * @return bool DB_OK
+ *
+ */
+
+ function freeResult($result)
+ {
+ sqlite3_query_close($result);
+ return DB_OK; /* always sucessful ! */
+ }
+
+ // }}}
+ // {{{ int affectedRow(void)
+
+ /**
+ * Determines the number of rows affected by a data maniuplation query
+ *
+ * 0 is returned for queries that don't manipulate data.
+ *
+ * @return int the number of rows. A DB_Error object on failure.
+ */
+
+ function affectedRows()
+ {
+ return sqlite3_changes ($this->connection);
+ }
+
+ // }}}
+ // {{{ mixed numCols(resource $result)
+
+ /**
+ * Get the the number of columns in a result set
+ *
+ * @return int the number of columns. A DB_Error object on failure.
+ */
+
+ function numCols($result)
+ {
+ return sqlite3_column_count($result);
+ }
+
+ // {{{ mixed createSequence(string $seq_name)
+
+ /**
+ * Creates a new sequence
+ *
+ * The name of a given sequence is determined by passing the string
+ * provided in the <var>$seq_name</var> argument through PHP's sprintf()
+ * function using the value from the <var>seqname_format</var> option as
+ * the sprintf()'s format argument.
+ *
+ * <var>seqname_format</var> is set via setOption().
+ *
+ * @param string $seq_name name of the new sequence
+ *
+ * @return int DB_OK on success. A DB_Error object on failure.
+ *
+ * @see DB_common::dropSequence(), DB_common::getSequenceName(),
+ * DB_common::nextID()
+ */
+
+ function createSequence($seq_name)
+ {
+ return $this->query ("CREATE TABLE " . $this->getSequenceName($seq_name) . " (id INTEGER PRIMARY KEY AUTOINCREMENT)");
+ }
+
+ // }}}
+ // {{{ mixed nextId(string $sequence [, bool $ondemand])
+
+ /**
+ * Returns the next free id in a sequence
+ *
+ * @param string $seq_name name of the sequence
+ * @param boolean $ondemand when true, the seqence is automatically
+ * created if it does not exist
+ *
+ * @return int the next id number in the sequence.
+ * A DB_Error object on failure.
+ *
+ * @see DB_common::createSequence(), DB_common::dropSequence(),
+ * DB_common::getSequenceName()
+ */
+ function nextId($seq_name, $ondemand = true)
+ {
+
+ $sqn = $this->getSequenceName($seq_name);
+
+ if ($ondemand)
+ {
+ $tables = $this->getTables();
+ if (DB::isError($tables)) return $tables;
+
+ if (! in_array ($sqn, $tables))
+ {
+ $res = $this->createSequence($seq_name);
+ if ( DB::isError($res))
+ return $res;
+ }
+ }
+
+ $res = $this->query ("INSERT INTO " . $sqn . " VALUES (NULL)");
+ if (DB::isError($res)) return $res;
+
+ return sqlite3_last_insert_rowid ($this->connection);
+ }
+
+ // }}}
+ // {{{ mixed dropSequence (string $seq_name)
+
+ /**
+ * Deletes a sequence
+ *
+ * @param string $seq_name name of the sequence to be deleted
+ *
+ * @return int DB_OK on success. A DB_Error object on failure.
+ *
+ * @see DB_common::createSequence(), DB_common::getSequenceName(),
+ * DB_common::nextID()
+ */
+ function dropSequence($seq_name)
+ {
+ return $this->query("DROP TABLE ". $this->getSequenceName($seq_name));
+ }
+
+ // }}}
+ // {{{ string getSpecialQuery(string $type)
+
+ /**
+ * Obtains the query string needed for listing a given type of objects
+ *
+ * @param string $type the kind of objects you want to retrieve
+ *
+ * @return string the SQL query string or null if the driver doesn't
+ * support the object type requested
+ *
+ * @access protected
+ * @see DB_common::getListOf()
+ */
+
+ function getSpecialQuery($type)
+ {
+ switch ($type) {
+ case 'tables':
+ return "SELECT name FROM SQLITE_MASTER ORDER BY name";
+ default:
+ return $this->raiseError(DB_ERROR_UNSUPPORTED);
+ }
+ }
+
+ // }}}
+
+
+}
+?>
--- /dev/null
+<?php phpinfo(); ?>
+
--- /dev/null
+<?php
+
+# test.db.php
+# David Rowe Feb 2008
+#
+# Used to test and debug PEAR/DB sqlite3 support for FreePBX
+
+require_once('DB.php'); // PEAR must be installed
+
+/*
+ datasource in in this style:
+ dbengine://username:password@host/database
+*/
+
+# Mysql connection as a starting point ----------------------------
+
+/*
+
+$db_engine = "mysql";
+$db_user = "asteriskuser";
+$db_pass = "amp109";
+$db_host = "localhost";
+$db_name = "asterisk";
+
+$datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
+$db = DB::connect($datasource); // attempt connection
+print("Connecting to $datasource.....<br>");
+if (DB::isError ($db))
+ die ("Cannot connect: " . $db->getMessage () . "\n");
+print("Disconnecting...<br>");
+$db->disconnect ();
+
+*/
+
+# Basic sqlite connection ----------------------------------------
+
+$options = array(
+ 'debug' => 4,
+ 'portability' => DB_PORTABILITY_NUMROWS
+);
+
+$file = "/var/lib/asterisk/freepbx.db";
+$datasource = "sqlite3:///" . $file . "?mode=0666";
+
+print("Connecting to $datasource.....<br>");
+
+if (! extension_loaded('sqlite3') ) {
+ print("Loading sqlite3.so....<br>");
+ dl('sqlite3.so');
+}
+
+$db = DB::connect($datasource, $options);
+if (DB::isError ($db))
+ die ("Cannot connect: " . $db->getMessage () . "\n");
+
+$result = $db->query ("SELECT * FROM admin");
+if (DB::isError ($result))
+ die ("SELECT failed: " . $result->getMessage () . "\n");
+
+print("admin table rows:<br>");
+while ($row =& $result->fetchRow ())
+ printf("  %s, %s<br>", $row[0], $row[1]);
+
+# numRows Test --------------------------------------------------
+
+$numRows = $result->numRows();
+
+if (DB::isError ($numRows))
+ die ("numRows failed: " . $numRows->getMessage () . "<br>");
+print ("result contains: $numRows rows<br>");
+
+# Try inserting a few values -----------------------------------
+
+$result =& $db->query ("INSERT INTO tbl1 VALUES ('AA',30)");
+
+if (DB::isError ($result))
+ die ("INSERT failed: " . $result->getMessage () . "\n");
+
+$result = $db->query ("SELECT * FROM tbl1");
+
+if (DB::isError ($result))
+ die ("SELECT failed: " . $result->getMessage () . "\n");
+
+while ($row =& $result->fetchRow ())
+ printf("  %s<br>", $row[0]);
+
+$result->free();
+print("Disconnecting...");
+$db->disconnect ();
+
+?>
--- /dev/null
+--- orig/common.php 2008-03-01 09:40:36.000000000 +1030
++++ mod/common.php 2008-03-01 09:14:34.000000000 +1030
+@@ -1213,6 +1213,7 @@
+ return $ret;
+ } else {
+ $this->last_parameters = array();
++ $this->last_query = $query;
+ $result = $this->simpleQuery($query);
+ if ($result === DB_OK || DB::isError($result)) {
+ return $result;
--- /dev/null
+--- freepbx-2.4.0-orig//amp_conf/htdocs/admin/modules/core/functions.inc.php 2008-02-10 05:16:02.000000000 +1030
++++ root/www/admin/modules/core/functions.inc.php 2008-03-11 11:31:52.000000000 +1030
+@@ -2886,6 +2886,7 @@
+ // TODO: sqlite work arround - diego
+ // TODO: WILL NOT WORK, need to remove the usage of SUBSTRING
+ // need to reorder the trunks in PHP code
++/*
+ $sqlstr = "SELECT t.variable, t.value, d.value state FROM `globals` t ";
+ $sqlstr .= "JOIN (SELECT x.variable, x.value FROM globals x WHERE x.variable LIKE 'OUTDISABLE\_%') d ";
+ $sqlstr .= "ON substring(t.variable,5) = substring(d.variable,12) WHERE t.variable LIKE 'OUT\_%' ";
+@@ -2894,9 +2895,9 @@
+ $sqlstr .= "WHERE v.variable LIKE 'OUT\_%' AND concat('OUTDISABLE_',substring(v.variable,5)) NOT IN ";
+ $sqlstr .= " ( SELECT variable from globals WHERE variable LIKE 'OUTDISABLE\_%' ) ";
+ $sqlstr .= "ORDER BY variable";
+-
+- //$unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");
+- $unique_trunks = sql($sqlstr,"getAll");
++*/
++ $unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");
++ //$unique_trunks = sql($sqlstr,"getAll");
+ }
+ else
+ {
+--- freepbx-2.4.0-orig//amp_conf/htdocs/admin/common/db_connect.php 2007-09-09 20:41:11.000000000 +0930
++++ root/www/admin/common/db_connect.php 2008-03-11 11:31:52.000000000 +1030
+@@ -52,7 +52,11 @@
+ }
+
+ $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666";
+- $db = DB::connect($datasource);
++ $options = array(
++ 'debug' => 4,
++ 'portability' => DB_PORTABILITY_NUMROWS
++ );
++ $db = DB::connect($datasource, $options);
+ break;
+
+ default:
+@@ -70,6 +74,7 @@
+ $nt = notifications::create($db);
+
+ if ($amp_conf['AMPDBPASS'] == $amp_conf_defaults['AMPDBPASS'][1]) {
++ print
+ $nt->add_warning('core', 'AMPDBPASS', _("Default SQL Password Used"), _("You are using the default SQL password that is widely known, you should set a secure password"));
+ } else {
+ $nt->delete('core', 'AMPDBPASS');
+--- freepbx-2.4.0-orig//amp_conf/htdocs/recordings/includes/database.php 2006-05-01 01:05:45.000000000 +0930
++++ root/www/recordings/includes/database.php 2008-03-11 11:31:52.000000000 +1030
+@@ -43,18 +43,25 @@
+ // connect string
+ if ($dbfile) {
+ // datasource mostly to support sqlite: dbengine://dbfile?mode=xxxx
+- $dsn = $engine . '://' . $dbfile . '?mode=0666';
++ $datasource = $engine . ':///' . $dbfile . '?mode=0666';
++ $options = array(
++ 'debug' => 4
++ );
++ if (! extension_loaded('sqlite3') ) {
++ dl('sqlite3.so');
++ }
++
+ }
+ else {
+ // datasource in in this style: dbengine://username:password@host/database
+ $datasource = $engine . '://' . $username . ':' . $password . '@' . $host . '/' . $name;
+- }
+
+- // options
+- $options = array(
+- 'debug' => 2,
+- 'portability' => DB_PORTABILITY_LOWERCASE|DB_PORTABILITY_RTRIM|DB_PORTABILITY_DELETE_COUNT|DB_PORTABILITY_NUMROWS|DB_PORTABILITY_ERRORS|DB_PORTABILITY_NULL_TO_EMPTY,
+- );
++ // options
++ $options = array(
++ 'debug' => 2,
++ 'portability' => DB_PORTABILITY_LOWERCASE|DB_PORTABILITY_RTRIM|DB_PORTABILITY_DELETE_COUNT|DB_PORTABILITY_NUMROWS|DB_PORTABILITY_ERRORS|DB_PORTABILITY_NULL_TO_EMPTY,
++ );
++ }
+
+ // attempt connection
+ $dbh = DB::connect($datasource,$options);
+--- freepbx-2.4.0-orig//amp_conf/htdocs/admin/cdr/lib/defines.php 2006-09-26 20:48:51.000000000 +0930
++++ root/www/admin/cdr/lib/defines.php 2008-03-11 11:31:52.000000000 +1030
+@@ -12,7 +12,7 @@
+ return $conf;
+ }
+
+-$amp_conf = parse_amportal_conf("/etc/amportal.conf");
++$amp_conf = parse_amportal_conf("/etc/amportal.conf");
+
+
+ define ("WEBROOT", "http://".$amp_conf["AMPWEBADDRESS"]."/admin/cdr/");
+@@ -27,8 +27,8 @@
+ define ("PORT", "5432");
+ define ("USER", $amp_conf["AMPDBUSER"]);
+ define ("PASS", $amp_conf["AMPDBPASS"]);
+-define ("DBNAME", "asteriskcdrdb");
+-define ("DB_TYPE", "mysql"); // mysql or postgres
++define ("DBNAME","/var/asteriskcdr.db");
++define ("DB_TYPE","sqlite3");
+
+
+ define ("DB_TABLENAME", "cdr");
+@@ -47,16 +47,36 @@
+
+ function DbConnect()
+ {
+- if (DB_TYPE == "postgres")
+- {
++ switch (DB_TYPE)
++ {
++
++ case "pgsql":
+ $datasource = 'pgsql://'.USER.':'.PASS.'@'.HOST.'/'.DBNAME;
+- }
+- else
+- {
++ $options = array();
++ break;
++
++ case "mysql":
+ $datasource = DB_TYPE.'://'.USER.':'.PASS.'@'.HOST.'/'.DBNAME;
+- }
++ $options = array();
++ break;
++
++ case "sqlite3":
++ $datasource = DB_TYPE . ':///' . DBNAME . '?mode=0666';
++ if (! extension_loaded('sqlite3') ) {
++ dl('sqlite3.so');
++ }
++ if (! require_once('DB/sqlite3.php') )
++ {
++ die_freepbx("Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear.");
++ }
++ $options = array(
++ 'debug' => 4,
++ 'portability' => DB_PORTABILITY_NUMROWS
++ );
++ break;
++ }
+
+- $db = DB::connect($datasource); // attempt connection
++ $db = DB::connect($datasource, $options); // attempt connection
+
+ if(DB::isError($db))
+ {
+--- freepbx-2.4.0-orig//amp_conf/htdocs/admin/cdr/lib/Class.Table.php 2006-09-26 20:48:51.000000000 +0930
++++ root/www/admin/cdr/lib/Class.Table.php 2008-03-11 11:31:52.000000000 +1030
+@@ -80,8 +80,11 @@
+
+ //$res=DbExec($link, $QUERY);
+ $res = $DBHandle -> query($QUERY);
++ if(DB::IsError($res)) {
++ print($res->getMessage());
++ print("<br>Is Asterisk CDR database initialised?");
++ }
+
+-
+ $num = $res -> numRows();
+
+
+--- freepbx-2.4.0-orig//SQL/newinstall.sqlite3.sql 2008-02-11 14:27:53.000000000 +1030
++++ freepbx-2.4.0//SQL/newinstall.sqlite3.sql 2008-03-08 10:05:24.000000000 +1030
+@@ -323,7 +323,7 @@
+ -- Dumping data for table `modules`
+ --
+
+-DROP TABLE IF EXISTS `modules_xml`;
++DROP TABLE IF EXISTS `module_xml`;
+ CREATE TABLE `module_xml` (
+ `id` varchar(20) NOT NULL default 'xml',
+ `time` int(11) NOT NULL default '0',
+--- freepbx-2.4.0-orig//install_amp 2008-01-28 04:22:58.000000000 +1030
++++ freepbx-2.4.0//install_amp 2008-03-08 10:05:29.000000000 +1030
+@@ -4,7 +4,7 @@
+ require_once ("libfreepbx.install.php");
+
+ # constants
+-define("AMP_CONF", "/etc/amportal.conf");
++define("AMP_CONF", "/etc/amportal.conf");
+ define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
+ define("UPGRADE_DIR", dirname(__FILE__)."/upgrades");
+ define("MODULE_DIR", dirname(__FILE__)."/amp_conf/htdocs/admin/modules/");
+@@ -691,13 +691,16 @@
+ // **** Look for user = root
+
+ outn("Checking user..");
+-//$current_user=(isset($_ENV["USER"]) ? $_ENV["USER"] : exec('whoami',$output));
+-$euid = (posix_getpwuid(posix_geteuid()));
+-$current_user = $euid['name'];
+-if ($current_user != "root"){
+- out("FAILED");
+- fatal($argv[0]." must be run as root");
++if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
++ //$current_user=(isset($_ENV["USER"]) ? $_ENV["USER"] : exec('whoami',$output));
++ $euid = (posix_getpwuid(posix_geteuid()));
++ $current_user = $euid['name'];
++ if ($current_user != "root"){
++ out("FAILED");
++ fatal($argv[0]." must be run as root");
++ }
+ }
++
+ out("OK");
+
+
+@@ -892,10 +895,12 @@
+
+ outn("Connecting to database..");
+
+-$db_user = $amp_conf["AMPDBUSER"];
+-$db_pass = $amp_conf["AMPDBPASS"];
+-$db_host = $amp_conf["AMPDBHOST"];
+ $db_engine = $amp_conf["AMPDBENGINE"];
++if ($db_engine != "sqlite3") {
++ $db_user = $amp_conf["AMPDBUSER"];
++ $db_pass = $amp_conf["AMPDBPASS"];
++ $db_host = $amp_conf["AMPDBHOST"];
++}
+ $db_name = $amp_conf["AMPDBNAME"];
+
+ // we still support older configurations, and fall back
+--- freepbx-2.4.0-orig//amp_conf/htdocs/admin/modules/recordings/install.php 2007-08-08 14:34:58.000000000 +0930
++++ freepbx-2.4.0//amp_conf/htdocs/admin/modules/recordings/install.php 2008-03-08 10:05:24.000000000 +1030
+@@ -22,7 +22,14 @@
+ unset($fcc);
+
+ // Make sure table exists
+-$sql = "CREATE TABLE IF NOT EXISTS recordings ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50) , filename BLOB, description VARCHAR(254));";
++
++if ($amp_conf["AMPDBENGINE"] == 'sqlite3') {
++ $sql = "CREATE TABLE IF NOT EXISTS recordings ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, displayname VARCHAR(50) , filename BLOB, description VARCHAR(254));";
++}
++else {
++ $sql = "CREATE TABLE IF NOT EXISTS recordings ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50) , filename BLOB, description VARCHAR(254));";
++}
++
+ $result = $db->query($sql);
+ if(DB::IsError($result)) {
+ die_freepbx($result->getDebugInfo());
+@@ -42,7 +49,13 @@
+ $sql = "SELECT * FROM recordings where displayname = '__invalid'";
+ $results = $db->getRow($sql, DB_FETCHMODE_ASSOC);
+ if (!isset($results['filename'])) {
+- sql("INSERT INTO recordings values ('', '__invalid', 'install done', '')");
++ if ($amp_conf["AMPDBENGINE"] == 'sqlite3') {
++ sql("INSERT INTO recordings values (NULL, '__invalid', 'install done', '')");
++ }
++ else
++ sql("INSERT INTO recordings values ('', '__invalid', 'install done', '')");
++ print("AFTE2\n");
++
+ $dh = opendir($recordings_directory);
+ while (false !== ($file = readdir($dh))) { // http://au3.php.net/readdir
+ if ($file[0] != "." && $file != "CVS" && $file != "svn" && !is_dir("$recordings_directory/$file")) {
+@@ -59,10 +72,14 @@
+
+ // Upgrade to recordings 3.0
+ // Change filename from VARCHAR(80) to BLOB
+-$sql = 'ALTER TABLE recordings CHANGE filename filename BLOB';
+-$result = $db->query($sql);
+-if(DB::IsError($result)) {
+- die_freepbx($result->getDebugInfo());
++// Note sqlite3 doesn't support ALTER
++
++if ($amp_conf["AMPDBENGINE"] != 'sqlite3') {
++ $sql = 'ALTER TABLE recordings CHANGE filename filename BLOB';
++ $result = $db->query($sql);
++ if(DB::IsError($result)) {
++ die_freepbx($result->getDebugInfo());
++ }
+ }
+
+ ?>
+--- freepbx-2.4.0-orig//amp_conf/bin/retrieve_conf 2007-12-15 08:18:39.000000000 +1030
++++ freepbx-2.4.0//amp_conf/bin/retrieve_conf 2008-03-08 10:05:28.000000000 +1030
+@@ -10,7 +10,7 @@
+
+ ini_set('error_reporting', E_ALL & ~E_NOTICE);
+
+-define("AMP_CONF", "/etc/amportal.conf");
++define("AMP_CONF", "/etc/amportal.conf");
+ $amportalconf = AMP_CONF;
+
+ //define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
+@@ -272,8 +272,6 @@
+ fatal(_("database connection failure"),("failed trying to connect to the configured database"));
+
+ }
+-out(_("OK"));
+-
+
+ //TODO : make this engine-neutral
+ outn(_("Connecting to Asterisk manager interface.."));
+@@ -284,7 +282,6 @@
+ out(_("FAILED"));
+ fatal(_("Asterisk Manager Connection Failure"),sprintf(_("Failed to connect to the Asterisk manager through port: %s"), $amp_conf['ASTMANAGERPORT']));
+ }
+-out(_("OK"));
+
+ //include common functions
+ require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
+@@ -293,7 +290,7 @@
+ // query for our modules
+ // var_dump( $db );
+ $modules = module_getinfo();
+-
++out(_("DR-BBB"));
+ //Putting the core module last, to move outbound-allroutes
+ // last in from-internals-additional
+ if (array_key_exists('core', $modules)) {
+@@ -671,8 +668,11 @@
+
+ // script to write op_server.cfg file from mysql
+ //
+-$script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.pl '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
+-exec($script);
++if ($amp_conf["AMPDBENGINE"] != 'sqlite3') {
++ // sqlite3 not supported just yet
++ $script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.pl '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
++ exec($script);
++}
+
+ // generate configuration files
+ //
+@@ -684,10 +684,7 @@
+ generate_configurations_iax($version);
+ generate_configurations_zap($version);
+ }
+-if (!isset($queues_conf) || !is_a($queues_conf, "queues_conf")) {
+- generate_configurations_queues($version);
+-}
+-
++
+ // Check and install the freepbx-cron-scheduler.php manager
+ //
+ install_cron_scheduler();
+--- freepbx-2.4.0-orig//amp_conf/astetc/manager.conf 2006-05-01 11:39:24.000000000 +0930
++++ freepbx-2.4.0//amp_conf/astetc/manager.conf 2008-03-08 10:05:24.000000000 +1030
+@@ -6,8 +6,8 @@
+ port = 5038
+ bindaddr = 0.0.0.0
+
+-[AMPMGRUSER]
+-secret = AMPMGRPASS
++[admin]
++secret = amp111
+ deny=0.0.0.0/0.0.0.0
+ permit=127.0.0.1/255.255.255.0
+ read = system,call,log,verbose,command,agent,user
+--- freepbx-2.4.0-orig//amp_conf/htdocs/admin/config.php 2007-12-02 18:06:31.000000000 +1030
++++ root/www/admin/config.php 2008-03-11 13:22:34.000000000 +1030
+@@ -39,7 +39,9 @@
+ /** AJAX handler for reload event
+ */
+ include_once('common/json.inc.php');
+- $response = do_reload();
++ // DR: include as global code
++ include_once('do_reload.php');
++ //$response = do_reload();
+ $json = new Services_JSON();
+ echo $json->encode($response);
+ break;
+++ /dev/null
-# Makefile
-# David Rowe 12 Feb 2008
-
-# Builds (almost) everything you need for FreePBX with sqlite3 from
-# scratch and configures FreePBX to run in a "sandbox" environment.
-
-TOPDIR = $(shell pwd)
-BUILD_DIR = $(TOPDIR)
-DL_DIR = $(TOPDIR)/dl
-ROOT = $(TOPDIR)/root
-export PATH:= $(ROOT)/bin:$(PATH)
-
-all: php sqlite pear-db php-sqlite3 xdebug lighttpd freepbx
-
-##############################################################
-# PHP --------------------------------------------------------
-##############################################################
-
-PHP_VERSION=5.2.5
-PHP_DIRNAME=php-$(PHP_VERSION)
-PHP_DIR=$(BUILD_DIR)/$(PHP_DIRNAME)
-PHP_SITE=http://www.php.net/distributions
-PHP_SOURCE=php-$(PHP_VERSION).tar.bz2
-PHP_CONFIGURE_OPTS=--disable-all --with-pcre-regex --enable-force-cgi-redirect \
- --with-config-file-path=$(ROOT)/etc --prefix=$(ROOT) \
- --with-pear --enable-xml --enable-libxml --enable-session \
- --with-gettext --enable-debug
-
-$(DL_DIR)/$(PHP_SOURCE):
- mkdir -p dl
- wget -P $(DL_DIR) $(PHP_SITE)/$(PHP_SOURCE)
-
-$(PHP_DIR)/.unpacked: $(DL_DIR)/$(PHP_SOURCE)
- bzcat $(DL_DIR)/$(PHP_SOURCE) | tar -C $(BUILD_DIR) -xf -
- touch $(PHP_DIR)/.unpacked
-
-$(PHP_DIR)/.configured: $(PHP_DIR)/.unpacked
- cd $(PHP_DIR); ./configure $(PHP_CONFIGURE_OPTS)
- touch $(PHP_DIR)/.configured
-
-$(PHP_DIR)/.built: $(PHP_DIR)/.configured
- cd $(PHP_DIR); make
- cd $(PHP_DIR); make install
- cp $(PHP_DIR)/php.ini-recommended $(ROOT)/etc/php.ini
- echo include_path=\".:$(ROOT)/lib/php\" >> $(ROOT)/etc/php.ini
- touch $(PHP_DIR)/.built
-
-php: $(PHP_DIR)/.built
-
-##############################################################
-# sqlite3 ----------------------------------------------------
-##############################################################
-
-SQLITE_VERSION=3.5.6
-SQLITE_DIRNAME=sqlite-$(SQLITE_VERSION)
-SQLITE_DIR=$(BUILD_DIR)/$(SQLITE_DIRNAME)
-SQLITE_SITE=http://www.sqlite.org/
-SQLITE_SOURCE=sqlite-amalgamation-$(SQLITE_VERSION).tar.gz
-SQLITE_CONFIGURE_OPTS = --prefix=$(ROOT)
-
-$(DL_DIR)/$(SQLITE_SOURCE):
- mkdir -p dl
- wget -P $(DL_DIR) $(SQLITE_SITE)/$(SQLITE_SOURCE)
-
-$(SQLITE_DIR)/.unpacked: $(DL_DIR)/$(SQLITE_SOURCE)
- zcat $(DL_DIR)/$(SQLITE_SOURCE) | tar -C $(BUILD_DIR) -xf -
- touch $(SQLITE_DIR)/.unpacked
-
-$(SQLITE_DIR)/.configured: $(SQLITE_DIR)/.unpacked
- cd $(SQLITE_DIR); ./configure $(SQLITE_CONFIGURE_OPTS)
- touch $(SQLITE_DIR)/.configured
-
-$(SQLITE_DIR)/.built: $(SQLITE_DIR)/.configured
- cd $(SQLITE_DIR); make
- cd $(SQLITE_DIR); make install
- touch $(SQLITE_DIR)/.built
-
-sqlite: $(SQLITE_DIR)/.built
-
-##############################################################
-# PEAR:DB ---------------------------------------------------
-##############################################################
-
-$(ROOT)/lib/php/.db-installed:
- pear install DB
- cd $(ROOT)/lib/php/DB; patch -p1 < $(TOPDIR)/patch/common.patch
- touch $(ROOT)/lib/php/.db-installed
-
-pear-db: $(ROOT)/lib/php/.db-installed
-
-##############################################################
-# php-sqlite3 ------------------------------------------------
-##############################################################
-
-PHP-SQLITE3_VERSION=0.5
-PHP-SQLITE3_DIRNAME=sqlite3-$(PHP-SQLITE3_VERSION)
-PHP-SQLITE3_DIR=$(BUILD_DIR)/$(PHP-SQLITE3_DIRNAME)
-PHP-SQLITE3_SITE=http://optusnet.dl.sourceforge.net/sourceforge/php-sqlite3/
-PHP-SQLITE3_SOURCE=sqlite3-$(PHP-SQLITE3_VERSION).tgz
-PHP-SQLITE3_CONFIGURE_OPTS=--prefix=$(ROOT) \
- --with-sqlite3=$(ROOT) \
- --with-php-config=$(ROOT)/bin/php-config
-
-$(DL_DIR)/$(PHP-SQLITE3_SOURCE):
- mkdir -p dl
- wget -P $(DL_DIR) $(PHP-SQLITE3_SITE)/$(PHP-SQLITE3_SOURCE)
-
-$(PHP-SQLITE3_DIR)/.unpacked: $(DL_DIR)/$(PHP-SQLITE3_SOURCE)
- zcat $(DL_DIR)/$(PHP-SQLITE3_SOURCE) | tar -C $(BUILD_DIR) -xf -
- touch $(PHP-SQLITE3_DIR)/.unpacked
-
-$(PHP-SQLITE3_DIR)/.configured: $(PHP-SQLITE3_DIR)/.unpacked
- cd $(PHP-SQLITE3_DIR); phpize; ./configure $(PHP-SQLITE3_CONFIGURE_OPTS)
- touch $(PHP-SQLITE3_DIR)/.configured
-
-$(PHP-SQLITE3_DIR)/.built: $(PHP-SQLITE3_DIR)/.configured
- cd $(PHP-SQLITE3_DIR); make
- cd $(PHP-SQLITE3_DIR); make install
-
- # use modified sqlite3.php for PHP 5. We use a sym link so that
- # we can edit it in place and capture changes to source control
-
- ln -sf $(TOPDIR)/files/sqlite3.php $(ROOT)/lib/php/DB/sqlite3.php
-
- # update php.ini extensions line for sqlite3.so
-
- cat $(ROOT)/etc/php.ini | sed '/extension_dir/ d' > $(ROOT)/etc/php.ini.tmp
- mv $(ROOT)/etc/php.ini.tmp $(ROOT)/etc/php.ini
- echo extension_dir=\"`find $(ROOT) -name sqlite3.so | xargs dirname`\" >> $(ROOT)/etc/php.ini
-
- touch $(PHP-SQLITE3_DIR)/.built
-
-php-sqlite3: $(PHP-SQLITE3_DIR)/.built
-
-##############################################################
-# xdebug -----------------------------------------------------
-##############################################################
-
-XDEBUG_VERSION=2.0.2
-XDEBUG_DIRNAME=xdebug-$(XDEBUG_VERSION)
-XDEBUG_DIR=$(BUILD_DIR)/$(XDEBUG_DIRNAME)
-XDEBUG_SITE=http://www.xdebug.org/files/
-XDEBUG_SOURCE=xdebug-$(XDEBUG_VERSION).tgz
-XDEBUG_CONFIGURE_OPTS=--prefix=$(ROOT) --enable-xdebug
-
-$(DL_DIR)/$(XDEBUG_SOURCE):
- mkdir -p dl
- wget -P $(DL_DIR) $(XDEBUG_SITE)/$(XDEBUG_SOURCE)
-
-$(XDEBUG_DIR)/.unpacked: $(DL_DIR)/$(XDEBUG_SOURCE)
- zcat $(DL_DIR)/$(XDEBUG_SOURCE) | tar -C $(BUILD_DIR) -xf -
- touch $(XDEBUG_DIR)/.unpacked
-
-$(XDEBUG_DIR)/.configured: $(XDEBUG_DIR)/.unpacked
- cd $(XDEBUG_DIR); phpize; ./configure $(XDEBUG_CONFIGURE_OPTS)
- touch $(XDEBUG_DIR)/.configured
-
-$(XDEBUG_DIR)/.built: $(XDEBUG_DIR)/.configured
- cd $(XDEBUG_DIR); make
- cp $(XDEBUG_DIR)/modules/xdebug.so $(ROOT)/lib
-
- # update php.ini extensions line for xdebug.so
-
- echo zend_extension=\"$(ROOT)/lib/xdebug.so\" >> $(ROOT)/etc/php.ini
- echo "xdebug.auto_trace=On" >> $(ROOT)/etc/php.ini
- echo "xdebug.show_exception_trace=On" >> $(ROOT)/etc/php.ini
-
- touch $(XDEBUG_DIR)/.built
-
-xdebug: $(XDEBUG_DIR)/.built
-
-#########################################################################
-# lighttpd --------------------------------------------------------------
-#########################################################################
-
-LIGHTTPD_VERSION=1.4.18
-LIGHTTPD_DIRNAME=lighttpd-$(LIGHTTPD_VERSION)
-LIGHTTPD_DIR=$(BUILD_DIR)/$(LIGHTTPD_DIRNAME)
-LIGHTTPD_SITE=http://www.lighttpd.net/download
-LIGHTTPD_SOURCE=lighttpd-$(LIGHTTPD_VERSION).tar.gz
-LIGHTTPD_CONFIGURE_OPTS=--prefix=$(ROOT) --disable-ipv6
-
-$(DL_DIR)/$(LIGHTTPD_SOURCE):
- mkdir -p dl
- wget -P $(DL_DIR) $(LIGHTTPD_SITE)/$(LIGHTTPD_SOURCE)
-
-$(LIGHTTPD_DIR)/.unpacked: $(DL_DIR)/$(LIGHTTPD_SOURCE)
- zcat $(DL_DIR)/$(LIGHTTPD_SOURCE) | tar -C $(BUILD_DIR) -xf -
- touch $(LIGHTTPD_DIR)/.unpacked
-
-$(LIGHTTPD_DIR)/.configured: $(LIGHTTPD_DIR)/.unpacked
- cd $(LIGHTTPD_DIR); ./configure $(LIGHTTPD_CONFIGURE_OPTS)
- touch $(LIGHTTPD_DIR)/.configured
-
-$(LIGHTTPD_DIR)/.built: $(LIGHTTPD_DIR)/.configured
- cd $(LIGHTTPD_DIR); make
- cd $(LIGHTTPD_DIR); make install
-
- cp files/lighttpd.conf $(ROOT)/etc
- mkdir -p $(ROOT)/www
- cp files/test.php $(ROOT)/www
-
- # change server root and set up cgi-assign for PHP
-
- cat $(ROOT)/etc/lighttpd.conf | sed '/server.document-root/ d' > $(ROOT)/etc/lighttpd.conf.tmp
- mv $(ROOT)/etc/lighttpd.conf.tmp $(ROOT)/etc/lighttpd.conf
- echo "server.document-root = \"$(ROOT)/www/\"" >> $(ROOT)/etc/lighttpd.conf
- echo "cgi.assign = (\".php\" => \"$(ROOT)/bin/php-cgi\")" >> $(ROOT)/etc/lighttpd.conf
-
- touch $(LIGHTTPD_DIR)/.built
-
-lighttpd: $(LIGHTTPD_DIR)/.built
-
-#########################################################################
-# freepbx ---------------------------------------------------------------
-#########################################################################
-
-FREEPBX_VERSION=2.4.0
-FREEPBX_DIRNAME=freepbx-$(FREEPBX_VERSION)
-FREEPBX_DIR=$(BUILD_DIR)/$(FREEPBX_DIRNAME)
-FREEPBX_SITE= http://mirror.freepbx.org
-FREEPBX_SOURCE=freepbx-$(FREEPBX_VERSION).tar.gz
-FREEPBX_CONFIGURE_OPTS=
-
-# sed command to change hard coded PHP /etc/amportal.conf path
-
-FREEPBX_AMP_CONF='s|"/etc/amportal.conf"|"$(ROOT)/etc/amportal.conf"|'
-
-$(DL_DIR)/$(FREEPBX_SOURCE):
- mkdir -p dl
- wget -P $(DL_DIR) $(FREEPBX_SITE)/$(FREEPBX_SOURCE)
-
-$(FREEPBX_DIR)/.unpacked: $(DL_DIR)/$(FREEPBX_SOURCE)
- zcat $(DL_DIR)/$(FREEPBX_SOURCE) | tar -C $(BUILD_DIR) -xf -
- patch -d $(FREEPBX_DIR) -p1 < patch/freepbx.patch
-
- # additional files to implement retrieve_conf as include
-
- cp files/retrieve_conf.inc.php files/do_reload.php \
- $(FREEPBX_DIR)/amp_conf/htdocs/admin
-
- touch $(FREEPBX_DIR)/.unpacked
-
-$(FREEPBX_DIR)/.installed: $(FREEPBX_DIR)/.unpacked
-
- # initialise databases (freepbx and CDR)
-
- mkdir -p $(ROOT)/var
- cat $(FREEPBX_DIR)/SQL/newinstall.sqlite3.sql | sqlite3 $(ROOT)/var/freepbx.db
- touch $(ROOT)/var/asteriskcdr.db
-
- # edit amportal.conf
-
- # out with the old......
-
- cat $(FREEPBX_DIR)/amportal.conf | \
- sed -e '/AMPDBENGINE=/ d' -e '/AMPDBFILE=/ d' \
- -e '/AMPWEBROOT=/ d' -e '/FOPWEBROOT=/ d' \
- -e '/AMPDBHOST=/ d' -e '/AMPDBUSER=/ d' -e '/AMPDBPASS=/ d' \
- > $(FREEPBX_DIR)/amportal.conf.tmp
-
- mv $(FREEPBX_DIR)/amportal.conf.tmp $(FREEPBX_DIR)/amportal.conf
-
- # in with the new........
-
- echo "AMPDBENGINE=sqlite3" >> $(FREEPBX_DIR)/amportal.conf
- echo "AMPDBFILE=$(ROOT)/var/freepbx.db" >> $(FREEPBX_DIR)/amportal.conf
- echo "AMPWEBROOT=$(ROOT)/www" >> $(FREEPBX_DIR)/amportal.conf
- echo "FOPWEBROOT=$(ROOT)/www/panel" >> $(FREEPBX_DIR)/amportal.conf
-
- sed -i "s|/var/www/html|$(ROOT)/www|" $(FREEPBX_DIR)/amportal.conf
-
- # Wholesale hacking of FreePBX source to move AMP_CONF to our local conf dir:
- # FYI to find where AMP_CONF is used:
- # grep -r "define(\"AMP_CONF\", \"/etc/amportal.conf\")" *
-
- cd $(FREEPBX_DIR); \
- FILES=`grep -r "\"/etc/amportal.conf\"" * | sed 's/:.*//'`; \
- for f in $$FILES; do \
- sed -i $(FREEPBX_AMP_CONF) $$f; \
- done
-
- # change recordings/includes/main.conf.php DBENGINE and DBFILE settings which
- # are hard coded for mysql
-
- sed -i "s|ASTERISKCDR_DBENGINE.*|ASTERISKCDR_DBENGINE=\"sqlite3\";|" \
- $(FREEPBX_DIR)/amp_conf/htdocs/recordings/includes/main.conf.php
- sed -i "s|ASTERISKCDR_DBFILE.*|ASTERISKCDR_DBFILE=\"$(ROOT)/var/asteriskcdr.db\";|" \
- $(FREEPBX_DIR)/amp_conf/htdocs/recordings/includes/main.conf.php
-
- # change admin/cdr/lib/defines DB_TYPE and DBNAME settings
-
- sed -i "s|\"DBNAME\".*|\"DBNAME\",\"$(ROOT)/var/asteriskcdr.db\");|" \
- $(FREEPBX_DIR)/amp_conf/htdocs/admin/cdr/lib/defines.php
- sed -i "s|\"DB_TYPE\".*|\"DB_TYPE\",\"sqlite3\");|" \
- $(FREEPBX_DIR)/amp_conf/htdocs/admin/cdr/lib/defines.php
-
- # switch off mp3 support as I dont have asterisk-addons and Asterisk keeps
- # crashing when I start it
-
- sed -i "s|load => format_mp3.so|;load => format_mp3.so|" \
- $(FREEPBX_DIR)/amp_conf/astetc/modules.conf
-
- # cp amportal.conf ourselves to bypass a lot of questions in install script
-
- cp $(FREEPBX_DIR)/amportal.conf $(ROOT)/etc
-
- # run installer
-
- sudo mkdir -p $(ROOT)/var/run/asterisk; sudo chmod 777 $(ROOT)/var/run/asterisk;
- sudo mkdir -p $(ROOT)/var/lib/asterisk/bin; sudo chmod 777 $(ROOT)/var/lib/asterisk/bin;
- cd $(FREEPBX_DIR); sudo ./install_amp; sudo chmod 777 $(ROOT)/www -R
-
- #touch $(FREEPBX_DIR).installed
-
-
-freepbx: $(FREEPBX_DIR)/.installed
-
-#########################################################################
-# clean ----------------------------------------------------------------
-#########################################################################
-
-clean:
- rm -Rf $(PHP_DIR) $(SQLITE_DIR) $(PHP-SQLITE3_DIR) \
- $(XDEBUG_DIR) $(LIGHTTPD_DIR) $(FREEPBX_DIR) root \
- $(FREEPBX_DIR)-orig
-
- find . -name '*~' | xargs rm -f
- rm -f *.xml # where do these come from?
-
-#########################################################################
-# freepbx-make-patch ---------------------------------------------------
-#########################################################################
-
-# Generate patches between original tar ball $(AO) and either the
-# installed files $(AROOT), or modified tar ball $A.
-# Run this Makefile target to capture any changes to patches
-
-AO = $(FREEPBX_DIRNAME)-orig/
-AROOT = root/www
-A = $(FREEPBX_DIRNAME)/
-
-freepbx-make-patch:
-
- # untar original, to save time we check if the orig is already there
-
- if [ ! -d $(FREEPBX_DIR)-orig ] ; then \
- cd $(DL_DIR); tar xvf $(FREEPBX_SOURCE); \
- mv $(FREEPBX_DIRNAME) $(FREEPBX_DIR)-orig; \
- fi
-
- # make big-ass SQL statement work with sqlite3
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/admin/modules/core/functions.inc.php \
- $(AROOT)/admin/modules/core/functions.inc.php \
- > patch/freepbx.patch
-
- # add $options array to help numRows() support in sqlite3
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/admin/common/db_connect.php \
- $(AROOT)/admin/common/db_connect.php \
- >> patch/freepbx.patch
-
- # sqlite3 support for cdr in recordings
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/recordings/includes/database.php \
- $(AROOT)/recordings/includes/database.php \
- >> patch/freepbx.patch
-
- # sqlite3 support for cdr
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/admin/cdr/lib/defines.php \
- $(AROOT)/admin/cdr/lib/defines.php \
- >> patch/freepbx.patch
-
- # trap missing cdr table error in Reports menu
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/admin/cdr/lib/Class.Table.php \
- $(AROOT)/admin/cdr/lib/Class.Table.php \
- >> patch/freepbx.patch
-
- # typo in newinstall.sqlite3.sql
-
- -diff -uN \
- $(AO)/SQL/newinstall.sqlite3.sql \
- $(A)/SQL/newinstall.sqlite3.sql \
- >> patch/freepbx.patch
-
- # stop installer warning/errors when sqlite3 and blackfin used
-
- -diff -uN \
- $(AO)/install_amp \
- $(A)/install_amp \
- >> patch/freepbx.patch
-
- # use sqlite3 SQL syntax for recording installer
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/admin/modules/recordings/install.php \
- $(A)/amp_conf/htdocs/admin/modules/recordings/install.php \
- >> patch/freepbx.patch
-
- # 1/ stop perl script for flash panel being called, as
- # this won't work on Blackfin (might work on x86 with
- # appropriate Perl lib but not tested)
- #
- # 2/ Remove code to set up queues, as it seems to be killing retrive_conf
- # Is this needed or a legacy thing?
-
- -diff -uN \
- $(AO)/amp_conf/bin/retrieve_conf \
- $(A)/amp_conf/bin/retrieve_conf \
- >> patch/freepbx.patch
-
- # set up default AMP user and password
-
- -diff -uN \
- $(AO)/amp_conf/astetc/manager.conf \
- $(A)/amp_conf/astetc/manager.conf \
- >> patch/freepbx.patch
-
- # make retrieve_conf an include from config.php rather
- # than exec to save about 15M
-
- -diff -uN \
- $(AO)/amp_conf/htdocs/admin/config.php \
- $(AROOT)/admin/config.php \
- >> patch/freepbx.patch
-
- # NOTE: common.patch was generated manually from command line
-
- # undo sandbox path (messy! Must be a better way....)
-
- sed -i 's|$(ROOT)||' patch/freepbx.patch
-
-
-
+++ /dev/null
-README for freepbx-sandbox
-David Rowe Feb 2008
-
-Introduction
-------------
-
-This directory contains a "sandbox" type development environment for
-FreePBX using sqlite3. It was used to develop patches against FreePBX
-2.4.0 to progress sqlite3 support.
-
-The Makefile builds (almost) everything you need for FreePBX (web
-server, php etc) from scratch and runs it in a "sandbox" environment.
-The notable exception is that it doesn't build Asterisk (yet).
-
-FreePBX is configured to use lighttpd (easier than building Apache)
-and and sqlite3.
-
-Most of the files for are confined to this directory, i.e. you mostly
-(except for Asterisk) don't need to mess with your PC's configuration.
-Used to model and test configuration for Blackfin port, but may be
-useful for general FreePBX development.
-
-FreePBX Sqlite3 Status
-----------------------
-
-Most of the screens (Admin/Reports/Recording) present OK but have not
-been extensively tested. The Flash Panel isn't working/hasn't been
-tested. Reports/Recording is awaiting sqlite3 CDR support (e.g. in
-Asterisk 1.6) for further testing. The amp_conf installer works OK.
-
-I have run some basic tests such as adding an extension/route/trunk
-and made a few calls OK.
-
-This FreePBX/Sqlite3 development has been performed on a laptop
-running Ubuntu (no zaptel hardware) with Asterisk 1.4 and FreePBX
-2.4.0.
-
-Motivation
-----------
-
-1/ When I first tried to manually install FreePBX I had a lot of
-problems installing all the apps I needed, especially as I was new to
-PHP/SQL/FreePBX. So I thought about automating the installation (from
-source).
-
-2/ It may allow multiple installations of FreePBX, or for example lets
-you use a different PHP version to currently installed on your system.
-Asterisk would also need to be sandboxed for this to work.
-
-3/ It doesn't mess with your root filesystem.
-
-4/ Let me collect all the code I needed in one dir tree, making source
-control easier.
-
-5/ Stepping stone for a Blackfin port.
-
-Building and Running FreePBX-sqlite3 Sandbox
---------------------------------------------
-
-Building:
-
-1/ Install Asterisk 1.4.x and start Asterisk.
-
-2/ Build freepbx-sandbox:
-
-[your home]$ svn co \
- https://freetel.svn.sourceforge.net/svnroot/freetel/freepbx-sandbox \
- freepbx-sandbox
-[your home]$ cd freepbx
-[freepbx-sandbox]$ make
-
-3/ You will eventually get prompted for your root passwd - this is
- required for several stages of the installation.
-
-Running:
-
-1/ Start the web server:
- [freepbx-sandbox]$ sudo ./root/sbin/lighttpd -D -f root/etc/lighttpd.conf
-2/ If not already running start Asterisk:
- [freepbx-sandbox]$ sudo asterisk
-3/ Point your browser at locahost
-
-Manual Installation of FreePBX with sqlite3
--------------------------------------------
-
-Here is a rough guide for a regular (non-sandbox) installation of
-FreePBX with sqlite3.
-
-The Makefile automates FreePBX/sqlite3 installation in a sandbox
-environment, use it as a reference for manual installation as I may
-have missed a step in the steps below. See also sqlite.readme in the
-FreePBX tar ball.
-
-1/ Install and test a web server with PHP 5.
-
-2/ Install PHP PEAR. Patch DB/common.php with files/common.patch to
- enable numRows() to work.
-
-3/ Install sqlite3 (shared libs and application).
-
-4/ Install sqlite3-0.5 (PEAR/DB support for sqlite3)
- + cp files/sqlite3.php /your/php/path/DB/sqlite3.php. This is an updated
- version of the sqlite3.php file that comes with sqlite3-0.5
- + make sure you install sqlite.so and update php.ini so it can find it.
- + optional: see Test 2 in the next section
-
-5/ tar xvzf freepbx-2.4.0.tar.gz
-
-6/ Edit amportal.conf for sqlite (see sqlite.readme), manually cp to
- /etc (that way installer ask less questions).
-
-7/ Create sqlite database (see sqlite.readme). Create a dummy cdr
- database file using 'touch /var/asteriskcdr.db' (this last step
- prevents reports/recording screens choking in the absence of
- Asterisk sqlite3 CDR records).
-
-8/ Apply patch/freepbx.patch to freepbx-2.4.0 directory.
-
-9/ Manually edit recordings/includes/main.conf.php:
- ASTERISKCDR_DBENGINE="sqlite3"
- ASTERISKCDR_DBFILE="/var/asteriskcdr.db"
-
- Manually edit: admin/cdr/lib/defines.php:
- DB_TYPE="sqlite3"
- DB_NAME="/var/asteriskcdr.db"
-
-10/ Run freepbx installer
-
-Tests
------
-
-1/ basic PHP support: run file/test.php on your webserver
-
-2/ PEAR/DB with sqlite3: run files/testdb.php on your webserver
- (after freepbx.db has been created by step 9)
-
-Notes
------
-
-1/ The Recordings screen needs a sqlite3 CDR backend for Asterisk.
-This is available in Asterisk 1.6. This hasn't been tested yet.
-
-2/ The Makefile automates FreePBX/sqlite3 installation in a sandbox
-environment, use it as a reference for manual installation. See
-Makefile for more information.
-
-3/ Changes to FreePBX are in the patch directory. An updated
-sqlite3.php DB/PEAR backend is also required (files dir).
-
-4/ If port 80 is not available kill your existing web server.
-
-5/ Xdebug generates trace files in your /tmp directory. Useful to
-determine what went wrong. Also keep an eye on the lighttpd log.
-
-6/ I used a laptop running Ubuntu and Asterisk 1.4.4 for these tests -
-Asterisk had no analog hardware installed so I didn't install Zaptel.
-Asterisk was compiled in another directory in the usual way:
-./configure && make && sudo make install.
-
-7/ In files/testdb.php is a simple test script for exercising sqlite3
-PEAR/DB support - useful for debugging any sqlite3 problems you might
-encounter.
-
-Suggested FreePBX Changes
--------------------------
-
-1/ Consider patch/freepbx.patch (for FreePBX) & patch/common.patch
- (for PEAR/DB). Patches are explained at the end of Makefile
- (freepbx-make-patch target).
-
- Please note that some of the patches contain some hard-coded
- information (e.g. changed paths), for example:
-
- admin/cdr/lib/defines.php (DBNAME & DBTYPE lines)
- install_amp (AMP_CONF)
- retrieve_conf (AMP_CONF)
-
- This is a consequence of the sandbox method I am using, and in some
- cases current FreePBX sqlite3 support (e.g. the Asterisk CDR
- database is hard coded in several places rather than being set in
- amportal.conf). If checking into FreePBX source control this part
- of the patch should not be applied. I will try and work out a
- better way to generate patches in future.
-
-2/ It might be better to store the CDR database parameters in
- amportal.conf rather than hard coding them in
- recordings/includes/main.conf.php ($ASTERISKCDR_DBFILE,
- $ASTERISKCDR_DBNAME) & admin/cdr/lib/defines.php (DBNAME, DB_TYPE).
-
-3/ Include sqlite3.php in FreePBX to support sqlite3 in PEAR/DB for
- PHP 5.
-
-4/ newinstall.sqlite3.sql has a typo on line 327:
-
- modules_xml -> module_xml
-
- This correction is included in patch/freepbx.patch
-
-TODO
-----
-
-1/ Try to get Asterisk 1.6 CDR working with sqlite3, so we can further
- develop the Reports/recordings menus.
-
-2/ Bunch of warnings from the web server I haven't worked out yet:
-
- a) when saving a new extension:
-
- <snip>
- 2008-03-02 08:14:41: (mod_cgi.c.1231) cgi died ?
-
- b) lots of this sort of thing:
-
- <snip>
- PHP Notice: Undefined offset: 2 in
- /home/david/freepbx-sandbox/root/www/admin/modules/core/functions.inc.php
- on line 2946
+++ /dev/null
-<?php
-
-// do_reload.php
-// David Rowe March 11 2008
-// non-function version that executes in same php-cgi as config.php to
-// save run-time memory
-
-//Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
-//
-//This program is free software; you can redistribute it and/or
-//modify it under the terms of the GNU General Public License
-//as published by the Free Software Foundation; either version 2
-//of the License, or (at your option) any later version.
-//
-//This program is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-//GNU General Public License for more details.
-
-# this file runs inside special window that makes it hard to log
-# messages using regular HTML. So we use a log file instead.
-
-function reload_dbg($msg) {
- $myFile = "/tmp/log.txt";
- $fh = fopen($myFile, 'a') or die("can't open file");
- fwrite($fh, $msg);
- fclose($fh);
-}
-
-# This is more or less the code copied from do_reload() in
-# admin/functions.inc.php
-
- $notify =& notifications::create($db);
-
- $return = array('num_errors'=>0,'test'=>'abc');
- $exit_val = null;
-
- if (isset($amp_conf["PRE_RELOAD"]) && !empty($amp_conf['PRE_RELOAD'])) {
- exec( $amp_conf["PRE_RELOAD"], $output, $exit_val );
-
- if ($exit_val != 0) {
- $desc = sprintf(_("Exit code was %s and output was: %s"), $exit_val, "\n\n".implode("\n",$output));
- $notify->add_error('freepbx','reload_pre_script', sprintf(_('Could not run %s script.'), $amp_conf['PRE_RELOAD']), $desc);
-
- $return['num_errors']++;
- } else {
- $notify->delete('freepbx', 'reload_pre_script');
- }
- }
-
- // use include file in current php-cgi, avoid repeating a lot
- // of the code
-
- require_once('retrieve_conf.inc.php');
- $return['retrieve_conf'] = $rc_output;
-
- // retrive_conf html output
- if ($exit_val != 0) {
- $return['status'] = false;
- $return['message'] = sprintf(_('Reload failed because retrieve_conf encountered an error: %s'),$exit_val);
- $return['num_errors']++;
- $notify->add_critical('freepbx','RCONFFAIL', _("retrieve_conf failed, config not applied"), $return['message']);
- return $return;
- }
-
- if (!isset($astman) || !$astman) {
- $return['status'] = false;
- $return['message'] = _('Reload failed because FreePBX could not connect to the asterisk manager interface.');
- $return['num_errors']++;
- $notify->add_critical('freepbx','RCONFFAIL', _("retrieve_conf failed, config not applied"), $return['message']);
- return $return;
- }
- $notify->delete('freepbx', 'RCONFFAIL');
-
- //reload MOH to get around 'reload' not actually doing that.
- $astman->send_request('Command', array('Command'=>'moh reload'));
-
- //reload asterisk
- $astman->send_request('Command', array('Command'=>'reload'));
-
- $return['status'] = true;
- $return['message'] = _('Successfully reloaded');
-
- if ($amp_conf['FOPRUN']) {
- //bounce op_server.pl
- $wOpBounce = $amp_conf['AMPBIN'].'/bounce_op.sh';
- exec($wOpBounce.' &>'.$asterisk_conf['astlogdir'].'/freepbx-bounce_op.log', $output, $exit_val);
-
- if ($exit_val != 0) {
- $desc = _('Could not reload the FOP operator panel server using the bounce_op.sh script. Configuration changes may not be reflected in the panel display.');
- $notify->add_error('freepbx','reload_fop', _('Could not reload FOP server'), $desc);
-
- $return['num_errors']++;
- } else {
- $notify->delete('freepbx','reload_fop');
- }
- }
-
- //store asterisk reloaded status
- $sql = "UPDATE admin SET value = 'false' WHERE variable = 'need_reload'";
- $result = $db->query($sql);
- if(DB::IsError($result)) {
- $return['message'] = _('Successful reload, but could not clear reload flag due to a database error: ').$db->getMessage();
- $return['num_errors']++;
- }
-
- if (isset($amp_conf["POST_RELOAD"]) && !empty($amp_conf['POST_RELOAD'])) {
- exec( $amp_conf["POST_RELOAD"], $output, $exit_val );
-
- if ($exit_val != 0) {
- $desc = sprintf(_("Exit code was %s and output was: %s"), $exit_val, "\n\n".implode("\n",$output));
- $notify->add_error('freepbx','reload_post_script', sprintf(_('Could not run %s script.'), 'POST_RELOAD'), $desc);
-
- $return['num_errors']++;
- } else {
- $notify->delete('freepbx', 'reload_post_script');
- }
- }
- $response = $return;
-
-?>
+++ /dev/null
-# lighttpd configuration file
-#
-# use a it as base for lighttpd 1.0.0 and above
-#
-# $Id: lighttpd.conf,v 1.6 2004/08/29 09:44:53 weigon Exp $
-
-############ Options you really have to take care of ####################
-
-## modules to load
-# at least mod_access and mod_accesslog should be loaded
-# all other module should only be loaded if really neccesary
-# - saves some time
-# - saves memory
-server.modules = (
-# "mod_rewrite",
-# "mod_redirect",
- "mod_access",
-# "mod_auth",
-# "mod_status",
-# "mod_fastcgi",
-# "mod_simple_vhost",
-# "mod_evhost",
- "mod_cgi",
-# "mod_compress",
-# "mod_ssi",
-# "mod_usertrack",
-# "mod_rrdtool",
-# "mod_accesslog"
-)
-
-## a static document-root, for virtual-hosting take look at the
-## server.virtual-* options
-server.document-root = "/var/www/html"
-
-## where to send error-messages to
-# server.errorlog = ""
-
-# files to check for if .../ is requested
-server.indexfiles = ( "index.php", "index.html",
- "index.htm", "default.htm" )
-
-# mimetype mapping
-mimetype.assign = (
- ".pdf" => "application/pdf",
- ".sig" => "application/pgp-signature",
- ".spl" => "application/futuresplash",
- ".class" => "application/octet-stream",
- ".ps" => "application/postscript",
- ".torrent" => "application/x-bittorrent",
- ".dvi" => "application/x-dvi",
- ".gz" => "application/x-gzip",
- ".pac" => "application/x-ns-proxy-autoconfig",
- ".swf" => "application/x-shockwave-flash",
- ".tar.gz" => "application/x-tgz",
- ".tgz" => "application/x-tgz",
- ".tar" => "application/x-tar",
- ".zip" => "application/zip",
- ".mp3" => "audio/mpeg",
- ".m3u" => "audio/x-mpegurl",
- ".wma" => "audio/x-ms-wma",
- ".wax" => "audio/x-ms-wax",
- ".ogg" => "audio/x-wav",
- ".wav" => "audio/x-wav",
- ".gif" => "image/gif",
- ".jpg" => "image/jpeg",
- ".jpeg" => "image/jpeg",
- ".png" => "image/png",
- ".xbm" => "image/x-xbitmap",
- ".xpm" => "image/x-xpixmap",
- ".xwd" => "image/x-xwindowdump",
- ".css" => "text/css",
- ".html" => "text/html",
- ".htm" => "text/html",
- ".js" => "text/javascript",
- ".asc" => "text/plain",
- ".c" => "text/plain",
- ".conf" => "text/plain",
- ".text" => "text/plain",
- ".txt" => "text/plain",
- ".dtd" => "text/xml",
- ".xml" => "text/xml",
- ".mpeg" => "video/mpeg",
- ".mpg" => "video/mpeg",
- ".mov" => "video/quicktime",
- ".qt" => "video/quicktime",
- ".avi" => "video/x-msvideo",
- ".asf" => "video/x-ms-asf",
- ".asx" => "video/x-ms-asf",
- ".wmv" => "video/x-ms-wmv"
- )
-
-# Use the "Content-Type" extended attribute to obtain mime type if possible
-# mimetypes.use-xattr = "enable"
-
-#### accesslog module
-# accesslog.filename = "/www/logs/access.log"
-
-## deny access the file-extensions
-#
-# ~ is for backupfiles from vi, emacs, joe, ...
-# .inc is often used for code includes which should in general not be part
-# of the document-root
-url.access-deny = ( "~", ".inc" )
-
-
-
-######### Options that are good to be but not neccesary to be changed #######
-
-## bind to port (default: 80)
-#server.port = 81
-
-## bind to localhost (default: all interfaces)
-#server.bind = "grisu.home.kneschke.de"
-
-## error-handler for status 404
-#server.error-handler-404 = "/error-handler.html"
-#server.error-handler-404 = "/error-handler.php"
-
-
-###### virtual hosts
-##
-## If you want name-based virtual hosting add the next three settings and load
-## mod_simple_vhost
-##
-## document-root =
-## virtual-server-root + virtual-server-default-host + virtual-server-docroot or
-## virtual-server-root + http-host + virtual-server-docroot
-##
-#simple-vhost.server-root = "/home/weigon/wwwroot/servers/"
-#simple-vhost.default-host = "grisu.home.kneschke.de"
-#simple-vhost.document-root = "/pages/"
-
-
-##
-## Format: <errorfile-prefix><status>.html
-## -> ..../status-404.html for 'File not found'
-#server.errorfile-prefix = "/home/weigon/projects/lighttpd/doc/status-"
-
-## virtual directory listings
-#server.dir-listing = "enable"
-
-## send unhandled HTTP-header headers to error-log
-#debug.dump-unknown-headers = "enable"
-
-### only root can use these options
-#
-# chroot() to directory (default: no chroot() )
-#server.chroot = "/"
-
-## change uid to <uid> (default: don't care)
-#server.username = "wwwrun"
-
-## change uid to <uid> (default: don't care)
-#server.groupname = "wwwrun"
-
-#### compress module
-#compress.cache-dir = "/tmp/lighttpd/cache/compress/"
-#compress.filetype = ("text/plain", "text/html")
-
-#### fastcgi module
-## read fastcgi.txt for more info
-#fastcgi.server = ( ".php" =>
-# ( "grisu" =>
-# (
-# "host" => "192.168.2.10",
-# "port" => 1026
-# )
-# )
-# )
-
-#### CGI module
-#cgi.assign = ( ".pl" => "/usr/bin/perl",
-# ".cgi" => "/usr/bin/perl" )
-#
-
-#### SSL engine
-#ssl.engine = "enable"
-#ssl.pemfile = "server.pem"
-
-#### status module
-# status.status-url = "/server-status"
-# status.config-url = "/server-config"
-
-#### auth module
-## read authentification.txt for more info
-# auth.backend = "plain"
-# auth.backend.plain.userfile = "lighttpd.user"
-# auth.backend.plain.groupfile = "lighttpd.group"
-
-# auth.backend.ldap.hostname = "localhost"
-# auth.backend.ldap.base-dn = "dc=my-domain,dc=com"
-# auth.backend.ldap.filter = "(uid=$)"
-
-# auth.require = ( "/server-status" =>
-# (
-# "method" => "digest",
-# "realm" => "download archiv",
-# "require" => "group=www|user=jan|host=192.168.2.10"
-# ),
-# "/server-info" =>
-# (
-# "method" => "digest",
-# "realm" => "download archiv",
-# "require" => "group=www|user=jan|host=192.168.2.10"
-# )
-# )
-
-#### url handling modules (rewrite, redirect, access)
-# url.rewrite = ( "^/$" => "/server-status" )
-# url.redirect = ( "^/wishlist/(.+)" => "http://www.123.org/$1" )
-
-#
-# define a pattern for the host url finding
-# %% => % sign
-# %0 => domain name + tld
-# %1 => tld
-# %2 => domain name without tld
-# %3 => subdomain 1 name
-# %4 => subdomain 2 name
-#
-# evhost.path-pattern = "/home/storage/dev/www/%3/htdocs/"
-
-#### expire module
-# expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")
-
-#### ssi
-# ssi.extension = ( ".shtml" )
-
-#### rrdtool
-# rrdtool.binary = "/usr/bin/rrdtool"
-# rrdtool.db-name = "/var/www/lighttpd.rrd"
+++ /dev/null
-<?php
-
-/* fairly similar to retrieve_conf, have just commented out a bunch of
- code we don't need when used as an include file from do_update.php
- rather than a stand alone exec. */
-
-if (! function_exists("_")) {
- function _($str) {
- return $str;
- }
-}
-
-ini_set('error_reporting', E_ALL & ~E_NOTICE);
-
-define("AMP_CONF", "/home/david/freepbx-sandbox/root/etc/amportal.conf");
-$amportalconf = AMP_CONF;
-
-//define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
-define("WARNING_BANNER", "; "._("do not edit this file, this is an auto-generated file by freepbx\n")."; "._("all modifications must be done from the web gui")."\n\n\n");
-
-// Emulate gettext extension functions if gettext is not available
-if (!function_exists('_')) {
- function _($str) {
- return $str;
- }
-}
-
-function out($text) {
- global $rc_output;
- $rc_output = $rc_output . $text. "\n";
-}
-
-function outn($text) {
- global $rc_output;
- $rc_output = $rc_output . $text;
-}
-
-function error($text) {
- global $rc_output;
- $rc_output = $rc_output . "[ERROR] ".$text."\n";
-}
-
-function fatal($text, $extended_text="", $type="FATAL") {
- global $db;
-
- echo "[$type] ".$text." ".$extended_text."\n";
-
- if(!DB::isError($db)) {
- $nt = notifications::create($db);
- $nt->add_critical('retrieve_conf', $type, $text, $extended_text);
- }
-
- exit(1);
-}
-
-function debug($text) {
- global $debug;
-
- if ($debug) echo "[DEBUG-preDB] ".$text."\n";
-}
-
-function showHelp() {
- out(_("Optional parameters:"));
- out(_(" --help, -h, -? Show this help"));
- out(_(" --debug Enable debug output"));
- out(_(" --dry-run Don't actually do anything"));
-}
-
-
-// bootstrap retrieve_conf by getting the AMPWEBROOT since that is currently where the necessary
-// functions.inc.php resides, and then use that parser to properly parse the file and get all
-// the defaults as needed.
-//
-function parse_amportal_conf_bootstrap($filename) {
- $file = file($filename);
- foreach ($file as $line) {
- if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\*\%-]*)\"?\s*([;#].*)?/",$line,$matches)) {
- $conf[ $matches[1] ] = $matches[2];
- }
- }
- if ( !isset($conf["AMPWEBROOT"]) || ($conf["AMPWEBROOT"] == "")) {
- $conf["AMPWEBROOT"] = "/var/www/html";
- } else {
- $conf["AMPWEBROOT"] = rtrim($conf["AMPWEBROOT"],'/');
- }
-
- return $conf;
-}
-
-/** Adds a trailing slash to a directory, if it doesn't already have one
- */
-function addslash($dir) {
- return (($dir[ strlen($dir)-1 ] == '/') ? $dir : $dir.'/');
-}
-
-
-/********************************************************************************************************************/
-/* DR
-// **** Make sure we have STDIN etc
-
-// from ben-php dot net at efros dot com at php.net/install.unix.commandline
-if (version_compare(phpversion(),'4.3.0','<') || !defined("STDIN")) {
- define('STDIN',fopen("php://stdin","r"));
- define('STDOUT',fopen("php://stdout","r"));
- define('STDERR',fopen("php://stderr","r"));
- register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;' ) );
-}
-
-// **** Make sure we have PEAR's DB.php, and include it
-
-outn(_("Checking for PEAR DB.."));
-if (! @ include('DB.php')) {
- out(_("FAILED"));
- fatal(_("PEAR Missing"),sprintf(_("PEAR must be installed (requires DB.php). Include path: %s "), ini_get("include_path")));
-}
-out(_("OK"));
-
-
-// **** Make sure we have PEAR's GetOpts.php, and include it
-
-outn(_("Checking for PEAR Console::Getopt.."));
-if (! @ include("Console/Getopt.php")) {
- out(_("FAILED"));
- fatal(_("PEAR Getopt.php Missing"),sprintf(_("PEAR must be installed (requires Console/Getopt.php). Include path: %s"), ini_get("include_path")));
-}
-out(_("OK"));
-
-
-// **** Parse out command-line options
-
-$shortopts = "h?u:p:";
-$longopts = array("help","debug","dry-run","run-install","amportalconf=");
-
-$args = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), $shortopts, $longopts);
-if (is_object($args)) {
- // assume it's PEAR_ERROR
- out($args->message);
- exit(255);
-}
-*/
-$debug = false;
-$dryrun = false;
-$run_install = false;
-
-/*
-foreach ($args[0] as $arg) {
- switch ($arg[0]) {
- case "--help": case "h": case "?":
- showHelp();
- exit(10);
- break;
- case "--dry-run":
- out(_("Dry-run only, no files will be written"));
- $dryrun = true;
- break;
- case "--debug":
- $debug = true;
- debug(_("Debug mode enabled"));
- break;
- case "--run-install":
- $run_install = true;
- out(_("Running module install.php and install.sql scripts"));
- break;
- case "--amportalconf":
- $amportalconf = $arg[1];
- out(sprintf(_("Using %s configuration file"), $amportalconf));
- break;
- }
-}
-
-// **** Check for amportal.conf
-
-outn(sprintf(_("Checking for %s "), $amportalconf)._(".."));
-if (!file_exists($amportalconf)) {
- fatal(_("amportal.conf access problem: "),sprintf(_("The %s file does not exist, or is inaccessible"), $amportalconf));
-}
-out(_("OK"));
-
-// **** read amportal.conf
-
-outn(sprintf(_("Bootstrapping %s .."), $amportalconf));
-$amp_conf = parse_amportal_conf_bootstrap($amportalconf);
-if (count($amp_conf) == 0) {
- fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf));
-}
-out(_("OK"));
-
-outn(sprintf(_("Parsing %s .."), $amportalconf));
-require_once($amp_conf['AMPWEBROOT']."/admin/functions.inc.php");
-$amp_conf = parse_amportal_conf($amportalconf);
-if (count($amp_conf) == 0) {
- fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf));
-}
-out(_("OK"));
-
-$asterisk_conf_file = $amp_conf["ASTETCDIR"]."/asterisk.conf";
-outn(sprintf(_("Parsing %s .."), $asterisk_conf_file));
-$asterisk_conf = parse_asterisk_conf($asterisk_conf_file);
-if (count($asterisk_conf) == 0) {
- fatal(_("asterisk.conf parsing failure"),sprintf(_("no entries found in %s"), $asterisk_conf_file));
-}
-out(_("OK"));
-
-// **** Connect to database
-
-outn(_("Connecting to database.."));
-
-# the engine to be used for the SQL queries,
-# if none supplied, backfall to mysql
-$db_engine = "mysql";
-if (isset($amp_conf["AMPDBENGINE"])){
- $db_engine = $amp_conf["AMPDBENGINE"];
-}
-*/
-
-// Define the notification class for logging to the dashboard
-//
-$nt = notifications::create($db);
-
-// **** Create symlinks array
-$symlink_dirs = array();
-$symlink_dirs['sounds'] = $amp_conf['ASTVARLIBDIR'].'/sounds';
-$symlink_dirs['bin'] = $amp_conf['AMPBIN'];
-$symlink_dirs['etc'] = $amp_conf['ASTETCDIR'];
-$symlink_dirs['images'] = $amp_conf['AMPWEBROOT']."/admin/images";
-
-/*
-switch ($db_engine)
-{
- case "pgsql":
- case "mysql":
- // datasource in in this style:
- // dbengine://username:password@host/database
-
- $db_user = $amp_conf["AMPDBUSER"];
- $db_pass = $amp_conf["AMPDBPASS"];
- $db_host = $amp_conf["AMPDBHOST"];
- $db_name = $amp_conf["AMPDBNAME"];
-
- $datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
- $db = DB::connect($datasource); // attempt connection
- break;
-
- case "sqlite":
- die_freepbx("SQLite2 support is deprecated. Please use sqlite3 only.");
- break;
-
- case "sqlite3":
- if (!isset($amp_conf["AMPDBFILE"]))
- fatal("You must setup properly AMPDBFILE in $amportalconf");
-
- if (isset($amp_conf["AMPDBFILE"]) == "")
- fatal("AMPDBFILE in $amportalconf cannot be blank");
-
- // on centos this extension is not loaded by default
- if (! extension_loaded('sqlite3.so') )
- dl('sqlite3.so');
-
- if (! @require_once('DB/sqlite3.php') )
- {
- die_freepbx("Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear.");
- }
-
- require_once('DB/sqlite3.php');
- $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666";
- $db = DB::connect($datasource);
- break;
-
- default:
- fatal( "Unknown SQL engine: [$db_engine]");
-}
-
-if(DB::isError($db)) {
- out(_("FAILED"));
- debug($db->userinfo);
- fatal(_("database connection failure"),("failed trying to connect to the configured database"));
-
-}
-
-//TODO : make this engine-neutral
-outn(_("Connecting to Asterisk manager interface.."));
-// connect to asterisk manager
-require_once($amp_conf['AMPWEBROOT'].'/admin/common/php-asmanager.php');
-$astman = new AGI_AsteriskManager();
-if (! $res = $astman->connect("127.0.0.1:".$amp_conf["ASTMANAGERPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
- out(_("FAILED"));
- fatal(_("Asterisk Manager Connection Failure"),sprintf(_("Failed to connect to the Asterisk manager through port: %s"), $amp_conf['ASTMANAGERPORT']));
-}
-*/
-
-//include common functions
-require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
-freepbx_log("retrieve_conf", "devel-debug", "Started retrieve_conf, DB Connection OK");
-
-// query for our modules
-// var_dump( $db );
-$modules = module_getinfo();
-
-//Putting the core module last, to move outbound-allroutes
-// last in from-internals-additional
-if (array_key_exists('core', $modules)) {
- $core_tmp = $modules['core'];
- unset($modules['core']);
- $modules['core'] = $core_tmp;
-}
-
-// include any module global functions
-if(is_array($modules)){
- foreach($modules as $key => $module) {
- $return['retrieve_conf'] = $return['retrieve_conf'] . $key . "\n";
- //only use this module if it's enabled (status=2)
- if (isset($module['status']) && $module['status'] == MODULE_STATUS_ENABLED) {
- // Make sure the module is installed and up to date
- if ($run_install) module_install($key);
- // active_modules array used in genConf function
- $active_modules[] = $key;
- //include module functions
- if (is_file($amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php")) {
- freepbx_log('retrieve_conf', 'devel-debug', 'Including '.$amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php");
- include_once($amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php");
- freepbx_log('retrieve_conf', 'devel-debug', $amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php processed OK");
- }
-
- // create symlinks for files in appropriate sub directories
- symlink_subdirs( $amp_conf['AMPWEBROOT'].'/admin/modules/'.$key );
- cp_subdirs( $amp_conf['AMPWEBROOT'].'/admin/modules/'.$key );
- }
- }
-}
-$return['retrieve_conf'] = $return['retrieve_conf'] . $amp_conf['AMPWEBROOT'];
-
-// create an object of the extensions class
-require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
-$ext = new extensions;
-
-// create objects for any module classes
-// currently only 1 class can be declared per module, not sure if that will be an issue
-if(isset($active_modules) && is_array($active_modules)){
- foreach($active_modules as $active_module) {
- freepbx_log('retrieve_conf', 'devel-debug', "Creating ".$active_module."_conf class");
- $classname = $active_module."_conf";
- if(class_exists($classname)) {
- ${$classname} = new $classname;
- }
- }
-}
-
-$engineinfo = engine_getinfo();
-if($engineinfo['version'] == 0){
- freepbx_log('retrieve_conf', 'fatal', "Failed to get engine information (engine_getinfo: {$engineinfo['engine']})");
- fatal(_("Failed to get engine_info"),_("retreive_conf failed to get engine information and cannot configure up a softwitch with out it. Error: {$engineinfo['engine']}"));
-}
-// was setting these variables before, assume we still need them
-$engine = $engineinfo['engine'];
-$version = $engineinfo['version'];
-
-// Check for and report any extension conflicts
-//
-
-$extens_ok = true;
-$dests_ok = true;
-
-$nt = notifications::create($db);
-
-$my_hash = array_flip($active_modules);
-$my_prob_extens = framework_list_extension_conflicts($my_hash);
-
-if (empty($my_prob_extens)) {
- $nt->delete('retrieve_conf', 'XTNCONFLICT');
-} else {
- $previous = null;
- $str = null;
- $count = 0;
- foreach ($my_prob_extens as $extens) {
- foreach ($extens as $exten => $details) {
- if ($exten != $previous) {
- $str .= "Extension: $exten:<br />";
- $count++;
- }
- $str .= sprintf("%8s: %s<br />",$details['status'], $details['description']);
- $previous = $exten;
- }
- }
- $nt->add_error('retrieve_conf', 'XTNCONFLICT', sprintf(_("There are %s conflicting extensions"),$count), $str);
- $extens_ok = false;
-}
-
-// Check for and report any bogus destinations
-//
-$my_probs = framework_list_problem_destinations($my_hash, !$amp_conf['CUSTOMASERROR']);
-
-if (empty($my_probs)) {
- $nt->delete('retrieve_conf', 'BADDEST');
-} else {
- $results = array();
- $count = 0;
- $str = null;
- foreach ($my_probs as $problem) {
- //print_r($problem);
- $results[$problem['status']][] = $problem['description'];
- $count++;
- }
- foreach ($results as $status => $subjects) {
- $str .= sprintf(_("DEST STATUS: %s%s"),$status,"\n");
- foreach ($subjects as $subject) {
- //$str .= $subject."<br />";
- $str .= " ".$subject."\n";
- }
- }
- $nt->add_error('retrieve_conf', 'BADDEST', sprintf(_("There are %s bad destinations"),$count), $str);
- $dests_ok = false;
-}
-
-if ((!$exten_ok && $amp_conf['XTNCONFLICTABORT']) || (!$dest_ok && $amp_conf['BADDESTABORT'])) {
- out(_("Aborting reload because extension conflicts or bad destinations"));
- exit(20);
-}
-//$return['retrieve_conf'] = $return['retrieve_conf'] . "\n";
-
-// run all of the *_get_config and _hookGet_config functions, which will populate the appropriate objects
-if(isset($active_modules) && is_array($active_modules)){
- foreach($active_modules as $module) {
- $funcname = $module."_get_config";
- if (function_exists($funcname)) {
- freepbx_log('retrieve_conf', 'devel-debug', 'Calling '.$funcname.'()');
- $return['retrieve_conf'] = $return['retrieve_conf'] . $funcname . "\n";
- $funcname($engine);
- }
- }
- foreach($active_modules as $module) {
- $funcname = $module."_hookGet_config";
- if (function_exists($funcname)) {
- freepbx_log('retrieve_conf', 'devel-debug', 'Calling '.$funcname.'()');
- $return['retrieve_conf'] = $return['retrieve_conf'] . $funcname . "\n";
- $funcname($engine);
- }
- }
-}
-
-// extensions_additional.conf
-// create the from-internal-additional context so other can add to it
-$ext->add('from-internal-additional', 'h', '', new ext_hangup(''));
-//echo $ext->get_filename();
-//echo $ext->generateConf();
-write_file($ext->get_filename(),$ext->generateConf());
-
-// now we write out our conf files for modules
-// check for any objects for each of the active modules
-// ** conferences is an example of a module that write a conf
-if(isset($active_modules) && is_array($active_modules)){
- foreach($active_modules as $active_module) {
- $classname = $active_module."_conf";
- if(class_exists($classname) && get_class(${$classname}) !== false) {
- //echo ${$classname}->get_filename();
- //echo ${$classname}->generateConf();
-
- // if the module returns an array, it wants to write multiple files
- // ** pinsets is an example of a module that does this
- if (is_array(${$classname}->get_filename())) {
- foreach(${$classname}->get_filename() as $modconf) {
- freepbx_log('retrieve_conf', 'devel-debug', 'generateConf from '.$classname.'->'.$modconf.'');
- write_file($modconf,${$classname}->generateConf($modconf));
- }
- } else {
- freepbx_log('retrieve_conf', 'devel-debug', 'generateConf from '.$classname);
- write_file(${$classname}->get_filename(),${$classname}->generateConf());
- }
- }
- }
-}
-
-
-function write_file($filename,$contents) {
- global $asterisk_conf;
- freepbx_log('retrieve_conf', 'devel-debug', 'Writing '.$filename);
- if (isset($filename) && !empty($filename)) {
- if ($fd = fopen(addslash($asterisk_conf['astetcdir']).$filename, "w")) {
- fwrite($fd, WARNING_BANNER );
- fwrite($fd, $contents);
- fclose($fd);
- }
- }
-}
-
-/* file_exists_wrapper()
- * wrapper for file_exists() with the following additonal functionality.
- * if the file is a symlink, it will check if the link exists and if not
- * it will try to remove this file. It returns a false (file does not exists)
- * if the file is successfully removed, true if not. If not a symlink, just
- * returns file_exists()
- */
-function file_exists_wrapper($string) {
- if (is_link($string)) {
- $linkinfo = readlink($string);
- if ($linkinfo === false) {
- //TODO: throw error?
- return !unlink($string);
- } else {
- if (file_exists($linkinfo)) {
- return true;
- } else {
- return !unlink($string);
- }
- }
- } else {
- return file_exists($string);
- }
-}
-
-function symlink_subdirs($moduledir) {
-global $amp_conf;
-$symlink_dirs = array();
-$symlink_dirs['sounds'] = $amp_conf['ASTVARLIBDIR'].'/sounds';
-$symlink_dirs['bin'] = $amp_conf['AMPBIN'];
-$symlink_dirs['etc'] = $amp_conf['ASTETCDIR'];
-$symlink_dirs['images'] = $amp_conf['AMPWEBROOT']."/admin/images";
-
-// global $symlink_dirs;
- $symlink_errors = false;
-
- $nt = notifications::create($db);
-
- foreach ($symlink_dirs as $subdir => $targetdir) {
- $dir = addslash($moduledir).$subdir;
- if (is_dir($dir)) {
- $d = opendir($dir);
- while ($file = readdir($d)) {
- if ($file[0] != '.') {
- $src = addslash($dir).$file;
- $dest = addslash($targetdir).$file;
- if (file_exists_wrapper($dest)) {
- if (!is_link($dest)) {
- freepbx_log('retrieve-conf', 'error', $dest.' already exists, and is not a symlink!');
- $nt->add_error('retrieve_conf', 'SYMLINK', _("symlink from modules failed"), sprintf(_("retrieve_conf failed to sym link the %s file from modules"),$dest));
- $symlink_errors = true;
- } else if (readlink($dest) != $src) {
- // TODO : is this the proper handling? should we just overwrite..?
- freepbx_log('retrieve-conf', 'error', $dest.' already exists, and is linked to something else!');
- $nt->add_error('retrieve_conf', 'SYMLINK', _("symlink from modules failed"), sprintf(_("retrieve_conf failed to sym link the %s file from modules"),$dest));
- $symlink_errors = true;
- } else {
- freepbx_log('retrieve-conf', 'devel-debug', $dest.' already points to '.$src.' - OK');
- }
- } else {
-// // symlink, unlike copy, doesn't overwrite - have to delete first
-// if (is_link($dest) || file_exists($dest)) {
-// unlink($dest);
-// }
- if (symlink($src, $dest)) {
- freepbx_log('retrieve-conf', 'devel-debug', 'Symlinked '.$src.' to '.$dest);
- } else {
- freepbx_log('retreive-conf', 'devel-debug', 'Cannot symlink '.$src.' to '.$dest.'. Check Permissions?');
- }
- }
- }
- }
- closedir($d);
- }
- }
- if (!$symlink_errors) {
- $nt->delete('retrieve_conf', 'SYMLINK');
- }
-}
-
-// wrap copy with error handler
-//
-function err_copy($source, $dest) {
- $ret = false;
- set_error_handler("report_errors");
- if (copy($source, $dest)) {
- $ret = chmod($dest,'0754');
- }
- restore_error_handler();
- return $ret;
-}
-
-// wrap unlink with error handler
-//
-function err_unlink($dest) {
- set_error_handler("report_errors");
- $ret = unlink($dest);
- restore_error_handler();
- return $ret;
-}
-
-function cp_subdirs($moduledir) {
- global $cp_errors;
-global $amp_conf;
-$cp_dirs = array();
-$cp_dirs['agi-bin'] = $amp_conf['ASTAGIDIR'];
-// global $cp_dirs;
-
- $cp_errors = "";
- foreach ($cp_dirs as $subdir => $targetdir) {
- $dir = addslash($moduledir).$subdir;
- if (is_dir($dir)) {
- $d = opendir($dir);
- while ($file = readdir($d)) {
- if ($file[0] != '.') {
- $sourcefile = addslash($dir).$file;
- $targetfile = addslash($targetdir).$file;
-
- if (file_exists_wrapper($targetfile)) {
- if (is_link($targetfile)) {
- if (err_unlink($targetfile)) {
- freepbx_log('retrieve-conf', 'devel-debug', "$targetfile was symbolic link, unlink successful");
- } else {
- freepbx_log('retrieve-conf', 'error', "$targetfile is a symblolic link, failed to unlink!");
- break;
- }
- }
- }
- // OK, now either the file is a regular file or isn't there, so proceed
- //
- if (err_copy($sourcefile,$targetfile)) {
- freepbx_log('retrieve-conf', 'devel-debug', "$targetfile successfully copied");
- // copy was successful, make sure it has execute permissions
- chmod($targetfile,0754);
- } else {
- freepbx_log('retrieve-conf', 'error', "$targetfile failed to copy from module directory");
- }
- }
- }
- closedir($d);
- }
- }
- $nt = notifications::create($db);
- if ($cp_errors) {
- $nt->add_error('retrieve_conf', 'CPAGIBIN', _("Failed to copy from module agi-bin"), sprintf(_("Retrieve conf failed to copy file(s) from a module's agi-bin dir: %s"),$cp_errors));
- } else {
- $nt->delete('retrieve_conf', 'CPAGIBIN');
- }
-}
-
-function report_errors($errno, $errstr, $errfile, $errline) {
- global $cp_errors;
- freepbx_log('retrieve-conf', 'error', "php reported: '".mysql_real_escape_string($errstr)."' after copy or unlink attempt!");
- $cp_errors .= $errstr."\n";
-}
-
-/** Check if there is a job running, if one is found then all is good, if one is not found, it will be added and a
- * notification will be sent.
- */
-function install_cron_scheduler() {
- global $amp_conf;
- global $nt;
-
- // crontab appears to return an error when no entries, os only fail if error returned AND a list of entries.
- // Don't know if this will ever happen, but a failure and a list could indicate something wrong.
- //
- exec("/usr/bin/crontab -l", $outlines, $ret);
- if ($ret && count($outlines)) {
- $nt->add_error('retrieve_conf', 'CRONMGR', _("Failed to check crontab for cron manager"), sprintf(_("crontab returned %s error code when checking for crontab entries to start freepbx-cron-scheduler.php crontab manager"),$ret));
- } else {
- $nt->delete('retrieve_conf', 'CRONMGR');
- $outlines2 = preg_grep("/freepbx-cron-scheduler.php/",$outlines);
- $cnt = count($outlines2);
- switch ($cnt) {
- case 0:
- /** grab any other cronjobs that are running as asterisk and NOT associated with backups
- * this code was taken from the backup module for the most part. But seems to work...
- */
- $outlines = array();
- exec("/usr/bin/crontab -l | grep -v ^#\ DO\ NOT | grep -v ^#\ \( | grep -v freepbx-cron-scheduler.php", $outlines, $ret);
- $crontab_entry = "";
- foreach ($outlines as $line) {
- $crontab_entry .= $line."\n";
- }
- // schedule to run hourly, at a random time. The random time is explicit to accomodate things like module_admin online update checking
- // since we will want a random access to the server. In the case of module_admin, that will also be scheduled randomly within the hour
- // that it is to run
- //
- $crontab_entry .= rand(0,59)." * * * * ".$amp_conf['AMPBIN']."/freepbx-cron-scheduler.php";
- system("/bin/echo '$crontab_entry' | /usr/bin/crontab -");
- break;
- case 1:
- // already running, nothing to do
- break;
- default:
- // error, there should never be more than one running
- echo "TODO: deal with error here\n";
- $nt->add_error('retrieve_conf', 'CRONMGR', _("Multiple freepbx-cron-scheduler.php running"), sprintf(_("There were %s freepbx-cron-scheduler.php instances running. There should be only 1."),$cnt));
- }
- }
-}
-include($amp_conf['AMPBIN']."/libfreepbx.confgen.php");
-// script to write op_server.cfg file from mysql
-//
-if ($amp_conf["AMPDBENGINE"] != 'sqlite3') {
- // sqlite3 not supported just yet
- $script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.pl '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
- exec($script);
-}
-
-// generate configuration files
-//
-// Leave the legacy scripts in for a little while to help with odd-ball upgrade scenarios if they haven't gotten
-// a module upgraded yet. In particular Queues
-//
-if (!isset($core_conf) || !is_a($core_conf, "core_conf")) {
- generate_configurations_sip($version);
- generate_configurations_iax($version);
- generate_configurations_zap($version);
-}
-
-// Check and install the freepbx-cron-scheduler.php manager
-//
-install_cron_scheduler();
-// run retrieve_conf_post_custom
-// If the following file exists, it will be run. This allows customization to be run automatically after the normal
-// processing. Caution should be taken using this as it is only deisgned for expert usage. Errors in the code will
-// have bad consequences and can cripple the system.
-//
-if (isset($amp_conf['AMPLOCALBIN'])) {
-$post_custom = $amp_conf['AMPLOCALBIN'].'/retrieve_conf_post_custom';
- if (file_exists($post_custom)) {
- outn(sprintf(_("Found script %s, executing.."), $post_custom));
- include($post_custom);
- out(_("OK"));
- }
-}
-
-out("after post");
-/* As of Asterisk 1.4.16 or there abouts, a missing #include file will make the reload fail. So
- we need to make sure that we have such for everything that is in our configs. We will simply
- look for the #include statements and touch the files vs. trying to inventory everything we may
- need and then forgetting something.
-*/
-
-exec("grep '#include' ".$amp_conf['ASTETCDIR']."/*.conf | sed 's/;.*//; s/#include//'",$output,$retcode);
-if ($retcode != 0) {
- error("Error code $retcode: trying to search for missing #include files");
-}
-foreach($output as $file) {
- if (trim($file) == '') {
- continue;
- }
- $parse1 = explode(':',$file);
- $parse2 = explode(';',$parse1[1]);
- $rawfile = trim($parse2[0]);
- if ($rawfile == '') {
- continue;
- }
-
- $target = ($rawfile[0] == '/') ? $rawfile : $amp_conf['ASTETCDIR']."/$rawfile";
-
- if (!file_exists($target)) {
- exec("touch $target", $output, $retcode);
- error("Error code $retcode: trying to create empty file $target");
- }
-}
-
-// **** Set reload flag for AMP admin
-needreload();
-if (isset($amp_conf["AMPWEBADDRESS"]) && $amp_conf["AMPWEBADDRESS"])
-{
- out(sprintf(_("Please update your modules and reload Asterisk by visiting %s"), "http://".$amp_conf["AMPWEBADDRESS"]."/admin"));
-}
-else
-{
- out(_("Please update your modules and reload Asterisk by browsing to your server."));
-}
- $nt->delete('retrieve_conf', 'FATAL');
-out("end\n");
-$exit_val = 0;
-?>
+++ /dev/null
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * The PEAR DB driver for PHP's sqlite3 extension
- * for interacting with SQLite3 databases
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Database
- * @package DB
- * @author Bruno Fleisch
- * @copyright 1997-2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
- * @version CVS: $Id: sqlite3.php,v 1.3 2007/04/04 14:13:19 bfleisch Exp $
- * @link http://pear.php.net/package/DB
- */
-
-include_once 'DB/common.php';
-
-
-
-/**
- * The methods PEAR DB uses to interact with PHP's sqlite extension
- * for interacting with SQLite databases
- *
- * These methods overload the ones declared in DB_common.
- *
- */
-
-class DB_sqlite3 extends DB_common
-{
-
- // {{{ PROPERTIES
-
-
- var $phptype = 'sqlite3';
-
- /**
- * The database syntax variant to be used (db2, access, etc.), if any
- * @var string
- */
- var $dbsyntax = 'sqlite3';
-
- /**
- * The capabilities of this DB implementation
- *
- * The 'new_link' element contains the PHP version that first provided
- * new_link support for this DBMS. Contains false if it's unsupported.
- *
- * Meaning of the 'limit' element:
- * + 'emulate' = emulate with fetch row by number
- * + 'alter' = alter the query
- * + false = skip rows
- *
- * @var array
- */
- var $features = array(
- 'limit' => 'alter',
- 'new_link' => false,
- 'numrows' => 'emulate',
- 'pconnect' => true,
- 'prepare' => false,
- 'ssl' => false,
- 'transactions' => false,
- );
-
-
- /**
- * A mapping of native error codes to DB error codes
- *
- * {@internal Error codes according to sqlite_exec. See the online
- * manual at http://sqlite.org/c_interface.html for info.
- * This error handling based on sqlite_exec is not yet implemented.}}
- *
- * @var array
- */
- var $errorcode_map = array(
- );
-
- /**
- * The raw database connection created by PHP
- * @var resource
- */
- var $connection;
-
- /* The DSN information for connecting to a database
- * @var array
- */
- var $dsn = array();
-
-
- /**
- * SQLite data types
- *
- * @link http://www.sqlite.org/datatypes.html
- *
- * @var array
- */
- var $keywords = array (
- 'BLOB' => '',
- 'BOOLEAN' => '',
- 'CHARACTER' => '',
- 'CLOB' => '',
- 'FLOAT' => '',
- 'INTEGER' => '',
- 'KEY' => '',
- 'NATIONAL' => '',
- 'NUMERIC' => '',
- 'NVARCHAR' => '',
- 'PRIMARY' => '',
- 'TEXT' => '',
- 'TIMESTAMP' => '',
- 'UNIQUE' => '',
- 'VARCHAR' => '',
- 'VARYING' => '',
- );
-
- /**
- * The most recent error message from $php_errormsg
- * @var string
- * @access private
- */
- var $_lasterror = '';
-
-
-
- // }}}
- // {{{ constructor
-
- /**
- * constructor
- *
- * @return void
- */
-
- function DB_sqlite3()
- {
- $this->DB_common();
- }
-
-
- // }}}
- // {{{ string errorNative(void)
-
- /**
- * Gets the DBMS' native error code produced by the last query
- *
- * @return mixed the DBMS' error code. A DB_Error object on failure.
- */
-
- function errorNative()
- {
- return sqlite3_error ($this->connection);
- }
-
- // }}}
- // {{{ mixed connect(array $dsn, bool $persitent)
-
- /**
- * create or connect to the specified database.
- *
- * @param array $dsn the data source name
- * @param bool $persitent if the connection is persitent
- *
- * @return DB_OK on success or DB_error object on failure
- */
-
-
- function connect($dsn, $persitent = false)
- {
- $this->connection = sqlite3_open ($dsn['database']);
- if (!$this->connection)
- return $this->raiseError(DB_ERROR_NODBSELECTED);
-
- return DB_OK;
- }
-
- // }}}
- // {{{ bool disconnect (void)
-
-
- /**
- * release all resources for this connection, and close database
- *
- * @return bool TRUE on sucess, FALSE otherwise.
- */
-
- function disconnect()
- {
- return sqlite3_close ($this->connection);
- }
-
- // }}}
- // {{{ mixed simpleQuery(string $sql)
-
- /**
- * execute a SQL query.
- *
- * @param string $query the SQL query
- *
- * @return mixed + object DB_error object on failure
- * + object Result resource for SELECT requests
- * + bool TRUE for other sucessful requests
- */
-
- function simpleQuery($query)
- {
-
- $isSelect = preg_match ("/^\s*SELECT/i", $query);
-
- #$handle = fopen("/tmp/sql.txt",'a');
- #fwrite($handle, "<strong>sqlite3 simpleQuery: $query</strong><br>\n");
- #fclose($handle);
-
- if (! $isSelect)
- $this->result = sqlite3_exec($this->connection, $query);
- else
- $this->result = sqlite3_query($this->connection, $query);
-
- if (!$this->result)
- return $this->RaiseError($this->errorNative());
-
- return $this->result;
- }
-
- // }}}
- // {{{ mixed fetchInto(resource $res, array $arr, int $fetchmode [, int $rownum])
-
- /**
- * Fetch a row of data into an array which is passed by reference
- *
- * The type of array returned can be controlled either by setting this
- * method's <var>$fetchmode</var> parameter or by changing the default
- * fetch mode setFetchMode() before calling this method.
- *
- * There are two options for standardizing the information returned
- * from databases, ensuring their values are consistent when changing
- * DBMS's. These portability options can be turned on when creating a
- * new DB object or by using setOption().
- *
- * + <var>DB_PORTABILITY_LOWERCASE</var>
- * convert names of fields to lower case
- *
- * + <var>DB_PORTABILITY_RTRIM</var>
- * right trim the data
- *
- * @param resource $result the result resource
- * @param array &$arr the variable where the data should be placed
- * @param int $fetchmode the constant indicating how to format the data
- * @param int $rownum the row number to fetch (index starts at 0)
- *
- * @return mixed DB_OK if a row is processed, NULL when the end of the
- * result set is reached or a DB_Error object on failure
- *
- * @see DB_common::setOption(), DB_common::setFetchMode()
- */
-
- function fetchInto($result, &$arr, $fetchmode, $rownum = null)
- {
- if ($rownum !==NULL)
- return $this->RaiseError (DB_ERROR_NOTIMPLEMENTED);
-
- switch ($fetchmode)
- {
-
- case DB_FETCHMODE_ORDERED:
- $fetchfunc="sqlite3_fetch";
- break;
-
- case DB_FETCHMODE_OBJECT:
- return $this->RaiseError(DB_ERROR_NODBSELECTED);
- break;
-
- case DB_FETCHMODE_ASSOC:
- default:
- $fetchfunc="sqlite3_fetch_array";
- break;
- }
-
- $arr = $fetchfunc($result);
-
- if ($arr)
- return DB_OK;
-
- return NULL;
- }
-
- // }}}
- // {{{ string modifyLimitQuery(string $query, int $from, int $count [,mixed $params])
-
-
- /**
- * Adds LIMIT clauses to a query string according to current DBMS standards
- *
- * It is defined here to assure that all implementations
- * have this method defined.
- *
- * @param string $query the query to modify
- * @param int $from the row to start to fetching (0 = the first row)
- * @param int $count the numbers of rows to fetch
- * @param mixed $params array, string or numeric data to be used in
- * execution of the statement. Quantity of items
- * passed must match quantity of placeholders in
- * query: meaning 1 placeholder for non-array
- * parameters or 1 placeholder per array element.
- *
- * @return string the query string with LIMIT clauses added
- *
- * @access protected
- */
-
- function modifyLimitQuery($query, $from, $count, $params = array())
- {
- return "$query LIMIT $count OFFSET $from";
- }
-
-
- // }}}
- // {{{ bool freeResult(void)
-
- /**
- * free the specified result.
- *
- * @param resource $result the query resource result
- *
- * @return bool DB_OK
- *
- */
-
- function freeResult($result)
- {
- sqlite3_query_close($result);
- return DB_OK; /* always sucessful ! */
- }
-
- // }}}
- // {{{ int affectedRow(void)
-
- /**
- * Determines the number of rows affected by a data maniuplation query
- *
- * 0 is returned for queries that don't manipulate data.
- *
- * @return int the number of rows. A DB_Error object on failure.
- */
-
- function affectedRows()
- {
- return sqlite3_changes ($this->connection);
- }
-
- // }}}
- // {{{ mixed numCols(resource $result)
-
- /**
- * Get the the number of columns in a result set
- *
- * @return int the number of columns. A DB_Error object on failure.
- */
-
- function numCols($result)
- {
- return sqlite3_column_count($result);
- }
-
- // {{{ mixed createSequence(string $seq_name)
-
- /**
- * Creates a new sequence
- *
- * The name of a given sequence is determined by passing the string
- * provided in the <var>$seq_name</var> argument through PHP's sprintf()
- * function using the value from the <var>seqname_format</var> option as
- * the sprintf()'s format argument.
- *
- * <var>seqname_format</var> is set via setOption().
- *
- * @param string $seq_name name of the new sequence
- *
- * @return int DB_OK on success. A DB_Error object on failure.
- *
- * @see DB_common::dropSequence(), DB_common::getSequenceName(),
- * DB_common::nextID()
- */
-
- function createSequence($seq_name)
- {
- return $this->query ("CREATE TABLE " . $this->getSequenceName($seq_name) . " (id INTEGER PRIMARY KEY AUTOINCREMENT)");
- }
-
- // }}}
- // {{{ mixed nextId(string $sequence [, bool $ondemand])
-
- /**
- * Returns the next free id in a sequence
- *
- * @param string $seq_name name of the sequence
- * @param boolean $ondemand when true, the seqence is automatically
- * created if it does not exist
- *
- * @return int the next id number in the sequence.
- * A DB_Error object on failure.
- *
- * @see DB_common::createSequence(), DB_common::dropSequence(),
- * DB_common::getSequenceName()
- */
- function nextId($seq_name, $ondemand = true)
- {
-
- $sqn = $this->getSequenceName($seq_name);
-
- if ($ondemand)
- {
- $tables = $this->getTables();
- if (DB::isError($tables)) return $tables;
-
- if (! in_array ($sqn, $tables))
- {
- $res = $this->createSequence($seq_name);
- if ( DB::isError($res))
- return $res;
- }
- }
-
- $res = $this->query ("INSERT INTO " . $sqn . " VALUES (NULL)");
- if (DB::isError($res)) return $res;
-
- return sqlite3_last_insert_rowid ($this->connection);
- }
-
- // }}}
- // {{{ mixed dropSequence (string $seq_name)
-
- /**
- * Deletes a sequence
- *
- * @param string $seq_name name of the sequence to be deleted
- *
- * @return int DB_OK on success. A DB_Error object on failure.
- *
- * @see DB_common::createSequence(), DB_common::getSequenceName(),
- * DB_common::nextID()
- */
- function dropSequence($seq_name)
- {
- return $this->query("DROP TABLE ". $this->getSequenceName($seq_name));
- }
-
- // }}}
- // {{{ string getSpecialQuery(string $type)
-
- /**
- * Obtains the query string needed for listing a given type of objects
- *
- * @param string $type the kind of objects you want to retrieve
- *
- * @return string the SQL query string or null if the driver doesn't
- * support the object type requested
- *
- * @access protected
- * @see DB_common::getListOf()
- */
-
- function getSpecialQuery($type)
- {
- switch ($type) {
- case 'tables':
- return "SELECT name FROM SQLITE_MASTER ORDER BY name";
- default:
- return $this->raiseError(DB_ERROR_UNSUPPORTED);
- }
- }
-
- // }}}
-
-
-}
-?>
+++ /dev/null
-<?php phpinfo(); ?>
-
+++ /dev/null
-<?php
-
-# test.db.php
-# David Rowe Feb 2008
-#
-# Used to test and debug PEAR/DB sqlite3 support for FreePBX
-
-require_once('DB.php'); // PEAR must be installed
-
-/*
- datasource in in this style:
- dbengine://username:password@host/database
-*/
-
-# Mysql connection as a starting point ----------------------------
-
-/*
-
-$db_engine = "mysql";
-$db_user = "asteriskuser";
-$db_pass = "amp109";
-$db_host = "localhost";
-$db_name = "asterisk";
-
-$datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
-$db = DB::connect($datasource); // attempt connection
-print("Connecting to $datasource.....<br>");
-if (DB::isError ($db))
- die ("Cannot connect: " . $db->getMessage () . "\n");
-print("Disconnecting...<br>");
-$db->disconnect ();
-
-*/
-
-# Basic sqlite connection ----------------------------------------
-
-$options = array(
- 'debug' => 4,
- 'portability' => DB_PORTABILITY_NUMROWS
-);
-
-$file = "/var/lib/asterisk/freepbx.db";
-$datasource = "sqlite3:///" . $file . "?mode=0666";
-
-print("Connecting to $datasource.....<br>");
-
-if (! extension_loaded('sqlite3') ) {
- print("Loading sqlite3.so....<br>");
- dl('sqlite3.so');
-}
-
-$db = DB::connect($datasource, $options);
-if (DB::isError ($db))
- die ("Cannot connect: " . $db->getMessage () . "\n");
-
-$result = $db->query ("SELECT * FROM admin");
-if (DB::isError ($result))
- die ("SELECT failed: " . $result->getMessage () . "\n");
-
-print("admin table rows:<br>");
-while ($row =& $result->fetchRow ())
- printf("  %s, %s<br>", $row[0], $row[1]);
-
-# numRows Test --------------------------------------------------
-
-$numRows = $result->numRows();
-
-if (DB::isError ($numRows))
- die ("numRows failed: " . $numRows->getMessage () . "<br>");
-print ("result contains: $numRows rows<br>");
-
-# Try inserting a few values -----------------------------------
-
-$result =& $db->query ("INSERT INTO tbl1 VALUES ('AA',30)");
-
-if (DB::isError ($result))
- die ("INSERT failed: " . $result->getMessage () . "\n");
-
-$result = $db->query ("SELECT * FROM tbl1");
-
-if (DB::isError ($result))
- die ("SELECT failed: " . $result->getMessage () . "\n");
-
-while ($row =& $result->fetchRow ())
- printf("  %s<br>", $row[0]);
-
-$result->free();
-print("Disconnecting...");
-$db->disconnect ();
-
-?>
+++ /dev/null
---- orig/common.php 2008-03-01 09:40:36.000000000 +1030
-+++ mod/common.php 2008-03-01 09:14:34.000000000 +1030
-@@ -1213,6 +1213,7 @@
- return $ret;
- } else {
- $this->last_parameters = array();
-+ $this->last_query = $query;
- $result = $this->simpleQuery($query);
- if ($result === DB_OK || DB::isError($result)) {
- return $result;
+++ /dev/null
---- freepbx-2.4.0-orig//amp_conf/htdocs/admin/modules/core/functions.inc.php 2008-02-10 05:16:02.000000000 +1030
-+++ root/www/admin/modules/core/functions.inc.php 2008-03-11 11:31:52.000000000 +1030
-@@ -2886,6 +2886,7 @@
- // TODO: sqlite work arround - diego
- // TODO: WILL NOT WORK, need to remove the usage of SUBSTRING
- // need to reorder the trunks in PHP code
-+/*
- $sqlstr = "SELECT t.variable, t.value, d.value state FROM `globals` t ";
- $sqlstr .= "JOIN (SELECT x.variable, x.value FROM globals x WHERE x.variable LIKE 'OUTDISABLE\_%') d ";
- $sqlstr .= "ON substring(t.variable,5) = substring(d.variable,12) WHERE t.variable LIKE 'OUT\_%' ";
-@@ -2894,9 +2895,9 @@
- $sqlstr .= "WHERE v.variable LIKE 'OUT\_%' AND concat('OUTDISABLE_',substring(v.variable,5)) NOT IN ";
- $sqlstr .= " ( SELECT variable from globals WHERE variable LIKE 'OUTDISABLE\_%' ) ";
- $sqlstr .= "ORDER BY variable";
--
-- //$unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");
-- $unique_trunks = sql($sqlstr,"getAll");
-+*/
-+ $unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");
-+ //$unique_trunks = sql($sqlstr,"getAll");
- }
- else
- {
---- freepbx-2.4.0-orig//amp_conf/htdocs/admin/common/db_connect.php 2007-09-09 20:41:11.000000000 +0930
-+++ root/www/admin/common/db_connect.php 2008-03-11 11:31:52.000000000 +1030
-@@ -52,7 +52,11 @@
- }
-
- $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666";
-- $db = DB::connect($datasource);
-+ $options = array(
-+ 'debug' => 4,
-+ 'portability' => DB_PORTABILITY_NUMROWS
-+ );
-+ $db = DB::connect($datasource, $options);
- break;
-
- default:
-@@ -70,6 +74,7 @@
- $nt = notifications::create($db);
-
- if ($amp_conf['AMPDBPASS'] == $amp_conf_defaults['AMPDBPASS'][1]) {
-+ print
- $nt->add_warning('core', 'AMPDBPASS', _("Default SQL Password Used"), _("You are using the default SQL password that is widely known, you should set a secure password"));
- } else {
- $nt->delete('core', 'AMPDBPASS');
---- freepbx-2.4.0-orig//amp_conf/htdocs/recordings/includes/database.php 2006-05-01 01:05:45.000000000 +0930
-+++ root/www/recordings/includes/database.php 2008-03-11 11:31:52.000000000 +1030
-@@ -43,18 +43,25 @@
- // connect string
- if ($dbfile) {
- // datasource mostly to support sqlite: dbengine://dbfile?mode=xxxx
-- $dsn = $engine . '://' . $dbfile . '?mode=0666';
-+ $datasource = $engine . ':///' . $dbfile . '?mode=0666';
-+ $options = array(
-+ 'debug' => 4
-+ );
-+ if (! extension_loaded('sqlite3') ) {
-+ dl('sqlite3.so');
-+ }
-+
- }
- else {
- // datasource in in this style: dbengine://username:password@host/database
- $datasource = $engine . '://' . $username . ':' . $password . '@' . $host . '/' . $name;
-- }
-
-- // options
-- $options = array(
-- 'debug' => 2,
-- 'portability' => DB_PORTABILITY_LOWERCASE|DB_PORTABILITY_RTRIM|DB_PORTABILITY_DELETE_COUNT|DB_PORTABILITY_NUMROWS|DB_PORTABILITY_ERRORS|DB_PORTABILITY_NULL_TO_EMPTY,
-- );
-+ // options
-+ $options = array(
-+ 'debug' => 2,
-+ 'portability' => DB_PORTABILITY_LOWERCASE|DB_PORTABILITY_RTRIM|DB_PORTABILITY_DELETE_COUNT|DB_PORTABILITY_NUMROWS|DB_PORTABILITY_ERRORS|DB_PORTABILITY_NULL_TO_EMPTY,
-+ );
-+ }
-
- // attempt connection
- $dbh = DB::connect($datasource,$options);
---- freepbx-2.4.0-orig//amp_conf/htdocs/admin/cdr/lib/defines.php 2006-09-26 20:48:51.000000000 +0930
-+++ root/www/admin/cdr/lib/defines.php 2008-03-11 11:31:52.000000000 +1030
-@@ -12,7 +12,7 @@
- return $conf;
- }
-
--$amp_conf = parse_amportal_conf("/etc/amportal.conf");
-+$amp_conf = parse_amportal_conf("/etc/amportal.conf");
-
-
- define ("WEBROOT", "http://".$amp_conf["AMPWEBADDRESS"]."/admin/cdr/");
-@@ -27,8 +27,8 @@
- define ("PORT", "5432");
- define ("USER", $amp_conf["AMPDBUSER"]);
- define ("PASS", $amp_conf["AMPDBPASS"]);
--define ("DBNAME", "asteriskcdrdb");
--define ("DB_TYPE", "mysql"); // mysql or postgres
-+define ("DBNAME","/var/asteriskcdr.db");
-+define ("DB_TYPE","sqlite3");
-
-
- define ("DB_TABLENAME", "cdr");
-@@ -47,16 +47,36 @@
-
- function DbConnect()
- {
-- if (DB_TYPE == "postgres")
-- {
-+ switch (DB_TYPE)
-+ {
-+
-+ case "pgsql":
- $datasource = 'pgsql://'.USER.':'.PASS.'@'.HOST.'/'.DBNAME;
-- }
-- else
-- {
-+ $options = array();
-+ break;
-+
-+ case "mysql":
- $datasource = DB_TYPE.'://'.USER.':'.PASS.'@'.HOST.'/'.DBNAME;
-- }
-+ $options = array();
-+ break;
-+
-+ case "sqlite3":
-+ $datasource = DB_TYPE . ':///' . DBNAME . '?mode=0666';
-+ if (! extension_loaded('sqlite3') ) {
-+ dl('sqlite3.so');
-+ }
-+ if (! require_once('DB/sqlite3.php') )
-+ {
-+ die_freepbx("Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear.");
-+ }
-+ $options = array(
-+ 'debug' => 4,
-+ 'portability' => DB_PORTABILITY_NUMROWS
-+ );
-+ break;
-+ }
-
-- $db = DB::connect($datasource); // attempt connection
-+ $db = DB::connect($datasource, $options); // attempt connection
-
- if(DB::isError($db))
- {
---- freepbx-2.4.0-orig//amp_conf/htdocs/admin/cdr/lib/Class.Table.php 2006-09-26 20:48:51.000000000 +0930
-+++ root/www/admin/cdr/lib/Class.Table.php 2008-03-11 11:31:52.000000000 +1030
-@@ -80,8 +80,11 @@
-
- //$res=DbExec($link, $QUERY);
- $res = $DBHandle -> query($QUERY);
-+ if(DB::IsError($res)) {
-+ print($res->getMessage());
-+ print("<br>Is Asterisk CDR database initialised?");
-+ }
-
--
- $num = $res -> numRows();
-
-
---- freepbx-2.4.0-orig//SQL/newinstall.sqlite3.sql 2008-02-11 14:27:53.000000000 +1030
-+++ freepbx-2.4.0//SQL/newinstall.sqlite3.sql 2008-03-08 10:05:24.000000000 +1030
-@@ -323,7 +323,7 @@
- -- Dumping data for table `modules`
- --
-
--DROP TABLE IF EXISTS `modules_xml`;
-+DROP TABLE IF EXISTS `module_xml`;
- CREATE TABLE `module_xml` (
- `id` varchar(20) NOT NULL default 'xml',
- `time` int(11) NOT NULL default '0',
---- freepbx-2.4.0-orig//install_amp 2008-01-28 04:22:58.000000000 +1030
-+++ freepbx-2.4.0//install_amp 2008-03-08 10:05:29.000000000 +1030
-@@ -4,7 +4,7 @@
- require_once ("libfreepbx.install.php");
-
- # constants
--define("AMP_CONF", "/etc/amportal.conf");
-+define("AMP_CONF", "/etc/amportal.conf");
- define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
- define("UPGRADE_DIR", dirname(__FILE__)."/upgrades");
- define("MODULE_DIR", dirname(__FILE__)."/amp_conf/htdocs/admin/modules/");
-@@ -691,13 +691,16 @@
- // **** Look for user = root
-
- outn("Checking user..");
--//$current_user=(isset($_ENV["USER"]) ? $_ENV["USER"] : exec('whoami',$output));
--$euid = (posix_getpwuid(posix_geteuid()));
--$current_user = $euid['name'];
--if ($current_user != "root"){
-- out("FAILED");
-- fatal($argv[0]." must be run as root");
-+if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
-+ //$current_user=(isset($_ENV["USER"]) ? $_ENV["USER"] : exec('whoami',$output));
-+ $euid = (posix_getpwuid(posix_geteuid()));
-+ $current_user = $euid['name'];
-+ if ($current_user != "root"){
-+ out("FAILED");
-+ fatal($argv[0]." must be run as root");
-+ }
- }
-+
- out("OK");
-
-
-@@ -892,10 +895,12 @@
-
- outn("Connecting to database..");
-
--$db_user = $amp_conf["AMPDBUSER"];
--$db_pass = $amp_conf["AMPDBPASS"];
--$db_host = $amp_conf["AMPDBHOST"];
- $db_engine = $amp_conf["AMPDBENGINE"];
-+if ($db_engine != "sqlite3") {
-+ $db_user = $amp_conf["AMPDBUSER"];
-+ $db_pass = $amp_conf["AMPDBPASS"];
-+ $db_host = $amp_conf["AMPDBHOST"];
-+}
- $db_name = $amp_conf["AMPDBNAME"];
-
- // we still support older configurations, and fall back
---- freepbx-2.4.0-orig//amp_conf/htdocs/admin/modules/recordings/install.php 2007-08-08 14:34:58.000000000 +0930
-+++ freepbx-2.4.0//amp_conf/htdocs/admin/modules/recordings/install.php 2008-03-08 10:05:24.000000000 +1030
-@@ -22,7 +22,14 @@
- unset($fcc);
-
- // Make sure table exists
--$sql = "CREATE TABLE IF NOT EXISTS recordings ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50) , filename BLOB, description VARCHAR(254));";
-+
-+if ($amp_conf["AMPDBENGINE"] == 'sqlite3') {
-+ $sql = "CREATE TABLE IF NOT EXISTS recordings ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, displayname VARCHAR(50) , filename BLOB, description VARCHAR(254));";
-+}
-+else {
-+ $sql = "CREATE TABLE IF NOT EXISTS recordings ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50) , filename BLOB, description VARCHAR(254));";
-+}
-+
- $result = $db->query($sql);
- if(DB::IsError($result)) {
- die_freepbx($result->getDebugInfo());
-@@ -42,7 +49,13 @@
- $sql = "SELECT * FROM recordings where displayname = '__invalid'";
- $results = $db->getRow($sql, DB_FETCHMODE_ASSOC);
- if (!isset($results['filename'])) {
-- sql("INSERT INTO recordings values ('', '__invalid', 'install done', '')");
-+ if ($amp_conf["AMPDBENGINE"] == 'sqlite3') {
-+ sql("INSERT INTO recordings values (NULL, '__invalid', 'install done', '')");
-+ }
-+ else
-+ sql("INSERT INTO recordings values ('', '__invalid', 'install done', '')");
-+ print("AFTE2\n");
-+
- $dh = opendir($recordings_directory);
- while (false !== ($file = readdir($dh))) { // http://au3.php.net/readdir
- if ($file[0] != "." && $file != "CVS" && $file != "svn" && !is_dir("$recordings_directory/$file")) {
-@@ -59,10 +72,14 @@
-
- // Upgrade to recordings 3.0
- // Change filename from VARCHAR(80) to BLOB
--$sql = 'ALTER TABLE recordings CHANGE filename filename BLOB';
--$result = $db->query($sql);
--if(DB::IsError($result)) {
-- die_freepbx($result->getDebugInfo());
-+// Note sqlite3 doesn't support ALTER
-+
-+if ($amp_conf["AMPDBENGINE"] != 'sqlite3') {
-+ $sql = 'ALTER TABLE recordings CHANGE filename filename BLOB';
-+ $result = $db->query($sql);
-+ if(DB::IsError($result)) {
-+ die_freepbx($result->getDebugInfo());
-+ }
- }
-
- ?>
---- freepbx-2.4.0-orig//amp_conf/bin/retrieve_conf 2007-12-15 08:18:39.000000000 +1030
-+++ freepbx-2.4.0//amp_conf/bin/retrieve_conf 2008-03-08 10:05:28.000000000 +1030
-@@ -10,7 +10,7 @@
-
- ini_set('error_reporting', E_ALL & ~E_NOTICE);
-
--define("AMP_CONF", "/etc/amportal.conf");
-+define("AMP_CONF", "/etc/amportal.conf");
- $amportalconf = AMP_CONF;
-
- //define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
-@@ -272,8 +272,6 @@
- fatal(_("database connection failure"),("failed trying to connect to the configured database"));
-
- }
--out(_("OK"));
--
-
- //TODO : make this engine-neutral
- outn(_("Connecting to Asterisk manager interface.."));
-@@ -284,7 +282,6 @@
- out(_("FAILED"));
- fatal(_("Asterisk Manager Connection Failure"),sprintf(_("Failed to connect to the Asterisk manager through port: %s"), $amp_conf['ASTMANAGERPORT']));
- }
--out(_("OK"));
-
- //include common functions
- require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
-@@ -293,7 +290,7 @@
- // query for our modules
- // var_dump( $db );
- $modules = module_getinfo();
--
-+out(_("DR-BBB"));
- //Putting the core module last, to move outbound-allroutes
- // last in from-internals-additional
- if (array_key_exists('core', $modules)) {
-@@ -671,8 +668,11 @@
-
- // script to write op_server.cfg file from mysql
- //
--$script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.pl '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
--exec($script);
-+if ($amp_conf["AMPDBENGINE"] != 'sqlite3') {
-+ // sqlite3 not supported just yet
-+ $script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.pl '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
-+ exec($script);
-+}
-
- // generate configuration files
- //
-@@ -684,10 +684,7 @@
- generate_configurations_iax($version);
- generate_configurations_zap($version);
- }
--if (!isset($queues_conf) || !is_a($queues_conf, "queues_conf")) {
-- generate_configurations_queues($version);
--}
--
-+
- // Check and install the freepbx-cron-scheduler.php manager
- //
- install_cron_scheduler();
---- freepbx-2.4.0-orig//amp_conf/astetc/manager.conf 2006-05-01 11:39:24.000000000 +0930
-+++ freepbx-2.4.0//amp_conf/astetc/manager.conf 2008-03-08 10:05:24.000000000 +1030
-@@ -6,8 +6,8 @@
- port = 5038
- bindaddr = 0.0.0.0
-
--[AMPMGRUSER]
--secret = AMPMGRPASS
-+[admin]
-+secret = amp111
- deny=0.0.0.0/0.0.0.0
- permit=127.0.0.1/255.255.255.0
- read = system,call,log,verbose,command,agent,user
---- freepbx-2.4.0-orig//amp_conf/htdocs/admin/config.php 2007-12-02 18:06:31.000000000 +1030
-+++ root/www/admin/config.php 2008-03-11 13:22:34.000000000 +1030
-@@ -39,7 +39,9 @@
- /** AJAX handler for reload event
- */
- include_once('common/json.inc.php');
-- $response = do_reload();
-+ // DR: include as global code
-+ include_once('do_reload.php');
-+ //$response = do_reload();
- $json = new Services_JSON();
- echo $json->encode($response);
- break;