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