Changeset 424

Show
Ignore:
Timestamp:
02/03/05 23:05:28 (8 years ago)
Author:
minaguib
Message:

Keep track of whether we're online or not, show user apology if we're not
Fix building ipkg's - didn't work on my openwrt build
Fix memory leak
Misc

Location:
trunk/wifidog
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/ChangeLog

    r423 r424  
    11# $Header$ 
     2 
     32005-02-03 Mina Naguib <mina@ilesansfil.org> 
     4        * Keep track of last times we successfully & unsuccessfully spoke to the 
     5        auth server/used DNS. Then, if we know we're not online, show a little 
     6        apology to the user instead of re-directing them to the auth server. 
     7        * ipkg/rules: Added some extra version detection to auto-detect versions 
     8        of kernel, iptables and ipkg-utils instead of having them hardcoded.  This 
     9        makes creating ipkg's work with different OpenWRT releases 
     10        * fw_iptables.c: Fixed memory leak caused by not freeing return from 
     11        iptables_compile in iptables_load_ruleset 
     12        * http.c: Deleted unused call to client_list_find 
     13        * http.c: /about URL now shows wifidog version 
     14        * Cosmetic typo fixes 
     15 
    2162005-02-03 Philippe April <isf_lists@philippeapril.com> 
    317        * Ping the users everytime we check their counters, that way we keep them 
  • trunk/wifidog/ipkg/rules

    r281 r424  
    1515TMP_DIR:=$(BUILD_DIR)/tmp 
    1616STAGING_DIR=$(BUILDROOT)/build_$(ARCH)/staging_dir 
    17 IPTABLES_DIR := $(BUILDROOT)/build_$(ARCH)/iptables-1.2.9 
    18 IPKG_DIR := $(BUILDROOT)/build_$(ARCH)/ipkg-utils-1.7 
    19 KERNEL_MODULES_DIR := $(BUILDROOT)/build_$(ARCH)/WRT54GS/release/src/linux/linux/modules/lib/modules/2.4.20 
     17IPTABLES_DIR := $(wildcard $(BUILDROOT)/build_$(ARCH)/iptables-*/) 
     18IPKG_DIR := $(wildcard $(BUILDROOT)/build_$(ARCH)/ipkg-utils-*/) 
     19KERNEL_VERSION := $(shell awk '$$1 == "\#define" && $$2 == "UTS_RELEASE" {gsub(/["]/, "", $$3); print $$3}' $(BUILDROOT)/build_$(ARCH)/WRT54GS/release/src/linux/linux/include/linux/version.h) 
     20KERNEL_MODULES_DIR := $(BUILDROOT)/build_$(ARCH)/WRT54GS/release/src/linux/linux/modules/lib/modules/$(KERNEL_VERSION) 
    2021UCLIBC_DIR := $(BUILDROOT)/build_$(ARCH)/uClibc 
    2122 
     
    8889 
    8990install-kernel-modules: 
    90         mkdir -p $(TMP_DIR)/lib/modules/2.4.20/kernel/net/ipv4/netfilter 
    91         cp $(KERNEL_MODULES_DIR)/kernel/net/ipv4/netfilter/ipt_mac.o $(TMP_DIR)/lib/modules/2.4.20/kernel/net/ipv4/netfilter 
     91        mkdir -p $(TMP_DIR)/lib/modules/$(KERNEL_VERSION)/kernel/net/ipv4/netfilter 
     92        cp $(KERNEL_MODULES_DIR)/kernel/net/ipv4/netfilter/ipt_mac.o $(TMP_DIR)/lib/modules/$(KERNEL_VERSION)/kernel/net/ipv4/netfilter 
    9293 
    9394install-pthread: 
  • trunk/wifidog/src/auth.c

    r391 r424  
    168168         
    169169        if (client == NULL) { 
    170                 debug(LOG_ERR, "Could not find client client for %s (%s)", 
     170                debug(LOG_ERR, "Could not find client node for %s (%s)", 
    171171                                r->clientAddr, mac); 
    172172                pthread_mutex_unlock(&client_list_mutex); 
  • trunk/wifidog/src/centralserver.c

    r274 r424  
    101101                        debug(LOG_ERR, "connect(): %s", strerror(errno)); 
    102102                        debug(LOG_ERR, "Trying next Auth Server (if any)"); 
    103                         if (num_tries++ < config->authserv_maxtries) { 
    104                                 mark_auth_server_bad(auth_server); 
    105                         } else { 
    106                                 mark_auth_server_bad(auth_server); 
     103                        mark_auth_server_bad(auth_server); 
     104                        if (++num_tries > config->authserv_maxtries) { 
    107105                                debug(LOG_ERR, "Aborting request"); 
    108106                                free(h_addr); 
     
    115113                free(h_addr); 
    116114        } 
     115 
     116        mark_online(); 
     117 
    117118        /** 
    118119         * TODO: XXX change the PHP so we can harmonize stage as request_type 
  • trunk/wifidog/src/conf.c

    r422 r424  
    4343#include "auth.h" 
    4444#include "firewall.h" 
     45 
     46#include "util.h" 
    4547 
    4648/** @internal 
     
    766768        } 
    767769 
     770        mark_offline(); 
     771 
    768772        pthread_mutex_unlock(&config_mutex); 
    769773 
  • trunk/wifidog/src/fw_iptables.c

    r422 r424  
    140140                debug(LOG_DEBUG, "Loading rule \"%s\" into %s", cmd, chain); 
    141141                iptables_do_command(cmd); 
     142                free(cmd); 
    142143        } 
    143144 
  • trunk/wifidog/src/http.c

    r274 r424  
    4545#include "common.h" 
    4646 
     47#include "util.h" 
     48 
     49#include "../config.h" 
     50 
    4751extern pthread_mutex_t  client_list_mutex; 
    4852 
     
    5862        t_auth_serv     *auth_server = get_auth_server(); 
    5963         
     64        if (!is_online()) { 
     65                /* No point re-directing them to the auth server if we haven't been able to talk 
     66                 * to it for a while */ 
     67                httpdOutput(r, "<html><head><title>Currently unavailable</title></head><body><h1>Uh oh!</h1>"); 
     68                httpdOutput(r, "We apologize, but it seems that we are currently unable to re-direct you to the login screen."); 
     69                httpdOutput(r, "<p>"); 
     70                httpdOutput(r, "The maintainers of this network are aware of this disruption.  We hope that this situation will be resolved soon."); 
     71                httpdOutput(r, "<p>"); 
     72                httpdOutput(r, "Please try again another time."); 
     73                httpdOutput(r, "</body></html>"); 
     74                return; 
     75        } 
     76 
    6077        if (auth_server->authserv_use_ssl) { 
    6178                strcpy(protocol, "https"); 
     
    111128http_callback_about(httpd *webserver, request *r) 
    112129{ 
    113         httpdOutput(r, "<html><body><h1>About:</h1>"); 
    114         httpdOutput(r, "This is WiFiDog. Copyright (C) 2004 and " 
    115                         "released under the GNU GPL license."); 
     130        httpdOutput(r, "<html><head><title>About WiFiDog</title></head><body><h1>About WiFiDog:</h1>"); 
     131        httpdOutput(r, "This is WiFiDog version <b>" VERSION "</b>"); 
     132        httpdOutput(r, "<p>"); 
     133        httpdOutput(r, "Copyright (C) 2004-2005.  This software is released under the GNU GPL license."); 
    116134        httpdOutput(r, "<p>"); 
    117135        httpdOutput(r, "For more information visit <a href='http://" 
     
    150168                        } 
    151169 
    152                         client = client_list_find(r->clientAddr, mac); 
    153  
    154170                        UNLOCK_CLIENT_LIST(); 
    155171 
  • trunk/wifidog/src/ping_thread.c

    r422 r424  
    165165        free(h_addr); 
    166166                 
     167        mark_online(); 
     168 
    167169        snprintf(request, sizeof(request) - 1, "GET %sping/?gw_id=%s HTTP/1.0\n" 
    168170                        "User-Agent: WiFiDog %s\n" 
  • trunk/wifidog/src/util.c

    r422 r424  
    5151 
    5252static pthread_mutex_t ghbn_mutex = PTHREAD_MUTEX_INITIALIZER; 
     53 
     54/* XXX Do these need to be locked ? */ 
     55static time_t last_online_time = 0; 
     56static time_t last_offline_time = 0; 
    5357 
    5458/** Fork a child and execute a shell command, the parent 
     
    108112        if (he == NULL) { 
    109113                free(h_addr); 
     114                mark_offline(); 
    110115                UNLOCK_GHBN(); 
    111116                return NULL; 
    112117        } 
     118 
     119        mark_online(); 
    113120 
    114121        in_addr_temp = (struct in_addr *)he->h_addr_list[0]; 
     
    145152    return (char *)inet_ntoa(in); 
    146153} 
     154 
     155void mark_online() { 
     156        time(&last_online_time); 
     157} 
     158 
     159void mark_offline() { 
     160        time(&last_offline_time); 
     161} 
     162 
     163int is_online() { 
     164        if (last_online_time == 0 || (last_offline_time - last_online_time) >= (config_get_config()->checkinterval * 2) ) { 
     165                /* We're probably offline */ 
     166                return (0); 
     167        } 
     168        else { 
     169                /* We're probably online */ 
     170                return (1); 
     171        } 
     172} 
     173 
  • trunk/wifidog/src/util.h

    r422 r424  
    3636char *get_iface_ip(char *ifname); 
    3737 
     38/* @brief Sets hint that an online action (dns/connect/etc using WAN) succeeded */ 
     39void mark_online(); 
     40/* @brief Sets hint that an online action (dns/connect/etc using WAN) failed */ 
     41void mark_offline(); 
     42/* @brief Returns a guess (true or false) on whether we're online or not based on previous calls to mark_online and mark_offline */ 
     43int is_online(); 
     44 
    3845#define LOCK_GHBN() do { \ 
    3946        debug(LOG_DEBUG, "Locking wd_gethostbyname()"); \