From 6876522621fc240df704f47433fe8e9b780579a6 Mon Sep 17 00:00:00 2001 From: xoyxoyxoy <91625208+xoyxoyxoy@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:58:13 +0100 Subject: [PATCH] =?UTF-8?q?grundger=C3=BCst=20der=20neuen=20homepage,=20re?= =?UTF-8?q?konstrukt=20der=20alten=20neuen=20homepage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + file.go | 16 +++++ func.go | 104 ++++++++++++++++++++++++++++++++ go.mod | 3 + html.go | 44 ++++++++++++++ http.go | 46 +++++++++++++++ main.go | 5 ++ structs.go | 11 ++++ web/.DS_Store | Bin 0 -> 6148 bytes web/images/adresse_knopf.webp | Bin 0 -> 10858 bytes web/images/chat_knopf.webp | Bin 0 -> 10190 bytes web/images/header.jpg | Bin 0 -> 21264 bytes web/images/logo_ctdo.svg | 3 + web/images/mail_knopf.webp | Bin 0 -> 9972 bytes web/images/tel_knopf.webp | Bin 0 -> 8004 bytes web/pages/about.html | 52 ++++++++++++++++ web/pages/datenschutz.html | 22 +++++++ web/pages/events.html | 26 ++++++++ web/pages/home.html | 39 ++++++++++++ web/pages/impressum.html | 51 ++++++++++++++++ web/pages/kontakt.html | 35 +++++++++++ web/pages/kontakt/adresse.html | 32 ++++++++++ web/pages/kontakt/irc.html | 55 +++++++++++++++++ web/pages/kontakt/mail.html | 60 +++++++++++++++++++ web/pages/kontakt/tel.html | 25 ++++++++ web/pages/support.html | 37 ++++++++++++ web/pages/treff.html | 43 ++++++++++++++ web/pages/verein.html | 56 ++++++++++++++++++ web/styles/home.css | 4 ++ web/styles/kontakt.css | 16 +++++ web/styles/main.css | 105 +++++++++++++++++++++++++++++++++ 31 files changed, 891 insertions(+) create mode 100644 README.md create mode 100644 file.go create mode 100644 func.go create mode 100644 go.mod create mode 100644 html.go create mode 100644 http.go create mode 100644 main.go create mode 100644 structs.go create mode 100644 web/.DS_Store create mode 100644 web/images/adresse_knopf.webp create mode 100644 web/images/chat_knopf.webp create mode 100644 web/images/header.jpg create mode 100644 web/images/logo_ctdo.svg create mode 100644 web/images/mail_knopf.webp create mode 100644 web/images/tel_knopf.webp create mode 100644 web/pages/about.html create mode 100644 web/pages/datenschutz.html create mode 100644 web/pages/events.html create mode 100644 web/pages/home.html create mode 100644 web/pages/impressum.html create mode 100644 web/pages/kontakt.html create mode 100644 web/pages/kontakt/adresse.html create mode 100644 web/pages/kontakt/irc.html create mode 100644 web/pages/kontakt/mail.html create mode 100644 web/pages/kontakt/tel.html create mode 100644 web/pages/support.html create mode 100644 web/pages/treff.html create mode 100644 web/pages/verein.html create mode 100644 web/styles/home.css create mode 100644 web/styles/kontakt.css create mode 100644 web/styles/main.css diff --git a/README.md b/README.md new file mode 100644 index 0000000..ec46004 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Readme \ No newline at end of file diff --git a/file.go b/file.go new file mode 100644 index 0000000..c5bc322 --- /dev/null +++ b/file.go @@ -0,0 +1,16 @@ +package main + +import ( + "io/ioutil" + "log" +) + +func file_read(src string) string { + content, err := ioutil.ReadFile(src) + + if err != nil { + log.Fatal(err) + } + + return string(content) +} diff --git a/func.go b/func.go new file mode 100644 index 0000000..816e6d1 --- /dev/null +++ b/func.go @@ -0,0 +1,104 @@ +package main + +import ( + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func handler() { + //Pages + http_HandleFunc("home", "./web/pages/home.html", true, "text/html") + http_HandleFunc("treff", "./web/pages/treff.html", false, "text/html") + http_HandleFunc("events", "./web/pages/events.html", false, "text/html") + http_HandleFunc("about", "./web/pages/about.html", false, "text/html") + + http_HandleFunc("kontakt", "./web/pages/kontakt.html", false, "text/html") + http_HandleFunc("kontakt/adresse", "./web/pages/kontakt/adresse.html", false, "text/html") + http_HandleFunc("kontakt/irc", "./web/pages/kontakt/irc.html", false, "text/html") + http_HandleFunc("kontakt/mail", "./web/pages/kontakt/mail.html", false, "text/html") + http_HandleFunc("kontakt/tel", "./web/pages/kontakt/tel.html", false, "text/html") + + http_HandleFunc("verein", "./web/pages/verein.html", false, "text/html") + http_HandleFunc("support", "./web/pages/support.html", false, "text/html") + + http_HandleFunc("impressum", "./web/pages/impressum.html", false, "text/html") + http_HandleFunc("datenschutz", "./web/pages/datenschutz.html", false, "text/html") + + //Styles + http_HandleFunc("style/main.css", "./web/styles/main.css", false, "text/css") + http_HandleFunc("style/kontakt.css", "./web/styles/kontakt.css", false, "text/css") + http_HandleFunc("style/home.css", "./web/styles/home.css", false, "text/css") + + //Images + http_HandleFunc("image/logo_ctdo.svg", "./web/images/logo_ctdo.svg", false, "image/svg+xml") + http_HandleFunc("image/header.jpg", "./web/images/header.jpg", false, "image/jpeg") + http_HandleFunc("image/adresse_knopf.webp", "./web/images/adresse_knopf.webp", false, "image/webp") + http_HandleFunc("image/chat_knopf.webp", "./web/images/chat_knopf.webp", false, "image/webp") + http_HandleFunc("image/mail_knopf.webp", "./web/images/mail_knopf.webp", false, "image/webp") + http_HandleFunc("image/tel_knopf.webp", "./web/images/tel_knopf.webp", false, "image/webp") +} + +func getPages() [][]string { + output := [][]string{} + + output = append(output, []string{"home", "/home"}) + output = append(output, []string{"zeiten & location", "/treff"}) + output = append(output, []string{"events", "/events"}) + output = append(output, []string{"über uns", "/about"}) + output = append(output, []string{"kontakt", "/kontakt"}) + output = append(output, []string{"verein", "/verein"}) + output = append(output, []string{"unterstützung", "/support"}) + + return output +} + +func getFooterPages() [][]string { + output := [][]string{} + + output = append(output, []string{"impressum", "/impressum"}) + output = append(output, []string{"datenschutzerklärung", "/datenschutz"}) + + return output +} + +func getRoomState() status { + c := &http.Client{Timeout: 10 * time.Second} + r, err := c.Get("https://status.ctdo.de/api/simple/v2") + if err != nil { + panic(err) + } + defer r.Body.Close() + + body, _err := io.ReadAll(r.Body) + if _err != nil { + panic(_err) + } + + bodyString := string(body) + + temp := []string{} + + bodyString = strings.ReplaceAll(bodyString, "{", "") + bodyString = strings.ReplaceAll(bodyString, "}", "") + + _temp := strings.Split(bodyString, ",") + + for _, element := range _temp { + __temp := strings.Split(element, ":") + temp = append(temp, __temp[1]) + } + + roomState := new(status) + + roomState.state = temp[0] == "true" + var __err error + roomState.power, __err = strconv.ParseInt(temp[2], 0, 64) + if __err != nil { + panic(__err) + } + + return *roomState +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..65e558b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module xoy.dev/ctdo + +go 1.19 diff --git a/html.go b/html.go new file mode 100644 index 0000000..f57bc4d --- /dev/null +++ b/html.go @@ -0,0 +1,44 @@ +package main + +import "strings" + +func html_Element(tag string, innerHTML string, args string) string { + return "<" + tag + " " + args + ">" + innerHTML + "" + tag + ">" +} + +func html_LinkElement(innerHTML string, destination string, blank bool, args string) string { + b := "" + if blank { + b = "target=\"_blank\"" + } + + return html_Element("a", innerHTML, " href=\""+destination+"\" "+b) +} + +func html_InputElement(name string, _type string, value string, args string) string { + return "" +} + +func html_Nav(pages [][]string) string { + output := "" + + for _, page := range pages { + output += html_Element("li", html_LinkElement(page[0], page[1], false, ""), "") + } + + return html_Element("nav", html_Element("ul", output, ""), "") +} + +func html_replacer(input string) string { + output := strings.ReplaceAll(input, "!NAV", html_Nav(getPages())) + + if getRoomState().state { + output = strings.ReplaceAll(output, "!RAUMSTATUS", "
Raumstatus: offen
") + } else { + output = strings.ReplaceAll(output, "!RAUMSTATUS", "Raumstatus: geschlossen
") + } + + output = strings.ReplaceAll(output, "!FOOTERNAV", html_Nav(getFooterPages())) + + return output +} diff --git a/http.go b/http.go new file mode 100644 index 0000000..74c8cdf --- /dev/null +++ b/http.go @@ -0,0 +1,46 @@ +package main + +import ( + "errors" + "fmt" + "io" + "net/http" + "os" +) + +func http_HandleFunc(url_path string, filepath string, is_mainpage bool, content_type string) { + if is_mainpage { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", content_type) + io.WriteString(w, html_replacer(file_read(filepath))) + }) + } else { + s := new(submit) + s.data = "null" + http.HandleFunc("/"+url_path, func(w http.ResponseWriter, r *http.Request) { + if r.Method == "POST" { + if err := r.ParseForm(); err != nil { + fmt.Fprintf(w, "ParseForm() err: %v", err) + return + } + } + + w.Header().Add("Content-Type", content_type) + + io.WriteString(w, html_replacer(file_read(filepath))) + }) + } +} + +func http_start(address string) { // address could be = ":8080" + handler() + + err := http.ListenAndServe(address, nil) + + if errors.Is(err, http.ErrServerClosed) { + fmt.Printf("server closed\n") + } else if err != nil { + fmt.Printf("error starting server: %s\n", err) + os.Exit(1) + } +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..0faaad6 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + http_start(":80") +} diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..ff1f44b --- /dev/null +++ b/structs.go @@ -0,0 +1,11 @@ +package main + +type submit struct { + data string +} + +type status struct { + state bool + lastchange int64 + power int64 +} diff --git a/web/.DS_Store b/web/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6d1a987ed21a4f3d3ed2166ea5725aae42973f4b GIT binary patch literal 6148 zcmeHKy-veG47N+DT7g7I#v6Em_6
zZ?~2k1H}hM)lv%#a{I&ya=9V6bu>6+?;(U{GseDfU}|MQFp5OP2gsXqOLF>UKMd)I
zO3RdF!UxK!8-d=cPaj|;y`_NUgXPYD2O1Dce9s|@f{~&NF<|h>l;$@4(sP!2&8Vy>
zBoD_@fC_|9Qf+8rkLj&*e78^>^lpTu1Wtv;V$qgeAuK`aLex^z4bUzYi$%Lrd|dvj
zEh*kpkNx?EecFY9s}!M>$;p`N3PBfw9@|)EQcovMxPgb u!*hT>7mlxkQ;H
z#8~v+?)X7_0Y{)P`;CI-H`s1HIbjXMVNRM^g}RF^5=_qWRm;m}^aU2uAGza40z;q-
z8 hEIMFjc)t!(2RV++WH
z)Q6mty=qOM=on#3_HWNBJauopF%)F(9`m2dXUUln%kTV_TjF)qp>;ZmJV0=Z8u@}~
z6Mk;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