diff --git a/go.mod b/go.mod
index b0b6d5e..ed1f665 100644
--- a/go.mod
+++ b/go.mod
@@ -9,6 +9,7 @@ require (
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c
github.com/ccding/go-stun v0.0.0-20180726100737-be486d185f3d
+ github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f
github.com/dsnet/compress v0.0.1 // indirect
github.com/golang/snappy v0.0.3
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
diff --git a/go.sum b/go.sum
index 61be7ae..84616fe 100644
--- a/go.sum
+++ b/go.sum
@@ -31,6 +31,8 @@ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGii
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f h1:q/DpyjJjZs94bziQ7YkBmIlpqbVP7yw179rnzoNVX1M=
+github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f/go.mod h1:QGrK8vMWWHQYQ3QU9bw9Y9OPNfxccGzfb41qjvVeXtY=
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
diff --git a/server/server.go b/server/server.go
index 164b281..2c15b7a 100644
--- a/server/server.go
+++ b/server/server.go
@@ -172,6 +172,7 @@ func StopServer(id int) error {
return err
} else {
t.Status = false
+ logs.Info("close port %d,remark %s,client id %d,task id %d", t.Port, t.Remark, t.Client.Id, t.Id)
file.GetDb().UpdateTask(t)
}
//delete(RunList, id)
diff --git a/web/controllers/login.go b/web/controllers/login.go
index 770a2c0..2e849ad 100755
--- a/web/controllers/login.go
+++ b/web/controllers/login.go
@@ -1,6 +1,8 @@
package controllers
import (
+ "github.com/astaxie/beego/cache"
+ "github.com/astaxie/beego/utils/captcha"
"math/rand"
"net"
"sync"
@@ -17,12 +19,19 @@ type LoginController struct {
}
var ipRecord sync.Map
+var cpt *captcha.Captcha
type record struct {
hasLoginFailTimes int
lastLoginTime time.Time
}
+func init() {
+ // use beego cache system store the captcha data
+ store := cache.NewMemoryCache()
+ cpt = captcha.NewWithFilter("/captcha/", store)
+}
+
func (self *LoginController) Index() {
// Try login implicitly, will succeed if it's configured as no-auth(empty username&password).
webBaseUrl := beego.AppConfig.String("web_base_url")
@@ -31,12 +40,20 @@ func (self *LoginController) Index() {
}
self.Data["web_base_url"] = webBaseUrl
self.Data["register_allow"], _ = beego.AppConfig.Bool("allow_user_register")
+ self.Data["captcha_open"], _ = beego.AppConfig.Bool("open_captcha")
self.TplName = "login/index.html"
}
func (self *LoginController) Verify() {
username := self.GetString("username")
password := self.GetString("password")
+ captchaOpen, _ := beego.AppConfig.Bool("open_captcha")
+ if captchaOpen {
+ if !cpt.VerifyReq(self.Ctx.Request) {
+ self.Data["json"] = map[string]interface{}{"status": 0, "msg": "the verification code is wrong, please get it again and try again"}
+ self.ServeJSON()
+ }
+ }
if self.doLogin(username, password, true) {
self.Data["json"] = map[string]interface{}{"status": 1, "msg": "login success"}
} else {
diff --git a/web/static/page/languages.xml b/web/static/page/languages.xml
index 680bee2..52eef51 100644
--- a/web/static/page/languages.xml
+++ b/web/static/page/languages.xml
@@ -367,6 +367,10 @@
密码
Password
+
+ 验证码
+ Captcha
+
端口
Port
diff --git a/web/views/login/index.html b/web/views/login/index.html
index b2816ed..9e3eeb5 100644
--- a/web/views/login/index.html
+++ b/web/views/login/index.html
@@ -24,16 +24,18 @@
-