Refactor: Config-Dateipfade generisch – mailwolt-* Prefix entfernt
- rspamd: mailwolt-actions.conf → actions.conf - dovecot: 99-mailwolt-tls.conf → 99-tls.conf - postfix: mailwolt-tls.cf → tls.cf - fail2ban: mailwolt-whitelist.local / 00-mailwolt-defaults.local → generic - neu: clubird:migrate-config-names Artisan-Kommando für Server-Migration Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>main v1.1.386
parent
978fad64f4
commit
653bf55415
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MigrateConfigNames extends Command
|
||||
{
|
||||
protected $signature = 'clubird:migrate-config-names {--dry-run : Nur anzeigen was gemacht würde}';
|
||||
protected $description = 'Benennt server-seitige Config-Dateien von mailwolt-* auf generische Namen um';
|
||||
|
||||
private array $renames = [
|
||||
'/etc/rspamd/local.d/mailwolt-actions.conf' => '/etc/rspamd/local.d/actions.conf',
|
||||
'/etc/dovecot/conf.d/99-mailwolt-tls.conf' => '/etc/dovecot/conf.d/99-tls.conf',
|
||||
'/etc/postfix/mailwolt-tls.cf' => '/etc/postfix/tls.cf',
|
||||
'/etc/fail2ban/jail.d/mailwolt-whitelist.local' => '/etc/fail2ban/jail.d/whitelist.local',
|
||||
'/etc/fail2ban/jail.d/00-mailwolt-defaults.local'=> '/etc/fail2ban/jail.d/00-defaults.local',
|
||||
];
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$dry = $this->option('dry-run');
|
||||
|
||||
foreach ($this->renames as $old => $new) {
|
||||
if (!file_exists($old)) {
|
||||
$this->line(" <fg=gray>übersprungen</> {$old} (nicht vorhanden)");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file_exists($new) && !is_link($new)) {
|
||||
$this->line(" <fg=yellow>bereits vorhanden</> {$new}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($dry) {
|
||||
$this->line(" <fg=cyan>[dry-run]</> mv {$old} → {$new}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Als root direkt umbenennen; als www-data via sudo (sudo mv muss in sudoers sein)
|
||||
if (posix_getuid() === 0) {
|
||||
$ok = @rename($old, $new);
|
||||
$errMsg = error_get_last()['message'] ?? '';
|
||||
} else {
|
||||
@exec('sudo -n mv ' . escapeshellarg($old) . ' ' . escapeshellarg($new) . ' 2>&1', $out, $rc);
|
||||
$ok = ($rc === 0);
|
||||
$errMsg = implode(' ', $out);
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
$this->info(" umbenannt: {$old} → {$new}");
|
||||
} else {
|
||||
$this->error(" FEHLER bei {$old}: {$errMsg}");
|
||||
$this->line(" → manuell: <fg=yellow>mv {$old} {$new}</>");
|
||||
}
|
||||
}
|
||||
|
||||
if (!$dry) {
|
||||
$this->info('Fertig. Dienste ggf. neu starten: rspamd, dovecot, postfix, fail2ban');
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -135,7 +135,7 @@ bantime.factor = {$s->bantime_factor}
|
|||
bantime.maxtime = {$s->max_bantime}
|
||||
CONF;
|
||||
|
||||
$this->writeRootFileViaTee('/etc/fail2ban/jail.d/00-mailwolt-defaults.local', $content);
|
||||
$this->writeRootFileViaTee('/etc/fail2ban/jail.d/00-defaults.local', $content);
|
||||
}
|
||||
|
||||
protected function writeWhitelistConfig(): void
|
||||
|
|
@ -146,7 +146,7 @@ CONF;
|
|||
|
||||
$content = "[DEFAULT]\nignoreip = {$ignore}\n";
|
||||
|
||||
$this->writeRootFileViaTee('/etc/fail2ban/jail.d/mailwolt-whitelist.local', $content);
|
||||
$this->writeRootFileViaTee('/etc/fail2ban/jail.d/whitelist.local', $content);
|
||||
}
|
||||
|
||||
/* ---------------- Helper ---------------- */
|
||||
|
|
@ -320,7 +320,7 @@ CONF;
|
|||
//bantime.maxtime = {$s->max_bantime}
|
||||
//CONF;
|
||||
//
|
||||
// $this->writeRootFileViaTee('/etc/fail2ban/jail.d/00-mailwolt-defaults.local', $content);
|
||||
// $this->writeRootFileViaTee('/etc/fail2ban/jail.d/00-defaults.local', $content);
|
||||
// }
|
||||
//
|
||||
// protected function writeWhitelistConfig(): void
|
||||
|
|
@ -330,7 +330,7 @@ CONF;
|
|||
//
|
||||
// $content = "[DEFAULT]\nignoreip = {$ignore}\n";
|
||||
//
|
||||
// $this->writeRootFileViaTee('/etc/fail2ban/jail.d/mailwolt-whitelist.local', $content);
|
||||
// $this->writeRootFileViaTee('/etc/fail2ban/jail.d/whitelist.local', $content);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
|
|
@ -493,7 +493,7 @@ CONF;
|
|||
//bantime.factor = {$s->bantime_factor}
|
||||
//bantime.maxtime = {$s->max_bantime}
|
||||
//CONF;
|
||||
// file_put_contents('/etc/fail2ban/jail.d/00-mailwolt-defaults.local', $content);
|
||||
// file_put_contents('/etc/fail2ban/jail.d/00-defaults.local', $content);
|
||||
// }
|
||||
//
|
||||
// protected function writeWhitelistConfig(): void
|
||||
|
|
@ -501,7 +501,7 @@ CONF;
|
|||
// $ips = Fail2banIpList::where('type','whitelist')->pluck('ip')->toArray();
|
||||
// $ignore = implode(' ', array_unique(array_filter($ips)));
|
||||
// $content = "[DEFAULT]\nignoreip = {$ignore}\n";
|
||||
// file_put_contents('/etc/fail2ban/jail.d/mailwolt-whitelist.local', $content);
|
||||
// file_put_contents('/etc/fail2ban/jail.d/whitelist.local', $content);
|
||||
// }
|
||||
//
|
||||
// private function writeRootFileViaTee(string $target, string $content): void
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ class Fail2banIpModal extends ModalComponent
|
|||
$ignore = implode(' ', array_unique(array_filter($ips)));
|
||||
$content = "[DEFAULT]\nignoreip = {$ignore}\n";
|
||||
|
||||
$this->writeRootFileViaTee('/etc/fail2ban/jail.d/mailwolt-whitelist.local', $content);
|
||||
$this->writeRootFileViaTee('/etc/fail2ban/jail.d/whitelist.local', $content);
|
||||
}
|
||||
|
||||
private function writeRootFileViaTee(string $target, string $content): void
|
||||
|
|
@ -293,7 +293,7 @@ class Fail2banIpModal extends ModalComponent
|
|||
// Fail2banIpList::create(['ip' => $ip, 'type' => $this->type]);
|
||||
//
|
||||
// if ($this->type === 'whitelist') {
|
||||
// $this->writeWhitelistConfig(); // schreibt /etc/fail2ban/jail.d/mailwolt-whitelist.local
|
||||
// $this->writeWhitelistConfig(); // schreibt /etc/fail2ban/jail.d/whitelist.local
|
||||
// $this->reloadFail2ban(); // f2b neu laden
|
||||
// } else {
|
||||
// // Blacklist = sofort bannen im dedizierten Jail
|
||||
|
|
@ -356,7 +356,7 @@ class Fail2banIpModal extends ModalComponent
|
|||
// $content = "[DEFAULT]\nignoreip = {$ignore}\n";
|
||||
//
|
||||
// // sicher in Root-Pfad schreiben (sudo tee)
|
||||
// $this->writeRootFileViaTee('/etc/fail2ban/jail.d/mailwolt-whitelist.local', $content);
|
||||
// $this->writeRootFileViaTee('/etc/fail2ban/jail.d/whitelist.local', $content);
|
||||
// }
|
||||
//
|
||||
// private function writeRootFileViaTee(string $target, string $content): void
|
||||
|
|
@ -540,7 +540,7 @@ class Fail2banIpModal extends ModalComponent
|
|||
// $ignore = implode(' ', array_unique(array_filter($ips)));
|
||||
// $content = "[DEFAULT]\nignoreip = {$ignore}\n";
|
||||
//
|
||||
// $file = '/etc/fail2ban/jail.d/mailwolt-whitelist.local';
|
||||
// $file = '/etc/fail2ban/jail.d/whitelist.local';
|
||||
// $tmp = $file.'.tmp';
|
||||
// @file_put_contents($tmp, $content, LOCK_EX);
|
||||
// @chmod($tmp, 0644);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class RspamdForm extends Component
|
|||
|
||||
private function writeRspamdConfig(): void
|
||||
{
|
||||
$target = '/etc/rspamd/local.d/mailwolt-actions.conf';
|
||||
$target = '/etc/rspamd/local.d/actions.conf';
|
||||
$content = <<<CONF
|
||||
actions {
|
||||
reject = {$this->reject_score};
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class TlsCiphersForm extends Component
|
|||
|
||||
private function writePostfixConfig(): void
|
||||
{
|
||||
$target = '/etc/postfix/mailwolt-tls.cf';
|
||||
$target = '/etc/postfix/tls.cf';
|
||||
$content = "smtpd_tls_protocols = {$this->postfix_protocols}\n"
|
||||
. "smtp_tls_protocols = {$this->postfix_protocols}\n"
|
||||
. "smtpd_tls_ciphers = {$this->postfix_ciphers}\n"
|
||||
|
|
@ -106,7 +106,7 @@ class TlsCiphersForm extends Component
|
|||
|
||||
private function writeDovecotConfig(): void
|
||||
{
|
||||
$target = '/etc/dovecot/conf.d/99-mailwolt-tls.conf';
|
||||
$target = '/etc/dovecot/conf.d/99-tls.conf';
|
||||
$content = "ssl_min_protocol = {$this->dovecot_min_proto}\n"
|
||||
. "ssl_cipher_list = {$this->dovecot_ciphers}\n";
|
||||
$this->tee($target, $content);
|
||||
|
|
|
|||
Loading…
Reference in New Issue