fix windows support

This commit is contained in:
kayos@tcp.direct 2021-09-21 23:47:32 -07:00
parent 14e3bc7377
commit 9b02101f71
4 changed files with 53 additions and 28 deletions

View File

@ -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

View File

@ -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)
}

37
http/router_unix.go Normal file
View File

@ -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
}

13
http/router_windows.go Normal file
View File

@ -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")
}