HEX
Server: LiteSpeed
System: Linux sg-cp4.cloudnetwork.vn 4.18.0-553.69.1.lve.el8.x86_64 #1 SMP Wed Aug 13 19:53:59 UTC 2025 x86_64
User: thu28850 (1134)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //opt/imunify360/venv/lib/python3.11/site-packages/im360/internals/core/rules/port.py
"""Put redirect_port_rules here to avoid circular import."""
from typing import Callable, Dict, Iterator, Set

from im360.internals.core.firewall import FirewallRules
from .types_ import FirewallRule


def redirect_port_rules(
    ipset_name: str,
    dest_ports: Set[int],
    redirect_map: Dict[int, int],
    table: str,
    redirector: Callable,
    priority: int = FirewallRules.DEFAULT_PRIORITY,
) -> Iterator[FirewallRule]:
    """Generate common port redirection rules for captcha/splashscreen."""

    for dest_port, target in redirect_map.items():
        if dest_port not in dest_ports:
            continue
        yield FirewallRule(
            rule=redirector(ipset_name, dest_port, target),
            table=table,
            priority=priority,
        )