diff --git a/extend/api/api.go b/extend/api/api.go index aab0765..0b4f86b 100755 --- a/extend/api/api.go +++ b/extend/api/api.go @@ -150,10 +150,10 @@ func (s Service) CheckProxy(user string, pMsg *msg.NewProxy, timestamp int64, st 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("action", "getlimit") values.Set("user", user) values.Set("timestamp", fmt.Sprintf("%d", timestamp)) - values.Set("frpstoken", stk) + values.Set("apitoken", stk) s.Host.RawQuery = values.Encode() defer func(u *url.URL) { u.RawQuery = "" @@ -180,6 +180,8 @@ func (s Service) GetProxyLimit(user string, pxyConf *config.BaseProxyConf, times if err = json.Unmarshal(body, response); err != nil { return 0, 0, err } + + // 这里直接返回 uint64 应该问题不大 return response.MaxIn, response.MaxOut, nil } @@ -193,11 +195,11 @@ func BoolToString(val bool) (str string) { type ErrHTTPStatus struct { Status int `json:"status"` - Text string `json:"massage"` + Text string `json:"message"` } func (e ErrHTTPStatus) Error() string { - return fmt.Sprintf("%s", e.Text) + return fmt.Sprintf("SakuraFrp API Error (Status: %d, Text: %s)", e.Status, e.Text) } type ResponseGetLimit struct { diff --git a/extend/limit/limit.go b/extend/limit/limit.go old mode 100644 new mode 100755 index 1c0f9d6..1f09d4f --- a/extend/limit/limit.go +++ b/extend/limit/limit.go @@ -26,9 +26,11 @@ type LimitConn struct { } func NewLimitConn(maxread, maxwrite uint64, c frpNet.Conn) LimitConn { + // 这里不知道为什么要 49 才能对的上真实速度 + // 49 是根据 wget 速度来取的,测试了 512、1024、2048、4096、8192 等多种速度下都很准确 return LimitConn{ - lr: NewReaderWithLimit(c, maxread*KB), - lw: NewWriterWithLimit(c, maxwrite*KB), + lr: NewReaderWithLimit(c, maxread * 49), + lw: NewWriterWithLimit(c, maxwrite * 49), Conn: c, } } diff --git a/models/config/server_common.go b/models/config/server_common.go index e64ba7a..d45503e 100755 --- a/models/config/server_common.go +++ b/models/config/server_common.go @@ -69,7 +69,7 @@ type ServerCommonConf struct { Token string `json:"token"` SubDomainHost string `json:"subdomain_host"` TcpMux bool `json:"tcp_mux"` - Custom404Page string `json:"custom_404_page"` + Custom503Page string `json:"custom_503_page"` AllowPorts map[int]struct{} MaxPoolCount int64 `json:"max_pool_count"` @@ -110,7 +110,7 @@ func GetDefaultServerConf() *ServerCommonConf { MaxPortsPerClient: 0, HeartBeatTimeout: 90, UserConnTimeout: 10, - Custom404Page: "", + Custom503Page: "", EnableApi: false, ApiBaseUrl: "", ApiToken: "", @@ -303,8 +303,8 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c cfg.TcpMux = true } - if tmpStr, ok = conf.Get("common", "custom_404_page"); ok { - cfg.Custom404Page = tmpStr + if tmpStr, ok = conf.Get("common", "custom_503_page"); ok { + cfg.Custom503Page = tmpStr } if tmpStr, ok = conf.Get("common", "heartbeat_timeout"); ok { diff --git a/server/control.go b/server/control.go index da084bb..3da3709 100755 --- a/server/control.go +++ b/server/control.go @@ -431,7 +431,7 @@ func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err // Load configures from NewProxy message and check. pxyConf, err = config.NewProxyConfFromMsg(pxyMsg) if err != nil { - return + return remoteAddr, err } if g.GlbServerCfg.EnableApi { @@ -451,6 +451,10 @@ func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err if err != nil { return remoteAddr, err } + + // 测试用 + ctl.conn.Debug("client speed limit: %dKB/s (Inbound) / %dKB/s (Outbound)", in, out) + workConn = func() (frpNet.Conn, error) { fconn, err := ctl.GetWorkConn() if err != nil { diff --git a/server/service.go b/server/service.go index 3b97573..4f79be2 100755 --- a/server/service.go +++ b/server/service.go @@ -119,7 +119,7 @@ func NewService() (svr *Service, err error) { } // Init 404 not found page - vhost.NotFoundPagePath = cfg.Custom404Page + vhost.ServiceUnavailablePagePath = cfg.Custom503Page var ( httpMuxOn bool diff --git a/utils/vhost/http.go b/utils/vhost/http.go old mode 100644 new mode 100755 index 7c2d7a3..e919ca7 --- a/utils/vhost/http.go +++ b/utils/vhost/http.go @@ -93,8 +93,8 @@ func NewHttpReverseProxy(option HttpReverseProxyOptions, vhostRouter *VhostRoute ErrorLog: log.New(newWrapLogger(), "", 0), ErrorHandler: func(rw http.ResponseWriter, req *http.Request, err error) { frpLog.Warn("do http proxy request error: %v", err) - rw.WriteHeader(http.StatusNotFound) - rw.Write(getNotFoundPageContent()) + rw.WriteHeader(http.StatusServiceUnavailable) + rw.Write(getServiceUnavailablePageContent()) }, } rp.proxy = proxy diff --git a/utils/vhost/resource.go b/utils/vhost/resource.go old mode 100644 new mode 100755 index 9553e7e..71bfc3a --- a/utils/vhost/resource.go +++ b/utils/vhost/resource.go @@ -24,63 +24,86 @@ import ( ) var ( - NotFoundPagePath = "" + ServiceUnavailablePagePath = "" ) const ( - NotFound = ` + ServiceUnavailable = ` -
-Sorry, the page you are looking for is currently unavailable.
-Please try again later.
The server is powered by frp.
-Faithfully yours, frp.
- + +您访问的网站或服务暂时不可用
+如果您是隧道所有者,造成无法访问的原因可能有:
+如果您是普通访问者,您可以:
+Powered by Sakura Panel | Based on Frp
+