blob: 903fcedc43ba3c87c77f394961129fdc63ba92b9 [file] [log] [blame]
Andy Bavier8d51c6c2015-04-01 11:40:22 -04001#!/bin/sh
2
3SHELL="/bin/bash"
4
5NIC=$( route|grep default|awk '{print$8}' )
6PORTAL=$( dig +short portal.opencloud.us )
7
8NAME="${1}"
9OP="${2}"
10SUBOP="${3}"
11ARGS="${4}"
12
13add_rule() {
14 ARGS=$1
15 iptables -C FORWARD $ARGS
16 if [ "$?" -ne 0 ]
17 then
18 iptables -I FORWARD 1 $ARGS
19 fi
20}
21
22add_local_access_rules() {
23 SUBNET=$( ip addr show $NIC|grep "inet "|awk '{print $2}' )
24 add_rule "-s $SUBNET -j ACCEPT"
25}
26
27add_portal_access_rules() {
28 add_rule "-s $PORTAL -j ACCEPT"
29}
30
31add_web_access_rules() {
32 add_rule "-p tcp --dport 80 -j ACCEPT"
33}
34
35if [ "$OP" = "start" ]
36then
37 add_local_access_rules
38 add_portal_access_rules
39 add_web_access_rules
40fi