Remove auth

This commit is contained in:
Florian Hoss 2025-01-31 12:08:03 +01:00
parent c27660524b
commit 1d3ffc6c58
Signed by: flohoss
GPG key ID: 3F35C7F6E6F66F6B
17 changed files with 152 additions and 420 deletions

3
.vscode/launch.json vendored
View file

@ -15,9 +15,6 @@
"PUBLIC_URL": "http://localhost:4000", "PUBLIC_URL": "http://localhost:4000",
"WEATHER_KEY": "3722ce75e9330aaefde1cb3eb1b8b030", "WEATHER_KEY": "3722ce75e9330aaefde1cb3eb1b8b030",
"APP_VERSION": "v0.0.1-DEV", "APP_VERSION": "v0.0.1-DEV",
"AUTH_CLIENT_ID": "home",
"AUTH_CLIENT_SECRET": "PkfS5S7BkiEeqX3Km7BGxsBrmH6MOzjqcpODTz2akxMCMFHv8TAvIfyWgTlKof85",
"AUTH_ISSUER": "https://sso.unjx.de/auth/v1",
} }
} }
] ]

View file

@ -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) {
<a href={ templ.URL(application.URL) } class="flex items-center hover-effect">
<div class={ "w-8", "h-8", "flex", templ.KV("dark:hidden", displayDark(application)), "items-center" }>
@templ.Raw(application.Icon)
</div>
if displayDark(application) {
<div class={ "w-8", "h-8", "hidden", "dark:flex", "items-center" }>
@templ.Raw(application.IconLight)
</div>
}
<div class="uppercase truncate ml-2">{ application.Name }</div>
</a>
}
templ Link(link services.Link) {
<a href={ templ.URL(link.URL) } class="hover-effect">
<div class="truncate">{ link.Name }</div>
</a>
}

View file

@ -1,13 +0,0 @@
package components
import "gitlab.unjx.de/flohoss/godash/services"
templ User(user *services.User) {
<div class="tooltip tooltip-left" data-tip="Logout">
<a class="avatar" href="/logout">
<div class="ring-primary ring-offset-base-100 w-12 rounded-full ring-2 ring-offset-2">
<img src={ string(templ.SafeURL(user.Gravatar)) }/>
</div>
</a>
</div>
}

26
go.mod
View file

