✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ premium290.web-hosting.com ​🇻​♯➤ 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2025

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 63.250.38.37 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.217.51
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /opt/cloudlinux/venv/lib/python3.11/site-packages/clcagefslib/webisolation/crontab//processor.py
# -*- coding: utf-8 -*-
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2025 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENCE.TXT
#
"""Processing functions for crontab operations."""

import os
import pwd
import shlex
import subprocess
import sys
from typing import BinaryIO, Callable, Optional

from clcagefslib.domain import is_isolation_enabled

from .constants import ISOLATION_WRAPPER
from .parser import (
    parse_crontab_structure,
    write_crontab_structure,
    entries_to_str_list,
)
from .structure import ParsedCrontabLine
from .utils import get_document_root

CRONTAB_BIN = "/usr/bin/crontab"


def process_list(stdout: Optional[BinaryIO] = None, stderr: Optional[BinaryIO] = None) -> int:
    """
    Process CRONTAB_LIST command.

    Runs 'crontab -l' to get current crontab entries. When isolation is active
    (PROXYEXEC_DOCUMENT_ROOT is set), only shows entries for the current
    document root. Removes isolation prefixes from output.

    Args:
        stdout: Output stream buffer (defaults to sys.stdout.buffer)
        stderr: Error stream buffer (defaults to sys.stderr.buffer)

    Returns:
        int: Exit code from crontab command, or 1 on error
    """
    stdout = stdout or sys.stdout.buffer
    stderr = stderr or sys.stderr.buffer

    result = subprocess.run(
        [CRONTAB_BIN, "-l"],
        capture_output=True,
    )

    # early exit in case site isolation is not turned on
    if not is_isolation_enabled(pwd.getpwuid(os.getuid()).pw_name):
        stdout.write(result.stdout)
        stderr.write(result.stderr)
        return result.returncode

    if result.returncode != 0:
        # Pass through stderr from crontab
        stderr.write(result.stderr)
        return result.returncode

    document_root = get_document_root()

    # Parse structure and pick entries to show
    structure = parse_crontab_structure(result.stdout)

    if document_root is not None:
        entries_to_show = structure.docroot_sections.get(document_root, [])
    else:
        entries_to_show = structure.global_records

    # Convert selected entries to bytes, removing wrapper prefixes if isolation is active
    result_parts = entries_to_str_list(entries_to_show, without_wrapper=bool(document_root))
    output_data = b"".join(result_parts)
    stdout.write(output_data)
    return 0


def process_save(
    stdin: Optional[BinaryIO] = None,
    stdout: Optional[BinaryIO] = None,
    stderr: Optional[BinaryIO] = None,
    run_func: Optional[Callable] = None,
) -> int:
    """
    Process CRONTAB_SAVE command.

    Reads crontab entries from stdin. If isolation is active:
    1. Gets the current full crontab
    2. Removes entries for the current document root
    3. Adds new entries to the current document root section
    4. Merges and saves the result in new format

    If isolation is not active:
    1. Gets the current full crontab
    2. Replaces user records section with new entries
    3. Preserves all docroot sections
    4. Saves in new format

    This ensures entries for other document roots are preserved.

    Args:
        stdin: Input stream buffer (defaults to sys.stdin.buffer)
        stdout: Output stream buffer (defaults to sys.stdout.buffer)
        stderr: Error stream buffer (defaults to sys.stderr.buffer)
        run_func: Function to run subprocess (defaults to subprocess.run)

    Returns:
        int: Exit code from crontab command, or 1 on error
    """

    stdin = stdin or sys.stdin.buffer
    stdout = stdout or sys.stdout.buffer
    stderr = stderr or sys.stderr.buffer
    run_func = run_func or subprocess.run

    input_data = stdin.read()
    document_root = get_document_root()

    if document_root is not None and ('\n' in document_root or '\r' in document_root):
        raise ValueError(f'Invalid document root: {document_root!r}')

    if is_isolation_enabled(pwd.getpwuid(os.getuid()).pw_name):
        # Get current crontab to preserve entries
        list_result = run_func(
            [CRONTAB_BIN, "-l"],
            capture_output=True,
        )

        # No existing crontab or error - start fresh
        # Note: returncode 1 typically means "no crontab for user", which is acceptable
        existing_data = list_result.stdout if list_result.returncode == 0 else b""

        # Parse existing crontab into structure
        existing_structure = parse_crontab_structure(existing_data)

        # Parse new input (filtered data, no section markers)
        # input_data is already bytes from stdin.read()
        new_structure = parse_crontab_structure(input_data)

        # Extract entries and add wrapper prefixes for docroot sections
        parsed_entries = []
        for entry in new_structure.global_records:
            if isinstance(entry, ParsedCrontabLine) and document_root:
                # Decode command to string for shlex.quote()
                command_bytes = entry.command
                has_newline = command_bytes.endswith(b"\n")
                command_str = command_bytes.rstrip(b"\n").decode("utf-8", errors="replace")

                # Use shlex.quote() to properly quote the command for bash -c
                quoted_command = shlex.quote(command_str)

                # Build the wrapped command: wrapper path docroot bash -c "quoted_command"
                # Use shlex.join() for the prefix to handle paths with spaces, then add quoted command
                prefix_parts = shlex.join([ISOLATION_WRAPPER, document_root, "bash", "-c"])
                wrapped_command_str = f"{prefix_parts} {quoted_command}"
                wrapped_command = wrapped_command_str.encode("utf-8")
                if has_newline:
                    wrapped_command += b"\n"

                parsed_entries.append(
                    ParsedCrontabLine(schedule=entry.schedule, command=wrapped_command)
                )
            else:
                # Keep as-is for comments and when document_root is None (may have wrapper prefixes)
                parsed_entries.append(entry)

        if document_root:
            # Isolation active: replace docroot section with new entries
            existing_structure.docroot_sections[document_root] = parsed_entries
        else:
            existing_structure.global_records = parsed_entries

        # Write in new format
        modified_data = write_crontab_structure(existing_structure)
    else:
        # pass through
        modified_data = input_data

    result = run_func(
        [CRONTAB_BIN, "-"],
        input=modified_data,
        capture_output=True,
    )

    # Pass through any output from crontab
    if result.stdout:
        stdout.write(result.stdout)
    if result.stderr:
        stderr.write(result.stderr)

    return result.returncode


Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
23 Jun 2026 7.00 AM
root / root
0755
__pycache__
--
23 Jun 2026 7.00 AM
root / root
0755
__init__.py
0.536 KB
29 May 2026 9.37 AM
root / root
0644
constants.py
0.844 KB
29 May 2026 9.37 AM
root / root
0644
libhooks.py
6.83 KB
29 May 2026 9.37 AM
root / root
0644
parser.py
4.481 KB
29 May 2026 9.37 AM
root / root
0644
processor.py
6.658 KB
29 May 2026 9.37 AM
root / root
0644
structure.py
4.106 KB
29 May 2026 9.37 AM
root / root
0644
utils.py
1.432 KB
29 May 2026 9.37 AM
root / root
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF