mirror of
https://github.com/gotify/server.git
synced 2024-01-28 15:20:56 +03:00
Can be enabled via the registration config flag. (disabled per default) Fixes gotify/server#395 Co-authored-by: pigpig <pigpig@pig.pig> Co-authored-by: Karmanyaah Malhotra <32671690+karmanyaahm@users.noreply.github.com> Co-authored-by: Jannis Mattheis <contact@jmattheis.de>
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/gotify/configor"
|
|
"github.com/gotify/server/v2/mode"
|
|
)
|
|
|
|
// Configuration is stuff that can be configured externally per env variables or config file (config.yml).
|
|
type Configuration struct {
|
|
Server struct {
|
|
KeepAlivePeriodSeconds int
|
|
ListenAddr string `default:""`
|
|
Port int `default:"80"`
|
|
|
|
SSL struct {
|
|
Enabled *bool `default:"false"`
|
|
RedirectToHTTPS *bool `default:"true"`
|
|
ListenAddr string `default:""`
|
|
Port int `default:"443"`
|
|
CertFile string `default:""`
|
|
CertKey string `default:""`
|
|
LetsEncrypt struct {
|
|
Enabled *bool `default:"false"`
|
|
AcceptTOS *bool `default:"false"`
|
|
Cache string `default:"data/certs"`
|
|
Hosts []string
|
|
}
|
|
}
|
|
ResponseHeaders map[string]string
|
|
Stream struct {
|
|
PingPeriodSeconds int `default:"45"`
|
|
AllowedOrigins []string
|
|
}
|
|
Cors struct {
|
|
AllowOrigins []string
|
|
AllowMethods []string
|
|
AllowHeaders []string
|
|
}
|
|
}
|
|
Database struct {
|
|
Dialect string `default:"sqlite3"`
|
|
Connection string `default:"data/gotify.db"`
|
|
}
|
|
DefaultUser struct {
|
|
Name string `default:"admin"`
|
|
Pass string `default:"admin"`
|
|
}
|
|
PassStrength int `default:"10"`
|
|
UploadedImagesDir string `default:"data/images"`
|
|
PluginsDir string `default:"data/plugins"`
|
|
Registration bool `default:"false"`
|
|
}
|
|
|
|
func configFiles() []string {
|
|
if mode.Get() == mode.TestDev {
|
|
return []string{"config.yml"}
|
|
}
|
|
return []string{"config.yml", "/etc/gotify/config.yml"}
|
|
}
|
|
|
|
// Get returns the configuration extracted from env variables or config file.
|
|
func Get() *Configuration {
|
|
conf := new(Configuration)
|
|
err := configor.New(&configor.Config{EnvironmentPrefix: "GOTIFY"}).Load(conf, configFiles()...)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
addTrailingSlashToPaths(conf)
|
|
return conf
|
|
}
|
|
|
|
func addTrailingSlashToPaths(conf *Configuration) {
|
|
if !strings.HasSuffix(conf.UploadedImagesDir, "/") && !strings.HasSuffix(conf.UploadedImagesDir, "\\") {
|
|
conf.UploadedImagesDir += string(filepath.Separator)
|
|
}
|
|
}
|