Release WiFi GPS Mapper v2.3.0
This commit is contained in:
+632
-166
@@ -78,10 +78,15 @@ from reports.vendors import render_vendors_page
|
||||
from vendor_service import VendorService
|
||||
from sudo import SudoChecker
|
||||
from config import Config
|
||||
from database import Database
|
||||
from parser import CaptureParser
|
||||
from session import Session
|
||||
from reports.recovery import CAPTURES_DIR, _has_recoverable_capture
|
||||
from gps_test import GPSTestService
|
||||
from auto_gps import AutoGPSService
|
||||
from auto_wifi_verification import AutoWiFiVerificationService
|
||||
from wifi_connection import WiFiConnectionError, WiFiConnectionService
|
||||
from gpsrelay_discovery import GPSRelayDiscoveryError, discover_gpsrelay
|
||||
from gui.timezones import get_timezone_options
|
||||
from logging_config import (
|
||||
LOG_DATE_FORMAT,
|
||||
@@ -273,6 +278,8 @@ def scanner_navigation_guard():
|
||||
"api_wifi_verification_stop",
|
||||
"api_wifi_verification_settings",
|
||||
"api_wifi_verification_settings_save",
|
||||
"api_wifi_verification_gpsrelay_discovery_start",
|
||||
"api_wifi_verification_gpsrelay_discovery_status",
|
||||
"api_wifi_verification_radius_apply",
|
||||
"static",
|
||||
}
|
||||
@@ -309,6 +316,8 @@ def scanner_navigation_guard():
|
||||
"scanner_stop",
|
||||
"api_gps_test",
|
||||
"gps_test_stop",
|
||||
"api_wifi_verification_gpsrelay_discovery_start",
|
||||
"api_wifi_verification_gpsrelay_discovery_status",
|
||||
"static"
|
||||
}
|
||||
|
||||
@@ -368,6 +377,10 @@ auto_wifi_verification_service = None
|
||||
|
||||
auto_wifi_verification_lock = threading.Lock()
|
||||
|
||||
gpsrelay_discovery_job = None
|
||||
gpsrelay_discovery_thread = None
|
||||
gpsrelay_discovery_lock = threading.Lock()
|
||||
|
||||
# Shared GPS service for the Auto Verification map and Auto Verification worker.
|
||||
wifi_verification_shared_gps_service = None
|
||||
wifi_verification_shared_gps_lock = threading.RLock()
|
||||
@@ -642,35 +655,14 @@ def _stop_wifi_verification_shared_gps_locked():
|
||||
|
||||
def acquire_wifi_verification_network_owner(owner, gps_service):
|
||||
|
||||
if owner == "MANUAL_WIFI_VERIFY":
|
||||
with scanner_lock:
|
||||
return _acquire_network_owner_locked(owner)
|
||||
|
||||
if owner != "AUTO_WIFI_VERIFY":
|
||||
return acquire_network_owner(owner)
|
||||
|
||||
with wifi_verification_shared_gps_lock:
|
||||
|
||||
if wifi_verification_map_monitor_enabled:
|
||||
|
||||
thread = gps_service.thread
|
||||
|
||||
if thread is None or not thread.is_alive():
|
||||
return False, (
|
||||
"Map GPS monitor is enabled, "
|
||||
"but its GPS service is not running."
|
||||
)
|
||||
|
||||
with scanner_lock:
|
||||
transferred = _transfer_network_owner_locked(
|
||||
"MAP_GPS_MONITOR",
|
||||
"AUTO_WIFI_VERIFY"
|
||||
)
|
||||
|
||||
if not transferred:
|
||||
return False, (
|
||||
"Unable to transfer network ownership "
|
||||
"from the map GPS monitor."
|
||||
)
|
||||
|
||||
return True, None
|
||||
|
||||
with scanner_lock:
|
||||
acquired, error = _acquire_network_owner_locked(owner)
|
||||
|
||||
@@ -678,6 +670,11 @@ def acquire_wifi_verification_network_owner(owner, gps_service):
|
||||
return False, error
|
||||
|
||||
try:
|
||||
if gps_service is None:
|
||||
raise RuntimeError(
|
||||
"Shared GPS service is not configured."
|
||||
)
|
||||
|
||||
thread = gps_service.thread
|
||||
|
||||
if thread is not None and thread.is_alive():
|
||||
@@ -710,30 +707,19 @@ def acquire_wifi_verification_network_owner(owner, gps_service):
|
||||
|
||||
def release_wifi_verification_network_owner(owner):
|
||||
|
||||
if owner == "MANUAL_WIFI_VERIFY":
|
||||
with scanner_lock:
|
||||
if network_operation_owner == owner:
|
||||
_release_network_owner_locked(owner)
|
||||
|
||||
return
|
||||
|
||||
if owner != "AUTO_WIFI_VERIFY":
|
||||
release_network_owner(owner)
|
||||
return
|
||||
|
||||
with wifi_verification_shared_gps_lock:
|
||||
|
||||
if wifi_verification_map_monitor_enabled:
|
||||
|
||||
with scanner_lock:
|
||||
transferred = _transfer_network_owner_locked(
|
||||
"AUTO_WIFI_VERIFY",
|
||||
"MAP_GPS_MONITOR"
|
||||
)
|
||||
|
||||
if not transferred:
|
||||
logger.warning(
|
||||
"Could not return network ownership "
|
||||
"to the map GPS monitor."
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
with scanner_lock:
|
||||
|
||||
current_owner = network_operation_owner
|
||||
|
||||
if current_owner == owner:
|
||||
@@ -742,7 +728,8 @@ def release_wifi_verification_network_owner(owner):
|
||||
elif current_owner is not None:
|
||||
return
|
||||
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
if not wifi_verification_map_monitor_enabled:
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
|
||||
|
||||
def network_actions_busy():
|
||||
@@ -2388,6 +2375,261 @@ def reports_trips():
|
||||
)
|
||||
|
||||
|
||||
@app.route(
|
||||
"/reports/recovery/<directory_name>",
|
||||
methods=["POST"]
|
||||
)
|
||||
def reports_recovery_restore(directory_name):
|
||||
|
||||
captures_root = Path(
|
||||
CAPTURES_DIR
|
||||
).resolve()
|
||||
|
||||
session_path = (
|
||||
captures_root / directory_name
|
||||
).resolve()
|
||||
|
||||
if session_path.parent != captures_root:
|
||||
abort(400)
|
||||
|
||||
if not session_path.is_dir():
|
||||
abort(404)
|
||||
|
||||
capture_file = (
|
||||
session_path / "capture.pcapng"
|
||||
)
|
||||
|
||||
if not capture_file.is_file():
|
||||
return jsonify(
|
||||
{
|
||||
"error": "Capture file was not found."
|
||||
}
|
||||
), 400
|
||||
|
||||
if capture_file.stat().st_size <= 0:
|
||||
return jsonify(
|
||||
{
|
||||
"error": "Capture file is empty."
|
||||
}
|
||||
), 400
|
||||
|
||||
if not _has_recoverable_capture(session_path):
|
||||
return jsonify(
|
||||
{
|
||||
"error": (
|
||||
"Capture duration is shorter than "
|
||||
"the required 5 minutes."
|
||||
)
|
||||
}
|
||||
), 400
|
||||
|
||||
acquired, lock_error = acquire_network_owner(
|
||||
"SESSION_RECOVERY"
|
||||
)
|
||||
|
||||
if not acquired:
|
||||
return jsonify(
|
||||
{
|
||||
"error": (
|
||||
lock_error
|
||||
or "Network operation is currently busy."
|
||||
)
|
||||
}
|
||||
), 409
|
||||
|
||||
db = None
|
||||
|
||||
try:
|
||||
|
||||
cfg = Config()
|
||||
|
||||
db = Database(
|
||||
cfg.database
|
||||
)
|
||||
|
||||
existing_sessions = db.conn.execute(
|
||||
"""
|
||||
SELECT
|
||||
id,
|
||||
capture_file
|
||||
FROM capture_sessions
|
||||
"""
|
||||
).fetchall()
|
||||
|
||||
for row in existing_sessions:
|
||||
|
||||
stored_capture_file = row["capture_file"]
|
||||
|
||||
if not stored_capture_file:
|
||||
continue
|
||||
|
||||
if Path(
|
||||
stored_capture_file
|
||||
).resolve() == capture_file.resolve():
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"error": (
|
||||
"A database record already exists "
|
||||
"for this capture."
|
||||
),
|
||||
"session_id": row["id"],
|
||||
}
|
||||
), 409
|
||||
|
||||
session = Session.from_existing(
|
||||
session_path
|
||||
)
|
||||
|
||||
session_id = db.create_session(
|
||||
str(session.capture_file),
|
||||
start_time=session.start_time
|
||||
)
|
||||
|
||||
session.id = session_id
|
||||
|
||||
parser = CaptureParser(
|
||||
cfg,
|
||||
db
|
||||
)
|
||||
|
||||
parser.parse(
|
||||
session,
|
||||
session_id
|
||||
)
|
||||
|
||||
db.flush_observations()
|
||||
|
||||
event_times = []
|
||||
|
||||
timestamp_sources = (
|
||||
("gps_track", "timestamp"),
|
||||
("access_point_observations", "observed_at"),
|
||||
("handshakes", "captured_at"),
|
||||
)
|
||||
|
||||
for table, column in timestamp_sources:
|
||||
|
||||
rows = db.conn.execute(
|
||||
f"""
|
||||
SELECT {column}
|
||||
FROM {table}
|
||||
WHERE session_id = ?
|
||||
AND {column} IS NOT NULL
|
||||
""",
|
||||
(session_id,),
|
||||
).fetchall()
|
||||
|
||||
for row in rows:
|
||||
|
||||
try:
|
||||
timestamp = datetime.fromisoformat(
|
||||
str(row[0]).replace("Z", "+00:00")
|
||||
)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
if timestamp.tzinfo is None:
|
||||
timestamp = timestamp.replace(
|
||||
tzinfo=timezone.utc
|
||||
)
|
||||
else:
|
||||
timestamp = timestamp.astimezone(
|
||||
timezone.utc
|
||||
)
|
||||
|
||||
event_times.append(timestamp)
|
||||
|
||||
if event_times:
|
||||
|
||||
start_time = min(event_times)
|
||||
|
||||
end_time = max(event_times)
|
||||
|
||||
db.conn.execute(
|
||||
"""
|
||||
UPDATE capture_sessions
|
||||
SET start_time = ?,
|
||||
end_time = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(
|
||||
start_time.isoformat().replace("+00:00", "Z"),
|
||||
end_time.isoformat().replace("+00:00", "Z"),
|
||||
session_id,
|
||||
),
|
||||
)
|
||||
|
||||
recovered = db.finalize_session(
|
||||
session_id
|
||||
)
|
||||
|
||||
db.commit()
|
||||
|
||||
if not recovered:
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"error": (
|
||||
"Parsing completed, but no GPS positions, "
|
||||
"access points or handshakes were found. "
|
||||
"The empty database record was removed."
|
||||
)
|
||||
}
|
||||
), 422
|
||||
|
||||
logger.info(
|
||||
"Interrupted capture recovered: %s (session_id=%s)",
|
||||
session_path,
|
||||
session_id,
|
||||
)
|
||||
|
||||
return redirect(
|
||||
url_for("reports_trips")
|
||||
)
|
||||
|
||||
except Exception:
|
||||
|
||||
if db is not None:
|
||||
|
||||
try:
|
||||
db.rollback()
|
||||
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to rollback session recovery."
|
||||
)
|
||||
|
||||
finally:
|
||||
db.observation_buffer.clear()
|
||||
|
||||
logger.exception(
|
||||
"Failed to recover interrupted capture: %s",
|
||||
session_path,
|
||||
)
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"error": "Failed to recover interrupted capture."
|
||||
}
|
||||
), 500
|
||||
|
||||
finally:
|
||||
|
||||
if db is not None:
|
||||
|
||||
try:
|
||||
db.close()
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to close database after session recovery."
|
||||
)
|
||||
|
||||
release_network_owner(
|
||||
"SESSION_RECOVERY"
|
||||
)
|
||||
|
||||
|
||||
@app.route("/reports/trips/preview")
|
||||
def reports_trips_preview():
|
||||
|
||||
@@ -3183,6 +3425,232 @@ def api_gps_test():
|
||||
|
||||
|
||||
|
||||
def _run_gpsrelay_discovery(port):
|
||||
global gpsrelay_discovery_job
|
||||
|
||||
try:
|
||||
result = discover_gpsrelay(port)
|
||||
|
||||
with gpsrelay_discovery_lock:
|
||||
gpsrelay_discovery_job = {
|
||||
"state": "SUCCEEDED",
|
||||
"running": False,
|
||||
"port": port,
|
||||
"result": result,
|
||||
"error": None,
|
||||
}
|
||||
|
||||
except GPSRelayDiscoveryError as error:
|
||||
|
||||
with gpsrelay_discovery_lock:
|
||||
gpsrelay_discovery_job = {
|
||||
"state": "FAILED",
|
||||
"running": False,
|
||||
"port": port,
|
||||
"result": None,
|
||||
"error": str(error),
|
||||
}
|
||||
|
||||
except Exception:
|
||||
app.logger.exception(
|
||||
"Unexpected GPSRelay discovery error"
|
||||
)
|
||||
|
||||
with gpsrelay_discovery_lock:
|
||||
gpsrelay_discovery_job = {
|
||||
"state": "FAILED",
|
||||
"running": False,
|
||||
"port": port,
|
||||
"result": None,
|
||||
"error": "Unexpected GPSRelay discovery error.",
|
||||
}
|
||||
|
||||
finally:
|
||||
try:
|
||||
release_network_owner("GPSRELAY_DISCOVERY")
|
||||
except Exception:
|
||||
app.logger.exception(
|
||||
"Could not release GPSRelay discovery network owner"
|
||||
)
|
||||
|
||||
|
||||
@app.route(
|
||||
"/api/wifi-verification/gpsrelay-discovery/start",
|
||||
methods=["POST"]
|
||||
)
|
||||
def api_wifi_verification_gpsrelay_discovery_start():
|
||||
global gpsrelay_discovery_job
|
||||
global gpsrelay_discovery_thread
|
||||
|
||||
payload = request.get_json(silent=True)
|
||||
|
||||
if payload is None:
|
||||
payload = {}
|
||||
|
||||
if not isinstance(payload, dict):
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "Invalid request body.",
|
||||
}
|
||||
), 400
|
||||
|
||||
raw_port = payload.get("port", 5000)
|
||||
|
||||
if raw_port is None or raw_port == "":
|
||||
raw_port = 5000
|
||||
|
||||
if isinstance(raw_port, bool):
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "Port must be an integer between 1 and 65535.",
|
||||
}
|
||||
), 400
|
||||
|
||||
if isinstance(raw_port, int):
|
||||
port = raw_port
|
||||
elif isinstance(raw_port, str) and raw_port.strip().isdigit():
|
||||
port = int(raw_port.strip())
|
||||
else:
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "Port must be an integer between 1 and 65535.",
|
||||
}
|
||||
), 400
|
||||
|
||||
if not 1 <= port <= 65535:
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "Port must be between 1 and 65535.",
|
||||
}
|
||||
), 400
|
||||
|
||||
start_error = False
|
||||
|
||||
with auto_wifi_verification_lock:
|
||||
|
||||
current = auto_wifi_verification_service
|
||||
|
||||
if (
|
||||
current is not None
|
||||
and current.thread is not None
|
||||
and current.thread.is_alive()
|
||||
):
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "Auto Verification is running.",
|
||||
}
|
||||
), 409
|
||||
|
||||
with gpsrelay_discovery_lock:
|
||||
|
||||
if (
|
||||
gpsrelay_discovery_thread is not None
|
||||
and gpsrelay_discovery_thread.is_alive()
|
||||
):
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "GPSRelay discovery is already running.",
|
||||
}
|
||||
), 409
|
||||
|
||||
acquired, error = acquire_network_owner(
|
||||
"GPSRELAY_DISCOVERY"
|
||||
)
|
||||
|
||||
if not acquired:
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": error or "Network interface is busy.",
|
||||
}
|
||||
), 409
|
||||
|
||||
gpsrelay_discovery_job = {
|
||||
"state": "RUNNING",
|
||||
"running": True,
|
||||
"port": port,
|
||||
"result": None,
|
||||
"error": None,
|
||||
}
|
||||
|
||||
gpsrelay_discovery_thread = threading.Thread(
|
||||
target=_run_gpsrelay_discovery,
|
||||
args=(port,),
|
||||
daemon=True,
|
||||
)
|
||||
|
||||
try:
|
||||
gpsrelay_discovery_thread.start()
|
||||
|
||||
except Exception:
|
||||
app.logger.exception(
|
||||
"Could not start GPSRelay discovery thread"
|
||||
)
|
||||
|
||||
gpsrelay_discovery_thread = None
|
||||
|
||||
gpsrelay_discovery_job = {
|
||||
"state": "FAILED",
|
||||
"running": False,
|
||||
"port": port,
|
||||
"result": None,
|
||||
"error": "Could not start GPSRelay discovery.",
|
||||
}
|
||||
|
||||
start_error = True
|
||||
|
||||
if start_error:
|
||||
release_network_owner("GPSRELAY_DISCOVERY")
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "Could not start GPSRelay discovery.",
|
||||
}
|
||||
), 500
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"ok": True,
|
||||
"state": "RUNNING",
|
||||
"port": port,
|
||||
}
|
||||
), 202
|
||||
|
||||
|
||||
@app.route(
|
||||
"/api/wifi-verification/gpsrelay-discovery/status",
|
||||
methods=["GET"]
|
||||
)
|
||||
def api_wifi_verification_gpsrelay_discovery_status():
|
||||
|
||||
with gpsrelay_discovery_lock:
|
||||
|
||||
if gpsrelay_discovery_job is None:
|
||||
job = {
|
||||
"state": "IDLE",
|
||||
"running": False,
|
||||
"port": None,
|
||||
"result": None,
|
||||
"error": None,
|
||||
}
|
||||
else:
|
||||
job = dict(gpsrelay_discovery_job)
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"ok": True,
|
||||
**job,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/api/wifi-verification/settings", methods=["GET"])
|
||||
def api_wifi_verification_settings():
|
||||
conn = None
|
||||
@@ -3598,7 +4066,6 @@ def api_wifi_verification_map_gps_start():
|
||||
service = wifi_verification_shared_gps_service
|
||||
|
||||
if wifi_verification_map_monitor_enabled:
|
||||
|
||||
if (
|
||||
service is not None
|
||||
and service.thread is not None
|
||||
@@ -3613,42 +4080,45 @@ def api_wifi_verification_map_gps_start():
|
||||
wifi_verification_map_monitor_enabled = False
|
||||
|
||||
if auto_running:
|
||||
if auto_service.verification_mode == "MANUAL":
|
||||
settings = auto_service.settings
|
||||
else:
|
||||
if (
|
||||
service is None
|
||||
or service.thread is None
|
||||
or not service.thread.is_alive()
|
||||
):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": (
|
||||
"GPS service used by Auto Verification "
|
||||
"is not running."
|
||||
)
|
||||
}), 409
|
||||
|
||||
wifi_verification_map_monitor_enabled = True
|
||||
|
||||
if (
|
||||
service is None
|
||||
or service.thread is None
|
||||
or not service.thread.is_alive()
|
||||
):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": (
|
||||
"GPS service used by Auto Verification "
|
||||
"is not running."
|
||||
)
|
||||
}), 409
|
||||
"ok": True,
|
||||
"monitor_enabled": True,
|
||||
"gps": service.get_status()
|
||||
})
|
||||
|
||||
wifi_verification_map_monitor_enabled = True
|
||||
else:
|
||||
connection = connect_database()
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"monitor_enabled": True,
|
||||
"gps": service.get_status()
|
||||
})
|
||||
row = connection.execute(
|
||||
"""
|
||||
SELECT *
|
||||
FROM wifi_verification_settings
|
||||
WHERE id = 1
|
||||
"""
|
||||
).fetchone()
|
||||
|
||||
connection = connect_database()
|
||||
settings = dict(row) if row is not None else None
|
||||
|
||||
row = connection.execute(
|
||||
"""
|
||||
SELECT *
|
||||
FROM wifi_verification_settings
|
||||
WHERE id = 1
|
||||
"""
|
||||
).fetchone()
|
||||
|
||||
settings = dict(row) if row is not None else None
|
||||
|
||||
close_database(connection)
|
||||
connection = None
|
||||
close_database(connection)
|
||||
connection = None
|
||||
|
||||
if settings is None:
|
||||
return jsonify({
|
||||
@@ -3665,20 +4135,7 @@ def api_wifi_verification_map_gps_start():
|
||||
):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": (
|
||||
"Select GPS source: gpsd or gpsrelay."
|
||||
)
|
||||
}), 409
|
||||
|
||||
acquired, owner_error = acquire_network_owner(
|
||||
"MAP_GPS_MONITOR"
|
||||
)
|
||||
|
||||
if not acquired:
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": owner_error,
|
||||
"owner": network_operation_owner
|
||||
"error": "Select GPS source: gpsd or gpsrelay."
|
||||
}), 409
|
||||
|
||||
service = _get_wifi_verification_shared_gps(
|
||||
@@ -3699,22 +4156,16 @@ def api_wifi_verification_map_gps_start():
|
||||
)
|
||||
|
||||
if not started:
|
||||
cleanup_ok = True
|
||||
thread = service.thread
|
||||
|
||||
if started_service:
|
||||
cleanup_ok = (
|
||||
if thread is None or not thread.is_alive():
|
||||
if started_service:
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
)
|
||||
|
||||
if cleanup_ok:
|
||||
release_network_owner(
|
||||
"MAP_GPS_MONITOR"
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "GPS service could not be started."
|
||||
}), 409
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "GPS service could not be started."
|
||||
}), 409
|
||||
|
||||
wifi_verification_map_monitor_enabled = True
|
||||
|
||||
@@ -3732,20 +4183,8 @@ def api_wifi_verification_map_gps_start():
|
||||
|
||||
with wifi_verification_shared_gps_lock:
|
||||
|
||||
cleanup_ok = True
|
||||
|
||||
if started_service and service is not None:
|
||||
cleanup_ok = (
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
)
|
||||
|
||||
if (
|
||||
cleanup_ok
|
||||
and network_operation_owner == "MAP_GPS_MONITOR"
|
||||
):
|
||||
release_network_owner(
|
||||
"MAP_GPS_MONITOR"
|
||||
)
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
@@ -3769,12 +4208,9 @@ def api_wifi_verification_map_gps_stop():
|
||||
with auto_wifi_verification_lock:
|
||||
with wifi_verification_shared_gps_lock:
|
||||
|
||||
wifi_verification_map_monitor_enabled = False
|
||||
|
||||
owner = network_operation_owner
|
||||
|
||||
if owner == "AUTO_WIFI_VERIFY":
|
||||
|
||||
service = wifi_verification_shared_gps_service
|
||||
|
||||
gps_status = (
|
||||
@@ -3783,67 +4219,39 @@ def api_wifi_verification_map_gps_stop():
|
||||
else None
|
||||
)
|
||||
|
||||
wifi_verification_map_monitor_enabled = False
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"monitor_enabled": False,
|
||||
"stop_deferred": True,
|
||||
"owner": owner,
|
||||
"gps": gps_status
|
||||
})
|
||||
|
||||
if owner == "MAP_GPS_MONITOR":
|
||||
|
||||
stopped = (
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
)
|
||||
|
||||
if not stopped:
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": (
|
||||
"GPS service did not stop. "
|
||||
"Its state was preserved."
|
||||
),
|
||||
"monitor_enabled": False
|
||||
}), 409
|
||||
|
||||
release_network_owner(
|
||||
"MAP_GPS_MONITOR"
|
||||
)
|
||||
|
||||
elif owner is not None:
|
||||
stopped = (
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
)
|
||||
|
||||
if not stopped:
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": (
|
||||
"GPS is owned by another operation."
|
||||
"GPS service did not stop. "
|
||||
"Its state was preserved."
|
||||
),
|
||||
"owner": owner,
|
||||
"monitor_enabled": False
|
||||
"monitor_enabled": (
|
||||
wifi_verification_map_monitor_enabled
|
||||
)
|
||||
}), 409
|
||||
|
||||
else:
|
||||
|
||||
service = wifi_verification_shared_gps_service
|
||||
|
||||
if (
|
||||
service is not None
|
||||
and service.thread is not None
|
||||
and service.thread.is_alive()
|
||||
):
|
||||
stopped = (
|
||||
_stop_wifi_verification_shared_gps_locked()
|
||||
)
|
||||
|
||||
if not stopped:
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "GPS service did not stop."
|
||||
}), 409
|
||||
wifi_verification_map_monitor_enabled = False
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"monitor_enabled": False,
|
||||
"stop_deferred": False
|
||||
"stop_deferred": False,
|
||||
"owner": owner
|
||||
})
|
||||
|
||||
except Exception:
|
||||
@@ -3919,6 +4327,51 @@ def api_wifi_verification_start():
|
||||
|
||||
interface = interface.strip()
|
||||
|
||||
mode = data.get("mode", "AUTO")
|
||||
|
||||
if not isinstance(mode, str):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "Invalid verification mode."
|
||||
}), 400
|
||||
|
||||
mode = mode.strip().upper()
|
||||
|
||||
if mode not in ("AUTO", "MANUAL"):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "Invalid verification mode."
|
||||
}), 400
|
||||
|
||||
manual_center = None
|
||||
|
||||
if mode == "MANUAL":
|
||||
coordinates = data.get("manual_center")
|
||||
|
||||
if (
|
||||
not isinstance(coordinates, list)
|
||||
or len(coordinates) != 2
|
||||
or any(type(value) not in (int, float) for value in coordinates)
|
||||
):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "Manual center must contain numeric latitude and longitude."
|
||||
}), 400
|
||||
|
||||
latitude = float(coordinates[0])
|
||||
longitude = float(coordinates[1])
|
||||
|
||||
if not (
|
||||
-90 <= latitude <= 90
|
||||
and -180 <= longitude <= 180
|
||||
):
|
||||
return jsonify({
|
||||
"ok": False,
|
||||
"error": "Manual center coordinates are out of range."
|
||||
}), 400
|
||||
|
||||
manual_center = (latitude, longitude)
|
||||
|
||||
device, error, status = validate_network_interface(
|
||||
interface
|
||||
)
|
||||
@@ -3977,7 +4430,10 @@ def api_wifi_verification_start():
|
||||
}
|
||||
), 409
|
||||
|
||||
if settings.get("gps_source") not in ("gpsd", "gpsrelay"):
|
||||
if (
|
||||
mode == "AUTO"
|
||||
and settings.get("gps_source") not in ("gpsd", "gpsrelay")
|
||||
):
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
@@ -4002,9 +4458,17 @@ def api_wifi_verification_start():
|
||||
}
|
||||
), 409
|
||||
|
||||
shared_gps_service = (
|
||||
_get_wifi_verification_shared_gps(settings)
|
||||
)
|
||||
if mode == "AUTO":
|
||||
shared_gps_service = (
|
||||
_get_wifi_verification_shared_gps(settings)
|
||||
)
|
||||
else:
|
||||
with wifi_verification_shared_gps_lock:
|
||||
shared_gps_service = (
|
||||
wifi_verification_shared_gps_service
|
||||
if wifi_verification_map_monitor_enabled
|
||||
else None
|
||||
)
|
||||
|
||||
service = AutoWiFiVerificationService(
|
||||
settings=settings,
|
||||
@@ -4019,7 +4483,9 @@ def api_wifi_verification_start():
|
||||
),
|
||||
release_network_owner=(
|
||||
release_wifi_verification_network_owner
|
||||
)
|
||||
),
|
||||
mode=mode,
|
||||
manual_center=manual_center
|
||||
)
|
||||
|
||||
auto_wifi_verification_service = service
|
||||
|
||||
+58
-1
@@ -1444,7 +1444,7 @@ pre {
|
||||
font: inherit;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
cursor: default;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.capture-mode-button.active {
|
||||
@@ -1835,6 +1835,24 @@ pre {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.auto-verification-relay-discovery {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.auto-verification-relay-discovery .button {
|
||||
min-width: 190px;
|
||||
}
|
||||
|
||||
#auto-gpsrelay-discovery-status {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.auto-verification-config .field {
|
||||
width: 100%;
|
||||
max-width: none;
|
||||
@@ -2238,6 +2256,21 @@ pre {
|
||||
box-shadow: 0 0 0 5px rgba(38, 136, 255, 0.25);
|
||||
}
|
||||
|
||||
.auto-manual-map-marker {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: 3px solid #fff;
|
||||
border-radius: 50%;
|
||||
background: #a855f7;
|
||||
box-shadow: 0 0 0 6px rgba(168, 85, 247, 0.25);
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.auto-manual-map-marker:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Auto Verification — map top row and layers */
|
||||
.capture-map-top-row {
|
||||
@@ -2819,3 +2852,27 @@ pre {
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#capture-map .auto-gps-follow-control button:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#capture-map .auto-gps-follow-control .auto-manual-center-button svg {
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.8;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
|
||||
#capture-map .auto-gps-follow-control .auto-gps-follow-button.is-manual {
|
||||
color: #2688ff;
|
||||
}
|
||||
|
||||
#capture-map .auto-gps-follow-control .auto-manual-center-button {
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
#capture-map .auto-gps-follow-control .auto-manual-center-button.active {
|
||||
color: #a855f7;
|
||||
}
|
||||
|
||||
@@ -53,19 +53,18 @@
|
||||
|
||||
<button
|
||||
type="button"
|
||||
id="auto-mode-button"
|
||||
class="capture-mode-button active"
|
||||
aria-pressed="true"
|
||||
disabled
|
||||
>
|
||||
Auto
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
id="manual-mode-button"
|
||||
class="capture-mode-button"
|
||||
aria-pressed="false"
|
||||
title="Будет доступен на следующем этапе"
|
||||
disabled
|
||||
>
|
||||
Manual
|
||||
</button>
|
||||
@@ -395,9 +394,26 @@
|
||||
name="gpsrelay_port"
|
||||
min="1"
|
||||
max="65535"
|
||||
value="5000"
|
||||
placeholder="1–65535"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="auto-verification-relay-discovery">
|
||||
<button
|
||||
type="button"
|
||||
class="button start"
|
||||
id="auto-gpsrelay-discover"
|
||||
>
|
||||
Найти GPS Relay
|
||||
</button>
|
||||
<div
|
||||
class="config-help"
|
||||
id="auto-gpsrelay-discovery-status"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -505,6 +521,12 @@
|
||||
const relayFields = document.getElementById("auto-gpsrelay-fields");
|
||||
const relayHost = document.getElementById("auto-gpsrelay-host");
|
||||
const relayPort = document.getElementById("auto-gpsrelay-port");
|
||||
const relayDiscoverButton = document.getElementById(
|
||||
"auto-gpsrelay-discover"
|
||||
);
|
||||
const relayDiscoveryStatus = document.getElementById(
|
||||
"auto-gpsrelay-discovery-status"
|
||||
);
|
||||
|
||||
const gnssMaxAge = document.getElementById("auto-gnss-max-age");
|
||||
const retryPasses = document.getElementById("auto-queue-retry-passes");
|
||||
@@ -525,6 +547,14 @@
|
||||
);
|
||||
|
||||
const settingsUrl = "/api/wifi-verification/settings";
|
||||
const relayDiscoveryStartUrl =
|
||||
"/api/wifi-verification/gpsrelay-discovery/start";
|
||||
const relayDiscoveryStatusUrl =
|
||||
"/api/wifi-verification/gpsrelay-discovery/status";
|
||||
|
||||
let relayDiscoveryTimer = null;
|
||||
let relayDiscoveryActive = false;
|
||||
let relayDiscoveryApplyResult = false;
|
||||
|
||||
function updateGpsSourceFields() {
|
||||
const useRelay = gpsSource.value === "gpsrelay";
|
||||
@@ -563,6 +593,150 @@
|
||||
radiusApplyStatus.classList.toggle("error", isError);
|
||||
}
|
||||
|
||||
function showRelayDiscoveryStatus(message, isError = false) {
|
||||
relayDiscoveryStatus.textContent = message;
|
||||
relayDiscoveryStatus.classList.toggle("error", isError);
|
||||
}
|
||||
|
||||
function scheduleRelayDiscoveryPoll() {
|
||||
if (relayDiscoveryTimer !== null) {
|
||||
window.clearTimeout(relayDiscoveryTimer);
|
||||
}
|
||||
|
||||
relayDiscoveryTimer = window.setTimeout(() => {
|
||||
relayDiscoveryTimer = null;
|
||||
refreshRelayDiscoveryStatus();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async function refreshRelayDiscoveryStatus() {
|
||||
try {
|
||||
const response = await fetch(relayDiscoveryStatusUrl);
|
||||
const job = await response.json();
|
||||
|
||||
if (!response.ok || !job.ok) {
|
||||
throw new Error(
|
||||
job.error || "Не удалось получить состояние поиска."
|
||||
);
|
||||
}
|
||||
|
||||
if (job.state === "RUNNING") {
|
||||
relayDiscoveryActive = true;
|
||||
relayDiscoveryApplyResult = true;
|
||||
relayDiscoverButton.disabled = true;
|
||||
|
||||
showRelayDiscoveryStatus(
|
||||
"Поиск GPSRelay и проверка потока NMEA…"
|
||||
);
|
||||
|
||||
scheduleRelayDiscoveryPoll();
|
||||
return;
|
||||
}
|
||||
|
||||
relayDiscoveryActive = false;
|
||||
relayDiscoverButton.disabled = false;
|
||||
|
||||
if (job.state === "SUCCEEDED" && job.result) {
|
||||
if (relayDiscoveryApplyResult) {
|
||||
const found = job.result;
|
||||
const types = Array.isArray(found.sentence_types)
|
||||
? found.sentence_types.join(", ")
|
||||
: "";
|
||||
|
||||
relayHost.value = found.host || relayHost.value;
|
||||
relayPort.value = found.port ?? relayPort.value;
|
||||
|
||||
showRelayDiscoveryStatus(
|
||||
`Найден GPSRelay: ${found.host}:${found.port}. `
|
||||
+ `Интерфейс: ${found.interface}. `
|
||||
+ `Корректных NMEA-предложений: `
|
||||
+ `${found.valid_sentences}. `
|
||||
+ `Типы: ${types}. `
|
||||
+ "Для сохранения нажмите SAVE."
|
||||
);
|
||||
} else {
|
||||
showRelayDiscoveryStatus("");
|
||||
}
|
||||
|
||||
} else if (job.state === "FAILED") {
|
||||
if (relayDiscoveryApplyResult) {
|
||||
showRelayDiscoveryStatus(
|
||||
job.error || "GPSRelay не найден.",
|
||||
true
|
||||
);
|
||||
} else {
|
||||
showRelayDiscoveryStatus("");
|
||||
}
|
||||
|
||||
} else {
|
||||
showRelayDiscoveryStatus("");
|
||||
}
|
||||
|
||||
relayDiscoveryApplyResult = false;
|
||||
|
||||
} catch (error) {
|
||||
if (relayDiscoveryActive) {
|
||||
relayDiscoverButton.disabled = true;
|
||||
showRelayDiscoveryStatus(
|
||||
`Не удалось обновить состояние поиска: ${error.message}`
|
||||
);
|
||||
scheduleRelayDiscoveryPoll();
|
||||
} else {
|
||||
relayDiscoverButton.disabled = false;
|
||||
showRelayDiscoveryStatus(error.message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function startRelayDiscovery() {
|
||||
const rawPort = relayPort.value.trim();
|
||||
const port = rawPort === "" ? 5000 : Number(rawPort);
|
||||
|
||||
if (
|
||||
!Number.isInteger(port)
|
||||
|| port < 1
|
||||
|| port > 65535
|
||||
) {
|
||||
showRelayDiscoveryStatus(
|
||||
"Укажите корректный порт от 1 до 65535.",
|
||||
true
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
relayDiscoverButton.disabled = true;
|
||||
relayDiscoveryActive = true;
|
||||
relayDiscoveryApplyResult = true;
|
||||
|
||||
showRelayDiscoveryStatus("Запуск поиска GPSRelay…");
|
||||
|
||||
try {
|
||||
const response = await fetch(relayDiscoveryStartUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ port: port })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok || !result.ok) {
|
||||
throw new Error(
|
||||
result.error || "Не удалось запустить поиск GPSRelay."
|
||||
);
|
||||
}
|
||||
|
||||
await refreshRelayDiscoveryStatus();
|
||||
|
||||
} catch (error) {
|
||||
relayDiscoveryActive = false;
|
||||
relayDiscoveryApplyResult = false;
|
||||
relayDiscoverButton.disabled = false;
|
||||
showRelayDiscoveryStatus(error.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function applyRadius() {
|
||||
const radius = getSelectedRadius();
|
||||
|
||||
@@ -598,6 +772,11 @@
|
||||
: `Радиус ${radius} м сохранён и будет использован при следующем запуске.`
|
||||
);
|
||||
|
||||
window.dispatchEvent(new CustomEvent(
|
||||
"wifi-verification-radius-applied",
|
||||
{ detail: { radius_m: radius } }
|
||||
));
|
||||
|
||||
} catch (error) {
|
||||
showRadiusStatus(error.message, true);
|
||||
|
||||
@@ -611,7 +790,7 @@
|
||||
gpsSource.value = settings.gps_source || "";
|
||||
|
||||
relayHost.value = settings.gpsrelay_host || "";
|
||||
relayPort.value = settings.gpsrelay_port ?? "";
|
||||
relayPort.value = settings.gpsrelay_port ?? "5000";
|
||||
|
||||
gnssMaxAge.value = settings.gnss_max_age_seconds;
|
||||
retryPasses.value = settings.queue_retry_passes;
|
||||
@@ -642,6 +821,7 @@
|
||||
|
||||
loadSettings(result.settings);
|
||||
showStatus("Настройки загружены.");
|
||||
refreshRelayDiscoveryStatus();
|
||||
|
||||
} catch (error) {
|
||||
showStatus(error.message, true);
|
||||
@@ -724,6 +904,10 @@
|
||||
});
|
||||
|
||||
saveButton.addEventListener("click", saveSettings);
|
||||
relayDiscoverButton.addEventListener(
|
||||
"click",
|
||||
startRelayDiscovery
|
||||
);
|
||||
radiusApplyButton.addEventListener("click", applyRadius);
|
||||
mapRadiusApplyButton.addEventListener("click", applyRadius);
|
||||
|
||||
@@ -734,7 +918,8 @@
|
||||
gpsSource.selectedIndex = 0;
|
||||
|
||||
relayHost.value = "";
|
||||
relayPort.value = "";
|
||||
relayPort.value = "5000";
|
||||
showRelayDiscoveryStatus("");
|
||||
|
||||
gnssMaxAge.value = "5";
|
||||
retryPasses.value = "1";
|
||||
@@ -767,6 +952,8 @@
|
||||
const count = document.getElementById("capture-map-count");
|
||||
const startButton = document.getElementById("auto-start");
|
||||
const stopButton = document.getElementById("auto-stop");
|
||||
const autoModeButton = document.getElementById("auto-mode-button");
|
||||
const manualModeButton = document.getElementById("manual-mode-button");
|
||||
const interfaceSelect = document.getElementById("auto-interface");
|
||||
const statusText = document.getElementById("header-scanner-status");
|
||||
const statusIndicator = document.getElementById("auto-status-indicator");
|
||||
@@ -797,6 +984,8 @@
|
||||
const gpsValue = document.querySelector(".auto-position-gps");
|
||||
const coordinatesInput = document.getElementById("auto-position-coordinates");
|
||||
const radiusText = document.getElementById("auto-position-radius");
|
||||
let manualCenterButton = null;
|
||||
const mapRadiusSelect = document.getElementById("auto-map-radius-select");
|
||||
|
||||
const filters = {
|
||||
green: true,
|
||||
@@ -815,6 +1004,10 @@
|
||||
let gpsLastRadius = null;
|
||||
let latestGpsPosition = null;
|
||||
let autoRunning = false;
|
||||
let verificationMode = "AUTO";
|
||||
let manualCenter = null;
|
||||
let manualMarker = null;
|
||||
let manualPlacementEnabled = false;
|
||||
|
||||
const map = new maplibregl.Map({
|
||||
container: "capture-map",
|
||||
@@ -855,8 +1048,6 @@
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "auto-gps-follow-button";
|
||||
button.title = "Вернуться к GPS";
|
||||
button.setAttribute("aria-label", "Вернуться к GPS");
|
||||
button.setAttribute("aria-pressed", "true");
|
||||
button.innerHTML = `
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
@@ -867,6 +1058,47 @@
|
||||
gpsFollowButton = button;
|
||||
|
||||
button.addEventListener("click", () => {
|
||||
if (verificationMode === "MANUAL") {
|
||||
if (!manualCenter) {
|
||||
setMessage("Сначала установите ручной центр проверки.");
|
||||
return;
|
||||
}
|
||||
|
||||
const radius = Number(mapRadiusSelect.value);
|
||||
const cameraOptions = {
|
||||
center: [
|
||||
manualCenter.longitude,
|
||||
manualCenter.latitude
|
||||
],
|
||||
duration: 500
|
||||
};
|
||||
|
||||
if (Number.isFinite(radius) && radius > 0) {
|
||||
const extent = buildGpsCircle(
|
||||
manualCenter.latitude,
|
||||
manualCenter.longitude,
|
||||
radius * 2
|
||||
);
|
||||
|
||||
const bounds = new maplibregl.LngLatBounds();
|
||||
|
||||
extent.geometry.coordinates[0].forEach(point => {
|
||||
bounds.extend(point);
|
||||
});
|
||||
|
||||
const camera = map.cameraForBounds(bounds, {
|
||||
padding: 0
|
||||
});
|
||||
|
||||
if (camera && Number.isFinite(camera.zoom)) {
|
||||
cameraOptions.zoom = camera.zoom;
|
||||
}
|
||||
}
|
||||
|
||||
map.easeTo(cameraOptions);
|
||||
return;
|
||||
}
|
||||
|
||||
setGpsFollowing(true);
|
||||
|
||||
if (latestGpsPosition) {
|
||||
@@ -882,16 +1114,59 @@
|
||||
});
|
||||
|
||||
container.appendChild(button);
|
||||
|
||||
const manualButton = document.createElement("button");
|
||||
manualButton.type = "button";
|
||||
manualButton.className = "auto-manual-center-button";
|
||||
manualButton.title = "Установить центр проверки";
|
||||
manualButton.setAttribute(
|
||||
"aria-label",
|
||||
"Установить центр проверки"
|
||||
);
|
||||
manualButton.disabled = true;
|
||||
manualButton.innerHTML = `
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="7"/>
|
||||
<circle cx="12" cy="12" r="2"/>
|
||||
<path d="M12 2v3M12 19v3M2 12h3M19 12h3"/>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
manualCenterButton = manualButton;
|
||||
|
||||
manualButton.addEventListener("click", () => {
|
||||
if (verificationMode !== "MANUAL" || autoRunning) return;
|
||||
|
||||
manualPlacementEnabled = !manualPlacementEnabled;
|
||||
|
||||
map.getCanvas().style.cursor = (
|
||||
manualPlacementEnabled ? "crosshair" : ""
|
||||
);
|
||||
|
||||
manualButton.classList.toggle(
|
||||
"active",
|
||||
manualPlacementEnabled
|
||||
);
|
||||
|
||||
setMessage(
|
||||
manualPlacementEnabled
|
||||
? "Выберите центр проверки щелчком на карте."
|
||||
: "Установка центра отменена."
|
||||
);
|
||||
});
|
||||
|
||||
container.appendChild(manualButton);
|
||||
|
||||
return container;
|
||||
},
|
||||
|
||||
onRemove() {
|
||||
gpsFollowButton = null;
|
||||
manualCenterButton = null;
|
||||
}
|
||||
};
|
||||
|
||||
map.addControl(gpsFollowControl, "top-right");
|
||||
|
||||
map.on("dragstart", pauseGpsFollowing);
|
||||
map.on("dblclick", pauseGpsFollowing);
|
||||
|
||||
@@ -969,8 +1244,38 @@
|
||||
return data;
|
||||
}
|
||||
|
||||
function renderModeButtons() {
|
||||
const isAuto = verificationMode === "AUTO";
|
||||
|
||||
autoModeButton.classList.toggle("active", isAuto);
|
||||
autoModeButton.setAttribute("aria-pressed", String(isAuto));
|
||||
|
||||
manualModeButton.classList.toggle("active", !isAuto);
|
||||
manualModeButton.setAttribute("aria-pressed", String(!isAuto));
|
||||
|
||||
autoModeButton.disabled = autoRunning;
|
||||
manualModeButton.disabled = autoRunning;
|
||||
|
||||
updateManualModeUI();
|
||||
}
|
||||
|
||||
function setVerificationMode(mode) {
|
||||
if (autoRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
verificationMode = mode === "MANUAL" ? "MANUAL" : "AUTO";
|
||||
|
||||
renderModeButtons();
|
||||
updateStartButton();
|
||||
}
|
||||
|
||||
function updateStartButton() {
|
||||
startButton.disabled = autoRunning || !interfaceSelect.value;
|
||||
startButton.disabled = (
|
||||
autoRunning ||
|
||||
!interfaceSelect.value ||
|
||||
(verificationMode === "MANUAL" && !manualCenter)
|
||||
);
|
||||
}
|
||||
|
||||
function createMonitorElement(tag, className, text) {
|
||||
@@ -1265,6 +1570,26 @@
|
||||
const running = Boolean(status.running);
|
||||
autoRunning = running;
|
||||
|
||||
if (running && status.verification_mode) {
|
||||
verificationMode = status.verification_mode === "MANUAL"
|
||||
? "MANUAL"
|
||||
: "AUTO";
|
||||
}
|
||||
|
||||
renderModeButtons();
|
||||
|
||||
if (
|
||||
running &&
|
||||
verificationMode === "MANUAL" &&
|
||||
Array.isArray(status.manual_center) &&
|
||||
status.manual_center.length === 2
|
||||
) {
|
||||
setManualCenter(
|
||||
Number(status.manual_center[0]),
|
||||
Number(status.manual_center[1])
|
||||
);
|
||||
}
|
||||
|
||||
const stateLabels = {
|
||||
STOPPED: "остановлен",
|
||||
WAITING_GPS: "ожидание GPS",
|
||||
@@ -1278,7 +1603,7 @@
|
||||
);
|
||||
|
||||
statusText.textContent =
|
||||
`Auto: ${stateLabels[actualState] || actualState}`;
|
||||
`${verificationMode === "MANUAL" ? "Manual" : "Auto"}: ${stateLabels[actualState] || actualState}`;
|
||||
|
||||
monitorState.textContent =
|
||||
stateLabels[actualState] || actualState;
|
||||
@@ -1367,6 +1692,149 @@
|
||||
};
|
||||
}
|
||||
|
||||
function updateManualCircle() {
|
||||
const source = map.getSource("manual-search-radius");
|
||||
|
||||
if (!source) return;
|
||||
|
||||
if (verificationMode !== "MANUAL" || !manualCenter) {
|
||||
source.setData(emptyGpsFeatureCollection());
|
||||
return;
|
||||
}
|
||||
|
||||
const radius = Number(mapRadiusSelect.value);
|
||||
|
||||
if (!Number.isFinite(radius) || radius <= 0) {
|
||||
source.setData(emptyGpsFeatureCollection());
|
||||
return;
|
||||
}
|
||||
|
||||
source.setData({
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
buildGpsCircle(
|
||||
manualCenter.latitude,
|
||||
manualCenter.longitude,
|
||||
radius
|
||||
)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
function updateManualModeUI() {
|
||||
const manualMode = verificationMode === "MANUAL";
|
||||
|
||||
if (manualMode) {
|
||||
gpsPositionActive = false;
|
||||
gpsCenterKey = null;
|
||||
}
|
||||
|
||||
if (gpsFollowButton) {
|
||||
gpsFollowButton.title = manualMode
|
||||
? "К центру проверки"
|
||||
: "Вернуться к GPS";
|
||||
gpsFollowButton.setAttribute(
|
||||
"aria-label",
|
||||
gpsFollowButton.title
|
||||
);
|
||||
gpsFollowButton.classList.toggle(
|
||||
"is-active",
|
||||
!manualMode && gpsFollowEnabled
|
||||
);
|
||||
gpsFollowButton.classList.toggle(
|
||||
"is-manual",
|
||||
manualMode
|
||||
);
|
||||
gpsFollowButton.setAttribute(
|
||||
"aria-pressed",
|
||||
String(!manualMode && gpsFollowEnabled)
|
||||
);
|
||||
}
|
||||
|
||||
if (manualCenterButton) {
|
||||
manualCenterButton.style.display = manualMode ? "" : "none";
|
||||
manualCenterButton.disabled = !manualMode || autoRunning;
|
||||
}
|
||||
|
||||
if (!manualMode || autoRunning) {
|
||||
manualPlacementEnabled = false;
|
||||
map.getCanvas().style.cursor = "";
|
||||
|
||||
if (manualCenterButton) {
|
||||
manualCenterButton.classList.remove("active");
|
||||
}
|
||||
}
|
||||
|
||||
if (manualMarker) {
|
||||
manualMarker.setDraggable(!autoRunning);
|
||||
manualMarker.getElement().style.display = (
|
||||
manualMode ? "" : "none"
|
||||
);
|
||||
}
|
||||
|
||||
updateManualCircle();
|
||||
}
|
||||
|
||||
function setManualCenter(latitude, longitude) {
|
||||
if (
|
||||
!Number.isFinite(latitude) ||
|
||||
!Number.isFinite(longitude) ||
|
||||
latitude < -90 ||
|
||||
latitude > 90 ||
|
||||
longitude < -180 ||
|
||||
longitude > 180
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
manualCenter = { latitude, longitude };
|
||||
|
||||
if (!manualMarker) {
|
||||
const element = document.createElement("div");
|
||||
element.className = "auto-manual-map-marker";
|
||||
|
||||
manualMarker = new maplibregl.Marker({
|
||||
element,
|
||||
draggable: !autoRunning
|
||||
})
|
||||
.setLngLat([longitude, latitude])
|
||||
.addTo(map);
|
||||
|
||||
manualMarker.on("dragend", () => {
|
||||
if (autoRunning) return;
|
||||
|
||||
const position = manualMarker.getLngLat();
|
||||
|
||||
manualCenter = {
|
||||
latitude: position.lat,
|
||||
longitude: position.lng
|
||||
};
|
||||
|
||||
coordinatesInput.value = (
|
||||
`${position.lat.toFixed(6)}, ${position.lng.toFixed(6)}`
|
||||
);
|
||||
|
||||
updateManualCircle();
|
||||
updateStartButton();
|
||||
});
|
||||
} else {
|
||||
manualMarker
|
||||
.setLngLat([longitude, latitude])
|
||||
.setDraggable(!autoRunning);
|
||||
|
||||
manualMarker.getElement().style.display = (
|
||||
verificationMode === "MANUAL" ? "" : "none"
|
||||
);
|
||||
}
|
||||
|
||||
coordinatesInput.value = (
|
||||
`${latitude.toFixed(6)}, ${longitude.toFixed(6)}`
|
||||
);
|
||||
|
||||
updateManualCircle();
|
||||
updateStartButton();
|
||||
}
|
||||
|
||||
function updateGpsMap(latitude, longitude, radiusMeters) {
|
||||
const source = map.getSource("auto-gps-radius");
|
||||
|
||||
@@ -1383,7 +1851,9 @@
|
||||
gpsMarker.setLngLat([longitude, latitude]);
|
||||
}
|
||||
|
||||
if (Number.isFinite(radiusMeters) && radiusMeters > 0) {
|
||||
if (verificationMode === "MANUAL") {
|
||||
source.setData(emptyGpsFeatureCollection());
|
||||
} else if (Number.isFinite(radiusMeters) && radiusMeters > 0) {
|
||||
source.setData({
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
@@ -1402,6 +1872,10 @@
|
||||
radiusMeters
|
||||
};
|
||||
|
||||
if (verificationMode === "MANUAL") {
|
||||
return;
|
||||
}
|
||||
|
||||
const validRadius = (
|
||||
Number.isFinite(radiusMeters) && radiusMeters > 0
|
||||
);
|
||||
@@ -1469,7 +1943,10 @@
|
||||
gpsCenterKey = null;
|
||||
gpsLastRadius = null;
|
||||
latestGpsPosition = null;
|
||||
setGpsFollowing(true);
|
||||
|
||||
if (verificationMode !== "MANUAL") {
|
||||
setGpsFollowing(true);
|
||||
}
|
||||
}
|
||||
|
||||
function updateGpsStatus(data) {
|
||||
@@ -1477,7 +1954,7 @@
|
||||
const monitorEnabled = Boolean(data.monitor_enabled);
|
||||
const running = Boolean(gps.running);
|
||||
const hasFix = (
|
||||
(monitorEnabled || data.owner === "AUTO_WIFI_VERIFY") &&
|
||||
monitorEnabled &&
|
||||
running &&
|
||||
Boolean(gps.has_fresh_fix) &&
|
||||
gps.latitude !== null &&
|
||||
@@ -1508,11 +1985,18 @@
|
||||
gpsValue.classList.add("is-searching");
|
||||
gpsDetail.textContent = (
|
||||
running
|
||||
? "GPS используется другой операцией; монитор карты выключен"
|
||||
? (
|
||||
data.owner === "AUTO_WIFI_VERIFY"
|
||||
? "GPS продолжает работать для Auto Verification; монитор карты выключен"
|
||||
: "GPS работает, монитор карты выключен"
|
||||
)
|
||||
: "GPS-монитор карты остановлен"
|
||||
);
|
||||
|
||||
coordinatesInput.value = "";
|
||||
if (verificationMode !== "MANUAL") {
|
||||
coordinatesInput.value = "";
|
||||
}
|
||||
|
||||
clearGpsMap();
|
||||
return;
|
||||
}
|
||||
@@ -1525,9 +2009,11 @@
|
||||
const latitude = Number(gps.latitude);
|
||||
const longitude = Number(gps.longitude);
|
||||
|
||||
coordinatesInput.value = (
|
||||
`${latitude.toFixed(6)}, ${longitude.toFixed(6)}`
|
||||
);
|
||||
if (verificationMode !== "MANUAL") {
|
||||
coordinatesInput.value = (
|
||||
`${latitude.toFixed(6)}, ${longitude.toFixed(6)}`
|
||||
);
|
||||
}
|
||||
|
||||
const age = Number(gps.fix_age_seconds);
|
||||
const ageText = Number.isFinite(age)
|
||||
@@ -1542,7 +2028,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
coordinatesInput.value = "";
|
||||
if (verificationMode !== "MANUAL") {
|
||||
coordinatesInput.value = "";
|
||||
}
|
||||
|
||||
clearGpsMap();
|
||||
|
||||
if (gps.state === "ERROR") {
|
||||
@@ -1637,7 +2126,11 @@
|
||||
visibleCoordinates.push(coordinates);
|
||||
});
|
||||
|
||||
if (visibleCoordinates.length && !gpsPositionActive) {
|
||||
if (
|
||||
visibleCoordinates.length &&
|
||||
!gpsPositionActive &&
|
||||
!(verificationMode === "MANUAL" && manualCenter)
|
||||
) {
|
||||
const bounds = new maplibregl.LngLatBounds();
|
||||
visibleCoordinates.forEach(point => bounds.extend(point));
|
||||
map.fitBounds(bounds, { padding: 45, maxZoom: 15 });
|
||||
@@ -1666,6 +2159,37 @@
|
||||
|
||||
interfaceSelect.addEventListener("change", updateStartButton);
|
||||
|
||||
map.on("click", event => {
|
||||
if (
|
||||
verificationMode !== "MANUAL" ||
|
||||
autoRunning ||
|
||||
!manualPlacementEnabled
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
setManualCenter(event.lngLat.lat, event.lngLat.lng);
|
||||
|
||||
manualPlacementEnabled = false;
|
||||
map.getCanvas().style.cursor = "";
|
||||
manualCenterButton.classList.remove("active");
|
||||
|
||||
setMessage("Ручной центр установлен.");
|
||||
});
|
||||
|
||||
window.addEventListener(
|
||||
"wifi-verification-radius-applied",
|
||||
updateManualCircle
|
||||
);
|
||||
|
||||
autoModeButton.addEventListener("click", () => {
|
||||
setVerificationMode("AUTO");
|
||||
});
|
||||
|
||||
manualModeButton.addEventListener("click", () => {
|
||||
setVerificationMode("MANUAL");
|
||||
});
|
||||
|
||||
startButton.addEventListener("click", async () => {
|
||||
const interfaceName = interfaceSelect.value;
|
||||
|
||||
@@ -1675,22 +2199,46 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (verificationMode === "MANUAL" && !manualCenter) {
|
||||
setMessage("Сначала установите ручной центр проверки.");
|
||||
updateStartButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
interface: interfaceName,
|
||||
mode: verificationMode
|
||||
};
|
||||
|
||||
if (verificationMode === "MANUAL") {
|
||||
payload.manual_center = [
|
||||
manualCenter.latitude,
|
||||
manualCenter.longitude
|
||||
];
|
||||
}
|
||||
|
||||
startButton.disabled = true;
|
||||
setMessage("Запуск Auto Verification…");
|
||||
setMessage(
|
||||
verificationMode === "MANUAL"
|
||||
? "Запуск Manual Verification…"
|
||||
: "Запуск Auto Verification…"
|
||||
);
|
||||
|
||||
try {
|
||||
await requestJson(startUrl, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
interface: interfaceName
|
||||
})
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
await refreshStatus();
|
||||
setMessage("Auto Verification запущен.");
|
||||
setMessage(
|
||||
verificationMode === "MANUAL"
|
||||
? "Manual Verification запущен."
|
||||
: "Auto Verification запущен."
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
setMessage(`Не удалось запустить Auto Verification: ${error.message}`);
|
||||
setMessage(`Не удалось запустить проверку: ${error.message}`);
|
||||
await refreshStatus();
|
||||
}
|
||||
});
|
||||
@@ -1756,6 +2304,33 @@
|
||||
}
|
||||
});
|
||||
|
||||
map.addSource("manual-search-radius", {
|
||||
type: "geojson",
|
||||
data: emptyGpsFeatureCollection()
|
||||
});
|
||||
|
||||
map.addLayer({
|
||||
id: "manual-search-radius-fill",
|
||||
type: "fill",
|
||||
source: "manual-search-radius",
|
||||
paint: {
|
||||
"fill-color": "#a855f7",
|
||||
"fill-opacity": 0.12
|
||||
}
|
||||
});
|
||||
|
||||
map.addLayer({
|
||||
id: "manual-search-radius-line",
|
||||
type: "line",
|
||||
source: "manual-search-radius",
|
||||
paint: {
|
||||
"line-color": "#a855f7",
|
||||
"line-width": 2,
|
||||
"line-opacity": 0.9
|
||||
}
|
||||
});
|
||||
|
||||
updateManualCircle();
|
||||
refreshMap();
|
||||
refreshGpsStatus();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user