Changeset 1346
- Timestamp:
- 04/21/08 19:04:40 (6 months ago)
- Files:
-
- trunk/wifidog/ChangeLog (modified) (1 diff)
- trunk/wifidog/configure.in (modified) (1 diff)
- trunk/wifidog/libhttpd/httpd.h (modified) (1 diff)
- trunk/wifidog/src/auth.c (modified) (2 diffs)
- trunk/wifidog/src/conf.c (modified) (5 diffs)
- trunk/wifidog/src/conf.h (modified) (2 diffs)
- trunk/wifidog/src/http.c (modified) (10 diffs)
- trunk/wifidog/src/http.h (modified) (1 diff)
- trunk/wifidog/wifidog.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wifidog/ChangeLog
r1345 r1346 2 2 2008-04-21 Alexandre Carmel-Veilleux <acv@miniguru.ca> 3 3 * Integrated patch #452 from Wichert Akkerman <wichert@wiggy.net>: Add const to function arguments in libhttpd to enforce more type checking and prevent certain class of problems. 4 * Compatiblity fix: Libhttpd assumes that type u_int is defined. Added an #ifndef/#define pair to httpd.h to make sure that assertion is true. 4 * Compatiblity fix: Libhttpd assumes that type u_int is defined. Added an #ifndef/#include <sys/types.h> pair to httpd.h to make sure that assertion is true. 5 * Integrated patch #453 from Wichert Akkerman <wichert@wiggy.net>: Add configurable html to wifidog error messages. This has been a long-requested feature. 5 6 6 7 2008-04-13 Benoit Gr�ire <bock@step.polymtl.ca> trunk/wifidog/configure.in
r1340 r1346 98 98 AC_OUTPUT( Makefile 99 99 wifidog.spec 100 wifidog-msg.html 100 101 src/Makefile 101 102 libhttpd/Makefile trunk/wifidog/libhttpd/httpd.h
r1345 r1346 44 44 45 45 #ifndef u_int 46 # define u_int unsigned int46 #include <sys/types.h> 47 47 #endif 48 48 trunk/wifidog/src/auth.c
r1305 r1346 149 149 /* Error talking to central server */ 150 150 debug(LOG_ERR, "Got %d from central server authenticating token %s from %s at %s", auth_response, client->token, client->ip, client->mac); 151 http_wifidog_header(r, "Error!"); 152 httpdOutput(r, "Error: We did not get a valid answer from the central server"); 153 http_wifidog_footer(r); 151 send_http_page(r, "Error!", "Error: We did not get a valid answer from the central server"); 154 152 break; 155 153 … … 209 207 default: 210 208 debug(LOG_WARNING, "I don't know what the validation code %d means for token %s from %s at %s - sending error message", auth_response.authcode, client->token, client->ip, client->mac); 211 http_wifidog_header(r, "Internal error"); 212 httpdOutput(r, "We can not validate your request at this time"); 213 http_wifidog_footer(r); 209 send_http_page(r, "Internal Error", "We can not validate your request at this time"); 214 210 break; 215 211 trunk/wifidog/src/conf.c
r1305 r1346 91 91 oFirewallRule, 92 92 oFirewallRuleSet, 93 oTrustedMACList 93 oTrustedMACList, 94 oHtmlMessageFile, 94 95 } OpCodes; 95 96 … … 128 129 { "firewallrule", oFirewallRule }, 129 130 { "trustedmaclist", oTrustedMACList }, 131 { "htmlmessagefile", oHtmlMessageFile }, 130 132 { NULL, oBadOption }, 131 133 }; … … 154 156 debug(LOG_DEBUG, "Setting default config parameters"); 155 157 strncpy(config.configfile, DEFAULT_CONFIGFILE, sizeof(config.configfile)); 158 config.htmlmsgfile = safe_strdup(DEFAULT_HTMLMSGFILE); 156 159 config.debuglevel = DEFAULT_DEBUGLEVEL; 157 160 config.httpdmaxconn = DEFAULT_HTTPDMAXCONN; … … 343 346 new->authserv_path = path; 344 347 new->authserv_login_script_path_fragment = loginscriptpathfragment; 345 new->authserv_portal_script_path_fragment = portalscriptpathfragment;346 new->authserv_msg_script_path_fragment = msgscriptpathfragment;347 new->authserv_ping_script_path_fragment = pingscriptpathfragment;348 new->authserv_auth_script_path_fragment = authscriptpathfragment;348 new->authserv_portal_script_path_fragment = portalscriptpathfragment; 349 new->authserv_msg_script_path_fragment = msgscriptpathfragment; 350 new->authserv_ping_script_path_fragment = pingscriptpathfragment; 351 new->authserv_auth_script_path_fragment = authscriptpathfragment; 349 352 new->authserv_http_port = http_port; 350 353 new->authserv_ssl_port = ssl_port; … … 723 726 sscanf(p1, "%d", &config.syslog_facility); 724 727 break; 728 case oHtmlMessageFile: 729 config.htmlmsgfile = safe_strdup(p1); 730 break; 731 725 732 } 726 733 } trunk/wifidog/src/conf.h
r1305 r1346 40 40 #ifndef SYSCONFDIR 41 41 #define DEFAULT_CONFIGFILE "/etc/wifidog.conf" 42 #define DEFAULT_HTMLMSGFILE "/etc/wifidog-msg.html" 42 43 #else 43 44 #define DEFAULT_CONFIGFILE SYSCONFDIR"/wifidog.conf" 45 #define DEFAULT_HTMLMSGFILE SYSCONFDIR"/wifidog-msg.html" 44 46 #endif 45 47 #define DEFAULT_DAEMON 1 … … 121 123 typedef struct { 122 124 char configfile[255]; /**< @brief name of the config file */ 125 char *htmlmsgfile; /**< @brief name of the HTML file used for messages */ 123 126 char *wdctl_sock; /**< @brief wdctl path to socket */ 124 127 char *internal_sock; /**< @brief internal path to socket */ trunk/wifidog/src/http.c
r1340 r1346 36 36 #include <unistd.h> 37 37 #include <syslog.h> 38 #include <sys/types.h> 39 #include <sys/stat.h> 40 #include <fcntl.h> 41 #include <errno.h> 38 42 39 43 #include "httpd.h" … … 60 64 http_callback_404(httpd *webserver, request *r) 61 65 { 62 char *urlFragment, 63 tmp_url[MAX_BUF], 66 char tmp_url[MAX_BUF], 64 67 *url; 65 68 s_config *config = config_get_config(); … … 81 84 if (!is_online()) { 82 85 /* The internet connection is down at the moment - apologize and do not redirect anywhere */ 83 http_wifidog_header(r, "<h2>Uh oh! Internet access unavailable</h2>"); 84 httpdOutput(r, "<p>We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable.</p>"); 85 httpdOutput(r, "<p>If at all possible, please notify the owners of this hotspot that the internet connection is out of service.</p>"); 86 httpdOutput(r, "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>"); 87 httpdPrintf(r, "<p>In a while please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); 88 http_wifidog_footer(r); 86 char * buf; 87 safe_asprintf(&buf, 88 "<p>We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable.</p>" 89 "<p>If at all possible, please notify the owners of this hotspot that the internet connection is out of service.</p>" 90 "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>" 91 "<p>In a while please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); 92 93 send_http_page(r, "Uh oh! Internet access unavailable!", buf); 94 free(buf); 89 95 debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr); 90 96 } 91 97 else if (!is_auth_online()) { 92 98 /* The auth server is down at the moment - apologize and do not redirect anywhere */ 93 http_wifidog_header(r, "<h2>Uh oh! Login screen unavailable</h2>"); 94 httpdOutput(r, "<p>We apologize, but it seems that we are currently unable to re-direct you to the login screen.</p>"); 95 httpdOutput(r, "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>"); 96 httpdPrintf(r, "<p>In a couple of minutes please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); 97 http_wifidog_footer(r); 99 char * buf; 100 safe_asprintf(&buf, 101 "<p>We apologize, but it seems that we are currently unable to re-direct you to the login screen.</p>" 102 "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>" 103 "<p>In a couple of minutes please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); 104 105 send_http_page(r, "Uh oh! Login screen unavailable!", buf); 106 free(buf); 98 107 debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr); 99 108 } 100 109 else { 101 110 /* Re-direct them to auth server */ 111 char *urlFragment; 102 112 safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&url=%s", 103 113 auth_server->authserv_login_script_path_fragment, … … 116 126 http_callback_wifidog(httpd *webserver, request *r) 117 127 { 118 http_wifidog_header(r, "WiFiDog"); 119 httpdOutput(r, "Please use the menu to navigate the features of this WiFiDog installation."); 120 http_wifidog_footer(r); 128 send_http_page(r, "WiFiDog", "Please use the menu to navigate the features of this WiFiDog installation."); 121 129 } 122 130 … … 124 132 http_callback_about(httpd *webserver, request *r) 125 133 { 126 http_wifidog_header(r, "About WiFiDog"); 127 httpdOutput(r, "This is WiFiDog version <b>" VERSION "</b>"); 128 http_wifidog_footer(r); 134 send_http_page(r, "About WiFiDog", "This is WiFiDog version <strong>" VERSION "</strong>"); 129 135 } 130 136 … … 133 139 { 134 140 char * status = NULL; 141 char *buf; 135 142 status = get_status_text(); 136 http_wifidog_header(r, "WiFiDog Status"); 137 httpdOutput(r, "<pre>"); 138 httpdOutput(r, status); 139 httpdOutput(r, "</pre>"); 140 http_wifidog_footer(r); 143 safe_asprintf(&buf, "<pre>%s</pre>", status); 144 send_http_page(r, "WiFiDog Status", buf); 145 free(buf); 141 146 free(status); 142 147 } … … 177 182 void http_send_redirect(request *r, char *url, char *text) 178 183 { 184 char *message = NULL; 179 185 char *header = NULL; 180 186 char *response = NULL; … … 198 204 free(response); 199 205 free(header); 200 if(text) { 201 http_wifidog_header(r, text); 202 } 203 else { 204 http_wifidog_header(r, "Redirection to message"); 205 } 206 207 httpdPrintf(r, "Please <a href='%s'>click here</a>.", 208 url 209 ); 210 http_wifidog_footer(r); 206 safe_asprintf(&message, "Please <a href='%s'>click here</a>.", url); 207 send_http_page(r, text ? text : "Redirection to message", message); 208 free(message); 211 209 } 212 210 … … 223 221 /* We could not get their MAC address */ 224 222 debug(LOG_ERR, "Failed to retrieve MAC address for ip %s", r->clientAddr); 225 http_wifidog_header(r, "WiFiDog Error"); 226 httpdOutput(r, "Failed to retrieve your MAC address"); 227 http_wifidog_footer(r); 223 send_http_page(r, "WiFiDog Error", "Failed to retrieve your MAC address"); 228 224 } else { 229 225 /* We have their MAC address */ … … 277 273 } else { 278 274 /* They did not supply variable "token" */ 279 http_wifidog_header(r, "WiFiDog Error"); 280 httpdOutput(r, "Invalid token"); 281 http_wifidog_footer(r); 282 } 283 } 284 285 void 286 http_wifidog_header(request *r, char *title) 287 { 288 httpdOutput(r, "<html>\n"); 289 httpdOutput(r, "<head>\n"); 290 httpdPrintf(r, "<title>%s</title>\n", title); 291 httpdOutput(r, "<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>\n"); 292 293 httpdOutput(r, "<style>\n"); 294 httpdOutput(r, "body {\n"); 295 httpdOutput(r, " margin: 10px 60px 0 60px; \n"); 296 httpdOutput(r, " font-family : bitstream vera sans, sans-serif;\n"); 297 httpdOutput(r, " color: #46a43a;\n"); 298 httpdOutput(r, "}\n"); 299 300 httpdOutput(r, "a {\n"); 301 httpdOutput(r, " color: #46a43a;\n"); 302 httpdOutput(r, "}\n"); 303 304 httpdOutput(r, "a:active {\n"); 305 httpdOutput(r, " color: #46a43a;\n"); 306 httpdOutput(r, "}\n"); 307 308 httpdOutput(r, "a:link {\n"); 309 httpdOutput(r, " color: #46a43a;\n"); 310 httpdOutput(r, "}\n"); 311 312 httpdOutput(r, "a:visited {\n"); 313 httpdOutput(r, " color: #46a43a;\n"); 314 httpdOutput(r, "}\n"); 315 316 httpdOutput(r, "#header {\n"); 317 httpdOutput(r, " height: 30px;\n"); 318 httpdOutput(r, " background-color: #B4F663;\n"); 319 httpdOutput(r, " padding: 20px;\n"); 320 httpdOutput(r, " font-size: 20pt;\n"); 321 httpdOutput(r, " text-align: center;\n"); 322 httpdOutput(r, " border: 2px solid #46a43a;\n"); 323 httpdOutput(r, " border-bottom: 0;\n"); 324 httpdOutput(r, "}\n"); 325 326 httpdOutput(r, "#menu {\n"); 327 httpdOutput(r, " width: 200px;\n"); 328 httpdOutput(r, " float: right;\n"); 329 httpdOutput(r, " background-color: #B4F663;\n"); 330 httpdOutput(r, " border: 2px solid #46a43a;\n"); 331 httpdOutput(r, " font-size: 80%;\n"); 332 httpdOutput(r, " min-height: 300px;\n"); 333 httpdOutput(r, "}\n"); 334 335 httpdOutput(r, "#menu h2 {\n"); 336 httpdOutput(r, " margin: 0;\n"); 337 httpdOutput(r, " background-color: #46a43a;\n"); 338 httpdOutput(r, " text-align: center;\n"); 339 httpdOutput(r, " color: #B4F663;\n"); 340 httpdOutput(r, "}\n"); 341 342 httpdOutput(r, "#copyright {\n"); 343 httpdOutput(r, "}\n"); 344 345 httpdOutput(r, "#content {\n"); 346 httpdOutput(r, " padding: 20px;\n"); 347 httpdOutput(r, " border: 2px solid #46a43a;\n"); 348 httpdOutput(r, " min-height: 300px;\n"); 349 httpdOutput(r, "}\n"); 350 httpdOutput(r, "</style>\n"); 351 352 httpdOutput(r, "</head>\n"); 353 354 httpdOutput(r, "<body\n"); 355 356 httpdOutput(r, "<div id=\"header\">\n"); 357 httpdPrintf(r, " %s\n", title); 358 httpdOutput(r, "</div>\n"); 359 360 httpdOutput(r, "<div id=\"menu\">\n"); 361 362 363 httpdOutput(r, " <h2>Info</h2>\n"); 364 httpdOutput(r, " <ul>\n"); 365 httpdOutput(r, " <li>Version: " VERSION "\n"); 366 httpdPrintf(r, " <li>Node ID: %s\n", config_get_config()->gw_id); 367 httpdOutput(r, " </ul>\n"); 368 httpdOutput(r, " <br>\n"); 369 370 httpdOutput(r, " <h2>Menu</h2>\n"); 371 httpdOutput(r, " <ul>\n"); 372 httpdOutput(r, " <li><a href='/wifidog/status'>WiFiDog Status</a>\n"); 373 httpdOutput(r, " <li><a href='/wifidog/about'>About WiFiDog</a>\n"); 374 httpdOutput(r, " <li><a href='http://www.wifidog.org'>WiFiDog's homepage</a>\n"); 375 httpdOutput(r, " </ul>\n"); 376 httpdOutput(r, "</div>\n"); 377 378 httpdOutput(r, "<div id=\"content\">\n"); 379 httpdPrintf(r, "<h2>%s</h2>\n", title); 380 } 381 382 void 383 http_wifidog_footer(request *r) 384 { 385 httpdOutput(r, "</div>\n"); 386 387 httpdOutput(r, "<div id=\"copyright\">\n"); 388 httpdOutput(r, "Copyright (C) 2004-2005. This software is released under the GNU GPL license.\n"); 389 httpdOutput(r, "</div>\n"); 390 391 392 httpdOutput(r, "</body>\n"); 393 httpdOutput(r, "</html>\n"); 394 } 275 send_http_page(r, "WiFiDog error", "Invalid token"); 276 } 277 } 278 279 void send_http_page(request *r, const char *title, const char* message) 280 { 281 s_config *config = config_get_config(); 282 unsigned char *buffer; 283 struct stat stat_info; 284 int fd; 285 ssize_t written; 286 287 fd=open(config->htmlmsgfile, O_RDONLY); 288 if (fd==-1) { 289 debug(LOG_CRIT, "Failed to open HTML message file %s: %s", config->htmlmsgfile, strerror(errno)); 290 return; 291 } 292 293 if (fstat(fd, &stat_info)==-1) { 294 debug(LOG_CRIT, "Failed to stat HTML message file: %s", strerror(errno)); 295 close(fd); 296 return; 297 } 298 299 buffer=(unsigned char*)safe_malloc(stat_info.st_size+1); 300 written=read(fd, buffer, stat_info.st_size); 301 if (written==-1) { 302 debug(LOG_CRIT, "Failed to read HTML message file: %s", strerror(errno)); 303 free(buffer); 304 close(fd); 305 return; 306 } 307 close(fd); 308 309 buffer[written]=0; 310 httpdAddVariable(r, "title", title); 311 httpdAddVariable(r, "message", message); 312 httpdAddVariable(r, "nodeID", config->gw_id); 313 httpdOutput(r, buffer); 314 free(buffer); 315 } 316 trunk/wifidog/src/http.h
r1243 r1346 41 41 void http_callback_auth(httpd *webserver, request *r); 42 42 43 /** @brief Sends HTML header+menu to web browser */ 44 void http_wifidog_header(request *r, char *title); 45 /** @brief Sends HTML footer to web browser */ 46 void http_wifidog_footer(request *r); 43 /** @brief Sends a HTML page to web browser */ 44 void send_http_page(request *r, const char *title, const char* message); 47 45 48 46 /** @brief Sends a redirect to the web browser */ trunk/wifidog/wifidog.conf
r1243 r1346 40 40 41 41 # GatewayAddress 192.168.1.1 42 43 # Parameter: HtmlMessageFile 44 # Default: wifidog-msg.html 45 # Optional 46 # 47 # This allows you to specify a custome HTML file which will be used for 48 # system errors by the gateway. Any $title, $message and $node variables 49 # used inside the file will be replaced. 50 # 51 # HtmlMessageFile /opt/wifidog/etc/wifidog-.html 42 52 43 53 # Parameter: AuthServer
