X-Git-Url: http://git.ipfire.org/?p=people%2Fteissler%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Faliases.cgi;h=7c3ba91ae02fc3a522ba86aa0aac1a0a993f4a15;hp=4b475c144bdbfa966096e35670f79a725d0ef7d3;hb=48fde0b6f999e12d916127d413357720ac5bd670;hpb=cb5e9c6c64d5281eba5c790f14c2e5f3066becbf diff --git a/html/cgi-bin/aliases.cgi b/html/cgi-bin/aliases.cgi index 4b475c144..7c3ba91ae 100644 --- a/html/cgi-bin/aliases.cgi +++ b/html/cgi-bin/aliases.cgi @@ -1,13 +1,26 @@ #!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007 Michael Tremer & Christian Schmidt # +# # +# 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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 . # +# # +############################################################################### # -# IPFire CGI's - aliases.cgi +# this cgi is base on IPCop CGI - aliases.cgi # -# This code is distributed under the terms of the GPL -# -# (c) Steve Bootes 2002/04/13 - Manage IP Aliases -# -# $Id: aliases.cgi,v 1.5.2.14 2006/01/13 20:14:48 eoberlander Exp $ - # to fully troubleshot your code, uncomment diagnostics, Carp and cluck lines #use diagnostics; # need to add the file /usr/lib/perl5/5.8.x/pods/perldiag.pod before to work @@ -17,10 +30,17 @@ use strict; #use Carp (); #local $SIG{__WARN__} = \&Carp::cluck; -require '/var/ipfire/general-functions.pl'; # replace /var/ipfire with /var/ipfire in case of manual install +require '/var/ipfire/general-functions.pl'; # replace /var/ipcop with /var/ipcop in case of manual install 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} ); @@ -77,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 @@ -106,7 +125,8 @@ if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { #move out new line chomp(@current[$settings{'KEY1'}]); my @temp = split(/\,/,@current[$settings{'KEY1'}]); - $temp[1] = $temp[1] eq 'on' ? '' : 'on'; # Toggle the field + $temp[1] = $temp[1] eq 'on' ? 'off' : 'on'; # Toggle the field + $temp[2] = '' if ( $temp[2] eq '' ); @current[$settings{'KEY1'}] = join (',',@temp)."\n"; $settings{'KEY1'} = ''; # End edit mode @@ -132,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); @@ -148,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"); @@ -227,16 +285,16 @@ my %checked =(); # Checkbox manipulations if ($errormessage) { &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage "; + print "$errormessage "; &Header::closebox(); } unless (( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ ) && ($netsettings{'RED_TYPE'} eq 'STATIC')) { &Header::openbox('100%', 'left', $Lang::tr{'capswarning'}); print < + - +
$Lang::tr{'aliases not active'}$Lang::tr{'aliases not active'}
END @@ -247,7 +305,7 @@ END # # Second check box is for editing the list # -$checked{'ENABLED'}{'on'} = ($settings{'ENABLED'} eq '') ? '' : "checked='checked'"; +$checked{'ENABLED'}{'on'} = ($settings{'ENABLED'} eq 'on') ? "checked='checked'" : '' ; my $buttontext = $Lang::tr{'add'}; if ($settings{'KEY1'} ne '') { @@ -261,21 +319,23 @@ if ($settings{'KEY1'} ne '') { print < - + + +
- + - + - +
$Lang::tr{'name'}: *$Lang::tr{'name'}: $Lang::tr{'alias ip'}: $Lang::tr{'alias ip'}:  $Lang::tr{'enabled'} $Lang::tr{'enabled'} 
+

- +
- - +
* $Lang::tr{'this field may be blank'}
@@ -283,6 +343,20 @@ END ; &Header::closebox(); +# Add visual indicators to column headings to show sort order - EO +my $sortarrow1 = ''; +my $sortarrow2 = ''; + +if ($netsettings{'SORT_ALIASES'} eq 'NAMERev') { + $sortarrow1 = $Header::sortdn; +} elsif ($netsettings{'SORT_ALIASES'} eq 'NAME') { + $sortarrow1 = $Header::sortup; +} elsif ($netsettings{'SORT_ALIASES'} eq 'IPRev') { + $sortarrow2 = $Header::sortdn; +} else { + $sortarrow2 = $Header::sortup; +} + # # Third box shows the list, in columns # @@ -290,11 +364,11 @@ END # &Header::openbox('100%', 'left', $Lang::tr{'current aliases'}); print < + - - - + + + END ; @@ -306,6 +380,7 @@ END # my $key = 0; +my $col=""; foreach my $line (@current) { chomp($line); my @temp = split(/\,/,$line); @@ -323,18 +398,19 @@ foreach my $line (@current) { #Colorize each line if ($settings{'KEY1'} eq $key) { - print ""; + $col="background-color:${Header::colouryellow};"; } elsif ($key % 2) { - print ""; + $col="background-color:${Header::table2colour};"; } else { - print ""; + $col="background-color:${Header::table1colour};"; } + print ""; print <$temp[2] - + + - - -
$Lang::tr{'name'}$Lang::tr{'alias ip'}$Lang::tr{'action'}$Lang::tr{'name'} $sortarrow1$Lang::tr{'alias ip'} $sortarrow2$Lang::tr{'action'}
$temp[0]$temp[2]$temp[0] +
@@ -342,7 +418,7 @@ foreach my $line (@current) {
+
@@ -350,7 +426,7 @@ foreach my $line (@current) {
+
@@ -480,3 +556,4 @@ sub BuildConfiguration { # Restart service associated with this system '/usr/local/bin/setaliases'; } +