-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_readers.go
65 lines (57 loc) · 1.28 KB
/
db_readers.go
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
package main
import (
"database/sql"
"fmt"
"iter"
)
func getDbFieldData(qs string, db *sql.DB) iter.Seq[fieldData] {
return func(yield func(fieldData) bool) {
tx := check1(db.Begin())
rows := check1(tx.Query(qs))
for rows.Next() {
var fd fieldData
check(rows.Scan(&fd.name, &fd.id))
if !yield(fd) {
break
}
}
check(rows.Close())
check(tx.Commit())
}
}
// wrapper that prepends `_dmarc.` to the name while keeping the id the same
func getUnqueriedDMARC(db *sql.DB) iter.Seq[fieldData] {
return func(yield func(fieldData) bool) {
for fd := range getDbFieldData(`
SELECT DISTINCT name.name, name.id
FROM name
INNER JOIN name_mx ON name_mx.name_id=name.id
WHERE name.dmarc_tried=FALSE
`, db) {
fd.name = "_dmarc." + fd.name
if !yield(fd) {
return
}
}
}
}
func getUnqueriedChaosTXT(db *sql.DB) iter.Seq[fieldData] {
var v4Filter string
if !v6 {
v4Filter = `AND ip.address LIKE '%.%'`
}
filter := fmt.Sprintf(`
SELECT address, id
FROM ip
WHERE ch_resolved=FALSE %s
`, v4Filter)
return getDbFieldData(filter, db)
}
func netZoneReader(db *sql.DB, extraFilter string) iter.Seq[fieldData] {
qs := fmt.Sprintf(`
SELECT zone.name, zone.id
FROM name AS zone
WHERE zone.is_zone=TRUE %s
`, extraFilter)
return getDbFieldData(qs, db)
}