Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
data/config.toml
data/announcements.json
22 changes: 20 additions & 2 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,39 @@ pipeline:
build:
when:
event: [push, pull_request, tag, deployment]

image: golang:latest
commands:
- go build -o segfautils
dockerize_n_publish:
when:
branch : [master]
event: [push]
name: dockerize and publish
image: plugins/docker
image: plugins/docker
registry: git.projectsegfau.lt
repo: git.projectsegfau.lt/projectsegfault/segfautils
settings:
username:
from_secret: username
password:
from_secret: password
repo: projectsegfault/segfautils
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


23 changes: 23 additions & 0 deletions api/announcements.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,30 @@ import (

var (
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() {
http.HandleFunc("/api/announcements", getAnnouncements)
http.HandleFunc("/api/announcements/post", handleAnnouncements)
Expand All @@ -39,6 +61,7 @@ func handleAnnouncements(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
now := time.Now().Unix()
data := map[string]interface{}{
"enabled": "true",
"title": r.FormValue("title"),
"link": r.FormValue("link"),
"severity": r.FormValue("severity"),
Expand Down
39 changes: 33 additions & 6 deletions api/form.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
package api

import (
"log"
"net/http"

"github.com/kataras/hcaptcha"

"fmt"

"io"
"log"
"net/http"
"net/url"
"text/template"

"github.com/ProjectSegfault/segfautils/config"
"github.com/ProjectSegfault/segfautils/utils"
"github.com/kataras/hcaptcha"
)

var (
siteKey = config.HCaptchaSiteKey()
secretKey = config.HCaptchaSecretKey()
webhookURL = config.WebhookURL()
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() {
http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode))
}
Expand Down
15 changes: 15 additions & 0 deletions api/oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"github.com/ProjectSegfault/segfautils/config"
)

var (
clientID = config.OAuthClientID()
clientSecret = config.OAuthClientSecret()
redirectURL = config.OAuthRedirectURL()
authURL = config.OAuthURL()
)

func LoginOAuth() {
}
2 changes: 1 addition & 1 deletion config/authtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func AuthToken() string {
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
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")
return result
Expand Down
2 changes: 1 addition & 1 deletion config/hcaptchasecretkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func HCaptchaSecretKey() string {
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
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")
return result
Expand Down
2 changes: 1 addition & 1 deletion config/hcaptchasitekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func HCaptchaSiteKey() string {
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
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")
return result
Expand Down
18 changes: 18 additions & 0 deletions config/oauthclientid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"log"

"github.com/spf13/viper"
)

func OAuthClientID() string {
viper.SetConfigName("config")
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
if err != nil {
log.Println("Error reading config for getting oauth.client_id", err.Error())
}
result := viper.GetString("oauth.client_id")
return result
}
18 changes: 18 additions & 0 deletions config/oauthclientsecret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"log"

"github.com/spf13/viper"
)

func OAuthClientSecret() string {
viper.SetConfigName("config")
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
if err != nil {
log.Println("Error reading config for getting oauth.client_secret", err.Error())
}
result := viper.GetString("oauth.client_secret")
return result
}
18 changes: 18 additions & 0 deletions config/oauthredirect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"log"

"github.com/spf13/viper"
)

func OAuthRedirectURL() string {
viper.SetConfigName("config")
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
if err != nil {
log.Println("Error reading config for getting oauth.redirect_url", err.Error())
}
result := viper.GetString("oauth.redirect_url")
return result
}
18 changes: 18 additions & 0 deletions config/oauthurl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"log"

"github.com/spf13/viper"
)

func OAuthURL() string {
viper.SetConfigName("config")
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
if err != nil {
log.Println("Error reading config for getting oauth.auth_url", err.Error())
}
result := viper.GetString("oauth.auth_url")
return result
}
18 changes: 18 additions & 0 deletions config/optionannounce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
}
18 changes: 18 additions & 0 deletions config/optionform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
}
2 changes: 1 addition & 1 deletion config/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Port() string {
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
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"))
return result
Expand Down
2 changes: 1 addition & 1 deletion config/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func WebhookURL() string {
viper.AddConfigPath("./data")
err := viper.ReadInConfig()
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")
return result
Expand Down
12 changes: 11 additions & 1 deletion data/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ auth_token = "YOURAUTHTOKEN"

[hcaptcha]
site_key = "YOURSITEKEY"
secret_key = "YOURSECRETKEY"
secret_key = "YOURSECRETKEY"

[oauth]
client_id = "YOURCLIENTID"
client_secret = "YOURCLIENTSECRET"
redirect_url = "YOURREDIRECTURL"
auth_url = "YOURAUTHURL"

[options]
announce = true
form = false
8 changes: 8 additions & 0 deletions data/lol.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[segfautils]
port = 6893
webhook_url = "https://127.0.0.1:8080/segfautils"
auth_token = "121212"

[hcaptcha]
site_key = "lol"
secret_key = "lol2"
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/goccy/go-json v0.9.10 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/feeds v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/kataras/hcaptcha v0.0.0-20200711031247-2927d4faf32f // indirect
Expand All @@ -18,8 +19,12 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 //indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading