Archive for March, 2008

Increasing method visibility through extension

Sunday, March 16th, 2008

Although it’s nothing superspecial, I wanted to illustrate how it is possible to modify the visibility of a parent class method when extending it, to convert it from ‘protected’ to ‘public’. Assume we have a base class which exposes a protected function called ‘Test’. We want to extend the class and make that function public in our extension. Here’s how:

<?php
    class Fred {
        protected function Test() {
            ?>Boo!<?php
        }
    }
 
    class Barney extends Fred {
        public function Test() {
            parent::Test();
        }
    }
 
    $barney = New Barney();
    $barney->Test();
?>

Notice that $barney->Test() is a public method call. It’s also possible to disallow this kind of behavior from the parent’s perspective by declaring a method as final. This way it can no longer be overridden (including its visibility):

<?php
    class Fred {
        final protected function Test() {
            ?>Boo!<?php
        }
    }
?>

Fighting against DDoS

Wednesday, March 12th, 2008

The last week we had some downtimes due to a distributed denial-of-service attack. I’m not sure if it was directly related to our Kamibu projects because there is a bug in the current lighttpd version. An attack can cause a bufferoverflow of Lighttpd with a DDoS. So at all someone tried to get our sites down.

Our solution is very easy. We created a little script fetching all connections by using netstat, counting the number of connections per IP and if there are more than x connections from a certain IP it will add the IP to our firewall. Very simple but helpfull. We execute the script periodically to stop a possible DDoS.