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