mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-15 09:46:11 +01:00
bug fix: maintain csf custom configs ref: https://github.com/usmannasir/cyberpanel/issues/1353
This commit is contained in:
@@ -3556,12 +3556,59 @@ pm.max_spare_servers = 3
|
||||
#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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user