#!/bin/bash

if [ $# -eq 0 ];then
   ports="5060 5061"
else
   ports="$@"
fi

# flush tables
iptables -F

# loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Allow eth0
iptables -A INPUT -i eth0 -p all -j ACCEPT
iptables -A OUTPUT -o eth0 -p all -j ACCEPT

#Allow some input ports for eth1
for i in ${ports}; do
   if [ ${i} -eq ${i} 2>/dev/null ]; then
      iptables -A INPUT -i eth1 -p tcp --dport ${i} -j ACCEPT
      iptables -A INPUT -i eth1 -p udp --dport ${i} -j ACCEPT
   else
      echo "Invalid port: ${i}."
   fi
done

# Deny all other input
iptables -A INPUT -i eth1 -p all -j DROP


iptables -A OUTPUT -o eth1 -p all -j ACCEPT
