Compare commits
4 Commits
427bec5081
...
41209f3ee3
Author | SHA1 | Date | |
---|---|---|---|
41209f3ee3 | |||
|
977136d9c2 | ||
|
b05c48cfbb | ||
|
11a792d96c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
data/config.toml
|
data/config.toml
|
||||||
|
data/options.json
|
@ -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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
api/form.go
23
api/form.go
@ -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))
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -1 +0,0 @@
|
|||||||
{"Announcements":"false","Form":"true"}
|
|
2
main.go
2
main.go
@ -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))
|
||||||
|
Reference in New Issue
Block a user