自动升级SYN Flood配置

This commit is contained in:
GoEdgeLab
2022-01-10 20:07:26 +08:00
parent e48c02176b
commit ace2a93bbe
3 changed files with 35 additions and 6 deletions

View File

@@ -133,12 +133,7 @@ func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64
op.UseLocalFirewall = true
{
synFloodJSON, err := json.Marshal(&firewallconfigs.SYNFloodConfig{
IsOn: true,
MinAttempts: 10,
TimeoutSeconds: 600,
IgnoreLocal: true,
})
synFloodJSON, err := json.Marshal(firewallconfigs.DefaultSYNFloodConfig())
if err != nil {
return 0, err
}

View File

@@ -62,6 +62,9 @@ var upgradeFuncs = []*upgradeVersion{
{
"0.3.7", upgradeV0_3_7,
},
{
"0.4.0", upgradeV0_4_0,
},
}
// UpgradeSQLData 升级SQL数据
@@ -552,3 +555,17 @@ func upgradeV0_3_7(db *dbs.DB) error {
return nil
}
// v0.4.0
func upgradeV0_4_0(db *dbs.DB) error {
// 升级SYN Flood配置
synFloodJSON, err := json.Marshal(firewallconfigs.DefaultSYNFloodConfig())
if err == nil {
_, err := db.Exec("UPDATE edgeHTTPFirewallPolicies SET synFlood=? WHERE synFlood IS NULL AND state=1", string(synFloodJSON))
if err != nil {
return err
}
}
return nil
}

View File

@@ -84,3 +84,20 @@ func TestUpgradeSQLData_v0_3_7(t *testing.T) {
}
t.Log("ok")
}
func TestUpgradeSQLData_v0_4_0(t *testing.T) {
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
Driver: "mysql",
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
Prefix: "edge",
})
if err != nil {
t.Fatal(err)
}
err = upgradeV0_4_0(db)
if err != nil {
t.Fatal(err)
}
t.Log("ok")
}