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