package wafModels import ( "regexp" "strconv" "github.rackspace.com/gorax/tools/util" ) var ( interfaceRe = regexp.MustCompile(`(?i)(lan|management)(.*)\n`) routeRe = regexp.MustCompile(`(?i)platform:(.*)\n`) platformRe = regexp.MustCompile(`(?i)platform:(\S+)`) nameRe = regexp.MustCompile(`(?i)(lan|management)`) addressV4Re = regexp.MustCompile(`(?i)address-v4=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d+)`) addressV6Re = regexp.MustCompile(`(?i)address-v6=(\S+),`) protoRe = regexp.MustCompile(`(?i)proto=(\w+)`) ipVerRe = regexp.MustCompile(`(?i)ip-ver=(\w+)`) gatewayRe = regexp.MustCompile(`(?i)gateway=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})`) netRe = regexp.MustCompile(`(?i)net=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d+)`) deviceRe = regexp.MustCompile(`(?i)device=(\w+)`) ) type PlatformInterface struct { Name string `json:"name"` Device string `json:"device"` AddressV4 string `json:"address_v4"` AddressV6 string `json:"address_v6"` Proto string `json:"proto"` } func ParsePlatformInterface(s string) (pn []PlatformInterface) { for _, nw := range interfaceRe.FindAllStringSubmatch(s, -1) { if len(nw) == 0 { continue } pn = append(pn, PlatformInterface{ Name: util.RegexpString(nameRe, nw[0]), Device: util.RegexpString(deviceRe, nw[0]), AddressV4: util.RegexpString(addressV4Re, nw[0]), AddressV6: util.RegexpString(addressV6Re, nw[0]), Proto: util.RegexpString(protoRe, nw[0]), }) } return } type PlatformRoute struct { Platform string `json:"platform"` IPVer int `json:"ip_ver"` Network string `json:"net"` Gateway string `json:"gateway"` Device string `json:"device"` } func ParsePlatformRoute(s string) (pr []PlatformRoute) { for _, nw := range routeRe.FindAllStringSubmatch(s, -1) { if len(nw) == 0 { continue } pr = append(pr, PlatformRoute{ Platform: util.RegexpString(platformRe, nw[0]), IPVer: func() int { v := util.RegexpString(ipVerRe, nw[0]) if v != "" { i, _ := strconv.Atoi(v) return i } return 0 }(), Network: util.RegexpString(netRe, nw[0]), Gateway: util.RegexpString(gatewayRe, nw[0]), Device: util.RegexpString(deviceRe, nw[0]), }) } return }