Changeset 1346

Show
Ignore:
Timestamp:
04/21/08 19:04:40 (6 years ago)
Author:
acv
Message:

Merged in path #453

Location:
trunk/wifidog
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/ChangeLog

    r1345 r1346  
    222008-04-21 Alexandre Carmel-Veilleux <acv@miniguru.ca> 
    33        * 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. 
    56 
    672008-04-13 Benoit Gr�goire  <bock@step.polymtl.ca> 
  • trunk/wifidog/configure.in

    r1340 r1346  
    9898AC_OUTPUT(              Makefile  
    9999                        wifidog.spec 
     100                        wifidog-msg.html 
    100101                        src/Makefile 
    101102                        libhttpd/Makefile 
  • trunk/wifidog/libhttpd/httpd.h

    r1345 r1346  
    4444 
    4545#ifndef u_int 
    46 #define u_int unsigned int 
     46#include <sys/types.h> 
    4747#endif 
    4848 
  • trunk/wifidog/src/auth.c

    r1305 r1346  
    149149                /* Error talking to central server */ 
    150150                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"); 
    154152                break; 
    155153 
     
    209207    default: 
    210208                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"); 
    214210            break; 
    215211 
  • trunk/wifidog/src/conf.c

    r1305 r1346  
    9191        oFirewallRule, 
    9292        oFirewallRuleSet, 
    93         oTrustedMACList 
     93        oTrustedMACList, 
     94        oHtmlMessageFile, 
    9495} OpCodes; 
    9596 
     
    128129        { "firewallrule",           oFirewallRule }, 
    129130        { "trustedmaclist",         oTrustedMACList }, 
     131        { "htmlmessagefile",    oHtmlMessageFile }, 
    130132        { NULL,                 oBadOption }, 
    131133}; 
     
    154156        debug(LOG_DEBUG, "Setting default config parameters"); 
    155157        strncpy(config.configfile, DEFAULT_CONFIGFILE, sizeof(config.configfile)); 
     158        config.htmlmsgfile = safe_strdup(DEFAULT_HTMLMSGFILE); 
    156159        config.debuglevel = DEFAULT_DEBUGLEVEL; 
    157160        config.httpdmaxconn = DEFAULT_HTTPDMAXCONN; 
     
    343346        new->authserv_path = path; 
    344347        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;   
    349352        new->authserv_http_port = http_port; 
    350353        new->authserv_ssl_port = ssl_port; 
     
    723726                                        sscanf(p1, "%d", &config.syslog_facility); 
    724727                                        break; 
     728                                case oHtmlMessageFile: 
     729                                        config.htmlmsgfile = safe_strdup(p1); 
     730                                        break; 
     731 
    725732                                } 
    726733                        } 
  • trunk/wifidog/src/conf.h

    r1305 r1346  
    4040#ifndef SYSCONFDIR 
    4141        #define DEFAULT_CONFIGFILE "/etc/wifidog.conf" 
     42        #define DEFAULT_HTMLMSGFILE "/etc/wifidog-msg.html" 
    4243#else 
    4344        #define DEFAULT_CONFIGFILE SYSCONFDIR"/wifidog.conf" 
     45        #define DEFAULT_HTMLMSGFILE SYSCONFDIR"/wifidog-msg.html" 
    4446#endif   
    4547#define DEFAULT_DAEMON 1 
     
    121123typedef struct { 
    122124    char configfile[255];       /**< @brief name of the config file */ 
     125    char *htmlmsgfile;          /**< @brief name of the HTML file used for messages */ 
    123126    char *wdctl_sock;           /**< @brief wdctl path to socket */ 
    124127    char *internal_sock;                /**< @brief internal path to socket */ 
  • trunk/wifidog/src/http.c

    r1340 r1346  
    3636#include <unistd.h> 
    3737#include <syslog.h> 
     38#include <sys/types.h> 
     39#include <sys/stat.h> 
     40#include <fcntl.h> 
     41#include <errno.h> 
    3842 
    3943#include "httpd.h" 
     
    6064http_callback_404(httpd *webserver, request *r) 
    6165{ 
    62         char            *urlFragment, 
    63                         tmp_url[MAX_BUF], 
     66        char            tmp_url[MAX_BUF], 
    6467                        *url; 
    6568        s_config        *config = config_get_config(); 
     
    8184        if (!is_online()) { 
    8285                /* 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); 
    8995                debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr); 
    9096        } 
    9197        else if (!is_auth_online()) { 
    9298                /* 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); 
    98107                debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr); 
    99108        } 
    100109        else { 
    101110                /* Re-direct them to auth server */ 
     111                char *urlFragment; 
    102112                safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&url=%s", 
    103113                        auth_server->authserv_login_script_path_fragment, 
     
    116126http_callback_wifidog(httpd *webserver, request *r) 
    117127{ 
    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."); 
    121129} 
    122130 
     
    124132http_callback_about(httpd *webserver, request *r) 
    125133{ 
    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>"); 
    129135} 
    130136 
     
    133139{ 
    134140        char * status = NULL; 
     141        char *buf; 
    135142        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); 
    141146        free(status); 
    142147} 
     
    177182void http_send_redirect(request *r, char *url, char *text) 
    178183{ 
     184                char *message = NULL; 
    179185                char *header = NULL; 
    180186                char *response = NULL; 
     
    198204                free(response); 
    199205                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); 
    211209} 
    212210 
     
    223221                        /* We could not get their MAC address */ 
    224222                        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"); 
    228224                } else { 
    229225                        /* We have their MAC address */ 
     
    277273        } else { 
    278274                /* 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 
     279void 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  
    4141void http_callback_auth(httpd *webserver, request *r); 
    4242 
    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 */ 
     44void send_http_page(request *r, const char *title, const char* message); 
    4745 
    4846/** @brief Sends a redirect to the web browser */ 
  • trunk/wifidog/wifidog.conf

    r1243 r1346  
    4040 
    4141# 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 
    4252 
    4353# Parameter: AuthServer