Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > dca483b59ba61f3fa092de932ddd570e > files > 243

nuface-2.0.14-2mdv2009.1.i586.rpm

<?php
# Copyright(C) 2004-2008 INL
# Written by Eric Leblond <regit@inl.fr>
#            Vincent Deffontaines <gryzor@inl.fr>
#            Jean Gillaux <jean@inl.fr>
#            Damien Boucard <damien.boucard AT inl.fr>
#
# $Id: local.class.php 17927 2009-02-16 13:16:09Z haypo $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
#  This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

require_once('aclbase.class.php');

class local extends aclbase
{
  var $interface;
  var $way;
    function local(&$ruleset, $way, $ress,$type='xml',$id=0){
        if ($way == 'out')
            parent::aclbase('OUTPUT');
        else
            parent::aclbase('INPUT');
        $this->way = $way;

      if ($type != 'xml')
      {
        $this->loadArray($ress);
      }else{
        $this->loadXML($ress);
      }

      $errmsg = $this->check_consistency($ruleset);
      if ($errmsg) {
          $errmsg = sprintf(_("%s consistency error: %s!"), $this->str(), $errmsg);
          throw new Exception($errmsg);
      }
    }

    function loadArray($ress)
    {
        parent::loadArray($ress);
        $this->interface = array_get($ress, 'interface');
    }

    function loadXML($ress)
    {
        parent::loadXML($ress);
        $this->interface = $ress->get_attribute('interface');
    }

    function check_consistency($ruleset)
    {
        $errmsg = parent::check_consistency($ruleset);
        if ($errmsg) {
            return $errmsg;
        }

        if ($this->way == 'in') {
            $net_attr = 'from';
            $net_label = _('source');
        } else {
            $net_attr = 'to';
            $net_label = _('destination');
        }

        if ($this->interface) {
            if ($this->$net_attr)
                return sprintf(_('Interface and %s can not be used simultaneously'), $net_label);
        } else {
            if (!$this->$net_attr)
                return sprintf(_('Missing interface or %s'), $net_label);
        }
        return '';
    }

    function xmldump($xml, $node)
    {
        parent::writeXML($node);
        $node->set_attribute('interface',$this->interface);
    }

    function new_id(){
      return($this->get_max_id()+1);
    }

    function get_id(){
      return($this->ID);
    }

    function cloneobj(&$ruleset){
      $t=array();
      $t['ID']=$this->ID;
      $t['name']=$this->name;
      $t['interface']=$this->interface;
      $t['proto']=$this->proto;
      $t['from']=$this->from;
      $t['to']=$this->to;
      $t['decision']=$this->decision;
      $t['log']=$this->log;
      $t['modified']=$this->modified;
      $t['comment']=$this->comment;
      $t['group']=$this->group;
      return new local($ruleset, $this->way, $t, $type='toto', $id=$this->ID);
    }
}

?>