From 55568d6efd85c691bcfeded55285cedc5355bfcb Mon Sep 17 00:00:00 2001 From: sp Date: Sun, 10 Jul 2022 01:20:35 +1000 Subject: [PATCH] collective commit before overhaul --- .gitignore | 3 ++ Dockerfile | 27 +++++++++++++ config.go | 66 +++++++++++++++++++++++++++----- config.json | 6 ++- deploy/config_production.json | 4 +- form_contactus.go | 17 ++++++-- go.mod | 9 +++++ html/assets/icons/address.png | Bin 0 -> 352 bytes html/assets/icons/email.png | Bin 0 -> 170 bytes html/assets/icons/facebook.png | Bin 0 -> 515 bytes html/assets/icons/instagram.png | Bin 0 -> 638 bytes html/assets/icons/link.png | Bin 0 -> 216 bytes html/assets/icons/linkedin.png | Bin 0 -> 300 bytes html/assets/icons/phone.png | Bin 0 -> 177 bytes html/assets/icons/twitter.png | Bin 0 -> 681 bytes http_handler.go | 37 +++++++++++++----- http_video.go | 22 +++++++++-- main.go | 3 ++ rsync.go | 25 ++++++++++++ 19 files changed, 192 insertions(+), 27 deletions(-) create mode 100644 Dockerfile create mode 100644 go.mod create mode 100644 html/assets/icons/address.png create mode 100644 html/assets/icons/email.png create mode 100644 html/assets/icons/facebook.png create mode 100644 html/assets/icons/instagram.png create mode 100644 html/assets/icons/link.png create mode 100644 html/assets/icons/linkedin.png create mode 100644 html/assets/icons/phone.png create mode 100644 html/assets/icons/twitter.png create mode 100644 rsync.go diff --git a/.gitignore b/.gitignore index d8f181c..e2cd304 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /cert/ +/goweb +/vendor +/deploy/biukopweb-html/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4f3b7ad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM alpine:3.16 + +# make sure it support go binary library +# https://stackoverflow.com/questions/34729748/installed-go-binary-not-found-in-path-on-alpine-linux-docker +RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 + +# we don't compile golang at alpine, but we will compile it at somewhere else. +ENV GO111MODULE=on +ENV GOFLAGS=-mod=vendor + +#APP HOME +ENV APP_HOME /biukop/web +RUN mkdir -p "$APP_HOME" + +#update static html files +RUN mkdir -p $APP_HOME/html +COPY ./deploy/biukopweb-html $APP_HOME/html + +#copy production configuration file +COPY ./deploy/config_production.json $APP_HOME/config.json +COPY ./goweb $APP_HOME/goweb + +WORKDIR "$APP_HOME" +EXPOSE 8080 + +ENV PATH "$APP_HOME:$PATH" +CMD ["goweb", "-f", "config.json"] \ No newline at end of file diff --git a/config.go b/config.go index a94fcc8..e7d0986 100644 --- a/config.go +++ b/config.go @@ -4,24 +4,28 @@ import ( "encoding/json" "io/ioutil" "log" + "os" + "path/filepath" ) type configStaticHtml struct { Dir string StaticUrl string StripPrefix string + Sync string } type configuration struct { - Host string - Port string - DSN string - TlsCert string - TlsKey string - Static []configStaticHtml - Debug bool - TempDir string - Session struct { //TODO: figure what is this intended for + Host string + Port string + DSN string + TlsCert string + TlsKey string + RSyncKey string + Static []configStaticHtml + Debug bool + TempDir string + Session struct { //TODO: figure what is this intended for Guest bool Year int //how many years Month int //how many years @@ -41,8 +45,52 @@ func (m *configuration) readConfig() (e error) { } e = json.Unmarshal(body, m) + // Check upload dir and defaults + if !config.checkUploadDir() { + log.Fatal("bad config file", configFile) + return + } + if config.Debug { log.Println(config) } return } + +func (m *configuration) checkUploadDir() (valid bool) { + valid = true + for idx, node := range m.Static { + if node.StaticUrl == "/" { + if !fileExists(node.Dir) { + valid = false + log.Fatal(" html / not exist ", node) + } else { + // convert to absolute path : fileDir + p, e := filepath.Abs(node.Dir) + if e != nil { + valid = false + log.Fatal("bad html (webroot) dir ", node, e) + } + m.Static[idx].Dir = p + string(os.PathSeparator) //change it to absolute dir + } + } + } + + // convert rsync key file to absolute dir + p, e := filepath.Abs(config.RSyncKey) + if e != nil { + valid = false + log.Fatal("bad html (webroot) dir ", config.RSyncKey, e) + } + m.RSyncKey = p //change it to absolute dir + + return +} + +func fileExists(path string) bool { + if _, err := os.Stat(path); os.IsNotExist(err) { + // path/to/whatever does not exist + return false + } + return true +} diff --git a/config.json b/config.json index abfdb80..d51864d 100644 --- a/config.json +++ b/config.json @@ -5,11 +5,13 @@ "TlsCert": "cert/fullchain.pem", "TlsKey": "cert/privkey.pem", "Debug": true, + "RSyncKey": "cert/rsync.key", "Static": [ { - "Dir": "/mnt/hgfs/workspace/2021-07-31-BiukopWeb", + "Dir": "./deploy/biukopweb-html/", "StaticUrl": "/", - "StripPrefix" : "/" + "StripPrefix" : "/", + "Sync": "a@c5015.biukop.com.au:/home/a/public_html/" }, { "Dir": "./html/test/", diff --git a/deploy/config_production.json b/deploy/config_production.json index b612a4c..dfff480 100644 --- a/deploy/config_production.json +++ b/deploy/config_production.json @@ -5,11 +5,13 @@ "TlsCert": "cert/fullchain.pem", "TlsKey": "cert/privkey.pem", "Debug": true, + "RSyncKey": "cert/rsync.key", "Static": [ { "Dir": "./html/", "StaticUrl": "/", - "StripPrefix" : "/" + "StripPrefix" : "/", + "Sync": "a@c5015.biukop.com.au:/home/a/public_html/" }, { "Dir": "./html/test/", diff --git a/form_contactus.go b/form_contactus.go index 35d10cf..5a60880 100644 --- a/form_contactus.go +++ b/form_contactus.go @@ -24,7 +24,18 @@ func formMain(w http.ResponseWriter, r *http.Request) { func (m *formInput) contactUs() { ret := map[string]interface{}{} ret["success"] = true - m.r.ParseForm() + // e := m.r.ParseForm() + e := m.r.ParseMultipartForm(32 * 1024 * 1024) + if e != nil { + return + } + + for key, values := range m.r.Form { // range over map + for _, value := range values { // range over []string + fmt.Println(key, value) + } + } + name := m.r.FormValue("name") email := m.r.FormValue("email") message := m.r.FormValue("message") @@ -65,12 +76,12 @@ func sendContactUs(name string, email string, userInput string) { smtpHost := "smtp.gmail.com" smtpPort := "587" - raw := `Subject: {name} Contact form on Biukop Web + raw := `Subject: {name} [ Contact form on Biukop Web ] Content-Type: text/plain; charset="UTF-8" Dear Manager, - We receive a a form submission from biukop.com.au + We received a a form submission from biukop.com.au name : {name} email : {email} message: diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4195161 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/lawipac/biukopweb + +go 1.18 + +require ( + github.com/gorilla/websocket v1.5.0 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect + golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect +) diff --git a/html/assets/icons/address.png b/html/assets/icons/address.png new file mode 100644 index 0000000000000000000000000000000000000000..d3730b2569f1448309b72bd8e84471fd14a456cd GIT binary patch literal 352 zcmV-m0iXVfP)52R#}VTK_hw~BGhHJ2PI z#toK;%*km74w++#wP)?X6EU$CaIOTL5fBru2?z49&jg3q^ePW8Y!JRHIk>1F1{&_x-AoYKIkk;V&VQDTE4!b=40V6ws~#8rn2etOp~)s+9;tYBUpYu z{dB70+!GTcF0h7`DH$72ocooDxp7)&Z|}ru2Rb(G(S8y;t=h+sJMiJx-=CQ+ny!di Tay8utTF&6<>gTe~DWM4f?*2W4 literal 0 HcmV?d00001 diff --git a/html/assets/icons/facebook.png b/html/assets/icons/facebook.png new file mode 100644 index 0000000000000000000000000000000000000000..08e9214ef6cd3fb526a13ef67615bcd588cd945c GIT binary patch literal 515 zcmV+e0{s1nP)1F zc541AAy5K^{Aa+vDT?p^l=ytUvqJMo5y6KC2R1BNu;IXij|geAvpV=TLkJgbs6Ez( zix8O}AVC0Yuk@x_2$0ACIY#JG;w$T7gq#J$=!?Wx)3@Luh=0Gk7V$P9*NmL~5tY{gqm#-PHrfOv!fnNE zz2pxN&~BG_#4{Fn$E??QH+J%{0?Y&eU%{g$4lux^0?f;&0hJg% z1&0FcjxWm3QLr@uAC#Z1$W698UbupQ1q?A5c{1bVS@%fQcZAY<7`#0S+6c zx&TkI(R2X5Bvt4DB1y871IlE_r)xRDl^r;8KqxyhrGWL3$sYPQSd{ie0s@0&%h?Mr z1Eu5Hi(dofyMYG8KnrD{2{h2g8fe4~TqPK}3^~zt&M$NiWFgo&jCBA2002ovPDHLk FV1h7G;Q;^u literal 0 HcmV?d00001 diff --git a/html/assets/icons/instagram.png b/html/assets/icons/instagram.png new file mode 100644 index 0000000000000000000000000000000000000000..8441a2b1a7039e0609241d5d511e3734bc4e6b39 GIT binary patch literal 638 zcmV-^0)hRBP){C9Yz#RNfS{}`UsGSo)i?6Gzig9 z`1cit4?B$iVB+<3p56C$XLjH0u8{m~n9!m@jS3}7RH)IQ#e_|AXNmQ0aj0{PMA$8L z9JbjA*0d=_LIz>jv1jhB{S#mhzDM|)wFhQQ?^6TBci;3g4_C}f5g zgaV^Df)O`Y!3)Aom_kCqDO?Tj&%)IRR#(LSJQu6q1YX9K6TPCmFo7M>@EMCSQ|2sK z25iBcDPt_2BYN6Fg0;G>9{D8A_sOHW_0}hXwhI3Pzz&xIJvvwc>(FC>%MO4am7;wl z*s7Z2kG?}OHr7QthgoPEwe<-cHTFJy9QYk?ydnn*Efc~*#VZ) zq7K4F)%!8v{`yy?iH%K@DuVC|*6Qd%-zcV!_G1 zWTq?n-B8i*UQ+Z899wcfco{f4=6?7!aC|p#0WoleGH?kraE&!^5jXIZVB|66kDhb> Y0m6|Am9;9C+W-In07*qoM6N<$f}mX&tpET3 literal 0 HcmV?d00001 diff --git a/html/assets/icons/link.png b/html/assets/icons/link.png new file mode 100644 index 0000000000000000000000000000000000000000..ecfb77343ed2f86cda796d458807ce7ccd7e1285 GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+i`JOJ0Ar-gIPT9!Y>>$7reu!0| zfn!AzpFoI1Qj*sKW-SL3$6%K!4(yMQoUmHFedn9+i{k&X)PJu&l$E|f#j&GhQsdpY z36{A}UaT(KW^h5#<@}d*>P{tz3a%l?RtiK)2rM%5>-BidAT`VS0P{sAb|)E!-_jDA z5xg6M4B8rlzoBBi6u4SWdS16n9jxC@t{*aIL6at3a&n~pXDeH8rJtJq6+ znrB<{NhA9`i&!-tONqfyV)4|mLBYDgQK%&f9L--q#aIb3rfLH#2Fi#5s}QL2_A64| zfF>QL6|A`c?tb*eiDd?HAnM1>Z~_h)pr95$IQZniJR8dk8*E1yM%Oyzg*T?WMt~J% zu-yQgTjd*oAKn8;DNF)*Xcst48u;ad347oe1F1+`Nn!yIN3scEElJE;fQ_%U8}RYN ybpV%#3tOWLa6Oyv-|gLFfO?E*k5AyqZ{`ezP~Sm*Zu~|700002(*;J)78&qol`;+0LmUddH?_b literal 0 HcmV?d00001 diff --git a/html/assets/icons/twitter.png b/html/assets/icons/twitter.png new file mode 100644 index 0000000000000000000000000000000000000000..69d3c537e2844159dfb8e9720016913a7629a57a GIT binary patch literal 681 zcmV;a0#^NrP)1W+Zt*n4uO2sE{97UJ&wBY=8_053x zh$}~5QSCuMX-nk=q0|p(q}*1?wq9cc5Tty04_A4>edgKSo7i1LzY4m5rZMNta!`>! z&(FT4agqbv;te|uIjY$KghrWVzOdi${1mN$z0(3(oHGD~umkXnfDgboW{0-XXG8XS z!DDV4G&~R@CEvdXV2vB>=zDrp$;wZSDmfyds*LoL-piku??J8@<;!YOstUf+bz)Qb zDRYe@EEoY7)b-{IMWt(sWsK{p(^mBNaS@+;EOD1bJSJ0E zgCIlOvhBtz1M9f$<~IZTp1}bmgCkT1hrkSuu^Al1Gq_5~&2 stderr") + stdoutStderr, err := cmd.CombinedOutput() + if err != nil { + log.Error(err) + break + } + log.Printf("%s\n", stdoutStderr) + time.Sleep(5 * time.Second) + } +}