feat: add dedicated WebSocket service for subdomain ping
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 6m33s
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 6m33s
This commit is contained in:
@ -16,8 +16,9 @@ import (
|
||||
"time"
|
||||
portUtil "tunnel_pls/internal/port"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
"tunnel_pls/utils"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
type SessionStatus string
|
||||
@ -28,6 +29,10 @@ const (
|
||||
SETUP SessionStatus = "SETUP"
|
||||
)
|
||||
|
||||
var forbiddenSlug = []string{
|
||||
"ping",
|
||||
}
|
||||
|
||||
type UserConnection struct {
|
||||
Reader io.Reader
|
||||
Writer net.Conn
|
||||
@ -409,12 +414,21 @@ func (s *Session) handleSlugEditMode(connection ssh.Channel, inSlugEditMode *boo
|
||||
}
|
||||
}
|
||||
|
||||
func isForbiddenSlug(slug string) bool {
|
||||
for _, s := range forbiddenSlug {
|
||||
if slug == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Session) handleSlugSave(connection ssh.Channel, inSlugEditMode *bool, editSlug *string, commandBuffer *bytes.Buffer) {
|
||||
isValid := isValidSlug(*editSlug)
|
||||
|
||||
connection.Write([]byte("\033[H\033[2J"))
|
||||
|
||||
if isValid {
|
||||
if !isValid {
|
||||
oldSlug := s.Slug
|
||||
newSlug := *editSlug
|
||||
|
||||
@ -426,6 +440,11 @@ func (s *Session) handleSlugSave(connection ssh.Channel, inSlugEditMode *bool, e
|
||||
connection.Write([]byte("\r\n\r\n✅ SUBDOMAIN UPDATED ✅\r\n\r\n"))
|
||||
connection.Write([]byte("Your new address is: " + newSlug + "." + utils.Getenv("domain") + "\r\n\r\n"))
|
||||
connection.Write([]byte("Press any key to continue...\r\n"))
|
||||
} else if isForbiddenSlug(*editSlug) {
|
||||
connection.Write([]byte("\r\n\r\n❌ FORBIDDEN SUBDOMAIN ❌\r\n\r\n"))
|
||||
connection.Write([]byte("This subdomain is not allowed.\r\n"))
|
||||
connection.Write([]byte("Please try a different subdomain.\r\n\r\n"))
|
||||
connection.Write([]byte("Press any key to continue...\r\n"))
|
||||
} else {
|
||||
connection.Write([]byte("\r\n\r\n❌ INVALID SUBDOMAIN ❌\r\n\r\n"))
|
||||
connection.Write([]byte("Use only lowercase letters, numbers, and hyphens.\r\n"))
|
||||
|
||||
Reference in New Issue
Block a user