From f56a73f1adbd41570b3cbdede3d544e0043583d8 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Wed, 12 Dec 2007 17:45:08 +0000 Subject: Correctly remove old clients correctly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Submitted to m0n0wall list by Ršnnblom JanŚke /Teknous --- etc/inc/captiveportal.inc | 54 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'etc/inc/captiveportal.inc') diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc index a0f58f1..b06176e 100644 --- a/etc/inc/captiveportal.inc +++ b/etc/inc/captiveportal.inc @@ -376,8 +376,8 @@ EOD; $cprules .= <<= $idletimeout)) { $timedout = true; $term_cause = 4; // Idle-Timeout @@ -813,25 +822,37 @@ function captiveportal_get_radius_servers() { return false; } -/* lock captive portal information, decide that the lock file is stale after - 10 seconds */ +/* lock captive portal information, decide that the lock file is stale after + 10 minutes and EXIT the process to not risk dataloss, issue warning in syslog every 1 minutes */ function captiveportal_lock() { global $lockfile; - $n = 0; - while ($n < 10) { + $n = 1; + while ($n) { /* open the lock file in append mode to avoid race condition */ if ($fd = @fopen($lockfile, "x")) { /* succeeded */ fclose($fd); + if($n > 10) { + captiveportal_syslog("LOCKINFO: Waiting for lock for $n seconds/s!"); + } return; } else { /* file locked, wait and try again */ sleep(1); - $n++; + + if(($n % 60) == 0) { + captiveportal_syslog("LOCKWARNING: waiting for lock for " . $n/60 . " minute/s!"); + if(($n % 600) == 0) { + captiveportal_syslog("LOCKERROR: waiting for lock for 10 minute/s - EXITING PROCESS!"); + die("Can't get a lock"); + } + } } + $n++; } + /* we never get here */ } /* unlock captive portal information file */ @@ -846,14 +867,23 @@ function captiveportal_unlock() { /* log successful captive portal authentication to syslog */ /* part of this code from php.net */ function captiveportal_logportalauth($user,$mac,$ip,$status, $message = null) { - define_syslog_variables(); $message = trim($message); - openlog("logportalauth", LOG_PID, LOG_LOCAL4); // Log it if (!$message) - syslog(LOG_INFO, "$status: $user, $mac, $ip"); + $message = "$status: $user, $mac, $ip"; else - syslog(LOG_INFO, "$status: $user, $mac, $ip, $message"); + $message = "$status: $user, $mac, $ip, $message"; + captiveportal_syslog($message); + closelog(); +} + +/* log simple messages to syslog */ +function captiveportal_syslog($message) { + define_syslog_variables(); + $message = trim($message); + openlog("logportalauth", LOG_PID, LOG_LOCAL4); + // Log it + syslog(LOG_INFO, $message); closelog(); } -- cgit v1.1