gistfile1.txt
· 2.0 KiB · Text
Eredeti
function cmd::logs::follow() {
local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}"
local fw_only="${4:-false}" wg_only="${5:-false}"
log::section "WireGuard Live Log (Ctrl+C to stop)"
printf "\n"
local watch_args=()
[[ -n "$filter_name" ]] && watch_args+=(--name "$filter_name")
[[ -n "$filter_type" ]] && watch_args+=(--type "$filter_type")
$fw_only && watch_args+=(--restricted)
$wg_only && watch_args+=(--blocked)
cmd::watch::run "${watch_args[@]}"
}
function cmd::watch::run() {
local filter_name="" filter_type="" filter_peers=""
local blocked_only=false allowed_only=false restricted_only=false
local raw=false
rm -f /tmp/wgctl_hs_* /tmp/wgctl_attempt_* 2>/dev/null || true
while [[ $# -gt 0 ]]; do
case "$1" in
--name) filter_name="$2"; shift 2 ;;
--type) filter_type="$2"; shift 2 ;;
--peers) filter_peers="$2"; shift 2 ;;
--blocked) blocked_only=true; shift ;;
--allowed) allowed_only=true; shift ;;
--restricted) restricted_only=true; shift ;;
--raw) _WGCTL_RAW=true; shift ;;
--help) cmd::watch::help; return ;;
*)
log::error "Unknown flag: $1"
cmd::watch::help
return 1
;;
esac
done
log::section "wgctl — Live Monitor (Ctrl+C to stop)"
printf "\n"
local w_client=20 w_dest=18
if ! $blocked_only && ! $restricted_only; then
(
while true; do
cmd::watch::_poll_handshakes \
"$filter_name" "$filter_type" "$filter_peers" "$w_client" "$w_dest"
sleep 5
done
) &
local poller_pid=$!
fi
cmd::watch::_tail_events \
"$filter_name" "$filter_type" "$filter_peers" \
"$blocked_only" "$restricted_only" "$allowed_only" \
"$w_client" "$w_dest" &
local tailer_pid=$!
trap "kill $tailer_pid ${poller_pid:-} 2>/dev/null; \
rm -f /tmp/wgctl_hs_* /tmp/wgctl_attempt_*; printf '\n'; exit 0" INT TERM
wait
}
| 1 | function 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 | } |
| 16 | function 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 |