feat(config): database settings (SQLite/MariaDB) in global settings

This commit is contained in:
Claus Lohmar 2026-06-15 04:57:24 +00:00
parent 6944223d35
commit ef9510704f
5 changed files with 284 additions and 83 deletions

View file

@ -225,6 +225,11 @@ admin:
database:
type: "sqlite"
path: "${DATA_DIR}/nextwks.db"
host: ""
port: 3306
user: ""
password: ""
name: ""
authelia:
host: "http://127.0.0.1:9091"
config_path: "${AUTHELIA_CONFIG}"

View file

@ -1,12 +1,62 @@
package templates
templ GlobalSettings(smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort, nextwksURL, authURL, lang, tz, msg string) {
templ GlobalSettings(dbType, dbPath, dbHost, dbPort, dbUser, dbPass, dbName, smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort, nextwksURL, authURL, lang, tz, msg string) {
@Layout("global") {
<h2 style="font-size:1.15rem;font-weight:600;margin-bottom:20px">Global Settings</h2>
if msg != "" {
<div class="alert success">{ msg }</div>
}
<form hx-post="/admin/global" hx-target="body" hx-swap="outerHTML">
<div class="form-card">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:12px">Database</h3>
<div class="form-group">
<label>Type</label>
<select name="db_type" class="input" onchange="toggleDBFields()" id="db_type">
<option value="sqlite" if dbType == "sqlite" { selected }>SQLite (built-in)</option>
<option value="mariadb" if dbType == "mariadb" { selected }>MariaDB (external)</option>
</select>
</div>
<div id="sqlite-fields" style="display:{ dbShowSQLite(dbType) }">
<div class="form-group">
<label>Data Path</label>
<input type="text" name="db_path" class="input" value={ dbPath } placeholder="/opt/nextwks/data/nextwks.db"/>
</div>
</div>
<div id="mariadb-fields" style="display:{ dbShowMaria(dbType) }">
<div class="form-row">
<div class="form-group">
<label>Host</label>
<input type="text" name="db_host" class="input" value={ dbHost }/>
</div>
<div class="form-group">
<label>Port</label>
<input type="text" name="db_port" class="input" value={ dbPort }/>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label>Username</label>
<input type="text" name="db_user" class="input" value={ dbUser }/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="db_pass" class="input" value={ dbPass }/>
</div>
</div>
<div class="form-group">
<label>Database Name</label>
<input type="text" name="db_name" class="input" value={ dbName }/>
</div>
</div>
</div>
<script type="text/javascript">
function toggleDBFields() {
var v = document.getElementById('db_type').value;
document.getElementById('sqlite-fields').style.display = v === 'sqlite' ? 'block' : 'none';
document.getElementById('mariadb-fields').style.display = v === 'mariadb' ? 'block' : 'none';
}
</script>
<div class="form-card">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:12px">Email</h3>
<div class="form-row">
@ -82,3 +132,16 @@ templ GlobalSettings(smtpHost, smtpPort, smtpUser, smtpPass, imapHost, imapPort,
</form>
}
}
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"
}

View file

@ -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, " <form hx-post=\"/admin/global\" hx-target=\"body\" hx-swap=\"outerHTML\"><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">Email</h3><div class=\"form-row\"><div class=\"form-group\"><label>SMTP Host</label> <input type=\"text\" name=\"smtp_host\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " <form hx-post=\"/admin/global\" hx-target=\"body\" hx-swap=\"outerHTML\"><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">Database</h3><div class=\"form-group\"><label>Type</label> <select name=\"db_type\" class=\"input\" onchange=\"toggleDBFields()\" id=\"db_type\"><option value=\"sqlite\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if dbType == "sqlite" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, ">SQLite (built-in)</option> <option value=\"mariadb\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if dbType == "mariadb" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, ">MariaDB (external)</option></select></div><div id=\"sqlite-fields\" style=\"display:{ dbShowSQLite(dbType) }\"><div class=\"form-group\"><label>Data Path</label> <input type=\"text\" name=\"db_path\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpHost)
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.ResolveAttributeValue(dbPath)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 15, Col: 72}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 22, Col: 68}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\"></div><div class=\"form-group\"><label>SMTP Port</label> <input type=\"text\" name=\"smtp_port\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" placeholder=\"/opt/nextwks/data/nextwks.db\"></div></div><div id=\"mariadb-fields\" style=\"display:{ dbShowMaria(dbType) }\"><div class=\"form-row\"><div class=\"form-group\"><label>Host</label> <input type=\"text\" name=\"db_host\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpPort)
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.ResolveAttributeValue(dbHost)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 19, Col: 72}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 29, Col: 69}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\"></div></div><div class=\"form-row\"><div class=\"form-group\"><label>SMTP Username</label> <input type=\"text\" name=\"smtp_user\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\"></div><div class=\"form-group\"><label>Port</label> <input type=\"text\" name=\"db_port\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpUser)
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.ResolveAttributeValue(dbPort)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 25, Col: 72}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 33, Col: 69}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\"></div><div class=\"form-group\"><label>SMTP Password</label> <input type=\"password\" name=\"smtp_pass\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "\"></div></div><div class=\"form-row\"><div class=\"form-group\"><label>Username</label> <input type=\"text\" name=\"db_user\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpPass)
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.ResolveAttributeValue(dbUser)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 29, Col: 76}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 39, Col: 69}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\"></div></div><div class=\"form-row\"><div class=\"form-group\"><label>IMAP Host</label> <input type=\"text\" name=\"imap_host\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "\"></div><div class=\"form-group\"><label>Password</label> <input type=\"password\" name=\"db_pass\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.ResolveAttributeValue(imapHost)
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.ResolveAttributeValue(dbPass)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 35, Col: 72}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 43, Col: 73}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\"></div><div class=\"form-group\"><label>IMAP Port</label> <input type=\"text\" name=\"imap_port\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\"></div></div><div class=\"form-group\"><label>Database Name</label> <input type=\"text\" name=\"db_name\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.ResolveAttributeValue(imapPort)
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.ResolveAttributeValue(dbName)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 39, Col: 72}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 48, Col: 68}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\"></div></div></div><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">URLs</h3><div class=\"form-row\"><div class=\"form-group\"><label>NextWks URL</label> <input type=\"text\" name=\"nextwks_url\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\"></div></div></div><script type=\"text/javascript\">\n\t\t\t\tfunction toggleDBFields() {\n\t\t\t\t\tvar v = document.getElementById('db_type').value;\n\t\t\t\t\tdocument.getElementById('sqlite-fields').style.display = v === 'sqlite' ? 'block' : 'none';\n\t\t\t\t\tdocument.getElementById('mariadb-fields').style.display = v === 'mariadb' ? 'block' : 'none';\n\t\t\t\t}\n\t\t\t</script><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">Email</h3><div class=\"form-row\"><div class=\"form-group\"><label>SMTP Host</label> <input type=\"text\" name=\"smtp_host\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.ResolveAttributeValue(nextwksURL)
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpHost)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 49, Col: 76}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 65, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "\"></div><div class=\"form-group\"><label>Auth URL</label> <input type=\"text\" name=\"auth_url\" class=\"input\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\"></div><div class=\"form-group\"><label>SMTP Port</label> <input type=\"text\" name=\"smtp_port\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.ResolveAttributeValue(authURL)
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpPort)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 53, Col: 70}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 69, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "\"></div></div></div><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">Localization</h3><div class=\"form-row\"><div class=\"form-group\"><label>Default Language</label> <select name=\"lang\" class=\"input\"><option value=\"en\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\"></div></div><div class=\"form-row\"><div class=\"form-group\"><label>SMTP Username</label> <input type=\"text\" name=\"smtp_user\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpUser)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 75, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\"></div><div class=\"form-group\"><label>SMTP Password</label> <input type=\"password\" name=\"smtp_pass\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.ResolveAttributeValue(smtpPass)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 79, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "\"></div></div><div class=\"form-row\"><div class=\"form-group\"><label>IMAP Host</label> <input type=\"text\" name=\"imap_host\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.ResolveAttributeValue(imapHost)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 85, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\"></div><div class=\"form-group\"><label>IMAP Port</label> <input type=\"text\" name=\"imap_port\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.ResolveAttributeValue(imapPort)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 89, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\"></div></div></div><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">URLs</h3><div class=\"form-row\"><div class=\"form-group\"><label>NextWks URL</label> <input type=\"text\" name=\"nextwks_url\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.ResolveAttributeValue(nextwksURL)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 99, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\"></div><div class=\"form-group\"><label>Auth URL</label> <input type=\"text\" name=\"auth_url\" class=\"input\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.ResolveAttributeValue(authURL)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `core/admin/templates/global.templ`, Line: 103, Col: 70}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\"></div></div></div><div class=\"form-card\"><h3 style=\"font-size:0.95rem;font-weight:600;margin-bottom:12px\">Localization</h3><div class=\"form-row\"><div class=\"form-group\"><label>Default Language</label> <select name=\"lang\" class=\"input\"><option value=\"en\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if lang == "en" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, ">English</option> <option value=\"de\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if lang == "de" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, ">Deutsch</option></select></div><div class=\"form-group\"><label>Default Timezone</label> <select name=\"tz\" class=\"input\"><option value=\"UTC\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "UTC" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, ">UTC</option> <option value=\"Europe/London\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "Europe/London" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, ">London</option> <option value=\"Europe/Berlin\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "Europe/Berlin" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, ">Berlin</option> <option value=\"Europe/Paris\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "Europe/Paris" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, ">Paris</option> <option value=\"America/New_York\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, ">English</option> <option value=\"de\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "America/New_York" {
if lang == "de" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, ">New York</option></select></div></div></div><button type=\"submit\" class=\"btn\" style=\"width:100%\">Save Settings</button></form>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, ">Deutsch</option></select></div><div class=\"form-group\"><label>Default Timezone</label> <select name=\"tz\" class=\"input\"><option value=\"UTC\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "UTC" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, ">UTC</option> <option value=\"Europe/London\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "Europe/London" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, ">London</option> <option value=\"Europe/Berlin\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "Europe/Berlin" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, ">Berlin</option> <option value=\"Europe/Paris\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "Europe/Paris" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, ">Paris</option> <option value=\"America/New_York\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if tz == "America/New_York" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, ">New York</option></select></div></div></div><button type=\"submit\" class=\"btn\" style=\"width:100%\">Save Settings</button></form>")
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

View file

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

View file

@ -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 {