Compare commits
5 Commits
master
...
fotogaleri
| Author | SHA1 | Date |
|---|---|---|
|
|
c559b531b1 | 5 years ago |
|
|
b952023629 | 5 years ago |
|
|
2c83df5617 | 5 years ago |
|
|
6cd4508428 | 5 years ago |
|
|
07396413f9 | 5 years ago |
@ -1,36 +1,13 @@ |
|||||||
FROM golang:alpine as builder |
FROM nginx:alpine |
||||||
|
|
||||||
RUN apk --no-cache add --update \ |
COPY frontend/assets /usr/share/nginx/html/assets/ |
||||||
gcc \ |
COPY frontend/css /usr/share/nginx/html/css/ |
||||||
musl-dev \ |
COPY frontend/js /usr/share/nginx/html/js/ |
||||||
git \ |
COPY frontend/index.html /usr/share/nginx/html/ |
||||||
ca-certificates |
|
||||||
WORKDIR /go/src/gitea.ckris.de/titzi/anmeldeportal_hochzeit |
|
||||||
RUN CGO_ENABLED=1 go get -d -v github.com/mattn/go-sqlite3 |
|
||||||
COPY backend/go/src/server/main.go . |
|
||||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o backend . |
|
||||||
|
|
||||||
|
RUN addgroup -g 3333 -S web && \ |
||||||
|
adduser -h /web -u 3333 -G web -S web && \ |
||||||
FROM alpine:latest |
chown -R web:web . |
||||||
|
USER web |
||||||
RUN apk --no-cache add --update \ |
|
||||||
gcc \ |
|
||||||
musl-dev |
|
||||||
|
|
||||||
WORKDIR /go/ |
|
||||||
|
|
||||||
COPY --from=builder /go/src/gitea.ckris.de/titzi/anmeldeportal_hochzeit/backend . |
|
||||||
COPY frontend/assets ./frontend/assets/ |
|
||||||
COPY frontend/js ./frontend/js/ |
|
||||||
COPY frontend/css ./frontend/css/ |
|
||||||
COPY frontend/index.html ./frontend/ |
|
||||||
|
|
||||||
RUN addgroup -g 3333 -S go && \ |
|
||||||
adduser -h /go -u 3333 -G go -S go && \ |
|
||||||
chown -R go:go . |
|
||||||
USER go |
|
||||||
|
|
||||||
EXPOSE 8080 |
EXPOSE 8080 |
||||||
|
|
||||||
CMD ["./backend"] |
|
||||||
@ -1,184 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"database/sql" |
|
||||||
"fmt" |
|
||||||
_ "github.com/mattn/go-sqlite3" |
|
||||||
"log" |
|
||||||
"net/http" |
|
||||||
"strconv" |
|
||||||
) |
|
||||||
|
|
||||||
type Response struct { |
|
||||||
FirstName, Name string |
|
||||||
Answer string |
|
||||||
NumAdult, NumKids uint |
|
||||||
Vegi, Vegan bool |
|
||||||
NumVegi, NumVegan uint |
|
||||||
Allerien bool |
|
||||||
Allergene string |
|
||||||
Accumodation bool |
|
||||||
NumRooms uint |
|
||||||
Arrival string |
|
||||||
Musik string |
|
||||||
Email string |
|
||||||
Permission bool |
|
||||||
Covid19 string |
|
||||||
} |
|
||||||
|
|
||||||
func newRespose(db *sql.DB, row *Response) error { |
|
||||||
sqlStmt := fmt.Sprintf(`INSERT INTO response |
|
||||||
(fName, lName, answer, numAdult, numKids, vegi, numVegi, vegan, numVegan, allergiger, allergene, accommodation, numRooms, arrival, musik, email, permission, covid19) |
|
||||||
VALUES |
|
||||||
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`) |
|
||||||
|
|
||||||
tx, err := db.Begin() |
|
||||||
if err != nil { |
|
||||||
return err |
|
||||||
} |
|
||||||
|
|
||||||
stmt, err := tx.Prepare(sqlStmt) |
|
||||||
defer tx.Commit() |
|
||||||
if err != nil { |
|
||||||
return err |
|
||||||
} |
|
||||||
defer stmt.Close() |
|
||||||
|
|
||||||
log.Printf("Add new response: %s", row) |
|
||||||
_, err = stmt.Exec( |
|
||||||
row.FirstName, row.Name, |
|
||||||
row.Answer, |
|
||||||
row.NumAdult, row.NumKids, |
|
||||||
row.Vegi, row.NumVegi, |
|
||||||
row.Vegan, row.NumVegan, |
|
||||||
row.Allerien, row.Allergene, |
|
||||||
row.Accumodation, row.NumRooms, |
|
||||||
row.Arrival, |
|
||||||
row.Musik, |
|
||||||
row.Email, row.Permission, |
|
||||||
row.Covid19, |
|
||||||
) |
|
||||||
if err != nil { |
|
||||||
return err |
|
||||||
} |
|
||||||
|
|
||||||
return nil |
|
||||||
} |
|
||||||
|
|
||||||
func initDB(dbS string) (*sql.DB, error) { |
|
||||||
db, err := sql.Open("sqlite3", dbS) |
|
||||||
if err != nil { |
|
||||||
return nil, err |
|
||||||
} |
|
||||||
|
|
||||||
sqlStmt := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS response |
|
||||||
(id INTEGER NOT NULL PRIMARY KEY, |
|
||||||
fName TEXT NOT NULL, lName TEXT NOT NULL, |
|
||||||
answer TEXT NOT NULL, |
|
||||||
numAdult INTEGER NOT NULL, numKids INTEGER NOT NULL, |
|
||||||
vegi BOOLEAN, numVegi INTEGER, |
|
||||||
vegan BOOLEAN, numVegan INTEGER, |
|
||||||
allergiger BOOLEAN, allergene TEXT, |
|
||||||
accommodation BOOLEAN, numRooms INTEGER, |
|
||||||
arrival TEXT, |
|
||||||
musik TEXT, |
|
||||||
email TEXT, permission BOOLEAN, |
|
||||||
covid19 TEXT, |
|
||||||
created DATETIME DEFAULT CURRENT_TIMESTAMP);`) |
|
||||||
_, err = db.Exec(sqlStmt) |
|
||||||
if err != nil { |
|
||||||
return db, err |
|
||||||
} |
|
||||||
|
|
||||||
log.Printf("DB %s is up and running", dbS) |
|
||||||
return db, nil |
|
||||||
} |
|
||||||
|
|
||||||
func main() { |
|
||||||
// init database
|
|
||||||
db, err := initDB("data/response.sqlite") |
|
||||||
if err != nil { |
|
||||||
if db != nil { |
|
||||||
db.Close() |
|
||||||
} |
|
||||||
log.Panic(err) |
|
||||||
} |
|
||||||
defer db.Close() |
|
||||||
|
|
||||||
// init http server with two routes for onepage website and endpoint for sending the response
|
|
||||||
// http.Handle("/", httpLogHandler(http.FileServer(http.Dir("../../../../frontend"))))
|
|
||||||
http.Handle("/", httpLogHandler(http.FileServer(http.Dir("./frontend")))) |
|
||||||
http.HandleFunc("/response", func(w http.ResponseWriter, r *http.Request) { |
|
||||||
processAnmeldung(w, r, db) |
|
||||||
}) |
|
||||||
|
|
||||||
http.ListenAndServe(":8080", nil) |
|
||||||
} |
|
||||||
|
|
||||||
func parseBool(s string) bool { |
|
||||||
return s == "on" |
|
||||||
} |
|
||||||
|
|
||||||
func parseUInt(s string) uint { |
|
||||||
u64, err := strconv.ParseUint(s, 10, 32) |
|
||||||
if err != nil { |
|
||||||
return 0 |
|
||||||
} |
|
||||||
return uint(u64) |
|
||||||
} |
|
||||||
|
|
||||||
func httpLogHandler(h http.Handler) http.Handler { |
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
||||||
log.Printf("Webseiten Aufruf: '%v:%v' %v", r.Method, r.URL, r.Header) |
|
||||||
h.ServeHTTP(w, r) |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
func processAnmeldung(w http.ResponseWriter, r *http.Request, db *sql.DB) { |
|
||||||
log.Printf("Process Endpoint Aufruf: '%v:%v' %v", r.Method, r.URL, r.Header) |
|
||||||
|
|
||||||
if r.Method != http.MethodPost { |
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther) |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
// Call ParseForm() to parse the raw query and update r.PostForm and r.Form.
|
|
||||||
if err := r.ParseForm(); err != nil { |
|
||||||
fmt.Fprintf(w, "ParseForm() err: %v", err) |
|
||||||
w.WriteHeader(http.StatusInternalServerError) |
|
||||||
return |
|
||||||
} |
|
||||||
log.Printf("Post from website: %v", r.PostForm) |
|
||||||
|
|
||||||
response := Response{ |
|
||||||
FirstName: r.FormValue("firstname"), |
|
||||||
Name: r.FormValue("name"), |
|
||||||
Answer: r.FormValue("rueckmeldung"), |
|
||||||
NumAdult: parseUInt(r.FormValue("numAdult")), |
|
||||||
NumKids: parseUInt(r.FormValue("numKids")), |
|
||||||
Vegi: parseBool(r.FormValue("vegi")), |
|
||||||
Vegan: parseBool(r.FormValue("vegan")), |
|
||||||
NumVegi: parseUInt(r.FormValue("numVegi")), |
|
||||||
NumVegan: parseUInt(r.FormValue("numVegan")), |
|
||||||
Allergene: r.FormValue("allagene"), |
|
||||||
Allerien: parseBool(r.FormValue("allergiger")), |
|
||||||
Accumodation: parseBool(r.FormValue("unterkunft")), |
|
||||||
Arrival: r.FormValue("arrival"), |
|
||||||
NumRooms: parseUInt(r.FormValue("numUnterkunft")), |
|
||||||
Musik: r.FormValue("musik"), |
|
||||||
Email: r.FormValue("email"), |
|
||||||
Permission: parseBool(r.FormValue("weitergabe")), |
|
||||||
Covid19: r.FormValue("covid19"), |
|
||||||
} |
|
||||||
log.Printf("Form values parsed: %v", response) |
|
||||||
|
|
||||||
err := newRespose(db, &response) |
|
||||||
if err != nil { |
|
||||||
log.Print("Fehler beim einfügen in die DB: %v", err) |
|
||||||
w.WriteHeader(http.StatusInternalServerError) |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
//return success
|
|
||||||
w.WriteHeader(http.StatusCreated) |
|
||||||
} |
|
||||||
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 489 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 467 KiB |
|
After Width: | Height: | Size: 455 KiB |
|
After Width: | Height: | Size: 408 KiB |
|
After Width: | Height: | Size: 304 KiB |
|
After Width: | Height: | Size: 295 KiB |
|
After Width: | Height: | Size: 384 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 172 KiB |
|
After Width: | Height: | Size: 382 KiB |
|
After Width: | Height: | Size: 476 KiB |
|
After Width: | Height: | Size: 208 KiB |
|
After Width: | Height: | Size: 268 KiB |
|
After Width: | Height: | Size: 216 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 156 KiB |
|
After Width: | Height: | Size: 209 KiB |
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 332 KiB |
|
After Width: | Height: | Size: 340 KiB |
|
After Width: | Height: | Size: 504 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 168 KiB |
|
After Width: | Height: | Size: 553 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 170 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 340 KiB |
|
After Width: | Height: | Size: 436 KiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 328 KiB |
|
After Width: | Height: | Size: 408 KiB |
|
After Width: | Height: | Size: 531 KiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 420 KiB |
|
After Width: | Height: | Size: 250 KiB |
|
After Width: | Height: | Size: 482 KiB |
|
After Width: | Height: | Size: 657 KiB |
|
After Width: | Height: | Size: 483 KiB |
|
After Width: | Height: | Size: 384 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 225 KiB |
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 260 KiB |
|
After Width: | Height: | Size: 235 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 177 KiB |
|
After Width: | Height: | Size: 296 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 412 KiB |
|
After Width: | Height: | Size: 460 KiB |
|
After Width: | Height: | Size: 438 KiB |
|
After Width: | Height: | Size: 494 KiB |
|
After Width: | Height: | Size: 466 KiB |
|
After Width: | Height: | Size: 487 KiB |
|
After Width: | Height: | Size: 222 KiB |
|
After Width: | Height: | Size: 483 KiB |
|
After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 539 KiB |
|
After Width: | Height: | Size: 351 KiB |
|
After Width: | Height: | Size: 430 KiB |
|
After Width: | Height: | Size: 175 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 271 KiB |
|
After Width: | Height: | Size: 294 KiB |
|
After Width: | Height: | Size: 245 KiB |
|
After Width: | Height: | Size: 296 KiB |
|
After Width: | Height: | Size: 184 KiB |
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 165 KiB |
|
After Width: | Height: | Size: 168 KiB |