diff --git a/.gitignore b/.gitignore index 9184d62..0e7e6c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ data/config.toml +data/options.json \ No newline at end of file diff --git a/api/form.go b/api/form.go index dade019..1a73e93 100644 --- a/api/form.go +++ b/api/form.go @@ -1,9 +1,12 @@ package api import ( + "io/ioutil" "log" "net/http" + "os" + "github.com/goccy/go-json" "github.com/kataras/hcaptcha" "fmt" @@ -22,6 +25,26 @@ var ( client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */ ) +func FormCheck() { + jsonFile, err := os.Open("./data/options.json") + if err != nil { + fmt.Println(err) + } + defer jsonFile.Close() + byteValue, _ := ioutil.ReadAll(jsonFile) + var result map[string]interface{} + json.Unmarshal([]byte(byteValue), &result) + res := result["Form"] + if res == "true" { + Form() + } else { + log.Println("Forms disabled") + http.HandleFunc("/api/form", func(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "Disabled") + }) + } +} + func Form() { http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode)) } diff --git a/main.go b/main.go index 810f05f..19fdeba 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ func main() { http.ServeFile(w, r, "static/announcements.html") }) api.Settings() - api.Form() + api.FormCheck() api.CheckAnn() log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!") log.Println(http.ListenAndServe(":"+config.Port(), nil))