options.go 31 KB

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