diff options
author | Devaev Maxim <[email protected]> | 2018-12-16 22:25:48 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-12-16 22:25:48 +0300 |
commit | 18842fdd35d387fef89b8b73f40c9db334f54121 (patch) | |
tree | 8cecdf5ba21eb9d09d40cb397b074698f01502cf /web | |
parent | b8df7a71fec778f16d0905ac474cbdb8cc829789 (diff) |
process 401 and 403
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/index/main.js | 4 | ||||
-rw-r--r-- | web/share/js/kvm/session.js | 25 |
2 files changed, 22 insertions, 7 deletions
diff --git a/web/share/js/index/main.js b/web/share/js/index/main.js index f42b9af6..369706ac 100644 --- a/web/share/js/index/main.js +++ b/web/share/js/index/main.js @@ -53,6 +53,8 @@ function __loadKvmdInfo() { $("kvmd-meta-server-host").innerHTML = ""; document.title = "Pi-KVM Index"; } + } else if (http.status === 401 || http.status === 403) { + document.location.href = "/login"; } else { setTimeout(__loadKvmdInfo, 1000); } @@ -76,7 +78,7 @@ function __makeApp(id, path, icon, name) { function __logout() { var http = tools.makeRequest("POST", "/kvmd/auth/logout", function() { if (http.readyState === 4) { - if (http.status === 200) { + if (http.status === 200 || http.status === 401 || http.status === 403) { document.location.href = "/login"; } else { wm.error("Logout error:<br>", http.responseText); diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js index 5ba43511..95f8fd88 100644 --- a/web/share/js/kvm/session.js +++ b/web/share/js/kvm/session.js @@ -46,12 +46,25 @@ function Session() { var __startSession = function() { $("link-led").className = "led-yellow"; $("link-led").title = "Connecting..."; - var proto = (location.protocol === "https:" ? "wss" : "ws"); - __ws = new WebSocket(`${proto}://${location.host}/kvmd/ws`); - __ws.onopen = __wsOpenHandler; - __ws.onmessage = __wsMessageHandler; - __ws.onerror = __wsErrorHandler; - __ws.onclose = __wsCloseHandler; + + var http = tools.makeRequest("GET", "/kvmd/auth/check", function() { + if (http.readyState === 4) { + if (http.status === 200) { + var proto = (location.protocol === "https:" ? "wss" : "ws"); + __ws = new WebSocket(`${proto}://${location.host}/kvmd/ws`); + __ws.onopen = __wsOpenHandler; + __ws.onmessage = __wsMessageHandler; + __ws.onerror = __wsErrorHandler; + __ws.onclose = __wsCloseHandler; + } else if (http.status === 401 || http.status === 403) { + wm.error("Unexpected logout occured, please login again").then(function() { + document.location.href = "/login"; + }); + } else { + __wsCloseHandler(null); + } + } + }); }; var __wsOpenHandler = function(event) { |