Spaces:
Sleeping
Sleeping
Create main.go
Browse files
main.go
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
package main
|
2 |
+
|
3 |
+
import (
|
4 |
+
"fmt"
|
5 |
+
"net/http"
|
6 |
+
"strings"
|
7 |
+
)
|
8 |
+
|
9 |
+
var strValues string
|
10 |
+
var strUvalues string
|
11 |
+
var password = "123456"
|
12 |
+
|
13 |
+
func filterCookieValues(cookieValues string, keepKeys []string) string {
|
14 |
+
newCookieValues := ""
|
15 |
+
pairs := strings.Split(cookieValues, ";")
|
16 |
+
for _, pair := range pairs {
|
17 |
+
parts := strings.Split(pair, "=")
|
18 |
+
key := strings.TrimSpace(parts[0])
|
19 |
+
value := strings.Join(parts[1:], "=")
|
20 |
+
if contains(keepKeys, key) {
|
21 |
+
newCookieValues += key + "=" + value + "; "
|
22 |
+
}
|
23 |
+
}
|
24 |
+
newCookieValues = newCookieValues[:len(newCookieValues)-2]
|
25 |
+
return newCookieValues
|
26 |
+
}
|
27 |
+
|
28 |
+
func contains(keys []string, key string) bool {
|
29 |
+
for _, k := range keys {
|
30 |
+
if k == key {
|
31 |
+
return true
|
32 |
+
}
|
33 |
+
}
|
34 |
+
return false
|
35 |
+
}
|
36 |
+
|
37 |
+
func handleSET(w http.ResponseWriter, req *http.Request) {
|
38 |
+
method := req.Method
|
39 |
+
pwd := req.URL.Query().Get("pwd")
|
40 |
+
if pwd == "" || pwd != password {
|
41 |
+
w.WriteHeader(http.StatusUnauthorized)
|
42 |
+
w.Write([]byte("Invalid password"))
|
43 |
+
return
|
44 |
+
}
|
45 |
+
keepKeys := []string{"_U", "MUID", "KievRPSSecAuth", "cct", "_RwBf", "SRCHHPGUSR", "WLS"}
|
46 |
+
keepKeysU := []string{"_U", "WLS"}
|
47 |
+
cookieValues := req.Header.Get("Cookie-Values")
|
48 |
+
setValue := filterCookieValues(cookieValues, keepKeys)
|
49 |
+
getUValue := filterCookieValues(cookieValues, keepKeysU)
|
50 |
+
|
51 |
+
if setValue != "" {
|
52 |
+
strValues = setValue
|
53 |
+
if getUValue != "" && !strings.Contains(strUvalues, getUValue) {
|
54 |
+
strUvalues += ";" + getUValue
|
55 |
+
}
|
56 |
+
w.Write([]byte("Set value successfully"))
|
57 |
+
} else {
|
58 |
+
w.WriteHeader(http.StatusBadRequest)
|
59 |
+
w.Write([]byte("No Cookie-Values in header"))
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
func handleGET(w http.ResponseWriter, req *http.Request) {
|
64 |
+
method := req.Method
|
65 |
+
pwd := req.URL.Query().Get("pwd")
|
66 |
+
if pwd == "" || pwd != password {
|
67 |
+
w.WriteHeader(http.StatusUnauthorized)
|
68 |
+
w.Write([]byte("Invalid password"))
|
69 |
+
return
|
70 |
+
}
|
71 |
+
result := map[string]interface{}{"result": map[string]string{"cookies": strValues}}
|
72 |
+
w.Header().Set("Content-Type", "application/json")
|
73 |
+
w.Write([]byte(fmt.Sprintf("%v", result)))
|
74 |
+
}
|
75 |
+
|
76 |
+
func handleCLS(w http.ResponseWriter, req *http.Request) {
|
77 |
+
method := req.Method
|
78 |
+
pwd := req.URL.Query().Get("pwd")
|
79 |
+
if pwd == "" || pwd != password {
|
80 |
+
w.WriteHeader(http.StatusUnauthorized)
|
81 |
+
w.Write([]byte("Invalid password"))
|
82 |
+
return
|
83 |
+
}
|
84 |
+
replacedStr := strings.ReplaceAll(strUvalues, ";", "<br>")
|
85 |
+
valuesArray := strings.Split(strUvalues, ";")
|
86 |
+
jsonObject := make(map[string]string)
|
87 |
+
for index, value := range valuesArray {
|
88 |
+
jsonObject[fmt.Sprintf("No%d", index+1)] = value
|
89 |
+
}
|
90 |
+
jsonString := fmt.Sprintf("%v", jsonObject)
|
91 |
+
|
92 |
+
strValues = ""
|
93 |
+
strUvalues = ""
|
94 |
+
|
95 |
+
w.Write([]byte("Clear value successfully\n" + replacedStr))
|
96 |
+
}
|
97 |
+
|
98 |
+
func handleHisU(w http.ResponseWriter, req *http.Request) {
|
99 |
+
method := req.Method
|
100 |
+
pwd := req.URL.Query().Get("pwd")
|
101 |
+
if pwd == "" || pwd != password {
|
102 |
+
w.WriteHeader(http.StatusUnauthorized)
|
103 |
+
w.Write([]byte("Invalid password"))
|
104 |
+
return
|
105 |
+
}
|
106 |
+
replacedStr := strings.ReplaceAll(strUvalues, ";", "<br>")
|
107 |
+
w.Write([]byte("Ukey History:\n" + replacedStr))
|
108 |
+
}
|
109 |
+
|
110 |
+
func handleRoot(w http.ResponseWriter, req *http.Request) {
|
111 |
+
w.Write([]byte("Please visit /SET, /GET, or /CLS with ?pwd=xxxxxx"))
|
112 |
+
}
|
113 |
+
|
114 |
+
func main() {
|
115 |
+
port := ":7860"
|
116 |
+
http.HandleFunc("/SET", handleSET)
|
117 |
+
http.HandleFunc("/GET", handleGET)
|
118 |
+
http.HandleFunc("/CLS", handleCLS)
|
119 |
+
http.HandleFunc("/HisU", handleHisU)
|
120 |
+
http.HandleFunc("/", handleRoot)
|
121 |
+
|
122 |
+
fmt.Printf("Server is running on port %s\n", port)
|
123 |
+
http.ListenAndServe(port, nil)
|
124 |
+
}
|