Compare commits

..

No commits in common. "main" and "v2" have entirely different histories.
main ... v2

9 changed files with 35 additions and 91 deletions

View File

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

View File

@ -2,7 +2,6 @@ package forward
import (
"git.makemake.in/kzkzzzz/mycommon/mylog"
"log"
"math/rand"
"net"
"time"
@ -37,7 +36,7 @@ func (u *UDP) Forward() error {
}
u.conn = conn
log.Printf("[UDP] [%s] %s -> %s", u.forwardInfo.Name, u.forwardInfo.LocalAddr, u.forwardInfo.TargetAddr)
mylog.Infof("[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-JzuN2dGn.js"></script>
<title>端口转发配置</title>
<script type="module" crossorigin src="./assets/index-lqpwyav5.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BA8XwqWY.css">
</head>
<body>

View File

@ -12,9 +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"
"proxyport/app/forward"
"proxyport/app/model"
@ -31,7 +29,6 @@ type Cfg struct {
ListenAddr string
User string
Password string
WebName string
}
func Start(ctx context.Context) {
@ -51,8 +48,6 @@ 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)
@ -65,7 +60,7 @@ func Start(ctx context.Context) {
}
go func() {
log.Printf("http listen on %s", hs.Addr)
mylog.Infof("http listen on %s", hs.Addr)
mylog.Warn(hs.ListenAndServe())
}()
@ -89,12 +84,6 @@ 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)
@ -280,45 +269,23 @@ func Delete(ctx *gin.Context) {
success(ctx, "ok")
}
var (
hostReg = regexp.MustCompile(`^[a-zA-Z0-9]+[a-zA-Z0-9\-.]*[a-zA-Z]+$`)
letterReg = regexp.MustCompile(`[a-zA-Z\-]`)
emptyReg = regexp.MustCompile(`\s+`)
)
var addrReg = regexp.MustCompile(`^[^:]+:([0-9]{1,5})$`)
func checkAddr(addr string) error {
addr = strings.TrimSpace(addr)
if emptyReg.MatchString(addr) {
return fmt.Errorf("addr format err: %s", addr)
res := addrReg.FindStringSubmatch(addr)
if len(res) != 2 {
return fmt.Errorf("invalid addr: %s", addr)
}
sp := strings.SplitN(addr, ":", 2)
if len(sp) != 2 {
return fmt.Errorf("addr format err: %s", addr)
intPort := cast.ToInt(res[1])
if intPort < 10 || intPort > 65535 {
return fmt.Errorf("port: %d out of range: 10 - 65535", intPort)
}
host := sp[0]
port := sp[1]
intPort := cast.ToInt(port)
if intPort > 65535 || intPort < 10 {
return fmt.Errorf("port [%s] out of range: 10 - 65535", port)
}
if !letterReg.MatchString(host) {
_, err := netip.ParseAddrPort(addr)
if err != nil {
return fmt.Errorf("ip [%s] format err: %s", host, err)
}
return nil
}
if !hostReg.MatchString(host) {
return fmt.Errorf("host [%s] format err", host)
}
//_, err := netip.ParseAddrPort(addr)
//if err != nil {
// return err
//}
return nil
}

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,9 +1,7 @@
<template>
<div>
<div>
<h2>
<span>{{ data.title }}</span>
</h2>
<h2>端口转发</h2>
</div>
<div style="width: 100%;">
@ -11,15 +9,15 @@
</div>
<div>
<el-table :data="data.list" style="width: 100%;" max-height="75vh">
<el-table :data="data.list" style="width: 100%">
<el-table-column align="center" label="协议">
<template #default="scope">
<div v-if="scope.row.protocol === 1">
<el-tag disable-transitions type="success">UDP</el-tag>
<el-tag type="success">UDP</el-tag>
</div>
<div v-else>
<el-tag disable-transitions type="primary">TCP</el-tag>
<el-tag type="primary">TCP</el-tag>
</div>
</template>
</el-table-column>
@ -37,7 +35,7 @@
<el-table-column align="center" label="远程地址">
<template #default="scope">
<div style="white-space: pre-wrap; word-break: break-all">{{ formatList(scope.row.target_addr) }}</div>
<div style="white-space: pre">{{ formatList(scope.row.target_addr) }}</div>
</template>
</el-table-column>
@ -63,8 +61,6 @@
:title="data.form.id > 0 ? '修改': '添加'"
width="600px"
align-center
:close-on-click-modal="false"
:show-close="false"
>
<div>
@ -112,31 +108,17 @@ 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 = {
@ -193,7 +175,7 @@ const getList = async () => {
}
}
// console.log(res)
console.log(res)
}
const confirmConfig = async () => {

View File

@ -4,7 +4,6 @@ import (
"context"
"flag"
"git.makemake.in/kzkzzzz/mycommon/mylog"
"log"
"os"
"os/signal"
"proxyport/app/db"
@ -19,12 +18,10 @@ 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)