dhcp_parser 0.3.4 → 0.3.5

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
  SHA1:
3
- metadata.gz: 762ed2389f1faac46c7a27c6a15cb54d87a77a2e
4
- data.tar.gz: 8fc5242b62b07770970a2fcf5846d389d7d75f42
3
+ metadata.gz: 65f6a1a11d00dfa0f40e3b4f99d7911779aa3fb8
4
+ data.tar.gz: 5706e19dfedcced78ad4d180e49e8f943c8694df
5
5
  SHA512:
6
- metadata.gz: 018f89008ad70524b2c739bd3179fbfe245cd5ee48c46804d6ef19ac72164e70821166f80374e42c8ae6b9a70a51f9cb277ee745ddb48965c5698850b48947f6
7
- data.tar.gz: 50f8654a8f348d4b86fcf44eed5aa0debea7b08e92129bb0936875badbb87ab636bd019b7ec2f3a828840041f2b60191b859dbf67e7e3a1d23b08448d5873bd4
6
+ metadata.gz: 97e2408115a4b03891e4eacf6854ab1963fa582b4de03568a5a0ae8449eed2b61a76c8549b7aaf8be454c26f70e3d6cb936ced630211ce0bea519924e810ed4d
7
+ data.tar.gz: a6faaefba43fd0bc09889a4f0cf9264aca12199e85030f6b43cbf7c672f0153cb5122e2acbd2a40f074adf763b9f6e46d09bc6d4f841491166c1263b4ae39937
data/README.md CHANGED
@@ -224,11 +224,11 @@ net2.attribute
224
224
 
225
225
  #### 2. Write file
226
226
 
