nuno revidoval tento gist 2 months ago. Přejít na revizi
1 file changed, 47 insertions
gistfile1.txt(vytvořil soubor)
| @@ -0,0 +1,47 @@ | |||
| 1 | + | function cmd::rule::update() { | |
| 2 | + | local name="" desc="" | |
| 3 | + | local allow_ips=() block_ips=() block_ports=() | |
| 4 | + | local dns_redirect="" | |
| 5 | + | ||
| 6 | + | while [[ $# -gt 0 ]]; do | |
| 7 | + | case "$1" in | |
| 8 | + | --name) name="$2"; shift 2 ;; | |
| 9 | + | --desc) desc="$2"; shift 2 ;; | |
| 10 | + | --allow-ip) allow_ips+=("$2"); shift 2 ;; | |
| 11 | + | --block-ip) block_ips+=("$2"); shift 2 ;; | |
| 12 | + | --block-port) block_ports+=("$2"); shift 2 ;; | |
| 13 | + | --dns-redirect) dns_redirect=true; shift ;; | |
| 14 | + | --help) cmd::rule::help; return ;; | |
| 15 | + | *) | |
| 16 | + | log::error "Unknown flag: $1" | |
| 17 | + | return 1 | |
| 18 | + | ;; | |
| 19 | + | esac | |
| 20 | + | done | |
| 21 | + | ||
| 22 | + | if [[ -z "$name" ]]; then | |
| 23 | + | log::error "Missing required flag: --name" | |
| 24 | + | return 1 | |
| 25 | + | fi | |
| 26 | + | ||
| 27 | + | rule::require_exists "$name" || return 1 | |
| 28 | + | ||
| 29 | + | # Update individual fields if provided | |
| 30 | + | [[ -n "$desc" ]] && json::set "$(ctx::rule::path "${name}.rule")" "desc" "\"$desc\"" | |
| 31 | + | [[ -n "$dns_redirect" ]] && json::set "$(ctx::rule::path "${name}.rule")" "dns_redirect" "true" | |
| 32 | + | ||
| 33 | + | for ip in "${allow_ips[@]}"; do | |
| 34 | + | json::append "$(ctx::rule::path "${name}.rule")" "allow_ips" "$ip" | |
| 35 | + | done | |
| 36 | + | for ip in "${block_ips[@]}"; do | |
| 37 | + | json::append "$(ctx::rule::path "${name}.rule")" "block_ips" "$ip" | |
| 38 | + | done | |
| 39 | + | for port in "${block_ports[@]}"; do | |
| 40 | + | json::append "$(ctx::rule::path "${name}.rule")" "block_ports" "$port" | |
| 41 | + | done | |
| 42 | + | ||
| 43 | + | log::wg_success "Rule updated: ${name}" | |
| 44 | + | ||
| 45 | + | # Re-apply to all assigned peers | |
| 46 | + | rule::reapply_all "$name" | |
| 47 | + | } | |
Novější
Starší