Files
GoTunnel/cmd/client/main.go
Flik 5a03d9e1f1 feat: remove unused plugin version comparison and types, refactor proxy server to support authentication
- Deleted version comparison logic from `pkg/plugin/sign/version.go`.
- Removed unused types and constants from `pkg/plugin/types.go`.
- Updated `pkg/protocol/message.go` to remove plugin-related message types.
- Enhanced `pkg/proxy/http.go` and `pkg/proxy/socks5.go` to include username/password authentication for HTTP and SOCKS5 proxies.
- Modified `pkg/proxy/server.go` to pass authentication parameters to server constructors.
- Added new API endpoint to generate installation commands with a token for clients.
- Created database functions to manage installation tokens in `internal/server/db/install_token.go`.
- Implemented the installation command generation logic in `internal/server/router/handler/install.go`.
- Updated web frontend to support installation command generation and display in `web/src/views/ClientsView.vue`.
2026-03-17 23:16:30 +08:00

72 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"flag"
"log"
"github.com/gotunnel/internal/client/config"
"github.com/gotunnel/internal/client/tunnel"
"github.com/gotunnel/pkg/crypto"
"github.com/gotunnel/pkg/version"
)
// 版本信息(通过 ldflags 注入)
var Version string
var BuildTime string
var GitCommit string
func init() {
version.SetVersion(Version)
version.SetBuildInfo(GitCommit, BuildTime)
}
func main() {
server := flag.String("s", "", "server address (ip:port)")
token := flag.String("t", "", "auth token")
id := flag.String("id", "", "client id (optional, auto-assigned if empty)")
noTLS := flag.Bool("no-tls", false, "disable TLS")
configPath := flag.String("c", "", "config file path")
flag.Parse()
// 优先加载配置文件
var cfg *config.ClientConfig
if *configPath != "" {
var err error
cfg, err = config.LoadClientConfig(*configPath)
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
} else {
cfg = &config.ClientConfig{}
}
// 命令行参数覆盖配置文件
if *server != "" {
cfg.Server = *server
}
if *token != "" {
cfg.Token = *token
}
if *id != "" {
cfg.ID = *id
}
if *noTLS {
cfg.NoTLS = *noTLS
}
if cfg.Server == "" || cfg.Token == "" {
log.Fatal("Usage: client [-c config.yaml] | [-s <server:port> -t <token> [-id <client_id>] [-no-tls]]")
}
client := tunnel.NewClient(cfg.Server, cfg.Token, cfg.ID)
// TLS 默认启用,默认跳过证书验证(类似 frp
if !cfg.NoTLS {
client.TLSEnabled = true
client.TLSConfig = crypto.ClientTLSConfig()
log.Printf("[Client] TLS enabled")
}
client.Run()
}