]>
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 | |
24 | use warnings; | |
eff2dbf8 | 25 | use Sort::Naturally; |
2a81ab0d AM |
26 | use CGI::Carp 'fatalsToBrowser'; |
27 | no warnings 'uninitialized'; | |
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
31 | ||
32 | my %fwhostsettings=(); | |
33 | my %customnetwork=(); | |
34 | my %customhost=(); | |
35 | my %customgrp=(); | |
36 | my %customservice=(); | |
37 | my %customservicegrp=(); | |
38 | my %ccdnet=(); | |
39 | my %ccdhost=(); | |
40 | my %ipsecconf=(); | |
41 | my %icmptypes=(); | |
42 | my %color=(); | |
43 | my %defaultNetworks=(); | |
44 | my %mainsettings=(); | |
45 | my %ownnet=(); | |
46 | my %ipsecsettings=(); | |
62fc8511 AM |
47 | my %fwfwd=(); |
48 | my %fwinp=(); | |
3a162dc1 | 49 | my %fwout=(); |
b119578f | 50 | my %ovpnsettings=(); |
2aeb4b25 | 51 | |
2a81ab0d AM |
52 | |
53 | my $errormessage; | |
54 | my $hint; | |
55 | my $update=0; | |
56 | my $confignet = "${General::swroot}/fwhosts/customnetworks"; | |
57 | my $confighost = "${General::swroot}/fwhosts/customhosts"; | |
58 | my $configgrp = "${General::swroot}/fwhosts/customgroups"; | |
59 | my $configccdnet = "${General::swroot}/ovpn/ccd.conf"; | |
60 | my $configccdhost = "${General::swroot}/ovpn/ovpnconfig"; | |
61 | my $configipsec = "${General::swroot}/vpn/config"; | |
62 | my $configsrv = "${General::swroot}/fwhosts/customservices"; | |
63 | my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp"; | |
6d8eb5de AM |
64 | my $fwconfigfwd = "${General::swroot}/firewall/config"; |
65 | my $fwconfiginp = "${General::swroot}/firewall/input"; | |
3a162dc1 | 66 | my $fwconfigout = "${General::swroot}/firewall/outgoing"; |
b119578f AM |
67 | my $configovpn = "${General::swroot}/ovpn/settings"; |
68 | my $tdcolor=''; | |
b119578f | 69 | my $configipsecrw = "${General::swroot}/vpn/settings"; |
2a81ab0d AM |
70 | |
71 | unless (-e $confignet) { system("touch $confignet"); } | |
72 | unless (-e $confighost) { system("touch $confighost"); } | |
73 | unless (-e $configgrp) { system("touch $configgrp"); } | |
74 | unless (-e $configsrv) { system("touch $configsrv"); } | |
75 | unless (-e $configsrvgrp) { system("touch $configsrvgrp"); } | |
76 | ||
77 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
78 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
79 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
b119578f AM |
80 | &General::readhash("$configovpn", \%ovpnsettings); |
81 | &General::readhasharray("$configipsec", \%ipsecconf); | |
82 | &General::readhash("$configipsecrw", \%ipsecsettings); | |
83 | ||
2a81ab0d AM |
84 | &Header::getcgihash(\%fwhostsettings); |
85 | ||
86 | &Header::showhttpheaders(); | |
87 | &Header::openpage($Lang::tr{'fwhost hosts'}, 1, ''); | |
88 | &Header::openbigbox('100%', 'center'); | |
89 | ||
2e99ab8b AM |
90 | #### JAVA SCRIPT #### |
91 | print<<END; | |
92 | <script> | |
fda8c915 AM |
93 | var PROTOCOLS_WITH_PORTS = ["TCP", "UDP"]; |
94 | var update_protocol = function() { | |
95 | var protocol = \$("#protocol").val(); | |
96 | ||
97 | if (protocol === undefined) | |
98 | return; | |
99 | ||
100 | // Check if we are dealing with a protocol, that knows ports. | |
101 | if (\$.inArray(protocol, PROTOCOLS_WITH_PORTS) >= 0) { | |
102 | \$("#PORT").show(); | |
c9493d6c | 103 | \$("#PROTOKOLL").hide(); |
fda8c915 AM |
104 | } else { |
105 | \$("#PORT").hide(); | |
fda8c915 | 106 | \$("#PROTOKOLL").show(); |
fda8c915 AM |
107 | } |
108 | }; | |
109 | ||
2e99ab8b | 110 | \$(document).ready(function() { |
fda8c915 | 111 | var protocol = \$("#protocol").val(); |
fda8c915 AM |
112 | \$("#protocol").change(update_protocol); |
113 | update_protocol(); | |
2e99ab8b AM |
114 | }); |
115 | </script> | |
116 | END | |
117 | ||
2a81ab0d AM |
118 | ## ACTION #### |
119 | # Update | |
120 | if ($fwhostsettings{'ACTION'} eq 'updatenet' ) | |
121 | { | |
122 | &General::readhasharray("$confignet", \%customnetwork); | |
123 | foreach my $key (keys %customnetwork) | |
124 | { | |
125 | if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}) | |
126 | { | |
127 | $fwhostsettings{'orgname'} = $customnetwork{$key}[0]; | |
128 | $fwhostsettings{'orgip'} = $customnetwork{$key}[1]; | |
129 | $fwhostsettings{'orgsub'} = $customnetwork{$key}[2]; | |
e5a058c1 AM |
130 | $fwhostsettings{'netremark'} = $customnetwork{$key}[3]; |
131 | $fwhostsettings{'count'} = $customnetwork{$key}[4]; | |
2a81ab0d AM |
132 | delete $customnetwork{$key}; |
133 | ||
134 | } | |
135 | } | |
136 | &General::writehasharray("$confignet", \%customnetwork); | |
137 | $fwhostsettings{'actualize'} = 'on'; | |
138 | $fwhostsettings{'ACTION'} = 'savenet'; | |
139 | } | |
140 | if ($fwhostsettings{'ACTION'} eq 'updatehost') | |
141 | { | |
142 | my ($ip,$subnet); | |
143 | &General::readhasharray("$confighost", \%customhost); | |
144 | foreach my $key (keys %customhost) | |
145 | { | |
146 | if($customhost{$key}[0] eq $fwhostsettings{'orgname'}) | |
147 | { | |
2a81ab0d AM |
148 | if ($customhost{$key}[1] eq 'ip'){ |
149 | ($ip,$subnet) = split (/\//,$customhost{$key}[2]); | |
150 | }else{ | |
151 | $ip = $customhost{$key}[2]; | |
152 | } | |
153 | $fwhostsettings{'orgip'} = $ip; | |
e3580608 | 154 | $fwhostsettings{'count'} = $customhost{$key}[4]; |
2a81ab0d | 155 | delete $customhost{$key}; |
5e970723 | 156 | &General::writehasharray("$confighost", \%customhost); |
2a81ab0d AM |
157 | } |
158 | } | |
2a81ab0d | 159 | $fwhostsettings{'actualize'} = 'on'; |
5e970723 | 160 | if($fwhostsettings{'orgip'}){ |
2a81ab0d | 161 | $fwhostsettings{'ACTION'} = 'savehost'; |
5e970723 AM |
162 | }else{ |
163 | $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'}; | |
164 | } | |
2a81ab0d AM |
165 | } |
166 | if ($fwhostsettings{'ACTION'} eq 'updateservice') | |
167 | { | |
168 | my $count=0; | |
169 | my $needrules=0; | |
170 | $errormessage=&checkports(\%customservice); | |
3a162dc1 AM |
171 | if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){ |
172 | $errormessage=$Lang::tr{'fwhost err grpexist'}; | |
173 | } | |
2a81ab0d AM |
174 | if (!$errormessage){ |
175 | &General::readhasharray("$configsrv", \%customservice); | |
176 | foreach my $key (keys %customservice) | |
177 | { | |
178 | if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'}) | |
179 | { | |
2a81ab0d AM |
180 | delete $customservice{$key}; |
181 | &General::writehasharray("$configsrv", \%customservice); | |
182 | last; | |
183 | } | |
184 | } | |
185 | if ($fwhostsettings{'PROT'} ne 'ICMP'){ | |
186 | $fwhostsettings{'ICMP_TYPES'}='BLANK'; | |
187 | } | |
188 | my $key1 = &General::findhasharraykey(\%customservice); | |
2aeb4b25 AM |
189 | #find out short ICMP-TYPE |
190 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
191 | foreach my $key (keys %icmptypes){ | |
192 | if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){ | |
193 | $fwhostsettings{'ICMP_TYPES'}=$icmptypes{$key}[0]; | |
194 | } | |
195 | } | |
2a81ab0d AM |
196 | foreach my $i (0 .. 4) { $customservice{$key1}[$i] = "";} |
197 | $customservice{$key1}[0] = $fwhostsettings{'SRV_NAME'}; | |
198 | $customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'}; | |
199 | $customservice{$key1}[2] = $fwhostsettings{'PROT'}; | |
200 | $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'}; | |
2a81ab0d | 201 | &General::writehasharray("$configsrv", \%customservice); |
ed73b87e | 202 | #check if we need to update firewallrules |
bfee206c AM |
203 | if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){ |
204 | if ( ! -z $fwconfigfwd ){ | |
205 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
206 | foreach my $key (sort keys %fwfwd){ | |
207 | if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){ | |
208 | $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'}; | |
209 | } | |
210 | } | |
211 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
bfee206c AM |
212 | } |
213 | if ( ! -z $fwconfiginp ){ | |
214 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
215 | foreach my $line (sort keys %fwinp){ | |
216 | if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){ | |
217 | $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'}; | |
218 | } | |
219 | } | |
220 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
221 | } | |
3a162dc1 AM |
222 | if ( ! -z $fwconfigout ){ |
223 | &General::readhasharray("$fwconfigout", \%fwout); | |
224 | foreach my $line (sort keys %fwout){ | |
225 | if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){ | |
226 | $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'}; | |
227 | } | |
228 | } | |
229 | &General::writehasharray("$fwconfigout", \%fwout); | |
230 | } | |
bfac6bd4 AM |
231 | #check if we need to update groups |
232 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
233 | foreach my $key (sort keys %customservicegrp){ | |
234 | if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){ | |
235 | $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'}; | |
236 | } | |
237 | } | |
238 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
bfee206c AM |
239 | $needrules='on'; |
240 | } | |
ed73b87e AM |
241 | if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){ |
242 | $needrules='on'; | |
2a81ab0d | 243 | } |
ed73b87e AM |
244 | if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){ |
245 | $needrules='on'; | |
246 | } | |
2aeb4b25 AM |
247 | if($count gt 0 && $fwhostsettings{'oldsrvicmp'} ne $fwhostsettings{'ICMP'} ){ |
248 | $needrules='on'; | |
249 | } | |
2a81ab0d AM |
250 | $fwhostsettings{'SRV_NAME'} = ''; |
251 | $fwhostsettings{'SRV_PORT'} = ''; | |
252 | $fwhostsettings{'PROT'} = ''; | |
2aeb4b25 AM |
253 | $fwhostsettings{'ICMP'} = ''; |
254 | $fwhostsettings{'oldsrvicmp'} = ''; | |
3a162dc1 | 255 | $fwhostsettings{'updatesrv'} = ''; |
2a81ab0d AM |
256 | }else{ |
257 | $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'}; | |
258 | $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'}; | |
259 | $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'}; | |
2aeb4b25 | 260 | $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'}; |
2a81ab0d AM |
261 | $fwhostsettings{'updatesrv'}= 'on'; |
262 | } | |
2a81ab0d | 263 | if($needrules eq 'on'){ |
0e430797 | 264 | &General::firewall_config_changed(); |
2a81ab0d | 265 | } |
2a81ab0d AM |
266 | &addservice; |
267 | } | |
268 | # save | |
269 | if ($fwhostsettings{'ACTION'} eq 'savenet' ) | |
270 | { | |
2a81ab0d AM |
271 | my $needrules=0; |
272 | if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} | |
2a81ab0d AM |
273 | #check if all fields are set |
274 | if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') | |
275 | { | |
276 | $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; | |
277 | &addnet; | |
278 | &viewtablenet; | |
279 | }else{ | |
280 | #check valid ip | |
281 | if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'})) | |
282 | { | |
283 | $errormessage=$errormessage.$Lang::tr{'fwhost err addr'}; | |
284 | $fwhostsettings{'BLK_HOST'} ='readonly'; | |
285 | $fwhostsettings{'NOCHECK'} ='false'; | |
286 | $fwhostsettings{'error'} ='on'; | |
287 | } | |
e5a058c1 AM |
288 | #check remark |
289 | if ($fwhostsettings{'NETREMARK'} ne '' && !&validremark($fwhostsettings{'NETREMARK'})){ | |
290 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
291 | $fwhostsettings{'error'} ='on'; | |
292 | } | |
2a81ab0d AM |
293 | #check if subnet is sigle host |
294 | if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32') | |
295 | { | |
296 | $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'}; | |
2a81ab0d AM |
297 | } |
298 | if($fwhostsettings{'error'} ne 'on'){ | |
299 | #check if we use one of ipfire's networks (green,orange,blue) | |
300 | if (($ownnet{'GREEN_NETADDRESS'} ne '' && $ownnet{'GREEN_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'GREEN_NETADDRESS'},$ownnet{'GREEN_NETMASK'})) | |
301 | { | |
302 | $errormessage=$errormessage.$Lang::tr{'ccd err green'}."<br>"; | |
303 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
304 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
305 | } | |
306 | if (($ownnet{'ORANGE_NETADDRESS'} ne '' && $ownnet{'ORANGE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'ORANGE_NETADDRESS'},$ownnet{'ORANGE_NETMASK'})) | |
307 | { | |
308 | $errormessage=$errormessage.$Lang::tr{'ccd err orange'}."<br>"; | |
309 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
310 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
311 | } | |
312 | if (($ownnet{'BLUE_NETADDRESS'} ne '' && $ownnet{'BLUE_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'BLUE_NETADDRESS'},$ownnet{'BLUE_NETMASK'})) | |
313 | { | |
314 | $errormessage=$errormessage.$Lang::tr{'ccd err blue'}."<br>"; | |
315 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
316 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
317 | } | |
318 | if (($ownnet{'RED_NETADDRESS'} ne '' && $ownnet{'RED_NETADDRESS'} ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'RED_NETADDRESS'},$ownnet{'RED_NETMASK'})) | |
319 | { | |
320 | $errormessage=$errormessage.$Lang::tr{'ccd err red'}."<br>"; | |
321 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
322 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';} | |
323 | } | |
324 | } | |
325 | #only check plausi when no error till now | |
326 | if (!$errormessage){ | |
327 | &plausicheck("editnet"); | |
328 | } | |
2a81ab0d AM |
329 | #check if network ip is part of an already used one |
330 | if(&checksubnet(\%customnetwork)) | |
331 | { | |
332 | $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'}; | |
333 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
334 | } | |
2a81ab0d AM |
335 | if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage) |
336 | { | |
337 | $fwhostsettings{'actualize'} = ''; | |
338 | my $key = &General::findhasharraykey (\%customnetwork); | |
339 | foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";} | |
340 | $customnetwork{$key}[0] = $fwhostsettings{'orgname'} ; | |
341 | $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ; | |
342 | $customnetwork{$key}[2] = $fwhostsettings{'orgsub'}; | |
f80db6a4 | 343 | $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'}; |
2a81ab0d AM |
344 | &General::writehasharray("$confignet", \%customnetwork); |
345 | undef %customnetwork; | |
346 | } | |
2a81ab0d | 347 | if (!$errormessage){ |
e5a058c1 | 348 | |
2a81ab0d AM |
349 | &General::readhasharray("$confignet", \%customnetwork); |
350 | if ($fwhostsettings{'ACTION'} eq 'updatenet'){ | |
351 | if ($fwhostsettings{'update'} == '0'){ | |
352 | foreach my $key (keys %customnetwork) { | |
353 | if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){ | |
2a81ab0d AM |
354 | delete $customnetwork{$key}; |
355 | last; | |
356 | } | |
357 | } | |
358 | } | |
359 | } | |
360 | #get count if actualize is 'on' | |
361 | if($fwhostsettings{'actualize'} eq 'on'){ | |
362 | $fwhostsettings{'actualize'} = ''; | |
2a81ab0d | 363 | #check if we need to reload rules |
484269ce | 364 | if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){ |
2a81ab0d AM |
365 | $needrules='on'; |
366 | } | |
367 | if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ | |
368 | #check if we need to update groups | |
369 | &General::readhasharray("$configgrp", \%customgrp); | |
370 | foreach my $key (sort keys %customgrp){ | |
371 | if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ | |
372 | $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; | |
373 | last; | |
374 | } | |
375 | } | |
376 | &General::writehasharray("$configgrp", \%customgrp); | |
62fc8511 AM |
377 | #check if we need to update firewallrules |
378 | if ( ! -z $fwconfigfwd ){ | |
379 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
380 | foreach my $line (sort keys %fwfwd){ | |
381 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
382 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
383 | } | |
384 | if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){ | |
385 | $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'}; | |
386 | } | |
387 | } | |
388 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
389 | } | |
390 | if ( ! -z $fwconfiginp ){ | |
391 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
392 | foreach my $line (sort keys %fwinp){ | |
393 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
394 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
395 | } | |
396 | } | |
397 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
398 | } | |
2a81ab0d AM |
399 | } |
400 | } | |
401 | my $key = &General::findhasharraykey (\%customnetwork); | |
484269ce | 402 | foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";} |
2a81ab0d AM |
403 | $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'}); |
404 | $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'}; | |
405 | #convert ip when leading '0' in byte | |
e5a058c1 AM |
406 | $fwhostsettings{'IP'} =&General::ip2dec($fwhostsettings{'IP'}); |
407 | $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'}); | |
2a81ab0d AM |
408 | $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ; |
409 | $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ; | |
e5a058c1 | 410 | $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'}; |
2a81ab0d AM |
411 | &General::writehasharray("$confignet", \%customnetwork); |
412 | $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
413 | undef %customnetwork; | |
414 | $fwhostsettings{'HOSTNAME'}=''; | |
415 | $fwhostsettings{'IP'}=''; | |
416 | $fwhostsettings{'SUBNET'}=''; | |
e5a058c1 | 417 | $fwhostsettings{'NETREMARK'}=''; |
2a81ab0d AM |
418 | #check if an edited net affected groups and need to reload rules |
419 | if ($needrules eq 'on'){ | |
0e430797 | 420 | &General::firewall_config_changed(); |
2a81ab0d AM |
421 | } |
422 | &addnet; | |
423 | &viewtablenet; | |
2e99ab8b | 424 | }else { |
2a81ab0d AM |
425 | &addnet; |
426 | &viewtablenet; | |
427 | } | |
428 | } | |
2a81ab0d AM |
429 | } |
430 | if ($fwhostsettings{'ACTION'} eq 'savehost') | |
431 | { | |
2a81ab0d AM |
432 | my $needrules=0; |
433 | if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} | |
2a81ab0d | 434 | $fwhostsettings{'SUBNET'}='32'; |
2a81ab0d AM |
435 | #check if all fields are set |
436 | if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') | |
437 | { | |
438 | $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; | |
439 | $fwhostsettings{'ACTION'} = 'edithost'; | |
440 | }else{ | |
92e4ae9d | 441 | if($fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){ |
2a81ab0d | 442 | $fwhostsettings{'type'} = 'mac'; |
92e4ae9d | 443 | }elsif($fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ |
2a81ab0d AM |
444 | $fwhostsettings{'type'} = 'ip'; |
445 | }else{ | |
446 | $fwhostsettings{'type'} = ''; | |
447 | $errormessage=$Lang::tr{'fwhost err ipmac'}; | |
448 | } | |
e3580608 AM |
449 | #check remark |
450 | if ($fwhostsettings{'HOSTREMARK'} ne '' && !&validremark($fwhostsettings{'HOSTREMARK'})){ | |
451 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
452 | } | |
2a81ab0d AM |
453 | #CHECK IP-PART |
454 | if ($fwhostsettings{'type'} eq 'ip'){ | |
455 | #check for subnet | |
456 | if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){ | |
457 | if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32")) | |
458 | { | |
459 | $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'}; | |
460 | $fwhostsettings{'error'}='on'; | |
461 | } | |
2a81ab0d AM |
462 | }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){ |
463 | $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'}; | |
464 | $fwhostsettings{'error'}='on'; | |
465 | } | |
466 | #check if net or broadcast | |
467 | my @tmp= split (/\./,$fwhostsettings{'IP'}); | |
468 | if (($tmp[3] eq "0") || ($tmp[3] eq "255")){ | |
469 | $errormessage=$Lang::tr{'fwhost err hostip'}; | |
470 | } | |
471 | } | |
2a81ab0d AM |
472 | #only check plausi when no error till now |
473 | if (!$errormessage){ | |
474 | &plausicheck("edithost"); | |
475 | } | |
2a81ab0d AM |
476 | if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){ |
477 | $fwhostsettings{'actualize'} = ''; | |
478 | my $key = &General::findhasharraykey (\%customhost); | |
484269ce | 479 | foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";} |
2a81ab0d AM |
480 | $customhost{$key}[0] = $fwhostsettings{'orgname'} ; |
481 | $customhost{$key}[1] = $fwhostsettings{'type'} ; | |
482 | if($customhost{$key}[1] eq 'ip'){ | |
483 | $customhost{$key}[2] = $fwhostsettings{'orgip'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
484 | }else{ | |
485 | $customhost{$key}[2] = $fwhostsettings{'orgip'}; | |
486 | } | |
f80db6a4 | 487 | $customhost{$key}[3] = $fwhostsettings{'orgremark'}; |
2a81ab0d AM |
488 | &General::writehasharray("$confighost", \%customhost); |
489 | undef %customhost; | |
2a81ab0d | 490 | } |
2a81ab0d AM |
491 | if (!$errormessage){ |
492 | #get count if host was edited | |
493 | if($fwhostsettings{'actualize'} eq 'on'){ | |
484269ce | 494 | if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){ |
2a81ab0d AM |
495 | $needrules='on'; |
496 | } | |
497 | if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ | |
498 | #check if we need to update groups | |
499 | &General::readhasharray("$configgrp", \%customgrp); | |
500 | foreach my $key (sort keys %customgrp){ | |
501 | if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ | |
502 | $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; | |
2a81ab0d AM |
503 | } |
504 | } | |
505 | &General::writehasharray("$configgrp", \%customgrp); | |
62fc8511 AM |
506 | #check if we need to update firewallrules |
507 | if ( ! -z $fwconfigfwd ){ | |
508 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
509 | foreach my $line (sort keys %fwfwd){ | |
510 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
511 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
512 | } | |
513 | if ($fwfwd{$line}[6] eq $fwhostsettings{'orgname'}){ | |
514 | $fwfwd{$line}[6] = $fwhostsettings{'HOSTNAME'}; | |
515 | } | |
516 | } | |
517 | &General::writehasharray("$fwconfigfwd", \%fwfwd); | |
518 | } | |
519 | if ( ! -z $fwconfiginp ){ | |
520 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
521 | foreach my $line (sort keys %fwinp){ | |
522 | if ($fwfwd{$line}[4] eq $fwhostsettings{'orgname'}){ | |
523 | $fwfwd{$line}[4] = $fwhostsettings{'HOSTNAME'}; | |
524 | } | |
525 | } | |
526 | &General::writehasharray("$fwconfiginp", \%fwinp); | |
527 | } | |
2a81ab0d | 528 | } |
2a81ab0d AM |
529 | } |
530 | my $key = &General::findhasharraykey (\%customhost); | |
484269ce | 531 | foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";} |
2a81ab0d AM |
532 | $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ; |
533 | $customhost{$key}[1] = $fwhostsettings{'type'} ; | |
534 | if ($fwhostsettings{'type'} eq 'ip'){ | |
535 | #convert ip when leading '0' in byte | |
536 | $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'}); | |
537 | $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'}); | |
538 | $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); | |
539 | }else{ | |
540 | $customhost{$key}[2] = $fwhostsettings{'IP'}; | |
541 | } | |
e3580608 | 542 | $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'}; |
2a81ab0d | 543 | &General::writehasharray("$confighost", \%customhost); |
2a81ab0d AM |
544 | undef %customhost; |
545 | $fwhostsettings{'HOSTNAME'}=''; | |
546 | $fwhostsettings{'IP'}=''; | |
547 | $fwhostsettings{'type'}=''; | |
e3580608 | 548 | $fwhostsettings{'HOSTREMARK'}=''; |
2a81ab0d AM |
549 | #check if we need to update rules while host was edited |
550 | if($needrules eq 'on'){ | |
0e430797 | 551 | &General::firewall_config_changed(); |
2a81ab0d AM |
552 | } |
553 | &addhost; | |
554 | &viewtablehost; | |
555 | }else{ | |
556 | &addhost; | |
557 | &viewtablehost; | |
558 | } | |
2a81ab0d | 559 | } |
2a81ab0d AM |
560 | } |
561 | if ($fwhostsettings{'ACTION'} eq 'savegrp') | |
562 | { | |
484269ce | 563 | my $grp=$fwhostsettings{'grp_name'}; |
2a81ab0d AM |
564 | my $rem=$fwhostsettings{'remark'}; |
565 | my $count; | |
566 | my $type; | |
567 | my $updcounter='off'; | |
568 | my @target; | |
569 | my @newgrp; | |
570 | &General::readhasharray("$configgrp", \%customgrp); | |
571 | &General::readhasharray("$confignet", \%customnetwork); | |
572 | &General::readhasharray("$confighost", \%customhost); | |
484269ce AM |
573 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
574 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
575 | &General::readhasharray("$fwconfigout", \%fwout); | |
6c869961 AM |
576 | #check name |
577 | if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};} | |
f195a8d7 | 578 | #check existing name |
3a162dc1 | 579 | if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};} |
6c869961 AM |
580 | #check remark |
581 | if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){ | |
582 | $errormessage.=$Lang::tr{'fwhost err remark'}; | |
2a81ab0d | 583 | } |
6c869961 AM |
584 | if ($fwhostsettings{'update'} eq 'on'){ |
585 | #check standard networks | |
586 | if ($fwhostsettings{'grp2'} eq 'std_net'){ | |
587 | @target=$fwhostsettings{'DEFAULT_SRC_ADR'}; | |
588 | $type='Standard Network'; | |
589 | } | |
590 | #check custom networks | |
591 | if ($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} ne ''){ | |
592 | @target=$fwhostsettings{'CUST_SRC_NET'}; | |
593 | $updcounter='net'; | |
594 | $type='Custom Network'; | |
595 | }elsif($fwhostsettings{'grp2'} eq 'cust_net' && $fwhostsettings{'CUST_SRC_NET'} eq ''){ | |
596 | $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
597 | $fwhostsettings{'grp_name'}=''; | |
598 | $fwhostsettings{'remark'}=''; | |
599 | } | |
600 | #check custom addresses | |
601 | if ($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} ne ''){ | |
602 | @target=$fwhostsettings{'CUST_SRC_HOST'}; | |
603 | $updcounter='host'; | |
604 | $type='Custom Host'; | |
605 | }elsif($fwhostsettings{'grp2'} eq 'cust_host' && $fwhostsettings{'CUST_SRC_HOST'} eq ''){ | |
606 | $errormessage=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
607 | $fwhostsettings{'grp_name'}=''; | |
608 | $fwhostsettings{'remark'}=''; | |
609 | } | |
610 | #get address from ovpn ccd static net | |
611 | if ($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} ne ''){ | |
612 | @target=$fwhostsettings{'OVPN_CCD_NET'}; | |
613 | $type='OpenVPN static network'; | |
614 | }elsif($fwhostsettings{'grp2'} eq 'ovpn_net' && $fwhostsettings{'OVPN_CCD_NET'} eq ''){ | |
615 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
616 | $fwhostsettings{'grp_name'}=''; | |
617 | $fwhostsettings{'remark'}=''; | |
618 | } | |
619 | #get address from ovpn ccd static host | |
620 | if ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} ne ''){ | |
621 | @target=$fwhostsettings{'OVPN_CCD_HOST'}; | |
622 | $type='OpenVPN static host'; | |
623 | }elsif ($fwhostsettings{'grp2'} eq 'ovpn_host' && $fwhostsettings{'OVPN_CCD_HOST'} eq ''){ | |
624 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
625 | } | |
626 | #get address from ovpn ccd Net-2-Net | |
627 | if ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} ne ''){ | |
628 | @target=$fwhostsettings{'OVPN_N2N'}; | |
629 | $type='OpenVPN N-2-N'; | |
630 | }elsif ($fwhostsettings{'grp2'} eq 'ovpn_n2n' && $fwhostsettings{'OVPN_N2N'} eq ''){ | |
631 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
632 | $fwhostsettings{'grp_name'}=''; | |
633 | $fwhostsettings{'remark'}=''; | |
634 | } | |
635 | #get address from IPSEC HOST | |
636 | if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){ | |
637 | @target=$fwhostsettings{'IPSEC_HOST'}; | |
638 | $type='IpSec Host'; | |
639 | }elsif ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} eq ''){ | |
640 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
641 | $fwhostsettings{'grp_name'}=''; | |
642 | $fwhostsettings{'remark'}=''; | |
643 | } | |
644 | #get address from IPSEC NETWORK | |
645 | if ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} ne ''){ | |
646 | @target=$fwhostsettings{'IPSEC_NET'}; | |
647 | $type='IpSec Network'; | |
648 | }elsif ($fwhostsettings{'grp2'} eq 'ipsec_net' && $fwhostsettings{'IPSEC_NET'} eq ''){ | |
649 | $errormessage=$Lang::tr{'fwhost err groupempty'}; | |
650 | $fwhostsettings{'grp_name'}=''; | |
651 | $fwhostsettings{'remark'}=''; | |
652 | } | |
653 | #check if host/net exists in grp | |
654 | ||
655 | my $test="$grp,$fwhostsettings{'oldremark'},@target"; | |
656 | foreach my $key (keys %customgrp) { | |
657 | my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]"; | |
658 | if ($test1 eq $test){ | |
659 | $errormessage=$Lang::tr{'fwhost err isingrp'}; | |
660 | $fwhostsettings{'update'} = 'on'; | |
661 | } | |
2a81ab0d AM |
662 | } |
663 | } | |
6c869961 | 664 | |
2a81ab0d AM |
665 | if (!$errormessage){ |
666 | #on first save, we have an empty @target, so fill it with nothing | |
667 | my $targetvalues=@target; | |
668 | if ($targetvalues == '0'){ | |
6c869961 | 669 | @target="none"; |
2a81ab0d AM |
670 | } |
671 | #on update, we have to delete the dummy entry | |
2a81ab0d | 672 | foreach my $key (keys %customgrp){ |
6c869961 | 673 | if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq "none"){ |
2a81ab0d AM |
674 | delete $customgrp{$key}; |
675 | last; | |
676 | } | |
677 | } | |
678 | &General::writehasharray("$configgrp", \%customgrp); | |
679 | &General::readhasharray("$configgrp", \%customgrp); | |
2a81ab0d AM |
680 | #create array with new lines |
681 | foreach my $line (@target){ | |
682 | push (@newgrp,"$grp,$rem,$line"); | |
683 | } | |
684 | #append new entries | |
685 | my $key = &General::findhasharraykey (\%customgrp); | |
686 | foreach my $line (@newgrp){ | |
484269ce | 687 | foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";} |
2a81ab0d AM |
688 | my ($a,$b,$c,$d) = split (",",$line); |
689 | $customgrp{$key}[0] = $a; | |
690 | $customgrp{$key}[1] = $b; | |
691 | $customgrp{$key}[2] = $c; | |
692 | $customgrp{$key}[3] = $type; | |
2a81ab0d AM |
693 | } |
694 | &General::writehasharray("$configgrp", \%customgrp); | |
2a81ab0d | 695 | #update counter in Host/Net |
2a81ab0d | 696 | $fwhostsettings{'update'}='on'; |
2a81ab0d | 697 | } |
2a81ab0d | 698 | #check if ruleupdate is needed |
484269ce AM |
699 | my $netgrpcount=0; |
700 | $netgrpcount=&getnetcount($grp); | |
701 | if($netgrpcount > 0 ) | |
2a81ab0d | 702 | { |
0e430797 | 703 | &General::firewall_config_changed(); |
2a81ab0d AM |
704 | } |
705 | &addgrp; | |
706 | &viewtablegrp; | |
2a81ab0d AM |
707 | } |
708 | if ($fwhostsettings{'ACTION'} eq 'saveservice') | |
709 | { | |
710 | my $ICMP; | |
2a81ab0d | 711 | &General::readhasharray("$configsrv", \%customservice ); |
3a162dc1 | 712 | &General::readhasharray("$configgrp", \%customgrp); |
2a81ab0d | 713 | $errormessage=&checkports(\%customservice); |
2a81ab0d AM |
714 | if ($fwhostsettings{'PROT'} eq 'ICMP'){ |
715 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
716 | foreach my $key (keys %icmptypes){ | |
717 | if ("$icmptypes{$key}[0] ($icmptypes{$key}[1])" eq $fwhostsettings{'ICMP_TYPES'}){ | |
718 | $ICMP=$icmptypes{$key}[0]; | |
719 | } | |
720 | } | |
721 | } | |
86a921ee | 722 | if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};} |
3a162dc1 AM |
723 | if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';} |
724 | #Check if a group with the same name already exists | |
725 | if (!&checkgroup($fwhostsettings{'SRV_NAME'})){ | |
726 | $errormessage = $Lang::tr{'fwhost err grpexist'}; | |
727 | } | |
2a81ab0d | 728 | if (!$errormessage){ |
2a81ab0d AM |
729 | my $key = &General::findhasharraykey (\%customservice); |
730 | foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";} | |
731 | $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'}; | |
732 | $customservice{$key}[1] = $fwhostsettings{'SRV_PORT'}; | |
733 | $customservice{$key}[2] = $fwhostsettings{'PROT'}; | |
734 | $customservice{$key}[3] = $ICMP; | |
2a81ab0d AM |
735 | &General::writehasharray("$configsrv", \%customservice ); |
736 | #reset fields | |
737 | $fwhostsettings{'SRV_NAME'}=''; | |
738 | $fwhostsettings{'SRV_PORT'}=''; | |
739 | $fwhostsettings{'PROT'}=''; | |
740 | $fwhostsettings{'ICMP_TYPES'}=''; | |
2a81ab0d | 741 | } |
2a81ab0d | 742 | &addservice; |
2a81ab0d AM |
743 | } |
744 | if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') | |
745 | { | |
746 | my $prot; | |
747 | my $port; | |
748 | my $count=0; | |
49192c7b AM |
749 | my $tcpcounter=0; |
750 | my $udpcounter=0; | |
2a81ab0d AM |
751 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); |
752 | &General::readhasharray("$configsrv", \%customservice ); | |
2a81ab0d | 753 | $errormessage=&checkservicegroup; |
82b837cf AM |
754 | #Check if we have more than 15 services from one Protocol in the group |
755 | #iptables can only handle 15 ports/portranges via multiport | |
49192c7b AM |
756 | foreach my $key (keys %customservicegrp){ |
757 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){ | |
758 | foreach my $key1 (keys %customservice){ | |
759 | $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0]; | |
7db6ad6a | 760 | $tcpcounter++ if $customservice{$key1}[2] eq 'TCP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i; |
49192c7b | 761 | $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0]; |
7db6ad6a | 762 | $udpcounter++ if $customservice{$key1}[2] eq 'UDP' && $customservicegrp{$key}[2] eq $customservice{$key1}[0] && $customservice{$key1}[1] =~m/:/i; |
49192c7b AM |
763 | } |
764 | } | |
765 | } | |
7db6ad6a | 766 | if ($tcpcounter > 15){ |
49192c7b AM |
767 | $errormessage=$Lang::tr{'fwhost err maxservicetcp'}; |
768 | } | |
7db6ad6a | 769 | if ($udpcounter > 15){ |
49192c7b AM |
770 | $errormessage=$Lang::tr{'fwhost err maxserviceudp'}; |
771 | } | |
772 | $tcpcounter=0; | |
773 | $udpcounter=0; | |
bc912c6e AM |
774 | #check remark |
775 | if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){ | |
49192c7b | 776 | $errormessage .= $Lang::tr{'fwhost err remark'}; |
bc912c6e | 777 | } |
3a162dc1 AM |
778 | #Check if there is already a service with the same name |
779 | if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){ | |
780 | $errormessage .= $Lang::tr{'fwhost err srv exists'}; | |
781 | } | |
2a81ab0d AM |
782 | if (!$errormessage){ |
783 | #on first save, we have to enter a dummy value | |
6c869961 AM |
784 | if ($fwhostsettings{'CUST_SRV'} eq ''){ |
785 | $fwhostsettings{'CUST_SRV'}='none'; | |
786 | } | |
2a81ab0d AM |
787 | #on update, we have to delete the dummy entry |
788 | foreach my $key (keys %customservicegrp){ | |
6c869961 | 789 | if ($customservicegrp{$key}[2] eq 'none'){ |
2a81ab0d AM |
790 | delete $customservicegrp{$key}; |
791 | last; | |
792 | } | |
793 | } | |
794 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); | |
795 | #check if remark has also changed | |
796 | if ($fwhostsettings{'SRVGRP_REMARK'} ne $fwhostsettings{'oldsrvgrpremark'} && $fwhostsettings{'updatesrvgrp'} eq 'on') | |
797 | { | |
798 | foreach my $key (keys %customservicegrp) | |
799 | { | |
800 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvgrpremark'}) | |
801 | { | |
802 | $customservicegrp{$key}[1]=''; | |
803 | $customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'}; | |
3a162dc1 | 804 | } |
2a81ab0d AM |
805 | } |
806 | } | |
2a81ab0d | 807 | my $key = &General::findhasharraykey (\%customservicegrp); |
3a162dc1 | 808 | foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";} |
2a81ab0d AM |
809 | $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'}; |
810 | $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'}; | |
811 | $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'}; | |
2a81ab0d AM |
812 | &General::writehasharray("$configsrvgrp", \%customservicegrp ); |
813 | $fwhostsettings{'updatesrvgrp'}='on'; | |
814 | } | |
2a81ab0d | 815 | if ($count gt 0){ |
0e430797 | 816 | &General::firewall_config_changed(); |
2a81ab0d AM |
817 | } |
818 | &addservicegrp; | |
819 | &viewtableservicegrp; | |
820 | } | |
821 | # edit | |
822 | if ($fwhostsettings{'ACTION'} eq 'editnet') | |
823 | { | |
824 | &addnet; | |
825 | &viewtablenet; | |
826 | } | |
827 | if ($fwhostsettings{'ACTION'} eq 'edithost') | |
828 | { | |
829 | &addhost; | |
830 | &viewtablehost; | |
831 | } | |
832 | if ($fwhostsettings{'ACTION'} eq 'editgrp') | |
833 | { | |
834 | $fwhostsettings{'update'}='on'; | |
835 | &addgrp; | |
836 | &viewtablegrp; | |
837 | } | |
838 | if ($fwhostsettings{'ACTION'} eq 'editservice') | |
839 | { | |
840 | $fwhostsettings{'updatesrv'}='on'; | |
841 | &addservice; | |
842 | } | |
843 | if ($fwhostsettings{'ACTION'} eq 'editservicegrp') | |
844 | { | |
845 | $fwhostsettings{'updatesrvgrp'} = 'on'; | |
846 | &addservicegrp; | |
847 | &viewtableservicegrp; | |
848 | } | |
849 | # reset | |
850 | if ($fwhostsettings{'ACTION'} eq 'resetnet') | |
851 | { | |
852 | $fwhostsettings{'HOSTNAME'} =""; | |
853 | $fwhostsettings{'IP'} =""; | |
854 | $fwhostsettings{'SUBNET'} =""; | |
855 | &showmenu; | |
856 | } | |
857 | if ($fwhostsettings{'ACTION'} eq 'resethost') | |
858 | { | |
859 | $fwhostsettings{'HOSTNAME'} =""; | |
860 | $fwhostsettings{'IP'} =""; | |
861 | $fwhostsettings{'type'} =""; | |
862 | &showmenu; | |
863 | } | |
43215686 AM |
864 | if ($fwhostsettings{'ACTION'} eq 'resetgrp') |
865 | { | |
866 | $fwhostsettings{'grp_name'} =""; | |
867 | $fwhostsettings{'remark'} =""; | |
868 | &showmenu; | |
869 | } | |
2a81ab0d AM |
870 | # delete |
871 | if ($fwhostsettings{'ACTION'} eq 'delnet') | |
872 | { | |
873 | &General::readhasharray("$confignet", \%customnetwork); | |
874 | foreach my $key (keys %customnetwork) { | |
875 | if($fwhostsettings{'key'} eq $customnetwork{$key}[0]){ | |
876 | delete $customnetwork{$key}; | |
877 | &General::writehasharray("$confignet", \%customnetwork); | |
878 | last; | |
879 | } | |
880 | } | |
881 | &addnet; | |
882 | &viewtablenet; | |
883 | } | |
884 | if ($fwhostsettings{'ACTION'} eq 'delhost') | |
885 | { | |
886 | &General::readhasharray("$confighost", \%customhost); | |
887 | foreach my $key (keys %customhost) { | |
888 | if($fwhostsettings{'key'} eq $customhost{$key}[0]){ | |
889 | delete $customhost{$key}; | |
890 | &General::writehasharray("$confighost", \%customhost); | |
891 | last; | |
892 | } | |
893 | } | |
894 | &addhost; | |
895 | &viewtablehost; | |
2a81ab0d AM |
896 | } |
897 | if ($fwhostsettings{'ACTION'} eq 'deletegrphost') | |
898 | { | |
3f8fe51e AM |
899 | my $grpremark; |
900 | my $grpname; | |
2a81ab0d AM |
901 | &General::readhasharray("$configgrp", \%customgrp); |
902 | foreach my $key (keys %customgrp){ | |
903 | if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){ | |
904 | #decrease count from source host/net | |
905 | if ($customgrp{$key}[3] eq 'Custom Network'){ | |
906 | &General::readhasharray("$confignet", \%customnetwork); | |
907 | foreach my $key1 (keys %customnetwork){ | |
908 | if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ | |
e09884e0 | 909 | $customnetwork{$key1}[4] = $customnetwork{$key1}[4]-1; |
2a81ab0d AM |
910 | last; |
911 | } | |
912 | } | |
913 | &General::writehasharray("$confignet", \%customnetwork); | |
914 | } | |
915 | if ($customgrp{$key}[3] eq 'Custom Host'){ | |
916 | &General::readhasharray("$confighost", \%customhost); | |
917 | foreach my $key1 (keys %customhost){ | |
918 | if ($customhost{$key1}[0] eq $customgrp{$key}[2]){ | |
e3580608 | 919 | $customhost{$key1}[4] = $customhost{$key1}[4]-1; |
2a81ab0d AM |
920 | last; |
921 | } | |
922 | } | |
923 | &General::writehasharray("$confighost", \%customhost); | |
924 | } | |
3f8fe51e AM |
925 | $grpname=$customgrp{$key}[0]; |
926 | $grpremark=$customgrp{$key}[1]; | |
2a81ab0d AM |
927 | delete $customgrp{$key}; |
928 | } | |
929 | } | |
930 | &General::writehasharray("$configgrp", \%customgrp); | |
0e430797 MT |
931 | if ($fwhostsettings{'grpcnt'} > 0){ |
932 | &General::firewall_config_changed(); | |
933 | } | |
3f8fe51e AM |
934 | if ($fwhostsettings{'update'} eq 'on'){ |
935 | $fwhostsettings{'remark'}= $grpremark; | |
936 | $fwhostsettings{'grp_name'}=$grpname; | |
937 | } | |
2a81ab0d AM |
938 | &addgrp; |
939 | &viewtablegrp; | |
940 | } | |
941 | if ($fwhostsettings{'ACTION'} eq 'delgrp') | |
942 | { | |
943 | &General::readhasharray("$configgrp", \%customgrp); | |
944 | &decrease($fwhostsettings{'grp_name'}); | |
945 | foreach my $key (sort keys %customgrp) | |
946 | { | |
947 | if($customgrp{$key}[0] eq $fwhostsettings{'grp_name'}) | |
948 | { | |
949 | delete $customgrp{$key}; | |
950 | } | |
951 | } | |
952 | &General::writehasharray("$configgrp", \%customgrp); | |
953 | $fwhostsettings{'grp_name'}=''; | |
954 | &addgrp; | |
955 | &viewtablegrp; | |
956 | } | |
957 | if ($fwhostsettings{'ACTION'} eq 'delservice') | |
958 | { | |
959 | &General::readhasharray("$configsrv", \%customservice); | |
960 | foreach my $key (keys %customservice) { | |
961 | if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){ | |
2a81ab0d AM |
962 | delete $customservice{$key}; |
963 | &General::writehasharray("$configsrv", \%customservice); | |
964 | last; | |
965 | } | |
966 | } | |
967 | $fwhostsettings{'SRV_NAME'}=''; | |
968 | $fwhostsettings{'SRV_PORT'}=''; | |
969 | $fwhostsettings{'PROT'}=''; | |
970 | &addservice; | |
971 | } | |
972 | if ($fwhostsettings{'ACTION'} eq 'delservicegrp') | |
973 | { | |
974 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
975 | &decreaseservice($fwhostsettings{'SRVGRP_NAME'}); | |
976 | foreach my $key (sort keys %customservicegrp) | |
977 | { | |
978 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}) | |
979 | { | |
980 | delete $customservicegrp{$key}; | |
981 | } | |
982 | } | |
983 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
984 | $fwhostsettings{'SRVGRP_NAME'}=''; | |
985 | &addservicegrp; | |
986 | &viewtableservicegrp; | |
987 | } | |
988 | if ($fwhostsettings{'ACTION'} eq 'delgrpservice') | |
989 | { | |
3f8fe51e AM |
990 | my $grpname; |
991 | my $grpremark; | |
2a81ab0d AM |
992 | &General::readhasharray("$configsrvgrp", \%customservicegrp); |
993 | &General::readhasharray("$configsrv", \%customservice); | |
994 | foreach my $key (keys %customservicegrp){ | |
3a162dc1 | 995 | if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'}) |
2a81ab0d AM |
996 | { |
997 | #decrease count from source service | |
fe2bae3b AM |
998 | foreach my $key1 (sort keys %customservice){ |
999 | if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){ | |
1000 | $customservice{$key1}[4]--; | |
1001 | last; | |
2a81ab0d AM |
1002 | } |
1003 | } | |
3f8fe51e AM |
1004 | $grpname=$customservicegrp{$key}[0]; |
1005 | $grpremark=$customservicegrp{$key}[1]; | |
1006 | delete $customservicegrp{$key}; | |
2a81ab0d AM |
1007 | } |
1008 | } | |
fe2bae3b | 1009 | &General::writehasharray("$configsrv", \%customservice); |
2a81ab0d | 1010 | &General::writehasharray("$configsrvgrp", \%customservicegrp); |
0e430797 | 1011 | &General::firewall_config_changed(); |
3f8fe51e | 1012 | if ($fwhostsettings{'updatesrvgrp'} eq 'on'){ |
3f8fe51e AM |
1013 | $fwhostsettings{'SRVGRP_NAME'}=$grpname; |
1014 | $fwhostsettings{'SRVGRP_REMARK'}=$grpremark; | |
1015 | } | |
2a81ab0d AM |
1016 | &addservicegrp; |
1017 | &viewtableservicegrp; | |
1018 | ||
1019 | } | |
1020 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'}) | |
1021 | { | |
1022 | &addnet; | |
1023 | &viewtablenet; | |
1024 | } | |
1025 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'}) | |
1026 | { | |
1027 | &addhost; | |
1028 | &viewtablehost; | |
1029 | } | |
1030 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'}) | |
1031 | { | |
1032 | &addgrp; | |
1033 | &viewtablegrp; | |
1034 | } | |
1035 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'}) | |
1036 | { | |
1037 | &addservice; | |
1038 | } | |
1039 | if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'}) | |
1040 | { | |
1041 | &addservicegrp; | |
1042 | &viewtableservicegrp; | |
1043 | } | |
6c869961 AM |
1044 | if ($fwhostsettings{'ACTION'} eq 'changegrpremark') |
1045 | { | |
1046 | &General::readhasharray("$configgrp", \%customgrp); | |
d0815ce4 | 1047 | if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){ |
6c869961 AM |
1048 | foreach my $key (sort keys %customgrp) |
1049 | { | |
6c869961 AM |
1050 | if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'}) |
1051 | { | |
6c869961 AM |
1052 | $customgrp{$key}[1]=''; |
1053 | $customgrp{$key}[1]=$fwhostsettings{'newrem'}; | |
1054 | } | |
1055 | } | |
1056 | &General::writehasharray("$configgrp", \%customgrp); | |
1057 | $fwhostsettings{'update'}='on'; | |
6c869961 AM |
1058 | $fwhostsettings{'remark'}=$fwhostsettings{'newrem'}; |
1059 | }else{ | |
1060 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1061 | $fwhostsettings{'remark'}=$fwhostsettings{'oldrem'}; | |
1062 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1063 | $fwhostsettings{'update'} = 'on'; | |
1064 | } | |
1065 | $fwhostsettings{'grp_name'}=$fwhostsettings{'grp'}; | |
1066 | &addgrp; | |
1067 | &viewtablegrp; | |
1068 | } | |
1069 | if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark') | |
1070 | { | |
1071 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); | |
d0815ce4 | 1072 | if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){ |
6c869961 AM |
1073 | foreach my $key (sort keys %customservicegrp) |
1074 | { | |
6c869961 AM |
1075 | if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'}) |
1076 | { | |
6c869961 AM |
1077 | $customservicegrp{$key}[1]=''; |
1078 | $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'}; | |
1079 | } | |
1080 | } | |
1081 | &General::writehasharray("$configsrvgrp", \%customservicegrp); | |
1082 | $fwhostsettings{'updatesrvgrp'}='on'; | |
6c869961 | 1083 | $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'}; |
82b837cf AM |
1084 | }elsif($fwhostsettings{'oldsrvrem'} eq $fwhostsettings{'newsrvrem'}){ |
1085 | &addservicegrp; | |
1086 | &viewtableservicegrp; | |
6c869961 AM |
1087 | }else{ |
1088 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
1089 | $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'oldsrvrem'}; | |
1090 | $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'}; | |
1091 | $fwhostsettings{'updatesrvgrp'} = 'on'; | |
1092 | } | |
1093 | $fwhostsettings{'SRVGRP_NAME'}=$fwhostsettings{'srvgrp'}; | |
1094 | &addservicegrp; | |
1095 | &viewtableservicegrp; | |
1096 | } | |
2a81ab0d AM |
1097 | ### VIEW ### |
1098 | if($fwhostsettings{'ACTION'} eq '') | |
1099 | { | |
1100 | &showmenu; | |
1101 | } | |
1102 | ### FUNCTIONS ### | |
0e430797 | 1103 | sub showmenu { |
2a81ab0d | 1104 | &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'}); |
43d8be09 | 1105 | print "$Lang::tr{'fwhost welcome'}"; |
2a81ab0d | 1106 | print<<END; |
2e99ab8b AM |
1107 | <br><br><table border='0' width='100%'> |
1108 | <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'}' ></form></td> | |
1109 | <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> | |
1110 | <tr><td colspan='6'><hr></td></tr></table> | |
2a81ab0d | 1111 | END |
2a81ab0d AM |
1112 | &Header::closebox(); |
1113 | ||
1114 | } | |
1115 | # Add | |
1116 | sub addnet | |
1117 | { | |
1118 | &error; | |
1119 | &showmenu; | |
1120 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addnet'}); | |
1121 | $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; | |
f80db6a4 | 1122 | $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'}; |
2a81ab0d | 1123 | print<<END; |
2e99ab8b AM |
1124 | <table border='0' width='100%'> |
1125 | <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 |
1126 | <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> |
1127 | <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 | 1128 | <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='NETREMARK' value='$fwhostsettings{'NETREMARK'}' style='width: 98.5%;'></td></tr> |
2e99ab8b | 1129 | <tr><td colspan='6'><br><hr></td></tr><tr> |
2a81ab0d AM |
1130 | END |
1131 | if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on') | |
1132 | { | |
2e99ab8b | 1133 | 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'}'></td>"; |
2a81ab0d | 1134 | }else{ |
7f5b2820 | 1135 | 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'>"; |
2a81ab0d | 1136 | } |
2e99ab8b | 1137 | 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 |
1138 | &Header::closebox(); |
1139 | } | |
1140 | sub addhost | |
1141 | { | |
1142 | &error; | |
1143 | &showmenu; | |
1144 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addhost'}); | |
1145 | $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; | |
f80db6a4 | 1146 | $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'}; |
2a81ab0d | 1147 | print<<END; |
2e99ab8b AM |
1148 | <table border='0' width='100%'> |
1149 | <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 | 1150 | <tr><td>IP/MAC:</td><td><input type='TEXT' name='IP' value='$fwhostsettings{'IP'}' $fwhostsettings{'BLK_IP'} size='20' maxlength='17'></td></tr> |
8013bd0a | 1151 | <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='HOSTREMARK' value='$fwhostsettings{'HOSTREMARK'}' style='width:98%;'></td></tr> |
2e99ab8b | 1152 | <tr><td colspan='5'><hr></td></tr><tr> |
2a81ab0d AM |
1153 | END |
1154 | ||
1155 | if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on') | |
1156 | { | |
1157 | ||
8013bd0a | 1158 | 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 | 1159 | }else{ |
2e99ab8b | 1160 | 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 | 1161 | } |
2e99ab8b | 1162 | 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 |
1163 | &Header::closebox(); |
1164 | } | |
1165 | sub addgrp | |
1166 | { | |
1167 | &hint; | |
1168 | &error; | |
1169 | &showmenu; | |
1170 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addgrp'}); | |
1171 | &General::setup_default_networks(\%defaultNetworks); | |
8013bd0a AM |
1172 | &General::readhasharray("$configccdnet", \%ccdnet); |
1173 | &General::readhasharray("$confignet", \%customnetwork); | |
1174 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1175 | &General::readhasharray("$confighost", \%customhost); | |
1176 | &General::readhasharray("$configipsec", \%ipsecconf); | |
1177 | ||
2a81ab0d | 1178 | my %checked=(); |
8013bd0a | 1179 | my $show=''; |
2a81ab0d AM |
1180 | $checked{'check1'}{'off'} = ''; |
1181 | $checked{'check1'}{'on'} = ''; | |
1182 | $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED'; | |
1183 | $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'}; | |
6c869961 AM |
1184 | my $grp=$fwhostsettings{'grp_name'}; |
1185 | my $rem=$fwhostsettings{'remark'}; | |
2a81ab0d AM |
1186 | if ($fwhostsettings{'update'} eq ''){ |
1187 | print<<END; | |
2e99ab8b AM |
1188 | <table width='100%' border='0'> |
1189 | <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><form method='post'><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='20'></td></tr> | |
8013bd0a AM |
1190 | <tr><td width='10%'>$Lang::tr{'remark'}:</td><td ><input type='TEXT' name='remark' value='$fwhostsettings{'remark'}' style='width: 98%;'></td></tr> |
1191 | <tr><td colspan='2'><br><hr></td></tr></table> | |
2a81ab0d AM |
1192 | END |
1193 | }else{ | |
1194 | print<<END; | |
6c869961 | 1195 | <table width='100%' border='0'><form method='post' style='display:inline'> |
8013bd0a AM |
1196 | <tr><td nowrap='nowrap' width='12%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp' value='$fwhostsettings{'grp_name'}' readonly ></td><td></td></tr> |
1197 | <tr><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='newrem' size='45' value='$fwhostsettings{'remark'}' style='width:98%'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldrem' value='$fwhostsettings{'oldremark'}'><input type='hidden' name='ACTION' value='changegrpremark' ></td></tr></table></form> | |
6c869961 | 1198 | <hr> |
2a81ab0d | 1199 | END |
2a81ab0d AM |
1200 | } |
1201 | if ($fwhostsettings{'update'} eq 'on'){ | |
2a81ab0d | 1202 | print<<END; |
8013bd0a AM |
1203 | <form method='post'><input type='hidden' name='remark' value='$rem'><input type='hidden' name='grp_name' value='$grp'> |
1204 | <table width='100%' border='0'> | |
1205 | <tr><td width=50% valign='top'> | |
1206 | <table width='100%' border='0'> | |
2e99ab8b | 1207 | <tr><td width='1%'><input type='radio' name='grp2' value='std_net' id='DEFAULT_SRC_ADR' checked></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost stdnet'}</td><td><select name='DEFAULT_SRC_ADR' style='min-width:185px;'> |
2a81ab0d AM |
1208 | END |
1209 | foreach my $network (sort keys %defaultNetworks) | |
1210 | { | |
1211 | next if($defaultNetworks{$network}{'LOCATION'} eq "IPCOP"); | |
7326051e | 1212 | next if($defaultNetworks{$network}{'NAME'} eq "IPFire"); |
2a81ab0d AM |
1213 | print "<option value='$defaultNetworks{$network}{'NAME'}'"; |
1214 | print " selected='selected'" if ($fwhostsettings{'DEFAULT_SRC_ADR'} eq $defaultNetworks{$network}{'NAME'}); | |
7326051e AM |
1215 | my $defnet="$defaultNetworks{$network}{'NAME'}_NETADDRESS"; |
1216 | my $defsub="$defaultNetworks{$network}{'NAME'}_NETMASK"; | |
1217 | my $defsub1=&General::subtocidr($ownnet{$defsub}); | |
1218 | $ownnet{$defnet}='' if ($defaultNetworks{$network}{'NAME'} eq 'RED'); | |
1219 | if ($ownnet{$defnet}){ | |
1220 | print ">$network ($ownnet{$defnet}/$defsub1)</option>"; | |
1221 | }else{ | |
1222 | print ">$network</option>"; | |
1223 | } | |
2a81ab0d | 1224 | } |
8013bd0a AM |
1225 | print"</select></td></tr>"; |
1226 | if (! -z $confignet){ | |
2e99ab8b | 1227 | print"<tr><td><input type='radio' name='grp2' id='CUST_SRC_NET' value='cust_net' $checked{'grp2'}{'cust_net'}></td><td>$Lang::tr{'fwhost cust net'}</td><td><select name='CUST_SRC_NET' style='min-width:185px;'>"; |
eff2dbf8 | 1228 | foreach my $key (sort { ncmp($customnetwork{$a}[0],$customnetwork{$b}[0]) } keys %customnetwork) { |
8013bd0a AM |
1229 | print"<option>$customnetwork{$key}[0]</option>"; |
1230 | } | |
1231 | print"</select></td></tr>"; | |
2a81ab0d | 1232 | } |
8013bd0a | 1233 | if (! -z $confighost){ |
2e99ab8b | 1234 | print"<tr><td valign='top'><input type='radio' name='grp2' id='CUST_SRC_HOST' value='cust_host' $checked{'grp2'}{'cust_host'}></td><td valign='top'>$Lang::tr{'fwhost cust addr'}</td><td><select name='CUST_SRC_HOST' style='min-width:185px;'>"; |
eff2dbf8 | 1235 | foreach my $key (sort { ncmp($customhost{$a}[0],$customhost{$b}[0]) } keys %customhost) { |
8013bd0a AM |
1236 | print"<option>$customhost{$key}[0]</option>"; |
1237 | } | |
1238 | print"</select></td></tr>"; | |
1239 | } | |
1240 | print"</table>"; | |
1241 | #Inner table right | |
1242 | print"</td><td valign='top'><table width='100%' border='0'>"; | |
1243 | #OVPN networks | |
1244 | if (! -z $configccdnet){ | |
2e99ab8b | 1245 | print"<td width='1%'><input type='radio' name='grp2' id='OVPN_CCD_NET' value='ovpn_net' $checked{'grp2'}{'ovpn_net'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdnet'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_NET' style='min-width:185px;'>"; |
eff2dbf8 | 1246 | foreach my $key (sort { ncmp($ccdnet{$a}[0],$ccdnet{$b}[0]) } keys %ccdnet) |
8013bd0a AM |
1247 | { |
1248 | print"<option value='$ccdnet{$key}[0]'>$ccdnet{$key}[0]</option>"; | |
1249 | } | |
1250 | print"</select></td></tr>"; | |
2a81ab0d | 1251 | } |
8013bd0a | 1252 | #OVPN clients |
eff2dbf8 | 1253 | foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost) |
2a81ab0d AM |
1254 | { |
1255 | if ($ccdhost{$key}[33] ne ''){ | |
8013bd0a AM |
1256 | print"<td width='1%'><input type='radio' name='grp2' value='ovpn_host' $checked{'grp2'}{'ovpn_host'}></td><td nowrap='nowrap' width='16%'>$Lang::tr{'fwhost ccdhost'}</td><td nowrap='nowrap' width='1%'><select name='OVPN_CCD_HOST' style='min-width:185px;'>" if ($show eq ''); |
1257 | $show='1'; | |
2a81ab0d AM |
1258 | print"<option value='$ccdhost{$key}[1]'>$ccdhost{$key}[1]</option>"; |
1259 | } | |
1260 | } | |
8013bd0a AM |
1261 | if ($show eq '1'){$show='';print"</select></td></tr>";} |
1262 | #OVPN n2n networks | |
eff2dbf8 | 1263 | foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) { |
2a81ab0d | 1264 | if($ccdhost{$key}[3] eq 'net'){ |
2e99ab8b | 1265 | print"<td width='1%'><input type='radio' name='grp2' id='OVPN_N2N' value='ovpn_n2n' $checked{'grp2'}{'ovpn_n2n'}></td><td valign='top'>$Lang::tr{'fwhost ovpn_n2n'}</td><td colspan='3'><select name='OVPN_N2N' style='min-width:185px;'>" if ($show eq ''); |
8013bd0a | 1266 | $show='1'; |
2a81ab0d AM |
1267 | print"<option>$ccdhost{$key}[1]</option>"; |
1268 | } | |
1269 | } | |
8013bd0a AM |
1270 | if ($show eq '1'){$show='';print"</select></td></tr>";} |
1271 | #IPsec networks | |
eff2dbf8 | 1272 | foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) { |
2a81ab0d | 1273 | if ($ipsecconf{$key}[3] eq 'net'){ |
2e99ab8b | 1274 | print"<td valign='top'><input type='radio' name='grp2' id='IPSEC_NET' value='ipsec_net' $checked{'grp2'}{'ipsec_net'}></td><td valign='top'>$Lang::tr{'fwhost ipsec net'}</td><td><select name='IPSEC_NET' style='min-width:185px;'>" if ($show eq ''); |
8013bd0a | 1275 | $show='1'; |
2a81ab0d AM |
1276 | print"<option value='$ipsecconf{$key}[1]'>$ipsecconf{$key}[1]</option>"; |
1277 | } | |
1278 | } | |
8013bd0a AM |
1279 | if ($show eq '1'){$show='';print"</select></td></tr>";} |
1280 | print"</table>"; | |
1281 | print"</td></tr></table>"; | |
9168da6f | 1282 | print"<br><br><hr>"; |
2a81ab0d | 1283 | } |
8013bd0a | 1284 | print"<table border='0' width='100%'>"; |
43215686 | 1285 | print"<tr><td 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 |
1286 | &Header::closebox(); |
1287 | } | |
1288 | sub addservice | |
1289 | { | |
1290 | &error; | |
1291 | &showmenu; | |
1a8fde0e | 1292 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'}); |
2a81ab0d AM |
1293 | if ($fwhostsettings{'updatesrv'} eq 'on') |
1294 | { | |
1295 | $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'}; | |
1296 | $fwhostsettings{'oldsrvport'} = $fwhostsettings{'SRV_PORT'}; | |
1297 | $fwhostsettings{'oldsrvprot'} = $fwhostsettings{'PROT'}; | |
2aeb4b25 | 1298 | $fwhostsettings{'oldsrvicmp'} = $fwhostsettings{'ICMP'}; |
2a81ab0d AM |
1299 | } |
1300 | print<<END; | |
fda8c915 | 1301 | <table width='100%' border='0'><form method='post'> |
1a8fde0e | 1302 | <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 | 1303 | <tr><td width='10%' nowrap='nowrap'>$Lang::tr{'fwhost prot'}:</td><td><select name='PROT' id='protocol' > |
2a81ab0d AM |
1304 | END |
1305 | foreach ("TCP","UDP","ICMP") | |
1306 | { | |
1307 | if ($_ eq $fwhostsettings{'PROT'}) | |
1308 | { | |
1309 | print"<option selected>$_</option>"; | |
1310 | }else{ | |
1311 | print"<option>$_</option>"; | |
1312 | } | |
1313 | } | |
1314 | print<<END; | |
fda8c915 | 1315 | </select></td></tr></table> |
bfc84eb1 | 1316 | <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 |
1317 | END |
1318 | &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); | |
86a921ee | 1319 | print"<option value='All ICMP-Types'>$Lang::tr{'fwdfw all icmp'}</option>"; |
eff2dbf8 | 1320 | foreach my $key (sort { ncmp($icmptypes{$a}[0],$icmptypes{$b}[0]) }keys %icmptypes){ |
2aeb4b25 AM |
1321 | if ($icmptypes{$key}[0] eq $fwhostsettings{'oldsrvicmp'}){ |
1322 | print"<option selected>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1323 | }else{ | |
1324 | print"<option>$icmptypes{$key}[0] ($icmptypes{$key}[1])</option>"; | |
1325 | } | |
2a81ab0d | 1326 | } |
2a81ab0d | 1327 | print<<END; |
bfc84eb1 AM |
1328 | </select></td></tr></table></div> |
1329 | <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> | |
1330 | <table width='100%' border='0'><tr><td colspan='6'><br><hr></td></tr> | |
2a81ab0d AM |
1331 | <tr><td colspan='6' align='right'> |
1332 | END | |
1333 | if ($fwhostsettings{'updatesrv'} eq 'on') | |
1334 | { | |
1335 | print<<END; | |
7f5b2820 | 1336 | <input type='submit' value='$Lang::tr{'update'}'style='min-width:100px;' > |
2a81ab0d AM |
1337 | <input type='hidden' name='ACTION' value='updateservice'> |
1338 | <input type='hidden' name='oldsrvname' value='$fwhostsettings{'oldsrvname'}'> | |
1339 | <input type='hidden' name='oldsrvport' value='$fwhostsettings{'oldsrvport'}'> | |
2aeb4b25 AM |
1340 | <input type='hidden' name='oldsrvprot' value='$fwhostsettings{'oldsrvprot'}'> |
1341 | <input type='hidden' name='oldsrvicmp' value='$fwhostsettings{'oldsrvicmp'}'> | |
1342 | </form> | |
2a81ab0d | 1343 | END |
fda8c915 | 1344 | }else{ |
7f5b2820 | 1345 | print"<input type='submit' value='$Lang::tr{'save'}' style='min-width:100px;'><input type='hidden' name='ACTION' value='saveservice'></form>"; |
2a81ab0d AM |
1346 | } |
1347 | print<<END; | |
7f5b2820 | 1348 | <form style='display:inline;' method='post'><input type='submit' value='$Lang::tr{'fwhost back'}' style='min-width:100px;'></form></td></tr> |
2a81ab0d | 1349 | </table></form> |
2a81ab0d AM |
1350 | END |
1351 | &Header::closebox(); | |
1352 | &viewtableservice; | |
1353 | } | |
1354 | sub addservicegrp | |
1355 | { | |
1356 | &hint; | |
1357 | &error; | |
1358 | &showmenu; | |
1a8fde0e | 1359 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'}); |
2a81ab0d | 1360 | $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'}; |
2a81ab0d AM |
1361 | if ($fwhostsettings{'updatesrvgrp'} eq ''){ |
1362 | print<<END; | |
1363 | <table width='100%' border='0'><form method='post'> | |
1a8fde0e | 1364 | <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 AM |
1365 | <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='SRVGRP_REMARK' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width: 98%;'></td></tr> |
1366 | <tr><td colspan='2'><br><hr></tr> | |
2a81ab0d AM |
1367 | </table> |
1368 | END | |
1369 | }else{ | |
1370 | print<<END; | |
6c869961 | 1371 | <table width='100%' border='0'><form method='post' style='display:inline'> |
8013bd0a AM |
1372 | <tr><td width='10%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='text' name='srvgrp' value='$fwhostsettings{'SRVGRP_NAME'}' readonly size='14'></td><td width='3%'></td></tr> |
1373 | <tr><td width='10%'>$Lang::tr{'remark'}:</td><td><input type='text' name='newsrvrem' value='$fwhostsettings{'SRVGRP_REMARK'}' style='width:98%;'></td><td align='right'><input type='submit' value='$Lang::tr{'fwhost change'}'><input type='hidden' name='oldsrvrem' value='$fwhostsettings{'oldsrvgrpremark'}'><input type='hidden' name='ACTION' value='changesrvgrpremark' ></td></tr> | |
1374 | <tr><td colspan='3'><br><hr></td></td></tr> | |
6c869961 | 1375 | </table></form> |
2a81ab0d AM |
1376 | END |
1377 | } | |
1378 | if($fwhostsettings{'updatesrvgrp'} eq 'on'){ | |
2a81ab0d | 1379 | print<<END; |
6c869961 | 1380 | <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%'> |
82b837cf | 1381 | <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'add'}</td><td><select name='CUST_SRV' style='min-width:185px;'> |
2a81ab0d AM |
1382 | END |
1383 | &General::readhasharray("$configsrv", \%customservice); | |
82b837cf AM |
1384 | #Protocols for use in servicegroups |
1385 | print "<optgroup label='$Lang::tr{'fwhost cust service'}'>"; | |
eff2dbf8 | 1386 | foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0]) } keys %customservice) |
2a81ab0d AM |
1387 | { |
1388 | print "<option>$customservice{$key}[0]</option>"; | |
1389 | } | |
82b837cf AM |
1390 | print "</optgroup>"; |
1391 | print "<optgroup label='$Lang::tr{'protocol'}'>"; | |
1392 | print "<option>GRE</option>"; | |
1393 | print "<option>AH</option>"; | |
1394 | print "<option>ESP</option>"; | |
1395 | print "<option>IGMP</option>"; | |
1396 | print "<option>IPIP</option>"; | |
1397 | print "<option value='IPV6'>IPv6 encap</option>"; | |
1398 | print "</optgroup>"; | |
2a81ab0d AM |
1399 | print<<END; |
1400 | </select></td></tr> | |
5dd84c25 | 1401 | <tr><td colspan='4'><br><br></td></tr> |
2a81ab0d AM |
1402 | <tr><td colspan='4'><hr></td></tr> |
1403 | </table> | |
1404 | END | |
1405 | } | |
1406 | print<<END; | |
7f5b2820 AM |
1407 | <table width='100%' border='0'> |
1408 | <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 |
1409 | </table></form> |
1410 | END | |
2a81ab0d AM |
1411 | &Header::closebox(); |
1412 | } | |
1413 | # View | |
1414 | sub viewtablenet | |
1415 | { | |
1416 | if(! -z $confignet){ | |
1417 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'}); | |
1418 | &General::readhasharray("$confignet", \%customnetwork); | |
484269ce AM |
1419 | &General::readhasharray("$configgrp", \%customgrp); |
1420 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
1421 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
1422 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d AM |
1423 | if (!keys %customnetwork) |
1424 | { | |
1425 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
1426 | }else{ | |
1427 | print<<END; | |
05612a54 | 1428 | <table border='0' width='100%' cellspacing='0'> |
2e99ab8b | 1429 | <tr><td align='center'><b>$Lang::tr{'name'}</b></td><td align='center'><b>$Lang::tr{'fwhost netaddress'}</b></td><td align='center'><b>$Lang::tr{'remark'}</b></td><td align='center'><b>$Lang::tr{'used'}</b></td><td></td><td width='3%'></td></tr> |
2a81ab0d AM |
1430 | END |
1431 | } | |
1432 | my $count=0; | |
eff2dbf8 | 1433 | foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) { |
2a81ab0d AM |
1434 | if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) { |
1435 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
1436 | }elsif ($count % 2) | |
1437 | { | |
1438 | print" <tr bgcolor='$color{'color22'}'>"; | |
1439 | }else | |
1440 | { | |
1441 | print" <tr bgcolor='$color{'color20'}'>"; | |
1442 | } | |
72586f0f | 1443 | my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]); |
484269ce AM |
1444 | my $netcount=&getnetcount($customnetwork{$key}[0]); |
1445 | print"<td width='20%'><form method='post'>$customnetwork{$key}[0]</td><td width='15%' align='center'>".&Header::colorize($colnet)."</td><td width='40%'>$customnetwork{$key}[3]</td><td align='center'>$netcount x</td>"; | |
2a81ab0d | 1446 | print<<END; |
2a81ab0d AM |
1447 | <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /> |
1448 | <input type='hidden' name='ACTION' value='editnet'> | |
1449 | <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' /> | |
1450 | <input type='hidden' name='IP' value='$customnetwork{$key}[1]' /> | |
1451 | <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' /> | |
e5a058c1 | 1452 | <input type='hidden' name='NETREMARK' value='$customnetwork{$key}[3]' /> |
2a81ab0d AM |
1453 | </td></form> |
1454 | END | |
484269ce | 1455 | if($netcount == '0') |
2a81ab0d AM |
1456 | { |
1457 | print"<td width='1%'><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>"; | |
1458 | }else{ | |
2e99ab8b | 1459 | print"<td></td></tr>"; |
2a81ab0d AM |
1460 | } |
1461 | $count++; | |
1462 | } | |
1463 | print"</table>"; | |
1464 | &Header::closebox(); | |
1465 | } | |
1466 | ||
1467 | } | |
b119578f AM |
1468 | sub getcolor |
1469 | { | |
1470 | my $c=shift; | |
1471 | #Check if IP is part of OpenVPN N2N subnet | |
1472 | foreach my $key (sort keys %ccdhost){ | |
1473 | if ($ccdhost{$key}[3] eq 'net'){ | |
1474 | my ($a,$b) = split("/",$ccdhost{$key}[11]); | |
1475 | if (&General::IpInSubnet($c,$a,$b)){ | |
1476 | $tdcolor="style='color:$Header::colourovpn ;'"; | |
1477 | return $tdcolor; | |
1478 | } | |
1479 | } | |
1480 | } | |
1481 | #Check if IP is part of OpenVPN dynamic subnet | |
1482 | my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'}); | |
1483 | if (&General::IpInSubnet($c,$a,$b)){ | |
1484 | $tdcolor="style='color: $Header::colourovpn;'"; | |
1485 | return $tdcolor; | |
1486 | } | |
1487 | #Check if IP is part of OpenVPN static subnet | |
1488 | foreach my $key (sort keys %ccdnet){ | |
1489 | my ($a,$b) = split("/",$ccdnet{$key}[1]); | |
1490 | $b =&General::iporsubtodec($b); | |
1491 | if (&General::IpInSubnet($c,$a,$b)){ | |
1492 | $tdcolor="style='color: $Header::colourovpn;'"; | |
1493 | return $tdcolor; | |
1494 | } | |
1495 | } | |
1496 | #Check if IP is part of IPsec RW network | |
1497 | if ($ipsecsettings{'RW_NET'} ne ''){ | |
1498 | my ($a,$b) = split("/",$ipsecsettings{'RW_NET'}); | |
1499 | $b=&General::iporsubtodec($b); | |
1500 | if (&General::IpInSubnet($c,$a,$b)){ | |
1501 | $tdcolor="style='color: $Header::colourvpn;'"; | |
1502 | return $tdcolor; | |
1503 | } | |
1504 | } | |
1505 | #Check if IP is part of a IPsec N2N network | |
1506 | foreach my $key (sort keys %ipsecconf){ | |
1507 | my ($a,$b) = split("/",$ipsecconf{$key}[11]); | |
1508 | if (&General::IpInSubnet($c,$a,$b)){ | |
1509 | $tdcolor="style='color: $Header::colourvpn;'"; | |
1510 | return $tdcolor; | |
1511 | } | |
1512 | } | |
1513 | $tdcolor=''; | |
1514 | return $tdcolor; | |
1515 | } | |
2a81ab0d AM |
1516 | sub viewtablehost |
1517 | { | |
1518 | if (! -z $confighost){ | |
1519 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'}); | |
1520 | &General::readhasharray("$confighost", \%customhost); | |
b119578f AM |
1521 | &General::readhasharray("$configccdnet", \%ccdnet); |
1522 | &General::readhasharray("$configccdhost", \%ccdhost); | |
484269ce AM |
1523 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
1524 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
1525 | &General::readhasharray("$fwconfigout", \%fwout); | |
1526 | &General::readhasharray("$configgrp", \%customgrp); | |
2a81ab0d AM |
1527 | if (!keys %customhost) |
1528 | { | |
1529 | print "<center><b>$Lang::tr{'fwhost empty'}</b>"; | |
1530 | }else{ | |
1531 | print<<END; | |
05612a54 | 1532 | <table border='0' width='100%' cellspacing='0'> |
2e99ab8b | 1533 | <tr><td align='center'><b>$Lang::tr{'name'}</b></td><td align='center'><b>$Lang::tr{'fwhost ip_mac'}</b></td><td align='center'><b>$Lang::tr{'remark'}</b></td><td align='center'><b>$Lang::tr{'used'}</b></td><td></td><td width='3%'></td></tr> |
2a81ab0d AM |
1534 | END |
1535 | } | |
1536 | my $count=0; | |
eff2dbf8 | 1537 | foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) { |
2a81ab0d AM |
1538 | if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) { |
1539 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
1540 | }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
1541 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
1542 | my ($ip,$sub)=split(/\//,$customhost{$key}[2]); | |
e3580608 | 1543 | $customhost{$key}[4]=~s/\s+//g; |
484269ce AM |
1544 | my $hostcount=0; |
1545 | $hostcount=&gethostcount($customhost{$key}[0]); | |
1546 | print"<td width='20%'>$customhost{$key}[0]</td><td width='20%' align='center' ".&getcolor($ip).">".&Header::colorize($ip)."</td><td width='50%' align='left'>$customhost{$key}[3]</td><td align='center'>$hostcount x</td>"; | |
2a81ab0d | 1547 | print<<END; |
2e99ab8b | 1548 | <td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /> |
2a81ab0d AM |
1549 | <input type='hidden' name='ACTION' value='edithost' /> |
1550 | <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' /> | |
1551 | <input type='hidden' name='IP' value='$ip' /> | |
1552 | <input type='hidden' name='type' value='$customhost{$key}[1]' /> | |
e3580608 | 1553 | <input type='hidden' name='HOSTREMARK' value='$customhost{$key}[3]' /> |
2e99ab8b | 1554 | </form></td> |
2a81ab0d | 1555 | END |
484269ce | 1556 | if($hostcount == '0') |
2a81ab0d AM |
1557 | { |
1558 | print"<td width='1%'><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>"; | |
1559 | }else{ | |
1560 | print"<td width='1%'></td></tr>"; | |
1561 | } | |
1562 | $count++; | |
1563 | } | |
1564 | print"</table>"; | |
1565 | &Header::closebox(); | |
1566 | } | |
1567 | } | |
1568 | sub viewtablegrp | |
1569 | { | |
1570 | if(! -z "$configgrp"){ | |
1571 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'}); | |
1572 | &General::readhasharray("$configgrp", \%customgrp); | |
1573 | &General::readhasharray("$configipsec", \%ipsecconf); | |
1574 | &General::readhasharray("$configccdhost", \%ccdhost); | |
1575 | &General::readhasharray("$configccdnet", \%ccdnet); | |
1576 | &General::readhasharray("$confighost", \%customhost); | |
1577 | &General::readhasharray("$confignet", \%customnetwork); | |
484269ce AM |
1578 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
1579 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
1580 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d AM |
1581 | my @grp=(); |
1582 | my $helper=''; | |
8f204435 | 1583 | my $count=1; |
2a81ab0d AM |
1584 | my $grpname; |
1585 | my $remark; | |
12dcfbbd | 1586 | my $number; |
2cee2462 | 1587 | my $delflag; |
2a81ab0d | 1588 | if (!keys %customgrp) |
484269ce | 1589 | { |
f195a8d7 | 1590 | print "<center><b>$Lang::tr{'fwhost err emptytable'}</b>"; |
2a81ab0d | 1591 | }else{ |
0c2cf9e2 | 1592 | foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ |
2a81ab0d AM |
1593 | $count++; |
1594 | if ($helper ne $customgrp{$key}[0]){ | |
2cee2462 | 1595 | $delflag='0'; |
eff2dbf8 | 1596 | foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ |
2cee2462 AM |
1597 | if ($customgrp{$key}[0] eq $customgrp{$key1}[0]) |
1598 | { | |
1599 | $delflag++; | |
1600 | } | |
d0815ce4 | 1601 | if($delflag > 1){ |
d13a9363 AM |
1602 | last; |
1603 | } | |
2cee2462 | 1604 | } |
8f204435 | 1605 | $number=1; |
f195a8d7 | 1606 | if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};} |
2a81ab0d | 1607 | $grpname=$customgrp{$key}[0]; |
6c869961 | 1608 | $remark="$customgrp{$key}[1]"; |
0c2cf9e2 | 1609 | if($count gt 1){ print"</table>";} |
2e99ab8b | 1610 | print "<br><b><u>$grpname</u></b> "; |
2a81ab0d | 1611 | print " <b>$Lang::tr{'remark'}:</b>  $remark   " if ($remark ne ''); |
484269ce AM |
1612 | my $netgrpcount=&getnetcount($grpname); |
1613 | print "<b>$Lang::tr{'used'}:</b> $netgrpcount x"; | |
1614 | if($netgrpcount == '0') | |
2a81ab0d AM |
1615 | { |
1616 | 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>"; | |
1617 | } | |
1618 | 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>"; | |
05612a54 | 1619 | print"<table width='100%' style='border: 1px solid #CCCCCC;' rules='none' cellspacing='0'><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'ip address'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost type'}</td><td></td></tr>"; |
2a81ab0d | 1620 | } |
2cee2462 | 1621 | |
2a81ab0d AM |
1622 | if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) { |
1623 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
6c869961 AM |
1624 | }elsif ($count %2 == 0){ |
1625 | print"<tr bgcolor='$color{'color22'}'>"; | |
1626 | }else{ | |
1627 | print"<tr bgcolor='$color{'color20'}'>"; | |
1628 | } | |
2a81ab0d AM |
1629 | my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]); |
1630 | if ($ip eq ''){print"<tr bgcolor='${Header::colouryellow}'>";} | |
05612a54 | 1631 | print "<td width='39%' align='left'>"; |
2a81ab0d AM |
1632 | if($customgrp{$key}[3] eq 'Standard Network'){ |
1633 | print &get_name($customgrp{$key}[2])."</td>"; | |
1634 | }else{ | |
1635 | print "$customgrp{$key}[2]</td>"; | |
1636 | } | |
f195a8d7 | 1637 | if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){ |
f833ef46 | 1638 | print "<td align='center'>$Lang::tr{'fwhost deleted'}</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>"; |
2a81ab0d | 1639 | }else{ |
72586f0f AM |
1640 | my ($colip,$colsub) = split("/",$ip); |
1641 | $ip="$colip/".&General::subtocidr($colsub) if ($colsub); | |
eb95ce89 | 1642 | print"<td align='center' ".&getcolor($colip).">".&Header::colorize($ip)."</td><td align='center'>$customgrp{$key}[3]</td><td width='1%'><form method='post'>"; |
2a81ab0d | 1643 | } |
484269ce | 1644 | if ($delflag > 1 && $ip ne ''){ |
2a81ab0d AM |
1645 | print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />"; |
1646 | } | |
e3580608 | 1647 | print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='grpcnt' value='$customgrp{$key}[4]'><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 AM |
1648 | |
1649 | $helper=$customgrp{$key}[0]; | |
12dcfbbd | 1650 | $number++; |
2a81ab0d AM |
1651 | } |
1652 | print"</table>"; | |
2a81ab0d AM |
1653 | } |
1654 | &Header::closebox(); | |
1655 | } | |
1656 | ||
1657 | } | |
1658 | sub viewtableservice | |
1659 | { | |
1660 | my $count=0; | |
3a162dc1 | 1661 | my $srvcount; |
2a81ab0d AM |
1662 | if(! -z "$configsrv") |
1663 | { | |
1664 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'}); | |
1665 | &General::readhasharray("$configsrv", \%customservice); | |
3a162dc1 AM |
1666 | &General::readhasharray("$configsrvgrp", \%customservicegrp); |
1667 | &General::readhasharray("$fwconfigfwd", \%fwfwd); | |
1668 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
1669 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d | 1670 | print<<END; |
05612a54 | 1671 | <table width='100%' border='0' cellspacing='0'> |
2e99ab8b | 1672 | <tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</b></td><td align='center'><b>$Lang::tr{'fwhost prot'}</b></td><td align='center'><b>$Lang::tr{'fwhost port'}</b></td><td align='center'><b>ICMP</b></td><td align='center'><b>$Lang::tr{'fwhost used'}</b></td><td></td><td width='3%'></td></tr> |
2a81ab0d | 1673 | END |
eff2dbf8 | 1674 | foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice) |
2a81ab0d AM |
1675 | { |
1676 | $count++; | |
1677 | if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) { | |
1678 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
1679 | }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}else{ print" <tr bgcolor='$color{'color20'}'>";} | |
1680 | print<<END; | |
1681 | <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'> | |
1682 | END | |
3a162dc1 AM |
1683 | #Neuer count |
1684 | $srvcount=&getsrvcount($customservice{$key}[0]); | |
86a921ee AM |
1685 | if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};} |
1686 | elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];} | |
2a81ab0d | 1687 | print<<END; |
3a162dc1 | 1688 | </td><td align='center'>$srvcount x</td> |
2a81ab0d AM |
1689 | <td width='1%'><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' /> |
1690 | <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' /> | |
1691 | <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' /> | |
2aeb4b25 AM |
1692 | <input type='hidden' name='PROT' value='$customservice{$key}[2]' /> |
1693 | <input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td> | |
2a81ab0d | 1694 | END |
3a162dc1 | 1695 | if ($srvcount eq '0') |
2a81ab0d AM |
1696 | { |
1697 | print"<td width='1%'><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>"; | |
1698 | }else{ | |
1699 | print"<td></td></tr>"; | |
1700 | } | |
1701 | } | |
1702 | print"</table>"; | |
1703 | &Header::closebox(); | |
1704 | } | |
1705 | } | |
1706 | sub viewtableservicegrp | |
1707 | { | |
1708 | my $count=0; | |
1709 | my $grpname; | |
1710 | my $remark; | |
1711 | my $helper; | |
937d4e08 AM |
1712 | my $port; |
1713 | my $protocol; | |
c7043621 | 1714 | my $delflag; |
3a162dc1 | 1715 | my $grpcount=0; |
2a81ab0d | 1716 | if (! -z $configsrvgrp){ |
2a81ab0d AM |
1717 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'}); |
1718 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
937d4e08 | 1719 | &General::readhasharray("$configsrv", \%customservice); |
3a162dc1 AM |
1720 | &General::readhasharray("$fwconfigfwd", \%fwfwd); |
1721 | &General::readhasharray("$fwconfiginp", \%fwinp); | |
1722 | &General::readhasharray("$fwconfigout", \%fwout); | |
2a81ab0d | 1723 | my $number= keys %customservicegrp; |
fe2bae3b | 1724 | foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){ |
2a81ab0d AM |
1725 | $count++; |
1726 | if ($helper ne $customservicegrp{$key}[0]){ | |
3a162dc1 AM |
1727 | #Get used groupcounter |
1728 | $grpcount=&getsrvcount($customservicegrp{$key}[0]); | |
d13a9363 | 1729 | $delflag=0; |
eff2dbf8 | 1730 | foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){ |
d13a9363 AM |
1731 | if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0]) |
1732 | { | |
1733 | $delflag++; | |
1734 | } | |
1735 | if($delflag > 1){ | |
1736 | last; | |
1737 | } | |
1738 | } | |
2a81ab0d | 1739 | $grpname=$customservicegrp{$key}[0]; |
6c869961 AM |
1740 | if ($customservicegrp{$key}[2] eq "none"){ |
1741 | $customservicegrp{$key}[2]=$Lang::tr{'fwhost empty'}; | |
0b54aaed AM |
1742 | $port=''; |
1743 | $protocol=''; | |
6c869961 AM |
1744 | } |
1745 | $remark="$customservicegrp{$key}[1]"; | |
2a81ab0d | 1746 | if($count >=2){print"</table>";} |
2e99ab8b AM |
1747 | print "<br><b><u>$grpname</u></b> "; |
1748 | print "<b>$Lang::tr{'remark'}:</b> $remark " if ($remark ne ''); | |
3a162dc1 AM |
1749 | print " <b>$Lang::tr{'used'}:</b> $grpcount x"; |
1750 | if($grpcount == '0') | |
2a81ab0d AM |
1751 | { |
1752 | 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>"; | |
1753 | } | |
1754 | 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>"; | |
05612a54 | 1755 | print"<table width='100%' style='border: 1px solid #CCCCCC;' rules='none' cellspacing='0'><tr><td align='center'><b>Name</b></td><td align='center'><b>$Lang::tr{'port'}</b></td><td align='center' width='25%'><b>$Lang::tr{'fwhost prot'}</td><td></td></tr>"; |
2a81ab0d AM |
1756 | } |
1757 | if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) { | |
1758 | print" <tr bgcolor='${Header::colouryellow}'>"; | |
6c869961 | 1759 | }elsif ($count %2 == 0){ |
0f869e32 AM |
1760 | print"<tr bgcolor='$color{'color22'}'>"; |
1761 | }else{ | |
1762 | print"<tr bgcolor='$color{'color20'}'>"; | |
1763 | } | |
82b837cf AM |
1764 | #Set fields if we use protocols in servicegroups |
1765 | if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){ | |
1766 | $port='-'; | |
1767 | } | |
1768 | if ($customservicegrp{$key}[2] eq 'GRE'){$protocol='GRE';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} GRE";} | |
1769 | if ($customservicegrp{$key}[2] eq 'ESP'){$protocol='ESP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} ESP";} | |
1770 | if ($customservicegrp{$key}[2] eq 'AH'){$protocol='AH';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} AH";} | |
1771 | if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";} | |
1772 | if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";} | |
1773 | if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";} | |
0f869e32 | 1774 | print "<td width='39%'>$customservicegrp{$key}[2]</td>"; |
937d4e08 AM |
1775 | foreach my $srv (sort keys %customservice){ |
1776 | if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){ | |
1777 | $protocol=$customservice{$srv}[2]; | |
1778 | $port=$customservice{$srv}[1]; | |
1779 | last; | |
1780 | } | |
1781 | } | |
1782 | print"<td align='center'>$port</td><td align='center'>$protocol</td><td width='1%'><form method='post'>"; | |
64e822fb | 1783 | if ($delflag gt '1'){ |
0f869e32 AM |
1784 | print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />"; |
1785 | } | |
82b837cf | 1786 | print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>"; |
fe2bae3b | 1787 | if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){ |
3a162dc1 | 1788 | print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>"; |
82b837cf | 1789 | }else{ |
3a162dc1 | 1790 | print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>"; |
82b837cf | 1791 | } |
0f869e32 | 1792 | $helper=$customservicegrp{$key}[0]; |
2a81ab0d AM |
1793 | } |
1794 | print"</table>"; | |
1795 | &Header::closebox(); | |
1796 | } | |
1797 | } | |
1798 | # Check | |
1799 | sub checkname | |
1800 | { | |
1801 | my %hash=%{(shift)}; | |
1802 | foreach my $key (keys %hash) { | |
1803 | if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){ | |
1804 | return 0; | |
1805 | } | |
1806 | } | |
1807 | return 1; | |
1808 | ||
1809 | } | |
f195a8d7 AM |
1810 | sub checkgroup |
1811 | { | |
3a162dc1 | 1812 | &General::readhasharray("$configsrvgrp", \%customservicegrp ); |
f195a8d7 | 1813 | my $name=shift; |
3a162dc1 AM |
1814 | foreach my $key (keys %customservicegrp) { |
1815 | if($customservicegrp{$key}[0] eq $name){ | |
1816 | return 0; | |
1817 | } | |
1818 | } | |
1819 | return 1; | |
1820 | } | |
1821 | sub checkservice | |
1822 | { | |
1823 | &General::readhasharray("$configsrv", \%customservice ); | |
1824 | my $name=shift; | |
1825 | foreach my $key (keys %customservice) { | |
1826 | if($customservice{$key}[0] eq $name){ | |
f195a8d7 AM |
1827 | return 0; |
1828 | } | |
1829 | } | |
1830 | return 1; | |
1831 | } | |
2a81ab0d AM |
1832 | sub checkip |
1833 | { | |
1834 | ||
1835 | my %hash=%{(shift)}; | |
1836 | my $a=shift; | |
1837 | foreach my $key (keys %hash) { | |
1838 | if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){ | |
1839 | return 0; | |
1840 | } | |
1841 | } | |
1842 | return 1; | |
1843 | } | |
1844 | sub checksubnet | |
1845 | { | |
2a81ab0d AM |
1846 | my %hash=%{(shift)}; |
1847 | &General::readhasharray("$confignet", \%hash); | |
1848 | foreach my $key (keys %hash) { | |
1849 | if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2])) | |
1850 | { | |
1851 | return 1; | |
1852 | } | |
1853 | } | |
1854 | return 0; | |
1855 | } | |
1856 | sub checkservicegroup | |
1857 | { | |
1858 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
2a81ab0d | 1859 | #check name |
7772ae73 | 1860 | if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'})) |
2a81ab0d AM |
1861 | { |
1862 | $errormessage.=$Lang::tr{'fwhost err name'}."<br>"; | |
1863 | return $errormessage; | |
1864 | } | |
2a81ab0d AM |
1865 | #check empty selectbox |
1866 | if (keys %customservice lt 1) | |
1867 | { | |
1868 | $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>"; | |
1869 | } | |
2a81ab0d AM |
1870 | #check if name already exists |
1871 | if ($fwhostsettings{'updatesrvgrp'} ne 'on'){ | |
1872 | foreach my $key (keys %customservicegrp) { | |
1873 | if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){ | |
1874 | $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>"; | |
1875 | ||
1876 | } | |
1877 | } | |
1878 | } | |
1879 | #check if service already exists in group | |
1880 | foreach my $key (keys %customservicegrp) { | |
13e5dda4 AM |
1881 | if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){ |
1882 | $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>"; | |
2a81ab0d | 1883 | } |
13e5dda4 | 1884 | } |
2a81ab0d AM |
1885 | return $errormessage; |
1886 | } | |
1887 | sub error | |
1888 | { | |
1889 | if ($errormessage) { | |
1890 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
1891 | print "<class name='base'>$errormessage\n"; | |
1892 | print " </class>\n"; | |
1893 | &Header::closebox(); | |
1894 | } | |
1895 | } | |
1896 | sub hint | |
1897 | { | |
1898 | if ($hint) { | |
1899 | &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'}); | |
1900 | print "<class name='base'>$hint\n"; | |
1901 | print " </class>\n"; | |
1902 | &Header::closebox(); | |
1903 | } | |
1904 | } | |
1905 | sub get_name | |
1906 | { | |
1907 | my $val=shift; | |
1908 | &General::setup_default_networks(\%defaultNetworks); | |
1909 | foreach my $network (sort keys %defaultNetworks) | |
1910 | { | |
1911 | return "$network" if ($val eq $defaultNetworks{$network}{'NAME'}); | |
1912 | } | |
1913 | } | |
484269ce AM |
1914 | sub gethostcount |
1915 | { | |
1916 | my $searchstring=shift; | |
1917 | my $srvcounter=0; | |
1918 | #Count services used in servicegroups | |
1919 | foreach my $key (keys %customgrp) { | |
1920 | if($customgrp{$key}[2] eq $searchstring){ | |
1921 | $srvcounter++; | |
1922 | } | |
1923 | } | |
1924 | #Count services used in firewall - config | |
1925 | foreach my $key1 (keys %fwfwd) { | |
1926 | if($fwfwd{$key1}[4] eq $searchstring){ | |
1927 | $srvcounter++; | |
1928 | } | |
1929 | if($fwfwd{$key1}[6] eq $searchstring){ | |
1930 | $srvcounter++; | |
1931 | } | |
1932 | } | |
1933 | #Count services used in firewall - input | |
1934 | foreach my $key2 (keys %fwinp) { | |
1935 | if($fwinp{$key2}[4] eq $searchstring){ | |
1936 | $srvcounter++; | |
1937 | } | |
1938 | if($fwinp{$key2}[6] eq $searchstring){ | |
1939 | $srvcounter++; | |
1940 | } | |
1941 | } | |
1942 | #Count services used in firewall - outgoing | |
1943 | foreach my $key3 (keys %fwout) { | |
1944 | if($fwout{$key3}[4] eq $searchstring){ | |
1945 | $srvcounter++; | |
1946 | } | |
1947 | if($fwout{$key3}[6] eq $searchstring){ | |
1948 | $srvcounter++; | |
1949 | } | |
1950 | } | |
1951 | return $srvcounter; | |
1952 | } | |
1953 | sub getnetcount | |
1954 | { | |
1955 | my $searchstring=shift; | |
1956 | my $srvcounter=0; | |
1957 | #Count services used in servicegroups | |
1958 | foreach my $key (keys %customgrp) { | |
1959 | if($customgrp{$key}[2] eq $searchstring){ | |
1960 | $srvcounter++; | |
1961 | } | |
1962 | } | |
1963 | #Count services used in firewall - config | |
1964 | foreach my $key1 (keys %fwfwd) { | |
1965 | if($fwfwd{$key1}[4] eq $searchstring){ | |
1966 | $srvcounter++; | |
1967 | } | |
1968 | if($fwfwd{$key1}[6] eq $searchstring){ | |
1969 | $srvcounter++; | |
1970 | } | |
1971 | } | |
1972 | #Count services used in firewall - input | |
1973 | foreach my $key2 (keys %fwinp) { | |
1974 | if($fwinp{$key2}[4] eq $searchstring){ | |
1975 | $srvcounter++; | |
1976 | } | |
1977 | if($fwinp{$key2}[6] eq $searchstring){ | |
1978 | $srvcounter++; | |
1979 | } | |
1980 | } | |
1981 | #Count services used in firewall - outgoing | |
1982 | foreach my $key3 (keys %fwout) { | |
1983 | if($fwout{$key3}[4] eq $searchstring){ | |
1984 | $srvcounter++; | |
1985 | } | |
1986 | if($fwout{$key3}[6] eq $searchstring){ | |
1987 | $srvcounter++; | |
1988 | } | |
1989 | } | |
1990 | return $srvcounter; | |
1991 | } | |
3a162dc1 AM |
1992 | sub getsrvcount |
1993 | { | |
1994 | my $searchstring=shift; | |
1995 | my $srvcounter=0; | |
1996 | #Count services used in servicegroups | |
1997 | foreach my $key (keys %customservicegrp) { | |
1998 | if($customservicegrp{$key}[2] eq $searchstring){ | |
1999 | $srvcounter++; | |
2000 | } | |
2001 | } | |
2002 | #Count services used in firewall - config | |
2003 | foreach my $key1 (keys %fwfwd) { | |
2004 | if($fwfwd{$key1}[15] eq $searchstring){ | |
2005 | $srvcounter++; | |
2006 | } | |
2007 | } | |
2008 | #Count services used in firewall - input | |
2009 | foreach my $key2 (keys %fwinp) { | |
2010 | if($fwinp{$key2}[15] eq $searchstring){ | |
2011 | $srvcounter++; | |
2012 | } | |
2013 | } | |
2014 | #Count services used in firewall - outgoing | |
2015 | foreach my $key3 (keys %fwout) { | |
2016 | if($fwout{$key3}[15] eq $searchstring){ | |
2017 | $srvcounter++; | |
2018 | } | |
2019 | } | |
2020 | return $srvcounter; | |
2021 | } | |
2a81ab0d AM |
2022 | sub deletefromgrp |
2023 | { | |
2024 | my $target=shift; | |
2025 | my $config=shift; | |
2026 | my %hash=(); | |
2027 | &General::readhasharray("$config",\%hash); | |
2028 | foreach my $key (keys %hash) { | |
2a81ab0d | 2029 | if($hash{$key}[2] eq $target){ |
2a81ab0d | 2030 | delete $hash{$key}; |
2a81ab0d AM |
2031 | } |
2032 | } | |
2033 | &General::writehasharray("$config",\%hash); | |
2034 | ||
2035 | } | |
2036 | sub plausicheck | |
2037 | { | |
2a81ab0d AM |
2038 | my $edit=shift; |
2039 | #check hostname | |
d0815ce4 | 2040 | if (!&validhostname($fwhostsettings{'HOSTNAME'})) |
2a81ab0d AM |
2041 | { |
2042 | $errormessage=$errormessage.$Lang::tr{'fwhost err name'}; | |
2043 | $fwhostsettings{'BLK_IP'}='readonly'; | |
2044 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
2045 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2046 | } | |
2047 | #check if name collides with CCD Netname | |
2a81ab0d AM |
2048 | &General::readhasharray("$configccdnet", \%ccdnet); |
2049 | foreach my $key (keys %ccdnet) { | |
2050 | if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){ | |
2051 | $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};; | |
2052 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
2053 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2054 | last; | |
2055 | } | |
2056 | } | |
2a81ab0d AM |
2057 | #check if IP collides with CCD NetIP |
2058 | if ($fwhostsettings{'type'} ne 'mac'){ | |
2059 | &General::readhasharray("$configccdnet", \%ccdnet); | |
2060 | foreach my $key (keys %ccdnet) { | |
2061 | my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'}; | |
2062 | if($ccdnet{$key}[1] eq $test){ | |
2063 | $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'}; | |
2064 | $fwhostsettings{'IP'} = $fwhostsettings{'orgip'}; | |
2065 | $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'}; | |
2066 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2067 | last; | |
2068 | } | |
2069 | } | |
2070 | } | |
2a81ab0d AM |
2071 | #check if name collides with CCD Hostname |
2072 | &General::readhasharray("$configccdhost", \%ccdhost); | |
2073 | foreach my $key (keys %ccdhost) { | |
2074 | my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]); | |
2075 | if($ip eq $fwhostsettings{'IP'}){ | |
2076 | $errormessage=$Lang::tr{'fwhost err isccdiphost'}; | |
2077 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2078 | last; | |
2079 | } | |
2080 | } | |
2081 | #check if IP collides with CCD HostIP (only hosts) | |
2082 | if ($edit eq 'edithost') | |
2083 | { | |
2084 | foreach my $key (keys %ccdhost) { | |
2085 | if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){ | |
2086 | $errormessage=$Lang::tr{'fwhost err isccdhost'}; | |
2087 | $fwhostsettings{'IP'} = $fwhostsettings{'orgname'}; | |
2088 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2089 | last; | |
2090 | } | |
2091 | } | |
2092 | } | |
2093 | #check if network with this name already exists | |
2094 | &General::readhasharray("$confignet", \%customnetwork); | |
2095 | if (!&checkname(\%customnetwork)) | |
2096 | { | |
2097 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'}; | |
2098 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; | |
2099 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2100 | } | |
2101 | #check if network ip already exists | |
2102 | if (!&checkip(\%customnetwork,1)) | |
2103 | { | |
2104 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'}; | |
2105 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} | |
2106 | } | |
2107 | #check if host with this name already exists | |
2108 | &General::readhasharray("$confighost", \%customhost); | |
2109 | if (!&checkname(\%customhost)) | |
2110 | { | |
0013abb0 | 2111 | $errormessage.="<br>".$Lang::tr{'fwhost err hostexist'}; |
2a81ab0d | 2112 | $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; |
ed73b87e | 2113 | if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;} |
2a81ab0d AM |
2114 | } |
2115 | #check if host with this ip already exists | |
2116 | if (!&checkip(\%customhost,2)) | |
2117 | { | |
2118 | $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'}; | |
2a81ab0d | 2119 | } |
2a81ab0d AM |
2120 | return; |
2121 | } | |
2122 | sub getipforgroup | |
2123 | { | |
2124 | my $name=$_[0], | |
2125 | my $type=$_[1]; | |
2126 | my $value; | |
2127 | ||
2128 | #get address from IPSEC NETWORK | |
2129 | if ($type eq 'IpSec Network'){ | |
2130 | foreach my $key (keys %ipsecconf) { | |
2131 | if ($ipsecconf{$key}[1] eq $name){ | |
2132 | return $ipsecconf{$key}[11]; | |
2133 | } | |
2134 | } | |
2135 | &deletefromgrp($name,$configgrp); | |
2136 | } | |
2137 | ||
2138 | #get address from IPSEC HOST | |
2139 | if ($type eq 'IpSec Host'){ | |
2140 | foreach my $key (keys %ipsecconf) { | |
2141 | if ($ipsecconf{$key}[1] eq $name){ | |
2142 | return $ipsecconf{$key}[10]; | |
2143 | } | |
2144 | } | |
2145 | &deletefromgrp($name,$configgrp); | |
2146 | } | |
2147 | ||
2148 | #get address from ovpn ccd Net-2-Net | |
2149 | if ($type eq 'OpenVPN N-2-N'){ | |
2150 | foreach my $key (keys %ccdhost) { | |
2151 | if($ccdhost{$key}[1] eq $name){ | |
2152 | my ($a,$b) = split ("/",$ccdhost{$key}[11]); | |
2153 | $b=&General::iporsubtodec($b); | |
2154 | return "$a/$b"; | |
2155 | } | |
2156 | } | |
2157 | &deletefromgrp($name,$configgrp); | |
2158 | } | |
2159 | ||
2160 | #get address from ovpn ccd static host | |
2161 | if ($type eq 'OpenVPN static host'){ | |
2162 | foreach my $key (keys %ccdhost) { | |
2163 | if($ccdhost{$key}[1] eq $name){ | |
2164 | my ($a,$b) = split (/\//,$ccdhost{$key}[33]); | |
2165 | $b=&General::iporsubtodec($b); | |
2166 | return "$a/$b"; | |
2167 | } | |
2168 | } | |
2169 | &deletefromgrp($name,$configgrp); | |
2170 | } | |
2171 | ||
2172 | #get address from ovpn ccd static net | |
2173 | if ($type eq 'OpenVPN static network'){ | |
2174 | foreach my $key (keys %ccdnet) { | |
2175 | if ($ccdnet{$key}[0] eq $name){ | |
2176 | my ($a,$b) = split (/\//,$ccdnet{$key}[1]); | |
2177 | $b=&General::iporsubtodec($b); | |
2178 | return "$a/$b"; | |
2179 | } | |
2180 | } | |
2181 | } | |
2182 | ||
2183 | #check custom addresses | |
2184 | if ($type eq 'Custom Host'){ | |
2185 | foreach my $key (keys %customhost) { | |
2186 | if ($customhost{$key}[0] eq $name){ | |
f1934a05 AM |
2187 | my ($ip,$sub) = split("/",$customhost{$key}[2]); |
2188 | return $ip; | |
2a81ab0d AM |
2189 | } |
2190 | } | |
2191 | } | |
2192 | ||
2193 | ##check custom networks | |
2194 | if ($type eq 'Custom Network'){ | |
2195 | foreach my $key (keys %customnetwork) { | |
2196 | if($customnetwork{$key}[0] eq $name){ | |
2197 | return $customnetwork{$key}[1]."/".$customnetwork{$key}[2]; | |
2198 | } | |
2199 | } | |
2200 | } | |
2201 | ||
2202 | #check standard networks | |
2203 | if ($type eq 'Standard Network'){ | |
2204 | if ($name =~ /OpenVPN/i){ | |
2205 | my %ovpn=(); | |
2206 | &General::readhash("${General::swroot}/ovpn/settings",\%ovpn); | |
2207 | return $ovpn{'DOVPN_SUBNET'}; | |
2208 | } | |
2209 | if ($name eq 'GREEN'){ | |
2210 | my %hash=(); | |
2211 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
2212 | return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'}; | |
2213 | } | |
2214 | if ($name eq 'BLUE'){ | |
2215 | my %hash=(); | |
2216 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
2217 | return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'}; | |
2218 | } | |
2219 | if ($name eq 'ORANGE'){ | |
2220 | my %hash=(); | |
2221 | &General::readhash("${General::swroot}/ethernet/settings",\%hash); | |
2222 | return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'}; | |
2223 | } | |
2224 | if ($name eq 'ALL'){ | |
2225 | return "0.0.0.0/0.0.0.0"; | |
2226 | } | |
2227 | if ($name =~ /IPsec/i){ | |
2228 | my %hash=(); | |
2229 | &General::readhash("${General::swroot}/vpn/settings",\%hash); | |
2230 | return $hash{'RW_NET'}; | |
2231 | } | |
2232 | } | |
2233 | } | |
fe2bae3b AM |
2234 | sub decrease |
2235 | { | |
2a81ab0d AM |
2236 | my $grp=$_[0]; |
2237 | &General::readhasharray("$confignet", \%customnetwork); | |
2238 | &General::readhasharray("$confighost", \%customhost); | |
2239 | foreach my $key (sort keys %customgrp ){ | |
2240 | if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){ | |
2241 | foreach my $key1 (sort keys %customnetwork){ | |
2242 | if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ | |
8013bd0a | 2243 | $customnetwork{$key1}[4]=$customnetwork{$key1}[4]-1; |
2a81ab0d AM |
2244 | last; |
2245 | } | |
2246 | } | |
2247 | } | |
2248 | ||
2249 | if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){ | |
2250 | foreach my $key2 (sort keys %customhost){ | |
2251 | if ($customhost{$key2}[0] eq $customgrp{$key}[2]){ | |
8013bd0a | 2252 | $customhost{$key2}[4]=$customhost{$key2}[4]-1; |
2a81ab0d AM |
2253 | last; |
2254 | } | |
2255 | } | |
2256 | ||
2257 | } | |
2258 | } | |
2259 | &General::writehasharray("$confignet", \%customnetwork); | |
2260 | &General::writehasharray("$confighost", \%customhost); | |
2261 | } | |
2262 | sub decreaseservice | |
2263 | { | |
2264 | my $grp=$_[0]; | |
2265 | &General::readhasharray("$configsrv", \%customservice); | |
2266 | &General::readhasharray("$configsrvgrp", \%customservicegrp); | |
2267 | ||
2268 | foreach my $key (sort keys %customservicegrp){ | |
2269 | if ($customservicegrp{$key}[0] eq $grp ){ | |
2270 | foreach my $key2 (sort keys %customservice){ | |
2271 | if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){ | |
2272 | $customservice{$key2}[4]--; | |
2273 | } | |
2274 | } | |
2275 | } | |
2276 | } | |
2277 | &General::writehasharray("$configsrv", \%customservice); | |
2278 | ||
2279 | } | |
2280 | sub checkports | |
2281 | { | |
2282 | ||
2283 | my %hash=%{(shift)}; | |
2284 | #check empty fields | |
2285 | if ($fwhostsettings{'SRV_NAME'} eq '' ){ | |
2286 | $errormessage=$Lang::tr{'fwhost err name1'}; | |
2287 | } | |
2288 | if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){ | |
2289 | $errormessage=$Lang::tr{'fwhost err port'}; | |
2290 | } | |
2291 | #check valid name | |
7772ae73 | 2292 | if (! &validhostname($fwhostsettings{'SRV_NAME'})){ |
2a81ab0d AM |
2293 | $errormessage="<br>".$Lang::tr{'fwhost err name'}; |
2294 | } | |
2295 | #change dashes with : | |
2296 | $fwhostsettings{'SRV_PORT'}=~ tr/-/:/; | |
2297 | ||
2298 | if ($fwhostsettings{'SRV_PORT'} eq "*") { | |
2299 | $fwhostsettings{'SRV_PORT'} = "1:65535"; | |
2300 | } | |
2301 | if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) { | |
2302 | $fwhostsettings{'SRV_PORT'} = "1:$2"; | |
2303 | } | |
2304 | if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) { | |
2305 | $fwhostsettings{'SRV_PORT'} = "$1:65535"; | |
2306 | } | |
2307 | if($fwhostsettings{'PROT'} ne 'ICMP'){ | |
2308 | $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src'); | |
2309 | } | |
2310 | # a new service has to have a different name | |
2311 | foreach my $key (keys %hash){ | |
2312 | if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){ | |
2313 | $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'}; | |
2314 | last; | |
2315 | } | |
2316 | } | |
2317 | return $errormessage; | |
2318 | } | |
2319 | sub validhostname | |
2320 | { | |
2321 | # Checks a hostname against RFC1035 | |
2322 | my $hostname = $_[0]; | |
2323 | ||
2324 | # Each part should be at least two characters in length | |
2325 | # but no more than 63 characters | |
2326 | if (length ($hostname) < 1 || length ($hostname) > 63) { | |
2327 | return 0;} | |
2328 | # Only valid characters are a-z, A-Z, 0-9 and - | |
d0815ce4 | 2329 | if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_.;()\/\s]*$/) { |
2a81ab0d AM |
2330 | return 0;} |
2331 | # First character can only be a letter or a digit | |
2332 | if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) { | |
2333 | return 0;} | |
2334 | # Last character can only be a letter or a digit | |
7772ae73 | 2335 | if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) { |
2a81ab0d AM |
2336 | return 0;} |
2337 | return 1; | |
2338 | } | |
6c869961 AM |
2339 | sub validremark |
2340 | { | |
2341 | # Checks a hostname against RFC1035 | |
2342 | my $remark = $_[0]; | |
2343 | # Each part should be at least two characters in length | |
2344 | # but no more than 63 characters | |
2345 | if (length ($remark) < 1 || length ($remark) > 255) { | |
2346 | return 0;} | |
2347 | # Only valid characters are a-z, A-Z, 0-9 and - | |
d928d795 | 2348 | if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) { |
6c869961 AM |
2349 | return 0;} |
2350 | # First character can only be a letter or a digit | |
2351 | if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) { | |
2352 | return 0;} | |
2353 | # Last character can only be a letter or a digit | |
d928d795 | 2354 | if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) { |
6c869961 AM |
2355 | return 0;} |
2356 | return 1; | |
2357 | } | |
2a81ab0d AM |
2358 | &Header::closebigbox(); |
2359 | &Header::closepage(); |