refactor(admin): удалить мёртвый updater/config-write API и его UI
Маршруты, операциями которых продукт не владеет, отвечали заглушкой "managed by orchestrator" или пустым списком: POST /hysteria2ChangeVersion GET /listRelease POST /config/updateHysteria2Config POST /config/importHysteria2Config POST /config/restartServer POST /config/uploadCertFile GET /config/hysteria2AcmePath (не имел потребителя вовсе) Они удалены, а не оставлены заглушками. Причины две. API-контракт не должен обещать updater, которого у продукта принципиально нет: маршрут, всегда возвращающий отказ, вводит в заблуждение. И это лишняя attack surface плюс технический мусор от прежней архитектуры. Вместе с маршрутами убраны мёртвые сервисы (StartHysteria2, StopHysteria2, RestartHysteria2, SetHysteria2Config, UpdateHysteria2Config, GetAuthHttpUrl, Hysteria2AcmePath), неиспользуемые типы и клиентские функции фронтенда. Отдельно - кнопки. "Перезапустить панель" и загрузка сертификатов обращались к заглушкам, то есть гарантированно возвращали ошибку. Кнопка, которая всегда падает, - не точка расширения на будущее, а дефект UX. Удалены вместе со строками i18n. Конфигурация Hysteria остаётся доступной панели на чтение и на выгрузку: getHysteria2Config и exportHysteria2Config.
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"hy2xs-admin/model/constant"
|
||||
"hy2xs-admin/model/entity"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -54,62 +53,6 @@ func GetHysteria2Config() (bo.Hysteria2ServerConfig, error) {
|
||||
return serverConfig, nil
|
||||
}
|
||||
|
||||
func UpdateHysteria2Config(hysteria2ServerConfig bo.Hysteria2ServerConfig) error {
|
||||
// Значения по умолчанию
|
||||
config, err := dao.ListConfig("key in ?", []string{constant.HUIWebPort, constant.Hysteria2TrafficStatsSecret})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var hUIWebPort string
|
||||
var trafficStatsSecret string
|
||||
for _, item := range config {
|
||||
if *item.Key == constant.HUIWebPort {
|
||||
hUIWebPort = *item.Value
|
||||
} else if *item.Key == constant.Hysteria2TrafficStatsSecret {
|
||||
trafficStatsSecret = *item.Value
|
||||
}
|
||||
}
|
||||
|
||||
if hUIWebPort == "" || trafficStatsSecret == "" {
|
||||
logrus.Errorf("hUIWebPort or trafficStatsSecret is nil")
|
||||
return errors.New(constant.SysError)
|
||||
}
|
||||
|
||||
authHttpUrl, err := GetAuthHttpUrl()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authType := "http"
|
||||
authHttpInsecure := true
|
||||
var auth bo.ServerConfigAuth
|
||||
auth.Type = &authType
|
||||
var http bo.ServerConfigAuthHTTP
|
||||
http.URL = &authHttpUrl
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dao.UpdateConfig([]string{constant.Hysteria2Config}, map[string]interface{}{"value": string(yamlConfig)})
|
||||
}
|
||||
|
||||
func SetHysteria2Config(hysteria2ServerConfig bo.Hysteria2ServerConfig) error {
|
||||
config, err := yaml.Marshal(&hysteria2ServerConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dao.UpdateConfig([]string{constant.Hysteria2Config}, map[string]interface{}{"value": string(config)})
|
||||
}
|
||||
|
||||
func UpsertConfig(configs []entity.Config) error {
|
||||
return dao.UpsertConfig(configs)
|
||||
}
|
||||
@@ -185,31 +128,3 @@ func GetPortAndCert() (int64, string, string, error) {
|
||||
|
||||
return portInt, crtPath, keyPath, nil
|
||||
}
|
||||
|
||||
func GetAuthHttpUrl() (string, error) {
|
||||
port, crtPath, keyPath, err := GetPortAndCert()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
protocol := "http"
|
||||
if crtPath != "" && keyPath != "" {
|
||||
protocol = "https"
|
||||
}
|
||||
config, err := dao.GetConfig("key = ?", constant.HUIWebContext)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
webContext := ""
|
||||
if config.Value != nil && *config.Value != "/" && strings.HasPrefix(*config.Value, "/") {
|
||||
webContext = *config.Value
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"hy2xs-admin/dao"
|
||||
"hy2xs-admin/model/constant"
|
||||
"hy2xs-admin/model/vo"
|
||||
"hy2xs-admin/util"
|
||||
)
|
||||
|
||||
// Жизненный цикл Hysteria принадлежит systemd и install-оркестратору.
|
||||
// Панель умеет только наблюдать состояние: функций Start/Stop/Restart и
|
||||
// смены версии здесь нет намеренно, а не «временно отключены».
|
||||
|
||||
func InitHysteria2() error {
|
||||
if !util.Exists(util.GetHysteria2BinPath()) {
|
||||
return errors.New("systemd-managed hysteria binary not found")
|
||||
@@ -31,58 +34,6 @@ func Hysteria2IsRunning() bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func StartHysteria2() error {
|
||||
return errors.New("managed by orchestrator: use hy2xs-orchestrator reconfigure")
|
||||
}
|
||||
|
||||
func StopHysteria2() error {
|
||||
return errors.New("managed by orchestrator: use hy2xs-orchestrator reconfigure")
|
||||
}
|
||||
|
||||
func RestartHysteria2() error {
|
||||
return errors.New("managed by orchestrator: use hy2xs-orchestrator reconfigure")
|
||||
}
|
||||
|
||||
func ReleaseHysteria2() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Hysteria2AcmePath() (vo.Hysteria2AcmePathVo, error) {
|
||||
hysteria2AcmePathVo := vo.Hysteria2AcmePathVo{}
|
||||
hysteria2Config, err := GetHysteria2Config()
|
||||
if err != nil {
|
||||
return hysteria2AcmePathVo, err
|
||||
}
|
||||
if hysteria2Config.TLS != nil &&
|
||||
hysteria2Config.TLS.Cert != nil && *hysteria2Config.TLS.Cert != "" &&
|
||||
hysteria2Config.TLS.Key != nil && *hysteria2Config.TLS.Key != "" {
|
||||
if util.Exists(*hysteria2Config.TLS.Cert) && util.Exists(*hysteria2Config.TLS.Key) {
|
||||
hysteria2AcmePathVo.CrtPath = *hysteria2Config.TLS.Cert
|
||||
hysteria2AcmePathVo.KeyPath = *hysteria2Config.TLS.Key
|
||||
return hysteria2AcmePathVo, nil
|
||||
}
|
||||
return hysteria2AcmePathVo, errors.New("cert not found")
|
||||
} else if hysteria2Config.ACME != nil &&
|
||||
hysteria2Config.ACME.Domains != nil &&
|
||||
len(hysteria2Config.ACME.Domains) > 0 &&
|
||||
hysteria2Config.ACME.CA != nil &&
|
||||
*hysteria2Config.ACME.CA != "" &&
|
||||
hysteria2Config.ACME.Dir != nil &&
|
||||
*hysteria2Config.ACME.Dir != "" {
|
||||
acmeDir := *hysteria2Config.ACME.Dir
|
||||
for _, domain := range hysteria2Config.ACME.Domains {
|
||||
crtPath, err := util.FindFile(acmeDir, fmt.Sprintf("%s.crt", domain))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
keyPath, err := util.FindFile(acmeDir, fmt.Sprintf("%s.key", domain))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
hysteria2AcmePathVo.CrtPath = crtPath
|
||||
hysteria2AcmePathVo.KeyPath = keyPath
|
||||
return hysteria2AcmePathVo, nil
|
||||
}
|
||||
}
|
||||
return vo.Hysteria2AcmePathVo{}, errors.New("cert not found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user