channel 表添加 IP 白名单字段用于快照保存与展示
This commit is contained in:
@@ -30,6 +30,7 @@ type Channel struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp without time zone;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
EdgeHost string `gorm:"column:edge_host;type:character varying(255);comment:节点地址" json:"edge_host"` // 节点地址
|
||||
EdgeID int32 `gorm:"column:edge_id;type:integer;comment:节点ID" json:"edge_id"` // 节点ID
|
||||
Whitelists string `gorm:"column:whitelists;type:text;comment:IP白名单,逗号分隔" json:"whitelists"` // IP白名单,逗号分隔
|
||||
}
|
||||
|
||||
// TableName Channel's table name
|
||||
|
||||
@@ -43,6 +43,7 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
_channel.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_channel.EdgeHost = field.NewString(tableName, "edge_host")
|
||||
_channel.EdgeID = field.NewInt32(tableName, "edge_id")
|
||||
_channel.Whitelists = field.NewString(tableName, "whitelists")
|
||||
|
||||
_channel.fillFieldMap()
|
||||
|
||||
@@ -69,6 +70,7 @@ type channel struct {
|
||||
DeletedAt field.Field // 删除时间
|
||||
EdgeHost field.String // 节点地址
|
||||
EdgeID field.Int32 // 节点ID
|
||||
Whitelists field.String // IP白名单,逗号分隔
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -101,6 +103,7 @@ func (c *channel) updateTableName(table string) *channel {
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
c.EdgeHost = field.NewString(table, "edge_host")
|
||||
c.EdgeID = field.NewInt32(table, "edge_id")
|
||||
c.Whitelists = field.NewString(table, "whitelists")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
@@ -117,7 +120,7 @@ func (c *channel) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (c *channel) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 16)
|
||||
c.fieldMap = make(map[string]field.Expr, 17)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["proxy_id"] = c.ProxyID
|
||||
@@ -134,6 +137,7 @@ func (c *channel) fillFieldMap() {
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
c.fieldMap["edge_host"] = c.EdgeHost
|
||||
c.fieldMap["edge_id"] = c.EdgeID
|
||||
c.fieldMap["whitelists"] = c.Whitelists
|
||||
}
|
||||
|
||||
func (c channel) clone(db *gorm.DB) channel {
|
||||
|
||||
@@ -512,6 +512,7 @@ func assignShortChannels(
|
||||
if config.AuthIp {
|
||||
portConf.Whitelist = &config.Whitelists
|
||||
newChannel.AuthIP = true
|
||||
newChannel.Whitelists = strings.Join(config.Whitelists, ",")
|
||||
}
|
||||
|
||||
if config.AuthPass {
|
||||
@@ -637,6 +638,9 @@ func assignLongChannels(q *q.Query, userId int32, count int, config ChannelCreat
|
||||
ProxyHost: edge.Host,
|
||||
ProxyPort: edge.ProxyPort,
|
||||
}
|
||||
if config.AuthIp {
|
||||
channel.Whitelists = strings.Join(config.Whitelists, ",")
|
||||
}
|
||||
if config.AuthPass {
|
||||
username, password := genPassPair()
|
||||
channel.Username = username
|
||||
|
||||
Reference in New Issue
Block a user