REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.51 KB
Close
//opt/imunify360/venv/share/imunify360/scripts/migrate_csf/smtp.py
Text
Base64
""" SMTP blocking migration from CSF to Imunify360. Mapping: SMTP_BLOCK = "1" -> SMTP_BLOCKING.enable = true SMTP_PORTS = "25,465,587" -> SMTP_BLOCKING.ports = "25,587,465" SMTP_ALLOWUSER = "user1" -> SMTP_BLOCKING.allow_users = ["user1"] SMTP_ALLOWGROUP = "group1" -> SMTP_BLOCKING.allow_groups = ["group1"] SMTP_ALLOWLOCAL = "1" -> SMTP_BLOCKING.allow_local = true """ import pathlib import yaml from csf_conf import get_csf_config_value from logger_config import get_logger, capture_exception CONFIG_DIR = pathlib.Path("/etc/sysconfig/imunify360/imunify360.config.d/") def migrate_smtp() -> None: """Migrate SMTP blocking configuration from CSF to Imunify360.""" logger = get_logger() try: logger.info("Migrating SMTP blocking configuration...") smtp_block = get_csf_config_value("SMTP_BLOCK") smtp_ports = get_csf_config_value("SMTP_PORTS") smtp_allowuser = get_csf_config_value("SMTP_ALLOWUSER") smtp_allowgroup = get_csf_config_value("SMTP_ALLOWGROUP") smtp_allowlocal = get_csf_config_value("SMTP_ALLOWLOCAL") if smtp_block != "1": logger.info( "SMTP blocking is disabled in CSF, skipping migration." ) return imunify_config = {"SMTP_BLOCKING": {}} imunify_config["SMTP_BLOCKING"]["enable"] = smtp_block == "1" if smtp_ports: imunify_config["SMTP_BLOCKING"]["ports"] = smtp_ports.split(",") if smtp_allowuser: users = [ user.strip() for user in smtp_allowuser.split(",") if user.strip() ] if users: imunify_config["SMTP_BLOCKING"]["allow_users"] = users if smtp_allowgroup: groups = [ group.strip() for group in smtp_allowgroup.split(",") if group.strip() ] if groups: imunify_config["SMTP_BLOCKING"]["allow_groups"] = groups imunify_config["SMTP_BLOCKING"]["allow_local"] = smtp_allowlocal == "1" CONFIG_DIR.mkdir(parents=True, exist_ok=True) config_file = CONFIG_DIR / "70-csf-smtp.conf" with open(config_file, "w") as f: yaml.dump(imunify_config, f) logger.info(f"SMTP blocking configuration written to {config_file}") logger.info("SMTP migration completed successfully.") except Exception as e: logger.error(f"Error during SMTP migration: {e}") capture_exception(e, {"migration_type": "smtp"})
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 6
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
country.py
4.05 KB
lrwxr-xr-x
2026-05-26 21:25:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
csf_conf.py
1.34 KB
lrwxr-xr-x
2026-05-26 21:25:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ips.py
24.55 KB
lrwxr-xr-x
2026-05-26 21:25:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
logger_config.py
7.05 KB
lrwxr-xr-x
2026-05-26 21:25:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
main.py
2.00 KB
lrwxr-xr-x
2026-05-26 21:25:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
smtp.py
2.51 KB
lrwxr-xr-x
2026-05-26 21:25:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).