arnaucube
arnaucube/goImgServerPublic Self-hosted repository
goImgServer/ipFilter.go
ipFilter.goRaw
 1package main
 2
 3import (
 4	"errors"
 5	"fmt"
 6	"net/http"
 7	"strings"
 8)
 9
10func ipFilter(r *http.Request) error {
11	var err error
12	fmt.Println(r.RemoteAddr)
13	reqIP := strings.Split(r.RemoteAddr, ":")[0]
14	for _, ip := range config.BlockedIPs {
15		if reqIP == ip {
16			err = errors.New("ip not allowed to post images")
17		}
18	}
19
20	for _, ip := range config.AllowedIPs {
21		if reqIP != ip {
22			err = errors.New("ip not allowed to post images")
23		}
24	}
25	return err
26}