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