test
This commit is contained in:
parent
6a34c73071
commit
fb65a33047
@ -8,7 +8,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/fatedier/frp/extend/limit"
|
// "github.com/fatedier/frp/extend/limit"
|
||||||
"github.com/fatedier/frp/models/config"
|
"github.com/fatedier/frp/models/config"
|
||||||
"github.com/fatedier/frp/models/msg"
|
"github.com/fatedier/frp/models/msg"
|
||||||
)
|
)
|
||||||
@ -147,11 +147,12 @@ func (s Service) CheckProxy(user string, pMsg *msg.NewProxy, timestamp int64, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetProxyLimit 获取隧道限速信息
|
// 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
|
// 这部分就照之前的搬过去了,能跑就行x
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
values.Set("do", "getlimit")
|
values.Set("do", "getlimit")
|
||||||
values.Set("user", user)
|
values.Set("user", user)
|
||||||
|
values.Set("timestamp", fmt.Sprintf("%d", timestamp))
|
||||||
values.Set("frpstoken", stk)
|
values.Set("frpstoken", stk)
|
||||||
s.Host.RawQuery = values.Encode()
|
s.Host.RawQuery = values.Encode()
|
||||||
defer func(u *url.URL) {
|
defer func(u *url.URL) {
|
||||||
@ -159,27 +160,27 @@ func (s Service) GetProxyLimit(pxyConf *config.BaseProxyConf) (inLimit, outLimit
|
|||||||
}(&s.Host)
|
}(&s.Host)
|
||||||
resp, err := http.Get(s.Host.String())
|
resp, err := http.Get(s.Host.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
er := &ErrHTTPStatus{}
|
er := &ErrHTTPStatus{}
|
||||||
if err = json.Unmarshal(body, er); err != nil {
|
if err = json.Unmarshal(body, er); err != nil {
|
||||||
return nil, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
if er.Status != 200 {
|
if er.Status != 200 {
|
||||||
return nil, er
|
return 0, 0, er
|
||||||
}
|
}
|
||||||
|
|
||||||
r = &ResponseGetLimit{}
|
response := &ResponseGetLimit{}
|
||||||
if err = json.Unmarshal(body, r); err != nil {
|
if err = json.Unmarshal(body, response); err != nil {
|
||||||
return nil, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return r.MaxIn, r.MaxOut, nil
|
return response.MaxIn, response.MaxOut, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func BoolToString(val bool) (str string) {
|
func BoolToString(val bool) (str string) {
|
||||||
|
@ -78,10 +78,9 @@ type ServerCommonConf struct {
|
|||||||
UserConnTimeout int64 `json:"user_conn_timeout"`
|
UserConnTimeout int64 `json:"user_conn_timeout"`
|
||||||
|
|
||||||
// API
|
// API
|
||||||
EnableApi bool `json:"api_enable"`
|
EnableApi bool `json:"api_enable"`
|
||||||
ApiBaseUrl string `json:"api_baseurl"`
|
ApiBaseUrl string `json:"api_baseurl"`
|
||||||
ApiToken string `json:"api_token"`
|
ApiToken string `json:"api_token"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultServerConf() *ServerCommonConf {
|
func GetDefaultServerConf() *ServerCommonConf {
|
||||||
|
@ -447,7 +447,7 @@ func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err
|
|||||||
return remoteAddr, fmt.Errorf("invalid proxy configuration")
|
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 {
|
if err != nil {
|
||||||
return remoteAddr, err
|
return remoteAddr, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user