Compare commits

...

4 Commits

Author SHA1 Message Date
41209f3ee3
ignore options.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-09-17 22:18:21 +01:00
Odyssey
977136d9c2 h
Signed-off-by: Odyssey <odyssey346@disroot.org>
2022-09-17 23:08:33 +02:00
Odyssey
b05c48cfbb no options.sjon
Signed-off-by: Odyssey <odyssey346@disroot.org>
2022-09-17 23:04:03 +02:00
Odyssey
11a792d96c improve grammar here
Signed-off-by: Odyssey <odyssey346@disroot.org>
2022-09-17 23:03:47 +02:00
12 changed files with 33 additions and 10 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
data/config.toml data/config.toml
data/options.json

View File

@ -33,7 +33,7 @@ func CheckAnn() {
} else { } else {
log.Println("Announcements disabled") log.Println("Announcements disabled")
http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Disabled") http.Error(w, "Announcements are disabled.", http.StatusNotFound)
}) })
} }
} }

View File

@ -1,9 +1,12 @@
package api package api
import ( import (
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os"
"github.com/goccy/go-json"
"github.com/kataras/hcaptcha" "github.com/kataras/hcaptcha"
"fmt" "fmt"
@ -22,6 +25,26 @@ var (
client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */ 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() { func Form() {
http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode)) http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode))
} }

View File

@ -15,7 +15,7 @@ func AuthToken() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting segfautils.auth_token", err.Error()) log.Println("Error reading config. Error getting: segfautils.auth_token", err.Error())
} }
result := viper.GetString("segfautils.auth_token") result := viper.GetString("segfautils.auth_token")
return result return result

View File

@ -11,7 +11,7 @@ func HCaptchaSecretKey() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting hcaptcha.secret_key", err.Error()) log.Println("Error reading config. Error getting: hcaptcha.secret_key", err.Error())
} }
result := viper.GetString("hcaptcha.secret_key") result := viper.GetString("hcaptcha.secret_key")
return result return result

View File

@ -11,7 +11,7 @@ func HCaptchaSiteKey() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting hcaptcha.site_key", err.Error()) log.Println("Error reading config. Error getting: hcaptcha.site_key", err.Error())
} }
result := viper.GetString("hcaptcha.site_key") result := viper.GetString("hcaptcha.site_key")
return result return result

View File

@ -11,7 +11,7 @@ func OptForm() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting options.form", err.Error()) log.Println("Error reading config. Error getting: options.form", err.Error())
} }
result := viper.GetString("options.form") result := viper.GetString("options.form")
return result return result

View File

@ -11,7 +11,7 @@ func OptAnn() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting options.announce", err.Error()) log.Println("Error reading config. Error getting: options.announce", err.Error())
} }
result := viper.GetString("options.announce") result := viper.GetString("options.announce")
return result return result

View File

@ -12,7 +12,7 @@ func Port() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting segfautils.port", err.Error()) log.Println("Error reading config. Error getting: segfautils.port", err.Error())
} }
result := strconv.Itoa(viper.GetInt("segfautils.port")) result := strconv.Itoa(viper.GetInt("segfautils.port"))
return result return result

View File

@ -11,7 +11,7 @@ func WebhookURL() string {
viper.AddConfigPath("./data") viper.AddConfigPath("./data")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Println("Error reading config for getting segfautils.webhook_url", err.Error()) log.Println("Error reading config. Error getting: segfautils.webhook_url", err.Error())
} }
result := viper.GetString("segfautils.webhook_url") result := viper.GetString("segfautils.webhook_url")
return result return result

View File

@ -1 +0,0 @@
{"Announcements":"false","Form":"true"}

View File

@ -47,7 +47,7 @@ func main() {
http.ServeFile(w, r, "static/announcements.html") http.ServeFile(w, r, "static/announcements.html")
}) })
api.Settings() api.Settings()
api.Form() api.FormCheck()
api.CheckAnn() api.CheckAnn()
log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!") log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!")
log.Println(http.ListenAndServe(":"+config.Port(), nil)) log.Println(http.ListenAndServe(":"+config.Port(), nil))