error.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package auth
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/gravitl/netmaker/servercfg"
  6. )
  7. var htmlBaseTemplate = `<!DOCTYPE html>
  8. <html lang="en">
  9. <head>
  10. <meta charset="UTF-8">
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
  12. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  13. <title>Netmaker :: SSO</title>
  14. <script type="text/javascript">
  15. function redirect()
  16. {
  17. window.location.href="` + fmt.Sprintf("https://dashboard.%s/login", servercfg.GetNmBaseDomain()) + `";
  18. }
  19. </script>
  20. <style>
  21. html,
  22. body {
  23. margin: 0px;
  24. padding: 0px;
  25. }
  26. body {
  27. height: 100vh;
  28. overflow: hidden;
  29. display: flex;
  30. flex-flow: column nowrap;
  31. justify-content: center;
  32. align-items: center;
  33. }
  34. #logo {
  35. width: 150px;
  36. }
  37. h3 {
  38. margin-bottom: 3rem;
  39. color: rgb(25, 135, 84);
  40. font-size: xx-large;
  41. }
  42. h4 {
  43. margin-bottom: 0px;
  44. }
  45. p {
  46. margin-top: 0px;
  47. margin-bottom: 0px;
  48. }
  49. .back-to-login-btn {
  50. background: #5E5DF0;
  51. border-radius: 999px;
  52. box-shadow: #5E5DF0 0 10px 20px -10px;
  53. box-sizing: border-box;
  54. color: #FFFFFF;
  55. cursor: pointer;
  56. font-family: Inter,Helvetica,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Noto Color Emoji","Segoe UI Symbol","Android Emoji",EmojiSymbols,-apple-system,system-ui,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans",sans-serif;
  57. font-size: 16px;
  58. font-weight: 700;
  59. line-height: 24px;
  60. opacity: 1;
  61. outline: 0 solid transparent;
  62. padding: 8px 18px;
  63. user-select: none;
  64. -webkit-user-select: none;
  65. touch-action: manipulation;
  66. width: fit-content;
  67. word-break: break-word;
  68. border: 0;
  69. margin: 20px;
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <img
  75. src="https://raw.githubusercontent.com/gravitl/netmaker-docs/master/images/netmaker-github/netmaker-teal.png"
  76. alt="netmaker logo"
  77. id="logo"
  78. >
  79. %s
  80. <button class="back-to-login-btn" onClick="redirect()" role="button">Back To Login</button>
  81. </body>
  82. </html>`
  83. var oauthNotConfigured = fmt.Sprintf(htmlBaseTemplate, `<h2>Your Netmaker server does not have OAuth configured.</h2>
  84. <p>Please visit the docs <a href="https://docs.netmaker.io/docs/server-installation/integrating-oauth" target="_blank" rel="noopener">here</a> to learn how to.</p>`)
  85. var oauthStateInvalid = fmt.Sprintf(htmlBaseTemplate, `<h2>Invalid OAuth Session. Please re-try again.</h2>`)
  86. var userNotAllowed = fmt.Sprintf(htmlBaseTemplate, `<h2>Your account does not have access to the dashboard. Please contact your administrator for more information about your account.</h2>
  87. <p>Non-Admins can access the netmaker networks using <a href="https://docs.netmaker.io/docs/remote-access-client-rac#downloadinstallation" target="_blank" rel="noopener">our Remote Access Client.</a></p>`)
  88. var userFirstTimeSignUp = fmt.Sprintf(htmlBaseTemplate, `<h2>Thank you for signing up. Please contact your administrator for access.</h2>`)
  89. var userSignUpApprovalPending = fmt.Sprintf(htmlBaseTemplate, `<h2>Your account is yet to be approved. Please contact your administrator for access.</h2>`)
  90. var userNotFound = fmt.Sprintf(htmlBaseTemplate, `<h2>User Not Found.</h2>`)
  91. var somethingwentwrong = fmt.Sprintf(htmlBaseTemplate, `<h2>Something went wrong. Contact Admin.</h2>`)
  92. var notallowedtosignup = fmt.Sprintf(htmlBaseTemplate, `<h2>Your email is not allowed. Please contact your administrator.</h2>`)
  93. func handleOauthUserNotFound(response http.ResponseWriter) {
  94. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  95. response.WriteHeader(http.StatusNotFound)
  96. response.Write([]byte(userNotFound))
  97. }
  98. func handleOauthUserNotAllowed(response http.ResponseWriter) {
  99. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  100. response.WriteHeader(http.StatusForbidden)
  101. response.Write([]byte(userNotAllowed))
  102. }
  103. func handleFirstTimeOauthUserSignUp(response http.ResponseWriter) {
  104. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  105. response.WriteHeader(http.StatusForbidden)
  106. response.Write([]byte(userFirstTimeSignUp))
  107. }
  108. func handleOauthUserSignUpApprovalPending(response http.ResponseWriter) {
  109. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  110. response.WriteHeader(http.StatusForbidden)
  111. response.Write([]byte(userSignUpApprovalPending))
  112. }
  113. func handleOauthUserNotAllowedToSignUp(response http.ResponseWriter) {
  114. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  115. response.WriteHeader(http.StatusForbidden)
  116. response.Write([]byte(notallowedtosignup))
  117. }
  118. // handleOauthNotConfigured - returns an appropriate html page when oauth is not configured on netmaker server but an oauth login was attempted
  119. func handleOauthNotConfigured(response http.ResponseWriter) {
  120. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  121. response.WriteHeader(http.StatusInternalServerError)
  122. response.Write([]byte(oauthNotConfigured))
  123. }
  124. func handleOauthNotValid(response http.ResponseWriter) {
  125. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  126. response.WriteHeader(http.StatusBadRequest)
  127. response.Write([]byte(oauthStateInvalid))
  128. }
  129. func handleSomethingWentWrong(response http.ResponseWriter) {
  130. response.Header().Set("Content-Type", "text/html; charset=utf-8")
  131. response.WriteHeader(http.StatusInternalServerError)
  132. response.Write([]byte(somethingwentwrong))
  133. }