(feature): check if conferenceId is valid

This commit is contained in:
TheDevisi
2026-04-11 13:20:07 +03:00
parent 5e984603bb
commit 21fdb8aeef

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
)
@@ -29,6 +30,18 @@ func isValidPort(portStr string) bool {
return port > 0 && port <= 65535
}
func isValidConferenceID(conferenceID string) bool {
conferenceID = strings.TrimSpace(conferenceID)
if conferenceID == "" {
return false
}
matched, err := regexp.MatchString(`^\d+$`, conferenceID)
if err != nil {
return false
}
return matched
}
func (p *Program) getConfigPath() string {
dir, err := os.UserConfigDir()
if err != nil {
@@ -67,6 +80,10 @@ func (p *Program) loadConfig() *Config {
return cfg
}
cfg.ConferenceID = strings.ReplaceAll(cfg.ConferenceID, " ", "")
if !isValidConferenceID(cfg.ConferenceID) {
log("WARNING: Invalid conference ID in config (must be numbers only)")
cfg.ConferenceID = ""
}
if !isValidPort(cfg.SocksPort) {
log("WARNING: Invalid port in config, using default: 1080")
cfg.SocksPort = "1080"
@@ -86,6 +103,12 @@ func (p *Program) saveConfig(dns, encryptionKey, socksPort, conferenceID string)
return
}
if !isValidConferenceID(conferenceID) {
log("ERROR: Invalid conference ID: %s", conferenceID)
p.showError(fmt.Errorf("invalid conference ID: must contain only numbers"))
return
}
p.Config = &Config{
DNS: dns,
EncryptionKey: encryptionKey,