Sophie

Sophie

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

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

<?php
# Copyright(C) 2004-2007 INL http://www.inl.fr/
# Written by Victor Stinner <victor.stinner AT inl.fr>
#
# $Id: acl_operation.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('acl_common.php');

function deleteAcl($ruleset, $aclid)
{
    if (!preg_match('/^\d+$/',$aclid))
    {
        log_error(_('Sorry, bad parameter received'));
        return;
    }
    $tmp = $ruleset->acls->get_elt($aclid);
    if (!$tmp)
    {
        log_error(sprintf(_('Sorry, cannot work on non-existing element: "%s".'),
            "ACL #$aclid"));
        return;
    }
    $ruleset->acls->del_elt($aclid);
    saveRuleset($ruleset);
}

function cloneAcl($ruleset, $aclid)
{
    if (!preg_match('/^\d+$/',$aclid))
    {
        log_error(_('Sorry, bad parameter received'));
        return;
    }
    $tmp = $ruleset->acls->get_elt($aclid);
    if (!$tmp)
    {
        log_error(sprintf(_('Sorry, cannot work on non-existing element: "%s".'),
            "ACL #$aclid"));
        return;
    }
    $new = clone $tmp->cloneobj($ruleset);
    foreach ($new->descsorts->elts as $acldesc)
    {
      foreach ($acldesc->elts as $order)
      {
	$order->order=0;
      }
    }
    $new->ID = $ruleset->acls->new_id();
    $new->name = sprintf(_("Copy of %s"), $new->name);
    $ruleset->acls->add_elt($new);
    $used_desc = $GLOBALS['used_desc'];
    recompute_all_descsorts($ruleset, $ruleset->descs->elts[$used_desc]);
    saveRuleset($ruleset);
    $GLOBALS['ch_acl'] = $new->ID;
}

function changeAcl($ruleset, $ch_acl)
{
    global $nufw_firewall, $support_periods, $title;

    if (!$ruleset->acls->has_elt($ch_acl))
    {
        log_error(sprintf(_('Sorry, cannot work on non-existing element: "%s".'),
            "ACL #".$ch_acl));
        return;
    }

    $received = changeAclBase_get();
    if (!$received) {
        return;
    }

    $ch_os=getHttp('os', 0);
    if (!check_nb($ch_os))
        return;

    $ch_auth=getHttp('auth');
    if (!check_nb($ch_auth))
        return;

    $ch_duration=getHttp('duration', 0);
    if (!check_nb($ch_duration))
        return;

    $ch_from=getHttp('subject');
    if (!check_nb($ch_from))
        return;

    $ch_to=getHttp('resource');
    if (!check_nb($ch_to))
        return;

    $ch_periodicity=getHttp('periodicity', 0);
    if (!check_nb($ch_periodicity))
        return;

    $ch_application=getHttp('application', 0);
    if (!check_nb($ch_application))
        return;

    $my_acl = $ruleset->acls->get_elt($ch_acl);
    $received['ID']=$my_acl->ID;
    $received['from']=$ch_from;
    $received['to']=$ch_to;
    $received['auth']=$ch_auth;
    $received['transparent_proxy'] = (int)getHttp('transparent_proxy', NO_PROXY);
    if ($ch_auth)
    {
        $received['periodicity']=$ch_periodicity;
        $received['duration']=$ch_duration;
        $received['on']=$ch_os;
        $received['with']=$ch_application;
    }
    $acl_descsorts = $my_acl->descsorts;
    $received['descsorts'] = $acl_descsorts;
    try
    {
        $new_acl=new acl($ruleset, $received,'data');
        $ruleset->acls->replace_elt($new_acl);

        $used_desc = $GLOBALS['used_desc'];
        recompute_all_descsorts($ruleset, $ruleset->descs->elts[$used_desc]);
    } catch (Exception $err) {
        log_exception($err);
        $ruleset = reloadRuleset();
        return false;
    }

    saveRuleset($ruleset);
    $link = createLink("$title.php?acl={$new_acl->ID}", $new_acl->str());
    add_log(sprintf(_('%s saved correctly.'), $link));
    return true;
}

?>