diff -Nur --no-dereference smeserver-freepbx-14.old/root/etc/e-smith/events/actions/freepbx-backup smeserver-freepbx-14/root/etc/e-smith/events/actions/freepbx-backup --- smeserver-freepbx-14.old/root/etc/e-smith/events/actions/freepbx-backup 2022-12-13 01:07:25.747000000 -0500 +++ smeserver-freepbx-14/root/etc/e-smith/events/actions/freepbx-backup 2022-12-13 01:15:52.204000000 -0500 @@ -1,3 +1,20 @@ #!/bin/bash -su asterisk -s /bin/bash -c '/usr/sbin/php /var/lib/asterisk/bin/backup.php --id=1' +#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 diff -Nur --no-dereference smeserver-freepbx-14.old/root/etc/e-smith/events/actions/freepbx-checkinstall smeserver-freepbx-14/root/etc/e-smith/events/actions/freepbx-checkinstall --- smeserver-freepbx-14.old/root/etc/e-smith/events/actions/freepbx-checkinstall 2022-12-13 01:07:25.743000000 -0500 +++ smeserver-freepbx-14/root/etc/e-smith/events/actions/freepbx-checkinstall 2022-12-13 01:42:25.665000000 -0500 @@ -88,9 +88,26 @@ 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="/usr/bin/php74" +if [[ $version -ge 16 ]] +then + php="/usr/bin/php80" +elif [[ $version -lt 15 ]] +then + php="/usr/bin/php56" +fi +ln -sf $php /usr/sbin/php + + # update modules -/usr/sbin/fwconsole ma upgrade framework -/usr/sbin/fwconsole ma upgradeall -R standard -R extended -/usr/sbin/fwconsole ma refreshsignatures -/usr/sbin/fwconsole ma downloadinstall userman certman ucp +/usr/sbin/e-smith/fwconsole ma upgrade framework +/usr/sbin/e-smith/fwconsole ma upgradeall -R standard -R extended +/usr/sbin/e-smith/fwconsole ma refreshsignatures +/usr/sbin/e-smith/fwconsole ma downloadinstall userman certman +/usr/sbin/e-smith/fwconsole ma downloadinstall ucp 2>/dev/null + exit 0 diff -Nur --no-dereference smeserver-freepbx-14.old/root/etc/e-smith/events/actions/freepbx-checkinstall-backup smeserver-freepbx-14/root/etc/e-smith/events/actions/freepbx-checkinstall-backup --- smeserver-freepbx-14.old/root/etc/e-smith/events/actions/freepbx-checkinstall-backup 2022-12-13 01:07:25.747000000 -0500 +++ smeserver-freepbx-14/root/etc/e-smith/events/actions/freepbx-checkinstall-backup 2022-12-13 01:15:45.666000000 -0500 @@ -19,44 +19,182 @@ /bin/mkdir -p $backuppath fi -# 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\` ;" +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" + + ##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);" + +else + # 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 diff -Nur --no-dereference smeserver-freepbx-14.old/root/sbin/e-smith/fwconsole smeserver-freepbx-14/root/sbin/e-smith/fwconsole --- smeserver-freepbx-14.old/root/sbin/e-smith/fwconsole 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-freepbx-14/root/sbin/e-smith/fwconsole 2022-12-13 01:40:13.673000000 -0500 @@ -0,0 +1,12 @@ +#!/bin/bash +version=$(/usr/bin/xmllint --xpath 'string(/module/version)' /opt/freepbx/admin/modules/core/module.xml|cut -d. -f1) +php="/usr/bin/php74" +if [[ $version -ge 16 ]] +then + php="/usr/bin/php80" +elif [[ $version -lt 15 ]] +then + php="/usr/bin/php56" +fi + +$php --define sys_temp_dir=/var/spool/asterisk/tmp/ --define allow_url_fopen=1 /var/lib/asterisk/bin/fwconsole $@