Skip to content

Commit

Permalink
Merge pull request #18 from plesk/add-restore-dovecot-config-action
Browse files Browse the repository at this point in the history
Add an action to restore /ect/dovecot/dovecto.conf to state before conversion/distupgrade
  • Loading branch information
SandakovMM authored Mar 20, 2024
2 parents 2ac3850 + eed3b9b commit 225eb4a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pleskdistup/actions/emails.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright 2023-2024. WebPros International GmbH. All rights reserved.
import json
import os
import shutil
import subprocess

from pleskdistup.common import action, log, util
from pleskdistup.common import action, files, log, motd, plesk, util


class SetMinDovecotDhParamSize(action.ActiveAction):
Expand Down Expand Up @@ -52,3 +54,33 @@ def _revert_action(self) -> action.ActionResult:

def estimate_post_time(self) -> int:
return 5


class RestoreDovecotConfiguration(action.ActiveAction):
dovecot_config_path: str
temp_directory: str

def __init__(self, temp_directory: str):
self.name = "restore Dovecot configuration"
self.dovecot_config_path = "/etc/dovecot/dovecot.conf"
self.temp_directory = temp_directory

def _is_required(self) -> bool:
return os.path.exists(self.dovecot_config_path)

def _prepare_action(self) -> action.ActionResult:
files.backup_file(self.dovecot_config_path)
return action.ActionResult()

def _post_action(self) -> action.ActionResult:
path_to_backup = os.path.join(self.temp_directory, "dovecot.conf.bak")
if os.path.exists(self.dovecot_config_path):
shutil.copy(self.dovecot_config_path, path_to_backup)
motd.add_finish_ssh_login_message(f"The dovecot configuration '{self.dovecot_config_path}' has been restored from original distro. Modern configuration was placed in '{path_to_backup}'.")

files.restore_file_from_backup(self.dovecot_config_path)
return action.ActionResult()

def _revert_action(self) -> action.ActionResult:
files.remove_backup(self.dovecot_config_path)
return action.ActionResult()

0 comments on commit 225eb4a

Please sign in to comment.