diff --git a/elasticsearch/elasticsearch.go b/elasticsearch/elasticsearch.go index 60241c9..71a3e28 100644 --- a/elasticsearch/elasticsearch.go +++ b/elasticsearch/elasticsearch.go @@ -20,7 +20,7 @@ func (m *ElasticSearchMatcher) Key() string { func (m *ElasticSearchMatcher) Name(matchCtx *osm.MatchCtx) string { name := "ElasticSearch" if v, ok := matchCtx.GetAttribute("number"); ok { - name = name + " (" + v.(string) + ")" + name = name + " (" + v + ")" } return name } diff --git a/http/http.go b/http/http.go index a4c97c8..00df303 100644 --- a/http/http.go +++ b/http/http.go @@ -17,7 +17,7 @@ func (m *HTTPMatcher) Key() string { func (m *HTTPMatcher) Name(matchCtx *osm.MatchCtx) string { name := "HTTP" if v, ok := matchCtx.GetAttribute("server"); ok { - name = name + " (" + v.(string) + ")" + name = name + " (" + v + ")" } return name } diff --git a/matcher.go b/matcher.go index aa3dae7..7ac978f 100644 --- a/matcher.go +++ b/matcher.go @@ -42,7 +42,7 @@ func (m *Matchers) AddPacket(packet *Packet) { type MatchCtx struct { address string port int - attributes map[string]interface{} + attributes map[string]string } func (mc *MatchCtx) Address() string { @@ -53,25 +53,25 @@ func (mc *MatchCtx) Port() int { return mc.port } -func (mc *MatchCtx) GetAttribute(key string) (value interface{}, ok bool) { +func (mc *MatchCtx) GetAttribute(key string) (value string, ok bool) { value, ok = mc.attributes[key] return } -func (mc *MatchCtx) SetAttribute(key string, value interface{}) { +func (mc *MatchCtx) SetAttribute(key string, value string) { mc.attributes[key] = value } func (mc *MatchCtx) InitAttribute() { - mc.attributes = make(map[string]interface{}) + mc.attributes = make(map[string]string) } func NewMatchCtx(address string, port int) *MatchCtx { return &MatchCtx{ address: address, port: port, - attributes: make(map[string]interface{}), + attributes: make(map[string]string), } } diff --git a/mysql/mysql.go b/mysql/mysql.go index 4fdebf2..44227de 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -20,10 +20,10 @@ func (m *MySqlMatcher) Key() string { func (m *MySqlMatcher) Name(matchCtx *osm.MatchCtx) string { name := "MySQL" if v, ok := matchCtx.GetAttribute("version"); ok { - if strings.Contains(v.(string), "MariaDB") { + if strings.Contains(v, "MariaDB") { name = "MariaDB" } - name = name + " (" + v.(string) + ")" + name = name + " (" + v + ")" } return name } diff --git a/redis/redis.go b/redis/redis.go index 4719c65..98db016 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -2,6 +2,7 @@ package redis import ( "bufio" + "strconv" "strings" osm "git.loafle.net/overflow/service_matcher-go" @@ -23,16 +24,16 @@ func (m *RedisMatcher) Name(matchCtx *osm.MatchCtx) string { name := "Redis" if v, ok := matchCtx.GetAttribute("protected"); ok { - if v.(bool) { + if _v, _err := strconv.ParseBool(v); nil != _err && _v { return name + " (protected)" } } if v, ok := matchCtx.GetAttribute("redis_mode"); ok { - name = name + " " + v.(string) + name = name + " " + v } if v, ok := matchCtx.GetAttribute("redis_version"); ok { - name = name + " (" + v.(string) + ")" + name = name + " (" + v + ")" } return name } @@ -80,7 +81,7 @@ func (m *RedisMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Pack protected := m.checkProtectedMode(packet) - matchCtx.SetAttribute("protected", protected) + matchCtx.SetAttribute("protected", strconv.FormatBool(protected)) if protected { return nil } @@ -89,10 +90,11 @@ func (m *RedisMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Pack response := string(packet.Bytes()) if v, ok := matchCtx.GetAttribute("protected"); ok { - if !v.(bool) { + if _v, _err := strconv.ParseBool(v); nil != _err && _v { m.parseResponse(matchCtx, response) } } + return nil case 2: sign := string([]rune(resp)[0]) @@ -151,7 +153,7 @@ func (m *RedisMatcher) parseResponse(matchCtx *osm.MatchCtx, response string) { func (m *RedisMatcher) PacketCount(matchCtx *osm.MatchCtx) int { if v, ok := matchCtx.GetAttribute("protected"); ok { - if v.(bool) { + if _v, _err := strconv.ParseBool(v); nil != _err && _v { return 1 } } diff --git a/sqlserver/sqlserver.go b/sqlserver/sqlserver.go index 7a98439..5dd2dda 100644 --- a/sqlserver/sqlserver.go +++ b/sqlserver/sqlserver.go @@ -3,6 +3,7 @@ package sqlserver import ( "bytes" "encoding/binary" + "strconv" osm "git.loafle.net/overflow/service_matcher-go" ) @@ -118,12 +119,12 @@ func (m *SQLServerMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm. case 0: return nil case 1: - matchCtx.SetAttribute("isSSL", true) + matchCtx.SetAttribute("isSSL", strconv.FormatBool(true)) return nil case 2: return nil case 3: - matchCtx.SetAttribute("isSSL", true) + matchCtx.SetAttribute("isSSL", strconv.FormatBool(true)) return nil default: return osm.NotMatchedError() diff --git a/ssh/ssh.go b/ssh/ssh.go index a8e66f0..99bdf94 100644 --- a/ssh/ssh.go +++ b/ssh/ssh.go @@ -19,7 +19,7 @@ func (m *SSHMatcher) Key() string { func (m *SSHMatcher) Name(matchCtx *osm.MatchCtx) string { name := "SSH" if v, ok := matchCtx.GetAttribute("softwareversion"); ok { - name = name + " (" + v.(string) + ")" + name = name + " (" + v + ")" } return name }