-
Notifications
You must be signed in to change notification settings - Fork 0
/
stuff.go
121 lines (103 loc) · 2.16 KB
/
stuff.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
115
116
117
118
119
120
121
package main
import (
"encoding/json"
"log"
"os"
"strings"
"github.com/Xe/uuid"
"golang.org/x/crypto/bcrypt"
)
type User struct {
Username string `json:"user"`
Password string `json:"password"`
Log bool `json:"log"`
Networks []*Network `json:"networks"`
}
type Network struct {
Name string `json:"name"`
Host string `json:"host"`
Port string `json:"port"`
TLS bool `json:"tls"`
Username string `json:"username"`
Realname string `json:"realname"`
Nick string `json:"nick"`
Join string `json:"join"`
}
func clear(b []byte) {
for i := 0; i < len(b); i++ {
b[i] = 0
}
}
func Crypt(password []byte) ([]byte, error) {
defer clear(password)
return bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
}
func MakeUser(name, password string) {
ctext, err := Crypt([]byte(password))
if err != nil {
panic(err)
}
u := &User{
Username: name,
Password: string(ctext),
Log: true,
Networks: []*Network{
&Network{
Name: "PonyChat",
Host: "irc.ponychat.net",
Port: "6697",
TLS: true,
Username: uuid.New()[:8],
Realname: name + " via the PonyChat BNC",
Nick: name,
Join: "#bnc,#geek,#ponychat",
},
},
}
jsonOut, err := json.MarshalIndent(u, "", " ")
if err != nil {
panic(err)
}
fname := os.Getenv("OUTPUT_PATH") + "/" + strings.ToLower(name) + ".json"
log.Printf("Writing for %s to %s", name, fname)
fout, err := os.Create(fname)
if err != nil {
panic(err)
}
defer fout.Close()
_, err = fout.Write(jsonOut)
if err != nil {
panic(err)
}
}
/*
func main() {
ctext, err := Crypt([]byte("foobar"))
if err != nil {
log.Fatal(err)
}
u := &User{
Username: "foo",
Password: string(ctext),
Log: true,
Networks: []*Network{
&Network{
Name: "PonyChat",
Host: "irc.ponychat.net",
Port: "6697",
TLS: true,
Username: "foo",
Realname: "foo via the PonyChat BNC",
Nick: "foo",
Join: "#bnc,#geek,#ponychat",
},
},
}
fmt.Println(string(ctext))
jsonOut, err := json.MarshalIndent(u, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(jsonOut))
}
*/