Make work with http proxy

This commit is contained in:
ravenclaw900 2022-04-15 17:11:56 -05:00
parent bf0542bf18
commit 952584e064
No known key found for this signature in database
GPG Key ID: BB7D044236B5E82C
5 changed files with 14 additions and 1 deletions

View File

@ -754,6 +754,7 @@ func (cfg *HTTPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
cfg.HostHeaderRewrite = pMsg.HostHeaderRewrite cfg.HostHeaderRewrite = pMsg.HostHeaderRewrite
cfg.HTTPUser = pMsg.HTTPUser cfg.HTTPUser = pMsg.HTTPUser
cfg.HTTPPwd = pMsg.HTTPPwd cfg.HTTPPwd = pMsg.HTTPPwd
cfg.HashedPwd = pMsg.HashedPwd
cfg.Headers = pMsg.Headers cfg.Headers = pMsg.Headers
} }
@ -767,6 +768,7 @@ func (cfg *HTTPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
pMsg.HostHeaderRewrite = cfg.HostHeaderRewrite pMsg.HostHeaderRewrite = cfg.HostHeaderRewrite
pMsg.HTTPUser = cfg.HTTPUser pMsg.HTTPUser = cfg.HTTPUser
pMsg.HTTPPwd = cfg.HTTPPwd pMsg.HTTPPwd = cfg.HTTPPwd
pMsg.HashedPwd = cfg.HashedPwd
pMsg.Headers = cfg.Headers pMsg.Headers = cfg.Headers
} }

View File

@ -102,6 +102,7 @@ type NewProxy struct {
Locations []string `json:"locations"` Locations []string `json:"locations"`
HTTPUser string `json:"http_user"` HTTPUser string `json:"http_user"`
HTTPPwd string `json:"http_pwd"` HTTPPwd string `json:"http_pwd"`
HashedPwd bool `json:"hashed_pwd"`
HostHeaderRewrite string `json:"host_header_rewrite"` HostHeaderRewrite string `json:"host_header_rewrite"`
Headers map[string]string `json:"headers"` Headers map[string]string `json:"headers"`

View File

@ -28,6 +28,7 @@ import (
frpLog "github.com/fatedier/frp/pkg/util/log" frpLog "github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/util"
"golang.org/x/crypto/bcrypt"
"github.com/fatedier/golib/pool" "github.com/fatedier/golib/pool"
) )
@ -154,7 +155,14 @@ func (rp *HTTPReverseProxy) CheckAuth(domain, location, user, passwd string) boo
if ok { if ok {
checkUser := vr.payload.(*RouteConfig).Username checkUser := vr.payload.(*RouteConfig).Username
checkPasswd := vr.payload.(*RouteConfig).Password checkPasswd := vr.payload.(*RouteConfig).Password
if (checkUser != "" || checkPasswd != "") && (checkUser != user || checkPasswd != passwd) { hashed := vr.payload.(*RouteConfig).Hashed
var correctPwd bool
if hashed {
correctPwd = bcrypt.CompareHashAndPassword([]byte(checkPasswd), []byte(passwd)) == nil
} else {
correctPwd = checkPasswd == passwd
}
if (checkUser != "" || checkPasswd != "") && (checkUser != user || !correctPwd) {
return false return false
} }
} }

View File

@ -75,6 +75,7 @@ type RouteConfig struct {
Headers map[string]string Headers map[string]string
CreateConnFn CreateConnFunc CreateConnFn CreateConnFunc
Hashed bool
} }
// listen for a new domain name, if rewriteHost is not empty and rewriteFunc is not nil // listen for a new domain name, if rewriteHost is not empty and rewriteFunc is not nil

View File

@ -43,6 +43,7 @@ func (pxy *HTTPProxy) Run() (remoteAddr string, err error) {
Username: pxy.cfg.HTTPUser, Username: pxy.cfg.HTTPUser,
Password: pxy.cfg.HTTPPwd, Password: pxy.cfg.HTTPPwd,
CreateConnFn: pxy.GetRealConn, CreateConnFn: pxy.GetRealConn,
Hashed: pxy.cfg.HashedPwd,
} }
locations := pxy.cfg.Locations locations := pxy.cfg.Locations