HEX
Server: LiteSpeed
System: Linux cpir1.prohostdns.com 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: pelakir (2976)
PHP: 8.2.31
Disabled: exec, shell_exec, system, passthru, proc_open, proc_close, proc_terminate, proc_get_status, popen, pclose, pcntl_exec
Upload Files
File: //opt/imunify360/venv/lib64/python3.11/site-packages/imav/migrations/022_scan_queue_to_json.py
"""
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.


This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU General Public License for more details.


You should have received a copy of the GNU General Public License
 along with this program.  If not, see <https://www.gnu.org/licenses/>.

Copyright © 2019 Cloud Linux Software Inc.

This software is also available under ImunifyAV commercial license,
see <https://www.imunify360.com/legal/eula>

One-shot upgrade migration: drop any legacy non-JSON scan queue file.

The runtime reads JSON only; migration 002 already normalized the
on-disk objects to plain dicts.
"""

import logging
from pathlib import Path

logger = logging.getLogger(__name__)

SCANS_PATH = Path("/var/imunify360/aibolit/scans.pickle")


def _looks_like_json(raw: bytes) -> bool:
    head = raw.lstrip()[:1]
    return head in (b"[", b"{")


def migrate(migrator, *_, fake=False, **__):
    if fake or not SCANS_PATH.exists():
        return

    if _looks_like_json(SCANS_PATH.read_bytes()):
        return

    # Drop, don't pickle-load: deserializing this file is the RCE we remove.
    logger.warning("Removing legacy non-JSON scans file %s", SCANS_PATH)
    SCANS_PATH.unlink(missing_ok=True)


def rollback(migrator, *_, fake=False, **__):
    pass