Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
|
@ -3,10 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -15,35 +12,11 @@ var (
|
||||||
|
|
||||||
func server() {
|
func server() {
|
||||||
fmt.Printf("Listening on port %v...\n", listenPort)
|
fmt.Printf("Listening on port %v...\n", listenPort)
|
||||||
|
|
||||||
gin.SetMode(gin.ReleaseMode)
|
|
||||||
gin.DisableConsoleColor()
|
|
||||||
|
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.GET("/", serveIP)
|
router.GET("/", serveIP)
|
||||||
router.GET("/:id", serveIP)
|
|
||||||
router.Run(":" + listenPort)
|
router.Run(":" + listenPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveIP(c *gin.Context) {
|
func serveIP(c *gin.Context) {
|
||||||
c.Writer.Header().Set("Federal-Agents", "Outside my home")
|
|
||||||
c.String(http.StatusOK, c.ClientIP()+"\n")
|
c.String(http.StatusOK, c.ClientIP()+"\n")
|
||||||
writeToLog(c.ClientIP(), c.Request.UserAgent(), c.Request.URL.Path, c.Request.Method)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeToLog(ip string, useragent string, request string, requestmethod string) {
|
|
||||||
f, err := os.OpenFile("./reply-ip.log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0660)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error happened opening file: %v\n", err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
log := fmt.Sprintf("[%v] | [%v] | [%v] | [%v \"%v\"]\n", getTime(), useragent, ip, requestmethod, request)
|
|
||||||
f.WriteString(log)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTime() string {
|
|
||||||
t := time.Now()
|
|
||||||
currentTime := fmt.Sprintf("%d-%02d-%02d | %02d:%02d:%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
|
|
||||||
return currentTime
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue