-
Notifications
You must be signed in to change notification settings - Fork 0
/
Firewall.py
64 lines (51 loc) · 1.36 KB
/
Firewall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import string, os
from Accesslist import *
from Interface import *
from Tuple import *
from Rule import *
from Util import *
class Firewall:
WILDCARD = Interface('*')
def __init__(self):
self.__interfaces = {}
self.__accesslists = {}
def addInterface(self, interface):
#print "Firewall.addInterface"
self.__interfaces[interface.getName()] = interface
def getInterfaces(self):
return self.__interfaces.values()
def getInterface(self, name):
#print "Getting key %s" % name
interface = None
try:
interface = self.__interfaces[name]
except:
pass
return interface
def addAccesslist(self, accesslist):
key = makeKey(accesslist.getIncoming(), accesslist.getOutgoing())
self.__accesslists[key] = accesslist
def getAccesslist(self, incoming, outgoing):
key = makeKey(incoming, outgoing)
try:
accesslist = self.__accesslists[key]
except KeyError:
accesslist = None
return accesslist
fw = Firewall()
iface1 = Interface("inside")
iface1.setSecuritylevel(100)
fw.addInterface(iface1)
iface2 = Interface("outside")
iface2.setSecuritylevel(0)
fw.addInterface(iface2)
al = Accesslist(iface1,iface2)
fw.addAccesslist(al)
r = Rule('accept')
t = Tuple();
t.setAddress("10.0.5.2");
t.setProtocol('tcp');
t.setPort('ssh')
r.setSource(Tuple())
r.setDestination(t)
al.addRule(r)