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