75 lines
1.2 KiB
Go
75 lines
1.2 KiB
Go
package protected
|
|
|
|
import (
|
|
cnsm "git.loafle.net/commons_go/network_service_matcher"
|
|
)
|
|
|
|
const (
|
|
COMPARE_STR_1 = "-"
|
|
COMPARE_STR_2 = "DENIED"
|
|
)
|
|
|
|
type RedisProtectedMatcher struct {
|
|
cnsm.Matchers
|
|
}
|
|
|
|
func (r *RedisProtectedMatcher) ServiceName() string {
|
|
return "REDIS"
|
|
}
|
|
|
|
func (r *RedisProtectedMatcher) String() string {
|
|
return "Redis:Protected"
|
|
}
|
|
|
|
func (r *RedisProtectedMatcher) IsPrePacket() bool {
|
|
return true
|
|
}
|
|
|
|
func (r *RedisProtectedMatcher) HasResponse(index int) bool {
|
|
return true
|
|
}
|
|
|
|
func (r *RedisProtectedMatcher) IsError(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
|
|
return false
|
|
}
|
|
|
|
func (r *RedisProtectedMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
|
|
|
|
if packet == nil {
|
|
return false
|
|
}
|
|
|
|
switch index {
|
|
case 0:
|
|
str := string(packet.Buffer[:packet.Len])
|
|
|
|
if str == "" {
|
|
return false
|
|
}
|
|
if len(str) <= 0 {
|
|
return false
|
|
}
|
|
|
|
firstCompare := str[0:1]
|
|
seconcdCompare := str[1 : len(COMPARE_STR_2)+1]
|
|
|
|
if firstCompare != COMPARE_STR_1 {
|
|
return false
|
|
}
|
|
if seconcdCompare != COMPARE_STR_2 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
func NewMatcher() cnsm.Matcher {
|
|
m := &RedisProtectedMatcher{}
|
|
|
|
return m
|
|
}
|