mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-08 21:39:56 +00:00
31 lines
697 B
Go
31 lines
697 B
Go
package auth
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"net"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type CmdAuthProvider struct {
|
|
Cmd string
|
|
}
|
|
|
|
func (p *CmdAuthProvider) Auth(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) {
|
|
cmd := exec.Command(p.Cmd, addr.String(), string(auth), strconv.Itoa(int(sSend)), strconv.Itoa(int(sRecv)))
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
if _, ok := err.(*exec.ExitError); ok {
|
|
return false, strings.TrimSpace(string(out))
|
|
} else {
|
|
logrus.WithFields(logrus.Fields{
|
|
"error": err,
|
|
}).Error("Failed to execute auth command")
|
|
return false, "internal error"
|
|
}
|
|
} else {
|
|
return true, strings.TrimSpace(string(out))
|
|
}
|
|
}
|