Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

config.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. // Copyright (c) 2012-2014 Jeremy Latt
  2. // Copyright (c) 2014-2015 Edmund Huber
  3. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  4. // released under the MIT license
  5. package irc
  6. import (
  7. "crypto/tls"
  8. "encoding/json"
  9. "errors"
  10. "fmt"
  11. "io/ioutil"
  12. "log"
  13. "path/filepath"
  14. "strings"
  15. "time"
  16. "code.cloudfoundry.org/bytefmt"
  17. "github.com/oragono/oragono/irc/connection_limits"
  18. "github.com/oragono/oragono/irc/custime"
  19. "github.com/oragono/oragono/irc/languages"
  20. "github.com/oragono/oragono/irc/logger"
  21. "github.com/oragono/oragono/irc/modes"
  22. "github.com/oragono/oragono/irc/passwd"
  23. "github.com/oragono/oragono/irc/utils"
  24. "gopkg.in/yaml.v2"
  25. )
  26. // PassConfig holds the connection password.
  27. type PassConfig struct {
  28. Password string
  29. }
  30. // TLSListenConfig defines configuration options for listening on TLS.
  31. type TLSListenConfig struct {
  32. Cert string
  33. Key string
  34. }
  35. // Config returns the TLS contiguration assicated with this TLSListenConfig.
  36. func (conf *TLSListenConfig) Config() (*tls.Config, error) {
  37. cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
  38. if err != nil {
  39. return nil, ErrInvalidCertKeyPair
  40. }
  41. return &tls.Config{
  42. Certificates: []tls.Certificate{cert},
  43. }, err
  44. }
  45. // PasswordBytes returns the bytes represented by the password hash.
  46. func (conf *PassConfig) PasswordBytes() []byte {
  47. bytes, err := passwd.DecodePasswordHash(conf.Password)
  48. if err != nil {
  49. log.Fatal("decode password error: ", err)
  50. }
  51. return bytes
  52. }
  53. type AccountConfig struct {
  54. Registration AccountRegistrationConfig
  55. AuthenticationEnabled bool `yaml:"authentication-enabled"`
  56. SkipServerPassword bool `yaml:"skip-server-password"`
  57. NickReservation NickReservationConfig `yaml:"nick-reservation"`
  58. }
  59. // AccountRegistrationConfig controls account registration.
  60. type AccountRegistrationConfig struct {
  61. Enabled bool
  62. EnabledCallbacks []string `yaml:"enabled-callbacks"`
  63. EnabledCredentialTypes []string `yaml:"-"`
  64. VerifyTimeout time.Duration `yaml:"verify-timeout"`
  65. Callbacks struct {
  66. Mailto struct {
  67. Server string
  68. Port int
  69. TLS struct {
  70. Enabled bool
  71. InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
  72. ServerName string `yaml:"servername"`
  73. }
  74. Username string
  75. Password string
  76. Sender string
  77. VerifyMessageSubject string `yaml:"verify-message-subject"`
  78. VerifyMessage string `yaml:"verify-message"`
  79. }
  80. }
  81. AllowMultiplePerConnection bool `yaml:"allow-multiple-per-connection"`
  82. }
  83. type NickReservationMethod int
  84. const (
  85. NickReservationWithTimeout NickReservationMethod = iota
  86. NickReservationStrict
  87. )
  88. func (nr *NickReservationMethod) UnmarshalYAML(unmarshal func(interface{}) error) error {
  89. var orig, raw string
  90. var err error
  91. if err = unmarshal(&orig); err != nil {
  92. return err
  93. }
  94. if raw, err = Casefold(orig); err != nil {
  95. return err
  96. }
  97. if raw == "timeout" {
  98. *nr = NickReservationWithTimeout
  99. } else if raw == "strict" {
  100. *nr = NickReservationStrict
  101. } else {
  102. return errors.New(fmt.Sprintf("invalid nick-reservation.method value: %s", orig))
  103. }
  104. return nil
  105. }
  106. type NickReservationConfig struct {
  107. Enabled bool
  108. AdditionalNickLimit int `yaml:"additional-nick-limit"`
  109. Method NickReservationMethod
  110. RenameTimeout time.Duration `yaml:"rename-timeout"`
  111. RenamePrefix string `yaml:"rename-prefix"`
  112. }
  113. // ChannelRegistrationConfig controls channel registration.
  114. type ChannelRegistrationConfig struct {
  115. Enabled bool
  116. }
  117. // OperClassConfig defines a specific operator class.
  118. type OperClassConfig struct {
  119. Title string
  120. WhoisLine string
  121. Extends string
  122. Capabilities []string
  123. }
  124. // OperConfig defines a specific operator's configuration.
  125. type OperConfig struct {
  126. Class string
  127. Vhost string
  128. WhoisLine string `yaml:"whois-line"`
  129. Password string
  130. Modes string
  131. }
  132. // PasswordBytes returns the bytes represented by the password hash.
  133. func (conf *OperConfig) PasswordBytes() []byte {
  134. bytes, err := passwd.DecodePasswordHash(conf.Password)
  135. if err != nil {
  136. log.Fatal("decode password error: ", err)
  137. }
  138. return bytes
  139. }
  140. // LineLenConfig controls line lengths.
  141. type LineLenConfig struct {
  142. Tags int
  143. Rest int
  144. }
  145. // STSConfig controls the STS configuration/
  146. type STSConfig struct {
  147. Enabled bool
  148. Duration time.Duration `yaml:"duration-real"`
  149. DurationString string `yaml:"duration"`
  150. Port int
  151. Preload bool
  152. }
  153. // Value returns the STS value to advertise in CAP
  154. func (sts *STSConfig) Value() string {
  155. val := fmt.Sprintf("duration=%d", int(sts.Duration.Seconds()))
  156. if sts.Enabled && sts.Port > 0 {
  157. val += fmt.Sprintf(",port=%d", sts.Port)
  158. }
  159. if sts.Enabled && sts.Preload {
  160. val += ",preload"
  161. }
  162. return val
  163. }
  164. // StackImpactConfig is the config used for StackImpact's profiling.
  165. type StackImpactConfig struct {
  166. Enabled bool
  167. AgentKey string `yaml:"agent-key"`
  168. AppName string `yaml:"app-name"`
  169. }
  170. type FakelagConfig struct {
  171. Enabled bool
  172. Window time.Duration
  173. BurstLimit uint `yaml:"burst-limit"`
  174. MessagesPerWindow uint `yaml:"messages-per-window"`
  175. Cooldown time.Duration
  176. }
  177. // Config defines the overall configuration.
  178. type Config struct {
  179. Network struct {
  180. Name string
  181. }
  182. Server struct {
  183. PassConfig
  184. Password string
  185. Name string
  186. Listen []string
  187. TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
  188. STS STSConfig
  189. CheckIdent bool `yaml:"check-ident"`
  190. MOTD string
  191. MOTDFormatting bool `yaml:"motd-formatting"`
  192. ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
  193. WebIRC []webircConfig `yaml:"webirc"`
  194. MaxSendQString string `yaml:"max-sendq"`
  195. MaxSendQBytes int
  196. ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"`
  197. ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
  198. }
  199. Languages struct {
  200. Enabled bool
  201. Path string
  202. Default string
  203. Data map[string]languages.LangData
  204. }
  205. Datastore struct {
  206. Path string
  207. AutoUpgrade bool
  208. }
  209. Accounts AccountConfig
  210. Channels struct {
  211. DefaultModes *string `yaml:"default-modes"`
  212. Registration ChannelRegistrationConfig
  213. }
  214. OperClasses map[string]*OperClassConfig `yaml:"oper-classes"`
  215. Opers map[string]*OperConfig
  216. Logging []logger.LoggingConfig
  217. Debug struct {
  218. RecoverFromErrors *bool `yaml:"recover-from-errors"`
  219. PprofListener *string `yaml:"pprof-listener"`
  220. StackImpact StackImpactConfig
  221. }
  222. Limits struct {
  223. AwayLen uint `yaml:"awaylen"`
  224. ChanListModes uint `yaml:"chan-list-modes"`
  225. ChannelLen uint `yaml:"channellen"`
  226. KickLen uint `yaml:"kicklen"`
  227. MonitorEntries uint `yaml:"monitor-entries"`
  228. NickLen uint `yaml:"nicklen"`
  229. TopicLen uint `yaml:"topiclen"`
  230. WhowasEntries uint `yaml:"whowas-entries"`
  231. LineLen LineLenConfig `yaml:"linelen"`
  232. }
  233. Fakelag FakelagConfig
  234. Filename string
  235. }
  236. // OperClass defines an assembled operator class.
  237. type OperClass struct {
  238. Title string
  239. WhoisLine string `yaml:"whois-line"`
  240. Capabilities map[string]bool // map to make lookups much easier
  241. }
  242. // OperatorClasses returns a map of assembled operator classes from the given config.
  243. func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
  244. ocs := make(map[string]OperClass)
  245. // loop from no extends to most extended, breaking if we can't add any more
  246. lenOfLastOcs := -1
  247. for {
  248. if lenOfLastOcs == len(ocs) {
  249. return nil, ErrOperClassDependencies
  250. }
  251. lenOfLastOcs = len(ocs)
  252. var anyMissing bool
  253. for name, info := range conf.OperClasses {
  254. _, exists := ocs[name]
  255. _, extendsExists := ocs[info.Extends]
  256. if exists {
  257. // class already exists
  258. continue
  259. } else if len(info.Extends) > 0 && !extendsExists {
  260. // class we extend on doesn't exist
  261. _, exists := conf.OperClasses[info.Extends]
  262. if !exists {
  263. return nil, fmt.Errorf("Operclass [%s] extends [%s], which doesn't exist", name, info.Extends)
  264. }
  265. anyMissing = true
  266. continue
  267. }
  268. // create new operclass
  269. var oc OperClass
  270. oc.Capabilities = make(map[string]bool)
  271. // get inhereted info from other operclasses
  272. if len(info.Extends) > 0 {
  273. einfo, _ := ocs[info.Extends]
  274. for capab := range einfo.Capabilities {
  275. oc.Capabilities[capab] = true
  276. }
  277. }
  278. // add our own info
  279. oc.Title = info.Title
  280. for _, capab := range info.Capabilities {
  281. oc.Capabilities[capab] = true
  282. }
  283. if len(info.WhoisLine) > 0 {
  284. oc.WhoisLine = info.WhoisLine
  285. } else {
  286. oc.WhoisLine = "is a"
  287. if strings.Contains(strings.ToLower(string(oc.Title[0])), "aeiou") {
  288. oc.WhoisLine += "n"
  289. }
  290. oc.WhoisLine += " "
  291. oc.WhoisLine += oc.Title
  292. }
  293. ocs[name] = oc
  294. }
  295. if !anyMissing {
  296. // we've got every operclass!
  297. break
  298. }
  299. }
  300. return &ocs, nil
  301. }
  302. // Oper represents a single assembled operator's config.
  303. type Oper struct {
  304. Class *OperClass
  305. WhoisLine string
  306. Vhost string
  307. Pass []byte
  308. Modes []modes.ModeChange
  309. }
  310. // Operators returns a map of operator configs from the given OperClass and config.
  311. func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error) {
  312. operators := make(map[string]Oper)
  313. for name, opConf := range conf.Opers {
  314. var oper Oper
  315. // oper name
  316. name, err := CasefoldName(name)
  317. if err != nil {
  318. return nil, fmt.Errorf("Could not casefold oper name: %s", err.Error())
  319. }
  320. oper.Pass = opConf.PasswordBytes()
  321. oper.Vhost = opConf.Vhost
  322. class, exists := (*oc)[opConf.Class]
  323. if !exists {
  324. return nil, fmt.Errorf("Could not load operator [%s] - they use operclass [%s] which does not exist", name, opConf.Class)
  325. }
  326. oper.Class = &class
  327. if len(opConf.WhoisLine) > 0 {
  328. oper.WhoisLine = opConf.WhoisLine
  329. } else {
  330. oper.WhoisLine = class.WhoisLine
  331. }
  332. modeStr := strings.TrimSpace(opConf.Modes)
  333. modeChanges, unknownChanges := modes.ParseUserModeChanges(strings.Split(modeStr, " ")...)
  334. if len(unknownChanges) > 0 {
  335. return nil, fmt.Errorf("Could not load operator [%s] due to unknown modes %v", name, unknownChanges)
  336. }
  337. oper.Modes = modeChanges
  338. // successful, attach to list of opers
  339. operators[name] = oper
  340. }
  341. return operators, nil
  342. }
  343. // TLSListeners returns a list of TLS listeners and their configs.
  344. func (conf *Config) TLSListeners() map[string]*tls.Config {
  345. tlsListeners := make(map[string]*tls.Config)
  346. for s, tlsListenersConf := range conf.Server.TLSListeners {
  347. config, err := tlsListenersConf.Config()
  348. if err != nil {
  349. log.Fatal(err)
  350. }
  351. config.ClientAuth = tls.RequestClientCert
  352. tlsListeners[s] = config
  353. }
  354. return tlsListeners
  355. }
  356. // LoadConfig loads the given YAML configuration file.
  357. func LoadConfig(filename string) (config *Config, err error) {
  358. data, err := ioutil.ReadFile(filename)
  359. if err != nil {
  360. return nil, err
  361. }
  362. err = yaml.Unmarshal(data, &config)
  363. if err != nil {
  364. return nil, err
  365. }
  366. config.Filename = filename
  367. // we need this so PasswordBytes returns the correct info
  368. if config.Server.Password != "" {
  369. config.Server.PassConfig.Password = config.Server.Password
  370. }
  371. if config.Network.Name == "" {
  372. return nil, ErrNetworkNameMissing
  373. }
  374. if config.Server.Name == "" {
  375. return nil, ErrServerNameMissing
  376. }
  377. if !utils.IsHostname(config.Server.Name) {
  378. return nil, ErrServerNameNotHostname
  379. }
  380. if config.Datastore.Path == "" {
  381. return nil, ErrDatastorePathMissing
  382. }
  383. if len(config.Server.Listen) == 0 {
  384. return nil, ErrNoListenersDefined
  385. }
  386. if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
  387. return nil, ErrLimitsAreInsane
  388. }
  389. if config.Server.STS.Enabled {
  390. config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
  391. if err != nil {
  392. return nil, fmt.Errorf("Could not parse STS duration: %s", err.Error())
  393. }
  394. if config.Server.STS.Port < 0 || config.Server.STS.Port > 65535 {
  395. return nil, fmt.Errorf("STS port is incorrect, should be 0 if disabled: %d", config.Server.STS.Port)
  396. }
  397. }
  398. if config.Server.ConnectionThrottler.Enabled {
  399. config.Server.ConnectionThrottler.Duration, err = time.ParseDuration(config.Server.ConnectionThrottler.DurationString)
  400. if err != nil {
  401. return nil, fmt.Errorf("Could not parse connection-throttle duration: %s", err.Error())
  402. }
  403. config.Server.ConnectionThrottler.BanDuration, err = time.ParseDuration(config.Server.ConnectionThrottler.BanDurationString)
  404. if err != nil {
  405. return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
  406. }
  407. }
  408. // process webirc blocks
  409. var newWebIRC []webircConfig
  410. for _, webirc := range config.Server.WebIRC {
  411. // skip webirc blocks with no hosts (such as the example one)
  412. if len(webirc.Hosts) == 0 {
  413. continue
  414. }
  415. err = webirc.Populate()
  416. if err != nil {
  417. return nil, fmt.Errorf("Could not parse WebIRC config: %s", err.Error())
  418. }
  419. newWebIRC = append(newWebIRC, webirc)
  420. }
  421. config.Server.WebIRC = newWebIRC
  422. // process limits
  423. if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
  424. return nil, ErrLineLengthsTooSmall
  425. }
  426. var newLogConfigs []logger.LoggingConfig
  427. for _, logConfig := range config.Logging {
  428. // methods
  429. methods := make(map[string]bool)
  430. for _, method := range strings.Split(logConfig.Method, " ") {
  431. if len(method) > 0 {
  432. methods[strings.ToLower(method)] = true
  433. }
  434. }
  435. if methods["file"] && logConfig.Filename == "" {
  436. return nil, ErrLoggerFilenameMissing
  437. }
  438. logConfig.MethodFile = methods["file"]
  439. logConfig.MethodStdout = methods["stdout"]
  440. logConfig.MethodStderr = methods["stderr"]
  441. // levels
  442. level, exists := logger.LogLevelNames[strings.ToLower(logConfig.LevelString)]
  443. if !exists {
  444. return nil, fmt.Errorf("Could not translate log leve [%s]", logConfig.LevelString)
  445. }
  446. logConfig.Level = level
  447. // types
  448. for _, typeStr := range strings.Split(logConfig.TypeString, " ") {
  449. if len(typeStr) == 0 {
  450. continue
  451. }
  452. if typeStr == "-" {
  453. return nil, ErrLoggerExcludeEmpty
  454. }
  455. if typeStr[0] == '-' {
  456. typeStr = typeStr[1:]
  457. logConfig.ExcludedTypes = append(logConfig.ExcludedTypes, typeStr)
  458. } else {
  459. logConfig.Types = append(logConfig.Types, typeStr)
  460. }
  461. }
  462. if len(logConfig.Types) < 1 {
  463. return nil, ErrLoggerHasNoTypes
  464. }
  465. newLogConfigs = append(newLogConfigs, logConfig)
  466. }
  467. config.Logging = newLogConfigs
  468. // hardcode this for now
  469. config.Accounts.Registration.EnabledCredentialTypes = []string{"passphrase", "certfp"}
  470. for i, name := range config.Accounts.Registration.EnabledCallbacks {
  471. if name == "none" {
  472. // we store "none" as "*" internally
  473. config.Accounts.Registration.EnabledCallbacks[i] = "*"
  474. }
  475. }
  476. maxSendQBytes, err := bytefmt.ToBytes(config.Server.MaxSendQString)
  477. if err != nil {
  478. return nil, fmt.Errorf("Could not parse maximum SendQ size (make sure it only contains whole numbers): %s", err.Error())
  479. }
  480. config.Server.MaxSendQBytes = int(maxSendQBytes)
  481. // get language files
  482. config.Languages.Data = make(map[string]languages.LangData)
  483. if config.Languages.Enabled {
  484. files, err := ioutil.ReadDir(config.Languages.Path)
  485. if err != nil {
  486. return nil, fmt.Errorf("Could not load language files: %s", err.Error())
  487. }
  488. for _, f := range files {
  489. // skip dirs
  490. if f.IsDir() {
  491. continue
  492. }
  493. // only load core .lang.yaml files, and ignore help/irc files
  494. name := f.Name()
  495. lowerName := strings.ToLower(name)
  496. if !strings.HasSuffix(lowerName, ".lang.yaml") {
  497. continue
  498. }
  499. // don't load our example files in practice
  500. if strings.HasPrefix(lowerName, "example") {
  501. continue
  502. }
  503. // load core info file
  504. data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, name))
  505. if err != nil {
  506. return nil, fmt.Errorf("Could not load language file [%s]: %s", name, err.Error())
  507. }
  508. var langInfo languages.LangData
  509. err = yaml.Unmarshal(data, &langInfo)
  510. if err != nil {
  511. return nil, fmt.Errorf("Could not parse language file [%s]: %s", name, err.Error())
  512. }
  513. langInfo.Translations = make(map[string]string)
  514. // load actual translation files
  515. var tlList map[string]string
  516. // load irc strings file
  517. ircName := strings.TrimSuffix(name, ".lang.yaml") + "-irc.lang.json"
  518. data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, ircName))
  519. if err != nil {
  520. return nil, fmt.Errorf("Could not load language's irc file [%s]: %s", ircName, err.Error())
  521. }
  522. err = json.Unmarshal(data, &tlList)
  523. if err != nil {
  524. return nil, fmt.Errorf("Could not parse language's irc file [%s]: %s", ircName, err.Error())
  525. }
  526. for key, value := range tlList {
  527. // because of how crowdin works, this is how we skip untranslated lines
  528. if key == value || value == "" {
  529. continue
  530. }
  531. langInfo.Translations[key] = value
  532. }
  533. // load help strings file
  534. helpName := strings.TrimSuffix(name, ".lang.yaml") + "-help.lang.json"
  535. data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, helpName))
  536. if err != nil {
  537. return nil, fmt.Errorf("Could not load language's help file [%s]: %s", helpName, err.Error())
  538. }
  539. err = json.Unmarshal(data, &tlList)
  540. if err != nil {
  541. return nil, fmt.Errorf("Could not parse language's help file [%s]: %s", helpName, err.Error())
  542. }
  543. for key, value := range tlList {
  544. // because of how crowdin works, this is how we skip untranslated lines
  545. if key == value || value == "" {
  546. continue
  547. }
  548. langInfo.Translations[key] = value
  549. }
  550. // confirm that values are correct
  551. if langInfo.Code == "en" {
  552. return nil, fmt.Errorf("Cannot have language file with code 'en' (this is the default language using strings inside the server code). If you're making an English variant, name it with a more specific code")
  553. }
  554. if langInfo.Code == "" || langInfo.Name == "" || langInfo.Contributors == "" {
  555. return nil, fmt.Errorf("Code, name or contributors is empty in language file [%s]", name)
  556. }
  557. if len(langInfo.Translations) == 0 {
  558. return nil, fmt.Errorf("Language [%s / %s] contains no translations", langInfo.Code, langInfo.Name)
  559. }
  560. // check for duplicate languages
  561. _, exists := config.Languages.Data[strings.ToLower(langInfo.Code)]
  562. if exists {
  563. return nil, fmt.Errorf("Language code [%s] defined twice", langInfo.Code)
  564. }
  565. // and insert into lang info
  566. config.Languages.Data[strings.ToLower(langInfo.Code)] = langInfo
  567. }
  568. // confirm that default language exists
  569. if config.Languages.Default == "" {
  570. config.Languages.Default = "en"
  571. } else {
  572. config.Languages.Default = strings.ToLower(config.Languages.Default)
  573. }
  574. _, exists := config.Languages.Data[config.Languages.Default]
  575. if config.Languages.Default != "en" && !exists {
  576. return nil, fmt.Errorf("Cannot find default language [%s]", config.Languages.Default)
  577. }
  578. }
  579. return config, nil
  580. }