web.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (C) 2019-2023 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package httpd
  15. import (
  16. "strings"
  17. )
  18. const (
  19. pageMFATitle = "Two-factor authentication"
  20. page400Title = "Bad request"
  21. page403Title = "Forbidden"
  22. page404Title = "Not found"
  23. page404Body = "The page you are looking for does not exist."
  24. page500Title = "Internal Server Error"
  25. page500Body = "The server is unable to fulfill your request."
  26. webDateTimeFormat = "2006-01-02 15:04:05" // YYYY-MM-DD HH:MM:SS
  27. redactedSecret = "[**redacted**]"
  28. csrfFormToken = "_form_token"
  29. csrfHeaderToken = "X-CSRF-TOKEN"
  30. templateCommonDir = "common"
  31. templateTwoFactor = "twofactor.html"
  32. templateTwoFactorRecovery = "twofactor-recovery.html"
  33. templateForgotPassword = "forgot-password.html"
  34. templateResetPassword = "reset-password.html"
  35. templateCommonCSS = "sftpgo.css"
  36. templateCommonBase = "base.html"
  37. )
  38. type loginPage struct {
  39. CurrentURL string
  40. Version string
  41. Error string
  42. CSRFToken string
  43. StaticURL string
  44. AltLoginURL string
  45. AltLoginName string
  46. ForgotPwdURL string
  47. OpenIDLoginURL string
  48. Branding UIBranding
  49. FormDisabled bool
  50. }
  51. type twoFactorPage struct {
  52. CurrentURL string
  53. Version string
  54. Error string
  55. CSRFToken string
  56. StaticURL string
  57. RecoveryURL string
  58. Branding UIBranding
  59. }
  60. type forgotPwdPage struct {
  61. CurrentURL string
  62. Error string
  63. CSRFToken string
  64. StaticURL string
  65. LoginURL string
  66. Title string
  67. Branding UIBranding
  68. }
  69. type resetPwdPage struct {
  70. CurrentURL string
  71. Error string
  72. CSRFToken string
  73. StaticURL string
  74. LoginURL string
  75. Title string
  76. Branding UIBranding
  77. }
  78. func getSliceFromDelimitedValues(values, delimiter string) []string {
  79. result := []string{}
  80. for _, v := range strings.Split(values, delimiter) {
  81. cleaned := strings.TrimSpace(v)
  82. if cleaned != "" {
  83. result = append(result, cleaned)
  84. }
  85. }
  86. return result
  87. }