minor fixes
This commit is contained in:
@@ -5,11 +5,11 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="fgex",
|
name="fgex",
|
||||||
version="0.0.0",
|
version="0.0.1",
|
||||||
author="Pwnzer0tt1",
|
author="Pwnzer0tt1",
|
||||||
author_email="pwnzer0tt1@poliba.it",
|
author_email="pwnzer0tt1@poliba.it",
|
||||||
py_modules=["fgex"],
|
py_modules=["fgex"],
|
||||||
install_requires=["fgex"],
|
install_requires=["firegex"],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
description="Firegex client",
|
description="Firegex client",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
|||||||
@@ -2,6 +2,4 @@
|
|||||||
__version__ = "{{VERSION_PLACEHOLDER}}" if "{" not in "{{VERSION_PLACEHOLDER}}" else "0.0.0"
|
__version__ = "{{VERSION_PLACEHOLDER}}" if "{" not in "{{VERSION_PLACEHOLDER}}" else "0.0.0"
|
||||||
|
|
||||||
#Exported functions
|
#Exported functions
|
||||||
__all__ = [
|
__all__ = []
|
||||||
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich import print
|
from rich import print
|
||||||
|
from rich.markup import escape
|
||||||
from typer import Exit
|
from typer import Exit
|
||||||
from firegex import __version__
|
from firegex import __version__
|
||||||
from firegex.nfproxy.proxysim import run_proxy_simulation
|
from firegex.nfproxy.proxysim import run_proxy_simulation
|
||||||
from firegex.nfproxy.models import Protocols
|
from firegex.nfproxy.models import Protocols
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
|
||||||
app = typer.Typer(
|
app = typer.Typer(
|
||||||
no_args_is_help=True,
|
no_args_is_help=True,
|
||||||
@@ -18,6 +21,19 @@ def close_cli(code:int=1):
|
|||||||
|
|
||||||
DEV_MODE = __version__ == "0.0.0"
|
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")
|
@app.command(help="Run an nfproxy simulation")
|
||||||
def nfproxy(
|
def nfproxy(
|
||||||
filter_file: str = typer.Argument(..., help="The path to the filter file"),
|
filter_file: str = typer.Argument(..., help="The path to the filter file"),
|
||||||
@@ -31,7 +47,12 @@ def nfproxy(
|
|||||||
):
|
):
|
||||||
if from_address is None:
|
if from_address is None:
|
||||||
from_address = "::1" if ipv6 else "127.0.0.1"
|
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)
|
run_proxy_simulation(filter_file, proto.value, address, port, from_address, from_port, ipv6)
|
||||||
|
|
||||||
def version_callback(verison: bool):
|
def version_callback(verison: bool):
|
||||||
|
|||||||
@@ -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]:
|
def get_filters_info(code:str, proto:str) -> list[FilterHandler]:
|
||||||
glob = {}
|
glob = {}
|
||||||
exec(code, glob, glob)
|
|
||||||
exec("import firegex.nfproxy", 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)
|
filters = eval("firegex.nfproxy.get_pyfilters()", glob, glob)
|
||||||
try:
|
try:
|
||||||
return generate_filter_structure(filters, proto, glob)
|
return generate_filter_structure(filters, proto, glob)
|
||||||
|
|||||||
@@ -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:
|
if os.path.isfile(filter_file) is False:
|
||||||
raise Exception(f"\\[nfproxy]\\[init] Filter file {filter_file} not found")
|
raise Exception(f"\\[nfproxy]\\[init] Filter file {filter_file} not found")
|
||||||
|
else:
|
||||||
|
filter_file = os.path.abspath(filter_file)
|
||||||
|
|
||||||
proxy_process:Process|None = None
|
proxy_process:Process|None = None
|
||||||
|
|
||||||
def reload_proxy_proc():
|
def reload_proxy_proc():
|
||||||
nonlocal proxy_process
|
nonlocal proxy_process
|
||||||
if proxy_process is not None:
|
if proxy_process is not None:
|
||||||
|
log_print("RELOADING", "Proxy reload triggered", level=LogLevels.WARNING)
|
||||||
proxy_process.kill()
|
proxy_process.kill()
|
||||||
proxy_process.join()
|
proxy_process.join()
|
||||||
proxy_process = None
|
proxy_process = None
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
typer==0.15.1
|
typer==0.15.2
|
||||||
pydantic>=2
|
pydantic>=2
|
||||||
typing-extensions>=4.7.1
|
typing-extensions>=4.7.1
|
||||||
watchfiles
|
watchfiles
|
||||||
|
|||||||
Reference in New Issue
Block a user