maddinxx
2012-08-15 a8ccf60181373b68ca8bb77ca45f879e1aea9c0b
auth.log e.g. for fail2ban
- install: touch auth.log
- login: write success/fail to auth.log
- cron: log rotation for auth.log
3 files modified
28 ■■■■ changed files
install/lib/installer_base.lib.php 5 ●●●●● patch | view | raw | blame | history
interface/web/login/index.php 16 ●●●● patch | view | raw | blame | history
server/cron_daily.php 7 ●●●●● patch | view | raw | blame | history
install/lib/installer_base.lib.php
@@ -1957,6 +1957,11 @@
            touch($conf['ispconfig_log_dir'].'/ispconfig.log');
        }
        
        //* Create the ispconfig auth log file
        if(!is_file($conf['ispconfig_log_dir'].'/auth.log')) {
            touch($conf['ispconfig_log_dir'].'/auth.log', 0666);
        }
        if(is_user('getmail')) {
            rename($install_dir.'/server/scripts/run-getmail.sh','/usr/local/bin/run-getmail.sh');
            if(is_user('getmail')) chown('/usr/local/bin/run-getmail.sh', 'getmail');
interface/web/login/index.php
@@ -78,7 +78,6 @@
            $passwort = $app->db->quote($_POST['passwort']);
            $loginAs  = false;
            $time = time();
            $logging = 'Failed login for user '. $username .' from '. long2ip($ip) .' at '. date('Y-m-d H:i:s');
            if($username != '' && $passwort != '' && $error == '') {
                /*
@@ -200,6 +199,12 @@
                                $app->plugin->raiseEvent('login',$this);
                                //* Save successfull login message to var
                                $authlog = 'Successful login for user \''. $username .'\' from '. long2ip($ip) .' at '. date('Y-m-d H:i:s');
                                $authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a');
                                fwrite($authlog_handle, $authlog ."\n");
                                fclose($authlog_handle);
                                /*
                                * We need LOGIN_REDIRECT instead of HEADER_REDIRECT to load the
                                * new theme, if the logged-in user has another
@@ -211,6 +216,7 @@
                         } else {
                            $error = $app->lng('error_user_blocked');
                        }
                    } else {
                        if(!$alreadyfailed['times'] )
                        {
@@ -228,10 +234,14 @@
                        $app->plugin->raiseEvent('login_failed',$this);
                        //* write to log (e.g. for fail2ban)
                        exec('echo '. $logging .' >> /tmp/login.log');
                        //* Save failed login message to var
                        $authlog = 'Failed login for user \''. $username .'\' from '. long2ip($ip) .' at '. date('Y-m-d H:i:s');
                        $authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a');
                        fwrite($authlog_handle, $authlog ."\n");
                        fclose($authlog_handle);
                       }
                }
              } else {
                   //* Username or password empty
                if($error == '') $error = $app->lng('error_user_password_empty');
server/cron_daily.php
@@ -348,6 +348,13 @@
    exec("cat /dev/null > $logfile");
}
// rotate the auth.log when it exceeds a size of 10 MB
$logfile = $conf['ispconfig_log_dir'].'/auth.log';
if(is_file($logfile) && filesize($logfile) > 10000000) {
    exec("gzip -c $logfile > $logfile.1.gz");
    exec("cat /dev/null > $logfile");
}
#######################################################################################################
// Cleanup website tmp directories
#######################################################################################################