network-utility 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +2 -0
- data/document/acl-M6000-16E.md +27 -0
- data/document/acl-M6000-18S.md +27 -0
- data/document/acl-M6000-8.md +27 -0
- data/document/acl-M6000-8E.md +27 -0
- data/document/acl-MA5200G-8.md +204 -0
- data/document/acl-ME60-16.md +177 -0
- data/document/acl-ME60-X16.md +177 -0
- data/document/acl-NE40E-X16.md +204 -0
- data/document/acl-NE40E-X16A.md +204 -0
- data/document/acl-NE40E-X8.md +204 -0
- data/document/acl-NE40E.md +204 -0
- data/document/acl-NE5000E-20.md +25 -0
- data/document/acl-NE5000E-X16.md +25 -0
- data/document/acl-NE5000E-X16A.md +25 -0
- data/document/acl-NE80E.md +204 -0
- data/document/bgp-CR16010H-F.md +25 -0
- data/document/bgp-CR16018-F.md +25 -0
- data/document/bgp-CR19000-20.md +25 -0
- data/document/bgp-M6000-16E.md +25 -0
- data/document/bgp-M6000-18S.md +25 -0
- data/document/bgp-M6000-8.md +25 -0
- data/document/bgp-M6000-8E.md +25 -0
- data/document/bgp-MA5200G-8.md +25 -0
- data/document/bgp-ME60-16.md +25 -0
- data/document/bgp-ME60-X16.md +25 -0
- data/document/bgp-NE40E-X16.md +25 -0
- data/document/bgp-NE40E-X16A.md +25 -0
- data/document/bgp-NE40E-X8.md +25 -0
- data/document/bgp-NE40E.md +25 -0
- data/document/bgp-NE5000E-20.md +25 -0
- data/document/bgp-NE5000E-X16.md +25 -0
- data/document/bgp-NE5000E-X16A.md +25 -0
- data/document/bgp-NE80E.md +25 -0
- data/document/config.md +1153 -0
- data/document/document.rb +27 -0
- data/document/if-ALCATEL7750.md +48 -0
- data/document/if-C7609.md +47 -0
- data/document/if-CR16010H-F.md +300 -0
- data/document/if-CR16018-F.md +300 -0
- data/document/if-CR19000-20.md +300 -0
- data/document/if-CRS-16.md +47 -0
- data/document/if-CX600-X16A.md +349 -0
- data/document/if-CX600-X8A.md +349 -0
- data/document/if-M6000-16E.md +652 -0
- data/document/if-M6000-18S.md +846 -0
- data/document/if-M6000-8.md +653 -0
- data/document/if-M6000-8E.md +653 -0
- data/document/if-MA5200G-8.md +357 -0
- data/document/if-ME60-16.md +357 -0
- data/document/if-ME60-X16.md +357 -0
- data/document/if-NE40E-X16.md +357 -0
- data/document/if-NE40E-X16A.md +357 -0
- data/document/if-NE40E-X8.md +357 -0
- data/document/if-NE40E.md +357 -0
- data/document/if-NE5000E-20.md +357 -0
- data/document/if-NE5000E-X16.md +357 -0
- data/document/if-NE5000E-X16A.md +357 -0
- data/document/if-NE8000E-X8.md +357 -0
- data/document/if-NE80E.md +357 -0
- data/document/if-NE8100-X8.md +357 -0
- data/document/if-Nokia7750.md +48 -0
- data/document/if-T8000-18.md +653 -0
- data/document/if-V6000.md +663 -0
- data/document/if-VNE9000.md +357 -0
- data/document/if-ZXCTN9000-18EA.md +762 -0
- data/document/if-ZXCTN9000-8EA.md +762 -0
- data/document/lic-M6000-16E.md +28 -0
- data/document/lic-M6000-18S.md +28 -0
- data/document/lic-M6000-8.md +28 -0
- data/document/lic-M6000-8E.md +28 -0
- data/document/lic-MA5200G-8.md +27 -0
- data/document/lic-ME60-16.md +27 -0
- data/document/lic-ME60-X16.md +27 -0
- data/document/lic-NE40E-X16.md +27 -0
- data/document/lic-NE40E-X16A.md +27 -0
- data/document/lic-NE40E-X8.md +27 -0
- data/document/log-M6000-16E.md +36 -0
- data/document/log-M6000-18S.md +36 -0
- data/document/log-M6000-8.md +36 -0
- data/document/log-M6000-8E.md +36 -0
- data/document/log-MA5200G-8.md +61 -0
- data/document/log-ME60-16.md +61 -0
- data/document/log-ME60-X16.md +61 -0
- data/document/log-NE40E-X16.md +61 -0
- data/document/log-NE40E-X16A.md +61 -0
- data/document/log-NE40E-X8.md +61 -0
- data/document/log-NE40E.md +61 -0
- data/document/log-NE5000E-20.md +61 -0
- data/document/log-NE5000E-X16.md +61 -0
- data/document/log-NE5000E-X16A.md +61 -0
- data/document/log-NE80E.md +61 -0
- data/document/nat-CR16010H-F.md +27 -0
- data/document/nat-CR16018-F.md +27 -0
- data/document/nat-M6000-16E.md +27 -0
- data/document/nat-M6000-18S.md +27 -0
- data/document/nat-M6000-8.md +27 -0
- data/document/nat-M6000-8E.md +27 -0
- data/document/nat-ME60-16.md +44 -0
- data/document/nat-ME60-X16.md +44 -0
- data/document/nat-NE40E-X16.md +44 -0
- data/document/nat-NE40E-X16A.md +44 -0
- data/document/policy-M6000-16E.md +13 -0
- data/document/policy-M6000-18S.md +13 -0
- data/document/policy-M6000-8.md +13 -0
- data/document/policy-M6000-8E.md +13 -0
- data/document/policy-MA5200G-8.md +87 -0
- data/document/policy-ME60-16.md +87 -0
- data/document/policy-ME60-X16.md +87 -0
- data/document/policy-NE40E-X16.md +87 -0
- data/document/policy-NE40E-X16A.md +87 -0
- data/document/policy-NE40E-X8.md +87 -0
- data/document/policy-NE40E.md +87 -0
- data/document/policy-NE5000E-20.md +87 -0
- data/document/policy-NE5000E-X16.md +87 -0
- data/document/policy-NE5000E-X16A.md +87 -0
- data/document/policy-NE80E.md +87 -0
- data/document/pool-M6000-16E.md +126 -0
- data/document/pool-M6000-18S.md +126 -0
- data/document/pool-M6000-8.md +126 -0
- data/document/pool-M6000-8E.md +126 -0
- data/document/pool-MA5200G-8.md +138 -0
- data/document/pool-ME60-16.md +138 -0
- data/document/pool-ME60-X16.md +138 -0
- data/document/pool-NE40E-X16.md +138 -0
- data/document/pool-NE40E-X16A.md +138 -0
- data/document/pool-NE40E-X8.md +138 -0
- data/document/pool-NE40E.md +138 -0
- data/document/pool-NE80E.md +138 -0
- data/document/static-CR16010H-F.md +60 -0
- data/document/static-CR16018-F.md +60 -0
- data/document/static-CR19000-20.md +60 -0
- data/document/static-CX600-X16A.md +26 -0
- data/document/static-CX600-X8A.md +26 -0
- data/document/static-M6000-16E.md +104 -0
- data/document/static-M6000-18S.md +104 -0
- data/document/static-M6000-8.md +104 -0
- data/document/static-M6000-8E.md +104 -0
- data/document/static-MA5200G-8.md +82 -0
- data/document/static-ME60-16.md +82 -0
- data/document/static-ME60-X16.md +82 -0
- data/document/static-NE40E-X16.md +82 -0
- data/document/static-NE40E-X16A.md +81 -0
- data/document/static-NE40E-X8.md +82 -0
- data/document/static-NE40E.md +67 -0
- data/document/static-NE5000E-20.md +67 -0
- data/document/static-NE5000E-X16.md +67 -0
- data/document/static-NE5000E-X16A.md +67 -0
- data/document/static-NE8000E-X8.md +26 -0
- data/document/static-NE80E.md +67 -0
- data/document/static-NE8100-X8.md +26 -0
- data/document/static-T8000-18.md +34 -0
- data/document/static-ZXCTN9000-18EA.md +34 -0
- data/document/static-ZXCTN9000-8EA.md +34 -0
- data/document/system-M6000-16E.md +75 -0
- data/document/system-M6000-18S.md +76 -0
- data/document/system-M6000-8.md +75 -0
- data/document/system-M6000-8E.md +75 -0
- data/document/system-MA5200G-8.md +51 -0
- data/document/system-ME60-16.md +51 -0
- data/document/system-ME60-X16.md +51 -0
- data/document/system-NE40E-X16.md +51 -0
- data/document/system-NE40E-X16A.md +51 -0
- data/document/system-NE40E-X8.md +51 -0
- data/document/system-NE40E.md +51 -0
- data/document/system-NE5000E-20.md +51 -0
- data/document/system-NE5000E-X16.md +51 -0
- data/document/system-NE5000E-X16A.md +51 -0
- data/document/system-NE80E.md +51 -0
- data/document/telnet.md +332 -0
- data/network.rb +24 -0
- data/utility/ipv4_address.rb +266 -0
- data/utility/ipv6_address.rb +201 -0
- data/utility/mac_address.rb +77 -0
- data/utility/netmerge.rb +46 -0
- data/utility/route.rb +79 -0
- data/utility/whitelist.rb +21 -0
- metadata +258 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23f18332854c170df2b04dd20be2e6f6879ef3e934a98745008c147633973d2d
|
4
|
+
data.tar.gz: a9ac6e6461595415f2417b337d0b7cac064bed839f0fd5100b455c65c82bbc85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f06a78c3d35a93a3cff081c2cd472dec4c05fe2467262c3fcfb62dda916d292af34f1968b1e5115f84de4e590444069a6ec3e7f9805a17f0ed1de2001acd001e
|
7
|
+
data.tar.gz: 965189ade7f96895262c02b63b7c7b7b2cf09b23fcd4744f23c70797a2534c71714cfa1361195830e14d789842f625b483f39fd4e5121b9654e3f0c10d57c8c0
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# M6000-16E 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['M6000-16E', 'ACL']
|
6
|
+
|
7
|
+
module M6000_16E
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def ACL config
|
11
|
+
table = {}
|
12
|
+
name = nil
|
13
|
+
config.split("\n").each do|line|
|
14
|
+
name = line.split('ipv4-access-list')[1].strip if line.include?('ipv4-access-list')
|
15
|
+
name = line.split('ipv6-access-list')[1].strip if line.include?('ipv6-access-list')
|
16
|
+
name = line.split('link-access-list')[1].strip if line.include?('link-access-list')
|
17
|
+
table[name] ||= {}
|
18
|
+
if line.include?('rule')
|
19
|
+
rule = line.split(' ')
|
20
|
+
table[name][rule[1].to_i] = rule[2..-1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
table.delete(nil)
|
24
|
+
return table
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# M6000-18S 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['M6000-18S', 'ACL']
|
6
|
+
|
7
|
+
module M6000_18S
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def ACL config
|
11
|
+
table = {}
|
12
|
+
name = nil
|
13
|
+
config.split("\n").each do|line|
|
14
|
+
name = line.split('ipv4-access-list')[1].strip if line.include?('ipv4-access-list')
|
15
|
+
name = line.split('ipv6-access-list')[1].strip if line.include?('ipv6-access-list')
|
16
|
+
name = line.split('link-access-list')[1].strip if line.include?('link-access-list')
|
17
|
+
table[name] ||= {}
|
18
|
+
if line.include?('rule')
|
19
|
+
rule = line.split(' ')
|
20
|
+
table[name][rule[1].to_i] = rule[2..-1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
table.delete(nil)
|
24
|
+
return table
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# M6000-8 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['M6000-8', 'ACL']
|
6
|
+
|
7
|
+
module M6000_8
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def ACL config
|
11
|
+
table = {}
|
12
|
+
name = nil
|
13
|
+
config.split("\n").each do|line|
|
14
|
+
name = line.split('ipv4-access-list')[1].strip if line.include?('ipv4-access-list')
|
15
|
+
name = line.split('ipv6-access-list')[1].strip if line.include?('ipv6-access-list')
|
16
|
+
name = line.split('link-access-list')[1].strip if line.include?('link-access-list')
|
17
|
+
table[name] ||= {}
|
18
|
+
if line.include?('rule')
|
19
|
+
rule = line.split(' ')
|
20
|
+
table[name][rule[1].to_i] = rule[2..-1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
table.delete(nil)
|
24
|
+
return table
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# M6000-8E 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['M6000-8E', 'ACL']
|
6
|
+
|
7
|
+
module M6000_8E
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def ACL config
|
11
|
+
table = {}
|
12
|
+
name = nil
|
13
|
+
config.split("\n").each do|line|
|
14
|
+
name = line.split('ipv4-access-list')[1].strip if line.include?('ipv4-access-list')
|
15
|
+
name = line.split('ipv6-access-list')[1].strip if line.include?('ipv6-access-list')
|
16
|
+
name = line.split('link-access-list')[1].strip if line.include?('link-access-list')
|
17
|
+
table[name] ||= {}
|
18
|
+
if line.include?('rule')
|
19
|
+
rule = line.split(' ')
|
20
|
+
table[name][rule[1].to_i] = rule[2..-1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
table.delete(nil)
|
24
|
+
return table
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
@@ -0,0 +1,204 @@
|
|
1
|
+
|
2
|
+
# MA5200G-8 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['MA5200G-8', 'ACL']
|
6
|
+
@sign << ['MA5200G-8', 'resort']
|
7
|
+
@sign << ['MA5200G-8', 'detect_adv']
|
8
|
+
@sign << ['MA5200G-8', 'gen_rule']
|
9
|
+
|
10
|
+
module MA5200G_8
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def ACL config
|
14
|
+
table = {}
|
15
|
+
number = nil
|
16
|
+
config.split("\n").each do|line|
|
17
|
+
number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
|
18
|
+
table[number] ||= {}
|
19
|
+
if line.include?('rule')
|
20
|
+
rule = line.split(' ')
|
21
|
+
table[number][rule[1].to_i] = rule[2..-1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
table.delete(nil)
|
25
|
+
return table
|
26
|
+
end
|
27
|
+
|
28
|
+
# 重排ACL序号,只对纯文本编排,注意最末行
|
29
|
+
def resort text, index # {[old,old]=>new}
|
30
|
+
packs,newlist = {},[]
|
31
|
+
index.each do|is,ni| packs[ni] = [] end
|
32
|
+
text.split("\n").each do|line|
|
33
|
+
items = line.split(' ')
|
34
|
+
id = items[1].to_i
|
35
|
+
index.each do|is,ni|
|
36
|
+
packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
|
37
|
+
end
|
38
|
+
newlist << "undo rule #{id}"
|
39
|
+
end
|
40
|
+
packs.each do|ni,pack|
|
41
|
+
pack.sort.each_with_index do|rule, si|
|
42
|
+
newlist << "rule #{ni.to_i+si.to_i} #{rule}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return newlist.join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
# INTEGER<1000-1999> Interface access-list(add to current using rules)
|
49
|
+
# INTEGER<10000-10999> MPLS access list (add to current using rules)
|
50
|
+
# INTEGER<2000-2999> Basic access-list(add to current using rules)
|
51
|
+
# INTEGER<3000-3999> Advanced access-list(add to current using rules)
|
52
|
+
# INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
|
53
|
+
# ip-pool Specify IP pool configuration
|
54
|
+
# ipv6 ACL IPv6
|
55
|
+
# name Specify a named ACL
|
56
|
+
# number Specify a numbered ACL
|
57
|
+
|
58
|
+
PORTS = {
|
59
|
+
137 => 'netbios-ns',
|
60
|
+
138 => 'netbios-dgm',
|
61
|
+
139 => 'netbios-ssn',
|
62
|
+
19 => 'CHARgen',
|
63
|
+
179 => 'bgp',
|
64
|
+
514 => 'cmd',
|
65
|
+
13 => 'daytime',
|
66
|
+
9 => 'discard',
|
67
|
+
53 => 'domain',
|
68
|
+
7 => 'echo',
|
69
|
+
512 => 'exec',
|
70
|
+
79 => 'finger',
|
71
|
+
21 => 'ftp',
|
72
|
+
20 => 'ftp-data',
|
73
|
+
70 => 'gopher',
|
74
|
+
101 => 'hostname',
|
75
|
+
194 => 'irc',
|
76
|
+
543 => 'klogin',
|
77
|
+
544 => 'kshell',
|
78
|
+
513 => 'login',
|
79
|
+
515 => 'lpd',
|
80
|
+
119 => 'nntp',
|
81
|
+
109 => 'pop2',
|
82
|
+
110 => 'pop3',
|
83
|
+
25 => 'smtp',
|
84
|
+
111 => 'sunrpc',
|
85
|
+
49 => 'tacacs',
|
86
|
+
517 => 'talk',
|
87
|
+
23 => 'telnet',
|
88
|
+
37 => 'time',
|
89
|
+
540 => 'uucp',
|
90
|
+
43 => 'whois',
|
91
|
+
80 => 'www'
|
92
|
+
}
|
93
|
+
|
94
|
+
# acl-adv rule
|
95
|
+
def detect_adv rule,index=nil
|
96
|
+
words = rule.instance_of?(String) ? rule.split(' ') : rule # text or array
|
97
|
+
# words: <action> <protocol> [<src>] [<dst>] [<tail>]
|
98
|
+
# <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
|
99
|
+
# <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
|
100
|
+
# <tail> := "PENDING"
|
101
|
+
ritle = {}
|
102
|
+
ritle['index'] = index if index
|
103
|
+
action,protocol = words[0..1]
|
104
|
+
ritle['action'] = action
|
105
|
+
ritle['protocol'] = protocol
|
106
|
+
['source','destination'].each do|edge|
|
107
|
+
if words.include?(edge)
|
108
|
+
edge_ip = words[words.index(edge)+1]
|
109
|
+
unless edge_ip=='any'
|
110
|
+
if edge_ip.include?(':')
|
111
|
+
start_ip, ei_amask = IP.v6(edge_ip)
|
112
|
+
else
|
113
|
+
ei_amask_str = words[words.index(edge)+2]
|
114
|
+
ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
|
115
|
+
start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
|
116
|
+
end
|
117
|
+
end_ip = start_ip.clone + ei_amask.number
|
118
|
+
ritle[edge] = [start_ip.to_s, end_ip.to_s]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
['source-port', 'destination-port'].each do|port|
|
123
|
+
if words.include?(port)
|
124
|
+
op = words[words.index(port)+1]
|
125
|
+
range = case op
|
126
|
+
when 'range'
|
127
|
+
a, b = words[words.index(port)+2], words[words.index(port)+3]
|
128
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
129
|
+
b = PORTS.key(b) ? PORTS.key(b) : b.to_i
|
130
|
+
[ a, b ]
|
131
|
+
when 'lt'
|
132
|
+
a = words[words.index(port)+2]
|
133
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
134
|
+
[ 0, a ]
|
135
|
+
when 'gt'
|
136
|
+
a = words[words.index(port)+2]
|
137
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
138
|
+
[ 65535, a ]
|
139
|
+
when 'eq'
|
140
|
+
a = words[words.index(port)+2]
|
141
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
142
|
+
[ a, a ]
|
143
|
+
end.sort
|
144
|
+
ritle[port] = range
|
145
|
+
end
|
146
|
+
end
|
147
|
+
# TODO: tail
|
148
|
+
return ritle
|
149
|
+
end
|
150
|
+
|
151
|
+
# 查询规则1#
|
152
|
+
def in_range? ritle, target
|
153
|
+
tip = IP.v4(target[:ip])
|
154
|
+
tnum = tip.number
|
155
|
+
if ritle["destination"] && ritle["destination-port"]
|
156
|
+
si,ei = ritle["destination"].map{|i|IP.v4(i).number}
|
157
|
+
sp,ep = ritle["destination-port"]
|
158
|
+
return ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
|
159
|
+
end
|
160
|
+
return nil
|
161
|
+
end
|
162
|
+
|
163
|
+
# 查询规则2#
|
164
|
+
def list_in_range? list, target
|
165
|
+
tip = IP.v4(target[:ip])
|
166
|
+
tnum = tip.number
|
167
|
+
set = []
|
168
|
+
list.each do|ritle|
|
169
|
+
if ritle["destination"] && ritle["destination-port"]
|
170
|
+
si,ei = ritle["destination"].map{|i|IP.v4(i).number}
|
171
|
+
sp,ep = ritle["destination-port"]
|
172
|
+
set << ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
return set
|
176
|
+
end
|
177
|
+
|
178
|
+
# 生成规则:
|
179
|
+
# options = {
|
180
|
+
# index: 107,
|
181
|
+
# action: 'deny',
|
182
|
+
# protocol: 'tcp',
|
183
|
+
# sip: '1.1.1.1',
|
184
|
+
# sport: 80,
|
185
|
+
# dip: '2.2.2.2',
|
186
|
+
# dport: 443
|
187
|
+
# }
|
188
|
+
def gen_rule options
|
189
|
+
rule = ['rule']
|
190
|
+
return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
|
191
|
+
return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
|
192
|
+
return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
|
193
|
+
return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
|
194
|
+
rule << options[:index]
|
195
|
+
rule << options[:action]
|
196
|
+
rule << options[:protocol]
|
197
|
+
options[:sip] and rule << "source #{options[:sip]}"
|
198
|
+
options[:sport] and rule << "source-port eq #{options[:sport]}"
|
199
|
+
options[:dip] and rule << "destination #{options[:dip]}"
|
200
|
+
options[:dport] and rule << "destination-port eq #{options[:dport]}"
|
201
|
+
return {"operation"=>rule.join(" ")}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
```
|
@@ -0,0 +1,177 @@
|
|
1
|
+
|
2
|
+
# ME60-16 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['ME60-16', 'ACL']
|
6
|
+
@sign << ['ME60-16', 'resort']
|
7
|
+
@sign << ['ME60-16', 'detect_adv']
|
8
|
+
@sign << ['ME60-16', 'gen_rule']
|
9
|
+
|
10
|
+
module ME60_16
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def ACL config
|
14
|
+
table = {}
|
15
|
+
number = nil
|
16
|
+
config.split("\n").each do|line|
|
17
|
+
number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
|
18
|
+
table[number] ||= {}
|
19
|
+
if line.include?('rule')
|
20
|
+
rule = line.split(' ')
|
21
|
+
table[number][rule[1].to_i] = rule[2..-1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
table.delete(nil)
|
25
|
+
return table
|
26
|
+
end
|
27
|
+
|
28
|
+
# 重排ACL序号,只对纯文本编排,注意最末行
|
29
|
+
def resort text, index # {[old,old]=>new}
|
30
|
+
packs,newlist = {},[]
|
31
|
+
index.each do|is,ni| packs[ni] = [] end
|
32
|
+
text.split("\n").each do|line|
|
33
|
+
items = line.split(' ')
|
34
|
+
id = items[1].to_i
|
35
|
+
index.each do|is,ni|
|
36
|
+
packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
|
37
|
+
end
|
38
|
+
newlist << "undo rule #{id}"
|
39
|
+
end
|
40
|
+
packs.each do|ni,pack|
|
41
|
+
pack.sort.each_with_index do|rule, si|
|
42
|
+
newlist << "rule #{ni.to_i+si.to_i} #{rule}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return newlist.join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
# INTEGER<1000-1999> Interface access-list(add to current using rules)
|
49
|
+
# INTEGER<10000-10999> MPLS access list (add to current using rules)
|
50
|
+
# INTEGER<2000-2999> Basic access-list(add to current using rules)
|
51
|
+
# INTEGER<3000-3999> Advanced access-list(add to current using rules)
|
52
|
+
# INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
|
53
|
+
# ip-pool Specify IP pool configuration
|
54
|
+
# ipv6 ACL IPv6
|
55
|
+
# name Specify a named ACL
|
56
|
+
# number Specify a numbered ACL
|
57
|
+
|
58
|
+
PORTS = {
|
59
|
+
137 => 'netbios-ns',
|
60
|
+
138 => 'netbios-dgm',
|
61
|
+
139 => 'netbios-ssn',
|
62
|
+
19 => 'CHARgen',
|
63
|
+
179 => 'bgp',
|
64
|
+
514 => 'cmd',
|
65
|
+
13 => 'daytime',
|
66
|
+
9 => 'discard',
|
67
|
+
53 => 'domain',
|
68
|
+
7 => 'echo',
|
69
|
+
512 => 'exec',
|
70
|
+
79 => 'finger',
|
71
|
+
21 => 'ftp',
|
72
|
+
20 => 'ftp-data',
|
73
|
+
70 => 'gopher',
|
74
|
+
101 => 'hostname',
|
75
|
+
194 => 'irc',
|
76
|
+
543 => 'klogin',
|
77
|
+
544 => 'kshell',
|
78
|
+
513 => 'login',
|
79
|
+
515 => 'lpd',
|
80
|
+
119 => 'nntp',
|
81
|
+
109 => 'pop2',
|
82
|
+
110 => 'pop3',
|
83
|
+
25 => 'smtp',
|
84
|
+
111 => 'sunrpc',
|
85
|
+
49 => 'tacacs',
|
86
|
+
517 => 'talk',
|
87
|
+
23 => 'telnet',
|
88
|
+
37 => 'time',
|
89
|
+
540 => 'uucp',
|
90
|
+
43 => 'whois',
|
91
|
+
80 => 'www'
|
92
|
+
}
|
93
|
+
|
94
|
+
# acl-adv rule
|
95
|
+
def detect_adv rule,index=nil
|
96
|
+
words = rule.split(' ')
|
97
|
+
# words: <action> <protocol> [<src>] [<dst>] [<tail>]
|
98
|
+
# <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
|
99
|
+
# <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
|
100
|
+
# <tail> := "PENDING"
|
101
|
+
ritle = {}
|
102
|
+
ritle['index'] = index if index
|
103
|
+
action,protocol = words[0..1]
|
104
|
+
ritle['action'] = action
|
105
|
+
ritle['protocol'] = protocol
|
106
|
+
['source','destination'].each do|edge|
|
107
|
+
if words.include?(edge)
|
108
|
+
edge_ip = words[words.index(edge)+1]
|
109
|
+
unless edge_ip=='any'
|
110
|
+
if edge_ip.include?(':')
|
111
|
+
start_ip, ei_amask = IP.v6(edge_ip)
|
112
|
+
else
|
113
|
+
ei_amask_str = words[words.index(edge)+2]
|
114
|
+
ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
|
115
|
+
start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
|
116
|
+
end
|
117
|
+
end_ip = start_ip.clone + ei_amask.number
|
118
|
+
ritle[edge] = [start_ip.to_s, end_ip.to_s]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
['source-port', 'destination-port'].each do|port|
|
123
|
+
if words.include?(port)
|
124
|
+
op = words[words.index(port)+1]
|
125
|
+
range = case op
|
126
|
+
when 'range'
|
127
|
+
a, b = words[words.index(port)+2], words[words.index(port)+3]
|
128
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
129
|
+
b = PORTS.key(b) ? PORTS.key(b) : b.to_i
|
130
|
+
[ a, b ]
|
131
|
+
when 'lt'
|
132
|
+
a = words[words.index(port)+2]
|
133
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
134
|
+
[ 0, a ]
|
135
|
+
when 'gt'
|
136
|
+
a = words[words.index(port)+2]
|
137
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
138
|
+
[ 65535, a ]
|
139
|
+
when 'eq'
|
140
|
+
a = words[words.index(port)+2]
|
141
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
142
|
+
[ a, a ]
|
143
|
+
end.sort
|
144
|
+
ritle[port] = range
|
145
|
+
end
|
146
|
+
end
|
147
|
+
# TODO: tail
|
148
|
+
return ritle
|
149
|
+
end
|
150
|
+
|
151
|
+
# 生成规则:
|
152
|
+
# options = {
|
153
|
+
# index: 107,
|
154
|
+
# action: 'deny',
|
155
|
+
# protocol: 'tcp',
|
156
|
+
# sip: '1.1.1.1',
|
157
|
+
# sport: 80,
|
158
|
+
# dip: '2.2.2.2',
|
159
|
+
# dport: 443
|
160
|
+
# }
|
161
|
+
def gen_rule options
|
162
|
+
rule = ['rule']
|
163
|
+
return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
|
164
|
+
return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
|
165
|
+
return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
|
166
|
+
return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
|
167
|
+
rule << options[:index]
|
168
|
+
rule << options[:action]
|
169
|
+
rule << options[:protocol]
|
170
|
+
options[:sip] and rule << "source #{options[:sip]}"
|
171
|
+
options[:sport] and rule << "source-port eq #{options[:sport]}"
|
172
|
+
options[:dip] and rule << "destination #{options[:dip]}"
|
173
|
+
options[:dport] and rule << "destination-port eq #{options[:dport]}"
|
174
|
+
return {"operation"=>rule.join(" ")}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
```
|
@@ -0,0 +1,177 @@
|
|
1
|
+
|
2
|
+
# ME60-X16 访问控制列表
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
@sign << ['ME60-X16', 'ACL']
|
6
|
+
@sign << ['ME60-X16', 'resort']
|
7
|
+
@sign << ['ME60-X16', 'detect_adv']
|
8
|
+
@sign << ['ME60-X16', 'gen_rule']
|
9
|
+
|
10
|
+
module ME60_X16
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def ACL config
|
14
|
+
table = {}
|
15
|
+
number = nil
|
16
|
+
config.split("\n").each do|line|
|
17
|
+
number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
|
18
|
+
table[number] ||= {}
|
19
|
+
if line.include?('rule')
|
20
|
+
rule = line.split(' ')
|
21
|
+
table[number][rule[1].to_i] = rule[2..-1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
table.delete(nil)
|
25
|
+
return table
|
26
|
+
end
|
27
|
+
|
28
|
+
# 重排ACL序号,只对纯文本编排,注意最末行
|
29
|
+
def resort text, index # {[old,old]=>new}
|
30
|
+
packs,newlist = {},[]
|
31
|
+
index.each do|is,ni| packs[ni] = [] end
|
32
|
+
text.split("\n").each do|line|
|
33
|
+
items = line.split(' ')
|
34
|
+
id = items[1].to_i
|
35
|
+
index.each do|is,ni|
|
36
|
+
packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
|
37
|
+
end
|
38
|
+
newlist << "undo rule #{id}"
|
39
|
+
end
|
40
|
+
packs.each do|ni,pack|
|
41
|
+
pack.sort.each_with_index do|rule, si|
|
42
|
+
newlist << "rule #{ni.to_i+si.to_i} #{rule}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return newlist.join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
# INTEGER<1000-1999> Interface access-list(add to current using rules)
|
49
|
+
# INTEGER<10000-10999> MPLS access list (add to current using rules)
|
50
|
+
# INTEGER<2000-2999> Basic access-list(add to current using rules)
|
51
|
+
# INTEGER<3000-3999> Advanced access-list(add to current using rules)
|
52
|
+
# INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
|
53
|
+
# ip-pool Specify IP pool configuration
|
54
|
+
# ipv6 ACL IPv6
|
55
|
+
# name Specify a named ACL
|
56
|
+
# number Specify a numbered ACL
|
57
|
+
|
58
|
+
PORTS = {
|
59
|
+
137 => 'netbios-ns',
|
60
|
+
138 => 'netbios-dgm',
|
61
|
+
139 => 'netbios-ssn',
|
62
|
+
19 => 'CHARgen',
|
63
|
+
179 => 'bgp',
|
64
|
+
514 => 'cmd',
|
65
|
+
13 => 'daytime',
|
66
|
+
9 => 'discard',
|
67
|
+
53 => 'domain',
|
68
|
+
7 => 'echo',
|
69
|
+
512 => 'exec',
|
70
|
+
79 => 'finger',
|
71
|
+
21 => 'ftp',
|
72
|
+
20 => 'ftp-data',
|
73
|
+
70 => 'gopher',
|
74
|
+
101 => 'hostname',
|
75
|
+
194 => 'irc',
|
76
|
+
543 => 'klogin',
|
77
|
+
544 => 'kshell',
|
78
|
+
513 => 'login',
|
79
|
+
515 => 'lpd',
|
80
|
+
119 => 'nntp',
|
81
|
+
109 => 'pop2',
|
82
|
+
110 => 'pop3',
|
83
|
+
25 => 'smtp',
|
84
|
+
111 => 'sunrpc',
|
85
|
+
49 => 'tacacs',
|
86
|
+
517 => 'talk',
|
87
|
+
23 => 'telnet',
|
88
|
+
37 => 'time',
|
89
|
+
540 => 'uucp',
|
90
|
+
43 => 'whois',
|
91
|
+
80 => 'www'
|
92
|
+
}
|
93
|
+
|
94
|
+
# acl-adv rule
|
95
|
+
def detect_adv rule,index=nil
|
96
|
+
words = rule.split(' ')
|
97
|
+
# words: <action> <protocol> [<src>] [<dst>] [<tail>]
|
98
|
+
# <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
|
99
|
+
# <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
|
100
|
+
# <tail> := "PENDING"
|
101
|
+
ritle = {}
|
102
|
+
ritle['index'] = index if index
|
103
|
+
action,protocol = words[0..1]
|
104
|
+
ritle['action'] = action
|
105
|
+
ritle['protocol'] = protocol
|
106
|
+
['source','destination'].each do|edge|
|
107
|
+
if words.include?(edge)
|
108
|
+
edge_ip = words[words.index(edge)+1]
|
109
|
+
unless edge_ip=='any'
|
110
|
+
if edge_ip.include?(':')
|
111
|
+
start_ip, ei_amask = IP.v6(edge_ip)
|
112
|
+
else
|
113
|
+
ei_amask_str = words[words.index(edge)+2]
|
114
|
+
ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
|
115
|
+
start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
|
116
|
+
end
|
117
|
+
end_ip = start_ip.clone + ei_amask.number
|
118
|
+
ritle[edge] = [start_ip.to_s, end_ip.to_s]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
['source-port', 'destination-port'].each do|port|
|
123
|
+
if words.include?(port)
|
124
|
+
op = words[words.index(port)+1]
|
125
|
+
range = case op
|
126
|
+
when 'range'
|
127
|
+
a, b = words[words.index(port)+2], words[words.index(port)+3]
|
128
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
129
|
+
b = PORTS.key(b) ? PORTS.key(b) : b.to_i
|
130
|
+
[ a, b ]
|
131
|
+
when 'lt'
|
132
|
+
a = words[words.index(port)+2]
|
133
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
134
|
+
[ 0, a ]
|
135
|
+
when 'gt'
|
136
|
+
a = words[words.index(port)+2]
|
137
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
138
|
+
[ 65535, a ]
|
139
|
+
when 'eq'
|
140
|
+
a = words[words.index(port)+2]
|
141
|
+
a = PORTS.key(a) ? PORTS.key(a) : a.to_i
|
142
|
+
[ a, a ]
|
143
|
+
end.sort
|
144
|
+
ritle[port] = range
|
145
|
+
end
|
146
|
+
end
|
147
|
+
# TODO: tail
|
148
|
+
return ritle
|
149
|
+
end
|
150
|
+
|
151
|
+
# 生成规则:
|
152
|
+
# options = {
|
153
|
+
# index: 107,
|
154
|
+
# action: 'deny',
|
155
|
+
# protocol: 'tcp',
|
156
|
+
# sip: '1.1.1.1',
|
157
|
+
# sport: 80,
|
158
|
+
# dip: '2.2.2.2',
|
159
|
+
# dport: 443
|
160
|
+
# }
|
161
|
+
def gen_rule options
|
162
|
+
rule = ['rule']
|
163
|
+
return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
|
164
|
+
return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
|
165
|
+
return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
|
166
|
+
return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
|
167
|
+
rule << options[:index]
|
168
|
+
rule << options[:action]
|
169
|
+
rule << options[:protocol]
|
170
|
+
options[:sip] and rule << "source #{options[:sip]}"
|
171
|
+
options[:sport] and rule << "source-port eq #{options[:sport]}"
|
172
|
+
options[:dip] and rule << "destination #{options[:dip]}"
|
173
|
+
options[:dport] and rule << "destination-port eq #{options[:dport]}"
|
174
|
+
return {"operation"=>rule.join(" ")}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
```
|