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