Index: trunk/wifidog/src/util.c
===================================================================
--- trunk/wifidog/src/util.c	(revision 467)
+++ trunk/wifidog/src/util.c	(revision 469)
@@ -56,4 +56,6 @@
 static time_t last_online_time = 0;
 static time_t last_offline_time = 0;
+static time_t last_auth_online_time = 0;
+static time_t last_auth_offline_time = 0;
 
 /** Fork a child and execute a shell command, the parent
@@ -110,6 +112,6 @@
 	if (he == NULL) {
 		free(h_addr);
+		UNLOCK_GHBN();
 		mark_offline();
-		UNLOCK_GHBN();
 		return NULL;
 	}
@@ -154,9 +156,21 @@
 
 void mark_online() {
+	int isonline;
+	isonline = is_online();
 	time(&last_online_time);
+	if (!isonline) {
+		debug(LOG_INFO, "ONLINE status changed to ON");
+	}
 }
 
 void mark_offline() {
+	int isonline;
+	isonline = is_online();
 	time(&last_offline_time);
+	/* If we're offline it definately means the auth server is offline */
+	mark_auth_offline();
+	if (isonline) {
+		debug(LOG_INFO, "ONLINE status changed to OFF");
+	}
 }
 
@@ -172,2 +186,37 @@
 }
 
+void mark_auth_online() {
+	int isauthonline;
+	isauthonline = is_auth_online();
+	time(&last_auth_online_time);
+	/* If auth server is online it means we're definately online */
+	mark_online();
+	if (!isauthonline) {
+		debug(LOG_INFO, "AUTH_ONLINE status changed to ON");
+	}
+}
+
+void mark_auth_offline() {
+	int isauthonline;
+	isauthonline = is_auth_online();
+	time(&last_auth_offline_time);
+	if (isauthonline) {
+		debug(LOG_INFO, "AUTH_ONLINE status changed to OFF");
+	}
+}
+
+int is_auth_online() {
+	if (!is_online()) {
+		/* If we're not online auth is definately not online :) */
+		return (0);
+	}
+	else if (last_auth_online_time == 0 || (last_auth_offline_time - last_auth_online_time) >= (config_get_config()->checkinterval * 2) ) {
+		/* Auth is  probably offline */
+		return (0);
+	}
+	else {
+		/* Auth is probably online */
+		return (1);
+	}
+}
+
