From 9bd3f8333ac9ed6396e1a5d198bed9cc6f454686 Mon Sep 17 00:00:00 2001 From: Odyssey346 Date: Wed, 27 Jul 2022 20:07:18 +0200 Subject: [PATCH] less hardcoding Signed-off-by: Odyssey346 --- api/form.go | 30 +++++++++++++++--------------- otherthings/checkenv.go | 6 ++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/api/form.go b/api/form.go index 8346209..cf2c993 100644 --- a/api/form.go +++ b/api/form.go @@ -17,6 +17,7 @@ import ( var ( siteKey = os.Getenv("HCAPTCHA_SITE_KEY") secretKey = os.Getenv("HCAPTCHA_SECRET_KEY") + webhookURL = os.Getenv("SEGFAUTILITIES_WEBHOOK_URL") ) var ( @@ -39,27 +40,26 @@ func theActualFormCode(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusUnauthorized) fmt.Fprint(w, "Seems like captcha failed, you didn't complete the captcha or you are a bot. Please try again.\nPlease note that your IP has been logged in our systems for manual review to check if you're an abusive user. If you're seen as abusive, you will be blacklisted.") postData := url.Values{ - "content": {"IP " + r.RemoteAddr + "failed captcha!"}, + "content": {"IP " + r.RemoteAddr + "failed captcha! [AbuseIPDB](https://abuseipdb.com/check/" + r.RemoteAddr}, } - req, err := http.PostForm("https://canary.discord.com/api/webhooks/1001546472971587674/XpxdpvlrEvEo7jnRmWyrEudTW0eNC_LpNVd-uC20R44e_efgwvhzSNQ26IaGeO9yan6f", postData) + req, err := http.PostForm(webhookURL, postData) if err != nil { - log.Fatal(err) + log.Fatal("Something went terribly wrong!", err) } fmt.Fprint(io.Discard, req) // I don't want the result of the request in stdout - return - } - log.Printf(r.FormValue("aisdjaoidjoiajsidaoj")) - fmt.Fprintf(w, "Thanks for your message, and thanks for doing the captcha!\n%#+v", hcaptchaResp) - postData := url.Values{ - "content": {"IP " + r.RemoteAddr + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**"}, - } - req, err := http.PostForm("https://discord.com/api/webhooks/1001546472971587674/XpxdpvlrEvEo7jnRmWyrEudTW0eNC_LpNVd-uC20R44e_efgwvhzSNQ26IaGeO9yan6f", postData) - if err != nil { - log.Fatal(err) - } + } else { + fmt.Fprintf(w, "Thanks for your message, and thanks for doing the captcha!\n%#+v", hcaptchaResp) + postData := url.Values{ + "content": {"IP " + r.RemoteAddr + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**"}, + } + 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/otherthings/checkenv.go b/otherthings/checkenv.go index 9333619..4130249 100644 --- a/otherthings/checkenv.go +++ b/otherthings/checkenv.go @@ -30,5 +30,11 @@ func CheckEnv() { } else { log.Println("[Segfautilities] Environment variable HCAPTCHA_SECRET_KEY is set!") } + unused, ok1 = os.LookupEnv("SEGFAUTILITIES_WEBHOOK_URL") + if !ok1 { + log.Fatal("[Segfautilities] Environment variable SEGFAUTILITIES_WEBHOOK_URL is not set! Please set it to your webhook URL. If that URL doesn't work, make an issue on GitHub!") + } else { + log.Println("[Segfautilities] Environment variable SEGFAUTILITIES_WEBHOOK_URL is set!") + } log.Println("[Segfautilities] ✅ Passed the Environment Variables check") } \ No newline at end of file