mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 23:30:26 +08:00
支持UDP代理
This commit is contained in:
@@ -52,6 +52,7 @@ func (this *AddOriginPopupAction) RunPost(params struct {
|
|||||||
PortRange: port,
|
PortRange: port,
|
||||||
},
|
},
|
||||||
Description: "",
|
Description: "",
|
||||||
|
Weight: 10,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -161,6 +161,34 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
tlsConfig.AddListen(addr)
|
tlsConfig.AddListen(addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case serverconfigs.ServerTypeUDPProxy:
|
||||||
|
// 在DEMO模式下不能创建
|
||||||
|
if teaconst.IsDemo {
|
||||||
|
this.Fail("DEMO模式下不能创建UDP反向代理")
|
||||||
|
}
|
||||||
|
|
||||||
|
listen := []*serverconfigs.NetworkAddressConfig{}
|
||||||
|
err := json.Unmarshal([]byte(params.Addresses), &listen)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("端口地址解析失败:" + err.Error())
|
||||||
|
}
|
||||||
|
if len(listen) == 0 {
|
||||||
|
this.Fail("至少需要绑定一个端口")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, addr := range listen {
|
||||||
|
switch addr.Protocol.Primary() {
|
||||||
|
case serverconfigs.ProtocolUDP:
|
||||||
|
if udpConfig == nil {
|
||||||
|
udpConfig = &serverconfigs.UDPProtocolConfig{
|
||||||
|
BaseProtocol: serverconfigs.BaseProtocol{
|
||||||
|
IsOn: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
udpConfig.AddListen(addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
this.Fail("请选择正确的服务类型")
|
this.Fail("请选择正确的服务类型")
|
||||||
}
|
}
|
||||||
@@ -237,7 +265,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
// 源站地址
|
// 源站地址
|
||||||
reverseProxyRefJSON := []byte{}
|
reverseProxyRefJSON := []byte{}
|
||||||
switch params.ServerType {
|
switch params.ServerType {
|
||||||
case serverconfigs.ServerTypeHTTPProxy, serverconfigs.ServerTypeTCPProxy:
|
case serverconfigs.ServerTypeHTTPProxy, serverconfigs.ServerTypeTCPProxy, serverconfigs.ServerTypeUDPProxy:
|
||||||
originConfigs := []*serverconfigs.OriginConfig{}
|
originConfigs := []*serverconfigs.OriginConfig{}
|
||||||
err := json.Unmarshal([]byte(params.Origins), &originConfigs)
|
err := json.Unmarshal([]byte(params.Origins), &originConfigs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,5 +20,19 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
ServerId int64
|
ServerId int64
|
||||||
}) {
|
}) {
|
||||||
// TODO 等看板实现后,需要跳转到看板
|
// TODO 等看板实现后,需要跳转到看板
|
||||||
|
|
||||||
|
// TCP & UDP跳转到设置
|
||||||
|
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serverType := serverTypeResp.Type
|
||||||
|
if serverType == serverconfigs.ServerTypeTCPProxy || serverType == serverconfigs.ServerTypeUDPProxy {
|
||||||
|
this.RedirectURL("/servers/server/settings?serverId=" + strconv.FormatInt(params.ServerId, 10))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP跳转到访问日志
|
||||||
this.RedirectURL("/servers/server/log?serverId=" + strconv.FormatInt(params.ServerId, 10))
|
this.RedirectURL("/servers/server/log?serverId=" + strconv.FormatInt(params.ServerId, 10))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package udp
|
package udp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IndexAction UDP设置
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
}
|
}
|
||||||
@@ -16,7 +22,71 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
ServerId int64
|
ServerId int64
|
||||||
}) {
|
}) {
|
||||||
// TODO
|
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
|
||||||
|
if !isOk {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
udpConfig := &serverconfigs.UDPProtocolConfig{}
|
||||||
|
if len(server.UdpJSON) > 0 {
|
||||||
|
err := json.Unmarshal(server.UdpJSON, udpConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
udpConfig.IsOn = true
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["serverType"] = server.Type
|
||||||
|
this.Data["udpConfig"] = udpConfig
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
ServerId int64
|
||||||
|
ServerType string
|
||||||
|
Addresses string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改代理服务 %d UDP设置", params.ServerId)
|
||||||
|
|
||||||
|
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
|
||||||
|
if !isOk {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
addresses := []*serverconfigs.NetworkAddressConfig{}
|
||||||
|
err := json.Unmarshal([]byte(params.Addresses), &addresses)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("端口地址解析失败:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
udpConfig := &serverconfigs.UDPProtocolConfig{}
|
||||||
|
if len(server.UdpJSON) > 0 {
|
||||||
|
err := json.Unmarshal(server.UdpJSON, udpConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
udpConfig.IsOn = true
|
||||||
|
}
|
||||||
|
udpConfig.Listen = addresses
|
||||||
|
|
||||||
|
configData, err := json.Marshal(udpConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().ServerRPC().UpdateServerUDP(this.AdminContext(), &pb.UpdateServerUDPRequest{
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
UdpJSON: configData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func init() {
|
|||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||||
Helper(serverutils.NewServerHelper()).
|
Helper(serverutils.NewServerHelper()).
|
||||||
Prefix("/servers/server/settings/udp").
|
Prefix("/servers/server/settings/udp").
|
||||||
Get("", new(IndexAction)).
|
GetPost("", new(IndexAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
|||||||
tabbar := actionutils.NewTabbar()
|
tabbar := actionutils.NewTabbar()
|
||||||
tabbar.Add("服务列表", "", "/servers", "", false)
|
tabbar.Add("服务列表", "", "/servers", "", false)
|
||||||
//tabbar.Add("看板", "", "/servers/server/board?serverId="+serverIdString, "dashboard", selectedTabbar == "board")
|
//tabbar.Add("看板", "", "/servers/server/board?serverId="+serverIdString, "dashboard", selectedTabbar == "board")
|
||||||
tabbar.Add("日志", "", "/servers/server/log?serverId="+serverIdString, "history", selectedTabbar == "log")
|
if family == "http" {
|
||||||
|
tabbar.Add("日志", "", "/servers/server/log?serverId="+serverIdString, "history", selectedTabbar == "log")
|
||||||
|
}
|
||||||
if family == "http" {
|
if family == "http" {
|
||||||
tabbar.Add("统计", "", "/servers/server/stat?serverId="+serverIdString, "chart area", selectedTabbar == "stat")
|
tabbar.Add("统计", "", "/servers/server/stat?serverId="+serverIdString, "chart area", selectedTabbar == "stat")
|
||||||
}
|
}
|
||||||
@@ -350,6 +352,12 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
|||||||
"isActive": secondMenuItem == "udp",
|
"isActive": secondMenuItem == "udp",
|
||||||
"isOn": serverConfig.UDP != nil && serverConfig.UDP.IsOn && len(serverConfig.UDP.Listen) > 0,
|
"isOn": serverConfig.UDP != nil && serverConfig.UDP.IsOn && len(serverConfig.UDP.Listen) > 0,
|
||||||
})
|
})
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "反向代理",
|
||||||
|
"url": "/servers/server/settings/reverseProxy?serverId=" + serverIdString,
|
||||||
|
"isActive": secondMenuItem == "reverseProxy",
|
||||||
|
"isOn": serverConfig.ReverseProxyRef != nil && serverConfig.ReverseProxyRef.IsOn,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return menuItems
|
return menuItems
|
||||||
|
|||||||
@@ -18,6 +18,11 @@
|
|||||||
<option value="tcp">TCP</option>
|
<option value="tcp">TCP</option>
|
||||||
<option value="tls">TLS</option>
|
<option value="tls">TLS</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- UDP -->
|
||||||
|
<select class="ui dropdown auto-width" name="protocol" v-if="serverType == 'udpProxy'">
|
||||||
|
<option value="udp">UDP</option>
|
||||||
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -20,6 +20,11 @@
|
|||||||
<option value="tcp">TCP</option>
|
<option value="tcp">TCP</option>
|
||||||
<option value="tls">TLS</option>
|
<option value="tls">TLS</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- UDP -->
|
||||||
|
<select class="ui dropdown auto-width" name="protocol" v-if="serverType == 'udpProxy'">
|
||||||
|
<option value="udp">UDP</option>
|
||||||
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
<option value="tcp">TCP</option>
|
<option value="tcp">TCP</option>
|
||||||
<option value="tls">TLS</option>
|
<option value="tls">TLS</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- UDP -->
|
||||||
|
<select class="ui dropdown auto-width" name="protocol" v-model="origin.protocol" v-if="serverType == 'udpProxy'">
|
||||||
|
<option value="udp">UDP</option>
|
||||||
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
{$layout}
|
{$layout}
|
||||||
|
|
||||||
{$template "/left_menu"}
|
{$template "/left_menu"}
|
||||||
|
|
||||||
<div class="right-box">
|
<div class="right-box">
|
||||||
<p class="ui message">此功能暂未开放,敬请期待。</p>
|
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<input type="hidden" name="serverId" :value="serverId"/>
|
||||||
|
<input type="hidden" name="serverType" :value="serverType"/>
|
||||||
|
<table class="ui table selectable definition">
|
||||||
|
<tr>
|
||||||
|
<td class="title">绑定端口 *</td>
|
||||||
|
<td>
|
||||||
|
<network-addresses-box :v-server-type="serverType" :v-addresses="udpConfig.listen" :v-protocol="'udp'"></network-addresses-box>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
3
web/views/@default/servers/server/settings/udp/index.js
Normal file
3
web/views/@default/servers/server/settings/udp/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifyReloadSuccess("保存成功")
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user