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