Source for file policy1.php

Documentation is available at policy1.php

  1. <?php
  2.  
  3. /** Sample Policy File
  4.  *
  5.  * This policy file allows access to known devices into the network and will place them
  6.  * in the global default vlan defined in the config table and accessible via the
  7.  * conf object. If an unknown device connects to the network, it will be denied.
  8.  *
  9.  * @package            FreeNAC
  10.  * @author            Sean Boran (FreeNAC Core Team)
  11.  * @author            Thomas Seiler (contributer)
  12.  * @author            Hector Ortiz (FreeNAC Core Team)
  13.  * @copyright            2007 FreeNAC
  14.  * @license            http://www.gnu.org/copyleft/gpl.html   GNU Public License Version 2
  15.  * @version            SVN: $Id$
  16.  * @link            http://www.freenac.net
  17.  *
  18.  */
  19.  
  20.  
  21. class BasicPolicy extends Policy 
  22. {
  23.    /**
  24.    * This method logs to syslog the decision taken so far.
  25.    * @param object $REQUEST    A request object
  26.    * @param integer $vlan        The vlan id of the assigned vlan. Default is 0.
  27.    * @param mixed $message        A message to display along with the host and port information
  28.    */
  29.    public function reportDecision($REQUEST,$vlan=0,$message='')
  30.    {
  31.       if (is_numeric($vlan))
  32.       {
  33.          if (empty($message))
  34.             $this->logger->logit("Note: Device {$REQUEST->host->getmac()}({$REQUEST->host->gethostname()},{$REQUEST->host->getusername()}) on switch {$REQUEST->switch_port->getswitch_ip()}({$REQUEST->switch_port->getswitch_name()}), port {$REQUEST->switch_port->getport_name()}, office {$REQUEST->switch_port->getoffice()}@{$REQUEST->switch_port->getbuilding()} has been placed in vlan ".vlanId2Name($vlan));
  35.          else
  36.             $this->logger->logit("Note: $message {$REQUEST->host->getmac()}({$REQUEST->host->gethostname()},{$REQUEST->host->getusername()}) on switch {$REQUEST->switch_port->getswitch_ip()}({$REQUEST->switch_port->getswitch_name()}), port {$REQUEST->switch_port->getport_name()}, office {$REQUEST->switch_port->getoffice()}@{$REQUEST->switch_port->getbuilding()} has been placed in vlan ".vlanId2Name($vlan));
  37.       }
  38.    }        
  39.  
  40.    /**
  41.    * The preconnect method is used by vmpsd_external.
  42.    * Here we define how to handle devices with different status
  43.    * @param object $REQUEST    The VMPS request, which contains also HOST and PORT information
  44.    */
  45.    public function preconnect($REQUEST
  46.    
  47.         
  48.       #Handling of active systems
  49.       if ($REQUEST->host->isActive())
  50.       {
  51.          $this->reportDecision($REQUEST,$this->conf->default_vlan);
  52.          #Allow host in global default vlan
  53.          ALLOW($this->conf->default_vlan);
  54.       
  55.       else
  56.       {
  57.          #Default policy is DENY
  58.          DENY('Default policy reached. Unknown or unmanaged device and no default_vlan specified');
  59.       }
  60.    }
  61.  
  62.    /**
  63.    * This function will provide an interface to change the current decision.
  64.    * This can prove useful for hub detection tests.
  65.    * At the moment it doesn't do anything in particular, it is here only for completeness' sake.
  66.    * @param integer $vlan        Vlan ID of the assigned vlan
  67.    * @return integer        Vlan Id of the assigned vlan
  68.    */
  69.    public function catch_ALLOW($vlan
  70.    {
  71.       //Rethrow the exception
  72.       ALLOW($vlan);
  73.    }
  74.  
  75.    /**
  76.    * The postconnect method is used by the postconnect daemon.
  77.    * It updates information for PORTS and HOSTS
  78.    * This method writes to the database, so it shouldn't be called from a slave server.
  79.    * @param object $REQUEST    A SyslogRequest object
  80.    */
  81.    public function postconnect($REQUEST)
  82.    {
  83.    }
  84. }
  85.  
  86. ?>

Documentation generated on Mon, 01 Dec 2008 01:10:39 +0100 by phpDocumentor 1.4.0