2024-01-12 14:27:55 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2024-01-13 09:31:08 +03:00
|
|
|
|
|
|
|
"github.com/armon/go-socks5"
|
2024-01-12 14:27:55 +03:00
|
|
|
)
|
|
|
|
|
2024-01-13 09:22:40 +03:00
|
|
|
type Credentials struct {
|
2024-01-12 14:29:25 +03:00
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
2024-01-12 14:27:55 +03:00
|
|
|
}
|
|
|
|
|
2024-01-13 09:31:08 +03:00
|
|
|
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
|
2024-01-12 14:27:55 +03:00
|
|
|
}
|
|
|
|
|
2024-01-13 09:22:40 +03:00
|
|
|
return creds, nil
|
2024-01-12 14:27:55 +03:00
|
|
|
}
|