diff --git a/install/froxlor.sql.php b/install/froxlor.sql.php index cd6e0bdb..1b5e4ea6 100644 --- a/install/froxlor.sql.php +++ b/install/froxlor.sql.php @@ -223,6 +223,8 @@ CREATE TABLE `panel_customers` ( `api_allowed` tinyint(1) NOT NULL default '1', `logviewenabled` tinyint(1) NOT NULL default '0', `allowed_mysqlserver` text NOT NULL, + `backup` int(11) NOT NULL default '1', + `access_backups` tinyint(1) NOT NULL default '1', PRIMARY KEY (`customerid`), UNIQUE KEY `loginname` (`loginname`) ) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC; @@ -1063,6 +1065,7 @@ CREATE TABLE `panel_usercolumns` ( KEY customerid (customerid) ) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci; + DROP TABLE IF EXISTS `panel_loginlinks`; CREATE TABLE `panel_loginlinks` ( `hash` varchar(500) NOT NULL, @@ -1072,6 +1075,27 @@ CREATE TABLE `panel_loginlinks` ( UNIQUE KEY `loginname` (`loginname`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; + +DROP TABLE IF EXISTS `panel_backup_storages`; +CREATE TABLE `panel_backup_storages` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(255) NOT NULL, + `type` varchar(255) NOT NULL DEFAULT 'local', + `region` varchar(255) NULL, + `bucket` varchar(255) NULL, + `destination_path` varchar(255) NOT NULL, + `hostname` varchar(255) NULL, + `username` varchar(255) NULL, + `password` varchar(255) NULL, + `pgp_public_key` varchar(255) NULL, + `retention` int(3) NOT NULL DEFAULT 3, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; + +INSERT INTO `panel_backup_storages` (`id`, `description`, `destination_path`) VALUES + (1, 'Local backup storage', '/var/customers/backups'); + + DROP TABLE IF EXISTS `panel_backups`; CREATE TABLE `panel_backups` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -1079,6 +1103,8 @@ CREATE TABLE `panel_backups` ( `customerid` int(11) NOT NULL, `loginname` varchar(255) NOT NULL, `size` bigint(20) NOT NULL, + `storage_id` int(11) NOT NULL, + `filename` varchar(255) NOT NULL, `created_at` int(15) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; diff --git a/install/updates/froxlor/update_2.x.inc.php b/install/updates/froxlor/update_2.0.inc.php similarity index 86% rename from install/updates/froxlor/update_2.x.inc.php rename to install/updates/froxlor/update_2.0.inc.php index fd0d1217..7e3541df 100644 --- a/install/updates/froxlor/update_2.x.inc.php +++ b/install/updates/froxlor/update_2.0.inc.php @@ -497,86 +497,3 @@ if (Froxlor::isFroxlorVersion('2.0.19')) { Update::showUpdateStep("Updating from 2.0.19 to 2.0.20", false); Froxlor::updateToVersion('2.0.20'); } - -if (Froxlor::isDatabaseVersion('202304260')) { - Update::showUpdateStep("Cleaning domains table"); - Database::query("ALTER TABLE `" . TABLE_PANEL_DOMAINS . "` DROP COLUMN `ismainbutsubto`;"); - Update::lastStepStatus(0); - - Update::showUpdateStep("Creating new tables and fields"); - Database::query("DROP TABLE IF EXISTS `panel_loginlinks`;"); - $sql = "CREATE TABLE `panel_loginlinks` ( - `hash` varchar(500) NOT NULL, - `loginname` varchar(50) NOT NULL, - `valid_until` int(15) NOT NULL, - `allowed_from` text NOT NULL, - UNIQUE KEY `loginname` (`loginname`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; - Database::query($sql); - Update::lastStepStatus(0); - - Update::showUpdateStep("Adjusting setting for deactivated webroot"); - $current_deactivated_webroot = Settings::Get('system.deactivateddocroot'); - if (empty($current_deactivated_webroot)) { - Settings::Set('system.deactivateddocroot', FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/templates/misc/deactivated/')); - Update::lastStepStatus(0); - } else { - Update::lastStepStatus(1, 'Customized setting, not changing'); - } - - Update::showUpdateStep("Creating new tables and fields for backups"); - Database::query("DROP TABLE IF EXISTS `panel_backups`;"); - $sql = "CREATE TABLE `panel_backups` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `adminid` int(11) NOT NULL, - `customerid` int(11) NOT NULL, - `loginname` varchar(255) NOT NULL, - `size` bigint(20) NOT NULL, - `created_at` int(15) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; - Database::query($sql); - Update::lastStepStatus(0); - - Update::showUpdateStep("Adding new backup settings"); - Settings::AddNew('backup.enabled', 0); - Settings::AddNew('backup.type', 'Local'); - Settings::AddNew('backup.region', ''); - Settings::AddNew('backup.bucket', ''); - Settings::AddNew('backup.destination_path', '/srv/backups/'); - Settings::AddNew('backup.hostname', ''); - Settings::AddNew('backup.username', ''); - Settings::AddNew('backup.password', ''); - Settings::AddNew('backup.pgp_public_key', ''); - Settings::AddNew('backup.retention', 3); - Update::lastStepStatus(0); - - Update::showUpdateStep("Adjusting cronjobs"); - Database::query(" - UPDATE `" . TABLE_PANEL_CRONRUNS . "` SET - `module`= 'froxlor/export', - `cronfile` = 'export', - `cronclass` = '\\Froxlor\\Cron\\System\\ExportCron', - `desc_lng_key` = 'cron_export' - WHERE `module` = 'froxlor/backup' - "); - Database::query(" - INSERT INTO `" . TABLE_PANEL_CRONRUNS . "` SET - `module`= 'froxlor/backup', - `cronfile` = 'backup', - `cronclass` = '\\Froxlor\\Cron\\Backup\\BackupCron', - `interval` = '1 DAY', - `isactive` = '0', - `desc_lng_key` = 'cron_backup' - "); - Update::lastStepStatus(0); - - Update::showUpdateStep("Adjusting system for data-export function"); - Database::query("UPDATE `" . TABLE_PANEL_SETTINGS . "`SET `varname` = 'exportenabled' WHERE `settinggroup`= 'system' AND `varname`= 'backupenabled"); - Database::query("UPDATE `" . TABLE_PANEL_SETTINGS . "`SET `value` = REPLACE(`value`, 'extras.backup', 'extras.export') WHERE `settinggroup` = 'panel' AND `varname` = 'customer_hide_options'"); - Database::query("DELETE FROM `" . TABLE_PANEL_USERCOLUMNS . "` WHERE `section` = 'backup_list'"); - Database::query("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20'"); - Update::lastStepStatus(0); - - Froxlor::updateToDbVersion('202305240'); -} diff --git a/install/updates/froxlor/update_2.1.inc.php b/install/updates/froxlor/update_2.1.inc.php new file mode 100644 index 00000000..6d304094 --- /dev/null +++ b/install/updates/froxlor/update_2.1.inc.php @@ -0,0 +1,138 @@ + + * @license https://files.froxlor.org/misc/COPYING.txt GPLv2 + */ + +use Froxlor\Database\Database; +use Froxlor\FileDir; +use Froxlor\Froxlor; +use Froxlor\Install\Update; +use Froxlor\Settings; + +if (!defined('_CRON_UPDATE')) { + if (!defined('AREA') || (defined('AREA') && AREA != 'admin') || !isset($userinfo['loginname']) || (isset($userinfo['loginname']) && $userinfo['loginname'] == '')) { + header('Location: ../../../../index.php'); + exit(); + } +} + +if (Froxlor::isDatabaseVersion('202304260')) { + Update::showUpdateStep("Cleaning domains table"); + Database::query("ALTER TABLE `" . TABLE_PANEL_DOMAINS . "` DROP COLUMN `ismainbutsubto`;"); + Update::lastStepStatus(0); + + Update::showUpdateStep("Creating new tables and fields"); + Database::query("DROP TABLE IF EXISTS `panel_loginlinks`;"); + $sql = "CREATE TABLE `panel_loginlinks` ( + `hash` varchar(500) NOT NULL, + `loginname` varchar(50) NOT NULL, + `valid_until` int(15) NOT NULL, + `allowed_from` text NOT NULL, + UNIQUE KEY `loginname` (`loginname`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; + Database::query($sql); + Update::lastStepStatus(0); + + Update::showUpdateStep("Adjusting setting for deactivated webroot"); + $current_deactivated_webroot = Settings::Get('system.deactivateddocroot'); + if (empty($current_deactivated_webroot)) { + Settings::Set('system.deactivateddocroot', FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/templates/misc/deactivated/')); + Update::lastStepStatus(0); + } else { + Update::lastStepStatus(1, 'Customized setting, not changing'); + } + + Update::showUpdateStep("Creating new tables and fields for backups"); + Database::query("DROP TABLE IF EXISTS `panel_backup_storages`;"); + $sql = "CREATE TABLE `panel_backup_storages` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(255) NOT NULL, + `type` varchar(255) NOT NULL DEFAULT 'local', + `region` varchar(255) NULL, + `bucket` varchar(255) NULL, + `destination_path` varchar(255) NOT NULL, + `hostname` varchar(255) NULL, + `username` varchar(255) NULL, + `password` varchar(255) NULL, + `pgp_public_key` varchar(255) NULL, + `retention` int(3) NOT NULL DEFAULT 3, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; + Database::query($sql); + Database::query(" + INSERT INTO `panel_backup_storages` (`id`, `description`, `destination_path`) VALUES + (1, 'Local backup storage', '/var/customers/backups'); + "); + Database::query("DROP TABLE IF EXISTS `panel_backups`;"); + $sql = "CREATE TABLE `panel_backups` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `adminid` int(11) NOT NULL, + `customerid` int(11) NOT NULL, + `loginname` varchar(255) NOT NULL, + `size` bigint(20) NOT NULL, + `storage_id` int(11) NOT NULL, + `filename` varchar(255) NOT NULL, + `created_at` int(15) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; + Database::query($sql); + // add customer backup-target-storage + Database::query("ALTER TABLE `" . TABLE_PANEL_CUSTOMERS . "` ADD `backup` int(11) NOT NULL default '1' AFTER `allowed_mysqlserver`;"); + Database::query("ALTER TABLE `" . TABLE_PANEL_CUSTOMERS . "` ADD `access_backups` tinyint(1) NOT NULL default '1' AFTER `backup`;"); + Update::lastStepStatus(0); + + Update::showUpdateStep("Adding new backup settings"); + Settings::AddNew('backup.enabled', 0); + Settings::AddNew('backup.default_storage', 1); + Settings::AddNew('backup.default_customer_access', 1); + Update::lastStepStatus(0); + + Update::showUpdateStep("Adjusting cronjobs"); + Database::query(" + UPDATE `" . TABLE_PANEL_CRONRUNS . "` SET + `module`= 'froxlor/export', + `cronfile` = 'export', + `cronclass` = '\\Froxlor\\Cron\\System\\ExportCron', + `desc_lng_key` = 'cron_export' + WHERE `module` = 'froxlor/backup' + "); + Database::query(" + INSERT INTO `" . TABLE_PANEL_CRONRUNS . "` SET + `module`= 'froxlor/backup', + `cronfile` = 'backup', + `cronclass` = '\\Froxlor\\Cron\\Backup\\BackupCron', + `interval` = '1 DAY', + `isactive` = '0', + `desc_lng_key` = 'cron_backup' + "); + Update::lastStepStatus(0); + + Update::showUpdateStep("Adjusting system for data-export function"); + Database::query("UPDATE `" . TABLE_PANEL_SETTINGS . "`SET `varname` = 'exportenabled' WHERE `settinggroup`= 'system' AND `varname`= 'backupenabled"); + Database::query("UPDATE `" . TABLE_PANEL_SETTINGS . "`SET `value` = REPLACE(`value`, 'extras.backup', 'extras.export') WHERE `settinggroup` = 'panel' AND `varname` = 'customer_hide_options'"); + Database::query("DELETE FROM `" . TABLE_PANEL_USERCOLUMNS . "` WHERE `section` = 'backup_list'"); + Database::query("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20'"); + Update::lastStepStatus(0); + + Froxlor::updateToDbVersion('202305240'); +} diff --git a/install/updates/preconfig/preconfig_2.x.inc.php b/install/updates/preconfig/preconfig_2.0.inc.php similarity index 99% rename from install/updates/preconfig/preconfig_2.x.inc.php rename to install/updates/preconfig/preconfig_2.0.inc.php index 5eb3d97d..6dd0dc33 100644 --- a/install/updates/preconfig/preconfig_2.x.inc.php +++ b/install/updates/preconfig/preconfig_2.0.inc.php @@ -30,7 +30,7 @@ use Froxlor\Install\Update; use Froxlor\Settings; $preconfig = [ - 'title' => '2.x updates', + 'title' => '2.0.x updates', 'fields' => [] ]; $return = []; diff --git a/install/updates/preconfig/preconfig_2.1.inc.php b/install/updates/preconfig/preconfig_2.1.inc.php new file mode 100644 index 00000000..88529296 --- /dev/null +++ b/install/updates/preconfig/preconfig_2.1.inc.php @@ -0,0 +1,43 @@ + + * @license https://files.froxlor.org/misc/COPYING.txt GPLv2 + */ + +use Froxlor\Froxlor; +use Froxlor\FileDir; +use Froxlor\Config\ConfigParser; +use Froxlor\Install\Update; +use Froxlor\Settings; + +$preconfig = [ + 'title' => '2.1.x updates', + 'fields' => [] +]; +$return = []; + +if (Update::versionInUpdate($current_version, '2.1.0-dev1')) { + +} + +$preconfig['fields'] = $return; +return $preconfig; diff --git a/install/updatesql.php b/install/updatesql.php index f759d159..47b45a44 100644 --- a/install/updatesql.php +++ b/install/updatesql.php @@ -53,7 +53,8 @@ try { if (Froxlor::isFroxlor()) { include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/update_0.10.inc.php')); - include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/update_2.x.inc.php')); + include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/update_2.0.inc.php')); + include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/update_2.1.inc.php')); // Check Froxlor - database integrity (only happens after all updates are done, so we know the db-layout is okay) Update::showUpdateStep("Checking database integrity"); diff --git a/lib/Froxlor/Cron/Backup/BackupCron.php b/lib/Froxlor/Cron/Backup/BackupCron.php index 248cbe34..cd162e58 100644 --- a/lib/Froxlor/Cron/Backup/BackupCron.php +++ b/lib/Froxlor/Cron/Backup/BackupCron.php @@ -48,14 +48,14 @@ class BackupCron extends FroxlorCron ]); } - private static function handle($user, $data) + private static function handle(array $userdata) { - echo "BackupCron: started - creating customer backup for user $user\n"; + echo "BackupCron: started - creating customer backup for user " . $userdata['user'] . "\n"; - echo $data . "\n"; + echo $userdata['data'] . "\n"; sleep(rand(1, 3)); - echo "BackupCron: finished - creating customer backup for user $user\n"; + echo "BackupCron: finished - creating customer backup for user " . $userdata['user'] . "\n"; } }