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