]>
Commit | Line | Data |
---|---|---|
2a81ab0d AM |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2012 # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | # # | |
22 | # Hi folks! I hope this code is useful for all. I needed something to handle # | |
23 | # my VPN Connections in a comfortable way. As a prerequisite i needed # | |
24 | # something that makes sure the vpn roadwarrior are able to have a fixed # | |
25 | # ip-address. So i developed the ccd extension for the vpn server. # | |
26 | # # | |
27 | # Now that the ccd extension is ready i am able to develop the main request. # | |
28 | # Any feedback is appreciated. # | |
29 | # # | |
c7043621 | 30 | #Copymaster # |
2a81ab0d AM |
31 | ############################################################################### |
32 | ||
33 | use strict; | |
34 | no warnings 'uninitialized'; | |
35 | # enable only the following on debugging purpose | |
36 | #use warnings; | |
37 | #use CGI::Carp 'fatalsToBrowser'; | |
38 | ||
39 | require '/var/ipfire/general-functions.pl'; | |
40 | require "${General::swroot}/lang.pl"; | |
41 | require "${General::swroot}/header.pl"; | |
42 | require "${General::swroot}/forward/bin/firewall-lib.pl"; | |
43 | ||
44 | unless (-d "${General::swroot}/forward") { system("mkdir ${General::swroot}/forward"); } | |
45 | unless (-e "${General::swroot}/forward/settings") { system("touch ${General::swroot}/forward/settings"); } | |
46 | unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); } | |
47 | unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); } | |
c7043621 | 48 | unless (-e "${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); } |
2a81ab0d AM |
49 | |
50 | my %fwdfwsettings=(); | |
51 | my %selected=() ; | |
52 | my %defaultNetworks=(); | |
53 | my %netsettings=(); | |
54 | my %customhost=(); | |
55 | my %customgrp=(); | |
56 | my %customnetworks=(); | |
57 | my %customservice=(); | |
58 | my %customservicegrp=(); | |
59 | my %ccdnet=(); | |
60 | my %customnetwork=(); | |
61 | my %ccdhost=(); | |
62 | my %configfwdfw=(); | |
63 | my %configinputfw=(); | |
c7043621 | 64 | my %configoutgoingfw=(); |
2a81ab0d AM |
65 | my %ipsecconf=(); |
66 | my %color=(); | |
67 | my %mainsettings=(); | |
68 | my %checked=(); | |
69 | my %icmptypes=(); | |
70 | my %ovpnsettings=(); | |
71 | my %ipsecsettings=(); | |
72 | my %aliases=(); | |
15add1c8 | 73 | my %optionsfw=(); |
c7043621 | 74 | |
2a81ab0d AM |
75 | my $color; |
76 | my $confignet = "${General::swroot}/fwhosts/customnetworks"; | |
77 | my $confighost = "${General::swroot}/fwhosts/customhosts"; | |
78 | my $configgrp = "${General::swroot}/fwhosts/customgroups"; | |
79 | my $configsrv = "${General::swroot}/fwhosts/customservices"; | |
80 | my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp"; | |
81 | my $configccdnet = "${General::swroot}/ovpn/ccd.conf"; | |
82 | my $configccdhost = "${General::swroot}/ovpn/ovpnconfig"; | |
83 | my $configipsec = "${General::swroot}/vpn/config"; | |
84 | my $configipsecrw = "${General::swroot}/vpn/settings"; | |
85 | my $configfwdfw = "${General::swroot}/forward/config"; | |
86 | my $configinput = "${General::swroot}/forward/input"; | |
c7043621 | 87 | my $configoutgoing = "${General::swroot}/forward/outgoing"; |
2a81ab0d | 88 | my $configovpn = "${General::swroot}/ovpn/settings"; |
15add1c8 | 89 | my $fwoptions = "${General::swroot}/optionsfw/settings"; |
2a81ab0d AM |
90 | my $errormessage=''; |
91 | my $hint=''; | |
92 | my $ipgrp="${General::swroot}/outgoing/groups"; | |
15add1c8 | 93 | my $tdcolor=''; |
2a81ab0d AM |
94 | |
95 | &General::readhash("${General::swroot}/forward/settings", \%fwdfwsettings); | |
96 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
97 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
15add1c8 | 98 | &General::readhash($fwoptions, \%optionsfw); |
2a81ab0d AM |
99 | |
100 | &Header::showhttpheaders(); | |
101 | &Header::getcgihash(\%fwdfwsettings); | |
102 | &Header::openpage($Lang::tr{'fwdfw menu'}, 1, ''); | |
103 | &Header::openbigbox('100%', 'center',$errormessage); | |
104 | #### ACTION ##### | |
105 | ||
106 | if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'save'}) | |
107 | { | |
108 | my $MODE = $fwdfwsettings{'POLICY'}; | |
5d7faa45 | 109 | my $MODE1 = $fwdfwsettings{'POLICY1'}; |
2a81ab0d AM |
110 | %fwdfwsettings = (); |
111 | $fwdfwsettings{'POLICY'} = "$MODE"; | |
5d7faa45 | 112 | $fwdfwsettings{'POLICY1'} = "$MODE1"; |
2a81ab0d AM |
113 | &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings); |
114 | &reread_rules; | |
115 | } | |
116 | if ($fwdfwsettings{'ACTION'} eq 'saverule') | |
117 | { | |
118 | &General::readhasharray("$configfwdfw", \%configfwdfw); | |
119 | &General::readhasharray("$configinput", \%configinputfw); | |
5d7faa45 | 120 | &General::readhasharray("$configoutgoing", \%configoutgoingfw); |
2a81ab0d AM |
121 | $errormessage=&checksource; |
122 | if(!$errormessage){&checktarget;} | |
123 | if(!$errormessage){&checkrule;} | |
c7043621 AM |
124 | #check if we try to break rules |
125 | if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire'){ | |
126 | $errormessage.=$Lang::tr{'fwdfw err same'}; | |
127 | } | |
2a81ab0d AM |
128 | #INPUT part |
129 | if($fwdfwsettings{'grp2'} eq 'ipfire'){ | |
5de39dea | 130 | $fwdfwsettings{'config'}=$configinput; |
2a81ab0d | 131 | $fwdfwsettings{'chain'} = 'INPUTFW'; |
70d38e50 | 132 | my $maxkey=&General::findhasharraykey(\%configinputfw); |
2a81ab0d | 133 | #check if we have an identical rule already |
70d38e50 | 134 | if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){ |
2da264ec AM |
135 | foreach my $key (sort keys %configinputfw){ |
136 | if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}" | |
137 | eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27]"){ | |
138 | $errormessage.=$Lang::tr{'fwdfw err ruleexists'}; | |
15add1c8 | 139 | if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} eq ''){ |
02da9f7b | 140 | $errormessage=''; |
15add1c8 | 141 | }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){ |
61068ee1 | 142 | $errormessage=$Lang::tr{'fwdfw err remark'}."<br>"; |
02da9f7b AM |
143 | } |
144 | if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){ | |
145 | $fwdfwsettings{'nosave'} = 'on'; | |
146 | } | |
2da264ec | 147 | } |
62fc8511 | 148 | } |
2da264ec | 149 | } |
70d38e50 AM |
150 | #check Rulepos on new Rule |
151 | if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){ | |
152 | $fwdfwsettings{'oldrulenumber'}=$maxkey; | |
153 | foreach my $key (sort keys %configinputfw){ | |
154 | if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}" | |
155 | eq "$configinputfw{$key}[0],$configinputfw{$key}[2],$configinputfw{$key}[3],$configinputfw{$key}[4],$configinputfw{$key}[5],$configinputfw{$key}[6],$configinputfw{$key}[7],$configinputfw{$key}[8],$configinputfw{$key}[9],$configinputfw{$key}[10],$configinputfw{$key}[11],$configinputfw{$key}[12],$configinputfw{$key}[13],$configinputfw{$key}[14],$configinputfw{$key}[15],$configinputfw{$key}[17],$configinputfw{$key}[18],$configinputfw{$key}[19],$configinputfw{$key}[20],$configinputfw{$key}[21],$configinputfw{$key}[22],$configinputfw{$key}[23],$configinputfw{$key}[24],$configinputfw{$key}[25],$configinputfw{$key}[26],$configinputfw{$key}[27]"){ | |
156 | $errormessage.=$Lang::tr{'fwdfw err ruleexists'}; | |
157 | } | |
158 | } | |
159 | } | |
992394d5 AM |
160 | #check if we just close a rule |
161 | if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} ) { | |
162 | if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
163 | $errormessage=''; | |
164 | $fwdfwsettings{'nosave2'} = 'on'; | |
165 | } | |
166 | } | |
62fc8511 AM |
167 | &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}}); |
168 | if ($fwdfwsettings{'nobase'} ne 'on'){ | |
169 | &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}}); | |
170 | } | |
171 | if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){ | |
172 | &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
173 | }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') { | |
174 | &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0); | |
175 | }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
176 | &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
177 | } | |
992394d5 AM |
178 | if($fwdfwsettings{'nosave2'} ne 'on'){ |
179 | &saverule(\%configinputfw,$configinput); | |
180 | } | |
2a81ab0d AM |
181 | #print "Source: $fwdfwsettings{'grp1'} -> $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>"; |
182 | #print "Sourceport: $fwdfwsettings{'USE_SRC_PORT'}, $fwdfwsettings{'PROT'}, $fwdfwsettings{'ICMP_TYPES'}, $fwdfwsettings{'SRC_PORT'}<br>"; | |
183 | #print "Target: $fwdfwsettings{'grp2'} -> $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>"; | |
184 | #print "Dienst: $fwdfwsettings{'USESRV'}, $fwdfwsettings{'grp3'} -> $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>"; | |
185 | #print "BEMERKUNG: $fwdfwsettings{'ruleremark'}<br>"; | |
186 | #print " Regel AKTIV: $fwdfwsettings{'ACTIVE'}<br>"; | |
187 | #print " Regel LOG: $fwdfwsettings{'LOG'}<br>"; | |
188 | #print " ZEITRAHMEN: $fwdfwsettings{'TIME'}<br>"; | |
189 | #print " MO: $fwdfwsettings{'TIME_MON'}<br>"; | |
190 | #print " DI: $fwdfwsettings{'TIME_TUE'}<br>"; | |
191 | #print " MI: $fwdfwsettings{'TIME_WED'}<br>"; | |
192 | #print " DO: $fwdfwsettings{'TIME_THU'}<br>"; | |
193 | #print " FR: $fwdfwsettings{'TIME_FRI'}<br>"; | |
194 | #print " SA: $fwdfwsettings{'TIME_SAT'}<br>"; | |
195 | #print " SO: $fwdfwsettings{'TIME_SUN'}<br>"; | |
196 | #print " VON: $fwdfwsettings{'TIME_FROM'} bis $fwdfwsettings{'TIME_TO'}<br>"; | |
197 | #print "<br>"; | |
198 | #print"ALT: $fwdfwsettings{'oldgrp1a'} $fwdfwsettings{'oldgrp1b'} NEU: $fwdfwsettings{'grp1'} $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>"; | |
199 | #print"ALT: $fwdfwsettings{'oldgrp2a'} $fwdfwsettings{'oldgrp2b'} NEU: $fwdfwsettings{'grp2'} $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>"; | |
200 | #print"ALT: $fwdfwsettings{'oldgrp3a'} $fwdfwsettings{'oldgrp3b'} NEU: $fwdfwsettings{'grp3'} $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>"; | |
201 | #print"DIENSTE Checkalt:$fwdfwsettings{'oldusesrv'} DIENSTE Checkneu:$fwdfwsettings{'USESRV'} DIENST ALT:$fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'} DIENST NEU:$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}<br>"; | |
aa864783 | 202 | }elsif($fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' ){ |
d7127db8 | 203 | # OUTGOING PART |
c7043621 AM |
204 | $fwdfwsettings{'config'}=$configoutgoing; |
205 | $fwdfwsettings{'chain'} = 'OUTGOINGFW'; | |
206 | my $maxkey=&General::findhasharraykey(\%configoutgoingfw); | |
207 | if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){ | |
208 | foreach my $key (sort keys %configoutgoingfw){ | |
209 | if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}" | |
210 | eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27]"){ | |
211 | $errormessage.=$Lang::tr{'fwdfw err ruleexists'}; | |
15add1c8 | 212 | if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} eq ''){ |
c7043621 | 213 | $errormessage=''; |
15add1c8 | 214 | }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){ |
c7043621 AM |
215 | $errormessage=$Lang::tr{'fwdfw err remark'}."<br>"; |
216 | } | |
217 | if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){ | |
218 | $fwdfwsettings{'nosave'} = 'on'; | |
219 | } | |
220 | } | |
221 | } | |
222 | } | |
223 | #check Rulepos on new Rule | |
224 | if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){ | |
5d7faa45 | 225 | print"CHECK OUTGOING DOPPELTE REGEL<br>"; |
c7043621 AM |
226 | $fwdfwsettings{'oldrulenumber'}=$maxkey; |
227 | foreach my $key (sort keys %configoutgoingfw){ | |
228 | if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}" | |
229 | eq "$configoutgoingfw{$key}[0],$configoutgoingfw{$key}[2],$configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],$configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],$configoutgoingfw{$key}[7],$configoutgoingfw{$key}[8],$configoutgoingfw{$key}[9],$configoutgoingfw{$key}[10],$configoutgoingfw{$key}[11],$configoutgoingfw{$key}[12],$configoutgoingfw{$key}[13],$configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],$configoutgoingfw{$key}[17],$configoutgoingfw{$key}[18],$configoutgoingfw{$key}[19],$configoutgoingfw{$key}[20],$configoutgoingfw{$key}[21],$configoutgoingfw{$key}[22],$configoutgoingfw{$key}[23],$configoutgoingfw{$key}[24],$configoutgoingfw{$key}[25],$configoutgoingfw{$key}[26],$configoutgoingfw{$key}[27]"){ | |
230 | $errormessage.=$Lang::tr{'fwdfw err ruleexists'}; | |
231 | } | |
232 | } | |
233 | } | |
234 | #check if we just close a rule | |
235 | if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'} ) { | |
236 | if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
237 | $fwdfwsettings{'nosave2'} = 'on'; | |
238 | $errormessage=''; | |
239 | } | |
240 | } | |
241 | #increase counters | |
242 | &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}}); | |
243 | &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}}); | |
244 | if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){ | |
245 | &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
246 | }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') { | |
247 | &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0); | |
248 | }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
249 | &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
250 | } | |
251 | if ($fwdfwsettings{'nobase'} eq 'on'){ | |
252 | &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
253 | } | |
254 | if ($fwdfwsettings{'nosave2'} ne 'on'){ | |
255 | &saverule(\%configoutgoingfw,$configoutgoing); | |
256 | } | |
2a81ab0d | 257 | }else{ |
27f4a6b1 | 258 | #FORWARD PART |
5de39dea | 259 | $fwdfwsettings{'config'}=$configfwdfw; |
2a81ab0d | 260 | $fwdfwsettings{'chain'} = 'FORWARDFW'; |
70d38e50 | 261 | my $maxkey=&General::findhasharraykey(\%configfwdfw); |
2da264ec AM |
262 | if($fwdfwsettings{'oldrulenumber'} eq $fwdfwsettings{'rulepos'}){ |
263 | #check if we have an identical rule already | |
264 | foreach my $key (sort keys %configfwdfw){ | |
265 | if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}" | |
266 | eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[17],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27]"){ | |
267 | $errormessage.=$Lang::tr{'fwdfw err ruleexists'}; | |
15add1c8 | 268 | if ($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} eq ''){ |
02da9f7b | 269 | $errormessage=''; |
15add1c8 | 270 | }elsif($fwdfwsettings{'oldruleremark'} ne $fwdfwsettings{'ruleremark'} && $fwdfwsettings{'updatefwrule'} eq 'on' && $fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){ |
61068ee1 | 271 | $errormessage=$Lang::tr{'fwdfw err remark'}."<br>"; |
02da9f7b AM |
272 | } |
273 | if ($fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'}){ | |
274 | $fwdfwsettings{'nosave'} = 'on'; | |
275 | } | |
2da264ec AM |
276 | } |
277 | } | |
2a81ab0d | 278 | } |
70d38e50 AM |
279 | #check Rulepos on new Rule |
280 | if($fwdfwsettings{'rulepos'} > 0 && !$fwdfwsettings{'oldrulenumber'}){ | |
281 | $fwdfwsettings{'oldrulenumber'}=$maxkey; | |
282 | foreach my $key (sort keys %configfwdfw){ | |
283 | if ("$fwdfwsettings{'RULE_ACTION'},$fwdfwsettings{'ACTIVE'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}},$fwdfwsettings{'USE_SRC_PORT'},$fwdfwsettings{'PROT'},$fwdfwsettings{'ICMP_TYPES'},$fwdfwsettings{'SRC_PORT'},$fwdfwsettings{'USESRV'},$fwdfwsettings{'TGT_PROT'},$fwdfwsettings{'ICMP_TGT'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}},$fwdfwsettings{'LOG'},$fwdfwsettings{'TIME'},$fwdfwsettings{'TIME_MON'},$fwdfwsettings{'TIME_TUE'},$fwdfwsettings{'TIME_WED'},$fwdfwsettings{'TIME_THU'},$fwdfwsettings{'TIME_FRI'},$fwdfwsettings{'TIME_SAT'},$fwdfwsettings{'TIME_SUN'},$fwdfwsettings{'TIME_FROM'},$fwdfwsettings{'TIME_TO'}" | |
284 | eq "$configfwdfw{$key}[0],$configfwdfw{$key}[2],$configfwdfw{$key}[3],$configfwdfw{$key}[4],$configfwdfw{$key}[5],$configfwdfw{$key}[6],$configfwdfw{$key}[7],$configfwdfw{$key}[8],$configfwdfw{$key}[9],$configfwdfw{$key}[10],$configfwdfw{$key}[11],$configfwdfw{$key}[12],$configfwdfw{$key}[13],$configfwdfw{$key}[14],$configfwdfw{$key}[15],$configfwdfw{$key}[17],$configfwdfw{$key}[18],$configfwdfw{$key}[19],$configfwdfw{$key}[20],$configfwdfw{$key}[21],$configfwdfw{$key}[22],$configfwdfw{$key}[23],$configfwdfw{$key}[24],$configfwdfw{$key}[25],$configfwdfw{$key}[26],$configfwdfw{$key}[27]"){ | |
285 | $errormessage.=$Lang::tr{'fwdfw err ruleexists'}; | |
286 | } | |
287 | } | |
288 | } | |
992394d5 | 289 | #check if we just close a rule |
8f0b047b | 290 | if( $fwdfwsettings{'oldgrp1a'} eq $fwdfwsettings{'grp1'} && $fwdfwsettings{'oldgrp1b'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'oldgrp2a'} eq $fwdfwsettings{'grp2'} && $fwdfwsettings{'oldgrp2b'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'oldgrp3a'} eq $fwdfwsettings{'grp3'} && $fwdfwsettings{'oldgrp3b'} eq $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldruleremark'} eq $fwdfwsettings{'ruleremark'} ) { |
992394d5 AM |
291 | if($fwdfwsettings{'nosave'} eq 'on' && $fwdfwsettings{'updatefwrule'} eq 'on'){ |
292 | $fwdfwsettings{'nosave2'} = 'on'; | |
293 | $errormessage=''; | |
294 | } | |
295 | } | |
2a81ab0d AM |
296 | #increase counters |
297 | &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}}); | |
2a81ab0d | 298 | &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}}); |
2a81ab0d AM |
299 | if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){ |
300 | &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
301 | }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') { | |
302 | &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0); | |
303 | }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
304 | &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
305 | } | |
2a81ab0d AM |
306 | if ($fwdfwsettings{'nobase'} eq 'on'){ |
307 | &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
308 | } | |
992394d5 AM |
309 | if ($fwdfwsettings{'nosave2'} ne 'on'){ |
310 | &saverule(\%configfwdfw,$configfwdfw); | |
311 | } | |
2a81ab0d AM |
312 | #print "Source: $fwdfwsettings{'grp1'} -> $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>"; |
313 | #print "Sourceport: $fwdfwsettings{'USE_SRC_PORT'}, $fwdfwsettings{'PROT'}, $fwdfwsettings{'ICMP_TYPES'}, $fwdfwsettings{'SRC_PORT'}<br>"; | |
314 | #print "Target: $fwdfwsettings{'grp2'} -> $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>"; | |
315 | #print "Dienst: $fwdfwsettings{'USESRV'}, $fwdfwsettings{'grp3'} -> $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>"; | |
316 | #print "BEMERKUNG: $fwdfwsettings{'ruleremark'}<br>"; | |
317 | #print " Regel AKTIV: $fwdfwsettings{'ACTIVE'}<br>"; | |
318 | #print " Regel LOG: $fwdfwsettings{'LOG'}<br>"; | |
319 | #print " ZEITRAHMEN: $fwdfwsettings{'TIME'}<br>"; | |
320 | #print " MO: $fwdfwsettings{'TIME_MON'}<br>"; | |
321 | #print " DI: $fwdfwsettings{'TIME_TUE'}<br>"; | |
322 | #print " MI: $fwdfwsettings{'TIME_WED'}<br>"; | |
323 | #print " DO: $fwdfwsettings{'TIME_THU'}<br>"; | |
324 | #print " FR: $fwdfwsettings{'TIME_FRI'}<br>"; | |
325 | #print " SA: $fwdfwsettings{'TIME_SAT'}<br>"; | |
326 | #print " SO: $fwdfwsettings{'TIME_SUN'}<br>"; | |
327 | #print " VON: $fwdfwsettings{'TIME_FROM'} bis $fwdfwsettings{'TIME_TO'}<br>"; | |
328 | #print "<br>"; | |
329 | #print"ALT: $fwdfwsettings{'oldgrp1a'} $fwdfwsettings{'oldgrp1b'} NEU: $fwdfwsettings{'grp1'} $fwdfwsettings{$fwdfwsettings{'grp1'}}<br>"; | |
330 | #print"ALT: $fwdfwsettings{'oldgrp2a'} $fwdfwsettings{'oldgrp2b'} NEU: $fwdfwsettings{'grp2'} $fwdfwsettings{$fwdfwsettings{'grp2'}}<br>"; | |
331 | #print"ALT: $fwdfwsettings{'oldgrp3a'} $fwdfwsettings{'oldgrp3b'} NEU: $fwdfwsettings{'grp3'} $fwdfwsettings{$fwdfwsettings{'grp3'}}<br>"; | |
332 | #print"DIENSTE Checkalt:$fwdfwsettings{'oldusesrv'} DIENSTE Checkneu:$fwdfwsettings{'USESRV'} DIENST ALT:$fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'} DIENST NEU:$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}<br>"; | |
2a81ab0d AM |
333 | } |
334 | if ($errormessage){ | |
335 | &newrule; | |
336 | }else{ | |
992394d5 AM |
337 | if($fwdfwsettings{'nosave2'} ne 'on'){ |
338 | &rules; | |
339 | } | |
2a81ab0d AM |
340 | &base; |
341 | } | |
2a81ab0d AM |
342 | } |
343 | if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'reset'}) | |
344 | { | |
345 | &General::readhasharray("$configfwdfw", \%configfwdfw); | |
346 | foreach my $key (sort keys %configfwdfw){ | |
347 | &checkcounter($configfwdfw{$key}[3],$configfwdfw{$key}[4],,); | |
348 | &checkcounter($configfwdfw{$key}[5],$configfwdfw{$key}[6],,); | |
349 | &checkcounter($configfwdfw{$key}[14],$configfwdfw{$key}[15],,); | |
350 | } | |
351 | &General::readhasharray("$configinput", \%configinputfw); | |
352 | foreach my $key (sort keys %configinputfw){ | |
353 | &checkcounter($configinputfw{$key}[3],$configinputfw{$key}[4],,); | |
354 | &checkcounter($configinputfw{$key}[5],$configinputfw{$key}[6],,); | |
355 | &checkcounter($configinputfw{$key}[14],$configinputfw{$key}[15],,); | |
356 | } | |
7bd9d462 | 357 | |
2a81ab0d AM |
358 | system("rm ${General::swroot}/forward/config"); |
359 | system("rm ${General::swroot}/forward/input"); | |
2a81ab0d AM |
360 | &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings); |
361 | unless (-e "${General::swroot}/forward/config") { system("touch ${General::swroot}/forward/config"); } | |
362 | unless (-e "${General::swroot}/forward/input") { system("touch ${General::swroot}/forward/input"); } | |
5d7faa45 | 363 | my $MODE1=$fwdfwsettings{'POLICY1'}; |
62fc8511 | 364 | %fwdfwsettings = (); |
7bd9d462 | 365 | $fwdfwsettings{'POLICY'}='MODE2'; |
5d7faa45 AM |
366 | $fwdfwsettings{'POLICY1'}=$MODE1; |
367 | &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings); | |
368 | &reread_rules; | |
369 | ||
370 | } | |
371 | if ($fwdfwsettings{'ACTION'} eq 'resetoutgoing') | |
372 | { | |
373 | &General::readhasharray("$configoutgoing", \%configoutgoingfw); | |
374 | foreach my $key (sort keys %configoutgoingfw){ | |
375 | &checkcounter($configoutgoingfw{$key}[3],$configoutgoingfw{$key}[4],,); | |
376 | &checkcounter($configoutgoingfw{$key}[5],$configoutgoingfw{$key}[6],,); | |
377 | &checkcounter($configoutgoingfw{$key}[14],$configoutgoingfw{$key}[15],,); | |
378 | } | |
379 | system("rm ${General::swroot}/forward/outgoing"); | |
380 | &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings); | |
381 | unless (-e "${General::swroot}/forward/outgoing") { system("touch ${General::swroot}/forward/outgoing"); } | |
382 | my $MODE=$fwdfwsettings{'POLICY'}; | |
383 | %fwdfwsettings = (); | |
384 | $fwdfwsettings{'POLICY'}=$MODE; | |
385 | $fwdfwsettings{'POLICY1'}='MODE2'; | |
7bd9d462 | 386 | &General::writehash("${General::swroot}/forward/settings", \%fwdfwsettings); |
2a81ab0d AM |
387 | &reread_rules; |
388 | ||
389 | } | |
390 | if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw newrule'}) | |
391 | { | |
392 | &newrule; | |
393 | } | |
394 | if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'}) | |
395 | { | |
396 | my %togglehash=(); | |
397 | &General::readhasharray($fwdfwsettings{'config'}, \%togglehash); | |
398 | foreach my $key (sort keys %togglehash){ | |
399 | if ($key eq $fwdfwsettings{'key'}){ | |
400 | if ($togglehash{$key}[2] eq 'ON'){$togglehash{$key}[2]='';}else{$togglehash{$key}[2]='ON';} | |
401 | } | |
402 | } | |
403 | &General::writehasharray($fwdfwsettings{'config'}, \%togglehash); | |
404 | &rules; | |
405 | &base; | |
406 | } | |
407 | if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'}) | |
408 | { | |
409 | my %togglehash=(); | |
410 | &General::readhasharray($fwdfwsettings{'config'}, \%togglehash); | |
411 | foreach my $key (sort keys %togglehash){ | |
412 | if ($key eq $fwdfwsettings{'key'}){ | |
413 | if ($togglehash{$key}[17] eq 'ON'){$togglehash{$key}[17]='';}else{$togglehash{$key}[17]='ON';} | |
414 | } | |
415 | } | |
416 | &General::writehasharray($fwdfwsettings{'config'}, \%togglehash); | |
417 | &rules; | |
418 | &base; | |
419 | } | |
420 | if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'}) | |
421 | { | |
422 | &reread_rules; | |
423 | &base; | |
424 | } | |
425 | if ($fwdfwsettings{'ACTION'} eq 'editrule') | |
426 | { | |
427 | $fwdfwsettings{'updatefwrule'}='on'; | |
428 | &newrule; | |
429 | } | |
430 | if ($fwdfwsettings{'ACTION'} eq 'deleterule') | |
431 | { | |
432 | &deleterule; | |
433 | } | |
434 | if ($fwdfwsettings{'ACTION'} eq 'moveup') | |
435 | { | |
436 | &pos_up; | |
437 | &base; | |
438 | } | |
439 | if ($fwdfwsettings{'ACTION'} eq 'movedown') | |
440 | { | |
441 | &pos_down; | |
442 | &base; | |
443 | } | |
444 | if ($fwdfwsettings{'ACTION'} eq 'copyrule') | |
445 | { | |
446 | $fwdfwsettings{'copyfwrule'}='on'; | |
447 | #$fwdfwsettings{'updatefwrule'}='on'; | |
448 | &newrule; | |
449 | } | |
450 | if ($fwdfwsettings{'ACTION'} eq '') | |
451 | { | |
452 | &base; | |
453 | } | |
454 | ### Functions #### | |
c7043621 AM |
455 | sub changerule |
456 | { | |
457 | my $oldchain=shift; | |
458 | $fwdfwsettings{'updatefwrule'}=''; | |
459 | $fwdfwsettings{'config'}=$oldchain; | |
460 | $fwdfwsettings{'nobase'}='on'; | |
461 | &deleterule; | |
462 | &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}}); | |
463 | &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}}); | |
464 | } | |
2a81ab0d AM |
465 | sub pos_up |
466 | { | |
467 | my %uphash=(); | |
468 | my %tmp=(); | |
469 | &General::readhasharray($fwdfwsettings{'config'}, \%uphash); | |
470 | foreach my $key (sort keys %uphash){ | |
471 | if ($key eq $fwdfwsettings{'key'}) { | |
472 | my $last = $key -1; | |
473 | if (exists $uphash{$last}){ | |
474 | #save rule last | |
475 | foreach my $y (0 .. $#{$uphash{$last}}) { | |
476 | $tmp{0}[$y] = $uphash{$last}[$y]; | |
477 | } | |
478 | #copy active rule to last | |
479 | foreach my $i (0 .. $#{$uphash{$last}}) { | |
480 | $uphash{$last}[$i] = $uphash{$key}[$i]; | |
481 | } | |
482 | #copy saved rule to actual position | |
483 | foreach my $x (0 .. $#{$tmp{0}}) { | |
484 | $uphash{$key}[$x] = $tmp{0}[$x]; | |
485 | } | |
486 | } | |
487 | } | |
488 | } | |
489 | &General::writehasharray($fwdfwsettings{'config'}, \%uphash); | |
490 | &rules; | |
491 | } | |
492 | sub pos_down | |
493 | { | |
494 | my %downhash=(); | |
495 | my %tmp=(); | |
496 | &General::readhasharray($fwdfwsettings{'config'}, \%downhash); | |
497 | foreach my $key (sort keys %downhash){ | |
498 | if ($key eq $fwdfwsettings{'key'}) { | |
499 | my $next = $key + 1; | |
500 | if (exists $downhash{$next}){ | |
501 | #save rule next | |
502 | foreach my $y (0 .. $#{$downhash{$next}}) { | |
503 | $tmp{0}[$y] = $downhash{$next}[$y]; | |
504 | } | |
505 | #copy active rule to next | |
506 | foreach my $i (0 .. $#{$downhash{$next}}) { | |
507 | $downhash{$next}[$i] = $downhash{$key}[$i]; | |
508 | } | |
509 | #copy saved rule to actual position | |
510 | foreach my $x (0 .. $#{$tmp{0}}) { | |
511 | $downhash{$key}[$x] = $tmp{0}[$x]; | |
512 | } | |
513 | } | |
514 | } | |
515 | } | |
516 | &General::writehasharray($fwdfwsettings{'config'}, \%downhash); | |
517 | &rules; | |
518 | } | |
519 | sub checkcounter | |
520 | { | |
521 | my ($base1,$val1,$base2,$val2) = @_; | |
522 | ||
523 | if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){ | |
524 | &dec_counter($confignet,\%customnetwork,$val1); | |
525 | }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){ | |
526 | &dec_counter($confighost,\%customhost,$val1); | |
527 | }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){ | |
528 | &dec_counter($configgrp,\%customgrp,$val1); | |
529 | }elsif($base1 eq 'cust_srv'){ | |
530 | &dec_counter($configsrv,\%customservice,$val1); | |
531 | }elsif($base1 eq 'cust_srvgrp'){ | |
532 | &dec_counter($configsrvgrp,\%customservicegrp,$val1); | |
533 | } | |
62fc8511 | 534 | |
2a81ab0d AM |
535 | if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){ |
536 | &inc_counter($confignet,\%customnetwork,$val2); | |
537 | }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){ | |
538 | &inc_counter($confighost,\%customhost,$val2); | |
539 | }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){ | |
540 | &inc_counter($configgrp,\%customgrp,$val2); | |
541 | }elsif($base2 eq 'cust_srv'){ | |
542 | &inc_counter($configsrv,\%customservice,$val2); | |
543 | }elsif($base2 eq 'cust_srvgrp'){ | |
544 | &inc_counter($configsrvgrp,\%customservicegrp,$val2); | |
545 | } | |
546 | } | |
547 | sub inc_counter | |
548 | { | |
549 | my $config=shift; | |
550 | my %hash=%{(shift)}; | |
551 | my $val=shift; | |
552 | my $pos; | |
62fc8511 | 553 | |
2a81ab0d AM |
554 | &General::readhasharray($config, \%hash); |
555 | foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){ | |
556 | if($hash{$key}[0] eq $val){ | |
557 | $pos=$#{$hash{$key}}; | |
558 | $hash{$key}[$pos] = $hash{$key}[$pos]+1; | |
2a81ab0d AM |
559 | } |
560 | } | |
561 | &General::writehasharray($config, \%hash); | |
562 | } | |
563 | sub dec_counter | |
564 | { | |
565 | my $config=shift; | |
566 | my %hash=%{(shift)}; | |
567 | my $val=shift; | |
568 | my $pos; | |
569 | #$errormessage.="ALT:config: $config , verringert wird $val <br>"; | |
570 | &General::readhasharray($config, \%hash); | |
571 | foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){ | |
572 | if($hash{$key}[0] eq $val){ | |
573 | $pos=$#{$hash{$key}}; | |
574 | $hash{$key}[$pos] = $hash{$key}[$pos]-1; | |
2a81ab0d AM |
575 | } |
576 | } | |
577 | &General::writehasharray($config, \%hash); | |
578 | } | |
579 | sub base | |
580 | { | |
2a81ab0d AM |
581 | if ($fwdfwsettings{'POLICY'} eq 'MODE1'){ $selected{'POLICY'}{'MODE1'} = 'selected'; } else { $selected{'POLICY'}{'MODE1'} = ''; } |
582 | if ($fwdfwsettings{'POLICY'} eq 'MODE2'){ $selected{'POLICY'}{'MODE2'} = 'selected'; } else { $selected{'POLICY'}{'MODE2'} = ''; } | |
5d7faa45 AM |
583 | if ($fwdfwsettings{'POLICY1'} eq 'MODE1'){ $selected{'POLICY1'}{'MODE1'} = 'selected'; } else { $selected{'POLICY1'}{'MODE1'} = ''; } |
584 | if ($fwdfwsettings{'POLICY1'} eq 'MODE2'){ $selected{'POLICY1'}{'MODE2'} = 'selected'; } else { $selected{'POLICY1'}{'MODE2'} = ''; } | |
2a81ab0d | 585 | &hint; |
7bd9d462 | 586 | &addrule; |
7bf83f9d | 587 | print "<br><hr><br><br>"; |
2b9460ab | 588 | &Header::openbox('100%', 'center', $Lang::tr{'fwdfw pol title'}); |
2a81ab0d AM |
589 | print <<END; |
590 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
2b9460ab | 591 | <table width='100%' border='0'> |
5d7faa45 | 592 | <tr><td colspan='3' style='font-weight:bold;color:red;'>FORWARD </td></tr> |
2b9460ab | 593 | <tr><td colspan='3'>$Lang::tr{'fwdfw pol text'}</td></tr> |
2a81ab0d | 594 | <tr><td colspan='3'><hr /></td></tr> |
8f1634ff | 595 | <tr><td width='15%' align='left'> <select name='POLICY' style="width: 100px"> |
2b9460ab AM |
596 | <option value='MODE1' $selected{'POLICY'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option> |
597 | <option value='MODE2' $selected{'POLICY'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select> | |
b324de14 AM |
598 | <input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td><td width='45%' align='right'> |
599 | ||
2a81ab0d | 600 | END |
b324de14 | 601 | print "$Lang::tr{'outgoing firewall reset'}: <input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /></td></tr>"; |
36196d0d | 602 | print "</table></form>"; |
5d7faa45 AM |
603 | print"<br><br>"; |
604 | print <<END; | |
605 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
606 | <table width='100%' border='0'> | |
607 | <tr><td colspan='3' style='font-weight:bold;color:red;'>OUTGOING </td></tr> | |
608 | <tr><td colspan='3'>$Lang::tr{'fwdfw pol text1'}</td></tr> | |
609 | <tr><td colspan='3'><hr /></td></tr> | |
610 | <tr><td width='15%' align='left'> <select name='POLICY1' style="width: 100px"> | |
611 | <option value='MODE1' $selected{'POLICY1'}{'MODE1'}>$Lang::tr{'fwdfw pol block'}</option> | |
612 | <option value='MODE2' $selected{'POLICY1'}{'MODE2'}>$Lang::tr{'fwdfw pol allow'}</option></select> | |
b324de14 AM |
613 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></form></td><td width='45%' align='right'> |
614 | ||
5d7faa45 | 615 | END |
b324de14 | 616 | print "$Lang::tr{'outgoing firewall reset'}: <form method='post' action='$ENV{'SCRIPT_NAME'}' style='display:inline'><input type='submit' value='$Lang::tr{'reset'}' /><input type='hidden' name='ACTION' value='resetoutgoing' /></tr>"; |
5d7faa45 | 617 | print "</table></form>"; |
2a81ab0d AM |
618 | &Header::closebox(); |
619 | } | |
620 | sub addrule | |
621 | { | |
622 | &error; | |
7bf83f9d AM |
623 | if (-f "${General::swroot}/forward/reread"){ |
624 | print "<table border='0'><form method='post'><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: red; font-weight: bold;'>$Lang::tr{'fwhost reread'}</td></tr></table></form><hr><br>"; | |
625 | } | |
2a81ab0d | 626 | &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'}); |
2a81ab0d AM |
627 | print "<form method='post'>"; |
628 | print "<table border='0'>"; | |
629 | print "<tr><td><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw newrule'}'></td>"; | |
7bf83f9d | 630 | print"</tr></table></form><hr>"; |
2a81ab0d AM |
631 | &Header::closebox(); |
632 | &viewtablerule; | |
2a81ab0d AM |
633 | } |
634 | sub deleterule | |
635 | { | |
636 | my %delhash=(); | |
637 | &General::readhasharray($fwdfwsettings{'config'}, \%delhash); | |
2da264ec | 638 | foreach my $key (sort {$a <=> $b} keys %delhash){ |
992394d5 | 639 | if ($key == $fwdfwsettings{'key'}){ |
2a81ab0d AM |
640 | #check hosts/net and groups |
641 | &checkcounter($delhash{$key}[3],$delhash{$key}[4],,); | |
642 | &checkcounter($delhash{$key}[5],$delhash{$key}[6],,); | |
643 | #check services and groups | |
644 | if ($delhash{$key}[11] eq 'ON'){ | |
645 | &checkcounter($delhash{$key}[14],$delhash{$key}[15],,); | |
646 | } | |
647 | } | |
992394d5 | 648 | if ($key >= $fwdfwsettings{'key'}) { |
2a81ab0d AM |
649 | my $next = $key + 1; |
650 | if (exists $delhash{$next}) { | |
e5345541 | 651 | foreach my $i (0 .. $#{$delhash{$next}}) { |
2a81ab0d AM |
652 | $delhash{$key}[$i] = $delhash{$next}[$i]; |
653 | } | |
654 | } | |
655 | } | |
656 | } | |
657 | # Remove the very last entry. | |
275a92e8 | 658 | my $last_key = (sort {$a <=> $b} keys %delhash)[-1]; |
2a81ab0d AM |
659 | delete $delhash{$last_key}; |
660 | ||
661 | &General::writehasharray($fwdfwsettings{'config'}, \%delhash); | |
662 | &rules; | |
62fc8511 | 663 | |
2a81ab0d AM |
664 | if($fwdfwsettings{'nobase'} ne 'on'){ |
665 | &base; | |
666 | } | |
667 | } | |
668 | sub disable_rule | |
669 | { | |
670 | my $key1=shift; | |
671 | &General::readhasharray("$configfwdfw", \%configfwdfw); | |
672 | foreach my $key (sort keys %configfwdfw){ | |
673 | if ($key eq $key1 ){ | |
674 | if ($configfwdfw{$key}[2] eq 'ON'){$configfwdfw{$key}[2]='';} | |
675 | } | |
676 | } | |
677 | &General::writehasharray("$configfwdfw", \%configfwdfw); | |
678 | &rules; | |
2a81ab0d AM |
679 | } |
680 | sub checksource | |
681 | { | |
682 | my ($ip,$subnet); | |
36196d0d | 683 | |
2a81ab0d AM |
684 | #check ip-address if manual |
685 | if ($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} ne ''){ | |
686 | #check if ip with subnet | |
687 | if ($fwdfwsettings{'src_addr'} =~ /^(.*?)\/(.*?)$/) { | |
688 | ($ip,$subnet)=split (/\//,$fwdfwsettings{'src_addr'}); | |
689 | $subnet = &General::iporsubtocidr($subnet); | |
b5269091 | 690 | $fwdfwsettings{'isip'}='on'; |
2a81ab0d AM |
691 | } |
692 | #check if only ip | |
693 | if($fwdfwsettings{'src_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ | |
694 | $ip=$fwdfwsettings{'src_addr'}; | |
695 | $subnet = '32'; | |
b5269091 | 696 | $fwdfwsettings{'isip'}='on'; |
2a81ab0d | 697 | } |
36196d0d | 698 | |
b5269091 AM |
699 | if ($fwdfwsettings{'isip'} ne 'on'){ |
700 | if (&General::validmac($fwdfwsettings{'src_addr'})){$fwdfwsettings{'ismac'}='on';} | |
701 | } | |
702 | if ($fwdfwsettings{'isip'} eq 'on'){ | |
703 | #check and form valid IP | |
704 | $ip=&General::ip2dec($ip); | |
705 | $ip=&General::dec2ip($ip); | |
706 | #check if net or broadcast | |
707 | my @tmp= split (/\./,$ip); | |
708 | if (($tmp[3] eq "0") || ($tmp[3] eq "255")) | |
709 | { | |
710 | $errormessage=$Lang::tr{'fwhost err hostip'}."<br>"; | |
711 | } | |
712 | $fwdfwsettings{'src_addr'}="$ip/$subnet"; | |
36196d0d | 713 | |
b5269091 AM |
714 | if(!&General::validipandmask($fwdfwsettings{'src_addr'})){ |
715 | $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>"; | |
716 | } | |
717 | } | |
718 | if ($fwdfwsettings{'isip'} ne 'on' && $fwdfwsettings{'ismac'} ne 'on'){ | |
2a81ab0d AM |
719 | $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>"; |
720 | } | |
721 | }elsif($fwdfwsettings{'src_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp1'}} && $fwdfwsettings{'src_addr'} eq ''){ | |
722 | $errormessage.=$Lang::tr{'fwdfw err nosrcip'}; | |
723 | return $errormessage; | |
724 | } | |
62fc8511 | 725 | |
2a81ab0d AM |
726 | #check empty fields |
727 | if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err nosrc'}."<br>";} | |
728 | #check icmp source | |
729 | if ($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ICMP'){ | |
730 | $fwdfwsettings{'SRC_PORT'}=''; | |
731 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
732 | foreach my $key (keys %icmptypes){ | |
733 | if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0] ($icmptypes{$key}[1])"){ | |
734 | $fwdfwsettings{'ICMP_TYPES'}="$icmptypes{$key}[0]"; | |
735 | } | |
736 | } | |
62fc8511 AM |
737 | }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'GRE'){ |
738 | $fwdfwsettings{'SRC_PORT'}=''; | |
739 | $fwdfwsettings{'ICMP_TYPES'}=''; | |
740 | }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'ESP'){ | |
741 | $fwdfwsettings{'SRC_PORT'}=''; | |
742 | $fwdfwsettings{'ICMP_TYPES'}=''; | |
d1f01304 AM |
743 | }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} eq 'AH'){ |
744 | $fwdfwsettings{'SRC_PORT'}=''; | |
745 | $fwdfwsettings{'ICMP_TYPES'}=''; | |
2a81ab0d AM |
746 | }elsif($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'PROT'} ne 'ICMP'){ |
747 | $fwdfwsettings{'ICMP_TYPES'}=''; | |
748 | }else{ | |
749 | $fwdfwsettings{'ICMP_TYPES'}=''; | |
750 | $fwdfwsettings{'SRC_PORT'}=''; | |
751 | $fwdfwsettings{'PROT'}=''; | |
752 | } | |
62fc8511 | 753 | |
8f0b047b AM |
754 | if($fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') && $fwdfwsettings{'SRC_PORT'} ne ''){ |
755 | my @parts=split(",",$fwdfwsettings{'SRC_PORT'}); | |
756 | my @values=(); | |
757 | foreach (@parts){ | |
758 | chomp($_); | |
759 | if ($_ =~ /^(\d+)\:(\d+)$/) { | |
760 | my $check; | |
761 | #change dashes with : | |
762 | $_=~ tr/-/:/; | |
763 | if ($_ eq "*") { | |
764 | push(@values,"1:65535"); | |
765 | $check='on'; | |
766 | } | |
767 | if ($_ =~ /^(\D)\:(\d+)$/) { | |
768 | push(@values,"1:$2"); | |
769 | $check='on'; | |
770 | } | |
771 | if ($_ =~ /^(\d+)\:(\D)$/) { | |
772 | push(@values,"$1:65535"); | |
773 | $check='on' | |
774 | } | |
775 | $errormessage .= &General::validportrange($_, 'destination'); | |
776 | if(!$check){ | |
777 | push (@values,$_); | |
778 | } | |
779 | }else{ | |
780 | if (&General::validport($_)){ | |
781 | push (@values,$_); | |
782 | }else{ | |
783 | ||
784 | } | |
785 | } | |
2a81ab0d | 786 | } |
8f0b047b AM |
787 | $fwdfwsettings{'SRC_PORT'}=join("|",@values); |
788 | return $errormessage; | |
2a81ab0d | 789 | } |
2a81ab0d AM |
790 | } |
791 | sub checktarget | |
792 | { | |
793 | my ($ip,$subnet); | |
62fc8511 | 794 | |
2a81ab0d AM |
795 | if ($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} ne ''){ |
796 | #check if ip with subnet | |
797 | if ($fwdfwsettings{'tgt_addr'} =~ /^(.*?)\/(.*?)$/) { | |
798 | ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'}); | |
799 | $subnet = &General::iporsubtocidr($subnet); | |
800 | } | |
801 | #check if only ip | |
802 | if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ | |
803 | $ip=$fwdfwsettings{'tgt_addr'}; | |
804 | $subnet='32'; | |
805 | } | |
806 | #check and form valid IP | |
807 | $ip=&General::ip2dec($ip); | |
808 | $ip=&General::dec2ip($ip); | |
36196d0d | 809 | |
0918e516 AM |
810 | ##check if net or broadcast |
811 | #my @tmp= split (/\./,$ip); | |
812 | #if ($tmp[3] eq "0" || ($tmp[3] eq "255")) | |
813 | #{ | |
814 | #$errormessage=$Lang::tr{'fwhost err hostip'}."<br>"; | |
815 | #} | |
55674e0d | 816 | $fwdfwsettings{'tgt_addr'}="$ip/$subnet"; |
2a81ab0d AM |
817 | |
818 | if(!&General::validipandmask($fwdfwsettings{'tgt_addr'})){ | |
819 | $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>"; | |
820 | } | |
62fc8511 | 821 | |
2a81ab0d AM |
822 | }elsif($fwdfwsettings{'tgt_addr'} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{'tgt_addr'} eq ''){ |
823 | $errormessage.=$Lang::tr{'fwdfw err notgtip'}; | |
824 | return $errormessage; | |
825 | } | |
62fc8511 | 826 | |
2a81ab0d AM |
827 | #check empty fields |
828 | if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq ''){ $errormessage.=$Lang::tr{'fwdfw err notgt'}."<br>";} | |
62fc8511 | 829 | |
2a81ab0d AM |
830 | #check tgt services |
831 | if ($fwdfwsettings{'USESRV'} eq 'ON'){ | |
832 | if ($fwdfwsettings{'grp3'} eq 'cust_srv'){ | |
833 | $fwdfwsettings{'TGT_PROT'}=''; | |
834 | $fwdfwsettings{'ICMP_TGT'}=''; | |
835 | } | |
836 | if ($fwdfwsettings{'grp3'} eq 'cust_srvgrp'){ | |
837 | $fwdfwsettings{'TGT_PROT'}=''; | |
838 | $fwdfwsettings{'ICMP_TGT'}=''; | |
839 | #check target service | |
840 | if($fwdfwsettings{$fwdfwsettings{'grp3'}} eq ''){ | |
841 | $errormessage.=$Lang::tr{'fwdfw err tgt_grp'}; | |
842 | } | |
843 | } | |
844 | if ($fwdfwsettings{'grp3'} eq 'TGT_PORT'){ | |
bcbf1b8e | 845 | if ($fwdfwsettings{'TGT_PROT'} eq 'TCP' || $fwdfwsettings{'TGT_PROT'} eq 'UDP'){ |
2a81ab0d | 846 | if ($fwdfwsettings{'TGT_PORT'} ne ''){ |
8f0b047b AM |
847 | my @parts=split(",",$fwdfwsettings{'TGT_PORT'}); |
848 | my @values=(); | |
849 | foreach (@parts){ | |
850 | chomp($_); | |
851 | if ($_ =~ /^(\d+)\:(\d+)$/) { | |
852 | my $check; | |
853 | #change dashes with : | |
854 | $_=~ tr/-/:/; | |
855 | if ($_ eq "*") { | |
856 | push(@values,"1:65535"); | |
857 | $check='on'; | |
858 | } | |
859 | if ($_ =~ /^(\D)\:(\d+)$/) { | |
860 | push(@values,"1:$2"); | |
861 | $check='on'; | |
862 | } | |
863 | if ($_ =~ /^(\d+)\:(\D)$/) { | |
864 | push(@values,"$1:65535"); | |
865 | $check='on' | |
866 | } | |
867 | $errormessage .= &General::validportrange($_, 'destination'); | |
868 | if(!$check){ | |
869 | push (@values,$_); | |
870 | } | |
871 | }else{ | |
872 | if (&General::validport($_)){ | |
873 | push (@values,$_); | |
874 | }else{ | |
875 | ||
876 | } | |
877 | } | |
2a81ab0d | 878 | } |
8f0b047b | 879 | $fwdfwsettings{'TGT_PORT'}=join("|",@values); |
2a81ab0d | 880 | } |
62fc8511 | 881 | }elsif ($fwdfwsettings{'TGT_PROT'} eq 'GRE'){ |
d1f01304 | 882 | $fwdfwsettings{$fwdfwsettings{'grp3'}} = ''; |
bcbf1b8e | 883 | $fwdfwsettings{'TGT_PORT'} = ''; |
62fc8511 | 884 | $fwdfwsettings{'ICMP_TGT'} = ''; |
bcbf1b8e | 885 | }elsif($fwdfwsettings{'TGT_PROT'} eq 'ESP'){ |
d1f01304 | 886 | $fwdfwsettings{$fwdfwsettings{'grp3'}} = ''; |
bcbf1b8e | 887 | $fwdfwsettings{'TGT_PORT'} = ''; |
d1f01304 | 888 | $fwdfwsettings{'ICMP_TGT'}=''; |
bcbf1b8e | 889 | }elsif($fwdfwsettings{'TGT_PROT'} eq 'AH'){ |
d1f01304 | 890 | $fwdfwsettings{$fwdfwsettings{'grp3'}} = ''; |
bcbf1b8e | 891 | $fwdfwsettings{'TGT_PORT'} = ''; |
62fc8511 | 892 | $fwdfwsettings{'ICMP_TGT'}=''; |
2a81ab0d | 893 | }elsif ($fwdfwsettings{'TGT_PROT'} eq 'ICMP'){ |
d1f01304 | 894 | $fwdfwsettings{$fwdfwsettings{'grp3'}} = ''; |
bcbf1b8e | 895 | $fwdfwsettings{'TGT_PORT'} = ''; |
2a81ab0d AM |
896 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); |
897 | foreach my $key (keys %icmptypes){ | |
898 | ||
899 | if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwdfwsettings{'ICMP_TGT'}){ | |
2a81ab0d AM |
900 | $fwdfwsettings{'ICMP_TGT'}=$icmptypes{$key}[0]; |
901 | } | |
902 | } | |
903 | } | |
904 | } | |
905 | } | |
62fc8511 | 906 | |
2a81ab0d AM |
907 | #check targetport |
908 | if ($fwdfwsettings{'USESRV'} ne 'ON'){ | |
909 | $fwdfwsettings{'grp3'}=''; | |
910 | $fwdfwsettings{$fwdfwsettings{'grp3'}}=''; | |
911 | $fwdfwsettings{'TGT_PROT'}=''; | |
912 | $fwdfwsettings{'ICMP_TGT'}=''; | |
913 | } | |
2a81ab0d AM |
914 | #check timeframe |
915 | if($fwdfwsettings{'TIME'} eq 'ON'){ | |
916 | if($fwdfwsettings{'TIME_MON'} eq '' && $fwdfwsettings{'TIME_TUE'} eq '' && $fwdfwsettings{'TIME_WED'} eq '' && $fwdfwsettings{'TIME_THU'} eq '' && $fwdfwsettings{'TIME_FRI'} eq '' && $fwdfwsettings{'TIME_SAT'} eq '' && $fwdfwsettings{'TIME_SUN'} eq ''){ | |
917 | $errormessage=$Lang::tr{'fwdfw err time'}; | |
918 | } | |
919 | } | |
2a81ab0d AM |
920 | return $errormessage; |
921 | } | |
922 | sub checkrule | |
923 | { | |
924 | #check valid remark | |
925 | if ($fwdfwsettings{'ruleremark'} ne '' && !&validremark($fwdfwsettings{'ruleremark'})){ | |
926 | $errormessage.=$Lang::tr{'fwdfw err remark'}."<br>"; | |
927 | } | |
928 | #check if source and target identical | |
27f4a6b1 | 929 | if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $fwdfwsettings{$fwdfwsettings{'grp2'}} && $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'ALL'){ |
2a81ab0d AM |
930 | $errormessage.=$Lang::tr{'fwdfw err same'}; |
931 | return $errormessage; | |
932 | } | |
62fc8511 | 933 | |
2a81ab0d AM |
934 | #get source and targetip address if possible |
935 | my ($sip,$scidr,$tip,$tcidr); | |
936 | ($sip,$scidr)=&get_ip("src","grp1"); | |
937 | ($tip,$tcidr)=&get_ip("tgt","grp2"); | |
62fc8511 | 938 | |
2a81ab0d AM |
939 | #check same iprange in source and target |
940 | if ($sip ne '' && $scidr ne '' && $tip ne '' && $tcidr ne ''){ | |
2a81ab0d AM |
941 | my $networkip1=&General::getnetworkip($sip,$scidr); |
942 | my $networkip2=&General::getnetworkip($tip,$tcidr); | |
943 | if ($scidr gt $tcidr){ | |
210ee67b | 944 | if ( &General::IpInSubnet($networkip1,$tip,&General::iporsubtodec($tcidr))){ |
2a81ab0d AM |
945 | $errormessage.=$Lang::tr{'fwdfw err samesub'}; |
946 | } | |
947 | }elsif($scidr eq $tcidr && $scidr eq '32'){ | |
62fc8511 AM |
948 | my ($sbyte1,$sbyte2,$sbyte3,$sbyte4)=split(/\./,$networkip1); |
949 | my ($tbyte1,$tbyte2,$tbyte3,$tbyte4)=split(/\./,$networkip2); | |
2a81ab0d AM |
950 | if ($sbyte1 eq $tbyte1 && $sbyte2 eq $tbyte2 && $sbyte3 eq $tbyte3){ |
951 | $hint=$Lang::tr{'fwdfw hint ip1'}."<br>"; | |
55674e0d | 952 | $hint.=$Lang::tr{'fwdfw hint ip2'}." Source: $networkip1/$scidr Target: $networkip2/$tcidr<br>"; |
2a81ab0d | 953 | } |
2a81ab0d | 954 | }else{ |
6adcf156 | 955 | if ( &General::IpInSubnet($networkip2,$sip,&General::iporsubtodec($scidr)) ){ |
2a81ab0d AM |
956 | $errormessage.=$Lang::tr{'fwdfw err samesub'}; |
957 | } | |
958 | } | |
959 | } | |
62fc8511 | 960 | |
2a81ab0d AM |
961 | #check source and destination protocol if manual |
962 | if( $fwdfwsettings{'USE_SRC_PORT'} eq 'ON' && $fwdfwsettings{'USESRV'} eq 'ON'){ | |
210ee67b | 963 | if($fwdfwsettings{'PROT'} ne $fwdfwsettings{'TGT_PROT'} && $fwdfwsettings{'grp3'} eq 'TGT_PORT'){ |
2a81ab0d AM |
964 | $errormessage.=$Lang::tr{'fwdfw err prot'}; |
965 | } | |
966 | #check source and destination protocol if source manual and dest servicegrp | |
967 | if ($fwdfwsettings{'grp3'} eq 'cust_srv'){ | |
968 | &General::readhasharray("$configsrv", \%customservice); | |
969 | foreach my $key (sort keys %customservice){ | |
970 | if($customservice{$key}[0] eq $fwdfwsettings{$fwdfwsettings{'grp3'}}){ | |
971 | if ($customservice{$key}[2] ne $fwdfwsettings{'PROT'}){ | |
972 | $errormessage.=$Lang::tr{'fwdfw err prot'}; | |
973 | last; | |
974 | } | |
975 | } | |
976 | } | |
977 | } | |
978 | } | |
2a81ab0d AM |
979 | } |
980 | sub get_ip | |
981 | { | |
982 | my $val=shift; | |
983 | my $grp =shift; | |
984 | my $a; | |
985 | my $b; | |
986 | &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); | |
987 | if ($fwdfwsettings{$grp} ne $Lang::tr{'fwhost any'}){ | |
988 | if ($fwdfwsettings{$grp} eq $val.'_addr'){ | |
989 | ($a,$b) = split (/\//, $fwdfwsettings{$fwdfwsettings{$grp}}); | |
990 | }elsif($fwdfwsettings{$grp} eq 'std_net_'.$val){ | |
991 | if ($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Gr/i){ | |
992 | $a=$netsettings{'GREEN_NETADDRESS'}; | |
993 | $b=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'}); | |
994 | }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Ora/i){ | |
995 | $a=$netsettings{'ORANGE_NETADDRESS'}; | |
996 | $b=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'}); | |
997 | }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /Bl/i){ | |
998 | $a=$netsettings{'BLUE_NETADDRESS'}; | |
999 | $b=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'}); | |
1000 | }elsif($fwdfwsettings{$fwdfwsettings{$grp}} =~ /OpenVPN/i){ | |
1001 | &General::readhash("$configovpn",\%ovpnsettings); | |
1002 | ($a,$b) = split (/\//, $ovpnsettings{'DOVPN_SUBNET'}); | |
1003 | $b=&General::iporsubtocidr($b); | |
1004 | } | |
1005 | }elsif($fwdfwsettings{$grp} eq 'cust_net_'.$val){ | |
1006 | &General::readhasharray("$confignet", \%customnetwork); | |
1007 | foreach my $key (keys %customnetwork){ | |
1008 | if($customnetwork{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){ | |
1009 | $a=$customnetwork{$key}[1]; | |
1010 | $b=&General::iporsubtocidr($customnetwork{$key}[2]); | |
1011 | } | |
1012 | } | |
1013 | }elsif($fwdfwsettings{$grp} eq 'cust_host_'.$val){ | |
1014 | &General::readhasharray("$confighost", \%customhost); | |
1015 | foreach my $key (keys %customhost){ | |
1016 | if($customhost{$key}[0] eq $fwdfwsettings{$fwdfwsettings{$grp}}){ | |
1017 | if ($customhost{$key}[1] eq 'ip'){ | |
1018 | ($a,$b)=split (/\//,$customhost{$key}[2]); | |
1019 | $b=&General::iporsubtocidr($b); | |
1020 | }else{ | |
1021 | if ($grp eq 'grp2'){ | |
1022 | $errormessage=$Lang::tr{'fwdfw err tgt_mac'}; | |
1023 | } | |
1024 | } | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | } | |
2a81ab0d AM |
1029 | return $a,$b; |
1030 | } | |
1031 | sub newrule | |
1032 | { | |
1033 | &error; | |
1034 | &General::setup_default_networks(\%defaultNetworks); | |
1035 | #read all configfiles | |
1036 | &General::readhasharray("$configccdnet", \%ccdnet); | |
1037 | &General::readhasharray("$confignet", \%customnetwork); | |
1038 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1039 | &General::readhasharray("$confighost", \%customhost); | |
1040 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1041 | &General::readhasharray("$configgrp", \%customgrp); | |
1042 | &General::readhasharray("$configipsec", \%ipsecconf); | |
1043 | &General::get_aliases(\%aliases); | |
2a81ab0d AM |
1044 | my %checked=(); |
1045 | my $helper; | |
2da264ec | 1046 | my $sum=0; |
2a81ab0d AM |
1047 | if($fwdfwsettings{'config'} eq ''){$fwdfwsettings{'config'}=$configfwdfw;} |
1048 | my $config=$fwdfwsettings{'config'}; | |
1049 | my %hash=(); | |
2a81ab0d AM |
1050 | $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED'; |
1051 | $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED'; | |
1052 | $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED'; | |
1053 | $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED'; | |
1054 | $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED'; | |
1055 | $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED'; | |
1056 | $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED'; | |
1057 | $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED'; | |
1058 | $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED'; | |
1059 | $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED'; | |
1060 | $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED'; | |
1061 | $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED'; | |
1062 | $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED'; | |
1063 | $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED'; | |
1064 | $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED'; | |
1065 | $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected'; | |
1066 | $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected'; | |
1067 | $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected'; | |
2a81ab0d AM |
1068 | #check if update and get values |
1069 | if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on' && !$errormessage){ | |
1070 | &General::readhasharray("$config", \%hash); | |
1071 | foreach my $key (sort keys %hash){ | |
2da264ec | 1072 | $sum++; |
2a81ab0d | 1073 | if ($key eq $fwdfwsettings{'key'}){ |
70d38e50 | 1074 | $fwdfwsettings{'oldrulenumber'} = $fwdfwsettings{'key'}; |
2a81ab0d AM |
1075 | $fwdfwsettings{'RULE_ACTION'} = $hash{$key}[0]; |
1076 | $fwdfwsettings{'ACTIVE'} = $hash{$key}[2]; | |
1077 | $fwdfwsettings{'grp1'} = $hash{$key}[3]; | |
1078 | $fwdfwsettings{$fwdfwsettings{'grp1'}} = $hash{$key}[4]; | |
1079 | $fwdfwsettings{'grp2'} = $hash{$key}[5]; | |
1080 | $fwdfwsettings{$fwdfwsettings{'grp2'}} = $hash{$key}[6]; | |
1081 | $fwdfwsettings{'USE_SRC_PORT'} = $hash{$key}[7]; | |
1082 | $fwdfwsettings{'PROT'} = $hash{$key}[8]; | |
1083 | $fwdfwsettings{'ICMP_TYPES'} = $hash{$key}[9]; | |
1084 | $fwdfwsettings{'SRC_PORT'} = $hash{$key}[10]; | |
1085 | $fwdfwsettings{'USESRV'} = $hash{$key}[11]; | |
1086 | $fwdfwsettings{'TGT_PROT'} = $hash{$key}[12]; | |
1087 | $fwdfwsettings{'ICMP_TGT'} = $hash{$key}[13]; | |
1088 | $fwdfwsettings{'grp3'} = $hash{$key}[14]; | |
1089 | $fwdfwsettings{$fwdfwsettings{'grp3'}} = $hash{$key}[15]; | |
1090 | $fwdfwsettings{'ruleremark'} = $hash{$key}[16]; | |
1091 | $fwdfwsettings{'LOG'} = $hash{$key}[17]; | |
1092 | $fwdfwsettings{'TIME'} = $hash{$key}[18]; | |
1093 | $fwdfwsettings{'TIME_MON'} = $hash{$key}[19]; | |
1094 | $fwdfwsettings{'TIME_TUE'} = $hash{$key}[20]; | |
1095 | $fwdfwsettings{'TIME_WED'} = $hash{$key}[21]; | |
1096 | $fwdfwsettings{'TIME_THU'} = $hash{$key}[22]; | |
1097 | $fwdfwsettings{'TIME_FRI'} = $hash{$key}[23]; | |
1098 | $fwdfwsettings{'TIME_SAT'} = $hash{$key}[24]; | |
1099 | $fwdfwsettings{'TIME_SUN'} = $hash{$key}[25]; | |
1100 | $fwdfwsettings{'TIME_FROM'} = $hash{$key}[26]; | |
1101 | $fwdfwsettings{'TIME_TO'} = $hash{$key}[27]; | |
2a81ab0d AM |
1102 | $checked{'grp1'}{$fwdfwsettings{'grp1'}} = 'CHECKED'; |
1103 | $checked{'grp2'}{$fwdfwsettings{'grp2'}} = 'CHECKED'; | |
1104 | $checked{'grp3'}{$fwdfwsettings{'grp3'}} = 'CHECKED'; | |
1105 | $checked{'USE_SRC_PORT'}{$fwdfwsettings{'USE_SRC_PORT'}} = 'CHECKED'; | |
1106 | $checked{'USESRV'}{$fwdfwsettings{'USESRV'}} = 'CHECKED'; | |
1107 | $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED'; | |
1108 | $checked{'LOG'}{$fwdfwsettings{'LOG'}} = 'CHECKED'; | |
1109 | $checked{'TIME'}{$fwdfwsettings{'TIME'}} = 'CHECKED'; | |
1110 | $checked{'TIME_MON'}{$fwdfwsettings{'TIME_MON'}} = 'CHECKED'; | |
1111 | $checked{'TIME_TUE'}{$fwdfwsettings{'TIME_TUE'}} = 'CHECKED'; | |
1112 | $checked{'TIME_WED'}{$fwdfwsettings{'TIME_WED'}} = 'CHECKED'; | |
1113 | $checked{'TIME_THU'}{$fwdfwsettings{'TIME_THU'}} = 'CHECKED'; | |
1114 | $checked{'TIME_FRI'}{$fwdfwsettings{'TIME_FRI'}} = 'CHECKED'; | |
1115 | $checked{'TIME_SAT'}{$fwdfwsettings{'TIME_SAT'}} = 'CHECKED'; | |
1116 | $checked{'TIME_SUN'}{$fwdfwsettings{'TIME_SUN'}} = 'CHECKED'; | |
1117 | $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} = 'selected'; | |
1118 | $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} = 'selected'; | |
1119 | $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} ='selected'; | |
1120 | } | |
1121 | } | |
1122 | $fwdfwsettings{'oldgrp1a'}=$fwdfwsettings{'grp1'}; | |
1123 | $fwdfwsettings{'oldgrp1b'}=$fwdfwsettings{$fwdfwsettings{'grp1'}}; | |
1124 | $fwdfwsettings{'oldgrp2a'}=$fwdfwsettings{'grp2'}; | |
1125 | $fwdfwsettings{'oldgrp2b'}=$fwdfwsettings{$fwdfwsettings{'grp2'}}; | |
1126 | $fwdfwsettings{'oldgrp3a'}=$fwdfwsettings{'grp3'}; | |
1127 | $fwdfwsettings{'oldgrp3b'}=$fwdfwsettings{$fwdfwsettings{'grp3'}}; | |
1128 | $fwdfwsettings{'oldusesrv'}=$fwdfwsettings{'USESRV'}; | |
02da9f7b | 1129 | $fwdfwsettings{'oldruleremark'}=$fwdfwsettings{'ruleremark'}; |
2a81ab0d AM |
1130 | }else{ |
1131 | $fwdfwsettings{'ACTIVE'}='ON'; | |
1132 | $checked{'ACTIVE'}{$fwdfwsettings{'ACTIVE'}} = 'CHECKED'; | |
1133 | } | |
62fc8511 | 1134 | |
2a81ab0d | 1135 | &Header::openbox('100%', 'left', $Lang::tr{'fwdfw addrule'}); |
62fc8511 | 1136 | |
2a81ab0d AM |
1137 | print <<END; |
1138 | <form method="post"> | |
1139 | <table border='0'> | |
1140 | <tr><td nowrap>$Lang::tr{'fwdfw rule action'}</td><td><select name='RULE_ACTION'> | |
1141 | END | |
1142 | foreach ("ACCEPT","DROP","REJECT") | |
1143 | { | |
cf576a12 AM |
1144 | if($fwdfwsettings{'updatefwrule'} eq 'on'){ |
1145 | print"<option "; | |
1146 | print "selected='selected'" if ($fwdfwsettings{'RULE_ACTION'} eq $_); | |
1147 | print">$_</option>"; | |
2a81ab0d | 1148 | }else{ |
cf576a12 AM |
1149 | if($fwdfwsettings{'POLICY'} eq 'MODE2'){ |
1150 | $fwdfwsettings{'RULE_ACTION'} = 'DROP'; | |
1151 | } | |
1152 | ||
1153 | if ($_ eq $fwdfwsettings{'RULE_ACTION'}) | |
1154 | { | |
1155 | print"<option selected>$_</option>"; | |
1156 | }else{ | |
1157 | print"<option>$_</option>"; | |
1158 | } | |
2a81ab0d AM |
1159 | } |
1160 | } | |
1161 | print"</select></td></tr></table><hr>"; | |
1162 | ||
2a81ab0d AM |
1163 | &Header::closebox(); |
1164 | &Header::openbox('100%', 'left', $Lang::tr{'fwdfw source'}); | |
2a81ab0d AM |
1165 | #------SOURCE------------------------------------------------------- |
1166 | print<<END; | |
1167 | <table width='100%' border='0'> | |
1168 | <tr><td width='1%'><input type='radio' name='grp1' value='src_addr' checked></td><td colspan='5'>$Lang::tr{'fwdfw sourceip'}<input type='TEXT' name='src_addr' value='$fwdfwsettings{'src_addr'}' ></td></tr> | |
1169 | <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr> | |
1170 | <tr><td width='1%'><input type='radio' name='grp1' value='std_net_src' $checked{'grp1'}{'std_net_src'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_src' style='min-width:185px;'> | |
2a81ab0d AM |
1171 | END |
1172 | foreach my $network (sort keys %defaultNetworks) | |
1173 | { | |
1174 | next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP"); | |
62fc8511 | 1175 | next if($defaultNetworks{$network}{'NAME'} eq "RED"); |
2a81ab0d AM |
1176 | print "<option value='$defaultNetworks{$network}{'NAME'}'"; |
1177 | print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $defaultNetworks{$network}{'NAME'}); | |
1178 | print ">$network</option>"; | |
1179 | } | |
1180 | print<<END; | |
1181 | </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_net_src' $checked{'grp1'}{'ovpn_net_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_src' style='min-width:185px;'> | |
1182 | END | |
1183 | &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp1'}}); | |
1184 | print<<END; | |
1185 | </select></td></tr> | |
1186 | <tr><td><input type='radio' name='grp1' value='cust_net_src' $checked{'grp1'}{'cust_net_src'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_src' style='min-width:185px;'> | |
1187 | END | |
1188 | &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp1'}}); | |
1189 | print<<END; | |
1190 | </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_host_src' $checked{'grp1'}{'ovpn_host_src'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_src' style='min-width:185px;'> | |
1191 | END | |
1192 | foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) | |
1193 | { | |
1194 | if ($ccdhost{$key}[33] ne ''){ | |
1195 | ||
1196 | print "<option value='$ccdhost{$key}[1]'"; | |
1197 | print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]); | |
1198 | print ">$ccdhost{$key}[1]</option>"; | |
1199 | } | |
1200 | } | |
1201 | print<<END; | |
1202 | </select></td></tr> | |
1203 | <tr><td valign='top'><input type='radio' name='grp1' value='cust_host_src' $checked{'grp1'}{'cust_host_src'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_src' style='min-width:185px;'> | |
1204 | END | |
1205 | &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp1'}}); | |
1206 | print<<END; | |
1207 | </select></td><td width='1%'><input type='radio' name='grp1' value='ovpn_n2n_src' $checked{'grp1'}{'ovpn_n2n_src'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_src' style='min-width:185px;'> | |
1208 | END | |
1209 | foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) { | |
1210 | if($ccdhost{$key}[3] eq 'net'){ | |
1211 | print"<option "; | |
1212 | print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ccdhost{$key}[1]); | |
1213 | print ">$ccdhost{$key}[1]</option>"; | |
1214 | } | |
1215 | } | |
1216 | print<<END; | |
1217 | </select></td></tr> | |
62fc8511 | 1218 | |
2a81ab0d AM |
1219 | <tr><td valign='top'><input type='radio' name='grp1' value='cust_grp_src' $checked{'grp1'}{'cust_grp_src'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_src' style='min-width:185px;'> |
1220 | END | |
1221 | foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) { | |
1222 | if($helper ne $customgrp{$key}[0]){ | |
1223 | print"<option "; | |
1224 | print "selected='selected' " if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $customgrp{$key}[0]); | |
1225 | print ">$customgrp{$key}[0]</option>"; | |
2a81ab0d AM |
1226 | } |
1227 | $helper=$customgrp{$key}[0]; | |
1228 | } | |
1229 | print<<END; | |
1230 | </select></td> | |
1231 | <td valign='top'><input type='radio' name='grp1' value='ipsec_net_src' $checked{'grp1'}{'ipsec_net_src'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_src' style='min-width:185px;'> | |
1232 | END | |
1233 | foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) { | |
1234 | if ($ipsecconf{$key}[3] eq 'net'){ | |
1235 | print "<option "; | |
1236 | print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]); | |
1237 | print ">$ipsecconf{$key}[1]</option>"; | |
1238 | } | |
1239 | } | |
1240 | #sourceport | |
1241 | print<<END; | |
1242 | </select></td></tr> | |
1243 | END | |
62fc8511 | 1244 | |
2a81ab0d AM |
1245 | # <td valign='top'><input type='radio' name='grp1' value='ipsec_host_src' $checked{'grp1'}{'ipsec_host_src'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_src' style='min-width:185px;'> |
1246 | #END | |
1247 | # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) { | |
1248 | # if ($ipsecconf{$key}[3] eq 'host'){ | |
1249 | # print "<option "; | |
1250 | # print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp1'}} eq $ipsecconf{$key}[1]); | |
1251 | # print ">$ipsecconf{$key}[1]</option>"; | |
1252 | # } | |
1253 | # } | |
1254 | print<<END; | |
2a81ab0d | 1255 | <tr><td colspan='8'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr></table> |
2a81ab0d AM |
1256 | <table width='100%' border='0'> |
1257 | <tr><td width='1%'><input type='checkbox' name='USE_SRC_PORT' value='ON' $checked{'USE_SRC_PORT'}{'ON'}></td><td width='51%' colspan='3'>$Lang::tr{'fwdfw use srcport'}</td> | |
1258 | <td width='15%' nowrap='nowrap'>$Lang::tr{'fwdfw man port'}</td><td><select name='PROT'> | |
1259 | END | |
d1f01304 | 1260 | foreach ("TCP","UDP","GRE","ESP","AH","ICMP") |
2a81ab0d AM |
1261 | { |
1262 | if ($_ eq $fwdfwsettings{'PROT'}) | |
1263 | { | |
1264 | print"<option selected>$_</option>"; | |
1265 | }else{ | |
1266 | print"<option>$_</option>"; | |
1267 | } | |
1268 | } | |
8f0b047b | 1269 | $fwdfwsettings{'SRC_PORT'}=~ s/\|/,/g; |
2a81ab0d | 1270 | print<<END; |
8f0b047b | 1271 | </select></td><td align='right'><input type='text' name='SRC_PORT' value='$fwdfwsettings{'SRC_PORT'}' maxlength='20' size='18' ></td></tr> |
2a81ab0d AM |
1272 | <tr><td></td><td></td><td></td><td></td><td nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TYPES'> |
1273 | END | |
1274 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
1275 | print"<option>All ICMP-Types</option>"; | |
1276 | foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) } keys %icmptypes){ | |
1277 | if($fwdfwsettings{'ICMP_TYPES'} eq "$icmptypes{$key}[0]"){ | |
1278 | print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1279 | }else{ | |
1280 | print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1281 | } | |
1282 | } | |
1283 | print<<END; | |
1284 | </select></td></tr></table><hr> | |
1285 | END | |
1286 | &Header::closebox(); | |
1287 | ||
1288 | #---TARGET------------------------------------------------------ | |
1289 | &Header::openbox('100%', 'left', $Lang::tr{'fwdfw target'}); | |
1290 | print<<END; | |
1291 | <table width='100%' border='0'> | |
1292 | <tr><td width='1%'><input type='radio' name='grp2' value='tgt_addr' checked></td><td colspan='2'>$Lang::tr{'fwdfw targetip'}<input type='TEXT' name='tgt_addr' value='$fwdfwsettings{'tgt_addr'}' size='16'><td><input type='radio' name='grp2' value='ipfire' $checked{'grp2'}{'ipfire'}></td><td><b>IPFire ($Lang::tr{'external access'})</b></td><td><select name='ipfire' style='min-width:185px;'> | |
1293 | END | |
1294 | print "<option value='Default IP' $selected{'ipfire'}{'Default IP'}>Default IP</option>"; | |
62fc8511 | 1295 | |
2a81ab0d AM |
1296 | foreach my $alias (sort keys %aliases) |
1297 | { | |
1298 | print "<option value='$alias' $selected{'ipfire'}{$alias}>$alias</option>"; | |
1299 | } | |
62fc8511 | 1300 | |
2a81ab0d AM |
1301 | print<<END; |
1302 | </td></tr> | |
1303 | <tr><td colspan='7'><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; ' /></td></tr> | |
1304 | <tr><td width='1%'><input type='radio' name='grp2' value='std_net_tgt' $checked{'grp2'}{'std_net_tgt'}></td><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost stdnet'}</td><td width='13%'><select name='std_net_tgt' style='min-width:185px;'> | |
2a81ab0d | 1305 | END |
2a81ab0d AM |
1306 | foreach my $network (sort keys %defaultNetworks) |
1307 | { | |
c7043621 | 1308 | next if($defaultNetworks{$network}{'NAME'} eq "IPFire"); |
2a81ab0d AM |
1309 | print "<option value='$defaultNetworks{$network}{'NAME'}'"; |
1310 | print " selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $defaultNetworks{$network}{'NAME'}); | |
1311 | print ">$network</option>"; | |
1312 | } | |
1313 | print<<END; | |
1314 | </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_net_tgt' $checked{'grp2'}{'ovpn_net_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_net_tgt' style='min-width:185px;'> | |
1315 | END | |
1316 | &fillselect(\%ccdnet,$fwdfwsettings{$fwdfwsettings{'grp2'}}); | |
2a81ab0d AM |
1317 | print<<END; |
1318 | </select></td></tr> | |
1319 | <tr><td><input type='radio' name='grp2' value='cust_net_tgt' $checked{'grp2'}{'cust_net_tgt'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='cust_net_tgt' style='min-width:185px;'> | |
1320 | END | |
1321 | &fillselect(\%customnetwork,$fwdfwsettings{$fwdfwsettings{'grp2'}}); | |
1322 | print<<END; | |
1323 | </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_host_tgt' $checked{'grp2'}{'ovpn_host_tgt'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='ovpn_host_tgt' style='min-width:185px;'> | |
1324 | END | |
1325 | foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) | |
1326 | { | |
1327 | if ($ccdhost{$key}[33] ne ''){ | |
1328 | print "<option value='$ccdhost{$key}[1]' "; | |
1329 | print "selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[33]); | |
1330 | print ">$ccdhost{$key}[1]</option>"; | |
1331 | } | |
1332 | } | |
1333 | print<<END; | |
1334 | </select></td></tr> | |
1335 | <tr><td valign='top'><input type='radio' name='grp2' value='cust_host_tgt' $checked{'grp2'}{'cust_host_tgt'}></td><td>$Lang::tr{'fwhost cust addr'}</td><td><select name='cust_host_tgt' style='min-width:185px;'> | |
1336 | END | |
1337 | &fillselect(\%customhost,$fwdfwsettings{$fwdfwsettings{'grp2'}}); | |
1338 | print<<END; | |
1339 | </select></td><td width='1%'><input type='radio' name='grp2' value='ovpn_n2n_tgt' $checked{'grp2'}{'ovpn_n2n_tgt'}></td><td >$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='ovpn_n2n_tgt' style='min-width:185px;'> | |
1340 | END | |
1341 | foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) { | |
1342 | if($ccdhost{$key}[3] eq 'net'){ | |
1343 | print "<option "; | |
1344 | print "selected='selected'" if($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ccdhost{$key}[1]); | |
1345 | print ">$ccdhost{$key}[1]</option>"; | |
1346 | } | |
1347 | } | |
1348 | print<<END; | |
1349 | </select></td></tr> | |
2a81ab0d AM |
1350 | <tr><td valign='top'><input type='radio' name='grp2' value='cust_grp_tgt' $checked{'grp2'}{'cust_grp_tgt'}></td><td >$Lang::tr{'fwhost cust grp'}</td><td><select name='cust_grp_tgt' style='min-width:185px;'> |
1351 | END | |
1352 | $helper=''; | |
1353 | foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } keys %customgrp) { | |
1354 | if($helper ne $customgrp{$key}[0]){ | |
1355 | print"<option "; | |
1356 | print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $customgrp{$key}[0]); | |
1357 | print">$customgrp{$key}[0]</option>"; | |
1358 | } | |
1359 | $helper=$customgrp{$key}[0]; | |
1360 | } | |
1361 | print<<END; | |
1362 | </select></td> | |
1363 | <td valign='top'><input type='radio' name='grp2' value='ipsec_net_tgt' $checked{'grp2'}{'ipsec_net_tgt'}></td><td >$Lang::tr{'fwhost ipsec net'}</td><td><select name='ipsec_net_tgt' style='min-width:185px;'> | |
1364 | END | |
1365 | foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) { | |
1366 | if ($ipsecconf{$key}[3] eq 'net'){ | |
1367 | print"<option "; | |
1368 | print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]); | |
1369 | print">$ipsecconf{$key}[1]</option>"; | |
1370 | } | |
1371 | } | |
1372 | print<<END; | |
1373 | </select></td></tr> | |
1374 | END | |
2a81ab0d AM |
1375 | # <td valign='top'><input type='radio' name='grp2' value='ipsec_host_tgt' $checked{'grp2'}{'ipsec_host_tgt'}></td><td >$Lang::tr{'fwhost ipsec host'}</td><td><select name='ipsec_host_tgt' style='min-width:185px;'> |
1376 | #END | |
1377 | # foreach my $key (sort { uc($ipsecconf{$a}[1]) cmp uc($ipsecconf{$b}[1]) } keys %ipsecconf) { | |
1378 | # if ($ipsecconf{$key}[3] eq 'host'){ | |
1379 | # print"<option "; | |
1380 | # print"selected='Selected'" if ($fwdfwsettings{$fwdfwsettings{'grp2'}} eq $ipsecconf{$key}[1]); | |
1381 | # print">$ipsecconf{$key}[1]</option>"; | |
1382 | # } | |
1383 | # } | |
1384 | print<<END; | |
1385 | </table> | |
1386 | <b>$Lang::tr{'fwhost attention'}:</b><br> | |
1387 | $Lang::tr{'fwhost macwarn'}<br><hr style='border:dotted #BFBFBF; border-width:1px 0 0 0 ; '></hr><br> | |
62fc8511 | 1388 | |
2a81ab0d AM |
1389 | <table width='100%' border='0'> |
1390 | <tr><td width='1%'><input type='checkbox' name='USESRV' value='ON' $checked{'USESRV'}{'ON'} ></td><td width='48%'>$Lang::tr{'fwdfw use srv'}</td><td width='1%'><input type='radio' name='grp3' value='cust_srv' checked></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td width='1%' colspan='2'><select name='cust_srv'style='min-width:230px;' > | |
1391 | END | |
1392 | &General::readhasharray("$configsrv", \%customservice); | |
62fc8511 | 1393 | foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){ |
2a81ab0d AM |
1394 | print"<option "; |
1395 | print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservice{$key}[0]); | |
1396 | print"value='$customservice{$key}[0]'>$customservice{$key}[0]</option>"; | |
1397 | } | |
1398 | print<<END; | |
1399 | </select></td></tr> | |
1400 | <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='cust_srvgrp' $checked{'grp3'}{'cust_srvgrp'}></td><td nowrap='nowrap'>$Lang::tr{'fwhost cust srvgrp'}:</td><td colspan='2'><select name='cust_srvgrp'style='min-width:230px;' > | |
1401 | END | |
1402 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
1403 | my $helper; | |
62fc8511 | 1404 | foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){ |
2a81ab0d AM |
1405 | if ($helper ne $customservicegrp{$key}[0]){ |
1406 | print"<option "; | |
1407 | print"selected='selected'" if ($fwdfwsettings{$fwdfwsettings{'grp3'}} eq $customservicegrp{$key}[0]); | |
1408 | print">$customservicegrp{$key}[0]</option>"; | |
1409 | } | |
1410 | $helper=$customservicegrp{$key}[0]; | |
1411 | } | |
1412 | print<<END; | |
1413 | </select></td></tr> | |
1414 | <tr><td colspan='2'></td><td><input type='radio' name='grp3' value='TGT_PORT' $checked{'grp3'}{'TGT_PORT'}></td><td>$Lang::tr{'fwdfw man port'}</td><td><select name='TGT_PROT'> | |
1415 | END | |
d1f01304 | 1416 | foreach ("TCP","UDP","GRE","ESP","AH","ICMP") |
2a81ab0d AM |
1417 | { |
1418 | if ($_ eq $fwdfwsettings{'TGT_PROT'}) | |
1419 | { | |
1420 | print"<option selected>$_</option>"; | |
1421 | }else{ | |
1422 | print"<option>$_</option>"; | |
1423 | } | |
1424 | } | |
8f0b047b | 1425 | $fwdfwsettings{'TGT_PORT'} =~ s/\|/,/g; |
2a81ab0d | 1426 | print<<END; |
8f0b047b | 1427 | </select></td><td align='right'><input type='text' name='TGT_PORT' value='$fwdfwsettings{'TGT_PORT'}' maxlength='20' size='18' ></td></tr> |
2a81ab0d AM |
1428 | <tr><td colspan='2'></td><td></td><td>$Lang::tr{'fwhost icmptype'}</td><td colspan='2'><select name='ICMP_TGT'> |
1429 | END | |
1430 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
1431 | print"<option>All ICMP-Types</option>"; | |
1432 | foreach my $key (sort { uc($icmptypes{$a}[0]) cmp uc($icmptypes{$b}[0]) }keys %icmptypes){ | |
1433 | if($fwdfwsettings{'ICMP_TGT'} eq "$icmptypes{$key}[0]"){ | |
1434 | print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1435 | }else{ | |
1436 | print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1437 | } | |
1438 | } | |
1439 | print<<END; | |
1440 | </select></td></tr> | |
1441 | </table><hr><br><br> | |
62fc8511 | 1442 | |
2a81ab0d AM |
1443 | END |
1444 | #---Activate/logging/remark------------------------------------- | |
1445 | &Header::openbox('100%', 'left', $Lang::tr{'fwdfw additional'}); | |
1446 | print<<END; | |
1447 | <table width='100%' border='0'> | |
2da264ec AM |
1448 | <tr><td width='12%'>$Lang::tr{'remark'}:</td><td align='left'><input type='text' name='ruleremark' size='40' maxlength='255' value='$fwdfwsettings{'ruleremark'}'></td></tr> |
1449 | END | |
1450 | if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} eq 'on'){ | |
1451 | print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><select name='rulepos' >"; | |
1452 | for (my $count =1; $count <= $sum; $count++){ | |
1453 | print"<option value='$count' "; | |
1454 | print"selected='selected'" if($fwdfwsettings{'oldrulenumber'} eq $count); | |
1455 | print">$count</option>"; | |
1456 | } | |
1457 | print"</select></td></tr>"; | |
70d38e50 AM |
1458 | }else{ |
1459 | print "<tr><td width='12%'>$Lang::tr{'fwdfw rulepos'}:</td><td><input type='text' name='rulepos' size='2'></td></tr>"; | |
2da264ec AM |
1460 | } |
1461 | ||
1462 | print<<END; | |
1463 | </table><table width='100%'> | |
2a81ab0d AM |
1464 | <tr><td width='1%'><input type='checkbox' name='ACTIVE' value='ON' $checked{'ACTIVE'}{'ON'}></td><td>$Lang::tr{'fwdfw rule activate'}</td></tr> |
1465 | <tr><td width='1%'><input type='checkbox' name='LOG' value='ON' $checked{'LOG'}{'ON'} ></td><td>$Lang::tr{'fwdfw log rule'}</td></tr> | |
1466 | </table><hr><br> | |
1467 | END | |
1468 | &Header::closebox(); | |
1469 | #---ADD TIMEFRAME----------------------------------------------- | |
1470 | &Header::openbox('100%', 'left', $Lang::tr{'fwdfw timeframe'}); | |
1471 | print<<END; | |
1472 | <table width='70%' border='0'> | |
1473 | <tr><td width='1%'><input type='checkbox' name='TIME' value='ON' $checked{'TIME'}{'ON'}></td><td colspan='4'>$Lang::tr{'fwdfw timeframe'}</td></tr> | |
1474 | <tr><td colspan='7'> </td></tr> | |
1475 | <tr> | |
1476 | <td align='left'>$Lang::tr{'time'}:</td> | |
1477 | <td width='30%' align='left'>$Lang::tr{'advproxy monday'} $Lang::tr{'advproxy tuesday'} $Lang::tr{'advproxy wednesday'} $Lang::tr{'advproxy thursday'} $Lang::tr{'advproxy friday'} $Lang::tr{'advproxy saturday'} $Lang::tr{'advproxy sunday'}</td> | |
2a81ab0d AM |
1478 | <td width='15%' align='left'>$Lang::tr{'advproxy from'}</td> |
1479 | <td width='15%' align='left'>$Lang::tr{'advproxy to'}</td> | |
1480 | </tr> | |
1481 | <tr> | |
1482 | <td align='right'></td> | |
1483 | <td width='30%' align='left'> | |
1484 | <input type='checkbox' name='TIME_MON' value='on' $checked{'TIME_MON'}{'on'} /> | |
1485 | <input type='checkbox' name='TIME_TUE' value='on' $checked{'TIME_TUE'}{'on'} /> | |
1486 | <input type='checkbox' name='TIME_WED' value='on' $checked{'TIME_WED'}{'on'} /> | |
1487 | <input type='checkbox' name='TIME_THU' value='on' $checked{'TIME_THU'}{'on'} /> | |
1488 | <input type='checkbox' name='TIME_FRI' value='on' $checked{'TIME_FRI'}{'on'} /> | |
1489 | <input type='checkbox' name='TIME_SAT' value='on' $checked{'TIME_SAT'}{'on'} /> | |
27f4a6b1 | 1490 | <input type='checkbox' name='TIME_SUN' value='on' $checked{'TIME_SUN'}{'on'} /> |
2a81ab0d | 1491 | </td> |
2a81ab0d AM |
1492 | <td><select name='TIME_FROM'> |
1493 | END | |
1494 | for (my $i=0;$i<=23;$i++) { | |
1495 | $i = sprintf("%02s",$i); | |
1496 | for (my $j=0;$j<=45;$j+=15) { | |
1497 | $j = sprintf("%02s",$j); | |
1498 | my $time = $i.":".$j; | |
1499 | print "\t\t\t\t\t<option $selected{'TIME_FROM'}{$time}>$i:$j</option>\n"; | |
1500 | } | |
1501 | } | |
1502 | print<<END; | |
1503 | </select></td> | |
1504 | <td><select name='TIME_TO'> | |
1505 | END | |
1506 | for (my $i=0;$i<=23;$i++) { | |
1507 | $i = sprintf("%02s",$i); | |
1508 | for (my $j=0;$j<=45;$j+=15) { | |
1509 | $j = sprintf("%02s",$j); | |
1510 | my $time = $i.":".$j; | |
1511 | print "\t\t\t\t\t<option $selected{'TIME_TO'}{$time}>$i:$j</option>\n"; | |
1512 | } | |
1513 | } | |
62fc8511 | 1514 | print<<END; |
2a81ab0d AM |
1515 | </select></td></tr> |
1516 | </table><hr> | |
1517 | END | |
1518 | &Header::closebox(); | |
1519 | #---ACTION------------------------------------------------------ | |
1520 | if($fwdfwsettings{'updatefwrule'} ne 'on'){ | |
1521 | print<<END; | |
1522 | <table border='0' width='100%'> | |
1523 | <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /> | |
1524 | <input type='hidden' name='config' value='$config' > | |
70d38e50 AM |
1525 | <input type='hidden' name='ACTION' value='saverule' > |
1526 | </form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td> | |
2a81ab0d AM |
1527 | </table></form> |
1528 | END | |
1529 | }else{ | |
1530 | print<<END; | |
1531 | <table border='0' width='100%'> | |
1532 | <tr><td align='right'><input type='submit' value='$Lang::tr{'fwdfw change'}' style='min-width:100px;' /><input type='hidden' name='updatefwrule' value='$fwdfwsettings{'updatefwrule'}'><input type='hidden' name='key' value='$fwdfwsettings{'key'}'> | |
1533 | <input type='hidden' name='oldgrp1a' value='$fwdfwsettings{'oldgrp1a'}' /> | |
1534 | <input type='hidden' name='oldgrp1b' value='$fwdfwsettings{'oldgrp1b'}' /> | |
1535 | <input type='hidden' name='oldgrp2a' value='$fwdfwsettings{'oldgrp2a'}' /> | |
1536 | <input type='hidden' name='oldgrp2b' value='$fwdfwsettings{'oldgrp2b'}' /> | |
1537 | <input type='hidden' name='oldgrp3a' value='$fwdfwsettings{'oldgrp3a'}' /> | |
1538 | <input type='hidden' name='oldgrp3b' value='$fwdfwsettings{'oldgrp3b'}' /> | |
1539 | <input type='hidden' name='oldusesrv' value='$fwdfwsettings{'oldusesrv'}' /> | |
2da264ec AM |
1540 | <input type='hidden' name='oldrulenumber' value='$fwdfwsettings{'oldrulenumber'}' /> |
1541 | <input type='hidden' name='rulenumber' value='$fwdfwsettings{'rulepos'}' /> | |
8f0b047b | 1542 | <input type='hidden' name='oldruleremark' value='$fwdfwsettings{'oldruleremark'}' /> |
2a81ab0d | 1543 | <input type='hidden' name='ACTION' value='saverule' ></form><form method='post' style='display:inline'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'><input type='hidden' name='ACTION' value'reset'></td></td> |
2a81ab0d AM |
1544 | </table></form> |
1545 | END | |
1546 | } | |
1547 | &Header::closebox(); | |
1548 | } | |
1549 | sub saverule | |
1550 | { | |
2a81ab0d AM |
1551 | my $hash=shift; |
1552 | my $config=shift; | |
1553 | &General::readhasharray("$config", $hash); | |
1554 | if (!$errormessage){ | |
d7127db8 AM |
1555 | #check if we change an forward rule to an external access |
1556 | if( $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'oldgrp2a'} ne 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
1557 | &changerule($configfwdfw); | |
1558 | } | |
1559 | #check if we change an forward rule to an outgoing | |
1560 | if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'oldgrp1b'} ne 'IPFire' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
1561 | &changerule($configfwdfw); | |
1562 | } | |
1563 | #check if we change an external access rule to a forward | |
1564 | if( $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
1565 | &changerule($configinput); | |
1566 | } | |
1567 | #check if we change an external access rule to a outgoing | |
1568 | if( $fwdfwsettings{$fwdfwsettings{'grp1'}} eq 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' && $fwdfwsettings{'oldgrp2a'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
1569 | &changerule($configinput); | |
1570 | } | |
1571 | #check if we change an outgoing rule to a forward | |
1572 | if( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} ne 'ipfire' &&$fwdfwsettings{'updatefwrule'} eq 'on'){ | |
1573 | &changerule($configoutgoing); | |
1574 | } | |
1575 | #check if we change an outgoing rule to a external access | |
1576 | if( $fwdfwsettings{$fwdfwsettings{'grp1'}} ne 'IPFire' && $fwdfwsettings{'oldgrp1b'} eq 'IPFire' && $fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{'updatefwrule'} eq 'on'){ | |
1577 | &changerule($configoutgoing); | |
1578 | } | |
2da264ec | 1579 | if ($fwdfwsettings{'updatefwrule'} ne 'on'){ |
2a81ab0d AM |
1580 | my $key = &General::findhasharraykey ($hash); |
1581 | $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'}; | |
1582 | $$hash{$key}[1] = $fwdfwsettings{'chain'}; | |
1583 | $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'}; | |
1584 | $$hash{$key}[3] = $fwdfwsettings{'grp1'}; | |
1585 | $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}}; | |
1586 | $$hash{$key}[5] = $fwdfwsettings{'grp2'}; | |
1587 | $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}}; | |
1588 | $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'}; | |
1589 | $$hash{$key}[8] = $fwdfwsettings{'PROT'}; | |
1590 | $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'}; | |
1591 | $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'}; | |
1592 | $$hash{$key}[11] = $fwdfwsettings{'USESRV'}; | |
1593 | $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'}; | |
1594 | $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'}; | |
1595 | $$hash{$key}[14] = $fwdfwsettings{'grp3'}; | |
1596 | $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}}; | |
1597 | $$hash{$key}[16] = $fwdfwsettings{'ruleremark'}; | |
1598 | $$hash{$key}[17] = $fwdfwsettings{'LOG'}; | |
1599 | $$hash{$key}[18] = $fwdfwsettings{'TIME'}; | |
1600 | $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'}; | |
1601 | $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'}; | |
1602 | $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'}; | |
1603 | $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'}; | |
1604 | $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'}; | |
1605 | $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'}; | |
1606 | $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'}; | |
1607 | $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'}; | |
1608 | $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'}; | |
1609 | &General::writehasharray("$config", $hash); | |
1610 | }else{ | |
e44fa079 AM |
1611 | foreach my $key (sort {$a <=> $b} keys %$hash){ |
1612 | if($key eq $fwdfwsettings{'key'}){ | |
1613 | $$hash{$key}[0] = $fwdfwsettings{'RULE_ACTION'}; | |
1614 | $$hash{$key}[1] = $fwdfwsettings{'chain'}; | |
1615 | $$hash{$key}[2] = $fwdfwsettings{'ACTIVE'}; | |
1616 | $$hash{$key}[3] = $fwdfwsettings{'grp1'}; | |
1617 | $$hash{$key}[4] = $fwdfwsettings{$fwdfwsettings{'grp1'}}; | |
1618 | $$hash{$key}[5] = $fwdfwsettings{'grp2'}; | |
1619 | $$hash{$key}[6] = $fwdfwsettings{$fwdfwsettings{'grp2'}}; | |
1620 | $$hash{$key}[7] = $fwdfwsettings{'USE_SRC_PORT'}; | |
1621 | $$hash{$key}[8] = $fwdfwsettings{'PROT'}; | |
1622 | $$hash{$key}[9] = $fwdfwsettings{'ICMP_TYPES'}; | |
1623 | $$hash{$key}[10] = $fwdfwsettings{'SRC_PORT'}; | |
1624 | $$hash{$key}[11] = $fwdfwsettings{'USESRV'}; | |
1625 | $$hash{$key}[12] = $fwdfwsettings{'TGT_PROT'}; | |
1626 | $$hash{$key}[13] = $fwdfwsettings{'ICMP_TGT'}; | |
1627 | $$hash{$key}[14] = $fwdfwsettings{'grp3'}; | |
1628 | $$hash{$key}[15] = $fwdfwsettings{$fwdfwsettings{'grp3'}}; | |
1629 | $$hash{$key}[16] = $fwdfwsettings{'ruleremark'}; | |
1630 | $$hash{$key}[17] = $fwdfwsettings{'LOG'}; | |
1631 | $$hash{$key}[18] = $fwdfwsettings{'TIME'}; | |
1632 | $$hash{$key}[19] = $fwdfwsettings{'TIME_MON'}; | |
1633 | $$hash{$key}[20] = $fwdfwsettings{'TIME_TUE'}; | |
1634 | $$hash{$key}[21] = $fwdfwsettings{'TIME_WED'}; | |
1635 | $$hash{$key}[22] = $fwdfwsettings{'TIME_THU'}; | |
1636 | $$hash{$key}[23] = $fwdfwsettings{'TIME_FRI'}; | |
1637 | $$hash{$key}[24] = $fwdfwsettings{'TIME_SAT'}; | |
1638 | $$hash{$key}[25] = $fwdfwsettings{'TIME_SUN'}; | |
1639 | $$hash{$key}[26] = $fwdfwsettings{'TIME_FROM'}; | |
1640 | $$hash{$key}[27] = $fwdfwsettings{'TIME_TO'}; | |
1641 | last; | |
1642 | } | |
1643 | } | |
1644 | } | |
1645 | &General::writehasharray("$config", $hash); | |
0918e516 | 1646 | if($fwdfwsettings{'oldrulenumber'} > $fwdfwsettings{'rulepos'}){ |
e44fa079 AM |
1647 | my %tmp=(); |
1648 | my $val=$fwdfwsettings{'oldrulenumber'}-$fwdfwsettings{'rulepos'}; | |
1649 | for (my $z=0;$z<$val;$z++){ | |
1650 | foreach my $key (sort {$a <=> $b} keys %$hash){ | |
1651 | if ($key eq $fwdfwsettings{'oldrulenumber'}) { | |
1652 | my $last = $key -1; | |
1653 | if (exists $$hash{$last}){ | |
1654 | #save rule last | |
1655 | foreach my $y (0 .. $#{$$hash{$last}}) { | |
1656 | $tmp{0}[$y] = $$hash{$last}[$y]; | |
1657 | } | |
1658 | #copy active rule to last | |
1659 | foreach my $i (0 .. $#{$$hash{$last}}) { | |
1660 | $$hash{$last}[$i] = $$hash{$key}[$i]; | |
1661 | } | |
1662 | #copy saved rule to actual position | |
1663 | foreach my $x (0 .. $#{$tmp{0}}) { | |
1664 | $$hash{$key}[$x] = $tmp{0}[$x]; | |
2da264ec AM |
1665 | } |
1666 | } | |
1667 | } | |
1668 | } | |
e44fa079 AM |
1669 | $fwdfwsettings{'oldrulenumber'}--; |
1670 | } | |
1671 | &General::writehasharray("$config", $hash); | |
1672 | &rules; | |
0918e516 | 1673 | }elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){ |
e44fa079 AM |
1674 | my %tmp=(); |
1675 | my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'}; | |
1676 | for (my $z=0;$z<$val;$z++){ | |
1677 | foreach my $key (sort {$a <=> $b} keys %$hash){ | |
1678 | if ($key eq $fwdfwsettings{'oldrulenumber'}) { | |
1679 | my $next = $key + 1; | |
1680 | if (exists $$hash{$next}){ | |
1681 | #save rule next | |
1682 | foreach my $y (0 .. $#{$$hash{$next}}) { | |
1683 | $tmp{0}[$y] = $$hash{$next}[$y]; | |
1684 | } | |
1685 | #copy active rule to next | |
1686 | foreach my $i (0 .. $#{$$hash{$next}}) { | |
1687 | $$hash{$next}[$i] = $$hash{$key}[$i]; | |
1688 | } | |
1689 | #copy saved rule to actual position | |
1690 | foreach my $x (0 .. $#{$tmp{0}}) { | |
1691 | $$hash{$key}[$x] = $tmp{0}[$x]; | |
2da264ec AM |
1692 | } |
1693 | } | |
1694 | } | |
2a81ab0d | 1695 | } |
e44fa079 | 1696 | $fwdfwsettings{'oldrulenumber'}++; |
2a81ab0d AM |
1697 | } |
1698 | &General::writehasharray("$config", $hash); | |
e44fa079 | 1699 | &rules; |
2a81ab0d AM |
1700 | } |
1701 | } | |
1702 | } | |
1703 | sub error | |
1704 | { | |
1705 | if ($errormessage) { | |
1706 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
1707 | print "<class name='base'>$errormessage\n"; | |
1708 | print " </class>\n"; | |
1709 | &Header::closebox(); | |
1710 | print"<hr>"; | |
1711 | } | |
1712 | } | |
1713 | sub hint | |
1714 | { | |
1715 | if ($hint) { | |
1716 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'}); | |
1717 | print "<class name='base'>$hint\n"; | |
1718 | print " </class>\n"; | |
1719 | &Header::closebox(); | |
1720 | print"<hr>"; | |
1721 | } | |
1722 | } | |
1723 | sub get_name | |
1724 | { | |
1725 | my $val=shift; | |
1726 | &General::setup_default_networks(\%defaultNetworks); | |
1727 | foreach my $network (sort keys %defaultNetworks) | |
1728 | { | |
1729 | return "$network" if ($val eq $defaultNetworks{$network}{'NAME'}); | |
62fc8511 | 1730 | } |
2a81ab0d AM |
1731 | } |
1732 | sub validremark | |
1733 | { | |
1734 | # Checks a hostname against RFC1035 | |
1735 | my $remark = $_[0]; | |
1736 | ||
1737 | # Each part should be at least two characters in length | |
1738 | # but no more than 63 characters | |
d24a34cb | 1739 | if (length ($remark) < 1 || length ($remark) > 255) { |
2a81ab0d AM |
1740 | return 0;} |
1741 | # Only valid characters are a-z, A-Z, 0-9 and - | |
e3580608 | 1742 | if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) { |
2a81ab0d AM |
1743 | return 0;} |
1744 | # First character can only be a letter or a digit | |
1745 | if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) { | |
1746 | return 0;} | |
1747 | # Last character can only be a letter or a digit | |
e3580608 | 1748 | if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) { |
2a81ab0d AM |
1749 | return 0;} |
1750 | return 1; | |
1751 | } | |
1752 | sub getsrcport | |
1753 | { | |
1754 | my %hash=%{(shift)}; | |
1755 | my $key=shift; | |
93a5f4a5 | 1756 | if($hash{$key}[7] eq 'ON' && $hash{$key}[8] ne '' && $hash{$key}[10]){ |
8f0b047b | 1757 | $hash{$key}[10]=~ s/\|/,/g; |
93a5f4a5 | 1758 | print": $hash{$key}[10]"; |
2a81ab0d | 1759 | }elsif($hash{$key}[7] eq 'ON' && $hash{$key}[8] eq 'ICMP'){ |
93a5f4a5 | 1760 | print": <br>$hash{$key}[9] "; |
2a81ab0d AM |
1761 | } |
1762 | } | |
1763 | sub gettgtport | |
1764 | { | |
1765 | my %hash=%{(shift)}; | |
1766 | my $key=shift; | |
1767 | my $service; | |
1768 | my $prot; | |
2a81ab0d AM |
1769 | if($hash{$key}[11] eq 'ON' && $hash{$key}[12] ne 'ICMP'){ |
1770 | if($hash{$key}[14] eq 'cust_srv'){ | |
1771 | &General::readhasharray("$configsrv", \%customservice); | |
1772 | foreach my $i (sort keys %customservice){ | |
2a81ab0d | 1773 | if($customservice{$i}[0] eq $hash{$key}[15]){ |
2a81ab0d AM |
1774 | $service = $customservice{$i}[0]; |
1775 | } | |
1776 | } | |
1777 | }elsif($hash{$key}[14] eq 'cust_srvgrp'){ | |
2a81ab0d AM |
1778 | $service=$hash{$key}[15]; |
1779 | }elsif($hash{$key}[14] eq 'TGT_PORT'){ | |
8f0b047b | 1780 | $hash{$key}[15]=~ s/\|/,/g; |
2a81ab0d | 1781 | $service=$hash{$key}[15]; |
2a81ab0d | 1782 | } |
99e698d0 AM |
1783 | if($service){ |
1784 | print": $service"; | |
1785 | } | |
2a81ab0d | 1786 | }elsif($hash{$key}[11] eq 'ON' && $hash{$key}[12] eq 'ICMP'){ |
93a5f4a5 | 1787 | print":<br>$hash{$key}[13]"; |
2a81ab0d | 1788 | } |
93a5f4a5 AM |
1789 | } |
1790 | sub get_serviceports | |
1791 | { | |
1792 | my $type=shift; | |
1793 | my $name=shift; | |
1794 | &General::readhasharray("$configsrv", \%customservice); | |
1795 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
1796 | my $protocols; | |
1797 | my $tcp; | |
1798 | my $udp; | |
1799 | if($type eq 'service'){ | |
1800 | foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){ | |
1801 | if ($customservice{$key}[0] eq $name){ | |
1802 | $protocols=$customservice{$key}[2]; | |
1803 | } | |
1804 | } | |
93a5f4a5 AM |
1805 | }elsif($type eq 'group'){ |
1806 | foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){ | |
1807 | if ($customservicegrp{$key}[0] eq $name){ | |
5edf47ff AM |
1808 | foreach my $key1 (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice){ |
1809 | if ($customservice{$key1}[0] eq $customservicegrp{$key}[2]){ | |
1810 | if($customservice{$key1}[2] eq 'TCP'){$tcp='TCP';}else{$udp='UDP';} | |
1811 | } | |
1812 | } | |
93a5f4a5 | 1813 | } |
2a81ab0d | 1814 | } |
2a81ab0d | 1815 | } |
5edf47ff AM |
1816 | if($tcp && $udp){$protocols="TCP,UDP"; |
1817 | }elsif($tcp){$protocols.="TCP"; | |
1818 | }elsif($udp){$protocols.="UDP";} | |
93a5f4a5 | 1819 | return $protocols; |
2a81ab0d AM |
1820 | } |
1821 | sub viewtablerule | |
1822 | { | |
15add1c8 | 1823 | &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); |
2a81ab0d AM |
1824 | &viewtablenew(\%configfwdfw,$configfwdfw,$Lang::tr{'fwdfw rules'},"Forward" ); |
1825 | &viewtablenew(\%configinputfw,$configinput,"",$Lang::tr{'external access'} ); | |
c7043621 | 1826 | &viewtablenew(\%configoutgoingfw,$configoutgoing,"","Outgoing" ); |
2a81ab0d AM |
1827 | } |
1828 | sub viewtablenew | |
1829 | { | |
1830 | my $hash=shift; | |
1831 | my $config=shift; | |
1832 | my $title=shift; | |
1833 | my $title1=shift; | |
7bd9d462 | 1834 | my $go=''; |
15add1c8 | 1835 | &General::get_aliases(\%aliases); |
7bd9d462 | 1836 | &General::readhasharray("$config", $hash); |
5d7faa45 | 1837 | if( ! -z $config){ |
2a81ab0d AM |
1838 | &Header::openbox('100%', 'left',$title); |
1839 | my $count=0; | |
1840 | my ($gif,$log); | |
1841 | my $ruletype; | |
1842 | my $rulecolor; | |
1843 | my $tooltip; | |
1844 | my @tmpsrc=(); | |
1845 | my $coloryellow=''; | |
2a81ab0d | 1846 | print"<b>$title1</b><br>"; |
15add1c8 AM |
1847 | print"<table width='100%' cellspacing='1' rules='none'; padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'>"; |
1848 | print"<tr><td align='center'><b>#</td><td ></td><td align='center'><b>$Lang::tr{'fwdfw source'}</td><td><b>Log</td><td align='center'><b>$Lang::tr{'fwdfw target'}</td><td align='center'><b>$Lang::tr{'protocol'}</b></td><td align='center'><b>$Lang::tr{'remark'}</td><td align='center' colspan='6'><b>$Lang::tr{'fwdfw action'}</td></tr>"; | |
62fc8511 | 1849 | foreach my $key (sort {$a <=> $b} keys %$hash){ |
2a81ab0d AM |
1850 | @tmpsrc=(); |
1851 | #check if vpn hosts/nets have been deleted | |
1852 | if($$hash{$key}[3] =~ /ipsec/i || $$hash{$key}[3] =~ /ovpn/i){ | |
1853 | push (@tmpsrc,$$hash{$key}[4]); | |
1854 | } | |
1855 | if($$hash{$key}[5] =~ /ipsec/i || $$hash{$key}[5] =~ /ovpn/i){ | |
1856 | push (@tmpsrc,$$hash{$key}[6]); | |
1857 | } | |
2a81ab0d AM |
1858 | foreach my $host (@tmpsrc){ |
1859 | if($$hash{$key}[3] eq 'ipsec_net_src' || $$hash{$key}[5] eq 'ipsec_net_tgt'){ | |
62fc8511 | 1860 | if(&fwlib::get_ipsec_net_ip($host,11) eq ''){ |
2a81ab0d AM |
1861 | $coloryellow='on'; |
1862 | &disable_rule($key); | |
1863 | $$hash{$key}[2]=''; | |
2a81ab0d AM |
1864 | } |
1865 | }elsif($$hash{$key}[3] eq 'ovpn_net_src' || $$hash{$key}[5] eq 'ovpn_net_tgt'){ | |
1866 | if(&fwlib::get_ovpn_net_ip($host,1) eq ''){ | |
1867 | $coloryellow='on'; | |
1868 | &disable_rule($key); | |
1869 | $$hash{$key}[2]=''; | |
1870 | } | |
1871 | }elsif($$hash{$key}[3] eq 'ovpn_n2n_src' || $$hash{$key}[5] eq 'ovpn_n2n_tgt'){ | |
1872 | if(&fwlib::get_ovpn_n2n_ip($host,27) eq ''){ | |
1873 | $coloryellow='on'; | |
1874 | &disable_rule($key); | |
1875 | $$hash{$key}[2]=''; | |
1876 | } | |
1877 | }elsif($$hash{$key}[3] eq 'ovpn_host_src' || $$hash{$key}[5] eq 'ovpn_host_tgt'){ | |
1878 | if(&fwlib::get_ovpn_host_ip($host,33) eq ''){ | |
1879 | $coloryellow='on'; | |
1880 | &disable_rule($key); | |
1881 | $$hash{$key}[2]=''; | |
1882 | } | |
1883 | } | |
1884 | $$hash{$key}[3]=''; | |
1885 | $$hash{$key}[5]=''; | |
1886 | } | |
2a81ab0d AM |
1887 | $$hash{'ACTIVE'}=$$hash{$key}[2]; |
1888 | $count++; | |
2a81ab0d AM |
1889 | if($coloryellow eq 'on'){ |
1890 | print"<tr bgcolor='$color{'color14'}' >"; | |
1891 | $coloryellow=''; | |
1892 | }elsif($coloryellow eq ''){ | |
1893 | if ($count % 2){ | |
15add1c8 | 1894 | $color="$color{'color22'}"; |
2a81ab0d AM |
1895 | } |
1896 | else{ | |
15add1c8 | 1897 | $color="$color{'color20'}"; |
2a81ab0d AM |
1898 | } |
1899 | } | |
15add1c8 | 1900 | print"<tr bgcolor='$color' >"; |
2a81ab0d | 1901 | print<<END; |
15add1c8 | 1902 | <td align='right' width='15'>$key</td> |
2a81ab0d AM |
1903 | END |
1904 | if ($$hash{$key}[0] eq 'ACCEPT'){ | |
1905 | $ruletype='A'; | |
1906 | $tooltip='ACCEPT'; | |
1907 | $rulecolor=$color{'color17'}; | |
1908 | }elsif($$hash{$key}[0] eq 'DROP'){ | |
1909 | $ruletype='D'; | |
1910 | $tooltip='DROP'; | |
1911 | $rulecolor=$color{'color25'}; | |
1912 | }elsif($$hash{$key}[0] eq 'REJECT'){ | |
1913 | $ruletype='R'; | |
1914 | $tooltip='REJECT'; | |
1915 | $rulecolor=$color{'color16'}; | |
1916 | } | |
15add1c8 AM |
1917 | print"<td bgcolor='$rulecolor' align='center' width='20'><span title='$tooltip'><b>$ruletype</b></span></td>"; |
1918 | &getcolor($$hash{$key}[4]); | |
1919 | print"<td align='center' width='160' $tdcolor>"; | |
2a81ab0d AM |
1920 | if ($$hash{$key}[3] eq 'std_net_src'){ |
1921 | print &get_name($$hash{$key}[4]); | |
1922 | }else{ | |
1923 | print $$hash{$key}[4]; | |
1924 | } | |
15add1c8 | 1925 | $tdcolor=''; |
2a81ab0d AM |
1926 | &getsrcport(\%$hash,$key); |
1927 | if ($$hash{$key}[17] eq 'ON'){ | |
1928 | $log="/images/on.gif"; | |
1929 | }else{ | |
1930 | $log="/images/off.gif"; | |
1931 | } | |
1932 | print<<END; | |
1933 | </td> | |
2a81ab0d | 1934 | <form method='post'> |
15add1c8 | 1935 | <td align='left' width='25'><input type='image' img src='$log' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw togglelog'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;'/> |
2a81ab0d AM |
1936 | <input type='hidden' name='key' value='$key' /> |
1937 | <input type='hidden' name='config' value='$config' /> | |
1938 | <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw togglelog'}' /> | |
1939 | </td></form> | |
1940 | END | |
15add1c8 | 1941 | &getcolor($$hash{$key}[6]); |
2a81ab0d | 1942 | print<<END; |
15add1c8 | 1943 | <td align='center' width='160' $tdcolor> |
2a81ab0d AM |
1944 | END |
1945 | if ($$hash{$key}[5] eq 'std_net_tgt'){ | |
1946 | print &get_name($$hash{$key}[6]); | |
1947 | }else{ | |
1948 | print $$hash{$key}[6]; | |
1949 | } | |
1950 | &gettgtport(\%$hash,$key); | |
93a5f4a5 AM |
1951 | print"</td>"; |
1952 | #Get Protocol | |
1953 | my $prot; | |
1954 | if ($$hash{$key}[12]){ #target prot if manual | |
1955 | $prot=$$hash{$key}[12]; | |
1956 | }elsif($$hash{$key}[8]){ #source prot if manual | |
1957 | $prot=$$hash{$key}[8]; | |
1958 | }elsif($$hash{$key}[14] eq 'cust_srv'){ | |
1959 | $prot=&get_serviceports("service",$$hash{$key}[15]); | |
1960 | }elsif($$hash{$key}[14] eq 'cust_srvgrp'){ | |
1961 | $prot=&get_serviceports("group",$$hash{$key}[15]); | |
1962 | }else{ | |
1963 | $prot=$Lang::tr{'all'}; | |
1964 | } | |
1965 | print"<td align='center'>$prot</td>"; | |
15add1c8 AM |
1966 | if ($$hash{$key}[18] eq 'ON'){ |
1967 | my @days=(); | |
1968 | if($$hash{$key}[19] ne ''){push (@days,$Lang::tr{'fwdfw wd_mon'});} | |
1969 | if($$hash{$key}[20] ne ''){push (@days,$Lang::tr{'fwdfw wd_tue'});} | |
1970 | if($$hash{$key}[21] ne ''){push (@days,$Lang::tr{'fwdfw wd_wed'});} | |
1971 | if($$hash{$key}[22] ne ''){push (@days,$Lang::tr{'fwdfw wd_thu'});} | |
1972 | if($$hash{$key}[23] ne ''){push (@days,$Lang::tr{'fwdfw wd_fri'});} | |
1973 | if($$hash{$key}[24] ne ''){push (@days,$Lang::tr{'fwdfw wd_sat'});} | |
1974 | if($$hash{$key}[25] ne ''){push (@days,$Lang::tr{'fwdfw wd_sun'});} | |
1975 | my $weekdays=join(",",@days); | |
1976 | if (@days){ | |
1977 | print"<td align='center' width='100'>$weekdays   $$hash{$key}[26] - $$hash{$key}[27]</td>"; | |
1978 | } | |
1979 | }else{ | |
1980 | print"<td></td>"; | |
1981 | } | |
2a81ab0d AM |
1982 | if($$hash{$key}[2] eq 'ON'){ |
1983 | $gif="/images/on.gif" | |
1984 | ||
1985 | }else{ | |
1986 | $gif="/images/off.gif" | |
2a81ab0d AM |
1987 | } |
1988 | print<<END; | |
1989 | <form method='post'> | |
15add1c8 | 1990 | <td width='25'><input type='image' img src='$gif' alt='$Lang::tr{'click to disable'}' title='$Lang::tr{'fwdfw toggle'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' /> |
2a81ab0d AM |
1991 | <input type='hidden' name='key' value='$key' /> |
1992 | <input type='hidden' name='config' value='$config' /> | |
1993 | <input type='hidden' name='ACTION' value='$Lang::tr{'fwdfw toggle'}' /> | |
1994 | </td></form> | |
2a81ab0d | 1995 | <form method='post'> |
15add1c8 | 1996 | <td width='25' ><input type='image' img src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'fwdfw edit'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' /> |
2a81ab0d AM |
1997 | <input type='hidden' name='key' value='$key' /> |
1998 | <input type='hidden' name='config' value='$config' /> | |
1999 | <input type='hidden' name='ACTION' value='editrule' /> | |
2000 | </td></form></td> | |
2a81ab0d | 2001 | <form method='post'> |
15add1c8 | 2002 | <td width='25'><input type='image' img src='/images/addblue.gif' alt='$Lang::tr{'fwdfw copy'}' title='$Lang::tr{'fwdfw copy'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' /> |
2a81ab0d AM |
2003 | <input type='hidden' name='key' value='$key' /> |
2004 | <input type='hidden' name='config' value='$config' /> | |
2005 | <input type='hidden' name='ACTION' value='copyrule' /> | |
2006 | </td></form></td> | |
2a81ab0d | 2007 | <form method='post'> |
15add1c8 | 2008 | <td width='25' ><input type='image' img src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'fwdfw delete'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' /> |
2a81ab0d AM |
2009 | <input type='hidden' name='key' value='$key' /> |
2010 | <input type='hidden' name='config' value='$config' /> | |
2011 | <input type='hidden' name='ACTION' value='deleterule' /> | |
2012 | </td></form></td> | |
2013 | END | |
2014 | if (exists $$hash{$key-1}){ | |
2015 | print<<END; | |
2016 | <form method='post'> | |
15add1c8 | 2017 | <td width='25'><input type='image' img src='/images/up.gif' alt='$Lang::tr{'fwdfw moveup'}' title='$Lang::tr{'fwdfw moveup'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' /> |
2a81ab0d AM |
2018 | <input type='hidden' name='key' value='$key' /> |
2019 | <input type='hidden' name='config' value='$config' /> | |
2020 | <input type='hidden' name='ACTION' value='moveup' /> | |
2021 | </td></form></td> | |
2022 | END | |
2023 | }else{ | |
15add1c8 | 2024 | print"<td width='25'><input type='image' img src='/images/up.gif' style='visibility:hidden;'></td>"; |
2a81ab0d | 2025 | } |
2a81ab0d AM |
2026 | if (exists $$hash{$key+1}){ |
2027 | print<<END; | |
2028 | <form method='post'> | |
15add1c8 | 2029 | <td width='25' ><input type='image' img src='/images/down.gif' alt='$Lang::tr{'fwdfw movedown'}' title='$Lang::tr{'fwdfw movedown'}' style='padding-top: 0px; padding-left: 0px; padding-bottom: 0px ;padding-right: 0px ;display: block;' /> |
2a81ab0d AM |
2030 | <input type='hidden' name='key' value='$key' /> |
2031 | <input type='hidden' name='config' value='$config' /> | |
2032 | <input type='hidden' name='ACTION' value='movedown' /> | |
2033 | </td></form></td></tr> | |
2034 | END | |
2035 | }else{ | |
15add1c8 | 2036 | print"<td width='25'><input type='image' img src='/images/down.gif' style='visibility:hidden;'></td></tr>"; |
2a81ab0d | 2037 | } |
15add1c8 AM |
2038 | #REMARK |
2039 | print"<tr bgcolor='$color'><td colspan='13' style='border-bottom: 1px solid black'>"; | |
2040 | print"<b>$Lang::tr{'remark'}:</b> $$hash{$key}[16]</td></tr>"; | |
2a81ab0d AM |
2041 | } |
2042 | print"</table>"; | |
2043 | &Header::closebox(); | |
2044 | } | |
2a81ab0d | 2045 | } |
15add1c8 AM |
2046 | sub getcolor |
2047 | { | |
2048 | my $val=shift; | |
2049 | if($optionsfw{'SHOWCOLORS'} eq 'on'){ | |
2050 | foreach my $alias (sort keys %aliases) | |
2051 | { | |
2052 | if ($val eq $alias){ | |
2053 | $tdcolor="style='border: 2px solid red;'"; | |
2054 | return; | |
2055 | } | |
2056 | } | |
2057 | if ($val eq 'GREEN'){ | |
2058 | $tdcolor="style='border: 2px solid green;'"; | |
2059 | }elsif ($val eq 'ORANGE'){ | |
2060 | $tdcolor="style='border: 2px solid orange;'"; | |
2061 | }elsif ($val eq 'BLUE'){ | |
2062 | $tdcolor="style='border: 2px solid blue;'"; | |
2063 | }elsif ($val eq 'IPFire' ){ | |
2064 | $tdcolor="style='border: 2px solid red;'"; | |
2065 | }elsif($val =~ /^(.*?)\/(.*?)$/){ | |
2066 | my ($sip,$scidr) = split ("/",$val); | |
2067 | if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){ | |
2068 | $tdcolor="style='border: 2px solid orange;'"; | |
2069 | } | |
2070 | if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){ | |
2071 | $tdcolor="style='border: 2px solid green;'"; | |
2072 | } | |
2073 | if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){ | |
2074 | $tdcolor="style='border: 2px solid blue;'"; | |
2075 | } | |
2076 | if ( &General::IpInSubnet($sip,$netsettings{'RED_ADDRESS'},$netsettings{'RED_NETMASK'})){ | |
2077 | $tdcolor="style='border: 2px solid red;'"; | |
2078 | } | |
2079 | }elsif ($val eq 'Default IP'){ | |
2080 | $tdcolor="style='border: 2px solid red;'"; | |
2081 | }else{ | |
2082 | $tdcolor=''; | |
2083 | } | |
2084 | } | |
2085 | } | |
2a81ab0d AM |
2086 | sub fillselect |
2087 | { | |
2088 | my %hash=%{(shift)}; | |
2089 | my $val=shift; | |
2090 | my $key; | |
62fc8511 AM |
2091 | foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){ |
2092 | if($hash{$key}[0] eq $val){ | |
2093 | print"<option value='$hash{$key}[0]' selected>$hash{$key}[0]</option>"; | |
2094 | }else{ | |
2095 | print"<option value='$hash{$key}[0]'>$hash{$key}[0]</option>"; | |
2a81ab0d | 2096 | } |
62fc8511 | 2097 | } |
2a81ab0d AM |
2098 | } |
2099 | sub rules | |
2100 | { | |
2101 | if (!-f "${General::swroot}/forward/reread"){ | |
2102 | system("touch ${General::swroot}/forward/reread"); | |
d0815ce4 | 2103 | system("touch ${General::swroot}/fwhosts/reread"); |
2a81ab0d AM |
2104 | } |
2105 | } | |
2106 | sub reread_rules | |
2107 | { | |
2108 | system("/usr/local/bin/forwardfwctrl"); | |
e974ced8 AM |
2109 | if ( -f "${General::swroot}/forward/reread"){ |
2110 | system("rm ${General::swroot}/forward/reread"); | |
d0815ce4 | 2111 | system("rm ${General::swroot}/fwhosts/reread"); |
e974ced8 | 2112 | } |
2a81ab0d AM |
2113 | } |
2114 | &Header::closebigbox(); | |
2115 | &Header::closepage(); |