This repository was archived by the owner on Jun 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.go
More file actions
103 lines (92 loc) · 2.15 KB
/
Copy pathutils.go
File metadata and controls
103 lines (92 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package parsers
import (
"regexp"
"strings"
)
var (
TitleRegexp = regexp.MustCompile("(?Uis)<title>(.*)</title>")
ServerRegexp = regexp.MustCompile("(?i)Server: ([\x20-\x7e]+)")
//XPBRegexp = regexp.MustCompile("(?i)X-Powered-By: ([\x20-\x7e]+)")
//SessionRegexp = regexp.MustCompile("(?i) (.*SESS.*?ID)")
HeaderCharsetRegexp = regexp.MustCompile("(?i)Content-Type:.*charset=(.+)")
BodyCharsetRegexp = regexp.MustCompile("(?i)<meta.*?charset=[\"']?(.*?)[\"' >]")
)
func MatchOne(reg *regexp.Regexp, s []byte) (string, bool) {
matched := reg.FindSubmatch(s)
if len(matched) == 0 {
return "", false
}
if len(matched) == 1 {
return "", true
} else {
return strings.TrimSpace(string(matched[1])), true
}
}
func MatchCharset(content []byte) string {
charset, ok := MatchOne(HeaderCharsetRegexp, content)
if ok {
return charset
}
charset, ok = MatchOne(BodyCharsetRegexp, content)
if ok {
return charset
}
return ""
}
func MatchTitle(content []byte) string {
title, ok := MatchOne(TitleRegexp, content)
if ok {
return title
}
return ""
}
func MatchCharacter(content []byte) string {
if len(content) > 13 {
return string(content[0:13])
} else {
return string(content)
}
}
//func MatchLanguage(resp *http.Response) string {
// var powered string
// powered = resp.Header.Get("X-Powered-By")
// if powered != "" {
// return powered
// }
//
// cookies := getCookies(resp)
// if cookies["JSESSIONID"] != "" {
// return "JAVA"
// } else if cookies["ASP.NET_SessionId"] != "" {
// return "ASP"
// } else if cookies["PHPSESSID"] != "" {
// return "PHP"
// } else {
// return ""
// }
//}
//func MatchLanguageWithRaw(content []byte) string {
// powered, ok := MatchOne(XPBRegexp, content)
// if ok {
// return powered
// }
//
// sessionid, ok := MatchOne(SessionRegexp, content)
// if ok {
// switch sessionid {
// case "JSESSIONID":
// return "JAVA"
// case "ASP.NET_SessionId":
// return "ASP.NET"
// case "PHPSESSID":
// return "PHP"
// }
// }
// return ""
//}
func notContains(s, substr string) bool {
return !strings.Contains(s, substr)
}
func notEqualFlod(s, substr string) bool {
return !strings.EqualFold(s, substr)
}