add paramter 'mail-notify' to froxlor:update CLI script to notify the system administrator via email about a new version (once per version)

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-07-31 16:26:39 +02:00
parent fabc68d13f
commit 5b3ea24725
6 changed files with 38 additions and 5 deletions

View File

@@ -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'),

View File

@@ -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);
}

View File

@@ -23,8 +23,6 @@
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
*/
use Froxlor\Froxlor;
use Froxlor\FileDir;
use Froxlor\Install\Update;
$preconfig = [

View File

@@ -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("<br/>", " ", $text);
$text = str_replace("<b>", "<info>", $text);
$text = str_replace("</b>", "</info>", $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('<error>' . $mail->ErrorInfo . '</>');
}
Settings::Set('system.update_notify_last', AutoUpdate::getFromResult('version'));
}
}
}
private function updateDatabase()
{
include_once Froxlor::getInstallDir() . '/lib/tables.inc.php';

View File

@@ -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' => [

View File

@@ -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' => [