]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/firewall.cgi
captive-portal: Move CGI files to CGI directory
[ipfire-2.x.git] / html / cgi-bin / firewall.cgi
index 3e1b33618c98fa01aecb30543e20d1628e73ba4d..face0f460974350f10c5bea26f54acb58cd9825e 100644 (file)
@@ -31,6 +31,7 @@ no warnings 'uninitialized';
 #use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
+require '/var/ipfire/network-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 require "${General::swroot}/geoip-functions.pl";
@@ -157,6 +158,19 @@ print<<END;
                        \$("#actions").toggle();
                });
 
+               // Hide SNAT items when DNAT is selected and vice versa.
+               if (\$('input[name=nat]:checked').val() == 'dnat') {
+                       \$('.snat').hide();
+               } else {
+                       \$('.dnat').hide();
+               }
+
+               // Show/Hide elements when SNAT/DNAT get changed.
+               \$('input[name=nat]').change(function() {
+                       \$('.snat').toggle();
+                       \$('.dnat').toggle();
+               });
+
                // Time constraints
                if(!\$("#USE_TIME_CONSTRAINTS").attr("checked")) {
                        \$("#TIME_CONSTRAINTS").hide();
@@ -452,6 +466,9 @@ sub checksource
                        }
                }
                if ($fwdfwsettings{'isip'} eq 'on'){
+                       #remove leading zero
+                       $ip = &Network::ip_remove_zero($ip);
+
                        ##check if ip is valid
                        if (! &General::validip($ip)){
                                $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
@@ -522,16 +539,6 @@ sub checktarget
        #check DNAT settings (has to be single Host and single Port or portrange)
        if ($fwdfwsettings{'USE_NAT'} eq 'ON' && $fwdfwsettings{'nat'} eq 'dnat'){
                if($fwdfwsettings{'grp2'} eq 'tgt_addr' || $fwdfwsettings{'grp2'} eq 'cust_host_tgt' || $fwdfwsettings{'grp2'} eq 'ovpn_host_tgt'){
-                       #check if manual ip is a single Host (if set)
-                       if ($fwdfwsettings{'grp2'} eq 'tgt_addr'){
-                               my @tmp= split (/\./,$fwdfwsettings{$fwdfwsettings{'grp2'}});
-                               my @tmp1= split ("/",$tmp[3]);
-                               if (($tmp1[0] eq "0") || ($tmp1[0] eq "255"))
-                               {
-                                       $errormessage=$Lang::tr{'fwdfw dnat error'}."<br>";
-                                       return $errormessage;
-                               }
-                       }
                        #check if Port is a single Port or portrange
                        if ($fwdfwsettings{'nat'} eq 'dnat' &&  $fwdfwsettings{'grp3'} eq 'TGT_PORT'){
                                if(($fwdfwsettings{'PROT'} ne 'TCP'|| $fwdfwsettings{'PROT'} ne 'UDP') && $fwdfwsettings{'TGT_PORT'} eq ''){
@@ -556,11 +563,15 @@ sub checktarget
                        ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
                        $subnet = &General::iporsubtocidr($subnet);
                }
+
                #check if only ip
                if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
                        $ip=$fwdfwsettings{'tgt_addr'};
                        $subnet='32';
                }
+               #remove leading zero
+               $ip = &Network::ip_remove_zero($ip);
+
                #check if ip is valid
                if (! &General::validip($ip)){
                        $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
@@ -584,7 +595,7 @@ sub checktarget
                &General::readhasharray("$confighost", \%customhost);
                foreach my $grpkey (sort keys %customgrp){
                        foreach my $hostkey (sort keys %customhost){
-                               if ($customgrp{$grpkey}[2] eq $customhost{$hostkey}[0] && $customhost{$hostkey}[1] eq 'mac'){
+                               if ($customgrp{$grpkey}[2] eq $customhost{$hostkey}[0] && $customgrp{$grpkey}[2] eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $customhost{$hostkey}[1] eq 'mac'){
                                        $hint=$Lang::tr{'fwdfw hint mac'};
                                        return $hint;
                                }
@@ -1643,7 +1654,7 @@ END
                                $Lang::tr{'fwdfw use nat'}
                        </label>
                        <div class="NAT">
-                               <table width='100%' border='0'>
+                               <table class='fw-nat' width='100%' border='0'>
                                        <tr>
                                                <td width='5%'></td>
                                                <td width='40%'>
@@ -1655,9 +1666,9 @@ END
 END
 
        print <<END;
-                                               <td width='25%' align='right'>$Lang::tr{'dnat address'}:</td>
+                                               <td width='25%' align='right'><span class='dnat'>$Lang::tr{'dnat address'}:</span></td>
                                                <td width='30%'>
-                                                       <select name='dnat' style='width: 100%;'>
+                                                       <select name='dnat' class='dnat' style='width: 100%;'>
                                                                <option value='AUTO' $selected{'dnat'}{'AUTO'}>- $Lang::tr{'automatic'} -</option>
                                                                <option value='Default IP' $selected{'dnat'}{'Default IP'}>$Lang::tr{'red1'} ($redip)</option>
 END
@@ -1688,9 +1699,9 @@ END
                                                                $Lang::tr{'fwdfw snat'}
                                                        </label>
                                                </td>
-                                               <td width='25%' align='right'>$Lang::tr{'snat new source ip address'}:</td>
+                                               <td width='25%' align='right'><span class='snat'>$Lang::tr{'snat new source ip address'}:</span></td>
                                                <td width='30%'>
-                                                       <select name='snat' style='width: 100%;'>
+                                                       <select name='snat' class='snat' style='width: 100%;'>
 END
 
                foreach my $alias (sort keys %aliases) {