From d9776254c6259d221da0a05b0df5b53a67daa019 Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Fri, 27 Dec 2024 15:05:42 +0200 Subject: [PATCH] Rewriting in GO (currently just posts listing) --- .gitignore | 3 +- Dockerfile | 3 - Makefile | 21 +- compose.yaml | 12 - go.mod | 21 ++ go.sum | 49 ++++ index.html | 73 ++++++ main.go | 115 ++++++++++ src/api/.htaccess | 4 - src/api/index.php | 20 -- src/data/.gitignore | 5 - src/data/.htaccess | 2 - src/inc/.htaccess | 2 - src/inc/database.php | 213 ------------------ src/index.php | 110 --------- src/login.php | 16 -- src/logout.php | 7 - src/post.php | 14 -- {src => static}/snufficon/angel.png | Bin {src => static}/snufficon/angry.png | Bin {src => static}/snufficon/cat_face.png | Bin {src => static}/snufficon/clown.png | Bin {src => static}/snufficon/cold.png | Bin {src => static}/snufficon/cold_sweat.png | Bin {src => static}/snufficon/cowboy.png | Bin {src => static}/snufficon/cross_eyes.png | Bin .../snufficon/disappointed_relieved.png | Bin {src => static}/snufficon/drool.png | Bin {src => static}/snufficon/excited.png | Bin {src => static}/snufficon/exploding_head.png | Bin {src => static}/snufficon/expressionless.png | Bin {src => static}/snufficon/fearful.png | Bin {src => static}/snufficon/flush.png | Bin {src => static}/snufficon/giggle.png | Bin {src => static}/snufficon/hand_over_mouth.png | Bin {src => static}/snufficon/happy.png | Bin {src => static}/snufficon/head_bandage.png | Bin {src => static}/snufficon/heart_eyes.png | Bin .../snufficon/holding_back_tears.png | Bin {src => static}/snufficon/hot.png | Bin {src => static}/snufficon/hug.png | Bin {src => static}/snufficon/joy.png | Bin {src => static}/snufficon/kissing.png | Bin {src => static}/snufficon/kissing_heart.png | Bin {src => static}/snufficon/laughing.png | Bin {src => static}/snufficon/lying.png | Bin {src => static}/snufficon/mask.png | Bin {src => static}/snufficon/melting.png | Bin {src => static}/snufficon/money_face.png | Bin {src => static}/snufficon/monocle.png | Bin {src => static}/snufficon/mouthless.png | Bin {src => static}/snufficon/nerd.png | Bin {src => static}/snufficon/partying.png | Bin {src => static}/snufficon/peeking_eye.png | Bin {src => static}/snufficon/pleading_face.png | Bin {src => static}/snufficon/raging.png | Bin {src => static}/snufficon/raised_eyebrow.png | Bin {src => static}/snufficon/rolling_eyes.png | Bin {src => static}/snufficon/sad.png | Bin {src => static}/snufficon/saluting.png | Bin {src => static}/snufficon/scream.png | Bin {src => static}/snufficon/see_no_evil.png | Bin {src => static}/snufficon/shrug.png | Bin {src => static}/snufficon/shush.png | Bin {src => static}/snufficon/sick.png | Bin {src => static}/snufficon/sleeping.png | Bin {src => static}/snufficon/smiling.png | Bin .../snufficon/smiling_with_hearts.png | Bin .../snufficon/smiling_with_stars.png | Bin {src => static}/snufficon/smirk.png | Bin {src => static}/snufficon/sneeze.png | Bin {src => static}/snufficon/snuffmas.png | Bin {src => static}/snufficon/sob.png | Bin {src => static}/snufficon/spiral_eyes.png | Bin {src => static}/snufficon/star_struck.png | Bin {src => static}/snufficon/sunglasses.png | Bin {src => static}/snufficon/swearing.png | Bin {src => static}/snufficon/sweat.png | Bin {src => static}/snufficon/sweat_smile.png | Bin {src => static}/snufficon/thermometer.png | Bin {src => static}/snufficon/thinking.png | Bin {src => static}/snufficon/thumbs_down.png | Bin {src => static}/snufficon/thumbs_up.png | Bin {src => static}/snufficon/tongue_out.png | Bin .../snufficon/tongue_out_closed_eyes.png | Bin .../snufficon/tongue_out_winking.png | Bin {src => static}/snufficon/triumph.png | Bin {src => static}/snufficon/upside_down.png | Bin {src => static}/snufficon/vomiting.png | Bin {src => static}/snufficon/wink.png | Bin {src => static}/snufficon/woozy.png | Bin {src => static}/snufficon/yawning.png | Bin {src => static}/snufficon/zany.png | Bin {src => static}/snufficon/zipper_mouth.png | Bin {src => static}/style.css | 0 95 files changed, 264 insertions(+), 426 deletions(-) delete mode 100644 Dockerfile delete mode 100644 compose.yaml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 index.html create mode 100644 main.go delete mode 100644 src/api/.htaccess delete mode 100644 src/api/index.php delete mode 100644 src/data/.gitignore delete mode 100755 src/data/.htaccess delete mode 100755 src/inc/.htaccess delete mode 100755 src/inc/database.php delete mode 100755 src/index.php delete mode 100644 src/login.php delete mode 100644 src/logout.php delete mode 100644 src/post.php rename {src => static}/snufficon/angel.png (100%) rename {src => static}/snufficon/angry.png (100%) rename {src => static}/snufficon/cat_face.png (100%) rename {src => static}/snufficon/clown.png (100%) rename {src => static}/snufficon/cold.png (100%) rename {src => static}/snufficon/cold_sweat.png (100%) rename {src => static}/snufficon/cowboy.png (100%) rename {src => static}/snufficon/cross_eyes.png (100%) rename {src => static}/snufficon/disappointed_relieved.png (100%) rename {src => static}/snufficon/drool.png (100%) rename {src => static}/snufficon/excited.png (100%) rename {src => static}/snufficon/exploding_head.png (100%) rename {src => static}/snufficon/expressionless.png (100%) rename {src => static}/snufficon/fearful.png (100%) rename {src => static}/snufficon/flush.png (100%) rename {src => static}/snufficon/giggle.png (100%) rename {src => static}/snufficon/hand_over_mouth.png (100%) rename {src => static}/snufficon/happy.png (100%) rename {src => static}/snufficon/head_bandage.png (100%) rename {src => static}/snufficon/heart_eyes.png (100%) rename {src => static}/snufficon/holding_back_tears.png (100%) rename {src => static}/snufficon/hot.png (100%) rename {src => static}/snufficon/hug.png (100%) rename {src => static}/snufficon/joy.png (100%) rename {src => static}/snufficon/kissing.png (100%) rename {src => static}/snufficon/kissing_heart.png (100%) rename {src => static}/snufficon/laughing.png (100%) rename {src => static}/snufficon/lying.png (100%) rename {src => static}/snufficon/mask.png (100%) rename {src => static}/snufficon/melting.png (100%) rename {src => static}/snufficon/money_face.png (100%) rename {src => static}/snufficon/monocle.png (100%) rename {src => static}/snufficon/mouthless.png (100%) rename {src => static}/snufficon/nerd.png (100%) rename {src => static}/snufficon/partying.png (100%) rename {src => static}/snufficon/peeking_eye.png (100%) rename {src => static}/snufficon/pleading_face.png (100%) rename {src => static}/snufficon/raging.png (100%) rename {src => static}/snufficon/raised_eyebrow.png (100%) rename {src => static}/snufficon/rolling_eyes.png (100%) rename {src => static}/snufficon/sad.png (100%) rename {src => static}/snufficon/saluting.png (100%) rename {src => static}/snufficon/scream.png (100%) rename {src => static}/snufficon/see_no_evil.png (100%) rename {src => static}/snufficon/shrug.png (100%) rename {src => static}/snufficon/shush.png (100%) rename {src => static}/snufficon/sick.png (100%) rename {src => static}/snufficon/sleeping.png (100%) rename {src => static}/snufficon/smiling.png (100%) rename {src => static}/snufficon/smiling_with_hearts.png (100%) rename {src => static}/snufficon/smiling_with_stars.png (100%) rename {src => static}/snufficon/smirk.png (100%) rename {src => static}/snufficon/sneeze.png (100%) rename {src => static}/snufficon/snuffmas.png (100%) rename {src => static}/snufficon/sob.png (100%) rename {src => static}/snufficon/spiral_eyes.png (100%) rename {src => static}/snufficon/star_struck.png (100%) rename {src => static}/snufficon/sunglasses.png (100%) rename {src => static}/snufficon/swearing.png (100%) rename {src => static}/snufficon/sweat.png (100%) rename {src => static}/snufficon/sweat_smile.png (100%) rename {src => static}/snufficon/thermometer.png (100%) rename {src => static}/snufficon/thinking.png (100%) rename {src => static}/snufficon/thumbs_down.png (100%) rename {src => static}/snufficon/thumbs_up.png (100%) rename {src => static}/snufficon/tongue_out.png (100%) rename {src => static}/snufficon/tongue_out_closed_eyes.png (100%) rename {src => static}/snufficon/tongue_out_winking.png (100%) rename {src => static}/snufficon/triumph.png (100%) rename {src => static}/snufficon/upside_down.png (100%) rename {src => static}/snufficon/vomiting.png (100%) rename {src => static}/snufficon/wink.png (100%) rename {src => static}/snufficon/woozy.png (100%) rename {src => static}/snufficon/yawning.png (100%) rename {src => static}/snufficon/zany.png (100%) rename {src => static}/snufficon/zipper_mouth.png (100%) rename {src => static}/style.css (100%) diff --git a/.gitignore b/.gitignore index adbb97d..4840892 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data/ \ No newline at end of file +snuffler-web +database.db diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0bafedb..0000000 --- a/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM docker.io/php:8-apache - -COPY src/ /var/www/html/ diff --git a/Makefile b/Makefile index ec3db14..fe3eb8f 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,4 @@ -current_dir := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) - -data/: FORCE -podman-run: data/ - podman build -t snuffler/snuffler-web . - podman run -v ./data/:/var/www/html/data/ -p 8080:80 localhost/snuffler/snuffler-web:dev - -docker-run: data/ - docker build -t snuffler/snuffler-web:dev . - docker run -v $(current_dir)data/:/var/www/html/data/ -p 8080:80 snuffler/snuffler-web:dev - -FORCE: - cp -r src/data ./ - chmod 777 data - -docker-run-dev: data/ src/ - docker run -v $(current_dir)src/:/var/www/html/ -v $(current_dir)data/:/var/www/html/data/ -p 8080:80 snuffler/snuffler-web:dev \ No newline at end of file +run: + go run main.go +build: + go build main.go diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 94d00b0..0000000 --- a/compose.yaml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3' -services: - snuffler-web: - #image: snuffler/snuffler-web - container_name: snuffler-web - build: - context: . - dockerfile: Dockerfile - volumes: - - ./data/:/var/www/html/data/ - ports: - - "8080:80" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fa06b8b --- /dev/null +++ b/go.mod @@ -0,0 +1,21 @@ +module jakest.us/snuffler-web + +go 1.22.9 + +require modernc.org/sqlite v1.34.4 + +require ( + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/ncruces/go-strftime v0.1.9 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + golang.org/x/sys v0.22.0 // indirect + modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect + modernc.org/libc v1.55.3 // indirect + modernc.org/mathutil v1.6.0 // indirect + modernc.org/memory v1.8.0 // indirect + modernc.org/strutil v1.2.0 // indirect + modernc.org/token v1.1.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c337282 --- /dev/null +++ b/go.sum @@ -0,0 +1,49 @@ +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo= +github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= +github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= +golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= +golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= +modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ= +modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= +modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y= +modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s= +modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= +modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= +modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= +modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= +modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI= +modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4= +modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U= +modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w= +modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= +modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= +modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= +modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= +modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= +modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= +modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= +modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= +modernc.org/sqlite v1.34.4 h1:sjdARozcL5KJBvYQvLlZEmctRgW9xqIZc2ncN7PU0P8= +modernc.org/sqlite v1.34.4/go.mod h1:3QQFCG2SEMtc2nv+Wq4cQCH7Hjcg+p/RMlS1XK+zwbk= +modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= +modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= +modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= +modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= diff --git a/index.html b/index.html new file mode 100644 index 0000000..5b80bd2 --- /dev/null +++ b/index.html @@ -0,0 +1,73 @@ + + + + + + + + Snuffler + + +
+ +
+
    +
  • Kotisivu
  • +
  • Viestit
  • +
  • Kalavaleet
  • +
  • Takasivu
  • +
