gistfile1.txt
· 886 B · Text
Eredeti
function cmd::identity::_device_status() {
local peer_name="${1:-}"
local peer_ip
peer_ip=$(peers::get_ip "$peer_name" 2>/dev/null) || return 0
[[ -z "$peer_ip" ]] && return 0
local is_blocked is_restricted pubkey handshake_ts
is_blocked=$(peers::is_blocked "$peer_name")
is_restricted=$(peers::is_restricted "$peer_name")
pubkey=$(cat "$(ctx::clients)/${peer_name}.pub" 2>/dev/null) || pubkey=""
handshake_ts=$(wg show wg0 latest-handshakes 2>/dev/null \
| awk -v pk="$pubkey" '$1==pk{print $2}') || handshake_ts=0
local last_ts last_evt
last_ts=$(peers::get_meta "$peer_name" "last_ts" 2>/dev/null) || last_ts=""
last_evt=$(peers::get_meta "$peer_name" "last_evt" 2>/dev/null) || last_evt=""
local status
status=$(peers::format_status \
"$peer_name" "$pubkey" "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts")
echo " — ${status}"
}
| 1 | function cmd::identity::_device_status() { |
| 2 | local peer_name="${1:-}" |
| 3 | local peer_ip |
| 4 | peer_ip=$(peers::get_ip "$peer_name" 2>/dev/null) || return 0 |
| 5 | [[ -z "$peer_ip" ]] && return 0 |
| 6 | |
| 7 | local is_blocked is_restricted pubkey handshake_ts |
| 8 | is_blocked=$(peers::is_blocked "$peer_name") |
| 9 | is_restricted=$(peers::is_restricted "$peer_name") |
| 10 | pubkey=$(cat "$(ctx::clients)/${peer_name}.pub" 2>/dev/null) || pubkey="" |
| 11 | handshake_ts=$(wg show wg0 latest-handshakes 2>/dev/null \ |
| 12 | | awk -v pk="$pubkey" '$1==pk{print $2}') || handshake_ts=0 |
| 13 | |
| 14 | local last_ts last_evt |
| 15 | last_ts=$(peers::get_meta "$peer_name" "last_ts" 2>/dev/null) || last_ts="" |
| 16 | last_evt=$(peers::get_meta "$peer_name" "last_evt" 2>/dev/null) || last_evt="" |
| 17 | |
| 18 | local status |
| 19 | status=$(peers::format_status \ |
| 20 | "$peer_name" "$pubkey" "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts") |
| 21 | echo " — ${status}" |
| 22 | } |