Última atividade 1 month ago

Revisão d11adee5b2221d4b4709babedb908dc5044b6205

gistfile1.txt Bruto
1function cmd::logs::follow() {
2 local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}"
3 local fw_only="${4:-false}" wg_only="${5:-false}"
4
5 log::section "WireGuard Live Log (Ctrl+C to stop)"
6 printf "\n"
7
8 local watch_args=()
9 [[ -n "$filter_name" ]] && watch_args+=(--name "$filter_name")
10 [[ -n "$filter_type" ]] && watch_args+=(--type "$filter_type")
11 $fw_only && watch_args+=(--restricted)
12 $wg_only && watch_args+=(--blocked)
13
14 cmd::watch::run "${watch_args[@]}"
15}
16function cmd::watch::run() {
17 local filter_name="" filter_type="" filter_peers=""
18 local blocked_only=false allowed_only=false restricted_only=false
19 local raw=false
20
21 rm -f /tmp/wgctl_hs_* /tmp/wgctl_attempt_* 2>/dev/null || true
22
23 while [[ $# -gt 0 ]]; do
24 case "$1" in
25 --name) filter_name="$2"; shift 2 ;;
26 --type) filter_type="$2"; shift 2 ;;
27 --peers) filter_peers="$2"; shift 2 ;;
28 --blocked) blocked_only=true; shift ;;
29 --allowed) allowed_only=true; shift ;;
30 --restricted) restricted_only=true; shift ;;
31 --raw) _WGCTL_RAW=true; shift ;;
32 --help) cmd::watch::help; return ;;
33 *)
34 log::error "Unknown flag: $1"
35 cmd::watch::help
36 return 1
37 ;;
38 esac
39 done
40
41 log::section "wgctl — Live Monitor (Ctrl+C to stop)"
42 printf "\n"
43
44 local w_client=20 w_dest=18
45
46 if ! $blocked_only && ! $restricted_only; then
47 (
48 while true; do
49 cmd::watch::_poll_handshakes \
50 "$filter_name" "$filter_type" "$filter_peers" "$w_client" "$w_dest"
51 sleep 5
52 done
53 ) &
54 local poller_pid=$!
55 fi
56
57 cmd::watch::_tail_events \
58 "$filter_name" "$filter_type" "$filter_peers" \
59 "$blocked_only" "$restricted_only" "$allowed_only" \
60 "$w_client" "$w_dest" &
61 local tailer_pid=$!
62
63 trap "kill $tailer_pid ${poller_pid:-} 2>/dev/null; \
64 rm -f /tmp/wgctl_hs_* /tmp/wgctl_attempt_*; printf '\n'; exit 0" INT TERM
65
66 wait
67}
68