gistfile1.txt
· 1.3 KiB · Text
Originalformat
function cmd::inspect::_blocks_info() {
local name="${1:-}"
local block_file
block_file="$(ctx::block::path "${name}.block")"
[[ ! -f "$block_file" ]] && return 0
local data
data=$(json::block_get "$block_file")
[[ -z "$data" ]] && return 0
local blocked_direct blocked_groups
blocked_direct=$(echo "$data" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('blocked_direct', False))" </dev/null)
blocked_groups=$(echo "$data" | python3 -c "import json,sys; d=json.load(sys.stdin); print(','.join(d.get('blocked_by_groups', [])))" </dev/null)
cmd::inspect::_section "Peer Blocks"
if [[ "${blocked_direct,,}" == "true" ]]; then
printf " \033[1;31m🚫\033[0m blocked directly\n"
fi
if [[ -n "$blocked_groups" ]]; then
printf " \033[1;31m🚫\033[0m blocked by groups: %s\n" "$blocked_groups"
fi
while IFS="|" read -r bname btype target port proto; do
[[ -z "$btype" ]] && continue
local display=""
case "$btype" in
full) display="all traffic" ;;
ip) display="$target" ;;
port) display="${target}:${port}:${proto}" ;;
subnet) display="$target" ;;
esac
local label="${bname:-$btype}"
printf " \033[0;31m-\033[0m %-30s \033[0;37m%s\033[0m\n" \
"$display" "$label"
done < <(json::block_get_rules "$block_file")
}
| 1 | function cmd::inspect::_blocks_info() { |
| 2 | local name="${1:-}" |
| 3 | local block_file |
| 4 | block_file="$(ctx::block::path "${name}.block")" |
| 5 | [[ ! -f "$block_file" ]] && return 0 |
| 6 | |
| 7 | local data |
| 8 | data=$(json::block_get "$block_file") |
| 9 | [[ -z "$data" ]] && return 0 |
| 10 | |
| 11 | local blocked_direct blocked_groups |
| 12 | blocked_direct=$(echo "$data" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('blocked_direct', False))" </dev/null) |
| 13 | blocked_groups=$(echo "$data" | python3 -c "import json,sys; d=json.load(sys.stdin); print(','.join(d.get('blocked_by_groups', [])))" </dev/null) |
| 14 | |
| 15 | cmd::inspect::_section "Peer Blocks" |
| 16 | |
| 17 | if [[ "${blocked_direct,,}" == "true" ]]; then |
| 18 | printf " \033[1;31m🚫\033[0m blocked directly\n" |
| 19 | fi |
| 20 | if [[ -n "$blocked_groups" ]]; then |
| 21 | printf " \033[1;31m🚫\033[0m blocked by groups: %s\n" "$blocked_groups" |
| 22 | fi |
| 23 | |
| 24 | while IFS="|" read -r bname btype target port proto; do |
| 25 | [[ -z "$btype" ]] && continue |
| 26 | local display="" |
| 27 | case "$btype" in |
| 28 | full) display="all traffic" ;; |
| 29 | ip) display="$target" ;; |
| 30 | port) display="${target}:${port}:${proto}" ;; |
| 31 | subnet) display="$target" ;; |
| 32 | esac |
| 33 | local label="${bname:-$btype}" |
| 34 | printf " \033[0;31m-\033[0m %-30s \033[0;37m%s\033[0m\n" \ |
| 35 | "$display" "$label" |
| 36 | done < <(json::block_get_rules "$block_file") |
| 37 | } |