diff --git a/ctdo.sql b/ctdo.sql index ac93133..ee3fba7 100644 --- a/ctdo.sql +++ b/ctdo.sql @@ -7,4 +7,7 @@ create table events ( media varchar(10000), date varchar(10) not null, primary key(id) +); +create table adminKeys ( + adminKey varchar(16) not null ); \ No newline at end of file diff --git a/database.go b/database.go index e4fd191..aec9354 100644 --- a/database.go +++ b/database.go @@ -28,3 +28,9 @@ func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows { return results } + +func ctdoConnect() *sql.DB { + dbValues := readDatabaseYML() + + return dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database) +} diff --git a/events.go b/events.go index b6d7c8f..daf4d4f 100644 --- a/events.go +++ b/events.go @@ -1,9 +1,7 @@ package main func getEvents() []event { - dbValues := readDatabaseYML() - - db := dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database) + db := ctdoConnect() rows := dbQuerry(db, "SELECT * FROM events;") @@ -20,3 +18,38 @@ func getEvents() []event { return events } + +func addEvent(Event event) bool { + db := ctdoConnect() + + if len(Event.title) > 80 || len(Event.description) > 500 || len(Event.media) > 10000 || len(Event.date) > 10 { + return false + } + + dbQuerry(db, "insert into events (title, description, media, date) values ('"+Event.title+"', '"+Event.description+"', '"+Event.media+"', '"+Event.date+"');") + + return true +} + +func getAdminKeys() []string { + db := ctdoConnect() + + rows := dbQuerry(db, "select * from adminKeys;") + + output := []string{} + + for rows.Next() { + temp := "" + err := rows.Scan(temp) + if err != nil { + panic(err.Error()) + } + output = append(output, temp) + } + + if len(output) == 0 { + return nil + } + + return output +} diff --git a/func.go b/func.go index 054b9e2..7443858 100644 --- a/func.go +++ b/func.go @@ -2,6 +2,7 @@ package main import ( "io" + "math/rand" "net/http" "strconv" "strings" @@ -28,6 +29,14 @@ func handler() { httpHandleFunc("impressum", "./web/pages/impressum.html", "text/html") httpHandleFunc("datenschutz", "./web/pages/datenschutz.html", "text/html") + keys := getAdminKeys() + + if keys != nil { + for _, key := range keys { + httpHandleFunc("admin/"+key, "./web/pages/admin/dashboard.html", "text/html") + } + } + //Styles httpHandleFunc("style/main.css", "./web/styles/main.css", "text/css") httpHandleFunc("style/kontakt.css", "./web/styles/kontakt.css", "text/css") @@ -134,14 +143,16 @@ func htmlReplacer(input string, activePage string) string { output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+string(getNextTopic().days)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\"")) } - events := getEvents() + /* + events := getEvents() - if len(events) == 0 { - output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/")) - } else { + if len(events) == 0 { + output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/")) + } else { - output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/")) - } + output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/")) + } + */ output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/")) @@ -240,3 +251,16 @@ func readDatabaseYML() database { return *output } + +func generateRandomString(length int) string { + chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + chars += strings.ToLower(chars) + + output := "" + + for i := 0; i < length; i++ { + output += string(chars[rand.Intn(len(chars)-1)]) + } + + return output +} diff --git a/main.go b/main.go index d5d6f10..0ab12e4 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( ) func main() { - println(len(getEvents())) addr := ":80" handler() diff --git a/web/pages/admin/dashboard.html b/web/pages/admin/dashboard.html new file mode 100644 index 0000000..c6d50e1 --- /dev/null +++ b/web/pages/admin/dashboard.html @@ -0,0 +1,23 @@ + + + + + + + ctdo - admin + + + + +
+ ctdo logo + !NAV +
+
+ !RAUMSTATUS +
+ + + \ No newline at end of file diff --git a/web/styles/dashboard.css b/web/styles/dashboard.css new file mode 100644 index 0000000..e69de29