This commit is contained in:
Alex Tsai 2022-02-16 21:20:26 +08:00
parent 0dafbc8b98
commit fe522af42b
5 changed files with 16 additions and 12 deletions

View File

@ -28,6 +28,8 @@ Usage of ./vtun:
server address (default ":3001") server address (default ":3001")
-d string -d string
dns address (default "8.8.8.8:53") dns address (default "8.8.8.8:53")
-path string
websocket path (default "/way-to-freedom")
-P enable pporf server on :6060 -P enable pporf server on :6060
-S server mode -S server mode
-g client global mode -g client global mode

View File

@ -8,16 +8,17 @@ import (
) )
type Config struct { type Config struct {
LocalAddr string LocalAddr string
ServerAddr string ServerAddr string
CIDR string CIDR string
Key string Key string
Protocol string Protocol string
DNS string DNS string
ServerMode bool WebSocketPath string
GlobalMode bool ServerMode bool
Obfuscate bool GlobalMode bool
Pprof bool Obfuscate bool
Pprof bool
} }
func (config *Config) Init() { func (config *Config) Init() {

View File

@ -51,7 +51,7 @@ func ConnectServer(config config.Config) net.Conn {
if config.Protocol == "wss" { if config.Protocol == "wss" {
scheme = "wss" scheme = "wss"
} }
u := url.URL{Scheme: scheme, Host: config.ServerAddr, Path: "/way-to-freedom"} u := url.URL{Scheme: scheme, Host: config.ServerAddr, Path: config.WebSocketPath}
header := make(http.Header) header := make(http.Header)
header.Set("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36") header.Set("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36")
header.Set("key", config.Key) header.Set("key", config.Key)

View File

@ -19,6 +19,7 @@ func main() {
flag.StringVar(&config.Key, "k", "6w9z$C&F)J@NcRfWjXn3r4u7x!A%D*G-", "key") flag.StringVar(&config.Key, "k", "6w9z$C&F)J@NcRfWjXn3r4u7x!A%D*G-", "key")
flag.StringVar(&config.Protocol, "p", "wss", "protocol tcp/udp/ws/wss") flag.StringVar(&config.Protocol, "p", "wss", "protocol tcp/udp/ws/wss")
flag.StringVar(&config.DNS, "d", "8.8.8.8:53", "dns address") flag.StringVar(&config.DNS, "d", "8.8.8.8:53", "dns address")
flag.StringVar(&config.WebSocketPath, "path", "/way-to-freedom", "websocket path")
flag.BoolVar(&config.ServerMode, "S", false, "server mode") flag.BoolVar(&config.ServerMode, "S", false, "server mode")
flag.BoolVar(&config.GlobalMode, "g", false, "client global mode") flag.BoolVar(&config.GlobalMode, "g", false, "client global mode")
flag.BoolVar(&config.Obfuscate, "obfs", false, "enable obfuscation") flag.BoolVar(&config.Obfuscate, "obfs", false, "enable obfuscation")

View File

@ -31,7 +31,7 @@ func StartServer(config config.Config) {
// server -> client // server -> client
go toClient(config, iface, c) go toClient(config, iface, c)
// client -> server // client -> server
http.HandleFunc("/way-to-freedom", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc(config.WebSocketPath, func(w http.ResponseWriter, r *http.Request) {
if !checkPermission(w, r, config) { if !checkPermission(w, r, config) {
return return
} }