network-utility 2.0.7 → 2.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87c75a5f5b8679971f6e749bdc32952558724020c9ea11c9a7aaf3f926295dcd
4
- data.tar.gz: eed14980851e3224e176c48293c844acfa6753145182dce21d140e7f5f7660ac
3
+ metadata.gz: ef840b84dccd263f22272e28b83434fc7ef73671ab7d7d5cee76cf2ca6777db0
4
+ data.tar.gz: 79faa1234510f0e3278dcf271b9541e01c26f974f29c742c0244967a7087adb5
5
5
  SHA512:
6
- metadata.gz: d3b394f69972da92e48c4d24f0e588459c20d9296d1c00deffe3f28c6bfc92fbf546d9dcc856e016e320a3af74dd9f7dc65618556d63d5d4e7e841c83df11b1e
7
- data.tar.gz: 510f87f5fb0e43ba88f95d65b40109cce298d19a79079da9becaf2a52c23bc487b518ac06c7a55149f5ad459520ec5581f057e656ad416de00eed780638df03d
6
+ metadata.gz: cd3d516e9c115917be76168bc7c7e28689c9de22b83acbdacd01d410a22feaeea8d8cb586632b49a74660b9f0d1b0ef56895bae4d4cc7fb944b20effe44c0cb6
7
+ data.tar.gz: 6d8ed3f9edb5730cf890f53cc8fafd182ee6a702a4fd50e7ebbdc9aeed2ded766c833be4bdd52af512318dfce453fe72ebca14efdbbf3a488e63026ef15d4686
@@ -0,0 +1,204 @@
1
+
2
+ # CX600-X16A 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['CX600-X16A', 'ACL']
6
+ @sign << ['CX600-X16A', 'resort']
7
+ @sign << ['CX600-X16A', 'detect_adv']
8
+ @sign << ['CX600-X16A', 'gen_rule']
9
+
10
+ module CX600_X16A
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,204 @@
1
+
2
+ # CX600-X8A 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['CX600-X8A', 'ACL']
6
+ @sign << ['CX600-X8A', 'resort']
7
+ @sign << ['CX600-X8A', 'detect_adv']
8
+ @sign << ['CX600-X8A', 'gen_rule']
9
+
10
+ module CX600_X8A
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,77 @@
1
+ # ZXCTN9000-18EA 访问控制列表
2
+
3
+ ```ruby
4
+ @sign << ['ZXCTN9000-18EA', 'ACL']
5
+ @sign << ['ZXCTN9000-18EA', 'ACL6']
6
+ @sign << ['ZXCTN9000-18EA', 'LinkACL']
7
+
8
+ module ZXCTN9000_18EA
9
+ module_function
10
+
11
+ def ACL config, mode=:config # or :text
12
+ table = {}
13
+ name = nil
14
+ config.split("\n").each do|line|
15
+ name = line.split('ipv4-access-list')[1].strip if line.include?('ipv4-access-list')
16
+ table[name] ||= {}
17
+ if mode==:config
18
+ if line.include?('rule')
19
+ rule = line.split(' ')
20
+ table[name][rule[1].to_i] = rule[2..-1]
21
+ end
22
+ elsif mode==:text
23
+ if line.include?('permit') || line.include?('deny')
24
+ rule = line.split(' ')
25
+ table[name][rule[0].to_i] = rule[1..-1]
26
+ end
27
+ end
28
+ end
29
+ table.delete(nil)
30
+ return table
31
+ end
32
+
33
+ def ACL6 config, mode=:config # or :text
34
+ table = {}
35
+ name = nil
36
+ config.split("\n").each do|line|
37
+ name = line.split('ipv6-access-list')[1].strip if line.include?('ipv6-access-list')
38
+ table[name] ||= {}
39
+ if mode==:config
40
+ if line.include?('rule')
41
+ rule = line.split(' ')
42
+ table[name][rule[1].to_i] = rule[2..-1]
43
+ end
44
+ elsif mode==:text
45
+ if line.include?('permit') || line.include?('deny')
46
+ rule = line.split(' ')
47
+ table[name][rule[0].to_i] = rule[1..-1]
48
+ end
49
+ end
50
+ end
51
+ table.delete(nil)
52
+ return table
53
+ end
54
+
55
+ def LinkACL config, mode=:config # or :text
56
+ table = {}
57
+ name = nil
58
+ config.split("\n").each do|line|
59
+ name = line.split('link-access-list')[1].strip if line.include?('link-access-list')
60
+ table[name] ||= {}
61
+ if mode==:config
62
+ if line.include?('rule')
63
+ rule = line.split(' ')
64
+ table[name][rule[1].to_i] = rule[2..-1]
65
+ end
66
+ elsif mode==:text
67
+ if line.include?('permit') || line.include?('deny')
68
+ rule = line.split(' ')
69
+ table[name][rule[0].to_i] = rule[1..-1]
70
+ end
71
+ end
72
+ end
73
+ table.delete(nil)
74
+ return table
75
+ end
76
+ end
77
+ ```
@@ -0,0 +1,77 @@
1
+ # ZXCTN9000-8EA 访问控制列表
2
+
3
+ ```ruby
4
+ @sign << ['ZXCTN9000-8EA', 'ACL']
5
+ @sign << ['ZXCTN9000-8EA', 'ACL6']
6
+ @sign << ['ZXCTN9000-8EA', 'LinkACL']
7
+
8
+ module ZXCTN9000_8EA
9
+ module_function
10
+
11
+ def ACL config, mode=:config # or :text
12
+ table = {}
13
+ name = nil
14
+ config.split("\n").each do|line|
15
+ name = line.split('ipv4-access-list')[1].strip if line.include?('ipv4-access-list')
16
+ table[name] ||= {}
17
+ if mode==:config
18
+ if line.include?('rule')
19
+ rule = line.split(' ')
20
+ table[name][rule[1].to_i] = rule[2..-1]
21
+ end
22
+ elsif mode==:text
23
+ if line.include?('permit') || line.include?('deny')
24
+ rule = line.split(' ')
25
+ table[name][rule[0].to_i] = rule[1..-1]
26
+ end
27
+ end
28
+ end
29
+ table.delete(nil)
30
+ return table
31
+ end
32
+
33
+ def ACL6 config, mode=:config # or :text
34
+ table = {}
35
+ name = nil
36
+ config.split("\n").each do|line|
37
+ name = line.split('ipv6-access-list')[1].strip if line.include?('ipv6-access-list')
38
+ table[name] ||= {}
39
+ if mode==:config
40
+ if line.include?('rule')
41
+ rule = line.split(' ')
42
+ table[name][rule[1].to_i] = rule[2..-1]
43
+ end
44
+ elsif mode==:text
45
+ if line.include?('permit') || line.include?('deny')
46
+ rule = line.split(' ')
47
+ table[name][rule[0].to_i] = rule[1..-1]
48
+ end
49
+ end
50
+ end
51
+ table.delete(nil)
52
+ return table
53
+ end
54
+
55
+ def LinkACL config, mode=:config # or :text
56
+ table = {}
57
+ name = nil
58
+ config.split("\n").each do|line|
59
+ name = line.split('link-access-list')[1].strip if line.include?('link-access-list')
60
+ table[name] ||= {}
61
+ if mode==:config
62
+ if line.include?('rule')
63
+ rule = line.split(' ')
64
+ table[name][rule[1].to_i] = rule[2..-1]
65
+ end
66
+ elsif mode==:text
67
+ if line.include?('permit') || line.include?('deny')
68
+ rule = line.split(' ')
69
+ table[name][rule[0].to_i] = rule[1..-1]
70
+ end
71
+ end
72
+ end
73
+ table.delete(nil)
74
+ return table
75
+ end
76
+ end
77
+ ```