integration.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package form // import "miniflux.app/v2/internal/ui/form"
  4. import (
  5. "net/http"
  6. "strconv"
  7. "miniflux.app/v2/internal/locale"
  8. "miniflux.app/v2/internal/model"
  9. )
  10. // IntegrationForm represents user integration settings form.
  11. type IntegrationForm struct {
  12. PinboardEnabled bool
  13. PinboardToken string
  14. PinboardTags string
  15. PinboardMarkAsUnread bool
  16. InstapaperEnabled bool
  17. InstapaperUsername string
  18. InstapaperPassword string
  19. FeverEnabled bool
  20. FeverUsername string
  21. FeverPassword string
  22. GoogleReaderEnabled bool
  23. GoogleReaderUsername string
  24. GoogleReaderPassword string
  25. WallabagEnabled bool
  26. WallabagOnlyURL bool
  27. WallabagURL string
  28. WallabagClientID string
  29. WallabagClientSecret string
  30. WallabagUsername string
  31. WallabagPassword string
  32. WallabagTags string
  33. NotionEnabled bool
  34. NotionPageID string
  35. NotionToken string
  36. NunuxKeeperEnabled bool
  37. NunuxKeeperURL string
  38. NunuxKeeperAPIKey string
  39. EspialEnabled bool
  40. EspialURL string
  41. EspialAPIKey string
  42. EspialTags string
  43. ReadwiseEnabled bool
  44. ReadwiseAPIKey string
  45. TelegramBotEnabled bool
  46. TelegramBotToken string
  47. TelegramBotChatID string
  48. TelegramBotTopicID *int64
  49. TelegramBotDisableWebPagePreview bool
  50. TelegramBotDisableNotification bool
  51. TelegramBotDisableButtons bool
  52. LinkAceEnabled bool
  53. LinkAceURL string
  54. LinkAceAPIKey string
  55. LinkAceTags string
  56. LinkAcePrivate bool
  57. LinkAceCheckDisabled bool
  58. LinkdingEnabled bool
  59. LinkdingURL string
  60. LinkdingAPIKey string
  61. LinkdingTags string
  62. LinkdingMarkAsUnread bool
  63. LinktacoEnabled bool
  64. LinktacoAPIToken string
  65. LinktacoOrgSlug string
  66. LinktacoTags string
  67. LinktacoVisibility string
  68. LinkwardenEnabled bool
  69. LinkwardenURL string
  70. LinkwardenAPIKey string
  71. LinkwardenCollectionID *int64
  72. MatrixBotEnabled bool
  73. MatrixBotUser string
  74. MatrixBotPassword string
  75. MatrixBotURL string
  76. MatrixBotChatID string
  77. AppriseEnabled bool
  78. AppriseURL string
  79. AppriseServicesURL string
  80. ReadeckEnabled bool
  81. ReadeckPushEnabled bool
  82. ReadeckURL string
  83. ReadeckAPIKey string
  84. ReadeckLabels string
  85. ReadeckOnlyURL bool
  86. ShioriEnabled bool
  87. ShioriURL string
  88. ShioriUsername string
  89. ShioriPassword string
  90. ShaarliEnabled bool
  91. ShaarliURL string
  92. ShaarliAPISecret string
  93. WebhookEnabled bool
  94. WebhookURL string
  95. WebhookSecret string
  96. RSSBridgeEnabled bool
  97. RSSBridgeURL string
  98. RSSBridgeToken string
  99. OmnivoreEnabled bool
  100. OmnivoreAPIKey string
  101. OmnivoreURL string
  102. KarakeepEnabled bool
  103. KarakeepAPIKey string
  104. KarakeepURL string
  105. KarakeepTags string
  106. RaindropEnabled bool
  107. RaindropToken string
  108. RaindropCollectionID string
  109. RaindropTags string
  110. BetulaEnabled bool
  111. BetulaURL string
  112. BetulaToken string
  113. NtfyEnabled bool
  114. NtfyTopic string
  115. NtfyURL string
  116. NtfyAPIToken string
  117. NtfyUsername string
  118. NtfyPassword string
  119. NtfyIconURL string
  120. NtfyInternalLinks bool
  121. CuboxEnabled bool
  122. CuboxAPILink string
  123. DiscordEnabled bool
  124. DiscordWebhookLink string
  125. SlackEnabled bool
  126. SlackWebhookLink string
  127. PushoverEnabled bool
  128. PushoverUser string
  129. PushoverToken string
  130. PushoverDevice string
  131. PushoverPrefix string
  132. ArchiveorgEnabled bool
  133. GotifyEnabled bool
  134. GotifyURL string
  135. GotifyToken string
  136. GotifyPriority int
  137. }
  138. // Merge copy form values to the model.
  139. func (i IntegrationForm) Merge(integration *model.Integration) {
  140. integration.PinboardEnabled = i.PinboardEnabled
  141. integration.PinboardToken = i.PinboardToken
  142. integration.PinboardTags = i.PinboardTags
  143. integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
  144. integration.InstapaperEnabled = i.InstapaperEnabled
  145. integration.InstapaperUsername = i.InstapaperUsername
  146. integration.InstapaperPassword = i.InstapaperPassword
  147. integration.FeverEnabled = i.FeverEnabled
  148. integration.FeverUsername = i.FeverUsername
  149. integration.GoogleReaderEnabled = i.GoogleReaderEnabled
  150. integration.GoogleReaderUsername = i.GoogleReaderUsername
  151. integration.WallabagEnabled = i.WallabagEnabled
  152. integration.WallabagOnlyURL = i.WallabagOnlyURL
  153. integration.WallabagURL = i.WallabagURL
  154. integration.WallabagClientID = i.WallabagClientID
  155. integration.WallabagClientSecret = i.WallabagClientSecret
  156. integration.WallabagUsername = i.WallabagUsername
  157. integration.WallabagPassword = i.WallabagPassword
  158. integration.WallabagTags = i.WallabagTags
  159. integration.NotionEnabled = i.NotionEnabled
  160. integration.NotionPageID = i.NotionPageID
  161. integration.NotionToken = i.NotionToken
  162. integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled
  163. integration.NunuxKeeperURL = i.NunuxKeeperURL
  164. integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey
  165. integration.EspialEnabled = i.EspialEnabled
  166. integration.EspialURL = i.EspialURL
  167. integration.EspialAPIKey = i.EspialAPIKey
  168. integration.EspialTags = i.EspialTags
  169. integration.ReadwiseEnabled = i.ReadwiseEnabled
  170. integration.ReadwiseAPIKey = i.ReadwiseAPIKey
  171. integration.TelegramBotEnabled = i.TelegramBotEnabled
  172. integration.TelegramBotToken = i.TelegramBotToken
  173. integration.TelegramBotChatID = i.TelegramBotChatID
  174. integration.TelegramBotTopicID = i.TelegramBotTopicID
  175. integration.TelegramBotDisableWebPagePreview = i.TelegramBotDisableWebPagePreview
  176. integration.TelegramBotDisableNotification = i.TelegramBotDisableNotification
  177. integration.TelegramBotDisableButtons = i.TelegramBotDisableButtons
  178. integration.LinkAceEnabled = i.LinkAceEnabled
  179. integration.LinkAceURL = i.LinkAceURL
  180. integration.LinkAceAPIKey = i.LinkAceAPIKey
  181. integration.LinkAceTags = i.LinkAceTags
  182. integration.LinkAcePrivate = i.LinkAcePrivate
  183. integration.LinkAceCheckDisabled = i.LinkAceCheckDisabled
  184. integration.LinkdingEnabled = i.LinkdingEnabled
  185. integration.LinkdingURL = i.LinkdingURL
  186. integration.LinkdingAPIKey = i.LinkdingAPIKey
  187. integration.LinkdingTags = i.LinkdingTags
  188. integration.LinkdingMarkAsUnread = i.LinkdingMarkAsUnread
  189. integration.LinktacoEnabled = i.LinktacoEnabled
  190. integration.LinktacoAPIToken = i.LinktacoAPIToken
  191. integration.LinktacoOrgSlug = i.LinktacoOrgSlug
  192. integration.LinktacoTags = i.LinktacoTags
  193. integration.LinktacoVisibility = i.LinktacoVisibility
  194. integration.LinkwardenEnabled = i.LinkwardenEnabled
  195. integration.LinkwardenURL = i.LinkwardenURL
  196. integration.LinkwardenAPIKey = i.LinkwardenAPIKey
  197. integration.LinkwardenCollectionID = i.LinkwardenCollectionID
  198. integration.MatrixBotEnabled = i.MatrixBotEnabled
  199. integration.MatrixBotUser = i.MatrixBotUser
  200. integration.MatrixBotPassword = i.MatrixBotPassword
  201. integration.MatrixBotURL = i.MatrixBotURL
  202. integration.MatrixBotChatID = i.MatrixBotChatID
  203. integration.AppriseEnabled = i.AppriseEnabled
  204. integration.AppriseServicesURL = i.AppriseServicesURL
  205. integration.AppriseURL = i.AppriseURL
  206. integration.ReadeckEnabled = i.ReadeckEnabled
  207. integration.ReadeckPushEnabled = i.ReadeckPushEnabled
  208. integration.ReadeckURL = i.ReadeckURL
  209. integration.ReadeckAPIKey = i.ReadeckAPIKey
  210. integration.ReadeckLabels = i.ReadeckLabels
  211. integration.ReadeckOnlyURL = i.ReadeckOnlyURL
  212. integration.ShioriEnabled = i.ShioriEnabled
  213. integration.ShioriURL = i.ShioriURL
  214. integration.ShioriUsername = i.ShioriUsername
  215. integration.ShioriPassword = i.ShioriPassword
  216. integration.ShaarliEnabled = i.ShaarliEnabled
  217. integration.ShaarliURL = i.ShaarliURL
  218. integration.ShaarliAPISecret = i.ShaarliAPISecret
  219. integration.WebhookEnabled = i.WebhookEnabled
  220. integration.WebhookURL = i.WebhookURL
  221. integration.RSSBridgeEnabled = i.RSSBridgeEnabled
  222. integration.RSSBridgeURL = i.RSSBridgeURL
  223. integration.RSSBridgeToken = i.RSSBridgeToken
  224. integration.OmnivoreEnabled = i.OmnivoreEnabled
  225. integration.OmnivoreAPIKey = i.OmnivoreAPIKey
  226. integration.OmnivoreURL = i.OmnivoreURL
  227. integration.KarakeepEnabled = i.KarakeepEnabled
  228. integration.KarakeepAPIKey = i.KarakeepAPIKey
  229. integration.KarakeepURL = i.KarakeepURL
  230. integration.KarakeepTags = i.KarakeepTags
  231. integration.RaindropEnabled = i.RaindropEnabled
  232. integration.RaindropToken = i.RaindropToken
  233. integration.RaindropCollectionID = i.RaindropCollectionID
  234. integration.RaindropTags = i.RaindropTags
  235. integration.BetulaEnabled = i.BetulaEnabled
  236. integration.BetulaURL = i.BetulaURL
  237. integration.BetulaToken = i.BetulaToken
  238. integration.NtfyEnabled = i.NtfyEnabled
  239. integration.NtfyTopic = i.NtfyTopic
  240. integration.NtfyURL = i.NtfyURL
  241. integration.NtfyAPIToken = i.NtfyAPIToken
  242. integration.NtfyUsername = i.NtfyUsername
  243. integration.NtfyPassword = i.NtfyPassword
  244. integration.NtfyIconURL = i.NtfyIconURL
  245. integration.NtfyInternalLinks = i.NtfyInternalLinks
  246. integration.CuboxEnabled = i.CuboxEnabled
  247. integration.CuboxAPILink = i.CuboxAPILink
  248. integration.DiscordEnabled = i.DiscordEnabled
  249. integration.DiscordWebhookLink = i.DiscordWebhookLink
  250. integration.SlackEnabled = i.SlackEnabled
  251. integration.SlackWebhookLink = i.SlackWebhookLink
  252. integration.PushoverEnabled = i.PushoverEnabled
  253. integration.PushoverUser = i.PushoverUser
  254. integration.PushoverToken = i.PushoverToken
  255. integration.PushoverDevice = i.PushoverDevice
  256. integration.PushoverPrefix = i.PushoverPrefix
  257. integration.ArchiveorgEnabled = i.ArchiveorgEnabled
  258. integration.GotifyEnabled = i.GotifyEnabled
  259. integration.GotifyURL = i.GotifyURL
  260. integration.GotifyToken = i.GotifyToken
  261. integration.GotifyPriority = i.GotifyPriority
  262. }
  263. // ValidateGoogleReader ensures the Google Reader integration is not enabled without credentials.
  264. func (i IntegrationForm) ValidateGoogleReader(storedPasswordHash string) *locale.LocalizedError {
  265. if !i.GoogleReaderEnabled {
  266. return nil
  267. }
  268. if i.GoogleReaderUsername == "" || (i.GoogleReaderPassword == "" && storedPasswordHash == "") {
  269. return locale.NewLocalizedError("error.googlereader_missing_required_fields")
  270. }
  271. return nil
  272. }
  273. // NewIntegrationForm returns a new IntegrationForm.
  274. func NewIntegrationForm(r *http.Request) *IntegrationForm {
  275. gotifyPriority, _ := strconv.Atoi(r.FormValue("gotify_priority"))
  276. return &IntegrationForm{
  277. PinboardEnabled: r.FormValue("pinboard_enabled") == "1",
  278. PinboardToken: r.FormValue("pinboard_token"),
  279. PinboardTags: r.FormValue("pinboard_tags"),
  280. PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
  281. InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
  282. InstapaperUsername: r.FormValue("instapaper_username"),
  283. InstapaperPassword: r.FormValue("instapaper_password"),
  284. FeverEnabled: r.FormValue("fever_enabled") == "1",
  285. FeverUsername: r.FormValue("fever_username"),
  286. FeverPassword: r.FormValue("fever_password"),
  287. GoogleReaderEnabled: r.FormValue("googlereader_enabled") == "1",
  288. GoogleReaderUsername: r.FormValue("googlereader_username"),
  289. GoogleReaderPassword: r.FormValue("googlereader_password"),
  290. WallabagEnabled: r.FormValue("wallabag_enabled") == "1",
  291. WallabagOnlyURL: r.FormValue("wallabag_only_url") == "1",
  292. WallabagURL: r.FormValue("wallabag_url"),
  293. WallabagClientID: r.FormValue("wallabag_client_id"),
  294. WallabagClientSecret: r.FormValue("wallabag_client_secret"),
  295. WallabagUsername: r.FormValue("wallabag_username"),
  296. WallabagPassword: r.FormValue("wallabag_password"),
  297. WallabagTags: r.FormValue("wallabag_tags"),
  298. NotionEnabled: r.FormValue("notion_enabled") == "1",
  299. NotionPageID: r.FormValue("notion_page_id"),
  300. NotionToken: r.FormValue("notion_token"),
  301. NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1",
  302. NunuxKeeperURL: r.FormValue("nunux_keeper_url"),
  303. NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"),
  304. EspialEnabled: r.FormValue("espial_enabled") == "1",
  305. EspialURL: r.FormValue("espial_url"),
  306. EspialAPIKey: r.FormValue("espial_api_key"),
  307. EspialTags: r.FormValue("espial_tags"),
  308. ReadwiseEnabled: r.FormValue("readwise_enabled") == "1",
  309. ReadwiseAPIKey: r.FormValue("readwise_api_key"),
  310. TelegramBotEnabled: r.FormValue("telegram_bot_enabled") == "1",
  311. TelegramBotToken: r.FormValue("telegram_bot_token"),
  312. TelegramBotChatID: r.FormValue("telegram_bot_chat_id"),
  313. TelegramBotTopicID: optionalInt64Field(r.FormValue("telegram_bot_topic_id")),
  314. TelegramBotDisableWebPagePreview: r.FormValue("telegram_bot_disable_web_page_preview") == "1",
  315. TelegramBotDisableNotification: r.FormValue("telegram_bot_disable_notification") == "1",
  316. TelegramBotDisableButtons: r.FormValue("telegram_bot_disable_buttons") == "1",
  317. LinkAceEnabled: r.FormValue("linkace_enabled") == "1",
  318. LinkAceURL: r.FormValue("linkace_url"),
  319. LinkAceAPIKey: r.FormValue("linkace_api_key"),
  320. LinkAceTags: r.FormValue("linkace_tags"),
  321. LinkAcePrivate: r.FormValue("linkace_is_private") == "1",
  322. LinkAceCheckDisabled: r.FormValue("linkace_check_disabled") == "1",
  323. LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
  324. LinkdingURL: r.FormValue("linkding_url"),
  325. LinkdingAPIKey: r.FormValue("linkding_api_key"),
  326. LinkdingTags: r.FormValue("linkding_tags"),
  327. LinkdingMarkAsUnread: r.FormValue("linkding_mark_as_unread") == "1",
  328. LinktacoEnabled: r.FormValue("linktaco_enabled") == "1",
  329. LinktacoAPIToken: r.FormValue("linktaco_api_token"),
  330. LinktacoOrgSlug: r.FormValue("linktaco_org_slug"),
  331. LinktacoTags: r.FormValue("linktaco_tags"),
  332. LinktacoVisibility: r.FormValue("linktaco_visibility"),
  333. LinkwardenEnabled: r.FormValue("linkwarden_enabled") == "1",
  334. LinkwardenURL: r.FormValue("linkwarden_url"),
  335. LinkwardenAPIKey: r.FormValue("linkwarden_api_key"),
  336. LinkwardenCollectionID: optionalInt64Field(r.FormValue("linkwarden_collection_id")),
  337. MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
  338. MatrixBotUser: r.FormValue("matrix_bot_user"),
  339. MatrixBotPassword: r.FormValue("matrix_bot_password"),
  340. MatrixBotURL: r.FormValue("matrix_bot_url"),
  341. MatrixBotChatID: r.FormValue("matrix_bot_chat_id"),
  342. AppriseEnabled: r.FormValue("apprise_enabled") == "1",
  343. AppriseURL: r.FormValue("apprise_url"),
  344. AppriseServicesURL: r.FormValue("apprise_services_url"),
  345. ReadeckEnabled: r.FormValue("readeck_enabled") == "1",
  346. ReadeckPushEnabled: r.FormValue("readeck_push_enabled") == "1",
  347. ReadeckURL: r.FormValue("readeck_url"),
  348. ReadeckAPIKey: r.FormValue("readeck_api_key"),
  349. ReadeckLabels: r.FormValue("readeck_labels"),
  350. ReadeckOnlyURL: r.FormValue("readeck_only_url") == "1",
  351. ShioriEnabled: r.FormValue("shiori_enabled") == "1",
  352. ShioriURL: r.FormValue("shiori_url"),
  353. ShioriUsername: r.FormValue("shiori_username"),
  354. ShioriPassword: r.FormValue("shiori_password"),
  355. ShaarliEnabled: r.FormValue("shaarli_enabled") == "1",
  356. ShaarliURL: r.FormValue("shaarli_url"),
  357. ShaarliAPISecret: r.FormValue("shaarli_api_secret"),
  358. WebhookEnabled: r.FormValue("webhook_enabled") == "1",
  359. WebhookURL: r.FormValue("webhook_url"),
  360. RSSBridgeEnabled: r.FormValue("rssbridge_enabled") == "1",
  361. RSSBridgeURL: r.FormValue("rssbridge_url"),
  362. RSSBridgeToken: r.FormValue("rssbridge_token"),
  363. OmnivoreEnabled: r.FormValue("omnivore_enabled") == "1",
  364. OmnivoreAPIKey: r.FormValue("omnivore_api_key"),
  365. OmnivoreURL: r.FormValue("omnivore_url"),
  366. KarakeepEnabled: r.FormValue("karakeep_enabled") == "1",
  367. KarakeepAPIKey: r.FormValue("karakeep_api_key"),
  368. KarakeepURL: r.FormValue("karakeep_url"),
  369. KarakeepTags: r.FormValue("karakeep_tags"),
  370. RaindropEnabled: r.FormValue("raindrop_enabled") == "1",
  371. RaindropToken: r.FormValue("raindrop_token"),
  372. RaindropCollectionID: r.FormValue("raindrop_collection_id"),
  373. RaindropTags: r.FormValue("raindrop_tags"),
  374. BetulaEnabled: r.FormValue("betula_enabled") == "1",
  375. BetulaURL: r.FormValue("betula_url"),
  376. BetulaToken: r.FormValue("betula_token"),
  377. NtfyEnabled: r.FormValue("ntfy_enabled") == "1",
  378. NtfyTopic: r.FormValue("ntfy_topic"),
  379. NtfyURL: r.FormValue("ntfy_url"),
  380. NtfyAPIToken: r.FormValue("ntfy_api_token"),
  381. NtfyUsername: r.FormValue("ntfy_username"),
  382. NtfyPassword: r.FormValue("ntfy_password"),
  383. NtfyIconURL: r.FormValue("ntfy_icon_url"),
  384. NtfyInternalLinks: r.FormValue("ntfy_internal_links") == "1",
  385. CuboxEnabled: r.FormValue("cubox_enabled") == "1",
  386. CuboxAPILink: r.FormValue("cubox_api_link"),
  387. DiscordEnabled: r.FormValue("discord_enabled") == "1",
  388. DiscordWebhookLink: r.FormValue("discord_webhook_link"),
  389. SlackEnabled: r.FormValue("slack_enabled") == "1",
  390. SlackWebhookLink: r.FormValue("slack_webhook_link"),
  391. PushoverEnabled: r.FormValue("pushover_enabled") == "1",
  392. PushoverUser: r.FormValue("pushover_user"),
  393. PushoverToken: r.FormValue("pushover_token"),
  394. PushoverDevice: r.FormValue("pushover_device"),
  395. PushoverPrefix: r.FormValue("pushover_prefix"),
  396. ArchiveorgEnabled: r.FormValue("archiveorg_enabled") == "1",
  397. GotifyEnabled: r.FormValue("gotify_enabled") == "1",
  398. GotifyURL: r.FormValue("gotify_url"),
  399. GotifyToken: r.FormValue("gotify_token"),
  400. GotifyPriority: gotifyPriority,
  401. }
  402. }
  403. func optionalInt64Field(formValue string) *int64 {
  404. if formValue == "" {
  405. return nil
  406. }
  407. value, _ := strconv.ParseInt(formValue, 10, 64)
  408. return &value
  409. }