initial commit of file from CVS for smeserver-freepbx on Sat Sep 7 20:25:35 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:25:35 +10:00
parent bd24175623
commit 190a3e0d7a
80 changed files with 3092 additions and 2 deletions

View File

@@ -0,0 +1,33 @@
#!/bin/bash
version=$(/usr/bin/xmllint --xpath 'string(/module/version)' /opt/freepbx/admin/modules/core/module.xml|cut -d. -f1)
if [[ $version -ge 15 ]] ; then
fwconsole="/sbin/e-smith/fwconsole"
$fwconsole setting DISABLE_CSS_AUTOGEN 1
$fwconsole setting CHECKREFERER 0
$fwconsole setting AUTHTYPE none
$fwconsole setting AMPWEBROOT /opt/freepbx
$fwconsole setting MODULEADMINWGET 1
$fwconsole setting DYNAMICHINTS 1
$fwconsole setting ARI_ADMIN_PASSWORD $(/sbin/e-smith/db configuration getprop freepbx AriPassword) 2>/dev/null 1>&2
$fwconsole setting AMPMGRPASS $(/sbin/e-smith/db configuration getprop freepbx ManagerPassword)
$fwconsole setting RSSFEEDS 'http://www.freepbx.org/rss.xml'
$fwconsole setting BRAND_FREEPBX_ALT_FOOT FreePBX
else
# Change FreePBX database settings that should have come from /etc/amportal.conf,
# this is a dynamic template for FreePBX > 1.9 as it update the file on the fly, and also the db
FPBX_SETTING_PATH="/var/lib/asterisk/bin/freepbx_setting"
$FPBX_SETTING_PATH DISABLE_CSS_AUTOGEN 1
$FPBX_SETTING_PATH CHECKREFERER 0
$FPBX_SETTING_PATH AUTHTYPE none
$FPBX_SETTING_PATH AMPWEBROOT /opt/freepbx
$FPBX_SETTING_PATH MODULEADMINWGET 1
$FPBX_SETTING_PATH DYNAMICHINTS 1
$FPBX_SETTING_PATH ARI_ADMIN_PASSWORD $(/sbin/e-smith/db configuration getprop freepbx AriPassword)
$FPBX_SETTING_PATH AMPMGRPASS $(/sbin/e-smith/db configuration getprop freepbx ManagerPassword)
$FPBX_SETTING_PATH RSSFEEDS 'http://www.freepbx.org/rss.xml'
$FPBX_SETTING_PATH BRAND_FREEPBX_ALT_FOOT FreePBX
fi
# now regenrate the amportal.conf from mysql
/sbin/e-smith/fwconsole r

View File

@@ -0,0 +1,20 @@
#!/bin/bash
#version
version=$(/usr/bin/xmllint --xpath 'string(/module/version)' /opt/freepbx/admin/modules/backup/module.xml|cut -d. -f1)
#if version >=15
if [[ $version -ge 15 ]]
then
#backup id SELECT `id` FROM `kvstore_FreePBX_modules_Backup` WHERE `key` LIKE 'backup_name' and `val` LIKE 'Default-backup';
backupid=$(echo 'SELECT `id` FROM `kvstore_FreePBX_modules_Backup` WHERE `key` LIKE "backup_name" and `val` LIKE "Default-backup"'| mysql -u root freepbxdb -s)
#if backupid empty need to set one of manually backup something
if [ -z $backupid ] ; then
echo "missing backupid, we create the db entries"
/etc/e-smith/events/actions/freepbx-checkinstall-backup pre-backup
fi
echo "backup for freepbx version 15 or above"
/usr/sbin/fwconsole bu --backup $backupid 1>/dev/null
else
echo "backup for freepbx version 14 or below"
su asterisk -s /bin/bash -c '/usr/sbin/php56 /var/lib/asterisk/bin/backup.php --id=1'
fi

View File

