<!DOCTYPE html>
<html>
  <head><title>Monitor logout</title></head>
  <body>
    <noscript>Cannot logout without javascript</noscript>
    <script>
      var logoutURL = "/cgi-bin/monitor-logout.cgi",
        xhr = new XMLHttpRequest();
      xhr.onload = function () {
        if (xhr.status === 401) {
          document.body.innerHTML = "<p>You are now logged out. You can go back to the monitor interface <a href=\"/\">here</a>.</p>";
        } else {
          console.error("Cannot logout (" + xhr.status + ")");
          document.body.innerHTML = "<p>Cannot logout, retrying in 5 seconds.</p>";
          setTimeout(location.reload.bind(location), 5000);
        }
      };
      xhr.onerror = function () {
        document.body.innerHTML = "<p>Cannot logout, please try again later.</p>";
      };
      xhr.open("POST", logoutURL, true, " logout", " password");
      xhr.send();
      document.body.innerHTML = "<p>Logging out...</p>";
    </script>
  </body>
</html>