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