44 lines
1.3 KiB
Bash
Executable File
44 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# WireGuard status using ip command (no wg show needed)
|
|
ICON_ACTIVE="" # Shield with checkmark
|
|
ICON_INACTIVE="" # Shield disabled
|
|
|
|
# Get all WireGuard interfaces
|
|
wg_interfaces=$(ip a | grep -o 'wg[0-9]\+' | sort -u)
|
|
|
|
active_info=""
|
|
tooltip="<b>WireGuard Status</b>"
|
|
|
|
for interface in $wg_interfaces; do
|
|
# Check if interface has an IP address
|
|
ip_addr=$(ip -4 addr show dev "$interface" | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
|
|
|
|
if [ -n "$ip_addr" ]; then
|
|
# Interface is active
|
|
if [ -z "$active_info" ]; then
|
|
active_info="%{F#a3be8c}$ICON_ACTIVE%{F-} $interface:$ip_addr"
|
|
else
|
|
active_info+=" $interface:$ip_addr"
|
|
fi
|
|
tooltip+="\n\n<b>$interface</b>"
|
|
tooltip+="\n<b>Status:</b> <span color='#a3be8c'>Active</span>"
|
|
tooltip+="\n<b>IP:</b> $ip_addr"
|
|
else
|
|
# Interface exists but inactive
|
|
tooltip+="\n\n<b>$interface</b>"
|
|
tooltip+="\n<b>Status:</b> <span color='#bf616a'>Inactive</span>"
|
|
fi
|
|
done
|
|
|
|
if [ -z "$wg_interfaces" ]; then
|
|
# No WireGuard interfaces found
|
|
echo "{\"text\":\"$ICON_INACTIVE\",\"tooltip\":\"No WireGuard interfaces configured\"}"
|
|
elif [ -z "$active_info" ]; then
|
|
# Interfaces exist but none active
|
|
echo "{\"text\":\"$ICON_INACTIVE\",\"tooltip\":\"$tooltip\"}"
|
|
else
|
|
# Active interfaces found
|
|
echo "{\"text\":\"$ICON_ACTIVE\",\"tooltip\":\"$tooltip\"}"
|
|
fi
|