/
patreon.go
75 lines (67 loc) · 1.7 KB
/
patreon.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
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"strconv"
"strings"
"github.com/zxsecurity/steamer/importers/util"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type TemplateLineParser struct{}
func (t TemplateLineParser) ParseLine(line string) ([]interface{}, error) {
entries := make([]interface{}, 0)
// Parse the SQL line
users, err := util.ParseSQL(line, "tblUsers")
if err != nil {
return entries, nil
}
// Loop through each users
for _, row := range users {
// split on comma, use single quote
data := util.SplitString(row, ',', true, true)
// declare nil entry
entry := interface{}(nil)
// check data here
if len(data) < 23 {
entries = append(entries, entry)
continue
}
// validate/convert relevant data
memberid, err := strconv.Atoi(data[0])
if err != nil || !strings.Contains(data[1], "@") {
// append nil entry if condition fails
entries = append(entries, entry)
continue
}
// create our struct here
entry = util.GenericData{
Id: primitive.NewObjectID(),
MemberID: memberid,
Email: data[1],
Liame: util.Reverse(data[1]),
PasswordHash: data[4],
Username: data[13],
Breach: "Patreon2015",
}
entries = append(entries, entry)
}
return entries, nil
}
// EstimateCount estimates how many entries are in a line (for the progress bar)
func (t TemplateLineParser) EstimateCount(line string) (int, error) {
count := 0
users, err := util.ParseSQL(line, "tblUsers")
if err == nil {
count += len(users)
}
return count, nil
}
func main() {
parser := TemplateLineParser{}
importer, err := util.MakeImporter("/dumps/patreon.sql", parser, 15)
if err != nil {
fmt.Println(err)
return
}
importer.Run()
importer.Finish()
}