refactor: simplified and used db.go for operations on whitelists
This commit is contained in:
4
auth.go
4
auth.go
@@ -151,7 +151,6 @@ func logsHandler(cfg Config, db *sql.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Perm whitelist API endpoints (optional but useful) ---
|
|
||||||
func permWhitelistAddHandler(cfg Config, db *sql.DB) http.HandlerFunc {
|
func permWhitelistAddHandler(cfg Config, db *sql.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if !verifyAPIKey(r, cfg.APIToken) {
|
if !verifyAPIKey(r, cfg.APIToken) {
|
||||||
@@ -159,7 +158,7 @@ func permWhitelistAddHandler(cfg Config, db *sql.DB) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
type request struct {
|
type request struct {
|
||||||
Entry string `json:"entry"` // IP or CIDR
|
Entry string `json:"entry"`
|
||||||
}
|
}
|
||||||
var req request
|
var req request
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
@@ -204,7 +203,6 @@ func permWhitelistDeleteHandler(cfg Config, db *sql.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to get real client IP for audit (X-Real-IP or remote addr)
|
|
||||||
func getClientIP(r *http.Request) string {
|
func getClientIP(r *http.Request) string {
|
||||||
if ip := r.Header.Get("X-Real-IP"); ip != "" {
|
if ip := r.Header.Get("X-Real-IP"); ip != "" {
|
||||||
return ip
|
return ip
|
||||||
|
|||||||
Reference in New Issue
Block a user