]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] add support for "stats refresh <interval>"
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Jul 2007 05:26:38 +0000 (07:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 9 Sep 2007 19:09:28 +0000 (21:09 +0200)
Sometimes it may be desirable to automatically refresh the
stats page. Most browsers support the "Refresh:" header with
an interval in seconds. Specifying "stats refresh xxx" will
automatically add this header.

doc/configuration.txt
include/common/uri_auth.h
src/cfgparse.c
src/proto_http.c
src/uri_auth.c

index 6e7af4b878d71d941b15c1c944686b7a2d5ca208..12a7eb76dc131c9cbbc9bfc36c836cb7008fcb37 100644 (file)
@@ -2,9 +2,9 @@
                                  HAProxy
                           Configuration Manual
                          ----------------------
-                             version 1.3.12
+                             version 1.3.12.1
                              willy tarreau
-                               2007/07/24
+                               2007/07/25
 
 
 This document covers the configuration language as implemented in the version
@@ -287,6 +287,7 @@ srvtimeout                  X          -         X         X
 stats auth                  X          -         X         X
 stats enable                X          -         X         X
 stats realm                 X          -         X         X
+stats refresh               X          -         X         X
 stats scope                 X          -         X         X
 stats uri                   X          -         X         X
 transparent                 X          X         X         -
index bb25ac1ea3138aa709f64d32fcfc3c4d6121894d..9f675db6a828927ff3e8e7a749eca70cb1eee526 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * URI-based user authentication using the HTTP basic method.
  *
- * Copyright 2006 Willy Tarreau <w@1wt.eu>
+ * Copyright 2006-2007 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -36,6 +36,7 @@ struct uri_auth {
        int uri_len;                    /* the prefix length */
        char *uri_prefix;               /* the prefix we want to match */
        char *auth_realm;               /* the realm reported to the client */
+       int refresh;                    /* refresh interval for the browser (in seconds) */
        struct user_auth *users;        /* linked list of valid user:passwd couples */
        struct stat_scope *scope;       /* linked list of authorized proxies */
 };
@@ -65,7 +66,15 @@ struct uri_auth {
 struct uri_auth *stats_check_init_uri_auth(struct uri_auth **root);
 struct uri_auth *stats_set_uri(struct uri_auth **root, char *uri);
 struct uri_auth *stats_set_realm(struct uri_auth **root, char *realm);
+struct uri_auth *stats_set_refresh(struct uri_auth **root, int interval);
 struct uri_auth *stats_add_auth(struct uri_auth **root, char *user);
 struct uri_auth *stats_add_scope(struct uri_auth **root, char *scope);
 
 #endif /* _COMMON_URI_AUTH_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
index 967b9ca74d70b889d8ac4eba2d1cc20317dfb17b..783e189793e5b0ddce5ce90d126eaecb6d6f0909 100644 (file)
@@ -1040,6 +1040,16 @@ int cfg_parse_listen(const char *file, int linenum, char **args)
                                Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                                return -1;
                        }
+               } else if (!strcmp(args[1], "refresh")) {
+                       int interval = atoi(args[2]);
+                       
+                       if (interval < 0) {
+                               Alert("parsing [%s:%d] : 'refresh' needs a positive interval in seconds.\n", file, linenum);
+                               return -1;
+                       } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
+                               Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
+                               return -1;
+                       }
                } else if (!strcmp(args[1], "auth")) {
                        if (*(args[2]) == 0) {
                                Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
index 10420818ceaea368d1e218b0de2b814036681a26..8ebdc6116a516822e9c67fab497a24a495f79401 100644 (file)
@@ -3451,8 +3451,13 @@ int produce_content_stats(struct session *s)
                             "HTTP/1.0 200 OK\r\n"
                             "Cache-Control: no-cache\r\n"
                             "Connection: close\r\n"
-                            "Content-Type: text/html\r\n"
-                            "\r\n");
+                            "Content-Type: text/html\r\n");
+
+               if (s->be->uri_auth->refresh > 0)
+                       chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n",
+                                    s->be->uri_auth->refresh);
+
+               chunk_printf(&msg, sizeof(trash), "\r\n");
 
                s->txn.status = 200;
                client_retnclose(s, &msg); // send the start of the response.
index f666c0dfa0d5dd19035c8236b903b437c2356261..f5f90af7b251f09f59733ee8c59d85a6a2da1f48 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * URI-based user authentication using the HTTP basic method.
  *
- * Copyright 2006 Willy Tarreau <w@1wt.eu>
+ * Copyright 2006-2007 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -113,6 +113,19 @@ struct uri_auth *stats_set_realm(struct uri_auth **root, char *realm)
        return NULL;
 }
 
+/*
+ * Returns a default uri_auth with the <refresh> refresh interval.
+ * Uses the pointer provided if not NULL and not initialized.
+ */
+struct uri_auth *stats_set_refresh(struct uri_auth **root, int interval)
+{
+       struct uri_auth *u;
+       
+       if ((u = stats_check_init_uri_auth(root)) != NULL)
+               u->refresh = interval;
+       return u;
+}
+
 /*
  * Returns a default uri_auth with a <user:passwd> entry added to the list of
  * authorized users. If a matching entry is found, no update will be performed.
@@ -204,3 +217,9 @@ struct uri_auth *stats_add_scope(struct uri_auth **root, char *scope)
        return NULL;
 }
 
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */