mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-08-17 16:07:18 +02:00
Add geo IP checking
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/phishingclub/phishingclub/geoip"
|
||||
)
|
||||
|
||||
// GeoIP is a controller for GeoIP-related endpoints
|
||||
type GeoIP struct {
|
||||
Common
|
||||
}
|
||||
|
||||
// GetMetadata returns the GeoIP metadata including available country codes
|
||||
func (c *GeoIP) GetMetadata(g *gin.Context) {
|
||||
_, _, ok := c.handleSession(g)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// get geoip instance
|
||||
geo, err := geoip.Instance()
|
||||
if ok := c.handleErrors(g, err); !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// get metadata
|
||||
metadata := geo.GetMetadata()
|
||||
if metadata == nil {
|
||||
c.Response.BadRequest(g)
|
||||
return
|
||||
}
|
||||
|
||||
c.Response.OK(g, metadata)
|
||||
}
|
||||
Reference in New Issue
Block a user