mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-06-09 05:44:43 +00:00
(feature): check if conferenceId is valid
This commit is contained in:
23
ui/config.go
23
ui/config.go
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user