-
Notifications
You must be signed in to change notification settings - Fork 84
/
server.go
98 lines (83 loc) · 2.52 KB
/
server.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
package main
import (
"log"
"net/http"
"runtime"
"github.com/go-macaron/cache"
"github.com/go-macaron/captcha"
"github.com/go-macaron/csrf"
"github.com/go-macaron/session"
"gopkg.in/macaron.v1"
"github.com/xsec-lab/x-waf-admin/routers"
"github.com/xsec-lab/x-waf-admin/setting"
"fmt"
"strings"
)
const APP_VER = "0.1"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
setting.AppVer = APP_VER
}
func main() {
m := macaron.Classic()
m.Use(macaron.Renderer())
m.Use(session.Sessioner())
m.Use(csrf.Csrfer())
m.Use(cache.Cacher())
m.Use(captcha.Captchaer(captcha.Options{
URLPrefix: "/captcha/",
FieldIdName: "captcha_id",
FieldCaptchaName: "captcha",
ChallengeNums: 6,
Width: 220,
Height: 50,
Expiration: 600,
CachePrefix: "captcha_",
}))
m.Get("/", routers.Index)
m.Get("/login/", routers.LoginIndex)
m.Post("/login/", csrf.Validate, routers.Auth)
m.Group("/admin", func() {
m.Get("/index/", routers.Admin)
m.Group("/site/", func() {
m.Get("", routers.Admin)
m.Get("/list/", routers.Admin)
m.Get("/new/", routers.NewSite)
m.Post("/new/", csrf.Validate, routers.DoNewSite)
m.Get("/edit/:id", routers.EditSite)
m.Post("/edit/:id", csrf.Validate, routers.DoEditSite)
m.Get("/del/:id", routers.DelSite)
m.Get("/sync/", routers.SyncSite)
m.Get("/sync/:id", routers.SyncSiteById)
m.Get("/json/", routers.SiteJSON)
})
m.Group("/rule/", func() {
m.Get("", routers.ListRules)
m.Get("/list/", routers.ListRules)
m.Get("/new/:type", routers.NewRule)
m.Post("/new/:type", csrf.Validate, routers.DoNewRule)
m.Get("/edit/:id", routers.EditRule)
m.Post("/edit/:id", csrf.Validate, routers.DoEditRule)
m.Get("/del/:id", routers.DelRule)
m.Get("/sync/", routers.SyncRule)
})
m.Group("/user/", func() {
m.Get("", routers.ListUser)
m.Get("/list/", routers.ListUser)
m.Get("/new/", routers.NewUser)
m.Post("/new/", csrf.Validate, routers.DoNewUser)
m.Get("/edit/:id", routers.EditUser)
m.Post("edit/:id", csrf.Validate, routers.DoEditUser)
m.Get("/del/:id", routers.DelUser)
m.Get("/json/", routers.UserJSON)
})
})
m.Group("/api", func() {
m.Get("/site/sync/", routers.SyncSiteApi)
m.Get("/rule/sync/", routers.SyncRuleApi)
})
log.Printf("xsec waf admin %s", setting.AppVer)
log.Printf("Run mode %s", strings.Title(macaron.Env))
log.Printf("Server is running on %s", fmt.Sprintf("0.0.0.0:%v", setting.HTTPPort))
log.Println(http.ListenAndServe(fmt.Sprintf("0.0.0.0:%v", setting.HTTPPort), m))
}