-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexipam.py
executable file
·97 lines (71 loc) · 2.12 KB
/
flexipam.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
import sys
import getopt
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
_debug = False
flexipam_config = "/home/lechner/Projects/PAM/flexipam/sample-config/"
def GetFirstChild(e): return e[0] if len(e) else None
def execute(which):
if(_debug):
print("Exec:\t", which)
tree = ET.ElementTree(file=flexipam_config + "actions/" + which)
action = tree.getroot()
helper = action.find("helper")
config = action.find("config")
print("Call:\t", helper.text, "[" + config.text + "]")
def include(which):
if(_debug):
print("Load:\t", which)
tree = ET.ElementTree(file=flexipam_config + "modules/" + which)
module = tree.getroot()
for part in module:
eval(part)
return True
def all(parts):
for part in parts:
if eval(part) == False:
return False
return True
def any(parts):
for part in parts:
if eval(part) == True:
return True
return False
def eval(part):
if (_debug):
print("Eval:\t", part.tag)
if part.tag == "all":
return all(part)
elif part.tag == "any":
return any(part)
elif part.tag == "include":
return include(part.text)
elif part.tag == "execute":
return execute(part.text)
return False
def main(argv):
try:
opts, args = getopt.getopt(argv, "hp:d", ["help", "grammar="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt == '-d':
global _debug
_debug = True
elif opt in ("-p", "--protocol"):
protocol_arg = arg
tree = ET.ElementTree(file=flexipam_config + "protocols/" + protocol_arg)
protocol = tree.getroot()
for stage in protocol:
print("\nOpen:\t", stage.tag)
eval(GetFirstChild(stage))
print("Close:\t", stage.tag)
if __name__ == "__main__":
main(sys.argv[1:])