612d68f56f
Go + Vue 管理台,SQLite 持久化;支持隧道/域名穿透、域名转发插件链、访客认证、 IP 规则、API Key、Docker 单镜像部署;配置通过 Web 系统设置管理,无需 YAML 文件。 Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"reflect"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/wormhole/wormhole/internal/auth"
|
|
"github.com/wormhole/wormhole/internal/config"
|
|
)
|
|
|
|
func (s *Server) getSettings(c *gin.Context) {
|
|
claims := getClaims(c)
|
|
if !auth.IsAdmin(claims.Role) {
|
|
c.JSON(http.StatusForbidden, gin.H{"error": "admin only"})
|
|
return
|
|
}
|
|
dto := s.cfg.ToDTO()
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"settings": dto,
|
|
"note": "修改监听端口后需重启 wormhole server 生效",
|
|
})
|
|
}
|
|
|
|
func (s *Server) updateSettings(c *gin.Context) {
|
|
claims := getClaims(c)
|
|
if !auth.IsAdmin(claims.Role) {
|
|
c.JSON(http.StatusForbidden, gin.H{"error": "admin only"})
|
|
return
|
|
}
|
|
var req config.SettingsDTO
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
|
|
return
|
|
}
|
|
oldServer := s.cfg.Server
|
|
newCfg := config.SettingsFromDTO(req, s.cfg)
|
|
if err := s.store.SaveConfig(newCfg); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
*s.cfg = *newCfg
|
|
s.auth.ReloadAuth(&s.cfg.Auth)
|
|
s.resAuth.ReloadAuth(&s.cfg.Auth)
|
|
|
|
restartRequired := !reflect.DeepEqual(oldServer, s.cfg.Server) ||
|
|
oldServer.TLSCertFile != s.cfg.Server.TLSCertFile ||
|
|
oldServer.TLSKeyFile != s.cfg.Server.TLSKeyFile
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"settings": s.cfg.ToDTO(),
|
|
"restart_required": restartRequired,
|
|
})
|
|
}
|