Changeset 438
- Timestamp:
- 02/09/05 00:45:46 (4 years ago)
- Files:
-
- branches/CaptiveDNS/wifidog/ChangeLog (modified) (1 diff)
- branches/CaptiveDNS/wifidog/src/centralserver.c (modified) (5 diffs)
- branches/CaptiveDNS/wifidog/src/centralserver.h (modified) (1 diff)
- branches/CaptiveDNS/wifidog/src/conf.c (modified) (2 diffs)
- branches/CaptiveDNS/wifidog/src/fw_iptables.c (modified) (1 diff)
- branches/CaptiveDNS/wifidog/src/http.c (modified) (2 diffs)
- branches/CaptiveDNS/wifidog/src/ping_thread.c (modified) (4 diffs)
- branches/CaptiveDNS/wifidog/src/util.c (modified) (4 diffs)
- branches/CaptiveDNS/wifidog/src/util.h (modified) (1 diff)
- branches/CaptiveDNS/wifidog/src/wdctl_thread.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/CaptiveDNS/wifidog/ChangeLog
r431 r438 1 1 # $Header$ 2 3 2005-02-09 Mina Naguib <mina@ilesansfil.org> 4 * Consolidated much of the networking calls to the auth servers into a 5 magical function called connect_auth_server() that's responsible for 6 dns lookup, connecting, marking servers bad, marking online/auth_online, 7 and refreshing the firewall rules. 8 * Added new functions mark_auth_online(), mark_auth_offline() and 9 is_auth_online() - similar in nature to is_online() etc. except tailored to 10 decide on auth servers status - currently being called by 11 connect_auth_server() 12 * Different apology in 404 handler depending on whether internet is down or 13 just auth server is down 14 * wdctl status now shows status of is_online and is_auth_online 2 15 3 16 2005-02-06 Mina Naguib <mina@ilesansfil.org> branches/CaptiveDNS/wifidog/src/centralserver.c
r424 r438 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 server's DNS server is probably dead. Try the next 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 = 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 */ branches/CaptiveDNS/wifidog/src/centralserver.h
r137 r438 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_ */ branches/CaptiveDNS/wifidog/src/conf.c
r431 r438 759 759 t_auth_serv *tmp; 760 760 761 /* lock mutex so two different threads both don't mark the same762 * server as bad */763 pthread_mutex_lock(&config_mutex);764 765 761 if (config.auth_servers == bad_server && bad_server->next != NULL) { 766 762 /* Go to the last */ … … 774 770 } 775 771 776 mark_offline(); 777 778 pthread_mutex_unlock(&config_mutex); 779 780 fw_clear_authservers(); 781 fw_set_authservers(); 782 } 772 } branches/CaptiveDNS/wifidog/src/fw_iptables.c
r431 r438 160 160 config = config_get_config(); 161 161 162 LOCK_CONFIG();163 164 162 for (auth_server = config->auth_servers; auth_server != NULL; auth_server = auth_server->next) { 165 if (auth_server->last_ip == NULL || strcmp(auth_server->last_ip, "0.0.0.0") == 0) { 166 iptables_do_command("-t nat -A " TABLE_WIFIDOG_AUTHSERVERS " -d %s -j ACCEPT", auth_server->authserv_hostname); 167 } else { 163 if (auth_server->last_ip && strcmp(auth_server->last_ip, "0.0.0.0") != 0) { 168 164 iptables_do_command("-t nat -A " TABLE_WIFIDOG_AUTHSERVERS " -d %s -j ACCEPT", auth_server->last_ip); 169 165 } 170 166 } 171 167 172 UNLOCK_CONFIG();173 168 } 174 169 branches/CaptiveDNS/wifidog/src/http.c
r428 r438 77 77 78 78 if (!is_online()) { 79 /* No point re-directing them to the auth server if we haven't been able to talk 80 * to it for a while */ 81 httpdOutput(r, "<html><head><title>Currently unavailable</title></head><body><h1>Uh oh!</h1>"); 79 /* The internet connection is down at the moment - apologize and do not redirect anywhere */ 80 httpdOutput(r, "<html><head><title>Internet access currently unavailable</title></head><body><h1>Uh oh!</h1>"); 81 httpdOutput(r, "We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable."); 82 httpdOutput(r, "<p>"); 83 httpdOutput(r, "If at all possible, please notify the owners of this hotspot that the internet connection is out of service."); 84 httpdOutput(r, "<p>"); 85 httpdOutput(r, "The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon."); 86 httpdOutput(r, "<p>"); 87 httpdPrintf(r, "In a while please <a href='%s'>click here</a> to try your request again.", tmp_url); 88 httpdOutput(r, "</body></html>"); 89 debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr); 90 } 91 else if (!is_auth_online()) { 92 /* The auth server is down at the moment - apologize and do not redirect anywhere */ 93 httpdOutput(r, "<html><head><title>Login screen currently unavailable</title></head><body><h1>Uh oh!</h1>"); 82 94 httpdOutput(r, "We apologize, but it seems that we are currently unable to re-direct you to the login screen."); 83 95 httpdOutput(r, "<p>"); 84 96 httpdOutput(r, "The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon."); 85 97 httpdOutput(r, "<p>"); 86 httpdPrintf(r, "In a while please <a href='%s'>click here</a> to tryagain.", tmp_url);98 httpdPrintf(r, "In a couple of minutes please <a href='%s'>click here</a> to try your request again.", tmp_url); 87 99 httpdOutput(r, "</body></html>"); 88 debug(LOG_INFO, "Sent %s an apology since I amnot online - no point sending them to auth server", r->clientAddr);100 debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr); 89 101 } 90 102 else if ((asprintf(&newlocation, "Location: %s://%s:%d%slogin?" … … 115 127 config->gw_id, 116 128 url); 117 debug(LOG_INFO, "Captured %s and re-directed them to login " 118 "page", r->clientAddr); 129 debug(LOG_INFO, "Captured %s and re-directed them to login page", r->clientAddr); 119 130 free(newlocation); 120 131 } branches/CaptiveDNS/wifidog/src/ping_thread.c
r424 r438 92 92 size_t numbytes, 93 93 totalbytes; 94 int sockfd, 95 nfds, 96 done, 97 i; 98 t_auth_serv *auth_server; 99 char request[MAX_BUF], 100 *tmp_addr; 101 struct in_addr *h_addr; 102 struct sockaddr_in their_addr; 94 int sockfd, nfds, done; 95 char request[MAX_BUF]; 103 96 fd_set readfds; 104 97 struct timeval timeout; … … 106 99 debug(LOG_DEBUG, "Entering ping()"); 107 100 108 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 109 debug(LOG_ERR, "socket(): %s", strerror(errno)); 110 exit(1); 111 } 112 113 auth_server = get_auth_server(); 114 115 debug(LOG_DEBUG, "Using auth server %s", 116 auth_server->authserv_hostname); 117 118 debug(LOG_DEBUG, "Resolving IP"); 119 if ((h_addr = (struct in_addr *)wd_gethostbyname(auth_server->authserv_hostname)) == NULL) { 120 debug(LOG_ERR, "Failed to resolve %s via gethostbyname" 121 "(): %s", auth_server->authserv_hostname, 122 strerror(errno)); 123 debug(LOG_ERR, "Bumping auth server to last in line."); 124 mark_auth_server_bad(auth_server); 125 close(sockfd); 101 sockfd = connect_auth_server(); 102 if (sockfd == -1) { 103 /* 104 * No auth servers for me to talk to 105 */ 126 106 return; 127 107 } 128 129 if (auth_server->last_ip == NULL) {130 auth_server->last_ip = strdup(inet_ntoa(*h_addr));131 if (auth_server->last_ip == NULL) {132 debug(LOG_CRIT, "Could not allocate memory, Banzai!");133 exit(-1);134 }135 } else {136 tmp_addr = strdup(inet_ntoa(*h_addr));137 if (strcmp(auth_server->last_ip, tmp_addr) != 0) {138 free(auth_server->last_ip);139 auth_server->last_ip = tmp_addr;140 fw_clear_authservers();141 fw_set_authservers();142 } else {143 free(tmp_addr);144 }145 }146 147 their_addr.sin_family = AF_INET;148 their_addr.sin_port = htons(auth_server->authserv_http_port);149 their_addr.sin_addr = *h_addr;150 memset(&(their_addr.sin_zero), '\0', sizeof(their_addr.sin_zero));151 152 debug(LOG_INFO, "Connecting to auth server %s on port %d",153 auth_server->authserv_hostname,154 auth_server->authserv_http_port);155 156 if (connect(sockfd, (struct sockaddr *)&their_addr,157 sizeof(struct sockaddr)) == -1) {158 debug(LOG_ERR, "connect(): %s", strerror(errno));159 debug(LOG_ERR, "Bumping auth server to last in line.");160 mark_auth_server_bad(auth_server);161 close(sockfd);162 free(h_addr);163 return;164 }165 free(h_addr);166 167 mark_online();168 108 169 109 snprintf(request, sizeof(request) - 1, "GET %sping/?gw_id=%s HTTP/1.0\n" … … 171 111 "Host: %s\n" 172 112 "\n", 173 auth_server->authserv_path,113 config_get_config()->auth_servers->authserv_path, 174 114 config_get_config()->gw_id, 175 115 VERSION, 176 auth_server->authserv_hostname);116 config_get_config()->auth_servers->authserv_hostname); 177 117 178 118 debug(LOG_DEBUG, "HTTP Request to Server: [%s]", request); … … 199 139 MAX_BUF - (totalbytes + 1)); 200 140 if (numbytes < 0) { 201 debug(LOG_ERR, " read(): %s", strerror(errno));202 mark_auth_server_bad(auth_server);141 debug(LOG_ERR, "An error occurred while reading from auth server: %s", strerror(errno)); 142 /* FIXME */ 203 143 close(sockfd); 204 144 return; 205 } else if (numbytes == 0) { 145 } 146 else if (numbytes == 0) { 206 147 done = 1; 207 } else { 148 } 149 else { 208 150 totalbytes += numbytes; 209 debug(LOG_DEBUG, "Read %d bytes, total now %d", 210 numbytes, totalbytes); 151 debug(LOG_DEBUG, "Read %d bytes, total now %d", numbytes, totalbytes); 211 152 } 212 } else if (nfds == 0) { 213 debug(LOG_ERR, "select() timed out"); 214 mark_auth_server_bad(auth_server); 153 } 154 else if (nfds == 0) { 155 debug(LOG_ERR, "Timed out reading data via select() from auth server"); 156 /* FIXME */ 215 157 close(sockfd); 216 158 return; 217 } else if (nfds < 0) { 218 debug(LOG_ERR, "select(): %s", strerror(errno)); 219 mark_auth_server_bad(auth_server); 159 } 160 else if (nfds < 0) { 161 debug(LOG_ERR, "Error reading data via select() from auth server: %s", strerror(errno)); 162 /* FIXME */ 220 163 close(sockfd); 221 164 return; 222 165 } 223 166 } while (!done); 167 close(sockfd); 224 168 225 169 debug(LOG_DEBUG, "Done reading reply, total %d bytes", totalbytes); 226 170 227 numbytes = totalbytes; 228 229 request[numbytes] = '\0'; 230 231 close(sockfd); 171 request[totalbytes] = '\0'; 232 172 233 173 debug(LOG_DEBUG, "HTTP Response from Server: [%s]", request); 234 174 235 if (!strstr(request, "Pong")) { 236 debug(LOG_ERR, "Primary auth server offline"); 237 debug(LOG_ERR, "Bumping auth server to last in line."); 238 mark_auth_server_bad(auth_server); 239 return; 175 if (strstr(request, "Pong") == 0) { 176 debug(LOG_WARNING, "Auth server did NOT say pong!"); 177 /* FIXME */ 240 178 } 241 242 debug(LOG_DEBUG, "Auth Server Says: Pong"); 179 else { 180 debug(LOG_DEBUG, "Auth Server Says: Pong"); 181 } 182 243 183 return; 244 184 } branches/CaptiveDNS/wifidog/src/util.c
r426 r438 55 55 static time_t last_online_time = 0; 56 56 static time_t last_offline_time = 0; 57 static time_t last_auth_online_time = 0; 58 static time_t last_auth_offline_time = 0; 57 59 58 60 /** Fork a child and execute a shell command, the parent … … 112 114 if (he == NULL) { 113 115 free(h_addr); 116 UNLOCK_GHBN(); 114 117 mark_offline(); 115 UNLOCK_GHBN();116 118 return NULL; 117 119 } … … 156 158 157 159 void mark_online() { 160 int isonline; 161 isonline = is_online(); 158 162 time(&last_online_time); 163 if (!isonline) { 164 debug(LOG_INFO, "ONLINE status changed to ON"); 165 } 159 166 } 160 167 161 168 void mark_offline() { 169 int isonline; 170 isonline = is_online(); 162 171 time(&last_offline_time); 172 /* If we're offline it definately means the auth server is offline */ 173 mark_auth_offline(); 174 if (isonline) { 175 debug(LOG_INFO, "ONLINE status changed to OFF"); 176 } 163 177 } 164 178 … … 174 188 } 175 189 190 void mark_auth_online() { 191 int isauthonline; 192 isauthonline = is_auth_online(); 193 time(&last_auth_online_time); 194 /* If auth server is online it means we're definately online */ 195 mark_online(); 196 if (!isauthonline) { 197 debug(LOG_INFO, "AUTH_ONLINE status changed to ON"); 198 } 199 } 200 201 void mark_auth_offline() { 202 int isauthonline; 203 isauthonline = is_auth_online(); 204 time(&last_auth_offline_time); 205 if (isauthonline) { 206 debug(LOG_INFO, "AUTH_ONLINE status changed to OFF"); 207 } 208 } 209 210 int is_auth_online() { 211 if (!is_online()) { 212 /* If we're not online auth is definately not online :) */ 213 return (0); 214 } 215 else if (last_auth_online_time == 0 || (last_auth_offline_time - last_auth_online_time) >= (config_get_config()->checkinterval * 2) ) { 216 /* Auth is probably offline */ 217 return (0); 218 } 219 else { 220 /* Auth is probably online */ 221 return (1); 222 } 223 } 224 branches/CaptiveDNS/wifidog/src/util.h
r424 r438 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()"); \ branches/CaptiveDNS/wifidog/src/wdctl_thread.c
r422 r438 263 263 UNLOCK_CONFIG(); 264 264 265 snprintf((buffer + len), (sizeof(buffer) - len), "\nis_online: %s\n", (is_online() ? "yes" : "no")); 266 len = strlen(buffer); 267 268 snprintf((buffer + len), (sizeof(buffer) - len), "is_auth_online: %s\n", (is_auth_online() ? "yes" : "no")); 269 len = strlen(buffer); 270 265 271 write(fd, buffer, len); 266 272 }
