diff --git a/cmd/OliveTin/main.go b/cmd/OliveTin/main.go index 92641a1..d097e6e 100644 --- a/cmd/OliveTin/main.go +++ b/cmd/OliveTin/main.go @@ -136,14 +136,13 @@ func reloadConfig() { os.Exit(1) } + cfg.SetDir(path.Dir(viper.ConfigFileUsed())) cfg.Sanitize() } func main() { - configDir := path.Dir(viper.ConfigFileUsed()) - log.WithFields(log.Fields{ - "configDir": configDir, + "configDir": cfg.GetDir(), }).Infof("OliveTin started") log.Debugf("Config: %+v", cfg) @@ -158,7 +157,7 @@ func main() { go entityfiles.SetupEntityFileWatchers(cfg) - go updatecheck.StartUpdateChecker(version, commit, cfg, configDir) + go updatecheck.StartUpdateChecker(version, commit, cfg, cfg.GetDir()) go grpcapi.Start(cfg, executor) diff --git a/internal/config/config.go b/internal/config/config.go index e8fe85a..6c6580f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -98,6 +98,8 @@ type Config struct { InsecureAllowDumpVars bool InsecureAllowDumpSos bool InsecureAllowDumpActionMap bool + + usedConfigDir string } type DashboardComponent struct { diff --git a/internal/config/config_helpers.go b/internal/config/config_helpers.go index 39f8f52..84769d6 100644 --- a/internal/config/config_helpers.go +++ b/internal/config/config_helpers.go @@ -42,3 +42,11 @@ func (cfg *Config) FindAcl(aclTitle string) *AccessControlList { return nil } + +func (cfg *Config) SetDir(dir string) { + cfg.usedConfigDir = dir +} + +func (cfg *Config) GetDir() string { + return cfg.usedConfigDir +} diff --git a/internal/httpservers/webuiServer.go b/internal/httpservers/webuiServer.go index b97b8b6..4a93a4d 100644 --- a/internal/httpservers/webuiServer.go +++ b/internal/httpservers/webuiServer.go @@ -4,16 +4,22 @@ import ( "encoding/json" // cors "github.com/OliveTin/OliveTin/internal/cors" log "github.com/sirupsen/logrus" + "io/ioutil" "net/http" "os" + "path" config "github.com/OliveTin/OliveTin/internal/config" updatecheck "github.com/OliveTin/OliveTin/internal/updatecheck" ) +var ( + customThemeCss []byte + customThemeCssRead = false +) + type webUISettings struct { Rest string - ThemeName string ShowFooter bool ShowNavigation bool ShowNewVersions bool @@ -52,10 +58,43 @@ func findWebuiDir() string { return "./webui" // Should not exist } +func findCustomWebuiDir() string { + dir := path.Join(cfg.GetDir(), "custom-webui") + + return dir +} + +func setupCustomWebuiDir() { + dir := findCustomWebuiDir() + + err := os.MkdirAll(path.Join(dir, "themes/"), 0775) + + if err != nil { + log.Warnf("Could not create themes directory: %v", err) + } +} + +func generateThemeCss(w http.ResponseWriter, r *http.Request) { + themeCssFilename := path.Join(findCustomWebuiDir(), "themes", cfg.ThemeName, "theme.css") + + if !customThemeCssRead { + customThemeCssRead = true + + if _, err := os.Stat(themeCssFilename); err == nil { + customThemeCss, err = ioutil.ReadFile(themeCssFilename) + } else { + log.Debugf("Theme CSS not read: %v", err) + customThemeCss = []byte("/* not found */") + } + } + + w.Header().Add("Content-Type", "text/css") + w.Write(customThemeCss) +} + func generateWebUISettings(w http.ResponseWriter, r *http.Request) { jsonRet, _ := json.Marshal(webUISettings{ Rest: cfg.ExternalRestAddress + "/api/", - ThemeName: cfg.ThemeName, ShowFooter: cfg.ShowFooter, ShowNavigation: cfg.ShowNavigation, ShowNewVersions: cfg.ShowNewVersions, @@ -77,8 +116,12 @@ func startWebUIServer(cfg *config.Config) { "address": cfg.ListenAddressWebUI, }).Info("Starting WebUI server") + setupCustomWebuiDir() + mux := http.NewServeMux() mux.Handle("/", http.FileServer(http.Dir(findWebuiDir()))) + mux.Handle("/custom-webui/", http.FileServer(http.Dir(findCustomWebuiDir()))) + mux.HandleFunc("/theme.css", generateThemeCss) mux.HandleFunc("/webUiSettings.json", generateWebUISettings) srv := &http.Server{ diff --git a/webui.dev/.parcelrc b/webui.dev/.parcelrc new file mode 100644 index 0000000..d459a24 --- /dev/null +++ b/webui.dev/.parcelrc @@ -0,0 +1,4 @@ +{ + "extends": "@parcel/config-default", + "resolvers": ["parcel-resolver-ignore", "..."] +} diff --git a/webui.dev/index.html b/webui.dev/index.html index e852584..29807c3 100644 --- a/webui.dev/index.html +++ b/webui.dev/index.html @@ -8,6 +8,7 @@