update
							parent
							
								
									36d32e7222
								
							
						
					
					
						commit
						676aa5bdcb
					
				| 
						 | 
					@ -5,6 +5,7 @@ import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"git.makemake.in/kzkzzzz/mycommon/mylog"
 | 
						"git.makemake.in/kzkzzzz/mycommon/mylog"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
| 
						 | 
					@ -61,7 +62,7 @@ func (t *TCP) Forward() error {
 | 
				
			||||||
	//listener, err := lc.Listen(ctx0, "tcp", t.forwardInfo.LocalAddr)
 | 
						//listener, err := lc.Listen(ctx0, "tcp", t.forwardInfo.LocalAddr)
 | 
				
			||||||
	// 启动 TCP 监听
 | 
						// 启动 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() {
 | 
						go func() {
 | 
				
			||||||
		ctx, cancelCtx := context.WithCancel(context.Background())
 | 
							ctx, cancelCtx := context.WithCancel(context.Background())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ package forward
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"git.makemake.in/kzkzzzz/mycommon/mylog"
 | 
						"git.makemake.in/kzkzzzz/mycommon/mylog"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
| 
						 | 
					@ -36,7 +37,7 @@ func (u *UDP) Forward() error {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	u.conn = conn
 | 
						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() {
 | 
						go func() {
 | 
				
			||||||
		err := u.handleConn(conn)
 | 
							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
											
										
									
								
							| 
						 | 
					@ -3,8 +3,8 @@
 | 
				
			||||||
  <head>
 | 
					  <head>
 | 
				
			||||||
    <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-51cHkXnS.js"></script>
 | 
					    <script type="module" crossorigin src="./assets/index-JzuN2dGn.js"></script>
 | 
				
			||||||
    <link rel="stylesheet" crossorigin href="./assets/index-BA8XwqWY.css">
 | 
					    <link rel="stylesheet" crossorigin href="./assets/index-BA8XwqWY.css">
 | 
				
			||||||
  </head>
 | 
					  </head>
 | 
				
			||||||
  <body>
 | 
					  <body>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@ import (
 | 
				
			||||||
	enTr "github.com/go-playground/validator/v10/translations/en"
 | 
						enTr "github.com/go-playground/validator/v10/translations/en"
 | 
				
			||||||
	"github.com/spf13/cast"
 | 
						"github.com/spf13/cast"
 | 
				
			||||||
	"gorm.io/gorm"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"net/netip"
 | 
						"net/netip"
 | 
				
			||||||
	"proxyport/app/db"
 | 
						"proxyport/app/db"
 | 
				
			||||||
| 
						 | 
					@ -30,6 +31,7 @@ type Cfg struct {
 | 
				
			||||||
	ListenAddr string
 | 
						ListenAddr string
 | 
				
			||||||
	User       string
 | 
						User       string
 | 
				
			||||||
	Password   string
 | 
						Password   string
 | 
				
			||||||
 | 
						WebName    string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Start(ctx context.Context) {
 | 
					func Start(ctx context.Context) {
 | 
				
			||||||
| 
						 | 
					@ -49,6 +51,8 @@ func Start(ctx context.Context) {
 | 
				
			||||||
	engine.GET("/", func(ctx *gin.Context) {
 | 
						engine.GET("/", func(ctx *gin.Context) {
 | 
				
			||||||
		ctx.HTML(http.StatusOK, "index.html", nil)
 | 
							ctx.HTML(http.StatusOK, "index.html", nil)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						engine.GET("/GetConfig", GetConfig)
 | 
				
			||||||
	engine.GET("/List", List)
 | 
						engine.GET("/List", List)
 | 
				
			||||||
	engine.POST("/Create", Create)
 | 
						engine.POST("/Create", Create)
 | 
				
			||||||
	engine.POST("/Update", Update)
 | 
						engine.POST("/Update", Update)
 | 
				
			||||||
| 
						 | 
					@ -61,7 +65,7 @@ func Start(ctx context.Context) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		mylog.Infof("http listen on %s", hs.Addr)
 | 
							log.Printf("http listen on %s", hs.Addr)
 | 
				
			||||||
		mylog.Warn(hs.ListenAndServe())
 | 
							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) {
 | 
					func List(ctx *gin.Context) {
 | 
				
			||||||
	data := make([]*model.Forward, 0)
 | 
						data := make([]*model.Forward, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -271,7 +281,7 @@ func Delete(ctx *gin.Context) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					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\-]`)
 | 
						letterReg = regexp.MustCompile(`[a-zA-Z\-]`)
 | 
				
			||||||
	emptyReg  = regexp.MustCompile(`\s+`)
 | 
						emptyReg  = regexp.MustCompile(`\s+`)
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -284,6 +294,11 @@ func checkAddr(addr string) error {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sp := strings.SplitN(addr, ":", 2)
 | 
						sp := strings.SplitN(addr, ":", 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(sp) != 2 {
 | 
				
			||||||
 | 
							return fmt.Errorf("addr format err: %s", addr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	host := sp[0]
 | 
						host := sp[0]
 | 
				
			||||||
	port := sp[1]
 | 
						port := sp[1]
 | 
				
			||||||
	intPort := cast.ToInt(port)
 | 
						intPort := cast.ToInt(port)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@
 | 
				
			||||||
  <head>
 | 
					  <head>
 | 
				
			||||||
    <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>
 | 
				
			||||||
  </head>
 | 
					  </head>
 | 
				
			||||||
  <body>
 | 
					  <body>
 | 
				
			||||||
    <div id="app"></div>
 | 
					    <div id="app"></div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,9 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div>
 | 
					  <div>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
      <h2>端口转发</h2>
 | 
					      <h2>
 | 
				
			||||||
 | 
					        <span>{{ data.title }}</span>
 | 
				
			||||||
 | 
					      </h2>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div style="width: 100%;">
 | 
					    <div style="width: 100%;">
 | 
				
			||||||
| 
						 | 
					@ -35,7 +37,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <el-table-column align="center" label="远程地址">
 | 
					        <el-table-column align="center" label="远程地址">
 | 
				
			||||||
          <template #default="scope">
 | 
					          <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>
 | 
					          </template>
 | 
				
			||||||
        </el-table-column>
 | 
					        </el-table-column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,17 +112,31 @@ import {onMounted, reactive} from "vue";
 | 
				
			||||||
import http from "@/helper/http.js";
 | 
					import http from "@/helper/http.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const data = reactive({
 | 
					const data = reactive({
 | 
				
			||||||
 | 
					  title: "端口转发",
 | 
				
			||||||
  list: [],
 | 
					  list: [],
 | 
				
			||||||
  dialogVisible: false,
 | 
					  dialogVisible: false,
 | 
				
			||||||
  form: {
 | 
					  form: {
 | 
				
			||||||
    protocol: 0,
 | 
					    protocol: 0,
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
 | 
					  config: {}
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
onMounted(() => {
 | 
					onMounted(() => {
 | 
				
			||||||
 | 
					  getConfig()
 | 
				
			||||||
  getList()
 | 
					  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 = () => {
 | 
					const createForward = () => {
 | 
				
			||||||
  data.dialogVisible = true
 | 
					  data.dialogVisible = true
 | 
				
			||||||
  data.form = {
 | 
					  data.form = {
 | 
				
			||||||
| 
						 | 
					@ -177,7 +193,7 @@ const getList = async () => {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  console.log(res)
 | 
					  // console.log(res)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const confirmConfig = async () => {
 | 
					const confirmConfig = async () => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								main.go
								
								
								
								
							
							
						
						
									
										3
									
								
								main.go
								
								
								
								
							| 
						 | 
					@ -4,6 +4,7 @@ import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"git.makemake.in/kzkzzzz/mycommon/mylog"
 | 
						"git.makemake.in/kzkzzzz/mycommon/mylog"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/signal"
 | 
						"os/signal"
 | 
				
			||||||
	"proxyport/app/db"
 | 
						"proxyport/app/db"
 | 
				
			||||||
| 
						 | 
					@ -18,10 +19,12 @@ var (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
 | 
						log.SetOutput(os.Stdout)
 | 
				
			||||||
	flag.StringVar(&logLevel, "log_level", "debug", "log level")
 | 
						flag.StringVar(&logLevel, "log_level", "debug", "log level")
 | 
				
			||||||
	flag.StringVar(&web.Config.ListenAddr, "listen_addr", ":28083", "web port")
 | 
						flag.StringVar(&web.Config.ListenAddr, "listen_addr", ":28083", "web port")
 | 
				
			||||||
	flag.StringVar(&web.Config.User, "user", "", "web user")
 | 
						flag.StringVar(&web.Config.User, "user", "", "web user")
 | 
				
			||||||
	flag.StringVar(&web.Config.Password, "password", "", "web password")
 | 
						flag.StringVar(&web.Config.Password, "password", "", "web password")
 | 
				
			||||||
 | 
						flag.StringVar(&web.Config.WebName, "web_name", "", "web name")
 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mylog.SetLogLevel(logLevel)
 | 
						mylog.SetLogLevel(logLevel)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue