Forward Firewall: added new files
[people/teissler/ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
CommitLineData
2a81ab0d
AM
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2011 IPFire Team <info@ipfire.org> #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21# New function for forwarding firewall. To make it comfortable to create #
22# rules, we need "spelling names" for single Hosts. If you have any questions #
23# <amarx@ipfire.org> #
24###############################################################################
25use strict;
26
27# enable only the following on debugging purpose
28use warnings;
29use CGI::Carp 'fatalsToBrowser';
30no warnings 'uninitialized';
31require '/var/ipfire/general-functions.pl';
32require "${General::swroot}/lang.pl";
33require "${General::swroot}/header.pl";
34
35my %fwhostsettings=();
36my %customnetwork=();
37my %customhost=();
38my %customgrp=();
39my %customservice=();
40my %customservicegrp=();
41my %ccdnet=();
42my %ccdhost=();
43my %ipsecconf=();
44my %icmptypes=();
45my %color=();
46my %defaultNetworks=();
47my %mainsettings=();
48my %ownnet=();
49my %ipsecsettings=();
50
51my $errormessage;
52my $hint;
53my $update=0;
54my $confignet = "${General::swroot}/fwhosts/customnetworks";
55my $confighost = "${General::swroot}/fwhosts/customhosts";
56my $configgrp = "${General::swroot}/fwhosts/customgroups";
57my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
58my $configccdhost = "${General::swroot}/ovpn/ovpnconfig";
59my $configipsec = "${General::swroot}/vpn/config";
60my $configsrv = "${General::swroot}/fwhosts/customservices";
61my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
62
63unless (-e $confignet) { system("touch $confignet"); }
64unless (-e $confighost) { system("touch $confighost"); }
65unless (-e $configgrp) { system("touch $configgrp"); }
66unless (-e $configsrv) { system("touch $configsrv"); }
67unless (-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
80if ($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}
99if ($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}
122if ($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
178if ($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}
321if ($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}
458if ($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}
658if ($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}
695if ($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
781if ($fwhostsettings{'ACTION'} eq 'editnet')
782{
783 &addnet;
784 &viewtablenet;
785}
786if ($fwhostsettings{'ACTION'} eq 'edithost')
787{
788 &addhost;
789 &viewtablehost;
790}
791if ($fwhostsettings{'ACTION'} eq 'editgrp')
792{
793 $fwhostsettings{'update'}='on';
794 &addgrp;
795 &viewtablegrp;
796}
797if ($fwhostsettings{'ACTION'} eq 'editservice')
798{
799 $fwhostsettings{'updatesrv'}='on';
800 &addservice;
801}
802if ($fwhostsettings{'ACTION'} eq 'editservicegrp')
803{
804 $fwhostsettings{'updatesrvgrp'} = 'on';
805 &addservicegrp;
806 &viewtableservicegrp;
807}
808# reset
809if ($fwhostsettings{'ACTION'} eq 'resetnet')
810{
811 $fwhostsettings{'HOSTNAME'} ="";
812 $fwhostsettings{'IP'} ="";
813 $fwhostsettings{'SUBNET'} ="";
814 &showmenu;
815}
816if ($fwhostsettings{'ACTION'} eq 'resethost')
817{
818 $fwhostsettings{'HOSTNAME'} ="";
819 $fwhostsettings{'IP'} ="";
820 $fwhostsettings{'type'} ="";
821 &showmenu;
822}
823# delete
824if ($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}
837if ($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}
851if ($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}
885if ($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}
901if ($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}
917if ($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}
933if ($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}
957if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'})
958{
959 &addnet;
960 &viewtablenet;
961}
962if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newhost'})
963{
964 &addhost;
965 &viewtablehost;
966}
967if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newgrp'})
968{
969 &addgrp;
970 &viewtablegrp;
971}
972if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservice'})
973{
974 &addservice;
975}
976if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newservicegrp'})
977{
978 &addservicegrp;
979 &viewtableservicegrp;
980}
981### VIEW ###
982if($fwhostsettings{'ACTION'} eq '')
983{
984 &showmenu;
985}
986### FUNCTIONS ###
987sub 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>
996END
997
998 &Header::closebox();
999
1000}
1001# Add
1002sub 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>
1012END
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'}'><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'}' /><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'}' ><input type='hidden' name='ACTION' value='resetnet'></td></tr></table></form>";
1020 &Header::closebox();
1021}
1022sub 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'>
1031END
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>
1038END
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'}' /><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'}' /><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'}'><input type='hidden' name='ACTION' value='resethost'></td></tr></table></form>";
1048 &Header::closebox();
1049}
1050sub 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 nowrap='nowrap' width='16%'>$Lang::tr{'fwhost addgrpname'}</td><td><input type='TEXT' name='grp_name' value='$fwhostsettings{'grp_name'}' size='24'></td><td align='right'>$Lang::tr{'remark'}:</td><td align='right'><input type='TEXT' name='remark' size='30' value='$fwhostsettings{'remark'}'></tr>
1067 <tr><td colspan='5'><hr></td></tr></table>
1068END
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' size='24' value='$fwhostsettings{'grp_name'}' readonly ></td><td>$Lang::tr{'remark'}:</td><td><input type='TEXT' name='remark' size='30' value='$fwhostsettings{'remark'}'></tr>
1073 <tr><td colspan='5'><hr></td></tr></table>
1074END
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
1083END
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;'>
1094END
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;'>
1104END
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;'>
1112END
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;'>
1124END
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;'>
1131END
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;'>
1141END
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>
1150END
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>
1166END
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>
1172END
1173
1174 &Header::closebox();
1175}
1176sub 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'>
1190END
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'>
1203END
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'>
1214END
1215 if ($fwhostsettings{'updatesrv'} eq 'on')
1216 {
1217 print<<END;
1218 <input type='submit' value='$Lang::tr{'fwhost change'}'>
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>
1223END
1224
1225 }else{
1226 print"<input type='submit' value='$Lang::tr{'save'}'><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 reset'}'></form></td></tr>
1230 </table></form>
1231
1232
1233END
1234 &Header::closebox();
1235 &viewtableservice;
1236}
1237sub 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>
1251END
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>
1258END
1259 }
1260 if($fwhostsettings{'updatesrvgrp'} eq 'on'){
1261
1262
1263 print<<END;
1264 <table width='100%' border='0'>
1265 <tr><td width='1%' nowrap='nowrap'>$Lang::tr{'fwhost cust service'}</td><td><select name='CUST_SRV' style='min-width:185px;'>
1266END
1267 &General::readhasharray("$configsrv", \%customservice);
1268 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice)
1269 {
1270 print "<option>$customservice{$key}[0]</option>";
1271 }
1272 print<<END;
1273 </select></td></tr>
1274 <tr><td colspan='4'><br><br><br></td></tr>
1275 <tr><td colspan='4'><hr></td></tr>
1276 </table>
1277END
1278 }
1279 print<<END;
1280 <table width='100%'>
1281 <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'}'></td></tr>
1282 </table></form>
1283END
1284
1285 &Header::closebox();
1286}
1287# View
1288sub viewtablenet
1289{
1290 if(! -z $confignet){
1291 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'});
1292 &General::readhasharray("$confignet", \%customnetwork);
1293 if (!keys %customnetwork)
1294 {
1295 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1296 }else{
1297 print<<END;
1298 <table border='0' width='100%'>
1299 <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>
1300END
1301 }
1302 my $count=0;
1303 foreach my $key (sort { uc($customnetwork{$a}[0]) cmp uc($customnetwork{$b}[0]) } keys %customnetwork) {
1304 if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) {
1305 print" <tr bgcolor='${Header::colouryellow}'>";
1306 }elsif ($count % 2)
1307 {
1308 print" <tr bgcolor='$color{'color22'}'>";
1309 }else
1310 {
1311 print" <tr bgcolor='$color{'color20'}'>";
1312 }
1313 print<<END;
1314 <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>
1315 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1316 <input type='hidden' name='ACTION' value='editnet'>
1317 <input type='hidden' name='HOSTNAME' value='$customnetwork{$key}[0]' />
1318 <input type='hidden' name='IP' value='$customnetwork{$key}[1]' />
1319 <input type='hidden' name='SUBNET' value='$customnetwork{$key}[2]' />
1320 </td></form>
1321END
1322 if($customnetwork{$key}[3] == '0')
1323 {
1324 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>";
1325 }else{
1326 print"<td></td></form></tr>";
1327 }
1328 $count++;
1329 }
1330 print"</table>";
1331 &Header::closebox();
1332 }
1333
1334}
1335sub viewtablehost
1336{
1337 if (! -z $confighost){
1338 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust addr'});
1339 &General::readhasharray("$confighost", \%customhost);
1340 if (!keys %customhost)
1341 {
1342 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1343 }else{
1344 print<<END;
1345 <table border='0' width='100%'>
1346 <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>
1347END
1348 }
1349 my $count=0;
1350 foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0]) } keys %customhost) {
1351 if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) {
1352 print" <tr bgcolor='${Header::colouryellow}'>";
1353 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}
1354 else{ print" <tr bgcolor='$color{'color20'}'>";}
1355 my ($ip,$sub)=split(/\//,$customhost{$key}[2]);
1356 print<<END;
1357 <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>
1358 <td width='1%'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} />
1359 <input type='hidden' name='ACTION' value='edithost' />
1360 <input type='hidden' name='HOSTNAME' value='$customhost{$key}[0]' />
1361 <input type='hidden' name='IP' value='$ip' />
1362 <input type='hidden' name='type' value='$customhost{$key}[1]' />
1363 </td></form>
1364END
1365 if($customhost{$key}[3] == '0')
1366 {
1367 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>";
1368 }else{
1369 print"<td width='1%'></td></tr>";
1370 }
1371 $count++;
1372 }
1373 print"</table>";
1374 &Header::closebox();
1375 }
1376}
1377sub viewtablegrp
1378{
1379 if(! -z "$configgrp"){
1380 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust grp'});
1381 &General::readhasharray("$configgrp", \%customgrp);
1382 &General::readhasharray("$configipsec", \%ipsecconf);
1383 &General::readhasharray("$configccdhost", \%ccdhost);
1384 &General::readhasharray("$configccdnet", \%ccdnet);
1385 &General::readhasharray("$confighost", \%customhost);
1386 &General::readhasharray("$confignet", \%customnetwork);
1387 my @grp=();
1388 my $helper='';
1389 my $count=0;
1390 my $grpname;
1391 my $remark;
1392 my $number=keys %customgrp;
1393 if (!keys %customgrp)
1394 {
1395 print "<center><b>$Lang::tr{'fwhost empty'}</b>";
1396 }else{
1397 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){
1398
1399 $count++;
1400 if ($helper ne $customgrp{$key}[0]){
1401 $grpname=$customgrp{$key}[0];
1402 $remark=$customgrp{$key}[1];
1403 if($count >=2){print"</table>";}
1404 print "<br><b><u>$grpname</u></b> &nbsp &nbsp";
1405 print " <b>$Lang::tr{'remark'}:</b>&nbsp $remark &nbsp " if ($remark ne '');
1406 print "<b>$Lang::tr{'used'}:</b> $customgrp{$key}[4] x";
1407 if($customgrp{$key}[4] == '0')
1408 {
1409 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>";
1410 }
1411 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>";
1412 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>";
1413 }
1414 if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) {
1415 print" <tr bgcolor='${Header::colouryellow}'>";
1416 }elsif ($count %2 == 0){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";}
1417 my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]);
1418 if ($ip eq ''){print"<tr bgcolor='${Header::colouryellow}'>";}
1419
1420
1421 print "<td width='39%'>";
1422 if($customgrp{$key}[3] eq 'Standard Network'){
1423 print &get_name($customgrp{$key}[2])."</td>";
1424 }else{
1425 print "$customgrp{$key}[2]</td>";
1426 }
1427 if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost empty'}){
1428 print "<td align='center'>$Lang::tr{'fwhost deleted'}</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
1429 }else{
1430 print"<td>$ip</td><td>$customgrp{$key}[3]</td><td width='1%'><form method='post'>";
1431 }
1432 if ($number gt '1' && $ip ne ''){
1433 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1434 }
1435 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>";
1436
1437 $helper=$customgrp{$key}[0];
1438 }
1439 print"</table>";
1440
1441 }
1442 &Header::closebox();
1443}
1444
1445}
1446sub viewtableservice
1447{
1448 my $count=0;
1449 if(! -z "$configsrv")
1450 {
1451 &Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
1452 &General::readhasharray("$configsrv", \%customservice);
1453 print<<END;
1454 <table width='100%' border='0'>
1455 <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>
1456END
1457 foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0]) } keys %customservice)
1458 {
1459 $count++;
1460 if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) {
1461 print" <tr bgcolor='${Header::colouryellow}'>";
1462 }elsif ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}else{ print" <tr bgcolor='$color{'color20'}'>";}
1463 print<<END;
1464 <td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
1465END
1466 if($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];}
1467
1468 print<<END;
1469 </td><td align='center'>$customservice{$key}[4]x</td>
1470 <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' />
1471 <input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
1472 <input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
1473 <input type='hidden' name='PROT' value='$customservice{$key}[2]' /></form></td>
1474END
1475 if ($customservice{$key}[4] eq '0')
1476 {
1477 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>";
1478 }else{
1479 print"<td></td></tr>";
1480 }
1481 }
1482 print"</table>";
1483 &Header::closebox();
1484 }
1485}
1486sub viewtableservicegrp
1487{
1488 my $count=0;
1489 my $grpname;
1490 my $remark;
1491 my $helper;
1492 if (! -z $configsrvgrp){
1493
1494 &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
1495 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1496 my $number= keys %customservicegrp;
1497 foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } keys %customservicegrp){
1498 $count++;
1499 if ($helper ne $customservicegrp{$key}[0]){
1500 $grpname=$customservicegrp{$key}[0];
1501 $remark=$customservicegrp{$key}[1];
1502 if($count >=2){print"</table>";}
1503 print "<br><b><u>$grpname</u></b> &nbsp &nbsp ";
1504 print "<b>$Lang::tr{'remark'}:</b>&nbsp $remark " if ($remark ne '');
1505 print "&nbsp <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[5] x";
1506 if($customservicegrp{$key}[5] == '0')
1507 {
1508 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>";
1509 }
1510 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>";
1511 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>";
1512 }
1513 if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) {
1514 print" <tr bgcolor='${Header::colouryellow}'>";
1515 }elsif ($count %2 == 0){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";}
1516 print "<td width='39%'>$customservicegrp{$key}[2]</td>";
1517 print"<td align='center'>$customservicegrp{$key}[3]</td><td align='center'>$customservicegrp{$key}[4]</td><td width='1%'><form method='post'>";
1518 if ($number gt '1'){
1519 print"<input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} />";
1520 }
1521 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>";
1522 $helper=$customservicegrp{$key}[0];
1523 }
1524 print"</table>";
1525 &Header::closebox();
1526 }
1527}
1528# Check
1529sub checkname
1530{
1531 my %hash=%{(shift)};
1532 foreach my $key (keys %hash) {
1533 if($hash{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1534 return 0;
1535 }
1536 }
1537 return 1;
1538
1539}
1540sub checkip
1541{
1542
1543 my %hash=%{(shift)};
1544 my $a=shift;
1545 foreach my $key (keys %hash) {
1546 if($hash{$key}[$a] eq $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'})){
1547 return 0;
1548 }
1549 }
1550 return 1;
1551}
1552sub checksubnet
1553{
1554
1555 my %hash=%{(shift)};
1556 &General::readhasharray("$confignet", \%hash);
1557 foreach my $key (keys %hash) {
1558 if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
1559 {
1560 return 1;
1561 }
1562 }
1563 return 0;
1564}
1565sub checkservicegroup
1566{
1567 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1568
1569
1570 #check name
1571 if ( ! &General::validhostname($fwhostsettings{'SRVGRP_NAME'}))
1572 {
1573 $errormessage.=$Lang::tr{'fwhost err name'}."<br>";
1574 return $errormessage;
1575 }
1576 #check remark
1577 if ( ($fwhostsettings{'SRVGRP_REMARK'} ne '') && (! &validhostname($fwhostsettings{'SRVGRP_REMARK'})))
1578 {
1579 $errormessage.=$Lang::tr{'fwhost err remark'}."<br>";
1580 }
1581 #check empty selectbox
1582 if (keys %customservice lt 1)
1583 {
1584 $errormessage.=$Lang::tr{'fwhost err groupempty'}."<br>";
1585 }
1586
1587 #check if name already exists
1588 if ($fwhostsettings{'updatesrvgrp'} ne 'on'){
1589 foreach my $key (keys %customservicegrp) {
1590 if( $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} ){
1591 $errormessage.=$Lang::tr{'fwhost err grpexist'}."<br>";
1592
1593 }
1594 }
1595 }
1596 #check if service already exists in group
1597 foreach my $key (keys %customservicegrp) {
1598 if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'} && $customservicegrp{$key}[2] eq $fwhostsettings{'CUST_SRV'} ){
1599 $errormessage.=$Lang::tr{'fwhost err srvexist'}."<br>";
1600
1601 }
1602 }
1603
1604
1605
1606 return $errormessage;
1607}
1608sub error
1609{
1610 if ($errormessage) {
1611 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1612 print "<class name='base'>$errormessage\n";
1613 print "&nbsp;</class>\n";
1614 &Header::closebox();
1615 }
1616}
1617sub hint
1618{
1619 if ($hint) {
1620 &Header::openbox('100%', 'left', $Lang::tr{'fwhost hint'});
1621 print "<class name='base'>$hint\n";
1622 print "&nbsp;</class>\n";
1623 &Header::closebox();
1624 }
1625}
1626sub get_name
1627{
1628 my $val=shift;
1629 &General::setup_default_networks(\%defaultNetworks);
1630 foreach my $network (sort keys %defaultNetworks)
1631 {
1632 return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
1633 }
1634}
1635sub deletefromgrp
1636{
1637 my $target=shift;
1638 my $config=shift;
1639 my %hash=();
1640 &General::readhasharray("$config",\%hash);
1641 foreach my $key (keys %hash) {
1642 $errormessage.="lese $hash{$key}[2] und $target<br>";
1643 if($hash{$key}[2] eq $target){
1644
1645 delete $hash{$key};
1646 $errormessage.="Habe $target aus Gruppe gelöscht!<br>";
1647 }
1648 }
1649 &General::writehasharray("$config",\%hash);
1650
1651}
1652sub plausicheck
1653{
1654
1655 my $edit=shift;
1656 #check hostname
1657 if (!&General::validhostname($fwhostsettings{'HOSTNAME'}))
1658 {
1659 $errormessage=$errormessage.$Lang::tr{'fwhost err name'};
1660 $fwhostsettings{'BLK_IP'}='readonly';
1661 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1662 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1663 }
1664 #check if name collides with CCD Netname
1665
1666 &General::readhasharray("$configccdnet", \%ccdnet);
1667 foreach my $key (keys %ccdnet) {
1668 if($ccdnet{$key}[0] eq $fwhostsettings{'HOSTNAME'}){
1669 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdnet'};;
1670 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1671 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1672 last;
1673 }
1674 }
1675
1676 #check if IP collides with CCD NetIP
1677 if ($fwhostsettings{'type'} ne 'mac'){
1678 &General::readhasharray("$configccdnet", \%ccdnet);
1679 foreach my $key (keys %ccdnet) {
1680 my $test=(&General::getnetworkip($fwhostsettings{'IP'},&General::iporsubtocidr($fwhostsettings{'SUBNET'})))."/".$fwhostsettings{'SUBNET'};
1681 if($ccdnet{$key}[1] eq $test){
1682 $errormessage=$errormessage.$Lang::tr{'fwhost err isccdipnet'};
1683 $fwhostsettings{'IP'} = $fwhostsettings{'orgip'};
1684 $fwhostsettings{'SUBNET'} = $fwhostsettings{'orgsubnet'};
1685 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1686 last;
1687 }
1688 }
1689 }
1690
1691
1692
1693 #check if name collides with CCD Hostname
1694 &General::readhasharray("$configccdhost", \%ccdhost);
1695 foreach my $key (keys %ccdhost) {
1696 my ($ip,$sub)=split(/\//,$ccdhost{$key}[33]);
1697 if($ip eq $fwhostsettings{'IP'}){
1698 $errormessage=$Lang::tr{'fwhost err isccdiphost'};
1699 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1700 last;
1701 }
1702 }
1703 #check if IP collides with CCD HostIP (only hosts)
1704 if ($edit eq 'edithost')
1705 {
1706 foreach my $key (keys %ccdhost) {
1707 if($ccdhost{$key}[1] eq $fwhostsettings{'HOSTNAME'}){
1708 $errormessage=$Lang::tr{'fwhost err isccdhost'};
1709 $fwhostsettings{'IP'} = $fwhostsettings{'orgname'};
1710 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1711 last;
1712 }
1713 }
1714 }
1715 #check if network with this name already exists
1716 &General::readhasharray("$confignet", \%customnetwork);
1717 if (!&checkname(\%customnetwork))
1718 {
1719 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err netexist'};
1720 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1721 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1722 }
1723 #check if network ip already exists
1724 if (!&checkip(\%customnetwork,1))
1725 {
1726 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err net'};
1727 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1728 }
1729 #check if host with this name already exists
1730 &General::readhasharray("$confighost", \%customhost);
1731 if (!&checkname(\%customhost))
1732 {
1733 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err hostexist'};
1734 $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
1735 if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}=$edit;}
1736 }
1737 #check if host with this ip already exists
1738 if (!&checkip(\%customhost,2))
1739 {
1740 $errormessage=$errormessage."<br>".$Lang::tr{'fwhost err ipcheck'};
1741
1742 }
1743
1744
1745 return;
1746}
1747sub getipforgroup
1748{
1749 my $name=$_[0],
1750 my $type=$_[1];
1751 my $value;
1752
1753 #get address from IPSEC NETWORK
1754 if ($type eq 'IpSec Network'){
1755 foreach my $key (keys %ipsecconf) {
1756 if ($ipsecconf{$key}[1] eq $name){
1757 return $ipsecconf{$key}[11];
1758 }
1759 }
1760 &deletefromgrp($name,$configgrp);
1761 }
1762
1763 #get address from IPSEC HOST
1764 if ($type eq 'IpSec Host'){
1765 foreach my $key (keys %ipsecconf) {
1766 if ($ipsecconf{$key}[1] eq $name){
1767 return $ipsecconf{$key}[10];
1768 }
1769 }
1770 &deletefromgrp($name,$configgrp);
1771 }
1772
1773 #get address from ovpn ccd Net-2-Net
1774 if ($type eq 'OpenVPN N-2-N'){
1775 foreach my $key (keys %ccdhost) {
1776 if($ccdhost{$key}[1] eq $name){
1777 my ($a,$b) = split ("/",$ccdhost{$key}[11]);
1778 $b=&General::iporsubtodec($b);
1779 return "$a/$b";
1780 }
1781 }
1782 &deletefromgrp($name,$configgrp);
1783 }
1784
1785 #get address from ovpn ccd static host
1786 if ($type eq 'OpenVPN static host'){
1787 foreach my $key (keys %ccdhost) {
1788 if($ccdhost{$key}[1] eq $name){
1789 my ($a,$b) = split (/\//,$ccdhost{$key}[33]);
1790 $b=&General::iporsubtodec($b);
1791 return "$a/$b";
1792 }
1793 }
1794 &deletefromgrp($name,$configgrp);
1795 }
1796
1797 #get address from ovpn ccd static net
1798 if ($type eq 'OpenVPN static network'){
1799 foreach my $key (keys %ccdnet) {
1800 if ($ccdnet{$key}[0] eq $name){
1801 my ($a,$b) = split (/\//,$ccdnet{$key}[1]);
1802 $b=&General::iporsubtodec($b);
1803 return "$a/$b";
1804 }
1805 }
1806 }
1807
1808 #check custom addresses
1809 if ($type eq 'Custom Host'){
1810 foreach my $key (keys %customhost) {
1811 if ($customhost{$key}[0] eq $name){
1812 return $customhost{$key}[2];
1813 }
1814 }
1815 }
1816
1817 ##check custom networks
1818 if ($type eq 'Custom Network'){
1819 foreach my $key (keys %customnetwork) {
1820 if($customnetwork{$key}[0] eq $name){
1821 return $customnetwork{$key}[1]."/".$customnetwork{$key}[2];
1822 }
1823 }
1824 }
1825
1826 #check standard networks
1827 if ($type eq 'Standard Network'){
1828 if ($name =~ /OpenVPN/i){
1829 my %ovpn=();
1830 &General::readhash("${General::swroot}/ovpn/settings",\%ovpn);
1831 return $ovpn{'DOVPN_SUBNET'};
1832 }
1833 if ($name eq 'GREEN'){
1834 my %hash=();
1835 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1836 return $hash{'GREEN_NETADDRESS'}."/".$hash{'GREEN_NETMASK'};
1837 }
1838 if ($name eq 'BLUE'){
1839 my %hash=();
1840 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1841 return $hash{'BLUE_NETADDRESS'}."/".$hash{'BLUE_NETMASK'};
1842 }
1843 if ($name eq 'ORANGE'){
1844 my %hash=();
1845 &General::readhash("${General::swroot}/ethernet/settings",\%hash);
1846 return $hash{'ORANGE_NETADDRESS'}."/".$hash{'ORANGE_NETMASK'};
1847 }
1848 if ($name eq 'ALL'){
1849 return "0.0.0.0/0.0.0.0";
1850 }
1851 if ($name =~ /IPsec/i){
1852 my %hash=();
1853 &General::readhash("${General::swroot}/vpn/settings",\%hash);
1854 return $hash{'RW_NET'};
1855 }
1856 }
1857}
1858sub rules
1859{
1860 system ("/usr/local/bin/forwardfwctrl");
1861 system("rm ${General::swroot}/forward/reread");
1862}
1863sub decrease
1864{
1865 my $grp=$_[0];
1866 &General::readhasharray("$confignet", \%customnetwork);
1867 &General::readhasharray("$confighost", \%customhost);
1868 foreach my $key (sort keys %customgrp ){
1869 if ( ($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Network')){
1870 foreach my $key1 (sort keys %customnetwork){
1871 if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){
1872 $customnetwork{$key1}[3]=$customnetwork{$key1}[3]-1;
1873 last;
1874 }
1875 }
1876 }
1877
1878 if (($customgrp{$key}[0] eq $grp) && ($customgrp{$key}[3] eq 'Custom Host')){
1879 foreach my $key2 (sort keys %customhost){
1880 if ($customhost{$key2}[0] eq $customgrp{$key}[2]){
1881 $customhost{$key2}[3]=$customhost{$key2}[3]-1;
1882 last;
1883 }
1884 }
1885
1886 }
1887 }
1888 &General::writehasharray("$confignet", \%customnetwork);
1889 &General::writehasharray("$confighost", \%customhost);
1890}
1891sub decreaseservice
1892{
1893 my $grp=$_[0];
1894 &General::readhasharray("$configsrv", \%customservice);
1895 &General::readhasharray("$configsrvgrp", \%customservicegrp);
1896
1897 foreach my $key (sort keys %customservicegrp){
1898 if ($customservicegrp{$key}[0] eq $grp ){
1899 foreach my $key2 (sort keys %customservice){
1900 if ($customservice{$key2}[0] eq $customservicegrp{$key}[2]){
1901 $customservice{$key2}[4]--;
1902 }
1903 }
1904 }
1905 }
1906 &General::writehasharray("$configsrv", \%customservice);
1907
1908}
1909sub checkports
1910{
1911
1912 my %hash=%{(shift)};
1913 #check empty fields
1914 if ($fwhostsettings{'SRV_NAME'} eq '' ){
1915 $errormessage=$Lang::tr{'fwhost err name1'};
1916 }
1917 if ($fwhostsettings{'SRV_PORT'} eq '' && $fwhostsettings{'PROT'} ne 'ICMP'){
1918 $errormessage=$Lang::tr{'fwhost err port'};
1919 }
1920 #check valid name
1921 if (! &General::validhostname($fwhostsettings{'SRV_NAME'})){
1922 $errormessage="<br>".$Lang::tr{'fwhost err name'};
1923 }
1924 #change dashes with :
1925 $fwhostsettings{'SRV_PORT'}=~ tr/-/:/;
1926
1927 if ($fwhostsettings{'SRV_PORT'} eq "*") {
1928 $fwhostsettings{'SRV_PORT'} = "1:65535";
1929 }
1930 if ($fwhostsettings{'SRV_PORT'} =~ /^(\D)\:(\d+)$/) {
1931 $fwhostsettings{'SRV_PORT'} = "1:$2";
1932 }
1933 if ($fwhostsettings{'SRV_PORT'} =~ /^(\d+)\:(\D)$/) {
1934 $fwhostsettings{'SRV_PORT'} = "$1:65535";
1935 }
1936 if($fwhostsettings{'PROT'} ne 'ICMP'){
1937 $errormessage = $errormessage.&General::validportrange($fwhostsettings{'SRV_PORT'}, 'src');
1938 }
1939 # a new service has to have a different name
1940 foreach my $key (keys %hash){
1941 if ($hash{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
1942 $errormessage = "<br>".$Lang::tr{'fwhost err srv exists'};
1943 last;
1944 }
1945 }
1946 return $errormessage;
1947}
1948sub validhostname
1949{
1950 # Checks a hostname against RFC1035
1951 my $hostname = $_[0];
1952
1953 # Each part should be at least two characters in length
1954 # but no more than 63 characters
1955 if (length ($hostname) < 1 || length ($hostname) > 63) {
1956 return 0;}
1957 # Only valid characters are a-z, A-Z, 0-9 and -
1958 if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-\s]*$/) {
1959 return 0;}
1960 # First character can only be a letter or a digit
1961 if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
1962 return 0;}
1963 # Last character can only be a letter or a digit
1964 if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
1965 return 0;}
1966 return 1;
1967}
1968
1969&Header::closebigbox();
1970&Header::closepage();