@@ -0,0 +1,130 @@
#!/bin/bash
DBNAME=$(/sbin/e-smith/db configuration getprop freepbx DbName)
DBUSER=$(/sbin/e-smith/db configuration getprop freepbx DbUser)
DBPASS=$(/sbin/e-smith/db configuration getprop freepbx DbPassword)
CDRDBNAME=$(/sbin/e-smith/db configuration getprop freepbx CdrDbName)
MANAGERPASSWORD=$(/sbin/e-smith/db configuration getprop freepbx ManagerPassword)
DomainName=$(/sbin/e-smith/db configuration get DomainName)
if [ $(mysqlshow | grep -c $DBNAME) -lt 1 ]; then
mysql -e "create database $DBNAME CHARACTER SET utf8 COLLATE utf8_unicode_ci ;"
mysql -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASS';"
mysql -e 'flush privileges;'
if [ -e /usr/share/freepbx/sql/asterisk.sql ]; then
mysql $DBNAME < /usr/share/freepbx/sql/asterisk.sql
else
echo "Error: file /usr/share/freepbx/sql/asterisk.sql doesn't exists"
exit 1
fi
fi
if [ $(mysqlshow | grep -c $CDRDBNAME) -lt 1 ]; then
mysql -e "create database $CDRDBNAME CHARACTER SET utf8 COLLATE utf8_unicode_ci ;"
mysql -e "grant all privileges on $CDRDBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASS';"
mysql -e 'flush privileges;'
if [ -e /usr/share/freepbx/sources/freepbx/installlib/SQL/cdr.sql ]; then
mysql $CDRDBNAME < /usr/share/freepbx/sources/freepbx/installlib/SQL/cdr.sql
else
echo "Error: file /usr/share/freepbx/sources/freepbx/installlib/SQL/cdr.sql doesn't exists"
exit 1
fi
fi
# set user and passwords
/usr/bin/mysql $DBNAME -e "INSERT INTO \`admin\` (\`variable\`, \`value\`) VALUES ('email', 'admin\@$DomainName') ON DUPLICATE KEY UPDATE \`value\` = 'admin\@$DomainName';"
/usr/bin/mysql $DBNAME -e "INSERT INTO \`ampusers\` (\`username\`, \`password_sha1\`, \`extension_low\`, \`extension_high\`, \`deptname\`, \`sections\`) VALUES
('admin', sha1('$MANAGERPASSWORD '), '', '', '', 0x2a) ON DUPLICATE KEY UPDATE \`password_sha1\` = sha1('$ManagerPassword ');"
# Chown dir to allow user asterisk to create its files
chown asterisk:asterisk /var/lib/asterisk
# workaround as freepbx is expecting them in /var not /usr/share
cd /var/lib/asterisk
if [[ ! -d /var/lib/asterisk/documentation ]]; then ln -s /usr/share/asterisk/documentation ; fi
if [[ ! -d /var/lib/asterisk/moh ]]; then ln -s /usr/share/asterisk/moh ; fi
if [[ ! -d /var/lib/asterisk/sounds ]]; then ln -s /usr/share/asterisk/sounds/ ; fi
mkdir -p /usr/share/asterisk/sounds/tmp
chown asterisk: /usr/share/asterisk/sounds/tmp
chown asterisk: /usr/share/asterisk/sounds/ /usr/share/asterisk/moh
# Run the install script only if it's a new install
# Upgrades have to be done through freePBX and the online repository
if [ ! -d /opt/freepbx/admin ]; then
mkdir -p /opt/freepbx
# we need the right php version available
version=$(/usr/bin/rpm -q freepbx-src --qf "%{version}"|cut -d. -f1)
php="/usr/bin/php56"
if [[ $version -ge 16 ]]
then
php="/usr/bin/php74"
elif [[ $version -le 15 ]]
then
php="/usr/bin/php56"
fi
ln -sf $php /usr/sbin/php
ln -sf $php /usr/local/sbin/php
if [ -e /usr/share/freepbx/sources/freepbx/ ]; then
cd /usr/share/freepbx/sources/freepbx/
echo "Starting Asterisk..." > /root/freepbx_install.log
./start_asterisk start >> /root/freepbx_install.log 2>&1
echo "" >> /root/freepbx_install.log
echo "Installing FreePBX..." >> /root/freepbx_install.log
echo "a" |$php --define sys_temp_dir=/var/spool/asterisk/tmp/ --define allow_url_fopen=1 --define memory_limit=256M /usr/share/freepbx/sources/freepbx/install --webroot="/opt/freepbx" \
--dbengine="mysql" --dbname="freepbxdb" --dbuser="freepbxuser" --dbpass="$DBPASS" -n \
--cdrdbname="$CDRDBNAME" --astmoddir=/usr/lib64/asterisk/modules/ \
--astagidir=/usr/share/asterisk/agi-bin/ --ampsbin=/usr/sbin --ampcgibin=/opt/freepbx/cgi-bin \
>> /root/freepbx_install.log 2>&1
else
echo "error: /usr/share/freepbx/sources/freepbx/ doesn't exists"
exit 1
fi
else
if [ -x /var/lib/asterisk/bin/freepbx_engine ]; then
/var/lib/asterisk/bin/freepbx_engine chown > /dev/null 2>&1
else
echo "error: /var/lib/asterisk/bin/freepbx_engine is not executable"
exit 1
fi
if [ -x /var/lib/asterisk/bin/retrieve_conf ]; then
/var/lib/asterisk/bin/retrieve_conf > /dev/null 2>&1
else
echo "error: /var/lib/asterisk/bin/freepbx_engine is not executable"
exit 1
fi
fi
if [ ! -d /opt/freepbx/digium_phones ]; then
mkdir -p /opt/freepbx/digium_phones
chown asterisk:asterisk /opt/freepbx/digium_phones
fi
#change the links to get the right php
ln -sf /usr/sbin/e-smith/fwconsole /usr/sbin/fwconsole
ln -sf /usr/sbin/e-smith/fwconsole /usr/local/sbin/fwconsole
version=$(/usr/bin/xmllint --xpath 'string(/module/version)' /opt/freepbx/admin/modules/core/module.xml|cut -d. -f1)
php="56"
if [[ $version -ge 16 ]]
then
#version we have is not fully compatible, need newer source
php="74"
elif [[ $version -le 15 ]]
then
php="56"
fi
forcephp=$(/sbin/e-smith/db configuration getprop freepbx PHPVersion 2>/dev/null || echo $php )
php=$forcephp
ln -sf /usr/bin/php$php /usr/sbin/php
ln -sf /usr/bin/php$php /usr/local/sbin/php
# update modules
/usr/sbin/e-smith/fwconsole ma upgrade framework 2>/dev/null
/usr/sbin/e-smith/fwconsole ma upgrade core 2>/dev/null
/usr/sbin/e-smith/fwconsole ma upgradeall -R standard -R extended 2>/dev/null
/usr/sbin/e-smith/fwconsole ma refreshsignatures 2>/dev/null
/usr/sbin/e-smith/fwconsole ma downloadinstall userman certman arimanager 2>/dev/null
/usr/sbin/e-smith/fwconsole ma downloadinstall ucp 2>/dev/null
exit 0

View File

@@ -0,0 +1,211 @@
#!/bin/sh
DBNAME=$(/sbin/e-smith/db configuration getprop freepbx DbName)
backuppath='/home/e-smith/files/freepbx'
# check if backup module is local, enabled and running
# if not solve this...
if [[ ! `/usr/sbin/fwconsole ma list|/bin/grep backup` ]] ;then
/usr/sbin/fwconsole ma download backup -R standard -R extended >/dev/null 2>&1
fi
#force install
/usr/sbin/fwconsole ma install backup -R standard -R extended >/dev/null 2>&1
# force enable
/usr/sbin/fwconsole ma enable backup >/dev/null 2>&1
/usr/sbin/fwconsole r >/dev/null
# check our freepbx backup folder is there and accessible
if [[ ! -d $backuppath ]] ; then
/bin/mkdir -p $backuppath
fi
version=$(/usr/bin/xmllint --xpath 'string(/module/version)' /opt/freepbx/admin/modules/backup/module.xml|cut -d. -f1)
#if version >=15
if [[ $version -ge 15 ]]
then
############
# FILE STORE
############
# check local space is defined, if not do it kvstore_FreePBX_modules_Filestore
filestore=$(echo 'SELECT `id` FROM `kvstore_FreePBX_modules_Filestore` WHERE `key` LIKE "path" and `val` LIKE "/home/e-smith/files/freepbx/"'| mysql -u root freepbxdb -s)
if [ -z $filestore ] ; then
filestore=$(/usr/bin/uuidgen)
echo "creating new filestore id $filestore"
else
echo "filestore $filestore will be used"
fi
# we need existing servers value to update it
servers=$(echo 'SELECT `val` FROM `kvstore_FreePBX_modules_Filestore` WHERE `key` LIKE "servers" and `id` LIKE "noid"'| mysql -u root freepbxdb -s)
servers=$(echo $servers| jq '. |= . + {"'$filestore'" : { "id": "'$filestore'","name": "Local Storage","desc": "Storage location for backups", "driver": "Local" }}')
mysql -e "use $DBNAME; INSERT INTO \`kvstore_FreePBX_modules_Filestore\` (\`key\`, \`val\`, \`type\`, \`id\`) VALUES
('servers', '$servers', 'json-arr', 'noid')
ON DUPLICATE KEY UPDATE val=VALUES(val);"
mysql -e "use $DBNAME; INSERT INTO \`kvstore_FreePBX_modules_Filestore\` (\`key\`, \`val\`, \`type\`, \`id\`) VALUES
('name', 'Local Storage', NULL, '$filestore'),
('desc', 'Storage location for backups', NULL, '$filestore'),
('path', '/home/e-smith/files/freepbx/', NULL, '$filestore'),
('immortal', 'true', NULL, '$filestore'),
('driver', 'Local', NULL, '$filestore')
ON DUPLICATE KEY UPDATE val=VALUES(val);"
###########
# BACKUP
###########
# check Default-backup exists, if not set it, else update it
backupid=$(echo 'SELECT `id` FROM `kvstore_FreePBX_modules_Backup` WHERE `key` LIKE "backup_name" and `val` LIKE "Default-backup"'| mysql -u root freepbxdb -s)
if [ -z $backupid ] ; then
backupid=$(/usr/bin/uuidgen)
echo "creating new backup id $backupid"
mysql -e "use $DBNAME; CREATE TABLE IF NOT EXISTS \`kvstore_FreePBX_modules_Backup\` (
\`key\` char(255) NOT NULL,
\`val\` varchar(4096) DEFAULT NULL,
\`type\` char(16) DEFAULT NULL,
\`id\` char(255) DEFAULT NULL,
UNIQUE KEY \`uniqueindex\` (\`key\`(190),\`id\`(190)),
KEY \`keyindex\` (\`key\`(190)),
KEY \`idindex\` (\`id\`(190))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
##TODO SELECT * FROM `kvblobstore` WHERE `uuid` LIKE 'a9fe727b-fc4c-40c4-ad45-bcabd075302a'
### TODO : list modules enabled and populate
blobstore=$(/usr/bin/uuidgen)
mysql -e "use $DBNAME;INSERT INTO kvstore_FreePBX_modules_Backup (\`key\`, \`val\`, \`type\`, \`id\`) VALUES
('backup_items', '$blobstore', 'blob', '$backupid')
ON DUPLICATE KEY UPDATE val=VALUES(val);"
# create an empty blob store, it seems to not be a problem to actually run the backup
mysql -e "use $DBNAME;INSERT INTO kvblobstore (\`uuid\`, \`type\`, \`content\`) VALUES
('$blobstore', NULL, '');" || exit 1
# we do this only if the other did not failed to avoid hitting one existing uuid
mysql -e "use $DBNAME;INSERT INTO kvstore_FreePBX_modules_Backup (\`key\`, \`val\`, \`type\`, \`id\`) VALUES
('backup_items', '$blobstore', 'blob', '$backupid')
ON DUPLICATE KEY UPDATE val=VALUES(val);"
else
echo "Updating backup $backupid"
fi
mysql -e "use $DBNAME;INSERT INTO kvstore_FreePBX_modules_Backup (\`key\`, \`val\`, \`type\`, \`id\`) VALUES
('backup_name', 'Default-backup', NULL, '$backupid'),
('backup_description', 'Default SME PBX backup; automatically installed', NULL, '$backupid'),
('backup_email', 'admin', NULL, '$backupid'),
('created_by', 'SME Server Event', NULL, '$backupid'),
('desc', 'Default SME PBX backup; automatically installed', NULL, '$backupid'),
('warmspare_remoteip', '', NULL, '$backupid'),
('warmspare_user', '', NULL, '$backupid'),
('maintruns', '2', NULL, '$backupid'),
('backup_emailtype', 'failure', NULL, '$backupid'),
('backup_schedule', '31 5 * * 0', NULL, '$backupid'),
('schedule_enabled', 'yes', NULL, '$backupid'),
('backup_storage', '[\\\"Local_$filestore\\\"]', 'json-arr', '$backupid'),
('backup_items', 'a9fe727b-fc4c-40c4-ad45-bcabd075302a', 'blob', '$backupid'),
('maintage', 'Unlimited', NULL, '$backupid'),
('backup_emailinline', '', NULL, '$backupid'),
('backup_addbjname', 'yes', NULL, '$backupid'),
('warmspareenabled', 'on', NULL, '$backupid'),
('warmspare_remotenat', 'on', NULL, '$backupid'),
('warmspare_cert', 'on', NULL, '$backupid'),
('warmspare_remotebind', 'on', NULL, '$backupid'),
('warmspare_remotedns', 'on', NULL, '$backupid'),
('warmspare_remoteapply', 'on', NULL, '$backupid'),
('publickey', '', NULL, '$backupid'),
('warmsparewayofrestore', 'API', NULL, '$backupid'),
('warmspare_remoteapi_filestoreid', '', NULL, '$backupid'),
('warmspare_remoteapi_accesstoken', '', NULL, '$backupid'),
('warmspare_remoteapi_accesstokenurl', '', NULL, '$backupid'),
('warmspare_remoteapi_accesstoken_expire', '', NULL, '$backupid'),
('warmspare_remoteapi_clientid', '', NULL, '$backupid'),
('warmspare_remoteapi_secret', '', NULL, '$backupid'),
('warmspare_remoteapi_gql', '', NULL, '$backupid'),
('warmspare_excludetrunks', 'on', NULL, '$backupid'),
('warmspare_remotessh_filestoreid', '', NULL, '$backupid'),
('custom_files', '[{\"type\":\"dir\",\"path\":\"__ASTETCDIR__\",\"exclude\":[]}]', NULL, '$backupid'),
('prebu_hook', '', NULL, '$backupid'),
('postbu_hook', '', NULL, '$backupid'),
('prere_hook', '', NULL, '$backupid'),
('postre_hook', '', NULL, '$backupid'),
('core_disabletrunks', '', NULL, '$backupid'),
('$backupid', '{\\\"id\\\":\\\"$backupid\\\",\\\"name\\\":\\\"Default-backup\\\",\\\"description\\\":\\\"Default SME PBX backup; automatically installed\\\"}', 'json-arr', 'backupList'),
('bu_1', '{\\\"id\\\":\\\"1\\\",\\\"name\\\":\\\"Default backup\\\",\\\"description\\\":\\\"Default SME PBX backup; automatically installed\\\",\\\"immortal\\\":\\\"true\\\",\\\"data\\\":{\\\"created_by\\\":\\\"install.php\\\",\\\"desc\\\":\\\"Default SME PBX backup; automatically installed\\\",\\\"cron_schedule\\\":\\\"weekly\\\",\\\"storage_servers\\\":[\\\"1\\\"],\\\"bu_server\\\":\\\"0\\\",\\\"delete_amount\\\":\\\"2\\\",\\\"delete_time_type\\\":\\\"days\\\",\\\"cron_random\\\":\\\"on\\\",\\\"cron_month\\\":\\\"\\\",\\\"cron_minute\\\":\\\"0\\\",\\\"cron_hour\\\":\\\"0\\\",\\\"cron_dow\\\":\\\"0\\\",\\\"cron_dom\\\":\\\"\\\",\\\"delete_time\\\":\\\"0\\\",\\\"email\\\":\\\"admin\\\",\\\"emailfailonly\\\":\\\"1\\\"},\\\"email\\\":\\\"admin\\\",\\\"uuid\\\":\\\"$backupid\\\",\\\"items\\\":[{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"mysql\\\",\\\"path\\\":\\\"server-2\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"astdb\\\",\\\"path\\\":\\\"astdb\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"dir\\\",\\\"path\\\":\\\"\\/etc\\/dahdi\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"dir\\\",\\\"path\\\":\\\"__ASTSPOOLDIR__\\/voicemail\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"mysql\\\",\\\"path\\\":\\\"server-3\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"dir\\\",\\\"path\\\":\\\"__ASTETCDIR__\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"dir\\\",\\\"path\\\":\\\"__AMPWEBROOT__\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"dir\\\",\\\"path\\\":\\\"__AMPBIN__\\\",\\\"exclude\\\":[]},{\\\"backup_id\\\":\\\"1\\\",\\\"type\\\":\\\"dir\\\",\\\"path\\\":\\\"\\/tftpboot\\\",\\\"exclude\\\":[]}]}', 'json-arr', 'migratedbackups'),
('arimanager', '1', NULL, 'modules_$backupid'),
('backup', '1', NULL, 'modules_$backupid'),
('blacklist', '1', NULL, 'modules_$backupid'),
('callrecording', '1', NULL, 'modules_$backupid'),
('cdr', '1', NULL, 'modules_$backupid'),
('cel', '1', NULL, 'modules_$backupid'),
('certman', '1', NULL, 'modules_$backupid'),
('cidlookup', '1', NULL, 'modules_$backupid'),
('conferences', '1', NULL, 'modules_$backupid'),
('core', '1', NULL, 'modules_$backupid'),
('customappsreg', '1', NULL, 'modules_$backupid'),
('dashboard', '1', NULL, 'modules_$backupid'),
('fax', '1', NULL, 'modules_$backupid'),
('filestore', '1', NULL, 'modules_$backupid'),
('findmefollow', '1', NULL, 'modules_$backupid'),
('framework', '1', NULL, 'modules_$backupid'),
('infoservices', '1', NULL, 'modules_$backupid'),
('ivr', '1', NULL, 'modules_$backupid'),
('languages', '1', NULL, 'modules_$backupid'),
('logfiles', '1', NULL, 'modules_$backupid'),
('manager', '1', NULL, 'modules_$backupid'),
('music', '1', NULL, 'modules_$backupid'),
('phonebook', '1', NULL, 'modules_$backupid'),
('pm2', '1', NULL, 'modules_$backupid'),
('recordings', '1', NULL, 'modules_$backupid'),
('ringgroups', '1', NULL, 'modules_$backupid'),
('sipsettings', '1', NULL, 'modules_$backupid'),
('soundlang', '1', NULL, 'modules_$backupid'),
('ucp', '1', NULL, 'modules_$backupid'),
('userman', '1', NULL, 'modules_$backupid'),
('voicemail', '1', NULL, 'modules_$backupid')
ON DUPLICATE KEY UPDATE val=VALUES(val);"
# TODO update
#mysql -e "use $DBNAME;INSERT INTO kvstore_FreePBX_modules_Backup (\`key\`, \`val\`, \`type\`, \`id\`) VALUES
#('backup_items', 'a9fe727b-fc4c-40c4-ad45-bcabd075302a', 'blob', '$backupid')
#ON DUPLICATE KEY UPDATE val=VALUES(val);"
elif [[ $version -lt 15 ]] ; then
# set first backup as the one for SME way
# set destination
mysql -e "use $DBNAME;UPDATE backup_server_details set value = '/home/e-smith/files/freepbx' WHERE server_id = 1;"
# set info for backup 1
#data = a:1:{s:10:"created_by";s:11:"install.php";}
mysql -e "use $DBNAME;INSERT INTO backup (\`id\`, \`name\`, \`description\` , \`immortal\` ,\`data\`, \`email\` ) VALUES (1, 'Default backup', 'Default SME PBX backup; automatically installed', 'true','', 'admin' ) ON DUPLICATE KEY UPDATE \`description\` = 'Default SME PBX backup; automatically installed', \`immortal\` = 'true', \`email\` = 'admin' , \`name\`= 'Default backup' ;" 2>/dev/null || mysql -e "use $DBNAME;INSERT INTO backup (\`id\`, \`name\`, \`emailaddr\` ) VALUES (1, 'SMEbackup', 'admin' ) ON DUPLICATE KEY UPDATE \`name\` = 'SMEbackup', \`emailaddr\` = 'admin' ;"
mysql -e "use $DBNAME;ALTER TABLE backup_details ADD UNIQUE uniq ( \`backup_id\` , \`key\` , \`index\` ) ;"
mysql -e "use $DBNAME;INSERT INTO backup_details (\`backup_id\`, \`key\`, \`index\`, \`value\`) VALUES
(1, 'delete_time_type', '', 'days'),
(1, 'delete_amount', '', '2'),
(1, 'desc', '', 'Default SME PBX backup; automatically installed'),
(1, 'cron_schedule', '', 'weekly'),
(1, 'cron_random', '', 'on'),
(1, 'cron_month', '', ''),
(1, 'cron_minute', '', '0'),
(1, 'cron_hour', '', '0'),
(1, 'cron_dow', '', '0'),
(1, 'cron_dom', '', ''),
(1, 'bu_server', '', '0'),
(1, 'delete_time', '', '0'),
(1, 'email', '', 'admin'),
(1, 'emailfailonly', '', '1'),
(1, 'storage_servers', '0', '1') ON DUPLICATE KEY UPDATE \`value\`=VALUES(\`value\`) ;"
mysql -e "use $DBNAME;ALTER TABLE backup_details DROP INDEX uniq;"
# set what to backup
mysql -e "use $DBNAME;ALTER TABLE backup_items ADD UNIQUE \`uniq\` ( \`backup_id\` , \`type\` , \`path\` ( 15 ) ) ;"
mysql -e "use freepbxdb;INSERT INTO backup_items (\`backup_id\`, \`type\`, \`path\`, \`exclude\`) VALUES
(1, 'dir', '/etc/dahdi', 'a:0:{}'),
(1, 'dir', '__ASTSPOOLDIR__/voicemail', 'a:0:{}'),
(1, 'mysql', 'server-2', 'a:0:{}'),
(1, 'astdb', 'astdb', 'a:0:{}'),
(1, 'mysql', 'server-3', 'a:0:{}'),
(1, 'dir', '__ASTETCDIR__', 'a:0:{}'),
(1, 'dir', '__AMPWEBROOT__', 'a:0:{}'),
(1, 'dir', '__AMPBIN__', 'a:0:{}'),
(1, 'dir', '/tftpboot', 'a:0:{}') ON DUPLICATE KEY UPDATE \`exclude\`=VALUES(\`exclude\`) ;";
mysql -e "use $DBNAME;ALTER TABLE backup_items DROP INDEX \`uniq\` ;"
fi
# make sure all perms are ok for backup
/usr/sbin/fwconsole chown > /dev/null 2>&1

View File

@@ -0,0 +1,20 @@
#/bin/bash
# Remove crontab entry automatically added by FreePBX
# as it generate an error (run as root before asterisk
# which means asterisk won't be allowed to open the debug
# file /tmp/freepbx_debug.log, and send a email to the admin
crontab -l > /tmp/freepbx_old_crontab
awk '$0!~/freepbx-cron-scheduler.php/ { print $0 }' /tmp/freepbx_old_crontab > /tmp/freepbx_new_crontab
crontab /tmp/freepbx_new_crontab
rm -f /tmp/freepbx_old_crontab
rm -f /tmp/freepbx_new_crontab
# Now change permissions on /tmp/freepbx_debug.log to be sure
# asterisk user has write permission
if [ -e /tmp/freepbx_debug.log ]; then
chown asterisk:asterisk /tmp/freepbx_debug.log
chmod 700 /tmp/freepbx_debug.log
fi

View File

@@ -0,0 +1,22 @@
#!/bin/bash
path='PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/root\/bin'
cronfile='/var/spool/cron/asterisk'
[ ! -f $cronfile ] && exit 0
status=$(/sbin/e-smith/config getprop freepbx status || echo "disabled")
# add PATH to fist line if not present; else update it
sed -i "1!b;s/^PATH.*/$path/; t; 1i $path" $cronfile
# remove any other occurence of PATH
sed -i "1p;t; /^PATH.*/d" $cronfile
# check if freepbx enabled
if [[ $status == "enabled" ]]; then
# if enabled uncomment
sed -ri 's/^#(\@[a-zA-Z]+ .*|[0-9*]+ [0-9*]+ [0-9*]+ [0-9*]+ [0-9*]+ .*)/\1/' $cronfile
else
# if disabled comment out
sed -ri 's/^(\@[a-zA-Z]+ .*|[0-9*]+ [0-9*]+ [0-9*]+ [0-9*]+ [0-9*]+ .*)/#\1/' $cronfile
fi
#remove any duplicate entry
awk '!x[$0]++' ${cronfile} >${cronfile}-tmp && cat ${cronfile}-tmp > ${cronfile} && rm -f ${cronfile}-tmp

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env php
<?php
// No use outputting anything, as env forces php headers to appear. Sigh.
function getconf($filename) {
$file = file($filename);
foreach ($file as $line) {
if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\%-]*)\"?\s*([;#].*)?/",$line,$matches)) {
$conf[ $matches[1] ] = $matches[2];
}
}
return $conf;
}
$amp_conf = getconf("/etc/amportal.conf");
// Start quickly.
$bootstrap_settings['freepbx_auth'] = false; // Just in case.
$restrict_mods = true; // Takes startup from 0.2 seconds to 0.07 seconds.
include '/etc/freepbx.conf';
$astman = new AGI_AsteriskManager();
if (! $res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
unset( $astman );
}
@mkdir("/home/e-smith/db/freepbx/");
$fh = fopen("/home/e-smith/db/freepbx/astdb.dump", "w");
$astdb = $astman->database_show();
foreach ($astdb as $key => $val) {
if ($key == "") { continue; }
if ($key == "Privilege") { continue; }
fwrite($fh, "[$key] [$val]\n");
}
fclose($fh);
?>