minor fixes

This commit is contained in:
Domingo Dirutigliano
2025-03-04 16:57:15 +01:00
parent 47496287d5
commit 22b90376b3
6 changed files with 31 additions and 8 deletions

View File

@@ -5,11 +5,11 @@ with open("README.md", "r", encoding="utf-8") as fh:
setuptools.setup(
name="fgex",
version="0.0.0",
version="0.0.1",
author="Pwnzer0tt1",
author_email="pwnzer0tt1@poliba.it",
py_modules=["fgex"],
install_requires=["fgex"],
install_requires=["firegex"],
include_package_data=True,
description="Firegex client",
long_description=long_description,

View File

@@ -2,6 +2,4 @@
__version__ = "{{VERSION_PLACEHOLDER}}" if "{" not in "{{VERSION_PLACEHOLDER}}" else "0.0.0"
#Exported functions
__all__ = [
]
__all__ = []

View File

@@ -3,10 +3,13 @@
import typer
from rich import print
from rich.markup import escape
from typer import Exit
from firegex import __version__
from firegex.nfproxy.proxysim import run_proxy_simulation
from firegex.nfproxy.models import Protocols
import os
import socket
app = typer.Typer(
no_args_is_help=True,
@@ -18,6 +21,19 @@ def close_cli(code:int=1):
DEV_MODE = __version__ == "0.0.0"
def test_connection(host, port, use_ipv6=False):
family = socket.AF_INET6 if use_ipv6 else socket.AF_INET
sock = socket.socket(family, socket.SOCK_STREAM)
try:
sock.settimeout(3)
sock.connect((host, port))
return True
except Exception:
return False
finally:
sock.close()
@app.command(help="Run an nfproxy simulation")
def nfproxy(
filter_file: str = typer.Argument(..., help="The path to the filter file"),
@@ -31,7 +47,12 @@ def nfproxy(
):
if from_address is None:
from_address = "::1" if ipv6 else "127.0.0.1"
if not os.path.isfile(filter_file):
print(f"[bold red]'{escape(os.path.abspath(filter_file))}' not found[/]")
close_cli()
if not test_connection(address, port, ipv6):
print(f"[bold red]Can't connect to {escape(address)}:{port}[/]")
close_cli()
run_proxy_simulation(filter_file, proto.value, address, port, from_address, from_port, ipv6)
def version_callback(verison: bool):

View File

@@ -57,8 +57,9 @@ def generate_filter_structure(filters: list[str], proto:str, glob:dict) -> list[
def get_filters_info(code:str, proto:str) -> list[FilterHandler]:
glob = {}
exec(code, glob, glob)
exec("import firegex.nfproxy", glob, glob)
exec("firegex.nfproxy.clear_pyfilter_registry()", glob, glob)
exec(code, glob, glob)
filters = eval("firegex.nfproxy.get_pyfilters()", glob, glob)
try:
return generate_filter_structure(filters, proto, glob)

View File

@@ -262,12 +262,15 @@ def run_proxy_simulation(filter_file:str, proto:str, target_ip:str, target_port:
if os.path.isfile(filter_file) is False:
raise Exception(f"\\[nfproxy]\\[init] Filter file {filter_file} not found")
else:
filter_file = os.path.abspath(filter_file)
proxy_process:Process|None = None
def reload_proxy_proc():
nonlocal proxy_process
if proxy_process is not None:
log_print("RELOADING", "Proxy reload triggered", level=LogLevels.WARNING)
proxy_process.kill()
proxy_process.join()
proxy_process = None

View File

@@ -1,4 +1,4 @@
typer==0.15.1
typer==0.15.2
pydantic>=2
typing-extensions>=4.7.1
watchfiles