227
- Create object net, then set attribute for object. Then call method write_file in module WriteConf with param: "path/file_name", "array_net"
228
-
227
+ Create object net, then set attribute for object. Then call method write_file in module WriteConf with param: "path/file_name", "array_net","condition: true/false". If the condition is true, you will append new net into file.
228
+ If the condition is false, you will write the new file .
229
229
  ```ruby
230
230
  array_net = dhcp.net
231
- result = dhcp.write_file_conf(path/file_name.type, array_net)
231
+ result = dhcp.write_file_conf(path/file_name.type, array_net, condition)
232
232
  # Success
233
233
  => true
234
234
  # Fail
Binary file
@@ -0,0 +1,262 @@
1
+ subnet 192.168.1.0 netmask 255.255.255.0 {
2
+ option routers 192.168.1.1;
3
+ option subnet-mask 255.255.255.0;
4
+ option broadcast-address 192.168.1.255;
5
+ option domain-name-servers 194.168.4.100;
6
+ option ntp-servers 192.168.1.1;
7
+ option netbios-name-servers 192.168.1.1;
8
+ default-lease-time 60400;
9
+ max-lease-time 60400;
10
+ authoritative;
11
+ pool {
12
+ range 192.168.25.20 192.168.25.200;
13
+ allow unknown-clients;
14
+ host bla1 {
15
+ hardware ethernet DD:GH:DF:E5:F7:D7;
16
+ fixed-address 192.168.1.2
17
+ }
18
+ host bla2 {
19
+ hardware ethernet 00:JJ:YU:38:AC:45;
20
+ fixed-address 192.168.1.20
21
+ }
22
+ }
23
+ }
24
+
25
+ subnet 10.152.187.0 netmask 255.255.255.255 {
26
+ option routers 10.152.187.1;
27
+ option subnet-mask 255.255.255.255;
28
+ option broadcast-address 10.150.168.255;
29
+ option domain-name-servers 192.168.4.101;
30
+ option ntp-servers 10.152.187.10;
31
+ option netbios-name-servers 10.152.187.12;
32
+ option netbios-node-type 2;
33
+ default-lease-time 86400;
34
+ max-lease-time 86400;
35
+ pool {
36
+ range 192.168.25.20 192.168.25.30;
37
+ denny unknown-clients;
38
+ host bla3 {
39
+ hardware ethernet 00:KK:HD:66:55:9B;
40
+ fixed-address 10.152.187.2
41
+ }
42
+ }
43
+ }subnet 192.168.1.0 netmask 255.255.255.0 {
44
+ option routers 192.168.1.1;
45
+ option subnet-mask 255.255.255.0;
46
+ option broadcast-address 192.168.1.255;
47
+ option domain-name-servers 194.168.4.100;
48
+ option ntp-servers 192.168.1.1;
49
+ option netbios-name-servers 192.168.1.1;
50
+ default-lease-time 60400;
51
+ max-lease-time 60400;
52
+ authoritative;
53
+ pool {
54
+ range 192.168.25.20 192.168.25.200;
55
+ allow unknown-clients;
56
+ host bla1 {
57
+ hardware ethernet DD:GH:DF:E5:F7:D7;
58
+ fixed-address 192.168.1.2
59
+ }
60
+ host bla2 {
61
+ hardware ethernet 00:JJ:YU:38:AC:45;
62
+ fixed-address 192.168.1.20
63
+ }
64
+ }
65
+ }
66
+
67
+ subnet 10.152.187.0 netmask 255.255.255.255 {
68
+ option routers 10.152.187.1;
69
+ option subnet-mask 255.255.255.255;
70
+ option broadcast-address 10.150.168.255;
71
+ option domain-name-servers 192.168.4.101;
72
+ option ntp-servers 10.152.187.10;
73
+ option netbios-name-servers 10.152.187.12;
74
+ option netbios-node-type 2;
75
+ default-lease-time 86400;
76
+ max-lease-time 86400;
77
+ pool {
78
+ range 192.168.25.20 192.168.25.30;
79
+ denny unknown-clients;
80
+ host bla3 {
81
+ hardware ethernet 00:KK:HD:66:55:9B;
82
+ fixed-address 10.152.187.2
83
+ }
84
+ }
85
+ }
86
+
87
+ subnet 192.168.1.0 netmask 255.255.255.0 {
88
+ option routers 192.168.1.1;
89
+ option subnet-mask 255.255.255.0;
90
+ option broadcast-address 192.168.1.255;
91
+ option domain-name-servers 194.168.4.100;
92
+ option ntp-servers 192.168.1.1;
93
+ option netbios-name-servers 192.168.1.1;
94
+ default-lease-time 60400;
95
+ max-lease-time 60400;
96
+ authoritative;
97
+ pool {
98
+ range 192.168.25.20 192.168.25.200;
99
+ allow unknown-clients;
100
+ host bla1 {
101
+ hardware ethernet DD:GH:DF:E5:F7:D7;
102
+ fixed-address 192.168.1.2
103
+ }
104
+ host bla2 {
105
+ hardware ethernet 00:JJ:YU:38:AC:45;
106
+ fixed-address 192.168.1.20
107
+ }
108
+ }
109
+ }
110
+
111
+ subnet 10.152.187.0 netmask 255.255.255.255 {
112
+ option routers 10.152.187.1;
113
+ option subnet-mask 255.255.255.255;
114
+ option broadcast-address 10.150.168.255;
115
+ option domain-name-servers 192.168.4.101;
116
+ option ntp-servers 10.152.187.10;
117
+ option netbios-name-servers 10.152.187.12;
118
+ option netbios-node-type 2;
119
+ default-lease-time 86400;
120
+ max-lease-time 86400;
121
+ pool {
122
+ range 192.168.25.20 192.168.25.30;
123
+ denny unknown-clients;
124
+ host bla3 {
125
+ hardware ethernet 00:KK:HD:66:55:9B;
126
+ fixed-address 10.152.187.2
127
+ }
128
+ }
129
+ }
130
+
131
+ subnet 192.168.1.0 netmask 255.255.255.0 {
132
+ option routers 192.168.1.1;
133
+ option subnet-mask 255.255.255.0;
134
+ option broadcast-address 192.168.1.255;
135
+ option domain-name-servers 194.168.4.100;
136
+ option ntp-servers 192.168.1.1;
137
+ option netbios-name-servers 192.168.1.1;
138
+ default-lease-time 60400;
139
+ max-lease-time 60400;
140
+ authoritative;
141
+ pool {
142
+ range 192.168.25.20 192.168.25.200;
143
+ allow unknown-clients;
144
+ host bla1 {
145
+ hardware ethernet DD:GH:DF:E5:F7:D7;
146
+ fixed-address 192.168.1.2
147
+ }
148
+ host bla2 {
149
+ hardware ethernet 00:JJ:YU:38:AC:45;
150
+ fixed-address 192.168.1.20
151
+ }
152
+ }
153
+ }
154
+
155
+ subnet 10.152.187.0 netmask 255.255.255.255 {
156
+ option routers 10.152.187.1;
157
+ option subnet-mask 255.255.255.255;
158
+ option broadcast-address 10.150.168.255;
159
+ option domain-name-servers 192.168.4.101;
160
+ option ntp-servers 10.152.187.10;
161
+ option netbios-name-servers 10.152.187.12;
162
+ option netbios-node-type 2;
163
+ default-lease-time 86400;
164
+ max-lease-time 86400;
165
+ pool {
166
+ range 192.168.25.20 192.168.25.30;
167
+ denny unknown-clients;
168
+ host bla3 {
169
+ hardware ethernet 00:KK:HD:66:55:9B;
170
+ fixed-address 10.152.187.2
171
+ }
172
+ }
173
+ }
174
+
175
+ subnet 192.168.1.0 netmask 255.255.255.0 {
176
+ option routers 192.168.1.1;
177
+ option subnet-mask 255.255.255.0;
178
+ option broadcast-address 192.168.1.255;
179
+ option domain-name-servers 194.168.4.100;
180
+ option ntp-servers 192.168.1.1;
181
+ option netbios-name-servers 192.168.1.1;
182
+ default-lease-time 60400;
183
+ max-lease-time 60400;
184
+ authoritative;
185
+ pool {
186
+ range 192.168.25.20 192.168.25.200;
187
+ allow unknown-clients;
188
+ host bla1 {
189
+ hardware ethernet DD:GH:DF:E5:F7:D7;
190
+ fixed-address 192.168.1.2
191
+ }
192
+ host bla2 {
193
+ hardware ethernet 00:JJ:YU:38:AC:45;
194
+ fixed-address 192.168.1.20
195
+ }
196
+ }
197
+ }
198
+
199
+ subnet 10.152.187.0 netmask 255.255.255.255 {
200
+ option routers 10.152.187.1;
201
+ option subnet-mask 255.255.255.255;
202
+ option broadcast-address 10.150.168.255;
203
+ option domain-name-servers 192.168.4.101;
204
+ option ntp-servers 10.152.187.10;
205
+ option netbios-name-servers 10.152.187.12;
206
+ option netbios-node-type 2;
207
+ default-lease-time 86400;
208
+ max-lease-time 86400;
209
+ pool {
210
+ range 192.168.25.20 192.168.25.30;
211
+ denny unknown-clients;
212
+ host bla3 {
213
+ hardware ethernet 00:KK:HD:66:55:9B;
214
+ fixed-address 10.152.187.2
215
+ }
216
+ }
217
+ }
218
+
219
+ subnet 192.168.1.0 netmask 255.255.255.0 {
220
+ option routers 192.168.1.1;
221
+ option subnet-mask 255.255.255.0;
222
+ option broadcast-address 192.168.1.255;
223
+ option domain-name-servers 194.168.4.100;
224
+ option ntp-servers 192.168.1.1;
225
+ option netbios-name-servers 192.168.1.1;
226
+ default-lease-time 60400;
227
+ max-lease-time 60400;
228
+ authoritative;
229
+ pool {
230
+ range 192.168.25.20 192.168.25.200;
231
+ allow unknown-clients;
232
+ host bla1 {
233
+ hardware ethernet DD:GH:DF:E5:F7:D7;
234
+ fixed-address 192.168.1.2
235
+ }
236
+ host bla2 {
237
+ hardware ethernet 00:JJ:YU:38:AC:45;
238
+ fixed-address 192.168.1.20
239
+ }
240
+ }
241
+ }
242
+
243
+ subnet 10.152.187.0 netmask 255.255.255.255 {
244
+ option routers 10.152.187.1;
245
+ option subnet-mask 255.255.255.255;
246
+ option broadcast-address 10.150.168.255;
247
+ option domain-name-servers 192.168.4.101;
248
+ option ntp-servers 10.152.187.10;
249
+ option netbios-name-servers 10.152.187.12;
250
+ option netbios-node-type 2;
251
+ default-lease-time 86400;
252
+ max-lease-time 86400;
253
+ pool {
254
+ range 192.168.25.20 192.168.25.30;
255
+ denny unknown-clients;
256
+ host bla3 {
257
+ hardware ethernet 00:KK:HD:66:55:9B;
258
+ fixed-address 10.152.187.2
259
+ }
260
+ }
261
+ }
262
+
@@ -0,0 +1,68 @@
1
+ <subnets>
2
+ <subnet>
3
+ <net>192.168.1.0</net>
4
+ <mask>255.255.255.0</mask>
5
+ <option>
6
+ <routers>192.168.1.1</routers>
7
+ <subnet-mask>255.255.255.0</subnet-mask>
8
+ <broadcast-address>192.168.1.255</broadcast-address>
9
+ <domain-name-servers>194.168.4.100</domain-name-servers>
10
+ <ntp-servers>192.168.1.1</ntp-servers>
11
+ <netbios-name-servers>192.168.1.1</netbios-name-servers>
12
+ </option>
13
+ <default-lease-time>60400</default-lease-time>
14
+ <max-lease-time>60400</max-lease-time>
15
+ <authoritative>true</authoritative>
16
+ <pool>
17
+ <range>
18
+ <min>192.168.25.20</min>
19
+ <max>192.168.25.200</max>
20
+ </range>
21
+ <allow>unknown-clients</allow>
22
+ <denny></denny>
23
+ <hosts>
24
+ <host>
25
+ <name>bla1</name>
26
+ <ethernet>DD:GH:DF:E5:F7:D7</ethernet>
27
+ <address>192.168.1.2</address>
28
+ </host>
29
+ <host>
30
+ <name>bla2</name>
31
+ <ethernet>00:JJ:YU:38:AC:45</ethernet>
32
+ <address>192.168.1.20</address>
33
+ </host>
34
+ </hosts>
35
+ </pool>
36
+ </subnet>
37
+ <subnet>
38
+ <net>10.152.187.0</net>
39
+ <mask>255.255.255.255</mask>
40
+ <option>
41
+ <routers>10.152.187.1</routers>
42
+ <subnet-mask>255.255.255.255</subnet-mask>
43
+ <broadcast-address>10.150.168.255</broadcast-address>
44
+ <domain-name-servers>192.168.4.101</domain-name-servers>
45
+ <ntp-servers>10.152.187.10</ntp-servers>
46
+ <netbios-name-servers>10.152.187.12</netbios-name-servers>
47
+ <netbios-node-type>2</netbios-node-type>
48
+ </option>
49
+ <authoritative>false<authoritative>
50
+ <default-lease-time>86400</default-lease-time>
51
+ <max-lease-time>86400</max-lease-time>
52
+ <pool>
53
+ <range>
54
+ <min>192.168.25.20</min>
55
+ <max>192.168.25.30</max>
56
+ </range>
57
+ <allow></allow>
58
+ <denny>unknown-clients</denny>
59
+ <hosts>
60
+ <host>
61
+ <name>bla3</name>
62
+ <ethernet>00:KK:HD:66:55:9B</ethernet>
63
+ <address>10.152.187.2</address>
64
+ </host>
65
+ </hosts>
66
+ </pool>
67
+ </subnet>
68
+ </subnets>
@@ -1,3 +1,3 @@
1
1
  module DhcpParser
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module WriteConf
2
2
 
3
- def self.write_file_conf(file_name,nets)
3
+ def self.write_file_conf(file_name,nets,condition)
4
4
  if nets.nil?
5
5
  return false
6
6
  else
@@ -8,10 +8,17 @@ module WriteConf
8
8
  nets.each do |net|
9
9
  data += WriteConf.set_data(net)
10
10
  end
11
- file = File.open("#{file_name}","a+")
12
- file.puts(data)
13
- file.close
14
- return true
11
+ if condition
12
+ file = File.open("#{file_name}","a+")
13
+ file.puts(data)
14
+ file.close
15
+ return true
16
+ else
17
+ file = File.open("#{file_name}","w+")
18
+ file.write(data)
19
+ file.close
20
+ return true
21
+ end
15
22
  end
16
23
  end
17
24
 
data/lib/dhcp_parser.rb CHANGED
@@ -391,9 +391,9 @@ module DHCPParser
391
391
  end
392
392
 
393
393
  # Write file
394
- def write_file_conf(file_name, arr_net)
394
+ def write_file_conf(file_name, arr_net, condition)
395
395
  if !arr_net.empty?
396
- result = WriteConf.write_file_conf(file_name, arr_net)
396
+ result = WriteConf.write_file_conf(file_name, arr_net, condition)
397
397
  end
398
398
  end
399
399
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dhcp_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nguyen hoang anh
@@ -58,6 +58,7 @@ files:
58
58
  - dhcp_parser-0.3.0.gem
59
59
  - dhcp_parser-0.3.2.gem
60
60
  - dhcp_parser-0.3.3.gem
61
+ - dhcp_parser-0.3.4.gem
61
62
  - dhcp_parser.gemspec
62
63
  - examples/default_dhcp.conf
63
64
  - examples/test1_dhcp.conf
@@ -66,8 +67,10 @@ files:
66
67
  - examples/test5_dhcp.conf
67
68
  - examples/test6_dhcp.conf
68
69
  - examples/test7_dhcp.conf
70
+ - examples/test8_dhcp.conf
69
71
  - examples/test_data.xml
70
72
  - examples/test_dhcp.conf
73
+ - examples/testdhcp.xml
71
74
  - examples/xmlconvert.xml
72
75
  - lib/dhcp_parser.rb
73
76
  - lib/dhcp_parser/host.rb