Files
GoTunnel/pkg/proxy/server.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

63 lines
1.1 KiB
Go

package proxy
import (
"log"
"net"
)
// Server 代理服务器
type Server struct {
socks5 *SOCKS5Server
http *HTTPServer
listener net.Listener
typ string
}
// NewServer 创建代理服务器
func NewServer(typ string, dialer Dialer, onStats func(in, out int64), username, password string) *Server {
return &Server{
socks5: NewSOCKS5Server(dialer, onStats, username, password),
http: NewHTTPServer(dialer, onStats, username, password),
typ: typ,
}
}
// Run 启动代理服务
func (s *Server) Run(addr string) error {
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
}
s.listener = ln
log.Printf("[Proxy] %s listening on %s", s.typ, addr)
for {
conn, err := ln.Accept()
if err != nil {
return err
}
go s.HandleConn(conn)
}
}
func (s *Server) HandleConn(conn net.Conn) {
var err error
switch s.typ {
case "socks5":
err = s.socks5.HandleConn(conn)
case "http", "https":
err = s.http.HandleConn(conn)
}
if err != nil {
log.Printf("[Proxy] Error: %v", err)
}
}
// Close 关闭服务
func (s *Server) Close() error {
if s.listener != nil {
return s.listener.Close()
}
return nil
}