Skip to content

Commit

Permalink
fix sysproxy unspecified ip address bug
Browse files Browse the repository at this point in the history
Signed-off-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
  • Loading branch information
Asutorufa committed Jun 19, 2023
1 parent 6f95ce5 commit 9ce6cb3
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 29 deletions.
8 changes: 4 additions & 4 deletions internal/http/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"files": {
"main.css": "/static/css/main.1e446194.css",
"main.js": "/static/js/main.94855a25.js",
"main.css": "/static/css/main.c9167014.css",
"main.js": "/static/js/main.e29fa70d.js",
"static/js/27.5b60be63.chunk.js": "/static/js/27.5b60be63.chunk.js",
"static/media/bootstrap-icons.woff?": "/static/media/bootstrap-icons.4753c5ba57962b4d7bf8.woff",
"static/media/bootstrap-icons.woff2?": "/static/media/bootstrap-icons.6d63d0501e5ed7b79dab.woff2",
"index.html": "/index.html"
},
"entrypoints": [
"static/css/main.1e446194.css",
"static/js/main.94855a25.js"
"static/css/main.c9167014.css",
"static/js/main.e29fa70d.js"
]
}
2 changes: 1 addition & 1 deletion internal/http/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="yuhaiin"/><link rel="apple-touch-icon" href="/static/logo192.png"/><link rel="manifest" href="/static/manifest.json"/><title>ユハイイン</title><script defer="defer" src="/static/js/main.94855a25.js"></script><link href="/static/css/main.1e446194.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="yuhaiin"/><link rel="apple-touch-icon" href="/static/logo192.png"/><link rel="manifest" href="/static/manifest.json"/><title>ユハイイン</title><script defer="defer" src="/static/js/main.e29fa70d.js"></script><link href="/static/css/main.c9167014.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
17 changes: 0 additions & 17 deletions internal/http/build/static/css/main.1e446194.css

This file was deleted.

15 changes: 15 additions & 0 deletions internal/http/build/static/css/main.c9167014.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions internal/http/build/static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "yuhaiin",
"name": "a proxy client for linux/windows/darwin",
"icons": [
{
"src": "static/favicon.ico",
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "static/logo192.png",
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
}
Expand Down
14 changes: 14 additions & 0 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"strings"

"github.com/Asutorufa/yuhaiin/pkg/components/shunt"
"github.com/Asutorufa/yuhaiin/pkg/log"
config "github.com/Asutorufa/yuhaiin/pkg/protos/config/grpc"
snode "github.com/Asutorufa/yuhaiin/pkg/protos/node/grpc"
sstatistic "github.com/Asutorufa/yuhaiin/pkg/protos/statistic/grpc"
"golang.org/x/exp/slog"
)

//go:embed build
Expand Down Expand Up @@ -40,6 +42,7 @@ func Httpserver(o HttpServerOption) {
handlers := Handler{}

mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Debug("http new request", slog.String("method", r.Method), slog.String("path", r.URL.String()))
if strings.HasPrefix(r.URL.Path, "/yuhaiin") {
r.URL.Path = "/"
}
Expand Down Expand Up @@ -137,6 +140,17 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
method = "WS"
}

w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, PATCH, OPTIONS, HEAD")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Token")
w.Header().Set("Access-Control-Expose-Headers", "Access-Control-Allow-Headers, Token")
w.Header().Set("Access-Control-Allow-Credentials", "true")

if method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
return
}

m, ok := p[method]
if !ok {
w.WriteHeader(http.StatusNotFound)
Expand Down
22 changes: 21 additions & 1 deletion pkg/sysproxy/sysproxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sysproxy

import (
"net"
"net/netip"
"strconv"

cb "github.com/Asutorufa/yuhaiin/pkg/protos/config"
"github.com/Asutorufa/yuhaiin/pkg/protos/config/listener"
"google.golang.org/protobuf/proto"
Expand All @@ -24,10 +28,26 @@ func Update(s *cb.Setting) {
socks5 = v.GetSocks5().GetHost()
}
}
SetSysProxy(http, socks5)

SetSysProxy(replaceUnspecified(http), replaceUnspecified(socks5))
server = s.Server
}

func replaceUnspecified(s string) string {
if ip, err := netip.ParseAddrPort(s); err == nil {
if ip.Addr().IsUnspecified() {
if ip.Addr().Is6() {
return net.JoinHostPort(net.IPv6loopback.String(), strconv.Itoa(int(ip.Port())))
} else {
return net.JoinHostPort("127.0.0.1", strconv.Itoa(int(ip.Port())))

}
}
}

return s
}

func Unset() {
UnsetSysProxy()
}

0 comments on commit 9ce6cb3

Please sign in to comment.