2020-07-29 21:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-29 19:51:15 +00:00
|
|
|
"fmt"
|
2021-01-31 23:12:50 +00:00
|
|
|
"io/fs"
|
2021-02-18 12:58:30 +00:00
|
|
|
"os"
|
2020-07-29 21:11:28 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2020-11-22 16:36:43 +00:00
|
|
|
"strings"
|
2020-08-16 12:36:54 +00:00
|
|
|
|
|
|
|
"gopkg.in/ini.v1"
|
2020-07-29 21:11:28 +00:00
|
|
|
)
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
var emailEnabled = false
|
2021-05-07 20:53:29 +00:00
|
|
|
var messagesEnabled = false
|
|
|
|
var telegramEnabled = false
|
2021-05-17 22:42:33 +00:00
|
|
|
var discordEnabled = false
|
2021-05-29 16:43:11 +00:00
|
|
|
var matrixEnabled = false
|
2021-01-31 18:50:04 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
func (app *appContext) GetPath(sect, key string) (fs.FS, string) {
|
|
|
|
val := app.config.Section(sect).Key(key).MustString("")
|
|
|
|
if strings.HasPrefix(val, "jfa-go:") {
|
2021-02-02 15:44:30 +00:00
|
|
|
return localFS, strings.TrimPrefix(val, "jfa-go:")
|
2021-01-31 23:12:50 +00:00
|
|
|
}
|
2021-02-18 12:58:30 +00:00
|
|
|
dir, file := filepath.Split(val)
|
|
|
|
return os.DirFS(dir), file
|
2021-01-31 23:12:50 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
func (app *appContext) MustSetValue(section, key, val string) {
|
|
|
|
app.config.Section(section).Key(key).SetValue(app.config.Section(section).Key(key).MustString(val))
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) loadConfig() error {
|
2020-07-29 21:11:28 +00:00
|
|
|
var err error
|
2020-11-22 16:36:43 +00:00
|
|
|
app.config, err = ini.Load(app.configPath)
|
2020-07-29 21:11:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("jellyfin", "public_server", app.config.Section("jellyfin").Key("server").String())
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
for _, key := range app.config.Section("files").Keys() {
|
2021-02-19 21:38:20 +00:00
|
|
|
if name := key.Name(); name != "html_templates" && name != "lang_files" {
|
2020-11-22 16:36:43 +00:00
|
|
|
key.SetValue(key.MustString(filepath.Join(app.dataPath, (key.Name() + ".json"))))
|
2020-10-23 13:39:04 +00:00
|
|
|
}
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
2021-07-10 15:43:27 +00:00
|
|
|
for _, key := range []string{"user_configuration", "user_displayprefs", "user_profiles", "ombi_template", "invites", "emails", "user_template", "custom_emails", "users", "telegram_users", "discord_users", "matrix_users", "announcements"} {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.config.Section("files").Key(key).SetValue(app.config.Section("files").Key(key).MustString(filepath.Join(app.dataPath, (key + ".json"))))
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
app.URLBase = strings.TrimSuffix(app.config.Section("ui").Key("url_base").MustString(""), "/")
|
2020-08-16 12:36:54 +00:00
|
|
|
app.config.Section("email").Key("no_username").SetValue(strconv.FormatBool(app.config.Section("email").Key("no_username").MustBool(false)))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("password_resets", "email_html", "jfa-go:"+"email.html")
|
|
|
|
app.MustSetValue("password_resets", "email_text", "jfa-go:"+"email.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("invite_emails", "email_html", "jfa-go:"+"invite-email.html")
|
|
|
|
app.MustSetValue("invite_emails", "email_text", "jfa-go:"+"invite-email.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("email_confirmation", "email_html", "jfa-go:"+"confirmation.html")
|
|
|
|
app.MustSetValue("email_confirmation", "email_text", "jfa-go:"+"confirmation.txt")
|
2021-01-30 19:19:12 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("notifications", "expiry_html", "jfa-go:"+"expired.html")
|
|
|
|
app.MustSetValue("notifications", "expiry_text", "jfa-go:"+"expired.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("notifications", "created_html", "jfa-go:"+"created.html")
|
|
|
|
app.MustSetValue("notifications", "created_text", "jfa-go:"+"created.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("deletion", "email_html", "jfa-go:"+"deleted.html")
|
|
|
|
app.MustSetValue("deletion", "email_text", "jfa-go:"+"deleted.txt")
|
2020-09-17 22:50:07 +00:00
|
|
|
|
2021-06-27 00:10:08 +00:00
|
|
|
jfUrl := app.config.Section("jellyfin").Key("server").String()
|
|
|
|
if !(strings.HasPrefix(jfUrl, "http://") || strings.HasPrefix(jfUrl, "https://")) {
|
|
|
|
app.config.Section("jellyfin").Key("server").SetValue("http://" + jfUrl)
|
|
|
|
}
|
|
|
|
|
2021-04-12 20:28:36 +00:00
|
|
|
// Deletion template is good enough for these as well.
|
|
|
|
app.MustSetValue("disable_enable", "disabled_html", "jfa-go:"+"deleted.html")
|
|
|
|
app.MustSetValue("disable_enable", "disabled_text", "jfa-go:"+"deleted.txt")
|
|
|
|
app.MustSetValue("disable_enable", "enabled_html", "jfa-go:"+"deleted.html")
|
|
|
|
app.MustSetValue("disable_enable", "enabled_text", "jfa-go:"+"deleted.txt")
|
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("welcome_email", "email_html", "jfa-go:"+"welcome.html")
|
|
|
|
app.MustSetValue("welcome_email", "email_text", "jfa-go:"+"welcome.txt")
|
2021-01-24 15:19:58 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("template_email", "email_html", "jfa-go:"+"template.html")
|
|
|
|
app.MustSetValue("template_email", "email_text", "jfa-go:"+"template.txt")
|
2021-02-18 14:58:53 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("user_expiry", "behaviour", "disable_user")
|
|
|
|
app.MustSetValue("user_expiry", "email_html", "jfa-go:"+"user-expired.html")
|
|
|
|
app.MustSetValue("user_expiry", "email_text", "jfa-go:"+"user-expired.txt")
|
2021-02-28 15:41:06 +00:00
|
|
|
|
2021-05-30 10:47:41 +00:00
|
|
|
app.MustSetValue("matrix", "topic", "Jellyfin notifications")
|
|
|
|
|
2021-02-22 01:23:42 +00:00
|
|
|
app.config.Section("jellyfin").Key("version").SetValue(version)
|
2020-09-29 19:51:15 +00:00
|
|
|
app.config.Section("jellyfin").Key("device").SetValue("jfa-go")
|
2021-02-22 01:23:42 +00:00
|
|
|
app.config.Section("jellyfin").Key("device_id").SetValue(fmt.Sprintf("jfa-go-%s-%s", version, commit))
|
2021-05-07 20:53:29 +00:00
|
|
|
messagesEnabled = app.config.Section("messages").Key("enabled").MustBool(false)
|
|
|
|
telegramEnabled = app.config.Section("telegram").Key("enabled").MustBool(false)
|
2021-05-17 22:42:33 +00:00
|
|
|
discordEnabled = app.config.Section("discord").Key("enabled").MustBool(false)
|
2021-05-29 16:43:11 +00:00
|
|
|
matrixEnabled = app.config.Section("matrix").Key("enabled").MustBool(false)
|
2021-05-07 20:53:29 +00:00
|
|
|
if !messagesEnabled {
|
|
|
|
emailEnabled = false
|
|
|
|
telegramEnabled = false
|
2021-05-17 22:42:33 +00:00
|
|
|
discordEnabled = false
|
2021-05-29 16:43:11 +00:00
|
|
|
matrixEnabled = false
|
2021-05-07 20:53:29 +00:00
|
|
|
} else if app.config.Section("email").Key("method").MustString("") == "" {
|
2021-01-31 18:50:04 +00:00
|
|
|
emailEnabled = false
|
|
|
|
} else {
|
|
|
|
emailEnabled = true
|
|
|
|
}
|
2021-05-29 16:43:11 +00:00
|
|
|
if !emailEnabled && !telegramEnabled && !discordEnabled && !matrixEnabled {
|
2021-05-07 20:53:29 +00:00
|
|
|
messagesEnabled = false
|
|
|
|
}
|
2021-01-31 18:50:04 +00:00
|
|
|
|
2021-03-07 15:23:44 +00:00
|
|
|
app.MustSetValue("updates", "enabled", "true")
|
|
|
|
releaseChannel := app.config.Section("updates").Key("channel").String()
|
|
|
|
if app.config.Section("updates").Key("enabled").MustBool(false) {
|
|
|
|
v := version
|
|
|
|
if releaseChannel == "stable" {
|
|
|
|
if version == "git" {
|
|
|
|
v = "0.0.0"
|
|
|
|
}
|
|
|
|
} else if releaseChannel == "unstable" {
|
|
|
|
v = "git"
|
|
|
|
}
|
|
|
|
app.updater = newUpdater(baseURL, namespace, repo, v, commit, updater)
|
|
|
|
}
|
|
|
|
if releaseChannel == "" {
|
|
|
|
if version == "git" {
|
|
|
|
releaseChannel = "unstable"
|
|
|
|
} else {
|
|
|
|
releaseChannel = "stable"
|
|
|
|
}
|
|
|
|
app.MustSetValue("updates", "channel", releaseChannel)
|
|
|
|
}
|
|
|
|
|
2021-02-19 21:38:20 +00:00
|
|
|
app.storage.customEmails_path = app.config.Section("files").Key("custom_emails").String()
|
|
|
|
app.storage.loadCustomEmails()
|
|
|
|
|
2021-01-10 15:51:04 +00:00
|
|
|
substituteStrings = app.config.Section("jellyfin").Key("substitute_jellyfin_strings").MustString("")
|
|
|
|
|
2021-01-12 23:37:22 +00:00
|
|
|
oldFormLang := app.config.Section("ui").Key("language").MustString("")
|
|
|
|
if oldFormLang != "" {
|
|
|
|
app.storage.lang.chosenFormLang = oldFormLang
|
|
|
|
}
|
|
|
|
newFormLang := app.config.Section("ui").Key("language-form").MustString("")
|
|
|
|
if newFormLang != "" {
|
|
|
|
app.storage.lang.chosenFormLang = newFormLang
|
|
|
|
}
|
|
|
|
app.storage.lang.chosenAdminLang = app.config.Section("ui").Key("language-admin").MustString("en-us")
|
2021-01-14 17:51:12 +00:00
|
|
|
app.storage.lang.chosenEmailLang = app.config.Section("email").Key("language").MustString("en-us")
|
2021-03-30 21:41:28 +00:00
|
|
|
app.storage.lang.chosenPWRLang = app.config.Section("password_resets").Key("language").MustString("en-us")
|
2021-05-07 00:08:12 +00:00
|
|
|
app.storage.lang.chosenTelegramLang = app.config.Section("telegram").Key("language").MustString("en-us")
|
2021-01-14 17:51:12 +00:00
|
|
|
|
|
|
|
app.email = NewEmailer(app)
|
2021-01-11 19:17:43 +00:00
|
|
|
|
2020-07-29 21:11:28 +00:00
|
|
|
return nil
|
|
|
|
}
|