Skip to content

Commit

Permalink
add bridge status for api
Browse files Browse the repository at this point in the history
  • Loading branch information
ffdfgdfg committed Apr 2, 2020
1 parent b73491c commit 494d59c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
15 changes: 11 additions & 4 deletions web/controllers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (s *BaseController) Prepare() {
timestamp := s.GetIntNoErr("timestamp")
configKey := beego.AppConfig.String("auth_key")
timeNowUnix := time.Now().Unix()
if !(md5Key!="" && (math.Abs(float64(timeNowUnix-int64(timestamp))) <= 20) && (crypt.Md5(configKey+strconv.Itoa(timestamp)) == md5Key)) {
if !(md5Key != "" && (math.Abs(float64(timeNowUnix-int64(timestamp))) <= 20) && (crypt.Md5(configKey+strconv.Itoa(timestamp)) == md5Key)) {
if s.GetSession("auth") != true {
s.Redirect(beego.AppConfig.String("web_base_url")+"/login/index", 302)
}
}else {
s.SetSession("isAdmin",true)
} else {
s.SetSession("isAdmin", true)
s.Data["isAdmin"] = true
}
if s.GetSession("isAdmin") != nil && !s.GetSession("isAdmin").(bool) {
Expand Down Expand Up @@ -141,10 +141,17 @@ func ajax(str string, status int) map[string]interface{} {
}

//ajax table返回
func (s *BaseController) AjaxTable(list interface{}, cnt int, recordsTotal int) {
func (s *BaseController) AjaxTable(list interface{}, cnt int, recordsTotal int, kwargs map[string]interface{}) {
json := make(map[string]interface{})
json["rows"] = list
json["total"] = recordsTotal
if kwargs != nil {
for k, v := range kwargs {
if v != nil {
json[k] = v
}
}
}
s.Data["json"] = json
s.ServeJSON()
s.StopRun()
Expand Down
7 changes: 6 additions & 1 deletion web/controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ func (s *ClientController) List() {
clientId = clientIdSession.(int)
}
list, cnt := server.GetClientList(start, length, s.getEscapeString("search"), s.getEscapeString("sort"), s.getEscapeString("order"), clientId)
s.AjaxTable(list, cnt, cnt)
cmd := make(map[string]interface{})
ip := s.Ctx.Request.Host
cmd["ip"] = common.GetIpByAddr(ip)
cmd["bridgeType"] = beego.AppConfig.String("bridge_type")
cmd["bridgePort"] = server.Bridge.TunnelPort
s.AjaxTable(list, cnt, cnt, cmd)
}

//添加客户端
Expand Down
4 changes: 2 additions & 2 deletions web/controllers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *IndexController) GetTunnel() {
taskType := s.getEscapeString("type")
clientId := s.GetIntNoErr("client_id")
list, cnt := server.GetTunnel(start, length, taskType, clientId, s.getEscapeString("search"))
s.AjaxTable(list, cnt, cnt)
s.AjaxTable(list, cnt, cnt, nil)
}

func (s *IndexController) Add() {
Expand Down Expand Up @@ -215,7 +215,7 @@ func (s *IndexController) HostList() {
start, length := s.GetAjaxParams()
clientId := s.GetIntNoErr("client_id")
list, cnt := file.GetDb().GetHost(start, length, clientId, s.getEscapeString("search"))
s.AjaxTable(list, cnt, cnt)
s.AjaxTable(list, cnt, cnt, nil)
}
}

Expand Down

1 comment on commit 494d59c

@ffdfgdfg
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.