+
+
+
    +
  • Mikko Mällikäs
    @mmallikas
  • +
  • Jarkko Toivanen
    @jt
  • +
+
+ +
+
Snuffler
+ +
+ + + +
+ + LOG OUT +
+
+
+ + +
+
+ + +

{{.Title}}

+ {{range .Posts}} +
+ + +

{{.Text}}

+
{{.Time}} + + + + + + + +
+ {{end}} + + +
+
+ + \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..877a32b --- /dev/null +++ b/main.go @@ -0,0 +1,115 @@ +package main + +import ( + "database/sql" + "html/template" + "log" + "net/http" + + _ "modernc.org/sqlite" +) + +type user struct { + id uint + name string + handle string + pass string + email string + about string +} + +type persona struct { + id uint + userid uint + handle string + name string + about string + colour string +} + +type Post struct { + Id uint + Time uint + Userid uint + Personaid uint + Text string + PersonaName string + UserName string + PersonaHandle string + UserHandle string +} + +type comment struct { + id uint + time uint + userid uint + personaid uint + postid uint + text string +} + +type page struct { + Title string + Posts []Post +} + +var db *sql.DB + +func main() { + var err error + db, err = sql.Open("sqlite", "database.db") + if err != nil { + log.Fatal(err) + } + + http.Handle("/static/", http.FileServer(http.Dir("./"))) + http.HandleFunc("/", httpRootHandler) + err = http.ListenAndServe(":6900", nil) + if err != nil { + log.Fatal(err) + } + + db.Close() +} + +func httpRootHandler(w http.ResponseWriter, r *http.Request) { + t, _ := template.ParseFiles("index.html") + posts, err := getPosts() + if err != nil { + log.Fatal(err) + http.Error(w, http.StatusText(500), 500) + return + } + var p page + p.Title = "Snuffler" + p.Posts = posts + t.Execute(w, p) + +} + +func getPosts() ([]Post, error) { + + rows, err := db.Query("SELECT post.id, post.time, post.userid, post.personaid, post.text, user.name, user.handle, persona.name, persona.handle FROM posts AS post LEFT JOIN users AS user ON post.userid=user.id LEFT JOIN personas AS persona ON post.personaid=persona.id") + if err != nil { + log.Fatal(err) + return nil, err + } + + var posts []Post + for rows.Next() { + var post Post + err := rows.Scan(&post.Id, &post.Time, &post.Userid, &post.Personaid, &post.Text, &post.UserName, &post.UserHandle, &post.PersonaName, &post.PersonaHandle) + if err != nil { + log.Fatal(err) + return nil, err + } + posts = append(posts, post) + } + err = rows.Err() + if err != nil { + log.Fatal(err) + return nil, err + } + + return posts, nil +} diff --git a/src/api/.htaccess b/src/api/.htaccess deleted file mode 100644 index 46d7c45..0000000 --- a/src/api/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ -RewriteEngine on -RewriteCond %{HTTP:Authorization} ^(.*) -RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] -RewriteRule ^ index.php \ No newline at end of file diff --git a/src/api/index.php b/src/api/index.php deleted file mode 100644 index d0d9a76..0000000 --- a/src/api/index.php +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/src/data/.gitignore b/src/data/.gitignore deleted file mode 100644 index 71059e1..0000000 --- a/src/data/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore -!.htaccess \ No newline at end of file diff --git a/src/data/.htaccess b/src/data/.htaccess deleted file mode 100755 index ff2beb8..0000000 --- a/src/data/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -order deny,allow -deny from all diff --git a/src/inc/.htaccess b/src/inc/.htaccess deleted file mode 100755 index ff2beb8..0000000 --- a/src/inc/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -order deny,allow -deny from all diff --git a/src/inc/database.php b/src/inc/database.php deleted file mode 100755 index da03ecb..0000000 --- a/src/inc/database.php +++ /dev/null @@ -1,213 +0,0 @@ -open('data/database.db'); - $this->exec('PRAGMA foreign_keys=ON;'); - $this->exec('PRAGMA full_column_names=ON;'); - $this->exec('PRAGMA short_column_names=OFF;'); - - $sql = " - CREATE TABLE IF NOT EXISTS users ( - id INTEGER PRIMARY KEY UNIQUE, - pass TEXT, - email TEXT UNIQUE, - handle TEXT NOT NULL UNIQUE, - name TEXT NOT NULL, - about TEXT - ); - - CREATE TABLE IF NOT EXISTS personas ( - id INTEGER PRIMARY KEY UNIQUE, - userid INTEGER NOT NULL, - handle TEXT NOT NULL, - name TEXT NOT NULL, - about TEXT, - colour INTEGER, - FOREIGN KEY (userid) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, - UNIQUE (userid, handle) - ); - - CREATE TABLE IF NOT EXISTS posts ( - id INTEGER PRIMARY KEY UNIQUE, - time INTEGER NOT NULL, - userid INTEGER NOT NULL, - personaid INTEGER NOT NULL, - text TEXT NOT NULL, - FOREIGN KEY (userid) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, - FOREIGN KEY (personaid) REFERENCES personas(id) ON UPDATE CASCADE ON DELETE CASCADE - ); - - CREATE TABLE IF NOT EXISTS comments ( - id INTEGER PRIMARY KEY UNIQUE, - time INTEGER NOT NULL, - userid INTEGER NOT NULL, - personaid INTEGER, - postid INTEGER NOT NULL, - text TEXT NOT NULL, - FOREIGN KEY (postid) REFERENCES posts(id), - FOREIGN KEY (userid) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, - FOREIGN KEY (personaid) REFERENCES personas(id) ON UPDATE CASCADE ON DELETE CASCADE - ); - - CREATE TABLE IF NOT EXISTS tokens ( - id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, - userid INTEGER NOT NULL, - token TEXT NOT NULL UNIQUE, - lastuse TEXT NOT NULL, - expires TEXT NOT NULL, - FOREIGN KEY (userid) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE - ); - - INSERT OR IGNORE INTO users (id, handle, name, about) VALUES ('0', 'SYSTEM', 'SYSTEM', 'SYSTEM'); - - "; - - $ret = $this->exec($sql); - - } - - function addUser($handle, $name, $about=NULL) { - $id = hexdec(uniqid()); - $sql = "INSERT INTO users (id, handle, name, about) VALUES ('$id', '$handle', '$name', '$about')"; - $ret = $this->exec($sql); - if(!$ret) { - die($this->lastErrorMsg()); - } - } - - function getUserByHandle($handle) { - $handle = $this->escapeString($handle); - $sql = "SELECT * FROM users AS user WHERE handle='$handle';"; - $ret = $this->query($sql)->fetchArray(SQLITE3_ASSOC); - if(!$ret) { - return false; - } - return $ret; - } - - function addPost($text, $userid=NULL, $personaid=NULL) { - $id = hexdec(uniqid()); - $time = time(); - $sql = $this->prepare("INSERT INTO posts (id, time, userid, personaid, text) values ('$id', '$time', '$userid', :personaid, '$text')"); - $sql->bindParam(':personaid', $personaid, SQLITE3_INTEGER); - $ret = $sql->execute(); - if(!$ret) { - die($this->lastErrorMsg()); - } - } - - function addPersona($userid, $handle, $name, $about=NULL, $colour=NULL) { - $id = hexdec(uniqid()); - $sql = "INSERT INTO personas (id, userid, handle, name, about, colour) VALUES ('$id', '$userid', '$handle', '$name', '$about', '$colour');"; - $ret = $this->exec($sql); - if(!$ret) { - die($this->lastErrorMsg()); - } - } - - function passwordSet($userid, $password=NULL) { - $hash = empty($password) ? NULL : password_hash($password, PASSWORD_DEFAULT); - $sql = "UPDATE USERS SET pass='$hash' WHERE id='$userid';"; - $ret = $this->exec($sql); - if(!$ret) { - die($this->lastErrorMsg()); - } - } - - function passwordVerify($userid, $password) { - $sql = "SELECT pass FROM users WHERE id='$userid';"; - $ret = $this->query($sql)->fetchArray(SQLITE3_NUM); - if(!$ret) { - return false; - } - $dbhash = $ret[0]; - if(!$dbhash) { - return false; - } - return password_verify($password, $dbhash); - } - - function tokenGen() { - return random_bytes(32); - } - function tokenAdd($userid) { - $token = $this->tokenGen(); - $hashed = hash('sha256', $token); - $time = time(); - $expires = $time + 2592000; // 30 days - $sql = "INSERT INTO tokens (userid, token, lastuse, expires) VALUES ('$userid', '$hashed', '$time', '$expires');"; - $ret = $this->exec($sql); - if(!$ret) { - die($this->lastErrorMsg()); - } - return $token; - } - function tokenRefresh($tokenid) { - $time = time(); - $expires = $time + 2592000; // 30 days - $sql = "UPDATE tokens SET lastuse='$time', expires='$expires' WHERE id='$tokenid';"; - $ret = $this->exec($sql); - if(!$ret) { - die($this->lastErrorMsg()); - } - } - function tokenRemove($token) { - $hashed = hash('sha256', $token); - $sql = "DELETE FROM tokens WHERE token='$hashed';"; - $ret = $this->exec($sql); - if(!$ret) { - die($this->lastErrorMsg()); - } - } - - function getAuthedUserId($token=NULL) { - if (empty($token)) { - if (empty($_COOKIE['token'])) { - return false; - } - $token = base64_decode($_COOKIE['token']); - } - $hashed = hash('sha256', $token); - $sql = "SELECT id AS id, userid AS userid, expires AS expires FROM tokens WHERE token='$hashed';"; - $ret = $this->query($sql)->fetchArray(SQLITE3_ASSOC); - if(!$ret) { - return false; - } - if ($ret['expires'] < time()) { - $this->tokenRemove($token); - return false; - } - $this->tokenRefresh($ret['id']); - return $ret['userid']; - } - - function getPosts($userid=NULL, $personaid = NULL) { - $sql = "SELECT * FROM posts AS post LEFT JOIN users AS user ON post.userid=user.id LEFT JOIN personas AS persona ON post.personaid=persona.id;"; - - $ret = $this->query($sql); - $array = array(); - while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { - array_push($array, $row); - } - return $array; - } - - function getPersonas($userid=NULL) { - if(!$userid) { - $userid = $this->getAuthedUserId(); - } - $sql = "SELECT * FROM personas AS persona WHERE userid='$userid' ORDER BY name;"; - - $ret = $this->query($sql); - $array = array(); - while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { - array_push($array, $row); - } - return $array; - } -} -?> diff --git a/src/index.php b/src/index.php deleted file mode 100755 index 572542d..0000000 --- a/src/index.php +++ /dev/null @@ -1,110 +0,0 @@ -lastErrorMsg()); -} -?> - - - - - - - - Snuffler - - -
- -
-
    -
  • Kotisivu
  • -
  • Viestit
  • -
  • Kalavaleet
  • -
  • Takasivu
  • -
-
-
-
    -
  • Mikko Mällikäs
    @mmallikas
  • -
  • Jarkko Toivanen
    @jt
  • -
-
- -
-
Snuffler
- - getAuthedUserId()) { - ?> - -
- - - -
- - - LOG OUT -
-
-
- - -
-
- - - - -addPost("Test post", 0); - -$posts = array_reverse($database->getPosts()); -//var_dump($posts); -foreach($posts as $post) { - echo '
'; - echo ''; - - echo '

' . $post["post.text"] . '

'; - echo '
' . date("D j.n.Y \@ G:i", $post["post.time"]) . ''; - echo ' - - - - - - - '; - echo "
"; - -} -$database->close(); - -?> -
-
- - diff --git a/src/login.php b/src/login.php deleted file mode 100644 index 971ac7c..0000000 --- a/src/login.php +++ /dev/null @@ -1,16 +0,0 @@ -getUserByHandle($_POST['name']); -if ($db->passwordVerify($user['user.id'], $_POST['pass'])) { - $token = $db->tokenAdd($user['user.id']); - $token64 = base64_encode($token); - $expires = time() + 2592000; // 30 days - setcookie('token', $token64, $expires); -} -header("Location: /"); -?> diff --git a/src/logout.php b/src/logout.php deleted file mode 100644 index e6f4c66..0000000 --- a/src/logout.php +++ /dev/null @@ -1,7 +0,0 @@ -tokenRemove(base64_decode($_COOKIE['token'])); -header("Location: /"); -?> diff --git a/src/post.php b/src/post.php deleted file mode 100644 index e69d9c0..0000000 --- a/src/post.php +++ /dev/null @@ -1,14 +0,0 @@ -getAuthedUserId(); -$persid = $_POST['persona']; // TODO: CHECK OWNERSHIP! (db schema?) -if($userid) { - $db->addPost($_POST['text'], $userid, $persid); -} -header("Location: /"); -?> diff --git a/src/snufficon/angel.png b/static/snufficon/angel.png similarity index 100% rename from src/snufficon/angel.png rename to static/snufficon/angel.png diff --git a/src/snufficon/angry.png b/static/snufficon/angry.png similarity index 100% rename from src/snufficon/angry.png rename to static/snufficon/angry.png diff --git a/src/snufficon/cat_face.png b/static/snufficon/cat_face.png similarity index 100% rename from src/snufficon/cat_face.png rename to static/snufficon/cat_face.png diff --git a/src/snufficon/clown.png b/static/snufficon/clown.png similarity index 100% rename from src/snufficon/clown.png rename to static/snufficon/clown.png diff --git a/src/snufficon/cold.png b/static/snufficon/cold.png similarity index 100% rename from src/snufficon/cold.png rename to static/snufficon/cold.png diff --git a/src/snufficon/cold_sweat.png b/static/snufficon/cold_sweat.png similarity index 100% rename from src/snufficon/cold_sweat.png rename to static/snufficon/cold_sweat.png diff --git a/src/snufficon/cowboy.png b/static/snufficon/cowboy.png similarity index 100% rename from src/snufficon/cowboy.png rename to static/snufficon/cowboy.png diff --git a/src/snufficon/cross_eyes.png b/static/snufficon/cross_eyes.png similarity index 100% rename from src/snufficon/cross_eyes.png rename to static/snufficon/cross_eyes.png diff --git a/src/snufficon/disappointed_relieved.png b/static/snufficon/disappointed_relieved.png similarity index 100% rename from src/snufficon/disappointed_relieved.png rename to static/snufficon/disappointed_relieved.png diff --git a/src/snufficon/drool.png b/static/snufficon/drool.png similarity index 100% rename from src/snufficon/drool.png rename to static/snufficon/drool.png diff --git a/src/snufficon/excited.png b/static/snufficon/excited.png similarity index 100% rename from src/snufficon/excited.png rename to static/snufficon/excited.png diff --git a/src/snufficon/exploding_head.png b/static/snufficon/exploding_head.png similarity index 100% rename from src/snufficon/exploding_head.png rename to static/snufficon/exploding_head.png diff --git a/src/snufficon/expressionless.png b/static/snufficon/expressionless.png similarity index 100% rename from src/snufficon/expressionless.png rename to static/snufficon/expressionless.png diff --git a/src/snufficon/fearful.png b/static/snufficon/fearful.png similarity index 100% rename from src/snufficon/fearful.png rename to static/snufficon/fearful.png diff --git a/src/snufficon/flush.png b/static/snufficon/flush.png similarity index 100% rename from src/snufficon/flush.png rename to static/snufficon/flush.png diff --git a/src/snufficon/giggle.png b/static/snufficon/giggle.png similarity index 100% rename from src/snufficon/giggle.png rename to static/snufficon/giggle.png diff --git a/src/snufficon/hand_over_mouth.png b/static/snufficon/hand_over_mouth.png similarity index 100% rename from src/snufficon/hand_over_mouth.png rename to static/snufficon/hand_over_mouth.png diff --git a/src/snufficon/happy.png b/static/snufficon/happy.png similarity index 100% rename from src/snufficon/happy.png rename to static/snufficon/happy.png diff --git a/src/snufficon/head_bandage.png b/static/snufficon/head_bandage.png similarity index 100% rename from src/snufficon/head_bandage.png rename to static/snufficon/head_bandage.png diff --git a/src/snufficon/heart_eyes.png b/static/snufficon/heart_eyes.png similarity index 100% rename from src/snufficon/heart_eyes.png rename to static/snufficon/heart_eyes.png diff --git a/src/snufficon/holding_back_tears.png b/static/snufficon/holding_back_tears.png similarity index 100% rename from src/snufficon/holding_back_tears.png rename to static/snufficon/holding_back_tears.png diff --git a/src/snufficon/hot.png b/static/snufficon/hot.png similarity index 100% rename from src/snufficon/hot.png rename to static/snufficon/hot.png diff --git a/src/snufficon/hug.png b/static/snufficon/hug.png similarity index 100% rename from src/snufficon/hug.png rename to static/snufficon/hug.png diff --git a/src/snufficon/joy.png b/static/snufficon/joy.png similarity index 100% rename from src/snufficon/joy.png rename to static/snufficon/joy.png diff --git a/src/snufficon/kissing.png b/static/snufficon/kissing.png similarity index 100% rename from src/snufficon/kissing.png rename to static/snufficon/kissing.png diff --git a/src/snufficon/kissing_heart.png b/static/snufficon/kissing_heart.png similarity index 100% rename from src/snufficon/kissing_heart.png rename to static/snufficon/kissing_heart.png diff --git a/src/snufficon/laughing.png b/static/snufficon/laughing.png similarity index 100% rename from src/snufficon/laughing.png rename to static/snufficon/laughing.png diff --git a/src/snufficon/lying.png b/static/snufficon/lying.png similarity index 100% rename from src/snufficon/lying.png rename to static/snufficon/lying.png diff --git a/src/snufficon/mask.png b/static/snufficon/mask.png similarity index 100% rename from src/snufficon/mask.png rename to static/snufficon/mask.png diff --git a/src/snufficon/melting.png b/static/snufficon/melting.png similarity index 100% rename from src/snufficon/melting.png rename to static/snufficon/melting.png diff --git a/src/snufficon/money_face.png b/static/snufficon/money_face.png similarity index 100% rename from src/snufficon/money_face.png rename to static/snufficon/money_face.png diff --git a/src/snufficon/monocle.png b/static/snufficon/monocle.png similarity index 100% rename from src/snufficon/monocle.png rename to static/snufficon/monocle.png diff --git a/src/snufficon/mouthless.png b/static/snufficon/mouthless.png similarity index 100% rename from src/snufficon/mouthless.png rename to static/snufficon/mouthless.png diff --git a/src/snufficon/nerd.png b/static/snufficon/nerd.png similarity index 100% rename from src/snufficon/nerd.png rename to static/snufficon/nerd.png diff --git a/src/snufficon/partying.png b/static/snufficon/partying.png similarity index 100% rename from src/snufficon/partying.png rename to static/snufficon/partying.png diff --git a/src/snufficon/peeking_eye.png b/static/snufficon/peeking_eye.png similarity index 100% rename from src/snufficon/peeking_eye.png rename to static/snufficon/peeking_eye.png diff --git a/src/snufficon/pleading_face.png b/static/snufficon/pleading_face.png similarity index 100% rename from src/snufficon/pleading_face.png rename to static/snufficon/pleading_face.png diff --git a/src/snufficon/raging.png b/static/snufficon/raging.png similarity index 100% rename from src/snufficon/raging.png rename to static/snufficon/raging.png diff --git a/src/snufficon/raised_eyebrow.png b/static/snufficon/raised_eyebrow.png similarity index 100% rename from src/snufficon/raised_eyebrow.png rename to static/snufficon/raised_eyebrow.png diff --git a/src/snufficon/rolling_eyes.png b/static/snufficon/rolling_eyes.png similarity index 100% rename from src/snufficon/rolling_eyes.png rename to static/snufficon/rolling_eyes.png diff --git a/src/snufficon/sad.png b/static/snufficon/sad.png similarity index 100% rename from src/snufficon/sad.png rename to static/snufficon/sad.png diff --git a/src/snufficon/saluting.png b/static/snufficon/saluting.png similarity index 100% rename from src/snufficon/saluting.png rename to static/snufficon/saluting.png diff --git a/src/snufficon/scream.png b/static/snufficon/scream.png similarity index 100% rename from src/snufficon/scream.png rename to static/snufficon/scream.png diff --git a/src/snufficon/see_no_evil.png b/static/snufficon/see_no_evil.png similarity index 100% rename from src/snufficon/see_no_evil.png rename to static/snufficon/see_no_evil.png diff --git a/src/snufficon/shrug.png b/static/snufficon/shrug.png similarity index 100% rename from src/snufficon/shrug.png rename to static/snufficon/shrug.png diff --git a/src/snufficon/shush.png b/static/snufficon/shush.png similarity index 100% rename from src/snufficon/shush.png rename to static/snufficon/shush.png diff --git a/src/snufficon/sick.png b/static/snufficon/sick.png similarity index 100% rename from src/snufficon/sick.png rename to static/snufficon/sick.png diff --git a/src/snufficon/sleeping.png b/static/snufficon/sleeping.png similarity index 100% rename from src/snufficon/sleeping.png rename to static/snufficon/sleeping.png diff --git a/src/snufficon/smiling.png b/static/snufficon/smiling.png similarity index 100% rename from src/snufficon/smiling.png rename to static/snufficon/smiling.png diff --git a/src/snufficon/smiling_with_hearts.png b/static/snufficon/smiling_with_hearts.png similarity index 100% rename from src/snufficon/smiling_with_hearts.png rename to static/snufficon/smiling_with_hearts.png diff --git a/src/snufficon/smiling_with_stars.png b/static/snufficon/smiling_with_stars.png similarity index 100% rename from src/snufficon/smiling_with_stars.png rename to static/snufficon/smiling_with_stars.png diff --git a/src/snufficon/smirk.png b/static/snufficon/smirk.png similarity index 100% rename from src/snufficon/smirk.png rename to static/snufficon/smirk.png diff --git a/src/snufficon/sneeze.png b/static/snufficon/sneeze.png similarity index 100% rename from src/snufficon/sneeze.png rename to static/snufficon/sneeze.png diff --git a/src/snufficon/snuffmas.png b/static/snufficon/snuffmas.png similarity index 100% rename from src/snufficon/snuffmas.png rename to static/snufficon/snuffmas.png diff --git a/src/snufficon/sob.png b/static/snufficon/sob.png similarity index 100% rename from src/snufficon/sob.png rename to static/snufficon/sob.png diff --git a/src/snufficon/spiral_eyes.png b/static/snufficon/spiral_eyes.png similarity index 100% rename from src/snufficon/spiral_eyes.png rename to static/snufficon/spiral_eyes.png diff --git a/src/snufficon/star_struck.png b/static/snufficon/star_struck.png similarity index 100% rename from src/snufficon/star_struck.png rename to static/snufficon/star_struck.png diff --git a/src/snufficon/sunglasses.png b/static/snufficon/sunglasses.png similarity index 100% rename from src/snufficon/sunglasses.png rename to static/snufficon/sunglasses.png diff --git a/src/snufficon/swearing.png b/static/snufficon/swearing.png similarity index 100% rename from src/snufficon/swearing.png rename to static/snufficon/swearing.png diff --git a/src/snufficon/sweat.png b/static/snufficon/sweat.png similarity index 100% rename from src/snufficon/sweat.png rename to static/snufficon/sweat.png diff --git a/src/snufficon/sweat_smile.png b/static/snufficon/sweat_smile.png similarity index 100% rename from src/snufficon/sweat_smile.png rename to static/snufficon/sweat_smile.png diff --git a/src/snufficon/thermometer.png b/static/snufficon/thermometer.png similarity index 100% rename from src/snufficon/thermometer.png rename to static/snufficon/thermometer.png diff --git a/src/snufficon/thinking.png b/static/snufficon/thinking.png similarity index 100% rename from src/snufficon/thinking.png rename to static/snufficon/thinking.png diff --git a/src/snufficon/thumbs_down.png b/static/snufficon/thumbs_down.png similarity index 100% rename from src/snufficon/thumbs_down.png rename to static/snufficon/thumbs_down.png diff --git a/src/snufficon/thumbs_up.png b/static/snufficon/thumbs_up.png similarity index 100% rename from src/snufficon/thumbs_up.png rename to static/snufficon/thumbs_up.png diff --git a/src/snufficon/tongue_out.png b/static/snufficon/tongue_out.png similarity index 100% rename from src/snufficon/tongue_out.png rename to static/snufficon/tongue_out.png diff --git a/src/snufficon/tongue_out_closed_eyes.png b/static/snufficon/tongue_out_closed_eyes.png similarity index 100% rename from src/snufficon/tongue_out_closed_eyes.png rename to static/snufficon/tongue_out_closed_eyes.png diff --git a/src/snufficon/tongue_out_winking.png b/static/snufficon/tongue_out_winking.png similarity index 100% rename from src/snufficon/tongue_out_winking.png rename to static/snufficon/tongue_out_winking.png diff --git a/src/snufficon/triumph.png b/static/snufficon/triumph.png similarity index 100% rename from src/snufficon/triumph.png rename to static/snufficon/triumph.png diff --git a/src/snufficon/upside_down.png b/static/snufficon/upside_down.png similarity index 100% rename from src/snufficon/upside_down.png rename to static/snufficon/upside_down.png diff --git a/src/snufficon/vomiting.png b/static/snufficon/vomiting.png similarity index 100% rename from src/snufficon/vomiting.png rename to static/snufficon/vomiting.png diff --git a/src/snufficon/wink.png b/static/snufficon/wink.png similarity index 100% rename from src/snufficon/wink.png rename to static/snufficon/wink.png diff --git a/src/snufficon/woozy.png b/static/snufficon/woozy.png similarity index 100% rename from src/snufficon/woozy.png rename to static/snufficon/woozy.png diff --git a/src/snufficon/yawning.png b/static/snufficon/yawning.png similarity index 100% rename from src/snufficon/yawning.png rename to static/snufficon/yawning.png diff --git a/src/snufficon/zany.png b/static/snufficon/zany.png similarity index 100% rename from src/snufficon/zany.png rename to static/snufficon/zany.png diff --git a/src/snufficon/zipper_mouth.png b/static/snufficon/zipper_mouth.png similarity index 100% rename from src/snufficon/zipper_mouth.png rename to static/snufficon/zipper_mouth.png diff --git a/src/style.css b/static/style.css similarity index 100% rename from src/style.css rename to static/style.css