feat: DNS_SERVER env var — pre-fills discovery UI, optional for scan
- DNS_SERVER env var configures the default DNS server for PTR lookups - GET /api/discovery/config exposes it to the frontend - DiscoveryModal fetches it on mount and pre-fills the field (editable) - dns_server is now optional in ScanRequest (default empty string) - PTR lookup is skipped when dns_server is empty — scan still proceeds - Validator only runs when dns_server is non-empty - .env.example, docker-compose.yml, READMEs (fr/en/es) updated Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import errno
|
||||
import ipaddress
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import time
|
||||
@@ -16,6 +17,8 @@ router = APIRouter()
|
||||
MAX_HOSTS_PER_TARGET = 1024 # refuse les /21 et plus larges
|
||||
MAX_HOSTS_TOTAL = 4096 # cap global sur l'ensemble des targets
|
||||
|
||||
_ENV_DNS = os.environ.get("DNS_SERVER", "").strip()
|
||||
|
||||
|
||||
class ScanTarget(BaseModel):
|
||||
vlan_id: int
|
||||
@@ -23,20 +26,26 @@ class ScanTarget(BaseModel):
|
||||
|
||||
|
||||
class ScanRequest(BaseModel):
|
||||
dns_server: str
|
||||
dns_server: str = ""
|
||||
targets: list[ScanTarget]
|
||||
tcp_check: bool = False
|
||||
|
||||
@field_validator("dns_server")
|
||||
@classmethod
|
||||
def _dns_server(cls, v: str) -> str:
|
||||
try:
|
||||
ipaddress.ip_address(v)
|
||||
except ValueError:
|
||||
raise ValueError(f"dns_server must be a valid IP address, got: {v!r}")
|
||||
if v:
|
||||
try:
|
||||
ipaddress.ip_address(v)
|
||||
except ValueError:
|
||||
raise ValueError(f"dns_server must be a valid IP address, got: {v!r}")
|
||||
return v
|
||||
|
||||
|
||||
@router.get("/config")
|
||||
def get_config():
|
||||
return {"dns_server": _ENV_DNS}
|
||||
|
||||
|
||||
class DiscoveredHost(BaseModel):
|
||||
ip: str
|
||||
hostname: Optional[str] = None
|
||||
@@ -109,7 +118,7 @@ def _scan_one(ip: str, dns_server: str, vlan_id: int, cidr: str, tcp_check: bool
|
||||
return None
|
||||
if tcp_check and not _tcp_check(ip):
|
||||
return None
|
||||
hostname = _ptr_lookup(ip, dns_server)
|
||||
hostname = _ptr_lookup(ip, dns_server) if dns_server else None
|
||||
return DiscoveredHost(ip=ip, hostname=hostname, vlan_id=vlan_id, cidr=cidr)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user