View Single Post
  #1  
Old 8th September 2012, 17:41
phry phry is offline
Junior Member
 
Join Date: Sep 2012
Posts: 5
Thanks: 0
Thanked 3 Times in 2 Posts
Default Writing a simple plugin (fail2ban integration)

Heyo,
I wanted to log wrong logins into syslog so that fail2ban can parse it and ban the attacker's IP.
- Yes, I know, ISPConfig has a similar feature but I want to do this nonetheless.
- Yes, I know, ISPConfig logs wrong logins too, but only on DEBUG Level and I don't want the clutter. Neither do I want to change ispconfig files.

So I wrote a quick plugin:
/usr/local/ispconfig/server/plugins-available/login_fail2ban_plugin.inc.php
PHP Code:
<?php

class login_fail2ban_plugin {

        var 
$plugin_name 'login_fail2ban_plugin';
        var 
$class_name  'login_fail2ban_plugin';

        
//* This function is called during ispconfig installation to determine
        //  if a symlink shall be created for this plugin.
        
function onInstall() {

                return 
true;

        }


        
/*
                This function is called when the plugin is loaded
        */

        
function onLoad() {
                global 
$app;

                
/*
                Register for the events
                */
                
$app->plugins->registerEvent('login_failed',$this->plugin_name,'log_fail');
        }

        function 
log_failed($event_name,$data) {
        
openlog("ispconfig"LOG_PID LOG_PERRORLOG_LOCAL0);
        
syslog(LOG_WARNING"Login failed for user $_POST['username'] on IP $_SERVER['REMOTE_ADDR']");
        }




// end class

?>
and then I created a symlink in /usr/local/ispconfig/server/plugins-enabled
lrwxrwxrwx 1 ispconfig ispconfig 75 Sep 8 17:39 login_fail2ban_plugin.inc.php -> /usr/local/ispconfig/server/plugins-available/login_fail2ban_plugin.inc.php*

But here's the catch: it doesn't load. I tried writing stuff into the onLoad function, too - is doesn't execute.
Permissions and owner are set correctly, too:
-rwxr-x--- 1 ispconfig ispconfig 766 Sep 8 17:29 plugins-available/login_fail2ban_plugin.inc.php

Did I miss anything?
Reply With Quote
Sponsored Links