refactor - pasdns can now look sane 3.0
This commit is contained in:
parent
57fbfbf059
commit
61f89c8067
7 changed files with 3 additions and 3 deletions
81
parser/parser.go
Normal file
81
parser/parser.go
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
package parser
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.gay/exhq/pas/src/Constants"
|
||||
)
|
||||
|
||||
func CheckIpSyntax(ip string) bool {
|
||||
res, _ := regexp.MatchString(`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$`, ip)
|
||||
return res
|
||||
}
|
||||
|
||||
func CheckDomainSyntax(domain string) bool {
|
||||
res, _ := regexp.MatchString(`[a-z0-9]{2,}\.(gaming|sex2|dev|meow|horse)`, domain)
|
||||
return res
|
||||
}
|
||||
|
||||
func CheckKeysExistDomain(m map[string]string) bool {
|
||||
for _, key := range []string{"domain", "ip"} {
|
||||
if _, ok := m[key]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func ParseIntent(intent string) Constants.Intent {
|
||||
if intent == "" {
|
||||
return Constants.Intent{
|
||||
Method: Constants.UNKNOWN,
|
||||
Path: "",
|
||||
Version: "",
|
||||
Headers: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
lines := strings.Split(intent, "\n")
|
||||
if len(lines) < 1 {
|
||||
return Constants.Intent{
|
||||
Method: Constants.UNKNOWN,
|
||||
Path: "",
|
||||
Version: "",
|
||||
Headers: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
firstLine := lines[0]
|
||||
parts := strings.Fields(firstLine)
|
||||
if len(parts) != 3 {
|
||||
return Constants.Intent{
|
||||
Method: Constants.UNKNOWN,
|
||||
Path: "",
|
||||
Version: "",
|
||||
Headers: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
method := Constants.UNKNOWN
|
||||
if parts[0] == string(Constants.GET) {
|
||||
method = Constants.GET
|
||||
} else if parts[0] == string(Constants.POST) {
|
||||
method = Constants.POST
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
for _, line := range lines[1:] {
|
||||
headerParts := strings.SplitN(line, ":", 2)
|
||||
if len(headerParts) == 2 {
|
||||
headers[strings.TrimSpace(headerParts[0])] = strings.TrimSpace(headerParts[1])
|
||||
}
|
||||
}
|
||||
|
||||
return Constants.Intent{
|
||||
Method: method,
|
||||
Path: parts[1],
|
||||
Version: strings.ReplaceAll(parts[2], "PAS/", ""),
|
||||
Headers: headers,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue