This commit is contained in:
kasuganosoras 2019-09-08 20:49:26 +08:00
parent 6a34c73071
commit fb65a33047
4 changed files with 30 additions and 30 deletions

View File

@ -8,7 +8,7 @@ import (
"net/url"
"strconv"
"github.com/fatedier/frp/extend/limit"
// "github.com/fatedier/frp/extend/limit"
"github.com/fatedier/frp/models/config"
"github.com/fatedier/frp/models/msg"
)
@ -147,11 +147,12 @@ func (s Service) CheckProxy(user string, pMsg *msg.NewProxy, timestamp int64, st
}
// GetProxyLimit 获取隧道限速信息
func (s Service) GetProxyLimit(pxyConf *config.BaseProxyConf) (inLimit, outLimit uint64, err error) {
func (s Service) GetProxyLimit(user string, pxyConf *config.BaseProxyConf, timestamp int64, stk string) (inLimit, outLimit uint64, err error) {
// 这部分就照之前的搬过去了能跑就行x
values := url.Values{}
values.Set("do", "getlimit")
values.Set("user", user)
values.Set("timestamp", fmt.Sprintf("%d", timestamp))
values.Set("frpstoken", stk)
s.Host.RawQuery = values.Encode()
defer func(u *url.URL) {
@ -159,27 +160,27 @@ func (s Service) GetProxyLimit(pxyConf *config.BaseProxyConf) (inLimit, outLimit
}(&s.Host)
resp, err := http.Get(s.Host.String())
if err != nil {
return nil, err
return 0, 0, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
return 0, 0, err
}
er := &ErrHTTPStatus{}
if err = json.Unmarshal(body, er); err != nil {
return nil, err
return 0, 0, err
}
if er.Status != 200 {
return nil, er
return 0, 0, er
}
r = &ResponseGetLimit{}
if err = json.Unmarshal(body, r); err != nil {
return nil, err
response := &ResponseGetLimit{}
if err = json.Unmarshal(body, response); err != nil {
return 0, 0, err
}
return r.MaxIn, r.MaxOut, nil
return response.MaxIn, response.MaxOut, nil
}
func BoolToString(val bool) (str string) {

View File

@ -81,7 +81,6 @@ type ServerCommonConf struct {
EnableApi bool `json:"api_enable"`
ApiBaseUrl string `json:"api_baseurl"`
ApiToken string `json:"api_token"`
}
func GetDefaultServerConf() *ServerCommonConf {

View File

@ -447,7 +447,7 @@ func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err
return remoteAddr, fmt.Errorf("invalid proxy configuration")
}
in, out, err := s.GetProxyLimit(pxyConf.GetBaseInfo())
in, out, err := s.GetProxyLimit(ctl.loginMsg.User, pxyConf.GetBaseInfo(), nowTime, g.GlbServerCfg.ApiToken)
if err != nil {
return remoteAddr, err
}