Changeset 469
- Timestamp:
- 02/20/05 17:55:20 (4 years ago)
- Files:
-
- trunk/wifidog/ChangeLog (modified) (1 diff)
- trunk/wifidog/src/centralserver.c (modified) (6 diffs)
- trunk/wifidog/src/centralserver.h (modified) (1 diff)
- trunk/wifidog/src/conf.c (modified) (2 diffs)
- trunk/wifidog/src/fw_iptables.c (modified) (1 diff)
- trunk/wifidog/src/http.c (modified) (2 diffs)
- trunk/wifidog/src/ping_thread.c (modified) (5 diffs)
- trunk/wifidog/src/util.c (modified) (4 diffs)
- trunk/wifidog/src/util.h (modified) (1 diff)
- trunk/wifidog/src/wdctl_thread.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wifidog/ChangeLog
r467 r469 6 6 instances of original with safe versions in all files 7 7 * Fix memory leak in iptables_fw_counters_update 8 * Partial merge from CaptiveDNS branch: Consolidated much of the networking 9 calls to the auth servers into a magical function called connect_auth_server() 10 that's responsible for dns lookup, connecting, marking servers bad, marking 11 online/auth_online, and refreshing the firewall rules. 12 * Partial merge from CaptiveDNS branch: Added new functions mark_auth_online(), 13 mark_auth_offline() and is_auth_online() - similar in nature to is_online() 14 etc. except tailored to decide on auth servers status - currently being called by 15 connect_auth_server() 16 * Partial merge from CaptiveDNS branch: Different apology in 404 handler 17 depending on whether internet is down or just auth server is down 18 * Partial merge from CaptiveDNS branch: wdctl status now shows status of 19 is_online and is_auth_online 8 20 9 21 2005-02-16 Philippe April <philippe@ilesansfil.org> trunk/wifidog/src/centralserver.c
r424 r469 40 40 41 41 #include "common.h" 42 42 #include "safe.h" 43 43 #include "util.h" 44 44 #include "auth.h" … … 47 47 #include "centralserver.h" 48 48 #include "../config.h" 49 50 extern pthread_mutex_t config_mutex; 49 51 50 52 /** Initiates a transaction with the auth server, either to authenticate or to update the traffic counters at the server … … 60 62 auth_server_request(t_authresponse *authresponse, char *request_type, char *ip, char *mac, char *token, long int incoming, long int outgoing) 61 63 { 62 int sockfd , num_tries, done;63 size_t numbytes, totalbytes;64 int sockfd; 65 size_t numbytes, totalbytes; 64 66 char buf[MAX_BUF]; 65 struct in_addr *h_addr;66 struct sockaddr_in their_addr;67 67 char *tmp; 68 s_config *config = config_get_config();69 t_auth_serv *auth_server = NULL;70 68 71 69 /* Blanket default is failed. */ 72 70 authresponse->authcode = AUTH_VALIDATION_FAILED; 73 71 74 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 75 debug(LOG_ERR, "socket(): %s", strerror(errno)); 76 exit(1); 77 } 78 79 num_tries = 0; 80 done = 0; 81 while (!done && ((auth_server = get_auth_server()) != NULL)) { 82 if ((h_addr = wd_gethostbyname(auth_server->authserv_hostname)) == NULL) { 83 debug(LOG_ERR, "Failed to resolve %s via gethostbyname" 84 "(): %s", auth_server->authserv_hostname, 85 strerror(errno)); 86 close(sockfd); 87 return(-1); 88 } 89 90 their_addr.sin_family = AF_INET; 91 their_addr.sin_port = htons(auth_server->authserv_http_port); 92 their_addr.sin_addr = *h_addr; 93 memset(&(their_addr.sin_zero), '\0', sizeof(their_addr.sin_zero)); 94 95 debug(LOG_INFO, "Connecting to auth server %s on port %d", 96 auth_server->authserv_hostname, 97 auth_server->authserv_http_port); 98 99 if (connect(sockfd, (struct sockaddr *)&their_addr, 100 sizeof(struct sockaddr)) == -1) { 101 debug(LOG_ERR, "connect(): %s", strerror(errno)); 102 debug(LOG_ERR, "Trying next Auth Server (if any)"); 103 mark_auth_server_bad(auth_server); 104 if (++num_tries > config->authserv_maxtries) { 105 debug(LOG_ERR, "Aborting request"); 106 free(h_addr); 107 close(sockfd); 108 return(-1); /* non-fatal */ 109 } 110 } else { 111 done = 1; 112 } 113 free(h_addr); 114 } 115 116 mark_online(); 72 sockfd = connect_auth_server(); 73 if (sockfd == -1) { 74 /* Could not connect to any auth server */ 75 return (-1); 76 } 117 77 118 78 /** … … 126 86 "Host: %s\n" 127 87 "\n", 128 auth_server->authserv_path, request_type, ip, mac,88 config_get_config()->auth_servers->authserv_path, request_type, ip, mac, 129 89 token, incoming, outgoing, VERSION, 130 auth_server->authserv_hostname); 90 config_get_config()->auth_servers->authserv_hostname); 91 92 debug(LOG_DEBUG, "Sending HTTP request to auth server: [%s]\n", buf); 131 93 send(sockfd, buf, strlen(buf), 0); 132 133 debug(LOG_DEBUG, "Sending HTTP request to auth server: [%s]\n", buf);134 94 135 95 numbytes = totalbytes = 0; … … 139 99 140 100 if (numbytes == -1) { 141 debug(LOG_ERR, " read(): %s", strerror(errno));101 debug(LOG_ERR, "Error reading from auth server: %s", strerror(errno)); 142 102 close(sockfd); 143 103 return(-1); 144 104 } 145 146 numbytes = totalbytes;147 148 buf[numbytes] = '\0';149 150 105 close(sockfd); 151 106 107 buf[totalbytes] = '\0'; 152 108 debug(LOG_DEBUG, "HTTP Response from Server: [%s]", buf); 153 109 154 110 if ((tmp = strstr(buf, "Auth: "))) { 155 111 if (sscanf(tmp, "Auth: %d", (int *)&authresponse->authcode) == 1) { 156 debug(LOG_INFO, "Auth server returned authentication code %d", 157 authresponse->authcode); 112 debug(LOG_INFO, "Auth server returned authentication code %d", authresponse->authcode); 158 113 return(authresponse->authcode); 159 114 } else { 160 debug(LOG_WARNING, "Auth server did not return expected information");115 debug(LOG_WARNING, "Auth server did not return expected authentication code"); 161 116 return(AUTH_ERROR); 162 117 } … … 168 123 } 169 124 125 /* Tries really hard to connect to an auth server. Returns a file descriptor, -1 on error 126 */ 127 int connect_auth_server() { 128 int sockfd; 129 130 LOCK_CONFIG(); 131 sockfd = _connect_auth_server(0); 132 UNLOCK_CONFIG(); 133 134 if (sockfd == -1) { 135 debug(LOG_ERR, "Failed to connect to any of the auth servers"); 136 mark_auth_offline(); 137 } 138 else { 139 debug(LOG_DEBUG, "Connected to auth server"); 140 mark_auth_online(); 141 } 142 return (sockfd); 143 } 144 145 /* Helper function called by connect_auth_server() to do the actual work including recursion - do not call directly 146 @param level recursion level indicator 147 */ 148 int _connect_auth_server(int level) { 149 s_config *config = config_get_config(); 150 t_auth_serv *auth_server = NULL; 151 struct in_addr *h_addr; 152 int num_servers = 0; 153 char * hostname = NULL; 154 char * popular_servers[] = { 155 "www.google.com" 156 , "www.yahoo.com" 157 , NULL 158 }; 159 char ** popularserver; 160 char * ip; 161 struct sockaddr_in their_addr; 162 int sockfd; 163 164 level++; 165 166 /* 167 * Let's calculate the number of servers we have 168 */ 169 for (auth_server = config->auth_servers; auth_server; auth_server = auth_server->next) { 170 num_servers++; 171 } 172 debug(LOG_DEBUG, "Level %d: Calculated %d auth servers in list", level, num_servers); 173 174 if (level > num_servers) { 175 /* 176 * We've called ourselves too many times 177 * That means we've cycled through all the servers in the server list at least once and none are accessible 178 */ 179 return (-1); 180 } 181 182 /* 183 * Let's resolve the hostname of the top server to an IP address 184 */ 185 auth_server = config->auth_servers; 186 hostname = auth_server->authserv_hostname; 187 debug(LOG_DEBUG, "Level %d: Resolving auth server [%s]", level, hostname); 188 h_addr = wd_gethostbyname(hostname); 189 if (!h_addr) { 190 /* 191 * DNS resolving it failed 192 * 193 * Can we resolve any of the popular servers ? 194 */ 195 debug(LOG_DEBUG, "Level %d: Resolving auth server [%s] failed", level, hostname); 196 197 for (popularserver = popular_servers; *popularserver; popularserver++) { 198 debug(LOG_DEBUG, "Level %d: Resolving popular server [%s]", level, *popularserver); 199 h_addr = wd_gethostbyname(*popularserver); 200 if (h_addr) { 201 debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] succeeded = [%s]", level, *popularserver, inet_ntoa(*h_addr)); 202 break; 203 } 204 else { 205 debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] failed", level, *popularserver); 206 } 207 } 208 209 if (h_addr) { 210 free (h_addr); 211 /* 212 * Yes 213 * 214 * The auth server's DNS server is probably dead. Try the next auth server 215 */ 216 debug(LOG_DEBUG, "Level %d: Marking auth server [%s] as bad and trying next if possible", level, hostname); 217 if (auth_server->last_ip) { 218 free(auth_server->last_ip); 219 auth_server->last_ip = NULL; 220 } 221 mark_auth_server_bad(auth_server); 222 return _connect_auth_server(level); 223 } 224 else { 225 /* 226 * No 227 * 228 * It's probably safe to assume that the internet connection is malfunctioning 229 * and nothing we can do will make it work 230 */ 231 debug(LOG_DEBUG, "Level %d: Failed to resolve auth server and all popular servers. The internet connection is probably down", level); 232 return(-1); 233 } 234 } 235 else { 236 /* 237 * DNS resolving was successful 238 */ 239 ip = safe_strdup(inet_ntoa(*h_addr)); 240 debug(LOG_DEBUG, "Level %d: Resolving auth server [%s] succeeded = [%s]", level, hostname, ip); 241 242 if (!auth_server->last_ip || strcmp(auth_server->last_ip, ip) != 0) { 243 /* 244 * But the IP address is different from the last one we knew 245 * Update it 246 */ 247 debug(LOG_DEBUG, "Level %d: Updating last_ip IP of server [%s] to [%s]", level, hostname, ip); 248 if (auth_server->last_ip) free(auth_server->last_ip); 249 auth_server->last_ip = ip; 250 251 /* Update firewall rules */ 252 fw_clear_authservers(); 253 fw_set_authservers(); 254 } 255 else { 256 /* 257 * IP is the same as last time 258 */ 259 free(ip); 260 } 261 262 /* 263 * Connect to it 264 */ 265 debug(LOG_DEBUG, "Level %d: Connecting to auth server %s:%d", level, hostname, auth_server->authserv_http_port); 266 their_addr.sin_family = AF_INET; 267 their_addr.sin_port = htons(auth_server->authserv_http_port); 268 their_addr.sin_addr = *h_addr; 269 memset(&(their_addr.sin_zero), '\0', sizeof(their_addr.sin_zero)); 270 free (h_addr); 271 272 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 273 debug(LOG_ERR, "Level %d: Failed to create a new SOCK_STREAM socket: %s", strerror(errno)); 274 return(-1); 275 } 276 277 if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) { 278 /* 279 * Failed to connect 280 * Mark the server as bad and try the next one 281 */ 282 debug(LOG_DEBUG, "Level %d: Failed to connect to auth server %s:%d (%s). Marking it as bad and trying next if possible", level, hostname, auth_server->authserv_http_port, strerror(errno)); 283 close(sockfd); 284 mark_auth_server_bad(auth_server); 285 return _connect_auth_server(level); 286 } 287 else { 288 /* 289 * We have successfully connected 290 */ 291 debug(LOG_DEBUG, "Level %d: Successfully connected to auth server %s:%d", level, hostname, auth_server->authserv_http_port); 292 return sockfd; 293 } 294 } 295 } 296 297 /* config->authserv_maxtries */ trunk/wifidog/src/centralserver.h
r137 r469 38 38 int auth_server_request(t_authresponse *authresponse, char *request_type, char *ip, char *mac, char *token, long int incoming, long int outgoing); 39 39 40 /** @brief Tries really hard to connect to an auth server. Returns a connected file descriptor or -1 on error */ 41 int connect_auth_server(); 42 43 /** @brief Helper function called by connect_auth_server() to do the actual work including recursion - do not call directly */ 44 int _connect_auth_server(int level); 45 40 46 #endif /* _CENTRALSERVER_H_ */ trunk/wifidog/src/conf.c
r467 r469 746 746 t_auth_serv *tmp; 747 747 748 /* lock mutex so two different threads both don't mark the same749 * server as bad */750 pthread_mutex_lock(&config_mutex);751 752 748 if (config.auth_servers == bad_server && bad_server->next != NULL) { 753 749 /* Go to the last */ … … 761 757 } 762 758 763 mark_offline(); 764 765 pthread_mutex_unlock(&config_mutex); 766 767 fw_clear_authservers(); 768 fw_set_authservers(); 769 } 759 } trunk/wifidog/src/fw_iptables.c
r467 r469 168 168 config = config_get_config(); 169 169 170 LOCK_CONFIG();171 172 170 for (auth_server = config->auth_servers; auth_server != NULL; auth_server = auth_server->next) { 173 if (auth_server->last_ip == NULL || strcmp(auth_server->last_ip, "0.0.0.0") == 0) { 174 iptables_do_command("-t filter -A " TABLE_WIFIDOG_AUTHSERVERS " -d %s -j ACCEPT", auth_server->authserv_hostname); 175 } else { 171 if (auth_server->last_ip && strcmp(auth_server->last_ip, "0.0.0.0") != 0) { 176 172 iptables_do_command("-t filter -A " TABLE_WIFIDOG_AUTHSERVERS " -d %s -j ACCEPT", auth_server->last_ip); 177 173 } 178 174 } 179 175 180 UNLOCK_CONFIG();181 176 } 182 177 trunk/wifidog/src/http.c
r467 r469 78 78 79 79 if (!is_online()) { 80 /* No point re-directing them to the auth server if we haven't been able to talk 81 * to it for a while */ 82 httpdOutput(r, "<html><head><title>Currently unavailable</title></head><body><h1>Uh oh!</h1>"); 80 /* The internet connection is down at the moment - apologize and do not redirect anywhere */ 81 httpdOutput(r, "<html><head><title>Internet access currently unavailable</title></head><body><h1>Uh oh!</h1>"); 82 httpdOutput(r, "We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable."); 83 httpdOutput(r, "<p>"); 84 httpdOutput(r, "If at all possible, please notify the owners of this hotspot that the internet connection is out of service."); 85 httpdOutput(r, "<p>"); 86 httpdOutput(r, "The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon."); 87 httpdOutput(r, "<p>"); 88 httpdPrintf(r, "In a while please <a href='%s'>click here</a> to try your request again.", tmp_url); 89 httpdOutput(r, "</body></html>"); 90 debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr); 91 } 92 else if (!is_auth_online()) { 93 /* The auth server is down at the moment - apologize and do not redirect anywhere */ 94 httpdOutput(r, "<html><head><title>Login screen currently unavailable</title></head><body><h1>Uh oh!</h1>"); 83 95 httpdOutput(r, "We apologize, but it seems that we are currently unable to re-direct you to the login screen."); 84 96 httpdOutput(r, "<p>"); 85 97 httpdOutput(r, "The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon."); 86 98 httpdOutput(r, "<p>"); 87 httpdPrintf(r, "In a while please <a href='%s'>click here</a> to tryagain.", tmp_url);99 httpdPrintf(r, "In a couple of minutes please <a href='%s'>click here</a> to try your request again.", tmp_url); 88 100 httpdOutput(r, "</body></html>"); 89 debug(LOG_INFO, "Sent %s an apology since I amnot online - no point sending them to auth server", r->clientAddr);101 debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr); 90 102 } 91 103 else { … … 114 126 config->gw_id, 115 127 url); 116 debug(LOG_INFO, "Captured %s and re-directed them to login " 117 "page", r->clientAddr); 128 debug(LOG_INFO, "Captured %s and re-directed them to login page", r->clientAddr); 118 129 free(newlocation); 119 130 } trunk/wifidog/src/ping_thread.c
r467 r469 98 98 size_t numbytes, 99 99 totalbytes; 100 int sockfd, 101 nfds, 102 done, 103 i; 104 t_auth_serv *auth_server; 105 char request[MAX_BUF], 106 *tmp_addr; 107 struct in_addr *h_addr; 108 struct sockaddr_in their_addr; 100 int sockfd, nfds, done; 101 char request[MAX_BUF]; 109 102 fd_set readfds; 110 103 struct timeval timeout; … … 117 110 debug(LOG_DEBUG, "Entering ping()"); 118 111 119 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 120 debug(LOG_ERR, "socket(): %s", strerror(errno)); 121 exit(1); 122 } 123 124 auth_server = get_auth_server(); 125 126 debug(LOG_DEBUG, "Using auth server %s", 127 auth_server->authserv_hostname); 128 129 debug(LOG_DEBUG, "Resolving IP"); 130 if ((h_addr = (struct in_addr *)wd_gethostbyname(auth_server->authserv_hostname)) == NULL) { 131 debug(LOG_ERR, "Failed to resolve %s via gethostbyname" 132 "(): %s", auth_server->authserv_hostname, 133 strerror(errno)); 134 debug(LOG_ERR, "Bumping auth server to last in line."); 135 mark_auth_server_bad(auth_server); 136 close(sockfd); 112 sockfd = connect_auth_server(); 113 if (sockfd == -1) { 114 /* 115 * No auth servers for me to talk to 116 */ 137 117 return; 138 118 } 139 140 if (auth_server->last_ip == NULL) {141 auth_server->last_ip = safe_strdup(inet_ntoa(*h_addr));142 } else {143 tmp_addr = safe_strdup(inet_ntoa(*h_addr));144 if (strcmp(auth_server->last_ip, tmp_addr) != 0) {145 free(auth_server->last_ip);146 auth_server->last_ip = tmp_addr;147 fw_clear_authservers();148 fw_set_authservers();149 } else {150 free(tmp_addr);151 }152 }153 154 their_addr.sin_family = AF_INET;155 their_addr.sin_port = htons(auth_server->authserv_http_port);156 their_addr.sin_addr = *h_addr;157 memset(&(their_addr.sin_zero), '\0', sizeof(their_addr.sin_zero));158 159 debug(LOG_INFO, "Connecting to auth server %s on port %d",160 auth_server->authserv_hostname,161 auth_server->authserv_http_port);162 163 if (connect(sockfd, (struct sockaddr *)&their_addr,164 sizeof(struct sockaddr)) == -1) {165 debug(LOG_ERR, "connect(): %s", strerror(errno));166 debug(LOG_ERR, "Bumping auth server to last in line.");167 mark_auth_server_bad(auth_server);168 close(sockfd);169 free(h_addr);170 return;171 }172 free(h_addr);173 174 mark_online();175 119 176 120 /* … … 206 150 "Host: %s\n" 207 151 "\n", 208 auth_server->authserv_path,152 config_get_config()->auth_servers->authserv_path, 209 153 config_get_config()->gw_id, 210 154 sys_uptime, … … 213 157 (long unsigned int)((long unsigned int)time(NULL) - (long unsigned int)started_time), 214 158 VERSION, 215 auth_server->authserv_hostname);159 config_get_config()->auth_servers->authserv_hostname); 216 160 217 161 debug(LOG_DEBUG, "HTTP Request to Server: [%s]", request); … … 238 182 MAX_BUF - (totalbytes + 1)); 239 183 if (numbytes < 0) { 240 debug(LOG_ERR, " read(): %s", strerror(errno));241 mark_auth_server_bad(auth_server);184 debug(LOG_ERR, "An error occurred while reading from auth server: %s", strerror(errno)); 185 /* FIXME */ 242 186 close(sockfd); 243 187 return; 244 } else if (numbytes == 0) { 188 } 189 else if (numbytes == 0) { 245 190 done = 1; 246 } else { 191 } 192 else { 247 193 totalbytes += numbytes; 248 debug(LOG_DEBUG, "Read %d bytes, total now %d", 249 numbytes, totalbytes);250 }251 }else if (nfds == 0) {252 debug(LOG_ERR, " select() timed out");253 mark_auth_server_bad(auth_server);194 debug(LOG_DEBUG, "Read %d bytes, total now %d", numbytes, totalbytes); 195 } 196 } 197 else if (nfds == 0) { 198 debug(LOG_ERR, "Timed out reading data via select() from auth server"); 199 /* FIXME */ 254 200 close(sockfd); 255 201 return; 256 } else if (nfds < 0) { 257 debug(LOG_ERR, "select(): %s", strerror(errno)); 258 mark_auth_server_bad(auth_server); 202 } 203 else if (nfds < 0) { 204 debug(LOG_ERR, "Error reading data via select() from auth server: %s", strerror(errno)); 205 /* FIXME */ 259 206 close(sockfd); 260 207 return; 261 208 } 262 209 } while (!done); 210 close(sockfd); 263 211 264 212 debug(LOG_DEBUG, "Done reading reply, total %d bytes", totalbytes); 265 213 266 numbytes = totalbytes; 267 268 request[numbytes] = '\0'; 269 270 close(sockfd); 214 request[totalbytes] = '\0'; 271 215 272 216 debug(LOG_DEBUG, "HTTP Response from Server: [%s]", request); 273 217 274 if ( !strstr(request, "Pong")) {275 debug(LOG_ ERR, "Primary auth server offline");276 debug(LOG_ERR, "Bumping auth server to last in line.");277 mark_auth_server_bad(auth_server);278 return;279 }280 281 debug(LOG_DEBUG, "Auth Server Says: Pong"); 218 if (strstr(request, "Pong") == 0) { 219 debug(LOG_WARNING, "Auth server did NOT say pong!"); 220 /* FIXME */ 221 } 222 else { 223 debug(LOG_DEBUG, "Auth Server Says: Pong"); 224 } 225 282 226 return; 283 227 } trunk/wifidog/src/util.c
r467 r469 56 56 static time_t last_online_time = 0; 57 57 static time_t last_offline_time = 0; 58 static time_t last_auth_online_time = 0; 59 static time_t last_auth_offline_time = 0; 58 60 59 61 /** Fork a child and execute a shell command, the parent … … 110 112 if (he == NULL) { 111 113 free(h_addr); 114 UNLOCK_GHBN(); 112 115 mark_offline(); 113 UNLOCK_GHBN();114 116 return NULL; 115 117 } … … 154 156 155 157 void mark_online() { 158 int isonline; 159 isonline = is_online(); 156 160 time(&last_online_time); 161 if (!isonline) { 162 debug(LOG_INFO, "ONLINE status changed to ON"); 163 } 157 164 } 158 165 159 166 void mark_offline() { 167 int isonline; 168 isonline = is_online(); 160 169 time(&last_offline_time); 170 /* If we're offline it definately means the auth server is offline */ 171 mark_auth_offline(); 172 if (isonline) { 173 debug(LOG_INFO, "ONLINE status changed to OFF"); 174 } 161 175 } 162 176 … … 172 186 } 173 187 188 void mark_auth_online() { 189 int isauthonline; 190 isauthonline = is_auth_online(); 191 time(&last_auth_online_time); 192 /* If auth server is online it means we're definately online */ 193 mark_online(); 194 if (!isauthonline) { 195 debug(LOG_INFO, "AUTH_ONLINE status changed to ON"); 196 } 197 } 198 199 void mark_auth_offline() { 200 int isauthonline; 201 isauthonline = is_auth_online(); 202 time(&last_auth_offline_time); 203 if (isauthonline) { 204 debug(LOG_INFO, "AUTH_ONLINE status changed to OFF"); 205 } 206 } 207 208 int is_auth_online() { 209 if (!is_online()) { 210 /* If we're not online auth is definately not online :) */ 211 return (0); 212 } 213 else if (last_auth_online_time == 0 || (last_auth_offline_time - last_auth_online_time) >= (config_get_config()->checkinterval * 2) ) { 214 /* Auth is probably offline */ 215 return (0); 216 } 217 else { 218 /* Auth is probably online */ 219 return (1); 220 } 221 } 222 trunk/wifidog/src/util.h
r424 r469 43 43 int is_online(); 44 44 45 /* @brief Sets hint that an auth server online action succeeded */ 46 void mark_auth_online(); 47 /* @brief Sets hint that an auth server online action failed */ 48 void mark_auth_offline(); 49 /* @brief Returns a guess (true or false) on whether we're an auth server is online or not based on previous calls to mark_auth_online and mark_auth_offline */ 50 int is_auth_online(); 51 45 52 #define LOCK_GHBN() do { \ 46 53 debug(LOG_DEBUG, "Locking wd_gethostbyname()"); \ trunk/wifidog/src/wdctl_thread.c
r463 r469 225 225 uptime -= minutes * 60; 226 226 seconds = uptime; 227 snprintf((buffer + len), (sizeof(buffer) - len), "Uptime: %ud %uh %um %us\n\n", days, hours, minutes, seconds); 227 228 snprintf((buffer + len), (sizeof(buffer) - len), "Uptime: %ud %uh %um %us\n", days, hours, minutes, seconds); 229 len = strlen(buffer); 230 231 snprintf((buffer + len), (sizeof(buffer) - len), "is_online: %s\n", (is_online() ? "yes" : "no")); 232 len = strlen(buffer); 233 234 snprintf((buffer + len), (sizeof(buffer) - len), "is_auth_online: %s\n\n", (is_auth_online() ? "yes" : "no")); 228 235 len = strlen(buffer); 229 236 … … 277 284 278 285 UNLOCK_CONFIG(); 279 286 280 287 write(fd, buffer, len); 281 288 }
