Last active 1 month ago

nuno revised this gist 1 month ago. Go to revision

1 file changed, 37 insertions

gistfile1.txt(file created)

@@ -0,0 +1,37 @@
1 + function cmd::fw::list() {
2 + local peer="" type=""
3 + while [[ $# -gt 0 ]]; do
4 + case "$1" in
5 + --peer) peer="$2"; shift 2 ;;
6 + --type) type="$2"; shift 2 ;;
7 + *) shift ;;
8 + esac
9 + done
10 +
11 + log::section "Firewall Rules (FORWARD)"
12 +
13 + if [[ -n "$peer" ]]; then
14 + local ip
15 + ip=$(peers::get_ip "$peer")
16 + [[ -z "$ip" ]] && log::error "Peer not found: $peer" && return 1
17 + printf "\n"
18 + iptables -L FORWARD -n -v | grep -F "$ip"
19 + printf "\n"
20 + elif [[ -n "$type" ]]; then
21 + local subnet
22 + subnet=$(config::subnet_for "$type")
23 + [[ -z "$subnet" ]] && log::error "Unknown type: $type" && return 1
24 + printf "\n"
25 + iptables -L FORWARD -n -v | grep -F "$subnet"
26 + printf "\n"
27 + else
28 + printf "\n"
29 + iptables -L FORWARD -n -v | grep -v "^Chain\|^target\|^$\|ACCEPT.*0\.0\.0\.0.*0\.0\.0\.0"
30 + printf "\n"
31 + fi
32 + }
33 +
34 + function cmd::fw::nat() {
35 + log::section "NAT Rules (PREROUTING)"
36 + iptables -t nat -L PREROUTING -n -v
37 + }
Newer Older