When enabling/disabling a server with POST to the stats page, the
order of the required params is important: the server name had to be
first. This patch allows to handle those parameters in any order.
---
 src/proto_http.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/proto_http.c b/src/proto_http.c
index c71b839..068498f 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -2947,6 +2947,7 @@ int http_process_req_stat_post(struct stream_interface 
*si, struct http_txn *txn
        struct proxy *px;
        struct server *sv;
 
+       char *server = NULL;
        char *backend = NULL;
        int action = 0;
 
@@ -3017,30 +3018,34 @@ int http_process_req_stat_post(struct stream_interface 
*si, struct http_txn *txn
                                }
                        }
                        else if (strcmp(key, "s") == 0) {
-                               if (backend && action && 
get_backend_server(backend, value, &px, &sv)) {
-                                       switch (action) {
-                                       case 1:
-                                               if ((px->state != PR_STSTOPPED) 
&& !(sv->state & SRV_MAINTAIN)) {
-                                                       /* Not already in 
maintenance, we can change the server state */
-                                                       sv->state |= 
SRV_MAINTAIN;
-                                                       set_server_down(sv);
-                                                       
si->applet.ctx.stats.st_code = STAT_STATUS_DONE;
-                                               }
-                                               break;
-                                       case 2:
-                                               if ((px->state != PR_STSTOPPED) 
&& (sv->state & SRV_MAINTAIN)) {
-                                                       /* Already in 
maintenance, we can change the server state */
-                                                       set_server_up(sv);
-                                                       sv->health = sv->rise;  
/* up, but will fall down at first failure */
-                                                       
si->applet.ctx.stats.st_code = STAT_STATUS_DONE;
-                                               }
-                                               break;
-                                       }
-                               }
+                               server = value;
                        }
                        next_param = cur_param;
                }
        }
+
+       /* Check if we have everything needed to execute an action */
+       if (backend && server && action && get_backend_server(backend, server, 
&px, &sv)) {
+               switch (action) {
+               case 1:
+                       if ((px->state != PR_STSTOPPED) && !(sv->state & 
SRV_MAINTAIN)) {
+                               /* Not already in maintenance, we can change 
the server state */
+                               sv->state |= SRV_MAINTAIN;
+                               set_server_down(sv);
+                               si->applet.ctx.stats.st_code = STAT_STATUS_DONE;
+                       }
+                       break;
+               case 2:
+                       if ((px->state != PR_STSTOPPED) && (sv->state & 
SRV_MAINTAIN)) {
+                               /* Already in maintenance, we can change the 
server state */
+                               set_server_up(sv);
+                               sv->health = sv->rise;  /* up, but will fall 
down at first failure */
+                               si->applet.ctx.stats.st_code = STAT_STATUS_DONE;
+                       }
+                       break;
+               }
+       }
+
        return 1;
 }
 
-- 
1.7.9.1


Reply via email to