mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	将全局设置的TCP相关设置移到“集群设置--网站设置”中
This commit is contained in:
		@@ -122,6 +122,11 @@ func (this *IndexAction) RunPost(params struct {
 | 
			
		||||
	PerformanceAutoWriteTimeout bool
 | 
			
		||||
	PerformanceDebug            bool
 | 
			
		||||
 | 
			
		||||
	// TCP端口设置
 | 
			
		||||
	TcpAllPortRangeMin int
 | 
			
		||||
	TcpAllPortRangeMax int
 | 
			
		||||
	TcpAllDenyPorts    []int
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
	CSRF *actionutils.CSRF
 | 
			
		||||
}) {
 | 
			
		||||
@@ -197,6 +202,23 @@ func (this *IndexAction) RunPost(params struct {
 | 
			
		||||
	// 日志
 | 
			
		||||
	config.Log.RecordServerError = params.LogRecordServerError
 | 
			
		||||
 | 
			
		||||
	// TCP
 | 
			
		||||
	if params.TcpAllPortRangeMin < 1024 {
 | 
			
		||||
		params.TcpAllPortRangeMin = 1024
 | 
			
		||||
	}
 | 
			
		||||
	if params.TcpAllPortRangeMax > 65534 {
 | 
			
		||||
		params.TcpAllPortRangeMax = 65534
 | 
			
		||||
	} else if params.TcpAllPortRangeMax < 1024 {
 | 
			
		||||
		params.TcpAllPortRangeMax = 1024
 | 
			
		||||
	}
 | 
			
		||||
	if params.TcpAllPortRangeMin > params.TcpAllPortRangeMax {
 | 
			
		||||
		params.TcpAllPortRangeMin, params.TcpAllPortRangeMax = params.TcpAllPortRangeMax, params.TcpAllPortRangeMin
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config.TCPAll.DenyPorts = params.TcpAllDenyPorts
 | 
			
		||||
	config.TCPAll.PortRangeMin = params.TcpAllPortRangeMin
 | 
			
		||||
	config.TCPAll.PortRangeMax = params.TcpAllPortRangeMax
 | 
			
		||||
 | 
			
		||||
	// 性能
 | 
			
		||||
	config.Performance.AutoReadTimeout = params.PerformanceAutoReadTimeout
 | 
			
		||||
	config.Performance.AutoWriteTimeout = params.PerformanceAutoWriteTimeout
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +0,0 @@
 | 
			
		||||
package components
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Helper struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewHelper() *Helper {
 | 
			
		||||
	return &Helper{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Helper) BeforeAction(action *actions.ActionObject) {
 | 
			
		||||
	action.Data["teaMenu"] = "servers"
 | 
			
		||||
}
 | 
			
		||||
@@ -1,115 +0,0 @@
 | 
			
		||||
package components
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	SettingCodeServerGlobalConfig = "serverGlobalConfig"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type IndexAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *IndexAction) Init() {
 | 
			
		||||
	this.Nav("", "component", "index")
 | 
			
		||||
	this.SecondMenu("global")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *IndexAction) RunGet(params struct{}) {
 | 
			
		||||
	valueJSONResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: SettingCodeServerGlobalConfig})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	valueJSON := valueJSONResp.ValueJSON
 | 
			
		||||
	globalConfig := &serverconfigs.GlobalConfig{}
 | 
			
		||||
 | 
			
		||||
	if len(valueJSON) > 0 {
 | 
			
		||||
		err = json.Unmarshal(valueJSON, globalConfig)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			this.ErrorPage(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["globalConfig"] = globalConfig
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *IndexAction) RunPost(params struct {
 | 
			
		||||
	GlobalConfigJSON []byte
 | 
			
		||||
	Must             *actions.Must
 | 
			
		||||
 | 
			
		||||
	// 不匹配域名相关
 | 
			
		||||
	AllowMismatchDomains                []string
 | 
			
		||||
	DomainMismatchAction                string
 | 
			
		||||
	DomainMismatchActionPageStatusCode  int
 | 
			
		||||
	DomainMismatchActionPageContentHTML string
 | 
			
		||||
 | 
			
		||||
	// TCP端口设置
 | 
			
		||||
	TcpAllPortRangeMin int
 | 
			
		||||
	TcpAllPortRangeMax int
 | 
			
		||||
	TcpAllDenyPorts    []int
 | 
			
		||||
 | 
			
		||||
	DefaultDomain string
 | 
			
		||||
}) {
 | 
			
		||||
	// 创建日志
 | 
			
		||||
	defer this.CreateLogInfo(codes.Server_LogUpdateGlobalSettings)
 | 
			
		||||
 | 
			
		||||
	if len(params.GlobalConfigJSON) == 0 {
 | 
			
		||||
		this.Fail("错误的配置信息,请刷新当前页面后重试")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	globalConfig := &serverconfigs.GlobalConfig{}
 | 
			
		||||
	err := json.Unmarshal(params.GlobalConfigJSON, globalConfig)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.Fail("配置校验失败:" + err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// TCP端口范围
 | 
			
		||||
	if params.TcpAllPortRangeMin < 1024 {
 | 
			
		||||
		params.TcpAllPortRangeMin = 1024
 | 
			
		||||
	}
 | 
			
		||||
	if params.TcpAllPortRangeMax > 65534 {
 | 
			
		||||
		params.TcpAllPortRangeMax = 65534
 | 
			
		||||
	} else if params.TcpAllPortRangeMax < 1024 {
 | 
			
		||||
		params.TcpAllPortRangeMax = 1024
 | 
			
		||||
	}
 | 
			
		||||
	if params.TcpAllPortRangeMin > params.TcpAllPortRangeMax {
 | 
			
		||||
		params.TcpAllPortRangeMin, params.TcpAllPortRangeMax = params.TcpAllPortRangeMax, params.TcpAllPortRangeMin
 | 
			
		||||
	}
 | 
			
		||||
	globalConfig.TCPAll.DenyPorts = params.TcpAllDenyPorts
 | 
			
		||||
	globalConfig.TCPAll.PortRangeMin = params.TcpAllPortRangeMin
 | 
			
		||||
	globalConfig.TCPAll.PortRangeMax = params.TcpAllPortRangeMax
 | 
			
		||||
 | 
			
		||||
	// 修改配置
 | 
			
		||||
	globalConfigJSON, err := json.Marshal(globalConfig)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
 | 
			
		||||
		Code:      SettingCodeServerGlobalConfig,
 | 
			
		||||
		ValueJSON: globalConfigJSON,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//  通知更新
 | 
			
		||||
	_, err = this.RPC().ServerRPC().NotifyServersChange(this.AdminContext(), &pb.NotifyServersChangeRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
@@ -1,20 +0,0 @@
 | 
			
		||||
package components
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
 | 
			
		||||
	"github.com/iwind/TeaGo"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	TeaGo.BeforeStart(func(server *TeaGo.Server) {
 | 
			
		||||
		server.
 | 
			
		||||
			Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
 | 
			
		||||
			Data("teaMenu", "servers").
 | 
			
		||||
			Data("teaSubMenu", "global").
 | 
			
		||||
			Helper(NewHelper()).
 | 
			
		||||
			Prefix("/servers/components").
 | 
			
		||||
			GetPost("", new(IndexAction)).
 | 
			
		||||
			EndAll()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
@@ -37,7 +37,6 @@ import (
 | 
			
		||||
	// 服务相关
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/certs"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache/batch"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/log"
 | 
			
		||||
 
 | 
			
		||||
@@ -207,6 +207,34 @@
 | 
			
		||||
            </table>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <h4>TCP/UDP相关</h4>
 | 
			
		||||
        <table class="ui table definition selectable">
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td class="title">允许的端口范围</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <div class="ui fields inline">
 | 
			
		||||
                        <div class="ui field">
 | 
			
		||||
                            <input type="text" name="tcpAllPortRangeMin" maxlength="5" size="6" v-model="tcpAllPortRangeMin"/>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="ui field">
 | 
			
		||||
                            -
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="ui field">
 | 
			
		||||
                            <input type="text" name="tcpAllPortRangeMax" maxlength="5" size="6" v-model="tcpAllPortRangeMax"/>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <p class="comment">用户创建TCP/TLS负载均衡服务时可以随机选择的端口范围,最小不能小于1024,最大不能大于65534。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td>排除的端口</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <values-box placeholder="端口" size="6" name="tcpAllDenyPorts" :values="tcpAllDenyPorts"></values-box>
 | 
			
		||||
                    <p class="comment">当为用户随机分配端口时要排除的端口。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </table>
 | 
			
		||||
 | 
			
		||||
        <h4>其他</h4>
 | 
			
		||||
        <table class="ui table definition selectable">
 | 
			
		||||
            <tr>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,20 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	this.success = NotifyReloadSuccess("保存成功")
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * TCP端口
 | 
			
		||||
	 */
 | 
			
		||||
	this.tcpAllPortRangeMin = 10000
 | 
			
		||||
	this.tcpAllPortRangeMax = 40000
 | 
			
		||||
	if (this.config.tcpAll.portRangeMin > 0) {
 | 
			
		||||
		this.tcpAllPortRangeMin = this.config.tcpAll.portRangeMin
 | 
			
		||||
	}
 | 
			
		||||
	if (this.config.tcpAll.portRangeMax > 0) {
 | 
			
		||||
		this.tcpAllPortRangeMax = this.config.tcpAll.portRangeMax
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.tcpAllDenyPorts = []
 | 
			
		||||
	if (this.config.tcpAll.denyPorts != null) {
 | 
			
		||||
		this.tcpAllDenyPorts = this.config.tcpAll.denyPorts
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
@@ -1,42 +0,0 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
 | 
			
		||||
<div class="ui tabular menu tiny">
 | 
			
		||||
    <a href="" class="item" :class="{active: tab == 'tcpPorts'}" @click.prevent="selectTab('tcpPorts')">TCP/TLS端口</a>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
 | 
			
		||||
    <input type="hidden" name="globalConfigJSON" :value="JSON.stringify(globalConfig)"/>
 | 
			
		||||
 | 
			
		||||
    <!-- TCP 相关 -->
 | 
			
		||||
    <div v-show="tab == 'tcpPorts'">
 | 
			
		||||
        <table class="ui table definition selectable">
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td class="title">允许的端口范围</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <div class="ui fields inline">
 | 
			
		||||
                        <div class="ui field">
 | 
			
		||||
                            <input type="text" name="tcpAllPortRangeMin" maxlength="5" size="6" v-model="tcpAllPortRangeMin"/>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="ui field">
 | 
			
		||||
                            -
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="ui field">
 | 
			
		||||
                            <input type="text" name="tcpAllPortRangeMax" maxlength="5" size="6" v-model="tcpAllPortRangeMax"/>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <p class="comment">用户创建TCP/TLS负载均衡服务时可以随机选择的端口范围,最小不能小于1024,最大不能大于65534。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td>排除的端口</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <values-box placeholder="端口" size="6" name="tcpAllDenyPorts" :values="tcpAllDenyPorts"></values-box>
 | 
			
		||||
                    <p class="comment">当为用户随机分配端口时要排除的端口。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </table>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="margin"></div>
 | 
			
		||||
    <submit-btn v-show="tab != 'domainMatch'">保存</submit-btn>
 | 
			
		||||
</form>
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
    this.tab = "tcpPorts"
 | 
			
		||||
 | 
			
		||||
    this.$delay(function () {
 | 
			
		||||
        if (window.location.hash != null && window.location.hash.length > 1) {
 | 
			
		||||
            this.selectTab(window.location.hash.substring(1))
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    this.selectTab = function (tab) {
 | 
			
		||||
        this.tab = tab
 | 
			
		||||
        window.location.hash = "#" + tab
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.success = function () {
 | 
			
		||||
        teaweb.success("保存成功", function () {
 | 
			
		||||
            teaweb.reload()
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * TCP端口
 | 
			
		||||
     */
 | 
			
		||||
    this.tcpAllPortRangeMin = 10000
 | 
			
		||||
    this.tcpAllPortRangeMax = 40000
 | 
			
		||||
    if (this.globalConfig.tcpAll.portRangeMin > 0) {
 | 
			
		||||
        this.tcpAllPortRangeMin = this.globalConfig.tcpAll.portRangeMin
 | 
			
		||||
    }
 | 
			
		||||
    if (this.globalConfig.tcpAll.portRangeMax > 0) {
 | 
			
		||||
        this.tcpAllPortRangeMax = this.globalConfig.tcpAll.portRangeMax
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.tcpAllDenyPorts = []
 | 
			
		||||
    if (this.globalConfig.tcpAll.denyPorts != null) {
 | 
			
		||||
        this.tcpAllDenyPorts = this.globalConfig.tcpAll.denyPorts
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user