diff --git a/.vscode/launch.json b/.vscode/launch.json index b52be00..bd99506 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,9 +15,6 @@ "PUBLIC_URL": "http://localhost:4000", "WEATHER_KEY": "3722ce75e9330aaefde1cb3eb1b8b030", "APP_VERSION": "v0.0.1-DEV", - "AUTH_CLIENT_ID": "home", - "AUTH_CLIENT_SECRET": "PkfS5S7BkiEeqX3Km7BGxsBrmH6MOzjqcpODTz2akxMCMFHv8TAvIfyWgTlKof85", - "AUTH_ISSUER": "https://sso.unjx.de/auth/v1", } } ] diff --git a/components/application.templ b/components/application.templ deleted file mode 100644 index fb498b6..0000000 --- a/components/application.templ +++ /dev/null @@ -1,27 +0,0 @@ -package components - -import "gitlab.unjx.de/flohoss/godash/services" - -func displayDark(app services.Application) bool { - return !app.IgnoreDark && app.IconLight != "" -} - -templ Application(application services.Application) { - -
- @templ.Raw(application.Icon) -
- if displayDark(application) { -
- @templ.Raw(application.IconLight) -
- } -
{ application.Name }
-
-} - -templ Link(link services.Link) { - -
{ link.Name }
-
-} diff --git a/components/user.templ b/components/user.templ deleted file mode 100644 index 195ba42..0000000 --- a/components/user.templ +++ /dev/null @@ -1,13 +0,0 @@ -package components - -import "gitlab.unjx.de/flohoss/godash/services" - -templ User(user *services.User) { -
- -
- -
-
-
-} diff --git a/go.mod b/go.mod index 5c55a26..8cefef6 100644 --- a/go.mod +++ b/go.mod @@ -3,24 +3,18 @@ module gitlab.unjx.de/flohoss/godash go 1.23 require ( - github.com/a-h/templ v0.2.793 + github.com/a-h/templ v0.3.819 github.com/caarlos0/env/v10 v10.0.0 - github.com/coreos/go-oidc/v3 v3.11.0 - github.com/go-playground/validator/v10 v10.22.1 - github.com/gorilla/securecookie v1.1.2 - github.com/gorilla/sessions v1.4.0 - github.com/lmittmann/tint v1.0.5 + github.com/go-playground/validator/v10 v10.24.0 + github.com/lmittmann/tint v1.0.7 github.com/r3labs/sse/v2 v2.10.0 - github.com/shirou/gopsutil/v4 v4.24.9 - github.com/thanhpk/randstr v1.0.6 - golang.org/x/oauth2 v0.23.0 + github.com/shirou/gopsutil/v4 v4.24.12 gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/ebitengine/purego v0.8.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.6 // indirect - github.com/go-jose/go-jose/v4 v4.0.4 // indirect + github.com/ebitengine/purego v0.8.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect @@ -32,10 +26,10 @@ require ( github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/numcpus v0.9.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect - golang.org/x/crypto v0.28.0 // indirect - golang.org/x/net v0.30.0 // indirect - golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.19.0 // indirect + golang.org/x/crypto v0.32.0 // indirect + golang.org/x/net v0.34.0 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/text v0.21.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) diff --git a/go.sum b/go.sum index 236a93a..d6c83e3 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,15 @@ -github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY= -github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w= +github.com/a-h/templ v0.3.819 h1:KDJ5jTFN15FyJnmSmo2gNirIqt7hfvBD2VXVDTySckM= +github.com/a-h/templ v0.3.819/go.mod h1:iDJKJktpttVKdWoTkRNNLcllRI+BlpopJc+8au3gOUo= github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA= github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18= -github.com/coreos/go-oidc/v3 v3.11.0 h1:Ia3MxdwpSw702YW0xgfmP1GVCMA9aEFWu12XUZ3/OtI= -github.com/coreos/go-oidc/v3 v3.11.0/go.mod h1:gE3LgjOgFoHi9a4ce4/tJczr0Ai2/BoDhf0r5lltWI0= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE= -github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= -github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc= -github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc= -github.com/go-jose/go-jose/v4 v4.0.4 h1:VsjPI33J0SB9vQM6PLmNjoHqMQNGPiZ0rHL7Ni7Q6/E= -github.com/go-jose/go-jose/v4 v4.0.4/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc= +github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I= +github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= @@ -23,16 +19,10 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= -github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.24.0 h1:KHQckvo8G6hlWnrPX4NJJ+aBfWNAE/HH+qdL2cBpCmg= +github.com/go-playground/validator/v10 v10.24.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= -github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= -github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= -github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ= -github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -42,8 +32,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= -github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw= -github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= +github.com/lmittmann/tint v1.0.7 h1:D/0OqWZ0YOGZ6AyC+5Y2kD8PBEzBk6rFHVSfOqCkF9Y= +github.com/lmittmann/tint v1.0.7/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -56,14 +46,12 @@ github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktE github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/shirou/gopsutil/v4 v4.24.9 h1:KIV+/HaHD5ka5f570RZq+2SaeFsb/pq+fp2DGNWYoOI= -github.com/shirou/gopsutil/v4 v4.24.9/go.mod h1:3fkaHNeYsUFCGZ8+9vZVWtbyM1k2eRnlL+bWO8Bxa/Q= +github.com/shirou/gopsutil/v4 v4.24.12 h1:qvePBOk20e0IKA1QXrIIU+jmk+zEiYVVx06WjBRlZo4= +github.com/shirou/gopsutil/v4 v4.24.12/go.mod h1:DCtMPAad2XceTeIAbGyVfycbYQNBGk2P8cvDi7/VN9o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/thanhpk/randstr v1.0.6 h1:psAOktJFD4vV9NEVb3qkhRSMvYh4ORRaj1+w/hn4B+o= -github.com/thanhpk/randstr v1.0.6/go.mod h1:M/H2P1eNLZzlDwAzpkkkUvoyNNMbzRGhESZuEQk3r0U= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo= @@ -71,22 +59,20 @@ github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= -golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= -golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y= gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/handlers/app.handlers.go b/handlers/app.handlers.go index 6b7844a..e1d76cb 100644 --- a/handlers/app.handlers.go +++ b/handlers/app.handlers.go @@ -3,7 +3,6 @@ package handlers import ( "net/http" - "github.com/gorilla/sessions" "gitlab.unjx.de/flohoss/godash/internal/env" "gitlab.unjx.de/flohoss/godash/services" "gitlab.unjx.de/flohoss/godash/views/home" @@ -22,10 +21,9 @@ type WeatherService interface { GetCurrentWeather() *services.OpenWeather } -func NewAppHandler(env *env.Config, store *sessions.CookieStore, s SystemService, w WeatherService, b BookmarkService) *AppHandler { +func NewAppHandler(env *env.Config, s SystemService, w WeatherService, b BookmarkService) *AppHandler { return &AppHandler{ env: env, - store: store, systemService: s, weatherService: w, bookmarkService: b, @@ -34,7 +32,6 @@ func NewAppHandler(env *env.Config, store *sessions.CookieStore, s SystemService type AppHandler struct { env *env.Config - store *sessions.CookieStore systemService SystemService weatherService WeatherService bookmarkService BookmarkService @@ -48,12 +45,5 @@ func (bh *AppHandler) appHandler(w http.ResponseWriter, r *http.Request) { titlePage := bh.env.Title - session, _ := bh.store.Get(r, StoreSessionKey) - user := &services.User{ - Name: session.Values[string(NameKey)].(string), - Email: session.Values[string(EmailKey)].(string), - Gravatar: session.Values[string(GravatarKey)].(string), - } - - home.HomeIndex(titlePage, bh.env.Version, home.Home(titlePage, user, bookmarks, staticSystem, liveSystem, weather)).Render(r.Context(), w) + home.HomeIndex(titlePage, bh.env.Version, home.Home(titlePage, bookmarks, staticSystem, liveSystem, weather)).Render(r.Context(), w) } diff --git a/handlers/auth.handlers.go b/handlers/auth.handlers.go deleted file mode 100644 index 61656c5..0000000 --- a/handlers/auth.handlers.go +++ /dev/null @@ -1,161 +0,0 @@ -package handlers - -import ( - "context" - "crypto/rand" - "crypto/sha256" - "encoding/base64" - "io" - "log/slog" - "net/http" - "os" - - "github.com/coreos/go-oidc/v3/oidc" - "github.com/gorilla/sessions" - "github.com/thanhpk/randstr" - "golang.org/x/oauth2" - - "gitlab.unjx.de/flohoss/godash/internal/env" - "gitlab.unjx.de/flohoss/godash/services" -) - -type contextKey string - -const ( - NameKey contextKey = "name" - EmailKey contextKey = "email" - GravatarKey contextKey = "gravatar" - - StoreSessionKey = "godash_session" -) - -func generateCodeVerifier() (string, error) { - verifierLength := 64 - verifier := make([]byte, verifierLength) - - _, err := rand.Read(verifier) - if err != nil { - return "", err - } - return base64.RawURLEncoding.EncodeToString(verifier), nil -} - -func generateCodeChallenge(verifier string) string { - hash := sha256.New() - _, _ = io.WriteString(hash, verifier) - sha := hash.Sum(nil) - return base64.RawURLEncoding.EncodeToString(sha) -} - -func NewAuthHandler(env *env.Config, store *sessions.CookieStore) *AuthHandler { - ctx := context.Background() - provider, err := oidc.NewProvider(ctx, env.AuthIssuer) - if err != nil { - slog.Error("Failed to get oidc provider", "err", err.Error()) - os.Exit(1) - } - - config := &oauth2.Config{ - ClientID: env.AuthClientID, - ClientSecret: env.AuthClientSecret, - RedirectURL: env.PublicUrl + "/callback", - Scopes: env.AuthScopes, - Endpoint: provider.Endpoint(), - } - - codeVerifier, err := generateCodeVerifier() - if err != nil { - slog.Error("Error generating code verifier", "err", err.Error()) - os.Exit(1) - } - codeChallenge := generateCodeChallenge(codeVerifier) - authCodeOptions := []oauth2.AuthCodeOption{ - oauth2.SetAuthURLParam("code_challenge", codeChallenge), - oauth2.SetAuthURLParam("code_challenge_method", "S256"), - oauth2.SetAuthURLParam("code_verifier", codeVerifier), - } - - return &AuthHandler{ - provider: provider, - config: config, - authCodeOptions: authCodeOptions, - store: store, - } -} - -type AuthHandler struct { - provider *oidc.Provider - config *oauth2.Config - authCodeOptions []oauth2.AuthCodeOption - store *sessions.CookieStore -} - -func (ah *AuthHandler) handleCallback(w http.ResponseWriter, r *http.Request) { - session, _ := ah.store.Get(r, StoreSessionKey) - state, ok := session.Values["state"].(string) - if !ok || state == "" { - http.Error(w, "state not found", http.StatusBadRequest) - return - } - if r.URL.Query().Get("state") != state { - http.Error(w, "state did not match", http.StatusBadRequest) - return - } - - oauth2Token, err := ah.config.Exchange(r.Context(), r.URL.Query().Get("code"), ah.authCodeOptions...) - if err != nil { - http.Error(w, "failed to exchange token: "+err.Error(), http.StatusInternalServerError) - return - } - - userInfo, err := ah.provider.UserInfo(r.Context(), oauth2.StaticTokenSource(oauth2Token)) - if err != nil { - http.Error(w, "failed to get userinfo: "+err.Error(), http.StatusInternalServerError) - return - } - - user := &services.User{} - userInfo.Claims(user) - - session.Values[string(NameKey)] = user.Name - session.Values[string(EmailKey)] = user.Email - session.Values[string(GravatarKey)] = services.NewGravatarFromEmail(user.Email).GetURL() - err = session.Save(r, w) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - http.Redirect(w, r, "/", http.StatusFound) -} - -func (ah *AuthHandler) handleLogout(w http.ResponseWriter, r *http.Request) { - session, _ := ah.store.Get(r, StoreSessionKey) - session.Values = make(map[interface{}]interface{}) - err := session.Save(r, w) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - http.Redirect(w, r, "/", http.StatusFound) -} - -func (ah *AuthHandler) AuthMiddleware(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - session, _ := ah.store.Get(r, StoreSessionKey) - name, ok := session.Values[string(NameKey)].(string) - if !ok || name == "" { - state := randstr.String(16) - session.Values["state"] = state - err := session.Save(r, w) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - http.Redirect(w, r, ah.config.AuthCodeURL(state, ah.authCodeOptions...), http.StatusFound) - return - } - - next.ServeHTTP(w, r) - }) -} diff --git a/handlers/routes.go b/handlers/routes.go index f392140..a1f2f58 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -6,17 +6,14 @@ import ( "github.com/r3labs/sse/v2" ) -func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler, authHandler *AuthHandler) { - router.Handle("GET /sse", authHandler.AuthMiddleware(http.HandlerFunc(sse.ServeHTTP))) +func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler) { + router.Handle("GET /sse", http.HandlerFunc(sse.ServeHTTP)) fsAssets := http.FileServer(http.Dir("assets")) - router.Handle("GET /assets/", authHandler.AuthMiddleware(http.StripPrefix("/assets/", fsAssets))) + router.Handle("GET /assets/", http.StripPrefix("/assets/", fsAssets)) icons := http.FileServer(http.Dir("storage/icons")) - router.Handle("GET /icons/", authHandler.AuthMiddleware(http.StripPrefix("/icons/", icons))) + router.Handle("GET /icons/", http.StripPrefix("/icons/", icons)) - router.HandleFunc("GET /logout", authHandler.handleLogout) - router.HandleFunc("GET /callback", authHandler.handleCallback) - - router.Handle("GET /", authHandler.AuthMiddleware(http.HandlerFunc(appHandler.appHandler))) + router.Handle("GET /", http.HandlerFunc(appHandler.appHandler)) } diff --git a/internal/env/env.go b/internal/env/env.go index e652c66..04a6d65 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -8,22 +8,17 @@ import ( ) type Config struct { - TimeZone string `env:"TZ" envDefault:"Etc/UTC" validate:"timezone"` - Title string `env:"TITLE" envDefault:"goDash"` - PublicUrl string `env:"PUBLIC_URL" validate:"required,url"` - Port int `env:"PORT" envDefault:"4000" validate:"min=1024,max=49151"` - Version string `env:"APP_VERSION"` - LocationLatitude float32 `env:"LOCATION_LATITUDE" envDefault:"48.780331609463815" validate:"latitude"` - LocationLongitude float32 `env:"LOCATION_LONGITUDE" envDefault:"9.177968320179422" validate:"longitude"` - WeatherKey string `env:"WEATHER_KEY"` - WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"` - WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"` - WeatherDigits bool `env:"WEATHER_DIGITS" envDefault:"false"` - AuthClientID string `env:"AUTH_CLIENT_ID" validate:"required"` - AuthClientSecret string `env:"AUTH_CLIENT_SECRET" validate:"required"` - AuthScopes []string `env:"AUTH_SCOPES" envSeparator:"," envDefault:"openid,email,profile"` - AuthIssuer string `env:"AUTH_ISSUER" validate:"required,url,endsnotwith=/.well-known/openid-configuration"` - SessionKey string `env:"SESSION_KEY,unset"` + TimeZone string `env:"TZ" envDefault:"Etc/UTC" validate:"timezone"` + Title string `env:"TITLE" envDefault:"goDash"` + PublicUrl string `env:"PUBLIC_URL" validate:"required,url"` + Port int `env:"PORT" envDefault:"4000" validate:"min=1024,max=49151"` + Version string `env:"APP_VERSION"` + LocationLatitude float32 `env:"LOCATION_LATITUDE" envDefault:"48.780331609463815" validate:"latitude"` + LocationLongitude float32 `env:"LOCATION_LONGITUDE" envDefault:"9.177968320179422" validate:"longitude"` + WeatherKey string `env:"WEATHER_KEY"` + WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"` + WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"` + WeatherDigits bool `env:"WEATHER_DIGITS" envDefault:"false"` } var errParse = errors.New("error parsing environment variables") diff --git a/main.go b/main.go index ae51893..85e6a85 100644 --- a/main.go +++ b/main.go @@ -5,11 +5,8 @@ import ( "fmt" "log/slog" "net/http" - "net/url" "os" - "github.com/gorilla/securecookie" - "github.com/gorilla/sessions" "github.com/r3labs/sse/v2" "gitlab.unjx.de/flohoss/godash/handlers" @@ -35,24 +32,8 @@ func main() { w := services.NewWeatherService(sse, env) b := services.NewBookmarkService() - parsedUrl, _ := url.Parse(env.PublicUrl) - secret := []byte(env.SessionKey) - if len(secret) == 0 { - secret = securecookie.GenerateRandomKey(32) - } - store := sessions.NewCookieStore(secret) - store.Options = &sessions.Options{ - Domain: parsedUrl.Hostname(), - MaxAge: 86400 * 30, - Secure: parsedUrl.Scheme == "https", - HttpOnly: true, - Partitioned: true, - SameSite: http.SameSiteLaxMode, - } - - authHandler := handlers.NewAuthHandler(env, store) - appHandler := handlers.NewAppHandler(env, store, s, w, b) - handlers.SetupRoutes(router, sse, appHandler, authHandler) + appHandler := handlers.NewAppHandler(env, s, w, b) + handlers.SetupRoutes(router, sse, appHandler) slog.Info("server listening, press ctrl+c to stop", "addr", env.PublicUrl) err = http.ListenAndServe(fmt.Sprintf(":%d", env.Port), router) diff --git a/pkg/media/media.go b/pkg/media/media.go index 6be3ebd..d3c3117 100644 --- a/pkg/media/media.go +++ b/pkg/media/media.go @@ -6,68 +6,24 @@ import ( "io/fs" "net/http" "os" - "regexp" - "strings" ) -func DownloadSelfHostedIcon(url, title, filePath string) ([]byte, error) { +func DownloadSelfHostedIcon(url, title, filePath string) (string, error) { resp, err := http.Get(url) if err != nil { - return nil, fmt.Errorf("failed to get icon: %w", err) + return "", fmt.Errorf("failed to get icon: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("failed to get icon, status: %d, url: %s", resp.StatusCode, url) + return "", fmt.Errorf("failed to get icon, status: %d, url: %s", resp.StatusCode, url) } data, err := io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("failed to read icon: %w", err) + return "", fmt.Errorf("failed to read icon: %w", err) } - data = replaceClassNames(data, title) - data = insertWidthHeight(data) err = os.WriteFile(filePath, data, fs.FileMode(0640)) if err != nil { - return nil, fmt.Errorf("failed to write icon: %w", err) + return "", fmt.Errorf("failed to write icon: %w", err) } - return data, nil -} - -func insertWidthHeight(svgContent []byte) []byte { - classRegex := regexp.MustCompile(`(?:`, +)) + +var bgTemplateDark = template.Must(template.New("bgTemplate").Parse( + ``, +)) + +type Icon struct { + Path string +} + +templ Application(application services.Application) { + + if displayLight(application) { + @templ.FromGoHTML(bgTemplate, Icon{Path: application.Icon}) + } else { +
+
+ { placeHolder(application) } +
+
+ } + if displayDark(application) { + @templ.FromGoHTML(bgTemplateDark, Icon{Path: application.IconLight}) + } +
{ application.Name }
+
+} + +templ Link(link services.Link) { + +
{ link.Name }
+
+} diff --git a/components/system.templ b/views/components/system.templ similarity index 100% rename from components/system.templ rename to views/components/system.templ diff --git a/components/weather.templ b/views/components/weather.templ similarity index 100% rename from components/weather.templ rename to views/components/weather.templ diff --git a/views/home/home.templ b/views/home/home.templ index 00d732b..828fd2e 100644 --- a/views/home/home.templ +++ b/views/home/home.templ @@ -2,17 +2,14 @@ package home import ( "fmt" - "gitlab.unjx.de/flohoss/godash/components" "gitlab.unjx.de/flohoss/godash/services" + "gitlab.unjx.de/flohoss/godash/views/components" "gitlab.unjx.de/flohoss/godash/views/layout" ) -templ Home(title string, user *services.User, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation, weather *services.OpenWeather) { +templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation, weather *services.OpenWeather) {
-
- @components.Weather(weather) - @components.User(user) -
+ @components.Weather(weather)
@components.System("icon-[bi--cpu]", static.CPU.Name, "", static.CPU.Threads, "systemCpuPercentage", "", live.CPU) @components.System("icon-[bi--nvme]", live.Disk.Value, fmt.Sprintf(" | %s", static.Disk.Total), static.Disk.Partitions, "systemDiskPercentage", "systemDiskValue", live.Disk.Percentage)