refactor: replace PostgreSQL placeholders with generic SQL syntax and add audit logging for duplicate entries

- Replace $%d placeholders with ? in logsHandler for database abstraction
- Remove unused argIndex variable in auth.go
- Log duplicate permanent whitelist insertions to audit_log in db.go
This commit is contained in:
db123-test
2026-05-04 15:17:12 +03:30
parent 3fb4c6af95
commit 5a811241e1
2 changed files with 6 additions and 5 deletions

View File

@@ -136,7 +136,6 @@ func logsHandler(cfg Config, db *sql.DB) http.HandlerFunc {
query := `SELECT timestamp, action, ip, cidr, ttl_seconds, reason, api_client_ip FROM audit_log`
var args []any
argIndex := 1
filterAction := r.URL.Query().Get("action")
filterIP := r.URL.Query().Get("ip")
@@ -145,14 +144,12 @@ func logsHandler(cfg Config, db *sql.DB) http.HandlerFunc {
var conditions []string
if filterAction != "" {
conditions = append(conditions, fmt.Sprintf(`action = $%d`, argIndex))
conditions = append(conditions, `action = ?`)
args = append(args, filterAction)
argIndex++
}
if filterIP != "" {
conditions = append(conditions, fmt.Sprintf(`ip = $%d`, argIndex))
conditions = append(conditions, `ip = ?`)
args = append(args, filterIP)
argIndex++
}
if len(conditions) > 0 {