2025-02-20 19:51:28 +01:00
|
|
|
import functools
|
2025-03-03 21:15:49 +01:00
|
|
|
from firegex.nfproxy.models import RawPacket, TCPInputStream, TCPOutputStream, TCPClientStream, TCPServerStream
|
2025-03-03 20:25:36 +01:00
|
|
|
from firegex.nfproxy.internals.models import Action, FullStreamAction
|
2025-02-25 23:53:04 +01:00
|
|
|
|
|
|
|
|
ACCEPT = Action.ACCEPT
|
|
|
|
|
DROP = Action.DROP
|
|
|
|
|
REJECT = Action.REJECT
|
2025-03-03 20:25:36 +01:00
|
|
|
UNSTABLE_MANGLE = Action.MANGLE
|
2025-02-20 19:51:28 +01:00
|
|
|
|
|
|
|
|
def pyfilter(func):
|
|
|
|
|
"""
|
|
|
|
|
Decorator to mark functions that will be used in the proxy.
|
|
|
|
|
Stores the function reference in a global registry.
|
|
|
|
|
"""
|
|
|
|
|
if not hasattr(pyfilter, "registry"):
|
|
|
|
|
pyfilter.registry = set()
|
|
|
|
|
|
|
|
|
|
pyfilter.registry.add(func.__name__)
|
|
|
|
|
|
|
|
|
|
@functools.wraps(func)
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
def get_pyfilters():
|
|
|
|
|
"""Returns the list of functions marked with @pyfilter."""
|
2025-03-24 11:55:51 +01:00
|
|
|
if hasattr(pyfilter, "registry"):
|
|
|
|
|
return list(pyfilter.registry)
|
|
|
|
|
return []
|
2025-02-20 19:51:28 +01:00
|
|
|
|
2025-02-25 23:53:04 +01:00
|
|
|
def clear_pyfilter_registry():
|
|
|
|
|
"""Clears the pyfilter registry."""
|
|
|
|
|
if hasattr(pyfilter, "registry"):
|
|
|
|
|
pyfilter.registry.clear()
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
2025-03-03 20:25:36 +01:00
|
|
|
"ACCEPT", "DROP", "REJECT", "UNSTABLE_MANGLE"
|
|
|
|
|
"Action", "FullStreamAction", "pyfilter",
|
2025-03-03 21:15:49 +01:00
|
|
|
"RawPacket", "TCPInputStream", "TCPOutputStream", "TCPClientStream", "TCPServerStream"
|
2025-02-25 23:53:04 +01:00
|
|
|
]
|