Skip to content

Commit

Permalink
bug fix: maintain csf custom configs ref: #1353
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Nov 20, 2024
1 parent 684a3a4 commit 13bfef2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions plogical/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3556,12 +3556,59 @@ def upgrade(branch):
#Upgrade.executioner(command, 'fix csf if there', 0)

if os.path.exists('/etc/csf'):
##### Function to backup custom csf files and restore

from datetime import datetime

# List of files to backup
FILES = [
"/etc/csf/csf.allow",
"/etc/csf/csf.deny",
"/etc/csf/csf.conf",
"/etc/csf/csf.ignore",
"/etc/csf/csf.rignore",
"/etc/csf/csf.blocklists",
]

# Directory for backups
BACKUP_DIR = f"/home/cyberpanel/csf_backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}"

# Backup function
def backup_files():
os.makedirs(BACKUP_DIR, exist_ok=True)
for file in FILES:
if os.path.exists(file):
shutil.copy(file, BACKUP_DIR)
print(f"Backed up: {file}")
else:
print(f"File not found, skipping: {file}")

# Restore function
def restore_files():
for file in FILES:
backup_file = os.path.join(BACKUP_DIR, os.path.basename(file))
if os.path.exists(backup_file):
shutil.copy(backup_file, file)
print(f"Restored: {file}")
else:
print(f"Backup not found for: {file}")

# Backup the files
print("Backing up files...")
backup_files()

execPath = "sudo /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/csf.py"
execPath = execPath + " removeCSF"
Upgrade.executioner(execPath, 'fix csf if there', 0)

execPath = "sudo /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/csf.py"
execPath = execPath + " installCSF"

# Restore the files
print("Restoring files...")
restore_files()


Upgrade.executioner(execPath, 'fix csf if there', 0)


Expand Down

0 comments on commit 13bfef2

Please sign in to comment.