gistfile1.txt
· 954 B · Text
Surowy
function cmd::fw::list() {
local peer="" type=""
while [[ $# -gt 0 ]]; do
case "$1" in
--peer) peer="$2"; shift 2 ;;
--type) type="$2"; shift 2 ;;
*) shift ;;
esac
done
log::section "Firewall Rules (FORWARD)"
if [[ -n "$peer" ]]; then
local ip
ip=$(peers::get_ip "$peer")
[[ -z "$ip" ]] && log::error "Peer not found: $peer" && return 1
printf "\n"
iptables -L FORWARD -n -v | grep -F "$ip"
printf "\n"
elif [[ -n "$type" ]]; then
local subnet
subnet=$(config::subnet_for "$type")
[[ -z "$subnet" ]] && log::error "Unknown type: $type" && return 1
printf "\n"
iptables -L FORWARD -n -v | grep -F "$subnet"
printf "\n"
else
printf "\n"
iptables -L FORWARD -n -v | grep -v "^Chain\|^target\|^$\|ACCEPT.*0\.0\.0\.0.*0\.0\.0\.0"
printf "\n"
fi
}
function cmd::fw::nat() {
log::section "NAT Rules (PREROUTING)"
iptables -t nat -L PREROUTING -n -v
}
| 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 | } |