Rename to Segfautils

Signed-off-by: Odyssey346 <odyssey346@disroot.org>
This commit is contained in:
Odyssey346 2022-08-02 10:41:17 +02:00
parent 68e2c6475e
commit 2f6fbed9c0
11 changed files with 122 additions and 118 deletions

View File

@ -26,4 +26,4 @@ jobs:
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
push: true push: true
tags: projectsegfault/segfautilities:latest tags: projectsegfault/segfautils:latest

View File

@ -1,15 +1,15 @@
FROM golang:1.18-alpine3.16 FROM golang:1.18-alpine3.16
ENV SEGFAUTILITIES_PORT 6893 ENV SEGFAUTILS_PORT 6893
RUN mkdir /segfautilities RUN mkdir /segfautils
WORKDIR /segfautilities WORKDIR /segfautils
COPY . /segfautilities/ COPY . /segfautils/
RUN go mod download RUN go mod download
EXPOSE 6893 EXPOSE 6893
RUN go build -o segfautilities RUN go build -o segfautils
RUN chmod +x segfautilities RUN chmod +x segfautils
RUN go clean -modcache RUN go clean -modcache
CMD ["./segfautilities"] CMD ["./segfautils"]

View File

@ -1,24 +1,24 @@
package api package api
import ( import (
"net/http"
"log" "log"
"net/http"
"github.com/kataras/hcaptcha" "github.com/kataras/hcaptcha"
"os"
"fmt" "fmt"
"os"
"net/url"
"io" "io"
"net/url"
"github.com/ProjectSegfault/segfautilities/otherthings" "github.com/ProjectSegfault/segfautils/otherthings"
) )
var ( var (
siteKey = os.Getenv("HCAPTCHA_SITE_KEY") siteKey = os.Getenv("HCAPTCHA_SITE_KEY")
secretKey = os.Getenv("HCAPTCHA_SECRET_KEY") secretKey = os.Getenv("HCAPTCHA_SECRET_KEY")
webhookURL = os.Getenv("SEGFAUTILITIES_WEBHOOK_URL") webhookURL = os.Getenv("SEGFAUTILS_WEBHOOK_URL")
client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */ client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */
) )
@ -48,9 +48,9 @@ func theActualFormCode(w http.ResponseWriter, r *http.Request) {
"content": {"IP " + otherthings.GetUserIP(r) + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**\n https://abuseipdb.com/check/" + otherthings.GetUserIP(r)}, "content": {"IP " + otherthings.GetUserIP(r) + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**\n https://abuseipdb.com/check/" + otherthings.GetUserIP(r)},
} }
if r.FormValue("webhook") != "" { if r.FormValue("webhook") != "" {
fmt.Fprintf(w, "\nThanks for trying Segfautilities Contact Form :)") fmt.Fprintf(w, "\nThanks for trying Segfautils Contact Form :)")
postData := url.Values{ postData := url.Values{
"content": {"**Note: you are currently testing our form example. Please check out the actual project at https://github.com/ProjectSegfault/segfautilities! It's not hard to self-host :)**\n" + "IP " + otherthings.GetUserIP(r) + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**\n https://abuseipdb.com/check/" + otherthings.GetUserIP(r)}, "content": {"**Note: you are currently testing our form example. Please check out the actual project at https://github.com/ProjectSegfault/segfautils if you found this neat! It's not hard to self-host :)**\n" + "IP " + otherthings.GetUserIP(r) + "\nFrom " + r.FormValue("email") + " with feedback type " + r.FormValue("commentType") + ":\n" + "**" + r.FormValue("message") + "**\n https://abuseipdb.com/check/" + otherthings.GetUserIP(r)},
} }
req, err := http.PostForm(r.FormValue("webhook"), postData) req, err := http.PostForm(r.FormValue("webhook"), postData)
if err != nil { if err != nil {

View File

@ -1,3 +1,3 @@
HCAPTCHA_SITE_KEY=YOURSITEKEY HCAPTCHA_SITE_KEY=YOURSITEKEY
HCAPTCHA_SECRET_KEY=YOURSECRETKEY HCAPTCHA_SECRET_KEY=YOURSECRETKEY
SEGFAUTILITIES_WEBHOOK_URL=YOURWEBHOOKURL SEGFAUTILS_WEBHOOK_URL=YOURWEBHOOKURL

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/ProjectSegfault/segfautilities module github.com/ProjectSegfault/segfautils
go 1.18 go 1.18

11
main.go
View File

@ -1,13 +1,14 @@
package main package main
import ( import (
"net/http"
"html/template" "html/template"
"io" "io"
"log" "log"
"github.com/ProjectSegfault/segfautilities/otherthings" "net/http"
"os" "os"
"github.com/ProjectSegfault/segfautilities/api"
"github.com/ProjectSegfault/segfautils/api"
"github.com/ProjectSegfault/segfautils/otherthings"
) )
type StaticThingy struct { type StaticThingy struct {
@ -19,10 +20,10 @@ var port string
var shit bool var shit bool
func main() { func main() {
log.Println("[Segfautilities] Starting") log.Println("[Segfautils] Starting")
otherthings.CheckEnv() otherthings.CheckEnv()
log.Println("[HTTP] Starting server") log.Println("[HTTP] Starting server")
port := os.Getenv("SEGFAUTILITIES_PORT") port := os.Getenv("SEGFAUTILS_PORT")
hcaptcha_site_key := os.Getenv("HCAPTCHA_SITE_KEY") hcaptcha_site_key := os.Getenv("HCAPTCHA_SITE_KEY")
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) {

View File

@ -2,8 +2,8 @@
package otherthings package otherthings
import ( import (
"os"
"log" "log"
"os"
) )
var ( var (
@ -12,29 +12,29 @@ var (
) )
func CheckEnv() { func CheckEnv() {
unused, ok1 = os.LookupEnv("SEGFAUTILITIES_PORT") unused, ok1 = os.LookupEnv("SEGFAUTILS_PORT")
if ok1 { if ok1 {
log.Println("[Segfautilities] Environment variable SEGFAUTILITIES_PORT is set as " + unused) log.Println("[Segfautils] Environment variable SEGFAUTILS_PORT is set as " + unused)
} else { } else {
log.Fatal("[Segfautilities] Environment variable SEGFAUTILITIES_PORT is not set! Please set it to a number, for example 6893") log.Fatal("[Segfautils] Environment variable SEGFAUTILS_PORT is not set! Please set it to a number, for example 6893")
} }
unused, ok1 = os.LookupEnv("HCAPTCHA_SITE_KEY") unused, ok1 = os.LookupEnv("HCAPTCHA_SITE_KEY")
if !ok1 || unused == "YOURSITEKEY" { if !ok1 || unused == "YOURSITEKEY" {
log.Fatal("[Segfautilities] Environment variable HCAPTCHA_SITE_KEY is not set! Please set it to the site key you got from hCaptcha.") log.Fatal("[Segfautils] Environment variable HCAPTCHA_SITE_KEY is not set! Please set it to the site key you got from hCaptcha.")
} else { } else {
log.Println("[Segfautilities] Environment variable HCAPTCHA_SITE_KEY is set as " + unused) log.Println("[Segfautils] Environment variable HCAPTCHA_SITE_KEY is set as " + unused)
} }
unused, ok1 = os.LookupEnv("HCAPTCHA_SECRET_KEY") unused, ok1 = os.LookupEnv("HCAPTCHA_SECRET_KEY")
if !ok1 || unused == "YOURSECRETKEY" { if !ok1 || unused == "YOURSECRETKEY" {
log.Fatal("[Segfautilities] Environment variable HCAPTCHA_SECRET_KEY is not set! Please set it to the secret key you got from hCaptcha.") log.Fatal("[Segfautils] Environment variable HCAPTCHA_SECRET_KEY is not set! Please set it to the secret key you got from hCaptcha.")
} else { } else {
log.Println("[Segfautilities] Environment variable HCAPTCHA_SECRET_KEY is set!") log.Println("[Segfautils] Environment variable HCAPTCHA_SECRET_KEY is set!")
} }
unused, ok1 = os.LookupEnv("SEGFAUTILITIES_WEBHOOK_URL") unused, ok1 = os.LookupEnv("SEGFAUTILS_WEBHOOK_URL")
if !ok1 || unused == "YOURWEBHOOKURL" { if !ok1 || unused == "YOURWEBHOOKURL" {
log.Fatal("[Segfautilities] Environment variable SEGFAUTILITIES_WEBHOOK_URL is not set! Please set it to your webhook URL. If that URL doesn't work, make an issue on GitHub!") log.Fatal("[Segfautils] Environment variable SEGFAUTILS_WEBHOOK_URL is not set! Please set it to your webhook URL. If that URL doesn't work, make an issue on GitHub!")
} else { } else {
log.Println("[Segfautilities] Environment variable SEGFAUTILITIES_WEBHOOK_URL is set!") log.Println("[Segfautils] Environment variable SEGFAUTILS_WEBHOOK_URL is set!")
} }
log.Println("[Segfautilities] ✅ Passed the Environment Variables check") log.Println("[Segfautils] ✅ Passed the Environment Variables check")
} }

View File

@ -1,4 +1,4 @@
# Segfautilities # Segfautils
Web utilities for Project Segfault Web utilities for Project Segfault
## What does it do? ## What does it do?
@ -8,27 +8,30 @@ For now it powers our contact form. In the future we will expand our APIs so you
### Docker: ### Docker:
``` ```
docker run -d --restart=always -p 6893:6893 --name segfautilities projectsegfault/segfautilities:latest --env-file ./docker.env docker run -d --restart=always -p 6893:6893 --name segfautils projectsegfault/segfautils:latest --env-file ./docker.env
``` ```
docker.env should be the environment file located in this repository, customized to your settings. The env file is self-documenting so I don't need to go in any detail here. docker.env should be the environment file located in this repository, customized to your settings. The env file is self-documenting so I don't need to go in any detail here.
We recommend using Docker as it provides better security (we suck in security, so that's why) and we are constantly updating Segfautilities. Docker makes it easy to update the program. We recommend using Docker as it provides better security (we suck in security, so that's why) and we are constantly updating Segfautils. Docker makes it easy to update the program.
If you're using Portainer, you should know how to add Segfautilities. If you're using Portainer, you should know how to add Segfautils.
### Manual (recommended for development) ### Manual (recommended for development)
``` ```
git clone https://github.com/ProjectSegfault/segfautilities git clone https://github.com/ProjectSegfault/segfautils
cd segfautilities/ cd segfautils/
# You need to add the environment HCAPTCHA_SITE_KEY, HCAPTCHA_SECRET_KEY, SEGFAUTILITIES_WEBHOOK_URL and SEGFAUTILITIES_PORT. # You need to add the environment HCAPTCHA_SITE_KEY, HCAPTCHA_SECRET_KEY, SEGFAUTILS_WEBHOOK_URL and SEGFAUTILS_PORT.
go run main.go # Run this when you've done above! go run main.go # Run this when you've done above, and you're planning on developing, if not, do below
go build . -o segfautils
./segfautils
``` ```
#### NixOS #### NixOS
``` ```
git clone https://github.com/ProjectSegfault/segfautilities git clone https://github.com/ProjectSegfault/segfautils
cd segfautilities/ cd segfautils/
nix-shell # Avoid installing Go and setting up the web port, by just running a nix shell nix-shell # Avoid installing Go and setting up the web port, by just running a nix shell
# You still need the environment variables HCAPTCHA_SITE_KEY, HCAPTCHA_SECRET_KEY and SEGFAUTILITIES_WEBHOOK_URL though! # You still need the environment variables HCAPTCHA_SITE_KEY, HCAPTCHA_SECRET_KEY and SEGFAUTILS_WEBHOOK_URL though!
go run main.go # I wonder if this is good practice or not. If this isn't good practice, make a GitHub issue please. go run main.go # If you're developing
go build . -o segfautils && ./segfautils # If you're intending to use Segfautils for production.
``` ```

View File

@ -6,7 +6,7 @@ pkgs.mkShell {
pkgs.go pkgs.go
]; ];
shellHook = '' shellHook = ''
export SEGFAUTILITIES_PORT=6893 export SEGFAUTILS_PORT=6893
echo "Go installed, have your fun" echo "Go installed, have your fun"
''; '';
} }

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Segfautilites form implementation example</title> <title>Segfautils form implementation example</title>
<style> <style>
body { body {
background-color: #252525; background-color: #252525;

View File

@ -3,7 +3,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Segfautilites</title> <title>Segfautils</title>
<style> <style>
body { body {
background-color: #252525; background-color: #252525;
@ -21,7 +21,7 @@
</style> </style>
</head> </head>
<body> <body>
<h1>Welcome to Segfautilities</h1> <h1>Welcome to Segfautils</h1>
<h3>Running at port {{.Port}} | <a href="https://github.com/ProjectSegfault/segfautilities/" target="_blank">GitHub</a></h3> <h3>Running at port {{.Port}} | <a href="https://github.com/ProjectSegfault/segfautils/" target="_blank">GitHub</a></h3>
<h3><a href="/form">Click here for an example form implementation</a></h3> <h3><a href="/form">Click here for an example form implementation</a></h3>
</body> </body>