mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2026-07-22 11:04:46 +00:00
49ffcadb0a
High (behavioral bugs):
- service.Geo: add RLock on lookups, handle Reload error, keep old DBs on failure
- models.GeoDB.Reload: open new DBs before closing old ones (no reader gap)
- router: guard nil geo records (404 instead of 500) in geo.go, generic.go, dns.go
- router/port_scanner: reject undetermined client IPs (nil->localhost dial)
- internal/httputils: fix access log date layout (02/Jan/2006, not literal Nov)
- server/quic: log.Printf instead of log.Fatal in request handler
Medium:
- server/*: 10s shutdown timeout; SIGTERM drains servers before closing geo DBs
- httputils: Clone() request headers instead of mutating the live map; strings.Builder
- setting/app: handle all os.Stat errors; fix "truster" typos; use errors.New;
remove dead Token field
- cmd: errors.Is for sentinel checks; os.Stderr; log.Fatal instead of panic;
pass http.Handler by value (not pointer-to-interface)
- resolver: validate config at startup (pre-parse RRs, validate IPs); check WriteMsg
errors; Setup returns error
Low:
- .golangci.yaml: enable errcheck, govet, errorlint; fix all resulting findings
- server/tls: explicit TLSConfig{MinVersion: tls.VersionTLS12}
- router/dns: label-exact vhost suffix check, strip port; template.Must
- models: errors.Join instead of %s on []error
- service/geo_test: race-regression test (concurrent lookups during Reload)
- README: Go >= 1.25; fix latent test bug (store.Add->Set in dns_test.go)
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/dcarrillo/whatismyip/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type JSONScanResponse struct {
|
|
IP string `json:"ip"`
|
|
Port int `json:"port"`
|
|
Reachable bool `json:"reachable"`
|
|
Reason string `json:"reason"`
|
|
}
|
|
|
|
func scanTCPPort(ctx *gin.Context) {
|
|
port, err := strconv.Atoi(ctx.Params.ByName("port"))
|
|
if err == nil && (port < 1 || port > 65535) {
|
|
err = fmt.Errorf("%d is not a valid port number", port)
|
|
}
|
|
if err != nil {
|
|
ctx.JSON(http.StatusBadRequest, JSONScanResponse{
|
|
Reason: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
ip := net.ParseIP(ctx.ClientIP())
|
|
if ip == nil {
|
|
ctx.JSON(http.StatusBadRequest, JSONScanResponse{
|
|
Reason: "client ip could not be determined",
|
|
})
|
|
return
|
|
}
|
|
|
|
add := net.TCPAddr{
|
|
IP: ip,
|
|
Port: port,
|
|
}
|
|
|
|
scan := service.PortScanner{
|
|
Address: &add,
|
|
}
|
|
|
|
isOpen, err := scan.IsPortOpen()
|
|
reason := ""
|
|
if err != nil {
|
|
reason = err.Error()
|
|
}
|
|
|
|
response := JSONScanResponse{
|
|
IP: ctx.ClientIP(),
|
|
Port: port,
|
|
Reachable: isOpen,
|
|
Reason: reason,
|
|
}
|
|
ctx.JSON(http.StatusOK, response)
|
|
}
|