1773 lines
58 KiB
HTML
1773 lines
58 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>🗺 Capture Map — WiFi GPS Mapper</title>
|
||
|
||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||
<link rel="stylesheet"
|
||
href="{{ url_for('auto_verification_map_asset', filename='maplibre-gl.css') }}">
|
||
|
||
|
||
</head>
|
||
<body class="auto-verification-page">
|
||
<header class="app-header">
|
||
|
||
<div class="header-inner">
|
||
|
||
<a
|
||
class="report-brand"
|
||
href="{{ url_for('index') }}"
|
||
>
|
||
<h1>
|
||
WiFi GPS Mapper
|
||
</h1>
|
||
|
||
<div class="subtitle">
|
||
Wireless network scanner
|
||
</div>
|
||
</a>
|
||
|
||
<div class="header-actions">
|
||
|
||
<a
|
||
class="header-link"
|
||
href="{{ url_for('reports_dashboard') }}"
|
||
>
|
||
REPORTS
|
||
</a>
|
||
|
||
<a
|
||
class="header-link"
|
||
href="{{ url_for('cracklab.dashboard') }}"
|
||
>
|
||
CRACKLAB
|
||
</a>
|
||
|
||
<div class="header-scanner-controls">
|
||
|
||
<div class="capture-mode-switch"
|
||
role="group"
|
||
aria-label="Режим проверки">
|
||
|
||
<button
|
||
type="button"
|
||
class="capture-mode-button active"
|
||
aria-pressed="true"
|
||
disabled
|
||
>
|
||
Auto
|
||
</button>
|
||
|
||
<button
|
||
type="button"
|
||
class="capture-mode-button"
|
||
aria-pressed="false"
|
||
title="Будет доступен на следующем этапе"
|
||
disabled
|
||
>
|
||
Manual
|
||
</button>
|
||
|
||
</div>
|
||
|
||
<div class="auto-gps-actions">
|
||
<button
|
||
type="button"
|
||
class="auto-gps-button"
|
||
id="auto-gps-start"
|
||
>Вкл GPS</button>
|
||
<button
|
||
type="button"
|
||
class="auto-gps-button secondary"
|
||
id="auto-gps-stop"
|
||
disabled
|
||
>Выкл GPS</button>
|
||
</div>
|
||
|
||
<div
|
||
class="header-status auto-position-gps"
|
||
aria-live="polite"
|
||
>
|
||
<span
|
||
class="status-indicator warning"
|
||
id="auto-gps-indicator"
|
||
></span>
|
||
<span id="auto-gps-state">GPS ВЫКЛЮЧЕН</span>
|
||
</div>
|
||
|
||
<button
|
||
type="button"
|
||
id="auto-start"
|
||
class="header-button start"
|
||
disabled
|
||
title="Запуск станет доступен после настройки Wi-Fi интерфейса"
|
||
>
|
||
START
|
||
</button>
|
||
|
||
<button
|
||
type="button"
|
||
id="auto-stop"
|
||
class="header-button stop"
|
||
disabled
|
||
>
|
||
STOP
|
||
</button>
|
||
|
||
</div>
|
||
|
||
<div
|
||
id="auto-header-status"
|
||
class="header-status stopped"
|
||
>
|
||
|
||
<span
|
||
id="auto-status-indicator"
|
||
class="status-indicator stopped"
|
||
></span>
|
||
|
||
<span
|
||
id="header-scanner-status"
|
||
class="status-text"
|
||
>
|
||
Auto: остановлен
|
||
</span>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</header>
|
||
|
||
<main class="capture-map-page">
|
||
|
||
<div class="capture-map-page-heading auto-verification-page-heading">
|
||
<div class="auto-verification-section">REPORTS</div>
|
||
<div class="auto-verification-parent">Access Points</div>
|
||
<h1 class="auto-verification-title">🛡️ Auto Verification</h1>
|
||
<p class="panel-hint">
|
||
Географическое отображение результатов проверки паролей Wi-Fi.
|
||
</p>
|
||
</div>
|
||
|
||
<section class="panel auto-verification-monitor" aria-label="Монитор автоматической проверки">
|
||
<div class="panel-heading auto-monitor-heading">
|
||
<div>
|
||
<div class="panel-kicker">AUTO VERIFICATION ENGINE</div>
|
||
<h2>MONITOR</h2>
|
||
</div>
|
||
<div class="auto-monitor-count" id="auto-monitor-state">
|
||
Ожидание данных
|
||
</div>
|
||
</div>
|
||
|
||
<div class="auto-monitor-grid">
|
||
<section class="auto-monitor-column" aria-label="Кандидаты на проверку">
|
||
<div class="auto-monitor-column-heading">
|
||
<h3>Кандидаты на проверку</h3>
|
||
<span class="auto-monitor-count" id="auto-monitor-candidates-count">0 AP</span>
|
||
</div>
|
||
<div class="auto-monitor-list" id="auto-monitor-candidates">
|
||
<div class="auto-monitor-empty">Нет данных о кандидатах</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="auto-monitor-column" aria-label="Очередь проверки">
|
||
<div class="auto-monitor-column-heading">
|
||
<h3>Очередь проверки</h3>
|
||
<span class="auto-monitor-count" id="auto-monitor-queue-count">0 AP</span>
|
||
</div>
|
||
<div class="auto-monitor-list" id="auto-monitor-queue">
|
||
<div class="auto-monitor-empty">Очередь пуста</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="auto-monitor-column auto-monitor-statistics"
|
||
aria-label="Статистика проверок">
|
||
<div class="auto-monitor-column-heading">
|
||
<h3>Статистика</h3>
|
||
<span class="auto-monitor-count" id="auto-monitor-attempts-count">0</span>
|
||
</div>
|
||
|
||
<div class="auto-monitor-stat-group">
|
||
<div class="auto-monitor-stat-item is-success">
|
||
<span>Пароль верен</span>
|
||
<strong id="auto-stat-success">0</strong>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="auto-monitor-stat-group">
|
||
<div class="auto-monitor-stat-item is-warning">
|
||
<span>Точка не обнаружена</span>
|
||
<strong id="auto-stat-ap-not-found">0</strong>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="auto-monitor-stat-group">
|
||
<div class="auto-monitor-stat-item is-error">
|
||
<span>Неверный пароль</span>
|
||
<strong id="auto-stat-invalid-password">0</strong>
|
||
</div>
|
||
|
||
<div class="auto-monitor-stat-item is-error">
|
||
<span>Тайм-аут подключения</span>
|
||
<strong id="auto-stat-connection-timeout">0</strong>
|
||
</div>
|
||
|
||
<div class="auto-monitor-stat-item is-error">
|
||
<span>Ошибка сети</span>
|
||
<strong id="auto-stat-network-error">0</strong>
|
||
</div>
|
||
|
||
<div class="auto-monitor-stat-item is-error">
|
||
<span>Неизвестная ошибка</span>
|
||
<strong id="auto-stat-unknown-error">0</strong>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<section class="auto-monitor-log" aria-label="Журнал событий">
|
||
<div class="auto-monitor-log-heading">
|
||
<h3>Журнал событий</h3>
|
||
<span>Последние события</span>
|
||
</div>
|
||
|
||
<div class="auto-monitor-log-list" id="auto-monitor-events">
|
||
<div class="auto-monitor-empty">Событий пока нет</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<section class="capture-map-card panel" aria-label="Карта точек проверки">
|
||
<div class="capture-map-top-row">
|
||
<div class="capture-map-radius">
|
||
<span class="auto-position-label">SEARCH RADIUS</span>
|
||
<strong id="auto-position-radius">—</strong>
|
||
</div>
|
||
|
||
<div class="capture-map-scan-radius">
|
||
<span class="auto-config-section-title">SCAN RADIUS</span>
|
||
<label for="auto-map-radius-select">Available Radius</label>
|
||
<select id="auto-map-radius-select">
|
||
{% for radius in [50, 75, 100, 125, 150, 175, 200, 250, 350, 500] %}
|
||
<option value="{{ radius }}"{% if radius == 100 %} selected{% endif %}>
|
||
{{ radius }} m
|
||
</option>
|
||
{% endfor %}
|
||
</select>
|
||
<button
|
||
type="button"
|
||
class="button start auto-map-radius-apply"
|
||
id="auto-map-radius-apply"
|
||
>
|
||
APPLY
|
||
</button>
|
||
</div>
|
||
|
||
<div class="capture-map-gps-controls">
|
||
<p class="config-help capture-map-gps-detail" id="auto-gps-detail">
|
||
GPS-монитор карты остановлен
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="capture-map-layers-row">
|
||
<span class="session-map-title-text">🗺 Capture Map</span>
|
||
|
||
<span class="session-map-controls">
|
||
<label>
|
||
<input type="checkbox" data-map-filter="green" checked>
|
||
<span class="map-layer-dot map-layer-dot-verified"></span>
|
||
Verified
|
||
</label>
|
||
|
||
<label>
|
||
<input type="checkbox" data-map-filter="red" checked>
|
||
<span class="map-layer-dot map-layer-dot-invalid-password"></span>
|
||
Invalid password
|
||
</label>
|
||
|
||
<label>
|
||
<input type="checkbox" data-map-filter="orange" checked>
|
||
<span class="map-layer-dot map-layer-dot-technical-error"></span>
|
||
Technical error
|
||
</label>
|
||
|
||
<label>
|
||
<input type="checkbox" data-map-filter="gray" checked>
|
||
<span class="map-layer-dot map-layer-dot-not-verified"></span>
|
||
Not verified / incomplete
|
||
</label>
|
||
</span>
|
||
</div>
|
||
|
||
<div id="capture-map-message" role="status"></div>
|
||
<div id="capture-map"></div>
|
||
|
||
<div class="capture-map-toolbar">
|
||
<span id="capture-map-count">Загрузка точек…</span>
|
||
<div class="capture-map-coordinate">
|
||
<label for="auto-position-coordinates">Координаты центра</label>
|
||
<input
|
||
type="text"
|
||
id="auto-position-coordinates"
|
||
placeholder="Широта, долгота"
|
||
autocomplete="off"
|
||
spellcheck="false"
|
||
>
|
||
</div>
|
||
<button type="button" id="capture-map-refresh" class="button">
|
||
Обновить карту
|
||
</button>
|
||
</div>
|
||
</section>
|
||
|
||
|
||
|
||
<section class="panel auto-verification-config">
|
||
<div class="panel-heading">
|
||
<div>
|
||
<div class="panel-kicker">AUTO VERIFICATION</div>
|
||
<h2>CONFIGURATION</h2>
|
||
</div>
|
||
<p class="panel-hint">Параметры подключения и проверки</p>
|
||
</div>
|
||
|
||
<div class="auto-verification-top-grid">
|
||
<div class="field">
|
||
<label for="auto-interface">Wi-Fi Interface</label>
|
||
<select id="auto-interface" name="interface" required>
|
||
<option value="">Select interface</option>
|
||
{% for interface in interfaces %}
|
||
<option value="{{ interface }}">{{ interface }}</option>
|
||
{% endfor %}
|
||
</select>
|
||
{% if interface_error %}
|
||
<div class="config-help">{{ interface_error }}</div>
|
||
{% endif %}
|
||
{% if not interfaces and not interface_error %}
|
||
<div class="config-help">Wi-Fi-интерфейсы не найдены.</div>
|
||
{% endif %}
|
||
</div>
|
||
|
||
<div class="auto-config-gps-column">
|
||
<div class="field">
|
||
<label for="auto-gps-source">GPS Source</label>
|
||
<select id="auto-gps-source" name="gps_source" required>
|
||
<option value="">Select GPS source</option>
|
||
<option value="gpsd">GPSD</option>
|
||
<option value="gpsrelay">GPSRelay</option>
|
||
</select>
|
||
<div class="config-help">
|
||
GPSD использует локальную службу gpsd и GPS-приёмник.
|
||
GPSRelay получает координаты с вашего телефона.
|
||
</div>
|
||
</div>
|
||
|
||
<div
|
||
class="auto-verification-relay-fields"
|
||
id="auto-gpsrelay-fields"
|
||
hidden
|
||
>
|
||
<div class="field">
|
||
<label for="auto-gpsrelay-host">GPSRelay Host (phone IP)</label>
|
||
<input
|
||
type="text"
|
||
id="auto-gpsrelay-host"
|
||
name="gpsrelay_host"
|
||
placeholder="192.168.x.x"
|
||
autocomplete="off"
|
||
spellcheck="false"
|
||
>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label for="auto-gpsrelay-port">GPSRelay Port</label>
|
||
<input
|
||
type="number"
|
||
id="auto-gpsrelay-port"
|
||
name="gpsrelay_port"
|
||
min="1"
|
||
max="65535"
|
||
placeholder="1–65535"
|
||
>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="auto-verification-main-grid">
|
||
<div class="auto-config-section">
|
||
<div class="auto-config-section-title">SCAN RADIUS</div>
|
||
|
||
<div class="field auto-config-radius-field">
|
||
<label>Available Radius</label>
|
||
<div class="auto-verification-radius-options">
|
||
{% for radius in [50, 75, 100, 125, 150, 175, 200, 250, 350, 500] %}
|
||
<button
|
||
type="button"
|
||
class="auto-verification-radius-button{% if radius == 100 %} active{% endif %}"
|
||
data-radius="{{ radius }}"
|
||
aria-pressed="{{ 'true' if radius == 100 else 'false' }}"
|
||
>
|
||
{{ radius }} m
|
||
</button>
|
||
{% endfor %}
|
||
</div>
|
||
<div class="auto-verification-radius-actions">
|
||
<button
|
||
type="button"
|
||
class="button start auto-verification-radius-apply"
|
||
id="auto-verification-radius-apply"
|
||
>
|
||
APPLY
|
||
</button>
|
||
<div
|
||
class="auto-verification-radius-status"
|
||
id="auto-verification-radius-status"
|
||
role="status"
|
||
aria-live="polite"
|
||
></div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div class="auto-config-section">
|
||
<div class="auto-config-section-title">PROCESSING</div>
|
||
|
||
<div class="auto-verification-processing-grid">
|
||
<div class="field auto-config-number-field">
|
||
<label for="auto-gnss-max-age">GNSS Max Age (seconds)</label>
|
||
<input type="number" id="auto-gnss-max-age" min="1" max="30" value="5">
|
||
<div class="config-help">
|
||
Максимальный возраст координат GPS, которые принимает
|
||
система. Более старые координаты игнорируются.
|
||
</div>
|
||
<div class="config-help">
|
||
Допустимое значение: от 1 до 30 секунд.
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field auto-config-number-field">
|
||
<label for="auto-queue-retry-passes">Queue Retry Passes</label>
|
||
<input type="number" id="auto-queue-retry-passes" min="0" max="5" value="1">
|
||
<div class="config-help">
|
||
Количество дополнительных проходов для повторной проверки
|
||
точек, проверка которых завершилась неудачно.
|
||
</div>
|
||
<div class="config-help">
|
||
Допустимое значение: от 0 до 5 проходов.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="configuration-actions auto-verification-config-actions">
|
||
<div
|
||
id="auto-verification-save-status"
|
||
class="config-help"
|
||
role="status"
|
||
aria-live="polite"
|
||
></div>
|
||
|
||
<button
|
||
type="button"
|
||
class="button auto-verification-reset"
|
||
id="auto-verification-reset"
|
||
>
|
||
RESET
|
||
</button>
|
||
|
||
<button
|
||
type="button"
|
||
class="button start"
|
||
id="auto-verification-save"
|
||
>
|
||
SAVE
|
||
</button>
|
||
</div>
|
||
</section>
|
||
|
||
</main>
|
||
|
||
<script id="auto-verification-config-ui">
|
||
(() => {
|
||
const interfaceSelect = document.getElementById("auto-interface");
|
||
const gpsSource = document.getElementById("auto-gps-source");
|
||
const relayFields = document.getElementById("auto-gpsrelay-fields");
|
||
const relayHost = document.getElementById("auto-gpsrelay-host");
|
||
const relayPort = document.getElementById("auto-gpsrelay-port");
|
||
|
||
const gnssMaxAge = document.getElementById("auto-gnss-max-age");
|
||
const retryPasses = document.getElementById("auto-queue-retry-passes");
|
||
|
||
const saveButton = document.getElementById("auto-verification-save");
|
||
const saveStatus = document.getElementById("auto-verification-save-status");
|
||
const radiusApplyButton = document.getElementById(
|
||
"auto-verification-radius-apply"
|
||
);
|
||
const radiusApplyStatus = document.getElementById(
|
||
"auto-verification-radius-status"
|
||
);
|
||
const mapRadiusSelect = document.getElementById("auto-map-radius-select");
|
||
const mapRadiusApplyButton = document.getElementById("auto-map-radius-apply");
|
||
|
||
const radiusButtons = Array.from(
|
||
document.querySelectorAll(".auto-verification-radius-button")
|
||
);
|
||
|
||
const settingsUrl = "/api/wifi-verification/settings";
|
||
|
||
function updateGpsSourceFields() {
|
||
const useRelay = gpsSource.value === "gpsrelay";
|
||
|
||
relayFields.hidden = !useRelay;
|
||
relayHost.required = useRelay;
|
||
relayPort.required = useRelay;
|
||
}
|
||
|
||
function selectRadius(radius) {
|
||
radiusButtons.forEach(button => {
|
||
const active = Number(button.dataset.radius) === radius;
|
||
|
||
button.classList.toggle("active", active);
|
||
button.setAttribute("aria-pressed", String(active));
|
||
});
|
||
|
||
mapRadiusSelect.value = String(radius);
|
||
}
|
||
|
||
function getSelectedRadius() {
|
||
const selected = radiusButtons.find(
|
||
button => button.classList.contains("active")
|
||
);
|
||
|
||
return selected ? Number(selected.dataset.radius) : null;
|
||
}
|
||
|
||
function showStatus(message, isError = false) {
|
||
saveStatus.textContent = message;
|
||
saveStatus.classList.toggle("error", isError);
|
||
}
|
||
|
||
function showRadiusStatus(message, isError = false) {
|
||
radiusApplyStatus.textContent = message;
|
||
radiusApplyStatus.classList.toggle("error", isError);
|
||
}
|
||
|
||
async function applyRadius() {
|
||
const radius = getSelectedRadius();
|
||
|
||
if (radius === null) {
|
||
showRadiusStatus("Выберите радиус проверки.", true);
|
||
return;
|
||
}
|
||
|
||
radiusApplyButton.disabled = true;
|
||
mapRadiusApplyButton.disabled = true;
|
||
showRadiusStatus("Применение радиуса…");
|
||
|
||
try {
|
||
const response = await fetch("/api/wifi-verification/radius", {
|
||
method: "POST",
|
||
headers: {
|
||
"Content-Type": "application/json"
|
||
},
|
||
body: JSON.stringify({ radius_m: radius })
|
||
});
|
||
|
||
const result = await response.json();
|
||
|
||
if (!response.ok || !result.ok) {
|
||
throw new Error(
|
||
result.error || "Не удалось применить радиус."
|
||
);
|
||
}
|
||
|
||
showRadiusStatus(
|
||
result.pending
|
||
? `Радиус ${radius} м сохранён. Ожидается новый GPS FIX; текущая попытка завершится.`
|
||
: `Радиус ${radius} м сохранён и будет использован при следующем запуске.`
|
||
);
|
||
|
||
} catch (error) {
|
||
showRadiusStatus(error.message, true);
|
||
|
||
} finally {
|
||
radiusApplyButton.disabled = false;
|
||
mapRadiusApplyButton.disabled = false;
|
||
}
|
||
}
|
||
|
||
function loadSettings(settings) {
|
||
gpsSource.value = settings.gps_source || "";
|
||
|
||
relayHost.value = settings.gpsrelay_host || "";
|
||
relayPort.value = settings.gpsrelay_port ?? "";
|
||
|
||
gnssMaxAge.value = settings.gnss_max_age_seconds;
|
||
retryPasses.value = settings.queue_retry_passes;
|
||
|
||
const radius = Number(settings.radius_m);
|
||
|
||
if (radiusButtons.some(
|
||
button => Number(button.dataset.radius) === radius
|
||
)) {
|
||
selectRadius(radius);
|
||
} else {
|
||
selectRadius(100);
|
||
}
|
||
|
||
updateGpsSourceFields();
|
||
}
|
||
|
||
async function loadSavedSettings() {
|
||
try {
|
||
const response = await fetch(settingsUrl);
|
||
const result = await response.json();
|
||
|
||
if (!response.ok || !result.ok) {
|
||
throw new Error(
|
||
result.error || "Не удалось загрузить настройки."
|
||
);
|
||
}
|
||
|
||
loadSettings(result.settings);
|
||
showStatus("Настройки загружены.");
|
||
|
||
} catch (error) {
|
||
showStatus(error.message, true);
|
||
}
|
||
}
|
||
|
||
async function saveSettings() {
|
||
const radius = getSelectedRadius();
|
||
|
||
const settings = {
|
||
gps_source: gpsSource.value,
|
||
gpsrelay_host: relayHost.value.trim(),
|
||
gpsrelay_port: relayPort.value === ""
|
||
? null
|
||
: Number(relayPort.value),
|
||
radius_m: radius,
|
||
gnss_max_age_seconds: Number(gnssMaxAge.value),
|
||
queue_retry_passes: Number(retryPasses.value)
|
||
};
|
||
|
||
if (!gpsSource.value) {
|
||
showStatus("Выберите источник GPS.", true);
|
||
return;
|
||
}
|
||
|
||
if (radius === null) {
|
||
showStatus("Выберите радиус проверки.", true);
|
||
return;
|
||
}
|
||
|
||
if (
|
||
gpsSource.value === "gpsrelay"
|
||
&& (!settings.gpsrelay_host || settings.gpsrelay_port === null)
|
||
) {
|
||
showStatus("Укажите адрес и порт GPSRelay.", true);
|
||
return;
|
||
}
|
||
|
||
saveButton.disabled = true;
|
||
showStatus("Сохранение настроек…");
|
||
|
||
try {
|
||
const response = await fetch(settingsUrl, {
|
||
method: "POST",
|
||
headers: {
|
||
"Content-Type": "application/json"
|
||
},
|
||
body: JSON.stringify(settings)
|
||
});
|
||
|
||
const result = await response.json();
|
||
|
||
if (!response.ok || !result.ok) {
|
||
throw new Error(
|
||
result.error || "Не удалось сохранить настройки."
|
||
);
|
||
}
|
||
|
||
loadSettings(result.settings);
|
||
showStatus("Настройки успешно сохранены.");
|
||
|
||
} catch (error) {
|
||
showStatus(error.message, true);
|
||
|
||
} finally {
|
||
saveButton.disabled = false;
|
||
}
|
||
}
|
||
|
||
gpsSource.addEventListener("change", updateGpsSourceFields);
|
||
|
||
radiusButtons.forEach(button => {
|
||
button.addEventListener("click", () => {
|
||
selectRadius(Number(button.dataset.radius));
|
||
});
|
||
});
|
||
|
||
mapRadiusSelect.addEventListener("change", () => {
|
||
selectRadius(Number(mapRadiusSelect.value));
|
||
});
|
||
|
||
saveButton.addEventListener("click", saveSettings);
|
||
radiusApplyButton.addEventListener("click", applyRadius);
|
||
mapRadiusApplyButton.addEventListener("click", applyRadius);
|
||
|
||
document
|
||
.getElementById("auto-verification-reset")
|
||
.addEventListener("click", () => {
|
||
interfaceSelect.selectedIndex = 0;
|
||
gpsSource.selectedIndex = 0;
|
||
|
||
relayHost.value = "";
|
||
relayPort.value = "";
|
||
|
||
gnssMaxAge.value = "5";
|
||
retryPasses.value = "1";
|
||
|
||
selectRadius(100);
|
||
updateGpsSourceFields();
|
||
|
||
showStatus("Значения формы сброшены. Для сохранения нажмите SAVE.");
|
||
});
|
||
|
||
updateGpsSourceFields();
|
||
selectRadius(100);
|
||
loadSavedSettings();
|
||
})();
|
||
</script>
|
||
|
||
<script src="{{ url_for('auto_verification_map_asset', filename='maplibre-gl.js') }}"></script>
|
||
<script>
|
||
(() => {
|
||
const mapDataUrl = "{{ url_for('api_wifi_verification_map_data') }}";
|
||
const statusUrl = "{{ url_for('api_wifi_verification_status') }}";
|
||
const startUrl = "{{ url_for('api_wifi_verification_start') }}";
|
||
const stopUrl = "{{ url_for('api_wifi_verification_stop') }}";
|
||
const gpsStatusUrl = "{{ url_for('api_wifi_verification_map_gps_status') }}";
|
||
const gpsStartUrl = "{{ url_for('api_wifi_verification_map_gps_start') }}";
|
||
const gpsStopUrl = "{{ url_for('api_wifi_verification_map_gps_stop') }}";
|
||
const mapStyleUrl = {{ map_style_url | tojson }};
|
||
|
||
const message = document.getElementById("capture-map-message");
|
||
const count = document.getElementById("capture-map-count");
|
||
const startButton = document.getElementById("auto-start");
|
||
const stopButton = document.getElementById("auto-stop");
|
||
const interfaceSelect = document.getElementById("auto-interface");
|
||
const statusText = document.getElementById("header-scanner-status");
|
||
const statusIndicator = document.getElementById("auto-status-indicator");
|
||
const statusContainer = document.getElementById("auto-header-status");
|
||
|
||
const monitorState = document.getElementById("auto-monitor-state");
|
||
const monitorCandidates = document.getElementById("auto-monitor-candidates");
|
||
const monitorCandidatesCount = document.getElementById("auto-monitor-candidates-count");
|
||
const monitorQueue = document.getElementById("auto-monitor-queue");
|
||
const monitorQueueCount = document.getElementById("auto-monitor-queue-count");
|
||
const monitorEvents = document.getElementById("auto-monitor-events");
|
||
const monitorAttemptsCount = document.getElementById("auto-monitor-attempts-count");
|
||
|
||
const monitorStatistics = {
|
||
SUCCESS: document.getElementById("auto-stat-success"),
|
||
AP_NOT_FOUND: document.getElementById("auto-stat-ap-not-found"),
|
||
INVALID_PASSWORD: document.getElementById("auto-stat-invalid-password"),
|
||
CONNECTION_TIMEOUT: document.getElementById("auto-stat-connection-timeout"),
|
||
NETWORK_ERROR: document.getElementById("auto-stat-network-error"),
|
||
UNKNOWN_ERROR: document.getElementById("auto-stat-unknown-error")
|
||
};
|
||
|
||
const gpsStartButton = document.getElementById("auto-gps-start");
|
||
const gpsStopButton = document.getElementById("auto-gps-stop");
|
||
const gpsIndicator = document.getElementById("auto-gps-indicator");
|
||
const gpsStateText = document.getElementById("auto-gps-state");
|
||
const gpsDetail = document.getElementById("auto-gps-detail");
|
||
const gpsValue = document.querySelector(".auto-position-gps");
|
||
const coordinatesInput = document.getElementById("auto-position-coordinates");
|
||
const radiusText = document.getElementById("auto-position-radius");
|
||
|
||
const filters = {
|
||
green: true,
|
||
red: true,
|
||
orange: true,
|
||
gray: true
|
||
};
|
||
|
||
const markers = [];
|
||
let mapData = null;
|
||
let gpsMarker = null;
|
||
let gpsPositionActive = false;
|
||
let gpsCenterKey = null;
|
||
let gpsFollowEnabled = true;
|
||
let gpsFollowButton = null;
|
||
let gpsLastRadius = null;
|
||
let latestGpsPosition = null;
|
||
let autoRunning = false;
|
||
|
||
const map = new maplibregl.Map({
|
||
container: "capture-map",
|
||
style: mapStyleUrl,
|
||
center: [0, 0],
|
||
zoom: 2
|
||
});
|
||
|
||
map.addControl(new maplibregl.NavigationControl(), "top-right");
|
||
|
||
function setGpsFollowing(enabled) {
|
||
gpsFollowEnabled = Boolean(enabled);
|
||
|
||
if (gpsFollowButton) {
|
||
gpsFollowButton.classList.toggle(
|
||
"is-active",
|
||
gpsFollowEnabled
|
||
);
|
||
gpsFollowButton.setAttribute(
|
||
"aria-pressed",
|
||
String(gpsFollowEnabled)
|
||
);
|
||
}
|
||
}
|
||
|
||
function pauseGpsFollowing() {
|
||
setGpsFollowing(false);
|
||
}
|
||
|
||
const gpsFollowControl = {
|
||
onAdd() {
|
||
const container = document.createElement("div");
|
||
container.className = (
|
||
"maplibregl-ctrl maplibregl-ctrl-group " +
|
||
"auto-gps-follow-control"
|
||
);
|
||
|
||
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">
|
||
<path d="M12 2.5 4.7 21.5 12 17.2 19.3 21.5 12 2.5Z"/>
|
||
</svg>
|
||
`;
|
||
|
||
gpsFollowButton = button;
|
||
|
||
button.addEventListener("click", () => {
|
||
setGpsFollowing(true);
|
||
|
||
if (latestGpsPosition) {
|
||
gpsCenterKey = null;
|
||
gpsLastRadius = null;
|
||
|
||
updateGpsMap(
|
||
latestGpsPosition.latitude,
|
||
latestGpsPosition.longitude,
|
||
latestGpsPosition.radiusMeters
|
||
);
|
||
}
|
||
});
|
||
|
||
container.appendChild(button);
|
||
return container;
|
||
},
|
||
|
||
onRemove() {
|
||
gpsFollowButton = null;
|
||
}
|
||
};
|
||
|
||
map.addControl(gpsFollowControl, "top-right");
|
||
|
||
map.on("dragstart", pauseGpsFollowing);
|
||
map.on("dblclick", pauseGpsFollowing);
|
||
|
||
const mapCanvas = map.getCanvasContainer();
|
||
|
||
mapCanvas.addEventListener(
|
||
"wheel",
|
||
pauseGpsFollowing,
|
||
{ passive: true }
|
||
);
|
||
|
||
mapCanvas.addEventListener(
|
||
"touchstart",
|
||
event => {
|
||
if (event.touches.length >= 2) {
|
||
pauseGpsFollowing();
|
||
}
|
||
},
|
||
{ passive: true }
|
||
);
|
||
|
||
map.getContainer()
|
||
.querySelectorAll(
|
||
".maplibregl-ctrl-zoom-in, .maplibregl-ctrl-zoom-out"
|
||
)
|
||
.forEach(button => {
|
||
button.addEventListener("click", pauseGpsFollowing);
|
||
});
|
||
|
||
function setMessage(text) {
|
||
message.textContent = text || "";
|
||
}
|
||
|
||
function copyMapCoordinates(button) {
|
||
const value = button.dataset.coordinates || "";
|
||
if (!value) return;
|
||
|
||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||
navigator.clipboard.writeText(value).then(
|
||
() => setMessage("Координаты скопированы."),
|
||
() => setMessage("Не удалось скопировать координаты.")
|
||
);
|
||
return;
|
||
}
|
||
|
||
const field = document.createElement("textarea");
|
||
field.value = value;
|
||
document.body.appendChild(field);
|
||
field.select();
|
||
|
||
try {
|
||
document.execCommand("copy");
|
||
setMessage("Координаты скопированы.");
|
||
} catch (_) {
|
||
setMessage("Не удалось скопировать координаты.");
|
||
}
|
||
|
||
field.remove();
|
||
}
|
||
|
||
window.copyMapCoordinates = copyMapCoordinates;
|
||
|
||
async function requestJson(url, options = {}) {
|
||
const response = await fetch(url, {
|
||
headers: { "Content-Type": "application/json" },
|
||
...options
|
||
});
|
||
|
||
const data = await response.json().catch(() => ({}));
|
||
|
||
if (!response.ok || data.success === false) {
|
||
throw new Error(data.error || data.message || `HTTP ${response.status}`);
|
||
}
|
||
|
||
return data;
|
||
}
|
||
|
||
function updateStartButton() {
|
||
startButton.disabled = autoRunning || !interfaceSelect.value;
|
||
}
|
||
|
||
function createMonitorElement(tag, className, text) {
|
||
const element = document.createElement(tag);
|
||
|
||
if (className) {
|
||
element.className = className;
|
||
}
|
||
|
||
if (text !== undefined && text !== null) {
|
||
element.textContent = String(text);
|
||
}
|
||
|
||
return element;
|
||
}
|
||
|
||
function renderMonitorCandidates(candidates) {
|
||
const items = Array.isArray(candidates) ? candidates : [];
|
||
|
||
monitorCandidates.replaceChildren();
|
||
monitorCandidatesCount.textContent = `${items.length} AP`;
|
||
|
||
if (!items.length) {
|
||
monitorCandidates.appendChild(
|
||
createMonitorElement(
|
||
"div",
|
||
"auto-monitor-empty",
|
||
"Нет кандидатов на проверку"
|
||
)
|
||
);
|
||
return;
|
||
}
|
||
|
||
items.forEach(candidate => {
|
||
const row = createMonitorElement("div", "auto-monitor-ap");
|
||
const info = createMonitorElement("div", "auto-monitor-ap-info");
|
||
|
||
info.appendChild(
|
||
createMonitorElement(
|
||
"strong",
|
||
"",
|
||
candidate.essid || "Без имени"
|
||
)
|
||
);
|
||
|
||
const distance = candidate.distance !== null
|
||
&& candidate.distance !== undefined
|
||
&& Number.isFinite(Number(candidate.distance))
|
||
? ` · ${candidate.distance} м`
|
||
: "";
|
||
|
||
info.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
"",
|
||
`${candidate.bssid || "BSSID неизвестен"}${distance}`
|
||
)
|
||
);
|
||
|
||
row.appendChild(info);
|
||
|
||
const strength = candidate.strength;
|
||
|
||
if (
|
||
strength === null
|
||
|| strength === undefined
|
||
|| !Number.isInteger(strength)
|
||
|| strength < 0
|
||
|| strength > 100
|
||
) {
|
||
row.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
"auto-monitor-unavailable",
|
||
"⊘"
|
||
)
|
||
);
|
||
} else {
|
||
const signalClass = strength >= 70
|
||
? "is-strong"
|
||
: strength >= 40
|
||
? "is-medium"
|
||
: "is-weak";
|
||
|
||
const signal = createMonitorElement(
|
||
"span",
|
||
`auto-monitor-signal ${signalClass}`
|
||
);
|
||
|
||
signal.setAttribute(
|
||
"aria-label",
|
||
`Уровень сигнала: ${strength}%`
|
||
);
|
||
|
||
signal.appendChild(
|
||
createMonitorElement("span", "", `${strength}%`)
|
||
);
|
||
|
||
const icon = createMonitorElement(
|
||
"span",
|
||
"auto-monitor-signal-icon"
|
||
);
|
||
|
||
icon.setAttribute("aria-hidden", "true");
|
||
|
||
for (let i = 0; i < 4; i += 1) {
|
||
icon.appendChild(document.createElement("i"));
|
||
}
|
||
|
||
signal.appendChild(icon);
|
||
row.appendChild(signal);
|
||
}
|
||
|
||
monitorCandidates.appendChild(row);
|
||
});
|
||
}
|
||
|
||
function renderMonitorQueue(queue, active) {
|
||
const items = Array.isArray(queue) ? queue : [];
|
||
const rows = [];
|
||
|
||
monitorQueue.replaceChildren();
|
||
|
||
if (active && active.bssid) {
|
||
rows.push({
|
||
bssid: active.bssid,
|
||
essid: active.essid,
|
||
active: true
|
||
});
|
||
}
|
||
|
||
items.forEach(item => {
|
||
rows.push({
|
||
bssid: item.bssid,
|
||
essid: item.essid,
|
||
active: false
|
||
});
|
||
});
|
||
|
||
monitorQueueCount.textContent = `${rows.length} AP`;
|
||
|
||
if (!rows.length) {
|
||
monitorQueue.appendChild(
|
||
createMonitorElement(
|
||
"div",
|
||
"auto-monitor-empty",
|
||
"Очередь пуста"
|
||
)
|
||
);
|
||
return;
|
||
}
|
||
|
||
rows.forEach((item, index) => {
|
||
const row = createMonitorElement(
|
||
"div",
|
||
item.active
|
||
? "auto-monitor-queue-item is-processing"
|
||
: "auto-monitor-queue-item"
|
||
);
|
||
|
||
row.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
"auto-monitor-queue-number",
|
||
item.active ? "▶" : String(index + 1).padStart(2, "0")
|
||
)
|
||
);
|
||
|
||
const info = createMonitorElement("div", "auto-monitor-ap-info");
|
||
|
||
info.appendChild(
|
||
createMonitorElement(
|
||
"strong",
|
||
"",
|
||
item.essid || "Без имени"
|
||
)
|
||
);
|
||
|
||
info.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
"",
|
||
item.bssid || "BSSID неизвестен"
|
||
)
|
||
);
|
||
|
||
row.appendChild(info);
|
||
|
||
row.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
"auto-monitor-queue-state",
|
||
item.active
|
||
? "Проверяется"
|
||
: "Ожидает"
|
||
)
|
||
);
|
||
|
||
monitorQueue.appendChild(row);
|
||
});
|
||
}
|
||
|
||
function renderMonitorStatistics(status) {
|
||
const statistics = status.monitor_statistics || {};
|
||
|
||
Object.entries(monitorStatistics).forEach(([key, element]) => {
|
||
const value = Number(statistics[key] || 0);
|
||
element.textContent = Number.isFinite(value) ? String(value) : "0";
|
||
});
|
||
|
||
const attempts = Number(status.attempts_total || 0);
|
||
monitorAttemptsCount.textContent = Number.isFinite(attempts)
|
||
? String(attempts)
|
||
: "0";
|
||
}
|
||
|
||
function renderMonitorEvents(events) {
|
||
const items = Array.isArray(events) ? events : [];
|
||
|
||
monitorEvents.replaceChildren();
|
||
|
||
if (!items.length) {
|
||
monitorEvents.appendChild(
|
||
createMonitorElement(
|
||
"div",
|
||
"auto-monitor-empty",
|
||
"Событий пока нет"
|
||
)
|
||
);
|
||
return;
|
||
}
|
||
|
||
items.slice(-100).reverse().forEach(item => {
|
||
const row = createMonitorElement(
|
||
"div",
|
||
"auto-monitor-log-entry"
|
||
);
|
||
|
||
let timeText = "—";
|
||
|
||
if (item.timestamp) {
|
||
const date = new Date(item.timestamp);
|
||
|
||
if (!Number.isNaN(date.getTime())) {
|
||
timeText = date.toLocaleTimeString("ru-RU", {
|
||
hour: "2-digit",
|
||
minute: "2-digit",
|
||
second: "2-digit"
|
||
});
|
||
}
|
||
}
|
||
|
||
row.appendChild(
|
||
createMonitorElement("time", "", timeText)
|
||
);
|
||
|
||
const level = String(item.level || "info").toLowerCase();
|
||
const allowedLevels = ["info", "success", "warning", "error"];
|
||
const safeLevel = allowedLevels.includes(level) ? level : "info";
|
||
|
||
const eventName = String(item.event || "EVENT");
|
||
|
||
row.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
`auto-monitor-log-level is-${safeLevel}`,
|
||
eventName
|
||
)
|
||
);
|
||
|
||
row.appendChild(
|
||
createMonitorElement(
|
||
"span",
|
||
"",
|
||
item.message || ""
|
||
)
|
||
);
|
||
|
||
monitorEvents.appendChild(row);
|
||
});
|
||
}
|
||
|
||
function renderMonitor(status) {
|
||
renderMonitorCandidates(status.monitor_candidates);
|
||
renderMonitorQueue(status.monitor_queue, status.monitor_active);
|
||
renderMonitorStatistics(status);
|
||
renderMonitorEvents(status.monitor_events);
|
||
|
||
}
|
||
|
||
function updateStatus(status) {
|
||
const running = Boolean(status.running);
|
||
autoRunning = running;
|
||
|
||
const stateLabels = {
|
||
STOPPED: "остановлен",
|
||
WAITING_GPS: "ожидание GPS",
|
||
RUNNING: "работает",
|
||
BUSY: "сетевой ресурс занят",
|
||
ERROR: "ошибка"
|
||
};
|
||
|
||
const actualState = String(
|
||
status.state || (running ? "RUNNING" : "STOPPED")
|
||
);
|
||
|
||
statusText.textContent =
|
||
`Auto: ${stateLabels[actualState] || actualState}`;
|
||
|
||
monitorState.textContent =
|
||
stateLabels[actualState] || actualState;
|
||
|
||
statusContainer.classList.toggle("active", running);
|
||
statusContainer.classList.toggle("stopped", !running);
|
||
statusIndicator.classList.toggle("active", running);
|
||
statusIndicator.classList.toggle("stopped", !running);
|
||
updateStartButton();
|
||
stopButton.disabled = !running;
|
||
|
||
renderMonitor(status);
|
||
|
||
if (running) {
|
||
const parts = [];
|
||
if (status.interface) parts.push(status.interface);
|
||
if (status.access_points_total !== undefined) {
|
||
parts.push(`AP: ${status.access_points_total}`);
|
||
}
|
||
if (status.attempts_total !== undefined) {
|
||
parts.push(`попыток: ${status.attempts_total}`);
|
||
}
|
||
if (parts.length) {
|
||
statusText.title = parts.join(" · ");
|
||
}
|
||
} else {
|
||
statusText.title = "";
|
||
}
|
||
}
|
||
|
||
async function refreshStatus() {
|
||
try {
|
||
const status = await requestJson(statusUrl);
|
||
updateStatus(status);
|
||
} catch (error) {
|
||
setMessage(`Ошибка получения статуса Auto: ${error.message}`);
|
||
}
|
||
}
|
||
|
||
function emptyGpsFeatureCollection() {
|
||
return {
|
||
type: "FeatureCollection",
|
||
features: []
|
||
};
|
||
}
|
||
|
||
function buildGpsCircle(latitude, longitude, radiusMeters) {
|
||
const earthRadius = 6371008.8;
|
||
const angularDistance = radiusMeters / earthRadius;
|
||
const latitude1 = latitude * Math.PI / 180;
|
||
const longitude1 = longitude * Math.PI / 180;
|
||
const coordinates = [];
|
||
|
||
for (let i = 0; i <= 64; i += 1) {
|
||
const bearing = 2 * Math.PI * i / 64;
|
||
|
||
const latitude2 = Math.asin(
|
||
Math.sin(latitude1) * Math.cos(angularDistance) +
|
||
Math.cos(latitude1) * Math.sin(angularDistance) *
|
||
Math.cos(bearing)
|
||
);
|
||
|
||
const longitude2 = longitude1 + Math.atan2(
|
||
Math.sin(bearing) * Math.sin(angularDistance) *
|
||
Math.cos(latitude1),
|
||
Math.cos(angularDistance) -
|
||
Math.sin(latitude1) * Math.sin(latitude2)
|
||
);
|
||
|
||
const longitudeDegrees =
|
||
((longitude2 * 180 / Math.PI + 540) % 360) - 180;
|
||
|
||
coordinates.push([
|
||
longitudeDegrees,
|
||
latitude2 * 180 / Math.PI
|
||
]);
|
||
}
|
||
|
||
return {
|
||
type: "Feature",
|
||
properties: {},
|
||
geometry: {
|
||
type: "Polygon",
|
||
coordinates: [coordinates]
|
||
}
|
||
};
|
||
}
|
||
|
||
function updateGpsMap(latitude, longitude, radiusMeters) {
|
||
const source = map.getSource("auto-gps-radius");
|
||
|
||
if (!source) return;
|
||
|
||
if (!gpsMarker) {
|
||
const element = document.createElement("div");
|
||
element.className = "auto-gps-map-marker";
|
||
|
||
gpsMarker = new maplibregl.Marker({ element })
|
||
.setLngLat([longitude, latitude])
|
||
.addTo(map);
|
||
} else {
|
||
gpsMarker.setLngLat([longitude, latitude]);
|
||
}
|
||
|
||
if (Number.isFinite(radiusMeters) && radiusMeters > 0) {
|
||
source.setData({
|
||
type: "FeatureCollection",
|
||
features: [
|
||
buildGpsCircle(latitude, longitude, radiusMeters)
|
||
]
|
||
});
|
||
} else {
|
||
source.setData(emptyGpsFeatureCollection());
|
||
}
|
||
|
||
const centerKey = `${latitude.toFixed(6)},${longitude.toFixed(6)}`;
|
||
|
||
latestGpsPosition = {
|
||
latitude,
|
||
longitude,
|
||
radiusMeters
|
||
};
|
||
|
||
const validRadius = (
|
||
Number.isFinite(radiusMeters) && radiusMeters > 0
|
||
);
|
||
|
||
const radiusChanged = (
|
||
validRadius && gpsLastRadius !== radiusMeters
|
||
);
|
||
|
||
if (
|
||
gpsFollowEnabled &&
|
||
(
|
||
!gpsPositionActive ||
|
||
gpsCenterKey !== centerKey ||
|
||
radiusChanged
|
||
)
|
||
) {
|
||
const cameraOptions = {
|
||
center: [longitude, latitude],
|
||
duration: 500
|
||
};
|
||
|
||
if (validRadius && (!gpsPositionActive || radiusChanged)) {
|
||
const extent = buildGpsCircle(
|
||
latitude,
|
||
longitude,
|
||
radiusMeters * 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;
|
||
gpsLastRadius = radiusMeters;
|
||
}
|
||
}
|
||
|
||
map.easeTo(cameraOptions);
|
||
}
|
||
|
||
gpsPositionActive = true;
|
||
gpsCenterKey = centerKey;
|
||
}
|
||
|
||
function clearGpsMap() {
|
||
if (gpsMarker) {
|
||
gpsMarker.remove();
|
||
gpsMarker = null;
|
||
}
|
||
|
||
const source = map.getSource("auto-gps-radius");
|
||
|
||
if (source) {
|
||
source.setData(emptyGpsFeatureCollection());
|
||
}
|
||
|
||
gpsPositionActive = false;
|
||
gpsCenterKey = null;
|
||
gpsLastRadius = null;
|
||
latestGpsPosition = null;
|
||
setGpsFollowing(true);
|
||
}
|
||
|
||
function updateGpsStatus(data) {
|
||
const gps = data.gps || {};
|
||
const monitorEnabled = Boolean(data.monitor_enabled);
|
||
const running = Boolean(gps.running);
|
||
const hasFix = (
|
||
(monitorEnabled || data.owner === "AUTO_WIFI_VERIFY") &&
|
||
running &&
|
||
Boolean(gps.has_fresh_fix) &&
|
||
gps.latitude !== null &&
|
||
gps.latitude !== undefined &&
|
||
gps.longitude !== null &&
|
||
gps.longitude !== undefined &&
|
||
Number.isFinite(Number(gps.latitude)) &&
|
||
Number.isFinite(Number(gps.longitude))
|
||
);
|
||
|
||
const radius = Number(data.radius_m);
|
||
|
||
radiusText.textContent = (
|
||
Number.isFinite(radius) && radius > 0
|
||
? `${radius} м`
|
||
: "Не задан"
|
||
);
|
||
|
||
gpsStartButton.disabled = monitorEnabled;
|
||
gpsStopButton.disabled = !monitorEnabled;
|
||
|
||
gpsIndicator.classList.remove("active", "warning", "stopped");
|
||
gpsValue.classList.remove("is-fixed", "is-searching", "is-error");
|
||
|
||
if (!monitorEnabled && !hasFix) {
|
||
gpsIndicator.classList.add("warning");
|
||
gpsStateText.textContent = "GPS ВЫКЛЮЧЕН";
|
||
gpsValue.classList.add("is-searching");
|
||
gpsDetail.textContent = (
|
||
running
|
||
? "GPS используется другой операцией; монитор карты выключен"
|
||
: "GPS-монитор карты остановлен"
|
||
);
|
||
|
||
coordinatesInput.value = "";
|
||
clearGpsMap();
|
||
return;
|
||
}
|
||
|
||
if (hasFix) {
|
||
gpsIndicator.classList.add("active");
|
||
gpsValue.classList.add("is-fixed");
|
||
gpsStateText.textContent = "FIX ПОЛУЧЕН";
|
||
|
||
const latitude = Number(gps.latitude);
|
||
const longitude = Number(gps.longitude);
|
||
|
||
coordinatesInput.value = (
|
||
`${latitude.toFixed(6)}, ${longitude.toFixed(6)}`
|
||
);
|
||
|
||
const age = Number(gps.fix_age_seconds);
|
||
const ageText = Number.isFinite(age)
|
||
? ` · возраст FIX: ${age.toFixed(1)} с`
|
||
: "";
|
||
|
||
gpsDetail.textContent = (
|
||
`Координаты получены${ageText}`
|
||
);
|
||
|
||
updateGpsMap(latitude, longitude, radius);
|
||
return;
|
||
}
|
||
|
||
coordinatesInput.value = "";
|
||
clearGpsMap();
|
||
|
||
if (gps.state === "ERROR") {
|
||
gpsIndicator.classList.add("warning");
|
||
gpsValue.classList.add("is-error");
|
||
gpsStateText.textContent = "ОШИБКА GPS";
|
||
gpsDetail.textContent = gps.error || "Ошибка GPS-сервиса";
|
||
} else {
|
||
gpsIndicator.classList.add("warning");
|
||
gpsValue.classList.add("is-searching");
|
||
|
||
gpsStateText.textContent = running
|
||
? "ПОИСК FIX"
|
||
: "ЗАПУСК GPS";
|
||
|
||
gpsDetail.textContent = (
|
||
gps.error ||
|
||
`Состояние: ${gps.state || "ожидание данных"}`
|
||
);
|
||
}
|
||
}
|
||
|
||
async function refreshGpsStatus() {
|
||
try {
|
||
const data = await requestJson(gpsStatusUrl);
|
||
updateGpsStatus(data);
|
||
} catch (error) {
|
||
gpsIndicator.classList.remove("active");
|
||
gpsIndicator.classList.add("warning");
|
||
gpsStateText.textContent = "ОШИБКА СТАТУСА";
|
||
gpsDetail.textContent = error.message;
|
||
}
|
||
}
|
||
|
||
async function setGpsMonitor(url, action) {
|
||
gpsStartButton.disabled = true;
|
||
gpsStopButton.disabled = true;
|
||
|
||
try {
|
||
await requestJson(url, {
|
||
method: "POST",
|
||
body: JSON.stringify({})
|
||
});
|
||
|
||
await refreshGpsStatus();
|
||
|
||
setMessage(
|
||
action === "start"
|
||
? "GPS-монитор карты включён."
|
||
: "GPS-монитор карты выключен."
|
||
);
|
||
} catch (error) {
|
||
setMessage(`Не удалось изменить состояние GPS: ${error.message}`);
|
||
await refreshGpsStatus();
|
||
}
|
||
}
|
||
|
||
function clearMarkers() {
|
||
markers.forEach(marker => marker.remove());
|
||
markers.length = 0;
|
||
}
|
||
|
||
function renderMarkers() {
|
||
clearMarkers();
|
||
|
||
if (!mapData || !Array.isArray(mapData.features)) return;
|
||
|
||
const visibleCoordinates = [];
|
||
|
||
mapData.features.forEach(feature => {
|
||
const properties = feature.properties || {};
|
||
const status = properties.status || "gray";
|
||
|
||
if (!filters[status]) return;
|
||
|
||
const coordinates = feature.geometry.coordinates;
|
||
const element = document.createElement("div");
|
||
element.className = `capture-map-marker ${status}`;
|
||
|
||
const popup = new maplibregl.Popup({
|
||
offset: 12,
|
||
maxWidth: "380px",
|
||
className: "capture-map-popup"
|
||
}).setHTML(properties.popup || "");
|
||
|
||
const marker = new maplibregl.Marker({ element })
|
||
.setLngLat(coordinates)
|
||
.setPopup(popup)
|
||
.addTo(map);
|
||
|
||
markers.push(marker);
|
||
visibleCoordinates.push(coordinates);
|
||
});
|
||
|
||
if (visibleCoordinates.length && !gpsPositionActive) {
|
||
const bounds = new maplibregl.LngLatBounds();
|
||
visibleCoordinates.forEach(point => bounds.extend(point));
|
||
map.fitBounds(bounds, { padding: 45, maxZoom: 15 });
|
||
}
|
||
}
|
||
|
||
async function refreshMap() {
|
||
try {
|
||
setMessage("Загрузка точек карты…");
|
||
mapData = await requestJson(mapDataUrl);
|
||
|
||
const counts = mapData.counts || {};
|
||
count.textContent =
|
||
`Точек: ${mapData.total || 0} · ` +
|
||
`Verified: ${counts.green || 0} · ` +
|
||
`Invalid: ${counts.red || 0} · ` +
|
||
`Technical: ${counts.orange || 0} · ` +
|
||
`Incomplete: ${counts.gray || 0}`;
|
||
|
||
renderMarkers();
|
||
setMessage("");
|
||
} catch (error) {
|
||
setMessage(`Не удалось загрузить карту: ${error.message}`);
|
||
}
|
||
}
|
||
|
||
interfaceSelect.addEventListener("change", updateStartButton);
|
||
|
||
startButton.addEventListener("click", async () => {
|
||
const interfaceName = interfaceSelect.value;
|
||
|
||
if (!interfaceName) {
|
||
setMessage("Выберите Wi-Fi-интерфейс.");
|
||
updateStartButton();
|
||
return;
|
||
}
|
||
|
||
startButton.disabled = true;
|
||
setMessage("Запуск Auto Verification…");
|
||
|
||
try {
|
||
await requestJson(startUrl, {
|
||
method: "POST",
|
||
body: JSON.stringify({
|
||
interface: interfaceName
|
||
})
|
||
});
|
||
|
||
await refreshStatus();
|
||
setMessage("Auto Verification запущен.");
|
||
|
||
} catch (error) {
|
||
setMessage(`Не удалось запустить Auto Verification: ${error.message}`);
|
||
await refreshStatus();
|
||
}
|
||
});
|
||
|
||
stopButton.addEventListener("click", async () => {
|
||
stopButton.disabled = true;
|
||
|
||
try {
|
||
await requestJson(stopUrl, {
|
||
method: "POST",
|
||
body: JSON.stringify({})
|
||
});
|
||
await refreshStatus();
|
||
setMessage("Запрос остановки Auto отправлен. Ожидается завершение очистки.");
|
||
} catch (error) {
|
||
setMessage(`Не удалось остановить Auto: ${error.message}`);
|
||
await refreshStatus();
|
||
}
|
||
});
|
||
|
||
gpsStartButton.addEventListener("click", () => {
|
||
setGpsMonitor(gpsStartUrl, "start");
|
||
});
|
||
|
||
gpsStopButton.addEventListener("click", () => {
|
||
setGpsMonitor(gpsStopUrl, "stop");
|
||
});
|
||
|
||
document.getElementById("capture-map-refresh")
|
||
.addEventListener("click", refreshMap);
|
||
|
||
document.querySelectorAll("[data-map-filter]").forEach(input => {
|
||
input.addEventListener("change", () => {
|
||
filters[input.dataset.mapFilter] = input.checked;
|
||
renderMarkers();
|
||
});
|
||
});
|
||
|
||
map.on("load", () => {
|
||
map.addSource("auto-gps-radius", {
|
||
type: "geojson",
|
||
data: emptyGpsFeatureCollection()
|
||
});
|
||
|
||
map.addLayer({
|
||
id: "auto-gps-radius-fill",
|
||
type: "fill",
|
||
source: "auto-gps-radius",
|
||
paint: {
|
||
"fill-color": "#2688ff",
|
||
"fill-opacity": 0.12
|
||
}
|
||
});
|
||
|
||
map.addLayer({
|
||
id: "auto-gps-radius-line",
|
||
type: "line",
|
||
source: "auto-gps-radius",
|
||
paint: {
|
||
"line-color": "#2688ff",
|
||
"line-width": 2,
|
||
"line-opacity": 0.85
|
||
}
|
||
});
|
||
|
||
refreshMap();
|
||
refreshGpsStatus();
|
||
});
|
||
|
||
refreshStatus();
|
||
refreshGpsStatus();
|
||
|
||
// Обновляем статусы без перезагрузки страницы.
|
||
window.setInterval(refreshStatus, 3000);
|
||
window.setInterval(refreshGpsStatus, 3000);
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|