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:
db123-test
2026-05-04 09:08:11 +03:30
parent a5c9c42533
commit 515de33837
18 changed files with 467 additions and 254 deletions

10
db.go
View File

@@ -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"
}
}