From 9cd7285680eee801ce8b4cc26621c0cf0e0d4505 Mon Sep 17 00:00:00 2001 From: Warren Baker Date: Mon, 16 May 2011 16:25:32 +0200 Subject: Ensure that $timestamp is only ever written out if it contains a value and let file be retained through reboots. --- usr/local/bin/captiveportal_gather_stats.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/usr/local/bin/captiveportal_gather_stats.php b/usr/local/bin/captiveportal_gather_stats.php index 5fe1c6b..823b28f 100644 --- a/usr/local/bin/captiveportal_gather_stats.php +++ b/usr/local/bin/captiveportal_gather_stats.php @@ -43,7 +43,7 @@ $concurrent_users = $no_users; $current_user_count = 0; /* tmp file to use to store old data (per interface)*/ -$tmpfile = "{$g['tmp_path']}/captiveportal_online_users"; +$tmpfile = "{$g['vardb_path']}/captiveportal_online_users"; $type = $argv[1]; @@ -82,12 +82,14 @@ if ($type == "loggedin") { $current_user_count = $current_user_count + 1; } - // Write out the latest timestamp - $fd = @fopen($tmpfile, "w"); - if ($fd) { - fwrite($fd, $timestamp); + // Write out the latest timestamp but not if it is empty + if (!empty($timestamp)) { + $fd = @fopen($tmpfile, "w"); + if ($fd) { + fwrite($fd, $timestamp); + } + @fclose($fd); } - @fclose($fd); /* If $timestamp is less than or equal to previous_user_timestamp return 0, * as we only want the 'X' number of users logged in since last RRD poll. -- cgit v1.1