forked from mpdroog/radiusd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (81 loc) · 2.09 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
package main
import (
"flag"
S "sync"
"github.com/mpdroog/radiusd/config"
"github.com/mpdroog/radiusd/handlers"
"github.com/mpdroog/radiusd/radius"
"github.com/mpdroog/radiusd/storage"
"github.com/mpdroog/radiusd/sync"
)
var wg *S.WaitGroup
func listenAndServe(l config.Listener) {
defer wg.Done()
if config.Verbose {
config.Log.Printf("Listening on " + l.Addr)
}
conn, e := radius.Listen(l.Addr)
if e != nil {
panic(e)
}
config.Sock = append(config.Sock, conn)
if e := radius.Serve(conn, l.Secret, l.CIDR, config.Verbose, config.Log); e != nil {
if config.Stopping {
// Ignore close errors
return
}
panic(e)
}
}
func main() {
var configPath string
flag.BoolVar(&config.Debug, "d", false, "Debug packetdata")
flag.BoolVar(&config.Verbose, "v", false, "Show all that happens")
flag.StringVar(&configPath, "c", "./config.toml", "Configuration")
flag.Parse()
if e := config.Init(configPath); e != nil {
panic(e)
}
if config.Verbose {
config.Log.Printf("%+v", config.C)
}
if config.Debug {
config.Log.Printf("Auth RFC2865 https://tools.ietf.org/html/rfc2865")
config.Log.Printf("Acct RFC2866 https://tools.ietf.org/html/rfc2866")
}
/*
1 Start
2 Stop
3 Interim-Update
7 Accounting-On
8 Accounting-Off
9-14 Reserved for Tunnel Accounting
15 Reserved for Failed
*/
storage, e := storage.NewMySQL(config.C.Dsn)
if e != nil {
panic(e)
}
if e := storage.Strict(); e != nil {
panic(e)
}
h := &handlers.Handler{
Storage: storage,
Logger: config.Log,
Verbose: config.Verbose,
}
radius.HandleFunc(radius.AccessRequest, 0, h.Auth)
radius.HandleFunc(radius.AccountingRequest, 1, h.AcctBegin)
radius.HandleFunc(radius.AccountingRequest, 3, h.AcctUpdate)
radius.HandleFunc(radius.AccountingRequest, 2, h.AcctStop)
go Control()
go sync.Loop(storage, config.Hostname, config.Verbose, config.Log)
wg = new(S.WaitGroup)
for _, listen := range config.C.Listen {
wg.Add(1)
go listenAndServe(listen)
}
wg.Wait()
// Write all stats
sync.Force(storage, config.Hostname, config.Verbose, config.Log)
}