@ -3,24 +3,18 @@ module gitlab.unjx.de/flohoss/godash
go 1.23 go 1.23
require ( 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/caarlos0/env/v10 v10.0.0
github.com/coreos/go-oidc/v3 v3.11.0 github.com/go-playground/validator/v10 v10.24.0
github.com/go-playground/validator/v10 v10.22.1 github.com/lmittmann/tint v1.0.7
github.com/gorilla/securecookie v1.1.2
github.com/gorilla/sessions v1.4.0
github.com/lmittmann/tint v1.0.5
github.com/r3labs/sse/v2 v2.10.0 github.com/r3labs/sse/v2 v2.10.0
github.com/shirou/gopsutil/v4 v4.24.9 github.com/shirou/gopsutil/v4 v4.24.12
github.com/thanhpk/randstr v1.0.6
golang.org/x/oauth2 v0.23.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
require ( require (
github.com/ebitengine/purego v0.8.1 // indirect github.com/ebitengine/purego v0.8.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.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/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect github.com/tklauser/numcpus v0.9.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.28.0 // indirect golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.30.0 // indirect golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.26.0 // indirect golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.21.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
) )

58
go.sum
View file

@ -1,19 +1,15 @@
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY= github.com/a-h/templ v0.3.819 h1:KDJ5jTFN15FyJnmSmo2gNirIqt7hfvBD2VXVDTySckM=
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w= 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 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA=
github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18= 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/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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I=
github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
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/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 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 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= 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/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 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= 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.24.0 h1:KHQckvo8G6hlWnrPX4NJJ+aBfWNAE/HH+qdL2cBpCmg=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= 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 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 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.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 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/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 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= 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.7 h1:D/0OqWZ0YOGZ6AyC+5Y2kD8PBEzBk6rFHVSfOqCkF9Y=
github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= 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 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= 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= 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.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 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= 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.12 h1:qvePBOk20e0IKA1QXrIIU+jmk+zEiYVVx06WjBRlZo4=
github.com/shirou/gopsutil/v4 v4.24.9/go.mod h1:3fkaHNeYsUFCGZ8+9vZVWtbyM1k2eRnlL+bWO8Bxa/Q= 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/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.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.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.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/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= 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/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo= 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 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 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.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= 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.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.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/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.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 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 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= 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= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View file

@ -3,7 +3,6 @@ package handlers
import ( import (
"net/http" "net/http"
"github.com/gorilla/sessions"
"gitlab.unjx.de/flohoss/godash/internal/env" "gitlab.unjx.de/flohoss/godash/internal/env"
"gitlab.unjx.de/flohoss/godash/services" "gitlab.unjx.de/flohoss/godash/services"
"gitlab.unjx.de/flohoss/godash/views/home" "gitlab.unjx.de/flohoss/godash/views/home"
@ -22,10 +21,9 @@ type WeatherService interface {
GetCurrentWeather() *services.OpenWeather 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{ return &AppHandler{
env: env, env: env,
store: store,
systemService: s, systemService: s,
weatherService: w, weatherService: w,
bookmarkService: b, bookmarkService: b,
@ -34,7 +32,6 @@ func NewAppHandler(env *env.Config, store *sessions.CookieStore, s SystemService
type AppHandler struct { type AppHandler struct {
env *env.Config env *env.Config
store *sessions.CookieStore
systemService SystemService systemService SystemService
weatherService WeatherService weatherService WeatherService
bookmarkService BookmarkService bookmarkService BookmarkService
@ -48,12 +45,5 @@ func (bh *AppHandler) appHandler(w http.ResponseWriter, r *http.Request) {
titlePage := bh.env.Title titlePage := bh.env.Title
session, _ := bh.store.Get(r, StoreSessionKey) home.HomeIndex(titlePage, bh.env.Version, home.Home(titlePage, bookmarks, staticSystem, liveSystem, weather)).Render(r.Context(), w)
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)
} }

View file

@ -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)
})
}

View file

@ -6,17 +6,14 @@ import (
"github.com/r3labs/sse/v2" "github.com/r3labs/sse/v2"
) )
func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler, authHandler *AuthHandler) { func SetupRoutes(router *http.ServeMux, sse *sse.Server, appHandler *AppHandler) {
router.Handle("GET /sse", authHandler.AuthMiddleware(http.HandlerFunc(sse.ServeHTTP))) router.Handle("GET /sse", http.HandlerFunc(sse.ServeHTTP))
fsAssets := http.FileServer(http.Dir("assets")) 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")) 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.Handle("GET /", http.HandlerFunc(appHandler.appHandler))
router.HandleFunc("GET /callback", authHandler.handleCallback)
router.Handle("GET /", authHandler.AuthMiddleware(http.HandlerFunc(appHandler.appHandler)))
} }

27
internal/env/env.go vendored
View file

@ -8,22 +8,17 @@ import (
) )
type Config struct { type Config struct {
TimeZone string `env:"TZ" envDefault:"Etc/UTC" validate:"timezone"` TimeZone string `env:"TZ" envDefault:"Etc/UTC" validate:"timezone"`
Title string `env:"TITLE" envDefault:"goDash"` Title string `env:"TITLE" envDefault:"goDash"`
PublicUrl string `env:"PUBLIC_URL" validate:"required,url"` PublicUrl string `env:"PUBLIC_URL" validate:"required,url"`
Port int `env:"PORT" envDefault:"4000" validate:"min=1024,max=49151"` Port int `env:"PORT" envDefault:"4000" validate:"min=1024,max=49151"`
Version string `env:"APP_VERSION"` Version string `env:"APP_VERSION"`
LocationLatitude float32 `env:"LOCATION_LATITUDE" envDefault:"48.780331609463815" validate:"latitude"` LocationLatitude float32 `env:"LOCATION_LATITUDE" envDefault:"48.780331609463815" validate:"latitude"`
LocationLongitude float32 `env:"LOCATION_LONGITUDE" envDefault:"9.177968320179422" validate:"longitude"` LocationLongitude float32 `env:"LOCATION_LONGITUDE" envDefault:"9.177968320179422" validate:"longitude"`
WeatherKey string `env:"WEATHER_KEY"` WeatherKey string `env:"WEATHER_KEY"`
WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"` WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"`
WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"` WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"`
WeatherDigits bool `env:"WEATHER_DIGITS" envDefault:"false"` 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"`
} }
var errParse = errors.New("error parsing environment variables") var errParse = errors.New("error parsing environment variables")

