This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (66 loc) · 1.66 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
package main
import (
"database/sql"
"henrymail/config"
"henrymail/database"
"henrymail/dkim"
"henrymail/dns"
"henrymail/imap"
"henrymail/logic"
"henrymail/process"
"henrymail/smtp"
"henrymail/web"
"log"
"math/rand"
)
//go:generate mkdir -p embedded
//go:generate embed
func main() {
config.SetupConfig()
config.SetupResolver()
tlsConfig := config.GetTLSConfig()
db := database.OpenDatabase()
// submission agent processing chain
var msaChain process.MsgProcessor = process.NewSender(db)
if config.GetBool(config.DkimSign) {
msaChain = process.NewDkimSigner(dkim.GetOrCreateDkim(db), msaChain)
}
// transfer agent processing chain
mtaChain := process.NewSaver(db)
if config.GetBool(config.DkimVerify) {
mtaChain = process.NewDkimVerifier(mtaChain)
}
// SPF checker
// Virus scanner
// Spam filter
seedData(db)
smtp.StartMsa(db, msaChain, tlsConfig)
smtp.StartMta(db, mtaChain, tlsConfig)
imap.StartImap(db, tlsConfig)
web.StartWebAdmin(db, tlsConfig)
if config.GetBool(config.FakeDns) {
dns.StartFakeDNS(db, config.GetString(config.FakeDnsAddress), "udp")
}
// Wait for exit
select {}
}
func seedData(db *sql.DB) {
var pw string
if config.GetString(config.AdminPassword) == "" {
pw = randSeq(8)
} else {
pw = config.GetString(config.AdminPassword)
}
user, err := logic.NewUser(db, config.GetString(config.AdminUsername), pw, true)
if err == nil {
log.Printf("Generated admin user: %v password %v", user.Username, pw)
}
}
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func randSeq(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}