WebClient: add a ping URL
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
789d61f170
commit
6295be786f
6 changed files with 35 additions and 5 deletions
|
@ -165,6 +165,7 @@ const (
|
|||
webClientDirsPathDefault = "/web/client/dirs"
|
||||
webClientDownloadZipPathDefault = "/web/client/downloadzip"
|
||||
webClientProfilePathDefault = "/web/client/profile"
|
||||
webClientPingPathDefault = "/web/client/ping"
|
||||
webClientMFAPathDefault = "/web/client/mfa"
|
||||
webClientTOTPGeneratePathDefault = "/web/client/totp/generate"
|
||||
webClientTOTPValidatePathDefault = "/web/client/totp/validate"
|
||||
|
@ -264,6 +265,7 @@ var (
|
|||
webClientDirsPath string
|
||||
webClientDownloadZipPath string
|
||||
webClientProfilePath string
|
||||
webClientPingPath string
|
||||
webChangeClientPwdPath string
|
||||
webClientMFAPath string
|
||||
webClientTOTPGeneratePath string
|
||||
|
@ -1083,6 +1085,7 @@ func updateWebClientURLs(baseURL string) {
|
|||
webClientDirsPath = path.Join(baseURL, webClientDirsPathDefault)
|
||||
webClientDownloadZipPath = path.Join(baseURL, webClientDownloadZipPathDefault)
|
||||
webClientProfilePath = path.Join(baseURL, webClientProfilePathDefault)
|
||||
webClientPingPath = path.Join(baseURL, webClientPingPathDefault)
|
||||
webChangeClientPwdPath = path.Join(baseURL, webChangeClientPwdPathDefault)
|
||||
webClientLogoutPath = path.Join(baseURL, webClientLogoutPathDefault)
|
||||
webClientMFAPath = path.Join(baseURL, webClientMFAPathDefault)
|
||||
|
|
|
@ -180,6 +180,7 @@ const (
|
|||
webClientDownloadZipPath = "/web/client/downloadzip"
|
||||
webChangeClientPwdPath = "/web/client/changepwd"
|
||||
webClientProfilePath = "/web/client/profile"
|
||||
webClientPingPath = "/web/client/ping"
|
||||
webClientTwoFactorPath = "/web/client/twofactor"
|
||||
webClientTwoFactorRecoveryPath = "/web/client/twofactor-recovery"
|
||||
webClientLogoutPath = "/web/client/logout"
|
||||
|
@ -12247,12 +12248,23 @@ func TestWebClientLoginMock(t *testing.T) {
|
|||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
req, _ = http.NewRequest(http.MethodGet, webClientPingPath, nil)
|
||||
req.RemoteAddr = defaultRemoteAddr
|
||||
setBearerForReq(req, webToken)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
// now try to render client pages
|
||||
req, _ = http.NewRequest(http.MethodGet, webClientProfilePath, nil)
|
||||
req.RemoteAddr = defaultRemoteAddr
|
||||
setJWTCookieForReq(req, webToken)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusOK, rr)
|
||||
req, _ = http.NewRequest(http.MethodGet, webClientPingPath, nil)
|
||||
req.RemoteAddr = defaultRemoteAddr
|
||||
setJWTCookieForReq(req, webToken)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusOK, rr)
|
||||
req, _ = http.NewRequest(http.MethodGet, webClientFilesPath, nil)
|
||||
req.RemoteAddr = defaultRemoteAddr
|
||||
setJWTCookieForReq(req, webToken)
|
||||
|
@ -12269,7 +12281,12 @@ func TestWebClientLoginMock(t *testing.T) {
|
|||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
|
||||
req, _ = http.NewRequest(http.MethodGet, webClientPingPath, nil)
|
||||
req.RemoteAddr = defaultRemoteAddr
|
||||
setJWTCookieForReq(req, webToken)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
// get a new token and use it after removing the user
|
||||
webToken, err = getJWTWebClientTokenFromTestServer(defaultUsername, defaultPassword)
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -1550,6 +1550,7 @@ func (s *httpdServer) setupWebClientRoutes() {
|
|||
Post(webClientFileActionsPath+"/copy", copyUserFsEntry)
|
||||
router.With(s.checkAuthRequirements, s.refreshCookie).
|
||||
Post(webClientDownloadZipPath, s.handleWebClientDownloadZip)
|
||||
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientPingPath, s.handleClientPing)
|
||||
router.With(s.checkAuthRequirements, s.refreshCookie).Get(webClientProfilePath,
|
||||
s.handleClientGetProfile)
|
||||
router.With(s.checkAuthRequirements).Post(webClientProfilePath, s.handleWebClientProfilePost)
|
||||
|
|
|
@ -102,6 +102,7 @@ type baseClientPage struct {
|
|||
SharesURL string
|
||||
ShareURL string
|
||||
ProfileURL string
|
||||
PingURL string
|
||||
ChangePwdURL string
|
||||
StaticURL string
|
||||
LogoutURL string
|
||||
|
@ -540,6 +541,7 @@ func (s *httpdServer) getBaseClientPageData(title, currentURL string, r *http.Re
|
|||
SharesURL: webClientSharesPath,
|
||||
ShareURL: webClientSharePath,
|
||||
ProfileURL: webClientProfilePath,
|
||||
PingURL: webClientPingPath,
|
||||
ChangePwdURL: webChangeClientPwdPath,
|
||||
StaticURL: webStaticFilesPath,
|
||||
LogoutURL: webClientLogoutPath,
|
||||
|
@ -1792,3 +1794,8 @@ func (s *httpdServer) handleClientShareLoginPost(w http.ResponseWriter, r *http.
|
|||
s.renderClientMessagePage(w, r, "Share Login OK", "Share login successful, you can now use your link",
|
||||
http.StatusOK, nil, "")
|
||||
}
|
||||
|
||||
func (s *httpdServer) handleClientPing(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
||||
render.PlainText(w, r, "PONG")
|
||||
}
|
||||
|
|
|
@ -105,8 +105,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
|
|||
var cmView;
|
||||
|
||||
function keepAlive() {
|
||||
axios.get('{{.ProfileURL}}',{
|
||||
timeout: 15000
|
||||
axios.get('{{.PingURL}}',{
|
||||
timeout: 15000,
|
||||
responseType: 'text'
|
||||
}).catch(function (error){});
|
||||
}
|
||||
|
||||
|
|
|
@ -208,8 +208,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
|
|||
<script type="text/javascript">
|
||||
function keepAlive() {
|
||||
//{{- if not .ShareUploadBaseURL}}
|
||||
axios.get('{{.ProfileURL}}',{
|
||||
timeout: 15000
|
||||
axios.get('{{.PingURL}}',{
|
||||
timeout: 15000,
|
||||
responseType: 'text'
|
||||
}).catch(function (error){});
|
||||
//{{- end}}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue