<?php
/**
 * @author     Thomas Meyer
 * @licence    http://creativecommons.org/licenses/by-nc-sa/2.5/
 * @package    yana
 * @subpackage plugins
 */

/**
 * @access     public
 * @package    yana
 * @subpackage plugins
 */
class plugin_ipblock extends plugin 
{

    /* private blockfile */ var $whitelist;
    /* private blockfile */ var $blacklist;

    /* constructor */ function plugin_ipblock($name)
    {
        settype($name,"string");
        $this->name = $name;
        global $YANA;
        $this->whitelist = $YANA->plugins->get($this->name,"IPWHITELIST");
        $this->blacklist = $YANA->plugins->get($this->name,"IPBLACKLIST");
        $dir             = $YANA->plugins->get($this->name,"BLOCKDIR");

        if (!$dir->exists() && !$dir->create(777)) {
            $YANA->report( new log("Unable to create directory", $dir->getFilename()) );
            $YANA->report( new error("500"));
        }
    }

    /* public void */ function _default(/* String */ $event, /* Hashtable */ $ARGS)
    {
        settype($event, "string");
        settype($ARGS, "array");
        global $YANA;

        if ($this->blacklist && $this->whitelist && $this->blacklist->exists()) {
            if ($this->whitelist->exists()) {
                $this->whitelist->read();
            }
            if ($this->blacklist->exists()) {
                $this->blacklist->read();
            }

            if ($this->blacklist->isBlocked() && ! ($this->whitelist->exists() && $this->whitelist->isBlocked())) {
                /* access denied */
                $YANA->message("error", "BLOCK", $event);
                return false;
            } else {
                /* access granted */
                return true;
            }

        } else {
            return true;
        }
    }

}

// © 2006, Thomas Meyer www.All-Community.de
// Copyright Hinweis nicht entfernen!
?>