Browse Source

implemented filter by ip on posting new images

master
arnaucode 7 years ago
parent
commit
e72905e6b2
2 changed files with 24 additions and 0 deletions
  1. +5
    -0
      handlers.go
  2. +19
    -0
      ipFilter.go

+ 5
- 0
handlers.go

@ -33,6 +33,11 @@ func ImageShow(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")
if err != nil {
fmt.Println(err)

+ 19
- 0
ipFilter.go

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

Loading…
Cancel
Save