]>
Commit | Line | Data |
---|---|---|
2a81ab0d AM |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5bee9a9d | 5 | # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> # |
2a81ab0d AM |
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 | ############################################################################### | |
2a81ab0d AM |
21 | use strict; |
22 | ||
23 | # enable only the following on debugging purpose | |
dadffbf7 AM |
24 | #use warnings; |
25 | ||
eff2dbf8 | 26 | use Sort::Naturally; |
2a81ab0d AM |
27 | use CGI::Carp 'fatalsToBrowser'; |
28 | no warnings 'uninitialized'; | |
29 | require '/var/ipfire/general-functions.pl'; | |
f770b728 | 30 | require '/var/ipfire/network-functions.pl'; |
9aadc465 | 31 | require "/var/ipfire/location-functions.pl"; |
4313aa18 | 32 | require "/usr/lib/firewall/firewall-lib.pl"; |
2a81ab0d AM |
33 | require "${General::swroot}/lang.pl"; |
34 | require "${General::swroot}/header.pl"; | |
35 | ||
36 | my %fwhostsettings=(); | |
37 | my %customnetwork=(); | |
38 | my %customhost=(); | |
39 | my %customgrp=(); | |
40 | my %customservice=(); | |
41 | my %customservicegrp=(); | |
9aadc465 | 42 | my %customlocationgrp=(); |
2a81ab0d AM |
43 | my %ccdnet=(); |
44 | my %ccdhost=(); | |
45 | my %ipsecconf=(); | |
46 | my %icmptypes=(); | |
47 | my %color=(); | |
48 | my %defaultNetworks=(); | |
49 | my %mainsettings=(); | |
50 | my %ownnet=(); | |
51 | my %ipsecsettings=(); | |
62fc8511 AM |
52 | my %fwfwd=(); |
53 | my %fwinp=(); | |
3a162dc1 | 54 | my %fwout=(); |
b119578f | 55 | my %ovpnsettings=(); |
f620fa34 | 56 | my %netsettings=(); |
6d92ee11 | 57 | my %optionsfw=(); |
2a81ab0d AM |
58 | |
59 | my $errormessage; | |
60 | my $hint; | |
61 | my $update=0; | |
62 | my $confignet = "${General::swroot}/fwhosts/customnetworks"; | |
63 | my $confighost = "${General::swroot}/fwhosts/customhosts"; | |
64 | my $configgrp = "${General::swroot}/fwhosts/customgroups"; | |
65 | my $configccdnet = "${General::swroot}/ovpn/ccd.conf"; | |
66 | my $configccdhost = "${General::swroot}/ovpn/ovpnconfig"; | |
67 | my $configipsec = "${General::swroot}/vpn/config"; | |
68 | my $configsrv = "${General::swroot}/fwhosts/customservices"; | |
69 | my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp"; | |
9aadc465 | 70 | my $configlocationgrp = "${General::swroot}/fwhosts/customlocationgrp"; |
6d8eb5de AM |
71 | my $fwconfigfwd = "${General::swroot}/firewall/config"; |
72 | my $fwconfiginp = "${General::swroot}/firewall/input"; | |
3a162dc1 | 73 | my $fwconfigout = "${General::swroot}/firewall/outgoing"; |
6d92ee11 | 74 | my $fwoptions = "${General::swroot}/optionsfw/settings"; |
b119578f | 75 | my $configovpn = "${General::swroot}/ovpn/settings"; |
b119578f | 76 | my $configipsecrw = "${General::swroot}/vpn/settings"; |
2a81ab0d | 77 | |
0b0e6d58 MT |
78 | unless (-e $confignet) { &General::system("touch", "$confignet"); } |
79 | unless (-e $confighost) { &General::system("touch", "$confighost"); } | |
80 | unless (-e $configgrp) { &General::system("touch", "$configgrp"); } | |
81 | unless (-e $configsrv) { &General::system("touch", "$configsrv"); } | |
82 | unless (-e $configsrvgrp) { &General::system("touch", "$configsrvgrp"); } | |
83 | unless (-e $configlocationgrp) { &General::system("touch $configlocationgrp"); } | |
2a81ab0d AM |
84 | |
85 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 86 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
2a81ab0d | 87 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); |
b119578f AM |
88 | &General::readhash("$configovpn", \%ovpnsettings); |
89 | &General::readhasharray("$configipsec", \%ipsecconf); | |
90 | &General::readhash("$configipsecrw", \%ipsecsettings); | |
f620fa34 | 91 | &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); |
6d92ee11 | 92 | &General::readhash($fwoptions, \%optionsfw); |
2a81ab0d | 93 | |
6d92ee11 | 94 | &Header::getcgihash(\%fwhostsettings); |
2a81ab0d | 95 | &Header::showhttpheaders(); |
4d74a20d | 96 | &Header::openpage($Lang::tr{'fwhost menu'}, 1, ''); |
2a81ab0d AM |
97 | &Header::openbigbox('100%', 'center'); |
98 | ||
2e99ab8b AM |
99 | #### JAVA SCRIPT #### |
100 | print<<END; | |
101 | <script> | |
fda8c915 AM |
102 | var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"]; |
103 | var update_protocol = function() { | |
104 | var protocol = \$("#protocol").val(); | |
105 | ||
106 | if (protocol === undefined) | |
107 | return; | |
108 | ||
109 | // Check if we are dealing with a protocol, that knows ports. | |
110 | if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) { | |
111 | \$("#PORT").show(); | |
c9493d6c | 112 | \$("#PROTOKOLL").hide(); |
fda8c915 AM |
113 | } else { |
114 | \$("#PORT").hide(); | |
fda8c915 | 115 | \$("#PROTOKOLL").show(); |
fda8c915 AM |
116 | } |
117 | }; | |
118 | ||
2e99ab8b | 119 | \$(document).ready(function() { |
fda8c915 | 120 | var protocol = \$("#protocol").val(); |
fda8c915 AM |
121 | \$("#protocol").change(update_protocol); |
122 | update_protocol(); | |
5f037986 AM |
123 | // Automatically select radio buttons when corresponding |
124 | // dropdown menu changes. | |
125 | \$("select").change(function() { | |
126 | var id = \$(this).attr("name"); | |
127 | \$('#' + id).prop("checked", true); | |
128 | }); | |
2e99ab8b AM |
129 | }); |
130 | </script> | |
131 | END | |
132 | ||
2a81ab0d AM |
133 | ## ACTION #### |
134 | # Update | |
135 | if ($fwhostsettings{'ACTION'} eq 'updatenet' ) | |
136 | { | |
137 | &General::readhasharray("$confignet", \%customnetwork); | |
138 | foreach my $key (keys %customnetwork) | |
139 | { | |
140 | if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}) | |
141 | { | |
142 | $fwhostsettings{'orgname'} = $customnetwork{$key}[0]; | |
143 | $fwhostsettings{'orgip'} = $customnetwork{$key}[1]; | |
144 | $fwhostsettings{'orgsub'} = $customnetwork{$key}[2]; | |
e5a058c1 AM |
145 | $fwhostsettings{'netremark'} = $customnetwork{$key}[3]; |
146 | $fwhostsettings{'count'} = $customnetwork{$key}[4]; | |
2a81ab0d | 147 | delete $customnetwork{$key}; |
66c36198 | 148 | |
2a81ab0d AM |
149 | } |
150 | } | |
151 | &General::writehasharray("$confignet", \%customnetwork); | |
152 | $fwhostsettings{'actualize'} = 'on'; | |
153 | $fwhostsettings{'ACTION'} = 'savenet'; | |
154 | } | |
155 | if ($fwhostsettings{'ACTION'} eq 'updatehost') | |
156 | { | |
157 | my ($ip,$subnet); | |
158 | &General::readhasharray("$confighost", \%customhost); | |
159 | foreach my $key (keys %customhost) | |
160 | { | |
161 | if($customhost{$key}[0] eq $fwhostsettings{'orgname'}) | |
162 | { | |
2a81ab0d AM |
163 | if ($customhost{$key}[1] eq 'ip'){ |
164 | ($ip,$subnet) = split (/\//,$customhost{$key}[2]); | |
165 | }else{ | |
166 | $ip = $customhost{$key}[2]; | |
167 | } | |
168 | $fwhostsettings{'orgip'} = $ip; | |
e3580608 | 169 | $fwhostsettings{'count'} = $customhost{$key}[4]; |
2a81ab0d | 170 | delete $customhost{$key}; |
5e970723 | 171 | &General::writehasharray("$confighost", \%customhost); |
2a81ab0d AM |
172 | } |
173 | } | |
2a81ab0d | 174 | $fwhostsettings{'actualize'} = 'on'; |
5e970723 | 175 | if($fwhostsettings{'orgip'}){ |
2a81ab0d | 176 | $fwhostsettings{'ACTION'} = 'savehost'; |
5e970723 AM |
177 | }else{ |
178 | $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'}; | |
179 | } | |
2a81ab0d AM |
180 | } |
181 | if ($fwhostsettings{'ACTION'} eq 'updateservice') | |
182 | { | |
183 | my $count=0; | |
184 | my $needrules=0; | |
185 | $errormessage=&checkports(\%customservice); | |
3a162dc1 AM |
186 | if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){ |
187 | $errormessage=$Lang::tr{'fwhost err grpexist'}; | |
188 | } | |
2a81ab0d AM |
189 | if (!$errormessage){ |
190 | &General::readhasharray("$configsrv", \%customservice); | |
191 | foreach my $key (keys %customservice) | |
192 | { | |
193 | if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'}) | |
194 | { | |
2a81ab0d AM |
195 | delete $customservice{$key}; |
196 | &General::writehasharray("$configsrv", \%customservice); | |
197 | last; | |
198 | } | |
199 | } | |
200 | if ($fwhostsettings{'PROT'} ne 'ICMP'){ | |
201 | $fwhostsettings{'ICMP_TYPES'}='BLANK'; | |
202 | } | |
203 | my $key1 = &General::findhasharraykey(\%customservice); | |
2aeb4b25 AM |
204 | #find out short ICMP-TYPE |
205 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
206 | foreach my $key (keys %icmptypes){ | |
207 | if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){ | |
208 | $fwhostsettings{'ICMP_TYPES'}=$icmptypes{$key}[0]; | |
209 | } | |
210 | } | |
2a81ab0d AM |
211 | foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";} |
212 | $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'}; | |
213 | $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'}; | |
214 | $customservice{$key1}[2] = $fwhostsettings{'PROT'}; | |
215 | $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'}; | |
2a81ab0d | 216 | &General::writehasharray("$configsrv", \%customservice); |
ed73b87e | 217 | #check if we need to update firewallrules |
bfee206c AM |
218 | if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){ |
219 | if ( ! -z $fwconfigfwd ){ | |
220 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
221 | foreach my $key (sort keys %fwfwd){ | |
222 | if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){ | |
223 | $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'}; | |
224 | } | |
225 | } | |
226 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
bfee206c AM |
227 | } |
228 | if ( ! -z $fwconfiginp ){ | |
229 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
230 | foreach my $line (sort keys %fwinp){ | |
231 | if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){ | |
232 | $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'}; | |
233 | } | |
234 | } | |
235 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
236 | } | |
3a162dc1 AM |
237 | if ( ! -z $fwconfigout ){ |
238 | &General::readhasharray("$fwconfigout", \%fwout); | |
239 | foreach my $line (sort keys %fwout){ | |
240 | if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){ | |
241 | $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'}; | |
242 | } | |
243 | } | |
244 | &General::writehasharray("$fwconfigout", \%fwout); | |
245 | } | |
bfac6bd4 AM |
246 | #check if we need to update groups |
247 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
248 | foreach my $key (sort keys %customservicegrp){ | |
249 | if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){ | |
250 | $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'}; | |
49da7d79 | 251 | &checkrulereload($customservicegrp{$key}[0]); |
bfac6bd4 AM |
252 | } |
253 | } | |
254 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
2aeb4b25 | 255 | } |
49da7d79 | 256 | &checkrulereload($fwhostsettings{'SRV_NAME'}); |
2a81ab0d AM |
257 | $fwhostsettings{'SRV_NAME'} = ''; |
258 | $fwhostsettings{'SRV_PORT'} = ''; | |
259 | $fwhostsettings{'PROT'} = ''; | |
2aeb4b25 AM |
260 | $fwhostsettings{'ICMP'} = ''; |
261 | $fwhostsettings{'oldsrvicmp'} = ''; | |
3a162dc1 | 262 | $fwhostsettings{'updatesrv'} = ''; |
2a81ab0d AM |
263 | }else{ |
264 | $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'}; | |
265 | $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'}; | |
266 | $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'}; | |
2aeb4b25 | 267 | $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'}; |
2a81ab0d AM |
268 | $fwhostsettings{'updatesrv'}= 'on'; |
269 | } | |
2a81ab0d AM |
270 | &addservice; |
271 | } | |
272 | # save | |
273 | if ($fwhostsettings{'ACTION'} eq 'savenet' ) | |
274 | { | |
2a81ab0d AM |
275 | my $needrules=0; |
276 | if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} | |
2a81ab0d AM |
277 | #check if all fields are set |
278 | if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') | |
279 | { | |
280 | $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; | |
281 | &addnet; | |
282 | &viewtablenet; | |
283 | }else{ | |
f770b728 AM |
284 | #convert ip if leading '0' exists |
285 | $fwhostsettings{'IP'} = &Network::ip_remove_zero($fwhostsettings{'IP'}); | |
286 | ||
66c36198 | 287 | #check valid ip |
2a81ab0d AM |
288 | if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'})) |
289 | { | |
290 | $errormessage=$errormessage.$Lang::tr{'fwhost err addr'}; | |
291 | $fwhostsettings{'BLK_HOST'} ='readonly'; | |
292 | $fwhostsettings{'NOCHECK'} ='false'; | |
293 | $fwhostsettings{'error'} ='on'; | |
294 | } | |
e5a058c1 AM |
295 | #check remark |
296 | if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){ | |
297 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
298 | $fwhostsettings{'error'} ='on'; | |
299 | } | |
2a81ab0d AM |
300 | #check if subnet is sigle host |
301 | if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32') | |
302 | { | |
303 | $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'}; | |
2a81ab0d AM |
304 | } |
305 | if($fwhostsettings{'error'} ne 'on'){ | |
3928f52b | 306 | my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'}); |
b7ab17ad | 307 | $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"","exact"); |
2a81ab0d AM |
308 | } |
309 | #only check plausi when no error till now | |
310 | if (!$errormessage){ | |
311 | &plausicheck("editnet"); | |
312 | } | |
2a81ab0d AM |
313 | if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage) |
314 | { | |
315 | $fwhostsettings{'actualize'} = ''; | |
316 | my $key = &General::findhasharraykey (\%customnetwork); | |
317 | foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";} | |
318 | $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ; | |
319 | $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ; | |
320 | $customnetwork{$key}[2] = $fwhostsettings{'orgsub'}; | |
f80db6a4 | 321 | $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'}; |
2a81ab0d AM |
322 | &General::writehasharray("$confignet", \%customnetwork); |
323 | undef %customnetwork; | |
d8cc4439 | 324 | } |
2a81ab0d AM |
325 | if (!$errormessage){ |
326 | &General::readhasharray("$confignet", \%customnetwork); | |
327 | if ($fwhostsettings{'ACTION'} eq 'updatenet'){ | |
328 | if ($fwhostsettings{'update'} == '0'){ | |
329 | foreach my $key (keys %customnetwork) { | |
330 | if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){ | |
2a81ab0d AM |
331 | delete $customnetwork{$key}; |
332 | last; | |
333 | } | |
334 | } | |
335 | } | |
336 | } | |
337 | #get count if actualize is 'on' | |
338 | if($fwhostsettings{'actualize'} eq 'on'){ | |
339 | $fwhostsettings{'actualize'} = ''; | |
2a81ab0d | 340 | #check if we need to reload rules |
484269ce | 341 | if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){ |
2a81ab0d AM |
342 | $needrules='on'; |
343 | } | |
344 | if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ | |
345 | #check if we need to update groups | |
346 | &General::readhasharray("$configgrp", \%customgrp); | |
347 | foreach my $key (sort keys %customgrp){ | |
348 | if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ | |
349 | $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; | |
350 | last; | |
351 | } | |
352 | } | |
353 | &General::writehasharray("$configgrp", \%customgrp); | |
62fc8511 AM |
354 | #check if we need to update firewallrules |
355 | if ( ! -z $fwconfigfwd ){ | |
356 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
357 | foreach my $line (sort keys %fwfwd){ | |
358 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
359 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
360 | } | |
361 | if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){ | |
362 | $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'}; | |
363 | } | |
364 | } | |
365 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
366 | } | |
367 | if ( ! -z $fwconfiginp ){ | |
368 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
369 | foreach my $line (sort keys %fwinp){ | |
370 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
371 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
372 | } | |
373 | } | |
374 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
375 | } | |
2a81ab0d | 376 | } |
d8cc4439 | 377 | } |
2a81ab0d | 378 | my $key = &General::findhasharraykey (\%customnetwork); |
484269ce | 379 | foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";} |
2a81ab0d AM |
380 | $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'}); |
381 | $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'}; | |
2a81ab0d AM |
382 | $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ; |
383 | $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ; | |
e5a058c1 | 384 | $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'}; |
2a81ab0d AM |
385 | &General::writehasharray("$confignet", \%customnetwork); |
386 | $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
387 | undef %customnetwork; | |
388 | $fwhostsettings{'HOSTNAME'}=''; | |
389 | $fwhostsettings{'IP'}=''; | |
390 | $fwhostsettings{'SUBNET'}=''; | |
e5a058c1 | 391 | $fwhostsettings{'NETREMARK'}=''; |
2a81ab0d AM |
392 | #check if an edited net affected groups and need to reload rules |
393 | if ($needrules eq 'on'){ | |
0e430797 | 394 | &General::firewall_config_changed(); |
2a81ab0d AM |
395 | } |
396 | &addnet; | |
397 | &viewtablenet; | |
d8cc4439 | 398 | }else{ |
3928f52b | 399 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; |
2a81ab0d AM |
400 | &addnet; |
401 | &viewtablenet; | |
402 | } | |
403 | } | |
2a81ab0d AM |
404 | } |
405 | if ($fwhostsettings{'ACTION'} eq 'savehost') | |
406 | { | |
2a81ab0d AM |
407 | my $needrules=0; |
408 | if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} | |
2a81ab0d | 409 | $fwhostsettings{'SUBNET'}='32'; |
2a81ab0d AM |
410 | #check if all fields are set |
411 | if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') | |
412 | { | |
413 | $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; | |
414 | $fwhostsettings{'ACTION'} = 'edithost'; | |
415 | }else{ | |
92e4ae9d | 416 | if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){ |
2a81ab0d | 417 | $fwhostsettings{'type'} = 'mac'; |
92e4ae9d | 418 | }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ |
2a81ab0d AM |
419 | $fwhostsettings{'type'} = 'ip'; |
420 | }else{ | |
421 | $fwhostsettings{'type'} = ''; | |
422 | $errormessage=$Lang::tr{'fwhost err ipmac'}; | |
423 | } | |
e3580608 AM |
424 | #check remark |
425 | if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){ | |
426 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
427 | } | |
2a81ab0d AM |
428 | #CHECK IP-PART |
429 | if ($fwhostsettings{'type'} eq 'ip'){ | |
f770b728 AM |
430 | #convert ip if leading '0' exists |
431 | $fwhostsettings{'IP'} = &Network::ip_remove_zero($fwhostsettings{'IP'}); | |
432 | ||
2a81ab0d AM |
433 | #check for subnet |
434 | if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){ | |
435 | if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32")) | |
436 | { | |
437 | $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'}; | |
438 | $fwhostsettings{'error'}='on'; | |
439 | } | |
2a81ab0d AM |
440 | }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){ |
441 | $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'}; | |
442 | $fwhostsettings{'error'}='on'; | |
443 | } | |
444 | #check if net or broadcast | |
445 | my @tmp= split (/\./,$fwhostsettings{'IP'}); | |
446 | if (($tmp[3] eq "0") || ($tmp[3] eq "255")){ | |
447 | $errormessage=$Lang::tr{'fwhost err hostip'}; | |
448 | } | |
449 | } | |
2a81ab0d | 450 | #only check plausi when no error till now |
66c36198 | 451 | if (!$errormessage){ |
2a81ab0d AM |
452 | &plausicheck("edithost"); |
453 | } | |
2a81ab0d AM |
454 | if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){ |
455 | $fwhostsettings{'actualize'} = ''; | |
456 | my $key = &General::findhasharraykey (\%customhost); | |
484269ce | 457 | foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";} |
2a81ab0d AM |
458 | $customhost{$key}[0] = $fwhostsettings{'orgname'} ; |
459 | $customhost{$key}[1] = $fwhostsettings{'type'} ; | |
460 | if($customhost{$key}[1] eq 'ip'){ | |
461 | $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
462 | }else{ | |
463 | $customhost{$key}[2] = $fwhostsettings{'orgip'}; | |
464 | } | |
f80db6a4 | 465 | $customhost{$key}[3] = $fwhostsettings{'orgremark'}; |
2a81ab0d AM |
466 | &General::writehasharray("$confighost", \%customhost); |
467 | undef %customhost; | |
66c36198 | 468 | } |
2a81ab0d AM |
469 | if (!$errormessage){ |
470 | #get count if host was edited | |
471 | if($fwhostsettings{'actualize'} eq 'on'){ | |
484269ce | 472 | if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){ |
2a81ab0d AM |
473 | $needrules='on'; |
474 | } | |
475 | if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ | |
476 | #check if we need to update groups | |
477 | &General::readhasharray("$configgrp", \%customgrp); | |
478 | foreach my $key (sort keys %customgrp){ | |
479 | if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ | |
480 | $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; | |
2a81ab0d AM |
481 | } |
482 | } | |
483 | &General::writehasharray("$configgrp", \%customgrp); | |
62fc8511 AM |
484 | #check if we need to update firewallrules |
485 | if ( ! -z $fwconfigfwd ){ | |
486 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
487 | foreach my $line (sort keys %fwfwd){ | |
488 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
489 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
490 | } | |
491 | if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){ | |
492 | $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'}; | |
493 | } | |
494 | } | |
495 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
496 | } | |
497 | if ( ! -z $fwconfiginp ){ | |
498 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
499 | foreach my $line (sort keys %fwinp){ | |
500 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
501 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
502 | } | |
503 | } | |
504 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
505 | } | |
2a81ab0d | 506 | } |
2a81ab0d AM |
507 | } |
508 | my $key = &General::findhasharraykey (\%customhost); | |
484269ce | 509 | foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";} |
2a81ab0d AM |
510 | $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ; |
511 | $customhost{$key}[1] = $fwhostsettings{'type'} ; | |
512 | if ($fwhostsettings{'type'} eq 'ip'){ | |
2a81ab0d AM |
513 | $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); |
514 | }else{ | |
515 | $customhost{$key}[2] = $fwhostsettings{'IP'}; | |
516 | } | |
e3580608 | 517 | $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'}; |
2a81ab0d | 518 | &General::writehasharray("$confighost", \%customhost); |
2a81ab0d AM |
519 | undef %customhost; |
520 | $fwhostsettings{'HOSTNAME'}=''; | |
521 | $fwhostsettings{'IP'}=''; | |
522 | $fwhostsettings{'type'}=''; | |
e3580608 | 523 | $fwhostsettings{'HOSTREMARK'}=''; |
2a81ab0d AM |
524 | #check if we need to update rules while host was edited |
525 | if($needrules eq 'on'){ | |
0e430797 | 526 | &General::firewall_config_changed(); |
2a81ab0d AM |
527 | } |
528 | &addhost; | |
529 | &viewtablehost; | |
530 | }else{ | |
531 | &addhost; | |
532 | &viewtablehost; | |
533 | } | |
2a81ab0d | 534 | } |
2a81ab0d AM |
535 | } |
536 | if ($fwhostsettings{'ACTION'} eq 'savegrp') | |
537 | { | |
484269ce | 538 | my $grp=$fwhostsettings{'grp_name'}; |
2a81ab0d AM |
539 | my $rem=$fwhostsettings{'remark'}; |
540 | my $count; | |
541 | my $type; | |
542 | my $updcounter='off'; | |
543 | my @target; | |
544 | my @newgrp; | |
545 | &General::readhasharray("$configgrp", \%customgrp); | |
546 | &General::readhasharray("$confignet", \%customnetwork); | |
547 | &General::readhasharray("$confighost", \%customhost); | |
484269ce AM |
548 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
549 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
550 | &General::readhasharray("$fwconfigout", \%fwout); | |
6c869961 AM |
551 | #check name |
552 | if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};} | |
f195a8d7 | 553 | #check existing name |
3a162dc1 | 554 | if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};} |
6c869961 AM |
555 | #check remark |
556 | if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){ | |
557 | $errormessage.=$Lang::tr{'fwhost err remark'}; | |
2a81ab0d | 558 | } |
6c869961 AM |
559 | if ($fwhostsettings{'update'} eq 'on'){ |
560 | #check standard networks | |
561 | if ($fwhostsettings{'grp2'} eq 'std_net'){ | |
562 | @target=$fwhostsettings{'DEFAULT_SRC_ADR'}; | |
66c36198 | 563 | $type='Standard Network'; |
6c869961 AM |
564 | } |
565 | #check custom networks | |
566 | if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){ | |
567 | @target=$fwhostsettings{'CUST_SRC_NET'}; | |
568 | $updcounter='net'; | |
569 | $type='Custom Network'; | |
570 | }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){ | |
571 | $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
572 | $fwhostsettings{'grp_name'}=''; | |
573 | $fwhostsettings{'remark'}=''; | |
574 | } | |
575 | #check custom addresses | |
576 | if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){ | |
577 | @target=$fwhostsettings{'CUST_SRC_HOST'}; | |
578 | $updcounter='host'; | |
579 | $type='Custom Host'; | |
580 | }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){ | |
581 | $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
582 | $fwhostsettings{'grp_name'}=''; | |
583 | $fwhostsettings{'remark'}=''; | |
584 | } | |
585 | #get address from ovpn ccd static net | |
586 | if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){ | |
587 | @target=$fwhostsettings{'OVPN_CCD_NET'}; | |
588 | $type='OpenVPN static network'; | |
589 | }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){ | |
590 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
591 | $fwhostsettings{'grp_name'}=''; | |
592 | $fwhostsettings{'remark'}=''; | |
593 | } | |
594 | #get address from ovpn ccd static host | |
595 | if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){ | |
596 | @target=$fwhostsettings{'OVPN_CCD_HOST'}; | |
597 | $type='OpenVPN static host'; | |
598 | }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){ | |
599 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
600 | } | |
601 | #get address from ovpn ccd Net-2-Net | |
602 | if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){ | |
603 | @target=$fwhostsettings{'OVPN_N2N'}; | |
604 | $type='OpenVPN N-2-N'; | |
605 | }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){ | |
606 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
607 | $fwhostsettings{'grp_name'}=''; | |
608 | $fwhostsettings{'remark'}=''; | |
609 | } | |
610 | #get address from IPSEC HOST | |
611 | if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){ | |
612 | @target=$fwhostsettings{'IPSEC_HOST'}; | |
613 | $type='IpSec Host'; | |
614 | }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){ | |
615 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
616 | $fwhostsettings{'grp_name'}=''; | |
617 | $fwhostsettings{'remark'}=''; | |
618 | } | |
619 | #get address from IPSEC NETWORK | |
620 | if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){ | |
621 | @target=$fwhostsettings{'IPSEC_NET'}; | |
622 | $type='IpSec Network'; | |
623 | }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){ | |
624 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
625 | $fwhostsettings{'grp_name'}=''; | |
626 | $fwhostsettings{'remark'}=''; | |
627 | } | |
628 | #check if host/net exists in grp | |
66c36198 | 629 | |
bc4a6881 | 630 | my $test="$grp,$fwhostsettings{'oldremark'},@target,$type"; |
6c869961 | 631 | foreach my $key (keys %customgrp) { |
bc4a6881 | 632 | my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2],$customgrp{$key}[3]"; |
6c869961 AM |
633 | if ($test1 eq $test){ |
634 | $errormessage=$Lang::tr{'fwhost err isingrp'}; | |
635 | $fwhostsettings{'update'} = 'on'; | |
636 | } | |
2a81ab0d AM |
637 | } |
638 | } | |
66c36198 | 639 | |
2a81ab0d AM |
640 | if (!$errormessage){ |
641 | #on first save, we have an empty @target, so fill it with nothing | |
642 | my $targetvalues=@target; | |
643 | if ($targetvalues == '0'){ | |
6c869961 | 644 | @target="none"; |
2a81ab0d AM |
645 | } |
646 | #on update, we have to delete the dummy entry | |
2a81ab0d | 647 | foreach my $key (keys %customgrp){ |
6c869961 | 648 | if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){ |
2a81ab0d AM |
649 | delete $customgrp{$key}; |
650 | last; | |
651 | } | |
652 | } | |
653 | &General::writehasharray("$configgrp", \%customgrp); | |
654 | &General::readhasharray("$configgrp", \%customgrp); | |
2a81ab0d AM |
655 | #create array with new lines |
656 | foreach my $line (@target){ | |
657 | push (@newgrp,"$grp,$rem,$line"); | |
658 | } | |
659 | #append new entries | |
660 | my $key = &General::findhasharraykey (\%customgrp); | |
661 | foreach my $line (@newgrp){ | |
484269ce | 662 | foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";} |
2a81ab0d AM |
663 | my ($a,$b,$c,$d) = split (",",$line); |
664 | $customgrp{$key}[0] = $a; | |
665 | $customgrp{$key}[1] = $b; | |
666 | $customgrp{$key}[2] = $c; | |
667 | $customgrp{$key}[3] = $type; | |
2a81ab0d AM |
668 | } |
669 | &General::writehasharray("$configgrp", \%customgrp); | |
2a81ab0d | 670 | #update counter in Host/Net |
2a81ab0d | 671 | $fwhostsettings{'update'}='on'; |
2a81ab0d | 672 | } |
2a81ab0d | 673 | #check if ruleupdate is needed |
484269ce AM |
674 | my $netgrpcount=0; |
675 | $netgrpcount=&getnetcount($grp); | |
676 | if($netgrpcount > 0 ) | |
2a81ab0d | 677 | { |
0e430797 | 678 | &General::firewall_config_changed(); |
2a81ab0d AM |
679 | } |
680 | &addgrp; | |
681 | &viewtablegrp; | |
2a81ab0d | 682 | } |
9aadc465 | 683 | if ($fwhostsettings{'ACTION'} eq 'savelocationgrp') |
4313aa18 SS |
684 | { |
685 | my $grp=$fwhostsettings{'grp_name'}; | |
686 | my $rem=$fwhostsettings{'remark'}; | |
687 | my $count; | |
688 | my $type; | |
689 | my @target; | |
690 | my @newgrp; | |
9aadc465 | 691 | &General::readhasharray("$configlocationgrp", \%customlocationgrp); |
1ed8aedf SS |
692 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
693 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
694 | &General::readhasharray("$fwconfigout", \%fwout); | |
4313aa18 | 695 | |
d4c30a95 AB |
696 | # Check name |
697 | if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};} | |
698 | ||
4313aa18 SS |
699 | # Check for existing group name. |
700 | if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){ | |
701 | $errormessage = $Lang::tr{'fwhost err grpexist'}; | |
702 | } | |
703 | ||
704 | # Check remark. | |
705 | if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){ | |
706 | $errormessage = $Lang::tr{'fwhost err remark'}; | |
707 | } | |
708 | ||
709 | if ($fwhostsettings{'update'} eq 'on'){ | |
710 | @target=$fwhostsettings{'COUNTRY_CODE'}; | |
9aadc465 | 711 | $type='Location Group'; |
4313aa18 SS |
712 | |
713 | #check if host/net exists in grp | |
714 | my $test="$grp,$fwhostsettings{'oldremark'},@target"; | |
9aadc465 SS |
715 | foreach my $key (keys %customlocationgrp) { |
716 | my $test1="$customlocationgrp{$key}[0],$customlocationgrp{$key}[1],$customlocationgrp{$key}[2]"; | |
4313aa18 SS |
717 | if ($test1 eq $test){ |
718 | $errormessage=$Lang::tr{'fwhost err isingrp'}; | |
719 | $fwhostsettings{'update'} = 'on'; | |
720 | } | |
721 | } | |
722 | } | |
723 | ||
724 | if (!$errormessage){ | |
725 | #on first save, we have an empty @target, so fill it with nothing | |
726 | my $targetvalues=@target; | |
727 | if ($targetvalues == '0'){ | |
728 | @target="none"; | |
729 | } | |
730 | #on update, we have to delete the dummy entry | |
9aadc465 SS |
731 | foreach my $key (keys %customlocationgrp){ |
732 | if ($customlocationgrp{$key}[0] eq $grp && $customlocationgrp{$key}[2] eq "none"){ | |
733 | delete $customlocationgrp{$key}; | |
4313aa18 SS |
734 | last; |
735 | } | |
736 | } | |
9aadc465 SS |
737 | &General::writehasharray("$configlocationgrp", \%customlocationgrp); |
738 | &General::readhasharray("$configlocationgrp", \%customlocationgrp); | |
4313aa18 SS |
739 | #create array with new lines |
740 | foreach my $line (@target){ | |
741 | push (@newgrp,"$grp,$rem,$line"); | |
742 | } | |
743 | #append new entries | |
9aadc465 | 744 | my $key = &General::findhasharraykey (\%customlocationgrp); |
4313aa18 | 745 | foreach my $line (@newgrp){ |
9aadc465 | 746 | foreach my $i (0 .. 3) { $customlocationgrp{$key}[$i] = "";} |
4313aa18 | 747 | my ($a,$b,$c,$d) = split (",",$line); |
9aadc465 SS |
748 | $customlocationgrp{$key}[0] = $a; |
749 | $customlocationgrp{$key}[1] = $b; | |
750 | $customlocationgrp{$key}[2] = $c; | |
751 | $customlocationgrp{$key}[3] = $type; | |
4313aa18 | 752 | } |
9aadc465 | 753 | &General::writehasharray("$configlocationgrp", \%customlocationgrp); |
4313aa18 SS |
754 | #update counter in Host/Net |
755 | $fwhostsettings{'update'}='on'; | |
756 | } | |
757 | #check if ruleupdate is needed | |
9aadc465 SS |
758 | my $locationgrpcount=0; |
759 | $locationgrpcount=&getlocationcount($grp); | |
760 | if($locationgrpcount > 0 ) | |
4313aa18 SS |
761 | { |
762 | &General::firewall_config_changed(); | |
763 | } | |
9aadc465 SS |
764 | &addlocationgrp; |
765 | &viewtablelocationgrp; | |
4313aa18 | 766 | } |
2a81ab0d AM |
767 | if ($fwhostsettings{'ACTION'} eq 'saveservice') |
768 | { | |
769 | my $ICMP; | |
2a81ab0d | 770 | &General::readhasharray("$configsrv", \%customservice ); |
3a162dc1 | 771 | &General::readhasharray("$configgrp", \%customgrp); |
2a81ab0d | 772 | $errormessage=&checkports(\%customservice); |
2a81ab0d AM |
773 | if ($fwhostsettings{'PROT'} eq 'ICMP'){ |
774 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
775 | foreach my $key (keys %icmptypes){ | |
776 | if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){ | |
777 | $ICMP=$icmptypes{$key}[0]; | |
778 | } | |
779 | } | |
780 | } | |
86a921ee | 781 | if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};} |
3a162dc1 AM |
782 | if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';} |
783 | #Check if a group with the same name already exists | |
784 | if (!&checkgroup($fwhostsettings{'SRV_NAME'})){ | |
785 | $errormessage = $Lang::tr{'fwhost err grpexist'}; | |
786 | } | |
2a81ab0d | 787 | if (!$errormessage){ |
2a81ab0d AM |
788 | my $key = &General::findhasharraykey (\%customservice); |
789 | foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";} | |
790 | $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'}; | |
791 | $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'}; | |
792 | $customservice{$key}[2] = $fwhostsettings{'PROT'}; | |
793 | $customservice{$key}[3] = $ICMP; | |
2a81ab0d AM |
794 | &General::writehasharray("$configsrv", \%customservice ); |
795 | #reset fields | |
796 | $fwhostsettings{'SRV_NAME'}=''; | |
797 | $fwhostsettings{'SRV_PORT'}=''; | |
798 | $fwhostsettings{'PROT'}=''; | |
799 | $fwhostsettings{'ICMP_TYPES'}=''; | |
2a81ab0d | 800 | } |
2a81ab0d | 801 | &addservice; |
2a81ab0d AM |
802 | } |
803 | if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') | |
804 | { | |
805 | my $prot; | |
806 | my $port; | |
49192c7b AM |
807 | my $tcpcounter=0; |
808 | my $udpcounter=0; | |
2a81ab0d AM |
809 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); |
810 | &General::readhasharray("$configsrv", \%customservice ); | |
2a81ab0d | 811 | $errormessage=&checkservicegroup; |
82b837cf AM |
812 | #Check if we have more than 15 services from one Protocol in the group |
813 | #iptables can only handle 15 ports/portranges via multiport | |
49192c7b AM |
814 | foreach my $key (keys %customservicegrp){ |
815 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){ | |
816 | foreach my $key1 (keys %customservice){ | |
817 | $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0]; | |
7db6ad6a | 818 | $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i; |
49192c7b | 819 | $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0]; |
7db6ad6a | 820 | $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i; |
49192c7b AM |
821 | } |
822 | } | |
823 | } | |
0341e11f SS |
824 | |
825 | # Loop through the hash of configured services. | |
826 | foreach my $key (keys %customservice) { | |
827 | # Assign nice human-readable values. | |
828 | my $service_name = $customservice{$key}[0]; | |
829 | my $service_port = $customservice{$key}[1]; | |
830 | my $service_proto = $customservice{$key}[2]; | |
831 | ||
832 | # Skip services unless the processed one has found. | |
833 | next unless $service_name eq $fwhostsettings{'CUST_SRV'}; | |
834 | ||
835 | # Increase the counters. | |
836 | $tcpcounter++ if $service_proto eq 'TCP'; | |
837 | $tcpcounter++ if $service_proto eq 'TCP' && $service_port =~ m/:/i; | |
838 | $udpcounter++ if $service_proto eq 'UDP'; | |
839 | $udpcounter++ if $service_proto eq 'UDP' && $service_port =~ m/:/i; | |
840 | } | |
841 | ||
842 | if ($tcpcounter > 15) { | |
49192c7b AM |
843 | $errormessage=$Lang::tr{'fwhost err maxservicetcp'}; |
844 | } | |
0341e11f | 845 | if ($udpcounter > 15) { |
49192c7b AM |
846 | $errormessage=$Lang::tr{'fwhost err maxserviceudp'}; |
847 | } | |
848 | $tcpcounter=0; | |
849 | $udpcounter=0; | |
bc912c6e AM |
850 | #check remark |
851 | if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){ | |
49192c7b | 852 | $errormessage .= $Lang::tr{'fwhost err remark'}; |
bc912c6e | 853 | } |
3a162dc1 AM |
854 | #Check if there is already a service with the same name |
855 | if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){ | |
856 | $errormessage .= $Lang::tr{'fwhost err srv exists'}; | |
857 | } | |
2a81ab0d AM |
858 | if (!$errormessage){ |
859 | #on first save, we have to enter a dummy value | |
6c869961 AM |
860 | if ($fwhostsettings{'CUST_SRV'} eq ''){ |
861 | $fwhostsettings{'CUST_SRV'}='none'; | |
862 | } | |
2a81ab0d AM |
863 | #on update, we have to delete the dummy entry |
864 | foreach my $key (keys %customservicegrp){ | |
aeefcc9c | 865 | if ($customservicegrp{$key}[2] eq 'none' && $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){ |
2a81ab0d AM |
866 | delete $customservicegrp{$key}; |
867 | last; | |
868 | } | |
869 | } | |
870 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); | |
871 | #check if remark has also changed | |
872 | if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on') | |
873 | { | |
874 | foreach my $key (keys %customservicegrp) | |
875 | { | |
876 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'}) | |
877 | { | |
878 | $customservicegrp{$key}[1]=''; | |
879 | $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'}; | |
3a162dc1 | 880 | } |
2a81ab0d AM |
881 | } |
882 | } | |
2a81ab0d | 883 | my $key = &General::findhasharraykey (\%customservicegrp); |
3a162dc1 | 884 | foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";} |
2a81ab0d AM |
885 | $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'}; |
886 | $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'}; | |
887 | $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'}; | |
2a81ab0d AM |
888 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); |
889 | $fwhostsettings{'updatesrvgrp'}='on'; | |
890 | } | |
49da7d79 | 891 | &checkrulereload($fwhostsettings{'SRVGRP_NAME'}); |
2a81ab0d AM |
892 | &addservicegrp; |
893 | &viewtableservicegrp; | |
894 | } | |
895 | # edit | |
896 | if ($fwhostsettings{'ACTION'} eq 'editnet') | |
897 | { | |
898 | &addnet; | |
899 | &viewtablenet; | |
900 | } | |
901 | if ($fwhostsettings{'ACTION'} eq 'edithost') | |
902 | { | |
903 | &addhost; | |
904 | &viewtablehost; | |
905 | } | |
906 | if ($fwhostsettings{'ACTION'} eq 'editgrp') | |
907 | { | |
908 | $fwhostsettings{'update'}='on'; | |
909 | &addgrp; | |
910 | &viewtablegrp; | |
911 | } | |
9aadc465 | 912 | if ($fwhostsettings{'ACTION'} eq 'editlocationgrp') |
4313aa18 SS |
913 | { |
914 | $fwhostsettings{'update'}='on'; | |
9aadc465 SS |
915 | &addlocationgrp; |
916 | &viewtablelocationgrp; | |
4313aa18 | 917 | } |
2a81ab0d AM |
918 | if ($fwhostsettings{'ACTION'} eq 'editservice') |
919 | { | |
920 | $fwhostsettings{'updatesrv'}='on'; | |
921 | &addservice; | |
922 | } | |
923 | if ($fwhostsettings{'ACTION'} eq 'editservicegrp') | |
924 | { | |
925 | $fwhostsettings{'updatesrvgrp'} = 'on'; | |
926 | &addservicegrp; | |
927 | &viewtableservicegrp; | |
928 | } | |
929 | # reset | |
930 | if ($fwhostsettings{'ACTION'} eq 'resetnet') | |
931 | { | |
932 | $fwhostsettings{'HOSTNAME'} =""; | |
933 | $fwhostsettings{'IP'} =""; | |
934 | $fwhostsettings{'SUBNET'} =""; | |
935 | &showmenu; | |
936 | } | |
937 | if ($fwhostsettings{'ACTION'} eq 'resethost') | |
938 | { | |
939 | $fwhostsettings{'HOSTNAME'} =""; | |
940 | $fwhostsettings{'IP'} =""; | |
941 | $fwhostsettings{'type'} =""; | |
942 | &showmenu; | |
943 | } | |
43215686 AM |
944 | if ($fwhostsettings{'ACTION'} eq 'resetgrp') |
945 | { | |
946 | $fwhostsettings{'grp_name'} =""; | |
947 | $fwhostsettings{'remark'} =""; | |
948 | &showmenu; | |
949 | } | |
9aadc465 | 950 | if ($fwhostsettings{'ACTION'} eq 'resetlocationgrp') |
4313aa18 SS |
951 | { |
952 | $fwhostsettings{'grp_name'} =""; | |
953 | $fwhostsettings{'remark'} =""; | |
954 | &showmenu; | |
955 | } | |
2a81ab0d AM |
956 | # delete |
957 | if ($fwhostsettings{'ACTION'} eq 'delnet') | |
958 | { | |
959 | &General::readhasharray("$confignet", \%customnetwork); | |
960 | foreach my $key (keys %customnetwork) { | |
961 | if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){ | |
962 | delete $customnetwork{$key}; | |
963 | &General::writehasharray("$confignet", \%customnetwork); | |
964 | last; | |
965 | } | |
966 | } | |
967 | &addnet; | |
968 | &viewtablenet; | |
969 | } | |
970 | if ($fwhostsettings{'ACTION'} eq 'delhost') | |
971 | { | |
972 | &General::readhasharray("$confighost", \%customhost); | |
973 | foreach my $key (keys %customhost) { | |
974 | if($fwhostsettings{'key'} eq $customhost{$key}[0]){ | |
975 | delete $customhost{$key}; | |
976 | &General::writehasharray("$confighost", \%customhost); | |
977 | last; | |
978 | } | |
979 | } | |
980 | &addhost; | |
981 | &viewtablehost; | |
2a81ab0d AM |
982 | } |
983 | if ($fwhostsettings{'ACTION'} eq 'deletegrphost') | |
984 | { | |
3f8fe51e AM |
985 | my $grpremark; |
986 | my $grpname; | |
2a81ab0d AM |
987 | &General::readhasharray("$configgrp", \%customgrp); |
988 | foreach my $key (keys %customgrp){ | |
989 | if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){ | |
3f8fe51e AM |
990 | $grpname=$customgrp{$key}[0]; |
991 | $grpremark=$customgrp{$key}[1]; | |
aeefcc9c AM |
992 | #check if we delete the last entry, then generate dummy |
993 | if ($fwhostsettings{'last'} eq 'on'){ | |
994 | $customgrp{$key}[1] = ''; | |
995 | $customgrp{$key}[2] = 'none'; | |
996 | $customgrp{$key}[3] = ''; | |
997 | $fwhostsettings{'last'}=''; | |
998 | last; | |
999 | }else{ | |
1000 | delete $customgrp{$key}; | |
1001 | } | |
2a81ab0d AM |
1002 | } |
1003 | } | |
1004 | &General::writehasharray("$configgrp", \%customgrp); | |
aeefcc9c | 1005 | &General::firewall_config_changed(); |
3f8fe51e AM |
1006 | if ($fwhostsettings{'update'} eq 'on'){ |
1007 | $fwhostsettings{'remark'}= $grpremark; | |
1008 | $fwhostsettings{'grp_name'}=$grpname; | |
1009 | } | |
2a81ab0d AM |
1010 | &addgrp; |
1011 | &viewtablegrp; | |
1012 | } | |
9aadc465 | 1013 | if ($fwhostsettings{'ACTION'} eq 'deletelocationgrpentry') |
4313aa18 SS |
1014 | { |
1015 | my $grpremark; | |
1016 | my $grpname; | |
9aadc465 SS |
1017 | &General::readhasharray("$configlocationgrp", \%customlocationgrp); |
1018 | foreach my $key (keys %customlocationgrp){ | |
1019 | if($customlocationgrp{$key}[0].",".$customlocationgrp{$key}[1].",".$customlocationgrp{$key}[2].",".$customlocationgrp{$key}[3] eq $fwhostsettings{'delentry'}){ | |
1020 | $grpname=$customlocationgrp{$key}[0]; | |
1021 | $grpremark=$customlocationgrp{$key}[1]; | |
4313aa18 SS |
1022 | #check if we delete the last entry, then generate dummy |
1023 | if ($fwhostsettings{'last'} eq 'on'){ | |
9aadc465 SS |
1024 | $customlocationgrp{$key}[1] = ''; |
1025 | $customlocationgrp{$key}[2] = 'none'; | |
1026 | $customlocationgrp{$key}[3] = ''; | |
4313aa18 SS |
1027 | $fwhostsettings{'last'}=''; |
1028 | last; | |
1029 | }else{ | |
9aadc465 | 1030 | delete $customlocationgrp{$key}; |
4313aa18 SS |
1031 | } |
1032 | } | |
1033 | } | |
9aadc465 | 1034 | &General::writehasharray("$configlocationgrp", \%customlocationgrp); |
4313aa18 SS |
1035 | &General::firewall_config_changed(); |
1036 | if ($fwhostsettings{'update'} eq 'on'){ | |
1037 | $fwhostsettings{'remark'}= $grpremark; | |
1038 | $fwhostsettings{'grp_name'}=$grpname; | |
1039 | } | |
9aadc465 SS |
1040 | &addlocationgrp; |
1041 | &viewtablelocationgrp; | |
4313aa18 SS |
1042 | } |
1043 | ||
2a81ab0d AM |
1044 | if ($fwhostsettings{'ACTION'} eq 'delgrp') |
1045 | { | |
1046 | &General::readhasharray("$configgrp", \%customgrp); | |
1047 | &decrease($fwhostsettings{'grp_name'}); | |
1048 | foreach my $key (sort keys %customgrp) | |
1049 | { | |
1050 | if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'}) | |
1051 | { | |
1052 | delete $customgrp{$key}; | |
1053 | } | |
1054 | } | |
1055 | &General::writehasharray("$configgrp", \%customgrp); | |
1056 | $fwhostsettings{'grp_name'}=''; | |
1057 | &addgrp; | |
1058 | &viewtablegrp; | |
1059 | } | |
9aadc465 | 1060 | if ($fwhostsettings{'ACTION'} eq 'dellocationgrp') |
4313aa18 | 1061 | { |
9aadc465 | 1062 | &General::readhasharray("$configlocationgrp", \%customlocationgrp); |
4313aa18 | 1063 | &decrease($fwhostsettings{'grp_name'}); |
9aadc465 | 1064 | foreach my $key (sort keys %customlocationgrp) |
4313aa18 | 1065 | { |
9aadc465 | 1066 | if($customlocationgrp{$key}[0] eq $fwhostsettings{'grp_name'}) |
4313aa18 | 1067 | { |
9aadc465 | 1068 | delete $customlocationgrp{$key}; |
4313aa18 SS |
1069 | } |
1070 | } | |
9aadc465 | 1071 | &General::writehasharray("$configlocationgrp", \%customlocationgrp); |
4313aa18 | 1072 | $fwhostsettings{'grp_name'}=''; |
9aadc465 SS |
1073 | &addlocationgrp; |
1074 | &viewtablelocationgrp; | |
4313aa18 | 1075 | } |
2a81ab0d AM |
1076 | if ($fwhostsettings{'ACTION'} eq 'delservice') |
1077 | { | |
1078 | &General::readhasharray("$configsrv", \%customservice); | |
1079 | foreach my $key (keys %customservice) { | |
1080 | if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){ | |
2a81ab0d AM |
1081 | delete $customservice{$key}; |
1082 | &General::writehasharray("$configsrv", \%customservice); | |
1083 | last; | |
1084 | } | |
1085 | } | |
1086 | $fwhostsettings{'SRV_NAME'}=''; | |
1087 | $fwhostsettings{'SRV_PORT'}=''; | |
1088 | $fwhostsettings{'PROT'}=''; | |
1089 | &addservice; | |
1090 | } | |
1091 | if ($fwhostsettings{'ACTION'} eq 'delservicegrp') | |
1092 | { | |
1093 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
1094 | &decreaseservice($fwhostsettings{'SRVGRP_NAME'}); | |
1095 | foreach my $key (sort keys %customservicegrp) | |
1096 | { | |
1097 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}) | |
1098 | { | |
1099 | delete $customservicegrp{$key}; | |
1100 | } | |
1101 | } | |
1102 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
1103 | $fwhostsettings{'SRVGRP_NAME'}=''; | |
1104 | &addservicegrp; | |
1105 | &viewtableservicegrp; | |
1106 | } | |
1107 | if ($fwhostsettings{'ACTION'} eq 'delgrpservice') | |
1108 | { | |
3f8fe51e AM |
1109 | my $grpname; |
1110 | my $grpremark; | |
2a81ab0d | 1111 | &General::readhasharray("$configsrvgrp", \%customservicegrp); |
2a81ab0d | 1112 | foreach my $key (keys %customservicegrp){ |
3a162dc1 | 1113 | if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'}) |
2a81ab0d | 1114 | { |
3f8fe51e AM |
1115 | $grpname=$customservicegrp{$key}[0]; |
1116 | $grpremark=$customservicegrp{$key}[1]; | |
aeefcc9c AM |
1117 | if($fwhostsettings{'last'} eq 'on'){ |
1118 | $customservicegrp{$key}[2] = 'none'; | |
1119 | $fwhostsettings{'last'} = ''; | |
1120 | last; | |
1121 | }else{ | |
1122 | delete $customservicegrp{$key}; | |
1123 | } | |
2a81ab0d AM |
1124 | } |
1125 | } | |
1126 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
0e430797 | 1127 | &General::firewall_config_changed(); |
3f8fe51e | 1128 | if ($fwhostsettings{'updatesrvgrp'} eq 'on'){ |
3f8fe51e AM |
1129 | $fwhostsettings{'SRVGRP_NAME'}=$grpname; |
1130 | $fwhostsettings{'SRVGRP_REMARK'}=$grpremark; | |
1131 | } | |
2a81ab0d AM |
1132 | &addservicegrp; |
1133 | &viewtableservicegrp; | |
2a81ab0d AM |
1134 | } |
1135 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'}) | |
1136 | { | |
1137 | &addnet; | |
1138 | &viewtablenet; | |
1139 | } | |
1140 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'}) | |
1141 | { | |
1142 | &addhost; | |
1143 | &viewtablehost; | |
1144 | } | |
1145 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'}) | |
1146 | { | |
1147 | &addgrp; | |
1148 | &viewtablegrp; | |
1149 | } | |
9aadc465 | 1150 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newlocationgrp'}) |
4313aa18 | 1151 | { |
9aadc465 SS |
1152 | &addlocationgrp; |
1153 | &viewtablelocationgrp; | |
4313aa18 | 1154 | } |
2a81ab0d AM |
1155 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'}) |
1156 | { | |
1157 | &addservice; | |
1158 | } | |
1159 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'}) | |
1160 | { | |
1161 | &addservicegrp; | |
1162 | &viewtableservicegrp; | |
1163 | } | |
6c869961 AM |
1164 | if ($fwhostsettings{'ACTION'} eq 'changegrpremark') |
1165 | { | |
1166 | &General::readhasharray("$configgrp", \%customgrp); | |
d0815ce4 | 1167 | if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){ |
6c869961 AM |
1168 | foreach my $key (sort keys %customgrp) |
1169 | { | |
6c869961 AM |
1170 | if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'}) |
1171 | { | |
6c869961 AM |
1172 | $customgrp{$key}[1]=''; |
1173 | $customgrp{$key}[1]=$fwhostsettings{'newrem'}; | |
66c36198 | 1174 | } |
6c869961 AM |
1175 | } |
1176 | &General::writehasharray("$configgrp", \%customgrp); | |
1177 | $fwhostsettings{'update'}='on'; | |
6c869961 AM |
1178 | $fwhostsettings{'remark'}=$fwhostsettings{'newrem'}; |
1179 | }else{ | |
1180 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1181 | $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'}; | |
1182 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1183 | $fwhostsettings{'update'} = 'on'; | |
1184 | } | |
1185 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1186 | &addgrp; | |
1187 | &viewtablegrp; | |
1188 | } | |
9aadc465 | 1189 | if ($fwhostsettings{'ACTION'} eq 'changelocationgrpremark') |
4313aa18 | 1190 | { |
9aadc465 | 1191 | &General::readhasharray("$configlocationgrp", \%customlocationgrp); |
4313aa18 | 1192 | if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){ |
9aadc465 | 1193 | foreach my $key (sort keys %customlocationgrp) |
4313aa18 | 1194 | { |
9aadc465 | 1195 | if($customlocationgrp{$key}[0] eq $fwhostsettings{'grp'} && $customlocationgrp{$key}[1] eq $fwhostsettings{'oldrem'}) |
4313aa18 | 1196 | { |
9aadc465 SS |
1197 | $customlocationgrp{$key}[1]=''; |
1198 | $customlocationgrp{$key}[1]=$fwhostsettings{'newrem'}; | |
4313aa18 SS |
1199 | } |
1200 | } | |
9aadc465 | 1201 | &General::writehasharray("$configlocationgrp", \%customlocationgrp); |
4313aa18 SS |
1202 | $fwhostsettings{'update'}='on'; |
1203 | $fwhostsettings{'remark'}=$fwhostsettings{'newrem'}; | |
1204 | }else{ | |
1205 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1206 | $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'}; | |
1207 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1208 | $fwhostsettings{'update'} = 'on'; | |
1209 | } | |
1210 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
9aadc465 SS |
1211 | &addlocationgrp; |
1212 | &viewtablelocationgrp; | |
4313aa18 | 1213 | } |
6c869961 AM |
1214 | if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark') |
1215 | { | |
1216 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); | |
d0815ce4 | 1217 | if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){ |
6c869961 AM |
1218 | foreach my $key (sort keys %customservicegrp) |
1219 | { | |
6c869961 AM |
1220 | if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'}) |
1221 | { | |
6c869961 AM |
1222 | $customservicegrp{$key}[1]=''; |
1223 | $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'}; | |
66c36198 | 1224 | } |
6c869961 AM |
1225 | } |
1226 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
1227 | $fwhostsettings{'updatesrvgrp'}='on'; | |
6c869961 | 1228 | $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'}; |
82b837cf AM |
1229 | }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){ |
1230 | &addservicegrp; | |
1231 | &viewtableservicegrp; | |
6c869961 AM |
1232 | }else{ |
1233 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1234 | $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'}; | |
1235 | $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'}; | |
1236 | $fwhostsettings{'updatesrvgrp'} = 'on'; | |
1237 | } | |
1238 | $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'}; | |
1239 | &addservicegrp; | |
1240 | &viewtableservicegrp; | |
1241 | } | |
a8b113e7 AM |
1242 | if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname') |
1243 | { | |
1244 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); | |
1245 | if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){ | |
1246 | #Check new groupname | |
1247 | if (!&validhostname($fwhostsettings{'srvgrp'})){ | |
1248 | $errormessage.=$Lang::tr{'fwhost err name'}."<br>"; | |
1249 | } | |
1250 | if (!$errormessage){ | |
1251 | #Rename group in customservicegroup | |
1252 | foreach my $key (keys %customservicegrp) { | |
1253 | if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){ | |
1254 | $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'}; | |
1255 | } | |
1256 | } | |
1257 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); | |
1258 | #change name in FW Rules | |
1259 | &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15); | |
1260 | } | |
1261 | } | |
1262 | &addservicegrp; | |
1263 | &viewtableservicegrp; | |
1264 | } | |
1265 | if ($fwhostsettings{'ACTION'} eq 'changegrpname') | |
1266 | { | |
1267 | &General::readhasharray("$configgrp", \%customgrp ); | |
1268 | if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){ | |
1269 | #Check new groupname | |
1270 | if (!&validhostname($fwhostsettings{'grp'})){ | |
1271 | $errormessage.=$Lang::tr{'fwhost err name'}."<br>"; | |
1272 | } | |
1273 | if (!$errormessage){ | |
1274 | #Rename group in customservicegroup | |
1275 | foreach my $key (keys %customgrp) { | |
1276 | if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){ | |
1277 | $customgrp{$key}[0]=$fwhostsettings{'grp'}; | |
1278 | } | |
1279 | } | |
1280 | &General::writehasharray("$configgrp", \%customgrp ); | |
1281 | #change name in FW Rules | |
2754623f | 1282 | &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},4); |
a8b113e7 AM |
1283 | &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6); |
1284 | } | |
1285 | } | |
1286 | &addgrp; | |
1287 | &viewtablegrp; | |
1288 | } | |
9aadc465 | 1289 | if ($fwhostsettings{'ACTION'} eq 'changelocationgrpname') |
4313aa18 | 1290 | { |
9aadc465 | 1291 | &General::readhasharray("$configlocationgrp", \%customlocationgrp ); |
4313aa18 SS |
1292 | if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){ |
1293 | #Check new groupname | |
1294 | if (!&validhostname($fwhostsettings{'grp'})){ | |
1295 | $errormessage.=$Lang::tr{'fwhost err name'}."<br>"; | |
1296 | } | |
1297 | if (!$errormessage){ | |
1298 | # Rename group. | |
9aadc465 SS |
1299 | foreach my $key (keys %customlocationgrp) { |
1300 | if($customlocationgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){ | |
1301 | $customlocationgrp{$key}[0]=$fwhostsettings{'grp'}; | |
4313aa18 SS |
1302 | } |
1303 | } | |
9aadc465 | 1304 | &General::writehasharray("$configlocationgrp", \%customlocationgrp ); |
4313aa18 | 1305 | #change name in FW Rules |
9aadc465 SS |
1306 | &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},4,"location"); |
1307 | &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6,"location"); | |
4313aa18 SS |
1308 | } |
1309 | } | |
9aadc465 SS |
1310 | &addlocationgrp; |
1311 | &viewtablelocationgrp; | |
4313aa18 | 1312 | } |
2a81ab0d AM |
1313 | ### VIEW ### |
1314 | if($fwhostsettings{'ACTION'} eq '') | |
1315 | { | |
1316 | &showmenu; | |
1317 | } | |
1318 | ### FUNCTIONS ### | |
0e430797 | 1319 | sub showmenu { |
4d74a20d | 1320 | &Header::openbox('100%', 'left',); |
43d8be09 | 1321 | print "$Lang::tr{'fwhost welcome'}"; |
2a81ab0d | 1322 | print<<END; |
2e99ab8b | 1323 | <br><br><table border='0' width='100%'> |
9aadc465 | 1324 | <tr><td><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newnet'}' ><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newhost'}' ><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newgrp'}' ><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newlocationgrp'}' ></form></td> |
2e99ab8b | 1325 | <td align='right'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservice'}' ><input type='submit' name='ACTION' value='$Lang::tr{'fwhost newservicegrp'}' ></form></td></tr> |
bc8ecbd6 | 1326 | <tr><td colspan='6'></td></tr></table> |
2a81ab0d | 1327 | END |
2a81ab0d | 1328 | &Header::closebox(); |
66c36198 | 1329 | |
2a81ab0d AM |
1330 | } |
1331 | # Add | |
1332 | sub addnet | |
1333 | { | |
1334 | &error; | |
1335 | &showmenu; | |
1336 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'}); | |
1337 | $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; | |
f80db6a4 | 1338 | $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'}; |
2a81ab0d | 1339 | print<<END; |
902a15be | 1340 | <table border='0' width='100%' > |
2e99ab8b | 1341 | <tr><td width='15%'>$Lang::tr{'name'}:</td><td><form method='post'><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'} size='20'><script>document.getElementById('textbox1').focus()</script></td></tr> |
1a8fde0e AM |
1342 | <tr><td>$Lang::tr{'fwhost netaddress'}:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='15'></td></tr> |
1343 | <tr><td>$Lang::tr{'netmask'}:</td><td><input type='TEXT' name='SUBNET' value='$fwhostsettings{'SUBNET'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='15'></td></tr> | |
8013bd0a | 1344 | <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr> |
bc8ecbd6 | 1345 | <tr><td colspan='6'><br></td></tr><tr> |
2a81ab0d AM |
1346 | END |
1347 | if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on') | |
1348 | { | |
902a15be | 1349 | print "<td colspan='6' align='right'><input type='submit' value='$Lang::tr{'update'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='updatenet'><input type='hidden' name='orgnetremark' value='$fwhostsettings{'orgnetremark'}' ><input type='hidden' name='orgname' value='$fwhostsettings{'orgname'}' ><input type='hidden' name='update' value='on'><input type='hidden' name='newnet' value='$fwhostsettings{'newnet'}'>"; |
2a81ab0d | 1350 | }else{ |
902a15be AM |
1351 | print "<td colspan='6' align='right'><input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='savenet'><input type='hidden' name='newnet' value='on'>"; |
1352 | } | |
2e99ab8b | 1353 | print "</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='resetnet'></form></td></tr></table>"; |
2a81ab0d AM |
1354 | &Header::closebox(); |
1355 | } | |
1356 | sub addhost | |
1357 | { | |
1358 | &error; | |
1359 | &showmenu; | |
1360 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'}); | |
1361 | $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; | |
f80db6a4 | 1362 | $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'}; |
2a81ab0d | 1363 | print<<END; |
bc8ecbd6 | 1364 | <table width='100%'> |
2e99ab8b | 1365 | <tr><td>$Lang::tr{'name'}:</td><td><form method='post' style='display:inline;'><input type='TEXT' name='HOSTNAME' id='textbox1' value='$fwhostsettings{'HOSTNAME'}' $fwhostsettings{'BLK_HOST'} size='20'><script>document.getElementById('textbox1').focus()</script></td></tr> |
1a8fde0e | 1366 | <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr> |
8013bd0a | 1367 | <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr> |
bc8ecbd6 | 1368 | <tr><td colspan='5'><br></td></tr><tr> |
2a81ab0d AM |
1369 | END |
1370 | ||
1371 | if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on') | |
1372 | { | |
66c36198 | 1373 | |
8013bd0a | 1374 | print " <td colspan='4' align='right'><input type='submit' value='$Lang::tr{'update'}' style='min-width:100px;'/><input type='hidden' name='ACTION' value='updatehost'><input type='hidden' name='orgremark' value='$fwhostsettings{'orgremark'}' ><input type='hidden' name='orgname' value='$fwhostsettings{'orgname'}' ><input type='hidden' name='update' value='on'><input type='hidden' name='newhost' value='$fwhostsettings{'newhost'}'></form>"; |
2a81ab0d | 1375 | }else{ |
2e99ab8b | 1376 | print " <td colspan='4' align='right'><input type='submit' name='savehost' value='$Lang::tr{'save'}' style='min-width:100px;' /><input type='hidden' name='ACTION' value='savehost' /><input type='hidden' name='newhost' value='on'>"; |
66c36198 | 1377 | } |
2e99ab8b | 1378 | print " </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='resethost'></form></td></tr></table>"; |
2a81ab0d AM |
1379 | &Header::closebox(); |
1380 | } | |
1381 | sub addgrp | |
1382 | { | |
1383 | &hint; | |
1384 | &error; | |
1385 | &showmenu; | |
1386 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'}); | |
1387 | &General::setup_default_networks(\%defaultNetworks); | |
8013bd0a AM |
1388 | &General::readhasharray("$configccdnet", \%ccdnet); |
1389 | &General::readhasharray("$confignet", \%customnetwork); | |
1390 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1391 | &General::readhasharray("$confighost", \%customhost); | |
1392 | &General::readhasharray("$configipsec", \%ipsecconf); | |
1393 | ||
2a81ab0d | 1394 | my %checked=(); |
8013bd0a | 1395 | my $show=''; |
2a81ab0d AM |
1396 | $checked{'check1'}{'off'} = ''; |
1397 | $checked{'check1'}{'on'} = ''; | |
1398 | $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED'; | |
1399 | $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'}; | |
a8b113e7 | 1400 | $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'}; |
6c869961 AM |
1401 | my $grp=$fwhostsettings{'grp_name'}; |
1402 | my $rem=$fwhostsettings{'remark'}; | |
66c36198 | 1403 | if ($fwhostsettings{'update'} eq ''){ |
2a81ab0d | 1404 | print<<END; |
bc8ecbd6 AM |
1405 | <table width='100%' border='0'> |
1406 | <tr> | |
7429ee78 AM |
1407 | <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td> |
1408 | <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td> | |
bc8ecbd6 AM |
1409 | </tr> |
1410 | <tr> | |
f620fa34 | 1411 | <td>$Lang::tr{'remark'}:</td> |
7429ee78 | 1412 | <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td> |
bc8ecbd6 AM |
1413 | </tr> |
1414 | <tr> | |
1415 | <td colspan='2'><br></td> | |
1416 | </tr> | |
1417 | </table> | |
2a81ab0d AM |
1418 | END |
1419 | }else{ | |
1420 | print<<END; | |
7429ee78 | 1421 | <table width='100%' border='0'><form method='post'> |
bc8ecbd6 | 1422 | <tr> |
7429ee78 AM |
1423 | <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td> |
1424 | <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td> | |
bc8ecbd6 AM |
1425 | <td><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'><input type='hidden' name='ACTION' value='changegrpname'></td> |
1426 | <td></td></form> | |
1427 | </tr> | |
1428 | <tr><form method='post' style='display:inline'> | |
1429 | <td>$Lang::tr{'remark'}:</td> | |
7429ee78 | 1430 | <td colspan='2' style='width:98%;'><input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'></td> |
a72ae687 | 1431 | <td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td> |
bc8ecbd6 AM |
1432 | </tr> |
1433 | </table></form> | |
1434 | <br><br> | |
2a81ab0d | 1435 | END |
2a81ab0d AM |
1436 | } |
1437 | if ($fwhostsettings{'update'} eq 'on'){ | |
2a81ab0d | 1438 | print<<END; |
8013bd0a AM |
1439 | <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'> |
1440 | <table width='100%' border='0'> | |
1441 | <tr><td width=50% valign='top'> | |
f620fa34 AM |
1442 | <table width='90%' border='0'> |
1443 | <tr> | |
1444 | <td style='width:15em;'> | |
1445 | <label> | |
1446 | <input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked> | |
1447 | $Lang::tr{'fwhost stdnet'} | |
1448 | </label> | |
1449 | </td> | |
1450 | <td style='text-align:right;'> | |
a72ae687 | 1451 | <select name='DEFAULT_SRC_ADR' style='width:16em;'> |
2a81ab0d AM |
1452 | END |
1453 | foreach my $network (sort keys %defaultNetworks) | |
1454 | { | |
1455 | next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP"); | |
7326051e | 1456 | next if($defaultNetworks{$network}{'NAME'} eq "IPFire"); |
2a81ab0d AM |
1457 | print "<option value='$defaultNetworks{$network}{'NAME'}'"; |
1458 | print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'}); | |
7326051e AM |
1459 | my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS"; |
1460 | my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK"; | |
1461 | my $defsub1=&General::subtocidr($ownnet{$defsub}); | |
1462 | $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED'); | |
1463 | if ($ownnet{$defnet}){ | |
1464 | print ">$network ($ownnet{$defnet}/$defsub1)</option>"; | |
1465 | }else{ | |
1466 | print ">$network</option>"; | |
1467 | } | |
2a81ab0d | 1468 | } |
8013bd0a AM |
1469 | print"</select></td></tr>"; |
1470 | if (! -z $confignet){ | |
f620fa34 AM |
1471 | print<<END; |
1472 | <tr> | |
1473 | <td> | |
1474 | <label> | |
1475 | <input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}> | |
1476 | $Lang::tr{'fwhost cust net'}: | |
1477 | </label> | |
1478 | </td> | |
1479 | <td style='text-align:right;'> | |
a72ae687 | 1480 | <select name='CUST_SRC_NET' style='width:16em;'>"; |
f620fa34 | 1481 | END |
eff2dbf8 | 1482 | foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) { |
8013bd0a AM |
1483 | print"<option>$customnetwork{$key}[0]</option>"; |
1484 | } | |
1485 | print"</select></td></tr>"; | |
2a81ab0d | 1486 | } |
8013bd0a | 1487 | if (! -z $confighost){ |
f620fa34 AM |
1488 | print<<END; |
1489 | <tr> | |
1490 | <td valign='top'> | |
1491 | <label> | |
1492 | <input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}> | |
1493 | $Lang::tr{'fwhost cust addr'}: | |
1494 | </label> | |
1495 | </td> | |
1496 | <td style='text-align:right;'> | |
a72ae687 | 1497 | <select name='CUST_SRC_HOST' style='width:16em;'>"; |
f620fa34 | 1498 | END |
eff2dbf8 | 1499 | foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) { |
8013bd0a AM |
1500 | print"<option>$customhost{$key}[0]</option>"; |
1501 | } | |
1502 | print"</select></td></tr>"; | |
1503 | } | |
1504 | print"</table>"; | |
1505 | #Inner table right | |
f620fa34 | 1506 | print"</td><td align='right' style='vertical-align:top;'><table width='90%' border='0'>"; |
8013bd0a AM |
1507 | #OVPN networks |
1508 | if (! -z $configccdnet){ | |
f620fa34 AM |
1509 | print<<END; |
1510 | <td style='width:15em;'> | |
1511 | <label> | |
1512 | <input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}> | |
1513 | $Lang::tr{'fwhost ccdnet'} | |
1514 | </label> | |
1515 | </td> | |
1516 | <td style='text-align:right;'> | |
a72ae687 | 1517 | <select name='OVPN_CCD_NET' style='width:16em;'>"; |
f620fa34 | 1518 | END |
eff2dbf8 | 1519 | foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet) |
8013bd0a AM |
1520 | { |
1521 | print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>"; | |
1522 | } | |
1523 | print"</select></td></tr>"; | |
2a81ab0d | 1524 | } |
8013bd0a | 1525 | #OVPN clients |
a72ae687 | 1526 | my @ovpn_clients=(); |
eff2dbf8 | 1527 | foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost) |
2a81ab0d AM |
1528 | { |
1529 | if ($ccdhost{$key}[33] ne ''){ | |
a72ae687 AM |
1530 | $show='1'; |
1531 | push (@ovpn_clients,$ccdhost{$key}[1]); | |
1532 | } | |
1533 | } | |
1534 | if ($show eq '1'){ | |
1535 | $show=''; | |
1536 | print<<END; | |
f620fa34 AM |
1537 | <td style='width:15em;'> |
1538 | <label> | |
1539 | <input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}> | |
1540 | $Lang::tr{'fwhost ccdhost'} | |
1541 | </label> | |
1542 | </td> | |
1543 | <td style='text-align:right;'> | |
a72ae687 | 1544 | <select name='OVPN_CCD_HOST' style='width:16em;'>" if ($show eq ''); |
f620fa34 | 1545 | END |
a72ae687 AM |
1546 | foreach(@ovpn_clients){ |
1547 | print"<option value='$_'>$_</option>"; | |
2a81ab0d | 1548 | } |
a72ae687 | 1549 | print"</select></td></tr>"; |
2a81ab0d | 1550 | } |
8013bd0a | 1551 | #OVPN n2n networks |
a72ae687 | 1552 | my @OVPN_N2N=(); |
eff2dbf8 | 1553 | foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) { |
2a81ab0d | 1554 | if($ccdhost{$key}[3] eq 'net'){ |
a72ae687 AM |
1555 | $show='1'; |
1556 | push (@OVPN_N2N,$ccdhost{$key}[1]); | |
1557 | } | |
1558 | } | |
1559 | if ($show eq '1'){ | |
1560 | $show=''; | |
1561 | print<<END; | |
f620fa34 AM |
1562 | <td style='width:15em;'> |
1563 | <label> | |
1564 | <input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}> | |
1565 | $Lang::tr{'fwhost ovpn_n2n'}: | |
1566 | </label> | |
1567 | </td> | |
1568 | <td style='text-align:right;'> | |
a72ae687 | 1569 | <select name='OVPN_N2N' style='width:16em;'>" |
f620fa34 | 1570 | END |
a72ae687 AM |
1571 | foreach(@OVPN_N2N){ |
1572 | print"<option>$_</option>"; | |
2a81ab0d | 1573 | } |
a72ae687 | 1574 | print"</select></td></tr>"; |
2a81ab0d | 1575 | } |
8013bd0a | 1576 | #IPsec networks |
6d92ee11 | 1577 | |
eff2dbf8 | 1578 | foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) { |
6d92ee11 AM |
1579 | if ($ipsecconf{$key}[3] eq 'net' || ($optionsfw{'SHOWDROPDOWN'} eq 'on' && $ipsecconf{$key}[3] ne 'host')){ |
1580 | print "<td style='width:15em;'><label><input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}>$Lang::tr{'fwhost ipsec net'}</label></td><td style='text-align:right;'><select name='IPSEC_NET' style='width:16em;'>" if $show eq ''; | |
1581 | $show=1; | |
1582 | #Check if we have more than one REMOTE subnet in config | |
1583 | my @arr1 = split /\|/, $ipsecconf{$key}[11]; | |
1584 | my $cnt1 += @arr1; | |
1585 | ||
1586 | print"<option value=$ipsecconf{$key}[1]>"; | |
1587 | print"$ipsecconf{$key}[1]"; | |
1588 | print" ($Lang::tr{'fwdfw all subnets'})" if $cnt1 > 1; #If this Conenction has more than one subnet, print one option for all subnets | |
1589 | print"</option>"; | |
1590 | ||
1591 | if ($cnt1 > 1){ | |
1592 | foreach my $val (@arr1){ | |
1593 | #normalize subnet to cidr notation | |
1594 | my ($val1,$val2) = split /\//, $val; | |
1595 | my $val3 = &General::iporsubtocidr($val2); | |
1596 | print "<option "; | |
1597 | print "value='$ipsecconf{$key}[1]|$val1/$val3'"; | |
1598 | print ">$ipsecconf{$key}[1] ($val1/$val3)</option>"; | |
1599 | } | |
1600 | } | |
2a81ab0d AM |
1601 | } |
1602 | } | |
a72ae687 | 1603 | print"</select></td></tr>"; |
8013bd0a AM |
1604 | print"</table>"; |
1605 | print"</td></tr></table>"; | |
bc8ecbd6 | 1606 | print"<br><br>"; |
2a81ab0d | 1607 | } |
bc8ecbd6 | 1608 | print"<table width='100%'>"; |
f620fa34 | 1609 | print"<tr><td style='text-align:right;'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='update' value=\"$fwhostsettings{'update'}\"><input type='hidden' name='ACTION' value='savegrp' ></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='resetgrp'></form></td></table>"; |
2a81ab0d AM |
1610 | &Header::closebox(); |
1611 | } | |
9aadc465 | 1612 | sub addlocationgrp |
4313aa18 SS |
1613 | { |
1614 | &hint; | |
1615 | &error; | |
1616 | &showmenu; | |
9aadc465 | 1617 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addlocationgrp'}); |
4313aa18 SS |
1618 | |
1619 | my %checked=(); | |
1620 | my $show=''; | |
1621 | $checked{'check1'}{'off'} = ''; | |
1622 | $checked{'check1'}{'on'} = ''; | |
1623 | $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED'; | |
1624 | $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'}; | |
1625 | $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'}; | |
1626 | my $grp=$fwhostsettings{'grp_name'}; | |
1627 | my $rem=$fwhostsettings{'remark'}; | |
1628 | if ($fwhostsettings{'update'} eq ''){ | |
1629 | print<<END; | |
1630 | <table width='100%' border='0'> | |
1631 | <tr> | |
1632 | <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td> | |
1633 | <td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='30'></td> | |
1634 | </tr> | |
1635 | <tr> | |
1636 | <td>$Lang::tr{'remark'}:</td> | |
1637 | <td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 99%;'></td> | |
1638 | </tr> | |
1639 | <tr> | |
1640 | <td colspan='2'><br></td> | |
1641 | </tr> | |
1642 | </table> | |
1643 | END | |
1644 | } else { | |
1645 | print<<END; | |
1646 | <table width='100%' border='0'> | |
1647 | <form method='post'><tr> | |
1648 | <td style='width:15%;'>$Lang::tr{'fwhost addgrpname'}</td> | |
1649 | <td style='width:30%;'><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' size='30'></td> | |
1650 | <td> | |
1651 | <input type='submit' value='$Lang::tr{'fwhost change'}'> | |
1652 | <input type='hidden' name='oldgrpname' value='$fwhostsettings{'oldgrpname'}'> | |
9aadc465 | 1653 | <input type='hidden' name='ACTION' value='changelocationgrpname'> |
4313aa18 SS |
1654 | </td> |
1655 | <td></td> | |
1656 | </tr></form> | |
1657 | <tr><form method='post' style='display:inline'> | |
1658 | <td>$Lang::tr{'remark'}:</td> | |
1659 | <td colspan='2' style='width:98%;'> | |
1660 | <input type='TEXT' name='newrem' value='$fwhostsettings{'remark'}' style='width:98%;'> | |
1661 | </td> | |
1662 | <td align='right'> | |
1663 | <input type='submit' value='$Lang::tr{'fwhost change'}'> | |
1664 | <input type='hidden' name='grp' value='$fwhostsettings{'grp_name'}'> | |
1665 | <input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'> | |
9aadc465 | 1666 | <input type='hidden' name='ACTION' value='changelocationgrpremark'> |
4313aa18 SS |
1667 | </td> |
1668 | </tr></form> | |
1669 | </table> | |
1670 | <br><br> | |
1671 | END | |
1672 | } | |
1673 | if ($fwhostsettings{'update'} eq 'on') { | |
d3f7af81 | 1674 | my @location_locations = &fwlib::get_locations(); |
4313aa18 SS |
1675 | |
1676 | print<<END; | |
1677 | <form method='post'> | |
1678 | <input type='hidden' name='remark' value='$rem'> | |
1679 | <input type='hidden' name='grp_name' value='$grp'> | |
1680 | ||
1681 | <table width='100%' border='0'> | |
1682 | <tr> | |
1683 | <td style='text-align:left;'> | |
1684 | <select name='COUNTRY_CODE' style='width:16em;'>"; | |
1685 | END | |
9aadc465 | 1686 | foreach my $location (@location_locations) { |
4313aa18 | 1687 | # Get full country name. |
9aadc465 | 1688 | my $fullname = &Location::Functions::get_full_country_name($location); |
4313aa18 SS |
1689 | |
1690 | print"<option value='$location'>$location - $fullname</option>\n"; | |
1691 | } | |
1692 | print <<END; | |
1693 | </select> | |
1694 | </td> | |
1695 | </tr> | |
1696 | </table> | |
1697 | <br><br> | |
1698 | END | |
1699 | } | |
1700 | print <<END; | |
1701 | <table width='100%'> | |
1702 | <tr><td style='text-align:right;'> | |
1703 | <input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /> | |
1704 | <input type='hidden' name='oldremark' value='$fwhostsettings{'oldremark'}'> | |
1705 | <input type='hidden' name='update' value=\"$fwhostsettings{'update'}\"> | |
9aadc465 | 1706 | <input type='hidden' name='ACTION' value='savelocationgrp' > |
4313aa18 SS |
1707 | </form> |
1708 | ||
1709 | <form method='post' style='display:inline'> | |
1710 | ||
1711 | <input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'> | |
9aadc465 | 1712 | <input type='hidden' name='ACTION' value='resetlocationgrp'> |
4313aa18 SS |
1713 | |
1714 | </form> | |
1715 | </td></tr></table> | |
1716 | END | |
1717 | &Header::closebox(); | |
1718 | } | |
2a81ab0d AM |
1719 | sub addservice |
1720 | { | |
1721 | &error; | |
1722 | &showmenu; | |
1a8fde0e | 1723 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'}); |
2a81ab0d AM |
1724 | if ($fwhostsettings{'updatesrv'} eq 'on') |
1725 | { | |
1726 | $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'}; | |
1727 | $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'}; | |
1728 | $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'}; | |
2aeb4b25 | 1729 | $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'}; |
2a81ab0d AM |
1730 | } |
1731 | print<<END; | |
fda8c915 | 1732 | <table width='100%' border='0'><form method='post'> |
1a8fde0e | 1733 | <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost srv_name'}:</td><td><input type='text' name='SRV_NAME' id='textbox1' value='$fwhostsettings{'SRV_NAME'}' size='24'><script>document.getElementById('textbox1').focus()</script></td></tr> |
fda8c915 | 1734 | <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' > |
2a81ab0d AM |
1735 | END |
1736 | foreach ("TCP","UDP","ICMP") | |
1737 | { | |
1738 | if ($_ eq $fwhostsettings{'PROT'}) | |
1739 | { | |
1740 | print"<option selected>$_</option>"; | |
1741 | }else{ | |
1742 | print"<option>$_</option>"; | |
1743 | } | |
1744 | } | |
1745 | print<<END; | |
fda8c915 | 1746 | </select></td></tr></table> |
bfc84eb1 | 1747 | <div id='PROTOKOLL' class='noscript'><table width=100%' border='0'><tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost icmptype'}</td><td><select name='ICMP_TYPES'> |
2a81ab0d AM |
1748 | END |
1749 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
86a921ee | 1750 | print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>"; |
eff2dbf8 | 1751 | foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){ |
2aeb4b25 AM |
1752 | if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){ |
1753 | print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1754 | }else{ | |
1755 | print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1756 | } | |
2a81ab0d | 1757 | } |
2a81ab0d | 1758 | print<<END; |
bfc84eb1 AM |
1759 | </select></td></tr></table></div> |
1760 | <div id='PORT' class='noscript'><table width='100%' border='0'><tr><td width='10%'>$Lang::tr{'fwhost port'}:</td><td><input type='text' name='SRV_PORT' value='$fwhostsettings{'SRV_PORT'}' maxlength='11' size='24'></td></tr></table></div> | |
bc8ecbd6 | 1761 | <table width='100%' border='0'><tr><td colspan='6'><br></td></tr> |
2a81ab0d AM |
1762 | <tr><td colspan='6' align='right'> |
1763 | END | |
1764 | if ($fwhostsettings{'updatesrv'} eq 'on') | |
1765 | { | |
1766 | print<<END; | |
7f5b2820 | 1767 | <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' > |
2a81ab0d AM |
1768 | <input type='hidden' name='ACTION' value='updateservice'> |
1769 | <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'> | |
1770 | <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'> | |
2aeb4b25 AM |
1771 | <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'> |
1772 | <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'> | |
1773 | </form> | |
2a81ab0d | 1774 | END |
fda8c915 | 1775 | }else{ |
7f5b2820 | 1776 | print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>"; |
2a81ab0d AM |
1777 | } |
1778 | print<<END; | |
7f5b2820 | 1779 | <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr> |
2a81ab0d | 1780 | </table></form> |
2a81ab0d AM |
1781 | END |
1782 | &Header::closebox(); | |
1783 | &viewtableservice; | |
1784 | } | |
1785 | sub addservicegrp | |
1786 | { | |
1787 | &hint; | |
1788 | &error; | |
1789 | &showmenu; | |
1a8fde0e | 1790 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'}); |
2a81ab0d | 1791 | $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'}; |
a8b113e7 | 1792 | $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'}; |
2a81ab0d AM |
1793 | if ($fwhostsettings{'updatesrvgrp'} eq ''){ |
1794 | print<<END; | |
1795 | <table width='100%' border='0'><form method='post'> | |
1a8fde0e | 1796 | <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}' size='24'></td></tr> |
8013bd0a | 1797 | <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr> |
bc8ecbd6 | 1798 | <tr><td colspan='2'><br></tr> |
2a81ab0d AM |
1799 | </table> |
1800 | END | |
1801 | }else{ | |
1802 | print<<END; | |
bc8ecbd6 | 1803 | <table width='100%'><form method='post' style='display:inline'> |
a8b113e7 | 1804 | <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td width='20%'><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' size='14'></td><td align='left'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvgrpname' value='$fwhostsettings{'oldsrvgrpname'}'><input type='hidden' name='ACTION' value='changesrvgrpname'></td><td width='3%'></td></form></tr> |
a72ae687 AM |
1805 | <tr> |
1806 | <form method='post'> | |
1807 | <td width='10%'> | |
1808 | $Lang::tr{'remark'}: | |
1809 | </td> | |
1810 | <td colspan='2'> | |
1811 | <input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'> | |
1812 | </td> | |
1813 | <td align='right'> | |
1814 | <input type='submit' value='$Lang::tr{'fwhost change'}'> | |
1815 | <input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'> | |
1816 | <input type='hidden' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}'> | |
1817 | <input type='hidden' name='ACTION' value='changesrvgrpremark' > | |
1818 | </td> | |
1819 | </tr> | |
1820 | <tr> | |
1821 | <td colspan='4'> | |
1822 | <br> | |
1823 | </td> | |
1824 | </tr> | |
1825 | </table> | |
1826 | </form> | |
2a81ab0d AM |
1827 | END |
1828 | } | |
1829 | if($fwhostsettings{'updatesrvgrp'} eq 'on'){ | |
2a81ab0d | 1830 | print<<END; |
6c869961 | 1831 | <form method='post'><input type='hidden' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}'><input type='hidden' name='SRVGRP_NAME' value='$fwhostsettings{'SRVGRP_NAME'}'><table border='0' width='100%'> |
bc8ecbd6 | 1832 | <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'add'}: </td><td><select name='CUST_SRV' style='min-width:185px;'> |
2a81ab0d AM |
1833 | END |
1834 | &General::readhasharray("$configsrv", \%customservice); | |
82b837cf AM |
1835 | #Protocols for use in servicegroups |
1836 | print "<optgroup label='$Lang::tr{'fwhost cust service'}'>"; | |
eff2dbf8 | 1837 | foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice) |
2a81ab0d AM |
1838 | { |
1839 | print "<option>$customservice{$key}[0]</option>"; | |
1840 | } | |
82b837cf AM |
1841 | print "</optgroup>"; |
1842 | print "<optgroup label='$Lang::tr{'protocol'}'>"; | |
1843 | print "<option>GRE</option>"; | |
1844 | print "<option>AH</option>"; | |
1845 | print "<option>ESP</option>"; | |
1846 | print "<option>IGMP</option>"; | |
1847 | print "<option>IPIP</option>"; | |
1848 | print "<option value='IPV6'>IPv6 encap</option>"; | |
1849 | print "</optgroup>"; | |
2a81ab0d AM |
1850 | print<<END; |
1851 | </select></td></tr> | |
5dd84c25 | 1852 | <tr><td colspan='4'><br><br></td></tr> |
bc8ecbd6 | 1853 | <tr><td colspan='4'></td></tr> |
2a81ab0d AM |
1854 | </table> |
1855 | END | |
1856 | } | |
1857 | print<<END; | |
bc8ecbd6 | 1858 | <table width='100%'> |
7f5b2820 | 1859 | <tr><td align='right'><input type='submit' value='$Lang::tr{'add'}' style='min-width:100px;' /><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'><input type='hidden' name='oldsrvgrpremark' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='saveservicegrp' ></form><form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></td></tr> |
2a81ab0d AM |
1860 | </table></form> |
1861 | END | |
2a81ab0d AM |
1862 | &Header::closebox(); |
1863 | } | |
1864 | # View | |
1865 | sub viewtablenet | |
1866 | { | |
1867 | if(! -z $confignet){ | |
1868 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'}); | |
1869 | &General::readhasharray("$confignet", \%customnetwork); | |
484269ce AM |
1870 | &General::readhasharray("$configgrp", \%customgrp); |
1871 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
1872 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
1873 | &General::readhasharray("$fwconfigout", \%fwout); | |
f620fa34 | 1874 | |
66c36198 PM |
1875 | if (!keys %customnetwork) |
1876 | { | |
1877 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
2a81ab0d AM |
1878 | }else{ |
1879 | print<<END; | |
902a15be AM |
1880 | <table width='100%' cellspacing='0' class='tbl'> |
1881 | <tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost netaddress'}</b></th><th align='center'><b>$Lang::tr{'remark'}</b></th><th align='center'><b>$Lang::tr{'used'}</b></th><th></th><th width='3%'></th></tr> | |
2a81ab0d AM |
1882 | END |
1883 | } | |
1884 | my $count=0; | |
902a15be | 1885 | my $col=''; |
eff2dbf8 | 1886 | foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) { |
2a81ab0d | 1887 | if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) { |
902a15be AM |
1888 | print" <tr>"; |
1889 | $col="bgcolor='${Header::colouryellow}'"; | |
2a81ab0d | 1890 | }elsif ($count % 2) |
66c36198 | 1891 | { |
902a15be | 1892 | $col="bgcolor='$color{'color20'}'"; |
aeefcc9c | 1893 | print" <tr>"; |
2a81ab0d AM |
1894 | }else |
1895 | { | |
902a15be | 1896 | $col="bgcolor='$color{'color22'}'"; |
aeefcc9c | 1897 | print" <tr>"; |
2a81ab0d | 1898 | } |
72586f0f | 1899 | my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]); |
484269ce | 1900 | my $netcount=&getnetcount($customnetwork{$key}[0]); |
f620fa34 | 1901 | print"<td width='20%' $col><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center' $col>".&getcolor($colnet)."</td><td width='40%' $col>$customnetwork{$key}[3]</td><td align='center' $col>$netcount x</td>"; |
2a81ab0d | 1902 | print<<END; |
f8aa0679 | 1903 | <td width='1%' $col><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
2a81ab0d AM |
1904 | <input type='hidden' name='ACTION' value='editnet'> |
1905 | <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' /> | |
1906 | <input type='hidden' name='IP' value='$customnetwork{$key}[1]' /> | |
1907 | <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' /> | |
e5a058c1 | 1908 | <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' /> |
2a81ab0d AM |
1909 | </td></form> |
1910 | END | |
484269ce | 1911 | if($netcount == '0') |
2a81ab0d | 1912 | { |
f8aa0679 | 1913 | print"<td width='1%' $col><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><input type='hidden' name='ACTION' value='delnet' /><input type='hidden' name='key' value='$customnetwork{$key}[0]' /></td></form></tr>"; |
2a81ab0d | 1914 | }else{ |
902a15be | 1915 | print"<td $col></td></tr>"; |
2a81ab0d AM |
1916 | } |
1917 | $count++; | |
1918 | } | |
1919 | print"</table>"; | |
1920 | &Header::closebox(); | |
66c36198 | 1921 | } |
2a81ab0d AM |
1922 | |
1923 | } | |
b119578f AM |
1924 | sub getcolor |
1925 | { | |
1926 | my $c=shift; | |
f620fa34 AM |
1927 | my $sip; |
1928 | my $scidr; | |
1ccfb89e | 1929 | my $tdcolor=''; |
f620fa34 AM |
1930 | #Check if MAC |
1931 | if (&General::validmac($c)){ return $c;} | |
1932 | ||
1933 | #Check if we got a full IP with subnet then split it | |
1934 | if($c =~ /^(.*?)\/(.*?)$/){ | |
1935 | ($sip,$scidr) = split ("/",$c); | |
1936 | }else{ | |
1937 | $sip=$c; | |
1938 | } | |
1939 | ||
1940 | #Now check if IP is part of ORANGE,BLUE or GREEN | |
7fa1b16e | 1941 | if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){ |
f620fa34 AM |
1942 | $tdcolor="<font style='color: $Header::colourorange;'>$c</font>"; |
1943 | return $tdcolor; | |
1944 | } | |
1945 | if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){ | |
1946 | $tdcolor="<font style='color: $Header::colourgreen;'>$c</font>"; | |
1947 | return $tdcolor; | |
1948 | } | |
7fa1b16e | 1949 | if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){ |
f620fa34 AM |
1950 | $tdcolor="<font style='color: $Header::colourblue;'>$c</font>"; |
1951 | return $tdcolor; | |
1952 | } | |
48f07c19 AM |
1953 | if ("$sip/$scidr" eq "0.0.0.0/0"){ |
1954 | $tdcolor="<font style='color: $Header::colourred;'>$c</font>"; | |
1955 | return $tdcolor; | |
1956 | } | |
b119578f AM |
1957 | #Check if IP is part of OpenVPN N2N subnet |
1958 | foreach my $key (sort keys %ccdhost){ | |
1959 | if ($ccdhost{$key}[3] eq 'net'){ | |
1960 | my ($a,$b) = split("/",$ccdhost{$key}[11]); | |
f620fa34 AM |
1961 | if (&General::IpInSubnet($sip,$a,$b)){ |
1962 | $tdcolor="<font style='color:$Header::colourovpn ;'>$c</font>"; | |
b119578f AM |
1963 | return $tdcolor; |
1964 | } | |
1965 | } | |
1966 | } | |
f620fa34 | 1967 | |
b119578f AM |
1968 | #Check if IP is part of OpenVPN dynamic subnet |
1969 | my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'}); | |
f620fa34 AM |
1970 | if (&General::IpInSubnet($sip,$a,$b)){ |
1971 | $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>"; | |
b119578f AM |
1972 | return $tdcolor; |
1973 | } | |
f620fa34 | 1974 | |
b119578f AM |
1975 | #Check if IP is part of OpenVPN static subnet |
1976 | foreach my $key (sort keys %ccdnet){ | |
1977 | my ($a,$b) = split("/",$ccdnet{$key}[1]); | |
1978 | $b =&General::iporsubtodec($b); | |
f620fa34 AM |
1979 | if (&General::IpInSubnet($sip,$a,$b)){ |
1980 | $tdcolor="<font style='color: $Header::colourovpn;'>$c</font>"; | |
b119578f AM |
1981 | return $tdcolor; |
1982 | } | |
1983 | } | |
f620fa34 | 1984 | |
b119578f AM |
1985 | #Check if IP is part of IPsec RW network |
1986 | if ($ipsecsettings{'RW_NET'} ne ''){ | |
1987 | my ($a,$b) = split("/",$ipsecsettings{'RW_NET'}); | |
1988 | $b=&General::iporsubtodec($b); | |
f620fa34 AM |
1989 | if (&General::IpInSubnet($sip,$a,$b)){ |
1990 | $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>"; | |
b119578f AM |
1991 | return $tdcolor; |
1992 | } | |
1993 | } | |
f620fa34 | 1994 | |
b119578f AM |
1995 | #Check if IP is part of a IPsec N2N network |
1996 | foreach my $key (sort keys %ipsecconf){ | |
1ccfb89e | 1997 | if ($ipsecconf{$key}[11]){ |
6f36132e PM |
1998 | foreach my $ipsecsubitem (split(/\|/, $ipsecconf{$key}[11])) { |
1999 | my ($a,$b) = split("/",$ipsecsubitem); | |
2000 | $b=&General::iporsubtodec($b); | |
2001 | if (&General::IpInSubnet($sip,$a,$b)){ | |
2002 | $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>"; | |
2003 | return $tdcolor; | |
2004 | } | |
1ccfb89e | 2005 | } |
b119578f AM |
2006 | } |
2007 | } | |
f620fa34 | 2008 | return "$c"; |
b119578f | 2009 | } |
2a81ab0d AM |
2010 | sub viewtablehost |
2011 | { | |
2012 | if (! -z $confighost){ | |
2013 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'}); | |
2014 | &General::readhasharray("$confighost", \%customhost); | |
b119578f AM |
2015 | &General::readhasharray("$configccdnet", \%ccdnet); |
2016 | &General::readhasharray("$configccdhost", \%ccdhost); | |
484269ce AM |
2017 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
2018 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
2019 | &General::readhasharray("$fwconfigout", \%fwout); | |
2020 | &General::readhasharray("$configgrp", \%customgrp); | |
66c36198 PM |
2021 | if (!keys %customhost) |
2022 | { | |
2023 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
2a81ab0d AM |
2024 | }else{ |
2025 | print<<END; | |
902a15be AM |
2026 | <table width='100%' cellspacing='0' class='tbl'> |
2027 | <tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center'><b>$Lang::tr{'remark'}</b></th><th align='center'><b>$Lang::tr{'used'}</b></th><th></th><th width='3%'></th></tr> | |
2a81ab0d AM |
2028 | END |
2029 | } | |
2030 | my $count=0; | |
902a15be | 2031 | my $col=''; |
eff2dbf8 | 2032 | foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) { |
2a81ab0d | 2033 | if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) { |
902a15be AM |
2034 | print" <tr>"; |
2035 | $col="bgcolor='${Header::colouryellow}'"; | |
2036 | }elsif ($count % 2){ | |
2037 | print" <tr>"; | |
2038 | $col="bgcolor='$color{'color20'}'"; | |
2039 | }else{ | |
2040 | $col="bgcolor='$color{'color22'}'"; | |
2041 | print" <tr>"; | |
2042 | } | |
2a81ab0d | 2043 | my ($ip,$sub)=split(/\//,$customhost{$key}[2]); |
e3580608 | 2044 | $customhost{$key}[4]=~s/\s+//g; |
484269ce AM |
2045 | my $hostcount=0; |
2046 | $hostcount=&gethostcount($customhost{$key}[0]); | |
f620fa34 | 2047 | print"<td width='20%' $col>$customhost{$key}[0]</td><td width='20%' align='center' $col >".&getcolor($ip)."</td><td width='50%' align='left' $col>$customhost{$key}[3]</td><td align='center' $col>$hostcount x</td>"; |
2a81ab0d | 2048 | print<<END; |
f8aa0679 | 2049 | <td width='1%' $col><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
2a81ab0d AM |
2050 | <input type='hidden' name='ACTION' value='edithost' /> |
2051 | <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' /> | |
2052 | <input type='hidden' name='IP' value='$ip' /> | |
2053 | <input type='hidden' name='type' value='$customhost{$key}[1]' /> | |
e3580608 | 2054 | <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' /> |
2e99ab8b | 2055 | </form></td> |
2a81ab0d | 2056 | END |
484269ce | 2057 | if($hostcount == '0') |
2a81ab0d | 2058 | { |
f8aa0679 | 2059 | print"<td width='1%' $col><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><input type='hidden' name='ACTION' value='delhost' /><input type='hidden' name='key' value='$customhost{$key}[0]' /></td></form></tr>"; |
2a81ab0d | 2060 | }else{ |
902a15be | 2061 | print"<td width='1%' $col></td></tr>"; |
2a81ab0d AM |
2062 | } |
2063 | $count++; | |
2064 | } | |
2065 | print"</table>"; | |
2066 | &Header::closebox(); | |
2067 | } | |
2068 | } | |
2069 | sub viewtablegrp | |
2070 | { | |
2071 | if(! -z "$configgrp"){ | |
2072 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'}); | |
2073 | &General::readhasharray("$configgrp", \%customgrp); | |
2074 | &General::readhasharray("$configipsec", \%ipsecconf); | |
2075 | &General::readhasharray("$configccdhost", \%ccdhost); | |
2076 | &General::readhasharray("$configccdnet", \%ccdnet); | |
2077 | &General::readhasharray("$confighost", \%customhost); | |
2078 | &General::readhasharray("$confignet", \%customnetwork); | |
484269ce AM |
2079 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
2080 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
2081 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d AM |
2082 | my @grp=(); |
2083 | my $helper=''; | |
8f204435 | 2084 | my $count=1; |
2a81ab0d AM |
2085 | my $grpname; |
2086 | my $remark; | |
12dcfbbd | 2087 | my $number; |
2cee2462 | 2088 | my $delflag; |
aeefcc9c AM |
2089 | my @counter; |
2090 | my %hash; | |
66c36198 | 2091 | if (!keys %customgrp) |
484269ce | 2092 | { |
f195a8d7 | 2093 | print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>"; |
2a81ab0d | 2094 | }else{ |
aeefcc9c AM |
2095 | #get all groups in a hash |
2096 | foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ | |
2097 | push (@counter,$customgrp{$key}[0]); | |
2098 | } | |
2099 | foreach my $key1 (@counter) { | |
2100 | $hash{$key1}++ ; | |
2101 | } | |
0c2cf9e2 | 2102 | foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ |
2a81ab0d AM |
2103 | $count++; |
2104 | if ($helper ne $customgrp{$key}[0]){ | |
2cee2462 | 2105 | $delflag='0'; |
eff2dbf8 | 2106 | foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ |
2cee2462 AM |
2107 | if ($customgrp{$key}[0] eq $customgrp{$key1}[0]) |
2108 | { | |
2109 | $delflag++; | |
2110 | } | |
d0815ce4 | 2111 | if($delflag > 1){ |
d13a9363 AM |
2112 | last; |
2113 | } | |
2cee2462 | 2114 | } |
8f204435 | 2115 | $number=1; |
f195a8d7 | 2116 | if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};} |
2a81ab0d | 2117 | $grpname=$customgrp{$key}[0]; |
6c869961 | 2118 | $remark="$customgrp{$key}[1]"; |
aeefcc9c | 2119 | if($count gt 1){ print"</table>";$count=1;} |
2e99ab8b | 2120 | print "<br><b><u>$grpname</u></b> "; |
2a81ab0d | 2121 | print " <b>$Lang::tr{'remark'}:</b>  $remark   " if ($remark ne ''); |
484269ce AM |
2122 | my $netgrpcount=&getnetcount($grpname); |
2123 | print "<b>$Lang::tr{'used'}:</b> $netgrpcount x"; | |
2124 | if($netgrpcount == '0') | |
2a81ab0d | 2125 | { |
f8aa0679 | 2126 | print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='ACTION' value='delgrp'></form>"; |
2a81ab0d | 2127 | } |
f8aa0679 | 2128 | print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' align='right' /><input type='hidden' name='grp_name' value='$grpname' ><input type='hidden' name='remark' value='$remark' ><input type='hidden' name='ACTION' value='editgrp'></form>"; |
726e6882 | 2129 | print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>$Lang::tr{'name'}</b></th><th align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost type'}</th><th></th></tr>"; |
2a81ab0d | 2130 | } |
902a15be | 2131 | my $col=''; |
2a81ab0d | 2132 | if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) { |
902a15be AM |
2133 | print" <tr>"; |
2134 | $col="bgcolor='${Header::colouryellow}'"; | |
6c869961 | 2135 | }elsif ($count %2 == 0){ |
902a15be | 2136 | print"<tr>"; |
aeefcc9c | 2137 | $col="bgcolor='$color{'color20'}'"; |
6c869961 | 2138 | }else{ |
902a15be | 2139 | print"<tr>"; |
aeefcc9c | 2140 | $col="bgcolor='$color{'color22'}'"; |
6c869961 | 2141 | } |
66c36198 | 2142 | my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]); |
902a15be AM |
2143 | if ($ip eq ''){ |
2144 | print"<tr>"; | |
2145 | $col="bgcolor='${Header::colouryellow}'"; | |
2146 | } | |
2147 | print "<td width='39%' align='left' $col>"; | |
2a81ab0d AM |
2148 | if($customgrp{$key}[3] eq 'Standard Network'){ |
2149 | print &get_name($customgrp{$key}[2])."</td>"; | |
6d92ee11 AM |
2150 | }elsif($customgrp{$key}[3] eq "IpSec Network" && $customgrp{$key}[2] =~ /\|/){ |
2151 | my ($a,$b) = split /\|/, $customgrp{$key}[2]; | |
2152 | print "$a</td>"; | |
2a81ab0d AM |
2153 | }else{ |
2154 | print "$customgrp{$key}[2]</td>"; | |
2155 | } | |
f195a8d7 | 2156 | if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){ |
bc595f09 | 2157 | print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>"; |
2a81ab0d | 2158 | }else{ |
bc595f09 | 2159 | print"<td align='center' $col>".&getcolor($ip)."</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>"; |
2a81ab0d | 2160 | } |
aeefcc9c | 2161 | if ($delflag > 0 && $ip ne ''){ |
f8aa0679 | 2162 | print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' />"; |
aeefcc9c AM |
2163 | #check if this group has only one entry |
2164 | foreach my $key2 (keys %hash) { | |
2165 | if ($hash{$key2}<2 && $key2 eq $customgrp{$key}[0]){ | |
2166 | print "<input type='hidden' name='last' value='on'>" ; | |
2167 | } | |
2168 | } | |
2a81ab0d | 2169 | } |
bc595f09 | 2170 | print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>"; |
2a81ab0d | 2171 | $helper=$customgrp{$key}[0]; |
12dcfbbd | 2172 | $number++; |
2a81ab0d AM |
2173 | } |
2174 | print"</table>"; | |
2a81ab0d AM |
2175 | } |
2176 | &Header::closebox(); | |
2177 | } | |
2178 | ||
4313aa18 | 2179 | } |
9aadc465 | 2180 | sub viewtablelocationgrp |
4313aa18 SS |
2181 | { |
2182 | # If our filesize is "zero" there is nothing to read-in. | |
9aadc465 | 2183 | if (-z "$configlocationgrp") { |
4313aa18 SS |
2184 | return; |
2185 | } | |
2186 | ||
9aadc465 SS |
2187 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust locationgrp'}); |
2188 | &General::readhasharray("$configlocationgrp", \%customlocationgrp); | |
4313aa18 SS |
2189 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
2190 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
2191 | &General::readhasharray("$fwconfigout", \%fwout); | |
2192 | my @grp=(); | |
2193 | my $helper=''; | |
2194 | my $count=1; | |
2195 | my $country_code; | |
2196 | my $grpname; | |
2197 | my $remark; | |
2198 | my $number; | |
2199 | my $delflag; | |
2200 | my @counter; | |
2201 | my %hash; | |
2202 | ||
2203 | # If there are no groups we are finished here. | |
9aadc465 | 2204 | if (!keys %customlocationgrp) { |
4313aa18 SS |
2205 | print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>"; |
2206 | return; | |
2207 | } | |
2208 | ||
2209 | # Put all groups in a hash. | |
9aadc465 SS |
2210 | foreach my $key (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) } |
2211 | sort { ncmp($customlocationgrp{$a}[2],$customlocationgrp{$b}[2]) } keys %customlocationgrp) { | |
2212 | push (@counter,$customlocationgrp{$key}[0]); | |
4313aa18 SS |
2213 | } |
2214 | ||
2215 | # Increase current used key. | |
2216 | foreach my $key1 (@counter) { | |
2217 | $hash{$key1}++ ; | |
2218 | } | |
2219 | ||
2220 | # Sort hash. | |
9aadc465 SS |
2221 | foreach my $key (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) } |
2222 | sort { ncmp($customlocationgrp{$a}[2],$customlocationgrp{$b}[2]) } keys %customlocationgrp) { | |
4313aa18 | 2223 | $count++; |
9aadc465 | 2224 | if ($helper ne $customlocationgrp{$key}[0]) { |
4313aa18 SS |
2225 | $delflag='0'; |
2226 | ||
9aadc465 SS |
2227 | foreach my $key1 (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) } |
2228 | sort { ncmp($customlocationgrp{$a}[2],$customlocationgrp{$b}[2]) } keys %customlocationgrp) { | |
4313aa18 | 2229 | |
9aadc465 | 2230 | if ($customlocationgrp{$key}[0] eq $customlocationgrp{$key1}[0]) |
4313aa18 SS |
2231 | { |
2232 | $delflag++; | |
2233 | } | |
2234 | if($delflag > 1){ | |
2235 | last; | |
2236 | } | |
2237 | } | |
2238 | ||
2239 | $number=1; | |
2240 | ||
2241 | # Groupname. | |
9aadc465 | 2242 | $grpname=$customlocationgrp{$key}[0]; |
4313aa18 SS |
2243 | |
2244 | # Group remark. | |
9aadc465 | 2245 | $remark="$customlocationgrp{$key}[1]"; |
4313aa18 SS |
2246 | |
2247 | # Country code. | |
9aadc465 | 2248 | $country_code="$customlocationgrp{$key}[2]"; |
4313aa18 SS |
2249 | |
2250 | if ($count gt 1){ | |
2251 | print"</table>"; | |
2252 | $count=1; | |
2253 | } | |
2254 | ||
2255 | # Display groups header. | |
2256 | print "<br><b><u>$grpname</u></b> \n"; | |
2257 | print "<b>$Lang::tr{'remark'}:</b>  $remark  \n" if ($remark ne ''); | |
2258 | ||
2259 | # Get group count. | |
9aadc465 SS |
2260 | my $locationgrpcount=&getlocationcount($grpname); |
2261 | print "<b>$Lang::tr{'used'}:</b> $locationgrpcount x"; | |
4313aa18 SS |
2262 | |
2263 | # Only display delete icon, if the group is not used by a firewall rule. | |
9aadc465 | 2264 | if($locationgrpcount == '0') { |
4313aa18 SS |
2265 | print"<form method='post' style='display:inline'>\n"; |
2266 | print"<input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' />\n"; | |
2267 | print"<input type='hidden' name='grp_name' value='$grpname' >\n"; | |
9aadc465 | 2268 | print"<input type='hidden' name='ACTION' value='dellocationgrp'>\n"; |
4313aa18 SS |
2269 | print"</form>"; |
2270 | } | |
2271 | ||
2272 | # Icon for group editing. | |
2273 | print <<END; | |
2274 | <form method='post' style='display:inline'> | |
2275 | <input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' align='right'/> | |
2276 | <input type='hidden' name='grp_name' value='$grpname' > | |
2277 | <input type='hidden' name='remark' value='$remark' > | |
9aadc465 | 2278 | <input type='hidden' name='ACTION' value='editlocationgrp'> |
4313aa18 SS |
2279 | </form> |
2280 | ||
2281 | <table width='100%' cellspacing='0' class='tbl'> | |
2282 | END | |
2283 | # Display headlines if the group contains any entries. | |
2284 | if ($country_code ne "none") { | |
2285 | print <<END; | |
2286 | <tr> | |
2287 | <td width='10%' align='center'> | |
2288 | <b>$Lang::tr{'flag'}</b> | |
2289 | </td> | |
2290 | ||
2291 | <td width='10%'align='center'> | |
2292 | <b>$Lang::tr{'countrycode'}</b> | |
2293 | </td> | |
2294 | ||
2295 | <td width='70%'align='left'> | |
2296 | <b>$Lang::tr{'country'}</b> | |
2297 | </td> | |
2298 | ||
2299 | <td width='10%' align='right'></td> | |
2300 | </tr> | |
2301 | END | |
2302 | } | |
2303 | } | |
2304 | ||
2305 | # Check if our group contains any entries. | |
2306 | if ($country_code eq "none") { | |
2307 | print "<tr><td>$Lang::tr{'fwhost err emptytable'}</td></tr>\n"; | |
2308 | } else { | |
2309 | # Check if we are currently editing a group and assign column backgound colors. | |
2310 | my $col=''; | |
9aadc465 SS |
2311 | if ( ($fwhostsettings{'ACTION'} eq 'editlocationgrp' || $fwhostsettings{'update'} ne '') |
2312 | && $fwhostsettings{'grp_name'} eq $customlocationgrp{$key}[0]) { | |
4313aa18 SS |
2313 | $col="bgcolor='${Header::colouryellow}'"; |
2314 | } elsif ($count %2 == 0){ | |
2315 | $col="bgcolor='$color{'color20'}'"; | |
2316 | } else { | |
2317 | $col="bgcolor='$color{'color22'}'"; | |
2318 | } | |
2319 | ||
2320 | # Get country flag. | |
9aadc465 | 2321 | my $icon = &Location::Functions::get_flag_icon($customlocationgrp{$key}[2]); |
4313aa18 SS |
2322 | |
2323 | # Print column with flag icon. | |
2324 | my $col_content; | |
2325 | if ($icon) { | |
9aadc465 | 2326 | $col_content = "<img src='$icon' alt='$customlocationgrp{$key}[2]' title='$customlocationgrp{$key}[2]'>"; |
4313aa18 SS |
2327 | } else { |
2328 | $col_content = "<b>N/A</b>"; | |
2329 | } | |
2330 | ||
2331 | print "<td align='center' $col>$col_content</td>\n"; | |
2332 | ||
2333 | # Print column with country code. | |
9aadc465 | 2334 | print "<td align='center' $col>$customlocationgrp{$key}[2]</td>\n"; |
4313aa18 SS |
2335 | |
2336 | # Print column with full country name. | |
9aadc465 | 2337 | my $country_name = &Location::Functions::get_full_country_name($customlocationgrp{$key}[2]); |
4313aa18 SS |
2338 | print "<td align='left' $col>$country_name</td>\n"; |
2339 | ||
2340 | # Generate from for removing entries from a group. | |
2341 | print "<td align='right' width='1%' $col><form method='post'>\n"; | |
2342 | ||
2343 | if ($delflag > 0){ | |
2344 | print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}'/>\n"; | |
2345 | ||
2346 | # Check if this group only has a single entry. | |
2347 | foreach my $key2 (keys %hash) { | |
9aadc465 | 2348 | if ($hash{$key2}<2 && $key2 eq $customlocationgrp{$key}[0]){ |
4313aa18 SS |
2349 | print "<input type='hidden' name='last' value='on'>" ; |
2350 | } | |
2351 | } | |
2352 | } | |
2353 | ||
9aadc465 | 2354 | print "<input type='hidden' name='ACTION' value='deletelocationgrpentry'>\n"; |
4313aa18 | 2355 | print "<input type='hidden' name='update' value='$fwhostsettings{'update'}'>\n"; |
9aadc465 | 2356 | print "<input type='hidden' name='delentry' value='$grpname,$remark,$customlocationgrp{$key}[2],$customlocationgrp{$key}[3]'>\n"; |
4313aa18 SS |
2357 | print "</form>\n"; |
2358 | print "</td>\n"; | |
2359 | print "</tr>\n"; | |
2360 | } | |
2361 | ||
9aadc465 | 2362 | $helper=$customlocationgrp{$key}[0]; |
4313aa18 SS |
2363 | $number++; |
2364 | } | |
2365 | ||
2366 | print"</table>\n"; | |
2367 | &Header::closebox(); | |
2a81ab0d AM |
2368 | } |
2369 | sub viewtableservice | |
2370 | { | |
2371 | my $count=0; | |
3a162dc1 | 2372 | my $srvcount; |
2a81ab0d AM |
2373 | if(! -z "$configsrv") |
2374 | { | |
2375 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'}); | |
2376 | &General::readhasharray("$configsrv", \%customservice); | |
3a162dc1 AM |
2377 | &General::readhasharray("$configsrvgrp", \%customservicegrp); |
2378 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
2379 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
2380 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d | 2381 | print<<END; |
902a15be AM |
2382 | <table width='100%' cellspacing='0' class='tbl'> |
2383 | <tr><th align='center'><b>$Lang::tr{'fwhost srv_name'}</b></th><th align='center'><b>$Lang::tr{'fwhost prot'}</b></th><th align='center'><b>$Lang::tr{'fwhost port'}</b></th><th align='center'><b>ICMP</b></th><th align='center'><b>$Lang::tr{'fwhost used'}</b></th><th></th><th width='3%'></th></tr> | |
2a81ab0d | 2384 | END |
902a15be | 2385 | my $col=''; |
eff2dbf8 | 2386 | foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice) |
2a81ab0d AM |
2387 | { |
2388 | $count++; | |
2389 | if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) { | |
902a15be AM |
2390 | print" <tr>"; |
2391 | $col="bgcolor='${Header::colouryellow}'"; | |
2392 | }elsif ($count % 2){ | |
2393 | print" <tr>"; | |
2394 | $col="bgcolor='$color{'color22'}'"; | |
2395 | }else{ | |
2396 | print" <tr>"; | |
2397 | $col="bgcolor='$color{'color20'}'"; | |
2398 | } | |
2a81ab0d | 2399 | print<<END; |
902a15be | 2400 | <td $col>$customservice{$key}[0]</td><td align='center' $col>$customservice{$key}[2]</td><td align='center' $col>$customservice{$key}[1]</td><td align='center' $col> |
2a81ab0d | 2401 | END |
3a162dc1 AM |
2402 | #Neuer count |
2403 | $srvcount=&getsrvcount($customservice{$key}[0]); | |
86a921ee AM |
2404 | if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};} |
2405 | elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];} | |
2a81ab0d | 2406 | print<<END; |
902a15be | 2407 | </td><td align='center' $col>$srvcount x</td> |
f8aa0679 | 2408 | <td width='1%' $col><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /><input type='hidden' name='ACTION' value='editservice' /> |
2a81ab0d AM |
2409 | <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' /> |
2410 | <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' /> | |
2aeb4b25 AM |
2411 | <input type='hidden' name='PROT' value='$customservice{$key}[2]' /> |
2412 | <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td> | |
2a81ab0d | 2413 | END |
3a162dc1 | 2414 | if ($srvcount eq '0') |
2a81ab0d | 2415 | { |
f8aa0679 | 2416 | print"<td width='1%' $col><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><input type='hidden' name='ACTION' value='delservice' /><input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]'></td></tr></form>"; |
2a81ab0d | 2417 | }else{ |
902a15be | 2418 | print"<td $col></td></tr>"; |
2a81ab0d AM |
2419 | } |
2420 | } | |
2421 | print"</table>"; | |
2422 | &Header::closebox(); | |
2423 | } | |
2424 | } | |
2425 | sub viewtableservicegrp | |
2426 | { | |
2427 | my $count=0; | |
2428 | my $grpname; | |
2429 | my $remark; | |
2430 | my $helper; | |
aeefcc9c | 2431 | my $helper1; |
937d4e08 AM |
2432 | my $port; |
2433 | my $protocol; | |
c7043621 | 2434 | my $delflag; |
3a162dc1 | 2435 | my $grpcount=0; |
902a15be | 2436 | my $col=''; |
aeefcc9c AM |
2437 | my $lastentry=0; |
2438 | my @counter; | |
2439 | my %hash; | |
2a81ab0d | 2440 | if (! -z $configsrvgrp){ |
2a81ab0d AM |
2441 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'}); |
2442 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
937d4e08 | 2443 | &General::readhasharray("$configsrv", \%customservice); |
3a162dc1 AM |
2444 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
2445 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
2446 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d | 2447 | my $number= keys %customservicegrp; |
aeefcc9c AM |
2448 | foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){ |
2449 | push (@counter,$customservicegrp{$key}[0]); | |
2450 | } | |
2451 | foreach my $key1 (@counter) { | |
2452 | $hash{$key1}++ ; | |
2453 | } | |
fe2bae3b | 2454 | foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){ |
2a81ab0d AM |
2455 | $count++; |
2456 | if ($helper ne $customservicegrp{$key}[0]){ | |
3a162dc1 AM |
2457 | #Get used groupcounter |
2458 | $grpcount=&getsrvcount($customservicegrp{$key}[0]); | |
d13a9363 | 2459 | $delflag=0; |
eff2dbf8 | 2460 | foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){ |
d13a9363 AM |
2461 | if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0]) |
2462 | { | |
2463 | $delflag++; | |
2464 | } | |
2465 | if($delflag > 1){ | |
2466 | last; | |
2467 | } | |
2468 | } | |
2a81ab0d | 2469 | $grpname=$customservicegrp{$key}[0]; |
6c869961 | 2470 | if ($customservicegrp{$key}[2] eq "none"){ |
aeefcc9c | 2471 | $customservicegrp{$key}[2]=$Lang::tr{'fwhost err emptytable'}; |
0b54aaed AM |
2472 | $port=''; |
2473 | $protocol=''; | |
6c869961 AM |
2474 | } |
2475 | $remark="$customservicegrp{$key}[1]"; | |
aeefcc9c | 2476 | if($count >0){print"</table>";$count=1;} |
2e99ab8b AM |
2477 | print "<br><b><u>$grpname</u></b> "; |
2478 | print "<b>$Lang::tr{'remark'}:</b> $remark " if ($remark ne ''); | |
3a162dc1 AM |
2479 | print " <b>$Lang::tr{'used'}:</b> $grpcount x"; |
2480 | if($grpcount == '0') | |
2a81ab0d | 2481 | { |
f8aa0679 | 2482 | print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='ACTION' value='delservicegrp'></form>"; |
2a81ab0d | 2483 | } |
f8aa0679 | 2484 | print"<form method='post' style='display:inline'><input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='SRVGRP_REMARK' value='$remark' ><input type='hidden' name='ACTION' value='editservicegrp'></form>"; |
902a15be | 2485 | print"<table width='100%' cellspacing='0' class='tbl'><tr><th align='center'><b>Name</b></th><th align='center'><b>$Lang::tr{'port'}</b></th><th align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</th><th></th></tr>"; |
2a81ab0d AM |
2486 | } |
2487 | if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) { | |
902a15be AM |
2488 | print"<tr>"; |
2489 | $col="bgcolor='${Header::colouryellow}'"; | |
6c869961 | 2490 | }elsif ($count %2 == 0){ |
902a15be AM |
2491 | print"<tr>"; |
2492 | $col="bgcolor='$color{'color20'}'"; | |
0f869e32 | 2493 | }else{ |
902a15be AM |
2494 | print"<tr>"; |
2495 | $col="bgcolor='$color{'color22'}'"; | |
0f869e32 | 2496 | } |
aeefcc9c AM |
2497 | #make lines yellow if it is a dummy entry |
2498 | if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost err emptytable'}){ | |
2499 | print"<tr>"; | |
2500 | $col="bgcolor='${Header::colouryellow}'"; | |
2501 | } | |
82b837cf AM |
2502 | #Set fields if we use protocols in servicegroups |
2503 | if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){ | |
2504 | $port='-'; | |
2505 | } | |
2506 | if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";} | |
2507 | if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";} | |
2508 | if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";} | |
2509 | if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";} | |
2510 | if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";} | |
2511 | if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";} | |
902a15be | 2512 | print "<td width='39%' $col>$customservicegrp{$key}[2]</td>"; |
937d4e08 AM |
2513 | foreach my $srv (sort keys %customservice){ |
2514 | if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){ | |
2515 | $protocol=$customservice{$srv}[2]; | |
2516 | $port=$customservice{$srv}[1]; | |
2517 | last; | |
2518 | } | |
2519 | } | |
902a15be | 2520 | print"<td align='center' $col>$port</td><td align='center' $col>$protocol</td><td width='1%' $col><form method='post'>"; |
aeefcc9c AM |
2521 | if ($delflag gt '0'){ |
2522 | if ($customservicegrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){ | |
f8aa0679 | 2523 | print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title=$Lang::tr{'delete'} />"; |
aeefcc9c AM |
2524 | } |
2525 | #check if this group has only one entry | |
2526 | foreach my $key2 (keys %hash) { | |
2527 | if ($hash{$key2}<2 && $key2 eq $customservicegrp{$key}[0]){ | |
2528 | print "<input type='hidden' name='last' value='on'>" ; | |
2529 | } | |
2530 | } | |
0f869e32 | 2531 | } |
82b837cf | 2532 | print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>"; |
fe2bae3b | 2533 | if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){ |
3a162dc1 | 2534 | print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>"; |
82b837cf | 2535 | }else{ |
3a162dc1 | 2536 | print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>"; |
82b837cf | 2537 | } |
0f869e32 | 2538 | $helper=$customservicegrp{$key}[0]; |
2a81ab0d AM |
2539 | } |
2540 | print"</table>"; | |
2541 | &Header::closebox(); | |
2542 | } | |
2543 | } | |
2544 | # Check | |
2545 | sub checkname | |
2546 | { | |
2547 | my %hash=%{(shift)}; | |
2548 | foreach my $key (keys %hash) { | |
2549 | if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){ | |
2550 | return 0; | |
2551 | } | |
2552 | } | |
2553 | return 1; | |
66c36198 | 2554 | |
2a81ab0d | 2555 | } |
f195a8d7 AM |
2556 | sub checkgroup |
2557 | { | |
40962f97 | 2558 | &General::readhasharray("$configgrp", \%customgrp ); |
f195a8d7 | 2559 | my $name=shift; |
3a162dc1 AM |
2560 | foreach my $key (keys %customservicegrp) { |
2561 | if($customservicegrp{$key}[0] eq $name){ | |
2562 | return 0; | |
2563 | } | |
2564 | } | |
2565 | return 1; | |
2566 | } | |
2567 | sub checkservice | |
2568 | { | |
2569 | &General::readhasharray("$configsrv", \%customservice ); | |
2570 | my $name=shift; | |
2571 | foreach my $key (keys %customservice) { | |
2572 | if($customservice{$key}[0] eq $name){ | |
f195a8d7 AM |
2573 | return 0; |
2574 | } | |
2575 | } | |
2576 | return 1; | |
2577 | } | |
2a81ab0d AM |
2578 | sub checkip |
2579 | { | |
66c36198 | 2580 | |
2a81ab0d AM |
2581 | my %hash=%{(shift)}; |
2582 | my $a=shift; | |
2583 | foreach my $key (keys %hash) { | |
2584 | if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){ | |
2585 | return 0; | |
2586 | } | |
2587 | } | |
2588 | return 1; | |
2589 | } | |
2a81ab0d AM |
2590 | sub checkservicegroup |
2591 | { | |
2592 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
2a81ab0d | 2593 | #check name |
7772ae73 | 2594 | if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'})) |
2a81ab0d AM |
2595 | { |
2596 | $errormessage.=$Lang::tr{'fwhost err name'}."<br>"; | |
2597 | return $errormessage; | |
2598 | } | |
2a81ab0d AM |
2599 | #check empty selectbox |
2600 | if (keys %customservice lt 1) | |
2601 | { | |
2602 | $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
2603 | } | |
2a81ab0d AM |
2604 | #check if name already exists |
2605 | if ($fwhostsettings{'updatesrvgrp'} ne 'on'){ | |
2606 | foreach my $key (keys %customservicegrp) { | |
2607 | if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){ | |
2608 | $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>"; | |
66c36198 | 2609 | |
2a81ab0d AM |
2610 | } |
2611 | } | |
2612 | } | |
2613 | #check if service already exists in group | |
2614 | foreach my $key (keys %customservicegrp) { | |
13e5dda4 AM |
2615 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){ |
2616 | $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>"; | |
2a81ab0d | 2617 | } |
13e5dda4 | 2618 | } |
2a81ab0d AM |
2619 | return $errormessage; |
2620 | } | |
49da7d79 AM |
2621 | sub checkrulereload |
2622 | { | |
2623 | my $search=shift; | |
2624 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
2625 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
2626 | &General::readhasharray("$fwconfigout", \%fwout); | |
2627 | ||
2628 | #check if service or servicegroup is used in rules | |
2629 | foreach my $key (keys %fwfwd){ | |
2630 | if($search eq $fwfwd{$key}[15]){ | |
2631 | &General::firewall_config_changed(); | |
2632 | return; | |
2633 | } | |
2634 | } | |
2635 | foreach my $key (keys %fwinp){ | |
2636 | if($search eq $fwinp{$key}[15]){ | |
2637 | &General::firewall_config_changed(); | |
2638 | return; | |
2639 | } | |
2640 | } | |
2641 | foreach my $key (keys %fwout){ | |
2642 | if($search eq $fwout{$key}[15]){ | |
2643 | &General::firewall_config_changed(); | |
2644 | return; | |
2645 | } | |
2646 | } | |
2647 | } | |
2a81ab0d AM |
2648 | sub error |
2649 | { | |
2650 | if ($errormessage) { | |
2651 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
2652 | print "<class name='base'>$errormessage\n"; | |
2653 | print " </class>\n"; | |
2654 | &Header::closebox(); | |
2655 | } | |
2656 | } | |
2657 | sub hint | |
2658 | { | |
2659 | if ($hint) { | |
2660 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'}); | |
2661 | print "<class name='base'>$hint\n"; | |
2662 | print " </class>\n"; | |
2663 | &Header::closebox(); | |
2664 | } | |
2665 | } | |
2666 | sub get_name | |
2667 | { | |
2668 | my $val=shift; | |
2669 | &General::setup_default_networks(\%defaultNetworks); | |
2670 | foreach my $network (sort keys %defaultNetworks) | |
2671 | { | |
2672 | return "$network" if ($val eq $defaultNetworks{$network}{'NAME'}); | |
66c36198 | 2673 | } |
2a81ab0d | 2674 | } |
484269ce AM |
2675 | sub gethostcount |
2676 | { | |
2677 | my $searchstring=shift; | |
2678 | my $srvcounter=0; | |
2679 | #Count services used in servicegroups | |
2680 | foreach my $key (keys %customgrp) { | |
2681 | if($customgrp{$key}[2] eq $searchstring){ | |
2682 | $srvcounter++; | |
2683 | } | |
2684 | } | |
2685 | #Count services used in firewall - config | |
2686 | foreach my $key1 (keys %fwfwd) { | |
2687 | if($fwfwd{$key1}[4] eq $searchstring){ | |
2688 | $srvcounter++; | |
2689 | } | |
2690 | if($fwfwd{$key1}[6] eq $searchstring){ | |
2691 | $srvcounter++; | |
2692 | } | |
2693 | } | |
2694 | #Count services used in firewall - input | |
2695 | foreach my $key2 (keys %fwinp) { | |
2696 | if($fwinp{$key2}[4] eq $searchstring){ | |
2697 | $srvcounter++; | |
2698 | } | |
2699 | if($fwinp{$key2}[6] eq $searchstring){ | |
2700 | $srvcounter++; | |
2701 | } | |
2702 | } | |
2703 | #Count services used in firewall - outgoing | |
2704 | foreach my $key3 (keys %fwout) { | |
2705 | if($fwout{$key3}[4] eq $searchstring){ | |
2706 | $srvcounter++; | |
2707 | } | |
2708 | if($fwout{$key3}[6] eq $searchstring){ | |
2709 | $srvcounter++; | |
2710 | } | |
2711 | } | |
2712 | return $srvcounter; | |
2713 | } | |
9aadc465 | 2714 | sub getlocationcount |
4313aa18 SS |
2715 | { |
2716 | my $groupname=shift; | |
2717 | my $counter=0; | |
2718 | ||
9aadc465 | 2719 | # Location groups are stored as "group:groupname" in the |
4313aa18 SS |
2720 | # firewall settings files. |
2721 | my $searchstring = join(':', "group",$groupname); | |
2722 | ||
2723 | # Count services used in firewall - forward | |
2724 | foreach my $key1 (keys %fwfwd) { | |
2725 | if($fwfwd{$key1}[4] eq $searchstring){ | |
2726 | $counter++; | |
2727 | } | |
2728 | if($fwfwd{$key1}[6] eq $searchstring){ | |
2729 | $counter++; | |
2730 | } | |
2731 | } | |
2732 | #Count services used in firewall - input | |
2733 | foreach my $key2 (keys %fwinp) { | |
2734 | if($fwinp{$key2}[4] eq $searchstring){ | |
2735 | $counter++; | |
2736 | } | |
2737 | if($fwinp{$key2}[6] eq $searchstring){ | |
2738 | $counter++; | |
2739 | } | |
2740 | } | |
2741 | #Count services used in firewall - outgoing | |
2742 | foreach my $key3 (keys %fwout) { | |
2743 | if($fwout{$key3}[4] eq $searchstring){ | |
2744 | $counter++; | |
2745 | } | |
2746 | if($fwout{$key3}[6] eq $searchstring){ | |
2747 | $counter++; | |
2748 | } | |
2749 | } | |
2750 | return $counter; | |
2751 | } | |
484269ce AM |
2752 | sub getnetcount |
2753 | { | |
2754 | my $searchstring=shift; | |
2755 | my $srvcounter=0; | |
2756 | #Count services used in servicegroups | |
2757 | foreach my $key (keys %customgrp) { | |
2758 | if($customgrp{$key}[2] eq $searchstring){ | |
2759 | $srvcounter++; | |
2760 | } | |
2761 | } | |
2762 | #Count services used in firewall - config | |
2763 | foreach my $key1 (keys %fwfwd) { | |
2764 | if($fwfwd{$key1}[4] eq $searchstring){ | |
2765 | $srvcounter++; | |
2766 | } | |
2767 | if($fwfwd{$key1}[6] eq $searchstring){ | |
2768 | $srvcounter++; | |
2769 | } | |
2770 | } | |
2771 | #Count services used in firewall - input | |
2772 | foreach my $key2 (keys %fwinp) { | |
2773 | if($fwinp{$key2}[4] eq $searchstring){ | |
2774 | $srvcounter++; | |
2775 | } | |
2776 | if($fwinp{$key2}[6] eq $searchstring){ | |
2777 | $srvcounter++; | |
2778 | } | |
2779 | } | |
2780 | #Count services used in firewall - outgoing | |
2781 | foreach my $key3 (keys %fwout) { | |
2782 | if($fwout{$key3}[4] eq $searchstring){ | |
2783 | $srvcounter++; | |
2784 | } | |
2785 | if($fwout{$key3}[6] eq $searchstring){ | |
2786 | $srvcounter++; | |
2787 | } | |
2788 | } | |
2789 | return $srvcounter; | |
2790 | } | |
3a162dc1 AM |
2791 | sub getsrvcount |
2792 | { | |
2793 | my $searchstring=shift; | |
2794 | my $srvcounter=0; | |
2795 | #Count services used in servicegroups | |
2796 | foreach my $key (keys %customservicegrp) { | |
2797 | if($customservicegrp{$key}[2] eq $searchstring){ | |
2798 | $srvcounter++; | |
2799 | } | |
2800 | } | |
2801 | #Count services used in firewall - config | |
2802 | foreach my $key1 (keys %fwfwd) { | |
2803 | if($fwfwd{$key1}[15] eq $searchstring){ | |
2804 | $srvcounter++; | |
2805 | } | |
2806 | } | |
2807 | #Count services used in firewall - input | |
2808 | foreach my $key2 (keys %fwinp) { | |
2809 | if($fwinp{$key2}[15] eq $searchstring){ | |
2810 | $srvcounter++; | |
2811 | } | |
2812 | } | |
2813 | #Count services used in firewall - outgoing | |
2814 | foreach my $key3 (keys %fwout) { | |
2815 | if($fwout{$key3}[15] eq $searchstring){ | |
2816 | $srvcounter++; | |
2817 | } | |
2818 | } | |
2819 | return $srvcounter; | |
2820 | } | |
2a81ab0d AM |
2821 | sub deletefromgrp |
2822 | { | |
2823 | my $target=shift; | |
2824 | my $config=shift; | |
2825 | my %hash=(); | |
2826 | &General::readhasharray("$config",\%hash); | |
2827 | foreach my $key (keys %hash) { | |
2a81ab0d | 2828 | if($hash{$key}[2] eq $target){ |
2a81ab0d | 2829 | delete $hash{$key}; |
2a81ab0d AM |
2830 | } |
2831 | } | |
2832 | &General::writehasharray("$config",\%hash); | |
66c36198 | 2833 | |
2a81ab0d AM |
2834 | } |
2835 | sub plausicheck | |
2836 | { | |
2a81ab0d AM |
2837 | my $edit=shift; |
2838 | #check hostname | |
d0815ce4 | 2839 | if (!&validhostname($fwhostsettings{'HOSTNAME'})) |
2a81ab0d AM |
2840 | { |
2841 | $errormessage=$errormessage.$Lang::tr{'fwhost err name'}; | |
2842 | $fwhostsettings{'BLK_IP'}='readonly'; | |
2843 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
2844 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2845 | } | |
2846 | #check if name collides with CCD Netname | |
2a81ab0d AM |
2847 | &General::readhasharray("$configccdnet", \%ccdnet); |
2848 | foreach my $key (keys %ccdnet) { | |
2849 | if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){ | |
2850 | $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};; | |
2851 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
2852 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2853 | last; | |
2854 | } | |
2855 | } | |
2a81ab0d AM |
2856 | #check if IP collides with CCD NetIP |
2857 | if ($fwhostsettings{'type'} ne 'mac'){ | |
2858 | &General::readhasharray("$configccdnet", \%ccdnet); | |
2859 | foreach my $key (keys %ccdnet) { | |
2860 | my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'}; | |
2861 | if($ccdnet{$key}[1] eq $test){ | |
2862 | $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'}; | |
2863 | $fwhostsettings{'IP'} = $fwhostsettings{'orgip'}; | |
2864 | $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'}; | |
2865 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2866 | last; | |
2867 | } | |
2868 | } | |
2869 | } | |
2a81ab0d AM |
2870 | #check if name collides with CCD Hostname |
2871 | &General::readhasharray("$configccdhost", \%ccdhost); | |
2872 | foreach my $key (keys %ccdhost) { | |
2873 | my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]); | |
2874 | if($ip eq $fwhostsettings{'IP'}){ | |
2875 | $errormessage=$Lang::tr{'fwhost err isccdiphost'}; | |
2876 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2877 | last; | |
2878 | } | |
2879 | } | |
2880 | #check if IP collides with CCD HostIP (only hosts) | |
2881 | if ($edit eq 'edithost') | |
2882 | { | |
2883 | foreach my $key (keys %ccdhost) { | |
2884 | if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){ | |
2885 | $errormessage=$Lang::tr{'fwhost err isccdhost'}; | |
2886 | $fwhostsettings{'IP'} = $fwhostsettings{'orgname'}; | |
2887 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2888 | last; | |
2889 | } | |
2890 | } | |
2891 | } | |
2892 | #check if network with this name already exists | |
2893 | &General::readhasharray("$confignet", \%customnetwork); | |
2894 | if (!&checkname(\%customnetwork)) | |
2895 | { | |
2896 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'}; | |
2897 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
2898 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
66c36198 PM |
2899 | } |
2900 | #check if network ip already exists | |
2a81ab0d AM |
2901 | if (!&checkip(\%customnetwork,1)) |
2902 | { | |
2903 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'}; | |
2904 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
66c36198 | 2905 | } |
2a81ab0d AM |
2906 | #check if host with this name already exists |
2907 | &General::readhasharray("$confighost", \%customhost); | |
2908 | if (!&checkname(\%customhost)) | |
2909 | { | |
0013abb0 | 2910 | $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'}; |
2a81ab0d | 2911 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; |
ed73b87e | 2912 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} |
2a81ab0d AM |
2913 | } |
2914 | #check if host with this ip already exists | |
2915 | if (!&checkip(\%customhost,2)) | |
2916 | { | |
2917 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'}; | |
2a81ab0d | 2918 | } |
2a81ab0d AM |
2919 | return; |
2920 | } | |
2921 | sub getipforgroup | |
2922 | { | |
2923 | my $name=$_[0], | |
2924 | my $type=$_[1]; | |
2925 | my $value; | |
66c36198 | 2926 | |
2a81ab0d AM |
2927 | #get address from IPSEC NETWORK |
2928 | if ($type eq 'IpSec Network'){ | |
2929 | foreach my $key (keys %ipsecconf) { | |
2930 | if ($ipsecconf{$key}[1] eq $name){ | |
6d92ee11 AM |
2931 | if ($ipsecconf{$key}[11] =~ /\|/) { |
2932 | my $string; | |
2933 | my @parts = split /\|/ , $ipsecconf{$key}[11]; | |
2934 | foreach my $key1 (@parts){ | |
2935 | my ($val1,$val2) = split (/\//, $key1); | |
2936 | my $val3 = &Network::convert_netmask2prefix($val2) || $val2; | |
2937 | $string .= "$val1/$val3<br>"; | |
2938 | } | |
2939 | return $string; | |
2940 | }else{ | |
2941 | return $ipsecconf{$key}[11]; | |
2942 | } | |
2943 | }else{ | |
2944 | if ($name =~ /\|/) { | |
2945 | my ($a,$b) = split /\|/, $name; | |
2946 | return $b; | |
2947 | } | |
2a81ab0d AM |
2948 | } |
2949 | } | |
2950 | &deletefromgrp($name,$configgrp); | |
2951 | } | |
66c36198 | 2952 | |
2a81ab0d AM |
2953 | #get address from IPSEC HOST |
2954 | if ($type eq 'IpSec Host'){ | |
2955 | foreach my $key (keys %ipsecconf) { | |
2956 | if ($ipsecconf{$key}[1] eq $name){ | |
2957 | return $ipsecconf{$key}[10]; | |
2958 | } | |
2959 | } | |
2960 | &deletefromgrp($name,$configgrp); | |
2961 | } | |
66c36198 | 2962 | |
2a81ab0d AM |
2963 | #get address from ovpn ccd Net-2-Net |
2964 | if ($type eq 'OpenVPN N-2-N'){ | |
2965 | foreach my $key (keys %ccdhost) { | |
2966 | if($ccdhost{$key}[1] eq $name){ | |
2967 | my ($a,$b) = split ("/",$ccdhost{$key}[11]); | |
6d92ee11 | 2968 | $b=&Network::convert_netmask2prefix($b) || ($b); |
2a81ab0d AM |
2969 | return "$a/$b"; |
2970 | } | |
2971 | } | |
2972 | &deletefromgrp($name,$configgrp); | |
2973 | } | |
66c36198 | 2974 | |
2a81ab0d AM |
2975 | #get address from ovpn ccd static host |
2976 | if ($type eq 'OpenVPN static host'){ | |
2977 | foreach my $key (keys %ccdhost) { | |
2978 | if($ccdhost{$key}[1] eq $name){ | |
2979 | my ($a,$b) = split (/\//,$ccdhost{$key}[33]); | |
6d92ee11 | 2980 | $b=&Network::convert_netmask2prefix($b) || ($b) ; |
2a81ab0d AM |
2981 | return "$a/$b"; |
2982 | } | |
2983 | } | |
2984 | &deletefromgrp($name,$configgrp); | |
2985 | } | |
66c36198 | 2986 | |
2a81ab0d AM |
2987 | #get address from ovpn ccd static net |
2988 | if ($type eq 'OpenVPN static network'){ | |
2989 | foreach my $key (keys %ccdnet) { | |
2990 | if ($ccdnet{$key}[0] eq $name){ | |
2991 | my ($a,$b) = split (/\//,$ccdnet{$key}[1]); | |
6d92ee11 | 2992 | $b=&Network::convert_netmask2prefix($b) || ($b); |
2a81ab0d AM |
2993 | return "$a/$b"; |
2994 | } | |
2995 | } | |
2996 | } | |
66c36198 | 2997 | |
2a81ab0d AM |
2998 | #check custom addresses |
2999 | if ($type eq 'Custom Host'){ | |
3000 | foreach my $key (keys %customhost) { | |
3001 | if ($customhost{$key}[0] eq $name){ | |
f1934a05 AM |
3002 | my ($ip,$sub) = split("/",$customhost{$key}[2]); |
3003 | return $ip; | |
2a81ab0d AM |
3004 | } |
3005 | } | |
3006 | } | |
66c36198 | 3007 | |
2a81ab0d AM |
3008 | ##check custom networks |
3009 | if ($type eq 'Custom Network'){ | |
3010 | foreach my $key (keys %customnetwork) { | |
3011 | if($customnetwork{$key}[0] eq $name){ | |
6d92ee11 | 3012 | return $customnetwork{$key}[1]."/".&Network::convert_netmask2prefix($customnetwork{$key}[2]) || $customnetwork{$key}[2]; |
2a81ab0d AM |
3013 | } |
3014 | } | |
3015 | } | |
66c36198 | 3016 | |
2a81ab0d AM |
3017 | #check standard networks |
3018 | if ($type eq 'Standard Network'){ | |
3019 | if ($name =~ /OpenVPN/i){ | |
3020 | my %ovpn=(); | |
3021 | &General::readhash("${General::swroot}/ovpn/settings",\%ovpn); | |
3022 | return $ovpn{'DOVPN_SUBNET'}; | |
3023 | } | |
3024 | if ($name eq 'GREEN'){ | |
3025 | my %hash=(); | |
3026 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
6d92ee11 | 3027 | return $hash{'GREEN_NETADDRESS'}."/".&Network::convert_netmask2prefix($hash{'GREEN_NETMASK'}) || $hash{'GREEN_NETMASK'}; |
2a81ab0d AM |
3028 | } |
3029 | if ($name eq 'BLUE'){ | |
3030 | my %hash=(); | |
3031 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
6d92ee11 | 3032 | return $hash{'BLUE_NETADDRESS'}."/".&Network::convert_netmask2prefix($hash{'BLUE_NETMASK'}) || $hash{'BLUE_NETMASK'}; |
2a81ab0d AM |
3033 | } |
3034 | if ($name eq 'ORANGE'){ | |
3035 | my %hash=(); | |
3036 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
6d92ee11 | 3037 | return $hash{'ORANGE_NETADDRESS'}."/".&Network::convert_netmask2prefix($hash{'ORANGE_NETMASK'}) || $hash{'ORANGE_NETMASK'}; |
2a81ab0d AM |
3038 | } |
3039 | if ($name eq 'ALL'){ | |
6d92ee11 | 3040 | return "0.0.0.0/0"; |
2a81ab0d AM |
3041 | } |
3042 | if ($name =~ /IPsec/i){ | |
3043 | my %hash=(); | |
3044 | &General::readhash("${General::swroot}/vpn/settings",\%hash); | |
3045 | return $hash{'RW_NET'}; | |
3046 | } | |
48f07c19 AM |
3047 | if ($name eq 'RED'){ |
3048 | return "0.0.0.0/0"; | |
3049 | } | |
2a81ab0d AM |
3050 | } |
3051 | } | |
fe2bae3b AM |
3052 | sub decrease |
3053 | { | |
2a81ab0d AM |
3054 | my $grp=$_[0]; |
3055 | &General::readhasharray("$confignet", \%customnetwork); | |
3056 | &General::readhasharray("$confighost", \%customhost); | |
3057 | foreach my $key (sort keys %customgrp ){ | |
3058 | if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){ | |
3059 | foreach my $key1 (sort keys %customnetwork){ | |
3060 | if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ | |
8013bd0a | 3061 | $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1; |
2a81ab0d AM |
3062 | last; |
3063 | } | |
3064 | } | |
3065 | } | |
66c36198 | 3066 | |
2a81ab0d AM |
3067 | if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){ |
3068 | foreach my $key2 (sort keys %customhost){ | |
3069 | if ($customhost{$key2}[0] eq $customgrp{$key}[2]){ | |
8013bd0a | 3070 | $customhost{$key2}[4]=$customhost{$key2}[4]-1; |
2a81ab0d AM |
3071 | last; |
3072 | } | |
3073 | } | |
66c36198 | 3074 | |
2a81ab0d AM |
3075 | } |
3076 | } | |
3077 | &General::writehasharray("$confignet", \%customnetwork); | |
3078 | &General::writehasharray("$confighost", \%customhost); | |
3079 | } | |
3080 | sub decreaseservice | |
3081 | { | |
3082 | my $grp=$_[0]; | |
3083 | &General::readhasharray("$configsrv", \%customservice); | |
3084 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
66c36198 | 3085 | |
2a81ab0d AM |
3086 | foreach my $key (sort keys %customservicegrp){ |
3087 | if ($customservicegrp{$key}[0] eq $grp ){ | |
3088 | foreach my $key2 (sort keys %customservice){ | |
3089 | if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){ | |
3090 | $customservice{$key2}[4]--; | |
3091 | } | |
3092 | } | |
3093 | } | |
3094 | } | |
3095 | &General::writehasharray("$configsrv", \%customservice); | |
66c36198 | 3096 | |
2a81ab0d | 3097 | } |
a8b113e7 AM |
3098 | sub changenameinfw |
3099 | { | |
3100 | my $old=shift; | |
3101 | my $new=shift; | |
3102 | my $fld=shift; | |
40a930bd PM |
3103 | my $type=shift; |
3104 | ||
9aadc465 | 3105 | if ($type eq 'location'){ |
40a930bd PM |
3106 | $old="group:$old"; |
3107 | $new="group:$new"; | |
3108 | } | |
a8b113e7 AM |
3109 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
3110 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
3111 | &General::readhasharray("$fwconfigout", \%fwout); | |
3112 | #Rename group in Firewall-CONFIG | |
3113 | foreach my $key1 (keys %fwfwd) { | |
3114 | if($fwfwd{$key1}[$fld] eq $old){ | |
3115 | $fwfwd{$key1}[$fld]=$new; | |
3116 | } | |
3117 | } | |
3118 | &General::writehasharray("$fwconfigfwd", \%fwfwd ); | |
3119 | #Rename group in Firewall-INPUT | |
3120 | foreach my $key2 (keys %fwinp) { | |
3121 | if($fwinp{$key2}[$fld] eq $old){ | |
3122 | $fwinp{$key2}[$fld]=$new; | |
3123 | } | |
3124 | } | |
3125 | &General::writehasharray("$fwconfiginp", \%fwinp ); | |
3126 | #Rename group in Firewall-OUTGOING | |
3127 | foreach my $key3 (keys %fwout) { | |
3128 | if($fwout{$key3}[$fld] eq $old){ | |
3129 | $fwout{$key3}[$fld]=$new; | |
3130 | } | |
3131 | } | |
3132 | &General::writehasharray("$fwconfigout", \%fwout ); | |
3133 | } | |
2a81ab0d AM |
3134 | sub checkports |
3135 | { | |
66c36198 | 3136 | |
2a81ab0d AM |
3137 | my %hash=%{(shift)}; |
3138 | #check empty fields | |
3139 | if ($fwhostsettings{'SRV_NAME'} eq '' ){ | |
3140 | $errormessage=$Lang::tr{'fwhost err name1'}; | |
3141 | } | |
3142 | if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){ | |
3143 | $errormessage=$Lang::tr{'fwhost err port'}; | |
3144 | } | |
3145 | #check valid name | |
7772ae73 | 3146 | if (! &validhostname($fwhostsettings{'SRV_NAME'})){ |
2a81ab0d AM |
3147 | $errormessage="<br>".$Lang::tr{'fwhost err name'}; |
3148 | } | |
3149 | #change dashes with : | |
3150 | $fwhostsettings{'SRV_PORT'}=~ tr/-/:/; | |
66c36198 | 3151 | |
2a81ab0d AM |
3152 | if ($fwhostsettings{'SRV_PORT'} eq "*") { |
3153 | $fwhostsettings{'SRV_PORT'} = "1:65535"; | |
3154 | } | |
3155 | if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) { | |
3156 | $fwhostsettings{'SRV_PORT'} = "1:$2"; | |
3157 | } | |
3158 | if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) { | |
3159 | $fwhostsettings{'SRV_PORT'} = "$1:65535"; | |
3160 | } | |
3161 | if($fwhostsettings{'PROT'} ne 'ICMP'){ | |
3162 | $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src'); | |
3163 | } | |
3164 | # a new service has to have a different name | |
3165 | foreach my $key (keys %hash){ | |
3166 | if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){ | |
3167 | $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'}; | |
3168 | last; | |
3169 | } | |
3170 | } | |
3171 | return $errormessage; | |
3172 | } | |
3173 | sub validhostname | |
3174 | { | |
3175 | # Checks a hostname against RFC1035 | |
3176 | my $hostname = $_[0]; | |
3177 | ||
3178 | # Each part should be at least two characters in length | |
3179 | # but no more than 63 characters | |
3180 | if (length ($hostname) < 1 || length ($hostname) > 63) { | |
3181 | return 0;} | |
3182 | # Only valid characters are a-z, A-Z, 0-9 and - | |
d0815ce4 | 3183 | if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) { |
2a81ab0d AM |
3184 | return 0;} |
3185 | # First character can only be a letter or a digit | |
3186 | if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) { | |
3187 | return 0;} | |
3188 | # Last character can only be a letter or a digit | |
7772ae73 | 3189 | if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) { |
2a81ab0d AM |
3190 | return 0;} |
3191 | return 1; | |
3192 | } | |
6c869961 AM |
3193 | sub validremark |
3194 | { | |
3195 | # Checks a hostname against RFC1035 | |
3196 | my $remark = $_[0]; | |
3197 | # Each part should be at least two characters in length | |
3198 | # but no more than 63 characters | |
3199 | if (length ($remark) < 1 || length ($remark) > 255) { | |
3200 | return 0;} | |
3201 | # Only valid characters are a-z, A-Z, 0-9 and - | |
d928d795 | 3202 | if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) { |
6c869961 AM |
3203 | return 0;} |
3204 | # First character can only be a letter or a digit | |
3205 | if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) { | |
3206 | return 0;} | |
3207 | # Last character can only be a letter or a digit | |
d928d795 | 3208 | if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) { |
6c869961 AM |
3209 | return 0;} |
3210 | return 1; | |
3211 | } | |
2a81ab0d AM |
3212 | &Header::closebigbox(); |
3213 | &Header::closepage(); |