<?php # Copyright(C) 2004-2007 INL http://www.inl.fr/ # Written by Victor Stinner <victor.stinner AT inl.fr> # # $Id: edit_acl.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('acl_common.php'); function editAclApplication($applications, $with) { print "<tr><td class=\"rowtitle\">"; if ($with and isset($with->ID) and ($with->ID!=0)) print_reduced_link("applications.php",$with->ID,$with->name); print _('Application'); if ($with and isset($with->ID) and ($with->ID!=0)) print "</a>"; print "</td><td> <select name=application>\n"; print "<option value=\"0\">--</option>"; $array_applications=array(); foreach (($applications->list_tab()) as $key=>$app) { array_push($array_applications,$app); } natcasesort($array_applications); foreach ($array_applications as $app) { foreach ($applications->list_tab() as $key=>$foo) { if ($foo==$app) break; } if ($key!=""){ print "<option value=\"$key\""; if ($with and $app == $with->name) echo " selected"; print ">".$app."</option>"; } } print " </select></td><td>\n"; add_create_elt_button("application"); print "</td></tr>\n"; } function editAclOS($oss, $on) { print "<tr><td class=\"rowtitle\">"; if ($on and isset($on->ID) and ($on->ID!=0)) print_reduced_link("os.php",$on->ID,$on->name); print _('OS'); if ($on and isset($on->ID) and ($on->ID!=0)) print "</a>"; print "</td><td> <select name=os>\n"; print "<option value=\"0\">--</option>"; $array_oss=array(); foreach ($oss->list_tab() as $key=>$os) { array_push($array_oss,$os); } natcasesort($array_oss); foreach ($array_oss as $os) { foreach ($oss->list_tab() as $key=>$foo) { if ($foo==$os) break; } if ($key!=""){ print "<option value=\"$key\""; if ($on and $os == $on->name) echo " selected"; print ">".$os."</option>"; } } print " </select></td><td>\n"; add_create_elt_button("os"); print "</td><i/tr>\n"; } function editAclGroup($groups, $selected) { if ($selected) $selected = $selected->ID; else $selected = null; print "<tr><td class=\"rowtitle\">"._('Group')."</td><td colspan=2> <select name=group>\n"; $groups = $groups->list_tab(); natcasesort($groups); foreach ($groups as $key=>$text) { print "<option value=\"$key\""; if ($selected == $key) { echo " selected"; } print ">".$text."</option>"; } print "</select></td></td><td></tr>"; } function editAclSource($resources, $from) { print "<tr>\n"; print "<td class=\"rowtitle\">"; if (isset($from->ID) and ($from->ID!=0)) print_reduced_link("resources.php",$from->ID,$from->name); print _('Source'); if (isset($from->ID) and ($from->ID!=0)) print "</a>"; print "</td><td>"; form_subject_list($resources, $from, false); print "</td><td>\n"; add_create_elt_button("resource"); print "</td></tr>\n"; } function editAclDest($resources, $to) { print "<tr><td class=\"rowtitle\">"; if (isset($to->ID) and ($to->ID!=0)) print_reduced_link("resources.php",$to->ID,$to->name); print _('Destination'); if (isset($to->ID) and ($to->ID!=0)) print "</a>"; print '</td><td colspan="2">'."\n"; print "<div id=\"resourceContainer\"></div>\n"; print " <input id=\"resourceInput\" type=\"text\" size=\"2\">\n"; $resources = $resources->list_tab(); natcasesort($resources); gen_autocomplete_js('resource', $resources); print "<select name=resource id=resource>\n"; foreach ($resources as $key=>$text) { print "<option value=\"$key\""; if ($to and $to->ID == $key) echo " selected"; print ">".$text."</option>"; } print "</select></td></tr>"; } function editAclProtocols($protocols, $proto) { print "<tr><td class=\"rowtitle\">"; if (isset($proto->ID) and ($proto->ID!=0)) print_reduced_link("protocols.php",$proto->ID,$proto->name); print _('Protocol'); if (isset($proto->ID) and ($proto->ID!=0)) print "</a>"; print "</td><td>"; form_list_protocols($protocols, $proto); print "</td><td>"; /* end colspan protocol */ add_create_elt_button("protocol"); print "</td></tr>\n"; } function editAclTransparentProxy($acl) { print "<tr><td class=\"rowtitle\">"; print _('Proxy'); print '</td><td colspan="2">'; $values = Array( NO_PROXY => '--', USE_PROXY => _('Use the transparent proxy'), OVERRIDE_PROXY => _('Override the transparent proxy'), ); select_array('transparent_proxy', $values, $acl->transparent_proxy, NO_PROXY); print "</td></tr>\n"; } function editAclAuths($auths, $auth) { print "<tr><td class=\"rowtitle\">"; if ($auth and isset($auth->ID) and ($auth->ID!=0)) print_reduced_link("auths.php",$auth->ID,$auth->name); print _('Auth'); if ($auth and isset($auth->ID) and ($auth->ID!=0)) print "</a>"; print "</td><td>\n"; print "<div id=\"authContainer\">\n"; print "</div>\n"; print " <input id=\"authInput\" type=\"text\" size=\"2\" onChange=\"grey_on_auth()\">\n"; $array_auths=array(); foreach (($auths->list_tab()) as $key=>$sub) { array_push($array_auths,$sub); } natcasesort($array_auths); gen_autocomplete_js('auth',$array_auths,1); print "<select name=auth onChange=\"grey_on_auth()\" id=auth>\n"; print "<option value=\"0\">--</option>"; foreach ($array_auths as $sub) { foreach ($auths->list_tab() as $key=>$foo) { if ($foo==$sub) break; } if ($key!=""){ print "<option value=\"$key\""; if ($auth and $sub == $auth->name) echo " selected"; print ">".$sub."</option>"; } } print "</select>"; print "</td><td>\n"; add_create_elt_button("auth"); print "</td></tr>\n"; } function editAclPeriodicity($periodicities, $periodicity) { print "<tr><td class=\"rowtitle\">"; if (isset($periodicity->ID) and ($periodicity->ID!=0)) print_reduced_link("periodicities.php",$periodicity->ID,$periodicity->name); print _('Periodicity'); if (isset($periodicity->ID) and ($periodicity->ID!=0)) print "</a>"; print "</td><td>\n"; print "<div id=\"periodicityContainer\"></div>\n"; print " <input id=\"periodicityInput\" type=\"text\" size=\"2\">\n"; $array_periodicities=array(); foreach (($periodicities->list_tab()) as $key=>$pro) { array_push($array_periodicities,$pro); } natcasesort($array_periodicities); gen_autocomplete_js('periodicity',$array_periodicities,1); print "<select name=periodicity onChange=\"grey_on_periodicity()\" id=periodicity>\n"; print "<option value=\"0\">--</option>"; foreach ($array_periodicities as $pro) { foreach ($periodicities->list_tab() as $key=>$foo) { if ($foo==$pro) break; } if ($key!=""){ print "<option value=\"$key\""; if (isset($periodicity) and $pro == $periodicity->name) echo " selected"; print ">".$pro."</option>"; } } print " </select></td><td>\n"; add_create_elt_button("periodicity"); print "</td></tr>\n"; } function editAclDuration($durations, $duration) { print "<tr><td class=\"rowtitle\">"; if (isset($duration->ID) and ($duration->ID!=0)) print_reduced_link("durations.php",$duration->ID,$duration->name); print _('Duration'); if (isset($duration->ID) and ($duration->ID!=0)) print "</a>"; print "</td><td>\n"; print "<div id=\"durationContainer\"></div>\n"; print " <input id=\"durationInput\" type=\"text\" size=\"2\">\n"; $array_durations=array(); foreach (($durations->list_tab()) as $key=>$pro) { array_push($array_durations,$pro); } natcasesort($array_durations); gen_autocomplete_js('duration',$array_durations,1); print "<select name=duration onChange=\"grey_on_duration()\" id=duration>\n"; print "<option value=\"0\">--</option>"; foreach ($array_durations as $pro) { foreach ($durations->list_tab() as $key=>$foo) { if ($foo==$pro) break; } if ($key!=""){ print "<option value=\"$key\""; if (isset($duration) and $pro == $duration->name) echo " selected"; print ">".$pro."</option>"; } } print " </select></td><td>\n"; add_create_elt_button("duration"); print "</td></tr>\n"; } function editAclOpenForm($acl, $my_acl) { print "<form method=\"post\" action=\"acls.php\" onsubmit=\"aclHandle(bichains_t)\" name=\"acls\">"; echo '<input type="hidden" name="dndSort" value="" />'; print "<input type=hidden name=acl value=\"$acl\"/>\n"; print "<input type=hidden name=acl_nb value=\"".$my_acl->ID."\"/>"; print "<table class=\"acl_edit\">"; print "<tr><td class=\"rowtitle\">"._('Name')."</td>\n"; print "<td colspan=2>"; print "<input type=\"text\" size=36 name=\"ch_name\" value=\"".$my_acl->name."\"/>"; print "</td></tr>\n"; } function editAclCloseForm($bichain_label, $chain_from, $chain_to, $gr_high) { print "</td></tr></table>\n"; if (isset($bichain_label) && $bichain_label != ''){ print '<input type="hidden" name="bichain" value="'.$bichain_label.'"/>'; } if (isset($chain_from) && $chain_from != ''){ print '<input type="hidden" name="chainfrom" value="'.$chain_from.'"/>'; } print "<input type=\"hidden\" name=\"grhigh\" value=\"$gr_high\"/>"; if (isset($chain_to) && $chain_to != ''){ print '<input type="hidden" name="chainto" value="'.$chain_to.'"/>'; } print "<input type=\"submit\" value=\""._('Save')."\" class=\"button\" />"; echo '<input type="hidden" name="dndSort" value="" />'; print "</form>\n"; } function editAclDecision($my_acl) { print "<tr><td class=\"rowtitle\">"._('Decision')."</td><td colspan=2>"; form_decision_list($my_acl->decision); print "</td></tr>"; } function editAcl($expolicy, $bichains, $acl, $bichain_label, $chain_from, $chain_to, $gr_high, $aclorder) { global $nufw_firewall, $support_periods, $use_transparent_proxy; $my_acl=$expolicy->acls->get_elt_by_id($acl); if (!$my_acl) { log_error(sprintf(_("Invalid ACL identifier: %s!"), $acl)); return; } if(!isset($aclorder)) $my_acl = $expolicy->acls->get_elt($acl); $resources=$expolicy->resources; $from=$resources->get_elt($my_acl->from); $to=$resources->get_elt($my_acl->to); $auths=$expolicy->auths; $auth=$auths->get_elt($my_acl->auth); $protocols=$expolicy->protocols; $proto=$protocols->get_elt($my_acl->proto); $applications = $expolicy->applications; $with = $applications->get_elt($my_acl->with); print '<div class="acledit_tab">'; editAclTitle($my_acl, true); editAclOpenForm($acl, $my_acl); $groups = $expolicy->groups; $group=$groups->get_elt($my_acl->group); editAclGroup($groups, $group); print "<tr><td class=rowtitle>"._('Comment')."</td><td colspan=\"2\">"; html_textarea('comment', $my_acl->comment, 30, 1); formSeparator(_('Network parameters'), 3); editAclSource($resources, $from); editAclDest($resources, $to); editAclProtocols($protocols, $proto); if ($use_transparent_proxy) { editAclTransparentProxy($my_acl); } if ($nufw_firewall) { formSeparator(_('NuFW'), 3); editAclAuths($auths, $auth); if ($support_periods) { $periodicities=$expolicy->periodicities; $periodicity=$periodicities->get_elt($my_acl->periodicity); editAclPeriodicity($periodicities, $periodicity); $durations=$expolicy->durations; $duration=$durations->get_elt($my_acl->duration); editAclDuration($durations, $duration); } $oss = $expolicy->oss; $on = $oss->get_elt($my_acl->on); editAclOS($oss, $on); editAclApplication($applications, $with); } formSeparator(_('Action'), 3); editAclDecision($my_acl); editAclLog($my_acl); editAclCloseForm($bichain_label, $chain_from, $chain_to, $gr_high); add_js_form("resources","resource"); add_js_form("protocols","protocol"); if ($nufw_firewall) { add_js_form("auths","auth"); add_js_form("periodicities","periodicity"); add_js_form("durations","duration"); add_js_form("applications","application"); add_js_form("os","os"); } html_acl_get_bichains($bichain_label, $my_acl, $bichains, $gr_high); print "</div>"; } ?>