2024-01-01 10:31:45 +00:00
|
|
|
// Copyright (C) 2019 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
2023-01-03 09:18:30 +00:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
package httpd
|
|
|
|
|
|
|
|
import (
|
2021-05-11 04:54:06 +00:00
|
|
|
"context"
|
2021-01-17 21:29:08 +00:00
|
|
|
"crypto/tls"
|
2021-01-19 17:59:41 +00:00
|
|
|
"crypto/x509"
|
|
|
|
"errors"
|
2021-01-17 21:29:08 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2021-05-11 04:54:06 +00:00
|
|
|
"net"
|
2021-01-17 21:29:08 +00:00
|
|
|
"net/http"
|
2023-06-08 16:14:47 +00:00
|
|
|
"net/url"
|
2022-06-09 06:37:37 +00:00
|
|
|
"path/filepath"
|
2021-11-21 08:32:51 +00:00
|
|
|
"strings"
|
2021-01-17 21:29:08 +00:00
|
|
|
"time"
|
|
|
|
|
2021-03-01 18:28:11 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
2021-03-05 17:50:45 +00:00
|
|
|
"github.com/go-chi/jwtauth/v5"
|
2021-01-17 21:29:08 +00:00
|
|
|
"github.com/go-chi/render"
|
2022-11-16 18:04:50 +00:00
|
|
|
"github.com/lestrrat-go/jwx/v2/jwa"
|
2021-11-13 22:14:50 +00:00
|
|
|
"github.com/rs/cors"
|
2021-05-06 19:35:43 +00:00
|
|
|
"github.com/rs/xid"
|
2022-01-06 10:54:43 +00:00
|
|
|
"github.com/sftpgo/sdk"
|
2022-02-17 17:22:27 +00:00
|
|
|
"github.com/unrolled/secure"
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2023-02-24 19:08:14 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/internal/acme"
|
2022-07-24 14:18:54 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/internal/common"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/dataprovider"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/logger"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/mfa"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/smtp"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/util"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/version"
|
2021-01-17 21:29:08 +00:00
|
|
|
)
|
|
|
|
|
2024-01-14 20:36:23 +00:00
|
|
|
const (
|
|
|
|
jsonAPISuffix = "/json"
|
|
|
|
)
|
|
|
|
|
2021-05-11 04:54:06 +00:00
|
|
|
var (
|
|
|
|
compressor = middleware.NewCompressor(5)
|
|
|
|
xForwardedProto = http.CanonicalHeaderKey("X-Forwarded-Proto")
|
|
|
|
)
|
2021-02-04 21:32:55 +00:00
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
type httpdServer struct {
|
2021-07-01 18:17:40 +00:00
|
|
|
binding Binding
|
|
|
|
staticFilesPath string
|
2021-11-21 08:32:51 +00:00
|
|
|
openAPIPath string
|
2021-07-01 18:17:40 +00:00
|
|
|
enableWebAdmin bool
|
|
|
|
enableWebClient bool
|
2022-09-22 15:27:00 +00:00
|
|
|
enableRESTAPI bool
|
2021-11-21 08:32:51 +00:00
|
|
|
renderOpenAPI bool
|
2022-07-11 06:17:36 +00:00
|
|
|
isShared int
|
2021-07-01 18:17:40 +00:00
|
|
|
router *chi.Mux
|
|
|
|
tokenAuth *jwtauth.JWTAuth
|
|
|
|
signingPassphrase string
|
2021-11-13 22:14:50 +00:00
|
|
|
cors CorsConfig
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 08:32:51 +00:00
|
|
|
func newHttpdServer(b Binding, staticFilesPath, signingPassphrase string, cors CorsConfig,
|
|
|
|
openAPIPath string,
|
|
|
|
) *httpdServer {
|
|
|
|
if openAPIPath == "" {
|
|
|
|
b.RenderOpenAPI = false
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
return &httpdServer{
|
2021-07-01 18:17:40 +00:00
|
|
|
binding: b,
|
|
|
|
staticFilesPath: staticFilesPath,
|
2021-11-21 08:32:51 +00:00
|
|
|
openAPIPath: openAPIPath,
|
2021-07-01 18:17:40 +00:00
|
|
|
enableWebAdmin: b.EnableWebAdmin,
|
|
|
|
enableWebClient: b.EnableWebClient,
|
2022-09-22 15:27:00 +00:00
|
|
|
enableRESTAPI: b.EnableRESTAPI,
|
2021-11-21 08:32:51 +00:00
|
|
|
renderOpenAPI: b.RenderOpenAPI,
|
2021-07-01 18:17:40 +00:00
|
|
|
signingPassphrase: signingPassphrase,
|
2021-11-13 22:14:50 +00:00
|
|
|
cors: cors,
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 06:17:36 +00:00
|
|
|
func (s *httpdServer) setShared(value int) {
|
|
|
|
s.isShared = value
|
|
|
|
}
|
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
func (s *httpdServer) listenAndServe() error {
|
|
|
|
s.initializeRouter()
|
|
|
|
httpServer := &http.Server{
|
2021-05-06 19:35:43 +00:00
|
|
|
Handler: s.router,
|
|
|
|
ReadHeaderTimeout: 30 * time.Second,
|
2021-05-07 18:41:20 +00:00
|
|
|
ReadTimeout: 60 * time.Second,
|
|
|
|
WriteTimeout: 60 * time.Second,
|
|
|
|
IdleTimeout: 60 * time.Second,
|
2023-11-04 16:56:25 +00:00
|
|
|
MaxHeaderBytes: 1 << 16, // 64KB
|
2022-01-05 10:37:45 +00:00
|
|
|
ErrorLog: log.New(&logger.StdLoggerWrapper{Sender: logSender}, "", 0),
|
2021-05-06 19:35:43 +00:00
|
|
|
}
|
2021-01-19 17:59:41 +00:00
|
|
|
if certMgr != nil && s.binding.EnableHTTPS {
|
2022-05-21 14:34:47 +00:00
|
|
|
certID := common.DefaultTLSKeyPaidID
|
|
|
|
if getConfigPath(s.binding.CertificateFile, "") != "" && getConfigPath(s.binding.CertificateKeyFile, "") != "" {
|
|
|
|
certID = s.binding.GetAddress()
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
config := &tls.Config{
|
2023-08-07 17:11:48 +00:00
|
|
|
GetCertificate: certMgr.GetCertificateFunc(certID),
|
|
|
|
MinVersion: util.GetTLSVersion(s.binding.MinTLSVersion),
|
2023-10-28 10:35:26 +00:00
|
|
|
NextProtos: util.GetALPNProtocols(s.binding.Protocols),
|
2023-08-07 17:11:48 +00:00
|
|
|
CipherSuites: util.GetTLSCiphersFromNames(s.binding.TLSCipherSuites),
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
httpServer.TLSConfig = config
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "configured TLS cipher suites for binding %q: %v, certID: %v",
|
2022-05-21 14:34:47 +00:00
|
|
|
s.binding.GetAddress(), httpServer.TLSConfig.CipherSuites, certID)
|
2021-01-19 17:59:41 +00:00
|
|
|
if s.binding.ClientAuthType == 1 {
|
|
|
|
httpServer.TLSConfig.ClientCAs = certMgr.GetRootCAs()
|
|
|
|
httpServer.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
|
|
|
|
httpServer.TLSConfig.VerifyConnection = s.verifyTLSConnection
|
|
|
|
}
|
2021-07-11 13:26:51 +00:00
|
|
|
return util.HTTPListenAndServe(httpServer, s.binding.Address, s.binding.Port, true, logSender)
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
2021-07-11 13:26:51 +00:00
|
|
|
return util.HTTPListenAndServe(httpServer, s.binding.Address, s.binding.Port, false, logSender)
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 17:59:41 +00:00
|
|
|
func (s *httpdServer) verifyTLSConnection(state tls.ConnectionState) error {
|
|
|
|
if certMgr != nil {
|
|
|
|
var clientCrt *x509.Certificate
|
|
|
|
var clientCrtName string
|
|
|
|
if len(state.PeerCertificates) > 0 {
|
|
|
|
clientCrt = state.PeerCertificates[0]
|
|
|
|
clientCrtName = clientCrt.Subject.String()
|
|
|
|
}
|
|
|
|
if len(state.VerifiedChains) == 0 {
|
|
|
|
logger.Warn(logSender, "", "TLS connection cannot be verified: unable to get verification chain")
|
|
|
|
return errors.New("TLS connection cannot be verified: unable to get verification chain")
|
|
|
|
}
|
|
|
|
for _, verifiedChain := range state.VerifiedChains {
|
|
|
|
var caCrt *x509.Certificate
|
|
|
|
if len(verifiedChain) > 0 {
|
|
|
|
caCrt = verifiedChain[len(verifiedChain)-1]
|
|
|
|
}
|
|
|
|
if certMgr.IsRevoked(clientCrt, caCrt) {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "tls handshake error, client certificate %q has been revoked", clientCrtName)
|
2021-01-19 17:59:41 +00:00
|
|
|
return common.ErrCrtRevoked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
func (s *httpdServer) refreshCookie(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.checkCookieExpiration(w, r)
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-12 17:04:14 +00:00
|
|
|
func (s *httpdServer) renderClientLoginPage(w http.ResponseWriter, r *http.Request, err *util.I18nError, ip string) {
|
2023-12-30 18:12:22 +00:00
|
|
|
data := loginPage{
|
2023-11-25 17:30:56 +00:00
|
|
|
commonBasePage: getCommonBasePage(r),
|
2023-12-10 15:40:13 +00:00
|
|
|
Title: util.I18nLoginTitle,
|
2023-11-25 17:30:56 +00:00
|
|
|
CurrentURL: webClientLoginPath,
|
2023-12-12 17:04:14 +00:00
|
|
|
Error: err,
|
2023-11-25 17:30:56 +00:00
|
|
|
CSRFToken: createCSRFToken(ip),
|
|
|
|
Branding: s.binding.Branding.WebClient,
|
|
|
|
FormDisabled: s.binding.isWebClientLoginFormDisabled(),
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
2023-06-08 16:14:47 +00:00
|
|
|
if next := r.URL.Query().Get("next"); strings.HasPrefix(next, webClientFilesPath) {
|
|
|
|
data.CurrentURL += "?next=" + url.QueryEscape(next)
|
|
|
|
}
|
2021-07-27 16:43:00 +00:00
|
|
|
if s.binding.showAdminLoginURL() {
|
2022-02-13 13:30:20 +00:00
|
|
|
data.AltLoginURL = webAdminLoginPath
|
2022-05-15 05:30:36 +00:00
|
|
|
data.AltLoginName = s.binding.Branding.WebAdmin.ShortName
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
2022-07-19 20:25:00 +00:00
|
|
|
if smtp.IsEnabled() && !data.FormDisabled {
|
2021-11-13 12:25:43 +00:00
|
|
|
data.ForgotPwdURL = webClientForgotPwdPath
|
|
|
|
}
|
2022-07-22 18:55:33 +00:00
|
|
|
if s.binding.OIDC.isEnabled() && !s.binding.isWebClientOIDCLoginDisabled() {
|
2022-02-13 13:30:20 +00:00
|
|
|
data.OpenIDLoginURL = webClientOIDCLoginPath
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
renderClientTemplate(w, templateCommonLogin, data)
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 13:30:20 +00:00
|
|
|
func (s *httpdServer) handleWebClientLogout(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
|
|
|
c := jwtTokenClaims{}
|
|
|
|
c.removeCookie(w, r, webBaseClientPath)
|
|
|
|
s.logoutOIDCUser(w, r)
|
|
|
|
|
|
|
|
http.Redirect(w, r, webClientLoginPath, http.StatusFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebClientChangePwdPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2023-06-04 06:45:17 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientChangePasswordPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm))
|
2022-02-13 13:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), util.GetIPFromRemoteAddress(r.RemoteAddr)); err != nil {
|
2023-12-10 15:40:13 +00:00
|
|
|
s.renderClientForbiddenPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF))
|
2022-02-13 13:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
2023-06-04 06:45:17 +00:00
|
|
|
err := doChangeUserPassword(r, strings.TrimSpace(r.Form.Get("current_password")),
|
|
|
|
strings.TrimSpace(r.Form.Get("new_password1")), strings.TrimSpace(r.Form.Get("new_password2")))
|
2022-02-13 13:30:20 +00:00
|
|
|
if err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientChangePasswordPage(w, r, util.NewI18nError(err, util.I18nErrorChangePwdGeneric))
|
2022-02-13 13:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
s.handleWebClientLogout(w, r)
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:43:00 +00:00
|
|
|
func (s *httpdServer) handleClientWebLogin(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2021-09-25 10:20:31 +00:00
|
|
|
if !dataprovider.HasAdmin() {
|
|
|
|
http.Redirect(w, r, webAdminSetupPath, http.StatusFound)
|
|
|
|
return
|
|
|
|
}
|
2023-12-12 17:04:14 +00:00
|
|
|
msg := getFlashMessage(w, r)
|
|
|
|
s.renderClientLoginPage(w, r, msg.getI18nError(), util.GetIPFromRemoteAddress(r.RemoteAddr))
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
func (s *httpdServer) handleWebClientLoginPost(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2021-05-08 17:45:21 +00:00
|
|
|
|
2022-03-26 07:41:50 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
protocol := common.ProtocolHTTP
|
2023-06-04 06:45:17 +00:00
|
|
|
username := strings.TrimSpace(r.Form.Get("username"))
|
|
|
|
password := strings.TrimSpace(r.Form.Get("password"))
|
2021-05-06 19:35:43 +00:00
|
|
|
if username == "" || password == "" {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, common.ErrNoCredentials)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-19 09:53:35 +00:00
|
|
|
if err := common.Config.ExecutePostConnectHook(ipAddr, protocol); err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r, util.NewI18nError(err, util.I18nError403Message), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-19 09:53:35 +00:00
|
|
|
user, err := dataprovider.CheckUserAndPass(username, password, ipAddr, protocol)
|
2021-05-06 19:35:43 +00:00
|
|
|
if err != nil {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
connectionID := fmt.Sprintf("%v_%v", protocol, xid.New().String())
|
2022-04-14 17:07:41 +00:00
|
|
|
if err := checkHTTPClientUser(&user, r, connectionID, true); err != nil {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r, util.NewI18nError(err, util.I18nError403Message), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer user.CloseFs() //nolint:errcheck
|
|
|
|
err = user.CheckFsRoot(connectionID)
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, connectionID, "unable to check fs root: %v", err)
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientLoginPage(w, r, util.NewI18nError(err, util.I18nErrorFsGeneric), ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
2021-09-04 10:11:04 +00:00
|
|
|
s.loginUser(w, r, &user, connectionID, ipAddr, false, s.renderClientLoginPage)
|
|
|
|
}
|
2021-05-06 19:35:43 +00:00
|
|
|
|
2021-11-13 12:25:43 +00:00
|
|
|
func (s *httpdServer) handleWebClientPasswordResetPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2022-03-26 07:41:50 +00:00
|
|
|
|
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientResetPwdPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2023-12-10 15:40:13 +00:00
|
|
|
s.renderClientForbiddenPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF))
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
2023-11-04 09:54:52 +00:00
|
|
|
newPassword := strings.TrimSpace(r.Form.Get("password"))
|
|
|
|
confirmPassword := strings.TrimSpace(r.Form.Get("confirm_password"))
|
2023-06-04 06:45:17 +00:00
|
|
|
_, user, err := handleResetPassword(r, strings.TrimSpace(r.Form.Get("code")),
|
2023-12-30 18:12:22 +00:00
|
|
|
newPassword, confirmPassword, false)
|
2021-11-13 12:25:43 +00:00
|
|
|
if err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientResetPwdPage(w, r, util.NewI18nError(err, util.I18nErrorChangePwdGeneric), ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
connectionID := fmt.Sprintf("%v_%v", getProtocolFromRequest(r), xid.New().String())
|
2022-04-14 17:07:41 +00:00
|
|
|
if err := checkHTTPClientUser(user, r, connectionID, true); err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientResetPwdPage(w, r, util.NewI18nError(err, util.I18nErrorDirList403), ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer user.CloseFs() //nolint:errcheck
|
|
|
|
err = user.CheckFsRoot(connectionID)
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, connectionID, "unable to check fs root: %v", err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientResetPwdPage(w, r, util.NewI18nError(err, util.I18nErrorLoginAfterReset), ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-19 20:44:27 +00:00
|
|
|
s.loginUser(w, r, user, connectionID, ipAddr, false, s.renderClientResetPwdPage)
|
2021-11-13 12:25:43 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 10:11:04 +00:00
|
|
|
func (s *httpdServer) handleWebClientTwoFactorRecoveryPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
|
|
|
claims, err := getTokenClaims(r)
|
|
|
|
if err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderNotFoundPage(w, r, nil)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
username := claims.Username
|
2023-06-04 06:45:17 +00:00
|
|
|
recoveryCode := strings.TrimSpace(r.Form.Get("recovery_code"))
|
2021-09-04 10:11:04 +00:00
|
|
|
if username == "" || recoveryCode == "" {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
2021-05-06 19:35:43 +00:00
|
|
|
}
|
2022-11-16 18:04:50 +00:00
|
|
|
user, userMerged, err := dataprovider.GetUserVariants(username, "")
|
2021-09-04 10:11:04 +00:00
|
|
|
if err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
if errors.Is(err, util.ErrNotFound) {
|
|
|
|
handleDefenderEventLoginFailed(ipAddr, err) //nolint:errcheck
|
|
|
|
}
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-05-19 17:49:51 +00:00
|
|
|
if !userMerged.Filters.TOTPConfig.Enabled || !util.Contains(userMerged.Filters.TOTPConfig.Protocols, common.ProtocolHTTP) {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r, util.NewI18nError(
|
|
|
|
util.NewValidationError("two factory authentication is not enabled"), util.I18n2FADisabled), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
for idx, code := range user.Filters.RecoveryCodes {
|
|
|
|
if err := code.Secret.Decrypt(); err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderClientInternalServerErrorPage(w, r, fmt.Errorf("unable to decrypt recovery code: %w", err))
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if code.Secret.GetPayload() == recoveryCode {
|
|
|
|
if code.Used {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
user.Filters.RecoveryCodes[idx].Used = true
|
2022-12-03 10:45:27 +00:00
|
|
|
err = dataprovider.UpdateUser(&user, dataprovider.ActionExecutorSelf, ipAddr, user.Role)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err != nil {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Warn(logSender, "", "unable to set the recovery code %q as used: %v", recoveryCode, err)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderClientInternalServerErrorPage(w, r, errors.New("unable to set the recovery code as used"))
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
connectionID := fmt.Sprintf("%v_%v", getProtocolFromRequest(r), xid.New().String())
|
2022-04-25 13:49:11 +00:00
|
|
|
s.loginUser(w, r, &userMerged, connectionID, ipAddr, true,
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2023-03-04 12:55:48 +00:00
|
|
|
handleDefenderEventLoginFailed(ipAddr, dataprovider.ErrInvalidCredentials) //nolint:errcheck
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorRecoveryPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
}
|
2021-05-06 19:35:43 +00:00
|
|
|
|
2021-09-04 10:11:04 +00:00
|
|
|
func (s *httpdServer) handleWebClientTwoFactorPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
|
|
|
claims, err := getTokenClaims(r)
|
2021-05-06 19:35:43 +00:00
|
|
|
if err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderNotFoundPage(w, r, nil)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
username := claims.Username
|
2023-06-04 06:45:17 +00:00
|
|
|
passcode := strings.TrimSpace(r.Form.Get("passcode"))
|
2021-09-04 10:11:04 +00:00
|
|
|
if username == "" || passcode == "" {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, common.ErrNoCredentials)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-11-16 18:04:50 +00:00
|
|
|
user, err := dataprovider.GetUserWithGroupSettings(username, "")
|
2021-09-04 10:11:04 +00:00
|
|
|
if err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, err)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-05-19 17:49:51 +00:00
|
|
|
if !user.Filters.TOTPConfig.Enabled || !util.Contains(user.Filters.TOTPConfig.Protocols, common.ProtocolHTTP) {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r, util.NewI18nError(common.ErrInternalFailure, util.I18n2FADisabled), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err = user.Filters.TOTPConfig.Secret.Decrypt()
|
|
|
|
if err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderClientInternalServerErrorPage(w, r, err)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
match, err := mfa.ValidateTOTPPasscode(user.Filters.TOTPConfig.ConfigName, passcode,
|
|
|
|
user.Filters.TOTPConfig.Secret.GetPayload())
|
|
|
|
if !match || err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, dataprovider.ErrInvalidCredentials)
|
2023-12-12 17:04:14 +00:00
|
|
|
s.renderClientTwoFactorPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2023-03-04 12:55:48 +00:00
|
|
|
connectionID := fmt.Sprintf("%s_%s", getProtocolFromRequest(r), xid.New().String())
|
2022-03-26 07:41:50 +00:00
|
|
|
s.loginUser(w, r, &user, connectionID, ipAddr, true, s.renderClientTwoFactorPage)
|
2021-09-04 10:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebAdminTwoFactorRecoveryPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2022-03-26 07:41:50 +00:00
|
|
|
|
2021-09-04 10:11:04 +00:00
|
|
|
claims, err := getTokenClaims(r)
|
|
|
|
if err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderNotFoundPage(w, r, nil)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
username := claims.Username
|
2023-06-04 06:45:17 +00:00
|
|
|
recoveryCode := strings.TrimSpace(r.Form.Get("recovery_code"))
|
2021-09-04 10:11:04 +00:00
|
|
|
if username == "" || recoveryCode == "" {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
admin, err := dataprovider.AdminExists(username)
|
|
|
|
if err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
if errors.Is(err, util.ErrNotFound) {
|
|
|
|
handleDefenderEventLoginFailed(ipAddr, err) //nolint:errcheck
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if !admin.Filters.TOTPConfig.Enabled {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r, util.NewI18nError(util.NewValidationError("two factory authentication is not enabled"), util.I18n2FADisabled), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
for idx, code := range admin.Filters.RecoveryCodes {
|
|
|
|
if err := code.Secret.Decrypt(); err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderInternalServerErrorPage(w, r, fmt.Errorf("unable to decrypt recovery code: %w", err))
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if code.Secret.GetPayload() == recoveryCode {
|
|
|
|
if code.Used {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r,
|
|
|
|
util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
admin.Filters.RecoveryCodes[idx].Used = true
|
2022-12-03 10:45:27 +00:00
|
|
|
err = dataprovider.UpdateAdmin(&admin, dataprovider.ActionExecutorSelf, ipAddr, admin.Role)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err != nil {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Warn(logSender, "", "unable to set the recovery code %q as used: %v", recoveryCode, err)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderInternalServerErrorPage(w, r, errors.New("unable to set the recovery code as used"))
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:03:17 +00:00
|
|
|
s.loginAdmin(w, r, &admin, true, s.renderTwoFactorRecoveryPage, ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2023-03-04 12:55:48 +00:00
|
|
|
handleDefenderEventLoginFailed(ipAddr, dataprovider.ErrInvalidCredentials) //nolint:errcheck
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorRecoveryPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebAdminTwoFactorPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
|
|
|
claims, err := getTokenClaims(r)
|
|
|
|
if err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderNotFoundPage(w, r, nil)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
username := claims.Username
|
2023-06-04 06:45:17 +00:00
|
|
|
passcode := strings.TrimSpace(r.Form.Get("passcode"))
|
2021-09-04 10:11:04 +00:00
|
|
|
if username == "" || passcode == "" {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
err = handleDefenderEventLoginFailed(ipAddr, err)
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
admin, err := dataprovider.AdminExists(username)
|
|
|
|
if err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
if errors.Is(err, util.ErrNotFound) {
|
|
|
|
handleDefenderEventLoginFailed(ipAddr, err) //nolint:errcheck
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCredentials), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if !admin.Filters.TOTPConfig.Enabled {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorPage(w, r, util.NewI18nError(common.ErrInternalFailure, util.I18n2FADisabled), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err = admin.Filters.TOTPConfig.Secret.Decrypt()
|
|
|
|
if err != nil {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderInternalServerErrorPage(w, r, err)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
match, err := mfa.ValidateTOTPPasscode(admin.Filters.TOTPConfig.ConfigName, passcode,
|
|
|
|
admin.Filters.TOTPConfig.Secret.GetPayload())
|
|
|
|
if !match || err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
handleDefenderEventLoginFailed(ipAddr, dataprovider.ErrInvalidCredentials) //nolint:errcheck
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderTwoFactorPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
s.loginAdmin(w, r, &admin, true, s.renderTwoFactorPage, ipAddr)
|
2021-05-06 19:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebAdminLoginPost(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2022-03-26 07:41:50 +00:00
|
|
|
|
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminLoginPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2023-06-04 06:45:17 +00:00
|
|
|
username := strings.TrimSpace(r.Form.Get("username"))
|
|
|
|
password := strings.TrimSpace(r.Form.Get("password"))
|
2021-01-17 21:29:08 +00:00
|
|
|
if username == "" || password == "" {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminLoginPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminLoginPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF), ipAddr)
|
2021-02-03 07:55:28 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:03:17 +00:00
|
|
|
admin, err := dataprovider.CheckAdminAndPass(username, password, ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
if err != nil {
|
2023-12-31 16:35:14 +00:00
|
|
|
handleDefenderEventLoginFailed(ipAddr, err) //nolint:errcheck
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminLoginPage(w, r, util.NewI18nError(dataprovider.ErrInvalidCredentials, util.I18nErrorInvalidCredentials),
|
|
|
|
ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:03:17 +00:00
|
|
|
s.loginAdmin(w, r, &admin, false, s.renderAdminLoginPage, ipAddr)
|
2021-05-16 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2023-12-30 18:12:22 +00:00
|
|
|
func (s *httpdServer) renderAdminLoginPage(w http.ResponseWriter, r *http.Request, err *util.I18nError, ip string) {
|
2021-07-27 16:43:00 +00:00
|
|
|
data := loginPage{
|
2023-11-25 17:30:56 +00:00
|
|
|
commonBasePage: getCommonBasePage(r),
|
2023-12-10 15:40:13 +00:00
|
|
|
Title: util.I18nLoginTitle,
|
2023-11-25 17:30:56 +00:00
|
|
|
CurrentURL: webAdminLoginPath,
|
2023-12-30 18:12:22 +00:00
|
|
|
Error: err,
|
2023-11-25 17:30:56 +00:00
|
|
|
CSRFToken: createCSRFToken(ip),
|
|
|
|
Branding: s.binding.Branding.WebAdmin,
|
|
|
|
FormDisabled: s.binding.isWebAdminLoginFormDisabled(),
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
|
|
|
if s.binding.showClientLoginURL() {
|
|
|
|
data.AltLoginURL = webClientLoginPath
|
2022-05-15 05:30:36 +00:00
|
|
|
data.AltLoginName = s.binding.Branding.WebClient.ShortName
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
2022-07-19 20:25:00 +00:00
|
|
|
if smtp.IsEnabled() && !data.FormDisabled {
|
2021-11-13 12:25:43 +00:00
|
|
|
data.ForgotPwdURL = webAdminForgotPwdPath
|
|
|
|
}
|
2022-07-22 18:55:33 +00:00
|
|
|
if s.binding.OIDC.hasRoles() && !s.binding.isWebAdminOIDCLoginDisabled() {
|
2022-02-13 13:30:20 +00:00
|
|
|
data.OpenIDLoginURL = webAdminOIDCLoginPath
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
renderAdminTemplate(w, templateCommonLogin, data)
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebAdminLogin(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2021-07-27 16:43:00 +00:00
|
|
|
if !dataprovider.HasAdmin() {
|
|
|
|
http.Redirect(w, r, webAdminSetupPath, http.StatusFound)
|
|
|
|
return
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
msg := getFlashMessage(w, r)
|
|
|
|
s.renderAdminLoginPage(w, r, msg.getI18nError(), util.GetIPFromRemoteAddress(r.RemoteAddr))
|
2022-02-13 13:30:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebAdminLogout(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
|
|
|
c := jwtTokenClaims{}
|
|
|
|
c.removeCookie(w, r, webBaseAdminPath)
|
|
|
|
s.logoutOIDCUser(w, r)
|
|
|
|
|
|
|
|
http.Redirect(w, r, webAdminLoginPath, http.StatusFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) handleWebAdminChangePwdPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderChangePasswordPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm))
|
2022-02-13 13:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), util.GetIPFromRemoteAddress(r.RemoteAddr)); err != nil {
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderForbiddenPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF))
|
2022-02-13 13:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
2023-06-04 06:45:17 +00:00
|
|
|
err = doChangeAdminPassword(r, strings.TrimSpace(r.Form.Get("current_password")),
|
|
|
|
strings.TrimSpace(r.Form.Get("new_password1")), strings.TrimSpace(r.Form.Get("new_password2")))
|
2022-02-13 13:30:20 +00:00
|
|
|
if err != nil {
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderChangePasswordPage(w, r, util.NewI18nError(err, util.I18nErrorChangePwdGeneric))
|
2022-02-13 13:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
s.handleWebAdminLogout(w, r)
|
2021-07-27 16:43:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 12:25:43 +00:00
|
|
|
func (s *httpdServer) handleWebAdminPasswordResetPost(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2022-03-26 07:41:50 +00:00
|
|
|
|
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderResetPwdPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidForm), ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderForbiddenPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF))
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
newPassword := strings.TrimSpace(r.Form.Get("password"))
|
|
|
|
confirmPassword := strings.TrimSpace(r.Form.Get("confirm_password"))
|
2023-06-04 06:45:17 +00:00
|
|
|
admin, _, err := handleResetPassword(r, strings.TrimSpace(r.Form.Get("code")),
|
2023-12-30 18:12:22 +00:00
|
|
|
newPassword, confirmPassword, true)
|
2021-11-13 12:25:43 +00:00
|
|
|
if err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderResetPwdPage(w, r, util.NewI18nError(err, util.I18nErrorChangePwdGeneric), ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-26 07:41:50 +00:00
|
|
|
s.loginAdmin(w, r, admin, false, s.renderResetPwdPage, ipAddr)
|
2021-11-13 12:25:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-16 19:36:57 +00:00
|
|
|
func (s *httpdServer) handleWebAdminSetupPost(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2021-05-16 19:36:57 +00:00
|
|
|
if dataprovider.HasAdmin() {
|
2022-03-19 20:44:27 +00:00
|
|
|
s.renderBadRequestPage(w, r, errors.New("an admin user already exists"))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-05-16 19:36:57 +00:00
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, "", ipAddr, util.NewI18nError(err, util.I18nErrorInvalidForm))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-26 07:41:50 +00:00
|
|
|
if err := verifyCSRFToken(r.Form.Get(csrfFormToken), ipAddr); err != nil {
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderForbiddenPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
2023-06-04 06:45:17 +00:00
|
|
|
username := strings.TrimSpace(r.Form.Get("username"))
|
|
|
|
password := strings.TrimSpace(r.Form.Get("password"))
|
|
|
|
confirmPassword := strings.TrimSpace(r.Form.Get("confirm_password"))
|
|
|
|
installCode := strings.TrimSpace(r.Form.Get("install_code"))
|
2022-04-03 06:52:36 +00:00
|
|
|
if installationCode != "" && installCode != resolveInstallationCode() {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, username, ipAddr,
|
|
|
|
util.NewI18nError(
|
|
|
|
util.NewValidationError(fmt.Sprintf("%v mismatch", installationCodeHint)),
|
|
|
|
util.I18nErrorSetupInstallCode),
|
|
|
|
)
|
2022-02-27 12:08:47 +00:00
|
|
|
return
|
|
|
|
}
|
2021-05-16 19:36:57 +00:00
|
|
|
if username == "" {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, username, ipAddr,
|
|
|
|
util.NewI18nError(util.NewValidationError("please set a username"), util.I18nError500Message))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if password == "" {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, username, ipAddr,
|
|
|
|
util.NewI18nError(util.NewValidationError("please set a password"), util.I18nError500Message))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if password != confirmPassword {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, username, ipAddr,
|
|
|
|
util.NewI18nError(errors.New("the two password fields do not match"), util.I18nErrorChangePwdNoMatch))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
admin := dataprovider.Admin{
|
|
|
|
Username: username,
|
|
|
|
Password: password,
|
|
|
|
Status: 1,
|
|
|
|
Permissions: []string{dataprovider.PermAdminAny},
|
|
|
|
}
|
2022-12-03 10:45:27 +00:00
|
|
|
err = dataprovider.AddAdmin(&admin, username, ipAddr, "")
|
2021-05-16 19:36:57 +00:00
|
|
|
if err != nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, username, ipAddr, util.NewI18nError(err, util.I18nError500Message))
|
2021-05-16 19:36:57 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:03:17 +00:00
|
|
|
s.loginAdmin(w, r, &admin, false, nil, ipAddr)
|
2021-05-16 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 10:11:04 +00:00
|
|
|
func (s *httpdServer) loginUser(
|
|
|
|
w http.ResponseWriter, r *http.Request, user *dataprovider.User, connectionID, ipAddr string,
|
2023-12-12 17:04:14 +00:00
|
|
|
isSecondFactorAuth bool, errorFunc func(w http.ResponseWriter, r *http.Request, err *util.I18nError, ip string),
|
2021-09-04 10:11:04 +00:00
|
|
|
) {
|
|
|
|
c := jwtTokenClaims{
|
2022-03-06 15:57:13 +00:00
|
|
|
Username: user.Username,
|
|
|
|
Permissions: user.Filters.WebClient,
|
|
|
|
Signature: user.GetSignature(),
|
2022-12-03 10:45:27 +00:00
|
|
|
Role: user.Role,
|
2022-03-06 15:57:13 +00:00
|
|
|
MustSetTwoFactorAuth: user.MustSetSecondFactor(),
|
2022-12-11 16:15:34 +00:00
|
|
|
MustChangePassword: user.MustChangePassword(),
|
2022-03-06 15:57:13 +00:00
|
|
|
RequiredTwoFactorProtocols: user.Filters.TwoFactorAuthProtocols,
|
2021-09-04 10:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
audience := tokenAudienceWebClient
|
2022-05-19 17:49:51 +00:00
|
|
|
if user.Filters.TOTPConfig.Enabled && util.Contains(user.Filters.TOTPConfig.Protocols, common.ProtocolHTTP) &&
|
2021-09-04 10:11:04 +00:00
|
|
|
user.CanManageMFA() && !isSecondFactorAuth {
|
|
|
|
audience = tokenAudienceWebClientPartial
|
|
|
|
}
|
|
|
|
|
2022-03-24 21:03:17 +00:00
|
|
|
err := c.createAndSetCookie(w, r, s.tokenAuth, audience, ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, connectionID, "unable to set user login cookie %v", err)
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2023-12-12 17:04:14 +00:00
|
|
|
errorFunc(w, r, util.NewI18nError(err, util.I18nError500Message), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if isSecondFactorAuth {
|
|
|
|
invalidateToken(r)
|
|
|
|
}
|
|
|
|
if audience == tokenAudienceWebClientPartial {
|
2023-06-08 16:14:47 +00:00
|
|
|
redirectPath := webClientTwoFactorPath
|
|
|
|
if next := r.URL.Query().Get("next"); strings.HasPrefix(next, webClientFilesPath) {
|
|
|
|
redirectPath += "?next=" + url.QueryEscape(next)
|
|
|
|
}
|
|
|
|
http.Redirect(w, r, redirectPath, http.StatusFound)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(user, dataprovider.LoginMethodPassword, ipAddr, err)
|
2021-09-04 10:11:04 +00:00
|
|
|
dataprovider.UpdateLastLogin(user)
|
2023-06-08 16:14:47 +00:00
|
|
|
if next := r.URL.Query().Get("next"); strings.HasPrefix(next, webClientFilesPath) {
|
|
|
|
http.Redirect(w, r, next, http.StatusFound)
|
|
|
|
return
|
|
|
|
}
|
2021-09-04 10:11:04 +00:00
|
|
|
http.Redirect(w, r, webClientFilesPath, http.StatusFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) loginAdmin(
|
|
|
|
w http.ResponseWriter, r *http.Request, admin *dataprovider.Admin,
|
2023-12-30 18:12:22 +00:00
|
|
|
isSecondFactorAuth bool, errorFunc func(w http.ResponseWriter, r *http.Request, err *util.I18nError, ip string),
|
2022-03-26 07:41:50 +00:00
|
|
|
ipAddr string,
|
2021-09-04 10:11:04 +00:00
|
|
|
) {
|
2021-01-17 21:29:08 +00:00
|
|
|
c := jwtTokenClaims{
|
2022-09-21 17:36:08 +00:00
|
|
|
Username: admin.Username,
|
|
|
|
Permissions: admin.Permissions,
|
2022-11-16 18:04:50 +00:00
|
|
|
Role: admin.Role,
|
2022-09-21 17:36:08 +00:00
|
|
|
Signature: admin.GetSignature(),
|
|
|
|
HideUserPageSections: admin.Filters.Preferences.HideUserPageSections,
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 10:11:04 +00:00
|
|
|
audience := tokenAudienceWebAdmin
|
|
|
|
if admin.Filters.TOTPConfig.Enabled && admin.CanManageMFA() && !isSecondFactorAuth {
|
|
|
|
audience = tokenAudienceWebAdminPartial
|
|
|
|
}
|
|
|
|
|
2022-03-26 07:41:50 +00:00
|
|
|
err := c.createAndSetCookie(w, r, s.tokenAuth, audience, ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
if err != nil {
|
2021-05-16 07:13:00 +00:00
|
|
|
logger.Warn(logSender, "", "unable to set admin login cookie %v", err)
|
2021-09-04 10:11:04 +00:00
|
|
|
if errorFunc == nil {
|
2023-12-30 18:12:22 +00:00
|
|
|
s.renderAdminSetupPage(w, r, admin.Username, ipAddr, util.NewI18nError(err, util.I18nError500Message))
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
2023-12-30 18:12:22 +00:00
|
|
|
errorFunc(w, r, util.NewI18nError(err, util.I18nError500Message), ipAddr)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if isSecondFactorAuth {
|
|
|
|
invalidateToken(r)
|
|
|
|
}
|
|
|
|
if audience == tokenAudienceWebAdminPartial {
|
|
|
|
http.Redirect(w, r, webAdminTwoFactorPath, http.StatusFound)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2021-08-19 13:51:43 +00:00
|
|
|
dataprovider.UpdateAdminLastLogin(admin)
|
2021-09-04 10:11:04 +00:00
|
|
|
http.Redirect(w, r, webUsersPath, http.StatusFound)
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 21:35:36 +00:00
|
|
|
func (s *httpdServer) logout(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2021-01-26 21:35:36 +00:00
|
|
|
invalidateToken(r)
|
|
|
|
sendAPIResponse(w, r, nil, "Your token has been invalidated", http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2021-06-05 14:07:09 +00:00
|
|
|
func (s *httpdServer) getUserToken(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2021-07-11 13:26:51 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-06-05 14:07:09 +00:00
|
|
|
username, password, ok := r.BasicAuth()
|
2022-02-19 09:53:35 +00:00
|
|
|
protocol := common.ProtocolHTTP
|
2021-06-05 14:07:09 +00:00
|
|
|
if !ok {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, common.ErrNoCredentials)
|
2021-06-05 14:07:09 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
|
|
|
sendAPIResponse(w, r, nil, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if username == "" || password == "" {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, common.ErrNoCredentials)
|
2021-06-05 14:07:09 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
|
|
|
sendAPIResponse(w, r, nil, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
if err := common.Config.ExecutePostConnectHook(ipAddr, protocol); err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
updateLoginMetrics(&dataprovider.User{BaseUser: sdk.BaseUser{Username: username}},
|
|
|
|
dataprovider.LoginMethodPassword, ipAddr, err)
|
2021-06-05 14:07:09 +00:00
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
user, err := dataprovider.CheckUserAndPass(username, password, ipAddr, protocol)
|
2021-06-05 14:07:09 +00:00
|
|
|
if err != nil {
|
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, err)
|
2021-06-05 14:07:09 +00:00
|
|
|
sendAPIResponse(w, r, dataprovider.ErrInvalidCredentials, http.StatusText(http.StatusUnauthorized),
|
|
|
|
http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
connectionID := fmt.Sprintf("%v_%v", protocol, xid.New().String())
|
2022-04-14 17:07:41 +00:00
|
|
|
if err := checkHTTPClientUser(&user, r, connectionID, true); err != nil {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, err)
|
2021-06-05 14:07:09 +00:00
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-19 17:49:51 +00:00
|
|
|
if user.Filters.TOTPConfig.Enabled && util.Contains(user.Filters.TOTPConfig.Protocols, common.ProtocolHTTP) {
|
2021-09-04 10:11:04 +00:00
|
|
|
passcode := r.Header.Get(otpHeaderCode)
|
|
|
|
if passcode == "" {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "TOTP enabled for user %q and not passcode provided, authentication refused", user.Username)
|
2021-09-04 10:11:04 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, dataprovider.ErrInvalidCredentials)
|
2021-09-04 10:11:04 +00:00
|
|
|
sendAPIResponse(w, r, dataprovider.ErrInvalidCredentials, http.StatusText(http.StatusUnauthorized),
|
|
|
|
http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = user.Filters.TOTPConfig.Secret.Decrypt()
|
|
|
|
if err != nil {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2021-09-04 10:11:04 +00:00
|
|
|
sendAPIResponse(w, r, fmt.Errorf("unable to decrypt TOTP secret: %w", err), http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
match, err := mfa.ValidateTOTPPasscode(user.Filters.TOTPConfig.ConfigName, passcode,
|
|
|
|
user.Filters.TOTPConfig.Secret.GetPayload())
|
|
|
|
if !match || err != nil {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "invalid passcode for user %q, match? %v, err: %v", user.Username, match, err)
|
2021-09-04 10:11:04 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, dataprovider.ErrInvalidCredentials)
|
2021-09-04 10:11:04 +00:00
|
|
|
sendAPIResponse(w, r, dataprovider.ErrInvalidCredentials, http.StatusText(http.StatusUnauthorized),
|
|
|
|
http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-05 14:07:09 +00:00
|
|
|
defer user.CloseFs() //nolint:errcheck
|
|
|
|
err = user.CheckFsRoot(connectionID)
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, connectionID, "unable to check fs root: %v", err)
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2021-06-05 14:07:09 +00:00
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s.generateAndSendUserToken(w, r, ipAddr, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) generateAndSendUserToken(w http.ResponseWriter, r *http.Request, ipAddr string, user dataprovider.User) {
|
|
|
|
c := jwtTokenClaims{
|
2022-03-06 15:57:13 +00:00
|
|
|
Username: user.Username,
|
|
|
|
Permissions: user.Filters.WebClient,
|
|
|
|
Signature: user.GetSignature(),
|
2022-12-03 10:45:27 +00:00
|
|
|
Role: user.Role,
|
2022-03-06 15:57:13 +00:00
|
|
|
MustSetTwoFactorAuth: user.MustSetSecondFactor(),
|
2022-12-11 16:15:34 +00:00
|
|
|
MustChangePassword: user.MustChangePassword(),
|
2022-03-06 15:57:13 +00:00
|
|
|
RequiredTwoFactorProtocols: user.Filters.TwoFactorAuthProtocols,
|
2021-06-05 14:07:09 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 21:03:17 +00:00
|
|
|
resp, err := c.createTokenResponse(s.tokenAuth, tokenAudienceAPIUser, ipAddr)
|
2021-06-05 14:07:09 +00:00
|
|
|
if err != nil {
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, common.ErrInternalFailure)
|
2021-06-05 14:07:09 +00:00
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
2022-02-19 09:53:35 +00:00
|
|
|
updateLoginMetrics(&user, dataprovider.LoginMethodPassword, ipAddr, err)
|
2021-08-19 13:51:43 +00:00
|
|
|
dataprovider.UpdateLastLogin(&user)
|
2021-06-05 14:07:09 +00:00
|
|
|
|
|
|
|
render.JSON(w, r, resp)
|
|
|
|
}
|
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
func (s *httpdServer) getToken(w http.ResponseWriter, r *http.Request) {
|
|
|
|
username, password, ok := r.BasicAuth()
|
|
|
|
if !ok {
|
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
|
|
|
sendAPIResponse(w, r, nil, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:03:17 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
|
|
|
admin, err := dataprovider.CheckAdminAndPass(username, password, ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
if err != nil {
|
2023-03-04 12:55:48 +00:00
|
|
|
err = handleDefenderEventLoginFailed(ipAddr, err)
|
2021-01-17 21:29:08 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2021-09-04 10:11:04 +00:00
|
|
|
if admin.Filters.TOTPConfig.Enabled {
|
|
|
|
passcode := r.Header.Get(otpHeaderCode)
|
|
|
|
if passcode == "" {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "TOTP enabled for admin %q and not passcode provided, authentication refused", admin.Username)
|
2021-09-04 10:11:04 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
2023-03-04 12:55:48 +00:00
|
|
|
err = handleDefenderEventLoginFailed(ipAddr, dataprovider.ErrInvalidCredentials)
|
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
2021-09-04 10:11:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err = admin.Filters.TOTPConfig.Secret.Decrypt()
|
|
|
|
if err != nil {
|
|
|
|
sendAPIResponse(w, r, fmt.Errorf("unable to decrypt TOTP secret: %w", err),
|
|
|
|
http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
match, err := mfa.ValidateTOTPPasscode(admin.Filters.TOTPConfig.ConfigName, passcode,
|
|
|
|
admin.Filters.TOTPConfig.Secret.GetPayload())
|
|
|
|
if !match || err != nil {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "invalid passcode for admin %q, match? %v, err: %v", admin.Username, match, err)
|
2021-09-04 10:11:04 +00:00
|
|
|
w.Header().Set(common.HTTPAuthenticationHeader, basicRealm)
|
2023-03-04 12:55:48 +00:00
|
|
|
err = handleDefenderEventLoginFailed(ipAddr, dataprovider.ErrInvalidCredentials)
|
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusUnauthorized),
|
2021-09-04 10:11:04 +00:00
|
|
|
http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2022-03-24 21:03:17 +00:00
|
|
|
s.generateAndSendToken(w, r, admin, ipAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 21:03:17 +00:00
|
|
|
func (s *httpdServer) generateAndSendToken(w http.ResponseWriter, r *http.Request, admin dataprovider.Admin, ip string) {
|
2021-01-17 21:29:08 +00:00
|
|
|
c := jwtTokenClaims{
|
|
|
|
Username: admin.Username,
|
|
|
|
Permissions: admin.Permissions,
|
2022-11-16 18:04:50 +00:00
|
|
|
Role: admin.Role,
|
2021-01-17 21:29:08 +00:00
|
|
|
Signature: admin.GetSignature(),
|
|
|
|
}
|
|
|
|
|
2022-03-24 21:03:17 +00:00
|
|
|
resp, err := c.createTokenResponse(s.tokenAuth, tokenAudienceAPI, ip)
|
2021-01-17 21:29:08 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-19 13:51:43 +00:00
|
|
|
dataprovider.UpdateAdminLastLogin(&admin)
|
2021-01-17 21:29:08 +00:00
|
|
|
render.JSON(w, r, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) checkCookieExpiration(w http.ResponseWriter, r *http.Request) {
|
2022-02-13 13:30:20 +00:00
|
|
|
if _, ok := r.Context().Value(oidcTokenKey).(string); ok {
|
|
|
|
return
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
token, claims, err := jwtauth.FromContext(r.Context())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tokenClaims := jwtTokenClaims{}
|
|
|
|
tokenClaims.Decode(claims)
|
|
|
|
if tokenClaims.Username == "" || tokenClaims.Signature == "" {
|
|
|
|
return
|
|
|
|
}
|
2021-11-06 13:13:20 +00:00
|
|
|
if time.Until(token.Expiration()) > tokenRefreshThreshold {
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2022-05-19 17:49:51 +00:00
|
|
|
if util.Contains(token.Audience(), tokenAudienceWebClient) {
|
2021-05-06 19:35:43 +00:00
|
|
|
s.refreshClientToken(w, r, tokenClaims)
|
|
|
|
} else {
|
|
|
|
s.refreshAdminToken(w, r, tokenClaims)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) refreshClientToken(w http.ResponseWriter, r *http.Request, tokenClaims jwtTokenClaims) {
|
2022-11-16 18:04:50 +00:00
|
|
|
user, err := dataprovider.GetUserWithGroupSettings(tokenClaims.Username, "")
|
2021-05-06 19:35:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if user.GetSignature() != tokenClaims.Signature {
|
2022-12-03 10:45:27 +00:00
|
|
|
logger.Debug(logSender, "", "signature mismatch for user %q, unable to refresh cookie", user.Username)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
2022-04-14 17:07:41 +00:00
|
|
|
if err := checkHTTPClientUser(&user, r, xid.New().String(), true); err != nil {
|
2022-12-03 10:45:27 +00:00
|
|
|
logger.Debug(logSender, "", "unable to refresh cookie for user %q: %v", user.Username, err)
|
2021-05-06 19:35:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-20 09:48:39 +00:00
|
|
|
tokenClaims.Permissions = user.Filters.WebClient
|
2022-12-03 10:45:27 +00:00
|
|
|
tokenClaims.Role = user.Role
|
|
|
|
logger.Debug(logSender, "", "cookie refreshed for user %q", user.Username)
|
2022-03-24 21:03:17 +00:00
|
|
|
tokenClaims.createAndSetCookie(w, r, s.tokenAuth, tokenAudienceWebClient, util.GetIPFromRemoteAddress(r.RemoteAddr)) //nolint:errcheck
|
2021-05-06 19:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) refreshAdminToken(w http.ResponseWriter, r *http.Request, tokenClaims jwtTokenClaims) {
|
2021-01-17 21:29:08 +00:00
|
|
|
admin, err := dataprovider.AdminExists(tokenClaims.Username)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if admin.Status != 1 {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "admin %q is disabled, unable to refresh cookie", admin.Username)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if admin.GetSignature() != tokenClaims.Signature {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "signature mismatch for admin %q, unable to refresh cookie", admin.Username)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:03:17 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
|
|
|
if !admin.CanLoginFromIP(ipAddr) {
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "admin %q cannot login from %v, unable to refresh cookie", admin.Username, r.RemoteAddr)
|
2021-01-17 21:29:08 +00:00
|
|
|
return
|
|
|
|
}
|
2021-11-20 09:48:39 +00:00
|
|
|
tokenClaims.Permissions = admin.Permissions
|
2022-11-16 18:04:50 +00:00
|
|
|
tokenClaims.Role = admin.Role
|
2022-09-21 17:36:08 +00:00
|
|
|
tokenClaims.HideUserPageSections = admin.Filters.Preferences.HideUserPageSections
|
2023-02-27 18:02:43 +00:00
|
|
|
logger.Debug(logSender, "", "cookie refreshed for admin %q", admin.Username)
|
2022-03-24 21:03:17 +00:00
|
|
|
tokenClaims.createAndSetCookie(w, r, s.tokenAuth, tokenAudienceWebAdmin, ipAddr) //nolint:errcheck
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) updateContextFromCookie(r *http.Request) *http.Request {
|
|
|
|
token, _, err := jwtauth.FromContext(r.Context())
|
|
|
|
if token == nil || err != nil {
|
2022-02-13 13:30:20 +00:00
|
|
|
_, err = r.Cookie(jwtCookieKey)
|
2021-01-17 21:29:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
token, err = jwtauth.VerifyRequest(s.tokenAuth, r, jwtauth.TokenFromCookie)
|
|
|
|
ctx := jwtauth.NewContext(r.Context(), token, err)
|
|
|
|
return r.WithContext(ctx)
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2023-11-08 18:11:00 +00:00
|
|
|
func (s *httpdServer) parseHeaders(next http.Handler) http.Handler {
|
2021-05-11 04:54:06 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2021-07-11 13:26:51 +00:00
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2022-06-09 06:37:37 +00:00
|
|
|
var ip net.IP
|
|
|
|
isUnixSocket := filepath.IsAbs(s.binding.Address)
|
|
|
|
if !isUnixSocket {
|
|
|
|
ip = net.ParseIP(ipAddr)
|
|
|
|
}
|
2022-02-17 17:22:27 +00:00
|
|
|
areHeadersAllowed := false
|
2022-06-09 06:37:37 +00:00
|
|
|
if isUnixSocket || ip != nil {
|
2021-05-11 04:54:06 +00:00
|
|
|
for _, allow := range s.binding.allowHeadersFrom {
|
|
|
|
if allow(ip) {
|
2022-05-28 17:47:23 +00:00
|
|
|
parsedIP := util.GetRealIP(r, s.binding.ClientIPProxyHeader, s.binding.ClientIPHeaderDepth)
|
2021-05-11 04:54:06 +00:00
|
|
|
if parsedIP != "" {
|
|
|
|
ipAddr = parsedIP
|
|
|
|
r.RemoteAddr = ipAddr
|
|
|
|
}
|
|
|
|
if forwardedProto := r.Header.Get(xForwardedProto); forwardedProto != "" {
|
|
|
|
ctx := context.WithValue(r.Context(), forwardedProtoKey, forwardedProto)
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
}
|
2022-02-17 17:22:27 +00:00
|
|
|
areHeadersAllowed = true
|
2021-05-11 04:54:06 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-17 17:22:27 +00:00
|
|
|
if !areHeadersAllowed {
|
|
|
|
for idx := range s.binding.Security.proxyHeaders {
|
|
|
|
r.Header.Del(s.binding.Security.proxyHeaders[idx])
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 04:54:06 +00:00
|
|
|
|
2023-11-08 18:11:00 +00:00
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) checkConnection(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr)
|
2021-05-11 04:54:06 +00:00
|
|
|
common.Connections.AddClientConnection(ipAddr)
|
|
|
|
defer common.Connections.RemoveClientConnection(ipAddr)
|
|
|
|
|
2023-02-09 08:33:33 +00:00
|
|
|
if err := common.Connections.IsNewConnectionAllowed(ipAddr, common.ProtocolHTTP); err != nil {
|
2022-10-22 09:56:41 +00:00
|
|
|
logger.Log(logger.LevelDebug, common.ProtocolHTTP, "", "connection not allowed from ip %q: %v", ipAddr, err)
|
2023-12-10 15:40:13 +00:00
|
|
|
s.sendForbiddenResponse(w, r, util.NewI18nError(err, util.I18nErrorConnectionForbidden))
|
2021-05-11 04:54:06 +00:00
|
|
|
return
|
|
|
|
}
|
2023-02-09 08:33:33 +00:00
|
|
|
if common.IsBanned(ipAddr, common.ProtocolHTTP) {
|
2023-12-10 15:40:13 +00:00
|
|
|
s.sendForbiddenResponse(w, r, util.NewI18nError(
|
|
|
|
util.NewGenericError("your IP address is blocked"),
|
|
|
|
util.I18nErrorIPForbidden),
|
|
|
|
)
|
2021-05-11 04:54:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if delay, err := common.LimitRate(common.ProtocolHTTP, ipAddr); err != nil {
|
|
|
|
delay += 499999999 * time.Nanosecond
|
|
|
|
w.Header().Set("Retry-After", fmt.Sprintf("%.0f", delay.Seconds()))
|
|
|
|
w.Header().Set("X-Retry-In", delay.String())
|
|
|
|
s.sendTooManyRequestResponse(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) sendTooManyRequestResponse(w http.ResponseWriter, r *http.Request, err error) {
|
|
|
|
if (s.enableWebAdmin || s.enableWebClient) && isWebRequest(r) {
|
|
|
|
r = s.updateContextFromCookie(r)
|
|
|
|
if s.enableWebClient && (isWebClientRequest(r) || !s.enableWebAdmin) {
|
2023-12-10 15:40:13 +00:00
|
|
|
s.renderClientMessagePage(w, r, util.I18nError429Title, http.StatusTooManyRequests,
|
|
|
|
util.NewI18nError(errors.New(http.StatusText(http.StatusTooManyRequests)), util.I18nError429Message), "")
|
2021-05-11 04:54:06 +00:00
|
|
|
return
|
|
|
|
}
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderMessagePage(w, r, util.I18nError429Title, http.StatusTooManyRequests,
|
|
|
|
util.NewI18nError(errors.New(http.StatusText(http.StatusTooManyRequests)), util.I18nError429Message), "")
|
2021-05-11 04:54:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
|
|
|
}
|
|
|
|
|
2023-12-10 15:40:13 +00:00
|
|
|
func (s *httpdServer) sendForbiddenResponse(w http.ResponseWriter, r *http.Request, err error) {
|
2021-05-11 04:54:06 +00:00
|
|
|
if (s.enableWebAdmin || s.enableWebClient) && isWebRequest(r) {
|
|
|
|
r = s.updateContextFromCookie(r)
|
|
|
|
if s.enableWebClient && (isWebClientRequest(r) || !s.enableWebAdmin) {
|
2023-12-10 15:40:13 +00:00
|
|
|
s.renderClientForbiddenPage(w, r, err)
|
2021-05-11 04:54:06 +00:00
|
|
|
return
|
|
|
|
}
|
2024-01-18 18:18:57 +00:00
|
|
|
s.renderForbiddenPage(w, r, err)
|
2021-05-11 04:54:06 +00:00
|
|
|
return
|
|
|
|
}
|
2023-12-10 15:40:13 +00:00
|
|
|
sendAPIResponse(w, r, err, "", http.StatusForbidden)
|
2021-05-11 04:54:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 17:22:27 +00:00
|
|
|
func (s *httpdServer) badHostHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
host := r.Host
|
|
|
|
for _, header := range s.binding.Security.HostsProxyHeaders {
|
|
|
|
if h := r.Header.Get(header); h != "" {
|
|
|
|
host = h
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2023-12-10 15:40:13 +00:00
|
|
|
s.sendForbiddenResponse(w, r, util.NewI18nError(
|
|
|
|
util.NewGenericError(fmt.Sprintf("The host %q is not allowed", host)),
|
|
|
|
util.I18nErrorConnectionForbidden,
|
|
|
|
))
|
2023-02-24 19:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) notFoundHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
|
|
|
if (s.enableWebAdmin || s.enableWebClient) && isWebRequest(r) {
|
|
|
|
r = s.updateContextFromCookie(r)
|
|
|
|
if s.enableWebClient && (isWebClientRequest(r) || !s.enableWebAdmin) {
|
|
|
|
s.renderClientNotFoundPage(w, r, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.renderNotFoundPage(w, r, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sendAPIResponse(w, r, nil, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
2022-02-17 17:22:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:21:15 +00:00
|
|
|
func (s *httpdServer) redirectToWebPath(w http.ResponseWriter, r *http.Request, webPath string) {
|
|
|
|
if dataprovider.HasAdmin() {
|
2022-01-26 19:46:33 +00:00
|
|
|
http.Redirect(w, r, webPath, http.StatusFound)
|
2021-05-14 17:21:15 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if s.enableWebAdmin {
|
|
|
|
http.Redirect(w, r, webAdminSetupPath, http.StatusFound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-08 08:40:08 +00:00
|
|
|
// The StripSlashes causes infinite redirects at the root path if used with http.FileServer.
|
|
|
|
// We also don't strip paths with more than one trailing slash, see #1434
|
|
|
|
func (s *httpdServer) mustStripSlash(r *http.Request) bool {
|
2021-11-21 08:32:51 +00:00
|
|
|
var urlPath string
|
|
|
|
rctx := chi.RouteContext(r.Context())
|
|
|
|
if rctx != nil && rctx.RoutePath != "" {
|
|
|
|
urlPath = rctx.RoutePath
|
|
|
|
} else {
|
|
|
|
urlPath = r.URL.Path
|
|
|
|
}
|
2023-10-08 08:40:08 +00:00
|
|
|
return !strings.HasSuffix(urlPath, "//") && !strings.HasPrefix(urlPath, webOpenAPIPath) &&
|
|
|
|
!strings.HasPrefix(urlPath, webStaticFilesPath) && !strings.HasPrefix(urlPath, acmeChallengeURI)
|
2021-11-21 08:32:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
func (s *httpdServer) initializeRouter() {
|
2023-02-24 19:08:14 +00:00
|
|
|
var hasHTTPSRedirect bool
|
2021-07-01 18:17:40 +00:00
|
|
|
s.tokenAuth = jwtauth.New(jwa.HS256.String(), getSigningKey(s.signingPassphrase), nil)
|
2021-01-17 21:29:08 +00:00
|
|
|
s.router = chi.NewRouter()
|
|
|
|
|
2021-05-11 04:54:06 +00:00
|
|
|
s.router.Use(middleware.RequestID)
|
2023-11-08 18:11:00 +00:00
|
|
|
s.router.Use(s.parseHeaders)
|
2021-05-11 04:54:06 +00:00
|
|
|
s.router.Use(logger.NewStructuredLogger(logger.GetLogger()))
|
2022-01-04 08:48:16 +00:00
|
|
|
s.router.Use(middleware.Recoverer)
|
2023-11-08 18:11:00 +00:00
|
|
|
s.router.Use(s.checkConnection)
|
2022-02-17 17:22:27 +00:00
|
|
|
if s.binding.Security.Enabled {
|
|
|
|
secureMiddleware := secure.New(secure.Options{
|
|
|
|
AllowedHosts: s.binding.Security.AllowedHosts,
|
|
|
|
AllowedHostsAreRegex: s.binding.Security.AllowedHostsAreRegex,
|
|
|
|
HostsProxyHeaders: s.binding.Security.HostsProxyHeaders,
|
|
|
|
SSLProxyHeaders: s.binding.Security.getHTTPSProxyHeaders(),
|
|
|
|
STSSeconds: s.binding.Security.STSSeconds,
|
|
|
|
STSIncludeSubdomains: s.binding.Security.STSIncludeSubdomains,
|
|
|
|
STSPreload: s.binding.Security.STSPreload,
|
|
|
|
ContentTypeNosniff: s.binding.Security.ContentTypeNosniff,
|
|
|
|
ContentSecurityPolicy: s.binding.Security.ContentSecurityPolicy,
|
|
|
|
PermissionsPolicy: s.binding.Security.PermissionsPolicy,
|
|
|
|
CrossOriginOpenerPolicy: s.binding.Security.CrossOriginOpenerPolicy,
|
|
|
|
})
|
|
|
|
secureMiddleware.SetBadHostHandler(http.HandlerFunc(s.badHostHandler))
|
|
|
|
s.router.Use(secureMiddleware.Handler)
|
2023-02-24 19:08:14 +00:00
|
|
|
if s.binding.Security.HTTPSRedirect {
|
|
|
|
s.router.Use(s.binding.Security.redirectHandler)
|
|
|
|
hasHTTPSRedirect = true
|
|
|
|
}
|
2022-02-17 17:22:27 +00:00
|
|
|
}
|
2021-11-13 22:14:50 +00:00
|
|
|
if s.cors.Enabled {
|
|
|
|
c := cors.New(cors.Options{
|
2022-08-02 16:44:34 +00:00
|
|
|
AllowedOrigins: util.RemoveDuplicates(s.cors.AllowedOrigins, true),
|
|
|
|
AllowedMethods: util.RemoveDuplicates(s.cors.AllowedMethods, true),
|
|
|
|
AllowedHeaders: util.RemoveDuplicates(s.cors.AllowedHeaders, true),
|
|
|
|
ExposedHeaders: util.RemoveDuplicates(s.cors.ExposedHeaders, true),
|
|
|
|
MaxAge: s.cors.MaxAge,
|
|
|
|
AllowCredentials: s.cors.AllowCredentials,
|
|
|
|
OptionsPassthrough: s.cors.OptionsPassthrough,
|
|
|
|
OptionsSuccessStatus: s.cors.OptionsSuccessStatus,
|
|
|
|
AllowPrivateNetwork: s.cors.AllowPrivateNetwork,
|
2021-11-13 22:14:50 +00:00
|
|
|
})
|
|
|
|
s.router.Use(c.Handler)
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
s.router.Use(middleware.GetHead)
|
2023-10-08 08:40:08 +00:00
|
|
|
s.router.Use(middleware.Maybe(middleware.StripSlashes, s.mustStripSlash))
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2023-02-24 19:08:14 +00:00
|
|
|
s.router.NotFound(s.notFoundHandler)
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2021-05-11 04:54:06 +00:00
|
|
|
s.router.Get(healthzPath, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
render.PlainText(w, r, "ok")
|
|
|
|
})
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2022-05-13 07:23:43 +00:00
|
|
|
s.router.Get(robotsTxtPath, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
render.PlainText(w, r, "User-agent: *\nDisallow: /")
|
|
|
|
})
|
|
|
|
|
2023-02-24 19:08:14 +00:00
|
|
|
if hasHTTPSRedirect {
|
|
|
|
if p := acme.GetHTTP01WebRoot(); p != "" {
|
2023-09-08 17:55:45 +00:00
|
|
|
serveStaticDir(s.router, acmeChallengeURI, p, true)
|
2023-02-24 19:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 15:27:00 +00:00
|
|
|
if s.enableRESTAPI {
|
2023-02-09 08:33:33 +00:00
|
|
|
// share API available to external users
|
2023-10-20 18:31:17 +00:00
|
|
|
s.router.Get(sharesPath+"/{id}", s.downloadFromShare) //nolint:goconst
|
2022-09-22 15:27:00 +00:00
|
|
|
s.router.Post(sharesPath+"/{id}", s.uploadFilesToShare)
|
|
|
|
s.router.Post(sharesPath+"/{id}/{name}", s.uploadFileToShare)
|
|
|
|
s.router.With(compressor.Handler).Get(sharesPath+"/{id}/dirs", s.readBrowsableShareContents)
|
|
|
|
s.router.Get(sharesPath+"/{id}/files", s.downloadBrowsableSharedFile)
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2022-09-22 15:27:00 +00:00
|
|
|
s.router.Get(tokenPath, s.getToken)
|
|
|
|
s.router.Post(adminPath+"/{username}/forgot-password", forgotAdminPassword)
|
|
|
|
s.router.Post(adminPath+"/{username}/reset-password", resetAdminPassword)
|
|
|
|
s.router.Post(userPath+"/{username}/forgot-password", forgotUserPassword)
|
|
|
|
s.router.Post(userPath+"/{username}/reset-password", resetUserPassword)
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2022-09-22 15:27:00 +00:00
|
|
|
s.router.Group(func(router chi.Router) {
|
2022-09-25 17:48:55 +00:00
|
|
|
router.Use(checkNodeToken(s.tokenAuth))
|
2022-09-22 15:27:00 +00:00
|
|
|
router.Use(checkAPIKeyAuth(s.tokenAuth, dataprovider.APIKeyScopeAdmin))
|
|
|
|
router.Use(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromHeader))
|
|
|
|
router.Use(jwtAuthenticatorAPI)
|
|
|
|
|
|
|
|
router.Get(versionPath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2022-09-22 15:27:00 +00:00
|
|
|
render.JSON(w, r, version.Get())
|
2021-05-11 04:54:06 +00:00
|
|
|
})
|
|
|
|
|
2022-09-22 15:27:00 +00:00
|
|
|
router.With(forbidAPIKeyAuthentication).Get(logoutPath, s.logout)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Get(adminProfilePath, getAdminProfile)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Put(adminProfilePath, updateAdminProfile)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Put(adminPwdPath, changeAdminPassword)
|
|
|
|
// admin TOTP APIs
|
|
|
|
router.With(forbidAPIKeyAuthentication).Get(adminTOTPConfigsPath, getTOTPConfigs)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Post(adminTOTPGeneratePath, generateTOTPSecret)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Post(adminTOTPValidatePath, validateTOTPPasscode)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Post(adminTOTPSavePath, saveTOTPConfig)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Get(admin2FARecoveryCodesPath, getRecoveryCodes)
|
|
|
|
router.With(forbidAPIKeyAuthentication).Post(admin2FARecoveryCodesPath, generateRecoveryCodes)
|
|
|
|
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewServerStatus)).
|
|
|
|
Get(serverStatusPath, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
|
|
|
render.JSON(w, r, getServicesStatus())
|
|
|
|
})
|
|
|
|
|
2022-09-25 17:48:55 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewConnections)).Get(activeConnectionsPath, getActiveConnections)
|
2022-09-22 15:27:00 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminCloseConnections)).
|
|
|
|
Delete(activeConnectionsPath+"/{connectionID}", handleCloseConnection)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminQuotaScans)).Get(quotasBasePath+"/users/scans", getUsersQuotaScans)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminQuotaScans)).Post(quotasBasePath+"/users/{username}/scan", startUserQuotaScan)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminQuotaScans)).Get(quotasBasePath+"/folders/scans", getFoldersQuotaScans)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminQuotaScans)).Post(quotasBasePath+"/folders/{name}/scan", startFolderQuotaScan)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewUsers)).Get(userPath, getUsers)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminAddUsers)).Post(userPath, addUser)
|
2023-10-20 18:31:17 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewUsers)).Get(userPath+"/{username}", getUserByUsername) //nolint:goconst
|
2022-09-22 15:27:00 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers)).Put(userPath+"/{username}", updateUser)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminDeleteUsers)).Delete(userPath+"/{username}", deleteUser)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers)).Put(userPath+"/{username}/2fa/disable", disableUser2FA)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Get(folderPath, getFolders)
|
2023-10-20 18:31:17 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Get(folderPath+"/{name}", getFolderByName) //nolint:goconst
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Post(folderPath, addFolder)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Put(folderPath+"/{name}", updateFolder)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Delete(folderPath+"/{name}", deleteFolder)
|
2022-09-22 15:27:00 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Get(groupPath, getGroups)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Get(groupPath+"/{name}", getGroupByName)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Post(groupPath, addGroup)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Put(groupPath+"/{name}", updateGroup)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Delete(groupPath+"/{name}", deleteGroup)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Get(dumpDataPath, dumpData)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Get(loadDataPath, loadData)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Post(loadDataPath, loadDataFromRequest)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers)).Put(quotasBasePath+"/users/{username}/usage",
|
|
|
|
updateUserQuotaUsage)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers)).Put(quotasBasePath+"/users/{username}/transfer-usage",
|
|
|
|
updateUserTransferQuotaUsage)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers)).Put(quotasBasePath+"/folders/{name}/usage",
|
|
|
|
updateFolderQuotaUsage)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewDefender)).Get(defenderHosts, getDefenderHosts)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewDefender)).Get(defenderHosts+"/{id}", getDefenderHostByID)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageDefender)).Delete(defenderHosts+"/{id}", deleteDefenderHostByID)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Get(adminPath, getAdmins)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Post(adminPath, addAdmin)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Get(adminPath+"/{username}", getAdminByUsername)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Put(adminPath+"/{username}", updateAdmin)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Delete(adminPath+"/{username}", deleteAdmin)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Put(adminPath+"/{username}/2fa/disable", disableAdmin2FA)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminRetentionChecks)).Get(retentionChecksPath, getRetentionChecks)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminRetentionChecks)).Post(retentionBasePath+"/{username}/check",
|
|
|
|
startRetentionCheck)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminMetadataChecks)).Get(metadataChecksPath, getMetadataChecks)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminMetadataChecks)).Post(metadataBasePath+"/{username}/check",
|
|
|
|
startMetadataCheck)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), compressor.Handler).
|
|
|
|
Get(fsEventsPath, searchFsEvents)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), compressor.Handler).
|
|
|
|
Get(providerEventsPath, searchProviderEvents)
|
2023-05-12 16:34:59 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), compressor.Handler).
|
|
|
|
Get(logEventsPath, searchLogEvents)
|
2022-09-22 15:27:00 +00:00
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkPerm(dataprovider.PermAdminManageAPIKeys)).
|
|
|
|
Get(apiKeysPath, getAPIKeys)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkPerm(dataprovider.PermAdminManageAPIKeys)).
|
|
|
|
Post(apiKeysPath, addAPIKey)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkPerm(dataprovider.PermAdminManageAPIKeys)).
|
|
|
|
Get(apiKeysPath+"/{id}", getAPIKeyByID)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkPerm(dataprovider.PermAdminManageAPIKeys)).
|
|
|
|
Put(apiKeysPath+"/{id}", updateAPIKey)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkPerm(dataprovider.PermAdminManageAPIKeys)).
|
|
|
|
Delete(apiKeysPath+"/{id}", deleteAPIKey)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Get(eventActionsPath, getEventActions)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Get(eventActionsPath+"/{name}", getEventActionByName)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(eventActionsPath, addEventAction)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Put(eventActionsPath+"/{name}", updateEventAction)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Delete(eventActionsPath+"/{name}", deleteEventAction)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Get(eventRulesPath, getEventRules)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Get(eventRulesPath+"/{name}", getEventRuleByName)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(eventRulesPath, addEventRule)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Put(eventRulesPath+"/{name}", updateEventRule)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Delete(eventRulesPath+"/{name}", deleteEventRule)
|
2023-01-21 14:41:24 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(eventRulesPath+"/run/{name}", runOnDemandRule)
|
2022-11-16 18:04:50 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Get(rolesPath, getRoles)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Post(rolesPath, addRole)
|
2023-02-09 08:33:33 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Get(rolesPath+"/{name}", getRoleByName)
|
2022-11-16 18:04:50 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Put(rolesPath+"/{name}", updateRole)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Delete(rolesPath+"/{name}", deleteRole)
|
2023-10-20 18:31:17 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists), compressor.Handler).Get(ipListsPath+"/{type}", getIPListEntries) //nolint:goconst
|
2023-02-09 08:33:33 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Post(ipListsPath+"/{type}", addIPListEntry)
|
2023-10-20 18:31:17 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Get(ipListsPath+"/{type}/{ipornet}", getIPListEntry) //nolint:goconst
|
2023-02-09 08:33:33 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Put(ipListsPath+"/{type}/{ipornet}", updateIPListEntry)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Delete(ipListsPath+"/{type}/{ipornet}", deleteIPListEntry)
|
2022-09-22 15:27:00 +00:00
|
|
|
})
|
2021-05-11 04:54:06 +00:00
|
|
|
|
2022-09-22 15:27:00 +00:00
|
|
|
s.router.Get(userTokenPath, s.getUserToken)
|
2021-06-05 14:07:09 +00:00
|
|
|
|
2021-11-21 08:32:51 +00:00
|
|
|
s.router.Group(func(router chi.Router) {
|
2022-09-22 15:27:00 +00:00
|
|
|
router.Use(checkAPIKeyAuth(s.tokenAuth, dataprovider.APIKeyScopeUser))
|
|
|
|
router.Use(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromHeader))
|
|
|
|
router.Use(jwtAuthenticatorAPIUser)
|
|
|
|
|
|
|
|
router.With(forbidAPIKeyAuthentication).Get(userLogoutPath, s.logout)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)).
|
|
|
|
Put(userPwdPath, changeUserPassword)
|
2022-09-22 15:27:00 +00:00
|
|
|
router.With(forbidAPIKeyAuthentication).Get(userProfilePath, getUserProfile)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkAuthRequirements).Put(userProfilePath, updateUserProfile)
|
2022-09-22 15:27:00 +00:00
|
|
|
// user TOTP APIs
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientMFADisabled)).
|
|
|
|
Get(userTOTPConfigsPath, getTOTPConfigs)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientMFADisabled)).
|
|
|
|
Post(userTOTPGeneratePath, generateTOTPSecret)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientMFADisabled)).
|
|
|
|
Post(userTOTPValidatePath, validateTOTPPasscode)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientMFADisabled)).
|
|
|
|
Post(userTOTPSavePath, saveTOTPConfig)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientMFADisabled)).
|
|
|
|
Get(user2FARecoveryCodesPath, getRecoveryCodes)
|
|
|
|
router.With(forbidAPIKeyAuthentication, s.checkHTTPUserPerm(sdk.WebClientMFADisabled)).
|
|
|
|
Post(user2FARecoveryCodesPath, generateRecoveryCodes)
|
|
|
|
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, compressor.Handler).Get(userDirsPath, readUserFolder)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Post(userDirsPath, createUserDir)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-12-30 18:30:16 +00:00
|
|
|
Patch(userDirsPath, renameUserFsEntry)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Delete(userDirsPath, deleteUserDir)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements).Get(userFilesPath, getUserFile)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Post(userFilesPath, uploadUserFiles)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-12-30 18:30:16 +00:00
|
|
|
Patch(userFilesPath, renameUserFsEntry)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Delete(userFilesPath, deleteUserFile)
|
2022-12-30 18:30:16 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
|
|
|
Post(userFileActionsPath+"/move", renameUserFsEntry)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
|
|
|
Post(userFileActionsPath+"/copy", copyUserFsEntry)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements).Post(userStreamZipPath, getUserFilesAsZipStream)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Get(userSharesPath, getShares)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Post(userSharesPath, addShare)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Get(userSharesPath+"/{id}", getShareByID)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Put(userSharesPath+"/{id}", updateShare)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Delete(userSharesPath+"/{id}", deleteShare)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Post(userUploadFilePath, uploadUserFile)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled)).
|
2022-09-22 15:27:00 +00:00
|
|
|
Patch(userFilesDirsMetadataPath, setFileDirMetadata)
|
2021-11-21 08:32:51 +00:00
|
|
|
})
|
2022-09-22 15:27:00 +00:00
|
|
|
|
|
|
|
if s.renderOpenAPI {
|
|
|
|
s.router.Group(func(router chi.Router) {
|
|
|
|
router.Use(compressor.Handler)
|
2023-09-08 17:55:45 +00:00
|
|
|
serveStaticDir(router, webOpenAPIPath, s.openAPIPath, false)
|
2022-09-22 15:27:00 +00:00
|
|
|
})
|
|
|
|
}
|
2021-11-21 08:32:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 04:54:06 +00:00
|
|
|
if s.enableWebAdmin || s.enableWebClient {
|
|
|
|
s.router.Group(func(router chi.Router) {
|
|
|
|
router.Use(compressor.Handler)
|
2023-09-08 17:55:45 +00:00
|
|
|
serveStaticDir(router, webStaticFilesPath, s.staticFilesPath, true)
|
2021-05-11 04:54:06 +00:00
|
|
|
})
|
2022-02-13 13:30:20 +00:00
|
|
|
if s.binding.OIDC.isEnabled() {
|
|
|
|
s.router.Get(webOIDCRedirectPath, s.handleOIDCRedirect)
|
|
|
|
}
|
2021-05-06 19:35:43 +00:00
|
|
|
if s.enableWebClient {
|
2021-05-11 04:54:06 +00:00
|
|
|
s.router.Get(webRootPath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2021-05-14 17:21:15 +00:00
|
|
|
s.redirectToWebPath(w, r, webClientLoginPath)
|
2021-05-06 19:35:43 +00:00
|
|
|
})
|
2021-05-11 04:54:06 +00:00
|
|
|
s.router.Get(webBasePath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2021-05-14 17:21:15 +00:00
|
|
|
s.redirectToWebPath(w, r, webClientLoginPath)
|
2021-01-17 21:29:08 +00:00
|
|
|
})
|
2021-05-11 04:54:06 +00:00
|
|
|
} else {
|
|
|
|
s.router.Get(webRootPath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2022-02-13 13:30:20 +00:00
|
|
|
s.redirectToWebPath(w, r, webAdminLoginPath)
|
2021-05-06 19:35:43 +00:00
|
|
|
})
|
2021-05-11 04:54:06 +00:00
|
|
|
s.router.Get(webBasePath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2022-02-13 13:30:20 +00:00
|
|
|
s.redirectToWebPath(w, r, webAdminLoginPath)
|
2021-01-17 21:29:08 +00:00
|
|
|
})
|
|
|
|
}
|
2021-05-11 04:54:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 13:30:20 +00:00
|
|
|
s.setupWebClientRoutes()
|
|
|
|
s.setupWebAdminRoutes()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpdServer) setupWebClientRoutes() {
|
2021-05-11 04:54:06 +00:00
|
|
|
if s.enableWebClient {
|
|
|
|
s.router.Get(webBaseClientPath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
2022-01-26 19:46:33 +00:00
|
|
|
http.Redirect(w, r, webClientLoginPath, http.StatusFound)
|
2021-05-11 04:54:06 +00:00
|
|
|
})
|
2021-07-27 16:43:00 +00:00
|
|
|
s.router.Get(webClientLoginPath, s.handleClientWebLogin)
|
2022-07-22 18:55:33 +00:00
|
|
|
if s.binding.OIDC.isEnabled() && !s.binding.isWebClientOIDCLoginDisabled() {
|
2022-02-13 13:30:20 +00:00
|
|
|
s.router.Get(webClientOIDCLoginPath, s.handleWebClientOIDCLogin)
|
|
|
|
}
|
2022-07-19 20:25:00 +00:00
|
|
|
if !s.binding.isWebClientLoginFormDisabled() {
|
|
|
|
s.router.Post(webClientLoginPath, s.handleWebClientLoginPost)
|
|
|
|
s.router.Get(webClientForgotPwdPath, s.handleWebClientForgotPwd)
|
|
|
|
s.router.Post(webClientForgotPwdPath, s.handleWebClientForgotPwdPost)
|
|
|
|
s.router.Get(webClientResetPwdPath, s.handleWebClientPasswordReset)
|
|
|
|
s.router.Post(webClientResetPwdPath, s.handleWebClientPasswordResetPost)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebClientPartial)).
|
|
|
|
Get(webClientTwoFactorPath, s.handleWebClientTwoFactor)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebClientPartial)).
|
|
|
|
Post(webClientTwoFactorPath, s.handleWebClientTwoFactorPost)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebClientPartial)).
|
|
|
|
Get(webClientTwoFactorRecoveryPath, s.handleWebClientTwoFactorRecovery)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebClientPartial)).
|
|
|
|
Post(webClientTwoFactorRecoveryPath, s.handleWebClientTwoFactorRecoveryPost)
|
|
|
|
}
|
2023-02-09 08:33:33 +00:00
|
|
|
// share routes available to external users
|
2023-02-12 07:29:53 +00:00
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}/login", s.handleClientShareLoginGet)
|
|
|
|
s.router.Post(webClientPubSharesPath+"/{id}/login", s.handleClientShareLoginPost)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}", s.downloadFromShare)
|
2023-11-04 09:54:52 +00:00
|
|
|
s.router.Post(webClientPubSharesPath+"/{id}/partial", s.handleClientSharePartialDownload)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}/browse", s.handleShareGetFiles)
|
2023-12-28 17:43:07 +00:00
|
|
|
s.router.Post(webClientPubSharesPath+"/{id}/browse/exist", s.handleClientShareCheckExist)
|
2023-11-17 18:10:03 +00:00
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}/download", s.handleClientSharedFile)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}/upload", s.handleClientUploadToShare)
|
|
|
|
s.router.With(compressor.Handler).Get(webClientPubSharesPath+"/{id}/dirs", s.handleShareGetDirContents)
|
|
|
|
s.router.Post(webClientPubSharesPath+"/{id}", s.uploadFilesToShare)
|
|
|
|
s.router.Post(webClientPubSharesPath+"/{id}/{name}", s.uploadFileToShare)
|
2023-11-04 09:54:52 +00:00
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}/viewpdf", s.handleShareViewPDF)
|
|
|
|
s.router.Get(webClientPubSharesPath+"/{id}/getpdf", s.handleShareGetPDF)
|
2021-05-11 04:54:06 +00:00
|
|
|
|
|
|
|
s.router.Group(func(router chi.Router) {
|
2022-02-13 13:30:20 +00:00
|
|
|
if s.binding.OIDC.isEnabled() {
|
|
|
|
router.Use(s.oidcTokenAuthenticator(tokenAudienceWebClient))
|
|
|
|
}
|
|
|
|
router.Use(jwtauth.Verify(s.tokenAuth, tokenFromContext, jwtauth.TokenFromCookie))
|
2021-05-11 04:54:06 +00:00
|
|
|
router.Use(jwtAuthenticatorWebClient)
|
|
|
|
|
2022-02-13 13:30:20 +00:00
|
|
|
router.Get(webClientLogoutPath, s.handleWebClientLogout)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientFilesPath, s.handleClientGetFiles)
|
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientViewPDFPath, s.handleClientViewPDF)
|
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientGetPDFPath, s.handleClientGetPDF)
|
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie, verifyCSRFHeader).Get(webClientFilePath, getUserFile)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
2021-12-08 18:25:22 +00:00
|
|
|
Post(webClientFilePath, uploadUserFile)
|
2023-12-28 17:43:07 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
|
|
|
Post(webClientExistPath, s.handleClientCheckExist)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientEditFilePath, s.handleClientEditFile)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
2021-07-26 18:55:49 +00:00
|
|
|
Delete(webClientFilesPath, deleteUserFile)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, compressor.Handler, s.refreshCookie).
|
2022-03-06 15:57:13 +00:00
|
|
|
Get(webClientDirsPath, s.handleClientGetDirContents)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
2021-07-26 18:55:49 +00:00
|
|
|
Post(webClientDirsPath, createUserDir)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
2021-07-26 18:55:49 +00:00
|
|
|
Delete(webClientDirsPath, deleteUserDir)
|
2022-12-30 18:30:16 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
|
|
|
Post(webClientFileActionsPath+"/move", renameUserFsEntry)
|
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientWriteDisabled), verifyCSRFHeader).
|
|
|
|
Post(webClientFileActionsPath+"/copy", copyUserFsEntry)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).
|
2023-11-04 09:54:52 +00:00
|
|
|
Post(webClientDownloadZipPath, s.handleWebClientDownloadZip)
|
2023-12-28 17:43:07 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientPingPath, handlePingRequest)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientProfilePath,
|
2022-08-01 17:41:18 +00:00
|
|
|
s.handleClientGetProfile)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements).Post(webClientProfilePath, s.handleWebClientProfilePost)
|
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webChangeClientPwdPath, s.handleWebClientChangePwd)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientPasswordChangeDisabled)).
|
2022-02-13 13:30:20 +00:00
|
|
|
Post(webChangeClientPwdPath, s.handleWebClientChangePwdPost)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), s.refreshCookie).
|
|
|
|
Get(webClientMFAPath, s.handleWebClientMFA)
|
2023-11-18 19:06:31 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), s.refreshCookie).
|
|
|
|
Get(webClientMFAPath+"/qrcode", getQRCode)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), verifyCSRFHeader).
|
2021-09-04 10:11:04 +00:00
|
|
|
Post(webClientTOTPGeneratePath, generateTOTPSecret)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), verifyCSRFHeader).
|
2021-09-04 10:11:04 +00:00
|
|
|
Post(webClientTOTPValidatePath, validateTOTPPasscode)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), verifyCSRFHeader).
|
2021-09-04 10:11:04 +00:00
|
|
|
Post(webClientTOTPSavePath, saveTOTPConfig)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), verifyCSRFHeader, s.refreshCookie).
|
2021-09-04 10:11:04 +00:00
|
|
|
Get(webClientRecoveryCodesPath, getRecoveryCodes)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkHTTPUserPerm(sdk.WebClientMFADisabled), verifyCSRFHeader).
|
2021-09-04 10:11:04 +00:00
|
|
|
Post(webClientRecoveryCodesPath, generateRecoveryCodes)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled), s.refreshCookie).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webClientSharesPath, s.handleClientGetShares)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled), s.refreshCookie).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webClientSharePath, s.handleClientAddShareGet)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-03-19 20:44:27 +00:00
|
|
|
Post(webClientSharePath, s.handleClientAddSharePost)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled), s.refreshCookie).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webClientSharePath+"/{id}", s.handleClientUpdateShareGet)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled)).
|
2022-03-19 20:44:27 +00:00
|
|
|
Post(webClientSharePath+"/{id}", s.handleClientUpdateSharePost)
|
2022-12-11 16:15:34 +00:00
|
|
|
router.With(s.checkAuthRequirements, s.checkHTTPUserPerm(sdk.WebClientSharesDisabled), verifyCSRFHeader).
|
2021-11-06 13:13:20 +00:00
|
|
|
Delete(webClientSharePath+"/{id}", deleteShare)
|
2021-05-11 04:54:06 +00:00
|
|
|
})
|
|
|
|
}
|
2022-02-13 13:30:20 +00:00
|
|
|
}
|
2021-05-11 04:54:06 +00:00
|
|
|
|
2022-02-13 13:30:20 +00:00
|
|
|
func (s *httpdServer) setupWebAdminRoutes() {
|
2021-05-11 04:54:06 +00:00
|
|
|
if s.enableWebAdmin {
|
|
|
|
s.router.Get(webBaseAdminPath, func(w http.ResponseWriter, r *http.Request) {
|
2021-08-17 16:08:32 +00:00
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxLoginBodySize)
|
2022-02-13 13:30:20 +00:00
|
|
|
s.redirectToWebPath(w, r, webAdminLoginPath)
|
2021-05-11 04:54:06 +00:00
|
|
|
})
|
2022-02-13 13:30:20 +00:00
|
|
|
s.router.Get(webAdminLoginPath, s.handleWebAdminLogin)
|
2022-07-22 18:55:33 +00:00
|
|
|
if s.binding.OIDC.hasRoles() && !s.binding.isWebAdminOIDCLoginDisabled() {
|
2022-02-13 13:30:20 +00:00
|
|
|
s.router.Get(webAdminOIDCLoginPath, s.handleWebAdminOIDCLogin)
|
|
|
|
}
|
2023-06-03 14:17:32 +00:00
|
|
|
s.router.Get(webOAuth2RedirectPath, s.handleOAuth2TokenRedirect)
|
2022-03-19 20:44:27 +00:00
|
|
|
s.router.Get(webAdminSetupPath, s.handleWebAdminSetupGet)
|
2021-05-16 19:36:57 +00:00
|
|
|
s.router.Post(webAdminSetupPath, s.handleWebAdminSetupPost)
|
2022-07-19 20:25:00 +00:00
|
|
|
if !s.binding.isWebAdminLoginFormDisabled() {
|
|
|
|
s.router.Post(webAdminLoginPath, s.handleWebAdminLoginPost)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebAdminPartial)).
|
|
|
|
Get(webAdminTwoFactorPath, s.handleWebAdminTwoFactor)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebAdminPartial)).
|
|
|
|
Post(webAdminTwoFactorPath, s.handleWebAdminTwoFactorPost)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebAdminPartial)).
|
|
|
|
Get(webAdminTwoFactorRecoveryPath, s.handleWebAdminTwoFactorRecovery)
|
|
|
|
s.router.With(jwtauth.Verify(s.tokenAuth, jwtauth.TokenFromCookie),
|
|
|
|
s.jwtAuthenticatorPartial(tokenAudienceWebAdminPartial)).
|
|
|
|
Post(webAdminTwoFactorRecoveryPath, s.handleWebAdminTwoFactorRecoveryPost)
|
|
|
|
s.router.Get(webAdminForgotPwdPath, s.handleWebAdminForgotPwd)
|
|
|
|
s.router.Post(webAdminForgotPwdPath, s.handleWebAdminForgotPwdPost)
|
|
|
|
s.router.Get(webAdminResetPwdPath, s.handleWebAdminPasswordReset)
|
|
|
|
s.router.Post(webAdminResetPwdPath, s.handleWebAdminPasswordResetPost)
|
|
|
|
}
|
2021-05-11 04:54:06 +00:00
|
|
|
|
|
|
|
s.router.Group(func(router chi.Router) {
|
2022-02-13 13:30:20 +00:00
|
|
|
if s.binding.OIDC.isEnabled() {
|
|
|
|
router.Use(s.oidcTokenAuthenticator(tokenAudienceWebAdmin))
|
|
|
|
}
|
|
|
|
router.Use(jwtauth.Verify(s.tokenAuth, tokenFromContext, jwtauth.TokenFromCookie))
|
2021-05-11 04:54:06 +00:00
|
|
|
router.Use(jwtAuthenticatorWebAdmin)
|
|
|
|
|
2022-02-13 13:30:20 +00:00
|
|
|
router.Get(webLogoutPath, s.handleWebAdminLogout)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.refreshCookie, s.requireBuiltinLogin).Get(webAdminProfilePath, s.handleWebAdminProfile)
|
|
|
|
router.With(s.requireBuiltinLogin).Post(webAdminProfilePath, s.handleWebAdminProfilePost)
|
|
|
|
router.With(s.refreshCookie, s.requireBuiltinLogin).Get(webChangeAdminPwdPath, s.handleWebAdminChangePwd)
|
|
|
|
router.With(s.requireBuiltinLogin).Post(webChangeAdminPwdPath, s.handleWebAdminChangePwdPost)
|
|
|
|
|
|
|
|
router.With(s.refreshCookie, s.requireBuiltinLogin).Get(webAdminMFAPath, s.handleWebAdminMFA)
|
2023-11-18 19:06:31 +00:00
|
|
|
router.With(s.refreshCookie, s.requireBuiltinLogin).Get(webAdminMFAPath+"/qrcode", getQRCode)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(verifyCSRFHeader, s.requireBuiltinLogin).Post(webAdminTOTPGeneratePath, generateTOTPSecret)
|
|
|
|
router.With(verifyCSRFHeader, s.requireBuiltinLogin).Post(webAdminTOTPValidatePath, validateTOTPPasscode)
|
|
|
|
router.With(verifyCSRFHeader, s.requireBuiltinLogin).Post(webAdminTOTPSavePath, saveTOTPConfig)
|
2022-07-11 06:17:36 +00:00
|
|
|
router.With(verifyCSRFHeader, s.requireBuiltinLogin, s.refreshCookie).Get(webAdminRecoveryCodesPath,
|
|
|
|
getRecoveryCodes)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(verifyCSRFHeader, s.requireBuiltinLogin).Post(webAdminRecoveryCodesPath, generateRecoveryCodes)
|
|
|
|
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewUsers), s.refreshCookie).
|
|
|
|
Get(webUsersPath, s.handleGetWebUsers)
|
2024-01-14 15:59:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewUsers), compressor.Handler, s.refreshCookie).
|
2024-01-14 20:36:23 +00:00
|
|
|
Get(webUsersPath+jsonAPISuffix, getAllUsers)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminAddUsers), s.refreshCookie).
|
|
|
|
Get(webUserPath, s.handleWebAddUserGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers), s.refreshCookie).
|
|
|
|
Get(webUserPath+"/{username}", s.handleWebUpdateUserGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminAddUsers)).Post(webUserPath, s.handleWebAddUserPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminChangeUsers)).Post(webUserPath+"/{username}",
|
|
|
|
s.handleWebUpdateUserPost)
|
2022-04-25 13:49:11 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups), s.refreshCookie).
|
|
|
|
Get(webGroupsPath, s.handleWebGetGroups)
|
2024-01-14 15:59:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups), compressor.Handler, s.refreshCookie).
|
2024-01-14 20:36:23 +00:00
|
|
|
Get(webGroupsPath+jsonAPISuffix, getAllGroups)
|
2022-04-25 13:49:11 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups), s.refreshCookie).
|
|
|
|
Get(webGroupPath, s.handleWebAddGroupGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Post(webGroupPath, s.handleWebAddGroupPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups), s.refreshCookie).
|
|
|
|
Get(webGroupPath+"/{name}", s.handleWebUpdateGroupGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups)).Post(webGroupPath+"/{name}",
|
|
|
|
s.handleWebUpdateGroupPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageGroups), verifyCSRFHeader).
|
|
|
|
Delete(webGroupPath+"/{name}", deleteGroup)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewConnections), s.refreshCookie).
|
|
|
|
Get(webConnectionsPath, s.handleWebGetConnections)
|
2024-01-20 14:35:05 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewConnections), s.refreshCookie).
|
|
|
|
Get(webConnectionsPath+jsonAPISuffix, getActiveConnections)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders), s.refreshCookie).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webFoldersPath, s.handleWebGetFolders)
|
2024-01-14 15:59:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders), compressor.Handler, s.refreshCookie).
|
2024-01-14 20:36:23 +00:00
|
|
|
Get(webFoldersPath+jsonAPISuffix, getAllFolders)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders), s.refreshCookie).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webFolderPath, s.handleWebAddFolderGet)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Post(webFolderPath, s.handleWebAddFolderPost)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewServerStatus), s.refreshCookie).
|
|
|
|
Get(webStatusPath, s.handleWebGetStatus)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins), s.refreshCookie).
|
|
|
|
Get(webAdminsPath, s.handleGetWebAdmins)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins), s.refreshCookie).
|
|
|
|
Get(webAdminPath, s.handleWebAddAdminGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins), s.refreshCookie).
|
|
|
|
Get(webAdminPath+"/{username}", s.handleWebUpdateAdminGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Post(webAdminPath, s.handleWebAddAdminPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins)).Post(webAdminPath+"/{username}",
|
|
|
|
s.handleWebUpdateAdminPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageAdmins), verifyCSRFHeader).
|
2021-05-11 04:54:06 +00:00
|
|
|
Delete(webAdminPath+"/{username}", deleteAdmin)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminCloseConnections), verifyCSRFHeader).
|
2021-05-11 04:54:06 +00:00
|
|
|
Delete(webConnectionsPath+"/{connectionID}", handleCloseConnection)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders), s.refreshCookie).
|
2022-03-19 20:44:27 +00:00
|
|
|
Get(webFolderPath+"/{name}", s.handleWebUpdateFolderGet)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders)).Post(webFolderPath+"/{name}",
|
2022-03-19 20:44:27 +00:00
|
|
|
s.handleWebUpdateFolderPost)
|
2023-07-23 16:48:49 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageFolders), verifyCSRFHeader).
|
2021-05-11 04:54:06 +00:00
|
|
|
Delete(webFolderPath+"/{name}", deleteFolder)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminQuotaScans), verifyCSRFHeader).
|
2021-06-07 19:52:43 +00:00
|
|
|
Post(webScanVFolderPath+"/{name}", startFolderQuotaScan)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminDeleteUsers), verifyCSRFHeader).
|
2021-05-11 04:54:06 +00:00
|
|
|
Delete(webUserPath+"/{username}", deleteUser)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminQuotaScans), verifyCSRFHeader).
|
2021-06-07 19:52:43 +00:00
|
|
|
Post(webQuotaScanPath+"/{username}", startUserQuotaScan)
|
2022-03-19 20:44:27 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Get(webMaintenancePath, s.handleWebMaintenance)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Get(webBackupPath, dumpData)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Post(webRestorePath, s.handleWebRestore)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem), s.refreshCookie).
|
|
|
|
Get(webTemplateUser, s.handleWebTemplateUserGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Post(webTemplateUser, s.handleWebTemplateUserPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem), s.refreshCookie).
|
|
|
|
Get(webTemplateFolder, s.handleWebTemplateFolderGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Post(webTemplateFolder, s.handleWebTemplateFolderPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewDefender)).Get(webDefenderPath, s.handleWebDefenderPage)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewDefender)).Get(webDefenderHostsPath, getDefenderHosts)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageDefender)).Delete(webDefenderHostsPath+"/{id}",
|
2021-08-17 16:08:32 +00:00
|
|
|
deleteDefenderHostByID)
|
2022-07-11 06:17:36 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), s.refreshCookie).
|
|
|
|
Get(webAdminEventActionsPath, s.handleWebGetEventActions)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), s.refreshCookie).
|
|
|
|
Get(webAdminEventActionPath, s.handleWebAddEventActionGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(webAdminEventActionPath,
|
|
|
|
s.handleWebAddEventActionPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), s.refreshCookie).
|
|
|
|
Get(webAdminEventActionPath+"/{name}", s.handleWebUpdateEventActionGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(webAdminEventActionPath+"/{name}",
|
|
|
|
s.handleWebUpdateEventActionPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), verifyCSRFHeader).
|
|
|
|
Delete(webAdminEventActionPath+"/{name}", deleteEventAction)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), s.refreshCookie).
|
|
|
|
Get(webAdminEventRulesPath, s.handleWebGetEventRules)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), s.refreshCookie).
|
|
|
|
Get(webAdminEventRulePath, s.handleWebAddEventRuleGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(webAdminEventRulePath,
|
|
|
|
s.handleWebAddEventRulePost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), s.refreshCookie).
|
|
|
|
Get(webAdminEventRulePath+"/{name}", s.handleWebUpdateEventRuleGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules)).Post(webAdminEventRulePath+"/{name}",
|
|
|
|
s.handleWebUpdateEventRulePost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), verifyCSRFHeader).
|
|
|
|
Delete(webAdminEventRulePath+"/{name}", deleteEventRule)
|
2023-01-21 14:41:24 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageEventRules), verifyCSRFHeader).
|
|
|
|
Post(webAdminEventRulePath+"/run/{name}", runOnDemandRule)
|
2022-11-16 18:04:50 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles), s.refreshCookie).
|
|
|
|
Get(webAdminRolesPath, s.handleWebGetRoles)
|
2024-01-21 15:49:04 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles), compressor.Handler, s.refreshCookie).
|
|
|
|
Get(webAdminRolesPath+jsonAPISuffix, getAllRoles)
|
2022-11-16 18:04:50 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles), s.refreshCookie).
|
|
|
|
Get(webAdminRolePath, s.handleWebAddRoleGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Post(webAdminRolePath, s.handleWebAddRolePost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles), s.refreshCookie).
|
|
|
|
Get(webAdminRolePath+"/{name}", s.handleWebUpdateRoleGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles)).Post(webAdminRolePath+"/{name}",
|
|
|
|
s.handleWebUpdateRolePost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageRoles), verifyCSRFHeader).
|
|
|
|
Delete(webAdminRolePath+"/{name}", deleteRole)
|
2022-12-07 17:47:38 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), s.refreshCookie).Get(webEventsPath,
|
|
|
|
s.handleWebGetEvents)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), compressor.Handler, s.refreshCookie).
|
|
|
|
Get(webEventsFsSearchPath, searchFsEvents)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), compressor.Handler, s.refreshCookie).
|
|
|
|
Get(webEventsProviderSearchPath, searchProviderEvents)
|
2023-05-12 16:34:59 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminViewEvents), compressor.Handler, s.refreshCookie).
|
|
|
|
Get(webEventsLogSearchPath, searchLogEvents)
|
2023-02-09 08:33:33 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Get(webIPListsPath, s.handleWebIPListsPage)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists), compressor.Handler, s.refreshCookie).
|
|
|
|
Get(webIPListsPath+"/{type}", getIPListEntries)
|
2023-02-19 18:03:45 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists), s.refreshCookie).Get(webIPListPath+"/{type}",
|
2023-02-09 08:33:33 +00:00
|
|
|
s.handleWebAddIPListEntryGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Post(webIPListPath+"/{type}",
|
|
|
|
s.handleWebAddIPListEntryPost)
|
2023-02-19 18:03:45 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists), s.refreshCookie).Get(webIPListPath+"/{type}/{ipornet}",
|
2023-02-09 08:33:33 +00:00
|
|
|
s.handleWebUpdateIPListEntryGet)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists)).Post(webIPListPath+"/{type}/{ipornet}",
|
|
|
|
s.handleWebUpdateIPListEntryPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageIPLists), verifyCSRFHeader).
|
|
|
|
Delete(webIPListPath+"/{type}/{ipornet}", deleteIPListEntry)
|
2023-02-19 18:03:45 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem), s.refreshCookie).Get(webConfigsPath, s.handleWebConfigs)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem)).Post(webConfigsPath, s.handleWebConfigsPost)
|
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem), verifyCSRFHeader, s.refreshCookie).
|
|
|
|
Post(webConfigsPath+"/smtp/test", testSMTPConfig)
|
2023-06-03 14:17:32 +00:00
|
|
|
router.With(s.checkPerm(dataprovider.PermAdminManageSystem), verifyCSRFHeader, s.refreshCookie).
|
|
|
|
Post(webOAuth2TokenPath, handleSMTPOAuth2TokenRequestPost)
|
2021-05-11 04:54:06 +00:00
|
|
|
})
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|