package main import ( "compress/gzip" "encoding/base64" "fmt" "io" "log" "net/http" "os" "path/filepath" "strings" "sync" "time" "github.com/gorilla/websocket" ) var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, } type KeyPress struct { Key string `json:"key"` } type gzipResponseWriter struct { io.Writer http.ResponseWriter } func (w gzipResponseWriter) Write(b []byte) (int, error) { return w.Writer.Write(b) } func gzipHandler(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { next(w, r) return } gz := gzip.NewWriter(w) defer gz.Close() w.Header().Set("Content-Encoding", "gzip") next(gzipResponseWriter{Writer: gz, ResponseWriter: w}, r) } } func wsHandler(w http.ResponseWriter, r *http.Request) { conn, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Printf("WebSocket upgrade error: %v", err) return } defer conn.Close() var buffer string var lastPress time.Time var messageCount int startTime := time.Now() for { var keyPress KeyPress err := conn.ReadJSON(&keyPress) if err != nil { break } now := time.Now() if now.Sub(lastPress) > 5*time.Second { buffer = "" } lastPress = now messageCount++ if messageCount > 1000 || now.Sub(startTime) > 10*time.Minute { break } if len(keyPress.Key) > 1 { continue } buffer += keyPress.Key if len(buffer) > 20 { buffer = buffer[len(buffer)-20:] } if buffer == "lain" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://fauux.neocities.org"}) buffer = "" } else if buffer == "rabbit" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "wake up, Neo"}) buffer = "" } else if buffer == "whoareu" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://t.me/systemxplore"}) buffer = "" } else if buffer == "whoami" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://t.me/systemxplore"}) buffer = "" } else if buffer == "whoareyou" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://t.me/systemxplore"}) buffer = "" } else if buffer == "answer" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "it must be easy for you, isn't that right?"}) buffer = "" } else if buffer == "answers" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "it must be easy for you, isn't that right?"}) buffer = "" } else if buffer == "noise" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://noiseprotocol.org/"}) buffer = "" } else if buffer == "openbsd" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://openbsd.org/"}) buffer = "" } else if buffer == "linux" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "Linux sucks"}) buffer = "" } else if buffer == "mac" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "Yet another BSD-like OS"}) buffer = "" } else if buffer == "windows" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "Windows ALWAYS sucks"}) buffer = "" } else if buffer == "github" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://codeberg.org/"}) buffer = "" } else if buffer == "status" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "/status"}) buffer = "" } else if buffer == "reddit" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://www.reddit.com/r/openbsd/s/zxEkMj0uaW"}) buffer = "" } else if buffer == "intelme" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "Everything must be free, without tracking"}) buffer = "" } else if buffer == "amdpsp" { conn.WriteJSON(map[string]string{"action": "show_message", "message": "Everything must be free, without tracking"}) buffer = "" } else if buffer == "uefi" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "https://www.techtarget.com/searchsecurity/news/366618102/ESET-details-UEFI-Secure-Boot-bypass-vulnerability"}) buffer = "" } else if buffer == "trolling" { conn.WriteJSON(map[string]string{"action": "redirect", "url": "/trolling"}) buffer = "" } } } func trollingHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Server", "0BSD_FOR_EVERYONE") w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Frame-Options", "DENY") w.Header().Set("Referrer-Policy", "no-referrer") filePath := filepath.Clean("files/trolling.gif") if !strings.HasPrefix(filePath, "files/") { http.Error(w, "Forbidden", http.StatusForbidden) return } fileInfo, err := os.Stat(filePath) if err != nil { log.Printf("Ошибка чтения файла: %v", err) http.Error(w, "File not found", http.StatusNotFound) return } if fileInfo.Size() > 10*1024*1024 { http.Error(w, "File too large", http.StatusRequestEntityTooLarge) return } fileContent, err := os.ReadFile(filePath) if err != nil { log.Printf("Ошибка чтения файла: %v", err) http.Error(w, "Internal server error", http.StatusInternalServerError) return } base64Content := base64.StdEncoding.EncodeToString(fileContent) html := fmt.Sprintf(`