23
main.go
View file

@ -5,11 +5,8 @@ import (
"fmt" "fmt"
"log/slog" "log/slog"
"net/http" "net/http"
"net/url"
"os" "os"
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
"github.com/r3labs/sse/v2" "github.com/r3labs/sse/v2"
"gitlab.unjx.de/flohoss/godash/handlers" "gitlab.unjx.de/flohoss/godash/handlers"
@ -35,24 +32,8 @@ func main() {
w := services.NewWeatherService(sse, env) w := services.NewWeatherService(sse, env)
b := services.NewBookmarkService() b := services.NewBookmarkService()
parsedUrl, _ := url.Parse(env.PublicUrl) appHandler := handlers.NewAppHandler(env, s, w, b)
secret := []byte(env.SessionKey) handlers.SetupRoutes(router, sse, appHandler)
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)
slog.Info("server listening, press ctrl+c to stop", "addr", env.PublicUrl) slog.Info("server listening, press ctrl+c to stop", "addr", env.PublicUrl)
err = http.ListenAndServe(fmt.Sprintf(":%d", env.Port), router) err = http.ListenAndServe(fmt.Sprintf(":%d", env.Port), router)

View file

@ -6,68 +6,24 @@ import (
"io/fs" "io/fs"
"net/http" "net/http"
"os" "os"
"regexp"
"strings"
) )
func DownloadSelfHostedIcon(url, title, filePath string) ([]byte, error) { func DownloadSelfHostedIcon(url, title, filePath string) (string, error) {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { 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() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { 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) data, err := io.ReadAll(resp.Body)
if err != nil { 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)) err = os.WriteFile(filePath, data, fs.FileMode(0640))
if err != nil { 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 return filePath, nil
}
func insertWidthHeight(svgContent []byte) []byte {
classRegex := regexp.MustCompile(`(?:<svg(.+?)(width|height)=".+?")(.+?)(width|height)=".+?"|(<svg)`)
newSVGContent := classRegex.ReplaceAllFunc(svgContent, func(match []byte) []byte {
groups := classRegex.FindSubmatch(match)
if len(groups) == 0 {
return match
}
if string(match) == "<svg" {
return []byte(`<svg width="2rem" height="2rem" `)
} else {
return []byte(fmt.Sprintf(`<svg%s%s="2rem"%s%s="2rem"`, groups[1], groups[2], groups[3], groups[4]))
}
})
return newSVGContent
}
func replaceClassNames(svgContent []byte, title string) []byte {
// Regular expression to match either class="st0" or .st0
classRegex := regexp.MustCompile(`(class="|\.)([a-z]{2}\d)`)
title = strings.TrimSuffix(title, ".svg")
newSVGContent := classRegex.ReplaceAllFunc(svgContent, func(match []byte) []byte {
groups := classRegex.FindSubmatch(match)
if len(groups) == 0 {
return match
}
group1 := string(groups[1])
group2 := string(groups[2])
if group1 == `class="` {
return []byte(`class="` + title + "-" + group2)
}
if group1 == `.` {
return []byte(`.` + title + "-" + group2)
}
return match
})
return newSVGContent
} }

View file

@ -24,11 +24,11 @@ applications:
- category: "Code" - category: "Code"
entries: entries:
- name: "GitHub" - name: "GitHub"
icon: "shi/github.svg" icon: "sh/github"
ignore_color: true ignore_color: true
url: "https://github.com" url: "https://github.com"
- name: "Home Assistant" - name: "Home Assistant"
icon: "shi/home-assistant.svg" icon: "sh/home-assistant"
url: "https://www.home-assistant.io/"` url: "https://www.home-assistant.io/"`
func init() { func init() {
@ -85,84 +85,69 @@ func (bs *BookmarkService) readBookmarksFile() []byte {
func (bs *BookmarkService) replaceIconStrings() { func (bs *BookmarkService) replaceIconStrings() {
for i, v := range bs.bookmarks.Applications { for i, v := range bs.bookmarks.Applications {
for j, bookmark := range v.Entries { for j, bookmark := range v.Entries {
ext := filepath.Ext(bookmark.Icon) var filePath, filePathLight string
if ext != ".svg" {
slog.Error("icon must be an svg file")
continue
}
var data, lightData []byte
var err error var err error
if strings.HasPrefix(bookmark.Icon, "shi/") { if strings.HasPrefix(bookmark.Icon, "sh/") {
data, lightData, err = downloadIcons(handleSelfHostedIcons(bookmark.Icon, ext)) filePath, filePathLight, err = downloadIcons(handleSelfHostedIcons(bookmark.Icon, ".webp"))
if err != nil { if err != nil {
slog.Error(err.Error()) slog.Error(err.Error())
continue continue
} }
} else if strings.HasPrefix(bookmark.Icon, "si/") {
data, lightData, err = downloadIcons(handleSimpleIcons(bookmark.Icon, ext))
if err != nil {
slog.Error(err.Error())
continue
}
} else { } else {
data, lightData, err = handleLocalIcons(bookmark.Icon, ext) ext := filepath.Ext(bookmark.Icon)
if err != nil { filePath, filePathLight = handleLocalIcons(bookmark.Icon, ext)
slog.Error(err.Error()) if filePath == "" {
continue slog.Warn("could not find local icon", "path", bookmark.Icon)
} }
} }
bs.bookmarks.Applications[i].Entries[j].Icon = string(data) bs.bookmarks.Applications[i].Entries[j].Icon = filePath
bs.bookmarks.Applications[i].Entries[j].IconLight = string(lightData) bs.bookmarks.Applications[i].Entries[j].IconLight = filePathLight
} }
} }
} }
func downloadIcons(title, url, lightTitle, lightUrl string) ([]byte, []byte, error) { func downloadIcons(title, url, lightTitle, lightUrl string) (string, string, error) {
data, err := downloadIcon(title, url) path, err := downloadIcon(title, url)
if err != nil { if err != nil {
return nil, nil, err return "", "", err
} }
lightData, _ := downloadIcon(lightTitle, lightUrl) lightPath, _ := downloadIcon(lightTitle, lightUrl)
return data, lightData, nil return path, lightPath, nil
} }
func downloadIcon(title, url string) ([]byte, error) { func downloadIcon(title, url string) (string, error) {
filePath := iconsFolder + title filePath := iconsFolder + title
data, err := os.ReadFile(filePath) _, err := os.Stat(filePath)
if err != nil { if os.IsNotExist(err) {
data, err = media.DownloadSelfHostedIcon(url, title, filePath) filePath, err = media.DownloadSelfHostedIcon(url, title, filePath)
if err != nil { if err != nil {
return nil, err return "", err
} }
} }
return data, nil return "/" + strings.TrimPrefix(filePath, storageFolder), nil
} }
func handleSelfHostedIcons(icon, ext string) (string, string, string, string) { func handleSelfHostedIcons(icon, ext string) (string, string, string, string) {
title := strings.Replace(icon, "shi/", "", 1) title := strings.Replace(icon, "sh/", "", 1) + ext
url := "https://cdn.jsdelivr.net/gh/selfhst/icons/" + strings.TrimPrefix(ext, ".") + "/" + title url := "https://cdn.jsdelivr.net/gh/selfhst/icons/" + strings.TrimPrefix(ext, ".") + "/" + title
lightTitle := strings.Replace(title, ext, "-light.svg", 1) lightTitle := strings.Replace(title, ext, "-light"+ext, 1)
lightUrl := "https://cdn.jsdelivr.net/gh/selfhst/icons/" + strings.TrimPrefix(ext, ".") + "/" + lightTitle lightUrl := "https://cdn.jsdelivr.net/gh/selfhst/icons/" + strings.TrimPrefix(ext, ".") + "/" + lightTitle
return title, url, lightTitle, lightUrl return title, url, lightTitle, lightUrl
} }
func handleSimpleIcons(icon, ext string) (string, string, string, string) { func handleLocalIcons(title, ext string) (string, string) {
title := strings.Replace(icon, "si/", "", 1) filePath := iconsFolder + title
url := "https://cdn.simpleicons.org/" + strings.TrimSuffix(title, ext) _, err := os.Stat(filePath)
lightTitle := strings.Replace(title, ext, "-light.svg", 1) if os.IsNotExist(err) {
lightUrl := "https://cdn.simpleicons.org/" + strings.TrimSuffix(title, ext) + "/white" return "", ""
return title, url, lightTitle, lightUrl
}
func handleLocalIcons(title, ext string) ([]byte, []byte, error) {
data, err := os.ReadFile(iconsFolder + title)
if err != nil {
return nil, nil, err
} }
lightTitle := strings.Replace(title, ext, "-light.svg", 1) filePathLight := strings.Replace(title, ext, "-light"+ext, 1)
lightData, _ := os.ReadFile(iconsFolder + lightTitle) _, err = os.Stat(filePathLight)
return data, lightData, err if os.IsNotExist(err) {
return filePath, ""
}
return "/" + filePath, "/" + filePathLight
} }
func (bs *BookmarkService) parseBookmarks() { func (bs *BookmarkService) parseBookmarks() {

View file

@ -2,7 +2,7 @@ const { addDynamicIconSelectors } = require('@iconify/tailwind');
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
module.exports = { module.exports = {
content: ['./views/**/*.templ','./components/**/*.templ'], content: ['./views/**/*.templ'],
theme: { theme: {
container: { container: {
center: true center: true

View file

@ -0,0 +1,55 @@
package components
import (
"gitlab.unjx.de/flohoss/godash/services"
"html/template"
"strings"
)
func placeHolder(app services.Application) string {
return strings.ToUpper(app.Name[:1])
}
func displayLight(app services.Application) bool {
return app.Icon != ""
}
func displayDark(app services.Application) bool {
return !app.IgnoreDark && app.IconLight != ""
}
var bgTemplate = template.Must(template.New("bgTemplate").Parse(
`<div class="w-8 h-8 dark:hidden bg-cover bg-center" style="background-image: url('{{ .Path }}')"></div>`,
))
var bgTemplateDark = template.Must(template.New("bgTemplate").Parse(
`<div class="w-8 h-8 hidden dark:block bg-cover bg-center" style="background-image: url('{{ .Path }}')"></div>`,
))
type Icon struct {
Path string
}
templ Application(application services.Application) {
<a href={ templ.URL(application.URL) } class="flex items-center hover-effect">
if displayLight(application) {
@templ.FromGoHTML(bgTemplate, Icon{Path: application.Icon})
} else {
<div class="avatar placeholder">
<div class="bg-primary text-primary-content w-8 rounded-full">
<span class="text-xl">{ placeHolder(application) }</span>
</div>
</div>
}
if displayDark(application) {
@templ.FromGoHTML(bgTemplateDark, Icon{Path: application.IconLight})
}
<div class="uppercase truncate ml-2">{ application.Name }</div>
</a>
}
templ Link(link services.Link) {
<a href={ templ.URL(link.URL) } class="hover-effect">
<div class="truncate">{ link.Name }</div>
</a>
}

View file

@ -2,17 +2,14 @@ package home
import ( import (
"fmt" "fmt"
"gitlab.unjx.de/flohoss/godash/components"
"gitlab.unjx.de/flohoss/godash/services" "gitlab.unjx.de/flohoss/godash/services"
"gitlab.unjx.de/flohoss/godash/views/components"
"gitlab.unjx.de/flohoss/godash/views/layout" "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) {
<section class="grid gap-10"> <section class="grid gap-10">
<div class="flex w-full justify-between items-center"> @components.Weather(weather)
@components.Weather(weather)
@components.User(user)
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none"> <div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none">
@components.System("icon-[bi--cpu]", static.CPU.Name, "", static.CPU.Threads, "systemCpuPercentage", "", live.CPU) @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) @components.System("icon-[bi--nvme]", live.Disk.Value, fmt.Sprintf(" | %s", static.Disk.Total), static.Disk.Partitions, "systemDiskPercentage", "systemDiskValue", live.Disk.Percentage)