whoopsie
This commit is contained in:
parent
8cce4351f1
commit
2037c78dd3
54
main.go
54
main.go
@ -8,7 +8,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -60,8 +59,6 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var buffer string
|
var buffer string
|
||||||
var lastPress time.Time
|
var lastPress time.Time
|
||||||
var messageCount int
|
|
||||||
startTime := time.Now()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var keyPress KeyPress
|
var keyPress KeyPress
|
||||||
@ -76,15 +73,6 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
lastPress = now
|
lastPress = now
|
||||||
|
|
||||||
messageCount++
|
|
||||||
if messageCount > 1000 || now.Sub(startTime) > 10*time.Minute {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(keyPress.Key) > 1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += keyPress.Key
|
buffer += keyPress.Key
|
||||||
|
|
||||||
if len(buffer) > 20 {
|
if len(buffer) > 20 {
|
||||||
@ -155,33 +143,11 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
func trollingHandler(w http.ResponseWriter, r *http.Request) {
|
func trollingHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.Header().Set("Server", "0BSD_FOR_EVERYONE")
|
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")
|
fileContent, err := os.ReadFile("files/trolling.gif")
|
||||||
if !strings.HasPrefix(filePath, "files/") {
|
|
||||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fileInfo, err := os.Stat(filePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Ошибка чтения файла: %v", err)
|
log.Printf("Ошибка чтения файла: %v", err)
|
||||||
http.Error(w, "File not found", http.StatusNotFound)
|
fileContent = []byte("Файл не найден")
|
||||||
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)
|
base64Content := base64.StdEncoding.EncodeToString(fileContent)
|
||||||
@ -191,7 +157,6 @@ func trollingHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Trolling</title>
|
<title>Trolling</title>
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src data:;">
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: #000;
|
background-color: #000;
|
||||||
@ -220,8 +185,6 @@ func trollingHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
func statusHandler(w http.ResponseWriter, r *http.Request) {
|
func statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.Header().Set("Server", "0BSD_FOR_EVERYONE")
|
w.Header().Set("Server", "0BSD_FOR_EVERYONE")
|
||||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
||||||
w.Header().Set("X-Frame-Options", "DENY")
|
|
||||||
|
|
||||||
openbsdBirth := time.Date(1995, 10, 1, 0, 0, 0, 0, time.UTC)
|
openbsdBirth := time.Date(1995, 10, 1, 0, 0, 0, 0, time.UTC)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -249,8 +212,6 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("X-Powered-By", "0BSD_FOR_EVERYONE")
|
w.Header().Set("X-Powered-By", "0BSD_FOR_EVERYONE")
|
||||||
w.Header().Set("X-Frame-Options", "SAMEORIGIN")
|
w.Header().Set("X-Frame-Options", "SAMEORIGIN")
|
||||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
w.Header().Set("Referrer-Policy", "no-referrer")
|
|
||||||
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';")
|
|
||||||
|
|
||||||
html := `
|
html := `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -329,12 +290,11 @@ func main() {
|
|||||||
mux.HandleFunc("/trolling", gzipHandler(trollingHandler))
|
mux.HandleFunc("/trolling", gzipHandler(trollingHandler))
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: ":" + p,
|
Addr: ":" + p,
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
ReadTimeout: 30 * time.Second,
|
ReadTimeout: 30 * time.Second,
|
||||||
WriteTimeout: 30 * time.Second,
|
WriteTimeout: 30 * time.Second,
|
||||||
IdleTimeout: 60 * time.Second,
|
IdleTimeout: 60 * time.Second,
|
||||||
MaxHeaderBytes: 1 << 20,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Сервер запущен на порту %s", p)
|
log.Printf("Сервер запущен на порту %s", p)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user