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