Compare commits

..

No commits in common. "main" and "dev" have entirely different histories.
main ... dev

13 changed files with 197 additions and 244 deletions

View file

@ -1,29 +0,0 @@
on:
push:
branches:
- main
jobs:
docker:
runs-on: ubuntu-22.04
steps:
# - run: "echo reg: ${{ env.GITHUB_SERVER_URL }}, act: ${{ github.actor }}, sec: ${{ github.token }}"
-
name: Login to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_SERVER_URL }}
username: ${{ github.actor }}
password: ${{ secrets.REG_TOKEN }}
# -
# name: Set up QEMU
# uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: git.mstar.dev/${{ env.GITHUB_REPOSITORY }}:latest

0
.gcloudignore Normal file
View file

8
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mstar.iml" filepath="$PROJECT_DIR$/.idea/mstar.iml" />
</modules>
</component>
</project>

9
.idea/mstar.iml Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM golang:1.23 AS build-stage FROM golang:1.21 AS build-stage
WORKDIR /app WORKDIR /app
COPY go.mod ./ COPY go.mod ./
@ -15,7 +15,7 @@ COPY robots.txt ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /mstar RUN CGO_ENABLED=0 GOOS=linux go build -o /mstar
FROM scratch AS build-release-stage FROM gcr.io/distroless/base-debian11 AS build-release-stage
WORKDIR / WORKDIR /

13
go.mod
View file

@ -1,15 +1,10 @@
module gitlab.com/evilthings-services/mstar module gitlab.com/evilthings-services/mstar
go 1.23.4 go 1.21.5
require ( require (
git.mstar.dev/mstar/goutils v1.6.1 github.com/sirupsen/logrus v1.9.3
github.com/rs/zerolog v1.33.0 gitlab.com/mstarongitlab/weblogger v0.0.0-20240123135616-d64461e3b20d
) )
require ( require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/rs/xid v1.5.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)

39
go.sum
View file

@ -1,22 +1,17 @@
git.mstar.dev/mstar/goutils v1.5.4 h1:l/4oQe/fBk9zyXplQkGXbmQndnm0aRdHuy4wgQfNrFo= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
git.mstar.dev/mstar/goutils v1.5.4/go.mod h1:juxY0eZEMnA95fedRp2LVXvUBgEjz66nE8SEdGKcxMA= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
git.mstar.dev/mstar/goutils v1.6.0 h1:2K0KqoymJoEJUIYVHkjJ0GJKGNeWVfHMmpeRMtNiG3Q= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
git.mstar.dev/mstar/goutils v1.6.0/go.mod h1:juxY0eZEMnA95fedRp2LVXvUBgEjz66nE8SEdGKcxMA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
git.mstar.dev/mstar/goutils v1.6.1 h1:2yr9GYN8CJByZsJRu1pZ6WBp51Nn+3zJq49ky54xYDk= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
git.mstar.dev/mstar/goutils v1.6.1/go.mod h1:juxY0eZEMnA95fedRp2LVXvUBgEjz66nE8SEdGKcxMA= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= gitlab.com/mstarongitlab/weblogger v0.0.0-20240123135616-d64461e3b20d h1:ixTYuViFIDQh9fs3xyc8sPKBr7dU7T98rs4kqM0q51k=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= gitlab.com/mstarongitlab/weblogger v0.0.0-20240123135616-d64461e3b20d/go.mod h1:8G+BrXVs97wI7W+Z4E8M2MXFFKKy01cVnFazoCpNg9Y=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

89
main.go
View file

