nuno ревизий этого фрагмента 1 month ago. К ревизии
1 file changed, 80 insertions
gistfile1.txt(файл создан)
| @@ -0,0 +1,80 @@ | |||
| 1 | + | function cmd::unblock::run() { | |
| 2 | + | local name="" | |
| 3 | + | local type="" | |
| 4 | + | local ips=() | |
| 5 | + | local subnets=() | |
| 6 | + | local ports=() | |
| 7 | + | local all=false | |
| 8 | + | local quiet=false | |
| 9 | + | ||
| 10 | + | while [[ $# -gt 0 ]]; do | |
| 11 | + | case "$1" in | |
| 12 | + | --name) name="$2"; shift 2 ;; | |
| 13 | + | --type) type="$2"; shift 2 ;; | |
| 14 | + | --ip) ips+=("$2"); shift 2 ;; | |
| 15 | + | --force) force=true; shift ;; | |
| 16 | + | --quiet) quiet=true; shift ;; | |
| 17 | + | --subnet) subnets+=("$2"); shift 2 ;; | |
| 18 | + | --port) ports+=("$2"); shift 2 ;; | |
| 19 | + | --all) all=true; shift ;; | |
| 20 | + | --help) cmd::unblock::help; return ;; | |
| 21 | + | *) | |
| 22 | + | log::error "Unknown flag: $1" | |
| 23 | + | cmd::unblock::help | |
| 24 | + | return 1 | |
| 25 | + | ;; | |
| 26 | + | esac | |
| 27 | + | done | |
| 28 | + | ||
| 29 | + | if [[ -z "$name" ]]; then | |
| 30 | + | log::error "Missing required flag: --name" | |
| 31 | + | cmd::unblock::help | |
| 32 | + | return 1 | |
| 33 | + | fi | |
| 34 | + | ||
| 35 | + | name=$(peers::resolve_and_require "$name" "$type") || return 1 | |
| 36 | + | ||
| 37 | + | # Check if actually blocked | |
| 38 | + | if ! peers::is_blocked "$name" && ! block::has_file "$name"; then | |
| 39 | + | log::wg_warning "Client is not blocked: ${name}" | |
| 40 | + | return 0 | |
| 41 | + | fi | |
| 42 | + | ||
| 43 | + | # Default to full unblock if no specific flags given | |
| 44 | + | if [[ ${#ips[@]} -eq 0 && ${#subnets[@]} -eq 0 && ${#ports[@]} -eq 0 ]]; then | |
| 45 | + | all=true | |
| 46 | + | fi | |
| 47 | + | ||
| 48 | + | local client_ip | |
| 49 | + | client_ip=$(peers::get_ip "$name") || return 1 | |
| 50 | + | ||
| 51 | + | # $quiet || log::section "Unblocking client: ${name} (${client_ip})" | |
| 52 | + | ||
| 53 | + | if $all; then | |
| 54 | + | cmd::unblock::_unblock_all "$name" "$client_ip" "$quiet" | |
| 55 | + | return 0 | |
| 56 | + | fi | |
| 57 | + | ||
| 58 | + | # Unblock specific IPs | |
| 59 | + | for ip in "${ips[@]}"; do | |
| 60 | + | fw::unblock_ip "$client_ip" "$ip" | |
| 61 | + | block::remove_rule "$name" "ip" "$ip" | |
| 62 | + | done | |
| 63 | + | ||
| 64 | + | # Unblock specific subnets | |
| 65 | + | for subnet in "${subnets[@]}"; do | |
| 66 | + | fw::unblock_subnet "$client_ip" "$subnet" | |
| 67 | + | done | |
| 68 | + | ||
| 69 | + | # Unblock specific ports | |
| 70 | + | for entry in "${ports[@]}"; do | |
| 71 | + | local target port proto | |
| 72 | + | IFS=":" read -r target port proto <<< "$entry" | |
| 73 | + | proto="${proto:-tcp}" | |
| 74 | + | fw::unblock_port "$client_ip" "$target" "$port" "$proto" | |
| 75 | + | done | |
| 76 | + | ||
| 77 | + | $quiet || log::wg_success "Unblock rules applied for: ${name}" | |
| 78 | + | ||
| 79 | + | return 0 | |
| 80 | + | } | |
Новее
Позже