diff --git a/extra/banner.go b/extra/banner.go index d95844b..4cbc925 100644 --- a/extra/banner.go +++ b/extra/banner.go @@ -13,7 +13,7 @@ import ( "github.com/yunginnanet/HellPot/config" ) -const hellpot = "H4sIAAAAAAACA8WXMU/rMBDH93wFlhsYozbUBRTxBd7IXjGUUkGBpIgXnoT0hg4dssaV+gH7SUhzje04d45TqJBKZZy78/n/u7PT4GxyProZRwngQCS77bocXuzndtt8t5WmhZ7Ozybi+jAdJfs/MAw2dTQow9kRGVdqkSrSwRjgFPayHuis3G6bylRpxW+OFGZdf3JOb7UN7RwlASEtxtCOBbVHchXpRFZ66X0bBis3cSUoC6C/pf9WgRSOZpY3lGhv1BWoYU/mJumakSxQicN2pPKzwjmhHguBjwsqO2kh1EWgdO5ys2V2Azrek0erSTKFKjmYhRccdhdNYn26TFo8GngLLD9AjHsjZAgttHxzSbOErQPF7UhXRC+wR/qtm6ceHrUbSj0Osr1jfeSueO3bxUBCbZ65VFoFKSyJFmqOgDyEWk47qsY1r5x2TRr97boecr6aj/eUxlNKjnbxeStvNGx5pK2so9EO1FqnKzMWFFFr2IX64gBMgFPT1fFUKn564Iqbb2naN4Y0xP5hvLLuhcO36wWv4+AtmqfMsUg96cAp1CiYLH8tYlffMK/K3gnYfeGADz63CQ26UKA98LVAM7uiX4y89n8ib7oPuAvXt1oYgI5fPFSutRmagi+l7kodKSV6tCBdUifxEpHBAcA/oFPEQ1Sl07/a7TyZPtc6DsrBGCcXabWoWr36CgKYqBCPi2yQzd4GD4v3+Swbvkw/l3+Hf+avr7fLrDK/Q2NMrrR++rgfzJbJ8PMjfVyk6TSdZ037/2IUinEoLkNxFcYijEdhPA7jyzAu/42CLxeiz4pAEAAA" +const hellpot = "H4sIAAAAAAACA8VXvW7bQAze9QpZOGQUbNXnJBDyAh27Gx1c10icRHLRKgUCdPDgQavOgB/QT1JZ9P3oRJ5OTowAjnE5feSR30fy5Ohqdj25nyYZ4EJkh/22Xn457h325WEvbYTZLq9m4u60nWTHP7AAO+UNaneuR8aUOqTxdAIDXAIv1cJE5TfbNVDNFZ8cScxWfUqOb52GMU6yiKAWfRjDisqRPEV6JautTN4WYONXXBPKCjAcGZ4qkMTRmpUtJrqJ+hy18GRskq4ZyQoqcdn1VH82uCf0YyHwcUVFJx0JTRFonvvMXJr9Ap1vyUtrlGQKVXJiVkHisFm0FRvSZdLRoyVvheUHKOMRhBpCR1q+uaRdws5A8RvSFTFI2DPttu2ph6N2R7HHiexmbEbuhue+WwykqO2ZS4VVkcSS0oLSEVAPoY8zhrpx7SunW5NWf/uuh5Kv5vMtpfWUoqNbfMHMWw1bj7SNMxpdR51z+iJjhSJqDbvQXByAAXBs+jqeCiWMDzxx9y5Oh/qQFtkfLK9UvXD69r3g9Qzeqj1lzpU0UB24BBsVE+WneezrG+ZVOTgAty884kPIbUILXWmhA+TrCM1kRb8YBeV/IWu6D7gLN7RaGAE9v3ioWBUMoRCqUn+lTjQTA1qQLqmLWInE0gEg3KGXxJNXhfmrrK6z+ZOicVQvpri5yk2DNKvmK4pgpl08rIpRsfg1+rn6vVwU4+f52/rP+Ovy5eXbumjg3xGMwdXox9cfo8U6G7+95g+rPJ/ny6KN/ycmsZjG4iYWt3Eq4nQSp9M4vYnT+t8k+g/TQ9elQBAAAA==" func b64d(str string) []byte { var data []byte diff --git a/http/router.go b/http/router.go index 1b2734b..9604dea 100644 --- a/http/router.go +++ b/http/router.go @@ -3,9 +3,7 @@ package http import ( "bufio" "fmt" - "net" - "os" - "syscall" + "runtime" "time" "github.com/fasthttp/router" @@ -59,29 +57,6 @@ func hellPot(ctx *fasthttp.RequestCtx) { } -func listenOnUnixSocket(addr string, r *router.Router) error { - var err error - var unixAddr *net.UnixAddr - var unixListener *net.UnixListener - unixAddr, err = net.ResolveUnixAddr("unix", addr) - if err == nil { - // Always unlink sockets before listening on them - _ = syscall.Unlink(addr) - // Before we set socket permissions, we want to make sure only the user HellPot is running under - // has permission to the socket. - oldmask := syscall.Umask(0077) - unixListener, err = net.ListenUnix("unix", unixAddr) - syscall.Umask(oldmask) - if err == nil { - err = os.Chmod(unixAddr.Name, os.FileMode(config.UnixSocketPermissions)) - if err == nil { - err = fasthttp.Serve(unixListener, r.Handler) - } - } - } - return err -} - func getSrv(r *router.Router) fasthttp.Server { if !config.RestrictConcurrency { config.MaxWorkers = fasthttp.DefaultConcurrency @@ -132,7 +107,7 @@ func Serve() error { srv := getSrv(r) - if !config.UseUnixSocket { + if !config.UseUnixSocket || runtime.GOOS == "windows" { log.Info().Str("caller", l).Msg("Listening and serving HTTP...") return srv.ListenAndServe(l) } diff --git a/http/router_unix.go b/http/router_unix.go new file mode 100644 index 0000000..1475d07 --- /dev/null +++ b/http/router_unix.go @@ -0,0 +1,37 @@ +//+build linux darwin freebsd + +package http + +import ( + "net" + "os" + "syscall" + + "github.com/fasthttp/router" + "github.com/valyala/fasthttp" + + "github.com/yunginnanet/HellPot/config" +) + +func listenOnUnixSocket(addr string, r *router.Router) error { + var err error + var unixAddr *net.UnixAddr + var unixListener *net.UnixListener + unixAddr, err = net.ResolveUnixAddr("unix", addr) + if err == nil { + // Always unlink sockets before listening on them + _ = syscall.Unlink(addr) + // Before we set socket permissions, we want to make sure only the user HellPot is running under + // has permission to the socket. + oldmask := syscall.Umask(0077) + unixListener, err = net.ListenUnix("unix", unixAddr) + syscall.Umask(oldmask) + if err == nil { + err = os.Chmod(unixAddr.Name, os.FileMode(config.UnixSocketPermissions)) + if err == nil { + err = fasthttp.Serve(unixListener, r.Handler) + } + } + } + return err +} diff --git a/http/router_windows.go b/http/router_windows.go new file mode 100644 index 0000000..46998d1 --- /dev/null +++ b/http/router_windows.go @@ -0,0 +1,13 @@ +//go:build windows +// +build windows + +package http + +import ( + "errors" + "github.com/fasthttp/router" +) + +func listenOnUnixSocket(addr string, r *router.Router) error { + return errors.New("unix sockets are not supported on Windows") +}