123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package main
- import (
- "encoding/json"
- "net/http"
- "imuslab.com/arozos/ReverseProxy/mod/utils"
- )
- /*
- blacklist.go
- This script file is added to extend the
- reverse proxy function to include
- banning a specific IP address or country code
- */
- //List a of blacklisted ip address or country code
- func handleListBlacklisted(w http.ResponseWriter, r *http.Request) {
- bltype, err := utils.GetPara(r, "type")
- if err != nil {
- bltype = "country"
- }
- resulst := []string{}
- if bltype == "country" {
- resulst = geodbStore.GetAllBlacklistedCountryCode()
- } else if bltype == "ip" {
- resulst = geodbStore.GetAllBlacklistedIp()
- }
- js, _ := json.Marshal(resulst)
- utils.SendJSONResponse(w, string(js))
- }
- func handleCountryBlacklistAdd(w http.ResponseWriter, r *http.Request) {
- countryCode, err := utils.PostPara(r, "cc")
- if err != nil {
- utils.SendErrorResponse(w, "invalid or empty country code")
- return
- }
- geodbStore.AddCountryCodeToBlackList(countryCode)
- utils.SendOK(w)
- }
- func handleCountryBlacklistRemove(w http.ResponseWriter, r *http.Request) {
- countryCode, err := utils.PostPara(r, "cc")
- if err != nil {
- utils.SendErrorResponse(w, "invalid or empty country code")
- return
- }
- geodbStore.RemoveCountryCodeFromBlackList(countryCode)
- utils.SendOK(w)
- }
- func handleIpBlacklistAdd(w http.ResponseWriter, r *http.Request) {
- ipAddr, err := utils.PostPara(r, "ip")
- if err != nil {
- utils.SendErrorResponse(w, "invalid or empty ip address")
- return
- }
- geodbStore.AddIPToBlackList(ipAddr)
- }
- func handleIpBlacklistRemove(w http.ResponseWriter, r *http.Request) {
- ipAddr, err := utils.PostPara(r, "ip")
- if err != nil {
- utils.SendErrorResponse(w, "invalid or empty ip address")
- return
- }
- geodbStore.RemoveIPFromBlackList(ipAddr)
- utils.SendOK(w)
- }
|