From 140be4e9dd22a447e7d20197c70cd1c82caa1c93 Mon Sep 17 00:00:00 2001 From: Odyssey346 Date: Fri, 29 Jul 2022 23:51:10 +0200 Subject: [PATCH] use your own webhook you leech and fix akisbug Signed-off-by: Odyssey346 --- api/form.go | 21 ++++++++++++++++----- main.go | 3 +-- static/form.html | 6 ++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/api/form.go b/api/form.go index 15505c0..0cce691 100644 --- a/api/form.go +++ b/api/form.go @@ -47,12 +47,23 @@ func theActualFormCode(w http.ResponseWriter, r *http.Request) { postData := url.Values{ "content": {"IP " + otherthings.GetUserIP(r) + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**\n https://abuseipdb.com/check/" + otherthings.GetUserIP(r)}, } - req, err := http.PostForm(webhookURL, postData) - if err != nil { - log.Fatal("Something went terribly wrong!", err) + if r.FormValue("webhook") != "" { + fmt.Fprintf(w, "\nThanks for trying Segfautilities Contact Form :)") + postData := url.Values{ + "content": {"**Note: you are currently testing our form example. Please check out the actual project at https://github.com/ProjectSegfault/segfautilities! It's not hard to self-host :)**\n" + "IP " + otherthings.GetUserIP(r) + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**\n https://abuseipdb.com/check/" + otherthings.GetUserIP(r)}, + } + req, err := http.PostForm(r.FormValue("webhook"), postData) + if err != nil { + log.Println("Someone tried to send a webhook, but it failed!") + } + fmt.Fprint(io.Discard, req) // I don't want the result of the demo request in stdout at ALL. + } else { + req, err := http.PostForm(webhookURL, postData) + if err != nil { + log.Fatal("Something went terribly wrong!", err) + } + fmt.Fprint(io.Discard, req) // Out with your request! I don't want it. } - - fmt.Fprint(io.Discard, req) // Out with your request! I don't want it. } default: http.Error(w, "Method isn't allowed!\nYou may only POST here, not " + r.Method, http.StatusMethodNotAllowed) diff --git a/main.go b/main.go index e567461..a8e9431 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ func main() { otherthings.CheckEnv() log.Println("[HTTP] Starting server") port := os.Getenv("SEGFAUTILITIES_PORT") - hcaptcha_site_key := os.Getenv("SEGFAUTILITIES_PORT") + hcaptcha_site_key := os.Getenv("HCAPTCHA_SITE_KEY") tmpl := template.Must(template.ParseFiles("static/index.html")) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data := StaticThingy{ @@ -35,7 +35,6 @@ func main() { tmpl_form := template.Must(template.ParseFiles("static/form.html")) http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) { data := StaticThingy{ - Port: port, HCaptchaSiteKey: hcaptcha_site_key, } tmpl_form.Execute(w, data) diff --git a/static/form.html b/static/form.html index ca18499..310c452 100644 --- a/static/form.html +++ b/static/form.html @@ -50,6 +50,12 @@ required placeholder="Your message" > +