<?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_admin extends plugin 
{

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

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

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

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

            global $YANA;

            switch ($event) {

                case "get_block": case "get_root_block":
                     $YANA->setVar("BLACKLIST", $this->blacklist->get());
                     $YANA->setVar("WHITELIST", $this->whitelist->get());
                     return true;
                break;

                case "set_block":
                     $this->blacklist = new blockfile($this->dir->getFilename().$ARGS['id'].".blacklist");
                     $this->whitelist = new blockfile($this->dir->getFilename().$ARGS['id'].".whitelist");

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

                     return $this->_set($ARGS);
                break;

                case "set_root_block":
                     return $this->_set($ARGS);
                break;

                default:
                break;
            } /* end switch */
        }
        return true;
    }
    
    /* private boolean */ function _set(/* Hashtable */ $ARGS) 
    {
         settype($ARGS, "array");
         global $YANA;

         if (!$this->whitelist->exists() && !$this->whitelist->create()) {
             return false;
         }

         if (!$this->blacklist->exists() && !$this->blacklist->create()) {
             return false;
         }

         if ((!$this->blacklist->set($ARGS['blacklist']) || !$this->blacklist->write()) ||
             (!$this->whitelist->set($ARGS['whitelist']) || !$this->whitelist->write()))
         {
             return false;
         } else {
             return true;
         }
    }

}

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