feat: add SQLite persistence and REST API for temporary whitelisting
- Migrate IP-based temporary whitelisting from file to SQLite storage - Add REST API endpoints for managing temporary and permanent whitelists - Create `.env.example` with required environment variables - Document API endpoints in README.md and docs/api.md - Add new dependency `modernc.org/sqlite` for SQLite support - Update deployment and security documentation
This commit is contained in:
10
db.go
10
db.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
@@ -180,16 +181,15 @@ func ListTempEntries(db *sql.DB) ([]map[string]interface{}, error) {
|
||||
continue
|
||||
}
|
||||
list = append(list, map[string]interface{}{
|
||||
"ip": ip,
|
||||
"expires": expiresAt,
|
||||
"reason": reason,
|
||||
"ip": ip,
|
||||
"expires": expiresAt,
|
||||
"reason": reason,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func ipMatchesEntry(ip, entry string) (bool, error) {
|
||||
// Simple case: exact IP match
|
||||
if entry == ip {
|
||||
return true, nil
|
||||
}
|
||||
@@ -222,4 +222,4 @@ func isUniqueConstraintError(err error) bool {
|
||||
return false
|
||||
}
|
||||
return err.Error() == "UNIQUE constraint failed: permanent_whitelist.entry"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user