Compare commits

..

5 Commits

Author SHA1 Message Date
刘祥超
093826222a 将版本修改为v0.5.3.1 2022-09-26 12:16:44 +08:00
刘祥超
0d7b487afc 修复开源版本无法编译的问题 2022-09-26 12:16:20 +08:00
刘祥超
8de17b6d9c 只有在数据库用户是root时才执行某些命令 2022-09-26 12:16:08 +08:00
刘祥超
49d217a883 提交EdgeDNS API相关代码 2022-09-26 11:51:45 +08:00
刘祥超
4827555899 启动过程增加多个提示 2022-09-26 11:00:58 +08:00
16 changed files with 187 additions and 54 deletions

View File

@@ -1,7 +1,7 @@
package teaconst
const (
Version = "0.5.3"
Version = "0.5.3.1"
ProductName = "Edge API"
ProcessName = "edge-api"

View File

@@ -3,7 +3,6 @@ package models
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
)
@@ -29,47 +28,3 @@ func (this *NSCluster) HasDDoSProtection() bool {
}
return false
}
// DecodeHosts 解析主机地址
func (this *NSCluster) DecodeHosts() []string {
if IsNull(this.Hosts) {
return nil
}
var hosts = []string{}
err := json.Unmarshal(this.Hosts, &hosts)
if err != nil {
remotelogs.Error("NSCluster.DecodeHosts", "decode failed: "+err.Error())
}
return hosts
}
// DecodeSOAConfig 解析SOA设置
func (this *NSCluster) DecodeSOAConfig() *dnsconfigs.NSSOAConfig {
var config = dnsconfigs.DefaultNSSOAConfig()
if IsNull(this.Soa) {
return config
}
err := json.Unmarshal(this.Soa, config)
if err != nil {
remotelogs.Error("NSCluster.DecodeSOAConfig", "decode failed: "+err.Error())
}
return config
}
// DecodeAnswerConfig 解析应答设置
func (this *NSCluster) DecodeAnswerConfig() *dnsconfigs.NSAnswerConfig {
var config = dnsconfigs.DefaultNSAnswerConfig()
if IsNull(this.Answer) {
return config
}
err := json.Unmarshal(this.Answer, config)
if err != nil {
remotelogs.Error("NSCluster.DecodeAnswerConfig", "decode failed: "+err.Error())
}
return config
}

View File

@@ -0,0 +1,21 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
import (
"errors"
"github.com/iwind/TeaGo/types"
)
type BaseResponse struct {
Code int `json:"code"`
Message string `json:"message"`
}
func (this *BaseResponse) IsValid() bool {
return this.Code == 200
}
func (this *BaseResponse) Error() error {
return errors.New("code: " + types.String(this.Code) + ", message: " + this.Message)
}

View File

@@ -0,0 +1,11 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type CreateNSRecordResponse struct {
BaseResponse
Data struct {
NSRecordId int64 `json:"nsRecordId"`
} `json:"data"`
}

View File

@@ -0,0 +1,14 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type FindAllNSRoutesResponse struct {
BaseResponse
Data struct {
NSRoutes []struct {
Name string `json:"name"`
Code string `json:"code"`
} `json:"nsRoutes"`
} `json:"data"`
}

View File

@@ -0,0 +1,14 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type FindDomainWithNameResponse struct {
BaseResponse
Data struct {
NSDomain struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
} `json:"data"`
}

View File

@@ -0,0 +1,21 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type FindNSRecordWithNameAndTypeResponse struct {
BaseResponse
Data struct {
NSRecord struct {
Id int64 `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Value string `json:"value"`
TTL int32 `json:"ttl"`
NSRoutes []struct {
Name string `json:"name"`
Code string `json:"code"`
} `json:"nsRoutes"`
} `json:"nsRecord"`
}
}

View File

@@ -0,0 +1,12 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type GetAPIAccessToken struct {
BaseResponse
Data struct {
Token string `json:"token"`
ExpiresAt int64 `json:"expiresAt"`
} `json:"data"`
}

View File

@@ -0,0 +1,8 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type ResponseInterface interface {
IsValid() bool
Error() error
}

View File

@@ -0,0 +1,16 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type ListNSDomainsResponse struct {
BaseResponse
Data struct {
NSDomains []struct {
Id int64 `json:"id"`
Name string `json:"name"`
IsOn bool `json:"isOn"`
IsDeleted bool `json:"isDeleted"`
} `json:"nsDomains"`
} `json:"data"`
}

View File

@@ -0,0 +1,21 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type ListNSRecordsResponse struct {
BaseResponse
Data struct {
NSRecords []struct {
Id int64 `json:"id"`
Name string `json:"name"`
Value string `json:"value"`
TTL int32 `json:"ttl"`
Type string `json:"type"`
NSRoutes []struct {
Name string `json:"name"`
Code string `json:"code"`
} `json:"nsRoutes"`
} `json:"nsRecords"`
} `json:"data"`
}

View File

@@ -0,0 +1,7 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type SuccessResponse struct {
BaseResponse
}

View File

@@ -0,0 +1,7 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package edgeapi
type UpdateNSRecordResponse struct {
BaseResponse
}

View File

@@ -130,14 +130,16 @@ func (this *APINode) Start() {
}
// 数据库通知启动
this.setProgress("DATABASE", "正在建立数据库模型")
logs.Println("[API_NODE]notify ready ...")
dbs.NotifyReady()
// 设置时区
this.setProgress("TIMEZONE", "正在设置时区")
this.setupTimeZone()
// 读取配置
this.setProgress("DATABASE", "加载API配置")
this.setProgress("DATABASE", "正在加载API配置")
logs.Println("[API_NODE]reading api config ...")
config, err := configs.SharedAPIConfig()
if err != nil {
@@ -384,6 +386,19 @@ func (this *APINode) setupDB() error {
return err
}
// 检查是否为root用户
config, _ := db.Config()
if config == nil {
return nil
}
dsnConfig, err := mysql.ParseDSN(config.Dsn)
if err != nil || dsnConfig == nil {
return err
}
if dsnConfig.User != "root" {
return nil
}
// 设置Innodb事务提交模式
{
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")

View File

@@ -3,6 +3,7 @@ package setup
import (
"errors"
"fmt"
"github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/types"
@@ -137,12 +138,22 @@ func (this *SQLDump) Dump(db *dbs.DB) (result *SQLDumpResult, err error) {
func (this *SQLDump) Apply(db *dbs.DB, newResult *SQLDumpResult, showLog bool) (ops []string, err error) {
// 设置Innodb事务提交模式
{
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")
if err == nil && result != nil {
var oldValue = result.GetInt("Value")
if oldValue == 1 {
_, _ = db.Exec("SET GLOBAL innodb_flush_log_at_trx_commit=2")
// 检查是否为root用户
config, _ := db.Config()
if config == nil {
return nil, nil
}
dsnConfig, err := mysql.ParseDSN(config.Dsn)
if err != nil || dsnConfig == nil {
return nil, err
}
if dsnConfig.User == "root" {
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")
if err == nil && result != nil {
var oldValue = result.GetInt("Value")
if oldValue == 1 {
_, _ = db.Exec("SET GLOBAL innodb_flush_log_at_trx_commit=2")
}
}
}
}

View File

@@ -76,7 +76,7 @@ func TestSQLDump_Apply(t *testing.T) {
db2, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
Driver: "mysql",
Dsn: "root:123456@tcp(192.168.2.60:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
Dsn: "edge:123456@tcp(192.168.2.60:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
Prefix: "edge",
})
if err != nil {