-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsem_parse.awk
125 lines (109 loc) · 1.73 KB
/
sem_parse.awk
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/awk -f
# Remome the round brackets
function unwrap(word) {
return gensub(/.*\((.*)\).*/,"\\1","g",word)
}
# Remove the left bracket
function unwrapsvc(line) {
return gensub(/.*\((.*)$/,"\\1","g",line)
}
BEGIN {
servobj=0
bracket=0
svc=0
type=""
port=""
group=0
members=""
proto_type=0
expr=""
}
# :servobj (servobj
/:servobj\s+\(servobj/ {
# Beginning of the servobj block
servobj=1
bracket=1
}
# : (FW1_mgmt
/^\s*:\s+\(\S+$/ {
# Beginning of the object definition
if (!servobj) next
svc=1
bracket++
svcname=unwrapsvc($0)
}
# )
/^\s*\)\s*$/ {
# End of the object definition
if (!servobj) next
bracket--
if (bracket <= 0) {
servobj=0
next
}
if (proto_type) {
proto_type=0
next
}
# End of the servobj section?
if (group) {
print svcname " " members
}
else if (type != "ignore") {
print svcname " " type ":" port " " expr
}
expr=""
svc=0
type=""
port=""
group=0
members=""
}
/^\s*:type\s/ {
if (!svc || proto_type) next
type=tolower(unwrap($0))
switch (type) {
case "group":
group=1
break
case "other":
type="ip"
break
case /icmp|tcp|udp/:
break
default:
type="ignore"
break
}
}
/^\s*:proto_type\s\(\s*$/ {
if (svc) {
proto_type=1
bracket++
}
}
/^\s*:port\s\S/ {
if (svc) port=unwrap($0)
}
/^\s*:protocol\s/ {
if (svc) port=unwrap($0)
}
# :icmp_type (3)
/^\s*:icmp_type\s/ {
if (svc) port=unwrap($0)
}
# :exp ("dport=520,rip_cmd=RIPCMD_RESPONSE")
/^\s*:exp\s\(\S+.*\)/ {
if (svc) expr=unwrap($0)
}
# Group members
# : sqlnet2-1521
/^\s*:\s[^(]\S+$/ {
if (!group) next
if (members) members=members "," $NF
else members=$NF
}
# Something else withinga service definition with an open bracket
#/^\s*:\S+\s+\(\s*$/ {
# if (svc && servobj) bracket++
#}