Firewall: BUGFIX 10505
authorAlexander Marx <alexander.marx@ipfire.org>
Mon, 7 Apr 2014 10:04:50 +0000 (12:04 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Apr 2014 14:52:49 +0000 (16:52 +0200)
html/cgi-bin/aliases.cgi

index 09f6ea3..922d76d 100644 (file)
@@ -34,6 +34,13 @@ require '/var/ipfire/general-functions.pl';  # replace /var/ipcop with /var/ipcop
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
+my $configfwdfw                = "${General::swroot}/firewall/config";
+my $configinput                = "${General::swroot}/firewall/input";
+my $configoutgoing     = "${General::swroot}/firewall/outgoing";
+my %input=();
+my %forward=();
+my %output=();
+
 #workaround to suppress a warning when a variable is used only once
 my @dummy = ( ${Header::colouryellow} );
    @dummy = ( ${Header::table1colour} );
@@ -90,7 +97,6 @@ if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
     #
     #Validate static Settings1 here
     #
-    
     unless ($errormessage) {                                   # Everything is ok, save settings
        #map (delete ($settings{$_}) ,(@nosaved,'ACTION','KEY1'));# Must never be saved 
        #&General::writehash($setting, \%settings);             # Save good settings
@@ -146,6 +152,12 @@ if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
        $errormessage = $Lang::tr{'duplicate ip'} . ' (RED)';
         $spacer=" & ";
     }
+    #Check if we have an emtpy name
+    if (!$settings{'NAME'}){
+               $errormessage=$Lang::tr{'fwhost err name1'};
+       }elsif(! &General::validfqdn($settings{'NAME'}) && ! &General::validhostname($settings{'NAME'})){
+               $errormessage=$Lang::tr{'invalid hostname'};
+       }
     my $idx=0;
     foreach my $line (@current) {
         chomp ($line);
@@ -162,6 +174,38 @@ if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
        }
        $idx++;
     }
+       #Update firewallrules if aliasname is changed
+       if ($settings{'OLDNAME'} ne $settings {'NAME'}){
+               &General::readhasharray("$configfwdfw", \%forward);
+               &General::readhasharray("$configinput", \%input);
+               &General::readhasharray("$configoutgoing", \%output);
+               #Check FORWARD
+               foreach my $forwardkey (sort keys %forward){
+                       if ($forward{$forwardkey}[29] eq $settings{'OLDNAME'}){
+                               $forward{$forwardkey}[29] = $settings {'NAME'};
+                       }
+               }
+               &General::writehasharray($configfwdfw, \%forward);
+               #Check INPUT
+               foreach my $inputkey (sort keys %input){
+                       if ($input{$inputkey}[6] eq $settings{'OLDNAME'}){
+                               $input{$inputkey}[6] = $settings {'NAME'};
+                       }
+               }
+               &General::writehasharray($configinput, \%input);
+               #Check OUTPUT
+               foreach my $outputkey (sort keys %output){
+                       if ($output{$outputkey}[4] eq $settings{'OLDNAME'}){
+                               $output{$outputkey}[4] = $settings {'NAME'};
+                       }
+               }
+               &General::writehasharray($configoutgoing, \%output);
+               &General::firewall_config_changed;
+       }
+       #If Alias IP has changed, set firewall_config_changed
+       if($settings{'OLDIP'} ne $settings{'IP'} && $settings{'OLDIP'}){
+               &General::firewall_config_changed;
+       }
     unless ($errormessage) {
        if ($settings{'KEY1'} eq '') { #add or edit ?
            unshift (@current, "$settings{'IP'},$settings{'ENABLED'},$settings{'NAME'}\n");
@@ -275,6 +319,8 @@ if ($settings{'KEY1'} ne '') {
 print <<END
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='KEY1' value='$settings{'KEY1'}' />
+<input type='hidden' name='OLDNAME' value='$settings{'NAME'}' />
+<input type='hidden' name='OLDIP' value='$settings{'IP'}' />
 <table style='width:100%;'>
 <tr>
 <td class='base' style='color:${Header::colourred};'>$Lang::tr{'name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>