]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
HTTP server: use cookie to remember the logout state
authorJaroslav Kysela <perex@perex.cz>
Tue, 16 Sep 2014 12:44:55 +0000 (14:44 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 16 Sep 2014 13:03:11 +0000 (15:03 +0200)
src/http.c
src/http.h
src/webui/webui.c

index 15297e69a7af8f1646e4da12439934f83f0556cb..f591317465e79b4175308a8568bd594d4f34ee08 100644 (file)
@@ -252,6 +252,11 @@ http_send_header(http_connection_t *hc, int rc, const char *content,
 
   if(rc == HTTP_STATUS_UNAUTHORIZED)
     htsbuf_qprintf(&hdrs, "WWW-Authenticate: Basic realm=\"tvheadend\"\r\n");
+  if (hc->hc_logout_cookie == 1) {
+    htsbuf_qprintf(&hdrs, "Set-Cookie: logout=1; Path=\"/logout\"\r\n");
+  } else if (hc->hc_logout_cookie == 2) {
+    htsbuf_qprintf(&hdrs, "Set-Cookie: logout=0; Path=\"/logout'\"; expires=Thu, 01 Jan 1970 00:00:00 GMT\r\n");
+  }
 
   htsbuf_qprintf(&hdrs, "Connection: %s\r\n", 
              hc->hc_keep_alive ? "Keep-Alive" : "Close");
@@ -918,6 +923,8 @@ http_serve_requests(http_connection_t *hc, htsbuf_queue_t *spill)
     free(hc->hc_password);
     hc->hc_password = NULL;
 
+    hc->hc_logout_cookie = 0;
+
   } while(hc->hc_keep_alive && http_server);
 
 error:
index 7a4baf61ed70375692289cadb5a706377b87d0ca..544db669e562895674fec3484a751e72a60e28bc 100644 (file)
@@ -137,6 +137,7 @@ typedef struct http_connection {
   struct config_head *hc_user_config;
 
   int hc_no_output;
+  int hc_logout_cookie;
 
   /* Support for HTTP POST */
   
index 2d631ea715a85a9ac4a3b19f4462ac2f876fda66..04b213f0dfdc087e518d6a498be839af760ee081 100644 (file)
@@ -182,9 +182,22 @@ page_logout(http_connection_t *hc, const char *remain, void *opaque)
   if (hc->hc_access == NULL ||
       hc->hc_access->aa_username == NULL ||
       hc->hc_access->aa_username == '\0') {
+redirect:
     http_redirect(hc, "/", &hc->hc_req_args);
     return 0;
   } else {
+    const char *s = http_arg_get(&hc->hc_args, "Cookie");
+    if (s) {
+      while (*s && *s != ';')
+        s++;
+      if (*s) s++;
+      while (*s && *s <= ' ') s++;
+      if (!strncmp(s, "logout=1", 8)) {
+        hc->hc_logout_cookie = 2;
+        goto redirect;
+      }
+      hc->hc_logout_cookie = 1;
+    }
     return HTTP_STATUS_UNAUTHORIZED;
   }
 }