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