main
lzf 2025-09-26 14:32:03 +08:00
parent 676aa5bdcb
commit 2b2faec437
8 changed files with 47 additions and 19 deletions

View File

@ -17,14 +17,17 @@ func (p Protocol) String() string {
return "TCP" return "TCP"
case 1: case 1:
return "UDP" return "UDP"
case 2:
return "TCP-TLS"
} }
return "unknown" return "unknown"
} }
const ( const (
ProtocolTCP Protocol = 0 ProtocolTCP Protocol = 0
ProtocolUDP Protocol = 1 ProtocolUDP Protocol = 1
ProtocolTCPTLS Protocol = 2
) )
type IForward interface { type IForward interface {

View File

@ -2,6 +2,7 @@ package forward
import ( import (
"context" "context"
"crypto/tls"
"fmt" "fmt"
"git.makemake.in/kzkzzzz/mycommon/mylog" "git.makemake.in/kzkzzzz/mycommon/mylog"
"io" "io"
@ -88,12 +89,26 @@ func (t *TCP) handleConn(mainCtx context.Context, localConn net.Conn, targetAddr
targetAddr := targetAddrList[rand.Intn(len(targetAddrList))] targetAddr := targetAddrList[rand.Intn(len(targetAddrList))]
// 连接到目标地址 var (
targetConn, err := net.Dial("tcp", targetAddr) targetConn net.Conn
if err != nil { err error
mylog.Error("Error connecting to target:", err) )
return
switch t.forwardInfo.Protocol {
case ProtocolTCPTLS:
targetConn, err = tls.Dial("tcp", targetAddr, &tls.Config{
InsecureSkipVerify: true,
})
default:
targetConn, err = net.Dial("tcp", targetAddr)
if err != nil {
mylog.Error("Error connecting to target:", err)
return
}
} }
defer targetConn.Close() defer targetConn.Close()
ctx, cancelCtx := context.WithCancel(context.Background()) ctx, cancelCtx := context.WithCancel(context.Background())

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>端口转发</title> <title>端口转发</title>
<script type="module" crossorigin src="./assets/index-JzuN2dGn.js"></script> <script type="module" crossorigin src="./assets/index-PO_Ka5xU.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BA8XwqWY.css"> <link rel="stylesheet" crossorigin href="./assets/index-BA8XwqWY.css">
</head> </head>
<body> <body>

View File

@ -111,7 +111,7 @@ func Create(ctx *gin.Context) {
TargetAddr string `json:"target_addr" binding:"min=1"` TargetAddr string `json:"target_addr" binding:"min=1"`
LocalPort int `json:"local_port" binding:"required"` LocalPort int `json:"local_port" binding:"required"`
Name string `json:"name" binding:"required"` Name string `json:"name" binding:"required"`
ForwardType int `json:"protocol" binding:"oneof=0 1"` ForwardType int `json:"protocol"`
Status int `json:"status" binding:"oneof=0 1"` Status int `json:"status" binding:"oneof=0 1"`
} }
@ -180,7 +180,7 @@ func Update(ctx *gin.Context) {
TargetAddr string `json:"target_addr" binding:"min=1"` TargetAddr string `json:"target_addr" binding:"min=1"`
LocalPort int `json:"local_port" binding:"required"` LocalPort int `json:"local_port" binding:"required"`
Name string `json:"name" binding:"required"` Name string `json:"name" binding:"required"`
Protocol int `json:"protocol" binding:"oneof=0 1"` Protocol int `json:"protocol"`
Status int `json:"status" binding:"oneof=0 1"` Status int `json:"status" binding:"oneof=0 1"`
} }

View File

@ -18,6 +18,10 @@
<el-tag disable-transitions type="success">UDP</el-tag> <el-tag disable-transitions type="success">UDP</el-tag>
</div> </div>
<div v-else-if="scope.row.protocol === 2">
<el-tag disable-transitions type="success">TCP-TLS</el-tag>
</div>
<div v-else> <div v-else>
<el-tag disable-transitions type="primary">TCP</el-tag> <el-tag disable-transitions type="primary">TCP</el-tag>
</div> </div>
@ -75,6 +79,7 @@
<el-radio-group v-model="data.form.protocol"> <el-radio-group v-model="data.form.protocol">
<el-radio :value="0">TCP</el-radio> <el-radio :value="0">TCP</el-radio>
<el-radio :value="1">UDP</el-radio> <el-radio :value="1">UDP</el-radio>
<el-radio :value="2">TCP-TLS</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>

View File

@ -5,7 +5,12 @@ set -e
case $1 in case $1 in
"backend") "backend")
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o temp/proxyport.linux main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o temp/proxyport.linux main.go
scp -P 5566 temp/proxyport.linux kzkzzzz@193.32.149.42:temp/proxyport/proxyport.linux # scp -P 5566 temp/proxyport.linux kzkzzzz@193.32.149.42:temp/proxyport/proxyport.linux
wsl -d Debian -e bash -c "rsync -rvz -P -e 'ssh -p 22' temp/proxyport.linux zifeng.li@rta-kiwi.test:temp/proxyport/"
;;
"pi5")
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -v -o temp/proxyport.arm64 main.go
scp temp/proxyport.arm64 pi@100.93.0.65:temp/proxyport/proxyport.arm64
;; ;;
"frontend") "frontend")
cd frontend cd frontend