#! /bin/bash -eu


# For fixing the following dns issue in k8s
# Nameserver limits were exceeded, some nameservers have been omitted, the applied nameserver line is: 127.0.0.1 1.1.1.1 1.1.1.1

# Update dns

sudo vim /etc/systemd/resolved.conf
sudo systemctl restart systemd-resolved

# Update ip

sudo vim /etc/netplan/01-netcfg.yaml
sudo netplan apply

# Check DNS servers
resolvectl status

## Block IP

# Ban a single IP for 1 year
kubectl exec -n crowdsec deployment/crowdsec-lapi -- \
  cscli decisions add --ip 1.2.3.4 --duration 8760h --reason "manual-ban"

# Ban a subnet
kubectl exec -n crowdsec deployment/crowdsec-lapi -- \
  cscli decisions add --range 1.2.3.0/24 --duration 8760h --reason "manual-ban"

# List all active decisions (including manual ones)
kubectl exec -n crowdsec deployment/crowdsec-lapi -- cscli decisions list

# Remove a manual ban
kubectl exec -n crowdsec deployment/crowdsec-lapi -- \
  cscli decisions delete --ip 1.2.3.4


# # Add IPs (comma-separated, supports CIDRs)
kubectl patch configmap ingress-nginx-controller -n ingress-nginx \
  --type merge \
  -p '{"data":{"block-cidrs-manual":"1.2.3.4,5.6.7.0/24"}}'
