fix: Validate StreamPorts in StreamConfig to prevent empty values (#11332)

This commit is contained in:
KOMATA 2025-12-15 10:11:09 +08:00 committed by GitHub
parent 956a64c692
commit 191396c78a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 2 deletions

View file

@ -42,7 +42,7 @@ type WebsiteCreate struct {
} }
type StreamConfig struct { type StreamConfig struct {
StreamPorts string `json:"streamPorts" validate:"required"` StreamPorts string `json:"streamPorts"`
Name string `json:"name"` Name string `json:"name"`
Algorithm string `json:"algorithm"` Algorithm string `json:"algorithm"`

View file

@ -282,6 +282,9 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
primaryDomain string primaryDomain string
) )
if website.Type == constant.Stream { if website.Type == constant.Stream {
if create.StreamConfig.StreamPorts == "" {
return buserr.New("ErrTypePortRange")
}
website.PrimaryDomain = create.Name website.PrimaryDomain = create.Name
website.Protocol = constant.ProtocolStream website.Protocol = constant.ProtocolStream
website.StreamPorts = create.StreamConfig.StreamPorts website.StreamPorts = create.StreamConfig.StreamPorts
@ -2400,6 +2403,9 @@ func (w WebsiteService) ExecComposer(req request.ExecComposerReq) error {
} }
func (w WebsiteService) UpdateStream(req request.StreamUpdate) error { func (w WebsiteService) UpdateStream(req request.StreamUpdate) error {
if req.StreamConfig.StreamPorts == ""{
return buserr.New("ErrTypePortRange")
}
website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID))
if err != nil { if err != nil {
return err return err

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
"log" "log"
"net" "net"
"os" "os"
@ -15,6 +14,8 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
"github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto/request"
@ -189,6 +190,9 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
config *components.Config config *components.Config
) )
if website.Type == constant.Stream { if website.Type == constant.Stream {
if streamConfig.StreamPorts == "" {
return buserr.New("ErrTypePortRange")
}
nginxContent := nginx_conf.GetWebsiteFile("stream_default.conf") nginxContent := nginx_conf.GetWebsiteFile("stream_default.conf")
config, err = parser.NewStringParser(string(nginxContent)).Parse() config, err = parser.NewStringParser(string(nginxContent)).Parse()
if err != nil { if err != nil {