]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
Firewall: Language changes, JQuery code cleanup
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 9369c22d104976d1786b1bc2716c2dc8202a6357..cbe325c1d066e61afe0b928a51a76924f868a865 100755 (executable)
@@ -88,58 +88,28 @@ unless (-e $configsrvgrp) { system("touch $configsrvgrp"); }
 #### JAVA SCRIPT ####
 print<<END;
 <script>
+       var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"];
+       var update_protocol = function() {
+               var protocol = \$("#protocol").val();
+
+               if (protocol === undefined)
+                       return;
+
+               // Check if we are dealing with a protocol, that knows ports.
+               if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) {
+                       \$("#PORT").show();
+                       \$("#PROTOKOLL").hide();
+               } else {
+                       \$("#PORT").hide();
+                       \$("#PROTOKOLL").show();
+               }
+       };
+
        \$(document).ready(function() {
-               // Automatically select radio buttons when corresponding
-               // dropdown menu changes.
-               \$("select").change(function() {
-                       var id = \$(this).attr("name");
-                       //When using SNAT or DNAT, check "USE NAT" Checkbox
-                       if ( id === 'snat' || id === 'dnat') {
-                               \$('#USE_NAT').prop('checked', true);
-                       }
-                       \$('#' + id).prop("checked", true);
-               });
-               // When protokol is not ICMP hide icmp-types
-               if ( \$("#PROT").val() === 'ICMP') {
-                       \$('PROTOKOLL').hide();
-               }
-               // When protocol dropdown is changed, check if we selected icmp - then show icmp-types
-               \$("#prt").change(function(){
-                       if ( \$("#PROT").val() === 'ICMP' ){
-                               \$('PROTOKOLL').show();
-                       }
-                       else{
-                               \$('PROTOKOLL').hide();
-                       }
-               });
+               var protocol = \$("#protocol").val();
+               \$("#protocol").change(update_protocol);
+               update_protocol();
        });
-function hide_elements(){
-       var elementNames = hide_elements.arguments;
-       for (var i=0; i<elementNames.length; i++)
-       {
-               var elementName = elementNames[i];
-               document.getElementById(elementName).style.display='none';
-       }
-}
-function getdropdown(){
-       d = document.getElementById("PROT").value;
-       if ( d == 'ICMP' )
-       {
-               document.getElementById('PROTOKOLL').style.display='block';
-       }
-       else
-       {
-               document.getElementById('PROTOKOLL').style.display='none';
-       }
-       if(document.getElementById('PROTOKOLL').style.display== "block" )
-       {
-               document.getElementById('PORT').style.display='none';
-       }
-       if(document.getElementById('PROTOKOLL').style.display== "none" )
-       {
-               document.getElementById('PORT').style.display='block';
-       }
-}
 </script>
 END
 
@@ -775,7 +745,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice')
                        }
                }
        }
-       if($ICMP eq ''){$ICMP='BLANK';}
+       if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
        if (!$errormessage){
                my $key = &General::findhasharraykey (\%customservice);
                foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
@@ -1344,9 +1314,9 @@ sub addservice
                $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'};
        }
        print<<END;
-       <div id='prt'><table width='100%' border='0'><form method='post'>
+       <table width='100%' border='0'><form method='post'>
        <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost srv_name'}:</td><td><input type='text' name='SRV_NAME' id='textbox1' value='$fwhostsettings{'SRV_NAME'}' size='24'><script>document.getElementById('textbox1').focus()</script></td></tr>
-       <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='PROT' >
+       <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' >
 END
        foreach ("TCP","UDP","ICMP")
        {
@@ -1358,11 +1328,11 @@ END
                }
        }
        print<<END;
-       </select></td></tr></table></div>
+       </select></td></tr></table>
        <div id='PROTOKOLL' class='noscript'><table width=100%' border='0'><tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td><select name='ICMP_TYPES'>
 END
        &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
-       print"<option>All ICMP-Types</option>";
+       print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>";
        foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){
                if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){
                        print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>";
@@ -1387,19 +1357,13 @@ END
                <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'>
                </form>
 END
-               
-       }else{  
+       }else{
                print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>";
        }
        print<<END;
        <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr>
        </table></form>
-       
-       
 END
-       #if ($fwhostsettings{'PROT'} ne 'ICMP'){
-                       #print"<script language='JavaScript'>hide_elements('PROTOKOLL');</script>";
-               #}
        &Header::closebox();
        &viewtableservice;
 }
@@ -1701,8 +1665,8 @@ END
                        print<<END;
                        <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
 END
-                       if($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
-               
+                       if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};}
+                       elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
                        print<<END;
                        </td><td align='center'>$customservice{$key}[4]x</td>
                        <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /><input type='hidden' name='ACTION' value='editservice' />