fix: make(socks5.StaticCredentials)
This commit is contained in:
parent
ba68c42b6f
commit
07b5f76b66
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/armon/go-socks5"
|
||||
)
|
||||
|
||||
type Credentials struct {
|
||||
@ -9,11 +11,23 @@ type Credentials struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func parseCredentials(credsString string) ([]Credentials, error) {
|
||||
var creds []Credentials
|
||||
err := json.Unmarshal([]byte(credsString), &creds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func getCredentials(params params) (socks5.StaticCredentials, error) {
|
||||
var creds socks5.StaticCredentials = make(socks5.StaticCredentials)
|
||||
|
||||
if params.Creds != "" {
|
||||
var parsed_env_creds []Credentials
|
||||
err := json.Unmarshal([]byte(params.Creds), &parsed_env_creds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, kv := range parsed_env_creds {
|
||||
creds[kv.Username] = kv.Password
|
||||
}
|
||||
}
|
||||
|
||||
if params.User+params.Password != "" {
|
||||
creds[params.User] = params.Password
|
||||
}
|
||||
|
||||
return creds, nil
|
||||
|
14
server.go
14
server.go
@ -34,20 +34,8 @@ func main() {
|
||||
log.Printf(cfg.Creds)
|
||||
|
||||
var creds socks5.StaticCredentials
|
||||
if cfg.Creds != "" {
|
||||
var uname_pw_pairs, creds_err = parseCredentials(cfg.Creds)
|
||||
creds, err = getCredentials(cfg)
|
||||
|
||||
if creds_err != nil {
|
||||
log.Printf("%+v\n", err)
|
||||
}
|
||||
|
||||
for _, kv := range uname_pw_pairs {
|
||||
creds[kv.Username] = kv.Password
|
||||
}
|
||||
}
|
||||
if cfg.User+cfg.Password != "" {
|
||||
creds[cfg.User] = cfg.Password
|
||||
}
|
||||
if len(creds) > 0 {
|
||||
cator := socks5.UserPassAuthenticator{Credentials: creds}
|
||||
socks5conf.AuthMethods = []socks5.Authenticator{cator}
|
||||
|
Loading…
Reference in New Issue
Block a user