Ticket #465: 0001-Add-a-basic-disconnect-command.patch

File 0001-Add-a-basic-disconnect-command.patch, 2.9 KB (added by wichert@…, 4 years ago)
  • src/gateway.c

    From 99b4c9c6786a545711f93a60505785c592303bc2 Mon Sep 17 00:00:00 2001
    From: Wichert Akkerman <wichert@wiggy.net>
    Date: Mon, 21 Apr 2008 17:24:44 +0200
    Subject: [PATCH] Add a basic disconnect command.
    
    ---
     src/gateway.c |    1 +
     src/http.c    |   39 +++++++++++++++++++++++++++++++++++++++
     src/http.h    |    2 ++
     3 files changed, 42 insertions(+), 0 deletions(-)
    
    diff --git a/src/gateway.c b/src/gateway.c
    index b3fd559..88d13e1 100644
    a b  
    411411        httpdAddCContent(webserver, "/wifidog", "about", 0, NULL, http_callback_about); 
    412412        httpdAddCContent(webserver, "/wifidog", "status", 0, NULL, http_callback_status); 
    413413        httpdAddCContent(webserver, "/wifidog", "auth", 0, NULL, http_callback_auth); 
     414        httpdAddCContent(webserver, "/wifidog", "disconnect", 0, NULL, http_callback_disconnect); 
    414415 
    415416        httpdAddC404Content(webserver, http_callback_404); 
    416417 
  • src/http.c

    diff --git a/src/http.c b/src/http.c
    index b2b8ff9..d10c107 100644
    a b  
    276276        } 
    277277} 
    278278 
     279void  
     280http_callback_disconnect(httpd *webserver, request *r) 
     281{ 
     282        /* XXX How do you change the status code for the response?? */ 
     283        httpVar *token  = httpdGetVariableByName(r, "token"); 
     284        httpVar *mac    = httpdGetVariableByName(r, "mac"); 
     285 
     286        if (token && mac) { 
     287                t_client *client; 
     288                 
     289                LOCK_CLIENT_LIST(); 
     290                client = client_list_find_by_mac(mac->value); 
     291 
     292                if (!client || strcmp(client->token, token->value)) { 
     293                        UNLOCK_CLIENT_LIST(); 
     294                        debug(LOG_INFO, "Disconnect %s with incorrect token %s", mac->value, token->value); 
     295                        httpdOutput(r, "Invalid token for MAC"); 
     296                        return -1; 
     297                } 
     298 
     299                /* TODO: get current firewall counters, set counters to auth server, 
     300                 * send disconnect to auth server. 
     301                 * 
     302                 * XXX: this should share code with wdctl_reset 
     303                 */ 
     304                fw_deny(client->ip, client->mac, client->fw_connection_state); 
     305                client_list_delete(client); 
     306 
     307                UNLOCK_CLIENT_LIST(); 
     308 
     309        } else { 
     310                debug(LOG_INFO, "Disconnect called without both token and MAC given"); 
     311                httpdOutput(r, "Both the token and MAC need to be specified");  
     312                return -1; 
     313        } 
     314 
     315        return 0; 
     316} 
     317 
    279318void send_http_page(request *r, const char *title, const char* message) 
    280319{ 
    281320    s_config    *config = config_get_config(); 
  • src/http.h

    diff --git a/src/http.h b/src/http.h
    index 6a3e9bb..6e305f8 100644
    a b  
    3939void http_callback_status(httpd *webserver, request *r); 
    4040/**@brief Callback for libhttpd, main entry point post login for auth confirmation */ 
    4141void http_callback_auth(httpd *webserver, request *r); 
     42/**@brief Callback for libhttpd, disconnect user from network */ 
     43void http_callback_disconnect(httpd *webserver, request *r); 
    4244 
    4345/** @brief Sends a HTML page to web browser */ 
    4446void send_http_page(request *r, const char *title, const char* message);