Browse Source

well..

master
SeraphJACK 3 years ago
parent
commit
21868bd3c3
Signed by: SeraphJACK <seraphjack@outlook.com> GPG Key ID: 14162B46567AB06F
5 changed files with 54 additions and 2 deletions
  1. +14
    -1
      http/challenge.go
  2. +15
    -0
      http/ipcheck.go
  3. +8
    -1
      http/submit.go
  4. +10
    -0
      http/utils.go
  5. +7
    -0
      storage/ip.go

+ 14
- 1
http/challenge.go View File

@@ -1,7 +1,20 @@
package http

import "net/http"
import (
"fmt"
"net"
"net/http"
)

func handleChallenge(w http.ResponseWriter, r *http.Request) {
if !checkIp(getIp(r)) {
w.WriteHeader(429)
_, _ = fmt.Fprintf(w, "ip already voted")
}
// TODO
}

func checkChallenge(ip net.IP, challenge string) bool {
// TODO
return false
}

+ 15
- 0
http/ipcheck.go View File

@@ -0,0 +1,15 @@
package http

import (
"log"
"net"
"votes/storage"
)

func checkIp(ip net.IP) bool {
if ip == nil {
log.Printf("got nil ip addr\n")
return false
}
return !storage.IsIPVoted(ip)
}

+ 8
- 1
http/submit.go View File

@@ -1,7 +1,14 @@
package http

import "net/http"
import (
"fmt"
"net/http"
)

func handleSubmit(w http.ResponseWriter, r *http.Request) {
if !checkIp(getIp(r)) {
w.WriteHeader(429)
_, _ = fmt.Fprintf(w, "ip already voted")
}
// TODO
}

+ 10
- 0
http/utils.go View File

@@ -0,0 +1,10 @@
package http

import (
"net"
"net/http"
)

func getIp(r *http.Request) net.IP {
return net.ParseIP(r.Header.Get("X-Real-Ip"))
}

+ 7
- 0
storage/ip.go View File

@@ -1 +1,8 @@
package storage

import "net"

func IsIPVoted(ip net.IP) bool {
// TODO
return false
}

Loading…
Cancel
Save