Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | SHELL="/bin/bash" |
| 4 | |
| 5 | NIC=$( route|grep default|awk '{print $NF}' ) |
| 6 | PORTAL=$( dig +short portal.opencloud.us | tail -1 ) |
| 7 | |
| 8 | NAME="${1}" |
| 9 | OP="${2}" |
| 10 | SUBOP="${3}" |
| 11 | ARGS="${4}" |
| 12 | |
| 13 | add_rule() { |
| 14 | CHAIN=$1 |
| 15 | ARGS=$2 |
| 16 | iptables -C $CHAIN $ARGS |
| 17 | if [ "$?" -ne 0 ] |
| 18 | then |
| 19 | iptables -I $CHAIN 1 $ARGS |
| 20 | fi |
| 21 | } |
| 22 | |
| 23 | add_local_access_rules() { |
| 24 | SUBNET=$( ip addr show $NIC|grep "inet "|awk '{print $2}' ) |
| 25 | PRIVATENET=$( ip addr show virbr0|grep "inet "|awk '{print $2}' ) |
| 26 | add_rule "FORWARD" "-s $SUBNET -j ACCEPT" |
| 27 | # Don't NAT traffic from service VMs destined to the local subnet |
| 28 | add_rule "POSTROUTING" "-t nat -s $PRIVATENET -d $SUBNET -j RETURN" |
| 29 | } |
| 30 | |
| 31 | add_portal_access_rules() { |
| 32 | add_rule "FORWARD" "-s $PORTAL -j ACCEPT" |
| 33 | } |
| 34 | |
| 35 | add_web_access_rules() { |
| 36 | add_rule "FORWARD" "-p tcp --dport 80 -j ACCEPT" |
| 37 | } |
| 38 | |
| 39 | if [ "$OP" = "start" ] |
| 40 | then |
| 41 | add_local_access_rules |
| 42 | add_portal_access_rules |
| 43 | add_web_access_rules |
| 44 | fi |