-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathmain.go
More file actions
162 lines (127 loc) · 3.53 KB
/
main.go
File metadata and controls
162 lines (127 loc) · 3.53 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
r "github.com/cuu/softradius/routers"
. "github.com/cuu/softradius/controllers"
// "github.com/cuu/softradius/libs"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
"fmt"
"flag"
"errors"
"runtime"
"time"
"math/rand"
// "os"
re "gopkg.in/gorethink/gorethink.v3"
rdb "github.com/cuu/softradius/database/shelf"
rad "github.com/cuu/softradius/radius"
)
/*
func page_not_found(rw http.ResponseWriter, r *http.Request){
t,_:= template.New("404.html").ParseFiles(beego.ViewsPath+"/404.html")
data :=make(map[string]interface{})
data["content"] = "page not found"
t.Execute(rw, data)
}
*/
func init_database() {
err := rdb.Register(re.ConnectOpts{
Address: "localhost:28015",
}, "SoftRadius")
if err != nil {
panic("Db connect failed...")
}
}
func GuuRecoverPanic(ctx *context.Context) {
ErrAbort := errors.New("User stop run")
if err := recover(); err != nil {
if err == ErrAbort {
return
}
var stack string
logs.Critical("the request url is ", ctx.Input.URL())
logs.Critical("Handler crashed with error", err)
stack += fmt.Sprintln("the request url is ", ctx.Input.URL() )
stack += fmt.Sprintln("Handler crashed with error: ", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
logs.Critical(fmt.Sprintf("%s:%d", file, line))
stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d", file, line))
}
if ctx.Output.Status != 0 {
ctx.ResponseWriter.WriteHeader(ctx.Output.Status)
} else {
ctx.ResponseWriter.WriteHeader(500)
}
stack += "SoftRadius "
ctx.WriteString(stack)
}
}
func before_run_beego() {
//after all init() called
var menus = []string{ r.MenuSys,r.MenuBus,r.MenuOpt,r.MenuPlugin,r.MenuAgency, }
r.Permits.Build_menus( menus )
//还要 bind_super ,super是从 数据库得到 operator_type == 0 的用户们
init_database()
opera := &Operators{}
err := rdb.DataBase().FilterOne(opera,map[string]int{"Type":SUPEROPERA})
if err == nil {
r.Permits.Bind_super(opera.Name)
}else{
panic("no super admin ")
}
beego.ErrorController(&ErrorController{})
}
func run_beego(){
beego.BConfig.WebConfig.DirectoryIndex = true
/*
beego.BConfig.Listen.AdminEnable = true
beego.BConfig.Listen.AdminAddr = "localhost"
beego.BConfig.Listen.AdminPort = 8088
*/
beego.BConfig.WebConfig.Session.SessionOn = true
beego.BConfig.WebConfig.Session.SessionName = "guugosessionID"
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600
beego.BConfig.RecoverFunc = GuuRecoverPanic
beego.SetStaticPath("/AdminLTE", "static/AdminLTE")
// fmt.Println(beego.AppConfig.DefaultString("DEFAULT::Secret","NULL"))
//beego.ErrorHandler("404", page_not_found)
before_run_beego()
beego.Run()
}
func print_help() {
fmt.Println("Useage:")
fmt.Println("softradius -admin")
fmt.Println("softradius -radius")
fmt.Println("softradius -radacct")
}
func main() {
admin := flag.Bool("admin",false,"Run admin interface")
radius := flag.Bool("radius",false, "Run radius server")
radacct := flag.Bool("radacct",false,"Run radius acct server")
help := flag.Bool("help",false,"Print Help")
rand.Seed(time.Now().UTC().UnixNano())
flag.Parse()
if *help == true {
print_help()
return
}
if *admin == true {
fmt.Println("run beego")
run_beego()
}else {
if *radius == true {
// fmt.Println("Run radius server....")
init_database()
rad.BeAuthServer("testing123")
}else if *radacct == true {
init_database()
rad.BeAcctServer("testing123")
}
}
print_help()
}