@ -1,20 +1,14 @@
package main package main
import ( import (
"context"
"embed" "embed"
"flag"
"fmt" "fmt"
"html/template" "html/template"
"net/http" "net/http"
"os" "os"
"os/signal"
"time"
"git.mstar.dev/mstar/goutils/middleware" "github.com/sirupsen/logrus"
"git.mstar.dev/mstar/goutils/other" "gitlab.com/mstarongitlab/weblogger"
"github.com/rs/zerolog/hlog"
"github.com/rs/zerolog/log"
) )
const HTML_PREFIX = "<!-- " const HTML_PREFIX = "<!-- "
@ -36,59 +30,38 @@ var embed_robots_txt string
var embed_humans_txt string var embed_humans_txt string
func main() { func main() {
other.SetupFlags() port := os.Getenv("PORT")
portFlag := flag.String("port", "8080", "Set the port. Overwrites env vars") if port == "" {
flag.Parse() port = "8080"
other.ConfigureLoggingFromCliArgs() }
logrus.WithField("port", port).Info("starting server")
mux := http.NewServeMux() // Custom-ish paths. Includes templates
mux.HandleFunc("/{$}", handleRoot) http.HandleFunc("/", handleRoot)
// Catchall that just redirects to Hetzner's 10GB speedtest file
// TODO: Maybe swap that for a forced zip bomb?
mux.Handle(
"/",
http.RedirectHandler("https://hil-speed.hetzner.com/10GB.bin", http.StatusMovedPermanently),
)
mux.HandleFunc("/cat/awawawa", awawaStream) // Funny awawawa stream
http.HandleFunc("/cat/awawawa", awawaStream)
// static files in /static // static files in /static
mux.Handle("/static/", http.FileServer(http.FS(embed_static))) http.Handle("/static/", http.FileServer(http.FS(embed_static)))
// .well-known from /well-known // .well-known from /well-known
mux.Handle( http.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.FS(embed_well_known))))
"/.well-known/",
http.StripPrefix("/.well-known/", http.FileServer(http.FS(embed_well_known))),
)
// Static files not in /static or /.well-known // Static files not in /static or /.well-known
mux.HandleFunc("/robots.txt", buildHTTPFileReader(embed_robots_txt)) http.HandleFunc("/robots.txt", buildHTTPFileReader(embed_robots_txt))
mux.HandleFunc("/humans.txt", buildHTTPFileReader(embed_humans_txt)) http.HandleFunc("/humans.txt", buildHTTPFileReader(embed_humans_txt))
server := http.Server{ default_mux := http.DefaultServeMux
Addr: ":" + *portFlag, logger := weblogger.LoggingMiddleware(default_mux)
Handler: middleware.ChainMiddlewares(mux, middleware.LoggingMiddleware),
if err := http.ListenAndServe(":"+port, logger); err != nil {
logrus.WithField("event", "stop server").Fatal(err)
} }
exitChan := make(chan os.Signal, 1)
signal.Notify(exitChan, os.Interrupt)
go func() {
log.Info().Str("addr", server.Addr).Msg("Starting server")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatal().Err(err).Msg("Server exited unexpectedly")
}
}()
<-exitChan
log.Info().Msg("Shutting down server due to Interrupt")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
err := server.Shutdown(ctx)
if err != nil {
log.Fatal().Err(err).Msg("Failed to cleanly shut down")
}
log.Info().Msg("Clean shutdown complete")
} }
func handleRoot(w http.ResponseWriter, r *http.Request) { func handleRoot(w http.ResponseWriter, r *http.Request) {
// logRequestInfo(r)
tmpl, err := template.ParseFS(embed_templates, "templates/index.html") tmpl, err := template.ParseFS(embed_templates, "templates/index.html")
if err != nil { if err != nil {
http.Error(w, "Couldn't parse template file", http.StatusInternalServerError) http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
@ -102,6 +75,7 @@ func handleRoot(w http.ResponseWriter, r *http.Request) {
func buildHTTPFileReader(embed_content string) func(w http.ResponseWriter, r *http.Request) { func buildHTTPFileReader(embed_content string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
// logRequestInfo(r)
fmt.Fprintf(w, "%s", embed_content) fmt.Fprintf(w, "%s", embed_content)
} }
} }
@ -110,26 +84,21 @@ func awawaStream(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html") w.Header().Set("Content-Type", "text/html")
w.WriteHeader(206) w.WriteHeader(206)
w.Header().Set("Status", "206") w.Header().Set("Status", "206")
genStub( genStub(1024, w) // Hardcoded. Firefox & Chrome both have this value and a len of 0 wouldn't work
1024, fmt.Println("Starting awawawa stream")
w, i := 0
) // Hardcoded. Firefox & Chrome both have this value and a len of 0 wouldn't work
hlog.FromRequest(r).Debug().Msg("Starting stream")
i := true
// Only run every 0.2 seconds, aka 5 times a second
timer := time.Tick(time.Millisecond * 200)
for { for {
select { select {
case <-r.Context().Done(): case <-r.Context().Done():
hlog.FromRequest(r).Debug().Msg("Stream done") fmt.Println("awawawa Stream done")
return return
case <-timer: default:
if i { if i%2 == 0 {
fmt.Fprint(w, "a") fmt.Fprint(w, "a")
} else { } else {
fmt.Fprint(w, "w") fmt.Fprint(w, "w")
} }
i = !i i += 1
} }
} }
} }

View file

@ -15,6 +15,3 @@ Disallow: /
User-Agent: FacebookBot User-Agent: FacebookBot
Disallow: / Disallow: /
User-Agent: Googlebot
Disallow: /cat/awawawa

View file

@ -1,6 +1,5 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" href="/static/styles/index.css" /> <link rel="stylesheet" href="/static/styles/index.css" />
<meta charset="UTF-8" /> <meta charset="UTF-8" />
@ -38,16 +37,12 @@
<th>Link/Username</th> <th>Link/Username</th>
</tr> </tr>
<tr> <tr>
<td>Fedi (woem)</td> <td>Fedi</td>
<td> <td>
<a rel="me" href="https://woem.men/@mstar">https://woem.men/@mstar</a> <a rel="me" href="https://woem.men/@mstar"
>https://woem.men/@mstar</a
>
</td> </td>
<tr>
<td>Fedi (mkab, backup)</td>
<td>
<a rel="me" href="https://mk.absturztau.be/@mstar">https://mk.absturztau.be/@mstar</a>
</td>
</tr>
</tr> </tr>
<tr> <tr>
<td>Discord</td> <td>Discord</td>
@ -58,45 +53,48 @@
<tr> <tr>
<td>Pronouns page</td> <td>Pronouns page</td>
<td> <td>
<a href="https://en.pronouns.page/@m_evil">https://en.pronouns.page/@m_evil</a> <a href="https://en.pronouns.page/@m_evil"
>https://en.pronouns.page/@m_evil</a
>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Forgejo</td> <td>Gitlab</td>
<td> <td>
<a href="https://git.mstar.dev/mstar">https://git.mstar.dev/mstar</a> <a href="https://gitlab.com/mstarongitlab"
>https://gitlab.com/mstarongitlab</a
>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Gitlab (not actively used anymore)</td> <td>Github</td>
<td> <td>
<a href="https://gitlab.com/mstarongitlab">https://gitlab.com/mstarongitlab</a> <a href="https://github.com/mstarongithub/"
</td> >https://github.com/mstarongithub/</a
</tr> >
<tr>
<td>Github (same as Gitlab)</td>
<td>
<a href="https://github.com/mstarongithub/">https://github.com/mstarongithub/</a>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Twitch</td> <td>Twitch</td>
<td> <td>
<a href="https://twitch.tv/mstarontwitch">https://twitch.tv/mstarontwitch</a> <a href="https://twitch.tv/mstarontwitch"
>https://twitch.tv/mstarontwitch</a
>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Youtube</td> <td>Youtube</td>
<td> <td>
<a <a href="https://www.youtube.com/channel/UC-LklY_wt004i_30xcVohbg"
href="https://www.youtube.com/channel/UC-LklY_wt004i_30xcVohbg">https://www.youtube.com/channel/UC-LklY_wt004i_30xcVohbg</a> >https://www.youtube.com/channel/UC-LklY_wt004i_30xcVohbg</a
>
</td> </td>
</tr> </tr>
<tr> <tr>
<!-- Rickroll --> <!-- Rickroll -->
<td>Bluesky</td> <td>Twitter</td>
<td> <td>
<a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">https://bsky.app/profile/mstar.dev</a> <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">https://twitter.com/mstar</a>
</td> </td>
</tr> </tr>
</table> </table>
@ -105,17 +103,14 @@
<li><a href="https://linktr.ee/akijam">Fren Aki</a></li> <li><a href="https://linktr.ee/akijam">Fren Aki</a></li>
</ul> </ul>
<hr /> <hr />
<p>I'm also working on a Fediverse server, <a href="https://git.mstar.dev/mstar/linstrom">Linstrom</a></p>
<br>
<p>Todo: Add proper styling</p> <p>Todo: Add proper styling</p>
</div> </div>
</div> </div>
<footer> <footer>
<p>Contact: <a href="mailto:me@mstar.dev">me@mstar.dev (<a <p>Contact: <a href="mailto:me@mstar.dev">me@mstar.dev</> (<a href="/static/files/other/publickey.me@mstar.dev-27fcaabd3022acff023e6e2a053a2d9af0f03260.asc">Public PGP key</a>)</p>
href="/static/files/other/publickey.me@mstar.dev-27fcaabd3022acff023e6e2a053a2d9af0f03260.asc">Public PGP <p>Last updated: 20.04.2024</p>
key</a>)</p> <p>Privacy notice: This webserver stores no information</p>
<p>Last updated: 30.12.2024</p>
</footer> </footer>
</body> </body>
</html> </html>

View file

@ -1 +1 @@
https://ionos.com https://cloud.google.com