<?php # Copyright(C) 2004-2008 INL http://www.inl.fr/ # 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_page.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/>. $header_ask_list_change=Array('sortcat'); require_once("include/common.php"); require_once("include/network.class.php"); require_once("include/local.class.php"); require_once("include/desc.class.php"); require_once("include/edit_local.php"); require_once("include/headers.php"); require_once("include/display.php"); require_once("include/acl_func.php"); require_once("include/groups.php"); require_once('include/acl_common.php'); require_once('include/html.php'); initRuleset(); if ($title == 'localsout') { $localsout =& $expolicy->localsout; $container =& $localsout; } else { $localsin =& $expolicy->localsin; $container =& $localsin; } $descs = $expolicy->descs; $used_desc = getSession('used_desc', false); $new_name = getHttp('name'); $new_local = getHttp('new_local'); $delete = getHttp('delete'); $local_nb = getHttp('local_nb'); $mlocal = getHttp('mlocal'); $up = getHttp('up'); $down = getHttp('down'); $gr_enabled = getHttp('gr_enabled'); $modify_groups=getHttp('modify_groups'); #INPUT STRICT CHECKING if (!check_comment($new_name, "new local rule name")) { log_and_exit(-1); } $ch_local = getHttp('acl'); if (!check_nb($ch_local)) { log_and_exit(-1); } # store in session the acl to display in detail # or get ch_acl from session if (isset($ch_order) && $ch_order == "") { unset($ch_order); } else if (isset($ch_order)) { $_SESSION['order'] = $ch_order; } else if (isset($bichain_label)) { $ch_order = $_SESSION['order']; } if ((isset($down)) and ($down==1)) $up=-1; $aclorder = getHttp('dndSort_BICHAIN'); if ($aclorder) { saveLocalOrder($expolicy, $title, $container, $aclorder, $used_desc, $ch_local); } function changeLocal(&$ruleset, $ch_local) { global $container, $title; $received = changeAclBase_get(); if (!$received) { return; } if (!$container->has_elt($ch_local)) { log_error(_('Sorry, cannot work on non-existing element')." local".$ch_local); return; } $my_local = $container->get_elt($ch_local); $ch_interface = getHttp('interface'); if (!check_nb($ch_interface)) return; if ($my_local->way == 'out') { $ch_to = getHttp('resource'); if (!check_nb($ch_to)) return; $received['to']=$ch_to; } else { $ch_from = getHttp('subject'); if (!check_nb($ch_from)) return; $received['from']=$ch_from; } $received['ID']=$my_local->ID; $received['interface']=$ch_interface; try { $new_local=new local($ruleset, $my_local->way, $received, 'data'); $container->del_elt($my_local->ID); $container->add_elt($new_local); if ($my_local->way == 'out') { $localsout=&$ruleset->localsout; $container = &$localsout; } else { $localsin=&$ruleset->localsin; $container = &$localsin; } } catch (Exception $err) { log_error(sprintf(_("Reject invalid change: %s"), $err->getMessage())); return false; } saveRuleset($ruleset); $link = createLink("$title.php?acl={$new_local->ID}", $new_local->str()); add_log(sprintf(_('%s saved correctly.'), $link)); return true; } if (isset($new_name) and $new_local==1) { $new_local = array( 'group' => 1, 'name' => $new_name, 'ID' => $container->new_id(), ); if ($title == 'localsout') { $new_local['log'] = $NO_LOG; } else { $new_local['log'] = $DEFAULT_LOG; } try { $addr = array_first($expolicy->resources->elts); $addr = $addr->ID; if ($title == 'localsout') { $way = 'out'; $new_local['to'] = $addr; } else { $way = 'in'; $new_local['from'] = $addr; } $proto = array_first($expolicy->protocols->elts); $new_local['proto'] = $proto->ID; $local=new local($expolicy, $way, $new_local,'data'); $container->add_elt($local); saveRuleset($expolicy); $ch_local = $local->ID; } catch (Exception $err) { log_error(sprintf(_("Unable to create the new ACL: %s"), $err->getMessage()), $err->getTrace()); } } else if ($modify_groups==1) { modify_groups($expolicy); } else if ((isset($new_name) and (isset($new_group)) and ($new_group==1))) { $new_group = array( 'name' => $new_name, 'modified' => modifiedTimestamp(), ); $groups =& $expolicy->groups; $group=new group($new_group,'data',$groups->new_id()); $groups->add_elt($group); saveRuleset($expolicy); }elseif ($ch_local and getHttp('group')) { $ok = changeLocal($expolicy, $ch_local); if ($ok) $ch_local = null; }elseif (isset($delete)) { if (!preg_match('/^\d+$/',$delete)) { log_error(_('Sorry, bad parameter received')); log_and_exit(-1); } $tmp=$container->get_elt($delete); if ($tmp) { $container->del_elt($delete); deletefromhistory($title,$delete); saveRuleset($expolicy); } $ch_local = null; }elseif ((isset($mlocal)) and (isset($up)) and (($up==1) or ($up==-1))) { $list=$container->ordered_list_tab(); if (!isset($list)) { $list=array(); } $current=0;$in=0; foreach ($list as $is=>$value) { $last=$current; $current=$is; if ($current == $mlocal) $in=1; if ($in==1) { if (($last==0) and ($up==1)) #Cannot bring top element up break; #bring an element down means bring the following element up if ($up==-1) { $up=1; continue; } $cur_elt=&$container->get_elt($current); $last_elt=&$container->get_elt($last); $tmpid=$cur_elt->ID; $cur_elt->ID=$last_elt->ID; $last_elt->ID=$tmpid; $local1=$container->get_elt($cur_elt->ID); $local2=$container->get_elt($last_elt->ID); $container->del_elt($cur_elt->ID); $container->del_elt($last_elt->ID); $container->add_elt($local1,'data',$last_elt->ID); $container->add_elt($local2,'data',$cur_elt->ID); saveRuleset($expolicy); break; } } } $local=getHttp('local'); if (!check_nb($local)) { log_and_exit(-1); } $local_menu_class = "aclmenu_ext"; echo "<div class=\"$local_menu_class\" id=\"c1\">\n"; if ($title == 'localsout') { $type = 'localsout'; } else { $type = 'localsin'; } print_acls_onload(false); $display = new DisplayAcl($expolicy); $display->current_acl = $ch_local; $display->gr_high = getHttp('grhigh'); $display->local_all_acls(); unset($display); print "\n</div>\n"; display_acl_form(); # Display local detail # begin_content_detail(); if ($ch_local){ editLocal($expolicy, $container, $ch_local, $used_desc); }else{ display_groups($expolicy); } end_content_detail(); updateHistoryWrapper($title, $ch_local, $container); require_once ("include/footer.php"); ?>