From 58d585e6fe1d31f2344a0734afb97d1ed26376d7 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 13 Dec 2015 16:16:39 +0000 Subject: [PATCH] Updated daily.sh/daily.php to support removing users that have not logged in for X days - Radius only for now --- daily.php | 18 +++++++++++++++++- daily.sh | 5 +++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/daily.php b/daily.php index 40d4cd10a6..1c3e4d04fb 100644 --- a/daily.php +++ b/daily.php @@ -30,7 +30,7 @@ Take a look at https://dev.mysql.com/doc/refman/5.6/en/innodb-buffer-pool.html f The ' . $config['project_name'] . ' team.'; send_mail($config['alert']['default_mail'],$subject,$message,$html=false); - } + } echo warn_innodb_buffer($innodb_buffer); exit(2); } @@ -110,3 +110,19 @@ if ($options['f'] === 'device_perf') { if ($options['f'] === 'notifications') { include_once 'notifications.php'; } + +if ($options['f'] === 'purgeusers') { + $purge = 0; + if (is_numeric($config['radius']['users_purge']) && $config['auth_mechanism'] === 'radius') { + $purge = $config['radius']['users_purge']; + } + if ($purge > 0) { + foreach (dbFetchRows("SELECT DISTINCT(`user`) FROM `authlog` WHERE `datetime` >= DATE_SUB(NOW(), INTERVAL ? DAY)", array($purge)) as $user) { + $users[] = $user['user']; + } + $del_users = '"'.implode('","',$users).'"'; + if (dbDelete('users', "username NOT IN ($del_users)",array($del_users))) { + echo "Removed users that haven't logged in for $purge days"; + } + } +} diff --git a/daily.sh b/daily.sh index 34b17fe4b3..795311e900 100755 --- a/daily.sh +++ b/daily.sh @@ -4,12 +4,12 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . @@ -64,6 +64,7 @@ else php daily.php -f perf_times php daily.php -f callback php daily.php -f device_perf + php daily.php -f purgeusers ;; submodules) # Init+Update our submodules