@@ -82,3 +132,16 @@ templ GlobalSettings(smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort,
}
}
+
+func dbShowSQLite(t string) string {
+ if t == "sqlite" || t == "" {
+ return "block"
+ }
+ return "none"
+}
+func dbShowMaria(t string) string {
+ if t == "mariadb" {
+ return "block"
+ }
+ return "none"
+}
diff --git a/src/core/admin/templates/global_templ.go b/src/core/admin/templates/global_templ.go
index 8258867..7b26adc 100644
--- a/src/core/admin/templates/global_templ.go
+++ b/src/core/admin/templates/global_templ.go
@@ -8,7 +8,7 @@ package templates
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
-func GlobalSettings(smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort, nextwksURL, authURL, lang, tz, msg string) templ.Component {
+func GlobalSettings(dbType, dbPath, dbHost, dbPort, dbUser, dbPass, dbName, smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort, nextwksURL, authURL, lang, tz, msg string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -64,181 +64,279 @@ func GlobalSettings(smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort,
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -252,4 +350,17 @@ func GlobalSettings(smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort,
})
}
+func dbShowSQLite(t string) string {
+ if t == "sqlite" || t == "" {
+ return "block"
+ }
+ return "none"
+}
+func dbShowMaria(t string) string {
+ if t == "mariadb" {
+ return "block"
+ }
+ return "none"
+}
+
var _ = templruntime.GeneratedTemplate
diff --git a/src/core/admin/ui.go b/src/core/admin/ui.go
index 2f08a99..d13bf28 100644
--- a/src/core/admin/ui.go
+++ b/src/core/admin/ui.go
@@ -47,6 +47,8 @@ func (h *Handler) cancelForm(w http.ResponseWriter, r *http.Request) {
func (h *Handler) adminGlobal(w http.ResponseWriter, r *http.Request) {
cfg := readConfigRaw(h.configPath)
component := templates.GlobalSettings(
+ cfg["db_type"], cfg["db_path"], cfg["db_host"], cfg["db_port"],
+ cfg["db_user"], cfg["db_pass"], cfg["db_name"],
cfg["smtp_host"], cfg["smtp_port"], cfg["smtp_user"], cfg["smtp_pass"],
cfg["imap_host"], cfg["imap_port"], cfg["nextwks_url"], cfg["auth_url"],
cfg["lang"], cfg["tz"], "",
@@ -61,6 +63,8 @@ func (h *Handler) adminGlobalSave(w http.ResponseWriter, r *http.Request) {
// Re-read to show updated values
cfg := readConfigRaw(h.configPath)
component := templates.GlobalSettings(
+ cfg["db_type"], cfg["db_path"], cfg["db_host"], cfg["db_port"],
+ cfg["db_user"], cfg["db_pass"], cfg["db_name"],
cfg["smtp_host"], cfg["smtp_port"], cfg["smtp_user"], cfg["smtp_pass"],
cfg["imap_host"], cfg["imap_port"], cfg["nextwks_url"], cfg["auth_url"],
cfg["lang"], cfg["tz"], msg,
@@ -79,6 +83,13 @@ func readConfigRaw(path string) rawConfig {
yaml.Unmarshal(data, &m)
cfg := rawConfig{}
+ cfg["db_type"] = getNested(m, "database", "type")
+ cfg["db_path"] = getNested(m, "database", "path")
+ cfg["db_host"] = getNested(m, "database", "host")
+ cfg["db_port"] = getNested(m, "database", "port")
+ cfg["db_user"] = getNested(m, "database", "user")
+ cfg["db_pass"] = getNested(m, "database", "password")
+ cfg["db_name"] = getNested(m, "database", "name")
cfg["smtp_host"] = getNested(m, "smtp", "host")
cfg["smtp_port"] = getNested(m, "smtp", "port")
cfg["smtp_user"] = getNested(m, "smtp", "username")
@@ -103,7 +114,13 @@ func writeConfigRaw(path string, r *http.Request) string {
var m map[string]interface{}
yaml.Unmarshal(data, &m)
- setNested(m, r.FormValue("smtp_host"), "smtp", "host")
+ setNested(m, r.FormValue("db_type"), "database", "type")
+ setNested(m, r.FormValue("db_path"), "database", "path")
+ setNested(m, r.FormValue("db_host"), "database", "host")
+ setNested(m, r.FormValue("db_port"), "database", "port")
+ setNested(m, r.FormValue("db_user"), "database", "user")
+ setNested(m, r.FormValue("db_pass"), "database", "password")
+ setNested(m, r.FormValue("db_name"), "database", "name")
setNested(m, r.FormValue("smtp_port"), "smtp", "port")
setNested(m, r.FormValue("smtp_user"), "smtp", "username")
setNested(m, r.FormValue("smtp_pass"), "smtp", "password")
diff --git a/src/core/config/config.go b/src/core/config/config.go
index 08cda95..7d5a325 100644
--- a/src/core/config/config.go
+++ b/src/core/config/config.go
@@ -30,8 +30,13 @@ type AdminConfig struct {
}
type DatabaseConfig struct {
- Type string `yaml:"type"`
- Path string `yaml:"path"`
+ Type string `yaml:"type"` // "sqlite" or "mariadb"
+ Path string `yaml:"path"` // SQLite file path
+ Host string `yaml:"host"` // MariaDB host
+ Port int `yaml:"port"` // MariaDB port
+ User string `yaml:"user"` // MariaDB user
+ Password string `yaml:"password"` // MariaDB password
+ Name string `yaml:"name"` // MariaDB database name
}
type AutheliaConfig struct {