fix28: полный production-фикс графиков, machine-auth, i18n и peer import/export
This commit is contained in:
+41
-3
@@ -9,6 +9,8 @@ import (
|
||||
"hy2xs-admin/model/bo"
|
||||
"hy2xs-admin/model/constant"
|
||||
"hy2xs-admin/model/entity"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -88,6 +90,9 @@ func UpdateHysteria2Config(hysteria2ServerConfig bo.Hysteria2ServerConfig) error
|
||||
http.Insecure = &authHttpInsecure
|
||||
auth.HTTP = &http
|
||||
hysteria2ServerConfig.Auth = &auth
|
||||
if hysteria2ServerConfig.TrafficStats == nil {
|
||||
hysteria2ServerConfig.TrafficStats = &bo.ServerConfigTrafficStats{}
|
||||
}
|
||||
hysteria2ServerConfig.TrafficStats.Secret = &trafficStatsSecret
|
||||
|
||||
yamlConfig, err := yaml.Marshal(&hysteria2ServerConfig)
|
||||
@@ -119,15 +124,40 @@ func GetHysteria2ApiPort() (int64, error) {
|
||||
logrus.Errorf(errMsg)
|
||||
return 0, errors.New(errMsg)
|
||||
}
|
||||
apiPort, err := strconv.ParseInt(strings.Split(*hysteria2Config.TrafficStats.Listen, ":")[1], 10, 64)
|
||||
apiPort, err := parseTrafficStatsPort(*hysteria2Config.TrafficStats.Listen)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("apiPort: %s is invalid", *hysteria2Config.TrafficStats.Listen)
|
||||
errMsg := fmt.Sprintf("apiPort: %s is invalid: %v", *hysteria2Config.TrafficStats.Listen, err)
|
||||
logrus.Errorf(errMsg)
|
||||
return 0, errors.New(errMsg)
|
||||
}
|
||||
return apiPort, nil
|
||||
}
|
||||
|
||||
func parseTrafficStatsPort(listen string) (int64, error) {
|
||||
trimmed := strings.TrimSpace(listen)
|
||||
if trimmed == "" {
|
||||
return 0, errors.New("empty listen")
|
||||
}
|
||||
|
||||
hostPort := trimmed
|
||||
if strings.HasPrefix(trimmed, ":") {
|
||||
hostPort = "127.0.0.1" + trimmed
|
||||
}
|
||||
|
||||
_, portStr, err := net.SplitHostPort(hostPort)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
port, err := strconv.ParseInt(portStr, 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if port <= 0 || port > 65535 {
|
||||
return 0, errors.New("port out of range")
|
||||
}
|
||||
return port, nil
|
||||
}
|
||||
|
||||
func GetPortAndCert() (int64, string, string, error) {
|
||||
configs, err := dao.ListConfig("key in ?", []string{constant.HUIWebPort, constant.HUICrtPath, constant.HUIKeyPath})
|
||||
if err != nil {
|
||||
@@ -173,5 +203,13 @@ func GetAuthHttpUrl() (string, error) {
|
||||
if config.Value != nil && *config.Value != "/" && strings.HasPrefix(*config.Value, "/") {
|
||||
webContext = *config.Value
|
||||
}
|
||||
return fmt.Sprintf("%s://127.0.0.1:%d%s/hui/hysteria2/auth", protocol, port, webContext), nil
|
||||
trafficSecretConfig, err := dao.GetConfig("key = ?", constant.Hysteria2TrafficStatsSecret)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
authURL := fmt.Sprintf("%s://127.0.0.1:%d%s/hui/hysteria2/auth", protocol, port, webContext)
|
||||
if trafficSecretConfig.Value != nil && strings.TrimSpace(*trafficSecretConfig.Value) != "" {
|
||||
authURL = fmt.Sprintf("%s?access_token=%s", authURL, url.QueryEscape(strings.TrimSpace(*trafficSecretConfig.Value)))
|
||||
}
|
||||
return authURL, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user