Server IP : 66.29.132.122 / Your IP : 3.142.12.31 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/migrations/ |
Upload File : |
import csv import os import logging logger = logging.getLogger(__name__) PROACTIVE_CSV, PROACTIVE_ENV_CSV = "proactive.csv", "proactive_env.csv" PROACTIVE_SQL = """SELECT id, timestamp, ip, ip_int, ip_version, ip_country_id, description, action, host, path, url, count, uid, gid, rule_id, rule_name FROM proactive ORDER BY timestamp DESC LIMIT ?""" PROACTIVE_ENV_SQL = """ SELECT proactive_env.event_id, proactive_env.name, proactive_env.value FROM proactive_env INNER JOIN ({}) pa ON proactive_env.event_id=pa.id """.format( PROACTIVE_SQL ) EXPORT_DIR = "/var/lib/imunify360-php-daemon/export" def export(database, target_dir, events_num): for filename, query in [ (PROACTIVE_CSV, PROACTIVE_SQL), (PROACTIVE_ENV_CSV, PROACTIVE_ENV_SQL), ]: cur = database.execute_sql(query, (events_num,)) with open( os.path.join(target_dir, filename), "w", newline="", encoding="utf-8", ) as csvfile: csv_writer = csv.writer(csvfile) csv_writer.writerows(cur) def migrate(migrator, database, fake=False, **kwargs): if fake: return try: os.makedirs(EXPORT_DIR, exist_ok=True) export(database, EXPORT_DIR, 1000) except Exception: # not critical logger.exception("Failed to export proactive defence data") def rollback(migrator, database, fake=False, **kwargs): pass