diff --git a/localserver.go b/localserver.go index cfe4368..3de123c 100644 --- a/localserver.go +++ b/localserver.go @@ -150,6 +150,8 @@ func StartLocalServer() { REMOTE_APP: waf_host_add_req.REMOTE_APP, Remote_host: waf_host_add_req.Remote_host, Remote_port: waf_host_add_req.Remote_port, + Certfile: waf_host_add_req.Certfile, + Keyfile: waf_host_add_req.Keyfile, REMARKS: waf_host_add_req.REMARKS, CREATE_TIME: time.Now(), UPDATE_TIME: time.Now(), @@ -242,7 +244,10 @@ func StartLocalServer() { "Remote_host": waf_host_edit_req.Remote_host, "Remote_port": waf_host_edit_req.Remote_port, "REMARKS": waf_host_edit_req.REMARKS, - "UPDATE_TIME": time.Now(), + + "Certfile": waf_host_edit_req.Certfile, + "Keyfile": waf_host_edit_req.Keyfile, + "UPDATE_TIME": time.Now(), } //var edit_waf_host model.Hosts //global.GWAF_LOCAL_DB.Debug().Where("CODE=?", waf_host_edit_req.CODE).Find(edit_waf_host) diff --git a/localwaf/src/pages/waf-host/host/index.vue b/localwaf/src/pages/waf-host/host/index.vue index 1d62dc7..31adcd8 100644 --- a/localwaf/src/pages/waf-host/host/index.vue +++ b/localwaf/src/pages/waf-host/host/index.vue @@ -79,6 +79,14 @@ 加密证书(需上传证书) + + + + + + + + @@ -100,8 +108,8 @@ - - + + @@ -126,9 +134,17 @@ 非加密 - 加密证书(需上传证书) + 加密证书(需填写证书) + + + + + + + + @@ -150,8 +166,8 @@ - - + + @@ -186,7 +202,7 @@ const INITIAL_DATA = { port: 80, remote_host: 'baidu2.com', remote_port: 80, - ssl:0, + ssl:'0', remote_system:"宝塔", remote_app:"API业务系统", guard_status: '', @@ -506,6 +522,7 @@ export default Vue.extend({ console.log(resdata) if (resdata.code === 200) { that.detail_data = resdata.data; + that.detail_data.ssl = that.detail_data.ssl.toString() that.formEditData = {...that.detail_data} } }) diff --git a/main.go b/main.go index 406f60b..63b3cad 100644 --- a/main.go +++ b/main.go @@ -13,16 +13,12 @@ import ( "github.com/lionsoul2014/ip2region/binding/golang/xdb" "github.com/satori/go.uuid" "github.com/spf13/viper" - "gorm.io/driver/mysql" - "gorm.io/gorm" - "gorm.io/gorm/logger" "io" "log" "net/http" "net/http/httputil" _ "net/http/pprof" "net/url" - "os" "strconv" "strings" "time" @@ -230,37 +226,12 @@ func Start_WAF() { global.GWAF_LOCAL_SERVER_PORT = config.GetInt("local_port") //读取本地端口 fmt.Println(" load ini: ", global.GWAF_USER_CODE) - //数据库连接 - newLogger := logger.New( - log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer(日志输出的目标,前缀和日志包含的内容——译者注) - logger.Config{ - SlowThreshold: time.Second, // 慢 SQL 阈值 - LogLevel: logger.Silent, // 日志级别 - IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound(记录未找到)错误 - Colorful: false, // 禁用彩色打印 - - }, - ) - //初始化本地数据库 InitDb() - dsn := "samwaf:v&GP5e0BRpkm^RA@tcp(bj-cynosdbmysql-grp-37amo1rw.sql.tencentcdb.com:26762)/samwaf?charset=utf8mb4&parseTime=True" - db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: newLogger}) - if err != nil { - fmt.Printf("error `%s`: %s\n", "db initial error", err) - return - } - var base_config model.Base_config - - db.Debug().Where("name = ?", "esurl").Find(&base_config) - //esHelper.Init(base_config.Value) todo 暂时屏蔽es - - fmt.Printf("current_version %s \r\n", global.Version_name) - var hosts []model.Hosts - db.Where("user_code = ?", global.GWAF_USER_CODE).Find(&hosts) + global.GWAF_LOCAL_DB.Where("user_code = ?", global.GWAF_USER_CODE).Find(&hosts) //初始化步骤[加载ip数据库] var dbPath = "data/ip2region.xdb" @@ -278,11 +249,7 @@ func Start_WAF() { for i := 0; i < len(hosts); i++ { //检测https if hosts[i].Ssl == 1 { - //查询ssl证书 - var sslconfig model.Sslconfig - db.Debug().Where("code = ? and user_code=? ", hosts[i].Code, global.GWAF_USER_CODE).Find(&sslconfig) - // 第一个域名:example.com - cert, err := tls.LoadX509KeyPair(sslconfig.Certfile, sslconfig.Keyfile) + cert, err := tls.X509KeyPair([]byte(hosts[i].Certfile), []byte(hosts[i].Keyfile)) if err != nil { log.Fatal("Cannot find %s cert & key file. Error is: %s\n", hosts[i].Host, err) continue @@ -311,7 +278,7 @@ func Start_WAF() { //查询规则 var ruleconfig model.Rules - db.Debug().Where("code = ? and user_code=? ", hosts[i].Code, global.GWAF_USER_CODE).Find(&ruleconfig) + global.GWAF_LOCAL_DB.Debug().Where("code = ? and user_code=? ", hosts[i].Code, global.GWAF_USER_CODE).Find(&ruleconfig) ruleHelper.LoadRule(ruleconfig) hostsafe := &HostSafe{ @@ -393,7 +360,7 @@ func Start_WAF() { for code, host := range hostCode { //hostTarget[host].Rule var ruleconfig model.Rules - db.Debug().Where("code = ? and user_code=? ", code, global.GWAF_USER_CODE).Find(&ruleconfig) + global.GWAF_LOCAL_DB.Debug().Where("code = ? and user_code=? ", code, global.GWAF_USER_CODE).Find(&ruleconfig) if ruleconfig.Ruleversion > hostTarget[host].RuleData.Ruleversion { //说明该code有更新 hostRuleChan <- ruleconfig diff --git a/model/hosts.go b/model/hosts.go index 83b61c8..a8f8050 100644 --- a/model/hosts.go +++ b/model/hosts.go @@ -5,20 +5,21 @@ import ( ) type Hosts struct { - Id int `gorm:"primary_key" json:" - "` // - USER_CODE string `json:"user_code"` - Tenant_id string `json:"tenant_id"` //租户ID - Code string `json:"code"` //唯一码 - Host string `json:"host"` //域名 - Port int `json:"port"` //端口 - Ssl int `json:"ssl"` //是否是ssl - GUARD_STATUS int `json:"guard_status"` //防御状态 - REMOTE_SYSTEM string `json:"remote_system"` //是宝塔 phpstudy等 - REMOTE_APP string `json:"remote_app"` //是什么类型的应用 - Remote_host string `json:"remote_host"` //远端域名 - Remote_port int `json:"remote_port"` //远端端口 - - REMARKS string `json:"remarks"` //备注 - CREATE_TIME time.Time `json:"create_time"` //创建时间 - UPDATE_TIME time.Time `json:"update_time"` //更新时间 + Id int `gorm:"primary_key" json:" - "` // + USER_CODE string `json:"user_code"` + Tenant_id string `json:"tenant_id"` //租户ID + Code string `json:"code"` //唯一码 + Host string `json:"host"` //域名 + Port int `json:"port"` //端口 + Ssl int `json:"ssl"` //是否是ssl + GUARD_STATUS int `json:"guard_status"` //防御状态 + REMOTE_SYSTEM string `json:"remote_system"` //是宝塔 phpstudy等 + REMOTE_APP string `json:"remote_app"` //是什么类型的应用 + Remote_host string `json:"remote_host"` //远端域名 + Remote_port int `json:"remote_port"` //远端端口 + Certfile string `json:"certfile"` // 证书文件 + Keyfile string `json:"keyfile"` // 密钥文件 + REMARKS string `json:"remarks"` //备注 + CREATE_TIME time.Time `json:"create_time"` //创建时间 + UPDATE_TIME time.Time `json:"update_time"` //更新时间 } diff --git a/model/waflog/request/waf_host_add_req.go b/model/waflog/request/waf_host_add_req.go index 30aedc9..82483b1 100644 --- a/model/waflog/request/waf_host_add_req.go +++ b/model/waflog/request/waf_host_add_req.go @@ -9,4 +9,6 @@ type WafHostAddReq struct { Remote_host string `json:"remote_host"` //远端域名 Remote_port int `json:"remote_port"` //远端端口 REMARKS string `json:"remarks"` //备注 + Certfile string `json:"certfile"` // 证书文件 + Keyfile string `json:"keyfile"` // 密钥文件 } diff --git a/model/waflog/request/waf_host_edit_req.go b/model/waflog/request/waf_host_edit_req.go index 501de63..7ce4ec7 100644 --- a/model/waflog/request/waf_host_edit_req.go +++ b/model/waflog/request/waf_host_edit_req.go @@ -10,4 +10,6 @@ type WafHostEditReq struct { Remote_host string `json:"remote_host"` //远端域名 Remote_port int `json:"remote_port"` //远端端口 REMARKS string `json:"remarks"` //备注 + Certfile string `json:"certfile"` // 证书文件 + Keyfile string `json:"keyfile"` // 密钥文件 } diff --git a/wafengine.go b/wafengine.go index a17b38e..06ab7d0 100644 --- a/wafengine.go +++ b/wafengine.go @@ -1,4 +1 @@ package main - -type WafEngine struct { -}