From 2ece89662a5b948863c26f182521059f5eaf1aa3 Mon Sep 17 00:00:00 2001 From: dakrk Date: Mon, 15 Jan 2024 13:59:03 +0000 Subject: [PATCH] Allow toggling whitelist --- .gitignore | 1 + config.example.xml | 4 ++++ ias.go | 4 ++-- main.go | 3 +++ structure.go | 5 +++-- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 954aced..f995423 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea config.xml WiiSOAP +tmp/ diff --git a/config.example.xml b/config.example.xml index 012b991..694d0e6 100644 --- a/config.example.xml +++ b/config.example.xml @@ -20,4 +20,8 @@ This is useful when testing CAS directly. It is only functional when debug is enabled. --> false + + false diff --git a/ias.go b/ias.go index 36a54c9..5dd4e28 100644 --- a/ias.go +++ b/ias.go @@ -130,7 +130,7 @@ func syncRegistration(e *Envelope) { e.Error(7, "An error occurred querying the database.", err) } - if !slices.Contains(getWhitelistedSerialNumbers(), serialNumber) { + if whitelistEnabled && !slices.Contains(getWhitelistedSerialNumbers(), serialNumber) { // Since HTTP server runs on a separate Goroutine, this won't shut off the server, // rather kill communication with the requesting console panic(err) @@ -167,7 +167,7 @@ func register(e *Envelope) { return } - if !slices.Contains(getWhitelistedSerialNumbers(), serialNo) { + if whitelistEnabled && !slices.Contains(getWhitelistedSerialNumbers(), serialNo) { // Since HTTP server runs on a separate Goroutine, this won't shut off the server, // rather kill communication with the requesting console panic(err) diff --git a/main.go b/main.go index 1fc5e91..86bb079 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,7 @@ var pool *pgxpool.Pool var ctx = context.Background() var isDebug = false var ignoreAuth = false +var whitelistEnabled = false // checkError makes error handling not as ugly and inefficient. func checkError(err error) { @@ -72,6 +73,8 @@ func main() { ignoreAuth = readConfig.NoAuth } + whitelistEnabled = readConfig.Whitelist + // Start SQL. dbString := fmt.Sprintf("postgres://%s:%s@%s/%s", readConfig.SQLUser, readConfig.SQLPass, readConfig.SQLAddress, readConfig.SQLDB) dbConf, err := pgxpool.ParseConfig(dbString) diff --git a/structure.go b/structure.go index 177b865..1de9017 100644 --- a/structure.go +++ b/structure.go @@ -39,8 +39,9 @@ type Config struct { SQLPass string `xml:"SQLPass"` SQLDB string `xml:"SQLDB"` - Debug bool `xml:"Debug"` - NoAuth bool `xml:"NoAuth"` + Debug bool `xml:"Debug"` + NoAuth bool `xml:"NoAuth"` + Whitelist bool `xml:"Whitelist"` } // Envelope represents the root element of any response, soapenv:Envelope.