365 lines
6.3 KiB
Python
365 lines
6.3 KiB
Python
from pathlib import Path
|
|
import subprocess
|
|
import yaml
|
|
|
|
|
|
class Config:
|
|
|
|
def __init__(self):
|
|
|
|
# Путь к конфигурационному файлу
|
|
config_file = (
|
|
Path(__file__).parent.parent
|
|
/
|
|
"config"
|
|
/
|
|
"config.yaml"
|
|
)
|
|
|
|
|
|
# Загрузка YAML
|
|
with open(
|
|
config_file,
|
|
"r"
|
|
) as file:
|
|
|
|
self.cfg = yaml.safe_load(file)
|
|
|
|
self._interface = None
|
|
|
|
|
|
|
|
# -----------------------------
|
|
# GPS
|
|
# -----------------------------
|
|
|
|
@property
|
|
def gps_source(self):
|
|
gps = self.cfg["gps"]
|
|
|
|
return gps.get(
|
|
"source",
|
|
"gpsrelay"
|
|
)
|
|
|
|
@property
|
|
def gpsrelay_host(self):
|
|
gps = self.cfg["gps"]
|
|
|
|
if "gpsrelay" in gps:
|
|
return gps["gpsrelay"]["host"]
|
|
|
|
return gps["host"]
|
|
|
|
@property
|
|
def gpsrelay_port(self):
|
|
gps = self.cfg["gps"]
|
|
|
|
if "gpsrelay" in gps:
|
|
return gps["gpsrelay"]["port"]
|
|
|
|
return gps["port"]
|
|
|
|
@property
|
|
def gnss_device(self):
|
|
gnss = self.cfg["gps"]["gnss"]
|
|
handler = gnss["handler"]
|
|
|
|
return gnss[handler]["device"]
|
|
|
|
@property
|
|
def gnss_at_device(self):
|
|
return self.cfg["gps"]["gnss"]["modem"]["at_device"]
|
|
|
|
@property
|
|
def gnss_handler(self):
|
|
return self.cfg["gps"]["gnss"]["handler"]
|
|
|
|
|
|
|
|
# -----------------------------
|
|
# Database
|
|
# -----------------------------
|
|
|
|
@property
|
|
def database(self):
|
|
|
|
return self.cfg["database"]["file"]
|
|
|
|
@property
|
|
def vendor_database(self):
|
|
|
|
return (
|
|
Path(__file__).parent.parent
|
|
/
|
|
self.cfg["vendor"]["database"]
|
|
)
|
|
|
|
@property
|
|
def vendor_sources(self):
|
|
|
|
return self.cfg["vendor"]["sources"]
|
|
|
|
|
|
# -----------------------------
|
|
# WiFi
|
|
# -----------------------------
|
|
|
|
@property
|
|
def interface(self):
|
|
|
|
if self._interface is None:
|
|
|
|
raise RuntimeError(
|
|
"WiFi interface is not selected."
|
|
)
|
|
|
|
return self._interface
|
|
|
|
def select_interface(self):
|
|
|
|
result = subprocess.run(
|
|
|
|
[
|
|
"sudo",
|
|
"-n",
|
|
"iw",
|
|
"dev"
|
|
],
|
|
|
|
capture_output=True,
|
|
|
|
text=True
|
|
|
|
)
|
|
|
|
interfaces = []
|
|
|
|
current = None
|
|
|
|
for line in result.stdout.splitlines():
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith("Interface"):
|
|
|
|
current = line.split()[1]
|
|
|
|
elif (
|
|
line.startswith("type")
|
|
and
|
|
current
|
|
):
|
|
|
|
if "monitor" in line or "managed" in line:
|
|
|
|
interfaces.append(
|
|
current
|
|
)
|
|
|
|
current = None
|
|
|
|
|
|
if not interfaces:
|
|
|
|
raise RuntimeError(
|
|
"No WiFi interface found."
|
|
)
|
|
|
|
|
|
iwlist = subprocess.run(
|
|
|
|
[
|
|
"sudo",
|
|
"-n",
|
|
"iw",
|
|
"list"
|
|
],
|
|
|
|
capture_output=True,
|
|
|
|
text=True
|
|
|
|
).stdout
|
|
|
|
|
|
if "monitor" not in iwlist.lower():
|
|
|
|
raise RuntimeError(
|
|
"No adapter supports monitor mode."
|
|
)
|
|
|
|
|
|
import os
|
|
|
|
requested_interface = os.environ.get(
|
|
"WIFI_INTERFACE"
|
|
)
|
|
|
|
if requested_interface:
|
|
|
|
if requested_interface in interfaces:
|
|
|
|
self._interface = (
|
|
requested_interface
|
|
)
|
|
|
|
return self._interface
|
|
|
|
raise RuntimeError(
|
|
f"WiFi interface '{requested_interface}' "
|
|
"is not available."
|
|
)
|
|
|
|
|
|
if len(interfaces) == 1:
|
|
|
|
self._interface = interfaces[0]
|
|
|
|
return self._interface
|
|
|
|
|
|
print()
|
|
|
|
print(
|
|
"Available WiFi interfaces:"
|
|
)
|
|
|
|
print()
|
|
|
|
for index, iface in enumerate(
|
|
interfaces,
|
|
start=1
|
|
):
|
|
|
|
print(
|
|
f"{index}) {iface}"
|
|
)
|
|
|
|
print()
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
value = int(
|
|
input(
|
|
"Select interface: "
|
|
)
|
|
)
|
|
|
|
if (
|
|
1
|
|
<= value
|
|
<= len(interfaces)
|
|
):
|
|
|
|
self._interface = (
|
|
interfaces[value - 1]
|
|
)
|
|
|
|
return self._interface
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
print(
|
|
"Invalid selection."
|
|
)
|
|
|
|
@property
|
|
def wifi_enable_2_4ghz(self):
|
|
|
|
return self.cfg["wifi"]["enable_2_4ghz"]
|
|
|
|
|
|
@property
|
|
def wifi_channels_2_4ghz(self):
|
|
|
|
return self.cfg["wifi"]["channels_2_4ghz"]
|
|
|
|
|
|
@property
|
|
def wifi_enable_5ghz(self):
|
|
|
|
return self.cfg["wifi"]["enable_5ghz"]
|
|
|
|
|
|
@property
|
|
def wifi_channels_5ghz(self):
|
|
|
|
return self.cfg["wifi"]["channels_5ghz"]
|
|
|
|
|
|
@property
|
|
def wifi_enable_6ghz(self):
|
|
|
|
return self.cfg["wifi"]["enable_6ghz"]
|
|
|
|
|
|
@property
|
|
def wifi_channels_6ghz(self):
|
|
|
|
return self.cfg["wifi"]["channels_6ghz"]
|
|
|
|
|
|
@property
|
|
def wifi_filtermode(self):
|
|
|
|
return self.cfg["wifi"]["filtermode"]
|
|
|
|
|
|
@property
|
|
def wifi_extra_args(self):
|
|
|
|
return self.cfg["wifi"]["extra_args"]
|
|
|
|
|
|
|
|
# -----------------------------
|
|
# Tools
|
|
# -----------------------------
|
|
|
|
@property
|
|
def hcxdumptool(self):
|
|
|
|
return (
|
|
Path(__file__).parent.parent
|
|
/
|
|
"bin"
|
|
/
|
|
"hcxdumptool"
|
|
)
|
|
|
|
|
|
@property
|
|
def hcxpcapngtool(self):
|
|
|
|
return (
|
|
Path(__file__).parent.parent
|
|
/
|
|
"bin"
|
|
/
|
|
"hcxpcapngtool"
|
|
)
|
|
|
|
# -----------------------------
|
|
# Capture
|
|
# -----------------------------
|
|
|
|
@property
|
|
def capture_directory(self):
|
|
|
|
return self.cfg["captures"]["directory"]
|
|
|
|
|
|
|
|
# -----------------------------
|
|
# Status
|
|
# -----------------------------
|
|
|
|
@property
|
|
def status_interval(self):
|
|
|
|
return self.cfg["status"]["interval"] |