Sfoglia il codice sorgente

完善几个小功能

tavenli 5 anni fa
parent
commit
0a89a866b0

+ 11 - 8
.vscode/settings.json

@@ -3,7 +3,6 @@
     "go.alternateTools": {
     
     },
-    "go.useLanguageServer": true,
     "[go]": {
         "editor.formatOnSave": true,
         "editor.codeActionsOnSave": {
@@ -18,12 +17,16 @@
             "source.organizeImports": true,
         },
     },
-    "gopls": {
-        // Add parameter placeholders when completing a function.
-        "usePlaceholders": true,
+    "go.gotoSymbol.includeImports": true,
+    "go.gotoSymbol.includeGoroot": true,
+    "go.languageServerExperimentalFeatures": {
 
-        // If true, enable additional analyses with staticcheck.
-        // Warning: This will significantly increase memory usage.
-        "staticcheck": false,
-    }
+        "diagnostics": true,
+        "documentLink": true
+    },
+    "go.trace.server": "verbose",
+    "go.overwriteGoplsMiddleware": {
+    
+    },
+    "go.useLanguageServer": true
 }

+ 14 - 3
forward-server/Controllers/ForwardCtrl.go

@@ -29,9 +29,11 @@ func (c *ForwardCtrl) ForwardListJson() {
 	pageParam.PSize, _ = c.GetInt64("pSize")
 
 	port, _ := c.GetInt("port")
+	targetPort, _ := c.GetInt("targetPort")
 
 	query := &Models.PortForward{}
 	query.Port = port
+	query.TargetPort = targetPort
 	query.FType = -1
 
 	pageData := Service.SysDataS.GetPortForwardList(query, pageParam.PIndex, pageParam.PSize)
@@ -56,6 +58,7 @@ func (c *ForwardCtrl) ForwardListJson() {
 func (c *ForwardCtrl) AddForward() {
 
 	entity := Models.PortForward{}
+	entity.Status = 1
 
 	c.Data["entity"] = entity
 
@@ -126,9 +129,10 @@ func (c *ForwardCtrl) SaveForward() {
 
 	if Utils.IsEmpty(name) {
 		//
-		c.Data["json"] = Models.FuncResult{Code: 1, Msg: "名称 不能为空"}
-		c.ServeJSON()
-		return
+		//c.Data["json"] = Models.FuncResult{Code: 1, Msg: "名称 不能为空"}
+		//c.ServeJSON()
+		//return
+		name = "-"
 	}
 
 	if port < 0 || port > 65535 {
@@ -152,6 +156,13 @@ func (c *ForwardCtrl) SaveForward() {
 		return
 	}
 
+	if status != 0 && status != 1 {
+		//
+		c.Data["json"] = Models.FuncResult{Code: 1, Msg: "输入的 启用/禁用 值不正确"}
+		c.ServeJSON()
+		return
+	}
+
 	// if Utils.IsNotEmpty(others) {
 	// 	//如果有others信息,则检查
 

+ 4 - 0
forward-server/Service/SysDataService.go

@@ -194,6 +194,10 @@ func (_self *SysDataService) GetPortForwardList(query *Models.PortForward, pageI
 		qs = qs.Filter("Port", query.Port)
 	}
 
+	if query.TargetPort > 0 {
+		qs = qs.Filter("TargetPort", query.TargetPort)
+	}
+
 	if query.FType > -1 {
 		qs = qs.Filter("FType", query.FType)
 	}

BIN
forward-server/data/data.db


+ 5 - 1
forward-server/views/ucenter/forwardForm.html

@@ -58,7 +58,7 @@
       </div>
     </div>
     <div class="layui-form-item">
-      <label class="layui-form-label">是否用</label>
+      <label class="layui-form-label">是否用</label>
       <div class="layui-input-inline">
         <input type="text" name="status" value="{{.entity.Status}}" lay-verify="required" placeholder="0:禁用,1:开启" autocomplete="off" class="layui-input">
       </div>
@@ -69,6 +69,10 @@
 如果不需要“多分发”,请留空;
 如果需要分发到多个端口,填写格式为 “IP:端口”,多个用 ; 号隔开
 如 192.1.1.100:8081;192.1.1.100:8082
+
+*是否启用说明(可让程序每次运行后就开始转发该规则):
+0:禁用,1:启用
+
         </pre> 
     </div>
   </form>

+ 71 - 4
forward-server/views/ucenter/forwardList.html

@@ -1,10 +1,37 @@
 <div class="layui-tab layui-tab-card">
+  
   <ul class="layui-tab-title">
     <li class="layui-this">端口转发列表</li>
     <li>帮助说明</li>
   </ul>
   <div class="layui-tab-content" style="height: auto;">
+
+    
     <div class="layui-tab-item layui-show">
+      
+      <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
+        <div class="layui-form-item">
+          <div class="layui-inline">
+            <label class="layui-form-label">本地端口</label>
+            <div class="layui-input-inline">
+              <input type="text" id="port" name="port" placeholder="本地监听端口" autocomplete="off" class="layui-input">
+            </div>
+          </div>
+          <div class="layui-inline">
+            <label class="layui-form-label">目标端口</label>
+            <div class="layui-input-inline">
+              <input type="text" id="targetPort" name="targetPort" placeholder="转发到端口" autocomplete="off" class="layui-input">
+            </div>
+          </div>
+
+          <div class="layui-inline">
+            <button class="layui-btn layuiadmin-btn-list" onclick="query(1);">
+              查询
+            </button>
+          </div>
+        </div>
+      </div>
+
       <button class="layui-btn layui-btn-small" onclick="addForward();"><i class="layui-icon"></i> 添加转发</button>
       <button class="layui-btn layui-btn-small" onclick="delForward();"><i class="layui-icon"></i> 批量删除</button>
       <div class="layui-form">
@@ -47,7 +74,7 @@
     </div>
     <div class="layui-tab-item">
       <pre class="layui-code">
-说明文档请访问:<a href="https://github.com/tavenli/port-forward" target="_blank">https://github.com/tavenli/port-forward</a>
+说明文档请访问:<a href="https://gitee.com/tavenli/port-forward" target="_blank">https://gitee.com/tavenli/port-forward</a>
 
 使用问题或个性化需求可加QQ号:17020415 (申请时请备注:端口转发)
             </pre>
@@ -58,7 +85,7 @@
   {Start{# if(d.Data === null || d.Data.length === 0){ }End}
   <tr>
     <td colspan="10">
-      请先添加一条端口转发配置规则
+      查询转发配置规则结果为空
     </td>
   </tr>
   {Start{# } else { }End} {Start{# layui.each(d.Data, function(index, item){ }End}
@@ -106,7 +133,12 @@ $(document).ready(function() {
 function query(pIndex) {
   // var columnFiled = $("#columnFiled").val();
   // var keyWord = $("#keyWord").val();
+  var port = $("#port").val();
+  var targetPort = $("#targetPort").val();
+
   $.post("ForwardList/json", {
+    port: port,
+    targetPort: targetPort,
     pIndex: pIndex,
     pSize: 10
   }, function(json) {
@@ -288,7 +320,7 @@ function refreshGrid() {
   query(1);
 }
 
-function OpenForward(id) {
+function OpenForward2(id) {
   layer.confirm("确定启动该转发吗?", {
     btn: ['确定', '取消'] //按钮
   }, function(index, layero) {
@@ -309,7 +341,7 @@ function OpenForward(id) {
   });
 }
 
-function CloseForward(id) {
+function CloseForward2(id) {
   layer.confirm("确定停止该转发吗?", {
     btn: ['确定', '取消'] //按钮
   }, function(index, layero) {
@@ -329,4 +361,39 @@ function CloseForward(id) {
     }, 'json');
   });
 }
+
+function OpenForward(id) {
+  $.post("/u/OpenForward", {
+      rnd: Math.random(),
+      id: id
+    }, function(json) {
+      if (json.Code == 0) { //成功
+        layer.msg("执行成功.");
+        query(1);
+      } else { //失败
+        layer.alert(json.Msg, {
+          icon: 2
+        });
+        query(1);
+      }
+    }, 'json');
+}
+
+function CloseForward(id) {
+  $.post("/u/CloseForward", {
+      rnd: Math.random(),
+      id: id
+    }, function(json) {
+      if (json.Code == 0) { //成功
+        layer.msg("执行成功.");
+        query(1);
+      } else { //失败
+        layer.alert(json.Msg, {
+          icon: 2
+        });
+        query(1);
+      }
+    }, 'json');
+}
+
 </script>

+ 2 - 0
go.mod

@@ -1,3 +1,5 @@
 module port-forward
 
 go 1.14
+
+require golang.org/x/tools/gopls v0.5.1 // indirect

+ 64 - 0
go.sum

@@ -0,0 +1,64 @@
+github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
+github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
+github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
+github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
+github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
+github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
+golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
+golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
+golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200731060945-b5fad4ed8dd6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
+golang.org/x/tools v0.0.0-20200930165741-f1523d29dbb9 h1:1R38tQp22dcHpTKJPjgVa16FhlDy/kHEaCM/ndi/FIc=
+golang.org/x/tools v0.0.0-20200930165741-f1523d29dbb9/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
+golang.org/x/tools v0.0.0-20201014231627-1610a49f37af h1:VIUWFyOgzG3c0t9KYop5Ybp4m56LupfOnFYX7Ipnz+I=
+golang.org/x/tools/gopls v0.5.1 h1:AF3Uh7HF08SZpKFfgJO6zfF3bbxyDXWqdkK4kMXiQ1o=
+golang.org/x/tools/gopls v0.5.1/go.mod h1:6o4z8hIK5Ef1f7mLl0oxi5+SaYAw0rfyo6YZ7TcAfRY=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+honnef.co/go/tools v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=
+honnef.co/go/tools v0.0.1-2020.1.5/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
+mvdan.cc/gofumpt v0.0.0-20200802201014-ab5a8192947d h1:t8TAw9WgTLghti7RYkpPmqk4JtQ3+wcP5GgZqgWeWLQ=
+mvdan.cc/gofumpt v0.0.0-20200802201014-ab5a8192947d/go.mod h1:bzrjFmaD6+xqohD3KYP0H2FEuxknnBmyyOxdhLdaIws=
+mvdan.cc/xurls/v2 v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
+mvdan.cc/xurls/v2 v2.2.0/go.mod h1:EV1RMtya9D6G5DMYPGD8zTQzaHet6Jh8gFlRgGRJeO8=

粤ICP备19079148号