<?php # Copyright(C) 2004-2007 INL http://www.inl.fr/ # Written by Eric Leblond <regit@inl.fr> # Vincent Deffontaines <gryzor@inl.fr> # Jean Gillaux <jean@inl.fr> # # $Id: edit_nat.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/>. function editNat($expolicy, $nat_type, $ch_nat) { global $title; global $netfilter_snat_supports_sport_randomization; $nat = $ch_nat; print "<div class=\"acledit_tab\">"; if ($nat_type == 'SNAT') { $nats = $expolicy->snats; } else if ($nat_type == 'DNAT') { $nats = $expolicy->dnats; } else if ($nat_type == 'PNAT') { $nats = $expolicy->pnats; } else { add_log(sprintf(_('Invalid NAT type: "%s"!'), $nat_type)); return; } $my_nat = $nats->get_elt($nat); // Form title print "<h3>"; echo sprintf(_("Edit %s (%s)"), $my_nat->str(), $my_nat->modified); $msg = sprintf(_('Are you sure that you want to delete %s?'), $my_nat->str()); deleteIcon("$title.php?delete_s=".$my_nat->ID.'&nat_type='.$my_nat->nat_type, _("Delete the NAT rule"), $msg); echo "</h3>\n"; $srcnet=$my_nat->srcnet; $dstnet=$my_nat->dstnet; $proto=$my_nat->proto; $sport=$my_nat->sport; if ($nat_type == 'SNAT') $rand_sport=$my_nat->rand_sport; $dport=$my_nat->dport; $icmptype=$my_nat->icmptype; $rewritetoaddr=$my_nat->rewritetoaddr; $rewritetoport=$my_nat->rewritetoport; $rewritetovar = $rewritetoaddr; if ($nat_type == 'PNAT') $rewritetovar = $rewritetoport; if ($nat_type == 'DNAT') $rewritetovar = $rewritetoaddr.":".$rewritetoport; print '<form method="post" action="nat.php" onsubmit="natHandle()" id="natproto">'. '<input type="hidden" name="nat_nb" value="'.$my_nat->ID.'">'. '<input type="hidden" name="nat_type" value="'.$nat_type.'">'; echo '<input type="hidden" name="dndSort" value="" />'; print '<input type="hidden" name="nat" value="'.$nat.'">'; print '<table class="acl_edit">'; print '<tr><td class="rowtitle">'._('Name').'</td>'. '<td colspan="2"><input type="text" name="ch_name" value="'.$my_nat->name.'"></td></tr>' ."\n"; print '<tr><td class="rowtitle">'._('Comment').'</td><td colspan="2">'; html_textarea("comment", $my_nat->comment, 30, 3); print "</td></tr>"; formSeparator(_('Network parameters'), 3); print '<tr><td class="rowtitle">'._('Source address').'</td>' .'<td colspan="2"><input type="text" name="srcnet" value="'.$srcnet.'"></td></tr>'."\n"; print "<tr><td class=\"rowtitle\">"._('Destination address')."</td>" .'<td colspan="2"><input type="text" name="dstnet" value="'.$dstnet.'"></td></tr>'; $js = "griser_natproto();"; print "<tr><td class=\"rowtitle\">"._('Protocol')."</td><td colspan=\"2\">"; html_javascript($js, true); print "<select name=proto onFocus=\"$js\" onChange=\"griser_natproto();\">"; $array_protos=possible_values('elt','open_proto'); natcasesort($array_protos); foreach ($array_protos as $_proto) { print "<option value=\"$_proto\""; if ($_proto == $proto) echo " selected"; print ">".$_proto."</option>"; } print " </select></td></tr>\n"; print '<tr><td class="rowtitle">Sport</td><td colspan="2"><input type="text" name="sport" value="'. $sport. '"></td></tr>' ."\n"; print '<tr><td class="rowtitle">Dport</td><td colspan="2"><input type="text" name="dport" value="'. $dport. '"></td></tr>' ."\n"; if ($nat_type == 'SNAT') { if ($netfilter_snat_supports_sport_randomization) { print '<tr><td class="rowtitle">Sport_rand</td><td>'; html_checkbox('rand_sport', $rand_sport == 1); echo "</td></tr>\n"; } } print "<tr><td class=\"rowtitle\">"._('ICMP type').'</td><td colspan="2"> <select name=icmptype>'; $array_icmptypes=possible_values('proto','icmptype'); natcasesort($array_icmptypes); foreach ($array_icmptypes as $_icmptype) { print "\n\t<option value=\"$_icmptype\""; if ($icmptype == $_icmptype) echo " selected"; print ">".$_icmptype."</option>"; } print "</select></td></tr>\n"; $our_param = "nat_addr"; $rewritetovar=$rewritetoaddr; if ($nat_type == 'SNAT') { $text = _('Rewrite source to'); } else if ($nat_type == 'DNAT') { $text = _('Rewrite destination to'); } else if ($nat_type == 'PNAT') { $text = _('Rewrite port to'); $our_param="nat_port"; $rewritetovar=$rewritetoport; } print '<tr><td class="rowtitle">'.$text.'</td>'; if ($nat_type != 'DNAT') { echo '<td colspan="2">'; } else { echo '<td>'; } echo '<input type="text" name="'.$our_param.'" value="'.$rewritetovar.'"></td>'; if ($nat_type == 'DNAT') { print "<td>"._("port:")." <input name=\"nat_port\" value=\"$rewritetoport\" size=4></td>"; } print '</tr>'; print "</table>"; print "<input type=\"submit\" value=\""._('Save')."\" class=\"button\" onMouseOver=\"griser_natproto();\" />"; echo '<input type="hidden" name="dndSort" value="" />'; print "</form>\n"; print "</div>"; } ?>