nuno 修订了这个 Gist 1 month ago. 转到此修订
1 file changed, 37 insertions
gistfile1.txt(文件已创建)
| @@ -0,0 +1,37 @@ | |||
| 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 | + | } | |
上一页
下一页