Sophie

Sophie

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

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_func.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('function.php');
require_once('types.php');

function form_list_protocols($protocols, $selected)
{
    if ($selected) $selected = $selected->ID;
    print "<div id=\"protocolContainer\"></div>\n";
    print "<input id=\"protocolInput\" type=\"text\" size=\"2\">\n";

    $protocols = $protocols->list_tab();
    natcasesort($protocols);
    gen_autocomplete_js('protocol',$protocols,1);

    print "<select name=protocol id=protocol>\n";
    print "<option value=\"0\">--</option>";
    foreach ($protocols as $key=>$text)
    {
        if ($key!=""){
            print "<option value=\"$key\"";
            if ($selected == $key)
                echo " selected";
            print ">".$text."</option>";
        }
    }
    print " </select>";
}

function form_subj_res_list($name, $resources, $selected, $allow_empty)
{
    if ($selected)
        $selected = $selected->ID;
    else
        $selected = null;

    print "  <div id=\"".$name."Container\">\n";
    print "</div>\n";
    print "  <input id=\"".$name."Input\" type=\"text\" size=\"2\">\n";

    $resources = $resources->list_tab();
    natcasesort($resources);
    if ($allow_empty)
        $shift = 1;
    else
        $shift = 0;
    gen_autocomplete_js($name, $resources, $shift);

    print "<select name=\"$name\" id=$name>\n";
    if ($allow_empty) {
        print "<option value=\"\" name=\"--\">--</option>\n";
    }

    foreach ($resources as $key=>$text)
    {
        print "<option value=\"$key\"";
        if ($key == $selected)
            echo " selected";
        print ">".$text."</option>\n";
    }
    print "</select>";
}

function form_subject_list($resources, $selected, $allow_empty)
{
    form_subj_res_list('subject', $resources, $selected, $allow_empty);
}

function form_resource_list($resources, $selected, $allow_empty)
{
    form_subj_res_list('resource', $resources, $selected, $allow_empty);
}

function form_decision_list($selected)
{
    print "<select name=decision>\n";
    foreach (possible_values('acl','decision') as $possible)
    {
        print " <option";
        if ($possible==$selected) echo " selected";
        print ">$possible</option>";
    }
    print "</select>\n";
}

function gen_autocomplete_js($obj_type, $element_array, $shift=0)
{
    $element_array[] = '--';
    $element_array_js = implode(", ", array_map('quote_text', $element_array));
    $js = Array(
        "function ".$obj_type."Select(arg1,arg2,arg3) {",
        "   var  ".$obj_type."Value = document.getElementById('".$obj_type."Input');",
        "   var  ".$obj_type."ToSet = document.getElementById('".$obj_type."');",
        "   var ".$obj_type."Tab= [".$element_array_js."]",
        "   var count = $shift;",
        "   var found = 0;",
        "   for (var res in ".$obj_type."Tab){",
        "     if (".$obj_type."Tab[res] == ".$obj_type."Value.value){",
        "       found=1;",
        "       break;",
        "     }",
        "     count++;",
        "   }",
        "   if (found == 1){",
        "   ".$obj_type."ToSet.selectedIndex = count;",
    );
    if ($obj_type == 'auth') {
        $js[] = "   grey_on_auth();";
    } else if ($obj_type == 'periodicity') {
        $js[] = "   grey_on_periodicity();";
    } else if ($obj_type == 'duration') {
        $js[] = "   grey_on_duration();";
    }
    $js[] = "   }";
    $js[] = "}";
    $js[] = "var ".$obj_type."DataString= new YAHOO.widget.DS_JSArray([".$element_array_js."]);";
    $js[] = "var ".$obj_type."AutoComp = new YAHOO.widget.AutoComplete (\"".$obj_type."Input\",\"".$obj_type."Container\",".$obj_type."DataString);";
    $js[] = $obj_type."AutoComp.itemSelectEvent.subscribe(".$obj_type."Select);";
    html_javascript($js, true);
}

