options.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package config // import "miniflux.app/v2/internal/config"
  4. import (
  5. "fmt"
  6. "maps"
  7. "net/url"
  8. "slices"
  9. "strings"
  10. "time"
  11. "miniflux.app/v2/internal/crypto"
  12. "miniflux.app/v2/internal/version"
  13. )
  14. const (
  15. defaultHTTPS = false
  16. defaultLogFile = "stderr"
  17. defaultLogDateTime = false
  18. defaultLogFormat = "text"
  19. defaultLogLevel = "info"
  20. defaultHSTS = true
  21. defaultHTTPService = true
  22. defaultSchedulerService = true
  23. defaultBaseURL = "http://localhost"
  24. defaultRootURL = "http://localhost"
  25. defaultBasePath = ""
  26. defaultWorkerPoolSize = 16
  27. defaultPollingFrequency = 60
  28. defaultForceRefreshInterval = 30
  29. defaultBatchSize = 100
  30. defaultPollingScheduler = "round_robin"
  31. defaultSchedulerEntryFrequencyMinInterval = 5
  32. defaultSchedulerEntryFrequencyMaxInterval = 24 * 60
  33. defaultSchedulerEntryFrequencyFactor = 1
  34. defaultSchedulerRoundRobinMinInterval = 60
  35. defaultSchedulerRoundRobinMaxInterval = 1440
  36. defaultPollingParsingErrorLimit = 3
  37. defaultRunMigrations = false
  38. defaultDatabaseURL = "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
  39. defaultDatabaseMaxConns = 20
  40. defaultDatabaseMinConns = 1
  41. defaultDatabaseConnectionLifetime = 5
  42. defaultListenAddr = "127.0.0.1:8080"
  43. defaultCertFile = ""
  44. defaultKeyFile = ""
  45. defaultCertDomain = ""
  46. defaultCleanupFrequencyHours = 24
  47. defaultCleanupArchiveReadDays = 60
  48. defaultCleanupArchiveUnreadDays = 180
  49. defaultCleanupArchiveBatchSize = 10000
  50. defaultCleanupRemoveSessionsDays = 30
  51. defaultMediaProxyHTTPClientTimeout = 120
  52. defaultMediaProxyMode = "http-only"
  53. defaultMediaResourceTypes = "image"
  54. defaultMediaProxyURL = ""
  55. defaultFilterEntryMaxAgeDays = 0
  56. defaultFetchBilibiliWatchTime = false
  57. defaultFetchNebulaWatchTime = false
  58. defaultFetchOdyseeWatchTime = false
  59. defaultFetchYouTubeWatchTime = false
  60. defaultYouTubeApiKey = ""
  61. defaultYouTubeEmbedUrlOverride = "https://www.youtube-nocookie.com/embed/"
  62. defaultCreateAdmin = false
  63. defaultAdminUsername = ""
  64. defaultAdminPassword = ""
  65. defaultOAuth2UserCreation = false
  66. defaultOAuth2ClientID = ""
  67. defaultOAuth2ClientSecret = ""
  68. defaultOAuth2RedirectURL = ""
  69. defaultOAuth2OidcDiscoveryEndpoint = ""
  70. defaultOauth2OidcProviderName = "OpenID Connect"
  71. defaultOAuth2Provider = ""
  72. defaultDisableLocalAuth = false
  73. defaultHTTPClientTimeout = 20
  74. defaultHTTPClientMaxBodySize = 15
  75. defaultHTTPClientProxy = ""
  76. defaultHTTPServerTimeout = 300
  77. defaultAuthProxyHeader = ""
  78. defaultAuthProxyUserCreation = false
  79. defaultMaintenanceMode = false
  80. defaultMaintenanceMessage = "Miniflux is currently under maintenance"
  81. defaultMetricsCollector = false
  82. defaultMetricsRefreshInterval = 60
  83. defaultMetricsAllowedNetworks = "127.0.0.1/8"
  84. defaultMetricsUsername = ""
  85. defaultMetricsPassword = ""
  86. defaultWatchdog = true
  87. defaultInvidiousInstance = "yewtu.be"
  88. defaultWebAuthn = false
  89. )
  90. var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
  91. // option contains a key to value map of a single option. It may be used to output debug strings.
  92. type option struct {
  93. Key string
  94. Value any
  95. }
  96. // options contains configuration options.
  97. type options struct {
  98. HTTPS bool
  99. logFile string
  100. logDateTime bool
  101. logFormat string
  102. logLevel string
  103. hsts bool
  104. httpService bool
  105. schedulerService bool
  106. baseURL string
  107. rootURL string
  108. basePath string
  109. databaseURL string
  110. databaseMaxConns int
  111. databaseMinConns int
  112. databaseConnectionLifetime int
  113. runMigrations bool
  114. listenAddr []string
  115. certFile string
  116. certDomain string
  117. certKeyFile string
  118. cleanupFrequencyHours int
  119. cleanupArchiveReadDays int
  120. cleanupArchiveUnreadDays int
  121. cleanupArchiveBatchSize int
  122. cleanupRemoveSessionsDays int
  123. pollingFrequency int
  124. forceRefreshInterval int
  125. batchSize int
  126. pollingScheduler string
  127. schedulerEntryFrequencyMinInterval int
  128. schedulerEntryFrequencyMaxInterval int
  129. schedulerEntryFrequencyFactor int
  130. schedulerRoundRobinMinInterval int
  131. schedulerRoundRobinMaxInterval int
  132. pollingParsingErrorLimit int
  133. workerPoolSize int
  134. createAdmin bool
  135. adminUsername string
  136. adminPassword string
  137. mediaProxyHTTPClientTimeout int
  138. mediaProxyMode string
  139. mediaProxyResourceTypes []string
  140. mediaProxyCustomURL string
  141. fetchBilibiliWatchTime bool
  142. fetchNebulaWatchTime bool
  143. fetchOdyseeWatchTime bool
  144. fetchYouTubeWatchTime bool
  145. filterEntryMaxAgeDays int
  146. youTubeApiKey string
  147. youTubeEmbedUrlOverride string
  148. youTubeEmbedDomain string
  149. oauth2UserCreationAllowed bool
  150. oauth2ClientID string
  151. oauth2ClientSecret string
  152. oauth2RedirectURL string
  153. oidcDiscoveryEndpoint string
  154. oidcProviderName string
  155. oauth2Provider string
  156. disableLocalAuth bool
  157. httpClientTimeout int
  158. httpClientMaxBodySize int64
  159. httpClientProxyURL *url.URL
  160. httpClientProxies []string
  161. httpClientUserAgent string
  162. httpServerTimeout int
  163. authProxyHeader string
  164. authProxyUserCreation bool
  165. maintenanceMode bool
  166. maintenanceMessage string
  167. metricsCollector bool
  168. metricsRefreshInterval int
  169. metricsAllowedNetworks []string
  170. metricsUsername string
  171. metricsPassword string
  172. watchdog bool
  173. invidiousInstance string
  174. mediaProxyPrivateKey []byte
  175. webAuthn bool
  176. }
  177. // NewOptions returns Options with default values.
  178. func NewOptions() *options {
  179. return &options{
  180. HTTPS: defaultHTTPS,
  181. logFile: defaultLogFile,
  182. logDateTime: defaultLogDateTime,
  183. logFormat: defaultLogFormat,
  184. logLevel: defaultLogLevel,
  185. hsts: defaultHSTS,
  186. httpService: defaultHTTPService,
  187. schedulerService: defaultSchedulerService,
  188. baseURL: defaultBaseURL,
  189. rootURL: defaultRootURL,
  190. basePath: defaultBasePath,
  191. databaseURL: defaultDatabaseURL,
  192. databaseMaxConns: defaultDatabaseMaxConns,
  193. databaseMinConns: defaultDatabaseMinConns,
  194. databaseConnectionLifetime: defaultDatabaseConnectionLifetime,
  195. runMigrations: defaultRunMigrations,
  196. listenAddr: []string{defaultListenAddr},
  197. certFile: defaultCertFile,
  198. certDomain: defaultCertDomain,
  199. certKeyFile: defaultKeyFile,
  200. cleanupFrequencyHours: defaultCleanupFrequencyHours,
  201. cleanupArchiveReadDays: defaultCleanupArchiveReadDays,
  202. cleanupArchiveUnreadDays: defaultCleanupArchiveUnreadDays,
  203. cleanupArchiveBatchSize: defaultCleanupArchiveBatchSize,
  204. cleanupRemoveSessionsDays: defaultCleanupRemoveSessionsDays,
  205. pollingFrequency: defaultPollingFrequency,
  206. forceRefreshInterval: defaultForceRefreshInterval,
  207. batchSize: defaultBatchSize,
  208. pollingScheduler: defaultPollingScheduler,
  209. schedulerEntryFrequencyMinInterval: defaultSchedulerEntryFrequencyMinInterval,
  210. schedulerEntryFrequencyMaxInterval: defaultSchedulerEntryFrequencyMaxInterval,
  211. schedulerEntryFrequencyFactor: defaultSchedulerEntryFrequencyFactor,
  212. schedulerRoundRobinMinInterval: defaultSchedulerRoundRobinMinInterval,
  213. schedulerRoundRobinMaxInterval: defaultSchedulerRoundRobinMaxInterval,
  214. pollingParsingErrorLimit: defaultPollingParsingErrorLimit,
  215. workerPoolSize: defaultWorkerPoolSize,
  216. createAdmin: defaultCreateAdmin,
  217. mediaProxyHTTPClientTimeout: defaultMediaProxyHTTPClientTimeout,
  218. mediaProxyMode: defaultMediaProxyMode,
  219. mediaProxyResourceTypes: []string{defaultMediaResourceTypes},
  220. mediaProxyCustomURL: defaultMediaProxyURL,
  221. filterEntryMaxAgeDays: defaultFilterEntryMaxAgeDays,
  222. fetchBilibiliWatchTime: defaultFetchBilibiliWatchTime,
  223. fetchNebulaWatchTime: defaultFetchNebulaWatchTime,
  224. fetchOdyseeWatchTime: defaultFetchOdyseeWatchTime,
  225. fetchYouTubeWatchTime: defaultFetchYouTubeWatchTime,
  226. youTubeApiKey: defaultYouTubeApiKey,
  227. youTubeEmbedUrlOverride: defaultYouTubeEmbedUrlOverride,
  228. oauth2UserCreationAllowed: defaultOAuth2UserCreation,
  229. oauth2ClientID: defaultOAuth2ClientID,
  230. oauth2ClientSecret: defaultOAuth2ClientSecret,
  231. oauth2RedirectURL: defaultOAuth2RedirectURL,
  232. oidcDiscoveryEndpoint: defaultOAuth2OidcDiscoveryEndpoint,
  233. oidcProviderName: defaultOauth2OidcProviderName,
  234. oauth2Provider: defaultOAuth2Provider,
  235. disableLocalAuth: defaultDisableLocalAuth,
  236. httpClientTimeout: defaultHTTPClientTimeout,
  237. httpClientMaxBodySize: defaultHTTPClientMaxBodySize * 1024 * 1024,
  238. httpClientProxyURL: nil,
  239. httpClientProxies: []string{},
  240. httpClientUserAgent: defaultHTTPClientUserAgent,
  241. httpServerTimeout: defaultHTTPServerTimeout,
  242. authProxyHeader: defaultAuthProxyHeader,
  243. authProxyUserCreation: defaultAuthProxyUserCreation,
  244. maintenanceMode: defaultMaintenanceMode,
  245. maintenanceMessage: defaultMaintenanceMessage,
  246. metricsCollector: defaultMetricsCollector,
  247. metricsRefreshInterval: defaultMetricsRefreshInterval,
  248. metricsAllowedNetworks: []string{defaultMetricsAllowedNetworks},
  249. metricsUsername: defaultMetricsUsername,
  250. metricsPassword: defaultMetricsPassword,
  251. watchdog: defaultWatchdog,
  252. invidiousInstance: defaultInvidiousInstance,
  253. mediaProxyPrivateKey: crypto.GenerateRandomBytes(16),
  254. webAuthn: defaultWebAuthn,
  255. }
  256. }
  257. func (o *options) LogFile() string {
  258. return o.logFile
  259. }
  260. // LogDateTime returns true if the date/time should be displayed in log messages.
  261. func (o *options) LogDateTime() bool {
  262. return o.logDateTime
  263. }
  264. // LogFormat returns the log format.
  265. func (o *options) LogFormat() string {
  266. return o.logFormat
  267. }
  268. // LogLevel returns the log level.
  269. func (o *options) LogLevel() string {
  270. return o.logLevel
  271. }
  272. // SetLogLevel sets the log level.
  273. func (o *options) SetLogLevel(level string) {
  274. o.logLevel = level
  275. }
  276. // HasMaintenanceMode returns true if maintenance mode is enabled.
  277. func (o *options) HasMaintenanceMode() bool {
  278. return o.maintenanceMode
  279. }
  280. // MaintenanceMessage returns maintenance message.
  281. func (o *options) MaintenanceMessage() string {
  282. return o.maintenanceMessage
  283. }
  284. // BaseURL returns the application base URL with path.
  285. func (o *options) BaseURL() string {
  286. return o.baseURL
  287. }
  288. // RootURL returns the base URL without path.
  289. func (o *options) RootURL() string {
  290. return o.rootURL
  291. }
  292. // BasePath returns the application base path according to the base URL.
  293. func (o *options) BasePath() string {
  294. return o.basePath
  295. }
  296. // IsDefaultDatabaseURL returns true if the default database URL is used.
  297. func (o *options) IsDefaultDatabaseURL() bool {
  298. return o.databaseURL == defaultDatabaseURL
  299. }
  300. // DatabaseURL returns the database URL.
  301. func (o *options) DatabaseURL() string {
  302. return o.databaseURL
  303. }
  304. // DatabaseMaxConns returns the maximum number of database connections.
  305. func (o *options) DatabaseMaxConns() int {
  306. return o.databaseMaxConns
  307. }
  308. // DatabaseMinConns returns the minimum number of database connections.
  309. func (o *options) DatabaseMinConns() int {
  310. return o.databaseMinConns
  311. }
  312. // DatabaseConnectionLifetime returns the maximum amount of time a connection may be reused.
  313. func (o *options) DatabaseConnectionLifetime() time.Duration {
  314. return time.Duration(o.databaseConnectionLifetime) * time.Minute
  315. }
  316. // ListenAddr returns the listen address for the HTTP server.
  317. func (o *options) ListenAddr() []string {
  318. return o.listenAddr
  319. }
  320. // CertFile returns the SSL certificate filename if any.
  321. func (o *options) CertFile() string {
  322. return o.certFile
  323. }
  324. // CertKeyFile returns the private key filename for custom SSL certificate.
  325. func (o *options) CertKeyFile() string {
  326. return o.certKeyFile
  327. }
  328. // CertDomain returns the domain to use for Let's Encrypt certificate.
  329. func (o *options) CertDomain() string {
  330. return o.certDomain
  331. }
  332. // CleanupFrequencyHours returns the interval in hours for cleanup jobs.
  333. func (o *options) CleanupFrequencyHours() int {
  334. return o.cleanupFrequencyHours
  335. }
  336. // CleanupArchiveReadDays returns the number of days after which marking read items as removed.
  337. func (o *options) CleanupArchiveReadDays() int {
  338. return o.cleanupArchiveReadDays
  339. }
  340. // CleanupArchiveUnreadDays returns the number of days after which marking unread items as removed.
  341. func (o *options) CleanupArchiveUnreadDays() int {
  342. return o.cleanupArchiveUnreadDays
  343. }
  344. // CleanupArchiveBatchSize returns the number of entries to archive for each interval.
  345. func (o *options) CleanupArchiveBatchSize() int {
  346. return o.cleanupArchiveBatchSize
  347. }
  348. // CleanupRemoveSessionsDays returns the number of days after which to remove sessions.
  349. func (o *options) CleanupRemoveSessionsDays() int {
  350. return o.cleanupRemoveSessionsDays
  351. }
  352. // WorkerPoolSize returns the number of background worker.
  353. func (o *options) WorkerPoolSize() int {
  354. return o.workerPoolSize
  355. }
  356. // PollingFrequency returns the interval to refresh feeds in the background.
  357. func (o *options) PollingFrequency() int {
  358. return o.pollingFrequency
  359. }
  360. // ForceRefreshInterval returns the force refresh interval
  361. func (o *options) ForceRefreshInterval() int {
  362. return o.forceRefreshInterval
  363. }
  364. // BatchSize returns the number of feeds to send for background processing.
  365. func (o *options) BatchSize() int {
  366. return o.batchSize
  367. }
  368. // PollingScheduler returns the scheduler used for polling feeds.
  369. func (o *options) PollingScheduler() string {
  370. return o.pollingScheduler
  371. }
  372. // SchedulerEntryFrequencyMaxInterval returns the maximum interval in minutes for the entry frequency scheduler.
  373. func (o *options) SchedulerEntryFrequencyMaxInterval() int {
  374. return o.schedulerEntryFrequencyMaxInterval
  375. }
  376. // SchedulerEntryFrequencyMinInterval returns the minimum interval in minutes for the entry frequency scheduler.
  377. func (o *options) SchedulerEntryFrequencyMinInterval() int {
  378. return o.schedulerEntryFrequencyMinInterval
  379. }
  380. // SchedulerEntryFrequencyFactor returns the factor for the entry frequency scheduler.
  381. func (o *options) SchedulerEntryFrequencyFactor() int {
  382. return o.schedulerEntryFrequencyFactor
  383. }
  384. func (o *options) SchedulerRoundRobinMinInterval() int {
  385. return o.schedulerRoundRobinMinInterval
  386. }
  387. func (o *options) SchedulerRoundRobinMaxInterval() int {
  388. return o.schedulerRoundRobinMaxInterval
  389. }
  390. // PollingParsingErrorLimit returns the limit of errors when to stop polling.
  391. func (o *options) PollingParsingErrorLimit() int {
  392. return o.pollingParsingErrorLimit
  393. }
  394. // IsOAuth2UserCreationAllowed returns true if user creation is allowed for OAuth2 users.
  395. func (o *options) IsOAuth2UserCreationAllowed() bool {
  396. return o.oauth2UserCreationAllowed
  397. }
  398. // OAuth2ClientID returns the OAuth2 Client ID.
  399. func (o *options) OAuth2ClientID() string {
  400. return o.oauth2ClientID
  401. }
  402. // OAuth2ClientSecret returns the OAuth2 client secret.
  403. func (o *options) OAuth2ClientSecret() string {
  404. return o.oauth2ClientSecret
  405. }
  406. // OAuth2RedirectURL returns the OAuth2 redirect URL.
  407. func (o *options) OAuth2RedirectURL() string {
  408. return o.oauth2RedirectURL
  409. }
  410. // OIDCDiscoveryEndpoint returns the OAuth2 OIDC discovery endpoint.
  411. func (o *options) OIDCDiscoveryEndpoint() string {
  412. return o.oidcDiscoveryEndpoint
  413. }
  414. // OIDCProviderName returns the OAuth2 OIDC provider's display name
  415. func (o *options) OIDCProviderName() string {
  416. return o.oidcProviderName
  417. }
  418. // OAuth2Provider returns the name of the OAuth2 provider configured.
  419. func (o *options) OAuth2Provider() string {
  420. return o.oauth2Provider
  421. }
  422. // DisableLocalAUth returns true if the local user database should not be used to authenticate users
  423. func (o *options) DisableLocalAuth() bool {
  424. return o.disableLocalAuth
  425. }
  426. // HasHSTS returns true if HTTP Strict Transport Security is enabled.
  427. func (o *options) HasHSTS() bool {
  428. return o.hsts
  429. }
  430. // RunMigrations returns true if the environment variable RUN_MIGRATIONS is not empty.
  431. func (o *options) RunMigrations() bool {
  432. return o.runMigrations
  433. }
  434. // CreateAdmin returns true if the environment variable CREATE_ADMIN is not empty.
  435. func (o *options) CreateAdmin() bool {
  436. return o.createAdmin
  437. }
  438. // AdminUsername returns the admin username if defined.
  439. func (o *options) AdminUsername() string {
  440. return o.adminUsername
  441. }
  442. // AdminPassword returns the admin password if defined.
  443. func (o *options) AdminPassword() string {
  444. return o.adminPassword
  445. }
  446. // FetchYouTubeWatchTime returns true if the YouTube video duration
  447. // should be fetched and used as a reading time.
  448. func (o *options) FetchYouTubeWatchTime() bool {
  449. return o.fetchYouTubeWatchTime
  450. }
  451. // YouTubeApiKey returns the YouTube API key if defined.
  452. func (o *options) YouTubeApiKey() string {
  453. return o.youTubeApiKey
  454. }
  455. // YouTubeEmbedUrlOverride returns the YouTube embed URL override if defined.
  456. func (o *options) YouTubeEmbedUrlOverride() string {
  457. return o.youTubeEmbedUrlOverride
  458. }
  459. // YouTubeEmbedDomain returns the domain used for YouTube embeds.
  460. func (o *options) YouTubeEmbedDomain() string {
  461. if o.youTubeEmbedDomain != "" {
  462. return o.youTubeEmbedDomain
  463. }
  464. return "www.youtube-nocookie.com"
  465. }
  466. // FetchNebulaWatchTime returns true if the Nebula video duration
  467. // should be fetched and used as a reading time.
  468. func (o *options) FetchNebulaWatchTime() bool {
  469. return o.fetchNebulaWatchTime
  470. }
  471. // FetchOdyseeWatchTime returns true if the Odysee video duration
  472. // should be fetched and used as a reading time.
  473. func (o *options) FetchOdyseeWatchTime() bool {
  474. return o.fetchOdyseeWatchTime
  475. }
  476. // FetchBilibiliWatchTime returns true if the Bilibili video duration
  477. // should be fetched and used as a reading time.
  478. func (o *options) FetchBilibiliWatchTime() bool {
  479. return o.fetchBilibiliWatchTime
  480. }
  481. // MediaProxyMode returns "none" to never proxy, "http-only" to proxy non-HTTPS, "all" to always proxy.
  482. func (o *options) MediaProxyMode() string {
  483. return o.mediaProxyMode
  484. }
  485. // MediaProxyResourceTypes returns a slice of resource types to proxy.
  486. func (o *options) MediaProxyResourceTypes() []string {
  487. return o.mediaProxyResourceTypes
  488. }
  489. // MediaCustomProxyURL returns the custom proxy URL for medias.
  490. func (o *options) MediaCustomProxyURL() string {
  491. return o.mediaProxyCustomURL
  492. }
  493. // MediaProxyHTTPClientTimeout returns the time limit in seconds before the proxy HTTP client cancel the request.
  494. func (o *options) MediaProxyHTTPClientTimeout() int {
  495. return o.mediaProxyHTTPClientTimeout
  496. }
  497. // MediaProxyPrivateKey returns the private key used by the media proxy.
  498. func (o *options) MediaProxyPrivateKey() []byte {
  499. return o.mediaProxyPrivateKey
  500. }
  501. // HasHTTPService returns true if the HTTP service is enabled.
  502. func (o *options) HasHTTPService() bool {
  503. return o.httpService
  504. }
  505. // HasSchedulerService returns true if the scheduler service is enabled.
  506. func (o *options) HasSchedulerService() bool {
  507. return o.schedulerService
  508. }
  509. // HTTPClientTimeout returns the time limit in seconds before the HTTP client cancel the request.
  510. func (o *options) HTTPClientTimeout() int {
  511. return o.httpClientTimeout
  512. }
  513. // HTTPClientMaxBodySize returns the number of bytes allowed for the HTTP client to transfer.
  514. func (o *options) HTTPClientMaxBodySize() int64 {
  515. return o.httpClientMaxBodySize
  516. }
  517. // HTTPClientProxyURL returns the client HTTP proxy URL if configured.
  518. func (o *options) HTTPClientProxyURL() *url.URL {
  519. return o.httpClientProxyURL
  520. }
  521. // HasHTTPClientProxyURLConfigured returns true if the client HTTP proxy URL if configured.
  522. func (o *options) HasHTTPClientProxyURLConfigured() bool {
  523. return o.httpClientProxyURL != nil
  524. }
  525. // HTTPClientProxies returns the list of proxies.
  526. func (o *options) HTTPClientProxies() []string {
  527. return o.httpClientProxies
  528. }
  529. // HTTPClientProxiesString returns true if the list of rotating proxies are configured.
  530. func (o *options) HasHTTPClientProxiesConfigured() bool {
  531. return len(o.httpClientProxies) > 0
  532. }
  533. // HTTPServerTimeout returns the time limit in seconds before the HTTP server cancel the request.
  534. func (o *options) HTTPServerTimeout() int {
  535. return o.httpServerTimeout
  536. }
  537. // AuthProxyHeader returns an HTTP header name that contains username for
  538. // authentication using auth proxy.
  539. func (o *options) AuthProxyHeader() string {
  540. return o.authProxyHeader
  541. }
  542. // IsAuthProxyUserCreationAllowed returns true if user creation is allowed for
  543. // users authenticated using auth proxy.
  544. func (o *options) IsAuthProxyUserCreationAllowed() bool {
  545. return o.authProxyUserCreation
  546. }
  547. // HasMetricsCollector returns true if metrics collection is enabled.
  548. func (o *options) HasMetricsCollector() bool {
  549. return o.metricsCollector
  550. }
  551. // MetricsRefreshInterval returns the refresh interval in seconds.
  552. func (o *options) MetricsRefreshInterval() int {
  553. return o.metricsRefreshInterval
  554. }
  555. // MetricsAllowedNetworks returns the list of networks allowed to connect to the metrics endpoint.
  556. func (o *options) MetricsAllowedNetworks() []string {
  557. return o.metricsAllowedNetworks
  558. }
  559. func (o *options) MetricsUsername() string {
  560. return o.metricsUsername
  561. }
  562. func (o *options) MetricsPassword() string {
  563. return o.metricsPassword
  564. }
  565. // HTTPClientUserAgent returns the global User-Agent header for miniflux.
  566. func (o *options) HTTPClientUserAgent() string {
  567. return o.httpClientUserAgent
  568. }
  569. // HasWatchdog returns true if the systemd watchdog is enabled.
  570. func (o *options) HasWatchdog() bool {
  571. return o.watchdog
  572. }
  573. // InvidiousInstance returns the invidious instance used by miniflux
  574. func (o *options) InvidiousInstance() string {
  575. return o.invidiousInstance
  576. }
  577. // WebAuthn returns true if WebAuthn logins are supported
  578. func (o *options) WebAuthn() bool {
  579. return o.webAuthn
  580. }
  581. // FilterEntryMaxAgeDays returns the number of days after which entries should be retained.
  582. func (o *options) FilterEntryMaxAgeDays() int {
  583. return o.filterEntryMaxAgeDays
  584. }
  585. // SortedOptions returns options as a list of key value pairs, sorted by keys.
  586. func (o *options) SortedOptions(redactSecret bool) []*option {
  587. var clientProxyURLRedacted string
  588. if o.httpClientProxyURL != nil {
  589. if redactSecret {
  590. clientProxyURLRedacted = o.httpClientProxyURL.Redacted()
  591. } else {
  592. clientProxyURLRedacted = o.httpClientProxyURL.String()
  593. }
  594. }
  595. var clientProxyURLsRedacted string
  596. if len(o.httpClientProxies) > 0 {
  597. if redactSecret {
  598. var proxyURLs []string
  599. for range o.httpClientProxies {
  600. proxyURLs = append(proxyURLs, "<redacted>")
  601. }
  602. clientProxyURLsRedacted = strings.Join(proxyURLs, ",")
  603. } else {
  604. clientProxyURLsRedacted = strings.Join(o.httpClientProxies, ",")
  605. }
  606. }
  607. var mediaProxyPrivateKeyValue string
  608. if len(o.mediaProxyPrivateKey) > 0 {
  609. mediaProxyPrivateKeyValue = "<binary-data>"
  610. }
  611. var keyValues = map[string]interface{}{
  612. "ADMIN_PASSWORD": redactSecretValue(o.adminPassword, redactSecret),
  613. "ADMIN_USERNAME": o.adminUsername,
  614. "AUTH_PROXY_HEADER": o.authProxyHeader,
  615. "AUTH_PROXY_USER_CREATION": o.authProxyUserCreation,
  616. "BASE_PATH": o.basePath,
  617. "BASE_URL": o.baseURL,
  618. "BATCH_SIZE": o.batchSize,
  619. "CERT_DOMAIN": o.certDomain,
  620. "CERT_FILE": o.certFile,
  621. "CLEANUP_ARCHIVE_BATCH_SIZE": o.cleanupArchiveBatchSize,
  622. "CLEANUP_ARCHIVE_READ_DAYS": o.cleanupArchiveReadDays,
  623. "CLEANUP_ARCHIVE_UNREAD_DAYS": o.cleanupArchiveUnreadDays,
  624. "CLEANUP_FREQUENCY_HOURS": o.cleanupFrequencyHours,
  625. "CLEANUP_REMOVE_SESSIONS_DAYS": o.cleanupRemoveSessionsDays,
  626. "CREATE_ADMIN": o.createAdmin,
  627. "DATABASE_CONNECTION_LIFETIME": o.databaseConnectionLifetime,
  628. "DATABASE_MAX_CONNS": o.databaseMaxConns,
  629. "DATABASE_MIN_CONNS": o.databaseMinConns,
  630. "DATABASE_URL": redactSecretValue(o.databaseURL, redactSecret),
  631. "DISABLE_HSTS": !o.hsts,
  632. "DISABLE_HTTP_SERVICE": !o.httpService,
  633. "DISABLE_SCHEDULER_SERVICE": !o.schedulerService,
  634. "FILTER_ENTRY_MAX_AGE_DAYS": o.filterEntryMaxAgeDays,
  635. "FETCH_YOUTUBE_WATCH_TIME": o.fetchYouTubeWatchTime,
  636. "FETCH_NEBULA_WATCH_TIME": o.fetchNebulaWatchTime,
  637. "FETCH_ODYSEE_WATCH_TIME": o.fetchOdyseeWatchTime,
  638. "FETCH_BILIBILI_WATCH_TIME": o.fetchBilibiliWatchTime,
  639. "HTTPS": o.HTTPS,
  640. "HTTP_CLIENT_MAX_BODY_SIZE": o.httpClientMaxBodySize,
  641. "HTTP_CLIENT_PROXIES": clientProxyURLsRedacted,
  642. "HTTP_CLIENT_PROXY": clientProxyURLRedacted,
  643. "HTTP_CLIENT_TIMEOUT": o.httpClientTimeout,
  644. "HTTP_CLIENT_USER_AGENT": o.httpClientUserAgent,
  645. "HTTP_SERVER_TIMEOUT": o.httpServerTimeout,
  646. "HTTP_SERVICE": o.httpService,
  647. "INVIDIOUS_INSTANCE": o.invidiousInstance,
  648. "KEY_FILE": o.certKeyFile,
  649. "LISTEN_ADDR": strings.Join(o.listenAddr, ","),
  650. "LOG_FILE": o.logFile,
  651. "LOG_DATE_TIME": o.logDateTime,
  652. "LOG_FORMAT": o.logFormat,
  653. "LOG_LEVEL": o.logLevel,
  654. "MAINTENANCE_MESSAGE": o.maintenanceMessage,
  655. "MAINTENANCE_MODE": o.maintenanceMode,
  656. "METRICS_ALLOWED_NETWORKS": strings.Join(o.metricsAllowedNetworks, ","),
  657. "METRICS_COLLECTOR": o.metricsCollector,
  658. "METRICS_PASSWORD": redactSecretValue(o.metricsPassword, redactSecret),
  659. "METRICS_REFRESH_INTERVAL": o.metricsRefreshInterval,
  660. "METRICS_USERNAME": o.metricsUsername,
  661. "OAUTH2_CLIENT_ID": o.oauth2ClientID,
  662. "OAUTH2_CLIENT_SECRET": redactSecretValue(o.oauth2ClientSecret, redactSecret),
  663. "OAUTH2_OIDC_DISCOVERY_ENDPOINT": o.oidcDiscoveryEndpoint,
  664. "OAUTH2_OIDC_PROVIDER_NAME": o.oidcProviderName,
  665. "OAUTH2_PROVIDER": o.oauth2Provider,
  666. "OAUTH2_REDIRECT_URL": o.oauth2RedirectURL,
  667. "OAUTH2_USER_CREATION": o.oauth2UserCreationAllowed,
  668. "DISABLE_LOCAL_AUTH": o.disableLocalAuth,
  669. "POLLING_FREQUENCY": o.pollingFrequency,
  670. "FORCE_REFRESH_INTERVAL": o.forceRefreshInterval,
  671. "POLLING_PARSING_ERROR_LIMIT": o.pollingParsingErrorLimit,
  672. "POLLING_SCHEDULER": o.pollingScheduler,
  673. "MEDIA_PROXY_HTTP_CLIENT_TIMEOUT": o.mediaProxyHTTPClientTimeout,
  674. "MEDIA_PROXY_RESOURCE_TYPES": o.mediaProxyResourceTypes,
  675. "MEDIA_PROXY_MODE": o.mediaProxyMode,
  676. "MEDIA_PROXY_PRIVATE_KEY": mediaProxyPrivateKeyValue,
  677. "MEDIA_PROXY_CUSTOM_URL": o.mediaProxyCustomURL,
  678. "ROOT_URL": o.rootURL,
  679. "RUN_MIGRATIONS": o.runMigrations,
  680. "SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL": o.schedulerEntryFrequencyMaxInterval,
  681. "SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL": o.schedulerEntryFrequencyMinInterval,
  682. "SCHEDULER_ENTRY_FREQUENCY_FACTOR": o.schedulerEntryFrequencyFactor,
  683. "SCHEDULER_ROUND_ROBIN_MIN_INTERVAL": o.schedulerRoundRobinMinInterval,
  684. "SCHEDULER_ROUND_ROBIN_MAX_INTERVAL": o.schedulerRoundRobinMaxInterval,
  685. "SCHEDULER_SERVICE": o.schedulerService,
  686. "WATCHDOG": o.watchdog,
  687. "WORKER_POOL_SIZE": o.workerPoolSize,
  688. "YOUTUBE_API_KEY": redactSecretValue(o.youTubeApiKey, redactSecret),
  689. "YOUTUBE_EMBED_URL_OVERRIDE": o.youTubeEmbedUrlOverride,
  690. "WEBAUTHN": o.webAuthn,
  691. }
  692. sortedKeys := slices.Sorted(maps.Keys(keyValues))
  693. var sortedOptions = make([]*option, 0, len(sortedKeys))
  694. for _, key := range sortedKeys {
  695. sortedOptions = append(sortedOptions, &option{Key: key, Value: keyValues[key]})
  696. }
  697. return sortedOptions
  698. }
  699. func (o *options) String() string {
  700. var builder strings.Builder
  701. for _, option := range o.SortedOptions(false) {
  702. fmt.Fprintf(&builder, "%s=%v\n", option.Key, option.Value)
  703. }
  704. return builder.String()
  705. }
  706. func redactSecretValue(value string, redactSecret bool) string {
  707. if redactSecret && value != "" {
  708. return "<secret>"
  709. }
  710. return value
  711. }