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