Compare commits
No commits in common. "daf1ffe95c4a6042f5c59887d96414414adcd81a" and "a18f76d206ff739c441b9b49fd397d8cf4ca9945" have entirely different histories.
daf1ffe95c
...
a18f76d206
2
.github/workflows/docker.yml
vendored
2
.github/workflows/docker.yml
vendored
@ -26,4 +26,4 @@ jobs:
|
|||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: realprojectsegfault/segfautils:latest
|
tags: projectsegfault/segfautils:latest
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
data/config.toml
|
data/config.toml
|
||||||
data/announcements.json
|
|
@ -7,12 +7,9 @@ pipeline:
|
|||||||
- go build -o segfautils
|
- go build -o segfautils
|
||||||
dockerize_n_publish:
|
dockerize_n_publish:
|
||||||
when:
|
when:
|
||||||
branch : [master]
|
|
||||||
event: [push]
|
event: [push]
|
||||||
name: dockerize and publish
|
name: dockerize and publish
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
registry: git.projectsegfau.lt
|
|
||||||
repo: git.projectsegfau.lt/projectsegfault/segfautils
|
|
||||||
settings:
|
settings:
|
||||||
username:
|
username:
|
||||||
from_secret: username
|
from_secret: username
|
||||||
@ -20,20 +17,6 @@ pipeline:
|
|||||||
from_secret: password
|
from_secret: password
|
||||||
repo: projectsegfault/segfautils
|
repo: projectsegfault/segfautils
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
dockerize_dev:
|
|
||||||
when:
|
|
||||||
event: [push]
|
|
||||||
image: plugins/docker
|
|
||||||
name: dockerize and publish dev
|
|
||||||
registry: git.projectsegfau.lt
|
|
||||||
repo: git.projectsegfau.lt/projectsegfault/segfautils
|
|
||||||
settings:
|
|
||||||
username:
|
|
||||||
from_secret: username
|
|
||||||
password:
|
|
||||||
from_secret: password
|
|
||||||
repo: projectsegfau.lt/segfautils
|
|
||||||
tags: dev
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,30 +15,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
authToken = config.AuthToken()
|
authToken = config.AuthToken()
|
||||||
resAnn = config.OptAnn()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func AnnCheck() {
|
|
||||||
if resAnn == "false" {
|
|
||||||
log.Println("[Segfautils] ℹ Announcements are disabled")
|
|
||||||
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.Error(w, "Announcements are disabled.", http.StatusServiceUnavailable)
|
|
||||||
})
|
|
||||||
http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.Error(w, "{\"enabled\": \"false\"}", http.StatusServiceUnavailable)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
AnnPage()
|
|
||||||
Announcements()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func AnnPage() {
|
|
||||||
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.ServeFile(w, r, "static/announcements.html")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func Announcements() {
|
func Announcements() {
|
||||||
http.HandleFunc("/api/announcements", getAnnouncements)
|
http.HandleFunc("/api/announcements", getAnnouncements)
|
||||||
http.HandleFunc("/api/announcements/post", handleAnnouncements)
|
http.HandleFunc("/api/announcements/post", handleAnnouncements)
|
||||||
@ -61,7 +39,6 @@ func handleAnnouncements(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"enabled": "true",
|
|
||||||
"title": r.FormValue("title"),
|
"title": r.FormValue("title"),
|
||||||
"link": r.FormValue("link"),
|
"link": r.FormValue("link"),
|
||||||
"severity": r.FormValue("severity"),
|
"severity": r.FormValue("severity"),
|
||||||
|
39
api/form.go
39
api/form.go
@ -1,16 +1,18 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/kataras/hcaptcha"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/ProjectSegfault/segfautils/config"
|
"github.com/ProjectSegfault/segfautils/config"
|
||||||
"github.com/ProjectSegfault/segfautils/utils"
|
"github.com/ProjectSegfault/segfautils/utils"
|
||||||
"github.com/kataras/hcaptcha"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -18,37 +20,8 @@ var (
|
|||||||
secretKey = config.HCaptchaSecretKey()
|
secretKey = config.HCaptchaSecretKey()
|
||||||
webhookURL = config.WebhookURL()
|
webhookURL = config.WebhookURL()
|
||||||
client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */
|
client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */
|
||||||
resForm = config.OptForm()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormCheck() {
|
|
||||||
if resForm == "false" {
|
|
||||||
log.Println("[Segfautils] ℹ Contact form is disabled")
|
|
||||||
http.HandleFunc("/form", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.Error(w, "Form is disabled.", http.StatusServiceUnavailable)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
FormPage()
|
|
||||||
Form()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func FormPage() {
|
|
||||||
type StaticThing struct {
|
|
||||||
HCaptchaSiteKey string
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl_form := template.Must(template.ParseFiles("static/form.html"))
|
|
||||||
http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
hcaptcha_site_key := config.HCaptchaSiteKey()
|
|
||||||
data := StaticThing{
|
|
||||||
HCaptchaSiteKey: hcaptcha_site_key,
|
|
||||||
}
|
|
||||||
tmpl_form.Execute(w, data)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
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. Error getting: segfautils.auth_token", err.Error())
|
log.Println("Error reading config for 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. Error getting: hcaptcha.secret_key", err.Error())
|
log.Println("Error reading config for 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. Error getting: hcaptcha.site_key", err.Error())
|
log.Println("Error reading config for getting hcaptcha.site_key", err.Error())
|
||||||
}
|
}
|
||||||
result := viper.GetString("hcaptcha.site_key")
|
result := viper.GetString("hcaptcha.site_key")
|
||||||
return result
|
return result
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func OptAnn() string {
|
|
||||||
viper.SetConfigName("config")
|
|
||||||
viper.AddConfigPath("./data")
|
|
||||||
err := viper.ReadInConfig()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error reading config. Error getting: options.announce", err.Error())
|
|
||||||
}
|
|
||||||
result := viper.GetString("options.announce")
|
|
||||||
return result
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func OptForm() string {
|
|
||||||
viper.SetConfigName("config")
|
|
||||||
viper.AddConfigPath("./data")
|
|
||||||
err := viper.ReadInConfig()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error reading config. Error getting: options.form", err.Error())
|
|
||||||
}
|
|
||||||
result := viper.GetString("options.form")
|
|
||||||
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. Error getting: segfautils.port", err.Error())
|
log.Println("Error reading config for 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. Error getting: segfautils.webhook_url", err.Error())
|
log.Println("Error reading config for getting segfautils.webhook_url", err.Error())
|
||||||
}
|
}
|
||||||
result := viper.GetString("segfautils.webhook_url")
|
result := viper.GetString("segfautils.webhook_url")
|
||||||
return result
|
return result
|
||||||
|
@ -6,7 +6,3 @@ auth_token = "YOURAUTHTOKEN"
|
|||||||
[hcaptcha]
|
[hcaptcha]
|
||||||
site_key = "YOURSITEKEY"
|
site_key = "YOURSITEKEY"
|
||||||
secret_key = "YOURSECRETKEY"
|
secret_key = "YOURSECRETKEY"
|
||||||
|
|
||||||
[options]
|
|
||||||
announce = true
|
|
||||||
form = false
|
|
23
main.go
23
main.go
@ -13,12 +13,17 @@ import (
|
|||||||
|
|
||||||
type StaticThingy struct {
|
type StaticThingy struct {
|
||||||
Port string
|
Port string
|
||||||
|
HCaptchaSiteKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var port string
|
||||||
|
var shit bool
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("[Segfautils] Starting")
|
log.Println("[Segfautils] Starting")
|
||||||
utils.CheckConfig()
|
utils.CheckConfig()
|
||||||
|
log.Println("[HTTP] Starting server")
|
||||||
|
hcaptcha_site_key := config.HCaptchaSiteKey()
|
||||||
tmpl := template.Must(template.ParseFiles("static/index.html"))
|
tmpl := template.Must(template.ParseFiles("static/index.html"))
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := StaticThingy{
|
data := StaticThingy{
|
||||||
@ -27,14 +32,22 @@ func main() {
|
|||||||
tmpl.Execute(w, data)
|
tmpl.Execute(w, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("[HTTP] Starting server")
|
tmpl_form := template.Must(template.ParseFiles("static/form.html"))
|
||||||
api.AnnCheck()
|
http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
api.FormCheck()
|
data := StaticThingy{
|
||||||
|
HCaptchaSiteKey: hcaptcha_site_key,
|
||||||
|
}
|
||||||
|
tmpl_form.Execute(w, data)
|
||||||
|
})
|
||||||
|
|
||||||
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
io.WriteString(w, "welcome to hell")
|
io.WriteString(w, "welcome to hell")
|
||||||
})
|
})
|
||||||
|
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.ServeFile(w, r, "static/announcements.html")
|
||||||
|
})
|
||||||
|
api.Form()
|
||||||
|
api.Announcements()
|
||||||
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