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
|
|
| 411 | 411 | httpdAddCContent(webserver, "/wifidog", "about", 0, NULL, http_callback_about); |
| 412 | 412 | httpdAddCContent(webserver, "/wifidog", "status", 0, NULL, http_callback_status); |
| 413 | 413 | httpdAddCContent(webserver, "/wifidog", "auth", 0, NULL, http_callback_auth); |
| | 414 | httpdAddCContent(webserver, "/wifidog", "disconnect", 0, NULL, http_callback_disconnect); |
| 414 | 415 | |
| 415 | 416 | httpdAddC404Content(webserver, http_callback_404); |
| 416 | 417 | |
diff --git a/src/http.c b/src/http.c
index b2b8ff9..d10c107 100644
|
a
|
b
|
|
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
| | 279 | void |
| | 280 | http_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 | |
| 279 | 318 | void send_http_page(request *r, const char *title, const char* message) |
| 280 | 319 | { |
| 281 | 320 | s_config *config = config_get_config(); |
diff --git a/src/http.h b/src/http.h
index 6a3e9bb..6e305f8 100644
|
a
|
b
|
|
| 39 | 39 | void http_callback_status(httpd *webserver, request *r); |
| 40 | 40 | /**@brief Callback for libhttpd, main entry point post login for auth confirmation */ |
| 41 | 41 | void http_callback_auth(httpd *webserver, request *r); |
| | 42 | /**@brief Callback for libhttpd, disconnect user from network */ |
| | 43 | void http_callback_disconnect(httpd *webserver, request *r); |
| 42 | 44 | |
| 43 | 45 | /** @brief Sends a HTML page to web browser */ |
| 44 | 46 | void send_http_page(request *r, const char *title, const char* message); |