@@ -104,32 +104,46 @@ func (o *Operator) StopMonitoringLists() {
104
104
}
105
105
}
106
106
107
- func (o * Operator ) readDomainsList (raw , fileName string ) (dups uint64 ) {
108
- log .Debug ("Loading domains list: %s, size: %d" , fileName , len (raw ))
107
+ func filterDomains (line , defValue string ) (bool , string , string ) {
108
+ if len (line ) < 9 {
109
+ return true , line , defValue
110
+ }
111
+ // exclude not valid lines
112
+ if line [:7 ] != "0.0.0.0" && line [:9 ] != "127.0.0.1" {
113
+ return true , line , defValue
114
+ }
115
+ host := line [8 :]
116
+ // exclude localhost entries
117
+ if line [:9 ] == "127.0.0.1" {
118
+ host = line [10 :]
119
+ }
120
+ if host == "local" || host == "localhost" || host == "localhost.localdomain" || host == "broadcasthost" {
121
+ return true , line , defValue
122
+ }
123
+
124
+ return false , host , defValue
125
+ }
126
+
127
+ func filterSimple (line , hashPath string ) (bool , string , string ) {
128
+ // XXX: some lists may use TABs as separator
129
+ hash := strings .SplitN (line , " " , 2 )
130
+ return false , hash [0 ], hash [1 ]
131
+ }
132
+
133
+ func (o * Operator ) readTupleList (raw , fileName string , filter func (line , defValue string ) (bool , string , string )) (dups uint64 ) {
134
+ log .Debug ("Loading list: %s, size: %d" , fileName , len (raw ))
109
135
lines := strings .Split (string (raw ), "\n " )
110
- for _ , domain := range lines {
111
- if len (domain ) < 9 {
112
- continue
113
- }
114
- // exclude not valid lines
115
- if domain [:7 ] != "0.0.0.0" && domain [:9 ] != "127.0.0.1" {
116
- continue
117
- }
118
- host := domain [8 :]
119
- // exclude localhost entries
120
- if domain [:9 ] == "127.0.0.1" {
121
- host = domain [10 :]
122
- }
123
- if host == "local" || host == "localhost" || host == "localhost.localdomain" || host == "broadcasthost" {
136
+ for _ , line := range lines {
137
+ skip , key , value := filter (line , fileName )
138
+ if skip || len (line ) < 9 {
124
139
continue
125
140
}
126
-
127
- host = core .Trim (host )
128
- if _ , found := o .lists [host ]; found {
141
+ key = core .Trim (key )
142
+ if _ , found := o .lists [key ]; found {
129
143
dups ++
130
144
continue
131
145
}
132
- o .lists [host ] = fileName
146
+ o .lists [key ] = value
133
147
}
134
148
lines = nil
135
149
log .Info ("%d domains loaded, %s" , len (o .lists ), fileName )
@@ -187,22 +201,25 @@ func (o *Operator) readRegexpList(raw, fileName string) (dups uint64) {
187
201
return dups
188
202
}
189
203
190
- func (o * Operator ) readIPList (raw , fileName string ) (dups uint64 ) {
191
- log .Debug ("Loading IPs list: %s, size: %d" , fileName , len (raw ))
204
+ // A simple list is a list composed of one column with several entries, that
205
+ // don't require manipulation.
206
+ // It can be a list of IPs, domains, etc.
207
+ func (o * Operator ) readSimpleList (raw , fileName string ) (dups uint64 ) {
208
+ log .Debug ("Loading simple list: %s, size: %d" , fileName , len (raw ))
192
209
lines := strings .Split (string (raw ), "\n " )
193
210
for _ , line := range lines {
194
211
if line == "" || line [0 ] == '#' {
195
212
continue
196
213
}
197
- ip := core .Trim (line )
198
- if _ , found := o .lists [ip ]; found {
214
+ what := core .Trim (line )
215
+ if _ , found := o .lists [what ]; found {
199
216
dups ++
200
217
continue
201
218
}
202
- o .lists [ip ] = fileName
219
+ o .lists [what ] = fileName
203
220
}
204
221
lines = nil
205
- log .Info ("%d IPs loaded, %s" , len (o .lists ), fileName )
222
+ log .Info ("%d entries loaded, %s" , len (o .lists ), fileName )
206
223
207
224
return dups
208
225
}
@@ -236,13 +253,15 @@ func (o *Operator) readLists() error {
236
253
}
237
254
238
255
if o .Operand == OpDomainsLists {
239
- dups += o .readDomainsList (string (raw ), fileName )
256
+ dups += o .readTupleList (string (raw ), fileName , filterDomains )
240
257
} else if o .Operand == OpDomainsRegexpLists {
241
258
dups += o .readRegexpList (string (raw ), fileName )
242
259
} else if o .Operand == OpNetLists {
243
260
dups += o .readNetList (string (raw ), fileName )
244
261
} else if o .Operand == OpIPLists {
245
- dups += o .readIPList (string (raw ), fileName )
262
+ dups += o .readSimpleList (string (raw ), fileName )
263
+ } else if o .Operand == OpHashMD5Lists {
264
+ dups += o .readSimpleList (string (raw ), fileName )
246
265
} else {
247
266
log .Warning ("Unknown lists operand type: %s" , o .Operand )
248
267
}
0 commit comments