Keep Kismet UI available without starting capture

This commit is contained in:
alex committed 2026-08-25 00:30:57 +02:00
1 parent c894fad681
commit aa0ccfe92f
8 files changed
+247 -1

No files matched your search

+2
View File
@@ -184,6 +184,8 @@ Important values:
The installer installs Kismet and a manually controlled `pi-car-companion-kismet.service`. It does not start capture at boot. Open **Wardriving** in the dashboard (or the Android companion), pair a phone, and start a session when the vehicle is parked or moving in a place where discovery is lawful. The official Kismet repository currently provides the required capture packages for 64-bit Raspberry Pi OS; the installer stops with an explicit architecture message on unsupported 32-bit images.
The installer also adds a **Kismet** shortcut to the Raspberry Pi desktop. When no capture session is active, the shortcut starts a loopback-only idle Kismet web server with no capture sources, so opening the UI never changes the upstream WiFi adapter. Starting a wardriving session automatically replaces that idle server with the real capture service; stopping the session releases the port again.
Use a dedicated USB WiFi adapter that supports monitor mode. The Wardriving screen lists live physical WiFi hardware, identifies USB adapters by vendor/model/path or serial, and marks the Alfa AWUS 1900 as the default when present. The built-in `wlan0` hotspot remains protected. When Start is clicked, the privileged helper writes the selected physical radio into Kismet's source configuration, starts Kismet, and verifies that Kismet created monitor mode; monitor children such as `wlan1mon` are never treated as separate selectable hardware. The selected hardware identity is persisted across interface renames and revalidated by the privileged Kismet helper before every start. Bluetooth capture uses the Pi's `hci0` adapter by default and Kismet's discoverable-device scan; a second Bluetooth adapter can be selected with `WARDRIVING_BLUETOOTH_INTERFACE` if the companion BLE link needs its own controller. It does not pair with devices or enumerate services. Kismet is configured for live device tracking without retaining raw packet payloads. Pi Car Companion stores bounded sightings and joins them to a phone GPS fix only while that fix is fresh and accurate. Observations without a suitable fix remain visible but are marked unmapped. The Android companion receives the same adapter inventory and can change the saved selection while a session is stopped.
The UI exposes the active session, Kismet and GPS health, WiFi/Bluetooth counts, recent device metadata, a Leaflet map of mapped sightings, session controls, and data clearing. The Android app shows the same live summary over its existing Bluetooth bridge and can start or stop the session. Revoke a paired phone in **Settings → Mobile** to stop it contributing location data.
+10
View File
@@ -0,0 +1,10 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=Kismet
Comment=Open the Kismet wardriving web interface
Exec=/usr/local/bin/pi-car-companion-open-kismet
Icon=network-wireless
Terminal=false
Categories=Network;Security;
StartupNotify=true
+21
View File
@@ -249,6 +249,8 @@ install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-network-setup" /usr/loca
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-power" /usr/local/sbin/pi-car-companion-power
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-bluetooth-control" /usr/local/sbin/pi-car-companion-bluetooth-control
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-wardriving-control" /usr/local/sbin/pi-car-companion-wardriving-control
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-kismet-ui" /usr/local/sbin/pi-car-companion-kismet-ui
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-open-kismet" /usr/local/bin/pi-car-companion-open-kismet
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-update" /usr/local/sbin/pi-car-companion-update
install -d -m 0755 /usr/local/libexec
install -m 0755 "${SCRIPT_DIR}/scripts/pi-car-companion-bluetooth" /usr/local/libexec/pi-car-companion-bluetooth
@@ -260,8 +262,26 @@ install -m 0644 "${SCRIPT_DIR}/systemd/pi-car-companion-network-configure.servic
install -m 0644 "${SCRIPT_DIR}/systemd/pi-car-companion-network-observer.service" /etc/systemd/system/pi-car-companion-network-observer.service
install -m 0644 "${SCRIPT_DIR}/systemd/pi-car-companion-bluetooth.service" /etc/systemd/system/pi-car-companion-bluetooth.service
install -m 0644 "${SCRIPT_DIR}/systemd/pi-car-companion-kismet.service" /etc/systemd/system/pi-car-companion-kismet.service
install -m 0644 "${SCRIPT_DIR}/systemd/pi-car-companion-kismet-ui.service" /etc/systemd/system/pi-car-companion-kismet-ui.service
install -m 0440 "${SCRIPT_DIR}/systemd/pi-car-companion.sudoers" /etc/sudoers.d/pi-car-companion
visudo -cf /etc/sudoers.d/pi-car-companion >/dev/null
if [[ "${update_user}" != root ]]; then
printf '%s ALL=(root) NOPASSWD: /usr/local/sbin/pi-car-companion-kismet-ui start, /usr/local/sbin/pi-car-companion-kismet-ui stop\n' "${update_user}" > /etc/sudoers.d/pi-car-companion-kismet-ui
chown root:root /etc/sudoers.d/pi-car-companion-kismet-ui
chmod 0440 /etc/sudoers.d/pi-car-companion-kismet-ui
visudo -cf /etc/sudoers.d/pi-car-companion-kismet-ui >/dev/null
fi
desktop_home="$(getent passwd "${update_user}" | cut -d: -f6)"
if [[ "${update_user}" != root && -d "${desktop_home}/Desktop" ]]; then
install -m 0755 "${SCRIPT_DIR}/desktop/Kismet.desktop" "${desktop_home}/Desktop/Kismet.desktop"
chown "${update_user}:$(id -gn "${update_user}")" "${desktop_home}/Desktop/Kismet.desktop"
if command -v gio >/dev/null 2>&1 && [[ -d "/run/user/$(id -u "${update_user}")" ]]; then
sudo -H -u "${update_user}" env \
XDG_RUNTIME_DIR="/run/user/$(id -u "${update_user}")" \
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u "${update_user}")/bus" \
gio set "${desktop_home}/Desktop/Kismet.desktop" metadata::trusted true >/dev/null 2>&1 || true
fi
fi
install -d -m 0755 /etc/avahi/services
install -m 0644 "${SCRIPT_DIR}/config/pi-car-companion.service.xml" /etc/avahi/services/pi-car-companion.service
install -d -m 0755 /etc/NetworkManager/dnsmasq-shared.d
@@ -351,6 +371,7 @@ systemctl enable --now bluetooth.service
systemctl enable pi-car-companion-bluetooth.service
systemctl disable --now kismet.service >/dev/null 2>&1 || true
systemctl disable --now pi-car-companion-kismet.service >/dev/null 2>&1 || true
systemctl disable --now pi-car-companion-kismet-ui.service >/dev/null 2>&1 || true
systemctl enable pi-car-companion-network-observer.service
if grep -qx 'NETWORK_MANAGER_ENABLED=true' "${CONFIG_DIR}/companion.env"; then
systemctl enable --now pi-car-companion-network.service
+1 -1
View File
@@ -17,7 +17,7 @@
"test": "npm run test --workspaces --if-present",
"build": "npm run build --workspaces --if-present",
"build:apk": "./build-apk.sh",
"check:scripts": "bash -n install.sh build-apk.sh scripts/pi-car-companion-update scripts/pi-car-companion-network-setup scripts/pi-car-companion-power scripts/pi-car-companion-bluetooth-control scripts/pi-car-companion-wardriving-control && python3 -c \"compile(open('scripts/pi-car-companion-bluetooth', encoding='utf-8').read(), 'scripts/pi-car-companion-bluetooth', 'exec')\"",
"check:scripts": "bash -n install.sh build-apk.sh scripts/pi-car-companion-update scripts/pi-car-companion-network-setup scripts/pi-car-companion-power scripts/pi-car-companion-bluetooth-control scripts/pi-car-companion-wardriving-control scripts/pi-car-companion-kismet-ui scripts/pi-car-companion-open-kismet && python3 -c \"compile(open('scripts/pi-car-companion-bluetooth', encoding='utf-8').read(), 'scripts/pi-car-companion-bluetooth', 'exec')\"",
"check": "npm run check:scripts && npm run lint && npm run typecheck && npm test && npm run build"
},
"devDependencies": {
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/env bash
set -Eeuo pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "The Kismet UI helper must run as root." >&2
exit 1
fi
ACTION="${1:-}"
case "${ACTION}" in
start|stop) ;;
*)
echo "Usage: pi-car-companion-kismet-ui start|stop" >&2
exit 2
;;
esac
ENV_FILE=/etc/pi-car-companion/companion.env
CAPTURE_SERVICE=pi-car-companion-kismet.service
UI_SERVICE=pi-car-companion-kismet-ui.service
KISMET_DATA_DIR=/var/lib/pi-car-companion/kismet
UI_DATA_DIR=/var/lib/pi-car-companion/kismet-ui
UI_CONFIG=/etc/kismet/pi-car-companion-kismet-ui.conf
if [[ -f "${ENV_FILE}" ]]; then
# shellcheck disable=SC1091
source "${ENV_FILE}"
fi
AUTH_PATH="${WARDRIVING_KISMET_AUTH_PATH:-${KISMET_DATA_DIR}/kismet-api-credentials.json}"
AUTH_CONFIG="${KISMET_DATA_DIR}/config/kismet_httpd.conf"
ensure_authentication() {
local username="pi-car-companion"
local password=""
local temporary
if [[ -f "${AUTH_PATH}" ]]; then
password="$(sed -n 's/.*"password"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "${AUTH_PATH}" | head -n 1)"
fi
if [[ -z "${password}" && -f "${AUTH_CONFIG}" ]]; then
password="$(sed -n 's/^httpd_password=//p' "${AUTH_CONFIG}" | head -n 1)"
fi
if [[ -z "${password}" ]]; then
password="$(uuidgen | tr -d '-')$(uuidgen | tr -d '-')"
fi
install -d -m 0750 -o root -g pi-companion "$(dirname -- "${AUTH_PATH}")" "$(dirname -- "${AUTH_CONFIG}")"
temporary="${AUTH_PATH}.tmp"
printf '{"username":"%s","password":"%s"}\n' "${username}" "${password}" > "${temporary}"
chmod 0640 "${temporary}"
chown root:pi-companion "${temporary}"
mv -f -- "${temporary}" "${AUTH_PATH}"
temporary="${AUTH_CONFIG}.tmp"
printf 'httpd_username=%s\nhttpd_password=%s\n' "${username}" "${password}" > "${temporary}"
chmod 0600 "${temporary}"
chown root:root "${temporary}"
mv -f -- "${temporary}" "${AUTH_CONFIG}"
}
write_ui_config() {
local temporary="${UI_CONFIG}.tmp"
install -d -m 0750 -o root -g pi-companion \
"${UI_DATA_DIR}" \
"${UI_DATA_DIR}/config" \
"${UI_DATA_DIR}/config/httpd" \
"${UI_DATA_DIR}/logs" \
/etc/kismet
printf '%s\n' \
'# Generated by Pi Car Companion. This idle instance only serves the Kismet UI.' \
'# It deliberately defines no capture sources and never changes a radio.' \
"configdir=${UI_DATA_DIR}/config" \
"httpd_auth_file=${AUTH_CONFIG}" \
"httpd_session_db=${UI_DATA_DIR}/config/session.db" \
"httpd_user_home=${UI_DATA_DIR}/config/httpd" \
'httpd_home=/usr/share/kismet/httpd/' \
'httpd_bind_address=127.0.0.1' \
'httpd_port=2501' \
'remote_capture_enabled=false' \
'server_name=pi-car-companion-idle' \
"log_prefix=${UI_DATA_DIR}/logs" \
'log_types=kismet' \
'kis_log_packets=false' \
'kis_log_ephemeral_dangerous=true' \
'hidedata=true' \
'ouifile=/usr/share/kismet/kismet_manuf.txt.gz' \
'icaofile=/usr/share/kismet/kismet_adsb_icao.txt.gz' > "${temporary}"
chmod 0600 "${temporary}"
chown root:root "${temporary}"
mv -f -- "${temporary}" "${UI_CONFIG}"
}
wait_for_ui() {
local status
for _attempt in {1..30}; do
status="$(curl --silent --show-error --max-time 2 --output /dev/null --write-out '%{http_code}' http://127.0.0.1:2501/ 2>/dev/null || true)"
case "${status}" in
2??|401|403) return 0 ;;
esac
sleep 1
done
echo "The Kismet UI did not become reachable on 127.0.0.1:2501." >&2
systemctl status --no-pager "${UI_SERVICE}" >&2 || true
return 1
}
case "${ACTION}" in
start)
# A live capture session owns the real service and port. In that case the
# desktop launcher only needs to open the existing Kismet UI.
if systemctl is-active --quiet "${CAPTURE_SERVICE}"; then
exit 0
fi
ensure_authentication
write_ui_config
timeout 30 systemctl start "${UI_SERVICE}"
wait_for_ui
;;
stop)
timeout 30 systemctl stop "${UI_SERVICE}"
;;
esac
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
set -eu
url='http://127.0.0.1:2501/'
# The real capture service is only started by the wardriving controls. When it
# is stopped, start the loopback-only idle UI so the desktop shortcut remains
# useful without taking wlan1 away from the upstream connection.
if ! /usr/bin/curl --silent --show-error --max-time 2 --output /dev/null "${url}" 2>/dev/null; then
/usr/bin/sudo -n /usr/local/sbin/pi-car-companion-kismet-ui start || true
fi
exec /usr/bin/chromium --new-window "${url}"
+53
View File
@@ -14,6 +14,7 @@ BRANCH_FILE="${CONFIG_DIR}/update-branch"
UPDATE_USER_FILE="${CONFIG_DIR}/update-user"
LOCK_FILE="/run/lock/${APP_NAME}-update.lock"
SERVICE_USER="pi-companion"
KISMET_UI_SUDOERS="/etc/sudoers.d/pi-car-companion-kismet-ui"
WORKTREE=""
RELEASE_TMP=""
FROM_REVISION=""
@@ -32,6 +33,47 @@ ensure_service_data_directory() {
install -d -m 0750 -o root -g "${SERVICE_USER}" "/var/log/${APP_NAME}"
}
install_kismet_ui_sudoers() {
local desktop_user=""
if [[ -f "${UPDATE_USER_FILE}" ]]; then
desktop_user="$(tr -d '\r\n' < "${UPDATE_USER_FILE}")"
fi
if [[ -n "${desktop_user}" && "${desktop_user}" != root ]] && id "${desktop_user}" >/dev/null 2>&1; then
local temporary="${KISMET_UI_SUDOERS}.tmp"
printf '%s ALL=(root) NOPASSWD: /usr/local/sbin/pi-car-companion-kismet-ui start, /usr/local/sbin/pi-car-companion-kismet-ui stop\n' "${desktop_user}" > "${temporary}"
chown root:root "${temporary}"
chmod 0440 "${temporary}"
mv -f -- "${temporary}" "${KISMET_UI_SUDOERS}"
visudo -cf "${KISMET_UI_SUDOERS}" >/dev/null
fi
}
install_desktop_shortcut() {
local source_release="$1"
local desktop_user=""
local user_home=""
local desktop_dir=""
local runtime_dir=""
[[ -f "${source_release}/desktop/Kismet.desktop" ]] || return 0
[[ -f "${UPDATE_USER_FILE}" ]] || return 0
desktop_user="$(tr -d '\r\n' < "${UPDATE_USER_FILE}")"
[[ -n "${desktop_user}" && "${desktop_user}" != root ]] || return 0
user_home="$(getent passwd "${desktop_user}" | cut -d: -f6)"
desktop_dir="${user_home}/Desktop"
[[ -d "${desktop_dir}" ]] || return 0
install -m 0755 "${source_release}/desktop/Kismet.desktop" "${desktop_dir}/Kismet.desktop"
chown "${desktop_user}:$(id -gn "${desktop_user}")" "${desktop_dir}/Kismet.desktop"
if command -v gio >/dev/null 2>&1; then
runtime_dir="/run/user/$(id -u "${desktop_user}")"
if [[ -d "${runtime_dir}" ]]; then
sudo -H -u "${desktop_user}" env \
XDG_RUNTIME_DIR="${runtime_dir}" \
DBUS_SESSION_BUS_ADDRESS="unix:path=${runtime_dir}/bus" \
gio set "${desktop_dir}/Kismet.desktop" metadata::trusted true >/dev/null 2>&1 || true
fi
fi
}
if [[ "${1:-}" == "--check-only" ]]; then
CHECK_ONLY=true
elif [[ $# -gt 0 ]]; then
@@ -84,6 +126,12 @@ install_integration_files() {
if [[ -f "${source_release}/scripts/pi-car-companion-wardriving-control" ]]; then
install -m 0755 "${source_release}/scripts/pi-car-companion-wardriving-control" /usr/local/sbin/pi-car-companion-wardriving-control
fi
if [[ -f "${source_release}/scripts/pi-car-companion-kismet-ui" ]]; then
install -m 0755 "${source_release}/scripts/pi-car-companion-kismet-ui" /usr/local/sbin/pi-car-companion-kismet-ui
fi
if [[ -f "${source_release}/scripts/pi-car-companion-open-kismet" ]]; then
install -m 0755 "${source_release}/scripts/pi-car-companion-open-kismet" /usr/local/bin/pi-car-companion-open-kismet
fi
install -d -m 0755 /usr/local/libexec
install -m 0755 "${source_release}/scripts/pi-car-companion-bluetooth" /usr/local/libexec/pi-car-companion-bluetooth
install -m 0644 "${source_release}/systemd/pi-car-companion.service" /etc/systemd/system/pi-car-companion.service
@@ -96,6 +144,11 @@ install_integration_files() {
if [[ -f "${source_release}/systemd/pi-car-companion-kismet.service" ]]; then
install -m 0644 "${source_release}/systemd/pi-car-companion-kismet.service" /etc/systemd/system/pi-car-companion-kismet.service
fi
if [[ -f "${source_release}/systemd/pi-car-companion-kismet-ui.service" ]]; then
install -m 0644 "${source_release}/systemd/pi-car-companion-kismet-ui.service" /etc/systemd/system/pi-car-companion-kismet-ui.service
install_kismet_ui_sudoers
install_desktop_shortcut "${source_release}"
fi
install -m 0440 "${source_release}/systemd/pi-car-companion.sudoers" /etc/sudoers.d/pi-car-companion
install -d -m 0755 /etc/NetworkManager/dnsmasq-shared.d
install -m 0644 "${source_release}/config/dnsmasq-shared-pi-car-companion.conf" /etc/NetworkManager/dnsmasq-shared.d/pi-car-companion.conf
@@ -0,0 +1,24 @@
[Unit]
Description=Pi Car Companion idle Kismet web UI (no capture)
After=network.target
Before=pi-car-companion-kismet.service
Conflicts=pi-car-companion-kismet.service
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/bin/kismet --no-ncurses-wrapper --no-line-wrap --config-file=/etc/kismet/pi-car-companion-kismet-ui.conf
Restart=on-failure
RestartSec=8s
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictRealtime=true
LockPersonality=true
ReadWritePaths=/var/lib/pi-car-companion/kismet-ui
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK AF_PACKET AF_BLUETOOTH