# Reorder acls.
# iterate over bichain and change order for acls if needed
function saveAclOrder(&$expolicy, &$acls, $aclorder, $used_desc, $bichains, $bichain_name)
{
    if($aclorder == '' || !check_aclorder($aclorder, "dndSort_BICHAIN"))
        return;

    $new_set = array();
    $tab_order = array();
    $bichain = get_bichain_by_name($bichains, $bichain_name);
    foreach($acls->elts as $eid => $elt){
        $new_set[$elt->ID] = clone $acls->elts[$eid];
        if(bichain_touches_acl($bichain, $elt)){
            $ord = $elt->get_order($used_desc, $bichain['from'], $bichain['to']);
            $tab_order[$ord]= clone $acls->elts[$eid];
        }
    }
    if(!isset($bichain)){
        return;
    }

    $i = 1;
    foreach (explode('|', $aclorder) as $k => $acl_id) {
        if (!array_key_exists($acl_id, $tab_order))
        {
            add_log(sprintf(_('Invalid ACL order: unknown identifier %s.'), $acl_id));
            return;
        }
        $new_acl=$tab_order[$acl_id];
        $oldid = $new_acl->ID;
        $new_acl->set_order($used_desc, $bichain['from'], $bichain['to'], $i, $new_acl->get_max_elt_order_id());
        $new_set[$oldid] = $new_acl;
        $i++;
    }
    $newacls=new obj_set($acls->name, $new_set);
    $acls=$newacls;
    $expolicy->acls=$acls;
    saveRuleset($expolicy);
}


function saveLocalOrder(&$expolicy, $attrname, &$acls, $aclorder, $used_desc, &$ch_local)
{
    if($aclorder == '' || !check_aclorder($aclorder, null))
        return;

    $i = 1;
    $new_set = Array();
    $fixed = false;
    foreach (explode('|', $aclorder) as $k => $acl_id) {
        $new_acl = $acls->get_elt($acl_id);
        if (!$new_acl)
        {
            add_log(sprintf(_('Invalid ACL order: unknown identifier %s.'), $acl_id));
            return;
        }
        if (!$fixed and $new_acl->ID == $ch_local)
        {
            $fixed = true;
            $ch_local = $i;
        }
        $new_acl = $new_acl->cloneobj($expolicy);
        $new_acl->ID = $i;
        $new_set[$new_acl->ID] = $new_acl;
        $i++;
    }

    $newacls=new obj_set($acls->name, $new_set);
    $acls=$newacls;
    $expolicy->$attrname = $acls;
    saveRuleset($expolicy);
}

function createAcl($ruleset)
{
    global $DEFAULT_LOG;

    $new_acl = array();
    $new_acl['name'] = getHttp('name');

    if (!check_name($new_acl['name'], 'name'))
        return null;

    $addr = array_first($ruleset->resources->elts);
    $new_acl['from'] = $addr->ID;
    $new_acl['group'] = 1;
    $new_acl['to'] = $addr->ID;
    $new_acl['decision'] = 'accept';
    $new_acl['log'] = $DEFAULT_LOG;
    $new_acl['ID'] = $ruleset->acls->new_id();
    try {
        $acl = new acl($ruleset, $new_acl,'data');
        $ruleset->acls->add_elt($acl);
    } catch (Exception $err) {
        log_error(sprintf(_("Unable to create the new ACL: %s"),
                    $err->getMessage()), $err->getTrace());
        return null;
    }
    $_SESSION['need_acl_recalc'] = 1;
    return $acl;
}

function display_acl_form()
{
    global $title, $page_new_button, $acl_group;

    begin_content_detail();

    print $page_new_button{$title};
    print "<form action=\"$title.php\" method=\"post\">";
    html_input_text('name', '', Array('autocomplete' => 'off', 'size' => 20));
    if ($title == 'acls') {
        html_hidden("new_acl", "1");
    } else {
        html_hidden("new_local", 1);
    }
    echo ' ';
    html_submit(_('New'), Array('class' => 'button'));
    print "</form>";

    end_content_detail();

    if ($title == 'acls')
    {
        begin_content_detail();
        print _('New ACL group');
        print "<form action=\"$title.php\" method=POST>";
        html_input_text('name', '', Array('autocomplete' => 'off', 'size' => 20));
        html_hidden("new_group", 1);
        echo ' ';
        html_submit(_('New'), Array('class' => 'button'));
        print "</form>";
        end_content_detail();
    }

}

?>