diff --git a/install/froxlor.sql.php b/install/froxlor.sql.php index e043f861..01f1d38d 100644 --- a/install/froxlor.sql.php +++ b/install/froxlor.sql.php @@ -700,6 +700,8 @@ opcache.validate_timestamps'), ('system', 'acmeshpath', '/root/.acme.sh/acme.sh'), ('system', 'distribution', ''), ('system', 'update_channel', 'stable'), + ('system', 'updatecheck_data', ''), + ('system', 'update_notify_last', '0.11.0-dev1'), ('api', 'enabled', '0'), ('2fa', 'enabled', '1'), ('panel', 'decimal_places', '4'), diff --git a/install/updates/froxlor/update_0.11.inc.php b/install/updates/froxlor/update_0.11.inc.php index fea8d799..5177e26b 100644 --- a/install/updates/froxlor/update_0.11.inc.php +++ b/install/updates/froxlor/update_0.11.inc.php @@ -37,7 +37,10 @@ if (!defined('_CRON_UPDATE')) { // last 0.10.x release if (Froxlor::isFroxlorVersion('0.10.99')) { - Update::showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false); + + $update_to = '0.11.0-dev1'; + + Update::showUpdateStep("Updating from 0.10.99 to ".$update_to, false); Update::showUpdateStep("Removing unused table"); Database::query("DROP TABLE IF EXISTS `panel_sessions`;"); @@ -134,6 +137,7 @@ if (Froxlor::isFroxlorVersion('0.10.99')) { Settings::AddNew("system.distribution", $system_distribution); Settings::AddNew("system.update_channel", 'stable'); Settings::AddNew("system.updatecheck_data", ''); + Settings::AddNew("system.update_notify_last", $update_to); Update::lastStepStatus(0); Update::showUpdateStep("Adjusting existing settings"); @@ -152,5 +156,5 @@ if (Froxlor::isFroxlorVersion('0.10.99')) { Settings::Set('panel.standardlanguage', $lang_map[Settings::Get('panel_standardlanguage')] ?? 'en'); Update::lastStepStatus(0); - Froxlor::updateToVersion('0.11.0-dev1'); + Froxlor::updateToVersion($update_to); } diff --git a/install/updates/preconfig/preconfig_0.10.inc.php b/install/updates/preconfig/preconfig_0.10.inc.php index 109ae993..2a50eb7a 100644 --- a/install/updates/preconfig/preconfig_0.10.inc.php +++ b/install/updates/preconfig/preconfig_0.10.inc.php @@ -23,8 +23,6 @@ * @license https://files.froxlor.org/misc/COPYING.txt GPLv2 */ -use Froxlor\Froxlor; -use Froxlor\FileDir; use Froxlor\Install\Update; $preconfig = [ diff --git a/lib/Froxlor/Cli/UpdateCommand.php b/lib/Froxlor/Cli/UpdateCommand.php index 4a799227..15d3947c 100644 --- a/lib/Froxlor/Cli/UpdateCommand.php +++ b/lib/Froxlor/Cli/UpdateCommand.php @@ -27,7 +27,10 @@ namespace Froxlor\Cli; use Exception; use Froxlor\Froxlor; +use Froxlor\Settings; +use Froxlor\Install\Update; use Froxlor\Install\AutoUpdate; +use Froxlor\System\Mailer; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -41,6 +44,7 @@ final class UpdateCommand extends CliCommand $this->setName('froxlor:update'); $this->setDescription('Check for newer version and update froxlor'); $this->addOption('check-only', 'c', InputOption::VALUE_NONE, 'Only check for newer version and exit') + ->addOption('mail-notify', 'm', InputOption::VALUE_NONE, 'Additionally inform administrator via email if a newer version was found') ->addOption('yes-to-all', 'A', InputOption::VALUE_NONE, 'Do not ask for download, extract and database-update, just do it (if not --check-only is set)') ->addOption('integer-return', 'i', InputOption::VALUE_NONE, 'Return integer whether a new version is available or not (implies --check-only). Useful for programmatic use.'); } @@ -60,12 +64,17 @@ final class UpdateCommand extends CliCommand $aucheck = AutoUpdate::checkVersion(); if ($aucheck == 1) { + $this->mailNotify($input, $output); if ($input->getOption('integer-return')) { $output->write(1); return self::SUCCESS; } // there is a new version - $text = lng('admin.newerversionavailable') . ' ' . lng('admin.newerversiondetails', [AutoUpdate::getFromResult('version'), Froxlor::VERSION]); + if ($input->getOption('check-only')) { + $text = lng('update.uc_newinfo', [(Settings::Get('system.update_channel') == 'testing' ? 'testing ' : ''), AutoUpdate::getFromResult('version'), Froxlor::VERSION]); + } else { + $text = lng('admin.newerversionavailable') . ' ' . lng('admin.newerversiondetails', [AutoUpdate::getFromResult('version'), Froxlor::VERSION]); + } $text = str_replace("
", " ", $text); $text = str_replace("", "", $text); $text = str_replace("", "", $text); @@ -156,6 +165,24 @@ final class UpdateCommand extends CliCommand return $result; } + private function mailNotify(InputInterface $input, OutputInterface $output) + { + if ($input->getOption('mail-notify')) { + $last_check_version = Settings::Get('system.update_notify_last'); + if (Update::versionInUpdate($last_check_version, AutoUpdate::getFromResult('version'))) { + $text = lng('update.uc_newinfo', [(Settings::Get('system.update_channel') == 'testing' ? 'testing ' : ''), AutoUpdate::getFromResult('version'), Froxlor::VERSION]); + $mail = new Mailer(true); + $mail->Body = $text; + $mail->Subject = "[froxlor] " . lng('update.notify_subject'); + $mail->AddAddress(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname')); + if (!$mail->Send() && $input->getOption('integer-return') == null) { + $output->writeln('' . $mail->ErrorInfo . ''); + } + Settings::Set('system.update_notify_last', AutoUpdate::getFromResult('version')); + } + } + } + private function updateDatabase() { include_once Froxlor::getInstallDir() . '/lib/tables.inc.php'; diff --git a/lng/de.lng.php b/lng/de.lng.php index 18f70094..bab12045 100644 --- a/lng/de.lng.php +++ b/lng/de.lng.php @@ -2117,6 +2117,7 @@ Vielen Dank, Ihr Administrator', 'noupdatesavail' => 'Die genutzte %sVersion von Froxlor ist aktuell.', 'description' => 'Aktualisierung der froxlor Datenbank', 'uc_newinfo' => 'Eine neuere %sVersion ist verfügbar: "%s" (Aktuell installierte Version: %s)', + 'notify_subject' => 'Neues Update verfügbar', ], 'usersettings' => [ 'custom_notes' => [ diff --git a/lng/en.lng.php b/lng/en.lng.php index 68d1fd2f..d5a5632f 100644 --- a/lng/en.lng.php +++ b/lng/en.lng.php @@ -2502,6 +2502,7 @@ Yours sincerely, your administrator', 'noupdatesavail' => 'You already have the latest %sversion of Froxlor installed.', 'description' => 'Running database updates for your froxlor installation', 'uc_newinfo' => 'There is a newer %sversion available: "%s" (Your current version is: %s)', + 'notify_subject' => 'New update available', ], 'usersettings' => [ 'custom_notes' => [