mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 03:16:53 +00:00
Flow display and user login and rate limit bug
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/server"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"strconv"
|
||||
@@ -33,6 +34,14 @@ func (s *BaseController) Prepare() {
|
||||
s.Redirect("/login/index", 302)
|
||||
}
|
||||
}
|
||||
if s.GetSession("isAdmin") != nil && !s.GetSession("isAdmin").(bool) {
|
||||
s.Ctx.Input.SetData("client_id", s.GetSession("clientId").(int))
|
||||
s.Ctx.Input.SetParam("client_id", strconv.Itoa(s.GetSession("clientId").(int)))
|
||||
s.Data["isAdmin"] = false
|
||||
s.CheckUserAuth()
|
||||
} else {
|
||||
s.Data["isAdmin"] = true
|
||||
}
|
||||
}
|
||||
|
||||
//加载模板
|
||||
@@ -128,3 +137,30 @@ func (s *BaseController) SetInfo(name string) {
|
||||
func (s *BaseController) SetType(name string) {
|
||||
s.Data["type"] = name
|
||||
}
|
||||
|
||||
func (s *BaseController) CheckUserAuth() {
|
||||
if s.controllerName == "client" {
|
||||
s.StopRun()
|
||||
}
|
||||
if s.controllerName == "index" {
|
||||
if id := s.GetIntNoErr("id"); id != 0 {
|
||||
belong := false
|
||||
if strings.Contains(s.actionName, "H") {
|
||||
if v, ok := file.GetCsvDb().Hosts.Load(id); ok {
|
||||
if v.(*file.Host).Client.Id == s.GetSession("clientId").(int) {
|
||||
belong = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if v, ok := file.GetCsvDb().Tasks.Load(id); ok {
|
||||
if v.(*file.Tunnel).Client.Id == s.GetSession("clientId").(int) {
|
||||
belong = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !belong {
|
||||
s.StopRun()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -111,7 +111,8 @@ func (s *ClientController) Edit() {
|
||||
c.Rate = rate.NewRate(int64(c.RateLimit * 1024))
|
||||
c.Rate.Start()
|
||||
} else {
|
||||
c.Rate = nil
|
||||
c.Rate = rate.NewRate(int64(2 << 23))
|
||||
c.Rate.Start()
|
||||
}
|
||||
file.GetCsvDb().StoreClientsToCsv()
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/server"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"time"
|
||||
@@ -15,15 +16,32 @@ func (self *LoginController) Index() {
|
||||
self.TplName = "login/index.html"
|
||||
}
|
||||
func (self *LoginController) Verify() {
|
||||
var auth bool
|
||||
if self.GetString("password") == beego.AppConfig.String("web_password") && self.GetString("username") == beego.AppConfig.String("web_username") {
|
||||
self.SetSession("isAdmin", true)
|
||||
auth = true
|
||||
server.Bridge.Register.Store(common.GetIpByAddr(self.Ctx.Request.RemoteAddr), time.Now().Add(time.Hour*time.Duration(2)))
|
||||
}
|
||||
b, err := beego.AppConfig.Bool("allow_user_login")
|
||||
if err == nil && b && self.GetString("username") == "user" && !auth {
|
||||
file.GetCsvDb().Clients.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Client)
|
||||
if v.VerifyKey == self.GetString("password") && v.Status {
|
||||
self.SetSession("isAdmin", false)
|
||||
self.SetSession("clientId", v.Id)
|
||||
auth = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
if auth {
|
||||
self.SetSession("auth", true)
|
||||
self.Data["json"] = map[string]interface{}{"status": 1, "msg": "login success"}
|
||||
server.Bridge.Register.Store(common.GetIpByAddr(self.Ctx.Request.RemoteAddr), time.Now().Add(time.Hour*time.Duration(2)))
|
||||
self.ServeJSON()
|
||||
} else {
|
||||
self.Data["json"] = map[string]interface{}{"status": 0, "msg": "username or password incorrect"}
|
||||
self.ServeJSON()
|
||||
}
|
||||
self.ServeJSON()
|
||||
}
|
||||
func (self *LoginController) Out() {
|
||||
self.SetSession("auth", false)
|
||||
|
@@ -124,8 +124,7 @@
|
||||
+ '<b langtag="info-now-conn-num">当前连接数</b>:' + row.NowConn + `       `
|
||||
+ '<b langtag="info-flow-limit">流量限制</b>:' + row.Flow.FlowLimit + `m       `
|
||||
+ '<b langtag="info-rate-limit">带宽限制</b>:' + row.RateLimit + `kb/s       `
|
||||
+ '<b langtag="info-export-flow">出口流量</b>:' + change(row.Flow.ExportFlow) + `       `
|
||||
+ '<b langtag="info-inlet-flow">入口流量</b>:' + change(row.Flow.InletFlow) + `       ` + "<br/><br>"
|
||||
+ `       ` + "<br/><br>"
|
||||
+ '<b langtag="info-crypt">加密</b>:' + row.Cnf.Crypt + `       `
|
||||
+ '<b langtag="info-compress">压缩</b>:' + row.Cnf.Compress + `       `
|
||||
+ '<b langtag="info-config-conn-allow">是否允许配置文件模式连接</b>:' + row.ConfigConnAllow + `       `
|
||||
@@ -166,6 +165,33 @@
|
||||
visible: true,//false表示不显示
|
||||
sortable: true,//启用排序
|
||||
},
|
||||
{
|
||||
field: 'Addr',//域值
|
||||
title: 'in flow',//标题
|
||||
visible: true,//false表示不显示
|
||||
sortable: true,//启用排序
|
||||
formatter: function (value, row, index) {
|
||||
return change(row.Flow.InletFlow)
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'Addr',//域值
|
||||
title: 'out flow',//标题
|
||||
visible: true,//false表示不显示
|
||||
sortable: true,//启用排序
|
||||
formatter: function (value, row, index) {
|
||||
return change(row.Flow.ExportFlow)
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'IsConnect',//域值
|
||||
title: 'speed',//内容
|
||||
visible: true,//false表示不显示
|
||||
sortable: true,//启用排序
|
||||
formatter: function (value, row, index) {
|
||||
return change(row.Rate.NowRate) + "/S"
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'Status',//域值
|
||||
title: 'setting status',//内容
|
||||
|
@@ -43,16 +43,19 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="logo-element">
|
||||
IN+
|
||||
NPS
|
||||
</div>
|
||||
</li>
|
||||
{{if eq true .isAdmin}}
|
||||
<li class="{{if eq "index" .menu}}active{{end}}">
|
||||
<a href="/"><i class="fa fa-dashboard"></i> <span langtag="menu-dashboard" class="nav-label">仪表盘</span></a>
|
||||
<a href="/"><i class="fa fa-dashboard"></i> <span langtag="menu-dashboard"
|
||||
class="nav-label">仪表盘</span></a>
|
||||
</li>
|
||||
<li class="{{if eq "client" .menu}}active{{end}}">
|
||||
<a href="/client/list"><i class="fa fa-clipboard"></i> <span langtag="menu-client"
|
||||
class="nav-label">客户端</span></a>
|
||||
</li>
|
||||
{{end}}
|
||||
<li class="{{if eq "host" .menu}}active{{end}}">
|
||||
<a href="/index/hostlist"><i class="fa fa-paperclip"></i> <span langtag="menu-host"
|
||||
class="nav-label">域名解析</span></a>
|
||||
|
Reference in New Issue
Block a user