Allow toggling whitelist

This commit is contained in:
dakrk 2024-01-15 13:59:03 +00:00
parent 2b37235666
commit 2ece89662a
No known key found for this signature in database
GPG Key ID: 9AA47AFB7FE4409F
5 changed files with 13 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
config.xml
WiiSOAP
tmp/

View File

@ -20,4 +20,8 @@
This is useful when testing CAS directly.
It is only functional when debug is enabled. -->
<NoAuth>false</NoAuth>
<!-- Set to true to enable serial number
whitelisting by reading a newline separated file
located at whitelist.txt. -->
<Whitelist>false</Whitelist>
</Config>

4
ias.go
View File

@ -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)

View File

@ -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)

View File

@ -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.