Added wireguard portal

This commit is contained in:
2026-11-23 11:23:42 -05:00
parent f028cb482d
commit fb2bb4c675
2 changed files with 119 additions and 56 deletions
+33
View File
@@ -0,0 +1,33 @@
services:
wg-portal:
image: wgportal/wg-portal:v2
container_name: opsbox-wg-portal
restart: unless-stopped
cap_add:
- NET_ADMIN
ports:
- "51820:51820/udp"
- "${WG_PORTAL_BIND:-127.0.0.1}:${WG_PORTAL_UI_PORT:-8888}:8888/tcp"
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
environment:
WG_PORTAL_CORE_ADMIN_USER: "${WG_PORTAL_ADMIN_USER}"
WG_PORTAL_CORE_ADMIN_PASSWORD: "${WG_PORTAL_ADMIN_PASSWORD}"
WG_PORTAL_WEB_EXTERNAL_URL: "${WG_PORTAL_EXTERNAL_URL}"
WG_PORTAL_WEB_SESSION_SECRET: "${WG_PORTAL_WEB_SESSION_SECRET}"
WG_PORTAL_WEB_CSRF_SECRET: "${WG_PORTAL_WEB_CSRF_SECRET}"
volumes:
- "${OPSBOX_DATA_ROOT:?Set OPSBOX_DATA_ROOT}/wg-portal/data:/app/data"
- "${OPSBOX_DATA_ROOT:?Set OPSBOX_DATA_ROOT}/wg-portal/config:/app/config"
networks:
- default
- proxy
labels:
caddy: "${OPSBOX_SUB_WGPORTAL:-vpn}.${OPSBOX_DOMAIN:-opsbox.internal}"
caddy.reverse_proxy: "{{upstreams 8888}}"
caddy.tls: internal
networks:
proxy:
external: true
name: opsbox_proxy
+86 -56
View File
@@ -3,7 +3,7 @@ set -Eeuo pipefail
# OpsBox bootstrap + installer. Keep the Git URL in one place.
OPSBOX_GIT_REPO="${OPSBOX_GIT_REPO:-https://git.zakscode.com/ztimson/opsbox.git}"
OPSBOX_VERSION="1.1.1"
OPSBOX_VERSION="1.2.0"
OPSBOX_DIR="${OPSBOX_DIR:-}"
CONFIG_DIR="/etc/opsbox"
STATE_FILE="$CONFIG_DIR/selections"
@@ -51,21 +51,19 @@ require_root() { [[ $EUID -eq 0 ]] || die "Run as root: curl ... | sudo bash"; }
# Catalogue of components (alphabetical by tag)
# --------------------------------------------------------------------------------------
COMPONENTS=(
"adsb|ADS-B aircraft tracking (tar1090)"
"ai|Local AI (LiteRT)"
"atak|Tactical awareness kit (OpenTAK Server)"
"fallback-ap|Fallback wireless access point"
"hat|Wireless HAT (GPS, LoRa, RTC, SDR)"
"maps|Maps (Cartomake web UI)"
"openwebrx|OpenWebRX+ SDR receiver"
"pentest|Pen test suite (host tools + Bettercap)"
"personal-cloud|Personal cloud (AI, file editing, notes, ZIM reader)"
"rtl433|RTL_433 sensor decoder"
"sdr-tools|ADS-B, OpenWebRX+, RTL_433"
"speedtest|LibreSpeed speed test"
"tak|Tactical awareness kit (OpenTAK Server)"
"theme|Terminal prompt theme and login banner"
"tools|Tools (btop, jq, tmux)"
"vnc|VNC remote desktop"
"wireguard|WireGuard VPN"
"wireless-hat|4-in-1 (GPS, Lora, SDR, RTC)"
"zims|ZIM archives (offline Wikipedia, manuals, ...)"
)
for _c in "${COMPONENTS[@]}"; do COMP_LABEL["${_c%%|*}"]="${_c#*|}"; done
@@ -329,7 +327,11 @@ run_docker_component() {
step_components() {
local -a choices=() sel=()
local pair tag label lines lh selected t
sed -i -e '/^docker$/d' -e 's/^opentak$/atak/' -e 's/^sdr$/openwebrx/' "$STATE_FILE"
sed -i -e '/^docker$/d' -e 's/^opentak$/tak/' -e 's/^atak$/tak/' -e 's/^hat$/wireless-hat/' "$STATE_FILE"
if grep -qxE '^(adsb|openwebrx|rtl433|sdr)$' "$STATE_FILE"; then
grep -qx 'sdr-tools' "$STATE_FILE" || echo 'sdr-tools' >> "$STATE_FILE"
sed -i -e '/^adsb$/d' -e '/^openwebrx$/d' -e '/^rtl433$/d' -e '/^sdr$/d' "$STATE_FILE"
fi
lines="$(tlines)"; lh=$((lines - 9)); ((lh > 16)) && lh=16 || true; ((lh < 5)) && lh=5 || true
while true; do
choices=()
@@ -542,7 +544,7 @@ build_net_rows() {
local add='NET_ROWS+=("$1|$2|$3|$4|$5|$6|$7")'
net_add() { NET_ROWS+=("$1|$2|$3|$4|$5|$6|$7"); }
contains speedtest && net_add SPEEDTEST "LibreSpeed" speedtest 1900 LIBRESPEED_BIND LIBRESPEED_PORT no || true
contains atak && net_add OPENTAK "OpenTAK Server (web UI)" tak 8090 OTS_WEB_BIND OTS_WEB_PORT no || true
contains tak && net_add OPENTAK "TAK Server (web UI)" tak 8090 OTS_WEB_BIND OTS_WEB_PORT no || true
contains maps && net_add MAPS "Cartomake (maps UI)" maps 8020 CARTOMAKE_BIND CARTOMAKE_PORT no || true
[[ "${MAP_PHOTON:-no}" == yes ]] && net_add GEOCODE "Photon geocoder" geocode 8022 PHOTON_BIND PHOTON_PORT yes || true
[[ "${MAP_TILESERVER:-no}" == yes ]] && net_add TILES "TileServer GL" tiles 8021 TILESERVER_BIND TILESERVER_PORT yes || true
@@ -550,7 +552,8 @@ build_net_rows() {
net_add HARNESS "AI harness" home 8082 WEB_BIND HARNESS_PORT yes
net_add OFFICE "OnlyOffice" office 8083 WEB_BIND OFFICE_PORT yes
fi
contains openwebrx && net_add SDR "OpenWebRX+" sdr 8073 OPENWEBRX_BIND OPENWEBRX_PORT no || true
contains sdr-tools && net_add SDR "SDR tools (OpenWebRX+)" sdr 8073 OPENWEBRX_BIND OPENWEBRX_PORT no || true
contains wireguard && net_add WGPORTAL "WireGuard Portal" vpn 8888 - WG_PORTAL_UI_PORT no || true
if contains pentest; then
net_add BETTERCAP "Bettercap UI" bettercap 1600 - BETTERCAP_UI_PORT no
net_add BETTERCAP_API "Bettercap API" api.bettercap 8081 - BETTERCAP_API_PORT no
@@ -662,6 +665,30 @@ cfg_bettercap() {
done
}
cfg_wireguard() {
local err
WG_PORTAL_ADMIN_USER="${WG_PORTAL_ADMIN_USER:-admin@opsbox.internal}"
WG_PORTAL_ADMIN_PASSWORD="${WG_PORTAL_ADMIN_PASSWORD:-}"
WG_PORTAL_UI_PORT="${WG_PORTAL_UI_PORT:-8888}"
while true; do
form_run "WireGuard Portal" "Create the first WireGuard Portal administrator.
Use a strong password (at least 16 characters).
The web UI is routed through Caddy when enabled; UDP 51820 is used for VPN clients." \
"WG_PORTAL_ADMIN_USER|Admin email / username|t" \
"WG_PORTAL_ADMIN_PASSWORD|Admin password (16+ chars)|p" \
"WG_PORTAL_UI_PORT|Web UI port|t" || return 1
err=""
[[ "$WG_PORTAL_ADMIN_USER" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]] || err+="Admin username must be a valid email address.\n"
[[ "$WG_PORTAL_ADMIN_PASSWORD" =~ ^[A-Za-z0-9._-]{16,}$ ]] || err+="Password must be at least 16 characters (letters, numbers, dot, dash or underscore).\n"
valid_port "$WG_PORTAL_UI_PORT" || err+="Web UI port must be between 1 and 65535.\n"
[[ -z "$err" ]] && break
msg "$err"
done
WG_PORTAL_EXTERNAL_URL="https://${OPSBOX_SUB_WGPORTAL:-vpn}.$OPSBOX_DOMAIN"
WG_PORTAL_WEB_SESSION_SECRET="${WG_PORTAL_WEB_SESSION_SECRET:-$(openssl rand -hex 32)}"
WG_PORTAL_WEB_CSRF_SECRET="${WG_PORTAL_WEB_CSRF_SECRET:-$(openssl rand -hex 32)}"
}
cfg_openwebrx() {
local err
OPENWEBRX_ADMIN_USER="${OPENWEBRX_ADMIN_USER:-admin}"
@@ -797,10 +824,11 @@ step_services() {
local -a list=() n
local slug
contains pentest && list+=(cfg_bettercap) || true
contains openwebrx && list+=(cfg_openwebrx) || true
contains sdr-tools && list+=(cfg_openwebrx) || true
contains wireguard && list+=(cfg_wireguard) || true
contains fallback-ap && list+=(cfg_fallback_ap) || true
contains ai && list+=(cfg_ai) || true
contains hat && list+=(cfg_hat) || true
contains wireless-hat && list+=(cfg_hat) || true
if [[ "$MAP_SATELLITE" == yes || "$MAP_VECTOR" == yes || "$MAP_CONTOURS" == yes ]]; then list+=(cfg_maps); fi
if contains zims; then
for slug in "${ZIM_ORDER[@]}"; do
@@ -833,7 +861,9 @@ step_summary() {
for ((i = 0; i < ${#NET_ROWS[@]}; i++)); do
IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}"
sv="OPSBOX_SUB_$key"
if [[ "$USE_CADDY" == yes ]]; then sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (127.0.0.1:${!portv})"
if [[ "$USE_CADDY" == yes ]]; then
if [[ "$key" == WGPORTAL ]]; then sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (container:8888)"
else sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (127.0.0.1:${!portv})"; fi
else sum_add " $(printf '%-24s' "$label") ${!sv}.$OPSBOX_DOMAIN (host port ${!portv})"; fi
done
fi
@@ -853,19 +883,15 @@ step_summary() {
sum_add ""
sum_add "SERVICE SETTINGS"
contains pentest && sum_add " Bettercap: user '$BETTERCAP_USER'${BETTERCAP_UI_ADDR:+, listen $BETTERCAP_UI_ADDR}" || true
contains openwebrx && sum_add " OpenWebRX+: admin '$OPENWEBRX_ADMIN_USER', image $OPENWEBRX_IMAGE" || true
contains sdr-tools && sum_add " SDR tools: ADS-B, OpenWebRX+, RTL_433; OpenWebRX admin '$OPENWEBRX_ADMIN_USER'" || true
contains fallback-ap && sum_add " Fallback AP: SSID '$FALLBACK_AP_SSID' on $FALLBACK_AP_IFACE ($FALLBACK_AP_CIDR), check=$FALLBACK_AP_CHECK_MODE" || true
contains ai && sum_add " Local AI: $AI_REPO in $AI_DIR (download now: $AI_IMPORT)" || true
contains hat && sum_add " HAT overlays: GPS=$HAT_GPS LoRa=$HAT_LORA RTC=$HAT_RTC PPS=$HAT_PPS" || true
contains wireguard && sum_add " WireGuard: you will be offered an editor for wg0.conf if none exists" || true
local sdrn=0
contains openwebrx && sdrn=$((sdrn + 1)) || true
contains adsb && sdrn=$((sdrn + 1)) || true
contains rtl433 && sdrn=$((sdrn + 1)) || true
if ((sdrn > 1)); then
contains wireless-hat && sum_add " Wireless HAT: GPS=$HAT_GPS LoRa=$HAT_LORA RTC=$HAT_RTC PPS=$HAT_PPS" || true
contains wireguard && sum_add " WireGuard: WireGuard Portal admin '$WG_PORTAL_ADMIN_USER'" || true
if contains sdr-tools; then
sum_add ""
sum_add "NOTE: one RTL-SDR can only serve one SDR service at a time. You selected $sdrn;"
sum_add " use separate receivers or point only one at the HAT tuner."
sum_add "NOTE: one RTL-SDR can only be claimed by one SDR service at a time."
sum_add " Use separate receivers or configure only one service to use the HAT tuner."
fi
sum_add ""
sum_add "A reboot is recommended afterwards if hardware overlays or kernel modules change."
@@ -898,18 +924,28 @@ persist_config() {
if contains pentest; then
save_env BETTERCAP_USER BETTERCAP_PASSWORD BETTERCAP_UI_ADDR BETTERCAP_UI_PORT BETTERCAP_API_PORT BETTERCAP_ALLOW_ORIGIN
fi
if contains openwebrx; then save_env OPENWEBRX_ADMIN_USER OPENWEBRX_ADMIN_PASSWORD OPENWEBRX_IMAGE; fi
SDR_OPENWEBRX="$(contains openwebrx && echo yes || echo no)"
SDR_ADSB="$(contains adsb && echo yes || echo no)"
SDR_RTL433="$(contains rtl433 && echo yes || echo no)"
if contains sdr-tools; then
OPENWEBRX_IMAGE="${OPENWEBRX_IMAGE:-slechev/openwebrxplus-softmbe:latest}"
SDR_OPENWEBRX=yes; SDR_ADSB=yes; SDR_RTL433=yes
save_env OPENWEBRX_ADMIN_USER OPENWEBRX_ADMIN_PASSWORD OPENWEBRX_IMAGE
else
SDR_OPENWEBRX=no; SDR_ADSB=no; SDR_RTL433=no
fi
save_env SDR_OPENWEBRX SDR_ADSB SDR_RTL433
if contains wireguard; then
WG_PORTAL_EXTERNAL_URL="https://${OPSBOX_SUB_WGPORTAL:-vpn}.$OPSBOX_DOMAIN"
WG_PORTAL_WEB_SESSION_SECRET="${WG_PORTAL_WEB_SESSION_SECRET:-$(openssl rand -hex 32)}"
WG_PORTAL_WEB_CSRF_SECRET="${WG_PORTAL_WEB_CSRF_SECRET:-$(openssl rand -hex 32)}"
save_env WG_PORTAL_ADMIN_USER WG_PORTAL_ADMIN_PASSWORD WG_PORTAL_UI_PORT WG_PORTAL_BIND
save_env WG_PORTAL_EXTERNAL_URL WG_PORTAL_WEB_SESSION_SECRET WG_PORTAL_WEB_CSRF_SECRET
fi
save_env MAP_PHOTON MAP_TILESERVER MAP_SATELLITE MAP_VECTOR MAP_CONTOURS
if contains personal-cloud; then
OFFICE_JWT_SECRET="${OFFICE_JWT_SECRET:-$(openssl rand -hex 32)}"
save_env OFFICE_JWT_SECRET
fi
if contains ai; then save_env AI_DIR AI_REPO; fi
if contains hat; then save_env HAT_GPS HAT_LORA HAT_RTC HAT_PPS; fi
if contains wireless-hat; then save_env HAT_GPS HAT_LORA HAT_RTC HAT_PPS; fi
}
# ======================================================================================
@@ -1167,21 +1203,22 @@ HOOK
}
install_wireguard() {
apt_install wireguard || return 1
mkdir -p /etc/wireguard
chmod 0700 /etc/wireguard
if [[ ! -s /etc/wireguard/wg0.conf ]]; then
if ask_yes "No /etc/wireguard/wg0.conf exists. Open an editor to create it now?"; then
local editor="${EDITOR:-nano}"
has_cmd "$editor" || apt_install nano || return 1
"$editor" /etc/wireguard/wg0.conf
local url="${WG_PORTAL_EXTERNAL_URL:-https://${OPSBOX_SUB_WGPORTAL:-vpn}.$OPSBOX_DOMAIN}"
WG_PORTAL_BIND="${WG_PORTAL_BIND:-$([[ "$USE_CADDY" == yes ]] && echo 127.0.0.1 || echo 0.0.0.0)}"
mkdir -p "$DATA_ROOT/wg-portal/data" "$DATA_ROOT/wg-portal/config"
chmod 0700 "$DATA_ROOT/wg-portal" "$DATA_ROOT/wg-portal/config" "$DATA_ROOT/wg-portal/data"
save_env WG_PORTAL_BIND
compose_stack wg-portal docker/wg-portal.yml "$ENV_FILE" || return 1
log "WireGuard Portal is running."
if [[ "$USE_CADDY" == yes ]]; then
log "Web UI: $url (Caddy internal HTTPS)"
else
log "Web UI: http://$(hostname -I | awk '{print $1}'):${WG_PORTAL_UI_PORT:-8888}"
fi
fi
if [[ -s /etc/wireguard/wg0.conf ]]; then
chmod 0600 /etc/wireguard/wg0.conf
systemctl enable wg-quick@wg0
systemctl restart wg-quick@wg0 || return 1
else warn "WireGuard installed; wg0.conf not created, so the tunnel was not started."; fi
log "WireGuard UDP: port 51820"
log "Initial administrator: $WG_PORTAL_ADMIN_USER"
}
install_fallback_ap() {
@@ -1317,6 +1354,7 @@ os.chmod(tmp, 0o644); os.replace(tmp, path)
PY
systemctl enable --now docker || return 1
systemctl restart docker || return 1
docker login
register_docker_binfmt || return 1
docker network inspect opsbox_proxy >/dev/null 2>&1 || docker network create opsbox_proxy >/dev/null
usermod -aG docker "$ADMIN_USER"
@@ -1508,20 +1546,13 @@ BLACKLIST
fi
}
install_openwebrx() {
install_sdr_tools() {
prepare_rtlsdr_host || return 1
mkdir -p "$DATA_ROOT/sdr/openwebrx/etc" "$DATA_ROOT/sdr/openwebrx/var"
# The image's runtime uid isn't documented; keep state dirs writable until it's confirmed.
chmod 0777 "$DATA_ROOT/sdr/openwebrx/etc" "$DATA_ROOT/sdr/openwebrx/var"
compose_stack sdr/openwebrx docker/sdr.yml "$ENV_FILE"
}
install_sdr_decoders() {
prepare_rtlsdr_host || return 1
local -a profiles=()
contains adsb && profiles+=(--profile adsb) || true
contains rtl433 && profiles+=(--profile rtl433) || true
compose_stack sdr docker/sdr.yml "$ENV_FILE" "${profiles[@]}"
compose_stack sdr docker/sdr.yml "$ENV_FILE" \
--profile adsb --profile rtl433
}
install_ai() {
@@ -1607,18 +1638,17 @@ main() {
contains tools && run_component "Tools" install_tools || true
contains theme && run_component "Theme" install_theme || true
contains wireguard && run_component "WireGuard" install_wireguard || true
contains wireguard && run_docker_component "WireGuard Portal" install_wireguard || true
contains fallback-ap && run_component "Fallback AP" install_fallback_ap || true
contains vnc && run_component "VNC" install_vnc || true
contains ai && run_component "Local AI" install_ai || true
contains hat && run_component "Wireless HAT" install_hat || true
contains wireless-hat && run_component "Wireless HAT" install_hat || true
contains pentest && run_docker_component "Pen Test Suite" install_pentest || true
contains speedtest && run_docker_component "LibreSpeed" install_speedtest || true
contains atak && run_docker_component "OpenTAK Server" install_opentak || true
contains tak && run_docker_component "TAK Server" install_opentak || true
contains maps && run_docker_component "Maps" install_maps || true
contains personal-cloud && run_docker_component "Personal Cloud" install_personal_cloud || true
contains openwebrx && run_docker_component "OpenWebRX+" install_openwebrx || true
if contains adsb || contains rtl433; then run_docker_component "SDR decoders" install_sdr_decoders; fi
contains sdr-tools && run_docker_component "SDR tools" install_sdr_tools || true
contains zims && run_component "ZIM Archives" install_zims || true
[[ "$DOCKER_OK" == yes ]] && export_caddy_ca || true