-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
114 lines (95 loc) · 2.58 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
"sync"
"time"
"github.com/neo4j/neo4j-go-driver/v4/neo4j"
log "github.com/sirupsen/logrus"
)
func main() {
// Number of concurrent neo4j query threads
var concurrency int
flag.IntVar(&concurrency, "c", 5, "number of threads")
// Verbose flag for error msgs
var verbose bool
flag.BoolVar(&verbose, "v", true, "output errors to stderr")
// Neo4j bolt URL
var neo4jUrl string
flag.StringVar(&neo4jUrl, "b", "bolt://localhost:7687", "neo4j endpoint (Default: bolt://localhost:7687)")
// Neo4j bolt Username
var neo4jUsername string
flag.StringVar(&neo4jUsername, "u", "neo4j", "neo4j username (Default: neo4j)")
// Neo4j bolt Password
var neo4jPassword string
flag.StringVar(&neo4jPassword, "p", "neo4j", "neo4j password (Default: neo4j)")
flag.Parse()
if verbose {
log.SetLevel(log.TraceLevel)
}
logins := make(chan string)
var wg sync.WaitGroup
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
driver, err := neo4j.NewDriver(neo4jUrl, neo4j.BasicAuth(neo4jUsername, neo4jPassword, ""))
if err != nil {
log.Debug(err)
log.Fatal(err)
return
}
defer driver.Close()
session := driver.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeWrite})
defer session.Close()
for u := range logins {
if err != nil {
return
}
split := strings.Split(u, ":")
userd := strings.ToUpper(split[0])
if !strings.Contains(userd, "\\") {
continue
}
domain := strings.Split(userd, "\\")[0]
user := strings.Split(userd, "\\")[1] + "@" + domain
pass := strings.Join(split[1:len(split)], "")
res, err := session.WriteTransaction(func(tx neo4j.Transaction) (interface{}, error) {
var list []string
stmt := "MATCH (H:User {name:$user}) SET H.password=$pass,H.owned=true RETURN H.name"
params := map[string]interface{}{"user": user, "pass": pass}
result, err := tx.Run(stmt, params)
if err != nil {
return nil, err
}
for result.Next() {
list = append(list, result.Record().Values[0].(string))
}
if err = result.Err(); err != nil {
return nil, err
}
return list, nil
}, neo4j.WithTxTimeout(3*time.Second))
if err != nil {
log.Debug(err)
}
log.Debug(res.([]string))
}
wg.Done()
return
}()
}
// accept logins on stdin
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
logins <- sc.Text()
}
close(logins)
if err := sc.Err(); err != nil {
fmt.Fprintf(os.Stderr, "failed to read input: %s\n", err)
}
// Wait until all the workers have finished
wg.Wait()
}