nuno ha revisionato questo gist 1 month ago. Vai alla revisione
1 file changed, 67 insertions
gistfile1.txt(file creato)
| @@ -0,0 +1,67 @@ | |||
| 1 | + | function cmd::group::list() { | |
| 2 | + | local groups_dir | |
| 3 | + | groups_dir="$(ctx::groups)" | |
| 4 | + | ||
| 5 | + | local groups=("${groups_dir}"/*.group) | |
| 6 | + | if [[ ! -f "${groups[0]}" ]]; then | |
| 7 | + | log::wg "No groups configured" | |
| 8 | + | return 0 | |
| 9 | + | fi | |
| 10 | + | ||
| 11 | + | log::section "Groups" | |
| 12 | + | printf "\n %-20s %-35s %-8s %s\n" "NAME" "DESCRIPTION" "PEERS" "STATUS" | |
| 13 | + | printf " %s\n" "$(printf '─%.0s' {1..75})" | |
| 14 | + | ||
| 15 | + | while IFS="|" read -r name desc total blocked; do | |
| 16 | + | [[ -z "$name" ]] && continue | |
| 17 | + | ||
| 18 | + | local status_color="" status_str="active" | |
| 19 | + | if [[ "$total" -gt 0 ]]; then | |
| 20 | + | if [[ "$blocked" -eq "$total" ]]; then | |
| 21 | + | status_color="\033[1;31m" | |
| 22 | + | status_str="blocked" | |
| 23 | + | elif [[ "$blocked" -gt 0 ]]; then | |
| 24 | + | status_color="\033[1;33m" | |
| 25 | + | status_str="blocked (${blocked}/${total})" | |
| 26 | + | else | |
| 27 | + | status_color="\033[1;32m" | |
| 28 | + | status_str="active" | |
| 29 | + | fi | |
| 30 | + | fi | |
| 31 | + | ||
| 32 | + | local short_desc="${desc:0:33}" | |
| 33 | + | [[ ${#desc} -gt 33 ]] && short_desc="${short_desc}..." | |
| 34 | + | ||
| 35 | + | printf " %-20s %-35s %-8s %b\n" \ | |
| 36 | + | "$name" "${short_desc:-—}" "$total" \ | |
| 37 | + | "${status_color}${status_str}\033[0m" | |
| 38 | + | done < <(json::group_list_data "$groups_dir" "$(ctx::blocks)") | |
| 39 | + | ||
| 40 | + | printf "\n" | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | function cmd::rule::list() { | |
| 44 | + | local rules_dir | |
| 45 | + | rules_dir="$(ctx::rules)" | |
| 46 | + | ||
| 47 | + | local rules=("${rules_dir}"/*.rule) | |
| 48 | + | if [[ ! -f "${rules[0]}" ]]; then | |
| 49 | + | log::wg "No rules configured" | |
| 50 | + | return 0 | |
| 51 | + | fi | |
| 52 | + | ||
| 53 | + | log::section "Firewall Rules" | |
| 54 | + | printf "\n %-20s %-45s %-8s %-8s %s\n" \ | |
| 55 | + | "NAME" "DESCRIPTION" "ALLOWS" "BLOCKS" "PEERS" | |
| 56 | + | printf " %s\n" "$(printf '─%.0s' {1..95})" | |
| 57 | + | ||
| 58 | + | while IFS="|" read -r name desc n_allows n_blocks peer_count; do | |
| 59 | + | [[ -z "$name" ]] && continue | |
| 60 | + | local short_desc="${desc:0:43}" | |
| 61 | + | [[ ${#desc} -gt 43 ]] && short_desc="${short_desc}..." | |
| 62 | + | printf " %-20s %-45s %-8s %-8s %s\n" \ | |
| 63 | + | "$name" "${short_desc:-—}" "$n_allows" "$n_blocks" "${peer_count} peers" | |
| 64 | + | done < <(json::rule_list_data "$rules_dir" "$(ctx::meta)") | |
| 65 | + | ||
| 66 | + | printf "\n" | |
| 67 | + | } | |
Più nuovi
Più vecchi