mirror of
https://github.com/arnaucube/goImgServer.git
synced 2026-02-07 03:26:43 +01:00
implemented filter by ip on posting new images
This commit is contained in:
@@ -33,6 +33,11 @@ func ImageShow(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewImage(w http.ResponseWriter, r *http.Request) {
|
func NewImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
err := ipFilter(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(w, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
file, handler, err := r.FormFile("file")
|
file, handler, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
19
ipFilter.go
Normal file
19
ipFilter.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ipFilter(r *http.Request) error {
|
||||||
|
var err error
|
||||||
|
fmt.Println(r.RemoteAddr)
|
||||||
|
ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||||
|
if ip != "127.0.0.1" {
|
||||||
|
err = errors.New("ip not allowed to post images")
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user