Skip to content

Commit

Permalink
new feature multi user auth with socks5
Browse files Browse the repository at this point in the history
  • Loading branch information
arugal committed Sep 12, 2019
1 parent a05995f commit 11d185a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ loop:
tl.Password = t.Password
tl.LocalPath = t.LocalPath
tl.StripPre = t.StripPre
tl.MultiUser = t.MultiUser
tl.MultiAccount = t.MultiAccount
if !client.HasTunnel(tl) {
if err := file.GetDb().NewTask(tl); err != nil {
logs.Notice("Add task error ", err.Error())
Expand Down
6 changes: 3 additions & 3 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ func dealTunnel(s string) *file.Tunnel {
t.LocalPath = item[1]
case "strip_pre":
t.StripPre = item[1]
case "multi_user":
t.MultiUser = new(file.MultiUser)
case "multi_account":
t.MultiAccount = &file.MultiAccount{}
if b, err := common.ReadAllFromFile(item[1]); err != nil {
panic(err)
} else {
if content, err := common.ParseStr(string(b)); err != nil {
panic(err)
} else {
t.MultiUser.UserMap = dealMultiUser(content)
t.MultiAccount.AccountMap = dealMultiUser(content)
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions lib/file/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,23 @@ func (s *Client) HasHost(h *Host) bool {
}

type Tunnel struct {
Id int
Port int
ServerIp string
Mode string
Status bool
RunStatus bool
Client *Client
Ports string
Flow *Flow
Password string
Remark string
TargetAddr string
NoStore bool
LocalPath string
StripPre string
Target *Target
MultiUser *MultiUser
Id int
Port int
ServerIp string
Mode string
Status bool
RunStatus bool
Client *Client
Ports string
Flow *Flow
Password string
Remark string
TargetAddr string
NoStore bool
LocalPath string
StripPre string
Target *Target
MultiAccount *MultiAccount
Health
sync.RWMutex
}
Expand Down Expand Up @@ -185,8 +185,8 @@ type Target struct {
sync.RWMutex
}

type MultiUser struct {
UserMap map[string]string // multi user and pwd
type MultiAccount struct {
AccountMap map[string]string // multi account and pwd
}

func (s *Target) GetRandomTarget() (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions server/proxy/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *Sock5ModeServer) handleConn(c net.Conn) {
c.Close()
return
}
if (s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "") || (s.task.MultiUser != nil && len(s.task.MultiUser.UserMap) > 0) {
if (s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "") || (s.task.MultiAccount != nil && len(s.task.MultiAccount.AccountMap) > 0) {
buf[1] = UserPassAuth
c.Write(buf)
if err := s.Auth(c); err != nil {
Expand Down Expand Up @@ -238,11 +238,11 @@ func (s *Sock5ModeServer) Auth(c net.Conn) error {
}

var U, P string
if s.task.MultiUser != nil {
if s.task.MultiAccount != nil {
// enable multi user auth
U = string(user)
var ok bool
P, ok = s.task.MultiUser.UserMap[U]
P, ok = s.task.MultiAccount.AccountMap[U]
if !ok {
return errors.New("验证不通过")
}
Expand Down

0 comments on commit 11d185a

Please sign in to comment.