main
lzf 2024-10-10 10:53:08 +08:00
parent 36d32e7222
commit 676aa5bdcb
9 changed files with 58 additions and 22 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"git.makemake.in/kzkzzzz/mycommon/mylog"
"io"
"log"
"math/rand"
"net"
"time"
@ -61,7 +62,7 @@ func (t *TCP) Forward() error {
//listener, err := lc.Listen(ctx0, "tcp", t.forwardInfo.LocalAddr)
// 启动 TCP 监听
mylog.Infof("[TCP] %s %s -> %s", t.forwardInfo.Name, t.forwardInfo.LocalAddr, t.forwardInfo.TargetAddr)
log.Printf("[TCP] [%s] %s -> %s", t.forwardInfo.Name, t.forwardInfo.LocalAddr, t.forwardInfo.TargetAddr)
go func() {
ctx, cancelCtx := context.WithCancel(context.Background())

View File

@ -2,6 +2,7 @@ package forward
import (
"git.makemake.in/kzkzzzz/mycommon/mylog"
"log"
"math/rand"
"net"
"time"
@ -36,7 +37,7 @@ func (u *UDP) Forward() error {
}
u.conn = conn
mylog.Infof("[UDP] %s %s -> %s", u.forwardInfo.Name, u.forwardInfo.LocalAddr, u.forwardInfo.TargetAddr)
log.Printf("[UDP] [%s] %s -> %s", u.forwardInfo.Name, u.forwardInfo.LocalAddr, u.forwardInfo.TargetAddr)
go func() {
err := u.handleConn(conn)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

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

View File

@ -12,6 +12,7 @@ import (
enTr "github.com/go-playground/validator/v10/translations/en"
"github.com/spf13/cast"
"gorm.io/gorm"
"log"
"net/http"
"net/netip"
"proxyport/app/db"
@ -30,6 +31,7 @@ type Cfg struct {
ListenAddr string
User string
Password string
WebName string
}
func Start(ctx context.Context) {
@ -49,6 +51,8 @@ func Start(ctx context.Context) {
engine.GET("/", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "index.html", nil)
})
engine.GET("/GetConfig", GetConfig)
engine.GET("/List", List)
engine.POST("/Create", Create)
engine.POST("/Update", Update)
@ -61,7 +65,7 @@ func Start(ctx context.Context) {
}
go func() {
mylog.Infof("http listen on %s", hs.Addr)
log.Printf("http listen on %s", hs.Addr)
mylog.Warn(hs.ListenAndServe())
}()
@ -85,6 +89,12 @@ func cors() gin.HandlerFunc {
}
}
func GetConfig(ctx *gin.Context) {
success(ctx, gin.H{
"web_name": Config.WebName,
})
}
func List(ctx *gin.Context) {
data := make([]*model.Forward, 0)
@ -271,7 +281,7 @@ func Delete(ctx *gin.Context) {
}
var (
hostReg = regexp.MustCompile(`^[a-zA-Z0-9]+[a-zA-Z0-9.]*[a-zA-Z]+$`)
hostReg = regexp.MustCompile(`^[a-zA-Z0-9]+[a-zA-Z0-9\-.]*[a-zA-Z]+$`)
letterReg = regexp.MustCompile(`[a-zA-Z\-]`)
emptyReg = regexp.MustCompile(`\s+`)
)
@ -284,6 +294,11 @@ func checkAddr(addr string) error {
}
sp := strings.SplitN(addr, ":", 2)
if len(sp) != 2 {
return fmt.Errorf("addr format err: %s", addr)
}
host := sp[0]
port := sp[1]
intPort := cast.ToInt(port)

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>端口转发配置</title>
<title>端口转发</title>
</head>
<body>
<div id="app"></div>

View File

@ -1,7 +1,9 @@
<template>
<div>
<div>
<h2>端口转发</h2>
<h2>
<span>{{ data.title }}</span>
</h2>
</div>
<div style="width: 100%;">
@ -35,7 +37,7 @@
<el-table-column align="center" label="远程地址">
<template #default="scope">
<div style="white-space: pre">{{ formatList(scope.row.target_addr) }}</div>
<div style="white-space: pre-wrap; word-break: break-all">{{ formatList(scope.row.target_addr) }}</div>
</template>
</el-table-column>
@ -110,17 +112,31 @@ import {onMounted, reactive} from "vue";
import http from "@/helper/http.js";
const data = reactive({
title: "端口转发",
list: [],
dialogVisible: false,
form: {
protocol: 0,
}
},
config: {}
})
onMounted(() => {
getConfig()
getList()
})
const getConfig = async () => {
let res = await http.get("/GetConfig")
data.config = res.data.data
if (data.config.web_name !== "") {
data.title = `端口转发 - ${data.config.web_name}`
}
document.title = data.title
}
const createForward = () => {
data.dialogVisible = true
data.form = {
@ -177,7 +193,7 @@ const getList = async () => {
}
}
console.log(res)
// console.log(res)
}
const confirmConfig = async () => {

View File

@ -4,6 +4,7 @@ import (
"context"
"flag"
"git.makemake.in/kzkzzzz/mycommon/mylog"
"log"
"os"
"os/signal"
"proxyport/app/db"
@ -18,10 +19,12 @@ var (
)
func main() {
log.SetOutput(os.Stdout)
flag.StringVar(&logLevel, "log_level", "debug", "log level")
flag.StringVar(&web.Config.ListenAddr, "listen_addr", ":28083", "web port")
flag.StringVar(&web.Config.User, "user", "", "web user")
flag.StringVar(&web.Config.Password, "password", "", "web password")
flag.StringVar(&web.Config.WebName, "web_name", "", "web name")
flag.Parse()
mylog.SetLogLevel(logLevel)