diff --git a/.gitignore b/.gitignore index dc32eb1..74696ce 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,9 @@ acecore *.exe # Logging -logs/ \ No newline at end of file +logs/ + +# Web + +web/key.pem +web/cert.pem \ No newline at end of file diff --git a/custom/custom.go b/custom/custom.go index f1a7174..9aa9c43 100644 --- a/custom/custom.go +++ b/custom/custom.go @@ -13,7 +13,7 @@ var color map[string]string = map[string]string{ "primary": "#211951", } -var Gh_url string = "https://github.com/vaporvee/acecore/blob/main/" +const Gh_url string = "https://github.com/vaporvee/acecore/blob/main/" func GetColor(s string) int { hexColor := strings.TrimPrefix(color[s], "#") diff --git a/custom/privacy.html b/custom/privacy.html new file mode 120000 index 0000000..c0f1dd9 --- /dev/null +++ b/custom/privacy.html @@ -0,0 +1 @@ +web/html/privacy.html \ No newline at end of file diff --git a/custom/tos.html b/custom/tos.html new file mode 120000 index 0000000..07ee4f5 --- /dev/null +++ b/custom/tos.html @@ -0,0 +1 @@ +web/html/tos.html \ No newline at end of file diff --git a/main.go b/main.go index a6f7de4..fd62121 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "github.com/joho/godotenv" "github.com/sirupsen/logrus" "github.com/vaporvee/acecore/log2webhook" + "github.com/vaporvee/acecore/web" ) var ( @@ -70,6 +71,7 @@ func main() { logrus.Error(err) } logrus.Infof("Bot is now running as '%s'!", app.Bot.Username) + go web.HostRoutes(app.Bot.ID.String()) sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) diff --git a/web/privacy/index.html b/web/html/privacy.html similarity index 100% rename from web/privacy/index.html rename to web/html/privacy.html diff --git a/web/tos/index.html b/web/html/tos.html similarity index 100% rename from web/tos/index.html rename to web/html/tos.html diff --git a/web/index.html b/web/index.html deleted file mode 100644 index 99cb63f..0000000 --- a/web/index.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - acecore - - - - -

Redirect

- - - \ No newline at end of file diff --git a/web/web.go b/web/web.go new file mode 100644 index 0000000..9f7eb90 --- /dev/null +++ b/web/web.go @@ -0,0 +1,53 @@ +package web + +import ( + "embed" + "log" + "net/http" + "text/template" + + "github.com/sirupsen/logrus" + "github.com/vaporvee/acecore/custom" +) + +// Embed the HTML file into the binary +// +//go:embed html/privacy.html +var privacyHTML embed.FS + +//go:embed html/tos.html +var tosHTML embed.FS + +func handleHTML(w http.ResponseWriter, embed embed.FS, path string) { + tmpl, err := template.ParseFS(embed, path) + if err != nil { + logrus.Error(err) + return + } + tmpl.Execute(w, nil) +} + +func HostRoutes(botID string) { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, custom.Gh_url, http.StatusMovedPermanently) + }) + http.HandleFunc("/invite", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "https://discord.com/oauth2/authorize?client_id="+botID, http.StatusMovedPermanently) + }) + http.HandleFunc("/privacy", func(w http.ResponseWriter, r *http.Request) { + handleHTML(w, privacyHTML, "./html/privacy.html") + }) + http.HandleFunc("/tos", func(w http.ResponseWriter, r *http.Request) { + handleHTML(w, tosHTML, "./html/tos.html") + }) + + server := &http.Server{ + Addr: ":443", + Handler: nil, + ErrorLog: log.New(nil, "", 0), + } + logrus.Info("Starting server for html routes on :443...") + if err := server.ListenAndServeTLS("./web/cert.pem", "./web/key.pem"); err != nil { + logrus.Errorf("Error starting server: %v\n", err) + } +}